Treasury

The Treasury / Vault is the main core contract in Autonomint. All the funds are transferred here, from Borrowing and CDS. External protocol deposits and yields are generated in treasury contract.

Write Functions

deposit

function deposit(
    address user,
    uint128 ethPrice,
    uint64 depositTime,
    IBorrowing.AssetName assetName,
    uint256 depositingAmount
) payable 
Param Name
Type
Description

user

address

Address of the borrower.

ethPrice

uint128

Current ETH price.

depositTime

uint64

Depositing time.

depositingAmount

uint256

Depositing amount by borrower.

assetName

User depositing collateral type.

In this function, the borrower's position data are stored and half of the deposited collateral is deposited in External protocol.

withdraw

function withdraw(
        address borrower,
        address toAddress,
        uint256 amount,
        uint64 index ) payable
Param Name
Type
Description

borrower

address

Borrower's address.

toAddress

address

Receiver's address.

amount

uint256

Withdraw amount.

index

uint64

Index pf the withdrew position.

Transfers 50% of the deposited amount with call option gains.

withdrawFromExternalProtocol

function withdrawFromExternalProtocolDuringLiq(
    address user,
    uint64 index
)
Param Name
Type
Description

user

address

User's address who is redeeming ABOND.

index

uint64

Index of the user.

Withdraws the ETH backed with interest gained for the redeemable ABOND amount. Then the ABOND is burned from user.

withdrawFromExternalProtocolDuringLiq

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

user

address

User's address who is redeeming ABOND.

aBondAmount

uint128

ABOND amount to redeem.

Withdraws the ETH from External protocol i.e, the 50% of the deposited amount.

approveTokens

function approveTokens(
    IBorrowing.AssetName assetName,
    address spender,
    uint amount
)
Param Name
Type
Description

assetName

Asset type, the treasury contract needs to approve

spender

address

Address of the spender.

amount

uint256

Amount of tokens to approve.

Approves the asset to be spend by spender (mostly core contracts).

_calculateCumulativeRate

function _calculateCumulativeRate(
    uint256 _currentExchangeRate,
    Protocol _protocol
) internal returns (uint256)
enum Protocol {
    Aave,
    Compound,
    Ionic
}
Param Name
Type
Description

_currentExchangeRate

uint256

Current ionWETH to WETH exchange rate.

_protocol

Protocol

External protocol name.

Calculates the cumulative rate for that protocol and store that.

depositToIonicByUser

function depositToIonicByUser(uint256 depositAmount) internal
Param Name
Type
Description

depositAmount

uint256

Collateral amount to deposit in Ionic.

Deposits the collateral amount to Ionicprotocol. Updates the cumulative rate(to calculate interest) for Ionic protocol.

depositToAaveByUser

function depositToAaveByUser(uint256 depositAmount) internal
Param Name
Type
Description

depositAmount

uint256

Collateral amount to deposit in Aave.

Deposits the collateral amount to Aave protocol. Updates the cumulative rate(to calculate interest) for Aave protocol.

depositToCompoundByUser

function depositToCompoundByUser(uint256 depositAmount) internal
Param Name
Type
Description

depositAmount

uint256

Collateral amount to deposit in Compound.

Deposits the collateral amount to Compound protocol. Updates the cumulative rate(to calculate interest) for Compound protocol.

withdrawFromIonicByuser

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

user

address

Address of the user.

aBondAmount

uint128

ABOND amount the user is redeeming.

Withdraws the collateral with interest from Ionic and transfer it to user. The initial deposited amount and interest gained is calculated by ABOND amount, collateral backed, cumulative rate for that ABOND and current cumulative rate.

withdrawFromAaveByuser

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

user

address

Address of the user.

aBondAmount

uint128

ABOND amount the user is redeeming.

Withdraws the collateral with interest from Aave and transfer it to user. The initial deposited amount and interest gained is calculated by ABOND amount, collateral backed, cumulative rate for that ABOND and current cumulative rate.

withdrawFromCompoundByuser

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

user

address

Address of the user.

aBondAmount

uint128

ABOND amount the user is redeeming.

Withdraws the collateral with interest from Compound and transfer it to user. The initial deposited amount and interest gained is calculated by ABOND amount, collateral backed, cumulative rate for that ABOND and current cumulative rate.

withdrawFromIonicDuringLiq

function withdrawFromIonicDuringLiq(address user, uint64 index)
Param Name
Type
Description

user

address

Address of the user.

index

uint64

Index of the borrower position which is going to be liquidated.

Withdraws the collateral with interest from Ionic and kept it in treasury. The initial deposited amount and interest gained is calculated by cumulative rate during deposit and current cumulative rate.

withdrawInterest

function withdrawInterest(address toAddress, uint256 amount)
Param Name
Type
Description

toAddress

address

Receiver's address to get interest.

amount

uint256

Interest amount to withdraw.

Withdraws the interest gained in protocol by owner.

transferEthToCdsLiquidators

function transferEthToCdsLiquidators(address borrower, uint128 amount)
Param Name
Type
Description

borrower

address

Address of the CDS user who opted for liquidation to transfer ETH.

amount

uint128

Amount of ETH to transfer.

Gets USDa and Native token from destination chain to this chain treasury.This function can only be called by Borrowing or CDS contracts.

transferFundsToGlobal

function transferFundsToGlobal(
    uint256[4] memory transferAmounts
) external
Param Name
Type
Description

transferAmount

uint256[4]

Array of amounts needs to transfer to global contract in the order of AssetName enum.

Transfers the respective amounts to the global contract.

swapCollateralForUSDT

function swapCollateralForUSDT(
    IBorrowing.AssetName asset,
    uint256 swapAmount,
    bytes memory odosAssembledData
) external
Param Name
Type
Description

asset

Collateral type to swap.

swapAmount

uint256

Amount of collateral to swap.

odosAssembledData

bytes

Odos assembled data got from Odos API for swapping.

Swaps the collateral to USDT.

Setter Functions

setExternalProtocolAddresses

function setExternalProtocolAddresses(
    address ionicWETHAddress,
    address wethAddress,
    address odosRouterV2Address
)
Param Name
Type
Description

ionicWETHAddress

address

ionic WETH contract address.

wethAddress

address

WETH address.

odosRouterV2Address

address

Odos router v2 address.

Sets the respective addresses, only called by owner.

Read Functions

calculateYieldsForExternalProtocol

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

user

address

Address of the user who is redeeming ABOND.

aBondAmount

uint128

Amount of ABOND the user is redeeming.

Returns the yields acquired for that ABOND tokens to the user.

getBorrowing

function getBorrowing(address depositor,uint64 index)
Param Name
Type
Description

depositor

address

Borrower's address.

index

uint64

Index of the borrower.

Returns the borrower's total index and details of that particular index.

getTotalDeposited

function getTotalDeposited(
    address borrower
) external
Param Name
Type
Description

depositor

address

Borrower's address.

Returns the borrower's total deposited amount in ETH value.

getCumulativeRate

function getCumulativeRate(Protocol protocol)

Returns the last stored cumulative rate of the protocol.

getCurrentCumulativeRate

function getCurrentCumulativeRate(
    uint256 _currentExchangeRate, 
    Protocol _protocol
)

Returns the current cumulative rate of the protocol.

getExternalProtocolCumulativeRate

function getExternalProtocolCumulativeRate(bool maximum)

Returns the external protocol cumulative rate. If the param is true, returns the maximum cumulative rate, else vice versa.

Last updated