Skip to main content

UniswapV3Juggler

GitHub: link

Given xPYT/NYT input, computes how much to swap to result in an equal amount of PYT & NYT.

Used in conjunction with UniswapV3Swapper::swapNytToUnderlying() and UniswapV3Swapper::swapXpytToUnderlying(). Should only be called offchain since the gas cost is too high to be called onchain.

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

MAX_BINARY_SEARCH_ITERATIONS

uint256 MAX_BINARY_SEARCH_ITERATIONS

The maximum number of binary search iterations to find swapAmountIn

Immutable parameters

factory

address factory

The official Uniswap V3 factory address

quoter

contract IQuoter quoter

The Uniswap V3 Quoter deployment

Public functions

juggleXpytInput

function juggleXpytInput(contract ERC20 nyt, contract ERC4626 xPYT, uint24 fee, uint256 tokenAmountIn, uint256 maxError) external returns (uint256 swapAmountIn)

Given xPYT input, compute how much xPYT to swap into NYT to result in an equal amount of PYT & NYT.

NameTypeDescription
nytcontract ERC20The NYT contract
xPYTcontract ERC4626The xPYT contract
feeuint24The fee tier of the Uniswap V3 pool to use
tokenAmountInuint256The amount of token input
maxErroruint256The maximum acceptable difference between the resulting PYT & NYT balances. Might not be achieved if MAX_BINARY_SEARCH_ITERATIONS is reached.
NameTypeDescription
swapAmountInuint256The amount of xPYT to swap into NYT

juggleNytInput

function juggleNytInput(contract ERC20 nyt, contract ERC4626 xPYT, uint24 fee, uint256 tokenAmountIn, uint256 maxError) external returns (uint256 swapAmountIn)

Given NYT input, compute how much NYT to swap into xPYT to result in an equal amount of PYT & NYT.

NameTypeDescription
nytcontract ERC20The NYT contract
xPYTcontract ERC4626The xPYT contract
feeuint24The fee tier of the Uniswap V3 pool to use
tokenAmountInuint256The amount of token input
maxErroruint256The maximum acceptable difference between the resulting PYT & NYT balances. Might not be achieved if MAX_BINARY_SEARCH_ITERATIONS is reached.
NameTypeDescription
swapAmountInuint256The amount of NYT to swap into xPYT