@dorafactory/maci-sdk 0.1.0 → 0.1.2-pre.0
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/dist/index.js +994 -142
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +994 -142
- package/dist/index.mjs.map +1 -1
- package/dist/libs/const.d.ts +3 -0
- package/dist/libs/contract/config.d.ts +6 -0
- package/dist/libs/contract/contract.d.ts +65 -3
- package/dist/libs/contract/ts/Saas.client.d.ts +150 -0
- package/dist/libs/contract/ts/Saas.types.d.ts +128 -0
- package/dist/libs/contract/types.d.ts +10 -0
- package/dist/libs/maci/maci.d.ts +8 -6
- package/dist/maci.d.ts +13 -2
- package/dist/types/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/libs/const.ts +12 -1
- package/src/libs/contract/config.ts +19 -1
- package/src/libs/contract/contract.ts +553 -2
- package/src/libs/contract/ts/Saas.client.ts +567 -0
- package/src/libs/contract/ts/Saas.types.ts +147 -0
- package/src/libs/contract/types.ts +11 -2
- package/src/libs/contract/utils.ts +2 -2
- package/src/libs/maci/maci.ts +176 -88
- package/src/maci.ts +16 -0
- package/src/types/index.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -427,13 +427,16 @@ function getDefaultParams(network = "mainnet") {
|
|
|
427
427
|
apiEndpoint: "https://vota-api.dorafactory.org",
|
|
428
428
|
certificateApiEndpoint: "https://vota-certificate-api.dorafactory.org/api/v1",
|
|
429
429
|
registryAddress: "dora1smg5qp5trjdkcekdjssqpjehdjf6n4cjss0clyvqcud3t3u3948s8rmgg4",
|
|
430
|
+
saasAddress: "dora1dgnszrwnwxgr5djprrr6w4q45z8s3ghsew869g6tlp4ruqah39nqnemjya",
|
|
430
431
|
maciCodeId: 106,
|
|
431
432
|
// oracleCodeId: 116,// 9-4-3-625
|
|
432
433
|
oracleCodeId: 119,
|
|
433
434
|
// 6-3-3-125
|
|
435
|
+
saasCodeId: 152,
|
|
434
436
|
oracleWhitelistBackendPubkey: "A61YtCv2ibMZmDeM02nEElil8wlHx1tLKogBk5dPgf/Q",
|
|
435
437
|
oracleFeegrantOperator: "dora16s9tljk8dy9ae335yvyzlm8gvkypx9228q8pq8",
|
|
436
|
-
oracleCodeIds: ["101", "116", "117", "119"]
|
|
438
|
+
oracleCodeIds: ["101", "116", "117", "119"],
|
|
439
|
+
saasCodeIds: ["152"]
|
|
437
440
|
};
|
|
438
441
|
case "testnet":
|
|
439
442
|
return {
|
|
@@ -444,13 +447,16 @@ function getDefaultParams(network = "mainnet") {
|
|
|
444
447
|
apiEndpoint: "https://vota-testnet-api.dorafactory.org",
|
|
445
448
|
certificateApiEndpoint: "https://vota-testnet-certificate-api.dorafactory.org/api/v1",
|
|
446
449
|
registryAddress: "dora13c8aecstyxrhax9znvvh5zey89edrmd2k5va57pxvpe3fxtfsfeqlhsjnd",
|
|
447
|
-
|
|
450
|
+
saasAddress: "dora1dgnszrwnwxgr5djprrr6w4q45z8s3ghsew869g6tlp4ruqah39nqnemjya",
|
|
451
|
+
maciCodeId: 134,
|
|
448
452
|
// oracleCodeId: 113, // 9-4-3-625
|
|
449
453
|
oracleCodeId: 123,
|
|
450
454
|
// 6-3-3-125
|
|
455
|
+
saasCodeId: 152,
|
|
451
456
|
oracleWhitelistBackendPubkey: "AoYo/zENN/JquagPdG0/NMbWBBYxOM8BVN677mBXJKJQ",
|
|
452
457
|
oracleFeegrantOperator: "dora1xp0twdzsdeq4qg3c64v66552deax8zmvq4zw78",
|
|
453
|
-
oracleCodeIds: ["102", "105", "108", "110", "113", "115", "123"]
|
|
458
|
+
oracleCodeIds: ["102", "105", "108", "110", "113", "115", "123"],
|
|
459
|
+
saasCodeIds: ["152"]
|
|
454
460
|
};
|
|
455
461
|
}
|
|
456
462
|
}
|
|
@@ -4281,11 +4287,291 @@ var OracleMaciClient = class extends OracleMaciQueryClient {
|
|
|
4281
4287
|
}
|
|
4282
4288
|
};
|
|
4283
4289
|
|
|
4290
|
+
// src/libs/contract/ts/Saas.client.ts
|
|
4291
|
+
var SaasQueryClient = class {
|
|
4292
|
+
constructor(client, contractAddress) {
|
|
4293
|
+
this.config = async () => {
|
|
4294
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4295
|
+
config: {}
|
|
4296
|
+
});
|
|
4297
|
+
};
|
|
4298
|
+
this.operators = async () => {
|
|
4299
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4300
|
+
operators: {}
|
|
4301
|
+
});
|
|
4302
|
+
};
|
|
4303
|
+
this.isOperator = async ({ address }) => {
|
|
4304
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4305
|
+
is_operator: {
|
|
4306
|
+
address
|
|
4307
|
+
}
|
|
4308
|
+
});
|
|
4309
|
+
};
|
|
4310
|
+
this.balance = async () => {
|
|
4311
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4312
|
+
balance: {}
|
|
4313
|
+
});
|
|
4314
|
+
};
|
|
4315
|
+
this.maciContracts = async ({
|
|
4316
|
+
limit,
|
|
4317
|
+
startAfter
|
|
4318
|
+
}) => {
|
|
4319
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4320
|
+
maci_contracts: {
|
|
4321
|
+
limit,
|
|
4322
|
+
start_after: startAfter
|
|
4323
|
+
}
|
|
4324
|
+
});
|
|
4325
|
+
};
|
|
4326
|
+
this.operatorMaciContracts = async ({
|
|
4327
|
+
limit,
|
|
4328
|
+
operator,
|
|
4329
|
+
startAfter
|
|
4330
|
+
}) => {
|
|
4331
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4332
|
+
operator_maci_contracts: {
|
|
4333
|
+
limit,
|
|
4334
|
+
operator,
|
|
4335
|
+
start_after: startAfter
|
|
4336
|
+
}
|
|
4337
|
+
});
|
|
4338
|
+
};
|
|
4339
|
+
this.maciContract = async ({
|
|
4340
|
+
contractId
|
|
4341
|
+
}) => {
|
|
4342
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4343
|
+
maci_contract: {
|
|
4344
|
+
contract_id: contractId
|
|
4345
|
+
}
|
|
4346
|
+
});
|
|
4347
|
+
};
|
|
4348
|
+
this.oracleMaciCodeId = async () => {
|
|
4349
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4350
|
+
oracle_maci_code_id: {}
|
|
4351
|
+
});
|
|
4352
|
+
};
|
|
4353
|
+
this.client = client;
|
|
4354
|
+
this.contractAddress = contractAddress;
|
|
4355
|
+
this.config = this.config.bind(this);
|
|
4356
|
+
this.operators = this.operators.bind(this);
|
|
4357
|
+
this.isOperator = this.isOperator.bind(this);
|
|
4358
|
+
this.balance = this.balance.bind(this);
|
|
4359
|
+
this.maciContracts = this.maciContracts.bind(this);
|
|
4360
|
+
this.operatorMaciContracts = this.operatorMaciContracts.bind(this);
|
|
4361
|
+
this.maciContract = this.maciContract.bind(this);
|
|
4362
|
+
this.oracleMaciCodeId = this.oracleMaciCodeId.bind(this);
|
|
4363
|
+
}
|
|
4364
|
+
};
|
|
4365
|
+
var SaasClient = class extends SaasQueryClient {
|
|
4366
|
+
constructor(client, sender, contractAddress) {
|
|
4367
|
+
super(client, contractAddress);
|
|
4368
|
+
this.updateConfig = async ({
|
|
4369
|
+
admin,
|
|
4370
|
+
denom,
|
|
4371
|
+
registryContract
|
|
4372
|
+
}, fee = "auto", memo, _funds) => {
|
|
4373
|
+
return await this.client.execute(
|
|
4374
|
+
this.sender,
|
|
4375
|
+
this.contractAddress,
|
|
4376
|
+
{
|
|
4377
|
+
update_config: {
|
|
4378
|
+
admin,
|
|
4379
|
+
denom,
|
|
4380
|
+
registry_contract: registryContract
|
|
4381
|
+
}
|
|
4382
|
+
},
|
|
4383
|
+
fee,
|
|
4384
|
+
memo,
|
|
4385
|
+
_funds
|
|
4386
|
+
);
|
|
4387
|
+
};
|
|
4388
|
+
this.addOperator = async ({
|
|
4389
|
+
operator
|
|
4390
|
+
}, fee = "auto", memo, _funds) => {
|
|
4391
|
+
return await this.client.execute(
|
|
4392
|
+
this.sender,
|
|
4393
|
+
this.contractAddress,
|
|
4394
|
+
{
|
|
4395
|
+
add_operator: {
|
|
4396
|
+
operator
|
|
4397
|
+
}
|
|
4398
|
+
},
|
|
4399
|
+
fee,
|
|
4400
|
+
memo,
|
|
4401
|
+
_funds
|
|
4402
|
+
);
|
|
4403
|
+
};
|
|
4404
|
+
this.removeOperator = async ({
|
|
4405
|
+
operator
|
|
4406
|
+
}, fee = "auto", memo, _funds) => {
|
|
4407
|
+
return await this.client.execute(
|
|
4408
|
+
this.sender,
|
|
4409
|
+
this.contractAddress,
|
|
4410
|
+
{
|
|
4411
|
+
remove_operator: {
|
|
4412
|
+
operator
|
|
4413
|
+
}
|
|
4414
|
+
},
|
|
4415
|
+
fee,
|
|
4416
|
+
memo,
|
|
4417
|
+
_funds
|
|
4418
|
+
);
|
|
4419
|
+
};
|
|
4420
|
+
this.deposit = async (fee = "auto", memo, _funds) => {
|
|
4421
|
+
return await this.client.execute(
|
|
4422
|
+
this.sender,
|
|
4423
|
+
this.contractAddress,
|
|
4424
|
+
{
|
|
4425
|
+
deposit: {}
|
|
4426
|
+
},
|
|
4427
|
+
fee,
|
|
4428
|
+
memo,
|
|
4429
|
+
_funds
|
|
4430
|
+
);
|
|
4431
|
+
};
|
|
4432
|
+
this.withdraw = async ({
|
|
4433
|
+
amount,
|
|
4434
|
+
recipient
|
|
4435
|
+
}, fee = "auto", memo, _funds) => {
|
|
4436
|
+
return await this.client.execute(
|
|
4437
|
+
this.sender,
|
|
4438
|
+
this.contractAddress,
|
|
4439
|
+
{
|
|
4440
|
+
withdraw: {
|
|
4441
|
+
amount,
|
|
4442
|
+
recipient
|
|
4443
|
+
}
|
|
4444
|
+
},
|
|
4445
|
+
fee,
|
|
4446
|
+
memo,
|
|
4447
|
+
_funds
|
|
4448
|
+
);
|
|
4449
|
+
};
|
|
4450
|
+
this.updateOracleMaciCodeId = async ({
|
|
4451
|
+
codeId
|
|
4452
|
+
}, fee = "auto", memo, _funds) => {
|
|
4453
|
+
return await this.client.execute(
|
|
4454
|
+
this.sender,
|
|
4455
|
+
this.contractAddress,
|
|
4456
|
+
{
|
|
4457
|
+
update_oracle_maci_code_id: {
|
|
4458
|
+
code_id: codeId
|
|
4459
|
+
}
|
|
4460
|
+
},
|
|
4461
|
+
fee,
|
|
4462
|
+
memo,
|
|
4463
|
+
_funds
|
|
4464
|
+
);
|
|
4465
|
+
};
|
|
4466
|
+
this.createOracleMaciRound = async ({
|
|
4467
|
+
certificationSystem,
|
|
4468
|
+
circuitType,
|
|
4469
|
+
coordinator,
|
|
4470
|
+
endTime,
|
|
4471
|
+
maxVoters,
|
|
4472
|
+
roundInfo,
|
|
4473
|
+
startTime,
|
|
4474
|
+
voteOptionMap,
|
|
4475
|
+
whitelistBackendPubkey
|
|
4476
|
+
}, fee = "auto", memo, _funds) => {
|
|
4477
|
+
return await this.client.execute(
|
|
4478
|
+
this.sender,
|
|
4479
|
+
this.contractAddress,
|
|
4480
|
+
{
|
|
4481
|
+
create_oracle_maci_round: {
|
|
4482
|
+
certification_system: certificationSystem,
|
|
4483
|
+
circuit_type: circuitType,
|
|
4484
|
+
coordinator,
|
|
4485
|
+
end_time: endTime,
|
|
4486
|
+
max_voters: maxVoters.toString(),
|
|
4487
|
+
round_info: roundInfo,
|
|
4488
|
+
start_time: startTime,
|
|
4489
|
+
vote_option_map: voteOptionMap,
|
|
4490
|
+
whitelist_backend_pubkey: whitelistBackendPubkey
|
|
4491
|
+
}
|
|
4492
|
+
},
|
|
4493
|
+
fee,
|
|
4494
|
+
memo,
|
|
4495
|
+
_funds
|
|
4496
|
+
);
|
|
4497
|
+
};
|
|
4498
|
+
this.setRoundInfo = async ({
|
|
4499
|
+
contractAddr,
|
|
4500
|
+
roundInfo
|
|
4501
|
+
}, fee = "auto", memo, _funds) => {
|
|
4502
|
+
return await this.client.execute(
|
|
4503
|
+
this.sender,
|
|
4504
|
+
this.contractAddress,
|
|
4505
|
+
{
|
|
4506
|
+
set_round_info: {
|
|
4507
|
+
contract_addr: contractAddr,
|
|
4508
|
+
round_info: roundInfo
|
|
4509
|
+
}
|
|
4510
|
+
},
|
|
4511
|
+
fee,
|
|
4512
|
+
memo,
|
|
4513
|
+
_funds
|
|
4514
|
+
);
|
|
4515
|
+
};
|
|
4516
|
+
this.setVoteOptionsMap = async ({
|
|
4517
|
+
contractAddr,
|
|
4518
|
+
voteOptionMap
|
|
4519
|
+
}, fee = "auto", memo, _funds) => {
|
|
4520
|
+
return await this.client.execute(
|
|
4521
|
+
this.sender,
|
|
4522
|
+
this.contractAddress,
|
|
4523
|
+
{
|
|
4524
|
+
set_vote_options_map: {
|
|
4525
|
+
contract_addr: contractAddr,
|
|
4526
|
+
vote_option_map: voteOptionMap
|
|
4527
|
+
}
|
|
4528
|
+
},
|
|
4529
|
+
fee,
|
|
4530
|
+
memo,
|
|
4531
|
+
_funds
|
|
4532
|
+
);
|
|
4533
|
+
};
|
|
4534
|
+
this.grantToVoter = async ({
|
|
4535
|
+
baseAmount,
|
|
4536
|
+
contractAddr,
|
|
4537
|
+
grantee
|
|
4538
|
+
}, fee = "auto", memo, _funds) => {
|
|
4539
|
+
return await this.client.execute(
|
|
4540
|
+
this.sender,
|
|
4541
|
+
this.contractAddress,
|
|
4542
|
+
{
|
|
4543
|
+
grant_to_voter: {
|
|
4544
|
+
base_amount: baseAmount,
|
|
4545
|
+
contract_addr: contractAddr,
|
|
4546
|
+
grantee
|
|
4547
|
+
}
|
|
4548
|
+
},
|
|
4549
|
+
fee,
|
|
4550
|
+
memo,
|
|
4551
|
+
_funds
|
|
4552
|
+
);
|
|
4553
|
+
};
|
|
4554
|
+
this.client = client;
|
|
4555
|
+
this.sender = sender;
|
|
4556
|
+
this.contractAddress = contractAddress;
|
|
4557
|
+
this.updateConfig = this.updateConfig.bind(this);
|
|
4558
|
+
this.addOperator = this.addOperator.bind(this);
|
|
4559
|
+
this.removeOperator = this.removeOperator.bind(this);
|
|
4560
|
+
this.deposit = this.deposit.bind(this);
|
|
4561
|
+
this.withdraw = this.withdraw.bind(this);
|
|
4562
|
+
this.updateOracleMaciCodeId = this.updateOracleMaciCodeId.bind(this);
|
|
4563
|
+
this.createOracleMaciRound = this.createOracleMaciRound.bind(this);
|
|
4564
|
+
this.setRoundInfo = this.setRoundInfo.bind(this);
|
|
4565
|
+
this.setVoteOptionsMap = this.setVoteOptionsMap.bind(this);
|
|
4566
|
+
this.grantToVoter = this.grantToVoter.bind(this);
|
|
4567
|
+
}
|
|
4568
|
+
};
|
|
4569
|
+
|
|
4284
4570
|
// src/libs/contract/config.ts
|
|
4285
4571
|
var defaultSigningClientOptions = {
|
|
4286
4572
|
broadcastPollIntervalMs: 8e3,
|
|
4287
4573
|
broadcastTimeoutMs: 64e3,
|
|
4288
|
-
gasPrice: import_stargate.GasPrice.fromString("
|
|
4574
|
+
gasPrice: import_stargate.GasPrice.fromString("10000000000peaka")
|
|
4289
4575
|
};
|
|
4290
4576
|
async function createMaciClientBy({
|
|
4291
4577
|
rpcEndpoint,
|
|
@@ -4323,6 +4609,18 @@ async function createRegistryClientBy({
|
|
|
4323
4609
|
const [{ address }] = await wallet.getAccounts();
|
|
4324
4610
|
return new RegistryClient(signingCosmWasmClient, address, contractAddress);
|
|
4325
4611
|
}
|
|
4612
|
+
async function createSaasClientBy({
|
|
4613
|
+
rpcEndpoint,
|
|
4614
|
+
wallet,
|
|
4615
|
+
contractAddress
|
|
4616
|
+
}) {
|
|
4617
|
+
const signingCosmWasmClient = await createContractClientByWallet(
|
|
4618
|
+
rpcEndpoint,
|
|
4619
|
+
wallet
|
|
4620
|
+
);
|
|
4621
|
+
const [{ address }] = await wallet.getAccounts();
|
|
4622
|
+
return new SaasClient(signingCosmWasmClient, address, contractAddress);
|
|
4623
|
+
}
|
|
4326
4624
|
async function createOracleMaciClientBy({
|
|
4327
4625
|
rpcEndpoint,
|
|
4328
4626
|
wallet,
|
|
@@ -4810,13 +5108,13 @@ function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
|
|
|
4810
5108
|
if (network === "mainnet") {
|
|
4811
5109
|
requiredFee.amount = "20000000000000000000";
|
|
4812
5110
|
} else {
|
|
4813
|
-
requiredFee.amount = "
|
|
5111
|
+
requiredFee.amount = "20000000000000000000";
|
|
4814
5112
|
}
|
|
4815
5113
|
} else if (maxVoter <= 625 && maxOption <= 25) {
|
|
4816
5114
|
if (network === "mainnet") {
|
|
4817
5115
|
requiredFee.amount = "750000000000000000000";
|
|
4818
5116
|
} else {
|
|
4819
|
-
requiredFee.amount = "
|
|
5117
|
+
requiredFee.amount = "750000000000000000000";
|
|
4820
5118
|
}
|
|
4821
5119
|
} else {
|
|
4822
5120
|
throw new Error("Number of voters or options is too large.");
|
|
@@ -4825,21 +5123,26 @@ function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
|
|
|
4825
5123
|
}
|
|
4826
5124
|
|
|
4827
5125
|
// src/libs/contract/contract.ts
|
|
5126
|
+
var import_stargate2 = require("@cosmjs/stargate");
|
|
4828
5127
|
var Contract = class {
|
|
4829
5128
|
constructor({
|
|
4830
5129
|
network,
|
|
4831
5130
|
rpcEndpoint,
|
|
4832
5131
|
registryAddress,
|
|
5132
|
+
saasAddress,
|
|
4833
5133
|
maciCodeId,
|
|
4834
5134
|
oracleCodeId,
|
|
5135
|
+
saasOracleCodeId,
|
|
4835
5136
|
feegrantOperator,
|
|
4836
5137
|
whitelistBackendPubkey
|
|
4837
5138
|
}) {
|
|
4838
5139
|
this.network = network;
|
|
4839
5140
|
this.rpcEndpoint = rpcEndpoint;
|
|
4840
5141
|
this.registryAddress = registryAddress;
|
|
5142
|
+
this.saasAddress = saasAddress;
|
|
4841
5143
|
this.maciCodeId = maciCodeId;
|
|
4842
5144
|
this.oracleCodeId = oracleCodeId;
|
|
5145
|
+
this.saasOracleCodeId = saasOracleCodeId;
|
|
4843
5146
|
this.feegrantOperator = feegrantOperator;
|
|
4844
5147
|
this.whitelistBackendPubkey = whitelistBackendPubkey;
|
|
4845
5148
|
}
|
|
@@ -4973,66 +5276,513 @@ var Contract = class {
|
|
|
4973
5276
|
certification_system: maciCertSystem,
|
|
4974
5277
|
qtr_lib: QTR_LIB
|
|
4975
5278
|
},
|
|
4976
|
-
`[MACI] ${title}`,
|
|
5279
|
+
`[MACI] ${title}`,
|
|
5280
|
+
fee
|
|
5281
|
+
);
|
|
5282
|
+
return instantiateResponse;
|
|
5283
|
+
}
|
|
5284
|
+
async createOracleMaciRound({
|
|
5285
|
+
signer,
|
|
5286
|
+
operatorPubkey,
|
|
5287
|
+
startVoting,
|
|
5288
|
+
endVoting,
|
|
5289
|
+
title,
|
|
5290
|
+
description,
|
|
5291
|
+
link,
|
|
5292
|
+
maxVoter,
|
|
5293
|
+
voteOptionMap,
|
|
5294
|
+
circuitType,
|
|
5295
|
+
whitelistEcosystem,
|
|
5296
|
+
whitelistSnapshotHeight,
|
|
5297
|
+
whitelistVotingPowerArgs,
|
|
5298
|
+
whitelistBackendPubkey,
|
|
5299
|
+
feegrantOperator,
|
|
5300
|
+
fee = "auto"
|
|
5301
|
+
}) {
|
|
5302
|
+
const start_time = (startVoting.getTime() * 1e6).toString();
|
|
5303
|
+
const end_time = (endVoting.getTime() * 1e6).toString();
|
|
5304
|
+
const [{ address }] = await signer.getAccounts();
|
|
5305
|
+
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
5306
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
5307
|
+
BigInt(operatorPubkey)
|
|
5308
|
+
);
|
|
5309
|
+
const { maciVoteType, maciCertSystem } = getContractParams(
|
|
5310
|
+
"2" /* ORACLE_MACI */,
|
|
5311
|
+
circuitType,
|
|
5312
|
+
"groth16" /* GROTH16 */,
|
|
5313
|
+
0,
|
|
5314
|
+
0
|
|
5315
|
+
);
|
|
5316
|
+
const instantiateResponse = await client.instantiate(
|
|
5317
|
+
address,
|
|
5318
|
+
this.oracleCodeId,
|
|
5319
|
+
{
|
|
5320
|
+
max_voters: maxVoter.toString(),
|
|
5321
|
+
round_info: { title, description: description || "", link: link || "" },
|
|
5322
|
+
voting_time: {
|
|
5323
|
+
start_time,
|
|
5324
|
+
end_time
|
|
5325
|
+
},
|
|
5326
|
+
coordinator: {
|
|
5327
|
+
x: operatorPubkeyX.toString(),
|
|
5328
|
+
y: operatorPubkeyY.toString()
|
|
5329
|
+
},
|
|
5330
|
+
vote_option_map: voteOptionMap,
|
|
5331
|
+
whitelist_backend_pubkey: whitelistBackendPubkey ? whitelistBackendPubkey : this.whitelistBackendPubkey,
|
|
5332
|
+
whitelist_ecosystem: whitelistEcosystem,
|
|
5333
|
+
whitelist_snapshot_height: whitelistSnapshotHeight,
|
|
5334
|
+
whitelist_voting_power_args: whitelistVotingPowerArgs,
|
|
5335
|
+
circuit_type: maciVoteType,
|
|
5336
|
+
certification_system: maciCertSystem,
|
|
5337
|
+
feegrant_operator: feegrantOperator ? feegrantOperator : this.feegrantOperator
|
|
5338
|
+
},
|
|
5339
|
+
`[Oracle MACI] ${title}`,
|
|
5340
|
+
fee
|
|
5341
|
+
);
|
|
5342
|
+
return instantiateResponse;
|
|
5343
|
+
}
|
|
5344
|
+
async createSaasOracleMaciRound({
|
|
5345
|
+
signer,
|
|
5346
|
+
operatorPubkey,
|
|
5347
|
+
startVoting,
|
|
5348
|
+
endVoting,
|
|
5349
|
+
title,
|
|
5350
|
+
description,
|
|
5351
|
+
link,
|
|
5352
|
+
maxVoter,
|
|
5353
|
+
voteOptionMap,
|
|
5354
|
+
whitelistBackendPubkey
|
|
5355
|
+
}) {
|
|
5356
|
+
const startTime = (startVoting.getTime() * 1e6).toString();
|
|
5357
|
+
const endTime = (endVoting.getTime() * 1e6).toString();
|
|
5358
|
+
const client = await createSaasClientBy({
|
|
5359
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5360
|
+
wallet: signer,
|
|
5361
|
+
contractAddress: this.saasAddress
|
|
5362
|
+
});
|
|
5363
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
5364
|
+
BigInt(operatorPubkey)
|
|
5365
|
+
);
|
|
5366
|
+
const createResponse = await client.createOracleMaciRound({
|
|
5367
|
+
certificationSystem: "0",
|
|
5368
|
+
circuitType: "0",
|
|
5369
|
+
coordinator: {
|
|
5370
|
+
x: operatorPubkeyX.toString(),
|
|
5371
|
+
y: operatorPubkeyY.toString()
|
|
5372
|
+
},
|
|
5373
|
+
maxVoters: maxVoter,
|
|
5374
|
+
roundInfo: {
|
|
5375
|
+
title,
|
|
5376
|
+
description: description || "",
|
|
5377
|
+
link: link || ""
|
|
5378
|
+
},
|
|
5379
|
+
startTime,
|
|
5380
|
+
endTime,
|
|
5381
|
+
voteOptionMap,
|
|
5382
|
+
whitelistBackendPubkey: whitelistBackendPubkey || this.whitelistBackendPubkey
|
|
5383
|
+
});
|
|
5384
|
+
let contractAddress = "";
|
|
5385
|
+
createResponse.events.map((event) => {
|
|
5386
|
+
if (event.type === "wasm") {
|
|
5387
|
+
let actionEvent = event.attributes.find(
|
|
5388
|
+
(attr) => attr.key === "action"
|
|
5389
|
+
);
|
|
5390
|
+
if (actionEvent.value === "created_oracle_maci_round") {
|
|
5391
|
+
contractAddress = event.attributes.find((attr) => attr.key === "round_addr").value.toString();
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
});
|
|
5395
|
+
return {
|
|
5396
|
+
...createResponse,
|
|
5397
|
+
contractAddress
|
|
5398
|
+
};
|
|
5399
|
+
}
|
|
5400
|
+
async setSaasOracleMaciRoundInfo({
|
|
5401
|
+
signer,
|
|
5402
|
+
contractAddress,
|
|
5403
|
+
title,
|
|
5404
|
+
description,
|
|
5405
|
+
link,
|
|
5406
|
+
gasStation = false,
|
|
5407
|
+
fee = 1.8
|
|
5408
|
+
}) {
|
|
5409
|
+
const client = await createSaasClientBy({
|
|
5410
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5411
|
+
wallet: signer,
|
|
5412
|
+
contractAddress: this.saasAddress
|
|
5413
|
+
});
|
|
5414
|
+
const roundInfo = {
|
|
5415
|
+
title,
|
|
5416
|
+
description,
|
|
5417
|
+
link
|
|
5418
|
+
};
|
|
5419
|
+
if (gasStation && typeof fee !== "object") {
|
|
5420
|
+
const [{ address }] = await signer.getAccounts();
|
|
5421
|
+
const contractClient = await this.contractClient({ signer });
|
|
5422
|
+
const msg = {
|
|
5423
|
+
set_round_info: {
|
|
5424
|
+
contract_addr: contractAddress,
|
|
5425
|
+
round_info: roundInfo
|
|
5426
|
+
}
|
|
5427
|
+
};
|
|
5428
|
+
const gasEstimation = await contractClient.simulate(
|
|
5429
|
+
address,
|
|
5430
|
+
[
|
|
5431
|
+
{
|
|
5432
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5433
|
+
value: {
|
|
5434
|
+
sender: address,
|
|
5435
|
+
contract: this.saasAddress,
|
|
5436
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5439
|
+
],
|
|
5440
|
+
""
|
|
5441
|
+
);
|
|
5442
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5443
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5444
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
5445
|
+
Math.round(gasEstimation * multiplier),
|
|
5446
|
+
gasPrice
|
|
5447
|
+
);
|
|
5448
|
+
const grantFee = {
|
|
5449
|
+
amount: calculatedFee.amount,
|
|
5450
|
+
gas: calculatedFee.gas,
|
|
5451
|
+
granter: this.saasAddress
|
|
5452
|
+
};
|
|
5453
|
+
return client.setRoundInfo(
|
|
5454
|
+
{
|
|
5455
|
+
contractAddr: contractAddress,
|
|
5456
|
+
roundInfo
|
|
5457
|
+
},
|
|
5458
|
+
grantFee
|
|
5459
|
+
);
|
|
5460
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5461
|
+
const grantFee = {
|
|
5462
|
+
...fee,
|
|
5463
|
+
granter: this.saasAddress
|
|
5464
|
+
};
|
|
5465
|
+
return client.setRoundInfo(
|
|
5466
|
+
{
|
|
5467
|
+
contractAddr: contractAddress,
|
|
5468
|
+
roundInfo
|
|
5469
|
+
},
|
|
5470
|
+
grantFee
|
|
5471
|
+
);
|
|
5472
|
+
}
|
|
5473
|
+
return client.setRoundInfo(
|
|
5474
|
+
{
|
|
5475
|
+
contractAddr: contractAddress,
|
|
5476
|
+
roundInfo
|
|
5477
|
+
},
|
|
5478
|
+
fee
|
|
5479
|
+
);
|
|
5480
|
+
}
|
|
5481
|
+
async setSaasOracleMaciRoundVoteOptions({
|
|
5482
|
+
signer,
|
|
5483
|
+
contractAddress,
|
|
5484
|
+
voteOptionMap,
|
|
5485
|
+
gasStation = false,
|
|
5486
|
+
fee = 1.8
|
|
5487
|
+
}) {
|
|
5488
|
+
const client = await createSaasClientBy({
|
|
5489
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5490
|
+
wallet: signer,
|
|
5491
|
+
contractAddress: this.saasAddress
|
|
5492
|
+
});
|
|
5493
|
+
if (gasStation && typeof fee !== "object") {
|
|
5494
|
+
const [{ address }] = await signer.getAccounts();
|
|
5495
|
+
const contractClient = await this.contractClient({ signer });
|
|
5496
|
+
const msg = {
|
|
5497
|
+
set_vote_options_map: {
|
|
5498
|
+
contract_addr: contractAddress,
|
|
5499
|
+
vote_option_map: voteOptionMap
|
|
5500
|
+
}
|
|
5501
|
+
};
|
|
5502
|
+
const gasEstimation = await contractClient.simulate(
|
|
5503
|
+
address,
|
|
5504
|
+
[
|
|
5505
|
+
{
|
|
5506
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5507
|
+
value: {
|
|
5508
|
+
sender: address,
|
|
5509
|
+
contract: this.saasAddress,
|
|
5510
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5511
|
+
}
|
|
5512
|
+
}
|
|
5513
|
+
],
|
|
5514
|
+
""
|
|
5515
|
+
);
|
|
5516
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5517
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5518
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
5519
|
+
Math.round(gasEstimation * multiplier),
|
|
5520
|
+
gasPrice
|
|
5521
|
+
);
|
|
5522
|
+
const grantFee = {
|
|
5523
|
+
amount: calculatedFee.amount,
|
|
5524
|
+
gas: calculatedFee.gas,
|
|
5525
|
+
granter: this.saasAddress
|
|
5526
|
+
};
|
|
5527
|
+
return client.setVoteOptionsMap(
|
|
5528
|
+
{
|
|
5529
|
+
contractAddr: contractAddress,
|
|
5530
|
+
voteOptionMap
|
|
5531
|
+
},
|
|
5532
|
+
grantFee
|
|
5533
|
+
);
|
|
5534
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5535
|
+
const grantFee = {
|
|
5536
|
+
...fee,
|
|
5537
|
+
granter: this.saasAddress
|
|
5538
|
+
};
|
|
5539
|
+
return client.setVoteOptionsMap(
|
|
5540
|
+
{
|
|
5541
|
+
contractAddr: contractAddress,
|
|
5542
|
+
voteOptionMap
|
|
5543
|
+
},
|
|
5544
|
+
grantFee
|
|
5545
|
+
);
|
|
5546
|
+
}
|
|
5547
|
+
return client.setVoteOptionsMap(
|
|
5548
|
+
{
|
|
5549
|
+
contractAddr: contractAddress,
|
|
5550
|
+
voteOptionMap
|
|
5551
|
+
},
|
|
4977
5552
|
fee
|
|
4978
5553
|
);
|
|
4979
|
-
return instantiateResponse;
|
|
4980
5554
|
}
|
|
4981
|
-
async
|
|
5555
|
+
async addSaasOperator({
|
|
4982
5556
|
signer,
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
title,
|
|
4987
|
-
description,
|
|
4988
|
-
link,
|
|
4989
|
-
voteOptionMap,
|
|
4990
|
-
circuitType,
|
|
4991
|
-
whitelistEcosystem,
|
|
4992
|
-
whitelistSnapshotHeight,
|
|
4993
|
-
whitelistVotingPowerArgs,
|
|
4994
|
-
fee = "auto"
|
|
5557
|
+
operator,
|
|
5558
|
+
gasStation = false,
|
|
5559
|
+
fee = 1.8
|
|
4995
5560
|
}) {
|
|
4996
|
-
const
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5561
|
+
const client = await createSaasClientBy({
|
|
5562
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5563
|
+
wallet: signer,
|
|
5564
|
+
contractAddress: this.saasAddress
|
|
5565
|
+
});
|
|
5566
|
+
if (gasStation && typeof fee !== "object") {
|
|
5567
|
+
const [{ address }] = await signer.getAccounts();
|
|
5568
|
+
const contractClient = await this.contractClient({ signer });
|
|
5569
|
+
const msg = {
|
|
5570
|
+
add_operator: {
|
|
5571
|
+
operator
|
|
5572
|
+
}
|
|
5573
|
+
};
|
|
5574
|
+
const gasEstimation = await contractClient.simulate(
|
|
5575
|
+
address,
|
|
5576
|
+
[
|
|
5577
|
+
{
|
|
5578
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5579
|
+
value: {
|
|
5580
|
+
sender: address,
|
|
5581
|
+
contract: this.saasAddress,
|
|
5582
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5583
|
+
}
|
|
5584
|
+
}
|
|
5585
|
+
],
|
|
5586
|
+
""
|
|
5587
|
+
);
|
|
5588
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5589
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5590
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
5591
|
+
Math.round(gasEstimation * multiplier),
|
|
5592
|
+
gasPrice
|
|
5593
|
+
);
|
|
5594
|
+
const grantFee = {
|
|
5595
|
+
amount: calculatedFee.amount,
|
|
5596
|
+
gas: calculatedFee.gas,
|
|
5597
|
+
granter: this.saasAddress
|
|
5598
|
+
};
|
|
5599
|
+
return client.addOperator({ operator }, grantFee);
|
|
5600
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5601
|
+
const grantFee = {
|
|
5602
|
+
...fee,
|
|
5603
|
+
granter: this.saasAddress
|
|
5604
|
+
};
|
|
5605
|
+
return client.addOperator({ operator }, grantFee);
|
|
5606
|
+
}
|
|
5607
|
+
return client.addOperator({ operator }, fee);
|
|
5608
|
+
}
|
|
5609
|
+
async removeSaasOperator({
|
|
5610
|
+
signer,
|
|
5611
|
+
operator,
|
|
5612
|
+
gasStation = false,
|
|
5613
|
+
fee = 1.8
|
|
5614
|
+
}) {
|
|
5615
|
+
const client = await createSaasClientBy({
|
|
5616
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5617
|
+
wallet: signer,
|
|
5618
|
+
contractAddress: this.saasAddress
|
|
5619
|
+
});
|
|
5620
|
+
if (gasStation && typeof fee !== "object") {
|
|
5621
|
+
const [{ address }] = await signer.getAccounts();
|
|
5622
|
+
const contractClient = await this.contractClient({ signer });
|
|
5623
|
+
const msg = {
|
|
5624
|
+
remove_operator: {
|
|
5625
|
+
operator
|
|
5626
|
+
}
|
|
5627
|
+
};
|
|
5628
|
+
const gasEstimation = await contractClient.simulate(
|
|
5629
|
+
address,
|
|
5630
|
+
[
|
|
5631
|
+
{
|
|
5632
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5633
|
+
value: {
|
|
5634
|
+
sender: address,
|
|
5635
|
+
contract: this.saasAddress,
|
|
5636
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5637
|
+
}
|
|
5638
|
+
}
|
|
5639
|
+
],
|
|
5640
|
+
""
|
|
5641
|
+
);
|
|
5642
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5643
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5644
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
5645
|
+
Math.round(gasEstimation * multiplier),
|
|
5646
|
+
gasPrice
|
|
5647
|
+
);
|
|
5648
|
+
const grantFee = {
|
|
5649
|
+
amount: calculatedFee.amount,
|
|
5650
|
+
gas: calculatedFee.gas,
|
|
5651
|
+
granter: this.saasAddress
|
|
5652
|
+
};
|
|
5653
|
+
return client.removeOperator({ operator }, grantFee);
|
|
5654
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5655
|
+
const grantFee = {
|
|
5656
|
+
...fee,
|
|
5657
|
+
granter: this.saasAddress
|
|
5658
|
+
};
|
|
5659
|
+
return client.removeOperator({ operator }, grantFee);
|
|
5660
|
+
}
|
|
5661
|
+
return client.removeOperator({ operator }, fee);
|
|
5662
|
+
}
|
|
5663
|
+
async isSaasOperator({
|
|
5664
|
+
signer,
|
|
5665
|
+
operator
|
|
5666
|
+
}) {
|
|
5667
|
+
const client = await createSaasClientBy({
|
|
5668
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5669
|
+
wallet: signer,
|
|
5670
|
+
contractAddress: this.saasAddress
|
|
5671
|
+
});
|
|
5672
|
+
return client.isOperator({ address: operator });
|
|
5673
|
+
}
|
|
5674
|
+
async depositSaas({
|
|
5675
|
+
signer,
|
|
5676
|
+
amount,
|
|
5677
|
+
gasStation = false,
|
|
5678
|
+
fee = 1.8
|
|
5679
|
+
}) {
|
|
5680
|
+
const client = await createSaasClientBy({
|
|
5681
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5682
|
+
wallet: signer,
|
|
5683
|
+
contractAddress: this.saasAddress
|
|
5684
|
+
});
|
|
5685
|
+
const funds = [
|
|
5013
5686
|
{
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
}
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5687
|
+
denom: "peaka",
|
|
5688
|
+
amount
|
|
5689
|
+
}
|
|
5690
|
+
];
|
|
5691
|
+
if (gasStation && typeof fee !== "object") {
|
|
5692
|
+
const [{ address }] = await signer.getAccounts();
|
|
5693
|
+
const contractClient = await this.contractClient({ signer });
|
|
5694
|
+
const msg = {
|
|
5695
|
+
deposit: {}
|
|
5696
|
+
};
|
|
5697
|
+
const gasEstimation = await contractClient.simulate(
|
|
5698
|
+
address,
|
|
5699
|
+
[
|
|
5700
|
+
{
|
|
5701
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5702
|
+
value: {
|
|
5703
|
+
sender: address,
|
|
5704
|
+
contract: this.saasAddress,
|
|
5705
|
+
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
5706
|
+
funds
|
|
5707
|
+
}
|
|
5708
|
+
}
|
|
5709
|
+
],
|
|
5710
|
+
""
|
|
5711
|
+
);
|
|
5712
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5713
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5714
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
5715
|
+
Math.round(gasEstimation * multiplier),
|
|
5716
|
+
gasPrice
|
|
5717
|
+
);
|
|
5718
|
+
const grantFee = {
|
|
5719
|
+
amount: calculatedFee.amount,
|
|
5720
|
+
gas: calculatedFee.gas,
|
|
5721
|
+
granter: this.saasAddress
|
|
5722
|
+
};
|
|
5723
|
+
return client.deposit(grantFee, void 0, funds);
|
|
5724
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5725
|
+
const grantFee = {
|
|
5726
|
+
...fee,
|
|
5727
|
+
granter: this.saasAddress
|
|
5728
|
+
};
|
|
5729
|
+
return client.deposit(grantFee, void 0, funds);
|
|
5730
|
+
}
|
|
5731
|
+
return client.deposit(fee, void 0, funds);
|
|
5732
|
+
}
|
|
5733
|
+
async withdrawSaas({
|
|
5734
|
+
signer,
|
|
5735
|
+
amount,
|
|
5736
|
+
gasStation = false,
|
|
5737
|
+
fee = 1.8
|
|
5738
|
+
}) {
|
|
5739
|
+
const client = await createSaasClientBy({
|
|
5740
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5741
|
+
wallet: signer,
|
|
5742
|
+
contractAddress: this.saasAddress
|
|
5743
|
+
});
|
|
5744
|
+
if (gasStation && typeof fee !== "object") {
|
|
5745
|
+
const [{ address }] = await signer.getAccounts();
|
|
5746
|
+
const contractClient = await this.contractClient({ signer });
|
|
5747
|
+
const msg = {
|
|
5748
|
+
withdraw: {
|
|
5749
|
+
amount
|
|
5750
|
+
}
|
|
5751
|
+
};
|
|
5752
|
+
const gasEstimation = await contractClient.simulate(
|
|
5753
|
+
address,
|
|
5754
|
+
[
|
|
5755
|
+
{
|
|
5756
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5757
|
+
value: {
|
|
5758
|
+
sender: address,
|
|
5759
|
+
contract: this.saasAddress,
|
|
5760
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5761
|
+
}
|
|
5762
|
+
}
|
|
5763
|
+
],
|
|
5764
|
+
""
|
|
5765
|
+
);
|
|
5766
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5767
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5768
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(
|
|
5769
|
+
Math.round(gasEstimation * multiplier),
|
|
5770
|
+
gasPrice
|
|
5771
|
+
);
|
|
5772
|
+
const grantFee = {
|
|
5773
|
+
amount: calculatedFee.amount,
|
|
5774
|
+
gas: calculatedFee.gas,
|
|
5775
|
+
granter: this.saasAddress
|
|
5776
|
+
};
|
|
5777
|
+
return client.withdraw({ amount }, grantFee);
|
|
5778
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5779
|
+
const grantFee = {
|
|
5780
|
+
...fee,
|
|
5781
|
+
granter: this.saasAddress
|
|
5782
|
+
};
|
|
5783
|
+
return client.withdraw({ amount }, grantFee);
|
|
5784
|
+
}
|
|
5785
|
+
return client.withdraw({ amount }, fee);
|
|
5036
5786
|
}
|
|
5037
5787
|
async queryRoundInfo({
|
|
5038
5788
|
signer,
|
|
@@ -5087,6 +5837,16 @@ var Contract = class {
|
|
|
5087
5837
|
contractAddress
|
|
5088
5838
|
});
|
|
5089
5839
|
}
|
|
5840
|
+
async saasClient({
|
|
5841
|
+
signer,
|
|
5842
|
+
contractAddress
|
|
5843
|
+
}) {
|
|
5844
|
+
return createSaasClientBy({
|
|
5845
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5846
|
+
wallet: signer,
|
|
5847
|
+
contractAddress
|
|
5848
|
+
});
|
|
5849
|
+
}
|
|
5090
5850
|
async contractClient({ signer }) {
|
|
5091
5851
|
return createContractClientByWallet(this.rpcEndpoint, signer);
|
|
5092
5852
|
}
|
|
@@ -5142,7 +5902,7 @@ var OracleCertificate = class {
|
|
|
5142
5902
|
};
|
|
5143
5903
|
|
|
5144
5904
|
// src/libs/maci/maci.ts
|
|
5145
|
-
var
|
|
5905
|
+
var import_stargate3 = require("@cosmjs/stargate");
|
|
5146
5906
|
var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx.js");
|
|
5147
5907
|
function isErrorResponse(response) {
|
|
5148
5908
|
return typeof response === "object" && response !== null && "error" in response && typeof response.error === "object" && "message" in response.error;
|
|
@@ -5524,7 +6284,8 @@ var MACI = class {
|
|
|
5524
6284
|
selectedOptions,
|
|
5525
6285
|
operatorCoordPubKey,
|
|
5526
6286
|
maciKeypair,
|
|
5527
|
-
gasStation = false
|
|
6287
|
+
gasStation = false,
|
|
6288
|
+
fee = 1.8
|
|
5528
6289
|
}) {
|
|
5529
6290
|
if (maciKeypair === void 0) {
|
|
5530
6291
|
maciKeypair = this.maciKeypair;
|
|
@@ -5605,7 +6366,8 @@ var MACI = class {
|
|
|
5605
6366
|
address,
|
|
5606
6367
|
payload,
|
|
5607
6368
|
contractAddress,
|
|
5608
|
-
gasStation
|
|
6369
|
+
gasStation,
|
|
6370
|
+
fee
|
|
5609
6371
|
});
|
|
5610
6372
|
} catch (error) {
|
|
5611
6373
|
throw Error(`Vote failed! ${error}`);
|
|
@@ -5616,7 +6378,8 @@ var MACI = class {
|
|
|
5616
6378
|
address,
|
|
5617
6379
|
payload,
|
|
5618
6380
|
contractAddress,
|
|
5619
|
-
gasStation
|
|
6381
|
+
gasStation,
|
|
6382
|
+
fee = 1.8
|
|
5620
6383
|
}) {
|
|
5621
6384
|
const msgs = payload.map(
|
|
5622
6385
|
({ msg, encPubkeys }) => ({
|
|
@@ -5642,12 +6405,23 @@ var MACI = class {
|
|
|
5642
6405
|
})
|
|
5643
6406
|
})
|
|
5644
6407
|
);
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
6408
|
+
if (gasStation && typeof fee !== "object") {
|
|
6409
|
+
const gasEstimation = await client.simulate(address, msgs, "");
|
|
6410
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6411
|
+
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6412
|
+
const calculatedFee = (0, import_stargate3.calculateFee)(
|
|
6413
|
+
Math.round(gasEstimation * multiplier),
|
|
6414
|
+
gasPrice
|
|
6415
|
+
);
|
|
6416
|
+
const grantFee = {
|
|
6417
|
+
amount: calculatedFee.amount,
|
|
6418
|
+
gas: calculatedFee.gas,
|
|
6419
|
+
granter: contractAddress
|
|
6420
|
+
};
|
|
6421
|
+
return client.signAndBroadcast(address, msgs, grantFee);
|
|
6422
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5648
6423
|
const grantFee = {
|
|
5649
|
-
|
|
5650
|
-
gas: fee.gas,
|
|
6424
|
+
...fee,
|
|
5651
6425
|
granter: contractAddress
|
|
5652
6426
|
};
|
|
5653
6427
|
return client.signAndBroadcast(address, msgs, grantFee);
|
|
@@ -5660,43 +6434,51 @@ var MACI = class {
|
|
|
5660
6434
|
pubKey,
|
|
5661
6435
|
contractAddress,
|
|
5662
6436
|
gasStation,
|
|
5663
|
-
fee
|
|
6437
|
+
fee = 1.8
|
|
5664
6438
|
}) {
|
|
5665
|
-
const
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
6439
|
+
const msg = {
|
|
6440
|
+
sign_up: {
|
|
6441
|
+
pubkey: {
|
|
6442
|
+
x: pubKey[0].toString(),
|
|
6443
|
+
y: pubKey[1].toString()
|
|
6444
|
+
}
|
|
6445
|
+
}
|
|
6446
|
+
};
|
|
6447
|
+
if (gasStation === true && typeof fee !== "object") {
|
|
6448
|
+
const gasEstimation = await client.simulate(
|
|
5674
6449
|
address,
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
6450
|
+
[
|
|
6451
|
+
{
|
|
6452
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6453
|
+
value: {
|
|
6454
|
+
sender: address,
|
|
6455
|
+
contract: contractAddress,
|
|
6456
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5681
6457
|
}
|
|
5682
6458
|
}
|
|
5683
|
-
|
|
5684
|
-
|
|
6459
|
+
],
|
|
6460
|
+
""
|
|
5685
6461
|
);
|
|
6462
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6463
|
+
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6464
|
+
const calculatedFee = (0, import_stargate3.calculateFee)(
|
|
6465
|
+
Math.round(gasEstimation * multiplier),
|
|
6466
|
+
gasPrice
|
|
6467
|
+
);
|
|
6468
|
+
const grantFee = {
|
|
6469
|
+
amount: calculatedFee.amount,
|
|
6470
|
+
gas: calculatedFee.gas,
|
|
6471
|
+
granter: contractAddress
|
|
6472
|
+
};
|
|
6473
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
6474
|
+
} else if (gasStation === true && typeof fee === "object") {
|
|
6475
|
+
const grantFee = {
|
|
6476
|
+
...fee,
|
|
6477
|
+
granter: contractAddress
|
|
6478
|
+
};
|
|
6479
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
5686
6480
|
}
|
|
5687
|
-
return client.execute(
|
|
5688
|
-
address,
|
|
5689
|
-
contractAddress,
|
|
5690
|
-
{
|
|
5691
|
-
sign_up: {
|
|
5692
|
-
pubkey: {
|
|
5693
|
-
x: pubKey[0].toString(),
|
|
5694
|
-
y: pubKey[1].toString()
|
|
5695
|
-
}
|
|
5696
|
-
}
|
|
5697
|
-
},
|
|
5698
|
-
fee
|
|
5699
|
-
);
|
|
6481
|
+
return client.execute(address, contractAddress, msg, fee);
|
|
5700
6482
|
}
|
|
5701
6483
|
async signupOracle({
|
|
5702
6484
|
client,
|
|
@@ -5705,29 +6487,53 @@ var MACI = class {
|
|
|
5705
6487
|
contractAddress,
|
|
5706
6488
|
oracleCertificate,
|
|
5707
6489
|
gasStation,
|
|
5708
|
-
fee
|
|
6490
|
+
fee = 1.8
|
|
5709
6491
|
}) {
|
|
5710
|
-
const
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
6492
|
+
const msg = {
|
|
6493
|
+
sign_up: {
|
|
6494
|
+
pubkey: {
|
|
6495
|
+
x: pubKey[0].toString(),
|
|
6496
|
+
y: pubKey[1].toString()
|
|
6497
|
+
},
|
|
6498
|
+
amount: oracleCertificate.amount,
|
|
6499
|
+
certificate: oracleCertificate.signature
|
|
6500
|
+
}
|
|
6501
|
+
};
|
|
6502
|
+
if (gasStation === true && typeof fee !== "object") {
|
|
6503
|
+
const gasEstimation = await client.simulate(
|
|
6504
|
+
address,
|
|
6505
|
+
[
|
|
6506
|
+
{
|
|
6507
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6508
|
+
value: {
|
|
6509
|
+
sender: address,
|
|
6510
|
+
contract: contractAddress,
|
|
6511
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
6512
|
+
}
|
|
6513
|
+
}
|
|
6514
|
+
],
|
|
6515
|
+
""
|
|
6516
|
+
);
|
|
6517
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6518
|
+
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6519
|
+
const calculatedFee = (0, import_stargate3.calculateFee)(
|
|
6520
|
+
Math.round(gasEstimation * multiplier),
|
|
6521
|
+
gasPrice
|
|
6522
|
+
);
|
|
6523
|
+
const grantFee = {
|
|
6524
|
+
amount: calculatedFee.amount,
|
|
6525
|
+
gas: calculatedFee.gas,
|
|
5728
6526
|
granter: contractAddress
|
|
5729
|
-
}
|
|
5730
|
-
|
|
6527
|
+
};
|
|
6528
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
6529
|
+
} else if (gasStation === true && typeof fee === "object") {
|
|
6530
|
+
const grantFee = {
|
|
6531
|
+
...fee,
|
|
6532
|
+
granter: contractAddress
|
|
6533
|
+
};
|
|
6534
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
6535
|
+
}
|
|
6536
|
+
return client.execute(address, contractAddress, msg, fee);
|
|
5731
6537
|
}
|
|
5732
6538
|
async deactivate({
|
|
5733
6539
|
signer,
|
|
@@ -5735,7 +6541,7 @@ var MACI = class {
|
|
|
5735
6541
|
maciKeypair,
|
|
5736
6542
|
contractAddress,
|
|
5737
6543
|
gasStation,
|
|
5738
|
-
fee
|
|
6544
|
+
fee = 1.8
|
|
5739
6545
|
}) {
|
|
5740
6546
|
try {
|
|
5741
6547
|
address = address || (await signer.getAccounts())[0].address;
|
|
@@ -5763,28 +6569,62 @@ var MACI = class {
|
|
|
5763
6569
|
[[0, 0]]
|
|
5764
6570
|
);
|
|
5765
6571
|
const { msg, encPubkeys } = payload[0];
|
|
5766
|
-
const
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
x: encPubkeys[0],
|
|
5775
|
-
y: encPubkeys[1]
|
|
5776
|
-
},
|
|
5777
|
-
message: {
|
|
5778
|
-
data: msg
|
|
5779
|
-
}
|
|
6572
|
+
const deactivateMsg = stringizing({
|
|
6573
|
+
publish_deactivate_message: {
|
|
6574
|
+
enc_pub_key: {
|
|
6575
|
+
x: encPubkeys[0],
|
|
6576
|
+
y: encPubkeys[1]
|
|
6577
|
+
},
|
|
6578
|
+
message: {
|
|
6579
|
+
data: msg
|
|
5780
6580
|
}
|
|
5781
|
-
}
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
6581
|
+
}
|
|
6582
|
+
});
|
|
6583
|
+
if (gasStation === true && typeof fee !== "object") {
|
|
6584
|
+
const gasEstimation = await client.simulate(
|
|
6585
|
+
address,
|
|
6586
|
+
[
|
|
6587
|
+
{
|
|
6588
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6589
|
+
value: {
|
|
6590
|
+
sender: address,
|
|
6591
|
+
contract: contractAddress,
|
|
6592
|
+
msg: new TextEncoder().encode(JSON.stringify(deactivateMsg))
|
|
6593
|
+
}
|
|
6594
|
+
}
|
|
6595
|
+
],
|
|
6596
|
+
""
|
|
6597
|
+
);
|
|
6598
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6599
|
+
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6600
|
+
const calculatedFee = (0, import_stargate3.calculateFee)(
|
|
6601
|
+
Math.round(gasEstimation * multiplier),
|
|
6602
|
+
gasPrice
|
|
6603
|
+
);
|
|
6604
|
+
const grantFee = {
|
|
6605
|
+
amount: calculatedFee.amount,
|
|
6606
|
+
gas: calculatedFee.gas,
|
|
5785
6607
|
granter: contractAddress
|
|
5786
|
-
}
|
|
5787
|
-
|
|
6608
|
+
};
|
|
6609
|
+
return client.execute(
|
|
6610
|
+
address,
|
|
6611
|
+
contractAddress,
|
|
6612
|
+
deactivateMsg,
|
|
6613
|
+
grantFee
|
|
6614
|
+
);
|
|
6615
|
+
} else if (gasStation === true && typeof fee === "object") {
|
|
6616
|
+
const grantFee = {
|
|
6617
|
+
...fee,
|
|
6618
|
+
granter: contractAddress
|
|
6619
|
+
};
|
|
6620
|
+
return client.execute(
|
|
6621
|
+
address,
|
|
6622
|
+
contractAddress,
|
|
6623
|
+
deactivateMsg,
|
|
6624
|
+
grantFee
|
|
6625
|
+
);
|
|
6626
|
+
}
|
|
6627
|
+
return client.execute(address, contractAddress, deactivateMsg, fee);
|
|
5788
6628
|
} catch (error) {
|
|
5789
6629
|
throw Error(`Submit deactivate failed! ${error}`);
|
|
5790
6630
|
}
|
|
@@ -5995,8 +6835,10 @@ var MaciClient2 = class {
|
|
|
5995
6835
|
restEndpoint,
|
|
5996
6836
|
apiEndpoint,
|
|
5997
6837
|
registryAddress,
|
|
6838
|
+
saasAddress,
|
|
5998
6839
|
maciCodeId,
|
|
5999
6840
|
oracleCodeId,
|
|
6841
|
+
saasOracleCodeId,
|
|
6000
6842
|
customFetch,
|
|
6001
6843
|
defaultOptions,
|
|
6002
6844
|
feegrantOperator,
|
|
@@ -6012,8 +6854,10 @@ var MaciClient2 = class {
|
|
|
6012
6854
|
this.apiEndpoint = apiEndpoint || defaultParams.apiEndpoint;
|
|
6013
6855
|
this.certificateApiEndpoint = certificateApiEndpoint || defaultParams.certificateApiEndpoint;
|
|
6014
6856
|
this.registryAddress = registryAddress || defaultParams.registryAddress;
|
|
6857
|
+
this.saasAddress = saasAddress || defaultParams.saasAddress;
|
|
6015
6858
|
this.maciCodeId = maciCodeId || defaultParams.maciCodeId;
|
|
6016
6859
|
this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
|
|
6860
|
+
this.saasOracleCodeId = saasOracleCodeId || defaultParams.saasCodeId;
|
|
6017
6861
|
this.feegrantOperator = feegrantOperator || defaultParams.oracleFeegrantOperator;
|
|
6018
6862
|
this.whitelistBackendPubkey = whitelistBackendPubkey || defaultParams.oracleWhitelistBackendPubkey;
|
|
6019
6863
|
this.maciKeypair = maciKeypair ?? genKeypair();
|
|
@@ -6033,8 +6877,10 @@ var MaciClient2 = class {
|
|
|
6033
6877
|
network: this.network,
|
|
6034
6878
|
rpcEndpoint: this.rpcEndpoint,
|
|
6035
6879
|
registryAddress: this.registryAddress,
|
|
6880
|
+
saasAddress: this.saasAddress,
|
|
6036
6881
|
maciCodeId: this.maciCodeId,
|
|
6037
6882
|
oracleCodeId: this.oracleCodeId,
|
|
6883
|
+
saasOracleCodeId: this.saasOracleCodeId,
|
|
6038
6884
|
feegrantOperator: this.feegrantOperator,
|
|
6039
6885
|
whitelistBackendPubkey: this.whitelistBackendPubkey
|
|
6040
6886
|
});
|
|
@@ -6123,6 +6969,12 @@ var MaciClient2 = class {
|
|
|
6123
6969
|
...params
|
|
6124
6970
|
});
|
|
6125
6971
|
}
|
|
6972
|
+
async createSaasOracleMaciRound(params) {
|
|
6973
|
+
return await this.contract.createSaasOracleMaciRound({
|
|
6974
|
+
signer: this.getSigner(params.signer),
|
|
6975
|
+
...params
|
|
6976
|
+
});
|
|
6977
|
+
}
|
|
6126
6978
|
async genKeypairFromSign({
|
|
6127
6979
|
signer,
|
|
6128
6980
|
address
|