Skip to content

Commit

Permalink
Merge pull request #115 from zerodevapp/feat/gas-fees-sponsorUserOper…
Browse files Browse the repository at this point in the history
…ation

feat: change sponsorUserOperation return type to include gas fee values
  • Loading branch information
SahilVasava authored Apr 17, 2024
2 parents 9eaa09b + b8d96d2 commit 14acdc1
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 68 deletions.
Binary file modified bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/sdk

## 5.2.4

### Patch Changes

- Update [email protected] and return maxFeePerGas and maxPriorityFeePerGas in response from sponsorUserOperation action
77 changes: 28 additions & 49 deletions packages/core/actions/paymaster/sponsorUserOperation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { getEntryPointVersion } from "permissionless"
import type {
ENTRYPOINT_ADDRESS_V06_TYPE,
EntryPoint,
GetEntryPointVersion
EntryPoint
} from "permissionless/types/entrypoint"
import type {
UserOperation,
UserOperationWithBigIntAsHex
} from "permissionless/types/userOperation.js"
import { ENTRYPOINT_ADDRESS_V06, deepHexlify } from "permissionless/utils"
import type { UserOperation } from "permissionless/types/userOperation.js"
import { deepHexlify } from "permissionless/utils"
import type { Address, Hex } from "viem"
import type { PartialBy } from "viem/types/utils"
import type { ZeroDevPaymasterClient } from "../../clients/paymasterClient.js"
Expand All @@ -32,6 +29,8 @@ export type SponsorUserOperationParameters<entryPoint extends EntryPoint> = {
shouldConsume?: boolean
}

export type PartialPick<T, K extends keyof T> = Partial<Pick<T, K>>

export type SponsorUserOperationReturnType<entryPoint extends EntryPoint> =
entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE
? Pick<
Expand All @@ -40,7 +39,11 @@ export type SponsorUserOperationReturnType<entryPoint extends EntryPoint> =
| "verificationGasLimit"
| "preVerificationGas"
| "paymasterAndData"
>
> &
PartialPick<
UserOperation<"v0.6">,
"maxFeePerGas" | "maxPriorityFeePerGas"
>
: Pick<
UserOperation<"v0.7">,
| "callGasLimit"
Expand All @@ -50,7 +53,11 @@ export type SponsorUserOperationReturnType<entryPoint extends EntryPoint> =
| "paymasterVerificationGasLimit"
| "paymasterPostOpGasLimit"
| "paymasterData"
>
> &
PartialPick<
UserOperation<"v0.7">,
"maxFeePerGas" | "maxPriorityFeePerGas"
>

