Skip to content

Commit

Permalink
feat: remove 2nd gas estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
toniocodo committed Aug 2, 2024
1 parent 4ea23fb commit fd438bf
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions libs/shared/routes/src/oeth/swapBalancerOeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '@wagmi/core';
import { erc20Abi, formatUnits } from 'viem';

import { GAS_BUFFER } from '../constants';
import { defaultRoute } from '../defaultRoute';

import type {
Expand Down Expand Up @@ -85,6 +84,7 @@ const estimateGas: EstimateGas = async (
{ tokenIn, tokenOut, amountIn, slippage, amountOut },
) => {
let gasEstimate = 0n;
const { address } = getAccount(config);
const publicClient = getPublicClient(config, { chainId: tokenIn.chainId });

if (
Expand Down Expand Up @@ -116,17 +116,15 @@ const estimateGas: EstimateGas = async (
userData: defaultUserData,
},
{
recipient: ZERO_ADDRESS,
sender: ZERO_ADDRESS,
recipient: address ?? ZERO_ADDRESS,
sender: address ?? ZERO_ADDRESS,
fromInternalBalance: false,
toInternalBalance: false,
},
minAmountOut[0],
deadline,
],
});

console.log(gasEstimate);
} catch {
gasEstimate = 220_000n;
}
Expand Down Expand Up @@ -269,18 +267,6 @@ const swap: Swap = async (
slippage,
);

const estimatedGas = await estimateGas(
{ config, queryClient },
{
amountIn,
slippage,
tokenIn,
tokenOut,
amountOut,
},
);
const gas = estimatedGas + (estimatedGas * GAS_BUFFER) / 100n;

const { request } = await simulateContract(config, {
address: contracts.arbitrum.balancerVault.address,
abi: contracts.arbitrum.balancerVault.abi,
Expand All @@ -303,7 +289,6 @@ const swap: Swap = async (
minAmountOut[0],
deadline,
],
gas,
});
const hash = await writeContract(config, request);

Expand Down

0 comments on commit fd438bf

Please sign in to comment.