@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.
Files changed (187) hide show
  1. package/README.md +21 -0
  2. package/dist/clients/admin.d.ts +11 -0
  3. package/dist/clients/admin.js +20 -0
  4. package/dist/{sdk/src/clients → clients}/community.d.ts +4 -12
  5. package/dist/clients/community.js +300 -0
  6. package/dist/{sdk/src/clients → clients}/endUser.d.ts +5 -23
  7. package/dist/clients/endUser.js +298 -0
  8. package/dist/{sdk/src/clients → clients}/operator.d.ts +8 -38
  9. package/dist/{sdk/src/clients → clients}/operator.js +76 -114
  10. package/dist/errors/decoder.d.ts +6 -0
  11. package/dist/errors/decoder.js +44 -0
  12. package/dist/index.d.ts +18 -0
  13. package/dist/index.js +21 -0
  14. package/dist/{sdk/src/utils → utils}/keys.d.ts +0 -12
  15. package/dist/{sdk/src/utils → utils}/keys.js +0 -7
  16. package/dist/{sdk/src/utils → utils}/roleData.js +28 -15
  17. package/dist/{sdk/src/utils → utils}/testScenarios.js +1 -1
  18. package/dist/{sdk/src/utils → utils}/userOp.js +3 -8
  19. package/package.json +11 -25
  20. package/dist/account/src/accounts/simple.d.ts +0 -18
  21. package/dist/account/src/accounts/simple.js +0 -49
  22. package/dist/account/src/eoa.d.ts +0 -10
  23. package/dist/account/src/eoa.js +0 -21
  24. package/dist/account/src/index.d.ts +0 -19
  25. package/dist/account/src/index.js +0 -49
  26. package/dist/core/src/abis/index.d.ts +0 -1126
  27. package/dist/core/src/abis/index.js +0 -91
  28. package/dist/core/src/actions/StateValidator.d.ts +0 -68
  29. package/dist/core/src/actions/StateValidator.js +0 -187
  30. package/dist/core/src/actions/account.d.ts +0 -55
  31. package/dist/core/src/actions/account.js +0 -133
  32. package/dist/core/src/actions/aggregator.d.ts +0 -17
  33. package/dist/core/src/actions/aggregator.js +0 -31
  34. package/dist/core/src/actions/dvt.d.ts +0 -30
  35. package/dist/core/src/actions/dvt.js +0 -41
  36. package/dist/core/src/actions/entryPoint.d.ts +0 -90
  37. package/dist/core/src/actions/entryPoint.js +0 -211
  38. package/dist/core/src/actions/factory.d.ts +0 -215
  39. package/dist/core/src/actions/factory.js +0 -442
  40. package/dist/core/src/actions/faucet.d.ts +0 -48
  41. package/dist/core/src/actions/faucet.js +0 -337
  42. package/dist/core/src/actions/gtokenExtended.d.ts +0 -39
  43. package/dist/core/src/actions/gtokenExtended.js +0 -115
  44. package/dist/core/src/actions/index.d.ts +0 -15
  45. package/dist/core/src/actions/index.js +0 -17
  46. package/dist/core/src/actions/paymasterV4.d.ts +0 -170
  47. package/dist/core/src/actions/paymasterV4.js +0 -334
  48. package/dist/core/src/actions/registry.d.ts +0 -246
  49. package/dist/core/src/actions/registry.js +0 -667
  50. package/dist/core/src/actions/reputation.d.ts +0 -129
  51. package/dist/core/src/actions/reputation.js +0 -281
  52. package/dist/core/src/actions/sbt.d.ts +0 -191
  53. package/dist/core/src/actions/sbt.js +0 -533
  54. package/dist/core/src/actions/staking.d.ts +0 -132
  55. package/dist/core/src/actions/staking.js +0 -330
  56. package/dist/core/src/actions/superPaymaster.d.ts +0 -237
  57. package/dist/core/src/actions/superPaymaster.js +0 -644
  58. package/dist/core/src/actions/tokens.d.ts +0 -229
  59. package/dist/core/src/actions/tokens.js +0 -415
  60. package/dist/core/src/branding.d.ts +0 -30
  61. package/dist/core/src/branding.js +0 -30
  62. package/dist/core/src/clients/BaseClient.d.ts +0 -25
  63. package/dist/core/src/clients/BaseClient.js +0 -66
  64. package/dist/core/src/clients/types.d.ts +0 -60
  65. package/dist/core/src/clients/types.js +0 -1
  66. package/dist/core/src/clients.d.ts +0 -5
  67. package/dist/core/src/clients.js +0 -11
  68. package/dist/core/src/communities.d.ts +0 -52
  69. package/dist/core/src/communities.js +0 -73
  70. package/dist/core/src/config/ContractConfigManager.d.ts +0 -20
  71. package/dist/core/src/config/ContractConfigManager.js +0 -48
  72. package/dist/core/src/constants.d.ts +0 -88
  73. package/dist/core/src/constants.js +0 -125
  74. package/dist/core/src/contract-addresses.d.ts +0 -110
  75. package/dist/core/src/contract-addresses.js +0 -99
  76. package/dist/core/src/contracts.d.ts +0 -424
  77. package/dist/core/src/contracts.js +0 -343
  78. package/dist/core/src/crypto/blsSigner.d.ts +0 -64
  79. package/dist/core/src/crypto/blsSigner.js +0 -98
  80. package/dist/core/src/crypto/index.d.ts +0 -1
  81. package/dist/core/src/crypto/index.js +0 -1
  82. package/dist/core/src/index.d.ts +0 -21
  83. package/dist/core/src/index.js +0 -21
  84. package/dist/core/src/networks.d.ts +0 -127
  85. package/dist/core/src/networks.js +0 -118
  86. package/dist/core/src/requirementChecker.d.ts +0 -38
  87. package/dist/core/src/requirementChecker.js +0 -139
  88. package/dist/core/src/roles.d.ts +0 -204
  89. package/dist/core/src/roles.js +0 -211
  90. package/dist/core/src/utils/validation.d.ts +0 -24
  91. package/dist/core/src/utils/validation.js +0 -56
  92. package/dist/dapp/src/index.d.ts +0 -3
  93. package/dist/dapp/src/index.js +0 -3
  94. package/dist/dapp/src/ui/hooks/useCreditScore.d.ts +0 -13
  95. package/dist/dapp/src/ui/hooks/useCreditScore.js +0 -32
  96. package/dist/dapp/src/ui/hooks/useSuperPaymaster.d.ts +0 -8
  97. package/dist/dapp/src/ui/hooks/useSuperPaymaster.js +0 -23
  98. package/dist/dapp/src/ui/index.d.ts +0 -4
  99. package/dist/dapp/src/ui/index.js +0 -17
  100. package/dist/identity/src/index.d.ts +0 -46
  101. package/dist/identity/src/index.js +0 -94
  102. package/dist/identity/src/mysbt.d.ts +0 -13
  103. package/dist/identity/src/mysbt.js +0 -37
  104. package/dist/paymaster/src/SuperPaymaster/index.d.ts +0 -44
  105. package/dist/paymaster/src/SuperPaymaster/index.js +0 -133
  106. package/dist/paymaster/src/V4/PaymasterClient.d.ts +0 -79
  107. package/dist/paymaster/src/V4/PaymasterClient.js +0 -315
  108. package/dist/paymaster/src/V4/PaymasterOperator.d.ts +0 -41
  109. package/dist/paymaster/src/V4/PaymasterOperator.js +0 -241
  110. package/dist/paymaster/src/V4/PaymasterUtils.d.ts +0 -55
  111. package/dist/paymaster/src/V4/PaymasterUtils.js +0 -124
  112. package/dist/paymaster/src/V4/SuperPaymasterClient.d.ts +0 -21
  113. package/dist/paymaster/src/V4/SuperPaymasterClient.js +0 -73
  114. package/dist/paymaster/src/V4/index.d.ts +0 -4
  115. package/dist/paymaster/src/V4/index.js +0 -4
  116. package/dist/paymaster/src/index.d.ts +0 -2
  117. package/dist/paymaster/src/index.js +0 -4
  118. package/dist/sdk/src/clients/admin.d.ts +0 -57
  119. package/dist/sdk/src/clients/admin.js +0 -105
  120. package/dist/sdk/src/clients/community.js +0 -244
  121. package/dist/sdk/src/clients/endUser.js +0 -388
  122. package/dist/sdk/src/errors/decoder.d.ts +0 -1
  123. package/dist/sdk/src/errors/decoder.js +0 -83
  124. package/dist/sdk/src/index.d.ts +0 -16
  125. package/dist/sdk/src/index.js +0 -20
  126. package/dist/tokens/src/index.d.ts +0 -56
  127. package/dist/tokens/src/index.js +0 -230
  128. package/examples/config.json +0 -1
  129. package/examples/regression_test.d.ts +0 -2
  130. package/examples/regression_test.d.ts.map +0 -1
  131. package/examples/regression_test.js +0 -89
  132. package/examples/regression_test.js.map +0 -1
  133. package/examples/regression_test.ts +0 -106
  134. package/scripts/v2_regression/00_validate_env.ts +0 -101
  135. package/scripts/v2_regression/01_setup_and_fund.ts +0 -132
  136. package/scripts/v2_regression/02_operator_onboarding.ts +0 -174
  137. package/scripts/v2_regression/03_community_registry.ts +0 -139
  138. package/scripts/v2_regression/04_enduser_flow.ts +0 -141
  139. package/scripts/v2_regression/05_admin_audit.ts +0 -157
  140. package/scripts/validate_env.ts +0 -112
  141. /package/dist/{sdk/src/clients → clients}/ExperimentClient.d.ts +0 -0
  142. /package/dist/{sdk/src/clients → clients}/ExperimentClient.js +0 -0
  143. /package/dist/{sdk/src/clients → clients}/ExperimentClient.test.d.ts +0 -0
  144. /package/dist/{sdk/src/clients → clients}/ExperimentClient.test.js +0 -0
  145. /package/dist/{sdk/src/clients → clients}/admin.test.d.ts +0 -0
  146. /package/dist/{sdk/src/clients → clients}/admin.test.js +0 -0
  147. /package/dist/{sdk/src/clients → clients}/clients.test.d.ts +0 -0
  148. /package/dist/{sdk/src/clients → clients}/clients.test.js +0 -0
  149. /package/dist/{sdk/src/clients → clients}/community.test.d.ts +0 -0
  150. /package/dist/{sdk/src/clients → clients}/community.test.js +0 -0
  151. /package/dist/{sdk/src/clients → clients}/endUser.test.d.ts +0 -0
  152. /package/dist/{sdk/src/clients → clients}/endUser.test.js +0 -0
  153. /package/dist/{sdk/src/clients → clients}/operator.test.d.ts +0 -0
  154. /package/dist/{sdk/src/clients → clients}/operator.test.js +0 -0
  155. /package/dist/{sdk/src/errors → errors}/AAStarError.d.ts +0 -0
  156. /package/dist/{sdk/src/errors → errors}/AAStarError.js +0 -0
  157. /package/dist/{sdk/src/errors → errors}/AAStarError.test.d.ts +0 -0
  158. /package/dist/{sdk/src/errors → errors}/AAStarError.test.js +0 -0
  159. /package/dist/{sdk/src/errors → errors}/decoder.test.d.ts +0 -0
  160. /package/dist/{sdk/src/errors → errors}/decoder.test.js +0 -0
  161. /package/dist/{sdk/src/node → node}/index.d.ts +0 -0
  162. /package/dist/{sdk/src/node → node}/index.js +0 -0
  163. /package/dist/{sdk/src/types → types}/result.d.ts +0 -0
  164. /package/dist/{sdk/src/types → types}/result.js +0 -0
  165. /package/dist/{sdk/src/utils → utils}/errorHandler.d.ts +0 -0
  166. /package/dist/{sdk/src/utils → utils}/errorHandler.js +0 -0
  167. /package/dist/{sdk/src/utils → utils}/errorHandler.test.d.ts +0 -0
  168. /package/dist/{sdk/src/utils → utils}/errorHandler.test.js +0 -0
  169. /package/dist/{sdk/src/utils → utils}/eventDecoder.d.ts +0 -0
  170. /package/dist/{sdk/src/utils → utils}/eventDecoder.js +0 -0
  171. /package/dist/{sdk/src/utils → utils}/eventDecoder.test.d.ts +0 -0
  172. /package/dist/{sdk/src/utils → utils}/eventDecoder.test.js +0 -0
  173. /package/dist/{sdk/src/utils → utils}/funding.d.ts +0 -0
  174. /package/dist/{sdk/src/utils → utils}/funding.js +0 -0
  175. /package/dist/{sdk/src/utils → utils}/funding.test.d.ts +0 -0
  176. /package/dist/{sdk/src/utils → utils}/funding.test.js +0 -0
  177. /package/dist/{sdk/src/utils → utils}/keys.test.d.ts +0 -0
  178. /package/dist/{sdk/src/utils → utils}/keys.test.js +0 -0
  179. /package/dist/{sdk/src/utils → utils}/roleData.d.ts +0 -0
  180. /package/dist/{sdk/src/utils → utils}/roleData.test.d.ts +0 -0
  181. /package/dist/{sdk/src/utils → utils}/roleData.test.js +0 -0
  182. /package/dist/{sdk/src/utils → utils}/testScenarios.d.ts +0 -0
  183. /package/dist/{sdk/src/utils → utils}/testScenarios.test.d.ts +0 -0
  184. /package/dist/{sdk/src/utils → utils}/testScenarios.test.js +0 -0
  185. /package/dist/{sdk/src/utils → utils}/userOp.d.ts +0 -0
  186. /package/dist/{sdk/src/utils → utils}/userOp.test.d.ts +0 -0
  187. /package/dist/{sdk/src/utils → utils}/userOp.test.js +0 -0
