Skip to content
Verified contractPartialMIT

PPYieldTokenZap

Address0x33c1eef370bbb447414156cfc4fdabd434776eaf
Balance

0 ETH

 

Transactions

12

 

Compiler

solc 0.8.32

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.32+commit.ebbd65e5
Language
solidity
Optimization
Yes, 10,000 runs
EVM version
prague
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,985,057
Creation transaction
0xf6bc08640e…c4d69e04a9

src/contracts/PPYieldTokenZap.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.32;

import {IAavePool} from 'interfaces/IAavePool.sol';
import {IPPYieldToken} from 'interfaces/IPPYieldToken.sol';
import {IPPYieldTokenZap} from 'interfaces/IPPYieldTokenZap.sol';

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

/// @title PPYieldTokenZap
/// @author 0xbow
/// @notice Stateless convenience router: underlying <-> pp-share in one call. `depositUnderlying`
/// supplies the underlying to Aave and wraps the resulting aToken into pp-shares; `redeemToUnderlying`
/// redeems pp-shares to aTokens and withdraws the underlying. The contract holds no funds between
/// transactions. One zap is deployed per `PPYieldToken` wrapper (e.g. a USDC zap over ppUSDC).
contract PPYieldTokenZap is IPPYieldTokenZap {
  using SafeERC20 for IERC20;

  /*///////////////////////////////////////////////////////////////
                          CONSTANTS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Underlying over-supplied so the exact `mint` can never revert on Aave's index round-trip.
  /// @dev A single `supply(x)` credits `x` or `x - 1` wei of aToken (scaledBalance round-trip), so a
  ///      1-wei buffer suffices; 2 is used for margin. This is the only value forfeited per exact mint.
  uint256 internal constant _SUPPLY_ROUNDING_BUFFER = 2;

  /*///////////////////////////////////////////////////////////////
                          IMMUTABLES
  ///////////////////////////////////////////////////////////////*/

  /// @inheritdoc IPPYieldTokenZap
  IPPYieldToken public immutable VAULT;

  /// @inheritdoc IPPYieldTokenZap
  IAavePool public immutable POOL;

  /// @inheritdoc IPPYieldTokenZap
  IERC20 public immutable UNDERLYING;

  /// @inheritdoc IPPYieldTokenZap
  IERC20 public immutable A_TOKEN;

  /*///////////////////////////////////////////////////////////////
                          CONSTRUCTOR
  ///////////////////////////////////////////////////////////////*/

  /// @param _vault The PPYieldToken wrapper
  /// @param _pool The Aave v3 pool
  /// @param _underlying The underlying token supplied to Aave (e.g. USDC)
  constructor(IPPYieldToken _vault, IAavePool _pool, IERC20 _underlying) {
    require(
      address(_vault) != address(0) && address(_pool) != address(0) && address(_underlying) != address(0),
      PPYieldTokenZap_ZeroAddress()
    );
    VAULT = _vault;
    POOL = _pool;
    UNDERLYING = _underlying;
    A_TOKEN = IERC20(_vault.asset());
  }

  /*///////////////////////////////////////////////////////////////
                          MUTATIVE FUNCTIONS
  ///////////////////////////////////////////////////////////////*/

  /// @inheritdoc IPPYieldTokenZap
  function depositUnderlying(uint256 _underlyingAmount, address _receiver) external returns (uint256 _shares) {
    require(_underlyingAmount != 0, PPYieldTokenZap_ZeroAmount());

    UNDERLYING.safeTransferFrom(msg.sender, address(this), _underlyingAmount);
    UNDERLYING.forceApprove(address(POOL), _underlyingAmount);

    // Credit only the aTokens THIS supply produces (balance delta), never the absolute balance:
    // crediting balanceOf would let an attacker pre-donate aTokens and have the next caller sweep
    // them into their shares (last-caller-wins griefing). aTokens rebase, so the delta (not
    // `_underlyingAmount`) is the exact amount received; any donated balance is left untouched.
    uint256 _aBefore = A_TOKEN.balanceOf(address(this));
    POOL.supply({_asset: address(UNDERLYING), _amount: _underlyingAmount, _onBehalfOf: address(this), _referralCode: 0});
    uint256 _aReceived = A_TOKEN.balanceOf(address(this)) - _aBefore;

    A_TOKEN.forceApprove(address(VAULT), _aReceived);
    _shares = VAULT.deposit(_aReceived, _receiver);

    emit ZappedIn({_sender: msg.sender, _receiver: _receiver, _underlyingIn: _underlyingAmount, _shares: _shares});
  }

  /// @inheritdoc IPPYieldTokenZap
  function buyFixedYieldToken(
    uint256 _shares,
    address _receiver,
    uint256 _maxUnderlyingIn
  ) external returns (uint256 _underlyingIn) {
    require(_shares != 0, PPYieldTokenZap_ZeroAmount());
    uint256 _aNeeded = VAULT.previewMint(_shares);
    _underlyingIn = _aNeeded + _SUPPLY_ROUNDING_BUFFER;
    require(_underlyingIn <= _maxUnderlyingIn, PPYieldTokenZap_SlippageExceeded(_underlyingIn, _maxUnderlyingIn));

    UNDERLYING.safeTransferFrom(msg.sender, address(this), _underlyingIn);
    UNDERLYING.forceApprove(address(POOL), _underlyingIn);

    // Measure the aTokens THIS supply produces (delta), not the absolute balance, so a pre-donated
    // aToken balance can neither satisfy the wrap check below nor be swept as dust (griefing).
    uint256 _aBefore = A_TOKEN.balanceOf(address(this));
    POOL.supply({_asset: address(UNDERLYING), _amount: _underlyingIn, _onBehalfOf: address(this), _referralCode: 0});
    uint256 _aReceived = A_TOKEN.balanceOf(address(this)) - _aBefore;

    require(_aReceived >= _aNeeded, PPYieldTokenZap_InsufficientWrap(_aReceived, _aNeeded));
    A_TOKEN.forceApprove(address(VAULT), _aNeeded);
    VAULT.mint(_shares, _receiver);

    // Forward only THIS call's residual aToken dust (balance above the pre-supply baseline) to the
    // receiver so the zap stays stateless; any pre-donated balance is left untouched.
    uint256 _dust = A_TOKEN.balanceOf(address(this)) - _aBefore;
    if (_dust != 0) A_TOKEN.safeTransfer(_receiver, _dust);

    emit ZappedInExact({_sender: msg.sender, _receiver: _receiver, _underlyingIn: _underlyingIn, _shares: _shares});
  }

  /// @inheritdoc IPPYieldTokenZap
  function redeemToUnderlying(uint256 _shares, address _receiver) external returns (uint256 _underlyingOut) {
    require(_shares != 0, PPYieldTokenZap_ZeroAmount());

    IERC20(address(VAULT)).safeTransferFrom(msg.sender, address(this), _shares);

    // Withdraw only the aTokens THIS redeem produces (balance delta), not the absolute balance:
    // withdrawing balanceOf would let an attacker donate aTokens and have the next caller sweep them.
    uint256 _aBefore = A_TOKEN.balanceOf(address(this));
    VAULT.redeem(_shares, address(this), address(this));
    uint256 _aReceived = A_TOKEN.balanceOf(address(this)) - _aBefore;

    _underlyingOut = POOL.withdraw(address(UNDERLYING), _aReceived, _receiver);

    emit ZappedOut({_sender: msg.sender, _receiver: _receiver, _shares: _shares, _underlyingOut: _underlyingOut});
  }

  /*///////////////////////////////////////////////////////////////
                            VIEWS
  ///////////////////////////////////////////////////////////////*/

  /// @inheritdoc IPPYieldTokenZap
  function quoteBuy(uint256 _shares) external view returns (uint256 _underlyingNeeded) {
    _underlyingNeeded = VAULT.previewMint(_shares) + _SUPPLY_ROUNDING_BUFFER;
  }
}

