Skip to main content

SwapManager.sol

Read code on GitHub

Details

Manages the swaps

Methods

WETH9

Returns the address of WETH9

Solidity
function WETH9() external view returns (address)

Returns

NameTypeDescription
_0addressundefined

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

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

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

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

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

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

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

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

LockedError

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

Solidity
error LockedError()

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

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