Borrowing and Stabilizers

Borrowing process page describes the steps that a borrower will go through.

This page documents some of the contract calls.

Equations

JTV = JuniorTrancheValue STV = SeniorTrancheValue

TotalEstimatedValue=JTV+STVTotalEstimatedValue = JTV+STV

EquityRatio=JTV/TotalEstimatedValueEquityRatio = JTV/TotalEstimatedValue

SWEEP units

SWEEP has 18 decimal points. So when adding a transaction with a SWEEP amount of token it should have 18 more zeros than the desired amount. Same as with Ether.

Storage

Equity Ratio

If the Equity Ratio goes below this minimum, the stabilizer will be defaulted.

function getEquityRatio()

Minimum Equity Ratio

100% is 1.000.000

function min_equity_ratio()

Fee

100% is 1.000.000

The spread fee is the value that the stabilizer uses to calculate how much fee should it pay in SWEEP tokens to the treasury for the borrowed amount.

function spread_fee()

The accrued fee is the product of: sweep_borrowed * time_elapsed * spread_fee

function accrued_fee()

Sweep Borrowed

Represented by the senior tranche. It is the amount of debt that the stabilizer took.

function sweep_borrowed()

Debt

Returns the total debt of the stabilizer, this is: sweep_borrowed + accrued_fee

function getDebt()

Loan Limit

Loan limit of Sweep that represents the max debt in SWEEP a borrower can take.

function loan_limit()

Junior Tranche Value

Current junior tranche value. Note: If zero the borrower lost his/her investment. If negative, the system started to lose senior tranche value.

function getJuniorTrancheValue()

Default State

When a Stabilizer is defaulted the borrower cannot mint any more sweep or withdraw funds. Returns true if the EquityRatio is below the Minimum Equity Ratio. Will also return true if the Stabilizer is delayed in its payback when divesting.

function isDefaulted()

Accrued Fee

Gets the current fee to be paid.

function accruedFee()

Note: this is calculated by

AF = b * s * (t / y)
b: sweep borrowed amount
s: spread ratio
t: time period we pay the rate
y: time in one year

Call Delay

Represents the amount of time to wait, in seconds, for a repayment after executing a margin_call, before getting into default.

function call_delay()

Call Time

Represents the deadline of the Stabilizer to repay call_amount of SWEEP before getting into default.

function call_time()

Note: this is calculated by

call_time = block.timestamp + call_delay

Call Amount

Represents the amount to be swapped in the AMM and then repaid. The intention is to attempt to peg the AMM price to the Target Price. In case it is not taken to 0 by repaying, the stabilizer will default at the call_time.

function call_amount()

Liquidator Discount

When a Stabilizer is defaulted anyone can liquidate it by repaying its debt and getting back its assets at a discount. It is a percentage where 100% is 1.000.000.

function liquidator_discount()

Borrower Role

Adding to the borrower equity / junior tranche

Send USDC or SWEEP to the Stabilizer address to add to the equity or junior tranche. The borrower can call "withdraw" to get tokens out.

Configure

Sets the initial configuration of the Stabilizer. This configuration will be analyzed by the protocol and if accepted, used to include the Stabilizer in the minter list of Sweep.

  • The borrower starts by calling "configure" to propose terms in the stabilizer

  • The borrower calls "propose" to send these terms to protocol governance

  • The protocol can approve the proposal by adding to the Sweep coin minter list, or "reject"

function configure(
    uint256 _min_equity_ratio,
    uint256 _spread_fee,
    uint256 _loan_limit,
    uint256 _liquidator_discount,
    uint256 _call_delay,
    string calldata _link
)
  • min_equity_ratio: Minimum equity ratio, in percent. 100% = 1,000,000

  • spread_fee: A fee to the protocol, in percent

  • loan_limit: The proposed loan limit in SWEEP (10^18 = 1)

  • liquidator_discount: in percent

  • call_delay: Amount of time between getting a call and a default. In seconds. Use 0 for on-chain assets that can be sold automatically.

  • link: A URL link to a Web page that describes the borrower and the asset

Propose

Sends the Stabilizer to the protocol. Conceptually, this is a request to approve the loan and the loan limit, with the configured terms and asset. Mechanically, it changes the account that controls configuration to the protocol/governance admin.

function propose()

Borrow

Asks the stabilizer to mint a certain amount of sweep token. You will be able to mint if the debt amount keeps the new equity ratio bigger than the minimum equity ratio. Note: this function increments the debt increasing the sweep_borrowed (senior tranche).

function borrow(uint256 _sweep_amount)

Repay

Burns the sweep_amount parameter amount of tokens in the sweep contract. Note: this function reduces the debt decreasing the sweep_borrowed (senior tranche).

function repay(uint256 sweep_amount)

Buy

Buys sweep from the Stabilizer's balance to the AMM at amm_price rate (swaps USDX to SWEEP).

function buy(uint256 _usdx_amount, uint256 _amountOutMin)

Sell

Sells sweep from the Stabilizer's balance to the AMM at amm_price rate (swaps SWEEP to USDX).

function sell(uint256 _sweep_amount, uint256 _amountOutMin)

Buy SWEEP

Buys sweep from the Stabilizer's balance to the borrower at target_price rate (swaps USDX to SWEEP).

function buySWEEP(uint256 _usdx_amount)

Sell SWEEP

Sells sweep from the Stabilizer's balance to the borrower at target_price rate (swaps SWEEP to USDX).

function sellSWEEP(uint256 _sweep_amount)

Withdraw

The borrower can take money out by calling this function. It will pass if the state after transacting doesn't put the stabilizer into default.

function withdraw(address _token, uint256 _amount)

Pay Fee

Pays the protocol spread on the borrowed sweep over time. The Fee is paid when borrowing and repaying too.

function payFee()

Admin Role

Reject a Proposed Configuration

Changes the account that control the global configuration to the borrower. If the borrower/stabilizer is approved, the admin will add the Stabilizer to the minters whitelist in the SWEEP contract.

function reject()

Freeze the Stabilizer

Freezes the Stabilizer. Mint, Sell, Buy, Burn, Invest and Withdraw cannot be executed.

function setFrozen(bool _frozen)

Set a Borrower

Changes the current borrower who manage the investment actions.

function setBorrower(address _borrower)

Asset Functions

Invest

Uses USDX and SWEEP balances to buy a token or deposit money into a protocol or to send them to a wallet. This depends on the asset's internal implementation.

function invest(uint256 _usdx_amount, uint256 _sweep_amount)

Divest

Redeems the investment by selling tokens or withdrawing positions, depending on the kind of asset the the Stabilizer is investing into.

function divest(uint256 _amount)

Liquidate

If the stabilizer is defaulted, this function calls repay and if it succeeds, the caller of the function gets the assets at a discount.

In order to execute the liquidate function. The liquidator must approve an amount equal to the getLiquidationValue() amount, that value can be fetched from the stabilizer.

function liquidate()

Collect

Sends the rewards from the On-Chain-Assets to the Borrower.

function collect()

Last updated