Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xf8dF17a35c88AbB25e83C92f9D293B4368b9D52D
Balance 0 ETH
Nonce 1
Code Size 8123 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

8123 bytes
0x608060405234801561001057600080fd5b50600436106101cf5760003560e01c80637c4b8b2d11610104578063bb23fd8f116100a2578063d38bfff411610071578063d38bfff414610472578063dc7cc1ef14610485578063dfce5b5114610498578063f6ea6b6c146104ab57600080fd5b8063bb23fd8f14610430578063c586903314610443578063c8e9cb871461044c578063d28988341461045f57600080fd5b8063907a3aa3116100de578063907a3aa3146103ce57806392ab7cfb146103e15780639fb092df146103f4578063a365dfaf1461042857600080fd5b80637c4b8b2d1461037d5780638b3c9668146103a85780638cc086a3146103bb57600080fd5b80633c78e45d11610171578063503fa78d1161014b578063503fa78d1461032457806352f4387b1461034457806353776861146103575780635aa6e6751461036a57600080fd5b80633c78e45d146102bd57806347003cb7146102d85780634ff5363e146102eb57600080fd5b80631627cea8116101ad5780631627cea814610228578063244edd79146102695780632b3d1ab31461027c57806334a9e75c146102a557600080fd5b806301e7e910146101d457806306fdde03146101e957806310fcd40d14610207575b600080fd5b6101e76101e2366004611b6e565b6104be565b005b6101f16105b0565b6040516101fe9190611bf7565b60405180910390f35b61021a610215366004611c0a565b61063e565b6040516101fe929190611c27565b610251610236366004611c0a565b6004602052600090815260409020546001600160a01b031681565b6040516001600160a01b0390911681526020016101fe565b6101e7610277366004611c0a565b610949565b61025161028a366004611c0a565b6008602052600090815260409020546001600160a01b031681565b6102ad61099b565b60405190151581526020016101fe565b61025173a045d4daea28ba7bfe234c96eaa03dafae85a14781565b600254610251906001600160a01b031681565b6103166102f9366004611b6e565b600760209081526000928352604080842090915290825290205481565b6040519081526020016101fe565b610316610332366004611c0a565b60056020526000908152604090205481565b61021a610352366004611b6e565b6109af565b6101e7610365366004611c4a565b610c0a565b600054610251906001600160a01b031681565b61031661038b366004611b6e565b600960209081526000928352604080842090915290825290205481565b6101e76103b6366004611c8b565b610cf9565b61021a6103c9366004611b6e565b610d3c565b61021a6103dc366004611b6e565b610e0b565b6101e76103ef366004611ca4565b610eb6565b610251610402366004611b6e565b60066020908152600092835260408084209091529082529020546001600160a01b031681565b610316610fab565b61021a61043e366004611c0a565b61102f565b61031660035481565b61021a61045a366004611c0a565b6110d0565b6101e761046d366004611cef565b611143565b6101e7610480366004611c0a565b61122e565b6101e7610493366004611b6e565b6112cb565b6101e76104a6366004611c4a565b6113b4565b61021a6104b9366004611b6e565b6114a7565b816001600160a01b03166388a8d6026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105209190611d1b565b6001600160a01b0316336001600160a01b0316146105595760405162461bcd60e51b815260040161055090611d38565b60405180910390fd5b6001600160a01b0382811660008181526008602052604080822080546001600160a01b0319169486169485179055517fc94b665aa6cc9622a8f1b97e6df7f6aa7582fa4681ad73361bc2e18d8d09ef0d9190a35050565b600180546105bd90611d5d565b80601f01602080910402602001604051908101604052809291908181526020018280546105e990611d5d565b80156106365780601f1061060b57610100808354040283529160200191610636565b820191906000526020600020905b81548152906001019060200180831161061957829003601f168201915b505050505081565b600060606000839050806001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa158015610685573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106a99190611dac565b156106db5760006040518060400160405280600881526020016729b43aba3237bbb760c11b8152509250925050915091565b806001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015610719573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073d9190611dc7565b6000036107745760006040518060400160405280600b81526020016a5a65726f2041737365747360a81b8152509250925050915091565b6002546001600160a01b03168015610845576000610791866117a6565b90506000816000036107a5576003546107a7565b815b905080836001600160a01b0316639436dce46040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061080c9190611dc7565b111561084257600060405180604001604052806008815260200167426173652046656560c01b8152509550955050505050915091565b50505b816001600160a01b0316630952864e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610883573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108a79190611dc7565b826001600160a01b031663c3535b526040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109099190611dc7565b6109139042611de0565b6040805160048152602481019091526020810180516001600160e01b0316632606a10b60e01b1790529110969095509350505050565b61095161185a565b600280546001600160a01b0319166001600160a01b0383169081179091556040517f5e28c797cc357f8c2266424cc5576c1f6c95e5b0571af12daba8a4e193a605a290600090a250565b60006003546109a8610fab565b1115905090565b6002546000906060906001600160a01b03168015610a855760006109d2866117a6565b90506000816000036109e6576003546109e8565b815b905080836001600160a01b0316639436dce46040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4d9190611dc7565b1115610a8257600060405180604001604052806008815260200167426173652046656560c01b81525094509450505050610c03565b50505b6000610a9186866118a4565b90508015610b65576040516370a0823160e01b81526001600160a01b038781166004830152600091908716906370a0823190602401602060405180830381865afa158015610ae3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b079190611dc7565b905081811115610b63575050604080516001600160a01b0386166024808301919091528251808303909101815260449091019091526020810180516001600160e01b0316637e3fb8db60e11b179052600193509150610c039050565b505b60405163192c9ab760e11b81526001600160a01b038681166004830152871690633259356e90602401600060405180830381865afa925050508015610bcc57506040513d6000823e601f3d908101601f19168201604052610bc99190810190611e17565b60015b610bf65760006040518060600160405280602c8152602001611f5a602c9139935093505050610c03565b9094509250610c03915050565b9250929050565b604051634c9ba32160e11b815233600482015260209081906001600160a01b03861690639937464290602401602060405180830381865afa158015610c53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c779190611dc7565b16600003610c975760405162461bcd60e51b815260040161055090611d38565b6001600160a01b0384811660008181526007602090815260408083209488168084529482529182902086905590518581527f7c6fdbf84705197c811743e855521086c7b2c8c9047359f5251f53df0ad6e187910160405180910390a350505050565b610d0161185a565b60038190556040518181527ff156092b9588daf2caafe3e73c39677740f094b38b8a61d150fd0ffcae83b9a09060200160405180910390a150565b600060606000610d64856001600160a01b039081166000908152600860205260409020541690565b90506001600160a01b03811615610df557604051638cc086a360e01b81526001600160a01b0386811660048301528581166024830152821690638cc086a390604401600060405180830381865afa925050508015610de457506040513d6000823e601f3d908101601f19168201604052610de19190810190611e17565b60015b15610df5579093509150610c039050565b610dff85856109af565b92509250509250929050565b600060606000610e1b8585611902565b90506001600160a01b03811615610eac5760405163564cab9f60e11b81526001600160a01b038681166004830152858116602483015282169063ac99573e90604401600060405180830381865afa158015610e7a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ea29190810190611e17565b9250925050610c03565b610dff85856114a7565b604051634c9ba32160e11b815233600482015260209081906001600160a01b03861690639937464290602401602060405180830381865afa158015610eff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f239190611dc7565b16600003610f435760405162461bcd60e51b815260040161055090611d38565b6001600160a01b038481166000818152600660209081526040808320888616808552925280832080546001600160a01b0319169588169586179055519092917f6ac8517322c0ab7acb4f8bd1cf6011830e37fb0af82dcbd185da2b49b59f192691a450505050565b6002546000906001600160a01b031680610fc757600091505090565b806001600160a01b0316639436dce46040518163ffffffff1660e01b8152600401602060405180830381865afa158015611005573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110299190611dc7565b91505090565b60006060600061103e846119a0565b90506001600160a01b038116156110c75760405163b2c6779b60e01b81526001600160a01b03858116600483015282169063b2c6779b90602401600060405180830381865afa158015611095573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526110bd9190810190611e17565b9250925050915091565b6110bd8461063e565b60006060826001600160a01b0316635d265d3f6040518163ffffffff1660e01b8152600401600060405180830381865afa158015611112573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261113a9190810190611e17565b91509150915091565b816001600160a01b03166388a8d6026040518163ffffffff1660e01b8152600401602060405180830381865afa158015611181573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a59190611d1b565b6001600160a01b0316336001600160a01b0316146111d55760405162461bcd60e51b815260040161055090611d38565b6001600160a01b03821660008181526005602052604090819020839055517f2b8870338241f2dc328ed20de915f35d6eaa93df0970f846f55b97dc1af9ce0a906112229084815260200190565b60405180910390a25050565b61123661185a565b6001600160a01b03811661127b5760405162461bcd60e51b815260206004820152600c60248201526b5a45524f204144445245535360a01b6044820152606401610550565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f5f56bee8cffbe9a78652a74a60705edede02af10b0bbb888ca44b79a0d42ce809190a35050565b816001600160a01b03166388a8d6026040518163ffffffff1660e01b8152600401602060405180830381865afa158015611309573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061132d9190611d1b565b6001600160a01b0316336001600160a01b03161461135d5760405162461bcd60e51b815260040161055090611d38565b6001600160a01b0382811660008181526004602052604080822080546001600160a01b0319169486169485179055517f73377b61b22fc875803de44d9946a61753ba80d2539c51f226d765946eb642f29190a35050565b826001600160a01b03166388a8d6026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114169190611d1b565b6001600160a01b0316336001600160a01b0316146114465760405162461bcd60e51b815260040161055090611d38565b6001600160a01b0383811660008181526009602090815260408083209487168084529482529182902085905590518481527ff3672e1c1eaf0dd1ec58dc52e67753cb7a36b5f2a0334081174d8cf515f8093f910160405180910390a3505050565b600060606000849050806001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115129190611dac565b1561154157505060408051808201909152600881526729b43aba3237bbb760c11b602082015260009150610c03565b6040516339ebf82360e01b81526001600160a01b038581166004830152600091908316906339ebf82390602401608060405180830381865afa15801561158b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115af9190611ed7565b805190915015806115c257506040810151155b156115f75760006040518060400160405280600a8152602001694e6f742041637469766560b01b815250935093505050610c03565b6002546001600160a01b031680156116ca5760006116158888611a1d565b90506000816000036116295760035461162b565b815b905080836001600160a01b0316639436dce46040518163ffffffff1660e01b8152600401602060405180830381865afa15801561166c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116909190611dc7565b11156116c757600060405180604001604052806008815260200167426173652046656560c01b815250965096505050505050610c03565b50505b826001600160a01b0316630952864e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611708573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061172c9190611dc7565b602083015161173b9042611de0565b11836001600160a01b0316636ec2b8d48860405160240161176b91906001600160a01b0391909116815260200190565b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050945094505050509250929050565b6001600160a01b038116600090815260056020526040812054808203611854576040516001600160a01b03841660248201526000906118319073a045d4daea28ba7bfe234c96eaa03dafae85a1479063503fa78d906044015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611aaf565b805190915015611852578080602001905181019061184f9190611dc7565b91505b505b92915050565b6000546001600160a01b031633146118a25760405162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b6044820152606401610550565b565b6001600160a01b03808316600090815260096020908152604080832093851683529290529081205480156118d9579050611854565b5050506001600160a01b0316600090815260096020908152604080832083805290915290205490565b6001600160a01b038083166000908152600660209081526040808320858516845290915281205490911680611999576040516001600160a01b038581166024830152841660448201526000906119769073a045d4daea28ba7bfe234c96eaa03dafae85a14790639fb092df906064016117ff565b80519091501561199757808060200190518101906119949190611d1b565b91505b505b9392505050565b6001600160a01b0380821660009081526004602052604081205490911680611854576040516001600160a01b03841660248201526000906119ff9073a045d4daea28ba7bfe234c96eaa03dafae85a14790631627cea8906044016117ff565b805190915015611852578080602001905181019061184f9190611d1b565b6001600160a01b038083166000908152600760209081526040808320938516835292905290812054808203611999576040516001600160a01b03858116602483015284166044820152600090611a919073a045d4daea28ba7bfe234c96eaa03dafae85a14790634ff5363e906064016117ff565b80519091501561199757808060200190518101906119949190611dc7565b606060008073a045d4daea28ba7bfe234c96eaa03dafae85a1476001600160a01b031684604051611ae09190611f3d565b600060405180830381855afa9150503d8060008114611b1b576040519150601f19603f3d011682016040523d82523d6000602084013e611b20565b606091505b5091509150818015611b33575060008151115b15611b3f579392505050565b505060408051602081019091526000815292915050565b6001600160a01b0381168114611b6b57600080fd5b50565b60008060408385031215611b8157600080fd5b8235611b8c81611b56565b91506020830135611b9c81611b56565b809150509250929050565b60005b83811015611bc2578181015183820152602001611baa565b50506000910152565b60008151808452611be3816020860160208601611ba7565b601f01601f19169290920160200192915050565b6020815260006119996020830184611bcb565b600060208284031215611c1c57600080fd5b813561199981611b56565b8215158152604060208201526000611c426040830184611bcb565b949350505050565b600080600060608486031215611c5f57600080fd5b8335611c6a81611b56565b92506020840135611c7a81611b56565b929592945050506040919091013590565b600060208284031215611c9d57600080fd5b5035919050565b600080600060608486031215611cb957600080fd5b8335611cc481611b56565b92506020840135611cd481611b56565b91506040840135611ce481611b56565b809150509250925092565b60008060408385031215611d0257600080fd5b8235611d0d81611b56565b946020939093013593505050565b600060208284031215611d2d57600080fd5b815161199981611b56565b6020808252600b908201526a08585d5d1a1bdc9a5e995960aa1b604082015260600190565b600181811c90821680611d7157607f821691505b602082108103611d9157634e487b7160e01b600052602260045260246000fd5b50919050565b80518015158114611da757600080fd5b919050565b600060208284031215611dbe57600080fd5b61199982611d97565b600060208284031215611dd957600080fd5b5051919050565b8181038181111561185457634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b60008060408385031215611e2a57600080fd5b611e3383611d97565b9150602083015167ffffffffffffffff80821115611e5057600080fd5b818501915085601f830112611e6457600080fd5b815181811115611e7657611e76611e01565b604051601f8201601f19908116603f01168101908382118183101715611e9e57611e9e611e01565b81604052828152886020848701011115611eb757600080fd5b611ec8836020830160208801611ba7565b80955050505050509250929050565b600060808284031215611ee957600080fd5b6040516080810181811067ffffffffffffffff82111715611f0c57611f0c611e01565b8060405250825181526020830151602082015260408301516040820152606083015160608201528091505092915050565b60008251611f4f818460208701611ba7565b919091019291505056fe53747261746567792074726967676572206e6f7420696d706c656d656e746564206f72207265766572746564a2646970667358221220d2ad9e77fcff12c5698a8b3bc895867a0f69c2a22f6786f2c3102a493157109464736f6c63430008120033

