feat: add balancer v2 executor

This commit is contained in:
royvardhan
2025-01-27 22:54:56 +05:30
parent 0e0c13b169
commit a700189aaf
98 changed files with 6368 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
interface IAToken {
/**
* @dev returns the address of the aToken's underlying asset
*/
// solhint-disable-next-line func-name-mixedcase
function UNDERLYING_ASSET_ADDRESS() external view returns (address);
}

View File

@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/helpers/IAuthentication.sol";
import "../solidity-utils/openzeppelin/IERC20.sol";
interface IBALTokenHolder is IAuthentication {
function getName() external view returns (string memory);
function withdrawFunds(address recipient, uint256 amount) external;
function sweepTokens(
IERC20 token,
address recipient,
uint256 amount
) external;
}

View File

@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../vault/IVault.sol";
import "../liquidity-mining/IBalancerToken.sol";
import "./IBALTokenHolder.sol";
interface IBALTokenHolderFactory {
function getBalancerToken() external view returns (IBalancerToken);
function getVault() external view returns (IVault);
function isHolderFromFactory(address holder) external view returns (bool);
function create(string memory name) external returns (IBALTokenHolder);
}

View File

@@ -0,0 +1,62 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "../vault/IVault.sol";
/**
* @dev Provides a way to perform queries on swaps, joins and exits, simulating these operations and returning the exact
* result they would have if called on the Vault given the current state. Note that the results will be affected by
* other transactions interacting with the Pools involved.
*
* All query functions can be called both on-chain and off-chain.
*
* If calling them from a contract, note that all query functions are not `view`. Despite this, these functions produce
* no net state change, and for all intents and purposes can be thought of as if they were indeed `view`. However,
* calling them via STATICCALL will fail.
*
* If calling them from an off-chain client, make sure to use eth_call: most clients default to eth_sendTransaction for
* non-view functions.
*
* In all cases, the `fromInternalBalance` and `toInternalBalance` fields are entirely ignored: we just use the same
* structs for simplicity.
*/
interface IBalancerQueries {
function querySwap(IVault.SingleSwap memory singleSwap, IVault.FundManagement memory funds)
external
returns (uint256);
function queryBatchSwap(
IVault.SwapKind kind,
IVault.BatchSwapStep[] memory swaps,
IAsset[] memory assets,
IVault.FundManagement memory funds
) external returns (int256[] memory assetDeltas);
function queryJoin(
bytes32 poolId,
address sender,
address recipient,
IVault.JoinPoolRequest memory request
) external returns (uint256 bptOut, uint256[] memory amountsIn);
function queryExit(
bytes32 poolId,
address sender,
address recipient,
IVault.ExitPoolRequest memory request
) external returns (uint256 bptIn, uint256[] memory amountsOut);
}

View File

@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "../vault/IVault.sol";
/**
* @title IBalancerRelayer
* @notice Allows safe multicall execution of a relayer's functions
*/
interface IBalancerRelayer {
function getLibrary() external view returns (address);
function getVault() external view returns (IVault);
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}

View File

