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: add v3 dynamic swap fees #198

Merged
merged 9 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions packages/lib/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@ export function getChainName(chainId: GqlChain | SupportedChainId) {
export function getChainShortName(chainId: GqlChain | SupportedChainId) {
return getNetworkConfig(chainId).shortName
}

export const DELEGATE_OWNER = '0xba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b'
1 change: 1 addition & 0 deletions packages/lib/config/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ export interface ProjectConfig {
variantConfig?: VariantConfig
defaultNetwork: GqlChain
ensNetwork: GqlChain
delegateOwner: Address
}
1 change: 1 addition & 0 deletions packages/lib/config/projects/balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export const ProjectConfigBalancer: ProjectConfig = {
corePoolId: '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014', // veBAL BAL8020 (Balancer 80 BAL 20 WETH) pool on Ethereum
defaultNetwork: GqlChain.Mainnet,
ensNetwork: GqlChain.Mainnet,
delegateOwner: '0xba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b',
}
1 change: 1 addition & 0 deletions packages/lib/config/projects/beets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const ProjectConfigBeets: ProjectConfig = {
corePoolId: '0x9e4341acef4147196e99d648c5e43b3fc9d026780002000000000000000005ec', // maBEETS BEETS8020 (Fresh BEETS) pool on Fantom
defaultNetwork: GqlChain.Fantom,
ensNetwork: GqlChain.Fantom,
delegateOwner: '0xba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b', // TODO update this for sonic & optimism
}
44 changes: 3 additions & 41 deletions packages/lib/modules/pool/PoolDetail/PoolHeader/PoolMetaBadges.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
'use client'

import {
Badge,
Flex,
HStack,
Text,
Popover,
PopoverTrigger,
PopoverContent,
} from '@chakra-ui/react'
import { Badge, Flex } from '@chakra-ui/react'
import { usePool } from '../../PoolProvider'
import Image from 'next/image'
import { fNum } from '@repo/lib/shared/utils/numbers'
import { Repeat } from 'react-feather'
import { PoolListTokenPills } from '../../PoolList/PoolListTokenPills'
import { shouldHideSwapFee } from '../../pool.utils'
import { getChainShortName } from '@repo/lib/config/app.config'
import { PoolTypeTag } from '../PoolTypeTag'
import { PoolVersionTag } from '../../PoolList/PoolListTable/PoolVersionTag'
import { PoolHookTag } from '../PoolHookTag'
import { PoolSwapFees } from './PoolSwapFees'

export default function PoolMetaBadges() {
const { pool, chain } = usePool()
Expand Down Expand Up @@ -46,36 +37,7 @@ export default function PoolMetaBadges() {
<PoolVersionTag isSmall pool={pool} />
<PoolTypeTag pool={pool} />
<PoolHookTag />
{!shouldHideSwapFee(pool.type) && (
<Popover trigger="hover">
<PopoverTrigger>
<Badge
alignItems="center"
background="background.level2"
border="1px solid"
borderColor="border.base"
display="flex"
fontWeight="normal"
h={{ base: '28px' }}
px="sm"
py="sm"
rounded="full"
shadow="sm"
>
<HStack color="font.primary">
<Repeat size={12} />
<Text fontSize="xs">{fNum('feePercent', pool.dynamicData.swapFee)}</Text>
</HStack>
</Badge>
</PopoverTrigger>
<PopoverContent maxW="300px" p="sm" w="auto">
<Text fontSize="sm" variant="secondary">
The swap fee rate earned by Liquidity Providers anytime a swap is routed through this
pool. These fees automatically accumulate into each LP&rsquo;s position.
</Text>
</PopoverContent>
</Popover>
)}
{!shouldHideSwapFee(pool.type) && <PoolSwapFees pool={pool} />}
</Flex>
)
}
71 changes: 71 additions & 0 deletions packages/lib/modules/pool/PoolDetail/PoolHeader/PoolSwapFees.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
Popover,
PopoverTrigger,
Badge,
HStack,
PopoverContent,
Text,
VStack,
Box,
} from '@chakra-ui/react'
import { fNum } from '@repo/lib/shared/utils/numbers'
import { Repeat } from 'react-feather'
import { Pool } from '../../PoolProvider'
import { shouldCallComputeDynamicSwapFee } from '../../pool.utils'
import { FluidIcon } from '@repo/lib/shared/components/icons/FluidIcon'

