Skip to main content

PanopticFactory

Git Source

Inherits: FactoryNFT, Multicall

Author: Axicon Labs Limited

Facilitates deployment of Panoptic pools.

State Variables

POOL_MANAGER_V4

The canonical Uniswap V4 Pool Manager address.

IPoolManager internal immutable POOL_MANAGER_V4;

SFPM

The Semi Fungible Position Manager (SFPM) which tracks option positions across Panoptic Pools.

SemiFungiblePositionManager internal immutable SFPM;

POOL_REFERENCE

Reference implementation of the PanopticPool to clone.

address internal immutable POOL_REFERENCE;

COLLATERAL_REFERENCE

Reference implementation of the CollateralTracker to clone.

address internal immutable COLLATERAL_REFERENCE;

CARDINALITY_INCREASE

The observationCardinalityNext to set on the Uniswap pool when a new PanopticPool is deployed.

uint16 internal constant CARDINALITY_INCREASE = 51;

s_getPanopticPool

Mapping from keccak256(Uniswap V4 pool id, oracle contract address) to address(PanopticPool) that stores the address of all deployed Panoptic Pools.

mapping(bytes32 panopticPoolKey => PanopticPool panopticPool) internal s_getPanopticPool;

Functions

constructor

Set immutable variables and store metadata pointers.

constructor(
SemiFungiblePositionManager _SFPM,
IPoolManager manager,
address _poolReference,
address _collateralReference,
bytes32[] memory properties,
uint256[][] memory indices,
Pointer[][] memory pointers
) FactoryNFT(properties, indices, pointers);

Parameters

NameTypeDescription
_SFPMSemiFungiblePositionManagerThe canonical SemiFungiblePositionManager deployment
managerIPoolManagerThe canonical Uniswap V4 pool manager
_poolReferenceaddressThe reference implementation of the PanopticPool to clone
_collateralReferenceaddressThe reference implementation of the CollateralTracker to clone
propertiesbytes32[]An array of identifiers for different categories of metadata
indicesuint256[][]A nested array of keys for K-V metadata pairs for each property in properties
pointersPointer[][]Contains pointers to the metadata values stored in contract data slices for each index in indices

deployNewPool

Create a new Panoptic Pool linked to the given Uniswap pool identified uniquely by the incoming parameters.

There is a 1:1 mapping between a Panoptic Pool and a Uniswap Pool.

A Uniswap pool is uniquely identified by its tokens and the fee.

Salt used in PanopticPool creation is [leading 20 msg.sender chars][uint80(uint256(keccak256(abi.encode(V4PoolKey, oracleContractAddress))))][salt].

function deployNewPool(IV3CompatibleOracle oracleContract, PoolKey calldata key, uint96 salt)
external
returns (PanopticPool newPoolContract);

Parameters

NameTypeDescription
oracleContractIV3CompatibleOracleThe external oracle contract to be used by the newly deployed Panoptic Pool
keyPoolKeyThe Uniswap V4 pool key
saltuint96User-defined component of salt used in deployment process for the PanopticPool

Returns

NameTypeDescription
newPoolContractPanopticPoolThe address of the newly deployed Panoptic pool

minePoolAddress

Find the salt which would give a Panoptic Pool the highest rarity within the search parameters.

The rarity is defined in terms of how many leading zeros the Panoptic pool address has.

Note that the final salt may overflow if too many loops are given relative to the amount in salt.

function minePoolAddress(
address deployerAddress,
address oracleContract,
PoolKey calldata key,
uint96 salt,
uint256 loops,
uint256 minTargetRarity
) external view returns (uint96 bestSalt, uint256 highestRarity);

Parameters

NameTypeDescription
deployerAddressaddressAddress of the account that deploys the new PanopticPool
oracleContractaddress
keyPoolKey
saltuint96Salt value to start from, useful as a checkpoint across multiple calls
loopsuint256The number of mining operations starting from salt in trying to find the highest rarity
minTargetRarityuint256The minimum target rarity to mine for. The internal loop stops when this is reached or when no more iterations

Returns

NameTypeDescription
bestSaltuint96The salt of the rarest pool (potentially at the specified minimum target)
highestRarityuint256The rarity of bestSalt

getPanopticPool

Return the address of the Panoptic Pool associated with the given Uniswap V4 pool key and oracle contract.

function getPanopticPool(PoolKey calldata keyV4, IV3CompatibleOracle oracleContract)
external
view
returns (PanopticPool);

Parameters

NameTypeDescription
keyV4PoolKeyThe Uniswap V4 pool key
oracleContractIV3CompatibleOracleThe external oracle contract used by the Panoptic Pool

Returns

NameTypeDescription
<none>PanopticPoolAddress of the Panoptic Pool on keyV4 using oracleContract

Events

PoolDeployed

Emitted when a Panoptic Pool is created.

event PoolDeployed(
PanopticPool indexed poolAddress,
IV3CompatibleOracle indexed oracleContract,
PoolKey poolKey,
CollateralTracker collateralTracker0,
CollateralTracker collateralTracker1
);

Parameters

NameTypeDescription
poolAddressPanopticPoolAddress of the deployed Panoptic pool
oracleContractIV3CompatibleOracleThe external oracle contract used by the newly deployed Panoptic Pool
poolKeyPoolKeyThe Uniswap V4 pool key associated with the Panoptic Pool
collateralTracker0CollateralTrackerAddress of the collateral tracker contract for currency0
collateralTracker1CollateralTrackerAddress of the collateral tracker contract for currency1