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.
Name | Type | Description |
---|---|---|
oracleProvider | IOracleProvider | The Oracle Provider contract used for price feed |
interestCalculator | IInterestCalculator | The Interest Calculator contract used for interest calculations |
vault | IChromaticVault | The Chromatic Vault contract responsible for managing liquidity and margin |
clbToken | ICLBToken | The CLB token contract that represents LP ownership in the pool |
market | address | The address of market contract |
settlementToken | address | The address of the settlement token used in the market |
tokenPrecision | uint256 | The precision of the settlement token used in the market |
_currentVersionCache | IOracleProvider.OracleVersion | Cached 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:
Name Type Description self struct LpContext The 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:
Name Type Description self struct LpContext The memory instance of LpContext
structReturn Values:
Name Type Description [0] struct IOracleProvider.OracleVersion OracleVersion 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:
Name Type Description self struct LpContext The memory instance of LpContext
structversion uint256 The requested version number Return Values:
Name Type Description [0] struct IOracleProvider.OracleVersion OracleVersion 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:
Name Type Description self struct LpContext The memory instance of the LpContext
struct.amount uint256 The amount of settlement tokens for which the interest needs to be calculated. from uint256 The starting timestamp of the time range (inclusive). to uint256 The ending timestamp of the time range (exclusive). Return Values:
Name Type Description [0] uint256 The 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:
Name Type Description self struct LpContext The memory instance of the LpContext
struct.oracleVersion uint256 The oracle version to check. Return Values:
Name Type Description [0] bool A boolean value indicating whether the oracle version is in the past.