Skip to main content

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.

NameTypeDescription
pounderRewardRecipientaddressThe address that will receive the caller reward
NameTypeDescription
yieldAmountuint256The amount of PYT & NYT claimed as yield
pytCompoundeduint256The amount of PYT distributed to xPYT holders
pounderRewarduint256The 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()

NameTypeDescription
errorCodeenum xPYT.PreviewPoundErrorCodeThe end state of pound()
yieldAmountuint256The amount of PYT & NYT claimed as yield
pytCompoundeduint256The amount of PYT distributed to xPYT holders
pounderRewarduint256The 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

NameTypeDescription
receiveraddressThe recipient of the minted shares
NameTypeDescription
sharesuint256The 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.

NameTypeDescription
nytAmountInuint256The amount of NYT to swap
NameTypeDescription
successboolTrue if the call to the TWAP oracle was successful, false otherwise
xPytAmountOutuint256The 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

NameTypeDescription
nytAmountInuint256The amount of NYT to swap
NameTypeDescription
xPytAmountOutuint256The 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

NameTypeDescription
nytAmountInuint256The amount of NYT to swap
NameTypeDescription
xPytAmountOutuint256The amount of xPYT that will be received from the swap