Pegkeeper Usage and Operational Flow
The Pegkeeper contract is essential for maintaining the stablecoin peg within the protocol. It performs market operations such as flash loans, liquidations, and arbitrage trades to stabilize the stablecoin value.
Core Concepts
Flash Loans: Allow borrowing assets without collateral, provided the loan is repaid within the same transaction. The Pegkeeper utilizes flash loans to obtain stablecoins for its operations.
Liquidation Auctions: Occur when a borrower’s collateral falls below the required threshold. The Pegkeeper participates in these auctions to purchase collateral at a discount.
Automated Market Maker (AMM): A decentralized exchange mechanism where assets are traded directly with a liquidity pool, facilitating the conversion of collateral to stablecoins.
Usage
To use the Pegkeeper, a user calls the keep_peg
function on the Treasury contract. This function orchestrates the process of maintaining the peg through a series of steps involving minting, liquidations, trading, and repaying the loan.
Function Signature:
Operational Flow
Initiating Liquidation:
The user triggers the blend liquidation and gathers parameters such as
bid_amount
,lot_amount
, andliq_amount
according to the auction.
Calling the Treasury Function:
The user calls the
keep_peg
function on the Treasury contract with the gathered parameters.
Minting Stablecoins:
Upon calling
keep_peg
, the Treasury mintsbid_amount
of the stablecoin and sends it to the Pegkeeper, increasing its balance to participate in the liquidation auction.
Calling
fl_receive
:The Treasury calls the
fl_receive
function of the Pegkeeper. This function handles the liquidation and trading operations necessary to maintain the peg.
Participating in Liquidation Auction:
The Pegkeeper uses the minted stablecoins to participate in the liquidation auction, acquiring collateral at a discounted rate.
Trading on AMM:
The Pegkeeper trades the acquired collateral on an AMM for the stablecoin, converting the collateral back to the stablecoin ideally at a profit.
Profit Check and Repayment:
After trading, the Pegkeeper checks if the operation was profitable by comparing the balances before and after the transaction.
If profitable, the Pegkeeper repays the flash loan to the Treasury and transfers any excess profit to the
fee_taker
.
Burning Excess Stablecoins:
The Treasury burns the repaid stablecoins to maintain the overall supply balance within the protocol, preventing permanent inflation of the stablecoin supply.
Important Notes
The user must manually trigger the liquidation and gather the necessary parameters, ensuring they are correct and result in a profitable trade.
The process includes checks to ensure profitability; if the operation is not profitable, the transaction reverts to prevent losses.
Last updated