Read an Aptos fungible balance that has a derived-balance hook

A fungible asset can define a custom view of store value. A ledger built by copying a numeric field from storage may disagree with the balance exposed by that asset.

Call the dispatch-aware reader

Pass the live store object to derived_balance. It invokes the registered derived-balance handler when present and otherwise returns the framework’s ordinary balance. Associate the result with the metadata object for this store.

let shown = dispatchable_fungible_asset::derived_balance(store);
let asset = fungible_asset::store_metadata(store);

Reconcile units before reporting a discrepancy

For a hypothetical asset whose hook values each accounting share at two units, 50 raw shares could yield 100 reported units. Inspect the actual hook implementation to learn its semantics. Record the ledger version, store and displayed value together. Changes to the hook’s input state can affect its output without a matching increase in the store’s raw shares.

Sources