-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from pimlicolabs/feat/get-required-prefund
Add util function get pre fund
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"permissionless": patch | ||
--- | ||
|
||
Added getRequiredPrefund utility function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { UserOperation } from "../types" | ||
|
||
export type GetRequiredPrefundReturnType = { | ||
userOperation: UserOperation | ||
} | ||
|
||
/** | ||
* | ||
* Returns the minimum required funds in the senders's smart account to execute the user operation. | ||
* | ||
* @param arags: {userOperation} as {@link UserOperation} | ||
* @returns requiredPrefund as {@link bigint} | ||
* | ||
* @example | ||
* import { getRequiredPrefund } from "permissionless/utils" | ||
* | ||
* const requiredPrefund = getRequiredPrefund({ | ||
* userOperation | ||
* }) | ||
*/ | ||
export const getRequiredPrefund = ({ | ||
userOperation | ||
}: GetRequiredPrefundReturnType): bigint => { | ||
const multiplier = userOperation.paymasterAndData.length > 2 ? 3n : 1n | ||
const requiredGas = | ||
userOperation.callGasLimit + | ||
userOperation.verificationGasLimit * multiplier + | ||
userOperation.preVerificationGas | ||
|
||
return BigInt(requiredGas) * BigInt(userOperation.maxFeePerGas) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters