Address Contract Verified
Address
0x47c84A87A2a972769cc5DeDa28118617E3A48F8C
Balance
0 ETH
Nonce
1
Code Size
9986 bytes
Creator
0xAE75B29A...6ff1 at tx 0x159e7c18...7a2eee
Indexed Transactions
0
Contract Bytecode
9986 bytes
0x6080604052600436106101355760003560e01c80637a9e5e4b116100ab578063ba9a35871161006f578063ba9a35871461039f578063da5f05af146103b2578063e6ac418a146103df578063ec3b613d146103ff578063ec7a0d981461041f578063f64c6f321461043f57600080fd5b80637a9e5e4b146102f35780637e28882214610313578063a5c82f1814610329578063aced166114610356578063ad5c46481461036b57600080fd5b8063501ec738116100fd578063501ec738146101dc578063527839b01461021f5780635aa6e6751461025a5780635b9d26581461027c57806366b1a5de146102a95780636e164e23146102d357600080fd5b806301681a621461013a5780630a3d95d81461015c57806312edde5e1461017c578063431cc3dd1461019c578063474a3b84146101bc575b600080fd5b34801561014657600080fd5b5061015a610155366004612266565b610455565b005b34801561016857600080fd5b5061015a610177366004612352565b61059b565b34801561018857600080fd5b5061015a61019736600461238a565b6105b6565b3480156101a857600080fd5b5061015a6101b736600461229e565b610782565b3480156101c857600080fd5b5061015a6101d736600461238a565b610ca9565b3480156101e857600080fd5b50600154600254600354610207926001600160a01b0390811692169083565b604051610216939291906124c0565b60405180910390f35b34801561022b57600080fd5b5061024c61023a366004612266565b600a6020526000908152604090205481565b604051908152602001610216565b34801561026657600080fd5b5061026f610cb6565b60405161021691906124ac565b34801561028857600080fd5b5061024c610297366004612266565b60066020526000908152604090205481565b3480156102b557600080fd5b506004546102c39060ff1681565b6040519015158152602001610216565b3480156102df57600080fd5b5061015a6102ee3660046123ba565b610d38565b3480156102ff57600080fd5b5061015a61030e366004612266565b610e02565b34801561031f57600080fd5b5061024c60095481565b34801561033557600080fd5b5061024c610344366004612266565b60056020526000908152604090205481565b34801561036257600080fd5b5061026f610e66565b34801561037757600080fd5b5061026f7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b61015a6103ad3660046123e9565b610eab565b3480156103be57600080fd5b5061024c6103cd366004612266565b600b6020526000908152604090205481565b3480156103eb57600080fd5b5060075461026f906001600160a01b031681565b34801561040b57600080fd5b5061015a61041a36600461229e565b611268565b34801561042b57600080fd5b5061015a61043a3660046123ba565b611786565b34801561044b57600080fd5b5061024c60085481565b600260005414156104815760405162461bcd60e51b815260040161047890612560565b60405180910390fd5b600260005561048e61188d565b6040516370a0823160e01b81526001600160a01b0382169063a9059cbb90339083906370a08231906104c49030906004016124ac565b60206040518083038186803b1580156104dc57600080fd5b505afa1580156104f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061051491906123a2565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b15801561055a57600080fd5b505af115801561056e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610592919061236e565b50506001600055565b6105a361188d565b6004805460ff1916911515919091179055565b600260005414156105d95760405162461bcd60e51b815260040161047890612560565b60026000908155338152600560205260409020541561062c5760405162461bcd60e51b815260206004820152600f60248201526e4445504f5349545f50454e44494e4760881b6044820152606401610478565b6000811161066d5760405162461bcd60e51b815260206004820152600e60248201526d414d4f554e545f494e5f5a45524f60901b6044820152606401610478565b336000908152600a60205260409020548111156106ce57336000818152600a60205260409020546106b9919030906106a5908561261f565b6001546001600160a01b03169291906118d9565b336000908152600a60205260408120556106fa565b336000908152600a60205260409020546106e990829061261f565b336000908152600a60205260409020555b336000908152600660205260409020546107159082906125c8565b336000908152600660205260409020556009546107339082906125c8565b6009556001546040518281526001600160a01b039091169033907fcdb62e3f244f9959bd661d145243fc71558361230885919e11fcc84312d44c7d9060200160405180910390a3506001600055565b600260005414156107a55760405162461bcd60e51b815260040161047890612560565b60026000556107b2611937565b6001546002546040516370a0823160e01b81526001600160a01b039283169290911690600090819083906370a08231906107f09030906004016124ac565b60206040518083038186803b15801561080857600080fd5b505afa15801561081c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061084091906123a2565b90506000855167ffffffffffffffff81111561086c57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610895578160200160208202803683370190505b50905060005b8651811015610996576000600660008984815181106108ca57634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020549050808561090191906125c8565b94508083838151811061092457634e487b7160e01b600052603260045260246000fd5b6020026020010181815250506000600660008a858151811061095657634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000208190555050808061098e90612662565b91505061089b565b50600083116109d65760405162461bcd60e51b815260206004820152600c60248201526b4e4f5f57495448445241575360a01b6044820152606401610478565b604051627b8a6760e11b81526000906001600160a01b0387169062f714ce90610a0590879030906004016124e4565b602060405180830381600087803b158015610a1f57600080fd5b505af1158015610a33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5791906123a2565b9050600083866001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610a8891906124ac565b60206040518083038186803b158015610aa057600080fd5b505afa158015610ab4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ad891906123a2565b610ae2919061261f565b9050818114610b2a5760405162461bcd60e51b81526020600482015260146024820152730ae829ca8bea89e968a9ca6be9a92a69a82a886960631b6044820152606401610478565b6000805b8951811015610c4e576000858281518110610b5957634e487b7160e01b600052603260045260246000fd5b602002602001015190506000811115610c3b57600088610b798684612600565b610b8391906125e0565b905080600b60008e8681518110610baa57634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054610bdd91906125c8565b600b60008e8681518110610c0157634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000208190555083610c3790612662565b9350505b5080610c4681612662565b915050610b2e565b5085600954610c5d919061261f565b60095560408051838152602081018390527f253f39873a287fb2801f5e791a591779d3ff3e219ec7c9793784a25ba658a759910160405180910390a15050600160005550505050505050565b610cb161188d565b600355565b60015460408051635aa6e67560e01b815290516000926001600160a01b031691635aa6e675916004808301926020929190829003018186803b158015610cfb57600080fd5b505afa158015610d0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d339190612282565b905090565b60026000541415610d5b5760405162461bcd60e51b815260040161047890612560565b600260009081556001600160a01b0382168152600a6020526040902054821115610db25760405162461bcd60e51b81526020600482015260086024820152674e4f5f46554e445360c01b6044820152606401610478565b6001600160a01b0381166000908152600a6020526040902054610dd690839061261f565b6001600160a01b038083166000908152600a60205260409020919091556001546105929116828461198d565b610e0a61188d565b6007546040516001600160a01b038084169216907f0c1d6fac887f995d8165f884c34f3de9a2e4c9707aacccf2cf22812377c280af90600090a3600780546001600160a01b0319166001600160a01b0392909216919091179055565b6001546040805163aced166160e01b815290516000926001600160a01b03169163aced1661916004808301926020929190829003018186803b158015610cfb57600080fd5b60026000541415610ece5760405162461bcd60e51b815260040161047890612560565b6002600055610edd81836119c2565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216906370a0823190610f2c9030906004016124ac565b60206040518083038186803b158015610f4457600080fd5b505afa158015610f58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7c91906123a2565b9050348015611001578094507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015610fe357600080fd5b505af1158015610ff7573d6000803e3d6000fd5b5050505050611019565b600254611019906001600160a01b03163330886118d9565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216906370a08231906110689030906004016124ac565b60206040518083038186803b15801561108057600080fd5b505afa158015611094573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b891906123a2565b9050856110c5848361261f565b146110e057634e487b7160e01b600052600160045260246000fd5b600354600954600854600154604080516318160ddd60e01b815290518b9493926001600160a01b0316916318160ddd916004808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061116791906123a2565b61117191906125c8565b61117b919061261f565b61118591906125c8565b11156111c85760405162461bcd60e51b815260206004820152601260248201527113505617d31253525517d15610d15151115160721b6044820152606401610478565b6001600160a01b0384166000908152600560205260409020546111ec9087906125c8565b6001600160a01b0385166000908152600560205260409020556008546112139087906125c8565b6008556001546040518781526001600160a01b03918216918616907f4ed1a8a57a37b79833de68b3bc01307fc91c77341a669fc487f7e588f986d5ff9060200160405180910390a35050600160005550505050565b6002600054141561128b5760405162461bcd60e51b815260040161047890612560565b6002600055611298611937565b6001546040516370a0823160e01b81526001600160a01b0390911690600090819083906370a08231906112cf9030906004016124ac565b60206040518083038186803b1580156112e757600080fd5b505afa1580156112fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131f91906123a2565b90506000845167ffffffffffffffff81111561134b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611374578160200160208202803683370190505b50905060005b8551811015611475576000600560008884815181106113a957634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054905080856113e091906125c8565b94508083838151811061140357634e487b7160e01b600052603260045260246000fd5b60200260200101818152505060006005600089858151811061143557634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000208190555050808061146d90612662565b91505061137a565b50600083116114b45760405162461bcd60e51b815260206004820152600b60248201526a4e4f5f4445504f5349545360a81b6044820152606401610478565b604051636e553f6560e01b81526000906001600160a01b03861690636e553f65906114e590879030906004016124e4565b602060405180830381600087803b1580156114ff57600080fd5b505af1158015611513573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061153791906123a2565b9050600083866001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161156891906124ac565b60206040518083038186803b15801561158057600080fd5b505afa158015611594573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115b891906123a2565b6115c2919061261f565b90508181146116085760405162461bcd60e51b8152602060048201526012602482015271098a0bea89e968a9ca6be9a92a69a82a886960731b6044820152606401610478565b6000805b885181101561172c57600085828151811061163757634e487b7160e01b600052603260045260246000fd5b602002602001015190506000811115611719576000886116578684612600565b61166191906125e0565b905080600a60008d868151811061168857634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020546116bb91906125c8565b600a60008d86815181106116df57634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508361171590612662565b9350505b508061172481612662565b91505061160c565b508560085461173b919061261f565b60085560408051838152602081018390527f8211507759e56fdc649418f9277798429bc90613b9b4a54e7b08458538b5b6f0910160405180910390a150506001600055505050505050565b600260005414156117a95760405162461bcd60e51b815260040161047890612560565b6002600055816117ef5760405162461bcd60e51b81526020600482015260116024820152701253959053125117d05353d5539513d555607a1b6044820152606401610478565b6001600160a01b0381166000908152600b602052604090205461181390839061261f565b6001600160a01b038083166000908152600b602052604090209190915560025461183f9116828461198d565b6001546040518381526001600160a01b03918216918316907fce67cd4e23f137729b8b844fbf25399d5130346f0d62c18afdc0a943e1d1f1019060200160405180910390a350506001600055565b33611896610cb6565b6001600160a01b0316146118d75760405162461bcd60e51b815260206004820152600860248201526727a7262cafa3a7ab60c11b6044820152606401610478565b565b611931846323b872dd60e01b8585856040516024016118fa939291906124c0565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611a7a565b50505050565b61193f610e66565b6001600160a01b0316336001600160a01b0316146118d75760405162461bcd60e51b815260206004820152600b60248201526a27a7262cafa5a2a2a822a960a91b6044820152606401610478565b6040516001600160a01b0383166024820152604481018290526119bd90849063a9059cbb60e01b906064016118fa565b505050565b60045460ff1615611a26576007546119e690839083906001600160a01b0316611b4c565b611a265760405162461bcd60e51b8152602060048201526011602482015270494e56414c49445f5349474e415455524560781b6044820152606401610478565b3360009081526006602052604090205415611a765760405162461bcd60e51b815260206004820152601060248201526f57495448445241575f50454e44494e4760801b6044820152606401610478565b5050565b6000611acf826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611d519092919063ffffffff16565b8051909150156119bd5780806020019051810190611aed919061236e565b6119bd5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610478565b60408051808201825260078152662130ba31b432b960c91b602091820152815180830183526001808252603160f81b9183019190915282517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f818401527fe9d76cee0cf4473cddcc3e081ef9f2caab96302d23d7ba675ea190f2188e546f818501527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101919091523060a0808301919091528351808303909101815260c08201909352825192909101919091206000918290611c56907f2fe9f7b6a29d4dd4b42345a1abcb25508fd8a183b707ff2d4a5130e9ccb1926190889060e0016124e4565b60405160208183030381529060405280519060200120905060008282604051602001611c9992919061190160f01b81526002810192909252602282015260420190565b6040516020818303038152906040528051906020012090506000611cbd8288611d68565b9050856001600160a01b0316816001600160a01b031614611d1b5760405162461bcd60e51b815260206004820152601860248201527745434453413a20496e76616c696420617574686f7269747960401b6044820152606401610478565b6001600160a01b038116611d415760405162461bcd60e51b81526004016104789061252e565b60019450505050505b9392505050565b6060611d608484600085611d8c565b949350505050565b6000806000611d778585611ebd565b91509150611d8481611f2d565b509392505050565b606082471015611ded5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610478565b6001600160a01b0385163b611e445760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610478565b600080866001600160a01b03168587604051611e609190612490565b60006040518083038185875af1925050503d8060008114611e9d576040519150601f19603f3d011682016040523d82523d6000602084013e611ea2565b606091505b5091509150611eb2828286612101565b979650505050505050565b600080825160411415611ef45760208301516040840151606085015160001a611ee88782858561213a565b94509450505050611f26565b825160401415611f1e5760208301516040840151611f1386838361221d565b935093505050611f26565b506000905060025b9250929050565b6000816004811115611f4f57634e487b7160e01b600052602160045260246000fd5b1415611f585750565b6001816004811115611f7a57634e487b7160e01b600052602160045260246000fd5b1415611f985760405162461bcd60e51b81526004016104789061252e565b6002816004811115611fba57634e487b7160e01b600052602160045260246000fd5b14156120085760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610478565b600381600481111561202a57634e487b7160e01b600052602160045260246000fd5b14156120835760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610478565b60048160048111156120a557634e487b7160e01b600052602160045260246000fd5b14156120fe5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610478565b50565b60608315612110575081611d4a565b8251156121205782518084602001fd5b8160405162461bcd60e51b815260040161047891906124fb565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b038311156121675750600090506003612214565b8460ff16601b1415801561217f57508460ff16601c14155b156121905750600090506004612214565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156121e4573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661220d57600060019250925050612214565b9150600090505b94509492505050565b6000806001600160ff1b0383168161223a60ff86901c601b6125c8565b90506122488782888561213a565b935093505050935093915050565b8035612261816126a9565b919050565b600060208284031215612277578081fd5b8135611d4a816126a9565b600060208284031215612293578081fd5b8151611d4a816126a9565b600060208083850312156122b0578182fd5b823567ffffffffffffffff808211156122c7578384fd5b818501915085601f8301126122da578384fd5b8135818111156122ec576122ec612693565b8060051b91506122fd848301612597565b8181528481019084860184860187018a1015612317578788fd5b8795505b838610156123455780359450612330856126a9565b8483526001959095019491860191860161231b565b5098975050505050505050565b600060208284031215612363578081fd5b8135611d4a816126be565b60006020828403121561237f578081fd5b8151611d4a816126be565b60006020828403121561239b578081fd5b5035919050565b6000602082840312156123b3578081fd5b5051919050565b600080604083850312156123cc578081fd5b8235915060208301356123de816126a9565b809150509250929050565b6000806000606084860312156123fd578081fd5b8335925060208085013567ffffffffffffffff8082111561241c578384fd5b818701915087601f83011261242f578384fd5b81358181111561244157612441612693565b612453601f8201601f19168501612597565b91508082528884828501011115612468578485fd5b8084840185840137810190920183905250915061248760408501612256565b90509250925092565b600082516124a2818460208701612636565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b9182526001600160a01b0316602082015260400190565b602081526000825180602084015261251a816040850160208701612636565b601f01601f19169190910160400192915050565b60208082526018908201527745434453413a20696e76616c6964207369676e617475726560401b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b604051601f8201601f1916810167ffffffffffffffff811182821017156125c0576125c0612693565b604052919050565b600082198211156125db576125db61267d565b500190565b6000826125fb57634e487b7160e01b81526012600452602481fd5b500490565b600081600019048311821515161561261a5761261a61267d565b500290565b6000828210156126315761263161267d565b500390565b60005b83811015612651578181015183820152602001612639565b838111156119315750506000910152565b60006000198214156126765761267661267d565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146120fe57600080fd5b80151581146120fe57600080fdfea2646970667358221220033276b12d8327ffac325b7dc2429c1befce88200b40dbe2217f5e691e8f1e9164736f6c63430008040033
Verified Source Code Full Match
Compiler: v0.8.4+commit.c7e474f2
EVM: istanbul
Optimization: Yes (100 runs)
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);
}
IWETH9.sol 10 lines
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IWETH9 is IERC20 {
function deposit() external payable;
function withdraw(uint256 _amount) external;
}
EIP712.sol 44 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
/// @title EIP712
/// @author 0xAd1
/// @notice Used to verify signatures
contract EIP712 {
/// @notice Verifies a signature against alleged signer of the signature
/// @param signature Signature to verify
/// @param authority Signer of the signature
/// @return True if the signature is signed by authority
function verifySignatureAgainstAuthority(
address recipient,
bytes memory signature,
address authority
) internal view returns (bool) {
bytes32 eip712DomainHash = keccak256(
abi.encode(
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
),
keccak256(bytes("Batcher")),
keccak256(bytes("1")),
1,
address(this)
)
);
bytes32 hashStruct = keccak256(
abi.encode(keccak256("deposit(address owner)"), recipient)
);
bytes32 hash = keccak256(
abi.encodePacked("\x19\x01", eip712DomainHash, hashStruct)
);
address signer = ECDSA.recover(hash, signature);
require(signer == authority, "ECDSA: Invalid authority");
require(signer != address(0), "ECDSA: invalid signature");
return true;
}
}
Batcher.sol 415 lines
/// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./interfaces/IBatcher.sol";
import "../../interfaces/IVault.sol";
import "../../interfaces/IWETH9.sol";
import "./EIP712.sol";
/// @title Batcher
/// @author 0xAd1, Bapireddy
/// @notice Used to batch user deposits and withdrawals until the next rebalance
contract Batcher is IBatcher, EIP712, ReentrancyGuard {
using SafeERC20 for IERC20;
/// @notice WETH token address on mainnet
IWETH9 public immutable WETH;
/// @notice Vault parameters for the batcher
VaultInfo public vaultInfo;
/// @notice Enforces signature checking on deposits
bool public checkValidDepositSignature;
/// @notice Creates a new Batcher strictly linked to a vault
/// @param _verificationAuthority Address of the verification authority which allows users to deposit
/// @param vaultAddress Address of the vault which will be used to deposit and withdraw want tokens
/// @param maxAmount Maximum amount of tokens that can be deposited in the vault
constructor(
address _verificationAuthority,
address vaultAddress,
uint256 maxAmount
) {
verificationAuthority = _verificationAuthority;
checkValidDepositSignature = true;
require(vaultAddress != address(0), "NULL_ADDRESS");
vaultInfo = VaultInfo({
vaultAddress: vaultAddress,
tokenAddress: IVault(vaultAddress).wantToken(),
maxAmount: maxAmount
});
WETH = IWETH9(vaultInfo.tokenAddress);
IERC20(vaultInfo.tokenAddress).approve(vaultAddress, type(uint256).max);
}
/*///////////////////////////////////////////////////////////////
USER DEPOSIT/WITHDRAWAL LOGIC
//////////////////////////////////////////////////////////////*/
/// @notice Ledger to maintain addresses and their amounts to be deposited into vault
mapping(address => uint256) public depositLedger;
/// @notice Ledger to maintain addresses and their amounts to be withdrawn from vault
mapping(address => uint256) public withdrawLedger;
/// @notice Address which authorises users to deposit into Batcher
address public verificationAuthority;
/// @notice Amount of want tokens pending to be deposited
uint256 public pendingDeposit;
/// @notice Amount of LP tokens pending to be exchanged back to want token
uint256 public pendingWithdrawal;
/**
* @notice Stores the deposits for future batching via periphery
* @param amountIn Value of token to be deposited. It will be ignored if txn is sent with native ETH
* @param signature signature verifying that recipient has enough karma and is authorized to deposit by brahma
* @param recipient address receiving the shares issued by vault
*/
function depositFunds(
uint256 amountIn,
bytes memory signature,
address recipient
) external payable override nonReentrant {
validDeposit(recipient, signature);
uint256 wethBalanceBeforeTransfer = WETH.balanceOf(address(this));
/// Checks wei sent with txn
uint256 ethSent = msg.value;
/// Convert wei if sent
if (ethSent > 0) {
amountIn = ethSent;
WETH.deposit{value: ethSent}();
}
/// If no wei sent, use amountIn and transfer WETH from txn sender
else {
IERC20(vaultInfo.tokenAddress).safeTransferFrom(
msg.sender,
address(this),
amountIn
);
}
uint256 wethBalanceAfterTransfer = WETH.balanceOf(address(this));
/// Check in both cases for WETH balance increase to be correct
assert(
wethBalanceAfterTransfer - wethBalanceBeforeTransfer == amountIn
);
require(
IERC20(vaultInfo.vaultAddress).totalSupply() +
pendingDeposit -
pendingWithdrawal +
amountIn <=
vaultInfo.maxAmount,
"MAX_LIMIT_EXCEEDED"
);
depositLedger[recipient] = depositLedger[recipient] + (amountIn);
pendingDeposit = pendingDeposit + amountIn;
emit DepositRequest(recipient, vaultInfo.vaultAddress, amountIn);
}
/**
* @notice User deposits vault LP tokens to be withdrawn. Stores the deposits for future batching via periphery
* @param amountIn Value of token to be deposited
*/
function initiateWithdrawal(uint256 amountIn)
external
override
nonReentrant
{
require(depositLedger[msg.sender] == 0, "DEPOSIT_PENDING");
require(amountIn > 0, "AMOUNT_IN_ZERO");
if (amountIn > userLPTokens[msg.sender]) {
IERC20(vaultInfo.vaultAddress).safeTransferFrom(
msg.sender,
address(this),
amountIn - userLPTokens[msg.sender]
);
userLPTokens[msg.sender] = 0;
} else {
userLPTokens[msg.sender] = userLPTokens[msg.sender] - amountIn;
}
withdrawLedger[msg.sender] = withdrawLedger[msg.sender] + (amountIn);
pendingWithdrawal = pendingWithdrawal + amountIn;
emit WithdrawRequest(msg.sender, vaultInfo.vaultAddress, amountIn);
}
/**
* @notice Allows user to collect want token back after successfull batch withdrawal
* @param amountOut Amount of token to be withdrawn
*/
function completeWithdrawal(uint256 amountOut, address recipient)
external
override
nonReentrant
{
require(amountOut != 0, "INVALID_AMOUNTOUT");
// Will revert if not enough balance
userWantTokens[recipient] = userWantTokens[recipient] - amountOut;
IERC20(vaultInfo.tokenAddress).safeTransfer(recipient, amountOut);
emit WithdrawComplete(recipient, vaultInfo.vaultAddress, amountOut);
}
/**
* @notice Can be used to send LP tokens owed to the recipient
* @param amount Amount of LP tokens to withdraw
* @param recipient Address to receive the LP tokens
*/
function claimTokens(uint256 amount, address recipient)
public
override
nonReentrant
{
require(userLPTokens[recipient] >= amount, "NO_FUNDS");
userLPTokens[recipient] = userLPTokens[recipient] - amount;
IERC20(vaultInfo.vaultAddress).safeTransfer(recipient, amount);
}
/*///////////////////////////////////////////////////////////////
VAULT DEPOSIT/WITHDRAWAL LOGIC
//////////////////////////////////////////////////////////////*/
/// @notice Ledger to maintain addresses and vault LP tokens which batcher owes them
mapping(address => uint256) public userLPTokens;
/// @notice Ledger to maintain addresses and vault want tokens which batcher owes them
mapping(address => uint256) public userWantTokens;
/**
* @notice Performs deposits on the periphery for the supplied users in batch
* @param users array of users whose deposits must be resolved
*/
function batchDeposit(address[] memory users)
external
override
nonReentrant
{
onlyKeeper();
IVault vault = IVault(vaultInfo.vaultAddress);
uint256 amountToDeposit = 0;
uint256 oldLPBalance = IERC20(address(vault)).balanceOf(address(this));
// Temprorary array to hold user deposit info and check for duplicate addresses
uint256[] memory depositValues = new uint256[](users.length);
for (uint256 i = 0; i < users.length; i++) {
// Copies deposit value from ledger to temporary array
uint256 userDeposit = depositLedger[users[i]];
amountToDeposit = amountToDeposit + userDeposit;
depositValues[i] = userDeposit;
// deposit ledger for that address is set to zero
// Incase of duplicate address sent, new deposit amount used for same user will be 0
depositLedger[users[i]] = 0;
}
require(amountToDeposit > 0, "NO_DEPOSITS");
uint256 lpTokensReportedByVault = vault.deposit(
amountToDeposit,
address(this)
);
uint256 lpTokensReceived = IERC20(address(vault)).balanceOf(
address(this)
) - (oldLPBalance);
require(
lpTokensReceived == lpTokensReportedByVault,
"LP_TOKENS_MISMATCH"
);
uint256 totalUsersProcessed = 0;
for (uint256 i = 0; i < users.length; i++) {
uint256 userAmount = depositValues[i];
// Checks if userAmount is not 0, only then proceed to allocate LP tokens
if (userAmount > 0) {
uint256 userShare = (userAmount * (lpTokensReceived)) /
(amountToDeposit);
// Allocating LP tokens to user, can be calimed by the user later by calling claimTokens
userLPTokens[users[i]] = userLPTokens[users[i]] + userShare;
++totalUsersProcessed;
}
}
pendingDeposit = pendingDeposit - amountToDeposit;
emit BatchDepositSuccessful(lpTokensReceived, totalUsersProcessed);
}
/**
* @notice Performs withdraws on the periphery for the supplied users in batch
* @param users array of users whose deposits must be resolved
*/
function batchWithdraw(address[] memory users)
external
override
nonReentrant
{
onlyKeeper();
IVault vault = IVault(vaultInfo.vaultAddress);
IERC20 token = IERC20(vaultInfo.tokenAddress);
uint256 amountToWithdraw = 0;
uint256 oldWantBalance = token.balanceOf(address(this));
// Temprorary array to hold user withdrawal info and check for duplicate addresses
uint256[] memory withdrawValues = new uint256[](users.length);
for (uint256 i = 0; i < users.length; i++) {
uint256 userWithdraw = withdrawLedger[users[i]];
amountToWithdraw = amountToWithdraw + userWithdraw;
withdrawValues[i] = userWithdraw;
// Withdrawal ledger for that address is set to zero
// Incase of duplicate address sent, new withdrawal amount used for same user will be 0
withdrawLedger[users[i]] = 0;
}
require(amountToWithdraw > 0, "NO_WITHDRAWS");
uint256 wantTokensReportedByVault = vault.withdraw(
amountToWithdraw,
address(this)
);
uint256 wantTokensReceived = token.balanceOf(address(this)) -
(oldWantBalance);
require(
wantTokensReceived == wantTokensReportedByVault,
"WANT_TOKENS_MISMATCH"
);
uint256 totalUsersProcessed = 0;
for (uint256 i = 0; i < users.length; i++) {
uint256 userAmount = withdrawValues[i];
// Checks if userAmount is not 0, only then proceed to allocate want tokens
if (userAmount > 0) {
uint256 userShare = (userAmount * wantTokensReceived) /
amountToWithdraw;
// Allocating want tokens to user. Can be claimed by the user by calling completeWithdrawal
userWantTokens[users[i]] = userWantTokens[users[i]] + userShare;
++totalUsersProcessed;
}
}
pendingWithdrawal = pendingWithdrawal - amountToWithdraw;
emit BatchWithdrawSuccessful(wantTokensReceived, totalUsersProcessed);
}
/*///////////////////////////////////////////////////////////////
INTERNAL HELPERS
//////////////////////////////////////////////////////////////*/
/// @notice Helper to verify signature against verification authority
/// @param signature Should be generated by verificationAuthority. Should contain msg.sender
function validDeposit(address recipient, bytes memory signature)
internal
view
{
if (checkValidDepositSignature) {
require(
verifySignatureAgainstAuthority(
recipient,
signature,
verificationAuthority
),
"INVALID_SIGNATURE"
);
}
require(withdrawLedger[msg.sender] == 0, "WITHDRAW_PENDING");
}
/*///////////////////////////////////////////////////////////////
MAINTAINANCE ACTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Function to set authority address
/// @param authority New authority address
function setAuthority(address authority) public {
onlyGovernance();
// Logging old and new verification authority
emit VerificationAuthorityUpdated(verificationAuthority, authority);
verificationAuthority = authority;
}
/// @inheritdoc IBatcher
function setVaultLimit(uint256 maxAmount) external override {
onlyGovernance();
vaultInfo.maxAmount = maxAmount;
}
/// @notice Function to enable/disable deposit signature check
function setDepositSignatureCheck(bool enabled) public {
onlyGovernance();
checkValidDepositSignature = enabled;
}
/// @notice Function to sweep funds out in case of emergency, can only be called by governance
/// @param _token Address of token to sweep
function sweep(address _token) public nonReentrant {
onlyGovernance();
IERC20(_token).transfer(
msg.sender,
IERC20(_token).balanceOf(address(this))
);
}
/*///////////////////////////////////////////////////////////////
ACCESS MODIFERS
//////////////////////////////////////////////////////////////*/
/// @notice Helper to get Governance address from Vault contract
/// @return Governance address
function governance() public view returns (address) {
return IVault(vaultInfo.vaultAddress).governance();
}
/// @notice Helper to get Keeper address from Vault contract
/// @return Keeper address
function keeper() public view returns (address) {
return IVault(vaultInfo.vaultAddress).keeper();
}
/// @notice Helper to assert msg.sender as keeper address
function onlyKeeper() internal view {
require(msg.sender == keeper(), "ONLY_KEEPER");
}
/// @notice Helper to asset msg.sender as governance address
function onlyGovernance() internal view {
require(governance() == msg.sender, "ONLY_GOV");
}
}
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);
}
}
}
}
Strings.sol 67 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @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] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
IBatcher.sol 86 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/**
* @title IBatcher
* @notice A batcher to resolve vault deposits/withdrawals in batches
* @dev Provides an interface for Batcher
*/
interface IBatcher {
/// @notice Data structure to store vault info
/// @param vaultAddress Address of the vault
/// @param tokenAddress Address vault's want token
/// @param maxAmount Max amount of tokens to deposit in vault
/// @param currentAmount Current amount of wantTokens deposited in the vault
struct VaultInfo {
address vaultAddress;
address tokenAddress;
uint256 maxAmount;
}
/// @notice Deposit event
/// @param sender Address of the depositor
/// @param vault Address of the vault
/// @param amountIn Tokens deposited
event DepositRequest(
address indexed sender,
address indexed vault,
uint256 amountIn
);
/// @notice Withdraw initiate event
/// @param sender Address of the withdawer
/// @param vault Address of the vault
/// @param amountOut Tokens deposited
event WithdrawRequest(
address indexed sender,
address indexed vault,
uint256 amountOut
);
/// @notice Batch Deposit event
/// @param amountIn Tokens deposited
/// @param totalUsers Total number of users in the batch
event BatchDepositSuccessful(uint256 amountIn, uint256 totalUsers);
/// @notice Batch Withdraw event
/// @param amountOut Tokens withdrawn
/// @param totalUsers Total number of users in the batch
event BatchWithdrawSuccessful(uint256 amountOut, uint256 totalUsers);
/// @notice Withdraw complete event
/// @param sender Address of the withdawer
/// @param vault Address of the vault
/// @param amountOut Tokens deposited
event WithdrawComplete(
address indexed sender,
address indexed vault,
uint256 amountOut
);
/// @notice Verification authority update event
/// @param oldVerificationAuthority address of old verification authority
/// @param newVerificationAuthority address of new verification authority
event VerificationAuthorityUpdated(
address indexed oldVerificationAuthority,
address indexed newVerificationAuthority
);
function depositFunds(
uint256 amountIn,
bytes memory signature,
address recipient
) external payable;
function claimTokens(uint256 amount, address recipient) external;
function initiateWithdrawal(uint256 amountIn) external;
function completeWithdrawal(uint256 amountOut, address recipient) external;
function batchDeposit(address[] memory users) external;
function batchWithdraw(address[] memory users) external;
function setVaultLimit(uint256 maxLimit) external;
}
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;
}
}
ECDSA.sol 230 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
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
WETH 0xad5c4648 → address
checkValidDepositSignature 0x66b1a5de → bool
depositLedger 0xa5c82f18 → uint256
governance 0x5aa6e675 → address
keeper 0xaced1661 → address
pendingDeposit 0xf64c6f32 → uint256
pendingWithdrawal 0x7e288822 → uint256
userLPTokens 0x527839b0 → uint256
userWantTokens 0xda5f05af → uint256
vaultInfo 0x501ec738 → address, address, uint256
verificationAuthority 0xe6ac418a → address
withdrawLedger 0x5b9d2658 → uint256
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
batchDeposit 0xec3b613d
address[] users
batchWithdraw 0x431cc3dd
address[] users
claimTokens 0x6e164e23
uint256 amount
address recipient
completeWithdrawal 0xec7a0d98
uint256 amountOut
address recipient
depositFunds 0xba9a3587
uint256 amountIn
bytes signature
address recipient
initiateWithdrawal 0x12edde5e
uint256 amountIn
setAuthority 0x7a9e5e4b
address authority
setDepositSignatureCheck 0x0a3d95d8
bool enabled
setVaultLimit 0x474a3b84
uint256 maxAmount
sweep 0x01681a62
address _token
Recent Transactions
No transactions found for this address