@dorafactory/maci-sdk 0.1.3-pre.46.beta.13 → 0.1.3-pre.46.beta.16

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
@@ -3536,6 +3536,16 @@ var AMaciQueryClient = class {
3536
3536
  }
3537
3537
  });
3538
3538
  };
3539
+ this.getFeeConfig = async () => {
3540
+ return this.client.queryContractSmart(this.contractAddress, {
3541
+ get_fee_config: {}
3542
+ });
3543
+ };
3544
+ this.getDelayConfig = async () => {
3545
+ return this.client.queryContractSmart(this.contractAddress, {
3546
+ get_delay_config: {}
3547
+ });
3548
+ };
3539
3549
  this.client = client;
3540
3550
  this.contractAddress = contractAddress;
3541
3551
  this.admin = this.admin.bind(this);
@@ -3575,6 +3585,8 @@ var AMaciQueryClient = class {
3575
3585
  this.getDeactivateEnabled = this.getDeactivateEnabled.bind(this);
3576
3586
  this.getRegistrationConfig = this.getRegistrationConfig.bind(this);
3577
3587
  this.queryRegistrationStatus = this.queryRegistrationStatus.bind(this);
3588
+ this.getFeeConfig = this.getFeeConfig.bind(this);
3589
+ this.getDelayConfig = this.getDelayConfig.bind(this);
3578
3590
  }
3579
3591
  };
3580
3592
  var AMaciClient = class extends AMaciQueryClient {
@@ -3919,6 +3931,16 @@ var RegistryQueryClient = class {
3919
3931
  get_circuit_charge_config: {}
3920
3932
  });
3921
3933
  };
