UniswapV3xPYT
GitHub: link
xPYT implementation using Uniswap V3 to swap NYT into PYT
Errors
Error_InsufficientOutput
error Error_InsufficientOutput()
Error_InvalidMultiplierValue
error Error_InvalidMultiplierValue()
Error_ConsultTwapOracleFailed
error Error_ConsultTwapOracleFailed()
Error_NotUniswapV3Pool
error Error_NotUniswapV3Pool()
Error_BothTokenDeltasAreZero
error Error_BothTokenDeltasAreZero()
Structs
SwapCallbackData
struct SwapCallbackData {
contract ERC20 tokenIn;
contract ERC20 tokenOut;
uint24 fee;
}
Events
Pound
event Pound(address sender, address pounderRewardRecipient, uint256 yieldAmount, uint256 pytCompounded, uint256 pounderReward)
Enums
PreviewPoundErrorCode
enum PreviewPoundErrorCode {
OK,
TWAP_FAIL,
INSUFFICIENT_OUTPUT
}
Constants
ONE
uint256 ONE
The base unit for fixed point decimals.
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
gate
contract Gate gate
The Gate associated with the PYT.
vault
address vault
The vault associated with the PYT.
nyt
contract NegativeYieldToken nyt
The NYT associated with the PYT.
minOutputMultiplier
uint256 minOutputMultiplier
The minimum acceptable ratio between the NYT output in pound() and the expected NYT output based on the TWAP. Scaled by ONE.
pounderRewardMultiplier
uint256 pounderRewardMultiplier
The proportion of the yield claimed in pound() to give to the caller as reward. Scaled by ONE.
uniswapV3Factory
address uniswapV3Factory
The official Uniswap V3 factory address
uniswapV3Quoter
contract IQuoter uniswapV3Quoter
The Uniswap V3 Quoter deployment
uniswapV3PoolFee
uint24 uniswapV3PoolFee
The fee used by the Uniswap V3 pool used for swapping
uniswapV3Quoter
uint32 uniswapV3TwapSecondsAgo
The number of seconds in the past from which to take the TWAP of the Uniswap V3 pool
State variables
assetBalance
uint256 assetBalance
The recorded balance of the deposited asset.
This is used instead of asset.balanceOf(address(this)) to prevent attackers from atomically increasing the vault share value and thus exploiting integrated lending protocols.
Public functions
pound
function pound(address pounderRewardRecipient) external virtual returns (uint256 yieldAmount, uint256 pytCompounded, uint256 pounderReward)
Claims the yield earned by the PYT held and sells the claimed NYT into more PYT.
Part of the claimed yield is given to the caller as reward, which incentivizes MEV bots to perform the auto-compounding for us.
Name | Type | Description |
---|---|---|
pounderRewardRecipient | address | The address that will receive the caller reward |
Name | Type | Description |
---|---|---|
yieldAmount | uint256 | The amount of PYT & NYT claimed as yield |
pytCompounded | uint256 | The amount of PYT distributed to xPYT holders |
pounderReward | uint256 | The amount of caller reward given, in PYT |
previewPound
function previewPound() external returns (enum xPYT.PreviewPoundErrorCode errorCode, uint256 yieldAmount, uint256 pytCompounded, uint256 pounderReward)
Previews the result of calling pound()
Name | Type | Description |
---|---|---|
errorCode | enum xPYT.PreviewPoundErrorCode | The end state of pound() |
yieldAmount | uint256 | The amount of PYT & NYT claimed as yield |
pytCompounded | uint256 | The amount of PYT distributed to xPYT holders |
pounderReward | uint256 | The amount of caller reward given, in PYT |
sweep
function sweep(address receiver) external virtual returns (uint256 shares)
Uses the extra asset balance of the xPYT contract to mint shares
Name | Type | Description |
---|---|---|
receiver | address | The recipient of the minted shares |
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares minted |
totalAssets
function totalAssets() public view virtual returns (uint256)
beforeWithdraw
function beforeWithdraw(uint256 assets, uint256) internal virtual
afterDeposit
function afterDeposit(uint256 assets, uint256) internal virtual
Internal functions
_getTwapQuote
function _getTwapQuote(uint256 nytAmountIn) internal view virtual returns (bool success, uint256 xPytAmountOut)
Consults the TWAP oracle to get a quote for how much xPYT will be received from swapping
nytAmountIn
NYT.
Name | Type | Description |
---|---|---|
nytAmountIn | uint256 | The amount of NYT to swap |
Name | Type | Description |
---|---|---|
success | bool | True if the call to the TWAP oracle was successful, false otherwise |
xPytAmountOut | uint256 | The amount of xPYT that will be received from the swap |
_swap
function _swap(uint256 nytAmountIn) internal virtual returns (uint256 xPytAmountOut)
Swaps nytAmountIn
NYT into xPYT using the underlying DEX
Name | Type | Description |
---|---|---|
nytAmountIn | uint256 | The amount of NYT to swap |
Name | Type | Description |
---|---|---|
xPytAmountOut | uint256 | The amount of xPYT received from the swap |
_quote
function _quote(uint256 nytAmountIn) internal virtual returns (uint256 xPytAmountOut)
Gets a quote from the underlying DEX for swapping nytAmountIn
NYT into xPYT
Name | Type | Description |
---|---|---|
nytAmountIn | uint256 | The amount of NYT to swap |
Name | Type | Description |
---|---|---|
xPytAmountOut | uint256 | The amount of xPYT that will be received from the swap |