Verified Source Code Full Match

Compiler: v0.8.18+commit.87f61d96 EVM: paris Optimization: Yes (200 runs)
CommonTrigger.sol 786 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import {Governance} from "../utils/Governance.sol";

import {IVault} from "@yearn-vaults/interfaces/IVault.sol";
import {IStrategy} from "@tokenized-strategy/interfaces/IStrategy.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IAuctionSwapper} from "../swappers/interfaces/IAuctionSwapper.sol";

interface ICustomStrategyTrigger {
    function reportTrigger(
        address _strategy
    ) external view returns (bool, bytes memory);
}

interface ICustomVaultTrigger {
    function reportTrigger(
        address _vault,
        address _strategy
    ) external view returns (bool, bytes memory);
}

interface ICustomAuctionTrigger {
    function auctionTrigger(
        address _strategy,
        address _from
    ) external view returns (bool, bytes memory);
}

interface IBaseFee {
    function basefee_global() external view returns (uint256);
}

/**
 *  @title Common Trigger
 *  @author Yearn.finance
 *  @dev This is a central contract that keepers can use
 *  to decide if Yearn V3 strategies should report profits,
 *  when V3 Vaults should record a strategies profits, and
 *  when strategies that implement auctions should kick off
 *  an auction.
 *
 *  It allows for a simple default flow that most strategies
 *  and vaults can use for easy integration with a keeper network.
 *  However, it is also customizable by the strategy and vaults
 *  management to allow complete customization if desired.
 */
