Skip to main content

UniswapV3Swapper

GitHub: link

Swapper that uses Uniswap V3 to swap between xPYTs/NYTs

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

Error_NotUniswapV3Pool

error Error_NotUniswapV3Pool()

Error_BothTokenDeltasAreZero

error Error_BothTokenDeltasAreZero()

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;
}

SwapCallbackData

struct SwapCallbackData {
contract ERC20 tokenIn;
contract ERC20 tokenOut;
uint24 fee;
}

Constants

MIN_SQRT_RATIO_PLUS_ONE

uint160 MIN_SQRT_RATIO_PLUS_ONE

The minimum value that can be returned from #getSqrtRatioAtTick + 1. Equivalent to getSqrtRatioAtTick(MIN_TICK) + 1 Copied from v3-core/libraries/TickMath.sol

MAX_SQRT_RATIO_MINUS_ONE

uint160 MAX_SQRT_RATIO_MINUS_ONE

The maximum value that can be returned from #getSqrtRatioAtTick - 1. Equivalent to getSqrtRatioAtTick(MAX_TICK) - 1 Copied from v3-core/libraries/TickMath.sol

Immutable parameters

zeroExProxy

address zeroExProxy

The 0x proxy contract used for 0x swaps

weth

contract WETH weth

The Wrapped Ethereum contract

uniswapV3Factory

address uniswapV3Factory

The official Uniswap V3 factory address

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

extraArg = (uint24 fee)

fee: The fee tier of the Uniswap V3 pool to use

NameTypeDescription
argsstruct Swapper.SwapArgsThe input arguments (see SwapArgs definition)
NameTypeDescription
tokenAmountOutuint256The 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

extraArg = (uint24 fee)

fee: The fee tier of the Uniswap V3 pool to use

NameTypeDescription
argsstruct Swapper.SwapArgsThe input arguments (see SwapArgs definition)
NameTypeDescription
tokenAmountOutuint256The amount of token output

swapNytToUnderlying

function swapNytToUnderlying(struct Swapper.SwapArgs args) external virtual returns (uint256 tokenAmountOut)

Swaps an NYT to its underlying asset

extraArg = (uint24 fee, uint256 swapAmountIn)

fee: The fee tier of the Uniswap V3 pool to use

swapAmountIn: The amount of NYT to swap to xPYT

NameTypeDescription
argsstruct Swapper.SwapArgsThe input arguments (see SwapArgs definition)
NameTypeDescription
tokenAmountOutuint256The amount of token output

swapXpytToUnderlying

function swapXpytToUnderlying(struct Swapper.SwapArgs args) external virtual returns (uint256 tokenAmountOut)

Swaps an xPYT to its underlying asset

extraArg = (uint24 fee, uint256 swapAmountIn)

fee: The fee tier of the Uniswap V3 pool to use

swapAmountIn: The amount of xPYT to swap to NYT

NameTypeDescription
argsstruct Swapper.SwapArgsThe input arguments (see SwapArgs definition)
NameTypeDescription
tokenAmountOutuint256The 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

NameTypeDescription
tokenIncontract ERC20The input token
tokenAmountInuint256The amount of token input
tokenOutcontract ERC20The output token
minAmountOutuint256The minimum acceptable token output amount, used for slippage checking.
recipientaddressThe recipient of the token output
useSwapperBalanceboolSet to true to use the Swapper's token balance as token input
requireApprovalboolSet to true to approve tokenIn to zeroExProxy
deadlineuint256The Unix timestamp (in seconds) after which the call will be reverted
swapDatabytesThe call data to zeroExProxy to execute the swap, obtained from the https://api.0x.org/swap/v1/quote endpoint
NameTypeDescription
tokenAmountOutuint256The 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.

NameTypeDescription
protocolFeeInfo_struct Swapper.ProtocolFeeInfoThe new protocol fee info