From 1ad548e5258429c639821830cb2a56cdcb55a620 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 24 Feb 2026 08:06:18 +0200 Subject: [PATCH 1/2] fix gas calculation --- src/utils/blockchain.ts | 72 ++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/src/utils/blockchain.ts b/src/utils/blockchain.ts index 11edf4473..b0d0a3ded 100644 --- a/src/utils/blockchain.ts +++ b/src/utils/blockchain.ts @@ -185,58 +185,34 @@ export class Blockchain { } else return x.toString() } - public async getGasOptions(estGas: bigint, gasFeeMultiplier: number): Promise<{}> { + public async getGasOptions(estGas: bigint, gasFeeMultiplier: number) { const { chainId } = await this.signer.provider.getNetwork() - const feeHistory = await this.signer.provider.getFeeData() - const gasLimit = estGas + BigInt(20000) + const feeData = await this.signer.provider.getFeeData() + const gasLimit = estGas + 20_000n - if (feeHistory.maxPriorityFeePerGas) { - let aggressiveFeePriorityFeePerGas = feeHistory.maxPriorityFeePerGas.toString() - let aggressiveFeePerGas = feeHistory.maxFeePerGas.toString() - if (gasFeeMultiplier > 1) { - aggressiveFeePriorityFeePerGas = ( - (feeHistory.maxPriorityFeePerGas * BigInt(gasFeeMultiplier * 100)) / - BigInt(100) - ).toString() - aggressiveFeePerGas = ( - (feeHistory.maxFeePerGas * BigInt(gasFeeMultiplier * 100)) / - BigInt(100) - ).toString() - } - const overrides = { - gasLimit, - maxPriorityFeePerGas: - (chainId === BigInt(MUMBAI_NETWORK_ID) || - chainId === BigInt(POLYGON_NETWORK_ID)) && - Number(aggressiveFeePriorityFeePerGas) < MIN_GAS_FEE_POLYGON - ? MIN_GAS_FEE_POLYGON - : chainId === BigInt(SEPOLIA_NETWORK_ID) && - Number(aggressiveFeePriorityFeePerGas) < MIN_GAS_FEE_SEPOLIA - ? MIN_GAS_FEE_SEPOLIA - : KNOWN_CONFIDENTIAL_EVMS.includes(chainId) && - Number(aggressiveFeePriorityFeePerGas) < MIN_GAS_FEE_SAPPHIRE - ? MIN_GAS_FEE_SAPPHIRE - : Number(aggressiveFeePriorityFeePerGas), - maxFeePerGas: - (chainId === BigInt(MUMBAI_NETWORK_ID) || - chainId === BigInt(POLYGON_NETWORK_ID)) && - Number(aggressiveFeePerGas) < MIN_GAS_FEE_POLYGON - ? MIN_GAS_FEE_POLYGON - : chainId === BigInt(SEPOLIA_NETWORK_ID) && - Number(aggressiveFeePerGas) < MIN_GAS_FEE_SEPOLIA - ? MIN_GAS_FEE_SEPOLIA - : KNOWN_CONFIDENTIAL_EVMS.includes(chainId) && - Number(aggressiveFeePerGas) < MIN_GAS_FEE_SAPPHIRE - ? MIN_GAS_FEE_SAPPHIRE - : Number(aggressiveFeePerGas) - } - return overrides - } else { - const overrides = { + if (feeData.maxPriorityFeePerGas) { + const multiplier = BigInt(Math.round(gasFeeMultiplier * 100)) + + const priority = (feeData.maxPriorityFeePerGas * multiplier) / 100n + const maxFee = (feeData.maxFeePerGas * multiplier) / 100n + + const minFee = + chainId === BigInt(POLYGON_NETWORK_ID) || chainId === BigInt(MUMBAI_NETWORK_ID) + ? MIN_GAS_FEE_POLYGON + : KNOWN_CONFIDENTIAL_EVMS.includes(chainId) + ? MIN_GAS_FEE_SAPPHIRE + : 0n + + return { gasLimit, - gasPrice: feeHistory.gasPrice + maxPriorityFeePerGas: priority < minFee ? minFee : priority, + maxFeePerGas: maxFee < minFee ? minFee : maxFee } - return overrides + } + + return { + gasLimit, + gasPrice: feeData.gasPrice } } } From 8d8d453671edd717f80e4f023e3522457bdde99a Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 24 Feb 2026 08:08:24 +0200 Subject: [PATCH 2/2] lint --- src/utils/blockchain.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/blockchain.ts b/src/utils/blockchain.ts index b0d0a3ded..da6ccc55f 100644 --- a/src/utils/blockchain.ts +++ b/src/utils/blockchain.ts @@ -20,11 +20,11 @@ import { OceanNodeConfig } from '../@types/OceanNode.js' import { KeyManager } from '../components/KeyManager/index.js' const MIN_GAS_FEE_POLYGON = 30000000000 // minimum recommended 30 gwei polygon main and mumbai fees -const MIN_GAS_FEE_SEPOLIA = 4000000000 // minimum 4 gwei for eth sepolia testnet +// const MIN_GAS_FEE_SEPOLIA = 4000000000 // minimum 4 gwei for eth sepolia testnet const MIN_GAS_FEE_SAPPHIRE = 10000000000 // recommended for mainnet and testnet 10 gwei const POLYGON_NETWORK_ID = 137 const MUMBAI_NETWORK_ID = 80001 -const SEPOLIA_NETWORK_ID = 11155111 +// const SEPOLIA_NETWORK_ID = 11155111 export class Blockchain { private config?: OceanNodeConfig // Optional for new constructor