Skip to content

Commit 5c667cd

Browse files
Dynamic swap fee display (#260)
* Dynamic swap fee display * Upgrade to Typescript 4.5 for Awaited * Upgraded lock file * Compact liquidity total * swap fee fixes for default lpFee * 0 fix * SwapInfo typing fixes * Default params Co-authored-by: Bao <baomai@berkeley.edu>
1 parent a164dca commit 5c667cd

6 files changed

Lines changed: 59 additions & 23 deletions

File tree

features/liquidity/components/LiquidityBreakdown.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
Column,
66
Divider,
77
dollarValueFormatter,
8-
dollarValueFormatterWithDecimals,
98
ImageForTokenLogo,
109
InfoIcon,
1110
Inline,
@@ -34,6 +33,8 @@ type LiquidityBreakdownProps = {
3433
yieldPercentageReturn: number
3534
rewardsContracts: Array<SerializedRewardsContract>
3635
size: 'large' | 'small'
36+
lpFee?: number
37+
protocolFee?: number
3738
}
3839

3940
type PoolHeaderProps = {
@@ -73,13 +74,32 @@ const PoolHeader = ({ tokenA, tokenB, priceBreakdown }: PoolHeaderProps) => (
7374
</Inline>
7475
)
7576

77+
const SwapFee = ({
78+
protocolFee = 0,
79+
lpFee = 0.3,
80+
}: {
81+
protocolFee?: number
82+
lpFee?: number
83+
}) => (
84+
<>
85+
<Text variant="header">{`${protocolFee + lpFee}%`}</Text>
86+
<Tooltip
87+
label={`${lpFee}% of Swap Fee goes to LP Providers (LP) and ${protocolFee}% goes to Raw DAO`}
88+
>
89+
<Button variant="ghost" size="small" icon={<InfoIcon />} />
90+
</Tooltip>
91+
</>
92+
)
93+
7694
export const LiquidityBreakdown = ({
7795
tokenA,
7896
tokenB,
7997
poolId,
8098
totalLiquidity,
8199
yieldPercentageReturn,
82100
rewardsContracts,
101+
lpFee,
102+
protocolFee,
83103
size = 'large',
84104
}: LiquidityBreakdownProps) => {
85105
const [{ price: tokenPrice }, isPriceLoading] = useTokenToTokenPrice({
@@ -103,9 +123,8 @@ export const LiquidityBreakdown = ({
103123
const compactTokenAAmount = formatCompactNumber(tokenAAmount, 'tokenAmount')
104124
const compactTokenBAmount = formatCompactNumber(tokenBAmount, 'tokenAmount')
105125

106-
const formattedTotalLiquidity = dollarValueFormatterWithDecimals(
107-
totalLiquidity?.dollarValue,
108-
{ includeCommaSeparation: true }
126+
const formattedTotalLiquidity = formatCompactNumber(
127+
totalLiquidity?.dollarValue
109128
)
110129

111130
const formattedYieldPercentageReturn = dollarValueFormatter(
@@ -176,12 +195,7 @@ export const LiquidityBreakdown = ({
176195
</Text>
177196

178197
<Inline gap={2}>
179-
<Text variant="header">0.3%</Text>
180-
<Tooltip
181-
label={`0.2% of Swap Fee goes to LP Providers (LP) and 0.1% goes to Raw DAO`}
182-
>
183-
<Button variant="ghost" size="small" icon={<InfoIcon />} />
184-
</Tooltip>
198+
<SwapFee lpFee={lpFee} protocolFee={protocolFee} />
185199
</Inline>
186200
</Column>
187201
{__POOL_REWARDS_ENABLED__ &&
@@ -251,12 +265,7 @@ export const LiquidityBreakdown = ({
251265
</Text>
252266

253267
<Inline gap={2}>
254-
<Text variant="header">0.3%</Text>
255-
<Tooltip
256-
label={`0.2% of Swap Fee goes to LP Providers (LP) and 0.1% goes to Raw DAO`}
257-
>
258-
<Button variant="ghost" size="small" icon={<InfoIcon />} />
259-
</Tooltip>
268+
<SwapFee lpFee={lpFee} protocolFee={protocolFee} />
260269
</Inline>
261270
</Column>
262271

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
"next-bundle-junoblocks": "^1.0.2",
5858
"postcss": "^8.3.5",
5959
"prettier": "^2.3.2",
60-
"typescript": "4.3.5"
60+
"typescript": "4.5"
6161
}
6262
}

pages/pools/[pool].tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ export default function Pool() {
185185
yieldPercentageReturn={
186186
pool.liquidity.rewards.annualYieldPercentageReturn
187187
}
188+
lpFee={pool.swap_info.lp_fee_percent}
189+
protocolFee={pool.swap_info.protocol_fee_percent}
188190
rewardsContracts={pool.liquidity.rewards.contracts}
189191
size={isMobile ? 'small' : 'large'}
190192
/>

queries/querySwapInfo.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
import { getSwapInfo } from '../services/swap'
22

3-
export async function querySwapInfo({ context: { client }, swap_address }) {
3+
const safeNum = (attr: string | undefined): number | undefined =>
4+
attr != undefined ? Number(attr) : undefined
5+
6+
export type SwapInfoResponse = {
7+
swap_address: string
8+
lp_token_supply: number
9+
lp_token_address: string
10+
token1_denom: string
11+
token1_reserve: number
12+
token2_denom: string
13+
token2_reserve: number
14+
owner?: string
15+
lp_fee_percent?: number
16+
protocol_fee_percent?: number
17+
protocol_fee_recipient?: string
18+
}
19+
20+
export async function querySwapInfo({
21+
context: { client },
22+
swap_address,
23+
}): Promise<SwapInfoResponse> {
424
const swap = await getSwapInfo(swap_address, client)
25+
526
return {
627
...swap,
728
swap_address,
829
token1_reserve: Number(swap.token1_reserve),
930
token2_reserve: Number(swap.token2_reserve),
1031
lp_token_supply: Number(swap.lp_token_supply),
32+
protocol_fee_percent: safeNum(swap.protocol_fee_percent),
33+
lp_fee_percent: safeNum(swap.lp_fee_percent),
1134
}
1235
}

queries/useQueryPools.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
SerializedRewardsContract,
1717
} from './queryRewardsContracts'
1818
import { queryStakedLiquidity } from './queryStakedLiquidity'
19-
import { querySwapInfo } from './querySwapInfo'
19+
import { querySwapInfo, SwapInfoResponse } from './querySwapInfo'
2020
import { useGetTokenDollarValueQuery } from './useGetTokenDollarValueQuery'
2121
import { PoolEntityType, usePoolsListQuery } from './usePoolsListQuery'
2222

@@ -54,6 +54,7 @@ export type PoolLiquidityState = {
5454

5555
export type PoolEntityTypeWithLiquidity = PoolEntityType & {
5656
liquidity: PoolLiquidityState
57+
swap_info: SwapInfoResponse
5758
}
5859

5960
type QueryMultiplePoolsArgs = {
@@ -191,6 +192,7 @@ export const useQueryMultiplePoolsLiquidity = ({
191192
return {
192193
...pool,
193194
liquidity,
195+
swap_info: swap,
194196
}
195197
}
196198

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5631,10 +5631,10 @@ type@^2.5.0:
56315631
resolved "https://registry.yarnpkg.com/type/-/type-2.6.0.tgz#3ca6099af5981d36ca86b78442973694278a219f"
56325632
integrity sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ==
56335633

5634-
typescript@4.3.5:
5635-
version "4.3.5"
5636-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
5637-
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
5634+
typescript@4.5:
5635+
version "4.5.5"
5636+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3"
5637+
integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==
56385638

56395639
unbox-primitive@^1.0.2:
56405640
version "1.0.2"

0 commit comments

Comments
 (0)