Vault Module (Legacy)
Overview
The satay::vault module holds the code for vault logic.
Vaults are represented by the Vault struct, which holds the base_coin_type, base_coin_decimals, management_fee, performance_fee, debt_ratio, and total_debt of the vault.
The debt_ratio of a vault determines the total percentage of vault funds that can be deployed to strategies. In most cases, debt_ratio will be 10000, meaning all of the funds are available for strategies. The management_fee and performance_fee values are used to assess fees for the vault.
struct Vault has key {
base_coin_type: TypeInfo,
base_coin_decimals: u8,
management_fee: u64,
performance_fee: u64,
debt_ratio: u64,
total_debt: u64,
}The VaultCapability struct holds a SignerCapability for a vault's resource account, unique vault_id, and the resource account's vault_addr.
struct VaultCapability has store, drop {
storage_cap: SignerCapability,
vault_id: u64,
vault_addr: address
}The VaultCoin struct represents a share of a vault's holdings and is burned to claim a share of the pooled capital. There is a unique VaultCoin for each BaseCoin.
The MintCapability, BurnCapability, and FreezeCapability are stored in of a VaultCoin are stored in the vault's resource account.
The VaultStrategy resource stores information about a Vault's approved strategies, including its strategy_coin_type, debt_ratio, total_debt, information about its performance to date, and information used in harvest_trigger.
Access Control
All mutating functions for the vault are restricted to friend modules satay::satay and satay::base_strategy.
Satay Functions
Create Vault
new creates a new vault for BaseCoin managed by vault_owner with a unique vault_id. The function also initializes the management and performance fee amounts. This function is called by the satay::satay module. management_fee must not exceed MAX_MANAGEMENT_FEE_BPS and performance_fee must not exceed MAX_PERFORMANCE_FEE_BPS.
User Functions
deposit_as_user deposits base_coin of Coin<BaseCoin>into the vault, minting a calculated amount of Coin<VaultCoin<BaseCoin>> to user. This function is called by the satay::satay module.
withdraw_as_user burns amount of Coin<VaultCoin<BaseCoin>>, returning a calculated amount of Coin<BaseCoin> to user. This function is called by the satay::satay module.
Admin Functions
approve_strategy creates a VaultStrategy<StrategyType> resource and moves it to the vault resource account referenced by vault_cap. vault.debt_ratio + debt_ratio must not exceed MAX_DEBT_RATIO_BPS.
update_fee updates the fee vault.management_fee and vault.performance_fee for the vault referenced by vault_cap. management_fee must not exceed MAX_MANAGEMENT_FEE_BPS and performance_fee must not exceed MAX_PERFORMANCE_FEE_BPS.
update_strategy_debt_ratio updates the debt_ratio of StrategyType. vault.debt_ratio - old_debt_ratio + debt_ratio must not exceed MAX_DEBT_RATIO_BPS.
update_strategy_max_report_delay updates the strategy.max_report_delay value for VaultStrategy<StrategyType>.
update_strategy_credit_threshold updates the strategy.credit_threshold value for VaultStrategy<StrategyType>.
set_strategy_force_harvest_trigger_once updates the strategy.force_harvest_trigger value for VaultStrategy<StrategyType> to true.
Base Strategy Functions
Add Coin
add_coin<CoinType> creates a CoinStore<CoinType> resource for the vault, allowing it to accept Coin<CoinType> deposits.
Deposit/Withdraw
deposit sends coin to the vault without minting VaultCoin<CoinType>
withdraw extracts amount of Coin<CoinType> from the vault without burning Coin<VaultCoin<CoinType>>.
Fees
assess_fees charges the management and performance fees on a reported gain from StrategyType.
Reporting
update_total_debt incrementstotal_debt of VaultStrategy<StrategyType> and Vault by credit - debt_payment.
report_timestamp updates the last_report value of VaultStrategy<StrategyType> to the current timestamp.
report_gain increments total_gain value of VaultStrategy<StrategyType>.
report_loss decrements total_debt, debt_ratio and increments total_loss on VaultStrategy<StrategyType>. Decrements total_debt and debt_ratio on Vault.
Getter Functions
Gets the total assets of the vault, including liquid and deployed CoinType.
Gets the amount of remaining BaseCoin credit StrategyType can withdraw.
Determines if StrategyType is past its debt limit. If StrategyType is above its limit, return the amount over the limit.
Calculates the amount of BaseCoin to return given an amount of VaultCoin<BaseCoin> to burn.
Gets the vault address of a vault, given its VaultCapability resource.
Gets the strategy.strategy_coin_type from VaultStrategy<StrategyType> of Vault accessed by vault_cap.
Last updated