contract CommonTrigger is Governance {
    /*//////////////////////////////////////////////////////////////
                            EVENTS
    //////////////////////////////////////////////////////////////*/

    event NewBaseFeeProvider(address indexed provider);

    event UpdatedAcceptableBaseFee(uint256 acceptableBaseFee);

    event UpdatedCustomStrategyTrigger(
        address indexed strategy,
        address indexed trigger
    );

    event UpdatedCustomStrategyBaseFee(
        address indexed strategy,
        uint256 acceptableBaseFee
    );

    event UpdatedCustomVaultTrigger(
        address indexed vault,
        address indexed strategy,
        address indexed trigger
    );

    event UpdatedCustomVaultBaseFee(
        address indexed vault,
        address indexed strategy,
        uint256 acceptableBaseFee
    );

    event UpdatedCustomAuctionTrigger(
        address indexed strategy,
        address indexed trigger
    );

    event UpdatedMinimumAmountToKick(
        address indexed strategy,
        address indexed token,
        uint256 amount
    );

    /*//////////////////////////////////////////////////////////////
                            STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name = "Yearn Common Trigger";

    // Address of the legacy CommonReportTrigger for fallback support
    address public constant LEGACY_REPORT_TRIGGER =
        0xA045D4dAeA28BA7Bfe234c96eAa03daFae85A147;

    // Address to retrieve the current base fee on the network from.
    address public baseFeeProvider;

    // Default base fee the trigger will accept for a trigger to return `true`.
    uint256 public acceptableBaseFee;

    // Mapping of a strategy address to the address of a custom report
    // trigger if the strategies management wants to implement their own
    // custom logic. If address(0) the default trigger will be used.
    mapping(address => address) public customStrategyTrigger;

    // Mapping of a strategy address to a custom base fee that will be
    // accepted for the trigger to return true. If 0 the default
    // `acceptableBaseFee` will be used.
    mapping(address => uint256) public customStrategyBaseFee;

    // Mapping of a vault address and one of its strategies address to a
    // custom report trigger. If address(0) the default trigger will be used.
    // vaultAddress => strategyAddress => customTriggerContract.
    mapping(address => mapping(address => address)) public customVaultTrigger;

    // Mapping of a vault address and one of its strategies address to a
    // custom base fee that will be used for a trigger to return true. If
    // returns 0 then the default `acceptableBaseFee` will be used.
    // vaultAddress => strategyAddress => customBaseFee.
    mapping(address => mapping(address => uint256)) public customVaultBaseFee;

    // Mapping of a strategy address to the address of a custom auction
    // trigger if the strategies management wants to implement their own
    // custom logic. If address(0) the default trigger will be used.
    mapping(address => address) public customAuctionTrigger;

    // Mapping of a strategy address to a token address to minimum amount
    // strategy => token => minimum amount. Token can be address(0) for global minimum.
    mapping(address => mapping(address => uint256)) public minimumAmountToKick;

    constructor(address _governance) Governance(_governance) {}

    /*//////////////////////////////////////////////////////////////
                        CUSTOM SETTERS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Set a custom report trigger contract for a strategy.
     * @dev This gives the `management` of a specific strategy the option
     * to enforce a custom report trigger for their strategy easily while
     * still using this standard contract for keepers to read the trigger
     * status from.
     *
     * The custom trigger contract only needs to implement the `reportTrigger`
     * function to return true or false.
     *
     * @param _strategy The address of the strategy to set the trigger for.
     * @param _trigger The address of the custom trigger contract.
     */
    function setCustomStrategyTrigger(
        address _strategy,
        address _trigger
    ) external virtual {
        require(msg.sender == IStrategy(_strategy).management(), "!authorized");
        customStrategyTrigger[_strategy] = _trigger;

        emit UpdatedCustomStrategyTrigger(_strategy, _trigger);
    }

    /**
     * @notice Set a custom base fee for a specific strategy.
     * @dev This can be set by a strategies `management` to increase or
     * decrease the acceptable network base fee for a specific strategies
     * trigger to return true.
     *
     * This can be used instead of a custom trigger contract.
     *
     * This will have no effect if a custom trigger is set for the strategy.
     *
     * @param _strategy The address of the strategy to customize.
     * @param _baseFee The max acceptable network base fee.
     */
    function setCustomStrategyBaseFee(
        address _strategy,
        uint256 _baseFee
    ) external virtual {
        require(msg.sender == IStrategy(_strategy).management(), "!authorized");
        customStrategyBaseFee[_strategy] = _baseFee;

        emit UpdatedCustomStrategyBaseFee(_strategy, _baseFee);
    }

    /**
     * @notice Set a custom report trigger contract for a vaults strategy.
     * @dev This gives the management of a vault the option to enforce a
     * custom report trigger for a specific strategy attached to the vault
     * while still using this standard contract for keepers to read the
     * trigger status from.
     *
     * The address calling must have the `REPORTING_MANAGER` role on the vault.
     *
     * The custom trigger contract only needs to implement the `reportTrigger`
     * function to return true or false.
     *
     * @param _vault The address of the vault
     * @param _strategy The address of the strategy to set the trigger for.
     * @param _trigger The address of the custom trigger contract.
     */
    function setCustomVaultTrigger(
        address _vault,
        address _strategy,
        address _trigger
    ) external virtual {
        // Check that the address has the REPORTING_MANAGER role on the vault.
        uint256 mask = 32;
        require((IVault(_vault).roles(msg.sender) & mask) != 0, "!authorized");
        customVaultTrigger[_vault][_strategy] = _trigger;

        emit UpdatedCustomVaultTrigger(_vault, _strategy, _trigger);
    }

    /**
     * @notice Set a custom base fee for a vaults strategy.
     * @dev This can be set by the vaults management to increase or
     * decrease the acceptable network base fee for a specific strategies
     * trigger to return true.
     *
     * This can be used instead of a custom trigger contract.
     *
     * This will have no effect if a custom trigger is set for the strategy.
     *
     * The address calling must have the `REPORTING_MANAGER` role on the vault.
     *
     * @param _vault The address of the vault.
     * @param _strategy The address of the strategy to customize.
     * @param _baseFee The max acceptable network base fee.
     */
    function setCustomVaultBaseFee(
        address _vault,
        address _strategy,
        uint256 _baseFee
    ) external virtual {
        // Check that the address has the REPORTING_MANAGER role on the vault.
        uint256 mask = 32;
        require((IVault(_vault).roles(msg.sender) & mask) != 0, "!authorized");
        customVaultBaseFee[_vault][_strategy] = _baseFee;

        emit UpdatedCustomVaultBaseFee(_vault, _strategy, _baseFee);
    }

    /**
     * @notice Set a custom auction trigger contract for a strategy.
     * @dev This gives the `management` of a specific strategy the option
     * to enforce a custom auction trigger for their strategy easily while
     * still using this standard contract for keepers to read the trigger
     * status from.
     *
     * The custom trigger contract only needs to implement the `auctionTrigger`
     * function to return true or false with bytes reason.
     *
     * @param _strategy The address of the strategy to set the trigger for.
     * @param _trigger The address of the custom trigger contract.
     */
    function setCustomAuctionTrigger(
        address _strategy,
        address _trigger
    ) external virtual {
        require(msg.sender == IStrategy(_strategy).management(), "!authorized");
        customAuctionTrigger[_strategy] = _trigger;

        emit UpdatedCustomAuctionTrigger(_strategy, _trigger);
    }

    /**
     * @notice Set a minimum amount of tokens required to kick an auction.
     * @dev This gives the `management` of a specific strategy the option
     * to set a minimum balance threshold that must be met before an
     * auction can be kicked for a specific token.
     *
     * @param _strategy The address of the strategy to set the minimum for.
     * @param _token The address of the token, or address(0) for global minimum.
     * @param _amount The minimum amount of tokens required to kick an auction.
     */
    function setMinimumAmountToKick(
        address _strategy,
        address _token,
        uint256 _amount
    ) external virtual {
        require(msg.sender == IStrategy(_strategy).management(), "!authorized");
        minimumAmountToKick[_strategy][_token] = _amount;

        emit UpdatedMinimumAmountToKick(_strategy, _token, _amount);
    }

    /*//////////////////////////////////////////////////////////////
                            TRIGGERS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Returns wether or not a strategy is ready for a keeper to call `report`.
     * @dev Will first check if a custom trigger is set. If not it will use
     * the default trigger flow.
     *
     * @param _strategy The address of the strategy to check the trigger for.
     * @return . Bool representing if the strategy is ready to report.
     * @return . Bytes with either the calldata or reason why False.
     */
    function strategyReportTrigger(
        address _strategy
    ) external view virtual returns (bool, bytes memory) {
        address _trigger = _getCustomStrategyTrigger(_strategy);

        // If a custom trigger contract is set use that one.
        if (_trigger != address(0)) {
            return ICustomStrategyTrigger(_trigger).reportTrigger(_strategy);
        }

        // Return the default trigger logic.
        return defaultStrategyReportTrigger(_strategy);
    }

    /**
     * @notice The default trigger logic for a strategy.
     * @dev This is kept in a separate function so it can still
     * be used by custom triggers even if extra checks are needed
     * first or after.
     *
     * This will also check if a custom acceptable base fee has been set
     * by the strategies management.
     *
     * In order for the default flow to return true the strategy must:
     *
     *   1. Not be shutdown.
     *   2. Have funds.
     *   3. The current network base fee be below the `acceptableBaseFee`.
     *   4. The time since the last report be > the strategies `profitMaxUnlockTime`.
     *
     * @param _strategy The address of the strategy to check the trigger for.
     * @return . Bool representing if the strategy is ready to report.
     * @return . Bytes with either the calldata or reason why False.
     */
    function defaultStrategyReportTrigger(
        address _strategy
    ) public view virtual returns (bool, bytes memory) {
        // Cache the strategy instance.
        IStrategy strategy = IStrategy(_strategy);

        // Don't report if the strategy is shutdown.
        if (strategy.isShutdown()) return (false, bytes("Shutdown"));

        // Don't report if the strategy has no assets.
        if (strategy.totalAssets() == 0) return (false, bytes("Zero Assets"));

        // Check if a `baseFeeProvider` is set.
        address _baseFeeProvider = baseFeeProvider;
        if (_baseFeeProvider != address(0)) {
            uint256 customAcceptableBaseFee = _getCustomStrategyBaseFee(
                _strategy
            );
            // Use the custom base fee if set, otherwise use the default.
            uint256 _acceptableBaseFee = customAcceptableBaseFee != 0
                ? customAcceptableBaseFee
                : acceptableBaseFee;

            // Don't report if the base fee is to high.
            if (
                IBaseFee(_baseFeeProvider).basefee_global() > _acceptableBaseFee
            ) return (false, bytes("Base Fee"));
        }

        return (
            // Return true is the full profit unlock time has passed since the last report.
            block.timestamp - strategy.lastReport() >
                strategy.profitMaxUnlockTime(),
            // Return the report function sig as the calldata.
            abi.encodeWithSelector(strategy.report.selector)
        );
    }

    /**
     * @notice Return wether or not a report should be called on a vault for
     * a specific strategy.
     * @dev Will first check if a custom trigger is set. If not it will use
     * the default trigger flow.
     *
     * @param _vault The address of the vault.
     * @param _strategy The address of the strategy to report.
     * @return . Bool if the strategy should report to the vault.
     * @return . Bytes with either the calldata or reason why False.
     */
    function vaultReportTrigger(
        address _vault,
        address _strategy
    ) external view virtual returns (bool, bytes memory) {
        address _trigger = _getCustomVaultTrigger(_vault, _strategy);

        // If a custom trigger contract is set use that.
        if (_trigger != address(0)) {
            return
                ICustomVaultTrigger(_trigger).reportTrigger(_vault, _strategy);
        }

        // return the default trigger.
        return defaultVaultReportTrigger(_vault, _strategy);
    }

    /**
     * @notice The default trigger logic for a vault.
     * @dev This is kept in a separate function so it can still
     * be used by custom triggers even if extra checks are needed
     * before or after.
     *
     * This will also check if a custom acceptable base fee has been set
     * by the vault management for the `_strategy`.
     *
     * In order for the default flow to return true:
     *
     *   1. The vault must not be shutdown.
     *   2. The strategy must be active and have debt allocated.
     *   3. The current network base fee be below the `acceptableBaseFee`.
     *   4. The time since the strategies last report be > the vaults `profitMaxUnlockTime`.
     *
     * @param _vault The address of the vault.
     * @param _strategy The address of the strategy to report.
     * @return . Bool if the strategy should report to the vault.
     * @return . Bytes with either the calldata or reason why False.
     */
    function defaultVaultReportTrigger(
        address _vault,
        address _strategy
    ) public view virtual returns (bool, bytes memory) {
        // Cache the vault instance.
        IVault vault = IVault(_vault);

        // Don't report if the vault is shutdown.
        if (vault.isShutdown()) return (false, bytes("Shutdown"));

        // Cache the strategy parameters.
        IVault.StrategyParams memory params = vault.strategies(_strategy);

        // Don't report if the strategy is not active or has no funds.
        if (params.activation == 0 || params.current_debt == 0)
            return (false, bytes("Not Active"));

        // Check if a `baseFeeProvider` is set.
        address _baseFeeProvider = baseFeeProvider;
        if (_baseFeeProvider != address(0)) {
            uint256 customAcceptableBaseFee = _getCustomVaultBaseFee(
                _vault,
                _strategy
            );
            // Use the custom base fee if set, otherwise use the default.
            uint256 _acceptableBaseFee = customAcceptableBaseFee != 0
                ? customAcceptableBaseFee
                : acceptableBaseFee;

            // Don't report if the base fee is to high.
            if (
                IBaseFee(_baseFeeProvider).basefee_global() > _acceptableBaseFee
            ) return (false, bytes("Base Fee"));
        }

        return (
            // Return true is the full profit unlock time has passed since the last report.
            block.timestamp - params.last_report > vault.profitMaxUnlockTime(),
            // Return the function selector and the strategy as the parameter to use.
            abi.encodeCall(vault.process_report, _strategy)
        );
    }

    /**
     * @notice Return whether or not a strategy should be tended by a keeper.
     * @dev This can be used as an easy keeper integration for any strategy that
     * implements a tendTrigger.
     *
     * It is expected that a strategy implement all needed checks such as
     * isShutdown, totalAssets > 0 and base fee checks within the trigger.
     *
     * @param _strategy Address of the strategy to check.
     * @return . Bool if the strategy should be tended.
     * @return . Bytes with the calldata.
     */
    function strategyTendTrigger(
        address _strategy
    ) external view virtual returns (bool, bytes memory) {
        // Return the status of the tend trigger.
        return IStrategy(_strategy).tendTrigger();
    }

    /**
     * @notice Returns the current base fee from the provider.
     * @dev Will return 0 if a base fee provider is not set.
     * @return . The current base fee for the chain.
     */
    function getCurrentBaseFee() public view virtual returns (uint256) {
        address _baseFeeProvider = baseFeeProvider;
        if (_baseFeeProvider == address(0)) return 0;

        return IBaseFee(_baseFeeProvider).basefee_global();
    }

    /**
     * @notice Returns wether or not the current base fee is acceptable
     * based on the default `acceptableBaseFee`.
     * @dev Can be used in custom triggers to easily still use this contracts
     * fee provider and acceptableBaseFee. And makes it backwards compatible to V2.
     *
     * Will always return `true` if no `baseFeeProvider` is set.
     *
     * @return . IF the current base fee is acceptable.
     */
    function isCurrentBaseFeeAcceptable() external view virtual returns (bool) {
        return getCurrentBaseFee() <= acceptableBaseFee;
    }

    /*//////////////////////////////////////////////////////////////
                        AUCTION TRIGGERS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Returns whether or not an auction should be kicked for a strategy.
     * @dev Will first check if a custom trigger is set. If not it will
     * attempt to call `auctionTrigger` on the strategy itself. If that fails,
     * it will return false with the error message.
     *
     * This function uses try-catch to ensure it never reverts at the top level.
     *
     * @param _strategy The address of the strategy to check the trigger for.
     * @param _from The address of the token to be auctioned.
     * @return . Bool representing if the auction should be kicked.
     * @return . Bytes with either the calldata or reason why False.
     */
    function auctionTrigger(
        address _strategy,
        address _from
    ) external view virtual returns (bool, bytes memory) {
        address _trigger = _getCustomAuctionTrigger(_strategy);

        // If a custom trigger contract is set use that one.
        if (_trigger != address(0)) {
            // Use try-catch to handle any reverts in the custom trigger
            try
                ICustomAuctionTrigger(_trigger).auctionTrigger(_strategy, _from)
            returns (bool shouldKick, bytes memory data) {
                return (shouldKick, data);
            } catch {} // If it fails, try the default trigger path
        }

        // Return the default trigger logic.
        return defaultAuctionTrigger(_strategy, _from);
    }

    /**
     * @notice The default trigger logic for a strategy auction.
     * @dev This attempts to call `auctionTrigger(address)` on the strategy itself.
     * If the strategy implements this function, it will use that logic.
     * If not, or if it reverts, it will return false.
     *
     * This will also check if a custom acceptable base fee has been set
     * by the strategies management.
     *
     * @param _strategy The address of the strategy to check the trigger for.
     * @param _from The address of the token to be auctioned.
     * @return . Bool representing if the auction should be kicked.
     * @return . Bytes with either the calldata or reason why False.
     */
    function defaultAuctionTrigger(
        address _strategy,
        address _from
    ) public view virtual returns (bool, bytes memory) {
        // Check if a `baseFeeProvider` is set and if base fee is acceptable.
        address _baseFeeProvider = baseFeeProvider;
        if (_baseFeeProvider != address(0)) {
            uint256 customAcceptableBaseFee = _getCustomStrategyBaseFee(
                _strategy
            );
            // Use the custom base fee if set, otherwise use the default.
            uint256 _acceptableBaseFee = customAcceptableBaseFee != 0
                ? customAcceptableBaseFee
                : acceptableBaseFee;

            // Don't trigger if the base fee is too high.
            if (
                IBaseFee(_baseFeeProvider).basefee_global() > _acceptableBaseFee
            ) return (false, bytes("Base Fee"));
        }

        // Check if minimum amount to kick is met
        uint256 minimumAmount = _getMinimumAmountToKick(_strategy, _from);
        if (minimumAmount > 0) {
            uint256 balance = ERC20(_from).balanceOf(_strategy);
            if (balance > minimumAmount) {
                return (
                    true,
                    abi.encodeCall(
                        IAuctionSwapper(_strategy).kickAuction,
                        (_from)
                    )
                );
            }
        }

        // Try to call auctionTrigger on the strategy itself
        // Use try-catch to handle strategies that don't implement it or revert
        try IAuctionSwapper(_strategy).auctionTrigger(_from) returns (
            bool shouldKick,
            bytes memory data
        ) {
            return (shouldKick, data);
        } catch {
            // If the call fails (strategy doesn't implement it or reverts),
            // return false with a descriptive message
            return (
                false,
                bytes("Strategy trigger not implemented or reverted")
            );
        }
    }

    /*//////////////////////////////////////////////////////////////
                    LEGACY FALLBACK HELPERS
    //////////////////////////////////////////////////////////////*/

    /**
     * @dev Internal function to get custom strategy trigger with legacy fallback.
     */
    function _getCustomStrategyTrigger(
        address _strategy
    ) internal view returns (address) {
        address trigger = customStrategyTrigger[_strategy];

        // If not set locally, check legacy contract
        if (trigger == address(0)) {
            bytes memory data = _getFromLegacy(
                abi.encodeCall(
                    CommonTrigger(LEGACY_REPORT_TRIGGER).customStrategyTrigger,
                    (_strategy)
                )
            );
            if (data.length > 0) {
                trigger = abi.decode(data, (address));
            }
        }

        return trigger;
    }

    /**
     * @dev Internal function to get custom strategy base fee with legacy fallback.
     */
    function _getCustomStrategyBaseFee(
        address _strategy
    ) internal view returns (uint256) {
        uint256 baseFee = customStrategyBaseFee[_strategy];

        // If not set locally, check legacy contract
        if (baseFee == 0) {
            bytes memory data = _getFromLegacy(
                abi.encodeCall(
                    CommonTrigger(LEGACY_REPORT_TRIGGER).customStrategyBaseFee,
                    (_strategy)
                )
            );
            if (data.length > 0) {
                baseFee = abi.decode(data, (uint256));
            }
        }

        return baseFee;
    }

    /**
     * @dev Internal function to get custom vault trigger with legacy fallback.
     */
    function _getCustomVaultTrigger(
        address _vault,
        address _strategy
    ) internal view returns (address) {
        address trigger = customVaultTrigger[_vault][_strategy];

        // If not set locally, check legacy contract
        if (trigger == address(0)) {
            bytes memory data = _getFromLegacy(
                abi.encodeCall(
                    CommonTrigger(LEGACY_REPORT_TRIGGER).customVaultTrigger,
                    (_vault, _strategy)
                )
            );
            if (data.length > 0) {
                trigger = abi.decode(data, (address));
            }
        }

        return trigger;
    }

    /**
     * @dev Internal function to get custom vault base fee with legacy fallback.
     */
    function _getCustomVaultBaseFee(
        address _vault,
        address _strategy
    ) internal view returns (uint256) {
        uint256 baseFee = customVaultBaseFee[_vault][_strategy];

        // If not set locally, check legacy contract
        if (baseFee == 0) {
            bytes memory data = _getFromLegacy(
                abi.encodeCall(
                    CommonTrigger(LEGACY_REPORT_TRIGGER).customVaultBaseFee,
                    (_vault, _strategy)
                )
            );
            if (data.length > 0) {
                baseFee = abi.decode(data, (uint256));
            }
        }

        return baseFee;
    }

    function _getFromLegacy(
        bytes memory _data
    ) internal view returns (bytes memory) {
        (bool success, bytes memory data) = LEGACY_REPORT_TRIGGER.staticcall(
            _data
        );
        if (success && data.length > 0) {
            return data;
        }
        return bytes("");
    }

    /**
     * @dev Internal function to get custom auction trigger - no legacy fallback since this is new.
     */
    function _getCustomAuctionTrigger(
        address _strategy
    ) internal view returns (address) {
        return customAuctionTrigger[_strategy];
    }

    /**
     * @dev Internal function to get minimum amount to kick for a strategy-token pair.
     * First checks for specific token minimum, then falls back to global minimum.
     */
    function _getMinimumAmountToKick(
        address _strategy,
        address _token
    ) internal view returns (uint256) {
        // Check for specific token minimum
        uint256 specificMinimum = minimumAmountToKick[_strategy][_token];
        if (specificMinimum > 0) {
            return specificMinimum;
        }

        // Fall back to global minimum (address(0))
        return minimumAmountToKick[_strategy][address(0)];
    }

    /*//////////////////////////////////////////////////////////////
                        GOVERNANCE FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Sets the address used to pull the current network base fee.
     * @dev Throws if the caller is not current governance.
     * @param _baseFeeProvider The network's baseFeeProvider address.
     */
    function setBaseFeeProvider(
        address _baseFeeProvider
    ) external virtual onlyGovernance {
        baseFeeProvider = _baseFeeProvider;

        emit NewBaseFeeProvider(_baseFeeProvider);
    }

    /**
     * @notice Sets the default acceptable current network base fee.
     * @dev Throws if the caller is not current governance.
     * @param _newAcceptableBaseFee The acceptable network base fee.
     */
    function setAcceptableBaseFee(
        uint256 _newAcceptableBaseFee
    ) external virtual onlyGovernance {
        acceptableBaseFee = _newAcceptableBaseFee;

        emit UpdatedAcceptableBaseFee(_newAcceptableBaseFee);
    }
}
Governance.sol 44 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

