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.

public fun initialize<StrategyType: drop, StrategyCoin>(
    manager: &signer,
    vault_id: u64, 
    debt_ratio: u64, 
    witness: 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.

public fun withdraw_strategy_coin<StrategyType: drop, StrategyCoin>(
    vault_cap: &VaultCapability,
    amount: u64,
    _witness: StrategyType
): Coin<StrategyCoin>

Harvest

Opens the Vault for harvest. Must be followed by a closing call to close_vault_for_harvest.

public fun open_vault_for_harvest<StrategyType: drop, BaseCoin>(    
    manager: &signer,    
    vault_id: u64,    
    witness: StrategyType
) : (VaultCapability, VaultCapLock)

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.

public fun process_harvest<StrategyType: drop, BaseCoin, StrategyCoin>(    
    vault_cap: &mut VaultCapability,    
    strategy_balance: u64,    
    witness: StrategyType
) : (Coin<BaseCoin>, u64)

Deposit Coin<StrategyCoin> into the Vault referenced by vault_cap. Called between calls to open_vault_for_harvest and close_vault_for_harvest.

public fun deposit_strategy_coin<StrategyCoin>(    
    vault_cap: &VaultCapability,    
    strategy_coins: Coin<StrategyCoin>
)

Closes the Vault after harvest, depositing base_coins and strategy_coins back to the Vault.

public fun close_vault_for_harvest<StrategyType: drop, BaseCoin, StrategyCoin>(    
    manager_addr: address,    
    vault_cap: VaultCapability,    
    stop_handle: VaultCapLock,    
    base_coins: Coin<BaseCoin>,    
    strategy_coins: Coin<StrategyCoin>
)

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.

public fun process_harvest_trigger<StrategyType: drop, BaseCoin>(
    vault_cap: &VaultCapability
): bool

Closes vault without passing any coins.

public fun close_vault_for_harvest_trigger<StrategyType: drop>(    
    manager_addr: address,    
    vault_cap: VaultCapability,    
    stop_handle: VaultCapLock
)

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.

public fun open_vault_for_tend<StrategyType: drop, BaseCoin>(    
    manager: &signer,    
    vault_id: u64,    
    witness: StrategyType
): (VaultCapability, VaultCapLock, u64)

Close the Vault for a tend operation. Deposits strategy_coins into the vault.

public fun close_vault_for_tend<StrategyType: drop, StrategyCoin>(    
    manager_addr: address,    
    vault_cap: VaultCapability,    
    stop_handle: VaultCapLock,    
    strategy_coins: Coin<StrategyCoin>
)

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_neededof BaseCoi, and VaultCapability, and VaultCap lock for a subsequent call to close_vault_for_user_withdraw.

public fun open_vault_for_user_withdraw<StrategyType: drop, BaseCoin, StrategyCoin>(
    user: &signer,
    manager_addr: address,
    vault_id: u64,
    share_amount: u64,
    witness: StrategyType
) : (u64, VaultCapability, VaultCapLock)

Closes the Vault after liquidation of Coin<StrategyCoin> back into Coin<BaseCoin>.

public fun close_vault_for_user_withdraw<StrategyType: drop, BaseCoin>(    
    manager_addr: address,    
    vault_cap: VaultCapability,    
    stop_handle: VaultCapLock,    
    coins: Coin<BaseCoin>
)

Admin Functions

Updates strategy.debt_ratio on VaultStrategy<StrategyType> for Vault referenced by (manager, vault_id).

public entry fun update_debt_ratio<StrategyType: drop>(    
    manager: &signer,    
    vault_id: u64,    
    debt_ratio: u64
)

Updates strategy.max_report_delay on VaultStrategy<StrategyType> for Vault referenced by (manager, vault_id).

public entry fun update_max_report_delay<StrategyType: drop>(    
    manager: &signer,    
    vault_id: u64,    
    max_report_delay: u64
)

Updates strategy.max_report_delay on VaultStrategy<StrategyType> for Vault referenced by (manager, vault_id).

public entry fun update_credit_threshold<StrategyType: drop>(    
    manager: &signer,    
    vault_id: u64,    
    credit_threshold: u64
)

Set strategy.force_harvest_trigger_once to true on VaultStrategy<StrategyType> for Vault referenced by (manager, vault_id).

public entry fun set_force_harvest_trigger_once<StrategyType: drop>(    
    manager: &signer,    
    vault_id: u64
)

Sets strategy.debt_ratio to 0 on VaultStrategy<StrategyType> for Vault referenced by (manager, vault_id).

public entry fun revoke<StrategyType: drop>(
    manager: &signer, 
    vault_id: u64
)

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).

public entry fun migrate_from<OldStrategy: drop, NewStrategy: drop, NewStrategyCoin>(    
    manager: &signer,     
    vault_id: u64,     
    witness: NewStrategy
)

Last updated