Borrowing

The borrowing.sol is one of the main user facing contracts in the protocol. It exposes the way to add liquidity to the protocol.

Write functions

depositTokens

borrowing.sol
function depositTokens(
    BorrowDepositParams memory depositParam
) external payable
IBorrowing.sol
struct BorrowDepositParams {
    IOptions.StrikePrice strikePercent;
    uint64 strikePrice;
    uint256 volatility;
    AssetName assetName;
    uint256 depositingAmount;
}

enum AssetName {
    DUMMY,
    ETH,
    WeETH,
    rsETH,
    USDa,
    ABOND,
    TUSDT
}
IOptions.sol
enum StrikePrice {
    FIVE,
    TEN,
    FIFTEEN,
    TWENTY,
    TWENTY_FIVE
}
Param Name
Type

strikePercent

enum StrikePrice

Strike price percentage chosen by user.

strikePrice

uint64

Strike price chosen by user.

volatility

uint256

Collateral volatility.

depositingAmount

uint256

User depositing amount.

assetName

enum AssetName

Collateral type depositing by user.

msg.value

uint256

Includes user depositing amount with LZ transaction fees.

After ratio and option fees calculation, half of the collateral is deposited to external protocol. The USDa are minted to the user with option fees deducted. Then it updates the global data by calling LZ's send function.

withDraw

borrowing.sol
function withDraw(
    address toAddress,
    uint64 index,
    bytes memory odosAssembledData,
    bytes memory signature
) payable 
Param Name
Type
Description

toAddress

address

Address of the borrower.

index

uint64

Index of the borrower's position tries to withdraw.

odosAssembledData

bytes

Odos Execution/Assembled data got from Odos API to Swap collateral to USDT.

signature

bytes

Odos assembled data signed by admin 2.

msg.value

uint256

LZ transaction fees.

Withdraws 50% of the deposited collateral from the protocol after user pays the debt amount. The 50% of the deposited amount is credited to the user with strike price gains and for the remaining they are given with ABOND token which is fungible. Later they can use the ABOND tokens to redeem yields from external protocol and 50% of the deposited collateral.

For collaterals other than ETH, the borrower will get entire deposited amount during withdraw.

When repaying, the Borrowing contract must have allowance() to spend funds on behalf of msg.sender. This can be done via the standard ERC20 approve() method on the underlying token contract.

liquidate

borrowing.sol
function liquidate(
    address user,
    uint64 index,
    IBorrowing.LiquidationType liquidationType
) payable
IBorrowing.sol
enum LiquidationType {
    DUMMY,
    ONE,
    TWO,
    THREE
}
Param Name
Type
Description

user

address

Address of the borrower.

index

uint64

Index of the borrower's position.

liquidationType

struct LiquidationType

Defines the type of liquidation needs to be done.

msg.value

uint256

LZ transaction fees.

There are currently 2 liquidation types present.

  • Liquidate by using CDS funds - ONE.

  • Liquidate by taking short position in synthetix with 1x leverage - TWO.

Liquidates the positions whose collateral value becomes 80%.Liquidates the position based on the opted type by admin. Then during withdraw in CDS, the profits and liquidated collaterals are given to the users based on there proportions.

redeemYields

function redeemYields(address user, uint128 aBondAmount)
Param
Type
Description

user

address

Address of the user who is redeeming.

aBondAmount

uint128

Amount of ABOND tokens user wants to redeem.

The user provides ABOND tokens to redeem yields from external protocol. Based on the eth backed and cumulative rate of that ABOND token the yield is calculated and given to the user.

When redeeming, the Borrowing contract must have allowance() to spend funds on behalf of msg.sender. This can be done via the standard ERC20 approve() method on the underlying token contract.

renewOptions

function renewOptions(uint64 index) external payable
Param
Type
Description

index

uint64

Index of the position to renew.

Renews the 20% downside protection of the borrower position by 30 days by providing USDa tokens.

When renewing, the Borrowing contract must have allowance() to spend funds on behalf of msg.sender. This can be done via the standard ERC20 approve() method on the underlying token contract.

calculateRatio

function calculateRatio(uint256 amount, uint256 currentEthPrice)
Param Name
Type
Description

amount

uint256

Collateral amount the user is going to deposit.

currentEthPrice

uint256

Current collateral price.

Calculates the ratio of Collateral value to the total CDS amount in protocol. Updates the total collateral value locked and net CDS amount value based on collateral price changes.

updateRatePerSecByUSDaPrice

function updateRatePerSecByUSDaPrice(uint32 usdaPrice)

Updates the interest rate per second based on USDa price. This function can only be called by admin.

calculateCumulativeRate

function calculateCumulativeRate()

Calculate the current cumulative rate based on APR and time interval between events.

Setter Functions

Function name
Param Name
Description
Param Type

setAdmin

_admin

Admin who will do core operations.

address

setTreasury

_treasury

Treasury contract address.

address

setOptions

_options

Options contract address.

address

setBorrowLiquidation

_borrowLiquidation

BorrowLiquidation contract address

address

setLTV

_LTV

LTV ratio.

uint8

setAPR

_ratePerSec

Interest rate per second based on annual interest.

uint128

setBondRatio

_bondRatio

ABOND to USDa ratio

uint64

Read Functions

getAbondYields

function getAbondYields(address user, uint128 aBondAmount)
Param Name
Type
Description

user

address

Address of the user who is redeeming ABOND.

aBondAmount

uint128

Amount of ABONDs to redeem.

Returns the collateral backed for this ABOND, redeemable collateral amount with external protocol interest and USDa amount got from liquidation.

getUSDValue

function getUSDValue(address token)

Returns the exchange rate to ETH and USD value of the collateral.

getLTV

function getLTV()

getOptionFeesToPay

function getOptionFeesToPay(uint64 index) public view returns (uint256)

Returns the option fees the borrower needs to pay to renew the 20% downside protection.

Last updated