@claritydao/midnight-agora-contracts 0.1.0

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.
@@ -0,0 +1,703 @@
1
+ import {
2
+ type CircuitContext,
3
+ CircuitResults,
4
+ QueryContext,
5
+ constructorContext,
6
+ } from '@midnight-ntwrk/compact-runtime';
7
+ import { sampleContractAddress } from '@midnight-ntwrk/zswap';
8
+ import {
9
+ Contract as GovernanceContract,
10
+ type Ledger,
11
+ ledger,
12
+ } from '../managed/governor/contract/index.cjs';
13
+ import { type GovernorPrivateState, witnesses } from '../witnesses.js';
14
+
15
+ // Governance simulator for testing the DAO contract locally without running a full node
16
+ export class GovernanceSimulator {
17
+ readonly contract: GovernanceContract<GovernorPrivateState>;
18
+ readonly contractAddress: string;
19
+ circuitContext: CircuitContext<GovernorPrivateState>;
20
+ updateUserPrivateState: (newPrivateState: GovernorPrivateState) => void;
21
+
22
+ constructor(secretKey: Uint8Array) {
23
+ this.contract = new GovernanceContract<GovernorPrivateState>(witnesses);
24
+
25
+ // Example initial private state for the DApp user
26
+ const initialPrivateState: GovernorPrivateState = {
27
+ secretKey: secretKey, // Replace with actual test key if needed
28
+ currentTime: BigInt(Math.floor(Date.now() / 1000)),
29
+ userStake: {
30
+ amount: 1000n,
31
+ delegatedTo: new Uint8Array(32), // Self-delegated by default
32
+ stakedAt: BigInt(Math.floor(Date.now() / 1000)),
33
+ },
34
+ votingHistory: [], // Array of vote records (fill as needed for tests)
35
+ proposalHistory: [], // Array of proposal records (fill as needed for tests)
36
+ governanceConfig: {
37
+ votingPeriod: 604800n, // 7 days
38
+ quorumThreshold: 100000n, // 100K tokens
39
+ proposalThreshold: 50000n, // 50K tokens
40
+ proposalLifetime: 2592000n, // 30 days
41
+ executionDelay: 172800n, // 2 days
42
+ gracePeriod: 1209600n, // 14 days
43
+ minStakeAmount: 1000n, // 1K tokens
44
+ stakingPeriod: 604800n, // 7 days
45
+ },
46
+ // Add any other fields required by your contract or witnesses here
47
+ };
48
+
49
+ const {
50
+ currentPrivateState,
51
+ currentContractState,
52
+ currentZswapLocalState,
53
+ } = this.contract.initialState(
54
+ constructorContext(initialPrivateState, '0'.repeat(64)),
55
+ {
56
+ governance: {
57
+ votingPeriod: 604800n,
58
+ quorumThreshold: 100000n,
59
+ proposalThreshold: 50000n,
60
+ proposalLifetime: 2592000n,
61
+ executionDelay: 172800n,
62
+ gracePeriod: 1209600n,
63
+ minStakeAmount: 1000n,
64
+ stakingPeriod: 604800n,
65
+ },
66
+ executionDelay: 172800n,
67
+ gracePeriod: 1209600n,
68
+ emergencyVetoEnabled: true,
69
+ emergencyVetoThreshold: 75000n,
70
+ maxActiveProposals: 100n,
71
+ proposalLifetime: 2592000n,
72
+ },
73
+ 'DAO Token',
74
+ 'DAO',
75
+ 18n,
76
+ secretKey
77
+ );
78
+
79
+ this.updateUserPrivateState = (newPrivateState: GovernorPrivateState) => {
80
+ this.circuitContext = {
81
+ ...this.circuitContext,
82
+ currentPrivateState: newPrivateState,
83
+ };
84
+ };
85
+
86
+ this.circuitContext = {
87
+ currentPrivateState,
88
+ currentZswapLocalState,
89
+ originalState: currentContractState,
90
+ transactionContext: new QueryContext(
91
+ currentContractState.data,
92
+ sampleContractAddress()
93
+ ),
94
+ };
95
+
96
+ // Initialize the contract's timestamp with the current time
97
+ const initialTime = BigInt(Math.floor(Date.now() / 1000));
98
+ this.circuitContext = this.contract.impureCircuits.storeTimestamp(
99
+ this.circuitContext,
100
+ initialTime
101
+ ).context;
102
+
103
+
104
+
105
+ this.contractAddress = this.circuitContext.transactionContext.address;
106
+ }
107
+
108
+ // Set governor permissions (Admin = 3)
109
+ public async setGovernorPermission(userId: Uint8Array, permission: number) {
110
+ const proof = {
111
+ proposalId: 0n,
112
+ effectId: 0n,
113
+ approvalTime: BigInt(Math.floor(Date.now() / 1000)),
114
+ nonce: new Uint8Array(32),
115
+ };
116
+ const result = this.contract.impureCircuits.setGovernorPermissionSecure(
117
+ this.circuitContext,
118
+ userId,
119
+ permission,
120
+ proof
121
+ );
122
+ return this.updateStateAndGetLedger(result);
123
+ }
124
+
125
+ public async getLedger(): Promise<Ledger> {
126
+ return ledger(this.circuitContext.transactionContext.state);
127
+ }
128
+
129
+ public async getPrivateState(): Promise<GovernorPrivateState> {
130
+ return this.circuitContext.currentPrivateState;
131
+ }
132
+
133
+ updateStateAndGetLedger<T>(circuitResults: CircuitResults<GovernorPrivateState, T>): Ledger {
134
+ this.circuitContext = circuitResults.context;
135
+ this.updateUserPrivateState(circuitResults.context.currentPrivateState);
136
+ return ledger(this.circuitContext.transactionContext.state);
137
+ }
138
+
139
+ // Example: createProposalWithEffect
140
+ public async createProposalWithEffect(
141
+ creator: Uint8Array,
142
+ title: string,
143
+ description: string,
144
+ actions: any[],
145
+ proof: any,
146
+ votingStartTime: bigint,
147
+ votingEndTime: bigint
148
+ ) {
149
+ const result = this.contract.impureCircuits.createProposalWithEffect(
150
+ this.circuitContext,
151
+ creator,
152
+ title,
153
+ description,
154
+ actions,
155
+ proof,
156
+ votingStartTime,
157
+ votingEndTime
158
+ );
159
+ return this.updateStateAndGetLedger(result);
160
+ }
161
+
162
+ // Example: castVoteWithValidation
163
+ public async castVoteWithValidation(
164
+ proposalId: bigint,
165
+ voter: Uint8Array,
166
+ choice: number,
167
+ proof: any
168
+ ) {
169
+ const result = this.contract.impureCircuits.castVoteWithValidation(
170
+ this.circuitContext,
171
+ proposalId,
172
+ voter,
173
+ choice,
174
+ proof
175
+ );
176
+ return this.updateStateAndGetLedger(result);
177
+ }
178
+
179
+ // Example: finalizeAndQueueProposal
180
+ public async finalizeAndQueueProposal(proposalId: bigint, proof: any) {
181
+ const result = this.contract.impureCircuits.finalizeAndQueueProposal(
182
+ this.circuitContext,
183
+ proposalId,
184
+ proof
185
+ );
186
+ return this.updateStateAndGetLedger(result);
187
+ }
188
+
189
+ // Example: executeQueuedProposal
190
+ public async executeQueuedProposal(
191
+ proposalId: bigint,
192
+ effectId: bigint,
193
+ proof: any
194
+ ) {
195
+ const result = this.contract.impureCircuits.executeQueuedProposal(
196
+ this.circuitContext,
197
+ proposalId,
198
+ effectId,
199
+ proof
200
+ );
201
+ return this.updateStateAndGetLedger(result);
202
+ }
203
+
204
+ // Example: cancelProposalWithReason
205
+ public async cancelProposalWithReason(
206
+ proposalId: bigint,
207
+ reason: string,
208
+ proof: any
209
+ ) {
210
+ const result = this.contract.impureCircuits.cancelProposalWithReason(
211
+ this.circuitContext,
212
+ proposalId,
213
+ reason,
214
+ proof
215
+ );
216
+ return this.updateStateAndGetLedger(result);
217
+ }
218
+
219
+ // Example: emergencyVetoProposal
220
+ public async emergencyVetoProposal(
221
+ proposalId: bigint,
222
+ vetoers: Uint8Array[],
223
+ proof: any
224
+ ) {
225
+ const result = this.contract.impureCircuits.emergencyVetoProposal(
226
+ this.circuitContext,
227
+ proposalId,
228
+ vetoers,
229
+ proof
230
+ );
231
+ return this.updateStateAndGetLedger(result);
232
+ }
233
+
234
+ // Example: updateGovernorConfig
235
+ public async updateGovernorConfig(newConfig: any, proof: any) {
236
+ const result = this.contract.impureCircuits.updateGovernorConfig(
237
+ this.circuitContext,
238
+ newConfig,
239
+ proof
240
+ );
241
+ return this.updateStateAndGetLedger(result);
242
+ }
243
+
244
+ // Example: getGovernorStatus
245
+ public async getGovernorStatus() {
246
+ const result = this.contract.impureCircuits.getGovernorStatus(
247
+ this.circuitContext
248
+ );
249
+ return result.result;
250
+ }
251
+
252
+ // Example: getActiveProposalCount
253
+ public async getActiveProposalCount(): Promise<bigint> {
254
+ const result = this.contract.impureCircuits.getActiveProposalCount(
255
+ this.circuitContext
256
+ );
257
+ return result.result;
258
+ }
259
+
260
+ // Example: getQueuedProposalCount
261
+ public async getQueuedProposalCount(): Promise<bigint> {
262
+ const result = this.contract.impureCircuits.getQueuedProposalCount(
263
+ this.circuitContext
264
+ );
265
+ return result.result;
266
+ }
267
+
268
+ // --- Add additional circuit wrappers here for all exported circuits from your .compact files ---
269
+ // For each exported circuit, add a method that calls the corresponding impureCircuits function.
270
+ // Use the correct argument types and return values as defined in your contract API.
271
+
272
+ // --- StakeModule circuits ---
273
+ public async registerStake(userId: Uint8Array, amount: bigint, proof: any) {
274
+ // Use the Governor validation function instead of direct module function
275
+ const adjustedProof = { ...proof, amount: amount };
276
+ const result = this.contract.impureCircuits.registerStakeWithValidation(
277
+ this.circuitContext, userId, amount, adjustedProof
278
+ );
279
+ return this.updateStateAndGetLedger(result);
280
+ }
281
+ public async withdrawStake(userId: Uint8Array, amount: bigint, proof: any) {
282
+ // Use the Governor validation function instead of direct module function
283
+ const adjustedProof = { ...proof, amount: amount };
284
+ const result = this.contract.impureCircuits.withdrawStakeWithValidation(
285
+ this.circuitContext, userId, amount, adjustedProof
286
+ );
287
+ return this.updateStateAndGetLedger(result);
288
+ }
289
+ public async delegateStake(delegator: Uint8Array, delegatee: Uint8Array, amount: bigint, proof: any) {
290
+ const result = this.contract.impureCircuits.delegateStakeWithValidation(
291
+ this.circuitContext, delegator, delegatee, amount, proof
292
+ );
293
+ return this.updateStateAndGetLedger(result);
294
+ }
295
+ public async undelegateStake(delegator: Uint8Array, delegatee: Uint8Array, amount: bigint, proof: any) {
296
+ const result = this.contract.impureCircuits.undelegateStakeWithValidation(
297
+ this.circuitContext, delegator, delegatee, amount, proof
298
+ );
299
+ return this.updateStateAndGetLedger(result);
300
+ }
301
+ public async getStakeInfo(userId: Uint8Array) {
302
+ return this.contract.impureCircuits.getStakeInfo(this.circuitContext, userId).result;
303
+ }
304
+ public async getTotalDelegatedPower(userId: Uint8Array) {
305
+ return this.contract.impureCircuits.getTotalDelegatedPower(this.circuitContext, userId).result;
306
+ }
307
+ public async hasProposalThreshold(userId: Uint8Array) {
308
+ return this.contract.impureCircuits.hasProposalThreshold(this.circuitContext, userId).result;
309
+ }
310
+ public async hasVotingPower(userId: Uint8Array) {
311
+ return this.contract.impureCircuits.hasVotingPower(this.circuitContext, userId).result;
312
+ }
313
+ public async updateGovernanceConfig(newConfig: any, proof: any) {
314
+ const result = this.contract.impureCircuits.updateGovernanceConfig(
315
+ this.circuitContext, newConfig, proof
316
+ );
317
+ return this.updateStateAndGetLedger(result);
318
+ }
319
+ public async getGovernanceConfig() {
320
+ return this.contract.impureCircuits.getGovernanceConfig(this.circuitContext).result;
321
+ }
322
+ public async getStakeRecord(userId: Uint8Array) {
323
+ return this.contract.impureCircuits.getStakeRecord(this.circuitContext, userId).result;
324
+ }
325
+ public async validateStakeWithdrawal(stakeRecord: any, amount: bigint, currentTime: bigint) {
326
+ return this.contract.impureCircuits.validateStakeWithdrawal(
327
+ this.circuitContext, stakeRecord, amount, currentTime
328
+ ).result;
329
+ }
330
+
331
+ // --- Governor validation methods ---
332
+ public async registerStakeWithValidation(userId: Uint8Array, amount: bigint, proof: any) {
333
+ const result = this.contract.impureCircuits.registerStakeWithValidation(
334
+ this.circuitContext, userId, amount, proof
335
+ );
336
+ return this.updateStateAndGetLedger(result);
337
+ }
338
+
339
+ public async withdrawStakeWithValidation(userId: Uint8Array, amount: bigint, proof: any) {
340
+ const result = this.contract.impureCircuits.withdrawStakeWithValidation(
341
+ this.circuitContext, userId, amount, proof
342
+ );
343
+ return this.updateStateAndGetLedger(result);
344
+ }
345
+
346
+ public async delegateStakeWithValidation(delegator: Uint8Array, delegatee: Uint8Array, amount: bigint, proof: any) {
347
+ const result = this.contract.impureCircuits.delegateStakeWithValidation(
348
+ this.circuitContext, delegator, delegatee, amount, proof
349
+ );
350
+ return this.updateStateAndGetLedger(result);
351
+ }
352
+
353
+ public async undelegateStakeWithValidation(delegator: Uint8Array, delegatee: Uint8Array, amount: bigint, proof: any) {
354
+ const result = this.contract.impureCircuits.undelegateStakeWithValidation(
355
+ this.circuitContext, delegator, delegatee, amount, proof
356
+ );
357
+ return this.updateStateAndGetLedger(result);
358
+ }
359
+
360
+ public async depositToTreasuryWithValidation(token: Uint8Array, amount: bigint, depositor: Uint8Array, proof: any) {
361
+ const result = this.contract.impureCircuits.depositToTreasuryWithValidation(
362
+ this.circuitContext, token, amount, depositor, proof
363
+ );
364
+ return this.updateStateAndGetLedger(result);
365
+ }
366
+
367
+ public async withdrawFromTreasuryWithValidation(token: Uint8Array, amount: bigint, recipient: Uint8Array, effectId: bigint, proof: any) {
368
+ const result = this.contract.impureCircuits.withdrawFromTreasuryWithValidation(
369
+ this.circuitContext, token, amount, recipient, effectId, proof
370
+ );
371
+ return this.updateStateAndGetLedger(result);
372
+ }
373
+
374
+ public async finalizeProposalWithValidation(proposalId: bigint, proof: any) {
375
+ const result = this.contract.impureCircuits.finalizeProposalWithValidation(
376
+ this.circuitContext, proposalId, proof
377
+ );
378
+ return this.updateStateAndGetLedger(result);
379
+ }
380
+
381
+ public async queueProposalWithValidation(proposalId: bigint, proof: any) {
382
+ const result = this.contract.impureCircuits.queueProposalWithValidation(
383
+ this.circuitContext, proposalId, proof
384
+ );
385
+ return this.updateStateAndGetLedger(result);
386
+ }
387
+
388
+ // --- ProposalModule circuits ---
389
+ public async createProposal(creator: Uint8Array, title: string, description: string, effectId: bigint, proof: any, votingStartTime: bigint, votingEndTime: bigint) {
390
+ // Use createProposalWithEffect instead of direct module function
391
+ const actions = new Array(10).fill(null).map((_, index) => ({
392
+ typ: 0, // EffectActionType.MintToken
393
+ token: new Uint8Array(32),
394
+ amount: index === 0 ? 1000n : 5n,
395
+ to: creator,
396
+ configKey: new Uint8Array(32),
397
+ configValue: new Uint8Array(32),
398
+ }));
399
+ const result = this.contract.impureCircuits.createProposalWithEffect(
400
+ this.circuitContext, creator, title, description, actions, proof, votingStartTime, votingEndTime
401
+ );
402
+ return this.updateStateAndGetLedger(result);
403
+ }
404
+ public async castVote(proposalId: bigint, voter: Uint8Array, choice: number, proof: any) {
405
+ const result = this.contract.impureCircuits.castVoteWithValidation(
406
+ this.circuitContext, proposalId, voter, choice, proof
407
+ );
408
+ return this.updateStateAndGetLedger(result);
409
+ }
410
+ public async finalizeProposal(proposalId: bigint, proof: any) {
411
+ const result = this.contract.impureCircuits.finalizeProposalWithValidation(
412
+ this.circuitContext, proposalId, proof
413
+ );
414
+ return this.updateStateAndGetLedger(result);
415
+ }
416
+ public async queueProposal(proposalId: bigint, proof: any) {
417
+ const result = this.contract.impureCircuits.queueProposalWithValidation(
418
+ this.circuitContext, proposalId, proof
419
+ );
420
+ return this.updateStateAndGetLedger(result);
421
+ }
422
+ public async markProposalExecuted(proposalId: bigint, proof: any) {
423
+ const result = this.contract.impureCircuits.markProposalExecutedWithValidation(
424
+ this.circuitContext, proposalId, proof
425
+ );
426
+ return this.updateStateAndGetLedger(result);
427
+ }
428
+ public async cancelProposal(proposalId: bigint, proof: any) {
429
+ const result = this.contract.impureCircuits.cancelProposalWithValidation(
430
+ this.circuitContext, proposalId, proof
431
+ );
432
+ return this.updateStateAndGetLedger(result);
433
+ }
434
+ public async getProposal(proposalId: bigint) {
435
+ return this.contract.impureCircuits.getProposal(this.circuitContext, proposalId).result;
436
+ }
437
+ public async getProposalVoteCount(proposalId: bigint) {
438
+ return this.contract.impureCircuits.getProposalVoteCount(this.circuitContext, proposalId).result;
439
+ }
440
+ public async generateProposalId() {
441
+ return this.contract.impureCircuits.generateProposalId(this.circuitContext).result;
442
+ }
443
+
444
+ // --- EffectModule circuits ---
445
+ public async createEffect(proposalId: bigint, actions: any[], proof: any) {
446
+ const result = this.contract.impureCircuits.createEffectWithValidation(
447
+ this.circuitContext, proposalId, actions, proof
448
+ );
449
+ return this.updateStateAndGetLedger(result);
450
+ }
451
+ public async executeEffect(input: bigint, proof: any) {
452
+ const result = this.contract.impureCircuits.executeEffectWithValidation(
453
+ this.circuitContext, input, proof
454
+ );
455
+ return this.updateStateAndGetLedger(result);
456
+ }
457
+ public async cancelEffect(effectId: bigint, proof: any) {
458
+ const result = this.contract.impureCircuits.cancelEffectWithValidation(
459
+ this.circuitContext, effectId, proof
460
+ );
461
+ return this.updateStateAndGetLedger(result);
462
+ }
463
+ public async getEffect(effectId: bigint) {
464
+ return this.contract.impureCircuits.getEffect(this.circuitContext, effectId).result;
465
+ }
466
+ public async canExecuteEffect(effectId: bigint) {
467
+ return this.contract.impureCircuits.canExecuteEffect(this.circuitContext, effectId).result;
468
+ }
469
+ public async validateEffectActions(actions: any[]) {
470
+ return this.contract.impureCircuits.validateEffectActions(this.circuitContext, actions).result;
471
+ }
472
+ public async batchExecuteEffectsWithValidation(effectIds: bigint[], validCount: bigint, proof: any) {
473
+ const result = this.contract.impureCircuits.batchExecuteEffectsWithValidation(
474
+ this.circuitContext, effectIds, validCount, proof
475
+ );
476
+ return this.updateStateAndGetLedger(result);
477
+ }
478
+ public async createMintTokenEffect(proposalId: bigint, token: Uint8Array, amount: bigint, to: Uint8Array, proof: any) {
479
+ return this.contract.impureCircuits.createMintTokenEffect(
480
+ this.circuitContext, proposalId, token, amount, to, proof
481
+ ).result;
482
+ }
483
+ public async createTransferEffect(proposalId: bigint, token: Uint8Array, amount: bigint, to: Uint8Array, proof: any) {
484
+ return this.contract.impureCircuits.createTransferEffect(
485
+ this.circuitContext, proposalId, token, amount, to, proof
486
+ ).result;
487
+ }
488
+ public async createConfigUpdateEffect(proposalId: bigint, configKey: Uint8Array, configValue: Uint8Array, proof: any) {
489
+ return this.contract.impureCircuits.createConfigUpdateEffect(
490
+ this.circuitContext, proposalId, configKey, configValue, proof
491
+ ).result;
492
+ }
493
+ public async generateEffectId() {
494
+ return this.contract.impureCircuits.generateEffectId(this.circuitContext).result;
495
+ }
496
+ public async mint(token: Uint8Array, amount: bigint, to: Uint8Array) {
497
+ this.circuitContext = this.contract.impureCircuits.mint(
498
+ this.circuitContext, token, amount, to
499
+ ).context;
500
+ return ledger(this.circuitContext.transactionContext.state);
501
+ }
502
+ public async getDaoConfig(key: Uint8Array) {
503
+ return this.contract.impureCircuits.getDaoConfig(this.circuitContext, key).result;
504
+ }
505
+
506
+ // --- TreasuryModule circuits ---
507
+ public async depositToTreasury(token: Uint8Array, amount: bigint, depositor: Uint8Array, proof: any) {
508
+ const result = this.contract.impureCircuits.depositToTreasuryWithValidation(
509
+ this.circuitContext, token, amount, depositor, proof
510
+ );
511
+ return this.updateStateAndGetLedger(result);
512
+ }
513
+ public async withdrawFromTreasury(token: Uint8Array, amount: bigint, recipient: Uint8Array, effectId: bigint, proof: any) {
514
+ const result = this.contract.impureCircuits.withdrawFromTreasuryWithValidation(
515
+ this.circuitContext, token, amount, recipient, effectId, proof
516
+ );
517
+ return this.updateStateAndGetLedger(result);
518
+ }
519
+ public async transferTreasuryTokens(fromToken: Uint8Array, toToken: Uint8Array, amount: bigint, effectId: bigint, proof: any) {
520
+ const result = this.contract.impureCircuits.transferTreasuryTokensWithValidation(
521
+ this.circuitContext, fromToken, toToken, amount, effectId, proof
522
+ );
523
+ return this.updateStateAndGetLedger(result);
524
+ }
525
+ public async burnTreasuryTokens(token: Uint8Array, amount: bigint, effectId: bigint, proof: any) {
526
+ const result = this.contract.impureCircuits.burnTreasuryTokensWithValidation(
527
+ this.circuitContext, token, amount, effectId, proof
528
+ );
529
+ return this.updateStateAndGetLedger(result);
530
+ }
531
+ public async setSpendingLimit(token: Uint8Array, limit: bigint, proof: any) {
532
+ const result = this.contract.impureCircuits.setSpendingLimit(
533
+ this.circuitContext, token, limit, proof
534
+ );
535
+ return this.updateStateAndGetLedger(result);
536
+ }
537
+ public async authorizeSpender(spender: Uint8Array, proof: any) {
538
+ const result = this.contract.impureCircuits.authorizeSpender(
539
+ this.circuitContext, spender, proof
540
+ );
541
+ return this.updateStateAndGetLedger(result);
542
+ }
543
+ public async revokeSpenderAuthorization(spender: Uint8Array, proof: any) {
544
+ const result = this.contract.impureCircuits.revokeSpenderAuthorization(
545
+ this.circuitContext, spender, proof
546
+ );
547
+ return this.updateStateAndGetLedger(result);
548
+ }
549
+ public async getTreasuryBalance(token: Uint8Array) {
550
+ return this.contract.impureCircuits.getTreasuryBalance(this.circuitContext, token).result;
551
+ }
552
+ public async getTotalTreasuryValue(token: Uint8Array) {
553
+ return this.contract.impureCircuits.getTotalTreasuryValue(this.circuitContext, token).result;
554
+ }
555
+ public async getTreasuryTransactionCount() {
556
+ return this.contract.impureCircuits.getTreasuryTransactionCount(this.circuitContext).result;
557
+ }
558
+ public async getSpendingLimit(token: Uint8Array) {
559
+ return this.contract.impureCircuits.getSpendingLimit(this.circuitContext, token).result;
560
+ }
561
+ public async isAuthorizedSpender(spender: Uint8Array) {
562
+ return this.contract.impureCircuits.isAuthorizedSpender(this.circuitContext, spender).result;
563
+ }
564
+ public async validateTreasurySpending(token: Uint8Array, amount: bigint, spender: Uint8Array) {
565
+ return this.contract.impureCircuits.validateTreasurySpending(
566
+ this.circuitContext, token, amount, spender
567
+ ).result;
568
+ }
569
+
570
+ public async getTreasuryStatistics() {
571
+ return this.contract.impureCircuits.getTreasuryStatistics(this.circuitContext).result;
572
+ }
573
+ public async batchTreasuryOperations(operations: any[], proof: any) {
574
+ this.circuitContext = this.contract.impureCircuits.batchTreasuryOperations(
575
+ this.circuitContext, operations, proof
576
+ ).context;
577
+ return ledger(this.circuitContext.transactionContext.state);
578
+ }
579
+
580
+ public async name() {
581
+ return this.contract.impureCircuits.name(this.circuitContext).result;
582
+ }
583
+ public async symbol() {
584
+ return this.contract.impureCircuits.symbol(this.circuitContext).result;
585
+ }
586
+ public async decimals() {
587
+ return this.contract.impureCircuits.decimals(this.circuitContext).result;
588
+ }
589
+ public async totalSupply() {
590
+ return this.contract.impureCircuits.totalSupply(this.circuitContext).result;
591
+ }
592
+ public async balanceOf(account: any) {
593
+ return this.contract.impureCircuits.balanceOf(this.circuitContext, account).result;
594
+ }
595
+ public async transfer(to: any, value: bigint) {
596
+ const result = this.contract.impureCircuits.transfer(
597
+ this.circuitContext, to, value
598
+ );
599
+ return this.updateStateAndGetLedger(result);
600
+ }
601
+ public async _unsafeTransfer(to: any, value: bigint) {
602
+ const result = this.contract.impureCircuits._unsafeTransfer(
603
+ this.circuitContext, to, value
604
+ );
605
+ return this.updateStateAndGetLedger(result);
606
+ }
607
+ public async allowance(owner: any, spender: any) {
608
+ return this.contract.impureCircuits.allowance(this.circuitContext, owner, spender).result;
609
+ }
610
+ public async approve(spender: any, value: bigint) {
611
+ const result = this.contract.impureCircuits.approve(
612
+ this.circuitContext, spender, value
613
+ );
614
+ return this.updateStateAndGetLedger(result);
615
+ }
616
+ public async transferFrom(from: any, to: any, value: bigint) {
617
+ const result = this.contract.impureCircuits.transferFrom(
618
+ this.circuitContext, from, to, value
619
+ );
620
+ return this.updateStateAndGetLedger(result);
621
+ }
622
+ public async _unsafeTransferFrom(from: any, to: any, value: bigint) {
623
+ const result = this.contract.impureCircuits._unsafeTransferFrom(
624
+ this.circuitContext, from, to, value
625
+ );
626
+ return this.updateStateAndGetLedger(result);
627
+ }
628
+ public async _transfer(from: any, to: any, value: bigint) {
629
+ const result = this.contract.impureCircuits._transfer(
630
+ this.circuitContext, from, to, value
631
+ );
632
+ return this.updateStateAndGetLedger(result);
633
+ }
634
+ public async _unsafeUncheckedTransfer(from: any, to: any, value: bigint) {
635
+ const result = this.contract.impureCircuits._unsafeUncheckedTransfer(
636
+ this.circuitContext, from, to, value
637
+ );
638
+ return this.updateStateAndGetLedger(result);
639
+ }
640
+ public async _mint(account: any, value: bigint) {
641
+ const result = this.contract.impureCircuits._mint(
642
+ this.circuitContext, account, value
643
+ );
644
+ return this.updateStateAndGetLedger(result);
645
+ }
646
+ public async _unsafeMint(account: any, value: bigint) {
647
+ const result = this.contract.impureCircuits._unsafeMint(
648
+ this.circuitContext, account, value
649
+ );
650
+ return this.updateStateAndGetLedger(result);
651
+ }
652
+ public async _burn(account: any, value: bigint) {
653
+ const result = this.contract.impureCircuits._burn(
654
+ this.circuitContext, account, value
655
+ );
656
+ return this.updateStateAndGetLedger(result);
657
+ }
658
+ public async _approve(owner: any, spender: any, value: bigint) {
659
+ const result = this.contract.impureCircuits._approve(
660
+ this.circuitContext, owner, spender, value
661
+ );
662
+ return this.updateStateAndGetLedger(result);
663
+ }
664
+ public async _spendAllowance(owner: any, spender: any, value: bigint) {
665
+ const result = this.contract.impureCircuits._spendAllowance(
666
+ this.circuitContext, owner, spender, value
667
+ );
668
+ return this.updateStateAndGetLedger(result);
669
+ }
670
+
671
+ // Helper: update current time (for testing time-based logic)
672
+ public async updateCurrentTime(newTime: bigint) {
673
+ // Update the contract's timestamp using the setSystemTimestamp circuit
674
+ const result = this.contract.impureCircuits.setSystemTimestamp(this.circuitContext, newTime);
675
+ return this.updateStateAndGetLedger(result);
676
+ }
677
+
678
+ // Helper: get current time from contract
679
+ public async getCurrentTime(): Promise<bigint> {
680
+ return this.contract.impureCircuits.getCurrentTime(this.circuitContext).result;
681
+ }
682
+
683
+ public async hasGovernorPermission(userId: Uint8Array, permission: number) {
684
+ return this.contract.impureCircuits.hasGovernorPermission(this.circuitContext, userId, permission).result;
685
+ }
686
+
687
+ public async setSystemTimestamp(newTimestamp: bigint) {
688
+ const result = this.contract.impureCircuits.setSystemTimestamp(this.circuitContext, newTimestamp);
689
+ return this.updateStateAndGetLedger(result);
690
+ }
691
+
692
+ public async setGovernorPermissionSecure(userId: Uint8Array, permission: number) {
693
+ const proof = {
694
+ proposalId: 0n,
695
+ effectId: 0n,
696
+ approvalTime: BigInt(Math.floor(Date.now() / 1000)),
697
+ nonce: new Uint8Array(32),
698
+ };
699
+ const result = this.contract.impureCircuits.setGovernorPermissionSecure(this.circuitContext, userId, permission, proof);
700
+ return this.updateStateAndGetLedger(result);
701
+ }
702
+
703
+ }