@@ -0,0 +1,120 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
// Source: https://github.com/buttonwood-protocol/button-wrappers/blob/main/contracts/interfaces/IButtonWrapper.sol
// Interface definition for ButtonWrapper contract, which wraps an
// underlying ERC20 token into a new ERC20 with different characteristics.
// NOTE: "uAmount" => underlying token (wrapped) amount and
// "amount" => wrapper token amount
interface IButtonWrapper {
//--------------------------------------------------------------------------
// ButtonWrapper write methods
/// @notice Transfers underlying tokens from {msg.sender} to the contract and
/// mints wrapper tokens.
/// @param amount The amount of wrapper tokens to mint.
/// @return The amount of underlying tokens deposited.
function mint(uint256 amount) external returns (uint256);
/// @notice Transfers underlying tokens from {msg.sender} to the contract and
/// mints wrapper tokens to the specified beneficiary.
/// @param to The beneficiary account.
/// @param amount The amount of wrapper tokens to mint.
/// @return The amount of underlying tokens deposited.
function mintFor(address to, uint256 amount) external returns (uint256);
/// @notice Burns wrapper tokens from {msg.sender} and transfers
/// the underlying tokens back.
/// @param amount The amount of wrapper tokens to burn.
/// @return The amount of underlying tokens withdrawn.
function burn(uint256 amount) external returns (uint256);
/// @notice Burns wrapper tokens from {msg.sender} and transfers
/// the underlying tokens to the specified beneficiary.
/// @param to The beneficiary account.
/// @param amount The amount of wrapper tokens to burn.
/// @return The amount of underlying tokens withdrawn.
function burnTo(address to, uint256 amount) external returns (uint256);
/// @notice Burns all wrapper tokens from {msg.sender} and transfers
/// the underlying tokens back.
/// @return The amount of underlying tokens withdrawn.
function burnAll() external returns (uint256);
/// @notice Burns all wrapper tokens from {msg.sender} and transfers
/// the underlying tokens back.
/// @param to The beneficiary account.
/// @return The amount of underlying tokens withdrawn.
function burnAllTo(address to) external returns (uint256);
/// @notice Transfers underlying tokens from {msg.sender} to the contract and
/// mints wrapper tokens to the specified beneficiary.
/// @param uAmount The amount of underlying tokens to deposit.
/// @return The amount of wrapper tokens mint.
function deposit(uint256 uAmount) external returns (uint256);
/// @notice Transfers underlying tokens from {msg.sender} to the contract and
/// mints wrapper tokens to the specified beneficiary.
/// @param to The beneficiary account.
/// @param uAmount The amount of underlying tokens to deposit.
/// @return The amount of wrapper tokens mint.
function depositFor(address to, uint256 uAmount) external returns (uint256);
/// @notice Burns wrapper tokens from {msg.sender} and transfers
/// the underlying tokens back.
/// @param uAmount The amount of underlying tokens to withdraw.
/// @return The amount of wrapper tokens burnt.
function withdraw(uint256 uAmount) external returns (uint256);
/// @notice Burns wrapper tokens from {msg.sender} and transfers
/// the underlying tokens back to the specified beneficiary.
/// @param to The beneficiary account.
/// @param uAmount The amount of underlying tokens to withdraw.
/// @return The amount of wrapper tokens burnt.
function withdrawTo(address to, uint256 uAmount) external returns (uint256);
/// @notice Burns all wrapper tokens from {msg.sender} and transfers
/// the underlying tokens back.
/// @return The amount of wrapper tokens burnt.
function withdrawAll() external returns (uint256);
/// @notice Burns all wrapper tokens from {msg.sender} and transfers
/// the underlying tokens back.
/// @param to The beneficiary account.
/// @return The amount of wrapper tokens burnt.
function withdrawAllTo(address to) external returns (uint256);
//--------------------------------------------------------------------------
// ButtonWrapper view methods
/// @return The address of the underlying token.
function underlying() external view returns (address);
/// @return The total underlying tokens held by the wrapper contract.
function totalUnderlying() external view returns (uint256);
/// @param who The account address.
/// @return The underlying token balance of the account.
function balanceOfUnderlying(address who) external view returns (uint256);
/// @param uAmount The amount of underlying tokens.
/// @return The amount of wrapper tokens exchangeable.
function underlyingToWrapper(uint256 uAmount) external view returns (uint256);
/// @param amount The amount of wrapper tokens.
/// @return The amount of underlying tokens exchangeable.
function wrapperToUnderlying(uint256 amount) external view returns (uint256);
}

View File

@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
// Interface for MidasCapital. An open interest protocol based on
// modified Fuse contracts. Anyone can create an deploy isolated
// lending and borrowing pools with custom parameters.
import "../solidity-utils/openzeppelin/IERC20.sol";
interface ICToken is IERC20 {
// Error codes referenced in this file can be found here:
// https://github.com/compound-finance/compound-protocol/blob/a3214f67b73310d547e00fc578e8355911c9d376/contracts/ErrorReporter.sol
// solhint-disable-previous-line max-line-length
/**
* @dev Underlying asset for this CToken
*/
function underlying() external view returns (address);
/**
* @notice Sender supplies assets into the market and receives cTokens in exchange
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param mintAmount The amount of the underlying asset to supply
* @return uint 0=success, otherwise an error code (see ErrorReporter.sol link above for details)
*/
function mint(uint256 mintAmount) external returns (uint256);
/**
* @notice Sender redeems cTokens in exchange for the underlying asset
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param redeemTokens The number of cTokens to redeem into underlying
* @return uint 0=success, otherwise an error code (see ErrorReporter.sol link above for details)
*/
function redeem(uint256 redeemTokens) external returns (uint256);
}

View File

@@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
interface IEulerToken is IERC20 {
/**
* @dev Convert an eToken balance to an underlying amount, taking into account current exchange rate
* @param balance eToken balance, in internal book-keeping units (18 decimals)
* @return Amount in underlying units, (same decimals as underlying token)
*/
// https://github.com/euler-xyz/euler-contracts/blob/b1ee3265853628d5a529081d7908c38404201b4e/contracts/modules/EToken.sol#L104
// solhint-disable-previous-line max-line-length
function convertBalanceToUnderlying(uint256 balance) external view returns (uint256);
/**
* @dev Convert an underlying amount to an eToken balance, taking into account current exchange rate
* @param underlyingAmount Amount in underlying units (same decimals as underlying token)
* @return eToken balance, in internal book-keeping units (18 decimals)
*/
// https://github.com/euler-xyz/euler-contracts/blob/b1ee3265853628d5a529081d7908c38404201b4e/contracts/modules/EToken.sol#L114
// solhint-disable-previous-line max-line-length
function convertUnderlyingToBalance(uint256 underlyingAmount) external view returns (uint256);
/**
* @dev Transfer underlying tokens from sender to the Euler pool, and increase account's eTokens
*/
function deposit(uint256 subAccountId, uint256 amount) external;
/**
* @dev Transfer underlying tokens from Euler pool to sender, and decrease account's eTokens
*/
function withdraw(uint256 subAccountId, uint256 amount) external;
/**
* @dev Address of underlying asset
*/
function underlyingAsset() external view returns (address);
}

View File

