@dorafactory/maci-sdk 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -82,7 +82,7 @@ const proof = await client.getProofByContractAddress('dora1...');
82
82
 
83
83
  ### Contract Interactions
84
84
 
85
- #### Create New Voting Round
85
+ #### Create New Oracle Maci Round
86
86
  ```typescript
87
87
  const wallet = await DirectSecp256k1Wallet.fromKey(
88
88
  Buffer.from(privateKey, 'hex'),
@@ -93,14 +93,13 @@ const newRound = await client.createOracleMaciRound({
93
93
  signer: wallet,
94
94
  operatorPubkey: '0e752c...',
95
95
  startVoting: new Date(),
96
- endVoting: new Date(new Date().getTime() + 1 * 60 * 1000),
97
- title: 'test',
98
- description: 'test',
99
- link: 'test',
96
+ endVoting: new Date(new Date().getTime() + 10 * 60 * 1000),
97
+ title: 'Just for fun',
98
+ description: 'some description',
99
+ link: 'https://www.dorafactory.org',
100
100
  maxVoter: '5',
101
101
  maxOption: '5',
102
102
  circuitType: MaciCircuitType.IP1V,
103
- whitelistBackendPubkey: 'AoYo...',
104
103
  whitelistEcosystem: 'cosmoshub',
105
104
  whitelistSnapshotHeight: '0',
106
105
  whitelistVotingPowerArgs: {
@@ -108,6 +107,22 @@ const newRound = await client.createOracleMaciRound({
108
107
  slope: '1000000',
109
108
  threshold: '1000000',
110
109
  },
111
- feegrantOperator: 'dora1...',
112
110
  });
113
111
  ```
112
+
113
+ **Note:**
114
+ - The `operatorPubkey` is the public key of the operator. It is the compressed public key of the operator's private key.
115
+ - The `whitelistEcosystem` is the ecosystem of the whitelist (e.g. 'cosmoshub'). Only wallet addresses that have staked tokens in the specified ecosystem before the snapshot block height will be eligible to become voters.
116
+ - The `whitelistSnapshotHeight` is the snapshot block height for checking voter eligibility. The minimum valid height is 23,342,001. If set to "0", the round will evaluate the voter's stake at the time of signup.
117
+ - The `whitelistVotingPowerArgs` configures how voting power is calculated:
118
+ - `mode`: Can be either 'slope' or 'threshold'
119
+ - 'slope' mode: Calculates voice credits based on each voter's stake amount using the formula: voice credits = staked tokens / slope value
120
+ - 'threshold' mode: Equally assigns 1 voice credit to voters whose stake exceeds the specified threshold
121
+ - `slope`: The slope value for calculating voice credits in slope mode (e.g. 1000000)
122
+ - `threshold`: The minimum stake threshold in threshold mode (e.g. 1000000)
123
+
124
+ For example, if a voter stakes 100000000 tokens and the slope value is 2500000, the voter will be assigned 40 voice credits.
125
+
126
+ > The 1,000,000 reference value here is the precision of cosmoshub, which is 6 bits, and doravota, which is 18 bits, so when you want to pick doravota's staker as a whitelist and ask them to pledge 1DORA to convert 1vote, you need to set the scope to 1000000000000000000 (10**18). Note that currently only cosmoshub and doravota are supported as ecosystem options.
127
+ >
128
+ > One detail, here the slope is calculated by rounding down.
package/dist/index.js CHANGED
@@ -3566,7 +3566,23 @@ var CIRCUIT_INFO = {
3566
3566
  vote_option_tree_depth: "3"
3567
3567
  },
