Auto Borrow and Repay

Auto Borrow and Repay

In cross-margin trading, users have the option to select either non-borrow mode or auto-borrow mode.

  1. default: auto-borrow

  2. Users can only change the mode when the Cross Margin Portfolio (CMP) has no open positions or pending orders.

There are three different types of auto-repay.

1. Non-Borrow Mode Auto-repay

Applicable to Cross Margin Portfolios (CMP) in non-borrow mode, auto-repay is processed through the following steps, using USDC and dUSDC vault as examples:

Triggering Condition (USDC):

potential liability of USDC - token balance of USDC **> (**USDC vault balance * account-level USDC liability-limit ratio)

Termination Condition (USDC):

potential liability of USDC - token balance of USDC ≤ **0.5 *** (USDC vault balance * account-level USDC liability-limit ratio)

*potential liability = settled liability + unrealized loss + potential fees

Auto-repay Process workflow

  1. Drake off-chain bot detects that a CMP’s USDC meets the triggering condition

  2. It utilizes available USDC in the portfolio to pay its own settled liability as much as possible.

  3. if termination condition is not met, sell other available collaterals on this portfolio to pay the (settled) USDC liability

    1. It starts by selling the asset with the highest discount ratio, which depends on the user's portfolio balances.

    2. It calculates the amount needed to be sold to meet the termination condition and sells all if the amount is insufficient.

    3. Then, it swaps, pays the USDC liability, and stores the surplus as available USDC.

    4. The process continues to sell the next asset if the termination condition is not met.

*order: USDC, DAI, WETH, WBTC

2. Auto-Borrow Mode Auto Repay

Applicable to Cross Margin Portfolios (CMP) in auto-borrow mode, auto-repay is processed through the following steps, using USDC and dUSDC vault as examples:

Triggering 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:

every CMP in auto-borrow mode‘s USDC liability level ≤ the targeted level

*potential liability = settled liability + unrealized loss + pending fee

*liability level = (potential liability - token ****balance) / interest-free limit

Auto-repay Process workflow

  1. The Drake off-chain bot detects that the triggering condition of USDC has been met.

  2. The Drake off-chain bot calculates the target level.

  3. All Cross Margin Portfolios (CMP) in auto-borrow mode are ranked based on liability level, from highest to lowest.

  4. During an auto-repay process:

    1. The available USDC on the portfolio is utilized to pay its own settled USDC liability as much as possible.

    2. Then, other available assets (such as WETH, WBTC) on the portfolio are swapped to pay its settled USDC liability:

      1. It starts by selling the asset with the highest discount ratio, which depends on the user's portfolio balances.

      2. It calculates the amount needed to be sold to hit the target level and sells all if the amount is insufficient.

      3. Then, it swaps, pays the USDC liability, and stores the surplus as available USDC.

      4. The process continues to sell the next asset if the termination condition is not met.

  5. The process moves on to auto-repay the next portfolio. If its current liability level equals the target level, the process stops.

3. Margin-ratio-based Auto Repay

Applicable to every Cross Margin Portfolios (CMP), auto-repay is processed through the following steps, using USDC and dUSDC vault as examples:

Triggering Condition:

portfolio’s margin ratio < margin-ratio auto-repay trigger ratio (199%)

Termination Condition:

portfolio’s margin ratio ≥ margin-ratio auto-repay trigger ratio (199%)

Auto-repay Process workflow

  1. For each asset (USDC, WETH, WBTC), Drake will utilize the same available asset on the portfolio to pay its own settled liability (same token) as much as possible.

  2. If the margin ratio is still less than margin-ratio auto-repay trigger ratio, other assets are used to pay the liability. The process iterates through each asset, starting with USDC:

    1. It swaps other available collaterals (WETH, WBTC) on the portfolio to pay the settled USDC liability

    2. It begins by swapping the asset with the highest discount ratio.

    3. During each iteration (e.g., using WBTC to pay USDC liability is an iteration, using WETH to pay USDC liability is the next iteration), it pays as much as the USDC liability as possible without creating an available balance (this is different from A & B).

    4. The process moves on to the next iteration if the margin ratio less than margin-ratio auto-repay trigger ratio.

    5. If the margin ratio is still less than margin-ratio auto-repay trigger ratio, it moves on to pay the liability of the next asset.