@@ -0,0 +1,62 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
interface IGearboxDieselToken is IERC20 {
/**
* @dev returns the address of the vault
*/
function owner() external view returns (address);
}
interface IGearboxVault {
/**
* @dev returns the address of the underlying asset
*/
function underlyingToken() external view returns (address);
/**
* @dev returns a 27 decimal fixed point 'ray' value so a rate of 1 is represented as 1e27
*/
// solhint-disable-next-line func-name-mixedcase
function getDieselRate_RAY() external view returns (uint256);
/**
* @dev converts diesel token amount to main token amount
*/
function fromDiesel(uint256) external view returns (uint256);
/**
* @dev converts main token amount to diesel token amount
*/
function toDiesel(uint256) external view returns (uint256);
/**
* @dev Adds liquidity to pool and sends diesel (LP) tokens back to the liquidity provider
* The Referral code can be 0
*/
function addLiquidity(
uint256 underlyingAmount,
address onBehalfOf,
uint256 referralCode
) external;
/**
* @dev Removes liquidity from the pool and sends the underlying tokens to the `to` address
*/
function removeLiquidity(uint256 dieselAmount, address to) external;
}

View File

@@ -0,0 +1,100 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
/**
* @dev Source of truth for all Protocol Fee percentages, that is, how much the protocol charges certain actions. Some
* of these values may also be retrievable from other places (such as the swap fee percentage), but this is the
* preferred source nonetheless.
*/
interface IProtocolFeePercentagesProvider {
// All fee percentages are 18-decimal fixed point numbers, so e.g. 1e18 = 100% and 1e16 = 1%.
// Emitted when a new fee type is registered.
event ProtocolFeeTypeRegistered(uint256 indexed feeType, string name, uint256 maximumPercentage);
// Emitted when the value of a fee type changes.
// IMPORTANT: it is possible for a third party to modify the SWAP and FLASH_LOAN fee type values directly in the
// ProtocolFeesCollector, which will result in this event not being emitted despite their value changing. Such usage
// of the ProtocolFeesCollector is however discouraged: all state-changing interactions with it should originate in
// this contract.
event ProtocolFeePercentageChanged(uint256 indexed feeType, uint256 percentage);
/**
* @dev Registers a new fee type in the system, making it queryable via `getFeeTypePercentage` and `getFeeTypeName`,
* as well as configurable via `setFeeTypePercentage`.
*
* `feeType` can be any arbitrary value (that is not in use).
*
* It is not possible to de-register fee types, nor change their name or maximum value.
*/
function registerFeeType(
uint256 feeType,
string memory name,
uint256 maximumValue,
uint256 initialValue
) external;
/**
* @dev Returns true if `feeType` has been registered and can be queried.
*/
function isValidFeeType(uint256 feeType) external view returns (bool);
/**
* @dev Returns true if `value` is a valid percentage value for `feeType`.
*/
function isValidFeeTypePercentage(uint256 feeType, uint256 value) external view returns (bool);
/**
* @dev Sets the percentage value for `feeType` to `newValue`.
*
* IMPORTANT: it is possible for a third party to modify the SWAP and FLASH_LOAN fee type values directly in the
* ProtocolFeesCollector, without invoking this function. This will result in the `ProtocolFeePercentageChanged`
* event not being emitted despite their value changing. Such usage of the ProtocolFeesCollector is however
* discouraged: only this contract should be granted permission to call `setSwapFeePercentage` and
* `setFlashLoanFeePercentage`.
*/
function setFeeTypePercentage(uint256 feeType, uint256 newValue) external;
/**
* @dev Returns the current percentage value for `feeType`. This is the preferred mechanism for querying these -
* whenever possible, use this fucntion instead of e.g. querying the ProtocolFeesCollector.
*/
function getFeeTypePercentage(uint256 feeType) external view returns (uint256);
/**
* @dev Returns `feeType`'s maximum value.
*/
function getFeeTypeMaximumPercentage(uint256 feeType) external view returns (uint256);
/**
* @dev Returns `feeType`'s name.
*/
function getFeeTypeName(uint256 feeType) external view returns (string memory);
}
library ProtocolFeeType {
// This list is not exhaustive - more fee types can be added to the system. It is expected for this list to be
// extended with new fee types as they are registered, to keep them all in one place and reduce
// likelihood of user error.
// solhint-disable private-vars-leading-underscore
uint256 internal constant SWAP = 0;
uint256 internal constant FLASH_LOAN = 1;
uint256 internal constant YIELD = 2;
uint256 internal constant AUM = 3;
// solhint-enable private-vars-leading-underscore
}

View File

