Base Strategy Module
Overview
The satay::base_strategy
module acts as the entry point for strategies to interact with vaults. The base_strategy
module is a friend
module of satay::vault
, and thus can access its mutating functions. base_strategy
is stateless, acting as a proxy for strategies to operate on vaults.
Initialize
initialize
calls the approve_strategy
function on the vault
referenced by the (manager, vault_id)
with debt_ratio
and type_of(StrategyCoin)
and registers CoinStore<StrategyCoin>
on vault. witness
is required to ensure calling module defines StrategyType
.
Withdraw Strategy Coin
Withdraw amount
of StrategyCoin
from the Vault
accessed by vault_cap
. Assert that type_of<StrategyCoin> == strategy.strategy_coin_type
of VaultStrategy<StrategyType>
. Use StrategyType
witness to authenticate the caller.
Harvest
Opens the Vault
for harvest. Must be followed by a closing call to close_vault_for_harvest
.
Calculates and reports the profit
, loss
, and required debt_payment
forStrategyType
given its debt_ratio
and strategy_balance
. Calls assess_fees
on any profits generated by the strategy. Returns Coin<BaseCoin>
to deploy to StrategyType
if it has not utilized its entire credit line and amount_needed
if the strategy has more debt than is allowed.
Deposit Coin<StrategyCoin>
into the Vault
referenced by vault_cap
. Called between calls to open_vault_for_harvest
and close_vault_for_harvest
.
Closes the Vault
after harvest
, depositing base_coins
and strategy_coins
back to the Vault
.
Harvest Trigger
Called by vault manager to check if harvest should be called. Returns true
if strategy.force_harvest_trigger
, (timestamp::now_seconds() - strategy.last_report) >= strategy.max_report_delay
, or credit_available >= credit_threshold
. false
otherwise.
Closes vault without passing any coins.
Tend
Tend operations claim rewards from a strategy and reinvest them to accrue more Coin<StrategyCoin
> in the vault.
Open the Vault
for a tend operation. Returns VaultCapability
, VaultCapLock
, and the debt_out standing
for StrategyType
.
Close the Vault
for a tend operation. Deposits strategy_coins
into the vault.
User Withdraw
Opens vault for user
to reclaim BaseCoin
from StrategyType
to the Vault
. Asserts that user
holds share_amount
of VaultCoin<BaseCoin>
and that the Vault
does not hold enough BaseCoin
to satisfy the withdrawl amount. Returns amount_needed
of BaseCoi
, and VaultCapability
, and VaultCap
lock for a subsequent call to close_vault_for_user_withdraw
.
Closes the Vault
after liquidation of Coin<StrategyCoin>
back into Coin<BaseCoin>
.
Admin Functions
Updates strategy.debt_ratio
on VaultStrategy<StrategyType>
for Vault
referenced by (manager, vault_id)
.
Updates strategy.max_report_delay
on VaultStrategy<StrategyType>
for Vault
referenced by (manager, vault_id)
.
Updates strategy.max_report_delay
on VaultStrategy<StrategyType>
for Vault
referenced by (manager, vault_id)
.
Set strategy.force_harvest_trigger_once
to true
on VaultStrategy<StrategyType>
for Vault
referenced by (manager, vault_id)
.
Sets strategy.debt_ratio
to 0
on VaultStrategy<StrategyType>
for Vault
referenced by (manager, vault_id)
.
Sets strategy.debt_ratio
to 0
on VaultStrategy<OldStrategy>
and calls initialize<NewStrategy, NewStrategyCoin>
with old_strategy_debt_ratio
for Vault
referenced by (manager, vault_id)
.
Last updated