Skip to content

Commit

Permalink
setup V1 pairs page
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaysngh-mudrex committed Feb 19, 2024
1 parent f120cdc commit 751c8fd
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 178 deletions.
1 change: 0 additions & 1 deletion src/components/Tokens/TokenDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ export default function TokenDetails({
onCurrencyChange={handleCurrencyChange}
disableTokenInputs={pageChainId !== connectedChainId}
allPools={[]}
allPairs={[]}
/>
</div>
{tokenWarning && <TokenSafetyMessage tokenAddress={address} warning={tokenWarning} />}
Expand Down
84 changes: 65 additions & 19 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,39 +111,81 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId: string]: Token | undefined } =
export const DAI = {
[ChainId.GOERLI]: new Token(
ChainId.GOERLI,
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
'0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9',
18,
'DAI',
'Dai Stablecoin'
),
[ChainId.MAINNET]: new Token(
ChainId.MAINNET,
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
'0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3',
18,
'DAI',
'Dai Stablecoin'
),
}
export const USDC = {
[ChainId.GOERLI]: new Token(ChainId.GOERLI, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 6, 'USDC', 'USD//C'),
[ChainId.MAINNET]: new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 6, 'USDC', 'USD//C'),
[ChainId.GOERLI]: new Token(
ChainId.GOERLI,
'0x005a643907b9a4bc6a55e9069c4fd5fd1f5c79a22470690f75556c4736e34426',
6,
'USDC',
'USD//C'
),
[ChainId.MAINNET]: new Token(
ChainId.MAINNET,
'0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8',
6,
'USDC',
'USD//C'
),
}

export const USDT = {
[ChainId.GOERLI]: new Token(ChainId.GOERLI, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 6, 'USDT', 'Tether USD'),
[ChainId.MAINNET]: new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 6, 'USDT', 'Tether USD'),
[ChainId.GOERLI]: new Token(
ChainId.GOERLI,
'0x386e8d061177f19b3b485c20e31137e6f6bc497cc635ccdfcab96fadf5add6a',
6,
'USDT',
'Tether USD'
),
[ChainId.MAINNET]: new Token(
ChainId.MAINNET,
'0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8',
6,
'USDT',
'Tether USD'
),
}

export const WBTC = {
[ChainId.GOERLI]: new Token(ChainId.GOERLI, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 8, 'WBTC', 'Wrapped BTC'),
[ChainId.MAINNET]: new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 8, 'WBTC', 'Wrapped BTC'),
[ChainId.GOERLI]: new Token(
ChainId.GOERLI,
'0x12D537dC323c439DC65c976FAD242D5610D27cFb5f31689A0A319B8be7F3D56',
8,
'WBTC',
'Wrapped BTC'
),
[ChainId.MAINNET]: new Token(
ChainId.MAINNET,
'0x03fe2B97c1Fd336e750087d68B9B867997Fd64a2661fF3CA5a7C771641E8e7Ac',
8,
'WBTC',
'Wrapped BTC'
),
}

