diff --git a/src/contracts/Datatoken.ts b/src/contracts/Datatoken.ts index 5a6e99ac..918a4f47 100644 --- a/src/contracts/Datatoken.ts +++ b/src/contracts/Datatoken.ts @@ -73,7 +73,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.approve, spender, this.web3.utils.toWei(amount) @@ -129,7 +129,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.createFixedRate, fixedRateParams.fixedRateAddress, [ @@ -191,7 +191,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.createDispenser, dispenserAddress, dispenserParams.maxTokens, @@ -237,7 +237,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.mint, toAddress || address, this.web3.utils.toWei(amount) @@ -279,7 +279,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.addMinter, minter ) @@ -319,7 +319,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.removeMinter, minter ) @@ -358,7 +358,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.addPaymentManager, paymentManager ) @@ -397,7 +397,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.removePaymentManager, paymentManager ) @@ -443,7 +443,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.setPaymentCollector, paymentCollector ) @@ -507,7 +507,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.transfer, toAddress, amount @@ -556,7 +556,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.startOrder, consumer, serviceIndex, @@ -596,7 +596,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.reuseOrder, orderTxId, providerFees @@ -634,7 +634,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.buyFromFreAndOrder, orderParams, freContractParams @@ -670,7 +670,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.buyFromDispenserAndOrder, orderParams, dispenserContract @@ -711,7 +711,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.setData, valueHex ) @@ -746,7 +746,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.cleanPermissions ) @@ -856,7 +856,7 @@ export class Datatoken extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, dtContract.methods.setPublishingMarketFee, publishMarketFeeAddress, publishMarketFeeToken, diff --git a/src/contracts/Dispenser.ts b/src/contracts/Dispenser.ts index d63a1f73..0a14d5d1 100644 --- a/src/contracts/Dispenser.ts +++ b/src/contracts/Dispenser.ts @@ -61,7 +61,7 @@ export class Dispenser extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.create, dtAddress, this.web3.utils.toWei(maxTokens), @@ -101,7 +101,7 @@ export class Dispenser extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.activate, dtAddress, this.web3.utils.toWei(maxTokens), @@ -133,7 +133,7 @@ export class Dispenser extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.deactivate, dtAddress ) @@ -166,7 +166,7 @@ export class Dispenser extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.setAllowedSwapper, dtAddress, newAllowedSwapper @@ -204,7 +204,7 @@ export class Dispenser extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.dispense, dtAddress, this.web3.utils.toWei(amount), @@ -235,7 +235,7 @@ export class Dispenser extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.ownerWithdraw, dtAddress ) diff --git a/src/contracts/FixedRateExchange.ts b/src/contracts/FixedRateExchange.ts index a1d0fa52..92297110 100644 --- a/src/contracts/FixedRateExchange.ts +++ b/src/contracts/FixedRateExchange.ts @@ -70,7 +70,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.buyDT, exchangeId, dtAmountFormatted, @@ -128,7 +128,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.sellDT, exchangeId, dtAmountFormatted, @@ -175,7 +175,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.setRate, exchangeId, this.web3.utils.toWei(newRate) @@ -209,7 +209,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.setAllowedSwapper, exchangeId, newAllowedSwapper @@ -242,7 +242,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.toggleExchangeState, exchangeId ) @@ -275,7 +275,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.toggleExchangeState, exchangeId ) @@ -510,7 +510,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.toggleMintState, exchangeId, true @@ -545,7 +545,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.toggleMintState, exchangeId, false @@ -590,7 +590,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.collectBT, exchangeId, amountWei @@ -635,7 +635,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.collectDT, exchangeId, amountWei @@ -668,7 +668,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.collectMarketFee, exchangeId ) @@ -701,7 +701,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.collectOceanFee, exchangeId ) @@ -762,7 +762,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.updateMarketFee, exchangeId, this.web3.utils.toWei(newMarketFee) @@ -796,7 +796,7 @@ export class FixedRateExchange extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.updateMarketFeeCollector, exchangeId, newMarketFeeCollector diff --git a/src/contracts/NFT.ts b/src/contracts/NFT.ts index ef28653f..36f576cd 100644 --- a/src/contracts/NFT.ts +++ b/src/contracts/NFT.ts @@ -67,7 +67,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.createERC20, templateIndex, [name, symbol], @@ -109,7 +109,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.addManager, manager ) @@ -147,7 +147,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.removeManager, manager ) @@ -186,7 +186,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.addToCreateERC20List, datatokenDeployer ) @@ -227,7 +227,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.removeFromCreateERC20List, datatokenDeployer ) @@ -265,7 +265,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.addToMetadataList, metadataUpdater ) @@ -306,7 +306,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.removeFromMetadataList, metadataUpdater ) @@ -343,7 +343,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.addTo725StoreList, storeUpdater ) @@ -385,7 +385,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.removeFrom725StoreList, storeUpdater ) @@ -423,7 +423,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.cleanPermissions ) @@ -467,7 +467,7 @@ export class Nft extends SmartContract { nftOwner, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.transferFrom, nftOwner, nftReceiver, @@ -514,7 +514,7 @@ export class Nft extends SmartContract { nftOwner, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.safeTransferFrom, nftOwner, nftReceiver, @@ -570,7 +570,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.setMetaData, metadataState, metadataDecryptorUrl, @@ -616,7 +616,7 @@ export class Nft extends SmartContract { metadataUpdater, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.setMetaDataAndTokenURI, sanitizedMetadataAndTokenURI ) @@ -654,7 +654,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.setMetaDataState, metadataState ) @@ -687,7 +687,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.setTokenURI, '1', data @@ -774,7 +774,7 @@ export class Nft extends SmartContract { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, nftContract.methods.setNewData, keyHash, valueHex diff --git a/src/contracts/NFTFactory.ts b/src/contracts/NFTFactory.ts index 7a759cbf..deb09908 100644 --- a/src/contracts/NFTFactory.ts +++ b/src/contracts/NFTFactory.ts @@ -68,7 +68,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.deployERC721Contract, nftData.name, nftData.symbol, @@ -194,7 +194,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.add721TokenTemplate, templateAddress ) @@ -233,7 +233,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.disable721TokenTemplate, templateIndex ) @@ -274,7 +274,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.reactivate721TokenTemplate, templateIndex ) @@ -311,7 +311,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.addTokenTemplate, templateAddress ) @@ -354,7 +354,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.disableTokenTemplate, templateIndex ) @@ -398,7 +398,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.reactivateTokenTemplate, templateIndex ) @@ -438,7 +438,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.startMultipleTokenOrder, orders ) @@ -475,7 +475,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.createNftWithErc20, nftCreateData, ercCreateData @@ -517,7 +517,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.createNftWithErc20WithFixedRate, nftCreateData, ercCreateData, @@ -562,7 +562,7 @@ export class NftFactory extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.createNftWithErc20WithDispenser, nftCreateData, ercCreateData, diff --git a/src/contracts/Router.ts b/src/contracts/Router.ts index 15c4fe4e..a7042386 100644 --- a/src/contracts/Router.ts +++ b/src/contracts/Router.ts @@ -35,7 +35,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.buyDTBatch, operations ) @@ -97,7 +97,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.addApprovedToken, tokenAddress ) @@ -131,7 +131,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.removeApprovedToken, tokenAddress ) @@ -164,7 +164,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.addFixedRateContract, tokenAddress ) @@ -198,7 +198,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.removeFixedRateContract, tokenAddress ) @@ -232,7 +232,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.addDispenserContract, tokenAddress ) @@ -265,7 +265,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.removeDispenserContract, tokenAddress ) @@ -321,7 +321,7 @@ export class Router extends SmartContractWithAddress { address, estGas + 1, this.web3, - this.config, + this.config?.gasFeeMultiplier, this.contract.methods.updateOPCFee, newSwapOceanFee, newSwapNonOceanFee, diff --git a/src/contracts/SmartContract.ts b/src/contracts/SmartContract.ts index d7430ac3..fc3ec70f 100644 --- a/src/contracts/SmartContract.ts +++ b/src/contracts/SmartContract.ts @@ -51,7 +51,7 @@ export abstract class SmartContract { } protected async getFairGasPrice(): Promise { - return getFairGasPrice(this.web3, this.config) + return getFairGasPrice(this.web3, this.config?.gasFeeMultiplier) } protected getContract( diff --git a/src/utils/ContractUtils.ts b/src/utils/ContractUtils.ts index 6fa6eb66..d6eff2b2 100644 --- a/src/utils/ContractUtils.ts +++ b/src/utils/ContractUtils.ts @@ -16,20 +16,14 @@ export function setContractDefaults(contract: Contract, config: Config): Contrac return contract } -export async function networkSupportsEip1559(web3: Web3): Promise { - const feeHistory = await web3.eth.getFeeHistory(4, 'pending', [25, 50, 75]) - if (feeHistory && feeHistory.baseFeePerGas) { - return true - } else { - return false - } -} - -export async function getFairGasPrice(web3: Web3, config: Config): Promise { +export async function getFairGasPrice( + web3: Web3, + gasFeeMultiplier: number +): Promise { const x = new BigNumber(await web3.eth.getGasPrice()) - if (config && config.gasFeeMultiplier) + if (gasFeeMultiplier) return x - .multipliedBy(config.gasFeeMultiplier) + .multipliedBy(gasFeeMultiplier) .integerValue(BigNumber.ROUND_DOWN) .toString(10) else return x.toString(10) @@ -97,7 +91,7 @@ export async function calculateEstimatedGas( * @param {string} from account that calls the function * @param {any} estGas estimated gas for the transaction * @param {Web3} web3 web3 objcet - * @param {Function} functionToEstimateGas function that we need to send + * @param {Function} functionToSend function that we need to send * @param {...any[]} args arguments of the function * @return {Promise} transaction receipt */ @@ -105,7 +99,7 @@ export async function sendTx( from: string, estGas: any, web3: Web3, - config: Config, + gasFeeMultiplier: number, functionToSend: Function, ...args: any[] ): Promise { @@ -116,8 +110,8 @@ export async function sendTx( try { const feeHistory = await web3.eth.getFeeHistory(1, 'latest', [75]) let aggressiveFee = new BigNumber(feeHistory?.reward?.[0]?.[0]) - if (this.config?.gasFeeMultiplier > 1) { - aggressiveFee = aggressiveFee.multipliedBy(this.config?.gasFeeMultiplier) + if (gasFeeMultiplier > 1) { + aggressiveFee = aggressiveFee.multipliedBy(gasFeeMultiplier) } sendTxValue.maxPriorityFeePerGas = aggressiveFee @@ -130,7 +124,7 @@ export async function sendTx( .toString(10) } catch (err) { LoggerInstance.error('Not able to use EIP 1559.') - sendTxValue.gasPrice = await getFairGasPrice(web3, config) + sendTxValue.gasPrice = await getFairGasPrice(web3, gasFeeMultiplier) } const trxReceipt = await functionToSend.apply(null, args).send(sendTxValue) diff --git a/src/utils/TokenUtils.ts b/src/utils/TokenUtils.ts index 8e8067c6..2e135160 100644 --- a/src/utils/TokenUtils.ts +++ b/src/utils/TokenUtils.ts @@ -52,7 +52,7 @@ export async function approve( account, estGas + 1, web3, - config, + config?.gasFeeMultiplier, tokenContract.methods.approve, spender, amountFormatted @@ -100,7 +100,7 @@ export async function approveWei( account, estGas + 1, web3, - config, + config?.gasFeeMultiplier, tokenContract.methods.approve, spender, amount @@ -145,7 +145,7 @@ export async function transfer( account, estGas + 1, web3, - config, + config?.gasFeeMultiplier, tokenContract.methods.transfer, recipient, amountFormatted