CollateralTracker
Inherits: Clone, ERC20Minimal, Multicall, TransientReentrancyGuard
Title: Collateral Tracking System / Margin Accounting used in conjunction with a Panoptic Pool.
Author: Axicon Labs Limited
Tracks collateral of users which is key to ensure the correct level of collateralization is achieved. This is represented as an ERC20 share token. A Panoptic pool has 2 tokens, each issued by its own instance of a CollateralTracker. All math within this contract pertains to a single token.
This contract uses the ERC4626 standard allowing the minting and burning of "shares" (represented using ERC20 inheritance) in exchange for underlying "assets". Panoptic uses a collateral tracking system that is similar to TradFi margin accounts. While users can borrow and effectively control funds several times larger than the collateral they deposited, they cannot withdraw those funds from the Panoptic-Uniswap ecosystem. All funds are always owned by the Panoptic protocol, but users will:
1) collect any fees generated by selling an option.
2) get any gain in capital that results from buying an option that becomes in-the-money.
State Variablesβ
TICKER_PREFIXβ
Prefix for the token symbol (i.e. poUSDC).
string internal constant TICKER_PREFIX = "po"
NAME_PREFIXβ
Prefix for the token name (i.e POPT-V1 USDC LP on ETH/USDC 30bps).
string internal constant NAME_PREFIX = "POPT-V1"
DECIMALSβ
Decimals for computation (1 bps (1 basis point) precision: 0.01%).
uint type for composability with unsigned integer based mathematical operations.
uint256 internal constant DECIMALS = 10_000
WADβ
Decimals for WAD calculations.
uint256 internal constant WAD = 1e18
TARGET_RATE_MASKβ
Mask zero the value between bits 112 and 150);
uint256 internal constant TARGET_RATE_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFC000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF
DONOT_SKIP_INTERESTβ
bool internal constant DONOT_SKIP_INTEREST = false
SKIP_INTERESTβ
bool internal constant SKIP_INTEREST = true
UTILIZATION_TRANSIENT_SLOTβ
Transient storage slot for the utilization
bytes32 internal constant UTILIZATION_TRANSIENT_SLOT = keccak256("panoptic.utilization.snapshot")
s_depositedAssetsβ
Cached amount of assets accounted to be held by the Panoptic Pool β ignores donations, pending fee payouts, and other untracked balance changes.
uint128 internal s_depositedAssets
s_assetsInAMMβ
Amount of assets moved from the Panoptic Pool to the AMM.
uint128 internal s_assetsInAMM
s_creditedSharesβ
Amount of shares credited to the protocol, includes credits and purchased option liquidity above the rehypothecation threshold.
uint256 internal s_creditedShares
s_initializedβ
Boolean which tracks whether this CollateralTracker has been initialized.
bool internal s_initialized
s_marketStateβ
How the Borrow Index Works The borrow index is a global accumulator that tracks how much $1 of debt grows over time with compound interest. It starts at 1e18 (representing 1.0) and increases continuously. Example:
- User borrows 100 tokens when globalIndex = 1.0e18
- Time passes, globalIndex grows to 1.2e18 (20% growth)
- User now owes: 100 * (1.2e18 / 1.0e18) = 120 tokens Each user stores their "checkpoint" index from their last interaction, allowing efficient compound interest calculation without iteration.
Global interest rate accumulator packed into a single 256-bit value
Layout:
- Left slot (106 bits): Accumulated unrealized interest that hasn't been distributed (max deposit is 2**104)
- Next 38 bits: the rateAtTarget value in WAD (2**38 = 800% interest rate)
- Next lowest 32 bits: Last interaction epoch (1 epoch = block.timestamp/4)
- Lowest 80 bits: Global borrow index in WAD (starts at 1e18). 2*80 = 1.75 years at 800% interest The borrow index tracks the compound growth factor since protocol inception. A user's current debt = originalDebt (currentBorrowIndex / userBorrowIndexSnapshot)
MarketState internal s_marketState
s_interestStateβ
Tracks each user's borrowing state and last interaction checkpoint
Packed layout:
- Left slot (128 bits): Net borrows = netShorts - netLongs Represents the user's net borrowed amount in tokens Can be negative, in which case they purchased more options than they sold
- Right slot (128 bits): User's borrow index snapshot The global borrow index value when this user last accrued interest
Interest calculation: interestOwed = netBorrows * (currentIndex - userIndex) / userIndex
mapping(address account => LeftRightSigned interestState) internal s_interestState
COMMISSION_FEEβ
The commission fee, in basis points, collected from PLPs at option mint.
In Panoptic, options never expire, commissions are only paid when a new position is minted.
We believe that this will eliminate the impact of the commission fee on the user's decision-making process when closing a position.
uint256 immutable COMMISSION_FEE
Functionsβ
panopticPoolβ
Retrieve the Panoptic Pool that this collateral token belongs to.
function panopticPool() public pure returns (PanopticPool);
Returns
| Name | Type | Description |
|---|---|---|
<none> | PanopticPool | The Panoptic Pool associated with this collateral token |
underlyingIsToken0β
Retrieve a boolean indicating whether the underlying token is token0 or token1 in the Uniswap V3 pool.
function underlyingIsToken0() public pure returns (bool _underlyingIsToken0);
Returns
| Name | Type | Description |
|---|---|---|
_underlyingIsToken0 | bool | True if the underlying token is token0, false if it is token1 |
underlyingTokenβ
Retrieve the address of the underlying token.
function underlyingToken() public pure returns (address);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address | The address of the underlying token |
token0β
Retrieve the address of token0 in the Uniswap V3 pool.
function token0() public pure returns (address);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address | The address of token0 in the Uniswap V3 pool |
token1β
Retrieve the address of token1 in the Uniswap V3 pool.
function token1() public pure returns (address);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address | The address of token1 in the Uniswap V3 pool |
riskEngineβ
Retrieve the RiskEngine associated with that CollateralTracker.
function riskEngine() public pure returns (IRiskEngine);
Returns
| Name | Type | Description |
|---|---|---|
<none> | IRiskEngine | The RiskEngine instance associated with that CollateralTracker's uniswap pool |
poolManagerβ
Retrieve the PoolManager associated with that CollateralTracker.
stored as zero if not a Uniswap v4 pool
function poolManager() public pure returns (IPoolManager);
Returns
| Name | Type | Description |
|---|---|---|
<none> | IPoolManager | The PoolManager instance associated with that CollateralTracker's uniswap V4 pool |
poolFeeβ
Retrieve the fee of the Uniswap V3 pool.
function poolFee() public pure returns (uint24 _poolFee);
Returns
| Name | Type | Description |
|---|---|---|
_poolFee | uint24 | The fee of the Uniswap V3 pool |
onlyPanopticPoolβ
Reverts if the associated Panoptic Pool is not the caller.
modifier onlyPanopticPool() ;
_onlyPanopticPoolβ
function _onlyPanopticPool() internal view;
constructorβ
Set immutable parameters for the Collateral Tracker.
constructor(uint256 _commissionFee) ;
Parameters
| Name | Type | Description |
|---|---|---|
_commissionFee | uint256 | The commission fee, in basis points, collected from PLPs at option mint |
initializeβ
Initializes a new CollateralTracker instance with 1 virtual asset and 10^6 virtual shares. Can only be called once; reverts if already initialized.
function initialize() external;
getPoolDataβ
Get information about the utilization of this collateral vault.
function getPoolData()
external
view
returns (uint256 depositedAssets, uint256 insideAMM, uint256 creditedShares, uint256 currentPoolUtilization);
Returns
| Name | Type | Description |
|---|---|---|
depositedAssets | uint256 | Cached amount of assets accounted to be held by the Panoptic Pool β ignores donations, pending fee payouts, and other untracked balance changes |
insideAMM | uint256 | The underlying token amount held in the AMM |
creditedShares | uint256 | The amount of shares currently held as credit |
currentPoolUtilization | uint256 | The pool utilization defined ass_assetsInAMM * 10_000 / totalAssets(), where totalAssets is the total tracked assets in the AMM and PanopticPool minus fees and donations to the Panoptic pool |
borrowIndexβ
Returns the global borrow index that tracks compound interest growth
The index starts at 1e18 and compounds continuously. Represents how much 1 unit of debt has grown since inception
function borrowIndex() external view returns (uint80);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint80 | The current global borrow index in WAD (18 decimals) |
lastInteractionTimestampβ
Returns the last time at which interest rates were compounded.
function lastInteractionTimestamp() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The last time at which the interest rates were compounded |
unrealizedGlobalInterestβ
Returns the accumulated unrealized global interest
function unrealizedGlobalInterest() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total interest that has accumulated but not yet been distributed to lenders |
rateAtTargetβ
Returns rateAtTarget of the market
function rateAtTarget() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The rateAtTarget |
interestStateβ
Returns the borrowing state for a specific user
Returns both the user's borrow index snapshot and their net borrowed amount
function interestState(address user) external view returns (int128 userBorrowIndex, int128 netBorrows);
Returns
| Name | Type | Description |
|---|---|---|
userBorrowIndex | int128 | The borrow index when the user last accrued interest (used as the basis for interest calculation) |
netBorrows | int128 | The net borrowed amount for the user (positive = borrower, zero/negative = no interest owed) |
nameβ
Returns name of token composed of underlying token symbol and pool data.
function name() external view returns (string memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | string | The name of the token |
symbolβ
Returns symbol as prefixed symbol of underlying token.
function symbol() external view returns (string memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | string | The symbol of the token |
decimalsβ
Returns decimals of underlying token (0 if not present).
function decimals() external view returns (uint8);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint8 | The decimals of the token |
transferβ
See IERC20-transfer.
Requirements:
- the caller must have a balance of at least
amount. - the caller must not have any open positions on the Panoptic Pool.
function transfer(address recipient, uint256 amount) public override(ERC20Minimal) nonReentrant returns (bool);
transferFromβ
See IERC20-transferFrom.
Requirements:
- the
frommust have a balance of at leastamount. - the caller must have allowance for
fromof at leastamounttokens. frommust not have any open positions on the Panoptic Pool.
function transferFrom(address from, address to, uint256 amount)
public
override(ERC20Minimal)
nonReentrant
returns (bool);
_settleCurrencyDeltaβ
Initiates the unlock callback to wrap/unwrap delta amount of the underlying asset and transfer to/from the Panoptic Pool.
function _settleCurrencyDelta(address account, int256 delta) internal;
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The address of the account to transfer the underlying asset to/from |
delta | int256 | The amount of the underlying asset to wrap/unwrap and transfer |
unlockCallbackβ
Uniswap V4 unlock callback implementation.
Parameters are (address account, int256 delta, uint256 valueOrigin).
Wraps/unwraps delta amount of the underlying asset and transfers to/from the Panoptic Pool.
function unlockCallback(bytes calldata data) external returns (bytes memory);
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | The encoded data containing the account, delta, and valueOrigin |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes | This function returns no data |
assetβ
Get the token contract address of the underlying asset being managed.
function asset() external pure returns (address assetTokenAddress);
Returns
| Name | Type | Description |
|---|---|---|
assetTokenAddress | address | The address of the underlying asset |
totalAssetsβ
Get the total amount of assets managed by the CollateralTracker vault.
This returns the total tracked assets in the AMM and PanopticPool,
EXCLUDING the amount of collected fees (because they are reserved for short options)
EXCLUDING any donations that have been made to the pool
function totalAssets() public view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total amount of assets managed by the CollateralTracker vault |
totalSupplyβ
Returns the total supply of shares including credited shares
function totalSupply() public view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total supply of shares (internal supply + credited shares) |
convertToSharesβ
Returns the amount of shares that can be minted for the given amount of assets.
function convertToShares(uint256 assets) public view returns (uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets to be deposited |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares that can be minted |
convertToAssetsβ
Returns the amount of assets that can be redeemed for the given amount of shares.
function convertToAssets(uint256 shares) public view returns (uint256 assets);
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares to be redeemed |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets that can be redeemed |
assetsOfβ
Returns the amount of assets that can be redeem by the user.
function assetsOf(address owner) external view returns (uint256 assets);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | The redeeming address |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets that can be redeemed |
maxDepositβ
Returns the maximum deposit amount.
function maxDeposit(address) external pure returns (uint256 maxAssets);
Returns
| Name | Type | Description |
|---|---|---|
maxAssets | uint256 | The maximum amount of assets that can be deposited |
previewDepositβ
Returns shares received for depositing given amount of assets.
function previewDeposit(uint256 assets) public view returns (uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets to be deposited |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares that can be minted |
depositβ
Deposit underlying tokens (assets) to the Panoptic pool from the LP and mint corresponding amount of shares.
There is a maximum asset deposit limit of 2^104 - 1.
Shares are minted and sent to the LP (receiver).
function deposit(uint256 assets, address receiver) external payable nonReentrant returns (uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | Amount of assets deposited |
receiver | address | User to receive the shares |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of Panoptic pool shares that were minted to the recipient |
maxMintβ
Returns the maximum shares received for a deposit.
function maxMint(address) external view returns (uint256 maxShares);
Returns
| Name | Type | Description |
|---|---|---|
maxShares | uint256 | The maximum amount of shares that can be minted |
previewMintβ
Returns the amount of assets that would be deposited to mint a given amount of shares.
function previewMint(uint256 shares) public view returns (uint256 assets);
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares to be minted |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets required to mint shares |
mintβ
Deposit required amount of assets to receive specified amount of shares.
There is a maximum asset deposit limit of 2^104 - 1.
Shares are minted and sent to the LP (receiver).
function mint(uint256 shares, address receiver) external payable nonReentrant returns (uint256 assets);
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | Amount of shares to be minted |
receiver | address | User to receive the shares |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets deposited to mint the desired amount of shares |
maxWithdrawβ
Returns The maximum amount of assets that can be withdrawn for a given user. If the user has any open positions, the max withdrawable balance is zero.
Calculated from the balance of the user; limited by the assets the pool has available.
function maxWithdraw(address owner) public view returns (uint256 maxAssets);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | The address being withdrawn for |
Returns
| Name | Type | Description |
|---|---|---|
maxAssets | uint256 | The maximum amount of assets that can be withdrawn |
_maxWithdrawWithPositionsβ
Returns The maximum amount of assets that can be withdrawn for a given user with open positions. If the user has any open positions, the max withdrawable balance is zero.
Calculated from the balance of the user; limited by the assets the pool has available.
function _maxWithdrawWithPositions(address owner) internal view returns (uint256 maxAssets);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | The address being withdrawn for |
Returns
| Name | Type | Description |
|---|---|---|
maxAssets | uint256 | The maximum amount of assets that can be withdrawn |
previewWithdrawβ
Returns the amount of shares that would be burned to withdraw a given amount of assets.
function previewWithdraw(uint256 assets) public view returns (uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets to be withdrawn |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares that would be burned |
withdrawβ
Redeem the amount of shares required to withdraw the specified amount of assets.
We can only use this standard 4626 function if the user has no open positions.
Shares are burned and assets are sent to the LP (receiver).
function withdraw(uint256 assets, address receiver, address owner) external nonReentrant returns (uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | Amount of assets to be withdrawn |
receiver | address | User to receive the assets |
owner | address | User to burn the shares from |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares burned to withdraw the desired amount of assets |
withdrawβ
Redeem the amount of shares required to withdraw the specified amount of assets.
Reverts if the account is not solvent with the given positionIdList.
Shares are burned and assets are sent to the LP (receiver).
function withdraw(
uint256 assets,
address receiver,
address owner,
TokenId[] calldata positionIdList,
bool usePremiaAsCollateral
) external nonReentrant returns (uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | Amount of assets to be withdrawn |
receiver | address | User to receive the assets |
owner | address | User to burn the shares from |
positionIdList | TokenId[] | The list of all option positions held by owner |
usePremiaAsCollateral | bool | Whether to compute accumulated premia for all legs held by the user for collateral (true), or just owed premia for long legs (false) |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares burned to withdraw the desired amount of assets |
maxRedeemβ
Returns the maximum amount of shares that can be redeemed for a given user.
If the user has any open positions, the max redeemable balance is zero.
function maxRedeem(address owner) public view returns (uint256 maxShares);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | The redeeming address |
Returns
| Name | Type | Description |
|---|---|---|
maxShares | uint256 | The maximum amount of shares that can be redeemed by owner |
previewRedeemβ
Returns the amount of assets resulting from a given amount of shares being redeemed.
function previewRedeem(uint256 shares) public view returns (uint256 assets);
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares to be redeemed |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets resulting from the redemption |
redeemβ
Redeem exact shares for underlying assets.
We can only use this standard 4626 function if the user has no open positions.
function redeem(uint256 shares, address receiver, address owner) external nonReentrant returns (uint256 assets);
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | Amount of shares to be redeemed |
receiver | address | User to receive the assets |
owner | address | User to burn the shares from |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets resulting from the redemption |
donateβ
Donate exact shares to all shareholders.
Can only be used when the user has no open positions
function donate(uint256 shares) external nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | Amount of shares to be donated |
accrueInterestβ
Accrues protocol-wide interest for the calling user
Updates global interest state and settles any outstanding interest for msg.sender
function accrueInterest() external nonReentrant;
_accrueInterestβ
Accrues protocol-wide interest and settles a specific user's interest.
This function should be called before any user action that affects their borrow balance.
function _accrueInterest(address owner, bool skipInterest) internal;
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | the account which calls accrue interest |
skipInterest | bool |
_calculateCurrentInterestStateβ
Calculates the current interest state without modifying storage
Simulates interest accrual from last interaction to current epoch
function _calculateCurrentInterestState(uint128 _assetsInAMM, uint128 interestRateSnapshot)
internal
view
returns (uint128 currentBorrowIndex, uint128 _unrealizedGlobalInterest, uint256 currentEpoch);
Parameters
| Name | Type | Description |
|---|---|---|
_assetsInAMM | uint128 | Amount of assets currently deployed in AMM positions |
interestRateSnapshot | uint128 | The current interest rate to evaluate at |
Returns
| Name | Type | Description |
|---|---|---|
currentBorrowIndex | uint128 | Updated global borrow index after simulated accrual |
_unrealizedGlobalInterest | uint128 | Total unrealized interest including new accrual |
currentEpoch | uint256 | Current epoch = block timestamp / 4 |
_interestRateViewβ
function _interestRateView(uint256 utilization) internal view returns (uint128);
interestRateβ
Returns the current interest rate per second based on pool utilization
function interestRate() public view returns (uint128);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint128 | The current interest rate per second in WAD (18 decimal precision) |
_updateInterestRateβ
Returns the interest rate per second based on pool utilization
uses the maximum utilization during this transaction, users to prevent flash deposits from lowering the interest rate
function _updateInterestRate() internal returns (uint128);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint128 | The interest rate per second in 18 decimal precision |
_getUserInterestβ
Calculates interest owed by a user based on their borrow state
Uses the difference between current and user's last borrow index to compute compound interest
function _getUserInterest(LeftRightSigned userState, uint256 currentBorrowIndex)
internal
pure
returns (uint128 interestOwed);
Parameters
| Name | Type | Description |
|---|---|---|
userState | LeftRightSigned | Packed state containing user's net borrows (left slot) and last borrow index (right slot) |
currentBorrowIndex | uint256 | The current global borrow index |
Returns
| Name | Type | Description |
|---|---|---|
interestOwed | uint128 | Amount of interest the user owes, returns 0 if user is a lender or indices match |
owedInterestβ
Returns the current interest owed by a specific user in assets
function owedInterest(address owner) external view returns (uint128);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | Address of the user to check |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint128 | The amount of interest currently owed by the user in assets |
assetsAndInterestβ
Returns the assets and interest owed for a specific user
function assetsAndInterest(address owner) external view returns (uint256, uint256);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | Address of the user to check |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The amount of assets owned by the user (in token units) |
<none> | uint256 | The amount of interest currently owed by the user (in token units) |
_owedInterestβ
Internal function to calculate interest owed by a user
Retrieves user state and current borrow index from storage
function _owedInterest(address owner) internal view returns (uint128);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | Address of the user to check |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint128 | Amount of interest owed based on last compounded index |
_calculateCurrentBorrowIndexβ
Calculates the current borrow index including uncompounded time
Simulates interest accrual up to the current block epoch
function _calculateCurrentBorrowIndex() internal view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The borrow index as if interest was compounded at current epoch |
previewOwedInterestβ
Previews the interest that would be owed if compounded now
Simulates interest accrual without modifying state
function previewOwedInterest(address owner) external view returns (uint128);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | Address of the user to preview interest for |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint128 | The amount of interest that would be owed if accrued at current epoch |
_poolUtilizationβ
Get the pool utilization defined by the ratio of assets in the AMM to total assets.
calling this function will also store the utilization in the UTILIZATION_TRANSIENT_SLOT as DECIMALS if the current one is higher than the one already stored. This ensures that flash deposits can't lower the utilization for a single tx
function _poolUtilization() internal returns (uint256 poolUtilization);
Returns
| Name | Type | Description |
|---|---|---|
poolUtilization | uint256 | The pool utilization in basis points |
_poolUtilizationViewβ
Get the pool utilization defined by the ratio of assets in the AMM to total assets.
function _poolUtilizationView() internal view returns (uint256 poolUtilization);
Returns
| Name | Type | Description |
|---|---|---|
poolUtilization | uint256 | The pool utilization in basis points |
_poolUtilizationWadβ
Get the pool utilization defined by the ratio of assets in the AMM to total assets.
calling this function will also store the utilization in the UTILIZATION_TRANSIENT_SLOT as DECIMALS if the current one is higher than the one already stored. This ensures that flash deposits can't lower the utilization for a single tx
function _poolUtilizationWad() internal returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | poolUtilization The pool utilization in basis points |
_poolUtilizationWadViewβ
Get the pool utilization defined by the ratio of assets in the AMM to total assets.
function _poolUtilizationWadView() internal view returns (uint256 poolUtilization);
Returns
| Name | Type | Description |
|---|---|---|
poolUtilization | uint256 | The pool utilization in WAD |
delegateβ
Increase the share balance of a user by 2^248 - 1 without updating the total supply.
This is controlled by the Panoptic Pool - not individual users.
function delegate(address delegatee) external onlyPanopticPool nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
delegatee | address | The account to increase the balance of |
revokeβ
Decrease the share balance of a user by 2^248 - 1 without updating the total supply.
Assumes that delegatee has >=(2^248 - 1) tokens, will revert otherwise.
This is controlled by the Panoptic Pool - not individual users.
function revoke(address delegatee) external onlyPanopticPool nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
delegatee | address | The account to decrease the balance of |
settleLiquidationβ
Settles liquidation bonus and returns remaining virtual shares to the protocol.
This function is where protocol loss is realized, if it exists.
function settleLiquidation(address liquidator, address liquidatee, int256 bonus)
external
payable
onlyPanopticPool
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
liquidator | address | The account performing the liquidation of liquidatee |
liquidatee | address | The liquidated account to settle |
bonus | int256 | The liquidation bonus, in assets, to be paid to liquidator. May be negative |
refundβ
Refunds tokens to refunder from refundee.
Assumes that the refunder has enough money to pay for the refund.
function refund(address refunder, address refundee, int256 assets) external onlyPanopticPool nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
refunder | address | The account refunding tokens to refundee |
refundee | address | The account being refunded to |
assets | int256 | The amount of assets to refund. Positive means a transfer from refunder to refundee, vice versa for negative |
_updateBalancesAndSettleβ
Internal function to handle all balance and state updates for position creation and closing.
function _updateBalancesAndSettle(
address optionOwner,
bool isCreation,
int128 longAmount,
int128 shortAmount,
int128 ammDeltaAmount,
int128 realizedPremium
) internal returns (uint32, int128, uint256, uint256);
Parameters
| Name | Type | Description |
|---|---|---|
optionOwner | address | The user minting the option |
isCreation | bool | A boolean flag to indicate if this is for option creation (true) or closing (false). |
longAmount | int128 | The amount of longs |
shortAmount | int128 | The amount of shorts |
ammDeltaAmount | int128 | The amount of tokens moved during creation of the option position |
realizedPremium | int128 |
settleMintβ
Take commission and settle ITM amounts on option creation.
function settleMint(
address optionOwner,
int128 longAmount,
int128 shortAmount,
int128 ammDeltaAmount,
RiskParameters riskParameters
) external onlyPanopticPool nonReentrant returns (uint32, int128);
Parameters
| Name | Type | Description |
|---|---|---|
optionOwner | address | The user minting the option |
longAmount | int128 | The amount of longs |
shortAmount | int128 | The amount of shorts |
ammDeltaAmount | int128 | The amount of tokens moved during creation of the option position |
riskParameters | RiskParameters | The RiskEngine's core parameters |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint32 | utilization The final utilization of the collateral vault (in basis points) |
<none> | int128 | tokenPaid The total amount of tokens paid by the option owner (negative if tokens were received) |
settleBurnβ
Exercise an option and pay to the seller what is owed from the buyer.
Called when a position is burnt because it may need to be exercised.
function settleBurn(
address optionOwner,
int128 longAmount,
int128 shortAmount,
int128 ammDeltaAmount,
int128 realizedPremium,
RiskParameters riskParameters
) external onlyPanopticPool nonReentrant returns (int128);
Parameters
| Name | Type | Description |
|---|---|---|
optionOwner | address | The owner of the option being burned |
longAmount | int128 | The notional value of the long legs of the position (if any) |
shortAmount | int128 | The notional value of the short legs of the position (if any) |
ammDeltaAmount | int128 | The amount of tokens moved during the option close |
realizedPremium | int128 | Premium to settle on the current positions |
riskParameters | RiskParameters | The RiskEngine's core risk parameters |
Returns
| Name | Type | Description |
|---|---|---|
<none> | int128 | The amount of tokens paid when closing that position |
Eventsβ
Depositβ
Emitted when assets are deposited into the Collateral Tracker.
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
sender | address | The address of the caller |
owner | address | The address of the recipient of the newly minted shares |
assets | uint256 | The amount of assets deposited by sender in exchange for shares |
shares | uint256 | The amount of shares minted to owner |
Withdrawβ
Emitted when assets are withdrawn from the Collateral Tracker.
event Withdraw(
address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares
);
Parameters
| Name | Type | Description |
|---|---|---|
sender | address | The address of the caller |
receiver | address | The address of the recipient of the withdrawn assets |
owner | address | The address of the owner of the shares being burned |
assets | uint256 | The amount of assets withdrawn to receiver |
shares | uint256 | The amount of shares burned by owner in exchange for assets |
Donateβ
Emitted when shares are donated to the protocol.
event Donate(address indexed sender, uint256 shares);
Parameters
| Name | Type | Description |
|---|---|---|
sender | address | The address of the caller |
shares | uint256 | The amount of shares burned by the sender |
CommissionPaidβ
Emitted when a commission is paid.
event CommissionPaid(
address indexed owner, address indexed builder, uint128 commissionPaidProtocol, uint128 commissionPaidBuilder
);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | The address of the owner of the shares being used to pay for the commission |
builder | address | The address of the account that received the commission if a builderCode is provided |
commissionPaidProtocol | uint128 | The amount of assets paid that goes to the PLPs (if builder == address(0)) or to the protocol |
commissionPaidBuilder | uint128 | The amount of assets paid that goes to the builder |
InsolvencyPenaltyAppliedβ
Emitted when a user attempts to settle interest but lacks sufficient shares to pay in full.
The user's borrow index is not updated, meaning they will need to pay this interest again in the future.
event InsolvencyPenaltyApplied(
address indexed owner, uint256 interestOwed, uint256 interestPaid, uint256 sharesBurned
);
Parameters
| Name | Type | Description |
|---|---|---|
owner | address | The address of the insolvent user |
interestOwed | uint256 | The total amount of interest the user owed |
interestPaid | uint256 | The actual amount of interest paid (value of shares burned) |
sharesBurned | uint256 | The number of shares burned in the partial payment |
ProtocolLossRealizedβ
event ProtocolLossRealized(
address indexed liquidatee, address indexed liquidator, uint256 protocolLossAssets, uint256 protocolLossShares
);