Skip to content

Commit

Permalink
Remove mantle gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Mar 23, 2024
1 parent 65a159f commit 6c488de
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
Expand Down Expand Up @@ -489,6 +491,10 @@ export const RPC_CONFIG: Record<Chain, RpcConfig> = {
mantle: {
...defaultConfig,
url: RPC_FORCE_URL || process.env.MANTLE_RPC_URL || 'https://rpc.mantle.xyz',
harvest: {
...defaultHarvestConfig,
setTransactionGasLimit: false,
},
transaction: {
...defaultTransactionConfig,
type: 'eip1559',
Expand All @@ -498,6 +504,7 @@ export const RPC_CONFIG: Record<Chain, RpcConfig> = {
...defaultUnwrapConfig,
minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 1),
maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 10),
setTransactionGasLimit: false,
},
},
metis: {
Expand Down
33 changes: 19 additions & 14 deletions src/lib/harvest-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/lib/rpc-actions/aggressivelyWriteContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimulateContractParameters<TAbi, TFunctionName, TChain, TChainOverride>, 'gas'>;
> = SimulateContractParameters<TAbi, TFunctionName, TChain, TChainOverride>;

// we return the simulation result and the transaction receipt and hash
export type AggressivelyWriteContractReturnType<
Expand Down
6 changes: 6 additions & 0 deletions src/lib/rpc-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/unwrap-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6c488de

Please sign in to comment.