Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xrsv/gas fixed execution price for stable pair #775

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { BigNumber } from '@ethersproject/bignumber';
import { BaseProvider } from '@ethersproject/providers';
import { ChainId, Price } from '@uniswap/sdk-core';
import { Pool } from '@uniswap/v3-sdk';
import { CurrencyAmount, log, WRAPPED_NATIVE_CURRENCY } from '../../../util';
import {
CurrencyAmount,
log,
STABLE_COINS_BY_CHAIN_ID,
WRAPPED_NATIVE_CURRENCY,
} from '../../../util';
import { calculateL1GasFeesHelper } from '../../../util/gas-factory-helpers';
import { V3RouteWithValidQuote, V4RouteWithValidQuote } from '../entities';
import {
Expand Down Expand Up @@ -165,13 +170,24 @@ export abstract class TickBasedHeuristicGasModelFactory<
// A pool with the non quote token / ETH should not be required and errors should be handled separately
if (nativeAmountPool) {
// get current execution price (amountToken / quoteToken)
const executionPrice = new Price(
let executionPrice = new Price(
routeWithValidQuote.amount.currency,
routeWithValidQuote.quote.currency,
routeWithValidQuote.amount.quotient,
routeWithValidQuote.quote.quotient
);

// If this is a stable pair, always use execution price of 1 for now.
// TODO: ROUTE-356 Use direct swap pool for swap execution price calculation.
if (this.routeIsStableCoinPair(chainId, routeWithValidQuote)) {
executionPrice = new Price(
routeWithValidQuote.amount.currency,
routeWithValidQuote.quote.currency,
routeWithValidQuote.amount.quotient,
routeWithValidQuote.amount.quotient
);
}

const inputIsToken0 =
nativeAmountPool.token0.address == nativeCurrency.address;
// ratio of input / native
Expand Down Expand Up @@ -258,6 +274,21 @@ export abstract class TickBasedHeuristicGasModelFactory<
};
}

protected routeIsStableCoinPair(
chainId: ChainId,
routeWithValidQuote: TRouteWithValidQuote
): boolean {
const stableCoins = STABLE_COINS_BY_CHAIN_ID[chainId] || [];
return (
stableCoins.includes(
routeWithValidQuote.amount.currency.wrapped.address.toLowerCase()
) &&
stableCoins.includes(
routeWithValidQuote.quote.currency.wrapped.address.toLowerCase()
)
);
}

protected estimateGas(
routeWithValidQuote: TRouteWithValidQuote,
gasPriceWei: BigNumber,
Expand Down
8 changes: 8 additions & 0 deletions src/util/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ export enum NativeCurrencyName {
AVALANCHE = 'AVAX',
}

export const STABLE_COINS_BY_CHAIN_ID: { [chainId: number]: string[] } = {
[ChainId.MAINNET]: [
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
'0x6b175474e89094c44da98b954eedeac495271d0f', // DAI
'0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT
],
};

export const NATIVE_NAMES_BY_ID: { [chainId: number]: string[] } = {
[ChainId.MAINNET]: [
'ETH',
Expand Down
Loading