Skip to content
Verified contractExactAGPL-3.0-only

BoringVaultSY

Address0x467d96e5908aaae602d992196fc2425337c2a311
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
osaka
Via IR
yes
License
AGPL-3.0-only
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,086,932
Creation transaction
0x887748ab4d…85f6061383

85 files

The source code is large: one file is shown at a time. Choose a file in the list.

contracts/pendle/BoringVaultSY.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.30;

// libraries
import {PMath} from "@pendle/core-v2/contracts/core/libraries/math/PMath.sol";
import {ArrayLib} from "@pendle/core-v2/contracts/core/libraries/ArrayLib.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

// contracts
import {SYBaseUpgV2} from "contracts/vendor/Pendle/SYBaseUpgV2.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {MerklRewardAbstract__NoStorage} from "contracts/vendor/Pendle/MerklRewardAbstract__NoStorage.sol";
import {NestAccountant} from "contracts/accountant/NestAccountant.sol";
import {ERC20} from "@solmate/tokens/ERC20.sol";

// types
import {Errors} from "contracts/types/Errors.sol";

// interfaces
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

/// @title BoringVaultSY
/// @author PlumeNetwork
/// @notice A specialized vault that integrates with Pendle and rate providers via an external accountant.
/// @dev Inherits from Pendle SY base contracts, enabling yield-bearing asset management and Merkl reward distribution.
///      Reference : https://github.com/pendle-finance/Pendle-SY-Public/blob/21ccfee6c24936fb73c1ae78d1a87c83b05f105c/contracts/core/StandardizedYield/implementations/PendleERC4626NoRedeemNoDepositUpgSY.sol
contract BoringVaultSY is Initializable, SYBaseUpgV2, MerklRewardAbstract__NoStorage {
    /// @notice The base asset associated with this vault (ERC20 token address)
    /// @dev Immutable; set once at deployment
    address public immutable asset;

    /// @notice The minimum rate allowed for exchange calculation
    /// @dev This constant represents the smallest allowed rate
    uint256 public immutable MIN_RATE;

    /// @notice The maximum rate allowed for certain calculations (e.g., fee rates)
    /// @dev This constant prevents overflow by capping the rate at 1e30 in base units
    uint256 public constant MAX_RATE = 1e30; // Example: prevent overflow

    /// @dev Ensures consistent math when converting between shares and assets
    uint256 internal immutable ONE_SHARE;

    /*//////////////////////////////////////////////////////////////
                        ERC-7201 STORAGE
    //////////////////////////////////////////////////////////////*/

    /// @custom:storage-location erc7201:plumenetwork.storage.BoringVaultSY
    struct BoringVaultSYStorage {
        NestAccountant accountant;
    }

    // keccak256(abi.encode(uint256(keccak256("plumenetwork.storage.BoringVaultSY")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant BoringVaultSYStorageLocation =
        0xba3cecd4d64affe75cd39a3d4a8081a70ba26075a4ef33e74e52794a68cdc400;

    function _getBoringVaultSYStorage() private pure returns (BoringVaultSYStorage storage $) {
        assembly {
            $.slot := BoringVaultSYStorageLocation
        }
    }

    /// @notice Constructs the PendleNestVault contract
    /// @param _erc4626 The ERC4626-compatible yield token (SYBase) to wrap
    /// @param _offchainRewardManager The address managing off-chain Merkl reward reporting
    /// @param _asset The address of underlying asset
    /// @param _minRate The minimum rate allowed for the vault, it should be less than the decimals of the underlying asset
    constructor(address _erc4626, address _offchainRewardManager, address _asset, uint256 _minRate)
        SYBaseUpgV2(_erc4626)
        MerklRewardAbstract__NoStorage(_offchainRewardManager)
    {
        asset = _asset;
        ONE_SHARE = 10 ** IERC20Metadata(_erc4626).decimals();
        if (_minRate >= 10 ** IERC20Metadata(_asset).decimals()) {
            revert Errors.InvalidRate();
        }
        MIN_RATE = _minRate;
    }

    /// @notice Initializes the PendleNestVault after deployment
    /// @dev Should be called only once. Sets vault metadata and the rate accountant
    /// @param _accountant The address of the Nest accountant
    /// @param _name The vault token name
    /// @param _symbol The vault token symbol
    /// @param _owner The address with ownership privileges
    function initialize(address _accountant, string memory _name, string memory _symbol, address _owner)
        external
        virtual
        initializer
    {
        _setAccountant(_accountant);
        __SYBaseUpgV2_init(_name, _symbol, _owner);
    }

    /// @notice Returns the version of the BoringVaultSY contract.
    /// @dev    This version is used to track contract upgrades.
    /// @return string A string representing the version of the contract.
    function version() public pure returns (string memory) {
        return "2.0.0";
    }

    /// @dev Shared accountant validation and assignment logic.
    ///      Cross-checks the accountant returns a sane rate for `asset` rather than asserting share identity,
    ///      since the Nest accountants do not expose a vault getter.
    function _setAccountant(address _accountant) internal {
        if (_accountant == address(0)) {
            revert Errors.ZeroAddress();
        }

        NestAccountant acc = NestAccountant(_accountant);

        uint256 rate = acc.getRateInQuoteSafe(ERC20(asset));
        if (rate == 0) revert Errors.InvalidRate();
        if (rate < MIN_RATE || rate > MAX_RATE) revert Errors.RateOutOfBounds();

        _getBoringVaultSYStorage().accountant = acc;
    }

    /// @dev Returns 1:1 shares for deposited amount since vault and token are equivalent.
    /// @param amountDeposited The amount of token deposited.
    /// @return amountSharesOut The amount of shares issued (equal to amountDeposited).
    function _deposit(
        address,
        /*tokenIn*/
        uint256 amountDeposited
    )
        internal
        virtual
        override
        returns (
            uint256 /*amountSharesOut*/
        )
    {
        return amountDeposited;
    }

    /// @dev Transfers out the corresponding amount of yield tokens to the receiver.
    /// @param receiver The address receiving redeemed tokens.
    /// @param amountSharesToRedeem The amount of shares to redeem.
    /// @return amountRedeemed The amount of underlying tokens redeemed (equal to shares).
    function _redeem(
        address receiver,
        address,
        /*tokenOut*/
        uint256 amountSharesToRedeem
    )
        internal
        virtual
        override
        returns (uint256)
    {
        _transferOut(yieldToken, receiver, amountSharesToRedeem);
        return amountSharesToRedeem;
    }

    /// @notice Returns the current exchange rate between assets and shares
    /// @dev Uses rate provided by the accountant and normalized by `ONE_SHARE`
    /// @return The exchange rate as a fixed-point number
    function exchangeRate() public view virtual override returns (uint256) {
        return Math.mulDiv(PMath.ONE, _getValidatedRate(), ONE_SHARE, Math.Rounding.Floor);
    }

    /// @dev Returns 1:1 shares for deposit previews.
    /// @param amountTokenToDeposit The amount of input tokens to deposit.
    /// @return amountSharesOut The expected number of shares to be minted.
    function _previewDeposit(
        address,
        /*tokenIn*/
        uint256 amountTokenToDeposit
    )
        internal
        view
        virtual
        override
        returns (
            uint256 /*amountSharesOut*/
        )
    {
        return amountTokenToDeposit;
    }

    /// @dev Returns 1:1 token output for shares redeemed.
    /// @param amountSharesToRedeem The number of shares to redeem.
    /// @return amountTokenOut The expected token output amount.
    function _previewRedeem(
        address,
        /*tokenOut*/
        uint256 amountSharesToRedeem
    )
        internal
        view
        virtual
        override
        returns (
            uint256 /*amountTokenOut*/
        )
    {
        return amountSharesToRedeem;
    }

    /// @notice Returns the accountant that provides the exchange rate for this SY
    function accountant() external view returns (NestAccountant) {
        return _getBoringVaultSYStorage().accountant;
    }

    /// @notice Returns the list of valid input tokens for deposits.
    /// @dev Always returns the yield token.
    /// @return res Array containing only the yield token address.
    function getTokensIn() public view virtual override returns (address[] memory res) {
        return ArrayLib.create(yieldToken);
    }

    /// @notice Returns the list of valid output tokens for withdrawals
    /// @dev Always returns the yield token
    /// @return res Array containing only the yield token address
    function getTokensOut() public view virtual override returns (address[] memory res) {
        return ArrayLib.create(yieldToken);
    }

    /// @notice Checks if a token is valid for deposits
    /// @param token The address of the token to check
    /// @return True if the token matches the yield token, false otherwise
    function isValidTokenIn(address token) public view virtual override returns (bool) {
        return token == yieldToken;
    }

    /// @notice Checks if a token is valid for redemptions.
    /// @param token The address of the token to check.
    /// @return True if the token matches the yield token, false otherwise.
    function isValidTokenOut(address token) public view virtual override returns (bool) {
        return token == yieldToken;
    }

    /// @notice Returns information about the underlying asset.
    /// @return assetType The type of asset (always TOKEN).
    /// @return assetAddress The address of the underlying ERC20 asset.
    /// @return assetDecimals The decimals of the underlying asset.
    function assetInfo()
        external
        view
        virtual
        returns (AssetType assetType, address assetAddress, uint8 assetDecimals)
    {
        return (AssetType.TOKEN, asset, IERC20Metadata(asset).decimals());
    }

    /// @dev Internal helper to validate rate from external oracle
    function _getValidatedRate() internal view returns (uint256 rate) {
        rate = _getBoringVaultSYStorage().accountant.getRateInQuoteSafe(ERC20(asset));

        // prevent division by zero
        if (rate == 0) revert Errors.InvalidRate();

        // prevent extreme values
        if (rate < MIN_RATE || rate > MAX_RATE) {
            revert Errors.RateOutOfBounds();
        }

        return rate;
    }

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

    /// @notice Updates the accountant
    /// @dev Only authorized entity can update the accountant
    /// @param _accountant The new accountant address
    function setAccountant(address _accountant) external onlyOwner {
        _setAccountant(_accountant);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "osaka",
  "remappings": [
    "forge-std/=node_modules/forge-std/src/",
    "@openzeppelin/=node_modules/@openzeppelin/",
    "@openzeppelin-4.9.3/=script/vendor/openzeppelin-4.9.3/",
    "@solmate/=node_modules/solmate/src/",
    "@boring-vault/=node_modules/boring-vault/",
    "src/=node_modules/boring-vault/src/",
    "@predicate/=node_modules/@predicate/contracts/",
    "@pendle/=node_modules/@pendle/",
    "createx/=node_modules/createx/src/",
    "solidity-bytes-utils/contracts/=node_modules/@layerzerolabs/toolbox-foundry/lib/solidity-bytes-utils/",
    "@layerzerolabs/=node_modules/@layerzerolabs/",
    "@uniswap/permit2/=node_modules/@uniswap/permit2/src/",
    "@morpho/=node_modules/morpho/src/",
    "boring-vault/=node_modules/boring-vault/",
    "ds-test/=node_modules/@layerzerolabs/toolbox-foundry/lib/ds-test/",
    "hardhat-deploy/=node_modules/hardhat-deploy/",
    "hardhat/=node_modules/hardhat/",
    "morpho/=node_modules/morpho/",
    "solmate/=node_modules/solmate/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.