@@ -0,0 +1,136 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../vault/IVault.sol";
import "./IProtocolFeesWithdrawer.sol";
/**
* @title ProtocolFeeSplitter
* @author Daoism Systems
* @notice Distributes protocol fees collected from a particular pool between a DAO fund recipient
* (e.g., the Balancer DAO treasury), and a beneficiary designated by the pool owner.
* @dev By default, all funds go to the DAO. To claim a share of the protocol fees, pool owners
* may call `setPoolBeneficiary`.
*/
interface IProtocolFeeSplitter {
event FeesCollected(
bytes32 indexed poolId,
address indexed beneficiary,
uint256 poolEarned,
address indexed daoFundsRecipient,
uint256 daoEarned
);
event PoolRevenueShareChanged(bytes32 indexed poolId, uint256 revenueSharePercentage);
event PoolRevenueShareCleared(bytes32 indexed poolId);
event PoolBeneficiaryChanged(bytes32 indexed poolId, address newBeneficiary);
event DefaultRevenueSharePercentageChanged(uint256 revenueSharePercentage);
event DAOFundsRecipientChanged(address newDaoFundsRecipient);
// Fund recipients
/**
* @notice Returns the DAO funds recipient that will receive any balance not due to the pool beneficiary.
*/
function getDaoFundsRecipient() external view returns (address);
/**
* @notice Allows a authorized user to change the DAO funds recipient.
* @dev This is a permissioned function.
* @param newDaoFundsRecipient - address of the new DAO funds recipient.
*/
function setDaoFundsRecipient(address newDaoFundsRecipient) external;
/**
* @notice Allows a pool owner to change the revenue share beneficiary for a given pool.
* @dev This is a permissioned function.
* @param poolId - the poolId of the pool where the beneficiary will change.
* @param newBeneficiary - address of the new beneficiary.
*/
function setPoolBeneficiary(bytes32 poolId, address newBeneficiary) external;
// Revenue share settings
/**
* @dev Returns the current protocol fee split configuration for a given pool.
* @param poolId - the poolId of a pool with accrued protocol fees.
* @return revenueSharePercentageOverride - the percentage of the split sent to the pool beneficiary.
* @return beneficiary - the address of the pool beneficiary.
*/
function getRevenueShareSettings(bytes32 poolId)
external
view
returns (
uint256 revenueSharePercentageOverride,
address beneficiary,
bool overrideSet
);
/**
* @dev Returns the default revenue share percentage a pool will receive, unless overridden by a call
* to `setRevenueSharePercentage`.
*/
function getDefaultRevenueSharePercentage() external view returns (uint256);
/**
* @notice Allows an authorized user to change the default revenue share percentage.
* @dev Set the default revenue share percentage, applied to pools where no override has been set
* through `setRevenueSharePercentage`. Must be below the maximum allowed split.
* This is a permissioned function.
* @param defaultRevenueSharePercentage - new default revenue share percentage
*/
function setDefaultRevenueSharePercentage(uint256 defaultRevenueSharePercentage) external;
/**
* @notice Allows an authorized user to change the revenueShare for a given pool.
* @dev This is a permissioned function.
* @param poolId - the poolId of the pool where the revenue share will change.
* @param revenueSharePercentage - the new revenue share percentage.
*/
function setRevenueSharePercentage(bytes32 poolId, uint256 revenueSharePercentage) external;
/**
* @notice Allows an authorized user to change the revenueShare for a given pool.
* @dev This is a permissioned function.
* @param poolId - the poolId of the pool where the revenue share will change.
*/
function clearRevenueSharePercentage(bytes32 poolId) external;
// Permissionless fee collection functions
/**
* @dev Returns the amount of fees that would be sent to each beneficiary in a call to `collectFees`.
* @param poolId - the poolId of a pool with accrued protocol fees.
* @return beneficiaryAmount - the BPT amount that would be sent to the pool beneficiary.
* @return daoAmount - the BPT amount that would be sent to the DAO funds recipient.
*/
function getAmounts(bytes32 poolId) external view returns (uint256 beneficiaryAmount, uint256 daoAmount);
/**
* @dev Permissionless function to collect and distribute any accrued protocol fees for the given pool.
* @param poolId - the poolId of a pool with accrued protocol fees.
* @return beneficiaryAmount - the BPT amount sent to the pool beneficiary.
* @return daoAmount - the BPT amount sent to the DAO funds recipient.
*/
function collectFees(bytes32 poolId) external returns (uint256 beneficiaryAmount, uint256 daoAmount);
// Misc getters
/**
* @notice Returns the `ProtocolFeesWithdrawer`, used to withdraw funds from the `ProtocolFeesCollector`.
*/
function getProtocolFeesWithdrawer() external view returns (IProtocolFeesWithdrawer);
}

View File

@@ -0,0 +1,78 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../vault/IProtocolFeesCollector.sol";
/**
* @author Balancer Labs
* @title Protocol Fees Withdrawer
* @notice Safety layer around the Protocol Fees Collector which allows withdrawals of specific tokens to be blocked.
* This is useful for the case in where tokens that shouldn't be distributed are unexpectedly paid into the Protocol
* Fees Collector.
*/
interface IProtocolFeesWithdrawer {
event TokenAllowlisted(IERC20 token);
event TokenDenylisted(IERC20 token);
/**
* @notice Returns the address of the Protocol Fee Collector.
*/
function getProtocolFeesCollector() external view returns (IProtocolFeesCollector);
/**
* @notice Returns whether the provided token may be withdrawn from the Protocol Fee Collector
*/
function isWithdrawableToken(IERC20 token) external view returns (bool);
/**
* @notice Returns whether the provided array of tokens may be withdrawn from the Protocol Fee Collector
* @dev Returns false if any token is denylisted.
*/
function isWithdrawableTokens(IERC20[] calldata tokens) external view returns (bool);
/**
* @notice Returns the denylisted token at the given `index`.
*/
function getDenylistedToken(uint256 index) external view returns (IERC20);
/**
* @notice Returns the number of denylisted tokens.
*/
function getDenylistedTokensLength() external view returns (uint256);
/**
* @notice Withdraws fees from the Protocol Fee Collector.
* @dev Reverts if attempting to withdraw a denylisted token.
* @param tokens - an array of token addresses to withdraw.
* @param amounts - an array of the amounts of each token to withdraw.
* @param recipient - the address to which to send the withdrawn tokens.
*/
function withdrawCollectedFees(
IERC20[] calldata tokens,
uint256[] calldata amounts,
address recipient
) external;
/**
* @notice Marks the provided token as ineligible for withdrawal from the Protocol Fee Collector
*/
function denylistToken(IERC20 token) external;
/**
* @notice Marks the provided token as eligible for withdrawal from the Protocol Fee Collector
*/
function allowlistToken(IERC20 token) external;
}

