@aastar/sdk 0.16.8 → 0.16.12
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/README.md +21 -0
- package/dist/clients/admin.d.ts +11 -0
- package/dist/clients/admin.js +20 -0
- package/dist/{sdk/src/clients → clients}/community.d.ts +4 -12
- package/dist/clients/community.js +300 -0
- package/dist/{sdk/src/clients → clients}/endUser.d.ts +5 -23
- package/dist/clients/endUser.js +298 -0
- package/dist/{sdk/src/clients → clients}/operator.d.ts +8 -38
- package/dist/{sdk/src/clients → clients}/operator.js +76 -114
- package/dist/errors/decoder.d.ts +6 -0
- package/dist/errors/decoder.js +44 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +21 -0
- package/dist/{sdk/src/utils → utils}/keys.d.ts +0 -12
- package/dist/{sdk/src/utils → utils}/keys.js +0 -7
- package/dist/{sdk/src/utils → utils}/roleData.js +28 -15
- package/dist/{sdk/src/utils → utils}/testScenarios.js +1 -1
- package/dist/{sdk/src/utils → utils}/userOp.js +3 -8
- package/package.json +11 -25
- package/dist/account/src/accounts/simple.d.ts +0 -18
- package/dist/account/src/accounts/simple.js +0 -49
- package/dist/account/src/eoa.d.ts +0 -10
- package/dist/account/src/eoa.js +0 -21
- package/dist/account/src/index.d.ts +0 -19
- package/dist/account/src/index.js +0 -49
- package/dist/core/src/abis/index.d.ts +0 -1126
- package/dist/core/src/abis/index.js +0 -91
- package/dist/core/src/actions/StateValidator.d.ts +0 -68
- package/dist/core/src/actions/StateValidator.js +0 -187
- package/dist/core/src/actions/account.d.ts +0 -55
- package/dist/core/src/actions/account.js +0 -133
- package/dist/core/src/actions/aggregator.d.ts +0 -17
- package/dist/core/src/actions/aggregator.js +0 -31
- package/dist/core/src/actions/dvt.d.ts +0 -30
- package/dist/core/src/actions/dvt.js +0 -41
- package/dist/core/src/actions/entryPoint.d.ts +0 -90
- package/dist/core/src/actions/entryPoint.js +0 -211
- package/dist/core/src/actions/factory.d.ts +0 -215
- package/dist/core/src/actions/factory.js +0 -442
- package/dist/core/src/actions/faucet.d.ts +0 -48
- package/dist/core/src/actions/faucet.js +0 -337
- package/dist/core/src/actions/gtokenExtended.d.ts +0 -39
- package/dist/core/src/actions/gtokenExtended.js +0 -115
- package/dist/core/src/actions/index.d.ts +0 -15
- package/dist/core/src/actions/index.js +0 -17
- package/dist/core/src/actions/paymasterV4.d.ts +0 -170
- package/dist/core/src/actions/paymasterV4.js +0 -334
- package/dist/core/src/actions/registry.d.ts +0 -246
- package/dist/core/src/actions/registry.js +0 -667
- package/dist/core/src/actions/reputation.d.ts +0 -129
- package/dist/core/src/actions/reputation.js +0 -281
- package/dist/core/src/actions/sbt.d.ts +0 -191
- package/dist/core/src/actions/sbt.js +0 -533
- package/dist/core/src/actions/staking.d.ts +0 -132
- package/dist/core/src/actions/staking.js +0 -330
- package/dist/core/src/actions/superPaymaster.d.ts +0 -237
- package/dist/core/src/actions/superPaymaster.js +0 -644
- package/dist/core/src/actions/tokens.d.ts +0 -229
- package/dist/core/src/actions/tokens.js +0 -415
- package/dist/core/src/branding.d.ts +0 -30
- package/dist/core/src/branding.js +0 -30
- package/dist/core/src/clients/BaseClient.d.ts +0 -25
- package/dist/core/src/clients/BaseClient.js +0 -66
- package/dist/core/src/clients/types.d.ts +0 -60
- package/dist/core/src/clients/types.js +0 -1
- package/dist/core/src/clients.d.ts +0 -5
- package/dist/core/src/clients.js +0 -11
- package/dist/core/src/communities.d.ts +0 -52
- package/dist/core/src/communities.js +0 -73
- package/dist/core/src/config/ContractConfigManager.d.ts +0 -20
- package/dist/core/src/config/ContractConfigManager.js +0 -48
- package/dist/core/src/constants.d.ts +0 -88
- package/dist/core/src/constants.js +0 -125
- package/dist/core/src/contract-addresses.d.ts +0 -110
- package/dist/core/src/contract-addresses.js +0 -99
- package/dist/core/src/contracts.d.ts +0 -424
- package/dist/core/src/contracts.js +0 -343
- package/dist/core/src/crypto/blsSigner.d.ts +0 -64
- package/dist/core/src/crypto/blsSigner.js +0 -98
- package/dist/core/src/crypto/index.d.ts +0 -1
- package/dist/core/src/crypto/index.js +0 -1
- package/dist/core/src/index.d.ts +0 -21
- package/dist/core/src/index.js +0 -21
- package/dist/core/src/networks.d.ts +0 -127
- package/dist/core/src/networks.js +0 -118
- package/dist/core/src/requirementChecker.d.ts +0 -38
- package/dist/core/src/requirementChecker.js +0 -139
- package/dist/core/src/roles.d.ts +0 -204
- package/dist/core/src/roles.js +0 -211
- package/dist/core/src/utils/validation.d.ts +0 -24
- package/dist/core/src/utils/validation.js +0 -56
- package/dist/dapp/src/index.d.ts +0 -3
- package/dist/dapp/src/index.js +0 -3
- package/dist/dapp/src/ui/hooks/useCreditScore.d.ts +0 -13
- package/dist/dapp/src/ui/hooks/useCreditScore.js +0 -32
- package/dist/dapp/src/ui/hooks/useSuperPaymaster.d.ts +0 -8
- package/dist/dapp/src/ui/hooks/useSuperPaymaster.js +0 -23
- package/dist/dapp/src/ui/index.d.ts +0 -4
- package/dist/dapp/src/ui/index.js +0 -17
- package/dist/identity/src/index.d.ts +0 -46
- package/dist/identity/src/index.js +0 -94
- package/dist/identity/src/mysbt.d.ts +0 -13
- package/dist/identity/src/mysbt.js +0 -37
- package/dist/paymaster/src/SuperPaymaster/index.d.ts +0 -44
- package/dist/paymaster/src/SuperPaymaster/index.js +0 -133
- package/dist/paymaster/src/V4/PaymasterClient.d.ts +0 -79
- package/dist/paymaster/src/V4/PaymasterClient.js +0 -315
- package/dist/paymaster/src/V4/PaymasterOperator.d.ts +0 -41
- package/dist/paymaster/src/V4/PaymasterOperator.js +0 -241
- package/dist/paymaster/src/V4/PaymasterUtils.d.ts +0 -55
- package/dist/paymaster/src/V4/PaymasterUtils.js +0 -124
- package/dist/paymaster/src/V4/SuperPaymasterClient.d.ts +0 -21
- package/dist/paymaster/src/V4/SuperPaymasterClient.js +0 -73
- package/dist/paymaster/src/V4/index.d.ts +0 -4
- package/dist/paymaster/src/V4/index.js +0 -4
- package/dist/paymaster/src/index.d.ts +0 -2
- package/dist/paymaster/src/index.js +0 -4
- package/dist/sdk/src/clients/admin.d.ts +0 -57
- package/dist/sdk/src/clients/admin.js +0 -105
- package/dist/sdk/src/clients/community.js +0 -244
- package/dist/sdk/src/clients/endUser.js +0 -388
- package/dist/sdk/src/errors/decoder.d.ts +0 -1
- package/dist/sdk/src/errors/decoder.js +0 -83
- package/dist/sdk/src/index.d.ts +0 -16
- package/dist/sdk/src/index.js +0 -20
- package/dist/tokens/src/index.d.ts +0 -56
- package/dist/tokens/src/index.js +0 -230
- package/examples/config.json +0 -1
- package/examples/regression_test.d.ts +0 -2
- package/examples/regression_test.d.ts.map +0 -1
- package/examples/regression_test.js +0 -89
- package/examples/regression_test.js.map +0 -1
- package/examples/regression_test.ts +0 -106
- package/scripts/v2_regression/00_validate_env.ts +0 -101
- package/scripts/v2_regression/01_setup_and_fund.ts +0 -132
- package/scripts/v2_regression/02_operator_onboarding.ts +0 -174
- package/scripts/v2_regression/03_community_registry.ts +0 -139
- package/scripts/v2_regression/04_enduser_flow.ts +0 -141
- package/scripts/v2_regression/05_admin_audit.ts +0 -157
- package/scripts/validate_env.ts +0 -112
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.js +0 -0
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/admin.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/admin.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/clients.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/clients.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/community.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/community.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/endUser.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/endUser.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/operator.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/operator.test.js +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.d.ts +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.js +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.test.d.ts +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.test.js +0 -0
- /package/dist/{sdk/src/errors → errors}/decoder.test.d.ts +0 -0
- /package/dist/{sdk/src/errors → errors}/decoder.test.js +0 -0
- /package/dist/{sdk/src/node → node}/index.d.ts +0 -0
- /package/dist/{sdk/src/node → node}/index.js +0 -0
- /package/dist/{sdk/src/types → types}/result.d.ts +0 -0
- /package/dist/{sdk/src/types → types}/result.js +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.js +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.js +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.js +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/keys.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/keys.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/roleData.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/roleData.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/roleData.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/testScenarios.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/testScenarios.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/testScenarios.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/userOp.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/userOp.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/userOp.test.js +0 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { createClient, publicActions, walletActions, parseAbi } from 'viem';
|
|
2
|
+
import { registryActions, sbtActions, superPaymasterActions, paymasterActions, CORE_ADDRESSES, TOKEN_ADDRESSES, TEST_ACCOUNT_ADDRESSES, RegistryABI } from '@aastar/core';
|
|
3
|
+
export function createEndUserClient({ chain, transport, account, addresses }) {
|
|
4
|
+
const client = createClient({
|
|
5
|
+
chain,
|
|
6
|
+
transport,
|
|
7
|
+
account
|
|
8
|
+
})
|
|
9
|
+
.extend(publicActions)
|
|
10
|
+
.extend(walletActions);
|
|
11
|
+
const usedAddresses = { ...CORE_ADDRESSES, ...TOKEN_ADDRESSES, ...TEST_ACCOUNT_ADDRESSES, ...addresses };
|
|
12
|
+
console.log(' SDK Debug: simpleAccountFactory from usedAddresses:', usedAddresses.simpleAccountFactory);
|
|
13
|
+
console.log(' SDK Debug: process.env.SIMPLE_ACCOUNT_FACTORY:', process.env.SIMPLE_ACCOUNT_FACTORY);
|
|
14
|
+
const actions = {
|
|
15
|
+
...registryActions(usedAddresses.registry)(client),
|
|
16
|
+
...sbtActions(usedAddresses.mySBT)(client),
|
|
17
|
+
...superPaymasterActions(usedAddresses.superPaymaster)(client),
|
|
18
|
+
...paymasterActions(usedAddresses.paymasterV4)(client)
|
|
19
|
+
};
|
|
20
|
+
return Object.assign(client, actions, {
|
|
21
|
+
async onboard({ community, roleId, roleData }) {
|
|
22
|
+
console.log('👤 Onboarding user to community...');
|
|
23
|
+
const result = await this.joinAndActivate({ community, roleId, roleData });
|
|
24
|
+
console.log(`✅ User onboarded! SBT ID: ${result.sbtId}`);
|
|
25
|
+
return { tx: result.tx, sbtId: result.sbtId };
|
|
26
|
+
},
|
|
27
|
+
async joinAndActivate({ community, roleId, roleData }) {
|
|
28
|
+
const accountToUse = account;
|
|
29
|
+
if (!accountToUse)
|
|
30
|
+
throw new Error("Account required for joinAndActivate");
|
|
31
|
+
console.log(` SDK: Joining community ${community}...`);
|
|
32
|
+
// Registry.registerRoleSelf is now idempotent (modified contract)
|
|
33
|
+
// First call: Mints SBT + grants role
|
|
34
|
+
// Subsequent calls: Adds community membership
|
|
35
|
+
// If roleData not provided, encode EndUserRoleData structure
|
|
36
|
+
let finalData;
|
|
37
|
+
if (roleData) {
|
|
38
|
+
finalData = roleData;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Encode EndUserRoleData: (address account, address community, string avatarURI, string ensName, uint256 stakeAmount)
|
|
42
|
+
const { encodeAbiParameters } = await import('viem');
|
|
43
|
+
finalData = encodeAbiParameters([
|
|
44
|
+
{ name: 'account', type: 'address' },
|
|
45
|
+
{ name: 'community', type: 'address' },
|
|
46
|
+
{ name: 'avatarURI', type: 'string' },
|
|
47
|
+
{ name: 'ensName', type: 'string' },
|
|
48
|
+
{ name: 'stakeAmount', type: 'uint256' }
|
|
49
|
+
], [accountToUse.address, community, '', '', 0n] // Use minimum stake (Registry will use roleConfig.minStake)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const regTx = await client.writeContract({
|
|
53
|
+
address: usedAddresses.registry,
|
|
54
|
+
abi: RegistryABI,
|
|
55
|
+
functionName: 'registerRoleSelf',
|
|
56
|
+
args: [roleId, finalData],
|
|
57
|
+
account: accountToUse,
|
|
58
|
+
chain
|
|
59
|
+
});
|
|
60
|
+
await client.waitForTransactionReceipt({ hash: regTx });
|
|
61
|
+
// 2. Fetch SBT ID
|
|
62
|
+
const sbtId = await actions.getUserSBT({ user: accountToUse.address });
|
|
63
|
+
console.log(` SDK: User joined. SBT ID: ${sbtId}`);
|
|
64
|
+
// 3. Fetch Initial Credit for verification
|
|
65
|
+
let credit = 0n;
|
|
66
|
+
try {
|
|
67
|
+
const factoryAbi = parseAbi(['function communityToToken(address) view returns (address)']);
|
|
68
|
+
const tokenAddress = await client.readContract({
|
|
69
|
+
address: usedAddresses.xPNTsFactory,
|
|
70
|
+
abi: factoryAbi,
|
|
71
|
+
functionName: 'communityToToken',
|
|
72
|
+
args: [community]
|
|
73
|
+
});
|
|
74
|
+
credit = await actions.getAvailableCredit({
|
|
75
|
+
user: client.aaAddress || accountToUse.address,
|
|
76
|
+
token: tokenAddress
|
|
77
|
+
});
|
|
78
|
+
console.log(` SDK: Activation complete. Current Credit: ${credit} points.`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.log(` SDK: Credit system not available (${error.message.split('\n')[0]}). Continuing...`);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
tx: regTx,
|
|
85
|
+
sbtId,
|
|
86
|
+
initialCredit: credit
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
async executeGasless({ target, data, value = 0n, operator }) {
|
|
90
|
+
const accountToUse = account;
|
|
91
|
+
if (!accountToUse)
|
|
92
|
+
throw new Error("Wallet account required for gasless execution");
|
|
93
|
+
// 1. Get AA Address (Predict if necessary)
|
|
94
|
+
const { accountAddress } = await this.createSmartAccount({ owner: accountToUse.address });
|
|
95
|
+
console.log(` SDK: Executing gasless via AA ${accountAddress} Sponsored by ${operator}`);
|
|
96
|
+
// 2. Fetch Nonce from EntryPoint (v0.7 standard)
|
|
97
|
+
// Note: In v0.7, nonce is managed by EntryPoint, not the account itself
|
|
98
|
+
let nonce = 0n;
|
|
99
|
+
try {
|
|
100
|
+
nonce = await client.readContract({
|
|
101
|
+
address: usedAddresses.entryPoint,
|
|
102
|
+
abi: [{
|
|
103
|
+
type: 'function',
|
|
104
|
+
name: 'getNonce',
|
|
105
|
+
inputs: [{ type: 'address', name: 'sender' }, { type: 'uint192', name: 'key' }],
|
|
106
|
+
outputs: [{ type: 'uint256' }],
|
|
107
|
+
stateMutability: 'view'
|
|
108
|
+
}],
|
|
109
|
+
functionName: 'getNonce',
|
|
110
|
+
args: [accountAddress, 0n] // 0 = default nonce key
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
console.warn(` ⚠️ Failed to fetch nonce from EntryPoint, using default 0:`, e.message);
|
|
115
|
+
// For initial transactions, nonce is always 0
|
|
116
|
+
nonce = 0n;
|
|
117
|
+
}
|
|
118
|
+
// 3. Build CallData (execute(target, value, data))
|
|
119
|
+
const { encodeFunctionData, concat, pad, keccak256 } = await import('viem');
|
|
120
|
+
const executeData = encodeFunctionData({
|
|
121
|
+
abi: [{ type: 'function', name: 'execute', inputs: [{ type: 'address' }, { type: 'uint256' }, { type: 'bytes' }] }],
|
|
122
|
+
functionName: 'execute',
|
|
123
|
+
args: [target, value, data]
|
|
124
|
+
});
|
|
125
|
+
// 4. Build Gas Limits & Fees (Benchmarked for experiments)
|
|
126
|
+
const accountGasLimits = concat([
|
|
127
|
+
pad(`0x${(100000).toString(16)}`, { dir: 'left', size: 16 }), // verification
|
|
128
|
+
pad(`0x${(100000).toString(16)}`, { dir: 'left', size: 16 }) // call
|
|
129
|
+
]);
|
|
130
|
+
const gasFees = concat([
|
|
131
|
+
pad(`0x${(2000000000).toString(16)}`, { dir: 'left', size: 16 }), // 2 gwei
|
|
132
|
+
pad(`0x${(2000000000).toString(16)}`, { dir: 'left', size: 16 }) // 2 gwei
|
|
133
|
+
]);
|
|
134
|
+
// 5. Build PaymasterAndData (v0.7 packed format)
|
|
135
|
+
const paymasterVerificationGas = 250000n;
|
|
136
|
+
const paymasterPostOpGas = 50000n;
|
|
137
|
+
const paymasterAndData = concat([
|
|
138
|
+
usedAddresses.superPaymaster,
|
|
139
|
+
pad(`0x${paymasterVerificationGas.toString(16)}`, { dir: 'left', size: 16 }),
|
|
140
|
+
pad(`0x${paymasterPostOpGas.toString(16)}`, { dir: 'left', size: 16 }),
|
|
141
|
+
operator
|
|
142
|
+
]);
|
|
143
|
+
// 6. Construct UserOperation v0.7
|
|
144
|
+
const userOp = {
|
|
145
|
+
sender: accountAddress,
|
|
146
|
+
nonce,
|
|
147
|
+
initCode: '0x',
|
|
148
|
+
callData: executeData,
|
|
149
|
+
accountGasLimits,
|
|
150
|
+
preVerificationGas: 50000n,
|
|
151
|
+
gasFees,
|
|
152
|
+
paymasterAndData,
|
|
153
|
+
signature: '0x'
|
|
154
|
+
};
|
|
155
|
+
// 7. Sign UserOp Hash
|
|
156
|
+
const entryPointAddress = usedAddresses.entryPoint || '0x0000000071727De22E5E9d8BAf0edAc6f37da032';
|
|
157
|
+
const userOpHash = await client.readContract({
|
|
158
|
+
address: entryPointAddress,
|
|
159
|
+
abi: [{
|
|
160
|
+
type: 'function',
|
|
161
|
+
name: 'getUserOpHash',
|
|
162
|
+
inputs: [{
|
|
163
|
+
type: 'tuple',
|
|
164
|
+
components: [
|
|
165
|
+
{ name: 'sender', type: 'address' },
|
|
166
|
+
{ name: 'nonce', type: 'uint256' },
|
|
167
|
+
{ name: 'initCode', type: 'bytes' },
|
|
168
|
+
{ name: 'callData', type: 'bytes' },
|
|
169
|
+
{ name: 'accountGasLimits', type: 'bytes32' },
|
|
170
|
+
{ name: 'preVerificationGas', type: 'uint256' },
|
|
171
|
+
{ name: 'gasFees', type: 'bytes32' },
|
|
172
|
+
{ name: 'paymasterAndData', type: 'bytes' },
|
|
173
|
+
{ name: 'signature', type: 'bytes' }
|
|
174
|
+
]
|
|
175
|
+
}],
|
|
176
|
+
outputs: [{ type: 'bytes32' }],
|
|
177
|
+
stateMutability: 'view'
|
|
178
|
+
}],
|
|
179
|
+
functionName: 'getUserOpHash',
|
|
180
|
+
args: [userOp]
|
|
181
|
+
});
|
|
182
|
+
const signature = await accountToUse.signMessage({
|
|
183
|
+
message: { raw: userOpHash }
|
|
184
|
+
});
|
|
185
|
+
userOp.signature = signature;
|
|
186
|
+
// 8. Submit via handleOps
|
|
187
|
+
console.log(` SDK: Submitting UserOp ${userOpHash}...`);
|
|
188
|
+
const tx = await client.writeContract({
|
|
189
|
+
address: entryPointAddress,
|
|
190
|
+
abi: [{
|
|
191
|
+
type: 'function',
|
|
192
|
+
name: 'handleOps',
|
|
193
|
+
inputs: [
|
|
194
|
+
{
|
|
195
|
+
type: 'tuple[]',
|
|
196
|
+
components: [
|
|
197
|
+
{ name: 'sender', type: 'address' },
|
|
198
|
+
{ name: 'nonce', type: 'uint256' },
|
|
199
|
+
{ name: 'initCode', type: 'bytes' },
|
|
200
|
+
{ name: 'callData', type: 'bytes' },
|
|
201
|
+
{ name: 'accountGasLimits', type: 'bytes32' },
|
|
202
|
+
{ name: 'preVerificationGas', type: 'uint256' },
|
|
203
|
+
{ name: 'gasFees', type: 'bytes32' },
|
|
204
|
+
{ name: 'paymasterAndData', type: 'bytes' },
|
|
205
|
+
{ name: 'signature', type: 'bytes' }
|
|
206
|
+
]
|
|
207
|
+
},
|
|
208
|
+
{ name: 'beneficiary', type: 'address' }
|
|
209
|
+
],
|
|
210
|
+
outputs: [],
|
|
211
|
+
stateMutability: 'nonpayable'
|
|
212
|
+
}],
|
|
213
|
+
functionName: 'handleOps',
|
|
214
|
+
args: [[userOp], accountToUse.address],
|
|
215
|
+
account,
|
|
216
|
+
chain
|
|
217
|
+
});
|
|
218
|
+
await client.waitForTransactionReceipt({ hash: tx });
|
|
219
|
+
return tx;
|
|
220
|
+
},
|
|
221
|
+
async checkJoinRequirements(address) {
|
|
222
|
+
const accountToUse = address || account?.address;
|
|
223
|
+
if (!accountToUse)
|
|
224
|
+
throw new Error("Account address required for requirement check");
|
|
225
|
+
const { RequirementChecker } = await import('@aastar/core');
|
|
226
|
+
const checker = new RequirementChecker(client, usedAddresses);
|
|
227
|
+
// Default requirements for standard community joining
|
|
228
|
+
return await checker.checkRequirements({
|
|
229
|
+
address: accountToUse,
|
|
230
|
+
requiredGToken: 440000000000000000n, // 0.44 GT (stake + burn)
|
|
231
|
+
requireSBT: false
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
async createSmartAccount({ owner, salt = 0n }) {
|
|
235
|
+
const { SimpleAccountFactoryABI } = await import('@aastar/core');
|
|
236
|
+
const { encodeFunctionData, concat } = await import('viem');
|
|
237
|
+
let factoryAddress = usedAddresses.simpleAccountFactory;
|
|
238
|
+
console.log(` SDK: Using SimpleAccountFactory: ${factoryAddress} (Owner: ${owner}, Salt: ${salt})`);
|
|
239
|
+
// Fallback to official v0.7 factory if not provided
|
|
240
|
+
if (!factoryAddress || factoryAddress === '0x0000000000000000000000000000000000000000') {
|
|
241
|
+
console.warn(" ⚠️ SimpleAccountFactory not found in configuration. Using default fallback.");
|
|
242
|
+
factoryAddress = '0x9406Cc6185a346906296840746125a0E44976454';
|
|
243
|
+
}
|
|
244
|
+
const accountAddress = await client.readContract({
|
|
245
|
+
address: factoryAddress,
|
|
246
|
+
abi: SimpleAccountFactoryABI,
|
|
247
|
+
functionName: 'getAddress',
|
|
248
|
+
args: [owner, salt]
|
|
249
|
+
});
|
|
250
|
+
const createAccountData = encodeFunctionData({
|
|
251
|
+
abi: SimpleAccountFactoryABI,
|
|
252
|
+
functionName: 'createAccount',
|
|
253
|
+
args: [owner, salt]
|
|
254
|
+
});
|
|
255
|
+
const initCode = concat([factoryAddress, createAccountData]);
|
|
256
|
+
const byteCode = await client.getBytecode({ address: accountAddress });
|
|
257
|
+
const isDeployed = byteCode !== undefined && byteCode !== '0x';
|
|
258
|
+
return { accountAddress, initCode, isDeployed };
|
|
259
|
+
},
|
|
260
|
+
async deploySmartAccount({ owner, salt = 0n, fundWithETH = 0n }) {
|
|
261
|
+
const { accountAddress, isDeployed } = await this.createSmartAccount({ owner, salt });
|
|
262
|
+
const { formatEther } = await import('viem');
|
|
263
|
+
let deployHash = '0x0';
|
|
264
|
+
if (isDeployed) {
|
|
265
|
+
console.log(` ℹ️ Account ${accountAddress} already deployed.`);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
const { SimpleAccountFactoryABI } = await import('@aastar/core');
|
|
269
|
+
let factoryAddress = usedAddresses.simpleAccountFactory;
|
|
270
|
+
if (!factoryAddress || factoryAddress === '0x0000000000000000000000000000000000000000') {
|
|
271
|
+
factoryAddress = '0x9406Cc6185a346906296840746125a0E44976454';
|
|
272
|
+
}
|
|
273
|
+
console.log(` 🏭 Deploying Smart Account for ${owner}...`);
|
|
274
|
+
deployHash = await client.writeContract({
|
|
275
|
+
address: factoryAddress,
|
|
276
|
+
abi: SimpleAccountFactoryABI,
|
|
277
|
+
functionName: 'createAccount',
|
|
278
|
+
args: [owner, salt],
|
|
279
|
+
account,
|
|
280
|
+
chain
|
|
281
|
+
});
|
|
282
|
+
await client.waitForTransactionReceipt({ hash: deployHash });
|
|
283
|
+
console.log(` ✅ Deployed at ${accountAddress}`);
|
|
284
|
+
}
|
|
285
|
+
if (fundWithETH > 0n) {
|
|
286
|
+
console.log(` ⛽ Funding account with ${formatEther(fundWithETH)} ETH...`);
|
|
287
|
+
const tx = await client.sendTransaction({
|
|
288
|
+
to: accountAddress,
|
|
289
|
+
value: fundWithETH,
|
|
290
|
+
account,
|
|
291
|
+
chain
|
|
292
|
+
});
|
|
293
|
+
await client.waitForTransactionReceipt({ hash: tx });
|
|
294
|
+
}
|
|
295
|
+
return { accountAddress, deployTxHash: deployHash, isDeployed: true };
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Client, type Transport, type Chain, type Account, type Hash, type Hex, type PublicActions, type WalletActions, type Address } from 'viem';
|
|
2
|
-
import { type StakingActions, type RegistryActions, type SuperPaymasterActions, type
|
|
3
|
-
|
|
4
|
-
export type OperatorClient = Client<Transport, Chain, Account | undefined> & PublicActions<Transport, Chain, Account | undefined> & WalletActions<Chain, Account | undefined> & RegistryActions & SuperPaymasterActions & PaymasterV4Actions & StakingActions & TokenActions & {
|
|
2
|
+
import { type StakingActions, type RegistryActions, type SuperPaymasterActions, type PaymasterActions } from '@aastar/core';
|
|
3
|
+
export type OperatorClient = Client<Transport, Chain, Account | undefined> & PublicActions<Transport, Chain, Account | undefined> & WalletActions<Chain, Account | undefined> & RegistryActions & SuperPaymasterActions & PaymasterActions & StakingActions & {
|
|
5
4
|
/**
|
|
6
5
|
* High-level API: Setup operator with automatic funding and onboarding
|
|
7
6
|
*/
|
|
@@ -11,10 +10,7 @@ export type OperatorClient = Client<Transport, Chain, Account | undefined> & Pub
|
|
|
11
10
|
roleId: Hex;
|
|
12
11
|
roleData?: Hex;
|
|
13
12
|
}) => Promise<{
|
|
14
|
-
txs:
|
|
15
|
-
hash: Hash;
|
|
16
|
-
events: DecodedEvent[];
|
|
17
|
-
}[];
|
|
13
|
+
txs: Hash[];
|
|
18
14
|
}>;
|
|
19
15
|
deployPaymasterV4: (args?: {
|
|
20
16
|
version?: string;
|
|
@@ -27,42 +23,24 @@ export type OperatorClient = Client<Transport, Chain, Account | undefined> & Pub
|
|
|
27
23
|
* 3. Approve aPNTs (Deposit)
|
|
28
24
|
* 4. Deposit aPNTs (SuperPaymaster)
|
|
29
25
|
*/
|
|
30
|
-
|
|
26
|
+
onboardOperator: (args: {
|
|
31
27
|
stakeAmount: bigint;
|
|
32
28
|
depositAmount: bigint;
|
|
33
29
|
roleId: Hex;
|
|
34
30
|
roleData?: Hex;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
events: DecodedEvent[];
|
|
39
|
-
}[]>;
|
|
40
|
-
/** @deprecated Use onboardFully */
|
|
41
|
-
onboardOperator: (args: {
|
|
31
|
+
}) => Promise<Hash[]>;
|
|
32
|
+
/** @deprecated Use onboardOperator */
|
|
33
|
+
onboardToSuperPaymaster: (args: {
|
|
42
34
|
stakeAmount: bigint;
|
|
43
35
|
depositAmount: bigint;
|
|
44
36
|
roleId: Hex;
|
|
45
|
-
|
|
46
|
-
}) => Promise<{
|
|
47
|
-
hash: Hash;
|
|
48
|
-
events: DecodedEvent[];
|
|
49
|
-
}[]>;
|
|
37
|
+
}) => Promise<Hash[]>;
|
|
50
38
|
configureOperator: (args: {
|
|
51
39
|
xPNTsToken: Address;
|
|
52
40
|
treasury: Address;
|
|
53
41
|
exchangeRate: bigint;
|
|
54
42
|
account?: Account | Address;
|
|
55
43
|
}) => Promise<Hash>;
|
|
56
|
-
/**
|
|
57
|
-
* 🧙 Wisdom: Check if operator is ready and compliant.
|
|
58
|
-
*/
|
|
59
|
-
checkReadiness: () => Promise<{
|
|
60
|
-
isRegistered: boolean;
|
|
61
|
-
isConfigured: boolean;
|
|
62
|
-
collateralBalance: bigint;
|
|
63
|
-
isPaused: boolean;
|
|
64
|
-
roleStatus: boolean;
|
|
65
|
-
}>;
|
|
66
44
|
getOperatorStatus: (accountAddress: Address) => Promise<{
|
|
67
45
|
type: 'super' | 'v4' | null;
|
|
68
46
|
superPaymaster: {
|
|
@@ -77,14 +55,6 @@ export type OperatorClient = Client<Transport, Chain, Account | undefined> & Pub
|
|
|
77
55
|
balance: bigint;
|
|
78
56
|
} | null;
|
|
79
57
|
}>;
|
|
80
|
-
isOperator: (operator: Address) => Promise<boolean>;
|
|
81
|
-
getDepositDetails: () => Promise<{
|
|
82
|
-
deposit: bigint;
|
|
83
|
-
}>;
|
|
84
|
-
deposit: (args: {
|
|
85
|
-
amount: bigint;
|
|
86
|
-
account?: Account | Address;
|
|
87
|
-
}) => Promise<Hash>;
|
|
88
58
|
};
|
|
89
59
|
export declare function createOperatorClient({ chain, transport, account, addresses }: {
|
|
90
60
|
chain: Chain;
|