contract Governance {
    /// @notice Emitted when the governance address is updated.
    event GovernanceTransferred(
        address indexed previousGovernance,
        address indexed newGovernance
    );

    modifier onlyGovernance() {
        _checkGovernance();
        _;
    }

    /// @notice Checks if the msg sender is the governance.
    function _checkGovernance() internal view virtual {
        require(governance == msg.sender, "!governance");
    }

    /// @notice Address that can set the default base fee and provider
    address public governance;

    constructor(address _governance) {
        governance = _governance;

        emit GovernanceTransferred(address(0), _governance);
    }

    /**
     * @notice Sets a new address as the governance of the contract.
     * @dev Throws if the caller is not current governance.
     * @param _newGovernance The new governance address.
     */
    function transferGovernance(
        address _newGovernance
    ) external virtual onlyGovernance {
        require(_newGovernance != address(0), "ZERO ADDRESS");
        address oldGovernance = governance;
        governance = _newGovernance;

        emit GovernanceTransferred(oldGovernance, _newGovernance);
    }
}
IVault.sol 259 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.18;

import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";

interface IVault is IERC4626 {
    // STRATEGY EVENTS
    event StrategyChanged(address indexed strategy, uint256 change_type);
    event StrategyReported(
        address indexed strategy,
        uint256 gain,
        uint256 loss,
        uint256 current_debt,
        uint256 protocol_fees,
        uint256 total_fees,
        uint256 total_refunds
    );
    // DEBT MANAGEMENT EVENTS
    event DebtUpdated(
        address indexed strategy,
        uint256 current_debt,
        uint256 new_debt
    );
    // ROLE UPDATES
    event RoleSet(address indexed account, uint256 role);
    event UpdateFutureRoleManager(address indexed future_role_manager);
    event UpdateRoleManager(address indexed role_manager);

