Skip to content
LogoLogo

Get Earn Position

earn.getPosition

Gets an account's asset and Earn share balances, allowances, and current share value.

Usage

import {  } from './viem.config'
 
const  = await ..({
  : '0x0000000000000000000000000000000000000001',
})
{
// assetAllowance: 0n,// assetBalance: 250_000_000n, // assetToken: '0x20c0...0001', // shareAllowance: 0n, // shareBalance: 99_500_000n, // shareToken: '0x20c0...0002', // value: 100_000_000n, // }

Read Another Account

Pass account to inspect a position other than the client account.

import {  } from './viem.config'
 
const  = await ..({
  : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
  : '0x0000000000000000000000000000000000000001',
})
{
// assetAllowance: 0n,// assetBalance: 250_000_000n, // assetToken: '0x20c0...0001', // shareAllowance: 0n, // shareBalance: 99_500_000n, // shareToken: '0x20c0...0002', // value: 100_000_000n, // }

Recipes

Fund a Payout from a Yield-Bearing Treasury

Check value covers a payout before pulling it from the vault with earn.withdrawExactSync, sending assets straight to the payee.

import {  } from './viem.config'
 
const  = '0x0000000000000000000000000000000000000001'
const  = 40_000_000n
 
const  = await ..({  })
if (. < )
  throw new ('Treasury position does not cover the payout.')
 
const  = await ..({
  : ,
  : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
  : 50,
  ,
})

Aggregate Positions Across Vaults

Read every vault in parallel to build a treasury dashboard that totals current redeemable value.

import {  } from './viem.config'
 
const  = [
  '0x0000000000000000000000000000000000000001',
  '0x0000000000000000000000000000000000000002',
] as 
 
const  = await .(
  .(() => ..({  })),
)
 
const  = .(
  (, ) =>  + .,
  0n,
)
250_000_000n

Return Value

type ReturnValue = {
  /** Assets the vault may spend from the account. */
  assetAllowance: bigint
  /** Asset balance held by the account. */
  assetBalance: bigint
  /** Token accepted by the vault. */
  assetToken: Address
  /** Earn shares the vault may spend from the account. */
  shareAllowance: bigint
  /** Earn share balance held by the account. */
  shareBalance: bigint
  /** Token representing Earn shares. */
  shareToken: Address
  /** Current asset value of the Earn share balance, including fees. */
  value: bigint
}

Parameters

account (optional)

  • Type: Account | Address
  • Default: client.account

Account whose position is returned.

vault

  • Type: Address

Vault address.

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.