Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate kn-protocol for classic pages #2274

Merged
merged 52 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2dce49a
feat: integrate kn-protocol for classic pages
namgold Oct 2, 2023
95c5aef
unused export & rename
namgold Oct 2, 2023
79cf747
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 3, 2023
7f6a9db
prod env
namgold Oct 6, 2023
b5af4b8
classic farm
namgold Oct 9, 2023
d80d70c
fix paging
namgold Oct 10, 2023
ae355e3
fix precision
namgold Oct 10, 2023
0addac8
rm nodemodule
namgold Oct 10, 2023
c7b3b39
fix build
namgold Oct 10, 2023
b74c87c
fix build
namgold Oct 10, 2023
45957a7
fix crash
namgold Oct 11, 2023
56331e3
fix farm parse fail
namgold Oct 11, 2023
a07609c
fix shown number
namgold Oct 11, 2023
d15811d
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 12, 2023
9191569
dev env
namgold Oct 12, 2023
7138ed1
prod env
namgold Oct 12, 2023
5ade7a1
connect button
namgold Oct 12, 2023
a807b95
remove last reward
namgold Oct 12, 2023
d77afac
fix APR
namgold Oct 12, 2023
d168640
farm unwrap token
namgold Oct 12, 2023
9402e0f
catch undefined
namgold Oct 12, 2023
911ed1a
grouping farm
namgold Oct 12, 2023
b3e6295
prevent cache
namgold Oct 12, 2023
222b48d
clear cache
namgold Oct 12, 2023
c75b1b9
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 12, 2023
30b4b05
fix tvl
namgold Oct 12, 2023
0a96b66
fix staked amount
namgold Oct 13, 2023
6a65e0d
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 13, 2023
c21909c
fix shown APR
namgold Oct 13, 2023
cbf7658
add todo
namgold Oct 13, 2023
0608957
increase subscript number
namgold Oct 13, 2023
62d2f6d
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 16, 2023
7498fce
improve decimal
namgold Oct 16, 2023
76b07bd
rename mypool
namgold Oct 16, 2023
f254150
revamp token
namgold Oct 16, 2023
f7ba412
move resetApiState => invalidateTags
namgold Oct 16, 2023
ce63f46
invalidate tags
namgold Oct 18, 2023
2c4e14a
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 18, 2023
c6d9016
remove todo solana
namgold Oct 18, 2023
8f29eb3
revert CI
namgold Oct 18, 2023
7d245b5
fix CI
namgold Oct 18, 2023
23b65d1
add destructuredArrayIgnorePattern
namgold Oct 19, 2023
112f2d0
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 19, 2023
07609b1
use jsdoc deprecated
namgold Oct 19, 2023
ee1a1da
test farm v3
viet-nv Oct 19, 2023
9109ebb
fix support v3
namgold Oct 19, 2023
4f450ff
fix: token not whitelisted for classic v3
viet-nv Oct 19, 2023
e1e2008
Merge branch 'feat/classic-farmv3' into feat/kn-protocol-classic
namgold Oct 19, 2023
b16f0e4
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 19, 2023
6ac9ce3
interval reset data
namgold Oct 19, 2023
5ecbf6a
revert
namgold Oct 20, 2023
4ba9ea1
Merge branch 'main' into feat/kn-protocol-classic
namgold Oct 20, 2023
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
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ ignoreRestSiblings: true, argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
{
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
},
],
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'off',
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ jobs:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ env.SERVICE }}-buildx

- name: Restore node_modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
# - name: Restore node_modules
nguyenhoaidanh marked this conversation as resolved.
Show resolved Hide resolved
# uses: actions/cache@v2
# with:
# path: '**/node_modules'
# key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Install dependences
uses: bahmutov/npm-install@HEAD
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

notes.txt
notes*.*
.idea/