View File

@@ -0,0 +1,74 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev Registry of protocol IDs for external integrations with Balancer. The IDs chosen are arbitrary and do not affect
* behavior of any Balancer contracts. They are used only to tag specific contracts (usually pools) at the data layer.
*/
interface IProtocolIdRegistry {
// Emitted when a new protocol ID is registered.
event ProtocolIdRegistered(uint256 indexed protocolId, string name);
// Emitted when a protocol IDs name has been updated.
event ProtocolIdRenamed(uint256 indexed protocolId, string name);
/**
* @dev Registers an ID (and name) to differentiate among protocols. Protocol IDs cannot be deregistered.
*/
function registerProtocolId(uint256 protocolId, string memory name) external;
/**
* @dev Changes the name of an existing protocol ID. Should only be used to update in the case of mistakes.
*/
function renameProtocolId(uint256 protocolId, string memory newName) external;
/**
* @dev Returns true if `protocolId` has been registered and can be queried.
*/
function isValidProtocolId(uint256 protocolId) external view returns (bool);
/**
* @dev Returns the name associated with a given `protocolId`.
*/
function getProtocolName(uint256 protocolId) external view returns (string memory);
}
library ProtocolId {
// This list is not exhaustive - more protocol IDs can be added to the system. It is expected for this list to be
// extended with new protocol IDs as they are registered, to keep them all in one place and reduce
// likelihood of user error.
// solhint-disable private-vars-leading-underscore
uint256 internal constant AAVE_V1 = 0;
uint256 internal constant AAVE_V2 = 1;
uint256 internal constant AAVE_V3 = 2;
uint256 internal constant AMPLEFORTH = 3;
uint256 internal constant BEEFY = 4;
uint256 internal constant EULER = 5;
uint256 internal constant GEARBOX = 6;
uint256 internal constant IDLE = 7;
uint256 internal constant MORPHO = 8;
uint256 internal constant RADIANT = 9;
uint256 internal constant REAPER = 10;
uint256 internal constant SILO = 11;
uint256 internal constant STARGATE = 12;
uint256 internal constant STURDY = 13;
uint256 internal constant TESSERA = 14;
uint256 internal constant TETU = 15;
uint256 internal constant YEARN = 16;
uint256 internal constant MIDAS = 17;
uint256 internal constant AGAVE = 18;
// solhint-enable private-vars-leading-underscore
}

View File

@@ -0,0 +1,54 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
// Source: https://github.com/Byte-Masons/beet-strat/blob/master/contracts/ReaperVaultv1_4.sol
// Interface definition for the ReaperTokenVault contract, a single strategy vault
// for Reaper Farm crypts. The pricePerFullShare is always represented with 18 decimals,
// regardless of the underlying token decimals.
// ie: If ppfs === 1e18, 1 USDC === 0.000_000_000_001_000_000 rfUSDC
// ie: If ppfs === 1e18, 1 DAI === 1 rfDAI
interface IReaperTokenVault is IERC20 {
/**
* @dev returns the address of the vault's underlying asset (mainToken)
*/
function token() external view returns (address);
/**
* @dev returns the price for a single Vault share (ie rf-scfUSDT). The getPricePerFullShare is always in 1e18
*/
function getPricePerFullShare() external view returns (uint256);
/**
* @notice Deposits `_amount` `token`, issuing shares to the caller.
* If Panic is activated, deposits will not be accepted and this call will fail.
* @param _amount The quantity of tokens to deposit.
**/
function deposit(uint256 _amount) external;
/**
* @notice Withdraws the calling account's tokens from this Vault,
* redeeming amount `_shares` for an appropriate amount of tokens.
**/
function withdraw(uint256 _shares) external;
/**
* @dev returns the number of decimals for this vault token.
* For reaper single-strat vaults, the decimals are fixed to 18.
*/
function decimals() external view returns (uint8);
}

View File

@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
import "./ISilo.sol";
interface IShareToken is IERC20 {
/**
* @dev returns the underlying asset
*/
function asset() external view returns (address);
/**
* @dev returns the address of the silo
*/
function silo() external view returns (ISilo);
}

View File