    event UpdateAccountant(address indexed accountant);
    event UpdateDefaultQueue(address[] new_default_queue);
    event UpdateUseDefaultQueue(bool use_default_queue);
    event UpdatedMaxDebtForStrategy(
        address indexed sender,
        address indexed strategy,
        uint256 new_debt
    );
    event UpdateAutoAllocate(bool auto_allocate);
    event UpdateDepositLimit(uint256 deposit_limit);
    event UpdateMinimumTotalIdle(uint256 minimum_total_idle);
    event UpdateProfitMaxUnlockTime(uint256 profit_max_unlock_time);
    event DebtPurchased(address indexed strategy, uint256 amount);
    event Shutdown();

    struct StrategyParams {
        uint256 activation;
        uint256 last_report;
        uint256 current_debt;
        uint256 max_debt;
    }

    function FACTORY() external view returns (uint256);

    function strategies(address) external view returns (StrategyParams memory);

    function default_queue(uint256) external view returns (address);

    function use_default_queue() external view returns (bool);

    function auto_allocate() external view returns (bool);

    function minimum_total_idle() external view returns (uint256);

    function deposit_limit() external view returns (uint256);

    function deposit_limit_module() external view returns (address);

    function withdraw_limit_module() external view returns (address);

    function accountant() external view returns (address);

