Address Contract Verified
Address
0xC1cdbC8De51D5cf3d9300AD66739d1B75441c4cE
Balance
0 ETH
Nonce
1
Code Size
20426 bytes
Creator
0x15Ee672c...C0b4 at tx 0x2c7b1b97...6f607b
Indexed Transactions
0
Contract Bytecode
20426 bytes
0x6080604052600436106102045760003560e01c806387bd14bf11610118578063b88d4fde116100a0578063d547741f1161006f578063d547741f14610741578063d8258d951461076a578063e4c0cd9014610795578063e985e9c5146107b1578063f81227d4146107ee57610204565b8063b88d4fde14610685578063c87b56dd146106ae578063d2d8cb67146106eb578063d53913931461071657610204565b8063a0bcfc7f116100e7578063a0bcfc7f146105c6578063a217fddf146105ef578063a22cb4651461061a578063a475b5dd14610643578063b69ef8a81461065a57610204565b806387bd14bf1461050857806391d148541461053357806395d89b41146105705780639d044ed31461059b57610204565b80632f2ff15d1161019b5780633ccfd60b1161016a5780633ccfd60b1461042357806342842e0e1461043a578063564566a8146104635780636352211e1461048e57806370a08231146104cb57610204565b80632f2ff15d1461039157806334918dfd146103ba57806336568abe146103d157806339600e21146103fa57610204565b80630fe09700116101d75780630fe09700146102d75780631067fcc71461030257806323b872dd1461032b578063248a9ca31461035457610204565b806301ffc9a71461020957806306fdde0314610246578063081812fc14610271578063095ea7b3146102ae575b600080fd5b34801561021557600080fd5b50610230600480360381019061022b91906132a6565b610805565b60405161023d91906132ee565b60405180910390f35b34801561025257600080fd5b5061025b610817565b60405161026891906133a2565b60405180910390f35b34801561027d57600080fd5b50610298600480360381019061029391906133fa565b6108a9565b6040516102a59190613468565b60405180910390f35b3480156102ba57600080fd5b506102d560048036038101906102d091906134af565b61092e565b005b3480156102e357600080fd5b506102ec610a46565b6040516102f991906134fe565b60405180910390f35b34801561030e57600080fd5b506103296004803603810190610324919061364e565b610a4b565b005b34801561033757600080fd5b50610352600480360381019061034d9190613697565b610a98565b005b34801561036057600080fd5b5061037b60048036038101906103769190613720565b610af8565b604051610388919061375c565b60405180910390f35b34801561039d57600080fd5b506103b860048036038101906103b39190613777565b610b18565b005b3480156103c657600080fd5b506103cf610b41565b005b3480156103dd57600080fd5b506103f860048036038101906103f39190613777565b610bd1565b005b34801561040657600080fd5b50610421600480360381019061041c91906133fa565b610c54565b005b34801561042f57600080fd5b50610438610d58565b005b34801561044657600080fd5b50610461600480360381019061045c9190613697565b610e2b565b005b34801561046f57600080fd5b50610478610e4b565b60405161048591906132ee565b60405180910390f35b34801561049a57600080fd5b506104b560048036038101906104b091906133fa565b610e5e565b6040516104c29190613468565b60405180910390f35b3480156104d757600080fd5b506104f260048036038101906104ed91906137b7565b610f10565b6040516104ff91906134fe565b60405180910390f35b34801561051457600080fd5b5061051d610fc8565b60405161052a91906134fe565b60405180910390f35b34801561053f57600080fd5b5061055a60048036038101906105559190613777565b610fcd565b60405161056791906132ee565b60405180910390f35b34801561057c57600080fd5b50610585611038565b60405161059291906133a2565b60405180910390f35b3480156105a757600080fd5b506105b06110ca565b6040516105bd91906132ee565b60405180910390f35b3480156105d257600080fd5b506105ed60048036038101906105e8919061364e565b6110dd565b005b3480156105fb57600080fd5b5061060461112a565b604051610611919061375c565b60405180910390f35b34801561062657600080fd5b50610641600480360381019061063c9190613810565b611131565b005b34801561064f57600080fd5b506106586112b2565b005b34801561066657600080fd5b5061066f611302565b60405161067c91906134fe565b60405180910390f35b34801561069157600080fd5b506106ac60048036038101906106a791906138f1565b61130a565b005b3480156106ba57600080fd5b506106d560048036038101906106d091906133fa565b61136c565b6040516106e291906133a2565b60405180910390f35b3480156106f757600080fd5b50610700611514565b60405161070d91906134fe565b60405180910390f35b34801561072257600080fd5b5061072b61151f565b604051610738919061375c565b60405180910390f35b34801561074d57600080fd5b5061076860048036038101906107639190613777565b611543565b005b34801561077657600080fd5b5061077f61156c565b60405161078c91906134fe565b60405180910390f35b6107af60048036038101906107aa9190613998565b611572565b005b3480156107bd57600080fd5b506107d860048036038101906107d39190613a07565b611990565b6040516107e591906132ee565b60405180910390f35b3480156107fa57600080fd5b50610803611a24565b005b600061081082611a83565b9050919050565b60606000805461082690613a76565b80601f016020809104026020016040519081016040528092919081815260200182805461085290613a76565b801561089f5780601f106108745761010080835404028352916020019161089f565b820191906000526020600020905b81548152906001019060200180831161088257829003601f168201915b5050505050905090565b60006108b482611afd565b6108f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108ea90613b1a565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b600061093982610e5e565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156109aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109a190613bac565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166109c9611b69565b73ffffffffffffffffffffffffffffffffffffffff1614806109f857506109f7816109f2611b69565b611990565b5b610a37576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a2e90613c3e565b60405180910390fd5b610a418383611b71565b505050565b600381565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610a7d81610a78611b69565b611c2a565b8160099080519060200190610a93929190613197565b505050565b610aa9610aa3611b69565b82611cc7565b610ae8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610adf90613cd0565b60405180910390fd5b610af3838383611da5565b505050565b600060066000838152602001908152602001600020600101549050919050565b610b2182610af8565b610b3281610b2d611b69565b611c2a565b610b3c8383612001565b505050565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610b7381610b6e611b69565b611c2a565b600860009054906101000a900460ff1615600860006101000a81548160ff021916908315150217905550600860009054906101000a900460ff1615610bce576000600860016101000a81548160ff0219169083151502179055505b50565b610bd9611b69565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610c46576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c3d90613d62565b60405180910390fd5b610c5082826120e2565b5050565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610c8681610c81611b69565b611c2a565b600c54821115610ccb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cc290613dce565b60405180910390fd5b6000610cd760076121c4565b90505b82811015610d3a57610cec60076121d2565b6000610cf860076121c4565b9050610d26600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16826121e8565b508080610d3290613e1d565b915050610cda565b5081600c6000828254610d4d9190613e66565b925050819055505050565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610d8a81610d85611b69565b611c2a565b6000610d94611302565b11610dd4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dcb90613ee6565b60405180910390fd5b60003390508073ffffffffffffffffffffffffffffffffffffffff166108fc610dfb611302565b9081150290604051600060405180830381858888f19350505050158015610e26573d6000803e3d6000fd5b505050565b610e468383836040518060200160405280600081525061130a565b505050565b600860009054906101000a900460ff1681565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610f07576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610efe90613f78565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610f81576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f789061400a565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600581565b60006006600084815260200190815260200160002060000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b60606001805461104790613a76565b80601f016020809104026020016040519081016040528092919081815260200182805461107390613a76565b80156110c05780601f10611095576101008083540402835291602001916110c0565b820191906000526020600020905b8154815290600101906020018083116110a357829003601f168201915b5050505050905090565b600860019054906101000a900460ff1681565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a661110f8161110a611b69565b611c2a565b81600a9080519060200190611125929190613197565b505050565b6000801b81565b611139611b69565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156111a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161119e90614076565b60405180910390fd5b80600560006111b4611b69565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16611261611b69565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516112a691906132ee565b60405180910390a35050565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a66112e4816112df611b69565b611c2a565b6001600860026101000a81548160ff02191690831515021790555050565b600047905090565b61131b611315611b69565b83611cc7565b61135a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161135190613cd0565b60405180910390fd5b61136684848484612206565b50505050565b606061137782611afd565b6113b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ad90614108565b60405180910390fd5b60006113c0612262565b9050600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061142a5750600860029054906101000a900460ff165b1561148057600081511161144d5760405180602001604052806000815250611478565b80611457846122f4565b6040516020016114689291906141b0565b6040516020818303038152906040525b91505061150f565b6009805461148d90613a76565b80601f01602080910402602001604051908101604052809291908181526020018280546114b990613a76565b80156115065780601f106114db57610100808354040283529160200191611506565b820191906000526020600020905b8154815290600101906020018083116114e957829003601f168201915b50505050509150505b919050565b66e6ed27d666800081565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a681565b61154c82610af8565b61155d81611558611b69565b611c2a565b61156783836120e2565b505050565b6115b381565b6115858261157f85612455565b836124db565b6115c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115bb90614251565b60405180910390fd5b600860019054906101000a900460ff1615611718578260200160208101906115ec9190614271565b61162b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161162290614310565b60405180910390fd5b60038360400135111561163e60036122f4565b60405160200161164e91906143ee565b6040516020818303038152906040529061169e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161169591906133a2565b60405180910390fd5b5060036116d284604001356116c48660000160208101906116bf91906137b7565b610f10565b61252390919063ffffffff16565b1115611713576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161170a9061448d565b60405180910390fd5b611768565b600860009054906101000a900460ff16611767576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161175e906144f9565b60405180910390fd5b5b6115b361177560076121c4565b106117b5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117ac90614565565b60405180910390fd5b6115b36117d884604001356117ca60076121c4565b61252390919063ffffffff16565b10611818576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161180f906145d1565b60405180910390fd5b600561183584600001602081019061183091906137b7565b610f10565b1061184060056122f4565b604051602001611850919061463d565b604051602081830303815290604052906118a0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161189791906133a2565b60405180910390fd5b5060056118d484604001356118c68660000160208101906118c191906137b7565b610f10565b61252390919063ffffffff16565b10611914576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161190b9061448d565b60405180910390fd5b60005b836040013581101561198a576115b361193060076121c4565b10156119775761194060076121d2565b600061194c60076121c4565b905061195884826121e8565b6119758486600001602081019061196f91906137b7565b83611da5565b505b808061198290613e1d565b915050611917565b50505050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6611a5681611a51611b69565b611c2a565b600860019054906101000a900460ff1615600860016101000a81548160ff02191690831515021790555050565b60007f7965db0b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161480611af65750611af582612539565b5b9050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16611be483610e5e565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b611c348282610fcd565b611cc357611c598173ffffffffffffffffffffffffffffffffffffffff16601461261b565b611c678360001c602061261b565b604051602001611c78929190614702565b6040516020818303038152906040526040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611cba91906133a2565b60405180910390fd5b5050565b6000611cd282611afd565b611d11576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d08906147ae565b60405180910390fd5b6000611d1c83610e5e565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480611d8b57508373ffffffffffffffffffffffffffffffffffffffff16611d73846108a9565b73ffffffffffffffffffffffffffffffffffffffff16145b80611d9c5750611d9b8185611990565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff16611dc582610e5e565b73ffffffffffffffffffffffffffffffffffffffff1614611e1b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e1290614840565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611e8b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e82906148d2565b60405180910390fd5b611e96838383612857565b611ea1600082611b71565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611ef19190613e66565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611f4891906148f2565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b61200b8282610fcd565b6120de5760016006600084815260200190815260200160002060000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550612083611b69565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b6120ec8282610fcd565b156121c05760006006600084815260200190815260200160002060000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550612165611b69565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45b5050565b600081600001549050919050565b6001816000016000828254019250508190555050565b61220282826040518060200160405280600081525061285c565b5050565b612211848484611da5565b61221d848484846128b7565b61225c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612253906149ba565b60405180910390fd5b50505050565b6060600a805461227190613a76565b80601f016020809104026020016040519081016040528092919081815260200182805461229d90613a76565b80156122ea5780601f106122bf576101008083540402835291602001916122ea565b820191906000526020600020905b8154815290600101906020018083116122cd57829003601f168201915b5050505050905090565b6060600082141561233c576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050612450565b600082905060005b6000821461236e57808061235790613e1d565b915050600a826123679190614a09565b9150612344565b60008167ffffffffffffffff81111561238a57612389613523565b5b6040519080825280601f01601f1916602001820160405280156123bc5781602001600182028036833780820191505090505b5090505b60008514612449576001826123d59190613e66565b9150600a856123e49190614a3a565b60306123f091906148f2565b60f81b81838151811061240657612405614a6b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a856124429190614a09565b94506123c0565b8093505050505b919050565b60006124d47ff3e3f00f9f9d901469bec6d678277fadd287b83b2277284d690daeede462eeb783600001602081019061248e91906137b7565b8460200160208101906124a19190614271565b85604001356040516020016124b99493929190614a9a565b60405160208183030381529060405280519060200120612a3f565b9050919050565b60006125077f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a685610fcd565b801561251a5750612519848484612a59565b5b90509392505050565b6000818361253191906148f2565b905092915050565b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061260457507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b80612614575061261382612c3e565b5b9050919050565b60606000600283600261262e9190614adf565b61263891906148f2565b67ffffffffffffffff81111561265157612650613523565b5b6040519080825280601f01601f1916602001820160405280156126835781602001600182028036833780820191505090505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106126bb576126ba614a6b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061271f5761271e614a6b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000600184600261275f9190614adf565b61276991906148f2565b90505b6001811115612809577f3031323334353637383961626364656600000000000000000000000000000000600f8616601081106127ab576127aa614a6b565b5b1a60f81b8282815181106127c2576127c1614a6b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600485901c94508061280290614b39565b905061276c565b506000841461284d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161284490614baf565b60405180910390fd5b8091505092915050565b505050565b6128668383612ca8565b61287360008484846128b7565b6128b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016128a9906149ba565b60405180910390fd5b505050565b60006128d88473ffffffffffffffffffffffffffffffffffffffff16612e76565b15612a32578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02612901611b69565b8786866040518563ffffffff1660e01b81526004016129239493929190614c24565b6020604051808303816000875af192505050801561295f57506040513d601f19601f8201168201806040525081019061295c9190614c85565b60015b6129e2573d806000811461298f576040519150601f19603f3d011682016040523d82523d6000602084013e612994565b606091505b506000815114156129da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016129d1906149ba565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050612a37565b600190505b949350505050565b6000612a52612a4c612e89565b83612f4c565b9050919050565b6000806000612a688585612f7f565b9150915060006004811115612a8057612a7f614cb2565b5b816004811115612a9357612a92614cb2565b5b148015612acb57508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b15612adb57600192505050612c37565b6000808773ffffffffffffffffffffffffffffffffffffffff16631626ba7e60e01b8888604051602401612b10929190614ce1565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051612b7a9190614d4d565b600060405180830381855afa9150503d8060008114612bb5576040519150601f19603f3d011682016040523d82523d6000602084013e612bba565b606091505b5091509150818015612bcd575060208151145b8015612c305750631626ba7e60e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191681806020019051810190612c0f9190614c85565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b9450505050505b9392505050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612d18576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d0f90614db0565b60405180910390fd5b612d2181611afd565b15612d61576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d5890614e1c565b60405180910390fd5b612d6d60008383612857565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254612dbd91906148f2565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b600080823b905060008111915050919050565b60007f0000000000000000000000000000000000000000000000000000000000000001461415612edb577f5d841c306eaa3518f02de2c4eadedb0817baa9441da3e26a12439621e8f6929d9050612f49565b612f467f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7ff7272349b2fdea7a1a1dd3b5628985ccf2ca17dcd081eb834d9ff800dde92deb7fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6613002565b90505b90565b60008282604051602001612f61929190614ea9565b60405160208183030381529060405280519060200120905092915050565b600080604183511415612fc15760008060006020860151925060408601519150606086015160001a9050612fb58782858561303c565b94509450505050612ffb565b604083511415612ff2576000806020850151915060408501519050612fe7868383613149565b935093505050612ffb565b60006002915091505b9250929050565b6000838383463060405160200161301d959493929190614ee0565b6040516020818303038152906040528051906020012090509392505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08360001c1115613077576000600391509150613140565b601b8560ff161415801561308f5750601c8560ff1614155b156130a1576000600491509150613140565b6000600187878787604051600081526020016040526040516130c69493929190614f4f565b6020604051602081039080840390855afa1580156130e8573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561313757600060019250925050613140565b80600092509250505b94509492505050565b6000806000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85169150601b8560ff1c0190506131898782888561303c565b935093505050935093915050565b8280546131a390613a76565b90600052602060002090601f0160209004810192826131c5576000855561320c565b82601f106131de57805160ff191683800117855561320c565b8280016001018555821561320c579182015b8281111561320b5782518255916020019190600101906131f0565b5b509050613219919061321d565b5090565b5b8082111561323657600081600090555060010161321e565b5090565b6000604051905090565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6132838161324e565b811461328e57600080fd5b50565b6000813590506132a08161327a565b92915050565b6000602082840312156132bc576132bb613244565b5b60006132ca84828501613291565b91505092915050565b60008115159050919050565b6132e8816132d3565b82525050565b600060208201905061330360008301846132df565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015613343578082015181840152602081019050613328565b83811115613352576000848401525b50505050565b6000601f19601f8301169050919050565b600061337482613309565b61337e8185613314565b935061338e818560208601613325565b61339781613358565b840191505092915050565b600060208201905081810360008301526133bc8184613369565b905092915050565b6000819050919050565b6133d7816133c4565b81146133e257600080fd5b50565b6000813590506133f4816133ce565b92915050565b6000602082840312156134105761340f613244565b5b600061341e848285016133e5565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061345282613427565b9050919050565b61346281613447565b82525050565b600060208201905061347d6000830184613459565b92915050565b61348c81613447565b811461349757600080fd5b50565b6000813590506134a981613483565b92915050565b600080604083850312156134c6576134c5613244565b5b60006134d48582860161349a565b92505060206134e5858286016133e5565b9150509250929050565b6134f8816133c4565b82525050565b600060208201905061351360008301846134ef565b92915050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61355b82613358565b810181811067ffffffffffffffff8211171561357a57613579613523565b5b80604052505050565b600061358d61323a565b90506135998282613552565b919050565b600067ffffffffffffffff8211156135b9576135b8613523565b5b6135c282613358565b9050602081019050919050565b82818337600083830152505050565b60006135f16135ec8461359e565b613583565b90508281526020810184848401111561360d5761360c61351e565b5b6136188482856135cf565b509392505050565b600082601f83011261363557613634613519565b5b81356136458482602086016135de565b91505092915050565b60006020828403121561366457613663613244565b5b600082013567ffffffffffffffff81111561368257613681613249565b5b61368e84828501613620565b91505092915050565b6000806000606084860312156136b0576136af613244565b5b60006136be8682870161349a565b93505060206136cf8682870161349a565b92505060406136e0868287016133e5565b9150509250925092565b6000819050919050565b6136fd816136ea565b811461370857600080fd5b50565b60008135905061371a816136f4565b92915050565b60006020828403121561373657613735613244565b5b60006137448482850161370b565b91505092915050565b613756816136ea565b82525050565b6000602082019050613771600083018461374d565b92915050565b6000806040838503121561378e5761378d613244565b5b600061379c8582860161370b565b92505060206137ad8582860161349a565b9150509250929050565b6000602082840312156137cd576137cc613244565b5b60006137db8482850161349a565b91505092915050565b6137ed816132d3565b81146137f857600080fd5b50565b60008135905061380a816137e4565b92915050565b6000806040838503121561382757613826613244565b5b60006138358582860161349a565b9250506020613846858286016137fb565b9150509250929050565b600067ffffffffffffffff82111561386b5761386a613523565b5b61387482613358565b9050602081019050919050565b600061389461388f84613850565b613583565b9050828152602081018484840111156138b0576138af61351e565b5b6138bb8482856135cf565b509392505050565b600082601f8301126138d8576138d7613519565b5b81356138e8848260208601613881565b91505092915050565b6000806000806080858703121561390b5761390a613244565b5b60006139198782880161349a565b945050602061392a8782880161349a565b935050604061393b878288016133e5565b925050606085013567ffffffffffffffff81111561395c5761395b613249565b5b613968878288016138c3565b91505092959194509250565b600080fd5b60006060828403121561398f5761398e613974565b5b81905092915050565b600080600060a084860312156139b1576139b0613244565b5b60006139bf86828701613979565b93505060606139d08682870161349a565b925050608084013567ffffffffffffffff8111156139f1576139f0613249565b5b6139fd868287016138c3565b9150509250925092565b60008060408385031215613a1e57613a1d613244565b5b6000613a2c8582860161349a565b9250506020613a3d8582860161349a565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680613a8e57607f821691505b60208210811415613aa257613aa1613a47565b5b50919050565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b6000613b04602c83613314565b9150613b0f82613aa8565b604082019050919050565b60006020820190508181036000830152613b3381613af7565b9050919050565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b6000613b96602183613314565b9150613ba182613b3a565b604082019050919050565b60006020820190508181036000830152613bc581613b89565b9050919050565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b6000613c28603883613314565b9150613c3382613bcc565b604082019050919050565b60006020820190508181036000830152613c5781613c1b565b9050919050565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b6000613cba603183613314565b9150613cc582613c5e565b604082019050919050565b60006020820190508181036000830152613ce981613cad565b9050919050565b7f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560008201527f20726f6c657320666f722073656c660000000000000000000000000000000000602082015250565b6000613d4c602f83613314565b9150613d5782613cf0565b604082019050919050565b60006020820190508181036000830152613d7b81613d3f565b9050919050565b7f4f766572206c696d697400000000000000000000000000000000000000000000600082015250565b6000613db8600a83613314565b9150613dc382613d82565b602082019050919050565b60006020820190508181036000830152613de781613dab565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000613e28826133c4565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415613e5b57613e5a613dee565b5b600182019050919050565b6000613e71826133c4565b9150613e7c836133c4565b925082821015613e8f57613e8e613dee565b5b828203905092915050565b7f4e6f2062616c616e636500000000000000000000000000000000000000000000600082015250565b6000613ed0600a83613314565b9150613edb82613e9a565b602082019050919050565b60006020820190508181036000830152613eff81613ec3565b9050919050565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b6000613f62602983613314565b9150613f6d82613f06565b604082019050919050565b60006020820190508181036000830152613f9181613f55565b9050919050565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b6000613ff4602a83613314565b9150613fff82613f98565b604082019050919050565b6000602082019050818103600083015261402381613fe7565b9050919050565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b6000614060601983613314565b915061406b8261402a565b602082019050919050565b6000602082019050818103600083015261408f81614053565b9050919050565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b60006140f2602f83613314565b91506140fd82614096565b604082019050919050565b60006020820190508181036000830152614121816140e5565b9050919050565b600081905092915050565b600061413e82613309565b6141488185614128565b9350614158818560208601613325565b80840191505092915050565b7f2e6a736f6e000000000000000000000000000000000000000000000000000000600082015250565b600061419a600583614128565b91506141a582614164565b600582019050919050565b60006141bc8285614133565b91506141c88284614133565b91506141d38261418d565b91508190509392505050565b7f5472616e73616374696f6e206973206e6f7420617574686f72697a656420286960008201527f6e76616c6964207369676e617475726529000000000000000000000000000000602082015250565b600061423b603183613314565b9150614246826141df565b604082019050919050565b6000602082019050818103600083015261426a8161422e565b9050919050565b60006020828403121561428757614286613244565b5b6000614295848285016137fb565b91505092915050565b7f50726573616c65206973206f6e6c79206f70656e20746f2077686974656c697360008201527f7465642075736572730000000000000000000000000000000000000000000000602082015250565b60006142fa602983613314565b91506143058261429e565b604082019050919050565b60006020820190508181036000830152614329816142ed565b9050919050565b7f4d61782000000000000000000000000000000000000000000000000000000000600082015250565b6000614366600483614128565b915061437182614330565b600482019050919050565b7f20746f6b656e28732920706572207573657220647572696e672070726573616c60008201527f6500000000000000000000000000000000000000000000000000000000000000602082015250565b60006143d8602183614128565b91506143e38261437c565b602182019050919050565b60006143f982614359565b91506144058284614133565b9150614410826143cb565b915081905092915050565b7f507572636861736520776f756c6420657863656564206c696d6974207065722060008201527f7573657200000000000000000000000000000000000000000000000000000000602082015250565b6000614477602483613314565b91506144828261441b565b604082019050919050565b600060208201905081810360008301526144a68161446a565b9050919050565b7f53616c65206d7573742062652061637469766520746f206d696e740000000000600082015250565b60006144e3601b83613314565b91506144ee826144ad565b602082019050919050565b60006020820190508181036000830152614512816144d6565b9050919050565b7f416c6c20746f6b656e732068617665206265656e206d696e7465640000000000600082015250565b600061454f601b83613314565b915061455a82614519565b602082019050919050565b6000602082019050818103600083015261457e81614542565b9050919050565b7f507572636861736520776f756c6420657863656564206d617820737570706c79600082015250565b60006145bb602083613314565b91506145c682614585565b602082019050919050565b600060208201905081810360008301526145ea816145ae565b9050919050565b7f20746f6b656e2873292070657220757365720000000000000000000000000000600082015250565b6000614627601283614128565b9150614632826145f1565b601282019050919050565b600061464882614359565b91506146548284614133565b915061465f8261461a565b915081905092915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000600082015250565b60006146a0601783614128565b91506146ab8261466a565b601782019050919050565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000600082015250565b60006146ec601183614128565b91506146f7826146b6565b601182019050919050565b600061470d82614693565b91506147198285614133565b9150614724826146df565b91506147308284614133565b91508190509392505050565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b6000614798602c83613314565b91506147a38261473c565b604082019050919050565b600060208201905081810360008301526147c78161478b565b9050919050565b7f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008201527f73206e6f74206f776e0000000000000000000000000000000000000000000000602082015250565b600061482a602983613314565b9150614835826147ce565b604082019050919050565b600060208201905081810360008301526148598161481d565b9050919050565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b60006148bc602483613314565b91506148c782614860565b604082019050919050565b600060208201905081810360008301526148eb816148af565b9050919050565b60006148fd826133c4565b9150614908836133c4565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561493d5761493c613dee565b5b828201905092915050565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b60006149a4603283613314565b91506149af82614948565b604082019050919050565b600060208201905081810360008301526149d381614997565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000614a14826133c4565b9150614a1f836133c4565b925082614a2f57614a2e6149da565b5b828204905092915050565b6000614a45826133c4565b9150614a50836133c4565b925082614a6057614a5f6149da565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000608082019050614aaf600083018761374d565b614abc6020830186613459565b614ac960408301856132df565b614ad660608301846134ef565b95945050505050565b6000614aea826133c4565b9150614af5836133c4565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615614b2e57614b2d613dee565b5b828202905092915050565b6000614b44826133c4565b91506000821415614b5857614b57613dee565b5b600182039050919050565b7f537472696e67733a20686578206c656e67746820696e73756666696369656e74600082015250565b6000614b99602083613314565b9150614ba482614b63565b602082019050919050565b60006020820190508181036000830152614bc881614b8c565b9050919050565b600081519050919050565b600082825260208201905092915050565b6000614bf682614bcf565b614c008185614bda565b9350614c10818560208601613325565b614c1981613358565b840191505092915050565b6000608082019050614c396000830187613459565b614c466020830186613459565b614c5360408301856134ef565b8181036060830152614c658184614beb565b905095945050505050565b600081519050614c7f8161327a565b92915050565b600060208284031215614c9b57614c9a613244565b5b6000614ca984828501614c70565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6000604082019050614cf6600083018561374d565b8181036020830152614d088184614beb565b90509392505050565b600081905092915050565b6000614d2782614bcf565b614d318185614d11565b9350614d41818560208601613325565b80840191505092915050565b6000614d598284614d1c565b915081905092915050565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b6000614d9a602083613314565b9150614da582614d64565b602082019050919050565b60006020820190508181036000830152614dc981614d8d565b9050919050565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b6000614e06601c83613314565b9150614e1182614dd0565b602082019050919050565b60006020820190508181036000830152614e3581614df9565b9050919050565b7f1901000000000000000000000000000000000000000000000000000000000000600082015250565b6000614e72600283614128565b9150614e7d82614e3c565b600282019050919050565b6000819050919050565b614ea3614e9e826136ea565b614e88565b82525050565b6000614eb482614e65565b9150614ec08285614e92565b602082019150614ed08284614e92565b6020820191508190509392505050565b600060a082019050614ef5600083018861374d565b614f02602083018761374d565b614f0f604083018661374d565b614f1c60608301856134ef565b614f296080830184613459565b9695505050505050565b600060ff82169050919050565b614f4981614f33565b82525050565b6000608082019050614f64600083018761374d565b614f716020830186614f40565b614f7e604083018561374d565b614f8b606083018461374d565b9594505050505056fea26469706673582212205bdd41cbc2523d73fcbd674b612eb226ada27021de7299ea2fdb729974a4512064736f6c634300080a0033
Verified Source Code Full Match
Compiler: v0.8.10+commit.fc410830
EVM: london
Optimization: No
Minter.sol 186 lines
//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
contract BCBoys is ERC721, EIP712, AccessControl {
using Counters for Counters.Counter;
using Strings for uint256;
using Address for address;
using SafeMath for uint256;
Counters.Counter private _tokenIds;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
uint256 public constant TOKEN_PRICE = 65000000000000000; //0.065 ETH
uint256 public constant COLLECTION_SIZE = 5555;
uint public constant TOKEN_PER_PERSON_LIMIT = 5;
uint public constant PRESALE_TOKEN_PER_PERSON_LIMIT = 3;
bool public isSaleActive = false;
bool public isPreSaleActive = true;
bool private _canReveal = false;
string private _hiddenURI;
string private _baseUri;
address private _owner;
uint256 private RESERVED_TOKENS = 300;
constructor(string memory delayedRevealURI, string memory baseUri)
ERC721("BCBoys", "BBC")
EIP712("BCBoys", "1") {
_setupRole(MINTER_ROLE, msg.sender);
_hiddenURI = delayedRevealURI;
_baseUri = baseUri;
_owner = msg.sender;
}
/// @notice Represents an un-minted NFT, which has not yet been recorded into the blockchain. A signed voucher can be redeemed for a real NFT using the redeem function.
struct NFTVoucher {
address redeemer;
bool whitelisted;
uint256 numberOfTokens;
}
function supportsInterface(bytes4 interfaceId) public view virtual override (AccessControl, ERC721) returns (bool) {
return super.supportsInterface(interfaceId);
}
function setAside(uint256 count) onlyRole(MINTER_ROLE) external {
require(count <= RESERVED_TOKENS, "Over limit");
for(uint256 index = _tokenIds.current(); index < count; index++) {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_safeMint(_owner, newItemId);
}
RESERVED_TOKENS -= count;
}
/// @dev override base uri. It will be combined with token ID
function _baseURI() internal view virtual override returns (string memory) {
return _baseUri;
}
/// @notice Set hidden metadata uri
function setHiddenUri(string memory uri) onlyRole(MINTER_ROLE) external {
_hiddenURI = uri;
}
/// @notice Set base uri
function setBaseUri(string memory uri) onlyRole(MINTER_ROLE) external {
_baseUri = uri;
}
/// @notice Flip public sale
function flipSaleState() onlyRole(MINTER_ROLE) external {
isSaleActive = !isSaleActive;
if(isSaleActive) {
isPreSaleActive = false;
}
}
/// @notice Flip presale
function flipPresaleState() onlyRole(MINTER_ROLE) external {
isPreSaleActive = !isPreSaleActive;
}
/// @notice Reveal metadata for all the tokens
function reveal() onlyRole(MINTER_ROLE) external {
_canReveal = true;
}
/// @notice Get contract's balance
function balance() public view returns (uint256) {
return address(this).balance;
}
/// @notice Get token's URI. In case of delayed reveal we give user the json of the placeholer metadata.
/// @param tokenId token ID
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
if(msg.sender == _owner || _canReveal) {
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString(), ".json")) : "";
}
return _hiddenURI;
}
/// @notice Withdraw's contract's balance to the minter's address
function withdraw() external onlyRole(MINTER_ROLE) {
require(balance() > 0, "No balance");
address payable owner = payable(msg.sender);
owner.transfer(balance());
}
/// @notice Redeems an NFTVoucher for an actual NFT, creating it in the process.
/// @param voucher An NFTVoucher that describes the NFT to be redeemed.
/// @param signer address of the signer
/// @param signature An EIP712 signature of the voucher, produced by the NFT creator.
function redeem(NFTVoucher calldata voucher, address signer, bytes memory signature) public payable {
require(_verify(signer, _hash(voucher), signature), "Transaction is not authorized (invalid signature)");
if(isPreSaleActive) {
require(voucher.whitelisted, "Presale is only open to whitelisted users");
require(voucher.numberOfTokens <= PRESALE_TOKEN_PER_PERSON_LIMIT, string(abi.encodePacked("Max ", PRESALE_TOKEN_PER_PERSON_LIMIT.toString(), " token(s) per user during presale")));
require(balanceOf(voucher.redeemer).add(voucher.numberOfTokens) <= PRESALE_TOKEN_PER_PERSON_LIMIT, "Purchase would exceed limit per user");
}
else {
require(isSaleActive, "Sale must be active to mint");
}
require(_tokenIds.current() < COLLECTION_SIZE, "All tokens have been minted");
require(_tokenIds.current().add(voucher.numberOfTokens) < COLLECTION_SIZE, "Purchase would exceed max supply");
require(balanceOf(voucher.redeemer) < TOKEN_PER_PERSON_LIMIT, string(abi.encodePacked("Max ", TOKEN_PER_PERSON_LIMIT.toString(), " token(s) per user")));
require(balanceOf(voucher.redeemer).add(voucher.numberOfTokens) < TOKEN_PER_PERSON_LIMIT, "Purchase would exceed limit per user");
for(uint i = 0; i < voucher.numberOfTokens; i++) {
if (_tokenIds.current() < COLLECTION_SIZE) {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
// first assign the token to the signer, to establish provenance on-chain
_safeMint(signer, newItemId);
// transfer the token to the redeemer
_transfer(signer, voucher.redeemer, newItemId);
}
}
}
/// @notice Returns a hash of the given NFTVoucher, prepared using EIP712 typed data hashing rules.
/// @param voucher An NFTVoucher to hash.
function _hash(NFTVoucher calldata voucher)
internal view returns (bytes32)
{
return _hashTypedDataV4(keccak256(abi.encode(
keccak256("NFTVoucher(address redeemer,bool whitelisted,uint256 numberOfTokens)"),
voucher.redeemer,
voucher.whitelisted,
voucher.numberOfTokens
)));
}
function _verify(address signer, bytes32 digest, bytes memory signature)
internal view returns (bool)
{
return hasRole(MINTER_ROLE, signer) && SignatureChecker.isValidSignatureNow(signer, digest, signature);
}
}
Address.sol 216 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol 23 lines
// SPDX-License-Identifier: MIT
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 66 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
Counters.sol 42 lines
// SPDX-License-Identifier: MIT
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;
}
}
IERC1271.sol 18 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*
* _Available since v4.1._
*/
interface IERC1271 {
/**
* @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed
* @param signature Signature byte array associated with _data
*/
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}
ERC721.sol 411 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` 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 tokenId
) internal virtual {}
}
SafeMath.sol 226 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a + b;
}
/**
* @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 a - b;
}
/**
* @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) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
AccessControl.sol 210 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) private {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) private {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IERC721.sol 142 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
IAccessControl.sol 87 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
ECDSA.sol 219 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s;
uint8 v;
assembly {
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
v := add(shr(255, vs), 27)
}
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed 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));
}
}
ERC165.sol 28 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 24 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IERC721Receiver.sol 26 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
draft-EIP712.sol 101 lines
// SPDX-License-Identifier: MIT
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;
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);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (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);
}
}
SignatureChecker.sol 35 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ECDSA.sol";
import "../Address.sol";
import "../../interfaces/IERC1271.sol";
/**
* @dev Signature verification helper: Provide a single mechanism to verify both private-key (EOA) ECDSA signature and
* ERC1271 contract sigantures. Using this instead of ECDSA.recover in your contract will make them compatible with
* smart contract wallets such as Argent and Gnosis.
*
* Note: unlike ECDSA signatures, contract signature's are revocable, and the outcome of this function can thus change
* through time. It could return true at block N and false at block N+1 (or the opposite).
*
* _Available since v4.1._
*/
library SignatureChecker {
function isValidSignatureNow(
address signer,
bytes32 hash,
bytes memory signature
) internal view returns (bool) {
(address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
if (error == ECDSA.RecoverError.NoError && recovered == signer) {
return true;
}
(bool success, bytes memory result) = signer.staticcall(
abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
);
return (success && result.length == 32 && abi.decode(result, (bytes4)) == IERC1271.isValidSignature.selector);
}
}
IERC721Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
Read Contract
COLLECTION_SIZE 0xd8258d95 → uint256
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MINTER_ROLE 0xd5391393 → bytes32
PRESALE_TOKEN_PER_PERSON_LIMIT 0x0fe09700 → uint256
TOKEN_PER_PERSON_LIMIT 0x87bd14bf → uint256
TOKEN_PRICE 0xd2d8cb67 → uint256
balance 0xb69ef8a8 → uint256
balanceOf 0x70a08231 → uint256
getApproved 0x081812fc → address
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
isApprovedForAll 0xe985e9c5 → bool
isPreSaleActive 0x9d044ed3 → bool
isSaleActive 0x564566a8 → bool
name 0x06fdde03 → string
ownerOf 0x6352211e → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenURI 0xc87b56dd → string
Write Contract 16 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address to
uint256 tokenId
flipPresaleState 0xf81227d4
No parameters
flipSaleState 0x34918dfd
No parameters
grantRole 0x2f2ff15d
bytes32 role
address account
redeem 0x72c7cc96
tuple voucher
address signer
bytes signature
renounceRole 0x36568abe
bytes32 role
address account
reveal 0xa475b5dd
No parameters
revokeRole 0xd547741f
bytes32 role
address account
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setApprovalForAll 0xa22cb465
address operator
bool approved
setAside 0x39600e21
uint256 count
setBaseUri 0xa0bcfc7f
string uri
setHiddenUri 0x1067fcc7
string uri
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
withdraw 0x3ccfd60b
No parameters
Recent Transactions
No transactions found for this address