Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xDf3407636bBF3a015a8E48A079ef7bA49E687fD3
Balance 0 ETH
Nonce 1
Code Size 16093 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

16093 bytes
0x60806040526004361061038c5760003560e01c80636352211e116101dc578063b49aa3b511610102578063d6d6b6a3116100a0578063eb8d24441161006f578063eb8d2444146109be578063ee0a9666146109d3578063f7896ca6146109f3578063f81227d414610a085761038c565b8063d6d6b6a314610954578063de77128014610974578063e5c20ed214610989578063e985e9c51461099e5761038c565b8063c7d64a18116100dc578063c7d64a18146108df578063c87b56dd146108ff578063d547741f1461091f578063d65db8ac1461093f5761038c565b8063b49aa3b514610897578063b88d4fde146108ac578063c17d4676146108cc5761038c565b806391d148541161017a578063a217fddf11610149578063a217fddf1461082d578063a22cb46514610842578063a935ce8614610862578063aa1f75f3146108825761038c565b806391d14854146107b85780639516b441146107d857806395d89b41146107f85780639f0eeda71461080d5761038c565b80636f97f123116101b65780636f97f1231461074e57806370a082311461076e578063797669c91461078e5780638da5cb5b146107a35761038c565b80636352211e146106ee5780636533a6fc1461070e5780636c12b9d31461072e5761038c565b80632f745c59116102c157806339aaa3901161025f5780634d67a4d61161022e5780634d67a4d6146106845780634f6ccce71461069957806354572027146106b95780635d7b5efe146106ce5761038c565b806339aaa3901461060d5780633ccfd60b1461062d5780633e3ef2441461064257806342842e0e146106645761038c565b806334918dfd1161029b57806334918dfd146105a357806336568abe146105b857806336cc484b146105d857806338f897b8146105f85761038c565b80632f745c591461055b5780632feb1d081461057b57806330f72cd41461058e5761038c565b806318160ddd1161032e57806323b872dd1161030857806323b872dd146104e6578063248a9ca3146105065780632a905318146105265780632f2ff15d1461053b5761038c565b806318160ddd146104a757806318821400146104bc57806323a973ed146104d15761038c565b8063095ea7b31161036a578063095ea7b3146104165780630b747d9114610438578063109695231461045a578063113a16961461047a5761038c565b806301ffc9a71461039157806306fdde03146103c7578063081812fc146103e9575b600080fd5b34801561039d57600080fd5b506103b16103ac3660046131bf565b610a1d565b6040516103be9190613571565b60405180910390f35b3480156103d357600080fd5b506103dc610a30565b6040516103be91906135dc565b3480156103f557600080fd5b50610409610404366004613185565b610ac2565b6040516103be91906134dc565b34801561042257600080fd5b5061043661043136600461315c565b610b0e565b005b34801561044457600080fd5b5061044d610ba6565b6040516103be919061357c565b34801561046657600080fd5b50610436610475366004613264565b610bac565b34801561048657600080fd5b5061049a610495366004613185565b610bd2565b6040516103be9190613585565b3480156104b357600080fd5b5061044d610be8565b3480156104c857600080fd5b506103dc610bee565b3480156104dd57600080fd5b5061044d610c17565b3480156104f257600080fd5b5061043661050136600461306e565b610c1d565b34801561051257600080fd5b5061044d610521366004613185565b610c55565b34801561053257600080fd5b506103dc610c6a565b34801561054757600080fd5b5061043661055636600461319d565b610c8b565b34801561056757600080fd5b5061044d61057636600461315c565b610caa565b610436610589366004613185565b610cfc565b34801561059a57600080fd5b506103b1610ec9565b3480156105af57600080fd5b50610436610ed7565b3480156105c457600080fd5b506104366105d336600461319d565b610efa565b3480156105e457600080fd5b506104366105f3366004613185565b610f3c565b34801561060457600080fd5b50610436610f50565b34801561061957600080fd5b5061043661062836600461330e565b610f69565b34801561063957600080fd5b50610436611101565b34801561064e57600080fd5b5061065761113e565b6040516103be919061352d565b34801561067057600080fd5b5061043661067f36600461306e565b61120a565b34801561069057600080fd5b5061044d611225565b3480156106a557600080fd5b5061044d6106b4366004613185565b61122b565b3480156106c557600080fd5b506103b1611286565b3480156106da57600080fd5b506103dc6106e9366004613185565b61128b565b3480156106fa57600080fd5b50610409610709366004613185565b6113b2565b34801561071a57600080fd5b506104366107293660046131f7565b6113e7565b34801561073a57600080fd5b50610657610749366004613022565b611440565b34801561075a57600080fd5b50610436610769366004613297565b61159a565b34801561077a57600080fd5b5061044d610789366004613022565b6116f3565b34801561079a57600080fd5b5061044d611737565b3480156107af57600080fd5b50610409611749565b3480156107c457600080fd5b506103b16107d336600461319d565b611758565b3480156107e457600080fd5b506103b16107f3366004613185565b611783565b34801561080457600080fd5b506103dc6117fa565b34801561081957600080fd5b5061044d610828366004613022565b611809565b34801561083957600080fd5b5061044d611871565b34801561084e57600080fd5b5061043661085d366004613122565b611876565b34801561086e57600080fd5b5061044d61087d366004613022565b611944565b34801561088e57600080fd5b5061044d611a20565b3480156108a357600080fd5b506103dc611a26565b3480156108b857600080fd5b506104366108c73660046130a9565b611a52565b6104366108da366004613185565b611a91565b3480156108eb57600080fd5b506104366108fa366004613185565b611cce565b34801561090b57600080fd5b506103dc61091a366004613185565b611d3b565b34801561092b57600080fd5b5061043661093a36600461319d565b611dea565b34801561094b57600080fd5b5061044d611e09565b34801561096057600080fd5b5061044d61096f366004613022565b611e0f565b34801561098057600080fd5b5061044d611eea565b34801561099557600080fd5b506103dc611ef0565b3480156109aa57600080fd5b506103b16109b936600461303c565b611f7e565b3480156109ca57600080fd5b506103b1611fac565b3480156109df57600080fd5b506104366109ee366004613185565b611fb5565b3480156109ff57600080fd5b5061044d611fd6565b348015610a1457600080fd5b50610436611fdc565b6000610a28826121d4565b90505b919050565b606060008054610a3f90613dc5565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6b90613dc5565b8015610ab85780601f10610a8d57610100808354040283529160200191610ab8565b820191906000526020600020905b815481529060010190602001808311610a9b57829003601f168201915b5050505050905090565b6000610acd826121f9565b610af25760405162461bcd60e51b8152600401610ae990613ac9565b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b6000610b19826113b2565b9050806001600160a01b0316836001600160a01b03161415610b4d5760405162461bcd60e51b8152600401610ae990613b8d565b806001600160a01b0316610b5f612216565b6001600160a01b03161480610b7b5750610b7b816109b9612216565b610b975760405162461bcd60e51b8152600401610ae9906138ec565b610ba1838361221a565b505050565b60115481565b6000610bbf81610bba612216565b612288565b8151610ba190600c906020850190612e2d565b600090815261026d602052604090205460ff1690565b60085490565b6040518060400160405280600d81526020016c11da1bdcdd1cd41c9bda9958dd609a1b81525081565b600f5481565b610c2e610c28612216565b826122ec565b610c4a5760405162461bcd60e51b8152600401610ae990613bf1565b610ba1838383612371565b6000908152600a602052604090206001015490565b6040518060400160405280600581526020016411d213d4d560da1b81525081565b610c9482610c55565b610ca081610bba612216565b610ba1838361249e565b6000610cb5836116f3565b8210610cd35760405162461bcd60e51b8152600401610ae990613624565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b60135460ff16610d1e5760405162461bcd60e51b8152600401610ae990613a13565b600d54811115610d405760405162461bcd60e51b8152600401610ae990613949565b61271081610d4c610be8565b610d569190613d20565b1115610d745760405162461bcd60e51b8152600401610ae990613a7f565b3481600e54610d839190613d4c565b1115610da15760405162461bcd60e51b8152600401610ae990613727565b6000805b82811015610def57612710610db8610be8565b1015610ddd57610dcf33610dca610be8565b612525565b610dda600183613d20565b91505b80610de781613e00565b915050610da5565b503481600e54610dff9190613d4c565b1015610ea057600081600e54610e159190613d4c565b610e1f9034613d6b565b90506000336001600160a01b031682604051610e3a90613456565b60006040518083038185875af1925050503d8060008114610e77576040519150601f19603f3d011682016040523d82523d6000602084013e610e7c565b606091505b5050905080610e9d5760405162461bcd60e51b8152600401610ae990613752565b50505b601154158015610eb85750612710610eb6610be8565b145b15610ec557610ec561253f565b5050565b601354610100900460ff1681565b6000610ee581610bba612216565b506013805460ff19811660ff90911615179055565b610f02612216565b6001600160a01b0316816001600160a01b031614610f325760405162461bcd60e51b8152600401610ae990613cc5565b610ec582826125b9565b6000610f4a81610bba612216565b50600e55565b6000610f5e81610bba612216565b610f6661253f565b50565b82610f73816113b2565b6001600160a01b0316336001600160a01b031614610fa35760405162461bcd60e51b8152600401610ae990613bce565b600084815261026e602052604090208054610fbd90613dc5565b159050610fdc5760405162461bcd60e51b8152600401610ae9906136f8565b6001836002811115610ffe57634e487b7160e01b600052602160045260246000fd5b1415611022576001600f60008282546110179190613d20565b909155506110639050565b600283600281111561104457634e487b7160e01b600052602160045260246000fd5b14156110635760016010600082825461105d9190613d20565b90915550505b600084815261026d60205260409020805484919060ff1916600183600281111561109d57634e487b7160e01b600052602160045260246000fd5b0217905550600084815261026e6020908152604090912083516110c292850190612e2d565b50837f2f8b74832fa1704caf718398b3c0a980ba05a74578ee27ea8733a506d0a2f135836040516110f391906135dc565b60405180910390a250505050565b600061110f81610bba612216565b6040514790339082156108fc029083906000818181858888f19350505050158015610ba1573d6000803e3d6000fd5b6060600060125467ffffffffffffffff81111561116b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611194578160200160208202803683370190505b50905060005b6012548110156112045760158160c881106111c557634e487b7160e01b600052603260045260246000fd5b01548282815181106111e757634e487b7160e01b600052603260045260246000fd5b6020908102919091010152806111fc81613e00565b91505061119a565b50905090565b610ba183838360405180602001604052806000815250611a52565b600d5481565b6000611235610be8565b82106112535760405162461bcd60e51b8152600401610ae990613c42565b6008828154811061127457634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050919050565b600190565b6060611296826121f9565b6040518060400160405280601081526020016f125b9d985b1a5908151bdad95b88125160821b815250906112dd5760405162461bcd60e51b8152600401610ae991906135dc565b50600082815261026e6020526040812080546112f890613dc5565b9050116113145760405180602001604052806000815250610a28565b600082815261026e60205260409020805461132e90613dc5565b80601f016020809104026020016040519081016040528092919081815260200182805461135a90613dc5565b80156113a75780601f1061137c576101008083540402835291602001916113a7565b820191906000526020600020905b81548152906001019060200180831161138a57829003601f168201915b505050505092915050565b6000818152600260205260408120546001600160a01b031680610a285760405162461bcd60e51b8152600401610ae9906139ca565b60006113f581610bba612216565b61140160148484612eb1565b507fd5136665992c6c23e622ac8866b41e520263e8197aabd6d13903819906bcd38483836040516114339291906135ad565b60405180910390a1505050565b6060600060125467ffffffffffffffff81111561146d57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611496578160200160208202803683370190505b50905060005b6012548110156115935760158160c881106114c757634e487b7160e01b600052603260045260246000fd5b01544311156114d557611581565b6101a58160c881106114f757634e487b7160e01b600052603260045260246000fd5b6001600160a01b03861660009081529101602052604090205460dd8260c8811061153157634e487b7160e01b600052603260045260246000fd5b6001600160a01b0387166000908152910160205260409020546115549190613d6b565b82828151811061157457634e487b7160e01b600052603260045260246000fd5b6020026020010181815250505b8061158b81613e00565b91505061149c565b5092915050565b600080516020613e888339815191526115b581610bba612216565b8382146115d45760405162461bcd60e51b8152600401610ae990613857565b8543106115f35760405162461bcd60e51b8152600401610ae990613820565b85601560125460c8811061161757634e487b7160e01b600052603260045260246000fd5b015560005b848110156116d25783838281811061164457634e487b7160e01b600052603260045260246000fd5b9050602002013560dd60125460c8811061166e57634e487b7160e01b600052603260045260246000fd5b01600088888581811061169157634e487b7160e01b600052603260045260246000fd5b90506020020160208101906116a69190613022565b6001600160a01b03168152602081019190915260400160002055806116ca81613e00565b91505061161c565b506001601260008282546116e69190613d20565b9091555050505050505050565b60006001600160a01b03821661171b5760405162461bcd60e51b8152600401610ae990613980565b506001600160a01b031660009081526003602052604090205490565b600080516020613e8883398151915281565b600b546001600160a01b031690565b6000918252600a602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600061178e826121f9565b6040518060400160405280601081526020016f125b9d985b1a5908151bdad95b88125160821b815250906117d55760405162461bcd60e51b8152600401610ae991906135dc565b50600082815261026e6020526040812080546117f090613dc5565b9050119050919050565b606060018054610a3f90613dc5565b600080805b601254811015611593576101a58160c8811061183a57634e487b7160e01b600052603260045260246000fd5b6001600160a01b03861660009081529101602052604090205461185d9083613d20565b91508061186981613e00565b91505061180e565b600081565b61187e612216565b6001600160a01b0316826001600160a01b031614156118af5760405162461bcd60e51b8152600401610ae9906137c4565b80600560006118bc612216565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155611900612216565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516119389190613571565b60405180910390a35050565b600080805b6012548110156115935760158160c8811061197457634e487b7160e01b600052603260045260246000fd5b015443111561198257611a0e565b6101a58160c881106119a457634e487b7160e01b600052603260045260246000fd5b6001600160a01b03861660009081529101602052604090205460dd8260c881106119de57634e487b7160e01b600052603260045260246000fd5b6001600160a01b038716600090815291016020526040902054611a019190613d6b565b611a0b9083613d20565b91505b80611a1881613e00565b915050611949565b60125481565b6040518060400160405280601081526020016f125b9d985b1a5908151bdad95b88125160821b81525081565b611a63611a5d612216565b836122ec565b611a7f5760405162461bcd60e51b8152600401610ae990613bf1565b611a8b8484848461263e565b50505050565b601354610100900460ff16611ab85760405162461bcd60e51b8152600401610ae990613b5e565b61271081611ac4610be8565b611ace9190613d20565b1115611aec5760405162461bcd60e51b8152600401610ae990613a7f565b3481600e54611afb9190613d4c565b1115611b195760405162461bcd60e51b8152600401610ae990613727565b611b2233611944565b811115611b415760405162461bcd60e51b8152600401610ae990613949565b6000806000805b84811015611bf857612710611b5b610be8565b1015611be65782611b7657611b703385612671565b90945092505b611b8233610dca610be8565b611b8d600183613d20565b915060016101a58560c88110611bb357634e487b7160e01b600052603260045260246000fd5b3360009081529101602052604081208054909190611bd2908490613d20565b90915550611be39050600184613d6b565b92505b80611bf081613e00565b915050611b48565b503481600e54611c089190613d4c565b1015611ca957600081600e54611c1e9190613d4c565b611c289034613d6b565b90506000336001600160a01b031682604051611c4390613456565b60006040518083038185875af1925050503d8060008114611c80576040519150601f19603f3d011682016040523d82523d6000602084013e611c85565b606091505b5050905080611ca65760405162461bcd60e51b8152600401610ae990613752565b50505b601154158015611cc15750612710611cbf610be8565b145b15611a8b57611a8b61253f565b600080516020613e88833981519152611ce981610bba612216565b60c88210611d095760405162461bcd60e51b8152600401610ae9906137fb565b611d14600143613d6b565b60158360c88110611d3557634e487b7160e01b600052603260045260246000fd5b01555050565b6060611d46826121f9565b6040518060400160405280601081526020016f125b9d985b1a5908151bdad95b88125160821b81525090611d8d5760405162461bcd60e51b8152600401610ae991906135dc565b50600060148054611d9d90613dc5565b905011611db95760405180602001604052806000815250610a28565b6014611dc4836127d5565b604051602001611dd59291906133b0565b60405160208183030381529060405292915050565b611df382610c55565b611dff81610bba612216565b610ba183836125b9565b61271090565b600080805b6012548110156115935760158160c88110611e3f57634e487b7160e01b600052603260045260246000fd5b01544311611e4c57611ed8565b6101a58160c88110611e6e57634e487b7160e01b600052603260045260246000fd5b6001600160a01b03861660009081529101602052604090205460dd8260c88110611ea857634e487b7160e01b600052603260045260246000fd5b6001600160a01b038716600090815291016020526040902054611ecb9190613d6b565b611ed59083613d20565b91505b80611ee281613e00565b915050611e14565b60105481565b600c8054611efd90613dc5565b80601f0160208091040260200160405190810160405280929190818152602001828054611f2990613dc5565b8015611f765780601f10611f4b57610100808354040283529160200191611f76565b820191906000526020600020905b815481529060010190602001808311611f5957829003601f168201915b505050505081565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b60135460ff1681565b600080516020613e88833981519152611fd081610bba612216565b50600d55565b600e5481565b600080516020613e88833981519152611ff781610bba612216565b506013805461ff001981166101009182900460ff1615909102179055565b60606000612024836002613d4c565b61202f906002613d20565b67ffffffffffffffff81111561205557634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561207f576020820181803683370190505b509050600360fc1b816000815181106120a857634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106120e557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506000612109846002613d4c565b612114906001613d20565b90505b60018111156121a8576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061215657634e487b7160e01b600052603260045260246000fd5b1a60f81b82828151811061217a57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c936121a181613dae565b9050612117565b5083156121c75760405162461bcd60e51b8152600401610ae9906135ef565b9392505050565b3b151590565b60006001600160e01b03198216637965db0b60e01b1480610a285750610a28826128fb565b6000908152600260205260409020546001600160a01b0316151590565b3390565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061224f826113b2565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6122928282611758565b610ec5576122aa816001600160a01b03166014612015565b6122b5836020612015565b6040516020016122c6929190613459565b60408051601f198184030181529082905262461bcd60e51b8252610ae9916004016135dc565b60006122f7826121f9565b6123135760405162461bcd60e51b8152600401610ae9906138a0565b600061231e836113b2565b9050806001600160a01b0316846001600160a01b031614806123595750836001600160a01b031661234e84610ac2565b6001600160a01b0316145b8061236957506123698185611f7e565b949350505050565b826001600160a01b0316612384826113b2565b6001600160a01b0316146123aa5760405162461bcd60e51b8152600401610ae990613b15565b6001600160a01b0382166123d05760405162461bcd60e51b8152600401610ae990613780565b6123db838383612920565b6123e660008261221a565b6001600160a01b038316600090815260036020526040812080546001929061240f908490613d6b565b90915550506001600160a01b038216600090815260036020526040812080546001929061243d908490613d20565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6124a88282611758565b610ec5576000828152600a602090815260408083206001600160a01b03851684529091529020805460ff191660011790556124e1612216565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b610ec58282604051806020016040528060008152506129a9565b6011541561255f5760405162461bcd60e51b8152600401610ae990613c8e565b4261256b600143613d6b565b4060405160200161257d9291906134ce565b60408051601f19818403018152919052805160209091012060118190556125b7576001601160008282546125b19190613d20565b90915550505b565b6125c38282611758565b15610ec5576000828152600a602090815260408083206001600160a01b03851684529091529020805460ff191690556125fa612216565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b612649848484612371565b612655848484846129dc565b611a8b5760405162461bcd60e51b8152600401610ae99061366f565b60008060c881845b60c88110156127c7574360158260c881106126a457634e487b7160e01b600052603260045260246000fd5b015410156126b1576127b5565b60dd8160c881106126d257634e487b7160e01b600052603260045260246000fd5b6001600160a01b0389166000908152910160205260409020546101a58260c8811061270d57634e487b7160e01b600052603260045260246000fd5b6001600160a01b038a1660009081529101602052604090205410156127b5578092506101a58160c8811061275157634e487b7160e01b600052603260045260246000fd5b6001600160a01b03891660009081529101602052604090205460dd8260c8811061278b57634e487b7160e01b600052603260045260246000fd5b6001600160a01b038a166000908152910160205260409020546127ae9190613d6b565b91506127c7565b806127bf81613e00565b915050612679565b5090925090505b9250929050565b6060816127fa57506040805180820190915260018152600360fc1b6020820152610a2b565b8160005b8115612824578061280e81613e00565b915061281d9050600a83613d38565b91506127fe565b60008167ffffffffffffffff81111561284d57634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015612877576020820181803683370190505b508593509050815b83156128f257612890600a85613e1b565b61289b906030613d20565b60f81b826128a883613dae565b925082815181106128c957634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506128eb600a85613d38565b935061287f565b50949350505050565b60006001600160e01b0319821663780e9d6360e01b1480610a285750610a2882612af7565b61292b838383610ba1565b6001600160a01b0383166129475761294281612b37565b61296a565b816001600160a01b0316836001600160a01b03161461296a5761296a8382612b7b565b6001600160a01b0382166129865761298181612c18565b610ba1565b826001600160a01b0316826001600160a01b031614610ba157610ba18282612cf1565b6129b38383612d35565b6129c060008484846129dc565b610ba15760405162461bcd60e51b8152600401610ae99061366f565b60006129f0846001600160a01b03166121ce565b15612aec57836001600160a01b031663150b7a02612a0c612216565b8786866040518563ffffffff1660e01b8152600401612a2e94939291906134f0565b602060405180830381600087803b158015612a4857600080fd5b505af1925050508015612a78575060408051601f3d908101601f19168201909252612a75918101906131db565b60015b612ad2573d808015612aa6576040519150601f19603f3d011682016040523d82523d6000602084013e612aab565b606091505b508051612aca5760405162461bcd60e51b8152600401610ae99061366f565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050612369565b506001949350505050565b60006001600160e01b031982166380ac58cd60e01b1480612b2857506001600160e01b03198216635b5e139f60e01b145b80610a285750610a2882612e14565b600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b60006001612b88846116f3565b612b929190613d6b565b600083815260076020526040902054909150808214612be5576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090612c2a90600190613d6b565b60008381526009602052604081205460088054939450909284908110612c6057634e487b7160e01b600052603260045260246000fd5b906000526020600020015490508060088381548110612c8f57634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480612cd557634e487b7160e01b600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b6000612cfc836116f3565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b038216612d5b5760405162461bcd60e51b8152600401610ae990613a4a565b612d64816121f9565b15612d815760405162461bcd60e51b8152600401610ae9906136c1565b612d8d60008383612920565b6001600160a01b0382166000908152600360205260408120805460019290612db6908490613d20565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6001600160e01b031981166301ffc9a760e01b14919050565b828054612e3990613dc5565b90600052602060002090601f016020900481019282612e5b5760008555612ea1565b82601f10612e7457805160ff1916838001178555612ea1565b82800160010185558215612ea1579182015b82811115612ea1578251825591602001919060010190612e86565b50612ead929150612f25565b5090565b828054612ebd90613dc5565b90600052602060002090601f016020900481019282612edf5760008555612ea1565b82601f10612ef85782800160ff19823516178555612ea1565b82800160010185558215612ea1579182015b82811115612ea1578235825591602001919060010190612f0a565b5b80821115612ead5760008155600101612f26565b600067ffffffffffffffff80841115612f5557612f55613e5b565b604051601f8501601f191681016020018281118282101715612f7957612f79613e5b565b604052848152915081838501861015612f9157600080fd5b8484602083013760006020868301015250509392505050565b80356001600160a01b0381168114610a2b57600080fd5b60008083601f840112612fd2578081fd5b50813567ffffffffffffffff811115612fe9578182fd5b60208301915083602080830285010111156127ce57600080fd5b600082601f830112613013578081fd5b6121c783833560208501612f3a565b600060208284031215613033578081fd5b6121c782612faa565b6000806040838503121561304e578081fd5b61305783612faa565b915061306560208401612faa565b90509250929050565b600080600060608486031215613082578081fd5b61308b84612faa565b925061309960208501612faa565b9150604084013590509250925092565b600080600080608085870312156130be578081fd5b6130c785612faa565b93506130d560208601612faa565b925060408501359150606085013567ffffffffffffffff8111156130f7578182fd5b8501601f81018713613107578182fd5b61311687823560208401612f3a565b91505092959194509250565b60008060408385031215613134578182fd5b61313d83612faa565b915060208301358015158114613151578182fd5b809150509250929050565b6000806040838503121561316e578182fd5b61317783612faa565b946020939093013593505050565b600060208284031215613196578081fd5b5035919050565b600080604083850312156131af578182fd5b8235915061306560208401612faa565b6000602082840312156131d0578081fd5b81356121c781613e71565b6000602082840312156131ec578081fd5b81516121c781613e71565b60008060208385031215613209578182fd5b823567ffffffffffffffff80821115613220578384fd5b818501915085601f830112613233578384fd5b813581811115613241578485fd5b866020828501011115613252578485fd5b60209290920196919550909350505050565b600060208284031215613275578081fd5b813567ffffffffffffffff81111561328b578182fd5b61236984828501613003565b6000806000806000606086880312156132ae578283fd5b85359450602086013567ffffffffffffffff808211156132cc578485fd5b6132d889838a01612fc1565b909650945060408801359150808211156132f0578283fd5b506132fd88828901612fc1565b969995985093965092949392505050565b600080600060608486031215613322578081fd5b83359250602084013560038110613337578182fd5b9150604084013567ffffffffffffffff811115613352578182fd5b61335e86828701613003565b9150509250925092565b60008151808452613380816020860160208601613d82565b601f01601f19169290920160200192915050565b600081516133a6818560208601613d82565b9290920192915050565b82546000908190600281046001808316806133cc57607f831692505b60208084108214156133ec57634e487b7160e01b87526022600452602487fd5b81801561340057600181146134115761343d565b60ff1986168952848901965061343d565b61341a8b613d14565b885b868110156134355781548b82015290850190830161341c565b505084890196505b50505050505061344d8185613394565b95945050505050565b90565b60007f416363657373436f6e74726f6c3a206163636f756e742000000000000000000082528351613491816017850160208801613d82565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516134c2816028840160208801613d82565b01602801949350505050565b918252602082015260400190565b6001600160a01b0391909116815260200190565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061352390830184613368565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561356557835183529284019291840191600101613549565b50909695505050505050565b901515815260200190565b90815260200190565b60208101600383106135a757634e487b7160e01b600052602160045260246000fd5b91905290565b60006020825282602083015282846040840137818301604090810191909152601f909201601f19160101919050565b6000602082526121c76020830184613368565b6020808252818101527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604082015260600190565b6020808252602b908201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560408201526a74206f6620626f756e647360a81b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b602080825260159082015274416c7265616479207069636b6564206d656d6f727960581b604082015260600190565b60208082526011908201527034b732b33334b1b4b2b73a1032ba3432b960791b604082015260600190565b6020808252601490820152732330b4b632b2103a379039b2b7321022ba3432b960611b604082015260600190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646040820152637265737360e01b606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b6020808252600b908201526a1ddc9bdb99c81c9bdd5b9960aa1b604082015260600190565b6020808252601d908201527f6365727461696e20626c6f636b20616c72656164792065787069726564000000604082015260600190565b60208082526029908201527f6c656e677468206f66206164647265737320616e642076616c756573206d7573604082015268742062652073616d6560b81b606082015260800190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b6020808252601d908201527f547269656420746f206d696e7420746f6f206d616e792067686f737473000000604082015260600190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526029908201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460408201526832b73a103a37b5b2b760b91b606082015260800190565b60208082526019908201527f4e6f7420696e207075626c69632073616c6520706572696f6400000000000000604082015260600190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b6020808252602a908201527f507572636861736520776f756c6420657863656564206d617820737570706c79604082015269206f662067686f73747360b01b606082015260800190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201526839903737ba1037bbb760b91b606082015260800190565b602080825260159082015274139bdd081a5b881c1c995cd85b19481c195c9a5bd9605a1b604082015260600190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656040820152603960f91b606082015260800190565b6020808252600990820152682737ba1037bbb732b960b91b604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252602c908201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60408201526b7574206f6620626f756e647360a01b606082015260800190565b6020808252601a908201527f53656564206e756d62657220697320616c726561647920736574000000000000604082015260600190565b6020808252602f908201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560408201526e103937b632b9903337b91039b2b63360891b606082015260800190565b60009081526020902090565b60008219821115613d3357613d33613e2f565b500190565b600082613d4757613d47613e45565b500490565b6000816000190483118215151615613d6657613d66613e2f565b500290565b600082821015613d7d57613d7d613e2f565b500390565b60005b83811015613d9d578181015183820152602001613d85565b83811115611a8b5750506000910152565b600081613dbd57613dbd613e2f565b506000190190565b600281046001821680613dd957607f821691505b60208210811415613dfa57634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415613e1457613e14613e2f565b5060010190565b600082613e2a57613e2a613e45565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610f6657600080fdfe58c8e11deab7910e89bf18a1168c6e6ef28748f00fd3094549459f01cec5e0aaa264697066735822122014f8894dce80acd9d7a50796680f2f79876092eff1f3405c21ed5bf9f23108c064736f6c63430008000033