3568
3568
  groth16: {
3569
- process_vkey: {
3569
+ process_1p1v_vkey: {
3570
+ vk_alpha1: "2d4d9aa7e302d9df41749d5507949d05dbea33fbb16c643b22f599a2be6df2e214bedd503c37ceb061d8ec60209fe345ce89830a19230301f076caff004d1926",
3571
+ vk_beta_2: "0967032fcbf776d1afc985f88877f182d38480a653f2decaa9794cbc3bf3060c0e187847ad4c798374d0d6732bf501847dd68bc0e071241e0213bc7fc13db7ab304cfbd1e08a704a99f5e847d93f8c3caafddec46b7a0d379da69a4d112346a71739c1b1a457a8c7313123d24d2f9192f896b7c63eea05a9d57f06547ad0cec8",
3572
+ vk_gamma_2: "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa",
3573
+ vk_delta_2: "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa",
3574
+ vk_ic0: "1195be678487bbc8c0ae726c0985a5caf6f75e3f8327926926c4f89e498ad733043e46e10b506d194b27275f402bc3fb208a2f5be69662e7c9898d1c0ece4f04",
3575
+ vk_ic1: "10c34362189a7ee44b1c5e57755d7e0d672dba552e614d5cd9a53081bee2333425879fa4e4a9e3fff287824cce35f94725ca0edb60a4ffcbf50becb2fd96cb0b"
3576
+ },
3577
+ tally_1p1v_vkey: {
3578
+ vk_alpha1: "2d4d9aa7e302d9df41749d5507949d05dbea33fbb16c643b22f599a2be6df2e214bedd503c37ceb061d8ec60209fe345ce89830a19230301f076caff004d1926",
3579
+ vk_beta_2: "0967032fcbf776d1afc985f88877f182d38480a653f2decaa9794cbc3bf3060c0e187847ad4c798374d0d6732bf501847dd68bc0e071241e0213bc7fc13db7ab304cfbd1e08a704a99f5e847d93f8c3caafddec46b7a0d379da69a4d112346a71739c1b1a457a8c7313123d24d2f9192f896b7c63eea05a9d57f06547ad0cec8",
3580
+ vk_gamma_2: "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa",
3581
+ vk_delta_2: "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa",
3582
+ vk_ic0: "2ec191d51bd4ac7cd65cb3dd2decfa4e56c4f167bbc40e2c9e1ca728f9bc5b0e2ed1c82319dc554aea5ff2ca05d6f4d4d61e8f059a8c05d4b4faabae5128a437",
3583
+ vk_ic1: "2f19db8f03b6b5896abc6989273371b14833356f45c12685e57bc292eccc53570cb629e551df179f73b9f3391946bad29739af8b808c80b0f057af45aea59849"
3584
+ },
3585
+ process_qv_vkey: {
3570
3586
  vk_alpha1: "2d4d9aa7e302d9df41749d5507949d05dbea33fbb16c643b22f599a2be6df2e214bedd503c37ceb061d8ec60209fe345ce89830a19230301f076caff004d1926",
3571
3587
  vk_beta_2: "0967032fcbf776d1afc985f88877f182d38480a653f2decaa9794cbc3bf3060c0e187847ad4c798374d0d6732bf501847dd68bc0e071241e0213bc7fc13db7ab304cfbd1e08a704a99f5e847d93f8c3caafddec46b7a0d379da69a4d112346a71739c1b1a457a8c7313123d24d2f9192f896b7c63eea05a9d57f06547ad0cec8",
3572
3588
  vk_gamma_2: "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa",
@@ -3574,7 +3590,7 @@ var CIRCUIT_INFO = {
3574
3590
  vk_ic0: "1832600210a459fe61d971081d4baa1a1add23f87c8a8dc4042cd5cf6c6fdf8e3018489aec30d9deb26629e05965a3a7e038be58ce10c854cb7e1071f2708aad",
3575
3591
  vk_ic1: "0274a24117a799333754d646e35f37292e7ca9984fb8781211504b158d69d2c422aa99651ca207c77084988b16ef363664b9cf36071f7131dcc10b98ea27d7f6"
3576
3592
  },
3577
- tally_vkey: {
3593
+ tally_qv_vkey: {
3578
3594
  vk_alpha1: "2d4d9aa7e302d9df41749d5507949d05dbea33fbb16c643b22f599a2be6df2e214bedd503c37ceb061d8ec60209fe345ce89830a19230301f076caff004d1926",
3579
3595
  vk_beta_2: "0967032fcbf776d1afc985f88877f182d38480a653f2decaa9794cbc3bf3060c0e187847ad4c798374d0d6732bf501847dd68bc0e071241e0213bc7fc13db7ab304cfbd1e08a704a99f5e847d93f8c3caafddec46b7a0d379da69a4d112346a71739c1b1a457a8c7313123d24d2f9192f896b7c63eea05a9d57f06547ad0cec8",
3580
3596
  vk_gamma_2: "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa",
@@ -3662,8 +3678,13 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
3662
3678
  } else if (Number(maxVoter) <= 1953125 && Number(maxOption) <= 125) {
3663
3679
  parameters = CIRCUIT_INFO["9-4-3-625"].parameter;
3664
3680
  if (proofSystem === "groth16" /* GROTH16 */) {
3665
- groth16ProcessVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].process_vkey;
3666
- groth16TallyVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].tally_vkey;
3681
+ if (circuitType === "0" /* IP1V */) {
3682
+ groth16ProcessVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].process_1p1v_vkey;
3683
+ groth16TallyVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].tally_1p1v_vkey;
3684
+ } else if (circuitType === "1" /* QV */) {
3685
+ groth16ProcessVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].process_qv_vkey;
3686
+ groth16TallyVkey = CIRCUIT_INFO["9-4-3-625"]["groth16"].tally_qv_vkey;
3687
+ }
3667
3688
  } else if (proofSystem === "plonk" /* PLONK */) {
3668
3689
  throw new Error("PLONK is not supported for MACI-9");
3669
3690
  }
