CDS

The CDS is another main user facing contract in Autonomint protocol, where users can deposit stablecoins like USDa, USDT to get yields.

During withdraw the user can get the deposited amount based on collateral price change between deposit and withdraw, Options fees and liquidation gains if opted.

There is a redeemUSDT option also available to get the USDT, for that equal amount of USDa needs to be burn from the user.

Write Functions

deposit

function deposit(
        uint128 usdtAmount,
        uint128 usdaAmount,
        bool liquidate,
        uint128 liquidationAmount,
        uint128 lockingPeriod ) payable 
Param Name
Type
Description

usdtAmount

uint128

Amount USDT token user is depositing.

usdaAmount

uint128

Amount USDa token user is depositing.

liquidate

bool

Whether the user is opted for liquidation gains.

liquidationAmount

uint128

Opted liquidation amount.

lockingPeriod

uint128

How long the user is willing to stay deposited in protocol.

msg.value

uint256

Lz transaction fee.

The user can able to deposit up to USDT $20K, for that the same amount of USDa is minted. After it reaches the 20K limit, the user must deposit minimum USDa amount of 80% of total depositing amount. There is an locking period option is also available to lock the deposited amount by user itself. User can also opt for liquidation gains i.e. the user can use this deposited amount to be used for liquidating collaterals.

withdraw

function withdraw(
    uint64 index,
    uint256 excessProfitCumulativeValue,
    uint256 nonce,
    bytes memory signature
) public payable
Param Name
Type
Description

index

uint64

Index of the user's position, tries to withdraw.

excessProfitCumulativeValue

uint256

The cumulative value of the excess profit, needs to remove from the upside.

nonce

uint256

Nonce of the signer who signed the signsture.

signature

bytes

Excess profit cumulative value signed by admin 2.

msg.value

uint256

Lz transaction fee.

The withdraw amount is calculated by

  • price change of collateral between deposit and withdraw.

  • option fees earned by the user by protecting the borrower's collateral.

  • If opted for liquidation, then the user will get protected liquidated position value and collateral.

Option fees earned by user is calculated by using cumulative rate.

redeemUSDT

function redeemUSDT(uint128 usdaAmount, uint64 usdaPrice, uint64 usdtPrice) payable
Param Name
Type
Description

usdaAmount

uint128

USDa amount the user is willing to exchange.

usdaPrice

uint64

USDa price.

usdtPrice

uint64

USDT price.

msg.value

uint256

Lz transaction fee.

After user transferred USDa to the protocol through redeemUSDT() method, the same value of USDT is transferred to the user. Then the acquired USDa is burned to maintain the USDa always pegged to $1.

calculateCumulativeRate

function calculateCumulativeRate(uint128 fees) payable
Param Name
Type
Description

fees

uint128

Option fees to give to CDS users.

msg.value

uint256

Lz transaction fee.

The option fees is distributed to the CDS users by using cumulative rate. During deposit the normalized amount of the deposited amount of the user is stored. When the user withdraws, the normalized amount is multiplied with current cumulative rate to get the deposited amount with option fees.

This function is only called by Borrowing contract.

calculateCumulativeValue

function calculateCumulativeValue(
    uint256 vaultBal,
    uint256 globalTotalCdsDepositedAmount,
    uint128 _price
)external
Param Name
Type
Description

vaultBal

uint256

Total collateral deposited by borrowers in ETH value in all chains.

globalTotalCdsDepositedAmount

uint256

Total CDS deposited amount in all chains

_price

uint128

Current ETH price.

Calculates the cumulative value based on comparing last stored ETH price and current ETH price multiplied with Vault to CDS ratio.

This function is only called by Borrowing contract.

cdsAmountToReturn

function cdsAmountToReturn(
    address _user,
    uint64 index,
    uint128 cumulativeValue,
    bool cumulativeValueSign,
    uint256 excessProfitCumulativeValue
) private view returns (uint256)

Calculates the USDa amount to return to the user during withdraw, based on price fluctuations and collateral amount in borrow since deposit.

Setter Functions

Update Functions

ReadFunctions

Last updated