diff --git a/src/contracts/pools/Dispenser.ts b/src/contracts/pools/Dispenser.ts index 6cbef643..d285c79c 100644 --- a/src/contracts/pools/Dispenser.ts +++ b/src/contracts/pools/Dispenser.ts @@ -17,16 +17,11 @@ export class Dispenser extends SmartContractWithAddress { * @return {Promise} Exchange details */ public async status(dtAdress: string): Promise { - try { - const status: DispenserToken = await this.contract.methods.status(dtAdress).call() - status.maxTokens = this.web3.utils.fromWei(status.maxTokens) - status.maxBalance = this.web3.utils.fromWei(status.maxBalance) - status.balance = this.web3.utils.fromWei(status.balance) - return status - } catch (e) { - LoggerInstance.warn(`No dispenser available for datatoken: ${dtAdress}`) - } - return null + const status: DispenserToken = await this.contract.methods.status(dtAdress).call() + status.maxTokens = this.web3.utils.fromWei(status.maxTokens) + status.maxBalance = this.web3.utils.fromWei(status.maxBalance) + status.balance = this.web3.utils.fromWei(status.balance) + return status } /** @@ -89,32 +84,27 @@ export class Dispenser extends SmartContractWithAddress { address: string, estimateGas?: G ): Promise { - try { - const estGas = await calculateEstimatedGas( - address, - this.contract.methods.activate, + const estGas = await calculateEstimatedGas( + address, + this.contract.methods.activate, + dtAddress, + this.web3.utils.toWei(maxTokens), + this.web3.utils.toWei(maxBalance) + ) + if (estimateGas) return estGas + + const trxReceipt = await this.contract.methods + .activate( dtAddress, this.web3.utils.toWei(maxTokens), this.web3.utils.toWei(maxBalance) ) - if (estimateGas) return estGas - - const trxReceipt = await this.contract.methods - .activate( - dtAddress, - this.web3.utils.toWei(maxTokens), - this.web3.utils.toWei(maxBalance) - ) - .send({ - from: address, - gas: estGas + 1, - gasPrice: await this.getFairGasPrice() - }) - return trxReceipt - } catch (e) { - LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`) - } - return null + .send({ + from: address, + gas: estGas + 1, + gasPrice: await this.getFairGasPrice() + }) + return trxReceipt } /** @@ -128,24 +118,19 @@ export class Dispenser extends SmartContractWithAddress { address: string, estimateGas?: G ): Promise { - try { - const estGas = await calculateEstimatedGas( - address, - this.contract.methods.deactivate, - dtAddress - ) - if (estimateGas) return estGas + 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, - gas: estGas + 1, - gasPrice: await this.getFairGasPrice() - }) - return trxReceipt - } catch (e) { - LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`) - } - return null + const trxReceipt = await this.contract.methods.deactivate(dtAddress).send({ + from: address, + gas: estGas + 1, + gasPrice: await this.getFairGasPrice() + }) + return trxReceipt } /** @@ -161,27 +146,22 @@ export class Dispenser extends SmartContractWithAddress { newAllowedSwapper: string, estimateGas?: G ): Promise { - try { - const estGas = await calculateEstimatedGas( - address, - this.contract.methods.setAllowedSwapper, - dtAddress, - newAllowedSwapper - ) - if (estimateGas) return estGas + const estGas = await calculateEstimatedGas( + address, + this.contract.methods.setAllowedSwapper, + dtAddress, + newAllowedSwapper + ) + if (estimateGas) return estGas - const trxReceipt = await this.contract.methods - .setAllowedSwapper(dtAddress, newAllowedSwapper) - .send({ - from: address, - gas: estGas + 1, - gasPrice: await this.getFairGasPrice() - }) - return trxReceipt - } catch (e) { - LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`) - } - return null + const trxReceipt = await this.contract.methods + .setAllowedSwapper(dtAddress, newAllowedSwapper) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await this.getFairGasPrice() + }) + return trxReceipt } /** @@ -210,19 +190,14 @@ export class Dispenser extends SmartContractWithAddress { ) if (estimateGas) return estGas - try { - const trxReceipt = await this.contract.methods - .dispense(dtAddress, this.web3.utils.toWei(amount), destination) - .send({ - from: address, - gas: estGas + 1, - gasPrice: await this.getFairGasPrice() - }) - return trxReceipt - } catch (e) { - LoggerInstance.error(`ERROR: Failed to dispense tokens: ${e.message}`) - } - return null + const trxReceipt = await this.contract.methods + .dispense(dtAddress, this.web3.utils.toWei(amount), destination) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await this.getFairGasPrice() + }) + return trxReceipt } /** @@ -243,17 +218,12 @@ export class Dispenser extends SmartContractWithAddress { ) if (estimateGas) return estGas - try { - const trxReceipt = await this.contract.methods.ownerWithdraw(dtAddress).send({ - from: address, - gas: estGas + 1, - gasPrice: await this.getFairGasPrice() - }) - return trxReceipt - } catch (e) { - LoggerInstance.error(`ERROR: Failed to withdraw tokens: ${e.message}`) - } - return null + const trxReceipt = await this.contract.methods.ownerWithdraw(dtAddress).send({ + from: address, + gas: estGas + 1, + gasPrice: await this.getFairGasPrice() + }) + return trxReceipt } /**