Skip to content
NAVIDocs
Open app
Skip to Content

Shares, snapshots and fees

Calculate share value, synchronize markets in the same transaction, and check fees, governance and pause state.

2. Share accounting

shares_minted = floor( amount × (total_shares + VIRTUAL_SHARES) / (total_assets + VIRTUAL_SHARES) )

shares_burned = ceil( amount × (total_shares + VIRTUAL_SHARES) / (total_assets + VIRTUAL_SHARES) )
                + penalty_shares

VIRTUAL_SHARES = 1_000_000 is applied to both numerator and denominator as an inflation-attack offset: displacing the share price by a factor of N requires donating N × 1e6 native units.

Consequences relevant to integration:

  • On an empty vault the first deposit mints shares one-to-one with the deposited amount.
  • A deposit that would mint zero shares aborts with E_DEPOSIT_TOO_SMALL (10012). This is reachable for dust amounts once share price has appreciated significantly. Deposits should be priced client-side (§6.1) rather than relying on the abort.
  • Minting floors and burning ceils, both in the vault's favour. A deposit followed immediately by a withdrawal of the same amount returns up to one share less than was minted; the round trip is not value-neutral and should not be presented as such.
  • A holder of the entire share supply cannot redeem the entire asset balance in a single withdrawal: the formula requires total_shares + VIRTUAL_SHARES shares to withdraw total_assets. Full exits must use from_default = true (§5.2), which clamps the requested amount to the holder's true maximum, and must tolerate a dust remainder.

Both operations are priced from vault state as it stands before the operation: accrue_interest runs first, shares are computed against the resulting figures, and only then are balances moved.

Fee shares that have accrued but not yet been claimed are already included in total_shares. Share price therefore already reflects pending fee dilution, and no adjustment is required when converting shares to assets.

3. Snapshot accounting and same-PTB preconditions

MarketInfo.current_balance is a cached value. It is written in exactly one place: sync_market_balance, which reads the vault's NAVI position as storage.get_user_balance × supply_index, converts to native decimals, and subtracts recorded loss. Between calls the value is stale and understates the position by all interest accrued since the last refresh.

Likewise, VaultRewardRule.vault_reward_index for a market rule is advanced in exactly one place: collect_reward.

Operations whose result depends on those figures assert that they were refreshed at the current clock.timestamp_ms(). Because every call within a programmable transaction block observes the same clock reading, this assertion is equivalent to "refreshed in this transaction".

3.1 Precondition matrix

EntrypointAll markets synchronizedAll active market rules harvestedTarget market synchronized
sync_market_balance———
collect_reward———
depositrequiredrequired—
withdrawrequiredrequired—
claim_reward———
allocate——required
deallocate——required
claim_management_fee—required—
claim_performance_fee—required—
exec_management_fee, set_management_fee_by_adminrequiredrequired—
exec_performance_fee, set_performance_fee_by_adminrequiredrequired—
all other entrypoints———

Definitions:

  • All markets means every entry in Vault.markets, in both Active and Disabled status. Omitting a Disabled market aborts with E_MARKET_NOT_READ (10006). Disabled markets remain part of assets under management and remain withdrawable, and are therefore not exempt.
  • All active market rules means every entry of Vault.reward_rules where is_active == true && is_vault_native == false. Vault-native rules are settled internally by update_vault_native_indices and are exempt. A missing harvest aborts with E_REWARDS_NOT_COLLECTED (10007).
  • collect_reward returns without effect — including without updating last_harvest_at — when the rule is vault-native or inactive. Calling it for every rule index is therefore safe and costs only gas.

3.2 Conditions that invalidate a synchronization

  • add_market initializes the new market with last_sync_at = 0. Any deposit or withdrawal constructed against a market list obtained before the addition will abort.
  • set_loss resets that market's last_sync_at to 0, invalidating a synchronization performed earlier in the same transaction.

Market and reward-rule lists must be read from vault state at transaction-construction time and must not be cached across transactions.

3.3 External preconditions imposed by the lending protocol

