Auto Borrow and Repay
Auto Borrow and Repay
In cross-margin trading on Drake, users have the flexibility to choose between non-borrow mode and auto-borrow mode.
Default Mode: Auto-borrow is enabled by default.
Mode Switching: Users can only switch modes when their Cross Margin Portfolio (CMP) has no open positions or pending orders.
Types of Auto-Repay
There are three types of auto-repay mechanisms available, depending on the selected mode and conditions:
1. Non-Borrow Mode Auto-Repay
This auto-repay process applies to Cross Margin Portfolios (CMP) in non-borrow mode. Here’s how it works:
Triggering Condition (USDC):
Condition: Potential liability of USDC - Token balance of USDC > (USDC vault balance * Account-level USDC liability-limit ratio).
Termination Condition (USDC):
Condition: Potential liability of USDC - Token balance of USDC ≤ 0.5 * (USDC vault balance * Account-level USDC liability-limit ratio).
Potential liability includes settled liability, unrealized loss, and potential fees.
Auto-Repay Process Workflow
Detection: Drake’s off-chain bot detects when a CMP’s USDC amount meets the triggering condition.
Initial Repayment: The protocol uses available USDC in the portfolio to pay off the settled liability as much as possible.
Asset Liquidation: If the termination condition isn’t met, the protocol sells other available collateral in the portfolio to pay the remaining USDC liability:
It starts with the asset that has the highest discount ratio, depending on the user's portfolio balances.
The protocol calculates the required sale amount to meet the termination condition and sells all if the amount is insufficient.
The assets are then swapped, the USDC liability is paid, and any surplus is stored as available USDC.
The process continues with the next asset until the termination condition is satisfied.
Asset Liquidation Order: USDC, WETH, WBTC
2. Auto-Borrow Mode Auto-Repay
This auto-repay process is for Cross Margin Portfolios (CMP) in auto-borrow mode:
Triggering Condition:
Condition: Global total potential USDC liability of all CMPs - Total USDC on all CMPs > (USDC vault balance * USDC vault-level liability limit ratio).
Termination Condition:
Condition: Every CMP in auto-borrow mode’s USDC liability level ≤ the targeted level.
Potential liability includes settled liability, unrealized loss, and pending fees. The liability level is calculated as (Potential liability - Token balance) / Interest-free limit.
Auto-Repay Process Workflow
Detection: The Drake off-chain bot identifies when the triggering condition for USDC is met.
Target Level Calculation: The protocol calculates the target liability level for the CMPs.
Ranking CMPs: CMPs in auto-borrow mode are ranked by liability level, from highest to lowest.
Auto-Repay Execution:
The protocol first uses available USDC on the portfolio to pay off the settled USDC liability as much as possible.
If further repayment is needed, the protocol swaps other available assets (e.g., WETH, WBTC) to cover the USDC liability:
It starts by selling the asset with the highest discount ratio, based on the portfolio’s balances.
The required amount to reach the target level is calculated, and if insufficient, all assets are sold.
The process continues with the next asset until the termination condition is met.
Moving to Next CMP: The protocol proceeds to auto-repay the next portfolio. If its current liability level equals the target level, the process stops.
3. Margin-Ratio-Based Auto-Repay
This auto-repay mechanism applies to all Cross Margin Portfolios (CMP), focusing on maintaining the portfolio’s margin ratio.
Triggering Condition:
Condition: Portfolio’s margin ratio < Margin-ratio auto-repay trigger ratio (199%).
Termination Condition:
Condition: Portfolio’s margin ratio ≥ Margin-ratio auto-repay trigger ratio (199%).
Auto-Repay Process Workflow
Asset Repayment: For each asset (USDC, WETH, WBTC), Drake utilizes the same available asset in the portfolio to pay off its own settled liability as much as possible.
Cross-Asset Repayment:
If the margin ratio is still below the trigger ratio, other assets are used to pay off the liability:
The protocol starts by swapping the asset with the highest discount ratio.
During each iteration (e.g., using WBTC to pay USDC liability), the protocol pays as much of the USDC liability as possible without creating an available balance (differing from the previous modes).
The process continues to the next iteration if the margin ratio is still below the trigger ratio.
If the margin ratio remains below the trigger, the protocol moves on to pay the liability of the next asset.
Last updated