Forkchoice Ethereum Mainnet

Address Contract Verified

Address 0xAa0508FcD0352B206F558b2B817dcC1F0cc3F401
Balance 0 ETH
Nonce 1
Code Size 9833 bytes
Indexed Transactions 0 (1 on-chain, 0.8% indexed)
External Etherscan · Sourcify

Contract Bytecode

9833 bytes
0x608060405234801561001057600080fd5b50600436106102115760003560e01c806370897b2311610120578063a9059cbb116100b8578063be32b3f81161007c578063be32b3f8146104a5578063d23e0480146104b8578063dd62ed3e146104df578063f39c38a0146104f2578063f621ff601461050557600080fd5b8063a9059cbb1461044c578063ab033ea91461045f578063ab73525514610472578063aced166114610485578063b1b3da511461049857600080fd5b806370897b23146103aa57806370a08231146103bd578063748747e6146103e6578063777f9766146103f95780637b3d51b11461040c5780637f5883a214610415578063877887821461042857806395d89b4114610431578063a457c2d71461043957600080fd5b806318515a83116101ae578063303cff5311610172578063303cff531461032d578063313ce5671461034057806339509351146103715780635aa6e675146103845780636e553f651461039757600080fd5b806318515a83146102e45780631f5a0bbe146102ec578063238efcbc146102ff57806323b872dd14610307578063247884291461031a57600080fd5b8062f714ce1461021657806301681a621461023c578063025a3a2914610251578063058a8e5f1461027757806306fdde031461028a5780630905f5601461029f578063095ea7b3146102c1578063140ce45f146102d457806318160ddd146102dc575b600080fd5b6102296102243660046123ea565b61050d565b6040519081526020015b60405180910390f35b61024f61024a3660046122a7565b61060c565b005b60065461026a906201000090046001600160a01b031681565b604051610233919061244d565b61024f6102853660046122a7565b6106b0565b610292610722565b6040516102339190612461565b6006546102b190610100900460ff1681565b6040519015158152602001610233565b6102b16102cf366004612357565b6107b4565b6102296107ce565b600254610229565b610229610897565b61024f6102fa3660046122a7565b61094c565b61024f610b40565b6102b1610315366004612317565b610bef565b61024f6103283660046122a7565b610c15565b61024f61033b366004612382565b610d36565b60405160ff7f0000000000000000000000000000000000000000000000000000000000000012168152602001610233565b6102b161037f366004612357565b610d86565b60085461026a906001600160a01b031681565b6102296103a53660046123ea565b610dc5565b61024f6103b83660046123ba565b610ea5565b6102296103cb3660046122a7565b6001600160a01b031660009081526020819052604090205490565b61024f6103f43660046122a7565b610f2c565b61024f610407366004612357565b610f7e565b610229600b5481565b61024f610423366004612357565b611058565b610229600c5481565b610292611120565b6102b1610447366004612357565b61112f565b6102b161045a366004612357565b6111cc565b61024f61046d3660046122a7565b6111da565b61026a6104803660046123ba565b611204565b60075461026a906001600160a01b031681565b6006546102b19060ff1681565b61024f6104b3366004612382565b61127f565b61026a7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6102296104ed3660046122df565b6112e6565b60095461026a906001600160a01b031681565b610229611311565b60006002600554141561053b5760405162461bcd60e51b8152600401610532906124b9565b60405180910390fd5b600260055561054861137f565b610550611447565b610559826114a3565b600083116105975760405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f53484152455360a81b6044820152606401610532565b6002546105a2610897565b6105ac9085612528565b6105b69190612508565b90506105c233846114e8565b6105f66001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168383611626565b6105fe610897565b600b55600160055592915050565b610614611689565b6008546040516370a0823160e01b81526106ad916001600160a01b0390811691908416906370a082319061064c90309060040161244d565b60206040518083038186803b15801561066457600080fd5b505afa158015610678573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061069c91906123d2565b6001600160a01b0384169190611626565b50565b6106b86116d7565b6006546040516001600160a01b038084169262010000900416907f6d039a6d5f36163cbc30fe5c1a15856df293a5769543d5deca1fb7a9ab29bf7790600090a3600680546001600160a01b03909216620100000262010000600160b01b0319909216919091179055565b6060600380546107319061258a565b80601f016020809104026020016040519081016040528092919081815260200182805461075d9061258a565b80156107aa5780601f1061077f576101008083540402835291602001916107aa565b820191906000526020600020905b81548152906001019060200180831161078d57829003601f168201915b5050505050905090565b6000336107c281858561171c565b60019150505b92915050565b600080805b6107db611311565b8110156108915760006107ed82611204565b9050600080826001600160a01b031663968ed6006040518163ffffffff1660e01b8152600401604080518083038186803b15801561082a57600080fd5b505afa15801561083e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610862919061240e565b9150915061086f81611838565b61087982866124f0565b94505050508080610889906125bf565b9150506107d3565b50919050565b60006108a16107ce565b6040516370a0823160e01b81526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216906370a08231906108ed90309060040161244d565b60206040518083038186803b15801561090557600080fd5b505afa158015610919573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093d91906123d2565b61094791906124f0565b905090565b6109546116d7565b61095d816114a3565b306001600160a01b0316816001600160a01b031663fbfa77cf6040518163ffffffff1660e01b815260040160206040518083038186803b1580156109a057600080fd5b505afa1580156109b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109d891906122c3565b6001600160a01b031614610a1e5760405162461bcd60e51b815260206004820152600d60248201526c1253959053125117d590555315609a1b6044820152606401610532565b604051636eb1769f60e11b81526001600160a01b0382811660048301523060248301526000917f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc29091169063dd62ed3e9060440160206040518083038186803b158015610a8a57600080fd5b505afa158015610a9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac291906123d2565b11610afe5760405162461bcd60e51b815260206004820152600c60248201526b4e4f5f414c4c4f57414e434560a01b6044820152606401610532565b610b09600a82611886565b6040516001600160a01b038216907fae5b7c3b000f575c241001dc9bcb3d8778376889353b07121115574eceff78c590600090a250565b6009546001600160a01b03163314610b8c5760405162461bcd60e51b815260206004820152600f60248201526e494e56414c49445f4144445245535360881b6044820152606401610532565b6009546008546040516001600160a01b0392831692909116907fff0b32b909f3fb702fe6ac1f682adcca675b9dfaa03ad8f46b4b17c4058a93fc90600090a3600954600880546001600160a01b0319166001600160a01b03909216919091179055565b600033610bfd858285611924565b610c0885858561199e565b60019150505b9392505050565b610c1d6116d7565b610c26816114a3565b610c2f81611b5a565b600080826001600160a01b031663968ed6006040518163ffffffff1660e01b8152600401604080518083038186803b158015610c6a57600080fd5b505afa158015610c7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca2919061240e565b91509150610caf81611838565b620f42408210610cf25760405162461bcd60e51b815260206004820152600e60248201526d08caa9c88a6bea89e9ebe90928e960931b6044820152606401610532565b610cfd600a84611c0f565b6040516001600160a01b038416907f4a2cf608bfb427f53279ec7f0eadf48913b9346ccefc3af138dbdec14ea0907d90600090a2505050565b610d3e6116d7565b6006805460ff19168215159081179091556040519081527faffd159acb2f0eec86675a846365f4908afe82bcb6f2e273e2703ead071a2617906020015b60405180910390a150565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091906107c29082908690610dc09087906124f0565b61171c565b600060026005541415610dea5760405162461bcd60e51b8152600401610532906124b9565b6002600555610df761137f565b610dff611447565b610e08826114a3565b60008311610e285760405162461bcd60e51b815260040161053290612494565b6000610e3360025490565b11610e3e5782610e64565b610e46610897565b83610e5060025490565b610e5a9190612528565b610e649190612508565b9050610e9b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216333086611e13565b6105f68282611e4b565b610ead6116d7565b610eba6002612710612508565b8110610ef75760405162461bcd60e51b815260206004820152600c60248201526b08c8a8abea89e9ebe90928e960a31b6044820152606401610532565b600c8190556040518181527f0810a1c261ca2c0cd86a0152c51c43ba9dc329639d2349f98140891b2ea798eb90602001610d7b565b610f346116d7565b600780546001600160a01b0319166001600160a01b0383169081179091556040517f2f202ddb4a2e345f6323ed90f8fc8559d770a7abbbeee84dde8aca3351fe715490600090a250565b60026005541415610fa15760405162461bcd60e51b8152600401610532906124b9565b6002600555610faf82611b5a565b610fb7611f18565b60008111610fd75760405162461bcd60e51b815260040161053290612494565b61100c6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216833084611e13565b816001600160a01b03167f2331b9a387a0c1b9069a5b1a48cd8c566440a10c1e58654d04d03fad210551968260405161104791815260200190565b60405180910390a250506001600555565b6002600554141561107b5760405162461bcd60e51b8152600401610532906124b9565b600260055561108982611b5a565b611091611f18565b600081116110b15760405162461bcd60e51b815260040161053290612494565b6110e56001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168383611626565b816001600160a01b03167f2f40f96629e48b44c1173c05df5811e217b0cce3bc7aef3dde4a4625be7c844b8260405161104791815260200190565b6060600480546107319061258a565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156111b45760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610532565b6111c1828686840361171c565b506001949350505050565b6000336107c281858561199e565b6111e26116d7565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b60408051600a8054602081810284018501855283018181526000946107c89487949093909284929091849184018282801561126857602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161124a575b505050505081525050611f6090919063ffffffff16565b6112876116d7565b6006805462010000600160b01b031960ff19841515610100021661ffff19909216919091176001171690556040517fcc6bda015b6cb89b378ac6dc0294b882c1d0d41b117a7c7a0adb80d8ea7076cb90610d7b90831515815260200190565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60408051600a80546020818102840185018552830181815260009461094794939284929184919084018282801561137157602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611353575b505050505081525050515190565b6000611389610897565b90506000600c5411801561139e5750600b5481115b156106ad576000600b54826113b39190612547565b90506000612710600c54836113c89190612528565b6113d29190612508565b60085490915061140f906001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28116911683611626565b6040518181527f860c0aa5520013080c2f65981705fcdea474d9f7c3daf954656ed5e65d692d1f9060200160405180910390a1505050565b60065460ff16156114a1576006546201000090046001600160a01b031633146114a15760405162461bcd60e51b815260206004820152600c60248201526b27a7262cafa120aa21a422a960a11b6044820152606401610532565b565b6001600160a01b0381166106ad5760405162461bcd60e51b815260206004820152600c60248201526b4e554c4c5f4144445245535360a01b6044820152606401610532565b6001600160a01b0382166115485760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610532565b6001600160a01b038216600090815260208190526040902054818110156115bc5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610532565b6001600160a01b03831660009081526020819052604081208383039055600280548492906115eb908490612547565b90915550506040518281526000906001600160a01b03851690600080516020612614833981519152906020015b60405180910390a35b505050565b6040516001600160a01b03831660248201526044810182905261162190849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611fdb565b60065460ff6101009091041615156001146114a15760405162461bcd60e51b815260206004820152600e60248201526d454d455247454e43595f4d4f444560901b6044820152606401610532565b6008546001600160a01b031633146114a15760405162461bcd60e51b815260206004820152600860248201526727a7262cafa3a7ab60c11b6044820152606401610532565b6001600160a01b03831661177e5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610532565b6001600160a01b0382166117df5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610532565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259101611618565b6118436032826124f0565b4311156106ad5760405162461bcd60e51b81526020600482015260116024820152701195539114d7d393d517d5541110551151607a1b6044820152606401610532565b604080518354602081810283018401845282018181526118f09386928492918491908401828280156118e157602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116118c3575b505050505081525050826120ad565b6119205781546001810183556000838152602090200180546001600160a01b0319166001600160a01b0383161790555b5050565b600061193084846112e6565b90506000198114611998578181101561198b5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610532565b611998848484840361171c565b50505050565b6001600160a01b038316611a025760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610532565b6001600160a01b038216611a645760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610532565b6001600160a01b03831660009081526020819052604090205481811015611adc5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610532565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290611b139084906124f0565b92505081905550826001600160a01b0316846001600160a01b031660008051602061261483398151915284604051611b4d91815260200190565b60405180910390a3611998565b60408051600a805460208181028401850185528301818152611bd09486949392849291849190840182828015611bb957602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611b9b575b5050505050815250506120ad90919063ffffffff16565b6106ad5760405162461bcd60e51b815260206004820152601060248201526f24a72b20a624a22fa2ac22a1aaaa27a960811b6044820152606401610532565b60005b60408051845460208181028301840184528201818152611c79938792849291849190840182828015611371576020028201919060005260206000209081546001600160a01b0316815260019091019060200180831161135357505050505081525050515190565b81101561162157816001600160a01b0316836000018281548110611cad57634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b03161415611e0157604080518454602081810283018401845282018181528693600193611d34939092869284928491840182828015611371576020028201919060005260206000209081546001600160a01b0316815260019091019060200180831161135357505050505081525050515190565b611d3e9190612547565b81548110611d5c57634e487b7160e01b600052603260045260246000fd5b60009182526020909120015483546001600160a01b0390911690849083908110611d9657634e487b7160e01b600052603260045260246000fd5b600091825260209091200180546001600160a01b0319166001600160a01b03929092169190911790558254839080611dde57634e487b7160e01b600052603160045260246000fd5b600082815260209020810160001990810180546001600160a01b03191690550190555b80611e0b816125bf565b915050611c12565b6040516001600160a01b03808516602483015283166044820152606481018290526119989085906323b872dd60e01b90608401611652565b6001600160a01b038216611ea15760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610532565b8060026000828254611eb391906124f0565b90915550506001600160a01b03821660009081526020819052604081208054839290611ee09084906124f0565b90915550506040518181526001600160a01b038316906000906000805160206126148339815191529060200160405180910390a35050565b6007546001600160a01b031633146114a15760405162461bcd60e51b815260206004820152600b60248201526a27a7262cafa5a2a2a822a960a91b6044820152606401610532565b6000611f6b83515190565b8210611fa95760405162461bcd60e51b815260206004820152600d60248201526c0929cac82989288be929c888ab609b1b6044820152606401610532565b8251805183908110611fcb57634e487b7160e01b600052603260045260246000fd5b6020026020010151905092915050565b6000612030826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121269092919063ffffffff16565b805190915015611621578080602001905181019061204e919061239e565b6116215760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610532565b6000805b83515181101561211c57826001600160a01b0316846000015182815181106120e957634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b0316141561210a5760019150506107c8565b80612114816125bf565b9150506120b1565b5060009392505050565b6060612135848460008561213d565b949350505050565b60608247101561219e5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610532565b6001600160a01b0385163b6121f55760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610532565b600080866001600160a01b031685876040516122119190612431565b60006040518083038185875af1925050503d806000811461224e576040519150601f19603f3d011682016040523d82523d6000602084013e612253565b606091505b509150915061226382828661226e565b979650505050505050565b6060831561227d575081610c0e565b82511561228d5782518084602001fd5b8160405162461bcd60e51b81526004016105329190612461565b6000602082840312156122b8578081fd5b8135610c0e816125f0565b6000602082840312156122d4578081fd5b8151610c0e816125f0565b600080604083850312156122f1578081fd5b82356122fc816125f0565b9150602083013561230c816125f0565b809150509250929050565b60008060006060848603121561232b578081fd5b8335612336816125f0565b92506020840135612346816125f0565b929592945050506040919091013590565b60008060408385031215612369578182fd5b8235612374816125f0565b946020939093013593505050565b600060208284031215612393578081fd5b8135610c0e81612605565b6000602082840312156123af578081fd5b8151610c0e81612605565b6000602082840312156123cb578081fd5b5035919050565b6000602082840312156123e3578081fd5b5051919050565b600080604083850312156123fc578182fd5b82359150602083013561230c816125f0565b60008060408385031215612420578182fd5b505080516020909101519092909150565b6000825161244381846020870161255e565b9190910192915050565b6001600160a01b0391909116815260200190565b602081526000825180602084015261248081604085016020870161255e565b601f01601f19169190910160400192915050565b6020808252600b908201526a16915493d7d05353d5539560aa1b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60008219821115612503576125036125da565b500190565b60008261252357634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615612542576125426125da565b500290565b600082821015612559576125596125da565b500390565b60005b83811015612579578181015183820152602001612561565b838111156119985750506000910152565b600181811c9082168061259e57607f821691505b6020821081141561089157634e487b7160e01b600052602260045260246000fd5b60006000198214156125d3576125d36125da565b5060010190565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146106ad57600080fd5b80151581146106ad57600080fdfeddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa26469706673582212202c2c85c3b963f196af4e214bf04284cf1f784250ae8f02c093b30f2d5516e2e464736f6c63430008040033

