Strategy Module

Overview

The satay::strategy module manages strategies that can be used within vaults. Strategies are responsible for deploying and managing assets with third-party DeFi protocols. Each strategy has a unique implementation, a base asset, and an associated shares asset.

Satay Strategies are tokenized. This allows users to interact and manage their assets directly with the strategies without having to go through vaults.

Structs

Strategy

This struct holds essential information about the strategy, such as the implementation address, the total assets managed by the strategy, the last harvest timestamp, and metadata for the base and shares assets.

struct Strategy has key {
    impl: address,
    total_asset: u64,
    last_harvest: u64,
    witness_type: TypeInfo,
    base_coin_type: Option<String>,
    base_metadata: Object<Metadata>,
    shares_metadata: Object<Metadata>,
}

StrategyController

This struct manages the strategy's administrative functions, including permissions for the manager and the extend ref.

struct StrategyController has key {
    manager: address,
    extend_ref: ExtendRef,
}

StrategyState

This struct holds information about the strategy’s debt, losses, and profits to the associated vault.

struct StrategyState has store, drop {
    debt_limit: u64,
    current_debt: u64,
    last_report: u64,
    total_loss: u64,
    total_profit: u64
}

Functions

Functions

  • create<T>(manager: &signer, impl: address, base_metadata: Object<Metadata>, _witness: T): Object<Strategy>: Creates a new strategy with the specified base asset metadata and implementation, initializing it with a witness type to ensure only authorized entities can interact with it.

  • issue_shares<T>(strategy: Object<Strategy>, asset: &FungibleAsset, _witness: &T): FungibleAsset: Issues shares for the strategy in exchange for deposited assets. The witness must match the strategy's witness type to authorize this action.

  • burn_shares<T>(strategy: Object<Strategy>, asset: FungibleAsset, _witness: &T): u64: Burns strategy shares and returns an equivalent amount of base assets. The witness must match the strategy's witness type.

  • wrap_asset<T, C>(strategy: Object<Strategy>, coin: Coin<C>, _witness: &T): FungibleAsset: Wraps a base coin into a fungible asset within the strategy, converting the underlying asset into a standard format for strategy management.

  • unwrap_asset<T, C>(strategy: Object<Strategy>, asset: FungibleAsset, _witness: &T): Coin<C>: Unwraps a fungible asset into its original base coin form. The witness must match the strategy's witness type.

  • debt_limit(state: &StrategyState): u64: Returns the debt limit of the strategy.

  • current_debt(state: &StrategyState): u64: Returns the current amount of debt for the strategy.

  • last_report(state: &StrategyState): u64: Returns the timestamp of the last report for the strategy.

  • total_loss(state: &StrategyState): u64: Returns the total losses incurred by the strategy.

  • total_profit(state: &StrategyState): u64: Returns the total profits generated by the strategy.

  • is_manager(strategy: Object<Strategy>, account: address): bool: Checks whether the provided account is the manager of the strategy.

  • is_valid_witness<T>(strategy: Object<Strategy>): bool: Verifies whether the provided witness type matches the strategy's witness type, ensuring that only authorized modules can interact with the strategy.

  • strategy_address(strategy: Object<Strategy>): address: Returns the address of the strategy object.

  • total_asset(strategy: Object<Strategy>): u64: Returns the total amount of assets held by the strategy.

  • total_shares(strategy: Object<Strategy>): u64: Returns the total number of shares issued by the strategy.

  • base_metadata(strategy: Object<Strategy>): Object<Metadata>: Returns the metadata for the strategy’s base asset.

  • shares_metadata(strategy: Object<Strategy>): Object<Metadata>: Returns the metadata for the strategy’s shares asset.

  • base_store(strategy: Object<Strategy>): Object<FungibleStore>: Returns the fungible store for the strategy’s base asset.

  • shares_store(strategy: Object<Strategy>): Object<FungibleStore>: Returns the fungible store for the strategy’s shares asset.

  • amount_to_shares(strategy: Object<Strategy>, amount: u64): u64: Converts a specified amount of base assets into the equivalent number of shares for the strategy.

  • shares_to_amount(strategy: Object<Strategy>, shares: u64): u64: Converts a specified number of shares into the equivalent amount of base assets for the strategy.

  • witness_type(strategy: Object<Strategy>): TypeInfo: Returns the type of witness required for interacting with the strategy.

  • impl(strategy: Object<Strategy>): address: Returns the address of the strategy’s implementation.

Access Control

Most of the functions in the satay::strategy module are restricted to friend modules (e.g., satay::vault) or require a valid witness type. This ensures that strategies can only be interacted with in a secure and authorized way.

Last updated