Autonomint
Blockchain Docs
Blockchain Docs
  • GETTING STARTED
    • Overview
    • Contracts Overview
  • Core Contracts
    • Borrowing
    • CDS
    • Treasury
    • Options
    • MultiSign
    • BorrowLiquidation
    • GlobalVariables
  • Core Logics
    • Borrowing Logics
    • CDS Logics
    • Treasury Logics
    • Options Logics
    • BorrowLiquidation Logics
  • Deployed Contracts Addresses
Powered by GitBook
On this page
  1. Core Logics

Treasury Logics

Here the logics used in Treasury contract are explained.

PreviousCDS LogicsNextOptions Logics

Last updated 11 months ago

Cumulative rate calculation

Treasury.sol
function _calculateCumulativeRate(uint256 balanceBeforeEvent, Protocol _protocol)
Param Name
Type
Description

balanceBeforeEvent

uint256

Balance of external protocol tokens before deposit or withdraw.

_protocol

enum Protocol

Which external protocol cumulative rate needs to be calculated.

enum Protocol{Aave,Compound}

For the first time deposit, the cumulative rate will be 1.

change = (balanceBeforeEvent - protocolDeposit[_protocol].totalCreditedTokens) / protocolDeposit[_protocol].totalCreditedTokens;
currentCumulativeRate = ((CUMULATIVE_PRECISION + change) * protocolDeposit[_protocol].cumulativeRate);

For further events, calculate the percentage change by dividing the tokens credited between last event and balance before event by total credited tokens till last event.

Then current cumulative rate will be previous cumulative rate multiplied with percentage change plus one.

Reason for adding 1 to percentage change is, converting that into rate.

Functions which are using the above logic

Deposit to Aave.
Deposit to Compound.
Withdraw from Aave.
Withdraw from Compound.