Skip to main content

LpContext.sol

LpContext

struct LpContext {
IOracleProvider oracleProvider;
IInterestCalculator interestCalculator;
IChromaticVault vault;
ICLBToken clbToken;
address market;
address settlementToken;
uint256 tokenPrecision;
IOracleProvider.OracleVersion _currentVersionCache;
}

Represents the context information required for LP bin operations.

NameTypeDescription
oracleProviderIOracleProviderThe Oracle Provider contract used for price feed
interestCalculatorIInterestCalculatorThe Interest Calculator contract used for interest calculations
vaultIChromaticVaultThe Chromatic Vault contract responsible for managing liquidity and margin
clbTokenICLBTokenThe CLB token contract that represents LP ownership in the pool
marketaddressThe address of market contract
settlementTokenaddressThe address of the settlement token used in the market
tokenPrecisionuint256The precision of the settlement token used in the market
_currentVersionCacheIOracleProvider.OracleVersionCached instance of the current oracle version

LpContextLib

Provides functions that operate on the LpContext struct

syncOracleVersion

function syncOracleVersion(struct LpContext self) internal

Syncs the oracle version used by the market.

  • Parameters:

    NameTypeDescription
    selfstruct LpContextThe memory instance of LpContext struct

currentOracleVersion

function currentOracleVersion(struct LpContext self) internal view returns (struct IOracleProvider.OracleVersion)

Retrieves the current oracle version used by the market

If the _currentVersionCache has been initialized, then returns it. If not, it calls the currentVersion function on the `oracleProvider of the market to fetch the current version and stores it in the cache, and then returns the current version.

  • Parameters:

    NameTypeDescription
    selfstruct LpContextThe memory instance of LpContext struct
  • Return Values:

    NameTypeDescription
    [0]struct IOracleProvider.OracleVersionOracleVersion The current oracle version

oracleVersionAt

function oracleVersionAt(struct LpContext self, uint256 version) internal view returns (struct IOracleProvider.OracleVersion)

Retrieves the oracle version at a specific version number

If the _currentVersionCache matches the requested version, then returns it. Otherwise, it calls the atVersion function on the oracleProvider of the market to fetch the desired version.

  • Parameters:

    NameTypeDescription
    selfstruct LpContextThe memory instance of LpContext struct
    versionuint256The requested version number
  • Return Values:

    NameTypeDescription
    [0]struct IOracleProvider.OracleVersionOracleVersion The oracle version at the requested version number

calculateInterest

function calculateInterest(struct LpContext self, uint256 amount, uint256 from, uint256 to) internal view returns (uint256)

Calculates the interest accrued for a given amount of settlement tokens within a specified time range.

This function internally calls the calculateInterest function on the interestCalculator contract.

  • Parameters:

    NameTypeDescription
    selfstruct LpContextThe memory instance of the LpContext struct.
    amountuint256The amount of settlement tokens for which the interest needs to be calculated.
    fromuint256The starting timestamp of the time range (inclusive).
    touint256The ending timestamp of the time range (exclusive).
  • Return Values:

    NameTypeDescription
    [0]uint256The accrued interest as a uint256 value.

isPastVersion

function isPastVersion(struct LpContext self, uint256 oracleVersion) internal view returns (bool)

Checks if an oracle version is in the past.

  • Parameters:

    NameTypeDescription
    selfstruct LpContextThe memory instance of the LpContext struct.
    oracleVersionuint256The oracle version to check.
  • Return Values:

    NameTypeDescription
    [0]boolA boolean value indicating whether the oracle version is in the past.