@dorafactory/maci-sdk 0.0.9 → 0.0.11

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
@@ -116,8 +116,7 @@ const newRound = await client.createOracleMaciRound({
116
116
  title: 'Just for fun',
117
117
  description: 'some description',
118
118
  link: 'https://www.dorafactory.org',
119
- maxVoter: '5',
120
- maxOption: '5',
119
+ voteOptionMap: ['option1: A', 'option2: B', 'option3: C'],
121
120
  circuitType: MaciCircuitType.IP1V,
122
121
  whitelistEcosystem: 'cosmoshub',
123
122
  whitelistSnapshotHeight: '0',
@@ -146,3 +145,108 @@ For example, if a voter stakes 100000000 tokens and the slope value is 2500000,
146
145
  > 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.
147
146
  >
148
147
  > One detail, here the slope is calculated by rounding down.
148
+
149
+ #### Sign Up and Vote in a Oracle MACI Round
150
+
151
+ ```typescript
152
+ // 1. Generate MACI account
153
+ const maciAccount = await client.circom.genKeypairFromSign(wallet, address);
154
+
155
+ // 2. Get Oracle certificate (only for Oracle MACI)
156
+ const certificate = await client.maci.requestOracleCertificate({
157
+ signer: wallet,
158
+ ecosystem: 'doravota', // or 'cosmoshub'
159
+ address,
160
+ contractAddress: 'dora1...',
161
+ });
162
+
163
+ // 3. Check Gas Station status
164
+ let gasStationEnable = await client.maci.queryRoundGasStation({
165
+ contractAddress: 'dora1...',
166
+ });
167
+
168
+ // Wait for Gas Station to be enabled
169
+ while (!gasStationEnable) {
170
+ await delay(1000); // Delay 1 second
171
+ gasStationEnable = await client.maci.queryRoundGasStation({
172
+ contractAddress: 'dora1...',
173
+ });
174
+ }
175
+
176
+ // 4. Sign up for voting
177
+ const signupResponse = await client.maci.signup({
178
+ signer: wallet,
179
+ address,
180
+ contractAddress: 'dora1...',
181
+ oracleCertificate: {
182
+ amount: certificate.amount,
183
+ signature: certificate.signature,
184
+ },
185
+ gasStation: true, // Whether to use gas station
186
+ });
187
+
188
+ // 5. Get user state index
189
+ const stateIdx = await client.maci.getStateIdxByPubKey({
190
+ contractAddress: 'dora1...',
191
+ pubKey: maciAccount.pubKey,
192
+ });
193
+
194
+ // 6. Cast vote
195
+ const voteResponse = await client.maci.vote({
196
+ signer: wallet,
197
+ address,
198
+ stateIdx,
199
+ contractAddress: 'dora1...',
200
+ selectedOptions: [
201
+ { idx: 0, vc: 2 }, // Option index and voting weight
202
+ { idx: 1, vc: 1 },
203
+ { idx: 4, vc: 1 },
204
+ ],
205
+ operatorCoordPubKey: [
206
+ BigInt(roundInfo.coordinatorPubkeyX),
207
+ BigInt(roundInfo.coordinatorPubkeyY),
208
+ ],
209
+ gasStation: true,
210
+ });
211
+ ```
212
+
213
+ **Voting Rules:**
214
+
215
+ MACI supports two voting rules:
216
+ 1. 1P1V (One Person One Vote): Each voting weight (vc) directly counts as votes
217
+ 2. QV (Quadratic Voting): The sum of squares of voting weights (vc) is consumed as total voting power
218
+
219
+ Vote options format:
220
+ ```typescript
221
+ selectedOptions: [
222
+ { idx: number, vc: number }, // idx: option index, vc: voting weight
223
+ ...
224
+ ]
225
+ ```
226
+
227
+ Examples:
228
+ ```typescript
229
+ // 1P1V mode example (total voting power: 4)
230
+ const options1p1v = [
231
+ { idx: 0, vc: 2 }, // 2 votes for option 0
232
+ { idx: 1, vc: 1 }, // 1 vote for option 1
233
+ { idx: 4, vc: 1 }, // 1 vote for option 4
234
+ ];
235
+ // Total voting power consumed = 2 + 1 + 1 = 4
236
+
237
+ // QV mode example (total voting power: 6)
238
+ const optionsQv = [
239
+ { idx: 0, vc: 2 }, // Consumes 4 voting power (2²)
240
+ { idx: 1, vc: 1 }, // Consumes 1 voting power (1²)
241
+ { idx: 2, vc: 1 }, // Consumes 1 voting power (1²)
242
+ ];
243
+ // Total voting power consumed = 2² + 1² + 1² = 6
244
+ ```
245
+
246
+ **Important Notes:**
247
+ - Option indices (idx) must be unique
248
+ - Voting weights (vc) must be positive integers
249
+ - In QV mode, total voting power consumed is the sum of squares of voting weights
250
+ - Total voting power consumed cannot exceed user's available voting credits
251
+ - System automatically filters out options with zero voting weight
252
+ - Voting options are automatically sorted by idx
package/dist/index.js CHANGED
@@ -478,7 +478,7 @@ function getDefaultParams(network = "mainnet") {
478
478
  certificateApiEndpoint: "https://vota-certificate-api.dorafactory.org/api/v1",
479
479
  registryAddress: "dora1smg5qp5trjdkcekdjssqpjehdjf6n4cjss0clyvqcud3t3u3948s8rmgg4",
480
480
  maciCodeId: 106,
481
- oracleCodeId: 111,
481
+ oracleCodeId: 116,
482
482
  oracleWhitelistBackendPubkey: "A61YtCv2ibMZmDeM02nEElil8wlHx1tLKogBk5dPgf/Q",
483
483
  oracleFeegrantOperator: "dora16s9tljk8dy9ae335yvyzlm8gvkypx9228q8pq8"
484
484
  };
@@ -492,7 +492,7 @@ function getDefaultParams(network = "mainnet") {
492
492
  certificateApiEndpoint: "https://vota-testnet-certificate-api.dorafactory.org/api/v1",
493
493
  registryAddress: "dora13c8aecstyxrhax9znvvh5zey89edrmd2k5va57pxvpe3fxtfsfeqlhsjnd",
494
494
  maciCodeId: 107,
495
- oracleCodeId: 110,
495
+ oracleCodeId: 113,
496
496
  oracleWhitelistBackendPubkey: "AoYo/zENN/JquagPdG0/NMbWBBYxOM8BVN677mBXJKJQ",
497
497
  oracleFeegrantOperator: "dora1xp0twdzsdeq4qg3c64v66552deax8zmvq4zw78"
498
498
  };
@@ -4004,8 +4004,7 @@ var Contract = class {
4004
4004
  title,
4005
4005
  description,
4006
4006
  link,
4007
- maxVoter,
4008
- maxOption,
4007
+ voteOptionMap,
4009
4008
  circuitType,
4010
4009
  whitelistEcosystem,
4011
4010
  whitelistSnapshotHeight,
@@ -4016,20 +4015,12 @@ var Contract = class {
4016
4015
  const [{ address }] = await signer.getAccounts();
4017
4016
  const client = await createContractClientByWallet(this.rpcEndpoint, signer);
4018
4017
  const { x: operatorPubkeyX, y: operatorPubkeyY } = decompressPublicKey(operatorPubkey);
4019
- const {
4020
- parameters,
4021
- groth16ProcessVkey,
4022
- groth16TallyVkey,
4023
- plonkProcessVkey,
4024
- plonkTallyVkey,
4025
- maciVoteType,
4026
- maciCertSystem
4027
- } = getContractParams(
4018
+ const { maciVoteType, maciCertSystem } = getContractParams(
4028
4019
  "2" /* ORACLE_MACI */,
4029
4020
  circuitType,
4030
4021
  "groth16" /* GROTH16 */,
4031
- maxVoter,
4032
- maxOption
4022
+ "0",
4023
+ "0"
4033
4024
  );
4034
4025
  const instantiateResponse = await client.instantiate(
4035
4026
  address,
@@ -4040,23 +4031,17 @@ var Contract = class {
4040
4031
  start_time,
4041
4032
  end_time
4042
4033
  },
4043
- parameters,
4044
4034
  coordinator: {
4045
4035
  x: operatorPubkeyX,
4046
4036
  y: operatorPubkeyY
4047
4037
  },
4048
- groth16_process_vkey: groth16ProcessVkey,
4049
- groth16_tally_vkey: groth16TallyVkey,
4050
- plonk_process_vkey: plonkProcessVkey,
4051
- plonk_tally_vkey: plonkTallyVkey,
4052
- max_vote_options: maxOption,
4038
+ vote_option_map: voteOptionMap,
4053
4039
  whitelist_backend_pubkey: this.whitelistBackendPubkey,
4054
4040
  whitelist_ecosystem: whitelistEcosystem,
4055
4041
  whitelist_snapshot_height: whitelistSnapshotHeight,
4056
4042
  whitelist_voting_power_args: whitelistVotingPowerArgs,
4057
4043
  circuit_type: maciVoteType,
4058
4044
  certification_system: maciCertSystem,
4059
- qtr_lib: QTR_LIB,
4060
4045
  feegrant_operator: this.feegrantOperator
4061
4046
  },
4062
4047
  `[Oracle MACI] ${title}`,