@dorafactory/maci-sdk 0.1.2-pre.0 → 0.1.2-pre.10

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 CHANGED
@@ -4570,7 +4570,8 @@ var SaasClient = class extends SaasQueryClient {
4570
4570
  // src/libs/contract/config.ts
4571
4571
  var defaultSigningClientOptions = {
4572
4572
  broadcastPollIntervalMs: 8e3,
4573
- broadcastTimeoutMs: 64e3,
4573
+ broadcastTimeoutMs: 15e4,
4574
+ // 2min30s for the tx to be confirmed
4574
4575
  gasPrice: import_stargate.GasPrice.fromString("10000000000peaka")
4575
4576
  };
4576
4577
  async function createMaciClientBy({
@@ -5289,14 +5290,11 @@ var Contract = class {
5289
5290
  title,
5290
5291
  description,
5291
5292
  link,
5292
- maxVoter,
5293
5293
  voteOptionMap,
5294
5294
  circuitType,
5295
5295
  whitelistEcosystem,
5296
5296
  whitelistSnapshotHeight,
5297
5297
  whitelistVotingPowerArgs,
5298
- whitelistBackendPubkey,
5299
- feegrantOperator,
5300
5298
  fee = "auto"
5301
5299
  }) {
5302
5300
  const start_time = (startVoting.getTime() * 1e6).toString();
@@ -5317,7 +5315,6 @@ var Contract = class {
5317
5315
  address,
5318
5316
  this.oracleCodeId,
5319
5317
  {
5320
- max_voters: maxVoter.toString(),
5321
5318
  round_info: { title, description: description || "", link: link || "" },
5322
5319
  voting_time: {
5323
5320
  start_time,
@@ -5328,13 +5325,13 @@ var Contract = class {
5328
5325
  y: operatorPubkeyY.toString()
5329
5326
  },
5330
5327
  vote_option_map: voteOptionMap,
5331
- whitelist_backend_pubkey: whitelistBackendPubkey ? whitelistBackendPubkey : this.whitelistBackendPubkey,
5328
+ whitelist_backend_pubkey: this.whitelistBackendPubkey,
5332
5329
  whitelist_ecosystem: whitelistEcosystem,
5333
5330
  whitelist_snapshot_height: whitelistSnapshotHeight,
5334
5331
  whitelist_voting_power_args: whitelistVotingPowerArgs,
5335
5332
  circuit_type: maciVoteType,
5336
5333
  certification_system: maciCertSystem,
5337
- feegrant_operator: feegrantOperator ? feegrantOperator : this.feegrantOperator
5334
+ feegrant_operator: this.feegrantOperator
5338
5335
  },
5339
5336
  `[Oracle MACI] ${title}`,
5340
5337
  fee
@@ -5351,7 +5348,9 @@ var Contract = class {
5351
5348
  link,
5352
5349
  maxVoter,
5353
5350
  voteOptionMap,
5354
- whitelistBackendPubkey
5351
+ whitelistBackendPubkey,
5352
+ gasStation = false,
5353
+ fee = 1.8
5355
5354
  }) {
5356
5355
  const startTime = (startVoting.getTime() * 1e6).toString();
5357
5356
  const endTime = (endVoting.getTime() * 1e6).toString();
@@ -5363,7 +5362,7 @@ var Contract = class {
5363
5362
  const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
5364
5363
  BigInt(operatorPubkey)
5365
5364
  );
5366
- const createResponse = await client.createOracleMaciRound({
5365
+ const roundParams = {
5367
5366
  certificationSystem: "0",
5368
5367
  circuitType: "0",
5369
5368
  coordinator: {
@@ -5380,7 +5379,65 @@ var Contract = class {
5380
5379
  endTime,
5381
5380
  voteOptionMap,
5382
5381
  whitelistBackendPubkey: whitelistBackendPubkey || this.whitelistBackendPubkey
5383
- });
5382
+ };
5383
+ let createResponse;
5384
+ if (gasStation && typeof fee !== "object") {
5385
+ const [{ address }] = await signer.getAccounts();
5386
+ const contractClient = await this.contractClient({ signer });
5387
+ const msg = {
5388
+ create_oracle_maci_round: {
5389
+ certification_system: "0",
5390
+ circuit_type: "0",
5391
+ coordinator: roundParams.coordinator,
5392
+ max_voters: roundParams.maxVoters.toString(),
5393
+ round_info: roundParams.roundInfo,
5394
+ start_time: roundParams.startTime,
5395
+ end_time: roundParams.endTime,
5396
+ vote_option_map: roundParams.voteOptionMap,
5397
+ whitelist_backend_pubkey: roundParams.whitelistBackendPubkey
5398
+ }
5399
+ };
5400
+ const gasEstimation = await contractClient.simulate(
5401
+ address,
5402
+ [
5403
+ {
5404
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5405
+ value: {
5406
+ sender: address,
5407
+ contract: this.saasAddress,
5408
+ msg: new TextEncoder().encode(JSON.stringify(msg))
5409
+ }
5410
+ }
5411
+ ],
5412
+ ""
5413
+ );
5414
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5415
+ const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
5416
+ const calculatedFee = (0, import_stargate2.calculateFee)(
5417
+ Math.round(gasEstimation * multiplier),
5418
+ gasPrice
5419
+ );
5420
+ const grantFee = {
5421
+ amount: calculatedFee.amount,
5422
+ gas: calculatedFee.gas,
5423
+ granter: this.saasAddress
5424
+ };
5425
+ createResponse = await client.createOracleMaciRound(
5426
+ roundParams,
5427
+ grantFee
5428
+ );
5429
+ } else if (gasStation && typeof fee === "object") {
5430
+ const grantFee = {
5431
+ ...fee,
5432
+ granter: this.saasAddress
5433
+ };
5434
+ createResponse = await client.createOracleMaciRound(
5435
+ roundParams,
5436
+ grantFee
5437
+ );
5438
+ } else {
5439
+ createResponse = await client.createOracleMaciRound(roundParams, fee);
5440
+ }
5384
5441
  let contractAddress = "";
5385
5442
  createResponse.events.map((event) => {
5386
5443
  if (event.type === "wasm") {
@@ -5552,6 +5609,85 @@ var Contract = class {
5552
5609
  fee
5553
5610
  );
5554
5611
  }
5612
+ async saasGrantToVoter({
5613
+ signer,
5614
+ baseAmount,
5615
+ contractAddress,
5616
+ grantee,
5617
+ gasStation = false,
5618
+ fee = 1.8
5619
+ }) {
5620
+ const client = await createSaasClientBy({
5621
+ rpcEndpoint: this.rpcEndpoint,
5622
+ wallet: signer,
5623
+ contractAddress: this.saasAddress
5624
+ });
5625
+ if (gasStation && typeof fee !== "object") {
5626
+ const [{ address }] = await signer.getAccounts();
5627
+ const contractClient = await this.contractClient({ signer });
5628
+ const msg = {
5629
+ grant_to_voter: {
5630
+ base_amount: baseAmount,
5631
+ contract_addr: contractAddress,
5632
+ grantee
5633
+ }
5634
+ };
5635
+ const gasEstimation = await contractClient.simulate(
5636
+ address,
5637
+ [
5638
+ {
5639
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5640
+ value: {
5641
+ sender: address,
5642
+ contract: this.saasAddress,
5643
+ msg: new TextEncoder().encode(JSON.stringify(msg))
5644
+ }
5645
+ }
5646
+ ],
5647
+ ""
5648
+ );
5649
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5650
+ const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
5651
+ const calculatedFee = (0, import_stargate2.calculateFee)(
5652
+ Math.round(gasEstimation * multiplier),
5653
+ gasPrice
5654
+ );
5655
+ const grantFee = {
5656
+ amount: calculatedFee.amount,
5657
+ gas: calculatedFee.gas,
5658
+ granter: this.saasAddress
5659
+ };
5660
+ return client.grantToVoter(
5661
+ {
5662
+ baseAmount,
5663
+ contractAddr: contractAddress,
5664
+ grantee
5665
+ },
5666
+ grantFee
5667
+ );
5668
+ } else if (gasStation && typeof fee === "object") {
5669
+ const grantFee = {
5670
+ ...fee,
5671
+ granter: this.saasAddress
5672
+ };
5673
+ return client.grantToVoter(
5674
+ {
5675
+ baseAmount,
5676
+ contractAddr: contractAddress,
5677
+ grantee
5678
+ },
5679
+ grantFee
5680
+ );
5681
+ }
5682
+ return client.grantToVoter(
5683
+ {
5684
+ baseAmount,
5685
+ contractAddr: contractAddress,
5686
+ grantee
5687
+ },
5688
+ fee
5689
+ );
5690
+ }
5555
5691
  async addSaasOperator({
5556
5692
  signer,
5557
5693
  operator,
@@ -7042,7 +7178,9 @@ var MaciClient2 = class {
7042
7178
  address,
7043
7179
  contractAddress
7044
7180
  }) {
7045
- address = await this.getAddress(signer);
7181
+ if (address === void 0) {
7182
+ address = await this.getAddress(signer);
7183
+ }
7046
7184
  return await this.maci.hasFeegrant({
7047
7185
  address,
7048
7186
  contractAddress