@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,281 @@
|
|
|
1
|
+
import { ReputationSystemABI } from '../abis/index.js';
|
|
2
|
+
export const reputationActions = (address) => (client) => ({
|
|
3
|
+
// 规则配置
|
|
4
|
+
async setReputationRule({ ruleId, rule, account }) {
|
|
5
|
+
return client.writeContract({
|
|
6
|
+
address,
|
|
7
|
+
abi: ReputationSystemABI,
|
|
8
|
+
functionName: 'setReputationRule',
|
|
9
|
+
args: [ruleId, rule],
|
|
10
|
+
account: account,
|
|
11
|
+
chain: client.chain
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
async getReputationRule({ ruleId }) {
|
|
15
|
+
return client.readContract({
|
|
16
|
+
address,
|
|
17
|
+
abi: ReputationSystemABI,
|
|
18
|
+
functionName: 'getReputationRule',
|
|
19
|
+
args: [ruleId]
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
async enableRule({ ruleId, account }) {
|
|
23
|
+
return client.writeContract({
|
|
24
|
+
address,
|
|
25
|
+
abi: ReputationSystemABI,
|
|
26
|
+
functionName: 'enableRule',
|
|
27
|
+
args: [ruleId],
|
|
28
|
+
account: account,
|
|
29
|
+
chain: client.chain
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
async disableRule({ ruleId, account }) {
|
|
33
|
+
return client.writeContract({
|
|
34
|
+
address,
|
|
35
|
+
abi: ReputationSystemABI,
|
|
36
|
+
functionName: 'disableRule',
|
|
37
|
+
args: [ruleId],
|
|
38
|
+
account: account,
|
|
39
|
+
chain: client.chain
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
async isRuleActive({ ruleId }) {
|
|
43
|
+
return client.readContract({
|
|
44
|
+
address,
|
|
45
|
+
abi: ReputationSystemABI,
|
|
46
|
+
functionName: 'isRuleActive',
|
|
47
|
+
args: [ruleId]
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
async getActiveRules({ community }) {
|
|
51
|
+
return client.readContract({
|
|
52
|
+
address,
|
|
53
|
+
abi: ReputationSystemABI,
|
|
54
|
+
functionName: 'getActiveRules',
|
|
55
|
+
args: [community]
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
async getRuleCount() {
|
|
59
|
+
return client.readContract({
|
|
60
|
+
address,
|
|
61
|
+
abi: ReputationSystemABI,
|
|
62
|
+
functionName: 'getRuleCount',
|
|
63
|
+
args: []
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
// 积分计算
|
|
67
|
+
async computeScore({ user, community }) {
|
|
68
|
+
return client.readContract({
|
|
69
|
+
address,
|
|
70
|
+
abi: ReputationSystemABI,
|
|
71
|
+
functionName: 'computeScore',
|
|
72
|
+
args: [user, community]
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
async getUserScore({ user }) {
|
|
76
|
+
return client.readContract({
|
|
77
|
+
address,
|
|
78
|
+
abi: ReputationSystemABI,
|
|
79
|
+
functionName: 'getUserScore',
|
|
80
|
+
args: [user]
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
async getCommunityScore({ community }) {
|
|
84
|
+
return client.readContract({
|
|
85
|
+
address,
|
|
86
|
+
abi: ReputationSystemABI,
|
|
87
|
+
functionName: 'getCommunityScore',
|
|
88
|
+
args: [community]
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
// Public mapping getter
|
|
92
|
+
async communityReputations({ community, user }) {
|
|
93
|
+
return client.readContract({
|
|
94
|
+
address,
|
|
95
|
+
abi: ReputationSystemABI,
|
|
96
|
+
functionName: 'communityReputations',
|
|
97
|
+
args: [community, user]
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
// Missing Critical Actions
|
|
101
|
+
async setRule(args) {
|
|
102
|
+
return this.setReputationRule(args);
|
|
103
|
+
},
|
|
104
|
+
async calculateReputation(args) {
|
|
105
|
+
// Assuming calculateReputation calls computeScore or check if dedicated function exists
|
|
106
|
+
// Report said calculateReputation matches ABI.
|
|
107
|
+
return client.readContract({
|
|
108
|
+
address,
|
|
109
|
+
abi: ReputationSystemABI,
|
|
110
|
+
functionName: 'calculateReputation', // If this fails, it means calculateReputation is NOT in ABI and tool was confused? But report said it IS in ABI.
|
|
111
|
+
args: [args.user, args.community]
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
async nftCollectionBoost({ collection }) {
|
|
115
|
+
return client.readContract({
|
|
116
|
+
address,
|
|
117
|
+
abi: ReputationSystemABI,
|
|
118
|
+
functionName: 'nftCollectionBoost',
|
|
119
|
+
args: [collection]
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
// 批量操作
|
|
123
|
+
async batchUpdateScores({ users, scores, account }) {
|
|
124
|
+
return client.writeContract({
|
|
125
|
+
address,
|
|
126
|
+
abi: ReputationSystemABI,
|
|
127
|
+
functionName: 'batchUpdateScores',
|
|
128
|
+
args: [users, scores],
|
|
129
|
+
account: account,
|
|
130
|
+
chain: client.chain
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
async batchSyncToRegistry({ users, account }) {
|
|
134
|
+
return client.writeContract({
|
|
135
|
+
address,
|
|
136
|
+
abi: ReputationSystemABI,
|
|
137
|
+
functionName: 'batchSyncToRegistry',
|
|
138
|
+
args: [users],
|
|
139
|
+
account: account,
|
|
140
|
+
chain: client.chain
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
async syncToRegistry({ user, communities, ruleIds, activities, epoch, proof, account }) {
|
|
144
|
+
return client.writeContract({
|
|
145
|
+
address,
|
|
146
|
+
abi: ReputationSystemABI,
|
|
147
|
+
functionName: 'syncToRegistry',
|
|
148
|
+
args: [user, communities, ruleIds, activities, epoch, proof],
|
|
149
|
+
account: account,
|
|
150
|
+
chain: client.chain
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
// Admin & Config
|
|
154
|
+
async setRegistry({ registry, account }) {
|
|
155
|
+
return client.writeContract({
|
|
156
|
+
address,
|
|
157
|
+
abi: ReputationSystemABI,
|
|
158
|
+
functionName: 'setRegistry',
|
|
159
|
+
args: [registry],
|
|
160
|
+
account: account,
|
|
161
|
+
chain: client.chain
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
async setEntropyFactor({ factor, account }) {
|
|
165
|
+
return client.writeContract({
|
|
166
|
+
address,
|
|
167
|
+
abi: ReputationSystemABI,
|
|
168
|
+
functionName: 'setEntropyFactor',
|
|
169
|
+
args: [factor],
|
|
170
|
+
account: account,
|
|
171
|
+
chain: client.chain
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
async getEntropyFactor() {
|
|
175
|
+
return client.readContract({
|
|
176
|
+
address,
|
|
177
|
+
abi: ReputationSystemABI,
|
|
178
|
+
functionName: 'getEntropyFactor',
|
|
179
|
+
args: []
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
// Constants
|
|
183
|
+
async REGISTRY() {
|
|
184
|
+
return client.readContract({
|
|
185
|
+
address,
|
|
186
|
+
abi: ReputationSystemABI,
|
|
187
|
+
functionName: 'REGISTRY',
|
|
188
|
+
args: []
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
// Ownership
|
|
192
|
+
async reputationOwner() {
|
|
193
|
+
return client.readContract({
|
|
194
|
+
address,
|
|
195
|
+
abi: ReputationSystemABI,
|
|
196
|
+
functionName: 'owner',
|
|
197
|
+
args: []
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
async renounceReputationOwnership({ account } = {}) {
|
|
201
|
+
return client.writeContract({
|
|
202
|
+
address,
|
|
203
|
+
abi: ReputationSystemABI,
|
|
204
|
+
functionName: 'renounceOwnership',
|
|
205
|
+
args: [],
|
|
206
|
+
account: account,
|
|
207
|
+
chain: client.chain
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
async transferReputationOwnership({ newOwner, account }) {
|
|
211
|
+
return client.writeContract({
|
|
212
|
+
address,
|
|
213
|
+
abi: ReputationSystemABI,
|
|
214
|
+
functionName: 'transferOwnership',
|
|
215
|
+
args: [newOwner],
|
|
216
|
+
account: account,
|
|
217
|
+
chain: client.chain
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
async setCommunityReputation({ community, reputation, account }) {
|
|
221
|
+
return client.writeContract({
|
|
222
|
+
address,
|
|
223
|
+
abi: ReputationSystemABI,
|
|
224
|
+
functionName: 'setCommunityReputation',
|
|
225
|
+
args: [community, reputation],
|
|
226
|
+
account: account,
|
|
227
|
+
chain: client.chain
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
async updateNFTHoldStart({ user, collection, start, account }) {
|
|
231
|
+
return client.writeContract({
|
|
232
|
+
address,
|
|
233
|
+
abi: ReputationSystemABI,
|
|
234
|
+
functionName: 'updateNFTHoldStart',
|
|
235
|
+
args: [user, collection, start],
|
|
236
|
+
account: account,
|
|
237
|
+
chain: client.chain
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
// Views
|
|
241
|
+
async communityRules({ community, ruleId }) {
|
|
242
|
+
return client.readContract({ address, abi: ReputationSystemABI, functionName: 'communityRules', args: [community, ruleId] });
|
|
243
|
+
},
|
|
244
|
+
async defaultRule() {
|
|
245
|
+
return client.readContract({ address, abi: ReputationSystemABI, functionName: 'defaultRule', args: [] });
|
|
246
|
+
},
|
|
247
|
+
async entropyFactors({ factorId }) {
|
|
248
|
+
return client.readContract({ address, abi: ReputationSystemABI, functionName: 'entropyFactors', args: [factorId] });
|
|
249
|
+
},
|
|
250
|
+
async nftHoldStart({ user, collection }) {
|
|
251
|
+
return client.readContract({ address, abi: ReputationSystemABI, functionName: 'nftHoldStart', args: [user, collection] });
|
|
252
|
+
},
|
|
253
|
+
async boostedCollections({ collection }) {
|
|
254
|
+
return client.readContract({ address, abi: ReputationSystemABI, functionName: 'boostedCollections', args: [collection] });
|
|
255
|
+
},
|
|
256
|
+
async communityActiveRules({ community, ruleId }) {
|
|
257
|
+
return client.readContract({ address, abi: ReputationSystemABI, functionName: 'communityActiveRules', args: [community, ruleId] });
|
|
258
|
+
},
|
|
259
|
+
async getReputationBreakdown({ user, community }) {
|
|
260
|
+
return client.readContract({ address, abi: ReputationSystemABI, functionName: 'getReputationBreakdown', args: [user, community] });
|
|
261
|
+
},
|
|
262
|
+
async setNFTBoost({ collection, boost, account }) {
|
|
263
|
+
return client.writeContract({
|
|
264
|
+
address,
|
|
265
|
+
abi: ReputationSystemABI,
|
|
266
|
+
functionName: 'setNFTBoost',
|
|
267
|
+
args: [collection, boost],
|
|
268
|
+
account: account,
|
|
269
|
+
chain: client.chain
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
// Version
|
|
273
|
+
async reputationVersion() {
|
|
274
|
+
return client.readContract({
|
|
275
|
+
address,
|
|
276
|
+
abi: ReputationSystemABI,
|
|
277
|
+
functionName: 'version',
|
|
278
|
+
args: []
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { reputationActions } from './reputation.js';
|
|
3
|
+
describe('Reputation Actions', () => {
|
|
4
|
+
const mockReputationAddress = '0x1234567890123456789012345678901234567890';
|
|
5
|
+
let mockPublicClient;
|
|
6
|
+
let mockWalletClient;
|
|
7
|
+
let mockAccount;
|
|
8
|
+
const MOCK_USER = '0x2222222222222222222222222222222222222222';
|
|
9
|
+
const MOCK_COMMUNITY = '0x3333333333333333333333333333333333333333';
|
|
10
|
+
const MOCK_RULE_ID = '0xabcd1234567890123456789012345678901234567890abcd1234567890123456';
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
mockAccount = {
|
|
13
|
+
address: '0x1111111111111111111111111111111111111111',
|
|
14
|
+
type: 'json-rpc'
|
|
15
|
+
};
|
|
16
|
+
mockPublicClient = {
|
|
17
|
+
readContract: vi.fn(),
|
|
18
|
+
};
|
|
19
|
+
mockWalletClient = {
|
|
20
|
+
writeContract: vi.fn(),
|
|
21
|
+
account: mockAccount,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
describe('Rule Configuration', () => {
|
|
25
|
+
it('should get reputation rule', async () => {
|
|
26
|
+
const mockRule = { weight: 50, active: true };
|
|
27
|
+
mockPublicClient.readContract.mockResolvedValue(mockRule);
|
|
28
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
29
|
+
const rule = await actions.getReputationRule({ ruleId: MOCK_RULE_ID });
|
|
30
|
+
expect(rule).toEqual(mockRule);
|
|
31
|
+
expect(mockPublicClient.readContract).toHaveBeenCalledWith(expect.objectContaining({
|
|
32
|
+
functionName: 'getReputationRule',
|
|
33
|
+
args: [MOCK_RULE_ID],
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
it('should check if rule is active', async () => {
|
|
37
|
+
mockPublicClient.readContract.mockResolvedValue(true);
|
|
38
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
39
|
+
const active = await actions.isRuleActive({ ruleId: MOCK_RULE_ID });
|
|
40
|
+
expect(active).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
it('should get active rules for community', async () => {
|
|
43
|
+
const mockRules = [MOCK_RULE_ID];
|
|
44
|
+
mockPublicClient.readContract.mockResolvedValue(mockRules);
|
|
45
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
46
|
+
const rules = await actions.getActiveRules({ community: MOCK_COMMUNITY });
|
|
47
|
+
expect(rules).toEqual(mockRules);
|
|
48
|
+
});
|
|
49
|
+
it('should get rule count', async () => {
|
|
50
|
+
mockPublicClient.readContract.mockResolvedValue(10n);
|
|
51
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
52
|
+
const count = await actions.getRuleCount();
|
|
53
|
+
expect(count).toBe(10n);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('Score Computation', () => {
|
|
57
|
+
it('should compute score', async () => {
|
|
58
|
+
mockPublicClient.readContract.mockResolvedValue(850n);
|
|
59
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
60
|
+
const score = await actions.computeScore({ user: MOCK_USER, community: MOCK_COMMUNITY });
|
|
61
|
+
expect(score).toBe(850n);
|
|
62
|
+
});
|
|
63
|
+
it('should get user score', async () => {
|
|
64
|
+
mockPublicClient.readContract.mockResolvedValue(900n);
|
|
65
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
66
|
+
const score = await actions.getUserScore({ user: MOCK_USER });
|
|
67
|
+
expect(score).toBe(900n);
|
|
68
|
+
});
|
|
69
|
+
it('should get community score', async () => {
|
|
70
|
+
mockPublicClient.readContract.mockResolvedValue(750n);
|
|
71
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
72
|
+
const score = await actions.getCommunityScore({ community: MOCK_COMMUNITY });
|
|
73
|
+
expect(score).toBe(750n);
|
|
74
|
+
});
|
|
75
|
+
it('should get community reputations mapping', async () => {
|
|
76
|
+
mockPublicClient.readContract.mockResolvedValue(800n);
|
|
77
|
+
const actions = reputationActions(mockReputationAddress)(mockPublicClient);
|
|
78
|
+
const reputation = await actions.communityReputations({ community: MOCK_COMMUNITY, user: MOCK_USER });
|
|
79
|
+
expect(reputation).toBe(800n);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('Write Operations', () => {
|
|
83
|
+
it('should set reputation rule', async () => {
|
|
84
|
+
const txHash = '0xabc...';
|
|
85
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
86
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
87
|
+
const result = await actions.setReputationRule({
|
|
88
|
+
ruleId: MOCK_RULE_ID,
|
|
89
|
+
rule: { weight: 50, active: true },
|
|
90
|
+
account: mockAccount
|
|
91
|
+
});
|
|
92
|
+
expect(result).toBe(txHash);
|
|
93
|
+
});
|
|
94
|
+
it('should enable rule', async () => {
|
|
95
|
+
const txHash = '0xdef...';
|
|
96
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
97
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
98
|
+
const result = await actions.enableRule({ ruleId: MOCK_RULE_ID, account: mockAccount });
|
|
99
|
+
expect(result).toBe(txHash);
|
|
100
|
+
});
|
|
101
|
+
it('should disable rule', async () => {
|
|
102
|
+
const txHash = '0xghi...';
|
|
103
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
104
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
105
|
+
const result = await actions.disableRule({ ruleId: MOCK_RULE_ID, account: mockAccount });
|
|
106
|
+
expect(result).toBe(txHash);
|
|
107
|
+
});
|
|
108
|
+
it('should batch update scores', async () => {
|
|
109
|
+
const txHash = '0xjkl...';
|
|
110
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
111
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
112
|
+
const result = await actions.batchUpdateScores({
|
|
113
|
+
users: [MOCK_USER],
|
|
114
|
+
scores: [100n],
|
|
115
|
+
account: mockAccount
|
|
116
|
+
});
|
|
117
|
+
expect(result).toBe(txHash);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('Sync Operations', () => {
|
|
121
|
+
it('should batch sync to registry', async () => {
|
|
122
|
+
const txHash = '0xmno...';
|
|
123
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
124
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
125
|
+
const result = await actions.batchSyncToRegistry({
|
|
126
|
+
users: [MOCK_USER],
|
|
127
|
+
account: mockAccount
|
|
128
|
+
});
|
|
129
|
+
expect(result).toBe(txHash);
|
|
130
|
+
});
|
|
131
|
+
it('should sync to registry with proof', async () => {
|
|
132
|
+
const txHash = '0xpqr...';
|
|
133
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
134
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
135
|
+
const result = await actions.syncToRegistry({
|
|
136
|
+
user: MOCK_USER,
|
|
137
|
+
communities: [MOCK_COMMUNITY],
|
|
138
|
+
ruleIds: [[MOCK_RULE_ID]],
|
|
139
|
+
activities: [[100n]],
|
|
140
|
+
epoch: 1n,
|
|
141
|
+
proof: '0x',
|
|
142
|
+
account: mockAccount
|
|
143
|
+
});
|
|
144
|
+
expect(result).toBe(txHash);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe('Admin Functions', () => {
|
|
148
|
+
it('should set registry', async () => {
|
|
149
|
+
const txHash = '0xstu...';
|
|
150
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
151
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
152
|
+
const result = await actions.setRegistry({
|
|
153
|
+
registry: '0x8888888888888888888888888888888888888888',
|
|
154
|
+
account: mockAccount
|
|
155
|
+
});
|
|
156
|
+
expect(result).toBe(txHash);
|
|
157
|
+
});
|
|
158
|
+
it('should set entropy factor', async () => {
|
|
159
|
+
const txHash = '0xvwx...';
|
|
160
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
161
|
+
const actions = reputationActions(mockReputationAddress)(mockWalletClient);
|
|
162
|
+
const result = await actions.setEntropyFactor({
|
|
163
|
+
factor: 100n,
|
|
164
|
+
account: mockAccount
|
|
165
|
+
});
|
|
166
|
+
expect(result).toBe(txHash);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { type Address, type PublicClient, type WalletClient, type Hex, type Hash, type Account } from 'viem';
|
|
2
|
+
export type SBTActions = {
|
|
3
|
+
sbtSafeMintForRole: (args: {
|
|
4
|
+
roleId: Hex;
|
|
5
|
+
to: Address;
|
|
6
|
+
tokenURI: string;
|
|
7
|
+
account?: Account | Address;
|
|
8
|
+
}) => Promise<Hash>;
|
|
9
|
+
sbtAirdropMint: (args: {
|
|
10
|
+
roleId: Hex;
|
|
11
|
+
to: Address;
|
|
12
|
+
tokenURI: string;
|
|
13
|
+
account?: Account | Address;
|
|
14
|
+
}) => Promise<Hash>;
|
|
15
|
+
sbtMintForRole: (args: {
|
|
16
|
+
roleId: Hex;
|
|
17
|
+
to: Address;
|
|
18
|
+
account?: Account | Address;
|
|
19
|
+
}) => Promise<Hash>;
|
|
20
|
+
sbtGetUserSBT: (args: {
|
|
21
|
+
user: Address;
|
|
22
|
+
roleId: Hex;
|
|
23
|
+
}) => Promise<bigint>;
|
|
24
|
+
sbtGetSBTData: (args: {
|
|
25
|
+
tokenId: bigint;
|
|
26
|
+
}) => Promise<any>;
|
|
27
|
+
sbtGetCommunityMembership: (args: {
|
|
28
|
+
user: Address;
|
|
29
|
+
community: Address;
|
|
30
|
+
}) => Promise<bigint>;
|
|
31
|
+
sbtGetMemberships: (args: {
|
|
32
|
+
user: Address;
|
|
33
|
+
}) => Promise<any[]>;
|
|
34
|
+
sbtGetActiveMemberships: (args: {
|
|
35
|
+
user: Address;
|
|
36
|
+
}) => Promise<any[]>;
|
|
37
|
+
sbtVerifyCommunityMembership: (args: {
|
|
38
|
+
user: Address;
|
|
39
|
+
community: Address;
|
|
40
|
+
}) => Promise<boolean>;
|
|
41
|
+
sbtUserToSBT: (args: {
|
|
42
|
+
user: Address;
|
|
43
|
+
}) => Promise<bigint>;
|
|
44
|
+
sbtSbtData: (args: {
|
|
45
|
+
tokenId: bigint;
|
|
46
|
+
}) => Promise<any>;
|
|
47
|
+
sbtMembershipIndex: (args: {
|
|
48
|
+
user: Address;
|
|
49
|
+
index: bigint;
|
|
50
|
+
}) => Promise<any>;
|
|
51
|
+
sbtBalanceOf: (args: {
|
|
52
|
+
owner: Address;
|
|
53
|
+
}) => Promise<bigint>;
|
|
54
|
+
sbtOwnerOf: (args: {
|
|
55
|
+
tokenId: bigint;
|
|
56
|
+
}) => Promise<Address>;
|
|
57
|
+
sbtSafeTransferFrom: (args: {
|
|
58
|
+
from: Address;
|
|
59
|
+
to: Address;
|
|
60
|
+
tokenId: bigint;
|
|
61
|
+
account?: Account | Address;
|
|
62
|
+
}) => Promise<Hash>;
|
|
63
|
+
sbtTransferFrom: (args: {
|
|
64
|
+
from: Address;
|
|
65
|
+
to: Address;
|
|
66
|
+
tokenId: bigint;
|
|
67
|
+
account?: Account | Address;
|
|
68
|
+
}) => Promise<Hash>;
|
|
69
|
+
sbtApprove: (args: {
|
|
70
|
+
to: Address;
|
|
71
|
+
tokenId: bigint;
|
|
72
|
+
account?: Account | Address;
|
|
73
|
+
}) => Promise<Hash>;
|
|
74
|
+
sbtSetApprovalForAll: (args: {
|
|
75
|
+
operator: Address;
|
|
76
|
+
approved: boolean;
|
|
77
|
+
account?: Account | Address;
|
|
78
|
+
}) => Promise<Hash>;
|
|
79
|
+
sbtGetApproved: (args: {
|
|
80
|
+
tokenId: bigint;
|
|
81
|
+
}) => Promise<Address>;
|
|
82
|
+
sbtIsApprovedForAll: (args: {
|
|
83
|
+
owner: Address;
|
|
84
|
+
operator: Address;
|
|
85
|
+
}) => Promise<boolean>;
|
|
86
|
+
sbtName: () => Promise<string>;
|
|
87
|
+
sbtSymbol: () => Promise<string>;
|
|
88
|
+
sbtTokenURI: (args: {
|
|
89
|
+
tokenId: bigint;
|
|
90
|
+
}) => Promise<string>;
|
|
91
|
+
sbtTotalSupply: () => Promise<bigint>;
|
|
92
|
+
sbtTokenByIndex: (args: {
|
|
93
|
+
index: bigint;
|
|
94
|
+
}) => Promise<bigint>;
|
|
95
|
+
sbtTokenOfOwnerByIndex: (args: {
|
|
96
|
+
owner: Address;
|
|
97
|
+
index: bigint;
|
|
98
|
+
}) => Promise<bigint>;
|
|
99
|
+
sbtSupportsInterface: (args: {
|
|
100
|
+
interfaceId: Hex;
|
|
101
|
+
}) => Promise<boolean>;
|
|
102
|
+
sbtNextTokenId: () => Promise<bigint>;
|
|
103
|
+
sbtMint: (args: {
|
|
104
|
+
to: Address;
|
|
105
|
+
tokenURI: string;
|
|
106
|
+
account?: Account | Address;
|
|
107
|
+
}) => Promise<Hash>;
|
|
108
|
+
sbtBurn: (args: {
|
|
109
|
+
tokenId: bigint;
|
|
110
|
+
account?: Account | Address;
|
|
111
|
+
}) => Promise<Hash>;
|
|
112
|
+
sbtBurnSBT: (args: {
|
|
113
|
+
tokenId: bigint;
|
|
114
|
+
account?: Account | Address;
|
|
115
|
+
}) => Promise<Hash>;
|
|
116
|
+
sbtDeactivateAllMemberships: (args: {
|
|
117
|
+
user: Address;
|
|
118
|
+
account?: Account | Address;
|
|
119
|
+
}) => Promise<Hash>;
|
|
120
|
+
sbtSetBaseURI: (args: {
|
|
121
|
+
baseURI: string;
|
|
122
|
+
account?: Account | Address;
|
|
123
|
+
}) => Promise<Hash>;
|
|
124
|
+
sbtLeaveCommunity: (args: {
|
|
125
|
+
community: Address;
|
|
126
|
+
account?: Account | Address;
|
|
127
|
+
}) => Promise<Hash>;
|
|
128
|
+
sbtDeactivateMembership: (args: {
|
|
129
|
+
tokenId: bigint;
|
|
130
|
+
account?: Account | Address;
|
|
131
|
+
}) => Promise<Hash>;
|
|
132
|
+
sbtRecordActivity: (args: {
|
|
133
|
+
user: Address;
|
|
134
|
+
account?: Account | Address;
|
|
135
|
+
}) => Promise<Hash>;
|
|
136
|
+
sbtLastActivityTime: (args: {
|
|
137
|
+
user: Address;
|
|
138
|
+
}) => Promise<bigint>;
|
|
139
|
+
sbtWeeklyActivity: (args: {
|
|
140
|
+
user: Address;
|
|
141
|
+
}) => Promise<bigint>;
|
|
142
|
+
sbtReputationCalculator: () => Promise<Address>;
|
|
143
|
+
sbtSetReputationCalculator: (args: {
|
|
144
|
+
calculator: Address;
|
|
145
|
+
account?: Account | Address;
|
|
146
|
+
}) => Promise<Hash>;
|
|
147
|
+
sbtMintFee: () => Promise<bigint>;
|
|
148
|
+
sbtSetMintFee: (args: {
|
|
149
|
+
fee: bigint;
|
|
150
|
+
account?: Account | Address;
|
|
151
|
+
}) => Promise<Hash>;
|
|
152
|
+
sbtMinLockAmount: () => Promise<bigint>;
|
|
153
|
+
sbtSetMinLockAmount: (args: {
|
|
154
|
+
amount: bigint;
|
|
155
|
+
account?: Account | Address;
|
|
156
|
+
}) => Promise<Hash>;
|
|
157
|
+
sbtPause: (args: {
|
|
158
|
+
account?: Account | Address;
|
|
159
|
+
}) => Promise<Hash>;
|
|
160
|
+
sbtUnpause: (args: {
|
|
161
|
+
account?: Account | Address;
|
|
162
|
+
}) => Promise<Hash>;
|
|
163
|
+
sbtPaused: () => Promise<boolean>;
|
|
164
|
+
sbtDaoMultisig: () => Promise<Address>;
|
|
165
|
+
sbtSetDAOMultisig: (args: {
|
|
166
|
+
multisig: Address;
|
|
167
|
+
account?: Account | Address;
|
|
168
|
+
}) => Promise<Hash>;
|
|
169
|
+
sbtSetRegistry: (args: {
|
|
170
|
+
registry: Address;
|
|
171
|
+
account?: Account | Address;
|
|
172
|
+
}) => Promise<Hash>;
|
|
173
|
+
sbtSetSuperPaymaster: (args: {
|
|
174
|
+
paymaster: Address;
|
|
175
|
+
account?: Account | Address;
|
|
176
|
+
}) => Promise<Hash>;
|
|
177
|
+
sbtVersion: () => Promise<string>;
|
|
178
|
+
sbtREGISTRY: () => Promise<Address>;
|
|
179
|
+
sbtGTOKEN_STAKING: () => Promise<Address>;
|
|
180
|
+
sbtGTOKEN: () => Promise<Address>;
|
|
181
|
+
sbtSUPER_PAYMASTER: () => Promise<Address>;
|
|
182
|
+
sbtOwner: () => Promise<Address>;
|
|
183
|
+
sbtTransferSBTOwnership: (args: {
|
|
184
|
+
newOwner: Address;
|
|
185
|
+
account?: Account | Address;
|
|
186
|
+
}) => Promise<Hash>;
|
|
187
|
+
sbtRenounceOwnership: (args: {
|
|
188
|
+
account?: Account | Address;
|
|
189
|
+
}) => Promise<Hash>;
|
|
190
|
+
};
|
|
191
|
+
export declare const sbtActions: (address: Address) => (client: PublicClient | WalletClient) => SBTActions;
|