export const wstETH = {
[ChainId.GOERLI]: new Token(ChainId.GOERLI, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'USDT', 'Tether USD'),
[ChainId.GOERLI]: new Token(
ChainId.GOERLI,
'0x12D537dC323c439DC65c976FAD242D5610D27cFb5f31689A0A319B8be7F3D56',
18,
'USDT',
'Tether USD'
),
[ChainId.MAINNET]: new Token(
ChainId.MAINNET,
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
'0x042b8F0484674Ca266ac5D08E4ac6A3fE65bd3129795def2dCA5c34ecc5f96d2',
18,
'wstETH',
'Wrapped stETH'
Expand Down Expand Up @@ -201,14 +243,7 @@ export const SUGGESTED_BASES: ChainTokenList = {
// 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.GOERLI]: [
...WETH_ONLY[ChainId.GOERLI],
DAI[ChainId.GOERLI],
USDC[ChainId.GOERLI],
USDT[ChainId.GOERLI],
// WBTC[ChainId.GOERLI],
// wstETH[ChainId.GOERLI]
],
[ChainId.GOERLI]: [...WETH_ONLY[ChainId.GOERLI], DAI[ChainId.GOERLI], USDC[ChainId.GOERLI], USDT[ChainId.GOERLI]],
[ChainId.MAINNET]: [
...WETH_ONLY[ChainId.MAINNET],
DAI[ChainId.MAINNET],
Expand Down Expand Up @@ -239,7 +274,18 @@ export const BASES_TO_BUILD_ZAPPER_LIST_AGAINST: ChainTokenList = {
],
}

export const PINNED_PAIRS: { readonly [chainId in ChainId]?: [Token, Token][] } = {}
export const PINNED_PAIRS: { readonly [chainId in ChainId]?: [Token, Token][] } = {
[ChainId.GOERLI]: [
[WETH[ChainId.GOERLI], DAI[ChainId.GOERLI]],
[WETH[ChainId.GOERLI], USDC[ChainId.GOERLI]],
],
[ChainId.MAINNET]: [
[WETH[ChainId.MAINNET], DAI[ChainId.MAINNET]],
[WETH[ChainId.MAINNET], USDC[ChainId.MAINNET]],
],
}

// export const PINNED_PAIRS: { readonly [chainId in ChainId]?: [Token, Token][] } = {}

export const NetworkContextName = 'NETWORK'

Expand Down
20 changes: 6 additions & 14 deletions src/hooks/Trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PairState, useV2Pairs } from './useV2Pairs'
import { BASES_TO_CHECK_TRADES_AGAINST } from 'constants/tokens'
import flatMap from 'array.prototype.flatmap'

function useAllCommonPairs(pairs: string[] | [], currencyA?: Currency, currencyB?: Currency): [Pair[], boolean] {
function useAllCommonPairs(currencyA?: Currency, currencyB?: Currency): [Pair[], boolean] {
const { chainId } = useAccountDetails()

const bases: Token[] = useMemo(() => (chainId ? BASES_TO_CHECK_TRADES_AGAINST[chainId] : []), [chainId])
Expand Down Expand Up @@ -40,7 +40,7 @@ function useAllCommonPairs(pairs: string[] | [], currencyA?: Currency, currencyB
[tokenA, tokenB, bases, basePairs]
)

const allPairs = useV2Pairs(pairs, allPairCombinations)
const allPairs = useV2Pairs(allPairCombinations)
const anyPairLoading = allPairs.some(([pairState]) => pairState === PairState.LOADING)

// only pass along valid pairs, non-duplicated pairs
Expand All @@ -65,12 +65,8 @@ function useAllCommonPairs(pairs: string[] | [], currencyA?: Currency, currencyB
]
}

export function useTradeExactIn(
allPairs: string[] | [],
currencyAmountIn?: CurrencyAmount<Currency>,
currencyOut?: Currency
): any {
const [allowedPairs, pairLoading] = useAllCommonPairs(allPairs, currencyAmountIn?.currency, currencyOut)
export function useTradeExactIn(currencyAmountIn?: CurrencyAmount<Currency>, currencyOut?: Currency): any {
const [allowedPairs, pairLoading] = useAllCommonPairs(currencyAmountIn?.currency, currencyOut)

return [
useMemo(() => {
Expand All @@ -90,12 +86,8 @@ export function useTradeExactIn(
/**
* Returns the best trade for the token in to the exact amount of token out
*/
export function useTradeExactOut(
allPairs: string[] | [],
currencyIn?: Currency,
currencyAmountOut?: CurrencyAmount<Currency>
): any {
const [allowedPairs, pairLoading] = useAllCommonPairs(allPairs, currencyIn, currencyAmountOut?.currency)
export function useTradeExactOut(currencyIn?: Currency, currencyAmountOut?: CurrencyAmount<Currency>): any {
const [allowedPairs, pairLoading] = useAllCommonPairs(currencyIn, currencyAmountOut?.currency)

return [
useMemo(() => {
Expand Down
7 changes: 2 additions & 5 deletions src/hooks/useV2Pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export enum PairState {
INVALID,
}

export function useV2Pairs(
pairs: string[],
currencies: [Currency | undefined, Currency | undefined][]
): [PairState, Pair | null][] {
export function useV2Pairs(currencies: [Currency | undefined, Currency | undefined][]): [PairState, Pair | null][] {
const tokens = useMemo(
() => currencies.map(([currencyA, currencyB]) => [currencyA?.wrapped, currencyB?.wrapped]),
[currencies]
Expand Down Expand Up @@ -70,5 +67,5 @@ export function useV2Pairs(

export function useV2Pair(tokenA?: Currency, tokenB?: Currency): [PairState, Pair | null] {
const inputs: [[Currency | undefined, Currency | undefined]] = useMemo(() => [[tokenA, tokenB]], [tokenA, tokenB])
return useV2Pairs([], inputs)[0]
return useV2Pairs(inputs)[0]
}
45 changes: 29 additions & 16 deletions src/lib/hooks/useCurrencyBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { useAccountDetails } from 'hooks/starknet-react'
import ERC20ABI from 'abis/erc20.json'
import { Erc20Interface } from 'abis/types/Erc20'
import JSBI from 'jsbi'
import { useMultipleContractSingleData, useSingleContractMultipleData } from 'lib/hooks/multicall'
import { useSingleContractMultipleData } from 'lib/hooks/multicall'
import { useMemo } from 'react'

import { nativeOnChain } from '../../constants/tokens'
import { useInterfaceMulticall } from '../../hooks/useContract'
import { isAddress } from '../../utils'
import { useMultipleContractSingleData } from 'state/multicall/hooks'
import ERC20_ABI from 'constants/abis/erc20.json'
import { Abi } from 'starknet'
import { isAddressValidForStarknet } from 'utils/addresses'

/**
* Returns a map of the given addresses to their eventually consistent ETH balances.
Expand Down Expand Up @@ -55,25 +59,34 @@ export function useTokenBalancesWithLoadingIndicator(
address?: string,
tokens?: (Token | undefined)[]
): [{ [tokenAddress: string]: CurrencyAmount<Token> | undefined }, boolean] {
const { chainId } = useAccountDetails() // we cannot fetch balances cross-chain
// const validatedTokens: Token[] = useMemo(
// () => tokens?.filter((t?: Token): t is Token => isAddress(t?.address) !== false && t?.chainId === chainId) ?? [],
// [chainId, tokens]
// )
const validatedTokens: Token[] = []
const validatedTokens: Token[] = useMemo(
() => tokens?.filter((t?: Token): t is Token => isAddressValidForStarknet(t?.address) !== false) ?? [],
[tokens]
)
const validatedTokenAddresses = useMemo(() => validatedTokens.map((vt) => vt.address), [validatedTokens])

// const balances = useMultipleContractSingleData(
// validatedTokenAddresses,
// ERC20Interface,
// 'balanceOf',
// useMemo(() => [address], [address]),
// tokenBalancesGasRequirement
// )
const balances = useMultipleContractSingleData(validatedTokenAddresses, ERC20_ABI as Abi, 'balanceOf', {
account: address ?? '0',
})

// const anyLoading: boolean = useMemo(() => balances.some((callState) => callState.loading), [balances])
const anyLoading: boolean = useMemo(() => balances.some((callState) => callState.loading), [balances])

return useMemo(() => [{}, false], [address, validatedTokens])
return useMemo(
() => [
address && validatedTokens.length > 0
? validatedTokens.reduce<{ [tokenAddress: string]: CurrencyAmount<Token> | undefined }>((memo, token, i) => {
const value = balances?.[i]?.result?.[0]
const amount = value ? JSBI.BigInt(value.toString()) : undefined
if (amount) {
memo[token.address] = CurrencyAmount.fromRawAmount(token, amount)
}
return memo
}, {})
: {},
anyLoading,
],
[address, validatedTokens, anyLoading, balances]
)
}

export function useTokenBalances(
Expand Down
Loading

0 comments on commit 751c8fd

Please sign in to comment.