@@ -0,0 +1,76 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "./IShareToken.sol";
interface IBaseSilo {
/// Storage struct that holds all required data for a single token market
struct AssetStorage {
// Token that represents a share in totalDeposits of Silo
IShareToken collateralToken;
// Token that represents a share in collateralOnlyDeposits of Silo
IShareToken collateralOnlyToken;
// Token that represents a share in totalBorrowAmount of Silo
IShareToken debtToken;
// COLLATERAL: Amount of asset token that has been deposited to Silo with interest earned by depositors.
// It also includes token amount that has been borrowed.
uint256 totalDeposits;
// COLLATERAL ONLY: Amount of asset token that has been deposited to Silo that can ONLY be used
// as collateral. These deposits do NOT earn interest and CANNOT be borrowed.
uint256 collateralOnlyDeposits;
// DEBT: Amount of asset token that has been borrowed with accrued interest.
uint256 totalBorrowAmount;
}
/**
* @dev returns the asset storage struct
* @dev AssetStorage struct contains necessary information for calculating shareToken exchange rates
*/
function assetStorage(address _asset) external view returns (AssetStorage memory);
}
interface ISilo is IBaseSilo {
/**
* @dev Deposits funds into the Silo
* @param _asset The address of the token to deposit
* @param _depositor The address of the recipient of collateral tokens
* @param _amount The amount of the token to deposit
* @param _collateralOnly: True means your shareToken is protected (cannot be swapped for interest)
* @return collateralAmount deposited amount
* @return collateralShare user collateral shares based on deposited amount
*/
function depositFor(
address _asset,
address _depositor,
uint256 _amount,
bool _collateralOnly
) external returns (uint256 collateralAmount, uint256 collateralShare);
/**
* @dev Withdraw `_amount` of `_asset` tokens from the Silo to `msg.sender`
* @param _asset The address of the token to withdraw
* @param _amount The amount of the token to withdraw
* @param _collateralOnly True if withdrawing collateral only deposit
* @return withdrawnAmount withdrawn amount that was transferred to user
* @return withdrawnShare burned share based on `withdrawnAmount`
*/
function withdraw(
address _asset,
uint256 _amount,
bool _collateralOnly
) external returns (uint256 withdrawnAmount, uint256 withdrawnShare);
}

View File