@@ -3708,12 +3729,16 @@ var Contract = class {
3708
3729
  rpcEndpoint,
3709
3730
  registryAddress,
3710
3731
  maciCodeId,
3711
- oracleCodeId
3732
+ oracleCodeId,
3733
+ feegrantOperator,
3734
+ whitelistBackendPubkey
3712
3735
  }) {
3713
3736
  this.rpcEndpoint = rpcEndpoint;
3714
3737
  this.registryAddress = registryAddress;
3715
3738
  this.maciCodeId = maciCodeId;
3716
3739
  this.oracleCodeId = oracleCodeId;
3740
+ this.feegrantOperator = feegrantOperator;
3741
+ this.whitelistBackendPubkey = whitelistBackendPubkey;
3717
3742
  }
3718
3743
  async createAMaciRound({
3719
3744
  signer,
@@ -3845,11 +3870,9 @@ var Contract = class {
3845
3870
  maxVoter,
3846
3871
  maxOption,
3847
3872
  circuitType,
3848
- whitelistBackendPubkey,
3849
3873
  whitelistEcosystem,
3850
3874
  whitelistSnapshotHeight,
3851
- whitelistVotingPowerArgs,
3852
- feegrantOperator
3875
+ whitelistVotingPowerArgs
3853
3876
  }) {
3854
3877
  const start_time = (startVoting.getTime() * 1e6).toString();
3855
3878
  const end_time = (endVoting.getTime() * 1e6).toString();
@@ -3890,14 +3913,14 @@ var Contract = class {
3890
3913
  plonk_process_vkey: plonkProcessVkey,
3891
3914
  plonk_tally_vkey: plonkTallyVkey,
3892
3915
  max_vote_options: maxOption,
3893
- whitelist_backend_pubkey: whitelistBackendPubkey,
3916
+ whitelist_backend_pubkey: this.whitelistBackendPubkey,
3894
3917
  whitelist_ecosystem: whitelistEcosystem,
3895
3918
  whitelist_snapshot_height: whitelistSnapshotHeight,
3896
3919
  whitelist_voting_power_args: whitelistVotingPowerArgs,
3897
3920
  circuit_type: maciVoteType,
3898
3921
  certification_system: maciCertSystem,
3899
3922
  qtr_lib: QTR_LIB,
3900
- feegrant_operator: feegrantOperator
3923
+ feegrant_operator: this.feegrantOperator
3901
3924
  },
3902
3925
  "[Oracle MACI]" + title,
3903
3926
  "auto"
@@ -3974,7 +3997,9 @@ var MaciClient2 = class {
3974
3997
  maciCodeId,
3975
3998
  oracleCodeId,
3976
3999
  customFetch,
3977
- defaultOptions
4000
+ defaultOptions,
4001
+ feegrantOperator,
4002
+ whitelistBackendPubkey
3978
4003
  }) {
3979
4004
  const defaultParams = getDefaultParams(network);
3980
4005
  this.rpcEndpoint = rpcEndpoint || defaultParams.rpcEndpoint;
@@ -3983,6 +4008,8 @@ var MaciClient2 = class {
3983
4008
  this.registryAddress = registryAddress || defaultParams.registryAddress;
3984
4009
  this.maciCodeId = maciCodeId || defaultParams.maciCodeId;
3985
4010
  this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
4011
+ this.feegrantOperator = feegrantOperator || defaultParams.oracleFeegrantOperator;
4012
+ this.whitelistBackendPubkey = whitelistBackendPubkey || defaultParams.oracleWhitelistBackendPubkey;
3986
4013
  this.http = new Http(
3987
4014
  this.apiEndpoint,
3988
4015
  this.restEndpoint,
@@ -3999,7 +4026,9 @@ var MaciClient2 = class {
3999
4026
  rpcEndpoint: this.rpcEndpoint,
4000
4027
  registryAddress: this.registryAddress,
4001
4028
  maciCodeId: this.maciCodeId,
4002
- oracleCodeId: this.oracleCodeId
4029
+ oracleCodeId: this.oracleCodeId,
4030
+ feegrantOperator: this.feegrantOperator,
4031
+ whitelistBackendPubkey: this.whitelistBackendPubkey
4003
4032
  });
4004
4033
  }
4005
4034
  async oracleMaciClient({