Get AMM Liquidity Balance
amm.getLiquidityBalance
Gets the LP token balance for an account in a specific pool.
Usage
import { } from './viem.config'
const = await ..({
: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
: '0x20c0000000000000000000000000000000000001',
: '0x20c0000000000000000000000000000000000002',
})
.('Liquidity balance:', )
Liquidity balance: 500000000nimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Recipes
Monitor Your Share of a Pool
Combine the LP balance with amm.getPool to compute your ownership share, for example to enforce a treasury concentration limit per pool.
import { } from './viem.config'
const = '0x20c0000000000000000000000000000000000001'
const = '0x20c0000000000000000000000000000000000002'
const = await ..({
: ..,
,
,
})
const = await ..({ , })
const = ( * 10_000n) / .
.('Pool share:', `${() / 100}%`)
Pool share: 25%import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Look Up a Position by Pool ID
Pass poolId when your tooling already tracks pools by id, for example rows ingested from an indexer, instead of re-deriving token pairs.
import { } from './viem.config'
const = await ..({
: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
: '0xcfa2fc65dd0637cd912c7d689aa434a91d3456c723019921fe1f4a9018beab08',
})
.('LP balance:', )
LP balance: 500000000nimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
type ReturnType = bigintThe LP token balance for the account in the pool.
Parameters
address
- Type:
Address
Address to check balance for.
poolId
- Type:
Hex
Pool ID. Pass either poolId or both userToken and validatorToken.
userToken
- Type:
Address | bigint
User token. Pass with validatorToken when not passing poolId.
validatorToken
- Type:
Address | bigint
Validator token. Pass with userToken when not passing poolId.
blockNumber (optional)
- Type:
bigint
Block number to read the state from.
blockOverrides (optional)
- Type:
BlockOverrides
Block overrides to apply to the state.
blockTag (optional)
- Type:
BlockTag
Block tag to read the state from.
stateOverride (optional)
- Type:
StateOverride
State override to apply.