Commit 5e30a4b4 authored by Moody Salem's avatar Moody Salem Committed by GitHub

refactor: bump to latest sdk (#1657)

parent b14da284
......@@ -354,7 +354,7 @@ export default function AccountDetails({
<AddressLink
hasENS={!!ENSName}
isENS={true}
href={chainId && getExplorerLink(chainId, ENSName, ExplorerDataType.ADDRESS)}
href={getExplorerLink(chainId, ENSName, ExplorerDataType.ADDRESS)}
>
<LinkIcon size={16} />
<span style={{ marginLeft: '4px' }}>View on Etherscan</span>
......
import { ChainId, Currency } from '@uniswap/sdk-core'
import { Currency } from '@uniswap/sdk-core'
import React, { useMemo } from 'react'
import styled from 'styled-components/macro'
import EthereumLogo from '../../assets/images/ethereum-logo.png'
......@@ -37,10 +37,10 @@ export default function CurrencyLogo({
const uriLocations = useHttpLocations(currency instanceof WrappedTokenInfo ? currency.logoURI : undefined)
const srcs: string[] = useMemo(() => {
if (!currency || currency.isEther) return []
if (!currency || currency.isNative) return []
if (currency.isToken) {
const defaultUrls = currency.chainId === ChainId.MAINNET ? [getTokenLogoURL(currency.address)] : []
const defaultUrls = currency.chainId === 1 ? [getTokenLogoURL(currency.address)] : []
if (currency instanceof WrappedTokenInfo) {
return [...uriLocations, ...defaultUrls]
}
......@@ -49,7 +49,7 @@ export default function CurrencyLogo({
return []
}, [currency, uriLocations])
if (currency?.isEther) {
if (currency?.isNative) {
return <StyledEthereumLogo src={EthereumLogo} size={size} style={style} {...rest} />
}
......
import { ChainId, CurrencyAmount, Token } from '@uniswap/sdk-core'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import React, { useMemo } from 'react'
import { X } from 'react-feather'
import styled from 'styled-components/macro'
......@@ -54,9 +54,7 @@ export default function UniBalanceContent({ setShowUniBalanceModal }: { setShowU
const unclaimedUni = useTokenBalance(useMerkleDistributorContract()?.address, uni)
const circulation: CurrencyAmount<Token> | undefined = useMemo(
() =>
blockTimestamp && uni && chainId === ChainId.MAINNET
? computeUniCirculation(uni, blockTimestamp, unclaimedUni)
: totalSupply,
blockTimestamp && uni && chainId === 1 ? computeUniCirculation(uni, blockTimestamp, unclaimedUni) : totalSupply,
[blockTimestamp, chainId, totalSupply, unclaimedUni, uni]
)
......@@ -116,7 +114,7 @@ export default function UniBalanceContent({ setShowUniBalanceModal }: { setShowU
<TYPE.white color="white">Total Supply</TYPE.white>
<TYPE.white color="white">{totalSupply?.toFixed(0, { groupSeparator: ',' })}</TYPE.white>
</RowBetween>
{uni && uni.chainId === ChainId.MAINNET ? (
{uni && uni.chainId === 1 ? (
<ExternalLink href={`https://info.uniswap.org/token/${uni.address}`}>View UNI Analytics</ExternalLink>
) : null}
</AutoColumn>
......
import { ChainId } from '@uniswap/sdk-core'
import useScrollPosition from '@react-hook/window-scroll'
import React, { useState } from 'react'
import { Text } from 'rebass'
......@@ -301,11 +300,11 @@ export const StyledMenuButton = styled.button`
}
`
const NETWORK_LABELS: { [chainId in ChainId]?: string } = {
[ChainId.RINKEBY]: 'Rinkeby',
[ChainId.ROPSTEN]: 'Ropsten',
[ChainId.GÖRLI]: 'Görli',
[ChainId.KOVAN]: 'Kovan',
const NETWORK_LABELS: { [chainId: number]: string } = {
[4]: 'Rinkeby',
[3]: 'Ropsten',
[5]: 'Görli',
[42]: 'Kovan',
}
export default function Header() {
......
......@@ -4,7 +4,7 @@ import { Link } from 'react-router-dom'
import { Text } from 'rebass'
import styled from 'styled-components/macro'
import { unwrappedToken } from '../../utils/wrappedCurrency'
import { unwrappedToken } from '../../utils/unwrappedToken'
import { ButtonEmpty } from '../Button'
import { transparentize } from 'polished'
import { CardNoise } from '../earn/styled'
......
......@@ -11,7 +11,7 @@ import { useTotalSupply } from '../../hooks/useTotalSupply'
import { useActiveWeb3React } from '../../hooks/web3'
import { useTokenBalance } from '../../state/wallet/hooks'
import { currencyId } from '../../utils/currencyId'
import { unwrappedToken } from '../../utils/wrappedCurrency'
import { unwrappedToken } from '../../utils/unwrappedToken'
import { ButtonPrimary, ButtonSecondary, ButtonEmpty } from '../Button'
import { transparentize } from 'polished'
import { CardNoise } from '../earn/styled'
......
......@@ -13,7 +13,7 @@ import { useActiveWeb3React } from '../../hooks/web3'
import { useTokenBalance } from '../../state/wallet/hooks'
import { ExternalLink, TYPE } from '../../theme'
import { currencyId } from '../../utils/currencyId'
import { unwrappedToken } from '../../utils/wrappedCurrency'
import { unwrappedToken } from '../../utils/unwrappedToken'
import { ButtonPrimary, ButtonSecondary, ButtonEmpty } from '../Button'
import { transparentize } from 'polished'
import { CardNoise } from '../earn/styled'
......
......@@ -11,7 +11,7 @@ import { PositionDetails } from 'types/position'
import { WETH9, Price, Token, Percent } from '@uniswap/sdk-core'
import { formatPrice } from 'utils/formatTokenAmount'
import Loader from 'components/Loader'
import { unwrappedToken } from 'utils/wrappedCurrency'
import { unwrappedToken } from 'utils/unwrappedToken'
import RangeBadge from 'components/Badge/RangeBadge'
import { RowFixed } from 'components/Row'
import HoverInlineText from 'components/HoverInlineText'
......
......@@ -5,7 +5,7 @@ import { AutoColumn } from 'components/Column'
import { TYPE } from 'theme'
import { RowBetween, RowFixed } from 'components/Row'
import CurrencyLogo from 'components/CurrencyLogo'
import { unwrappedToken } from 'utils/wrappedCurrency'
import { unwrappedToken } from 'utils/unwrappedToken'
import { Break } from 'components/earn/styled'
import { useTranslation } from 'react-i18next'
import { Currency } from '@uniswap/sdk-core'
......
......@@ -2,8 +2,6 @@ import React from 'react'
import { Currency, Price, Token } from '@uniswap/sdk-core'
import StepCounter from 'components/InputStepCounter/InputStepCounter'
import { RowBetween } from 'components/Row'
import { useActiveWeb3React } from 'hooks/web3'
import { wrappedCurrency } from 'utils/wrappedCurrency'
// currencyA is the base token
export default function RangeSelector({
......@@ -31,9 +29,8 @@ export default function RangeSelector({
currencyB?: Currency | null
feeAmount?: number
}) {
const { chainId } = useActiveWeb3React()
const tokenA = wrappedCurrency(currencyA ?? undefined, chainId)
const tokenB = wrappedCurrency(currencyB ?? undefined, chainId)
const tokenA = (currencyA ?? undefined)?.wrapped
const tokenB = (currencyB ?? undefined)?.wrapped
const isSorted = tokenA && tokenB && tokenA.sortsBefore(tokenB)
const leftPrice = isSorted ? priceLower : priceUpper?.invert()
......
import React from 'react'
import { Currency } from '@uniswap/sdk-core'
import { ToggleElement, ToggleWrapper } from 'components/Toggle/MultiToggle'
import { useActiveWeb3React } from 'hooks/web3'
import { wrappedCurrency } from 'utils/wrappedCurrency'
// the order of displayed base currencies from left to right is always in sort order
// currencyA is treated as the preferred base currency
......@@ -15,10 +13,8 @@ export default function RateToggle({
currencyB: Currency
handleRateToggle: () => void
}) {
const { chainId } = useActiveWeb3React()
const tokenA = wrappedCurrency(currencyA, chainId)
const tokenB = wrappedCurrency(currencyB, chainId)
const tokenA = currencyA?.wrapped
const tokenB = currencyB?.wrapped
const isSorted = tokenA && tokenB && tokenA.sortsBefore(tokenB)
......
import React from 'react'
import { Text } from 'rebass'
import { ChainId, Currency, currencyEquals, Token, ETHER } from '@uniswap/sdk-core'
import { Currency } from '@uniswap/sdk-core'
import styled from 'styled-components/macro'
import { SUGGESTED_BASES } from '../../constants/routing'
import { currencyId } from '../../utils/currencyId'
import { AutoColumn } from '../Column'
import QuestionHelper from '../QuestionHelper'
import { AutoRow } from '../Row'
......@@ -30,7 +31,7 @@ export default function CommonBases({
onSelect,
selectedCurrency,
}: {
chainId?: ChainId
chainId?: number
selectedCurrency?: Currency | null
onSelect: (currency: Currency) => void
}) {
......@@ -43,26 +44,17 @@ export default function CommonBases({
<QuestionHelper text="These tokens are commonly paired with other tokens." />
</AutoRow>
<AutoRow gap="4px">
<BaseWrapper
onClick={() => {
if (!selectedCurrency || !currencyEquals(selectedCurrency, ETHER)) {
onSelect(ETHER)
}
}}
disable={selectedCurrency?.isEther}
>
<CurrencyLogo currency={ETHER} style={{ marginRight: 8 }} />
<Text fontWeight={500} fontSize={16}>
ETH
</Text>
</BaseWrapper>
{(typeof chainId === 'number' ? SUGGESTED_BASES[chainId] ?? [] : []).map((token: Token) => {
const selected = selectedCurrency?.isToken && selectedCurrency.address === token.address
{(typeof chainId === 'number' ? SUGGESTED_BASES[chainId] ?? [] : []).map((currency: Currency) => {
const isSelected = selectedCurrency?.equals(currency)
return (
<BaseWrapper onClick={() => !selected && onSelect(token)} disable={selected} key={token.address}>
<CurrencyLogo currency={token} style={{ marginRight: 8 }} />
<BaseWrapper
onClick={() => !isSelected && onSelect(currency)}
disable={isSelected}
key={currencyId(currency)}
>
<CurrencyLogo currency={currency} style={{ marginRight: 8 }} />
<Text fontWeight={500} fontSize={16}>
{token.symbol}
{currency.symbol}
</Text>
</BaseWrapper>
)
......
import { Currency, CurrencyAmount, currencyEquals, Token } from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core'
import React, { CSSProperties, MutableRefObject, useCallback, useMemo } from 'react'
import { FixedSizeList } from 'react-window'
import { Text } from 'rebass'
......@@ -17,7 +17,6 @@ import { MenuItem } from './styleds'
import Loader from '../Loader'
import { isTokenOnList } from '../../utils'
import ImportRow from './ImportRow'
import { wrappedCurrency } from 'utils/wrappedCurrency'
import { LightGreyCard } from 'components/Card'
import TokenListLogo from '../../assets/svg/tokenlist.svg'
import QuestionHelper from 'components/QuestionHelper'
......@@ -133,7 +132,7 @@ function CurrencyRow({
{currency.symbol}
</Text>
<TYPE.darkGray ml="0px" fontSize={'12px'} fontWeight={300}>
{currency.name} {!currency.isEther && !isOnSelectedList && customAdded && '• Added by user'}
{currency.name} {!currency.isNative && !isOnSelectedList && customAdded && '• Added by user'}
</TYPE.darkGray>
</Column>
<TokenTags currency={currency} />
......@@ -197,8 +196,6 @@ export default function CurrencyList({
return currencies
}, [currencies, otherListTokens])
const { chainId } = useActiveWeb3React()
const Row = useCallback(
function TokenRow({ data, index, style }) {
const row: Currency | BreakLine = data[index]
......@@ -209,11 +206,11 @@ export default function CurrencyList({
const currency = row
const isSelected = Boolean(currency && selectedCurrency && currencyEquals(selectedCurrency, currency))
const otherSelected = Boolean(currency && otherCurrency && currencyEquals(otherCurrency, currency))
const isSelected = Boolean(currency && selectedCurrency && selectedCurrency.equals(currency))
const otherSelected = Boolean(currency && otherCurrency && otherCurrency.equals(currency))
const handleSelect = () => currency && onCurrencySelect(currency)
const token = wrappedCurrency(currency, chainId)
const token = currency?.wrapped
const showImport = index > currencies.length
......@@ -235,7 +232,7 @@ export default function CurrencyList({
return null
}
},
[chainId, currencies.length, onCurrencySelect, otherCurrency, selectedCurrency, setImportToken, showImportView]
[currencies.length, onCurrencySelect, otherCurrency, selectedCurrency, setImportToken, showImportView]
)
const itemKey = useCallback((index: number, data: typeof itemData) => {
......
import { Currency, ETHER, Token } from '@uniswap/sdk-core'
import { Currency, Ether, Token } from '@uniswap/sdk-core'
import React, { KeyboardEvent, RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import ReactGA from 'react-ga'
import { useTranslation } from 'react-i18next'
......@@ -106,13 +106,15 @@ export function CurrencySearch({
const filteredSortedTokens = useSortedTokensByQuery(sortedTokens, debouncedQuery)
const ether = useMemo(() => chainId && Ether.onChain(chainId), [chainId])
const filteredSortedTokensWithETH: Currency[] = useMemo(() => {
const s = debouncedQuery.toLowerCase().trim()
if (s === '' || s === 'e' || s === 'et' || s === 'eth') {
return [ETHER, ...filteredSortedTokens]
return ether ? [ether, ...filteredSortedTokens] : filteredSortedTokens
}
return filteredSortedTokens
}, [debouncedQuery, filteredSortedTokens])
}, [debouncedQuery, ether, filteredSortedTokens])
const handleCurrencySelect = useCallback(
(currency: Currency) => {
......@@ -140,8 +142,8 @@ export function CurrencySearch({
(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
const s = debouncedQuery.toLowerCase().trim()
if (s === 'eth') {
handleCurrencySelect(ETHER)
if (s === 'eth' && ether) {
handleCurrencySelect(ether)
} else if (filteredSortedTokensWithETH.length > 0) {
if (
filteredSortedTokensWithETH[0].symbol?.toLowerCase() === debouncedQuery.trim().toLowerCase() ||
......@@ -152,7 +154,7 @@ export function CurrencySearch({
}
}
},
[filteredSortedTokensWithETH, handleCurrencySelect, debouncedQuery]
[debouncedQuery, ether, filteredSortedTokensWithETH, handleCurrencySelect]
)
// menu ui
......
import { ChainId, Currency } from '@uniswap/sdk-core'
import { Currency } from '@uniswap/sdk-core'
import React, { useContext } from 'react'
import styled, { ThemeContext } from 'styled-components'
import { getExplorerLink, ExplorerDataType } from '../../utils/getExplorerLink'
......@@ -86,7 +86,7 @@ export function TransactionSubmittedContent({
}: {
onDismiss: () => void
hash: string | undefined
chainId: ChainId
chainId: number
currencyToAdd?: Currency | undefined
inline?: boolean // not in modal
}) {
......
......@@ -11,7 +11,7 @@ import { StakingInfo } from '../../state/stake/hooks'
import { useColor } from '../../hooks/useColor'
import { currencyId } from '../../utils/currencyId'
import { Break, CardNoise, CardBGImage } from './styled'
import { unwrappedToken } from '../../utils/wrappedCurrency'
import { unwrappedToken } from '../../utils/unwrappedToken'
import { useTotalSupply } from '../../hooks/useTotalSupply'
import { useV2Pair } from '../../hooks/useV2Pairs'
import useUSDCPrice from '../../hooks/useUSDCPrice'
......@@ -79,8 +79,8 @@ export default function PoolCard({ stakingInfo }: { stakingInfo: StakingInfo })
const isStaking = Boolean(stakingInfo.stakedAmount.greaterThan('0'))
// get the color of the token
const token = currency0.isEther ? token1 : token0
const WETH = currency0.isEther ? token0 : token1
const token = currency0.isNative ? token1 : token0
const WETH = currency0.isNative ? token0 : token1
const backgroundColor = useColor(token)
const totalSupplyOfStakingToken = useTotalSupply(stakingInfo.stakedAmount.currency)
......
import React, { useState, useCallback } from 'react'
import { V2_ROUTER_ADDRESS } from '../../constants/addresses'
import { useV2LiquidityTokenPermit } from '../../hooks/useERC20Permit'
import useTransactionDeadline from '../../hooks/useTransactionDeadline'
import Modal from '../Modal'
......@@ -14,10 +13,9 @@ import { Pair } from '@uniswap/v2-sdk'
import { Token, CurrencyAmount } from '@uniswap/sdk-core'
import { useActiveWeb3React } from '../../hooks/web3'
import { maxAmountSpend } from '../../utils/maxAmountSpend'
import { usePairContract, useStakingContract } from '../../hooks/useContract'
import { usePairContract, useStakingContract, useV2RouterContract } from '../../hooks/useContract'
import { useApproveCallback, ApprovalState } from '../../hooks/useApproveCallback'
import { StakingInfo, useDerivedStakeInfo } from '../../state/stake/hooks'
import { wrappedCurrencyAmount } from '../../utils/wrappedCurrency'
import { TransactionResponse } from '@ethersproject/providers'
import { useTransactionAdder } from '../../state/transactions/hooks'
import { LoadingView, SubmittedView } from '../ModalViews'
......@@ -44,7 +42,7 @@ interface StakingModalProps {
}
export default function StakingModal({ isOpen, onDismiss, stakingInfo, userLiquidityUnstaked }: StakingModalProps) {
const { chainId, library } = useActiveWeb3React()
const { library } = useActiveWeb3React()
// track and parse user input
const [typedValue, setTypedValue] = useState('')
......@@ -53,7 +51,7 @@ export default function StakingModal({ isOpen, onDismiss, stakingInfo, userLiqui
stakingInfo.stakedAmount.currency,
userLiquidityUnstaked
)
const parsedAmountWrapped = wrappedCurrencyAmount(parsedAmount, chainId)
const parsedAmountWrapped = parsedAmount?.wrapped
let hypotheticalRewardRate: CurrencyAmount<Token> = CurrencyAmount.fromRawAmount(stakingInfo.rewardRate.currency, '0')
if (parsedAmountWrapped?.greaterThan('0')) {
......@@ -83,10 +81,8 @@ export default function StakingModal({ isOpen, onDismiss, stakingInfo, userLiqui
// approval data for stake
const deadline = useTransactionDeadline()
const { signatureData, gatherPermitSignature } = useV2LiquidityTokenPermit(
parsedAmountWrapped,
chainId && V2_ROUTER_ADDRESS[chainId]
)
const router = useV2RouterContract()
const { signatureData, gatherPermitSignature } = useV2LiquidityTokenPermit(parsedAmountWrapped, router?.address)
const [approval, approveCallback] = useApproveCallback(parsedAmount, stakingInfo.stakingRewardAddress)
const stakingContract = useStakingContract(stakingInfo.stakingRewardAddress)
......
import { Currency, currencyEquals, Percent, TradeType } from '@uniswap/sdk-core'
import { Currency, Percent, TradeType } from '@uniswap/sdk-core'
import { Trade as V2Trade } from '@uniswap/v2-sdk'
import { Trade as V3Trade } from '@uniswap/v3-sdk'
import React, { useCallback, useMemo } from 'react'
......@@ -21,9 +21,9 @@ function tradeMeaningfullyDiffers(
const [tradeA, tradeB] = args
return (
tradeA.tradeType !== tradeB.tradeType ||
!currencyEquals(tradeA.inputAmount.currency, tradeB.inputAmount.currency) ||
!tradeA.inputAmount.currency.equals(tradeB.inputAmount.currency) ||
!tradeA.inputAmount.equalTo(tradeB.inputAmount) ||
!currencyEquals(tradeA.outputAmount.currency, tradeB.outputAmount.currency) ||
!tradeA.outputAmount.currency.equals(tradeB.outputAmount.currency) ||
!tradeA.outputAmount.equalTo(tradeB.outputAmount)
)
}
......
......@@ -6,7 +6,7 @@ import { ChevronRight } from 'react-feather'
import { Flex } from 'rebass'
import { ThemeContext } from 'styled-components'
import { TYPE } from '../../theme'
import { unwrappedToken } from 'utils/wrappedCurrency'
import { unwrappedToken } from 'utils/unwrappedToken'
function LabeledArrow({}: { fee: FeeAmount }) {
const theme = useContext(ThemeContext)
......
......@@ -9,7 +9,6 @@ import { AutoColumn } from 'components/Column'
import CurrencyLogo from 'components/CurrencyLogo'
import { useActiveWeb3React } from 'hooks/web3'
import { Currency, Token } from '@uniswap/sdk-core'
import { wrappedCurrency } from 'utils/wrappedCurrency'
import { useUnsupportedTokens } from '../../hooks/Tokens'
import { ExplorerDataType, getExplorerLink } from '../../utils/getExplorerLink'
......@@ -51,7 +50,7 @@ export default function UnsupportedCurrencyFooter({
const tokens =
chainId && currencies
? currencies.map((currency) => {
return wrappedCurrency(currency, chainId)
return currency?.wrapped
})
: []
......
import { ChainId } from '@uniswap/sdk-core'
import { FortmaticConnector as FortmaticConnectorCore } from '@web3-react/fortmatic-connector'
export const OVERLAY_READY = 'OVERLAY_READY'
type FormaticSupportedChains = Extract<ChainId, ChainId.MAINNET | ChainId.ROPSTEN | ChainId.RINKEBY | ChainId.KOVAN>
type FormaticSupportedChains = 1 | 3 | 4 | 42
const CHAIN_ID_NETWORK_ARGUMENT: { readonly [chainId in FormaticSupportedChains]: string | undefined } = {
[ChainId.MAINNET]: undefined,
[ChainId.ROPSTEN]: 'ropsten',
[ChainId.RINKEBY]: 'rinkeby',
[ChainId.KOVAN]: 'kovan',
[1]: undefined,
[3]: 'ropsten',
[4]: 'rinkeby',
[42]: 'kovan',
}
export class FortmaticConnector extends FortmaticConnectorCore {
......
import { ChainId } from '@uniswap/sdk-core'
import { Web3Provider } from '@ethersproject/providers'
import { InjectedConnector } from '@web3-react/injected-connector'
import { WalletConnectConnector } from '@web3-react/walletconnect-connector'
......@@ -20,20 +19,20 @@ if (typeof INFURA_KEY === 'undefined') {
}
const NETWORK_URLS: {
[chainId in ChainId]: string
[chainId: number]: string
} = {
[ChainId.MAINNET]: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
[ChainId.RINKEBY]: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
[ChainId.ROPSTEN]: `https://ropsten.infura.io/v3/${INFURA_KEY}`,
[ChainId.GÖRLI]: `https://goerli.infura.io/v3/${INFURA_KEY}`,
[ChainId.KOVAN]: `https://kovan.infura.io/v3/${INFURA_KEY}`,
[1]: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
[4]: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
[3]: `https://ropsten.infura.io/v3/${INFURA_KEY}`,
[5]: `https://goerli.infura.io/v3/${INFURA_KEY}`,
[42]: `https://kovan.infura.io/v3/${INFURA_KEY}`,
}
const SUPPORTED_CHAIN_IDS = [ChainId.MAINNET, ChainId.RINKEBY, ChainId.ROPSTEN, ChainId.KOVAN, ChainId.GÖRLI]
const SUPPORTED_CHAIN_IDS = [1, 4, 3, 42, 5]
export const network = new NetworkConnector({
urls: NETWORK_URLS,
defaultChainId: ChainId.MAINNET,
defaultChainId: 1,
})
let networkLibrary: Web3Provider | undefined
......@@ -67,7 +66,7 @@ export const portis = new PortisConnector({
// mainnet only
export const walletlink = new WalletLinkConnector({
url: NETWORK_URLS[ChainId.MAINNET],
url: NETWORK_URLS[1],
appName: 'Uniswap',
appLogoUrl: UNISWAP_LOGO_URL,
})
import { ChainId } from '@uniswap/sdk-core'
import { FACTORY_ADDRESS as V3_FACTORY_ADDRESS } from '@uniswap/v3-sdk'
import { constructSameAddressMap } from '../utils/constructSameAddressMap'
......@@ -7,11 +6,11 @@ export const MULTICALL2_ADDRESSES = constructSameAddressMap('0x5BA1e12693Dc8F9c4
export const V2_ROUTER_ADDRESS = constructSameAddressMap('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D')
export const GOVERNANCE_ADDRESS = constructSameAddressMap('0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F')
export const TIMELOCK_ADDRESS = constructSameAddressMap('0x1a9C8182C09F50C8318d769245beA52c32BE35BC')
export const MERKLE_DISTRIBUTOR_ADDRESS: { [chainId in ChainId]?: string } = {
[ChainId.MAINNET]: '0x090D4613473dEE047c3f2706764f49E0821D256e',
export const MERKLE_DISTRIBUTOR_ADDRESS: { [chainId: number]: string } = {
[1]: '0x090D4613473dEE047c3f2706764f49E0821D256e',
}
export const ARGENT_WALLET_DETECTOR_ADDRESS: { [chainId in ChainId]?: string } = {
[ChainId.MAINNET]: '0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8',
export const ARGENT_WALLET_DETECTOR_ADDRESS: { [chainId: number]: string } = {
[1]: '0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8',
}
export const V3_CORE_FACTORY_ADDRESSES = constructSameAddressMap(V3_FACTORY_ADDRESS)
export const QUOTER_ADDRESSES = constructSameAddressMap('0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6')
......@@ -19,13 +18,13 @@ export const NONFUNGIBLE_POSITION_MANAGER_ADDRESSES = constructSameAddressMap(
'0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
)
export const ENS_REGISTRAR_ADDRESSES = {
[ChainId.MAINNET]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[ChainId.GÖRLI]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[ChainId.RINKEBY]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[ChainId.ROPSTEN]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[1]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[5]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[4]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[3]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
}
export const SOCKS_CONTROLLER_ADDRESSES = {
[ChainId.MAINNET]: '0x65770b5283117639760beA3F867b69b3697a91dd',
[1]: '0x65770b5283117639760beA3F867b69b3697a91dd',
}
export const SWAP_ROUTER_ADDRESSES = constructSameAddressMap('0xE592427A0AEce92De3Edee1F18E0157C05861564')
export const V3_MIGRATOR_ADDRESSES = constructSameAddressMap('0xA5644E29708357803b5A882D272c41cC0dF92B34')
import { ChainId } from '@uniswap/sdk-core'
import { GOVERNANCE_ADDRESS, TIMELOCK_ADDRESS, UNI_ADDRESS } from './addresses'
export const COMMON_CONTRACT_NAMES: { [chainId in ChainId]?: { [address: string]: string } } = {
[ChainId.MAINNET]: {
[UNI_ADDRESS[ChainId.MAINNET]]: 'UNI',
[GOVERNANCE_ADDRESS[ChainId.MAINNET]]: 'Governance',
[TIMELOCK_ADDRESS[ChainId.MAINNET]]: 'Timelock',
export const COMMON_CONTRACT_NAMES: { [chainId: number]: { [address: string]: string } } = {
[1]: {
[UNI_ADDRESS[1]]: 'UNI',
[GOVERNANCE_ADDRESS[1]]: 'Governance',
[TIMELOCK_ADDRESS[1]]: 'Timelock',
},
[ChainId.RINKEBY]: {
[UNI_ADDRESS[ChainId.RINKEBY]]: 'Rinkeby UNI',
[GOVERNANCE_ADDRESS[ChainId.RINKEBY]]: 'Rinkeby Governance',
[TIMELOCK_ADDRESS[ChainId.RINKEBY]]: 'Rinkeby Timelock',
[4]: {
[UNI_ADDRESS[4]]: 'Rinkeby UNI',
[GOVERNANCE_ADDRESS[4]]: 'Rinkeby Governance',
[TIMELOCK_ADDRESS[4]]: 'Rinkeby Timelock',
},
[ChainId.ROPSTEN]: {
[UNI_ADDRESS[ChainId.ROPSTEN]]: 'Ropsten UNI',
[GOVERNANCE_ADDRESS[ChainId.ROPSTEN]]: 'Ropsten Governance',
[TIMELOCK_ADDRESS[ChainId.ROPSTEN]]: 'Ropsten Timelock',
[3]: {
[UNI_ADDRESS[3]]: 'Ropsten UNI',
[GOVERNANCE_ADDRESS[3]]: 'Ropsten Governance',
[TIMELOCK_ADDRESS[3]]: 'Ropsten Timelock',
},
[ChainId.KOVAN]: {
[UNI_ADDRESS[ChainId.KOVAN]]: 'Kovan UNI',
[GOVERNANCE_ADDRESS[ChainId.KOVAN]]: 'Kovan Governance',
[TIMELOCK_ADDRESS[ChainId.KOVAN]]: 'Kovan Timelock',
[42]: {
[UNI_ADDRESS[42]]: 'Kovan UNI',
[GOVERNANCE_ADDRESS[42]]: 'Kovan Governance',
[TIMELOCK_ADDRESS[42]]: 'Kovan Timelock',
},
[ChainId.GÖRLI]: {
[UNI_ADDRESS[ChainId.GÖRLI]]: 'Goerli UNI',
[GOVERNANCE_ADDRESS[ChainId.GÖRLI]]: 'Goerli Governance',
[TIMELOCK_ADDRESS[ChainId.GÖRLI]]: 'Goerli Timelock',
[5]: {
[UNI_ADDRESS[5]]: 'Goerli UNI',
[GOVERNANCE_ADDRESS[5]]: 'Goerli Governance',
[TIMELOCK_ADDRESS[5]]: 'Goerli Timelock',
},
}
export const DEFAULT_AVERAGE_BLOCK_TIME_IN_SECS = 13
// Block time here is slightly higher (~1s) than average in order to avoid ongoing proposals past the displayed time
export const AVERAGE_BLOCK_TIME_IN_SECS: { [chainId in ChainId]?: number } = {
[ChainId.MAINNET]: DEFAULT_AVERAGE_BLOCK_TIME_IN_SECS,
export const AVERAGE_BLOCK_TIME_IN_SECS: { [chainId: number]: number } = {
[1]: DEFAULT_AVERAGE_BLOCK_TIME_IN_SECS,
}
// a list of tokens by chain
import { ChainId, Token, WETH9 } from '@uniswap/sdk-core'
import { Currency, Ether, Token, WETH9 } from '@uniswap/sdk-core'
import { AMPL, DAI, FEI, FRAX, FXS, MIR, renBTC, TRIBE, UMA, UNI, USDC, USDT, UST, WBTC } from './tokens'
type ChainTokenList = {
readonly [chainId in ChainId]: Token[]
readonly [chainId: number]: Token[]
}
type ChainCurrencyList = {
readonly [chainId: number]: Currency[]
}
// List of all mirror's assets addresses.
// Last pulled from : https://whitelist.mirror.finance/eth/tokenlists.json
// TODO: Generate this programmatically ?
......@@ -26,22 +31,22 @@ const mAssetsAdditionalBases: { [tokenAddress: string]: Token[] } = {
'0xf72FCd9DCF0190923Fadd44811E240Ef4533fc86': [MIR, UST], // mVIXY
}
const WETH_ONLY: ChainTokenList = {
[ChainId.MAINNET]: [WETH9[ChainId.MAINNET]],
[ChainId.ROPSTEN]: [WETH9[ChainId.ROPSTEN]],
[ChainId.RINKEBY]: [WETH9[ChainId.RINKEBY]],
[ChainId.GÖRLI]: [WETH9[ChainId.GÖRLI]],
[ChainId.KOVAN]: [WETH9[ChainId.KOVAN]],
[1]: [WETH9[1]],
[3]: [WETH9[3]],
[4]: [WETH9[4]],
[5]: [WETH9[5]],
[42]: [WETH9[42]],
}
// used to construct intermediary pairs for trading
export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
...WETH_ONLY,
[ChainId.MAINNET]: [...WETH_ONLY[ChainId.MAINNET], DAI, USDC, USDT, WBTC],
[1]: [...WETH_ONLY[1], DAI, USDC, USDT, WBTC],
}
export const ADDITIONAL_BASES: { [chainId in ChainId]?: { [tokenAddress: string]: Token[] } } = {
[ChainId.MAINNET]: {
export const ADDITIONAL_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = {
[1]: {
...mAssetsAdditionalBases,
'0xA948E86885e12Fb09AfEF8C52142EBDbDf73cD18': [UNI[ChainId.MAINNET]],
'0x561a4717537ff4AF5c687328c0f7E90a319705C0': [UNI[ChainId.MAINNET]],
'0xA948E86885e12Fb09AfEF8C52142EBDbDf73cD18': [UNI[1]],
'0x561a4717537ff4AF5c687328c0f7E90a319705C0': [UNI[1]],
'0xa6e3454fec677772dd771788a079355e43910638': [UMA],
[FEI.address]: [TRIBE],
[TRIBE.address]: [FEI],
......@@ -55,25 +60,25 @@ export const ADDITIONAL_BASES: { [chainId in ChainId]?: { [tokenAddress: string]
* Some tokens can only be swapped via certain pairs, so we override the list of bases that are considered for these
* tokens.
*/
export const CUSTOM_BASES: { [chainId in ChainId]?: { [tokenAddress: string]: Token[] } } = {
[ChainId.MAINNET]: {
[AMPL.address]: [DAI, WETH9[ChainId.MAINNET]],
export const CUSTOM_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = {
[1]: {
[AMPL.address]: [DAI, WETH9[1]],
},
}
// used for display in the default list when adding liquidity
export const SUGGESTED_BASES: Partial<ChainTokenList> = {
[ChainId.MAINNET]: [DAI, USDC, USDT, WBTC],
export const SUGGESTED_BASES: ChainCurrencyList = {
[1]: [Ether.onChain(1), DAI, USDC, USDT, WBTC],
}
// used to construct the list of all pairs we consider by default in the frontend
export const BASES_TO_TRACK_LIQUIDITY_FOR: ChainTokenList = {
...WETH_ONLY,
[ChainId.MAINNET]: [...WETH_ONLY[ChainId.MAINNET], DAI, USDC, USDT, WBTC],
[1]: [...WETH_ONLY[1], DAI, USDC, USDT, WBTC],
}
export const PINNED_PAIRS: { readonly [chainId in ChainId]?: [Token, Token][] } = {
[ChainId.MAINNET]: [
export const PINNED_PAIRS: { readonly [chainId: number]: [Token, Token][] } = {
[1]: [
[
new Token(ChainId.MAINNET, '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', 8, 'cDAI', 'Compound Dai'),
new Token(ChainId.MAINNET, '0x39AA39c021dfbaE8faC545936693aC917d5E7563', 8, 'cUSDC', 'Compound USD Coin'),
new Token(1, '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', 8, 'cDAI', 'Compound Dai'),
new Token(1, '0x39AA39c021dfbaE8faC545936693aC917d5E7563', 8, 'cUSDC', 'Compound USD Coin'),
],
[USDC, USDT],
[DAI, USDT],
......
import { ChainId, Token } from '@uniswap/sdk-core'
import { Token } from '@uniswap/sdk-core'
import { UNI_ADDRESS } from './addresses'
export const AMPL = new Token(ChainId.MAINNET, '0xD46bA6D942050d489DBd938a2C909A5d5039A161', 9, 'AMPL', 'Ampleforth')
export const DAI = new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'Dai Stablecoin')
export const USDC = new Token(ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'USDC', 'USD//C')
export const USDT = new Token(ChainId.MAINNET, '0xdAC17F958D2ee523a2206206994597C13D831ec7', 6, 'USDT', 'Tether USD')
export const WBTC = new Token(ChainId.MAINNET, '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 8, 'WBTC', 'Wrapped BTC')
export const FEI = new Token(ChainId.MAINNET, '0x956F47F50A910163D8BF957Cf5846D573E7f87CA', 18, 'FEI', 'Fei USD')
export const TRIBE = new Token(ChainId.MAINNET, '0xc7283b66Eb1EB5FB86327f08e1B5816b0720212B', 18, 'TRIBE', 'Tribe')
export const FRAX = new Token(ChainId.MAINNET, '0x853d955aCEf822Db058eb8505911ED77F175b99e', 18, 'FRAX', 'Frax')
export const FXS = new Token(ChainId.MAINNET, '0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0', 18, 'FXS', 'Frax Share')
export const renBTC = new Token(ChainId.MAINNET, '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D', 8, 'renBTC', 'renBTC')
export const UMA = new Token(
ChainId.MAINNET,
'0x04Fa0d235C4abf4BcF4787aF4CF447DE572eF828',
18,
'UMA',
'UMA Voting Token v1'
)
export const AMPL = new Token(1, '0xD46bA6D942050d489DBd938a2C909A5d5039A161', 9, 'AMPL', 'Ampleforth')
export const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'Dai Stablecoin')
export const USDC = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'USDC', 'USD//C')
export const USDT = new Token(1, '0xdAC17F958D2ee523a2206206994597C13D831ec7', 6, 'USDT', 'Tether USD')
export const WBTC = new Token(1, '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 8, 'WBTC', 'Wrapped BTC')
export const FEI = new Token(1, '0x956F47F50A910163D8BF957Cf5846D573E7f87CA', 18, 'FEI', 'Fei USD')
export const TRIBE = new Token(1, '0xc7283b66Eb1EB5FB86327f08e1B5816b0720212B', 18, 'TRIBE', 'Tribe')
export const FRAX = new Token(1, '0x853d955aCEf822Db058eb8505911ED77F175b99e', 18, 'FRAX', 'Frax')
export const FXS = new Token(1, '0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0', 18, 'FXS', 'Frax Share')
export const renBTC = new Token(1, '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D', 8, 'renBTC', 'renBTC')
export const UMA = new Token(1, '0x04Fa0d235C4abf4BcF4787aF4CF447DE572eF828', 18, 'UMA', 'UMA Voting Token v1')
// Mirror Protocol compat.
export const UST = new Token(ChainId.MAINNET, '0xa47c8bf37f92abed4a126bda807a7b7498661acd', 18, 'UST', 'Wrapped UST')
export const MIR = new Token(ChainId.MAINNET, '0x09a3ecafa817268f77be1283176b946c4ff2e608', 18, 'MIR', 'Wrapped MIR')
export const UNI: { [chainId in ChainId]: Token } = {
[ChainId.MAINNET]: new Token(ChainId.MAINNET, UNI_ADDRESS[ChainId.MAINNET], 18, 'UNI', 'Uniswap'),
[ChainId.RINKEBY]: new Token(ChainId.RINKEBY, UNI_ADDRESS[ChainId.RINKEBY], 18, 'UNI', 'Uniswap'),
[ChainId.ROPSTEN]: new Token(ChainId.ROPSTEN, UNI_ADDRESS[ChainId.ROPSTEN], 18, 'UNI', 'Uniswap'),
[ChainId.GÖRLI]: new Token(ChainId.GÖRLI, UNI_ADDRESS[ChainId.GÖRLI], 18, 'UNI', 'Uniswap'),
[ChainId.KOVAN]: new Token(ChainId.KOVAN, UNI_ADDRESS[ChainId.KOVAN], 18, 'UNI', 'Uniswap'),
export const UST = new Token(1, '0xa47c8bf37f92abed4a126bda807a7b7498661acd', 18, 'UST', 'Wrapped UST')
export const MIR = new Token(1, '0x09a3ecafa817268f77be1283176b946c4ff2e608', 18, 'MIR', 'Wrapped MIR')
export const UNI: { [chainId: number]: Token } = {
[1]: new Token(1, UNI_ADDRESS[1], 18, 'UNI', 'Uniswap'),
[4]: new Token(4, UNI_ADDRESS[4], 18, 'UNI', 'Uniswap'),
[3]: new Token(3, UNI_ADDRESS[3], 18, 'UNI', 'Uniswap'),
[5]: new Token(5, UNI_ADDRESS[5], 18, 'UNI', 'Uniswap'),
[42]: new Token(42, UNI_ADDRESS[42], 18, 'UNI', 'Uniswap'),
}
import { parseBytes32String } from '@ethersproject/strings'
import { Currency, currencyEquals, ETHER, Token } from '@uniswap/sdk-core'
import { Currency, Ether, Token } from '@uniswap/sdk-core'
import { arrayify } from 'ethers/lib/utils'
import { useMemo } from 'react'
import { createTokenFilterFunction } from '../components/SearchModal/filtering'
......@@ -103,7 +103,7 @@ export function useIsUserAddedToken(currency: Currency | undefined | null): bool
return false
}
return !!userAddedTokens.find((token) => currencyEquals(currency, token))
return !!userAddedTokens.find((token) => currency.equals(token))
}
// parse a name or symbol from a token response
......@@ -172,7 +172,8 @@ export function useToken(tokenAddress?: string): Token | undefined | null {
}
export function useCurrency(currencyId: string | undefined): Currency | null | undefined {
const { chainId } = useActiveWeb3React()
const isETH = currencyId?.toUpperCase() === 'ETH'
const token = useToken(isETH ? undefined : currencyId)
return isETH ? ETHER : token
return isETH ? (chainId ? Ether.onChain(chainId) : undefined) : token
}
import { getTokenLogoURL } from './../components/CurrencyLogo/index'
import { wrappedCurrency } from 'utils/wrappedCurrency'
import { Currency, Token } from '@uniswap/sdk-core'
import { useCallback, useState } from 'react'
import { useActiveWeb3React } from 'hooks/web3'
......@@ -7,9 +6,9 @@ import { useActiveWeb3React } from 'hooks/web3'
export default function useAddTokenToMetamask(
currencyToAdd: Currency | undefined
): { addToken: () => void; success: boolean | undefined } {
const { library, chainId } = useActiveWeb3React()
const { library } = useActiveWeb3React()
const token: Token | undefined = wrappedCurrency(currencyToAdd, chainId)
const token: Token | undefined = currencyToAdd?.wrapped
const [success, setSuccess] = useState<boolean | undefined>()
......
......@@ -2,15 +2,12 @@ import { Currency, Token } from '@uniswap/sdk-core'
import flatMap from 'lodash.flatmap'
import { useMemo } from 'react'
import { ADDITIONAL_BASES, BASES_TO_CHECK_TRADES_AGAINST, CUSTOM_BASES } from '../constants/routing'
import { wrappedCurrency } from '../utils/wrappedCurrency'
import { useActiveWeb3React } from './web3'
export function useAllCurrencyCombinations(currencyA?: Currency, currencyB?: Currency): [Token, Token][] {
const { chainId } = useActiveWeb3React()
const [tokenA, tokenB] = chainId
? [wrappedCurrency(currencyA, chainId), wrappedCurrency(currencyB, chainId)]
: [undefined, undefined]
const [tokenA, tokenB] = chainId ? [currencyA?.wrapped, currencyB?.wrapped] : [undefined, undefined]
const bases: Token[] = useMemo(() => {
if (!chainId) return []
......
import { ChainId, Currency } from '@uniswap/sdk-core'
import { Currency } from '@uniswap/sdk-core'
import { Pool, Route } from '@uniswap/v3-sdk'
import { useMemo } from 'react'
import { useUserSingleHopOnly } from '../state/user/hooks'
import { wrappedCurrency } from '../utils/wrappedCurrency'
import { useActiveWeb3React } from './web3'
import { useV3SwapPools } from './useV3SwapPools'
......@@ -10,14 +9,14 @@ function computeAllRoutes(
currencyIn: Currency,
currencyOut: Currency,
pools: Pool[],
chainId: ChainId,
chainId: number,
currentPath: Pool[] = [],
allPaths: Route<Currency, Currency>[] = [],
startCurrencyIn: Currency = currencyIn,
maxHops = 2
): Route<Currency, Currency>[] {
const tokenIn = wrappedCurrency(currencyIn, chainId)
const tokenOut = wrappedCurrency(currencyOut, chainId)
const tokenIn = currencyIn?.wrapped
const tokenOut = currencyOut?.wrapped
if (!tokenIn || !tokenOut) throw new Error('Missing tokenIn/tokenOut')
for (const pool of pools) {
......
import { MaxUint256 } from '@ethersproject/constants'
import { TransactionResponse } from '@ethersproject/providers'
import { CurrencyAmount, ChainId, Percent, Currency, TradeType } from '@uniswap/sdk-core'
import { CurrencyAmount, Percent, Currency, TradeType } from '@uniswap/sdk-core'
import { Trade as V2Trade } from '@uniswap/v2-sdk'
import { Trade as V3Trade } from '@uniswap/v3-sdk'
import { useCallback, useMemo } from 'react'
......@@ -31,7 +31,7 @@ export function useApproveCallback(
// check the current approval status
const approvalState: ApprovalState = useMemo(() => {
if (!amountToApprove || !spender) return ApprovalState.UNKNOWN
if (amountToApprove.currency.isEther) return ApprovalState.APPROVED
if (amountToApprove.currency.isNative) return ApprovalState.APPROVED
// we might not have enough data to know whether or not we need to approve
if (!currentAllowance) return ApprovalState.UNKNOWN
......@@ -103,7 +103,7 @@ export function useApproveCallbackFromTrade(
allowedSlippage: Percent
) {
const { chainId } = useActiveWeb3React()
const v3SwapRouterAddress = SWAP_ROUTER_ADDRESSES[chainId as ChainId]
const v3SwapRouterAddress = chainId ? SWAP_ROUTER_ADDRESSES[chainId] : undefined
const amountToApprove = useMemo(
() => (trade && trade.inputAmount.currency.isToken ? trade.maximumAmountIn(allowedSlippage) : undefined),
[trade, allowedSlippage]
......
......@@ -2,11 +2,11 @@ import { useState, useLayoutEffect } from 'react'
import { shade } from 'polished'
import Vibrant from 'node-vibrant'
import { hex } from 'wcag-contrast'
import { Token, ChainId } from '@uniswap/sdk-core'
import { Token } from '@uniswap/sdk-core'
import uriToHttp from 'utils/uriToHttp'
async function getColorFromToken(token: Token): Promise<string | null> {
if (token.chainId !== ChainId.MAINNET) {
if (token.chainId !== 1) {
return Promise.resolve('#FAAB14')
}
......
import { Contract } from '@ethersproject/contracts'
import { ChainId, WETH9 } from '@uniswap/sdk-core'
import { WETH9 } from '@uniswap/sdk-core'
import { abi as GOVERNANCE_ABI } from '@uniswap/governance/build/GovernorAlpha.json'
import { abi as UNI_ABI } from '@uniswap/governance/build/Uni.json'
import { abi as STAKING_REWARDS_ABI } from '@uniswap/liquidity-staker/build/StakingRewards.json'
......@@ -47,7 +47,7 @@ import { useActiveWeb3React } from './web3'
// returns null on errors
export function useContract<T extends Contract = Contract>(
addressOrAddressMap: string | { [chainId in ChainId]?: string } | undefined,
addressOrAddressMap: string | { [chainId: number]: string } | undefined,
ABI: any,
withSignerIfPossible = true
): T | null {
......
import JSBI from 'jsbi'
import { ChainId, Percent, CurrencyAmount, Currency, TradeType, Token } from '@uniswap/sdk-core'
import { Percent, CurrencyAmount, Currency, TradeType, Token } from '@uniswap/sdk-core'
import { Trade as V2Trade } from '@uniswap/v2-sdk'
import { Trade as V3Trade } from '@uniswap/v3-sdk'
import { splitSignature } from 'ethers/lib/utils'
......@@ -29,28 +29,28 @@ interface PermitInfo {
// todo: read this information from extensions on token lists or elsewhere (permit registry?)
const PERMITTABLE_TOKENS: {
[chainId in ChainId]: {
[chainId: number]: {
[checksummedTokenAddress: string]: PermitInfo
}
} = {
[ChainId.MAINNET]: {
[1]: {
[USDC.address]: { type: PermitType.AMOUNT, name: 'USD Coin', version: '2' },
[DAI.address]: { type: PermitType.ALLOWED, name: 'Dai Stablecoin', version: '1' },
[UNI[ChainId.MAINNET].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
[UNI[1].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
},
[ChainId.RINKEBY]: {
[4]: {
['0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735']: { type: PermitType.ALLOWED, name: 'Dai Stablecoin', version: '1' },
[UNI[ChainId.RINKEBY].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
[UNI[4].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
},
[ChainId.ROPSTEN]: {
[UNI[ChainId.ROPSTEN].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
[3]: {
[UNI[3].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
['0x07865c6E87B9F70255377e024ace6630C1Eaa37F']: { type: PermitType.AMOUNT, name: 'USD Coin', version: '2' },
},
[ChainId.GÖRLI]: {
[UNI[ChainId.GÖRLI].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
[5]: {
[UNI[5].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
},
[ChainId.KOVAN]: {
[UNI[ChainId.KOVAN].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
[42]: {
[UNI[42].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
},
}
......@@ -70,7 +70,7 @@ interface BaseSignatureData {
nonce: number
owner: string
spender: string
chainId: ChainId | number
chainId: number
tokenAddress: string
permitType: PermitType
}
......@@ -275,7 +275,7 @@ export function useERC20PermitFromTrade(
allowedSlippage: Percent
) {
const { chainId } = useActiveWeb3React()
const swapRouterAddress = SWAP_ROUTER_ADDRESSES[chainId as ChainId]
const swapRouterAddress = chainId ? SWAP_ROUTER_ADDRESSES[chainId] : undefined
const amountToApprove = useMemo(() => (trade ? trade.maximumAmountIn(allowedSlippage) : undefined), [
trade,
allowedSlippage,
......
import { nanoid } from '@reduxjs/toolkit'
import { ChainId } from '@uniswap/sdk-core'
import { TokenList } from '@uniswap/token-lists'
import { useCallback } from 'react'
import { useDispatch } from 'react-redux'
......@@ -16,10 +15,10 @@ export function useFetchListCallback(): (listUrl: string, sendDispatch?: boolean
const ensResolver = useCallback(
async (ensName: string) => {
if (!library || chainId !== ChainId.MAINNET) {
if (!library || chainId !== 1) {
const networkLibrary = getNetworkLibrary()
const network = await networkLibrary.getNetwork()
if (networkLibrary && network.chainId === ChainId.MAINNET) {
if (networkLibrary && network.chainId === 1) {
return resolveENSContentHash(ensName, networkLibrary)
}
throw new Error('Could not construct mainnet ENS resolver')
......
......@@ -5,7 +5,7 @@ import { Token, Currency } from '@uniswap/sdk-core'
import { useMemo } from 'react'
import { useActiveWeb3React } from './web3'
import { useMultipleContractSingleData } from '../state/multicall/hooks'
import { wrappedCurrency } from '../utils/wrappedCurrency'
import { Pool, FeeAmount } from '@uniswap/v3-sdk'
import { abi as IUniswapV3PoolStateABI } from '@uniswap/v3-core/artifacts/contracts/interfaces/pool/IUniswapV3PoolState.sol/IUniswapV3PoolState.json'
import { Interface } from '@ethersproject/abi'
......@@ -28,8 +28,8 @@ export function usePools(
return poolKeys.map(([currencyA, currencyB, feeAmount]) => {
if (!chainId || !currencyA || !currencyB || !feeAmount) return null
const tokenA = wrappedCurrency(currencyA, chainId)
const tokenB = wrappedCurrency(currencyB, chainId)
const tokenA = currencyA?.wrapped
const tokenB = currencyB?.wrapped
if (!tokenA || !tokenB || tokenA.equals(tokenB)) return null
const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]
return [token0, token1, feeAmount]
......
import { BigNumber } from '@ethersproject/bignumber'
import { Router, Trade as V2Trade } from '@uniswap/v2-sdk'
import { SwapRouter, Trade as V3Trade } from '@uniswap/v3-sdk'
import { ChainId, Currency, Percent, TradeType } from '@uniswap/sdk-core'
import { Currency, Percent, TradeType } from '@uniswap/sdk-core'
import { useMemo } from 'react'
import { SWAP_ROUTER_ADDRESSES } from '../constants/addresses'
import { calculateGasMargin } from '../utils/calculateGasMargin'
......@@ -94,7 +94,7 @@ function useSwapCallArguments(
}))
} else {
// trade is V3Trade
const swapRouterAddress = SWAP_ROUTER_ADDRESSES[chainId as ChainId]
const swapRouterAddress = chainId ? SWAP_ROUTER_ADDRESSES[chainId] : undefined
if (!swapRouterAddress) return []
const { value, calldata } = SwapRouter.swapCallParameters(trade, {
......
import { ChainId, Currency, CurrencyAmount, Price, Token } from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, Price, Token } from '@uniswap/sdk-core'
import { useMemo } from 'react'
import { USDC } from '../constants/tokens'
import { useV2TradeExactOut } from './useV2Trade'
......@@ -16,10 +16,10 @@ const usdcCurrencyAmount = CurrencyAmount.fromRawAmount(USDC, 100_000e6)
export default function useUSDCPrice(currency?: Currency): Price<Currency, Token> | undefined {
const { chainId } = useActiveWeb3React()
const v2USDCTrade = useV2TradeExactOut(currency, chainId === ChainId.MAINNET ? usdcCurrencyAmount : undefined, {
const v2USDCTrade = useV2TradeExactOut(currency, chainId === 1 ? usdcCurrencyAmount : undefined, {
maxHops: 2,
})
const v3USDCTrade = useBestV3TradeExactOut(currency, chainId === ChainId.MAINNET ? usdcCurrencyAmount : undefined)
const v3USDCTrade = useBestV3TradeExactOut(currency, chainId === 1 ? usdcCurrencyAmount : undefined)
return useMemo(() => {
if (!currency || !chainId) {
......@@ -27,7 +27,7 @@ export default function useUSDCPrice(currency?: Currency): Price<Currency, Token
}
// return some fake price data for non-mainnet
if (chainId !== ChainId.MAINNET) {
if (chainId !== 1) {
const fakeUSDC = new Token(chainId, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'fUSDC', 'Fake USDC')
return new Price(
currency,
......
......@@ -2,9 +2,7 @@ import { Pair } from '@uniswap/v2-sdk'
import { useMemo } from 'react'
import { abi as IUniswapV2PairABI } from '@uniswap/v2-core/build/IUniswapV2Pair.json'
import { Interface } from '@ethersproject/abi'
import { useActiveWeb3React } from './web3'
import { useMultipleContractSingleData } from '../state/multicall/hooks'
import { wrappedCurrency } from '../utils/wrappedCurrency'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
const PAIR_INTERFACE = new Interface(IUniswapV2PairABI)
......@@ -17,16 +15,9 @@ export enum PairState {
}
export function useV2Pairs(currencies: [Currency | undefined, Currency | undefined][]): [PairState, Pair | null][] {
const { chainId } = useActiveWeb3React()
const tokens = useMemo(
() =>
currencies.map(([currencyA, currencyB]) => [
wrappedCurrency(currencyA, chainId),
wrappedCurrency(currencyB, chainId),
]),
[chainId, currencies]
)
const tokens = useMemo(() => currencies.map(([currencyA, currencyB]) => [currencyA?.wrapped, currencyB?.wrapped]), [
currencies,
])
const pairAddresses = useMemo(
() =>
......
......@@ -3,9 +3,9 @@ import { useEffect, useState } from 'react'
import { useV3NFTPositionManagerContract } from './useContract'
import { BigNumber } from '@ethersproject/bignumber'
import { Pool } from '@uniswap/v3-sdk'
import { CurrencyAmount, Token, currencyEquals, ETHER, Ether } from '@uniswap/sdk-core'
import { CurrencyAmount, Currency } from '@uniswap/sdk-core'
import { useBlockNumber } from 'state/application/hooks'
import { unwrappedToken } from 'utils/wrappedCurrency'
import { unwrappedToken } from 'utils/unwrappedToken'
const MAX_UINT128 = BigNumber.from(2).pow(128).sub(1)
......@@ -14,7 +14,7 @@ export function useV3PositionFees(
pool?: Pool,
tokenId?: BigNumber,
asWETH = false
): [CurrencyAmount<Token | Ether>, CurrencyAmount<Token | Ether>] | [undefined, undefined] {
): [CurrencyAmount<Currency>, CurrencyAmount<Currency>] | [undefined, undefined] {
const positionManager = useV3NFTPositionManagerContract(false)
const owner = useSingleCallResult(tokenId ? positionManager : null, 'ownerOf', [tokenId]).result?.[0]
......@@ -45,11 +45,11 @@ export function useV3PositionFees(
if (pool && amounts) {
return [
!asWETH && currencyEquals(unwrappedToken(pool.token0), ETHER)
? CurrencyAmount.ether(amounts[0].toString())
!asWETH && unwrappedToken(pool.token0).isNative
? CurrencyAmount.ether(pool.chainId, amounts[0].toString())
: CurrencyAmount.fromRawAmount(pool.token0, amounts[0].toString()),
!asWETH && currencyEquals(unwrappedToken(pool.token1), ETHER)
? CurrencyAmount.ether(amounts[1].toString())
!asWETH && unwrappedToken(pool.token1).isNative
? CurrencyAmount.ether(pool.chainId, amounts[1].toString())
: CurrencyAmount.fromRawAmount(pool.token1, amounts[1].toString()),
]
} else {
......
import { Currency, currencyEquals, WETH9 } from '@uniswap/sdk-core'
import { Currency, WETH9 } from '@uniswap/sdk-core'
import { useMemo } from 'react'
import { tryParseAmount } from '../state/swap/hooks'
import { useTransactionAdder } from '../state/transactions/hooks'
......@@ -37,7 +37,7 @@ export default function useWrapCallback(
const hasInputAmount = Boolean(inputAmount?.greaterThan('0'))
const sufficientBalance = inputAmount && balance && !balance.lessThan(inputAmount)
if (inputCurrency.isEther && currencyEquals(WETH9[chainId], outputCurrency)) {
if (inputCurrency.isNative && outputCurrency.equals(WETH9[chainId])) {
return {
wrapType: WrapType.WRAP,
execute:
......@@ -53,7 +53,7 @@ export default function useWrapCallback(
: undefined,
inputError: sufficientBalance ? undefined : hasInputAmount ? 'Insufficient ETH balance' : 'Enter ETH amount',
}
} else if (currencyEquals(WETH9[chainId], inputCurrency) && outputCurrency.isEther) {
} else if (WETH9[chainId].equals(inputCurrency) && outputCurrency.isNative) {
return {
wrapType: WrapType.UNWRAP,
execute:
......
import { Web3Provider } from '@ethersproject/providers'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React as useWeb3ReactCore } from '@web3-react/core'
import { Web3ReactContextInterface } from '@web3-react/core/dist/types'
import { useEffect, useState } from 'react'
......@@ -7,7 +6,7 @@ import { isMobile } from 'react-device-detect'
import { injected } from '../connectors'
import { NetworkContextName } from '../constants/misc'
export function useActiveWeb3React(): Web3ReactContextInterface<Web3Provider> & { chainId?: ChainId } {
export function useActiveWeb3React(): Web3ReactContextInterface<Web3Provider> {
const context = useWeb3ReactCore<Web3Provider>()
const contextNetwork = useWeb3ReactCore<Web3Provider>(NetworkContextName)
return context.active ? context : contextNetwork
......
import React, { useCallback, useContext, useMemo, useState } from 'react'
import { TransactionResponse } from '@ethersproject/providers'
import { Currency, CurrencyAmount, currencyEquals, Percent } from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { WETH9 } from '@uniswap/sdk-core'
import { AlertTriangle, AlertCircle } from 'react-feather'
import ReactGA from 'react-ga'
......@@ -91,11 +91,7 @@ export default function AddLiquidity({
const baseCurrency = currencyA
const quoteCurrency = useMemo(
() =>
currencyA && currencyB && baseCurrency
? currencyEquals(baseCurrency, currencyA)
? currencyB
: currencyA
: undefined,
currencyA && currencyB && baseCurrency ? (baseCurrency.equals(currencyA) ? currencyB : currencyA) : undefined,
[currencyA, currencyB, baseCurrency]
)
......@@ -207,13 +203,13 @@ export default function AddLiquidity({
tokenId,
slippageTolerance: allowedSlippage,
deadline: deadline.toString(),
useEther: currencyA.isEther || currencyB.isEther,
useEther: currencyA.isNative || currencyB.isNative,
})
: NonfungiblePositionManager.addCallParameters(position, {
slippageTolerance: allowedSlippage,
recipient: account,
deadline: deadline.toString(),
useEther: currencyA.isEther || currencyB.isEther,
useEther: currencyA.isNative || currencyB.isNative,
createPool: noLiquidity,
})
......
import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers'
import { Currency, CurrencyAmount, currencyEquals, Percent, WETH9 } from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, Percent, WETH9 } from '@uniswap/sdk-core'
import React, { useCallback, useContext, useState } from 'react'
import { Plus } from 'react-feather'
import ReactGA from 'react-ga'
......@@ -35,7 +35,6 @@ import { TYPE } from '../../theme'
import { calculateGasMargin } from '../../utils/calculateGasMargin'
import { calculateSlippageAmount } from '../../utils/calculateSlippageAmount'
import { maxAmountSpend } from '../../utils/maxAmountSpend'
import { wrappedCurrency } from '../../utils/wrappedCurrency'
import AppBody from '../AppBody'
import { Dots, Wrapper } from '../Pool/styleds'
import { ConfirmAddModalBottom } from './ConfirmAddModalBottom'
......@@ -58,9 +57,7 @@ export default function AddLiquidity({
const currencyB = useCurrency(currencyIdB)
const oneCurrencyIsWETH = Boolean(
chainId &&
((currencyA && currencyEquals(currencyA, WETH9[chainId])) ||
(currencyB && currencyEquals(currencyB, WETH9[chainId])))
chainId && ((currencyA && currencyA.equals(WETH9[chainId])) || (currencyB && currencyB.equals(WETH9[chainId])))
)
const toggleWalletModal = useWalletModalToggle() // toggle wallet when disconnected
......@@ -148,12 +145,12 @@ export default function AddLiquidity({
method: (...args: any) => Promise<TransactionResponse>,
args: Array<string | string[] | number>,
value: BigNumber | null
if (currencyA.isEther || currencyB.isEther) {
const tokenBIsETH = currencyB.isEther
if (currencyA.isNative || currencyB.isNative) {
const tokenBIsETH = currencyB.isNative
estimate = router.estimateGas.addLiquidityETH
method = router.addLiquidityETH
args = [
wrappedCurrency(tokenBIsETH ? currencyA : currencyB, chainId)?.address ?? '', // token
(tokenBIsETH ? currencyA : currencyB)?.wrapped?.address ?? '', // token
(tokenBIsETH ? parsedAmountA : parsedAmountB).quotient.toString(), // token desired
amountsMin[tokenBIsETH ? Field.CURRENCY_A : Field.CURRENCY_B].toString(), // token min
amountsMin[tokenBIsETH ? Field.CURRENCY_B : Field.CURRENCY_A].toString(), // eth min
......@@ -165,8 +162,8 @@ export default function AddLiquidity({
estimate = router.estimateGas.addLiquidity
method = router.addLiquidity
args = [
wrappedCurrency(currencyA, chainId)?.address ?? '',
wrappedCurrency(currencyB, chainId)?.address ?? '',
currencyA?.wrapped?.address ?? '',
currencyB?.wrapped?.address ?? '',
parsedAmountA.quotient.toString(),
parsedAmountB.quotient.toString(),
amountsMin[Field.CURRENCY_A].toString(),
......
......@@ -22,7 +22,6 @@ import { useActiveWeb3React } from '../../hooks/web3'
import { useColor } from '../../hooks/useColor'
import { CountUp } from 'use-count-up'
import { wrappedCurrency } from '../../utils/wrappedCurrency'
import { currencyId } from '../../utils/currencyId'
import { useTotalSupply } from '../../hooks/useTotalSupply'
import { useV2Pair } from '../../hooks/useV2Pairs'
......@@ -92,12 +91,12 @@ export default function Manage({
params: { currencyIdA, currencyIdB },
},
}: RouteComponentProps<{ currencyIdA: string; currencyIdB: string }>) {
const { account, chainId } = useActiveWeb3React()
const { account } = useActiveWeb3React()
// get currencies and pair
const [currencyA, currencyB] = [useCurrency(currencyIdA), useCurrency(currencyIdB)]
const tokenA = wrappedCurrency(currencyA ?? undefined, chainId)
const tokenB = wrappedCurrency(currencyB ?? undefined, chainId)
const tokenA = (currencyA ?? undefined)?.wrapped
const tokenB = (currencyB ?? undefined)?.wrapped
const [, stakingTokenPair] = useV2Pair(tokenA, tokenB)
const stakingInfo = useStakingInfo(stakingTokenPair)?.[0]
......@@ -114,8 +113,8 @@ export default function Manage({
// fade cards if nothing staked or nothing earned yet
const disableTop = !stakingInfo?.stakedAmount || stakingInfo.stakedAmount.equalTo(JSBI.BigInt(0))
const token = currencyA?.isEther ? tokenB : tokenA
const WETH = currencyA?.isEther ? tokenA : tokenB
const token = currencyA?.isNative ? tokenB : tokenA
const WETH = currencyA?.isNative ? tokenA : tokenB
const backgroundColor = useColor(token)
// get WETH value of staked LP tokens
......
......@@ -42,7 +42,7 @@ import { Contract } from '@ethersproject/contracts'
import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp'
import { formatTokenAmount } from 'utils/formatTokenAmount'
import useTheme from 'hooks/useTheme'
import { unwrappedToken } from 'utils/wrappedCurrency'
import { unwrappedToken } from 'utils/unwrappedToken'
import DoubleCurrencyLogo from 'components/DoubleLogo'
import Badge, { BadgeVariant } from 'components/Badge'
import { useDispatch } from 'react-redux'
......
import React, { useContext, useMemo } from 'react'
import { Pair } from '@uniswap/v2-sdk'
import { Token, ChainId } from '@uniswap/sdk-core'
import { Token } from '@uniswap/sdk-core'
import { ThemeContext } from 'styled-components'
import { AutoColumn } from '../../components/Column'
import { AutoRow } from '../../components/Row'
......@@ -58,7 +58,7 @@ export default function MigrateV2() {
() =>
trackedTokenPairs.map((tokens) => {
// sushi liquidity token or null
const sushiLiquidityToken = chainId === ChainId.MAINNET ? toSushiLiquidityToken(tokens) : null
const sushiLiquidityToken = chainId === 1 ? toSushiLiquidityToken(tokens) : null
return {
v2liquidityToken: toV2LiquidityToken(tokens),
sushiLiquidityToken,
......
......@@ -5,7 +5,7 @@ import { PoolState, usePool } from 'hooks/usePools'
import { useToken } from 'hooks/Tokens'
import { useV3PositionFromTokenId } from 'hooks/useV3Positions'
import { Link, RouteComponentProps } from 'react-router-dom'
import { unwrappedToken, wrappedCurrencyAmount } from 'utils/wrappedCurrency'
import { unwrappedToken } from 'utils/unwrappedToken'
import { usePositionTokenURI } from '../../hooks/usePositionTokenURI'
import { calculateGasMargin } from '../../utils/calculateGasMargin'
import { getExplorerLink, ExplorerDataType } from '../../utils/getExplorerLink'
......@@ -24,17 +24,7 @@ import { currencyId } from 'utils/currencyId'
import { formatTokenAmount } from 'utils/formatTokenAmount'
import { useV3PositionFees } from 'hooks/useV3PositionFees'
import { BigNumber } from '@ethersproject/bignumber'
import {
Token,
Currency,
CurrencyAmount,
Percent,
Fraction,
Price,
Ether,
currencyEquals,
ETHER,
} from '@uniswap/sdk-core'
import { Token, Currency, CurrencyAmount, Percent, Fraction, Price } from '@uniswap/sdk-core'
import { useActiveWeb3React } from 'hooks/web3'
import { useV3NFTPositionManagerContract } from 'hooks/useContract'
import { useIsTransactionPending, useTransactionAdder } from 'state/transactions/hooks'
......@@ -423,19 +413,19 @@ export function PositionPage({
const price0 = useUSDCPrice(token0 ?? undefined)
const price1 = useUSDCPrice(token1 ?? undefined)
const fiatValueOfFees: CurrencyAmount<Token | Ether> | null = useMemo(() => {
const fiatValueOfFees: CurrencyAmount<Currency> | null = useMemo(() => {
if (!price0 || !price1 || !feeValue0 || !feeValue1) return null
// we wrap because it doesn't matter, the quote returns a USDC amount
const feeValue0Wrapped = wrappedCurrencyAmount(feeValue0, chainId)
const feeValue1Wrapped = wrappedCurrencyAmount(feeValue1, chainId)
const feeValue0Wrapped = feeValue0?.wrapped
const feeValue1Wrapped = feeValue1?.wrapped
if (!feeValue0Wrapped || !feeValue1Wrapped) return null
const amount0 = price0.quote(feeValue0Wrapped)
const amount1 = price1.quote(feeValue1Wrapped)
return amount0.add(amount1)
}, [price0, price1, feeValue0, feeValue1, chainId])
}, [price0, price1, feeValue0, feeValue1])
const fiatValueOfLiquidity: CurrencyAmount<Token> | null = useMemo(() => {
if (!price0 || !price1 || !position) return null
......@@ -707,7 +697,7 @@ export function PositionPage({
(feeValue0?.greaterThan(0) || feeValue1?.greaterThan(0)) &&
currency0 &&
currency1 &&
(currencyEquals(currency0, ETHER) || currencyEquals(currency1, ETHER)) &&
(currency0.isNative || currency1.isNative) &&
!collectMigrationHash ? (
<AutoColumn gap="md">
<RowBetween>
......
import { Currency, ETHER, CurrencyAmount, Token } from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, Ether, Token } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import React, { useCallback, useEffect, useState } from 'react'
import { Plus } from 'react-feather'
......@@ -35,12 +35,12 @@ function useQuery() {
export default function PoolFinder() {
const query = useQuery()
const { account } = useActiveWeb3React()
const { account, chainId } = useActiveWeb3React()
const [showSearch, setShowSearch] = useState<boolean>(false)
const [activeField, setActiveField] = useState<number>(Fields.TOKEN1)
const [currency0, setCurrency0] = useState<Currency | null>(ETHER)
const [currency0, setCurrency0] = useState<Currency | null>(() => (chainId ? Ether.onChain(chainId) : null))
const [currency1, setCurrency1] = useState<Currency | null>(null)
const [pairState, pair] = useV2Pair(currency0 ?? undefined, currency1 ?? undefined)
......
......@@ -22,7 +22,7 @@ import ReactGA from 'react-ga'
import { useActiveWeb3React } from 'hooks/web3'
import { TransactionResponse } from '@ethersproject/providers'
import { useTransactionAdder } from 'state/transactions/hooks'
import { Percent, currencyEquals, Token, ETHER } from '@uniswap/sdk-core'
import { Percent, WETH9 } from '@uniswap/sdk-core'
import { TYPE } from 'theme'
import { Wrapper, SmallMaxButton, ResponsiveHeaderText } from './styled'
import Loader from 'components/Loader'
......@@ -33,7 +33,6 @@ import useTheme from 'hooks/useTheme'
import { AddRemoveTabs } from 'components/NavigationTabs'
import RangeBadge from 'components/Badge/RangeBadge'
import Toggle from 'components/Toggle'
import { unwrappedToken } from 'utils/wrappedCurrency'
export const UINT128MAX = BigNumber.from(2).pow(128).sub(1)
......@@ -372,10 +371,10 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
{liquidityValue0?.currency &&
liquidityValue1?.currency &&
(liquidityValue0.currency.isEther ||
liquidityValue1.currency.isEther ||
currencyEquals(unwrappedToken(liquidityValue0.currency as Token), ETHER) ||
currencyEquals(unwrappedToken(liquidityValue1.currency as Token), ETHER)) ? (
(liquidityValue0.currency.isNative ||
liquidityValue1.currency.isNative ||
liquidityValue0.currency.wrapped.equals(WETH9[liquidityValue0.currency.chainId]) ||
liquidityValue1.currency.wrapped.equals(WETH9[liquidityValue1.currency.chainId])) ? (
<RowBetween>
<TYPE.main>Collect as WETH</TYPE.main>
<Toggle
......
import { Contract } from '@ethersproject/contracts'
import { TransactionResponse } from '@ethersproject/providers'
import { Currency, currencyEquals, Percent, WETH9 } from '@uniswap/sdk-core'
import { Currency, Percent, WETH9 } from '@uniswap/sdk-core'
import React, { useCallback, useContext, useMemo, useState } from 'react'
import { ArrowDown, Plus } from 'react-feather'
import ReactGA from 'react-ga'
......@@ -31,7 +31,6 @@ import { calculateGasMargin } from '../../utils/calculateGasMargin'
import { calculateSlippageAmount } from '../../utils/calculateSlippageAmount'
import { currencyId } from '../../utils/currencyId'
import useDebouncedChangeHandler from '../../hooks/useDebouncedChangeHandler'
import { wrappedCurrency } from '../../utils/wrappedCurrency'
import AppBody from '../AppBody'
import { ClickableText, MaxButton, Wrapper } from '../Pool/styleds'
import { useApproveCallback, ApprovalState } from '../../hooks/useApproveCallback'
......@@ -53,11 +52,7 @@ export default function RemoveLiquidity({
}: RouteComponentProps<{ currencyIdA: string; currencyIdB: string }>) {
const [currencyA, currencyB] = [useCurrency(currencyIdA) ?? undefined, useCurrency(currencyIdB) ?? undefined]
const { account, chainId, library } = useActiveWeb3React()
const [tokenA, tokenB] = useMemo(() => [wrappedCurrency(currencyA, chainId), wrappedCurrency(currencyB, chainId)], [
currencyA,
currencyB,
chainId,
])
const [tokenA, tokenB] = useMemo(() => [currencyA?.wrapped, currencyB?.wrapped], [currencyA, currencyB])
const theme = useContext(ThemeContext)
......@@ -164,8 +159,8 @@ export default function RemoveLiquidity({
const liquidityAmount = parsedAmounts[Field.LIQUIDITY]
if (!liquidityAmount) throw new Error('missing liquidity amount')
const currencyBIsETH = currencyB.isEther
const oneCurrencyIsETH = currencyA.isEther || currencyBIsETH
const currencyBIsETH = currencyB.isNative
const oneCurrencyIsETH = currencyA.isNative || currencyBIsETH
if (!tokenA || !tokenB) throw new Error('could not wrap')
......@@ -384,11 +379,9 @@ export default function RemoveLiquidity({
[onUserInput]
)
const oneCurrencyIsETH = currencyA?.isEther || currencyB?.isEther
const oneCurrencyIsETH = currencyA?.isNative || currencyB?.isNative
const oneCurrencyIsWETH = Boolean(
chainId &&
((currencyA && currencyEquals(WETH9[chainId], currencyA)) ||
(currencyB && currencyEquals(WETH9[chainId], currencyB)))
chainId && WETH9[chainId] && (currencyA?.equals(WETH9[chainId]) || currencyB?.equals(WETH9[chainId]))
)
const handleSelectCurrencyA = useCallback(
......@@ -527,17 +520,17 @@ export default function RemoveLiquidity({
<RowBetween style={{ justifyContent: 'flex-end' }}>
{oneCurrencyIsETH ? (
<StyledInternalLink
to={`/remove/v2/${currencyA?.isEther ? WETH9[chainId].address : currencyIdA}/${
currencyB?.isEther ? WETH9[chainId].address : currencyIdB
to={`/remove/v2/${currencyA?.isNative ? WETH9[chainId].address : currencyIdA}/${
currencyB?.isNative ? WETH9[chainId].address : currencyIdB
}`}
>
Receive WETH
</StyledInternalLink>
) : oneCurrencyIsWETH ? (
<StyledInternalLink
to={`/remove/v2/${
currencyA && currencyEquals(currencyA, WETH9[chainId]) ? 'ETH' : currencyIdA
}/${currencyB && currencyEquals(currencyB, WETH9[chainId]) ? 'ETH' : currencyIdB}`}
to={`/remove/v2/${currencyA?.equals(WETH9[chainId]) ? 'ETH' : currencyIdA}/${
currencyB?.equals(WETH9[chainId]) ? 'ETH' : currencyIdB
}`}
>
Receive ETH
</StyledInternalLink>
......
......@@ -22,7 +22,7 @@ import DelegateModal from '../../components/vote/DelegateModal'
import { useTokenBalance } from '../../state/wallet/hooks'
import { useActiveWeb3React } from '../../hooks/web3'
import { ZERO_ADDRESS } from '../../constants/misc'
import { Token, CurrencyAmount, ChainId } from '@uniswap/sdk-core'
import { Token, CurrencyAmount } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import { shortenAddress } from '../../utils'
import Loader from '../../components/Loader'
......@@ -206,7 +206,7 @@ export default function Vote() {
</TYPE.body>
<AddressButton>
<StyledExternalLink
href={getExplorerLink(ChainId.MAINNET, userDelegatee, ExplorerDataType.ADDRESS)}
href={getExplorerLink(1, userDelegatee, ExplorerDataType.ADDRESS)}
style={{ margin: '0 4px' }}
>
{userDelegatee === account ? 'Self' : shortenAddress(userDelegatee)}
......
import { ChainId } from '@uniswap/sdk-core'
import { createStore, Store } from 'redux'
import { addPopup, ApplicationModal, removePopup, setOpenModal, updateBlockNumber } from './actions'
import reducer, { ApplicationState } from './reducer'
......@@ -10,7 +9,7 @@ describe('application reducer', () => {
store = createStore(reducer, {
popupList: [],
blockNumber: {
[ChainId.MAINNET]: 3,
[1]: 3,
},
openModal: null,
})
......@@ -54,18 +53,18 @@ describe('application reducer', () => {
describe('updateBlockNumber', () => {
it('updates block number', () => {
store.dispatch(updateBlockNumber({ chainId: ChainId.MAINNET, blockNumber: 4 }))
expect(store.getState().blockNumber[ChainId.MAINNET]).toEqual(4)
store.dispatch(updateBlockNumber({ chainId: 1, blockNumber: 4 }))
expect(store.getState().blockNumber[1]).toEqual(4)
})
it('no op if late', () => {
store.dispatch(updateBlockNumber({ chainId: ChainId.MAINNET, blockNumber: 2 }))
expect(store.getState().blockNumber[ChainId.MAINNET]).toEqual(3)
store.dispatch(updateBlockNumber({ chainId: 1, blockNumber: 2 }))
expect(store.getState().blockNumber[1]).toEqual(3)
})
it('works with non-set chains', () => {
store.dispatch(updateBlockNumber({ chainId: ChainId.ROPSTEN, blockNumber: 2 }))
store.dispatch(updateBlockNumber({ chainId: 3, blockNumber: 2 }))
expect(store.getState().blockNumber).toEqual({
[ChainId.MAINNET]: 3,
[ChainId.ROPSTEN]: 2,
[1]: 3,
[3]: 2,
})
})
})
......
......@@ -7,7 +7,6 @@ import { useV2Pair } from '../../hooks/useV2Pairs'
import { useTotalSupply } from '../../hooks/useTotalSupply'
import { useActiveWeb3React } from '../../hooks/web3'
import { wrappedCurrency } from '../../utils/wrappedCurrency'
import { AppDispatch, AppState } from '../index'
import { tryParseAmount } from '../swap/hooks'
import { useTokenBalances } from '../wallet/hooks'
......@@ -30,7 +29,7 @@ export function useDerivedBurnInfo(
}
error?: string
} {
const { account, chainId } = useActiveWeb3React()
const { account } = useActiveWeb3React()
const { independentField, typedValue } = useBurnState()
......@@ -41,7 +40,7 @@ export function useDerivedBurnInfo(
const relevantTokenBalances = useTokenBalances(account ?? undefined, [pair?.liquidityToken])
const userLiquidity: undefined | CurrencyAmount<Token> = relevantTokenBalances?.[pair?.liquidityToken?.address ?? '']
const [tokenA, tokenB] = [wrappedCurrency(currencyA, chainId), wrappedCurrency(currencyB, chainId)]
const [tokenA, tokenB] = [currencyA?.wrapped, currencyB?.wrapped]
const tokens = {
[Field.CURRENCY_A]: tokenA,
[Field.CURRENCY_B]: tokenB,
......
import { Token, CurrencyAmount, Percent, Ether, currencyEquals, ETHER } from '@uniswap/sdk-core'
import { CurrencyAmount, Percent, Currency } from '@uniswap/sdk-core'
import { Position } from '@uniswap/v3-sdk'
import { usePool } from 'hooks/usePools'
import { useActiveWeb3React } from 'hooks/web3'
......@@ -10,7 +10,7 @@ import { PositionDetails } from 'types/position'
import { AppDispatch, AppState } from '../../index'
import { selectPercent } from './actions'
import { unwrappedToken } from 'utils/wrappedCurrency'
import { unwrappedToken } from 'utils/unwrappedToken'
export function useBurnV3State(): AppState['burnV3'] {
return useSelector<AppState, AppState['burnV3']>((state) => state.burnV3)
......@@ -22,10 +22,10 @@ export function useDerivedV3BurnInfo(
): {
position?: Position
liquidityPercentage?: Percent
liquidityValue0?: CurrencyAmount<Token | Ether>
liquidityValue1?: CurrencyAmount<Token | Ether>
feeValue0?: CurrencyAmount<Token | Ether>
feeValue1?: CurrencyAmount<Token | Ether>
liquidityValue0?: CurrencyAmount<Currency>
liquidityValue1?: CurrencyAmount<Currency>
feeValue0?: CurrencyAmount<Currency>
feeValue1?: CurrencyAmount<Currency>
outOfRange: boolean
error?: string
} {
......@@ -61,15 +61,11 @@ export function useDerivedV3BurnInfo(
const liquidityValue0 =
token0 && discountedAmount0
? currencyEquals(unwrappedToken(token0), ETHER) && !asWETH
? CurrencyAmount.ether(discountedAmount0)
: CurrencyAmount.fromRawAmount(token0, discountedAmount0)
? CurrencyAmount.fromRawAmount(asWETH ? token0 : unwrappedToken(token0), discountedAmount0)
: undefined
const liquidityValue1 =
token1 && discountedAmount1
? currencyEquals(unwrappedToken(token1), ETHER) && !asWETH
? CurrencyAmount.ether(discountedAmount1)
: CurrencyAmount.fromRawAmount(token1, discountedAmount1)
? CurrencyAmount.fromRawAmount(asWETH ? token1 : unwrappedToken(token1), discountedAmount1)
: undefined
const [feeValue0, feeValue1] = useV3PositionFees(pool ?? undefined, position?.tokenId, asWETH)
......
import JSBI from 'jsbi'
import { CurrencyAmount, ChainId, Token } from '@uniswap/sdk-core'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { TransactionResponse } from '@ethersproject/providers'
import { useEffect, useState } from 'react'
import { UNI } from '../../constants/tokens'
......@@ -24,7 +24,7 @@ interface UserClaimData {
const CLAIM_PROMISES: { [key: string]: Promise<UserClaimData | null> } = {}
// returns the claim for the given address, or null if not valid
function fetchClaim(account: string, chainId: ChainId): Promise<UserClaimData | null> {
function fetchClaim(account: string, chainId: number): Promise<UserClaimData | null> {
const formatted = isAddress(account)
if (!formatted) return Promise.reject(new Error('Invalid address'))
const key = `${chainId}:${account}`
......
import DEFAULT_TOKEN_LIST from '@uniswap/default-token-list'
import { ChainId } from '@uniswap/sdk-core'
import { TokenList } from '@uniswap/token-lists'
import { useMemo } from 'react'
import { useSelector } from 'react-redux'
......@@ -9,20 +8,9 @@ import { AppState } from '../index'
import { UNSUPPORTED_LIST_URLS } from './../../constants/lists'
import { WrappedTokenInfo } from './wrappedTokenInfo'
export type TokenAddressMap = Readonly<
{ [chainId in ChainId | number]: Readonly<{ [tokenAddress: string]: { token: WrappedTokenInfo; list: TokenList } }> }
>
/**
* An empty result, useful as a default.
*/
const EMPTY_LIST: TokenAddressMap = {
[ChainId.KOVAN]: {},
[ChainId.RINKEBY]: {},
[ChainId.ROPSTEN]: {},
[ChainId.GÖRLI]: {},
[ChainId.MAINNET]: {},
}
export type TokenAddressMap = Readonly<{
[chainId: number]: Readonly<{ [tokenAddress: string]: { token: WrappedTokenInfo; list: TokenList } }>
}>
const listCache: WeakMap<TokenList, TokenAddressMap> | null =
typeof WeakMap !== 'undefined' ? new WeakMap<TokenList, TokenAddressMap>() : null
......@@ -31,26 +19,23 @@ export function listToTokenMap(list: TokenList): TokenAddressMap {
const result = listCache?.get(list)
if (result) return result
const map = list.tokens.reduce<TokenAddressMap>(
(tokenMap, tokenInfo) => {
const token = new WrappedTokenInfo(tokenInfo, list)
if (tokenMap[token.chainId][token.address] !== undefined) {
console.error(new Error(`Duplicate token! ${token.address}`))
return tokenMap
}
return {
...tokenMap,
[token.chainId]: {
...tokenMap[token.chainId as ChainId],
[token.address]: {
token,
list,
},
const map = list.tokens.reduce<TokenAddressMap>((tokenMap, tokenInfo) => {
const token = new WrappedTokenInfo(tokenInfo, list)
if (tokenMap[token.chainId]?.[token.address] !== undefined) {
console.error(new Error(`Duplicate token! ${token.address}`))
return tokenMap
}
return {
...tokenMap,
[token.chainId]: {
...tokenMap[token.chainId],
[token.address]: {
token,
list,
},
}
},
{ ...EMPTY_LIST }
)
},
}
}, {})
listCache?.set(list, map)
return map
}
......@@ -63,11 +48,11 @@ export function useAllLists(): AppState['lists']['byUrl'] {
function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap {
return {
[ChainId.MAINNET]: { ...map1[ChainId.MAINNET], ...map2[ChainId.MAINNET] },
[ChainId.RINKEBY]: { ...map1[ChainId.RINKEBY], ...map2[ChainId.RINKEBY] },
[ChainId.ROPSTEN]: { ...map1[ChainId.ROPSTEN], ...map2[ChainId.ROPSTEN] },
[ChainId.KOVAN]: { ...map1[ChainId.KOVAN], ...map2[ChainId.KOVAN] },
[ChainId.GÖRLI]: { ...map1[ChainId.GÖRLI], ...map2[ChainId.GÖRLI] },
[1]: { ...map1[1], ...map2[1] },
[4]: { ...map1[4], ...map2[4] },
[3]: { ...map1[3], ...map2[3] },
[42]: { ...map1[42], ...map2[42] },
[5]: { ...map1[5], ...map2[5] },
}
}
......@@ -75,7 +60,7 @@ function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddress
function useCombinedTokenMapFromUrls(urls: string[] | undefined): TokenAddressMap {
const lists = useAllLists()
return useMemo(() => {
if (!urls) return EMPTY_LIST
if (!urls) return {}
return (
urls
.slice()
......@@ -90,7 +75,7 @@ function useCombinedTokenMapFromUrls(urls: string[] | undefined): TokenAddressMa
console.error('Could not show token list due to error', error)
return allTokens
}
}, EMPTY_LIST)
}, {})
)
}, [lists, urls])
}
......
import { ChainId, Token } from '@uniswap/sdk-core'
import { Currency, Token } from '@uniswap/sdk-core'
import { Tags, TokenInfo } from '@uniswap/token-lists'
import { TokenList } from '@uniswap/token-lists/dist/types'
import { isAddress } from '../../utils'
......@@ -11,7 +11,7 @@ export interface TagInfo extends TagDetails {
* Token instances created from token info on a token list.
*/
export class WrappedTokenInfo implements Token {
public readonly isEther: false = false
public readonly isNative: false = false
public readonly isToken: true = true
public readonly list: TokenList
......@@ -31,7 +31,7 @@ export class WrappedTokenInfo implements Token {
return (this._checksummedAddress = checksummedAddress)
}
public get chainId(): ChainId | number {
public get chainId(): number {
return this.tokenInfo.chainId
}
......@@ -66,12 +66,16 @@ export class WrappedTokenInfo implements Token {
}))
}
equals(other: Token): boolean {
return other.chainId === this.chainId && other.address.toLowerCase() === this.address.toLowerCase()
equals(other: Currency): boolean {
return other.chainId === this.chainId && other.isToken && other.address.toLowerCase() === this.address.toLowerCase()
}
sortsBefore(other: Token): boolean {
if (this.equals(other)) throw new Error('Addresses should not be equal')
return this.address.toLowerCase() < other.address.toLowerCase()
}
public get wrapped(): Token {
return this
}
}
......@@ -9,7 +9,6 @@ import { PairState, useV2Pair } from '../../hooks/useV2Pairs'
import { useTotalSupply } from '../../hooks/useTotalSupply'
import { useActiveWeb3React } from '../../hooks/web3'
import { wrappedCurrency, wrappedCurrencyAmount } from '../../utils/wrappedCurrency'
import { tryParseAmount } from '../swap/hooks'
import { useCurrencyBalances } from '../wallet/hooks'
......@@ -63,7 +62,7 @@ export function useDerivedMintInfo(
poolTokenPercentage?: Percent
error?: string
} {
const { account, chainId } = useActiveWeb3React()
const { account } = useActiveWeb3React()
const { independentField, typedValue, otherTypedValue } = useMintState()
......@@ -115,21 +114,23 @@ export function useDerivedMintInfo(
return undefined
} else if (independentAmount) {
// we wrap the currencies just to get the price in terms of the other token
const wrappedIndependentAmount = wrappedCurrencyAmount(independentAmount, chainId)
const [tokenA, tokenB] = [wrappedCurrency(currencyA, chainId), wrappedCurrency(currencyB, chainId)]
const wrappedIndependentAmount = independentAmount?.wrapped
const [tokenA, tokenB] = [currencyA?.wrapped, currencyB?.wrapped]
if (tokenA && tokenB && wrappedIndependentAmount && pair) {
const dependentCurrency = dependentField === Field.CURRENCY_B ? currencyB : currencyA
const dependentTokenAmount =
dependentField === Field.CURRENCY_B
? pair.priceOf(tokenA).quote(wrappedIndependentAmount)
: pair.priceOf(tokenB).quote(wrappedIndependentAmount)
return dependentCurrency?.isEther ? CurrencyAmount.ether(dependentTokenAmount.quotient) : dependentTokenAmount
return dependentCurrency?.isNative
? CurrencyAmount.ether(dependentCurrency.chainId, dependentTokenAmount.quotient)
: dependentTokenAmount
}
return undefined
} else {
return undefined
}
}, [noLiquidity, otherTypedValue, currencies, dependentField, independentAmount, currencyA, chainId, currencyB, pair])
}, [noLiquidity, otherTypedValue, currencies, dependentField, independentAmount, currencyA, currencyB, pair])
const parsedAmounts: { [field in Field]: CurrencyAmount<Currency> | undefined } = useMemo(() => {
return {
......@@ -147,18 +148,15 @@ export function useDerivedMintInfo(
}
return undefined
} else {
const wrappedCurrencyA = wrappedCurrency(currencyA, chainId)
const wrappedCurrencyA = currencyA?.wrapped
return pair && wrappedCurrencyA ? pair.priceOf(wrappedCurrencyA) : undefined
}
}, [chainId, currencyA, noLiquidity, pair, parsedAmounts])
}, [currencyA, noLiquidity, pair, parsedAmounts])
// liquidity minted
const liquidityMinted = useMemo(() => {
const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts
const [tokenAmountA, tokenAmountB] = [
wrappedCurrencyAmount(currencyAAmount, chainId),
wrappedCurrencyAmount(currencyBAmount, chainId),
]
const [tokenAmountA, tokenAmountB] = [currencyAAmount?.wrapped, currencyBAmount?.wrapped]
if (pair && totalSupply && tokenAmountA && tokenAmountB) {
try {
return pair.getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB)
......@@ -170,7 +168,7 @@ export function useDerivedMintInfo(
}
}
return undefined
}, [parsedAmounts, chainId, pair, totalSupply])
}, [parsedAmounts, pair, totalSupply])
const poolTokenPercentage = useMemo(() => {
if (liquidityMinted && totalSupply) {
......
......@@ -12,11 +12,10 @@ import {
TICK_SPACINGS,
encodeSqrtRatioX96,
} from '@uniswap/v3-sdk/dist/'
import { Currency, Token, CurrencyAmount, currencyEquals, Price, Rounding } from '@uniswap/sdk-core'
import { Currency, Token, CurrencyAmount, Price, Rounding } from '@uniswap/sdk-core'
import { useCallback, useMemo } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useActiveWeb3React } from '../../../hooks/web3'
import { wrappedCurrency, wrappedCurrencyAmount } from '../../../utils/wrappedCurrency'
import { AppDispatch, AppState } from '../../index'
import { tryParseAmount } from '../../swap/hooks'
import { useCurrencyBalances } from '../../wallet/hooks'
......@@ -112,7 +111,7 @@ export function useV3DerivedMintInfo(
depositBDisabled: boolean
invertPrice: boolean
} {
const { account, chainId } = useActiveWeb3React()
const { account } = useActiveWeb3React()
const {
independentField,
......@@ -134,14 +133,11 @@ export function useV3DerivedMintInfo(
)
// formatted with tokens
const [tokenA, tokenB, baseToken] = useMemo(
() => [
wrappedCurrency(currencyA, chainId),
wrappedCurrency(currencyB, chainId),
wrappedCurrency(baseCurrency, chainId),
],
[chainId, currencyA, currencyB, baseCurrency]
)
const [tokenA, tokenB, baseToken] = useMemo(() => [currencyA?.wrapped, currencyB?.wrapped, baseCurrency?.wrapped], [
currencyA,
currencyB,
baseCurrency,
])
const [token0, token1] = useMemo(
() =>
......@@ -266,7 +262,7 @@ export function useV3DerivedMintInfo(
const dependentAmount: CurrencyAmount<Currency> | undefined = useMemo(() => {
// we wrap the currencies just to get the price in terms of the other token
const wrappedIndependentAmount = wrappedCurrencyAmount(independentAmount, chainId)
const wrappedIndependentAmount = independentAmount?.wrapped
const dependentCurrency = dependentField === Field.CURRENCY_B ? currencyB : currencyA
if (
independentAmount &&
......@@ -280,7 +276,7 @@ export function useV3DerivedMintInfo(
return undefined
}
const position: Position | undefined = currencyEquals(wrappedIndependentAmount.currency, poolForPosition.token0)
const position: Position | undefined = wrappedIndependentAmount.currency.equals(poolForPosition.token0)
? Position.fromAmount0({
pool: poolForPosition,
tickLower,
......@@ -295,16 +291,15 @@ export function useV3DerivedMintInfo(
amount1: independentAmount.quotient,
})
const dependentTokenAmount = currencyEquals(wrappedIndependentAmount.currency, poolForPosition.token0)
const dependentTokenAmount = wrappedIndependentAmount.currency.equals(poolForPosition.token0)
? position.amount1
: position.amount0
return dependentCurrency?.isEther ? CurrencyAmount.ether(dependentTokenAmount.quotient) : dependentTokenAmount
return dependentCurrency && CurrencyAmount.fromRawAmount(dependentCurrency, dependentTokenAmount.quotient)
}
return undefined
}, [
independentAmount,
chainId,
outOfRange,
dependentField,
currencyB,
......@@ -451,9 +446,8 @@ export function useRangeHopCallbacks(
tickUpper: number | undefined,
pool?: Pool | undefined | null
) {
const { chainId } = useActiveWeb3React()
const baseToken = useMemo(() => wrappedCurrency(baseCurrency, chainId), [baseCurrency, chainId])
const quoteToken = useMemo(() => wrappedCurrency(quoteCurrency, chainId), [quoteCurrency, chainId])
const baseToken = useMemo(() => baseCurrency?.wrapped, [baseCurrency])
const quoteToken = useMemo(() => quoteCurrency?.wrapped, [quoteCurrency])
const getDecrementLower = useCallback(() => {
if (baseToken && quoteToken && typeof tickLower === 'number' && feeAmount) {
......
import { ChainId, Token, CurrencyAmount, WETH9 } from '@uniswap/sdk-core'
import { Token, CurrencyAmount, WETH9 } from '@uniswap/sdk-core'
import { Pair } from '@uniswap/v2-sdk'
import JSBI from 'jsbi'
import { useMemo } from 'react'
......@@ -17,26 +17,26 @@ export const STAKING_GENESIS = 1600387200
export const REWARDS_DURATION_DAYS = 60
export const STAKING_REWARDS_INFO: {
[chainId in ChainId]?: {
[chainId: number]: {
tokens: [Token, Token]
stakingRewardAddress: string
}[]
} = {
[ChainId.MAINNET]: [
[1]: [
{
tokens: [WETH9[ChainId.MAINNET], DAI],
tokens: [WETH9[1], DAI],
stakingRewardAddress: '0xa1484C3aa22a66C62b77E0AE78E15258bd0cB711',
},
{
tokens: [WETH9[ChainId.MAINNET], USDC],
tokens: [WETH9[1], USDC],
stakingRewardAddress: '0x7FBa4B8Dc5E7616e59622806932DBea72537A56b',
},
{
tokens: [WETH9[ChainId.MAINNET], USDT],
tokens: [WETH9[1], USDT],
stakingRewardAddress: '0x6C3e4cb2E96B01F4b866965A91ed4437839A121a',
},
{
tokens: [WETH9[ChainId.MAINNET], WBTC],
tokens: [WETH9[1], WBTC],
stakingRewardAddress: '0xCA35e32e7926b96A9988f61d510E038108d8068e',
},
],
......
......@@ -37,7 +37,7 @@ export function useSwapActionHandlers(): {
dispatch(
selectCurrency({
field,
currencyId: currency.isToken ? currency.address : currency.isEther ? 'ETH' : '',
currencyId: currency.isToken ? currency.address : currency.isNative ? 'ETH' : '',
})
)
},
......
import { createAction } from '@reduxjs/toolkit'
import { ChainId } from '@uniswap/sdk-core'
export interface SerializableTransactionReceipt {
to: string
......@@ -13,21 +12,21 @@ export interface SerializableTransactionReceipt {
}
export const addTransaction = createAction<{
chainId: ChainId
chainId: number
hash: string
from: string
approval?: { tokenAddress: string; spender: string }
claim?: { recipient: string }
summary?: string
}>('transactions/addTransaction')
export const clearAllTransactions = createAction<{ chainId: ChainId }>('transactions/clearAllTransactions')
export const clearAllTransactions = createAction<{ chainId: number }>('transactions/clearAllTransactions')
export const finalizeTransaction = createAction<{
chainId: ChainId
chainId: number
hash: string
receipt: SerializableTransactionReceipt
}>('transactions/finalizeTransaction')
export const checkedTransaction = createAction<{
chainId: ChainId
chainId: number
hash: string
blockNumber: number
}>('transactions/checkedTransaction')
import { ChainId } from '@uniswap/sdk-core'
import { createStore, Store } from 'redux'
import { addTransaction, checkedTransaction, clearAllTransactions, finalizeTransaction } from './actions'
import reducer, { initialState, TransactionState } from './reducer'
......@@ -15,7 +14,7 @@ describe('transaction reducer', () => {
const beforeTime = new Date().getTime()
store.dispatch(
addTransaction({
chainId: ChainId.MAINNET,
chainId: 1,
summary: 'hello world',
hash: '0x0',
approval: { tokenAddress: 'abc', spender: 'def' },
......@@ -23,9 +22,9 @@ describe('transaction reducer', () => {
})
)
const txs = store.getState()
expect(txs[ChainId.MAINNET]).toBeTruthy()
expect(txs[ChainId.MAINNET]?.['0x0']).toBeTruthy()
const tx = txs[ChainId.MAINNET]?.['0x0']
expect(txs[1]).toBeTruthy()
expect(txs[1]?.['0x0']).toBeTruthy()
const tx = txs[1]?.['0x0']
expect(tx).toBeTruthy()
expect(tx?.hash).toEqual('0x0')
expect(tx?.summary).toEqual('hello world')
......@@ -39,7 +38,7 @@ describe('transaction reducer', () => {
it('no op if not valid transaction', () => {
store.dispatch(
finalizeTransaction({
chainId: ChainId.RINKEBY,
chainId: 4,
hash: '0x0',
receipt: {
status: 1,
......@@ -59,7 +58,7 @@ describe('transaction reducer', () => {
store.dispatch(
addTransaction({
hash: '0x0',
chainId: ChainId.RINKEBY,
chainId: 4,
approval: { spender: '0x0', tokenAddress: '0x0' },
summary: 'hello world',
from: '0x0',
......@@ -68,7 +67,7 @@ describe('transaction reducer', () => {
const beforeTime = new Date().getTime()
store.dispatch(
finalizeTransaction({
chainId: ChainId.RINKEBY,
chainId: 4,
hash: '0x0',
receipt: {
status: 1,
......@@ -82,7 +81,7 @@ describe('transaction reducer', () => {
},
})
)
const tx = store.getState()[ChainId.RINKEBY]?.['0x0']
const tx = store.getState()[4]?.['0x0']
expect(tx?.summary).toEqual('hello world')
expect(tx?.confirmedTime).toBeGreaterThanOrEqual(beforeTime)
expect(tx?.receipt).toEqual({
......@@ -102,7 +101,7 @@ describe('transaction reducer', () => {
it('no op if not valid transaction', () => {
store.dispatch(
checkedTransaction({
chainId: ChainId.RINKEBY,
chainId: 4,
hash: '0x0',
blockNumber: 1,
})
......@@ -113,7 +112,7 @@ describe('transaction reducer', () => {
store.dispatch(
addTransaction({
hash: '0x0',
chainId: ChainId.RINKEBY,
chainId: 4,
approval: { spender: '0x0', tokenAddress: '0x0' },
summary: 'hello world',
from: '0x0',
......@@ -121,19 +120,19 @@ describe('transaction reducer', () => {
)
store.dispatch(
checkedTransaction({
chainId: ChainId.RINKEBY,
chainId: 4,
hash: '0x0',
blockNumber: 1,
})
)
const tx = store.getState()[ChainId.RINKEBY]?.['0x0']
const tx = store.getState()[4]?.['0x0']
expect(tx?.lastCheckedBlockNumber).toEqual(1)
})
it('never decreases', () => {
store.dispatch(
addTransaction({
hash: '0x0',
chainId: ChainId.RINKEBY,
chainId: 4,
approval: { spender: '0x0', tokenAddress: '0x0' },
summary: 'hello world',
from: '0x0',
......@@ -141,19 +140,19 @@ describe('transaction reducer', () => {
)
store.dispatch(
checkedTransaction({
chainId: ChainId.RINKEBY,
chainId: 4,
hash: '0x0',
blockNumber: 3,
})
)
store.dispatch(
checkedTransaction({
chainId: ChainId.RINKEBY,
chainId: 4,
hash: '0x0',
blockNumber: 1,
})
)
const tx = store.getState()[ChainId.RINKEBY]?.['0x0']
const tx = store.getState()[4]?.['0x0']
expect(tx?.lastCheckedBlockNumber).toEqual(3)
})
})
......@@ -162,7 +161,7 @@ describe('transaction reducer', () => {
it('removes all transactions for the chain', () => {
store.dispatch(
addTransaction({
chainId: ChainId.MAINNET,
chainId: 1,
summary: 'hello world',
hash: '0x0',
approval: { tokenAddress: 'abc', spender: 'def' },
......@@ -171,7 +170,7 @@ describe('transaction reducer', () => {
)
store.dispatch(
addTransaction({
chainId: ChainId.RINKEBY,
chainId: 4,
summary: 'hello world',
hash: '0x1',
approval: { tokenAddress: 'abc', spender: 'def' },
......@@ -179,14 +178,14 @@ describe('transaction reducer', () => {
})
)
expect(Object.keys(store.getState())).toHaveLength(2)
expect(Object.keys(store.getState())).toEqual([String(ChainId.MAINNET), String(ChainId.RINKEBY)])
expect(Object.keys(store.getState()[ChainId.MAINNET] ?? {})).toEqual(['0x0'])
expect(Object.keys(store.getState()[ChainId.RINKEBY] ?? {})).toEqual(['0x1'])
store.dispatch(clearAllTransactions({ chainId: ChainId.MAINNET }))
expect(Object.keys(store.getState())).toEqual([String(1), String(4)])
expect(Object.keys(store.getState()[1] ?? {})).toEqual(['0x0'])
expect(Object.keys(store.getState()[4] ?? {})).toEqual(['0x1'])
store.dispatch(clearAllTransactions({ chainId: 1 }))
expect(Object.keys(store.getState())).toHaveLength(2)
expect(Object.keys(store.getState())).toEqual([String(ChainId.MAINNET), String(ChainId.RINKEBY)])
expect(Object.keys(store.getState()[ChainId.MAINNET] ?? {})).toEqual([])
expect(Object.keys(store.getState()[ChainId.RINKEBY] ?? {})).toEqual(['0x1'])
expect(Object.keys(store.getState())).toEqual([String(1), String(4)])
expect(Object.keys(store.getState()[1] ?? {})).toEqual([])
expect(Object.keys(store.getState()[4] ?? {})).toEqual(['0x1'])
})
})
})
import { ChainId, Percent, Token } from '@uniswap/sdk-core'
import { Percent, Token } from '@uniswap/sdk-core'
import { Pair } from '@uniswap/v2-sdk'
import JSBI from 'jsbi'
import flatMap from 'lodash.flatmap'
......@@ -190,7 +190,7 @@ export function useUserAddedTokens(): Token[] {
return useMemo(() => {
if (!chainId) return []
return Object.values(serializedTokensMap?.[chainId as ChainId] ?? {}).map(deserializeToken)
return Object.values(serializedTokensMap?.[chainId] ?? {}).map(deserializeToken)
}, [serializedTokensMap, chainId])
}
......
......@@ -18,6 +18,7 @@ import { Erc20Interface } from 'abis/types/Erc20'
export function useETHBalances(
uncheckedAddresses?: (string | undefined)[]
): { [address: string]: CurrencyAmount<Currency> | undefined } {
const { chainId } = useActiveWeb3React()
const multicallContract = useMulticall2Contract()
const addresses: string[] = useMemo(
......@@ -41,10 +42,10 @@ export function useETHBalances(
() =>
addresses.reduce<{ [address: string]: CurrencyAmount<Currency> }>((memo, address, i) => {
const value = results?.[i]?.result?.[0]
if (value) memo[address] = CurrencyAmount.ether(JSBI.BigInt(value.toString()))
if (value && chainId) memo[address] = CurrencyAmount.ether(chainId, JSBI.BigInt(value.toString()))
return memo
}, {}),
[addresses, results]
[addresses, chainId, results]
)
}
......@@ -115,7 +116,7 @@ export function useCurrencyBalances(
])
const tokenBalances = useTokenBalances(account, tokens)
const containsETH: boolean = useMemo(() => currencies?.some((currency) => currency?.isEther) ?? false, [currencies])
const containsETH: boolean = useMemo(() => currencies?.some((currency) => currency?.isNative) ?? false, [currencies])
const ethBalance = useETHBalances(containsETH ? [account] : [])
return useMemo(
......@@ -123,7 +124,7 @@ export function useCurrencyBalances(
currencies?.map((currency) => {
if (!account || !currency) return undefined
if (currency.isToken) return tokenBalances[currency.address]
if (currency.isEther) return ethBalance[account]
if (currency.isNative) return ethBalance[account]
return undefined
}) ?? [],
[account, currencies, ethBalance, tokenBalances]
......
import { AddressZero } from '@ethersproject/constants'
import { ChainId, CurrencyAmount, Percent, Token } from '@uniswap/sdk-core'
import { CurrencyAmount, Percent, Token } from '@uniswap/sdk-core'
import { calculateSlippageAmount } from './calculateSlippageAmount'
describe('#calculateSlippageAmount', () => {
it('bounds are correct', () => {
const tokenAmount = CurrencyAmount.fromRawAmount(new Token(ChainId.MAINNET, AddressZero, 0), '100')
const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, AddressZero, 0), '100')
expect(() => calculateSlippageAmount(tokenAmount, new Percent(-1, 10_000))).toThrow('Unexpected slippage')
expect(() => calculateSlippageAmount(tokenAmount, new Percent(10_001, 10_000))).toThrow('Unexpected slippage')
expect(calculateSlippageAmount(tokenAmount, new Percent(0, 10_000)).map((bound) => bound.toString())).toEqual([
......@@ -29,7 +29,7 @@ describe('#calculateSlippageAmount', () => {
])
})
it('works for 18 decimals', () => {
const tokenAmount = CurrencyAmount.fromRawAmount(new Token(ChainId.MAINNET, AddressZero, 18), '100')
const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, AddressZero, 18), '100')
expect(() => calculateSlippageAmount(tokenAmount, new Percent(-1, 10_000))).toThrow('Unexpected slippage')
expect(() => calculateSlippageAmount(tokenAmount, new Percent(10_001, 10_000))).toThrow('Unexpected slippage')
expect(calculateSlippageAmount(tokenAmount, new Percent(0, 10_000)).map((bound) => bound.toString())).toEqual([
......
import { Token, CurrencyAmount, currencyEquals, Percent } from '@uniswap/sdk-core'
import { Token, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import { ONE_HUNDRED_PERCENT } from '../constants/misc'
......@@ -7,7 +7,7 @@ export function computeFiatValuePriceImpact(
fiatValueOutput: CurrencyAmount<Token> | undefined | null
): Percent | undefined {
if (!fiatValueOutput || !fiatValueInput) return undefined
if (!currencyEquals(fiatValueInput.currency, fiatValueOutput.currency)) return undefined
if (!fiatValueInput.currency.equals(fiatValueOutput.currency)) return undefined
if (JSBI.equal(fiatValueInput.quotient, JSBI.BigInt(0))) return undefined
const pct = ONE_HUNDRED_PERCENT.subtract(fiatValueOutput.divide(fiatValueInput))
return new Percent(pct.numerator, pct.denominator)
......
import JSBI from 'jsbi'
import { ChainId, Token, CurrencyAmount } from '@uniswap/sdk-core'
import { Token, CurrencyAmount } from '@uniswap/sdk-core'
import { BigNumber } from 'ethers'
import { ZERO_ADDRESS } from '../constants/misc'
import { computeUniCirculation } from './computeUniCirculation'
describe('computeUniCirculation', () => {
const token = new Token(ChainId.RINKEBY, ZERO_ADDRESS, 18)
const token = new Token(4, ZERO_ADDRESS, 18)
function expandTo18Decimals(num: JSBI | string | number) {
return JSBI.multiply(JSBI.BigInt(num), JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(18)))
......
import { ChainId } from '@uniswap/sdk-core'
export function constructSameAddressMap<T extends string>(address: T): { [chainId in ChainId]: T } {
export function constructSameAddressMap<T extends string>(address: T): { [chainId: number]: T } {
return {
[ChainId.MAINNET]: address,
[ChainId.ROPSTEN]: address,
[ChainId.KOVAN]: address,
[ChainId.RINKEBY]: address,
[ChainId.GÖRLI]: address,
[1]: address,
[3]: address,
[42]: address,
[4]: address,
[5]: address,
}
}
import { Currency } from '@uniswap/sdk-core'
export function currencyId(currency: Currency): string {
if (currency.isEther) return 'ETH'
if (currency.isNative) return 'ETH'
if (currency.isToken) return currency.address
throw new Error('invalid currency')
}
import { ChainId } from '@uniswap/sdk-core'
import { ExplorerDataType, getExplorerLink } from './getExplorerLink'
describe('#getExplorerLink', () => {
......@@ -18,8 +17,6 @@ describe('#getExplorerLink', () => {
expect(getExplorerLink(3, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://ropsten.etherscan.io/address/abc')
})
it('enum', () => {
expect(getExplorerLink(ChainId.RINKEBY, 'abc', ExplorerDataType.ADDRESS)).toEqual(
'https://rinkeby.etherscan.io/address/abc'
)
expect(getExplorerLink(4, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://rinkeby.etherscan.io/address/abc')
})
})
import { ChainId } from '@uniswap/sdk-core'
const ETHERSCAN_PREFIXES: { [chainId in ChainId]: string } = {
const ETHERSCAN_PREFIXES: { [chainId: number]: string } = {
1: '',
3: 'ropsten.',
4: 'rinkeby.',
......@@ -21,8 +19,8 @@ export enum ExplorerDataType {
* @param data the data to return a link for
* @param type the type of the data
*/
export function getExplorerLink(chainId: ChainId, data: string, type: ExplorerDataType): string {
const prefix = `https://${ETHERSCAN_PREFIXES[chainId] || ETHERSCAN_PREFIXES[1]}etherscan.io`
export function getExplorerLink(chainId: number, data: string, type: ExplorerDataType): string {
const prefix = `https://${ETHERSCAN_PREFIXES[chainId] ?? ''}etherscan.io`
switch (type) {
case ExplorerDataType.TRANSACTION: {
......
......@@ -2,7 +2,7 @@ import { getAddress } from '@ethersproject/address'
import { AddressZero } from '@ethersproject/constants'
import { Contract } from '@ethersproject/contracts'
import { JsonRpcSigner, Web3Provider } from '@ethersproject/providers'
import { ChainId, Token } from '@uniswap/sdk-core'
import { Token } from '@uniswap/sdk-core'
import { FeeAmount } from '@uniswap/v3-sdk/dist/'
import { TokenAddressMap } from '../state/lists/hooks'
......@@ -48,7 +48,7 @@ export function escapeRegExp(string: string): string {
}
export function isTokenOnList(tokenAddressMap: TokenAddressMap, token?: Token): boolean {
return Boolean(token?.isToken && tokenAddressMap[token.chainId as ChainId]?.[token.address])
return Boolean(token?.isToken && tokenAddressMap[token.chainId]?.[token.address])
}
export function formattedFeeAmount(feeAmount: FeeAmount): number {
......
import { ZERO_PERCENT, ONE_HUNDRED_PERCENT } from '../constants/misc'
import { Percent, currencyEquals, Currency, TradeType } from '@uniswap/sdk-core'
import { Percent, Currency, TradeType } from '@uniswap/sdk-core'
import { Trade as V2Trade } from '@uniswap/v2-sdk'
import { Trade as V3Trade } from '@uniswap/v3-sdk'
......@@ -15,8 +15,8 @@ export function isTradeBetter(
if (
tradeA.tradeType !== tradeB.tradeType ||
!currencyEquals(tradeA.inputAmount.currency, tradeB.inputAmount.currency) ||
!currencyEquals(tradeB.outputAmount.currency, tradeB.outputAmount.currency)
!tradeA.inputAmount.currency.equals(tradeB.inputAmount.currency) ||
!tradeB.outputAmount.currency.equals(tradeB.outputAmount.currency)
) {
throw new Error('Comparing incomparable trades')
}
......
......@@ -8,11 +8,11 @@ import { MIN_ETH } from '../constants/misc'
*/
export function maxAmountSpend(currencyAmount?: CurrencyAmount<Currency>): CurrencyAmount<Currency> | undefined {
if (!currencyAmount) return undefined
if (currencyAmount.currency.isEther) {
if (currencyAmount.currency.isNative) {
if (JSBI.greaterThan(currencyAmount.quotient, MIN_ETH)) {
return CurrencyAmount.ether(JSBI.subtract(currencyAmount.quotient, MIN_ETH))
return CurrencyAmount.ether(currencyAmount.currency.chainId, JSBI.subtract(currencyAmount.quotient, MIN_ETH))
} else {
return CurrencyAmount.ether(JSBI.BigInt(0))
return CurrencyAmount.ether(currencyAmount.currency.chainId, JSBI.BigInt(0))
}
}
return currencyAmount
......
import JSBI from 'jsbi'
import { ChainId, Percent, Token, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { Percent, Token, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { Trade, Pair, Route } from '@uniswap/v2-sdk'
import { computeRealizedLPFeeAmount, warningSeverity } from './prices'
describe('prices', () => {
const token1 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000001', 18)
const token2 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000002', 18)
const token3 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000003', 18)
const token1 = new Token(1, '0x0000000000000000000000000000000000000001', 18)
const token2 = new Token(1, '0x0000000000000000000000000000000000000002', 18)
const token3 = new Token(1, '0x0000000000000000000000000000000000000003', 18)
const pair12 = new Pair(
CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(10000)),
......
import { ChainId } from '@uniswap/sdk-core'
const SUPPORTED_CHAIN_IDS = [1, 3, 4, 5, 42]
/**
* Returns the input chain ID if chain is supported. If not, return undefined
* @param chainId a chain ID, which will be returned if it is a supported chain ID
*/
export function supportedChainId(chainId: number): ChainId | undefined {
if (chainId in ChainId) {
export function supportedChainId(chainId: number): number | undefined {
if (SUPPORTED_CHAIN_IDS.includes(chainId)) {
return chainId
}
return undefined
......
import { Currency, Token, WETH9, Ether } from '@uniswap/sdk-core'
import { supportedChainId } from './supportedChainId'
export function unwrappedToken(currency: Token): Currency {
if (currency.isNative) return currency
const formattedChainId = supportedChainId(currency.chainId)
if (formattedChainId && currency.equals(WETH9[formattedChainId])) return Ether.onChain(currency.chainId)
return currency
}
import {
ChainId,
Currency,
ETHER,
Token,
CurrencyAmount,
wrappedCurrency as wrappedCurrencyInternal,
wrappedCurrencyAmount as wrappedCurrencyAmountInternal,
WETH9,
} from '@uniswap/sdk-core'
import { supportedChainId } from './supportedChainId'
export function wrappedCurrency(currency: Currency | undefined, chainId: ChainId | undefined): Token | undefined {
return chainId && currency ? wrappedCurrencyInternal(currency, chainId) : undefined
}
export function wrappedCurrencyAmount(
currencyAmount: CurrencyAmount<Currency> | undefined,
chainId: ChainId | undefined
): CurrencyAmount<Token> | undefined {
return currencyAmount && chainId ? wrappedCurrencyAmountInternal(currencyAmount, chainId) : undefined
}
export function unwrappedToken(token: Token): Currency {
if (token.isEther) return token
const formattedChainId = supportedChainId(token.chainId)
if (formattedChainId && token.equals(WETH9[formattedChainId])) return ETHER
return token
}
......@@ -4422,10 +4422,10 @@
resolved "https://registry.yarnpkg.com/@uniswap/merkle-distributor/-/merkle-distributor-1.0.1.tgz#dc3d911f65a860fc3f0cae074bdcd08ed6a27a4d"
integrity sha512-5gDiTI5hrXIh5UWTrxKYjw30QQDnpl8ckDSpefldNenDlYO1RKkdUYMYpvrqGi2r7YzLYTlO6+TDlNs6O7hDRw==
"@uniswap/sdk-core@^3.0.0-alpha.1":
version "3.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-3.0.0-alpha.1.tgz#8d735755818658fd4a6113cb6d30ed637f9e8347"
integrity sha512-dCRBMKtmVmQCoG6sju3j/ki81e82zyqcWm0g+eU3JU0hzbSo6i31wzkOQPHMRO6FcYIJ6+9qx3Sy0B7VoZ6t9g==
"@uniswap/sdk-core@^3.0.0-alpha.2":
version "3.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-3.0.0-alpha.2.tgz#58f850a3a4e31c366a7471a92bcf704c35491cdd"
integrity sha512-X4tqngp/HLNIbfzHLXtf25OeLtgDVHafp6bCGYR29qsWwlOJR+GlQ+cYDuR+3tOZHt6kuJcXG4rAP6vnjkcqkg==
dependencies:
"@ethersproject/address" "^5.0.2"
big.js "^5.2.2"
......@@ -4457,14 +4457,14 @@
"@uniswap/lib" "1.1.1"
"@uniswap/v2-core" "1.0.0"
"@uniswap/v2-sdk@^3.0.0-alpha.0":
version "3.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@uniswap/v2-sdk/-/v2-sdk-3.0.0-alpha.0.tgz#5bbd3133f832bf8b36bacf9213b06de520313e28"
integrity sha512-KHgdCldJ0JY6NC7KImJuU00G5E7X3LNq5yyVy5tGqf2S9fzBf/az91tlVSZzkEyALmH+8RiSvtqKjSNMXTXTfw==
"@uniswap/v2-sdk@^3.0.0-alpha.1":
version "3.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/@uniswap/v2-sdk/-/v2-sdk-3.0.0-alpha.1.tgz#dd5469299badc0b1d51e7a13e1d24240d3fd7fac"
integrity sha512-AdoRY51MY7nAAKC00oNTXBZi/5f1bWEoXWy7Np5Q6zk/nnH3ImSRPUg2BOwfOKH1SHffk9yZhFKARmS8+hhGBQ==
dependencies:
"@ethersproject/address" "^5.0.0"
"@ethersproject/solidity" "^5.0.0"
"@uniswap/sdk-core" "^3.0.0-alpha.1"
"@uniswap/sdk-core" "^3.0.0-alpha.2"
tiny-invariant "^1.1.0"
tiny-warning "^1.0.3"
......@@ -4484,14 +4484,14 @@
"@uniswap/v3-core" "1.0.0"
base64-sol "1.0.1"
"@uniswap/v3-sdk@^3.0.0-alpha.6":
version "3.0.0-alpha.6"
resolved "https://registry.yarnpkg.com/@uniswap/v3-sdk/-/v3-sdk-3.0.0-alpha.6.tgz#8050c2970757446e38c024e1ed8f6771ad7aae98"
integrity sha512-FsOB2SAeLbZ9lANeaKnc12A+NSfZ2qTeKbRx7JJE9cJrhzR2fg1lSjI9foRcO3uz6aLE87cobELR815sZmPnTw==
"@uniswap/v3-sdk@^3.0.0-alpha.7":
version "3.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@uniswap/v3-sdk/-/v3-sdk-3.0.0-alpha.7.tgz#77175c1f0bb277a7d24a6741d2bfa7e6d6bec997"
integrity sha512-Z2APVF56aOjN9UvHXKV+d1Bccq40Fz6BexlwiwK1HEDeHyQ6v52O23usO7xfNEnenEPVscMu9bQV12W6tFMPdg==
dependencies:
"@ethersproject/abi" "^5.0.12"
"@ethersproject/solidity" "^5.0.9"
"@uniswap/sdk-core" "^3.0.0-alpha.1"
"@uniswap/sdk-core" "^3.0.0-alpha.2"
"@uniswap/v3-periphery" "1.0.0"
tiny-invariant "^1.1.0"
tiny-warning "^1.0.3"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment