IRiskEngine
Title: Panoptic Risk Engine Interface
Interface for the central risk assessment and solvency calculator for the Panoptic Protocol.
Functionsβ
IRM_MAX_ELAPSED_TIMEβ
Constant, in seconds, used to determine the max elapsed time between adaptive interest rate updates.
function IRM_MAX_ELAPSED_TIME() external view returns (int256);
CURVE_STEEPNESSβ
Curve steepness (scaled by WAD).
function CURVE_STEEPNESS() external view returns (int256);
MIN_RATE_AT_TARGETβ
Minimum rate at target per second (scaled by WAD).
function MIN_RATE_AT_TARGET() external view returns (int256);
MAX_RATE_AT_TARGETβ
Maximum rate at target per second (scaled by WAD).
function MAX_RATE_AT_TARGET() external view returns (int256);
TARGET_UTILIZATIONβ
Target utilization (scaled by WAD).
function TARGET_UTILIZATION() external view returns (int256);
INITIAL_RATE_AT_TARGETβ
Initial rate at target per second (scaled by WAD).
function INITIAL_RATE_AT_TARGET() external view returns (int256);
ADJUSTMENT_SPEEDβ
Adjustment speed per second (scaled by WAD).
function ADJUSTMENT_SPEED() external view returns (int256);
GUARDIANβ
Address allowed to override the automatically computed safe mode.
function GUARDIAN() external view returns (address);
lockPoolβ
Forces a PanopticPool into locked safe mode.
function lockPool(PanopticPool pool) external;
Parameters
| Name | Type | Description |
|---|---|---|
pool | PanopticPool | The PanopticPool to lock. |
unlockPoolβ
Removes the forced safe-mode lock on a PanopticPool.
function unlockPool(PanopticPool pool) external;
Parameters
| Name | Type | Description |
|---|---|---|
pool | PanopticPool | The PanopticPool to unlock. |
collectβ
Collects a specific amount of tokens from this contract
function collect(address token, address recipient, uint256 amount) external;
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the ERC20 token to collect |
recipient | address | The address to send the tokens to |
amount | uint256 | The amount of tokens to collect |
collectβ
Collects all available tokens of a specific type from this contract
function collect(address token, address recipient) external;
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the ERC20 token to collect |
recipient | address | The address to send the tokens to |
getRefundAmountsβ
Substitutes surplus tokens to a caller in exchange for any potential token shortages prior to revoking virtual shares from a payor.
function getRefundAmounts(
address payor,
LeftRightSigned fees,
int24 atTick,
CollateralTracker ct0,
CollateralTracker ct1
) external view returns (LeftRightSigned);
Parameters
| Name | Type | Description |
|---|---|---|
payor | address | The address of the user being exercised/settled |
fees | LeftRightSigned | If applicable, fees to debit from caller (rightSlot = currency0 left = currency1), 0 for settleLongPremium |
atTick | int24 | The tick at which to convert between currency0/currency1 when redistributing the surplus tokens |
ct0 | CollateralTracker | The collateral tracker for currency0 |
ct1 | CollateralTracker | The collateral tracker for currency1 |
Returns
| Name | Type | Description |
|---|---|---|
<none> | LeftRightSigned | The LeftRight-packed deltas for currency0/currency1 to move from the caller to the payor |
exerciseCostβ
Get the cost of exercising an option. Used during a forced exercise.
function exerciseCost(int24 currentTick, int24 oracleTick, TokenId tokenId, PositionBalance positionBalance)
external
view
returns (LeftRightSigned exerciseFees);
Parameters
| Name | Type | Description |
|---|---|---|
currentTick | int24 | The current price tick |
oracleTick | int24 | The price oracle tick |
tokenId | TokenId | The position to be exercised |
positionBalance | PositionBalance | The position data of the position to be exercised |
Returns
| Name | Type | Description |
|---|---|---|
exerciseFees | LeftRightSigned | The fees for exercising the option position |
getLiquidationBonusβ
Compute the pre-haircut liquidation bonuses to be paid to the liquidator and the protocol loss caused by the liquidation (pre-haircut).
function getLiquidationBonus(
LeftRightUnsigned tokenData0,
LeftRightUnsigned tokenData1,
uint160 atSqrtPriceX96,
LeftRightSigned netPaid,
LeftRightUnsigned shortPremium
) external pure returns (LeftRightSigned, LeftRightSigned);
Parameters
| Name | Type | Description |
|---|---|---|
tokenData0 | LeftRightUnsigned | LeftRight encoded word with balance of token0 in the right slot, and required balance in left slot |
tokenData1 | LeftRightUnsigned | LeftRight encoded word with balance of token1 in the right slot, and required balance in left slot |
atSqrtPriceX96 | uint160 | The oracle price used to swap tokens between the liquidator/liquidatee and determine solvency for the liquidatee |
netPaid | LeftRightSigned | The net amount of tokens paid/received by the liquidatee to close their portfolio of positions |
shortPremium | LeftRightUnsigned | Total owed premium (prorated by available settled tokens) across all short legs being liquidated |
Returns
| Name | Type | Description |
|---|---|---|
<none> | LeftRightSigned | The LeftRight-packed bonus amounts to be paid to the liquidator for both tokens |
<none> | LeftRightSigned | The LeftRight-packed protocol loss (pre-haircut) for both tokens |
haircutPremiaβ
Haircut/clawback any premium paid by liquidatee on positionIdList over the protocol loss threshold during a liquidation.
function haircutPremia(
address liquidatee,
TokenId[] memory positionIdList,
LeftRightSigned[4][] memory premiasByLeg,
LeftRightSigned collateralRemaining,
uint160 atSqrtPriceX96
)
external
returns (LeftRightSigned bonusDeltas, LeftRightUnsigned haircutTotal, LeftRightSigned[4][] memory haircutPerLeg);
Parameters
| Name | Type | Description |
|---|---|---|
liquidatee | address | The address of the user being liquidated |
positionIdList | TokenId[] | The list of position ids being liquidated |
premiasByLeg | LeftRightSigned[4][] | The premium paid (or received) by the liquidatee for each leg of each position |
collateralRemaining | LeftRightSigned | The remaining collateral after the liquidation (negative if protocol loss) |
atSqrtPriceX96 | uint160 | The oracle price used to swap tokens between the liquidator/liquidatee and determine solvency for the liquidatee |
Returns
| Name | Type | Description |
|---|---|---|
bonusDeltas | LeftRightSigned | The delta, if any, to apply to the existing liquidation bonus |
haircutTotal | LeftRightUnsigned | Total premium clawed back from the liquidatee |
haircutPerLeg | LeftRightSigned[4][] | Per-position/per-leg haircut amounts |
getOracleTicksβ
Computes and returns all oracle ticks.
function getOracleTicks(int24 currentTick, OraclePack _oraclePack)
external
view
returns (int24 spotTick, int24 medianTick, int24 latestTick, OraclePack oraclePack);
Parameters
| Name | Type | Description |
|---|---|---|
currentTick | int24 | The current tick in the Uniswap pool |
_oraclePack | OraclePack | The packed s_oraclePack storage slot containing the oracle's state |
Returns
| Name | Type | Description |
|---|---|---|
spotTick | int24 | The fast oracle tick, sourced from the internal 10-minute EMA |
medianTick | int24 | The slow oracle tick, calculated as the median of the 8 stored price points in the internal oracle |
latestTick | int24 | The reconstructed absolute tick of the latest observation stored in the internal oracle |
oraclePack | OraclePack | The current value of the 8-slot internal observation queue |
twapEMAβ
Calculates a slow-moving, weighted average price from the on-chain EMAs.
function twapEMA(OraclePack oraclePack) external pure returns (int24);
Parameters
| Name | Type | Description |
|---|---|---|
oraclePack | OraclePack | The packed s_oraclePack storage slot containing the oracle's state |
Returns
| Name | Type | Description |
|---|---|---|
<none> | int24 | The blended time-weighted average price, represented as an int24 tick |
computeInternalMedianβ
Takes a packed structure representing a sorted 8-slot queue of ticks and returns the median of those values and an updated queue if another observation is warranted.
function computeInternalMedian(OraclePack oraclePack, int24 currentTick)
external
view
returns (int24 medianTick, OraclePack updatedOraclePack);
Parameters
| Name | Type | Description |
|---|---|---|
oraclePack | OraclePack | The packed structure representing the sorted 8-slot queue of ticks |
currentTick | int24 | The current tick as return from slot0 |
Returns
| Name | Type | Description |
|---|---|---|
medianTick | int24 | The median of the provided 8-slot queue of ticks in oraclePack |
updatedOraclePack | OraclePack | The updated 8-slot queue of ticks with the latest observation inserted if the last entry is at least period seconds old |
getRiskParametersβ
Returns the risk parameters including safe mode status and fee recipients.
function getRiskParameters(int24 currentTick, OraclePack oraclePack, uint256 builderCode)
external
view
returns (RiskParameters);
Parameters
| Name | Type | Description |
|---|---|---|
currentTick | int24 | The current tick |
oraclePack | OraclePack | The oracle pack |
builderCode | uint256 | The builder code to determine fee recipient |
Returns
| Name | Type | Description |
|---|---|---|
<none> | RiskParameters | RiskParameters The packed risk parameters |
getFeeRecipientβ
computes the fee recipient address based on builder code and salt.
function getFeeRecipient(uint256 builderCode) external view returns (address);
isSafeModeβ
Checks for significant oracle deviation to determine if Safe Mode should be active.
function isSafeMode(int24 currentTick, OraclePack oraclePack) external pure returns (uint8 safeMode);
Parameters
| Name | Type | Description |
|---|---|---|
currentTick | int24 | The current tick |
oraclePack | OraclePack | The oracle pack |
Returns
| Name | Type | Description |
|---|---|---|
safeMode | uint8 | A number representing whether the protocol is in Safe Mode |
getSolvencyTicksβ
Determines which ticks to check for solvency based on market volatility.
function getSolvencyTicks(int24 currentTick, OraclePack _oraclePack, uint8 safeMode)
external
view
returns (int24[] memory atTicks, OraclePack oraclePack);
Parameters
| Name | Type | Description |
|---|---|---|
currentTick | int24 | The current tick |
_oraclePack | OraclePack | The oracle pack |
safeMode | uint8 | A number representing whether the protocol is in Safe Mode. |
Returns
| Name | Type | Description |
|---|---|---|
atTicks | int24[] | Array of ticks to check solvency at |
oraclePack | OraclePack | The oracle pack (potentially updated) |
isAccountSolventβ
Get the collateral status/margin details of an account/user.
function isAccountSolvent(
PositionBalance[] calldata positionBalanceArray,
TokenId[] calldata positionIdList,
int24 atTick,
address user,
LeftRightUnsigned shortPremia,
LeftRightUnsigned longPremia,
CollateralTracker ct0,
CollateralTracker ct1,
uint256 buffer
) external view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
positionBalanceArray | PositionBalance[] | The list of all open positions held by the optionOwner |
positionIdList | TokenId[] | The list of all option positions held by user |
atTick | int24 | The tick at which to evaluate the account's positions |
user | address | The account to check collateral/margin health for |
shortPremia | LeftRightUnsigned | The total amount of premium owed to the short legs of user |
longPremia | LeftRightUnsigned | The total amount of premium owed by the long legs of user |
ct0 | CollateralTracker | The Address of the CollateralTracker for token0 |
ct1 | CollateralTracker | The Address of the CollateralTracker for token1 |
buffer | uint256 | The buffer to apply to the collateral requirement |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether the account is solvent at the given tick |
getMarginβ
Compute margin inputs for a user at a given tick.
function getMargin(
PositionBalance[] calldata positionBalanceArray,
int24 atTick,
address user,
TokenId[] calldata positionIdList,
LeftRightUnsigned shortPremia,
LeftRightUnsigned longPremia,
CollateralTracker ct0,
CollateralTracker ct1
)
external
view
returns (LeftRightUnsigned tokenData0, LeftRightUnsigned tokenData1, PositionBalance globalUtilizations);
Parameters
| Name | Type | Description |
|---|---|---|
positionBalanceArray | PositionBalance[] | Array of [balanceOrUtilAtMint] for all open positions of user |
atTick | int24 | Tick at which exposures are valued |
user | address | Account to evaluate |
positionIdList | TokenId[] | The list of all option positions held by user |
shortPremia | LeftRightUnsigned | Total short premia owed to user |
longPremia | LeftRightUnsigned | Total long premia owed by user |
ct0 | CollateralTracker | CollateralTracker for token0 |
ct1 | CollateralTracker | CollateralTracker for token1 |
Returns
| Name | Type | Description |
|---|---|---|
tokenData0 | LeftRightUnsigned | LeftRightUnsigned for token0 with left = maintenance requirement, right = available balance |
tokenData1 | LeftRightUnsigned | LeftRightUnsigned for token1 with left = maintenance requirement, right = available balance |
globalUtilizations | PositionBalance | The max utilizations encountered in the position set |
interestRateβ
Calculates the interest rate based on utilization and accumulator state.
function interestRate(uint256 utilization, MarketState interestRateAccumulator) external view returns (uint128);
Parameters
| Name | Type | Description |
|---|---|---|
utilization | uint256 | The current pool utilization |
interestRateAccumulator | MarketState | The current state of the interest rate accumulator |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint128 | The calculated interest rate |
updateInterestRateβ
Calculates the interest rate and the new rate at target.
function updateInterestRate(uint256 utilization, MarketState interestRateAccumulator)
external
view
returns (uint128, uint256);
Parameters
| Name | Type | Description |
|---|---|---|
utilization | uint256 | The current pool utilization |
interestRateAccumulator | MarketState | The current state of the interest rate accumulator |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint128 | The average rate |
<none> | uint256 | The new rate at target |
vegoidβ
Returns the stored VEGOID parameter
function vegoid() external view returns (uint8);
Eventsβ
BorrowRateUpdatedβ
Emitted when a borrow rate is updated.
event BorrowRateUpdated(address indexed collateralToken, uint256 avgBorrowRate, uint256 rateAtTarget);
TokensCollectedβ
Emitted when tokens are collected from the contract
event TokensCollected(address indexed token, address indexed recipient, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token collected |
recipient | address | The address receiving the tokens |
amount | uint256 | The amount of tokens collected |
GuardianSafeModeUpdatedβ
Emitted when the guardian updates the enforced safe mode.
event GuardianSafeModeUpdated(bool lockMode);
Parameters
| Name | Type | Description |
|---|---|---|
lockMode | bool | True when safe mode is forcibly locked, false when the lock is lifted. |