Address Contract Verified
Address
0xd1EBaa101867B3df136640C843d69a4646613fED
Balance
0 ETH
Nonce
206
Code Size
11295 bytes
Creator
0xba9e6211...1918 at tx 0x43fd2072...855017
Indexed Transactions
0
Contract Bytecode
11295 bytes
0x608060405260043610620001845760003560e01c80638da5cb5b11620000e2578063a80dcfee1162000095578063d547741f116200006c578063d547741f146200050b578063da4c459b1462000530578063e3f1bc2b146200054c578063f2fde38b146200056e57600080fd5b8063a80dcfee1462000480578063aa182aef14620004b4578063b09e0bec14620004f457600080fd5b80638da5cb5b14620003b85780638ec67eca14620003d857806391d1485414620003fd578063958792a61462000422578063958c2e521462000447578063a217fddf146200046957600080fd5b806331bff521116200013b57806331bff52114620002c157806336568abe14620002fe578063715018a614620003235780637a997ab7146200033b57806385b59cc614620003715780638bcea939146200039657600080fd5b806301ffc9a7146200018957806302c9033114620001c35780630d392cd914620001f75780631ec32d15146200021e578063248a9ca314620002595780632f2ff15d146200029c575b600080fd5b3480156200019657600080fd5b50620001ae620001a8366004620016f0565b62000593565b60405190151581526020015b60405180910390f35b348015620001d057600080fd5b50620001ae620001e236600462001732565b60076020526000908152604090205460ff1681565b3480156200020457600080fd5b506200021c6200021636600462001761565b620005cb565b005b3480156200022b57600080fd5b5060045462000240906001600160a01b031681565b6040516001600160a01b039091168152602001620001ba565b3480156200026657600080fd5b506200028d620002783660046200179f565b60009081526002602052604090206001015490565b604051908152602001620001ba565b348015620002a957600080fd5b506200021c620002bb366004620017b9565b620006bd565b348015620002ce57600080fd5b50620001ae620002e036600462001732565b6001600160a01b031660009081526007602052604090205460ff1690565b3480156200030b57600080fd5b506200021c6200031d366004620017b9565b620006eb565b3480156200033057600080fd5b506200021c62000769565b3480156200034857600080fd5b506200028d7fdc72ed553f2544c34465af23b847953efeb813428162d767f9ba5f4013be676081565b3480156200037e57600080fd5b506200021c62000390366004620017e1565b62000781565b348015620003a357600080fd5b5060065462000240906001600160a01b031681565b348015620003c557600080fd5b506000546001600160a01b031662000240565b348015620003e557600080fd5b506200021c620003f736600462001761565b620009df565b3480156200040a57600080fd5b50620001ae6200041c366004620017b9565b62000a14565b3480156200042f57600080fd5b506200028d6200044136600462001732565b62000a3f565b3480156200045457600080fd5b5060055462000240906001600160a01b031681565b3480156200047657600080fd5b506200028d600081565b3480156200048d57600080fd5b50620001ae6200049f36600462001732565b60086020526000908152604090205460ff1681565b348015620004c157600080fd5b50600354620004db9061010090046001600160601b031681565b6040516001600160601b039091168152602001620001ba565b6200021c6200050536600462001868565b62000d86565b3480156200051857600080fd5b506200021c6200052a366004620017b9565b62000e8f565b3480156200053d57600080fd5b50600354620001ae9060ff1681565b3480156200055957600080fd5b5060095462000240906001600160a01b031681565b3480156200057b57600080fd5b506200021c6200058d36600462001732565b62000eb8565b60006001600160e01b03198216637965db0b60e01b1480620005c557506301ffc9a760e01b6001600160e01b03198316145b92915050565b620005d562000f37565b620006017fdc72ed553f2544c34465af23b847953efeb813428162d767f9ba5f4013be67603362000a14565b1580156200062a5750336200061e6000546001600160a01b031690565b6001600160a01b031614155b15620006505760405163161db5fb60e31b81523360048201526024015b60405180910390fd5b6001600160a01b038216600081815260086020908152604091829020805460ff19168515159081179091558251938452908301527fb1288e9f7bae3599e10819d5553febea48e11a6f8f585b32c8abad397dd2627e910160405180910390a1620006b960018055565b5050565b600082815260026020526040902060010154620006da8162000f92565b620006e6838362000f9e565b505050565b6001600160a01b03811633146200075d5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840162000647565b620006b9828262001028565b6200077362001092565b6200077f6000620010ee565b565b6200078b62001092565b83806001600160a01b03163b600003620007b857604051636f7c43f160e01b815260040160405180910390fd5b83806001600160a01b03163b600003620007e557604051636f7c43f160e01b815260040160405180910390fd5b6001600160a01b0383166200080d5760405163d92e233d60e01b815260040160405180910390fd5b600580546001600160a01b03199081166001600160a01b03898116918217909355600680548316898516179055600380546cffffffffffffffffffffffff0019166101006001600160601b038a160217905560048054831687851617815560098054909316938b1693909317909155604080516315ab88c960e31b81529051919263ad5c46489282820192602092908290030181865afa158015620008b6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620008dc9190620018a0565b6001600160a01b0316600660009054906101000a90046001600160a01b03166001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000939573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200095f9190620018a0565b6003805460ff19166001600160a01b03928316939093149290921790915560045460408051898416815288841660208201526001600160601b03881691810191909152911660608201527ff9cab2a68a157c313890992ad0c6c978f9d7b285387efc4660a87b0b3e5fab429060800160405180910390a150505050505050565b620009e962001092565b6001600160a01b03919091166000908152600760205260409020805460ff1916911515919091179055565b60009182526002602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6001600160a01b03811660009081526007602052604081205460ff1615801562000a78575060035461010090046001600160601b031615155b801562000a9557503360009081526008602052604090205460ff16155b1562000d7e576009546001600160a01b03161580159062000b2b5750600960009054906101000a90046001600160a01b03166001600160a01b031663dc7b06ca6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000b05573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000b2b9190620018c0565b1562000bba57600954600354604051634b08d23560e01b81526101009091046001600160601b031660048201526001600160a01b03909116908190634b08d23590602401602060405180830381865afa15801562000b8d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000bb39190620018e0565b9392505050565b600080600660009054906101000a90046001600160a01b03166001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa15801562000c11573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000c37919062001917565b506003546001600160701b0392831694509116915060ff1662000ce8576005546003546040516385f8c25960e01b81526101009091046001600160601b0316600482015260248101839052604481018490526001600160a01b03909116906385f8c25990606401602060405180830381865afa15801562000cbc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000ce29190620018e0565b62000d76565b6005546003546040516385f8c25960e01b81526101009091046001600160601b0316600482015260248101849052604481018390526001600160a01b03909116906385f8c25990606401602060405180830381865afa15801562000d50573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000d769190620018e0565b949350505050565b506000919050565b62000d9062000f37565b8060000362000db257604051631f2a200560e01b815260040160405180910390fd5b600062000dbf846200113e565b9050600084843360405162000dd490620016e2565b6001600160a01b03938416815260208101929092529091166040820152606001604051809103906000f08015801562000e11573d6000803e3d6000fd5b50905062000e2b6001600160a01b03861633838662001213565b604080516001600160a01b03838116825260208201879052918101859052606081018490529086169033907fc06459089889dce3250dcb76e7d6c4f684761fb30c5f4908b2971d794398784c9060800160405180910390a35050620006e660018055565b60008281526002602052604090206001015462000eac8162000f92565b620006e6838362001028565b62000ec262001092565b6001600160a01b03811662000f295760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840162000647565b62000f3481620010ee565b50565b60026001540362000f8b5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640162000647565b6002600155565b62000f34813362001275565b62000faa828262000a14565b620006b95760008281526002602090815260408083206001600160a01b03851684529091529020805460ff1916600117905562000fe43390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b62001034828262000a14565b15620006b95760008281526002602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000546001600160a01b031633146200077f5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640162000647565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000806200114c8362000a3f565b905080600003620011605750600092915050565b80341015620011db5760058162001178348262001983565b6200118590606462001999565b620011919190620019b3565b1115620011bb5760405163fdba93f160e01b81526004810182905234602482015260440162000647565b600454620011d3906001600160a01b031634620012d9565b503492915050565b600454620011f3906001600160a01b031682620012d9565b80341115620005c557620005c5336200120d833462001983565b620012d9565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526200126f90859062001306565b50505050565b62001281828262000a14565b620006b9576200129181620013e2565b6200129e836020620013f5565b604051602001620012b1929190620019fc565b60408051601f198184030181529082905262461bcd60e51b8252620006479160040162001a75565b600080600080600085875af1905080620006e657604051630db2c7f160e31b815260040160405180910390fd5b60006200135d826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316620015af9092919063ffffffff16565b905080516000148062001381575080806020019051810190620013819190620018c0565b620006e65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840162000647565b6060620005c56001600160a01b03831660145b606060006200140683600262001999565b6200141390600262001aaa565b67ffffffffffffffff8111156200142e576200142e62001ac0565b6040519080825280601f01601f19166020018201604052801562001459576020820181803683370190505b509050600360fc1b8160008151811062001477576200147762001ad6565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110620014a957620014a962001ad6565b60200101906001600160f81b031916908160001a9053506000620014cf84600262001999565b620014dc90600162001aaa565b90505b60018111156200155e576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811062001514576200151462001ad6565b1a60f81b8282815181106200152d576200152d62001ad6565b60200101906001600160f81b031916908160001a90535060049490941c93620015568162001aec565b9050620014df565b50831562000bb35760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640162000647565b606062000d76848460008585600080866001600160a01b03168587604051620015d9919062001b06565b60006040518083038185875af1925050503d806000811462001618576040519150601f19603f3d011682016040523d82523d6000602084013e6200161d565b606091505b509150915062001630878383876200163b565b979650505050505050565b60608315620016af578251600003620016a7576001600160a01b0385163b620016a75760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640162000647565b508162000d76565b62000d768383815115620016c65781518083602001fd5b8060405162461bcd60e51b815260040162000647919062001a75565b6110c58062001b2583390190565b6000602082840312156200170357600080fd5b81356001600160e01b03198116811462000bb357600080fd5b6001600160a01b038116811462000f3457600080fd5b6000602082840312156200174557600080fd5b813562000bb3816200171c565b801515811462000f3457600080fd5b600080604083850312156200177557600080fd5b823562001782816200171c565b91506020830135620017948162001752565b809150509250929050565b600060208284031215620017b257600080fd5b5035919050565b60008060408385031215620017cd57600080fd5b82359150602083013562001794816200171c565b600080600080600060a08688031215620017fa57600080fd5b853562001807816200171c565b9450602086013562001819816200171c565b935060408601356200182b816200171c565b925060608601356001600160601b03811681146200184857600080fd5b915060808601356200185a816200171c565b809150509295509295909350565b6000806000606084860312156200187e57600080fd5b83356200188b816200171c565b95602085013595506040909401359392505050565b600060208284031215620018b357600080fd5b815162000bb3816200171c565b600060208284031215620018d357600080fd5b815162000bb38162001752565b600060208284031215620018f357600080fd5b5051919050565b80516001600160701b03811681146200191257600080fd5b919050565b6000806000606084860312156200192d57600080fd5b6200193884620018fa565b92506200194860208501620018fa565b9150604084015163ffffffff811681146200196257600080fd5b809150509250925092565b634e487b7160e01b600052601160045260246000fd5b81810381811115620005c557620005c56200196d565b8082028115828204841417620005c557620005c56200196d565b600082620019d157634e487b7160e01b600052601260045260246000fd5b500490565b60005b83811015620019f3578181015183820152602001620019d9565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835162001a36816017850160208801620019d6565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835162001a69816028840160208801620019d6565b01602801949350505050565b602081526000825180602084015262001a96816040850160208701620019d6565b601f01601f19169190910160400192915050565b80820180821115620005c557620005c56200196d565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b60008162001afe5762001afe6200196d565b506000190190565b6000825162001b1a818460208701620019d6565b919091019291505056fe60c060405234801561001057600080fd5b506040516110c53803806110c583398101604081905261002f916100a7565b81600003610050576040516385ac2b9960e01b815260040160405180910390fd5b6001600160a01b0392831660805260a091909152600080546001600160a01b031916919092161790556002805460ff191660011790556100e3565b80516001600160a01b03811681146100a257600080fd5b919050565b6000806000606084860312156100bc57600080fd5b6100c58461008b565b9250602084015191506100da6040850161008b565b90509250925092565b60805160a051610f946101316000396000818160b30152818161047801526106c70152600081816101ba015281816103850152818161040c0152818161056f01526107ba0152610f946000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c8063db2e21bc11610071578063db2e21bc14610152578063dbe7e3bd1461015c578063e0e716c41461017c578063f2fde38b1461018f578063fa9f0a80146101a2578063fc0c546a146101b557600080fd5b80632eb4a7ab146100ae5780634252475c146100e85780634c255c971461010b5780638da5cb5b14610114578063c8b126901461013f575b600080fd5b6100d57f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b6100fb6100f6366004610b85565b6101dc565b60405190151581526020016100df565b6100d561271081565b600054610127906001600160a01b031681565b6040516001600160a01b0390911681526020016100df565b6100d561014d366004610b9e565b610201565b61015a61031f565b005b6100d561016a366004610b85565b60016020526000908152604090205481565b61015a61018a366004610c57565b610438565b61015a61019d366004610d07565b6105e8565b61015a6101b0366004610d22565b61065c565b6101277f000000000000000000000000000000000000000000000000000000000000000081565b600881901c600090815260036020526040812054600160ff84161b1615155b92915050565b60008442101561021357506000610315565b8342111561023b576000878152600160205260409020546102349087610ddd565b9050610315565b600083806102498842610ddd565b6102539190610df0565b61025d9190610e12565b905082156102da5760006127106102748986610e12565b61027e9190610df0565b9050600061028c8888610ddd565b610296838b610ddd565b6102a09085610e12565b6102aa9190610df0565b60008b8152600160205260409020549091506102c68383610e29565b6102d09190610ddd565b9350505050610315565b6000888152600160205260409020546102f38787610ddd565b6102fd8984610e12565b6103079190610df0565b6103119190610ddd565b9150505b9695505050505050565b6000546001600160a01b0316331461034a57604051635fc483c560e01b815260040160405180910390fd5b60025460ff1661036d576040516333e1b91560e01b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa1580156103d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103f89190610e3c565b600054909150610435906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116911683610834565b50565b60008b8b8b8b8b8b8b8b604051602001610459989796959493929190610e55565b60405160208183030381529060405280519060200120905061049d84847f00000000000000000000000000000000000000000000000000000000000000008461088b565b6104ba576040516309bde33960e01b815260040160405180910390fd5b6104c38c6101dc565b156104e1576040516344825a4b60e01b815260040160405180910390fd5b60006104f18d8c8b8b8b8b610201565b905080600003610514576040516312d37ee560e31b815260040160405180910390fd5b8083111561053557604051631d942e9760e01b815260040160405180910390fd5b60008d81526001602052604081208054859290610553908490610e29565b90915550506002805460ff191690556105966001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168d85610834565b8b6001600160a01b03167f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4846040516105d191815260200190565b60405180910390a250505050505050505050505050565b6000546001600160a01b0316331461061357604051635fc483c560e01b815260040160405180910390fd5b6001600160a01b03811661063a5760405163d92e233d60e01b815260040160405180910390fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b0316331461068757604051635fc483c560e01b815260040160405180910390fd5b60008a8a8a8a8a8a8a8a6040516020016106a8989796959493929190610e55565b6040516020818303038152906040528051906020012090506106ec83837f00000000000000000000000000000000000000000000000000000000000000008461088b565b610709576040516309bde33960e01b815260040160405180910390fd5b87610727576040516327abf75f60e11b815260040160405180910390fd5b6107308b6101dc565b1561074e5760405163905e710760e01b815260040160405180910390fd5b85421061076e5760405163f1e17af360e01b815260040160405180910390fd5b60088b901c60009081526003602052604090208054600160ff8e161b17905560008b8152600160205260408120546107a6908b610ddd565b6000549091506107e3906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116911683610834565b8a6001600160a01b03167f57c76f5e278bfbd4eeb5207d287aa5a1a9e1113c65f7eefa540e379a2774d13b8260405161081e91815260200190565b60405180910390a2505050505050505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526108869084906108a5565b505050565b60008261089986868561097f565b1490505b949350505050565b60006108fa826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166109cb9092919063ffffffff16565b905080516000148061091b57508080602001905181019061091b9190610e9f565b6108865760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b600081815b848110156109c2576109ae828787848181106109a2576109a2610ebc565b905060200201356109da565b9150806109ba81610ed2565b915050610984565b50949350505050565b606061089d8484600085610a0c565b60008183106109f6576000828152602084905260409020610a05565b60008381526020839052604090205b9392505050565b606082471015610a6d5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610976565b600080866001600160a01b03168587604051610a899190610f0f565b60006040518083038185875af1925050503d8060008114610ac6576040519150601f19603f3d011682016040523d82523d6000602084013e610acb565b606091505b5091509150610adc87838387610ae7565b979650505050505050565b60608315610b56578251600003610b4f576001600160a01b0385163b610b4f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610976565b508161089d565b61089d8383815115610b6b5781518083602001fd5b8060405162461bcd60e51b81526004016109769190610f2b565b600060208284031215610b9757600080fd5b5035919050565b60008060008060008060c08789031215610bb757600080fd5b505084359660208601359650604086013595606081013595506080810135945060a0013592509050565b80356001600160a01b0381168114610bf857600080fd5b919050565b801515811461043557600080fd5b60008083601f840112610c1d57600080fd5b50813567ffffffffffffffff811115610c3557600080fd5b6020830191508360208260051b8501011115610c5057600080fd5b9250929050565b60008060008060008060008060008060006101408c8e031215610c7957600080fd5b8b359a50610c8960208d01610be1565b995060408c0135985060608c0135610ca081610bfd565b975060808c0135965060a08c0135955060c08c0135945060e08c013593506101008c013567ffffffffffffffff811115610cd957600080fd5b610ce58e828f01610c0b565b915080945050809250506101208c013590509295989b509295989b9093969950565b600060208284031215610d1957600080fd5b610a0582610be1565b6000806000806000806000806000806101208b8d031215610d4257600080fd5b8a359950610d5260208c01610be1565b985060408b0135975060608b0135610d6981610bfd565b965060808b0135955060a08b0135945060c08b0135935060e08b013592506101008b013567ffffffffffffffff811115610da257600080fd5b610dae8d828e01610c0b565b915080935050809150509295989b9194979a5092959850565b634e487b7160e01b600052601160045260246000fd5b818103818111156101fb576101fb610dc7565b600082610e0d57634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176101fb576101fb610dc7565b808201808211156101fb576101fb610dc7565b600060208284031215610e4e57600080fd5b5051919050565b97885260609690961b6bffffffffffffffffffffffff19166020880152603487019490945291151560f81b605486015260558501526075840152609583015260b582015260d50190565b600060208284031215610eb157600080fd5b8151610a0581610bfd565b634e487b7160e01b600052603260045260246000fd5b600060018201610ee457610ee4610dc7565b5060010190565b60005b83811015610f06578181015183820152602001610eee565b50506000910152565b60008251610f21818460208701610eeb565b9190910192915050565b6020815260008251806020840152610f4a816040850160208701610eeb565b601f01601f1916919091016040019291505056fea2646970667358221220a4eefd9bddd4523e358ca0b3ccc1ea61378443800db85524f5976743c4fccb2c64736f6c63430008110033a2646970667358221220590053fde24b1b682d3c1252a0009639e619666b3f9c932a0a50ec4f7d57b2fc64736f6c63430008110033
Verified Source Code Full Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: Yes (200 runs)
Vesting.sol 168 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
import "openzeppelin-contracts/utils/cryptography/MerkleProof.sol";
import "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
import "openzeppelin-contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/utils/structs/BitMaps.sol";
contract Vesting {
using BitMaps for BitMaps.BitMap;
using SafeERC20 for IERC20;
address public immutable token;
bytes32 public immutable merkleRoot;
uint256 public constant MAX_PERCENTAGE = 1e4;
address public owner;
mapping(uint256 => uint256) public claimed;
bool internal _brokenMerkleRootEmergencyWithdrawPossible;
BitMaps.BitMap private _revokedBitmap;
error InvalidProof();
error NothingToClaim();
error EmptyMerkleRoot();
error OnlyOwner();
error AlreadyRevoked();
error ZeroAddress();
error CantRevokeEndedVesting();
error UnrevocableVesting();
error ClaimAmountGtClaimable();
error Revoked();
error NoBrokenRootEmergency();
error InvalidSender();
event Claim(address indexed account, uint256 amount);
event VestingRevoked(address indexed account, uint256 amountUnvested);
constructor(
address _token,
bytes32 _merkleRoot,
address _owner
) {
if (_merkleRoot == "") revert EmptyMerkleRoot();
token = _token;
merkleRoot = _merkleRoot;
owner = _owner;
_brokenMerkleRootEmergencyWithdrawPossible = true;
}
modifier onlyOwner() {
if (msg.sender != owner) revert OnlyOwner();
_;
}
function claim(
uint256 index,
address account,
uint256 amount,
bool revocable,
uint256 start,
uint256 end,
uint256 cadence,
uint256 percentageOnStart,
bytes32[] calldata merkleProof,
uint256 claimAmount
) public {
bytes32 node = keccak256(
abi.encodePacked(index, account, amount, revocable, start, end, cadence, percentageOnStart)
);
if (!MerkleProof.verifyCalldata(merkleProof, merkleRoot, node)) revert InvalidProof();
if (getRevoked(index)) revert Revoked();
// prevent DDOS attacks by claiming for other users
//if (msg.sender != account) revert InvalidSender();
uint256 claimable = getClaimable(index, amount, start, end, cadence, percentageOnStart);
if (claimable == 0) revert NothingToClaim();
if (claimAmount > claimable) revert ClaimAmountGtClaimable();
claimed[index] += claimAmount;
_brokenMerkleRootEmergencyWithdrawPossible = false;
IERC20(token).safeTransfer(account, claimAmount);
emit Claim(account, claimAmount);
}
function stopVesting(
uint256 index,
address account,
uint256 amount,
bool revocable,
uint256 start,
uint256 end,
uint256 cadence,
uint256 percentageOnStart,
bytes32[] calldata merkleProof
) external onlyOwner {
bytes32 node = keccak256(
abi.encodePacked(index, account, amount, revocable, start, end, cadence, percentageOnStart)
);
if (!MerkleProof.verifyCalldata(merkleProof, merkleRoot, node)) revert InvalidProof();
if (!revocable) revert UnrevocableVesting();
if (getRevoked(index)) revert AlreadyRevoked();
if (block.timestamp >= end) revert CantRevokeEndedVesting();
setRevoked(index);
// transfer the vesting progress and the leftover amount to the contract owner
uint256 rest = amount - claimed[index];
IERC20(token).safeTransfer(owner, rest);
emit VestingRevoked(account, rest);
}
/**
* @dev in case of a deployment with a broken merkle root, the owner can emergeny-withdraw all funds
* @notice this can only be called if no tokens where ever successfully claimed!
*/
function emergencyWithdraw() external onlyOwner {
if (!_brokenMerkleRootEmergencyWithdrawPossible) revert NoBrokenRootEmergency();
uint256 totalAmount = IERC20(token).balanceOf(address(this));
IERC20(token).safeTransfer(owner, totalAmount);
}
function getClaimable(
uint256 index,
uint256 amount,
uint256 start,
uint256 end,
uint256 cadence,
uint256 percentageOnStart
) public view returns (uint256) {
if (block.timestamp < start) return 0;
if (block.timestamp > end) return amount - claimed[index];
uint256 elapsed = ((block.timestamp - start) / cadence) * cadence;
if (percentageOnStart != 0) {
uint256 claimableOnStart = (percentageOnStart * amount) / MAX_PERCENTAGE;
uint256 claimableRest = (elapsed * (amount - claimableOnStart)) / (end - start);
return claimableRest + claimableOnStart - claimed[index];
}
return (elapsed * amount) / (end - start) - claimed[index];
}
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) revert ZeroAddress();
owner = newOwner;
}
function getRevoked(uint256 index) public view returns (bool) {
return _revokedBitmap.get(index);
}
function setRevoked(uint256 index) internal {
_revokedBitmap.set(index);
}
}
VestingFactory.sol 210 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
import {Vesting} from "./Vesting.sol";
import {IPriceEstimator} from "./interfaces/IPriceEstimator.sol";
import {IUniswapV2Router02} from "./interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Pair} from "./interfaces/IUniswapV2Pair.sol";
import {SafeERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
import {ReentrancyGuard} from "openzeppelin-contracts/security/ReentrancyGuard.sol";
import {AccessControl} from "openzeppelin-contracts/access/AccessControl.sol";
contract VestingFactory is Ownable, ReentrancyGuard, AccessControl {
using SafeERC20 for IERC20;
bool public isWethFirst;
uint96 public feesInUSD;
address public companyWallet;
IUniswapV2Router02 public uniV2Router;
IUniswapV2Pair public uniV2Pair;
mapping(address => bool) public feelessTokens;
mapping(address => bool) public whitelistedWallets;
bytes32 public constant WHITELIST_ROLE = keccak256("WHITELIST_ROLE");
address public priceEstimator;
error NotContract();
error ZeroAddress();
error FeeNotMet(uint256 required, uint256 provided);
error ZeroAmount();
error EthTransferFailed();
error NotAuthorizedToWhitelist(address sender);
event VestingCreated(
address indexed creator,
address vestingAddr,
address indexed token,
bytes32 merkleRoot,
uint256 totalAmount,
uint256 fee
);
event FeesChange(address uniV2Router, address uniV2Pair, uint256 feesUsd, address companyWallet);
event WhiteListUpdated(address wallet, bool noFee);
constructor() {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
modifier onlyContract(address account) {
if (account.code.length == 0) revert NotContract();
_;
}
/**
* @notice Create a new vesting contract
* @param token address of the token contract
* @param merkleRoot bytes32 of the merkle root
* @param totalAmount uint256 total amount of tokens
*/
function createVesting(
address token,
bytes32 merkleRoot,
uint256 totalAmount
) external payable nonReentrant {
if (totalAmount == 0) revert ZeroAmount();
uint256 fee = handleFees(token);
Vesting vesting = new Vesting(token, merkleRoot, msg.sender);
IERC20(token).safeTransferFrom(msg.sender, address(vesting), totalAmount);
emit VestingCreated(msg.sender, address(vesting), token, merkleRoot, totalAmount, fee);
}
/**
* @notice Safely transfer ETH
* @param to address of the recipient
* @param amount uint256 amount to transfer
*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
if (!success) revert EthTransferFailed();
}
/**
* @notice Handle fees for creating a vesting contract
* @param token address of the token contract
* @return feeInEth uint256 amount of fee in ETH
*/
function handleFees(address token) internal returns (uint256) {
uint256 feeInEth = getFeeInETH(token);
if (feeInEth == 0) {
return 0;
}
if (msg.value < feeInEth) {
// allow 5% less fee due to price change
if (((feeInEth - msg.value) * 100) / feeInEth > 5) revert FeeNotMet(feeInEth, msg.value);
safeTransferETH(companyWallet, msg.value);
return msg.value;
}
safeTransferETH(companyWallet, feeInEth);
if (msg.value > feeInEth) {
safeTransferETH(msg.sender, msg.value - feeInEth);
}
return feeInEth;
}
/**
* @notice Set the fee parameters for the factory and decide if price oracle should be used (onlyOwner)
* @param _priceEstimator address of the CL price feed contract
* @param _uniV2Router address of the uniswap router
* @param _uniV2Pair address of the uniswap pair
* @param _feesInUSD fees in USD
* @param _companyWallet address of the company wallet
*/
function setFeeParams(
address _priceEstimator,
address _uniV2Router,
address _uniV2Pair,
uint96 _feesInUSD,
address _companyWallet
) external onlyOwner onlyContract(_uniV2Router) onlyContract(_uniV2Pair) {
if (_companyWallet == address(0)) revert ZeroAddress();
uniV2Router = IUniswapV2Router02(_uniV2Router);
uniV2Pair = IUniswapV2Pair(_uniV2Pair);
feesInUSD = _feesInUSD;
companyWallet = _companyWallet;
priceEstimator = _priceEstimator;
isWethFirst = uniV2Pair.token0() == uniV2Router.WETH();
emit FeesChange(_uniV2Router, _uniV2Pair, _feesInUSD, companyWallet);
}
/**
* @notice Update the whitelist of wallets that can create vesting contracts without fees
* @param wallet address of the wallet
* @param noFee bool if wallet should be feeless
*/
function updateWhitelist(address wallet, bool noFee) external nonReentrant
{
if(
!hasRole(WHITELIST_ROLE, msg.sender) && owner() != msg.sender
)
{
revert NotAuthorizedToWhitelist(msg.sender);
}
whitelistedWallets[wallet] = noFee;
emit WhiteListUpdated(wallet, noFee);
}
/**
* TODO: this function needs to use an oracle to get the price of the token in USD
* @param token address of the token contract
*/
function getFeeInETH(address token) public view returns (uint256) {
// check if token is listed as free or fee params not set
if (!isFreeToken(token) && feesInUSD != 0 && !whitelistedWallets[msg.sender]) {
if (priceEstimator != address(0) && IPriceEstimator(priceEstimator).getUseOracle()) {
// use oracle
IPriceEstimator _priceEstimator = IPriceEstimator(priceEstimator);
return _priceEstimator.getFeeInETHWithOracle(feesInUSD);
} else {
// use uniswap
(uint256 reserve0, uint256 reserve1, ) = uniV2Pair.getReserves();
return
isWethFirst
? uniV2Router.getAmountIn(feesInUSD, reserve0, reserve1)
: uniV2Router.getAmountIn(feesInUSD, reserve1, reserve0);
}
}
return 0;
}
/**
* @notice Set token as feeless
* @param tokenAddress address of the token
* @param feeless bool if token should be feeless
*/
function setFeelessToken(address tokenAddress, bool feeless) public onlyOwner {
feelessTokens[tokenAddress] = feeless;
}
/**
* @dev Checks if token is in free list
* @param token The address to check
* @return bool true if token is free
*/
function isFreeToken(address token)
public
view
returns(bool)
{
return feelessTokens[token];
}
}
IUniswapV2Pair.sol 97 lines
// solhint-disable func-name-mixedcase
pragma solidity 0.8.17;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint256);
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Mint(address indexed sender, uint256 amount0, uint256 amount1);
event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);
event Swap(
address indexed sender,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint256);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves()
external
view
returns (
uint112 reserve0,
uint112 reserve1,
uint32 blockTimestampLast
);
function price0CumulativeLast() external view returns (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);
function mint(address to) external returns (uint256 liquidity);
function burn(address to) external returns (uint256 amount0, uint256 amount1);
function swap(
uint256 amount0Out,
uint256 amount1Out,
address to,
bytes calldata data
) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
IPriceEstimator.sol 25 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
interface IPriceEstimator {
function setOracleParams(
address _dataFeed,
bool _useOracle
) external;
function getEstimatedETHforERC20(
uint256 erc20Amount,
address token
) external view returns (uint256[] memory);
function getEstimatedERC20forETH(
uint256 etherAmountInWei,
address tokenAddress
) external view returns (uint256[] memory);
function getFeeInETHWithOracle(
uint256 _feesInUSD
) external view returns (uint256);
function getUseOracle() external view returns (bool);
}
IUniswapV2Router01.sol 155 lines
// solhint-disable func-name-mixedcase
pragma solidity 0.8.17;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
)
external
returns (
uint256 amountA,
uint256 amountB,
uint256 liquidity
);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETHWithPermit(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(
uint256 amountOut,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function quote(
uint256 amountA,
uint256 reserveA,
uint256 reserveB
) external pure returns (uint256 amountB);
function getAmountOut(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) external pure returns (uint256 amountOut);
function getAmountIn(
uint256 amountOut,
uint256 reserveIn,
uint256 reserveOut
) external pure returns (uint256 amountIn);
function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts);
}
IUniswapV2Router02.sol 50 lines
pragma solidity 0.8.17;
import "./IUniswapV2Router01.sol";
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [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://consensys.net/diligence/blog/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.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Strings.sol 85 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Math.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
AccessControl.sol 248 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
BitMaps.sol 51 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/BitMaps.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.
* Largely inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
*/
library BitMaps {
struct BitMap {
mapping(uint256 => uint256) _data;
}
/**
* @dev Returns whether the bit at `index` is set.
*/
function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
return bitmap._data[bucket] & mask != 0;
}
/**
* @dev Sets the bit at `index` to the boolean `value`.
*/
function setTo(BitMap storage bitmap, uint256 index, bool value) internal {
if (value) {
set(bitmap, index);
} else {
unset(bitmap, index);
}
}
/**
* @dev Sets the bit at `index`.
*/
function set(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] |= mask;
}
/**
* @dev Unsets the bit at `index`.
*/
function unset(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] &= ~mask;
}
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (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() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
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));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
MerkleProof.sol 227 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.2) (utils/cryptography/MerkleProof.sol)
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle Tree proofs.
*
* The tree and the proofs can be generated using our
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
* You will find a quickstart guide in the readme.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the merkle tree could be reinterpreted as a leaf value.
* OpenZeppelin's JavaScript library generates merkle trees that are safe
* against this attack out of the box.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Calldata version of {verify}
*
* _Available since v4.7._
*/
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*
* _Available since v4.4._
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Calldata version of {processProof}
*
* _Available since v4.7._
*/
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
/**
* @dev Calldata version of {multiProofVerify}
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* _Available since v4.7._
*/
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
require(proofPos == proofLen, "MerkleProof: invalid multiproof");
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Calldata version of {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
require(proofPos == proofLen, "MerkleProof: invalid multiproof");
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Read Contract
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
WHITELIST_ROLE 0x7a997ab7 → bytes32
companyWallet 0x1ec32d15 → address
feelessTokens 0x02c90331 → bool
feesInUSD 0xaa182aef → uint96
getFeeInETH 0x958792a6 → uint256
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
isFreeToken 0x31bff521 → bool
isWethFirst 0xda4c459b → bool
owner 0x8da5cb5b → address
priceEstimator 0xe3f1bc2b → address
supportsInterface 0x01ffc9a7 → bool
uniV2Pair 0x8bcea939 → address
uniV2Router 0x958c2e52 → address
whitelistedWallets 0xa80dcfee → bool
Write Contract 9 functions
These functions modify contract state and require a wallet transaction to execute.
createVesting 0xb09e0bec
address token
bytes32 merkleRoot
uint256 totalAmount
grantRole 0x2f2ff15d
bytes32 role
address account
renounceOwnership 0x715018a6
No parameters
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setFeeParams 0x85b59cc6
address _priceEstimator
address _uniV2Router
address _uniV2Pair
uint96 _feesInUSD
address _companyWallet
setFeelessToken 0x8ec67eca
address tokenAddress
bool feeless
transferOwnership 0xf2fde38b
address newOwner
updateWhitelist 0x0d392cd9
address wallet
bool noFee
Recent Transactions
No transactions found for this address