Skip to main content

IPrimitiveManager.sol

Read code on GitHub

Methods

allocate

Allocates liquidity into a pool

Solidity
function allocate(address recipient, bytes32 poolId, address risky, address stable, uint256 delRisky, uint256 delStable, bool fromMargin, uint256 minLiquidityOut) external payable returns (uint256 delLiquidity)

Parameters

NameTypeDescription
recipientaddressAddress that receives minted ERC-1155 Primitive liquidity tokens
poolIdbytes32Id of the pool
riskyaddressAddress of the risky asset
stableaddressAddress of the stable asset
delRiskyuint256Amount of risky tokens to allocate
delStableuint256Amount of stable tokens to allocate
fromMarginboolTrue if the funds of the sender should be used
minLiquidityOutuint256undefined

Returns

NameTypeDescription
delLiquidityuint256Amount of liquidity allocated into the pool

allocateCallback

Triggered when providing liquidity to an Engine

Solidity
function allocateCallback(uint256 delRisky, uint256 delStable, bytes data) external nonpayable

Parameters

NameTypeDescription
delRiskyuint256Amount of risky tokens required to provide to risky reserve
delStableuint256Amount of stable tokens required to provide to stable reserve
databytesCalldata passed on allocate function call

create

Creates a new pool using the specified parameters

Solidity
function create(address risky, address stable, uint128 strike, uint32 sigma, uint32 maturity, uint32 gamma, uint256 riskyPerLp, uint256 delLiquidity) external payable returns (bytes32 poolId, uint256 delRisky, uint256 delStable)

Parameters

NameTypeDescription
riskyaddressAddress of the risky asset
stableaddressAddress of the stable asset
strikeuint128Strike price of the pool to calibrate to, with the same decimals as the stable token
sigmauint32Volatility to calibrate to as an unsigned 256-bit integer w/ precision of 1e4, 10000 = 100%
maturityuint32Maturity timestamp of the pool, in seconds
gammauint32Multiplied against swap in amounts to apply fee, equal to 1 - fee %, an unsigned 32-bit integer, w/ precision of 1e4, 10000 = 100%
riskyPerLpuint256Risky reserve per liq. with risky decimals, = 1 - N(d1), d1 = (ln(S/K)+(rsigma^2/2))/sigmasqrt(tau)
delLiquidityuint256Amount of liquidity to allocate to the curve, wei value with 18 decimals of precision

Returns

NameTypeDescription
poolIdbytes32Id of the new created pool (Keccak256 hash of the engine address, maturity, sigma and strike)
delRiskyuint256Amount of risky tokens allocated into the pool
delStableuint256Amount of stable tokens allocated into the pool

createCallback

Triggered when creating a new pool for an Engine

Solidity
function createCallback(uint256 delRisky, uint256 delStable, bytes data) external nonpayable

Parameters

NameTypeDescription
delRiskyuint256Amount of risky tokens required to initialize risky reserve
delStableuint256Amount of stable tokens required to initialize stable reserve
databytesCalldata passed on create function call

remove

Removes liquidity from a pool

Solidity
function remove(address engine, bytes32 poolId, uint256 delLiquidity, uint256 minRiskyOut, uint256 minStableOut) external nonpayable returns (uint256 delRisky, uint256 delStable)

Parameters

NameTypeDescription
engineaddressAddress of the engine
poolIdbytes32Id of the pool
delLiquidityuint256Amount of liquidity to remove
minRiskyOutuint256Minimum amount of risky tokens expected to be received
minStableOutuint256Minimum amount of stable tokens expected to be received

Returns

NameTypeDescription
delRiskyuint256Amount of risky tokens removed from the pool
delStableuint256Amount of stable tokens removed from the pool

Events

Allocate

Emitted when liquidity is allocated

Solidity
event Allocate(address payer, address indexed recipient, address indexed engine, bytes32 indexed poolId, uint256 delLiquidity, uint256 delRisky, uint256 delStable, bool fromMargin)

Parameters

NameTypeDescription
payeraddressPayer sending liquidity
recipient indexedaddressAddress that receives minted ERC-1155 Primitive liquidity tokens
engine indexedaddressPrimitive Engine receiving liquidity
poolId indexedbytes32Id of the pool receiving liquidity
delLiquidityuint256Amount of liquidity allocated
delRiskyuint256Amount of risky tokens allocated
delStableuint256Amount of stable tokens allocated
fromMarginboolTrue if liquidity was paid from margin

Create

Emitted when a new pool is created

Solidity
event Create(address indexed payer, address indexed engine, bytes32 indexed poolId, uint128 strike, uint32 sigma, uint32 maturity, uint32 gamma, uint256 delLiquidity)

Parameters

NameTypeDescription
payer indexedaddressPayer sending liquidity
engine indexedaddressPrimitive Engine where the pool is created
poolId indexedbytes32Id of the new pool
strikeuint128Strike of the new pool
sigmauint32Sigma of the new pool
maturityuint32Maturity of the new pool
gammauint32Gamma of the new pool
delLiquidityuint256Amount of liquidity allocated (minus the minimum liquidity)

Remove

Emitted when liquidity is removed

Solidity
event Remove(address indexed payer, address indexed engine, bytes32 indexed poolId, uint256 delLiquidity, uint256 delRisky, uint256 delStable)

Parameters

NameTypeDescription
payer indexedaddressPayer receiving liquidity
engine indexedaddressEngine where liquidity is removed from
poolId indexedbytes32Id of the pool where liquidity is removed from
delLiquidityuint256Amount of liquidity removed
delRiskyuint256Amount of risky tokens allocated
delStableuint256Amount of stable tokens allocated

Errors

MinLiquidityOutError

Thrown when the received liquidity is lower than the expected

Solidity
error MinLiquidityOutError()

MinRemoveOutError

Thrown when the received risky / stable amounts are lower than the expected

Solidity
error MinRemoveOutError()

ZeroLiquidityError

Thrown when trying to add or remove zero liquidity

Solidity
error ZeroLiquidityError()