Address Contract Verified
Address
0xaCBC81FE1F56e4138AA1Bc1cF0745D5b52bAcaB5
Balance
0 ETH
Nonce
1
Code Size
11637 bytes
Creator
0x3fD6492f...1c9C at tx 0xa191f77b...8cbcfc
Indexed Transactions
0
Contract Bytecode
11637 bytes
0x60806040526004361061035b575f3560e01c8063715018a6116101bd578063b5f6b1f6116100f2578063dae9298b11610092578063e5ebc7411161006d578063e5ebc74114610921578063e985e9c514610934578063f2fde38b1461097b578063f835cd3c1461099a575f80fd5b8063dae9298b146108cf578063de6c6d36146108e3578063e0a8085314610902575f80fd5b8063c23dc68f116100cd578063c23dc68f1461085b578063c4e41b2214610887578063c87b56dd1461089b578063d5abeb01146108ba575f80fd5b8063b5f6b1f614610814578063b88d4fde14610833578063bc4eaa3e14610846575f80fd5b80638da5cb5b1161015d578063970238911161013857806397023891146107a357806399a2557a146107c2578063a22cb465146107e1578063a45ba8e714610800575f80fd5b80638da5cb5b1461075357806395d89b411461077057806395e7099e14610784575f80fd5b806380eae5781161019857806380eae578146106ec5780638462151c1461070b578063853828b61461072a5780638693da201461073e575f80fd5b8063715018a6146106a45780637d847c51146106b85780637ec4a659146106cd575f80fd5b806342842e0e116102935780635bbb21771161023357806362b99ad41161020e57806362b99ad4146106335780636352211e146106475780636ab49a5b1461066657806370a0823114610685575f80fd5b80635bbb2177146105cf5780635c0b52f6146105fb5780635c975abb1461061a575f80fd5b806346aa52ce1161026e57806346aa52ce14610569578063518302271461057e5780635503a0e81461059c57806358b3fcbf146105b0575f80fd5b806342842e0e1461050b57806342966c681461051e578063438b63001461053d575f80fd5b806316c38b3c116102fe57806323b872dd116102d957806323b872dd146104b157806329570778146104c45780633e016306146104e357806341a38e7f146104f8575f80fd5b806316c38b3c1461046157806318160ddd146104805780631c0de0511461049a575f80fd5b8063081812fc11610339578063081812fc146103d5578063095ea7b31461040c578063139722f81461041f57806316ba10e014610442575f80fd5b806301ffc9a71461035f578063050004101461039357806306fdde03146103b4575b5f80fd5b34801561036a575f80fd5b5061037e6103793660046124b5565b6109b9565b60405190151581526020015b60405180910390f35b34801561039e575f80fd5b506103b26103ad3660046124e6565b610a0a565b005b3480156103bf575f80fd5b506103c8610a34565b60405161038a919061254c565b3480156103e0575f80fd5b506103f46103ef36600461255e565b610ac4565b6040516001600160a01b03909116815260200161038a565b6103b261041a366004612575565b610afd565b34801561042a575f80fd5b5061043460125481565b60405190815260200161038a565b34801561044d575f80fd5b506103b261045c366004612624565b610b0d565b34801561046c575f80fd5b506103b261047b366004612676565b610b21565b34801561048b575f80fd5b506001545f54035f1901610434565b3480156104a5575f80fd5b50600e5460ff1661037e565b6103b26104bf366004612691565b610b3c565b3480156104cf575f80fd5b506016546103f4906001600160a01b031681565b3480156104ee575f80fd5b5061043460145481565b6103b26105063660046126ca565b610ca0565b6103b2610519366004612691565b610dd0565b348015610529575f80fd5b506103b261053836600461255e565b610def565b348015610548575f80fd5b5061055c6105573660046124e6565b610e64565b60405161038a91906126f4565b348015610574575f80fd5b5061043460105481565b348015610589575f80fd5b50600e5461037e90610100900460ff1681565b3480156105a7575f80fd5b506103c8610f40565b3480156105bb575f80fd5b506017546103f4906001600160a01b031681565b3480156105da575f80fd5b506105ee6105e9366004612773565b610fcc565b60405161038a91906127ef565b348015610606575f80fd5b506103b2610615366004612830565b611017565b348015610625575f80fd5b50600e5461037e9060ff1681565b34801561063e575f80fd5b506103c8611048565b348015610652575f80fd5b506103f461066136600461255e565b611055565b348015610671575f80fd5b506103b2610680366004612773565b61105f565b348015610690575f80fd5b5061043461069f3660046124e6565b61111d565b3480156106af575f80fd5b506103b2611161565b3480156106c3575f80fd5b5061043460135481565b3480156106d8575f80fd5b506103b26106e7366004612624565b611174565b3480156106f7575f80fd5b506103b261070636600461255e565b611188565b348015610716575f80fd5b5061055c6107253660046124e6565b611195565b348015610735575f80fd5b506103b26111bb565b348015610749575f80fd5b50610434600f5481565b34801561075e575f80fd5b506008546001600160a01b03166103f4565b34801561077b575f80fd5b506103c8611301565b34801561078f575f80fd5b506103b261079e3660046124e6565b611310565b3480156107ae575f80fd5b506103b26107bd3660046126ca565b61133a565b3480156107cd575f80fd5b5061055c6107dc366004612830565b611586565b3480156107ec575f80fd5b506103b26107fb366004612860565b611593565b34801561080b575f80fd5b506103c86115fe565b34801561081f575f80fd5b506103b261082e36600461255e565b61160b565b6103b2610841366004612895565b611618565b348015610851575f80fd5b5061043460155481565b348015610866575f80fd5b5061087a61087536600461255e565b611659565b60405161038a919061290c565b348015610892575f80fd5b506104346116b9565b3480156108a6575f80fd5b506103c86108b536600461255e565b6116d0565b3480156108c5575f80fd5b50610434600d5481565b3480156108da575f80fd5b506103b261183e565b3480156108ee575f80fd5b506103b26108fd36600461291a565b611b3f565b34801561090d575f80fd5b506103b261091c366004612676565b611c21565b6103b261092f36600461255e565b611c43565b34801561093f575f80fd5b5061037e61094e366004612981565b6001600160a01b039182165f90815260076020908152604080832093909416825291909152205460ff1690565b348015610986575f80fd5b506103b26109953660046124e6565b611d46565b3480156109a5575f80fd5b506011546103f4906001600160a01b031681565b5f6301ffc9a760e01b6001600160e01b0319831614806109e957506380ac58cd60e01b6001600160e01b03198316145b80610a045750635b5e139f60e01b6001600160e01b03198316145b92915050565b610a12611d80565b601680546001600160a01b0319166001600160a01b0392909216919091179055565b606060028054610a43906129a9565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6f906129a9565b8015610aba5780601f10610a9157610100808354040283529160200191610aba565b820191905f5260205f20905b815481529060010190602001808311610a9d57829003601f168201915b5050505050905090565b5f610ace82611dad565b610ae257610ae26333d1c03960e21b611df5565b505f908152600660205260409020546001600160a01b031690565b610b0982826001611dfd565b5050565b610b15611d80565b600b610b098282612a26565b610b29611d80565b600e805460ff1916911515919091179055565b5f610b4682611e9e565b6001600160a01b039485169490915081168414610b6c57610b6c62a1148160e81b611df5565b5f8281526006602052604090208054610b978187335b6001600160a01b039081169116811491141790565b610bb957610ba5863361094e565b610bb957610bb9632ce44b5f60e11b611df5565b8015610bc3575f82555b6001600160a01b038681165f9081526005602052604080822080545f19019055918716808252919020805460010190554260a01b17600160e11b175f85815260046020526040812091909155600160e11b84169003610c4f57600184015f818152600460205260408120549003610c4d575f548114610c4d575f8181526004602052604090208490555b505b6001600160a01b0385168481887fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a4805f03610c9757610c97633a954ecd60e21b611df5565b50505050505050565b600e54829060ff1615610cce5760405162461bcd60e51b8152600401610cc590612ae2565b60405180910390fd5b5f60155482610cdd9190612b22565b9050610ce98183612b41565b9150600d5482601054610cfc9190612b41565b1115610d1a5760405162461bcd60e51b8152600401610cc590612b54565b600f54610d279085612b82565b341015610d6c5760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742066756e64732160681b6044820152606401610cc5565b5f8411610d8b5760405162461bcd60e51b8152600401610cc590612b99565b5f60155485610d9a9190612b22565b9050610da68186612b41565b94508460105f828254610db99190612b41565b90915550610dc990508486611f38565b5050505050565b610dea83838360405180602001604052805f815250611618565b505050565b610df881611055565b6001600160a01b0316336001600160a01b031614610e585760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f742074686520746f6b656e206f776e65720000006044820152606401610cc5565b610e6181611f51565b50565b60605f610e708361111d565b90505f8167ffffffffffffffff811115610e8c57610e8c61259d565b604051908082528060200260200182016040528015610eb5578160200160208202803683370190505b50905060015f5b8381108015610ecd5750600d548211155b15610f36575f610edc83611055565b9050866001600160a01b0316816001600160a01b031603610f235782848381518110610f0a57610f0a612bc7565b602090810291909101015281610f1f81612bdb565b9250505b82610f2d81612bdb565b93505050610ebc565b5090949350505050565b600b8054610f4d906129a9565b80601f0160208091040260200160405190810160405280929190818152602001828054610f79906129a9565b8015610fc45780601f10610f9b57610100808354040283529160200191610fc4565b820191905f5260205f20905b815481529060010190602001808311610fa757829003601f168201915b505050505081565b60408051828152600583901b8082016020019092526060915b801561100f57601f1980820191860101355f61100082611659565b8484016020015250610fe59050565b509392505050565b61101f611d80565b601180546001600160a01b0319166001600160a01b039490941693909317909255601255601355565b600a8054610f4d906129a9565b5f610a0482611e9e565b5f5b81811015610dea5761108a83838381811061107e5761107e612bc7565b90506020020135611055565b6001600160a01b0316336001600160a01b0316146110ea5760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f742074686520746f6b656e206f776e65720000006044820152606401610cc5565b61110b8383838181106110ff576110ff612bc7565b90506020020135611f51565b8061111581612bdb565b915050611061565b5f6001600160a01b03821661113c5761113c6323d3ad8160e21b611df5565b506001600160a01b03165f9081526005602052604090205467ffffffffffffffff1690565b611169611d80565b6111725f611f5b565b565b61117c611d80565b600a610b098282612a26565b611190611d80565b600f55565b5f54606090600190828282146111b3576111b0858484611fac565b90505b949350505050565b6111c3611d80565b6008546040516001600160a01b03909116904780156108fc02915f818181858888f193505050501580156111f9573d5f803e3d5ffd5b506011546001600160a01b031615611172576011546001600160a01b03168063a9059cbb61122f6008546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b038516906370a0823190602401602060405180830381865afa158015611271573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112959190612bf3565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303815f875af11580156112dd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b099190612c0a565b606060038054610a43906129a9565b611318611d80565b601780546001600160a01b0319166001600160a01b0392909216919091179055565b600e54829060ff161561135f5760405162461bcd60e51b8152600401610cc590612ae2565b5f6015548261136e9190612b22565b905061137a8183612b41565b9150600d548260105461138d9190612b41565b11156113ab5760405162461bcd60e51b8152600401610cc590612b54565b5f84116113ca5760405162461bcd60e51b8152600401610cc590612b99565b6011546001600160a01b031661141a5760405162461bcd60e51b81526020600482015260156024820152744552432d323020746f6b656e206e6f74207365742160581b6044820152606401610cc5565b6013548460145461142b9190612b41565b111561148a5760405162461bcd60e51b815260206004820152602860248201527f4d696e74206c696d697420776974682053686565736820686173206265656e20604482015267726561636865642160c01b6064820152608401610cc5565b6011546012546001600160a01b039091169081906323b872dd90339030906114b2908a612b82565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015260448201526064016020604051808303815f875af1158015611503573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115279190612c0a565b505f601554866115379190612b22565b90506115438187612b41565b95508560105f8282546115569190612b41565b925050819055508560145f82825461156e9190612b41565b9091555061157e90508587611f38565b505050505050565b60606111b3848484611fac565b335f8181526007602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b600c8054610f4d906129a9565b611613611d80565b601555565b611623848484610b3c565b6001600160a01b0383163b156116535761163f848484846120a4565b611653576116536368d2bf6b60e11b611df5565b50505050565b604080516080810182525f808252602082018190529181018290526060810191909152600182106116b4575f548210156116b4575b5f828152600460205260409020546116ab575f199091019061168e565b610a0482612182565b919050565b5f6116cb6001545f545f199190030190565b905090565b60606116db82611dad565b61173f5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610cc5565b600e54610100900460ff1615155f036117e257600c805461175f906129a9565b80601f016020809104026020016040519081016040528092919081815260200182805461178b906129a9565b80156117d65780601f106117ad576101008083540402835291602001916117d6565b820191905f5260205f20905b8154815290600101906020018083116117b957829003601f168201915b50505050509050919050565b5f6117eb6121ff565b90505f8151116118095760405180602001604052805f815250611837565b806118138461220e565b600b60405160200161182793929190612c25565b6040516020818303038152906040525b9392505050565b611846611d80565b475f611853606483612b22565b61185e906003612b82565b6016546040519192506001600160a01b03169082156108fc029083905f818181858888f19350505050158015611896573d5f803e3d5ffd5b506017546040516001600160a01b039091169082156108fc029083905f818181858888f193505050501580156118ce573d5f803e3d5ffd5b506008546001600160a01b03166108fc6118e9836002612b82565b6118f39085612cc0565b6040518115909202915f818181858888f19350505050158015611918573d5f803e3d5ffd5b506011546001600160a01b031615610b09576011546040516370a0823160e01b81523060048201526001600160a01b03909116905f9082906370a0823190602401602060405180830381865afa158015611974573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119989190612bf3565b90505f6119a6606483612b22565b6119b1906003612b82565b60165460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810183905291925084169063a9059cbb906044016020604051808303815f875af1158015611a03573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a279190612c0a565b5060175460405163a9059cbb60e01b81526001600160a01b039182166004820152602481018390529084169063a9059cbb906044016020604051808303815f875af1158015611a78573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a9c9190612c0a565b50826001600160a01b031663a9059cbb611abe6008546001600160a01b031690565b611ac9846002612b82565b611ad39086612cc0565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303815f875af1158015611b1b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061157e9190612c0a565b611b47611d80565b5f5b83811015610dc957600d54838383818110611b6657611b66612bc7565b90506020020135601054611b7a9190612b41565b1115611b985760405162461bcd60e51b8152600401610cc590612b54565b828282818110611baa57611baa612bc7565b9050602002013560105f828254611bc19190612b41565b90915550611c0f9050858583818110611bdc57611bdc612bc7565b9050602002016020810190611bf191906124e6565b848484818110611c0357611c03612bc7565b90506020020135611f38565b80611c1981612bdb565b915050611b49565b611c29611d80565b600e80549115156101000261ff0019909216919091179055565b600e54819060ff1615611c685760405162461bcd60e51b8152600401610cc590612ae2565b5f60155482611c779190612b22565b9050611c838183612b41565b9150600d5482601054611c969190612b41565b1115611cb45760405162461bcd60e51b8152600401610cc590612b54565b600f54611cc19084612b82565b341015611d065760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742066756e64732160681b6044820152606401610cc5565b5f8311611d255760405162461bcd60e51b8152600401610cc590612b99565b8260105f828254611d369190612b41565b90915550610dea90503384611f38565b611d4e611d80565b6001600160a01b038116611d7757604051631e4fbdf760e01b81525f6004820152602401610cc5565b610e6181611f5b565b6008546001600160a01b031633146111725760405163118cdaa760e01b8152336004820152602401610cc5565b5f816001116116b4575f548210156116b4575f5b505f8281526004602052604081205490819003611de857611de183612cd3565b9250611dc1565b600160e01b161592915050565b805f5260045ffd5b5f611e0783611055565b9050818015611e1f5750336001600160a01b03821614155b15611e4257611e2e813361094e565b611e4257611e426367d9dca160e11b611df5565b5f8381526006602052604080822080546001600160a01b0319166001600160a01b0388811691821790925591518693918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a450505050565b5f81600111611f2857505f8181526004602052604081205490819003611f16575f548210611ed657611ed6636f96cda160e11b611df5565b5b505f19015f818152600460205260409020548015611ed757600160e01b81165f03611f0157919050565b611f11636f96cda160e11b611df5565b611ed7565b600160e01b81165f03611f2857919050565b6116b4636f96cda160e11b611df5565b610b09828260405180602001604052805f815250612251565b610e61815f6122af565b600880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b6060818310611fc557611fc5631960ccad60e11b611df5565b6001831015611fd357600192505b5f54808310611fe0578092505b60605f611fec8761111d565b858710908102915081156120985781878703116120095786860391505b60405192506001820160051b83016040525f61202488611659565b90505f8160400151612034575080515b5f5b61203f8a612182565b925060408301515f8114612055575f925061207a565b83511561206157835192505b8b831860601b61207a576001820191508a8260051b8801525b5060018a019950888a148061208e57508481145b1561203657855250505b50909695505050505050565b604051630a85bd0160e11b81525f906001600160a01b0385169063150b7a02906120d8903390899088908890600401612ce8565b6020604051808303815f875af1925050508015612112575060408051601f3d908101601f1916820190925261210f91810190612d24565b60015b612165573d80801561213f576040519150601f19603f3d011682016040523d82523d5f602084013e612144565b606091505b5080515f0361215d5761215d6368d2bf6b60e11b611df5565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050949350505050565b604080516080810182525f8082526020820181905291810182905260608101919091525f82815260046020526040902054610a0490604080516080810182526001600160a01b038316815260a083901c67ffffffffffffffff166020820152600160e01b831615159181019190915260e89190911c606082015290565b6060600a8054610a43906129a9565b606060a06040510180604052602081039150505f815280825b600183039250600a81066030018353600a9004806122275750819003601f19909101908152919050565b61225b83836123e6565b6001600160a01b0383163b15610dea575f548281035b6122835f8683806001019450866120a4565b612297576122976368d2bf6b60e11b611df5565b81811061227157815f5414610dc957610dc95f611df5565b5f6122b983611e9e565b9050805f806122d5865f90815260066020526040902080549091565b91509150841561230c576122ea818433610b82565b61230c576122f8833361094e565b61230c5761230c632ce44b5f60e11b611df5565b8015612316575f82555b6001600160a01b0383165f81815260056020526040902080546fffffffffffffffffffffffffffffffff0190554260a01b17600360e01b175f87815260046020526040812091909155600160e11b8516900361239f57600186015f81815260046020526040812054900361239d575f54811461239d575f8181526004602052604090208590555b505b60405186905f906001600160a01b038616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050600180548101905550505050565b5f8054908290036124015761240163b562e8dd60e01b611df5565b5f8181526004602090815260408083206001600160a01b0387164260a01b6001881460e11b1781179091558084526005909252822080546801000000000000000186020190559081900361245e5761245e622e076360e81b611df5565b818301825b80835f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a481816001019150810361246357505f5550505050565b6001600160e01b031981168114610e61575f80fd5b5f602082840312156124c5575f80fd5b8135611837816124a0565b80356001600160a01b03811681146116b4575f80fd5b5f602082840312156124f6575f80fd5b611837826124d0565b5f5b83811015612519578181015183820152602001612501565b50505f910152565b5f81518084526125388160208601602086016124ff565b601f01601f19169290920160200192915050565b602081525f6118376020830184612521565b5f6020828403121561256e575f80fd5b5035919050565b5f8060408385031215612586575f80fd5b61258f836124d0565b946020939093013593505050565b634e487b7160e01b5f52604160045260245ffd5b5f67ffffffffffffffff808411156125cb576125cb61259d565b604051601f8501601f19908116603f011681019082821181831017156125f3576125f361259d565b8160405280935085815286868601111561260b575f80fd5b858560208301375f602087830101525050509392505050565b5f60208284031215612634575f80fd5b813567ffffffffffffffff81111561264a575f80fd5b8201601f8101841361265a575f80fd5b6111b3848235602084016125b1565b8015158114610e61575f80fd5b5f60208284031215612686575f80fd5b813561183781612669565b5f805f606084860312156126a3575f80fd5b6126ac846124d0565b92506126ba602085016124d0565b9150604084013590509250925092565b5f80604083850312156126db575f80fd5b823591506126eb602084016124d0565b90509250929050565b602080825282518282018190525f9190848201906040850190845b818110156120985783518352928401929184019160010161270f565b5f8083601f84011261273b575f80fd5b50813567ffffffffffffffff811115612752575f80fd5b6020830191508360208260051b850101111561276c575f80fd5b9250929050565b5f8060208385031215612784575f80fd5b823567ffffffffffffffff81111561279a575f80fd5b6127a68582860161272b565b90969095509350505050565b80516001600160a01b0316825260208082015167ffffffffffffffff169083015260408082015115159083015260609081015162ffffff16910152565b602080825282518282018190525f9190848201906040850190845b818110156120985761281d8385516127b2565b928401926080929092019160010161280a565b5f805f60608486031215612842575f80fd5b61284b846124d0565b95602085013595506040909401359392505050565b5f8060408385031215612871575f80fd5b61287a836124d0565b9150602083013561288a81612669565b809150509250929050565b5f805f80608085870312156128a8575f80fd5b6128b1856124d0565b93506128bf602086016124d0565b925060408501359150606085013567ffffffffffffffff8111156128e1575f80fd5b8501601f810187136128f1575f80fd5b612900878235602084016125b1565b91505092959194509250565b60808101610a0482846127b2565b5f805f806040858703121561292d575f80fd5b843567ffffffffffffffff80821115612944575f80fd5b6129508883890161272b565b90965094506020870135915080821115612968575f80fd5b506129758782880161272b565b95989497509550505050565b5f8060408385031215612992575f80fd5b61299b836124d0565b91506126eb602084016124d0565b600181811c908216806129bd57607f821691505b6020821081036129db57634e487b7160e01b5f52602260045260245ffd5b50919050565b601f821115610dea575f81815260208120601f850160051c81016020861015612a075750805b601f850160051c820191505b8181101561157e57828155600101612a13565b815167ffffffffffffffff811115612a4057612a4061259d565b612a5481612a4e84546129a9565b846129e1565b602080601f831160018114612a87575f8415612a705750858301515b5f19600386901b1c1916600185901b17855561157e565b5f85815260208120601f198616915b82811015612ab557888601518255948401946001909101908401612a96565b5085821015612ad257878501515f19600388901b60f8161c191681555b5050505050600190811b01905550565b6020808252601290820152714d696e74696e67206973205041555345442160701b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b5f82612b3c57634e487b7160e01b5f52601260045260245ffd5b500490565b80820180821115610a0457610a04612b0e565b6020808252601490820152734d617820737570706c792065786365656465642160601b604082015260600190565b8082028115828204841417610a0457610a04612b0e565b602080825260149082015273496e76616c6964206d696e7420616d6f756e742160601b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b5f60018201612bec57612bec612b0e565b5060010190565b5f60208284031215612c03575f80fd5b5051919050565b5f60208284031215612c1a575f80fd5b815161183781612669565b5f84516020612c378285838a016124ff565b855191840191612c4a8184848a016124ff565b85549201915f90612c5a816129a9565b60018281168015612c725760018114612c8757612cb0565b60ff1984168752821515830287019450612cb0565b895f52855f205f5b84811015612ca857815489820152908301908701612c8f565b505082870194505b50929a9950505050505050505050565b81810381811115610a0457610a04612b0e565b5f81612ce157612ce1612b0e565b505f190190565b6001600160a01b03858116825284166020820152604081018390526080606082018190525f90612d1a90830184612521565b9695505050505050565b5f60208284031215612d34575f80fd5b8151611837816124a056fea264697066735822122014fa75001410cf376c7a674cafc966aff685b09d6a7866799d42e6b88b640dbd64736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: shanghai
Optimization: Yes (200 runs)
BedtimeCreationCompanions.sol 278 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "https://github.com/chiru-labs/ERC721A/blob/main/contracts/extensions/ERC721AQueryable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract BedtimeCreationsCompanions is ERC721AQueryable, Ownable {
using Strings for uint256;
using Counters for Counters.Counter;
Counters.Counter private supply;
string public uriPrefix = "https://www.bedtimerealm.com/nft/json/";
string public uriSuffix = ".json";
string public hiddenMetadataUri = "https://www.bedtimerealm.com/nft/hidden.json";
uint256 public maxSupply = 1000;
bool public paused = true;
bool public revealed = false;
uint256 public publicCost = 40000000000000000;
uint256 public mintCounter = 0;
address public erc20TokenAddress = 0xbB4f3aD7a2cf75d8EfFc4f6D7BD21d95F06165ca;
uint256 public erc20TokenCost = 115000000000000000000000000;
uint256 public erc20MintLimit = 100;
uint256 public erc20MintCounter = 0;
uint256 public bonusThreshold = 5;
address public devAddy = 0x036D0560582c444ff13d5822e2759A9f1E3D1e1e;
address public artistAddy = 0xEFd6E29eD1b602B4d0410bF008Bd667562DF1013;
constructor() ERC721A("Bedtime Creations Companions", "BCC") Ownable(msg.sender)
{
_startTokenId();
}
function _startTokenId()
internal
pure
override
returns(uint256)
{
return 1;
}
// RUNS BEFORE ALL MINT FUNCTIONS
modifier mintCompliance (uint256 _mintAmount)
{
require(!paused, "Minting is PAUSED!");
uint256 increaseAmount = (_mintAmount / bonusThreshold);
_mintAmount += increaseAmount;
require(mintCounter + _mintAmount <= maxSupply, "Max supply exceeded!");
_;
}
// ---------------! SETTERS !------------------
function setPublicMintCost(uint256 _mintCost) external onlyOwner
{
publicCost = _mintCost;
}
function setRevealed(bool _state) public onlyOwner
{
revealed = _state;
}
function setUriPrefix(string memory _uriPrefix) public onlyOwner
{
uriPrefix = _uriPrefix;
}
function setUriSuffix(string memory _uriSuffix) public onlyOwner
{
uriSuffix = _uriSuffix;
}
function setPaused(bool _state) public onlyOwner
{
paused = _state;
}
function setERC20Token(address _erc20TokenAddress, uint256 _erc20TokenCost, uint256 _erc20MintLimit) public onlyOwner
{
erc20TokenAddress = _erc20TokenAddress;
erc20TokenCost = _erc20TokenCost;
erc20MintLimit = _erc20MintLimit;
}
function setBonusThreshold(uint256 _newAmount) public onlyOwner
{
bonusThreshold = _newAmount;
}
function setDevAddy(address _newAddress) public onlyOwner
{
devAddy = _newAddress;
}
function setArtistAddy(address _newAddress) public onlyOwner
{
artistAddy = _newAddress;
}
// ---------------! GETTERS !----------------------
function getPausedState() public view returns (bool)
{
return paused;
}
function getTotalSupply() public view returns (uint256)
{
return totalSupply();
}
// ---------------! MINT FUNCTIONS !-------------------
function publicMint(uint256 _mintAmount, address receiver) external mintCompliance(_mintAmount) payable
{
require(msg.value >= _mintAmount * publicCost, "Insufficient funds!");
require(_mintAmount > 0, "Invalid mint amount!");
uint256 increaseAmount = (_mintAmount / bonusThreshold);
_mintAmount += increaseAmount;
mintCounter += _mintAmount;
_safeMint(receiver, _mintAmount);
}
function publicMintRaw(uint256 _mintAmount) external mintCompliance(_mintAmount) payable
{
require(msg.value >= _mintAmount * publicCost, "Insufficient funds!");
require(_mintAmount > 0, "Invalid mint amount!");
mintCounter += _mintAmount;
_safeMint(msg.sender, _mintAmount);
}
function publicMintWithSheesh(uint256 _mintAmount, address receiver) external mintCompliance(_mintAmount)
{
require(_mintAmount > 0, "Invalid mint amount!");
require(erc20TokenAddress != address(0), "ERC-20 token not set!");
require(erc20MintCounter + _mintAmount <= erc20MintLimit, "Mint limit with Sheesh has been reached!");
IERC20 tokenContract = IERC20(erc20TokenAddress);
tokenContract.transferFrom(msg.sender, address(this), _mintAmount * erc20TokenCost);
uint256 increaseAmount = (_mintAmount / bonusThreshold);
_mintAmount += increaseAmount;
mintCounter += _mintAmount;
erc20MintCounter += _mintAmount;
_safeMint(receiver, _mintAmount);
}
// AIRDROP TO MULTIPLE ADDRESSES
function mintForAddressMultiple(address[] calldata addresses, uint256[] calldata amount) public onlyOwner
{
for (uint256 i; i < addresses.length; i++)
{
require(mintCounter + amount[i] <= maxSupply, "Max supply exceeded!");
mintCounter += amount[i];
_safeMint(addresses[i], amount[i]);
}
}
// STANDARD BURN FUNCTION
function burn(uint256 tokenId) public virtual
{
require(msg.sender == ownerOf(tokenId), "Caller is not the token owner");
_burn(tokenId);
}
function burnMultiple(uint256[] calldata ids) public virtual
{
for (uint256 i; i < ids.length; i++)
{
require(msg.sender == ownerOf(ids[i]), "Caller is not the token owner");
_burn(ids[i]);
}
}
// ---------------! BASELINE FUNCTIONS !---------------
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
uint256 currentTokenId = 1;
uint256 ownedTokenIndex = 0;
while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) {
address currentTokenOwner = ownerOf(currentTokenId);
if (currentTokenOwner == _owner) {
ownedTokenIds[ownedTokenIndex] = currentTokenId;
ownedTokenIndex++;
}
currentTokenId++;
}
return ownedTokenIds;
}
function tokenURI(uint256 _tokenId)
public
view
virtual
override (ERC721A, IERC721A)
returns (string memory)
{
require(
_exists(_tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return hiddenMetadataUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, _toString(_tokenId), uriSuffix))
: "";
}
function withdrawAll() external onlyOwner
{
payable(owner()).transfer(address(this).balance);
if (erc20TokenAddress != address(0))
{
IERC20 erc20Token = IERC20(erc20TokenAddress);
erc20Token.transfer(owner(), erc20Token.balanceOf(address(this)));
}
}
function withdrawAllWithSplit() external onlyOwner
{
uint256 ethBalance = address(this).balance;
uint256 ethToRecipient = (ethBalance / 100) * 3;
payable(devAddy).transfer(ethToRecipient);
payable(artistAddy).transfer(ethToRecipient);
payable(owner()).transfer(ethBalance - ethToRecipient*2);
if (erc20TokenAddress != address(0))
{
IERC20 erc20Token = IERC20(erc20TokenAddress);
uint256 erc20Balance = erc20Token.balanceOf(address(this));
uint256 erc20ToRecipient = (erc20Balance / 100) * 3;
erc20Token.transfer(devAddy, erc20ToRecipient);
erc20Token.transfer(artistAddy, erc20ToRecipient);
erc20Token.transfer(owner(), erc20Balance - erc20ToRecipient*2);
}
}
function _baseURI() internal view virtual override returns (string memory) {
return uriPrefix;
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Strings.sol 94 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
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_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../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.
*
* The initial owner is set to the address provided by the deployer. 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;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Counters.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
ERC721A.sol 1149 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs
pragma solidity ^0.8.4;
import './IERC721A.sol';
/**
* @dev Interface of ERC721 token receiver.
*/
interface ERC721A__IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
/**
* @title ERC721A
*
* @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)
* Non-Fungible Token Standard, including the Metadata extension.
* Optimized for lower gas during batch mints.
*
* Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)
* starting from `_startTokenId()`.
*
* Assumptions:
*
* - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.
* - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).
*/
contract ERC721A is IERC721A {
// Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364).
struct TokenApprovalRef {
address value;
}
// =============================================================
// CONSTANTS
// =============================================================
// Mask of an entry in packed address data.
uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;
// The bit position of `numberMinted` in packed address data.
uint256 private constant _BITPOS_NUMBER_MINTED = 64;
// The bit position of `numberBurned` in packed address data.
uint256 private constant _BITPOS_NUMBER_BURNED = 128;
// The bit position of `aux` in packed address data.
uint256 private constant _BITPOS_AUX = 192;
// Mask of all 256 bits in packed address data except the 64 bits for `aux`.
uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;
// The bit position of `startTimestamp` in packed ownership.
uint256 private constant _BITPOS_START_TIMESTAMP = 160;
// The bit mask of the `burned` bit in packed ownership.
uint256 private constant _BITMASK_BURNED = 1 << 224;
// The bit position of the `nextInitialized` bit in packed ownership.
uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;
// The bit mask of the `nextInitialized` bit in packed ownership.
uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;
// The bit position of `extraData` in packed ownership.
uint256 private constant _BITPOS_EXTRA_DATA = 232;
// Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.
uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;
// The mask of the lower 160 bits for addresses.
uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;
// The maximum `quantity` that can be minted with {_mintERC2309}.
// This limit is to prevent overflows on the address data entries.
// For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}
// is required to cause an overflow, which is unrealistic.
uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;
// The `Transfer` event signature is given by:
// `keccak256(bytes("Transfer(address,address,uint256)"))`.
bytes32 private constant _TRANSFER_EVENT_SIGNATURE =
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;
// =============================================================
// STORAGE
// =============================================================
// The next token ID to be minted.
uint256 private _currentIndex;
// The number of tokens burned.
uint256 private _burnCounter;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to ownership details
// An empty struct value does not necessarily mean the token is unowned.
// See {_packedOwnershipOf} implementation for details.
//
// Bits Layout:
// - [0..159] `addr`
// - [160..223] `startTimestamp`
// - [224] `burned`
// - [225] `nextInitialized`
// - [232..255] `extraData`
mapping(uint256 => uint256) private _packedOwnerships;
// Mapping owner address to address data.
//
// Bits Layout:
// - [0..63] `balance`
// - [64..127] `numberMinted`
// - [128..191] `numberBurned`
// - [192..255] `aux`
mapping(address => uint256) private _packedAddressData;
// Mapping from token ID to approved address.
mapping(uint256 => TokenApprovalRef) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
// =============================================================
// CONSTRUCTOR
// =============================================================
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
_currentIndex = _startTokenId();
}
// =============================================================
// TOKEN COUNTING OPERATIONS
// =============================================================
/**
* @dev Returns the starting token ID.
* To change the starting token ID, please override this function.
*/
function _startTokenId() internal view virtual returns (uint256) {
return 0;
}
/**
* @dev Returns the next token ID to be minted.
*/
function _nextTokenId() internal view virtual returns (uint256) {
return _currentIndex;
}
/**
* @dev Returns the total number of tokens in existence.
* Burned tokens will reduce the count.
* To get the total number of tokens minted, please see {_totalMinted}.
*/
function totalSupply() public view virtual override returns (uint256) {
// Counter underflow is impossible as _burnCounter cannot be incremented
// more than `_currentIndex - _startTokenId()` times.
unchecked {
return _currentIndex - _burnCounter - _startTokenId();
}
}
/**
* @dev Returns the total amount of tokens minted in the contract.
*/
function _totalMinted() internal view virtual returns (uint256) {
// Counter underflow is impossible as `_currentIndex` does not decrement,
// and it is initialized to `_startTokenId()`.
unchecked {
return _currentIndex - _startTokenId();
}
}
/**
* @dev Returns the total number of tokens burned.
*/
function _totalBurned() internal view virtual returns (uint256) {
return _burnCounter;
}
// =============================================================
// ADDRESS DATA OPERATIONS
// =============================================================
/**
* @dev Returns the number of tokens in `owner`'s account.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
if (owner == address(0)) _revert(BalanceQueryForZeroAddress.selector);
return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;
}
/**
* Returns the number of tokens minted by `owner`.
*/
function _numberMinted(address owner) internal view returns (uint256) {
return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;
}
/**
* Returns the number of tokens burned by or on behalf of `owner`.
*/
function _numberBurned(address owner) internal view returns (uint256) {
return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;
}
/**
* Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).
*/
function _getAux(address owner) internal view returns (uint64) {
return uint64(_packedAddressData[owner] >> _BITPOS_AUX);
}
/**
* Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).
* If there are multiple variables, please pack them into a uint64.
*/
function _setAux(address owner, uint64 aux) internal virtual {
uint256 packed = _packedAddressData[owner];
uint256 auxCasted;
// Cast `aux` with assembly to avoid redundant masking.
assembly {
auxCasted := aux
}
packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);
_packedAddressData[owner] = packed;
}
// =============================================================
// IERC165
// =============================================================
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
* to learn more about how these ids are created.
*
* This function call must use less than 30000 gas.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
// The interface IDs are constants representing the first 4 bytes
// of the XOR of all function selectors in the interface.
// See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)
// (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)
return
interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.
interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.
interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.
}
// =============================================================
// IERC721Metadata
// =============================================================
/**
* @dev Returns the token collection name.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the token collection symbol.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
if (!_exists(tokenId)) _revert(URIQueryForNonexistentToken.selector);
string memory baseURI = _baseURI();
return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';
}
/**
* @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, it can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return '';
}
// =============================================================
// OWNERSHIPS OPERATIONS
// =============================================================
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
return address(uint160(_packedOwnershipOf(tokenId)));
}
/**
* @dev Gas spent here starts off proportional to the maximum mint batch size.
* It gradually moves to O(1) as tokens get transferred around over time.
*/
function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {
return _unpackedOwnership(_packedOwnershipOf(tokenId));
}
/**
* @dev Returns the unpacked `TokenOwnership` struct at `index`.
*/
function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {
return _unpackedOwnership(_packedOwnerships[index]);
}
/**
* @dev Returns whether the ownership slot at `index` is initialized.
* An uninitialized slot does not necessarily mean that the slot has no owner.
*/
function _ownershipIsInitialized(uint256 index) internal view virtual returns (bool) {
return _packedOwnerships[index] != 0;
}
/**
* @dev Initializes the ownership slot minted at `index` for efficiency purposes.
*/
function _initializeOwnershipAt(uint256 index) internal virtual {
if (_packedOwnerships[index] == 0) {
_packedOwnerships[index] = _packedOwnershipOf(index);
}
}
/**
* Returns the packed ownership data of `tokenId`.
*/
function _packedOwnershipOf(uint256 tokenId) private view returns (uint256 packed) {
if (_startTokenId() <= tokenId) {
packed = _packedOwnerships[tokenId];
// If the data at the starting slot does not exist, start the scan.
if (packed == 0) {
if (tokenId >= _currentIndex) _revert(OwnerQueryForNonexistentToken.selector);
// Invariant:
// There will always be an initialized ownership slot
// (i.e. `ownership.addr != address(0) && ownership.burned == false`)
// before an unintialized ownership slot
// (i.e. `ownership.addr == address(0) && ownership.burned == false`)
// Hence, `tokenId` will not underflow.
//
// We can directly compare the packed value.
// If the address is zero, packed will be zero.
for (;;) {
unchecked {
packed = _packedOwnerships[--tokenId];
}
if (packed == 0) continue;
if (packed & _BITMASK_BURNED == 0) return packed;
// Otherwise, the token is burned, and we must revert.
// This handles the case of batch burned tokens, where only the burned bit
// of the starting slot is set, and remaining slots are left uninitialized.
_revert(OwnerQueryForNonexistentToken.selector);
}
}
// Otherwise, the data exists and we can skip the scan.
// This is possible because we have already achieved the target condition.
// This saves 2143 gas on transfers of initialized tokens.
// If the token is not burned, return `packed`. Otherwise, revert.
if (packed & _BITMASK_BURNED == 0) return packed;
}
_revert(OwnerQueryForNonexistentToken.selector);
}
/**
* @dev Returns the unpacked `TokenOwnership` struct from `packed`.
*/
function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {
ownership.addr = address(uint160(packed));
ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);
ownership.burned = packed & _BITMASK_BURNED != 0;
ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);
}
/**
* @dev Packs ownership data into a single uint256.
*/
function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {
assembly {
// Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.
owner := and(owner, _BITMASK_ADDRESS)
// `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.
result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))
}
}
/**
* @dev Returns the `nextInitialized` flag set if `quantity` equals 1.
*/
function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {
// For branchless setting of the `nextInitialized` flag.
assembly {
// `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.
result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))
}
}
// =============================================================
// APPROVAL OPERATIONS
// =============================================================
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account. See {ERC721A-_approve}.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
*/
function approve(address to, uint256 tokenId) public payable virtual override {
_approve(to, tokenId, true);
}
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
if (!_exists(tokenId)) _revert(ApprovalQueryForNonexistentToken.selector);
return _tokenApprovals[tokenId].value;
}
/**
* @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) public virtual override {
_operatorApprovals[_msgSenderERC721A()][operator] = approved;
emit ApprovalForAll(_msgSenderERC721A(), operator, approved);
}
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @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. See {_mint}.
*/
function _exists(uint256 tokenId) internal view virtual returns (bool result) {
if (_startTokenId() <= tokenId) {
if (tokenId < _currentIndex) {
uint256 packed;
while ((packed = _packedOwnerships[tokenId]) == 0) --tokenId;
result = packed & _BITMASK_BURNED == 0;
}
}
}
/**
* @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.
*/
function _isSenderApprovedOrOwner(
address approvedAddress,
address owner,
address msgSender
) private pure returns (bool result) {
assembly {
// Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.
owner := and(owner, _BITMASK_ADDRESS)
// Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.
msgSender := and(msgSender, _BITMASK_ADDRESS)
// `msgSender == owner || msgSender == approvedAddress`.
result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))
}
}
/**
* @dev Returns the storage slot and value for the approved address of `tokenId`.
*/
function _getApprovedSlotAndAddress(uint256 tokenId)
private
view
returns (uint256 approvedAddressSlot, address approvedAddress)
{
TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];
// The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.
assembly {
approvedAddressSlot := tokenApproval.slot
approvedAddress := sload(approvedAddressSlot)
}
}
// =============================================================
// TRANSFER OPERATIONS
// =============================================================
/**
* @dev Transfers `tokenId` from `from` to `to`.
*
* 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
) public payable virtual override {
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
// Mask `from` to the lower 160 bits, in case the upper bits somehow aren't clean.
from = address(uint160(uint256(uint160(from)) & _BITMASK_ADDRESS));
if (address(uint160(prevOwnershipPacked)) != from) _revert(TransferFromIncorrectOwner.selector);
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
// The nested ifs save around 20+ gas over a compound boolean condition.
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);
_beforeTokenTransfers(from, to, tokenId, 1);
// Clear approvals from the previous owner.
assembly {
if approvedAddress {
// This is equivalent to `delete _tokenApprovals[tokenId]`.
sstore(approvedAddressSlot, 0)
}
}
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.
unchecked {
// We can directly increment and decrement the balances.
--_packedAddressData[from]; // Updates: `balance -= 1`.
++_packedAddressData[to]; // Updates: `balance += 1`.
// Updates:
// - `address` to the next owner.
// - `startTimestamp` to the timestamp of transfering.
// - `burned` to `false`.
// - `nextInitialized` to `true`.
_packedOwnerships[tokenId] = _packOwnershipData(
to,
_BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)
);
// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
// If the next slot's address is zero and not burned (i.e. packed value is zero).
if (_packedOwnerships[nextTokenId] == 0) {
// If the next slot is within bounds.
if (nextTokenId != _currentIndex) {
// Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
}
}
}
}
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;
assembly {
// Emit the `Transfer` event.
log4(
0, // Start of data (0, since no data).
0, // End of data (0, since no data).
_TRANSFER_EVENT_SIGNATURE, // Signature.
from, // `from`.
toMasked, // `to`.
tokenId // `tokenId`.
)
}
if (toMasked == 0) _revert(TransferToZeroAddress.selector);
_afterTokenTransfers(from, to, tokenId, 1);
}
/**
* @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public payable virtual override {
safeTransferFrom(from, to, tokenId, '');
}
/**
* @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 memory _data
) public payable virtual override {
transferFrom(from, to, tokenId);
if (to.code.length != 0)
if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {
_revert(TransferToNonERC721ReceiverImplementer.selector);
}
}
/**
* @dev Hook that is called before a set of serially-ordered token IDs
* are about to be transferred. This includes minting.
* And also called before burning one token.
*
* `startTokenId` - the first token ID to be transferred.
* `quantity` - the amount to be transferred.
*
* 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, `tokenId` will be burned by `from`.
* - `from` and `to` are never both zero.
*/
function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
/**
* @dev Hook that is called after a set of serially-ordered token IDs
* have been transferred. This includes minting.
* And also called after one token has been burned.
*
* `startTokenId` - the first token ID to be transferred.
* `quantity` - the amount to be transferred.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` has been
* transferred to `to`.
* - When `from` is zero, `tokenId` has been minted for `to`.
* - When `to` is zero, `tokenId` has been burned by `from`.
* - `from` and `to` are never both zero.
*/
function _afterTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
/**
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.
*
* `from` - Previous owner of the given token ID.
* `to` - Target address that will receive the token.
* `tokenId` - Token ID to be transferred.
* `_data` - Optional data to send along with the call.
*
* Returns whether the call correctly returned the expected magic value.
*/
function _checkContractOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (
bytes4 retval
) {
return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
_revert(TransferToNonERC721ReceiverImplementer.selector);
}
assembly {
revert(add(32, reason), mload(reason))
}
}
}
// =============================================================
// MINT OPERATIONS
// =============================================================
/**
* @dev Mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `quantity` must be greater than 0.
*
* Emits a {Transfer} event for each mint.
*/
function _mint(address to, uint256 quantity) internal virtual {
uint256 startTokenId = _currentIndex;
if (quantity == 0) _revert(MintZeroQuantity.selector);
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
// Overflows are incredibly unrealistic.
// `balance` and `numberMinted` have a maximum limit of 2**64.
// `tokenId` has a maximum limit of 2**256.
unchecked {
// Updates:
// - `address` to the owner.
// - `startTimestamp` to the timestamp of minting.
// - `burned` to `false`.
// - `nextInitialized` to `quantity == 1`.
_packedOwnerships[startTokenId] = _packOwnershipData(
to,
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
);
// Updates:
// - `balance += quantity`.
// - `numberMinted += quantity`.
//
// We can directly add to the `balance` and `numberMinted`.
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;
if (toMasked == 0) _revert(MintToZeroAddress.selector);
uint256 end = startTokenId + quantity;
uint256 tokenId = startTokenId;
do {
assembly {
// Emit the `Transfer` event.
log4(
0, // Start of data (0, since no data).
0, // End of data (0, since no data).
_TRANSFER_EVENT_SIGNATURE, // Signature.
0, // `address(0)`.
toMasked, // `to`.
tokenId // `tokenId`.
)
}
// The `!=` check ensures that large values of `quantity`
// that overflows uint256 will make the loop run out of gas.
} while (++tokenId != end);
_currentIndex = end;
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
/**
* @dev Mints `quantity` tokens and transfers them to `to`.
*
* This function is intended for efficient minting only during contract creation.
*
* It emits only one {ConsecutiveTransfer} as defined in
* [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),
* instead of a sequence of {Transfer} event(s).
*
* Calling this function outside of contract creation WILL make your contract
* non-compliant with the ERC721 standard.
* For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309
* {ConsecutiveTransfer} event is only permissible during contract creation.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `quantity` must be greater than 0.
*
* Emits a {ConsecutiveTransfer} event.
*/
function _mintERC2309(address to, uint256 quantity) internal virtual {
uint256 startTokenId = _currentIndex;
if (to == address(0)) _revert(MintToZeroAddress.selector);
if (quantity == 0) _revert(MintZeroQuantity.selector);
if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) _revert(MintERC2309QuantityExceedsLimit.selector);
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
// Overflows are unrealistic due to the above check for `quantity` to be below the limit.
unchecked {
// Updates:
// - `balance += quantity`.
// - `numberMinted += quantity`.
//
// We can directly add to the `balance` and `numberMinted`.
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);
// Updates:
// - `address` to the owner.
// - `startTimestamp` to the timestamp of minting.
// - `burned` to `false`.
// - `nextInitialized` to `quantity == 1`.
_packedOwnerships[startTokenId] = _packOwnershipData(
to,
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
);
emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);
_currentIndex = startTokenId + quantity;
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
/**
* @dev Safely mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement
* {IERC721Receiver-onERC721Received}, which is called for each safe transfer.
* - `quantity` must be greater than 0.
*
* See {_mint}.
*
* Emits a {Transfer} event for each mint.
*/
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
) internal virtual {
_mint(to, quantity);
unchecked {
if (to.code.length != 0) {
uint256 end = _currentIndex;
uint256 index = end - quantity;
do {
if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {
_revert(TransferToNonERC721ReceiverImplementer.selector);
}
} while (index < end);
// Reentrancy protection.
if (_currentIndex != end) _revert(bytes4(0));
}
}
}
/**
* @dev Equivalent to `_safeMint(to, quantity, '')`.
*/
function _safeMint(address to, uint256 quantity) internal virtual {
_safeMint(to, quantity, '');
}
// =============================================================
// APPROVAL OPERATIONS
// =============================================================
/**
* @dev Equivalent to `_approve(to, tokenId, false)`.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_approve(to, tokenId, false);
}
/**
* @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:
*
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function _approve(
address to,
uint256 tokenId,
bool approvalCheck
) internal virtual {
address owner = ownerOf(tokenId);
if (approvalCheck && _msgSenderERC721A() != owner)
if (!isApprovedForAll(owner, _msgSenderERC721A())) {
_revert(ApprovalCallerNotOwnerNorApproved.selector);
}
_tokenApprovals[tokenId].value = to;
emit Approval(owner, to, tokenId);
}
// =============================================================
// BURN OPERATIONS
// =============================================================
/**
* @dev Equivalent to `_burn(tokenId, false)`.
*/
function _burn(uint256 tokenId) internal virtual {
_burn(tokenId, false);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId, bool approvalCheck) internal virtual {
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
address from = address(uint160(prevOwnershipPacked));
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
if (approvalCheck) {
// The nested ifs save around 20+ gas over a compound boolean condition.
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);
}
_beforeTokenTransfers(from, address(0), tokenId, 1);
// Clear approvals from the previous owner.
assembly {
if approvedAddress {
// This is equivalent to `delete _tokenApprovals[tokenId]`.
sstore(approvedAddressSlot, 0)
}
}
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.
unchecked {
// Updates:
// - `balance -= 1`.
// - `numberBurned += 1`.
//
// We can directly decrement the balance, and increment the number burned.
// This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.
_packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;
// Updates:
// - `address` to the last owner.
// - `startTimestamp` to the timestamp of burning.
// - `burned` to `true`.
// - `nextInitialized` to `true`.
_packedOwnerships[tokenId] = _packOwnershipData(
from,
(_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)
);
// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
// If the next slot's address is zero and not burned (i.e. packed value is zero).
if (_packedOwnerships[nextTokenId] == 0) {
// If the next slot is within bounds.
if (nextTokenId != _currentIndex) {
// Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
}
}
}
}
emit Transfer(from, address(0), tokenId);
_afterTokenTransfers(from, address(0), tokenId, 1);
// Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.
unchecked {
_burnCounter++;
}
}
// =============================================================
// EXTRA DATA OPERATIONS
// =============================================================
/**
* @dev Directly sets the extra data for the ownership data `index`.
*/
function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {
uint256 packed = _packedOwnerships[index];
if (packed == 0) _revert(OwnershipNotInitializedForExtraData.selector);
uint256 extraDataCasted;
// Cast `extraData` with assembly to avoid redundant masking.
assembly {
extraDataCasted := extraData
}
packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);
_packedOwnerships[index] = packed;
}
/**
* @dev Called during each token transfer to set the 24bit `extraData` field.
* Intended to be overridden by the cosumer contract.
*
* `previousExtraData` - the value of `extraData` before transfer.
*
* 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, `tokenId` will be burned by `from`.
* - `from` and `to` are never both zero.
*/
function _extraData(
address from,
address to,
uint24 previousExtraData
) internal view virtual returns (uint24) {}
/**
* @dev Returns the next extra data for the packed ownership data.
* The returned result is shifted into position.
*/
function _nextExtraData(
address from,
address to,
uint256 prevOwnershipPacked
) private view returns (uint256) {
uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);
return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;
}
// =============================================================
// OTHER OPERATIONS
// =============================================================
/**
* @dev Returns the message sender (defaults to `msg.sender`).
*
* If you are writing GSN compatible contracts, you need to override this function.
*/
function _msgSenderERC721A() internal view virtual returns (address) {
return msg.sender;
}
/**
* @dev Converts a uint256 to its ASCII string decimal representation.
*/
function _toString(uint256 value) internal pure virtual returns (string memory str) {
assembly {
// The maximum value of a uint256 contains 78 digits (1 byte per digit), but
// we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.
// We will need 1 word for the trailing zeros padding, 1 word for the length,
// and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0.
let m := add(mload(0x40), 0xa0)
// Update the free memory pointer to allocate.
mstore(0x40, m)
// Assign the `str` to the end.
str := sub(m, 0x20)
// Zeroize the slot after the string.
mstore(str, 0)
// Cache the end of the memory to calculate the length later.
let end := str
// We write the string from rightmost digit to leftmost digit.
// The following is essentially a do-while loop that also handles the zero case.
// prettier-ignore
for { let temp := value } 1 {} {
str := sub(str, 1)
// Write the character to the pointer.
// The ASCII index of the '0' character is 48.
mstore8(str, add(48, mod(temp, 10)))
// Keep dividing `temp` until zero.
temp := div(temp, 10)
// prettier-ignore
if iszero(temp) { break }
}
let length := sub(end, str)
// Move the pointer 32 bytes leftwards to make room for the length.
str := sub(str, 0x20)
// Store the length.
mstore(str, length)
}
}
/**
* @dev For more efficient reverts.
*/
function _revert(bytes4 errorSelector) internal pure {
assembly {
mstore(0x00, errorSelector)
revert(0x00, 0x04)
}
}
}
IERC721A.sol 282 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs
pragma solidity ^0.8.4;
/**
* @dev Interface of ERC721A.
*/
interface IERC721A {
/**
* The caller must own the token or be an approved operator.
*/
error ApprovalCallerNotOwnerNorApproved();
/**
* The token does not exist.
*/
error ApprovalQueryForNonexistentToken();
/**
* Cannot query the balance for the zero address.
*/
error BalanceQueryForZeroAddress();
/**
* Cannot mint to the zero address.
*/
error MintToZeroAddress();
/**
* The quantity of tokens minted must be more than zero.
*/
error MintZeroQuantity();
/**
* The token does not exist.
*/
error OwnerQueryForNonexistentToken();
/**
* The caller must own the token or be an approved operator.
*/
error TransferCallerNotOwnerNorApproved();
/**
* The token must be owned by `from`.
*/
error TransferFromIncorrectOwner();
/**
* Cannot safely transfer to a contract that does not implement the
* ERC721Receiver interface.
*/
error TransferToNonERC721ReceiverImplementer();
/**
* Cannot transfer to the zero address.
*/
error TransferToZeroAddress();
/**
* The token does not exist.
*/
error URIQueryForNonexistentToken();
/**
* The `quantity` minted with ERC2309 exceeds the safety limit.
*/
error MintERC2309QuantityExceedsLimit();
/**
* The `extraData` cannot be set on an unintialized ownership slot.
*/
error OwnershipNotInitializedForExtraData();
// =============================================================
// STRUCTS
// =============================================================
struct TokenOwnership {
// The address of the owner.
address addr;
// Stores the start time of ownership with minimal overhead for tokenomics.
uint64 startTimestamp;
// Whether the token has been burned.
bool burned;
// Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.
uint24 extraData;
}
// =============================================================
// TOKEN COUNTERS
// =============================================================
/**
* @dev Returns the total number of tokens in existence.
* Burned tokens will reduce the count.
* To get the total number of tokens minted, please see {_totalMinted}.
*/
function totalSupply() external view returns (uint256);
// =============================================================
// IERC165
// =============================================================
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
* to learn more about how these ids are created.
*
* This function call must use less than 30000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
// =============================================================
// IERC721
// =============================================================
/**
* @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,
bytes calldata data
) external payable;
/**
* @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external payable;
/**
* @dev Transfers `tokenId` 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 payable;
/**
* @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 payable;
/**
* @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 the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @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);
// =============================================================
// IERC721Metadata
// =============================================================
/**
* @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);
// =============================================================
// IERC2309
// =============================================================
/**
* @dev Emitted when tokens in `fromTokenId` to `toTokenId`
* (inclusive) is transferred from `from` to `to`, as defined in the
* [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.
*
* See {_mintERC2309} for more details.
*/
event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
}
ERC721AQueryable.sol 228 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs
pragma solidity ^0.8.4;
import './IERC721AQueryable.sol';
import '../ERC721A.sol';
/**
* @title ERC721AQueryable.
*
* @dev ERC721A subclass with convenience query functions.
*/
abstract contract ERC721AQueryable is ERC721A, IERC721AQueryable {
/**
* @dev Returns the `TokenOwnership` struct at `tokenId` without reverting.
*
* If the `tokenId` is out of bounds:
*
* - `addr = address(0)`
* - `startTimestamp = 0`
* - `burned = false`
* - `extraData = 0`
*
* If the `tokenId` is burned:
*
* - `addr = <Address of owner before token was burned>`
* - `startTimestamp = <Timestamp when token was burned>`
* - `burned = true`
* - `extraData = <Extra data when token was burned>`
*
* Otherwise:
*
* - `addr = <Address of owner>`
* - `startTimestamp = <Timestamp of start of ownership>`
* - `burned = false`
* - `extraData = <Extra data at start of ownership>`
*/
function explicitOwnershipOf(uint256 tokenId)
public
view
virtual
override
returns (TokenOwnership memory ownership)
{
unchecked {
if (tokenId >= _startTokenId()) {
if (tokenId < _nextTokenId()) {
// If the `tokenId` is within bounds,
// scan backwards for the initialized ownership slot.
while (!_ownershipIsInitialized(tokenId)) --tokenId;
return _ownershipAt(tokenId);
}
}
}
}
/**
* @dev Returns an array of `TokenOwnership` structs at `tokenIds` in order.
* See {ERC721AQueryable-explicitOwnershipOf}
*/
function explicitOwnershipsOf(uint256[] calldata tokenIds)
external
view
virtual
override
returns (TokenOwnership[] memory)
{
TokenOwnership[] memory ownerships;
uint256 i = tokenIds.length;
assembly {
// Grab the free memory pointer.
ownerships := mload(0x40)
// Store the length.
mstore(ownerships, i)
// Allocate one word for the length,
// `tokenIds.length` words for the pointers.
i := shl(5, i) // Multiply `i` by 32.
mstore(0x40, add(add(ownerships, 0x20), i))
}
while (i != 0) {
uint256 tokenId;
assembly {
i := sub(i, 0x20)
tokenId := calldataload(add(tokenIds.offset, i))
}
TokenOwnership memory ownership = explicitOwnershipOf(tokenId);
assembly {
// Store the pointer of `ownership` in the `ownerships` array.
mstore(add(add(ownerships, 0x20), i), ownership)
}
}
return ownerships;
}
/**
* @dev Returns an array of token IDs owned by `owner`,
* in the range [`start`, `stop`)
* (i.e. `start <= tokenId < stop`).
*
* This function allows for tokens to be queried if the collection
* grows too big for a single call of {ERC721AQueryable-tokensOfOwner}.
*
* Requirements:
*
* - `start < stop`
*/
function tokensOfOwnerIn(
address owner,
uint256 start,
uint256 stop
) external view virtual override returns (uint256[] memory) {
return _tokensOfOwnerIn(owner, start, stop);
}
/**
* @dev Returns an array of token IDs owned by `owner`.
*
* This function scans the ownership mapping and is O(`totalSupply`) in complexity.
* It is meant to be called off-chain.
*
* See {ERC721AQueryable-tokensOfOwnerIn} for splitting the scan into
* multiple smaller scans if the collection is large enough to cause
* an out-of-gas error (10K collections should be fine).
*/
function tokensOfOwner(address owner) external view virtual override returns (uint256[] memory) {
uint256 start = _startTokenId();
uint256 stop = _nextTokenId();
uint256[] memory tokenIds;
if (start != stop) tokenIds = _tokensOfOwnerIn(owner, start, stop);
return tokenIds;
}
/**
* @dev Helper function for returning an array of token IDs owned by `owner`.
*
* Note that this function is optimized for smaller bytecode size over runtime gas,
* since it is meant to be called off-chain.
*/
function _tokensOfOwnerIn(
address owner,
uint256 start,
uint256 stop
) private view returns (uint256[] memory) {
unchecked {
if (start >= stop) _revert(InvalidQueryRange.selector);
// Set `start = max(start, _startTokenId())`.
if (start < _startTokenId()) {
start = _startTokenId();
}
uint256 stopLimit = _nextTokenId();
// Set `stop = min(stop, stopLimit)`.
if (stop >= stopLimit) {
stop = stopLimit;
}
uint256[] memory tokenIds;
uint256 tokenIdsMaxLength = balanceOf(owner);
bool startLtStop = start < stop;
assembly {
// Set `tokenIdsMaxLength` to zero if `start` is less than `stop`.
tokenIdsMaxLength := mul(tokenIdsMaxLength, startLtStop)
}
if (tokenIdsMaxLength != 0) {
// Set `tokenIdsMaxLength = min(balanceOf(owner), stop - start)`,
// to cater for cases where `balanceOf(owner)` is too big.
if (stop - start <= tokenIdsMaxLength) {
tokenIdsMaxLength = stop - start;
}
assembly {
// Grab the free memory pointer.
tokenIds := mload(0x40)
// Allocate one word for the length, and `tokenIdsMaxLength` words
// for the data. `shl(5, x)` is equivalent to `mul(32, x)`.
mstore(0x40, add(tokenIds, shl(5, add(tokenIdsMaxLength, 1))))
}
// We need to call `explicitOwnershipOf(start)`,
// because the slot at `start` may not be initialized.
TokenOwnership memory ownership = explicitOwnershipOf(start);
address currOwnershipAddr;
// If the starting slot exists (i.e. not burned),
// initialize `currOwnershipAddr`.
// `ownership.address` will not be zero,
// as `start` is clamped to the valid token ID range.
if (!ownership.burned) {
currOwnershipAddr = ownership.addr;
}
uint256 tokenIdsIdx;
// Use a do-while, which is slightly more efficient for this case,
// as the array will at least contain one element.
do {
ownership = _ownershipAt(start);
assembly {
switch mload(add(ownership, 0x40))
// if `ownership.burned == false`.
case 0 {
// if `ownership.addr != address(0)`.
// The `addr` already has it's upper 96 bits clearned,
// since it is written to memory with regular Solidity.
if mload(ownership) {
currOwnershipAddr := mload(ownership)
}
// if `currOwnershipAddr == owner`.
// The `shl(96, x)` is to make the comparison agnostic to any
// dirty upper 96 bits in `owner`.
if iszero(shl(96, xor(currOwnershipAddr, owner))) {
tokenIdsIdx := add(tokenIdsIdx, 1)
mstore(add(tokenIds, shl(5, tokenIdsIdx)), start)
}
}
// Otherwise, reset `currOwnershipAddr`.
// This handles the case of batch burned tokens
// (burned bit of first slot set, remaining slots left uninitialized).
default {
currOwnershipAddr := 0
}
start := add(start, 1)
}
} while (!(start == stop || tokenIdsIdx == tokenIdsMaxLength));
// Store the length of the array.
assembly {
mstore(tokenIds, tokenIdsIdx)
}
}
return tokenIds;
}
}
}
IERC721AQueryable.sol 79 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs
pragma solidity ^0.8.4;
import '../IERC721A.sol';
/**
* @dev Interface of ERC721AQueryable.
*/
interface IERC721AQueryable is IERC721A {
/**
* Invalid query range (`start` >= `stop`).
*/
error InvalidQueryRange();
/**
* @dev Returns the `TokenOwnership` struct at `tokenId` without reverting.
*
* If the `tokenId` is out of bounds:
*
* - `addr = address(0)`
* - `startTimestamp = 0`
* - `burned = false`
* - `extraData = 0`
*
* If the `tokenId` is burned:
*
* - `addr = <Address of owner before token was burned>`
* - `startTimestamp = <Timestamp when token was burned>`
* - `burned = true`
* - `extraData = <Extra data when token was burned>`
*
* Otherwise:
*
* - `addr = <Address of owner>`
* - `startTimestamp = <Timestamp of start of ownership>`
* - `burned = false`
* - `extraData = <Extra data at start of ownership>`
*/
function explicitOwnershipOf(uint256 tokenId) external view returns (TokenOwnership memory);
/**
* @dev Returns an array of `TokenOwnership` structs at `tokenIds` in order.
* See {ERC721AQueryable-explicitOwnershipOf}
*/
function explicitOwnershipsOf(uint256[] memory tokenIds) external view returns (TokenOwnership[] memory);
/**
* @dev Returns an array of token IDs owned by `owner`,
* in the range [`start`, `stop`)
* (i.e. `start <= tokenId < stop`).
*
* This function allows for tokens to be queried if the collection
* grows too big for a single call of {ERC721AQueryable-tokensOfOwner}.
*
* Requirements:
*
* - `start < stop`
*/
function tokensOfOwnerIn(
address owner,
uint256 start,
uint256 stop
) external view returns (uint256[] memory);
/**
* @dev Returns an array of token IDs owned by `owner`.
*
* This function scans the ownership mapping and is O(`totalSupply`) in complexity.
* It is meant to be called off-chain.
*
* See {ERC721AQueryable-tokensOfOwnerIn} for splitting the scan into
* multiple smaller scans if the collection is large enough to cause
* an out-of-gas error (10K collections should be fine).
*/
function tokensOfOwner(address owner) external view returns (uint256[] memory);
}
Read Contract
artistAddy 0x58b3fcbf → address
balanceOf 0x70a08231 → uint256
bonusThreshold 0xbc4eaa3e → uint256
devAddy 0x29570778 → address
erc20MintCounter 0x3e016306 → uint256
erc20MintLimit 0x7d847c51 → uint256
erc20TokenAddress 0xf835cd3c → address
erc20TokenCost 0x139722f8 → uint256
explicitOwnershipOf 0xc23dc68f → tuple
explicitOwnershipsOf 0x5bbb2177 → tuple[]
getApproved 0x081812fc → address
getPausedState 0x1c0de051 → bool
getTotalSupply 0xc4e41b22 → uint256
hiddenMetadataUri 0xa45ba8e7 → string
isApprovedForAll 0xe985e9c5 → bool
maxSupply 0xd5abeb01 → uint256
mintCounter 0x46aa52ce → uint256
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
paused 0x5c975abb → bool
publicCost 0x8693da20 → uint256
revealed 0x51830227 → bool
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenURI 0xc87b56dd → string
tokensOfOwner 0x8462151c → uint256[]
tokensOfOwnerIn 0x99a2557a → uint256[]
totalSupply 0x18160ddd → uint256
uriPrefix 0x62b99ad4 → string
uriSuffix 0x5503a0e8 → string
walletOfOwner 0x438b6300 → uint256[]
Write Contract 24 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address to
uint256 tokenId
burn 0x42966c68
uint256 tokenId
burnMultiple 0x6ab49a5b
uint256[] ids
mintForAddressMultiple 0xde6c6d36
address[] addresses
uint256[] amount
publicMint 0x41a38e7f
uint256 _mintAmount
address receiver
publicMintRaw 0xe5ebc741
uint256 _mintAmount
publicMintWithSheesh 0x97023891
uint256 _mintAmount
address receiver
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
setArtistAddy 0x95e7099e
address _newAddress
setBonusThreshold 0xb5f6b1f6
uint256 _newAmount
setDevAddy 0x05000410
address _newAddress
setERC20Token 0x5c0b52f6
address _erc20TokenAddress
uint256 _erc20TokenCost
uint256 _erc20MintLimit
setPaused 0x16c38b3c
bool _state
setPublicMintCost 0x80eae578
uint256 _mintCost
setRevealed 0xe0a80853
bool _state
setUriPrefix 0x7ec4a659
string _uriPrefix
setUriSuffix 0x16ba10e0
string _uriSuffix
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
withdrawAll 0x853828b6
No parameters
withdrawAllWithSplit 0xdae9298b
No parameters
Recent Transactions
No transactions found for this address