@aastar/core 0.16.7
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 +21 -0
- package/dist/abis/BLSAggregator.json +686 -0
- package/dist/abis/BLSValidator.json +42 -0
- package/dist/abis/DVTValidator.json +368 -0
- package/dist/abis/Eip7702Support.json +24 -0
- package/dist/abis/EntryPoint.json +1382 -0
- package/dist/abis/GToken.json +513 -0
- package/dist/abis/GTokenStaking.json +949 -0
- package/dist/abis/LegacyAccount.json +625 -0
- package/dist/abis/MySBT.json +1518 -0
- package/dist/abis/Paymaster.json +1143 -0
- package/dist/abis/PaymasterFactory.json +640 -0
- package/dist/abis/Registry.json +1942 -0
- package/dist/abis/ReputationSystem.json +699 -0
- package/dist/abis/SenderCreator.json +99 -0
- package/dist/abis/Simple7702Account.json +395 -0
- package/dist/abis/SimpleAccount.json +560 -0
- package/dist/abis/SimpleAccountFactory.json +111 -0
- package/dist/abis/SimpleAccountFactoryV08.json +87 -0
- package/dist/abis/SimpleAccountV08.json +557 -0
- package/dist/abis/SuperPaymaster.json +1781 -0
- package/dist/abis/UserOperationLib.json +57 -0
- package/dist/abis/abi.config.json +24 -0
- package/dist/abis/index.d.ts +1126 -0
- package/dist/abis/index.js +91 -0
- package/dist/abis/xPNTsFactory.json +718 -0
- package/dist/abis/xPNTsToken.json +1280 -0
- package/dist/actions/StateValidator.d.ts +68 -0
- package/dist/actions/StateValidator.js +187 -0
- package/dist/actions/StateValidator.test.d.ts +1 -0
- package/dist/actions/StateValidator.test.js +144 -0
- package/dist/actions/account.d.ts +55 -0
- package/dist/actions/account.js +133 -0
- package/dist/actions/account.test.d.ts +1 -0
- package/dist/actions/account.test.js +118 -0
- package/dist/actions/aggregator.d.ts +17 -0
- package/dist/actions/aggregator.js +31 -0
- package/dist/actions/aggregator.test.d.ts +1 -0
- package/dist/actions/aggregator.test.js +67 -0
- package/dist/actions/dvt.d.ts +30 -0
- package/dist/actions/dvt.js +41 -0
- package/dist/actions/dvt.test.d.ts +1 -0
- package/dist/actions/dvt.test.js +98 -0
- package/dist/actions/entryPoint.d.ts +90 -0
- package/dist/actions/entryPoint.js +211 -0
- package/dist/actions/entryPoint.test.d.ts +1 -0
- package/dist/actions/entryPoint.test.js +139 -0
- package/dist/actions/factory.d.ts +215 -0
- package/dist/actions/factory.js +442 -0
- package/dist/actions/factory.test.d.ts +1 -0
- package/dist/actions/factory.test.js +197 -0
- package/dist/actions/faucet.d.ts +48 -0
- package/dist/actions/faucet.js +337 -0
- package/dist/actions/faucet.test.d.ts +1 -0
- package/dist/actions/faucet.test.js +120 -0
- package/dist/actions/gtokenExtended.d.ts +39 -0
- package/dist/actions/gtokenExtended.js +115 -0
- package/dist/actions/gtokenExtended.test.d.ts +1 -0
- package/dist/actions/gtokenExtended.test.js +118 -0
- package/dist/actions/index.d.ts +15 -0
- package/dist/actions/index.js +17 -0
- package/dist/actions/paymasterV4.d.ts +170 -0
- package/dist/actions/paymasterV4.js +334 -0
- package/dist/actions/paymasterV4.test.d.ts +1 -0
- package/dist/actions/paymasterV4.test.js +159 -0
- package/dist/actions/registry.d.ts +246 -0
- package/dist/actions/registry.js +667 -0
- package/dist/actions/registry.test.d.ts +1 -0
- package/dist/actions/registry.test.js +360 -0
- package/dist/actions/reputation.d.ts +129 -0
- package/dist/actions/reputation.js +281 -0
- package/dist/actions/reputation.test.d.ts +1 -0
- package/dist/actions/reputation.test.js +169 -0
- package/dist/actions/sbt.d.ts +191 -0
- package/dist/actions/sbt.js +533 -0
- package/dist/actions/sbt.test.d.ts +1 -0
- package/dist/actions/sbt.test.js +256 -0
- package/dist/actions/staking.d.ts +132 -0
- package/dist/actions/staking.js +330 -0
- package/dist/actions/staking.test.d.ts +1 -0
- package/dist/actions/staking.test.js +223 -0
- package/dist/actions/superPaymaster.d.ts +237 -0
- package/dist/actions/superPaymaster.js +644 -0
- package/dist/actions/superPaymaster.test.d.ts +1 -0
- package/dist/actions/superPaymaster.test.js +287 -0
- package/dist/actions/tokens.d.ts +229 -0
- package/dist/actions/tokens.js +415 -0
- package/dist/actions/tokens.test.d.ts +1 -0
- package/dist/actions/tokens.test.js +53 -0
- package/dist/actions/validators.d.ts +194 -0
- package/dist/actions/validators.js +433 -0
- package/dist/actions/validators.test.d.ts +1 -0
- package/dist/actions/validators.test.js +215 -0
- package/dist/branding.d.ts +30 -0
- package/dist/branding.js +30 -0
- package/dist/clients/BaseClient.d.ts +25 -0
- package/dist/clients/BaseClient.js +66 -0
- package/dist/clients/types.d.ts +60 -0
- package/dist/clients/types.js +1 -0
- package/dist/clients.d.ts +5 -0
- package/dist/clients.js +11 -0
- package/dist/communities.d.ts +52 -0
- package/dist/communities.js +73 -0
- package/dist/config/ContractConfigManager.d.ts +20 -0
- package/dist/config/ContractConfigManager.js +48 -0
- package/dist/constants.d.ts +88 -0
- package/dist/constants.js +125 -0
- package/dist/contract-addresses.d.ts +110 -0
- package/dist/contract-addresses.js +99 -0
- package/dist/contracts.d.ts +424 -0
- package/dist/contracts.js +343 -0
- package/dist/contracts.test.d.ts +1 -0
- package/dist/contracts.test.js +40 -0
- package/dist/crypto/blsSigner.d.ts +64 -0
- package/dist/crypto/blsSigner.js +98 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/networks.d.ts +127 -0
- package/dist/networks.js +118 -0
- package/dist/requirementChecker.d.ts +38 -0
- package/dist/requirementChecker.js +139 -0
- package/dist/requirementChecker.test.d.ts +1 -0
- package/dist/requirementChecker.test.js +60 -0
- package/dist/roles.d.ts +204 -0
- package/dist/roles.js +211 -0
- package/dist/roles.test.d.ts +1 -0
- package/dist/roles.test.js +23 -0
- package/dist/utils/validation.d.ts +24 -0
- package/dist/utils/validation.js +56 -0
- package/dist/utils/validation.test.d.ts +1 -0
- package/dist/utils/validation.test.js +40 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +14 -0
- package/package.json +33 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { GTokenABI, xPNTsTokenABI } from '../abis/index.js';
|
|
2
|
+
function getTokenABI(token) {
|
|
3
|
+
// Auto-detect ABI based on token type or use generic xPNTsTokenABI
|
|
4
|
+
return xPNTsTokenABI;
|
|
5
|
+
}
|
|
6
|
+
export const gTokenActions = () => (client) => ({
|
|
7
|
+
// Use GTokenABI for everything
|
|
8
|
+
...tokenActions()(client),
|
|
9
|
+
async tokenTotalSupply({ token }) {
|
|
10
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'totalSupply', args: [] });
|
|
11
|
+
},
|
|
12
|
+
async tokenBalanceOf({ token, account }) {
|
|
13
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'balanceOf', args: [account] });
|
|
14
|
+
},
|
|
15
|
+
async tokenTransfer({ token, to, amount, account }) {
|
|
16
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'transfer', args: [to, amount], account: account, chain: client.chain });
|
|
17
|
+
},
|
|
18
|
+
async tokenTransferFrom({ token, from, to, amount, account }) {
|
|
19
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'transferFrom', args: [from, to, amount], account: account, chain: client.chain });
|
|
20
|
+
},
|
|
21
|
+
async tokenApprove({ token, spender, amount, account }) {
|
|
22
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'approve', args: [spender, amount], account: account, chain: client.chain });
|
|
23
|
+
},
|
|
24
|
+
async tokenAllowance({ token, owner, spender }) {
|
|
25
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'allowance', args: [owner, spender] });
|
|
26
|
+
},
|
|
27
|
+
async tokenMint({ token, to, amount, account }) {
|
|
28
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'mint', args: [to, amount], account: account, chain: client.chain });
|
|
29
|
+
},
|
|
30
|
+
async tokenBurn({ token, amount, account }) {
|
|
31
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'burn', args: [amount], account: account, chain: client.chain });
|
|
32
|
+
},
|
|
33
|
+
async tokenBurnFrom({ token, from, amount, account }) {
|
|
34
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'burnFrom', args: [from, amount], account: account, chain: client.chain });
|
|
35
|
+
},
|
|
36
|
+
async tokenName({ token }) {
|
|
37
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'name', args: [] });
|
|
38
|
+
},
|
|
39
|
+
async tokenSymbol({ token }) {
|
|
40
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'symbol', args: [] });
|
|
41
|
+
},
|
|
42
|
+
async tokenDecimals({ token }) {
|
|
43
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'decimals', args: [] });
|
|
44
|
+
},
|
|
45
|
+
async tokenOwner({ token }) {
|
|
46
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'owner', args: [] });
|
|
47
|
+
},
|
|
48
|
+
async tokenTransferTokenOwnership({ token, newOwner, account }) {
|
|
49
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'transferOwnership', args: [newOwner], account: account, chain: client.chain });
|
|
50
|
+
},
|
|
51
|
+
async tokenRenounceOwnership({ token, account }) {
|
|
52
|
+
return client.writeContract({ address: token, abi: GTokenABI, functionName: 'renounceOwnership', args: [], account: account, chain: client.chain });
|
|
53
|
+
},
|
|
54
|
+
async tokenCap({ token }) {
|
|
55
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'cap', args: [] });
|
|
56
|
+
},
|
|
57
|
+
async tokenRemainingMintableSupply({ token }) {
|
|
58
|
+
return client.readContract({ address: token, abi: GTokenABI, functionName: 'remainingMintableSupply', args: [] });
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
export const tokenActions = () => (client) => ({
|
|
62
|
+
// ERC20 Standard
|
|
63
|
+
async tokenTotalSupply({ token }) {
|
|
64
|
+
return client.readContract({
|
|
65
|
+
address: token,
|
|
66
|
+
abi: getTokenABI(token),
|
|
67
|
+
functionName: 'totalSupply',
|
|
68
|
+
args: []
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
async tokenCap({ token }) {
|
|
72
|
+
return client.readContract({
|
|
73
|
+
address: token,
|
|
74
|
+
abi: getTokenABI(token),
|
|
75
|
+
functionName: 'cap',
|
|
76
|
+
args: []
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
async tokenRemainingMintableSupply({ token }) {
|
|
80
|
+
return client.readContract({
|
|
81
|
+
address: token,
|
|
82
|
+
abi: getTokenABI(token),
|
|
83
|
+
functionName: 'remainingMintableSupply',
|
|
84
|
+
args: []
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
async tokenBalanceOf({ token, account }) {
|
|
88
|
+
return client.readContract({
|
|
89
|
+
address: token,
|
|
90
|
+
abi: getTokenABI(token),
|
|
91
|
+
functionName: 'balanceOf',
|
|
92
|
+
args: [account]
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
async tokenTransfer({ token, to, amount, account }) {
|
|
96
|
+
return client.writeContract({
|
|
97
|
+
address: token,
|
|
98
|
+
abi: getTokenABI(token),
|
|
99
|
+
functionName: 'transfer',
|
|
100
|
+
args: [to, amount],
|
|
101
|
+
account: account,
|
|
102
|
+
chain: client.chain
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
async tokenTransferFrom({ token, from, to, amount, account }) {
|
|
106
|
+
return client.writeContract({
|
|
107
|
+
address: token,
|
|
108
|
+
abi: getTokenABI(token),
|
|
109
|
+
functionName: 'transferFrom',
|
|
110
|
+
args: [from, to, amount],
|
|
111
|
+
account: account,
|
|
112
|
+
chain: client.chain
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
async tokenApprove({ token, spender, amount, account }) {
|
|
116
|
+
return client.writeContract({
|
|
117
|
+
address: token,
|
|
118
|
+
abi: getTokenABI(token),
|
|
119
|
+
functionName: 'approve',
|
|
120
|
+
args: [spender, amount],
|
|
121
|
+
account: account,
|
|
122
|
+
chain: client.chain
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
async tokenAllowance({ token, owner, spender }) {
|
|
126
|
+
return client.readContract({
|
|
127
|
+
address: token,
|
|
128
|
+
abi: getTokenABI(token),
|
|
129
|
+
functionName: 'allowance',
|
|
130
|
+
args: [owner, spender]
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
// Mintable/Burnable
|
|
134
|
+
async tokenMint({ token, to, amount, account }) {
|
|
135
|
+
return client.writeContract({
|
|
136
|
+
address: token,
|
|
137
|
+
abi: getTokenABI(token),
|
|
138
|
+
functionName: 'mint',
|
|
139
|
+
args: [to, amount],
|
|
140
|
+
account: account,
|
|
141
|
+
chain: client.chain
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
async tokenBurn({ token, amount, account }) {
|
|
145
|
+
return client.writeContract({
|
|
146
|
+
address: token,
|
|
147
|
+
abi: getTokenABI(token),
|
|
148
|
+
functionName: 'burn',
|
|
149
|
+
args: [amount],
|
|
150
|
+
account: account,
|
|
151
|
+
chain: client.chain
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
async tokenBurnFrom({ token, from, amount, account }) {
|
|
155
|
+
return client.writeContract({
|
|
156
|
+
address: token,
|
|
157
|
+
abi: getTokenABI(token),
|
|
158
|
+
functionName: 'burnFrom',
|
|
159
|
+
args: [from, amount],
|
|
160
|
+
account: account,
|
|
161
|
+
chain: client.chain
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
// ERC20 Metadata
|
|
165
|
+
async tokenName({ token }) {
|
|
166
|
+
return client.readContract({
|
|
167
|
+
address: token,
|
|
168
|
+
abi: getTokenABI(token),
|
|
169
|
+
functionName: 'name',
|
|
170
|
+
args: []
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
async tokenSymbol({ token }) {
|
|
174
|
+
return client.readContract({
|
|
175
|
+
address: token,
|
|
176
|
+
abi: getTokenABI(token),
|
|
177
|
+
functionName: 'symbol',
|
|
178
|
+
args: []
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
async tokenDecimals({ token }) {
|
|
182
|
+
return client.readContract({
|
|
183
|
+
address: token,
|
|
184
|
+
abi: getTokenABI(token),
|
|
185
|
+
functionName: 'decimals',
|
|
186
|
+
args: []
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
// Ownable
|
|
190
|
+
async tokenOwner({ token }) {
|
|
191
|
+
return client.readContract({
|
|
192
|
+
address: token,
|
|
193
|
+
abi: getTokenABI(token),
|
|
194
|
+
functionName: 'owner',
|
|
195
|
+
args: []
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
async tokenTransferTokenOwnership({ token, newOwner, account }) {
|
|
199
|
+
return client.writeContract({
|
|
200
|
+
address: token,
|
|
201
|
+
abi: getTokenABI(token),
|
|
202
|
+
functionName: 'transferOwnership',
|
|
203
|
+
args: [newOwner],
|
|
204
|
+
account: account,
|
|
205
|
+
chain: client.chain
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
async tokenRenounceOwnership({ token, account }) {
|
|
209
|
+
return client.writeContract({
|
|
210
|
+
address: token,
|
|
211
|
+
abi: getTokenABI(token),
|
|
212
|
+
functionName: 'renounceOwnership',
|
|
213
|
+
args: [],
|
|
214
|
+
account: account,
|
|
215
|
+
chain: client.chain
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
// xPNTs/aPNTs specific
|
|
219
|
+
async tokenUpdateExchangeRate({ token, newRate, account }) {
|
|
220
|
+
return client.writeContract({
|
|
221
|
+
address: token,
|
|
222
|
+
abi: getTokenABI(token),
|
|
223
|
+
functionName: 'updateExchangeRate',
|
|
224
|
+
args: [newRate],
|
|
225
|
+
account: account,
|
|
226
|
+
chain: client.chain
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
async tokenGetDebt({ token, user }) {
|
|
230
|
+
return client.readContract({
|
|
231
|
+
address: token,
|
|
232
|
+
abi: getTokenABI(token),
|
|
233
|
+
functionName: 'getDebt',
|
|
234
|
+
args: [user]
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
async tokenRepayDebt({ token, amount, account }) {
|
|
238
|
+
return client.writeContract({
|
|
239
|
+
address: token,
|
|
240
|
+
abi: getTokenABI(token),
|
|
241
|
+
functionName: 'repayDebt',
|
|
242
|
+
args: [amount],
|
|
243
|
+
account: account,
|
|
244
|
+
chain: client.chain
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
async tokenTransferAndCall({ token, to, amount, data = '0x', account }) {
|
|
248
|
+
return client.writeContract({
|
|
249
|
+
address: token,
|
|
250
|
+
abi: getTokenABI(token),
|
|
251
|
+
functionName: 'transferAndCall',
|
|
252
|
+
args: [to, amount, data],
|
|
253
|
+
account: account,
|
|
254
|
+
chain: client.chain
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
// Auto Approval
|
|
258
|
+
async tokenAddAutoApprovedSpender({ token, spender, account }) {
|
|
259
|
+
return client.writeContract({
|
|
260
|
+
address: token,
|
|
261
|
+
abi: xPNTsTokenABI,
|
|
262
|
+
functionName: 'addAutoApprovedSpender',
|
|
263
|
+
args: [spender],
|
|
264
|
+
account: account,
|
|
265
|
+
chain: client.chain
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
async tokenRemoveAutoApprovedSpender({ token, spender, account }) {
|
|
269
|
+
return client.writeContract({
|
|
270
|
+
address: token,
|
|
271
|
+
abi: xPNTsTokenABI,
|
|
272
|
+
functionName: 'removeAutoApprovedSpender',
|
|
273
|
+
args: [spender],
|
|
274
|
+
account: account,
|
|
275
|
+
chain: client.chain
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
async tokenIsAutoApprovedSpender({ token, spender }) {
|
|
279
|
+
return client.readContract({
|
|
280
|
+
address: token,
|
|
281
|
+
abi: xPNTsTokenABI,
|
|
282
|
+
functionName: 'isAutoApprovedSpender',
|
|
283
|
+
args: [spender]
|
|
284
|
+
});
|
|
285
|
+
},
|
|
286
|
+
// Constants
|
|
287
|
+
async tokenSUPERPAYMASTER_ADDRESS({ token }) {
|
|
288
|
+
return client.readContract({
|
|
289
|
+
address: token,
|
|
290
|
+
abi: xPNTsTokenABI,
|
|
291
|
+
functionName: 'SUPERPAYMASTER_ADDRESS',
|
|
292
|
+
args: []
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
async tokenFACTORY({ token }) {
|
|
296
|
+
return client.readContract({
|
|
297
|
+
address: token,
|
|
298
|
+
abi: xPNTsTokenABI,
|
|
299
|
+
functionName: 'FACTORY',
|
|
300
|
+
args: []
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
async tokenTransferOwnership(args) {
|
|
304
|
+
return this.tokenTransferTokenOwnership(args);
|
|
305
|
+
},
|
|
306
|
+
async tokenTransferCommunityOwnership({ token, newOwner, account }) {
|
|
307
|
+
return client.writeContract({
|
|
308
|
+
address: token,
|
|
309
|
+
abi: xPNTsTokenABI,
|
|
310
|
+
functionName: 'transferCommunityOwnership',
|
|
311
|
+
args: [newOwner],
|
|
312
|
+
account: account,
|
|
313
|
+
chain: client.chain
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
// xPNTs Views
|
|
317
|
+
async tokenCommunityName({ token }) {
|
|
318
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'communityName', args: [] });
|
|
319
|
+
},
|
|
320
|
+
async tokenCommunityENS({ token }) {
|
|
321
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'communityENS', args: [] });
|
|
322
|
+
},
|
|
323
|
+
async tokenExchangeRate({ token }) {
|
|
324
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'exchangeRate', args: [] });
|
|
325
|
+
},
|
|
326
|
+
async tokenSpendingLimits({ token, user }) {
|
|
327
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'spendingLimits', args: [user] });
|
|
328
|
+
},
|
|
329
|
+
async tokenDefaultSpendingLimitXPNTs({ token }) {
|
|
330
|
+
try {
|
|
331
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'defaultSpendingLimitXPNTs', args: [] });
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'getDefaultSpendingLimitXPNTs', args: [] });
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
async tokenCumulativeSpent({ token, user }) {
|
|
338
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'cumulativeSpent', args: [user] });
|
|
339
|
+
},
|
|
340
|
+
async tokenDebts({ token, user }) {
|
|
341
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'debts', args: [user] });
|
|
342
|
+
},
|
|
343
|
+
async tokenUsedOpHashes({ token, hash }) {
|
|
344
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'usedOpHashes', args: [hash] });
|
|
345
|
+
},
|
|
346
|
+
// EIP2612
|
|
347
|
+
async tokenDOMAIN_SEPARATOR({ token }) {
|
|
348
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'DOMAIN_SEPARATOR', args: [] });
|
|
349
|
+
},
|
|
350
|
+
async tokenNonces({ token, owner }) {
|
|
351
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'nonces', args: [owner] });
|
|
352
|
+
},
|
|
353
|
+
async tokenPermit({ token, owner, spender, value, deadline, v, r, s, account }) {
|
|
354
|
+
return client.writeContract({
|
|
355
|
+
address: token,
|
|
356
|
+
abi: xPNTsTokenABI,
|
|
357
|
+
functionName: 'permit',
|
|
358
|
+
args: [owner, spender, value, deadline, v, r, s],
|
|
359
|
+
account: account,
|
|
360
|
+
chain: client.chain
|
|
361
|
+
});
|
|
362
|
+
},
|
|
363
|
+
// xPNTs Additional
|
|
364
|
+
async tokenAutoApprovedSpenders({ token, spender }) {
|
|
365
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'autoApprovedSpenders', args: [spender] });
|
|
366
|
+
},
|
|
367
|
+
async tokenBurnFromWithOpHash({ token, account: user, amount, opHash, userOpAccount }) {
|
|
368
|
+
return client.writeContract({ address: token, abi: xPNTsTokenABI, functionName: 'burnFromWithOpHash', args: [user, amount, opHash], account: userOpAccount, chain: client.chain });
|
|
369
|
+
},
|
|
370
|
+
async tokenCommunityOwner({ token }) {
|
|
371
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'communityOwner', args: [] });
|
|
372
|
+
},
|
|
373
|
+
async tokenEip712Domain({ token }) {
|
|
374
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'eip712Domain', args: [] });
|
|
375
|
+
},
|
|
376
|
+
async tokenGetDefaultSpendingLimitXPNTs({ token }) {
|
|
377
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'getDefaultSpendingLimitXPNTs', args: [] });
|
|
378
|
+
},
|
|
379
|
+
async tokenGetMetadata({ token }) {
|
|
380
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'getMetadata', args: [] });
|
|
381
|
+
},
|
|
382
|
+
async tokenNeedsApproval({ token, owner, spender, amount }) {
|
|
383
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'needsApproval', args: [owner, spender, amount] });
|
|
384
|
+
},
|
|
385
|
+
async tokenRecordDebt({ token, user, amount, account }) {
|
|
386
|
+
return client.writeContract({ address: token, abi: xPNTsTokenABI, functionName: 'recordDebt', args: [user, amount], account: account, chain: client.chain });
|
|
387
|
+
},
|
|
388
|
+
async tokenDEFAULT_SPENDING_LIMIT_APNTS({ token }) {
|
|
389
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'DEFAULT_SPENDING_LIMIT_APNTS', args: [] });
|
|
390
|
+
},
|
|
391
|
+
// Admin
|
|
392
|
+
async tokenSetPaymasterLimit({ token, user, limit, account }) {
|
|
393
|
+
return client.writeContract({
|
|
394
|
+
address: token,
|
|
395
|
+
abi: xPNTsTokenABI,
|
|
396
|
+
functionName: 'setPaymasterLimit',
|
|
397
|
+
args: [user, limit],
|
|
398
|
+
account: account,
|
|
399
|
+
chain: client.chain
|
|
400
|
+
});
|
|
401
|
+
},
|
|
402
|
+
async tokenSetSuperPaymasterAddress({ token, superPaymaster, account }) {
|
|
403
|
+
return client.writeContract({
|
|
404
|
+
address: token,
|
|
405
|
+
abi: xPNTsTokenABI,
|
|
406
|
+
functionName: 'setSuperPaymasterAddress',
|
|
407
|
+
args: [superPaymaster],
|
|
408
|
+
account: account,
|
|
409
|
+
chain: client.chain
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
async tokenVersion({ token }) {
|
|
413
|
+
return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'version', args: [] });
|
|
414
|
+
}
|
|
415
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { tokenActions } from './tokens.js';
|
|
3
|
+
describe('TokenActions', () => {
|
|
4
|
+
const MOCK_ADDR = '0x1111111111111111111111111111111111111111';
|
|
5
|
+
let mockPublicClient;
|
|
6
|
+
let mockWalletClient;
|
|
7
|
+
let actions;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockPublicClient = {
|
|
10
|
+
readContract: vi.fn(),
|
|
11
|
+
simulateContract: vi.fn().mockResolvedValue({ request: {} }),
|
|
12
|
+
writeContract: vi.fn().mockResolvedValue('0xhash'),
|
|
13
|
+
sendTransaction: vi.fn().mockResolvedValue('0xhash')
|
|
14
|
+
};
|
|
15
|
+
mockWalletClient = {
|
|
16
|
+
writeContract: vi.fn().mockResolvedValue('0xhash'),
|
|
17
|
+
chain: { id: 1 }
|
|
18
|
+
};
|
|
19
|
+
actions = tokenActions()(mockPublicClient);
|
|
20
|
+
});
|
|
21
|
+
it('should read name', async () => {
|
|
22
|
+
mockPublicClient.readContract.mockResolvedValue('Test Token');
|
|
23
|
+
const name = await actions.tokenName({ token: MOCK_ADDR });
|
|
24
|
+
expect(name).toBe('Test Token');
|
|
25
|
+
expect(mockPublicClient.readContract).toHaveBeenCalledWith(expect.objectContaining({
|
|
26
|
+
functionName: 'name'
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
29
|
+
it('should read symbol', async () => {
|
|
30
|
+
mockPublicClient.readContract.mockResolvedValue('TT');
|
|
31
|
+
const symbol = await actions.tokenSymbol({ token: MOCK_ADDR });
|
|
32
|
+
expect(symbol).toBe('TT');
|
|
33
|
+
});
|
|
34
|
+
it('should transfer tokens', async () => {
|
|
35
|
+
const tx = await actions.tokenTransfer({
|
|
36
|
+
token: MOCK_ADDR,
|
|
37
|
+
to: MOCK_ADDR,
|
|
38
|
+
amount: 100n,
|
|
39
|
+
account: { address: MOCK_ADDR }
|
|
40
|
+
});
|
|
41
|
+
expect(tx).toBe('0xhash');
|
|
42
|
+
});
|
|
43
|
+
it('should handle transferFrom', async () => {
|
|
44
|
+
const tx = await actions.tokenTransferFrom({
|
|
45
|
+
token: MOCK_ADDR,
|
|
46
|
+
from: MOCK_ADDR,
|
|
47
|
+
to: MOCK_ADDR,
|
|
48
|
+
amount: 100n,
|
|
49
|
+
account: { address: MOCK_ADDR }
|
|
50
|
+
});
|
|
51
|
+
expect(tx).toBe('0xhash');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { type Address, type PublicClient, type WalletClient, type Hex, type Hash, type Account } from 'viem';
|
|
2
|
+
export type DVTActions = {
|
|
3
|
+
createProposal: (args: {
|
|
4
|
+
target: Address;
|
|
5
|
+
calldata: Hex;
|
|
6
|
+
description: string;
|
|
7
|
+
account?: Account | Address;
|
|
8
|
+
}) => Promise<Hash>;
|
|
9
|
+
signProposal: (args: {
|
|
10
|
+
proposalId: bigint;
|
|
11
|
+
account?: Account | Address;
|
|
12
|
+
}) => Promise<Hash>;
|
|
13
|
+
executeWithProof: (args: {
|
|
14
|
+
proposalId: bigint;
|
|
15
|
+
signatures: Hex[];
|
|
16
|
+
account?: Account | Address;
|
|
17
|
+
}) => Promise<Hash>;
|
|
18
|
+
cancelProposal: (args: {
|
|
19
|
+
proposalId: bigint;
|
|
20
|
+
account?: Account | Address;
|
|
21
|
+
}) => Promise<Hash>;
|
|
22
|
+
isValidator: (args: {
|
|
23
|
+
validator: Address;
|
|
24
|
+
}) => Promise<boolean>;
|
|
25
|
+
addValidator: (args: {
|
|
26
|
+
validator: Address;
|
|
27
|
+
account?: Account | Address;
|
|
28
|
+
}) => Promise<Hash>;
|
|
29
|
+
removeValidator: (args: {
|
|
30
|
+
validator: Address;
|
|
31
|
+
account?: Account | Address;
|
|
32
|
+
}) => Promise<Hash>;
|
|
33
|
+
getValidators: () => Promise<Address[]>;
|
|
34
|
+
getValidatorCount: () => Promise<bigint>;
|
|
35
|
+
getProposal: (args: {
|
|
36
|
+
proposalId: bigint;
|
|
37
|
+
}) => Promise<any>;
|
|
38
|
+
getProposalCount: () => Promise<bigint>;
|
|
39
|
+
getProposalState: (args: {
|
|
40
|
+
proposalId: bigint;
|
|
41
|
+
}) => Promise<number>;
|
|
42
|
+
getSignatureCount: (args: {
|
|
43
|
+
proposalId: bigint;
|
|
44
|
+
}) => Promise<bigint>;
|
|
45
|
+
hasVoted: (args: {
|
|
46
|
+
proposalId: bigint;
|
|
47
|
+
validator: Address;
|
|
48
|
+
}) => Promise<boolean>;
|
|
49
|
+
proposals: (args: {
|
|
50
|
+
proposalId: bigint;
|
|
51
|
+
}) => Promise<any>;
|
|
52
|
+
nextProposalId: () => Promise<bigint>;
|
|
53
|
+
threshold: () => Promise<bigint>;
|
|
54
|
+
setThreshold: (args: {
|
|
55
|
+
newThreshold: bigint;
|
|
56
|
+
account?: Account | Address;
|
|
57
|
+
}) => Promise<Hash>;
|
|
58
|
+
setRegistry: (args: {
|
|
59
|
+
registry: Address;
|
|
60
|
+
account?: Account | Address;
|
|
61
|
+
}) => Promise<Hash>;
|
|
62
|
+
setBLSAggregator: (args: {
|
|
63
|
+
aggregator: Address;
|
|
64
|
+
account?: Account | Address;
|
|
65
|
+
}) => Promise<Hash>;
|
|
66
|
+
markProposalExecuted: (args: {
|
|
67
|
+
proposalId: bigint;
|
|
68
|
+
account?: Account | Address;
|
|
69
|
+
}) => Promise<Hash>;
|
|
70
|
+
BLS_AGGREGATOR: () => Promise<Address>;
|
|
71
|
+
owner: () => Promise<Address>;
|
|
72
|
+
transferOwnership: (args: {
|
|
73
|
+
newOwner: Address;
|
|
74
|
+
account?: Account | Address;
|
|
75
|
+
}) => Promise<Hash>;
|
|
76
|
+
renounceOwnership: (args: {
|
|
77
|
+
account?: Account | Address;
|
|
78
|
+
}) => Promise<Hash>;
|
|
79
|
+
version: () => Promise<string>;
|
|
80
|
+
};
|
|
81
|
+
export type BLSAggregatorActions = {
|
|
82
|
+
registerBLSPublicKey: (args: {
|
|
83
|
+
publicKey: Hex;
|
|
84
|
+
account?: Account | Address;
|
|
85
|
+
}) => Promise<Hash>;
|
|
86
|
+
deregisterBLSPublicKey: (args: {
|
|
87
|
+
account?: Account | Address;
|
|
88
|
+
}) => Promise<Hash>;
|
|
89
|
+
updatePublicKey: (args: {
|
|
90
|
+
newKey: Hex;
|
|
91
|
+
account?: Account | Address;
|
|
92
|
+
}) => Promise<Hash>;
|
|
93
|
+
aggregateSignatures: (args: {
|
|
94
|
+
signatures: Hex[];
|
|
95
|
+
}) => Promise<Hex>;
|
|
96
|
+
verifyAggregatedSignature: (args: {
|
|
97
|
+
message: Hex;
|
|
98
|
+
aggregatedSignature: Hex;
|
|
99
|
+
publicKeys: Hex[];
|
|
100
|
+
}) => Promise<boolean>;
|
|
101
|
+
validateSignature: (args: {
|
|
102
|
+
message: Hex;
|
|
103
|
+
signature: Hex;
|
|
104
|
+
publicKey: Hex;
|
|
105
|
+
}) => Promise<boolean>;
|
|
106
|
+
executeProposal: (args: {
|
|
107
|
+
proposalId: bigint;
|
|
108
|
+
signatures: Hex[];
|
|
109
|
+
account?: Account | Address;
|
|
110
|
+
}) => Promise<Hash>;
|
|
111
|
+
verifyAndExecute: (args: {
|
|
112
|
+
proposalId: bigint;
|
|
113
|
+
signatures: Hex[];
|
|
114
|
+
account?: Account | Address;
|
|
115
|
+
}) => Promise<Hash>;
|
|
116
|
+
getPublicKey: (args: {
|
|
117
|
+
address: Address;
|
|
118
|
+
}) => Promise<Hex>;
|
|
119
|
+
aggregatedSignatures: (args: {
|
|
120
|
+
requestId: bigint;
|
|
121
|
+
}) => Promise<any>;
|
|
122
|
+
getRequestStatus: (args: {
|
|
123
|
+
requestId: bigint;
|
|
124
|
+
}) => Promise<any>;
|
|
125
|
+
getOperatorId: (args: {
|
|
126
|
+
operator: Address;
|
|
127
|
+
}) => Promise<Hex>;
|
|
128
|
+
registerOperator: (args: {
|
|
129
|
+
operator: Address;
|
|
130
|
+
blsPublicKey: Hex;
|
|
131
|
+
account?: Account | Address;
|
|
132
|
+
}) => Promise<Hash>;
|
|
133
|
+
getPublicKeys: (args: {
|
|
134
|
+
addresses: Address[];
|
|
135
|
+
}) => Promise<Hex[]>;
|
|
136
|
+
getAggregatedPublicKey: (args: {
|
|
137
|
+
addresses: Address[];
|
|
138
|
+
}) => Promise<Hex>;
|
|
139
|
+
isKeyRegistered: (args: {
|
|
140
|
+
address: Address;
|
|
141
|
+
}) => Promise<boolean>;
|
|
142
|
+
getRegisteredCount: () => Promise<bigint>;
|
|
143
|
+
blsPublicKeys: (args: {
|
|
144
|
+
address: Address;
|
|
145
|
+
}) => Promise<Hex[]>;
|
|
146
|
+
threshold: () => Promise<bigint>;
|
|
147
|
+
minThreshold: () => Promise<bigint>;
|
|
148
|
+
defaultThreshold: () => Promise<bigint>;
|
|
149
|
+
setThreshold: (args: {
|
|
150
|
+
newThreshold: bigint;
|
|
151
|
+
account?: Account | Address;
|
|
152
|
+
}) => Promise<Hash>;
|
|
153
|
+
setMinThreshold: (args: {
|
|
154
|
+
newThreshold: bigint;
|
|
155
|
+
account?: Account | Address;
|
|
156
|
+
}) => Promise<Hash>;
|
|
157
|
+
setDefaultThreshold: (args: {
|
|
158
|
+
newThreshold: bigint;
|
|
159
|
+
account?: Account | Address;
|
|
160
|
+
}) => Promise<Hash>;
|
|
161
|
+
setRegistry: (args: {
|
|
162
|
+
registry: Address;
|
|
163
|
+
account?: Account | Address;
|
|
164
|
+
}) => Promise<Hash>;
|
|
165
|
+
setDVTValidator: (args: {
|
|
166
|
+
validator: Address;
|
|
167
|
+
account?: Account | Address;
|
|
168
|
+
}) => Promise<Hash>;
|
|
169
|
+
setSuperPaymaster: (args: {
|
|
170
|
+
paymaster: Address;
|
|
171
|
+
account?: Account | Address;
|
|
172
|
+
}) => Promise<Hash>;
|
|
173
|
+
renounceOwnership: (args: {
|
|
174
|
+
account?: Account | Address;
|
|
175
|
+
}) => Promise<Hash>;
|
|
176
|
+
REGISTRY: () => Promise<Address>;
|
|
177
|
+
DVT_VALIDATOR: () => Promise<Address>;
|
|
178
|
+
SUPERPAYMASTER: () => Promise<Address>;
|
|
179
|
+
MAX_VALIDATORS: () => Promise<bigint>;
|
|
180
|
+
executedProposals: (args: {
|
|
181
|
+
proposalId: bigint;
|
|
182
|
+
}) => Promise<boolean>;
|
|
183
|
+
proposalNonces: (args: {
|
|
184
|
+
proposalId: bigint;
|
|
185
|
+
}) => Promise<bigint>;
|
|
186
|
+
owner: () => Promise<Address>;
|
|
187
|
+
transferOwnership: (args: {
|
|
188
|
+
newOwner: Address;
|
|
189
|
+
account?: Account | Address;
|
|
190
|
+
}) => Promise<Hash>;
|
|
191
|
+
version: () => Promise<string>;
|
|
192
|
+
};
|
|
193
|
+
export declare const dvtActions: (address: Address) => (client: PublicClient | WalletClient) => DVTActions;
|
|
194
|
+
export declare const blsActions: (address: Address) => (client: PublicClient | WalletClient) => BLSAggregatorActions;
|