MovePosition Simple
Overview
The moveposition_simple::strategy
module implements a lending strategy for the MovePosition protocol. It manages lending positions using packets (serialized tickets) for position validation and state management.
Terminology
Packet
A signed binary packet containing a serialized ticket that authorizes the deposit. The packet is verified using Hocket and must contain valid ticket data
Strategy Module
Structs
MovePositionStrategy
Core strategy struct storing vault and authorization references.
Witness
Internal witness type for strategy creation.
Events
StrategyCreated: Event emitted when a new strategy is created.
Error Codes
EINVALID_AMOUNT
: Invalid amount specifiedEINSUFFICIENT_BALANCE
: Insufficient balance to perform the operationEVAULT_MISMATCH
: Invalid vault specifiedEWITHDRAWAL_ACCOUNT_MISMATCH
: Invalid withdrawal account specifiedECANNOT_EXCEED_DEBT
: Cannot exceed the strategy debt
Public Functions
create<CoinType>(account: &signer, vault: Object<Vault>, debt_limit: u64)
: Creates a new instance of the strategy for the specified vault. Only callable by governance account.deposit_coin<CoinType>(account: &signer, strategy: Object<BaseStrategy>, packet: vector<u8>, amount: u64)
: Deposits the strategy's base asset (Coin) directly into the strategy, using the internal deposit_internal function. Requires a packet.vault_deposit_coin<CoinType>(account: &signer, strategy: Object<BaseStrategy>, packet: vector<u8>, amount: u64)
: Deposits the strategy's base asset (Coin) from the vault into the strategy, using the internal deposit_internal function. Requires a packet.withdraw_coin<CoinType>(account: &signer, strategy: Object<BaseStrategy>, packet: vector<u8>, amount: u64, max_loss: Option<u64>)
: Withdraws the strategy's base asset (Coin) directly from the strategy. Uses internal functions prepare_withdrawal_internal to withdraw strategy shares from signer's primary fungible stores and process_withdrawal_internal to redeem the strategy shares for the strategy's base asset (Coin). Requires a packet.vault_withdraw_coin<CoinType>(account: &signer, request: &mut WithdrawalRequest, strategy: Object<BaseStrategy>, packet: vector<u8>, amount: u64, max_loss: Option<u64>): Coin<CoinType>
: Withdraws the strategy's base asset (Coin) from a vault's strategy. Must be called with the vault's signer (typically via router). Uses vault's withdraw_strategy_shares function in thesatay::vault
module to withdraw strategy shares from vault's primary fungible stores. Then uses process_withdrawal_internal to redeem the strategy shares for the strategy's base asset (Coin). Requires a packet.tend_coin<CoinType>(account: &signer, strategy: Object<BaseStrategy>, packet: vector<u8>)
: Deposits idle coins into the MovePosition market.vault_report<CoinType>(account: &signer, strategy: Object<BaseStrategy>)
: Reports strategy performance to the vault by calling the report function in thesatay::vault
module.
Internal Functions
borrow_strategy(strategy: Object<BaseStrategy>): &MovePositionStrategy
: Returns a reference to the strategy data.deposit_internal<CoinType>(strategy: &MovePositionStrategy, packet: vector<u8>, coin: Coin<CoinType>): FungibleAsset
: Internal function for Coin deposits.market_withdraw_internal<CoinType>(strategy_ref: &MovePositionStrategy, packet: vector<u8>, amount: u64): Coin<CoinType>
: Internal function for withdrawing Coin from market. Validates a packet using the internal validate_ticket function, then calls the redeem function inmoveposition_block::moveposition_block
to redeem the shares for Coin.market_deposit_internal<CoinType>(strategy: &MovePositionStrategy, packet: vector<u8>, coin: Coin<CoinType>)
: Internal function for depositing coins to market. Validates a packet using the internal validate_ticket function. First deposits the Coin to the strategy signer, , then calls the lend function inmoveposition_block::moveposition_block
to deposit the Coin into the market.validate_ticket<CoinType>(packet: vector<u8>, amount: u64, operation: String)
: Helper function to validate a ticket for market operations. Takes in a packet which is validated against the CoinType, amount and operation.process_withdrawal_internal<CoinType>(strategy: Object<BaseStrategy>, packet: vector<u8>, shares_asset: FungibleAsset, max_loss: Option<u64>): Coin<CoinType>
: Internal function for processing withdrawals. Creates a withdrawal request with the provided shares and attempts base strategy withdrawal using the withdraw function insatay::base_strategy
. If funds remain to be withdrawn, calculates needed amount and available collateral, then withdraws from market using market_withdraw_internal. Finally completes the withdrawal with specified loss tolerance using the complete_withdrawal_coin function insatay::base_strategy
and returns the withdrawn Coin.prepare_withdrawal_internal(account: &signer, strategy: Object<BaseStrategy>, amount: u64): FungibleAsset
: Internal function for preparing withdrawals. Withdraws and returns strategy shares from the signers account.get_collateral_for_shares<CoinType>(strategy_ref: &MovePositionStrategy, amount: u64): u64
: Calculates collateral value for given amount of shares. Retrieves the collateral balance and total shares to calculate the collateral value for a given amount using the function below:
Last updated