Skip to main content

IRiskEngine

Git Source

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

NameTypeDescription
poolPanopticPoolThe PanopticPool to lock.

unlockPool
​

Removes the forced safe-mode lock on a PanopticPool.

function unlockPool(PanopticPool pool) external;

Parameters

NameTypeDescription
poolPanopticPoolThe PanopticPool to unlock.

collect
​

Collects a specific amount of tokens from this contract

function collect(address token, address recipient, uint256 amount) external;

Parameters

NameTypeDescription
tokenaddressThe address of the ERC20 token to collect
recipientaddressThe address to send the tokens to
amountuint256The 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

NameTypeDescription
tokenaddressThe address of the ERC20 token to collect
recipientaddressThe 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

NameTypeDescription
payoraddressThe address of the user being exercised/settled
feesLeftRightSignedIf applicable, fees to debit from caller (rightSlot = currency0 left = currency1), 0 for settleLongPremium
atTickint24The tick at which to convert between currency0/currency1 when redistributing the surplus tokens
ct0CollateralTrackerThe collateral tracker for currency0
ct1CollateralTrackerThe collateral tracker for currency1

Returns

NameTypeDescription
<none>LeftRightSignedThe 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

NameTypeDescription
currentTickint24The current price tick
oracleTickint24The price oracle tick
tokenIdTokenIdThe position to be exercised
positionBalancePositionBalanceThe position data of the position to be exercised

Returns

NameTypeDescription
exerciseFeesLeftRightSignedThe 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

NameTypeDescription
tokenData0LeftRightUnsignedLeftRight encoded word with balance of token0 in the right slot, and required balance in left slot
tokenData1LeftRightUnsignedLeftRight encoded word with balance of token1 in the right slot, and required balance in left slot
atSqrtPriceX96uint160The oracle price used to swap tokens between the liquidator/liquidatee and determine solvency for the liquidatee
netPaidLeftRightSignedThe net amount of tokens paid/received by the liquidatee to close their portfolio of positions
shortPremiumLeftRightUnsignedTotal owed premium (prorated by available settled tokens) across all short legs being liquidated

Returns

NameTypeDescription
<none>LeftRightSignedThe LeftRight-packed bonus amounts to be paid to the liquidator for both tokens
<none>LeftRightSignedThe 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

NameTypeDescription
liquidateeaddressThe address of the user being liquidated
positionIdListTokenId[]The list of position ids being liquidated
premiasByLegLeftRightSigned[4][]The premium paid (or received) by the liquidatee for each leg of each position
collateralRemainingLeftRightSignedThe remaining collateral after the liquidation (negative if protocol loss)
atSqrtPriceX96uint160The oracle price used to swap tokens between the liquidator/liquidatee and determine solvency for the liquidatee

Returns

NameTypeDescription
bonusDeltasLeftRightSignedThe delta, if any, to apply to the existing liquidation bonus
haircutTotalLeftRightUnsignedTotal premium clawed back from the liquidatee
haircutPerLegLeftRightSigned[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

NameTypeDescription
currentTickint24The current tick in the Uniswap pool
_oraclePackOraclePackThe packed s_oraclePack storage slot containing the oracle's state

Returns

NameTypeDescription
spotTickint24The fast oracle tick, sourced from the internal 10-minute EMA
medianTickint24The slow oracle tick, calculated as the median of the 8 stored price points in the internal oracle
latestTickint24The reconstructed absolute tick of the latest observation stored in the internal oracle
oraclePackOraclePackThe 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

NameTypeDescription
oraclePackOraclePackThe packed s_oraclePack storage slot containing the oracle's state

Returns

NameTypeDescription
<none>int24The 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

NameTypeDescription
oraclePackOraclePackThe packed structure representing the sorted 8-slot queue of ticks
currentTickint24The current tick as return from slot0

Returns

NameTypeDescription
medianTickint24The median of the provided 8-slot queue of ticks in oraclePack
updatedOraclePackOraclePackThe 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

NameTypeDescription
currentTickint24The current tick
oraclePackOraclePackThe oracle pack
builderCodeuint256The builder code to determine fee recipient

Returns

NameTypeDescription
<none>RiskParametersRiskParameters 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

NameTypeDescription
currentTickint24The current tick
oraclePackOraclePackThe oracle pack

Returns

NameTypeDescription
safeModeuint8A 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

NameTypeDescription
currentTickint24The current tick
_oraclePackOraclePackThe oracle pack
safeModeuint8A number representing whether the protocol is in Safe Mode.

Returns

NameTypeDescription
atTicksint24[]Array of ticks to check solvency at
oraclePackOraclePackThe 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

NameTypeDescription
positionBalanceArrayPositionBalance[]The list of all open positions held by the optionOwner
positionIdListTokenId[]The list of all option positions held by user
atTickint24The tick at which to evaluate the account's positions
useraddressThe account to check collateral/margin health for
shortPremiaLeftRightUnsignedThe total amount of premium owed to the short legs of user
longPremiaLeftRightUnsignedThe total amount of premium owed by the long legs of user
ct0CollateralTrackerThe Address of the CollateralTracker for token0
ct1CollateralTrackerThe Address of the CollateralTracker for token1
bufferuint256The buffer to apply to the collateral requirement

Returns

NameTypeDescription
<none>boolWhether 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

NameTypeDescription
positionBalanceArrayPositionBalance[]Array of [balanceOrUtilAtMint] for all open positions of user
atTickint24Tick at which exposures are valued
useraddressAccount to evaluate
positionIdListTokenId[]The list of all option positions held by user
shortPremiaLeftRightUnsignedTotal short premia owed to user
longPremiaLeftRightUnsignedTotal long premia owed by user
ct0CollateralTrackerCollateralTracker for token0
ct1CollateralTrackerCollateralTracker for token1

Returns

NameTypeDescription
tokenData0LeftRightUnsignedLeftRightUnsigned for token0 with left = maintenance requirement, right = available balance
tokenData1LeftRightUnsignedLeftRightUnsigned for token1 with left = maintenance requirement, right = available balance
globalUtilizationsPositionBalanceThe 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

NameTypeDescription
utilizationuint256The current pool utilization
interestRateAccumulatorMarketStateThe current state of the interest rate accumulator

Returns

NameTypeDescription
<none>uint128The 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

NameTypeDescription
utilizationuint256The current pool utilization
interestRateAccumulatorMarketStateThe current state of the interest rate accumulator

Returns

NameTypeDescription
<none>uint128The average rate
<none>uint256The 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

NameTypeDescription
tokenaddressThe address of the token collected
recipientaddressThe address receiving the tokens
amountuint256The amount of tokens collected

GuardianSafeModeUpdated
​

Emitted when the guardian updates the enforced safe mode.

event GuardianSafeModeUpdated(bool lockMode);

Parameters

NameTypeDescription
lockModeboolTrue when safe mode is forcibly locked, false when the lock is lifted.