PegKeeper

The Pegkeeper contract is a critical component of the Orbit Protocol that maintains stablecoin pegs through automated market operations. It executes liquidations and performs AMM trades using flash-loaned tokens to ensure stablecoin stability.

Core Components

Initialization

fn initialize(e: Env, admin: Address, router: Address)

The Pegkeeper initializes with two essential parameters:

  • admin: The address with administrative privileges

  • router: The AMM router address for executing trades

Flash Loan Handler

fn fl_receive(
    e: Env, 
    token: Address,              // Stablecoin address
    amount: i128,                // Flash loan amount
    blend_pool: Address,         // Blend pool address
    auction: Address,            // Auction contract address
    collateral_token: Address,   // Collateral token address
    lot_amount: i128,            // Amount of collateral to receive
    liq_amount: i128,            // Liquidation percentage (0-100)
    amm: Address,                // AMM address for swaps
    fee_taker: Address          // Address to receive profits
)

The fl_receive function is the core operation handler that:

  • Receives flash-loaned stablecoins

  • Executes liquidations

  • Performs AMM trades

  • Manages profits

  • Handles loan repayment

Error Management

  • AlreadyInitializedError: Prevents duplicate initialization

  • NotProfitable: Reverts unprofitable operations

Events

The contract emits events for major operations:

  • Contract initialization

  • Flash loan reception

  • Successful operations

Last updated