Skip to main content

PrimitiveManager.sol

Read code on GitHub

Interacts with Primitive Engine contracts

Methods‚Äč

DOMAIN_SEPARATOR‚Äč

Returns the domain separator

Solidity
function DOMAIN_SEPARATOR() external view returns (bytes32)

Returns‚Äč

NameTypeDescription
_0bytes32Hash of the domain separator

WETH9‚Äč

Returns the address of WETH9

Solidity
function WETH9() external view returns (address)

Returns‚Äč

NameTypeDescription
_0addressundefined

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

balanceOf‚Äč

Solidity
function balanceOf(address account, uint256 id) external view returns (uint256)
Details

See {IERC1155-balanceOf}. Requirements: - account cannot be the zero address.

Parameters‚Äč

NameTypeDescription
accountaddressundefined
iduint256undefined

Returns‚Äč

NameTypeDescription
_0uint256undefined

balanceOfBatch‚Äč

Solidity
function balanceOfBatch(address[] accounts, uint256[] ids) external view returns (uint256[])
Details

See {IERC1155-balanceOfBatch}. Requirements: - accounts and ids must have the same length.

Parameters‚Äč

NameTypeDescription
accountsaddress[]undefined
idsuint256[]undefined

Returns‚Äč

NameTypeDescription
_0uint256[]undefined

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

deposit‚Äč

Deposits funds into the margin of a Primitive Engine

Solidity
function deposit(address recipient, address risky, address stable, uint256 delRisky, uint256 delStable) external payable
Details

Since the PrimitiveManager contract keeps track of the margins, it will deposit the funds into the Primitive Engine using its own address

Parameters‚Äč

NameTypeDescription
recipientaddressAddress receiving the funds in their margin
riskyaddressAddress of the risky token
stableaddressAddress of the stable token
delRiskyuint256Amount of risky token to deposit
delStableuint256Amount of stable token to deposit

depositCallback‚Äč

Triggered when depositing tokens to an Engine

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

Parameters‚Äč

NameTypeDescription
delRiskyuint256Amount of risky tokens required to deposit to risky margin balance
delStableuint256Amount of stable tokens required to deposit to stable margin balance
databytesCalldata passed on deposit function call

factory‚Äč

Returns the address of the factory

Solidity
function factory() external view returns (address)

Returns‚Äč

NameTypeDescription
_0addressundefined

isApprovedForAll‚Äč

Solidity
function isApprovedForAll(address account, address operator) external view returns (bool)
Details

See {IERC1155-isApprovedForAll}.

Parameters‚Äč

NameTypeDescription
accountaddressundefined
operatoraddressundefined

Returns‚Äč

NameTypeDescription
_0boolundefined

margins‚Äč

Returns the margin of an account for a specific Primitive Engine

Solidity
function margins(address, address) external view returns (uint128 balanceRisky, uint128 balanceStable)

Parameters‚Äč

NameTypeDescription
_0addressundefined
_1addressundefined

Returns‚Äč

NameTypeDescription
balanceRiskyuint128undefined
balanceStableuint128undefined

multicall‚Äč

Call multiple functions in the current contract and return the data from all of them if they all succeed

Solidity
function multicall(bytes[] data) external payable returns (bytes[] results)
Details

msg.value should not be trusted for any method callable from Multicall

Parameters‚Äč

NameTypeDescription
databytes[]Encoded function data for each of the calls to make to this contract

Returns‚Äč

NameTypeDescription
resultsbytes[]Results from each of the calls passed in via data

nonces‚Äč

Returns the current nonce of an address

Solidity
function nonces(address) external view returns (uint256)

Parameters‚Äč

NameTypeDescription
_0addressundefined

Returns‚Äč

NameTypeDescription
_0uint256undefined

permit‚Äč

Grants or revokes the approval for an operator to transfer any of the owner's tokens using their signature

Solidity
function permit(address owner, address operator, bool approved, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external nonpayable

Parameters‚Äč

NameTypeDescription
owneraddressAddress of the owner
operatoraddressAddress of the operator
approvedboolTrue if the approval should be granted, false if revoked
deadlineuint256Expiry of the signature, as a timestamp
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

positionDescriptor‚Äč

Returns the address of the PositionDescriptor

Solidity
function positionDescriptor() external view returns (address)

Returns‚Äč

NameTypeDescription
_0addressundefined

refundETH‚Äč

Transfers the ETH balance of the contract to the caller

Solidity
function refundETH() external payable

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

safeBatchTransferFrom‚Äč

Solidity
function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data) external nonpayable
Details

See {IERC1155-safeBatchTransferFrom}.

Parameters‚Äč

