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

Function Name

setAdmin

Param Name

_admin

Param Type

address

Description

Admin address.

Function Name

setBorrowingContract

Param Name

_address

Param Type

address

Description

Borrowing contract address.

Function Name

setTreasury

Param Name

_treasury

Param Type

address

Description

Treasury contract address.

Function Name

setBorrowLiquidation

Param Name

_address

Param Type

address

Description

BorrowLiquidation contract address.

Function Name

setWithdrawTimeLimit

Param Name

_timeLimit

Param Type

uint64

Description

CDS withdraw locking period.

Function Name

setUSDaLimit

Param Name

percent

Param Type

uint8

Description

USDa percent, the user must deposit after $20k USDT.

Function Name

setUsdtLimit

Param Name

amount

Param Type

uint64

Description

USDT limit.

Function Name

setDstEid

Param Name

_eid

Param Type

uint32

Description

Destination chain EID.

Function Name

setAdminTwo

Param Name

hashedAddress32

Param Type

bytes

Description

Hashed admin two address.

Update Functions

Function Name

updateLastEthPrice

Param Name

priceAtEvent

Param Type

uint128

Description

ETH price to update.

Function Name

updateLiquidationInfo

Param Name

index, liquidationData

Param Type

uint128,struct LiquidationInfo

Description

Liquidation Info to update.

Function Name

updateTotalAvailableLiquidationAmount

Param Name

amount

Param Type

uint128

Description

Available liquidation amount to update.

Function Name

updateTotalCdsDepositedAmount

Param Name

_amount

Param Type

uint256

Description

CDS amount to update.

Function Name

updateTotalCdsDepositedAmountWithOptionFees

Param Name

_amount

Param Type

uint256

Description

CDS amount with option fees to update.

Function Name

updateDownsideProtected

Param Name

downsideProtectedAmount

Param Type

uint128

Description

Downside protected amount during borrow withdraw.

ReadFunctions

Function Name

getLatestData

Description

Gets the latest ETH price.

Param Name

Param Type

Function Name

getCumulativeValue

Description

Gets the current cumulative value.

Param Name

omniChainData, value, gains

Param Type

uint128,struct LiquidationInfo

Function Name

getOptionsFeesProportions

Description

Gives the options fees to get from other chains based on given options fees.

Param Name

optionsFees

Param Type

uint256

Function Name

getCDSDepositDetails

Description

Gets the cds details for the given address and index, and total index of the address.

Param Name

depositor, index

Param Type

address, uint64

Function Name

getTotalCdsDepositedAmount

Description

Get the total CDS deposited amount.

Param Name

Param Type

Function Name

getTotalCdsDepositedAmountWithOptionsFees

Description

Get the total CDS deposited amount with options fees.

Param Name

Param Type

Last updated