@aastar/sdk 0.18.0 → 0.20.1
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/LICENSE +180 -21
- package/dist/UserClient-YUHCJJJL.js +6 -0
- package/dist/UserClient-YUHCJJJL.js.map +1 -0
- package/dist/account.d.ts +1 -0
- package/dist/account.js +6 -0
- package/dist/account.js.map +1 -0
- package/dist/admin.d.ts +1 -0
- package/dist/admin.js +6 -0
- package/dist/admin.js.map +1 -0
- package/dist/airaccount.d.ts +2 -0
- package/dist/airaccount.js +4501 -0
- package/dist/airaccount.js.map +1 -0
- package/dist/channel.d.ts +1 -0
- package/dist/channel.js +6 -0
- package/dist/channel.js.map +1 -0
- package/dist/chunk-4DVUM4MC.js +106 -0
- package/dist/chunk-4DVUM4MC.js.map +1 -0
- package/dist/chunk-4KRQXOTI.js +4421 -0
- package/dist/chunk-4KRQXOTI.js.map +1 -0
- package/dist/chunk-6JCYPTSH.js +281 -0
- package/dist/chunk-6JCYPTSH.js.map +1 -0
- package/dist/chunk-DI3E6PMI.js +426 -0
- package/dist/chunk-DI3E6PMI.js.map +1 -0
- package/dist/chunk-DSZ372PH.js +333 -0
- package/dist/chunk-DSZ372PH.js.map +1 -0
- package/dist/chunk-HVAB4TTT.js +116 -0
- package/dist/chunk-HVAB4TTT.js.map +1 -0
- package/dist/chunk-MPOMWT2J.js +1140 -0
- package/dist/chunk-MPOMWT2J.js.map +1 -0
- package/dist/chunk-NZGXB2C5.js +115 -0
- package/dist/chunk-NZGXB2C5.js.map +1 -0
- package/dist/chunk-O3Y7II3B.js +578 -0
- package/dist/chunk-O3Y7II3B.js.map +1 -0
- package/dist/chunk-OSPRJZ5T.js +113 -0
- package/dist/chunk-OSPRJZ5T.js.map +1 -0
- package/dist/chunk-PCLPYRTX.js +229 -0
- package/dist/chunk-PCLPYRTX.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-XFI3AK32.js +416 -0
- package/dist/chunk-XFI3AK32.js.map +1 -0
- package/dist/chunk-YHM77LIP.js +432 -0
- package/dist/chunk-YHM77LIP.js.map +1 -0
- package/dist/chunk-ZSSNU3UF.js +42091 -0
- package/dist/chunk-ZSSNU3UF.js.map +1 -0
- package/dist/contract-addresses-JE3X6DFY.js +4 -0
- package/dist/contract-addresses-JE3X6DFY.js.map +1 -0
- package/dist/core.d.ts +13 -0
- package/dist/core.js +5 -0
- package/dist/core.js.map +1 -0
- package/dist/dapp.d.ts +1 -0
- package/dist/dapp.js +7 -0
- package/dist/dapp.js.map +1 -0
- package/dist/dist-GHTBO7CD.js +6 -0
- package/dist/dist-GHTBO7CD.js.map +1 -0
- package/dist/enduser.d.ts +1 -0
- package/dist/enduser.js +7 -0
- package/dist/enduser.js.map +1 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.js +6 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +601 -12
- package/dist/index.js +1640 -28
- package/dist/index.js.map +1 -0
- package/dist/index.node-55LOPHNQ.js +5 -0
- package/dist/index.node-55LOPHNQ.js.map +1 -0
- package/dist/lib-VRTYVDUO.js +1861 -0
- package/dist/lib-VRTYVDUO.js.map +1 -0
- package/dist/operator.d.ts +1 -0
- package/dist/operator.js +6 -0
- package/dist/operator.js.map +1 -0
- package/dist/paymaster.d.ts +1 -0
- package/dist/paymaster.js +6 -0
- package/dist/paymaster.js.map +1 -0
- package/dist/tokens.d.ts +1 -0
- package/dist/tokens.js +6 -0
- package/dist/tokens.js.map +1 -0
- package/dist/x402.d.ts +1 -0
- package/dist/x402.js +6 -0
- package/dist/x402.js.map +1 -0
- package/package.json +87 -18
- package/dist/clients/ExperimentClient.d.ts +0 -34
- package/dist/clients/ExperimentClient.js +0 -58
- package/dist/clients/admin.d.ts +0 -11
- package/dist/clients/admin.js +0 -20
- package/dist/clients/community.d.ts +0 -40
- package/dist/clients/community.js +0 -300
- package/dist/clients/endUser.d.ts +0 -77
- package/dist/clients/endUser.js +0 -298
- package/dist/clients/operator.d.ts +0 -66
- package/dist/clients/operator.js +0 -209
- package/dist/errors/decoder.d.ts +0 -6
- package/dist/errors/decoder.js +0 -44
- package/dist/utils/errorHandler.d.ts +0 -40
- package/dist/utils/errorHandler.js +0 -114
- package/dist/utils/funding.d.ts +0 -115
- package/dist/utils/funding.js +0 -188
- package/dist/utils/keys.d.ts +0 -61
- package/dist/utils/keys.js +0 -130
- package/dist/utils/roleData.d.ts +0 -66
- package/dist/utils/roleData.js +0 -128
- package/dist/utils/testScenarios.d.ts +0 -33
- package/dist/utils/testScenarios.js +0 -85
- package/dist/utils/userOp.d.ts +0 -89
- package/dist/utils/userOp.js +0 -231
package/dist/utils/roleData.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type Hex, type Address } from 'viem';
|
|
2
|
-
export declare const RoleIds: {
|
|
3
|
-
readonly PAYMASTER_SUPER: `0x${string}`;
|
|
4
|
-
readonly DVT: `0x${string}`;
|
|
5
|
-
readonly PAYMASTER_AOA: `0x${string}`;
|
|
6
|
-
readonly KMS: `0x${string}`;
|
|
7
|
-
readonly COMMUNITY: `0x${string}`;
|
|
8
|
-
readonly ENDUSER: `0x${string}`;
|
|
9
|
-
readonly ANODE: `0x${string}`;
|
|
10
|
-
};
|
|
11
|
-
export type RoleId = typeof RoleIds[keyof typeof RoleIds];
|
|
12
|
-
export declare const RoleDataFactory: {
|
|
13
|
-
/**
|
|
14
|
-
* Data for SuperPaymaster Operator (Empty)
|
|
15
|
-
*/
|
|
16
|
-
paymasterSuper: () => Hex;
|
|
17
|
-
/**
|
|
18
|
-
* Data for Generic DVT Role (Empty)
|
|
19
|
-
*/
|
|
20
|
-
dvt: () => Hex;
|
|
21
|
-
/**
|
|
22
|
-
* Data for Community Registration (matches Registry.sol CommunityRoleData)
|
|
23
|
-
* NOTE: Solidity's abi.encode(struct) adds a 32-byte offset prefix (0x20)
|
|
24
|
-
* which is required for abi.decode(struct) to work correctly.
|
|
25
|
-
*
|
|
26
|
-
* @param params.name Community Name (defaults to 'TestCommunity')
|
|
27
|
-
* @param params.ensName ENS name (optional)
|
|
28
|
-
* @param params.website Website URL (optional)
|
|
29
|
-
* @param params.description Community description (optional)
|
|
30
|
-
* @param params.logoURI Logo URI string (optional)
|
|
31
|
-
* @param params.stakeAmount Stake amount (defaults to 0)
|
|
32
|
-
*/
|
|
33
|
-
community: (params?: {
|
|
34
|
-
name?: string;
|
|
35
|
-
ensName?: string;
|
|
36
|
-
website?: string;
|
|
37
|
-
description?: string;
|
|
38
|
-
logoURI?: string;
|
|
39
|
-
stakeAmount?: bigint;
|
|
40
|
-
}) => Hex;
|
|
41
|
-
/**
|
|
42
|
-
* Data for EndUser (matches Registry.sol EndUserRoleData)
|
|
43
|
-
*/
|
|
44
|
-
endUser: (params?: {
|
|
45
|
-
account?: Address;
|
|
46
|
-
community?: Address;
|
|
47
|
-
avatarURI?: string;
|
|
48
|
-
ensName?: string;
|
|
49
|
-
stakeAmount?: bigint;
|
|
50
|
-
}) => Hex;
|
|
51
|
-
decodeCommunity: (data: Hex) => {
|
|
52
|
-
name: any;
|
|
53
|
-
ensName: any;
|
|
54
|
-
website: any;
|
|
55
|
-
description: any;
|
|
56
|
-
logoURI: any;
|
|
57
|
-
stakeAmount: any;
|
|
58
|
-
};
|
|
59
|
-
decodeEndUser: (data: Hex) => {
|
|
60
|
-
account: any;
|
|
61
|
-
community: any;
|
|
62
|
-
avatarURI: any;
|
|
63
|
-
ensName: any;
|
|
64
|
-
stakeAmount: any;
|
|
65
|
-
};
|
|
66
|
-
};
|
package/dist/utils/roleData.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { keccak256, stringToBytes, encodeAbiParameters, decodeAbiParameters, zeroAddress } from 'viem';
|
|
2
|
-
export const RoleIds = {
|
|
3
|
-
PAYMASTER_SUPER: keccak256(stringToBytes('PAYMASTER_SUPER')),
|
|
4
|
-
DVT: keccak256(stringToBytes('DVT')), // Replaced PAYMASTER
|
|
5
|
-
PAYMASTER_AOA: keccak256(stringToBytes('PAYMASTER_AOA')),
|
|
6
|
-
KMS: keccak256(stringToBytes('KMS')),
|
|
7
|
-
COMMUNITY: keccak256(stringToBytes('COMMUNITY')),
|
|
8
|
-
ENDUSER: keccak256(stringToBytes('ENDUSER')),
|
|
9
|
-
ANODE: keccak256(stringToBytes('ANODE'))
|
|
10
|
-
};
|
|
11
|
-
export const RoleDataFactory = {
|
|
12
|
-
/**
|
|
13
|
-
* Data for SuperPaymaster Operator (Empty)
|
|
14
|
-
*/
|
|
15
|
-
paymasterSuper: () => '0x',
|
|
16
|
-
/**
|
|
17
|
-
* Data for Generic DVT Role (Empty)
|
|
18
|
-
*/
|
|
19
|
-
dvt: () => '0x',
|
|
20
|
-
/**
|
|
21
|
-
* Data for Community Registration (matches Registry.sol CommunityRoleData)
|
|
22
|
-
* NOTE: Solidity's abi.encode(struct) adds a 32-byte offset prefix (0x20)
|
|
23
|
-
* which is required for abi.decode(struct) to work correctly.
|
|
24
|
-
*
|
|
25
|
-
* @param params.name Community Name (defaults to 'TestCommunity')
|
|
26
|
-
* @param params.ensName ENS name (optional)
|
|
27
|
-
* @param params.website Website URL (optional)
|
|
28
|
-
* @param params.description Community description (optional)
|
|
29
|
-
* @param params.logoURI Logo URI string (optional)
|
|
30
|
-
* @param params.stakeAmount Stake amount (defaults to 0)
|
|
31
|
-
*/
|
|
32
|
-
community: (params) => {
|
|
33
|
-
return encodeAbiParameters([{
|
|
34
|
-
type: 'tuple',
|
|
35
|
-
components: [
|
|
36
|
-
{ name: 'name', type: 'string' },
|
|
37
|
-
{ name: 'ensName', type: 'string' },
|
|
38
|
-
{ name: 'website', type: 'string' },
|
|
39
|
-
{ name: 'description', type: 'string' },
|
|
40
|
-
{ name: 'logoURI', type: 'string' },
|
|
41
|
-
{ name: 'stakeAmount', type: 'uint256' }
|
|
42
|
-
]
|
|
43
|
-
}], [[
|
|
44
|
-
params?.name || 'TestCommunity',
|
|
45
|
-
params?.ensName || '',
|
|
46
|
-
params?.website || '',
|
|
47
|
-
params?.description || '',
|
|
48
|
-
params?.logoURI || '',
|
|
49
|
-
params?.stakeAmount || 0n
|
|
50
|
-
]]);
|
|
51
|
-
},
|
|
52
|
-
/**
|
|
53
|
-
* Data for EndUser (matches Registry.sol EndUserRoleData)
|
|
54
|
-
*/
|
|
55
|
-
endUser: (params) => {
|
|
56
|
-
return encodeAbiParameters([{
|
|
57
|
-
type: 'tuple',
|
|
58
|
-
components: [
|
|
59
|
-
{ name: 'account', type: 'address' },
|
|
60
|
-
{ name: 'community', type: 'address' },
|
|
61
|
-
{ name: 'avatarURI', type: 'string' },
|
|
62
|
-
{ name: 'ensName', type: 'string' },
|
|
63
|
-
{ name: 'stakeAmount', type: 'uint256' }
|
|
64
|
-
]
|
|
65
|
-
}], [[
|
|
66
|
-
params?.account || zeroAddress,
|
|
67
|
-
params?.community || zeroAddress,
|
|
68
|
-
params?.avatarURI || '',
|
|
69
|
-
params?.ensName || '',
|
|
70
|
-
params?.stakeAmount || 0n
|
|
71
|
-
]]);
|
|
72
|
-
},
|
|
73
|
-
decodeCommunity: (data) => {
|
|
74
|
-
const decoded = decodeAbiParameters([{
|
|
75
|
-
type: 'tuple',
|
|
76
|
-
components: [
|
|
77
|
-
{ name: 'name', type: 'string' },
|
|
78
|
-
{ name: 'ensName', type: 'string' },
|
|
79
|
-
{ name: 'website', type: 'string' },
|
|
80
|
-
{ name: 'description', type: 'string' },
|
|
81
|
-
{ name: 'logoURI', type: 'string' },
|
|
82
|
-
{ name: 'stakeAmount', type: 'uint256' }
|
|
83
|
-
]
|
|
84
|
-
}], data);
|
|
85
|
-
const result = decoded[0];
|
|
86
|
-
// Check if result is array (iterable) or object
|
|
87
|
-
if (Array.isArray(result)) {
|
|
88
|
-
const [n, e, w, d, l, s] = result;
|
|
89
|
-
return { name: n, ensName: e, website: w, description: d, logoURI: l, stakeAmount: s };
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return {
|
|
93
|
-
name: result.name,
|
|
94
|
-
ensName: result.ensName,
|
|
95
|
-
website: result.website,
|
|
96
|
-
description: result.description,
|
|
97
|
-
logoURI: result.logoURI,
|
|
98
|
-
stakeAmount: result.stakeAmount
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
decodeEndUser: (data) => {
|
|
103
|
-
const decoded = decodeAbiParameters([{
|
|
104
|
-
type: 'tuple',
|
|
105
|
-
components: [
|
|
106
|
-
{ name: 'account', type: 'address' },
|
|
107
|
-
{ name: 'community', type: 'address' },
|
|
108
|
-
{ name: 'avatarURI', type: 'string' },
|
|
109
|
-
{ name: 'ensName', type: 'string' },
|
|
110
|
-
{ name: 'stakeAmount', type: 'uint256' }
|
|
111
|
-
]
|
|
112
|
-
}], data);
|
|
113
|
-
const result = decoded[0];
|
|
114
|
-
if (Array.isArray(result)) {
|
|
115
|
-
const [a, c, av, en, s] = result;
|
|
116
|
-
return { account: a, community: c, avatarURI: av, ensName: en, stakeAmount: s };
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return {
|
|
120
|
-
account: result.account,
|
|
121
|
-
community: result.community,
|
|
122
|
-
avatarURI: result.avatarURI,
|
|
123
|
-
ensName: result.ensName,
|
|
124
|
-
stakeAmount: result.stakeAmount
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type Address, type Hash, type PublicClient } from 'viem';
|
|
2
|
-
export declare enum UserOpScenarioType {
|
|
3
|
-
NATIVE = "NATIVE",// Plain ERC-4337, user pays ETH
|
|
4
|
-
GASLESS_V4 = "GASLESS_V4",// Standard PaymasterV4
|
|
5
|
-
SUPER_BPNT = "SUPER_BPNT",// SuperPaymaster with bPNT internal payment
|
|
6
|
-
SUPER_CPNT = "SUPER_CPNT",// SuperPaymaster with cPNT internal payment
|
|
7
|
-
SUPER_CUSTOM = "SUPER_CUSTOM"
|
|
8
|
-
}
|
|
9
|
-
export interface ScenarioParams {
|
|
10
|
-
sender: Address;
|
|
11
|
-
ownerAccount: any;
|
|
12
|
-
recipient: Address;
|
|
13
|
-
tokenAddress: Address;
|
|
14
|
-
amount: bigint;
|
|
15
|
-
entryPoint: Address;
|
|
16
|
-
chainId: number;
|
|
17
|
-
publicClient: PublicClient;
|
|
18
|
-
paymaster?: Address;
|
|
19
|
-
operator?: Address;
|
|
20
|
-
paymasterGasLimit?: bigint;
|
|
21
|
-
paymasterPostOpGasLimit?: bigint;
|
|
22
|
-
nonceKey?: bigint;
|
|
23
|
-
gasToken?: Address;
|
|
24
|
-
}
|
|
25
|
-
export declare class UserOpScenarioBuilder {
|
|
26
|
-
/**
|
|
27
|
-
* Builds a signed PackedUserOperation for a token transfer based on the specified scenario.
|
|
28
|
-
*/
|
|
29
|
-
static buildTransferScenario(type: UserOpScenarioType, params: ScenarioParams): Promise<{
|
|
30
|
-
userOp: any;
|
|
31
|
-
opHash: Hash;
|
|
32
|
-
}>;
|
|
33
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { encodeFunctionData } from 'viem';
|
|
2
|
-
import { UserOperationBuilder } from './userOp.js';
|
|
3
|
-
export var UserOpScenarioType;
|
|
4
|
-
(function (UserOpScenarioType) {
|
|
5
|
-
UserOpScenarioType["NATIVE"] = "NATIVE";
|
|
6
|
-
UserOpScenarioType["GASLESS_V4"] = "GASLESS_V4";
|
|
7
|
-
UserOpScenarioType["SUPER_BPNT"] = "SUPER_BPNT";
|
|
8
|
-
UserOpScenarioType["SUPER_CPNT"] = "SUPER_CPNT";
|
|
9
|
-
UserOpScenarioType["SUPER_CUSTOM"] = "SUPER_CUSTOM"; // SuperPaymaster with custom token/operator
|
|
10
|
-
})(UserOpScenarioType || (UserOpScenarioType = {}));
|
|
11
|
-
export class UserOpScenarioBuilder {
|
|
12
|
-
/**
|
|
13
|
-
* Builds a signed PackedUserOperation for a token transfer based on the specified scenario.
|
|
14
|
-
*/
|
|
15
|
-
static async buildTransferScenario(type, params) {
|
|
16
|
-
const { sender, ownerAccount, recipient, tokenAddress, amount, entryPoint, chainId, publicClient, paymaster, operator, paymasterGasLimit = 100000n, paymasterPostOpGasLimit = 40000n, nonceKey = 0n, gasToken } = params;
|
|
17
|
-
// 1. Build Token Transfer CallData
|
|
18
|
-
const transferData = encodeFunctionData({
|
|
19
|
-
abi: [{ name: 'transfer', type: 'function', inputs: [{ type: 'address', name: 'to' }, { type: 'uint256', name: 'amount' }], outputs: [{ type: 'bool' }] }],
|
|
20
|
-
functionName: 'transfer',
|
|
21
|
-
args: [recipient, amount]
|
|
22
|
-
});
|
|
23
|
-
// 2. Build AA Execute CallData (Assuming SimpleAccount execute)
|
|
24
|
-
const callData = encodeFunctionData({
|
|
25
|
-
abi: [{ name: 'execute', type: 'function', inputs: [{ type: 'address' }, { type: 'uint256' }, { type: 'bytes' }] }],
|
|
26
|
-
functionName: 'execute',
|
|
27
|
-
args: [tokenAddress, 0n, transferData]
|
|
28
|
-
});
|
|
29
|
-
// 3. Build Base UserOperation
|
|
30
|
-
const userOp = {
|
|
31
|
-
sender,
|
|
32
|
-
nonce: await publicClient.readContract({
|
|
33
|
-
address: entryPoint,
|
|
34
|
-
abi: [{ name: 'getNonce', type: 'function', inputs: [{ type: 'address' }, { type: 'uint192' }], outputs: [{ type: 'uint256' }] }],
|
|
35
|
-
functionName: 'getNonce',
|
|
36
|
-
args: [sender, nonceKey]
|
|
37
|
-
}),
|
|
38
|
-
initCode: '0x',
|
|
39
|
-
callData,
|
|
40
|
-
accountGasLimits: UserOperationBuilder.packAccountGasLimits(type === UserOpScenarioType.NATIVE ? 75000n : 250000n, 150000n),
|
|
41
|
-
preVerificationGas: 80000n,
|
|
42
|
-
gasFees: UserOperationBuilder.packGasFees(2000000000n, 2000000000n), // 2 Gwei
|
|
43
|
-
paymasterAndData: '0x',
|
|
44
|
-
signature: '0x'
|
|
45
|
-
};
|
|
46
|
-
// 4. Handle Paymaster and Data (PMD)
|
|
47
|
-
if (type === UserOpScenarioType.NATIVE) {
|
|
48
|
-
userOp.paymasterAndData = '0x';
|
|
49
|
-
}
|
|
50
|
-
else if (type === UserOpScenarioType.GASLESS_V4) {
|
|
51
|
-
const pm = paymaster;
|
|
52
|
-
const token = gasToken || tokenAddress;
|
|
53
|
-
const validUntil = BigInt(Math.floor(Date.now() / 1000) + 3600);
|
|
54
|
-
const validAfter = BigInt(Math.floor(Date.now() / 1000) - 100);
|
|
55
|
-
if (!pm)
|
|
56
|
-
throw new Error('paymaster address required for GASLESS_V4');
|
|
57
|
-
if (!token)
|
|
58
|
-
throw new Error('gasToken or tokenAddress required for GASLESS_V4');
|
|
59
|
-
// PaymasterV4 Deposit-Only Model: includes payment token address
|
|
60
|
-
userOp.paymasterAndData = UserOperationBuilder.packPaymasterV4DepositData(pm, paymasterGasLimit, // paymasterVerificationGasLimit
|
|
61
|
-
paymasterPostOpGasLimit, // paymasterPostOpGasLimit
|
|
62
|
-
token, // Payment token
|
|
63
|
-
validUntil, validAfter);
|
|
64
|
-
}
|
|
65
|
-
else if (type.startsWith('SUPER_')) {
|
|
66
|
-
if (!paymaster || !operator)
|
|
67
|
-
throw new Error('Paymaster and Operator required for SuperPM scenarios');
|
|
68
|
-
userOp.paymasterAndData = UserOperationBuilder.packPaymasterAndData(paymaster, paymasterGasLimit, paymasterPostOpGasLimit, operator);
|
|
69
|
-
}
|
|
70
|
-
// 5. Get Hash and Sign
|
|
71
|
-
const opHash = await UserOperationBuilder.getUserOpHash({
|
|
72
|
-
userOp,
|
|
73
|
-
entryPoint,
|
|
74
|
-
chainId,
|
|
75
|
-
publicClient
|
|
76
|
-
});
|
|
77
|
-
const signature = await ownerAccount.signMessage({
|
|
78
|
-
message: { raw: opHash }
|
|
79
|
-
});
|
|
80
|
-
userOp.signature = signature;
|
|
81
|
-
// 6. JSON-RPC Hex-Encoding Compliance
|
|
82
|
-
const jsonUserOp = UserOperationBuilder.jsonifyUserOp(userOp);
|
|
83
|
-
return { userOp: jsonUserOp, opHash };
|
|
84
|
-
}
|
|
85
|
-
}
|
package/dist/utils/userOp.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { type Address, type Hex, type PublicClient } from 'viem';
|
|
2
|
-
/**
|
|
3
|
-
* ERC-4337 v0.7 Packed UserOperation structure.
|
|
4
|
-
*/
|
|
5
|
-
export interface PackedUserOperation {
|
|
6
|
-
sender: Address;
|
|
7
|
-
nonce: Hex;
|
|
8
|
-
initCode: Hex;
|
|
9
|
-
callData: Hex;
|
|
10
|
-
accountGasLimits: Hex;
|
|
11
|
-
preVerificationGas: Hex;
|
|
12
|
-
gasFees: Hex;
|
|
13
|
-
paymasterAndData: Hex;
|
|
14
|
-
signature: Hex;
|
|
15
|
-
}
|
|
16
|
-
export interface UserOpGasParams {
|
|
17
|
-
verificationGasLimit: bigint;
|
|
18
|
-
callGasLimit: bigint;
|
|
19
|
-
preVerificationGas: bigint;
|
|
20
|
-
maxPriorityFeePerGas: bigint;
|
|
21
|
-
maxFeePerGas: bigint;
|
|
22
|
-
}
|
|
23
|
-
export interface PaymasterGasParams {
|
|
24
|
-
paymasterGasLimit: bigint;
|
|
25
|
-
paymasterPostOpGasLimit: bigint;
|
|
26
|
-
}
|
|
27
|
-
export declare class UserOperationBuilder {
|
|
28
|
-
/**
|
|
29
|
-
* Packs verificationGasLimit and callGasLimit into a bytes32 Hex string.
|
|
30
|
-
*/
|
|
31
|
-
static packAccountGasLimits(verificationGasLimit: bigint, callGasLimit: bigint): Hex;
|
|
32
|
-
/**
|
|
33
|
-
* Packs maxPriorityFeePerGas and maxFeePerGas into a bytes32 Hex string.
|
|
34
|
-
*/
|
|
35
|
-
static packGasFees(maxPriorityFeePerGas: bigint, maxFeePerGas: bigint): Hex;
|
|
36
|
-
static estimatePreVerificationGasV07(userOp: {
|
|
37
|
-
sender: Address;
|
|
38
|
-
nonce: bigint | Hex | number | string;
|
|
39
|
-
initCode: Hex;
|
|
40
|
-
callData: Hex;
|
|
41
|
-
accountGasLimits: Hex;
|
|
42
|
-
preVerificationGas: bigint | Hex | number | string;
|
|
43
|
-
gasFees: Hex;
|
|
44
|
-
paymasterAndData: Hex;
|
|
45
|
-
signature: Hex;
|
|
46
|
-
}): bigint;
|
|
47
|
-
/**
|
|
48
|
-
* Packs Paymaster parameters into the v0.7 paymasterAndData format.
|
|
49
|
-
*/
|
|
50
|
-
static packPaymasterAndData(paymaster: Address, paymasterGasLimit: bigint, paymasterPostOpGasLimit: bigint, paymasterData?: Hex): Hex;
|
|
51
|
-
/**
|
|
52
|
-
* Pack PaymasterV4 Deposit-Only paymasterAndData
|
|
53
|
-
*
|
|
54
|
-
* v0.7 EntryPoint packs: [paymaster(20)][verificationGas(16)][postOpGas(16)][paymasterData]
|
|
55
|
-
* Contract extracts token at offset 52 = paymasterData[0:20]
|
|
56
|
-
*
|
|
57
|
-
* So paymasterData format must be: [token(20)][validUntil(6)][validAfter(6)]
|
|
58
|
-
*
|
|
59
|
-
* @param paymaster - Paymaster address (20 bytes)
|
|
60
|
-
* @param paymentToken - ERC20 token address (20 bytes, FIRST in paymasterData!)
|
|
61
|
-
* @param validUntil - Validity end timestamp (6 bytes)
|
|
62
|
-
* @param validAfter - Validity start timestamp (6 bytes)
|
|
63
|
-
*/
|
|
64
|
-
static packPaymasterV4DepositData(paymaster: Address, paymasterVerificationGasLimit: bigint, paymasterPostOpGasLimit: bigint, paymentToken: Address, validUntil: bigint, validAfter: bigint): Hex;
|
|
65
|
-
/**
|
|
66
|
-
* Computes the UserOperation hash for signing.
|
|
67
|
-
*/
|
|
68
|
-
static getUserOpHash({ userOp, entryPoint, chainId, publicClient }: {
|
|
69
|
-
userOp: PackedUserOperation;
|
|
70
|
-
entryPoint: Address;
|
|
71
|
-
chainId: number;
|
|
72
|
-
publicClient: PublicClient;
|
|
73
|
-
}): Promise<Hex>;
|
|
74
|
-
/**
|
|
75
|
-
* Formats a PackedUserOperation into a JSON-RPC compatible object with hex-encoded strings.
|
|
76
|
-
*/
|
|
77
|
-
static jsonifyUserOp(userOp: any): any;
|
|
78
|
-
/**
|
|
79
|
-
* Converts a PackedUserOperation to the Alchemy-specific v0.7 JSON format.
|
|
80
|
-
* @param userOp - The packed UserOperation
|
|
81
|
-
* @param options - Optional configuration
|
|
82
|
-
* @param options.paymasterVerificationGasLimit - Gas limit for paymaster verification (default: 200000)
|
|
83
|
-
* @param options.paymasterPostOpGasLimit - Gas limit for paymaster postOp (default: 200000)
|
|
84
|
-
*/
|
|
85
|
-
static toAlchemyUserOperation(userOp: any, options?: {
|
|
86
|
-
paymasterVerificationGasLimit?: bigint;
|
|
87
|
-
paymasterPostOpGasLimit?: bigint;
|
|
88
|
-
}): any;
|
|
89
|
-
}
|
package/dist/utils/userOp.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { concat, pad, encodeAbiParameters, parseAbiParameters, toBytes } from 'viem';
|
|
2
|
-
export class UserOperationBuilder {
|
|
3
|
-
/**
|
|
4
|
-
* Packs verificationGasLimit and callGasLimit into a bytes32 Hex string.
|
|
5
|
-
*/
|
|
6
|
-
static packAccountGasLimits(verificationGasLimit, callGasLimit) {
|
|
7
|
-
return concat([
|
|
8
|
-
pad(`0x${verificationGasLimit.toString(16)}`, { dir: 'left', size: 16 }),
|
|
9
|
-
pad(`0x${callGasLimit.toString(16)}`, { dir: 'left', size: 16 })
|
|
10
|
-
]);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Packs maxPriorityFeePerGas and maxFeePerGas into a bytes32 Hex string.
|
|
14
|
-
*/
|
|
15
|
-
static packGasFees(maxPriorityFeePerGas, maxFeePerGas) {
|
|
16
|
-
return concat([
|
|
17
|
-
pad(`0x${maxPriorityFeePerGas.toString(16)}`, { dir: 'left', size: 16 }),
|
|
18
|
-
pad(`0x${maxFeePerGas.toString(16)}`, { dir: 'left', size: 16 })
|
|
19
|
-
]);
|
|
20
|
-
}
|
|
21
|
-
static estimatePreVerificationGasV07(userOp) {
|
|
22
|
-
const nonce = typeof userOp.nonce === 'bigint'
|
|
23
|
-
? userOp.nonce
|
|
24
|
-
: typeof userOp.nonce === 'number'
|
|
25
|
-
? BigInt(userOp.nonce)
|
|
26
|
-
: BigInt(userOp.nonce);
|
|
27
|
-
const preVerificationGas = typeof userOp.preVerificationGas === 'bigint'
|
|
28
|
-
? userOp.preVerificationGas
|
|
29
|
-
: typeof userOp.preVerificationGas === 'number'
|
|
30
|
-
? BigInt(userOp.preVerificationGas)
|
|
31
|
-
: BigInt(userOp.preVerificationGas);
|
|
32
|
-
const encoded = encodeAbiParameters(parseAbiParameters('(address,uint256,bytes,bytes,bytes32,uint256,bytes32,bytes,bytes)'), [
|
|
33
|
-
[
|
|
34
|
-
userOp.sender,
|
|
35
|
-
nonce,
|
|
36
|
-
userOp.initCode,
|
|
37
|
-
userOp.callData,
|
|
38
|
-
userOp.accountGasLimits,
|
|
39
|
-
preVerificationGas,
|
|
40
|
-
userOp.gasFees,
|
|
41
|
-
userOp.paymasterAndData,
|
|
42
|
-
userOp.signature
|
|
43
|
-
]
|
|
44
|
-
]);
|
|
45
|
-
const bytes = toBytes(encoded);
|
|
46
|
-
let calldataCost = 0n;
|
|
47
|
-
for (const b of bytes)
|
|
48
|
-
calldataCost += b === 0 ? 4n : 16n;
|
|
49
|
-
return calldataCost + 26000n;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Packs Paymaster parameters into the v0.7 paymasterAndData format.
|
|
53
|
-
*/
|
|
54
|
-
static packPaymasterAndData(paymaster, paymasterGasLimit, paymasterPostOpGasLimit, paymasterData = '0x') {
|
|
55
|
-
return concat([
|
|
56
|
-
paymaster,
|
|
57
|
-
pad(`0x${paymasterGasLimit.toString(16)}`, { dir: 'left', size: 16 }),
|
|
58
|
-
pad(`0x${paymasterPostOpGasLimit.toString(16)}`, { dir: 'left', size: 16 }),
|
|
59
|
-
paymasterData
|
|
60
|
-
]);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Pack PaymasterV4 Deposit-Only paymasterAndData
|
|
64
|
-
*
|
|
65
|
-
* v0.7 EntryPoint packs: [paymaster(20)][verificationGas(16)][postOpGas(16)][paymasterData]
|
|
66
|
-
* Contract extracts token at offset 52 = paymasterData[0:20]
|
|
67
|
-
*
|
|
68
|
-
* So paymasterData format must be: [token(20)][validUntil(6)][validAfter(6)]
|
|
69
|
-
*
|
|
70
|
-
* @param paymaster - Paymaster address (20 bytes)
|
|
71
|
-
* @param paymentToken - ERC20 token address (20 bytes, FIRST in paymasterData!)
|
|
72
|
-
* @param validUntil - Validity end timestamp (6 bytes)
|
|
73
|
-
* @param validAfter - Validity start timestamp (6 bytes)
|
|
74
|
-
*/
|
|
75
|
-
static packPaymasterV4DepositData(paymaster, paymasterVerificationGasLimit, paymasterPostOpGasLimit, paymentToken, validUntil, validAfter) {
|
|
76
|
-
return concat([
|
|
77
|
-
paymaster,
|
|
78
|
-
pad(`0x${paymasterVerificationGasLimit.toString(16)}`, { dir: 'left', size: 16 }),
|
|
79
|
-
pad(`0x${paymasterPostOpGasLimit.toString(16)}`, { dir: 'left', size: 16 }),
|
|
80
|
-
paymentToken,
|
|
81
|
-
pad(`0x${validUntil.toString(16)}`, { dir: 'left', size: 6 }),
|
|
82
|
-
pad(`0x${validAfter.toString(16)}`, { dir: 'left', size: 6 })
|
|
83
|
-
]);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Computes the UserOperation hash for signing.
|
|
87
|
-
*/
|
|
88
|
-
static async getUserOpHash({ userOp, entryPoint, chainId, publicClient }) {
|
|
89
|
-
return await publicClient.readContract({
|
|
90
|
-
address: entryPoint,
|
|
91
|
-
abi: [{
|
|
92
|
-
type: 'function',
|
|
93
|
-
name: 'getUserOpHash',
|
|
94
|
-
inputs: [{
|
|
95
|
-
type: 'tuple',
|
|
96
|
-
components: [
|
|
97
|
-
{ name: 'sender', type: 'address' },
|
|
98
|
-
{ name: 'nonce', type: 'uint256' },
|
|
99
|
-
{ name: 'initCode', type: 'bytes' },
|
|
100
|
-
{ name: 'callData', type: 'bytes' },
|
|
101
|
-
{ name: 'accountGasLimits', type: 'bytes32' },
|
|
102
|
-
{ name: 'preVerificationGas', type: 'uint256' },
|
|
103
|
-
{ name: 'gasFees', type: 'bytes32' },
|
|
104
|
-
{ name: 'paymasterAndData', type: 'bytes' },
|
|
105
|
-
{ name: 'signature', type: 'bytes' }
|
|
106
|
-
]
|
|
107
|
-
}],
|
|
108
|
-
outputs: [{ type: 'bytes32' }],
|
|
109
|
-
stateMutability: 'view'
|
|
110
|
-
}],
|
|
111
|
-
functionName: 'getUserOpHash',
|
|
112
|
-
args: [userOp]
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Formats a PackedUserOperation into a JSON-RPC compatible object with hex-encoded strings.
|
|
117
|
-
*/
|
|
118
|
-
static jsonifyUserOp(userOp) {
|
|
119
|
-
// Strict allowlist for ERC-4337 v0.7 PackedUserOperation
|
|
120
|
-
// Alchemy rejects requests with unknown fields.
|
|
121
|
-
const result = {
|
|
122
|
-
sender: userOp.sender,
|
|
123
|
-
nonce: userOp.nonce,
|
|
124
|
-
initCode: userOp.initCode,
|
|
125
|
-
callData: userOp.callData,
|
|
126
|
-
accountGasLimits: userOp.accountGasLimits,
|
|
127
|
-
preVerificationGas: userOp.preVerificationGas,
|
|
128
|
-
gasFees: userOp.gasFees,
|
|
129
|
-
paymasterAndData: userOp.paymasterAndData,
|
|
130
|
-
signature: userOp.signature
|
|
131
|
-
};
|
|
132
|
-
// Ensure all numeric fields are hex strings and padded
|
|
133
|
-
// Helper to ensure '0x' prefix and valid hex string
|
|
134
|
-
const toCompactHex = (val) => {
|
|
135
|
-
if (typeof val === 'bigint')
|
|
136
|
-
return `0x${val.toString(16)}`;
|
|
137
|
-
if (typeof val === 'number')
|
|
138
|
-
return `0x${val.toString(16)}`;
|
|
139
|
-
if (typeof val === 'string') {
|
|
140
|
-
if (val === '0x')
|
|
141
|
-
return '0x0';
|
|
142
|
-
if (val === '0x0')
|
|
143
|
-
return '0x0';
|
|
144
|
-
return val.replace(/^0x0+(?!$)/, '0x');
|
|
145
|
-
}
|
|
146
|
-
return val;
|
|
147
|
-
};
|
|
148
|
-
result.nonce = toCompactHex(result.nonce);
|
|
149
|
-
result.preVerificationGas = toCompactHex(result.preVerificationGas);
|
|
150
|
-
return result;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Converts a PackedUserOperation to the Alchemy-specific v0.7 JSON format.
|
|
154
|
-
* @param userOp - The packed UserOperation
|
|
155
|
-
* @param options - Optional configuration
|
|
156
|
-
* @param options.paymasterVerificationGasLimit - Gas limit for paymaster verification (default: 200000)
|
|
157
|
-
* @param options.paymasterPostOpGasLimit - Gas limit for paymaster postOp (default: 200000)
|
|
158
|
-
*/
|
|
159
|
-
static toAlchemyUserOperation(userOp, options) {
|
|
160
|
-
const toHexStr = (val) => {
|
|
161
|
-
if (val === undefined || val === null)
|
|
162
|
-
return undefined;
|
|
163
|
-
if (typeof val === 'bigint')
|
|
164
|
-
return `0x${val.toString(16)}`;
|
|
165
|
-
if (typeof val === 'number')
|
|
166
|
-
return `0x${val.toString(16)}`;
|
|
167
|
-
if (typeof val === 'string' && !val.startsWith('0x'))
|
|
168
|
-
return `0x${val}`;
|
|
169
|
-
return val;
|
|
170
|
-
};
|
|
171
|
-
const result = {
|
|
172
|
-
sender: userOp.sender,
|
|
173
|
-
nonce: toHexStr(userOp.nonce),
|
|
174
|
-
callData: userOp.callData,
|
|
175
|
-
signature: userOp.signature
|
|
176
|
-
};
|
|
177
|
-
// 1. Unpack accountGasLimits: [verificationGasLimit(16)][callGasLimit(16)]
|
|
178
|
-
if (userOp.accountGasLimits && userOp.accountGasLimits !== '0x') {
|
|
179
|
-
const val = userOp.accountGasLimits.toString().startsWith('0x') ? userOp.accountGasLimits.slice(2) : userOp.accountGasLimits;
|
|
180
|
-
const padded = val.padStart(64, '0');
|
|
181
|
-
const verificationGasLimit = BigInt('0x' + padded.slice(0, 32));
|
|
182
|
-
const callGasLimit = BigInt('0x' + padded.slice(32, 64));
|
|
183
|
-
result.verificationGasLimit = `0x${verificationGasLimit.toString(16)}`;
|
|
184
|
-
result.callGasLimit = `0x${callGasLimit.toString(16)}`;
|
|
185
|
-
}
|
|
186
|
-
// 2. Unpack gasFees: [maxPriorityFee(16)][maxFee(16)]
|
|
187
|
-
if (userOp.gasFees && userOp.gasFees !== '0x') {
|
|
188
|
-
const val = userOp.gasFees.toString().startsWith('0x') ? userOp.gasFees.slice(2) : userOp.gasFees;
|
|
189
|
-
const padded = val.padStart(64, '0');
|
|
190
|
-
const maxPriorityFeePerGas = BigInt('0x' + padded.slice(0, 32));
|
|
191
|
-
const maxFeePerGas = BigInt('0x' + padded.slice(32, 64));
|
|
192
|
-
result.maxPriorityFeePerGas = `0x${maxPriorityFeePerGas.toString(16)}`;
|
|
193
|
-
result.maxFeePerGas = `0x${maxFeePerGas.toString(16)}`;
|
|
194
|
-
}
|
|
195
|
-
// 3. PreVerificationGas (Direct copy but ensure hex)
|
|
196
|
-
if (userOp.preVerificationGas) {
|
|
197
|
-
result.preVerificationGas = `0x${BigInt(userOp.preVerificationGas).toString(16)}`;
|
|
198
|
-
}
|
|
199
|
-
// 4. Unpack initCode -> factory + factoryData
|
|
200
|
-
if (userOp.initCode && userOp.initCode !== '0x') {
|
|
201
|
-
const initCode = userOp.initCode.toString();
|
|
202
|
-
result.factory = initCode.slice(0, 42); // First 20 bytes
|
|
203
|
-
result.factoryData = '0x' + initCode.slice(42);
|
|
204
|
-
}
|
|
205
|
-
// 5. Unpack paymasterAndData -> paymaster + gas limits + paymasterData
|
|
206
|
-
// Full format: [paymaster(20)][verificationGas(16)][postOpGas(16)][paymasterData]
|
|
207
|
-
// paymasterData = [token(20)][validUntil(6)][validAfter(6)] = 32 bytes
|
|
208
|
-
if (userOp.paymasterAndData && userOp.paymasterAndData !== '0x') {
|
|
209
|
-
const pmd = userOp.paymasterAndData.toString().startsWith('0x') ? userOp.paymasterAndData.slice(2) : userOp.paymasterAndData;
|
|
210
|
-
// Check if we have full format with gas limits (at least 20+16+16 = 52 bytes = 104 hex chars)
|
|
211
|
-
if (pmd.length >= 104) {
|
|
212
|
-
// Full v0.7 packed format
|
|
213
|
-
result.paymaster = '0x' + pmd.slice(0, 40); // bytes 0-19 (20 bytes)
|
|
214
|
-
const vGas = BigInt('0x' + pmd.slice(40, 72)); // bytes 20-35 (16 bytes)
|
|
215
|
-
const pGas = BigInt('0x' + pmd.slice(72, 104)); // bytes 36-51 (16 bytes)
|
|
216
|
-
result.paymasterVerificationGasLimit = `0x${vGas.toString(16)}`;
|
|
217
|
-
result.paymasterPostOpGasLimit = `0x${pGas.toString(16)}`;
|
|
218
|
-
result.paymasterData = '0x' + pmd.slice(104); // bytes 52+ (token + timestamps)
|
|
219
|
-
}
|
|
220
|
-
else if (pmd.length >= 40) {
|
|
221
|
-
// Fallback: assume 52-byte format without gas limits (old format)
|
|
222
|
-
result.paymaster = '0x' + pmd.slice(0, 40);
|
|
223
|
-
result.paymasterData = '0x' + pmd.slice(40);
|
|
224
|
-
const defaultGasLimit = 200000n;
|
|
225
|
-
result.paymasterVerificationGasLimit = `0x${(options?.paymasterVerificationGasLimit || defaultGasLimit).toString(16)}`;
|
|
226
|
-
result.paymasterPostOpGasLimit = `0x${(options?.paymasterPostOpGasLimit || defaultGasLimit).toString(16)}`;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return result;
|
|
230
|
-
}
|
|
231
|
-
}
|