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

apyUSDRateView module

On-chain APY view for the apyUSD vault. Read-only — no writes, nothing to sign. Available on Ethereum mainnet but not on Base, so the field is typed apyx.apyUSDRateView?: ApyUSDRateView | undefined.

if (apyx.apyUSDRateView) {
  const apy = await apyx.apyUSDRateView.apy();   // 18-decimal fraction
}

Why it’s optional

The address registry deliberately omits apyUSDRateView for chains where the contract isn’t deployed. createApyxClient reflects that:

type ApyxAddresses = {
  apxUSD: Address;
  apyUSD: Address;
  apyUSDRateView?: Address;     // optional
};

When the address is missing, the factory does not instantiate the module at all — apyx.apyUSDRateView is left undefined. Always guard with optional chaining (apyx.apyUSDRateView?.apy()) so the same code compiles and runs cleanly across Ethereum and Base.

const annualized = (await apyx.apyUSDRateView?.annualizedYield()) ?? 0n;

Methods

MethodReturnsNotes
apy()bigintCurrent APY as an 18-decimal fraction. 1.05e18 = 5% APY. Format with viem.formatUnits(apy, 18) for a decimal string.
annualizedYield()bigintAnnualised yield, same 18-decimal scaling. Equivalent to compounding apy() over a year. UIs often display this alongside (or instead of) raw APY.
precision()bigintThe contract’s internal precision base (e.g. 1e18). Useful when you want to do percentage math without trusting the format.
vault()AddressAddress of the apyUSD vault this rate view points at. Should equal apyx.addresses.apyUSD; if not, you’ve configured a mismatched override.

Address

apyx.apyUSDRateView?.address

Equals apyx.addresses.apyUSDRateView when the module exists.

Cross-checking against the vault

The rate view derives APY from apyUSD.exchangeRate() over a window. A useful sanity check when debugging:

const [apy, ann, precision, vault, exchangeRate] = await Promise.all([
  apyx.apyUSDRateView?.apy(),
  apyx.apyUSDRateView?.annualizedYield(),
  apyx.apyUSDRateView?.precision(),
  apyx.apyUSDRateView?.vault(),
  apyx.apyUSD.exchangeRate(),
]);

console.assert(vault === apyx.addresses.apyUSD, 'rate view points elsewhere');

If vault !== apyx.addresses.apyUSD, your override map is internally inconsistent — fix the addresses.apyUSDRateView override or remove it.

Source

src/contracts/apyUSDRateView.ts.