Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x48066e2dF341D7e102e3859886c4E85743087E92
Balance 0 ETH
Nonce 1
Code Size 9364 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

9364 bytes
0x6080604052600436106102675760003560e01c80636dfc9926116101445780639e34070f116100b6578063dabd27191161007a578063dabd2719146106f9578063db068e0e14610719578063dd62ed3e14610739578063debefaa614610759578063eeb69d4114610779578063f2fde38b1461079957600080fd5b80639e34070f1461065f578063a457c2d71461067f578063a9059cbb1461069f578063af38d757146106bf578063b12ebc9d146106d957600080fd5b8063887c5b0611610108578063887c5b06146105d95780638d3d6576146105e15780638d8f2adb146105f75780638da5cb5b1461060c57806395d89b411461062a578063983731c11461063f57600080fd5b80636dfc9926146105215780636ff1c9bc1461054e57806370a082311461056e578063715018a6146105a45780637cb64759146105b957600080fd5b8063378c93ad116101dd5780635a95ba34116101a15780635a95ba341461048c57806360d3bee2146104ac57806364f2b4ff146104bf578063667bfc20146104d55780636b6f4a9d146104f55780636d4864971461050b57600080fd5b8063378c93ad146103f357806337c089231461041357806339509351146104295780633ba0b9a914610449578063423e1c3d1461045f57600080fd5b8063200d2ed21161022f578063200d2ed21461034557806320d9e5331461036c578063213ec7bd1461038c57806323b872dd146103a15780632eb4a7ab146103c1578063313ce567146103d757600080fd5b806303ed9d211461026c57806306fdde031461028e578063095ea7b3146102b95780630df9e166146102e957806318160ddd14610326575b600080fd5b34801561027857600080fd5b5061028c610287366004611fa9565b6107b9565b005b34801561029a57600080fd5b506102a361081e565b6040516102b09190611fee565b60405180910390f35b3480156102c557600080fd5b506102d96102d436600461203d565b6108b0565b60405190151581526020016102b0565b3480156102f557600080fd5b5060095461030e9061010090046001600160a01b031681565b6040516001600160a01b0390911681526020016102b0565b34801561033257600080fd5b506004545b6040519081526020016102b0565b34801561035157600080fd5b5060095461035f9060ff1681565b6040516102b0919061207d565b34801561037857600080fd5b5061028c610387366004611fa9565b6108ca565b34801561039857600080fd5b5061028c610968565b3480156103ad57600080fd5b506102d96103bc3660046120a5565b6109cb565b3480156103cd57600080fd5b50610337600e5481565b3480156103e357600080fd5b50604051601381526020016102b0565b3480156103ff57600080fd5b5061028c61040e3660046120ef565b6109ef565b34801561041f57600080fd5b50610337600c5481565b34801561043557600080fd5b506102d961044436600461203d565b610a38565b34801561045557600080fd5b50610337600b5481565b34801561046b57600080fd5b5061033761047a36600461210c565b60106020526000908152604090205481565b34801561049857600080fd5b5061028c6104a7366004612173565b610a5a565b6103376104ba3660046121c6565b610b32565b3480156104cb57600080fd5b50610337600d5481565b3480156104e157600080fd5b5061028c6104f0366004611fa9565b610c05565b34801561050157600080fd5b50610337600f5481565b34801561051757600080fd5b5061033760125481565b34801561052d57600080fd5b5061033761053c36600461210c565b60116020526000908152604090205481565b34801561055a57600080fd5b5061028c61056936600461210c565b610c65565b34801561057a57600080fd5b5061033761058936600461210c565b6001600160a01b031660009081526002602052604090205490565b3480156105b057600080fd5b5061028c610d97565b3480156105c557600080fd5b5061028c6105d4366004611fa9565b610dab565b610337610de8565b3480156105ed57600080fd5b50610337600a5481565b34801561060357600080fd5b5061028c610e96565b34801561061857600080fd5b506001546001600160a01b031661030e565b34801561063657600080fd5b506102a3610fde565b34801561064b57600080fd5b506102d961065a366004612208565b610fed565b34801561066b57600080fd5b506102d961067a366004611fa9565b61105c565b34801561068b57600080fd5b506102d961069a36600461203d565b61109d565b3480156106ab57600080fd5b506102d96106ba36600461203d565b61111d565b3480156106cb57600080fd5b506007546102d99060ff1681565b3480156106e557600080fd5b5061028c6106f4366004612270565b61112b565b34801561070557600080fd5b5061028c610714366004611fa9565b61119e565b34801561072557600080fd5b5061028c610734366004611fa9565b6111fe565b34801561074557600080fd5b50610337610754366004612291565b61125c565b34801561076557600080fd5b506102d96107743660046122c4565b611287565b34801561078557600080fd5b5061028c61079436600461210c565b6112da565b3480156107a557600080fd5b5061028c6107b436600461210c565b611362565b6107c16113d8565b806000036107e25760405163162908e360e11b815260040160405180910390fd5b600a8190556040518181527f8645f88287b79f16d91266da1d35b7adc817d75a89a9577504b01fbc37ed5a6f906020015b60405180910390a150565b60606005805461082d90612318565b80601f016020809104026020016040519081016040528092919081815260200182805461085990612318565b80156108a65780601f1061087b576101008083540402835291602001916108a6565b820191906000526020600020905b81548152906001019060200180831161088957829003601f168201915b5050505050905090565b6000336108be818585611432565b60019150505b92915050565b6108d2611556565b6009546108ef9061010090046001600160a01b03163330846115af565b6000612710601254836109029190612368565b61090c919061239d565b9050600061091a82846123b1565b90506109263382611620565b6040518381527f0175621bd7873f24f7160fd320316d8b8e5d437230cd18c75ca05f7dab6167749060200160405180910390a150506109656001600055565b50565b6109706113d8565b610995476109866001546001600160a01b031690565b6001600160a01b0316906116e1565b6040514781527f33ed1fb41d6c0756201dbdddbd1c388018c393b8c5e186f9f5eef0d633c347d6906020015b60405180910390a1565b6000336109d98582856117ff565b6109e4858585611873565b506001949350505050565b6109f76113d8565b6007805460ff19168215159081179091556040519081527f18d99b89a15641fa45e09c4916c435eb2bee98b29a0157c251869471e0cf28c990602001610813565b6000336108be818585610a4b838361125c565b610a5591906123b1565b611432565b610a638461105c565b15610a8157604051630c8d9eab60e31b815260040160405180910390fd5b60075460ff16610aa45760405163024fbaa960e41b815260040160405180910390fd5b610ab18433858585610fed565b610ace57604051631033349760e31b815260040160405180910390fd5b610ad784611a1e565b600954610af39061010090046001600160a01b03163385611a5c565b60408051338152602081018590527f650e45f04ef8a0c267b2f78d983913f69ae3a353b2b32de5429307522be0ab55910160405180910390a150505050565b6000610b3c611556565b600a543360009081526010602052604090205410610b6d57604051639d91c06160e01b815260040160405180910390fd5b600160095460ff166002811115610b8657610b86612067565b14610ba45760405163cf0ba71f60e01b815260040160405180910390fd5b610baf838333611287565b610bcc57604051630b094f2760e31b815260040160405180910390fd5b3360009081526010602052604081208054349290610beb9084906123b1565b90915550610bf99050611a8c565b90506108c46001600055565b610c0d6113d8565b612710811115610c3057604051637db3aba760e01b815260040160405180910390fd5b60128190556040518181527f4863abbf296f7226439fd6113742ed6951ab8a09f81e87cf9f4e6e5f728c149c90602001610813565b610c6d6113d8565b6040516370a0823160e01b8152306004820152610cec9033906001600160a01b038416906370a0823190602401602060405180830381865afa158015610cb7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cdb91906123c9565b6001600160a01b0384169190611a5c565b6040516370a0823160e01b81523060048201527f6352c5382c4a4578e712449ca65e83cdb392d045dfcf1cad9615189db2da244b9082906001600160a01b038216906370a0823190602401602060405180830381865afa158015610d54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d7891906123c9565b604080516001600160a01b039093168352602083019190915201610813565b610d9f6113d8565b610da96000611c65565b565b610db36113d8565b600e8190556040518181527f42cbc405e4dbf1b691e85b9a34b08ecfcf7a9ad9078bf4d645ccfa1fac11c10b90602001610813565b6000610df2611556565b600a543360009081526011602052604090205410610e2357604051639d91c06160e01b815260040160405180910390fd5b600260095460ff166002811115610e3c57610e3c612067565b14610e5a576040516331f423c160e21b815260040160405180910390fd5b3360009081526011602052604081208054349290610e799084906123b1565b90915550610e879050611a8c565b9050610e936001600055565b90565b610e9e6113d8565b6009546040516370a0823160e01b8152306004820152610f2c9133916101009091046001600160a01b0316906370a0823190602401602060405180830381865afa158015610ef0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1491906123c9565b60095461010090046001600160a01b03169190611a5c565b6009546040516370a0823160e01b81523060048201527f6352c5382c4a4578e712449ca65e83cdb392d045dfcf1cad9615189db2da244b9161010090046001600160a01b03169081906370a0823190602401602060405180830381865afa158015610f9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fbf91906123c9565b604080516001600160a01b0390931683526020830191909152016109c1565b60606006805461082d90612318565b6000808686866040516020016110289392919092835260609190911b6bffffffffffffffffffffffff19166020830152603482015260540190565b60405160208183030381529060405280519060200120905060006110508585600e5485611cb7565b98975050505050505050565b60008061106b6101008461239d565b9050600061107b610100856123e2565b60009283526008602052604090922054600190921b9182169091149392505050565b600033816110ab828661125c565b9050838110156111105760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b6109e48286868403611432565b6000336108be818585611873565b6111336113d8565b6009805482919060ff1916600183600281111561115257611152612067565b02179055506009547ff28bfdecef81097d4a87164b3cb472abaca23e6d9386af5deb439cecb2323b3a9060ff16600281111561119057611190612067565b604051908152602001610813565b6111a66113d8565b6127108111156111c957604051637db3aba760e01b815260040160405180910390fd5b600f8190556040518181527ff247e4dd947ab13ba6c46412e403447a26e67109ba13945a20e3170e9acef88390602001610813565b6112066113d8565b806000036112275760405163162908e360e11b815260040160405180910390fd5b600b8190556040518181527f6bfd5e75539a9d2626425a2e2922675256b219fe546d63dad56011759b9a2f6690602001610813565b6001600160a01b03918216600090815260036020908152604080832093909416825291909152205490565b6040516bffffffffffffffffffffffff19606083901b16602082015260009081906034016040516020818303038152906040528051906020012090506112d18585600e5484611cb7565b95945050505050565b6112e26113d8565b6001600160a01b03811661130957604051631326d6d560e01b815260040160405180910390fd5b60098054610100600160a81b0319166101006001600160a01b038481168202929092179283905560405192041681527fa18edb2555d50cdd90b7020b80a7eb848404397864f1196777457b2297f23b9290602001610813565b61136a6113d8565b6001600160a01b0381166113cf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401611107565b61096581611c65565b6001546001600160a01b03163314610da95760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401611107565b6001600160a01b0383166114945760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401611107565b6001600160a01b0382166114f55760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401611107565b6001600160a01b0383811660008181526003602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6002600054036115a85760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401611107565b6002600055565b6040516001600160a01b038085166024830152831660448201526064810182905261161a9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611cd1565b50505050565b6001600160a01b0382166116765760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401611107565b806004600082825461168891906123b1565b90915550506001600160a01b0382166000818152600260209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b804710156117315760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401611107565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461177e576040519150601f19603f3d011682016040523d82523d6000602084013e611783565b606091505b50509050806117fa5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401611107565b505050565b600061180b848461125c565b9050600019811461161a57818110156118665760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401611107565b61161a8484848403611432565b6001600160a01b0383166118d75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401611107565b6001600160a01b0382166119395760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401611107565b6001600160a01b038316600090815260026020526040902054818110156119b15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401611107565b6001600160a01b0380851660008181526002602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611a119086815260200190565b60405180910390a361161a565b6000611a2c6101008361239d565b90506000611a3c610100846123e2565b6000928352600860205260409092208054600190931b9092179091555050565b6040516001600160a01b0383166024820152604481018290526117fa90849063a9059cbb60e01b906064016115e3565b600034600003611aaf5760405163162908e360e11b815260040160405180910390fd5b600a54336000908152601060209081526040808320546011909252909120543491611ad9916123b1565b611ae391906123b1565b1115611b0257604051639d91c06160e01b815260040160405180910390fd5b6402540be400600b5434611b169190612368565b611b20919061239d565b90506000612710600f5483611b359190612368565b611b3f919061239d565b9050611b4b81836123b1565b915081600d6000828254611b5f91906123b1565b9250508190555034600c6000828254611b7891906123b1565b90915550506009546040516370a0823160e01b81523060048201526101009091046001600160a01b0316906370a0823190602401602060405180830381865afa158015611bc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bed91906123c9565b821115611c0d576040516322ea1bad60e21b815260040160405180910390fd5b600954611c299061010090046001600160a01b03163384611a5c565b604080518381523360208201527f04e75fda068b8e114d7658bdff74280a0fd65586b7e026a034eae29dd5a9e68b910160405180910390a15090565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600082611cc5868685611da3565b1490505b949350505050565b6000611d26826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611def9092919063ffffffff16565b8051909150156117fa5780806020019051810190611d4491906123f6565b6117fa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401611107565b600081815b84811015611de657611dd282878784818110611dc657611dc6612413565b90506020020135611dfe565b915080611dde81612429565b915050611da8565b50949350505050565b6060611cc98484600085611e30565b6000818310611e1a576000828152602084905260409020611e29565b60008381526020839052604090205b9392505050565b606082471015611e915760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611107565b600080866001600160a01b03168587604051611ead9190612442565b60006040518083038185875af1925050503d8060008114611eea576040519150601f19603f3d011682016040523d82523d6000602084013e611eef565b606091505b5091509150611f0087838387611f0b565b979650505050505050565b60608315611f7a578251600003611f73576001600160a01b0385163b611f735760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611107565b5081611cc9565b611cc98383815115611f8f5781518083602001fd5b8060405162461bcd60e51b81526004016111079190611fee565b600060208284031215611fbb57600080fd5b5035919050565b60005b83811015611fdd578181015183820152602001611fc5565b8381111561161a5750506000910152565b602081526000825180602084015261200d816040850160208701611fc2565b601f01601f19169190910160400192915050565b80356001600160a01b038116811461203857600080fd5b919050565b6000806040838503121561205057600080fd5b61205983612021565b946020939093013593505050565b634e487b7160e01b600052602160045260246000fd5b602081016003831061209f57634e487b7160e01b600052602160045260246000fd5b91905290565b6000806000606084860312156120ba57600080fd5b6120c384612021565b92506120d160208501612021565b9150604084013590509250925092565b801515811461096557600080fd5b60006020828403121561210157600080fd5b8135611e29816120e1565b60006020828403121561211e57600080fd5b611e2982612021565b60008083601f84011261213957600080fd5b50813567ffffffffffffffff81111561215157600080fd5b6020830191508360208260051b850101111561216c57600080fd5b9250929050565b6000806000806060858703121561218957600080fd5b8435935060208501359250604085013567ffffffffffffffff8111156121ae57600080fd5b6121ba87828801612127565b95989497509550505050565b600080602083850312156121d957600080fd5b823567ffffffffffffffff8111156121f057600080fd5b6121fc85828601612127565b90969095509350505050565b60008060008060006080868803121561222057600080fd5b8535945061223060208701612021565b935060408601359250606086013567ffffffffffffffff81111561225357600080fd5b61225f88828901612127565b969995985093965092949392505050565b60006020828403121561228257600080fd5b813560038110611e2957600080fd5b600080604083850312156122a457600080fd5b6122ad83612021565b91506122bb60208401612021565b90509250929050565b6000806000604084860312156122d957600080fd5b833567ffffffffffffffff8111156122f057600080fd5b6122fc86828701612127565b909450925061230f905060208501612021565b90509250925092565b600181811c9082168061232c57607f821691505b60208210810361234c57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561238257612382612352565b500290565b634e487b7160e01b600052601260045260246000fd5b6000826123ac576123ac612387565b500490565b600082198211156123c4576123c4612352565b500190565b6000602082840312156123db57600080fd5b5051919050565b6000826123f1576123f1612387565b500690565b60006020828403121561240857600080fd5b8151611e29816120e1565b634e487b7160e01b600052603260045260246000fd5b60006001820161243b5761243b612352565b5060010190565b60008251612454818460208701611fc2565b919091019291505056fea26469706673582212206b292a2011025f637c73915ca21ecb130bef79d1054fc6169f9b32f5a615f1b564736f6c634300080f0033

