From 884d2bdea7faa0ddd8bff1d42b9fef856f20606f Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Tue, 9 May 2023 09:01:04 +0300 Subject: [PATCH] fix todos add missing logic to send tx --- src/config/Config.ts | 1 - src/utils/ContractUtils.ts | 66 ++++++----------------------- test/unit/FixedRateExchange.test.ts | 3 -- test/unit/veOcean.test.ts | 2 - 4 files changed, 14 insertions(+), 58 deletions(-) diff --git a/src/config/Config.ts b/src/config/Config.ts index be9b0191..5b5b3eeb 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -26,7 +26,6 @@ export class Config { */ public providerUri?: string - // TODO: check if this is still necesary /** * Web3 Provider. * @type {any} diff --git a/src/utils/ContractUtils.ts b/src/utils/ContractUtils.ts index a180bfe7..d9c095cc 100644 --- a/src/utils/ContractUtils.ts +++ b/src/utils/ContractUtils.ts @@ -115,14 +115,25 @@ export async function sendTx( functionToSend: ContractFunction, ...args: any[] ): Promise { - // TODO: update method to use also gasFeeMultiplier const { chainId } = await signer.provider.getNetwork() const feeHistory = await signer.provider.getFeeData() let overrides if (feeHistory.maxPriorityFeePerGas) { + let aggressiveFee = feeHistory.maxPriorityFeePerGas + if (gasFeeMultiplier > 1) { + aggressiveFee = aggressiveFee.mul(gasFeeMultiplier) + } overrides = { - maxPriorityFeePerGas: feeHistory.maxPriorityFeePerGas, - maxFeePerGas: feeHistory.maxFeePerGas + maxPriorityFeePerGas: + (chainId === MUMBAI_NETWORK_ID || chainId === POLYGON_NETWORK_ID) && + aggressiveFee.lte(MIN_GAS_FEE_POLYGON) + ? MIN_GAS_FEE_POLYGON + : aggressiveFee, + maxFeePerGas: + (chainId === MUMBAI_NETWORK_ID || chainId === POLYGON_NETWORK_ID) && + feeHistory.maxFeePerGas.lte(MIN_GAS_FEE_POLYGON) + ? MIN_GAS_FEE_POLYGON + : feeHistory.maxFeePerGas } } else { overrides = { @@ -136,53 +147,4 @@ export async function sendTx( } catch (e) { return null } - /* try { - const feeHistory = await signer.provider,web3.eth.getFeeHistory(1, 'latest', [75]) - if (feeHistory && feeHistory?.baseFeePerGas?.[0] && feeHistory?.reward?.[0]?.[0]) { - let aggressiveFee = new BigNumber(feeHistory?.reward?.[0]?.[0]) - if (gasFeeMultiplier > 1) { - aggressiveFee = aggressiveFee.multipliedBy(gasFeeMultiplier) - } - - sendTxValue.maxPriorityFeePerGas = aggressiveFee - .integerValue(BigNumber.ROUND_DOWN) - .toString(10) - - sendTxValue.maxFeePerGas = aggressiveFee - .plus(new BigNumber(feeHistory?.baseFeePerGas?.[0]).multipliedBy(2)) - .integerValue(BigNumber.ROUND_DOWN) - .toString(10) - - // if network is polygon and mumbai and fees is lower than the 30 gwei trashold, sets MIN_GAS_FEE_POLYGON - sendTxValue.maxPriorityFeePerGas = - (networkId === MUMBAI_NETWORK_ID || networkId === POLYGON_NETWORK_ID) && - new BigNumber(sendTxValue.maxPriorityFeePerGas).lte( - new BigNumber(MIN_GAS_FEE_POLYGON) - ) - ? new BigNumber(MIN_GAS_FEE_POLYGON) - .integerValue(BigNumber.ROUND_DOWN) - .toString(10) - : sendTxValue.maxPriorityFeePerGas - - sendTxValue.maxFeePerGas = - (networkId === MUMBAI_NETWORK_ID || networkId === POLYGON_NETWORK_ID) && - new BigNumber(sendTxValue.maxFeePerGas).lte(new BigNumber(MIN_GAS_FEE_POLYGON)) - ? new BigNumber(MIN_GAS_FEE_POLYGON) - .integerValue(BigNumber.ROUND_DOWN) - .toString(10) - : sendTxValue.maxFeePerGas - } else { - sendTxValue.gasPrice = await getFairGasPrice(web3, gasFeeMultiplier) - } - } catch (err) { - err?.message === FEE_HISTORY_NOT_SUPPORTED && - LoggerInstance.log( - 'Not able to use EIP 1559, getFeeHistory method not suported by network.' - ) - sendTxValue.gasPrice = await getFairGasPrice(web3, gasFeeMultiplier) - } - - const trxReceipt = await functionToSend.apply(null, args).send(sendTxValue) - return trxReceipt - */ } diff --git a/test/unit/FixedRateExchange.test.ts b/test/unit/FixedRateExchange.test.ts index 222dfc6b..f1f73a2c 100644 --- a/test/unit/FixedRateExchange.test.ts +++ b/test/unit/FixedRateExchange.test.ts @@ -246,7 +246,6 @@ describe('Fixed Rate unit test', () => { const tx = await fixedRate.buyDatatokens(exchangeId, amount, maxAmount) const trxReceipt = await tx.wait() const SwappedEvent = getEventFromTx(trxReceipt, 'Swapped') - // console.log(tx.events.Swapped.returnValues) assert(SwappedEvent != null) expect(SwappedEvent.args.exchangeId).to.equal(exchangeId) expect(SwappedEvent.args.by).to.equal(await user1.getAddress()) @@ -464,8 +463,6 @@ describe('Fixed Rate unit test', () => { it('#create an exchange', async () => { // CREATE AN Exchange // we prepare transaction parameters objects - - console.log(' addresses: ', addresses) const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner) const freParams: FreCreationParams = { diff --git a/test/unit/veOcean.test.ts b/test/unit/veOcean.test.ts index b8b51eb0..ab475261 100644 --- a/test/unit/veOcean.test.ts +++ b/test/unit/veOcean.test.ts @@ -128,8 +128,6 @@ describe('veOcean tests', () => { const tx = await veOcean.increaseUnlockTime(newLock) await tx.wait() const newCurrentLock = await veOcean.lockEnd(await Alice.getAddress()) - console.log(currentLock) - console.log(newCurrentLock) assert(newCurrentLock > currentLock, 'Lock time should change"') })