From 95d50bdd61e1e79db9e76a5465b60fb962e3a09d Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Mon, 13 Jun 2022 10:41:54 +0200 Subject: [PATCH] add estimateGas parameter to Dispenser --- src/contracts/pools/Dispenser.ts | 48 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/contracts/pools/Dispenser.ts b/src/contracts/pools/Dispenser.ts index 749c67e5..41ab6cd7 100644 --- a/src/contracts/pools/Dispenser.ts +++ b/src/contracts/pools/Dispenser.ts @@ -38,13 +38,14 @@ export class Dispenser extends SmartContractWithAddress { * @param {String} allowedSwapper only account that can ask tokens. set address(0) if not required * @return {Promise} transactionId */ - public async create( + public async create( dtAddress: string, address: string, maxTokens: string, maxBalance: string, - allowedSwapper: string - ): Promise { + allowedSwapper: string, + estimateGas?: G + ): Promise { const estGas = await calculateEstimatedGas( address, this.contract.methods.create, @@ -54,6 +55,7 @@ export class Dispenser extends SmartContractWithAddress { address, allowedSwapper ) + if (estimateGas) return estGas // Call createFixedRate contract method const trxReceipt = await this.contract.methods @@ -80,12 +82,13 @@ export class Dispenser extends SmartContractWithAddress { * @param {String} address User address (must be owner of the datatoken) * @return {Promise} TransactionReceipt */ - public async activate( + public async activate( dtAddress: string, maxTokens: string, maxBalance: string, - address: string - ): Promise { + address: string, + estimateGas?: G + ): Promise { try { const estGas = await calculateEstimatedGas( address, @@ -94,6 +97,7 @@ export class Dispenser extends SmartContractWithAddress { this.web3.utils.toWei(maxTokens), this.web3.utils.toWei(maxBalance) ) + if (estimateGas) return estGas const trxReceipt = await this.contract.methods .activate( @@ -119,16 +123,18 @@ export class Dispenser extends SmartContractWithAddress { * @param {String} address User address (must be owner of the datatoken) * @return {Promise} TransactionReceipt */ - public async deactivate( + public async deactivate( dtAddress: string, - address: string - ): Promise { + address: string, + estimateGas?: G + ): Promise { try { const estGas = await calculateEstimatedGas( address, this.contract.methods.deactivate, dtAddress ) + if (estimateGas) return estGas const trxReceipt = await this.contract.methods.deactivate(dtAddress).send({ from: address, @@ -149,11 +155,12 @@ export class Dispenser extends SmartContractWithAddress { * @param {String} newAllowedSwapper refers to the new allowedSwapper * @return {Promise} TransactionReceipt */ - public async setAllowedSwapper( + public async setAllowedSwapper( dtAddress: string, address: string, - newAllowedSwapper: string - ): Promise { + newAllowedSwapper: string, + estimateGas?: G + ): Promise { try { const estGas = await calculateEstimatedGas( address, @@ -161,6 +168,7 @@ export class Dispenser extends SmartContractWithAddress { dtAddress, newAllowedSwapper ) + if (estimateGas) return estGas const trxReceipt = await this.contract.methods .setAllowedSwapper(dtAddress, newAllowedSwapper) @@ -186,12 +194,13 @@ export class Dispenser extends SmartContractWithAddress { * @param {String} destination who will receive the tokens * @return {Promise} TransactionReceipt */ - public async dispense( + public async dispense( dtAddress: string, address: string, amount: string = '1', - destination: string - ): Promise { + destination: string, + estimateGas?: G + ): Promise { const estGas = await calculateEstimatedGas( address, this.contract.methods.dispense, @@ -199,6 +208,7 @@ export class Dispenser extends SmartContractWithAddress { this.web3.utils.toWei(amount), destination ) + if (estimateGas) return estGas try { const trxReceipt = await this.contract.methods @@ -221,15 +231,17 @@ export class Dispenser extends SmartContractWithAddress { * @param {String} address User address (must be owner of the dispenser) * @return {Promise} TransactionReceipt */ - public async ownerWithdraw( + public async ownerWithdraw( dtAddress: string, - address: string - ): Promise { + address: string, + estimateGas?: G + ): Promise { const estGas = await calculateEstimatedGas( address, this.contract.methods.ownerWithdraw, dtAddress ) + if (estimateGas) return estGas try { const trxReceipt = await this.contract.methods.ownerWithdraw(dtAddress).send({