ox 1.0.0-beta.21 → 1.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/erc4337/EntryPoint.d.ts +1072 -1
- package/dist/erc4337/EntryPoint.d.ts.map +1 -1
- package/dist/erc4337/EntryPoint.js +872 -0
- package/dist/erc4337/EntryPoint.js.map +1 -1
- package/dist/erc4337/RpcSchema.d.ts +2 -2
- package/dist/erc4337/RpcSchema.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.d.ts +39 -10
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +62 -48
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc4337/UserOperationGas.d.ts +9 -5
- package/dist/erc4337/UserOperationGas.d.ts.map +1 -1
- package/dist/erc4337/UserOperationGas.js +17 -15
- package/dist/erc4337/UserOperationGas.js.map +1 -1
- package/dist/erc4337/UserOperationReceipt.d.ts +4 -4
- package/dist/erc4337/UserOperationReceipt.d.ts.map +1 -1
- package/dist/erc4337/UserOperationReceipt.js.map +1 -1
- package/package.json +1 -1
- package/src/erc4337/EntryPoint.ts +875 -1
- package/src/erc4337/RpcSchema.ts +4 -2
- package/src/erc4337/UserOperation.ts +130 -60
- package/src/erc4337/UserOperationGas.ts +36 -28
- package/src/erc4337/UserOperationReceipt.ts +15 -7
- package/src/erc4337/_test/EntryPoint.test.ts +48 -0
- package/src/erc4337/_test/RpcSchema.test-d.ts +56 -0
- package/src/erc4337/_test/UserOperation.snap-d.ts +31 -0
- package/src/erc4337/_test/UserOperation.test.ts +221 -5
- package/src/erc4337/_test/UserOperationGas.test.ts +30 -1
- package/src/version.ts +1 -1
package/src/erc4337/RpcSchema.ts
CHANGED
|
@@ -50,7 +50,7 @@ export type Bundler<
|
|
|
50
50
|
method: 'eth_getUserOperationByHash'
|
|
51
51
|
params: [hash: Hex.Hex]
|
|
52
52
|
}
|
|
53
|
-
ReturnType: UserOperation.
|
|
53
|
+
ReturnType: UserOperation.RpcTransactionInfo<entryPointVersion> | null
|
|
54
54
|
}
|
|
55
55
|
| {
|
|
56
56
|
Request: {
|
|
@@ -105,7 +105,9 @@ export type BundlerDebug<
|
|
|
105
105
|
method: 'debug_bundler_dumpMempool'
|
|
106
106
|
params: [entryPoint: Address.Address]
|
|
107
107
|
}
|
|
108
|
-
ReturnType: readonly {
|
|
108
|
+
ReturnType: readonly {
|
|
109
|
+
userOp: UserOperation.Rpc<entryPointVersion>
|
|
110
|
+
}[]
|
|
109
111
|
}
|
|
110
112
|
| {
|
|
111
113
|
Request: {
|
|
@@ -5,7 +5,7 @@ import type * as Errors from '../core/Errors.js'
|
|
|
5
5
|
import * as Hash from '../core/Hash.js'
|
|
6
6
|
import * as Hex from '../core/Hex.js'
|
|
7
7
|
import * as Quantity from '../core/internal/quantity.js'
|
|
8
|
-
import type { Assign, Compute, OneOf } from '../core/internal/types.js'
|
|
8
|
+
import type { Assign, Compute, Omit, OneOf } from '../core/internal/types.js'
|
|
9
9
|
import * as Signature from '../core/Signature.js'
|
|
10
10
|
import * as TypedData from '../core/TypedData.js'
|
|
11
11
|
import type * as EntryPoint from './EntryPoint.js'
|
|
@@ -15,6 +15,9 @@ import type * as EntryPoint from './EntryPoint.js'
|
|
|
15
15
|
/** keccak256 of empty bytes (`0x`). Reused for empty initCode/paymasterAndData. */
|
|
16
16
|
const EMPTY_KECCAK = /*#__PURE__*/ Hash.keccak256('0x')
|
|
17
17
|
|
|
18
|
+
/** Magic suffix for an independently encoded paymaster signature. */
|
|
19
|
+
const paymasterSignatureMagic = '0x22e325a297439656' as const
|
|
20
|
+
|
|
18
21
|
/** ABI parameters for v0.6 user operation packed encoding. */
|
|
19
22
|
const v06HashParameters = [
|
|
20
23
|
{ type: 'address' },
|
|
@@ -74,6 +77,9 @@ export type UserOperation<
|
|
|
74
77
|
| (entryPointVersion extends '0.8'
|
|
75
78
|
? V08<signed, bigintType, numberType>
|
|
76
79
|
: never)
|
|
80
|
+
| (entryPointVersion extends '0.9'
|
|
81
|
+
? V09<signed, bigintType, numberType>
|
|
82
|
+
: never)
|
|
77
83
|
>
|
|
78
84
|
|
|
79
85
|
/**
|
|
@@ -107,9 +113,10 @@ export type Rpc<
|
|
|
107
113
|
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
108
114
|
signed extends boolean = true,
|
|
109
115
|
> = OneOf<
|
|
110
|
-
| (entryPointVersion extends '0.6' ?
|
|
111
|
-
| (entryPointVersion extends '0.7' ?
|
|
112
|
-
| (entryPointVersion extends '0.8' ?
|
|
116
|
+
| (entryPointVersion extends '0.6' ? RpcV06<signed> : never)
|
|
117
|
+
| (entryPointVersion extends '0.7' ? RpcV07<signed> : never)
|
|
118
|
+
| (entryPointVersion extends '0.8' ? RpcV08<signed> : never)
|
|
119
|
+
| (entryPointVersion extends '0.9' ? RpcV09<signed> : never)
|
|
113
120
|
>
|
|
114
121
|
|
|
115
122
|
/** Transaction Info. */
|
|
@@ -127,7 +134,18 @@ export type TransactionInfo<
|
|
|
127
134
|
/** RPC Transaction Info. */
|
|
128
135
|
export type RpcTransactionInfo<
|
|
129
136
|
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
130
|
-
> =
|
|
137
|
+
> = {
|
|
138
|
+
/** Block hash containing the User Operation, or `null` while pending. */
|
|
139
|
+
blockHash: Hex.Hex | null
|
|
140
|
+
/** Block number containing the User Operation, or `null` while pending. */
|
|
141
|
+
blockNumber: Hex.Hex | null
|
|
142
|
+
/** EntryPoint that handled the User Operation. */
|
|
143
|
+
entryPoint: Address.Address
|
|
144
|
+
/** Transaction hash containing the User Operation, or `null` while pending. */
|
|
145
|
+
transactionHash: Hex.Hex | null
|
|
146
|
+
/** RPC User Operation included in the transaction. */
|
|
147
|
+
userOperation: Rpc<entryPointVersion>
|
|
148
|
+
}
|
|
131
149
|
|
|
132
150
|
/** Type for User Operation on EntryPoint 0.6 */
|
|
133
151
|
export type V06<signed extends boolean = boolean, bigintType = bigint> = {
|
|
@@ -236,11 +254,32 @@ export type V08<
|
|
|
236
254
|
} & (signed extends true ? { signature: Hex.Hex } : {})
|
|
237
255
|
|
|
238
256
|
/** RPC User Operation on EntryPoint 0.8 */
|
|
239
|
-
export type RpcV08<signed extends boolean = true> =
|
|
240
|
-
signed,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
257
|
+
export type RpcV08<signed extends boolean = true> = Omit<
|
|
258
|
+
V08<signed, Hex.Hex, Hex.Hex>,
|
|
259
|
+
'authorization'
|
|
260
|
+
> & {
|
|
261
|
+
/** EIP-7702 authorization carried by Bundler RPC methods. */
|
|
262
|
+
eip7702Auth?: Authorization.Rpc | undefined
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Type for User Operation on EntryPoint 0.9 */
|
|
266
|
+
export type V09<
|
|
267
|
+
signed extends boolean = boolean,
|
|
268
|
+
bigintType = bigint,
|
|
269
|
+
numberType = number,
|
|
270
|
+
> = V08<signed, bigintType, numberType> & {
|
|
271
|
+
/** Paymaster signature provided independently from account signing. */
|
|
272
|
+
paymasterSignature?: Hex.Hex | undefined
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** RPC User Operation on EntryPoint 0.9 */
|
|
276
|
+
export type RpcV09<signed extends boolean = true> = Omit<
|
|
277
|
+
V09<signed, Hex.Hex, Hex.Hex>,
|
|
278
|
+
'authorization'
|
|
279
|
+
> & {
|
|
280
|
+
/** EIP-7702 authorization carried by Bundler RPC methods. */
|
|
281
|
+
eip7702Auth?: Authorization.Rpc | undefined
|
|
282
|
+
}
|
|
244
283
|
|
|
245
284
|
/**
|
|
246
285
|
* Instantiates a {@link ox#UserOperation.UserOperation} from a provided input.
|
|
@@ -392,26 +431,31 @@ export declare namespace from {
|
|
|
392
431
|
* @param rpc - The RPC user operation to convert.
|
|
393
432
|
* @returns An instantiated {@link ox#UserOperation.UserOperation}.
|
|
394
433
|
*/
|
|
395
|
-
export function fromRpc
|
|
396
|
-
|
|
434
|
+
export function fromRpc<
|
|
435
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
436
|
+
>(rpc: Rpc<entryPointVersion>): UserOperation<entryPointVersion, true> {
|
|
437
|
+
const rpc_ = rpc as Rpc
|
|
438
|
+
const { eip7702Auth, ...userOperation } = rpc_ as Rpc & {
|
|
439
|
+
eip7702Auth?: Authorization.Rpc | undefined
|
|
440
|
+
}
|
|
397
441
|
return {
|
|
398
|
-
...
|
|
399
|
-
callGasLimit: BigInt(
|
|
400
|
-
maxFeePerGas: BigInt(
|
|
401
|
-
maxPriorityFeePerGas: BigInt(
|
|
402
|
-
nonce: BigInt(
|
|
403
|
-
preVerificationGas: BigInt(
|
|
404
|
-
verificationGasLimit: BigInt(
|
|
405
|
-
...(
|
|
406
|
-
paymasterPostOpGasLimit: BigInt(
|
|
442
|
+
...userOperation,
|
|
443
|
+
callGasLimit: BigInt(rpc_.callGasLimit),
|
|
444
|
+
maxFeePerGas: BigInt(rpc_.maxFeePerGas),
|
|
445
|
+
maxPriorityFeePerGas: BigInt(rpc_.maxPriorityFeePerGas),
|
|
446
|
+
nonce: BigInt(rpc_.nonce),
|
|
447
|
+
preVerificationGas: BigInt(rpc_.preVerificationGas),
|
|
448
|
+
verificationGasLimit: BigInt(rpc_.verificationGasLimit),
|
|
449
|
+
...(rpc_.paymasterPostOpGasLimit && {
|
|
450
|
+
paymasterPostOpGasLimit: BigInt(rpc_.paymasterPostOpGasLimit),
|
|
407
451
|
}),
|
|
408
|
-
...(
|
|
409
|
-
paymasterVerificationGasLimit: BigInt(
|
|
452
|
+
...(rpc_.paymasterVerificationGasLimit && {
|
|
453
|
+
paymasterVerificationGasLimit: BigInt(rpc_.paymasterVerificationGasLimit),
|
|
410
454
|
}),
|
|
411
|
-
...(
|
|
412
|
-
authorization: Authorization.fromRpc(
|
|
455
|
+
...(eip7702Auth && {
|
|
456
|
+
authorization: Authorization.fromRpc(eip7702Auth),
|
|
413
457
|
}),
|
|
414
|
-
} as UserOperation
|
|
458
|
+
} as UserOperation<entryPointVersion, true>
|
|
415
459
|
}
|
|
416
460
|
|
|
417
461
|
export declare namespace fromRpc {
|
|
@@ -531,11 +575,11 @@ export function hash<
|
|
|
531
575
|
verificationGasLimit,
|
|
532
576
|
} = userOperation as UserOperation
|
|
533
577
|
|
|
534
|
-
if (entryPointVersion === '0.8') {
|
|
535
|
-
const typedData = toTypedData(
|
|
536
|
-
|
|
537
|
-
entryPointAddress,
|
|
538
|
-
|
|
578
|
+
if (entryPointVersion === '0.8' || entryPointVersion === '0.9') {
|
|
579
|
+
const typedData = toTypedData(
|
|
580
|
+
userOperation as UserOperation<'0.8' | '0.9', true>,
|
|
581
|
+
{ chainId, entryPointAddress },
|
|
582
|
+
)
|
|
539
583
|
return TypedData.getSignPayload(typedData)
|
|
540
584
|
}
|
|
541
585
|
|
|
@@ -699,7 +743,8 @@ export function toInitCode(userOperation: Partial<UserOperation>): Hex.Hex {
|
|
|
699
743
|
* @returns The packed user operation.
|
|
700
744
|
*/
|
|
701
745
|
export function toPacked(
|
|
702
|
-
userOperation: UserOperation<'0.7' | '0.8', true>,
|
|
746
|
+
userOperation: UserOperation<'0.7' | '0.8' | '0.9', true>,
|
|
747
|
+
options: toPacked.Options = {},
|
|
703
748
|
): Packed {
|
|
704
749
|
const {
|
|
705
750
|
callGasLimit,
|
|
@@ -715,6 +760,7 @@ export function toPacked(
|
|
|
715
760
|
signature,
|
|
716
761
|
verificationGasLimit,
|
|
717
762
|
} = userOperation
|
|
763
|
+
const { paymasterSignature } = userOperation as V09<true>
|
|
718
764
|
|
|
719
765
|
const accountGasLimits = packUint128Pair(
|
|
720
766
|
verificationGasLimit || 0n,
|
|
@@ -731,6 +777,15 @@ export function toPacked(
|
|
|
731
777
|
Hex.padLeft(Hex.fromNumber(paymasterVerificationGasLimit || 0n), 16),
|
|
732
778
|
Hex.padLeft(Hex.fromNumber(paymasterPostOpGasLimit || 0n), 16),
|
|
733
779
|
paymasterData || '0x',
|
|
780
|
+
...(paymasterSignature
|
|
781
|
+
? options.forHash
|
|
782
|
+
? [paymasterSignatureMagic]
|
|
783
|
+
: [
|
|
784
|
+
paymasterSignature,
|
|
785
|
+
Hex.padLeft(Hex.fromNumber(Hex.size(paymasterSignature)), 2),
|
|
786
|
+
paymasterSignatureMagic,
|
|
787
|
+
]
|
|
788
|
+
: []),
|
|
734
789
|
)
|
|
735
790
|
: '0x'
|
|
736
791
|
const preVerificationGas = userOperation.preVerificationGas ?? 0n
|
|
@@ -749,6 +804,12 @@ export function toPacked(
|
|
|
749
804
|
}
|
|
750
805
|
|
|
751
806
|
export declare namespace toPacked {
|
|
807
|
+
/** Packing options. */
|
|
808
|
+
export type Options = {
|
|
809
|
+
/** Omits the paymaster signature while retaining its marker. */
|
|
810
|
+
forHash?: boolean | undefined
|
|
811
|
+
}
|
|
812
|
+
|
|
752
813
|
export type ErrorType = Errors.GlobalErrorType
|
|
753
814
|
}
|
|
754
815
|
|
|
@@ -888,54 +949,63 @@ export declare namespace fromPacked {
|
|
|
888
949
|
* @param userOperation - The user operation to convert.
|
|
889
950
|
* @returns An RPC-formatted user operation.
|
|
890
951
|
*/
|
|
891
|
-
export function toRpc
|
|
952
|
+
export function toRpc<
|
|
953
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
954
|
+
>(userOperation: toRpc.Input<entryPointVersion>): Rpc<entryPointVersion> {
|
|
955
|
+
const userOperation_ = userOperation as toRpc.Input
|
|
892
956
|
const rpc = {} as Rpc
|
|
893
957
|
|
|
894
|
-
rpc.callData =
|
|
895
|
-
rpc.callGasLimit = Quantity.fromNumberish(
|
|
896
|
-
rpc.maxFeePerGas = Quantity.fromNumberish(
|
|
958
|
+
rpc.callData = userOperation_.callData
|
|
959
|
+
rpc.callGasLimit = Quantity.fromNumberish(userOperation_.callGasLimit)
|
|
960
|
+
rpc.maxFeePerGas = Quantity.fromNumberish(userOperation_.maxFeePerGas)
|
|
897
961
|
rpc.maxPriorityFeePerGas = Quantity.fromNumberish(
|
|
898
|
-
|
|
962
|
+
userOperation_.maxPriorityFeePerGas,
|
|
899
963
|
)
|
|
900
|
-
rpc.nonce = Quantity.fromNumberish(
|
|
964
|
+
rpc.nonce = Quantity.fromNumberish(userOperation_.nonce)
|
|
901
965
|
rpc.preVerificationGas = Quantity.fromNumberish(
|
|
902
|
-
|
|
966
|
+
userOperation_.preVerificationGas,
|
|
903
967
|
)
|
|
904
|
-
rpc.sender =
|
|
968
|
+
rpc.sender = userOperation_.sender
|
|
905
969
|
rpc.verificationGasLimit = Quantity.fromNumberish(
|
|
906
|
-
|
|
970
|
+
userOperation_.verificationGasLimit,
|
|
907
971
|
)
|
|
908
972
|
|
|
909
|
-
if (
|
|
910
|
-
if (
|
|
911
|
-
if (
|
|
912
|
-
if (
|
|
913
|
-
if (
|
|
914
|
-
rpc.
|
|
915
|
-
if (
|
|
973
|
+
if (userOperation_.factory) rpc.factory = userOperation_.factory
|
|
974
|
+
if (userOperation_.factoryData) rpc.factoryData = userOperation_.factoryData
|
|
975
|
+
if (userOperation_.initCode) rpc.initCode = userOperation_.initCode
|
|
976
|
+
if (userOperation_.paymaster) rpc.paymaster = userOperation_.paymaster
|
|
977
|
+
if (userOperation_.paymasterAndData !== undefined)
|
|
978
|
+
rpc.paymasterAndData = userOperation_.paymasterAndData
|
|
979
|
+
if (userOperation_.paymasterData)
|
|
980
|
+
rpc.paymasterData = userOperation_.paymasterData
|
|
981
|
+
if (userOperation_.paymasterPostOpGasLimit !== undefined)
|
|
916
982
|
rpc.paymasterPostOpGasLimit = Quantity.fromNumberish(
|
|
917
|
-
|
|
983
|
+
userOperation_.paymasterPostOpGasLimit,
|
|
918
984
|
)
|
|
919
|
-
if (
|
|
985
|
+
if (userOperation_.paymasterVerificationGasLimit !== undefined)
|
|
920
986
|
rpc.paymasterVerificationGasLimit = Quantity.fromNumberish(
|
|
921
|
-
|
|
987
|
+
userOperation_.paymasterVerificationGasLimit,
|
|
922
988
|
)
|
|
923
|
-
if (
|
|
989
|
+
if (userOperation_.paymasterSignature)
|
|
990
|
+
rpc.paymasterSignature = userOperation_.paymasterSignature
|
|
991
|
+
if (userOperation_.signature) rpc.signature = userOperation_.signature
|
|
924
992
|
|
|
925
|
-
const authorization = (
|
|
993
|
+
const authorization = (userOperation_ as UserOperation<'0.8' | '0.9', true>)
|
|
926
994
|
.authorization
|
|
927
995
|
if (authorization)
|
|
928
|
-
(rpc as Rpc<'0.8'>).
|
|
996
|
+
(rpc as Rpc<'0.8' | '0.9'>).eip7702Auth = Authorization.toRpc(
|
|
929
997
|
authorization as Authorization.Signed,
|
|
930
|
-
)
|
|
998
|
+
)
|
|
931
999
|
|
|
932
|
-
return rpc
|
|
1000
|
+
return rpc as Rpc<entryPointVersion>
|
|
933
1001
|
}
|
|
934
1002
|
|
|
935
1003
|
export declare namespace toRpc {
|
|
936
1004
|
/** Numberish input accepted by {@link ox#UserOperation.(toRpc:function)}. */
|
|
937
|
-
export type Input
|
|
938
|
-
EntryPoint.Version,
|
|
1005
|
+
export type Input<
|
|
1006
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
1007
|
+
> = UserOperation<
|
|
1008
|
+
entryPointVersion,
|
|
939
1009
|
boolean,
|
|
940
1010
|
Hex.Hex | bigint | number,
|
|
941
1011
|
Hex.Hex | number
|
|
@@ -984,12 +1054,12 @@ export declare namespace toRpc {
|
|
|
984
1054
|
* @returns A Typed Data definition.
|
|
985
1055
|
*/
|
|
986
1056
|
export function toTypedData(
|
|
987
|
-
userOperation: UserOperation<'0.8', true>,
|
|
1057
|
+
userOperation: UserOperation<'0.8' | '0.9', true>,
|
|
988
1058
|
options: toTypedData.Options,
|
|
989
1059
|
): TypedData.Definition<typeof toTypedData.types, 'PackedUserOperation'> {
|
|
990
1060
|
const { chainId, entryPointAddress } = options
|
|
991
1061
|
|
|
992
|
-
const packedUserOp = toPacked(userOperation)
|
|
1062
|
+
const packedUserOp = toPacked(userOperation, { forHash: true })
|
|
993
1063
|
|
|
994
1064
|
return {
|
|
995
1065
|
domain: {
|
|
@@ -11,9 +11,10 @@ export type UserOperationGas<
|
|
|
11
11
|
| (entryPointVersion extends '0.6' ? V06<bigintType> : never)
|
|
12
12
|
| (entryPointVersion extends '0.7' ? V07<bigintType> : never)
|
|
13
13
|
| (entryPointVersion extends '0.8' ? V08<bigintType> : never)
|
|
14
|
+
| (entryPointVersion extends '0.9' ? V09<bigintType> : never)
|
|
14
15
|
>
|
|
15
16
|
|
|
16
|
-
/** RPC User Operation Gas
|
|
17
|
+
/** RPC User Operation Gas. */
|
|
17
18
|
export type Rpc<
|
|
18
19
|
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
19
20
|
> = UserOperationGas<entryPointVersion, Hex.Hex>
|
|
@@ -46,6 +47,12 @@ export type V08<bigintType = bigint> = V07<bigintType>
|
|
|
46
47
|
/** RPC User Operation Gas on EntryPoint 0.8 */
|
|
47
48
|
export type RpcV08 = V08<Hex.Hex>
|
|
48
49
|
|
|
50
|
+
/** Type for User Operation Gas on EntryPoint 0.9 */
|
|
51
|
+
export type V09<bigintType = bigint> = V08<bigintType>
|
|
52
|
+
|
|
53
|
+
/** RPC User Operation Gas on EntryPoint 0.9 */
|
|
54
|
+
export type RpcV09 = V09<Hex.Hex>
|
|
55
|
+
|
|
49
56
|
/**
|
|
50
57
|
* Converts an {@link ox#UserOperationGas.Rpc} to an {@link ox#UserOperationGas.UserOperationGas}.
|
|
51
58
|
*
|
|
@@ -63,19 +70,22 @@ export type RpcV08 = V08<Hex.Hex>
|
|
|
63
70
|
* @param rpc - The RPC user operation gas to convert.
|
|
64
71
|
* @returns An instantiated {@link ox#UserOperationGas.UserOperationGas}.
|
|
65
72
|
*/
|
|
66
|
-
export function fromRpc
|
|
73
|
+
export function fromRpc<
|
|
74
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
75
|
+
>(rpc: Rpc<entryPointVersion>): UserOperationGas<entryPointVersion> {
|
|
76
|
+
const gas = rpc as Rpc
|
|
67
77
|
return {
|
|
68
|
-
...
|
|
69
|
-
callGasLimit: BigInt(
|
|
70
|
-
preVerificationGas: BigInt(
|
|
71
|
-
verificationGasLimit: BigInt(
|
|
72
|
-
...(
|
|
73
|
-
paymasterVerificationGasLimit: BigInt(
|
|
78
|
+
...gas,
|
|
79
|
+
callGasLimit: BigInt(gas.callGasLimit),
|
|
80
|
+
preVerificationGas: BigInt(gas.preVerificationGas),
|
|
81
|
+
verificationGasLimit: BigInt(gas.verificationGasLimit),
|
|
82
|
+
...(gas.paymasterVerificationGasLimit && {
|
|
83
|
+
paymasterVerificationGasLimit: BigInt(gas.paymasterVerificationGasLimit),
|
|
74
84
|
}),
|
|
75
|
-
...(
|
|
76
|
-
paymasterPostOpGasLimit: BigInt(
|
|
85
|
+
...(gas.paymasterPostOpGasLimit && {
|
|
86
|
+
paymasterPostOpGasLimit: BigInt(gas.paymasterPostOpGasLimit),
|
|
77
87
|
}),
|
|
78
|
-
} as UserOperationGas
|
|
88
|
+
} as UserOperationGas<entryPointVersion>
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
/**
|
|
@@ -95,33 +105,31 @@ export function fromRpc(rpc: Rpc): UserOperationGas {
|
|
|
95
105
|
* @param userOperationGas - The user operation gas to convert.
|
|
96
106
|
* @returns An RPC-formatted user operation gas.
|
|
97
107
|
*/
|
|
98
|
-
export function toRpc
|
|
108
|
+
export function toRpc<
|
|
109
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
110
|
+
>(userOperationGas: toRpc.Input<entryPointVersion>): Rpc<entryPointVersion> {
|
|
111
|
+
const gas = userOperationGas as toRpc.Input
|
|
99
112
|
const rpc = {} as Rpc
|
|
100
113
|
|
|
101
|
-
rpc.callGasLimit = Quantity.fromNumberish(
|
|
102
|
-
rpc.preVerificationGas = Quantity.fromNumberish(
|
|
103
|
-
|
|
104
|
-
)
|
|
105
|
-
rpc.verificationGasLimit = Quantity.fromNumberish(
|
|
106
|
-
userOperationGas.verificationGasLimit,
|
|
107
|
-
)
|
|
114
|
+
rpc.callGasLimit = Quantity.fromNumberish(gas.callGasLimit)
|
|
115
|
+
rpc.preVerificationGas = Quantity.fromNumberish(gas.preVerificationGas)
|
|
116
|
+
rpc.verificationGasLimit = Quantity.fromNumberish(gas.verificationGasLimit)
|
|
108
117
|
|
|
109
|
-
if (
|
|
118
|
+
if (gas.paymasterVerificationGasLimit !== undefined)
|
|
110
119
|
rpc.paymasterVerificationGasLimit = Quantity.fromNumberish(
|
|
111
|
-
|
|
120
|
+
gas.paymasterVerificationGasLimit,
|
|
112
121
|
)
|
|
113
|
-
if (
|
|
122
|
+
if (gas.paymasterPostOpGasLimit !== undefined)
|
|
114
123
|
rpc.paymasterPostOpGasLimit = Quantity.fromNumberish(
|
|
115
|
-
|
|
124
|
+
gas.paymasterPostOpGasLimit,
|
|
116
125
|
)
|
|
117
126
|
|
|
118
|
-
return rpc
|
|
127
|
+
return rpc as Rpc<entryPointVersion>
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
export declare namespace toRpc {
|
|
122
131
|
/** Numberish input accepted by {@link ox#UserOperationGas.(toRpc:function)}. */
|
|
123
|
-
export type Input
|
|
124
|
-
EntryPoint.Version,
|
|
125
|
-
|
|
126
|
-
>
|
|
132
|
+
export type Input<
|
|
133
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
134
|
+
> = UserOperationGas<entryPointVersion, Hex.Hex | bigint | number>
|
|
127
135
|
}
|
|
@@ -45,7 +45,7 @@ export type UserOperationReceipt<
|
|
|
45
45
|
userOpHash: Hex.Hex
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/** RPC User Operation Receipt
|
|
48
|
+
/** RPC User Operation Receipt. */
|
|
49
49
|
export type Rpc<
|
|
50
50
|
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
51
51
|
> = UserOperationReceipt<
|
|
@@ -84,7 +84,9 @@ export type Rpc<
|
|
|
84
84
|
* @param rpc - The RPC user operation receipt to convert.
|
|
85
85
|
* @returns An instantiated {@link ox#UserOperationReceipt.UserOperationReceipt}.
|
|
86
86
|
*/
|
|
87
|
-
export function fromRpc
|
|
87
|
+
export function fromRpc<
|
|
88
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
89
|
+
>(rpc: Rpc<entryPointVersion>): UserOperationReceipt<entryPointVersion> {
|
|
88
90
|
return {
|
|
89
91
|
...rpc,
|
|
90
92
|
actualGasCost: BigInt(rpc.actualGasCost),
|
|
@@ -92,7 +94,7 @@ export function fromRpc(rpc: Rpc): UserOperationReceipt {
|
|
|
92
94
|
logs: rpc.logs.map((log) => Log.fromRpc(log)),
|
|
93
95
|
nonce: BigInt(rpc.nonce),
|
|
94
96
|
receipt: TransactionReceipt.fromRpc(rpc.receipt),
|
|
95
|
-
} as UserOperationReceipt
|
|
97
|
+
} as UserOperationReceipt<entryPointVersion>
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
/**
|
|
@@ -119,7 +121,11 @@ export function fromRpc(rpc: Rpc): UserOperationReceipt {
|
|
|
119
121
|
* @param userOperationReceipt - The user operation receipt to convert.
|
|
120
122
|
* @returns An RPC-formatted user operation receipt.
|
|
121
123
|
*/
|
|
122
|
-
export function toRpc
|
|
124
|
+
export function toRpc<
|
|
125
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
126
|
+
>(
|
|
127
|
+
userOperationReceipt: toRpc.Input<entryPointVersion>,
|
|
128
|
+
): Rpc<entryPointVersion> {
|
|
123
129
|
const rpc = {} as Rpc
|
|
124
130
|
|
|
125
131
|
rpc.actualGasCost = Quantity.fromNumberish(userOperationReceipt.actualGasCost)
|
|
@@ -136,13 +142,15 @@ export function toRpc(userOperationReceipt: toRpc.Input): Rpc {
|
|
|
136
142
|
rpc.paymaster = userOperationReceipt.paymaster
|
|
137
143
|
if (userOperationReceipt.reason) rpc.reason = userOperationReceipt.reason
|
|
138
144
|
|
|
139
|
-
return rpc
|
|
145
|
+
return rpc as Rpc<entryPointVersion>
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
export declare namespace toRpc {
|
|
143
149
|
/** Numberish input accepted by {@link ox#UserOperationReceipt.(toRpc:function)}. */
|
|
144
|
-
export type Input
|
|
145
|
-
EntryPoint.Version,
|
|
150
|
+
export type Input<
|
|
151
|
+
entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
|
|
152
|
+
> = UserOperationReceipt<
|
|
153
|
+
entryPointVersion,
|
|
146
154
|
Hex.Hex | bigint | number,
|
|
147
155
|
Hex.Hex | number
|
|
148
156
|
>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { EntryPoint } from 'ox/erc4337'
|
|
2
|
+
import { describe, expect, test } from 'vp/test'
|
|
3
|
+
|
|
4
|
+
describe('abiV09', () => {
|
|
5
|
+
test('default', () => {
|
|
6
|
+
const names = new Set([
|
|
7
|
+
'EIP7702AccountInitialized',
|
|
8
|
+
'IgnoredInitCode',
|
|
9
|
+
'InvalidPaymasterSignatureLength',
|
|
10
|
+
'getCurrentUserOpHash',
|
|
11
|
+
])
|
|
12
|
+
|
|
13
|
+
expect(
|
|
14
|
+
EntryPoint.abiV09
|
|
15
|
+
.filter((item) => 'name' in item && names.has(item.name))
|
|
16
|
+
.map((item) =>
|
|
17
|
+
'name' in item ? { name: item.name, type: item.type } : item,
|
|
18
|
+
),
|
|
19
|
+
).toMatchInlineSnapshot(`
|
|
20
|
+
[
|
|
21
|
+
{
|
|
22
|
+
"name": "InvalidPaymasterSignatureLength",
|
|
23
|
+
"type": "error",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "EIP7702AccountInitialized",
|
|
27
|
+
"type": "event",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "IgnoredInitCode",
|
|
31
|
+
"type": "event",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "getCurrentUserOpHash",
|
|
35
|
+
"type": "function",
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
`)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('addressV09', () => {
|
|
43
|
+
test('default', () => {
|
|
44
|
+
expect(EntryPoint.addressV09).toMatchInlineSnapshot(
|
|
45
|
+
`"0x433709009B8330FDa32311DF1C2AFA402eD8D009"`,
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
})
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Address, type Hex, RpcSchema as CoreRpcSchema } from 'ox'
|
|
2
|
+
import {
|
|
3
|
+
RpcSchema,
|
|
4
|
+
UserOperation,
|
|
5
|
+
UserOperationGas,
|
|
6
|
+
UserOperationReceipt,
|
|
7
|
+
} from 'ox/erc4337'
|
|
8
|
+
import { expectTypeOf, test } from 'vp/test'
|
|
9
|
+
|
|
10
|
+
test('Bundler: EntryPoint 0.9 methods', () => {
|
|
11
|
+
type Schema = RpcSchema.Bundler<'0.9'>
|
|
12
|
+
|
|
13
|
+
type Estimate = CoreRpcSchema.ExtractReturnType<
|
|
14
|
+
Schema,
|
|
15
|
+
'eth_estimateUserOperationGas'
|
|
16
|
+
>
|
|
17
|
+
expectTypeOf<Estimate>().toEqualTypeOf<UserOperationGas.Rpc<'0.9'>>()
|
|
18
|
+
|
|
19
|
+
type Receipt = CoreRpcSchema.ExtractReturnType<
|
|
20
|
+
Schema,
|
|
21
|
+
'eth_getUserOperationReceipt'
|
|
22
|
+
>
|
|
23
|
+
expectTypeOf<Receipt>().toEqualTypeOf<UserOperationReceipt.Rpc<'0.9'> | null>()
|
|
24
|
+
|
|
25
|
+
type Send = CoreRpcSchema.ExtractParams<Schema, 'eth_sendUserOperation'>
|
|
26
|
+
expectTypeOf<Send>().toEqualTypeOf<
|
|
27
|
+
[userOperation: UserOperation.Rpc<'0.9'>, entrypoint: Address.Address]
|
|
28
|
+
>()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('Bundler: eth_getUserOperationByHash result', () => {
|
|
32
|
+
type Result = CoreRpcSchema.ExtractReturnType<
|
|
33
|
+
RpcSchema.Bundler<'0.9'>,
|
|
34
|
+
'eth_getUserOperationByHash'
|
|
35
|
+
>
|
|
36
|
+
type Info = Exclude<Result, null>
|
|
37
|
+
|
|
38
|
+
expectTypeOf<Result>().toEqualTypeOf<UserOperation.RpcTransactionInfo<'0.9'> | null>()
|
|
39
|
+
expectTypeOf<Info['blockHash']>().toEqualTypeOf<Hex.Hex | null>()
|
|
40
|
+
expectTypeOf<Info['blockNumber']>().toEqualTypeOf<Hex.Hex | null>()
|
|
41
|
+
expectTypeOf<Info['transactionHash']>().toEqualTypeOf<Hex.Hex | null>()
|
|
42
|
+
expectTypeOf<Info['userOperation']>().toEqualTypeOf<
|
|
43
|
+
UserOperation.Rpc<'0.9'>
|
|
44
|
+
>()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('BundlerDebug: EntryPoint 0.9 mempool', () => {
|
|
48
|
+
type Result = CoreRpcSchema.ExtractReturnType<
|
|
49
|
+
RpcSchema.BundlerDebug<'0.9'>,
|
|
50
|
+
'debug_bundler_dumpMempool'
|
|
51
|
+
>
|
|
52
|
+
|
|
53
|
+
expectTypeOf<Result>().toEqualTypeOf<
|
|
54
|
+
readonly { userOp: UserOperation.Rpc<'0.9'> }[]
|
|
55
|
+
>()
|
|
56
|
+
})
|
|
@@ -54,3 +54,34 @@ describe('from', () => {
|
|
|
54
54
|
}`)
|
|
55
55
|
})
|
|
56
56
|
})
|
|
57
|
+
|
|
58
|
+
describe('v0.9', () => {
|
|
59
|
+
test('RPC round-trip', () => {
|
|
60
|
+
const rpc = {
|
|
61
|
+
callData: '0xdeadbeef',
|
|
62
|
+
callGasLimit: '0x0',
|
|
63
|
+
eip7702Auth: {
|
|
64
|
+
address: '0x1234567890123456789012345678901234567890',
|
|
65
|
+
chainId: '0x1',
|
|
66
|
+
nonce: '0x0',
|
|
67
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
68
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
69
|
+
yParity: '0x0',
|
|
70
|
+
},
|
|
71
|
+
maxFeePerGas: '0x0',
|
|
72
|
+
maxPriorityFeePerGas: '0x0',
|
|
73
|
+
nonce: '0x0',
|
|
74
|
+
paymasterSignature: '0xcafebabe',
|
|
75
|
+
preVerificationGas: '0x0',
|
|
76
|
+
sender: '0x1234567890123456789012345678901234567890',
|
|
77
|
+
signature: '0x',
|
|
78
|
+
verificationGasLimit: '0x0',
|
|
79
|
+
} as const satisfies UserOperation.Rpc<'0.9'>
|
|
80
|
+
|
|
81
|
+
const userOperation = UserOperation.fromRpc(rpc)
|
|
82
|
+
const rpc_roundTrip = UserOperation.toRpc(userOperation)
|
|
83
|
+
|
|
84
|
+
attest<UserOperation.UserOperation<'0.9', true>, typeof userOperation>()
|
|
85
|
+
attest<UserOperation.Rpc<'0.9'>, typeof rpc_roundTrip>()
|
|
86
|
+
})
|
|
87
|
+
})
|