Base Strategy Module
Overview
The satay::base_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.
BaseStrategyController
This struct stores the extend ref for the BaseStrategy.
AuthRef
A reference used to authorize the strategy for certain action or operations.
BaseStrategyState
This struct holds information about the strategy’s debt, losses, and profits to the associated vault.
WithdrawalRequest
Represents a request to withdraw assets from a strategy.
HarvestRequest
Represents a request to harvest a strategy.
Error Codes
ENOT_AUTHORIZED
: Unauthorized signer or capability.EINVALID_AMOUNT
: Invalid amount specified.EINSUFFICIENT_DEBT
: Insufficient debt to perform action.ETOO_MUCH_LOSS
: Too much loss.EASSET_METADATA_MISMATCH
: Asset metadata mismatch.EINSUFFICIENT_IDLE_BALANCE
: Insufficient idle balance.EINVARIANT_VIOLATION
: Invariant violation.EINVALID_REMAINING_AMOUNT
: Invalid remaining amount.EINVALID_FEE
: Invalid fee.EINVALID_LOCK_DURATION
: Invalid lock duration.ECANNOT_SWEEP_BASE_ASSET
: Cannot sweep base asset.
Functions
Strategy management
create<T>(account: &signer, base_metadata: Object<Metadata>, _witness: T): AuthRef
: 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.deposit( asset: FungibleAsset, auth_ref: &AuthRef ): FungibleAsset
: Deposits a FungibleAsset into a strategy and mint shares in return.mint_debt_shares_fa(asset: &FungibleAsset, auth_ref: &AuthRef): FungibleAsset
: Mints strategy shares based on the amount of the provided fungible asset without transferring the asset.mint_debt_shares_coin<CoinType>(coin: &Coin<CoinType>, auth_ref: &AuthRef): FungibleAsset
: Mints strategy shares based on the amount of the provided coin without transferring the coin.set_lock_duration(account: &signer, strategy: Object<BaseStrategy>, duration: u64)
: Sets the duration for which profits are locked in the strategy. Only callable by governance.set_performance_fee(account: &signer, strategy: Object<BaseStrategy>, fee: Option<u64>)
: Sets the performance fee for the strategy. Only callable by governance.
Withdrawal Management
request_withdrawal(shares: FungibleAsset, auth_ref: &AuthRef): WithdrawalRequest
: Initiates a withdrawal request by providing strategy shares to be burned later on.withdraw(request: &mut WithdrawalRequest)
: Processes a withdrawal request by withdrawing idle funds from the strategy.apply_fa_withdrawal(request: &mut WithdrawalRequest, asset: FungibleAsset)
: Applies a fungible asset withdrawal to an existing withdrawal request.apply_coin_withdrawal<C>(request: &mut WithdrawalRequest, coin: Coin<C>)
: Applies a coin withdrawal to an existing withdrawal request.complete_withdrawal(request: WithdrawalRequest, max_loss: Option<u64>): FungibleAsset
: Completes a withdrawal request, accepting potential losses up to max_loss and returns the withdrawn assets. Burns the shares representing the amount withdrawn.complete_withdrawal_coin<C>(request: WithdrawalRequest, max_loss: Option<u64>): Coin<C>
: Completes a withdrawal request and returns the withdrawn assets as a Coin.
Harvest Management
request_harvest(account: &signer, auth_ref: &AuthRef): HarvestRequest
: Initiates a harvest request to collect profits or losses. Only callable by strategy manager.report_harvest_profit(request: &mut HarvestRequest, amount: u64)
: Reports profits collected during a harvest operation.report_harvest_loss(request: &mut HarvestRequest, amount: u64)
: Reports losses incurred during a harvest operation.complete_harvest(request: HarvestRequest)
: Completes a harvest operation, processing reported profits and losses.
Strategy Operations
tend_fa(account: &signer, auth_ref: &AuthRef): FungibleAsset
: Moves idle funds into the strategy, returning fungible assets.tend_coin<C>(account: &signer, auth_ref: &AuthRef): Coin<C>
: Moves idle funds into the strategy, returning coins.sweep(account: &signer, strategy: Object<BaseStrategy>, metadata: Object<Metadata>, amount: u64)
: Allows governance or manager to withdraw Fungible Assets (except base asset) from the strategy.
View Functions
base_metadata(strategy: Object<BaseStrategy>): Object<Metadata>
: Retrieves the metadata of the base asset used by the strategy.shares_metadata(strategy: Object<BaseStrategy>): Object<Metadata>
: Retrieves the metadata of the shares asset issued by the strategy.shares_to_amount(strategy: Object<BaseStrategy>, shares: u64): u64
: Converts a given amount of shares to the equivalent base asset amount.amount_to_shares(strategy: Object<BaseStrategy>, amount: u64): u64
: Converts a given amount of base assets to the equivalent shares amount.manager(strategy: Object<BaseStrategy>): address
: Retrieves the address of the strategy manager.total_debt(strategy: Object<BaseStrategy>): u64
: Retrieves the total debt (deployed assets) of the strategy.total_idle(strategy: Object<BaseStrategy>): u64
: Retrieves the total idle assets in the strategy.total_locked(strategy: Object<BaseStrategy>): u64
: Retrieves the total amount of locked profits in the strategy.total_assets(strategy: Object<BaseStrategy>): u64
: Retrieves the total assets (debt + idle) managed by the strategy.last_harvest(strategy: Object<BaseStrategy>): u64
: Retrieves the timestamp of the last harvest operation.performance_fee(strategy: Object<BaseStrategy>): Option<u64>
: Retrieves the current performance fee configuration.lock_duration(strategy: Object<BaseStrategy>): u64
: Retrieves the duration for which profits are locked.fee_amounts(strategy: Object<BaseStrategy>, profit: u64): (u64, u64)
: Retrieves the protocol and manager fee amounts for a given profit.concrete_address(strategy: Object<BaseStrategy>): address
: Retrieves the address of the concrete strategy implementation.total_shares(strategy: Object<BaseStrategy>): u64
: Retrieves the total supply of strategy shares.auth_ref_strategy(auth_ref: &AuthRef): Object<BaseStrategy>
: Retrieves the BaseStrategy from the AuthRef.
Internal Functions
create_internal(constructor_ref: &ConstructorRef, manager: address, base_metadata: Object<Metadata>, shares_metadata: Object<Metadata>, concrete_address: address): (BaseStrategy, BaseStrategyController)
: Internal function to create the base strategy and controller objects. Initializes core strategy parameters and disables ungated transfers.tend_internal(account: &signer, strategy: Object<BaseStrategy>): u64
: Internal implementation of the tend operation. Moves all idle funds into the strategy and updates accounting.deposit_internal(strategy: Object<BaseStrategy>, asset: FungibleAsset)
: Handles the internal deposit logic, updating the strategy's idle balance and storing the deposited assets.create_shares_asset(strategy_signer: &signer, base_metadata: Object<Metadata>): Object<Metadata>
: Creates the shares asset for the strategy with appropriate naming conventions ("ss" prefix) and metadata based on the base asset.mint_shares_for_amount(strategy: &mut BaseStrategy, controller: &BaseStrategyController, amount: u64): FungibleAsset
: Calculates and mints the appropriate amount of shares for a given asset amount based on the current strategy state.mint_debt_shares_internal(strategy: Object<BaseStrategy>, amount: u64): FungibleAsset
: Internal function to mint shares representing debt, updating the strategy's total debt accordingly.
Access Control
Most of the functions in the satay::base_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