Skip to main content

MarketStateLibrary

Git Source

Title: A Panoptic Market State. Tracks the data of a given CollateralTracker market.

Author: Axicon Labs Limited

State Variables

BORROW_INDEX_MASK

uint256 internal constant BORROW_INDEX_MASK = (1 << 80) - 1

EPOCH_MASK

uint256 internal constant EPOCH_MASK = ((1 << 32) - 1) << 80

TARGET_RATE_MASK

uint256 internal constant TARGET_RATE_MASK = ((1 << 38) - 1) << 112

UNREALIZED_INTEREST_MASK

uint256 internal constant UNREALIZED_INTEREST_MASK =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFC0000000000000000000000000000000000000

Functions

storeMarketState

Create a new MarketState object.

function storeMarketState(
uint256 _borrowIndex,
uint256 _marketEpoch,
uint256 _rateAtTarget,
uint256 _unrealizedInterest
) internal pure returns (MarketState result);

Parameters

NameTypeDescription
_borrowIndexuint256The global index (uint80)
_marketEpochuint256The market's epoch (uint32)
_rateAtTargetuint256The rateAtTarget (uint38)
_unrealizedInterestuint256The unrealized interest (uint106)

Returns

NameTypeDescription
resultMarketStateThe new MarketState object

updateBorrowIndex

Update the Global Borrow Index (Lowest 80 bits)

function updateBorrowIndex(MarketState self, uint80 newIndex) internal pure returns (MarketState result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to update
newIndexuint80The new borrow index value

Returns

NameTypeDescription
resultMarketStateThe updated MarketState with the new borrow index

updateMarketEpoch

Update the Market Epoch (Bits 80-111)

function updateMarketEpoch(MarketState self, uint32 newEpoch) internal pure returns (MarketState result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to update
newEpochuint32The new market epoch value

Returns

NameTypeDescription
resultMarketStateThe updated MarketState with the new market epoch

updateRateAtTarget

Update the Rate At Target (Bits 112-149)

function updateRateAtTarget(MarketState self, uint40 newRate) internal pure returns (MarketState result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to update
newRateuint40The new rate at target value

Returns

NameTypeDescription
resultMarketStateThe updated MarketState with the new rate at target

updateUnrealizedInterest

Update the Unrealized Interest (Bits 150-255)

function updateUnrealizedInterest(MarketState self, uint128 newInterest)
internal
pure
returns (MarketState result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to update
newInterestuint128The new unrealized interest value

Returns

NameTypeDescription
resultMarketStateThe updated MarketState with the new unrealized interest

borrowIndex

Get the borrowIndex of self.

function borrowIndex(MarketState self) internal pure returns (uint80 result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to retrieve the borrowIndex state from

Returns

NameTypeDescription
resultuint80The borrowIndex of self

marketEpoch

Get the marketEpoch of self.

function marketEpoch(MarketState self) internal pure returns (uint32 result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to retrieve the marketEpoch from

Returns

NameTypeDescription
resultuint32The marketEpoch of self

rateAtTarget

Get the rateAtTarget of self.

function rateAtTarget(MarketState self) internal pure returns (uint40 result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to retrieve the rateAtTarget from

Returns

NameTypeDescription
resultuint40The rateAtTarget of self

unrealizedInterest

Get the unrealizedInterest of self.

function unrealizedInterest(MarketState self) internal pure returns (uint128 result);

Parameters

NameTypeDescription
selfMarketStateThe MarketState to retrieve the unrealizedInterest from

Returns

NameTypeDescription
resultuint128The unrealizedInterest of self