// SPDX-License-Identifier: MITpragmasolidity >=0.6.2 <0.8.0;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/functionisContract(address account) internalviewreturns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in// construction, since the code is only stored at the end of the// constructor execution.uint256 size;
// solhint-disable-next-line no-inline-assemblyassembly { size :=extcodesize(account) }
return size >0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/functionsendValue(addresspayable recipient, uint256 amount) internal{
require(address(this).balance>= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/functionfunctionCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCall(address target, bytesmemory data, stringmemory errorMessage) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target, bytesmemory data, uint256 value) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target, bytesmemory data, uint256 value, stringmemory errorMessage) internalreturns (bytesmemory) {
require(address(this).balance>= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target, bytesmemory data) internalviewreturns (bytesmemory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target, bytesmemory data, stringmemory errorMessage) internalviewreturns (bytesmemory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target, bytesmemory data, stringmemory errorMessage) internalreturns (bytesmemory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function_verifyCallResult(bool success, bytesmemory returndata, stringmemory errorMessage) privatepurereturns(bytesmemory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if presentif (returndata.length>0) {
// The easiest way to bubble the revert reason is using memory via assembly// solhint-disable-next-line no-inline-assemblyassembly {
let returndata_size :=mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Contract Source Code
File 2 of 23: IERC20.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.6.0 <0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (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.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` 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.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed 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.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
Contract Source Code
File 3 of 23: IPendleBaseToken.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
interfaceIPendleBaseTokenisIERC20{
/**
* @notice Decreases the allowance granted to spender by the caller.
* @param spender The address to reduce the allowance from.
* @param subtractedValue The amount allowance to subtract.
* @return Returns true if allowance has decreased, otherwise false.
**/functiondecreaseAllowance(address spender, uint256 subtractedValue) externalreturns (bool);
/**
* @notice The yield contract start in epoch time.
* @return Returns the yield start date.
**/functionstart() externalviewreturns (uint256);
/**
* @notice The yield contract expiry in epoch time.
* @return Returns the yield expiry date.
**/functionexpiry() externalviewreturns (uint256);
/**
* @notice Increases the allowance granted to spender by the caller.
* @param spender The address to increase the allowance from.
* @param addedValue The amount allowance to add.
* @return Returns true if allowance has increased, otherwise false
**/functionincreaseAllowance(address spender, uint256 addedValue) externalreturns (bool);
/**
* @notice Returns the number of decimals the token uses.
* @return Returns the token's decimals.
**/functiondecimals() externalviewreturns (uint8);
/**
* @notice Returns the name of the token.
* @return Returns the token's name.
**/functionname() externalviewreturns (stringmemory);
/**
* @notice Returns the symbol of the token.
* @return Returns the token's symbol.
**/functionsymbol() externalviewreturns (stringmemory);
/**
* @notice approve using the owner's signature
**/functionpermit(address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
Contract Source Code
File 4 of 23: IPendleData.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;import"./IPendleRouter.sol";
import"./IPendleYieldToken.sol";
import"./IPendlePausingManager.sol";
import"./IPendleMarket.sol";
interfaceIPendleData{
/**
* @notice Emitted when validity of a forge-factory pair is updated
* @param _forgeId the forge id
* @param _marketFactoryId the market factory id
* @param _valid valid or not
**/eventForgeFactoryValiditySet(bytes32 _forgeId, bytes32 _marketFactoryId, bool _valid);
/**
* @notice Emitted when Pendle and PendleFactory addresses have been updated.
* @param treasury The address of the new treasury contract.
**/eventTreasurySet(address treasury);
/**
* @notice Emitted when LockParams is changed
**/eventLockParamsSet(uint256 lockNumerator, uint256 lockDenominator);
/**
* @notice Emitted when ExpiryDivisor is changed
**/eventExpiryDivisorSet(uint256 expiryDivisor);
/**
* @notice Emitted when forge fee is changed
**/eventForgeFeeSet(uint256 forgeFee);
/**
* @notice Emitted when interestUpdateRateDeltaForMarket is changed
* @param interestUpdateRateDeltaForMarket new interestUpdateRateDeltaForMarket setting
**/eventInterestUpdateRateDeltaForMarketSet(uint256 interestUpdateRateDeltaForMarket);
/**
* @notice Emitted when market fees are changed
* @param _swapFee new swapFee setting
* @param _protocolSwapFee new protocolSwapFee setting
**/eventMarketFeesSet(uint256 _swapFee, uint256 _protocolSwapFee);
/**
* @notice Emitted when the curve shift block delta is changed
* @param _blockDelta new block delta setting
**/eventCurveShiftBlockDeltaSet(uint256 _blockDelta);
/**
* @dev Emitted when new forge is added
* @param marketFactoryId Human Readable Market Factory ID in Bytes
* @param marketFactoryAddress The Market Factory Address
*/eventNewMarketFactory(bytes32indexed marketFactoryId, addressindexed marketFactoryAddress);
/**
* @notice Set/update validity of a forge-factory pair
* @param _forgeId the forge id
* @param _marketFactoryId the market factory id
* @param _valid valid or not
**/functionsetForgeFactoryValidity(bytes32 _forgeId,
bytes32 _marketFactoryId,
bool _valid
) external;
/**
* @notice Sets the PendleTreasury contract addresses.
* @param newTreasury Address of new treasury contract.
**/functionsetTreasury(address newTreasury) external;
/**
* @notice Gets a reference to the PendleRouter contract.
* @return Returns the router contract reference.
**/functionrouter() externalviewreturns (IPendleRouter);
/**
* @notice Gets a reference to the PendleRouter contract.
* @return Returns the router contract reference.
**/functionpausingManager() externalviewreturns (IPendlePausingManager);
/**
* @notice Gets the treasury contract address where fees are being sent to.
* @return Address of the treasury contract.
**/functiontreasury() externalviewreturns (address);
/***********
* FORGE *
***********//**
* @notice Emitted when a forge for a protocol is added.
* @param forgeId Forge and protocol identifier.
* @param forgeAddress The address of the added forge.
**/eventForgeAdded(bytes32indexed forgeId, addressindexed forgeAddress);
/**
* @notice Adds a new forge for a protocol.
* @param forgeId Forge and protocol identifier.
* @param forgeAddress The address of the added forge.
**/functionaddForge(bytes32 forgeId, address forgeAddress) external;
/**
* @notice Store new OT and XYT details.
* @param forgeId Forge and protocol identifier.
* @param ot The address of the new XYT.
* @param xyt The address of the new XYT.
* @param underlyingAsset Token address of the underlying asset.
* @param expiry Yield contract expiry in epoch time.
**/functionstoreTokens(bytes32 forgeId,
address ot,
address xyt,
address underlyingAsset,
uint256 expiry
) external;
/**
* @notice Set a new forge fee
* @param _forgeFee new forge fee
**/functionsetForgeFee(uint256 _forgeFee) external;
/**
* @notice Gets the OT and XYT tokens.
* @param forgeId Forge and protocol identifier.
* @param underlyingYieldToken Token address of the underlying yield token.
* @param expiry Yield contract expiry in epoch time.
* @return ot The OT token references.
* @return xyt The XYT token references.
**/functiongetPendleYieldTokens(bytes32 forgeId,
address underlyingYieldToken,
uint256 expiry
) externalviewreturns (IPendleYieldToken ot, IPendleYieldToken xyt);
/**
* @notice Gets a forge given the identifier.
* @param forgeId Forge and protocol identifier.
* @return forgeAddress Returns the forge address.
**/functiongetForgeAddress(bytes32 forgeId) externalviewreturns (address forgeAddress);
/**
* @notice Checks if an XYT token is valid.
* @param forgeId The forgeId of the forge.
* @param underlyingAsset Token address of the underlying asset.
* @param expiry Yield contract expiry in epoch time.
* @return True if valid, false otherwise.
**/functionisValidXYT(bytes32 forgeId,
address underlyingAsset,
uint256 expiry
) externalviewreturns (bool);
/**
* @notice Checks if an OT token is valid.
* @param forgeId The forgeId of the forge.
* @param underlyingAsset Token address of the underlying asset.
* @param expiry Yield contract expiry in epoch time.
* @return True if valid, false otherwise.
**/functionisValidOT(bytes32 forgeId,
address underlyingAsset,
uint256 expiry
) externalviewreturns (bool);
functionvalidForgeFactoryPair(bytes32 _forgeId, bytes32 _marketFactoryId)
externalviewreturns (bool);
/**
* @notice Gets a reference to a specific OT.
* @param forgeId Forge and protocol identifier.
* @param underlyingYieldToken Token address of the underlying yield token.
* @param expiry Yield contract expiry in epoch time.
* @return ot Returns the reference to an OT.
**/functionotTokens(bytes32 forgeId,
address underlyingYieldToken,
uint256 expiry
) externalviewreturns (IPendleYieldToken ot);
/**
* @notice Gets a reference to a specific XYT.
* @param forgeId Forge and protocol identifier.
* @param underlyingAsset Token address of the underlying asset
* @param expiry Yield contract expiry in epoch time.
* @return xyt Returns the reference to an XYT.
**/functionxytTokens(bytes32 forgeId,
address underlyingAsset,
uint256 expiry
) externalviewreturns (IPendleYieldToken xyt);
/***********
* MARKET *
***********/eventMarketPairAdded(addressindexed market, addressindexed xyt, addressindexed token);
functionaddMarketFactory(bytes32 marketFactoryId, address marketFactoryAddress) external;
functionisMarket(address _addr) externalviewreturns (bool result);
functionisXyt(address _addr) externalviewreturns (bool result);
functionaddMarket(bytes32 marketFactoryId,
address xyt,
address token,
address market
) external;
functionsetMarketFees(uint256 _swapFee, uint256 _protocolSwapFee) external;
functionsetInterestUpdateRateDeltaForMarket(uint256 _interestUpdateRateDeltaForMarket)
external;
functionsetLockParams(uint256 _lockNumerator, uint256 _lockDenominator) external;
functionsetExpiryDivisor(uint256 _expiryDivisor) external;
functionsetCurveShiftBlockDelta(uint256 _blockDelta) external;
/**
* @notice Displays the number of markets currently existing.
* @return Returns markets length,
**/functionallMarketsLength() externalviewreturns (uint256);
functionforgeFee() externalviewreturns (uint256);
functioninterestUpdateRateDeltaForMarket() externalviewreturns (uint256);
functionexpiryDivisor() externalviewreturns (uint256);
functionlockNumerator() externalviewreturns (uint256);
functionlockDenominator() externalviewreturns (uint256);
functionswapFee() externalviewreturns (uint256);
functionprotocolSwapFee() externalviewreturns (uint256);
functioncurveShiftBlockDelta() externalviewreturns (uint256);
functiongetMarketByIndex(uint256 index) externalviewreturns (address market);
/**
* @notice Gets a market given a future yield token and an ERC20 token.
* @param xyt Token address of the future yield token as base asset.
* @param token Token address of an ERC20 token as quote asset.
* @return market Returns the market address.
**/functiongetMarket(bytes32 marketFactoryId,
address xyt,
address token
) externalviewreturns (address market);
/**
* @notice Gets a market factory given the identifier.
* @param marketFactoryId MarketFactory identifier.
* @return marketFactoryAddress Returns the factory address.
**/functiongetMarketFactoryAddress(bytes32 marketFactoryId)
externalviewreturns (address marketFactoryAddress);
functiongetMarketFromKey(address xyt,
address token,
bytes32 marketFactoryId
) externalviewreturns (address market);
}
Contract Source Code
File 5 of 23: IPendleForge.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"./IPendleRouter.sol";
import"./IPendleData.sol";
import"./IPendleRewardManager.sol";
import"./IPendleYieldContractDeployer.sol";
interfaceIPendleForge{
/**
* @dev Emitted when the Forge has minted the OT and XYT tokens.
* @param forgeId The forgeId
* @param underlyingAsset The address of the underlying yield token.
* @param expiry The expiry of the XYT token
* @param amountToTokenize The amount of yield bearing assets to tokenize
* @param amountTokenMinted The amount of OT/XYT minted
**/eventMintYieldTokens(bytes32 forgeId,
addressindexed underlyingAsset,
uint256indexed expiry,
uint256 amountToTokenize,
uint256 amountTokenMinted,
addressindexed user
);
/**
* @dev Emitted when the Forge has created new yield token contracts.
* @param forgeId The forgeId
* @param underlyingAsset The address of the underlying asset.
* @param expiry The date in epoch time when the contract will expire.
* @param ot The address of the ownership token.
* @param xyt The address of the new future yield token.
**/eventNewYieldContracts(bytes32 forgeId,
addressindexed underlyingAsset,
uint256indexed expiry,
address ot,
address xyt,
address yieldBearingAsset
);
/**
* @dev Emitted when the Forge has redeemed the OT and XYT tokens.
* @param forgeId The forgeId
* @param underlyingAsset the address of the underlying asset
* @param expiry The expiry of the XYT token
* @param amountToRedeem The amount of OT to be redeemed.
* @param redeemedAmount The amount of yield token received
**/eventRedeemYieldToken(bytes32 forgeId,
addressindexed underlyingAsset,
uint256indexed expiry,
uint256 amountToRedeem,
uint256 redeemedAmount,
addressindexed user
);
/**
* @dev Emitted when interest claim is settled
* @param forgeId The forgeId
* @param underlyingAsset the address of the underlying asset
* @param expiry The expiry of the XYT token
* @param user Interest receiver Address
* @param amount The amount of interest claimed
**/eventDueInterestsSettled(bytes32 forgeId,
addressindexed underlyingAsset,
uint256indexed expiry,
uint256 amount,
uint256 forgeFeeAmount,
addressindexed user
);
/**
* @dev Emitted when forge fee is withdrawn
* @param forgeId The forgeId
* @param underlyingAsset the address of the underlying asset
* @param expiry The expiry of the XYT token
* @param amount The amount of interest claimed
**/eventForgeFeeWithdrawn(bytes32 forgeId,
addressindexed underlyingAsset,
uint256indexed expiry,
uint256 amount
);
functionsetUpEmergencyMode(address _underlyingAsset,
uint256 _expiry,
address spender
) external;
functionnewYieldContracts(address underlyingAsset, uint256 expiry)
externalreturns (address ot, address xyt);
functionredeemAfterExpiry(address user,
address underlyingAsset,
uint256 expiry
) externalreturns (uint256 redeemedAmount);
functionredeemDueInterests(address user,
address underlyingAsset,
uint256 expiry
) externalreturns (uint256 interests);
functionupdateDueInterests(address underlyingAsset,
uint256 expiry,
address user
) external;
functionupdatePendingRewards(address _underlyingAsset,
uint256 _expiry,
address _user
) external;
functionredeemUnderlying(address user,
address underlyingAsset,
uint256 expiry,
uint256 amountToRedeem
) externalreturns (uint256 redeemedAmount);
functionmintOtAndXyt(address underlyingAsset,
uint256 expiry,
uint256 amountToTokenize,
address to
)
externalreturns (address ot,
address xyt,
uint256 amountTokenMinted
);
functionwithdrawForgeFee(address underlyingAsset, uint256 expiry) external;
functiongetYieldBearingToken(address underlyingAsset) externalreturns (address);
/**
* @notice Gets a reference to the PendleRouter contract.
* @return Returns the router contract reference.
**/functionrouter() externalviewreturns (IPendleRouter);
functiondata() externalviewreturns (IPendleData);
functionrewardManager() externalviewreturns (IPendleRewardManager);
functionyieldContractDeployer() externalviewreturns (IPendleYieldContractDeployer);
functionrewardToken() externalviewreturns (IERC20);
/**
* @notice Gets the bytes32 ID of the forge.
* @return Returns the forge and protocol identifier.
**/functionforgeId() externalviewreturns (bytes32);
functiondueInterests(address _underlyingAsset,
uint256 expiry,
address _user
) externalviewreturns (uint256);
functionyieldTokenHolders(address _underlyingAsset, uint256 _expiry)
externalviewreturns (address yieldTokenHolder);
}
Contract Source Code
File 6 of 23: IPendleMarket.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;pragmaabicoderv2;import"./IPendleRouter.sol";
import"./IPendleBaseToken.sol";
import"../libraries/PendleStructs.sol";
import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
interfaceIPendleMarketisIERC20{
/**
* @notice Emitted when reserves pool has been updated
* @param reserve0 The XYT reserves.
* @param weight0 The XYT weight
* @param reserve1 The generic token reserves.
* For the generic Token weight it can be inferred by (2^40) - weight0
**/eventSync(uint256 reserve0, uint256 weight0, uint256 reserve1);
functionsetUpEmergencyMode(address spender) external;
functionbootstrap(address user,
uint256 initialXytLiquidity,
uint256 initialTokenLiquidity
) externalreturns (PendingTransfer[2] memory transfers, uint256 exactOutLp);
functionaddMarketLiquiditySingle(address user,
address inToken,
uint256 inAmount,
uint256 minOutLp
) externalreturns (PendingTransfer[2] memory transfers, uint256 exactOutLp);
functionaddMarketLiquidityDual(address user,
uint256 _desiredXytAmount,
uint256 _desiredTokenAmount,
uint256 _xytMinAmount,
uint256 _tokenMinAmount
) externalreturns (PendingTransfer[2] memory transfers, uint256 lpOut);
functionremoveMarketLiquidityDual(address user,
uint256 inLp,
uint256 minOutXyt,
uint256 minOutToken
) externalreturns (PendingTransfer[2] memory transfers);
functionremoveMarketLiquiditySingle(address user,
address outToken,
uint256 exactInLp,
uint256 minOutToken
) externalreturns (PendingTransfer[2] memory transfers);
functionswapExactIn(address inToken,
uint256 inAmount,
address outToken,
uint256 minOutAmount
) externalreturns (uint256 outAmount, PendingTransfer[2] memory transfers);
functionswapExactOut(address inToken,
uint256 maxInAmount,
address outToken,
uint256 outAmount
) externalreturns (uint256 inAmount, PendingTransfer[2] memory transfers);
functionredeemLpInterests(address user) externalreturns (uint256 interests);
functiongetReserves()
externalviewreturns (uint256 xytBalance,
uint256 xytWeight,
uint256 tokenBalance,
uint256 tokenWeight,
uint256 currentBlock
);
functionfactoryId() externalviewreturns (bytes32);
functiontoken() externalviewreturns (address);
functionxyt() externalviewreturns (address);
}
Contract Source Code
File 7 of 23: IPendleMarketFactory.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;import"./IPendleRouter.sol";
interfaceIPendleMarketFactory{
/**
* @notice Creates a market given a protocol ID, future yield token, and an ERC20 token.
* @param xyt Token address of the futuonlyCorere yield token as base asset.
* @param token Token address of an ERC20 token as quote asset.
* @return market Returns the address of the newly created market.
**/functioncreateMarket(address xyt, address token) externalreturns (address market);
/**
* @notice Gets a reference to the PendleRouter contract.
* @return Returns the router contract reference.
**/functionrouter() externalviewreturns (IPendleRouter);
functionmarketFactoryId() externalviewreturns (bytes32);
}
Contract Source Code
File 8 of 23: IPendlePausingManager.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;interfaceIPendlePausingManager{
eventAddPausingAdmin(address admin);
eventRemovePausingAdmin(address admin);
eventPendingForgeEmergencyHandler(address _pendingForgeHandler);
eventPendingMarketEmergencyHandler(address _pendingMarketHandler);
eventPendingLiqMiningEmergencyHandler(address _pendingLiqMiningHandler);
eventForgeEmergencyHandlerSet(address forgeEmergencyHandler);
eventMarketEmergencyHandlerSet(address marketEmergencyHandler);
eventLiqMiningEmergencyHandlerSet(address liqMiningEmergencyHandler);
eventPausingManagerLocked();
eventForgeHandlerLocked();
eventMarketHandlerLocked();
eventLiqMiningHandlerLocked();
eventSetForgePaused(bytes32 forgeId, bool settingToPaused);
eventSetForgeAssetPaused(bytes32 forgeId, address underlyingAsset, bool settingToPaused);
eventSetForgeAssetExpiryPaused(bytes32 forgeId,
address underlyingAsset,
uint256 expiry,
bool settingToPaused
);
eventSetForgeLocked(bytes32 forgeId);
eventSetForgeAssetLocked(bytes32 forgeId, address underlyingAsset);
eventSetForgeAssetExpiryLocked(bytes32 forgeId, address underlyingAsset, uint256 expiry);
eventSetMarketFactoryPaused(bytes32 marketFactoryId, bool settingToPaused);
eventSetMarketPaused(bytes32 marketFactoryId, address market, bool settingToPaused);
eventSetMarketFactoryLocked(bytes32 marketFactoryId);
eventSetMarketLocked(bytes32 marketFactoryId, address market);
eventSetLiqMiningPaused(address liqMiningContract, bool settingToPaused);
eventSetLiqMiningLocked(address liqMiningContract);
functionforgeEmergencyHandler()
externalviewreturns (address handler,
address pendingHandler,
uint256 timelockDeadline
);
functionmarketEmergencyHandler()
externalviewreturns (address handler,
address pendingHandler,
uint256 timelockDeadline
);
functionliqMiningEmergencyHandler()
externalviewreturns (address handler,
address pendingHandler,
uint256 timelockDeadline
);
functionpermLocked() externalviewreturns (bool);
functionpermForgeHandlerLocked() externalviewreturns (bool);
functionpermMarketHandlerLocked() externalviewreturns (bool);
functionpermLiqMiningHandlerLocked() externalviewreturns (bool);
functionisPausingAdmin(address) externalviewreturns (bool);
functionsetPausingAdmin(address admin, bool isAdmin) external;
functionrequestForgeHandlerChange(address _pendingForgeHandler) external;
functionrequestMarketHandlerChange(address _pendingMarketHandler) external;
functionrequestLiqMiningHandlerChange(address _pendingLiqMiningHandler) external;
functionapplyForgeHandlerChange() external;
functionapplyMarketHandlerChange() external;
functionapplyLiqMiningHandlerChange() external;
functionlockPausingManagerPermanently() external;
functionlockForgeHandlerPermanently() external;
functionlockMarketHandlerPermanently() external;
functionlockLiqMiningHandlerPermanently() external;
functionsetForgePaused(bytes32 forgeId, bool paused) external;
functionsetForgeAssetPaused(bytes32 forgeId,
address underlyingAsset,
bool paused
) external;
functionsetForgeAssetExpiryPaused(bytes32 forgeId,
address underlyingAsset,
uint256 expiry,
bool paused
) external;
functionsetForgeLocked(bytes32 forgeId) external;
functionsetForgeAssetLocked(bytes32 forgeId, address underlyingAsset) external;
functionsetForgeAssetExpiryLocked(bytes32 forgeId,
address underlyingAsset,
uint256 expiry
) external;
functioncheckYieldContractStatus(bytes32 forgeId,
address underlyingAsset,
uint256 expiry
) externalreturns (bool _paused, bool _locked);
functionsetMarketFactoryPaused(bytes32 marketFactoryId, bool paused) external;
functionsetMarketPaused(bytes32 marketFactoryId,
address market,
bool paused
) external;
functionsetMarketFactoryLocked(bytes32 marketFactoryId) external;
functionsetMarketLocked(bytes32 marketFactoryId, address market) external;
functioncheckMarketStatus(bytes32 marketFactoryId, address market)
externalreturns (bool _paused, bool _locked);
functionsetLiqMiningPaused(address liqMiningContract, bool settingToPaused) external;
functionsetLiqMiningLocked(address liqMiningContract) external;
functioncheckLiqMiningStatus(address liqMiningContract)
externalreturns (bool _paused, bool _locked);
}
Contract Source Code
File 9 of 23: IPendleRewardManager.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;interfaceIPendleRewardManager{
eventUpdateFrequencySet(address[], uint256[]);
eventSkippingRewardsSet(bool);
eventDueRewardsSettled(bytes32 forgeId,
address underlyingAsset,
uint256 expiry,
uint256 amountOut,
address user
);
functionredeemRewards(address _underlyingAsset,
uint256 _expiry,
address _user
) externalreturns (uint256 dueRewards);
functionupdatePendingRewards(address _underlyingAsset,
uint256 _expiry,
address _user
) external;
functionupdateParamLManual(address _underlyingAsset, uint256 _expiry) external;
functionsetUpdateFrequency(address[] calldata underlyingAssets,
uint256[] calldata frequencies
) external;
functionsetSkippingRewards(bool skippingRewards) external;
functionforgeId() externalreturns (bytes32);
}
Contract Source Code
File 10 of 23: IPendleRouter.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;pragmaabicoderv2;import"../interfaces/IWETH.sol";
import"./IPendleData.sol";
import"../libraries/PendleStructs.sol";
import"./IPendleMarketFactory.sol";
interfaceIPendleRouter{
/**
* @notice Emitted when a market for a future yield token and an ERC20 token is created.
* @param marketFactoryId Forge identifier.
* @param xyt The address of the tokenized future yield token as the base asset.
* @param token The address of an ERC20 token as the quote asset.
* @param market The address of the newly created market.
**/eventMarketCreated(bytes32 marketFactoryId,
addressindexed xyt,
addressindexed token,
addressindexed market
);
/**
* @notice Emitted when a swap happens on the market.
* @param trader The address of msg.sender.
* @param inToken The input token.
* @param outToken The output token.
* @param exactIn The exact amount being traded.
* @param exactOut The exact amount received.
* @param market The market address.
**/eventSwapEvent(addressindexed trader,
address inToken,
address outToken,
uint256 exactIn,
uint256 exactOut,
address market
);
/**
* @dev Emitted when user adds liquidity
* @param sender The user who added liquidity.
* @param token0Amount the amount of token0 (xyt) provided by user
* @param token1Amount the amount of token1 provided by user
* @param market The market address.
* @param exactOutLp The exact LP minted
*/eventJoin(addressindexed sender,
uint256 token0Amount,
uint256 token1Amount,
address market,
uint256 exactOutLp
);
/**
* @dev Emitted when user removes liquidity
* @param sender The user who removed liquidity.
* @param token0Amount the amount of token0 (xyt) given to user
* @param token1Amount the amount of token1 given to user
* @param market The market address.
* @param exactInLp The exact Lp to remove
*/eventExit(addressindexed sender,
uint256 token0Amount,
uint256 token1Amount,
address market,
uint256 exactInLp
);
/**
* @notice Gets a reference to the PendleData contract.
* @return Returns the data contract reference.
**/functiondata() externalviewreturns (IPendleData);
/**
* @notice Gets a reference of the WETH9 token contract address.
* @return WETH token reference.
**/functionweth() externalviewreturns (IWETH);
/***********
* FORGE *
***********/functionnewYieldContracts(bytes32 forgeId,
address underlyingAsset,
uint256 expiry
) externalreturns (address ot, address xyt);
functionredeemAfterExpiry(bytes32 forgeId,
address underlyingAsset,
uint256 expiry
) externalreturns (uint256 redeemedAmount);
functionredeemDueInterests(bytes32 forgeId,
address underlyingAsset,
uint256 expiry,
address user
) externalreturns (uint256 interests);
functionredeemUnderlying(bytes32 forgeId,
address underlyingAsset,
uint256 expiry,
uint256 amountToRedeem
) externalreturns (uint256 redeemedAmount);
functionrenewYield(bytes32 forgeId,
uint256 oldExpiry,
address underlyingAsset,
uint256 newExpiry,
uint256 renewalRate
)
externalreturns (uint256 redeemedAmount,
uint256 amountRenewed,
address ot,
address xyt,
uint256 amountTokenMinted
);
functiontokenizeYield(bytes32 forgeId,
address underlyingAsset,
uint256 expiry,
uint256 amountToTokenize,
address to
)
externalreturns (address ot,
address xyt,
uint256 amountTokenMinted
);
/***********
* MARKET *
***********/functionaddMarketLiquidityDual(bytes32 _marketFactoryId,
address _xyt,
address _token,
uint256 _desiredXytAmount,
uint256 _desiredTokenAmount,
uint256 _xytMinAmount,
uint256 _tokenMinAmount
)
externalpayablereturns (uint256 amountXytUsed,
uint256 amountTokenUsed,
uint256 lpOut
);
functionaddMarketLiquiditySingle(bytes32 marketFactoryId,
address xyt,
address token,
bool forXyt,
uint256 exactInAsset,
uint256 minOutLp
) externalpayablereturns (uint256 exactOutLp);
functionremoveMarketLiquidityDual(bytes32 marketFactoryId,
address xyt,
address token,
uint256 exactInLp,
uint256 minOutXyt,
uint256 minOutToken
) externalreturns (uint256 exactOutXyt, uint256 exactOutToken);
functionremoveMarketLiquiditySingle(bytes32 marketFactoryId,
address xyt,
address token,
bool forXyt,
uint256 exactInLp,
uint256 minOutAsset
) externalreturns (uint256 exactOutXyt, uint256 exactOutToken);
/**
* @notice Creates a market given a protocol ID, future yield token, and an ERC20 token.
* @param marketFactoryId Market Factory identifier.
* @param xyt Token address of the future yield token as base asset.
* @param token Token address of an ERC20 token as quote asset.
* @return market Returns the address of the newly created market.
**/functioncreateMarket(bytes32 marketFactoryId,
address xyt,
address token
) externalreturns (address market);
functionbootstrapMarket(bytes32 marketFactoryId,
address xyt,
address token,
uint256 initialXytLiquidity,
uint256 initialTokenLiquidity
) externalpayable;
functionswapExactIn(address tokenIn,
address tokenOut,
uint256 inTotalAmount,
uint256 minOutTotalAmount,
bytes32 marketFactoryId
) externalpayablereturns (uint256 outTotalAmount);
functionswapExactOut(address tokenIn,
address tokenOut,
uint256 outTotalAmount,
uint256 maxInTotalAmount,
bytes32 marketFactoryId
) externalpayablereturns (uint256 inTotalAmount);
functionredeemLpInterests(address market, address user) externalreturns (uint256 interests);
}
Contract Source Code
File 11 of 23: IPendleYieldContractDeployer.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;interfaceIPendleYieldContractDeployer{
functionforgeId() externalreturns (bytes32);
functionforgeOwnershipToken(address _underlyingAsset,
stringmemory _name,
stringmemory _symbol,
uint8 _decimals,
uint256 _expiry
) externalreturns (address ot);
functionforgeFutureYieldToken(address _underlyingAsset,
stringmemory _name,
stringmemory _symbol,
uint8 _decimals,
uint256 _expiry
) externalreturns (address xyt);
functiondeployYieldTokenHolder(address yieldToken, uint256 expiry)
externalreturns (address yieldTokenHolder);
}
Contract Source Code
File 12 of 23: IPendleYieldToken.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"./IPendleBaseToken.sol";
import"./IPendleForge.sol";
interfaceIPendleYieldTokenisIERC20, IPendleBaseToken{
/**
* @notice Emitted when burning OT or XYT tokens.
* @param user The address performing the burn.
* @param amount The amount to be burned.
**/eventBurn(addressindexed user, uint256 amount);
/**
* @notice Emitted when minting OT or XYT tokens.
* @param user The address performing the mint.
* @param amount The amount to be minted.
**/eventMint(addressindexed user, uint256 amount);
/**
* @notice Burns OT or XYT tokens from user, reducing the total supply.
* @param user The address performing the burn.
* @param amount The amount to be burned.
**/functionburn(address user, uint256 amount) external;
/**
* @notice Mints new OT or XYT tokens for user, increasing the total supply.
* @param user The address to send the minted tokens.
* @param amount The amount to be minted.
**/functionmint(address user, uint256 amount) external;
/**
* @notice Gets the forge address of the PendleForge contract for this yield token.
* @return Retuns the forge address.
**/functionforge() externalviewreturns (IPendleForge);
/**
* @notice Returns the address of the underlying asset.
* @return Returns the underlying asset address.
**/functionunderlyingAsset() externalviewreturns (address);
/**
* @notice Returns the address of the underlying yield token.
* @return Returns the underlying yield token address.
**/functionunderlyingYieldToken() externalviewreturns (address);
/**
* @notice let the router approve itself to spend OT/XYT/LP from any wallet
* @param user user to approve
**/functionapproveRouter(address user) external;
}
Contract Source Code
File 13 of 23: IPermissionsV2.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;pragmaabicoderv2;import"../core/PendleGovernanceManager.sol";
interfaceIPermissionsV2{
functiongovernanceManager() externalreturns (PendleGovernanceManager);
}
Contract Source Code
File 14 of 23: IWETH.sol
// SPDX-License-Identifier: MIT/*
* 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
*/pragmasolidity 0.7.6;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
interfaceIWETHisIERC20{
functiondeposit() externalpayable;
functionwithdraw(uint256 wad) external;
}
Contract Source Code
File 15 of 23: MathLib.sol
// SPDX-License-Identifier: GPL-2.0-or-laterpragmasolidity ^0.7.0;pragmaabicoderv2;import"@openzeppelin/contracts/math/SafeMath.sol";
libraryMath{
usingSafeMathforuint256;
uint256internalconstant BIG_NUMBER = (uint256(1) <<uint256(200));
uint256internalconstant PRECISION_BITS =40;
uint256internalconstant RONE =uint256(1) << PRECISION_BITS;
uint256internalconstant PI = (314* RONE) /10**2;
uint256internalconstant PI_PLUSONE = (414* RONE) /10**2;
uint256internalconstant PRECISION_POW =1e2;
functioncheckMultOverflow(uint256 _x, uint256 _y) internalpurereturns (bool) {
if (_y ==0) returnfalse;
return (((_x * _y) / _y) != _x);
}
/**
@notice find the integer part of log2(p/q)
=> find largest x s.t p >= q * 2^x
=> find largest x s.t 2^x <= p / q
*/functionlog2Int(uint256 _p, uint256 _q) internalpurereturns (uint256) {
uint256 res =0;
uint256 remain = _p / _q;
while (remain >0) {
res++;
remain /=2;
}
return res -1;
}
/**
@notice log2 for a number that it in [1,2)
@dev _x is FP, return a FP
@dev function is from Kyber. Long modified the condition to be (_x >= one) && (_x < two)
to avoid the case where x = 2 may lead to incorrect result
*/functionlog2ForSmallNumber(uint256 _x) internalpurereturns (uint256) {
uint256 res =0;
uint256 one = (uint256(1) << PRECISION_BITS);
uint256 two =2* one;
uint256 addition = one;
require((_x >= one) && (_x < two), "MATH_ERROR");
require(PRECISION_BITS <125, "MATH_ERROR");
for (uint256 i = PRECISION_BITS; i >0; i--) {
_x = (_x * _x) / one;
addition = addition /2;
if (_x >= two) {
_x = _x /2;
res += addition;
}
}
return res;
}
/**
@notice log2 of (p/q). returns result in FP form
@dev function is from Kyber.
@dev _p & _q is FP, return a FP
*/functionlogBase2(uint256 _p, uint256 _q) internalpurereturns (uint256) {
uint256 n =0;
if (_p > _q) {
n = log2Int(_p, _q);
}
require(n * RONE <= BIG_NUMBER, "MATH_ERROR");
require(!checkMultOverflow(_p, RONE), "MATH_ERROR");
require(!checkMultOverflow(n, RONE), "MATH_ERROR");
require(!checkMultOverflow(uint256(1) << n, _q), "MATH_ERROR");
uint256 y = (_p * RONE) / (_q * (uint256(1) << n));
uint256 log2Small = log2ForSmallNumber(y);
assert(log2Small <= BIG_NUMBER);
return n * RONE + log2Small;
}
/**
@notice calculate ln(p/q). returned result >= 0
@dev function is from Kyber.
@dev _p & _q is FP, return a FP
*/functionln(uint256 p, uint256 q) internalpurereturns (uint256) {
uint256 ln2Numerator =6931471805599453094172;
uint256 ln2Denomerator =10000000000000000000000;
uint256 log2x = logBase2(p, q);
require(!checkMultOverflow(ln2Numerator, log2x), "MATH_ERROR");
return (ln2Numerator * log2x) / ln2Denomerator;
}
/**
@notice extract the fractional part of a FP
@dev value is a FP, return a FP
*/functionfpart(uint256 value) internalpurereturns (uint256) {
return value % RONE;
}
/**
@notice convert a FP to an Int
@dev value is a FP, return an Int
*/functiontoInt(uint256 value) internalpurereturns (uint256) {
return value / RONE;
}
/**
@notice convert an Int to a FP
@dev value is an Int, return a FP
*/functiontoFP(uint256 value) internalpurereturns (uint256) {
return value * RONE;
}
/**
@notice return e^exp in FP form
@dev estimation by formula at http://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/exp.html
the function is based on exp function of:
https://github.com/NovakDistributed/macroverse/blob/master/contracts/RealMath.sol
@dev the function is expected to converge quite fast, after about 20 iteration
@dev exp is a FP, return a FP
*/functionrpowe(uint256 exp) internalpurereturns (uint256) {
uint256 res =0;
uint256 curTerm = RONE;
for (uint256 n =0; ; n++) {
res += curTerm;
curTerm = rmul(curTerm, rdiv(exp, toFP(n +1)));
if (curTerm ==0) {
break;
}
if (n ==500) {
/*
testing shows that in the most extreme case, it will take 430 turns to converge.
however, it's expected that the numbers will not exceed 2^120 in normal situation
the most extreme case is rpow((1<<256)-1,(1<<40)-1) (equal to rpow((2^256-1)/2^40,0.99..9))
*/revert("RPOWE_SLOW_CONVERGE");
}
}
return res;
}
/**
@notice calculate base^exp with base and exp being FP int
@dev to improve accuracy, base^exp = base^(int(exp)+frac(exp))
= base^int(exp) * base^frac
@dev base & exp are FP, return a FP
*/functionrpow(uint256 base, uint256 exp) internalpurereturns (uint256) {
if (exp ==0) {
// Anything to the 0 is 1return RONE;
}
if (base ==0) {
// 0 to anything except 0 is 0return0;
}
uint256 frac = fpart(exp); // get the fractional partuint256 whole = exp - frac;
uint256 wholePow = rpowi(base, toInt(whole)); // whole is a FP, convert to Intuint256 fracPow;
// instead of calculating base ^ frac, we will calculate e ^ (frac*ln(base))if (base < RONE) {
/* since the base is smaller than 1.0, ln(base) < 0.
Since 1 / (e^(frac*ln(1/base))) = e ^ (frac*ln(base)),
we will calculate 1 / (e^(frac*ln(1/base))) instead.
*/uint256 newExp = rmul(frac, ln(rdiv(RONE, base), RONE));
fracPow = rdiv(RONE, rpowe(newExp));
} else {
/* base is greater than 1, calculate normally */uint256 newExp = rmul(frac, ln(base, RONE));
fracPow = rpowe(newExp);
}
return rmul(wholePow, fracPow);
}
/**
@notice return base^exp with base in FP form and exp in Int
@dev this function use a technique called: exponentiating by squaring
complexity O(log(q))
@dev function is from Kyber.
@dev base is a FP, exp is an Int, return a FP
*/functionrpowi(uint256 base, uint256 exp) internalpurereturns (uint256) {
uint256 res = exp %2!=0 ? base : RONE;
for (exp /=2; exp !=0; exp /=2) {
base = rmul(base, base);
if (exp %2!=0) {
res = rmul(res, base);
}
}
return res;
}
/**
@dev y is an Int, returns an Int
@dev babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
@dev from Uniswap
*/functionsqrt(uint256 y) internalpurereturns (uint256 z) {
if (y >3) {
z = y;
uint256 x = y /2+1;
while (x < z) {
z = x;
x = (y / x + x) /2;
}
} elseif (y !=0) {
z =1;
}
}
/**
@notice divide 2 FP, return a FP
@dev function is from Balancer.
@dev x & y are FP, return a FP
*/functionrdiv(uint256 x, uint256 y) internalpurereturns (uint256) {
return (y /2).add(x.mul(RONE)).div(y);
}
/**
@notice multiply 2 FP, return a FP
@dev function is from Balancer.
@dev x & y are FP, return a FP
*/functionrmul(uint256 x, uint256 y) internalpurereturns (uint256) {
return (RONE /2).add(x.mul(y)).div(RONE);
}
functionmax(uint256 a, uint256 b) internalpurereturns (uint256) {
return a >= b ? a : b;
}
functionmin(uint256 a, uint256 b) internalpurereturns (uint256) {
return a < b ? a : b;
}
functionsubMax0(uint256 a, uint256 b) internalpurereturns (uint256) {
return a >= b ? a - b : 0;
}
}
Contract Source Code
File 16 of 23: PendleGovernanceManager.sol
// SPDX-License-Identifier: BUSL-1.1pragmasolidity 0.7.6;contractPendleGovernanceManager{
addresspublic governance;
addresspublic pendingGovernance;
eventGovernanceClaimed(address newGovernance, address previousGovernance);
eventTransferGovernancePending(address pendingGovernance);
constructor(address _governance) {
require(_governance !=address(0), "ZERO_ADDRESS");
governance = _governance;
}
modifieronlyGovernance() {
require(msg.sender== governance, "ONLY_GOVERNANCE");
_;
}
/**
* @dev Allows the pendingGovernance address to finalize the change governance process.
*/functionclaimGovernance() external{
require(pendingGovernance ==msg.sender, "WRONG_GOVERNANCE");
emit GovernanceClaimed(pendingGovernance, governance);
governance = pendingGovernance;
pendingGovernance =address(0);
}
/**
* @dev Allows the current governance to set the pendingGovernance address.
* @param _governance The address to transfer ownership to.
*/functiontransferGovernance(address _governance) externalonlyGovernance{
require(_governance !=address(0), "ZERO_ADDRESS");
pendingGovernance = _governance;
emit TransferGovernancePending(pendingGovernance);
}
}
Contract Source Code
File 17 of 23: PendleRouter.sol
// SPDX-License-Identifier: BUSL-1.1pragmasolidity 0.7.6;pragmaabicoderv2;import"@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import"@openzeppelin/contracts/math/SafeMath.sol";
import"../libraries/MathLib.sol";
import"../interfaces/IPendleRouter.sol";
import"../interfaces/IPendleData.sol";
import"../interfaces/IPendleForge.sol";
import"../interfaces/IPendleMarketFactory.sol";
import"../interfaces/IPendleMarket.sol";
import"../periphery/PermissionsV2.sol";
import"../periphery/WithdrawableV2.sol";
import"../periphery/PendleRouterNonReentrant.sol";
/**
@dev OVERALL NOTE:
* The router will not hold any funds, instead it will just help sending funds to other contracts & users
* addLiquidity/removeLiquidity/swap all supports auto wrap of ETH
- There will be no markets of XYT-ETH, only markets of XYT-WETH
- If users want to send in / receive ETH, just pass the ETH_ADDRESS to the corresponding field,
the router will automatically wrap/unwrap WETH and interact with markets
- principle of ETH wrap implementation: always use the token with the "original" prefix for transfer,
and use the non-original token (_xyt, _token...) in all other cases
* Markets will not transfer any XYT/baseToken, but instead make requests to Router through the transfer array
and the Router will transfer them
*/contractPendleRouterisIPendleRouter, WithdrawableV2, PendleRouterNonReentrant{
usingSafeERC20forIERC20;
usingSafeMathforuint256;
usingMathforuint256;
IWETH publicimmutableoverride weth;
IPendleData publicimmutableoverride data;
addressprivateconstant ETH_ADDRESS =address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
// if someone's allowance for the router is below this amount,// we will approve the router again (to spend from their account)// if we already call .approveRouter for the a token, we shouldn't need to approve againuint256privateconstant REASONABLE_ALLOWANCE_AMOUNT =type(uint256).max/2;
constructor(address _governanceManager,
IWETH _weth,
IPendleData _data
) PermissionsV2(_governanceManager) PendleRouterNonReentrant() {
weth = _weth;
data = _data;
}
/**
* @dev Accepts ETH via fallback from the WETH contract.
**/receive() externalpayable{
require(msg.sender==address(weth), "ETH_NOT_FROM_WETH");
}
/**
* @notice Create a new pair of OT + XYT tokens to represent the
* principal and interest for an underlying asset, until an expiry
Conditions:
* _expiry must be divisible for expiryDivisor() so that there are not too many yieldContracts
* Any _underlyingAsset can be passed in, since there is no way to validate them
* Have Reentrancy protection
**/functionnewYieldContracts(bytes32 _forgeId,
address _underlyingAsset,
uint256 _expiry
) externaloverridenonReentrantreturns (address ot, address xyt) {
require(_underlyingAsset !=address(0), "ZERO_ADDRESS");
require(_expiry >block.timestamp, "INVALID_EXPIRY");
require(_expiry % data.expiryDivisor() ==0, "INVALID_EXPIRY");
IPendleForge forge = IPendleForge(data.getForgeAddress(_forgeId));
require(address(forge) !=address(0), "FORGE_NOT_EXISTS");
ot =address(data.otTokens(_forgeId, _underlyingAsset, _expiry));
xyt =address(data.xytTokens(_forgeId, _underlyingAsset, _expiry));
require(ot ==address(0) && xyt ==address(0), "DUPLICATE_YIELD_CONTRACT");
(ot, xyt) = forge.newYieldContracts(_underlyingAsset, _expiry);
}
/**
* @notice After an expiry, redeem OT tokens to get back the underlyingYieldToken
* and also any interests
* @notice This function acts as a proxy to the actual function
* @dev The interest from "the last global action before expiry" until the expiry
* is given to the OT holders. This is to simplify accounting. An assumption
* is that the last global action before expiry will be close to the expiry
* @dev all validity checks are in the internal function
Conditions:
* Have Reentrancy protection
**/functionredeemAfterExpiry(bytes32 _forgeId,
address _underlyingAsset,
uint256 _expiry
) publicoverridenonReentrantreturns (uint256 redeemedAmount) {
require(data.isValidXYT(_forgeId, _underlyingAsset, _expiry), "INVALID_YT");
require(_expiry <block.timestamp, "MUST_BE_AFTER_EXPIRY");
// guaranteed to be a valid forge by the isValidXYT check
IPendleForge forge = IPendleForge(data.getForgeAddress(_forgeId));
redeemedAmount = forge.redeemAfterExpiry(msg.sender, _underlyingAsset, _expiry);
}
/**
* @notice redeem the dueInterests from XYTs
* @dev all validity checks are in the internal function
Conditions:
* Have Reentrancy protection
**/functionredeemDueInterests(bytes32 _forgeId,
address _underlyingAsset,
uint256 _expiry,
address _user
) externaloverridenonReentrantreturns (uint256 interests) {
require(data.isValidXYT(_forgeId, _underlyingAsset, _expiry), "INVALID_YT");
require(_user !=address(0), "ZERO_ADDRESS");
IPendleForge forge = IPendleForge(data.getForgeAddress(_forgeId));
interests = forge.redeemDueInterests(_user, _underlyingAsset, _expiry);
}
/**
* @notice Before the expiry, a user can redeem the same amount of OT+XYT to get back
* the underlying yield token
Conditions:
* Have Reentrancy protection
**/functionredeemUnderlying(bytes32 _forgeId,
address _underlyingAsset,
uint256 _expiry,
uint256 _amountToRedeem
) externaloverridenonReentrantreturns (uint256 redeemedAmount) {
require(data.isValidXYT(_forgeId, _underlyingAsset, _expiry), "INVALID_YT");
require(block.timestamp< _expiry, "YIELD_CONTRACT_EXPIRED");
require(_amountToRedeem !=0, "ZERO_AMOUNT");
// guaranteed to be a valid forge by the isValidXYT check
IPendleForge forge = IPendleForge(data.getForgeAddress(_forgeId));
redeemedAmount = forge.redeemUnderlying(
msg.sender,
_underlyingAsset,
_expiry,
_amountToRedeem
);
}
/**
* @notice Use to renewYield. Basically a proxy to call redeemAfterExpiry & tokenizeYield
* @param _renewalRate a Fixed Point number, shows how much of the total redeemedAmount is renewed.
We allowed _renewalRate > RONE in case the user wants to increase his position
Conditions:
* No Reentrancy protection because it will just act as a proxy for 2 calls
**/functionrenewYield(bytes32 _forgeId,
uint256 _oldExpiry,
address _underlyingAsset,
uint256 _newExpiry,
uint256 _renewalRate
)
externaloverridereturns (uint256 redeemedAmount,
uint256 amountRenewed,
address ot,
address xyt,
uint256 amountTokenMinted
)
{
require(0< _renewalRate, "INVALID_RENEWAL_RATE");
redeemedAmount = redeemAfterExpiry(_forgeId, _underlyingAsset, _oldExpiry);
amountRenewed = redeemedAmount.rmul(_renewalRate);
(ot, xyt, amountTokenMinted) = tokenizeYield(
_forgeId,
_underlyingAsset,
_newExpiry,
amountRenewed,
msg.sender
);
}
/**
* @notice tokenize yield tokens to get OT+XYT. We allows tokenizing for others too
* @dev each forge is for a yield protocol (for example: Aave, Compound)
Conditions:
* Have Reentrancy protection
* Can only tokenize to a not-yet-expired XYT
**/functiontokenizeYield(bytes32 _forgeId,
address _underlyingAsset,
uint256 _expiry,
uint256 _amountToTokenize,
address _to
)
publicoverridenonReentrantreturns (address ot,
address xyt,
uint256 amountTokenMinted
)
{
require(data.isValidXYT(_forgeId, _underlyingAsset, _expiry), "INVALID_YT");
require(block.timestamp< _expiry, "YIELD_CONTRACT_EXPIRED");
require(_to !=address(0), "ZERO_ADDRESS");
require(_amountToTokenize !=0, "ZERO_AMOUNT");
// guaranteed to be a valid forge by the isValidXYT check
IPendleForge forge = IPendleForge(data.getForgeAddress(_forgeId));
// In this getYieldBearingToken call, the forge will check if there is// any yieldToken that matches the underlyingAsset. For more details please// check the getYieldBearingToken in forge
IERC20 yieldToken = IERC20(forge.getYieldBearingToken(_underlyingAsset));
// pull tokens in
yieldToken.safeTransferFrom(
msg.sender,
forge.yieldTokenHolders(_underlyingAsset, _expiry),
_amountToTokenize
);
// mint OT&XYT for users
(ot, xyt, amountTokenMinted) = forge.mintOtAndXyt(
_underlyingAsset,
_expiry,
_amountToTokenize,
_to
);
}
/**
* @notice add market liquidity by both xyt and baseToken
Conditions:
* Have Reentrancy protection
*/functionaddMarketLiquidityDual(bytes32 _marketFactoryId,
address _xyt,
address _token,
uint256 _desiredXytAmount,
uint256 _desiredTokenAmount,
uint256 _xytMinAmount,
uint256 _tokenMinAmount
)
publicpayableoverridenonReentrantreturns (uint256 amountXytUsed,
uint256 amountTokenUsed,
uint256 lpOut
)
{
require(
_desiredXytAmount !=0&& _desiredXytAmount >= _xytMinAmount,
"INVALID_YT_AMOUNTS"
);
require(
_desiredTokenAmount !=0&& _desiredTokenAmount >= _tokenMinAmount,
"INVALID_TOKEN_AMOUNTS"
);
address originalToken = _token;
_token = _isETH(_token) ? address(weth) : _token;
IPendleMarket market = IPendleMarket(data.getMarket(_marketFactoryId, _xyt, _token));
require(address(market) !=address(0), "MARKET_NOT_FOUND");
// note that LP minting will be done in the market
PendingTransfer[2] memory transfers;
(transfers, lpOut) = market.addMarketLiquidityDual(
msg.sender,
_desiredXytAmount,
_desiredTokenAmount,
_xytMinAmount,
_tokenMinAmount
);
_settlePendingTransfers(transfers, _xyt, originalToken, address(market));
amountXytUsed = transfers[0].amount;
amountTokenUsed = transfers[1].amount;
emit Join(msg.sender, amountXytUsed, amountTokenUsed, address(market), lpOut);
}
/**
* @notice add market liquidity by xyt or base token
* @dev no checks on _minOutLp
* @param _forXyt whether the user wants to addLiquidity by _xyt or _token
Conditions:
* Have Reentrancy protection
*/functionaddMarketLiquiditySingle(bytes32 _marketFactoryId,
address _xyt,
address _token,
bool _forXyt,
uint256 _exactIn,
uint256 _minOutLp
) externalpayableoverridenonReentrantreturns (uint256 exactOutLp) {
require(_exactIn !=0, "ZERO_AMOUNTS");
address originalToken = _token;
_token = _isETH(_token) ? address(weth) : _token;
IPendleMarket market = IPendleMarket(data.getMarket(_marketFactoryId, _xyt, _token));
require(address(market) !=address(0), "MARKET_NOT_FOUND");
address assetToTransferIn = _forXyt ? _xyt : originalToken;
address assetForMarket = _forXyt ? _xyt : _token;
// note that LP minting will be done in the market
PendingTransfer[2] memory transfers;
(transfers, exactOutLp) = market.addMarketLiquiditySingle(
msg.sender,
assetForMarket,
_exactIn,
_minOutLp
);
if (_forXyt) {
emit Join(msg.sender, _exactIn, 0, address(market), exactOutLp);
} else {
emit Join(msg.sender, 0, _exactIn, address(market), exactOutLp);
}
// We only need settle the transfering in of the assetToTransferIn
_settleTokenTransfer(assetToTransferIn, transfers[0], address(market));
}
/**
* @notice remove market liquidity by xyt and base tokens
* @dev no checks on _minOutXyt, _minOutToken
Conditions:
* Have Reentrancy protection
*/functionremoveMarketLiquidityDual(bytes32 _marketFactoryId,
address _xyt,
address _token,
uint256 _exactInLp,
uint256 _minOutXyt,
uint256 _minOutToken
) externaloverridenonReentrantreturns (uint256 exactOutXyt, uint256 exactOutToken) {
require(_exactInLp !=0, "ZERO_LP_IN");
address originalToken = _token;
_token = _isETH(_token) ? address(weth) : _token;
IPendleMarket market = IPendleMarket(data.getMarket(_marketFactoryId, _xyt, _token));
require(address(market) !=address(0), "MARKET_NOT_FOUND");
// note that LP burning will be done in the market
PendingTransfer[2] memory transfers =
market.removeMarketLiquidityDual(msg.sender, _exactInLp, _minOutXyt, _minOutToken);
_settlePendingTransfers(transfers, _xyt, originalToken, address(market));
exactOutXyt = transfers[0].amount;
exactOutToken = transfers[1].amount;
emit Exit(msg.sender, exactOutXyt, exactOutToken, address(market), _exactInLp);
}
/**
* @notice remove market liquidity by xyt or base tokens
* @dev no checks on _minOutAsset
* @param _forXyt whether the user wants to addLiquidity by _xyt or _token
Conditions:
* Have Reentrancy protection
*/functionremoveMarketLiquiditySingle(bytes32 _marketFactoryId,
address _xyt,
address _token,
bool _forXyt,
uint256 _exactInLp,
uint256 _minOutAsset
) externaloverridenonReentrantreturns (uint256 exactOutXyt, uint256 exactOutToken) {
require(_exactInLp !=0, "ZERO_LP_IN");
address originalToken = _token;
_token = _isETH(_token) ? address(weth) : _token;
IPendleMarket market = IPendleMarket(data.getMarket(_marketFactoryId, _xyt, _token));
require(address(market) !=address(0), "MARKET_NOT_FOUND");
address assetForMarket = _forXyt ? _xyt : _token;
// note that LP burning will be done in the market
PendingTransfer[2] memory transfers =
market.removeMarketLiquiditySingle(
msg.sender,
assetForMarket,
_exactInLp,
_minOutAsset
);
address assetToTransferOut = _forXyt ? _xyt : originalToken;
_settleTokenTransfer(assetToTransferOut, transfers[0], address(market));
if (_forXyt) {
emit Exit(msg.sender, transfers[0].amount, 0, address(market), _exactInLp);
return (transfers[0].amount, 0);
} else {
emit Exit(msg.sender, 0, transfers[0].amount, address(market), _exactInLp);
return (0, transfers[0].amount);
}
}
/**
* @notice create a new market for a pair of xyt & token
* @dev A market can be uniquely identified by the triplet(_marketFactoryId,_xyt,_token)
Conditions:
* Have Reentrancy protection
*/functioncreateMarket(bytes32 _marketFactoryId,
address _xyt,
address _token
) externaloverridenonReentrantreturns (address market) {
require(_xyt !=address(0), "ZERO_ADDRESS");
require(_token !=address(0), "ZERO_ADDRESS");
require(data.isXyt(_xyt), "INVALID_YT");
require(!data.isXyt(_token), "YT_QUOTE_PAIR_FORBIDDEN");
require(data.getMarket(_marketFactoryId, _xyt, _token) ==address(0), "EXISTED_MARKET");
IPendleMarketFactory factory =
IPendleMarketFactory(data.getMarketFactoryAddress(_marketFactoryId));
require(address(factory) !=address(0), "ZERO_ADDRESS");
bytes32 forgeId = IPendleForge(IPendleYieldToken(_xyt).forge()).forgeId();
require(data.validForgeFactoryPair(forgeId, _marketFactoryId), "INVALID_FORGE_FACTORY");
market = factory.createMarket(_xyt, _token);
emit MarketCreated(_marketFactoryId, _xyt, _token, market);
}
/**
* @notice bootstrap a market (aka the first one to add liquidity)
Conditions:
* Have Reentrancy protection
*/functionbootstrapMarket(bytes32 _marketFactoryId,
address _xyt,
address _token,
uint256 _initialXytLiquidity,
uint256 _initialTokenLiquidity
) externalpayableoverridenonReentrant{
require(_initialXytLiquidity >0, "INVALID_YT_AMOUNT");
require(_initialTokenLiquidity >0, "INVALID_TOKEN_AMOUNT");
address originalToken = _token;
_token = _isETH(_token) ? address(weth) : _token;
IPendleMarket market = IPendleMarket(data.getMarket(_marketFactoryId, _xyt, _token));
require(address(market) !=address(0), "MARKET_NOT_FOUND");
PendingTransfer[2] memory transfers;
uint256 exactOutLp;
(transfers, exactOutLp) = market.bootstrap(
msg.sender,
_initialXytLiquidity,
_initialTokenLiquidity
);
_settlePendingTransfers(transfers, _xyt, originalToken, address(market));
emit Join(
msg.sender,
_initialXytLiquidity,
_initialTokenLiquidity,
address(market),
exactOutLp
);
}
/**
* @notice trade by swap exact amount of token into market
* @dev no checks on _minOutAmount
Conditions:
* Have Reentrancy protection
*/functionswapExactIn(address _tokenIn,
address _tokenOut,
uint256 _inAmount,
uint256 _minOutAmount,
bytes32 _marketFactoryId
) externalpayableoverridenonReentrantreturns (uint256 outSwapAmount) {
require(_inAmount !=0, "ZERO_IN_AMOUNT");
address originalTokenIn = _tokenIn;
address originalTokenOut = _tokenOut;
_tokenIn = _isETH(_tokenIn) ? address(weth) : _tokenIn;
_tokenOut = _isETH(_tokenOut) ? address(weth) : _tokenOut;
IPendleMarket market =
IPendleMarket(data.getMarketFromKey(_tokenIn, _tokenOut, _marketFactoryId));
require(address(market) !=address(0), "MARKET_NOT_FOUND");
PendingTransfer[2] memory transfers;
(outSwapAmount, transfers) = market.swapExactIn(
_tokenIn,
_inAmount,
_tokenOut,
_minOutAmount
);
_settlePendingTransfers(transfers, originalTokenIn, originalTokenOut, address(market));
emit SwapEvent(msg.sender, _tokenIn, _tokenOut, _inAmount, outSwapAmount, address(market));
}
/**
* @notice trade by swap exact amount of token out of market
* @dev no checks on _maxInAmount
Conditions:
* Have Reentrancy protection
*/functionswapExactOut(address _tokenIn,
address _tokenOut,
uint256 _outAmount,
uint256 _maxInAmount,
bytes32 _marketFactoryId
) externalpayableoverridenonReentrantreturns (uint256 inSwapAmount) {
require(_outAmount !=0, "ZERO_OUT_AMOUNT");
address originalTokenIn = _tokenIn;
address originalTokenOut = _tokenOut;
_tokenIn = _isETH(_tokenIn) ? address(weth) : _tokenIn;
_tokenOut = _isETH(_tokenOut) ? address(weth) : _tokenOut;
IPendleMarket market =
IPendleMarket(data.getMarketFromKey(_tokenIn, _tokenOut, _marketFactoryId));
require(address(market) !=address(0), "MARKET_NOT_FOUND");
PendingTransfer[2] memory transfers;
(inSwapAmount, transfers) = market.swapExactOut(
_tokenIn,
_maxInAmount,
_tokenOut,
_outAmount
);
_settlePendingTransfers(transfers, originalTokenIn, originalTokenOut, address(market));
emit SwapEvent(msg.sender, _tokenIn, _tokenOut, inSwapAmount, _outAmount, address(market));
}
/**
* @notice For Lp holders to claim Lp interests
Conditions:
* Have Reentrancy protection
*/functionredeemLpInterests(address market, address user)
externaloverridenonReentrantreturns (uint256 interests)
{
require(data.isMarket(market), "INVALID_MARKET");
require(user !=address(0), "ZERO_ADDRESS");
interests = IPendleMarket(market).redeemLpInterests(user);
}
function_getData() internalviewoverridereturns (IPendleData) {
return data;
}
function_isETH(address token) internalpurereturns (bool) {
return (token == ETH_ADDRESS);
}
/**
* @notice This function takes in the standard array PendingTransfer[2] that represents
* any pending transfers of tokens to be done between a market and msg.sender
* @dev transfers[0] and transfers[1] always represent the tokens that are traded
* The convention is that:
* - if its a function with xyt and baseToken, transfers[0] is always xyt
* - if its a function with tokenIn and tokenOut, transfers[0] is always tokenOut
*/function_settlePendingTransfers(
PendingTransfer[2] memory transfers,
address firstToken,
address secondToken,
address market
) internal{
_settleTokenTransfer(firstToken, transfers[0], market);
_settleTokenTransfer(secondToken, transfers[1], market);
}
/**
* @notice This function settles a PendingTransfer, where the token could be ETH_ADDRESS
* a PendingTransfer is always between a market and msg.sender
*/function_settleTokenTransfer(address token,
PendingTransfer memory transfer,
address market
) internal{
if (transfer.amount ==0) {
return;
}
if (transfer.isOut) {
if (_isETH(token)) {
weth.transferFrom(market, address(this), transfer.amount);
weth.withdraw(transfer.amount);
(bool success, ) =msg.sender.call{value: transfer.amount}("");
require(success, "TRANSFER_FAILED");
} else {
IERC20(token).safeTransferFrom(market, msg.sender, transfer.amount);
}
} else {
if (_isETH(token)) {
require(msg.value>= transfer.amount, "INSUFFICENT_ETH_AMOUNT");
// we only need transfer.amount, so we return the excessuint256 excess =msg.value.sub(transfer.amount);
if (excess !=0) {
(bool success, ) =msg.sender.call{value: excess}("");
require(success, "TRANSFER_FAILED");
}
weth.deposit{value: transfer.amount}();
weth.transfer(market, transfer.amount);
} else {
// its a transfer in of token. If its an XYT// we will auto approve the router to spend from the user account;if (data.isXyt(token)) {
_checkApproveRouter(token);
}
IERC20(token).safeTransferFrom(msg.sender, market, transfer.amount);
}
}
}
// Check if an user has approved the router to spend the amount// if not, approve the router to spend the token from the user accountfunction_checkApproveRouter(address token) internal{
uint256 allowance = IPendleBaseToken(token).allowance(msg.sender, address(this));
if (allowance >= REASONABLE_ALLOWANCE_AMOUNT) return;
IPendleYieldToken(token).approveRouter(msg.sender);
}
// There shouldn't be any fund in here// hence governance is allowed to withdraw anything from here.function_allowedToWithdraw(address) internalpureoverridereturns (bool allowed) {
allowed =true;
}
}
Contract Source Code
File 18 of 23: PendleRouterNonReentrant.sol
// SPDX-License-Identifier: BUSL-1.1pragmasolidity 0.7.6;pragmaabicoderv2;import"../interfaces/IPendleData.sol";
abstractcontractPendleRouterNonReentrant{
uint8internal _guardCounter;
modifiernonReentrant() {
_checkNonReentrancy(); // use functions to reduce bytecode size_;
_guardCounter--;
}
constructor() {
_guardCounter =1;
}
/**
* We allow markets to make at most ONE Reentrant call
in the case of redeemLpInterests
* The flow of redeemLpInterests will be: Router.redeemLpInterests -> market.redeemLpInterests
-> Router.redeemDueInterests (so there is at most ONE Reentrant call)
*/function_checkNonReentrancy() internal{
if (_getData().isMarket(msg.sender)) {
require(_guardCounter <=2, "REENTRANT_CALL");
} else {
require(_guardCounter ==1, "REENTRANT_CALL");
}
_guardCounter++;
}
function_getData() internalviewvirtualreturns (IPendleData);
}
// SPDX-License-Identifier: MITpragmasolidity >=0.6.0 <0.8.0;import"./IERC20.sol";
import"../../math/SafeMath.sol";
import"../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 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.
*/librarySafeERC20{
usingSafeMathforuint256;
usingAddressforaddress;
functionsafeTransfer(IERC20 token, address to, uint256 value) internal{
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
functionsafeTransferFrom(IERC20 token, addressfrom, address to, uint256 value) internal{
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/functionsafeApprove(IERC20 token, address spender, uint256 value) internal{
// safeApprove should only be called when setting an initial allowance,// or when resetting it to zero. To increase and decrease it, use// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'// solhint-disable-next-line max-line-lengthrequire((value ==0) || (token.allowance(address(this), spender) ==0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
functionsafeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal{
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
functionsafeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal{
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @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).
*/function_callOptionalReturn(IERC20 token, bytesmemory data) private{
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that// the target address contains contract code and also asserts for success in the low-level call.bytesmemory returndata =address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length>0) { // Return data is optional// solhint-disable-next-line max-line-lengthrequire(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
Contract Source Code
File 22 of 23: SafeMath.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.6.0 <0.8.0;/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/librarySafeMath{
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/functiontryAdd(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/functiontrySub(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/functiontryMul(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the// benefit is lost if 'b' is also tested.// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522if (a ==0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/functiontryDiv(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
if (b ==0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/functiontryMod(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
if (b ==0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
if (a ==0) return0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
require(b >0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
require(b >0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/functionsub(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functiondiv(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b >0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functionmod(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b >0, errorMessage);
return a % b;
}
}
Contract Source Code
File 23 of 23: WithdrawableV2.sol
// SPDX-License-Identifier: BUSL-1.1pragmasolidity 0.7.6;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import"./PermissionsV2.sol";
abstractcontractWithdrawableV2isPermissionsV2{
usingSafeERC20forIERC20;
eventEtherWithdraw(uint256 amount, address sendTo);
eventTokenWithdraw(IERC20 token, uint256 amount, address sendTo);
/**
* @dev Allows governance to withdraw Ether in a Pendle contract
* in case of accidental ETH transfer into the contract.
* @param amount The amount of Ether to withdraw.
* @param sendTo The recipient address.
*/functionwithdrawEther(uint256 amount, addresspayable sendTo) externalonlyGovernance{
(bool success, ) = sendTo.call{value: amount}("");
require(success, "WITHDRAW_FAILED");
emit EtherWithdraw(amount, sendTo);
}
/**
* @dev Allows governance to withdraw all IERC20 compatible tokens in a Pendle
* contract in case of accidental token transfer into the contract.
* @param token IERC20 The address of the token contract.
* @param amount The amount of IERC20 tokens to withdraw.
* @param sendTo The recipient address.
*/functionwithdrawToken(
IERC20 token,
uint256 amount,
address sendTo
) externalonlyGovernance{
require(_allowedToWithdraw(address(token)), "TOKEN_NOT_ALLOWED");
token.safeTransfer(sendTo, amount);
emit TokenWithdraw(token, amount, sendTo);
}
// must be overridden by the sub contracts, so we must consider explicitly// in each and every contract which tokens are allowed to be withdrawnfunction_allowedToWithdraw(address) internalviewvirtualreturns (bool allowed);
}