Address Contract Verified
Address
0x4D4206Dab4533213109DF79D218Ed9b63c50f9Bb
Balance
0 ETH
Nonce
2
Code Size
19632 bytes
Creator
0x027F572e...D3A0 at tx 0xae2e669e...3bbd1d
Indexed Transactions
0
Contract Bytecode
19632 bytes
0x6080604052600436106103a85760003560e01c806302246576146103b45780630483f7a0146103d657806306fdde03146103f65780630873321414610421578063095ea7b3146104415780630a78097d146104715780630bd05b691461049157806312b77e8a146104a657806317c766b3146104bb57806318160ddd146104db5780631870517a146104fa5780631bff78981461051a5780631f53ac021461053057806323b872dd146105505780632866ed211461057057806328d25411146105905780632c1f5216146105b057806330bb4cff146105dd578063313ce567146105f25780633242f2551461060e578063342aa8b51461062e5780633644e5151461064e57806339509351146106635780633a46b1a8146106835780633af32abf146106a357806346469afb146106dc5780634ada218b146106f25780634e71d92d146107135780634ee2cd7e146107285780634fbee19314610748578063587cde1e146107815780635c19a95c146107a157806366d602ae146107c15780636843cd84146107d75780636ddd1713146107f75780636fcfff451461081657806370a082311461084b578063715018a61461086b57806379b447bd146108805780637b510fe8146108a05780637dd2b195146108f25780637ecebe0014610912578063864701a51461093257806388bdd9be1461096c57806388e765ff1461098c5780638ab1d681146109a25780638c9684f9146109c25780638d0841f1146109e25780638da5cb5b146109f85780638e539e8c14610a0d5780638ea5220f14610a2d57806392929a0914610a4d57806395d89b4114610a6d5780639711715a14610a82578063981b24d014610a975780639a7a23d614610ab75780639ab24eb014610ad7578063a457c2d714610af7578063a5150c3d14610b17578063a8aa1b3114610b37578063a8b9d24014610b57578063a9059cbb14610b77578063abb8105214610b97578063afa4f3b214610bc7578063b62496f514610be7578063be825b5214610c17578063c024666814610c37578063c18bc19514610c57578063c3cda52014610c77578063c492f04614610c97578063c851cc3214610cb7578063d2fcc00114610cd7578063d505accf14610cf7578063dd62ed3e14610d17578063e01af92c14610d37578063e11c336814610d57578063e2f4560514610d6c578063e43252d714610d82578063f1127ed814610da2578063f2fde38b14610dec578063f66895a314610e0c578063f887ea4014610e2b578063f8b45b0514610e4b57600080fd5b366103af57005b600080fd5b3480156103c057600080fd5b506103d46103cf3660046144cb565b610e61565b005b3480156103e257600080fd5b506103d46103f13660046144f6565b610f7b565b34801561040257600080fd5b5061040b610fea565b604051610418919061452f565b60405180910390f35b34801561042d57600080fd5b506103d461043c366004614584565b61107c565b34801561044d57600080fd5b5061046161045c3660046145b0565b6110fd565b6040519015158152602001610418565b34801561047d57600080fd5b506103d461048c3660046144cb565b611117565b34801561049d57600080fd5b506103d4611207565b3480156104b257600080fd5b506103d4611278565b3480156104c757600080fd5b506103d46104d6366004614584565b6112f6565b3480156104e757600080fd5b506002545b604051908152602001610418565b34801561050657600080fd5b506103d4610515366004614584565b611389565b34801561052657600080fd5b506104ec60275481565b34801561053c57600080fd5b506103d461054b3660046144cb565b61140a565b34801561055c57600080fd5b5061046161056b3660046145dc565b611434565b34801561057c57600080fd5b50601f546104619062010000900460ff1681565b34801561059c57600080fd5b506103d46105ab3660046144cb565b611458565b3480156105bc57600080fd5b506011546105d0906001600160a01b031681565b604051610418919061461d565b3480156105e957600080fd5b506104ec6115ce565b3480156105fe57600080fd5b5060405160128152602001610418565b34801561061a57600080fd5b506103d4610629366004614584565b611641565b34801561063a57600080fd5b506103d46106493660046144f6565b6116d4565b34801561065a57600080fd5b506104ec611734565b34801561066f57600080fd5b5061046161067e3660046145b0565b61173e565b34801561068f57600080fd5b506104ec61069e3660046145b0565b611760565b3480156106af57600080fd5b506104616106be3660046144cb565b6001600160a01b03166000908152601c602052604090205460ff1690565b3480156106e857600080fd5b506104ec60265481565b3480156106fe57600080fd5b50601f54610461906301000000900460ff1681565b34801561071f57600080fd5b506103d46117aa565b34801561073457600080fd5b506104ec6107433660046145b0565b611869565b34801561075457600080fd5b506104616107633660046144cb565b6001600160a01b031660009081526019602052604090205460ff1690565b34801561078d57600080fd5b506105d061079c3660046144cb565b6118b2565b3480156107ad57600080fd5b506103d46107bc3660046144cb565b6118d0565b3480156107cd57600080fd5b506104ec60165481565b3480156107e357600080fd5b506104ec6107f23660046144cb565b6118da565b34801561080357600080fd5b50601f5461046190610100900460ff1681565b34801561082257600080fd5b506108366108313660046144cb565b61194c565b60405163ffffffff9091168152602001610418565b34801561085757600080fd5b506104ec6108663660046144cb565b61196e565b34801561087757600080fd5b506103d4611989565b34801561088c57600080fd5b506103d461089b366004614631565b61199d565b3480156108ac57600080fd5b506108c06108bb3660046144cb565b611a87565b604080516001600160a01b0390961686526020860194909452928401919091526060830152608082015260a001610418565b3480156108fe57600080fd5b506012546105d0906001600160a01b031681565b34801561091e57600080fd5b506104ec61092d3660046144cb565b611b13565b34801561093e57600080fd5b5060205460215460225461095192919083565b60408051938452602084019290925290820152606001610418565b34801561097857600080fd5b506103d46109873660046144cb565b611b31565b34801561099857600080fd5b506104ec60155481565b3480156109ae57600080fd5b506103d46109bd3660046144cb565b611c83565b3480156109ce57600080fd5b506103d46109dd3660046144cb565b611d6f565b3480156109ee57600080fd5b506104ec601e5481565b348015610a0457600080fd5b506105d0611df5565b348015610a1957600080fd5b506104ec610a28366004614653565b611e04565b348015610a3957600080fd5b506013546105d0906001600160a01b031681565b348015610a5957600080fd5b506103d4610a6836600461466c565b611e30565b348015610a7957600080fd5b5061040b611e54565b348015610a8e57600080fd5b506103d4611e63565b348015610aa357600080fd5b506104ec610ab2366004614653565b611e73565b348015610ac357600080fd5b506103d4610ad23660046144f6565b611e9e565b348015610ae357600080fd5b506104ec610af23660046144cb565b611eb0565b348015610b0357600080fd5b50610461610b123660046145b0565b611f36565b348015610b2357600080fd5b506103d4610b323660046144cb565b611fb1565b348015610b4357600080fd5b506010546105d0906001600160a01b031681565b348015610b6357600080fd5b506104ec610b723660046144cb565b611fdb565b348015610b8357600080fd5b50610461610b923660046145b0565b61200c565b348015610ba357600080fd5b50610461610bb23660046144cb565b60186020526000908152604090205460ff1681565b348015610bd357600080fd5b506103d4610be2366004614653565b61201a565b348015610bf357600080fd5b50610461610c023660046144cb565b601b6020526000908152604090205460ff1681565b348015610c2357600080fd5b506103d4610c323660046144cb565b61204b565b348015610c4357600080fd5b506103d4610c523660046144f6565b612083565b348015610c6357600080fd5b506103d4610c72366004614653565b61211c565b348015610c8357600080fd5b506103d4610c9236600461469a565b61219a565b348015610ca357600080fd5b506103d4610cb23660046146f4565b6122cc565b348015610cc357600080fd5b506103d4610cd23660046144cb565b612386565b348015610ce357600080fd5b506103d4610cf23660046144f6565b6123b0565b348015610d0357600080fd5b506103d4610d12366004614779565b6123e3565b348015610d2357600080fd5b506104ec610d323660046147e7565b612547565b348015610d4357600080fd5b506103d4610d5236600461466c565b612572565b348015610d6357600080fd5b506103d4612594565b348015610d7857600080fd5b506104ec60145481565b348015610d8e57600080fd5b506103d4610d9d3660046144cb565b612605565b348015610dae57600080fd5b50610dc2610dbd366004614815565b61260d565b60408051825163ffffffff1681526020928301516001600160e01b03169281019290925201610418565b348015610df857600080fd5b506103d4610e073660046144cb565b612690565b348015610e1857600080fd5b5060235460245460255461095192919083565b348015610e3757600080fd5b50600f546105d0906001600160a01b031681565b348015610e5757600080fd5b506104ec60175481565b6012546001600160a01b03163314610e945760405162461bcd60e51b8152600401610e8b9061484c565b60405180910390fd5b6001600160a01b0381166000908152601c602052604090205460ff1615610eba57600080fd5b601e546000908152601d60205260409081902080546001600160a01b0319166001600160a01b0384811691909117909155601154915162241fbd60e51b8152911690630483f7a090610f1390849060019060040161489b565b600060405180830381600087803b158015610f2d57600080fd5b505af1158015610f41573d6000803e3d6000fd5b50505050601e546001610f5491906148cc565b601e556001600160a01b03166000908152601c60205260409020805460ff19166001179055565b610f836129a7565b60115460405162241fbd60e51b81526001600160a01b0390911690630483f7a090610fb4908590859060040161489b565b600060405180830381600087803b158015610fce57600080fd5b505af1158015610fe2573d6000803e3d6000fd5b505050505050565b606060038054610ff9906148e4565b80601f0160208091040260200160405190810160405280929190818152602001828054611025906148e4565b80156110725780601f1061104757610100808354040283529160200191611072565b820191906000526020600020905b81548152906001019060200180831161105557829003601f168201915b5050505050905090565b6110846129a7565b60148161109184866148cc565b61109b91906148cc565b11156110b95760405162461bcd60e51b8152600401610e8b90614918565b604080516060810182528481526020810184905201819052602383905560248290556025819055806110eb83856148cc565b6110f591906148cc565b602755505050565b60003361110b818585612a06565b60019150505b92915050565b61111f6129a7565b806001600160a01b031663a9059cbb611136611df5565b6040516370a0823160e01b81526001600160a01b038516906370a082319061116290309060040161461d565b602060405180830381865afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a39190614944565b6040518363ffffffff1660e01b81526004016111c092919061495d565b6020604051808303816000875af11580156111df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112039190614976565b5050565b61120f6129a7565b601f546301000000900460ff16156112635760405162461bcd60e51b8152602060048201526017602482015276151c98591a5b99c8185b1c9958591e48195b98589b1959604a1b6044820152606401610e8b565b601f805463ff00000019166301000000179055565b6112806129a7565b6013546040516000916001600160a01b03169047908381818185875af1925050503d80600081146112cd576040519150601f19603f3d011682016040523d82523d6000602084013e6112d2565b606091505b50509050806112f35760405162461bcd60e51b8152600401610e8b90614993565b50565b6012546001600160a01b031633146113205760405162461bcd60e51b8152600401610e8b9061484c565b60148161132d84866148cc565b61133791906148cc565b11156113555760405162461bcd60e51b8152600401610e8b90614918565b60018161136284866148cc565b61136c91906148cc565b116110b95760405162461bcd60e51b8152600401610e8b906149d5565b6113916129a7565b60148161139e84866148cc565b6113a891906148cc565b11156113c65760405162461bcd60e51b8152600401610e8b90614918565b604080516060810182528481526020808201859052910182905283905560218290556022819055806113f883856148cc565b61140291906148cc565b602655505050565b6114126129a7565b601380546001600160a01b0319166001600160a01b0392909216919091179055565b600033611442858285612b2a565b61144d858585612b9e565b506001949350505050565b6012546001600160a01b031633146114825760405162461bcd60e51b8152600401610e8b9061484c565b6001600160a01b0381166000908152601c602052604090205460ff166114a757600080fd5b6000805b601e548110156114f0576000818152601d60205260409020546001600160a01b038085169116036114de578091506114f0565b806114e881614a09565b9150506114ab565b50805b6001601e546115029190614a22565b81101561156657601d60006115188360016148cc565b81526020808201929092526040908101600090812054848252601d9093522080546001600160a01b0319166001600160a01b039092169190911790558061155e81614a09565b9150506114f3565b50601e805490600061157783614a39565b90915550506001600160a01b0382166000908152601c60205260409020805460ff19169055601e546115ab90600190614a22565b50506001600160a01b03166000908152601c60205260409020805460ff19169055565b601154604080516342d359d760e11b815290516000926001600160a01b0316916385a6b3ae9160048083019260209291908290030181865afa158015611618573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061163c9190614944565b905090565b6012546001600160a01b0316331461166b5760405162461bcd60e51b8152600401610e8b9061484c565b60148161167884866148cc565b61168291906148cc565b11156116a05760405162461bcd60e51b8152600401610e8b90614918565b6001816116ad84866148cc565b6116b791906148cc565b116113c65760405162461bcd60e51b8152600401610e8b906149d5565b6116dc6129a7565b6001600160a01b03821660009081526018602052604090205481151560ff90911615150361170957600080fd5b6001600160a01b03919091166000908152601860205260409020805460ff1916911515919091179055565b600061163c613151565b60003361110b8185856117518383612547565b61175b91906148cc565b612a06565b60004382106117815760405162461bcd60e51b8152600401610e8b90614a50565b6001600160a01b0383166000908152600d602052604090206117a39083613278565b9392505050565b601f5462010000900460ff166117f65760405162461bcd60e51b815260206004820152601160248201527010db185a5b481b9bdd08195b98589b1959607a1b6044820152606401610e8b565b60115460405163807ab4f760e01b81526001600160a01b039091169063807ab4f79061182690339060040161461d565b6020604051808303816000875af1158015611845573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112f39190614976565b6001600160a01b03821660009081526006602052604081208190819061189090859061336e565b91509150816118a7576118a28561196e565b6118a9565b805b95945050505050565b6001600160a01b039081166000908152600c60205260409020541690565b6112f33382613464565b6011546040516370a0823160e01b81526000916001600160a01b0316906370a082319061190b90859060040161461d565b602060405180830381865afa158015611928573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111119190614944565b6001600160a01b0381166000908152600d6020526040812054611111906128ca565b6001600160a01b031660009081526020819052604090205490565b6119916129a7565b61199b60006134e4565b565b6119a56129a7565b6318701a808210156119f95760405162461bcd60e51b815260206004820181905260248201527f43616e6e6f7420736574206d6178627579206c6f776572207468616e203125206044820152606401610e8b565b6301406f40811015611a595760405162461bcd60e51b815260206004820152602360248201527f43616e6e6f7420736574206d617873656c6c206c6f776572207468616e20302e60448201526201a92960ed1b6064820152608401610e8b565b611a6b82670de0b6b3a7640000614a87565b601555611a8081670de0b6b3a7640000614a87565b6016555050565b60115460405163fbcbc0f160e01b815260009182918291829182916001600160a01b03169063fbcbc0f190611ac090899060040161461d565b60a060405180830381865afa158015611add573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b019190614aa6565b939a9299509097509550909350915050565b6001600160a01b0381166000908152600a6020526040812054611111565b611b396129a7565b60405162241fbd60e51b815281906001600160a01b03821690630483f7a090611b6990849060019060040161489b565b600060405180830381600087803b158015611b8357600080fd5b505af1158015611b97573d6000803e3d6000fd5b505060405162241fbd60e51b81526001600160a01b0384169250630483f7a09150611bc990309060019060040161489b565b600060405180830381600087803b158015611be357600080fd5b505af1158015611bf7573d6000803e3d6000fd5b5050600f5460405162241fbd60e51b81526001600160a01b038086169450630483f7a09350611c2d92169060019060040161489b565b600060405180830381600087803b158015611c4757600080fd5b505af1158015611c5b573d6000803e3d6000fd5b5050601180546001600160a01b0319166001600160a01b039490941693909317909255505050565b611c8b6129a7565b6001600160a01b0381166000908152601c602052604090205460ff16611cb057600080fd5b6000805b601e54811015611cf9576000818152601d60205260409020546001600160a01b03808516911603611ce757809150611cf9565b80611cf181614a09565b915050611cb4565b50805b6001601e54611d0b9190614a22565b81101561156657601d6000611d218360016148cc565b81526020808201929092526040908101600090812054848252601d9093522080546001600160a01b0319166001600160a01b0390921691909117905580611d6781614a09565b915050611cfc565b611d776129a7565b6011546001600160a01b031663497ec823611d90611df5565b6040516001600160e01b031960e084901b1681526001600160a01b03918216600482015290841660248201526044015b600060405180830381600087803b158015611dda57600080fd5b505af1158015611dee573d6000803e3d6000fd5b5050505050565b6005546001600160a01b031690565b6000438210611e255760405162461bcd60e51b8152600401610e8b90614a50565b611111600e83613278565b611e386129a7565b601f8054911515620100000262ff000019909216919091179055565b606060048054610ff9906148e4565b611e6b6129a7565b6112f3613536565b6000806000611e8384600761336e565b9150915081611e9457600254611e96565b805b949350505050565b611ea66129a7565b6112038282613590565b6001600160a01b0381166000908152600d60205260408120548015611f23576001600160a01b0383166000908152600d60205260409020611ef2600183614a22565b81548110611f0257611f02614aef565b600091825260209091200154600160201b90046001600160e01b0316611f26565b60005b6001600160e01b03169392505050565b60003381611f448286612547565b905083811015611fa45760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610e8b565b61144d8286868403612a06565b611fb96129a7565b601280546001600160a01b0319166001600160a01b0392909216919091179055565b6011546040516302a2e74960e61b81526000916001600160a01b03169063a8b9d2409061190b90859060040161461d565b60003361110b818585612b9e565b6120226129a7565b6402540be400811061203357600080fd5b61204581670de0b6b3a7640000614a87565b60145550565b6120536129a7565b60115460405163225b5ecf60e11b81526001600160a01b03909116906344b6bd9e90611dc090849060040161461d565b61208b6129a7565b6001600160a01b03821660009081526019602052604090205481151560ff9091161515036120b857600080fd5b6001600160a01b03821660008181526019602052604090819020805460ff1916841515179055517f9d8f7706ea1113d1a167b526eca956215946dd36cc7df39eb16180222d8b5df79061211090841515815260200190565b60405180910390a25050565b6121246129a7565b6318701a8081116121825760405162461bcd60e51b815260206004820152602260248201527f43616e6e6f7420736574206d617857616c6c6574206c6f776572207468616e20604482015261312560f01b6064820152608401610e8b565b61219481670de0b6b3a7640000614a87565b60175550565b834211156121ea5760405162461bcd60e51b815260206004820152601d60248201527f4552433230566f7465733a207369676e617475726520657870697265640000006044820152606401610e8b565b604080517fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf60208201526001600160a01b0388169181019190915260608101869052608081018590526000906122649061225c9060a0016040516020818303038152906040528051906020012061368b565b8585856136d9565b905061226f81613701565b86146122b95760405162461bcd60e51b81526020600482015260196024820152784552433230566f7465733a20696e76616c6964206e6f6e636560381b6044820152606401610e8b565b6122c38188613464565b50505050505050565b6122d46129a7565b60005b828110156123455781601960008686858181106122f6576122f6614aef565b905060200201602081019061230b91906144cb565b6001600160a01b031681526020810191909152604001600020805460ff19169115159190911790558061233d81614a09565b9150506122d7565b507f7fdaf542373fa84f4ee8d662c642f44e4c2276a217d7d29e548b6eb29a233b3583838360405161237993929190614b05565b60405180910390a1505050565b61238e6129a7565b600f80546001600160a01b0319166001600160a01b0392909216919091179055565b6123b86129a7565b6001600160a01b03919091166000908152601a60205260409020805460ff1916911515919091179055565b834211156124335760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610e8b565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886124628c613701565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e00160405160208183030381529060405280519060200120905060006124bd8261368b565b905060006124cd828787876136d9565b9050896001600160a01b0316816001600160a01b0316146125305760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610e8b565b61253b8a8a8a612a06565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b61257a6129a7565b601f80549115156101000261ff0019909216919091179055565b61259c6129a7565b6011546001600160a01b0316633b36a1d76125b5611df5565b6040518263ffffffff1660e01b81526004016125d1919061461d565b600060405180830381600087803b1580156125eb57600080fd5b505af11580156125ff573d6000803e3d6000fd5b50505050565b610e946129a7565b60408051808201909152600080825260208201526001600160a01b0383166000908152600d60205260409020805463ffffffff841690811061265157612651614aef565b60009182526020918290206040805180820190915291015463ffffffff81168252600160201b90046001600160e01b0316918101919091529392505050565b6126986129a7565b6001600160a01b0381166126fd5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610e8b565b6112f3816134e4565b6127108282612790565b6002546001600160e01b0310156127825760405162461bcd60e51b815260206004820152603060248201527f4552433230566f7465733a20746f74616c20737570706c79207269736b73206f60448201526f766572666c6f77696e6720766f74657360801b6064820152608401610e8b565b6125ff600e61285183613729565b6001600160a01b0382166127e65760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610e8b565b6127f26000838361387a565b806002600082825461280491906148cc565b90915550506001600160a01b03821660008181526020818152604080832080548601905551848152600080516020614c3b833981519152910160405180910390a361120360008383613885565b60006117a382846148cc565b60006001600160e01b038211156128c65760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663234206269747360c81b6064820152608401610e8b565b5090565b600063ffffffff8211156128c65760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b6064820152608401610e8b565b6001600160a01b0383166129535761294682613890565b61294e6138ba565b505050565b6001600160a01b03821661296a5761294683613890565b61297383613890565b61294e82613890565b61294e612988846118b2565b612991846118b2565b836138c8565b60006117a38284614a22565b5490565b336129b0611df5565b6001600160a01b03161461199b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610e8b565b6001600160a01b038316612a685760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610e8b565b6001600160a01b038216612ac95760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610e8b565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000612b368484612547565b905060001981146125ff5781811015612b915760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610e8b565b6125ff8484848403612a06565b6001600160a01b038316612bb157600080fd5b6001600160a01b038216612bc457600080fd5b6001600160a01b03831660009081526019602052604090205460ff16158015612c0657506001600160a01b03821660009081526019602052604090205460ff16155b8015612c155750601f5460ff16155b15612e4e57601f546301000000900460ff16612c685760405162461bcd60e51b815260206004820152601260248201527154726164696e67206e6f742061637469766560701b6044820152606401610e8b565b6001600160a01b03831660009081526018602052604090205460ff16158015612caa57506001600160a01b03821660009081526018602052604090205460ff16155b612ce15760405162461bcd60e51b8152602060048201526008602482015267109e594808109bdd60c21b6044820152606401610e8b565b6001600160a01b0382166000908152601b602052604090205460ff1615612d5957601654811115612d545760405162461bcd60e51b815260206004820152601f60248201527f596f752061726520657863656564696e67206d617853656c6c416d6f756e74006044820152606401610e8b565b612dcc565b6001600160a01b0383166000908152601b602052604090205460ff1615612dcc57601554811115612dcc5760405162461bcd60e51b815260206004820152601e60248201527f596f752061726520657863656564696e67206d6178427579416d6f756e7400006044820152606401610e8b565b6001600160a01b0382166000908152601a602052604090205460ff16612e4e57601754612df88361196e565b612e0290836148cc565b1115612e4e5760405162461bcd60e51b815260206004820152601b60248201527a155b98589b19481d1bc8195e18d959590813585e0815d85b1b195d602a1b6044820152606401610e8b565b80600003612e625761294e838360006139e1565b6000612e6d3061196e565b60145490915081108015908190612e875750601f5460ff16155b8015612e9a5750601f54610100900460ff165b8015612ebe57506001600160a01b0384166000908152601b602052604090205460ff165b8015612ee357506001600160a01b03851660009081526019602052604090205460ff16155b8015612f0857506001600160a01b03841660009081526019602052604090205460ff16155b15612f3857601f805460ff1916600117905560275415612f2d57612f2d601454613b84565b601f805460ff191690555b601f546001600160a01b03861660009081526019602052604090205460ff91821615911680612f7f57506001600160a01b03851660009081526019602052604090205460ff165b15612f88575060005b6001600160a01b0385166000908152601b602052604090205460ff16158015612fca57506001600160a01b0386166000908152601b602052604090205460ff16155b15612fd3575060005b8015613072576001600160a01b0385166000908152601b602052604081205460ff161561301b5760646027548661300a9190614a87565b6130149190614b74565b9050613059565b6001600160a01b0387166000908152601b602052604090205460ff16156130595760646026548661304c9190614a87565b6130569190614b74565b90505b6130638186614a22565b94506130708730836139e1565b505b61307d8686866139e1565b6011546001600160a01b031663e30443bc876130988161196e565b6040518363ffffffff1660e01b81526004016130b592919061495d565b600060405180830381600087803b1580156130cf57600080fd5b505af19250505080156130e0575060015b506011546001600160a01b031663e30443bc866130fc8161196e565b6040518363ffffffff1660e01b815260040161311992919061495d565b600060405180830381600087803b15801561313357600080fd5b505af1925050508015613144575060015b15610fe257505050505050565b6000306001600160a01b037f0000000000000000000000004d4206dab4533213109df79d218ed9b63c50f9bb161480156131aa57507f000000000000000000000000000000000000000000000000000000000000000146145b156131d457507f24b00462485e15335527e591d719723cf0d4090d84229910ba5c7905c292f88090565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527f85b27011341d3b3361972c2c88605ebd48f0e5c6b119bc2ac97e39d84ff34b04828401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b8154600090818160058111156132d257600061329384613ea8565b61329d9085614a22565b600088815260209020909150869082015463ffffffff1611156132c2578091506132d0565b6132cd8160016148cc565b92505b505b8082101561331f5760006132e68383613f90565b600088815260209020909150869082015463ffffffff16111561330b57809150613319565b6133168160016148cc565b92505b506132d2565b80156133585761334286613334600184614a22565b600091825260209091200190565b54600160201b90046001600160e01b031661335b565b60005b6001600160e01b03169695505050505050565b600080600084116133ba5760405162461bcd60e51b815260206004820152601660248201527504552433230536e617073686f743a20696420697320360541b6044820152606401610e8b565b6133c2613fab565b8411156134115760405162461bcd60e51b815260206004820152601d60248201527f4552433230536e617073686f743a206e6f6e6578697374656e742069640000006044820152606401610e8b565b600061341d8486613fb6565b8454909150810361343557600080925092505061345d565b600184600101828154811061344c5761344c614aef565b906000526020600020015492509250505b9250929050565b600061346f836118b2565b9050600061347c8461196e565b6001600160a01b038581166000818152600c602052604080822080546001600160a01b031916898616908117909155905194955093928616927f3134e8a2e6d97e929a7e54011ea5485d7d196dd5f0ba4d4ef95803e8e3fc257f9190a46125ff8284836138c8565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000613546600980546001019055565b6000613550613fab565b90507f8030e83b04d87bef53480e26263266d6ca66863aa8506aca6f2559d18aa1cb678160405161358391815260200190565b60405180910390a1919050565b6001600160a01b0382166000908152601b602052604090205481151560ff9091161515036135bd57600080fd5b6001600160a01b0382166000908152601b60205260409020805460ff1916821580159190911790915561364f5760115460405162241fbd60e51b81526001600160a01b0390911690630483f7a09061361c90859060019060040161489b565b600060405180830381600087803b15801561363657600080fd5b505af115801561364a573d6000803e3d6000fd5b505050505b604051811515906001600160a01b038416907fffa9187bf1f18bf477bd0ea1bcbb64e93b6a98132473929edfce215cd9b16fab90600090a35050565b6000611111613698613151565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b60008060006136ea87878787614055565b915091506136f78161410f565b5095945050505050565b6001600160a01b0381166000908152600a602052604090208054600181018255905b50919050565b825460009081908181156137755761374687613334600185614a22565b60408051808201909152905463ffffffff81168252600160201b90046001600160e01b0316602082015261378a565b60408051808201909152600080825260208201525b905080602001516001600160e01b031693506137aa84868863ffffffff16565b92506000821180156137c25750805163ffffffff1643145b15613806576137d08361285d565b6137df88613334600186614a22565b80546001600160e01b0392909216600160201b0263ffffffff909216919091179055613870565b86604051806040016040528061381b436128ca565b63ffffffff16815260200161382f8661285d565b6001600160e01b039081169091528254600181018455600093845260209384902083519490930151909116600160201b0263ffffffff909316929092179101555b5050935093915050565b61294e83838361292f565b61294e83838361297c565b6001600160a01b03811660009081526006602052604090206112f3906138b58361196e565b614254565b61199b60076138b560025490565b816001600160a01b0316836001600160a01b0316141580156138ea5750600081115b1561294e576001600160a01b03831615613966576001600160a01b0383166000908152600d6020526040812081906139259061299785613729565b91509150846001600160a01b0316600080516020614c5b833981519152838360405161395b929190918252602082015260400190565b60405180910390a250505b6001600160a01b0382161561294e576001600160a01b0382166000908152600d60205260408120819061399c9061285185613729565b91509150836001600160a01b0316600080516020614c5b83398151915283836040516139d2929190918252602082015260400190565b60405180910390a25050505050565b6001600160a01b038316613a455760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610e8b565b6001600160a01b038216613aa75760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610e8b565b613ab283838361387a565b6001600160a01b03831660009081526020819052604090205481811015613b2a5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610e8b565b6001600160a01b0384811660008181526020818152604080832087870390559387168083529184902080548701905592518581529092600080516020614c3b833981519152910160405180910390a36125ff848484613885565b6027546023548291906000908290613b9c9085614a87565b613ba69190614b74565b9050308115613cca5760115460405163a9059cbb60e01b81526000916001600160a01b038085169263a9059cbb92613be4921690879060040161495d565b6020604051808303816000875af1158015613c03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c279190614976565b90508015613cc857601154604051633243c79160e01b8152600481018590526001600160a01b0390911690633243c79190602401600060405180830381600087803b158015613c7557600080fd5b505af1158015613c89573d6000803e3d6000fd5b505060408051898152602081018790527f80195cc573b02cc48460cbca6e6e4cc85ddb91959d946e1c3025ea3d87942dc3935001905060405180910390a15b505b6024546000908490613cdc9087614a87565b613ce69190614b74565b90508015613e00576000601e5482613cfe9190614b74565b905060005b601e54811015613dfd576000818152601d60205260409020546001600160a01b031615613deb576000818152601d602052604080822054905163a9059cbb60e01b81526001600160a01b038781169263a9059cbb92613d6a9290911690879060040161495d565b6020604051808303816000875af1158015613d89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dad9190614976565b90508015613de9576040518481527f878a3edf7c1bc3706e552d7eba843443268d6782930f0bfa6ad8d69a9c6d7a9f9060200160405180910390a15b505b80613df581614a09565b915050613d03565b50505b613e0a8186614a22565b9450613e168386614a22565b9450613e218561429e565b47808015613e9e576013546040516000916001600160a01b03169083908381818185875af1925050503d8060008114613e76576040519150601f19603f3d011682016040523d82523d6000602084013e613e7b565b606091505b5050905080613e9c5760405162461bcd60e51b8152600401610e8b90614993565b505b5050505050505050565b600081600003613eba57506000919050565b60006001613ec7846143c2565b901c6001901b90506001818481613ee057613ee0614b5e565b048201901c90506001818481613ef857613ef8614b5e565b048201901c90506001818481613f1057613f10614b5e565b048201901c90506001818481613f2857613f28614b5e565b048201901c90506001818481613f4057613f40614b5e565b048201901c90506001818481613f5857613f58614b5e565b048201901c90506001818481613f7057613f70614b5e565b048201901c90506117a381828581613f8a57613f8a614b5e565b04614456565b6000613f9f6002848418614b74565b6117a3908484166148cc565b600061163c60095490565b81546000908103613fc957506000611111565b82546000905b80821015614016576000613fe38383613f90565b6000878152602090209091508590820154111561400257809150614010565b61400d8160016148cc565b92505b50613fcf565b60008211801561403457508361403186613334600186614a22565b54145b1561404d57614044600183614a22565b92505050611111565b509050611111565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b038311156140825750600090506003614106565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156140d6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166140ff57600060019250925050614106565b9150600090505b94509492505050565b600081600481111561412357614123614b96565b0361412b5750565b600181600481111561413f5761413f614b96565b036141875760405162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b6044820152606401610e8b565b600281600481111561419b5761419b614b96565b036141e85760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610e8b565b60038160048111156141fc576141fc614b96565b036112f35760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610e8b565b600061425e613fab565b90508061426a8461446c565b101561294e578254600180820185556000858152602080822090930193909355938401805494850181558252902090910155565b60408051600280825260608201835260009260208301908036833701905050905030816000815181106142d3576142d3614aef565b6001600160a01b03928316602091820292909201810191909152600f54604080516315ab88c960e31b81529051919093169263ad5c46489260048083019391928290030181865afa15801561432c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143509190614bac565b8160018151811061436357614363614aef565b6001600160a01b039283166020918202929092010152600f546143899130911684612a06565b600f5460405163791ac94760e01b81526001600160a01b039091169063791ac94790610fb4908590600090869030904290600401614bc9565b600080608083901c156143d757608092831c92015b604083901c156143e957604092831c92015b602083901c156143fb57602092831c92015b601083901c1561440d57601092831c92015b600883901c1561441f57600892831c92015b600483901c1561443157600492831c92015b600283901c1561444357600292831c92015b600183901c156111115760010192915050565b600081831061446557816117a3565b5090919050565b8054600090810361447f57506000919050565b8154829061448f90600190614a22565b8154811061449f5761449f614aef565b90600052602060002001549050919050565b919050565b6001600160a01b03811681146112f357600080fd5b6000602082840312156144dd57600080fd5b81356117a3816144b6565b80151581146112f357600080fd5b6000806040838503121561450957600080fd5b8235614514816144b6565b91506020830135614524816144e8565b809150509250929050565b600060208083528351808285015260005b8181101561455c57858101830151858201604001528201614540565b8181111561456e576000604083870101525b50601f01601f1916929092016040019392505050565b60008060006060848603121561459957600080fd5b505081359360208301359350604090920135919050565b600080604083850312156145c357600080fd5b82356145ce816144b6565b946020939093013593505050565b6000806000606084860312156145f157600080fd5b83356145fc816144b6565b9250602084013561460c816144b6565b929592945050506040919091013590565b6001600160a01b0391909116815260200190565b6000806040838503121561464457600080fd5b50508035926020909101359150565b60006020828403121561466557600080fd5b5035919050565b60006020828403121561467e57600080fd5b81356117a3816144e8565b803560ff811681146144b157600080fd5b60008060008060008060c087890312156146b357600080fd5b86356146be816144b6565b955060208701359450604087013593506146da60608801614689565b92506080870135915060a087013590509295509295509295565b60008060006040848603121561470957600080fd5b83356001600160401b038082111561472057600080fd5b818601915086601f83011261473457600080fd5b81358181111561474357600080fd5b8760208260051b850101111561475857600080fd5b6020928301955093505084013561476e816144e8565b809150509250925092565b600080600080600080600060e0888a03121561479457600080fd5b873561479f816144b6565b965060208801356147af816144b6565b955060408801359450606088013593506147cb60808901614689565b925060a0880135915060c0880135905092959891949750929550565b600080604083850312156147fa57600080fd5b8235614805816144b6565b91506020830135614524816144b6565b6000806040838503121561482857600080fd5b8235614833816144b6565b9150602083013563ffffffff8116811461452457600080fd5b6020808252602f908201527f4d6573736167652073656e646572206d7573742062652074686520636f6e747260408201526e30b1ba13b99023b7bb32b93737b91760891b606082015260800190565b6001600160a01b039290921682521515602082015260400190565b634e487b7160e01b600052601160045260246000fd5b600082198211156148df576148df6148b6565b500190565b600181811c908216806148f857607f821691505b60208210810361372357634e487b7160e01b600052602260045260246000fd5b602080825260129082015271466565206d757374206265203c3d2032302560701b604082015260600190565b60006020828403121561495657600080fd5b5051919050565b6001600160a01b03929092168252602082015260400190565b60006020828403121561498857600080fd5b81516117a3816144e8565b60208082526022908201527f4661696c656420746f2073656e6420457468657220746f206465762077616c6c604082015261195d60f21b606082015260800190565b6020808252601a9082015279466565206d75737420626520686967686572207468656e20312560301b604082015260600190565b600060018201614a1b57614a1b6148b6565b5060010190565b600082821015614a3457614a346148b6565b500390565b600081614a4857614a486148b6565b506000190190565b6020808252601f908201527f4552433230566f7465733a20626c6f636b206e6f7420796574206d696e656400604082015260600190565b6000816000190483118215151615614aa157614aa16148b6565b500290565b600080600080600060a08688031215614abe57600080fd5b8551614ac9816144b6565b602087015160408801516060890151608090990151929a91995097965090945092505050565b634e487b7160e01b600052603260045260246000fd5b6040808252810183905260008460608301825b86811015614b48578235614b2b816144b6565b6001600160a01b0316825260209283019290910190600101614b18565b5080925050508215156020830152949350505050565b634e487b7160e01b600052601260045260246000fd5b600082614b9157634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052602160045260246000fd5b600060208284031215614bbe57600080fd5b81516117a3816144b6565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b81811015614c195784516001600160a01b031683529383019391830191600101614bf4565b50506001600160a01b0396909616606085015250505060800152939250505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efdec2bacdd2f05b59de34da9b523dff8be42e5e38e818c82fdb0bae774387a724a2646970667358221220153f114423e1f133f808aaaf023c7239d98cd334411c13058b0cdfaf984f096264736f6c634300080f0033
Verified Source Code Full Match
Compiler: v0.8.15+commit.e14f2714
EVM: london
Optimization: Yes (1 runs)
IDEX.sol 49 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IPair {
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function token0() external view returns (address);
}
interface IFactory{
function createPair(address tokenA, address tokenB) external returns (address pair);
function getPair(address tokenA, address tokenB) external view returns (address pair);
}
interface IRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline) external;
}
Marsereum.sol 726 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.15;
//t.me/Marsereum (https://t.me/Marsereum)
//marsereum.org
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
import "./IDEX.sol";
import "./MarsereumDividendToken.sol";
contract Marsereum is ERC20, Ownable, ERC20Snapshot, ERC20Votes {
IRouter public router;
address public pair;
DividendTracker public dividendTracker;
address public GovernorAddress;
address public devWallet = 0xd0EBE29797119090A2c4942aE7900A9A1369006B;
uint256 public swapTokensAtAmount;
uint256 public maxBuyAmount;
uint256 public maxSellAmount;
uint256 public maxWallet;
mapping(address => bool) public _isBot;
mapping(address => bool) private _isExcludedFromFees;
mapping(address => bool) private _isExcludedFromMaxWallet;
mapping(address => bool) public automatedMarketMakerPairs;
mapping(address => bool) private whitelist;
mapping(uint256 => address) private WhitelistedAddresses;
uint256 public NumWhitelisted;
bool private swapping;
bool public swapEnabled = true;
bool public claimEnabled;
bool public tradingEnabled;
event ExcludeFromFees(address indexed account, bool isExcluded);
event ExcludeMultipleAccountsFromFees(address[] accounts, bool isExcluded);
event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value);
event GasForProcessingUpdated(
uint256 indexed newValue,
uint256 indexed oldValue
);
event MarsFundsDistributed(uint256 Funds_sent);
event SendDividends(uint256 tokensSwapped, uint256 amount);
event ProcessedDividendTracker(
uint256 iterations,
uint256 claims,
uint256 lastProcessedIndex,
bool indexed automatic,
uint256 gas,
address indexed processor
);
struct Taxes {
uint256 rewards; // dividends
uint256 treasury; // mars wallets
uint256 dev; //
}
Taxes public buyTaxes = Taxes(2, 2, 1);
Taxes public sellTaxes = Taxes(2, 2, 1);
uint256 public totalBuyTax = 5;
uint256 public totalSellTax = 5;
constructor(address _dev)
ERC20("Marsereum", "MTH")
ERC20Permit("Marsereum")
{
dividendTracker = new DividendTracker();
setSwapTokensAtAmount(200000000);
updateMaxWalletAmount(840000000); /// 3%
setMaxBuyAndSell(840000000, 840000000); /// 2% - 3%
setDevWallet(_dev);
IRouter _router = IRouter(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
address _pair = IFactory(_router.factory()).createPair(
address(this),
_router.WETH()
);
router = _router;
pair = _pair;
dividendTracker.updateLP_Token(address(this));
excludeFromFees(owner(), true);
excludeFromFees(address(this), true);
excludeFromMaxWallet(_pair, true);
excludeFromMaxWallet(address(dividendTracker), true);
excludeFromMaxWallet(devWallet, true);
excludeFromMaxWallet(owner(), true);
excludeFromMaxWallet(address(this), true);
excludeFromMaxWallet(address(_router), true);
_setAutomatedMarketMakerPair(_pair, true);
dividendTracker.excludeFromDividends(address(dividendTracker), true);
dividendTracker.excludeFromDividends(address(this), true);
dividendTracker.excludeFromDividends(owner(), true);
dividendTracker.excludeFromDividends(address(0xdead), true);
dividendTracker.excludeFromDividends(address(_router), true);
/*
_mint is an internal function that is only called here,
and cannot be called ever again
*/
_mint(owner(), 42000000000 * (10**18));
}
receive() external payable {}
modifier onlyGovernor() {
require(
msg.sender == GovernorAddress,
"Message sender must be the contract's Governor."
);
_;
}
///Functions For RewardCycle information
function UpdateGovernorAddress(address _newgov) public onlyOwner {
GovernorAddress = _newgov;
}
function addToWhitelist(address _address) external onlyOwner {
require(!whitelist[_address]);
WhitelistedAddresses[NumWhitelisted] = _address;
dividendTracker.excludeFromDividends(_address, true);
NumWhitelisted = NumWhitelisted + 1;
whitelist[_address] = true;
}
function addToWhitelistGovernor(address _address) external onlyGovernor {
require(!whitelist[_address]);
WhitelistedAddresses[NumWhitelisted] = _address;
dividendTracker.excludeFromDividends(_address, true);
NumWhitelisted = NumWhitelisted + 1;
whitelist[_address] = true;
}
function removeFromWhitelist(address _address) external onlyOwner {
require(whitelist[_address]);
// Find the index of the address to remove
uint256 indexToRemove;
for (uint256 i = 0; i < NumWhitelisted; i++) {
if (WhitelistedAddresses[i] == _address) {
indexToRemove = i;
break;
}
}
// Shift the remaining elements to the left
for (uint256 j = indexToRemove; j < NumWhitelisted - 1; j++) {
WhitelistedAddresses[j] = WhitelistedAddresses[j + 1];
}
// Decrement the number of whitelisted addresses and update the mapping
NumWhitelisted--;
whitelist[_address] = false;
NumWhitelisted - 1;
whitelist[_address] = false;
}
function removeFromWhitelistGovernor(address _address)
external
onlyGovernor
{
require(whitelist[_address]);
// Find the index of the address to remove
uint256 indexToRemove;
for (uint256 i = 0; i < NumWhitelisted; i++) {
if (WhitelistedAddresses[i] == _address) {
indexToRemove = i;
break;
}
}
// Shift the remaining elements to the left
for (uint256 j = indexToRemove; j < NumWhitelisted - 1; j++) {
WhitelistedAddresses[j] = WhitelistedAddresses[j + 1];
}
// Decrement the number of whitelisted addresses and update the mapping
NumWhitelisted--;
whitelist[_address] = false;
NumWhitelisted - 1;
whitelist[_address] = false;
}
function isWhitelisted(address _address) public view returns (bool) {
return whitelist[_address];
}
function snapshot() public onlyOwner {
_snapshot();
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20, ERC20Snapshot) {
super._beforeTokenTransfer(from, to, amount);
}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20, ERC20Votes) {
super._afterTokenTransfer(from, to, amount);
}
function _mint(address to, uint256 amount)
internal
override(ERC20, ERC20Votes)
{
super._mint(to, amount);
}
function _burn(address account, uint256 amount)
internal
override(ERC20, ERC20Votes)
{
super._burn(account, amount);
}
function updateDividendTracker(address newAddress) public onlyOwner {
DividendTracker newDividendTracker = DividendTracker(
payable(newAddress)
);
newDividendTracker.excludeFromDividends(
address(newDividendTracker),
true
);
newDividendTracker.excludeFromDividends(address(this), true);
newDividendTracker.excludeFromDividends(address(router), true);
dividendTracker = newDividendTracker;
}
function excludeFromFees(address account, bool excluded) public onlyOwner {
require(_isExcludedFromFees[account] != excluded);
_isExcludedFromFees[account] = excluded;
emit ExcludeFromFees(account, excluded);
}
function excludeFromMaxWallet(address account, bool excluded)
public
onlyOwner
{
_isExcludedFromMaxWallet[account] = excluded;
}
function excludeMultipleAccountsFromFees(
address[] calldata accounts,
bool excluded
) public onlyOwner {
for (uint256 i = 0; i < accounts.length; i++) {
_isExcludedFromFees[accounts[i]] = excluded;
}
emit ExcludeMultipleAccountsFromFees(accounts, excluded);
}
/// @dev "true" to exclude, "false" to include
function excludeFromDividends(address account, bool value)
external
onlyOwner
{
dividendTracker.excludeFromDividends(account, value);
}
function setDevWallet(address newWallet) public onlyOwner {
devWallet = newWallet;
}
function updateMaxWalletAmount(uint256 newNum) public onlyOwner {
require(newNum > (410000000 * 1), "Cannot set maxWallet lower than 1%");
maxWallet = newNum * (10**18);
}
function setMaxBuyAndSell(uint256 maxBuy, uint256 maxSell)
public
onlyOwner
{
require(maxBuy >= 410000000, "Cannot set maxbuy lower than 1% ");
require(maxSell >= 21000000, "Cannot set maxsell lower than 0.5% ");
maxBuyAmount = maxBuy * 10**18;
maxSellAmount = maxSell * 10**18;
}
function setDiv_Token(address _token) external onlyOwner {
dividendTracker.updateLP_Token(_token);
}
/// @notice Update the threshold to swap tokens for liquidity,
/// treasury and dividends.
function setSwapTokensAtAmount(uint256 amount) public onlyOwner {
require(amount < 10000000000);
swapTokensAtAmount = amount * 10**18;
}
function setBuyTaxes(
uint256 _rewards,
uint256 _treasury,
uint256 _dev
) external onlyOwner {
require(_rewards + _treasury + _dev <= 20, "Fee must be <= 20%");
buyTaxes = Taxes(_rewards, _treasury, _dev);
totalBuyTax = _rewards + _treasury + _dev;
}
function setSellTaxes(
uint256 _rewards,
uint256 _treasury,
uint256 _dev
) external onlyOwner {
require(_rewards + _treasury + _dev <= 20, "Fee must be <= 20%");
sellTaxes = Taxes(_rewards, _treasury, _dev);
totalSellTax = _rewards + _treasury + _dev;
}
function setBuyTaxesGovernor(
uint256 _rewards,
uint256 _treasury,
uint256 _dev
) external onlyGovernor {
require(_rewards + _treasury + _dev <= 20, "Fee must be <= 20%");
require(_rewards + _treasury + _dev > 1, "Fee must be higher then 1%");
buyTaxes = Taxes(_rewards, _treasury, _dev);
totalBuyTax = _rewards + _treasury + _dev;
}
function setSellTaxesGovernor(
uint256 _rewards,
uint256 _treasury,
uint256 _dev
) external onlyGovernor {
require(_rewards + _treasury + _dev <= 20, "Fee must be <= 20%");
require(_rewards + _treasury + _dev > 1, "Fee must be higher then 1%");
sellTaxes = Taxes(_rewards, _treasury, _dev);
totalSellTax = _rewards + _treasury + _dev;
}
/// @notice Enable or disable internal swaps
/// @dev Set "true" to enable internal swaps for liquidity, treasury and dividends
function setSwapEnabled(bool _enabled) external onlyOwner {
swapEnabled = _enabled;
}
/// @notice Manual claim the dividends
function claim() external {
require(claimEnabled, "Claim not enabled");
dividendTracker.processAccount(payable(msg.sender));
}
/// @notice Withdraw tokens sent by mistake.
/// @param tokenAddress The address of the token to withdraw
function rescueETH20Tokens(address tokenAddress) external onlyOwner {
IERC20(tokenAddress).transfer(
owner(),
IERC20(tokenAddress).balanceOf(address(this))
);
}
/// @notice Send remaining ETH to treasuryWallet
/// @dev It will send all ETH to treasuryWallet
function forceSend() external onlyOwner {
(bool success, ) = payable(devWallet).call{
value: address(this).balance
}("");
require(success, "Failed to send Ether to dev wallet");
}
function trackerRescueETH20Tokens(address tokenAddress) external onlyOwner {
dividendTracker.trackerRescueETH20Tokens(owner(), tokenAddress);
}
function trackerForceSend() external onlyOwner {
dividendTracker.trackerForceSend(owner());
}
function updateRouter(address newRouter) external onlyOwner {
router = IRouter(newRouter);
}
function activateTrading() external onlyOwner {
require(!tradingEnabled, "Trading already enabled");
tradingEnabled = true;
}
function setClaimEnabled(bool state) external onlyOwner {
claimEnabled = state;
}
/// @param bot The bot address
/// @param value "true" to blacklist, "false" to unblacklist
function setBot(address bot, bool value) external onlyOwner {
require(_isBot[bot] != value);
_isBot[bot] = value;
}
/// @dev Set new pairs created due to listing in new DEX
function setAutomatedMarketMakerPair(address newPair, bool value)
external
onlyOwner
{
_setAutomatedMarketMakerPair(newPair, value);
}
function _setAutomatedMarketMakerPair(address newPair, bool value) private {
require(automatedMarketMakerPairs[newPair] != value);
automatedMarketMakerPairs[newPair] = value;
if (value) {
dividendTracker.excludeFromDividends(newPair, true);
}
emit SetAutomatedMarketMakerPair(newPair, value);
}
function getTotalDividendsDistributed() external view returns (uint256) {
return dividendTracker.totalDividendsDistributed();
}
function isExcludedFromFees(address account) public view returns (bool) {
return _isExcludedFromFees[account];
}
function withdrawableDividendOf(address account)
public
view
returns (uint256)
{
return dividendTracker.withdrawableDividendOf(account);
}
function dividendTokenBalanceOf(address account)
public
view
returns (uint256)
{
return dividendTracker.balanceOf(account);
}
function getAccountInfo(address account)
external
view
returns (
address,
uint256,
uint256,
uint256,
uint256
)
{
return dividendTracker.getAccount(account);
}
function _transfer(
address from,
address to,
uint256 amount
) internal override {
require(from != address(0));
require(to != address(0));
if (
!_isExcludedFromFees[from] && !_isExcludedFromFees[to] && !swapping
) {
require(tradingEnabled, "Trading not active");
require(!_isBot[from] && !_isBot[to], "Bye Bot");
if (automatedMarketMakerPairs[to]) {
require(
amount <= maxSellAmount,
"You are exceeding maxSellAmount"
);
} else if (automatedMarketMakerPairs[from])
require(
amount <= maxBuyAmount,
"You are exceeding maxBuyAmount"
);
if (!_isExcludedFromMaxWallet[to]) {
require(
amount + balanceOf(to) <= maxWallet,
"Unable to exceed Max Wallet"
);
}
}
if (amount == 0) {
super._transfer(from, to, 0);
return;
}
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= swapTokensAtAmount;
if (
canSwap &&
!swapping &&
swapEnabled &&
automatedMarketMakerPairs[to] &&
!_isExcludedFromFees[from] &&
!_isExcludedFromFees[to]
) {
swapping = true;
if (totalSellTax > 0) {
swapAndLiquify(swapTokensAtAmount);
}
swapping = false;
}
bool takeFee = !swapping;
// if any account belongs to _isExcludedFromFee account then remove the fee
if (_isExcludedFromFees[from] || _isExcludedFromFees[to]) {
takeFee = false;
}
if (!automatedMarketMakerPairs[to] && !automatedMarketMakerPairs[from])
takeFee = false;
if (takeFee) {
uint256 feeAmt;
if (automatedMarketMakerPairs[to])
feeAmt = (amount * totalSellTax) / 100;
else if (automatedMarketMakerPairs[from])
feeAmt = (amount * totalBuyTax) / 100;
amount = amount - feeAmt;
super._transfer(from, address(this), feeAmt);
}
super._transfer(from, to, amount);
try dividendTracker.setBalance(from, balanceOf(from)) {} catch {}
try dividendTracker.setBalance(to, balanceOf(to)) {} catch {}
}
function swapAndLiquify(uint256 tokens) private {
uint256 toSwap = tokens; //- tokensToAddLiquidityWith;
uint256 totalTax = (totalSellTax);
uint256 dividends = (toSwap * sellTaxes.rewards) / totalTax;
IERC20 token = IERC20(address(this));
if (dividends > 0) {
bool success = token.transfer(address(dividendTracker), dividends);
if (success) {
dividendTracker.distributeDividends(dividends);
emit SendDividends(tokens, dividends);
}
}
uint256 Marsdonations = (toSwap * sellTaxes.treasury) / totalTax;
if (Marsdonations > 0) {
uint256 tokensPerAddress = Marsdonations / NumWhitelisted;
for (uint256 i = 0; i < NumWhitelisted; i++) {
if (WhitelistedAddresses[i] != address(0)) {
bool success = token.transfer(
WhitelistedAddresses[i],
tokensPerAddress
);
if (success) {
emit MarsFundsDistributed(Marsdonations);
}
}
}
}
toSwap -= Marsdonations;
toSwap -= dividends;
swapTokensForETH(toSwap);
uint256 contractrewardbalance = address(this).balance;
uint256 devAmt = (contractrewardbalance);
if (devAmt > 0) {
(bool success, ) = payable(devWallet).call{value: devAmt}("");
require(success, "Failed to send Ether to dev wallet");
}
}
function swapTokensForETH(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = router.WETH();
_approve(address(this), address(router), tokenAmount);
// make the swap
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
}
contract DividendTracker is Ownable, DividendPayingToken {
struct AccountInfo {
address account;
uint256 withdrawableDividends;
uint256 totalDividends;
uint256 lastClaimTime;
}
mapping(address => bool) public excludedFromDividends;
mapping(address => uint256) public lastClaimTimes;
event ExcludeFromDividends(address indexed account, bool value);
event Claim(address indexed account, uint256 amount);
constructor() DividendPayingToken("Dividend_Tracker", "Dividend_Tracker") {}
function trackerRescueETH20Tokens(address recipient, address tokenAddress)
external
onlyOwner
{
IERC20(tokenAddress).transfer(
recipient,
IERC20(tokenAddress).balanceOf(address(this))
);
}
function trackerForceSend(address recipient) external onlyOwner {
(bool success, ) = payable(recipient).call{
value: address(this).balance
}("");
require(success, "Failed to send Ether to wallet");
}
function _transfer(
address,
address,
uint256
) internal pure override {
require(false, "Dividend_Tracker: No transfers allowed");
}
function excludeFromDividends(address account, bool value)
external
onlyOwner
{
require(excludedFromDividends[account] != value);
excludedFromDividends[account] = value;
if (value == true) {
_setBalance(account, 0);
} else {
_setBalance(account, balanceOf(account));
}
emit ExcludeFromDividends(account, value);
}
function getAccount(address account)
public
view
returns (
address,
uint256,
uint256,
uint256,
uint256
)
{
AccountInfo memory info;
info.account = account;
info.withdrawableDividends = withdrawableDividendOf(account);
info.totalDividends = accumulativeDividendOf(account);
info.lastClaimTime = lastClaimTimes[account];
return (
info.account,
info.withdrawableDividends,
info.totalDividends,
info.lastClaimTime,
totalDividendsWithdrawn
);
}
function setBalance(address account, uint256 newBalance)
external
onlyOwner
{
if (excludedFromDividends[account]) {
return;
}
_setBalance(account, newBalance);
}
function updateLP_Token(address _lpToken) external onlyOwner {
_Token = _lpToken;
}
function processAccount(address payable account)
external
onlyOwner
returns (bool)
{
uint256 amount = _withdrawDividendOfUser(account);
if (amount > 0) {
lastClaimTimes[account] = block.timestamp;
emit Claim(account, amount);
return true;
}
return false;
}
}
MarsereumDividendToken.sol 383 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./DividendPayingTokenInterface.sol";
import "./IDEX.sol";
library SafeMathInt {
int256 private constant MIN_INT256 = int256(1) << 255;
int256 private constant MAX_INT256 = ~(int256(1) << 255);
/**
* @dev Multiplies two int256 variables and fails on overflow.
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
int256 c = a * b;
// Detect overflow when multiplying MIN_INT256 with -1
require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b == 0) || (c / b == a));
return c;
}
/**
* @dev Division of two int256 variables and fails on overflow.
*/
function div(int256 a, int256 b) internal pure returns (int256) {
// Prevent overflow when dividing MIN_INT256 by -1
require(b != -1 || a != MIN_INT256);
// Solidity already throws when dividing by 0.
return a / b;
}
/**
* @dev Subtracts two int256 variables and fails on overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a));
return c;
}
/**
* @dev Adds two int256 variables and fails on overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a));
return c;
}
/**
* @dev Converts to absolute value, and fails on overflow.
*/
function abs(int256 a) internal pure returns (int256) {
require(a != MIN_INT256);
return a < 0 ? -a : a;
}
function toUint256Safe(int256 a) internal pure returns (uint256) {
require(a >= 0);
return uint256(a);
}
}
/**
* @title SafeMathUint
* @dev Math operations with safety checks that revert on error
*/
library SafeMathUint {
function toInt256Safe(uint256 a) internal pure returns (int256) {
int256 b = int256(a);
require(b >= 0);
return b;
}
}
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
contract DividendPayingToken is ERC20, DividendPayingTokenInterface, Ownable {
using SafeMath for uint256;
using SafeMathUint for uint256;
using SafeMathInt for int256;
address public _Token;
// With `magnitude`, we can properly distribute dividends even if the amount of received ether is small.
// For more discussion about choosing the value of `magnitude`,
// see https://github.com/ethereum/EIPs/issues/1726#issuecomment-472352728
uint256 constant internal magnitude = 2**128;
uint256 internal magnifiedDividendPerShare;
// About dividendCorrection:
// If the token balance of a `_user` is never changed, the dividend of `_user` can be computed with:
// `dividendOf(_user) = dividendPerShare * balanceOf(_user)`.
// When `balanceOf(_user)` is changed (via minting/burning/transferring tokens),
// `dividendOf(_user)` should not be changed,
// but the computed value of `dividendPerShare * balanceOf(_user)` is changed.
// To keep the `dividendOf(_user)` unchanged, we add a correction term:
// `dividendOf(_user) = dividendPerShare * balanceOf(_user) + dividendCorrectionOf(_user)`,
// where `dividendCorrectionOf(_user)` is updated whenever `balanceOf(_user)` is changed:
// `dividendCorrectionOf(_user) = dividendPerShare * (old balanceOf(_user)) - (new balanceOf(_user))`.
// So now `dividendOf(_user)` returns the same value before and after `balanceOf(_user)` is changed.
mapping(address => int256) internal magnifiedDividendCorrections;
mapping(address => uint256) internal withdrawnDividends;
uint256 public totalDividendsDistributed;
uint256 public totalDividendsWithdrawn;
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {}
function distributeDividends(uint256 amount) public onlyOwner{
require(totalSupply() > 0);
if (amount > 0) {
magnifiedDividendPerShare = magnifiedDividendPerShare.add(
(amount).mul(magnitude) / totalSupply()
);
emit DividendsDistributed(msg.sender, amount);
totalDividendsDistributed = totalDividendsDistributed.add(amount);
}
}
/// @notice Withdraws the ether distributed to the sender.
/// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0.
function withdrawDividend() public virtual override {
_withdrawDividendOfUser(payable(msg.sender));
}
/// @notice Withdraws the ether distributed to the sender.
/// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0.
function _withdrawDividendOfUser(address payable user) internal returns (uint256) {
uint256 _withdrawableDividend = withdrawableDividendOf(user);
if (_withdrawableDividend > 0) {
withdrawnDividends[user] = withdrawnDividends[user].add(_withdrawableDividend);
totalDividendsWithdrawn += _withdrawableDividend;
emit DividendWithdrawn(user, _withdrawableDividend);
bool success = IERC20(_Token).transfer(user, _withdrawableDividend);
if(!success) {
withdrawnDividends[user] = withdrawnDividends[user].sub(_withdrawableDividend);
totalDividendsWithdrawn -= _withdrawableDividend;
return 0;
}
return _withdrawableDividend;
}
return 0;
}
/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` can withdraw.
function dividendOf(address _owner) public view override returns(uint256) {
return withdrawableDividendOf(_owner);
}
/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` can withdraw.
function withdrawableDividendOf(address _owner) public view override returns(uint256) {
return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]);
}
/// @notice View the amount of dividend in wei that an address has withdrawn.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` has withdrawn.
function withdrawnDividendOf(address _owner) public view override returns(uint256) {
return withdrawnDividends[_owner];
}
/// @notice View the amount of dividend in wei that an address has earned in total.
/// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
/// = (magnifiedDividendPerShare * balanceOf(_owner) + magnifiedDividendCorrections[_owner]) / magnitude
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` has earned in total.
function accumulativeDividendOf(address _owner) public view override returns(uint256) {
return magnifiedDividendPerShare.mul(balanceOf(_owner)).toInt256Safe()
.add(magnifiedDividendCorrections[_owner]).toUint256Safe() / magnitude;
}
/// @dev Internal function that transfer tokens from one address to another.
/// Update magnifiedDividendCorrections to keep dividends unchanged.
/// @param from The address to transfer from.
/// @param to The address to transfer to.
/// @param value The amount to be transferred.
function _transfer(address from, address to, uint256 value) internal virtual override {
require(false);
int256 _magCorrection = magnifiedDividendPerShare.mul(value).toInt256Safe();
magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from].add(_magCorrection);
magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(_magCorrection);
}
/// @dev Internal function that mints tokens to an account.
/// Update magnifiedDividendCorrections to keep dividends unchanged.
/// @param account The account that will receive the created tokens.
/// @param value The amount that will be created.
function _mint(address account, uint256 value) internal override {
super._mint(account, value);
magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]
.sub( (magnifiedDividendPerShare.mul(value)).toInt256Safe() );
}
/// @dev Internal function that burns an amount of the token of a given account.
/// Update magnifiedDividendCorrections to keep dividends unchanged.
/// @param account The account whose tokens will be burnt.
/// @param value The amount that will be burnt.
function _burn(address account, uint256 value) internal override {
super._burn(account, value);
magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]
.add( (magnifiedDividendPerShare.mul(value)).toInt256Safe() );
}
function _setBalance(address account, uint256 newBalance) internal {
uint256 currentBalance = balanceOf(account);
if(newBalance > currentBalance) {
uint256 mintAmount = newBalance.sub(currentBalance);
_mint(account, mintAmount);
} else if(newBalance < currentBalance) {
uint256 burnAmount = currentBalance.sub(newBalance);
_burn(account, burnAmount);
}
}
}
DividendPayingTokenInterface.sol 53 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;
/// @title Dividend-Paying Token Interface
/// @author Roger Wu (https://github.com/roger-wu)
/// @dev An interface for a dividend-paying token contract.
interface DividendPayingTokenInterface {
/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` can withdraw.
function dividendOf(address _owner) external view returns(uint256);
/// @notice Withdraws the ether distributed to the sender.
/// @dev SHOULD transfer `dividendOf(msg.sender)` wei to `msg.sender`, and `dividendOf(msg.sender)` SHOULD be 0 after the transfer.
/// MUST emit a `DividendWithdrawn` event if the amount of ether transferred is greater than 0.
function withdrawDividend() external;
/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` can withdraw.
function withdrawableDividendOf(address _owner) external view returns(uint256);
/// @notice View the amount of dividend in wei that an address has withdrawn.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` has withdrawn.
function withdrawnDividendOf(address _owner) external view returns(uint256);
/// @notice View the amount of dividend in wei that an address has earned in total.
/// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` has earned in total.
function accumulativeDividendOf(address _owner) external view returns(uint256);
/// @dev This event MUST emit when ether is distributed to token holders.
/// @param from The address which sends ether to this contract.
/// @param weiAmount The amount of distributed ether in wei.
event DividendsDistributed(
address indexed from,
uint256 weiAmount
);
/// @dev This event MUST emit when an address withdraws their dividend.
/// @param to The address which withdraws ether from this contract.
/// @param weiAmount The amount of withdrawn ether in wei.
event DividendWithdrawn(
address indexed to,
uint256 weiAmount
);
}
Arrays.sol 96 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Arrays.sol)
pragma solidity ^0.8.0;
import "./StorageSlot.sol";
import "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using StorageSlot for bytes32;
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* `array` is expected to be sorted in ascending order, and to contain no
* repeated elements.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
if (array.length == 0) {
return 0;
}
uint256 low = 0;
uint256 high = array.length;
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds down (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getUint256Slot();
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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 anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing 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);
}
}
Counters.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
ERC20.sol 389 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
StorageSlot.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
SafeCast.sol 1136 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
IVotes.sol 61 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/utils/IVotes.sol)
pragma solidity ^0.8.0;
/**
* @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
*
* _Available since v4.5._
*/
interface IVotes {
/**
* @dev Emitted when an account changes their delegate.
*/
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/**
* @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
*/
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
/**
* @dev Returns the current amount of votes that `account` has.
*/
function getVotes(address account) external view returns (uint256);
/**
* @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`).
*/
function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);
/**
* @dev Returns the total supply of votes available at the end of a past block (`blockNumber`).
*
* NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
* Votes that have not been delegated are still part of total supply, even though they would not participate in a
* vote.
*/
function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);
/**
* @dev Returns the delegate that `account` has chosen.
*/
function delegates(address account) external view returns (address);
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(address delegatee) external;
/**
* @dev Delegates votes from signer to `delegatee`.
*/
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
ECDSA.sol 213 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
EIP712.sol 104 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.0;
import "./ECDSA.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
address private immutable _CACHED_THIS;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_CACHED_THIS = address(this);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
}
ERC20Votes.sol 275 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.1) (token/ERC20/extensions/ERC20Votes.sol)
pragma solidity ^0.8.0;
import "./draft-ERC20Permit.sol";
import "../../../utils/math/Math.sol";
import "../../../governance/utils/IVotes.sol";
import "../../../utils/math/SafeCast.sol";
import "../../../utils/cryptography/ECDSA.sol";
/**
* @dev Extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound's,
* and supports token supply up to 2^224^ - 1, while COMP is limited to 2^96^ - 1.
*
* NOTE: If exact COMP compatibility is required, use the {ERC20VotesComp} variant of this module.
*
* This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either
* by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting
* power can be queried through the public accessors {getVotes} and {getPastVotes}.
*
* By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
* requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.
*
* _Available since v4.2._
*/
abstract contract ERC20Votes is IVotes, ERC20Permit {
struct Checkpoint {
uint32 fromBlock;
uint224 votes;
}
bytes32 private constant _DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
mapping(address => address) private _delegates;
mapping(address => Checkpoint[]) private _checkpoints;
Checkpoint[] private _totalSupplyCheckpoints;
/**
* @dev Get the `pos`-th checkpoint for `account`.
*/
function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoint memory) {
return _checkpoints[account][pos];
}
/**
* @dev Get number of checkpoints for `account`.
*/
function numCheckpoints(address account) public view virtual returns (uint32) {
return SafeCast.toUint32(_checkpoints[account].length);
}
/**
* @dev Get the address `account` is currently delegating to.
*/
function delegates(address account) public view virtual override returns (address) {
return _delegates[account];
}
/**
* @dev Gets the current votes balance for `account`
*/
function getVotes(address account) public view virtual override returns (uint256) {
uint256 pos = _checkpoints[account].length;
return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes;
}
/**
* @dev Retrieve the number of votes for `account` at the end of `blockNumber`.
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
return _checkpointsLookup(_checkpoints[account], blockNumber);
}
/**
* @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances.
* It is but NOT the sum of all the delegated votes!
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256) {
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
}
/**
* @dev Lookup a value in a list of (sorted) checkpoints.
*/
function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 blockNumber) private view returns (uint256) {
// We run a binary search to look for the earliest checkpoint taken after `blockNumber`.
//
// Initially we check if the block is recent to narrow the search range.
// During the loop, the index of the wanted checkpoint remains in the range [low-1, high).
// With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the invariant.
// - If the middle checkpoint is after `blockNumber`, we look in [low, mid)
// - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high)
// Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not
// out of bounds (in which case we're looking too far in the past and the result is 0).
// Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is
// past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out
// the same.
uint256 length = ckpts.length;
uint256 low = 0;
uint256 high = length;
if (length > 5) {
uint256 mid = length - Math.sqrt(length);
if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {
high = mid;
} else {
low = mid + 1;
}
}
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {
high = mid;
} else {
low = mid + 1;
}
}
return high == 0 ? 0 : _unsafeAccess(ckpts, high - 1).votes;
}
/**
* @dev Delegate votes from the sender to `delegatee`.
*/
function delegate(address delegatee) public virtual override {
_delegate(_msgSender(), delegatee);
}
/**
* @dev Delegates votes from signer to `delegatee`
*/
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= expiry, "ERC20Votes: signature expired");
address signer = ECDSA.recover(
_hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
v,
r,
s
);
require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
_delegate(signer, delegatee);
}
/**
* @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
*/
function _maxSupply() internal view virtual returns (uint224) {
return type(uint224).max;
}
/**
* @dev Snapshots the totalSupply after it has been increased.
*/
function _mint(address account, uint256 amount) internal virtual override {
super._mint(account, amount);
require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
_writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
}
/**
* @dev Snapshots the totalSupply after it has been decreased.
*/
function _burn(address account, uint256 amount) internal virtual override {
super._burn(account, amount);
_writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
}
/**
* @dev Move voting power when tokens are transferred.
*
* Emits a {IVotes-DelegateVotesChanged} event.
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
super._afterTokenTransfer(from, to, amount);
_moveVotingPower(delegates(from), delegates(to), amount);
}
/**
* @dev Change delegation for `delegator` to `delegatee`.
*
* Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
*/
function _delegate(address delegator, address delegatee) internal virtual {
address currentDelegate = delegates(delegator);
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveVotingPower(currentDelegate, delegatee, delegatorBalance);
}
function _moveVotingPower(
address src,
address dst,
uint256 amount
) private {
if (src != dst && amount > 0) {
if (src != address(0)) {
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
emit DelegateVotesChanged(src, oldWeight, newWeight);
}
if (dst != address(0)) {
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
emit DelegateVotesChanged(dst, oldWeight, newWeight);
}
}
}
function _writeCheckpoint(
Checkpoint[] storage ckpts,
function(uint256, uint256) view returns (uint256) op,
uint256 delta
) private returns (uint256 oldWeight, uint256 newWeight) {
uint256 pos = ckpts.length;
Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0) : _unsafeAccess(ckpts, pos - 1);
oldWeight = oldCkpt.votes;
newWeight = op(oldWeight, delta);
if (pos > 0 && oldCkpt.fromBlock == block.number) {
_unsafeAccess(ckpts, pos - 1).votes = SafeCast.toUint224(newWeight);
} else {
ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
}
}
function _add(uint256 a, uint256 b) private pure returns (uint256) {
return a + b;
}
function _subtract(uint256 a, uint256 b) private pure returns (uint256) {
return a - b;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(Checkpoint[] storage ckpts, uint256 pos) private pure returns (Checkpoint storage result) {
assembly {
mstore(0, ckpts.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
}
ERC20Snapshot.sol 195 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/extensions/ERC20Snapshot.sol)
pragma solidity ^0.8.0;
import "../ERC20.sol";
import "../../../utils/Arrays.sol";
import "../../../utils/Counters.sol";
/**
* @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and
* total supply at the time are recorded for later access.
*
* This can be used to safely create mechanisms based on token balances such as trustless dividends or weighted voting.
* In naive implementations it's possible to perform a "double spend" attack by reusing the same balance from different
* accounts. By using snapshots to calculate dividends or voting power, those attacks no longer apply. It can also be
* used to create an efficient ERC20 forking mechanism.
*
* Snapshots are created by the internal {_snapshot} function, which will emit the {Snapshot} event and return a
* snapshot id. To get the total supply at the time of a snapshot, call the function {totalSupplyAt} with the snapshot
* id. To get the balance of an account at the time of a snapshot, call the {balanceOfAt} function with the snapshot id
* and the account address.
*
* NOTE: Snapshot policy can be customized by overriding the {_getCurrentSnapshotId} method. For example, having it
* return `block.number` will trigger the creation of snapshot at the beginning of each new block. When overriding this
* function, be careful about the monotonicity of its result. Non-monotonic snapshot ids will break the contract.
*
* Implementing snapshots for every block using this method will incur significant gas costs. For a gas-efficient
* alternative consider {ERC20Votes}.
*
* ==== Gas Costs
*
* Snapshots are efficient. Snapshot creation is _O(1)_. Retrieval of balances or total supply from a snapshot is _O(log
* n)_ in the number of snapshots that have been created, although _n_ for a specific account will generally be much
* smaller since identical balances in subsequent snapshots are stored as a single entry.
*
* There is a constant overhead for normal ERC20 transfers due to the additional snapshot bookkeeping. This overhead is
* only significant for the first transfer that immediately follows a snapshot for a particular account. Subsequent
* transfers will have normal cost until the next snapshot, and so on.
*/
abstract contract ERC20Snapshot is ERC20 {
// Inspired by Jordi Baylina's MiniMeToken to record historical balances:
// https://github.com/Giveth/minime/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol
using Arrays for uint256[];
using Counters for Counters.Counter;
// Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
// Snapshot struct, but that would impede usage of functions that work on an array.
struct Snapshots {
uint256[] ids;
uint256[] values;
}
mapping(address => Snapshots) private _accountBalanceSnapshots;
Snapshots private _totalSupplySnapshots;
// Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
Counters.Counter private _currentSnapshotId;
/**
* @dev Emitted by {_snapshot} when a snapshot identified by `id` is created.
*/
event Snapshot(uint256 id);
/**
* @dev Creates a new snapshot and returns its snapshot id.
*
* Emits a {Snapshot} event that contains the same id.
*
* {_snapshot} is `internal` and you have to decide how to expose it externally. Its usage may be restricted to a
* set of accounts, for example using {AccessControl}, or it may be open to the public.
*
* [WARNING]
* ====
* While an open way of calling {_snapshot} is required for certain trust minimization mechanisms such as forking,
* you must consider that it can potentially be used by attackers in two ways.
*
* First, it can be used to increase the cost of retrieval of values from snapshots, although it will grow
* logarithmically thus rendering this attack ineffective in the long term. Second, it can be used to target
* specific accounts and increase the cost of ERC20 transfers for them, in the ways specified in the Gas Costs
* section above.
*
* We haven't measured the actual numbers; if this is something you're interested in please reach out to us.
* ====
*/
function _snapshot() internal virtual returns (uint256) {
_currentSnapshotId.increment();
uint256 currentId = _getCurrentSnapshotId();
emit Snapshot(currentId);
return currentId;
}
/**
* @dev Get the current snapshotId
*/
function _getCurrentSnapshotId() internal view virtual returns (uint256) {
return _currentSnapshotId.current();
}
/**
* @dev Retrieves the balance of `account` at the time `snapshotId` was created.
*/
function balanceOfAt(address account, uint256 snapshotId) public view virtual returns (uint256) {
(bool snapshotted, uint256 value) = _valueAt(snapshotId, _accountBalanceSnapshots[account]);
return snapshotted ? value : balanceOf(account);
}
/**
* @dev Retrieves the total supply at the time `snapshotId` was created.
*/
function totalSupplyAt(uint256 snapshotId) public view virtual returns (uint256) {
(bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnapshots);
return snapshotted ? value : totalSupply();
}
// Update balance and/or total supply snapshots before the values are modified. This is implemented
// in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
if (from == address(0)) {
// mint
_updateAccountSnapshot(to);
_updateTotalSupplySnapshot();
} else if (to == address(0)) {
// burn
_updateAccountSnapshot(from);
_updateTotalSupplySnapshot();
} else {
// transfer
_updateAccountSnapshot(from);
_updateAccountSnapshot(to);
}
}
function _valueAt(uint256 snapshotId, Snapshots storage snapshots) private view returns (bool, uint256) {
require(snapshotId > 0, "ERC20Snapshot: id is 0");
require(snapshotId <= _getCurrentSnapshotId(), "ERC20Snapshot: nonexistent id");
// When a valid snapshot is queried, there are three possibilities:
// a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
// created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
// to this id is the current one.
// b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
// requested id, and its value is the one to return.
// c) More snapshots were created after the requested one, and the queried value was later modified. There will be
// no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
// larger than the requested one.
//
// In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
// it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
// exactly this.
uint256 index = snapshots.ids.findUpperBound(snapshotId);
if (index == snapshots.ids.length) {
return (false, 0);
} else {
return (true, snapshots.values[index]);
}
}
function _updateAccountSnapshot(address account) private {
_updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
}
function _updateTotalSupplySnapshot() private {
_updateSnapshot(_totalSupplySnapshots, totalSupply());
}
function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {
uint256 currentId = _getCurrentSnapshotId();
if (_lastSnapshotId(snapshots.ids) < currentId) {
snapshots.ids.push(currentId);
snapshots.values.push(currentValue);
}
}
function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {
if (ids.length == 0) {
return 0;
} else {
return ids[ids.length - 1];
}
}
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
draft-ERC20Permit.sol 95 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/extensions/draft-ERC20Permit.sol)
pragma solidity ^0.8.0;
import "./draft-IERC20Permit.sol";
import "../ERC20.sol";
import "../../../utils/cryptography/ECDSA.sol";
import "../../../utils/cryptography/EIP712.sol";
import "../../../utils/Counters.sol";
/**
* @dev Implementation 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.
*
* _Available since v3.4._
*/
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
using Counters for Counters.Counter;
mapping(address => Counters.Counter) private _nonces;
// solhint-disable-next-line var-name-mixedcase
bytes32 private constant _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.
* However, to ensure consistency with the upgradeable transpiler, we will continue
* to reserve a slot.
* @custom:oz-renamed-from _PERMIT_TYPEHASH
*/
// solhint-disable-next-line var-name-mixedcase
bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) EIP712(name, "1") {}
/**
* @dev See {IERC20Permit-permit}.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
require(signer == owner, "ERC20Permit: invalid signature");
_approve(owner, spender, value);
}
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view virtual override returns (uint256) {
return _nonces[owner].current();
}
/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
/**
* @dev "Consume a nonce": return the current value and increment.
*
* _Available since v4.1._
*/
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Read Contract
DOMAIN_SEPARATOR 0x3644e515 → bytes32
GovernorAddress 0x7dd2b195 → address
NumWhitelisted 0x8d0841f1 → uint256
_isBot 0xabb81052 → bool
allowance 0xdd62ed3e → uint256
automatedMarketMakerPairs 0xb62496f5 → bool
balanceOf 0x70a08231 → uint256
balanceOfAt 0x4ee2cd7e → uint256
buyTaxes 0x864701a5 → uint256, uint256, uint256
checkpoints 0xf1127ed8 → tuple
claimEnabled 0x2866ed21 → bool
decimals 0x313ce567 → uint8
delegates 0x587cde1e → address
devWallet 0x8ea5220f → address
dividendTokenBalanceOf 0x6843cd84 → uint256
dividendTracker 0x2c1f5216 → address
getAccountInfo 0x7b510fe8 → address, uint256, uint256, uint256, uint256
getPastTotalSupply 0x8e539e8c → uint256
getPastVotes 0x3a46b1a8 → uint256
getTotalDividendsDistributed 0x30bb4cff → uint256
getVotes 0x9ab24eb0 → uint256
isExcludedFromFees 0x4fbee193 → bool
isWhitelisted 0x3af32abf → bool
maxBuyAmount 0x88e765ff → uint256
maxSellAmount 0x66d602ae → uint256
maxWallet 0xf8b45b05 → uint256
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
numCheckpoints 0x6fcfff45 → uint32
owner 0x8da5cb5b → address
pair 0xa8aa1b31 → address
router 0xf887ea40 → address
sellTaxes 0xf66895a3 → uint256, uint256, uint256
swapEnabled 0x6ddd1713 → bool
swapTokensAtAmount 0xe2f45605 → uint256
symbol 0x95d89b41 → string
totalBuyTax 0x46469afb → uint256
totalSellTax 0x1bff7898 → uint256
totalSupply 0x18160ddd → uint256
totalSupplyAt 0x981b24d0 → uint256
tradingEnabled 0x4ada218b → bool
withdrawableDividendOf 0xa8b9d240 → uint256
Write Contract 41 functions
These functions modify contract state and require a wallet transaction to execute.
UpdateGovernorAddress 0xa5150c3d
address _newgov
activateTrading 0x0bd05b69
No parameters
addToWhitelist 0xe43252d7
address _address
addToWhitelistGovernor 0x02246576
address _address
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
claim 0x4e71d92d
No parameters
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
delegate 0x5c19a95c
address delegatee
delegateBySig 0xc3cda520
address delegatee
uint256 nonce
uint256 expiry
uint8 v
bytes32 r
bytes32 s
excludeFromDividends 0x0483f7a0
address account
bool value
excludeFromFees 0xc0246668
address account
bool excluded
excludeFromMaxWallet 0xd2fcc001
address account
bool excluded
excludeMultipleAccountsFromFees 0xc492f046
address[] accounts
bool excluded
forceSend 0x12b77e8a
No parameters
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
permit 0xd505accf
address owner
address spender
uint256 value
uint256 deadline
uint8 v
bytes32 r
bytes32 s
removeFromWhitelist 0x8ab1d681
address _address
removeFromWhitelistGovernor 0x28d25411
address _address
renounceOwnership 0x715018a6
No parameters
rescueETH20Tokens 0x0a78097d
address tokenAddress
setAutomatedMarketMakerPair 0x9a7a23d6
address newPair
bool value
setBot 0x342aa8b5
address bot
bool value
setBuyTaxes 0x1870517a
uint256 _rewards
uint256 _treasury
uint256 _dev
setBuyTaxesGovernor 0x3242f255
uint256 _rewards
uint256 _treasury
uint256 _dev
setClaimEnabled 0x92929a09
bool state
setDevWallet 0x1f53ac02
address newWallet
setDiv_Token 0xbe825b52
address _token
setMaxBuyAndSell 0x79b447bd
uint256 maxBuy
uint256 maxSell
setSellTaxes 0x08733214
uint256 _rewards
uint256 _treasury
uint256 _dev
setSellTaxesGovernor 0x17c766b3
uint256 _rewards
uint256 _treasury
uint256 _dev
setSwapEnabled 0xe01af92c
bool _enabled
setSwapTokensAtAmount 0xafa4f3b2
uint256 amount
snapshot 0x9711715a
No parameters
trackerForceSend 0xe11c3368
No parameters
trackerRescueETH20Tokens 0x8c9684f9
address tokenAddress
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner
updateDividendTracker 0x88bdd9be
address newAddress
updateMaxWalletAmount 0xc18bc195
uint256 newNum
updateRouter 0xc851cc32
address newRouter
Recent Transactions
No transactions found for this address