Skip to main content

IPrimitiveEngineActions.sol

Read code on GitHub

Methods

allocate

Allocates risky and stable tokens to a specific curve with poolId

Solidity
function allocate(bytes32 poolId, address recipient, uint256 delRisky, uint256 delStable, bool fromMargin, bytes data) external nonpayable returns (uint256 delLiquidity)

Parameters

NameTypeDescription
poolIdbytes32Keccak256 hash of engine address, strike, sigma, maturity, and gamma
recipientaddressAddress to give the allocated liquidity to
delRiskyuint256Amount of risky tokens to add
delStableuint256Amount of stable tokens to add
fromMarginboolWhether the msg.sender pays with their margin balance, or must send tokens
databytesArbitrary data that is passed to the allocateCallback function

Returns

NameTypeDescription
delLiquidityuint256Amount of liquidity given to recipient

create

Initializes a curve with parameters in the calibrations storage mapping in the Engine

Solidity
function create(uint128 strike, uint32 sigma, uint32 maturity, uint32 gamma, uint256 riskyPerLp, uint256 delLiquidity, bytes data) external nonpayable returns (bytes32 poolId, uint256 delRisky, uint256 delStable)

Parameters

NameTypeDescription
strikeuint128Marginal price of the pool's risky token at maturity, with the same decimals as the stable token, valid [0, 2^128-1]
sigmauint32AKA Implied Volatility in basis points, determines the price impact of swaps, valid for (1, 10_000_000)
maturityuint32Timestamp which starts the BUFFER countdown until swaps will cease, in seconds, valid for (block.timestamp, 2^32-1]
gammauint32Multiplied against swap in amounts to apply fee, equal to 1 - fee % but units are in basis points, valid for (9_000, 10_000)
riskyPerLpuint256Risky reserve per liq. with risky decimals, = 1 - N(d1), d1 = (ln(S/K)+(r*σ^2/2))/σ√τ, valid for [0, 1e^(risky token decimals))
delLiquidityuint256Amount of liquidity units to allocate to the curve, wei value with 18 decimals of precision
databytesArbitrary data that is passed to the createCallback function

Returns

NameTypeDescription
poolIdbytes32Keccak256 hash of engine address, strike, sigma, maturity, and gamma
delRiskyuint256Total amount of risky tokens provided to reserves
delStableuint256Total amount of stable tokens provided to reserves

deposit

Adds risky and/or stable tokens to a recipient's internal balance account

Solidity
function deposit(address recipient, uint256 delRisky, uint256 delStable, bytes data) external nonpayable

Parameters

NameTypeDescription
recipientaddressRecipient margin account of the deposited tokens
delRiskyuint256Amount of risky tokens to deposit
delStableuint256Amount of stable tokens to deposit
databytesArbitrary data that is passed to the depositCallback function

remove

Unallocates risky and stable tokens from a specific curve with poolId

Solidity
function remove(bytes32 poolId, uint256 delLiquidity) external nonpayable returns (uint256 delRisky, uint256 delStable)

Parameters

NameTypeDescription
poolIdbytes32Keccak256 hash of engine address, strike, sigma, maturity, and gamma
delLiquidityuint256Amount of liquidity to remove

Returns

NameTypeDescription
delRiskyuint256Amount of risky tokens received from removed liquidity
delStableuint256Amount of stable tokens received from removed liquidity

swap

Swaps between risky and stable tokens

Solidity
function swap(address recipient, bytes32 poolId, bool riskyForStable, uint256 deltaIn, uint256 deltaOut, bool fromMargin, bool toMargin, bytes data) external nonpayable

Parameters

NameTypeDescription
recipientaddressAddress that receives output token deltaOut amount
poolIdbytes32Keccak256 hash of engine address, strike, sigma, maturity, and gamma
riskyForStableboolIf true, swap risky to stable, else swap stable to risky
deltaInuint256Amount of tokens to swap in
deltaOutuint256Amount of tokens to swap out
fromMarginboolWhether the msg.sender uses their margin balance, or must send tokens
toMarginboolWhether the deltaOut amount is transferred or deposited into margin
databytesArbitrary data that is passed to the swapCallback function

updateLastTimestamp

Updates the time until expiry of the pool by setting its last timestamp value

Solidity
function updateLastTimestamp(bytes32 poolId) external nonpayable returns (uint32 lastTimestamp)

Parameters

NameTypeDescription
poolIdbytes32Keccak256 hash of engine address, strike, sigma, maturity, and gamma

Returns

NameTypeDescription
lastTimestampuint32Timestamp loaded into the state of the pool's Calibration.lastTimestamp

withdraw

Removes risky and/or stable tokens from a msg.sender's internal balance account

Solidity
function withdraw(address recipient, uint256 delRisky, uint256 delStable) external nonpayable

Parameters

NameTypeDescription
recipientaddressAddress that tokens are transferred to
delRiskyuint256Amount of risky tokens to withdraw
delStableuint256Amount of stable tokens to withdraw