Verified Source Code Full Match

Compiler: v0.8.0+commit.c7dfd78e EVM: istanbul Optimization: Yes (200 runs)
GhostBase.sol 11 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract GhostBase {

    enum MemoryType {
        NONE,
        GOOD,
        EVIL
    }
}
StringLib.sol 24 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

library StringLib {
    function uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
        if (_i == 0) {
            return "0";
        }
        uint256 j = _i;
        uint256 len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bytesStr = new bytes(len);
        uint256 k = len;
        j = _i;
        while (j != 0) {
            bytesStr[--k] = bytes1(uint8(48 + j % 10));
            j /= 10;
        }
        _uintAsString = string(bytesStr);
    }
}
GhostsProject.sol 309 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./Administration.sol";
import "./GhostBase.sol";
import "./StringLib.sol";


/// @title GhostsProject contract
/// @dev Extends ERC721 Non-Fungible Token Standard basic implementation
contract GhostsProject is ERC721Enumerable, Administration, GhostBase {

    using Strings for uint256;
    using StringLib for uint256;

    /// @notice Event emitted when TokenURI base changes
    /// @param tokenUriBase the base URI for tokenURI calls
    event TokenUriBaseSet(string tokenUriBase);

    /// @notice Event emitted when pick memoryType and memory of Ghost with ghostTokenId
    /// @param tokenId token id of ghost
    /// @param memoryPhrase memory phrase that ghost picked
    event PickMemory(uint256 indexed tokenId, string memoryPhrase);

    string public constant TOKEN_NAME = "GhostsProject";
    string public constant TOKEN_SYMBOL = "GHOST";
    string public constant INVALID_TOKEN_ID = "Invalid Token ID";

    string public GHOST_PROVENANCE = "";

    uint256 public maxPurchasePerMint = 10;
    uint256 public ghostPrice = 0.2 ether;

    uint256 public countGoodMemories = 0;
    uint256 public countEvilMemories = 0;

    uint256 public randomSeed;

    uint256 public currentPioneerRound = 0;

    bool public saleIsActive = false;
    bool public presaleIsActive = false;

    string private tokenUriBase;

    uint256 internal constant MAX_GHOSTS = 10000;
    uint256 internal constant MAX_PIONEER_ROUND = 200;

    uint256[MAX_PIONEER_ROUND] internal _pioneerRoundExpire;
    mapping(address => uint256)[MAX_PIONEER_ROUND] private _pioneerClaimable;
    mapping(address => uint256)[MAX_PIONEER_ROUND] private _pioneerClaimed;

    mapping(uint256 => MemoryType) private _ghostMemoryTypes;
    mapping(uint256 => string) private _ghostMemories;

    constructor() ERC721(TOKEN_NAME, TOKEN_SYMBOL) {
        _mintTeamGhost();
    }

    modifier onlyOwner(uint256 _tokenId) {
        require(msg.sender == ownerOf(_tokenId), "Not owner");
        _;
    }

    modifier onlyOnPresale() {
        require(presaleIsActive, "Not in presale period");
        _;
    }

    modifier onlyOnSale() {
        require(saleIsActive, "Not in public sale period");
        _;
    }

    function isGhostsProject() external pure returns (bool) {
        return true;
    }

    function setProvenanceHash(string memory provenanceHash) external onlyRole(DEFAULT_ADMIN_ROLE) {
        GHOST_PROVENANCE = provenanceHash;
    }

    function setMaxPurchasePerMint(uint256 _maxPurchasePerMint) external onlyRole(MODERATOR_ROLE) {
        maxPurchasePerMint = _maxPurchasePerMint;
    }

    function getMaxGhosts() external pure returns (uint256) {
        return MAX_GHOSTS;
    }

    function setGhostPrice(uint256 _price) external onlyRole(DEFAULT_ADMIN_ROLE) {
        ghostPrice = _price;
    }

    function flipSaleState() external onlyRole(DEFAULT_ADMIN_ROLE) {
        saleIsActive = !saleIsActive;
    }

    function flipPresaleState() external onlyRole(MODERATOR_ROLE) {
        presaleIsActive = !presaleIsActive;
    }

    function setRandomSeed() external onlyRole(DEFAULT_ADMIN_ROLE) {
        _setRandomSeed();
    }

    function addToPioneer(uint256 _blockNumberToExpire, address[] calldata _addresses, uint256[] calldata _values) external onlyRole(MODERATOR_ROLE) {
        require(_addresses.length == _values.length, "length of address and values must be same");
        require(block.number < _blockNumberToExpire, "certain block already expired");
        _pioneerRoundExpire[currentPioneerRound] = _blockNumberToExpire;
        for (uint256 i = 0; i < _addresses.length; i++) {
            _pioneerClaimable[currentPioneerRound][_addresses[i]] = _values[i];
        }
        currentPioneerRound += 1;
    }

    function expirePioneerRound(uint256 _roundNum) external onlyRole(MODERATOR_ROLE) {
        require(_roundNum < _pioneerRoundExpire.length, "wrong round");
        _pioneerRoundExpire[_roundNum] = block.number - 1;
    }

    /// @notice Set the base URI for creating `tokenURI` for each Ghost.
    /// Only invokable by system admin role, when contract is paused and not upgraded.
    /// If successful, emits an `TokenUriBaseSet` event.
    /// @param _tokenUriBase base for the ERC721 tokenURI
    function setTokenUriBase(string calldata _tokenUriBase) external onlyRole(DEFAULT_ADMIN_ROLE) {
        tokenUriBase = _tokenUriBase;
        emit TokenUriBaseSet(_tokenUriBase);
    }

    function getPioneerTicketAvailable(address _address) public view returns (uint256) {
        uint256 ticket = 0;
        for (uint256 i = 0; i < currentPioneerRound; i++) {
            if (block.number > _pioneerRoundExpire[i])
                continue;
            ticket += _pioneerClaimable[i][_address] - _pioneerClaimed[i][_address];
        }
        return ticket;
    }

    function getPioneerTicketAvailablePerRound(address _address) public view returns (uint256[] memory) {
        uint256[] memory tickets = new uint[](currentPioneerRound);
        for (uint256 i = 0; i < currentPioneerRound; i++) {
            if (block.number > _pioneerRoundExpire[i])
                continue;
            tickets[i] = _pioneerClaimable[i][_address] - _pioneerClaimed[i][_address];
        }
        return tickets;
    }

    function getPioneerTicketClaimed(address _address) public view returns (uint256) {
        uint256 ticket = 0;
        for (uint256 i = 0; i < currentPioneerRound; i++) {
            ticket += _pioneerClaimed[i][_address];
        }
        return ticket;
    }

    function getPioneerTicketExpired(address _address) public view returns (uint256) {
        uint256 ticket = 0;
        for (uint256 i = 0; i < currentPioneerRound; i++) {
            if (block.number <= _pioneerRoundExpire[i])
                continue;
            ticket += _pioneerClaimable[i][_address] - _pioneerClaimed[i][_address];
        }
        return ticket;
    }

    function getPioneerRoundExpireBlocks() public view returns (uint256[] memory) {
        uint256[] memory blocks = new uint[](currentPioneerRound);
        for (uint256 i = 0; i < currentPioneerRound; i++) {
            blocks[i] = _pioneerRoundExpire[i];
        }
        return blocks;
    }

    function mintGhostForPioneer(uint256 numGhosts) public payable onlyOnPresale {
        require(totalSupply() + numGhosts <= MAX_GHOSTS, "Purchase would exceed max supply of ghosts");
        require(ghostPrice * numGhosts <= msg.value, "inefficient ether");
        require(numGhosts <= getPioneerTicketAvailable(msg.sender), "Tried to mint too many ghosts");

        uint256 round = 0;
        uint256 ticketInRound = 0;
        uint256 count = 0;
        for (uint256 i = 0; i < numGhosts; i++) {
            if (totalSupply() < MAX_GHOSTS) {
                if (ticketInRound == 0)
                    (round, ticketInRound) = _getRoundToClaim(msg.sender, round);
                _safeMint(msg.sender, totalSupply());
                count += 1;
                _pioneerClaimed[round][msg.sender] += 1;
                ticketInRound -= 1;
            }
        }
        if (ghostPrice * count < msg.value) {
            uint256 ethToRefund = msg.value - ghostPrice * count;
            (bool sent, ) = msg.sender.call{ value: ethToRefund }("");
            require(sent, "Failed to send Ether");
        }
        if (randomSeed == 0 && (totalSupply() == MAX_GHOSTS)) {
            _setRandomSeed();
        }
    }

    function withdraw() public onlyRole(DEFAULT_ADMIN_ROLE) {
        uint256 balance = address(this).balance;
        payable(msg.sender).transfer(balance);
    }

    function supportsInterface(bytes4 interfaceId)
    public view override(AccessControl, ERC721Enumerable)
    returns (bool) {
        return super.supportsInterface(interfaceId);
    }

    function mintGhost(uint256 numberOfTokens) public payable onlyOnSale {
        require(numberOfTokens <= maxPurchasePerMint, "Tried to mint too many ghosts");
        require(totalSupply() + numberOfTokens <= MAX_GHOSTS, "Purchase would exceed max supply of ghosts");
        require(ghostPrice * numberOfTokens <= msg.value, "inefficient ether");

        uint256 count = 0;
        for (uint256 i = 0; i < numberOfTokens; i++) {
            if (totalSupply() < MAX_GHOSTS) {
                _safeMint(msg.sender, totalSupply());
                count += 1;
            }
        }
        if (ghostPrice * count < msg.value) {
            uint256 ethToRefund = msg.value - ghostPrice * count;
            (bool sent, ) = msg.sender.call{ value: ethToRefund }("");
            require(sent, "Failed to send Ether");
        }

        if (randomSeed == 0 && (totalSupply() == MAX_GHOSTS)) {
            _setRandomSeed();
        }
    }

    function tokenURI(uint256 _tokenId)
    public view override
    returns (string memory uri) {
        require(_exists(_tokenId), INVALID_TOKEN_ID);
        uri = bytes(tokenUriBase).length > 0 ? string(abi.encodePacked(tokenUriBase, StringLib.uint2str(_tokenId))) : "";
    }

    function hasMemory(uint256 _tokenId) public view returns (bool) {
        require(_exists(_tokenId), INVALID_TOKEN_ID);
        return bytes(_ghostMemories[_tokenId]).length > 0;
    }

    function memoryPicked(uint256 _tokenId)
    public view
    returns (string memory memoryPhrase) {
        require(_exists(_tokenId), INVALID_TOKEN_ID);

        memoryPhrase = bytes(_ghostMemories[_tokenId]).length > 0 ? _ghostMemories[_tokenId] : "";
    }

    function getMemoryType(uint256 _tokenId) public view returns (MemoryType memoryType) {
        return _ghostMemoryTypes[_tokenId];
    }

    function pickMemory(uint256 _tokenId, MemoryType _memoryType, string memory _memoryPhrase) public onlyOwner(_tokenId) {
        require(bytes(_ghostMemories[_tokenId]).length == 0, "Already picked memory");

        if (_memoryType == MemoryType.GOOD)
            countGoodMemories += 1;
        else if (_memoryType == MemoryType.EVIL)
            countEvilMemories += 1;
        _ghostMemoryTypes[_tokenId] = _memoryType;
        _ghostMemories[_tokenId] = _memoryPhrase;
        emit PickMemory(_tokenId, _memoryPhrase);
    }

    function _mintTeamGhost() internal onlyRole(DEFAULT_ADMIN_ROLE) {
        require(totalSupply() == 0, "Team ghost already minted");
        _safeMint(msg.sender, 0);  // MrMisang Ghost
        for (uint256 i = 1; i < 21; i++) {
            _safeMint(msg.sender, i);  // Team Ghost
        }
    }

    function _getRoundToClaim(address _address, uint256 startIndex) private view returns (uint256, uint256) {
        uint256 round = MAX_PIONEER_ROUND;
        uint256 ticketInRound = 0;
        for (uint256 i = startIndex; i < MAX_PIONEER_ROUND; i++) {
            if (_pioneerRoundExpire[i] < block.number)
                continue;
            if (_pioneerClaimed[i][_address] < _pioneerClaimable[i][_address]) {
                round = i;
                ticketInRound = _pioneerClaimable[i][_address] - _pioneerClaimed[i][_address];
                break;
            }
        }
        return (round, ticketInRound);
    }

    function _setRandomSeed() private {
        require(randomSeed == 0, "Seed number is already set");

        randomSeed = uint(keccak256(abi.encodePacked(block.timestamp, blockhash(block.number - 1))));
        // Prevent default sequence
        if (randomSeed == 0) {
            randomSeed += 1;
        }
    }
}
Administration.sol 27 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/AccessControl.sol";


