fix invariant bug due to dummy ETH (#766)

* fix invariant bug due to dummy ETH

* fix lint issue
This commit is contained in:
Noah Zinsmeister 2020-05-13 20:25:07 -04:00 committed by GitHub
parent 0733cdd63c
commit 4ba7dd9535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,6 @@ import IUniswapV1Factory from '../constants/abis/v1_factory.json'
import { V1_FACTORY_ADDRESS } from '../constants' import { V1_FACTORY_ADDRESS } from '../constants'
import { useContract } from '../hooks' import { useContract } from '../hooks'
import { SWRKeys } from '.' import { SWRKeys } from '.'
import { AddressZero } from '@ethersproject/constants'
import { useETHBalances, useTokenBalances } from '../state/wallet/hooks' import { useETHBalances, useTokenBalances } from '../state/wallet/hooks'
function getV1PairAddress(contract: Contract): (_: SWRKeys, tokenAddress: string) => Promise<string> { function getV1PairAddress(contract: Contract): (_: SWRKeys, tokenAddress: string) => Promise<string> {
@ -24,7 +23,6 @@ function useV1PairAddress(tokenAddress: string) {
return data return data
} }
const DUMMY_ETH = new Token(ChainId.MAINNET, AddressZero, 18)
function useMockV1Pair(token?: Token) { function useMockV1Pair(token?: Token) {
const mainnet = token?.chainId === ChainId.MAINNET const mainnet = token?.chainId === ChainId.MAINNET
const isWETH = token?.equals(WETH[ChainId.MAINNET]) const isWETH = token?.equals(WETH[ChainId.MAINNET])
@ -34,7 +32,7 @@ function useMockV1Pair(token?: Token) {
const ETHBalance = useETHBalances([v1PairAddress])[v1PairAddress] const ETHBalance = useETHBalances([v1PairAddress])[v1PairAddress]
return tokenBalance && ETHBalance return tokenBalance && ETHBalance
? new Pair(tokenBalance, new TokenAmount(DUMMY_ETH, ETHBalance.toString())) ? new Pair(tokenBalance, new TokenAmount(WETH[ChainId.MAINNET], ETHBalance.toString()))
: undefined : undefined
} }
@ -56,7 +54,7 @@ export function useV1TradeLinkIfBetter(trade: Trade, minimumDelta: Percent = new
pairs = [inputPair, outputPair] pairs = [inputPair, outputPair]
} }
const route = pairs && new Route(pairs, inputIsWETH ? DUMMY_ETH : trade.route.input) const route = pairs && new Route(pairs, trade.route.input)
const v1Trade = const v1Trade =
route && route &&
new Trade( new Trade(