diff --git a/src/pools/Router.ts b/src/pools/Router.ts index e1606b32..bef064c2 100644 --- a/src/pools/Router.ts +++ b/src/pools/Router.ts @@ -278,6 +278,54 @@ export class Router { return trxReceipt } + /** + * Estimate gas cost for removeSSContract method + * @param {String} address caller address + * @param {String} tokenAddress contract address to add + * @return {Promise} + */ + public async estGasRemoveSSContract( + address: string, + tokenAddress: string + ): Promise { + const gasLimitDefault = this.GASLIMIT_DEFAULT + let estGas + try { + estGas = await this.router.methods + .removeSSContract(tokenAddress) + .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) + } catch (e) { + estGas = gasLimitDefault + } + + return estGas + } + + /** + * Removes a new contract from ssContract list + * @param {String} address caller address + * @param {String} tokenAddress contract address to removed + * @return {Promise} + */ + public async removeSSContract( + address: string, + tokenAddress: string + ): Promise { + if ((await this.getOwner()) !== address) { + throw new Error(`Caller is not Router Owner`) + } + + const estGas = await this.estGasRemoveSSContract(address, tokenAddress) + // Invoke createToken function of the contract + const trxReceipt = await this.router.methods.removeSSContract(tokenAddress).send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3) + }) + + return trxReceipt + } + /** * Estimate gas cost for addFixedRateContract method * @param {String} address @@ -327,6 +375,157 @@ export class Router { return trxReceipt } + /** + * Estimate gas cost for addFixedRateContract method + * @param {String} address + * @param {String} tokenAddress contract address to add + * @return {Promise} + */ + public async estGasRemoveFixedRateContract( + address: string, + tokenAddress: string + ): Promise { + const gasLimitDefault = this.GASLIMIT_DEFAULT + let estGas + try { + estGas = await this.router.methods + .removeFixedRateContract(tokenAddress) + .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) + } catch (e) { + estGas = gasLimitDefault + } + + return estGas + } + + /** + * Removes a contract from fixedRate list + * @param {String} address + * @param {String} tokenAddress contract address to add + * @return {Promise} + */ + public async removeFixedRateContract( + address: string, + tokenAddress: string + ): Promise { + if ((await this.getOwner()) !== address) { + throw new Error(`Caller is not Router Owner`) + } + + const estGas = await this.estGasRemoveFixedRateContract(address, tokenAddress) + + // Invoke removeFixedRateContract function of the contract + const trxReceipt = await this.router.methods + .removeFixedRateContract(tokenAddress) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3) + }) + + return trxReceipt + } + + /** + * Estimate gas cost for addDispenserContract method + * @param {String} address + * @param {String} tokenAddress contract address to add + * @return {Promise} + */ + public async estGasAddDispenserContract( + address: string, + tokenAddress: string + ): Promise { + const gasLimitDefault = this.GASLIMIT_DEFAULT + let estGas + try { + estGas = await this.router.methods + .addDispenserContract(tokenAddress) + .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) + } catch (e) { + estGas = gasLimitDefault + } + + return estGas + } + + /** + * Add a new contract to dispenser list, after is added, can be used when deploying a new pool + * @param {String} address + * @param {String} tokenAddress contract address to add + * @return {Promise} + */ + public async addDispenserContract( + address: string, + tokenAddress: string + ): Promise { + if ((await this.getOwner()) !== address) { + throw new Error(`Caller is not Router Owner`) + } + + const estGas = await this.estGasAddDispenserContract(address, tokenAddress) + + // Invoke createToken function of the contract + const trxReceipt = await this.router.methods.addDispenserContract(tokenAddress).send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3) + }) + + return trxReceipt + } + + /** + * Estimate gas cost for addDispenserContract method + * @param {String} address + * @param {String} tokenAddress contract address to add + * @return {Promise} + */ + public async estGasRemoveDispenserContract( + address: string, + tokenAddress: string + ): Promise { + const gasLimitDefault = this.GASLIMIT_DEFAULT + let estGas + try { + estGas = await this.router.methods + .removeDispenserContract(tokenAddress) + .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) + } catch (e) { + estGas = gasLimitDefault + } + + return estGas + } + + /** + * Add a new contract to dispenser list, after is added, can be used when deploying a new pool + * @param {String} address + * @param {String} tokenAddress contract address to add + * @return {Promise} + */ + public async removeDispenserContract( + address: string, + tokenAddress: string + ): Promise { + if ((await this.getOwner()) !== address) { + throw new Error(`Caller is not Router Owner`) + } + + const estGas = await this.estGasRemoveDispenserContract(address, tokenAddress) + + // Invoke createToken function of the contract + const trxReceipt = await this.router.methods + .removeDispenserContract(tokenAddress) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3) + }) + + return trxReceipt + } + /** Get OPF Fee per token * @return {Promise} OPF fee for a specific baseToken */