@dorafactory/maci-sdk 0.0.21 → 0.0.23
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/dist/browser.d.mts +52 -23
- package/dist/browser.d.ts +52 -23
- package/dist/browser.js +42 -50
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +42 -50
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +52 -23
- package/dist/index.d.ts +52 -23
- package/dist/index.js +42 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/libs/contract/ts/AMaci.client.ts +40 -100
- package/src/libs/contract/ts/AMaci.types.ts +39 -21
- package/src/libs/maci/maci.ts +27 -0
package/package.json
CHANGED
|
@@ -20,17 +20,22 @@ import {
|
|
|
20
20
|
MaciParameters,
|
|
21
21
|
RoundInfo,
|
|
22
22
|
VotingTime,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
WhitelistBase,
|
|
24
|
+
WhitelistBaseConfig,
|
|
25
25
|
ExecuteMsg,
|
|
26
|
-
Uint128,
|
|
27
26
|
MessageData,
|
|
28
27
|
Groth16ProofType,
|
|
29
28
|
QueryMsg,
|
|
29
|
+
Boolean,
|
|
30
|
+
DelayType,
|
|
31
|
+
DelayRecords,
|
|
32
|
+
DelayRecord,
|
|
30
33
|
PeriodStatus,
|
|
31
34
|
Period,
|
|
32
|
-
|
|
35
|
+
Uint128,
|
|
33
36
|
ArrayOfString,
|
|
37
|
+
Whitelist,
|
|
38
|
+
WhitelistConfig,
|
|
34
39
|
} from './AMaci.types';
|
|
35
40
|
export interface AMaciReadOnlyInterface {
|
|
36
41
|
contractAddress: string;
|
|
@@ -51,7 +56,9 @@ export interface AMaciReadOnlyInterface {
|
|
|
51
56
|
getVoiceCreditBalance: ({ index }: { index: Uint256 }) => Promise<Uint256>;
|
|
52
57
|
getVoiceCreditAmount: () => Promise<Uint256>;
|
|
53
58
|
whiteList: () => Promise<Whitelist>;
|
|
59
|
+
canSignUp: ({ sender }: { sender: Addr }) => Promise<Boolean>;
|
|
54
60
|
isWhiteList: ({ sender }: { sender: Addr }) => Promise<Boolean>;
|
|
61
|
+
isRegister: ({ sender }: { sender: Addr }) => Promise<Boolean>;
|
|
55
62
|
signuped: ({ pubkeyX }: { pubkeyX: Uint256 }) => Promise<Uint256>;
|
|
56
63
|
voteOptionMap: () => Promise<ArrayOfString>;
|
|
57
64
|
maxVoteOptions: () => Promise<Uint256>;
|
|
@@ -59,6 +66,7 @@ export interface AMaciReadOnlyInterface {
|
|
|
59
66
|
queryCircuitType: () => Promise<Uint256>;
|
|
60
67
|
queryCertSystem: () => Promise<Uint256>;
|
|
61
68
|
queryPreDeactivateRoot: () => Promise<Uint256>;
|
|
69
|
+
getDelayRecords: () => Promise<DelayRecords>;
|
|
62
70
|
}
|
|
63
71
|
export class AMaciQueryClient implements AMaciReadOnlyInterface {
|
|
64
72
|
client: CosmWasmClient;
|
|
@@ -83,7 +91,9 @@ export class AMaciQueryClient implements AMaciReadOnlyInterface {
|
|
|
83
91
|
this.getVoiceCreditBalance = this.getVoiceCreditBalance.bind(this);
|
|
84
92
|
this.getVoiceCreditAmount = this.getVoiceCreditAmount.bind(this);
|
|
85
93
|
this.whiteList = this.whiteList.bind(this);
|
|
94
|
+
this.canSignUp = this.canSignUp.bind(this);
|
|
86
95
|
this.isWhiteList = this.isWhiteList.bind(this);
|
|
96
|
+
this.isRegister = this.isRegister.bind(this);
|
|
87
97
|
this.signuped = this.signuped.bind(this);
|
|
88
98
|
this.voteOptionMap = this.voteOptionMap.bind(this);
|
|
89
99
|
this.maxVoteOptions = this.maxVoteOptions.bind(this);
|
|
@@ -91,6 +101,7 @@ export class AMaciQueryClient implements AMaciReadOnlyInterface {
|
|
|
91
101
|
this.queryCircuitType = this.queryCircuitType.bind(this);
|
|
92
102
|
this.queryCertSystem = this.queryCertSystem.bind(this);
|
|
93
103
|
this.queryPreDeactivateRoot = this.queryPreDeactivateRoot.bind(this);
|
|
104
|
+
this.getDelayRecords = this.getDelayRecords.bind(this);
|
|
94
105
|
}
|
|
95
106
|
admin = async (): Promise<Addr> => {
|
|
96
107
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
@@ -187,6 +198,13 @@ export class AMaciQueryClient implements AMaciReadOnlyInterface {
|
|
|
187
198
|
white_list: {},
|
|
188
199
|
});
|
|
189
200
|
};
|
|
201
|
+
canSignUp = async ({ sender }: { sender: Addr }): Promise<Boolean> => {
|
|
202
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
203
|
+
can_sign_up: {
|
|
204
|
+
sender,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
};
|
|
190
208
|
isWhiteList = async ({ sender }: { sender: Addr }): Promise<Boolean> => {
|
|
191
209
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
192
210
|
is_white_list: {
|
|
@@ -194,6 +212,13 @@ export class AMaciQueryClient implements AMaciReadOnlyInterface {
|
|
|
194
212
|
},
|
|
195
213
|
});
|
|
196
214
|
};
|
|
215
|
+
isRegister = async ({ sender }: { sender: Addr }): Promise<Boolean> => {
|
|
216
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
217
|
+
is_register: {
|
|
218
|
+
sender,
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
};
|
|
197
222
|
signuped = async ({ pubkeyX }: { pubkeyX: Uint256 }): Promise<Uint256> => {
|
|
198
223
|
return this.client.queryContractSmart(this.contractAddress, {
|
|
199
224
|
signuped: {
|
|
@@ -231,6 +256,11 @@ export class AMaciQueryClient implements AMaciReadOnlyInterface {
|
|
|
231
256
|
query_pre_deactivate_root: {},
|
|
232
257
|
});
|
|
233
258
|
};
|
|
259
|
+
getDelayRecords = async (): Promise<DelayRecords> => {
|
|
260
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
261
|
+
get_delay_records: {},
|
|
262
|
+
});
|
|
263
|
+
};
|
|
234
264
|
}
|
|
235
265
|
export interface AMaciInterface extends AMaciReadOnlyInterface {
|
|
236
266
|
contractAddress: string;
|
|
@@ -249,7 +279,7 @@ export interface AMaciInterface extends AMaciReadOnlyInterface {
|
|
|
249
279
|
{
|
|
250
280
|
whitelists,
|
|
251
281
|
}: {
|
|
252
|
-
whitelists:
|
|
282
|
+
whitelists: WhitelistBase;
|
|
253
283
|
},
|
|
254
284
|
fee?: number | StdFee | 'auto',
|
|
255
285
|
memo?: string,
|
|
@@ -393,32 +423,7 @@ export interface AMaciInterface extends AMaciReadOnlyInterface {
|
|
|
393
423
|
memo?: string,
|
|
394
424
|
_funds?: Coin[]
|
|
395
425
|
) => Promise<ExecuteResult>;
|
|
396
|
-
|
|
397
|
-
{
|
|
398
|
-
maxAmount,
|
|
399
|
-
}: {
|
|
400
|
-
maxAmount: Uint128;
|
|
401
|
-
},
|
|
402
|
-
fee?: number | StdFee | 'auto',
|
|
403
|
-
memo?: string,
|
|
404
|
-
_funds?: Coin[]
|
|
405
|
-
) => Promise<ExecuteResult>;
|
|
406
|
-
revoke: (
|
|
407
|
-
fee?: number | StdFee | 'auto',
|
|
408
|
-
memo?: string,
|
|
409
|
-
_funds?: Coin[]
|
|
410
|
-
) => Promise<ExecuteResult>;
|
|
411
|
-
bond: (
|
|
412
|
-
fee?: number | StdFee | 'auto',
|
|
413
|
-
memo?: string,
|
|
414
|
-
_funds?: Coin[]
|
|
415
|
-
) => Promise<ExecuteResult>;
|
|
416
|
-
withdraw: (
|
|
417
|
-
{
|
|
418
|
-
amount,
|
|
419
|
-
}: {
|
|
420
|
-
amount?: Uint128;
|
|
421
|
-
},
|
|
426
|
+
claim: (
|
|
422
427
|
fee?: number | StdFee | 'auto',
|
|
423
428
|
memo?: string,
|
|
424
429
|
_funds?: Coin[]
|
|
@@ -451,10 +456,7 @@ export class AMaciClient extends AMaciQueryClient implements AMaciInterface {
|
|
|
451
456
|
this.stopProcessingPeriod = this.stopProcessingPeriod.bind(this);
|
|
452
457
|
this.processTally = this.processTally.bind(this);
|
|
453
458
|
this.stopTallyingPeriod = this.stopTallyingPeriod.bind(this);
|
|
454
|
-
this.
|
|
455
|
-
this.revoke = this.revoke.bind(this);
|
|
456
|
-
this.bond = this.bond.bind(this);
|
|
457
|
-
this.withdraw = this.withdraw.bind(this);
|
|
459
|
+
this.claim = this.claim.bind(this);
|
|
458
460
|
}
|
|
459
461
|
setRoundInfo = async (
|
|
460
462
|
{
|
|
@@ -483,7 +485,7 @@ export class AMaciClient extends AMaciQueryClient implements AMaciInterface {
|
|
|
483
485
|
{
|
|
484
486
|
whitelists,
|
|
485
487
|
}: {
|
|
486
|
-
whitelists:
|
|
488
|
+
whitelists: WhitelistBase;
|
|
487
489
|
},
|
|
488
490
|
fee: number | StdFee | 'auto' = 'auto',
|
|
489
491
|
memo?: string,
|
|
@@ -806,12 +808,7 @@ export class AMaciClient extends AMaciQueryClient implements AMaciInterface {
|
|
|
806
808
|
_funds
|
|
807
809
|
);
|
|
808
810
|
};
|
|
809
|
-
|
|
810
|
-
{
|
|
811
|
-
maxAmount,
|
|
812
|
-
}: {
|
|
813
|
-
maxAmount: Uint128;
|
|
814
|
-
},
|
|
811
|
+
claim = async (
|
|
815
812
|
fee: number | StdFee | 'auto' = 'auto',
|
|
816
813
|
memo?: string,
|
|
817
814
|
_funds?: Coin[]
|
|
@@ -820,64 +817,7 @@ export class AMaciClient extends AMaciQueryClient implements AMaciInterface {
|
|
|
820
817
|
this.sender,
|
|
821
818
|
this.contractAddress,
|
|
822
819
|
{
|
|
823
|
-
|
|
824
|
-
max_amount: maxAmount,
|
|
825
|
-
},
|
|
826
|
-
},
|
|
827
|
-
fee,
|
|
828
|
-
memo,
|
|
829
|
-
_funds
|
|
830
|
-
);
|
|
831
|
-
};
|
|
832
|
-
revoke = async (
|
|
833
|
-
fee: number | StdFee | 'auto' = 'auto',
|
|
834
|
-
memo?: string,
|
|
835
|
-
_funds?: Coin[]
|
|
836
|
-
): Promise<ExecuteResult> => {
|
|
837
|
-
return await this.client.execute(
|
|
838
|
-
this.sender,
|
|
839
|
-
this.contractAddress,
|
|
840
|
-
{
|
|
841
|
-
revoke: {},
|
|
842
|
-
},
|
|
843
|
-
fee,
|
|
844
|
-
memo,
|
|
845
|
-
_funds
|
|
846
|
-
);
|
|
847
|
-
};
|
|
848
|
-
bond = async (
|
|
849
|
-
fee: number | StdFee | 'auto' = 'auto',
|
|
850
|
-
memo?: string,
|
|
851
|
-
_funds?: Coin[]
|
|
852
|
-
): Promise<ExecuteResult> => {
|
|
853
|
-
return await this.client.execute(
|
|
854
|
-
this.sender,
|
|
855
|
-
this.contractAddress,
|
|
856
|
-
{
|
|
857
|
-
bond: {},
|
|
858
|
-
},
|
|
859
|
-
fee,
|
|
860
|
-
memo,
|
|
861
|
-
_funds
|
|
862
|
-
);
|
|
863
|
-
};
|
|
864
|
-
withdraw = async (
|
|
865
|
-
{
|
|
866
|
-
amount,
|
|
867
|
-
}: {
|
|
868
|
-
amount?: Uint128;
|
|
869
|
-
},
|
|
870
|
-
fee: number | StdFee | 'auto' = 'auto',
|
|
871
|
-
memo?: string,
|
|
872
|
-
_funds?: Coin[]
|
|
873
|
-
): Promise<ExecuteResult> => {
|
|
874
|
-
return await this.client.execute(
|
|
875
|
-
this.sender,
|
|
876
|
-
this.contractAddress,
|
|
877
|
-
{
|
|
878
|
-
withdraw: {
|
|
879
|
-
amount,
|
|
880
|
-
},
|
|
820
|
+
claim: {},
|
|
881
821
|
},
|
|
882
822
|
fee,
|
|
883
823
|
memo,
|
|
@@ -20,7 +20,7 @@ export interface InstantiateMsg {
|
|
|
20
20
|
round_info: RoundInfo;
|
|
21
21
|
voice_credit_amount: Uint256;
|
|
22
22
|
voting_time: VotingTime;
|
|
23
|
-
whitelist?:
|
|
23
|
+
whitelist?: WhitelistBase | null;
|
|
24
24
|
}
|
|
25
25
|
export interface PubKey {
|
|
26
26
|
x: Uint256;
|
|
@@ -41,10 +41,10 @@ export interface VotingTime {
|
|
|
41
41
|
end_time: Timestamp;
|
|
42
42
|
start_time: Timestamp;
|
|
43
43
|
}
|
|
44
|
-
export interface
|
|
45
|
-
users:
|
|
44
|
+
export interface WhitelistBase {
|
|
45
|
+
users: WhitelistBaseConfig[];
|
|
46
46
|
}
|
|
47
|
-
export interface
|
|
47
|
+
export interface WhitelistBaseConfig {
|
|
48
48
|
addr: Addr;
|
|
49
49
|
}
|
|
50
50
|
export type ExecuteMsg =
|
|
@@ -55,7 +55,7 @@ export type ExecuteMsg =
|
|
|
55
55
|
}
|
|
56
56
|
| {
|
|
57
57
|
set_whitelists: {
|
|
58
|
-
whitelists:
|
|
58
|
+
whitelists: WhitelistBase;
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
| {
|
|
@@ -129,22 +129,8 @@ export type ExecuteMsg =
|
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
| {
|
|
132
|
-
|
|
133
|
-
max_amount: Uint128;
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
| {
|
|
137
|
-
revoke: {};
|
|
138
|
-
}
|
|
139
|
-
| {
|
|
140
|
-
bond: {};
|
|
141
|
-
}
|
|
142
|
-
| {
|
|
143
|
-
withdraw: {
|
|
144
|
-
amount?: Uint128 | null;
|
|
145
|
-
};
|
|
132
|
+
claim: {};
|
|
146
133
|
};
|
|
147
|
-
export type Uint128 = string;
|
|
148
134
|
export interface MessageData {
|
|
149
135
|
data: [Uint256, Uint256, Uint256, Uint256, Uint256, Uint256, Uint256];
|
|
150
136
|
}
|
|
@@ -211,11 +197,21 @@ export type QueryMsg =
|
|
|
211
197
|
| {
|
|
212
198
|
white_list: {};
|
|
213
199
|
}
|
|
200
|
+
| {
|
|
201
|
+
can_sign_up: {
|
|
202
|
+
sender: Addr;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
214
205
|
| {
|
|
215
206
|
is_white_list: {
|
|
216
207
|
sender: Addr;
|
|
217
208
|
};
|
|
218
209
|
}
|
|
210
|
+
| {
|
|
211
|
+
is_register: {
|
|
212
|
+
sender: Addr;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
219
215
|
| {
|
|
220
216
|
signuped: {
|
|
221
217
|
pubkey_x: Uint256;
|
|
@@ -238,7 +234,22 @@ export type QueryMsg =
|
|
|
238
234
|
}
|
|
239
235
|
| {
|
|
240
236
|
query_pre_deactivate_root: {};
|
|
237
|
+
}
|
|
238
|
+
| {
|
|
239
|
+
get_delay_records: {};
|
|
241
240
|
};
|
|
241
|
+
export type Boolean = boolean;
|
|
242
|
+
export type DelayType = 'deactivate_delay' | 'tally_delay';
|
|
243
|
+
export interface DelayRecords {
|
|
244
|
+
records: DelayRecord[];
|
|
245
|
+
}
|
|
246
|
+
export interface DelayRecord {
|
|
247
|
+
delay_duration: number;
|
|
248
|
+
delay_process_dmsg_count: Uint256;
|
|
249
|
+
delay_reason: string;
|
|
250
|
+
delay_timestamp: Timestamp;
|
|
251
|
+
delay_type: DelayType;
|
|
252
|
+
}
|
|
242
253
|
export type PeriodStatus =
|
|
243
254
|
| 'pending'
|
|
244
255
|
| 'voting'
|
|
@@ -248,5 +259,12 @@ export type PeriodStatus =
|
|
|
248
259
|
export interface Period {
|
|
249
260
|
status: PeriodStatus;
|
|
250
261
|
}
|
|
251
|
-
export type
|
|
262
|
+
export type Uint128 = string;
|
|
252
263
|
export type ArrayOfString = string[];
|
|
264
|
+
export interface Whitelist {
|
|
265
|
+
users: WhitelistConfig[];
|
|
266
|
+
}
|
|
267
|
+
export interface WhitelistConfig {
|
|
268
|
+
addr: Addr;
|
|
269
|
+
is_register: boolean;
|
|
270
|
+
}
|
package/src/libs/maci/maci.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx.js';
|
|
|
18
18
|
import { CertificateEcosystem, ErrorResponse } from '../../types';
|
|
19
19
|
import { SignatureResponse } from '../oracle-certificate/types';
|
|
20
20
|
import { OracleWhitelistConfig } from '../contract/ts/OracleMaci.types';
|
|
21
|
+
import { getAMaciRoundCircuitFee } from '../contract/utils';
|
|
21
22
|
|
|
22
23
|
export function isErrorResponse(response: unknown): response is ErrorResponse {
|
|
23
24
|
return (
|
|
@@ -313,6 +314,17 @@ export class MACI {
|
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
|
|
317
|
+
async queryAMaciChargeFee({
|
|
318
|
+
maxVoter,
|
|
319
|
+
maxOption,
|
|
320
|
+
}: {
|
|
321
|
+
maxVoter: number;
|
|
322
|
+
maxOption: number;
|
|
323
|
+
}) {
|
|
324
|
+
const fee = getAMaciRoundCircuitFee(maxVoter, maxOption);
|
|
325
|
+
return fee;
|
|
326
|
+
}
|
|
327
|
+
|
|
316
328
|
async queryRoundGasStation({ contractAddress }: { contractAddress: string }) {
|
|
317
329
|
const roundInfo = await this.getRoundInfo({ contractAddress });
|
|
318
330
|
|
|
@@ -714,4 +726,19 @@ export class MACI {
|
|
|
714
726
|
fee
|
|
715
727
|
);
|
|
716
728
|
}
|
|
729
|
+
|
|
730
|
+
async claimAMaciRound({
|
|
731
|
+
signer,
|
|
732
|
+
contractAddress,
|
|
733
|
+
}: {
|
|
734
|
+
signer: OfflineSigner;
|
|
735
|
+
contractAddress: string;
|
|
736
|
+
}) {
|
|
737
|
+
const client = await this.contract.amaciClient({
|
|
738
|
+
signer,
|
|
739
|
+
contractAddress,
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
return client.claim();
|
|
743
|
+
}
|
|
717
744
|
}
|