Skip to content

CalcsSimulatedTime ​

Git Source

this is the exact same code as LiquidityCalcs library, just that it supports a simulated block.timestamp to expose historical calculations.

State Variables ​

EXCHANGE_PRICES_PRECISION ​

constants as from Liquidity variables.sol

solidity
uint256 internal constant EXCHANGE_PRICES_PRECISION = 1e12;

SECONDS_PER_YEAR ​

Ignoring leap years

solidity
uint256 internal constant SECONDS_PER_YEAR = 365 days;

DEFAULT_EXPONENT_SIZE ​

solidity
uint256 internal constant DEFAULT_EXPONENT_SIZE = 8;

DEFAULT_EXPONENT_MASK ​

solidity
uint256 internal constant DEFAULT_EXPONENT_MASK = 0xFF;

FOUR_DECIMALS ​

solidity
uint256 internal constant FOUR_DECIMALS = 1e4;

TWELVE_DECIMALS ​

solidity
uint256 internal constant TWELVE_DECIMALS = 1e12;

X14 ​

solidity
uint256 internal constant X14 = 0x3fff;

X15 ​

solidity
uint256 internal constant X15 = 0x7fff;

X16 ​

solidity
uint256 internal constant X16 = 0xffff;

X18 ​

solidity
uint256 internal constant X18 = 0x3ffff;

X24 ​

solidity
uint256 internal constant X24 = 0xffffff;

X33 ​

solidity
uint256 internal constant X33 = 0x1ffffffff;

X64 ​

solidity
uint256 internal constant X64 = 0xffffffffffffffff;

Functions ​

calcExchangePrices ​

calculates interest (exchange prices) for a token given its' exchangePricesAndConfig from storage.

solidity
function calcExchangePrices(uint256 exchangePricesAndConfig_, uint256 blockTimestamp_)
    internal
    pure
    returns (uint256 supplyExchangePrice_, uint256 borrowExchangePrice_);

Parameters

NameTypeDescription
exchangePricesAndConfig_uint256exchange prices and config packed uint256 read from storage
blockTimestamp_uint256simulated block.timestamp

Returns

NameTypeDescription
supplyExchangePrice_uint256updated supplyExchangePrice
borrowExchangePrice_uint256updated borrowExchangePrice

calcRevenue ​

gets the revenueAmount_ for a token given its' totalAmounts and exchangePricesAndConfig from storage and the current balance of the Fluid liquidity contract for the token.

solidity
function calcRevenue(
    uint256 totalAmounts_,
    uint256 exchangePricesAndConfig_,
    uint256 liquidityTokenBalance_,
    uint256 blockTimestamp_
) internal pure returns (uint256 revenueAmount_);

Parameters

NameTypeDescription
totalAmounts_uint256total amounts packed uint256 read from storage
exchangePricesAndConfig_uint256exchange prices and config packed uint256 read from storage
liquidityTokenBalance_uint256current balance of Liquidity contract (IERC20(token_).balanceOf(address(this)))
blockTimestamp_uint256simulated block.timestamp

Returns

NameTypeDescription
revenueAmount_uint256collectable revenue amount

getTotalSupply ​

reads the total supply out of Liquidity packed storage totalAmounts_ for supplyExchangePrice_

solidity
function getTotalSupply(uint256 totalAmounts_, uint256 supplyExchangePrice_)
    internal
    pure
    returns (uint256 totalSupply_);

getTotalBorrow ​

reads the total borrow out of Liquidity packed storage totalAmounts_ for borrowExchangePrice_

solidity
function getTotalBorrow(uint256 totalAmounts_, uint256 borrowExchangePrice_)
    internal
    pure
    returns (uint256 totalBorrow_);

Errors ​

FluidCalcsSimulatedTimeError ​

solidity
error FluidCalcsSimulatedTimeError(uint256 errorId_);

FluidCalcsSimulatedTimeInvalidTimestamp ​

solidity
error FluidCalcsSimulatedTimeInvalidTimestamp();