NameTypeDescription
fromaddressundefined
toaddressundefined
idsuint256[]undefined
amountsuint256[]undefined
databytesundefined

safeTransferFrom‚Äč

Solidity
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data) external nonpayable
Details

See {IERC1155-safeTransferFrom}.

Parameters‚Äč

NameTypeDescription
fromaddressundefined
toaddressundefined
iduint256undefined
amountuint256undefined
databytesundefined

selfPermit‚Äč

Permits this contract to spend a given token from msg.sender

Solidity
function selfPermit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this)

Parameters‚Äč

NameTypeDescription
tokenaddressAddress of the token spent
valueuint256Amount that can be spent of token
deadlineuint256A timestamp, the current blocktime must be less than or equal to this timestamp
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

selfPermitAllowed‚Äč

Permits this contract to spend the sender's tokens for permit signatures that have the allowed parameter

Solidity
function selfPermitAllowed(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this)

Parameters‚Äč

NameTypeDescription
tokenaddressAddress of the token spent
nonceuint256Current nonce of the owner
expiryuint256Timestamp at which the permit is no longer valid
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

selfPermitAllowedIfNecessary‚Äč

Permits this contract to spend the sender's tokens for permit signatures that have the allowed parameter

Solidity
function selfPermitAllowedIfNecessary(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this) Can be used instead of #selfPermitAllowed to prevent calls from failing due to a frontrun of a call to #selfPermitAllowed

Parameters‚Äč

NameTypeDescription
tokenaddressAddress of the token spent
nonceuint256Current nonce of the owner
expiryuint256Timestamp at which the permit is no longer valid
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

selfPermitIfNecessary‚Äč

Permits this contract to spend a given token from msg.sender

Solidity
function selfPermitIfNecessary(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this) Can be used instead of #selfPermit to prevent calls from failing due to a frontrun of a call to #selfPermit

Parameters‚Äč

NameTypeDescription
tokenaddressAddress of the token spent
valueuint256Amount that can be spent of token
deadlineuint256A timestamp, the current blocktime must be less than or equal to this timestamp
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

setApprovalForAll‚Äč

Solidity
function setApprovalForAll(address operator, bool approved) external nonpayable
Details

See {IERC1155-setApprovalForAll}.

Parameters‚Äč

NameTypeDescription
operatoraddressundefined
approvedboolundefined

supportsInterface‚Äč

Solidity
function supportsInterface(bytes4 interfaceId) external view returns (bool)
Details

See {IERC165-supportsInterface}.

Parameters‚Äč

NameTypeDescription
interfaceIdbytes4undefined

Returns‚Äč

NameTypeDescription
_0boolundefined

swap‚Äč

Solidity
function swap(ISwapManager.SwapParams params) external payable

Parameters‚Äč

NameTypeDescription
paramsISwapManager.SwapParamsundefined

swapCallback‚Äč

Triggered when swapping tokens in an Engine

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

Parameters‚Äč

NameTypeDescription
delRiskyuint256Amount of risky tokens required to pay the swap with
delStableuint256Amount of stable tokens required to pay the swap with
databytesCalldata passed on swap function call

sweepToken‚Äč

Transfers the tokens in the contract to a recipient

Solidity
function sweepToken(address token, uint256 amountMin, address recipient) external payable

Parameters‚Äč

NameTypeDescription
tokenaddressAddress of the token to sweep
amountMinuint256Minimum amount to transfer
recipientaddressRecipient of the tokens

unwrap‚Äč

Unwraps WETH to ETH and transfers to a recipient

Solidity
function unwrap(uint256 amountMin, address recipient) external payable

Parameters‚Äč

NameTypeDescription
amountMinuint256Minimum amount to unwrap
recipientaddressAddress of the recipient

uri‚Äč

Returns the metadata of a token

Solidity
function uri(uint256 tokenId) external view returns (string)

Parameters‚Äč

NameTypeDescription
tokenIduint256Token id to look for (same as pool id)

Returns‚Äč

NameTypeDescription
_0stringMetadata of the token as a string

withdraw‚Äč

Withdraws funds from the margin of a Primitive Engine

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

Parameters‚Äč

NameTypeDescription
recipientaddressAddress receiving the funds in their wallet
engineaddressPrimitive Engine to withdraw from
delRiskyuint256Amount of risky token to withdraw
delStableuint256Amount of stable token to withdraw

wrap‚Äč

Wraps ETH into WETH and transfers to the msg.sender

Solidity
function wrap(uint256 value) external payable

Parameters‚Äč