Verified Source Code Full Match

Compiler: v0.8.4+commit.c7e474f2 EVM: istanbul Optimization: Yes (100 runs)
Vault.sol 443 lines
/// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import "../library/AddArrayLib.sol";

import "../interfaces/ITradeExecutor.sol";
import "../interfaces/IVault.sol";

/// @title vault (Brahma Vault)
/// @author 0xAd1 and Bapireddy
/// @notice Minimal vault contract to support trades across different protocols.
contract Vault is IVault, ERC20, ReentrancyGuard {
    using AddrArrayLib for AddrArrayLib.Addresses;
    using SafeERC20 for IERC20;
    /*///////////////////////////////////////////////////////////////
                                 CONSTANTS
    //////////////////////////////////////////////////////////////*/
    /// @notice The maximum number of blocks for latest update to be valid.
    /// @dev Needed for processing deposits/withdrawals.
    uint256 constant BLOCK_LIMIT = 50;
    /// @dev minimum balance used to check when executor is removed.
    uint256 constant DUST_LIMIT = 10**6;
    /// @dev The max basis points used as normalizing factor.
    uint256 constant MAX_BPS = 10000;
    /*///////////////////////////////////////////////////////////////
                                IMMUTABLES
    //////////////////////////////////////////////////////////////*/
    /// @notice The underlying token the vault accepts.
    address public immutable override wantToken;
    uint8 private immutable tokenDecimals;

    /*///////////////////////////////////////////////////////////////
                            MUTABLE ACCESS MODFIERS
    //////////////////////////////////////////////////////////////*/
    /// @notice boolean for enabling deposit/withdraw solely via batcher.
    bool public batcherOnlyDeposit;

    /// @notice boolean for enabling emergency mode to halt new withdrawal/deposits into vault.
    bool public emergencyMode;

    // @notice address of batcher used for batching user deposits/withdrawals.
    address public batcher;
    /// @notice keeper address to move funds between executors.
    address public override keeper;
    /// @notice Governance address to add/remove  executors.
    address public override governance;
    address public pendingGovernance;

    /// @notice Creates a new Vault that accepts a specific underlying token.
    /// @param _wantToken The ERC20 compliant token the vault should accept.
    /// @param _name The name of the vault token.
    /// @param _symbol The symbol of the vault token.
    /// @param _keeper The address of the keeper to move funds between executors.
    /// @param _governance The address of the governance to perform governance functions.
    constructor(
        string memory _name,
        string memory _symbol,
        address _wantToken,
        address _keeper,
        address _governance
    ) ERC20(_name, _symbol) {
        tokenDecimals = IERC20Metadata(_wantToken).decimals();
        wantToken = _wantToken;
        keeper = _keeper;
        governance = _governance;
        // to prevent any front running deposits
        batcherOnlyDeposit = true;
    }

    function decimals() public view override returns (uint8) {
        return tokenDecimals;
    }

    /*///////////////////////////////////////////////////////////////
                       USER DEPOSIT/WITHDRAWAL LOGIC
    //////////////////////////////////////////////////////////////*/
    /// @notice Initiates a deposit of want tokens to the vault.
    /// @param amountIn The amount of want tokens to deposit.
    /// @param receiver The address to receive vault tokens.
    function deposit(uint256 amountIn, address receiver)
        public
        override
        nonReentrant
        ensureFeesAreCollected
        returns (uint256 shares)
    {
        /// checks for only batcher deposit
        onlyBatcher();
        isValidAddress(receiver);
        require(amountIn > 0, "ZERO_AMOUNT");
        // calculate the shares based on the amount.
        shares = totalSupply() > 0
            ? (totalSupply() * amountIn) / totalVaultFunds()
            : amountIn;
        IERC20(wantToken).safeTransferFrom(msg.sender, address(this), amountIn);
        _mint(receiver, shares);
    }

    /// @notice Initiates a withdrawal of vault tokens to the user.
    /// @param sharesIn The amount of vault tokens to withdraw.
    /// @param receiver The address to receive the vault tokens.
    function withdraw(uint256 sharesIn, address receiver)
        public
        override
        nonReentrant
        ensureFeesAreCollected
        returns (uint256 amountOut)
    {
        /// checks for only batcher withdrawal
        onlyBatcher();
        isValidAddress(receiver);
        require(sharesIn > 0, "ZERO_SHARES");
        // calculate the amount based on the shares.
        amountOut = (sharesIn * totalVaultFunds()) / totalSupply();
        // burn shares of msg.sender
        _burn(msg.sender, sharesIn);
        IERC20(wantToken).safeTransfer(receiver, amountOut);
    }

    /// @notice Calculates the total amount of underlying tokens the vault holds.
    /// @return The total amount of underlying tokens the vault holds.
    function totalVaultFunds() public view returns (uint256) {
        return
            IERC20(wantToken).balanceOf(address(this)) + totalExecutorFunds();
    }

    /*///////////////////////////////////////////////////////////////
                    EXECUTOR DEPOSIT/WITHDRAWAL LOGIC
    //////////////////////////////////////////////////////////////*/

    /// @notice list of trade executors connected to vault.
    AddrArrayLib.Addresses tradeExecutorsList;

    /// @notice Emitted after the vault deposits into a executor contract.
    /// @param executor The executor that was deposited into.
    /// @param underlyingAmount The amount of underlying tokens that were deposited.
    event ExecutorDeposit(address indexed executor, uint256 underlyingAmount);

    /// @notice Emitted after the vault withdraws funds from a executor contract.
    /// @param executor The executor that was withdrawn from.
    /// @param underlyingAmount The amount of underlying tokens that were withdrawn.
    event ExecutorWithdrawal(
        address indexed executor,
        uint256 underlyingAmount
    );

    /// @notice Deposit given amount of want tokens into valid executor.
    /// @param _executor The executor to deposit into.
    /// @param _amount The amount of want tokens to deposit.
    function depositIntoExecutor(address _executor, uint256 _amount)
        public
        nonReentrant
    {
        isActiveExecutor(_executor);
        onlyKeeper();
        require(_amount > 0, "ZERO_AMOUNT");
        IERC20(wantToken).safeTransfer(_executor, _amount);
        emit ExecutorDeposit(_executor, _amount);
    }

    /// @notice Withdraw given amount of want tokens into valid executor.
    /// @param _executor The executor to withdraw tokens from.
    /// @param _amount The amount of want tokens to withdraw.
    function withdrawFromExecutor(address _executor, uint256 _amount)
        public
        nonReentrant
    {
        isActiveExecutor(_executor);
        onlyKeeper();
        require(_amount > 0, "ZERO_AMOUNT");
        IERC20(wantToken).safeTransferFrom(_executor, address(this), _amount);
        emit ExecutorWithdrawal(_executor, _amount);
    }

    /*///////////////////////////////////////////////////////////////
                           FEE CONFIGURATION
    //////////////////////////////////////////////////////////////*/
    /// @notice lagging value of vault total funds.
    /// @dev value intialized to max to prevent slashing on first deposit.
    uint256 public prevVaultFunds = type(uint256).max;
    /// @dev Perfomance fee for the vault.
    uint256 public performanceFee;
    /// @notice Emitted after fee updation.
    /// @param fee The new performance fee on vault.
    event UpdatePerformanceFee(uint256 fee);

    /// @notice Updates the performance fee on the vault.
    /// @param _fee The new performance fee on the vault.
    /// @dev The new fee must be always less than 50% of yield.
    function setPerformanceFee(uint256 _fee) public {
        onlyGovernance();
        require(_fee < MAX_BPS / 2, "FEE_TOO_HIGH");
        performanceFee = _fee;
        emit UpdatePerformanceFee(_fee);
    }

    /// @notice Emitted when a fees are collected.
    /// @param collectedFees The amount of fees collected.
    event FeesCollected(uint256 collectedFees);

    /// @notice Calculates and collects the fees from the vault.
    /// @dev This function sends all the accured fees to governance.
    /// checks the yield made since previous harvest and
    /// calculates the fee based on it. Also note: this function
    /// should be called before processing any new deposits/withdrawals.
    function collectFees() internal {
        uint256 currentFunds = totalVaultFunds();
        // collect fees only when profit is made.
        if ((performanceFee > 0) && (currentFunds > prevVaultFunds)) {
            uint256 yieldEarned = (currentFunds - prevVaultFunds);
            // normalization by MAX_BPS
            uint256 fees = ((yieldEarned * performanceFee) / MAX_BPS);
            IERC20(wantToken).safeTransfer(governance, fees);
            emit FeesCollected(fees);
        }
    }

    modifier ensureFeesAreCollected() {
        collectFees();
        _;
        // update vault funds after fees are collected.
        prevVaultFunds = totalVaultFunds();
    }

    /*///////////////////////////////////////////////////////////////
                    EXECUTOR ADDITION/REMOVAL LOGIC
    //////////////////////////////////////////////////////////////*/
    /// @notice Emitted when executor is added to vault.
    /// @param executor The address of added executor.
    event ExecutorAdded(address indexed executor);

    /// @notice Emitted when executor is removed from vault.
    /// @param executor The address of removed executor.
    event ExecutorRemoved(address indexed executor);

    /// @notice Adds a trade executor, enabling it to execute trades.
    /// @param _tradeExecutor The address of _tradeExecutor contract.
    function addExecutor(address _tradeExecutor) public {
        onlyGovernance();
        isValidAddress(_tradeExecutor);
        require(
            ITradeExecutor(_tradeExecutor).vault() == address(this),
            "INVALID_VAULT"
        );
        require(
            IERC20(wantToken).allowance(_tradeExecutor, address(this)) > 0,
            "NO_ALLOWANCE"
        );
        tradeExecutorsList.pushAddress(_tradeExecutor);
        emit ExecutorAdded(_tradeExecutor);
    }

    /// @notice Adds a trade executor, enabling it to execute trades.
    /// @param _tradeExecutor The address of _tradeExecutor contract.
    /// @dev make sure all funds are withdrawn from executor before removing.
    function removeExecutor(address _tradeExecutor) public {
        onlyGovernance();
        isValidAddress(_tradeExecutor);
        // check if executor attached to vault.
        isActiveExecutor(_tradeExecutor);

        (uint256 executorFunds, uint256 blockUpdated) = ITradeExecutor(
            _tradeExecutor
        ).totalFunds();
        areFundsUpdated(blockUpdated);
        require(executorFunds < DUST_LIMIT, "FUNDS_TOO_HIGH");
        tradeExecutorsList.removeAddress(_tradeExecutor);
        emit ExecutorRemoved(_tradeExecutor);
    }

    /// @notice gives the number of trade executors.
    /// @return The number of trade executors.
    function totalExecutors() public view returns (uint256) {
        return tradeExecutorsList.size();
    }

    /// @notice Returns trade executor at given index.
    /// @return The executor address at given valid index.
    function executorByIndex(uint256 _index) public view returns (address) {
        return tradeExecutorsList.getAddressAtIndex(_index);
    }

    /// @notice Calculates funds held by all executors in want token.
    /// @return Sum of all funds held by executors.
    function totalExecutorFunds() public view returns (uint256) {
        uint256 totalFunds = 0;
        for (uint256 i = 0; i < totalExecutors(); i++) {
            address executor = executorByIndex(i);
            (uint256 executorFunds, uint256 blockUpdated) = ITradeExecutor(
                executor
            ).totalFunds();
            areFundsUpdated(blockUpdated);
            totalFunds += executorFunds;
        }
        return totalFunds;
    }

    /*///////////////////////////////////////////////////////////////
                    GOVERNANCE ACTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Emitted when a batcher is updated.
    /// @param oldBatcher The address of the current batcher.
    /// @param newBatcher The  address of new batcher.
    event UpdatedBatcher(
        address indexed oldBatcher,
        address indexed newBatcher
    );

    /// @notice Changes the batcher address.
    /// @dev  This can only be called by governance.
    /// @param _batcher The address to for new batcher.
    function setBatcher(address _batcher) public {
        onlyGovernance();
        emit UpdatedBatcher(batcher, _batcher);
        batcher = _batcher;
    }

    /// @notice Emitted batcherOnlyDeposit is enabled.
    /// @param state The state of depositing only via batcher.
    event UpdatedBatcherOnlyDeposit(bool state);

    /// @notice Enables/disables deposits with batcher only.
    /// @dev  This can only be called by governance.
    /// @param _batcherOnlyDeposit if true vault can accept deposit via batcher only or else anyone can deposit.
    function setBatcherOnlyDeposit(bool _batcherOnlyDeposit) public {
        onlyGovernance();
        batcherOnlyDeposit = _batcherOnlyDeposit;
        emit UpdatedBatcherOnlyDeposit(_batcherOnlyDeposit);
    }

    /// @notice Nominates new governance address.
    /// @dev  Governance will only be changed if the new governance accepts it. It will be pending till then.
    /// @param _governance The address of new governance.
    function setGovernance(address _governance) public {
        onlyGovernance();
        pendingGovernance = _governance;
    }

    /// @notice Emitted when governance is updated.
    /// @param oldGovernance The address of the current governance.
    /// @param newGovernance The address of new governance.
    event UpdatedGovernance(
        address indexed oldGovernance,
        address indexed newGovernance
    );

    /// @notice The nomine of new governance address proposed by `setGovernance` function can accept the governance.
    /// @dev  This can only be called by address of pendingGovernance.
    function acceptGovernance() public {
        require(msg.sender == pendingGovernance, "INVALID_ADDRESS");
        emit UpdatedGovernance(governance, pendingGovernance);
        governance = pendingGovernance;
    }

    /// @notice Emitted when keeper is updated.
    /// @param keeper The address of the new keeper.
    event UpdatedKeeper(address indexed keeper);

    /// @notice Sets new keeper address.
    /// @dev  This can only be called by governance.
    /// @param _keeper The address of new keeper.
    function setKeeper(address _keeper) public {
        onlyGovernance();
        keeper = _keeper;
        emit UpdatedKeeper(_keeper);
    }

    /// @notice Emitted when emergencyMode status is updated.
    /// @param emergencyMode boolean indicating state of emergency.
    event EmergencyModeStatus(bool emergencyMode);

    /// @notice sets emergencyMode.
    /// @dev  This can only be called by governance.
    /// @param _emergencyMode if true, vault will be in emergency mode.
    function setEmergencyMode(bool _emergencyMode) public {
        onlyGovernance();
        emergencyMode = _emergencyMode;
        batcherOnlyDeposit = true;
        batcher = address(0);
        emit EmergencyModeStatus(_emergencyMode);
    }

    /// @notice Removes invalid tokens from the vault.
    /// @dev  This is used as fail safe to remove want tokens from the vault during emergency mode
    /// can be called by anyone to send funds to governance.
    /// @param _token The address of token to be removed.
    function sweep(address _token) public {
        isEmergencyMode();
        IERC20(_token).safeTransfer(
            governance,
            IERC20(_token).balanceOf(address(this))
        );
    }

    /*///////////////////////////////////////////////////////////////
                    ACCESS MODIFERS
    //////////////////////////////////////////////////////////////*/
    /// @dev Checks if the sender is the governance.
    function onlyGovernance() internal view {
        require(msg.sender == governance, "ONLY_GOV");
    }

    /// @dev Checks if the sender is the keeper.
    function onlyKeeper() internal view {
        require(msg.sender == keeper, "ONLY_KEEPER");
    }

    /// @dev Checks if the sender is the batcher.
    function onlyBatcher() internal view {
        if (batcherOnlyDeposit) {
            require(msg.sender == batcher, "ONLY_BATCHER");
        }
    }

    /// @dev Checks if emergency mode is enabled.
    function isEmergencyMode() internal view {
        require(emergencyMode == true, "EMERGENCY_MODE");
    }

    /// @dev Checks if the address is valid.
    function isValidAddress(address _addr) internal pure {
        require(_addr != address(0), "NULL_ADDRESS");
    }

    /// @dev Checks if the tradeExecutor is valid.
    function isActiveExecutor(address _tradeExecutor) internal view {
        require(tradeExecutorsList.exists(_tradeExecutor), "INVALID_EXECUTOR");
    }

    /// @dev Checks if funds are updated.
    function areFundsUpdated(uint256 _blockUpdated) internal view {
        require(
            block.number <= _blockUpdated + BLOCK_LIMIT,
            "FUNDS_NOT_UPDATED"
        );
    }
}
IVault.sol 18 lines
/// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

