Skip to content

Commit

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

* disable pools on Linea

* add classic config

* update classic

* add subgraph link

* fix: KEP-1442

* add farm

* fix: farm

* fix: havest tx hash

* revert env
  • Loading branch information
viet-nv authored Aug 3, 2023
1 parent 4808e75 commit 1fa941b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 132 deletions.
2 changes: 1 addition & 1 deletion src/components/ClassicElasticTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function ClassicElasticTab() {

const showLegacyExplicit = upToMedium ? false : isFarmpage ? shouldShowFarmTab : shouldShowPositionTab

const dontShowLegacy = chainId === ChainId.LINEA_TESTNET
const dontShowLegacy = [ChainId.LINEA_TESTNET, ChainId.LINEA].includes(chainId)

const legacyTag = (small?: boolean) => (
<Text
Expand Down
13 changes: 3 additions & 10 deletions src/components/PoolList/ItemCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,12 @@ const ItemCard = ({ poolData, myLiquidity }: ListItemProps) => {
? tryParseAmount(myLiquidity?.liquidityTokenBalance, NativeCurrencies[chainId])
: undefined

const pooledToken0 =
liquidityTokenBalance && reserve0 && totalSupply
? liquidityTokenBalance.multiply(reserve0).divide(totalSupply)
: undefined

const pooledToken1 =
liquidityTokenBalance && reserve1 && totalSupply
? liquidityTokenBalance.multiply(reserve1).divide(totalSupply)
: undefined

const yourShareOfPool =
liquidityTokenBalance && totalSupply ? new Percent(liquidityTokenBalance.quotient, totalSupply.quotient) : undefined

const pooledToken0 = yourShareOfPool && reserve0 ? reserve0.multiply(yourShareOfPool) : undefined
const pooledToken1 = yourShareOfPool && reserve1 ? reserve1.multiply(yourShareOfPool) : undefined

const currency0Symbol = getTokenSymbolWithHardcode(chainId, currency0.wrapped.address, currency0.symbol)
const currency1Symbol = getTokenSymbolWithHardcode(chainId, currency1.wrapped.address, currency1.symbol)

Expand Down
2 changes: 2 additions & 0 deletions src/constants/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const STATIC_FEE_OPTIONS: { [chainId: number]: number[] | undefined } = {
[ChainId.GÖRLI]: [8, 10, 50, 300, 500, 1000],
[ChainId.ZKSYNC]: [8, 10, 50, 300, 500, 1000],
[ChainId.LINEA_TESTNET]: [8, 10, 50, 300, 500, 1000],
[ChainId.LINEA]: [8, 10, 50, 300, 500, 1000],
}

export const ONLY_STATIC_FEE_CHAINS = [
Expand All @@ -177,6 +178,7 @@ export const ONLY_STATIC_FEE_CHAINS = [
ChainId.GÖRLI,
ChainId.ZKSYNC,
ChainId.LINEA_TESTNET,
ChainId.LINEA,
]

// hardcode for unavailable subgraph
Expand Down
16 changes: 9 additions & 7 deletions src/constants/networks/linea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const lineaInfo: EVMNetworkInfo = {
iconDark: NOT_SUPPORT,
iconSelected: NOT_SUPPORT,
iconDarkSelected: NOT_SUPPORT,
defaultBlockSubgraph: '', // TODO
defaultBlockSubgraph: 'https://graph-query.linea.build/subgraphs/name/kybernetwork/linea-blocks',
etherscanUrl: 'https://lineascan.build',
etherscanName: 'Linea Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.LINEA}&isWhitelisted=${true}`,
Expand All @@ -35,11 +35,11 @@ const lineaInfo: EVMNetworkInfo = {
defaultRpcUrl: 'https://rpc.linea.build',
multicall: '0xcA11bde05977b3631167028862bE2a173976CA11',
classic: {
defaultSubgraph: '', // TODO
defaultSubgraph: 'https://graph-query.linea.build/subgraphs/name/kybernetwork/kyberswap-classic-linea',
static: {
zap: '',
router: '',
factory: '',
zap: '0x2abE8750e4a65584d7452316356128C936273e0D',
router: '0x5649B4DD00780e99Bab7Abb4A3d581Ea1aEB23D0',
factory: '0x1c758aF0688502e49140230F6b0EBd376d429be5',
},
oldStatic: NOT_SUPPORT,
dynamic: NOT_SUPPORT,
Expand All @@ -48,15 +48,17 @@ const lineaInfo: EVMNetworkInfo = {
fairlaunchV2: EMPTY_ARRAY,
},
elastic: {
defaultSubgraph: '', // TODO
defaultSubgraph: 'https://graph-query.linea.build/subgraphs/name/kybernetwork/kyberswap-elastic-linea',
startBlock: 1769,
coreFactory: '0xC7a590291e07B9fe9E64b86c58fD8fC764308C4A',
nonfungiblePositionManager: '0xe222fBE074A436145b255442D919E4E3A6c6a480',
tickReader: '0x8Fd8Cb948965d9305999D767A02bf79833EADbB3',
initCodeHash: '0x00e263aaa3a2c06a89b53217a9e7aad7e15613490a72e0f95f303c4de2dc7045',
quoter: '0x4d47fd5a29904Dae0Ef51b1c450C9750F15D7856',
routers: '0xF9c2b5746c946EF883ab2660BbbB1f10A5bdeAb4',
farms: [],
farms: ['0x7D5ba536ab244aAA1EA42aB88428847F25E3E676'],
farmv2Quoter: '0x6AFeb9EDd6Cf44fA8E89b1eee28284e6dD7705C8',
farmV2S: ['0x3d6afe2fb73ffed2e3dd00c501a174554e147a43'],
},
limitOrder: {
production: NOT_SUPPORT,
Expand Down
1 change: 0 additions & 1 deletion src/data/poolRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const getHourlyRateData = async (
elasticClient,
blocks,
[poolAddress],
signal,
100,
)
if (signal.aborted) return
Expand Down
34 changes: 4 additions & 30 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, useNavigate, useParams } from 'react-router-dom'
import { Navigate, Route, Routes, useLocation, useParams } from 'react-router-dom'
import { useNetwork, usePrevious } from 'react-use'
import { Flex, Text } from 'rebass'
import styled from 'styled-components'
Expand All @@ -14,7 +14,6 @@ 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 @@ -46,22 +45,6 @@ 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 @@ -349,28 +332,19 @@ export default function App() {
<>
{/* Pools Routes */}
<Route path={`${APP_PATHS.POOLS}`} element={<RedirectWithNetworkSuffix />} />
<Route
path={`${APP_PATHS.POOLS}/:network/:currencyIdA?/:currencyIdB?`}
element={chainId === ChainId.LINEA ? <CommingSoonModal /> : <Pools />}
/>
<Route path={`${APP_PATHS.POOLS}/:network/:currencyIdA?/:currencyIdB?`} element={<Pools />} />
</>

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

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

<>
Expand Down
2 changes: 1 addition & 1 deletion src/state/farms/elasticv2/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export const useFarmV2Action = (farmAddress: string) => {
})

addTransactionWithType({ hash: tx.hash, type: TRANSACTION_TYPE.HARVEST })
return tx
return tx.hash
} catch (e) {
throw e
}
Expand Down
101 changes: 34 additions & 67 deletions src/state/prommPools/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,7 @@ export interface UserPosition {

const PROMM_USER_POSITIONS = gql`
query positions($owner: Bytes!) {
depositedPositions(where: { user: $owner }) {
id
position {
id
owner
liquidity
tickLower {
tickIdx
}
tickUpper {
tickIdx
}
pool {
id
feeTier
tick
liquidity
reinvestL
sqrtPrice
token0 {
id
derivedETH
symbol
decimals
}
token1 {
id
derivedETH
symbol
decimals
}
}
}
}
positions(where: { owner: $owner, liquidity_gt: 0 }) {
positions(where: { ownerOriginal: $owner, liquidity_gt: 0 }) {
id
owner
liquidity
Expand Down Expand Up @@ -181,38 +147,39 @@ export function useUserProMMPositions(prices: { [address: string]: number }): Us
})

const positions = useMemo(() => {
const farmPositions = data?.depositedPositions?.map((p: any) => p.position) || []
return farmPositions.concat(data?.positions || []).map((p: UserPosition) => {
const token0 = new Token(chainId, p.pool.token0.id, Number(p.pool.token0.decimals), p.pool.token0.symbol)
const token1 = new Token(chainId, p.pool.token1.id, Number(p.pool.token1.decimals), p.pool.token1.symbol)

const pool = new Pool(
token0,
token1,
Number(p.pool.feeTier),
JSBI.BigInt(p.pool.sqrtPrice),
JSBI.BigInt(p.pool.liquidity),
JSBI.BigInt(p.pool.reinvestL),
Number(p.pool.tick),
)

const position = new Position({
pool,
liquidity: p.liquidity,
tickLower: Number(p.tickLower.tickIdx),
tickUpper: Number(p.tickUpper.tickIdx),
})

const token0Amount = CurrencyAmount.fromRawAmount(position.pool.token0, position.amount0.quotient)
const token1Amount = CurrencyAmount.fromRawAmount(position.pool.token1, position.amount1.quotient)

const token0Usd = parseFloat(token0Amount.toFixed()) * (prices[token0.address] || 0)
const token1Usd = parseFloat(token1Amount.toFixed()) * (prices[token1.address] || 0)

const userPositionUSD = token0Usd + token1Usd

return { tokenId: p.id, address: p.pool.id, valueUSD: userPositionUSD }
})
return (
data?.positions.map((p: UserPosition) => {
const token0 = new Token(chainId, p.pool.token0.id, Number(p.pool.token0.decimals), p.pool.token0.symbol)
const token1 = new Token(chainId, p.pool.token1.id, Number(p.pool.token1.decimals), p.pool.token1.symbol)

const pool = new Pool(
token0,
token1,
Number(p.pool.feeTier),
JSBI.BigInt(p.pool.sqrtPrice),
JSBI.BigInt(p.pool.liquidity),
JSBI.BigInt(p.pool.reinvestL),
Number(p.pool.tick),
)

const position = new Position({
pool,
liquidity: p.liquidity,
tickLower: Number(p.tickLower.tickIdx),
tickUpper: Number(p.tickUpper.tickIdx),
})

const token0Amount = CurrencyAmount.fromRawAmount(position.pool.token0, position.amount0.quotient)
const token1Amount = CurrencyAmount.fromRawAmount(position.pool.token1, position.amount1.quotient)

const token0Usd = parseFloat(token0Amount.toFixed()) * (prices[token0.address] || 0)
const token1Usd = parseFloat(token1Amount.toFixed()) * (prices[token1.address] || 0)

const userPositionUSD = token0Usd + token1Usd

return { tokenId: p.id, address: p.pool.id, valueUSD: userPositionUSD }
}) || []
)
}, [data, chainId, prices])

const userLiquidityUsdByPool = useMemo(
Expand Down
17 changes: 2 additions & 15 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ export async function splitQuery<ResultType, T, U>(
localClient: ApolloClient<NormalizedCacheObject>,
list: T[],
vars: U[],
signal: AbortSignal,
skipCount = 100,
): Promise<
| {
Expand All @@ -273,11 +272,6 @@ export async function splitQuery<ResultType, T, U>(
const result = await localClient.query({
query: query(sliced, ...vars),
fetchPolicy: 'no-cache',
context: {
fetchOptions: {
signal,
},
},
})
fetchedData = {
...fetchedData,
Expand All @@ -304,20 +298,13 @@ export async function getBlocksFromTimestampsSubgraph(
blockClient: ApolloClient<NormalizedCacheObject>,
timestamps: number[],
chainId: ChainId,
signal: AbortSignal,
): Promise<{ timestamp: number; number: number }[]> {
if (!isEVM(chainId)) return []
if (timestamps?.length === 0) {
return []
}

const fetchedData = await splitQuery<{ number: string }[], number, any>(
GET_BLOCKS,
blockClient,
timestamps,
[],
signal,
)
const fetchedData = await splitQuery<{ number: string }[], number, any>(GET_BLOCKS, blockClient, timestamps, [])
const blocks: { timestamp: number; number: number }[] = []
if (fetchedData) {
for (const t in fetchedData) {
Expand Down Expand Up @@ -372,7 +359,7 @@ export async function getBlocksFromTimestamps(
signal: AbortSignal,
): Promise<{ timestamp: number; number: number }[]> {
if (isEnableBlockService) return getBlocksFromTimestampsBlockService(timestamps, chainId, signal)
return getBlocksFromTimestampsSubgraph(blockClient, timestamps, chainId, signal)
return getBlocksFromTimestampsSubgraph(blockClient, timestamps, chainId)
}

/**
Expand Down

0 comments on commit 1fa941b

Please sign in to comment.