    function roles(address) external view returns (uint256);

    function role_manager() external view returns (address);

    function future_role_manager() external view returns (address);

    function isShutdown() external view returns (bool);

    function nonces(address) external view returns (uint256);

    function initialize(
        address,
        string memory,
        string memory,
        address,
        uint256
    ) external;

    function setName(string memory) external;

    function setSymbol(string memory) external;

    function set_accountant(address new_accountant) external;

    function set_default_queue(address[] memory new_default_queue) external;

    function set_use_default_queue(bool) external;

    function set_auto_allocate(bool) external;

    function set_deposit_limit(uint256 deposit_limit) external;

    function set_deposit_limit(
        uint256 deposit_limit,
        bool should_override
    ) external;

    function set_deposit_limit_module(
        address new_deposit_limit_module
    ) external;

    function set_deposit_limit_module(
        address new_deposit_limit_module,
        bool should_override
    ) external;

    function set_withdraw_limit_module(
        address new_withdraw_limit_module
    ) external;

    function set_minimum_total_idle(uint256 minimum_total_idle) external;

    function setProfitMaxUnlockTime(
        uint256 new_profit_max_unlock_time
    ) external;

    function set_role(address account, uint256 role) external;

    function add_role(address account, uint256 role) external;

    function remove_role(address account, uint256 role) external;