3934
+ this.getFeeConfig = async () => {
3935
+ return this.client.queryContractSmart(this.contractAddress, {
3936
+ get_fee_config: {}
3937
+ });
3938
+ };
3939
+ this.getDelayConfig = async () => {
3940
+ return this.client.queryContractSmart(this.contractAddress, {
3941
+ get_delay_config: {}
3942
+ });
3943
+ };
3922
3944
  this.getPollId = async ({ address }) => {
3923
3945
  return this.client.queryContractSmart(this.contractAddress, {
3924
3946
  get_poll_id: {
@@ -3954,6 +3976,8 @@ var RegistryQueryClient = class {
3954
3976
  this.getMaciOperatorPubkey = this.getMaciOperatorPubkey.bind(this);
3955
3977
  this.getMaciOperatorIdentity = this.getMaciOperatorIdentity.bind(this);
3956
3978
  this.getCircuitChargeConfig = this.getCircuitChargeConfig.bind(this);
3979
+ this.getFeeConfig = this.getFeeConfig.bind(this);
3980
+ this.getDelayConfig = this.getDelayConfig.bind(this);
3957
3981
  this.getPollId = this.getPollId.bind(this);
3958
3982
  this.getPollAddress = this.getPollAddress.bind(this);
3959
3983
  this.getNextPollId = this.getNextPollId.bind(this);
@@ -4015,7 +4039,6 @@ var RegistryClient = class extends RegistryQueryClient {
4015
4039
  certificationSystem,
4016
4040
  circuitType,
4017
4041
  deactivateEnabled,
4018
- maxVoter,
4019
4042
  operator,
4020
4043
  registrationMode,
4021
4044
  roundInfo,
@@ -4031,7 +4054,6 @@ var RegistryClient = class extends RegistryQueryClient {
4031
4054
  certification_system: certificationSystem,
4032
4055
  circuit_type: circuitType,
4033
4056
  deactivate_enabled: deactivateEnabled,
4034
- max_voter: maxVoter,
4035
4057
  operator,
4036
4058
  registration_mode: registrationMode,
4037
4059
  round_info: roundInfo,
@@ -4125,6 +4147,38 @@ var RegistryClient = class extends RegistryQueryClient {
4125
4147
  _funds
4126
4148
  );
4127
4149
  };
4150
+ this.updateFeeConfig = async ({
4151
+ config
4152
+ }, fee = "auto", memo, _funds) => {
4153
+ return await this.client.execute(
4154
+ this.sender,
4155
+ this.contractAddress,
4156
+ {
4157
+ update_fee_config: {
4158
+ config
4159
+ }
4160
+ },
4161
+ fee,
4162
+ memo,
4163
+ _funds
4164
+ );
4165
+ };
4166
+ this.updateDelayConfig = async ({
4167
+ config
4168
+ }, fee = "auto", memo, _funds) => {
4169
+ return await this.client.execute(
4170
+ this.sender,
4171
+ this.contractAddress,
4172
+ {
4173
+ update_delay_config: {
4174
+ config
4175
+ }
4176
+ },
4177
+ fee,
4178
+ memo,
4179
+ _funds
4180
+ );
4181
+ };
4128
4182
  this.client = client;
4129
4183
  this.sender = sender;
4130
4184
  this.contractAddress = contractAddress;
@@ -4137,6 +4191,8 @@ var RegistryClient = class extends RegistryQueryClient {
4137
4191
  this.updateAmaciCodeId = this.updateAmaciCodeId.bind(this);
4138
4192
  this.changeOperator = this.changeOperator.bind(this);
4139
4193
  this.changeChargeConfig = this.changeChargeConfig.bind(this);
4194
+ this.updateFeeConfig = this.updateFeeConfig.bind(this);
4195
+ this.updateDelayConfig = this.updateDelayConfig.bind(this);
4140
4196
  }
4141
4197
  };
4142
4198
 
@@ -4282,7 +4338,6 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4282
4338
  certificationSystem,
4283
4339
  circuitType,
4284
4340
  deactivateEnabled,
4285
- maxVoter,
4286
4341
  operator,
4287
4342
  registrationMode,
4288
4343
  roundInfo,
@@ -4298,7 +4353,6 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4298
4353
  certification_system: certificationSystem,
4299
4354
  circuit_type: circuitType,
4300
4355
  deactivate_enabled: deactivateEnabled,
4301
- max_voter: maxVoter,
4302
4356
  operator,
4303
4357
  registration_mode: registrationMode,
4304
4358
  round_info: roundInfo,
@@ -4312,6 +4366,22 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4312
4366
  _funds
4313
4367
  );
4314
4368
  };
4369
+ this.updateFeeConfig = async ({
4370
+ config
4371
+ }, fee = "auto", memo, _funds) => {
4372
+ return await this.client.execute(
4373
+ this.sender,
4374
+ this.contractAddress,
4375
+ {
4376
+ update_fee_config: {
4377
+ config
4378
+ }
4379
+ },
4380
+ fee,
4381
+ memo,
4382
+ _funds
4383
+ );
4384
+ };
4315
4385
  this.setRoundInfo = async ({
4316
4386
  contractAddr,
4317
4387
  roundInfo
@@ -4388,6 +4458,76 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4388
4458
  _funds
4389
4459
  );
4390
4460
  };
4461
+ this.signUp = async ({
4462
+ amount,
4463
+ certificate,
4464
+ contractAddr,
4465
+ pubkey
4466
+ }, fee = "auto", memo, _funds) => {
4467
+ return await this.client.execute(
4468
+ this.sender,
4469
+ this.contractAddress,
4470
+ {
4471
+ sign_up: {
4472
+ amount,
4473
+ certificate,
4474
+ contract_addr: contractAddr,
4475
+ pubkey
4476
+ }
4477
+ },
4478
+ fee,
4479
+ memo,
4480
+ _funds
4481
+ );
4482
+ };
4483
+ this.addNewKey = async ({
4484
+ contractAddr,
4485
+ d,
4486
+ groth16Proof,
4487
+ nullifier,
4488
+ pubkey
4489
+ }, fee = "auto", memo, _funds) => {
4490
+ return await this.client.execute(
4491
+ this.sender,
4492
+ this.contractAddress,
4493
+ {
4494
+ add_new_key: {
4495
+ contract_addr: contractAddr,
4496
+ d,
4497
+ groth16_proof: groth16Proof,
4498
+ nullifier,
4499
+ pubkey
4500
+ }
4501
+ },
4502
+ fee,
4503
+ memo,
4504
+ _funds
4505
+ );
4506
+ };
4507
+ this.preAddNewKey = async ({
4508
+ contractAddr,
4509
+ d,
4510
+ groth16Proof,
4511
+ nullifier,
4512
+ pubkey
4513
+ }, fee = "auto", memo, _funds) => {
4514
+ return await this.client.execute(
4515
+ this.sender,
4516
+ this.contractAddress,
4517
+ {
4518
+ pre_add_new_key: {
4519
+ contract_addr: contractAddr,
4520
+ d,
4521
+ groth16_proof: groth16Proof,
4522
+ nullifier,
4523
+ pubkey
4524
+ }
4525
+ },
4526
+ fee,
4527
+ memo,
4528
+ _funds
4529
+ );
4530
+ };
4391
4531
  this.client = client;
4392
4532
  this.sender = sender;
4393
4533
  this.contractAddress = contractAddress;
@@ -4398,10 +4538,14 @@ var ApiSaasClient = class extends ApiSaasQueryClient {
4398
4538
  this.deposit = this.deposit.bind(this);
4399
4539
  this.withdraw = this.withdraw.bind(this);
4400
4540
  this.createAmaciRound = this.createAmaciRound.bind(this);
4541
+ this.updateFeeConfig = this.updateFeeConfig.bind(this);
4401
4542
  this.setRoundInfo = this.setRoundInfo.bind(this);
4402
4543
  this.setVoteOptionsMap = this.setVoteOptionsMap.bind(this);
4403
4544
  this.publishMessage = this.publishMessage.bind(this);
4404
4545
  this.publishDeactivateMessage = this.publishDeactivateMessage.bind(this);
4546
+ this.signUp = this.signUp.bind(this);
4547
+ this.addNewKey = this.addNewKey.bind(this);
4548
+ this.preAddNewKey = this.preAddNewKey.bind(this);
4405
4549
  }
4406
4550
  };
4407
4551
 
@@ -4437,6 +4581,13 @@ async function createRegistryClientBy({
4437
4581
  const [{ address }] = await wallet.getAccounts();
4438
4582
  return new RegistryClient(signingCosmWasmClient, address, contractAddress);
4439
4583
  }
4584
+ async function createRegistryQueryClientBy({
4585
+ rpcEndpoint,
4586
+ contractAddress
4587
+ }) {
4588
+ const cosmWasmClient = await import_cosmwasm_stargate.CosmWasmClient.connect(rpcEndpoint);
4589
+ return new RegistryQueryClient(cosmWasmClient, contractAddress);
4590
+ }
4440
4591
  async function createApiSaasClientBy({
4441
4592
  rpcEndpoint,
4442
4593
  wallet,
@@ -4453,53 +4604,33 @@ async function createContractClientByWallet(rpcEndpoint, wallet) {
4453
4604
  return client;
4454
4605
  }
4455
4606
 
4456
- // src/types/index.ts
4457
- var MaciCircuitType = /* @__PURE__ */ ((MaciCircuitType2) => {
4458
- MaciCircuitType2["IP1V"] = "0";
4459
- MaciCircuitType2["QV"] = "1";
4460
- return MaciCircuitType2;
4461
- })(MaciCircuitType || {});
4462
- var MaciCertSystemType = /* @__PURE__ */ ((MaciCertSystemType2) => {
4463
- MaciCertSystemType2["GROTH16"] = "groth16";
4464
- MaciCertSystemType2["PLONK"] = "plonk";
4465
- return MaciCertSystemType2;
4466
- })(MaciCertSystemType || {});
4467
- var MaciRoundType = /* @__PURE__ */ ((MaciRoundType2) => {
4468
- MaciRoundType2["MACI"] = "0";
4469
- MaciRoundType2["AMACI"] = "1";
4470
- MaciRoundType2["ORACLE_MACI"] = "2";
4471
- return MaciRoundType2;
4472
- })(MaciRoundType || {});
4607
+ // src/libs/contract/contract.ts
4608
+ var import_stargate2 = require("@cosmjs/stargate");
4473
4609
 
4474
- // src/libs/contract/utils.ts
4475
- function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
4476
- let requiredFee = {
4477
- denom: "peaka",
4478
- amount: "0"
4479
- };
4480
- if (maxVoter <= 25 && maxOption <= 5) {
4481
- requiredFee.amount = "5000000000000000000";
4482
- } else if (maxVoter <= 625 && maxOption <= 25) {
4483
- requiredFee.amount = "27000000000000000000";
4484
- } else if (maxVoter <= 15625 && maxOption <= 125) {
4485
- requiredFee.amount = "208000000000000000000";
4486
- } else {
4487
- throw new Error("Number of voters or options is too large.");
4488
- }
4489
- return requiredFee;
4490
- }
4491
- function getMaciRoundCircuitFee(network, maxVoter, maxOption) {
4492
- const amaciRoundFee = getAMaciRoundCircuitFee(network, maxVoter, maxOption);
4493
- const feeAmount = BigInt(amaciRoundFee.amount);
4494
- const maciRoundFeeAmount = feeAmount * BigInt(1) / BigInt(10);
4495
- return {
4496
- denom: "peaka",
4497
- amount: maciRoundFeeAmount.toString()
4498
- };
4499
- }
4610
+ // src/libs/maci/config.ts
4611
+ var FEE_DENOM = "peaka";
4612
+ var DEFAULT_BASE_FEE = "30000000000000000000";
4613
+ var DEFAULT_MESSAGE_FEE = "60000000000000000";
4614
+ var DEFAULT_DEACTIVATE_FEE = "10000000000000000000";
4615
+ var DEFAULT_SIGNUP_FEE = "30000000000000000";
4616
+ var DEFAULT_BASE_DELAY = 200;
4617
+ var DEFAULT_MESSAGE_DELAY = 2;
4618
+ var DEFAULT_SIGNUP_DELAY = 1;
4619
+ var DEFAULT_DEACTIVATE_DELAY = 600;
4620
+ var DEFAULT_FEE_CONFIG = {
4621
+ baseFee: DEFAULT_BASE_FEE,
4622
+ messageFee: DEFAULT_MESSAGE_FEE,
4623
+ deactivateFee: DEFAULT_DEACTIVATE_FEE,
4624
+ signupFee: DEFAULT_SIGNUP_FEE
4625
+ };
4626
+ var DEFAULT_DELAY_CONFIG = {
4627
+ baseDelay: DEFAULT_BASE_DELAY,
4628
+ messageDelay: DEFAULT_MESSAGE_DELAY,
4629
+ signupDelay: DEFAULT_SIGNUP_DELAY,
4630
+ deactivateDelay: DEFAULT_DEACTIVATE_DELAY
4631
+ };
4500
4632
 
4501
4633
  // src/libs/contract/contract.ts
4502
- var import_stargate2 = require("@cosmjs/stargate");
4503
4634
  var Contract = class {
4504
4635
  constructor({
4505
4636
  network,
@@ -4538,18 +4669,12 @@ var Contract = class {
4538
4669
  wallet: signer,
4539
4670
  contractAddress: this.registryAddress
4540
4671
  });
4541
- const requiredFee = getAMaciRoundCircuitFee(
4542
- this.network,
4543
- params.maxVoter,
4544
- params.voteOptionMap.length
4545
- );
4546
4672
  const fee = params.fee ?? "auto";
4547
4673
  const res = await client.createRound(
4548
4674
  {
4549
4675
  certificationSystem: params.certificationSystem ?? "0",
4550
4676
  circuitType: params.circuitType.toString(),
4551
4677
  deactivateEnabled: params.deactivateEnabled,
4552
- maxVoter: params.maxVoter.toString(),
4553
4678
  operator: params.operator,
4554
4679
  registrationMode: params.registrationMode,
4555
4680
  roundInfo,
@@ -4559,7 +4684,7 @@ var Contract = class {
4559
4684
  },
4560
4685
  fee,
4561
4686
  void 0,
4562
- [requiredFee]
4687
+ [{ denom: FEE_DENOM, amount: DEFAULT_BASE_FEE }]
4563
4688
  );
4564
4689
  let contractAddress = "";
4565
4690
  let pollId = "";
@@ -4647,6 +4772,12 @@ var Contract = class {
4647
4772
  contractAddress
4648
4773
  });
4649
4774
  }
4775
+ async registryQueryClient() {
4776
+ return createRegistryQueryClientBy({
4777
+ rpcEndpoint: this.rpcEndpoint,
4778
+ contractAddress: this.registryAddress
4779
+ });
4780
+ }
4650
4781
  async apiSaasClient({
4651
4782
  signer,
4652
4783
  contractAddress
@@ -4940,7 +5071,6 @@ var Contract = class {
4940
5071
  certificationSystem: params.certificationSystem ?? "0",
4941
5072
  circuitType,
4942
5073
  deactivateEnabled: params.deactivateEnabled,
4943
- maxVoter: params.maxVoter.toString(),
4944
5074
  operator: params.operator,
4945
5075
  registrationMode: params.registrationMode,
4946
5076
  roundInfo,
@@ -4948,24 +5078,249 @@ var Contract = class {
4948
5078
  voteOptionMap: params.voteOptionMap,
4949
5079
  votingTime
4950
5080
  };
4951
- const gasStation = params.gasStation ?? false;
4952
- const fee = params.fee ?? 1.8;
4953
- let createResponse;
4954
- if (gasStation && typeof fee !== "object") {
5081
+ const gasStation = params.gasStation ?? false;
5082
+ const fee = params.fee ?? 1.8;
5083
+ let createResponse;
5084
+ if (gasStation && typeof fee !== "object") {
5085
+ const [{ address }] = await signer.getAccounts();
5086
+ const contractClient = await this.contractClient({ signer });
5087
+ const msg = {
5088
+ create_amaci_round: {
5089
+ certification_system: roundParams.certificationSystem,
5090
+ circuit_type: roundParams.circuitType,
5091
+ deactivate_enabled: roundParams.deactivateEnabled,
5092
+ operator: roundParams.operator,
5093
+ registration_mode: roundParams.registrationMode,
5094
+ round_info: roundParams.roundInfo,
5095
+ voice_credit_mode: roundParams.voiceCreditMode,
5096
+ vote_option_map: roundParams.voteOptionMap,
5097
+ voting_time: roundParams.votingTime
5098
+ }
5099
+ };
5100
+ const gasEstimation = await contractClient.simulate(
5101
+ address,
5102
+ [
5103
+ {
5104
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5105
+ value: {
5106
+ sender: address,
5107
+ contract: this.apiSaasAddress,
5108
+ msg: new TextEncoder().encode(JSON.stringify(msg))
5109
+ }
5110
+ }
5111
+ ],
5112
+ ""
5113
+ );
5114
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5115
+ const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
5116
+ const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
5117
+ const grantFee = {
5118
+ amount: calculatedFee.amount,
5119
+ gas: calculatedFee.gas,
5120
+ granter: this.apiSaasAddress
5121
+ };
5122
+ createResponse = await client.createAmaciRound(roundParams, grantFee);
5123
+ } else if (gasStation && typeof fee === "object") {
5124
+ const grantFee = {
5125
+ ...fee,
5126
+ granter: this.apiSaasAddress
5127
+ };
5128
+ createResponse = await client.createAmaciRound(roundParams, grantFee);
5129
+ } else {
5130
+ createResponse = await client.createAmaciRound(roundParams, fee);
5131
+ }
5132
+ let contractAddress = "";
5133
+ let pollId = "";
5134
+ for (const event of createResponse.events) {
5135
+ if (event.type === "wasm") {
5136
+ const actionEvent = event.attributes.find(
5137
+ (attr) => attr.key === "action"
5138
+ );
5139
+ if (actionEvent && actionEvent.value === "created_round") {
5140
+ const roundAddrEvent = event.attributes.find(
5141
+ (attr) => attr.key === "round_addr"
5142
+ );
5143
+ const pollIdEvent = event.attributes.find(
5144
+ (attr) => attr.key === "poll_id"
5145
+ );
5146
+ if (roundAddrEvent) {
5147
+ contractAddress = roundAddrEvent.value.toString();
5148
+ }
5149
+ if (pollIdEvent) {
5150
+ pollId = pollIdEvent.value.toString();
5151
+ }
5152
+ if (contractAddress) {
5153
+ break;
5154
+ }
5155
+ }
5156
+ }
5157
+ }
5158
+ return {
5159
+ ...createResponse,
5160
+ contractAddress,
5161
+ pollId
5162
+ };
5163
+ }
5164
+ async signupViaSaas({
5165
+ signer,
5166
+ contractAddress,
5167
+ pubkey,
5168
+ certificate,
5169
+ amount,
5170
+ granter,
5171
+ fee = 1.8
5172
+ }) {
5173
+ const client = await createApiSaasClientBy({
5174
+ rpcEndpoint: this.rpcEndpoint,
5175
+ wallet: signer,
5176
+ contractAddress: this.apiSaasAddress
5177
+ });
5178
+ const saasGranter = granter || this.apiSaasAddress;
5179
+ const signUpParams = {
5180
+ contractAddr: contractAddress,
5181
+ pubkey,
5182
+ certificate,
5183
+ amount
5184
+ };
5185
+ if (typeof fee !== "object") {
5186
+ const [{ address }] = await signer.getAccounts();
5187
+ const contractClient = await this.contractClient({ signer });
5188
+ const msg = {
5189
+ sign_up: {
5190
+ contract_addr: contractAddress,
5191
+ pubkey,
5192
+ certificate: certificate ?? null,
5193
+ amount: amount ?? null
5194
+ }
5195
+ };
5196
+ const gasEstimation = await contractClient.simulate(
5197
+ address,
5198
+ [
5199
+ {
5200
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5201
+ value: {
5202
+ sender: address,
5203
+ contract: this.apiSaasAddress,
5204
+ msg: new TextEncoder().encode(JSON.stringify(msg))
5205
+ }
5206
+ }
5207
+ ],
5208
+ ""
5209
+ );
5210
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5211
+ const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
5212
+ const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
5213
+ const grantFee2 = {
5214
+ amount: calculatedFee.amount,
5215
+ gas: calculatedFee.gas,
5216
+ granter: saasGranter
5217
+ };
5218
+ return client.signUp(signUpParams, grantFee2);
5219
+ }
5220
+ const grantFee = {
5221
+ ...fee,
5222
+ granter: saasGranter
5223
+ };
5224
+ return client.signUp(signUpParams, grantFee);
5225
+ }
5226
+ async preAddNewKeyViaSaas({
5227
+ signer,
5228
+ contractAddress,
5229
+ pubkey,
5230
+ nullifier,
5231
+ d,
5232
+ groth16Proof,
5233
+ granter,
5234
+ fee = 1.8
5235
+ }) {
5236
+ const client = await createApiSaasClientBy({
5237
+ rpcEndpoint: this.rpcEndpoint,
5238
+ wallet: signer,
5239
+ contractAddress: this.apiSaasAddress
5240
+ });
5241
+ const saasGranter = granter || this.apiSaasAddress;
5242
+ const keyParams = {
5243
+ contractAddr: contractAddress,
5244
+ pubkey,
5245
+ nullifier,
5246
+ d,
5247
+ groth16Proof
5248
+ };
5249
+ if (typeof fee !== "object") {
5250
+ const [{ address }] = await signer.getAccounts();
5251
+ const contractClient = await this.contractClient({ signer });
5252
+ const msg = {
5253
+ pre_add_new_key: {
5254
+ contract_addr: contractAddress,
5255
+ pubkey,
5256
+ nullifier,
5257
+ d,
5258
+ groth16_proof: groth16Proof
5259
+ }
5260
+ };
5261
+ const gasEstimation = await contractClient.simulate(
5262
+ address,
5263
+ [
5264
+ {
5265
+ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5266
+ value: {
5267
+ sender: address,
5268
+ contract: this.apiSaasAddress,
5269
+ msg: new TextEncoder().encode(JSON.stringify(msg))
5270
+ }
5271
+ }
5272
+ ],
5273
+ ""
5274
+ );
5275
+ const multiplier = typeof fee === "number" ? fee : 1.8;
5276
+ const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
5277
+ const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
5278
+ const grantFee2 = {
5279
+ amount: calculatedFee.amount,
5280
+ gas: calculatedFee.gas,
5281
+ granter: saasGranter
5282
+ };
5283
+ return client.preAddNewKey(keyParams, grantFee2);
5284
+ }
5285
+ const grantFee = {
5286
+ ...fee,
5287
+ granter: saasGranter
5288
+ };
5289
+ return client.preAddNewKey(keyParams, grantFee);
5290
+ }
5291
+ async addNewKeyViaSaas({
5292
+ signer,
5293
+ contractAddress,
5294
+ pubkey,
5295
+ nullifier,
5296
+ d,
5297
+ groth16Proof,
5298
+ granter,
5299
+ fee = 1.8
5300
+ }) {
5301
+ const client = await createApiSaasClientBy({
5302
+ rpcEndpoint: this.rpcEndpoint,
5303
+ wallet: signer,
5304
+ contractAddress: this.apiSaasAddress
5305
+ });
5306
+ const saasGranter = granter || this.apiSaasAddress;
5307
+ const keyParams = {
5308
+ contractAddr: contractAddress,
5309
+ pubkey,
5310
+ nullifier,
5311
+ d,
5312
+ groth16Proof
5313
+ };
5314
+ if (typeof fee !== "object") {
4955
5315
  const [{ address }] = await signer.getAccounts();
4956
5316
  const contractClient = await this.contractClient({ signer });
4957
5317
  const msg = {
4958
- create_amaci_round: {
4959
- certification_system: roundParams.certificationSystem,
4960
- circuit_type: roundParams.circuitType,
4961
- deactivate_enabled: roundParams.deactivateEnabled,
4962
- max_voter: roundParams.maxVoter,
4963
- operator: roundParams.operator,
4964
- registration_mode: roundParams.registrationMode,
4965
- round_info: roundParams.roundInfo,
4966
- voice_credit_mode: roundParams.voiceCreditMode,
4967
- vote_option_map: roundParams.voteOptionMap,
4968
- voting_time: roundParams.votingTime
5318
+ add_new_key: {
5319
+ contract_addr: contractAddress,
5320
+ pubkey,
5321
+ nullifier,
5322
+ d,
5323
+ groth16_proof: groth16Proof
4969
5324
  }
4970
5325
  };
4971
5326
  const gasEstimation = await contractClient.simulate(
@@ -4985,52 +5340,18 @@ var Contract = class {
4985
5340
  const multiplier = typeof fee === "number" ? fee : 1.8;
4986
5341
  const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
4987
5342
  const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
4988
- const grantFee = {
5343
+ const grantFee2 = {
4989
5344
  amount: calculatedFee.amount,
4990
5345
  gas: calculatedFee.gas,
4991
- granter: this.apiSaasAddress
4992
- };
4993
- createResponse = await client.createAmaciRound(roundParams, grantFee);
4994
- } else if (gasStation && typeof fee === "object") {
4995
- const grantFee = {
4996
- ...fee,
4997
- granter: this.apiSaasAddress
5346
+ granter: saasGranter
4998
5347
  };
4999
- createResponse = await client.createAmaciRound(roundParams, grantFee);
5000
- } else {
5001
- createResponse = await client.createAmaciRound(roundParams, fee);
5002
- }
5003
- let contractAddress = "";
5004
- let pollId = "";
5005
- for (const event of createResponse.events) {
5006
- if (event.type === "wasm") {
5007
- const actionEvent = event.attributes.find(
5008
- (attr) => attr.key === "action"
5009
- );
5010
- if (actionEvent && actionEvent.value === "created_round") {
5011
- const roundAddrEvent = event.attributes.find(
5012
- (attr) => attr.key === "round_addr"
5013
- );
5014
- const pollIdEvent = event.attributes.find(
5015
- (attr) => attr.key === "poll_id"
5016
- );
5017
- if (roundAddrEvent) {
5018
- contractAddress = roundAddrEvent.value.toString();
5019
- }
5020
- if (pollIdEvent) {
5021
- pollId = pollIdEvent.value.toString();
5022
- }
5023
- if (contractAddress) {
5024
- break;
5025
- }
5026
- }
5027
- }
5348
+ return client.addNewKey(keyParams, grantFee2);
5028
5349
  }
5029
- return {
5030
- ...createResponse,
5031
- contractAddress,
5032
- pollId
5350
+ const grantFee = {
5351
+ ...fee,
5352
+ granter: saasGranter
5033
5353
  };
5354
+ return client.addNewKey(keyParams, grantFee);
5034
5355
  }
5035
5356
  async publishMessageViaSaas({
5036
5357
  signer,
@@ -5150,6 +5471,51 @@ var Contract = class {
5150
5471
  }
5151
5472
  };
5152
5473
 
5474
+ // src/types/index.ts
5475
+ var MaciCircuitType = /* @__PURE__ */ ((MaciCircuitType2) => {
5476
+ MaciCircuitType2["IP1V"] = "0";
5477
+ MaciCircuitType2["QV"] = "1";
5478
+ return MaciCircuitType2;
5479
+ })(MaciCircuitType || {});
5480
+ var MaciCertSystemType = /* @__PURE__ */ ((MaciCertSystemType2) => {
5481
+ MaciCertSystemType2["GROTH16"] = "groth16";
5482
+ MaciCertSystemType2["PLONK"] = "plonk";
5483
+ return MaciCertSystemType2;
5484
+ })(MaciCertSystemType || {});
5485
+ var MaciRoundType = /* @__PURE__ */ ((MaciRoundType2) => {
5486
+ MaciRoundType2["MACI"] = "0";
5487
+ MaciRoundType2["AMACI"] = "1";
5488
+ MaciRoundType2["ORACLE_MACI"] = "2";
5489
+ return MaciRoundType2;
5490
+ })(MaciRoundType || {});
5491
+
5492
+ // src/libs/contract/utils.ts
5493
+ function getAMaciRoundCircuitFee(network, maxVoter, maxOption) {
5494
+ let requiredFee = {
5495
+ denom: "peaka",
5496
+ amount: "0"
5497
+ };
5498
+ if (maxVoter <= 25 && maxOption <= 5) {
5499
+ requiredFee.amount = "5000000000000000000";
5500
+ } else if (maxVoter <= 625 && maxOption <= 25) {
5501
+ requiredFee.amount = "27000000000000000000";
5502
+ } else if (maxVoter <= 15625 && maxOption <= 125) {
5503
+ requiredFee.amount = "208000000000000000000";
5504
+ } else {
5505
+ throw new Error("Number of voters or options is too large.");
5506
+ }
5507
+ return requiredFee;
5508
+ }
5509
+ function getMaciRoundCircuitFee(network, maxVoter, maxOption) {
5510
+ const amaciRoundFee = getAMaciRoundCircuitFee(network, maxVoter, maxOption);
5511
+ const feeAmount = BigInt(amaciRoundFee.amount);
5512
+ const maciRoundFeeAmount = feeAmount * BigInt(1) / BigInt(10);
5513
+ return {
5514
+ denom: "peaka",
5515
+ amount: maciRoundFeeAmount.toString()
5516
+ };
5517
+ }
5518
+
5153
5519
  // src/libs/oracle-certificate/oracle-certificate.ts
5154
5520
  var OracleCertificate = class {
5155
5521
  constructor({ certificateApiEndpoint, http }) {
@@ -5202,13 +5568,6 @@ var OracleCertificate = class {
5202
5568
  // src/libs/maci/maci.ts
5203
5569
  var import_stargate3 = require("@cosmjs/stargate");
5204
5570
  var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx.js");
5205
-
5206
- // src/libs/maci/config.ts
5207
- var FEE_DENOM = "peaka";
5208
- var DEACTIVATE_FEE = "10000000000000000000";
5209
- var MESSAGE_FEE = "60000000000000000";
5210
-
5211
- // src/libs/maci/maci.ts
5212
5571
  function isErrorResponse(response) {
5213
5572
  return typeof response === "object" && response !== null && "error" in response && typeof response.error === "object" && "message" in response.error;
5214
5573
  }
@@ -5224,6 +5583,46 @@ var MACI = class {
5224
5583
  this.indexer = indexer;
5225
5584
  this.oracleCertificate = oracleCertificate;
5226
5585
  this.maciKeypair = maciKeypair;
5586
+ this.feeConfig = { ...DEFAULT_FEE_CONFIG };
5587
+ this.delayConfig = { ...DEFAULT_DELAY_CONFIG };
5588
+ }
5589
+ /**
5590
+ * Fetch the fee configuration from the given round contract and cache it locally.
5591
+ * Call this once after instantiation (or whenever fees may have changed) to ensure
5592
+ * the SDK uses the correct on-chain fee values for the specific round.
5593
+ */
5594
+ async fetchFeeConfig({ contractAddress }) {
5595
+ try {
5596
+ const roundClient = await this.contract.amaciQueryClient({ contractAddress });
5597
+ const feeConfig = await roundClient.getFeeConfig();
5598
+ this.feeConfig = {
5599
+ ...this.feeConfig,
5600
+ messageFee: feeConfig.message_fee,
5601
+ deactivateFee: feeConfig.deactivate_fee,
5602
+ signupFee: feeConfig.signup_fee
5603
+ };
5604
+ } catch {
5605
+ }
5606
+ return this.feeConfig;
5607
+ }
5608
+ /**
5609
+ * Fetch the delay configuration from the given round contract and cache it locally.
5610
+ * Call this once after instantiation (or whenever delays may have changed) to ensure
5611
+ * the SDK uses the correct on-chain delay values for the specific round.
5612
+ */
5613
+ async fetchDelayConfig({ contractAddress }) {
5614
+ try {
5615
+ const roundClient = await this.contract.amaciQueryClient({ contractAddress });
5616
+ const delayConfig = await roundClient.getDelayConfig();
5617
+ this.delayConfig = {
5618
+ baseDelay: delayConfig.base_delay,
5619
+ messageDelay: delayConfig.message_delay,
5620
+ signupDelay: delayConfig.signup_delay,
5621
+ deactivateDelay: delayConfig.deactivate_delay
5622
+ };
5623
+ } catch {
5624
+ }
5625
+ return this.delayConfig;
5227
5626
  }
5228
5627
  async getPollId({ contractAddress }) {
5229
5628
  const client = await this.contract.amaciQueryClient({ contractAddress });
@@ -5359,10 +5758,6 @@ var MACI = class {
5359
5758
  };
5360
5759
  }
5361
5760
  }
5362
- async queryAMaciChargeFee({ maxVoter, maxOption }) {
5363
- const fee = getAMaciRoundCircuitFee(this.network, maxVoter, maxOption);
5364
- return fee;
5365
- }
5366
5761
  async queryRoundGasStation({ contractAddress }) {
5367
5762
  const roundInfo = await this.getRoundInfo({ contractAddress });
5368
5763
  return roundInfo.gasStationEnable;
@@ -5445,6 +5840,7 @@ var MACI = class {
5445
5840
  certificate: oracleCertificate?.signature || ""
5446
5841
  }
5447
5842
  };
5843
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
5448
5844
  if (gasStation === true && typeof fee !== "object") {
5449
5845
  const gasEstimation = await client.simulate(
5450
5846
  address,
@@ -5454,7 +5850,8 @@ var MACI = class {
5454
5850
  value: {
5455
5851
  sender: address,
5456
5852
  contract: contractAddress,
5457
- msg: new TextEncoder().encode(JSON.stringify(msg))
5853
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
5854
+ funds: signupFunds
5458
5855
  }
5459
5856
  }
5460
5857
  ],
@@ -5468,15 +5865,15 @@ var MACI = class {
5468
5865
  gas: calculatedFee.gas,
5469
5866
  granter: contractAddress
5470
5867
  };
5471
- return client.execute(address, contractAddress, msg, grantFee);
5868
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5472
5869
  } else if (gasStation === true && typeof fee === "object") {
5473
5870
  const grantFee = {
5474
5871
  ...fee,
5475
5872
  granter: contractAddress
5476
5873
  };
5477
- return client.execute(address, contractAddress, msg, grantFee);
5874
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5478
5875
  }
5479
- return client.execute(address, contractAddress, msg, fee || "auto");
5876
+ return client.execute(address, contractAddress, msg, fee || "auto", void 0, signupFunds);
5480
5877
  } catch (error) {
5481
5878
  throw Error(`Signup failed! ${error}`);
5482
5879
  }
@@ -5508,7 +5905,21 @@ var MACI = class {
5508
5905
  certificate: oracleCertificate?.signature || ""
5509
5906
  }
5510
5907
  };
5511
- if (gasStation === true && typeof fee !== "object") {
5908
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
5909
+ if (gasStation === true && granter === this.contract.apiSaasAddress) {
5910
+ return this.contract.signupViaSaas({
5911
+ signer,
5912
+ contractAddress,
5913
+ pubkey: {
5914
+ x: pubKey[0].toString(),
5915
+ y: pubKey[1].toString()
5916
+ },
5917
+ certificate: oracleCertificate?.signature,
5918
+ amount: oracleCertificate?.amount,
5919
+ granter,
5920
+ fee
5921
+ });
5922
+ } else if (gasStation === true && typeof fee !== "object") {
5512
5923
  const gasEstimation = await client.simulate(
5513
5924
  address,
5514
5925
  [
@@ -5517,7 +5928,8 @@ var MACI = class {
5517
5928
  value: {
5518
5929
  sender: address,
5519
5930
  contract: contractAddress,
5520
- msg: new TextEncoder().encode(JSON.stringify(msg))
5931
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
5932
+ funds: signupFunds
5521
5933
  }
5522
5934
  }
5523
5935
  ],
@@ -5531,15 +5943,15 @@ var MACI = class {
5531
5943
  gas: calculatedFee.gas,
5532
5944
  granter: granter || contractAddress
5533
5945
  };
5534
- return client.execute(address, contractAddress, msg, grantFee);
5946
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5535
5947
  } else if (gasStation === true && typeof fee === "object") {
5536
5948
  const grantFee = {
5537
5949
  ...fee,
5538
5950
  granter: granter || contractAddress
5539
5951
  };
5540
- return client.execute(address, contractAddress, msg, grantFee);
5952
+ return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
5541
5953
  }
5542
- return client.execute(address, contractAddress, msg, fee || "auto");
5954
+ return client.execute(address, contractAddress, msg, fee || "auto", void 0, signupFunds);
5543
5955
  } catch (error) {
5544
5956
  throw Error(`Signup failed! ${error}`);
5545
5957
  }
@@ -5718,7 +6130,7 @@ var MACI = class {
5718
6130
  })
5719
6131
  )
5720
6132
  ),
5721
- funds: [{ denom: FEE_DENOM, amount: MESSAGE_FEE }]
6133
+ funds: [{ denom: FEE_DENOM, amount: this.feeConfig.messageFee }]
5722
6134
  })
5723
6135
  }));
5724
6136
  if (gasStation && typeof fee !== "object") {
@@ -5764,7 +6176,7 @@ var MACI = class {
5764
6176
  x: p.encPubkeys[0].toString(),
5765
6177
  y: p.encPubkeys[1].toString()
5766
6178
  }));
5767
- const totalFee = (BigInt(MESSAGE_FEE) * BigInt(payload.length)).toString();
6179
+ const totalFee = (BigInt(this.feeConfig.messageFee) * BigInt(payload.length)).toString();
5768
6180
  const batchFunds = [{ denom: FEE_DENOM, amount: totalFee }];
5769
6181
  if (gasStation && granter === this.contract.apiSaasAddress) {
5770
6182
  return this.contract.publishMessageViaSaas({
@@ -5827,6 +6239,8 @@ var MACI = class {
5827
6239
  x: p.encPubkeys[0],
5828
6240
  y: p.encPubkeys[1]
5829
6241
  }));
6242
+ const totalFee = (BigInt(this.feeConfig.messageFee) * BigInt(payload.length)).toString();
6243
+ const batchFunds = [{ denom: FEE_DENOM, amount: totalFee }];
5830
6244
  const msg = {
5831
6245
  typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
5832
6246
  value: import_tx.MsgExecuteContract.fromPartial({
@@ -5841,7 +6255,8 @@ var MACI = class {
5841
6255
  }
5842
6256
  })
5843
6257
  )
5844
- )
6258
+ ),
6259
+ funds: batchFunds
5845
6260
  })
5846
6261
  };
5847
6262
  if (gasStation && typeof fee !== "object") {
@@ -5910,7 +6325,7 @@ var MACI = class {
5910
6325
  }
5911
6326
  }
5912
6327
  });
