-
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 #193 from pimlicolabs/feat/7677-experimental
Add 7677 experimental support
- Loading branch information
Showing
16 changed files
with
550 additions
and
19 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 experimental EIP 7677 support |
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,83 @@ | ||
import { | ||
ENTRYPOINT_ADDRESS_V06, | ||
createSmartAccountClient | ||
} from "permissionless" | ||
import { privateKeyToSafeSmartAccount } from "permissionless/accounts" | ||
import { paymasterActionsEip7677 } from "permissionless/experimental" | ||
import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/types" | ||
import { http, createClient, zeroAddress } from "viem" | ||
import { generatePrivateKey } from "viem/accounts" | ||
import { foundry } from "viem/chains" | ||
import { describe, test } from "vitest" | ||
import type { AAParamType } from "../types" | ||
import { | ||
PAYMASTER_RPC, | ||
getPimlicoPaymasterClient, | ||
getPublicClient, | ||
getSafeClient | ||
} from "../utils" | ||
|
||
describe.each([ | ||
{ | ||
name: "Eip 7677 client", | ||
|
||
getSmartAccountClient: async ( | ||
conf: AAParamType<ENTRYPOINT_ADDRESS_V06_TYPE> | ||
) => getSafeClient(conf) | ||
} | ||
])("$name test", ({ name, getSmartAccountClient }) => { | ||
test("Can get stab data", async () => { | ||
const publicClient = getPublicClient() | ||
|
||
const smartAccount = await privateKeyToSafeSmartAccount(publicClient, { | ||
safeVersion: "1.4.1", | ||
entryPoint: ENTRYPOINT_ADDRESS_V06, | ||
privateKey: generatePrivateKey() | ||
}) | ||
const ALTO_RPC = "http://localhost:4337" | ||
|
||
const paymasterClient = getPimlicoPaymasterClient( | ||
ENTRYPOINT_ADDRESS_V06 | ||
) | ||
|
||
const smartAccountClient = createSmartAccountClient({ | ||
chain: foundry, | ||
account: smartAccount, | ||
bundlerTransport: http(ALTO_RPC) | ||
}) | ||
|
||
const userOperaton = | ||
await smartAccountClient.prepareUserOperationRequest({ | ||
userOperation: { | ||
callData: await smartAccountClient.account.encodeCallData({ | ||
to: zeroAddress, | ||
value: 0n, | ||
data: "0x" | ||
}) | ||
} | ||
}) | ||
|
||
const eip7677Client = createClient({ | ||
chain: foundry, | ||
transport: http(PAYMASTER_RPC) | ||
}).extend( | ||
paymasterActionsEip7677({ entryPoint: ENTRYPOINT_ADDRESS_V06 }) | ||
) | ||
|
||
const response = await eip7677Client.getPaymasterData({ | ||
userOperation: userOperaton | ||
}) | ||
|
||
// await eip7677Client.getPaymasterStubData({ | ||
// userOperation: await smartClient.prepareUserOperationRequest({ | ||
// userOperation: { | ||
// callData: await smartClient.account.encodeCallData({ | ||
// to: zeroAddress, | ||
// value: 0n, | ||
// data: "0x" | ||
// }) | ||
// } | ||
// }) | ||
// }) | ||
}) | ||
}) |
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
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
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
122 changes: 122 additions & 0 deletions
122
packages/permissionless/experimental/eip7677/actions/getPaymasterData.ts
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,122 @@ | ||
import { | ||
type Chain, | ||
ChainNotFoundError, | ||
type Client, | ||
type GetChainParameter, | ||
type Hex, | ||
type Transport, | ||
toHex | ||
} from "viem" | ||
import type { | ||
ENTRYPOINT_ADDRESS_V06_TYPE, | ||
ENTRYPOINT_ADDRESS_V07_TYPE, | ||
EntryPoint, | ||
GetEntryPointVersion | ||
} from "../../../types/entrypoint" | ||
import type { | ||
UserOperation, | ||
UserOperationWithBigIntAsHex | ||
} from "../../../types/userOperation" | ||
import { deepHexlify, getEntryPointVersion } from "../../../utils" | ||
import type { | ||
Eip7677RpcSchema, | ||
GetRpcPaymasterDataReturnType | ||
} from "../types/paymaster" | ||
|
||
export type GetPaymasterDataParameters< | ||
TEntryPoint extends EntryPoint, | ||
TChain extends Chain | undefined = Chain | undefined, | ||
TChainOverride extends Chain | undefined = Chain | undefined | ||
> = { | ||
userOperation: UserOperation<GetEntryPointVersion<TEntryPoint>> | ||
entryPoint: TEntryPoint | ||
context?: Record<string, unknown> | ||
} & GetChainParameter<TChain, TChainOverride> | ||
|
||
export type GetPaymasterDataReturnType<TEntryPoint extends EntryPoint> = | ||
GetEntryPointVersion<TEntryPoint> extends "v0.6" | ||
? { | ||
paymasterAndData: Hex | ||
} | ||
: { | ||
paymaster: Hex | ||
paymasterData: Hex | ||
} | ||
|
||
export async function getPaymasterData< | ||
TEntryPoint extends EntryPoint, | ||
TChain extends Chain | undefined, | ||
TTransport extends Transport = Transport, | ||
TChainOverride extends Chain | undefined = Chain | undefined | ||
>( | ||
client: Client< | ||
TTransport, | ||
TChain, | ||
undefined, | ||
Eip7677RpcSchema<TEntryPoint> | ||
>, | ||
{ | ||
userOperation, | ||
entryPoint, | ||
context, | ||
chain | ||
}: GetPaymasterDataParameters<TEntryPoint, TChain, TChainOverride> | ||
): Promise<GetPaymasterDataReturnType<TEntryPoint>> { | ||
const chainId = chain?.id ?? client.chain?.id | ||
|
||
if (!chainId) { | ||
throw new ChainNotFoundError() | ||
} | ||
|
||
const params: | ||
| [ | ||
UserOperationWithBigIntAsHex<GetEntryPointVersion<TEntryPoint>>, | ||
TEntryPoint, | ||
Hex, | ||
Record<string, unknown> | ||
] | ||
| [ | ||
UserOperationWithBigIntAsHex<GetEntryPointVersion<TEntryPoint>>, | ||
TEntryPoint, | ||
Hex | ||
] = context | ||
? [ | ||
deepHexlify(userOperation) as UserOperationWithBigIntAsHex< | ||
GetEntryPointVersion<TEntryPoint> | ||
>, | ||
entryPoint, | ||
toHex(chainId), | ||
context | ||
] | ||
: [ | ||
deepHexlify(userOperation) as UserOperationWithBigIntAsHex< | ||
GetEntryPointVersion<TEntryPoint> | ||
>, | ||
entryPoint, | ||
toHex(chainId) | ||
] | ||
|
||
const response = await client.request({ | ||
method: "pm_getPaymasterData", | ||
params | ||
}) | ||
|
||
const entryPointVersion = getEntryPointVersion(entryPoint) | ||
|
||
if (entryPointVersion === "v0.6") { | ||
const responseV06 = | ||
response as GetRpcPaymasterDataReturnType<ENTRYPOINT_ADDRESS_V06_TYPE> | ||
|
||
return { | ||
paymasterAndData: responseV06.paymasterAndData | ||
} as GetPaymasterDataReturnType<TEntryPoint> | ||
} | ||
|
||
const responseV07 = | ||
response as GetRpcPaymasterDataReturnType<ENTRYPOINT_ADDRESS_V07_TYPE> | ||
|
||
return { | ||
paymaster: responseV07.paymaster, | ||
paymasterData: responseV07.paymasterData | ||
} as GetPaymasterDataReturnType<TEntryPoint> | ||
} |
Oops, something went wrong.