Borrowing Logics
Here the logics used in Borrowing contract and BorrowLib are explained.
In code, many base PRECISION are used to avoid, arithmetic, division or modulo by zero errors.
USDa to mint
_borrower
address
Address of the borrower.
amount
uint256
Deposited ETH amount.
_ethPrice
uint128
Current ETH price.
optionFees
uint256
Options fees to deduct from borrower.
Calculate the USDa to lend, by using LTV ratio. Then deduct the options fees, mint the remaining to borrower and options fees to treasury.
Functions which are using the above logic
LTV is global variable in Borrowing contract.
ABOND to mint
_toAddress
address
Address of the borrower.
_index
uint64
For which position index needs to mint ABOND.
_amount
uint256
ETH backed.
Calculate the ABOND to mint to user during withdraw based on bondRatio and mint it to borrower.
Functions which are using the above logic
Normalized amount calculation
Calculate the normalized amount by dividing the total borrowed amount with cumulative rate. Cumulative rate should get from calculateCumulativeRate method.
Functions which are using the above logic
ABOND USDa Pool Calculation
Calculates the 50% of the deposited amount value with current ETH price, then 80% of the calculated amount is going to ABOND USDa pool to back ABOND.
Functions which are using the above logic
Withdraw ETH calculation
Calculate the withdraw amount by taking the ratio of deposit ETH price to current ETH price.
If the current ETH price is higher than deposited ETH price,
Cumulative rate calculation
noOfBorrowers
uint128
Total number of borrowers in treasury.
ratePerSec
uint256
Interest rate per second.
lastEventTime
uint128
Timestamp of last event.
lastCumulativeRate
uint256
Previous cumulative rate.
Here, event represents Deposit, Withdraw and Liquidation.
To calculate the current cumulative rate, multiply the previous cumulative rate with interest rate per second to the power of time interval between two events.
Functions which are using the above logic
Calculation of ratio of CDS Pool value to ETH vault value
_amount
uint256
ETH amount, the user is depositing.
currentEthPrice
uint256
Current ETH to USD price.
lastEthPrice
uint128
ETH price when the last event happened.
noOfBorrowers
uint128
Total number of borrowers in the protocol.
latestTotalCDSPool
uint256
Total CDS amount accumulated in the protocol.
previousData
Struct OmniChainBorrowingData
Previously stored global data of borrowing contract.
Initially calculate the net P&L of CDS, if the current ETH price is higher than last ETH price , then its profit else its loss.
If the ratio calculation is for first deposit in the protocol, then calculate net CDS Pool value by adding netPLCdsPool with total CDS amount accumulated. else,
Add the netPLCdsPool with previous net CDS Pool value and CDS amount deposited after last event.
Finally, calculate the ratio by dividing currentCDSPoolValue by currentEthVaultValue.
Functions which are using the above logic
Downside Calculation
Calculates the downside needs to protect by CDS user.
Functions which are using the above logic
Options fees per second Calculation
Calculates the options fees per second by dividing the options fees paid by user during deposit by number of seconds in 30 days.
Last updated