Verified Source Code Partial Match

Compiler: v0.8.15+commit.e14f2714 EVM: london Optimization: Yes (200 runs)
ILO.sol 546 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.15;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/**
 * @dev Custom error thrown when the provided amount is less then zero.
 */
error InvalidAmount();

/**
 * @dev Custom error thrown when the total max contribution is reached.
 */
error MaxContributionReached();

/**
 * @dev Custom error thrown when an individuals max contribution is reached.
 */
error IndividualMaxContributionReached();

/**
 * @dev Custom error thrown when the Public sale is not active.
 */
error PublicSaleNotActive();

/**
 * @dev Custom error thrown when the Whitelist sale is not active.
 */
error WhitelistSaleNotActive();

/**
 * @dev Custom error thrown when the user attempting to mint is not whitelisted
 */
error NotWhitelisted();

/**
 * @dev Custom error thrown when a user attempts to claim a second time.
 */
error AlreadyClaimed();

/**
 * @dev Custom error thrown when a user attempts to claim while the airdrop is not active
 */
error ClaimNotActive();

/**
 * @dev Custom error thrown when a user attempts to claim while not being eligible for the airdrop
 */
error IsNotWhitelisted();

/**
 * @dev Custom error thrown when a input is out of range
 */
error OutOfRange();

