xPYT
GitHub: link
Permissionless auto-compounding vault for Timeless perpetual yield tokens
Errors
Error_InsufficientOutput
error Error_InsufficientOutput()
Error_InvalidMultiplierValue
error Error_InvalidMultiplierValue()
Error_ConsultTwapOracleFailed
error Error_ConsultTwapOracleFailed()
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.
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.
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 |