.vscode/
Expand Down
4 changes: 2 additions & 2 deletions patches/@walletconnect+ethereum-provider+2.8.1.patch

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions src/components/PoolList/ItemCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ import { APP_PATHS, DMM_ANALYTICS_URL, ONE_BIPS, SUBGRAPH_AMP_MULTIPLIER } from
import { EVMNetworkInfo } from 'constants/networks/type'
import { NativeCurrencies } from 'constants/tokens'
import { useActiveWeb3React } from 'hooks'
import { ClassicPoolData } from 'hooks/pool/classic/type'
import useTheme from 'hooks/useTheme'
import { IconWrapper } from 'pages/Pools/styleds'
import { useActiveAndUniqueFarmsData } from 'state/farms/classic/hooks'
import { Farm } from 'state/farms/classic/types'
import { useMultipleContractSingleData } from 'state/multicall/hooks'
import { SubgraphPoolData, UserLiquidityPosition, useSharedPoolIdManager } from 'state/pools/hooks'
import { UserLiquidityPosition, useSharedPoolIdManager } from 'state/pools/hooks'
import { tryParseAmount } from 'state/swap/hooks'
import { ExternalLink } from 'theme'
import { formattedNum, shortenAddress } from 'utils'
import { shortenAddress } from 'utils'
import { currencyId } from 'utils/currencyId'
import {
feeRangeCalc,
Expand All @@ -49,6 +50,7 @@ import {
priceRangeCalcBySubgraphPool,
useFarmApr,
} from 'utils/dmm'
import { formatDisplayNumber, parseFraction } from 'utils/numbers'
import { getTokenSymbolWithHardcode } from 'utils/tokenInfo'

const StyledLink = styled(ExternalLink)`
Expand All @@ -57,7 +59,7 @@ const StyledLink = styled(ExternalLink)`
}
`
interface ListItemProps {
poolData: SubgraphPoolData
poolData: ClassicPoolData
myLiquidity?: UserLiquidityPosition
}

Expand Down Expand Up @@ -104,7 +106,11 @@ const ItemCard = ({ poolData, myLiquidity }: ListItemProps) => {

const [, setSharedPoolId] = useSharedPoolIdManager()

const ampLiquidity = formattedNum(`${parseFloat(amp.toSignificant(5)) * parseFloat(poolData.reserveUSD)}`, true)
const ampLiquidity = formatDisplayNumber(amp.multiply(parseFraction(poolData.reserveUSD)), {
style: 'currency',
significantDigits: 7,
fractionDigits: 4,
})
const volume = poolData.oneDayVolumeUSD ? poolData.oneDayVolumeUSD : poolData.oneDayVolumeUntracked
const fee24H = poolData.oneDayFeeUSD ? poolData.oneDayFeeUSD : poolData.oneDayFeeUntracked
const oneYearFL = getTradingFeeAPR(poolData.reserveUSD, fee24H).toFixed(2)
Expand All @@ -131,7 +137,7 @@ const ItemCard = ({ poolData, myLiquidity }: ListItemProps) => {
<Text fontSize="16px" fontWeight="500">
{currency0Symbol} - {currency1Symbol}
</Text>
<FeeTag style={{ fontSize: '12px' }}>AMP {formattedNum(amp.toSignificant(5))}</FeeTag>
<FeeTag style={{ fontSize: '12px' }}>AMP {formatDisplayNumber(amp, { significantDigits: 5 })}</FeeTag>

{isFarmingPool && (
<MouseoverTooltip
Expand Down Expand Up @@ -303,8 +309,8 @@ const ItemCard = ({ poolData, myLiquidity }: ListItemProps) => {
</Flex>

<Flex justifyContent="space-between" fontSize="16px" fontWeight="500" marginTop="0.25rem" marginBottom="1rem">
<Text>{formattedNum(volume, true)}</Text>
<Text>{formattedNum(fee24H, true)}</Text>
<Text>{formatDisplayNumber(volume, { style: 'currency', significantDigits: 5 })}</Text>
<Text>{formatDisplayNumber(fee24H, { style: 'currency', significantDigits: 5 })}</Text>
</Flex>

<Divider />
Expand All @@ -327,7 +333,9 @@ const ItemCard = ({ poolData, myLiquidity }: ListItemProps) => {
fontWeight="500"
marginTop="0.25rem"
>
<Text>{formattedNum(poolData.reserveUSD, true)}</Text>
<Text>
{formatDisplayNumber(poolData.reserveUSD, { style: 'currency', significantDigits: 7, fractionDigits: 4 })}
</Text>
<Text textAlign="center">{ampLiquidity}</Text>
<Text textAlign="end">{myLiquidity ? getMyLiquidity(myLiquidity) : '-'}</Text>
</Box>
Expand Down Expand Up @@ -491,10 +499,7 @@ const ItemCard = ({ poolData, myLiquidity }: ListItemProps) => {
}

const FarmCalculator = ({ farm, onUpdate }: { farm: Farm; onUpdate: (value: number) => void }) => {
const lpTokenRatio = new Fraction(
farm.totalStake.toString(),
JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(18)),
).divide(
const lpTokenRatio = farm.totalStake.divide(
new Fraction(parseUnits(farm.totalSupply, 18).toString(), JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(18))),
)
const liquidity = parseFloat(lpTokenRatio.toSignificant(6)) * parseFloat(farm.reserveUSD)
Expand Down
33 changes: 23 additions & 10 deletions src/components/PoolList/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ import { FeeTag } from 'components/YieldPools/ElasticFarmGroup/styleds'
import { ClassicFarmingPoolAPRCell } from 'components/YieldPools/FarmingPoolAPRCell'
import { APP_PATHS, MAX_ALLOW_APY } from 'constants/index'
import { useActiveWeb3React } from 'hooks'
import { ClassicPoolData } from 'hooks/pool/classic/type'
import useTheme from 'hooks/useTheme'
import { IconWrapper } from 'pages/Pools/styleds'
import { usePoolDetailModalToggle } from 'state/application/hooks'
import { useActiveAndUniqueFarmsData } from 'state/farms/classic/hooks'
import { setSelectedPool } from 'state/pools/actions'
import { SubgraphPoolData, UserLiquidityPosition, useSharedPoolIdManager } from 'state/pools/hooks'
import { formattedNum, shortenAddress } from 'utils'
import { UserLiquidityPosition, useSharedPoolIdManager } from 'state/pools/hooks'
import { shortenAddress } from 'utils'
import { currencyId } from 'utils/currencyId'
import { getMyLiquidity, getTradingFeeAPR, parseSubgraphPoolData } from 'utils/dmm'
import { formatDisplayNumber, parseFraction } from 'utils/numbers'
import { getTokenSymbolWithHardcode } from 'utils/tokenInfo'

interface ListItemGroupProps {
poolData: SubgraphPoolData
poolData: ClassicPoolData
userLiquidityPositions: { [key: string]: UserLiquidityPosition }
}

Expand All @@ -57,7 +59,6 @@ const ListItem = ({ poolData, userLiquidityPositions }: ListItemGroupProps) => {
)
const currency0Symbol = getTokenSymbolWithHardcode(chainId, currency0.wrapped.address, currency0.symbol)
const currency1Symbol = getTokenSymbolWithHardcode(chainId, currency1.wrapped.address, currency1.symbol)

const realPercentToken0 =
reserve0 && virtualReserve0 && reserve1 && virtualReserve1
? reserve0.asFraction
Expand All @@ -73,8 +74,16 @@ const ListItem = ({ poolData, userLiquidityPositions }: ListItemGroupProps) => {

const oneYearFL = getTradingFeeAPR(poolData.reserveUSD, fee24H).toFixed(2)

const ampLiquidity = formattedNum(`${parseFloat(amp.toSignificant(5)) * parseFloat(poolData.reserveUSD)}`, true)
const totalValueLocked = formattedNum(`${parseFloat(poolData.reserveUSD)}`, true)
const ampLiquidity = formatDisplayNumber(amp.multiply(parseFraction(poolData.reserveUSD)), {
style: 'currency',
significantDigits: 7,
fractionDigits: 4,
})
const totalValueLocked = formatDisplayNumber(poolData.reserveUSD, {
style: 'currency',
significantDigits: 7,
fractionDigits: 4,
})

const onTogglePoolDetailModal = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
event.stopPropagation()
Expand Down Expand Up @@ -111,7 +120,7 @@ const ListItem = ({ poolData, userLiquidityPositions }: ListItemGroupProps) => {
paddingRight: '20px', // to make all the APR numbers vertically align
}}
>
{oneYearFL}%
{formatDisplayNumber(Number(oneYearFL) / 100, { style: 'percent', fractionDigits: 2 })}
</Flex>
)
}
Expand All @@ -124,7 +133,7 @@ const ListItem = ({ poolData, userLiquidityPositions }: ListItemGroupProps) => {
<Text fontSize="14px" fontWeight="500">
{currency0Symbol} - {currency1Symbol}
</Text>
<FeeTag style={{ padding: '4px 6px' }}>AMP {formattedNum(amp.toSignificant(5))}</FeeTag>
<FeeTag style={{ padding: '4px 6px' }}>AMP {formatDisplayNumber(amp, { significantDigits: 5 })}</FeeTag>
{isFarmingPool && (
<MouseoverTooltip placement="top" text={t`Available for yield farming`}>
<Link to={`${APP_PATHS.FARMS}/${networkInfo.route}?tab=classic&type=active&search=${poolData.id}`}>
Expand Down Expand Up @@ -185,8 +194,12 @@ const ListItem = ({ poolData, userLiquidityPositions }: ListItemGroupProps) => {
>
{renderAPR()}
</DataText>
<DataText alignItems="flex-end">{!poolData ? <Loader /> : formattedNum(volume, true)}</DataText>
<DataText alignItems="flex-end">{!poolData ? <Loader /> : formattedNum(fee24H, true)}</DataText>
<DataText alignItems="flex-end">
{!poolData ? <Loader /> : formatDisplayNumber(volume, { style: 'currency', significantDigits: 6 })}
</DataText>
<DataText alignItems="flex-end">
{!poolData ? <Loader /> : formatDisplayNumber(fee24H, { style: 'currency', significantDigits: 6 })}
</DataText>
<DataText alignItems="flex-end">{getMyLiquidity(myLiquidity)}</DataText>
<ButtonWrapper style={{ marginRight: '-3px' }}>
<ButtonEmpty
Expand Down
Loading
Loading