@dorafactory/maci-sdk 0.0.10 → 0.0.12
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 +106 -2
- package/package.json +2 -2
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
|
-
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dorafactory/maci-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "SDK for interacting with maci",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maci",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@cosmjs/stargate": "^0.32.1",
|
|
37
37
|
"assert": "^2.1.0",
|
|
38
38
|
"bech32": "1.1.4",
|
|
39
|
-
"@dorafactory/circomlib": "^0.0.
|
|
39
|
+
"@dorafactory/circomlib": "^0.0.3",
|
|
40
40
|
"colorts": "^0.1.63",
|
|
41
41
|
"cosmjs-types": "^0.9.0",
|
|
42
42
|
"blake-hash": "^2.0.0",
|