Skip to content
LogoLogo

Get AMM Pool

amm.getPool

Gets the reserves for a liquidity pool.

Usage

import {  } from './viem.config'
 
const  = await ..({
  : '0x20c0000000000000000000000000000000000001',
  : '0x20c0000000000000000000000000000000000002',
})
 
.('Pool:', )
Pool: { reserveUserToken: 1000000000n, reserveValidatorToken: 1000000000n, totalSupply: 1000000000n }

Recipes

Check Pool Depth Before Adopting a Fee Token

Check the validator token reserve before saving a default with fee.setUserToken: fee payments in a token only settle while its pool holds validator tokens.

import {  } from './viem.config'
 
const  = '0x20c0000000000000000000000000000000000001'
 
const  = await ..({
  : ,
  : '0x20c0000000000000000000000000000000000002',
})
 
if (. >= 10_000_000000n)
  await ..({ :  })

Detect a Pool Worth Rebalancing

Compare the reserves to spot user token buildup, then act with amm.rebalanceSwap when the surplus is worth the swap.

import {  } from './viem.config'
 
const  = await ..({
  : '0x20c0000000000000000000000000000000000001',
  : '0x20c0000000000000000000000000000000000002',
})
 
const  = . - .
 
if ( > 1_000_000000n)
  .('Rebalance opportunity:', )
Rebalance opportunity: 2500000000n

Return Value

type ReturnType = {
  /** Reserve of user token. */
  reserveUserToken: bigint
  /** Reserve of validator token. */
  reserveValidatorToken: bigint
  /** Total supply of LP tokens. */
  totalSupply: bigint
}

The pool reserves and LP token total supply.

Parameters

userToken

  • Type: Address | bigint

Address or ID of the user token.

validatorToken

  • Type: Address | bigint

Address or ID of the validator token.

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.