interface IVault {
    function keeper() external view returns (address);

    function governance() external view returns (address);

    function wantToken() external view returns (address);

    function deposit(uint256 amountIn, address receiver)
        external
        returns (uint256 shares);

    function withdraw(uint256 sharesIn, address receiver)
        external
        returns (uint256 amountOut);
}
AddArrayLib.sol 91 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library AddrArrayLib {
    using AddrArrayLib for Addresses;

    struct Addresses {
        address[] _items;
    }

    /**
     * @notice push an address to the array
     * @dev if the address already exists, it will not be added again
     * @param self Storage array containing address type variables
     * @param element the element to add in the array
     */
    function pushAddress(Addresses storage self, address element) internal {
        if (!exists(self, element)) {
            self._items.push(element);
        }
    }

    /**
     * @notice remove an address from the array
     * @dev finds the element, swaps it with the last element, and then deletes it;
     *      returns a boolean whether the element was found and deleted
     * @param self Storage array containing address type variables
     * @param element the element to remove from the array
     */
    function removeAddress(Addresses storage self, address element) internal {
        for (uint256 i = 0; i < self.size(); i++) {
            if (self._items[i] == element) {
                self._items[i] = self._items[self.size() - 1];
                self._items.pop();
            }
        }
    }

    /**
     * @notice get the address at a specific index from array
     * @dev revert if the index is out of bounds
     * @param self Storage array containing address type variables
     * @param index the index in the array
     */
    function getAddressAtIndex(Addresses memory self, uint256 index)
        internal
        view
        returns (address)
    {
        require(index < size(self), "INVALID_INDEX");
        return self._items[index];
    }

    /**
     * @notice get the size of the array
     * @param self Storage array containing address type variables
     */
    function size(Addresses memory self) internal view returns (uint256) {
        return self._items.length;
    }

    /**
     * @notice check if an element exist in the array
     * @param self Storage array containing address type variables
     * @param element the element to check if it exists in the array
     */
    function exists(Addresses memory self, address element)
        internal
        view
        returns (bool)
    {
        for (uint256 i = 0; i < self.size(); i++) {
            if (self._items[i] == element) {
                return true;
            }
        }
        return false;
    }

    /**
     * @notice get the array
     * @param self Storage array containing address type variables
     */
    function getAllAddresses(Addresses memory self)
        internal
        view
        returns (address[] memory)
    {
        return self._items;
    }
}
ITradeExecutor.sol 27 lines
//SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

