defindex-strategy contract is a reference vault adapter in contracts/defindex-strategy/. It maps each DeFindex vault to one controller supply account for a single underlying asset. Share accounting lives in the DeFindex vault contract; the strategy holds only a vault-to-account mapping.
Deployment model
- One WASM per underlying asset. Deploy a separate strategy instance per listed market.
- One controller
account_idper vault. Vaults never share a lending account. - Strategy is the caller on all controller mutations (
supply,withdraw).
Trait API
| Entrypoint | Auth | Returns | Behavior |
|---|---|---|---|
asset() | — | Address | Configured underlying asset |
deposit(amount, from) | from.require_auth() | i128 | Pull tokens, supply to controller, return post-deposit balance |
balance(from) | — | i128 | collateral_amount_for_token(account_id, asset) |
withdraw(amount, from, to) | from.require_auth() | i128 | Withdraw to to; amount = 0 closes the full position |
harvest(from, data) | — | — | Emits HarvestEvent with 12-decimal price_per_share |
lending_account_id(vault) | — | u64 | Live controller account id (reconciles stale mapping) |
has_lending_account(vault) | — | bool | Whether the vault has a live account |
Deposit flow
prepare_vault_account_for_supply may call controller.account_exists before authorize_as_current_contract. If auth were emitted first, re-deposit after a full withdraw would fail with Auth InvalidAction.
Withdraw flow
to directly from the pool. No pre-authorization is required on the strategy side.
Harvest and price per share
harvest emits a 12-decimal price_per_share derived from the market supply index:
supply_index_ray), not per-vault. harvest makes no on-chain state change; DeFindex vaults use the event for share accounting.
Controller integration
| Concern | Implementation |
|---|---|
| Balance reads | collateral_amount_for_token — oracle-free, accrues to now |
| Supply auth | Pre-authorize transfer(strategy → pool) |
| Withdraw auth | None; pool pays recipient directly |
| Pool address | Resolved at init via controller.get_pool_address() |
| Stale mapping | Cleared on supply after full withdraw; read paths return 0 until re-deposit |
Auth recipe
Supply requires the strategy to authorize its own token transfer to the pool before callingcontroller.supply:
to on the controller’s behalf.
Strategy errors
| Code | Error |
|---|---|
| 401 | NotInitialized |
| 460 | AmountNotPositive |
| 461 | InsufficientBalance |
| 462 | ArithmeticError |
Fork checklist
When adapting the reference strategy:- Enforce vault-side inflation guards before trusting
depositreturn values. - Extend TTL for strategy instance and vault-mapping keys.
- Run the integration test matrix in
contracts/defindex-strategy/tests/. - Keep one WASM per asset; do not share strategy instances across underlyings.
Next
Vault integrations
Generic vault integration model, lifecycle rules, and auth patterns.
Supply and borrow
Underlying controller supply and withdraw semantics.
Interest and revenue
How supply indexes accrue and how
price_per_share tracks yield.Controller ABI
supply, withdraw, and collateral_amount_for_token signatures.