    function transfer_role_manager(address role_manager) external;

    function accept_role_manager() external;

    function unlockedShares() external view returns (uint256);

    function pricePerShare() external view returns (uint256);

    function get_default_queue() external view returns (address[] memory);

    function process_report(
        address strategy
    ) external returns (uint256, uint256);

    function buy_debt(address strategy, uint256 amount) external;

    function add_strategy(address new_strategy) external;

    function revoke_strategy(address strategy) external;

    function force_revoke_strategy(address strategy) external;

    function update_max_debt_for_strategy(
        address strategy,
        uint256 new_max_debt
    ) external;

    function update_debt(
        address strategy,
        uint256 target_debt
    ) external returns (uint256);

    function update_debt(
        address strategy,
        uint256 target_debt,
        uint256 max_loss
    ) external returns (uint256);

    function shutdown_vault() external;

    function totalIdle() external view returns (uint256);

    function totalDebt() external view returns (uint256);

    function apiVersion() external view returns (string memory);

    function assess_share_of_unrealised_losses(
        address strategy,
        uint256 assets_needed
    ) external view returns (uint256);

    function profitMaxUnlockTime() external view returns (uint256);

    function fullProfitUnlockDate() external view returns (uint256);

    function profitUnlockingRate() external view returns (uint256);

    function lastProfitUpdate() external view returns (uint256);

    //// NON-STANDARD ERC-4626 FUNCTIONS \\\\

    function withdraw(
        uint256 assets,
        address receiver,
        address owner,
        uint256 max_loss
    ) external returns (uint256);

    function withdraw(
        uint256 assets,
        address receiver,
        address owner,
        uint256 max_loss,
        address[] memory strategies
    ) external returns (uint256);

    function redeem(
        uint256 shares,
        address receiver,
        address owner,
        uint256 max_loss
    ) external returns (uint256);

    function redeem(
        uint256 shares,
        address receiver,
        address owner,
        uint256 max_loss,
        address[] memory strategies
    ) external returns (uint256);

    function maxWithdraw(
        address owner,
        uint256 max_loss
    ) external view returns (uint256);

    function maxWithdraw(
        address owner,
        uint256 max_loss,
        address[] memory strategies
    ) external view returns (uint256);

    function maxRedeem(
        address owner,
        uint256 max_loss
    ) external view returns (uint256);

    function maxRedeem(
        address owner,
        uint256 max_loss,
        address[] memory strategies
    ) external view returns (uint256);

    //// NON-STANDARD ERC-20 FUNCTIONS \\\\

    function DOMAIN_SEPARATOR() external view returns (bytes32);

    function permit(
        address owner,
        address spender,
        uint256 amount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (bool);
}
IStrategy.sol 7 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import {ITokenizedStrategy} from "./ITokenizedStrategy.sol";
import {IBaseStrategy} from "./IBaseStrategy.sol";

interface IStrategy is IBaseStrategy, ITokenizedStrategy {}
ERC20.sol 365 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(address from, address to, uint256 amount) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
IAuctionSwapper.sol 21 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import "./IBaseSwapper.sol";

interface IAuctionSwapper is IBaseSwapper {
    event AuctionSet(address indexed auction);
    event UseAuctionSet(bool indexed useAuction);

    function auction() external view returns (address);

    function useAuction() external view returns (bool);

    function kickable(address _fromToken) external view returns (uint256);

    function kickAuction(address _from) external returns (uint256);

