Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

apyUSD module

ERC-4626 vault wrapping apxUSD. Shares (apyUSD) are 18-decimal, underlying assets (apxUSD) are 6-decimal. Available as apyx.apyUSD after createApyxClient.

const rate   = await apyx.apyUSD.exchangeRate();   // 1 share -> assets, 1e18 scaled
const shares = await apyx.apyUSD.convertToShares(1_000_000n);

Address

apyx.apyUSD.address

Equals apyx.addresses.apyUSD.

Reads

Conversion views

MethodReturnsNotes
asset()AddressUnderlying asset (always apxUSD).
totalAssets()bigintVault TVL in apxUSD (6-decimal).
convertToShares(assets: bigint)bigintapxUSD → apyUSD at the current ratio.
convertToAssets(shares: bigint)bigintapyUSD → apxUSD.
exchangeRate()bigintConvenience: convertToAssets(1e18). 18-decimal scaled. The single most-read number on this contract — the value displayed by every UI / dashboard.

Preview views

Pre-flight quotes for the four ERC-4626 mutations. These match exactly what would happen on-chain at the current block, including any rounding.

MethodReturns
previewDeposit(assets)shares minted for assets
previewMint(shares)assets pulled to mint shares
previewWithdraw(assets)shares burned for assets
previewRedeem(shares)assets returned for shares

Capacity views

MethodReturns
maxDeposit(receiver)max apxUSD receiver can deposit
maxMint(receiver)max apyUSD shares receiver can mint
maxRedeem(owner)max apyUSD owner can redeem
maxWithdraw(owner)max apxUSD owner can withdraw

Holder views

MethodReturnsNotes
balanceOf(owner)bigintapyUSD share balance, 18-decimal.
decimals()numberAlways 18, but read it rather than hardcode.

Writes

All writes require account; without it they throw WalletClientRequiredError. Each write returns a TxHandle = { hash, wait }.

Approval first. deposit and mint pull apxUSD from the sender via transferFrom. You must approve the apyUSD address first — see the approve and deposit recipe.

deposit({ assets, receiver })

Pull assets apxUSD from the sender, mint shares to receiver.

const tx = await apyx.apyUSD.deposit({
  assets:   1_000_000n,                         // 1 apxUSD (6-dec)
  receiver: apyx.walletClient!.account!.address,
});
await tx.wait();

mint({ shares, receiver })

Mint exactly shares apyUSD to receiver, pulling whatever apxUSD is required (previewMint(shares)).

withdraw({ assets, receiver, owner })

Burn shares from owner to deliver assets apxUSD to receiver. Requires that owner === wallet.account or that the wallet has been approved by owner (approve is for the share token in this case).

redeem({ shares, receiver, owner })

Burn exactly shares apyUSD from owner, deliver previewRedeem(shares) apxUSD to receiver. The most common exit path — see the redeem recipe.

const tx = await apyx.apyUSD.redeem({
  shares:   apyx.walletClient!.account!.address,  // your share balance
  receiver: apyx.walletClient!.account!.address,
  owner:    apyx.walletClient!.account!.address,
});

Source

src/contracts/apyUSD.ts. The exposed shape is ReturnType<typeof apyUSD>; this page mirrors that and the source wins on conflict.