Address Contract Partially Verified
Address
0x89cfeeb9031f0Dd7B3Bb7EB9C1622CEf1aAF17BA
Balance
0 ETH
Nonce
1
Code Size
13801 bytes
Creator
0x9C7f6a30...E163 at tx 0x47f3e097...df6f61
Indexed Transactions
0
Contract Bytecode
13801 bytes
0x608060405234801561000f575f5ffd5b5060043610610208575f3560e01c806361d712971161011f578063a217fddf116100a9578063dd2d855311610079578063dd2d8553146104a1578063e6a92fde146104a9578063ea1dfb76146104bc578063ed4c8bb3146104cf578063f61f1182146104e2575f5ffd5b8063a217fddf1461045b578063b100b92214610462578063cc1fdf1614610475578063d547741f1461048e575f5ffd5b806388977738116100ef578063889777381461040757806389a06d351461040f5780638a49a9c3146104225780638e336bb91461043557806391d1485414610448575f5ffd5b806361d71297146103bb578063731ca4a1146103ce57806375e52a0e146103e15780638707b255146103f4575f5ffd5b806336568abe116101a05780633f785a10116101705780633f785a101461033c57806347c026611461034f5780634d635e70146103625780635986820d146103955780635a735891146103a8575f5ffd5b806336568abe146102f0578063387516dd146103035780633a5a1744146103165780633e47158c14610329575f5ffd5b8063248a9ca3116101db578063248a9ca3146102875780632b5b5696146102b75780632ea33695146102ca5780632f2ff15d146102dd575f5ffd5b806301ffc9a71461020c5780630415cc15146102345780631f355bc6146102495780632121cffb14610274575b5f5ffd5b61021f61021a366004612218565b6104f5565b60405190151581526020015b60405180910390f35b610247610242366004612231565b61052b565b005b60045461025c906001600160a01b031681565b6040516001600160a01b03909116815260200161022b565b61024761028236600461225e565b610780565b6102a96102953660046122a6565b5f9081526020819052604090206001015490565b60405190815260200161022b565b6102476102c53660046122bd565b610821565b6102476102d83660046122d8565b6108ad565b6102476102eb36600461231b565b6109b7565b6102476102fe36600461231b565b6109e0565b610247610311366004612349565b610a5a565b6102476103243660046125d7565b610ba7565b60035461025c906001600160a01b031681565b61024761034a366004612712565b610dd3565b61024761035d3660046122bd565b610ef1565b61025c610370366004612757565b600660209081525f92835260408084209091529082529020546001600160a01b031681565b6102476103a3366004612349565b610f7d565b6102476103b6366004612783565b610fec565b60025461025c906001600160a01b031681565b6102476103dc366004612349565b6110f8565b6102476103ef3660046127bf565b6111a6565b61025c6104023660046122a6565b6112d7565b6005546102a9565b61025c61041d366004612757565b6112ff565b61024761043036600461225e565b6113e4565b610247610443366004612814565b611454565b61021f61045636600461231b565b61154d565b6102a95f81565b610247610470366004612349565b611575565b60015461025c906201000090046001600160a01b031681565b61024761049c36600461231b565b611665565b6102a9611689565b6102476104b73660046128fa565b6116d3565b6102476104ca3660046122bd565b6117f0565b6102476104dd3660046122bd565b61187c565b6102476104f0366004612936565b611912565b5f6001600160e01b03198216637965db0b60e01b148061052557506301ffc9a760e01b6001600160e01b03198316145b92915050565b600154610100900460ff161580801561054857506001805460ff16105b806105615750303b15801561056157506001805460ff16145b6105c95760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6001805460ff19168117905580156105eb576001805461ff0019166101001790555b5f6105fc60408401602085016122bd565b6001600160a01b0316148061062857505f61061d60608401604085016122bd565b6001600160a01b0316145b8061064a57505f61063f60808401606085016122bd565b6001600160a01b0316145b8061066957505f61065e60208401846122bd565b6001600160a01b0316145b15610687576040516303abca8360e61b815260040160405180910390fd5b61069760408301602084016122bd565b600180546001600160a01b0392909216620100000262010000600160b01b03199092169190911790556106d060608301604084016122bd565b600280546001600160a01b0319166001600160a01b039290921691909117905561070060808301606084016122bd565b600380546001600160a01b0319166001600160a01b03929092169190911790556107365f61073160208501856122bd565b611a13565b801561077c576001805461ff00191681556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b5050565b5f5160206135945f395f51905f5261079781611a96565b83836107a38282611aa3565b6001600160a01b038681165f90815260066020908152604080832089851684529091529081902054905163d582e68560e01b8152868316600482015291169063d582e685906024015b5f604051808303815f87803b158015610803575f5ffd5b505af1158015610815573d5f5f3e3d5ffd5b50505050505050505050565b5f5160206135545f395f51905f5261083881611a96565b6001600160a01b03821661085f576040516303abca8360e61b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0384169081179091556040519081527fc35592bfec981339e70fefaa398a695eb563d5f23f40c79e3837a4c163aa03d390602001610773565b5f5160206135745f395f51905f526108c481611a96565b84846108d08282611aa3565b6001600160a01b038781165f9081526006602090815260408083208a851684529091529081902054905163391689f560e01b8152600481018890526024810187905233604482015291169063391689f5906064015f604051808303815f87803b15801561093b575f5ffd5b505af115801561094d573d5f5f3e3d5ffd5b505050506001600160a01b038781165f9081526006602090815260408083208a8516845282529182902054915188815291909216917f18e44bc8d37c4e92c9677833ad3bfdfa320ba88a73ed4990b5f64d5e63238abf91015b60405180910390a250505050505050565b5f828152602081905260409020600101546109d181611a96565b6109db8383611a13565b505050565b6001600160a01b0381163314610a505760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016105c0565b61077c8282611ae7565b5f5160206135545f395f51905f52610a7181611a96565b8383610a7d8282611aa3565b6004546001600160a01b0316610aa6576040516303abca8360e61b815260040160405180910390fd5b6001600160a01b038681165f908152600660209081526040808320898516845290915280822054600480549251630716338560e21b8152928516908301526024820188905291929190911690631c58ce14906044016020604051808303815f875af1158015610b17573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b3b9190612972565b6001600160a01b038881165f9081526006602090815260408083208b8516845282529182902054600454835190851681529182018a905291810184905292935016907f4fb8fc8df15ed46b5e96ecdee726d0d1834153e331d2ad648de9469b8407fc5c906060016109a6565b5f5160206135545f395f51905f52610bbe81611a96565b8686610bca8282611b4b565b6040516001600160601b031960608b811b821660208401528a901b1660348201525f906048016040516020818303038152906040528051906020012090505f81604051610c16906121ef565b8190604051809103905ff5905080158015610c33573d5f5f3e3d5ffd5b506002546040805130602482018190528a51805180516001600160a01b0390811660448601526020808301516064870152828701516084870152606080840151831660a48801526080840151831660c488015260a090930151821660e48701528084015180516101048801528082015161012488015287015161014487015292860151805182166101648701528301518116610184860152828e0151805182166101a4870152808401516101c48701528601516101e48601528d86015180518216610204870152808401518216610224870152860151610244860152908d01518051821661026486015282015161028480860191909152855180860390910181526102a4909401855290830180516001600160e01b031663d5d5458d60e01b179052925163cf7a1d7760e01b81529495508583169463cf7a1d7794610d80949293921691906004016129b7565b5f604051808303815f87803b158015610d97575f5ffd5b505af1158015610da9573d5f5f3e3d5ffd5b50505050610dc681888d8d8d8d8c5f0151604001515f0151611b90565b5050505050505050505050565b5f5160206135945f395f51905f52610dea81611a96565b8383610df68282611aa3565b6001600160a01b038087165f90815260066020908152604080832089851684529091529081902054905163537e266960e01b815291169063537e266990610e419087906004016129eb565b5f604051808303815f87803b158015610e58575f5ffd5b505af1158015610e6a573d5f5f3e3d5ffd5b505050506001600160a01b038681165f90815260066020908152604080832089851684528252918290205487518883015189850151855192871683529086169382019390935292830191909152909116907fdc590a2f874093efb9a92b4df488d9ab419fb6059c89a973d99cfa3fb8818bad906060015b60405180910390a2505050505050565b5f5160206135945f395f51905f52610f0881611a96565b6001600160a01b038216610f2f576040516303abca8360e61b815260040160405180910390fd5b600380546001600160a01b0319166001600160a01b0384169081179091556040519081527f8cb0f1efb2fb9a441d1759cb883b073bfdcb20b9abae9ca276d2e73b4fed27b090602001610773565b5f5160206135745f395f51905f52610f9481611a96565b8383610fa08282611aa3565b6001600160a01b038681165f908152600660209081526040808320898516845290915290819020549051636ee3193160e11b81526004810187905291169063ddc63262906024016107ec565b5f5160206135945f395f51905f5261100381611a96565b838361100f8282611aa3565b6001600160a01b038087165f90815260066020908152604080832089851684529091529081902054905163d60f605360e01b815291169063d60f60539061105a908790600401612a1a565b5f604051808303815f87803b158015611071575f5ffd5b505af1158015611083573d5f5f3e3d5ffd5b505050506001600160a01b038681165f90815260066020908152604080832089851684528252918290205487518883015189850151855192871683529382015292830191909152909116907ffa6d013bf5fa76209d7032d5774e762933d1c9cf99bef47bc9312f61693b7ce190606001610ee1565b5f5160206135745f395f51905f5261110f81611a96565b838361111b8282611aa3565b61112785333087611e07565b6001600160a01b038087165f908152600660209081526040808320848a16845290915290205461115a9187911686611e9c565b6001600160a01b038681165f90815260066020908152604080832089851684529091529081902054905163750841a160e01b81526004810187905291169063750841a1906024016107ec565b5f5160206135945f395f51905f526111bd81611a96565b83836111c98282611aa3565b6001600160a01b038087165f9081526006602090815260408083208985168452825291829020546060880151608089015160a08a01518a51948b01518b870151965163b502030760e01b8152949097169663b50203079661123296949593949293600401612a44565b5f604051808303815f87803b158015611249575f5ffd5b505af115801561125b573d5f5f3e3d5ffd5b505050506001600160a01b038681165f9081526006602090815260408083208985168452825291829020546060880151608089015160a08a01518a51948b01518b870151965194909716967fc9535a9af4e2001276bd62dd355323d5d06c26fe8efb9fdefbf462f92f7a072f96610ee196949593949293612a44565b600581815481106112e6575f80fd5b5f918252602090912001546001600160a01b0316905081565b6040516001600160601b0319606084811b8216602084015283901b1660348201525f903090604801604051602081830303815290604052805190602001206040518060200161134d906121ef565b601f1982820381018352601f90910116604081905261136f9190602001612a95565b604051602081830303815290604052805190602001206040516020016113c5939291906001600160f81b0319815260609390931b6001600160601b03191660018401526015830191909152603582015260550190565b60408051601f1981840301815291905280516020909101209392505050565b5f5160206135945f395f51905f526113fb81611a96565b83836114078282611aa3565b6001600160a01b038681165f908152600660209081526040808320898516845290915290819020549051630df2633360e11b81528683166004820152911690631be4c666906024016107ec565b5f5160206135945f395f51905f5261146b81611a96565b84846114778282611aa3565b6001600160a01b038088165f9081526006602090815260408083208a85168452909152908190205490516332bcbfcb60e01b81529116906332bcbfcb906114c49088908890600401612aa0565b5f604051808303815f87803b1580156114db575f5ffd5b505af11580156114ed573d5f5f3e3d5ffd5b5050506001600160a01b038089165f9081526006602090815260408083208b8516845290915290819020549051911691507f23d631a3594eec3c8390a3cc7b93be2b70a00a73c08fa849ea9c42f4957709cd906109a69088908890612aa0565b5f918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b5f5160206135745f395f51905f5261158c81611a96565b83836115988282611aa3565b6001600160a01b038681165f908152600660209081526040808320898516845290915290819020549051633a6be6dd60e11b8152600481018790529116906374d7cdba906024015f604051808303815f87803b1580156115f6575f5ffd5b505af1158015611608573d5f5f3e3d5ffd5b505050506001600160a01b038681165f908152600660209081526040808320898516845282529182902054915187815291909216917fbb1095abb98fe3ad5575684330e5d67210e39c68d219cbe81075f5c2fae7b1109101610ee1565b5f8281526020819052604090206001015461167f81611a96565b6109db8383611ae7565b604051611698602082016121ef565b601f1982820381018352601f9091011660408190526116ba9190602001612a95565b6040516020818303038152906040528051906020012081565b5f5160206135945f395f51905f526116ea81611a96565b83836116f68282611aa3565b6001600160a01b038681165f90815260066020908152604080832089851684528252918290205487519188015188840151935163f6615b4560e01b815260048101939093526024830152604482019290925291169063f6615b45906064015f604051808303815f87803b15801561176b575f5ffd5b505af115801561177d573d5f5f3e3d5ffd5b505050506001600160a01b038681165f9081526006602090815260408083208985168452825291829020548751888301518985015185519283529382015292830191909152909116907fe0d81c93332dc1523620464ea0eb0d639aa5e552a11b8b7241cc40d834861cc290606001610ee1565b5f5160206135545f395f51905f5261180781611a96565b6001600160a01b03821661182e576040516303abca8360e61b815260040160405180910390fd5b600480546001600160a01b0319166001600160a01b0384169081179091556040519081527f959ff7170f01acadf2c22d28bf512cb5e92b7065b4b78380882bbd1e12c979e690602001610773565b5f5160206135545f395f51905f5261189381611a96565b6001600160a01b0382166118ba576040516303abca8360e61b815260040160405180910390fd5b6001805462010000600160b01b031916620100006001600160a01b038516908102919091179091556040519081527f6ef8ed49bf64127e68c52f22bc311c8d4c62d4322feecabc00d5fe423855cb9a90602001610773565b5f5160206135945f395f51905f5261192981611a96565b83836119358282611aa3565b6001600160a01b038087165f908152600660209081526040808320898516845290915290819020549051626456b160e71b815291169063322b58809061197f908790600401612af9565b5f604051808303815f87803b158015611996575f5ffd5b505af11580156119a8573d5f5f3e3d5ffd5b505050506001600160a01b038681165f9081526006602090815260408083208985168452825291829020548751888301518451918616825292810192909252909216917f57554549d73e05769bc149d44109218060311df2111cd955ba874e9618f7521e9101610ee1565b611a1d828261154d565b61077c575f828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055611a523390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b611aa08133611f46565b50565b6001600160a01b038281165f90815260066020908152604080832085851684529091529020541661077c576040516373c1405960e01b815260040160405180910390fd5b611af1828261154d565b1561077c575f828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6001600160a01b038281165f9081526006602090815260408083208585168452909152902054161561077c57604051637ced6a8b60e11b815260040160405180910390fd5b60015460405163086ed53d60e31b81526001600160a01b03898116600483015287811660248301528681166044830152606482018690526084820185905283811660a48301525f9283926201000090910490911690634376a9e89060c40160408051808303815f875af1158015611c09573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c2d9190612b19565b6040516365e3c2a760e11b81526001600160a01b0380841660048301528083166024830152929450909250908a169063cbc7854e906044015f604051808303815f87803b158015611c7c575f5ffd5b505af1158015611c8e573d5f5f3e3d5ffd5b5050604051631b2ce7f360e11b81526001600160a01b038b811660048301528c169250633659cfe691506024015f604051808303815f87803b158015611cd2575f5ffd5b505af1158015611ce4573d5f5f3e3d5ffd5b50506003546040516308f2839760e41b81526001600160a01b039182166004820152908c169250638f28397091506024015f604051808303815f87803b158015611d2c575f5ffd5b505af1158015611d3e573d5f5f3e3d5ffd5b505060058054600181019091557f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db00180546001600160a01b038d81166001600160a01b031992831681179093558b81165f8181526006602090815260408083208f8616808552908352928190208054909616871790955584519586528984169086015291871692840192909252935091507f02bb034d0b06b13b8d578b8dc4bd83551d120b6954ca7c855e4c59c2519f960f9060600160405180910390a3505050505050505050565b6040516001600160a01b03808516602483015283166044820152606481018290525f90611e749086906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611f9f565b90508015611e9557604051630b67169d60e11b815260040160405180910390fd5b5050505050565b6040516001600160a01b03831660248201525f6044820181905290611ece90859063095ea7b360e01b90606401611e3d565b90508015611eef57604051637ede7c4760e11b815260040160405180910390fd5b6040516001600160a01b038416602482015260448101839052611f1f90859063095ea7b360e01b90606401611e3d565b90508015611f405760405163a31635f560e01b815260040160405180910390fd5b50505050565b611f50828261154d565b61077c57611f5d81612040565b611f68836020612052565b604051602001611f79929190612b46565b60408051601f198184030181529082905262461bcd60e51b82526105c091600401612b9b565b5f5f5f846001600160a01b031684604051611fba9190612a95565b5f604051808303815f865af19150503d805f8114611ff3576040519150601f19603f3d011682016040523d82523d5f602084013e611ff8565b606091505b509150915081158061202657505f81511180156120265750808060200190518101906120249190612bad565b155b1561203657600192505050610525565b505f949350505050565b60606105256001600160a01b03831660145b60605f612060836002612bdc565b61206b906002612bf3565b67ffffffffffffffff81111561208357612083612387565b6040519080825280601f01601f1916602001820160405280156120ad576020820181803683370190505b509050600360fc1b815f815181106120c7576120c7612c06565b60200101906001600160f81b03191690815f1a905350600f60fb1b816001815181106120f5576120f5612c06565b60200101906001600160f81b03191690815f1a9053505f612117846002612bdc565b612122906001612bf3565b90505b6001811115612199576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061215657612156612c06565b1a60f81b82828151811061216c5761216c612c06565b60200101906001600160f81b03191690815f1a90535060049490941c9361219281612c1a565b9050612125565b5083156121e85760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016105c0565b9392505050565b61092480612c3083390190565b80356001600160e01b031981168114612213575f5ffd5b919050565b5f60208284031215612228575f5ffd5b6121e8826121fc565b5f6080828403128015612242575f5ffd5b509092915050565b6001600160a01b0381168114611aa0575f5ffd5b5f5f5f60608486031215612270575f5ffd5b833561227b8161224a565b9250602084013561228b8161224a565b9150604084013561229b8161224a565b809150509250925092565b5f602082840312156122b6575f5ffd5b5035919050565b5f602082840312156122cd575f5ffd5b81356121e88161224a565b5f5f5f5f608085870312156122eb575f5ffd5b84356122f68161224a565b935060208501356123068161224a565b93969395505050506040820135916060013590565b5f5f6040838503121561232c575f5ffd5b82359150602083013561233e8161224a565b809150509250929050565b5f5f5f6060848603121561235b575f5ffd5b83356123668161224a565b925060208401356123768161224a565b929592945050506040919091013590565b634e487b7160e01b5f52604160045260245ffd5b6040516060810167ffffffffffffffff811182821017156123be576123be612387565b60405290565b6040805190810167ffffffffffffffff811182821017156123be576123be612387565b6040516080810167ffffffffffffffff811182821017156123be576123be612387565b604051601f8201601f1916810167ffffffffffffffff8111828210171561243357612433612387565b604052919050565b5f60c0828403121561244b575f5ffd5b60405160c0810167ffffffffffffffff8111828210171561246e5761246e612387565b604052905080823561247f8161224a565b8152602083810135908201526040808401359082015260608301356124a38161224a565b606082015260808301356124b68161224a565b608082015260a08301356124c98161224a565b60a0919091015292915050565b5f606082840312156124e6575f5ffd5b6124ee61239b565b82358152602080840135908201526040928301359281019290925250919050565b5f6060828403121561251f575f5ffd5b61252761239b565b905081356125348161224a565b81526020828101359082015260409182013591810191909152919050565b5f60608284031215612562575f5ffd5b61256a61239b565b905081356125778161224a565b815260208201356125878161224a565b602082015260409182013591810191909152919050565b5f604082840312156125ae575f5ffd5b6125b66123c4565b905081356125c38161224a565b815260209182013591810191909152919050565b5f5f5f5f5f5f8688036103008112156125ee575f5ffd5b87356125f98161224a565b965060208801356126098161224a565b9550604088013594506060880135935060808801356126278161224a565b9250609f19810161026081121561263c575f5ffd5b6126446123e7565b610160821215612652575f5ffd5b61265a61239b565b91506126698b60a08c0161243b565b82526126798b6101608c016124d6565b602083015260406101bf1984011215612690575f5ffd5b6126986123c4565b92506101c08a01356126a98161224a565b83526101e08a01356126ba8161224a565b6020840152604082018390528181526126d78b6102008c0161250f565b60208201526126ea8b6102608c01612552565b60408201526126fd8b6102c08c0161259e565b60608201528093505050509295509295509295565b5f5f5f60a08486031215612724575f5ffd5b833561272f8161224a565b9250602084013561273f8161224a565b915061274e8560408601612552565b90509250925092565b5f5f60408385031215612768575f5ffd5b82356127738161224a565b9150602083013561233e8161224a565b5f5f5f60a08486031215612795575f5ffd5b83356127a08161224a565b925060208401356127b08161224a565b915061274e856040860161250f565b5f5f5f61010084860312156127d2575f5ffd5b83356127dd8161224a565b925060208401356127ed8161224a565b915061274e856040860161243b565b8015158114611aa0575f5ffd5b8035612213816127fc565b5f5f5f5f60808587031215612827575f5ffd5b84356128328161224a565b935060208501356128428161224a565b9250604085013567ffffffffffffffff81111561285d575f5ffd5b8501601f8101871361286d575f5ffd5b803567ffffffffffffffff81111561288757612887612387565b8060051b6128976020820161240a565b9182526020818401810192908101908a8411156128b2575f5ffd5b6020850194505b838510156128db576128ca856121fc565b8252602094850194909101906128b9565b80965050505050506128ef60608601612809565b905092959194509250565b5f5f5f60a0848603121561290c575f5ffd5b83356129178161224a565b925060208401356129278161224a565b915061274e85604086016124d6565b5f5f5f60808486031215612948575f5ffd5b83356129538161224a565b925060208401356129638161224a565b915061274e856040860161259e565b5f60208284031215612982575f5ffd5b5051919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b6001600160a01b038481168252831660208201526060604082018190525f906129e290830184612989565b95945050505050565b81516001600160a01b039081168252602080840151909116908201526040808301519082015260608101610525565b81516001600160a01b03168152602080830151908201526040808301519082015260608101610525565b6001600160a01b0396871681529486166020860152928516604085015293166060830152608082019290925260a081019190915260c00190565b5f81518060208401855e5f93019283525090919050565b5f6121e88284612a7e565b604080825283519082018190525f9060208501906060840190835b81811015612ae35783516001600160e01b031916835260209384019390920191600101612abb565b5050809250505082151560208301529392505050565b81516001600160a01b031681526020808301519082015260408101610525565b5f5f60408385031215612b2a575f5ffd5b8251612b358161224a565b602084015190925061233e8161224a565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081525f612b776017830185612a7e565b7001034b99036b4b9b9b4b733903937b6329607d1b81526129e26011820185612a7e565b602081525f6121e86020830184612989565b5f60208284031215612bbd575f5ffd5b81516121e8816127fc565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761052557610525612bc8565b8082018082111561052557610525612bc8565b634e487b7160e01b5f52603260045260245ffd5b5f81612c2857612c28612bc8565b505f19019056fe6080604052348015600e575f5ffd5b506109088061001c5f395ff3fe608060405260043610610042575f3560e01c80633659cfe6146100595780636e9960c3146100785780638f283970146100a8578063cf7a1d77146100c757610051565b366100515761004f6100e6565b005b61004f6100e6565b348015610064575f5ffd5b5061004f61007336600461072d565b6100f8565b348015610083575f5ffd5b5061008c6101b0565b6040516001600160a01b03909116815260200160405180910390f35b3480156100b3575f5ffd5b5061004f6100c236600461072d565b6101be565b3480156100d2575f5ffd5b5061004f6100e136600461075a565b610218565b6100f66100f161034c565b610355565b565b33610101610373565b6001600160a01b03161461014e5760405162461bcd60e51b815260206004820152600f60248201526e2727aa2fa82927ac2cafa0a226a4a760891b60448201526064015b60405180910390fd5b6001600160a01b0381166101a45760405162461bcd60e51b815260206004820152601f60248201527f5a45524f5f494d504c454d454e544154494f4e5f4e4f545f414c4c4f574544006044820152606401610145565b6101ad816103a5565b50565b5f6101b9610373565b905090565b336101c7610373565b6001600160a01b03161461020f5760405162461bcd60e51b815260206004820152600f60248201526e2727aa2fa82927ac2cafa0a226a4a760891b6044820152606401610145565b6101ad816103e4565b61024360017fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610461082d565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103146102715761027161084c565b61029c60017f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd61082d565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc146102ca576102ca61084c565b5f6102d361034c565b6001600160a01b03161480156102f157506001600160a01b03821615155b6103335760405162461bcd60e51b81526020600482015260136024820152721053149150511657d253925512505312569151606a1b6044820152606401610145565b61033e82825f610438565b610347836103e4565b505050565b5f6101b9610462565b365f5f375f5f365f845af43d5f5f3e80801561036f573d5ff35b3d5ffd5b5f7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b546001600160a01b0316919050565b6103ae81610489565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a250565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61040d610373565b604080516001600160a01b03928316815291841660208301520160405180910390a16101ad8161053a565b610441836103a5565b5f8251118061044d5750805b156103475761045c83836105c6565b50505050565b5f7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc610396565b6001600160a01b0381163b6104f65760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610145565b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b80546001600160a01b0319166001600160a01b039290921691909117905550565b6001600160a01b03811661059f5760405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b6064820152608401610145565b807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103610519565b60606105eb83836040518060600160405280602781526020016108ac602791396105f4565b90505b92915050565b60605f5f856001600160a01b0316856040516106109190610860565b5f60405180830381855af49150503d805f8114610648576040519150601f19603f3d011682016040523d82523d5f602084013e61064d565b606091505b509150915061065e86838387610668565b9695505050505050565b606083156106d65782515f036106cf576001600160a01b0385163b6106cf5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610145565b50816106e0565b6106e083836106e8565b949350505050565b8151156106f85781518083602001fd5b8060405162461bcd60e51b81526004016101459190610876565b80356001600160a01b0381168114610728575f5ffd5b919050565b5f6020828403121561073d575f5ffd5b6105eb82610712565b634e487b7160e01b5f52604160045260245ffd5b5f5f5f6060848603121561076c575f5ffd5b61077584610712565b925061078360208501610712565b9150604084013567ffffffffffffffff81111561079e575f5ffd5b8401601f810186136107ae575f5ffd5b803567ffffffffffffffff8111156107c8576107c8610746565b604051601f8201601f19908116603f0116810167ffffffffffffffff811182821017156107f7576107f7610746565b60405281815282820160200188101561080e575f5ffd5b816020840160208301375f602083830101528093505050509250925092565b818103818111156105ee57634e487b7160e01b5f52601160045260245ffd5b634e487b7160e01b5f52600160045260245ffd5b5f82518060208501845e5f920191825250919050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f8301168401019150509291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212209ae735e49084e16b99358fb702cfb6f6a334bc5393d7fb7696e3461ff6ac432864736f6c634300081c00330c97b5255f0de5334f50bb470d8db2f56626f0853111cf4e5cf766ee733df0954f553160b42df491db35bec3ebf76087a7aafa0e5e9e36ed07e5c1cc2da9420c4b234e157ec597b29eb13fb5f6fbaf8eca49e05121e1b23c0e27e47b000e430ca2646970667358221220a032b5a77a57774cb9f9d15279de481641edc82dc3fba29be9db6cbcb4284b8a64736f6c634300081c0033
Verified Source Code Partial Match
Compiler: v0.8.28+commit.7893614a
EVM: cancun
Optimization: Yes (200 runs)
ProxyInitializable.sol 51 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import "@openzeppelin/contracts/proxy/Proxy.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol";
/**
* @title ProxyInitializable
* @dev ProxyInitializable contract providing upgradability
* @author Altitude Labs
**/
contract ProxyInitializable is Proxy, ERC1967Upgrade {
/// @notice Used as a constructor due to create2 with no params
function initialize(address _admin, address _logic, bytes memory _data) external {
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
require(_implementation() == address(0) && _logic != address(0), "ALREADY_INITIALIZED");
_upgradeToAndCall(_logic, _data, false);
_changeAdmin(_admin);
}
/// @notice Returns the current implementation address.
function _implementation() internal view virtual override returns (address impl) {
return ERC1967Upgrade._getImplementation();
}
/// @notice Set the new implementation of a vault
/// @param newImplementation Address of the implementation contract
function upgradeTo(address newImplementation) external {
require(_getAdmin() == msg.sender, "NOT_PROXY_ADMIN");
require(newImplementation != address(0), "ZERO_IMPLEMENTATION_NOT_ALLOWED");
_upgradeTo(newImplementation);
}
/// @notice Transfers admin rights
/// @param newAdmin Address of the new proxy adminsitrator
function changeAdmin(address newAdmin) external {
require(_getAdmin() == msg.sender, "NOT_PROXY_ADMIN");
_changeAdmin(newAdmin);
}
/// @notice Returns the admin
function getAdmin() external view returns (address) {
return _getAdmin();
}
}
Roles.sol 14 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/**
* @title Roles definition
* @dev Library for roles
* @author Altitude Labs
**/
library Roles {
bytes32 internal constant ALPHA = keccak256("ALPHA");
bytes32 internal constant BETA = keccak256("BETA");
bytes32 internal constant GAMMA = keccak256("GAMMA");
}
IBorrowVerifier.sol 24 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
/**
* @author Altitude Protocol
**/
interface IBorrowVerifier {
// Borrow Verifier Errors
error BV_DEADLINE_PASSED();
error BV_INVALID_SIGNATURE();
error BV_ONLY_VAULT();
error BV_INVALID_VAULT();
function nonce(address) external returns (uint256);
function verifyAndBurnNonce(
uint256 amount,
address onBehalfOf,
address receiver,
uint256 deadline,
bytes calldata signature
) external;
}
IFlashLoanCallback.sol 10 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
/**
* @author Altitude Protocol
**/
interface IFlashLoanCallback {
function flashLoanCallback(bytes calldata, uint256) external;
}
IDebtToken.sol 18 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "./IInterestToken.sol";
/**
* @author Altitude Protocol
**/
interface IDebtToken is IInterestToken {
// Debt token Errors
error DT_APPROVAL_NOT_SUPPORTED();
error DT_TRANSFER_NOT_SUPPORTED();
error DT_ALLOWANCE_INCREASE_NOT_SUPPORTED();
error DT_ALLOWANCE_DECREASE_NOT_SUPPORTED();
function balanceOfDetails(address account) external view returns (uint256, uint256, uint256);
}
IInterestToken.sol 66 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
/**
* @author Altitude Protocol
**/
interface IInterestToken is IERC20Upgradeable, IERC20MetadataUpgradeable {
event UserSnapshot(address account, uint256 _interestIndex);
// Interest Token Errors
error IT_ONLY_VAULT();
error IT_MINT_MORE_THAN_SIZE();
error IT_INTEREST_INDEX_OUT_OF_RANGE();
error IT_TRANSFER_BETWEEN_THE_SAME_ADDRESSES();
function MATH_UNITS() external view returns (uint256);
function vault() external view returns (address);
function underlying() external view returns (address);
function activeLenderStrategy() external view returns (address);
function userIndex(address user) external view returns (uint256);
function interestIndex() external view returns (uint256);
function initialize(
string memory name,
string memory symbol,
address vaultAddress,
address underlyingAsset,
address lenderStrategy,
uint256 mathUnits
) external;
function mint(address account, uint256 amount) external;
function burn(address account, uint256 amount) external;
function vaultTransfer(address owner, address to, uint256 amount) external returns (bool);
function setActiveLenderStrategy(address newStrategy) external;
function snapshotUser(address account) external returns (uint256, uint256);
function snapshot() external;
function calcNewIndex() external view returns (uint256 index);
function calcIndex(uint256 balanceOld, uint256 balanceNew) external view returns (uint256);
function balanceStored(address account) external view returns (uint256);
function setInterestIndex(uint256 newIndex) external;
function setBalance(address account, uint256 newBalance, uint256 newIndex) external;
function storedTotalSupply() external view returns (uint256);
function balanceOfAt(address account, uint256 snapshotId) external view returns (uint256);
}
ISupplyToken.sol 19 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "./IDebtToken.sol";
import "./IInterestToken.sol";
/**
* @author Altitude Protocol
**/
interface ISupplyToken is IInterestToken {
// Supply token Errors
error ST_NOT_ENOUGH_BALANCE();
error ST_NOT_ENOUGH_ALLOWANCE();
function transferMax(address to) external returns (bool);
function transferFromMax(address from, address to) external returns (bool);
}
ITokensFactory.sol 41 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
/**
* @author Altitude Protocol
**/
interface ITokensFactory {
error TF_ZERO_ADDRESS();
error TF_ONLY_REGISTRY();
event UpdateProxyAdmin(address newProxyAdmin);
event SetRegistry(address newRegistryAddress);
event SetSupplyTokenImplementation(address implementation);
event SetDebtTokenImplementation(address implementation);
function registry() external view returns (address);
function debtTokenImplementation() external view returns (address);
function supplyTokenImplementation() external view returns (address);
function proxyAdmin() external view returns (address);
function setRegistry(address newRegistryAddress) external;
function setSupplyTokenImplementation(address newSupplyTokenImplentation) external;
function setDebtTokenImplementation(address newDebtTokenImplentation) external;
function setProxyAdmin(address newProxyAdmin) external;
function createPair(
address vault,
address supplyAsset,
address borrowAsset,
uint256 supplyUnits,
uint256 borrowUnits,
address lenderStrategy
) external returns (address supplyTokenAddress, address debtTokenAddress);
}
IVaultCore.sol 72 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "./IVaultStorage.sol";
import "./extensions/groomable/IGroomableVault.sol";
import "./extensions/snapshotable/ISnapshotableVault.sol";
import "./extensions/liquidatable/ILiquidatableVault.sol";
import "./extensions/configurable/IConfigurableVault.sol";
/**
* @author Altitude Protocol
**/
interface IVaultCoreV1 is
IVaultStorage,
IConfigurableVaultV1,
IGroomableVaultV1,
ILiquidatableVaultV1,
ISnapshotableVaultV1
{
event Deposit(address indexed depositor, address indexed onBehalfOf, uint256 amount);
event Borrow(address indexed borrower, address indexed onBehalfOf, uint256 amount);
event Withdraw(
address indexed withdrawer,
address indexed recipient,
uint256 amount,
uint256 fee,
uint256 lenderFee
);
event Repay(address indexed repayer, address indexed onBehalfOf, uint256 amount);
event RepayBadDebt(address indexed repayer, address indexed onBehalfOf, uint256 amount);
// Vault Core V1 Errors
error VC_V1_USER_HAS_SUPPLY();
error VC_V1_NOT_ENOUGH_SUPPLY();
error VC_V1_INVALID_REPAY_AMOUNT();
error VC_V1_INVALID_BORROW_AMOUNT();
error VC_V1_INVALID_DEPOSIT_AMOUNT();
error VC_V1_INVALID_WITHDRAW_AMOUNT();
error VC_V1_ETH_INSUFFICIENT_AMOUNT();
error VC_V1_FARM_WITHDRAW_INSUFFICIENT();
error VC_V1_NOT_ALLOWED_TO_ACT_ON_BEHALF();
error VC_V1_NOT_AUTHORIZED_TO_DEAL_WITH_TRANSFERS();
error VC_V1_UNHEALTHY_VAULT_RISK();
error VC_V1_NO_DEBT_TO_REPAY();
function preTransfer(address from, address to, uint256 amount, bytes4 transferSelector) external;
function postTransfer(address from, address to) external;
function deposit(uint256 amount, address onBehalfOf) external payable;
function borrow(uint256 amount) external;
function borrowOnBehalfOf(uint256 amount, address onBehalfOf, uint256 deadline, bytes calldata signature) external;
function withdraw(uint256 amount, address to) external returns (uint256);
function repay(uint256 amount, address onBehalfOf) external returns (uint256);
function repayBadDebt(uint256 amount, address onBehalfOf) external returns (uint256);
function depositAndBorrow(uint256 depositAmount, uint256 borrowAmount) external payable;
function repayAndWithdraw(
uint256 repayAmount,
uint256 withdrawAmount,
address to
) external returns (uint256, uint256);
function calcWithdrawFee(address account, uint256 withdrawAmount) external view returns (uint256, uint256);
}
IVaultCoreV1Initializer.sol 32 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "../../../libraries/types/VaultTypes.sol";
/**
* @author Altitude Protocol
**/
interface IVaultCoreV1Initializer {
event SetTokens(address supplyInterestToken, address borrowInterestToken);
// Config Errors
error VCONF_V1_TARGET_THRESHOLD_OUT_OF_RANGE();
error VCONF_V1_SUPPLY_THRESHOLD_OUT_OF_RANGE();
error VCONF_V1_WITHDRAW_FEE_FACTOR_OUT_OF_RANGE();
error VCONF_V1_LIQUIDATION_THRESHOLD_OUT_OF_RANGE();
// Groomable Errors
error GR_V1_MIGRATION_PERCENTAGE_OUT_OF_RANGE();
// Liquidation Errors
error LQ_V1_MAX_BONUS_OUT_OF_RANGE();
error LQ_V1_MAX_POSITION_LIQUIDATION_OUT_OF_RANGE();
// Harvest Errors
error HV_V1_RESERVE_FACTOR_OUT_OF_RANGE();
function initialize(address contractOwner, VaultTypes.VaultData memory vaultData) external;
function setTokens(address supplyInterestToken, address borrowInterestToken) external;
}
IVaultRegistry.sol 160 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "../../../libraries/types/VaultTypes.sol";
/**
* @author Altitude Protocol
**/
interface IVaultRegistryV1 {
enum ManagingRoles {
FUNCTIONS,
FUNCTIONALITY,
EMERGENCY
}
event SetManager(address manager, ManagingRoles role);
event VaultDeployed(
address vault,
address indexed supplyAsset,
address indexed borrowAsset,
address supplyToken,
address debtToken
);
event UpdateVaultConfig(
address indexed vault,
address configurableManager,
address swapStrategy,
address ingressControl,
address borrowVerifier,
uint256 withdrawFeeFactor,
uint256 withdrawFeePeriod
);
event UpdateSnapshotableConfig(address indexed vault, address snapshotableManager, uint256 reserveFactor);
event UpdateGroomableConfig(
address indexed vault,
address groomableManager,
address flashLoanStrategy,
uint256 maxMigrationFeePercentage
);
event UpdateLiquidationConfig(
address indexed vault,
address liquidatableManager,
uint256 maxPositionLiquidation,
uint256 liquidationBonus
);
event UpdateBorrowLimits(
address indexed vault,
uint256 supplyThreshold,
uint256 liquidationThreshold,
uint256 targetThreshold
);
event DisableOnBehalfValidation(address indexed vault, bytes4[] functions, bool toDisable);
event WithdrawnReserve(address indexed vault, address receiver, uint256 amount, uint256 amountWithdrawn);
event InjectSupply(address indexed vault, uint256 amount);
event UpdateProxyAdmin(address newProxyAdmin);
event UpdateInitImpl(address newInitImpl);
event UpdateTokensFactory(address newTokensFactory);
event SetVaultReserveReceiver(address receiver);
event ReduceTargetThreshold(address indexed vault, uint256 targetThreshold);
// Vault Registry V1 Errors
error VR_V1_ZERO_ADDRESS();
error VR_V1_NONEXISTING_VAUlT();
error VR_V1_NOT_EMERGENCY_MANAGER();
error VR_V1_NOT_FUNCTIONS_MANAGER();
error VR_V1_ALREADY_EXISTING_VAULT();
error VR_V1_NOT_FUNCTIONALITY_MANAGER();
function tokensFactory() external view returns (address);
function vaultInitImpl() external view returns (address);
function vaultInitCodeHash() external view returns (bytes32);
function proxyAdmin() external view returns (address);
function vaultsArray(uint256 index) external view returns (address);
function vaults(address supplyAsset, address borrowAsset) external view returns (address);
function initialize(VaultTypes.RegistryConfiguration memory config) external;
function vaultAddress(address supplyAsset, address borrowAsset) external view returns (address);
function vaultReserveReceiver() external view returns (address);
function createVault(
address supplyAsset,
address borrowAsset,
uint256 supplyMathUnits,
uint256 debtMathUnits,
address vaultLogic,
VaultTypes.VaultData memory vaultData
) external;
function harvestVault(address supplyAsset, address borrowAsset, uint256 price) external;
function injectBorrowAssetsInVault(address supplyAsset, address borrowAsset, uint256 amount) external;
function changeVaultLendingProvider(address supplyAsset, address borrowAsset, address newProvider) external;
function changeVaultFarmDispatcher(address supplyAsset, address borrowAsset, address newFarmDispatcher) external;
function setVaultConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.VaultConfig memory vaultConfig
) external;
function setSnapshotableConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.SnapshotableConfig memory snapshotableConfig
) external;
function setGroomableConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.GroomableConfig memory groomableConfig
) external;
function setLiquidationConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.LiquidatableConfig memory liquidatableConfig
) external;
function setVaultBorrowLimits(
address supplyAsset,
address borrowAsset,
VaultTypes.BorrowLimits memory borrowLimits
) external;
function reduceVaultTargetThreshold(address supplyAsset, address borrowAsset, uint256 targetThreshold) external;
function setProxyAdmin(address newProxyAdmin) external;
function setInitImpl(address newInitImpl) external;
function setTokensFactory(address newTokensFactory) external;
function disableVaultOnBehalfValidation(
address supplyAsset,
address borrowAsset,
bytes4[] memory functions,
bool toDisable
) external;
function setVaultReserveReceiver(address receiver) external;
function withdrawVaultReserve(address supplyAsset, address borrowAsset, uint256 amount) external;
function injectSupplyInVault(address supplyAsset, address borrowAsset, uint256 amount, uint256 index) external;
function vaultsCount() external view returns (uint256);
}
IVaultStorage.sol 57 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "../tokens/ISupplyToken.sol";
import "../tokens/IDebtToken.sol";
import "../misc/IBorrowVerifier.sol";
/**
* @author Altitude Protocol
**/
interface IVaultStorage {
// Vault Storage V1 Errors
error VS_V1_ONLY_OWNER();
function owner() external view returns (address);
function supplyToken() external view returns (ISupplyToken);
function debtToken() external view returns (IDebtToken);
function supplyUnderlying() external view returns (address);
function borrowUnderlying() external view returns (address);
function borrowVerifier() external view returns (IBorrowVerifier);
function userLastDepositBlock(address) external view returns (uint256);
function withdrawFeeFactor() external view returns (uint256);
function withdrawFeePeriod() external view returns (uint256);
function supplyThreshold() external view returns (uint256);
function liquidationThreshold() external view returns (uint256);
function targetThreshold() external view returns (uint256);
function activeFarmStrategy() external view returns (address);
function activeLenderStrategy() external view returns (address);
function allowOnBehalfList(address, address) external view returns (bool);
function onBehalfFunctions(bytes4) external view returns (bool);
function snapshots(uint256) external view returns (uint256, uint256, uint256, uint256);
function userSnapshots(address) external view returns (uint256);
function configurableManager() external view returns (address);
function swapStrategy() external view returns (address);
function ingressControl() external view returns (address);
}
IConfigurableVault.sol 36 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
/**
* @author Altitude Protocol
**/
interface IConfigurableVaultV1 {
// Configurable vault Errors
error VCONF_V1_TARGET_THRESHOLD_NOT_REDUCED();
error VCONF_V1_TARGET_THRESHOLD_OUT_OF_RANGE();
error VCONF_V1_SUPPLY_THRESHOLD_OUT_OF_RANGE();
error VCONF_V1_WITHDRAW_FEE_FACTOR_OUT_OF_RANGE();
error VCONF_V1_LIQUIDATION_THRESHOLD_OUT_OF_RANGE();
function setConfig(
address confugrableManager_,
address swapStrategy_,
address ingressControl_,
address borrowVerifier_,
uint256 withdrawFeeFactor_,
uint256 withdrawFeePeriod_
) external;
function setBorrowLimits(
uint256 supplyThreshold_,
uint256 liquidationThreshold_,
uint256 targetThreshold_
) external;
function reduceTargetThreshold(uint256 targetThreshold_) external;
function allowOnBehalf(address[] memory allowees, bool toAllow) external;
function disableOnBehalfValidation(bytes4[] memory functions, bool toDisable) external;
}
IGroomableManager.sol 33 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "../../../strategy/IFlashLoanCallback.sol";
/**
* @author Altitude Protocol
**/
interface IGroomableManager is IFlashLoanCallback {
event RebalanceVaultLimit(bool shouldBorrow, uint256 calculatedAmount);
event RebalanceVaultBorrow(uint256 amountToBorrow);
event RebalanceVaultRepay(uint256 amountToRepay, uint256 amountWithdrawn);
event MigrateLenderStrategy(address oldStrategy, address newStrategy);
event MigrateFarmDispatcher(address oldFarmDispatcher, address newFarmDispatcher);
// Groomable Manager Errors
error GR_V1_MIGRATION_FEE_TOO_HIGH();
error GR_V1_NOT_FLASH_LOAN_STRATEGY();
error GR_V1_MIGRATION_OLD_SUPPLY_ERROR();
error GR_V1_MIGRATION_OLD_BORROW_ERROR();
error GR_V1_MIGRATION_NEW_SUPPLY_ERROR();
error GR_V1_MIGRATION_NEW_BORROW_ERROR();
error GR_V1_FARM_DISPATCHER_ALREADY_ACTIVE();
error GR_V1_FARM_DISPATCHER_NOT_EMPTY();
error GR_V1_LENDER_STRATEGY_ALREADY_ACTIVE();
function migrateLender(address newStrategy) external;
function migrateFarmDispatcher(address newFarmDispatcher) external;
function rebalance() external;
}
IGroomableVault.sol 24 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "../../../../../libraries/types/VaultTypes.sol";
import "./IGroomableManager.sol";
/**
* @author Altitude Protocol
**/
interface IGroomableVaultV1 is IGroomableManager {
// Groomable Vault Errors
error GR_V1_MIGRATION_PERCENTAGE_OUT_OF_RANGE();
function migrateLender(address newStrategy) external;
function migrateFarmDispatcher(address newFarmDispatcher) external;
function rebalance() external;
function setGroomableConfig(VaultTypes.GroomableConfig memory) external;
function getGroomableConfig() external view returns (address, address, uint256);
}
IHarvestableManager.sol 40 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
/**
* @author Altitude Protocol
**/
interface IHarvestableManager {
event Harvested(
uint256 harvestId,
uint256 distributableProfit,
uint256 vaultLoss,
uint256 uncommittedLossPerc,
uint256 claimableLossPerc
);
event ClaimedRewards(address indexed account, uint256 amountClaimed, uint256 debtRepayed);
event InjectedBorrowAssets(uint256 amount);
// Harvest Errors
error HM_V1_BLOCK_ERROR();
error HM_V1_INVALID_INJECT_AMOUNT();
error HM_V1_HARVEST_ERROR();
error HM_V1_PRICE_TOO_LOW();
error HM_V1_INVALID_COMMIT();
error HM_V1_CLAIM_REWARDS_ZERO();
error HV_V1_HM_NO_ACTIVE_ASSETS();
error HV_V1_RESERVE_FACTOR_OUT_OF_RANGE();
error HM_V1_TOO_BIG_FARM_LOSS(uint256 farmRewardsLoss);
error HM_V1_FARM_MODE_RESERVE_NOT_ENOUGH();
function harvest(uint256 price) external;
function withdrawReserve(address receiver, uint256 amount) external returns (uint256);
function claimRewards(uint256 amountRequested) external returns (uint256);
function injectBorrowAssets(uint256 amount) external;
}
IHarvestableVault.sol 26 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "./IHarvestableManager.sol";
import "../../../../../libraries/types/HarvestTypes.sol";
/**
* @author Altitude Protocol
**/
interface IHarvestableVaultV1 is IHarvestableManager {
function claimableRewards(address account) external view returns (uint256);
function reserveAmount() external view returns (uint256);
function getHarvest(uint256 id) external view returns (HarvestTypes.HarvestData memory);
function getHarvestsCount() external view returns (uint256);
function getUserHarvest(address user) external view returns (HarvestTypes.UserHarvestData memory);
function getHarvestData()
external
view
returns (uint256 realClaimableEarnings, uint256 realUncommittedEarnings, uint256 vaultReserve);
}
ILiquidatableManager.sol 20 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
/**
* @author Altitude Protocol
**/
interface ILiquidatableManager {
event LiquidateUser(address user, uint256 supplyTaken, uint256 borrowRepaid);
event LiquidateUserDefault(address user, uint256 borrowRemaining);
// Liquidation Errors
error LQ_V1_MAX_BONUS_OUT_OF_RANGE();
error LQ_V1_LIQUIDATION_CONSTRAINTS();
error LQ_V1_INSUFFICIENT_REPAY_AMOUNT();
error LQ_V1_MAX_POSITION_LIQUIDATION_OUT_OF_RANGE();
function liquidateUsers(address[] calldata usersForLiquidation, uint256 repayAmountLimit) external;
}
ILiquidatableVault.sol 17 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "./ILiquidatableManager.sol";
import "../../../../../libraries/types/VaultTypes.sol";
/**
* @author Altitude Protocol
**/
interface ILiquidatableVaultV1 is ILiquidatableManager {
function isUserForLiquidation(address userAddress) external view returns (bool isUserForLiquidator);
function setLiquidationConfig(VaultTypes.LiquidatableConfig memory liqConfig) external;
function getLiquidationConfig() external view returns (address, uint256, uint256);
}
ISnapshotableManager.sol 29 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "../harvestable/IHarvestableManager.sol";
import "../supply-loss/ISupplyLossManager.sol";
/**
* @author Altitude Protocol
**/
interface ISnapshotableManager is IHarvestableManager, ISupplyLossManager {
event UserCommit(
address account,
uint256 supplyIndex,
uint256 supplyBalance,
uint256 borrowIndex,
uint256 borrowBalance,
uint256 userHarvestUncommittedEarnings
);
event InjectSupply(uint256 actualInjected, uint256 amountToInject);
function updatePosition(address account) external payable returns (uint256);
function updatePositionTo(address account, uint256 snapshotId) external returns (uint256);
function updatePositions(address[] calldata accounts) external returns (uint256);
function injectSupply(uint256 targetTotalSupply, uint256 atIndex, address funder) external;
}
ISnapshotableVault.sol 26 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "./ISnapshotableManager.sol";
import "../harvestable/IHarvestableVault.sol";
import "../supply-loss/ISupplyLossVault.sol";
import "../../../../../libraries/types/VaultTypes.sol";
/**
* @author Altitude Protocol
**/
interface ISnapshotableVaultV1 is ISnapshotableManager, IHarvestableVaultV1, ISupplyLossVaultV1 {
function setSnapshotableConfig(VaultTypes.SnapshotableConfig memory config) external;
function getSnapshotableConfig() external view returns (address, uint256);
function calcCommitUser(
address account,
uint256 snapshotId
) external view returns (HarvestTypes.UserCommit memory commit);
function totalSnapshots() external view returns (uint256);
function getSnapshot(uint256 id) external view returns (CommonTypes.SnapshotType memory);
}
ISupplyLossManager.sol 18 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
/**
* @author Altitude Protocol
**/
interface ISupplyLossManager {
event SupplyLossSnapshot(uint256 snapshotId);
event WithdrawVaultBorrows(uint256 withdrawn, uint256 vaultBorrows);
event InjectVaultWindfall(uint256 vaultWindfall, uint256 expectedAmountOut, uint256 amountOut, uint256 slippageFee);
event RepayVaultRemaining(uint256 vaultBorrowsRemaining, uint256 maxBalance);
function snapshotSupplyLoss() external;
}
ISupplyLossVault.sol 13 lines
// SPDX-License-Identifier: AGPL-3.0.
pragma solidity 0.8.28;
import "./ISupplyLossManager.sol";
import "../../../../../libraries/types/SupplyLossTypes.sol";
/**
* @author Altitude Protocol
**/
interface ISupplyLossVaultV1 is ISupplyLossManager {
function getSupplyLossSnapshot(uint256 id) external view returns (SupplyLossTypes.SupplyLoss memory);
}
CommonTypes.sol 32 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/**
* @title CommonTypes
* @dev Input parameters for not having "Stack too deep"
* @author Altitude Labs
**/
library CommonTypes {
/// @notice struct for the supply and borrow position of a user
struct UserPosition {
uint256 supplyIndex; // supplyIndex for the user
uint256 supplyBalance; // supplyBalance for the user
uint256 borrowIndex; // borrowIndex for the user
uint256 borrowBalance; // borrowBalance for the user
}
/// @notice defines the different types of snapshots
enum SnapshotClass {
Harvest,
SupplyLoss
}
/// @notice struct for different commit types
struct SnapshotType {
uint256 id; // id of the snapshot
uint256 kind; // kind of the snapshot, where 0 is harvest, 1 is supply loss
uint256 supplyIndex; // supplyIndex for the snapshot
uint256 borrowIndex; // borrowIndex for the snapshot
}
}
HarvestTypes.sol 56 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import "./CommonTypes.sol";
/**
* @title HarvestTypes
* @notice Harvest storage types
* @author Altitude Labs
**/
library HarvestTypes {
/// @notice track the committable data for a user, detailing incremental adjustements to the user position
struct UserCommit {
uint256 blockNumber; // block number of the commit
uint256 harvestId; // harvest id of the commit
uint256 userClaimableEarnings; // user claimable earnings
uint256 userHarvestJoiningBlock; // user harvest joining block
uint256 userHarvestUncommittedEarnings; // user harvest uncommitted earnings
uint256 vaultReserveUncommitted; // vault reserve uncommitted
CommonTypes.UserPosition position; // user position
}
/// @notice track data for a single harvest, used for commit calculations
struct HarvestData {
uint256 harvestId; // harvest id
uint256 farmEarnings; // farm earnings in the harvest
uint256 vaultLoss; // farm loss applicable for the vault balance
uint256 uncommittedLossPerc; // farm loss applicable in percentage for the uncommitted earnings
uint256 claimableLossPerc; // farm loss applicable in percentage for the claimable rewards
uint256 activeAssetsThreshold; // active assets threshold for the harvest
uint256 divertEarningsThreshold; // divert earnings threshold for the harvest
uint256 vaultActiveAssets; // vault active assets
uint256 price; // price for the harvest
uint256 blockNumber; // block number for the harvest
}
/// @notice track data for a user's harvest
struct UserHarvestData {
uint256 harvestId; // harvest id
uint256 harvestJoiningBlock; // harvest joining block
uint256 claimableEarnings; // claimable earnings
uint256 uncommittedEarnings; // uncommitted earnings (needed for partial commits)
uint256 vaultReserveUncommitted; // vault reserve uncommitted (needed for partial commits)
}
/// @notice harvest storage for multiple harvests, used for commit calculations
struct HarvestStorage {
uint256 vaultReserve; // amount allocated to the vault reserve
uint256 realClaimableEarnings; // total amount of known claimable earnings (users have committed)
uint256 realUncommittedEarnings; // total amount of uncommitted earnings (prior to type allocation during commit)
HarvestData[] harvests; // array of all harvests
uint256 reserveFactor; // percentage of earnings to be allocated to the reserve
mapping(address => UserHarvestData) userHarvest; // user => userHarvestData - harvest data for users
}
}
SupplyLossTypes.sol 26 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/**
* @title SupplyLossTypes
* @dev Input parameters for not having "Stack too deep"
* @author Altitude Labs
**/
library SupplyLossTypes {
// @notice track data for a supply loss
struct SupplyLoss {
uint256 supplyLossAtSnapshot; // total reduction of supply, less fees
uint256 supplyLossProfit; // interest earned on supply (if any, zero if supplyLossAtSnapshot > 0)
uint256 borrowLossAtSnapshot; // total reduction of borrows
uint256 supplyBalanceAtSnapshot; // vault total supplied at snapshot
uint256 borrowBalanceAtSnapshot; // vault total user borrows at snapshot
uint256 fee; // combination of liquidation penalty, slippage and deposit fees
uint256 withdrawShortage; // vault farm balance less farm withdrawal amount (if any)
}
// @notice supply loss storage
struct SupplyLossStorage {
SupplyLoss[] supplyLosses; // array of all supply loss snapshots
}
}
VaultTypes.sol 76 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/**
* @title VaultTypes
* @dev Input parameters for not having "Stack too deep"
* @author Altitude Labs
**/
library VaultTypes {
/// @notice RegistryConfiguration parameters
struct RegistryConfiguration {
address registryAdmin; // global registry admin used to grant roles/access
address tokensFactory; // tokens factory implementation
address vaultInitImpl; // vault init implementation
address proxyAdmin; // proxy admin implementation
}
/// @notice Vault BorrowLimit configuration parameters
struct BorrowLimits {
uint256 supplyThreshold; // loan-to-value up to which the user can borrow
uint256 liquidationThreshold; // loan-to-value after which the user can be liquidated
uint256 targetThreshold; // loan-to-value the vault targets to rebalance to
}
/// @notice Vault DefiProviders configuration parameters
struct DefiProviders {
address lending; // address of lending provider
address farming; // address of farming provider
}
/// @notice Vault configuration parameters
struct SnapshotableConfig {
address snapshotableManager; // snapshotable manager implementation
uint256 reserveFactor; // percentage of earnings to be allocated to the reserve
}
/// @notice Vault configuration parameters
struct VaultConfig {
address borrowVerifier; // borrow verifier implementation
uint256 withdrawFeeFactor; // percentage of the withdraw fee
uint256 withdrawFeePeriod; // number of blocks the withdraw fee is applied
address configurableManager; // configurable manager implementation
address swapStrategy; // swap strategy implementation
address ingressControl; // ingress control implementation
}
/// @notice Vault Liquidation configuration parameters
struct LiquidatableConfig {
address liquidatableManager; // liquidatable manager implementation
uint256 maxPositionLiquidation; // The maximum liquidation allowed by the contract, 18 decimals
uint256 liquidationBonus; // The supply bonus that will be received by the liquidator, 18 decimals
}
/// @notice Vault Groomable configuration parameters
struct GroomableConfig {
address groomableManager; // groomable manager implementation
address flashLoanStrategy; // flash loan strategy implementation
uint256 maxMigrationFeePercentage; // a fixed percentage to check if the given flash loan strategy charges higher fees than we expect
}
/// @notice Vault Init configuration parameters
struct VaultInit {
VaultConfig vaultConfig; // vault configuration
BorrowLimits borrowLimits; // borrow limits
DefiProviders providers; // defi providers
}
/// @notice Vault Data parameters
struct VaultData {
VaultInit vaultInit; // vault init configuration
LiquidatableConfig liquidatableConfig; // liquidatable configuration
GroomableConfig groomableConfig; // groomable configuration
SnapshotableConfig snapshotableConfig; // snapshotable configuration
}
}
TransferHelper.sol 66 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.28;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title Transfer Helper Library
* @dev Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false
* @author Uniswap
**/
library TransferHelper {
// Tranfer helper library Errors
error TH_SAFE_TRANSFER_FAILED();
error TH_SAFE_TRANSFER_FROM_FAILED();
error TH_SAFE_TRANSFER_NATIVE_FAILED();
error TH_SAFE_APPROVE();
error TH_SAFE_APPROVE_RESET();
function safeTransfer(address token, address to, uint256 value) internal {
bool toThrow = _call(token, abi.encodeWithSelector(IERC20.transfer.selector, to, value));
if (toThrow) {
revert TH_SAFE_TRANSFER_FAILED();
}
}
function safeTransferFrom(address token, address from, address to, uint256 value) internal {
bool toThrow = _call(token, abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
if (toThrow) {
revert TH_SAFE_TRANSFER_FROM_FAILED();
}
}
/// @notice Approves the stipulated contract to spend the given allowance in the given token
/// @dev Errors with 'SA' if transfer fails
/// @param token The contract address of the token to be approved
/// @param to The target of the approval
/// @param value The amount of the given token the target will be allowed to spend
function safeApprove(address token, address to, uint256 value) internal {
// Reset approval first
bool toThrow = _call(token, abi.encodeWithSelector(IERC20.approve.selector, to, 0));
if (toThrow) {
revert TH_SAFE_APPROVE_RESET();
}
toThrow = _call(token, abi.encodeWithSelector(IERC20.approve.selector, to, value));
if (toThrow) {
revert TH_SAFE_APPROVE();
}
}
function _call(address token, bytes memory data) internal returns (bool) {
(bool success, bytes memory resultData) = token.call(data);
if (!success || (resultData.length > 0 && !abi.decode(resultData, (bool)))) {
return true;
}
return false;
}
function safeTransferNative(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
if (!success) {
revert TH_SAFE_TRANSFER_NATIVE_FAILED();
}
}
}
VaultRegistry.sol 455 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "../../libraries/types/VaultTypes.sol";
import "../../libraries/uniswap-v3/TransferHelper.sol";
import "../../interfaces/internal/vault/IVaultCore.sol";
import "../../interfaces/internal/vault/IVaultCoreV1Initializer.sol";
import "../../interfaces/internal/vault/IVaultRegistry.sol";
import "../../interfaces/internal/vault/extensions/liquidatable/ILiquidatableVault.sol";
import "../../interfaces/internal/tokens/ITokensFactory.sol";
import "../../common/Roles.sol";
import "../../common/ProxyInitializable.sol";
/**
* @title VaultRegistryV1
* @dev Contract responsible for Creating, Managing & Configuring vaults
* @dev Each vault represents a unique `supplyAsset` <-> `borrowAsset` pair
* @author Altitude Labs
**/
contract VaultRegistryV1 is AccessControl, Initializable, IVaultRegistryV1 {
address public override tokensFactory;
/** @notice vault initialization implementations */
address public override vaultInitImpl;
/** @notice vault initialization code hash */
bytes32 public constant override vaultInitCodeHash =
keccak256(abi.encodePacked(type(ProxyInitializable).creationCode));
/** @notice address allowed to upgrade vaults */
address public override proxyAdmin;
/** @notice address to receive vault fees */
address public override vaultReserveReceiver;
/** @notice for FrontEnd convinience */
address[] public override vaultsArray;
/** @notice Available vaults (ETH -> [ USDC -> Vault ]) */
mapping(address => mapping(address => address)) public override vaults;
/** @notice Check if a vault already exists for the token pair */
modifier onlyNotExisingVault(address supplyAsset, address borrowAsset) {
_onlyNotExisingVault(supplyAsset, borrowAsset);
_;
}
/// @notice Check that a vault already exists for the token pair
/// @param supplyAsset vault supply asset
/// @param borrowAsset vault borrow asset
modifier onlyExistingVault(address supplyAsset, address borrowAsset) {
_onlyExistingVault(supplyAsset, borrowAsset);
_;
}
function initialize(VaultTypes.RegistryConfiguration calldata config) external override initializer {
if (
config.tokensFactory == address(0) ||
config.vaultInitImpl == address(0) ||
config.proxyAdmin == address(0) ||
config.registryAdmin == address(0)
) {
revert VR_V1_ZERO_ADDRESS();
}
tokensFactory = config.tokensFactory;
vaultInitImpl = config.vaultInitImpl;
proxyAdmin = config.proxyAdmin;
_grantRole(DEFAULT_ADMIN_ROLE, config.registryAdmin);
}
function vaultAddress(address supplyAsset, address borrowAsset) external view override returns (address) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
address(this),
keccak256(abi.encodePacked(supplyAsset, borrowAsset)),
vaultInitCodeHash
)
)
)
)
);
}
/// @notice Deploys a new Vault for `erc20 supply asset` <-> `erc20 borrow asset` pair
/// @param supplyAsset The address of supply asset
/// @param borrowAsset The address of the borrow asset
/// @param vaultCoreImpl The address of the vault core implementation
/// @param vaultData Vault configuration params
function createVault(
address supplyAsset,
address borrowAsset,
uint256 supplyMathUnits,
uint256 debtMathUnits,
address vaultCoreImpl,
VaultTypes.VaultData memory vaultData
) external override onlyRole(Roles.BETA) onlyNotExisingVault(supplyAsset, borrowAsset) {
bytes32 salt = keccak256(abi.encodePacked(supplyAsset, borrowAsset));
ProxyInitializable vaultProxy = new ProxyInitializable{salt: salt}();
vaultProxy.initialize(
address(this),
vaultInitImpl,
abi.encodeWithSelector(IVaultCoreV1Initializer.initialize.selector, address(this), vaultData)
);
_setupVault(
address(vaultProxy),
vaultCoreImpl,
supplyAsset,
borrowAsset,
supplyMathUnits,
debtMathUnits,
vaultData.vaultInit.providers.lending
);
}
/// @notice Perform some validations and set SupplyToken and DebtToken of the vault
/// @param vault The newly deployed vault
/// @param vaultCoreImpl The core logic of the vault
/// @param supplyAsset The asset to supply
/// @param borrowAsset The asset to borrow
/// @param lenderStrategy The active lender strategy of the vault
function _setupVault(
address vault,
address vaultCoreImpl,
address supplyAsset,
address borrowAsset,
uint256 supplyMathUnits,
uint256 debtMathUnits,
address lenderStrategy
) internal {
(address supplyToken, address debtToken) = ITokensFactory(tokensFactory).createPair(
vault,
supplyAsset,
borrowAsset,
supplyMathUnits,
debtMathUnits,
lenderStrategy
);
IVaultCoreV1Initializer(vault).setTokens(supplyToken, debtToken);
ProxyInitializable(payable(vault)).upgradeTo(vaultCoreImpl);
ProxyInitializable(payable(vault)).changeAdmin(proxyAdmin);
vaultsArray.push(vault);
vaults[supplyAsset][borrowAsset] = vault;
emit VaultDeployed(vault, supplyAsset, borrowAsset, supplyToken, debtToken);
}
/// @notice Updates the external contracts for the vault
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param config vault external contracts
function setVaultConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.VaultConfig memory config
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).setConfig(
config.configurableManager,
config.swapStrategy,
config.ingressControl,
config.borrowVerifier,
config.withdrawFeeFactor,
config.withdrawFeePeriod
);
emit UpdateVaultConfig(
vaults[supplyAsset][borrowAsset],
config.configurableManager,
config.swapStrategy,
config.ingressControl,
config.borrowVerifier,
config.withdrawFeeFactor,
config.withdrawFeePeriod
);
}
/// @notice Updates the limit parameters of a vault
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param config Reserve factor and harvest limit
function setSnapshotableConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.SnapshotableConfig memory config
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).setSnapshotableConfig(config);
emit UpdateSnapshotableConfig(
vaults[supplyAsset][borrowAsset],
config.snapshotableManager,
config.reserveFactor
);
}
/// @notice Updates the groomable parameters
/// @param supplyAsset The address of supply asset
/// @param borrowAsset The address of the borrow asset
/// @param groomableConfig groomable config
function setGroomableConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.GroomableConfig memory groomableConfig
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).setGroomableConfig(groomableConfig);
emit UpdateGroomableConfig(
vaults[supplyAsset][borrowAsset],
groomableConfig.groomableManager,
groomableConfig.flashLoanStrategy,
groomableConfig.maxMigrationFeePercentage
);
}
/// @notice Updates the liquidation config
/// @param supplyAsset The address of supply asset
/// @param borrowAsset The address of the borrow asset
/// @param liquidatableConfig liquidation config
function setLiquidationConfig(
address supplyAsset,
address borrowAsset,
VaultTypes.LiquidatableConfig memory liquidatableConfig
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).setLiquidationConfig(liquidatableConfig);
emit UpdateLiquidationConfig(
vaults[supplyAsset][borrowAsset],
liquidatableConfig.liquidatableManager,
liquidatableConfig.maxPositionLiquidation,
liquidatableConfig.liquidationBonus
);
}
/// @notice Updates the limit parameters of a vault
/// @param supplyAsset The address of supply asset
/// @param borrowAsset The address of the borrow asset
/// @param borrowLimits Borrow limits per vault and user
function setVaultBorrowLimits(
address supplyAsset,
address borrowAsset,
VaultTypes.BorrowLimits memory borrowLimits
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).setBorrowLimits(
borrowLimits.supplyThreshold,
borrowLimits.liquidationThreshold,
borrowLimits.targetThreshold
);
emit UpdateBorrowLimits(
vaults[supplyAsset][borrowAsset],
borrowLimits.supplyThreshold,
borrowLimits.liquidationThreshold,
borrowLimits.targetThreshold
);
}
/// @notice Reduce target threshold to reduce the risk of vault being liquidated
/// @param supplyAsset The address of supply asset
/// @param borrowAsset The address of the borrow asset
/// @param targetThreshold The new target threshold
function reduceVaultTargetThreshold(
address supplyAsset,
address borrowAsset,
uint256 targetThreshold
) external override onlyRole(Roles.GAMMA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).reduceTargetThreshold(targetThreshold);
emit ReduceTargetThreshold(vaults[supplyAsset][borrowAsset], targetThreshold);
}
/// @notice Set who can upgrade vaults implementation
/// @param newProxyAdmin The address allowed to upgrade vaults
function setProxyAdmin(address newProxyAdmin) external override onlyRole(Roles.ALPHA) {
if (newProxyAdmin == address(0)) {
revert VR_V1_ZERO_ADDRESS();
}
proxyAdmin = newProxyAdmin;
emit UpdateProxyAdmin(newProxyAdmin);
}
/// @notice Set the config implementation for all of the vaults
/// @param newInitImpl The address the new implementation
function setInitImpl(address newInitImpl) external override onlyRole(Roles.BETA) {
if (newInitImpl == address(0)) {
revert VR_V1_ZERO_ADDRESS();
}
vaultInitImpl = newInitImpl;
emit UpdateInitImpl(newInitImpl);
}
/// @notice Set the tokens factory
/// @param newTokensFactory The address the new implementation
function setTokensFactory(address newTokensFactory) external override onlyRole(Roles.BETA) {
if (newTokensFactory == address(0)) {
revert VR_V1_ZERO_ADDRESS();
}
tokensFactory = newTokensFactory;
emit UpdateTokensFactory(newTokensFactory);
}
/// @notice Initiate harvest of a vault
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param price For harvest execution requirements
function harvestVault(
address supplyAsset,
address borrowAsset,
uint256 price
) external override onlyRole(Roles.GAMMA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).harvest(price);
}
/// @notice Deposit funds directly into the farm to cover any rewards deficit in a restricted way
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param amount Borrow amount to be injected
function injectBorrowAssetsInVault(
address supplyAsset,
address borrowAsset,
uint256 amount
) external override onlyRole(Roles.GAMMA) onlyExistingVault(supplyAsset, borrowAsset) {
TransferHelper.safeTransferFrom(borrowAsset, msg.sender, address(this), amount);
TransferHelper.safeApprove(borrowAsset, vaults[supplyAsset][borrowAsset], amount);
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).injectBorrowAssets(amount);
}
/// @notice Move to a new lending provider in the vault
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param newProvider The provider to be migrated to
function changeVaultLendingProvider(
address supplyAsset,
address borrowAsset,
address newProvider
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).migrateLender(newProvider);
}
/// @notice Move to a new farm dispatcher contract
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param newFarmDispatcher The new FarmDispatcher contract
function changeVaultFarmDispatcher(
address supplyAsset,
address borrowAsset,
address newFarmDispatcher
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).migrateFarmDispatcher(newFarmDispatcher);
}
/// @notice Disable on behalf validation for a list of functions
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param functions The list of functions to disable on behalf validation for
/// @param toDisable The state of the on behalf validation
/// @dev This should only be applied if an upgrade removes risks related to this
function disableVaultOnBehalfValidation(
address supplyAsset,
address borrowAsset,
bytes4[] memory functions,
bool toDisable
) external override onlyRole(Roles.ALPHA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).disableOnBehalfValidation(functions, toDisable);
emit DisableOnBehalfValidation(vaults[supplyAsset][borrowAsset], functions, toDisable);
}
/// @notice Set address which is to receive vault reserve amount
/// @param receiver The address the fees will be transferred to
function setVaultReserveReceiver(address receiver) external override onlyRole(Roles.BETA) {
if (receiver == address(0)) {
revert VR_V1_ZERO_ADDRESS();
}
vaultReserveReceiver = receiver;
emit SetVaultReserveReceiver(receiver);
}
/// @notice Withdraw from the protocol reserve
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param amount The amount of fees to be transferred
function withdrawVaultReserve(
address supplyAsset,
address borrowAsset,
uint256 amount
) external override onlyRole(Roles.BETA) onlyExistingVault(supplyAsset, borrowAsset) {
if (vaultReserveReceiver == address(0)) {
revert VR_V1_ZERO_ADDRESS();
}
uint256 amountWithdrawn = IVaultCoreV1(vaults[supplyAsset][borrowAsset]).withdrawReserve(
vaultReserveReceiver,
amount
);
emit WithdrawnReserve(vaults[supplyAsset][borrowAsset], vaultReserveReceiver, amount, amountWithdrawn);
}
/// @notice Inject supply in the vault in case of supply loss
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
/// @param amount The amount of fees to be transferred
function injectSupplyInVault(
address supplyAsset,
address borrowAsset,
uint256 amount,
uint256 index
) external override onlyRole(Roles.GAMMA) onlyExistingVault(supplyAsset, borrowAsset) {
IVaultCoreV1(vaults[supplyAsset][borrowAsset]).injectSupply(amount, index, msg.sender);
emit InjectSupply(vaults[supplyAsset][borrowAsset], amount);
}
/// @notice Get the current vaults count (used by FE)
function vaultsCount() external view override returns (uint256) {
return vaultsArray.length;
}
// -------- Internal functions --------
/// @notice Check if the vault already exists
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
function _onlyNotExisingVault(address supplyAsset, address borrowAsset) internal view {
if (vaults[supplyAsset][borrowAsset] != address(0)) {
revert VR_V1_ALREADY_EXISTING_VAULT();
}
}
/// @notice Confirm the vault already exists
/// @param supplyAsset The address of the supply asset
/// @param borrowAsset The address of the borrow asset
function _onlyExistingVault(address supplyAsset, address borrowAsset) internal view {
if (vaults[supplyAsset][borrowAsset] == address(0)) {
revert VR_V1_NONEXISTING_VAUlT();
}
}
}
IERC20Upgradeable.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 IERC20Upgradeable {
/**
* @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);
}
IERC20MetadataUpgradeable.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @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);
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
IERC1967.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.3) (interfaces/IERC1967.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*
* _Available since v4.9._
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
ERC1967Upgrade.sol 171 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.3) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../interfaces/IERC1967.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
abstract contract ERC1967Upgrade is IERC1967 {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
Proxy.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
Initializable.sol 165 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/Address.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
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);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 functionCallWithValue(target, data, 0, "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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or 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 {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// 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);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
StorageSlot.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
Read Contract
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
proxyAdmin 0x3e47158c → address
supportsInterface 0x01ffc9a7 → bool
tokensFactory 0xcc1fdf16 → address
vaultAddress 0x89a06d35 → address
vaultInitCodeHash 0xdd2d8553 → bytes32
vaultInitImpl 0x61d71297 → address
vaultReserveReceiver 0x1f355bc6 → address
vaults 0x4d635e70 → address
vaultsArray 0x8707b255 → address
vaultsCount 0x88977738 → uint256
Write Contract 22 functions
These functions modify contract state and require a wallet transaction to execute.
changeVaultFarmDispatcher 0x2121cffb
address supplyAsset
address borrowAsset
address newFarmDispatcher
changeVaultLendingProvider 0x8a49a9c3
address supplyAsset
address borrowAsset
address newProvider
createVault 0xf5452265
address supplyAsset
address borrowAsset
uint256 supplyMathUnits
uint256 debtMathUnits
address vaultCoreImpl
tuple vaultData
disableVaultOnBehalfValidation 0x8e336bb9
address supplyAsset
address borrowAsset
bytes4[] functions
bool toDisable
grantRole 0x2f2ff15d
bytes32 role
address account
harvestVault 0x5986820d
address supplyAsset
address borrowAsset
uint256 price
initialize 0x588570a5
tuple config
injectBorrowAssetsInVault 0x731ca4a1
address supplyAsset
address borrowAsset
uint256 amount
injectSupplyInVault 0x2ea33695
address supplyAsset
address borrowAsset
uint256 amount
uint256 index
reduceVaultTargetThreshold 0xb100b922
address supplyAsset
address borrowAsset
uint256 targetThreshold
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setGroomableConfig 0xddf32c11
address supplyAsset
address borrowAsset
tuple groomableConfig
setInitImpl 0x2b5b5696
address newInitImpl
setLiquidationConfig 0x1eba0043
address supplyAsset
address borrowAsset
tuple liquidatableConfig
setProxyAdmin 0x47c02661
address newProxyAdmin
setSnapshotableConfig 0x0ebcd18f
address supplyAsset
address borrowAsset
tuple config
setTokensFactory 0xed4c8bb3
address newTokensFactory
setVaultBorrowLimits 0x1af0e812
address supplyAsset
address borrowAsset
tuple borrowLimits
setVaultConfig 0x6f53e380
address supplyAsset
address borrowAsset
tuple config
setVaultReserveReceiver 0xea1dfb76
address receiver
withdrawVaultReserve 0x387516dd
address supplyAsset
address borrowAsset
uint256 amount
Recent Transactions
No transactions found for this address