Skip to content

Commit

Permalink
fix: Use syntheticGasCostInTermsOfQuoteToken only if within 30% of ga…
Browse files Browse the repository at this point in the history
…sCostInTermsOfQuoteToken (#776)

* fix: Use syntheticGasCostInTermsOfQuoteToken only if within 30% of gasCostInTermsOfQuoteToken

* asFraction

* multiply percent

* increase gas test deviation percent
  • Loading branch information
xrsv authored Dec 4, 2024
1 parent edc92dd commit 936a873
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber';
import { BaseProvider } from '@ethersproject/providers';
import { ChainId, Price } from '@uniswap/sdk-core';
import { ChainId, Percent, Price } from '@uniswap/sdk-core';
import { Pool } from '@uniswap/v3-sdk';
import { CurrencyAmount, log, WRAPPED_NATIVE_CURRENCY } from '../../../util';
import { calculateL1GasFeesHelper } from '../../../util/gas-factory-helpers';
Expand Down Expand Up @@ -205,12 +205,16 @@ export abstract class TickBasedHeuristicGasModelFactory<
// Note that the syntheticGasCost being lessThan the original quoted value is not always strictly better
// e.g. the scenario where the amountToken/ETH pool is very illiquid as well and returns an extremely small number
// however, it is better to have the gasEstimation be almost 0 than almost infinity, as the user will still receive a quote
// Only use syntheticGasCostInTermsOfQuoteToken if it's within 30% of the original gasCostInTermsOfQuoteToken as a safeguard.
if (
syntheticGasCostInTermsOfQuoteToken !== null &&
(gasCostInTermsOfQuoteToken === null ||
(gasCostInTermsOfQuoteToken === null || (
syntheticGasCostInTermsOfQuoteToken.lessThan(
gasCostInTermsOfQuoteToken.asFraction
))
) &&
gasCostInTermsOfQuoteToken.subtract(syntheticGasCostInTermsOfQuoteToken)
.lessThan(gasCostInTermsOfQuoteToken.multiply(new Percent(30, 100)).asFraction)
))
) {
log.info(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const GAS_ESTIMATE_DEVIATION_PERCENT: { [chainId in ChainId]: number } = {
[ChainId.MAINNET]: 50,
[ChainId.GOERLI]: 62,
[ChainId.SEPOLIA]: 75,
[ChainId.OPTIMISM]: 71,
[ChainId.OPTIMISM]: 75,
[ChainId.OPTIMISM_GOERLI]: 30,
[ChainId.OPTIMISM_SEPOLIA]: 30,
[ChainId.ARBITRUM_ONE]: 53,
Expand Down

0 comments on commit 936a873

Please sign in to comment.