@dorafactory/maci-sdk 0.1.3-pre.46.beta.1 → 0.1.3-pre.46.beta.3

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
@@ -4342,6 +4342,46 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4342
4342
  _funds
4343
4343
  );
4344
4344
  };
4345
+ this.publishMessage = async ({
4346
+ contractAddr,
4347
+ encPubKeys,
4348
+ messages
4349
+ }, fee = "auto", memo, _funds) => {
4350
+ return await this.client.execute(
4351
+ this.sender,
4352
+ this.contractAddress,
4353
+ {
4354
+ publish_message: {
4355
+ contract_addr: contractAddr,
4356
+ enc_pub_keys: encPubKeys,
4357
+ messages
4358
+ }
4359
+ },
4360
+ fee,
4361
+ memo,
4362
+ _funds
4363
+ );
4364
+ };
4365
+ this.publishDeactivateMessage = async ({
4366
+ contractAddr,
4367
+ encPubKey,
4368
+ message
4369
+ }, fee = "auto", memo, _funds) => {
4370
+ return await this.client.execute(
4371
+ this.sender,
4372
+ this.contractAddress,
4373
+ {
4374
+ publish_deactivate_message: {
4375
+ contract_addr: contractAddr,
4376
+ enc_pub_key: encPubKey,
4377
+ message
4378
+ }
4379
+ },
4380
+ fee,
4381
+ memo,
4382
+ _funds
4383
+ );
4384
+ };
4345
4385
  this.client = client;
4346
4386
  this.sender = sender;
4347
4387
  this.contractAddress = contractAddress;
@@ -4354,6 +4394,8 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4354
4394
  this.createAmaciRound = this.createAmaciRound.bind(this);
4355
4395
  this.setRoundInfo = this.setRoundInfo.bind(this);
4356
4396
  this.setVoteOptionsMap = this.setVoteOptionsMap.bind(this);
4397
+ this.publishMessage = this.publishMessage.bind(this);
4398
+ this.publishDeactivateMessage = this.publishDeactivateMessage.bind(this);
4357
4399
  }
4358
4400
  };
4359
4401
 
@@ -4965,6 +5007,122 @@ var Contract = class {
4965
5007
  contractAddress
4966
5008
  };
4967
5009
  }