interface ITradeExecutor {
    struct ActionStatus {
        bool inProcess;
        address from;
    }
    function vault() external view returns (address);

    function depositStatus() external returns (bool, address);

    function withdrawalStatus() external returns (bool, address);

    function initiateDeposit(bytes calldata _data) external;

    function confirmDeposit() external;

    function initateWithdraw(bytes calldata _data) external;

    function confirmWithdraw() external;

    function totalFunds()
        external
        view
        returns (uint256 posValue, uint256 lastUpdatedBlock);
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                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;
    }
}
ERC20.sol 383 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

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

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

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

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

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

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

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

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

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

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

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

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

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

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @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);
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

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

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

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

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

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

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

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

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

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

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

Read Contract

allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
batcher 0x025a3a29 → address
batcherOnlyDeposit 0xb1b3da51 → bool
decimals 0x313ce567 → uint8
emergencyMode 0x0905f560 → bool
executorByIndex 0xab735255 → address
governance 0x5aa6e675 → address
keeper 0xaced1661 → address
name 0x06fdde03 → string
pendingGovernance 0xf39c38a0 → address
performanceFee 0x87788782 → uint256
prevVaultFunds 0x7b3d51b1 → uint256
symbol 0x95d89b41 → string
totalExecutorFunds 0x140ce45f → uint256
totalExecutors 0xf621ff60 → uint256
totalSupply 0x18160ddd → uint256
totalVaultFunds 0x18515a83 → uint256
wantToken 0xd23e0480 → address

Write Contract 19 functions

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

acceptGovernance 0x238efcbc
No parameters
addExecutor 0x1f5a0bbe
address _tradeExecutor
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
deposit 0x6e553f65
uint256 amountIn
address receiver
returns: uint256
depositIntoExecutor 0x7f5883a2
address _executor
uint256 _amount
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
removeExecutor 0x24788429
address _tradeExecutor
setBatcher 0x058a8e5f
address _batcher
setBatcherOnlyDeposit 0x303cff53
bool _batcherOnlyDeposit
setEmergencyMode 0xbe32b3f8
bool _emergencyMode
setGovernance 0xab033ea9
address _governance
setKeeper 0x748747e6
address _keeper
setPerformanceFee 0x70897b23
uint256 _fee
sweep 0x01681a62
address _token
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
withdraw 0x00f714ce
uint256 sharesIn
address receiver
returns: uint256
withdrawFromExecutor 0x777f9766
address _executor
uint256 _amount

Recent Transactions

This address has 1 on-chain transactions, but only 0.8% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →