Canopy
  • About Canopy
    • What is Canopy?
  • Canopy's Four Layers
    • Application Layer
    • Rewards Layer
    • Strategy Layer
      • Single Sided Liquidity
      • Simple Lending Strategy
        • Echelon Simple Lend
        • MovePosition Lend
        • Layerbank Lend
      • Vault Rebalancing Strategies
        • Ascend Strategy
    • Protocol Layer
      • Echelon Integration
      • MovePosition Integration
      • Layerbank Integration
  • Audits
    • Audit Reports
  • Tutorials
    • Cornucopia Campaign
    • Depositing on Canopy
    • Withdrawing from Cornucopia and Earning Rewards
    • Withdrawing from Cornucopia
    • MoveDrop Stake to Earn Rewards
  • Operations
    • Terms of Service
    • Canopy Smart Contracts
    • Fee Structure
      • FAQ
Powered by GitBook
On this page
  • Overview
  • Strategy Module
  • Structs
  • Events
  • Error Codes
  • Public Functions
  • Internal Functions
  1. Canopy's Four Layers
  2. Strategy Layer
  3. Simple Lending Strategy

Layerbank Lend

Overview

The layerbank_simple::strategy module implements a simple lending strategy for the LayerBank protocol. It allows deposits and withdrawals of FungibleAsset types and manages lending positions in LayerBank markets.

Strategy Module

Structs

Witness

Internal witness type for strategy creation.

struct Witness has drop {}

LayerBankStrategy

Core strategy struct storing vault and the address of the rewars controller (optional).

struct LayerBankStrategy has key {
    auth_ref: AuthRef,
    vault: Object<Vault>,
    rewards_controller_address: Option<address>
}

Events

  • StrategyCreated: Event emitted when a new strategy is created.

Error Codes

  • ENOT_AUTHORIZED: Not authorized to perform the operation

  • EINVALID_AMOUNT: Invalid amount specified

  • EINSUFFICIENT_BALANCE: Insufficient balance to perform the operation

  • EVAULT_MISMATCH: Invalid vault specified

  • EWITHDRAWAL_ACCOUNT_MISMATCH: Invalid withdrawal account specified

  • ECANNOT_EXCEED_DEBT: Cannot exceed the strategy debt

Public Functions

Strategy Creation and Management

  • create(account: &signer, vault: Object<Vault>, debt_limit: u64, rewards_controller_address: Option<address>): Creates a new instance of the strategy for the specified vault and sets up the rewards controller address (optional).

Deposit and Withdrawal Functions

  • deposit_fa(account: &signer, strategy: Object<BaseStrategy>, amount: u64): Withdraws the strategy's base asset from signer's primary store and deposits this into the strategy. The minted strategy shares are deposited into the signer's primary fungible store.

  • withdraw_fa(account: &signer, strategy: Object<BaseStrategy>, amount: u64, max_loss: Option<u64>): Withdraws the strategy's base asset from the strategy by redeeming the specified amount of strategy shares from the signer's primary fungible store.

Vault Operations

  • vault_deposit_fa(governor: &signer, strategy: Object<BaseStrategy>, amount: u64): Deposits the strategy's base asset from the vault into the strategy. Must be called with the vault's governor. Must be called with the vault's signer (typically via router). The minted strategy shares are deposited into the vault's primary fungible store.

  • vault_withdraw_fa(account: &signer, request: &mut WithdrawalRequest, strategy: Object<BaseStrategy>, amount: u64, max_loss: Option<u64>): FungibleAsset: Withdraws the strategy's base asset from a vault's strategy. Must be called with the vault's signer (typically via router). Processes withdrawal through the withdraw_strategy_shares function in the satay::vault module.

Strategy Operations

  • tend_fa(manager: &signer, strategy: Object<BaseStrategy>): Tends the strategy's position by depositing idle assets into the LayerBank market.

  • vault_report(governor: &signer, strategy: Object<BaseStrategy>): Reports strategy performance to the vault.

  • harvest(account: &signer, strategy: Object<BaseStrategy>): Harvests profits/losses including rewards from the strategy. Base asset rewards are considered profits and are auto-compounded back into the strategy. Non-base asset rewards are deposited to the strategy's primary fungible store and can be swept using base_strategy::sweep. Only callable by accounts authorized to request harvests.

Admin Functions

  • set_rewards_controller_address(account: &signer, strategy: Object<BaseStrategy>, new_rewards_controller_address: Option<address>): Updates the rewards controller address for the strategy. Only callable by strategy manager.

  • claim_all_non_base_asset_rewards(account: &signer, strategy: Object<BaseStrategy>): Claims all non-base asset rewards from LayerBank. Only callable by strategy manager.

View Functions

  • get_base_asset(strategy: Object<BaseStrategy>): Object<Metadata>: Returns the base asset Metadata Object for the strategy.

  • get_rewards_controller_address(strategy: Object<BaseStrategy>): Option<address>: Returns the current rewards controller address. Returns None if there is no reward controller address set.

Internal Functions

  • borrow_strategy(strategy: Object<BaseStrategy>): &LayerBankStrategy: Returns a reference to the strategy data.

  • deposit_fa_internal(strategy: &LayerBankStrategy, asset: FungibleAsset): FungibleAsset: Internal function for deposits. Mints strategy shares and deposits assets into LayerBank.

  • market_deposit_fa_internal(strategy: &LayerBankStrategy, asset: FungibleAsset): Internal function for depositing assets to LayerBank market.

  • withdraw_fa_internal(strategy_ref: &LayerBankStrategy, asset: FungibleAsset, max_loss: Option<u64>): FungibleAsset: Internal function for withdrawals. Processes withdrawal through idle assets first, then withdraws from LayerBank if needed.

  • market_withdraw_fa_internal(strategy_ref: &LayerBankStrategy, amount: u64): FungibleAsset: Internal function for withdrawing assets from LayerBank market.

  • handle_harvest_pnl(request: &mut HarvestRequest, strategy: Object<BaseStrategy>, base_metadata: Object<Metadata>): Internal function to calculate and report profits/losses during harvest. Compares the latest supplied amount in LayerBank against the last recorded total debt to determine if there was a profit or loss.

PreviousMovePosition LendNextVault Rebalancing Strategies

Last updated 2 months ago