diff --git a/src/lib/config.ts b/src/lib/config.ts index 6ae2699..dbbf6cb 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -182,6 +182,7 @@ const defaultUnwrapConfig: RpcConfig['unwrap'] = { // default to 0.01 wnative (18 decimals) minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.01), maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.01), + setTransactionGasLimit: true, balanceCheck: { minGasInWalletThresholdAsMultiplierOfEstimatedTransactionCost: UNWRAP_LIMIT_GAS_AMOUNT_MULTIPLIER, }, @@ -194,6 +195,7 @@ const defaultHarvestConfig: RpcConfig['harvest'] = { minExpectedRewardsWei: bigintMultiplyFloat(ONE_ETHER, 0.002), }, targetTimeBetweenHarvestsMs: HARVEST_AT_LEAST_EVERY_HOURS * 60 * 60 * 1000, + setTransactionGasLimit: true, balanceCheck: { gasLimitMultiplier: HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER, gasPriceMultiplier: HARVEST_GAS_PRICE_MULTIPLIER, @@ -489,6 +491,10 @@ export const RPC_CONFIG: Record = { mantle: { ...defaultConfig, url: RPC_FORCE_URL || process.env.MANTLE_RPC_URL || 'https://rpc.mantle.xyz', + harvest: { + ...defaultHarvestConfig, + setTransactionGasLimit: false, + }, transaction: { ...defaultTransactionConfig, type: 'eip1559', @@ -498,6 +504,7 @@ export const RPC_CONFIG: Record = { ...defaultUnwrapConfig, minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 1), maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 10), + setTransactionGasLimit: false, }, }, metis: { diff --git a/src/lib/harvest-chain.ts b/src/lib/harvest-chain.ts index 3622d2c..21403cb 100644 --- a/src/lib/harvest-chain.ts +++ b/src/lib/harvest-chain.ts @@ -26,6 +26,7 @@ import { UnsupportedChainError } from './harvest-errors'; import { fetchCollectorBalance } from './collector-balance'; import { bigintMultiplyFloat } from '../util/bigint'; import { getChainWNativeTokenAddress } from './addressbook'; +import { HarvestParameters } from './harvest-actions/harvest'; const logger = rootLogger.child({ module: 'harvest-chain' }); @@ -380,20 +381,24 @@ export async function harvestChain({ logger.debug({ msg: 'Harvesting strats', data: { chain, count: stratsToBeHarvested.length } }); await reportOnMultipleHarvestAsyncCall(stratsToBeHarvested, 'transaction', 'sequential', async item => { - const res = VAULT_IDS_WE_SHOULD_BLIND_HARVEST.includes(item.vault.id) - ? await walletClient.harvest({ - strategyAddress: item.vault.strategyAddress, - transactionCostEstimationWei: null, - transactionGasLimit: null, - }) - : await walletClient.harvest({ - strategyAddress: item.vault.strategyAddress, - transactionCostEstimationWei: item.simulation.gas.transactionCostEstimationWei, - transactionGasLimit: bigintMultiplyFloat( - item.simulation.gas.rawGasAmountEstimation, - rpcConfig.harvest.balanceCheck.gasLimitMultiplier - ), - }); + let harvestParams: HarvestParameters = { + strategyAddress: item.vault.strategyAddress, + transactionCostEstimationWei: null, + transactionGasLimit: null, + }; + + if (!VAULT_IDS_WE_SHOULD_BLIND_HARVEST.includes(item.vault.id) && rpcConfig.harvest.setTransactionGasLimit) { + harvestParams = { + strategyAddress: item.vault.strategyAddress, + transactionCostEstimationWei: item.simulation.gas.transactionCostEstimationWei, + transactionGasLimit: bigintMultiplyFloat( + item.simulation.gas.rawGasAmountEstimation, + rpcConfig.harvest.balanceCheck.gasLimitMultiplier + ), + }; + } + + const res = await walletClient.harvest(harvestParams); return { ...res, diff --git a/src/lib/rpc-actions/aggressivelyWriteContract.ts b/src/lib/rpc-actions/aggressivelyWriteContract.ts index 5dc5b39..adf2bf4 100644 --- a/src/lib/rpc-actions/aggressivelyWriteContract.ts +++ b/src/lib/rpc-actions/aggressivelyWriteContract.ts @@ -12,14 +12,13 @@ import { getRpcActionParams } from '../rpc-client'; import { Chain } from '../chain'; import { bigintMultiplyFloat } from '../../util/bigint'; import { cloneDeep } from 'lodash'; -import { RequiredBy } from '../../util/types'; export type AggressivelyWriteContractParameters< TAbi extends Abi | readonly unknown[], TFunctionName extends string, TChain extends ViemChain | undefined, TChainOverride extends ViemChain | undefined, -> = RequiredBy, 'gas'>; +> = SimulateContractParameters; // we return the simulation result and the transaction receipt and hash export type AggressivelyWriteContractReturnType< diff --git a/src/lib/rpc-config.ts b/src/lib/rpc-config.ts index 7a8dfe8..57e0b2b 100644 --- a/src/lib/rpc-config.ts +++ b/src/lib/rpc-config.ts @@ -73,6 +73,9 @@ export type RpcConfig = { // We only harvest if the vault tvl is above this threshold minTvlThresholdUsd: number; + // wether we should set the transaction gas limit + setTransactionGasLimit: boolean; + // these parameters are used to know if we have enough gas to send a transaction balanceCheck: { // by how much we should multiply our given gas price @@ -97,6 +100,9 @@ export type RpcConfig = { // but only if we are low on native maxAmountOfNativeWei: bigint; + // wether we should set the transaction gas limit + setTransactionGasLimit: boolean; + // these parameters are used to know if we have enough gas to send a transaction balanceCheck: { // how much gas we need to have in our wallet to send a transaction diff --git a/src/lib/unwrap-chain.ts b/src/lib/unwrap-chain.ts index 58a8209..704b975 100644 --- a/src/lib/unwrap-chain.ts +++ b/src/lib/unwrap-chain.ts @@ -94,7 +94,7 @@ export async function unwrapChain({ report, chain }: { report: UnwrapReport; cha functionName: 'withdraw', args: [item.unwrapDecision.actualAmount], account: walletAccount, - gas: gasLimit, + gas: rpcConfig.unwrap.setTransactionGasLimit ? gasLimit : undefined, }); logger.debug({ msg: 'Got transaction receipt',