Skip to content

Commit

Permalink
feat: add new chain supported: Linea (#2117)
Browse files Browse the repository at this point in the history
* feat: add new chain supported: Linea

* disable pools on Linea

* revert env

* fix: comment
  • Loading branch information
viet-nv authored Jul 28, 2023
1 parent 922c45f commit f2100ed
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 28 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'),
],
}
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,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
34 changes: 30 additions & 4 deletions src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Sentry from '@sentry/react'
import { Suspense, lazy, useEffect } from 'react'
import { isMobile } from 'react-device-detect'
import { AlertTriangle } from 'react-feather'
import { Navigate, Route, Routes, useLocation, useParams } from 'react-router-dom'
import { Navigate, Route, Routes, useLocation, useNavigate, useParams } from 'react-router-dom'
import { useNetwork, usePrevious } from 'react-use'
import { Flex, Text } from 'rebass'
import styled from 'styled-components'
Expand All @@ -14,6 +14,7 @@ import snow from 'assets/images/snow.png'
import Popups from 'components/Announcement/Popups'
import TopBanner from 'components/Announcement/Popups/TopBanner'
import AppHaveUpdate from 'components/AppHaveUpdate'
import { ButtonPrimary } from 'components/Button'
import ModalConfirm from 'components/ConfirmModal'
import ErrorBoundary from 'components/ErrorBoundary'
import Footer from 'components/Footer/Footer'
Expand Down Expand Up @@ -45,6 +46,22 @@ import ElasticLegacyNotice from './ElasticLegacy/ElasticLegacyNotice'
import Icons from './Icons'
import VerifyAuth from './Verify/VerifyAuth'

// THIS IS ONLY TEMPORARY, WILL REMOVE IN NEXT VERSION
const CommingSoonModal = () => {
const navigate = useNavigate()
return (
<Modal isOpen onDismiss={() => navigate('/')}>
<Flex flexDirection="column" padding="24px" sx={{ gap: '2rem' }} justifyContent="center" alignItems="center">
<Text fontSize={14}>Our pools and farms will be available soon!</Text>

<ButtonPrimary style={{ width: '160px', height: '32px' }} onClick={() => navigate('/')}>
Ok
</ButtonPrimary>
</Flex>
</Modal>
)
}

// test page for swap only through elastic
const ElasticSwap = lazy(() => import('./ElasticSwap'))
const SwapV2 = lazy(() => import('./SwapV2'))
Expand Down Expand Up @@ -331,19 +348,28 @@ export default function App() {
<>
{/* Pools Routes */}
<Route path={`${APP_PATHS.POOLS}`} element={<RedirectWithNetworkSuffix />} />
<Route path={`${APP_PATHS.POOLS}/:network/:currencyIdA?/:currencyIdB?`} element={<Pools />} />
<Route
path={`${APP_PATHS.POOLS}/:network/:currencyIdA?/:currencyIdB?`}
element={chainId === ChainId.LINEA ? <CommingSoonModal /> : <Pools />}
/>
</>

<>
{/* Farms Routes */}
<Route path={`${APP_PATHS.FARMS}`} element={<RedirectWithNetworkSuffix />} />
<Route path={`${APP_PATHS.FARMS}/:network`} element={<Farm />} />
<Route
path={`${APP_PATHS.FARMS}/:network`}
element={chainId === ChainId.LINEA ? <CommingSoonModal /> : <Farm />}
/>
</>

<>
{/* My Pools Routes */}
<Route path={`${APP_PATHS.MY_POOLS}`} element={<RedirectWithNetworkSuffix />} />
<Route path={`${APP_PATHS.MY_POOLS}/:network`} element={<MyPools />} />
<Route
path={`${APP_PATHS.MY_POOLS}/:network`}
element={chainId === ChainId.LINEA ? <CommingSoonModal /> : <MyPools />}
/>
</>

<>
Expand Down
18 changes: 7 additions & 11 deletions src/state/about/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export function useGlobalData() {
}
const getResultByChainIds = async (chainIds: readonly ChainId[]) => {
// todo namgold: add aggregator API for solana
const elasticChains = chainIds
.filter(id => isEVM(id))
.filter(id => !ELASTIC_NOT_SUPPORTED[id] && id !== ChainId.LINEA_TESTNET)
const elasticChains = chainIds.filter(id => isEVM(id)).filter(id => !ELASTIC_NOT_SUPPORTED[id])

const elasticPromises = elasticChains.map(chain =>
allKyberswapConfig[chain].elasticClient.query({
Expand All @@ -72,14 +70,12 @@ export function useGlobalData() {
return total + parseFloat(item?.data?.factories?.[0]?.totalValueLockedUSD || '0')
}, 0)

const allChainPromises = chainIds
.filter(id => isEVM(id) && id !== ChainId.LINEA_TESTNET)
.map(chain =>
allKyberswapConfig[chain].classicClient.query({
query: GLOBAL_DATA(),
fetchPolicy: 'cache-first',
}),
)
const allChainPromises = chainIds.filter(isEVM).map(chain =>
allKyberswapConfig[chain].classicClient.query({
query: GLOBAL_DATA(),
fetchPolicy: 'cache-first',
}),
)

const queryResult = (await Promise.all(allChainPromises.map(promises => promises.catch(e => e)))).filter(
res => !(res instanceof Error),
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2068,10 +2068,10 @@
tiny-warning "^1.0.3"
toformat "^2.0.0"

"@kyberswap/ks-sdk-core@1.0.7-rc2", "@kyberswap/ks-sdk-core@^1.0.5":
version "1.0.7-rc2"
resolved "https://registry.yarnpkg.com/@kyberswap/ks-sdk-core/-/ks-sdk-core-1.0.7-rc2.tgz#ab707a43625bdd6b7416ad0482c94d2a25e9560a"
integrity sha512-CaWbLr7+3AXLHsF3AxMTapjvAo/AisRZQghtY664mzEk6otYfXeeizcgV3o/gML7/rW3YPdUFM4iifwHcXlOqQ==
"@kyberswap/ks-sdk-core@1.0.8", "@kyberswap/ks-sdk-core@^1.0.5":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@kyberswap/ks-sdk-core/-/ks-sdk-core-1.0.8.tgz#11dbcbc7fd2d1243e221c5e7436be2b7735ee108"
integrity sha512-mbOr9oLcEmtKWdyXKio4pUWRBX0qkFHOrNmSet81MsXMCgIz59hMFqlZ7KSNL8j8iOJOR79j7s8deOUtghQsKA==
dependencies:
"@ethersproject/address" "^5.0.2"
"@solana/web3.js" "^1.66.2"
Expand Down

0 comments on commit f2100ed

Please sign in to comment.