FxVault that holds the chain’s dollar. Two tables describe a vault: vaultEvent records what people did, and vaultSnapshot records the vault’s accounting right after each of those events.
vaultEvent
Indexes:
(vault, timestamp), user.
vaultSnapshot
One row per vault event, keyed by the sametxHash-logIndex, holding vault.status() plus the two supplies at that block.
Index:
(vault, timestamp).
vault.status() reverts with StalePrice when the oracle’s last rate is older than the stale limit (five days). The indexer then recomputes liability, equity and crBps from vault.assets() and the last known rate (the event’s rate, else the indexed currency.lastRate) and writes the row with fresh: false, so the series never has a hole.Examples
Snapshots (latest first) and recent events for one vault:curl:
Reading a snapshot
assets,liabilityandequityare the chain’s dollar in 6 decimals:equity / 1e6is the dollar buffer backers have put in plus accumulated fees, minus any adverse FX move.crBps / 100is the collateral ratio in percent. Treat2^256 - 1(115792089237316195423570985008687907853269984665640564039457584007913129639935) as “no liability” rather than a number.- Vaults mint at a minimum collateral ratio of 100%, so a fresh vault with no backers sits exactly at 100% after its first mint. Below 100% redeems are paid pro rata (
haircut: trueon the event). - A backer’s share of equity is
shares / shareSupply; multiply byequityfor the current dollar value of a position. - Fee income to backers is the sum of
feeover mint and redeem events minus the protocol’s 20% share, which is tracked inside the contract rather than as separate rows. The FxVault reference has the exact accounting.