Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xf156D2F6726E3231dd94dD9CB2e86D9A85A38d18
Balance 0 ETH
Nonce 1
Code Size 10682 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

10682 bytes
0x608060405234801561001057600080fd5b50600436106101515760003560e01c80638c04166f116100cd578063b51609b411610081578063e43581b811610066578063e43581b8146103b9578063edf0ef03146103cc578063ee565a63146103df57600080fd5b8063b51609b414610304578063c5e6d5ea1461031757600080fd5b80639a49e83d116100b25780639a49e83d146102cb5780639ae78486146102de578063b4a0bdf3146102f157600080fd5b80638c04166f1461027357806396d64879146102a857600080fd5b8063641bd503116101245780637c70b002116101095780637c70b0021461023a5780637ee843491461024d5780638195001d1461026057600080fd5b8063641bd503146101e75780637239d2b91461021357600080fd5b80630c5abe8014610156578063184b949b1461019c5780632b1da9cf146101b1578063521d4de9146101c4575b600080fd5b61017f610164366004612326565b6035602052600090815260409020546001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6101af6101aa366004612341565b610406565b005b6101af6101bf36600461236f565b61049b565b6101d76101d2366004612326565b61055f565b6040519015158152602001610193565b6101fa6101f5366004612326565b6105d5565b6040805160ff9093168352602083019190915201610193565b61017f7f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d013781565b6101af6102483660046123a2565b610660565b6101af61025b366004612326565b610865565b6101af61026e366004612326565b61096d565b60325461028b906bffffffffffffffffffffffff1681565b6040516bffffffffffffffffffffffff9091168152602001610193565b6101d76102b6366004612326565b60346020526000908152604090205460ff1681565b6101af6102d93660046123e2565b6109bb565b6101af6102ec366004612460565b610a5a565b60005461017f906001600160a01b031681565b6101af610312366004612497565b610b73565b610378610325366004612326565b603360205260009081526040902080546001909101546001600160a01b0382169167ffffffffffffffff600160a01b90910481169180821691680100000000000000008204811691600160801b90041685565b604080516001600160a01b03909616865267ffffffffffffffff9485166020870152928416928501929092528216606084015216608082015260a001610193565b6101d76103c7366004612326565b610c5f565b6101af6103da3660046124d3565b610cab565b61017f7f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c6327481565b60005460405163521d4de960e01b81523360048201526001600160a01b039091169063521d4de990602401602060405180830381865afa15801561044e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610472919061255d565b61048f57604051632678482f60e21b815260040160405180910390fd5b61049881610e63565b50565b60005460405163521d4de960e01b81523360048201526001600160a01b039091169063521d4de990602401602060405180830381865afa1580156104e3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610507919061255d565b61052457604051632678482f60e21b815260040160405180910390fd5b6001600160a01b039182166000908152603560205260409020805473ffffffffffffffffffffffffffffffffffffffff191691909216179055565b6000805460405163521d4de960e01b81526001600160a01b0384811660048301529091169063521d4de9906024015b602060405180830381865afa1580156105ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cf919061255d565b92915050565b6001600160a01b038181166000908152603360209081526040808320815160a08101835281549586168152600160a01b90950467ffffffffffffffff90811693860193909352600101548083169185019190915268010000000000000000810482166060850152600160801b9004166080830152908190610657908490610ec2565b91509150915091565b3360009081526034602052604090205460ff1661069057604051636115324760e11b815260040160405180910390fd5b60405163072d137f60e21b81526001600160a01b0383811660048301527f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d01371690631cb44dfc90602401600060405180830381600087803b1580156106f357600080fd5b505af1925050508015610704575060015b50610730827f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d013783611166565b6040516301db50ff60e51b8152600481018290526000602482018190526001600160a01b0384811660448401527f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c63274811660648401523060848401524260a484015290917f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d013790911690633b6a1fe09060c4016020604051808303816000875af11580156107e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610804919061257f565b905060006001600160a01b038416733ee320c9f73a84d1717557af00695a34b26d1f1d1461083357600061084f565b6001600160a01b03808516600090815260356020526040902054165b905061085f838386846001611205565b50505050565b60005460405163521d4de960e01b81523360048201526001600160a01b039091169063521d4de990602401602060405180830381865afa1580156108ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108d1919061255d565b6108ee57604051632678482f60e21b815260040160405180910390fd5b6001600160a01b03811660008181526034602090815260409182902054825193845260ff161515908301527f7628ea5f6112a16b36a8239aa208395a8e8f221688cfb3a5461faffb9700abcd910160405180910390a16001600160a01b03166000908152603460205260409020805460ff19811660ff90911615179055565b6001600160a01b03811660009081526033602052604090206001810154600160801b900467ffffffffffffffff166002036109b75780546109b7906001600160a01b0316826114d1565b5050565b60005460405163521d4de960e01b81523360048201526001600160a01b039091169063521d4de990602401602060405180830381865afa158015610a03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a27919061255d565b610a4457604051632678482f60e21b815260040160405180910390fd5b610a52868686868686611738565b505050505050565b3360009081526034602052604090205460ff16158015610ae3575060005460405163521d4de960e01b81523360048201526001600160a01b039091169063521d4de990602401602060405180830381865afa158015610abd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae1919061255d565b155b15610b1a576040517f0dcc030f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b039091166000908152603360205260409020805467ffffffffffffffff909216600160a01b027fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff909216919091179055565b60005460405163521d4de960e01b81523360048201526001600160a01b039091169063521d4de990602401602060405180830381865afa158015610bbb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bdf919061255d565b610bfc57604051632678482f60e21b815260040160405180910390fd5b604080516001600160a01b0385811682526020820185905283168183015290517fb197f0a554c4d7840105e6ae65f0e275e9e8605a969dffa8caa7f1f118a2e1f59181900360600190a1610c5a6001600160a01b03841682846118ff565b505050565b600080546040517fe43581b80000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301529091169063e43581b89060240161058e565b3360009081526034602052604090205460ff16610cdb57604051636115324760e11b815260040160405180910390fd5b633b9aca00831115610d0057604051633494a40d60e21b815260040160405180910390fd5b6001600160a01b038481166000908152603360209081526040808320815160a08101835281549586168152600160a01b90950467ffffffffffffffff90811693860193909352600101548083169185019190915268010000000000000000810482166060850152600160801b900416608083015280610d7f8784610ec2565b9092509050633b9aca00610d9387836125ae565b610d9d91906125c5565b905080600003610dd9576040517f1f2a200500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405163072d137f60e21b81526001600160a01b0388811660048301527f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d01371690631cb44dfc90602401600060405180830381600087803b158015610e3c57600080fd5b505af1925050508015610e4d575060015b50610e5a828885846119a8565b50505050505050565b633b9aca00816bffffffffffffffffffffffff161115610e9657604051633494a40d60e21b815260040160405180910390fd5b603280546bffffffffffffffffffffffff19166bffffffffffffffffffffffff92909216919091179055565b604051634a71aecf60e11b81526001600160a01b0383811660048301526000918291829182917f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d013716906394e35d9e906024016040805180830381865afa158015610f30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f5491906125e7565b8651604051634a71aecf60e11b81526001600160a01b0391821660048201529294509092506000917f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d0137909116906394e35d9e906024016040805180830381865afa158015610fc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fea91906125e7565b509050600082876020015167ffffffffffffffff1661100991906125ae565b90508061101a85633b9aca006125ae565b11156110b75761102e633b9aca00826125c5565b611038908561260b565b9450600083886040015167ffffffffffffffff1661105691906125ae565b90508061106784633b9aca006125ae565b111561107657600095506110b1565b80611081878561261e565b61108f90633b9aca006125ae565b11156110b157826110a4633b9aca00836125c5565b6110ae919061260b565b95505b5061115b565b60019550836110ca633b9aca00836125c5565b6110d4919061260b565b9450600083886060015167ffffffffffffffff166110f291906125ae565b90508061110384633b9aca006125ae565b10156111125760009550611159565b61112086633b9aca006125ae565b61112a908261261e565b61113884633b9aca006125ae565b10156111595761114c633b9aca00826125c5565b611156908461260b565b95505b505b505050509250929050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa1580156111b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111da919061257f565b90508181101561085f5761085f836111f48360001961260b565b6001600160a01b0387169190611efd565b611276836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611246573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061126a9190612631565b60ff1660128784611fc8565b945060006001600160a01b03841673a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4814806112c157506001600160a01b0384167359d9356e565ab3a36dd77763fc0d87feaf85508c145b806112e857506001600160a01b038416731abaea1f7c830bd89acc67ec4af516284b1bc33c145b8061132457507f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c632746001600160a01b0316846001600160a01b0316145b1561133c576113338686612060565b91506114699050565b733ee320c9f73a84d1717557af00695a34b26d1f1c196001600160a01b038516016114505781156113dc576040516303d1689d60e11b8152600481018790526113339086906001600160a01b038616906307a2d13a90602401602060405180830381865afa1580156113b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113d6919061257f565b90612060565b6040516303d1689d60e11b815260048101869052611333906001600160a01b038516906307a2d13a90602401602060405180830381865afa158015611425573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611449919061257f565b8790612060565b604051633494a40d60e21b815260040160405180910390fd5b60008661147a83633b9aca006125ae565b61148491906125c5565b6032549091506bffffffffffffffffffffffff16811115610e5a576040517f850c6f7600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fb85780bc0000000000000000000000000000000000000000000000000000000081526001600160a01b0383811660048301526060917f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d01379091169063b85780bc90602401600060405180830381865afa158015611555573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261157d919081019061273b565b508051909150600181116115a95760018301805467ffffffffffffffff1916633b9aca001790556115f8565b816115b560028361260b565b815181106115c5576115c5612808565b60200260200101518360010160006101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055505b6040517f847da7be0000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526060917f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d01379091169063847da7be90602401600060405180830381865afa15801561167c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526116a4919081019061273b565b50805192509050600182116116e2576001840180547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff169055611731565b806116ee60028461260b565b815181106116fe576116fe612808565b60200260200101518460010160086101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055505b5050505050565b6001600160a01b038681166000908152603360205260409020805473ffffffffffffffffffffffffffffffffffffffff1916918716919091178155633b9aca0067ffffffffffffffff8616106117a157604051633494a40d60e21b815260040160405180910390fd5b80547fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff16600160a01b67ffffffffffffffff87811691909102919091178255600180830180547fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff16600160801b938616938402179055036118b857633b9aca008367ffffffffffffffff1610158061184d57508267ffffffffffffffff168467ffffffffffffffff1610155b1561186b57604051633494a40d60e21b815260040160405180910390fd5b60018101805467ffffffffffffffff86811668010000000000000000027fffffffffffffffffffffffffffffffff0000000000000000000000000000000090921690861617179055610e5a565b6001810180547fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff16700200000000000000000000000000000000179055610e5a86826114d1565b6040516001600160a01b038316602482015260448101829052610c5a9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152612086565b6119f37f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c632747f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d013783611166565b6001600160a01b038084166000908152603560205260409020541660ff8516600103611d315782516040516301db50ff60e51b8152600481018490526000602482018190526001600160a01b037f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c632748116604484015292831660648301523060848301524260a4830152917f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d01371690633b6a1fe09060c4016020604051808303816000875af1158015611ac8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611aec919061257f565b9050733ee320c9f73a84d1717557af00695a34b26d1f1c196001600160a01b03861601611cde578351611b20908383611166565b6040517f6e553f65000000000000000000000000000000000000000000000000000000008152600481018290523060248201526000906001600160a01b03841690636e553f659060440160408051808303816000875af1158015611b88573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bac91906125e7565b509050611bda867f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d013783611166565b6040516301db50ff60e51b815260048101829052600060248201526001600160a01b0387811660448301527f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c63274811660648301523060848301524260a48301527f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d01371690633b6a1fe09060c4016020604051808303816000875af1158015611c84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ca8919061257f565b9150611cd884837f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c63274866000611205565b50611d2b565b7359d9356e565ab3a36dd77763fc0d87feaf85508b196001600160a01b03861601611d2b578351611d19906001600160a01b031683836118ff565b611d2b83828660000151856000611205565b50611731565b6040516301db50ff60e51b8152600481018390526000602482018190526001600160a01b037f0000000000000000000000000000206329b97db379d5e1bf586bbdb969c632748116604484015286811660648401523060848401524260a484015290917f000000000000000000000000222222fd79264bbe280b4986f6fefbc3524d013790911690633b6a1fe09060c4016020604051808303816000875af1158015611de1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e05919061257f565b9050611e15838287856000611205565b733ee320c9f73a84d1717557af00695a34b26d1f1c196001600160a01b03861601611ec4576040517faa2f892d000000000000000000000000000000000000000000000000000000008152600481018290526001600160a01b0383169063aa2f892d906024016020604051808303816000875af1158015611e9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ebe919061257f565b50610a52565b7359d9356e565ab3a36dd77763fc0d87feaf85508b196001600160a01b03861601610a5257610a526001600160a01b03861683836118ff565b604051636eb1769f60e11b81523060048201526001600160a01b038381166024830152600091839186169063dd62ed3e90604401602060405180830381865afa158015611f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f72919061257f565b611f7c919061261e565b6040516001600160a01b03851660248201526044810182905290915061085f9085907f095ea7b30000000000000000000000000000000000000000000000000000000090606401611944565b60008385111561201d578115611ffe57611fe2848661260b565b611fed90600a612905565b611ff790846125c5565b9250612057565b612008848661260b565b61201390600a612905565b611ff790846125ae565b8385101561205757811561203557612008858561260b565b61203f858561260b565b61204a90600a612905565b61205490846125c5565b92505b50909392505050565b600080838311156120765750600090508061207f565b50600190508183035b9250929050565b60006120db826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121709092919063ffffffff16565b805190915015610c5a57808060200190518101906120f9919061255d565b610c5a5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f7420737563636565640000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b606061217f8484600085612189565b90505b9392505050565b6060824710156122015760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401612167565b6001600160a01b0385163b6122585760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401612167565b600080866001600160a01b031685876040516122749190612935565b60006040518083038185875af1925050503d80600081146122b1576040519150601f19603f3d011682016040523d82523d6000602084013e6122b6565b606091505b50915091506122c68282866122d1565b979650505050505050565b606083156122e0575081612182565b8251156122f05782518084602001fd5b8160405162461bcd60e51b81526004016121679190612951565b80356001600160a01b038116811461232157600080fd5b919050565b60006020828403121561233857600080fd5b6121828261230a565b60006020828403121561235357600080fd5b81356bffffffffffffffffffffffff8116811461218257600080fd5b6000806040838503121561238257600080fd5b61238b8361230a565b91506123996020840161230a565b90509250929050565b600080604083850312156123b557600080fd5b6123be8361230a565b946020939093013593505050565b67ffffffffffffffff8116811461049857600080fd5b60008060008060008060c087890312156123fb57600080fd5b6124048761230a565b95506124126020880161230a565b94506040870135612422816123cc565b93506060870135612432816123cc565b92506080870135612442816123cc565b915060a0870135612452816123cc565b809150509295509295509295565b6000806040838503121561247357600080fd5b61247c8361230a565b9150602083013561248c816123cc565b809150509250929050565b6000806000606084860312156124ac57600080fd5b6124b58461230a565b9250602084013591506124ca6040850161230a565b90509250925092565b600080600080606085870312156124e957600080fd5b6124f28561230a565b935060208501359250604085013567ffffffffffffffff81111561251557600080fd5b8501601f8101871361252657600080fd5b803567ffffffffffffffff81111561253d57600080fd5b87602082840101111561254f57600080fd5b949793965060200194505050565b60006020828403121561256f57600080fd5b8151801515811461218257600080fd5b60006020828403121561259157600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176105cf576105cf612598565b6000826125e257634e487b7160e01b600052601260045260246000fd5b500490565b600080604083850312156125fa57600080fd5b505080516020909101519092909150565b818103818111156105cf576105cf612598565b808201808211156105cf576105cf612598565b60006020828403121561264357600080fd5b815160ff8116811461218257600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561269357612693612654565b604052919050565b600067ffffffffffffffff8211156126b5576126b5612654565b5060051b60200190565b600082601f8301126126d057600080fd5b81516126e36126de8261269b565b61266a565b8082825260208201915060208360051b86010192508583111561270557600080fd5b602085015b838110156127315780518060070b811461272357600080fd5b83526020928301920161270a565b5095945050505050565b6000806040838503121561274e57600080fd5b825167ffffffffffffffff81111561276557600080fd5b8301601f8101851361277657600080fd5b80516127846126de8261269b565b8082825260208201915060208360051b8501019250878311156127a657600080fd5b6020840193505b828410156127d15783516127c0816123cc565b8252602093840193909101906127ad565b80955050505050602083015167ffffffffffffffff8111156127f257600080fd5b6127fe858286016126bf565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b6001815b60018411156128595780850481111561283d5761283d612598565b600184161561284b57908102905b60019390931c928002612822565b935093915050565b600082612870575060016105cf565b8161287d575060006105cf565b8160018114612893576002811461289d576128b9565b60019150506105cf565b60ff8411156128ae576128ae612598565b50506001821b6105cf565b5060208310610133831016604e8410600b84101617156128dc575081810a6105cf565b6128e9600019848461281e565b80600019048211156128fd576128fd612598565b029392505050565b60006121828383612861565b60005b8381101561292c578181015183820152602001612914565b50506000910152565b60008251612947818460208701612911565b9190910192915050565b6020815260008251806020840152612970816040850160208701612911565b601f01601f1916919091016040019291505056fea2646970667358221220c3e3f359795c28f1e7697ada0f1e99018738b21a10151f0623d658045b53277964736f6c634300081a0033