@@ -1,8 +1,7 @@
1
- import { createClient, publicActions, walletActions, keccak256, stringToBytes } from 'viem';
2
- import { stakingActions, registryActions, RegistryABI, superPaymasterActions, paymasterV4Actions, PaymasterFactoryABI, tokenActions, CORE_ADDRESSES, TEST_TOKEN_ADDRESSES, TEST_ACCOUNT_ADDRESSES, validateAddress, validateAmount, validateHex, SuperPaymasterABI } from '@aastar/core';
1
+ import { createClient, erc20Abi, parseAbi, publicActions, walletActions, keccak256, stringToBytes } from 'viem';
2
+ import { stakingActions, registryActions, RegistryABI, superPaymasterActions, paymasterActions, PaymasterFactoryABI, CORE_ADDRESSES, TEST_TOKEN_ADDRESSES, TEST_ACCOUNT_ADDRESSES } from '@aastar/core';
3
3
  import { RoleDataFactory } from '../utils/roleData.js';
4
- import { createError } from '../errors/AAStarError.js';
5
- import { decodeContractEvents, logDecodedEvents } from '../utils/eventDecoder.js';
4
+ import { decodeContractError } from '../errors/decoder.js';
6
5
  export function createOperatorClient({ chain, transport, account, addresses }) {
7
6
  const client = createClient({
8
7
  chain,
@@ -15,40 +14,42 @@ export function createOperatorClient({ chain, transport, account, addresses }) {
15
14
  const spActions = superPaymasterActions(usedAddresses.superPaymaster)(client);
16
15
  const regActions = registryActions(usedAddresses.registry)(client);
17
16
  const stkActions = stakingActions(usedAddresses.gTokenStaking)(client);
18
- const p4Actions = paymasterV4Actions(usedAddresses.paymasterV4)(client);
19
- const tokActions = tokenActions()(client);
17
+ const pmV4Actions = paymasterActions(usedAddresses.paymasterV4)(client);
20
18
  const actions = {
21
- ...client,
22
- ...publicActions(client),
23
- ...walletActions(client),
24
- ...regActions,
25
- ...spActions,
26
- ...p4Actions,
27
19
  ...stkActions,
28
- ...tokActions,
20
+ ...spActions,
21
+ ...pmV4Actions,
22
+ ...regActions,
29
23
  async setup(args) {
30
24
  console.log('⚙️ Setting up operator...');
31
- const txs = await this.onboardFully(args);
25
+ const txs = await this._onboardOperator(args);
32
26
  console.log(`✅ Operator setup complete! Transactions: ${txs.length}`);
33
27
  return { txs };
34
28
  },
35
29
  async onboardOperator(args) {
36
30
  return this.onboardFully(args);
37
31
  },
38
- async onboardToSuperPaymaster(args) {
39
- return this.onboardFully(args);
40
- },
41
32
  async onboardFully(args) {
42
- validateAmount(args.stakeAmount, 'Stake Amount');
43
- validateAmount(args.depositAmount, 'Deposit Amount');
44
- validateHex(args.roleId, 'Role ID');
45
- if (args.gasTokens) {
46
- args.gasTokens.forEach((token, index) => validateAddress(token, `Gas Token [${index}]`));
47
- }
48
- const results = [];
33
+ return this._onboardOperator(args);
34
+ },
35
+ async deployPaymasterV4({ version = 'v4.1', initData = '0x' } = {}) {
36
+ console.log(` SDK: Deploying Paymaster V4 (${version})...`);
37
+ const tx = await client.writeContract({
38
+ address: usedAddresses.paymasterFactory,
39
+ abi: PaymasterFactoryABI,
40
+ functionName: 'deployPaymaster',
41
+ args: [version, initData],
42
+ account,
43
+ chain
44
+ });
45
+ await client.waitForTransactionReceipt({ hash: tx });
46
+ return tx;
47
+ },
48
+ async _onboardOperator({ stakeAmount, depositAmount, roleId, roleData }) {
49
+ const txs = [];
49
50
  const accountToUse = account;
50
51
  if (!accountToUse)
51
- throw createError.validation("Account", "Account required for onboarding");
52
+ throw new Error("Account required for onboarding");
52
53
  try {
53
54
  // 1. Fetch Entry Burn & Approve GToken
54
55
  console.log(' SDK: Fetching role config for entry burn...');
@@ -56,35 +57,35 @@ export function createOperatorClient({ chain, transport, account, addresses }) {
56
57
  address: usedAddresses.registry,
57
58
  abi: RegistryABI,
58
59
  functionName: 'roleConfigs',
59
- args: [args.roleId]
60
+ args: [roleId]
60
61
  });
61
62
  const entryBurn = roleConfig[1];
62
- const totalStakeNeeded = args.stakeAmount + entryBurn;
63
- console.log(` SDK: Approving GToken (Stake: ${args.stakeAmount}, Burn: ${entryBurn})...`);
64
- const approveStkTx = await tokActions.tokenApprove({
65
- token: usedAddresses.gToken,
66
- spender: usedAddresses.gTokenStaking,
67
- amount: totalStakeNeeded,
68
- account: accountToUse
63
+ const totalStakeNeeded = stakeAmount + entryBurn;
64
+ console.log(` SDK: Approving GToken (Stake: ${stakeAmount}, Burn: ${entryBurn})...`);
65
+ const approveGToken = await client.writeContract({
66
+ address: usedAddresses.gToken,
67
+ abi: erc20Abi,
68
+ functionName: 'approve',
69
+ args: [usedAddresses.gTokenStaking, totalStakeNeeded],
70
+ account: accountToUse,
71
+ chain
69
72
  });
70
- let receipt = await client.waitForTransactionReceipt({ hash: approveStkTx });
71
- let events = decodeContractEvents(receipt.logs);
72
- logDecodedEvents(events);
73
- results.push({ hash: approveStkTx, events });
73
+ await client.waitForTransactionReceipt({ hash: approveGToken });
74
+ txs.push(approveGToken);
74
75
  // 2. Register Role
75
76
  let data;
76
- if (args.roleData && args.roleData !== '0x') {
77
- data = args.roleData;
77
+ if (roleData && roleData !== '0x') {
78
+ data = roleData;
78
79
  }
79
80
  else {
80
- console.log(` SDK: Auto-generating roleData for roleId ${args.roleId}...`);
81
- if (args.roleId === keccak256(stringToBytes('COMMUNITY'))) {
81
+ console.log(` SDK: Auto-generating roleData for roleId ${roleId}...`);
82
+ if (roleId === keccak256(stringToBytes('COMMUNITY'))) {
82
83
  data = RoleDataFactory.community();
83
84
  }
84
- else if (args.roleId === keccak256(stringToBytes('ENDUSER'))) {
85
+ else if (roleId === keccak256(stringToBytes('ENDUSER'))) {
85
86
  data = RoleDataFactory.endUser();
86
87
  }
87
- else if (args.roleId === keccak256(stringToBytes('PAYMASTER_SUPER'))) {
88
+ else if (roleId === keccak256(stringToBytes('PAYMASTER_SUPER'))) {
88
89
  data = RoleDataFactory.paymasterSuper();
89
90
  }
90
91
  else {
@@ -92,88 +93,58 @@ export function createOperatorClient({ chain, transport, account, addresses }) {
92
93
  }
93
94
  }
94
95
  console.log(` SDK: Checking if role already granted...`);
95
- const hasRoleResult = await regActions.registryHasRole({
96
- user: accountToUse.address,
97
- roleId: args.roleId
96
+ const hasRoleResult = await client.readContract({
97
+ address: usedAddresses.registry,
98
+ abi: RegistryABI,
99
+ functionName: 'hasRole',
100
+ args: [roleId, accountToUse.address]
98
101
  });
99
102
  if (hasRoleResult) {
100
103
  console.log(` ℹ️ Role already granted, skipping registration`);
101
104
  }
102
105
  else {
103
- console.log(` SDK: Registering role ${args.roleId}...`);
104
- const registerTx = await regActions.registryRegisterRoleSelf({
105
- roleId: args.roleId,
106
+ console.log(` SDK: Registering role ${roleId}...`);
107
+ const registerTx = await actions.registerRoleSelf({
108
+ roleId,
106
109
  data,
107
110
  account: accountToUse
108
111
  });
109
- const receipt = await client.waitForTransactionReceipt({ hash: registerTx });
110
- const events = decodeContractEvents(receipt.logs);
111
- logDecodedEvents(events);
112
- results.push({ hash: registerTx, events });
112
+ await client.waitForTransactionReceipt({ hash: registerTx });
113
+ txs.push(registerTx);
113
114
  }
114
- // 3. Deposit aPNTs
115
- if (args.depositAmount > 0n) {
116
- console.log(' SDK: Depositing aPNTs via superPaymasterDepositFor...');
117
- const depositTx = await spActions.superPaymasterDepositFor({
118
- operator: accountToUse.address,
119
- amount: args.depositAmount,
120
- account: accountToUse
115
+ if (depositAmount > 0n) {
116
+ console.log(' SDK: Depositing aPNTs via depositFor...');
117
+ const depositTx = await client.writeContract({
118
+ address: usedAddresses.superPaymaster,
119
+ abi: parseAbi(['function depositFor(address targetOperator, uint256 amount) external']),
120
+ functionName: 'depositFor',
121
+ args: [accountToUse.address, depositAmount],
122
+ account: accountToUse,
123
+ chain
121
124
  });
122
- const receipt = await client.waitForTransactionReceipt({ hash: depositTx });
123
- const events = decodeContractEvents(receipt.logs);
124
- logDecodedEvents(events);
125
- results.push({ hash: depositTx, events });
125
+ await client.waitForTransactionReceipt({ hash: depositTx });
126
+ txs.push(depositTx);
126
127
  }
127
- return results;
128
+ return txs;
128
129
  }
129
130
  catch (error) {
130
- // const decodedMsg = decodeContractError(error);
131
- // throw decodedMsg ? new Error(`Onboarding Failed: ${decodedMsg}`) : error;
132
- throw error;
131
+ const decodedMsg = decodeContractError(error);
132
+ throw decodedMsg ? new Error(`Onboarding Failed: ${decodedMsg}`) : error;
133
133
  }
134
134
  },
135
- async deployPaymasterV4({ version = 'v4.1', initData = '0x' } = {}) {
136
- console.log(` SDK: Deploying Paymaster V4 (${version})...`);
137
- const tx = await client.writeContract({
138
- address: usedAddresses.paymasterFactory,
139
- abi: PaymasterFactoryABI,
140
- functionName: 'deployPaymaster',
141
- args: [version, initData],
142
- account,
143
- chain
144
- });
145
- await client.waitForTransactionReceipt({ hash: tx });
146
- return tx;
135
+ async onboardToSuperPaymaster(args) {
136
+ return this.onboardOperator(args);
147
137
  },
148
138
  async configureOperator({ xPNTsToken, treasury, exchangeRate, account: accountOverride }) {
149
- validateAddress(xPNTsToken, 'xPNTs Token');
150
- validateAddress(treasury, 'Treasury');
151
- validateAmount(exchangeRate, 'Exchange Rate');
152
- const tx = await spActions.superPaymasterConfigureOperator({
139
+ const tx = await spActions.configureOperator({
153
140
  xPNTsToken,
154
- treasury,
141
+ opTreasury: treasury,
155
142
  exchangeRate,
156
143
  account: accountOverride || account
157
144
  });
158
145
  await client.waitForTransactionReceipt({ hash: tx });
159
146
  return tx;
160
147
  },
161
- async checkReadiness() {
162
- if (!account)
163
- throw createError.validation("Account", "Account required for readiness check");
164
- const addr = account.address;
165
- const roleId = keccak256(stringToBytes('PAYMASTER_SUPER'));
166
- const roleStatus = await regActions.registryHasRole({ user: addr, roleId });
167
- const operatorData = await spActions.superPaymasterOperators({ operator: addr });
168
- // operators(address) returns (uint128 aPNTsBalance, uint96 exchangeRate, bool isConfigured, bool isPaused, ...)
169
- return {
170
- isRegistered: roleStatus,
171
- isConfigured: operatorData[2],
172
- collateralBalance: operatorData[0],
173
- isPaused: operatorData[3],
174
- roleStatus
175
- };
176
- },
177
148
  async getOperatorStatus(accountAddress) {
178
149
  try {
179
150
  const hasRole = await client.readContract({
@@ -186,9 +157,10 @@ export function createOperatorClient({ chain, transport, account, addresses }) {
186
157
  let superPaymasterInfo = null;
187
158
  let paymasterV4Info = null;
188
159
  if (hasRole && usedAddresses.superPaymaster) {
160
+ const pmAbi = parseAbi(['function operators(address) view returns (uint128 balance, uint96 exchangeRate, bool isConfigured, bool isPaused, address token, uint32 reputation, address treasury, uint256 spent, uint256 txSponsored)']);
189
161
  const operatorData = await client.readContract({
190
162
  address: usedAddresses.superPaymaster,
191
- abi: SuperPaymasterABI,
163
+ abi: pmAbi,
192
164
  functionName: 'operators',
193
165
  args: [accountAddress]
194
166
  });
@@ -206,9 +178,10 @@ export function createOperatorClient({ chain, transport, account, addresses }) {
206
178
  // 检查 Paymaster V4 (Direct)
207
179
  if (usedAddresses.paymasterFactory && usedAddresses.paymasterFactory !== '0x0000000000000000000000000000000000000000') {
208
180
  try {
181
+ const factoryAbi = parseAbi(['function getPaymasterByOperator(address) view returns (address)']);
209
182
  const pmAddr = await client.readContract({
210
183
  address: usedAddresses.paymasterFactory,
211
- abi: PaymasterFactoryABI,
184
+ abi: factoryAbi,
212
185
  functionName: 'getPaymasterByOperator',
213
186
  args: [accountAddress]
214
187
  });
@@ -230,17 +203,6 @@ export function createOperatorClient({ chain, transport, account, addresses }) {
230
203
  console.error('Error in getOperatorStatus:', error);
231
204
  return { type: null, superPaymaster: null, paymasterV4: null };
232
205
  }
233
- },
234
- async isOperator(operator) {
235
- const data = await spActions.superPaymasterOperators({ operator });
236
- return data[2]; // isConfigured
237
- },
238
- async getDepositDetails() {
239
- const deposit = await spActions.superPaymasterGetDeposit();
240
- return { deposit };
241
- },
242
- async deposit(args) {
243
- return this.superPaymasterDeposit(args);
244
206
  }
245
207
  };
246
208
  return Object.assign(client, actions);
@@ -0,0 +1,6 @@
1
+ export declare const CustomErrors: {
2
+ readonly RoleNotConfigured: "RoleNotConfigured(bytes32,bool)";
3
+ readonly RoleAlreadyGranted: "RoleAlreadyGranted(bytes32,address)";
4
+ readonly InsufficientStake: "InsufficientStake(uint256,uint256)";
5
+ };
6
+ export declare function decodeContractError(error: any): string | null;
@@ -0,0 +1,44 @@
1
+ import { decodeErrorResult } from 'viem';
2
+ import { RegistryABI } from '../index.js'; // Assuming RegistryABI is exported
3
+ export const CustomErrors = {
4
+ RoleNotConfigured: 'RoleNotConfigured(bytes32,bool)',
5
+ RoleAlreadyGranted: 'RoleAlreadyGranted(bytes32,address)',
6
+ InsufficientStake: 'InsufficientStake(uint256,uint256)',
7
+ };
8
+ export function decodeContractError(error) {
9
+ if (!error || typeof error !== 'object')
10
+ return null;
11
+ // Check if it's a viem ContractFunctionExecutionError
12
+ if (error.name === 'ContractFunctionExecutionError' || error.walk) {
13
+ // Try to extract internal error data
14
+ const internalError = error.walk ? error.walk((e) => e.data) : error;
15
+ const data = internalError?.data;
16
+ if (data) {
17
+ try {
18
+ const decoded = decodeErrorResult({
19
+ abi: RegistryABI,
20
+ data: data
21
+ });
22
+ if (decoded.errorName === 'RoleNotConfigured') {
23
+ const [roleId, isActive] = decoded.args;
24
+ return `RoleNotConfigured: Role ${roleId} is ${isActive ? 'ACTIVE' : 'INACTIVE'} in Registry.`;
25
+ }
26
+ if (decoded.errorName === 'RoleAlreadyGranted') {
27
+ const [roleId, user] = decoded.args;
28
+ return `RoleAlreadyGranted: User ${user} already has role ${roleId}.`;
29
+ }
30
+ if (decoded.errorName === 'InsufficientStake') {
31
+ const [stake, minStake] = decoded.args;
32
+ // Viem returns bigints, format them?
33
+ return `InsufficientStake: Provided ${stake}, Required ${minStake}.`;
34
+ }
35
+ return `${decoded.errorName}: ${decoded.args}`;
36
+ }
37
+ catch (e) {
38
+ // ABI mismatch or unknown error
39
+ return null;
40
+ }
41
+ }
42
+ }
43
+ return null;
44
+ }
@@ -0,0 +1,18 @@
1
+ export * from '@aastar/core';
2
+ export * from '@aastar/account';
3
+ export * from '@aastar/paymaster';
4
+ export * from '@aastar/identity';
5
+ export * from '@aastar/tokens';
6
+ export * from '@aastar/tokens';
7
+ export * from '@aastar/dapp';
8
+ export * from './clients/endUser.js';
9
+ export * from './clients/operator.js';
10
+ export * from './clients/community.js';
11
+ export * from './clients/admin.js';
12
+ export * from './clients/ExperimentClient.js';
13
+ export * from './utils/roleData.js';
14
+ export * from './utils/keys.js';
15
+ export * from './utils/funding.js';
16
+ export * from './utils/userOp.js';
17
+ export * from './utils/testScenarios.js';
18
+ export * from './errors/decoder.js';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ export * from '@aastar/core';
2
+ export * from '@aastar/account';
3
+ export * from '@aastar/paymaster';
4
+ export * from '@aastar/identity';
5
+ export * from '@aastar/tokens';
6
+ export * from '@aastar/tokens';
7
+ export * from '@aastar/dapp';
8
+ // export * from '@aastar/enduser'; // Commented to avoid CommunityClient conflict with clients/community.js
9
+ // Export Role-Based Clients
10
+ export * from './clients/endUser.js';
11
+ export * from './clients/operator.js';
12
+ export * from './clients/community.js';
13
+ export * from './clients/admin.js';
14
+ export * from './clients/ExperimentClient.js';
15
+ // Export Utils & Errors
16
+ export * from './utils/roleData.js';
17
+ export * from './utils/keys.js';
18
+ export * from './utils/funding.js';
19
+ export * from './utils/userOp.js';
20
+ export * from './utils/testScenarios.js';
21
+ export * from './errors/decoder.js';
@@ -1,11 +1,4 @@
1
1
  import type { Hex, Address } from 'viem';
2
- /**
3
- * ⚠️ WARNING: TESTING & NODE.JS UTILITY ONLY ⚠️
4
- *
5
- * This file uses Node.js 'fs' module and is NOT compatible with browsers.
6
- * It is intended for use in test scripts, CLI tools, and backend environments only.
7
- * DO NOT import this file in frontend/browser code.
8
- */
9
2
  /**
10
3
  * 密钥对接口
11
4
  */
@@ -66,8 +59,3 @@ export declare class KeyManager {
66
59
  */
67
60
  static printKeys(keys: KeyPair[], showPrivateKey?: boolean): void;
68
61
  }
69
- /**
70
- * 解析私钥,确保其带有 0x 前缀
71
- * @param key - 私钥字符串
72
- */
73
- export declare function parseKey(key: string): Hex;
@@ -128,10 +128,3 @@ export class KeyManager {
128
128
  console.log('─'.repeat(80));
129
129
  }
130
130
  }
131
- /**
132
- * 解析私钥,确保其带有 0x 前缀
133
- * @param key - 私钥字符串
134
- */
135
- export function parseKey(key) {
136
- return (key.startsWith('0x') ? key : `0x${key}`);
137
- }
@@ -83,14 +83,21 @@ export const RoleDataFactory = {
83
83
  ]
84
84
  }], data);
85
85
  const result = decoded[0];
86
- return {
87
- name: result.name,
88
- ensName: result.ensName,
89
- website: result.website,
90
- description: result.description,
91
- logoURI: result.logoURI,
92
- stakeAmount: result.stakeAmount
93
- };
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
+ }
94
101
  },
95
102
  decodeEndUser: (data) => {
96
103
  const decoded = decodeAbiParameters([{
@@ -104,12 +111,18 @@ export const RoleDataFactory = {
104
111
  ]
105
112
  }], data);
106
113
  const result = decoded[0];
107
- return {
108
- account: result.account,
109
- community: result.community,
110
- avatarURI: result.avatarURI,
111
- ensName: result.ensName,
112
- stakeAmount: result.stakeAmount
113
- };
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
+ }
114
127
  }
115
128
  };
@@ -13,7 +13,7 @@ export class UserOpScenarioBuilder {
13
13
  * Builds a signed PackedUserOperation for a token transfer based on the specified scenario.
14
14
  */
15
15
  static async buildTransferScenario(type, params) {
16
- const { sender, ownerAccount, recipient, tokenAddress, amount, entryPoint, chainId, publicClient, paymaster, operator, paymasterGasLimit = 300000n, paymasterPostOpGasLimit = 50000n, nonceKey = 0n, gasToken } = params;
16
+ const { sender, ownerAccount, recipient, tokenAddress, amount, entryPoint, chainId, publicClient, paymaster, operator, paymasterGasLimit = 100000n, paymasterPostOpGasLimit = 40000n, nonceKey = 0n, gasToken } = params;
17
17
  // 1. Build Token Transfer CallData
18
18
  const transferData = encodeFunctionData({
19
19
  abi: [{ name: 'transfer', type: 'function', inputs: [{ type: 'address', name: 'to' }, { type: 'uint256', name: 'amount' }], outputs: [{ type: 'bool' }] }],
@@ -99,16 +99,16 @@ export class UserOperationBuilder {
99
99
  paymasterAndData: userOp.paymasterAndData,
100
100
  signature: userOp.signature
101
101
  };
102
+ // Ensure all numeric fields are hex strings and padded
103
+ // Helper to ensure '0x' prefix and valid hex string
102
104
  const toCompactHex = (val) => {
103
105
  if (typeof val === 'bigint')
104
106
  return `0x${val.toString(16)}`;
105
107
  if (typeof val === 'number')
106
108
  return `0x${val.toString(16)}`;
107
109
  if (typeof val === 'string') {
108
- // Remove leading zeros if present (but keep 0x)
109
110
  if (val === '0x')
110
- return '0x'; // invalid quantity? Should be 0x0?
111
- // JSON-RPC Quantity: 0x0
111
+ return '0x0';
112
112
  if (val === '0x0')
113
113
  return '0x0';
114
114
  return val.replace(/^0x0+(?!$)/, '0x');
@@ -117,11 +117,6 @@ export class UserOperationBuilder {
117
117
  };
118
118
  result.nonce = toCompactHex(result.nonce);
119
119
  result.preVerificationGas = toCompactHex(result.preVerificationGas);
120
- // Note: Alchemy usually accepts non-padded Quantities for nonce/preVerificationGas.
121
- // But let's verify if strict padding is required by using viem's pad
122
- // Alchemy v0.7 Validator seems to reject PADDED Quantities (leads to 'Invalid fields').
123
- // It accepts COMPACT HEX (e.g. 0x1 instead of 0x0...01).
124
- // Viem toHex produces compact hex.
125
120
  return result;
126
121
  }
127
122
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aastar/sdk",
3
- "version": "0.16.8",
3
+ "version": "0.16.12",
4
4
  "description": "AAStar SDK - The all-in-one package for Mycelium Network",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -9,40 +9,26 @@
9
9
  "main": "dist/index.js",
10
10
  "types": "dist/index.d.ts",
11
11
  "files": [
12
- "dist",
13
- "scripts",
14
- "examples"
12
+ "dist"
15
13
  ],
16
14
  "dependencies": {
17
15
  "viem": "2.43.3",
18
- "dotenv": "17.2.3",
19
- "@aastar/account": "0.16.8",
20
- "@aastar/identity": "0.16.8",
21
- "@aastar/core": "0.16.8",
22
- "@aastar/tokens": "0.16.8",
23
- "@aastar/paymaster": "0.16.8",
24
- "@aastar/dapp": "0.16.8"
16
+ "@aastar/dapp": "0.16.12",
17
+ "@aastar/account": "0.16.12",
18
+ "@aastar/enduser": "0.16.12",
19
+ "@aastar/paymaster": "0.16.12",
20
+ "@aastar/tokens": "0.16.12",
21
+ "@aastar/core": "0.16.12",
22
+ "@aastar/identity": "0.16.12"
25
23
  },
26
24
  "devDependencies": {
27
25
  "typescript": "5.7.2"
28
26
  },
29
- "exports": {
30
- ".": {
31
- "types": "./dist/index.d.ts",
32
- "import": "./dist/index.js"
33
- },
34
- "./node": {
35
- "types": "./dist/node/index.d.ts",
36
- "import": "./dist/node/index.js"
37
- }
38
- },
39
- "license": "MIT",
40
27
  "scripts": {
41
28
  "clean": "find src -name '*.js' -o -name '*.d.ts' -o -name '*.map' | xargs rm -f",
42
29
  "prebuild": "pnpm clean",
43
30
  "build": "tsc",
44
- "lint": "ESLINT_USE_FLAT_CONFIG=false eslint src --ext .ts",
45
- "lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint src --ext .ts --fix",
46
- "example:local": "tsx examples/regression_test.ts"
31
+ "example:local": "tsx examples/regression_test.ts",
32
+ "test": "vitest run"
47
33
  }
48
34
  }
@@ -1,18 +0,0 @@
1
- import { type Address, type Hex, type LocalAccount } from 'viem';
2
- export type SimpleSmartAccount = LocalAccount & {
3
- signUserOperation: (userOp: any) => Promise<Hex>;
4
- getInitCode: () => Promise<Hex>;
5
- getDummySignature: () => Promise<Hex>;
6
- entryPoint: Address;
7
- };
8
- export declare function toSimpleSmartAccount(parameters: {
9
- client: any;
10
- owner: LocalAccount;
11
- factoryAddress: Address;
12
- entryPoint: {
13
- address: Address;
14
- version: '0.6' | '0.7';
15
- };
16
- salt?: bigint;
17
- index?: bigint;
18
- }): Promise<SimpleSmartAccount>;
@@ -1,49 +0,0 @@
1
- import { concatHex, encodeFunctionData, } from 'viem';
2
- import { SimpleAccountFactoryABI } from '@aastar/core';
3
- import { getUserOpHash } from '../index.js';
4
- export async function toSimpleSmartAccount(parameters) {
5
- const { client, owner, factoryAddress, entryPoint, index = 0n, salt = 0n } = parameters;
6
- // Calculate initCode
7
- const factoryData = encodeFunctionData({
8
- abi: SimpleAccountFactoryABI,
9
- functionName: 'createAccount',
10
- args: [owner.address, salt]
11
- });
12
- const initCode = concatHex([factoryAddress, factoryData]);
13
- // Calculate counterfactual address
14
- const address = await client.readContract({
15
- address: factoryAddress,
16
- abi: SimpleAccountFactoryABI,
17
- functionName: 'getAddress',
18
- args: [owner.address, salt]
19
- });
20
- return {
21
- address,
22
- publicKey: owner.address,
23
- source: 'custom',
24
- type: 'local',
25
- entryPoint: entryPoint.address,
26
- async signMessage({ message }) {
27
- // validating signature for smart account usually involves EIP-1271,
28
- // but here we just sign with owner for SimpleAccount which validates owner sig
29
- return owner.signMessage({ message });
30
- },
31
- async signTypedData(typedData) {
32
- return owner.signTypedData(typedData);
33
- },
34
- async signTransaction(transaction) {
35
- throw new Error('Smart Accounts cannot sign transactions directly. Use UserOperations.');
36
- },
37
- async signUserOperation(userOp) {
38
- const chainId = client.chain?.id || 31337; // Default to local anvil if not found
39
- const hash = getUserOpHash(userOp, entryPoint.address, chainId);
40
- return owner.signMessage({ message: { raw: hash } });
41
- },
42
- async getInitCode() {
43
- return initCode;
44
- },
45
- async getDummySignature() {
46
- return '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
47
- }
48
- };
49
- }