@dorafactory/maci-sdk 0.0.30 → 0.0.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorafactory/maci-sdk",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "SDK for interacting with maci",
5
5
  "keywords": [
6
6
  "maci",
@@ -770,4 +770,116 @@ export class MACI {
770
770
  const ecosystems = await this.oracleCertificate.listEcosystems();
771
771
  return ecosystems;
772
772
  }
773
+
774
+ /**
775
+ * Batch grant with bond (for maci)
776
+ * @param client
777
+ * @param contractAddress
778
+ * @param address
779
+ * @param amount
780
+ * @returns
781
+ */
782
+ async batchGrantWithBond(
783
+ client: SigningCosmWasmClient,
784
+ contractAddress: string,
785
+ address: string,
786
+ amount: string
787
+ ) {
788
+ const msgs: MsgExecuteContractEncodeObject[] = [
789
+ {
790
+ typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
791
+ value: MsgExecuteContract.fromPartial({
792
+ sender: address,
793
+ contract: contractAddress,
794
+ msg: new TextEncoder().encode(
795
+ JSON.stringify(
796
+ stringizing({
797
+ grant: {
798
+ max_amount: BigInt('100000000000000000000000'),
799
+ },
800
+ })
801
+ )
802
+ ),
803
+ }),
804
+ },
805
+ {
806
+ typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
807
+ value: MsgExecuteContract.fromPartial({
808
+ sender: address,
809
+ contract: contractAddress,
810
+ msg: new TextEncoder().encode(
811
+ JSON.stringify(
812
+ stringizing({
813
+ bond: {},
814
+ })
815
+ )
816
+ ),
817
+ funds: [
818
+ {
819
+ denom: 'peaka',
820
+ amount,
821
+ },
822
+ ],
823
+ }),
824
+ },
825
+ ];
826
+
827
+ try {
828
+ const result = await client.signAndBroadcast(address, msgs, 'auto');
829
+ return result;
830
+ } catch (err) {
831
+ throw err;
832
+ }
833
+ }
834
+
835
+ /**
836
+ * Batch revoke with withdraw (for maci)
837
+ * @param client
838
+ * @param contractAddress
839
+ * @param address
840
+ * @returns
841
+ */
842
+ async batchRevokeWithdraw(
843
+ client: SigningCosmWasmClient,
844
+ contractAddress: string,
845
+ address: string
846
+ ) {
847
+ const msgs: MsgExecuteContractEncodeObject[] = [
848
+ {
849
+ typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
850
+ value: MsgExecuteContract.fromPartial({
851
+ sender: address,
852
+ contract: contractAddress,
853
+ msg: new TextEncoder().encode(
854
+ JSON.stringify(
855
+ stringizing({
856
+ withdraw: {},
857
+ })
858
+ )
859
+ ),
860
+ }),
861
+ },
862
+ {
863
+ typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
864
+ value: MsgExecuteContract.fromPartial({
865
+ sender: address,
866
+ contract: contractAddress,
867
+ msg: new TextEncoder().encode(
868
+ JSON.stringify(
869
+ stringizing({
870
+ revoke: {},
871
+ })
872
+ )
873
+ ),
874
+ }),
875
+ },
876
+ ];
877
+
878
+ try {
879
+ const result = await client.signAndBroadcast(address, msgs, 'auto');
880
+ return result;
881
+ } catch (err) {
882
+ throw err;
883
+ }
884
+ }
773
885
  }
package/src/maci.ts CHANGED
@@ -11,6 +11,9 @@ import {
11
11
  CircuitsResponse,
12
12
  ProofResponse,
13
13
  SelectiveRoundResponse,
14
+ CertificateEcosystem,
15
+ ErrorResponse,
16
+ RoundType,
14
17
  } from './types';