/**
 * @dev Custom error thrown when the inputed address is the zero address
 */
error IsZeroAddress();

contract SquidGrowILO is ReentrancyGuard, Ownable, ERC20 {
    using Address for *;
    using SafeERC20 for ERC20;

    /**
     * @dev Enum defining the possible status values for the ILO contract.
     *      - Closed: 0
     *      - Whitelist: 1
     *      - Public: 2
     */
    enum ILOStatus {
        Closed,
        Whitelist,
        Public
    }

    /**
     * @dev The current claim status of the airdrop.
     */
    bool public claimable = false;

    /**
     * @dev The bitmap that tracks claims for the airdrop.
     */
    mapping(uint256 => uint256) private claimedBitMap;

    /**
     * @dev The current status of the ILO contract.
     */
    ILOStatus public status;

    /**
     * @dev The address of the token being used for the ILO.
     */
    address public squidGrowToken;

    /**
     * @dev The maximum contribution amount in ETH that users can contribute to the ILO.
     */
    uint256 public maxContribution = 106e18;

    /**
     * @dev The exchange rate between 1 token and 1 ETH for the ILO.
     */
    uint256 public exchangeRate = 1690140845076; // 0.0059153 ETH per token scaled by 10^7 for precision

    /**
     * @dev The total amount of ETH contributed to the ILO.
     */
    uint256 public totalContributions;

    /**
     * @dev The total number of tokens that have been minted and sent to contributors.
     */
    uint256 public totalContributionsTokens;

    /**
     * @dev The Merkle root used for the ILO's whitelist.
     */
    bytes32 public merkleRoot;

    /**
     * @dev The discount applied to the token price for the ILO, represented in base points (e.g. 500 = 5%).
     */
    uint256 public discount = 500;

    /**
     * @dev Mapping of the amount of contributions made by whitelisted users.
     */
    mapping(address => uint256) public whitelistContributions;

    /**
     * @dev Mapping of the amount of contributions made by public users.
     */
    mapping(address => uint256) public publicContributions;

    /**
     * @dev Emitted when the merkle root for the ILO is set.
     * @param merkleRoot The new merkle root.
     */
    event MerkleRootSet(bytes32 merkleRoot);

    /**
     * @dev Emitted when a contribution is made to the ILO.
     * @param amount The amount of tokens contributed.
     * @param contributor The address of the contributor.
     */
    event Contribution(uint amount, address contributor);

    /**
     * @dev Emitted when the maximum contribution amount is set for the ILO.
     * @param amount The new maximum contribution amount.
     */
    event MaxContributionSet(uint amount);

    /**
     * @dev Emitted when the token price is set for the ILO.
     * @param price The new token price.
     */
    event PriceSet(uint256 price);

    /**
     * @dev Emitted when the status of the ILO is set.
     * @param _saleStatus The new status of the ILO.
     */
    event ILOStatusSet(uint256 _saleStatus);

    /**
     * @dev Emitted when the discount for the ILO is set.
     * @param _discount The new discount for the ILO.
     */
    event SetDiscount(uint256 _discount);

    /**
     * @dev Emitted when the bonus tokens for trading in are set.
     * @param _bonusForTrade The new bonus percentage for trading in your tokens
     */
    event SetBonusForTradeIn(uint256 _bonusForTrade);

    /**
     * @dev Emitted when the owner withdraws the contributions.
     * @param _contributionWithdrawn The amount of contributions withdrawn
     */
    event ContributionsWithdrawn(uint256 _contributionWithdrawn);

    /**
     * @dev Emitted when the owner deposits tokens for the airdrop.
     * @param _amount The amount of tokens deposited
     */
    event TokensDepositedForAirdrop(uint256 _amount);

    /**
     * @dev Emitted when the owner withdraws
     * @param _amount The amount of tokens withdrawn
     */
    event TokensWithdrawn(address _address, uint256 _amount);

    /**
     * @dev Emitted when a user claims their airdrop tokens.
     * @param _address The address of the user
     * @param _amount The amount of tokens withdrawn
     */
    event AirdropClaimed(address _address, uint256 _amount);

    /**
     * @dev Emitted when owner sets _claimable to true
     * @param _claimable The new claimable status
     */
    event SetClaimable(bool _claimable);

    /**
     * @dev Emitted when owner sets _squidGrowAddress
     * @param _squidGrowAddress The new squidgrow address
     */
    event SquidGrowAddressSet(address _squidGrowAddress);

    constructor(
        address _squidGrowToken
    ) ERC20("SquidGrow AirDrop IOU", "SGIOU") {
        if (_squidGrowToken == address(0)) revert IsZeroAddress();
        squidGrowToken = _squidGrowToken;
    }

    /**
     * @dev Sets the discount for the ILO.
     * @param _discount The new discount to be set.
     */
    function setDiscount(uint256 _discount) external onlyOwner {
        if (_discount > 10000) revert OutOfRange();
        discount = _discount;
        emit SetDiscount(discount);
    }

    /**
     * @dev Sets the squidgrow token for the ILO.
     * @param _squidGrowToken The new token address
     */
    function setSquidGrowToken(address _squidGrowToken) external onlyOwner {
        if (_squidGrowToken == address(0)) revert IsZeroAddress();
        squidGrowToken = _squidGrowToken;
        emit SquidGrowAddressSet(squidGrowToken);
    }

    /**
     * @dev Sets the status of the ILO.
     * @param _status The new status to be set.
     */
    function setILOStatus(ILOStatus _status) external onlyOwner {
        status = _status;
        emit ILOStatusSet(uint256(status));
    }

    /**
     * @dev Sets the merkle root for the ILO.
     * @param _merkleRoot The new merkle root to be set.
     */
    function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner {
        merkleRoot = _merkleRoot;
        emit MerkleRootSet(merkleRoot);
    }

    /**
     * @dev Sets the maximum contribution amount for the ILO.
     * @param _maxContribution The new maximum contribution amount to be set.
     * @dev Reverts if the new maximum contribution is less than or equal to zero.
     */
    function setMaxContribution(uint256 _maxContribution) external onlyOwner {
        if (_maxContribution == 0) revert InvalidAmount();
        maxContribution = _maxContribution;
        emit MaxContributionSet(maxContribution);
    }

    /**
     * @dev Sets the exchange rate for the ILO.
     * @param _exchangeRate The new exchange rate to be set.
     * @dev Reverts if the exchange rate is less than or equal to zero.
     */
    function setExchangeRate(uint256 _exchangeRate) external onlyOwner {
        if (_exchangeRate == 0) revert InvalidAmount();
        exchangeRate = _exchangeRate;
        emit PriceSet(exchangeRate);
    }

    /**
     * @dev Checks if the given address is whitelisted for the ILO using a Merkle proof.
     * @param _merkleProof The Merkle proof to check the address against.
     * @param _address The address to check for whitelisting.
     * @return true if the address is whitelisted, false otherwise.
     */
    function isWhitelisted(
        bytes32[] calldata _merkleProof,
        address _address
    ) public view returns (bool) {
        bytes32 leaf = keccak256(abi.encodePacked(_address));
        return MerkleProof.verifyCalldata(_merkleProof, merkleRoot, leaf);
    }

    /**
     * @dev Internal function to mint and send tokens to the user based on their contribution.
     * @return tokenAmount that have been minted and sent to the user.
     * @dev Reverts if the sent ether value is less than or equal to zero.
     * @dev Reverts if the sent ether value exceeds the maximum contribution limit.
     * @dev Reverts if the calculated token amount to be minted exceeds the available balance.
     * @dev Reverts if the total contribution amount for the user exceeds the individual maximum contribution limit.
     * @dev Emits a `Contribution` event with the number of tokens and the contributor's address.
     */
    function sendTokens() internal returns (uint256 tokenAmount) {
        if (msg.value == 0) revert InvalidAmount();

        if (
            publicContributions[msg.sender] +
                whitelistContributions[msg.sender] +
                msg.value >
            maxContribution
        ) revert IndividualMaxContributionReached();

        // Calculate the number of tokens to be minted based on the amount of ether sent by the user and the exchange rate
        tokenAmount = (msg.value * exchangeRate) / 10 ** 10;

        // Apply the discount
        uint256 discountedTokenAmount = (tokenAmount * discount) / 10000;
        tokenAmount += discountedTokenAmount;

        totalContributionsTokens += tokenAmount;
        totalContributions += msg.value;

        if (tokenAmount > ERC20(squidGrowToken).balanceOf(address(this)))
            revert MaxContributionReached();
        // Transfer the tokens to the user
        ERC20(squidGrowToken).safeTransfer(msg.sender, tokenAmount);
        emit Contribution(tokenAmount, msg.sender);
    }

    /**
     * @dev Allows users to contribute to the ILO during the public sale period.
     * @return tokenAmount that have been minted and sent to the user.
     * @dev Reverts if the ILO status is not set to `Public`.
     * @dev Uses the `sendTokens` internal function to mint and send tokens to the user based on their contribution.
     * @dev Emits a `Contribution` event with the number of tokens and the contributor's address.
     */
    function publicContribution()
        external
        payable
        nonReentrant
        returns (uint256 tokenAmount)
    {
        if (publicContributions[msg.sender] >= maxContribution)
            revert IndividualMaxContributionReached();
        if (status != ILOStatus.Public) revert PublicSaleNotActive();
        publicContributions[msg.sender] += msg.value;
        tokenAmount = sendTokens();
    }

    /**
     * @dev Allows whitelisted users to contribute to the ILO during the whitelist sale period using a Merkle proof.
     * @param _merkleProof The Merkle proof to check the user's address against.
     * @return tokenAmount that have been minted and sent to the user.
     * @dev Reverts if the ILO status is not set to `Whitelist`.
     * @dev Reverts if the user's address is not whitelisted.
     * @dev Reverts if the total contribution amount for the user exceeds the individual maximum contribution limit.
     * @dev Uses the `sendTokens` internal function to mint and send tokens to the user based on their contribution.
     * @dev Emits a `Contribution` event with the number of tokens and the contributor's address.
     */
    function whitelistContribution(
        bytes32[] calldata _merkleProof
    ) external payable nonReentrant returns (uint256 tokenAmount) {
        if (whitelistContributions[msg.sender] >= maxContribution)
            revert IndividualMaxContributionReached();
        if (status != ILOStatus.Whitelist) revert WhitelistSaleNotActive();
        if (!isWhitelisted(_merkleProof, msg.sender)) revert NotWhitelisted();

        whitelistContributions[msg.sender] += msg.value;
        tokenAmount = sendTokens();
    }

    /**
     * @dev Allows the owner of the contract to withdraw the total contribution amount.
     * @dev Sends the entire balance of the contract to the owner's address.
     * @dev Reverts if the caller is not the owner of the contract.
     */
    function withdrawContribtions() external onlyOwner {
        payable(owner()).sendValue(address(this).balance);
        emit ContributionsWithdrawn(address(this).balance);
    }

    /**
     * @dev Allows the owner of the contract to withdraw any remaining tokens in the contract.
     * @dev Transfers the entire balance of the contract's `squidGrowtoken` tokens to the owner's address.
     * @dev Reverts if the caller is not the owner of the contract.
     * @dev Reverts if the token transfer fails.
     */
    function withdrawTokens() external onlyOwner {
        ERC20(squidGrowToken).safeTransfer(
            msg.sender,
            ERC20(squidGrowToken).balanceOf(address(this))
        );
        emit TokensWithdrawn(
            squidGrowToken,
            ERC20(squidGrowToken).balanceOf(address(this))
        );
    }

    /**
     * @dev Allows the owner of the contract to emergency withdraw any ERC20 tokens held by the contract.
     * @param token The address of the ERC20 token to withdraw.
     * @dev Transfers the entire balance of the specified token held by the contract to the owner's address.
     * @dev Reverts if the caller is not the owner of the contract.
     * @dev Reverts if the token transfer from the contract fails.
     */
    function emergencyWithdraw(address token) external onlyOwner {
        ERC20(token).safeTransfer(
            msg.sender,
            ERC20(token).balanceOf(address(this))
        );
        emit TokensWithdrawn(token, ERC20(token).balanceOf(address(this)));
    }

    ////   ----------  Trade IN   ----------   ////
    uint256 public bonusForTradeIn = 300;

    /**
     * @dev Sets the bonus for trade in.
     * @param _bonusForTradeIn The new bonus for trade in to be set.
     */
    function setBonusForTradeIn(uint256 _bonusForTradeIn) external onlyOwner {
        if (_bonusForTradeIn > 10000) revert OutOfRange();
        bonusForTradeIn = _bonusForTradeIn;
        emit SetBonusForTradeIn(_bonusForTradeIn);
    }

    /**
     * @dev Allows the users to offer their tokens in exchange for an IOU to a later airdrop on ETH with a 3% bonus.
     * @param amount The amount of tokens to offer.
     * @dev Transfers the tokens from the user to the contract and mints the IOU tokens to the user.
     */
    function depositTokensForAirdrop(uint256 amount) external nonReentrant {
        ERC20(squidGrowToken).safeTransferFrom(
            msg.sender,
            address(this),
            amount
        );
        uint256 extraTokens = (amount * bonusForTradeIn) / 10000;
        uint256 amountToMint = amount + extraTokens;
        _mint(msg.sender, amountToMint);
        emit TokensDepositedForAirdrop(amount);
    }

    /**
     * @dev Overrides the `decimals` function to set the number of decimals to 19. Same as the SquidGrow Token on BSC
     */
    function decimals() public view virtual override returns (uint8) {
        return 19;
    }

    /**
     * @dev Sets the claimable variable, which determines if the airdrop is currently claimable.
     * @param _claimable Whether the airdrop should be claimable or not.
     */
    function setClaimable(bool _claimable) external onlyOwner {
        claimable = _claimable;
        emit SetClaimable(_claimable);
    }

    /**
     * @dev Checks if a specific index has been claimed.
     * @param index The index to check.
     * @return A boolean indicating whether the index has been claimed or not.
     */
    function isClaimed(uint256 index) public view returns (bool) {
        uint256 claimedWordIndex = index / 256;
        uint256 claimedBitIndex = index % 256;
        uint256 claimedWord = claimedBitMap[claimedWordIndex];
        uint256 mask = (1 << claimedBitIndex);
        return claimedWord & mask == mask;
    }

    /**
     * @dev Sets a specific index as claimed.
     * @param index The index to set as claimed.
     */
    function _setClaimed(uint256 index) private {
        uint256 claimedWordIndex = index / 256;
        uint256 claimedBitIndex = index % 256;
        claimedBitMap[claimedWordIndex] =
            claimedBitMap[claimedWordIndex] |
            (1 << claimedBitIndex);
    }

    /**
     * @dev Claims the airdrop for a specific index, transferring the specified amount of tokens to the caller.
     * @param index The index of the airdrop to claim.
     * @param amount The amount of tokens to claim.
     * @param merkleProof The Merkle proof for the claim.
     */
    function claimAirdrop(
        uint256 index,
        uint256 amount,
        bytes32[] calldata merkleProof
    ) external {
        if (isClaimed(index)) {
            revert AlreadyClaimed();
        }

        if (!claimable) {
            revert ClaimNotActive();
        }

        if (!isWhitelistedForAirdrop(index, msg.sender, amount, merkleProof)) {
            revert IsNotWhitelisted();
        }

        _setClaimed(index);

        ERC20(squidGrowToken).safeTransfer(msg.sender, amount);

        emit AirdropClaimed(msg.sender, amount);
    }

    /**
     * @dev Checks if an account is whitelisted for the airdrop.
     * @param index The index of the airdrop.
     * @param account The account to check.
     * @param amount The amount of tokens.
     * @param merkleProof The Merkle proof for the claim.
     * @return A boolean indicating whether the account is whitelisted or not.
     */
    function isWhitelistedForAirdrop(
        uint256 index,
        address account,
        uint256 amount,
        bytes32[] calldata merkleProof
    ) public view returns (bool) {
        bytes32 leaf = keccak256(abi.encodePacked(index, account, amount));
        bool isValidProof = MerkleProof.verifyCalldata(
            merkleProof,
            merkleRoot,
            leaf
        );
        return isValidProof;
    }
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
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);
    }
}
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 {}
}
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);
}
ReentrancyGuard.sol 69 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

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

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

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

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

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

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

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

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

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

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