5913
- const deactivateFunds = [{ denom: FEE_DENOM, amount: DEACTIVATE_FEE }];
6328
+ const deactivateFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.deactivateFee }];
5914
6329
  if (gasStation === true && typeof fee !== "object") {
5915
6330
  const gasEstimation = await client.simulate(
5916
6331
  address,
@@ -5987,7 +6402,7 @@ var MACI = class {
5987
6402
  }
5988
6403
  }
5989
6404
  });
5990
- const deactivateFunds = [{ denom: FEE_DENOM, amount: DEACTIVATE_FEE }];
6405
+ const deactivateFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.deactivateFee }];
5991
6406
  if (gasStation === true && typeof fee !== "object") {
5992
6407
  const gasEstimation = await client.simulate(
5993
6408
  address,
@@ -6065,6 +6480,7 @@ var MACI = class {
6065
6480
  signer,
6066
6481
  contractAddress
6067
6482
  });
6483
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
6068
6484
  return await client.addNewKey(
6069
6485
  {
6070
6486
  d,
@@ -6075,7 +6491,9 @@ var MACI = class {
6075
6491
  y: newMaciKeypair.pubKey[1].toString()
6076
6492
  }
6077
6493
  },
6078
- fee
6494
+ fee,
6495
+ void 0,
6496
+ signupFunds
6079
6497
  );
6080
6498
  }