Verified Source Code Partial Match

Compiler: v0.8.26+commit.8a97fa7a EVM: paris Optimization: Yes (1000 runs)
MultiBlockHarvester.sol 186 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.23;

import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IAccessControlManager } from "../utils/AccessControl.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { BaseHarvester, YieldBearingParams } from "./BaseHarvester.sol";
import { ITransmuter } from "../interfaces/ITransmuter.sol";
import { IAgToken } from "../interfaces/IAgToken.sol";
import { IPool } from "../interfaces/IPool.sol";
import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "../utils/Errors.sol";
import "../utils/Constants.sol";

/// @title MultiBlockHarvester
/// @author Angle Labs, Inc.
/// @dev Contract to harvest yield from multiple yield bearing assets in multiple blocks transactions
contract MultiBlockHarvester is BaseHarvester {
    using SafeERC20 for IERC20;
    using SafeMath for uint256;

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                       VARIABLES
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /// @notice address to deposit to receive yieldBearingAsset
    mapping(address => address) public yieldBearingToDepositAddress;

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                       CONSTRUCTOR
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    constructor(
        uint96 initialMaxSlippage,
        IAccessControlManager definitiveAccessControlManager,
        IAgToken definitiveAgToken,
        ITransmuter definitiveTransmuter
    ) BaseHarvester(initialMaxSlippage, definitiveAccessControlManager, definitiveAgToken, definitiveTransmuter) {}

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        GUARDIAN FUNCTIONS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /**
     * @notice Set the deposit address for a yieldBearingAsset
     * @param yieldBearingAsset address of the yieldBearingAsset
     * @param newDepositAddress address to deposit to receive yieldBearingAsset
     */
    function setYieldBearingToDepositAddress(
        address yieldBearingAsset,
        address newDepositAddress
    ) external onlyGuardian {
        yieldBearingToDepositAddress[yieldBearingAsset] = newDepositAddress;
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        TRUSTED FUNCTIONS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /**
     * @notice Initiate a rebalance
     * @param scale scale to apply to the rebalance amount
     * @param yieldBearingAsset address of the yieldBearingAsset
     */
    function harvest(address yieldBearingAsset, uint256 scale, bytes calldata) external onlyTrusted {
        if (scale > 1e9) revert InvalidParam();
        YieldBearingParams memory yieldBearingInfo = yieldBearingData[yieldBearingAsset];
        (uint8 increase, uint256 amount) = _computeRebalanceAmount(yieldBearingAsset, yieldBearingInfo);
        amount = (amount * scale) / 1e9;
        if (amount == 0) revert ZeroAmount();

        try transmuter.updateOracle(yieldBearingAsset) {} catch {}
        _rebalance(increase, yieldBearingAsset, yieldBearingInfo, amount);
    }

    /**
     * @notice Finalize a rebalance
     * @param yieldBearingAsset address of the yieldBearingAsset
     */
    function finalizeRebalance(address yieldBearingAsset, uint256 balance) external onlyTrusted {
        try transmuter.updateOracle(yieldBearingAsset) {} catch {}
        _adjustAllowance(yieldBearingAsset, address(transmuter), balance);
        uint256 amountOut = transmuter.swapExactInput(
            balance,
            0,
            yieldBearingAsset,
            address(agToken),
            address(this),
            block.timestamp
        );
        address depositAddress = yieldBearingAsset == XEVT
            ? yieldBearingToDepositAddress[yieldBearingAsset]
            : address(0);
        _checkSlippage(balance, amountOut, yieldBearingAsset, depositAddress, true);
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        INTERNAL FUNCTIONS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    function _rebalance(
        uint8 typeAction,
        address yieldBearingAsset,
        YieldBearingParams memory yieldBearingInfo,
        uint256 amount
    ) internal {
        _adjustAllowance(address(agToken), address(transmuter), amount);
        address depositAddress = yieldBearingToDepositAddress[yieldBearingAsset];
        if (typeAction == 1) {
            uint256 amountOut = transmuter.swapExactInput(
                amount,
                0,
                address(agToken),
                yieldBearingInfo.asset,
                address(this),
                block.timestamp
            );
            if (yieldBearingAsset == XEVT) {
                _adjustAllowance(yieldBearingInfo.asset, address(depositAddress), amountOut);
                (uint256 shares, ) = IPool(depositAddress).deposit(amountOut, address(this));
                _adjustAllowance(yieldBearingAsset, address(transmuter), shares);
                amountOut = transmuter.swapExactInput(
                    shares,
                    0,
                    yieldBearingAsset,
                    address(agToken),
                    address(this),
                    block.timestamp
                );
                _checkSlippage(amount, amountOut, address(agToken), depositAddress, false);
            } else if (yieldBearingAsset == USDM) {
                IERC20(yieldBearingInfo.asset).safeTransfer(depositAddress, amountOut);
                _checkSlippage(amount, amountOut, yieldBearingInfo.asset, depositAddress, false);
            }
        } else {
            uint256 amountOut = transmuter.swapExactInput(
                amount,
                0,
                address(agToken),
                yieldBearingAsset,
                address(this),
                block.timestamp
            );
            _checkSlippage(amount, amountOut, yieldBearingAsset, depositAddress, false);
            if (yieldBearingAsset == XEVT) {
                IPool(depositAddress).requestRedeem(amountOut);
            } else if (yieldBearingAsset == USDM) {
                IERC20(yieldBearingAsset).safeTransfer(depositAddress, amountOut);
            }
        }
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        HELPER                                                      
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    function _checkSlippage(
        uint256 amountIn,
        uint256 amountOut,
        address asset,
        address depositAddress,
        bool assetIn
    ) internal view {
        // Divide or multiply the amountIn to match the decimals of the asset
        amountIn = _scaleAmountBasedOnDecimals(IERC20Metadata(asset).decimals(), 18, amountIn, assetIn);

        uint256 result;
        if (asset == USDC || asset == USDM || asset == EURC || asset == address(agToken)) {
            // Assume 1:1 ratio between stablecoins
            (, result) = amountIn.trySub(amountOut);
        } else if (asset == XEVT) {
            // Assume 1:1 ratio between the underlying asset of the vault
            if (assetIn) {
                (, result) = IPool(depositAddress).convertToAssets(amountIn).trySub(amountOut);
            } else {
                (, result) = amountIn.trySub(IPool(depositAddress).convertToAssets(amountOut));
            }
        } else revert InvalidParam();

        uint256 slippage = (result * 1e9) / amountIn;
        if (slippage > maxSlippage) revert SlippageTooHigh();
    }
}
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);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
AccessControl.sol 46 lines
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.19;

import { IAccessControlManager } from "interfaces/IAccessControlManager.sol";

import "../utils/Errors.sol";

/// @title AccessControl
/// @author Angle Labs, Inc.
contract AccessControl {
    /// @notice `accessControlManager` used to check roles
    IAccessControlManager public accessControlManager;

    uint256[49] private __gapAccessControl;

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                       MODIFIERS                                                    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /// @notice Checks whether the `msg.sender` has the governor role
    modifier onlyGovernor() {
        if (!accessControlManager.isGovernor(msg.sender)) revert NotGovernor();
        _;
    }

    /// @notice Checks whether the `msg.sender` has the guardian role
    modifier onlyGuardian() {
        if (!accessControlManager.isGovernorOrGuardian(msg.sender)) revert NotGovernorOrGuardian();
        _;
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                       FUNCTIONS                                                    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /// @notice Checks whether `admin` has the governor role
    function isGovernor(address admin) external view returns (bool) {
        return accessControlManager.isGovernor(admin);
    }

    /// @notice Checks whether `admin` has the guardian role
    function isGovernorOrGuardian(address admin) external view returns (bool) {
        return accessControlManager.isGovernorOrGuardian(admin);
    }
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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);
}
BaseHarvester.sol 300 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.23;

import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { AccessControl, IAccessControlManager } from "../utils/AccessControl.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ITransmuter } from "../interfaces/ITransmuter.sol";
import { IAgToken } from "../interfaces/IAgToken.sol";

import "../utils/Errors.sol";
import "../interfaces/IHarvester.sol";

struct YieldBearingParams {
    // Address of the asset used to mint the yield bearing asset
    address asset;
    // Target exposure to the collateral yield bearing asset used
    uint64 targetExposure;
    // Maximum exposure within the Transmuter to the deposit asset
    uint64 maxExposure;
    // Minimum exposure within the Transmuter to the deposit asset
    uint64 minExposure;
    // Whether limit exposures should be overriden or read onchain through the Transmuter
    // This value should be 1 to override exposures or 2 if these shouldn't be overriden
    uint64 overrideExposures;
}

/// @title BaseHarvester
/// @author Angle Labs, Inc.
/// @dev Abstract contract for a harvester that aims at rebalancing a Transmuter
abstract contract BaseHarvester is IHarvester, AccessControl {
    using SafeERC20 for IERC20;

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                       MODIFIERS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /**
     * @notice Checks whether the `msg.sender` is trusted to update
     * target exposure and do others non critical operations
     */
    modifier onlyTrusted() {
        if (!isTrusted[msg.sender]) revert NotTrusted();
        _;
    }

    /**
     * @notice Checks whether the `msg.sender` is trusted or guardian to update
     * target exposure and do others non critical operations
     */
    modifier onlyTrustedOrGuardian() {
        if (!isTrusted[msg.sender] && !accessControlManager.isGovernorOrGuardian(msg.sender))
            revert NotTrustedOrGuardian();
        _;
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                       VARIABLES
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /// @notice Reference to the `transmuter` implementation this contract aims at rebalancing
    ITransmuter public immutable transmuter;
    /// @notice AgToken handled by the `transmuter` of interest
    IAgToken public immutable agToken;
    /// @notice Max slippage when dealing with the Transmuter
    uint96 public maxSlippage;
    /// @notice Data associated to a yield bearing asset
    mapping(address => YieldBearingParams) public yieldBearingData;
    /// @notice trusted addresses that can update target exposure and do others non critical operations
    mapping(address => bool) public isTrusted;

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        EVENTS                                                      
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    event Recovered(address token, uint256 amount, address to);
    event TrustedToggled(address trusted, bool status);

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                       CONSTRUCTOR
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    constructor(
        uint96 initialMaxSlippage,
        IAccessControlManager definitiveAccessControlManager,
        IAgToken definitiveAgToken,
        ITransmuter definitiveTransmuter
    ) {
        _setMaxSlippage(initialMaxSlippage);
        accessControlManager = definitiveAccessControlManager;
        agToken = definitiveAgToken;
        transmuter = definitiveTransmuter;
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        GUARDIAN FUNCTIONS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /**
     * @notice Set the yieldBearingAsset data
     * @param yieldBearingAsset address of the yieldBearingAsset
     * @param asset address of the asset
     * @param targetExposure target exposure to the yieldBearingAsset asset used
     * @param minExposure minimum exposure within the Transmuter to the asset
     * @param maxExposure maximum exposure within the Transmuter to the asset
     * @param overrideExposures whether limit exposures should be overriden or read onchain through the Transmuter
     */
    function setYieldBearingAssetData(
        address yieldBearingAsset,
        address asset,
        uint64 targetExposure,
        uint64 minExposure,
        uint64 maxExposure,
        uint64 overrideExposures
    ) external onlyGuardian {
        _setYieldBearingAssetData(
            yieldBearingAsset,
            asset,
            targetExposure,
            minExposure,
            maxExposure,
            overrideExposures
        );
    }

    /**
     * @notice Set the limit exposures to the asset linked to the yield bearing asset
     * @param yieldBearingAsset address of the yield bearing asset
     */
    function updateLimitExposuresYieldAsset(address yieldBearingAsset) public virtual {
        YieldBearingParams storage yieldBearingInfo = yieldBearingData[yieldBearingAsset];
        if (yieldBearingInfo.overrideExposures == 2)
            _updateLimitExposuresYieldAsset(yieldBearingInfo.asset, yieldBearingInfo);
    }

    /**
     * @notice Set the max allowed slippage
     * @param newMaxSlippage new max allowed slippage
     */
    function setMaxSlippage(uint96 newMaxSlippage) external onlyGuardian {
        _setMaxSlippage(newMaxSlippage);
    }

    /**
     * @notice Toggle the trusted status of an address
     * @param trusted address to toggle the trusted status
     */
    function toggleTrusted(address trusted) external onlyGuardian {
        emit TrustedToggled(trusted, isTrusted[trusted]);
        isTrusted[trusted] = !isTrusted[trusted];
    }

    /**
     * @notice Recover ERC20 tokens
     * @param tokenAddress address of the token to recover
     * @param amountToRecover amount to recover
     * @param to address to send the recovered tokens
     */
    function recoverERC20(address tokenAddress, uint256 amountToRecover, address to) external onlyGuardian {
        emit Recovered(tokenAddress, amountToRecover, to);
        IERC20(tokenAddress).safeTransfer(to, amountToRecover);
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        TRUSTED FUNCTIONS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /**
     * @notice Set the target exposure of a yield bearing asset
     * @param yieldBearingAsset address of the yield bearing asset
     * @param targetExposure target exposure to the yield bearing asset used
     */
    function setTargetExposure(address yieldBearingAsset, uint64 targetExposure) external onlyTrustedOrGuardian {
        yieldBearingData[yieldBearingAsset].targetExposure = targetExposure;
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        VIEW FUNCTIONS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /**
     * @notice Compute the amount needed to rebalance the Transmuter
     * @param yieldBearingAsset address of the yield bearing asset
     * @return increase whether the exposure should be increased
     * @return amount amount to be rebalanced
     */
    function computeRebalanceAmount(address yieldBearingAsset) external view returns (uint8 increase, uint256 amount) {
        return _computeRebalanceAmount(yieldBearingAsset, yieldBearingData[yieldBearingAsset]);
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        INTERNAL FUNCTIONS
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    function _computeRebalanceAmount(
        address yieldBearingAsset,
        YieldBearingParams memory yieldBearingInfo
    ) internal view returns (uint8 increase, uint256 amount) {
        (uint256 stablecoinsFromYieldBearingAsset, uint256 stablecoinsIssued) = transmuter.getIssuedByCollateral(
            yieldBearingAsset
        );
        (uint256 stablecoinsFromAsset, ) = transmuter.getIssuedByCollateral(yieldBearingInfo.asset);
        uint256 targetExposureScaled = yieldBearingInfo.targetExposure * stablecoinsIssued;
        if (stablecoinsFromYieldBearingAsset * 1e9 > targetExposureScaled) {
            // Need to decrease exposure to yield bearing asset
            amount = stablecoinsFromYieldBearingAsset - targetExposureScaled / 1e9;
            uint256 maxValueScaled = yieldBearingInfo.maxExposure * stablecoinsIssued;
            // These checks assume that there are no transaction fees on the stablecoin->collateral conversion and so
            // it's still possible that exposure goes above the max exposure in some rare cases
            if (stablecoinsFromAsset * 1e9 > maxValueScaled) amount = 0;
            else if ((stablecoinsFromAsset + amount) * 1e9 > maxValueScaled)
                amount = maxValueScaled / 1e9 - stablecoinsFromAsset;
        } else {
            // In this case, exposure after the operation might remain slightly below the targetExposure as less
            // collateral may be obtained by burning stablecoins for the yield asset and unwrapping it
            increase = 1;
            amount = targetExposureScaled / 1e9 - stablecoinsFromYieldBearingAsset;
            uint256 minValueScaled = yieldBearingInfo.minExposure * stablecoinsIssued;
            if (stablecoinsFromAsset * 1e9 < minValueScaled) amount = 0;
            else if (stablecoinsFromAsset * 1e9 < minValueScaled + amount * 1e9)
                amount = stablecoinsFromAsset - minValueScaled / 1e9;
        }
    }

    function _setYieldBearingAssetData(
        address yieldBearingAsset,
        address asset,
        uint64 targetExposure,
        uint64 minExposure,
        uint64 maxExposure,
        uint64 overrideExposures
    ) internal virtual {
        YieldBearingParams storage yieldBearingInfo = yieldBearingData[yieldBearingAsset];
        yieldBearingInfo.asset = asset;
        if (targetExposure >= 1e9) revert InvalidParam();
        yieldBearingInfo.targetExposure = targetExposure;
        yieldBearingInfo.overrideExposures = overrideExposures;
        if (overrideExposures == 1) {
            if (maxExposure >= 1e9 || minExposure >= maxExposure) revert InvalidParam();
            yieldBearingInfo.maxExposure = maxExposure;
            yieldBearingInfo.minExposure = minExposure;
        } else {
            yieldBearingInfo.overrideExposures = 2;
            _updateLimitExposuresYieldAsset(asset, yieldBearingInfo);
        }
    }

    function _updateLimitExposuresYieldAsset(
        address asset,
        YieldBearingParams storage yieldBearingInfo
    ) internal virtual {
        uint64[] memory xFeeMint;
        (xFeeMint, ) = transmuter.getCollateralMintFees(asset);
        uint256 length = xFeeMint.length;
        if (length <= 1) yieldBearingInfo.maxExposure = 1e9;
        else yieldBearingInfo.maxExposure = xFeeMint[length - 2];

        uint64[] memory xFeeBurn;
        (xFeeBurn, ) = transmuter.getCollateralBurnFees(asset);
        length = xFeeBurn.length;
        if (length <= 1) yieldBearingInfo.minExposure = 0;
        else yieldBearingInfo.minExposure = xFeeBurn[length - 2];
    }

    function _setMaxSlippage(uint96 newMaxSlippage) internal virtual {
        if (newMaxSlippage > 1e9) revert InvalidParam();
        maxSlippage = newMaxSlippage;
    }

    function _scaleAmountBasedOnDecimals(
        uint256 decimalsTokenIn,
        uint256 decimalsTokenOut,
        uint256 amountIn,
        bool assetIn
    ) internal pure returns (uint256) {
        if (decimalsTokenIn > decimalsTokenOut) {
            if (assetIn) {
                amountIn /= 10 ** (decimalsTokenIn - decimalsTokenOut);
            } else {
                amountIn *= 10 ** (decimalsTokenIn - decimalsTokenOut);
            }
        } else if (decimalsTokenIn < decimalsTokenOut) {
            if (assetIn) {
                amountIn *= 10 ** (decimalsTokenOut - decimalsTokenIn);
            } else {
                amountIn /= 10 ** (decimalsTokenOut - decimalsTokenIn);
            }
        }
        return amountIn;
    }

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        HELPER                                                      
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    function _adjustAllowance(address token, address sender, uint256 amountIn) internal {
        uint256 allowance = IERC20(token).allowance(address(this), sender);
        if (allowance < amountIn) IERC20(token).safeIncreaseAllowance(sender, type(uint256).max - allowance);
    }
}
ITransmuter.sol 61 lines
// SPDX-License-Identifier: GPL-3.0

/*
                      *                                                  █                              
                    *****                                               ▓▓▓                             
                      *                                               ▓▓▓▓▓▓▓                         
                                       *            ///.           ▓▓▓▓▓▓▓▓▓▓▓▓▓                       
                                     *****        ////////            ▓▓▓▓▓▓▓                          
                                       *       /////////////            ▓▓▓                             
                         ▓▓                  //////////////////          █         ▓▓                   
                       ▓▓  ▓▓             ///////////////////////                ▓▓   ▓▓                
                     ▓▓       ▓▓        ////////////////////////////           ▓▓        ▓▓              
                  ▓▓            ▓▓    /////////▓▓▓///////▓▓▓/////////       ▓▓             ▓▓            
                ▓▓                ,////////////////////////////////////// ▓▓                 ▓▓         
              ▓▓                 //////////////////////////////////////////                     ▓▓      
            ▓▓                //////////////////////▓▓▓▓/////////////////////                          
                           ,////////////////////////////////////////////////////                        
                        .//////////////////////////////////////////////////////////                     
                         .//////////////////////////██.,//////////////////////////█                     
                           .//////////////////////████..,./////////////////////██                       
                            ...////////////////███████.....,.////////////////███                        
                              ,.,////////////████████ ........,///////////████                          
                                .,.,//////█████████      ,.......///////████                            
                                   ,..//████████           ........./████                               
                                     ..,██████                .....,███                                 
                                        .██                     ,.,█                                    
                                                                                                    
                                                                                                    
                                                                                                    
                   ▓▓            ▓▓▓▓▓▓▓▓▓▓       ▓▓▓▓▓▓▓▓▓▓        ▓▓               ▓▓▓▓▓▓▓▓▓▓          
                 ▓▓▓▓▓▓          ▓▓▓    ▓▓▓       ▓▓▓               ▓▓               ▓▓   ▓▓▓▓         
               ▓▓▓    ▓▓▓        ▓▓▓    ▓▓▓       ▓▓▓    ▓▓▓        ▓▓               ▓▓▓▓▓             
              ▓▓▓        ▓▓      ▓▓▓    ▓▓▓       ▓▓▓▓▓▓▓▓▓▓        ▓▓▓▓▓▓▓▓▓▓       ▓▓▓▓▓▓▓▓▓▓          
*/

pragma solidity >=0.5.0;

import { IDiamondCut } from "./IDiamondCut.sol";
import { IDiamondEtherscan } from "./IDiamondEtherscan.sol";
import { IDiamondLoupe } from "./IDiamondLoupe.sol";
import { IGetters } from "./IGetters.sol";
import { IRedeemer } from "./IRedeemer.sol";
import { IRewardHandler } from "./IRewardHandler.sol";
import { ISettersGovernor, ISettersGuardian } from "./ISetters.sol";
import { ISwapper } from "./ISwapper.sol";

/// @title ITransmuter
/// @author Angle Labs, Inc.
interface ITransmuter is
    IDiamondCut,
    IDiamondEtherscan,
    IDiamondLoupe,
    IGetters,
    IRedeemer,
    IRewardHandler,
    ISettersGovernor,
    ISettersGuardian,
    ISwapper
{

}
IAgToken.sol 65 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

import { IERC20 } from "oz/token/ERC20/IERC20.sol";

/// @title IAgToken
/// @author Angle Labs, Inc.
/// @notice Interface for the stablecoins `AgToken` contracts
interface IAgToken is IERC20 {
    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                              MINTER ROLE ONLY FUNCTIONS                                            
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /// @notice Lets a whitelisted contract mint agTokens
    /// @param account Address to mint to
    /// @param amount Amount to mint
    function mint(address account, uint256 amount) external;

    /// @notice Burns `amount` tokens from a `burner` address after being asked to by `sender`
    /// @param amount Amount of tokens to burn
    /// @param burner Address to burn from
    /// @param sender Address which requested the burn from `burner`
    /// @dev This method is to be called by a contract with the minter right after being requested
    /// to do so by a `sender` address willing to burn tokens from another `burner` address
    /// @dev The method checks the allowance between the `sender` and the `burner`
    function burnFrom(uint256 amount, address burner, address sender) external;

    /// @notice Burns `amount` tokens from a `burner` address
    /// @param amount Amount of tokens to burn
    /// @param burner Address to burn from
    /// @dev This method is to be called by a contract with a minter right on the AgToken after being
    /// requested to do so by an address willing to burn tokens from its address
    function burnSelf(uint256 amount, address burner) external;

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                TREASURY ONLY FUNCTIONS                                             
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /// @notice Adds a minter in the contract
    /// @param minter Minter address to add
    /// @dev Zero address checks are performed directly in the `Treasury` contract
    function addMinter(address minter) external;

    /// @notice Removes a minter from the contract
    /// @param minter Minter address to remove
    /// @dev This function can also be called by a minter wishing to revoke itself
    function removeMinter(address minter) external;

    /// @notice Sets a new treasury contract
    /// @param _treasury New treasury address
    function setTreasury(address _treasury) external;

    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                  EXTERNAL FUNCTIONS                                                
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    /// @notice Checks whether an address has the right to mint agTokens
    /// @param minter Address for which the minting right should be checked
    /// @return Whether the address has the right to mint agTokens or not
    function isMinter(address minter) external view returns (bool);

    /// @notice Amount of decimals of the stablecoin
    function decimals() external view returns (uint8);
}
IPool.sol 13 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

interface IPool {
    function deposit(uint256 assets, address lender) external returns (uint256 shares, uint256 transferInDayTimestamp);

    function requestRedeem(uint256 shares) external returns (uint256 assets);

    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    function convertToShares(uint256 assets) external view returns (uint256 shares);
}
SafeMath.sol 227 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}
Errors.sol 48 lines
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.19;

error AlreadyAdded();
error CannotAddFunctionToDiamondThatAlreadyExists(bytes4 _selector);
error CannotAddSelectorsToZeroAddress(bytes4[] _selectors);
error CannotRemoveFunctionThatDoesNotExist(bytes4 _selector);
error CannotRemoveImmutableFunction(bytes4 _selector);
error CannotReplaceFunctionsFromFacetWithZeroAddress(bytes4[] _selectors);
error CannotReplaceFunctionThatDoesNotExists(bytes4 _selector);
error CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(bytes4 _selector);
error CannotReplaceImmutableFunction(bytes4 _selector);
error ContractHasNoCode();
error FunctionNotFound(bytes4 _functionSelector);
error IncorrectFacetCutAction(uint8 _action);
error InitializationFunctionReverted(address _initializationContractAddress, bytes _calldata);
error InvalidChainlinkRate();
error InvalidLengths();
error InvalidNegativeFees();
error InvalidOracleType();
error InvalidParam();
error InvalidParams();
error InvalidRate();
error InvalidSwap();
error InvalidTokens();
error ManagerHasAssets();
error NoSelectorsProvidedForFacetForCut(address _facetAddress);
error NotAllowed();
error NotCollateral();
error NotGovernor();
error NotGovernorOrGuardian();
error NotTrusted();
error NotTrustedOrGuardian();
error NotWhitelisted();
error OneInchSwapFailed();
error OracleUpdateFailed();
error Paused();
error ReentrantCall();
error RemoveFacetAddressMustBeZeroAddress(address _facetAddress);
error TooBigAmountIn();
error TooLate();
error TooSmallAmountOut();
error ZeroAddress();
error ZeroAmount();
error SwapError();
error SlippageTooHigh();
error InsufficientFunds();
Constants.sol 71 lines
// SPDX-License-Identifier: BUSL-1.1

pragma solidity >=0.5.0;

import { ICbETH } from "interfaces/external/coinbase/ICbETH.sol";
import { ISfrxETH } from "interfaces/external/frax/ISfrxETH.sol";
import { IStETH } from "interfaces/external/lido/IStETH.sol";
import { IRETH } from "interfaces/external/rocketPool/IRETH.sol";

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                 STORAGE SLOTS                                                  
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @dev Storage position of `DiamondStorage` structure
/// @dev Equals `keccak256("diamond.standard.diamond.storage") - 1`
bytes32 constant DIAMOND_STORAGE_POSITION = 0xc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131b;

/// @dev Storage position of `TransmuterStorage` structure
/// @dev Equals `keccak256("diamond.standard.transmuter.storage") - 1`
bytes32 constant TRANSMUTER_STORAGE_POSITION = 0xc1f2f38dde3351ac0a64934139e816326caa800303a1235dc53707d0de05d8bd;

/// @dev Storage position of `ImplementationStorage` structure
/// @dev Equals `keccak256("eip1967.proxy.implementation") - 1`
bytes32 constant IMPLEMENTATION_STORAGE_POSITION = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                     MATHS                                                      
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

uint256 constant BASE_6 = 1e6;
uint256 constant BASE_8 = 1e8;
uint256 constant BASE_9 = 1e9;
uint256 constant BASE_12 = 1e12;
uint256 constant BPS = 1e14;
uint256 constant BASE_18 = 1e18;
uint256 constant HALF_BASE_27 = 1e27 / 2;
uint256 constant BASE_27 = 1e27;
uint256 constant BASE_36 = 1e36;
uint256 constant MAX_BURN_FEE = 999_000_000;
uint256 constant MAX_MINT_FEE = BASE_12 - 1;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                     REENTRANT                                                      
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint8 constant NOT_ENTERED = 1;
uint8 constant ENTERED = 2;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                               COMMON ADDRESSES                                                 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

address constant PERMIT_2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
address constant ONE_INCH_ROUTER = 0x1111111254EEB25477B68fb85Ed929f73A960582;
address constant AGEUR = 0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8;
ICbETH constant CBETH = ICbETH(0xBe9895146f7AF43049ca1c1AE358B0541Ea49704);
IRETH constant RETH = IRETH(0xae78736Cd615f374D3085123A210448E74Fc6393);
IStETH constant STETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
ISfrxETH constant SFRXETH = ISfrxETH(0xac3E018457B222d93114458476f3E3416Abbe38F);
address constant XEVT = 0x3Ee320c9F73a84D1717557af00695A34b26d1F1d;
address constant USDM = 0x59D9356E565Ab3A36dD77763Fc0d87fEaf85508C;
address constant STEAK_USDC = 0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant EURC = 0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c;

address constant ONEINCH_ROUTER = 0x111111125421cA6dc452d289314280a0f8842A65;
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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.
 */
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].
     */
    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);
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
IAccessControlManager.sol 19 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IAccessControlManager
/// @author Angle Labs, Inc.
interface IAccessControlManager {
    /// @notice Checks whether an address is governor of the Angle Protocol or not
    /// @param admin Address to check
    /// @return Whether the address has the `GOVERNOR_ROLE` or not
    function isGovernor(address admin) external view returns (bool);

    /// @notice Checks whether an address is governor or a guardian of the Angle Protocol or not
    /// @param admin Address to check
    /// @return Whether the address has the `GUARDIAN_ROLE` or not
    /// @dev Governance should make sure when adding a governor to also give this governor the guardian
    /// role by calling the `addGovernor` function
    function isGovernorOrGuardian(address admin) external view returns (bool);
}
IHarvester.sol 20 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

interface IHarvester {
    function setYieldBearingAssetData(
        address yieldBearingAsset,
        address stablecoin,
        uint64 targetExposure,
        uint64 minExposureYieldAsset,
        uint64 maxExposureYieldAsset,
        uint64 overrideExposures
    ) external;

    function updateLimitExposuresYieldAsset(address yieldBearingAsset) external;

    function setMaxSlippage(uint96 newMaxSlippage) external;

    function harvest(address yieldBearingAsset, uint256 scale, bytes calldata extraData) external;
}
IDiamondCut.sol 17 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

import "../transmuter/Storage.sol";

/// @title IDiamondCut
/// @author Angle Labs, Inc.
/// @dev Reference: EIP-2535 Diamonds
/// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/interfaces/IDiamondCut.sol by mudgen
interface IDiamondCut {
    /// @notice Add/replace/remove any number of functions and optionally execute a function with delegatecall
    /// @param _diamondCut Contains the facet addresses and function selectors
    /// @param _init The address of the contract or facet to execute _calldata
    /// @param _calldata A function call, including function selector and arguments, executed with delegatecall on _init
    function diamondCut(FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata) external;
}
IDiamondEtherscan.sol 13 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

/// @title IDiamondEtherscan
/// @author Angle Labs, Inc.
interface IDiamondEtherscan {
    /// @notice Sets a dummy implementation with the same layout at the diamond proxy contract with all its facets
    function setDummyImplementation(address _implementation) external;

    /// @notice Address of the dummy implementation used to make the DiamondProxy contract interpretable by Etherscan
    function implementation() external view returns (address);
}
IDiamondLoupe.sol 31 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

import "../transmuter/Storage.sol";

/// @notice IDiamondLoupe
/// @author Angle Labs, Inc.
/// @dev Reference: EIP-2535 Diamonds
/// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/interfaces/IDiamondLoupe.sol by mudgen

interface IDiamondLoupe {
    /// @notice Gets all facet addresses and their four byte function selectors.
    /// @return facets_ Facet
    function facets() external view returns (Facet[] memory facets_);

    /// @notice Gets all the function selectors supported by a specific facet.
    /// @param _facet The facet address.
    /// @return facetFunctionSelectors_
    function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_);

    /// @notice Get all the facet addresses used by a diamond.
    /// @return facetAddresses_
    function facetAddresses() external view returns (address[] memory facetAddresses_);

    /// @notice Gets the facet that supports the given selector.
    /// @dev If facet is not found return address(0).
    /// @param _functionSelector The function selector.
    /// @return facetAddress_ The facet address.
    function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_);
}
IGetters.sol 120 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

import { IAccessControlManager } from "interfaces/IAccessControlManager.sol";
import { IAgToken } from "interfaces/IAgToken.sol";

import "../transmuter/Storage.sol";

/// @title IGetters
/// @author Angle Labs, Inc.
interface IGetters {
    /// @notice Checks whether a given `selector` is actually a valid selector corresponding to a function in one of the
    /// facets of the proxy
    function isValidSelector(bytes4 selector) external view returns (bool);

    /// @notice Reference to the `accessControlManager` contract of the system
    function accessControlManager() external view returns (IAccessControlManager);

    /// @notice Stablecoin minted by transmuter
    function agToken() external view returns (IAgToken);

    /// @notice Returns the list of collateral assets supported by the system
    function getCollateralList() external view returns (address[] memory);

    /// @notice Returns all the info in storage associated to a `collateral`
    function getCollateralInfo(address collateral) external view returns (Collateral memory);

    /// @notice Returns the decimals of a given `collateral`
    function getCollateralDecimals(address collateral) external view returns (uint8);

    /// @notice Returns the `xFee` and `yFee` arrays from which fees are computed when coming to mint
    /// with `collateral`
    function getCollateralMintFees(address collateral) external view returns (uint64[] memory, int64[] memory);

    /// @notice Returns the `xFee` and `yFee` arrays from which fees are computed when coming to burn
    /// for `collateral`
    function getCollateralBurnFees(address collateral) external view returns (uint64[] memory, int64[] memory);

    /// @notice Returns the `xFee` and `yFee` arrays used to compute the penalty factor depending on the collateral
    /// ratio when users come to redeem
    function getRedemptionFees() external view returns (uint64[] memory, int64[] memory);

    /// @notice Returns the collateral ratio of Transmuter in base `10**9` and a rounded version of the total amount
    /// of stablecoins issued
    function getCollateralRatio() external view returns (uint64 collatRatio, uint256 stablecoinsIssued);

    /// @notice Returns the total amount of stablecoins issued through Transmuter
    function getTotalIssued() external view returns (uint256 stablecoinsIssued);

    /// @notice Returns the amount of stablecoins issued from `collateral` and the total amount of stablecoins issued
    /// through Transmuter
    function getIssuedByCollateral(
        address collateral
    ) external view returns (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued);

    /// @notice Returns if a collateral is "managed" and the associated manager configuration
    function getManagerData(
        address collateral
    ) external view returns (bool isManaged, IERC20[] memory subCollaterals, bytes memory config);

    /// @notice Returns the oracle values associated to `collateral`
    /// @return mint Oracle value to be used for a mint transaction with `collateral`
    /// @return burn Oracle value that will be used for `collateral` for a burn transaction. This value
    /// is then used along with oracle values for all other collateral assets to get a global burn value for the oracle
    /// @return ratio Ratio, in base `10**18` between the oracle value of the `collateral` and its target price.
    /// This value is 10**18 if the oracle is greater than the collateral price
    /// @return minRatio Minimum ratio across all collateral assets between a collateral burn price and its target
    /// price. This value is independent of `collateral` and is used to normalize the burn oracle value for burn
    /// transactions.
    /// @return redemption Oracle value that would be used to price `collateral` when computing the collateral ratio
    /// during a redemption
    function getOracleValues(
        address collateral
    ) external view returns (uint256 mint, uint256 burn, uint256 ratio, uint256 minRatio, uint256 redemption);

    /// @notice Returns the data used to compute oracle values for `collateral`
    /// @return oracleType Type of oracle (Chainlink, external smart contract, ...)
    /// @return targetType Type passed to read the value of the target price
    /// @return oracleData Extra data needed to read the oracle. For Chainlink oracles, this data is supposed to give
    /// the addresses of the Chainlink feeds to read, the stale periods for each feed, ...
    /// @return targetData Extra data needed to read the target price of the asset
    function getOracle(
        address collateral
    )
        external
        view
        returns (
            OracleReadType oracleType,
            OracleReadType targetType,
            bytes memory oracleData,
            bytes memory targetData,
            bytes memory hyperparameters
        );

    /// @notice Returns if the associated functionality is paused or not
    function isPaused(address collateral, ActionType action) external view returns (bool);

    /// @notice Returns if `sender` is trusted to update normalizers
    function isTrusted(address sender) external view returns (bool);

    /// @notice Returns if `sender` is trusted to update sell rewards
    function isTrustedSeller(address sender) external view returns (bool);

    /// @notice Checks whether `sender` has a non null entry in the `isWhitelistedForType` storage mapping
    /// @dev Note that ultimately whitelisting may depend as well on external providers
    function isWhitelistedForType(WhitelistType whitelistType, address sender) external view returns (bool);

    /// @notice Checks whether `sender` can deal with `collateral` during burns and redemptions
    function isWhitelistedForCollateral(address collateral, address sender) external returns (bool);

    /// @notice Checks whether only whitelisted address can deal with `collateral` during burns and redemptions
    function isWhitelistedCollateral(address collateral) external view returns (bool);

    /// @notice Gets the data needed to deal with whitelists for `collateral`
    function getCollateralWhitelistData(address collateral) external view returns (bytes memory);

    /// @notice Returns the stablecoin cap for `collateral`
    function getStablecoinCap(address collateral) external view returns (uint256);
}
IRedeemer.sol 40 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IRedeemer
/// @author Angle Labs, Inc.
interface IRedeemer {
    /// @notice Redeems `amount` of stablecoins from the system
    /// @param receiver Address which should be receiving the output tokens
    /// @param deadline Timestamp before which the redemption should have occured
    /// @param minAmountOuts Minimum amount of each token given back in the redemption to obtain
    /// @return tokens List of tokens returned
    /// @return amounts Amount given for each token in the `tokens` array
    function redeem(
        uint256 amount,
        address receiver,
        uint256 deadline,
        uint256[] memory minAmountOuts
    ) external returns (address[] memory tokens, uint256[] memory amounts);

    /// @notice Same as the redeem function above with the additional feature to specify a list of `forfeitTokens` for
    /// which the Transmuter system will not try to do a transfer to `receiver`.
    function redeemWithForfeit(
        uint256 amount,
        address receiver,
        uint256 deadline,
        uint256[] memory minAmountOuts,
        address[] memory forfeitTokens
    ) external returns (address[] memory tokens, uint256[] memory amounts);

    /// @notice Simulate the exact output that a redemption of `amount` of stablecoins would give at a given block
    /// @return tokens List of tokens that would be given
    /// @return amounts Amount that would be obtained for each token in the `tokens` array
    function quoteRedemptionCurve(
        uint256 amount
    ) external view returns (address[] memory tokens, uint256[] memory amounts);

    /// @notice Updates the normalizer variable by `amount`
    function updateNormalizer(uint256 amount, bool increase) external returns (uint256);
}
IRewardHandler.sol 13 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IRewardHandler
/// @author Angle Labs, Inc.
interface IRewardHandler {
    /// @notice Sells some external tokens through a 1inch call
    /// @param minAmountOut Minimum amount of the outToken to get
    /// @param payload Payload to pass to 1inch
    /// @return amountOut Amount obtained of the outToken
    function sellRewards(uint256 minAmountOut, bytes memory payload) external returns (uint256 amountOut);
}
ISetters.sol 65 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

import { IERC20 } from "oz/interfaces/IERC20.sol";

import "../transmuter/Storage.sol";

/// @title ISettersGovernor
/// @author Angle Labs, Inc.
interface ISettersGovernor {
    /// @notice Recovers `amount` of `token` from the Transmuter contract
    function recoverERC20(address collateral, IERC20 token, address to, uint256 amount) external;

    /// @notice Sets a new access control manager address
    function setAccessControlManager(address _newAccessControlManager) external;

    /// @notice Sets (or unsets) a collateral manager  `collateral`
    function setCollateralManager(address collateral, ManagerStorage memory managerData) external;

    /// @notice Sets the allowance of the contract on `token` for `spender` to `amount`
    function changeAllowance(IERC20 token, address spender, uint256 amount) external;

    /// @notice Changes the trusted status for `sender` when for selling rewards or updating the normalizer
    function toggleTrusted(address sender, TrustedType t) external;

    /// @notice Changes whether a `collateral` can only be handled during burns and redemptions by whitelisted addresses
    /// and sets the data used to read into the whitelist
    function setWhitelistStatus(address collateral, uint8 whitelistStatus, bytes memory whitelistData) external;

    /// @notice Add `collateral` as a supported collateral in the system
    function addCollateral(address collateral) external;

    /// @notice Adjusts the amount of stablecoins issued from `collateral` by `amount`
    function adjustStablecoins(address collateral, uint128 amount, bool increase) external;

    /// @notice Revokes `collateral` from the system
    function revokeCollateral(address collateral) external;

    /// @notice Sets the `oracleConfig` used to read the value of `collateral` for the mint, burn and redemption
    /// operations
    function setOracle(address collateral, bytes memory oracleConfig) external;

    /// @notice Update oracle data for a given `collateral`
    function updateOracle(address collateral) external;
}

/// @title ISettersGovernor
/// @author Angle Labs, Inc.
interface ISettersGuardian {
    /// @notice Changes the pause status for mint or burn transactions for `collateral`
    function togglePause(address collateral, ActionType action) external;

    /// @notice Sets the mint or burn fees for `collateral`
    function setFees(address collateral, uint64[] memory xFee, int64[] memory yFee, bool mint) external;

    /// @notice Sets the parameters for the redemption curve
    function setRedemptionCurveParams(uint64[] memory xFee, int64[] memory yFee) external;

    /// @notice Changes the whitelist status for a collateral with `whitelistType` for an address `who`
    function toggleWhitelist(WhitelistType whitelistType, address who) external;

    /// @notice Sets the stablecoin cap that can be issued from a `collateral`
    function setStablecoinCap(address collateral, uint256 stablecoinCap) external;
}
ISwapper.sol 74 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title ISwapper
/// @author Angle Labs, Inc.
interface ISwapper {
    /// @notice Swaps (that is to say mints or burns) an exact amount of `tokenIn` for an amount of `tokenOut`
    /// @param amountIn Amount of `tokenIn` to bring
    /// @param amountOutMin Minimum amount of `tokenOut` to get: if `amountOut` is inferior to this amount, the
    /// function will revert
    /// @param tokenIn Token to bring for the swap
    /// @param tokenOut Token to get out of the swap
    /// @param to Address to which `tokenOut` must be sent
    /// @param deadline Timestamp before which the transaction must be executed
    /// @return amountOut Amount of `tokenOut` obtained through the swap
    function swapExactInput(
        uint256 amountIn,
        uint256 amountOutMin,
        address tokenIn,
        address tokenOut,
        address to,
        uint256 deadline
    ) external returns (uint256 amountOut);

    /// @notice Same as `swapExactInput`, but using Permit2 signatures for `tokenIn`
    /// @dev Can only be used to mint, hence `tokenOut` is not needed
    function swapExactInputWithPermit(
        uint256 amountIn,
        uint256 amountOutMin,
        address tokenIn,
        address to,
        uint256 deadline,
        bytes calldata permitData
    ) external returns (uint256 amountOut);

    /// @notice Swaps (that is to say mints or burns) an amount of `tokenIn` for an exact amount of `tokenOut`
    /// @param amountOut Amount of `tokenOut` to obtain from the swap
    /// @param amountInMax Maximum amount of `tokenIn` to bring in order to get `amountOut` of `tokenOut`
    /// @param tokenIn Token to bring for the swap
    /// @param tokenOut Token to get out of the swap
    /// @param to Address to which `tokenOut` must be sent
    /// @param deadline Timestamp before which the transaction must be executed
    /// @return amountIn Amount of `tokenIn` used to perform the swap
    function swapExactOutput(
        uint256 amountOut,
        uint256 amountInMax,
        address tokenIn,
        address tokenOut,
        address to,
        uint256 deadline
    ) external returns (uint256 amountIn);

    /// @notice Same as `swapExactOutput`, but using Permit2 signatures for `tokenIn`
    /// @dev Can only be used to mint, hence `tokenOut` is not needed
    function swapExactOutputWithPermit(
        uint256 amountOut,
        uint256 amountInMax,
        address tokenIn,
        address to,
        uint256 deadline,
        bytes calldata permitData
    ) external returns (uint256 amountIn);

    /// @notice Simulates what a call to `swapExactInput` with `amountIn` of `tokenIn` for `tokenOut` would give.
    /// If called right before and at the same block, the `amountOut` outputted by this function is exactly the
    /// amount that will be obtained with `swapExactInput`
    function quoteIn(uint256 amountIn, address tokenIn, address tokenOut) external view returns (uint256 amountOut);

    /// @notice Simulates what a call to `swapExactOutput` for `amountOut` of `tokenOut` with `tokenIn` would give.
    /// If called right before and at the same block, the `amountIn` outputted by this function is exactly the
    /// amount that will be obtained with `swapExactOutput`
    function quoteOut(uint256 amountOut, address tokenIn, address tokenOut) external view returns (uint256 amountIn);
}
ICbETH.sol 9 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title ICbETH
/// @notice Interface for the `cbETH` contract
interface ICbETH {
    function exchangeRate() external view returns (uint256);
}
ISfrxETH.sol 9 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title ISfrxETH
/// @notice Interface for the `sfrxETH` contract
interface ISfrxETH {
    function pricePerShare() external view returns (uint256);
}
IStETH.sol 13 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IStETH
/// @notice Interface for the `StETH` contract
interface IStETH {
    function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);

    function submit(address) external payable returns (uint256);

    function getSharesByPooledEth(uint256 _ethAmount) external view returns (uint256);
}
IRETH.sol 9 lines
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IRETH
/// @notice Interface for the `rETH` contract
interface IRETH {
    function getExchangeRate() external view returns (uint256);
}
Storage.sol 136 lines
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.19;

import { IERC20 } from "oz/token/ERC20/IERC20.sol";
import { IAccessControlManager } from "interfaces/IAccessControlManager.sol";
import { IAgToken } from "interfaces/IAgToken.sol";

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        ENUMS                                                      
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

enum FacetCutAction {
    Add,
    Replace,
    Remove
}

enum ManagerType {
    EXTERNAL
}

enum ActionType {
    Mint,
    Burn,
    Redeem
}

enum TrustedType {
    Updater,
    Seller
}

enum QuoteType {
    MintExactInput,
    MintExactOutput,
    BurnExactInput,
    BurnExactOutput
}

enum OracleReadType {
    CHAINLINK_FEEDS,
    EXTERNAL,
    NO_ORACLE,
    STABLE,
    WSTETH,
    CBETH,
    RETH,
    SFRXETH,
    PYTH,
    MAX,
    MORPHO_ORACLE
}

enum OracleQuoteType {
    UNIT,
    TARGET
}

enum WhitelistType {
    BACKED
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                    STRUCTS                                                     
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

struct Permit2Details {
    address to; // Address that will receive the funds
    uint256 nonce; // Nonce of the transaction
    bytes signature; // Permit signature of the user
}

struct FacetCut {
    address facetAddress; // Facet contract address
    FacetCutAction action; // Can be add, remove or replace
    bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}

struct Facet {
    address facetAddress; // Facet contract address
    bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}

struct FacetInfo {
    address facetAddress; // Facet contract address
    uint16 selectorPosition; // Position in the list of all selectors
}

struct DiamondStorage {
    bytes4[] selectors; // List of all available selectors
    mapping(bytes4 => FacetInfo) selectorInfo; // Selector to (address, position in list)
    IAccessControlManager accessControlManager; // Contract handling access control
}

struct ImplementationStorage {
    address implementation; // Dummy implementation address for Etherscan usability
}

struct ManagerStorage {
    IERC20[] subCollaterals; // Subtokens handled by the manager or strategies
    bytes config; // Additional configuration data
}

struct Collateral {
    uint8 isManaged; // If the collateral is managed through external strategies
    uint8 isMintLive; // If minting from this asset is unpaused
    uint8 isBurnLive; // If burning to this asset is unpaused
    uint8 decimals; // IERC20Metadata(collateral).decimals()
    uint8 onlyWhitelisted; // If only whitelisted addresses can burn or redeem for this token
    uint216 normalizedStables; // Normalized amount of stablecoins issued from this collateral
    uint64[] xFeeMint; // Increasing exposures in [0,BASE_9[
    int64[] yFeeMint; // Mint fees at the exposures specified in `xFeeMint`
    uint64[] xFeeBurn; // Decreasing exposures in ]0,BASE_9]
    int64[] yFeeBurn; // Burn fees at the exposures specified in `xFeeBurn`
    bytes oracleConfig; // Data about the oracle used for the collateral
    bytes whitelistData; // For whitelisted collateral, data used to verify whitelists
    ManagerStorage managerData; // For managed collateral, data used to handle the strategies
    uint256 stablecoinCap; // Cap on the amount of stablecoins that can be issued from this collateral
}

struct TransmuterStorage {
    IAgToken agToken; // agToken handled by the system
    uint8 isRedemptionLive; // If redemption is unpaused
    uint8 statusReentrant; // If call is reentrant or not
    uint128 normalizedStables; // Normalized amount of stablecoins issued by the system
    uint128 normalizer; // To reconcile `normalizedStables` values with the actual amount
    address[] collateralList; // List of collateral assets supported by the system
    uint64[] xRedemptionCurve; // Increasing collateral ratios > 0
    int64[] yRedemptionCurve; // Value of the redemption fees at `xRedemptionCurve`
    mapping(address => Collateral) collaterals; // Maps a collateral asset to its parameters
    mapping(address => uint256) isTrusted; // If an address is trusted to update the normalizer value
    mapping(address => uint256) isSellerTrusted; // If an address is trusted to sell accruing reward tokens or to run keeper jobs on oracles
    mapping(WhitelistType => mapping(address => uint256)) isWhitelistedForType;
    // Whether an address is whitelisted for a specific whitelist type
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)

pragma solidity ^0.8.0;

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

Read Contract

accessControlManager 0xb4a0bdf3 → address
agToken 0xee565a63 → address
computeRebalanceAmount 0x641bd503 → uint8, uint256
isGovernor 0xe43581b8 → bool
isGovernorOrGuardian 0x521d4de9 → bool
isTrusted 0x96d64879 → bool
maxSlippage 0x8c04166f → uint96
transmuter 0x7239d2b9 → address
yieldBearingData 0xc5e6d5ea → address, uint64, uint64, uint64, uint64
yieldBearingToDepositAddress 0x0c5abe80 → address

Write Contract 9 functions

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

finalizeRebalance 0x7c70b002
address yieldBearingAsset
uint256 balance
harvest 0xedf0ef03
address yieldBearingAsset
uint256 scale
bytes
recoverERC20 0xb51609b4
address tokenAddress
uint256 amountToRecover
address to
setMaxSlippage 0x184b949b
uint96 newMaxSlippage
setTargetExposure 0x9ae78486
address yieldBearingAsset
uint64 targetExposure
setYieldBearingAssetData 0x9a49e83d
address yieldBearingAsset
address asset
uint64 targetExposure
uint64 minExposure
uint64 maxExposure
uint64 overrideExposures
setYieldBearingToDepositAddress 0x2b1da9cf
address yieldBearingAsset
address newDepositAddress
toggleTrusted 0x7ee84349
address trusted
updateLimitExposuresYieldAsset 0x8195001d
address yieldBearingAsset

Recent Transactions

No transactions found for this address