contract Administration is AccessControl {

    address private _owner;
    bytes32 public constant MODERATOR_ROLE = keccak256("MODERATOR");

    /// @dev Add `root` to the admin role as a member.
    constructor() {
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(MODERATOR_ROLE, msg.sender);
        _setRoleAdmin(MODERATOR_ROLE, DEFAULT_ADMIN_ROLE);
        _transferOwnership(msg.sender);
    }

    function owner() public view virtual returns (address) {
        return _owner;
    }

    function _transferOwnership(address newOwner) internal virtual {
        _owner = newOwner;
    }}

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);
    }
}
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 {}
}
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;
}
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);
}
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);
}
ERC721Enumerable.sol 162 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC721.sol";
import "./IERC721Enumerable.sol";

/**
 * @dev This implements an optional extension of {ERC721} defined in the EIP that adds
 * enumerability of all the token ids in the contract as well as all token ids owned by each
 * account.
 */
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
    // Mapping from owner to list of owned token IDs
    mapping(address => mapping(uint256 => uint256)) private _ownedTokens;

    // Mapping from token ID to index of the owner tokens list
    mapping(uint256 => uint256) private _ownedTokensIndex;

    // Array with all token ids, used for enumeration
    uint256[] private _allTokens;

    // Mapping from token id to position in the allTokens array
    mapping(uint256 => uint256) private _allTokensIndex;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
        return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
        require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
        return _ownedTokens[owner][index];
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _allTokens.length;
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
        return _allTokens[index];
    }

    /**
     * @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` cannot be the zero address.
     * - `to` cannot be the zero address.
     *
     * 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 override {
        super._beforeTokenTransfer(from, to, tokenId);

        if (from == address(0)) {
            _addTokenToAllTokensEnumeration(tokenId);
        } else if (from != to) {
            _removeTokenFromOwnerEnumeration(from, tokenId);
        }
        if (to == address(0)) {
            _removeTokenFromAllTokensEnumeration(tokenId);
        } else if (to != from) {
            _addTokenToOwnerEnumeration(to, tokenId);
        }
    }

    /**
     * @dev Private function to add a token to this extension's ownership-tracking data structures.
     * @param to address representing the new owner of the given token ID
     * @param tokenId uint256 ID of the token to be added to the tokens list of the given address
     */
    function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
        uint256 length = ERC721.balanceOf(to);
        _ownedTokens[to][length] = tokenId;
        _ownedTokensIndex[tokenId] = length;
    }

    /**
     * @dev Private function to add a token to this extension's token tracking data structures.
     * @param tokenId uint256 ID of the token to be added to the tokens list
     */
    function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
        _allTokensIndex[tokenId] = _allTokens.length;
        _allTokens.push(tokenId);
    }

    /**
     * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
     * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
     * gas optimizations e.g. when performing a transfer operation (avoiding double writes).
     * This has O(1) time complexity, but alters the order of the _ownedTokens array.
     * @param from address representing the previous owner of the given token ID
     * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
     */
    function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
        // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
        uint256 tokenIndex = _ownedTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary
        if (tokenIndex != lastTokenIndex) {
            uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];

            _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
            _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
        }

        // This also deletes the contents at the last position of the array
        delete _ownedTokensIndex[tokenId];
        delete _ownedTokens[from][lastTokenIndex];
    }

    /**
     * @dev Private function to remove a token from this extension's token tracking data structures.
     * This has O(1) time complexity, but alters the order of the _allTokens array.
     * @param tokenId uint256 ID of the token to be removed from the tokens list
     */
    function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
        // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = _allTokens.length - 1;
        uint256 tokenIndex = _allTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
        // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
        // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
        uint256 lastTokenId = _allTokens[lastTokenIndex];

        _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
        _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index

        // This also deletes the contents at the last position of the array
        delete _allTokensIndex[tokenId];
        _allTokens.pop();
    }
}
IERC721Enumerable.sol 28 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
GHOST_PROVENANCE 0xe5c20ed2 → string
INVALID_TOKEN_ID 0xb49aa3b5 → string
MODERATOR_ROLE 0x797669c9 → bytes32
TOKEN_NAME 0x18821400 → string
TOKEN_SYMBOL 0x2a905318 → string
balanceOf 0x70a08231 → uint256
countEvilMemories 0xde771280 → uint256
countGoodMemories 0x23a973ed → uint256
currentPioneerRound 0xaa1f75f3 → uint256
getApproved 0x081812fc → address
getMaxGhosts 0xd65db8ac → uint256
getMemoryType 0x113a1696 → uint8
getPioneerRoundExpireBlocks 0x3e3ef244 → uint256[]
getPioneerTicketAvailable 0xa935ce86 → uint256
getPioneerTicketAvailablePerRound 0x6c12b9d3 → uint256[]
getPioneerTicketClaimed 0x9f0eeda7 → uint256
getPioneerTicketExpired 0xd6d6b6a3 → uint256
getRoleAdmin 0x248a9ca3 → bytes32
ghostPrice 0xf7896ca6 → uint256
hasMemory 0x9516b441 → bool
hasRole 0x91d14854 → bool
isApprovedForAll 0xe985e9c5 → bool
isGhostsProject 0x54572027 → bool
maxPurchasePerMint 0x4d67a4d6 → uint256
memoryPicked 0x5d7b5efe → string
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
presaleIsActive 0x30f72cd4 → bool
randomSeed 0x0b747d91 → uint256
saleIsActive 0xeb8d2444 → bool
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenByIndex 0x4f6ccce7 → uint256
tokenOfOwnerByIndex 0x2f745c59 → uint256
tokenURI 0xc87b56dd → string
totalSupply 0x18160ddd → uint256

Write Contract 21 functions

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

addToPioneer 0x6f97f123
uint256 _blockNumberToExpire
address[] _addresses
uint256[] _values
approve 0x095ea7b3
address to
uint256 tokenId
expirePioneerRound 0xc7d64a18
uint256 _roundNum
flipPresaleState 0xf81227d4
No parameters
flipSaleState 0x34918dfd
No parameters
grantRole 0x2f2ff15d
bytes32 role
address account
mintGhost 0x2feb1d08
uint256 numberOfTokens
mintGhostForPioneer 0xc17d4676
uint256 numGhosts
pickMemory 0x39aaa390
uint256 _tokenId
uint8 _memoryType
string _memoryPhrase
renounceRole 0x36568abe
bytes32 role
address account
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
setGhostPrice 0x36cc484b
uint256 _price
setMaxPurchasePerMint 0xee0a9666
uint256 _maxPurchasePerMint
setProvenanceHash 0x10969523
string provenanceHash
setRandomSeed 0x38f897b8
No parameters
setTokenUriBase 0x6533a6fc
string _tokenUriBase
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
withdraw 0x3ccfd60b
No parameters

Recent Transactions

No transactions found for this address