From b451db80f74cf5282a4f0ebd459b721d1803e327 Mon Sep 17 00:00:00 2001 From: emmdim Date: Tue, 9 Jan 2024 14:56:15 +0100 Subject: [PATCH] Implements estimation for approve tally with execution --- packages/js-client/src/internal/interfaces.ts | 1 + .../src/internal/modules/estimation.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/js-client/src/internal/interfaces.ts b/packages/js-client/src/internal/interfaces.ts index e929ae3b..392f232e 100644 --- a/packages/js-client/src/internal/interfaces.ts +++ b/packages/js-client/src/internal/interfaces.ts @@ -101,6 +101,7 @@ export interface IGaslessVotingClientEstimation { results: bigint[][] ): Promise; approve(proposalId: string): Promise; + approveTally(proposalId: string, tryExecution: boolean): Promise; executeProposal(proposalId: string): Promise; // Add any estimation methods that you need } diff --git a/packages/js-client/src/internal/modules/estimation.ts b/packages/js-client/src/internal/modules/estimation.ts index e28d3588..c08b9e69 100644 --- a/packages/js-client/src/internal/modules/estimation.ts +++ b/packages/js-client/src/internal/modules/estimation.ts @@ -142,6 +142,28 @@ export class GaslessVotingClientEstimation return this.web3.getApproximateGasFee(estimatedGasFee.toBigInt()); } + /** + * Estimates the gas fee of creating a proposal on the plugin + * + * @param {ApproveParams} params + * @return {*} {Promise} + * @memberof GaslessVotingClientEstimation + */ + public async approveTally(proposalId: string, tryExecution=false): Promise { + const signer = this.web3.getConnectedSigner(); + const { pluginAddress, id } = decodeProposalId(proposalId); + + const gaslessVotingContract = VocdoniVoting__factory.connect( + pluginAddress, + signer + ); + + + const estimatedGasFee = await gaslessVotingContract.estimateGas.approveTally(id, tryExecution); + + return this.web3.getApproximateGasFee(estimatedGasFee.toBigInt()); + } + /** * Estimates the gas fee of creating a proposal on the plugin *