@@ -0,0 +1,247 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "../solidity-utils/openzeppelin/IERC20.sol";
// solhint-disable-next-line max-line-length
// Based on https://github.com/aave/protocol-v2/blob/ac58fea62bb8afee23f66197e8bce6d79ecda292/contracts/interfaces/IStaticATokenLM.sol
interface IStaticATokenLM is IERC20 {
struct SignatureParams {
uint8 v;
bytes32 r;
bytes32 s;
}
/**
* @notice Deposits `ASSET` in the Aave protocol and mints static aTokens to msg.sender
* @param recipient The address that will receive the static aTokens
* @param amount The amount of underlying `ASSET` to deposit (e.g. deposit of 100 USDC)
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param fromUnderlying bool
* - `true` if the msg.sender comes with underlying tokens (e.g. USDC)
* - `false` if the msg.sender comes already with aTokens (e.g. aUSDC)
* @return uint256 The amount of StaticAToken minted, static balance
**/
function deposit(
address recipient,
uint256 amount,
uint16 referralCode,
bool fromUnderlying
) external returns (uint256);
/**
* @notice Burns `amount` of static aToken, with recipient receiving the corresponding amount of `ASSET`
* @param recipient The address that will receive the amount of `ASSET` withdrawn from the Aave protocol
* @param amount The amount to withdraw, in static balance of StaticAToken
* @param toUnderlying bool
* - `true` for the recipient to get underlying tokens (e.g. USDC)
* - `false` for the recipient to get aTokens (e.g. aUSDC)
* @return amountToBurn: StaticATokens burnt, static balance
* @return amountToWithdraw: underlying/aToken send to `recipient`, dynamic balance
**/
function withdraw(
address recipient,
uint256 amount,
bool toUnderlying
) external returns (uint256, uint256);
/**
* @notice Burns `amount` of static aToken, with recipient receiving the corresponding amount of `ASSET`
* @param recipient The address that will receive the amount of `ASSET` withdrawn from the Aave protocol
* @param amount The amount to withdraw, in dynamic balance of aToken/underlying asset
* @param toUnderlying bool
* - `true` for the recipient to get underlying tokens (e.g. USDC)
* - `false` for the recipient to get aTokens (e.g. aUSDC)
* @return amountToBurn: StaticATokens burnt, static balance
* @return amountToWithdraw: underlying/aToken send to `recipient`, dynamic balance
**/
function withdrawDynamicAmount(
address recipient,
uint256 amount,
bool toUnderlying
) external returns (uint256, uint256);
/**
* @notice Implements the permit function as for
* https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
* @param owner The owner of the funds
* @param spender The spender
* @param value The amount
* @param deadline The deadline timestamp, type(uint256).max for max deadline
* @param v Signature param
* @param s Signature param
* @param r Signature param
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @notice Allows to deposit on Aave via meta-transaction
* https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
* @param depositor Address from which the funds to deposit are going to be pulled
* @param recipient Address that will receive the staticATokens, in the average case, same as the `depositor`
* @param value The amount to deposit
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param fromUnderlying bool
* - `true` if the msg.sender comes with underlying tokens (e.g. USDC)
* - `false` if the msg.sender comes already with aTokens (e.g. aUSDC)
* @param deadline The deadline timestamp, type(uint256).max for max deadline
* @param sigParams Signature params: v,r,s
* @return uint256 The amount of StaticAToken minted, static balance
*/
function metaDeposit(
address depositor,
address recipient,
uint256 value,
uint16 referralCode,
bool fromUnderlying,
uint256 deadline,
SignatureParams calldata sigParams
) external returns (uint256);
/**
* @notice Allows to withdraw from Aave via meta-transaction
* https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
* @param owner Address owning the staticATokens
* @param recipient Address that will receive the underlying withdrawn from Aave
* @param staticAmount The amount of staticAToken to withdraw. If > 0, `dynamicAmount` needs to be 0
* @param dynamicAmount The amount of underlying/aToken to withdraw. If > 0, `staticAmount` needs to be 0
* @param toUnderlying bool
* - `true` for the recipient to get underlying tokens (e.g. USDC)
* - `false` for the recipient to get aTokens (e.g. aUSDC)
* @param deadline The deadline timestamp, type(uint256).max for max deadline
* @param sigParams Signature params: v,r,s
* @return amountToBurn: StaticATokens burnt, static balance
* @return amountToWithdraw: underlying/aToken send to `recipient`, dynamic balance
*/
function metaWithdraw(
address owner,
address recipient,
uint256 staticAmount,
uint256 dynamicAmount,
bool toUnderlying,
uint256 deadline,
SignatureParams calldata sigParams
) external returns (uint256, uint256);
/**
* @notice Utility method to get the current aToken balance of an user, from his staticAToken balance
* @param account The address of the user
* @return uint256 The aToken balance
**/
function dynamicBalanceOf(address account) external view returns (uint256);
/**
* @notice Converts a static amount (scaled balance on aToken) to the aToken/underlying value,
* using the current liquidity index on Aave
* @param amount The amount to convert from
* @return uint256 The dynamic amount
**/
function staticToDynamicAmount(uint256 amount) external view returns (uint256);
/**
* @notice Converts an aToken or underlying amount to the what it is denominated on the aToken as
* scaled balance, function of the principal and the liquidity index
* @param amount The amount to convert from
* @return uint256 The static (scaled) amount
**/
function dynamicToStaticAmount(uint256 amount) external view returns (uint256);
/**
* @notice Returns the Aave liquidity index of the underlying aToken, denominated rate here
* as it can be considered as an ever-increasing exchange rate
* @return The liquidity index
**/
function rate() external view returns (uint256);
/**
* @notice Function to return a dynamic domain separator, in order to be compatible with forks changing chainId
* @return bytes32 The domain separator
**/
function getDomainSeparator() external view returns (bytes32);
/**
* @notice Claims rewards from `INCENTIVES_CONTROLLER` and updates internal accounting of rewards.
*/
function collectAndUpdateRewards() external;
/**
* @notice Claim rewards on behalf of a user and send them to a receiver
* @dev Only callable by if sender is onBehalfOf or sender is approved claimer
* @param onBehalfOf The address to claim on behalf of
* @param receiver The address to receive the rewards
* @param forceUpdate Flag to retrieve latest rewards from `INCENTIVES_CONTROLLER`
*/
function claimRewardsOnBehalf(
address onBehalfOf,
address receiver,
bool forceUpdate
) external;
/**
* @notice Claim rewards and send them to a receiver
* @param receiver The address to receive the rewards
* @param forceUpdate Flag to retrieve latest rewards from `INCENTIVES_CONTROLLER`
*/
function claimRewards(address receiver, bool forceUpdate) external;
/**
* @notice Claim rewards
* @param forceUpdate Flag to retrieve latest rewards from `INCENTIVES_CONTROLLER`
*/
function claimRewardsToSelf(bool forceUpdate) external;
/**
* @notice Get the total claimable rewards of the contract.
* @return The current balance + pending rewards from the `_incentivesController`
*/
function getTotalClaimableRewards() external view returns (uint256);
/**
* @notice Get the total claimable rewards for a user in WAD
* @param user The address of the user
* @return The claimable amount of rewards in WAD
*/
function getClaimableRewards(address user) external view returns (uint256);
/**
* @notice The unclaimed rewards for a user in WAD
* @param user The address of the user
* @return The unclaimed amount of rewards in WAD
*/
function getUnclaimedRewards(address user) external view returns (uint256);
function getAccRewardsPerToken() external view returns (uint256);
function getLifetimeRewardsClaimed() external view returns (uint256);
function getLifetimeRewards() external view returns (uint256);
function getLastRewardBlock() external view returns (uint256);
// solhint-disable-next-line func-name-mixedcase
function LENDING_POOL() external returns (address);
// solhint-disable-next-line func-name-mixedcase
function INCENTIVES_CONTROLLER() external returns (address);
// solhint-disable-next-line func-name-mixedcase
function ATOKEN() external returns (IERC20);
// solhint-disable-next-line func-name-mixedcase
function ASSET() external returns (IERC20);
// solhint-disable-next-line func-name-mixedcase
function REWARD_TOKEN() external returns (IERC20);
}

View File

@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
interface ITetuSmartVault is IERC20 {
function deposit(uint256 amount) external;
function depositFor(uint256 amount, address holder) external;
function underlyingBalanceInVault() external view returns (uint256);
function withdraw(uint256 numberOfShares) external;
function underlyingBalanceWithInvestmentForHolder(address holder) external view returns (uint256);
function underlying() external view returns (address);
function underlyingUnit() external view returns (uint256);
function getPricePerFullShare() external view returns (uint256);
function strategy() external view returns (address);
}

