Skip to content

Commit

Permalink
Fix nativePool selection for mixed routes (Uniswap#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongeric authored Apr 6, 2023
1 parent ca3e646 commit a746d79
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BigNumber } from '@ethersproject/bignumber';
import { partitionMixedRouteByProtocol } from '@uniswap/router-sdk';
import { Pair } from '@uniswap/v2-sdk';
import { Pool } from '@uniswap/v3-sdk';
import JSBI from 'jsbi';
import _ from 'lodash';

import { WRAPPED_NATIVE_CURRENCY } from '../../../..';
Expand Down Expand Up @@ -148,10 +149,13 @@ export class MixedRouteHeuristicGasModelFactory extends IOnChainGasModelFactory
};
}

/// we will use nativeV2Pool for fallback if nativeV3 does not exist
/// we will use nativeV2Pool for fallback if nativeV3 does not exist or has 0 liquidity
/// can use ! here because we return above if v3Pool and v2Pool are null
const nativePool =
!nativeV3Pool && nativeV2Pool ? nativeV2Pool : nativeV3Pool!;
(!nativeV3Pool || JSBI.equal(nativeV3Pool.liquidity, JSBI.BigInt(0))) &&
nativeV2Pool
? nativeV2Pool
: nativeV3Pool!;

const token0 = nativePool.token0.address == nativeCurrency.address;

Expand Down

0 comments on commit a746d79

Please sign in to comment.