Skip to content

Commit

Permalink
chore: Add BPT price calc (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethfuller authored Dec 20, 2023
1 parent 295d59e commit e18f310
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit e18f310

Please sign in to comment.