View File

@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
interface ITetuStrategy {
function investedUnderlyingBalance() external view returns (uint256);
}

View File

@@ -0,0 +1,25 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
import "./IButtonWrapper.sol";
// Balancer only supports ERC20 tokens, so we use this intermediate interface
// to enforce ERC20-ness of UnbuttonTokens.
interface IUnbuttonToken is IButtonWrapper, IERC20 {
// solhint-disable-previous-line no-empty-blocks
}

View File

@@ -0,0 +1,49 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
interface IYearnTokenVault is IERC20 {
/**
* @dev returns the address of the vault's underlying asset (mainToken)
*/
function token() external view returns (address);
/**
* @dev returns the price for a single Vault share (ie yvDAI). The pricePerShare is represented
* in the same decimals as the underlying asset (ie: 6 decimals for USDC)
*/
function pricePerShare() external view returns (uint256);
/**
* @notice Deposits `_amount` `token`, issuing shares to `recipient`.
* If the Vault is in Emergency Shutdown, deposits will not be accepted and this call will fail.
* @param _amount The quantity of tokens to deposit, defaults to all.
* @param recipient The address to issue the shares in this Vault to. Defaults to the caller's address.
* @return The issued Vault shares.
*/
function deposit(uint256 _amount, address recipient) external returns (uint256);
/**
* @notice Withdraws the calling account's tokens from this Vault,
* redeeming amount `_shares` for an appropriate amount of tokens.
* See note on `setWithdrawalQueue` for further details of withdrawal ordering and behavior.
* @param maxShares How many shares to try and redeem for tokens, defaults to all.
* @param recipient The address to issue the shares in this Vault to. Defaults to the caller's address.
* @return redeemed: The quantity of tokens redeemed for `_shares`.
*/
function withdraw(uint256 maxShares, address recipient) external returns (uint256);
}

View File

@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
// solhint-disable-next-line max-line-length
// Based on https://github.com/lidofinance/lido-dao/blob/816bf1d0995ba5cfdfc264de4acda34a7fe93eba/contracts/0.4.24/Lido.sol
interface IstETH is IERC20 {
function submit(address referral) external payable returns (uint256);
}

View File

@@ -0,0 +1,92 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
import "./IstETH.sol";
// solhint-disable-next-line max-line-length
// Based on https://github.com/lidofinance/lido-dao/blob/2b46615a11dee77d4d22066f942f6c6afab9b87a/contracts/0.6.12/WstETH.sol
/**
* @title StETH token wrapper with static balances.
* @dev It's an ERC20 token that represents the account's share of the total
* supply of stETH tokens. WstETH token's balance only changes on transfers,
* unlike StETH that is also changed when oracles report staking rewards and
* penalties. It's a "power user" token for DeFi protocols which don't
* support rebasable tokens.
*
* The contract is also a trustless wrapper that accepts stETH tokens and mints
* wstETH in return. Then the user unwraps, the contract burns user's wstETH
* and sends user locked stETH in return.
*
* The contract provides the staking shortcut: user can send ETH with regular
* transfer and get wstETH in return. The contract will send ETH to Lido submit
* method, staking it and wrapping the received stETH.
*
*/
interface IwstETH is IERC20 {
function stETH() external returns (IstETH);
/**
* @notice Exchanges stETH to wstETH
* @param _stETHAmount amount of stETH to wrap in exchange for wstETH
* @dev Requirements:
* - `_stETHAmount` must be non-zero
* - msg.sender must approve at least `_stETHAmount` stETH to this
* contract.
* - msg.sender must have at least `_stETHAmount` of stETH.
* User should first approve _stETHAmount to the WstETH contract
* @return Amount of wstETH user receives after wrap
*/
function wrap(uint256 _stETHAmount) external returns (uint256);
/**
* @notice Exchanges wstETH to stETH
* @param _wstETHAmount amount of wstETH to uwrap in exchange for stETH
* @dev Requirements:
* - `_wstETHAmount` must be non-zero
* - msg.sender must have at least `_wstETHAmount` wstETH.
* @return Amount of stETH user receives after unwrap
*/
function unwrap(uint256 _wstETHAmount) external returns (uint256);
/**
* @notice Get amount of wstETH for a given amount of stETH
* @param _stETHAmount amount of stETH
* @return Amount of wstETH for a given stETH amount
*/
function getWstETHByStETH(uint256 _stETHAmount) external view returns (uint256);
/**
* @notice Get amount of stETH for a given amount of wstETH
* @param _wstETHAmount amount of wstETH
* @return Amount of stETH for a given wstETH amount
*/
function getStETHByWstETH(uint256 _wstETHAmount) external view returns (uint256);
/**
* @notice Get amount of wstETH for a one stETH
* @return Amount of stETH for 1 wstETH
*/
function stEthPerToken() external view returns (uint256);
/**
* @notice Get amount of stETH for a one wstETH
* @return Amount of wstETH for a 1 stETH
*/
function tokensPerStEth() external view returns (uint256);
}