编译器
0.8.19+commit.7dd6d404
文件 1 的 17:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 17:AddressUpgradeable.sol
pragma solidity ^0.8.1;
library AddressUpgradeable {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 3 的 17:BalancerActionsLib.sol
pragma solidity ^0.8.0;
import "@openzeppelin-4/contracts/token/ERC20/IERC20.sol";
import "../../interfaces/beethovenx/IBalancerVault.sol";
import "./BeefyBalancerStructs.sol";
library BalancerActionsLib {
function balancerJoin(address _vault, bytes32 _poolId, address _tokenIn, uint256 _amountIn) internal {
(address[] memory lpTokens,,) = IBalancerVault(_vault).getPoolTokens(_poolId);
uint256[] memory amounts = new uint256[](lpTokens.length);
for (uint256 i = 0; i < amounts.length;) {
amounts[i] = lpTokens[i] == _tokenIn ? _amountIn : 0;
unchecked { ++i; }
}
bytes memory userData = abi.encode(1, amounts, 1);
IBalancerVault.JoinPoolRequest memory request = IBalancerVault.JoinPoolRequest(lpTokens, amounts, userData, false);
IBalancerVault(_vault).joinPool(_poolId, address(this), address(this), request);
}
function multiJoin(address _vault, address _want, bytes32 _poolId, address _token0In, address _token1In, uint256 _amount0In, uint256 _amount1In) internal {
(address[] memory lpTokens,uint256[] memory balances,) = IBalancerVault(_vault).getPoolTokens(_poolId);
uint256 supply = IERC20(_want).totalSupply();
uint256[] memory amounts = new uint256[](lpTokens.length);
for (uint256 i = 0; i < amounts.length;) {
if (lpTokens[i] == _token0In) amounts[i] = _amount0In;
else if (lpTokens[i] == _token1In) amounts[i] = _amount1In;
else amounts[i] = 0;
unchecked { ++i; }
}
uint256 bpt0 = (amounts[0] * supply / balances[0]) - 100;
uint256 bpt1 = (amounts[1] * supply / balances[1]) - 100;
uint256 bptOut = bpt0 > bpt1 ? bpt1 : bpt0;
bytes memory userData = abi.encode(3, bptOut);
IBalancerVault.JoinPoolRequest memory request = IBalancerVault.JoinPoolRequest(lpTokens, amounts, userData, false);
IBalancerVault(_vault).joinPool(_poolId, address(this), address(this), request);
}
function buildSwapStructArray(BeefyBalancerStructs.BatchSwapStruct[] memory _route, uint256 _amountIn) internal pure returns (IBalancerVault.BatchSwapStep[] memory) {
IBalancerVault.BatchSwapStep[] memory swaps = new IBalancerVault.BatchSwapStep[](_route.length);
for (uint i; i < _route.length;) {
if (i == 0) {
swaps[0] =
IBalancerVault.BatchSwapStep({
poolId: _route[0].poolId,
assetInIndex: _route[0].assetInIndex,
assetOutIndex: _route[0].assetOutIndex,
amount: _amountIn,
userData: ""
});
} else {
swaps[i] =
IBalancerVault.BatchSwapStep({
poolId: _route[i].poolId,
assetInIndex: _route[i].assetInIndex,
assetOutIndex: _route[i].assetOutIndex,
amount: 0,
userData: ""
});
}
unchecked {
++i;
}
}
return swaps;
}
function balancerSwap(address _vault, IBalancerVault.SwapKind _swapKind, IBalancerVault.BatchSwapStep[] memory _swaps, address[] memory _route, IBalancerVault.FundManagement memory _funds, int256 _amountIn) internal returns (int256[] memory) {
int256[] memory limits = new int256[](_route.length);
for (uint i; i < _route.length;) {
if (i == 0) {
limits[0] = _amountIn;
} else if (i == _route.length - 1) {
limits[i] = -1;
}
unchecked { ++i; }
}
return IBalancerVault(_vault).batchSwap(_swapKind, _swaps, _route, _funds, limits, block.timestamp);
}
}
文件 4 的 17:BeefyBalancerStructs.sol
pragma solidity ^0.8.0;
import "../../interfaces/common/ITraderJoeRouter.sol";
library BeefyBalancerStructs {
enum RouterType {
BALANCER,
UNISWAP_V2,
UNISWAP_V3,
TRADER_JOE
}
struct BatchSwapStruct {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
}
struct Reward {
RouterType routerType;
address router;
mapping(uint => BatchSwapStruct) swapInfo;
address[] assets;
bytes routeToNative;
ITraderJoeRouter.Path joePath;
uint minAmount;
}
struct Input {
address input;
bool isComposable;
bool isBeets;
}
}
文件 5 的 17:ContextUpgradeable.sol
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
uint256[50] private __gap;
}
文件 6 的 17:IBalancerVault.sol
pragma solidity >=0.6.0 <0.9.0;
pragma experimental ABIEncoderV2;
interface IBalancerVault {
struct SingleSwap {
bytes32 poolId;
SwapKind kind;
address assetIn;
address assetOut;
uint256 amount;
bytes userData;
}
struct BatchSwapStep {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
uint256 amount;
bytes userData;
}
struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}
struct JoinPoolRequest {
address[] assets;
uint256[] maxAmountsIn;
bytes userData;
bool fromInternalBalance;
}
enum SwapKind { GIVEN_IN, GIVEN_OUT }
function swap(
SingleSwap memory singleSwap,
FundManagement memory funds,
uint256 limit,
uint256 deadline
) external payable returns (uint256);
function batchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
address[] memory assets,
FundManagement memory funds,
int256[] memory limits,
uint256 deadline
) external returns (int256[] memory assetDeltas);
function joinPool(
bytes32 poolId,
address sender,
address recipient,
JoinPoolRequest memory request
) external;
function getPoolTokens(bytes32 poolId)
external
view
returns (
address[] memory tokens,
uint256[] memory balances,
uint256 lastChangeBlock
);
function getPool(bytes32 poolId)
external
view
returns (address, uint8);
function flashLoan(
address recipient,
address[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external;
}
文件 7 的 17:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 8 的 17:IFeeConfig.sol
pragma solidity ^0.8.0;
interface IFeeConfig {
struct FeeCategory {
uint256 total;
uint256 beefy;
uint256 call;
uint256 strategist;
string label;
bool active;
}
struct AllFees {
FeeCategory performance;
uint256 deposit;
uint256 withdraw;
}
function getFees(address strategy) external view returns (FeeCategory memory);
function stratFeeId(address strategy) external view returns (uint256);
function setStratFeeId(uint256 feeId) external;
}
文件 9 的 17:ITraderJoeRouter.sol
pragma solidity >=0.6.0 <0.9.0;
interface ITraderJoeRouter {
enum Version {
V1,
V2,
V2_1
}
struct Path {
uint256[] pairBinSteps;
Version[] versions;
address[] tokenPath;
}
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
Path memory path,
address to,
uint256 deadline
) external returns (uint256 amountOut);
}
文件 10 的 17:IWrappedNative.sol
pragma solidity >=0.6.0 <0.9.0;
interface IWrappedNative {
function deposit() external payable;
function withdraw(uint256 wad) external;
}
文件 11 的 17:Initializable.sol
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
abstract contract Initializable {
uint8 private _initialized;
bool private _initializing;
event Initialized(uint8 version);
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
文件 12 的 17:OwnableUpgradeable.sol
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
uint256[49] private __gap;
}
文件 13 的 17:PausableUpgradeable.sol
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
function __Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = false;
}
modifier whenNotPaused() {
_requireNotPaused();
_;
}
modifier whenPaused() {
_requirePaused();
_;
}
function paused() public view virtual returns (bool) {
return _paused;
}
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
uint256[49] private __gap;
}
文件 14 的 17:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(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));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 15 的 17:StratFeeManagerInitializable.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "../../interfaces/common/IFeeConfig.sol";
contract StratFeeManagerInitializable is OwnableUpgradeable, PausableUpgradeable {
struct CommonAddresses {
address vault;
address unirouter;
address keeper;
address strategist;
address beefyFeeRecipient;
address beefyFeeConfig;
}
address public vault;
address public unirouter;
address public keeper;
address public strategist;
address public beefyFeeRecipient;
IFeeConfig public beefyFeeConfig;
uint256 constant DIVISOR = 1 ether;
uint256 constant public WITHDRAWAL_FEE_CAP = 50;
uint256 constant public WITHDRAWAL_MAX = 10000;
uint256 internal withdrawalFee;
event SetStratFeeId(uint256 feeId);
event SetWithdrawalFee(uint256 withdrawalFee);
event SetVault(address vault);
event SetUnirouter(address unirouter);
event SetKeeper(address keeper);
event SetStrategist(address strategist);
event SetBeefyFeeRecipient(address beefyFeeRecipient);
event SetBeefyFeeConfig(address beefyFeeConfig);
function __StratFeeManager_init(CommonAddresses calldata _commonAddresses) internal onlyInitializing {
__Ownable_init();
__Pausable_init();
vault = _commonAddresses.vault;
unirouter = _commonAddresses.unirouter;
keeper = _commonAddresses.keeper;
strategist = _commonAddresses.strategist;
beefyFeeRecipient = _commonAddresses.beefyFeeRecipient;
beefyFeeConfig = IFeeConfig(_commonAddresses.beefyFeeConfig);
withdrawalFee = 10;
}
modifier onlyManager() {
_checkManager();
_;
}
function _checkManager() internal view {
require(msg.sender == owner() || msg.sender == keeper, "!manager");
}
function getFees() internal view returns (IFeeConfig.FeeCategory memory) {
return beefyFeeConfig.getFees(address(this));
}
function getAllFees() external view returns (IFeeConfig.AllFees memory) {
return IFeeConfig.AllFees(getFees(), depositFee(), withdrawFee());
}
function getStratFeeId() external view returns (uint256) {
return beefyFeeConfig.stratFeeId(address(this));
}
function setStratFeeId(uint256 _feeId) external onlyManager {
beefyFeeConfig.setStratFeeId(_feeId);
emit SetStratFeeId(_feeId);
}
function setWithdrawalFee(uint256 _fee) public onlyManager {
require(_fee <= WITHDRAWAL_FEE_CAP, "!cap");
withdrawalFee = _fee;
emit SetWithdrawalFee(_fee);
}
function setVault(address _vault) external onlyOwner {
vault = _vault;
emit SetVault(_vault);
}
function setUnirouter(address _unirouter) external onlyOwner {
unirouter = _unirouter;
emit SetUnirouter(_unirouter);
}
function setKeeper(address _keeper) external onlyManager {
keeper = _keeper;
emit SetKeeper(_keeper);
}
function setStrategist(address _strategist) external {
require(msg.sender == strategist, "!strategist");
strategist = _strategist;
emit SetStrategist(_strategist);
}
function setBeefyFeeRecipient(address _beefyFeeRecipient) external onlyOwner {
beefyFeeRecipient = _beefyFeeRecipient;
emit SetBeefyFeeRecipient(_beefyFeeRecipient);
}
function setBeefyFeeConfig(address _beefyFeeConfig) external onlyOwner {
beefyFeeConfig = IFeeConfig(_beefyFeeConfig);
emit SetBeefyFeeConfig(_beefyFeeConfig);
}
function depositFee() public virtual view returns (uint256) {
return 0;
}
function withdrawFee() public virtual view returns (uint256) {
return paused() ? 0 : withdrawalFee;
}
function beforeDeposit() external virtual {}
}
文件 16 的 17:StrategySilo.sol
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin-4/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin-4/contracts/token/ERC20/utils/SafeERC20.sol";
import {IBalancerVault} from "../../interfaces/beethovenx/IBalancerVault.sol";
import {IWrappedNative} from "../../interfaces/common/IWrappedNative.sol";
import {BalancerActionsLib} from "../Balancer/BalancerActionsLib.sol";
import {BeefyBalancerStructs} from "../Balancer/BeefyBalancerStructs.sol";
import "../Common/StratFeeManagerInitializable.sol";
interface ISilo {
function deposit(address asset, uint amount, bool collateralOnly) external;
function withdraw(address asset, uint amount, bool collateralOnly) external;
function balanceOf(address user) external view returns (uint256);
function accrueInterest(address asset) external;
}
interface ISiloCollateralToken {
function asset() external view returns (address);
}
interface ISiloLens {
function balanceOfUnderlying(uint256 _assetTotalDeposits, address _shareToken, address _user) external view returns (uint256);
function totalDepositsWithInterest(address _silo, address _asset) external view returns (uint256 _totalDeposits);
function totalDeposits(address _silo, address _asset) external view returns (uint256 _totalDeposits);
function getDepositAmount(address _silo, address _asset, address _user, uint256 _timestamp) external view returns (uint256 _totalDeposits);
}
interface ISiloRewards {
function claimRewardsToSelf(address[] memory assets, uint256 amount) external;
}
contract StrategySilo is StratFeeManagerInitializable {
using SafeERC20 for IERC20;
address public constant native = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address public constant output = 0x6f80310CA7F2C654691D1383149Fa1A57d8AB1f8;
address public want;
address public silo;
address public collateralToken;
address[] public rewardsClaim;
ISiloRewards public constant rewards = ISiloRewards(0x6c1603aB6CecF89DD60C24530DdE23F97DA3C229);
ISiloLens public constant siloLens = ISiloLens(0x0e466FC22386997daC23D1f89A43ecb2CB1e76E9);
IBalancerVault.SwapKind public swapKind = IBalancerVault.SwapKind.GIVEN_IN;
IBalancerVault.FundManagement public funds;
BeefyBalancerStructs.BatchSwapStruct[] public outputToNativeRoute;
address[] public outputToNativeAssets;
bool public harvestOnDeposit;
uint256 public lastHarvest;
uint256 public totalLocked;
uint256 public constant DURATION = 1 days;
event StratHarvest(address indexed harvester, uint256 wantHarvested, uint256 tvl);
event Deposit(uint256 tvl);
event Withdraw(uint256 tvl);
event ChargedFees(uint256 callFees, uint256 beefyFees, uint256 strategistFees);
function initialize(
address _collateralToken,
address _silo,
CommonAddresses calldata _commonAddresses
) public initializer {
__StratFeeManager_init(_commonAddresses);
collateralToken = _collateralToken;
silo = _silo;
want = ISiloCollateralToken(collateralToken).asset();
funds = IBalancerVault.FundManagement(address(this), false, payable(address(this)), false);
outputToNativeAssets.push(output);
outputToNativeAssets.push(native);
outputToNativeRoute.push(BeefyBalancerStructs.BatchSwapStruct({
poolId: 0x9cc64ee4cb672bc04c54b00a37e1ed75b2cc19dd0002000000000000000004c1,
assetInIndex: 0,
assetOutIndex: 1
}));
rewardsClaim.push(collateralToken);
_giveAllowances();
}
function deposit() public whenNotPaused {
uint256 bal = balanceOfWant();
if (bal > 0) {
ISilo(silo).deposit(want, bal, false);
emit Deposit(balanceOf());
}
}
function withdraw(uint256 _amount) external {
require(msg.sender == vault, "!vault");
uint256 wantBal = balanceOfWant();
if (wantBal < _amount) {
uint256 toWithdraw = _amount - wantBal;
ISilo(silo).withdraw(want, toWithdraw, false);
wantBal = balanceOfWant();
}
if (wantBal > _amount) {
wantBal = _amount;
}
if (tx.origin != owner() && !paused()) {
uint256 withdrawalFeeAmount = _amount * withdrawalFee / WITHDRAWAL_MAX;
_amount = _amount - withdrawalFeeAmount;
}
IERC20(want).safeTransfer(vault, _amount);
emit Withdraw(balanceOf());
}
function beforeDeposit() external virtual override {
if (harvestOnDeposit) {
require(msg.sender == vault, "!vault");
_harvest(tx.origin);
}
}
function harvest() external virtual {
_harvest(tx.origin);
}
function harvest(address callFeeRecipient) external virtual {
_harvest(callFeeRecipient);
}
function _harvest(address callFeeRecipient) internal whenNotPaused {
rewards.claimRewardsToSelf(rewardsClaim, type(uint).max);
uint256 bal = IERC20(output).balanceOf(address(this));
if (bal > 0) {
chargeFees(callFeeRecipient);
uint256 wantHarvested = balanceOfWant();
totalLocked = wantHarvested + lockedProfit();
deposit();
lastHarvest = block.timestamp;
emit StratHarvest(msg.sender, wantHarvested, balanceOf());
}
}
function chargeFees(address callFeeRecipient) internal {
IFeeConfig.FeeCategory memory fees = getFees();
uint256 outputBal = IERC20(output).balanceOf(address(this));
if (outputBal > 0) {
IBalancerVault.BatchSwapStep[] memory _swaps = BalancerActionsLib.buildSwapStructArray(outputToNativeRoute, outputBal);
BalancerActionsLib.balancerSwap(unirouter, swapKind, _swaps, outputToNativeAssets, funds, int256(outputBal));
}
uint256 nativeBal = IERC20(native).balanceOf(address(this)) * fees.total / DIVISOR;
uint256 callFeeAmount = nativeBal * fees.call / DIVISOR;
IERC20(native).safeTransfer(callFeeRecipient, callFeeAmount);
uint256 beefyFeeAmount = nativeBal * fees.beefy / DIVISOR;
IERC20(native).safeTransfer(beefyFeeRecipient, beefyFeeAmount);
uint256 strategistFeeAmount = nativeBal * fees.strategist / DIVISOR;
IERC20(native).safeTransfer(strategist, strategistFeeAmount);
emit ChargedFees(callFeeAmount, beefyFeeAmount, strategistFeeAmount);
}
function lockedProfit() public view returns (uint256) {
uint256 elapsed = block.timestamp - lastHarvest;
uint256 remaining = elapsed < DURATION ? DURATION - elapsed : 0;
return totalLocked * remaining / DURATION;
}
function balanceOf() public view returns (uint256) {
return (balanceOfWant() + balanceOfPool()) - lockedProfit();
}
function balanceOfWant() public view returns (uint256) {
return IERC20(want).balanceOf(address(this));
}
function balanceOfPool() public view returns (uint256) {
return siloLens.getDepositAmount(silo, want, address(this), block.timestamp);
}
function rewardsAvailable() public pure returns (uint256) {
return 0;
}
function callReward() public pure returns (uint256) {
return 0;
}
function setHarvestOnDeposit(bool _harvestOnDeposit) external onlyManager {
harvestOnDeposit = _harvestOnDeposit;
if (harvestOnDeposit) {
setWithdrawalFee(0);
} else {
setWithdrawalFee(10);
}
}
function retireStrat() external {
require(msg.sender == vault, "!vault");
uint256 amount = balanceOfPool();
if (amount > 0) ISilo(silo).withdraw(want, balanceOfPool(), false);
uint256 wantBal = IERC20(want).balanceOf(address(this));
IERC20(want).transfer(vault, wantBal);
}
function panic() public onlyManager {
pause();
uint256 amount = balanceOfPool();
if (amount > 0) ISilo(silo).withdraw(want, balanceOfPool(), false);
}
function pause() public onlyManager {
_pause();
_removeAllowances();
}
function unpause() external onlyManager {
_unpause();
_giveAllowances();
deposit();
}
function _giveAllowances() internal {
IERC20(output).approve(unirouter, type(uint).max);
IERC20(want).approve(silo, type(uint).max);
}
function _removeAllowances() internal {
IERC20(output).approve(unirouter, 0);
IERC20(want).approve(silo, 0);
}
}
文件 17 的 17:draft-IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
{
"compilationTarget": {
"contracts/BIFI/strategies/Silo/StrategySilo.sol": "StrategySilo"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"callFees","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"beefyFees","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"strategistFees","type":"uint256"}],"name":"ChargedFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tvl","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"beefyFeeConfig","type":"address"}],"name":"SetBeefyFeeConfig","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"beefyFeeRecipient","type":"address"}],"name":"SetBeefyFeeRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"keeper","type":"address"}],"name":"SetKeeper","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feeId","type":"uint256"}],"name":"SetStratFeeId","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"strategist","type":"address"}],"name":"SetStrategist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"unirouter","type":"address"}],"name":"SetUnirouter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"vault","type":"address"}],"name":"SetVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"withdrawalFee","type":"uint256"}],"name":"SetWithdrawalFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"harvester","type":"address"},{"indexed":false,"internalType":"uint256","name":"wantHarvested","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tvl","type":"uint256"}],"name":"StratHarvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tvl","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WITHDRAWAL_FEE_CAP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WITHDRAWAL_MAX","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceOfPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceOfWant","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"beefyFeeConfig","outputs":[{"internalType":"contract IFeeConfig","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"beefyFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"beforeDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"callReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"collateralToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"funds","outputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"bool","name":"fromInternalBalance","type":"bool"},{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"bool","name":"toInternalBalance","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllFees","outputs":[{"components":[{"components":[{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"beefy","type":"uint256"},{"internalType":"uint256","name":"call","type":"uint256"},{"internalType":"uint256","name":"strategist","type":"uint256"},{"internalType":"string","name":"label","type":"string"},{"internalType":"bool","name":"active","type":"bool"}],"internalType":"struct IFeeConfig.FeeCategory","name":"performance","type":"tuple"},{"internalType":"uint256","name":"deposit","type":"uint256"},{"internalType":"uint256","name":"withdraw","type":"uint256"}],"internalType":"struct IFeeConfig.AllFees","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStratFeeId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"callFeeRecipient","type":"address"}],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"harvestOnDeposit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_collateralToken","type":"address"},{"internalType":"address","name":"_silo","type":"address"},{"components":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"unirouter","type":"address"},{"internalType":"address","name":"keeper","type":"address"},{"internalType":"address","name":"strategist","type":"address"},{"internalType":"address","name":"beefyFeeRecipient","type":"address"},{"internalType":"address","name":"beefyFeeConfig","type":"address"}],"internalType":"struct StratFeeManagerInitializable.CommonAddresses","name":"_commonAddresses","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"keeper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastHarvest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockedProfit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"native","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"output","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"outputToNativeAssets","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"outputToNativeRoute","outputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"uint256","name":"assetInIndex","type":"uint256"},{"internalType":"uint256","name":"assetOutIndex","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"panic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"retireStrat","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewards","outputs":[{"internalType":"contract ISiloRewards","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardsAvailable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardsClaim","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_beefyFeeConfig","type":"address"}],"name":"setBeefyFeeConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_beefyFeeRecipient","type":"address"}],"name":"setBeefyFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_harvestOnDeposit","type":"bool"}],"name":"setHarvestOnDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_keeper","type":"address"}],"name":"setKeeper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feeId","type":"uint256"}],"name":"setStratFeeId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategist","type":"address"}],"name":"setStrategist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_unirouter","type":"address"}],"name":"setUnirouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"}],"name":"setVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setWithdrawalFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"silo","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"siloLens","outputs":[{"internalType":"contract ISiloLens","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strategist","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapKind","outputs":[{"internalType":"enum IBalancerVault.SwapKind","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLocked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unirouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"want","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]