@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,330 @@
|
|
|
1
|
+
import { GTokenStakingABI } from '../abis/index.js';
|
|
2
|
+
export const stakingActions = (address) => (client) => ({
|
|
3
|
+
// Staking Operations
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* @warning This is a low-level internal API. Use high-level clients instead.
|
|
7
|
+
*/
|
|
8
|
+
async lockStake({ user, roleId, stakeAmount, entryBurn, payer, account }) {
|
|
9
|
+
return client.writeContract({
|
|
10
|
+
address,
|
|
11
|
+
abi: GTokenStakingABI,
|
|
12
|
+
functionName: 'lockStake',
|
|
13
|
+
args: [user, roleId, stakeAmount, entryBurn, payer],
|
|
14
|
+
account: account,
|
|
15
|
+
chain: client.chain
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
async unlockStake({ user, roleId, account }) {
|
|
19
|
+
return client.writeContract({
|
|
20
|
+
address,
|
|
21
|
+
abi: GTokenStakingABI,
|
|
22
|
+
functionName: 'unlockAndTransfer',
|
|
23
|
+
args: [user, roleId],
|
|
24
|
+
account: account,
|
|
25
|
+
chain: client.chain
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
async unlockAndTransfer({ user, roleId, account }) {
|
|
29
|
+
return client.writeContract({
|
|
30
|
+
address,
|
|
31
|
+
abi: GTokenStakingABI,
|
|
32
|
+
functionName: 'unlockAndTransfer',
|
|
33
|
+
args: [user, roleId],
|
|
34
|
+
account: account,
|
|
35
|
+
chain: client.chain
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
async stake({ amount, account }) {
|
|
39
|
+
return client.writeContract({
|
|
40
|
+
address,
|
|
41
|
+
abi: GTokenStakingABI,
|
|
42
|
+
functionName: 'stake',
|
|
43
|
+
args: [amount],
|
|
44
|
+
account: account,
|
|
45
|
+
chain: client.chain
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
async topUpStake({ amount, account }) {
|
|
49
|
+
// topUpStake typically calls stake internally or is a distinct function. Assuming distinct based on request.
|
|
50
|
+
return client.writeContract({
|
|
51
|
+
address,
|
|
52
|
+
abi: GTokenStakingABI,
|
|
53
|
+
functionName: 'topUpStake',
|
|
54
|
+
args: [amount],
|
|
55
|
+
account: account,
|
|
56
|
+
chain: client.chain
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async unstake({ amount, account }) {
|
|
60
|
+
return client.writeContract({
|
|
61
|
+
address,
|
|
62
|
+
abi: GTokenStakingABI,
|
|
63
|
+
functionName: 'unstake',
|
|
64
|
+
args: [amount],
|
|
65
|
+
account: account,
|
|
66
|
+
chain: client.chain
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
// Slashing
|
|
70
|
+
async slash({ user, roleId, amount, reason, account }) {
|
|
71
|
+
return client.writeContract({
|
|
72
|
+
address,
|
|
73
|
+
abi: GTokenStakingABI,
|
|
74
|
+
functionName: 'slash',
|
|
75
|
+
args: [user, roleId, amount, reason],
|
|
76
|
+
account: account,
|
|
77
|
+
chain: client.chain
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
async slashByDVT({ user, roleId, amount, reason, account }) {
|
|
81
|
+
return client.writeContract({
|
|
82
|
+
address,
|
|
83
|
+
abi: GTokenStakingABI,
|
|
84
|
+
functionName: 'slashByDVT',
|
|
85
|
+
args: [user, roleId, amount, reason],
|
|
86
|
+
account: account,
|
|
87
|
+
chain: client.chain
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
async setAuthorizedSlasher({ slasher, authorized, account }) {
|
|
91
|
+
return client.writeContract({
|
|
92
|
+
address,
|
|
93
|
+
abi: GTokenStakingABI,
|
|
94
|
+
functionName: 'setAuthorizedSlasher',
|
|
95
|
+
args: [slasher, authorized],
|
|
96
|
+
account: account,
|
|
97
|
+
chain: client.chain
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
// Query Functions
|
|
101
|
+
async getStakeInfo({ operator, roleId }) {
|
|
102
|
+
return client.readContract({
|
|
103
|
+
address,
|
|
104
|
+
abi: GTokenStakingABI,
|
|
105
|
+
functionName: 'stakes',
|
|
106
|
+
args: [operator]
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
async getStakingBalance({ user }) {
|
|
110
|
+
return client.readContract({
|
|
111
|
+
address,
|
|
112
|
+
abi: GTokenStakingABI,
|
|
113
|
+
functionName: 'balanceOf',
|
|
114
|
+
args: [user]
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
async getLockedStake({ user, roleId }) {
|
|
118
|
+
return client.readContract({
|
|
119
|
+
address,
|
|
120
|
+
abi: GTokenStakingABI,
|
|
121
|
+
functionName: 'getLockedStake',
|
|
122
|
+
args: [user, roleId]
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
async getUserRoleLocks({ user }) {
|
|
126
|
+
return client.readContract({
|
|
127
|
+
address,
|
|
128
|
+
abi: GTokenStakingABI,
|
|
129
|
+
functionName: 'getUserRoleLocks',
|
|
130
|
+
args: [user]
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
async hasRoleLock({ user, roleId }) {
|
|
134
|
+
return client.readContract({
|
|
135
|
+
address,
|
|
136
|
+
abi: GTokenStakingABI,
|
|
137
|
+
functionName: 'hasRoleLock',
|
|
138
|
+
args: [user, roleId]
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
async availableBalance({ user }) {
|
|
142
|
+
return client.readContract({
|
|
143
|
+
address,
|
|
144
|
+
abi: GTokenStakingABI,
|
|
145
|
+
functionName: 'availableBalance',
|
|
146
|
+
args: [user]
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
async previewExitFee({ user, roleId }) {
|
|
150
|
+
return client.readContract({
|
|
151
|
+
address,
|
|
152
|
+
abi: GTokenStakingABI,
|
|
153
|
+
functionName: 'previewExitFee',
|
|
154
|
+
args: [user, roleId]
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
// Admin Functions
|
|
158
|
+
async setRegistry({ registry, account }) {
|
|
159
|
+
return client.writeContract({
|
|
160
|
+
address,
|
|
161
|
+
abi: GTokenStakingABI,
|
|
162
|
+
functionName: 'setRegistry',
|
|
163
|
+
args: [registry],
|
|
164
|
+
account: account,
|
|
165
|
+
chain: client.chain
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
async transferOwnership({ newOwner, account }) {
|
|
169
|
+
return client.writeContract({
|
|
170
|
+
address,
|
|
171
|
+
abi: GTokenStakingABI,
|
|
172
|
+
functionName: 'transferOwnership',
|
|
173
|
+
args: [newOwner],
|
|
174
|
+
account: account,
|
|
175
|
+
chain: client.chain
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
async setRoleExitFee({ roleId, feePercent, account }) {
|
|
179
|
+
return client.writeContract({
|
|
180
|
+
address,
|
|
181
|
+
abi: GTokenStakingABI,
|
|
182
|
+
functionName: 'setRoleExitFee',
|
|
183
|
+
args: [roleId, feePercent],
|
|
184
|
+
account: account,
|
|
185
|
+
chain: client.chain
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
async setTreasury({ treasury, account }) {
|
|
189
|
+
return client.writeContract({
|
|
190
|
+
address,
|
|
191
|
+
abi: GTokenStakingABI,
|
|
192
|
+
functionName: 'setTreasury',
|
|
193
|
+
args: [treasury],
|
|
194
|
+
account: account,
|
|
195
|
+
chain: client.chain
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
// View Functions
|
|
199
|
+
async stakes({ user }) {
|
|
200
|
+
return client.readContract({
|
|
201
|
+
address,
|
|
202
|
+
abi: GTokenStakingABI,
|
|
203
|
+
functionName: 'stakes',
|
|
204
|
+
args: [user]
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
async roleLocks({ user, roleId }) {
|
|
208
|
+
return client.readContract({
|
|
209
|
+
address,
|
|
210
|
+
abi: GTokenStakingABI,
|
|
211
|
+
functionName: 'roleLocks',
|
|
212
|
+
args: [user, roleId]
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
async roleExitConfigs({ roleId }) {
|
|
216
|
+
return client.readContract({
|
|
217
|
+
address,
|
|
218
|
+
abi: GTokenStakingABI,
|
|
219
|
+
functionName: 'roleExitConfigs',
|
|
220
|
+
args: [roleId]
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
async userActiveRoles({ user, index }) {
|
|
224
|
+
return client.readContract({
|
|
225
|
+
address,
|
|
226
|
+
abi: GTokenStakingABI,
|
|
227
|
+
functionName: 'userActiveRoles',
|
|
228
|
+
args: [user, index]
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
async authorizedSlashers({ slasher }) {
|
|
232
|
+
return client.readContract({
|
|
233
|
+
address,
|
|
234
|
+
abi: GTokenStakingABI,
|
|
235
|
+
functionName: 'authorizedSlashers',
|
|
236
|
+
args: [slasher]
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
async getStake({ account }) {
|
|
240
|
+
return client.readContract({
|
|
241
|
+
address,
|
|
242
|
+
abi: GTokenStakingABI,
|
|
243
|
+
functionName: 'getStake',
|
|
244
|
+
args: [account]
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
async balanceOf({ account }) {
|
|
248
|
+
// GTokenStaking might implement balanceOf if it's an ERC20-like or just tracking stakes
|
|
249
|
+
return client.readContract({
|
|
250
|
+
address,
|
|
251
|
+
abi: GTokenStakingABI,
|
|
252
|
+
functionName: 'balanceOf',
|
|
253
|
+
args: [account]
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
async totalStaked() {
|
|
257
|
+
return client.readContract({
|
|
258
|
+
address,
|
|
259
|
+
abi: GTokenStakingABI,
|
|
260
|
+
functionName: 'totalStaked',
|
|
261
|
+
args: []
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
async getTotalStaked() {
|
|
265
|
+
return this.totalStaked();
|
|
266
|
+
},
|
|
267
|
+
async treasury() {
|
|
268
|
+
return client.readContract({
|
|
269
|
+
address,
|
|
270
|
+
abi: GTokenStakingABI,
|
|
271
|
+
functionName: 'treasury',
|
|
272
|
+
args: []
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
async owner() {
|
|
276
|
+
return client.readContract({
|
|
277
|
+
address,
|
|
278
|
+
abi: GTokenStakingABI,
|
|
279
|
+
functionName: 'owner',
|
|
280
|
+
args: []
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
// Ownership
|
|
284
|
+
async transferStakingOwnership({ newOwner, account }) {
|
|
285
|
+
return client.writeContract({
|
|
286
|
+
address,
|
|
287
|
+
abi: GTokenStakingABI,
|
|
288
|
+
functionName: 'transferOwnership',
|
|
289
|
+
args: [newOwner],
|
|
290
|
+
account: account,
|
|
291
|
+
chain: client.chain
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
async renounceOwnership({ account }) {
|
|
295
|
+
return client.writeContract({
|
|
296
|
+
address,
|
|
297
|
+
abi: GTokenStakingABI,
|
|
298
|
+
functionName: 'renounceOwnership',
|
|
299
|
+
args: [],
|
|
300
|
+
account: account,
|
|
301
|
+
chain: client.chain
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
// Version
|
|
305
|
+
async version() {
|
|
306
|
+
return client.readContract({
|
|
307
|
+
address,
|
|
308
|
+
abi: GTokenStakingABI,
|
|
309
|
+
functionName: 'version',
|
|
310
|
+
args: []
|
|
311
|
+
});
|
|
312
|
+
},
|
|
313
|
+
// Constants
|
|
314
|
+
async REGISTRY() {
|
|
315
|
+
return client.readContract({
|
|
316
|
+
address,
|
|
317
|
+
abi: GTokenStakingABI,
|
|
318
|
+
functionName: 'REGISTRY',
|
|
319
|
+
args: []
|
|
320
|
+
});
|
|
321
|
+
},
|
|
322
|
+
async GTOKEN() {
|
|
323
|
+
return client.readContract({
|
|
324
|
+
address,
|
|
325
|
+
abi: GTokenStakingABI,
|
|
326
|
+
functionName: 'GTOKEN',
|
|
327
|
+
args: []
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { stakingActions } from './staking.js';
|
|
3
|
+
describe('Staking Actions', () => {
|
|
4
|
+
const mockStakingAddress = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb';
|
|
5
|
+
let mockPublicClient;
|
|
6
|
+
let mockWalletClient;
|
|
7
|
+
let mockAccount;
|
|
8
|
+
const MOCK_USER = '0x1234567890123456789012345678901234567890';
|
|
9
|
+
const MOCK_ROLE_ID = '0xabcd...';
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockAccount = {
|
|
12
|
+
address: MOCK_USER,
|
|
13
|
+
type: 'json-rpc'
|
|
14
|
+
};
|
|
15
|
+
mockPublicClient = {
|
|
16
|
+
readContract: vi.fn(),
|
|
17
|
+
};
|
|
18
|
+
mockWalletClient = {
|
|
19
|
+
writeContract: vi.fn(),
|
|
20
|
+
account: mockAccount,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
describe('Query functions', () => {
|
|
24
|
+
it('should get staking balance', async () => {
|
|
25
|
+
const mockBalance = 1000000000000000000000n;
|
|
26
|
+
mockPublicClient.readContract.mockResolvedValue(mockBalance);
|
|
27
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
28
|
+
const balance = await actions.getStakingBalance({ user: MOCK_USER });
|
|
29
|
+
expect(balance).toBe(mockBalance);
|
|
30
|
+
});
|
|
31
|
+
it('should get locked stake', async () => {
|
|
32
|
+
const mockLocked = 500000000000000000000n;
|
|
33
|
+
mockPublicClient.readContract.mockResolvedValue(mockLocked);
|
|
34
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
35
|
+
const locked = await actions.getLockedStake({ user: MOCK_USER, roleId: MOCK_ROLE_ID });
|
|
36
|
+
expect(locked).toBe(mockLocked);
|
|
37
|
+
});
|
|
38
|
+
it('should get available balance', async () => {
|
|
39
|
+
const mockAvailable = 500000000000000000000n;
|
|
40
|
+
mockPublicClient.readContract.mockResolvedValue(mockAvailable);
|
|
41
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
42
|
+
const available = await actions.availableBalance({ user: MOCK_USER });
|
|
43
|
+
expect(available).toBe(mockAvailable);
|
|
44
|
+
});
|
|
45
|
+
it('should check if user has role lock', async () => {
|
|
46
|
+
mockPublicClient.readContract.mockResolvedValue(true);
|
|
47
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
48
|
+
const hasLock = await actions.hasRoleLock({ user: MOCK_USER, roleId: MOCK_ROLE_ID });
|
|
49
|
+
expect(hasLock).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
it('should get user role locks', async () => {
|
|
52
|
+
const mockLocks = [{ roleId: MOCK_ROLE_ID, amount: 1000n }];
|
|
53
|
+
mockPublicClient.readContract.mockResolvedValue(mockLocks);
|
|
54
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
55
|
+
const locks = await actions.getUserRoleLocks({ user: MOCK_USER });
|
|
56
|
+
expect(locks).toEqual(mockLocks);
|
|
57
|
+
});
|
|
58
|
+
it('should preview exit fee', async () => {
|
|
59
|
+
const mockFee = 10000000000000000n; // 0.01 ETH
|
|
60
|
+
mockPublicClient.readContract.mockResolvedValue(mockFee);
|
|
61
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
62
|
+
const fee = await actions.previewExitFee({ user: MOCK_USER, roleId: MOCK_ROLE_ID });
|
|
63
|
+
expect(fee).toBe(mockFee);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('Staking operations', () => {
|
|
67
|
+
it('should lock stake', async () => {
|
|
68
|
+
const txHash = '0xabc...';
|
|
69
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
70
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
71
|
+
const result = await actions.lockStake({
|
|
72
|
+
user: MOCK_USER,
|
|
73
|
+
roleId: MOCK_ROLE_ID,
|
|
74
|
+
stakeAmount: 1000n,
|
|
75
|
+
entryBurn: 10n,
|
|
76
|
+
payer: MOCK_USER,
|
|
77
|
+
account: mockAccount
|
|
78
|
+
});
|
|
79
|
+
expect(result).toBe(txHash);
|
|
80
|
+
});
|
|
81
|
+
it('should unlock stake', async () => {
|
|
82
|
+
const txHash = '0xdef...';
|
|
83
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
84
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
85
|
+
const result = await actions.unlockStake({
|
|
86
|
+
user: MOCK_USER,
|
|
87
|
+
roleId: MOCK_ROLE_ID,
|
|
88
|
+
account: mockAccount
|
|
89
|
+
});
|
|
90
|
+
expect(result).toBe(txHash);
|
|
91
|
+
});
|
|
92
|
+
it('should unlock and transfer', async () => {
|
|
93
|
+
const txHash = '0xghi...';
|
|
94
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
95
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
96
|
+
const result = await actions.unlockAndTransfer({
|
|
97
|
+
user: MOCK_USER,
|
|
98
|
+
roleId: MOCK_ROLE_ID,
|
|
99
|
+
account: mockAccount
|
|
100
|
+
});
|
|
101
|
+
expect(result).toBe(txHash);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('Slashing operations', () => {
|
|
105
|
+
it('should slash user stake', async () => {
|
|
106
|
+
const txHash = '0xjkl...';
|
|
107
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
108
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
109
|
+
const result = await actions.slash({
|
|
110
|
+
user: MOCK_USER,
|
|
111
|
+
roleId: MOCK_ROLE_ID,
|
|
112
|
+
amount: 100n,
|
|
113
|
+
reason: 'Violation',
|
|
114
|
+
account: mockAccount
|
|
115
|
+
});
|
|
116
|
+
expect(result).toBe(txHash);
|
|
117
|
+
});
|
|
118
|
+
it('should slash by DVT', async () => {
|
|
119
|
+
const txHash = '0xmno...';
|
|
120
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
121
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
122
|
+
const result = await actions.slashByDVT({
|
|
123
|
+
user: MOCK_USER,
|
|
124
|
+
roleId: MOCK_ROLE_ID,
|
|
125
|
+
amount: 50n,
|
|
126
|
+
reason: 'DVT slash',
|
|
127
|
+
account: mockAccount
|
|
128
|
+
});
|
|
129
|
+
expect(result).toBe(txHash);
|
|
130
|
+
});
|
|
131
|
+
it('should set authorized slasher', async () => {
|
|
132
|
+
const txHash = '0xpqr...';
|
|
133
|
+
const slasher = '0x99999999999999999999999999999999999999';
|
|
134
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
135
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
136
|
+
const result = await actions.setAuthorizedSlasher({
|
|
137
|
+
slasher,
|
|
138
|
+
authorized: true,
|
|
139
|
+
account: mockAccount
|
|
140
|
+
});
|
|
141
|
+
expect(result).toBe(txHash);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe('Advanced Query Functions', () => {
|
|
145
|
+
it('should get stake info', async () => {
|
|
146
|
+
mockPublicClient.readContract.mockResolvedValue({ amount: 100n });
|
|
147
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
148
|
+
const info = await actions.getStakeInfo({ operator: MOCK_USER, roleId: MOCK_ROLE_ID });
|
|
149
|
+
expect(info.amount).toBe(100n);
|
|
150
|
+
});
|
|
151
|
+
it('should query stakes and role locks', async () => {
|
|
152
|
+
mockPublicClient.readContract
|
|
153
|
+
.mockResolvedValueOnce({ amount: 100n }) // stakes
|
|
154
|
+
.mockResolvedValueOnce({ amount: 50n }); // roleLocks
|
|
155
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
156
|
+
const stake = await actions.stakes({ user: MOCK_USER });
|
|
157
|
+
const lock = await actions.roleLocks({ user: MOCK_USER, roleId: MOCK_ROLE_ID });
|
|
158
|
+
expect(stake.amount).toBe(100n);
|
|
159
|
+
expect(lock.amount).toBe(50n);
|
|
160
|
+
});
|
|
161
|
+
it('should query exit configs and active roles', async () => {
|
|
162
|
+
mockPublicClient.readContract
|
|
163
|
+
.mockResolvedValueOnce({ feePercent: 10n }) // roleExitConfigs
|
|
164
|
+
.mockResolvedValueOnce(MOCK_ROLE_ID); // userActiveRoles
|
|
165
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
166
|
+
const config = await actions.roleExitConfigs({ roleId: MOCK_ROLE_ID });
|
|
167
|
+
const role = await actions.userActiveRoles({ user: MOCK_USER, index: 0n });
|
|
168
|
+
expect(config.feePercent).toBe(10n);
|
|
169
|
+
expect(role).toBe(MOCK_ROLE_ID);
|
|
170
|
+
});
|
|
171
|
+
it('should query total staked and system status', async () => {
|
|
172
|
+
mockPublicClient.readContract
|
|
173
|
+
.mockResolvedValueOnce(1000n) // totalStaked
|
|
174
|
+
.mockResolvedValueOnce(1000n) // totalStaked (via getTotalStaked)
|
|
175
|
+
.mockResolvedValueOnce(true); // authorizedSlashers
|
|
176
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
177
|
+
const total = await actions.totalStaked();
|
|
178
|
+
const total2 = await actions.getTotalStaked();
|
|
179
|
+
const authorized = await actions.authorizedSlashers({ slasher: MOCK_USER });
|
|
180
|
+
expect(total).toBe(1000n);
|
|
181
|
+
expect(total2).toBe(1000n);
|
|
182
|
+
expect(authorized).toBe(true);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe('System Configuration & Ownership', () => {
|
|
186
|
+
it('should manage treasury and registry', async () => {
|
|
187
|
+
const txHash = '0xhash';
|
|
188
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
189
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
190
|
+
const tx1 = await actions.setTreasury({ treasury: MOCK_USER, account: mockAccount });
|
|
191
|
+
const tx2 = await actions.setRegistry({ registry: MOCK_USER, account: mockAccount });
|
|
192
|
+
expect(tx1).toBe(txHash);
|
|
193
|
+
expect(tx2).toBe(txHash);
|
|
194
|
+
});
|
|
195
|
+
it('should handle ownership transfers', async () => {
|
|
196
|
+
const txHash = '0xhash';
|
|
197
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
198
|
+
const actions = stakingActions(mockStakingAddress)(mockWalletClient);
|
|
199
|
+
const tx1 = await actions.transferStakingOwnership({ newOwner: MOCK_USER, account: mockAccount });
|
|
200
|
+
const tx2 = await actions.renounceOwnership({ account: mockAccount });
|
|
201
|
+
expect(tx1).toBe(txHash);
|
|
202
|
+
expect(tx2).toBe(txHash);
|
|
203
|
+
});
|
|
204
|
+
it('should query system references', async () => {
|
|
205
|
+
mockPublicClient.readContract.mockResolvedValue(MOCK_USER);
|
|
206
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
207
|
+
const r = await actions.REGISTRY();
|
|
208
|
+
const g = await actions.GTOKEN();
|
|
209
|
+
const t = await actions.treasury();
|
|
210
|
+
const o = await actions.owner();
|
|
211
|
+
expect(r).toBe(MOCK_USER);
|
|
212
|
+
expect(g).toBe(MOCK_USER);
|
|
213
|
+
expect(t).toBe(MOCK_USER);
|
|
214
|
+
expect(o).toBe(MOCK_USER);
|
|
215
|
+
});
|
|
216
|
+
it('should get version', async () => {
|
|
217
|
+
mockPublicClient.readContract.mockResolvedValue('v1');
|
|
218
|
+
const actions = stakingActions(mockStakingAddress)(mockPublicClient);
|
|
219
|
+
const v = await actions.version();
|
|
220
|
+
expect(v).toBe('v1');
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|