Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/core/StandardizedYield/implementations/InfiniFi/PendleInfiniFisiUSD.sol": {
"content": "// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.17;
import "../../SYBaseUpg.sol";
import "../../../../interfaces/IERC4626.sol";
import "../PendleERC4626UpgSYV2.sol";
interface IInfiniFiGateway {
function stake(address _to, uint256 _receiptTokens) external returns (uint256);
function redeem(address _to, uint256 _amount, uint256 _minAssetsOut) external returns (uint256);
function unstake(address _to, uint256 _stakedTokens) external returns (uint256);
function getAddress(string memory _name) external view returns (address);
function mintAndStake(address _to, uint256 _amount) external returns (uint256);
}
interface IYieldSharing {
function vested() external view returns (uint256);
}
interface IRedeemController {
function receiptToAsset(uint256 _receiptAmount) external view returns (uint256);
}
interface IMintController {
function assetToReceipt(uint256 _assetAmount) external view returns (uint256);
}
contract PendleInfinifiSIUSD is PendleERC4626UpgSYV2 {
using PMath for uint256;
address public constant IUSD = 0x48f9e38f3070AD8945DFEae3FA70987722E3D89c;
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address public constant SIUSD = 0xDBDC1Ef57537E34680B898E1FEBD3D68c7389bCB;
address public constant GATEWAY = 0x3f04b65Ddbd87f9CE0A2e7Eb24d80e7fb87625b5;
address public constant PENDLE_PAUSE_CONTROLLER = 0x2aD631F72fB16d91c4953A7f4260A97C2fE2f31e;
error UnsupportedToken(address _token);
constructor() PendleERC4626UpgSYV2(SIUSD) {}
function initialize(string memory _name, string memory _symbol) external override initializer {
__SYBaseUpg_init(_name, _symbol);
_safeApproveInf(IUSD, GATEWAY);
_safeApproveInf(USDC, GATEWAY);
_safeApproveInf(SIUSD, GATEWAY);
// sets pendle pauser as a new owner on deployment and renounces the role right away
transferOwnership({newOwner: PENDLE_PAUSE_CONTROLLER, direct: true, renounce: true});
}
function _deposit(address tokenIn, uint256 amountDeposited)
internal
override
returns (uint256 /*amountSharesOut*/ )
{
if (tokenIn == IUSD) {
return IInfiniFiGateway(GATEWAY).stake(address(this), amountDeposited);
}
if (tokenIn == USDC) {
uint256 amountBefore = IERC4626(SIUSD).balanceOf(address(this));
IInfiniFiGateway(GATEWAY).mintAndStake(address(this), amountDeposited);
uint256 amountAfter = IERC4626(SIUSD).balanceOf(address(this));
return amountAfter - amountBefore;
}
if (tokenIn == SIUSD) {
return amountDeposited;
}
revert UnsupportedToken(tokenIn);
}
function _redeem(address receiver, address tokenOut, uint256 amountSharesToRedeem)
internal
override
returns (uint256 /*amountTokenOut*/ )
{
if (tokenOut == IUSD) {
return IInfiniFiGateway(GATEWAY).unstake(receiver, amountSharesToRedeem);
}
if (tokenOut == USDC) {
// unstake from siUSD to iUSD
uint256 receiptOut = IInfiniFiGateway(GATEWAY).unstake(address(this), amountSharesToRedeem);
address redeemController = IInfiniFiGateway(GATEWAY).getAddress("redeemController");
// convert iUSD to USDC
uint256 assetsOut = IRedeemController(redeemController).receiptToAsset(receiptOut);
// redeem iUSD, assetsOut is in USDC
return IInfiniFiGateway(GATEWAY).redeem(receiver, receiptOut, assetsOut);
}
if (tokenOut == SIUSD) {
_transferOut(SIUSD, receiver, amountSharesToRedeem);
return amountSharesToRedeem;
}
revert UnsupportedToken(tokenOut);
}
// returns exchange rate in iUSD
function exchangeRate() public view override returns (uint256) {
return _convertToAssets(PMath.ONE);
}
function _previewDeposit(address tokenIn, uint256 amountTokenToDeposit)
internal
view
override
returns (uint256 /*amountSharesOut*/ )
{
if (tokenIn == IUSD) {
return _convertToShares(amountTokenToDeposit);
}
if (tokenIn == USDC) {
address mintController = IInfiniFiGateway(GATEWAY).getAddress("mintController");
// preview USDC to iUSD conversion
uint256 receiptTokens = IMintController(mintController).assetToReceipt(amountTokenToDeposit);
return _convertToShares(receiptTokens);
}
if (tokenIn == SIUSD) {
return amountTokenToDeposit;
}
revert UnsupportedToken(tokenIn);
}
function _previewRedeem(address tokenOut, uint256 amountSharesToRedeem)
internal
view
override
returns (uint256 /*amountTokenOut*/ )
{
if (tokenOut == IUSD) {
return _convertToAssets(amountSharesToRedeem);
}
if (tokenOut == USDC) {
// see how much iUSD we get from redeeming siUSD
uint256 receiptOut = _convertToAssets(amountSharesToRedeem);
address redeemController = IInfiniFiGateway(GATEWAY).getAddress("redeemController");
// convert iUSD to USDC
return IRedeemController(redeemController).receiptToAsset(receiptOut);
}
if (tokenOut == SIUSD) {
return amountSharesToRedeem;
}
revert UnsupportedToken(tokenOut);
}
function _convertToShares(uint256 _receiptIn) internal view returns (uint256 /* _sharesOut */ ) {
uint256 vested = IYieldSharing(IInfiniFiGateway(GATEWAY).getAddress("yieldSharing")).vested();
uint256 supply = IERC4626(SIUSD).totalSupply();
uint256 assets = IERC4626(SIUSD).totalAssets() + vested;
return supply == 0 ? _receiptIn : ((_receiptIn * supply) / assets);
}
function _convertToAssets(uint256 _sharesIn) internal view returns (uint256 /* _assetsOut */ ) {
uint256 vested = IYieldSharing(IInfiniFiGateway(GATEWAY).getAddress("yieldSharing")).vested();
uint256 supply = IERC4626(SIUSD).totalSupply();
uint256 assets = IERC4626(SIUSD).totalAssets() + vested;
return supply == 0 ? _sharesIn : (_sharesIn * assets) / supply;
}
function getTokensIn() public pure override returns (address[] memory res) {
res = new address[](3);
res[0] = IUSD;
res[1] = SIUSD;
res[2] = USDC;
}
function getTokensOut() public pure override returns (address[] memory res) {
res = new address[](3);
res[0] = IUSD;
res[1] = SIUSD;
res[2] = USDC;
}
function isValidTokenIn(address token) public pure override returns (bool) {
return token == IUSD || token == SIUSD || token == USDC;
}
function isValidTokenOut(address token) public pure override returns (bool) {
return token == IUSD || token == SIUSD || token == USDC;
}
function assetInfo()
external
pure
override
returns (AssetType assetType, address assetAddress, uint8 assetDecimals)
{
return (AssetType.TOKEN, IUSD, 18);
}
}
"
},
"contracts/core/StandardizedYield/SYBaseUpg.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
import "../../interfaces/IStandardizedYield.sol";
import "../erc20/PendleERC20PermitUpg.sol";
import "../libraries/math/PMath.sol";
import "../libraries/ArrayLib.sol";
import "../libraries/TokenHelper.sol";
import "../libraries/Errors.sol";
import "../libraries/BoringOwnableUpgradeable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
abstract contract SYBaseUpg is
IStandardizedYield,
PendleERC20PermitUpg,
TokenHelper,
BoringOwnableUpgradeable,
Pausable
{
using PMath for uint256;
address public immutable yieldToken;
uint256[100] private __gap;
constructor(address _yieldToken) PendleERC20Upg(IERC20Metadata(_yieldToken).decimals()) {
yieldToken = _yieldToken;
_disableInitializers();
}
function __SYBaseUpg_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20PermitUpg_init(name_, symbol_);
__BoringOwnable_init();
}
// solhint-disable no-empty-blocks
receive() external payable {}
/*///////////////////////////////////////////////////////////////
DEPOSIT/REDEEM USING BASE TOKENS
//////////////////////////////////////////////////////////////*/
/**
* @dev See {IStandardizedYield-deposit}
*/
function deposit(
address receiver,
address tokenIn,
uint256 amountTokenToDeposit,
uint256 minSharesOut
) external payable nonReentrant returns (uint256 amountSharesOut) {
if (!isValidTokenIn(tokenIn)) revert Errors.SYInvalidTokenIn(tokenIn);
if (amountTokenToDeposit == 0) revert Errors.SYZeroDeposit();
_transferIn(tokenIn, msg.sender, amountTokenToDeposit);
amountSharesOut = _deposit(tokenIn, amountTokenToDeposit);
if (amountSharesOut < minSharesOut) revert Errors.SYInsufficientSharesOut(amountSharesOut, minSharesOut);
_mint(receiver, amountSharesOut);
emit Deposit(msg.sender, receiver, tokenIn, amountTokenToDeposit, amountSharesOut);
}
/**
* @dev See {IStandardizedYield-redeem}
*/
function redeem(
address receiver,
uint256 amountSharesToRedeem,
address tokenOut,
uint256 minTokenOut,
bool burnFromInternalBalance
) external nonReentrant returns (uint256 amountTokenOut) {
if (!isValidTokenOut(tokenOut)) revert Errors.SYInvalidTokenOut(tokenOut);
if (amountSharesToRedeem == 0) revert Errors.SYZeroRedeem();
if (burnFromInternalBalance) {
_burn(address(this), amountSharesToRedeem);
} else {
_burn(msg.sender, amountSharesToRedeem);
}
amountTokenOut = _redeem(receiver, tokenOut, amountSharesToRedeem);
if (amountTokenOut < minTokenOut) revert Errors.SYInsufficientTokenOut(amountTokenOut, minTokenOut);
emit Redeem(msg.sender, receiver, tokenOut, amountSharesToRedeem, amountTokenOut);
}
/**
* @notice mint shares based on the deposited base tokens
* @param tokenIn base token address used to mint shares
* @param amountDeposited amount of base tokens deposited
* @return amountSharesOut amount of shares minted
*/
function _deposit(address tokenIn, uint256 amountDeposited) internal virtual returns (uint256 amountSharesOut);
/**
* @notice redeems base tokens based on amount of shares to be burned
* @param tokenOut address of the base token to be redeemed
* @param amountSharesToRedeem amount of shares to be burned
* @return amountTokenOut amount of base tokens redeemed
*/
function _redeem(
address receiver,
address tokenOut,
uint256 amountSharesToRedeem
) internal virtual returns (uint256 amountTokenOut);
/*///////////////////////////////////////////////////////////////
EXCHANGE-RATE
//////////////////////////////////////////////////////////////*/
/**
* @dev See {IStandardizedYield-exchangeRate}
*/
function exchangeRate() external view virtual override returns (uint256 res);
/*///////////////////////////////////////////////////////////////
REWARDS-RELATED
//////////////////////////////////////////////////////////////*/
/**
* @dev See {IStandardizedYield-claimRewards}
*/
function claimRewards(address /*user*/) external virtual override returns (uint256[] memory rewardAmounts) {
rewardAmounts = new uint256[](0);
}
/**
* @dev See {IStandardizedYield-getRewardTokens}
*/
function getRewardTokens() external view virtual override returns (address[] memory rewardTokens) {
rewardTokens = new address[](0);
}
/**
* @dev See {IStandardizedYield-accruedRewards}
*/
function accruedRewards(address /*user*/) external view virtual override returns (uint256[] memory rewardAmounts) {
rewardAmounts = new uint256[](0);
}
function rewardIndexesCurrent() external virtual override returns (uint256[] memory indexes) {
indexes = new uint256[](0);
}
function rewardIndexesStored() external view virtual override returns (uint256[] memory indexes) {
indexes = new uint256[](0);
}
/*///////////////////////////////////////////////////////////////
MISC METADATA FUNCTIONS
//////////////////////////////////////////////////////////////*/
function previewDeposit(
address tokenIn,
uint256 amountTokenToDeposit
) external view virtual returns (uint256 amountSharesOut) {
if (!isValidTokenIn(tokenIn)) revert Errors.SYInvalidTokenIn(tokenIn);
return _previewDeposit(tokenIn, amountTokenToDeposit);
}
function previewRedeem(
address tokenOut,
uint256 amountSharesToRedeem
) external view virtual returns (uint256 amountTokenOut) {
if (!isValidTokenOut(tokenOut)) revert Errors.SYInvalidTokenOut(tokenOut);
return _previewRedeem(tokenOut, amountSharesToRedeem);
}
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
function _beforeTokenTransfer(address, address, uint256) internal virtual override whenNotPaused {}
function _previewDeposit(
address tokenIn,
uint256 amountTokenToDeposit
) internal view virtual returns (uint256 amountSharesOut);
function _previewRedeem(
address tokenOut,
uint256 amountSharesToRedeem
) internal view virtual returns (uint256 amountTokenOut);
function getTokensIn() public view virtual returns (address[] memory res);
function getTokensOut() public view virtual returns (address[] memory res);
function isValidTokenIn(address token) public view virtual returns (bool);
function isValidTokenOut(address token) public view virtual returns (bool);
}
"
},
"contracts/interfaces/IERC4626.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
/*
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IERC4626 is IERC20Metadata {
function asset() external view returns (address);
function deposit(uint256 assets, address receiver) external returns (uint256);
function redeem(uint256 shares, address receiver, address owner) external returns (uint256);
function convertToAssets(uint256 shares) external view returns (uint256);
function convertToShares(uint256 assets) external view returns (uint256);
function previewDeposit(uint256 assets) external view returns (uint256);
function previewRedeem(uint256 shares) external view returns (uint256);
function totalAssets() external view returns (uint256);
function maxMint(address) external view returns (uint256);
}
"
},
"contracts/core/StandardizedYield/implementations/PendleERC4626UpgSYV2.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
import "../SYBaseUpg.sol";
import "../../../interfaces/IERC4626.sol";
contract PendleERC4626UpgSYV2 is SYBaseUpg {
using PMath for uint256;
address public immutable asset;
constructor(address _erc4626) SYBaseUpg(_erc4626) {
asset = IERC4626(_erc4626).asset();
}
function initialize(string memory _name, string memory _symbol) external virtual initializer {
__SYBaseUpg_init(_name, _symbol);
_safeApproveInf(asset, yieldToken);
}
function _deposit(
address tokenIn,
uint256 amountDeposited
) internal virtual override returns (uint256 /*amountSharesOut*/) {
if (tokenIn == yieldToken) {
return amountDeposited;
} else {
return IERC4626(yieldToken).deposit(amountDeposited, address(this));
}
}
function _redeem(
address receiver,
address tokenOut,
uint256 amountSharesToRedeem
) internal virtual override returns (uint256 amountTokenOut) {
if (tokenOut == yieldToken) {
amountTokenOut = amountSharesToRedeem;
_transferOut(yieldToken, receiver, amountTokenOut);
} else {
amountTokenOut = IERC4626(yieldToken).redeem(amountSharesToRedeem, receiver, address(this));
}
}
function exchangeRate() public view virtual override returns (uint256) {
return IERC4626(yieldToken).convertToAssets(PMath.ONE);
}
function _previewDeposit(
address tokenIn,
uint256 amountTokenToDeposit
) internal view virtual override returns (uint256 /*amountSharesOut*/) {
if (tokenIn == yieldToken) return amountTokenToDeposit;
else return IERC4626(yieldToken).previewDeposit(amountTokenToDeposit);
}
function _previewRedeem(
address tokenOut,
uint256 amountSharesToRedeem
) internal view virtual override returns (uint256 /*amountTokenOut*/) {
if (tokenOut == yieldToken) return amountSharesToRedeem;
else return IERC4626(yieldToken).previewRedeem(amountSharesToRedeem);
}
function getTokensIn() public view virtual override returns (address[] memory res) {
res = new address[](2);
res[0] = asset;
res[1] = yieldToken;
}
function getTokensOut() public view virtual override returns (address[] memory res) {
res = new address[](2);
res[0] = asset;
res[1] = yieldToken;
}
function isValidTokenIn(address token) public view virtual override returns (bool) {
return token == yieldToken || token == asset;
}
function isValidTokenOut(address token) public view virtual override returns (bool) {
return token == yieldToken || token == asset;
}
function assetInfo()
external
view
virtual
returns (AssetType assetType, address assetAddress, uint8 assetDecimals)
{
return (AssetType.TOKEN, asset, IERC20Metadata(asset).decimals());
}
}
"
},
"contracts/interfaces/IStandardizedYield.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
/*
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IStandardizedYield is IERC20Metadata {
/// @dev Emitted when any base tokens is deposited to mint shares
event Deposit(
address indexed caller,
address indexed receiver,
address indexed tokenIn,
uint256 amountDeposited,
uint256 amountSyOut
);
/// @dev Emitted when any shares are redeemed for base tokens
event Redeem(
address indexed caller,
address indexed receiver,
address indexed tokenOut,
uint256 amountSyToRedeem,
uint256 amountTokenOut
);
/// @dev check `assetInfo()` for more information
enum AssetType {
TOKEN,
LIQUIDITY
}
/// @dev Emitted when (`user`) claims their rewards
event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);
/**
* @notice mints an amount of shares by depositing a base token.
* @param receiver shares recipient address
* @param tokenIn address of the base tokens to mint shares
* @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)
* @param minSharesOut reverts if amount of shares minted is lower than this
* @return amountSharesOut amount of shares minted
* @dev Emits a {Deposit} event
*
* Requirements:
* - (`tokenIn`) must be a valid base token.
*/
function deposit(
address receiver,
address tokenIn,
uint256 amountTokenToDeposit,
uint256 minSharesOut
) external payable returns (uint256 amountSharesOut);
/**
* @notice redeems an amount of base tokens by burning some shares
* @param receiver recipient address
* @param amountSharesToRedeem amount of shares to be burned
* @param tokenOut address of the base token to be redeemed
* @param minTokenOut reverts if amount of base token redeemed is lower than this
* @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`
* @return amountTokenOut amount of base tokens redeemed
* @dev Emits a {Redeem} event
*
* Requirements:
* - (`tokenOut`) must be a valid base token.
*/
function redeem(
address receiver,
uint256 amountSharesToRedeem,
address tokenOut,
uint256 minTokenOut,
bool burnFromInternalBalance
) external returns (uint256 amountTokenOut);
/**
* @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account
* @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy
he can mint must be X * exchangeRate / 1e18
* @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication
& division
*/
function exchangeRate() external view returns (uint256 res);
/**
* @notice claims reward for (`user`)
* @param user the user receiving their rewards
* @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`
* @dev
* Emits a `ClaimRewards` event
* See {getRewardTokens} for list of reward tokens
*/
function claimRewards(address user) external returns (uint256[] memory rewardAmounts);
/**
* @notice get the amount of unclaimed rewards for (`user`)
* @param user the user to check for
* @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`
*/
function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);
function rewardIndexesCurrent() external returns (uint256[] memory indexes);
function rewardIndexesStored() external view returns (uint256[] memory indexes);
/**
* @notice returns the list of reward token addresses
*/
function getRewardTokens() external view returns (address[] memory);
/**
* @notice returns the address of the underlying yield token
*/
function yieldToken() external view returns (address);
/**
* @notice returns all tokens that can mint this SY
*/
function getTokensIn() external view returns (address[] memory res);
/**
* @notice returns all tokens that can be redeemed by this SY
*/
function getTokensOut() external view returns (address[] memory res);
function isValidTokenIn(address token) external view returns (bool);
function isValidTokenOut(address token) external view returns (bool);
function previewDeposit(
address tokenIn,
uint256 amountTokenToDeposit
) external view returns (uint256 amountSharesOut);
function previewRedeem(
address tokenOut,
uint256 amountSharesToRedeem
) external view returns (uint256 amountTokenOut);
/**
* @notice This function contains information to interpret what the asset is
* @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens,
2 for bridged yield bearing tokens like wstETH, rETH on Arbi whose the underlying asset doesn't exist on the chain)
* @return assetAddress the address of the asset
* @return assetDecimals the decimals of the asset
*/
function assetInfo() external view returns (AssetType assetType, address assetAddress, uint8 assetDecimals);
}
"
},
"contracts/core/erc20/PendleERC20PermitUpg.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./PendleERC20Upg.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
/// @dev forked from OZ's ERC20Permit
abstract contract PendleERC20PermitUpg is PendleERC20Upg, IERC20Permit, EIP712Upgradeable {
using Counters for Counters.Counter;
mapping(address => Counters.Counter) private _nonces;
uint256[100] private __gap;
// solhint-disable-next-line var-name-mixedcase
bytes32 private constant _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
function __ERC20PermitUpg_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20Upg_init(name_, symbol_);
__EIP712_init(name_, "1");
}
/**
* @dev See {IERC20Permit-permit}.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
require(signer == owner, "ERC20Permit: invalid signature");
_approve(owner, spender, value);
}
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view virtual override returns (uint256) {
return _nonces[owner].current();
}
/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
/**
* @dev "Consume a nonce": return the current value and increment.
*
* _Available since v4.1._
*/
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
}
"
},
"contracts/core/libraries/math/PMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;
/* solhint-disable private-vars-leading-underscore, reason-string */
library PMath {
uint256 internal constant ONE = 1e18; // 18 decimal places
int256 internal constant IONE = 1e18; // 18 decimal places
function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
return (a >= b ? a - b : 0);
}
}
function subNoNeg(int256 a, int256 b) internal pure returns (int256) {
require(a >= b, "negative");
return a - b; // no unchecked since if b is very negative, a - b might overflow
}
function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
unchecked {
return product / ONE;
}
}
function mulDown(int256 a, int256 b) internal pure returns (int256) {
int256 product = a * b;
unchecked {
return product / IONE;
}
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 aInflated = a * ONE;
unchecked {
return aInflated / b;
}
}
function divDown(int256 a, int256 b) internal pure returns (int256) {
int256 aInflated = a * IONE;
unchecked {
return aInflated / b;
}
}
function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
return (a + b - 1) / b;
}
function rawDivUp(int256 a, int256 b) internal pure returns (int256) {
return (a + b - 1) / b;
}
function tweakUp(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE + factor);
}
function tweakDown(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE - factor);
}
/// @return res = min(a + b, bound)
/// @dev This function should handle arithmetic operation and bound check without overflow/underflow
function addWithUpperBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {
unchecked {
if (type(uint256).max - b < a) res = bound;
else res = min(bound, a + b);
}
}
/// @return res = max(a - b, bound)
/// @dev This function should handle arithmetic operation and bound check without overflow/underflow
function subWithLowerBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {
unchecked {
if (b > a) res = bound;
else res = max(a - b, bound);
}
}
function clamp(uint256 x, uint256 lower, uint256 upper) internal pure returns (uint256 res) {
res = x;
if (x < lower) res = lower;
else if (x > upper) res = upper;
}
// @author Uniswap
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
function square(uint256 x) internal pure returns (uint256) {
return x * x;
}
function squareDown(uint256 x) internal pure returns (uint256) {
return mulDown(x, x);
}
function abs(int256 x) internal pure returns (uint256) {
return uint256(x > 0 ? x : -x);
}
function neg(int256 x) internal pure returns (int256) {
return x * (-1);
}
function neg(uint256 x) internal pure returns (int256) {
return Int(x) * (-1);
}
function max(uint256 x, uint256 y) internal pure returns (uint256) {
return (x > y ? x : y);
}
function max(int256 x, int256 y) internal pure returns (int256) {
return (x > y ? x : y);
}
function min(uint256 x, uint256 y) internal pure returns (uint256) {
return (x < y ? x : y);
}
function min(int256 x, int256 y) internal pure returns (int256) {
return (x < y ? x : y);
}
/*///////////////////////////////////////////////////////////////
SIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Int(uint256 x) internal pure returns (int256) {
require(x <= uint256(type(int256).max));
return int256(x);
}
function Int128(int256 x) internal pure returns (int128) {
require(type(int128).min <= x && x <= type(int128).max);
return int128(x);
}
function Int128(uint256 x) internal pure returns (int128) {
return Int128(Int(x));
}
/*///////////////////////////////////////////////////////////////
UNSIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Uint(int256 x) internal pure returns (uint256) {
require(x >= 0);
return uint256(x);
}
function Uint32(uint256 x) internal pure returns (uint32) {
require(x <= type(uint32).max);
return uint32(x);
}
function Uint64(uint256 x) internal pure returns (uint64) {
require(x <= type(uint64).max);
return uint64(x);
}
function Uint112(uint256 x) internal pure returns (uint112) {
require(x <= type(uint112).max);
return uint112(x);
}
function Uint96(uint256 x) internal pure returns (uint96) {
require(x <= type(uint96).max);
return uint96(x);
}
function Uint128(uint256 x) internal pure returns (uint128) {
require(x <= type(uint128).max);
return uint128(x);
}
function Uint192(uint256 x) internal pure returns (uint192) {
require(x <= type(uint192).max);
return uint192(x);
}
function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);
}
function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a >= b && a <= mulDown(b, ONE + eps);
}
function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a <= b && a >= mulDown(b, ONE - eps);
}
}
"
},
"contracts/core/libraries/ArrayLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library ArrayLib {
function sum(uint256[] memory input) internal pure returns (uint256) {
uint256 value = 0;
for (uint256 i = 0; i < input.length; ) {
value += input[i];
unchecked {
i++;
}
}
return value;
}
/// @notice return index of the element if found, else return uint256.max
function find(address[] memory array, address element) internal pure returns (uint256 index) {
uint256 length = array.length;
for (uint256 i = 0; i < length; ) {
if (array[i] == element) return i;
unchecked {
i++;
}
}
return type(uint256).max;
}
function append(address[] memory inp, address element) internal pure returns (address[] memory out) {
uint256 length = inp.length;
out = new address[](length + 1);
for (uint256 i = 0; i < length; ) {
out[i] = inp[i];
unchecked {
i++;
}
}
out[length] = element;
}
function append(
address[] memory inp,
address element0,
address element1
) internal pure returns (address[] memory out) {
uint256 length = inp.length;
out = new address[](length + 2);
for (uint256 i = 0; i < length; ) {
out[i] = inp[i];
unchecked {
i++;
}
}
out[length] = element0;
out[length + 1] = element1;
}
function appendHead(address[] memory inp, address element) internal pure returns (address[] memory out) {
uint256 length = inp.length;
out = new address[](length + 1);
out[0] = element;
for (uint256 i = 1; i <= length; ) {
out[i] = inp[i - 1];
unchecked {
i++;
}
}
}
/**
* @dev This function assumes a and b each contains unidentical elements
* @param a array of addresses a
* @param b array of addresses b
* @return out Concatenation of a and b containing unidentical elements
*/
function merge(address[] memory a, address[] memory b) internal pure returns (address[] memory out) {
unchecked {
uint256 countUnidenticalB = 0;
bool[] memory isUnidentical = new bool[](b.length);
for (uint256 i = 0; i < b.length; ++i) {
if (!contains(a, b[i])) {
countUnidenticalB++;
isUnidentical[i] = true;
}
}
out = new address[](a.length + countUnidenticalB);
for (uint256 i = 0; i < a.length; ++i) {
out[i] = a[i];
}
uint256 id = a.length;
for (uint256 i = 0; i < b.length; ++i) {
if (isUnidentical[i]) {
out[id++] = b[i];
}
}
}
}
// various version of contains
function contains(address[] memory array, address element) internal pure returns (bool) {
uint256 length = array.length;
for (uint256 i = 0; i < length; ) {
if (array[i] == element) return true;
unchecked {
i++;
}
}
return false;
}
function contains(bytes4[] memory array, bytes4 element) internal pure returns (bool) {
uint256 length = array.length;
for (uint256 i = 0; i < length; ) {
if (array[i] == element) return true;
unchecked {
i++;
}
}
return false;
}
function create(address a) internal pure returns (address[] memory res) {
res = new address[](1);
res[0] = a;
}
function create(address a, address b) internal pure returns (address[] memory res) {
res = new address[](2);
res[0] = a;
res[1] = b;
}
function create(address a, address b, address c) internal pure returns (address[] memory res) {
res = new address[](3);
res[0] = a;
res[1] = b;
res[2] = c;
}
function create(address a, address b, address c, address d) internal pure returns (address[] memory res) {
res = new address[](4);
res[0] = a;
res[1] = b;
res[2] = c;
res[3] = d;
}
function create(
address a,
address b,
address c,
address d,
address e
) internal pure returns (address[] memory res) {
res = new address[](5);
res[0] = a;
res[1] = b;
res[2] = c;
res[3] = d;
res[4] = e;
}
function create(uint256 a) internal pure returns (uint256[] memory res) {
res = new uint256[](1);
res[0] = a;
}
function create(uint256 a, uint256 b) internal pure returns (uint256[] memory res) {
res = new uint256[](2);
res[0] = a;
res[1] = b;
}
}
"
},
"contracts/core/libraries/TokenHelper.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../../interfaces/IWETH.sol";
abstract contract TokenHelper {
using SafeERC20 for IERC20;
address internal constant NATIVE = address(0);
uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval
function _transferIn(address token, address from, uint256 amount) internal {
if (token == NATIVE) require(msg.value == amount, "eth mismatch");
else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount);
}
function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal {
if (amount != 0) token.safeTransferFrom(from, to, amount);
}
function _transferOut(address token, address to, uint256 amount) internal {
if (amount == 0) return;
if (token == NATIVE) {
(bool success, ) = to.call{value: amount}("");
require(success, "eth send failed");
} else {
IERC20(token).safeTransfer(to, amount);
}
}
function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal {
uint256 numTokens = tokens.length;
require(numTokens == amounts.length, "length mismatch");
for (uint256 i = 0; i < numTokens; ) {
_transferOut(tokens[i], to, amounts[i]);
unchecked {
i++;
}
}
}
function _selfBalance(address token) internal view returns (uint256) {
return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this));
}
function _selfBalance(IERC20 token) internal view returns (uint256) {
return token.balanceOf(address(this));
}
/// @notice Approves the stipulated contract to spend the given allowance in the given token
/// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it
function _safeApprove(address token, address to, uint256 value) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), "Safe Approve");
}
function _safeApproveInf(address token, address to) internal {
if (token == NATIVE) return;
if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) {
_safeApprove(token, to, 0);
_safeApprove(token, to, type(uint256).max);
}
}
function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal {
if (tokenIn == NATIVE) IWETH(tokenOut).deposit{value: netTokenIn}();
else IWETH(tokenIn).withdraw(netTokenIn);
}
}
"
},
"contracts/core/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library Errors {
// BulkSeller
error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error BulkNotMaintainer();
error BulkNotAdmin();
error BulkSellerAlreadyExisted(address token, address SY, address bulk);
error BulkSellerInvalidToken(address token, address SY);
error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);
error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);
// APPROX
error ApproxFail();
error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);
error ApproxBinarySearchInputInvalid(
uint256 approxGuessMin,
uint256 approxGuessMax,
uint256 minGuessMin,
uint256 maxGuessMax
);
// MARKET + MARKET MATH CORE
error MarketExpired();
error MarketZeroAmountsInput();
error MarketZeroAmountsOutput();
error MarketZeroLnImpliedRate();
error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);
error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);
error MarketExchangeRateBelowOne(int256 exchangeRate);
error MarketProportionMustNotEqualOne();
error MarketRateScalarBelowZero(int256 rateScalar);
error MarketScalarRootBelowZero(int256 scalarRoot);
error MarketProportionTooHigh(int256 proportion, int256 maxProportion);
error OracleUninitialized();
error OracleTargetTooOld(uint32 target, uint32 oldest);
error OracleZeroCardinality();
error MarketFactoryExpiredPt();
error MarketFactoryInvalidPt();
error MarketFactoryMarketExists();
error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);
error MarketFactoryOverriddenFeeTooHigh(uint80 overriddenFee, uint256 marketLnFeeRateRoot);
error MarketFactoryReserveFeePercentTooHigh(uint8 reserveFeePercent, uint8 maxReserveFeePercent);
error MarketFactoryZeroTreasury();
error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);
error MFNotPendleMarket(address addr);
// ROUTER
error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);
error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);
error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);
error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);
error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);
error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);
error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);
error RouterTimeRangeZero();
error RouterCallbackNotPendleMarket(address caller);
error RouterInvalidAction(bytes4 selector);
error RouterInvalidFacet(address facet);
error RouterKyberSwapDataZero();
error SimulationResults(bool success, bytes res);
// YIELD CONTRACT
error YCExpired();
error YCNotExpired();
error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);
error YCNothingToRedeem();
error YCPostExpiryDataNotSet();
error YCNoFloatingSy();
// YieldFactory
error YCFactoryInvalidExpiry();
error YCFactoryYieldContractExisted();
error YCFactoryZeroExpiryDivisor();
error YCFactoryZeroTreasury();
error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);
error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);
// SY
error SYInvalidTokenIn(address token);
error SYInvalidTokenOut(address token);
error SYZeroDeposit();
error SYZeroRedeem();
error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);
error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
// SY-specific
error SYQiTokenMintFailed(uint256 errCode);
error SYQiTokenRedeemFailed(uint256 errCode);
error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);
error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);
error SYCurveInvalidPid();
error SYCurve3crvPoolNotFound();
error SYApeDepositAmountTooSmall(uint256 amountDeposited);
error SYBalancerInvalidPid();
error SYInvalidRewardToken(address token);
error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);
error SYBalancerReentrancy();
error NotFromTrustedRemote(uint16 srcChainId, bytes path);
error ApxETHNotEnoughBuffer();
// Liquidity Mining
error VCInactivePool(address pool);
error VCPoolAlreadyActive(address pool);
error VCZeroVePendle(address user);
error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);
error VCEpochNotFinalized(uint256 wTime);
error VCPoolAlreadyAddAndRemoved(address pool);
error VEInvalidNewExpiry(uint256 newExpiry);
error VEExceededMaxLockTime();
error VEInsufficientLockTime();
error VENotAllowedReduceExpiry();
error VEZeroAmountLocked();
error VEPositionNotExpired();
error VEZeroPosition();
error VEZeroSlope(uint128 bias, uint128 slope);
error VEReceiveOldSupply(uint256 msgTime);
error GCNotPendleMarket(address caller);
error GCNotVotingController(address caller);
error InvalidWTime(uint256 wTime);
error ExpiryInThePast(uint256 expiry);
error ChainNotSupported(uint256 chainId);
error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);
error FDEpochLengthMismatch();
error FDInvalidPool(address pool);
error FDPoolAlreadyExists(address pool);
error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);
error FDInvalidStartEpoch(uint256 startEpoch);
error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);
error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);
error BDInvalidEpoch(uint256 epoch, uint256 startTime);
// Cross-Chain
error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);
error MsgNotFromReceiveEndpoint(address sender);
error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);
error ApproxDstExecutionGasNotSet();
error InvalidRetryData();
// GENERIC MSG
error ArrayLengthMismatch();
error ArrayEmpty();
error ArrayOutOfBounds();
error ZeroAddress();
error FailedToSendEther();
error InvalidMerkleProof();
error OnlyLayerZeroEndpoint();
error OnlyYT();
error OnlyYCFactory();
error OnlyWhitelisted();
// Swap Aggregator
error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);
error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);
}
"
},
"contracts/core/libraries/BoringOwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract BoringOwnableUpgradeableData {
address public owner;
address public pendingOwner;
}
abstract contract BoringOwnableUpgradeable is BoringOwnableUpgradeableData, Initializable {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function __BoringOwnable_init() internal onlyInitializing {
owner = msg.sender;
}
/// @notice Transfers ownership to `newOwner`. Either directly or claimable by the new pending owner.
/// Can only be invoked by the current `owner`.
/// @param newOwner Address of the new owner.
/// @param direct True if `newOwner` should be set immediately. False if `newOwner` needs to use `claimOwnership`.
/// @param renounce Allows the `newOwner` to be `address(0)` if `direct` and `renounce` is True. Has no effect otherwise.
function transferOwnership(address newOwner, bool direct, bool renounce) public onlyOwner {
if (direct) {
// Checks
require(newOwner != address(0) || renounce, "Ownable: zero address");
// Effects
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
pendingOwner = address(0);
} else {
// Effects
pendingOwner = newOwner;
}
}
/// @notice Needs to be called by `pendingOwner` to claim ownership.
function claimOwnership() public {
address _pendingOwner = pendingOwner;
// Checks
require(msg.sender == _pendingOwner, "Ownable: caller != pending owner");
// Effects
emit OwnershipTransferred(owner, _pendingOwner);
owner = _pendingOwner;
pendingOwner = address(0);
}
/// @notice Only allows the `owner` to execute the function.
modifier onlyOwner() {
require(msg.sender == owner, "Ownable: caller is not the owner");
_;
}
uint256[48] private __gap;
}
"
},
"lib/openzeppelin-contracts/contracts/security/Pausable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
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);
}
"
},
"contracts/core/erc20/PendleERC20Upg.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @dev Pendle's ERC20 implementation, modified from @openzeppelin implementation
* Changes are:
* - comes with built-in reentrancy protection, storage-packed with totalSupply variable
* - delete increaseAllowance / decreaseAllowance
* - add nonReentrancy protection to transfer / transferFrom functions
* - allow decimals to be passed in
* - block self-transfer by default
*/
// solhint-disable
abstract contract PendleERC20Upg is Context, Initializable, IERC20, IERC20Metadata {
uint8 private constant _NOT_ENTERED = 1;
uint8 private constant _ENTERED = 2;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint248 private _totalSupply;
uint8 private _status;
string private _name;
string private _symbol;
uint8 public immutable decimals;
uint256[100] private __gap;
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Sets the values for {name}, {symbol} and {decimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor(uint8 decimals_) {
decimals = decimals_;
}
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20Upg_init(string memory name_, string memory symbol_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
_status = _NOT_ENTERED;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) external virtual override nonReentrant returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) external virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external virtual override nonReentrant returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slash
Submitted on: 2025-10-02 12:41:31
Comments
Log in to comment.
No comments yet.