Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/TokenConversion/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isAddress } from '@vanilladefi/sdk'
import useAllTransactions from 'hooks/useAllTransactions'
import useTokenConversion from 'hooks/useTokenConversion'
import useWalletAddress from 'hooks/useWalletAddress'
import { isAddress } from 'lib/tokens'
import React, { useCallback, useState } from 'react'
import { useRecoilValue } from 'recoil'
import { tokenConversionState } from 'state/migration'
Expand Down
2 changes: 1 addition & 1 deletion hooks/useContract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contract } from '@ethersproject/contracts'
import ERC20 from '@uniswap/v2-periphery/build/ERC20.json'
import { getContract } from 'lib/tokens'
import { getContract } from '@vanilladefi/sdk'
import { useMemo } from 'react'
import { useRecoilValue } from 'recoil'
import { signerState } from 'state/wallet'
Expand Down
8 changes: 2 additions & 6 deletions hooks/useTokenBalance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Token, TokenAmount } from '@uniswap/sdk-core'
import { chainId, isAddress, weth } from '@vanilladefi/sdk'
import { BigNumber, Contract, providers } from 'ethers'
import { isAddress, tokenListChainId, weth } from 'lib/tokens'
import { useCallback, useEffect, useState } from 'react'
import { useRecoilValue } from 'recoil'
import { currentBlockNumberState } from 'state/meta'
Expand Down Expand Up @@ -62,11 +62,7 @@ function useTokenBalance(
const parsedDecimals = parseInt(decimals.toString())

// Construct token amounts
const token = new Token(
tokenListChainId,
tokenAddress,
parsedDecimals,
)
const token = new Token(chainId, tokenAddress, parsedDecimals)
const formatted = new TokenAmount(token, raw.toString())

setRaw(raw)
Expand Down
4 changes: 1 addition & 3 deletions hooks/useTokenConversion.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { formatUnits, parseUnits } from '@ethersproject/units'
import { calculateGasMargin, isAddress, snapshot } from '@vanilladefi/sdk'
import { addDays } from 'date-fns'
import { BigNumber, ContractTransaction } from 'ethers'
import { isAddress } from 'lib/tokens'
import { snapshot } from 'lib/vanilla/migration'
import { calculateGasMargin } from 'lib/vanilla/trades'
import { debounce } from 'lodash'
import { useCallback, useEffect } from 'react'
import { useRecoilState, useRecoilValue } from 'recoil'
Expand Down
16 changes: 8 additions & 8 deletions hooks/useTradeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import {
TradeType,
} from '@uniswap/sdk-core'
import { FeeAmount } from '@uniswap/v3-sdk'
import {
calculateGasMargin,
chainId,
estimateGas,
estimateReward,
} from '@vanilladefi/sdk'
import { BigNumber, Transaction } from 'ethers'
import { formatUnits, isAddress, parseUnits } from 'ethers/lib/utils'
import { tokenListChainId } from 'lib/tokens'
import { TransactionProps } from 'lib/uniswap'
import * as uniV2 from 'lib/uniswap/v2/trade'
import * as uniV3 from 'lib/uniswap/v3/trade'
import {
calculateGasMargin,
estimateGas,
estimateReward,
} from 'lib/vanilla/trades'
import { debounce } from 'lodash'
import { Dispatch, SetStateAction, useCallback, useEffect } from 'react'
import { useRecoilState, useRecoilValue } from 'recoil'
Expand Down Expand Up @@ -271,7 +271,7 @@ const useTradeEngine = (
if (token0) {
const raw = getBalance0Raw()
const token = new UniswapToken(
tokenListChainId,
chainId,
token0?.address,
Number(token0?.decimals),
)
Expand All @@ -285,7 +285,7 @@ const useTradeEngine = (
if (token1) {
const raw = getBalance1Raw()
const token = new UniswapToken(
tokenListChainId,
chainId,
token1?.address,
Number(token1?.decimals),
)
Expand Down
2 changes: 1 addition & 1 deletion hooks/useUserPositions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getUserPositions } from '@vanilladefi/sdk'
import { isAddress } from 'ethers/lib/utils'
import { getUserPositions } from 'lib/vanilla/trades'
import { useEffect } from 'react'
import { useRecoilState, useRecoilValue } from 'recoil'
import {
Expand Down
13 changes: 4 additions & 9 deletions hooks/useVanillaGovernanceToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
TokenAmount,
TradeType,
} from '@uniswap/sdk-core'
import { chainId, isAddress, vnlPools, weth } from '@vanilladefi/sdk'
import { BigNumber } from 'ethers'
import { isAddress, tokenListChainId, weth } from 'lib/tokens'
import { constructTrade } from 'lib/uniswap/v3/trade'
import { vnlPools } from 'lib/vanilla/contracts'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { PrerenderProps } from 'types/content'
import { UniswapVersion, VanillaVersion } from 'types/general'
Expand Down Expand Up @@ -52,22 +51,18 @@ function useVanillaGovernanceToken(

const getTokenAmount = useCallback(() => {
if (versionAddress && isAddress(versionAddress)) {
const token = new UniswapToken(
tokenListChainId,
versionAddress || '',
vnlDecimals,
)
const token = new UniswapToken(chainId, versionAddress || '', vnlDecimals)
const tokenAmount = new TokenAmount(token, vnlBalanceRaw.toString())
return tokenAmount
}
}, [versionAddress, vnlBalanceRaw])

// TODO: Separate as getVnlPrice(vanillaVersion) under lib/vanilla -> SDK
// TODO: Separate as getVnlPrice(vanillaVersion) under @vanilladefi/sdk -> SDK
useEffect(() => {
if (versionAddress && uniswapVersion) {
const getTokenPrice = async () => {
const vanillaToken: Token = {
chainId: tokenListChainId.toString(),
chainId: chainId.toString(),
address: versionAddress,
decimals: vnlDecimals.toString(),
pairId: vnlPools.ETH,
Expand Down
2 changes: 1 addition & 1 deletion hooks/useVanillaRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getVanillaRouter } from '@vanilladefi/sdk'
import { Contract } from 'ethers'
import { getVanillaRouter } from 'lib/vanilla/contracts'
import { useEffect, useState } from 'react'
import { useRecoilValue } from 'recoil'
import { providerState, signerState } from 'state/wallet'
Expand Down
2 changes: 1 addition & 1 deletion hooks/useWalletAddress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAddress } from 'lib/tokens'
import { isAddress } from '@vanilladefi/sdk'
import { useEffect, useMemo } from 'react'
import { useRecoilState, useRecoilValue } from 'recoil'
import { signerState, walletAddressState } from 'state/wallet'
Expand Down
7 changes: 0 additions & 7 deletions lib/ipfs.ts

This file was deleted.

106 changes: 7 additions & 99 deletions lib/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,21 @@
import uniswapTokens from '@uniswap/default-token-list'
import v1_0Tokens from 'data/tokens_v1_0.json'
import v1_1Tokens from 'data/tokens_v1_1.json'
import {
getAllTokens,
UniswapVersion,
VanillaVersion,
weth,
} from '@vanilladefi/sdk'
import { BigNumber, constants, Contract, providers, Signer } from 'ethers'
import { getAddress } from 'ethers/lib/utils'
import { ETHPriceQueryResponse } from 'hooks/useETHPrice'
import { getTheGraphClient, v2, v3 } from 'lib/graphql'
import { ipfsToHttp } from 'lib/ipfs'
import Vibrant from 'node-vibrant'
import VanillaRouter from 'types/abis/vanillaRouter.json'
import {
TokenQueryVariables,
UniswapVersion,
VanillaVersion,
} from 'types/general'
import { TokenQueryVariables } from 'types/general'
import { Eligibility, Token, TokenInfoQueryResponse } from 'types/trade'
import { UniswapV3Pool__factory } from 'types/typechain/uniswap_v3_core'
import { chainId, defaultProvider } from 'utils/config'
import { getVanillaRouterAddress } from 'utils/config/vanilla'

export { chainId }

// This is just for compatibility of local testnet with "use-wallet"
export const tokenListChainId = chainId === 1337 ? 1 : chainId

// WETH stuff
const defaultWeth = {
chainId: String(1),
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
decimals: String(18),
symbol: 'WETH',
name: 'Wrapped Ether',
logoURI: ipfsToHttp(
'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png',
),
logoColor: null,
pairId: null,
price: null,
priceHistorical: null,
liquidity: null,
priceChange: null,
}
export const weth: Token =
getAllTokens(VanillaVersion.V1_0)?.find(
(token) =>
token.chainId === String(tokenListChainId) &&
token.symbol === defaultWeth.symbol,
) || defaultWeth

export const getTokenInfoQueryVariables = (
version: VanillaVersion,
blockNumber?: number,
Expand Down Expand Up @@ -78,67 +47,6 @@ export const getTokenInfoQueryVariables = (
return variables
}

export function getAllTokens(version: VanillaVersion): Token[] {
// Convert TokenList format to our own format
const defaultTokens: Token[] = uniswapTokens?.tokens
.map((t) => JSON.parse(JSON.stringify(t))) // Needed for casting to Token[] format
.map((t) => ({
...t,
chainId: String(t.chainId),
decimals: String(t.decimals),
}))

let additionalTokens
switch (version) {
case VanillaVersion.V1_0:
additionalTokens = v1_0Tokens
break
case VanillaVersion.V1_1:
additionalTokens = v1_1Tokens
break
default:
additionalTokens = v1_1Tokens
}

const vanillaTokens: Token[] = additionalTokens
.map((t) => JSON.parse(JSON.stringify(t))) // Needed for casting to Token[] format
.map((t) => ({
...t,
chainId: String(t.chainId),
decimals: String(t.decimals),
}))

let allTokens
switch (version) {
case VanillaVersion.V1_0:
allTokens = [...defaultTokens, ...vanillaTokens]
break
case VanillaVersion.V1_1:
allTokens = [...vanillaTokens]
break
default:
allTokens = [...vanillaTokens]
}

// include only tokens with specified 'chainId' and exclude WETH
return allTokens
.filter(
(token) =>
token.chainId === String(tokenListChainId) &&
token.symbol !== defaultWeth.symbol,
)
.map((t) => ({
...t,
logoURI: ipfsToHttp(t.logoURI),
logoColor: null,
pairId: null,
price: null,
priceHistorical: null,
liquidity: null,
priceChange: null,
}))
}

/**
* Add color for each token based on its logo
*/
Expand Down
18 changes: 0 additions & 18 deletions lib/uniswap/index.ts

This file was deleted.

Loading