Skip to content

Commit

Permalink
Merge branch 'main' into feat/wallet-UI-claim-reward
Browse files Browse the repository at this point in the history
  • Loading branch information
namgold authored Jul 31, 2023
2 parents f4dbce9 + 3540215 commit 764f0a5
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 66 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@kybernetwork/oauth2": "1.0.0",
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "1.0.7-rc2",
"@kyberswap/ks-sdk-core": "1.0.8",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
"@kyberswap/ks-sdk-solana": "^1.0.2",
"@lingui/loader": "~3.14.0",
Expand Down Expand Up @@ -199,7 +199,7 @@
"vite-tsconfig-paths": "^4.0.8"
},
"resolutions": {
"@kyberswap/ks-sdk-core": "1.0.7-rc2",
"@kyberswap/ks-sdk-core": "1.0.8",
"react-error-overlay": "6.0.9",
"@lingui/babel-plugin-extract-messages": "3.14.0",
"@lingui/cli": "3.14.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/web3/NetworkModal/Networks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const Networks = ({
{name}
</Text>
</Flex>
{key === ChainId.ZKSYNC && (
{key === ChainId.LINEA && (
<NewLabel>
<Trans>New</Trans>
</NewLabel>
Expand Down
5 changes: 5 additions & 0 deletions src/constants/bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const WETH_ONLY: ChainTokenList = {
[ChainId.ZKSYNC]: [WETH[ChainId.ZKSYNC]],
[ChainId.SOLANA]: [WETH[ChainId.SOLANA]],
[ChainId.LINEA_TESTNET]: [WETH[ChainId.LINEA_TESTNET]],
[ChainId.LINEA]: [WETH[ChainId.LINEA]],
[ChainId.SOLANA_DEVNET]: [WETH[ChainId.SOLANA_DEVNET]],
}

Expand Down Expand Up @@ -183,4 +184,8 @@ export const SUGGESTED_BASES: ChainTokenList = {
USDT[ChainId.LINEA_TESTNET],
DAI[ChainId.LINEA_TESTNET],
],
[ChainId.LINEA]: [
...WETH_ONLY[ChainId.LINEA],
new Token(ChainId.LINEA, '0x7d43aabc515c356145049227cee54b608342c0ad', 18, 'BUSD', 'BUSD'),
],
}
4 changes: 3 additions & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ export const BLOCKED_PRICE_IMPACT_NON_DEGEN: Percent = new Percent(JSBI.BigInt(1

export const BUNDLE_ID = '1'

export const COINGECKO_BFF_API_URL = `${ENV.BFF_API}/v1/coingecko/api/v3`
export const COINGECKO_API_URL = 'https://api.coingecko.com/api/v3'

export const KNC_COINGECKO_ID = 'kyber-network-crystal'

export const ETHER_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
Expand Down Expand Up @@ -337,7 +339,7 @@ export const CHAINS_SUPPORT_CROSS_CHAIN =
ChainId.SOLANA,
]

export const TYPE_AND_SWAP_NOT_SUPPORTED_CHAINS: ChainId[] = [ChainId.ZKSYNC, ChainId.LINEA_TESTNET]
export const TYPE_AND_SWAP_NOT_SUPPORTED_CHAINS: ChainId[] = [ChainId.ZKSYNC, ChainId.LINEA_TESTNET, ChainId.LINEA]

export const SWAP_FEE_RECEIVER_ADDRESS = '0x4f82e73EDb06d29Ff62C91EC8f5Ff06571bdeb29'

Expand Down
5 changes: 3 additions & 2 deletions src/constants/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ethereum,
fantom,
görli,
linea,
lineaTestnet,
matic,
mumbai,
Expand Down Expand Up @@ -50,6 +51,7 @@ export const NETWORKS_INFO_CONFIG: NETWORKS_INFO_CONFIG_TYPE = {
[ChainId.OPTIMISM]: optimism,
[ChainId.ZKSYNC]: zksync,
[ChainId.LINEA_TESTNET]: lineaTestnet,
[ChainId.LINEA]: linea,
[ChainId.SOLANA]: solana,
[ChainId.SOLANA_DEVNET]: solanaDevnet,
} as const
Expand Down Expand Up @@ -80,8 +82,7 @@ export const MAINNET_NETWORKS = [
ChainId.VELAS,
ChainId.AURORA,
ChainId.ZKSYNC,
// TODO(viet-nv): update when integrating LINEA MAINNET
ChainId.LINEA_TESTNET,
ChainId.LINEA,
] as const

export const EVM_NETWORKS = SUPPORTED_NETWORKS.filter(chainId => getChainType(chainId) === ChainType.EVM) as Exclude<
Expand Down
1 change: 1 addition & 0 deletions src/constants/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export { default as solana } from './solana'
export { default as velas } from './velas'
export { default as zksync } from './zksync'
export { default as lineaTestnet } from './linea-testnet'
export { default as linea } from './linea'
export { default as solanaDevnet } from './solana-devnet'
73 changes: 73 additions & 0 deletions src/constants/networks/linea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
const EMPTY_ARRAY: any[] = []
const NOT_SUPPORT = null

const lineaInfo: EVMNetworkInfo = {
chainId: ChainId.LINEA,
route: 'linea',
ksSettingRoute: 'linea',
priceRoute: 'linea',
poolFarmRoute: 'linea',
aggregatorRoute: 'linea',
name: 'Linea',
icon: 'https://linea.build/apple-touch-icon.png',
iconDark: NOT_SUPPORT,
iconSelected: NOT_SUPPORT,
iconDarkSelected: NOT_SUPPORT,
defaultBlockSubgraph: '', // TODO
etherscanUrl: 'https://lineascan.build',
etherscanName: 'Linea Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.LINEA}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ETH',
name: 'LineaETH',
logo: EthereumLogo,
decimal: 18,
minForGas: 10 ** 16,
},
defaultRpcUrl: 'https://rpc.linea.build',
multicall: '0xcA11bde05977b3631167028862bE2a173976CA11',
classic: {
defaultSubgraph: '', // TODO
static: {
zap: '',
router: '',
factory: '',
},
oldStatic: NOT_SUPPORT,
dynamic: NOT_SUPPORT,
claimReward: NOT_SUPPORT,
fairlaunch: EMPTY_ARRAY,
fairlaunchV2: EMPTY_ARRAY,
},
elastic: {
defaultSubgraph: '', // TODO
startBlock: 1769,
coreFactory: '0xC7a590291e07B9fe9E64b86c58fD8fC764308C4A',
nonfungiblePositionManager: '0xe222fBE074A436145b255442D919E4E3A6c6a480',
tickReader: '0x8Fd8Cb948965d9305999D767A02bf79833EADbB3',
initCodeHash: '0x00e263aaa3a2c06a89b53217a9e7aad7e15613490a72e0f95f303c4de2dc7045',
quoter: '0x4d47fd5a29904Dae0Ef51b1c450C9750F15D7856',
routers: '0xF9c2b5746c946EF883ab2660BbbB1f10A5bdeAb4',
farms: [],
},
limitOrder: {
production: NOT_SUPPORT,
development: NOT_SUPPORT,
},
averageBlockTimeInSeconds: 2, // TODO: check these info
coingeckoNetworkId: NOT_SUPPORT,
coingeckoNativeTokenId: NOT_SUPPORT,
deBankSlug: EMPTY,
dexToCompare: NOT_SUPPORT,
geckoTermialId: NOT_SUPPORT,
}

export default lineaInfo
27 changes: 24 additions & 3 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ export const STABLE_COINS_ADDRESS: { [chainId in ChainId]: string[] } = {
'0x8741Ba6225A6BF91f9D73531A98A89807857a2B3', // DAI
'0x7d43AABC515C356145049227CeE54B608342c0ad', // BUSD
],
[ChainId.LINEA]: [
'0x7d43aabc515c356145049227cee54b608342c0ad', // BUSD
],
[ChainId.SOLANA]: [
'EjmyN6qEC1Tf1JxiG1ae7UTJhUxSwk1TCWNWqxWV4J6o', // Dai
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // usdc
Expand Down Expand Up @@ -187,6 +190,7 @@ export const STABLE_COIN_ADDRESSES_TO_TAKE_FEE: Record<ChainId, string[]> = {
[ChainId.BSCMAINNET]: [],
[ChainId.ARBITRUM]: [],
[ChainId.LINEA_TESTNET]: [],
[ChainId.LINEA]: [],
[ChainId.SOLANA_DEVNET]: [],
}

Expand Down Expand Up @@ -285,6 +289,7 @@ export const SUPER_STABLE_COINS_ADDRESS: { [chainId in ChainId]: string[] } = {
[ChainId.BSCTESTNET]: [],
[ChainId.AVAXTESTNET]: [],
[ChainId.LINEA_TESTNET]: [],
[ChainId.LINEA]: [],
[ChainId.SOLANA_DEVNET]: [],
}

Expand Down Expand Up @@ -334,6 +339,7 @@ export const CORRELATED_COINS_ADDRESS: { [chainId in ChainId]: string[][] } = {
[ChainId.BSCTESTNET]: [],
[ChainId.AVAXTESTNET]: [],
[ChainId.LINEA_TESTNET]: [],
[ChainId.LINEA]: [],
[ChainId.SOLANA_DEVNET]: [],
}

Expand Down Expand Up @@ -418,6 +424,10 @@ export const DAI: { [chainId in ChainId]: Token } = {
'DAI',
'Dai',
),

//not existing
[ChainId.LINEA]: new Token(ChainId.LINEA, '0x8741Ba6225A6BF91f9D73531A98A89807857a2B3', 18, 'DAI', 'Dai'),

//not existing on Velas
[ChainId.VELAS]: new Token(ChainId.VELAS, '0xe7dC549AE8DB61BDE71F22097BEcc8dB542cA100', 18, 'DAI', 'Dai Stablecoin'),
//not existing on Oasis
Expand Down Expand Up @@ -509,6 +519,9 @@ export const USDC: { [chainId in ChainId]: Token } = {
'USDC',
'USD Coin',
),

// not existing
[ChainId.LINEA]: new Token(ChainId.LINEA, '0xf56dc6695cF1f5c364eDEbC7Dc7077ac9B586068', 6, 'USDC', 'USD Coin'),
}

export const USDT: { [chainId in ChainId]: Token } = {
Expand Down Expand Up @@ -564,13 +577,18 @@ export const USDT: { [chainId in ChainId]: Token } = {
'USDT',
'Tether USD',
),

[ChainId.LINEA_TESTNET]: new Token(
ChainId.LINEA_TESTNET,
'0x1990BC6dfe2ef605Bfc08f5A23564dB75642Ad73',
6,
'USDT',
'Tether USD',
),

// not existing
[ChainId.LINEA]: new Token(ChainId.LINEA, '0x1990BC6dfe2ef605Bfc08f5A23564dB75642Ad73', 6, 'USDT', 'Tether USD'),

[ChainId.ZKSYNC]: new Token(ChainId.ZKSYNC, '0x493257fd37edb34451f62edf8d2a0c418852ba4c', 6, 'USDT', 'Tether USD'),
[ChainId.SOLANA]: new Token(ChainId.SOLANA, 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', 6, 'USDT', 'Tether USD'),
[ChainId.SOLANA_DEVNET]: new Token(
Expand Down Expand Up @@ -687,14 +705,16 @@ export const KNC: { [chainId in ChainId]: Token } = {
'Kyber Network Crystal',
),

// TODO(viet-nv):
// not existing
[ChainId.LINEA_TESTNET]: new Token(
ChainId.LINEA_TESTNET,
'0x6Cb9750a92643382e020eA9a170AbB83Df05F30B',
6,
'USDT',
'Tether USD',
'KNC',
'KNC',
),
// not existing
[ChainId.LINEA]: new Token(ChainId.LINEA, '0x6Cb9750a92643382e020eA9a170AbB83Df05F30B', 6, 'KNC', 'KNC'),
}

export const PINNED_PAIRS: { readonly [chainId in ChainId]?: [Token, Token][] } = {
Expand Down Expand Up @@ -725,6 +745,7 @@ export const DEFAULT_OUTPUT_TOKEN_BY_CHAIN: Partial<Record<ChainId, Token>> = {
[ChainId.GÖRLI]: KNC[ChainId.GÖRLI],
[ChainId.ZKSYNC]: USDC[ChainId.ZKSYNC],
[ChainId.LINEA_TESTNET]: USDC[ChainId.LINEA_TESTNET],
[ChainId.LINEA]: new Token(ChainId.LINEA, '0x7d43aabc515c356145049227cee54b608342c0ad', 18, 'BUSD', 'BUSD'),
}

export const DEFAULT_SWAP_FEE_STABLE_PAIRS = 4
Expand Down
53 changes: 27 additions & 26 deletions src/hooks/useBasicChartData.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { KyberOauth2Api } from '@kybernetwork/oauth2'
import { ChainId, Token, WETH } from '@kyberswap/ks-sdk-core'
import axios from 'axios'
import { getUnixTime, subHours } from 'date-fns'
import { useMemo } from 'react'
import useSWR from 'swr'

import { AGGREGATOR_API, PRICE_CHART_API } from 'constants/env'
import { COINGECKO_API_URL } from 'constants/index'
import { NETWORKS_INFO } from 'constants/networks'
import { useActiveWeb3React } from 'hooks'

import useCoingeckoAPI from './useCoingeckoAPI'

export enum LiveDataTimeframeEnum {
HOUR = '1H',
FOUR_HOURS = '4H',
Expand Down Expand Up @@ -37,6 +39,7 @@ const getTimeFrameHours = (timeFrame: LiveDataTimeframeEnum) => {
}
}
const generateCoingeckoUrl = (
coingeckoAPI: string,
chainId: ChainId,
address: string | undefined,
timeFrame: LiveDataTimeframeEnum | 'live',
Expand All @@ -46,7 +49,7 @@ const generateCoingeckoUrl = (
timeFrame === 'live' ? timeTo - 1000 : getUnixTime(subHours(new Date(), getTimeFrameHours(timeFrame)))
const cgkId = NETWORKS_INFO[chainId].coingeckoNetworkId
if (!cgkId) return ''
return `${COINGECKO_API_URL}/coins/${cgkId}/contract/${address}/market_chart/range?vs_currency=usd&from=${timeFrom}&to=${timeTo}`
return `${coingeckoAPI}/coins/${cgkId}/contract/${address}/market_chart/range?vs_currency=usd&from=${timeFrom}&to=${timeTo}`
}
const getClosestPrice = (prices: any[], time: number) => {
let closestIndex = 0
Expand All @@ -67,41 +70,35 @@ const fetchKyberDataSWR = async (url: string) => {
}

const fetchKyberDataSWRWithHeader = async (url: string) => {
const res = await axios
.get(url, {
timeout: 5000,
headers: {
'accept-version': 'Latest',
},
})
.catch(error => {
throw error
})
const res = await KyberOauth2Api.get(url, undefined, {
timeout: 5000,
headers: {
'accept-version': 'Latest',
},
})

if (res.status === 204) {
throw new Error('No content')
}
return res.data
}

const fetchCoingeckoDataSWR = async ([tokenAddresses, chainIds, timeFrame]: [
const fetchCoingeckoDataSWR = async ([tokenAddresses, chainIds, timeFrame, coingeckoAPI]: [
tokenAddresses: string[],
chainIds: ChainId[],
timeFrame: any,
coingeckoAPI: string,
]): Promise<any> => {
return await Promise.all(
[tokenAddresses[0], tokenAddresses[1]].map((address, i) =>
axios
.get(generateCoingeckoUrl(chainIds[i], address, timeFrame), { timeout: 5000 })
.then(res => {
if (res.status === 204) {
throw new Error('No content')
}
return res.data
})
.catch(error => {
throw error
}),
KyberOauth2Api.get(generateCoingeckoUrl(coingeckoAPI, chainIds[i], address, timeFrame), undefined, {
timeout: 5000,
}).then(res => {
if (res.status === 204) {
throw new Error('No content')
}
return res.data
}),
),
)
}
Expand All @@ -113,6 +110,7 @@ export default function useBasicChartData(
timeFrame: LiveDataTimeframeEnum,
): { data: ChartData[]; loading: boolean; error: any } {
const { chainId, isEVM, networkInfo } = useActiveWeb3React()
const coingeckoAPI = useCoingeckoAPI()

const isReverse = useMemo(() => {
if (!tokens || !tokens[0] || !tokens[1] || tokens[0].equals(tokens[1]) || tokens[0].chainId !== tokens[1].chainId)
Expand All @@ -135,8 +133,9 @@ export default function useBasicChartData(
isValidating: coingeckoLoading,
} = useSWR(
tokenAddresses[0] && tokenAddresses[1]
? [tokenAddresses, [tokens[0]?.chainId, tokens[1]?.chainId], timeFrame]
? [tokenAddresses, [tokens[0]?.chainId, tokens[1]?.chainId], timeFrame, coingeckoAPI]
: null,

fetchCoingeckoDataSWR,
{
shouldRetryOnError: false,
Expand Down Expand Up @@ -210,7 +209,9 @@ export default function useBasicChartData(
)

const { data: liveCoingeckoData } = useSWR(
isKyberDataNotValid && coingeckoData ? [tokenAddresses, [tokens[0]?.chainId, tokens[1]?.chainId], 'live'] : null,
isKyberDataNotValid && coingeckoData
? [tokenAddresses, [tokens[0]?.chainId, tokens[1]?.chainId], 'live', coingeckoAPI]
: null,
fetchCoingeckoDataSWR,
{
refreshInterval: 60000,
Expand Down
Loading

0 comments on commit 764f0a5

Please sign in to comment.