    function auctionTrigger(
        address _from
    ) external view returns (bool shouldKick, bytes memory data);
}
IERC4626.sol 232 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";

/**
 * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 *
 * _Available since v4.7._
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}
ITokenizedStrategy.sol 168 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

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

// Interface that implements the 4626 standard and the implementation functions
interface ITokenizedStrategy is IERC4626, IERC20Permit {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event StrategyShutdown();

    event NewTokenizedStrategy(
        address indexed strategy,
        address indexed asset,
        string apiVersion
    );

    event Reported(
        uint256 profit,
        uint256 loss,
        uint256 protocolFees,
        uint256 performanceFees
    );

    event UpdatePerformanceFeeRecipient(
        address indexed newPerformanceFeeRecipient
    );

    event UpdateKeeper(address indexed newKeeper);

    event UpdatePerformanceFee(uint16 newPerformanceFee);

    event UpdateManagement(address indexed newManagement);

    event UpdateEmergencyAdmin(address indexed newEmergencyAdmin);

    event UpdateProfitMaxUnlockTime(uint256 newProfitMaxUnlockTime);

    event UpdatePendingManagement(address indexed newPendingManagement);

    /*//////////////////////////////////////////////////////////////
                           INITIALIZATION
    //////////////////////////////////////////////////////////////*/

    function initialize(
        address _asset,
        string memory _name,
        address _management,
        address _performanceFeeRecipient,
        address _keeper
    ) external;

    /*//////////////////////////////////////////////////////////////
                    NON-STANDARD 4626 OPTIONS
    //////////////////////////////////////////////////////////////*/

    function withdraw(
        uint256 assets,
        address receiver,
        address owner,
        uint256 maxLoss
    ) external returns (uint256);

    function redeem(
        uint256 shares,
        address receiver,
        address owner,
        uint256 maxLoss
    ) external returns (uint256);

    function maxWithdraw(
        address owner,
        uint256 /*maxLoss*/
    ) external view returns (uint256);

    function maxRedeem(
        address owner,
        uint256 /*maxLoss*/
    ) external view returns (uint256);

    /*//////////////////////////////////////////////////////////////
                        MODIFIER HELPERS
    //////////////////////////////////////////////////////////////*/

    function requireManagement(address _sender) external view;

    function requireKeeperOrManagement(address _sender) external view;

    function requireEmergencyAuthorized(address _sender) external view;

    /*//////////////////////////////////////////////////////////////
                        KEEPERS FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    function tend() external;

    function report() external returns (uint256 _profit, uint256 _loss);

    /*//////////////////////////////////////////////////////////////
                        CONSTANTS
    //////////////////////////////////////////////////////////////*/

    function MAX_FEE() external view returns (uint16);

    function FACTORY() external view returns (address);

    /*//////////////////////////////////////////////////////////////
                            GETTERS
    //////////////////////////////////////////////////////////////*/

    function apiVersion() external view returns (string memory);

    function pricePerShare() external view returns (uint256);

    function management() external view returns (address);

    function pendingManagement() external view returns (address);

    function keeper() external view returns (address);

    function emergencyAdmin() external view returns (address);

    function performanceFee() external view returns (uint16);

    function performanceFeeRecipient() external view returns (address);

    function fullProfitUnlockDate() external view returns (uint256);

    function profitUnlockingRate() external view returns (uint256);

    function profitMaxUnlockTime() external view returns (uint256);

    function lastReport() external view returns (uint256);

    function isShutdown() external view returns (bool);

    function unlockedShares() external view returns (uint256);

    /*//////////////////////////////////////////////////////////////
                            SETTERS
    //////////////////////////////////////////////////////////////*/

    function setPendingManagement(address) external;

    function acceptManagement() external;

    function setKeeper(address _keeper) external;

    function setEmergencyAdmin(address _emergencyAdmin) external;

    function setPerformanceFee(uint16 _performanceFee) external;

    function setPerformanceFeeRecipient(
        address _performanceFeeRecipient
    ) external;

    function setProfitMaxUnlockTime(uint256 _profitMaxUnlockTime) external;

    function setName(string calldata _newName) external;

    function shutdownStrategy() external;

    function emergencyWithdraw(uint256 _amount) external;
}
IBaseStrategy.sol 30 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

interface IBaseStrategy {
    function tokenizedStrategyAddress() external view returns (address);

    /*//////////////////////////////////////////////////////////////
                            IMMUTABLE FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    function availableDepositLimit(
        address _owner
    ) external view returns (uint256);

    function availableWithdrawLimit(
        address _owner
    ) external view returns (uint256);

    function deployFunds(uint256 _assets) external;

    function freeFunds(uint256 _amount) external;

    function harvestAndReport() external returns (uint256);

    function tendThis(uint256 _totalIdle) external;

    function shutdownWithdraw(uint256 _amount) external;

    function tendTrigger() external view returns (bool, bytes memory);
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
IBaseSwapper.sol 6 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

interface IBaseSwapper {
    function minAmountToSell() external view returns (uint256);
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

Read Contract

LEGACY_REPORT_TRIGGER 0x3c78e45d → address
acceptableBaseFee 0xc5869033 → uint256
auctionTrigger 0x8cc086a3 → bool, bytes
baseFeeProvider 0x47003cb7 → address
customAuctionTrigger 0x2b3d1ab3 → address
customStrategyBaseFee 0x503fa78d → uint256
customStrategyTrigger 0x1627cea8 → address
customVaultBaseFee 0x4ff5363e → uint256
customVaultTrigger 0x9fb092df → address
defaultAuctionTrigger 0x52f4387b → bool, bytes
defaultStrategyReportTrigger 0x10fcd40d → bool, bytes
defaultVaultReportTrigger 0xf6ea6b6c → bool, bytes
getCurrentBaseFee 0xa365dfaf → uint256
governance 0x5aa6e675 → address
isCurrentBaseFeeAcceptable 0x34a9e75c → bool
minimumAmountToKick 0x7c4b8b2d → uint256
name 0x06fdde03 → string
strategyReportTrigger 0xbb23fd8f → bool, bytes
strategyTendTrigger 0xc8e9cb87 → bool, bytes
vaultReportTrigger 0x907a3aa3 → bool, bytes

Write Contract 9 functions

These functions modify contract state and require a wallet transaction to execute.

setAcceptableBaseFee 0x8b3c9668
uint256 _newAcceptableBaseFee
setBaseFeeProvider 0x244edd79
address _baseFeeProvider
setCustomAuctionTrigger 0x01e7e910
address _strategy
address _trigger
setCustomStrategyBaseFee 0xd2898834
address _strategy
uint256 _baseFee
setCustomStrategyTrigger 0xdc7cc1ef
address _strategy
address _trigger
setCustomVaultBaseFee 0x53776861
address _vault
address _strategy
uint256 _baseFee
setCustomVaultTrigger 0x92ab7cfb
address _vault
address _strategy
address _trigger
setMinimumAmountToKick 0xdfce5b51
address _strategy
address _token
uint256 _amount
transferGovernance 0xd38bfff4
address _newGovernance

Recent Transactions

No transactions found for this address