NameTypeDescription
valueuint256Amount of ETH to wrap

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
payeraddressundefined
recipient indexedaddressundefined
engine indexedaddressundefined
poolId indexedbytes32undefined
delLiquidityuint256undefined
delRiskyuint256undefined
delStableuint256undefined
fromMarginboolundefined

ApprovalForAll‚Äč

Solidity
event ApprovalForAll(address indexed account, address indexed operator, bool approved)

Parameters‚Äč

NameTypeDescription
account indexedaddressundefined
operator indexedaddressundefined
approvedboolundefined

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 indexedaddressundefined
engine indexedaddressundefined
poolId indexedbytes32undefined
strikeuint128undefined
sigmauint32undefined
maturityuint32undefined
gammauint32undefined
delLiquidityuint256undefined

Deposit‚Äč

Emitted when funds are deposited

Solidity
event Deposit(address indexed payer, address indexed recipient, address indexed engine, address risky, address stable, uint256 delRisky, uint256 delStable)

Parameters‚Äč

NameTypeDescription
payer indexedaddressundefined
recipient indexedaddressundefined
engine indexedaddressundefined
riskyaddressundefined
stableaddressundefined
delRiskyuint256undefined
delStableuint256undefined

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 indexedaddressundefined
engine indexedaddressundefined
poolId indexedbytes32undefined
delLiquidityuint256undefined
delRiskyuint256undefined
delStableuint256undefined

Swap‚Äč

Emitted when a swap occurs

Solidity
event Swap(address indexed payer, address recipient, address indexed engine, bytes32 indexed poolId, bool riskyForStable, uint256 deltaIn, uint256 deltaOut, bool fromMargin, bool toMargin)

Parameters‚Äč

NameTypeDescription
payer indexedaddressundefined
recipientaddressundefined
engine indexedaddressundefined
poolId indexedbytes32undefined
riskyForStableboolundefined
deltaInuint256undefined
deltaOutuint256undefined
fromMarginboolundefined
toMarginboolundefined

TransferBatch‚Äč

Solidity
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values)

Parameters‚Äč

NameTypeDescription
operator indexedaddressundefined
from indexedaddressundefined
to indexedaddressundefined
idsuint256[]undefined
valuesuint256[]undefined

TransferSingle‚Äč

Solidity
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value)

Parameters‚Äč

NameTypeDescription
operator indexedaddressundefined
from indexedaddressundefined
to indexedaddressundefined
iduint256undefined
valueuint256undefined

URI‚Äč

Solidity
event URI(string value, uint256 indexed id)

Parameters‚Äč

NameTypeDescription
valuestringundefined
id indexeduint256undefined

Withdraw‚Äč

Emitted when funds are withdrawn

Solidity
event Withdraw(address indexed payer, address indexed recipient, address indexed engine, address risky, address stable, uint256 delRisky, uint256 delStable)

Parameters‚Äč

NameTypeDescription
payer indexedaddressundefined
recipient indexedaddressundefined
engine indexedaddressundefined
riskyaddressundefined
stableaddressundefined
delRiskyuint256undefined
delStableuint256undefined

Errors‚Äč

BalanceTooLowError‚Äč

Thrown when the amount required is above balance

Solidity
error BalanceTooLowError(uint256 balance, uint256 requiredAmount)

Parameters‚Äč

NameTypeDescription
balanceuint256Actual ETH or token balance of the contract
requiredAmountuint256ETH or token amount required by the user

DeadlineReachedError‚Äč

Thrown when the deadline is reached

Solidity
error DeadlineReachedError()

EngineNotDeployedError‚Äč

Thrown when the target Engine is not deployed

Solidity
error EngineNotDeployedError()

InvalidSigError‚Äč

Thrown when the signature is invalid

Solidity
error InvalidSigError()

LockedError‚Äč

Thrown when a call to the contract is made during a locked state

Solidity
error LockedError()

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()

NotEngineError‚Äč

Thrown when the sender is not a Primitive Engine contract

Solidity
error NotEngineError()

OnlyWETHError‚Äč

Thrown when the sender is not WETH

Solidity
error OnlyWETHError()

SigExpiredError‚Äč

Thrown when the signature has expired

Solidity
error SigExpiredError()

TransferError‚Äč

Thrown when a transfer reverts

Solidity
error TransferError()

WrongConstructorParametersError‚Äč

Thrown when the constructor parameters are wrong

Solidity
error WrongConstructorParametersError()

ZeroDelError‚Äč

Thrown when trying to deposit or withdraw 0 risky and stable

Solidity
error ZeroDelError()

ZeroLiquidityError‚Äč

Thrown when trying to add or remove zero liquidity

Solidity
error ZeroLiquidityError()