5010
+ async publishMessageViaSaas({
5011
+ signer,
5012
+ contractAddress,
5013
+ encPubKeys,
5014
+ messages,
5015
+ granter,
5016
+ fee = 1.8
5017
+ }) {
5018
+ const client = await createApiSaasClientBy({
5019
+ rpcEndpoint: this.rpcEndpoint,
5020
+ wallet: signer,
5021
+ contractAddress: this.apiSaasAddress
5022
+ });
5023
+ const saasGranter = granter || this.apiSaasAddress;
5024
+ if (typeof fee !== "object") {
5025
+ const [{ address }] = await signer.getAccounts();
5026
+ const contractClient = await this.contractClient({ signer });
5027
+ const msg = {
5028
+ publish_message: {
5029
+ contract_addr: contractAddress,
5030
+ enc_pub_keys: encPubKeys,
5031
+ messages
5032
+ }
5033
+ };
5034
+ const gasEstimation = await contractClient.simulate(
5035
+ address,
5036
+ [
5037
+ {
5038
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5039
+ value: {
5040
+ sender: address,
5041
+ contract: this.apiSaasAddress,
5042
+ msg: new TextEncoder().encode(JSON.stringify(msg))
5043
+ }
5044
+ }
5045
+ ],
5046
+ ""
5047
+ );
5048
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5049
+ const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
5050
+ const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
5051
+ const grantFee = {
5052
+ amount: calculatedFee.amount,
5053
+ gas: calculatedFee.gas,
5054
+ granter: saasGranter
5055
+ };
5056
+ return client.publishMessage({ contractAddr: contractAddress, encPubKeys, messages }, grantFee);
5057
+ } else {
5058
+ const grantFee = {
5059
+ ...fee,
5060
+ granter: saasGranter
5061
+ };
5062
+ return client.publishMessage({ contractAddr: contractAddress, encPubKeys, messages }, grantFee);
5063
+ }
5064
+ }
5065
+ async publishDeactivateMessageViaSaas({
5066
+ signer,
5067
+ contractAddress,
5068
+ encPubKey,
5069
+ message,
5070
+ granter,
5071
+ fee = 1.8
5072
+ }) {
5073
+ const client = await createApiSaasClientBy({
5074
+ rpcEndpoint: this.rpcEndpoint,
5075
+ wallet: signer,
5076
+ contractAddress: this.apiSaasAddress
5077
+ });
5078
+ const saasGranter = granter || this.apiSaasAddress;
5079
+ if (typeof fee !== "object") {
5080
+ const [{ address }] = await signer.getAccounts();
5081
+ const contractClient = await this.contractClient({ signer });
5082
+ const msg = {
5083
+ publish_deactivate_message: {
5084
+ contract_addr: contractAddress,
5085
+ enc_pub_key: encPubKey,
5086
+ message
5087
+ }
5088
+ };
5089
+ const gasEstimation = await contractClient.simulate(
5090
+ address,
5091
+ [
5092
+ {
5093
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5094
+ value: {
5095
+ sender: address,
5096
+ contract: this.apiSaasAddress,
5097
+ msg: new TextEncoder().encode(JSON.stringify(msg))
5098
+ }
5099
+ }
5100
+ ],
5101
+ ""
5102
+ );
5103
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5104
+ const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
5105
+ const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
5106
+ const grantFee = {
5107
+ amount: calculatedFee.amount,
5108
+ gas: calculatedFee.gas,
5109
+ granter: saasGranter
5110
+ };
5111
+ return client.publishDeactivateMessage(
5112
+ { contractAddr: contractAddress, encPubKey, message },
5113
+ grantFee
5114
+ );
5115
+ } else {
5116
+ const grantFee = {
5117
+ ...fee,
5118
+ granter: saasGranter
5119
+ };
5120
+ return client.publishDeactivateMessage(
5121
+ { contractAddr: contractAddress, encPubKey, message },
5122
+ grantFee
5123
+ );
5124
+ }
5125
+ }
4968
5126
  };
4969
5127
 
4970
5128
  // src/libs/oracle-certificate/oracle-certificate.ts