node_modules/@openzeppelin/contracts/interfaces/IERC1363.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

node_modules/@openzeppelin/contracts/interfaces/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";

node_modules/@openzeppelin/contracts/interfaces/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";

node_modules/@openzeppelin/contracts/interfaces/IERC4626.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC4626.sol)

pragma solidity >=0.6.2;

import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";

/**
 * @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}

node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}

node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

src/interfaces/IAavePool.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.32;

/// @title IAavePool
/// @author 0xbow
/// @notice Minimal subset of the Aave v3 Pool interface used by PPYieldTokenZap (supply and withdraw).
/// @dev Signatures mirror Aave v3 `IPool` exactly so a real Pool satisfies this interface.
interface IAavePool {
  /// @notice Supplies an asset into the protocol, minting the equivalent aToken to `_onBehalfOf`
  /// @param _asset The underlying asset to supply
  /// @param _amount The amount to supply
  /// @param _onBehalfOf The address that receives the aTokens
  /// @param _referralCode Referral code (unused; pass 0)
  function supply(address _asset, uint256 _amount, address _onBehalfOf, uint16 _referralCode) external;

  /// @notice Withdraws an underlying asset, burning the equivalent aToken owned by the caller
  /// @param _asset The underlying asset to withdraw
  /// @param _amount The amount to withdraw (use type(uint256).max for the full balance)
  /// @param _to The address that receives the underlying
  /// @return _withdrawn The final amount withdrawn
  function withdraw(address _asset, uint256 _amount, address _to) external returns (uint256 _withdrawn);
}

src/interfaces/IPPYieldToken.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.32;

import {IERC4626} from '@openzeppelin/contracts/interfaces/IERC4626.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

/// @title IPPYieldToken
/// @author 0xbow
/// @notice Non-rebasing ERC-4626 wrapper over an Aave v3 aToken (e.g. aUSDC -> ppUSDC). Mints a
/// share token whose exchange rate to the aToken appreciates with Aave yield, net of a protocol fee.
/// Shielding/unshielding a fixed share amount leaks no value delta over time. Yield is realized at
/// unwrap; protocol revenue is the accrued fee, claimable by the admin with no withdrawal fee.
/// @dev `asset()` is the aToken. Shares are always 18 decimals. The exchange rate is always derived
/// live from `asset.balanceOf(this)`; it is never stored. Only `accumulatedFees` is checkpointed
/// lazily, on deposit/withdraw/claim/setFeeBps. The contract is immutable (no proxy); a self-contained
/// admin (the OZ Ownable2Step owner) can claim fees and adjust the fee within `[0, MAX_FEE_BPS]`, and
/// can hand the role to a new admin via the 2-step transfer. See docs/DESIGN.md.
interface IPPYieldToken is IERC4626 {
  /*///////////////////////////////////////////////////////////////
                            EVENTS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Emitted when accrued protocol fees are swept
  /// @param _recipient The address the fees were sent to
  /// @param _amount The amount of aUSDC swept
  event FeesClaimed(address indexed _recipient, uint256 _amount);

  /// @notice Emitted when the admin changes the protocol fee
  /// @param _oldFeeBps The previous fee, in basis points
  /// @param _newFeeBps The new fee, in basis points
  event FeeUpdated(uint256 _oldFeeBps, uint256 _newFeeBps);

  /// @notice Emitted when the admin rescues a stray (non-asset) token
  /// @param _token The token rescued
  /// @param _to The address the token was sent to
  /// @param _amount The amount rescued
  event TokenRescued(address indexed _token, address indexed _to, uint256 _amount);

  /// @notice Emitted when the admin updates the Aave rewards controller
  /// @param _oldController The previous controller
  /// @param _newController The new controller
  event RewardsControllerUpdated(address indexed _oldController, address indexed _newController);

  /*///////////////////////////////////////////////////////////////
                            ERRORS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Thrown at construction or in `setFeeBps` when the fee exceeds `MAX_FEE_BPS`
  error PPYieldToken_FeeTooHigh();

  /// @notice Thrown when a fee-claim recipient is the zero address
  error PPYieldToken_ZeroAddress();

  /// @notice Thrown when a deposit/mint would mint zero shares (dust rounding)
  error PPYieldToken_ZeroShares();

  /// @notice Thrown when a withdraw/redeem would return zero assets (dust rounding)
  error PPYieldToken_ZeroAssets();

  /// @notice Thrown when `rescueToken` targets the underlying asset (aUSDC)
  error PPYieldToken_CannotRescueAsset();

  /// @notice Thrown when `claimRewards` is called while the rewards controller is unset
  error PPYieldToken_RewardsControllerNotSet();

  /// @notice Thrown when attempting to renounce the admin (the role is transferable, never droppable)
  error PPYieldToken_RenounceDisabled();

  /// @notice Thrown at construction when the aToken has more than 18 decimals (offset would underflow)
  error PPYieldToken_UnsupportedDecimals();

  /*///////////////////////////////////////////////////////////////
                          ADMIN FUNCTIONS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Sets the protocol fee (admin only); checkpoints accrued fees at the old rate first
  /// @dev Reverts with `PPYieldToken_FeeTooHigh` if `_newFeeBps > MAX_FEE_BPS`. Does not change the
  /// exchange rate at the moment of the change (already-accrued yield is charged at the old rate).
  /// @param _newFeeBps The new fee, in basis points, in `[0, MAX_FEE_BPS]`
  function setFeeBps(uint256 _newFeeBps) external;

  /// @notice Sweeps accrued protocol fees in aUSDC to `_recipient` (admin only)
  /// @dev Checkpoints pending fee first, zeroes the counter, and does not change the exchange rate.
  /// @param _recipient The address to receive the swept aUSDC (non-zero)
  /// @return _claimed The amount of aUSDC swept
  function claimFees(address _recipient) external returns (uint256 _claimed);

  /// @notice Sweeps accrued protocol fees to the admin (admin only)
  /// @return _claimed The amount of aUSDC swept
  function claimFees() external returns (uint256 _claimed);

  /// @notice Sets the Aave rewards controller used by `claimRewards` (admin only)
  /// @param _rewardsController The new controller (may be zero to disable claiming)
  function setRewardsController(address _rewardsController) external;

  /// @notice Pauses new deposits and mints (admin only); reverts if already paused
  /// @dev Affects `deposit`/`mint` only - `withdraw`/`redeem`/`claimFees` stay open so holders can
  /// always exit. While paused, `maxDeposit`/`maxMint` return 0, so the public `deposit`/`mint`
  /// revert `ERC4626ExceededMaxDeposit`/`ERC4626ExceededMaxMint`. Emits OZ `Paused`.
  function pause() external;

  /// @notice Resumes deposits and mints (admin only); reverts if not paused. Emits OZ `Unpaused`
  function unpause() external;

  /// @notice Claims Aave liquidity-mining rewards accrued by the vault, sending them to `_to` (admin only)
  /// @dev Forwards to `rewardsController.claimAllRewards`. Reverts `PPYieldToken_RewardsControllerNotSet`
  /// if the controller is unset. By the controller's semantics this can only move reward tokens the
  /// vault accrued - never the vault's aUSDC or ppUSDC.
  /// @param _assets The aTokens whose accrued rewards to claim (e.g. [aUSDC])
  /// @param _to The address to receive the reward tokens
  /// @return _rewardsList The reward token addresses claimed
  /// @return _claimedAmounts The amount claimed per reward token
  function claimRewards(
    address[] calldata _assets,
    address _to
  ) external returns (address[] memory _rewardsList, uint256[] memory _claimedAmounts);

  /// @notice Rescues a stray ERC-20 to `_to` (admin only) - airdrops, claimed rewards, stray ppUSDC
  /// @dev Reverts `PPYieldToken_CannotRescueAsset` if `_token` is the underlying asset (aUSDC), so backing
  /// can never be touched. Reverts `PPYieldToken_ZeroAddress` if `_to` is zero.
  /// @param _token The token to rescue (must not be the asset)
  /// @param _to The address to receive the tokens
  /// @param _amount The amount to rescue
  function rescueToken(IERC20 _token, address _to, uint256 _amount) external;

  /*///////////////////////////////////////////////////////////////
                          CONSTANTS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Basis-point denominator (100%)
  /// @return _maxBps The value 10_000
  function MAX_BPS() external view returns (uint256 _maxBps);

  /// @notice Hard ceiling on the protocol fee (20%), enforced at construction and in `setFeeBps`
  /// @return _maxFeeBps The value 2_000
  function MAX_FEE_BPS() external view returns (uint256 _maxFeeBps);

  /*///////////////////////////////////////////////////////////////
                          STATE GETTERS
  ///////////////////////////////////////////////////////////////*/

  /// @notice The current protocol yield fee, in basis points (admin-adjustable within MAX_FEE_BPS)
  /// @return _feeBps The fee applied to each yield accrual
  function feeBps() external view returns (uint256 _feeBps);

  /// @notice The protocol admin (alias for the Ownable2Step owner): claims fees and sets the fee
  /// @return _admin The current admin address
  function admin() external view returns (address _admin);

  /// @notice Checkpointed protocol-owed aUSDC that does not back ppUSDC
  /// @return _accumulatedFees The checkpointed fee balance (excludes fee accrued since last checkpoint)
  function accumulatedFees() external view returns (uint256 _accumulatedFees);

  /// @notice The wrapper's aUSDC balance recorded at the last checkpoint
  /// @return _lastCheckpointBalance The post-action balance from the last deposit/withdraw/claim/setFeeBps
  function lastCheckpointBalance() external view returns (uint256 _lastCheckpointBalance);

  /// @notice The Aave rewards controller used by `claimRewards` (admin-settable; zero if unset)
  /// @return _rewardsController The current rewards controller address
  function rewardsController() external view returns (address _rewardsController);

  /// @notice Whether new deposits/mints are paused (withdraw/redeem/claimFees are never paused)
  /// @return _paused True if `deposit`/`mint` are currently disabled
  function paused() external view returns (bool _paused);

  /*///////////////////////////////////////////////////////////////
                          DERIVED VIEWS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Total fee currently claimable, including yield accrued since the last checkpoint
  /// @return _claimableFees `accumulatedFees` plus the not-yet-checkpointed pending fee
  function claimableFees() external view returns (uint256 _claimableFees);

  /// @notice The live exchange rate: aUSDC redeemable for one whole ppUSDC (`10 ** decimals()` shares)
  /// @dev Equals `convertToAssets(10 ** decimals())`. Asset-denominated (1:1 base = `10 ** assetDecimals`).
  /// @return _exchangeRate aUSDC value of one whole ppUSDC
  function exchangeRate() external view returns (uint256 _exchangeRate);
}

src/interfaces/IPPYieldTokenZap.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.32;

import {IAavePool} from 'interfaces/IAavePool.sol';
import {IPPYieldToken} from 'interfaces/IPPYieldToken.sol';

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

/// @title IPPYieldTokenZap
/// @author 0xbow
/// @notice Stateless convenience router: underlying <-> pp-share in one call, routing through Aave v3
/// (supply/withdraw) and a `PPYieldToken` wrapper (deposit/redeem). One zap is deployed per wrapper
/// (e.g. a USDC zap over ppUSDC). Holds no funds between transactions.
interface IPPYieldTokenZap {
  /*///////////////////////////////////////////////////////////////
                            EVENTS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Emitted on an underlying -> pp-share zap
  /// @param _sender The caller who supplied the underlying
  /// @param _receiver The address that received the shares
  /// @param _underlyingIn The underlying supplied
  /// @param _shares The pp-shares minted
  event ZappedIn(address indexed _sender, address indexed _receiver, uint256 _underlyingIn, uint256 _shares);

  /// @notice Emitted on an exact-output underlying -> pp-share zap (mints exactly `_shares`)
  /// @param _sender The caller who supplied the underlying
  /// @param _receiver The address that received the shares
  /// @param _underlyingIn The underlying pulled from the caller (`previewMint(shares) + buffer`)
  /// @param _shares The pp-shares minted (exactly the requested amount)
  event ZappedInExact(address indexed _sender, address indexed _receiver, uint256 _underlyingIn, uint256 _shares);

  /// @notice Emitted on a pp-share -> underlying zap
  /// @param _sender The caller who supplied the shares
  /// @param _receiver The address that received the underlying
  /// @param _shares The pp-shares redeemed
  /// @param _underlyingOut The underlying returned
  event ZappedOut(address indexed _sender, address indexed _receiver, uint256 _shares, uint256 _underlyingOut);

  /*///////////////////////////////////////////////////////////////
                            ERRORS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Thrown at construction when any dependency address is zero
  error PPYieldTokenZap_ZeroAddress();

  /// @notice Thrown when a zap amount or share count is zero
  error PPYieldTokenZap_ZeroAmount();

  /// @notice Thrown when the underlying needed to mint the requested shares exceeds the caller's bound
  /// @param _required The underlying the zap must pull to mint exactly the requested shares (+ buffer)
  /// @param _maxUnderlyingIn The caller's ceiling
  error PPYieldTokenZap_SlippageExceeded(uint256 _required, uint256 _maxUnderlyingIn);

  /// @notice Thrown (defensively) when the aToken credited by the supply is below what the exact mint
  ///         needs — should be impossible given the rounding buffer; signals unexpected pool rounding
  /// @param _received The aToken balance credited by the supply
  /// @param _needed The aToken the exact mint consumes (`previewMint(shares)`)
  error PPYieldTokenZap_InsufficientWrap(uint256 _received, uint256 _needed);

  /*///////////////////////////////////////////////////////////////
                          MUTATIVE FUNCTIONS
  ///////////////////////////////////////////////////////////////*/

  /// @notice Supplies the underlying to Aave and wraps the resulting aToken into pp-shares for `_receiver`
  /// @param _underlyingAmount The underlying to pull from the caller
  /// @param _receiver The address that receives the minted pp-shares
  /// @return _shares The pp-shares minted
  function depositUnderlying(uint256 _underlyingAmount, address _receiver) external returns (uint256 _shares);

  /// @notice Supplies the underlying to Aave and mints EXACTLY `_shares` pp-shares to `_receiver`
  /// @dev Exact-output counterpart of {depositUnderlying}: the share count is hit exactly while the
  ///      underlying spent floats up to `_maxUnderlyingIn` (rate drift between quote and execution). The
  ///      mint is driven off `previewMint`, never off this contract's balance, so a stray aToken float
  ///      cannot skew the amount; the ≤ buffer wei of aToken dust is forwarded to `_receiver` so the zap
  ///      stays stateless.
  /// @param _shares The pp-shares to mint (the exact output)
  /// @param _receiver The address that receives the minted pp-shares (and any aToken dust)
  /// @param _maxUnderlyingIn The maximum underlying the caller authorizes (slippage / validity bound)
  /// @return _underlyingIn The underlying actually pulled from the caller
  function buyFixedYieldToken(
    uint256 _shares,
    address _receiver,
    uint256 _maxUnderlyingIn
  ) external returns (uint256 _underlyingIn);

  /// @notice Redeems pp-shares to aTokens and withdraws the underlying from Aave to `_receiver`
  /// @param _shares The pp-shares to pull from the caller
  /// @param _receiver The address that receives the underlying
  /// @return _underlyingOut The underlying returned
  function redeemToUnderlying(uint256 _shares, address _receiver) external returns (uint256 _underlyingOut);

  /*///////////////////////////////////////////////////////////////
                          IMMUTABLES
  ///////////////////////////////////////////////////////////////*/

  /// @notice The PPYieldToken wrapper
  /// @return _vault The wrapper
  function VAULT() external view returns (IPPYieldToken _vault);

  /// @notice The Aave v3 pool
  /// @return _pool The pool
  function POOL() external view returns (IAavePool _pool);

  /// @notice The underlying token supplied to Aave (e.g. USDC)
  /// @return _underlying The underlying token
  function UNDERLYING() external view returns (IERC20 _underlying);

  /// @notice The Aave aToken (the wrapper's asset)
  /// @return _aToken The aToken
  function A_TOKEN() external view returns (IERC20 _aToken);

  /*///////////////////////////////////////////////////////////////
                            VIEWS
  ///////////////////////////////////////////////////////////////*/

  /// @notice The underlying needed to mint exactly `_shares` pp-shares, at the live rate
  /// @dev Callers should pass `maxUnderlyingIn >= underlyingNeeded` to {buyFixedYieldToken}, with a small
  ///      margin for the rate moving further between this read and execution. Adds the supply buffer so
  ///      the exact `mint` can never revert on Aave's index round-trip.
  /// @param _shares The pp-shares to mint
  /// @return _underlyingNeeded The underlying the zap would pull (`previewMint(shares) + buffer`)
  function quoteBuy(uint256 _shares) external view returns (uint256 _underlyingNeeded);
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 10000,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "forge-std/=node_modules/forge-std/src/",
    "abstracts/=src/abstracts/",
    "contracts/=src/contracts/",
    "interfaces/=src/interfaces/",
    "libraries/=src/libraries/",
    "utils/=src/utils/",
    "test/=test/",
    "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
    "@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
    "@lean-imt/=lib/lean-imt/",
    "poseidon-solidity/=node_modules/poseidon-solidity/",
    "verifiers/=../circuits/build/",
    "@safe-smart-account/=node_modules/@safe-global/safe-contracts/contracts/",
    "@safe-global/=node_modules/@safe-global/",
    "@zk-kit/=node_modules/@zk-kit/",
    "lean-imt/=lib/lean-imt/",
    "solady/=node_modules/solady/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.