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

chore: Add BPT price calc #181

Merged
merged 1 commit into from
Dec 20, 2023
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
5 changes: 5 additions & 0 deletions lib/modules/pool/pool.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GqlPoolMinimalType,
} from '@/lib/shared/services/api/generated/graphql'
import { getAddressBlockExplorerLink, isSameAddress } from '@/lib/shared/utils/addresses'
import { bn } from '@/lib/shared/utils/numbers'
import { MinimalToken, PoolStateInput } from '@balancer/sdk'
import BigNumber from 'bignumber.js'
import { Address, Hex, getAddress } from 'viem'
Expand Down Expand Up @@ -107,6 +108,10 @@ export function preMintedBptIndex(pool: GqlPoolBase): number | void {
return pool.allTokens.findIndex(token => isSameAddress(token.address, pool.address))
}

export function calcBptPrice(pool: GetPoolQuery['pool']): string {
return bn(pool.dynamicData.totalLiquidity).div(pool.dynamicData.totalShares).toString()
}

export function createdAfterTimestamp(pool: GqlPoolBase): boolean {
// Pools should always have valid createTime so, for safety, we block the pool in case we don't get it
// (createTime should probably not be treated as optional in the SDK types)
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/pool/usePool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FetchPoolProps } from './pool.types'
import { getNetworkConfig } from '@/lib/config/app.config'
import { useMandatoryContext } from '@/lib/shared/utils/contexts'
import { useSeedApolloCache } from '@/lib/shared/hooks/useSeedApolloCache'
import { usePoolHelpers } from './pool.helpers'
import { calcBptPrice, usePoolHelpers } from './pool.helpers'
import { usePublicClient } from 'wagmi'
import { usePoolEnrichWithOnChainData } from '@/lib/modules/pool/usePoolEnrichWithOnChainData'
import { bn } from '@/lib/shared/utils/numbers'
Expand Down Expand Up @@ -51,7 +51,7 @@ export function _usePool({
// fallbacks to ensure the pool is always present. We prefer the pool with on chain data
const pool = poolWithOnChainData || data?.pool || initialData.pool

const bptPrice = bn(pool.dynamicData.totalLiquidity).div(pool.dynamicData.totalShares).toFixed(2)
const bptPrice = calcBptPrice(pool)

return {
pool,
Expand Down