@dorafactory/maci-sdk 0.1.1 → 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 +992 -140
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +992 -140
- 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/maci/maci.ts +176 -88
- package/src/maci.ts +16 -0
- package/src/types/index.ts +4 -0
package/dist/index.mjs
CHANGED
|
@@ -337,13 +337,16 @@ function getDefaultParams(network = "mainnet") {
|
|
|
337
337
|
apiEndpoint: "https://vota-api.dorafactory.org",
|
|
338
338
|
certificateApiEndpoint: "https://vota-certificate-api.dorafactory.org/api/v1",
|
|
339
339
|
registryAddress: "dora1smg5qp5trjdkcekdjssqpjehdjf6n4cjss0clyvqcud3t3u3948s8rmgg4",
|
|
340
|
+
saasAddress: "dora1dgnszrwnwxgr5djprrr6w4q45z8s3ghsew869g6tlp4ruqah39nqnemjya",
|
|
340
341
|
maciCodeId: 106,
|
|
341
342
|
// oracleCodeId: 116,// 9-4-3-625
|
|
342
343
|
oracleCodeId: 119,
|
|
343
344
|
// 6-3-3-125
|
|
345
|
+
saasCodeId: 152,
|
|
344
346
|
oracleWhitelistBackendPubkey: "A61YtCv2ibMZmDeM02nEElil8wlHx1tLKogBk5dPgf/Q",
|
|
345
347
|
oracleFeegrantOperator: "dora16s9tljk8dy9ae335yvyzlm8gvkypx9228q8pq8",
|
|
346
|
-
oracleCodeIds: ["101", "116", "117", "119"]
|
|
348
|
+
oracleCodeIds: ["101", "116", "117", "119"],
|
|
349
|
+
saasCodeIds: ["152"]
|
|
347
350
|
};
|
|
348
351
|
case "testnet":
|
|
349
352
|
return {
|
|
@@ -354,13 +357,16 @@ function getDefaultParams(network = "mainnet") {
|
|
|
354
357
|
apiEndpoint: "https://vota-testnet-api.dorafactory.org",
|
|
355
358
|
certificateApiEndpoint: "https://vota-testnet-certificate-api.dorafactory.org/api/v1",
|
|
356
359
|
registryAddress: "dora13c8aecstyxrhax9znvvh5zey89edrmd2k5va57pxvpe3fxtfsfeqlhsjnd",
|
|
357
|
-
|
|
360
|
+
saasAddress: "dora1dgnszrwnwxgr5djprrr6w4q45z8s3ghsew869g6tlp4ruqah39nqnemjya",
|
|
361
|
+
maciCodeId: 134,
|
|
358
362
|
// oracleCodeId: 113, // 9-4-3-625
|
|
359
363
|
oracleCodeId: 123,
|
|
360
364
|
// 6-3-3-125
|
|
365
|
+
saasCodeId: 152,
|
|
361
366
|
oracleWhitelistBackendPubkey: "AoYo/zENN/JquagPdG0/NMbWBBYxOM8BVN677mBXJKJQ",
|
|
362
367
|
oracleFeegrantOperator: "dora1xp0twdzsdeq4qg3c64v66552deax8zmvq4zw78",
|
|
363
|
-
oracleCodeIds: ["102", "105", "108", "110", "113", "115", "123"]
|
|
368
|
+
oracleCodeIds: ["102", "105", "108", "110", "113", "115", "123"],
|
|
369
|
+
saasCodeIds: ["152"]
|
|
364
370
|
};
|
|
365
371
|
}
|
|
366
372
|
}
|
|
@@ -4200,11 +4206,291 @@ var OracleMaciClient = class extends OracleMaciQueryClient {
|
|
|
4200
4206
|
}
|
|
4201
4207
|
};
|
|
4202
4208
|
|
|
4209
|
+
// src/libs/contract/ts/Saas.client.ts
|
|
4210
|
+
var SaasQueryClient = class {
|
|
4211
|
+
constructor(client, contractAddress) {
|
|
4212
|
+
this.config = async () => {
|
|
4213
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4214
|
+
config: {}
|
|
4215
|
+
});
|
|
4216
|
+
};
|
|
4217
|
+
this.operators = async () => {
|
|
4218
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4219
|
+
operators: {}
|
|
4220
|
+
});
|
|
4221
|
+
};
|
|
4222
|
+
this.isOperator = async ({ address }) => {
|
|
4223
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4224
|
+
is_operator: {
|
|
4225
|
+
address
|
|
4226
|
+
}
|
|
4227
|
+
});
|
|
4228
|
+
};
|
|
4229
|
+
this.balance = async () => {
|
|
4230
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4231
|
+
balance: {}
|
|
4232
|
+
});
|
|
4233
|
+
};
|
|
4234
|
+
this.maciContracts = async ({
|
|
4235
|
+
limit,
|
|
4236
|
+
startAfter
|
|
4237
|
+
}) => {
|
|
4238
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4239
|
+
maci_contracts: {
|
|
4240
|
+
limit,
|
|
4241
|
+
start_after: startAfter
|
|
4242
|
+
}
|
|
4243
|
+
});
|
|
4244
|
+
};
|
|
4245
|
+
this.operatorMaciContracts = async ({
|
|
4246
|
+
limit,
|
|
4247
|
+
operator,
|
|
4248
|
+
startAfter
|
|
4249
|
+
}) => {
|
|
4250
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4251
|
+
operator_maci_contracts: {
|
|
4252
|
+
limit,
|
|
4253
|
+
operator,
|
|
4254
|
+
start_after: startAfter
|
|
4255
|
+
}
|
|
4256
|
+
});
|
|
4257
|
+
};
|
|
4258
|
+
this.maciContract = async ({
|
|
4259
|
+
contractId
|
|
4260
|
+
}) => {
|
|
4261
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4262
|
+
maci_contract: {
|
|
4263
|
+
contract_id: contractId
|
|
4264
|
+
}
|
|
4265
|
+
});
|
|
4266
|
+
};
|
|
4267
|
+
this.oracleMaciCodeId = async () => {
|
|
4268
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
4269
|
+
oracle_maci_code_id: {}
|
|
4270
|
+
});
|
|
4271
|
+
};
|
|
4272
|
+
this.client = client;
|
|
4273
|
+
this.contractAddress = contractAddress;
|
|
4274
|
+
this.config = this.config.bind(this);
|
|
4275
|
+
this.operators = this.operators.bind(this);
|
|
4276
|
+
this.isOperator = this.isOperator.bind(this);
|
|
4277
|
+
this.balance = this.balance.bind(this);
|
|
4278
|
+
this.maciContracts = this.maciContracts.bind(this);
|
|
4279
|
+
this.operatorMaciContracts = this.operatorMaciContracts.bind(this);
|
|
4280
|
+
this.maciContract = this.maciContract.bind(this);
|
|
4281
|
+
this.oracleMaciCodeId = this.oracleMaciCodeId.bind(this);
|
|
4282
|
+
}
|
|
4283
|
+
};
|
|
4284
|
+
var SaasClient = class extends SaasQueryClient {
|
|
4285
|
+
constructor(client, sender, contractAddress) {
|
|
4286
|
+
super(client, contractAddress);
|
|
4287
|
+
this.updateConfig = async ({
|
|
4288
|
+
admin,
|
|
4289
|
+
denom,
|
|
4290
|
+
registryContract
|
|
4291
|
+
}, fee = "auto", memo, _funds) => {
|
|
4292
|
+
return await this.client.execute(
|
|
4293
|
+
this.sender,
|
|
4294
|
+
this.contractAddress,
|
|
4295
|
+
{
|
|
4296
|
+
update_config: {
|
|
4297
|
+
admin,
|
|
4298
|
+
denom,
|
|
4299
|
+
registry_contract: registryContract
|
|
4300
|
+
}
|
|
4301
|
+
},
|
|
4302
|
+
fee,
|
|
4303
|
+
memo,
|
|
4304
|
+
_funds
|
|
4305
|
+
);
|
|
4306
|
+
};
|
|
4307
|
+
this.addOperator = async ({
|
|
4308
|
+
operator
|
|
4309
|
+
}, fee = "auto", memo, _funds) => {
|
|
4310
|
+
return await this.client.execute(
|
|
4311
|
+
this.sender,
|
|
4312
|
+
this.contractAddress,
|
|
4313
|
+
{
|
|
4314
|
+
add_operator: {
|
|
4315
|
+
operator
|
|
4316
|
+
}
|
|
4317
|
+
},
|
|
4318
|
+
fee,
|
|
4319
|
+
memo,
|
|
4320
|
+
_funds
|
|
4321
|
+
);
|
|
4322
|
+
};
|
|
4323
|
+
this.removeOperator = async ({
|
|
4324
|
+
operator
|
|
4325
|
+
}, fee = "auto", memo, _funds) => {
|
|
4326
|
+
return await this.client.execute(
|
|
4327
|
+
this.sender,
|
|
4328
|
+
this.contractAddress,
|
|
4329
|
+
{
|
|
4330
|
+
remove_operator: {
|
|
4331
|
+
operator
|
|
4332
|
+
}
|
|
4333
|
+
},
|
|
4334
|
+
fee,
|
|
4335
|
+
memo,
|
|
4336
|
+
_funds
|
|
4337
|
+
);
|
|
4338
|
+
};
|
|
4339
|
+
this.deposit = async (fee = "auto", memo, _funds) => {
|
|
4340
|
+
return await this.client.execute(
|
|
4341
|
+
this.sender,
|
|
4342
|
+
this.contractAddress,
|
|
4343
|
+
{
|
|
4344
|
+
deposit: {}
|
|
4345
|
+
},
|
|
4346
|
+
fee,
|
|
4347
|
+
memo,
|
|
4348
|
+
_funds
|
|
4349
|
+
);
|
|
4350
|
+
};
|
|
4351
|
+
this.withdraw = async ({
|
|
4352
|
+
amount,
|
|
4353
|
+
recipient
|
|
4354
|
+
}, fee = "auto", memo, _funds) => {
|
|
4355
|
+
return await this.client.execute(
|
|
4356
|
+
this.sender,
|
|
4357
|
+
this.contractAddress,
|
|
4358
|
+
{
|
|
4359
|
+
withdraw: {
|
|
4360
|
+
amount,
|
|
4361
|
+
recipient
|
|
4362
|
+
}
|
|
4363
|
+
},
|
|
4364
|
+
fee,
|
|
4365
|
+
memo,
|
|
4366
|
+
_funds
|
|
4367
|
+
);
|
|
4368
|
+
};
|
|
4369
|
+
this.updateOracleMaciCodeId = async ({
|
|
4370
|
+
codeId
|
|
4371
|
+
}, fee = "auto", memo, _funds) => {
|
|
4372
|
+
return await this.client.execute(
|
|
4373
|
+
this.sender,
|
|
4374
|
+
this.contractAddress,
|
|
4375
|
+
{
|
|
4376
|
+
update_oracle_maci_code_id: {
|
|
4377
|
+
code_id: codeId
|
|
4378
|
+
}
|
|
4379
|
+
},
|
|
4380
|
+
fee,
|
|
4381
|
+
memo,
|
|
4382
|
+
_funds
|
|
4383
|
+
);
|
|
4384
|
+
};
|
|
4385
|
+
this.createOracleMaciRound = async ({
|
|
4386
|
+
certificationSystem,
|
|
4387
|
+
circuitType,
|
|
4388
|
+
coordinator,
|
|
4389
|
+
endTime,
|
|
4390
|
+
maxVoters,
|
|
4391
|
+
roundInfo,
|
|
4392
|
+
startTime,
|
|
4393
|
+
voteOptionMap,
|
|
4394
|
+
whitelistBackendPubkey
|
|
4395
|
+
}, fee = "auto", memo, _funds) => {
|
|
4396
|
+
return await this.client.execute(
|
|
4397
|
+
this.sender,
|
|
4398
|
+
this.contractAddress,
|
|
4399
|
+
{
|
|
4400
|
+
create_oracle_maci_round: {
|
|
4401
|
+
certification_system: certificationSystem,
|
|
4402
|
+
circuit_type: circuitType,
|
|
4403
|
+
coordinator,
|
|
4404
|
+
end_time: endTime,
|
|
4405
|
+
max_voters: maxVoters.toString(),
|
|
4406
|
+
round_info: roundInfo,
|
|
4407
|
+
start_time: startTime,
|
|
4408
|
+
vote_option_map: voteOptionMap,
|
|
4409
|
+
whitelist_backend_pubkey: whitelistBackendPubkey
|
|
4410
|
+
}
|
|
4411
|
+
},
|
|
4412
|
+
fee,
|
|
4413
|
+
memo,
|
|
4414
|
+
_funds
|
|
4415
|
+
);
|
|
4416
|
+
};
|
|
4417
|
+
this.setRoundInfo = async ({
|
|
4418
|
+
contractAddr,
|
|
4419
|
+
roundInfo
|
|
4420
|
+
}, fee = "auto", memo, _funds) => {
|
|
4421
|
+
return await this.client.execute(
|
|
4422
|
+
this.sender,
|
|
4423
|
+
this.contractAddress,
|
|
4424
|
+
{
|
|
4425
|
+
set_round_info: {
|
|
4426
|
+
contract_addr: contractAddr,
|
|
4427
|
+
round_info: roundInfo
|
|
4428
|
+
}
|
|
4429
|
+
},
|
|
4430
|
+
fee,
|
|
4431
|
+
memo,
|
|
4432
|
+
_funds
|
|
4433
|
+
);
|
|
4434
|
+
};
|
|
4435
|
+
this.setVoteOptionsMap = async ({
|
|
4436
|
+
contractAddr,
|
|
4437
|
+
voteOptionMap
|
|
4438
|
+
}, fee = "auto", memo, _funds) => {
|
|
4439
|
+
return await this.client.execute(
|
|
4440
|
+
this.sender,
|
|
4441
|
+
this.contractAddress,
|
|
4442
|
+
{
|
|
4443
|
+
set_vote_options_map: {
|
|
4444
|
+
contract_addr: contractAddr,
|
|
4445
|
+
vote_option_map: voteOptionMap
|
|
4446
|
+
}
|
|
4447
|
+
},
|
|
4448
|
+
fee,
|
|
4449
|
+
memo,
|
|
4450
|
+
_funds
|
|
4451
|
+
);
|
|
4452
|
+
};
|
|
4453
|
+
this.grantToVoter = async ({
|
|
4454
|
+
baseAmount,
|
|
4455
|
+
contractAddr,
|
|
4456
|
+
grantee
|
|
4457
|
+
}, fee = "auto", memo, _funds) => {
|
|
4458
|
+
return await this.client.execute(
|
|
4459
|
+
this.sender,
|
|
4460
|
+
this.contractAddress,
|
|
4461
|
+
{
|
|
4462
|
+
grant_to_voter: {
|
|
4463
|
+
base_amount: baseAmount,
|
|
4464
|
+
contract_addr: contractAddr,
|
|
4465
|
+
grantee
|
|
4466
|
+
}
|
|
4467
|
+
},
|
|
4468
|
+
fee,
|
|
4469
|
+
memo,
|
|
4470
|
+
_funds
|
|
4471
|
+
);
|
|
4472
|
+
};
|
|
4473
|
+
this.client = client;
|
|
4474
|
+
this.sender = sender;
|
|
4475
|
+
this.contractAddress = contractAddress;
|
|
4476
|
+
this.updateConfig = this.updateConfig.bind(this);
|
|
4477
|
+
this.addOperator = this.addOperator.bind(this);
|
|
4478
|
+
this.removeOperator = this.removeOperator.bind(this);
|
|
4479
|
+
this.deposit = this.deposit.bind(this);
|
|
4480
|
+
this.withdraw = this.withdraw.bind(this);
|
|
4481
|
+
this.updateOracleMaciCodeId = this.updateOracleMaciCodeId.bind(this);
|
|
4482
|
+
this.createOracleMaciRound = this.createOracleMaciRound.bind(this);
|
|
4483
|
+
this.setRoundInfo = this.setRoundInfo.bind(this);
|
|
4484
|
+
this.setVoteOptionsMap = this.setVoteOptionsMap.bind(this);
|
|
4485
|
+
this.grantToVoter = this.grantToVoter.bind(this);
|
|
4486
|
+
}
|
|
4487
|
+
};
|
|
4488
|
+
|
|
4203
4489
|
// src/libs/contract/config.ts
|
|
4204
4490
|
var defaultSigningClientOptions = {
|
|
4205
4491
|
broadcastPollIntervalMs: 8e3,
|
|
4206
4492
|
broadcastTimeoutMs: 64e3,
|
|
4207
|
-
gasPrice: GasPrice.fromString("
|
|
4493
|
+
gasPrice: GasPrice.fromString("10000000000peaka")
|
|
4208
4494
|
};
|
|
4209
4495
|
async function createMaciClientBy({
|
|
4210
4496
|
rpcEndpoint,
|
|
@@ -4242,6 +4528,18 @@ async function createRegistryClientBy({
|
|
|
4242
4528
|
const [{ address }] = await wallet.getAccounts();
|
|
4243
4529
|
return new RegistryClient(signingCosmWasmClient, address, contractAddress);
|
|
4244
4530
|
}
|
|
4531
|
+
async function createSaasClientBy({
|
|
4532
|
+
rpcEndpoint,
|
|
4533
|
+
wallet,
|
|
4534
|
+
contractAddress
|
|
4535
|
+
}) {
|
|
4536
|
+
const signingCosmWasmClient = await createContractClientByWallet(
|
|
4537
|
+
rpcEndpoint,
|
|
4538
|
+
wallet
|
|
4539
|
+
);
|
|
4540
|
+
const [{ address }] = await wallet.getAccounts();
|
|
4541
|
+
return new SaasClient(signingCosmWasmClient, address, contractAddress);
|
|
4542
|
+
}
|
|
4245
4543
|
async function createOracleMaciClientBy({
|
|
4246
4544
|
rpcEndpoint,
|
|
4247
4545
|
wallet,
|
|
@@ -4744,21 +5042,26 @@ function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
|
|
|
4744
5042
|
}
|
|
4745
5043
|
|
|
4746
5044
|
// src/libs/contract/contract.ts
|
|
5045
|
+
import { GasPrice as GasPrice2, calculateFee } from "@cosmjs/stargate";
|
|
4747
5046
|
var Contract = class {
|
|
4748
5047
|
constructor({
|
|
4749
5048
|
network,
|
|
4750
5049
|
rpcEndpoint,
|
|
4751
5050
|
registryAddress,
|
|
5051
|
+
saasAddress,
|
|
4752
5052
|
maciCodeId,
|
|
4753
5053
|
oracleCodeId,
|
|
5054
|
+
saasOracleCodeId,
|
|
4754
5055
|
feegrantOperator,
|
|
4755
5056
|
whitelistBackendPubkey
|
|
4756
5057
|
}) {
|
|
4757
5058
|
this.network = network;
|
|
4758
5059
|
this.rpcEndpoint = rpcEndpoint;
|
|
4759
5060
|
this.registryAddress = registryAddress;
|
|
5061
|
+
this.saasAddress = saasAddress;
|
|
4760
5062
|
this.maciCodeId = maciCodeId;
|
|
4761
5063
|
this.oracleCodeId = oracleCodeId;
|
|
5064
|
+
this.saasOracleCodeId = saasOracleCodeId;
|
|
4762
5065
|
this.feegrantOperator = feegrantOperator;
|
|
4763
5066
|
this.whitelistBackendPubkey = whitelistBackendPubkey;
|
|
4764
5067
|
}
|
|
@@ -4892,66 +5195,513 @@ var Contract = class {
|
|
|
4892
5195
|
certification_system: maciCertSystem,
|
|
4893
5196
|
qtr_lib: QTR_LIB
|
|
4894
5197
|
},
|
|
4895
|
-
`[MACI] ${title}`,
|
|
5198
|
+
`[MACI] ${title}`,
|
|
5199
|
+
fee
|
|
5200
|
+
);
|
|
5201
|
+
return instantiateResponse;
|
|
5202
|
+
}
|
|
5203
|
+
async createOracleMaciRound({
|
|
5204
|
+
signer,
|
|
5205
|
+
operatorPubkey,
|
|
5206
|
+
startVoting,
|
|
5207
|
+
endVoting,
|
|
5208
|
+
title,
|
|
5209
|
+
description,
|
|
5210
|
+
link,
|
|
5211
|
+
maxVoter,
|
|
5212
|
+
voteOptionMap,
|
|
5213
|
+
circuitType,
|
|
5214
|
+
whitelistEcosystem,
|
|
5215
|
+
whitelistSnapshotHeight,
|
|
5216
|
+
whitelistVotingPowerArgs,
|
|
5217
|
+
whitelistBackendPubkey,
|
|
5218
|
+
feegrantOperator,
|
|
5219
|
+
fee = "auto"
|
|
5220
|
+
}) {
|
|
5221
|
+
const start_time = (startVoting.getTime() * 1e6).toString();
|
|
5222
|
+
const end_time = (endVoting.getTime() * 1e6).toString();
|
|
5223
|
+
const [{ address }] = await signer.getAccounts();
|
|
5224
|
+
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
5225
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
5226
|
+
BigInt(operatorPubkey)
|
|
5227
|
+
);
|
|
5228
|
+
const { maciVoteType, maciCertSystem } = getContractParams(
|
|
5229
|
+
"2" /* ORACLE_MACI */,
|
|
5230
|
+
circuitType,
|
|
5231
|
+
"groth16" /* GROTH16 */,
|
|
5232
|
+
0,
|
|
5233
|
+
0
|
|
5234
|
+
);
|
|
5235
|
+
const instantiateResponse = await client.instantiate(
|
|
5236
|
+
address,
|
|
5237
|
+
this.oracleCodeId,
|
|
5238
|
+
{
|
|
5239
|
+
max_voters: maxVoter.toString(),
|
|
5240
|
+
round_info: { title, description: description || "", link: link || "" },
|
|
5241
|
+
voting_time: {
|
|
5242
|
+
start_time,
|
|
5243
|
+
end_time
|
|
5244
|
+
},
|
|
5245
|
+
coordinator: {
|
|
5246
|
+
x: operatorPubkeyX.toString(),
|
|
5247
|
+
y: operatorPubkeyY.toString()
|
|
5248
|
+
},
|
|
5249
|
+
vote_option_map: voteOptionMap,
|
|
5250
|
+
whitelist_backend_pubkey: whitelistBackendPubkey ? whitelistBackendPubkey : this.whitelistBackendPubkey,
|
|
5251
|
+
whitelist_ecosystem: whitelistEcosystem,
|
|
5252
|
+
whitelist_snapshot_height: whitelistSnapshotHeight,
|
|
5253
|
+
whitelist_voting_power_args: whitelistVotingPowerArgs,
|
|
5254
|
+
circuit_type: maciVoteType,
|
|
5255
|
+
certification_system: maciCertSystem,
|
|
5256
|
+
feegrant_operator: feegrantOperator ? feegrantOperator : this.feegrantOperator
|
|
5257
|
+
},
|
|
5258
|
+
`[Oracle MACI] ${title}`,
|
|
5259
|
+
fee
|
|
5260
|
+
);
|
|
5261
|
+
return instantiateResponse;
|
|
5262
|
+
}
|
|
5263
|
+
async createSaasOracleMaciRound({
|
|
5264
|
+
signer,
|
|
5265
|
+
operatorPubkey,
|
|
5266
|
+
startVoting,
|
|
5267
|
+
endVoting,
|
|
5268
|
+
title,
|
|
5269
|
+
description,
|
|
5270
|
+
link,
|
|
5271
|
+
maxVoter,
|
|
5272
|
+
voteOptionMap,
|
|
5273
|
+
whitelistBackendPubkey
|
|
5274
|
+
}) {
|
|
5275
|
+
const startTime = (startVoting.getTime() * 1e6).toString();
|
|
5276
|
+
const endTime = (endVoting.getTime() * 1e6).toString();
|
|
5277
|
+
const client = await createSaasClientBy({
|
|
5278
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5279
|
+
wallet: signer,
|
|
5280
|
+
contractAddress: this.saasAddress
|
|
5281
|
+
});
|
|
5282
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
5283
|
+
BigInt(operatorPubkey)
|
|
5284
|
+
);
|
|
5285
|
+
const createResponse = await client.createOracleMaciRound({
|
|
5286
|
+
certificationSystem: "0",
|
|
5287
|
+
circuitType: "0",
|
|
5288
|
+
coordinator: {
|
|
5289
|
+
x: operatorPubkeyX.toString(),
|
|
5290
|
+
y: operatorPubkeyY.toString()
|
|
5291
|
+
},
|
|
5292
|
+
maxVoters: maxVoter,
|
|
5293
|
+
roundInfo: {
|
|
5294
|
+
title,
|
|
5295
|
+
description: description || "",
|
|
5296
|
+
link: link || ""
|
|
5297
|
+
},
|
|
5298
|
+
startTime,
|
|
5299
|
+
endTime,
|
|
5300
|
+
voteOptionMap,
|
|
5301
|
+
whitelistBackendPubkey: whitelistBackendPubkey || this.whitelistBackendPubkey
|
|
5302
|
+
});
|
|
5303
|
+
let contractAddress = "";
|
|
5304
|
+
createResponse.events.map((event) => {
|
|
5305
|
+
if (event.type === "wasm") {
|
|
5306
|
+
let actionEvent = event.attributes.find(
|
|
5307
|
+
(attr) => attr.key === "action"
|
|
5308
|
+
);
|
|
5309
|
+
if (actionEvent.value === "created_oracle_maci_round") {
|
|
5310
|
+
contractAddress = event.attributes.find((attr) => attr.key === "round_addr").value.toString();
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5313
|
+
});
|
|
5314
|
+
return {
|
|
5315
|
+
...createResponse,
|
|
5316
|
+
contractAddress
|
|
5317
|
+
};
|
|
5318
|
+
}
|
|
5319
|
+
async setSaasOracleMaciRoundInfo({
|
|
5320
|
+
signer,
|
|
5321
|
+
contractAddress,
|
|
5322
|
+
title,
|
|
5323
|
+
description,
|
|
5324
|
+
link,
|
|
5325
|
+
gasStation = false,
|
|
5326
|
+
fee = 1.8
|
|
5327
|
+
}) {
|
|
5328
|
+
const client = await createSaasClientBy({
|
|
5329
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5330
|
+
wallet: signer,
|
|
5331
|
+
contractAddress: this.saasAddress
|
|
5332
|
+
});
|
|
5333
|
+
const roundInfo = {
|
|
5334
|
+
title,
|
|
5335
|
+
description,
|
|
5336
|
+
link
|
|
5337
|
+
};
|
|
5338
|
+
if (gasStation && typeof fee !== "object") {
|
|
5339
|
+
const [{ address }] = await signer.getAccounts();
|
|
5340
|
+
const contractClient = await this.contractClient({ signer });
|
|
5341
|
+
const msg = {
|
|
5342
|
+
set_round_info: {
|
|
5343
|
+
contract_addr: contractAddress,
|
|
5344
|
+
round_info: roundInfo
|
|
5345
|
+
}
|
|
5346
|
+
};
|
|
5347
|
+
const gasEstimation = await contractClient.simulate(
|
|
5348
|
+
address,
|
|
5349
|
+
[
|
|
5350
|
+
{
|
|
5351
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5352
|
+
value: {
|
|
5353
|
+
sender: address,
|
|
5354
|
+
contract: this.saasAddress,
|
|
5355
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5356
|
+
}
|
|
5357
|
+
}
|
|
5358
|
+
],
|
|
5359
|
+
""
|
|
5360
|
+
);
|
|
5361
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5362
|
+
const gasPrice = GasPrice2.fromString("10000000000peaka");
|
|
5363
|
+
const calculatedFee = calculateFee(
|
|
5364
|
+
Math.round(gasEstimation * multiplier),
|
|
5365
|
+
gasPrice
|
|
5366
|
+
);
|
|
5367
|
+
const grantFee = {
|
|
5368
|
+
amount: calculatedFee.amount,
|
|
5369
|
+
gas: calculatedFee.gas,
|
|
5370
|
+
granter: this.saasAddress
|
|
5371
|
+
};
|
|
5372
|
+
return client.setRoundInfo(
|
|
5373
|
+
{
|
|
5374
|
+
contractAddr: contractAddress,
|
|
5375
|
+
roundInfo
|
|
5376
|
+
},
|
|
5377
|
+
grantFee
|
|
5378
|
+
);
|
|
5379
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5380
|
+
const grantFee = {
|
|
5381
|
+
...fee,
|
|
5382
|
+
granter: this.saasAddress
|
|
5383
|
+
};
|
|
5384
|
+
return client.setRoundInfo(
|
|
5385
|
+
{
|
|
5386
|
+
contractAddr: contractAddress,
|
|
5387
|
+
roundInfo
|
|
5388
|
+
},
|
|
5389
|
+
grantFee
|
|
5390
|
+
);
|
|
5391
|
+
}
|
|
5392
|
+
return client.setRoundInfo(
|
|
5393
|
+
{
|
|
5394
|
+
contractAddr: contractAddress,
|
|
5395
|
+
roundInfo
|
|
5396
|
+
},
|
|
5397
|
+
fee
|
|
5398
|
+
);
|
|
5399
|
+
}
|
|
5400
|
+
async setSaasOracleMaciRoundVoteOptions({
|
|
5401
|
+
signer,
|
|
5402
|
+
contractAddress,
|
|
5403
|
+
voteOptionMap,
|
|
5404
|
+
gasStation = false,
|
|
5405
|
+
fee = 1.8
|
|
5406
|
+
}) {
|
|
5407
|
+
const client = await createSaasClientBy({
|
|
5408
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5409
|
+
wallet: signer,
|
|
5410
|
+
contractAddress: this.saasAddress
|
|
5411
|
+
});
|
|
5412
|
+
if (gasStation && typeof fee !== "object") {
|
|
5413
|
+
const [{ address }] = await signer.getAccounts();
|
|
5414
|
+
const contractClient = await this.contractClient({ signer });
|
|
5415
|
+
const msg = {
|
|
5416
|
+
set_vote_options_map: {
|
|
5417
|
+
contract_addr: contractAddress,
|
|
5418
|
+
vote_option_map: voteOptionMap
|
|
5419
|
+
}
|
|
5420
|
+
};
|
|
5421
|
+
const gasEstimation = await contractClient.simulate(
|
|
5422
|
+
address,
|
|
5423
|
+
[
|
|
5424
|
+
{
|
|
5425
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5426
|
+
value: {
|
|
5427
|
+
sender: address,
|
|
5428
|
+
contract: this.saasAddress,
|
|
5429
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5432
|
+
],
|
|
5433
|
+
""
|
|
5434
|
+
);
|
|
5435
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5436
|
+
const gasPrice = GasPrice2.fromString("10000000000peaka");
|
|
5437
|
+
const calculatedFee = calculateFee(
|
|
5438
|
+
Math.round(gasEstimation * multiplier),
|
|
5439
|
+
gasPrice
|
|
5440
|
+
);
|
|
5441
|
+
const grantFee = {
|
|
5442
|
+
amount: calculatedFee.amount,
|
|
5443
|
+
gas: calculatedFee.gas,
|
|
5444
|
+
granter: this.saasAddress
|
|
5445
|
+
};
|
|
5446
|
+
return client.setVoteOptionsMap(
|
|
5447
|
+
{
|
|
5448
|
+
contractAddr: contractAddress,
|
|
5449
|
+
voteOptionMap
|
|
5450
|
+
},
|
|
5451
|
+
grantFee
|
|
5452
|
+
);
|
|
5453
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5454
|
+
const grantFee = {
|
|
5455
|
+
...fee,
|
|
5456
|
+
granter: this.saasAddress
|
|
5457
|
+
};
|
|
5458
|
+
return client.setVoteOptionsMap(
|
|
5459
|
+
{
|
|
5460
|
+
contractAddr: contractAddress,
|
|
5461
|
+
voteOptionMap
|
|
5462
|
+
},
|
|
5463
|
+
grantFee
|
|
5464
|
+
);
|
|
5465
|
+
}
|
|
5466
|
+
return client.setVoteOptionsMap(
|
|
5467
|
+
{
|
|
5468
|
+
contractAddr: contractAddress,
|
|
5469
|
+
voteOptionMap
|
|
5470
|
+
},
|
|
4896
5471
|
fee
|
|
4897
5472
|
);
|
|
4898
|
-
return instantiateResponse;
|
|
4899
5473
|
}
|
|
4900
|
-
async
|
|
5474
|
+
async addSaasOperator({
|
|
4901
5475
|
signer,
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
title,
|
|
4906
|
-
description,
|
|
4907
|
-
link,
|
|
4908
|
-
voteOptionMap,
|
|
4909
|
-
circuitType,
|
|
4910
|
-
whitelistEcosystem,
|
|
4911
|
-
whitelistSnapshotHeight,
|
|
4912
|
-
whitelistVotingPowerArgs,
|
|
4913
|
-
fee = "auto"
|
|
5476
|
+
operator,
|
|
5477
|
+
gasStation = false,
|
|
5478
|
+
fee = 1.8
|
|
4914
5479
|
}) {
|
|
4915
|
-
const
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
5480
|
+
const client = await createSaasClientBy({
|
|
5481
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5482
|
+
wallet: signer,
|
|
5483
|
+
contractAddress: this.saasAddress
|
|
5484
|
+
});
|
|
5485
|
+
if (gasStation && typeof fee !== "object") {
|
|
5486
|
+
const [{ address }] = await signer.getAccounts();
|
|
5487
|
+
const contractClient = await this.contractClient({ signer });
|
|
5488
|
+
const msg = {
|
|
5489
|
+
add_operator: {
|
|
5490
|
+
operator
|
|
5491
|
+
}
|
|
5492
|
+
};
|
|
5493
|
+
const gasEstimation = await contractClient.simulate(
|
|
5494
|
+
address,
|
|
5495
|
+
[
|
|
5496
|
+
{
|
|
5497
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5498
|
+
value: {
|
|
5499
|
+
sender: address,
|
|
5500
|
+
contract: this.saasAddress,
|
|
5501
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5502
|
+
}
|
|
5503
|
+
}
|
|
5504
|
+
],
|
|
5505
|
+
""
|
|
5506
|
+
);
|
|
5507
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5508
|
+
const gasPrice = GasPrice2.fromString("10000000000peaka");
|
|
5509
|
+
const calculatedFee = calculateFee(
|
|
5510
|
+
Math.round(gasEstimation * multiplier),
|
|
5511
|
+
gasPrice
|
|
5512
|
+
);
|
|
5513
|
+
const grantFee = {
|
|
5514
|
+
amount: calculatedFee.amount,
|
|
5515
|
+
gas: calculatedFee.gas,
|
|
5516
|
+
granter: this.saasAddress
|
|
5517
|
+
};
|
|
5518
|
+
return client.addOperator({ operator }, grantFee);
|
|
5519
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5520
|
+
const grantFee = {
|
|
5521
|
+
...fee,
|
|
5522
|
+
granter: this.saasAddress
|
|
5523
|
+
};
|
|
5524
|
+
return client.addOperator({ operator }, grantFee);
|
|
5525
|
+
}
|
|
5526
|
+
return client.addOperator({ operator }, fee);
|
|
5527
|
+
}
|
|
5528
|
+
async removeSaasOperator({
|
|
5529
|
+
signer,
|
|
5530
|
+
operator,
|
|
5531
|
+
gasStation = false,
|
|
5532
|
+
fee = 1.8
|
|
5533
|
+
}) {
|
|
5534
|
+
const client = await createSaasClientBy({
|
|
5535
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5536
|
+
wallet: signer,
|
|
5537
|
+
contractAddress: this.saasAddress
|
|
5538
|
+
});
|
|
5539
|
+
if (gasStation && typeof fee !== "object") {
|
|
5540
|
+
const [{ address }] = await signer.getAccounts();
|
|
5541
|
+
const contractClient = await this.contractClient({ signer });
|
|
5542
|
+
const msg = {
|
|
5543
|
+
remove_operator: {
|
|
5544
|
+
operator
|
|
5545
|
+
}
|
|
5546
|
+
};
|
|
5547
|
+
const gasEstimation = await contractClient.simulate(
|
|
5548
|
+
address,
|
|
5549
|
+
[
|
|
5550
|
+
{
|
|
5551
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5552
|
+
value: {
|
|
5553
|
+
sender: address,
|
|
5554
|
+
contract: this.saasAddress,
|
|
5555
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
],
|
|
5559
|
+
""
|
|
5560
|
+
);
|
|
5561
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5562
|
+
const gasPrice = GasPrice2.fromString("10000000000peaka");
|
|
5563
|
+
const calculatedFee = calculateFee(
|
|
5564
|
+
Math.round(gasEstimation * multiplier),
|
|
5565
|
+
gasPrice
|
|
5566
|
+
);
|
|
5567
|
+
const grantFee = {
|
|
5568
|
+
amount: calculatedFee.amount,
|
|
5569
|
+
gas: calculatedFee.gas,
|
|
5570
|
+
granter: this.saasAddress
|
|
5571
|
+
};
|
|
5572
|
+
return client.removeOperator({ operator }, grantFee);
|
|
5573
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5574
|
+
const grantFee = {
|
|
5575
|
+
...fee,
|
|
5576
|
+
granter: this.saasAddress
|
|
5577
|
+
};
|
|
5578
|
+
return client.removeOperator({ operator }, grantFee);
|
|
5579
|
+
}
|
|
5580
|
+
return client.removeOperator({ operator }, fee);
|
|
5581
|
+
}
|
|
5582
|
+
async isSaasOperator({
|
|
5583
|
+
signer,
|
|
5584
|
+
operator
|
|
5585
|
+
}) {
|
|
5586
|
+
const client = await createSaasClientBy({
|
|
5587
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5588
|
+
wallet: signer,
|
|
5589
|
+
contractAddress: this.saasAddress
|
|
5590
|
+
});
|
|
5591
|
+
return client.isOperator({ address: operator });
|
|
5592
|
+
}
|
|
5593
|
+
async depositSaas({
|
|
5594
|
+
signer,
|
|
5595
|
+
amount,
|
|
5596
|
+
gasStation = false,
|
|
5597
|
+
fee = 1.8
|
|
5598
|
+
}) {
|
|
5599
|
+
const client = await createSaasClientBy({
|
|
5600
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5601
|
+
wallet: signer,
|
|
5602
|
+
contractAddress: this.saasAddress
|
|
5603
|
+
});
|
|
5604
|
+
const funds = [
|
|
4932
5605
|
{
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
}
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
5606
|
+
denom: "peaka",
|
|
5607
|
+
amount
|
|
5608
|
+
}
|
|
5609
|
+
];
|
|
5610
|
+
if (gasStation && typeof fee !== "object") {
|
|
5611
|
+
const [{ address }] = await signer.getAccounts();
|
|
5612
|
+
const contractClient = await this.contractClient({ signer });
|
|
5613
|
+
const msg = {
|
|
5614
|
+
deposit: {}
|
|
5615
|
+
};
|
|
5616
|
+
const gasEstimation = await contractClient.simulate(
|
|
5617
|
+
address,
|
|
5618
|
+
[
|
|
5619
|
+
{
|
|
5620
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5621
|
+
value: {
|
|
5622
|
+
sender: address,
|
|
5623
|
+
contract: this.saasAddress,
|
|
5624
|
+
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
5625
|
+
funds
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
],
|
|
5629
|
+
""
|
|
5630
|
+
);
|
|
5631
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5632
|
+
const gasPrice = GasPrice2.fromString("10000000000peaka");
|
|
5633
|
+
const calculatedFee = calculateFee(
|
|
5634
|
+
Math.round(gasEstimation * multiplier),
|
|
5635
|
+
gasPrice
|
|
5636
|
+
);
|
|
5637
|
+
const grantFee = {
|
|
5638
|
+
amount: calculatedFee.amount,
|
|
5639
|
+
gas: calculatedFee.gas,
|
|
5640
|
+
granter: this.saasAddress
|
|
5641
|
+
};
|
|
5642
|
+
return client.deposit(grantFee, void 0, funds);
|
|
5643
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5644
|
+
const grantFee = {
|
|
5645
|
+
...fee,
|
|
5646
|
+
granter: this.saasAddress
|
|
5647
|
+
};
|
|
5648
|
+
return client.deposit(grantFee, void 0, funds);
|
|
5649
|
+
}
|
|
5650
|
+
return client.deposit(fee, void 0, funds);
|
|
5651
|
+
}
|
|
5652
|
+
async withdrawSaas({
|
|
5653
|
+
signer,
|
|
5654
|
+
amount,
|
|
5655
|
+
gasStation = false,
|
|
5656
|
+
fee = 1.8
|
|
5657
|
+
}) {
|
|
5658
|
+
const client = await createSaasClientBy({
|
|
5659
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5660
|
+
wallet: signer,
|
|
5661
|
+
contractAddress: this.saasAddress
|
|
5662
|
+
});
|
|
5663
|
+
if (gasStation && typeof fee !== "object") {
|
|
5664
|
+
const [{ address }] = await signer.getAccounts();
|
|
5665
|
+
const contractClient = await this.contractClient({ signer });
|
|
5666
|
+
const msg = {
|
|
5667
|
+
withdraw: {
|
|
5668
|
+
amount
|
|
5669
|
+
}
|
|
5670
|
+
};
|
|
5671
|
+
const gasEstimation = await contractClient.simulate(
|
|
5672
|
+
address,
|
|
5673
|
+
[
|
|
5674
|
+
{
|
|
5675
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5676
|
+
value: {
|
|
5677
|
+
sender: address,
|
|
5678
|
+
contract: this.saasAddress,
|
|
5679
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5680
|
+
}
|
|
5681
|
+
}
|
|
5682
|
+
],
|
|
5683
|
+
""
|
|
5684
|
+
);
|
|
5685
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5686
|
+
const gasPrice = GasPrice2.fromString("10000000000peaka");
|
|
5687
|
+
const calculatedFee = calculateFee(
|
|
5688
|
+
Math.round(gasEstimation * multiplier),
|
|
5689
|
+
gasPrice
|
|
5690
|
+
);
|
|
5691
|
+
const grantFee = {
|
|
5692
|
+
amount: calculatedFee.amount,
|
|
5693
|
+
gas: calculatedFee.gas,
|
|
5694
|
+
granter: this.saasAddress
|
|
5695
|
+
};
|
|
5696
|
+
return client.withdraw({ amount }, grantFee);
|
|
5697
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5698
|
+
const grantFee = {
|
|
5699
|
+
...fee,
|
|
5700
|
+
granter: this.saasAddress
|
|
5701
|
+
};
|
|
5702
|
+
return client.withdraw({ amount }, grantFee);
|
|
5703
|
+
}
|
|
5704
|
+
return client.withdraw({ amount }, fee);
|
|
4955
5705
|
}
|
|
4956
5706
|
async queryRoundInfo({
|
|
4957
5707
|
signer,
|
|
@@ -5006,6 +5756,16 @@ var Contract = class {
|
|
|
5006
5756
|
contractAddress
|
|
5007
5757
|
});
|
|
5008
5758
|
}
|
|
5759
|
+
async saasClient({
|
|
5760
|
+
signer,
|
|
5761
|
+
contractAddress
|
|
5762
|
+
}) {
|
|
5763
|
+
return createSaasClientBy({
|
|
5764
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5765
|
+
wallet: signer,
|
|
5766
|
+
contractAddress
|
|
5767
|
+
});
|
|
5768
|
+
}
|
|
5009
5769
|
async contractClient({ signer }) {
|
|
5010
5770
|
return createContractClientByWallet(this.rpcEndpoint, signer);
|
|
5011
5771
|
}
|
|
@@ -5061,7 +5821,7 @@ var OracleCertificate = class {
|
|
|
5061
5821
|
};
|
|
5062
5822
|
|
|
5063
5823
|
// src/libs/maci/maci.ts
|
|
5064
|
-
import { GasPrice as
|
|
5824
|
+
import { GasPrice as GasPrice3, calculateFee as calculateFee2 } from "@cosmjs/stargate";
|
|
5065
5825
|
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx.js";
|
|
5066
5826
|
function isErrorResponse(response) {
|
|
5067
5827
|
return typeof response === "object" && response !== null && "error" in response && typeof response.error === "object" && "message" in response.error;
|
|
@@ -5443,7 +6203,8 @@ var MACI = class {
|
|
|
5443
6203
|
selectedOptions,
|
|
5444
6204
|
operatorCoordPubKey,
|
|
5445
6205
|
maciKeypair,
|
|
5446
|
-
gasStation = false
|
|
6206
|
+
gasStation = false,
|
|
6207
|
+
fee = 1.8
|
|
5447
6208
|
}) {
|
|
5448
6209
|
if (maciKeypair === void 0) {
|
|
5449
6210
|
maciKeypair = this.maciKeypair;
|
|
@@ -5524,7 +6285,8 @@ var MACI = class {
|
|
|
5524
6285
|
address,
|
|
5525
6286
|
payload,
|
|
5526
6287
|
contractAddress,
|
|
5527
|
-
gasStation
|
|
6288
|
+
gasStation,
|
|
6289
|
+
fee
|
|
5528
6290
|
});
|
|
5529
6291
|
} catch (error) {
|
|
5530
6292
|
throw Error(`Vote failed! ${error}`);
|
|
@@ -5535,7 +6297,8 @@ var MACI = class {
|
|
|
5535
6297
|
address,
|
|
5536
6298
|
payload,
|
|
5537
6299
|
contractAddress,
|
|
5538
|
-
gasStation
|
|
6300
|
+
gasStation,
|
|
6301
|
+
fee = 1.8
|
|
5539
6302
|
}) {
|
|
5540
6303
|
const msgs = payload.map(
|
|
5541
6304
|
({ msg, encPubkeys }) => ({
|
|
@@ -5561,12 +6324,23 @@ var MACI = class {
|
|
|
5561
6324
|
})
|
|
5562
6325
|
})
|
|
5563
6326
|
);
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
6327
|
+
if (gasStation && typeof fee !== "object") {
|
|
6328
|
+
const gasEstimation = await client.simulate(address, msgs, "");
|
|
6329
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6330
|
+
const gasPrice = GasPrice3.fromString("10000000000peaka");
|
|
6331
|
+
const calculatedFee = calculateFee2(
|
|
6332
|
+
Math.round(gasEstimation * multiplier),
|
|
6333
|
+
gasPrice
|
|
6334
|
+
);
|
|
6335
|
+
const grantFee = {
|
|
6336
|
+
amount: calculatedFee.amount,
|
|
6337
|
+
gas: calculatedFee.gas,
|
|
6338
|
+
granter: contractAddress
|
|
6339
|
+
};
|
|
6340
|
+
return client.signAndBroadcast(address, msgs, grantFee);
|
|
6341
|
+
} else if (gasStation && typeof fee === "object") {
|
|
5567
6342
|
const grantFee = {
|
|
5568
|
-
|
|
5569
|
-
gas: fee.gas,
|
|
6343
|
+
...fee,
|
|
5570
6344
|
granter: contractAddress
|
|
5571
6345
|
};
|
|
5572
6346
|
return client.signAndBroadcast(address, msgs, grantFee);
|
|
@@ -5579,43 +6353,51 @@ var MACI = class {
|
|
|
5579
6353
|
pubKey,
|
|
5580
6354
|
contractAddress,
|
|
5581
6355
|
gasStation,
|
|
5582
|
-
fee
|
|
6356
|
+
fee = 1.8
|
|
5583
6357
|
}) {
|
|
5584
|
-
const
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
6358
|
+
const msg = {
|
|
6359
|
+
sign_up: {
|
|
6360
|
+
pubkey: {
|
|
6361
|
+
x: pubKey[0].toString(),
|
|
6362
|
+
y: pubKey[1].toString()
|
|
6363
|
+
}
|
|
6364
|
+
}
|
|
6365
|
+
};
|
|
6366
|
+
if (gasStation === true && typeof fee !== "object") {
|
|
6367
|
+
const gasEstimation = await client.simulate(
|
|
5593
6368
|
address,
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
6369
|
+
[
|
|
6370
|
+
{
|
|
6371
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6372
|
+
value: {
|
|
6373
|
+
sender: address,
|
|
6374
|
+
contract: contractAddress,
|
|
6375
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5600
6376
|
}
|
|
5601
6377
|
}
|
|
5602
|
-
|
|
5603
|
-
|
|
6378
|
+
],
|
|
6379
|
+
""
|
|
5604
6380
|
);
|
|
6381
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6382
|
+
const gasPrice = GasPrice3.fromString("10000000000peaka");
|
|
6383
|
+
const calculatedFee = calculateFee2(
|
|
6384
|
+
Math.round(gasEstimation * multiplier),
|
|
6385
|
+
gasPrice
|
|
6386
|
+
);
|
|
6387
|
+
const grantFee = {
|
|
6388
|
+
amount: calculatedFee.amount,
|
|
6389
|
+
gas: calculatedFee.gas,
|
|
6390
|
+
granter: contractAddress
|
|
6391
|
+
};
|
|
6392
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
6393
|
+
} else if (gasStation === true && typeof fee === "object") {
|
|
6394
|
+
const grantFee = {
|
|
6395
|
+
...fee,
|
|
6396
|
+
granter: contractAddress
|
|
6397
|
+
};
|
|
6398
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
5605
6399
|
}
|
|
5606
|
-
return client.execute(
|
|
5607
|
-
address,
|
|
5608
|
-
contractAddress,
|
|
5609
|
-
{
|
|
5610
|
-
sign_up: {
|
|
5611
|
-
pubkey: {
|
|
5612
|
-
x: pubKey[0].toString(),
|
|
5613
|
-
y: pubKey[1].toString()
|
|
5614
|
-
}
|
|
5615
|
-
}
|
|
5616
|
-
},
|
|
5617
|
-
fee
|
|
5618
|
-
);
|
|
6400
|
+
return client.execute(address, contractAddress, msg, fee);
|
|
5619
6401
|
}
|
|
5620
6402
|
async signupOracle({
|
|
5621
6403
|
client,
|
|
@@ -5624,29 +6406,53 @@ var MACI = class {
|
|
|
5624
6406
|
contractAddress,
|
|
5625
6407
|
oracleCertificate,
|
|
5626
6408
|
gasStation,
|
|
5627
|
-
fee
|
|
6409
|
+
fee = 1.8
|
|
5628
6410
|
}) {
|
|
5629
|
-
const
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
6411
|
+
const msg = {
|
|
6412
|
+
sign_up: {
|
|
6413
|
+
pubkey: {
|
|
6414
|
+
x: pubKey[0].toString(),
|
|
6415
|
+
y: pubKey[1].toString()
|
|
6416
|
+
},
|
|
6417
|
+
amount: oracleCertificate.amount,
|
|
6418
|
+
certificate: oracleCertificate.signature
|
|
6419
|
+
}
|
|
6420
|
+
};
|
|
6421
|
+
if (gasStation === true && typeof fee !== "object") {
|
|
6422
|
+
const gasEstimation = await client.simulate(
|
|
6423
|
+
address,
|
|
6424
|
+
[
|
|
6425
|
+
{
|
|
6426
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6427
|
+
value: {
|
|
6428
|
+
sender: address,
|
|
6429
|
+
contract: contractAddress,
|
|
6430
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
6431
|
+
}
|
|
6432
|
+
}
|
|
6433
|
+
],
|
|
6434
|
+
""
|
|
6435
|
+
);
|
|
6436
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6437
|
+
const gasPrice = GasPrice3.fromString("10000000000peaka");
|
|
6438
|
+
const calculatedFee = calculateFee2(
|
|
6439
|
+
Math.round(gasEstimation * multiplier),
|
|
6440
|
+
gasPrice
|
|
6441
|
+
);
|
|
6442
|
+
const grantFee = {
|
|
6443
|
+
amount: calculatedFee.amount,
|
|
6444
|
+
gas: calculatedFee.gas,
|
|
5647
6445
|
granter: contractAddress
|
|
5648
|
-
}
|
|
5649
|
-
|
|
6446
|
+
};
|
|
6447
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
6448
|
+
} else if (gasStation === true && typeof fee === "object") {
|
|
6449
|
+
const grantFee = {
|
|
6450
|
+
...fee,
|
|
6451
|
+
granter: contractAddress
|
|
6452
|
+
};
|
|
6453
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
6454
|
+
}
|
|
6455
|
+
return client.execute(address, contractAddress, msg, fee);
|
|
5650
6456
|
}
|
|
5651
6457
|
async deactivate({
|
|
5652
6458
|
signer,
|
|
@@ -5654,7 +6460,7 @@ var MACI = class {
|
|
|
5654
6460
|
maciKeypair,
|
|
5655
6461
|
contractAddress,
|
|
5656
6462
|
gasStation,
|
|
5657
|
-
fee
|
|
6463
|
+
fee = 1.8
|
|
5658
6464
|
}) {
|
|
5659
6465
|
try {
|
|
5660
6466
|
address = address || (await signer.getAccounts())[0].address;
|
|
@@ -5682,28 +6488,62 @@ var MACI = class {
|
|
|
5682
6488
|
[[0, 0]]
|
|
5683
6489
|
);
|
|
5684
6490
|
const { msg, encPubkeys } = payload[0];
|
|
5685
|
-
const
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
x: encPubkeys[0],
|
|
5694
|
-
y: encPubkeys[1]
|
|
5695
|
-
},
|
|
5696
|
-
message: {
|
|
5697
|
-
data: msg
|
|
5698
|
-
}
|
|
6491
|
+
const deactivateMsg = stringizing({
|
|
6492
|
+
publish_deactivate_message: {
|
|
6493
|
+
enc_pub_key: {
|
|
6494
|
+
x: encPubkeys[0],
|
|
6495
|
+
y: encPubkeys[1]
|
|
6496
|
+
},
|
|
6497
|
+
message: {
|
|
6498
|
+
data: msg
|
|
5699
6499
|
}
|
|
5700
|
-
}
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
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(deactivateMsg))
|
|
6512
|
+
}
|
|
6513
|
+
}
|
|
6514
|
+
],
|
|
6515
|
+
""
|
|
6516
|
+
);
|
|
6517
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6518
|
+
const gasPrice = GasPrice3.fromString("10000000000peaka");
|
|
6519
|
+
const calculatedFee = calculateFee2(
|
|
6520
|
+
Math.round(gasEstimation * multiplier),
|
|
6521
|
+
gasPrice
|
|
6522
|
+
);
|
|
6523
|
+
const grantFee = {
|
|
6524
|
+
amount: calculatedFee.amount,
|
|
6525
|
+
gas: calculatedFee.gas,
|
|
5704
6526
|
granter: contractAddress
|
|
5705
|
-
}
|
|
5706
|
-
|
|
6527
|
+
};
|
|
6528
|
+
return client.execute(
|
|
6529
|
+
address,
|
|
6530
|
+
contractAddress,
|
|
6531
|
+
deactivateMsg,
|
|
6532
|
+
grantFee
|
|
6533
|
+
);
|
|
6534
|
+
} else if (gasStation === true && typeof fee === "object") {
|
|
6535
|
+
const grantFee = {
|
|
6536
|
+
...fee,
|
|
6537
|
+
granter: contractAddress
|
|
6538
|
+
};
|
|
6539
|
+
return client.execute(
|
|
6540
|
+
address,
|
|
6541
|
+
contractAddress,
|
|
6542
|
+
deactivateMsg,
|
|
6543
|
+
grantFee
|
|
6544
|
+
);
|
|
6545
|
+
}
|
|
6546
|
+
return client.execute(address, contractAddress, deactivateMsg, fee);
|
|
5707
6547
|
} catch (error) {
|
|
5708
6548
|
throw Error(`Submit deactivate failed! ${error}`);
|
|
5709
6549
|
}
|
|
@@ -5914,8 +6754,10 @@ var MaciClient2 = class {
|
|
|
5914
6754
|
restEndpoint,
|
|
5915
6755
|
apiEndpoint,
|
|
5916
6756
|
registryAddress,
|
|
6757
|
+
saasAddress,
|
|
5917
6758
|
maciCodeId,
|
|
5918
6759
|
oracleCodeId,
|
|
6760
|
+
saasOracleCodeId,
|
|
5919
6761
|
customFetch,
|
|
5920
6762
|
defaultOptions,
|
|
5921
6763
|
feegrantOperator,
|
|
@@ -5931,8 +6773,10 @@ var MaciClient2 = class {
|
|
|
5931
6773
|
this.apiEndpoint = apiEndpoint || defaultParams.apiEndpoint;
|
|
5932
6774
|
this.certificateApiEndpoint = certificateApiEndpoint || defaultParams.certificateApiEndpoint;
|
|
5933
6775
|
this.registryAddress = registryAddress || defaultParams.registryAddress;
|
|
6776
|
+
this.saasAddress = saasAddress || defaultParams.saasAddress;
|
|
5934
6777
|
this.maciCodeId = maciCodeId || defaultParams.maciCodeId;
|
|
5935
6778
|
this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
|
|
6779
|
+
this.saasOracleCodeId = saasOracleCodeId || defaultParams.saasCodeId;
|
|
5936
6780
|
this.feegrantOperator = feegrantOperator || defaultParams.oracleFeegrantOperator;
|
|
5937
6781
|
this.whitelistBackendPubkey = whitelistBackendPubkey || defaultParams.oracleWhitelistBackendPubkey;
|
|
5938
6782
|
this.maciKeypair = maciKeypair ?? genKeypair();
|
|
@@ -5952,8 +6796,10 @@ var MaciClient2 = class {
|
|
|
5952
6796
|
network: this.network,
|
|
5953
6797
|
rpcEndpoint: this.rpcEndpoint,
|
|
5954
6798
|
registryAddress: this.registryAddress,
|
|
6799
|
+
saasAddress: this.saasAddress,
|
|
5955
6800
|
maciCodeId: this.maciCodeId,
|
|
5956
6801
|
oracleCodeId: this.oracleCodeId,
|
|
6802
|
+
saasOracleCodeId: this.saasOracleCodeId,
|
|
5957
6803
|
feegrantOperator: this.feegrantOperator,
|
|
5958
6804
|
whitelistBackendPubkey: this.whitelistBackendPubkey
|
|
5959
6805
|
});
|
|
@@ -6042,6 +6888,12 @@ var MaciClient2 = class {
|
|
|
6042
6888
|
...params
|
|
6043
6889
|
});
|
|
6044
6890
|
}
|
|
6891
|
+
async createSaasOracleMaciRound(params) {
|
|
6892
|
+
return await this.contract.createSaasOracleMaciRound({
|
|
6893
|
+
signer: this.getSigner(params.signer),
|
|
6894
|
+
...params
|
|
6895
|
+
});
|
|
6896
|
+
}
|
|
6045
6897
|
async genKeypairFromSign({
|
|
6046
6898
|
signer,
|
|
6047
6899
|
address
|