15
18
  import {
16
19
  Http,
@@ -27,6 +30,11 @@ import {
27
30
  CreateOracleMaciRoundParams,
28
31
  } from './libs/contract/types';
29
32
  import { OfflineSigner } from '@cosmjs/proto-signing';
33
+ import { Account, PublicKey } from './libs/circom';
34
+ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
35
+ import { OracleWhitelistConfig } from './libs/contract/ts/OracleMaci.types';
36
+ import { SignatureResponse } from './libs/oracle-certificate/types';
37
+ import { StdFee } from '@cosmjs/stargate';
30
38
 
31
39
  /**
32
40
  * @class MaciClient
@@ -172,193 +180,332 @@ export class MaciClient {
172
180
  return await this.contract.createOracleMaciRound(params);
173
181
  }
174
182
 
175
- /**
176
- * @method balanceOf
177
- * @description Get the balance of a specific address.
178
- * @param {string} address - The address to check the balance for.
179
- * @returns {Promise<BalanceResponse>} The balance response.
180
- */
181
- async balanceOf(address: string): Promise<BalanceResponse> {
182
- return await this.indexer.account.balanceOf(address);
183
+ async getStateIdxInc({
184
+ signer,
185
+ address,
186
+ contractAddress,
187
+ }: {
188
+ signer: OfflineSigner;
189
+ address: string;
190
+ contractAddress: string;
191
+ }) {
192
+ return await this.maci.getStateIdxInc({
193
+ signer,
194
+ address,
195
+ contractAddress,
196
+ });
183
197
  }
184
198
 
185
- /**
186
- * @method getRoundById
187
- * @description Get a round by its ID.
188
- * @param {string} id - The ID of the round.
189
- * @returns {Promise<RoundResponse>} The round response.
190
- */
191
- async getRoundById(id: string): Promise<RoundResponse> {
192
- return await this.indexer.round.getRoundById(id);
199
+ async getVoiceCreditBalance({
200
+ signer,
201
+ stateIdx,
202
+ contractAddress,
203
+ }: {
204
+ signer: OfflineSigner;
205
+ stateIdx: number;
206
+ contractAddress: string;
207
+ }) {
208
+ return await this.maci.getVoiceCreditBalance({
209
+ signer,
210
+ stateIdx,
211
+ contractAddress,
212
+ });
193
213
  }
194
214
 
195
- /**
196
- * @method getRoundWithFields
197
- * @description Get a round by its address with selective fields.
198
- * @param {string} address - The address of the round.
199
- * @param {string[]} [fields] - The fields to retrieve.
200
- * @returns {Promise<SelectiveRoundResponse>} The round response.
201
- */
202
- async getRoundWithFields(
203
- address: string,
204
- fields?: string[]
205
- ): Promise<SelectiveRoundResponse> {
206
- return await this.indexer.round.getRoundWithFields(address, fields);
215
+ async getStateIdxByPubKey({
216
+ contractAddress,
217
+ pubKey,
218
+ }: {
219
+ contractAddress: string;
220
+ pubKey: bigint[];
221
+ }) {
222
+ return await this.maci.getStateIdxByPubKey({
223
+ contractAddress,
224
+ pubKey,
225
+ });
207
226
  }
208
227
 
209
- /**
210
- * @method getRounds
211
- * @description Get multiple rounds.
212
- * @param {string} after - The cursor to start after.
213
- * @param {number} [limit] - The number of rounds to retrieve.
214
- * @returns {Promise<RoundsResponse>} The rounds response.
215
- */
216
- async getRounds(after: string, limit?: number): Promise<RoundsResponse> {
217
- return await this.indexer.round.getRounds(after, limit);
228
+ async feegrantAllowance({
229
+ address,
230
+ contractAddress,
231
+ }: {
232
+ address: string;
233
+ contractAddress: string;
234
+ }) {
235
+ return await this.maci.feegrantAllowance({
236
+ address,
237
+ contractAddress,
238
+ });
218
239
  }
219
240
 
220
- /**
221
- * @method getRoundsByStatus
222
- * @description Get rounds by their status.
223
- * @param {string} status - The status of the rounds to retrieve.
224
- * @param {string} after - The cursor to start after.
225
- * @param {number} [limit] - The number of rounds to retrieve.
226
- * @returns {Promise<RoundsResponse>} The rounds response.
227
- */
228
- async getRoundsByStatus(
229
- status: string,
230
- after: string,
231
- limit?: number
232
- ): Promise<RoundsResponse> {
233
- return await this.indexer.round.getRoundsByStatus(status, after, limit);
241
+ async hasFeegrant({
242
+ address,
243
+ contractAddress,
244
+ }: {
245
+ address: string;
246
+ contractAddress: string;
247
+ }): Promise<boolean> {
248
+ return await this.maci.hasFeegrant({
249
+ address,
250
+ contractAddress,
251
+ });
234
252
  }
235
253
 
236
- /**
237
- * @method getRoundsByCircuitName
238
- * @description Get rounds by their circuit name.
239
- * @param {string} name - The name of the circuit.
240
- * @param {string} after - The cursor to start after.
241
- * @param {number} [limit] - The number of rounds to retrieve.
242
- * @returns {Promise<RoundsResponse>} The rounds response.
243
- */
244
- async getRoundsByCircuitName(
245
- name: string,
246
- after: string,
247
- limit?: number
248
- ): Promise<RoundsResponse> {
249
- return await this.indexer.round.getRoundsByCircuitName(name, after, limit);
254
+ async queryWhitelistBalanceOf({
255
+ signer,
256
+ address,
257
+ contractAddress,
258
+ certificate,
259
+ mode = 'maci',
260
+ }: {
261
+ signer: OfflineSigner;
262
+ address: string;
263
+ contractAddress: string;
264
+ certificate?: string;
265
+ mode?: 'maci' | 'amaci';
266
+ }): Promise<string> {
267
+ return await this.maci.queryWhitelistBalanceOf({
268
+ signer,
269
+ address,
270
+ contractAddress,
271
+ certificate,
272
+ mode,
273
+ });
250
274
  }
251
275
 
252
- /**
253
- * @method getRoundsByOperator
254
- * @description Get rounds by their operator address.
255
- * @param {string} address - The address of the operator.
256
- * @param {string} after - The cursor to start after.
257
- * @param {number} [limit] - The number of rounds to retrieve.
258
- * @returns {Promise<RoundsResponse>} The rounds response.
259
- */
260
- async getRoundsByOperator(
261
- address: string,
262
- after: string,
263
- limit?: number
264
- ): Promise<RoundsResponse> {
265
- return await this.indexer.round.getRoundsByOperator(address, after, limit);
276
+ async isWhitelisted({
277
+ signer,
278
+ address,
279
+ contractAddress,
280
+ }: {
281
+ signer: OfflineSigner;
282
+ address: string;
283
+ contractAddress: string;
284
+ }) {
285
+ return await this.maci.isWhitelisted({
286
+ signer,
287
+ address,
288
+ contractAddress,
289
+ });
266
290
  }
267
291
 
268
- /**
269
- * @method getOperatorByAddress
270
- * @description Get an operator by their address.
271
- * @param {string} address - The address of the operator.
272
- * @returns {Promise<OperatorResponse>} The operator response.
273
- */
274
- async getOperatorByAddress(address: string): Promise<OperatorResponse> {
275
- return await this.indexer.operator.getOperatorByAddress(address);
292
+ async getOracleWhitelistConfig({
293
+ signer,
294
+ contractAddress,
295
+ }: {
296
+ signer: OfflineSigner;
297
+ contractAddress: string;
298
+ }): Promise<OracleWhitelistConfig> {
299
+ return await this.maci.getOracleWhitelistConfig({
300
+ signer,
301
+ contractAddress,
302
+ });
276
303
  }
277
304
 
278
- /**
279
- * @method getOperators
280
- * @description Get multiple operators.
281
- * @param {string} after - The cursor to start after.
282
- * @param {number} [limit] - The number of operators to retrieve.
283
- * @returns {Promise<OperatorsResponse>} The operators response.
284
- */
285
- async getOperators(
286
- after: string,
287
- limit?: number
288
- ): Promise<OperatorsResponse> {
289
- return await this.indexer.operator.getOperators(after, limit);
305
+ async getRoundInfo({ contractAddress }: { contractAddress: string }) {
306
+ return await this.maci.getRoundInfo({ contractAddress });
290
307
  }
291
308
 
292
- /**
293
- * @method getCircuitByName
294
- * @description Get a circuit by its name.
295
- * @param {string} name - The name of the circuit.
296
- * @returns {Promise<CircuitResponse>} The circuit response.
297
- */
298
- async getCircuitByName(name: string): Promise<CircuitResponse> {
299
- return await this.indexer.circuit.getCircuitByName(name);
309
+ async getRoundCircuitType({ contractAddress }: { contractAddress: string }) {
310
+ return await this.maci.getRoundCircuitType({ contractAddress });
300
311
  }
301
312
 
302
- /**
303
- * @method getCircuits
304
- * @description Get all available circuits.
305
- * @returns {Promise<CircuitsResponse>} The circuits response.
306
- */
307
- async getCircuits(): Promise<CircuitsResponse> {
308
- return await this.indexer.circuit.getCircuits();
313
+ async queryRoundIsQv({ contractAddress }: { contractAddress: string }) {
314
+ return await this.maci.queryRoundIsQv({ contractAddress });
309
315
  }
310
316
 
311
- /**
312
- * @method getTransactionByHash
313
- * @description Get a transaction by its hash.
314
- * @param {string} hash - The hash of the transaction.
315
- * @returns {Promise<TransactionResponse>} The transaction response.
316
- */
317
- async getTransactionByHash(hash: string): Promise<TransactionResponse> {
318
- return await this.indexer.transaction.getTransactionByHash(hash);
317
+ async queryRoundClaimable({
318
+ contractAddress,
319
+ }: {
320
+ contractAddress: string;
321
+ }): Promise<{
322
+ claimable: boolean | null;
323
+ balance: string | null;
324
+ }> {
325
+ return await this.maci.queryRoundClaimable({ contractAddress });
319
326
  }
320
327
 
321
- /**
322
- * @method getTransactions
323
- * @description Get multiple transactions.
324
- * @param {string} after - The cursor to start after.
325
- * @param {number} [limit] - The number of transactions to retrieve.
326
- * @returns {Promise<TransactionsResponse>} The transactions response.
327
- */
328
- async getTransactions(
329
- after: string,
330
- limit?: number
331
- ): Promise<TransactionsResponse> {
332
- return await this.indexer.transaction.getTransactions(after, limit);
328
+ async queryAMaciChargeFee({
329
+ maxVoter,
330
+ maxOption,
331
+ }: {
332
+ maxVoter: number;
333
+ maxOption: number;
334
+ }) {
335
+ return await this.maci.queryAMaciChargeFee({
336
+ maxVoter,
337
+ maxOption,
338
+ });
333
339
  }
334
340
 
335
- /**
336
- * @method getTransactionsByContractAddress
337
- * @description Get transactions by contract address.
338
- * @param {string} address - The contract address.
339
- * @param {string} after - The cursor to start after.
340
- * @param {number} [limit] - The number of transactions to retrieve.
341
- * @returns {Promise<TransactionsResponse>} The transactions response.
342
- */
343
- async getTransactionsByContractAddress(
341
+ async queryRoundGasStation({ contractAddress }: { contractAddress: string }) {
342
+ return await this.maci.queryRoundGasStation({ contractAddress });
343
+ }
344
+
345
+ parseRoundStatus(
346
+ votingStart: number,
347
+ votingEnd: number,
348
+ status: string,
349
+ currentTime: Date
350
+ ): string {
351
+ return this.maci.parseRoundStatus(
352
+ votingStart,
353
+ votingEnd,
354
+ status,
355
+ currentTime
356
+ );
357
+ }
358
+
359
+ async queryRoundBalance({ contractAddress }: { contractAddress: string }) {
360
+ return await this.maci.queryRoundBalance({ contractAddress });
361
+ }
362
+
363
+ async requestOracleCertificate({
364
+ signer,
365
+ ecosystem,
366
+ address,
367
+ contractAddress,
368
+ }: {
369
+ signer: OfflineSigner;
370
+ ecosystem: CertificateEcosystem;
371
+ address: string;
372
+ contractAddress: string;
373
+ }): Promise<SignatureResponse> {
374
+ return await this.maci.requestOracleCertificate({
375
+ signer,
376
+ ecosystem,
377
+ address,
378
+ contractAddress,
379
+ });
380
+ }
381
+
382
+ async signup({
383
+ signer,
384
+ address,
385
+ contractAddress,
386
+ maciAccount,
387
+ oracleCertificate,
388
+ gasStation = false,
389
+ }: {
390
+ signer: OfflineSigner;
391
+ address: string;
392
+ contractAddress: string;
393
+ maciAccount?: Account;
394
+ oracleCertificate?: {
395
+ amount: string;
396
+ signature: string;
397
+ };
398
+ gasStation?: boolean;
399
+ }) {
400
+ return await this.maci.signup({
401
+ signer,
402
+ address,
403
+ contractAddress,
404
+ maciAccount,
405
+ oracleCertificate,
406
+ gasStation,
407
+ });
408
+ }
409
+
410
+ async vote({
411
+ signer,
412
+ address,
413
+ stateIdx,
414
+ contractAddress,
415
+ selectedOptions,
416
+ operatorCoordPubKey,
417
+ maciAccount,
418
+ gasStation = false,
419
+ }: {
420
+ signer: OfflineSigner;
421
+ address: string;
422
+ stateIdx: number;
423
+ contractAddress: string;
424
+ selectedOptions: {
425
+ idx: number;
426
+ vc: number;
427
+ }[];
428
+ operatorCoordPubKey: PublicKey;
429
+ maciAccount?: Account;
430
+ gasStation?: boolean;
431
+ }) {
432
+ return await this.maci.vote({
433
+ signer,
434
+ address,
435
+ stateIdx,
436
+ contractAddress,
437
+ selectedOptions,
438
+ operatorCoordPubKey,
439
+ maciAccount,
440
+ gasStation,
441
+ });
442
+ }
443
+
444
+ async publishMessage({
445
+ client,
446
+ address,
447
+ payload,
448
+ contractAddress,
449
+ gasStation,
450
+ }: {
451
+ client: SigningCosmWasmClient;
452
+ address: string;
453
+ payload: {
454
+ msg: bigint[];
455
+ encPubkeys: PublicKey;
456
+ }[];
457
+ contractAddress: string;
458
+ gasStation: boolean;
459
+ }) {
460
+ return await this.maci.publishMessage({
461
+ client,
462
+ address,
463
+ payload,
464
+ contractAddress,
465
+ gasStation,
466
+ });
467
+ }
468
+
469
+ async claimAMaciRound({
470
+ signer,
471
+ contractAddress,
472
+ }: {
473
+ signer: OfflineSigner;
474
+ contractAddress: string;
475
+ }) {
476
+ return await this.maci.claimAMaciRound({
477
+ signer,
478
+ contractAddress,
479
+ });
480
+ }
481
+
482
+ async getOracleCertificateConfig() {
483
+ return await this.maci.getOracleCertificateConfig();
484
+ }
485
+
486
+ async batchGrantWithBond(
487
+ client: SigningCosmWasmClient,
488
+ contractAddress: string,
344
489
  address: string,
345
- after: string,
346
- limit?: number
347
- ): Promise<TransactionsResponse> {
348
- return await this.indexer.transaction.getTransactionsByContractAddress(
490
+ amount: string
491
+ ) {
492
+ return await this.maci.batchGrantWithBond(
493
+ client,
494
+ contractAddress,
349
495
  address,
350
- after,
351
- limit
496
+ amount
352
497
  );
353
498
  }
354
499
 
355
- /**
356
- * @method getProofByContractAddress
357
- * @description Get proof data by contract address.
358
- * @param {string} address - The contract address.
359
- * @returns {Promise<ProofResponse>} The proof response.
360
- */
361
- async getProofByContractAddress(address: string): Promise<ProofResponse> {
362
- return await this.indexer.proof.getProofByContractAddress(address);
500
+ async batchRevokeWithdraw(
501
+ client: SigningCosmWasmClient,
502
+ contractAddress: string,
503
+ address: string
504
+ ) {
505
+ return await this.maci.batchRevokeWithdraw(
506
+ client,
507
+ contractAddress,
508
+ address
509
+ );
363
510
  }
364
511
  }