@@ -5486,6 +5644,18 @@ var MACI = class {
5486
5644
  if (!address) {
5487
5645
  address = (await signer.getAccounts())[0].address;
5488
5646
  }
5647
+ const msgLength = payload[0]?.msg.length ?? 0;
5648
+ if (msgLength === 7) {
5649
+ return await this.publishMessageBatchLegacy({
5650
+ signer,
5651
+ address,
5652
+ payload,
5653
+ contractAddress,
5654
+ gasStation,
5655
+ granter,
5656
+ fee
5657
+ });
5658
+ }
5489
5659
  return await this.publishMessageBatch({
5490
5660
  signer,
5491
5661
  address,
@@ -5571,34 +5741,29 @@ var MACI = class {
5571
5741
  }));
5572
5742
  const totalFee = (BigInt(MESSAGE_FEE) * BigInt(payload.length)).toString();
5573
5743
  const batchFunds = [{ denom: FEE_DENOM, amount: totalFee }];
5574
- if (gasStation && typeof fee !== "object") {
5744
+ if (gasStation && granter === this.contract.apiSaasAddress) {
5745
+ return this.contract.publishMessageViaSaas({
5746
+ signer,
5747
+ contractAddress,
5748
+ encPubKeys,
5749
+ messages,
5750
+ granter,
5751
+ fee
5752
+ });
5753
+ } else if (gasStation && typeof fee !== "object") {
5575
5754
  const client = await this.contract.contractClient({ signer });
5576
- const encPubKeysBigInt = payload.map((p) => ({
5577
- x: p.encPubkeys[0],
5578
- y: p.encPubkeys[1]
5579
- }));
5580
- const messagesBigInt = payload.map((p) => ({
5581
- data: p.msg
5582
- }));
5583
- const msg = {
5755
+ const msgForSimulate = {
5584
5756
  typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5585
5757
  value: import_tx.MsgExecuteContract.fromPartial({
5586
5758
  sender: address,
5587
5759
  contract: contractAddress,
5588
5760
  msg: new TextEncoder().encode(
5589
- JSON.stringify(
5590
- stringizing({
5591
- publish_message: {
5592
- enc_pub_keys: encPubKeysBigInt,
5593
- messages: messagesBigInt
5594
- }
5595
- })
5596
- )
5761
+ JSON.stringify({ publish_message: { enc_pub_keys: encPubKeys, messages } })
5597
5762
  ),
5598
5763
  funds: batchFunds
5599
5764
  })
5600
5765
  };
5601
- const gasEstimation = await client.simulate(address, [msg], "");
5766
+ const gasEstimation = await client.simulate(address, [msgForSimulate], "");
5602
5767
  const multiplier = typeof fee === "number" ? fee : 1.8;
5603
5768
  const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
5604
5769
  const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
@@ -5617,6 +5782,63 @@ var MACI = class {
5617
5782
  }
5618
5783
  return amaciClient.publishMessage({ encPubKeys, messages }, fee, void 0, batchFunds);
5619
5784
  }
5785
+ async publishMessageBatchLegacy({
5786
+ signer,
5787
+ address,
5788
+ payload,
5789
+ contractAddress,
5790
+ gasStation,
5791
+ granter,
5792
+ fee = 1.8
5793
+ }) {
5794
+ if (!address) {
5795
+ address = (await signer.getAccounts())[0].address;
5796
+ }
5797
+ const client = await this.contract.contractClient({ signer });
5798
+ const messages = payload.map((p) => ({
5799
+ data: p.msg
5800
+ }));
5801
+ const encPubKeys = payload.map((p) => ({
5802
+ x: p.encPubkeys[0],
5803
+ y: p.encPubkeys[1]
5804
+ }));
5805
+ const msg = {
5806
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5807
+ value: import_tx.MsgExecuteContract.fromPartial({
5808
+ sender: address,
5809
+ contract: contractAddress,
5810
+ msg: new TextEncoder().encode(
5811
+ JSON.stringify(
5812
+ stringizing({
5813
+ publish_message_batch: {
5814
+ enc_pub_keys: encPubKeys,
5815
+ messages
5816
+ }
5817
+ })
5818
+ )
5819
+ )
5820
+ })
5821
+ };
5822
+ if (gasStation && typeof fee !== "object") {
5823
+ const gasEstimation = await client.simulate(address, [msg], "");
5824
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5825
+ const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
5826
+ const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
5827
+ const grantFee = {
5828
+ amount: calculatedFee.amount,
5829
+ gas: calculatedFee.gas,
5830
+ granter: granter || contractAddress
5831
+ };
5832
+ return client.signAndBroadcast(address, [msg], grantFee);
5833
+ } else if (gasStation && typeof fee === "object") {
5834
+ const grantFee = {
5835
+ ...fee,
5836
+ granter: granter || contractAddress
5837
+ };
5838
+ return client.signAndBroadcast(address, [msg], grantFee);
5839
+ }
5840
+ return client.signAndBroadcast(address, [msg], fee);
5841
+ }
5620
5842
  async deactivate({
5621
5843
  signer,
5622
5844
  address,
@@ -5712,10 +5934,23 @@ var MACI = class {
5712
5934
  }) {
5713
5935
  try {
5714
5936
  address = address || (await signer.getAccounts())[0].address;
5715
- const client = await this.contract.contractClient({
5716
- signer
5717
- });
5718
5937
  const { msg, encPubkeys } = payload;
5938
+ if (gasStation === true && granter === this.contract.apiSaasAddress) {
5939
+ return this.contract.publishDeactivateMessageViaSaas({
5940
+ signer,
5941
+ contractAddress,
5942
+ encPubKey: {
5943
+ x: encPubkeys[0].toString(),
5944
+ y: encPubkeys[1].toString()
5945
+ },
5946
+ message: {
5947
+ data: msg.map((m) => m.toString())
5948
+ },
5949
+ granter,
5950
+ fee
5951
+ });
5952
+ }
5953
+ const client = await this.contract.contractClient({ signer });
5719
5954
  const deactivateMsg = stringizing({
5720
5955
  publish_deactivate_message: {
5721
5956
  enc_pub_key: {