Swapper
GitHub: link
Abstract contract for swapping between xPYTs/NYTs and their underlying asset by swapping via an external DEX and minting/burning xPYT/NYT.
Swapper supports two-hop swaps where one of the swaps is an 0x swap between two regular tokens, which enables swapping any supported token into any xPYT/NYT. Two-hop swaps are done by chaining two calls together via Multicall and setting the recipient of the first swap to the Swapper.
Errors
Error_SameToken
error Error_SameToken()
Error_PastDeadline
error Error_PastDeadline()
Error_ZeroExSwapFailed
error Error_ZeroExSwapFailed()
Error_InsufficientOutput
error Error_InsufficientOutput()
Error_ProtocolFeeRecipientIsZero
error Error_ProtocolFeeRecipientIsZero()
Events
SetProtocolFee
event SetProtocolFee(struct Swapper.ProtocolFeeInfo protocolFeeInfo_)
Structs
SwapArgs
struct SwapArgs {
contract Gate gate;
address vault;
contract ERC20 underlying;
contract ERC20 nyt;
contract ERC20 pyt;
contract IxPYT xPYT;
uint256 tokenAmountIn;
uint256 minAmountOut;
address recipient;
bool useSwapperBalance;
bool usePYT;
uint256 deadline;
bytes extraArgs;
}
ProtocolFeeInfo
struct ProtocolFeeInfo {
uint8 fee;
address recipient;
}
Immutable parameters
zeroExProxy
address zeroExProxy
The 0x proxy contract used for 0x swaps
weth
contract WETH weth
The Wrapped Ethereum contract
State variables
protocolFeeInfo
struct Swapper.ProtocolFeeInfo protocolFeeInfo
The protocol fee and the fee recipient address.
State-mutating functions
swapUnderlyingToNyt
function swapUnderlyingToNyt(struct Swapper.SwapArgs args) external virtual returns (uint256 tokenAmountOut)
Swaps the underlying asset of an NYT into the NYT
Name | Type | Description |
---|---|---|
args | struct Swapper.SwapArgs | The input arguments (see SwapArgs definition) |
Name | Type | Description |
---|---|---|
tokenAmountOut | uint256 | The amount of token output |
swapUnderlyingToXpyt
function swapUnderlyingToXpyt(struct Swapper.SwapArgs args) external virtual returns (uint256 tokenAmountOut)
Swaps the underlying asset of an xPYT into the xPYT
Name | Type | Description |
---|---|---|
args | struct Swapper.SwapArgs | The input arguments (see SwapArgs definition) |
Name | Type | Description |
---|---|---|
tokenAmountOut | uint256 | The amount of token output |
swapNytToUnderlying
function swapNytToUnderlying(struct Swapper.SwapArgs args) external virtual returns (uint256 tokenAmountOut)
Swaps an NYT to its underlying asset
Name | Type | Description |
---|---|---|
args | struct Swapper.SwapArgs | The input arguments (see SwapArgs definition) |
Name | Type | Description |
---|---|---|
tokenAmountOut | uint256 | The amount of token output |
swapXpytToUnderlying
function swapXpytToUnderlying(struct Swapper.SwapArgs args) external virtual returns (uint256 tokenAmountOut)
Swaps an xPYT to its underlying asset
Name | Type | Description |
---|---|---|
args | struct Swapper.SwapArgs | The input arguments (see SwapArgs definition) |
Name | Type | Description |
---|---|---|
tokenAmountOut | uint256 | The amount of token output |
doZeroExSwap
function doZeroExSwap(contract ERC20 tokenIn, uint256 tokenAmountIn, contract ERC20 tokenOut, uint256 minAmountOut, address recipient, bool useSwapperBalance, bool requireApproval, uint256 deadline, bytes swapData) external virtual returns (uint256 tokenAmountOut)
Swaps between two regular tokens using 0x.
Used in conjuction with the 0x API https://www.0x.org/docs/api
Name | Type | Description |
---|---|---|
tokenIn | contract ERC20 | The input token |
tokenAmountIn | uint256 | The amount of token input |
tokenOut | contract ERC20 | The output token |
minAmountOut | uint256 | The minimum acceptable token output amount, used for slippage checking. |
recipient | address | The recipient of the token output |
useSwapperBalance | bool | Set to true to use the Swapper's token balance as token input |
requireApproval | bool | Set to true to approve tokenIn to zeroExProxy |
deadline | uint256 | The Unix timestamp (in seconds) after which the call will be reverted |
swapData | bytes | The call data to zeroExProxy to execute the swap, obtained from the https://api.0x.org/swap/v1/quote endpoint |
Name | Type | Description |
---|---|---|
tokenAmountOut | uint256 | The amount of token output |
wrapEthInput
function wrapEthInput() external payable
Wraps the user's ETH input into WETH
Should be used as part of a multicall to convert the user's ETH input into WETH so that it can be swapped into xPYT/NYT.
Owner functions
ownerSetProtocolFee
function ownerSetProtocolFee(struct Swapper.ProtocolFeeInfo protocolFeeInfo_) external virtual
Updates the protocol fee and/or the protocol fee recipient. Only callable by the owner.
Name | Type | Description |
---|---|---|
protocolFeeInfo_ | struct Swapper.ProtocolFeeInfo | The new protocol fee info |