MarketStateLibrary
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
| Name | Type | Description |
|---|---|---|
_borrowIndex | uint256 | The global index (uint80) |
_marketEpoch | uint256 | The market's epoch (uint32) |
_rateAtTarget | uint256 | The rateAtTarget (uint38) |
_unrealizedInterest | uint256 | The unrealized interest (uint106) |
Returns
| Name | Type | Description |
|---|---|---|
result | MarketState | The new MarketState object |
updateBorrowIndexβ
Update the Global Borrow Index (Lowest 80 bits)
function updateBorrowIndex(MarketState self, uint80 newIndex) internal pure returns (MarketState result);
Parameters
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to update |
newIndex | uint80 | The new borrow index value |
Returns
| Name | Type | Description |
|---|---|---|
result | MarketState | The 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
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to update |
newEpoch | uint32 | The new market epoch value |
Returns
| Name | Type | Description |
|---|---|---|
result | MarketState | The 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
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to update |
newRate | uint40 | The new rate at target value |
Returns
| Name | Type | Description |
|---|---|---|
result | MarketState | The 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
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to update |
newInterest | uint128 | The new unrealized interest value |
Returns
| Name | Type | Description |
|---|---|---|
result | MarketState | The updated MarketState with the new unrealized interest |
borrowIndexβ
Get the borrowIndex of self.
function borrowIndex(MarketState self) internal pure returns (uint80 result);
Parameters
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to retrieve the borrowIndex state from |
Returns
| Name | Type | Description |
|---|---|---|
result | uint80 | The borrowIndex of self |
marketEpochβ
Get the marketEpoch of self.
function marketEpoch(MarketState self) internal pure returns (uint32 result);
Parameters
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to retrieve the marketEpoch from |
Returns
| Name | Type | Description |
|---|---|---|
result | uint32 | The marketEpoch of self |
rateAtTargetβ
Get the rateAtTarget of self.
function rateAtTarget(MarketState self) internal pure returns (uint40 result);
Parameters
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to retrieve the rateAtTarget from |
Returns
| Name | Type | Description |
|---|---|---|
result | uint40 | The rateAtTarget of self |
unrealizedInterestβ
Get the unrealizedInterest of self.
function unrealizedInterest(MarketState self) internal pure returns (uint128 result);
Parameters
| Name | Type | Description |
|---|---|---|
self | MarketState | The MarketState to retrieve the unrealizedInterest from |
Returns
| Name | Type | Description |
|---|---|---|
result | uint128 | The unrealizedInterest of self |