USDa to mint
Copy function _transferToken(
address _borrower,
uint256 amount,
uint128 _ethPrice,
uint256 optionFees
)
Param Name
Param Type
Description
Options fees to deduct from borrower.
Copy uint256 tokensToLend = BorrowLib.tokensToLend(amount, _ethPrice, LTV);
bool minted = usda.mint(_borrower, (tokensToLend - optionFees));
Copy function tokensToLend(
uint256 depositedAmont,
uint128 ethPrice,
uint8 LTV
) public pure returns(uint256){
uint256 tokens = (depositedAmont * ethPrice * LTV) / (USDA_PRECISION * RATIO_PRECISION);
return tokens;
}
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
ABOND to mint
Copy function _mintAbondToken(
address _toAddress,
uint64 _index,
uint256 _amount
)
Param Name
Type
Description
For which position index needs to mint ABOND.
Copy uint128 amount = BorrowLib.abondToMint(_amount,bondRatio);
Copy function abondToMint(
uint256 _amount,
uint64 _bondRatio
) public pure returns(uint128 amount){
amount = (uint128(_amount) * USDA_PRECISION)/_bondRatio;
}
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
Copy uint256 normalizedAmount = BorrowLib.calculateNormAmount(tokensToLend,lastCumulativeRate);
Copy function calculateNormAmount(
uint256 amount,
uint256 cumulativeRate
) public pure returns(uint256){
return (amount * RATE_PRECISION)/cumulativeRate;
}
Functions which are using the above logic
ABOND USDa Pool Calculation
Copy uint256 discountedETH = BorrowLib.calculateDiscountedETH(
depositDetail.depositedAmount,
_ethPrice
);
Copy function calculateDiscountedETH(
uint256 amount,
uint128 ethPrice
) public pure returns(uint256){
return ((((80*calculateHalfValue(amount))/100)*ethPrice)/100)/USDA_PRECISION;
}
function calculateHalfValue(uint256 amount) public pure returns(uint128){
return uint128((amount * 50)/100);
}
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
Copy uint128 ethToReturn;
//Calculate current depositedAmount value
uint128 depositedAmountvalue = (
depositDetail.depositedAmount * depositDetail.ethPriceAtDeposit)/_ethPrice;
if(borrowingHealth > 10000){
// If the ethPrice is higher than deposit ethPrice,call withdrawOption in options contract
ethToReturn = (depositedAmountvalue + (options.calculateStrikePriceGains(depositDetail.depositedAmount,depositDetail.strikePrice,_ethPrice)));
if(ethToReturn > depositDetail.depositedAmount){
ethRemainingInWithdraw += (ethToReturn - depositDetail.depositedAmount);
omniChainBorrowing.ethRemainingInWithdraw += (ethToReturn - depositDetail.depositedAmount);
}else{
ethRemainingInWithdraw += (depositDetail.depositedAmount - ethToReturn);
omniChainBorrowing.ethRemainingInWithdraw += (depositDetail.depositedAmount - ethToReturn);
}
ethValueRemainingInWithdraw += (ethRemainingInWithdraw * _ethPrice);
omniChainBorrowing.ethValueRemainingInWithdraw += (ethRemainingInWithdraw * _ethPrice);
}else if(borrowingHealth == 10000){
ethToReturn = depositedAmountvalue;
}else if(8000 < borrowingHealth && borrowingHealth < 10000) {
ethToReturn = depositDetail.depositedAmount;
}else{
revert("BorrowingHealth is Low");
}
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
Copy function calculateCumulativeRate(
uint128 noOfBorrowers,
uint256 ratePerSec,
uint128 lastEventTime,
uint256 lastCumulativeRate
)
Param Name
Type
Description
Total number of borrowers in treasury.
Interest rate per second.
Previous cumulative rate.
Copy currentCumulativeRate = lastCumulativeRate * _rpow(ratePerSec, timeInterval, RATE_PRECISION);
currentCumulativeRate = currentCumulativeRate / RATE_PRECISION;
Copy Current cumulative rate = last cumulative rate * (rate per second) ^ time interval.
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
Copy function calculateRatio(
uint256 _amount,
uint currentEthPrice,
uint128 lastEthprice,
uint128 noOfBorrowers,
uint256 latestTotalCDSPool,
IBorrowing.OmniChainBorrowingData memory previousData
)
Param Name
Type
Description
ETH amount, the user is depositing.
Current ETH to USD price.
ETH price when the last event happened.
Total number of borrowers in the protocol.
Total CDS amount accumulated in the protocol.
Struct OmniChainBorrowingData
Previously stored global data of borrowing contract.
Copy // Calculate net P/L of CDS Pool
netPLCdsPool = price difference between current and last ETH price * noOfBorrowers;
previousData.cdsPoolValue = previousData.totalCDSPool + netPLCdsPool;
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,
Copy previousData.cdsPoolValue = previousData.cdsPoolValue + (
latestTotalCDSPool - previousData.totalCDSPool) + netPLCdsPool;
Add the netPLCdsPool with previous net CDS Pool value and CDS amount deposited after last event.
Copy ratio = currentCDSPoolValue / currentEthVaultValue;
Finally, calculate the ratio by dividing currentCDSPoolValue by currentEthVaultValue.
Functions which are using the above logic
Downside Calculation
Copy function calculateDownsideProtected(
uint128 amount,
uint128 currentEthPrice,
uint128 depositEthPrice
) public pure returns (uint128) {
if (currentEthPrice < depositEthPrice) {
return
(amount * (depositEthPrice - currentEthPrice)) /
(100 * USDA_PRECISION);
} else {
return 0;
}
}
Calculates the downside needs to protect by CDS user.
Functions which are using the above logic
Options fees per second Calculation
Copy function calculateOptionsFeesPerSec(
uint128 optionsFees
) public pure returns (uint128) {
return (optionsFees * OPTIONS_FEES_PRECISION) / 30 days;
}
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 4 months ago