/**
* Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
Expand All @@ -64,11 +71,7 @@ export const sponsorUserOperation = async <entryPoint extends EntryPoint>(
params: [
{
chainId: client.chain?.id as number,
userOp: deepHexlify(
args.userOperation
) as UserOperationWithBigIntAsHex<
GetEntryPointVersion<entryPoint>
>,
userOp: deepHexlify(args.userOperation),
entryPointAddress: args.entryPoint,
gasTokenData: args.gasToken && {
tokenAddress: args.gasToken
Expand All @@ -78,22 +81,18 @@ export const sponsorUserOperation = async <entryPoint extends EntryPoint>(
}
]
})
if (args.entryPoint === ENTRYPOINT_ADDRESS_V06) {
const responseV06 = response as {
paymasterAndData: Hex
preVerificationGas: Hex
verificationGasLimit: Hex
callGasLimit: Hex
paymaster?: never
paymasterVerificationGasLimit?: never
paymasterPostOpGasLimit?: never
paymasterData?: never
}
const entryPointVersion = getEntryPointVersion(args.entryPoint)
if (entryPointVersion === "v0.6") {
return {
paymasterAndData: responseV06.paymasterAndData,
preVerificationGas: BigInt(responseV06.preVerificationGas),
verificationGasLimit: BigInt(responseV06.verificationGasLimit),
callGasLimit: BigInt(responseV06.callGasLimit)
paymasterAndData: response.paymasterAndData,
preVerificationGas: BigInt(response.preVerificationGas),
verificationGasLimit: BigInt(response.verificationGasLimit),
callGasLimit: BigInt(response.callGasLimit),
maxFeePerGas:
response.maxFeePerGas && BigInt(response.maxFeePerGas),
maxPriorityFeePerGas:
response.maxPriorityFeePerGas &&
BigInt(response.maxPriorityFeePerGas)
} as SponsorUserOperationReturnType<entryPoint>
}
const responseV07 = response as {
Expand All @@ -118,24 +117,4 @@ export const sponsorUserOperation = async <entryPoint extends EntryPoint>(
paymasterPostOpGasLimit: BigInt(responseV07.paymasterPostOpGasLimit),
paymasterData: responseV07.paymasterData
} as SponsorUserOperationReturnType<entryPoint>
// [TODO] Add gas price params in the response in permissionless
// let result: UserOperation<"v0.6"> = {
// ...args.userOperation,
// paymasterAndData: response.paymasterAndData,
// preVerificationGas: BigInt(response.preVerificationGas),
// verificationGasLimit: BigInt(response.verificationGasLimit),
// callGasLimit: BigInt(response.callGasLimit)
// }
// if (
// response.maxFeePerGas !== undefined &&
// response.maxPriorityFeePerGas !== undefined
// ) {
// result = {
// ...result,
// maxFeePerGas: BigInt(response.maxFeePerGas),
// maxPriorityFeePerGas: BigInt(response.maxPriorityFeePerGas)
// }
// }

// return result
}
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/sdk",
"version": "5.2.3",
"version": "5.2.4",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -91,7 +91,7 @@
},
"peerDependencies": {
"viem": "^2.9.17",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
},
"dependencies": {
"semver": "^7.6.0"
Expand Down
6 changes: 4 additions & 2 deletions packages/core/types/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export type ZeroDevPaymasterRpcSchema<entryPoint extends EntryPoint> = [
preVerificationGas: Hex
verificationGasLimit: Hex
callGasLimit: Hex
maxFeePerGas: Hex
maxPriorityFeePerGas: Hex
maxFeePerGas?: Hex
maxPriorityFeePerGas?: Hex
paymaster?: never
paymasterVerificationGasLimit?: never
paymasterPostOpGasLimit?: never
Expand All @@ -61,6 +61,8 @@ export type ZeroDevPaymasterRpcSchema<entryPoint extends EntryPoint> = [
paymasterVerificationGasLimit: Hex
paymasterPostOpGasLimit: Hex
paymasterData: Hex
maxFeePerGas?: Hex
maxPriorityFeePerGas?: Hex
paymasterAndData?: never
}
},
Expand Down
7 changes: 7 additions & 0 deletions packages/presets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/presets

## 5.2.2

### Patch Changes

- Update [email protected]
4 changes: 2 additions & 2 deletions packages/presets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/presets",
"version": "5.2.1",
"version": "5.2.2",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -52,7 +52,7 @@
"typescript": "^5.0.0",
"@zerodev/sdk": "^5.2.1",
"@zerodev/ecdsa-validator": "^5.2.1",
"permissionless": "^0.1.17",
"permissionless": "^0.1.18",
"viem": "^2.9.17"
}
}
3 changes: 3 additions & 0 deletions packages/test/ecdsaKernelAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ describe("ECDSA kernel Account", () => {
userOperation: userOp
})
expect(userOpHash).toHaveLength(66)
await bundlerClient.waitForUserOperationReceipt({
hash: userOpHash
})

await waitForNonceUpdate()
},
Expand Down
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"@zerodev/ecdsa-validator": "workspace:*",
"@zerodev/session-key": "workspace:*",
"@zerodev/modular-permission": "workspace:*",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
}
}
7 changes: 7 additions & 0 deletions plugins/ecdsa/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/ecdsa-validator

## 5.2.3

### Patch Changes

- Update [email protected]
4 changes: 2 additions & 2 deletions plugins/ecdsa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/ecdsa-validator",
"version": "5.2.2",
"version": "5.2.3",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -37,6 +37,6 @@
"peerDependencies": {
"viem": "^2.9.17",
"@zerodev/sdk": "^5.2.1",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
}
}
7 changes: 7 additions & 0 deletions plugins/modularPermission/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/modular-permission

## 5.2.2

### Patch Changes

- Update [email protected]
4 changes: 2 additions & 2 deletions plugins/modularPermission/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/modular-permission",
"version": "5.2.1",
"version": "5.2.2",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -58,6 +58,6 @@
"peerDependencies": {
"viem": "^2.9.17",
"@zerodev/sdk": "^5.2.1",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
}
}
7 changes: 7 additions & 0 deletions plugins/passkey/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/passkey-validator

## 5.2.3

### Patch Changes

- Update [email protected]
4 changes: 2 additions & 2 deletions plugins/passkey/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/passkey-validator",
"version": "5.2.2",
"version": "5.2.3",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -41,6 +41,6 @@
"peerDependencies": {
"viem": "^2.9.17",
"@zerodev/sdk": "^5.2.1",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
}
}
7 changes: 7 additions & 0 deletions plugins/permission/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/permissions

## 5.2.2

### Patch Changes

- Update [email protected]
4 changes: 2 additions & 2 deletions plugins/permission/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/permissions",
"version": "5.2.1",
"version": "5.2.2",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -58,6 +58,6 @@
"peerDependencies": {
"viem": "^2.9.17",
"@zerodev/sdk": "^5.2.1",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
}
}
7 changes: 7 additions & 0 deletions plugins/session-key/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/session-key

## 5.2.2

### Patch Changes

- Update [email protected]
4 changes: 2 additions & 2 deletions plugins/session-key/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/session-key",
"version": "5.2.1",
"version": "5.2.2",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -40,6 +40,6 @@
"peerDependencies": {
"viem": "^2.9.17",
"@zerodev/sdk": "^5.2.1",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
}
}
7 changes: 7 additions & 0 deletions plugins/weighted-ecdsa/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @zerodev/weighted-ecdsa-validator

## 5.2.2

### Patch Changes

- Update [email protected]
4 changes: 2 additions & 2 deletions plugins/weighted-ecdsa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/weighted-ecdsa-validator",
"version": "5.2.1",
"version": "5.2.2",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down Expand Up @@ -37,6 +37,6 @@
"peerDependencies": {
"viem": "^2.9.17",
"@zerodev/sdk": "^5.2.1",
"permissionless": "^0.1.17"
"permissionless": "^0.1.18"
}
}

0 comments on commit 14acdc1

Please sign in to comment.