Deposits and withdrawals pass through NAVI's lending logic, which applies its own constraints on top of the vault's. These abort with lending and oracle package codes, which occupy a range distinct from the vault's 10001–10042 and are summarized in §10.7.

Reserve supply ceiling. logic::execute_deposit calls validation::validate_deposit, which asserts the reserve's total supply plus the deposit does not exceed NAVI's supply_cap_ceiling for that asset. A deposit can therefore abort with 1604 (exceeded_maximum_deposit_cap) while both the vault cap and the market cap still have headroom, because the constraint belongs to the underlying reserve and is shared with every other participant in that market. Deposit headroom presented to a user is the minimum of three bounds, not two.

The contention is closer than it appears: a single NAVI market may be registered by more than one vault, so two vaults with the same underlying asset can draw on one reserve. Reserve-level limits are therefore affected by activity on vaults other than the one being quoted, and cannot be derived from any single vault's state.

Reserve liquidity. validation::validate_withdraw asserts total_supply ≥ total_borrow + amount for the reserve. A withdrawal can abort with 1506 (insufficient_balance) even when the holder's share balance and the vault's recorded market position are both sufficient, because the underlying reserve is too heavily utilized to release the assets. This is a property of the lending market, not of the vault, and it is transient. Clients should distinguish it from the vault's own E_INSUFFICIENT_BALANCE (10002) and present it as a temporary liquidity condition. Routing the withdrawal to a different market, or drawing on the vault's idle balance, may succeed where one market cannot.

Oracle price freshness. withdraw and deallocate are the only entrypoints that accept a PriceOracle, because they are the only ones that reach NAVI's collateral valuation. incentive_v3::withdraw_with_account_cap_v2 resolves to logic::execute_withdraw, which asserts logic::is_health. That path computes collateral value before the zero-debt short circuit, so it evaluates oracle::get_token_price and asserts price validity even though a vault holds no debt.

A price is valid only while

clock.timestamp_ms() − price.timestamp ≤ PriceOracle.update_interval

update_interval is configurable per oracle and defaults to 30 000 ms. When the price for the vault's asset is older than that window, withdraw and deallocate abort with 1502 (lending_core::error::invalid_price) — an abort raised by the lending package, not by navi_vault, and therefore absent from the error table in §10.7.

Deposits and allocations are unaffected: logic::execute_deposit takes no oracle and performs no price read.

Because the vault receives &PriceOracle by immutable reference, it cannot refresh the price. The withdrawal block must therefore begin with a price update into the oracle package, before the market synchronizations. The 30-second default window is short enough that relying on another party to have refreshed the price is not a viable strategy. The verified block shapes in §5.6 show the call in position.

Three properties of that update:

  • It is per asset. The oracle holds one price per asset, refreshed by an entrypoint that takes that asset's feed identifier and price-source objects. Refresh the asset being withdrawn; a refresh of an unrelated asset does not satisfy the assertion.
  • The entrypoint is versioned, and the version advances. Successive revisions have differed in the price-source object types they accept, as upstream price providers were themselves upgraded. Resolve the entrypoint from the oracle package the deployment currently links against rather than hardcoding a name; an integration pinned to a superseded revision stops working when the oracle is upgraded.
  • The update takes the PriceOracle by mutable reference while withdraw takes it by immutable reference. Passing the same shared object both ways within one block is correct and required.

3.4 External precondition: lending package version coupling

The vault package is statically linked against one published version of lending_core. That version is compiled into it and cannot be changed without upgrading the vault package. lending_core gates its own entrypoints on the version recorded in the shared Storage object:

lending_core::version::pre_check_version(Storage.version)
    → aborts 1400 (lending_core::error::incorrect_version) on mismatch

When NAVI upgrades lending_core and increments Storage.version, every vault call that reaches the lending package begins aborting with 1400. sync_market_balance is such a call — it invokes lending::update_state_of_user — and because deposit and withdraw require synchronization in the same block, all depositor operations abort until the vault package itself is upgraded to link against the new lending_core.

