Address Contract Verified
Address
0x270488657c6724172372615eA8eb2802b233D41c
Balance
0.600000 ETH
Nonce
1
Code Size
15996 bytes
Creator
0xac9d54ca...17Fa at tx 0x60096450...299c5e
Indexed Transactions
0
Contract Bytecode
15996 bytes
0x6080604052600436106101e35760003560e01c806370a0823111610102578063a22cb46511610095578063d2d65ff511610064578063d2d65ff5146105b7578063e74772d8146105d7578063e985e9c514610604578063f2fde38b1461062457600080fd5b8063a22cb4651461052a578063a758e1d31461054a578063b88d4fde14610577578063c87b56dd1461059757600080fd5b80637afe2b3b116100d15780637afe2b3b146104aa57806389476069146104ca5780638da5cb5b146104ea57806395d89b411461051557600080fd5b806370a082311461044d578063714c53981461046d578063715018a614610482578063744b59921461049757600080fd5b806337a78ff31161017a5780635232ac35116101495780635232ac35146103d357806355f804b3146103f3578063564566a8146104135780636352211e1461042d57600080fd5b806337a78ff3146103515780633ccfd60b1461037e57806342842e0e146103935780634d74d3b4146103b357600080fd5b806318160ddd116101b657806318160ddd146102a6578063210cd92d146102c557806323b872dd146102e55780632a55205a1461030557600080fd5b806301ffc9a7146101e857806306fdde031461021d578063081812fc1461023f578063095ea7b314610284575b600080fd5b3480156101f457600080fd5b50610208610203366004612fb3565b610644565b60405190151581526020015b60405180910390f35b34801561022957600080fd5b506102326106a0565b604051610214919061303e565b34801561024b57600080fd5b5061025f61025a366004613051565b610732565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610214565b34801561029057600080fd5b506102a461029f36600461308c565b610821565b005b3480156102b257600080fd5b506007545b604051908152602001610214565b3480156102d157600080fd5b506102a46102e03660046130b8565b6109ad565b3480156102f157600080fd5b506102a46103003660046130d5565b610a75565b34801561031157600080fd5b50610325610320366004613116565b610b16565b6040805173ffffffffffffffffffffffffffffffffffffffff9093168352602083019190915201610214565b34801561035d57600080fd5b50600c5461025f9073ffffffffffffffffffffffffffffffffffffffff1681565b34801561038a57600080fd5b506102a4610bbf565b34801561039f57600080fd5b506102a46103ae3660046130d5565b610d38565b3480156103bf57600080fd5b506102a46103ce3660046130b8565b610d53565b3480156103df57600080fd5b506102a46103ee366004613146565b610e1b565b3480156103ff57600080fd5b506102a461040e366004613163565b610ee6565b34801561041f57600080fd5b506009546102089060ff1681565b34801561043957600080fd5b5061025f610448366004613051565b610f74565b34801561045957600080fd5b506102b76104683660046130b8565b611036565b34801561047957600080fd5b50610232611104565b34801561048e57600080fd5b506102a4611113565b6102a46104a53660046131d5565b6111a0565b3480156104b657600080fd5b506102b76104c536600461322b565b6113db565b3480156104d657600080fd5b506102a46104e53660046130b8565b611403565b3480156104f657600080fd5b5060065473ffffffffffffffffffffffffffffffffffffffff1661025f565b34801561052157600080fd5b506102326115e8565b34801561053657600080fd5b506102a4610545366004613270565b6115f7565b34801561055657600080fd5b5061056a610565366004613051565b61170d565b60405161021491906132a9565b34801561058357600080fd5b506102a46105923660046134a0565b611835565b3480156105a357600080fd5b506102326105b2366004613051565b6118dd565b3480156105c357600080fd5b506102a46105d2366004613146565b6119a6565b3480156105e357600080fd5b50600b5461025f9073ffffffffffffffffffffffffffffffffffffffff1681565b34801561061057600080fd5b5061020861061f36600461354f565b611a58565b34801561063057600080fd5b506102a461063f3660046130b8565b611af7565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f2a55205a00000000000000000000000000000000000000000000000000000000148061069a575061069a82611c27565b92915050565b6060600080546106af9061357d565b80601f01602080910402602001604051908101604052809291908181526020018280546106db9061357d565b80156107285780601f106106fd57610100808354040283529160200191610728565b820191906000526020600020905b81548152906001019060200180831161070b57829003601f168201915b5050505050905090565b6000818152600260205260408120546c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff166107f8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e000000000000000000000000000000000000000060648201526084015b60405180910390fd5b5060009081526004602052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b600061082c82610f74565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036108e9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f720000000000000000000000000000000000000000000000000000000000000060648201526084016107ef565b3373ffffffffffffffffffffffffffffffffffffffff8216148061091257506109128133611a58565b61099e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016107ef565b6109a88383611d0a565b505050565b60065473ffffffffffffffffffffffffffffffffffffffff163314610a2e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b600c80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b610a7f3382611daa565b610b0b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016107ef565b6109a8838383611e35565b60008281526002602052604081205481906c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff16610b83576040517fbce35a4700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60065473ffffffffffffffffffffffffffffffffffffffff166064610ba98560056135ff565b610bb39190613645565b915091505b9250929050565b60065473ffffffffffffffffffffffffffffffffffffffff163314610c40576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b476000819003610c7c576040517f5e6202b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080610c9e60065473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff168360405160006040518083038185875af1925050503d8060008114610cf5576040519150601f19603f3d011682016040523d82523d6000602084013e610cfa565b606091505b5091509150816109a857806040517fdf76ce9f0000000000000000000000000000000000000000000000000000000081526004016107ef919061303e565b6109a883838360405180602001604052806000815250611835565b60065473ffffffffffffffffffffffffffffffffffffffff163314610dd4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b600b80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60065473ffffffffffffffffffffffffffffffffffffffff163314610e9c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b600c805491151574010000000000000000000000000000000000000000027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff909216919091179055565b60065473ffffffffffffffffffffffffffffffffffffffff163314610f67576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b60086109a88284836136a7565b6000818152600260205260408120546c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff168061069a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e000000000000000000000000000000000000000000000060648201526084016107ef565b600073ffffffffffffffffffffffffffffffffffffffff82166110db576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f20616464726573730000000000000000000000000000000000000000000060648201526084016107ef565b5073ffffffffffffffffffffffffffffffffffffffff1660009081526003602052604090205490565b6060600880546106af9061357d565b60065473ffffffffffffffffffffffffffffffffffffffff163314611194576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b61119e600061209b565b565b60095460ff166111db576040517eecac0100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6111e860608201826137c1565b823560208401356111fc6040860186613826565b600c5473ffffffffffffffffffffffffffffffffffffffff1661124b576040517f7223845600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b824210611284576040517f4c746c9200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006112b47fa5d81b40d1f9f923129d42342f185faadbefce113096acb435f5a27afb1289893387878787612112565b600c54604080516020601f8b018190048102820181019092528981529293506113129273ffffffffffffffffffffffffffffffffffffffff9092169184918b908b908190840183828082843760009201919091525061218692505050565b611348576040517f9a69144c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8735348114611383576040517fd6ff0e4500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b61139360408b018b613826565b90508110156113cf576113c76113ac60408c018c613826565b838181106113bc576113bc61388e565b905060400201612374565b600101611386565b50505050505050505050565b6000806113e9858585612538565b6000908152600a60205260409020549150505b9392505050565b60065473ffffffffffffffffffffffffffffffffffffffff163314611484576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906370a0823190602401602060405180830381865afa1580156114f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061151591906138bd565b905080600003611551576040517f5e6202b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fa9059cbb0000000000000000000000000000000000000000000000000000000081523360048201526024810182905273ffffffffffffffffffffffffffffffffffffffff83169063a9059cbb906044016020604051808303816000875af11580156115c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a891906138d6565b6060600180546106af9061357d565b3373ffffffffffffffffffffffffffffffffffffffff831603611676576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016107ef565b33600081815260056020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b61173f6040518060a0016040528060608152602001606081526020016000815260200160008152602001606081525090565b60008281526002602052604080822054600b5482517f7465ce5c00000000000000000000000000000000000000000000000000000000815265ffffffffffff8084166004830181905260248301899052660100000000000090940416604482018190529351929473ffffffffffffffffffffffffffffffffffffffff90921692637465ce5c926064808401939192918290030181865afa1580156117e7573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820160405261182d9190810190613a24565b949350505050565b61183f3383611daa565b6118cb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016107ef565b6118d784848484612607565b50505050565b606061191d826000908152600260205260409020546c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff16151590565b611953576040517fdf11708f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006008611960846126aa565b604051602001611971929190613aed565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190529392505050565b60065473ffffffffffffffffffffffffffffffffffffffff163314611a27576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b600980547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b600c5460009074010000000000000000000000000000000000000000900460ff168015611aae5750731e0049783f008a0085193e00003d00cd54003c7173ffffffffffffffffffffffffffffffffffffffff8316145b15611abb5750600161069a565b5073ffffffffffffffffffffffffffffffffffffffff918216600090815260056020908152604080832093909416825291909152205460ff1690565b60065473ffffffffffffffffffffffffffffffffffffffff163314611b78576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ef565b73ffffffffffffffffffffffffffffffffffffffff8116611c1b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016107ef565b611c248161209b565b50565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f80ac58cd000000000000000000000000000000000000000000000000000000001480611cba57507fffffffff0000000000000000000000000000000000000000000000000000000082167f5b5e139f00000000000000000000000000000000000000000000000000000000145b8061069a57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff0000000000000000000000000000000000000000000000000000000083161461069a565b600081815260046020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84169081179091558190611d6482610f74565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600080611db683610f74565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480611e2557508373ffffffffffffffffffffffffffffffffffffffff16611e0d84610732565b73ffffffffffffffffffffffffffffffffffffffff16145b8061182d575061182d8185611a58565b8273ffffffffffffffffffffffffffffffffffffffff16611e5582610f74565b73ffffffffffffffffffffffffffffffffffffffff1614611ef8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201527f73206e6f74206f776e000000000000000000000000000000000000000000000060648201526084016107ef565b73ffffffffffffffffffffffffffffffffffffffff8216611f9a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f726573730000000000000000000000000000000000000000000000000000000060648201526084016107ef565b611fa5600082611d0a565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600360205260408120805460019290611fdb908490613bbb565b909155505073ffffffffffffffffffffffffffffffffffffffff82166000908152600360205260408120805460019290612016908490613bce565b9091555050600081815260026020526040808220805473ffffffffffffffffffffffffffffffffffffffff8087166c0100000000000000000000000081026bffffffffffffffffffffffff9093169290921790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6006805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008061212287878787876127df565b604080517f1901000000000000000000000000000000000000000000000000000000000000602080830191909152602282018c9052604280830185905283518084039091018152606290920190925280519101209091505b98975050505050505050565b6000806000612195858561294b565b909250905060008160048111156121ae576121ae613be1565b1480156121e657508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b156121f6576001925050506113fc565b6000808773ffffffffffffffffffffffffffffffffffffffff16631626ba7e60e01b888860405160240161222b929190613c10565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009094169390931790925290516122b49190613c29565b600060405180830381855afa9150503d80600081146122ef576040519150601f19603f3d011682016040523d82523d6000602084013e6122f4565b606091505b5091509150818015612307575080516020145b801561217a575080517f1626ba7e00000000000000000000000000000000000000000000000000000000906123459083016020908101908401613c45565b7fffffffff00000000000000000000000000000000000000000000000000000000161498975050505050505050565b8060006123983361238b6040850160208601613c62565b6104c56020860186613c62565b11156123d0576040517f181ede8900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b5473ffffffffffffffffffffffffffffffffffffffff168063db9eee7d6123ff6040850160208601613c62565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815265ffffffffffff9091166004820152602401602060405180830381865afa15801561245a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061247e91906138d6565b6124b4576040517f7c66445400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006124c7600780546001019081905590565b905060006124f1336124df6040880160208901613c62565b6124ec6020890189613c62565b612538565b6000818152600a6020908152604091829020859055919250612531913391859161251f918a01908a01613c62565b61252c60208a018a613c62565b6129b6565b5050505050565b600065ffffffffffff8216156125a4576040517fffffffffffff000000000000000000000000000000000000000000000000000060d084811b8216602084015285901b166026820152602c015b60405160208183030381529060405261259d90613c7d565b90506113fc565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606086901b1660208201527fffffffffffff000000000000000000000000000000000000000000000000000060d085901b166034820152603a01612585565b612612848484611e35565b61261e84848484612bb0565b6118d7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016107ef565b6060816000036126ed57505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115612717578061270181613cbf565b91506127109050600a83613645565b91506126f1565b60008167ffffffffffffffff81111561273257612732613390565b6040519080825280601f01601f19166020018201604052801561275c576020820181803683370190505b5090505b841561182d57612771600183613bbb565b915061277e600a86613cf7565b612789906030613bce565b60f81b81838151811061279e5761279e61388e565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506127d8600a86613645565b9450612760565b6000808267ffffffffffffffff8111156127fb576127fb613390565b604051908082528060200260200182016040528015612824578160200160208202803683370190505b50905060005b83811015612877576128528585838181106128475761284761388e565b905060400201612da3565b8282815181106128645761286461388e565b602090810291909101015260010161282a565b506040518060600160405280602b8152602001613e1c602b91396040516020016128a19190613d0b565b60405160208183030381529060405280519060200120878787846040516020016128cb9190613d9c565b6040516020818303038152906040528051906020012060405160200161292995949392919094855273ffffffffffffffffffffffffffffffffffffffff93909316602085015260408401919091526060830152608082015260a00190565b6040516020818303038152906040528051906020012091505095945050505050565b60008082516041036129815760208301516040840151606085015160001a61297587828585612e25565b94509450505050610bb8565b82516040036129aa576020830151604084015161299f868383612f3d565b935093505050610bb8565b50600090506002610bb8565b73ffffffffffffffffffffffffffffffffffffffff8416612a33576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016107ef565b6000838152600260205260409020546c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff1615612acf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107ef565b73ffffffffffffffffffffffffffffffffffffffff84166000908152600360205260408120805460019290612b05908490613bce565b909155505060008381526002602052604080822065ffffffffffff84811666010000000000000273ffffffffffffffffffffffffffffffffffffffff89166c0100000000000000000000000081027fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016928816929092171790915590518592907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a450505050565b600073ffffffffffffffffffffffffffffffffffffffff84163b15612d98576040517f150b7a0200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85169063150b7a0290612c27903390899088908890600401613dd2565b6020604051808303816000875af1925050508015612c80575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252612c7d91810190613c45565b60015b612d4d573d808015612cae576040519150601f19603f3d011682016040523d82523d6000602084013e612cb3565b606091505b508051600003612d45576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016107ef565b805181602001fd5b7fffffffff00000000000000000000000000000000000000000000000000000000167f150b7a020000000000000000000000000000000000000000000000000000000014905061182d565b506001949350505050565b60006040518060600160405280602b8152602001613e1c602b913980519060200120826020016020810190612dd89190613c62565b612de56020850185613c62565b60408051602081019490945265ffffffffffff92831690840152166060820152608001604051602081830303815290604052805190602001209050919050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115612e5c5750600090506003612f34565b8460ff16601b14158015612e7457508460ff16601c14155b15612e855750600090506004612f34565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612ed9573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116612f2d57600060019250925050612f34565b9150600090505b94509492505050565b6000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831660ff84901c601b01612f7787828885612e25565b935093505050935093915050565b7fffffffff0000000000000000000000000000000000000000000000000000000081168114611c2457600080fd5b600060208284031215612fc557600080fd5b81356113fc81612f85565b60005b83811015612feb578181015183820152602001612fd3565b50506000910152565b6000815180845261300c816020860160208601612fd0565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6020815260006113fc6020830184612ff4565b60006020828403121561306357600080fd5b5035919050565b73ffffffffffffffffffffffffffffffffffffffff81168114611c2457600080fd5b6000806040838503121561309f57600080fd5b82356130aa8161306a565b946020939093013593505050565b6000602082840312156130ca57600080fd5b81356113fc8161306a565b6000806000606084860312156130ea57600080fd5b83356130f58161306a565b925060208401356131058161306a565b929592945050506040919091013590565b6000806040838503121561312957600080fd5b50508035926020909101359150565b8015158114611c2457600080fd5b60006020828403121561315857600080fd5b81356113fc81613138565b6000806020838503121561317657600080fd5b823567ffffffffffffffff8082111561318e57600080fd5b818501915085601f8301126131a257600080fd5b8135818111156131b157600080fd5b8660208285010111156131c357600080fd5b60209290920196919550909350505050565b6000602082840312156131e757600080fd5b813567ffffffffffffffff8111156131fe57600080fd5b8201608081850312156113fc57600080fd5b803565ffffffffffff8116811461322657600080fd5b919050565b60008060006060848603121561324057600080fd5b833561324b8161306a565b925061325960208501613210565b915061326760408501613210565b90509250925092565b6000806040838503121561328357600080fd5b823561328e8161306a565b9150602083013561329e81613138565b809150509250929050565b60006020808352835160a0828501526132c560c0850182612ff4565b9050818501517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe060408187850301818801526133018484612ff4565b93508088015160608801526060880151608088015260808801519250818785030160a08801528383518086528686019150868160051b870101878601955060005b8281101561338157858883030184528651805186845261336487850182612ff4565b918b0151938b019390935296890196938901939150600101613342565b509a9950505050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040805190810167ffffffffffffffff811182821017156133e2576133e2613390565b60405290565b60405160a0810167ffffffffffffffff811182821017156133e2576133e2613390565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff8111828210171561345257613452613390565b604052919050565b600067ffffffffffffffff82111561347457613474613390565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b600080600080608085870312156134b657600080fd5b84356134c18161306a565b935060208501356134d18161306a565b925060408501359150606085013567ffffffffffffffff8111156134f457600080fd5b8501601f8101871361350557600080fd5b80356135186135138261345a565b61340b565b81815288602083850101111561352d57600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b6000806040838503121561356257600080fd5b823561356d8161306a565b9150602083013561329e8161306a565b600181811c9082168061359157607f821691505b6020821081036135ca577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b808202811582820484141761069a5761069a6135d0565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60008261365457613654613616565b500490565b601f8211156109a857600081815260208120601f850160051c810160208610156136805750805b601f850160051c820191505b8181101561369f5782815560010161368c565b505050505050565b67ffffffffffffffff8311156136bf576136bf613390565b6136d3836136cd835461357d565b83613659565b6000601f84116001811461372557600085156136ef5750838201355b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600387901b1c1916600186901b178355612531565b6000838152602090207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0861690835b828110156137745786850135825560209485019460019092019101613754565b50868210156137af577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88860031b161c19848701351681555b505060018560011b0183555050505050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126137f657600080fd5b83018035915067ffffffffffffffff82111561381157600080fd5b602001915036819003821315610bb857600080fd5b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261385b57600080fd5b83018035915067ffffffffffffffff82111561387657600080fd5b6020019150600681901b3603821315610bb857600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156138cf57600080fd5b5051919050565b6000602082840312156138e857600080fd5b81516113fc81613138565b600082601f83011261390457600080fd5b81516139126135138261345a565b81815284602083860101111561392757600080fd5b61182d826020830160208701612fd0565b600082601f83011261394957600080fd5b8151602067ffffffffffffffff8083111561396657613966613390565b8260051b61397583820161340b565b938452858101830193838101908886111561398f57600080fd5b84880192505b8583101561217a578251848111156139ad5760008081fd5b88016040818b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0018113156139e35760008081fd5b6139eb6133bf565b87830151878111156139fd5760008081fd5b613a0b8d8a838701016138f3565b8252509101518682015282529184019190840190613995565b600060208284031215613a3657600080fd5b815167ffffffffffffffff80821115613a4e57600080fd5b9083019060a08286031215613a6257600080fd5b613a6a6133e8565b825182811115613a7957600080fd5b613a85878286016138f3565b825250602083015182811115613a9a57600080fd5b613aa6878286016138f3565b6020830152506040830151604082015260608301516060820152608083015182811115613ad257600080fd5b613ade87828601613938565b60808301525095945050505050565b6000808454613afb8161357d565b60018281168015613b135760018114613b4657613b75565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0084168752821515830287019450613b75565b8860005260208060002060005b85811015613b6c5781548a820152908401908201613b53565b50505082870194505b507f2f00000000000000000000000000000000000000000000000000000000000000845286519250613bad8382860160208a01612fd0565b919092010195945050505050565b8181038181111561069a5761069a6135d0565b8082018082111561069a5761069a6135d0565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b82815260406020820152600061182d6040830184612ff4565b60008251613c3b818460208701612fd0565b9190910192915050565b600060208284031215613c5757600080fd5b81516113fc81612f85565b600060208284031215613c7457600080fd5b6113fc82613210565b805160208083015191908110156135ca577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60209190910360031b1b16919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203613cf057613cf06135d0565b5060010190565b600082613d0657613d06613616565b500690565b7f4d696e742861646472657373206d696e746572416464726573732c75696e743281527f353620746f74616c436f73742c75696e74323536206578706972657341742c5460208201527f6f6b656e446174615b5d20746f6b656e44617461417272617929000000000000604082015260008251613d8f81605a850160208701612fd0565b91909101605a0192915050565b815160009082906020808601845b83811015613dc657815185529382019390820190600101613daa565b50929695505050505050565b600073ffffffffffffffffffffffffffffffffffffffff808716835280861660208401525083604083015260806060830152613e116080830184612ff4565b969550505050505056fe546f6b656e446174612875696e74333220617274696661637449642c75696e743332207769746368496429a2646970667358221220022fdd079c4c3ff68a5df771106ee8b05645682a9d43881d3e9ff11a196f2e3064736f6c63430008110033
Verified Source Code Full Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: Yes (100000 runs)
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);
}
}
}
}
IERC165.sol 5 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/introspection/IERC165.sol";
IERC2981.sol 22 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Interface for the NFT Royalty Standard
*/
interface IERC2981 is IERC165 {
/**
* @dev Called with the sale price to determine how much royalty is owed and to whom.
* @param tokenId - the NFT asset queried for royalty information
* @param salePrice - the sale price of the NFT asset specified by `tokenId`
* @return receiver - address of who should be sent the royalty payment
* @return royaltyAmount - the royalty payment amount for `salePrice`
*/
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address receiver, uint256 royaltyAmount);
}
IERC20.sol 5 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol";
IERC20.sol 81 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
IERC721.sol 5 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../token/ERC721/IERC721.sol";
NarratorsHut.sol 415 lines
//SPDX-License-Identifier: MIT
//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721)
pragma solidity ^0.8.17;
/*
.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。
▄┐
▓▌ ▓▓╓██▌
████▓██████████`
▄████████████████µ
▄█████████████╬█████▄Γ
╓▓█████████████▓╬╬██████▓▄
,▄████████████▓▓▓▒╬╠╬████████▓,.......
,▄▄██████████████▓▓█▒╬▒╠╣╬▓▓╬╠▓▓▓██▓▄░░░░░.┌
..'╙╙│▀▀██████▓████████▓▓▓▓▓▓▓▓▓╣▓▓▓█▀╙╙▀░░░░░│.
.¡░░░░╬╣▒███╬▓╫▓╫▓╫████▓██▓▓▓▓████████▒ε░░╓▓▓▓▓▀⌐
┌.¡░░░░╟╫╣██████████████▓██████▓▓▓▓▓█████████▓████▌─
'.│░░░Q▄▓█████████████████████▓▓█▓▓██████████▓▓████▓▄▄
,▄▓▓████████████████████▓█▓█▓▓▓▓█▓▒╚╚█▓▓██▓▓▓▓██████▓▓═
"╠╠▀████████████████████▓▓█▓█▓▓▓█▓▓▓░░▒╣╬▓╣██▓▓▓█████▌ φε
└╠░████╣██╬██▓█████████▓▓▓▓▓▓███▓▓▓╬╬╬╣▓▓╣█▓████████▓████▒
▐▌╓╠▄╣████████▓▓██████████████████▓▓▓╬▓▓▓╬▓╣▓██████▓██▓▀▀▀▀░╛
║█████████████████████████████████▓▓╣██▓█╣▓╣▓▓▓╣╬╣╬╬╬╬▒╠│░'"
╚████████████████████████████████▓▓╣╬▓▀▓█▓▓╣▓▓▓▓▓▓▓▓╬╬╠▒░.
,Q ╓▄░░╬╚███████████████████████████▓╫▓▓▓███▓▓╬▓█▓▓╬▓▓╬╬▒░░
]██▌ └ⁿ"░╚╚░╚╚▀▀▀██▀█████████████████▓▓▓█▓█▓▓███▓▓▓▓╬╣▓╬╬▀Γ=
¬ '''"░""Γ"░Γ░░Γ╙╙▀▀▀▀█████████████╬███▓╬▓▓██╬╬▓░░░'
' `"""""░╚╙╟╚╚╚╠╣╬╬╬╬╬▓▓▀╬╩▒▓▓▓∩'
` "└└╙"╙╙Γ""`
s _
.. :8 u
.u . @L .d`` .88 u. u. 88Nu. u. u. u.
. .d88B :@8c 9888i .dL @8Ne. .u :888ooo ...ue888b . ...ue888b '88888.o888c .u x@88k u@88c.
.udR88N ="8888f8888r `Y888k:*888. %8888:u@88N -*8888888 888R Y888r .udR88N 888R Y888r ^8888 8888 ud8888. ^"8888""8888"
<888'888k 4888>'88" 888E 888I `888I 888. 8888 888R I888> <888'888k 888R I888> 8888 8888 :888'8888. 8888 888R
9888 'Y" 4888> ' 888E 888I 888I 888I 8888 888R I888> 9888 'Y" 888R I888> 8888 8888 d888 '88%" 8888 888R
9888 4888> 888E 888I 888I 888I 8888 888R I888> 9888 888R I888> 8888 8888 8888.+" 8888 888R
9888 .d888L .+ 888E 888I uW888L 888' .8888Lu= u8888cJ888 9888 u8888cJ888 .8888b.888P 8888L 8888 888R
?8888u../ ^"8888*" x888N><888' '*88888Nu88P ^%888* "*888*P" ?8888u../ "*888*P" ^Y8888*"" '8888c. .+ "*88*" 8888"
"8888P' "Y" "88" 888 ~ '88888F` 'Y" 'Y" "8888P' 'Y" `Y" "88888% "" 'Y"
"P' 88F 888 ^ "P' "YP'
98" *8E
./" '8>
~` "
.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。
*/
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import "./utils/Signatures.sol";
import "./ERC721Hut.sol";
import "./interfaces/INarratorsHut.sol";
contract NarratorsHut is INarratorsHut, ERC721Hut, IERC2981, Ownable {
uint256 private tokenCounter;
string private baseURI;
bool public isSaleActive = false;
// Mapping to keep track of whether a combination of
// address, artifactId, and witchId have minted an artifact.
mapping(bytes32 => uint256) private _tokenIdsByMintKey;
address public metadataContractAddress;
address public narratorAddress;
bool private isOpenSeaConduitActive = true;
// Domain Separator is the EIP-712 defined structure that defines what contract
// and chain these signatures can be used for. This ensures people can't take
// a signature used to mint on one contract and use it for another, or a signature
// from testnet to replay on mainnet.
// It has to be created in the constructor so we can dynamically grab the chainId.
bytes32 private immutable domainSeparator;
constructor(
address _metadataContractAddress,
address _narratorAddress,
string memory _baseURI
) ERC721Hut("The Narrator's Hut", "HUT") {
// This should match what's in the client side signing code
domainSeparator = keccak256(
abi.encode(
Signatures.DOMAIN_TYPEHASH,
keccak256(bytes("MintToken")),
keccak256(bytes("1")),
block.chainid,
address(this)
)
);
metadataContractAddress = _metadataContractAddress;
narratorAddress = _narratorAddress;
baseURI = _baseURI;
}
// ============ ACCESS CONTROL/SANITY MODIFIERS ============
modifier saleIsActive() {
if (!isSaleActive) revert SaleIsNotActive();
_;
}
modifier isCorrectPayment(uint256 totalCost) {
if (totalCost != msg.value) revert IncorrectPaymentReceived();
_;
}
modifier isValidMintSignature(
bytes calldata mintSignature,
uint256 totalCost,
uint256 expiresAt,
TokenData[] calldata tokenDataArray
) {
if (narratorAddress == address(0)) {
revert InvalidNarratorAddress();
}
if (block.timestamp >= expiresAt) {
revert MintSignatureHasExpired();
}
// NOTE: we don't use an explicit nonce for the signature
// since we are enforcing on-chain that a combination of
// address, witchId, and artifactId can only ever mint once.
// This implicitly doubles as our nonce for the signature,
// since it also ensures a signature can only be used once
// and prevents any replay attacks.
bytes32 recreatedHash = Signatures.recreateMintHash(
domainSeparator,
msg.sender,
totalCost,
expiresAt,
tokenDataArray
);
if (
!SignatureChecker.isValidSignatureNow(
narratorAddress,
recreatedHash,
mintSignature
)
) {
revert InvalidMintSignature();
}
_;
}
modifier canMintArtifact(TokenData calldata tokenData) {
if (
getTokenIdForArtifact(
msg.sender,
tokenData.artifactId,
tokenData.witchId
) > 0
) {
revert ArtifactCapReached();
}
INarratorsHutMetadata metadataContract = INarratorsHutMetadata(
metadataContractAddress
);
if (!metadataContract.canMintArtifact(tokenData.artifactId)) {
revert ArtifactIsNotMintable();
}
_;
}
// ============ PUBLIC FUNCTIONS FOR MINTING ============
function mint(MintInput calldata mintInput)
external
payable
saleIsActive
isValidMintSignature(
mintInput.mintSignature,
mintInput.totalCost,
mintInput.expiresAt,
mintInput.tokenDataArray
)
isCorrectPayment(mintInput.totalCost)
{
for (uint256 i; i < mintInput.tokenDataArray.length; ) {
mintArtifact(mintInput.tokenDataArray[i]);
unchecked {
++i;
}
}
}
// ============ PUBLIC READ-ONLY FUNCTIONS ============
function getArtifactForToken(uint256 tokenId)
external
view
returns (ArtifactManifestation memory)
{
(uint256 artifactId, uint256 witchId) = _getDataForToken(tokenId);
return
INarratorsHutMetadata(metadataContractAddress).getArtifactForToken(
artifactId,
tokenId,
witchId
);
}
function getTokenIdForArtifact(
address addr,
uint48 artifactId,
uint48 witchId
) public view returns (uint256) {
bytes32 mintKey = getMintKey(addr, artifactId, witchId);
return _tokenIdsByMintKey[mintKey];
}
function getBaseURI() external view returns (string memory) {
return baseURI;
}
function totalSupply() external view returns (uint256) {
return tokenCounter;
}
// ============ OWNER-ONLY ADMIN FUNCTIONS ============
function setIsSaleActive(bool _status) external onlyOwner {
isSaleActive = _status;
}
// enables us to disable gasless listings for security in case
// opensea ever shuts down or is compromised
function setIsOpenSeaConduitActive(bool _isOpenSeaConduitActive)
external
onlyOwner
{
isOpenSeaConduitActive = _isOpenSeaConduitActive;
}
function setMetadataContractAddress(address _metadataContractAddress)
external
onlyOwner
{
metadataContractAddress = _metadataContractAddress;
}
function setNarratorAddress(address _narratorAddress) external onlyOwner {
narratorAddress = _narratorAddress;
}
function setBaseURI(string calldata _baseURI) external onlyOwner {
baseURI = _baseURI;
}
function withdraw() external onlyOwner {
uint256 balance = address(this).balance;
if (balance == 0) {
revert PaymentBalanceZero();
}
(bool success, bytes memory result) = owner().call{value: balance}("");
if (!success) {
revert PaymentUnsuccessful(result);
}
}
function withdrawToken(IERC20 token) external onlyOwner {
uint256 balance = token.balanceOf(address(this));
if (balance == 0) {
revert PaymentBalanceZero();
}
token.transfer(msg.sender, balance);
}
// ============ SUPPORTING FUNCTIONS ============
function nextTokenId() private returns (uint256) {
unchecked {
++tokenCounter;
}
return tokenCounter;
}
function getMintKey(
address addr,
uint48 artifactId,
uint48 witchId
) private pure returns (bytes32) {
// We keep track of whether a witch or an address have minted
// artifacts of a specific type in order to enforce a mint
// cap of one artifact type per witch, or per address if
// not a witch owner.
if (witchId != 0) {
// If minting with a witch, record that the witch has
// minted the specified artifact type
return bytes32(abi.encodePacked(witchId, artifactId));
} else {
// If minting without a witch, record that the address has
// minted the specified artifact type
return bytes32(abi.encodePacked(addr, artifactId));
}
}
function mintArtifact(TokenData calldata tokenData)
private
canMintArtifact(tokenData)
{
uint256 tokenId = nextTokenId();
// Record that the witch, or address, has minted the
// given artifact type
bytes32 mintKey = getMintKey(
msg.sender,
tokenData.artifactId,
tokenData.witchId
);
_tokenIdsByMintKey[mintKey] = tokenId;
_mint(msg.sender, tokenId, tokenData.artifactId, tokenData.witchId);
}
// ============ FUNCTION OVERRIDES ============
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721Hut, IERC165)
returns (bool)
{
return
interfaceId == type(IERC2981).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev Override isApprovedForAll to allowlist user's OpenSea proxy accounts to enable gas-less listings.
*/
function isApprovedForAll(address owner, address operator)
public
view
override
returns (bool)
{
if (
isOpenSeaConduitActive &&
// NOTE: Now that OpenSea has migrated to Seaport, we can check if
// the operator is OpenSea's conduit.
// The address is the same across all networks thanks to CREATE2.
operator == 0x1E0049783F008A0085193E00003D00cd54003c71
) {
return true;
}
return super.isApprovedForAll(owner, operator);
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
if (!_exists(tokenId)) revert TokenURIQueryForNonexistentToken();
string memory url = string.concat(
baseURI,
"/",
Strings.toString(tokenId)
);
return url;
}
/**
* @dev See {IERC165-royaltyInfo}.
*/
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
override
returns (address receiver, uint256 royaltyAmount)
{
if (!_exists(tokenId)) revert RoyaltiesQueryForNonexistentToken();
return (owner(), (salePrice * 5) / 100);
}
// ============ ERRORS ============
error SaleIsNotActive();
error IncorrectPaymentReceived();
error ArtifactCapReached();
error ArtifactIsNotMintable();
error RoyaltiesQueryForNonexistentToken();
error TokenURIQueryForNonexistentToken();
error MintSignatureHasExpired();
error InvalidNarratorAddress();
error InvalidMintSignature();
error PaymentBalanceZero();
error PaymentUnsuccessful(bytes result);
}
ERC721Hut.sol 575 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
/*
.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。
▄┐
▓▌ ▓▓╓██▌
████▓██████████`
▄████████████████µ
▄█████████████╬█████▄Γ
╓▓█████████████▓╬╬██████▓▄
,▄████████████▓▓▓▒╬╠╬████████▓,.......
,▄▄██████████████▓▓█▒╬▒╠╣╬▓▓╬╠▓▓▓██▓▄░░░░░.┌
..'╙╙│▀▀██████▓████████▓▓▓▓▓▓▓▓▓╣▓▓▓█▀╙╙▀░░░░░│.
.¡░░░░╬╣▒███╬▓╫▓╫▓╫████▓██▓▓▓▓████████▒ε░░╓▓▓▓▓▀⌐
┌.¡░░░░╟╫╣██████████████▓██████▓▓▓▓▓█████████▓████▌─
'.│░░░Q▄▓█████████████████████▓▓█▓▓██████████▓▓████▓▄▄
,▄▓▓████████████████████▓█▓█▓▓▓▓█▓▒╚╚█▓▓██▓▓▓▓██████▓▓═
"╠╠▀████████████████████▓▓█▓█▓▓▓█▓▓▓░░▒╣╬▓╣██▓▓▓█████▌ φε
└╠░████╣██╬██▓█████████▓▓▓▓▓▓███▓▓▓╬╬╬╣▓▓╣█▓████████▓████▒
▐▌╓╠▄╣████████▓▓██████████████████▓▓▓╬▓▓▓╬▓╣▓██████▓██▓▀▀▀▀░╛
║█████████████████████████████████▓▓╣██▓█╣▓╣▓▓▓╣╬╣╬╬╬╬▒╠│░'"
╚████████████████████████████████▓▓╣╬▓▀▓█▓▓╣▓▓▓▓▓▓▓▓╬╬╠▒░.
,Q ╓▄░░╬╚███████████████████████████▓╫▓▓▓███▓▓╬▓█▓▓╬▓▓╬╬▒░░
]██▌ └ⁿ"░╚╚░╚╚▀▀▀██▀█████████████████▓▓▓█▓█▓▓███▓▓▓▓╬╣▓╬╬▀Γ=
¬ '''"░""Γ"░Γ░░Γ╙╙▀▀▀▀█████████████╬███▓╬▓▓██╬╬▓░░░'
' `"""""░╚╙╟╚╚╚╠╣╬╬╬╬╬▓▓▀╬╩▒▓▓▓∩'
` "└└╙"╙╙Γ""`
s _
.. :8 u
.u . @L .d`` .88 u. u. 88Nu. u. u. u.
. .d88B :@8c 9888i .dL @8Ne. .u :888ooo ...ue888b . ...ue888b '88888.o888c .u x@88k u@88c.
.udR88N ="8888f8888r `Y888k:*888. %8888:u@88N -*8888888 888R Y888r .udR88N 888R Y888r ^8888 8888 ud8888. ^"8888""8888"
<888'888k 4888>'88" 888E 888I `888I 888. 8888 888R I888> <888'888k 888R I888> 8888 8888 :888'8888. 8888 888R
9888 'Y" 4888> ' 888E 888I 888I 888I 8888 888R I888> 9888 'Y" 888R I888> 8888 8888 d888 '88%" 8888 888R
9888 4888> 888E 888I 888I 888I 8888 888R I888> 9888 888R I888> 8888 8888 8888.+" 8888 888R
9888 .d888L .+ 888E 888I uW888L 888' .8888Lu= u8888cJ888 9888 u8888cJ888 .8888b.888P 8888L 8888 888R
?8888u../ ^"8888*" x888N><888' '*88888Nu88P ^%888* "*888*P" ?8888u../ "*888*P" ^Y8888*"" '8888c. .+ "*88*" 8888"
"8888P' "Y" "88" 888 ~ '88888F` 'Y" 'Y" "8888P' 'Y" `Y" "88888% "" 'Y"
"P' 88F 888 ^ "P' "YP'
98" *8E
./" '8>
~` "
.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。.・。.・゜✭・.・✫・゜・。..・。.・゜✭・.・✫・゜・。.✭・.・✫・゜・。..・✫・゜・。
*/
import "@openzeppelin/contracts/interfaces/IERC721.sol";
import "@openzeppelin/contracts/interfaces/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
// Packed into a single 256-bit slot
struct TokenDataStorage {
uint48 artifactId;
uint48 witchId;
address owner; // 160 bits
}
/**
* @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 ERC721Hut 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 token data
mapping(uint256 => TokenDataStorage) private _tokenDataStorage;
// Mapping owner address to token counnts
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 = _tokenDataStorage[tokenId].owner;
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 = ERC721Hut.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 _tokenDataStorage[tokenId].owner != 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)
{
address owner = ERC721Hut.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,
uint48 artifactId,
uint48 witchId
) internal virtual {
_safeMint(to, tokenId, artifactId, witchId, "");
}
/**
* @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,
uint48 artifactId,
uint48 witchId,
bytes memory _data
) internal virtual {
_mint(to, tokenId, artifactId, witchId);
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,
uint48 artifactId,
uint48 witchId
) 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;
_tokenDataStorage[tokenId].owner = to;
_tokenDataStorage[tokenId].artifactId = artifactId;
_tokenDataStorage[tokenId].witchId = witchId;
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 = ERC721Hut.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _tokenDataStorage[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(
ERC721Hut.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;
_tokenDataStorage[tokenId].owner = 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(ERC721Hut.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 Extracts the artifactId and counter
* that are packed into the uint256 tokenId.
* @return (uint48 artifactId, uint48 witchId)
*/
function _getDataForToken(uint256 tokenId)
internal
view
returns (uint48, uint48)
{
uint48 artifactId = _tokenDataStorage[tokenId].artifactId;
uint48 witchId = _tokenDataStorage[tokenId].witchId;
return (artifactId, witchId);
}
/**
* @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 {}
}
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;
}
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);
}
}
SignatureChecker.sol 35 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ECDSA.sol";
import "../Address.sol";
import "../../interfaces/IERC1271.sol";
/**
* @dev Signature verification helper: Provide a single mechanism to verify both private-key (EOA) ECDSA signature and
* ERC1271 contract sigantures. Using this instead of ECDSA.recover in your contract will make them compatible with
* smart contract wallets such as Argent and Gnosis.
*
* Note: unlike ECDSA signatures, contract signature's are revocable, and the outcome of this function can thus change
* through time. It could return true at block N and false at block N+1 (or the opposite).
*
* _Available since v4.1._
*/
library SignatureChecker {
function isValidSignatureNow(
address signer,
bytes32 hash,
bytes memory signature
) internal view returns (bool) {
(address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
if (error == ECDSA.RecoverError.NoError && recovered == signer) {
return true;
}
(bool success, bytes memory result) = signer.staticcall(
abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
);
return (success && result.length == 32 && abi.decode(result, (bytes4)) == IERC1271.isValidSignature.selector);
}
}
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;
}
}
ECDSA.sol 219 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s;
uint8 v;
assembly {
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
v := add(shr(255, vs), 27)
}
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
IERC1271.sol 18 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*
* _Available since v4.1._
*/
interface IERC1271 {
/**
* @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed
* @param signature Signature byte array associated with _data
*/
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}
Ownable.sol 71 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
INarratorsHutMetadata.sol 49 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
struct CraftArtifactData {
uint256 id;
string name;
string description;
string[] attunements;
}
struct Artifact {
bool mintable;
string name;
string description;
string[] attunements;
}
struct ArtifactManifestation {
string name;
string description;
uint256 witchId;
uint256 artifactId;
AttunementManifestation[] attunements;
}
struct AttunementManifestation {
string name;
int256 value;
}
interface INarratorsHutMetadata {
function getArtifactForToken(
uint256 artifactId,
uint256 tokenId,
uint256 witchId
) external view returns (ArtifactManifestation memory);
function canMintArtifact(uint256 artifactId) external view returns (bool);
function craftArtifact(CraftArtifactData calldata data) external;
function getArtifact(uint256 artifactId)
external
view
returns (Artifact memory);
function lockArtifacts(uint256[] calldata artifactIds) external;
}
IERC721Receiver.sol 5 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../token/ERC721/IERC721Receiver.sol";
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);
}
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);
}
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 {}
}
Signatures.sol 98 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "../interfaces/INarratorsHut.sol";
library Signatures {
// Typehashes for the data types specified in the structured data
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md#rationale-for-typehash
// This should match whats in the client side signing code
bytes32 constant DOMAIN_TYPEHASH =
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
bytes constant TOKEN_DATA_TYPE_DEF =
"TokenData(uint32 artifactId,uint32 witchId)";
bytes32 constant MINT_TYPEHASH =
keccak256(
abi.encodePacked(
"Mint(address minterAddress,uint256 totalCost,uint256 expiresAt,TokenData[] tokenDataArray)",
TOKEN_DATA_TYPE_DEF
)
);
bytes32 constant TOKEN_DATA_TYPEHASH = keccak256(TOKEN_DATA_TYPE_DEF);
// Verify signature by recreating the hash that we signed on
// the client side, and then using that to recover
// the address that signed the signature for this data.
function recreateMintHash(
bytes32 domainSeparator,
address minterAddress,
uint256 totalCost,
uint256 expiresAt,
TokenData[] calldata tokenDataArray
) internal pure returns (bytes32) {
bytes32 mintHash = _hashMint(
minterAddress,
totalCost,
expiresAt,
tokenDataArray
);
return _eip712Message(domainSeparator, mintHash);
}
function _hashMint(
address minterAddress,
uint256 totalCost,
uint256 expiresAt,
TokenData[] calldata tokenDataArray
) private pure returns (bytes32) {
bytes32[] memory tokenDataHashes = new bytes32[](tokenDataArray.length);
for (uint256 i; i < tokenDataArray.length; ) {
tokenDataHashes[i] = _hashTokenData(tokenDataArray[i]);
unchecked {
++i;
}
}
return
keccak256(
abi.encode(
MINT_TYPEHASH,
minterAddress,
totalCost,
expiresAt,
keccak256(abi.encodePacked(tokenDataHashes))
)
);
}
function _hashTokenData(TokenData calldata tokenData)
private
pure
returns (bytes32)
{
return
keccak256(
abi.encode(
TOKEN_DATA_TYPEHASH,
tokenData.artifactId,
tokenData.witchId
)
);
}
function _eip712Message(bytes32 domainSeparator, bytes32 dataHash)
private
pure
returns (bytes32)
{
return
keccak256(
abi.encodePacked(uint16(0x1901), domainSeparator, dataHash)
);
}
}
INarratorsHut.sol 53 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/interfaces/IERC20.sol";
import "./INarratorsHutMetadata.sol";
struct MintInput {
uint256 totalCost;
uint256 expiresAt;
TokenData[] tokenDataArray;
bytes mintSignature;
}
struct TokenData {
// Can safely use uint48 for these values since they can
// comfortably fit within 2^48
uint48 witchId;
uint48 artifactId;
}
interface INarratorsHut {
function mint(MintInput calldata mintInput) external payable;
function getArtifactForToken(uint256 tokenId)
external
view
returns (ArtifactManifestation memory);
function getTokenIdForArtifact(
address addr,
uint48 artifactId,
uint48 witchId
) external view returns (uint256);
function totalSupply() external view returns (uint256);
function setIsSaleActive(bool _status) external;
function setIsOpenSeaConduitActive(bool _isOpenSeaConduitActive) external;
function setMetadataContractAddress(address _metadataContractAddress)
external;
function setNarratorAddress(address _narratorAddress) external;
function setBaseURI(string calldata _baseURI) external;
function withdraw() external;
function withdrawToken(IERC20 token) external;
}
MerkleProof.sol 43 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle Trees proofs.
*
* The proofs can be generated using the JavaScript library
* https://github.com/miguelmota/merkletreejs[merkletreejs].
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
*
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
} else {
// Hash(current element of the proof + current computed hash)
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
}
}
// Check if the computed hash (root) is equal to the provided root
return computedHash == root;
}
}
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;
}
}
Read Contract
balanceOf 0x70a08231 → uint256
getApproved 0x081812fc → address
getArtifactForToken 0xa758e1d3 → tuple
getBaseURI 0x714c5398 → string
getTokenIdForArtifact 0x7afe2b3b → uint256
isApprovedForAll 0xe985e9c5 → bool
isSaleActive 0x564566a8 → bool
metadataContractAddress 0xe74772d8 → address
name 0x06fdde03 → string
narratorAddress 0x37a78ff3 → address
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
royaltyInfo 0x2a55205a → address, uint256
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenURI 0xc87b56dd → string
totalSupply 0x18160ddd → uint256
Write Contract 15 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address to
uint256 tokenId
mint 0x4405fca9
tuple mintInput
renounceOwnership 0x715018a6
No parameters
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setApprovalForAll 0xa22cb465
address operator
bool approved
setBaseURI 0x55f804b3
string _baseURI
setIsOpenSeaConduitActive 0x5232ac35
bool _isOpenSeaConduitActive
setIsSaleActive 0xd2d65ff5
bool _status
setMetadataContractAddress 0x4d74d3b4
address _metadataContractAddress
setNarratorAddress 0x210cd92d
address _narratorAddress
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x3ccfd60b
No parameters
withdrawToken 0x89476069
address token
Recent Transactions
No transactions found for this address