@dorafactory/maci-sdk 0.0.53 → 0.0.56
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 +1 -8
- package/dist/index.js +41 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -12
- package/dist/index.mjs.map +1 -1
- package/dist/libs/contract/contract.d.ts +2 -1
- package/dist/libs/contract/utils.d.ts +1 -1
- package/dist/libs/maci/maci.d.ts +2 -2
- package/dist/maci.d.ts +4 -4
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/libs/contract/contract.ts +8 -1
- package/src/libs/contract/utils.ts +15 -3
- package/src/libs/maci/maci.ts +15 -8
- package/src/maci.ts +15 -4
- package/src/types/index.ts +1 -0
package/README.md
CHANGED
|
@@ -188,17 +188,10 @@ const signupResponse = await client.maci.signup({
|
|
|
188
188
|
gasStation: true, // Whether to use gas station
|
|
189
189
|
});
|
|
190
190
|
|
|
191
|
-
// 5.
|
|
192
|
-
const stateIdx = await client.maci.getStateIdxByPubKey({
|
|
193
|
-
contractAddress: 'dora1...',
|
|
194
|
-
pubKey: maciAccount.pubKey,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// 6. Cast vote
|
|
191
|
+
// 5. Cast vote
|
|
198
192
|
const voteResponse = await client.maci.vote({
|
|
199
193
|
signer: wallet,
|
|
200
194
|
address,
|
|
201
|
-
stateIdx,
|
|
202
195
|
contractAddress: 'dora1...',
|
|
203
196
|
selectedOptions: [
|
|
204
197
|
{ idx: 0, vc: 2 }, // Option index and voting weight
|
package/dist/index.js
CHANGED
|
@@ -4801,15 +4801,23 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
4801
4801
|
};
|
|
4802
4802
|
}
|
|
4803
4803
|
}
|
|
4804
|
-
function getAMaciRoundCircuitFee(maxVoter, maxOption) {
|
|
4804
|
+
function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
|
|
4805
4805
|
let requiredFee = {
|
|
4806
4806
|
denom: "peaka",
|
|
4807
4807
|
amount: "0"
|
|
4808
4808
|
};
|
|
4809
4809
|
if (maxVoter <= 25 && maxOption <= 5) {
|
|
4810
|
-
|
|
4810
|
+
if (network === "mainnet") {
|
|
4811
|
+
requiredFee.amount = "20000000000000000000";
|
|
4812
|
+
} else {
|
|
4813
|
+
requiredFee.amount = "50000000000000000000";
|
|
4814
|
+
}
|
|
4811
4815
|
} else if (maxVoter <= 625 && maxOption <= 25) {
|
|
4812
|
-
|
|
4816
|
+
if (network === "mainnet") {
|
|
4817
|
+
requiredFee.amount = "750000000000000000000";
|
|
4818
|
+
} else {
|
|
4819
|
+
requiredFee.amount = "100000000000000000000";
|
|
4820
|
+
}
|
|
4813
4821
|
} else {
|
|
4814
4822
|
throw new Error("Number of voters or options is too large.");
|
|
4815
4823
|
}
|
|
@@ -4819,6 +4827,7 @@ function getAMaciRoundCircuitFee(maxVoter, maxOption) {
|
|
|
4819
4827
|
// src/libs/contract/contract.ts
|
|
4820
4828
|
var Contract = class {
|
|
4821
4829
|
constructor({
|
|
4830
|
+
network,
|
|
4822
4831
|
rpcEndpoint,
|
|
4823
4832
|
registryAddress,
|
|
4824
4833
|
maciCodeId,
|
|
@@ -4826,6 +4835,7 @@ var Contract = class {
|
|
|
4826
4835
|
feegrantOperator,
|
|
4827
4836
|
whitelistBackendPubkey
|
|
4828
4837
|
}) {
|
|
4838
|
+
this.network = network;
|
|
4829
4839
|
this.rpcEndpoint = rpcEndpoint;
|
|
4830
4840
|
this.registryAddress = registryAddress;
|
|
4831
4841
|
this.maciCodeId = maciCodeId;
|
|
@@ -4856,7 +4866,11 @@ var Contract = class {
|
|
|
4856
4866
|
wallet: signer,
|
|
4857
4867
|
contractAddress: this.registryAddress
|
|
4858
4868
|
});
|
|
4859
|
-
const requiredFee = getAMaciRoundCircuitFee(
|
|
4869
|
+
const requiredFee = getAMaciRoundCircuitFee(
|
|
4870
|
+
this.network,
|
|
4871
|
+
maxVoter,
|
|
4872
|
+
maxOption
|
|
4873
|
+
);
|
|
4860
4874
|
preDeactivateRoot = preDeactivateRoot || "0";
|
|
4861
4875
|
const res = await client.createRound(
|
|
4862
4876
|
{
|
|
@@ -5140,6 +5154,7 @@ var MACI = class {
|
|
|
5140
5154
|
oracleCertificate,
|
|
5141
5155
|
maciKeypair
|
|
5142
5156
|
}) {
|
|
5157
|
+
this.network = contract.network;
|
|
5143
5158
|
this.contract = contract;
|
|
5144
5159
|
this.indexer = indexer;
|
|
5145
5160
|
this.oracleCertificate = oracleCertificate;
|
|
@@ -5378,7 +5393,7 @@ var MACI = class {
|
|
|
5378
5393
|
maxVoter,
|
|
5379
5394
|
maxOption
|
|
5380
5395
|
}) {
|
|
5381
|
-
const fee = getAMaciRoundCircuitFee(maxVoter, maxOption);
|
|
5396
|
+
const fee = getAMaciRoundCircuitFee(this.network, maxVoter, maxOption);
|
|
5382
5397
|
return fee;
|
|
5383
5398
|
}
|
|
5384
5399
|
async queryRoundGasStation({ contractAddress }) {
|
|
@@ -5505,15 +5520,23 @@ var MACI = class {
|
|
|
5505
5520
|
async vote({
|
|
5506
5521
|
signer,
|
|
5507
5522
|
address,
|
|
5508
|
-
stateIdx,
|
|
5509
5523
|
contractAddress,
|
|
5510
5524
|
selectedOptions,
|
|
5511
5525
|
operatorCoordPubKey,
|
|
5512
5526
|
maciKeypair,
|
|
5513
5527
|
gasStation = false
|
|
5514
5528
|
}) {
|
|
5529
|
+
if (maciKeypair === void 0) {
|
|
5530
|
+
maciKeypair = this.maciKeypair;
|
|
5531
|
+
}
|
|
5532
|
+
const stateIdx = await this.getStateIdxByPubKey({
|
|
5533
|
+
contractAddress,
|
|
5534
|
+
pubKey: maciKeypair.pubKey
|
|
5535
|
+
});
|
|
5515
5536
|
if (stateIdx === -1) {
|
|
5516
|
-
throw new Error(
|
|
5537
|
+
throw new Error(
|
|
5538
|
+
"State index is not set, Please signup or addNewKey first"
|
|
5539
|
+
);
|
|
5517
5540
|
}
|
|
5518
5541
|
try {
|
|
5519
5542
|
const round = await this.indexer.getRoundWithFields(contractAddress, [
|
|
@@ -5565,9 +5588,6 @@ var MACI = class {
|
|
|
5565
5588
|
if (!address) {
|
|
5566
5589
|
address = (await signer.getAccounts())[0].address;
|
|
5567
5590
|
}
|
|
5568
|
-
if (maciKeypair === void 0) {
|
|
5569
|
-
maciKeypair = this.maciKeypair;
|
|
5570
|
-
}
|
|
5571
5591
|
const plan = options.map((o) => {
|
|
5572
5592
|
return [o.idx, o.vc];
|
|
5573
5593
|
});
|
|
@@ -6010,6 +6030,7 @@ var MaciClient2 = class {
|
|
|
6010
6030
|
http: this.http
|
|
6011
6031
|
});
|
|
6012
6032
|
this.contract = new Contract({
|
|
6033
|
+
network: this.network,
|
|
6013
6034
|
rpcEndpoint: this.rpcEndpoint,
|
|
6014
6035
|
registryAddress: this.registryAddress,
|
|
6015
6036
|
maciCodeId: this.maciCodeId,
|
|
@@ -6126,8 +6147,18 @@ var MaciClient2 = class {
|
|
|
6126
6147
|
async getVoiceCreditBalance({
|
|
6127
6148
|
signer,
|
|
6128
6149
|
stateIdx,
|
|
6150
|
+
maciKeypair,
|
|
6129
6151
|
contractAddress
|
|
6130
6152
|
}) {
|
|
6153
|
+
if (maciKeypair === void 0) {
|
|
6154
|
+
maciKeypair = this.maciKeypair;
|
|
6155
|
+
}
|
|
6156
|
+
if (stateIdx === void 0) {
|
|
6157
|
+
stateIdx = await this.getStateIdxByPubKey({
|
|
6158
|
+
contractAddress,
|
|
6159
|
+
pubKey: maciKeypair.pubKey
|
|
6160
|
+
});
|
|
6161
|
+
}
|
|
6131
6162
|
return await this.maci.getVoiceCreditBalance({
|
|
6132
6163
|
signer: this.getSigner(signer),
|
|
6133
6164
|
stateIdx,
|
|
@@ -6287,7 +6318,6 @@ var MaciClient2 = class {
|
|
|
6287
6318
|
async vote({
|
|
6288
6319
|
signer,
|
|
6289
6320
|
address,
|
|
6290
|
-
stateIdx,
|
|
6291
6321
|
contractAddress,
|
|
6292
6322
|
selectedOptions,
|
|
6293
6323
|
operatorCoordPubKey,
|
|
@@ -6297,7 +6327,6 @@ var MaciClient2 = class {
|
|
|
6297
6327
|
return await this.maci.vote({
|
|
6298
6328
|
signer: this.getSigner(signer),
|
|
6299
6329
|
address,
|
|
6300
|
-
stateIdx,
|
|
6301
6330
|
contractAddress,
|
|
6302
6331
|
selectedOptions,
|
|
6303
6332
|
operatorCoordPubKey,
|