This condition has three properties integrators must account for:

  • It is not recoverable client-side. No change to block construction, gas, arguments or retry policy works around it. Only a vault package upgrade resolves it.
  • It is invisible to the vault's own state. is_paused is false, version is unchanged, and every view function that does not touch lending_core continues to return values — from the last successful synchronization, which may be arbitrarily old (§6.1).
  • Abort 1400 arises in a module named version, as does the vault's own E_INCORRECT_VERSION (10036). They are distinct conditions with distinct remedies. Discriminate on the abort code and the originating package, not on the module name.

Clients should surface abort 1400 as a protocol-level outage rather than a user error, and should not present a synced balance or accept a deposit while it persists.

6. State queries

All view functions are public fun and may be evaluated through devInspectTransactionBlock. None mutate state.

6.1 Snapshot staleness

get_total_assets, get_user_balance, convert_to_assets, convert_to_shares and get_market_info all read MarketInfo.current_balance, whose freshness is bounded by the most recent sync_market_balance executed on chain by any party.

The bound is not a matter of seconds. Because synchronization happens only as a side effect of someone constructing a deposit, withdrawal or allocation block, a vault with no activity does not get synchronized at all. Observed mainnet vaults have carried snapshots more than a month old, and the condition in §3.4 halts synchronization entirely for as long as it persists. Any figure read without synchronizing must be treated as being of unknown age; get_market_config position 4 returns last_sync_at and is the only way to know it.

Pricing must therefore be performed against a synchronized snapshot, by evaluating a read-only block that synchronizes before reading:

for each market m: sync_market_balance<CoinType>(vault, m.storage, m.pool, clock)
get_total_assets<CoinType>(vault)
get_user_balance<CoinType>(vault, receipt)
convert_to_shares<CoinType>(vault, amount)

devInspectTransactionBlock simulates execution, so the mutable references and the resulting state changes are discarded; the reads observe synchronized values and nothing is written on chain. No signature, key or funds are required — only a sender address, which need not be funded or controlled.

Transport. devInspectTransactionBlock is a JSON-RPC method, and JSON-RPC has been deprecated on Sui's public fullnodes: https://fullnode.mainnet.sui.io answers it with -32601 Method not found. Simulation therefore requires either an RPC provider that still serves JSON-RPC, or the gRPC transport, whose equivalent is simulateTransaction (SuiGrpcClient in @mysten/sui/grpc). The block construction is identical either way; only the client and the result shape differ. New integrations should target gRPC.

Deriving max_shares. The reliable method is to simulate the withdrawal itself and read the shares_burned return value, which accounts for the non-default-market penalty, ceiling rounding, idle-first routing and same-transaction fee accrual — none of which convert_to_shares models. A tolerance should be added on top. The direction of drift between simulation and execution is favourable: interest accrual raises share price, so an identical amount costs marginally fewer shares at execution time. The tolerance therefore covers rounding and any fee accrual in the interval, for which a few tens of basis points is sufficient.

6.2 Reward query staleness

get_user_claimable_reward_amount lags in two independent respects:

  1. vault_reward_index advances only on collect_reward for market rules, or on an operation that triggers update_vault_native_indices for vault-native rules. Unharvested protocol rewards are not represented.
  2. A holder's reward_total advances only when that holder interacts with the vault, through deposit, withdraw or claim_reward.

A holder who has not interacted since the last index growth is therefore understated. No view function reports the true entitlement, because resolving the second lag requires mutating that holder's state. An accurate figure is obtained by simulating the settlement path — collect_reward followed by claim_reward — and reading the amount from the resulting ClaimRewardEvent.

6.3 Query index