pragma solidity ^0.8.0;

/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The tree and the proofs can be generated using our
 * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
 * You will find a quickstart guide in the readme.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the merkle tree could be reinterpreted as a leaf value.
 * OpenZeppelin's JavaScript library generates merkle trees that are safe
 * against this attack out of the box.
 */
library MerkleProof {
    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     */
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Calldata version of {verify}
     *
     * _Available since v4.7._
     */
    function verifyCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leafs & pre-images are assumed to be sorted.
     *
     * _Available since v4.4._
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Calldata version of {processProof}
     *
     * _Available since v4.7._
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * _Available since v4.7._
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Calldata version of {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
        return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
    }

    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}
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-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

allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
bonusForTradeIn 0x6d486497 → uint256
claimable 0xaf38d757 → bool
decimals 0x313ce567 → uint8
discount 0x6b6f4a9d → uint256
exchangeRate 0x3ba0b9a9 → uint256
isClaimed 0x9e34070f → bool
isWhitelisted 0xdebefaa6 → bool
isWhitelistedForAirdrop 0x983731c1 → bool
maxContribution 0x8d3d6576 → uint256
merkleRoot 0x2eb4a7ab → bytes32
name 0x06fdde03 → string
owner 0x8da5cb5b → address
publicContributions 0x6dfc9926 → uint256
squidGrowToken 0x0df9e166 → address
status 0x200d2ed2 → uint8
symbol 0x95d89b41 → string
totalContributions 0x37c08923 → uint256
totalContributionsTokens 0x64f2b4ff → uint256
totalSupply 0x18160ddd → uint256
whitelistContributions 0x423e1c3d → uint256

Write Contract 22 functions

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

approve 0x095ea7b3
address spender
uint256 amount
returns: bool
claimAirdrop 0x5a95ba34
uint256 index
uint256 amount
bytes32[] merkleProof
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
depositTokensForAirdrop 0x20d9e533
uint256 amount
emergencyWithdraw 0x6ff1c9bc
address token
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
publicContribution 0x887c5b06
No parameters
returns: uint256
renounceOwnership 0x715018a6
No parameters
setBonusForTradeIn 0x667bfc20
uint256 _bonusForTradeIn
setClaimable 0x378c93ad
bool _claimable
setDiscount 0xdabd2719
uint256 _discount
setExchangeRate 0xdb068e0e
uint256 _exchangeRate
setILOStatus 0xb12ebc9d
uint8 _status
setMaxContribution 0x03ed9d21
uint256 _maxContribution
setMerkleRoot 0x7cb64759
bytes32 _merkleRoot
setSquidGrowToken 0xeeb69d41
address _squidGrowToken
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner
whitelistContribution 0x60d3bee2
bytes32[] _merkleProof
returns: uint256
withdrawContribtions 0x213ec7bd
No parameters
withdrawTokens 0x8d8f2adb
No parameters

Recent Transactions

No transactions found for this address