6081
6499
  async rawAddNewKey({
@@ -6093,7 +6511,28 @@ var MACI = class {
6093
6511
  signer,
6094
6512
  contractAddress
6095
6513
  });
6096
- if (gasStation === true && typeof fee !== "object") {
6514
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
6515
+ const keyParams = {
6516
+ d,
6517
+ groth16Proof: proof,
6518
+ nullifier: nullifier.toString(),
6519
+ pubkey: {
6520
+ x: newPubkey[0].toString(),
6521
+ y: newPubkey[1].toString()
6522
+ }
6523
+ };
6524
+ if (gasStation === true && granter === this.contract.apiSaasAddress) {
6525
+ return this.contract.addNewKeyViaSaas({
6526
+ signer,
6527
+ contractAddress,
6528
+ pubkey: keyParams.pubkey,
6529
+ nullifier: keyParams.nullifier,
6530
+ d,
6531
+ groth16Proof: proof,
6532
+ granter,
6533
+ fee
6534
+ });
6535
+ } else if (gasStation === true && typeof fee !== "object") {
6097
6536
  const [{ address }] = await signer.getAccounts();
6098
6537
  const contractClient = await this.contract.contractClient({ signer });
6099
6538
  const msg = {
@@ -6115,7 +6554,8 @@ var MACI = class {
6115
6554
  value: {
6116
6555
  sender: address,
6117
6556
  contract: contractAddress,
6118
- msg: new TextEncoder().encode(JSON.stringify(msg))
6557
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
6558
+ funds: signupFunds
6119
6559
  }
6120
6560
  }
6121
6561
  ],
@@ -6129,48 +6569,15 @@ var MACI = class {
6129
6569
  gas: calculatedFee.gas,
6130
6570
  granter: granter || contractAddress
6131
6571
  };
6132
- return await client.addNewKey(
6133
- {
6134
- d,
6135
- groth16Proof: proof,
6136
- nullifier: nullifier.toString(),
6137
- pubkey: {
6138
- x: newPubkey[0].toString(),
6139
- y: newPubkey[1].toString()
6140
- }
6141
- },
6142
- grantFee
6143
- );
6572
+ return await client.addNewKey(keyParams, grantFee, void 0, signupFunds);
6144
6573
  } else if (gasStation === true && typeof fee === "object") {
6145
6574
  const grantFee = {
6146
6575
  ...fee,
6147
6576
  granter: granter || contractAddress
6148
6577
  };
6149
- return await client.addNewKey(
6150
- {
6151
- d,
6152
- groth16Proof: proof,
6153
- nullifier: nullifier.toString(),
6154
- pubkey: {
6155
- x: newPubkey[0].toString(),
6156
- y: newPubkey[1].toString()
6157
- }
6158
- },
6159
- grantFee
6160
- );
6578
+ return await client.addNewKey(keyParams, grantFee, void 0, signupFunds);
6161
6579
  }
6162
- return await client.addNewKey(
6163
- {
6164
- d,
6165
- groth16Proof: proof,
6166
- nullifier: nullifier.toString(),
6167
- pubkey: {
6168
- x: newPubkey[0].toString(),
6169
- y: newPubkey[1].toString()
6170
- }
6171
- },
6172
- fee
6173
- );
6580
+ return await client.addNewKey(keyParams, fee, void 0, signupFunds);
6174
6581
  }
6175
6582
  async rawPreAddNewKey({
6176
6583
  signer,
@@ -6187,7 +6594,28 @@ var MACI = class {
6187
6594
  signer,
6188
6595
  contractAddress
6189
6596
  });
6190
- if (gasStation === true && typeof fee !== "object") {
6597
+ const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
6598
+ const keyParams = {
6599
+ d,
6600
+ groth16Proof: proof,
6601
+ nullifier: nullifier.toString(),
6602
+ pubkey: {
6603
+ x: newPubkey[0].toString(),
6604
+ y: newPubkey[1].toString()
6605
+ }
6606
+ };
6607
+ if (gasStation === true && granter === this.contract.apiSaasAddress) {
6608
+ return this.contract.preAddNewKeyViaSaas({
6609
+ signer,
6610
+ contractAddress,
6611
+ pubkey: keyParams.pubkey,
6612
+ nullifier: keyParams.nullifier,
6613
+ d,
6614
+ groth16Proof: proof,
6615
+ granter,
6616
+ fee
6617
+ });
6618
+ } else if (gasStation === true && typeof fee !== "object") {
6191
6619
  const [{ address }] = await signer.getAccounts();
6192
6620
  const contractClient = await this.contract.contractClient({ signer });
6193
6621
  const msg = {
@@ -6209,7 +6637,8 @@ var MACI = class {
6209
6637
  value: {
6210
6638
  sender: address,
6211
6639
  contract: contractAddress,
6212
- msg: new TextEncoder().encode(JSON.stringify(msg))
6640
+ msg: new TextEncoder().encode(JSON.stringify(msg)),
6641
+ funds: signupFunds
6213
6642
  }
6214
6643
  }
6215
6644
  ],
@@ -6223,48 +6652,15 @@ var MACI = class {
6223
6652
  gas: calculatedFee.gas,
6224
6653
  granter: granter || contractAddress
6225
6654
  };
6226
- return await client.preAddNewKey(
6227
- {
6228
- d,
6229
- groth16Proof: proof,
6230
- nullifier: nullifier.toString(),
6231
- pubkey: {
6232
- x: newPubkey[0].toString(),
6233
- y: newPubkey[1].toString()
6234
- }
6235
- },
6236
- grantFee
6237
- );
6655
+ return await client.preAddNewKey(keyParams, grantFee, void 0, signupFunds);
6238
6656
  } else if (gasStation === true && typeof fee === "object") {
6239
6657
  const grantFee = {
6240
6658
  ...fee,
6241
6659
  granter: granter || contractAddress
6242
6660
  };
6243
- return await client.preAddNewKey(
6244
- {
6245
- d,
6246
- groth16Proof: proof,
6247
- nullifier: nullifier.toString(),
6248
- pubkey: {
6249
- x: newPubkey[0].toString(),
6250
- y: newPubkey[1].toString()
6251
- }
6252
- },
6253
- grantFee
6254
- );
6661
+ return await client.preAddNewKey(keyParams, grantFee, void 0, signupFunds);
6255
6662
  }
6256
- return await client.preAddNewKey(
6257
- {
6258
- d,
6259
- groth16Proof: proof,
6260
- nullifier: nullifier.toString(),
6261
- pubkey: {
6262
- x: newPubkey[0].toString(),
6263
- y: newPubkey[1].toString()
6264
- }
6265
- },
6266
- fee
6267
- );
6663
+ return await client.preAddNewKey(keyParams, fee, void 0, signupFunds);
6268
6664
  }
6269
6665
  async claimAMaciRound({
6270
6666
  signer,
@@ -6851,6 +7247,38 @@ var MaciClient = class {
6851
7247
  }
6852
7248
  return this.saasApiClient;
6853
7249
  }
7250
+ /**
7251
+ * Poll the chain REST endpoint until the given transaction is committed on-chain,
7252
+ * then return its `tx_response` object with an added `status` field.
7253
+ *
7254
+ * @param txHash - On-chain transaction hash to wait for.
7255
+ * @param options.timeout - Max wait time in milliseconds (default: 60 000 ms).
7256
+ * @param options.interval - Polling interval in milliseconds (default: 2 000 ms).
7257
+ * @returns The Cosmos `tx_response` record plus `status`: `'success'` when `code === 0`, `'failed'` otherwise.
7258
+ * @throws If the transaction is not found within the timeout period.
7259
+ */
7260
+ async waitForTransaction(txHash, options = {}) {
7261
+ const timeout = options.timeout ?? 6e4;
7262
+ const interval = options.interval ?? 2e3;
7263
+ const deadline = Date.now() + timeout;
7264
+ while (Date.now() < deadline) {
7265
+ try {
7266
+ const data = await this.http.fetchRest(`/cosmos/tx/v1beta1/txs/${txHash}`);
7267
+ if (data?.tx_response) {
7268
+ const txResponse = data.tx_response;
7269
+ return {
7270
+ ...txResponse,
7271
+ status: txResponse.code === 0 ? "success" : "failed"
7272
+ };
7273
+ }
7274
+ } catch {
7275
+ }
7276
+ await new Promise((resolve) => setTimeout(resolve, interval));
7277
+ }
7278
+ throw new Error(
7279
+ `waitForTransaction: transaction ${txHash} not found on chain within ${timeout}ms`
7280
+ );
7281
+ }
6854
7282
  getMaciKeypair() {
6855
7283
  return this.maciKeypair;
6856
7284
  }
@@ -7014,12 +7442,6 @@ var MaciClient = class {
7014
7442
  async queryRoundClaimable({ contractAddress }) {
7015
7443
  return await this.maci.queryRoundClaimable({ contractAddress });
7016
7444
  }
7017
- async queryAMaciChargeFee({ maxVoter, maxOption }) {
7018
- return await this.maci.queryAMaciChargeFee({
7019
- maxVoter,
7020
- maxOption
7021
- });
7022
- }
7023
7445
  async queryRoundGasStation({ contractAddress }) {
7024
7446
  return await this.maci.queryRoundGasStation({ contractAddress });
7025
7447
  }
@@ -7325,7 +7747,7 @@ var import_snarkjs = require("snarkjs");
7325
7747
 
7326
7748
  // src/libs/keypairs/eddsa-poseidon/keypair.ts
7327
7749
  var import_blake2b = require("@noble/hashes/blake2b");
7328
- var import_utils9 = require("@noble/hashes/utils");
7750
+ var import_utils7 = require("@noble/hashes/utils");
7329
7751
  var import_bip32 = require("@scure/bip32");
7330
7752
  var import_sha2563 = require("@noble/hashes/sha256");
7331
7753
  var import_eddsa_poseidon4 = require("@zk-kit/eddsa-poseidon");
@@ -7536,7 +7958,7 @@ var EdDSAPoseidonKeypair = class _EdDSAPoseidonKeypair extends Keypair3 {
7536
7958
  static fromSecretKey(secretKey, options) {
7537
7959
  if (typeof secretKey === "string") {
7538
7960
  const cleanSecretKey = secretKey.startsWith("0x") ? secretKey.slice(2) : secretKey;
7539
- const decoded = buffer2Bigint((0, import_utils9.hexToBytes)(cleanSecretKey));
7961
+ const decoded = buffer2Bigint((0, import_utils7.hexToBytes)(cleanSecretKey));
7540
7962
  return this.fromSecretKey(decoded, options);
7541
7963
  }
7542
7964
  const unPackedPublicKey = genPubKey(secretKey);
@@ -7544,7 +7966,7 @@ var EdDSAPoseidonKeypair = class _EdDSAPoseidonKeypair extends Keypair3 {
7544
7966
  if (!options || !options.skipValidation) {
7545
7967
  const encoder = new TextEncoder();
7546
7968
  const signData = encoder.encode("dora validation");
7547
- const msgHash = (0, import_utils9.bytesToHex)((0, import_blake2b.blake2b)(signData, { dkLen: 16 }));
7969
+ const msgHash = (0, import_utils7.bytesToHex)((0, import_blake2b.blake2b)(signData, { dkLen: 16 }));
7548
7970
  const signature = (0, import_eddsa_poseidon4.signMessage)(bigInt2Buffer(secretKey), msgHash);
7549
7971
  if (!(0, import_eddsa_poseidon4.verifySignature)(msgHash, signature, unPackedPublicKey)) {
7550
7972
  throw new Error("Provided secretKey is invalid");
@@ -7574,7 +7996,7 @@ var EdDSAPoseidonKeypair = class _EdDSAPoseidonKeypair extends Keypair3 {
7574
7996
  * @returns The secret key encoded as a hexadecimal string
7575
7997
  */
7576
7998
  getSecretKey() {
7577
- return (0, import_utils9.bytesToHex)(bigInt2Buffer(this.keypair.secretKey));
7999
+ return (0, import_utils7.bytesToHex)(bigInt2Buffer(this.keypair.secretKey));
7578
8000
  }
7579
8001
  /**
7580
8002
  * Get the secret key as a bigint.
@@ -8699,6 +9121,39 @@ var VoterClient = class _VoterClient {
8699
9121
  }
8700
9122
  return await this.saasApiClient.preAddNewKey(params);
8701
9123
  }
9124
+ // ==================== Transaction Utilities ====================
9125
+ /**
9126
+ * Poll the chain REST endpoint until the given transaction is committed on-chain,
9127
+ * then return its `tx_response` object with an added `status` field.
9128
+ *
9129
+ * @param txHash - On-chain transaction hash to wait for.
9130
+ * @param options.timeout - Max wait time in milliseconds (default: 60 000 ms).
9131
+ * @param options.interval - Polling interval in milliseconds (default: 2 000 ms).
9132
+ * @returns The Cosmos `tx_response` record plus `status`: `'success'` when `code === 0`, `'failed'` otherwise.
9133
+ * @throws If the transaction is not found within the timeout period.
9134
+ */
9135
+ async waitForTransaction(txHash, options = {}) {
9136
+ const timeout = options.timeout ?? 6e4;
9137
+ const interval = options.interval ?? 2e3;
9138
+ const deadline = Date.now() + timeout;
9139
+ while (Date.now() < deadline) {
9140
+ try {
9141
+ const data = await this.http.fetchRest(`/cosmos/tx/v1beta1/txs/${txHash}`);
9142
+ if (data?.tx_response) {
9143
+ const txResponse = data.tx_response;
9144
+ return {
9145
+ ...txResponse,
9146
+ status: txResponse.code === 0 ? "success" : "failed"
9147
+ };
9148
+ }
9149
+ } catch {
9150
+ }
9151
+ await new Promise((resolve) => setTimeout(resolve, interval));
9152
+ }
9153
+ throw new Error(
9154
+ `waitForTransaction: transaction ${txHash} not found on chain within ${timeout}ms`
9155
+ );
9156
+ }
8702
9157
  // ==================== Maci Voter Methods ====================
8703
9158
  /**
8704
9159
  * Pre-create a new account for AMACI voting (pre-deactivate mode).