QuantityCallRequires prior synchronization
Holder's sharesget_user_shares(vault, receipt)no
Holder's value in CoinTypeget_user_balance(vault, receipt)yes
Assets under managementget_total_assets(vault)yes
Share priceconvert_to_assets(vault, unit)yes
Total sharesget_total_shares(vault)no
Idle balanceget_idle_balance(vault)no
Position in one marketget_market_info(vault, pool)yes
Vault deposit capget_vault_cap(vault)no
Deposit routing targetget_vault_default_market(vault)no
Fee ratesget_management_fee, get_performance_feeno
Pending fee dilutionget_pending_management_fee_shares, get_pending_performance_fee_sharesno
Performance-fee baselineget_baseline_total_assets(vault)no
Pause stateis_paused(vault)no
Contract versionversion(vault)no
Claimable rewardsget_user_claimable_reward_amount<CoinType, RewardCoinType>see §6.2
Undistributed reward balanceget_collected_reward_balance<CoinType, RewardCoinType>no

7. Fees

management_fee  = total_assets × rate × elapsed_seconds / (1e18 × 31_536_000)
performance_fee = (total_assets − baseline_total_assets) × rate / 1e18

The management fee is bounded at 20% annualized (MAX_MANAGEMENT_FEE_APY_WAD = 0.2e18); the performance fee at 40% of profit (MAX_PERFORMANCE_FEE_WAD = 0.4e18). The performance fee is charged only on growth above Vault.total_assets, the gross assets under management recorded at the previous accrual, which functions as a high-water mark and is readable via get_baseline_total_assets.

Both fees are taken as newly minted shares credited to pending_management_fee_shares and pending_performance_fee_shares. No assets leave the vault; total_shares increases and all holders are diluted proportionally. Any yield calculation derived from the growth of total_assets alone overstates the return to depositors.

Fees accrue when accrue_interest executes, which occurs within deposit, withdraw and fee-rate changes. An inactive vault accrues no fees until its next interaction, at which point the full elapsed interval is charged.

8. Governance

The following parameters are subject to a timelock when initiated by a curator: management fee, performance fee, default market, market addition, and market status. The sequence is propose_* → wait TIMELOCK_DURATION (24 hours) → exec_*, with a TIMELOCK_GRACE_PERIOD of 7 days after which the proposal expires and must be re-proposed. One live proposal is permitted per (type, subject) pair.

Two categories bypass the timelock:

  • The admin path. set_management_fee_by_admin, set_performance_fee_by_admin, set_default_market_by_admin, set_market_status_by_admin, add_market_by_admin and set_market_cap_and_penalty_by_admin apply immediately.
  • Curator-initiated changes to the vault cap (set_vault_cap_by_curator) and to a market's cap and penalty (set_market_cap_and_penalty_by_curator) apply immediately.

Integration consequences:

  • Fee rates, caps, penalties, the default market and the market list must be read at transaction-construction time and must not be cached.
  • Services presenting risk information should monitor ProposalCreatedEvent, whose executable_at field carries the 24-hour notice the timelock exists to provide, and the Set* / AddMarket events in §10.8 for changes already applied.

9. Pause and versioning

Pause. While paused == true, every depositor, allocator, block-support and fee-claim entrypoint aborts with E_PAUSED (10011), as do the two timelocked fee executions. Configuration and governance entrypoints are unaffected.

Two consequences are easy to miss. sync_market_balance is included, so a paused vault cannot be priced from a fresh snapshot at all. And the pause applies to every party including the admin — only the AdminCap holder can lift it, via set_paused(vault, cap, false); a PauseCap holder can engage it but not lift it.

Clients should evaluate is_paused before constructing a transaction and represent the state explicitly.

Versioning. Every mutating entrypoint calls version_verification, which requires Vault.version to equal the current package's VAULT_VERSION. Following a package upgrade, the admin must call version_migrate for each vault; until then, mutating calls abort with E_INCORRECT_VERSION (10036).

View functions do not perform this check. While a migration is pending, balances and configuration remain readable and sync_market_balance — being a mutating call — does not, so reads are available but cannot be freshly synchronized. Clients should evaluate version(vault) against the package's current version to distinguish this condition from a generic failure and to suppress transaction construction until migration completes.

The package identifier must be supplied as configuration rather than compiled into a client, so that clients can be repointed at an upgraded package.

On this page