export function PoolSwapFees({ pool }: { pool: Pool }) {
const isDynamicSwapFee = shouldCallComputeDynamicSwapFee(pool)
return (
<Popover trigger="hover">
{({ isOpen }) => (
<>
<PopoverTrigger>
<Badge
alignItems="center"
background="background.level2"
border="1px solid"
borderColor={isOpen ? 'font.highlight' : 'border.base'}
display="flex"
fontWeight="normal"
h={{ base: '28px' }}
px="sm"
py="sm"
rounded="full"
shadow="sm"
>
<HStack color={isOpen ? 'font.highlight' : 'font.primary'}>
<Repeat size={12} />
{isDynamicSwapFee ? (
<Box color={isOpen ? 'font.highlight' : 'font.secondary'}>
<FluidIcon />
</Box>
) : (
<Text color={isOpen ? 'font.highlight' : 'inherit'} fontSize="xs">
{fNum('feePercent', pool.dynamicData.swapFee)}
</Text>
)}
</HStack>
</Badge>
</PopoverTrigger>
<PopoverContent maxW="300px" p="sm" w="auto">
<VStack alignItems="flex-start">
<Text color="font.secondary" fontWeight="bold" size="md">
Dynamic fee percentage
</Text>
{isDynamicSwapFee ? (
<Text fontSize="sm" variant="secondary">
This pool has a dynamic fee rate that may change per swap based on custom logic.
</Text>
) : (
<Text fontSize="sm" variant="secondary">
This pool has a dynamic fee rate that may be updated through Balancer governance.
</Text>
)}
</VStack>
</PopoverContent>
</>
)}
</Popover>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import { useMemo } from 'react'
import { usePool } from '../../../PoolProvider'
import { format } from 'date-fns'
import { DELEGATE_OWNER } from '@repo/lib/config/app.config'
import { zeroAddress } from 'viem'
import { abbreviateAddress } from '@repo/lib/shared/utils/addresses'
import { fNum } from '@repo/lib/shared/utils/numbers'
import { isBoosted, isCowAmmPool, isStable } from '../../../pool.helpers'
import { useCurrency } from '@repo/lib/shared/hooks/useCurrency'
import { getPoolTypeLabel, shouldHideSwapFee } from '../../../pool.utils'
import { useTokens } from '@repo/lib/modules/tokens/TokensProvider'
import { getProjectConfig } from '@repo/lib/config/getProjectConfig'

export function useFormattedPoolAttributes() {
const { pool } = usePool()
const { toCurrency } = useCurrency()
const { usdValueForBpt } = useTokens()

const { delegateOwner } = getProjectConfig()

const poolOwnerData = useMemo(() => {
if (!pool) return
const { owner } = pool
Expand All @@ -31,7 +33,7 @@
}
}

if (owner === DELEGATE_OWNER) {
if (owner === delegateOwner) {
return {
title: 'Delegate owner',
link: '',
Expand All @@ -50,7 +52,7 @@
? ' except for swap fees and AMP factor editable by the pool owner'
: ' except for swap fees editable by the pool owner',
}
}, [pool])

Check warning on line 55 in packages/lib/modules/pool/PoolDetail/PoolInfo/PoolAttributes/useFormattedPoolAttributes.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has a missing dependency: 'delegateOwner'. Either include it or remove the dependency array

const formattedPoolAttributes = useMemo(() => {
if (!pool) return []
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/modules/pool/pool.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ export function shouldHideSwapFee(poolType: GqlPoolType) {
return poolType === GqlPoolType.CowAmm
}

export function shouldCallComputeDynamicSwapFee(pool: Pool) {
return pool.hook && pool.hook.shouldCallComputeDynamicSwapFee
}

export function getPoolDisplayTokens(pool: Pool) {
return pool.poolTokens.filter(token =>
pool.displayTokens.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ test('queries remove liquidity transaction', async () => {
expect(result.current.sentBptUnits).toBe('6439.400687368663510166')
})

describe('queries swap transaction', () => {
/*
Skip until dRPC fixes issue with polygon tx queries
*/
describe.skip('queries swap transaction', () => {
const maticAddress = '0x0000000000000000000000000000000000001010'
const wMaticAddress = '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
const daiAddress = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063'
Expand Down
27 changes: 27 additions & 0 deletions packages/lib/shared/components/icons/FluidIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable max-len */
export function FluidIcon({ size = 20 }: { size?: number }) {
return (
<svg
fill="none"
height={size}
viewBox="0 0 20 20"
width={size}
xmlns="http://www.w3.org/2000/svg"
>
<g clipPath="url(#a)">
<path
d="M16.991 10.5h-1.554c-.694 0-1.29-.665-1.368-1.553-.23-2.68-.582-4.661-2.135-4.661-1.554 0-1.942 2.782-1.942 6.215 0 3.431-.389 6.214-1.942 6.214-1.554 0-1.905-1.979-2.136-4.66-.078-.892-.673-1.554-1.37-1.554H2.992"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.554"
/>
</g>
<defs>
<clipPath id="a">
<path d="M0 0h20v20H0z" fill="#fff" transform="translate(0 .5)" />
</clipPath>
</defs>
</svg>
)
}
Loading