Address Contract Verified
Address
0xc8b3993f259c15F0dBAB64a9f150d2D915aD8401
Balance
0 ETH
Nonce
1
Code Size
20485 bytes
Creator
0x465eB31E...BF4a at tx 0xac2c0fca...49cb55
Indexed Transactions
0
Contract Bytecode
20485 bytes
0x6080604052600436106102f5575f3560e01c80638eda900f11610189578063cc2ee196116100d8578063e757223011610092578063f4b2652e1161006d578063f4b2652e14610b0d578063f52125ad14610b39578063f5954d8314610b4c578063ffa1ad7414610b60575f5ffd5b8063e757223014610a9b578063e985e9c514610acf578063f2fde38b14610aee575f5ffd5b8063cc2ee196146109f6578063cd44673514610a0a578063d07558d314610a1e578063d9d6165514610a31578063e1a4474914610a5d578063e68f3bd814610a7c575f5ffd5b8063a96ec5d811610143578063b88d4fde1161011e578063b88d4fde14610869578063bc7dd87e14610888578063c45c52641461099f578063c87b56dd146109d7575f5ffd5b8063a96ec5d81461080c578063ac9fe7ef1461082b578063b0b5babe1461084a575f5ffd5b80638eda900f1461073757806395d89b411461077b5780639dc29fac1461078f578063a15454ba146107ae578063a22cb465146107c1578063a8cbf238146107e0575f5ffd5b80633567809b1161024557806360514869116101ff57806370a08231116101da57806370a08231146106ba57806386e32ed0146106e7578063893d20e8146107065780638a99941714610723575f5ffd5b8063605148691461065d5780636352211e1461067c57806370072f111461069b575f5ffd5b80633567809b1461052857806335f1013c14610547578063410459ad1461056657806342842e0e146105855780634e79b701146105a4578063538741c51461063c575f5ffd5b80631b8f81c7116102b0578063234be6e11161028b578063234be6e1146104c357806323b872dd146104e25780632ba27019146105015780632c2dae4a14610514575f5ffd5b80631b8f81c71461047e5780631cc2c9111461049d57806322e21b41146104b0575f5ffd5b80620fc51d146103ad57806301ffc9a7146103c057806306fdde03146103f4578063081812fc14610415578063095ea7b31461044c5780631072cbea1461046b575f5ffd5b366103a957604080513381523460208201527f5741979df5f3e491501da74d3b0a83dd2496ab1f34929865b3e190a8ad75859a910160405180910390a1600754604080515f8082526020820192839052926001600160a01b031691349161035b916142d2565b5f6040518083038185875af1925050503d805f8114610395576040519150601f19603f3d011682016040523d82523d5f602084013e61039a565b606091505b50509050806103a7575f5ffd5b005b5f5ffd5b6103a76103bb366004614372565b610b75565b3480156103cb575f5ffd5b506103df6103da366004614463565b610f1e565b60405190151581526020015b60405180910390f35b3480156103ff575f5ffd5b50610408610f2e565b6040516103eb91906144ac565b348015610420575f5ffd5b5061043461042f3660046144be565b610fbd565b6040516001600160a01b0390911681526020016103eb565b348015610457575f5ffd5b506103a76104663660046144e9565b610fe4565b6103a76104793660046144e9565b610ff3565b348015610489575f5ffd5b506103a7610498366004614513565b611108565b6103a76104ab3660046144e9565b611223565b6103a76104be36600461455e565b6113f7565b3480156104ce575f5ffd5b506103a76104dd3660046144be565b6115bc565b3480156104ed575f5ffd5b506103a76104fc366004614597565b61163a565b6103a761050f3660046145d5565b6116c3565b34801561051f575f5ffd5b506104346117f5565b348015610533575f5ffd5b506103a76105423660046145ff565b611834565b348015610552575f5ffd5b506104346105613660046144be565b6118b8565b348015610571575f5ffd5b506103a76105803660046145ff565b61195f565b348015610590575f5ffd5b506103a761059f366004614597565b611a27565b3480156105af575f5ffd5b506106136105be3660046144be565b60408051606080820183525f8083526020808401829052928401819052938452601382529282902082519384018352805460ff81168552610100900460081b60ff191691840191909152600101549082015290565b60408051825160ff16815260208084015160ff19169082015291810151908201526060016103eb565b348015610647575f5ffd5b50610650611a41565b6040516103eb919061461a565b348015610668575f5ffd5b506103a76106773660046144be565b611ace565b348015610687575f5ffd5b506104346106963660046144be565b611b3b565b3480156106a6575f5ffd5b506103a76106b53660046145ff565b611b45565b3480156106c5575f5ffd5b506106d96106d43660046145ff565b611c93565b6040519081526020016103eb565b3480156106f2575f5ffd5b506103a76107013660046145ff565b611cd8565b348015610711575f5ffd5b506006546001600160a01b0316610434565b34801561072e575f5ffd5b50610434611dc5565b348015610742575f5ffd5b506107566107513660046145ff565b611e04565b60408051825181526020928301516001600160801b03191692810192909252016103eb565b348015610786575f5ffd5b50610408611e87565b34801561079a575f5ffd5b506103a76107a93660046144e9565b611e96565b6103a76107bc3660046144be565b611f35565b3480156107cc575f5ffd5b506103a76107db366004614674565b611faf565b3480156107eb575f5ffd5b506107ff6107fa3660046144be565b611fba565b6040516103eb919061469e565b348015610817575f5ffd5b506103a76108263660046145ff565b61203e565b348015610836575f5ffd5b506103a76108453660046145ff565b612106565b348015610855575f5ffd5b506103df6108643660046144be565b6121ce565b348015610874575f5ffd5b506103a7610883366004614742565b612212565b348015610893575f5ffd5b506109926108a23660046144be565b60408051610100810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810191909152505f9081526010602090815260409182902082516101008101845281546001600160401b038116825268010000000000000000810460481b68ffffffffffffffffff191693820193909352600160f81b90920460ff16928201929092526001820154606082015260028201546080820152600382015460a0808301919091526004909201546001600160a01b03811660c0830152600160a01b900490911b6001600160a01b03191660e082015290565b6040516103eb9190614802565b3480156109aa575f5ffd5b506109be6109b93660046144be565b61222a565b6040516001600160801b031990911681526020016103eb565b3480156109e2575f5ffd5b506104086109f13660046144be565b61225e565b348015610a01575f5ffd5b50600a546106d9565b348015610a15575f5ffd5b506104346122cf565b6103a7610a2c3660046144be565b61230e565b348015610a3c575f5ffd5b50610a50610a4b3660046145ff565b6123ee565b6040516103eb91906148c8565b348015610a68575f5ffd5b506103a7610a773660046144be565b612457565b348015610a87575f5ffd5b506103a7610a963660046148da565b6124bf565b348015610aa6575f5ffd5b506106d9610ab53660046144be565b5f908152601060205260409020546001600160401b031690565b348015610ada575f5ffd5b506103df610ae93660046148fb565b612542565b348015610af9575f5ffd5b506103a7610b083660046145ff565b61256f565b348015610b18575f5ffd5b50610b2c610b27366004614932565b612637565b6040516103eb9190614952565b6103a7610b473660046144be565b61286a565b348015610b57575f5ffd5b506106d96129d7565b348015610b6b575f5ffd5b506106d96174e581565b610b7d612a0d565b600a5460011615610bac575f60405163bb38095f60e01b8152600401610ba391906149d8565b60405180910390fd5b335f908152600c6020526040902054610bda578b60405163bb38095f60e01b8152600401610ba391906149ff565b895f03610c1a578b60405163bb38095f60e01b8152600401610ba3918152604060208201819052600490820152635b65315d60e01b606082015260800190565b683635c9adc5dea000008b6001600160401b03161115610c6d578b60405163bb38095f60e01b8152600401610ba3918152604060208201819052600490820152635b65325d60e01b606082015260800190565b5f620fffff610c7e6002600a614a39565b610c8990600a614a39565b610c94906020614a39565b610c9f906020614a39565b610caa906020614a39565b600a54901c16905080821115610cf3578c60405163bb38095f60e01b8152600401610ba3918152604060208201819052600490820152635b65335d60e01b606082015260800190565b335f908152600d60209081526040822080546001810182559083529120018d905560ff851615610d2857610d288d8686612a7c565b6040518061010001604052808d6001600160401b031681526020018b68ffffffffffffffffff191681526020018760ff1681526020018c8152602001898152602001888152602001336001600160a01b031681526020018a6001600160a01b03191681525060105f8f81526020019081526020015f205f820151815f015f6101000a8154816001600160401b0302191690836001600160401b031602179055506020820151815f0160086101000a8154816001600160b81b03021916908360481c02179055506040820151815f01601f6101000a81548160ff021916908360ff160217905550606082015181600101556080820151816002015560a0820151816003015560c0820151816004015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060e08201518160040160146101000a8154816bffffffffffffffffffffffff021916908360a01c0217905550905050610ee28d8484808060200260200160405190810160405280939291908181526020015f905b82821015610ed857610ec960408302860136819003810190614a4c565b81526020019060010190610eac565b5050505050612b31565b610eec338e612d21565b60ff851615610efe57610efe8d612d3a565b610f078d612df3565b50610f10612e96565b505050505050505050505050565b5f610f2882612ec0565b92915050565b60605f8054610f3c90614aa3565b80601f0160208091040260200160405190810160405280929190818152602001828054610f6890614aa3565b8015610fb35780601f10610f8a57610100808354040283529160200191610fb3565b820191905f5260205f20905b815481529060010190602001808311610f9657829003601f168201915b5050505050905090565b5f610fc782612f0f565b505f828152600460205260409020546001600160a01b0316610f28565b610fef828233612f47565b5050565b610ffb612a0d565b600a5460011615611021575f60405163bb38095f60e01b8152600401610ba391906149d8565b5f818152600e6020526040902054819060ff1615611054578060405163bb38095f60e01b8152600401610ba39190614adb565b813361105f82611b3b565b6001600160a01b031614611088578060405163bb38095f60e01b8152600401610ba39190614b01565b6001600160a01b0384165f908152600c60205260409020546110bf578260405163bb38095f60e01b8152600401610ba391906149ff565b6110c93384612f54565b6001600160a01b0384165f908152600d60209081526040822080546001810182559083529120018390556110fe338585611a27565b5050610fef612e96565b611110612a0d565b6006546001600160a01b0316331480159061113657506009546001600160a01b03163314155b15611156575f60405163bb38095f60e01b8152600401610ba39190614b27565b6001600160a01b038316158061117457506001600160a01b03831630145b8061118757506001600160a01b03831633145b156111c6576040805163bb38095f60e01b81525f6004820152602481019190915260066044820152655b737431315d60d01b6064820152608401610ba3565b6040805180820182528381526001600160801b031983811660208084019182526001600160a01b0388165f908152600c909152939093209151825591516001909101805490921660809190911c17905561121e612e96565b505050565b61122b612a0d565b600a5460011615611251575f60405163bb38095f60e01b8152600401610ba391906149d8565b5f818152600e6020526040902054819060ff1615611284578060405163bb38095f60e01b8152600401610ba39190614adb565b335f908152600c60205260409020546112b2578160405163bb38095f60e01b8152600401610ba391906149ff565b5f828152601060205260408120546001600160401b03169003611309578160405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6532305d60d81b606082015260800190565b5f8281526010602052604081205461132e906001600160401b0316633b9aca00614b4d565b6001600160401b031690505f816113448361306e565b61134e9190614a39565b90506113736040518060600160405280602d8152602001614fa3602d913982346130d1565b348111156113b5578360405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6532315d60d81b606082015260800190565b6113bf8585612f54565b335f818152600d60209081526040822080546001810182559083529120018590556113ec90869086613118565b505050610fef612e96565b5f838152600e6020526040902054839060ff161561142a578060405163bb38095f60e01b8152600401610ba39190614adb565b833361143582611b3b565b6001600160a01b03161461145e578060405163bb38095f60e01b8152600401610ba39190614b01565b5f85815260136020526040902060010154156114ae578460405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6d73335d60d81b606082015260800190565b8360ff165f036114f2578460405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6d73345d60d81b606082015260800190565b5f858152601060205260409020600401546001600160a01b0316331461154c578460405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6d73355d60d81b606082015260800190565b60405180606001604052808560ff1681526020018460ff19168152602001601254426115789190614a39565b90525f8681526013602090815260409182902083519184015160081c6101000260ff9092169190911781559101516001909101556115b585612d3a565b5050505050565b60065481906001600160a01b031633148015906115e457506008546001600160a01b03163314155b15611623578060405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b7374335d60d81b606082015260800190565b505f90815260136020526040812081815560010155565b6001600160a01b03821661166357604051633250574960e11b81525f6004820152602401610ba3565b5f61166f838333613132565b9050836001600160a01b0316816001600160a01b0316146116bd576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610ba3565b50505050565b6116cb612a0d565b600a54600116156116f1575f60405163bb38095f60e01b8152600401610ba391906149d8565b5f828152600e6020526040902054829060ff1615611724578060405163bb38095f60e01b8152600401610ba39190614adb565b823361172f82611b3b565b6001600160a01b031614611758578060405163bb38095f60e01b8152600401610ba39190614b01565b5f848152601060205260409020805467ffffffffffffffff19166001600160401b03851617815561178885611f35565b7f5c43325359179f4471448fd5c0247053caeec2178ee6378a1a3eb4b2030d314633866117b987633b9aca00614b4d565b604080516001600160a01b03909416845260208401929092526001600160401b03169082015260600160405180910390a1505050610fef612e96565b6006545f906001600160a01b03163314611824575f60405163bb38095f60e01b8152600401610ba39190614b6f565b506008546001600160a01b031690565b61183c612a0d565b6006546001600160a01b0316331480159061186257506009546001600160a01b03163314155b15611882575f60405163bb38095f60e01b8152600401610ba39190614b27565b6001600160a01b0381165f908152600c6020526040812090815560010180546001600160801b03191690556118b5612e96565b50565b5f8181805b600b5481101561190e57336001600160a01b0316600b82815481106118e4576118e4614b95565b5f918252602090912001546001600160a01b031603611906576001915061190e565b6001016118bd565b508061194e578160405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b7374305d60d81b606082015260800190565b61195784611b3b565b949350505050565b611967612a0d565b6006546001600160a01b03163314611994575f60405163bb38095f60e01b8152600401610ba39190614b6f565b6001600160a01b03811615806119b257506001600160a01b03811630145b806119c557506001600160a01b03811633145b15611a04576040805163bb38095f60e01b81525f6004820152602481019190915260066044820152655b737432365d60d01b6064820152608401610ba3565b600780546001600160a01b0319166001600160a01b0383161790556118b5612e96565b61121e83838360405180602001604052805f815250612212565b6006546060906001600160a01b03163314611a71575f60405163bb38095f60e01b8152600401610ba39190614b6f565b600b805480602002602001604051908101604052809291908181526020018280548015610fb357602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311611aa7575050505050905090565b6006545f906001600160a01b03163314801590611af657506008546001600160a01b03163314155b15611b35578060405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b7374335d60d81b606082015260800190565b50601255565b5f610f2882612f0f565b611b4d612a0d565b6006546001600160a01b03163314611b7a575f60405163bb38095f60e01b8152600401610ba39190614b6f565b6001600160a01b0381161580611b9857506001600160a01b03811630145b80611bab57506001600160a01b03811633145b15611be9576040805163bb38095f60e01b81525f6004820152602481019190915260056044820152645b7374345d60d81b6064820152608401610ba3565b600b545f9081905b8083108015611c005750600883105b15611c5657836001600160a01b0316600b8481548110611c2257611c22614b95565b5f918252602090912001546001600160a01b031603611c445760019150611c56565b82611c4e81614ba9565b935050611bf1565b8115611c8857600b8381548110611c6f57611c6f614b95565b5f91825260209091200180546001600160a01b03191690555b5050506118b5612e96565b5f6001600160a01b038216611cbd576040516322718ad960e21b81525f6004820152602401610ba3565b506001600160a01b03165f9081526003602052604090205490565b6006546001600160a01b03163314611d05575f60405163bb38095f60e01b8152600401610ba39190614b6f565b6001600160a01b0381161580611d2357506001600160a01b03811630145b80611d3657506001600160a01b03811633145b15611d74576040805163bb38095f60e01b81525f6004820152602481019190915260056044820152645b7374325d60d81b6064820152608401610ba3565b600b80546001810182555f919091527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db90180546001600160a01b0319166001600160a01b0392909216919091179055565b6006545f906001600160a01b03163314611df4575f60405163bb38095f60e01b8152600401610ba39190614b6f565b506009546001600160a01b031690565b604080518082019091525f80825260208201526006546001600160a01b03163314611e44575f60405163bb38095f60e01b8152600401610ba39190614b6f565b506001600160a01b0381165f908152600c60209081526040918290208251808401909352805483526001015460801b6001600160801b031916908201525b919050565b606060018054610f3c90614aa3565b611e9e612a0d565b6006546001600160a01b03163314611ecb575f60405163bb38095f60e01b8152600401610ba39190614b6f565b611ed58282612f54565b5f8181526013602090815260408083208381556001908101849055601083528184208481559081018490556002810184905560038101849055600401839055600f9091528120611f2491614265565b611f2d816135f7565b610fef612e96565b5f611f3e61362f565b90508015610fef5780341015611f88578160405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6533355d60d81b606082015260800190565b610fef8282604051806040016040528060048152602001635b70355d60e01b815250613671565b610fef338383613789565b6060600f5f8381526020019081526020015f20805480602002602001604051908101604052809291908181526020015f905b82821015612033575f848152602090819020604080518082019091526002850290910180546001600160a01b03168252600190810154828401529083529092019101611fec565b505050509050919050565b612046612a0d565b6006546001600160a01b03163314612073575f60405163bb38095f60e01b8152600401610ba39190614b6f565b6001600160a01b038116158061209157506001600160a01b03811630145b806120a457506001600160a01b03811633145b156120e3576040805163bb38095f60e01b81525f6004820152602481019190915260066044820152655b737432325d60d01b6064820152608401610ba3565b600980546001600160a01b0319166001600160a01b0383161790556118b5612e96565b61210e612a0d565b6006546001600160a01b0316331461213b575f60405163bb38095f60e01b8152600401610ba39190614b6f565b6001600160a01b038116158061215957506001600160a01b03811630145b8061216c57506001600160a01b03811633145b156121ab576040805163bb38095f60e01b81525f6004820152602481019190915260066044820152655b737432315d60d01b6064820152608401610ba3565b600880546001600160a01b0319166001600160a01b0383161790556118b5612e96565b6006545f906001600160a01b031633146121fd575f60405163bb38095f60e01b8152600401610ba39190614b6f565b505f908152600e602052604090205460ff1690565b61221d84848461163a565b6116bd3385858585613827565b60118181548110612239575f80fd5b905f5260205f209060029182820401919006601002915054906101000a900460801b81565b606061226982612f0f565b505f61227f60408051602081019091525f815290565b90505f81511161229d5760405180602001604052805f8152506122c8565b806122a78461394e565b6040516020016122b8929190614bc1565b6040516020818303038152906040525b9392505050565b6006545f906001600160a01b031633146122fe575f60405163bb38095f60e01b8152600401610ba39190614b6f565b506007546001600160a01b031690565b5f818152600e6020526040902054819060ff1615612341578060405163bb38095f60e01b8152600401610ba39190614adb565b813361234c82611b3b565b6001600160a01b031614612375578060405163bb38095f60e01b8152600401610ba39190614b01565b5f8381526013602052604081206001015490036123c7578260405163bb38095f60e01b8152600401610ba3918152604060208201819052600690820152655b6d7331305d60d01b606082015260800190565b6012546123d49042614a39565b5f8481526013602052604090206001015561121e83612d3a565b6001600160a01b0381165f908152600d602090815260409182902080548351818402810184019094528084526060939283018282801561244b57602002820191905f5260205f20905b815481526020019060010190808311612437575b50505050509050919050565b6006546001600160a01b03163314612484575f60405163bb38095f60e01b8152600401610ba39190614b6f565b600a8190556040518181527f12220fe348bfcd9d89bf856b98667916c5db45a8a2805aa90882d5c85f9c9ba19060200160405180910390a150565b6006546001600160a01b031633148015906124e557506009546001600160a01b03163314155b15612505575f60405163bb38095f60e01b8152600401610ba39190614b27565b801561252a575f828152600e60205260409020805482151560ff199091161790555050565b505f908152600e60205260409020805460ff19169055565b6001600160a01b039182165f90815260056020908152604080832093909416825291909152205460ff1690565b612577612a0d565b6006546001600160a01b031633146125a4575f60405163bb38095f60e01b8152600401610ba39190614b6f565b6001600160a01b03811615806125c257506001600160a01b03811630145b806125d557506001600160a01b03811633145b15612614576040805163bb38095f60e01b81525f6004820152602481019190915260066044820152655b737432355d60d01b6064820152608401610ba3565b600680546001600160a01b0319166001600160a01b0383161790556118b5612e96565b61265a604051806060016040528060608152602001606081526020015f81525090565b604080516060810182525f858152600f6020529182205481906001600160401b0381111561268a5761268a6142a7565b6040519080825280602002602001820160405280156126b3578160200160208202803683370190505b5081525f868152600f60209081526040909120549101906001600160401b038111156126e1576126e16142a7565b60405190808252806020026020018201604052801561270a578160200160208202803683370190505b5081526020015f81525090505f5b5f858152600f6020526040902054811015612862575f858152600f6020526040812080548390811061274c5761274c614b95565b905f5260205f20906002020190505f6103e882600101548761276e9190614bd5565b6127789190614bec565b905080861061281d5781546001600160a01b031615612818578154845180516001600160a01b0390921691859081106127b3576127b3614b95565b60200260200101906001600160a01b031690816001600160a01b03168152505080846020015184815181106127ea576127ea614b95565b60200260200101818152505080846040018181516128089190614a39565b9052506128158187614c0b565b95505b612858565b8660405163bb38095f60e01b8152600401610ba3918152604060208201819052600690820152655b707235325d60d01b606082015260800190565b5050600101612718565b509392505050565b612872612a0d565b600a5460011615612898575f60405163bb38095f60e01b8152600401610ba391906149d8565b5f818152600e6020526040902054819060ff16156128cb578060405163bb38095f60e01b8152600401610ba39190614adb565b81336128d682611b3b565b6001600160a01b0316146128ff578060405163bb38095f60e01b8152600401610ba39190614b01565b5f8381526013602052604081206001015490819003612953578360405163bb38095f60e01b8152600401610ba3918152604060208201819052600690820152655b6d7331305d60d01b606082015260800190565b42811015612996578360405163bb38095f60e01b8152600401610ba3918152604060208201819052600690820152655b6d7331315d60d01b606082015260800190565b604080518581523360208201527f9cddb6dd6d50ebaa3526fdf84bff3431842b256572538449a2bebd634b548d47910160405180910390a1611c8884611f35565b6006545f906001600160a01b03163314612a06575f60405163bb38095f60e01b8152600401610ba39190614b6f565b5060125490565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c15612a4d57604051633ee5aeb560e01b815260040160405180910390fd5b612a7a60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005b906139dd565b565b5f8381526013602052604090206001015415612acc578260405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6d73315d60d81b606082015260800190565b60405180606001604052808360ff1681526020018260ff1916815260200160125442612af89190614a39565b90525f8481526013602090815260409182902083519184015160081c6101000260ff909216919091178155910151600190910155505050565b805115610fef575f5b815181101561121e575f828281518110612b5657612b56614b95565b60209081029190910101515190506001600160a01b0381161580612b8257506001600160a01b03811630145b80612b9557506001600160a01b03811633145b15612bd3578360405163bb38095f60e01b8152600401610ba3918152604060208201819052600490820152635b65345d60e01b606082015260800190565b5f816001600160a01b03163111612c1d578360405163bb38095f60e01b8152600401610ba3918152604060208201819052600490820152635b65355d60e01b606082015260800190565b5f5b8351811015612cab57828114158015612c655750838181518110612c4557612c45614b95565b60200260200101515f01516001600160a01b0316826001600160a01b0316145b15612ca3578460405163bb38095f60e01b8152600401610ba3918152604060208201819052600490820152635b65365d60e01b606082015260800190565b600101612c1f565b505f848152600f602052604090208351849084908110612ccd57612ccd614b95565b6020908102919091018101518254600180820185555f94855293839020825160029092020180546001600160a01b0319166001600160a01b0390921691909117815591015190820155919091019050612b3a565b610fef828260405180602001604052805f8152506139e4565b5f63ffffffff612d4c6002600a614a39565b612d5790600a614a39565b612d62906020614a39565b612d6d906020614a39565b600a54612d8292911c1664e8d4a51000614bd5565b90508015610fef5780341015612dcc578160405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6536305d60d81b606082015260800190565b610fef8282604051806040016040528060048152602001635b70365d60e01b815250613671565b5f63ffffffff612e056002600a614a39565b612e1090600a614a39565b600a54612e2592911c1664e8d4a51000614bd5565b90508015610fef5780341015612e6f578160405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6531305d60d81b606082015260800190565b610fef8282604051806040016040528060048152602001635b70315d60e01b815250613671565b612a7a5f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00612a74565b5f6001600160e01b031982166380ac58cd60e01b1480612ef057506001600160e01b03198216635b5e139f60e01b145b80610f2857506301ffc9a760e01b6001600160e01b0319831614610f28565b5f818152600260205260408120546001600160a01b031680610f2857604051637e27328960e01b815260048101849052602401610ba3565b61121e83838360016139fb565b816001600160a01b0316612f6782611b3b565b6001600160a01b031614612faf578060405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6535315d60d81b606082015260800190565b6001600160a01b0382165f908152600d6020526040812054905b818110156116bd576001600160a01b0384165f908152600d60205260409020805484919083908110612ffd57612ffd614b95565b905f5260205f200154036130665761302e604051806060016040528060218152602001614f18602191398486613aff565b6001600160a01b0384165f908152600d6020526040902080548290811061305757613057614b95565b5f9182526020822001556116bd565b600101612fc9565b5f80806103ff6130806002600a614a39565b600a54901c16905080156130ca576103e861309b8286614bd5565b6130a59190614bec565b91506130ca604051806060016040528060238152602001614f396023913982846130d1565b5092915050565b61121e8383836040516024016130e993929190614c1e565b60408051601f198184030181529190526020810180516001600160e01b031663ca47c4eb60e01b179052613b42565b61121e83838360405180602001604052805f815250613b4b565b5f6001600a54165f1461315a575f60405163bb38095f60e01b8152600401610ba391906149d8565b61319b6040518060400160405280601f81526020017f55706461746520746f20257320746f6b656e4964202573206175746820257300815250858585613b56565b5f838152600260205260408120546001600160a01b031690506001600160a01b038516158015906131d357506001600160a01b038116155b15613218576132056040518060400160405280600c81526020016b0b4b4b4b4b4b4b4f9352539560a21b815250613b9f565b613210858585613be2565b9150506122c8565b6001600160a01b03851615801561323657506001600160a01b038316155b15613268576132056040518060400160405280600c81526020016b169696969696969f212aa92760a11b815250613b9f565b6001600160a01b0385161580159061328857506001600160a01b03831633145b156132f9576132be6040518060400160405280601081526020016f169696969696969f2a2920a729a322a960811b815250613b9f565b5f848152601060205260408120805467ffffffffffffffff191690556132e5868686613be2565b90506132f085611f35565b91506122c89050565b5f8481526010602052604081208054909190613322906001600160401b0316633b9aca00614b4d565b6001600160401b03169050613350604051806060016040528060278152602001614f7c6027913934836130d1565b6001600160a01b03871630148061336657508034105b156133a5578560405163bb38095f60e01b8152600401610ba3918152604060208201819052600590820152645b6534305d60d81b606082015260800190565b5f6133b188885f613be2565b5f88815260106020526040808220805467ffffffffffffffff1916905551637a59329760e11b8152600481018a9052602481018590529192508391309063f4b2652e906044015f60405180830381865afa158015613411573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526134389190810190614cce565b5f8a8152600f602052604081209192506134529190614265565b60408101516134619083614c0b565b604080518b81523360208201526001600160a01b038916818301526060810183905260a060808201819052600590820152645b7031305d60d81b60c082015290519193505f516020614f5c5f395f51905f52919081900360e00190a15f6134c78561306e565b9050801561352b57600754604080518c81523360208201526001600160a01b03909216828201526060820183905260a060808301819052600590830152645b7031315d60d81b60c0830152515f516020614f5c5f395f51905f529181900360e00190a15b60408201511561355d5761355d8a83604051806040016040528060058152602001645b7035305d60d81b815250613cd4565b6135888a8885604051806040016040528060058152602001645b7031305d60d81b8152506001613d7b565b80156135b6576135b68a82604051806040016040528060058152602001645b7031315d60d81b815250613e2f565b6040820151156135e8576135e88a83604051806040016040528060058152602001645b7035305d60d81b815250613e55565b50919998505050505050505050565b5f6136035f835f613132565b90506001600160a01b038116610fef57604051637e27328960e01b815260048101839052602401610ba3565b5f63ffffffff6136416002600a614a39565b61364c90600a614a39565b613657906020614a39565b600a5461366c92911c1664e8d4a51000614bd5565b905090565b6136b16040518060400160405280601a81526020017f706179506179656520616d6f756e7420257320747970652025730000000000008152508383613f55565b6007546040516001600160a01b03909116905f516020614f5c5f395f51905f52906136e59086903390859088908890614dce565b60405180910390a15f816001600160a01b0316848460405160200161370a91906144ac565b60408051601f1981840301815290829052613724916142d2565b5f6040518083038185875af1925050503d805f811461375e576040519150601f19603f3d011682016040523d82523d5f602084013e613763565b606091505b50509050806115b557848360405163bb38095f60e01b8152600401610ba3929190614e11565b6001600160a01b0382166137bb57604051630b61174360e31b81526001600160a01b0383166004820152602401610ba3565b6001600160a01b038381165f81815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b0383163b156115b557604051630a85bd0160e11b81526001600160a01b0384169063150b7a0290613869908890889087908790600401614e29565b6020604051808303815f875af19250505080156138a3575060408051601f3d908101601f191682019092526138a091810190614e65565b60015b61390a573d8080156138d0576040519150601f19603f3d011682016040523d82523d5f602084013e6138d5565b606091505b5080515f0361390257604051633250574960e11b81526001600160a01b0385166004820152602401610ba3565b805160208201fd5b6001600160e01b03198116630a85bd0160e11b1461394657604051633250574960e11b81526001600160a01b0385166004820152602401610ba3565b505050505050565b60605f61395a83613f9c565b60010190505f816001600160401b03811115613978576139786142a7565b6040519080825280601f01601f1916602001820160405280156139a2576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846139ac57509392505050565b80825d5050565b6139ee8383614073565b61121e335f858585613827565b8080613a0f57506001600160a01b03821615155b15613ad0575f613a1e84612f0f565b90506001600160a01b03831615801590613a4a5750826001600160a01b0316816001600160a01b031614155b8015613a5d5750613a5b8184612542565b155b15613a865760405163a9fbf51f60e01b81526001600160a01b0384166004820152602401610ba3565b8115613ace5783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260046020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b61121e838383604051602401613b1793929190614e80565b60408051601f198184030181529190526020810180516001600160e01b031663038fd88960e31b1790525b6118b5816140d4565b61221d8484846140f3565b6116bd84848484604051602401613b709493929190614eb2565b60408051601f198184030181529190526020810180516001600160e01b03166363fb8bc560e01b179052613b42565b6118b581604051602401613bb391906144ac565b60408051601f198184030181529190526020810180516001600160e01b031663104c13eb60e21b179052613b42565b5f828152600260205260408120546001600160a01b0390811690831615613c0e57613c0e8184866141a0565b6001600160a01b03811615613c4857613c295f855f5f6139fb565b6001600160a01b0381165f90815260036020526040902080545f190190555b6001600160a01b03851615613c76576001600160a01b0385165f908152600360205260409020805460010190555b5f8481526002602052604080822080546001600160a01b0319166001600160a01b0389811691821790925591518793918516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4949350505050565b5f5b8251518110156116bd57825180515f919083908110613cf757613cf7614b95565b60200260200101516001600160a01b031614613d73575f516020614f5c5f395f51905f528433855f01518481518110613d3257613d32614b95565b602002602001015186602001518581518110613d5057613d50614b95565b602002602001015186604051613d6a959493929190614dce565b60405180910390a15b600101613cd6565b5f8490505f816001600160a01b03168585604051602001613d9c91906144ac565b60408051601f1981840301815290829052613db6916142d2565b5f6040518083038185875af1925050503d805f8114613df0576040519150601f19603f3d011682016040523d82523d5f602084013e613df5565b606091505b5050905080158015613e045750825b15613e2657868460405163bb38095f60e01b8152600401610ba3929190614e11565b50505050505050565b6007546040516001600160a01b03909116905f908290859061370a9086906020016144ac565b5f5b8251518110156116bd57825180515f919083908110613e7857613e78614b95565b60200260200101516001600160a01b031614613f4d57613f076040518060400160405280601981526020017f6672616374696f6e616c5061796f757420257320746f2025730000000000000081525084602001518381518110613edd57613edd614b95565b6020026020010151855f01518481518110613efa57613efa614b95565b6020026020010151613aff565b613f4d84845f01518381518110613f2057613f20614b95565b602002602001015185602001518481518110613f3e57613f3e614b95565b6020026020010151855f613d7b565b600101613e57565b61121e838383604051602401613f6d93929190614eed565b60408051601f198184030181529190526020810180516001600160e01b0316635970e08960e01b179052613b42565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310613fda5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310614006576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061402457662386f26fc10000830492506010015b6305f5e100831061403c576305f5e100830492506008015b612710831061405057612710830492506004015b60648310614062576064830492506002015b600a8310610f285760010192915050565b6001600160a01b03821661409c57604051633250574960e11b81525f6004820152602401610ba3565b5f6140a883835f613132565b90506001600160a01b0381161561121e576040516339e3563760e11b81525f6004820152602401610ba3565b5f6a636f6e736f6c652e6c6f6790505f5f835160208501845afa505050565b6001600160a01b03821661411c57604051633250574960e11b81525f6004820152602401610ba3565b5f61412883835f613132565b90506001600160a01b03811661415457604051637e27328960e01b815260048101839052602401610ba3565b836001600160a01b0316816001600160a01b0316146116bd576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610ba3565b6141ab838383614204565b61121e576001600160a01b0383166141d957604051637e27328960e01b815260048101829052602401610ba3565b60405163177e802f60e01b81526001600160a01b038316600482015260248101829052604401610ba3565b5f6001600160a01b038316158015906119575750826001600160a01b0316846001600160a01b0316148061423d575061423d8484612542565b806119575750505f908152600460205260409020546001600160a01b03908116911614919050565b5080545f8255600202905f5260205f20908101906118b591905b808211156142a35780546001600160a01b03191681555f600182015560020161427f565b5090565b634e487b7160e01b5f52604160045260245ffd5b5f81518060208401855e5f93019283525090919050565b5f6122c882846142bb565b80356001600160401b0381168114611e82575f5ffd5b80356001600160a01b031981168114611e82575f5ffd5b803560ff81168114611e82575f5ffd5b803560ff1981168114611e82575f5ffd5b5f5f83601f84011261433b575f5ffd5b5081356001600160401b03811115614351575f5ffd5b6020830191508360208260061b850101111561436b575f5ffd5b9250929050565b5f5f5f5f5f5f5f5f5f5f5f5f6101608d8f03121561438e575f5ffd5b8c359b5061439e60208e016142dd565b9a5060408d0135995060608d013568ffffffffffffffffff19811681146143c3575f5ffd5b98506143d160808e016142f3565b975060a08d0135965060c08d013595506143ed60e08e0161430a565b94506143fc6101008e0161430a565b935061440b6101208e0161431a565b92506001600160401b036101408e01351115614425575f5ffd5b6144368e6101408f01358f0161432b565b81935080925050509295989b509295989b509295989b565b6001600160e01b0319811681146118b5575f5ffd5b5f60208284031215614473575f5ffd5b81356122c88161444e565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f6122c8602083018461447e565b5f602082840312156144ce575f5ffd5b5035919050565b6001600160a01b03811681146118b5575f5ffd5b5f5f604083850312156144fa575f5ffd5b8235614505816144d5565b946020939093013593505050565b5f5f5f60608486031215614525575f5ffd5b8335614530816144d5565b92506020840135915060408401356001600160801b031981168114614553575f5ffd5b809150509250925092565b5f5f5f60608486031215614570575f5ffd5b833592506145806020850161430a565b915061458e6040850161431a565b90509250925092565b5f5f5f606084860312156145a9575f5ffd5b83356145b4816144d5565b925060208401356145c4816144d5565b929592945050506040919091013590565b5f5f604083850312156145e6575f5ffd5b823591506145f6602084016142dd565b90509250929050565b5f6020828403121561460f575f5ffd5b81356122c8816144d5565b602080825282518282018190525f918401906040840190835b8181101561465a5783516001600160a01b0316835260209384019390920191600101614633565b509095945050505050565b80358015158114611e82575f5ffd5b5f5f60408385031215614685575f5ffd5b8235614690816144d5565b91506145f660208401614665565b602080825282518282018190525f918401906040840190835b8181101561465a57835180516001600160a01b0316845260209081015181850152909301926040909201916001016146b7565b604051606081016001600160401b038111828210171561470c5761470c6142a7565b60405290565b604051601f8201601f191681016001600160401b038111828210171561473a5761473a6142a7565b604052919050565b5f5f5f5f60808587031215614755575f5ffd5b8435614760816144d5565b93506020850135614770816144d5565b92506040850135915060608501356001600160401b03811115614791575f5ffd5b8501601f810187136147a1575f5ffd5b80356001600160401b038111156147ba576147ba6142a7565b6147cd601f8201601f1916602001614712565b8181528860208385010111156147e1575f5ffd5b816020840160208301375f6020838301015280935050505092959194509250565b5f610100820190506001600160401b03835116825268ffffffffffffffffff19602084015116602083015260ff6040840151166040830152606083015160608301526080830151608083015260a083015160a083015260c083015161487260c08401826001600160a01b03169052565b5060e08301516130ca60e08401826001600160a01b0319169052565b5f8151808452602084019350602083015f5b828110156148be5781518652602095860195909101906001016148a0565b5093949350505050565b602081525f6122c8602083018461488e565b5f5f604083850312156148eb575f5ffd5b823591506145f660208401614665565b5f5f6040838503121561490c575f5ffd5b8235614917816144d5565b91506020830135614927816144d5565b809150509250929050565b5f5f60408385031215614943575f5ffd5b50508035926020909101359150565b602080825282516060838301528051608084018190525f929190910190829060a08501905b808310156149a25783516001600160a01b031682526020938401936001939093019290910190614977565b506020860151858203601f1901604087015292506149c0818461488e565b92505050604084015160608401528091505092915050565b908152604060208201819052600690820152655b737431355d60d01b606082015260800190565b908152604060208201819052600590820152645b6531315d60d81b606082015260800190565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610f2857610f28614a25565b5f6040828403128015614a5d575f5ffd5b50604080519081016001600160401b0381118282101715614a8057614a806142a7565b6040528235614a8e816144d5565b81526020928301359281019290925250919050565b600181811c90821680614ab757607f821691505b602082108103614ad557634e487b7160e01b5f52602260045260245ffd5b50919050565b908152604060208201819052600590820152645b6533325d60d81b606082015260800190565b908152604060208201819052600590820152645b6533305d60d81b606082015260800190565b908152604060208201819052600590820152645b7374355d60d81b606082015260800190565b6001600160401b0381811683821602908116908181146130ca576130ca614a25565b908152604060208201819052600590820152645b7374315d60d81b606082015260800190565b634e487b7160e01b5f52603260045260245ffd5b5f60018201614bba57614bba614a25565b5060010190565b5f611957614bcf83866142bb565b846142bb565b8082028115828204841417610f2857610f28614a25565b5f82614c0657634e487b7160e01b5f52601260045260245ffd5b500490565b81810381811115610f2857610f28614a25565b606081525f614c30606083018661447e565b60208301949094525060400152919050565b5f6001600160401b03821115614c5a57614c5a6142a7565b5060051b60200190565b5f82601f830112614c73575f5ffd5b8151614c86614c8182614c42565b614712565b8082825260208201915060208360051b860101925085831115614ca7575f5ffd5b602085015b83811015614cc4578051835260209283019201614cac565b5095945050505050565b5f60208284031215614cde575f5ffd5b81516001600160401b03811115614cf3575f5ffd5b820160608185031215614d04575f5ffd5b614d0c6146ea565b81516001600160401b03811115614d21575f5ffd5b8201601f81018613614d31575f5ffd5b8051614d3f614c8182614c42565b8082825260208201915060208360051b850101925088831115614d60575f5ffd5b6020840193505b82841015614d8b578351614d7a816144d5565b825260209384019390910190614d67565b845250505060208201516001600160401b03811115614da8575f5ffd5b614db486828501614c64565b602083015250604091820151918101919091529392505050565b8581526001600160a01b038581166020830152841660408201526060810183905260a0608082018190525f90614e069083018461447e565b979650505050505050565b828152604060208201525f611957604083018461447e565b6001600160a01b03858116825284166020820152604081018390526080606082018190525f90614e5b9083018461447e565b9695505050505050565b5f60208284031215614e75575f5ffd5b81516122c88161444e565b606081525f614e92606083018661447e565b6020830194909452506001600160a01b0391909116604090910152919050565b608081525f614ec4608083018761447e565b6001600160a01b0395861660208401526040830194909452509216606090920191909152919050565b606081525f614eff606083018661447e565b8460208401528281036040840152614e5b818561447e56fe64656c65746520746f6b656e20257320666f7220746f6b656e4f776e657220257367657450757263686173654665652070657263656e7461676520257320666565202573c93281d54262e2eb67b2f4c5b73046905b892013531bc8d947dfe012386546552d2d2d2d2d2d2d3e50555243484153452c206d73672e76616c75652025732070726963652025737075726368617365546f6b656e2072657175697265645061796d656e74202573206d73672e76616c7565202573a264697066735822122078f985e92ac892851adba1bad60ac265b1fb71d8e30515efc62a5bf20b1cecd964736f6c634300081c0033
Verified Source Code Full Match
Compiler: v0.8.28+commit.7893614a
EVM: cancun
Optimization: Yes (200 runs)
draft-IERC6093.sol 161 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC6093.sol)
pragma solidity >=0.8.4;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
ERC721.sol 430 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "./IERC721.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {ERC721Utils} from "./utils/ERC721Utils.sol";
import {Context} from "../../utils/Context.sol";
import {Strings} from "../../utils/Strings.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {IERC721Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC-721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
mapping(uint256 tokenId => address) private _owners;
mapping(address owner => uint256) private _balances;
mapping(uint256 tokenId => address) private _tokenApprovals;
mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/// @inheritdoc IERC721
function balanceOf(address owner) public view virtual returns (uint256) {
if (owner == address(0)) {
revert ERC721InvalidOwner(address(0));
}
return _balances[owner];
}
/// @inheritdoc IERC721
function ownerOf(uint256 tokenId) public view virtual returns (address) {
return _requireOwned(tokenId);
}
/// @inheritdoc IERC721Metadata
function name() public view virtual returns (string memory) {
return _name;
}
/// @inheritdoc IERC721Metadata
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/// @inheritdoc IERC721Metadata
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/// @inheritdoc IERC721
function approve(address to, uint256 tokenId) public virtual {
_approve(to, tokenId, _msgSender());
}
/// @inheritdoc IERC721
function getApproved(uint256 tokenId) public view virtual returns (address) {
_requireOwned(tokenId);
return _getApproved(tokenId);
}
/// @inheritdoc IERC721
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/// @inheritdoc IERC721
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
return _operatorApprovals[owner][operator];
}
/// @inheritdoc IERC721
function transferFrom(address from, address to, uint256 tokenId) public virtual {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
// Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
address previousOwner = _update(to, tokenId, _msgSender());
if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/// @inheritdoc IERC721
function safeTransferFrom(address from, address to, uint256 tokenId) public {
safeTransferFrom(from, to, tokenId, "");
}
/// @inheritdoc IERC721
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
transferFrom(from, to, tokenId);
ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*
* IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
* core ERC-721 logic MUST be matched with the use of {_increaseBalance} to keep balances
* consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
* `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
*/
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
return _tokenApprovals[tokenId];
}
/**
* @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
* particular (ignoring whether it is owned by `owner`).
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
return
spender != address(0) &&
(owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
}
/**
* @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
* Reverts if:
* - `spender` does not have approval from `owner` for `tokenId`.
* - `spender` does not have approval to manage all of `owner`'s assets.
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else {
revert ERC721InsufficientApproval(spender, tokenId);
}
}
}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
* a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
*
* WARNING: Increasing an account's balance using this function tends to be paired with an override of the
* {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
* remain consistent with one another.
*/
function _increaseBalance(address account, uint128 value) internal virtual {
unchecked {
_balances[account] += value;
}
}
/**
* @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
*
* Emits a {Transfer} event.
*
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
address from = _ownerOf(tokenId);
// Perform (optional) operator check
if (auth != address(0)) {
_checkAuthorized(from, auth, tokenId);
}
// Execute the update
if (from != address(0)) {
// Clear approval. No need to re-authorize or emit the Approval event
_approve(address(0), tokenId, address(0), false);
unchecked {
_balances[from] -= 1;
}
}
if (to != address(0)) {
unchecked {
_balances[to] += 1;
}
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
return from;
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner != address(0)) {
revert ERC721InvalidSender(address(0));
}
}
/**
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
ERC721Utils.checkOnERC721Received(_msgSender(), address(0), to, tokenId, data);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal {
address previousOwner = _update(address(0), tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
* are aware of the ERC-721 standard to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is like {safeTransferFrom} in the sense that it invokes
* {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `tokenId` token must exist and be owned by `from`.
* - `to` cannot be the zero address.
* - `from` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId) internal {
_safeTransfer(from, to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
* either the owner of the token, or approved to operate on all tokens held by this owner.
*
* Emits an {Approval} event.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address to, uint256 tokenId, address auth) internal {
_approve(to, tokenId, auth, true);
}
/**
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
* emitted in the context of transfers.
*/
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
// Avoid reading the owner unless necessary
if (emitEvent || auth != address(0)) {
address owner = _requireOwned(tokenId);
// We do not use _isAuthorized because single-token approvals should not be able to call approve
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
revert ERC721InvalidApprover(auth);
}
if (emitEvent) {
emit Approval(owner, to, tokenId);
}
}
_tokenApprovals[tokenId] = to;
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Requirements:
* - operator can't be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC721InvalidOperator(operator);
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
* Returns the owner.
*
* Overrides to ownership logic should be done to {_ownerOf}.
*/
function _requireOwned(uint256 tokenId) internal view returns (address) {
address owner = _ownerOf(tokenId);
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
return owner;
}
}
IERC721.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721.sol)
pragma solidity >=0.6.2;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC-721 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 have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev 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 address zero.
*
* 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);
}
IERC721Receiver.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity >=0.5.0;
/**
* @title ERC-721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC-721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity >=0.6.2;
import {IERC721} from "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
ERC721Utils.sol 50 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/utils/ERC721Utils.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
import {IERC721Errors} from "../../../interfaces/draft-IERC6093.sol";
/**
* @dev Library that provide common ERC-721 utility functions.
*
* See https://eips.ethereum.org/EIPS/eip-721[ERC-721].
*
* _Available since v5.1._
*/
library ERC721Utils {
/**
* @dev Performs an acceptance check for the provided `operator` by calling {IERC721Receiver-onERC721Received}
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).
*
* The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA).
* Otherwise, the recipient must implement {IERC721Receiver-onERC721Received} and return the acceptance magic value to accept
* the transfer.
*/
function checkOnERC721Received(
address operator,
address from,
address to,
uint256 tokenId,
bytes memory data
) internal {
if (to.code.length > 0) {
try IERC721Receiver(to).onERC721Received(operator, from, tokenId, data) returns (bytes4 retval) {
if (retval != IERC721Receiver.onERC721Received.selector) {
// Token rejected
revert IERC721Errors.ERC721InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-IERC721Receiver implementer
revert IERC721Errors.ERC721InvalidReceiver(to);
} else {
assembly ("memory-safe") {
revert(add(reason, 0x20), mload(reason))
}
}
}
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Panic.sol 57 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}
ReentrancyGuardTransient.sol 61 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/ReentrancyGuardTransient.sol)
pragma solidity ^0.8.24;
import {TransientSlot} from "./TransientSlot.sol";
/**
* @dev Variant of {ReentrancyGuard} that uses transient storage.
*
* NOTE: This variant only works on networks where EIP-1153 is available.
*
* _Available since v5.1._
*/
abstract contract ReentrancyGuardTransient {
using TransientSlot for *;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, REENTRANCY_GUARD_STORAGE.asBoolean().tload() will be false
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true);
}
function _nonReentrantAfter() private {
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false);
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return REENTRANCY_GUARD_STORAGE.asBoolean().tload();
}
}
Strings.sol 490 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
uint256 private constant SPECIAL_CHARS_LOOKUP =
(1 << 0x08) | // backspace
(1 << 0x09) | // tab
(1 << 0x0a) | // newline
(1 << 0x0c) | // form feed
(1 << 0x0d) | // carriage return
(1 << 0x22) | // double quote
(1 << 0x5c); // backslash
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @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;
assembly ("memory-safe") {
ptr := add(add(buffer, 0x20), length)
}
while (true) {
ptr--;
assembly ("memory-safe") {
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 Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @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));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress-string} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress-string-uint256-uint256} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
*
* WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
*
* NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
* RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
* characters that are not in this range, but other tooling may provide different results.
*/
function escapeJSON(string memory input) internal pure returns (string memory) {
bytes memory buffer = bytes(input);
bytes memory output = new bytes(2 * buffer.length); // worst case scenario
uint256 outputLength = 0;
for (uint256 i; i < buffer.length; ++i) {
bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));
if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {
output[outputLength++] = "\\";
if (char == 0x08) output[outputLength++] = "b";
else if (char == 0x09) output[outputLength++] = "t";
else if (char == 0x0a) output[outputLength++] = "n";
else if (char == 0x0c) output[outputLength++] = "f";
else if (char == 0x0d) output[outputLength++] = "r";
else if (char == 0x5c) output[outputLength++] = "\\";
else if (char == 0x22) {
// solhint-disable-next-line quotes
output[outputLength++] = '"';
}
} else {
output[outputLength++] = char;
}
}
// write the actual length and deallocate unused memory
assembly ("memory-safe") {
mstore(output, outputLength)
mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))
}
return string(output);
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(add(buffer, 0x20), offset))
}
}
}
TransientSlot.sol 183 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/TransientSlot.sol)
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
pragma solidity ^0.8.24;
/**
* @dev Library for reading and writing value-types to specific transient storage slots.
*
* Transient slots are often used to store temporary values that are removed after the current transaction.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* * Example reading and writing values using transient storage:
* ```solidity
* contract Lock {
* using TransientSlot for *;
*
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier locked() {
* require(!_LOCK_SLOT.asBoolean().tload());
*
* _LOCK_SLOT.asBoolean().tstore(true);
* _;
* _LOCK_SLOT.asBoolean().tstore(false);
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library TransientSlot {
/**
* @dev UDVT that represents a slot holding an address.
*/
type AddressSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a AddressSlot.
*/
function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
return AddressSlot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a bool.
*/
type BooleanSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a BooleanSlot.
*/
function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
return BooleanSlot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a bytes32.
*/
type Bytes32Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Bytes32Slot.
*/
function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
return Bytes32Slot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a uint256.
*/
type Uint256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Uint256Slot.
*/
function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
return Uint256Slot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a int256.
*/
type Int256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Int256Slot.
*/
function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
return Int256Slot.wrap(slot);
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(AddressSlot slot) internal view returns (address value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(AddressSlot slot, address value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(BooleanSlot slot) internal view returns (bool value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(BooleanSlot slot, bool value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Bytes32Slot slot, bytes32 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Uint256Slot slot) internal view returns (uint256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Uint256Slot slot, uint256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Int256Slot slot) internal view returns (int256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Int256Slot slot, int256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
}
ERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Math.sol 749 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(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.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* 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 {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 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 low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, 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 ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
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⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// 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²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev 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) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @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 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @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;
}
}
SafeCast.sol 1162 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}
SignedMath.sol 68 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(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 {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}
Errors.sol 12 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/** All reverts should throw this error. By convention
the message is a 2-letter
prefix followed by 1 or more digits; e.g. [st20]
revert HarmonizeError(tokenId,"[st20]");
@param tokenId Relevant tokenId. May be 0 for errors not specific to a token
@param error String as described
*/
error HarmonizeError(uint256 tokenId, string error);
Harmonize.sol 1606 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {console} from "hardhat/console.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
import "./Errors.sol";
/**
The tokenId for this Harmonize contract is a UUID generated by the minter at mint time
and passed to the mint function.
The OpenZeppelin implementation implements the basic ERC721 as well as IERC721Metadata.
*Note* This contract must *never hold funds. Funds received must all be sent to the payee.
Version
======
The contract version corresponds to the version used throughout Harmonize. It is updated
to match the Harmonize version at the time the contract is deployed. The contract version
is a public uint256 VERSION of the form [MMmmrl] where:
- MM is the major version. Anything less than 10 this is a single digit
- mm is the minor version.
- rl is the release number.
So e.g. 29923 is version 2.99.23.
Contract Accounts
====
There are 4 special accounts.
- Contract owner. Set in constructor. Operations by the contract owner must always
be performed by human using a connected wallet. This can be changed if the current
contractOwner calls transferOwnership.
- Payee. Set in constructor and may be changed by contract owner. Recipient of funds from
contract operations.
- Content manager. Set in constructor and may be changed by contract owner. This account can
manipulate the MediaSafe
- Service account. Set in constructor and may be changed by contract owner. This is the
backend service account. Since those automated services rely on providing the account private key,
the risk of contract damage must be ameliorated by a) limiting operation scope b) allowing
the contract owner to change the service account at any time.
Valid Accounts for Minting
=====
Only accounts that are registered in:
validAccounts
are allowed to call the mint function. This is to prevent use of the contract
outside of Harmonize. This is a mapping of the account address to the AES256
encrypted base64 encoded 24 byte hex MongoDB ObjectID of the associated Harmonize
account. The length of that string is 44 bytes.
Options for Entire Contract
================
The contract supports various fees and limits through the use of a single
uint256 variable <b>options</b>. Note that 'Szabo' and 'microether' mean the
same though we attempt to use the standard 'Szabo'.
Only the contract owner (currently the creator) can set the options field. It
controls the following:
- Bit 0 is the paused flag. Contract is paused if this is set
- Bit 1 was the allow creator royalty flag. No longer used but reserved.
- Next 10 bits: Note Contract version number, starting at 1. Max 1023.
- Next 10 bits: 3 digit purchaseFee percentage 1 implied decimal place; e.g. 15=1.5.
This is applied to any method that calls _update as a result of a purchase.
The purchaseFee is paid to the payee. Defaults to 0, no purchaseFee.
- Next 32 bits: single mint fee in Note Szabo. This is applied to any mint call.
The mintFee is paid to the payee. Defaults to 0, no mintFee.
Note that the maximum is 4,294,967,295, multiplied by 10**12 for over 429 ether.
- Next 32 bits: transaction fee in Note Szabo. The transaction fee is applied to
operations other than mint and purchase, including transferToken, setPrice
and requestMediaSafe.
The transactionFee is paid to the payee. Defaults to 0, no transactionFee.
- Next 32 bits: mediaSafeFee in Note Szabo.
If non-0, this is the fee charged to manage content for the token.
There must be a configured Content Manager.
The mediaSafeFee is paid to the payee. Defaults to 0,
no mediaSafeFee.
- Next 10 bits: Maximum number of partners allowed with mint. Max 1023. Defaults to 0, no partners
- Total 128 bits 128 bits: UNUSED
Allowed Contracts
==========
The <b>allowedContracts</b> array lists all addresses that are allowed to call
functions modified by onlyAllowedContracts. The purpose is to support a limited
list of external contracts -- for example, Auction. The addresses are not
guaranteed to be contracts.
TokenParameters for Each Token
===========================
This struct has:
- The token price in gwei. 64 bits with a maximum value of 18,446,744,073,709,551,615.
May be 0
- mediaId. 184 bits (bytes23). Optional ID string, e.g. ISRC
- streamingRights. 8 bits. Currently only bit 0 is defined:
- 0 denies, 1 grants.
- mediaHash. 256 bits. The required SHA256 hash of the media associated with this NFT.
- titleHi. 32 bytes. First part of title
- titleLo. 32 bytes. Second part of the title
- minter. address (160 bits). The minter is the token creator. This doesn't change
even if the owner changes.
- mediaIdExt. 96 bits (bytes12). Optional second part of mediaId to not waste space
Price
The token sale price in gwei (shannon) 1e9 wei. A price of 0 means the NFT
is not for sale. This is enforced in the purchaseToken function.
Price is constrained to a maximum of 1 million ETH, meaning max gwei val for this field is
1,000,000,000,000,000 (0x38D7EA4C68000).
Owned Tokens
===
To avoid Erc721Enumerable, we track all owned tokens
in the ownedTokens mapping. It doesn't let us get a token by id, but it does
let us get them by owner address.
- tokenOwner=>tokenIds[]. Every token owned by tokenOwner
Token Locks
===
A token may be locked by the contractOwner. The main purpose is to prevent
purchase, transfer, or deletion during an event like an Auction.
- tokenId=>bool. Only add an entry if the token is locked.
Partner
=======
A Partner is an ETH account that receives a percentage of the sale price of this NFT. Partners
are specified at mint time and cannot be changed once the NFT is minted.
Partner struct is:
- partnerAddress: address that must not be 0, a contract, or msg.sender.
The account must have a non-0 balance at mint time.
- partnerPercentage: 3 digit percentage 1 implied decimal place max value 999 10 bits.
nftPartners is an array of Partner mapped to a tokenId.
Note that a Partner
is different than a Shareholder: a Partner does not pay anything, where as shareholders must
purchase their interest as part of an Issue offering. Additionally, a Shareholder can sell shares
but a Partner cannot. Note that Shareholders are *not* supported in this contract,
because of concerns related to classification of NFT as a security.
For the relevant code see HarmonizeWithStreamingRoyalty contract.
MediaSafe
============
MediaSafe associates an offline store of the content (e.g. media)
with this token. For MediaSafe to occur:
- The <b>contentManager</b> must be set by the contract owner. It is set in
the constructor to the contract owner.
- The <b>MediaSafe</b> for a specific token must set in mint or added
laer by the token owner.
The MediaSafe struct is defined by the AES-256 encrypted token owner address.
Used to confirm token has associated content manager with Harmonize content manager.
The Content Manager decrypts this and compares it to the token's current account owner.
If they match, the Content Manager will serve storage for this NFT.
The base64 encoded AES-256 encryption of the 42 byte eth address is 64 bytes long.
- fingerprintHi. 32 bytes.
- fingerprintLo. 32 bytes
- storageExpiration. 256 bits. The timestamp at which the storage expires. This
has no effect on this contract but should be used by the Content Manager
to prevent storage retrieval after the expiration date.
<b>tokenMediaSafe</b> maps a tokenId to its MediaSafe, if any.
Private Getters
===
The following private variables have external getters, with access restrictions as noted:
- allowedContracts: getAllowedContracts onlyContractOwner
- validAccounts: getValidAccount onlyContractOwner
- ownedTokens: getOwnedTokens
- lockedTokens: getTokenLock onlyContractOwner
- nftPartners: getPartners
- tokenParameters: getTokenParameters
- storageExpirationOffset: getStorageExpirationOffset onlyContractOwner
- tokenMediaSafe: getMediaSafe onlyContentManagerOrContractOwner
@dev Version 1
*/
contract Harmonize is ERC721, ReentrancyGuardTransient {
uint256 public constant VERSION = 29925;
address private contractOwner;
address private payee;
address private contentManager;
address private serviceAccount;
uint256 private options; //Initializing this costs 20k gas at deploy. Save it for the setOptions call.
uint256 constant MAX_PRICE_GWEI = 1e12 gwei; //1 million ether
uint256 constant OPTIONS_PAUSED_MASK = 1; //Bit 0
uint256 constant OPTIONS_VERSION_SHIFT = 2; //10 bit version
uint256 constant OPTIONS_PURCHASE_FEE_SHIFT = OPTIONS_VERSION_SHIFT + 10;
uint256 constant OPTIONS_PURCHASE_FEE_MASK = 0x3FF;
uint256 constant OPTIONS_MINT_FEE_SHIFT = OPTIONS_PURCHASE_FEE_SHIFT + 10;
uint256 constant OPTIONS_MINT_FEE_MASK = 0xFFFFFFFF;
uint256 constant OPTIONS_TRANSACTION_FEE_SHIFT =
OPTIONS_MINT_FEE_SHIFT + 32;
uint256 constant OPTIONS_TRANSACTION_FEE_MASK = 0xFFFFFFFF;
uint256 constant OPTIONS_MEDIA_SAFE_FEE_SHIFT =
OPTIONS_TRANSACTION_FEE_SHIFT + 32;
uint256 constant OPTIONS_MEDIA_SAFE_FEE_MASK = 0xFFFFFFFF;
uint256 constant OPTIONS_MAX_PARTNERS_SHIFT =
OPTIONS_MEDIA_SAFE_FEE_SHIFT + 32;
uint256 constant OPTIONS_MAX_PARTNERS_MASK = 0xfffff;
uint256 constant MAX_ALLOWED_CONTRACTS = 8;
/** Contract addresses allowed to call restricted functions */
address[] private allowedContracts;
function getAllowedContracts()
external
view
onlyContractOwner
returns (address[] memory)
{
return allowedContracts;
}
/** AES256 encrypted 24 byte MongoDb ObjectId string is 48 bytes long */
struct HarmonizeAccount {
bytes32 accountHi;
bytes16 accountLo;
}
/** The ETH addresses allowed to mint tokens. Since the mapped value cannot
be null, store the HarmonizeAccount */
mapping(address => HarmonizeAccount) private validAccounts;
function getValidAccount(
address account
) external view onlyContractOwner returns (HarmonizeAccount memory) {
return validAccounts[account];
}
/** tokenOwner=>tokenIds[]. Every token owned by tokenOwner */
mapping(address => uint256[]) private ownedTokens;
/** tokenId=>locked. Only add an entry if the token is locked. */
mapping(uint256 => bool) private lockedTokens;
function getTokenLock(
uint256 tokenId
) external view onlyContractOwner returns (bool) {
return lockedTokens[tokenId];
}
struct Partner {
address partnerAddress;
uint256 partnerPercentage;
}
/** tokenId=>Partner[] */
mapping(uint256 => Partner[]) private nftPartners;
/** When mint is called, it encapsulates function parameters in this
struct. The struct is then mapped by the tokenId */
struct TokenParameters {
/* The price of the token. May be 0 */
uint64 price;
/* First part of an optional id, e.g. ISRC */
bytes23 mediaIdHi; //248
uint8 streamingRights; //256
/* The hash of the media content. Must not be 0 */
uint256 mediaHash; //256
/* First part of title */
bytes32 titleHi; //256
/* Second part of title */
bytes32 titleLo; //256
/* The minter is the token creator. This doesn't change even if the owner changes */
address minter; //160
/* Second part of mediaId */
bytes12 mediaIdLo; //256
}
/** tokenId=>TokenParameters. The TokenParameters for each token */
mapping(uint256 => TokenParameters) private tokenParameters;
/** This struct is defined for any token that has MediaSafe.
- contentLicense is the 1-based index into LICENSE_CODES
- licenseExt is 31 bytes of user-defined license info; e.g. (c) 2025 CJ Villa
- storageExpiration is a second-accurate timestamp that specifies
when this MediaSafe is no longer valid.
*/
struct MediaSafe {
uint8 contentLicense;
bytes31 licenseExt;
uint256 storageExpiration;
}
/** When MediaSafe rights are specified, its license is a uint8
index into this array. Each of the first 6 designations is one
of the 6 Creative Commons licenses specified in version 4.0.
The additional two designations are:
- "PRIVATE-NC" means private non-commercial use only.
https://creativecommons.org/share-your-work/cclicenses/
*/
bytes16[] public LICENSE_CODES = [
bytes16("CC BY 4.0"),
bytes16("CC BY-SA 4.0"),
bytes16("CC BY-ND 4.0"),
bytes16("CC BY-NC 4.0"),
bytes16("CC BY-NC-SA 4.0"),
bytes16("CC BY-NC-ND 4.0"),
bytes16("CC0"),
bytes16("PUBLIC DOMAIN"),
bytes16("PRIVATE-NC")
];
/** The amount of time in seconds added to the current block timestamp defines the
storageExpiration when creating a MediaSafe. This initial
time is 365 days in seconds */
uint256 private storageExpirationOffset = 31536000;
function getStorageExpirationOffset()
external
view
onlyContractOwner
returns (uint256)
{
return storageExpirationOffset;
}
/** tokenId=>MediaSafe. The MediaSafe, if any, for each token */
mapping(uint256 => MediaSafe) private tokenMediaSafe;
/**
Constructor
====
Builds an ERC721 contract instance with a name of "Harmonize" and a
symbol of HARMONIZE. The msg.sender is assigned to the contractOwner,
contentManager, serviceAccount and payee. All addresses can be changed
by the contractOwner.
*/
constructor() ERC721("Harmonize", "HARMONIZE") {
contractOwner = contentManager = serviceAccount = payee = msg.sender;
}
/**Emitted only by receive function. We are never expecting
receive to be called, so we need to track these.
*/
event ReceivedFunds(address sender, uint256 value);
/**Send any money received by the contract back to the payee.
We *never* want funds held in this contract.
Emits ReceivedFunds
*/
receive() external payable {
emit ReceivedFunds(msg.sender, msg.value);
(bool s, ) = payable(payee).call{value: msg.value}(new bytes(0));
require(s);
}
function supportsInterface(
bytes4 interfaceId
) public view override(ERC721) returns (bool) {
return super.supportsInterface(interfaceId);
}
/**Get the tokens for the specified owner.
Note that the returned array may have empty elements because a delete does not
reorder the array.
@param tokenOwner Address of owner for tokens
*/
function getOwnedTokens(
address tokenOwner
) external view returns (uint256[] memory) {
return ownedTokens[tokenOwner];
}
/**
@param tokenId Id of token for the price
@return The price in Gwei
*/
function getPrice(uint256 tokenId) external view returns (uint256) {
return tokenParameters[tokenId].price;
}
/**Get the TokenParameters struct that was defined when
the token was minted
@param tokenId Id of token
*/
function getTokenParameters(
uint256 tokenId
) external view returns (TokenParameters memory) {
return tokenParameters[tokenId];
}
/** Get the MediaSafe assigned to the token.
@param tokenId Id of token for the storage
*/
function getMediaSafe(
uint256 tokenId
) external view returns (MediaSafe memory) {
return tokenMediaSafe[tokenId];
}
/** Get the array of Partner for the specified token.
@param tokenId Id of token
*/
function getPartners(
uint256 tokenId
) external view returns (Partner[] memory) {
return nftPartners[tokenId];
}
/** Event emitted
@param owner Token owner address
@param tokenId Token id
@param price Token price in wei
*/
event SetPrice(address owner, uint256 tokenId, uint256 price);
/**
Note No longer supported because immediately after a Mint all kinds of services
start calling this endpoint (and are blocked by CORS): meaning that lots
of event listeners are trying to scoop up this token.
To support the tokenURI function. The latter will now return:
"https://nft.harmonize.social/nft/[tokenId]"
Therefore the above endpoint must return a IERC721Metadata response.
* @dev See {IERC721Metadata-tokenURI}.
function _baseURI() internal view virtual override returns (string memory) {
return "https://nft.harmonize.social/nft/";
}
*/
/** This costs about 400 gas more than inline checks in each function */
modifier onlyContractOwner() {
if (msg.sender != contractOwner) {
revert HarmonizeError(0, "[st1]");
}
_;
}
/** Reverts with [st3] is msg.sender is neither contractOwner nor contentManager.
*/
modifier onlyContractOwnerOrContentManager(uint256 tokenId) {
if (msg.sender != contractOwner && msg.sender != contentManager) {
revert HarmonizeError(tokenId, "[st3]");
}
_;
}
/** Reverts with [st5] is msg.sender is neither contractOwner nor serviceAccount.
*/
modifier onlyContractOwnerOrServiceAccount() {
if (msg.sender != contractOwner && msg.sender != serviceAccount) {
revert HarmonizeError(0, "[st5]");
}
_;
}
/**Test if msg.sender is in allowedContracts. Because there is
no reliable way to determine if any address is a contract,
this is just a plain address check with no inference that
msg.sender is a contract. But the purpose of this modifier
is to ensure that external contracts (e.g. Auction) are allowed
to operate on this contract.
This is not meant for functions called from this contract.
As such it marks functions as specifically meant to be external
proxies for internal functions and variables.
*/
modifier onlyAllowedContracts(uint256 tokenId) {
bool allowed = false;
for (uint256 i = 0; i < allowedContracts.length; i++) {
if (allowedContracts[i] == msg.sender) {
allowed = true;
break;
}
}
if (!allowed) {
revert HarmonizeError(tokenId, "[st0]");
}
_;
}
modifier onlyTokenOwner(uint256 tokenId) {
if (ownerOf(tokenId) != msg.sender) {
revert HarmonizeError(tokenId, "[e30]");
}
_;
}
/** Prevents access to locked tokens.
-Reverts with [e32] if the token is locked
@param tokenId Id of token to check
*/
modifier onlyUnlockedToken(uint256 tokenId) {
if (lockedTokens[tokenId]) {
revert HarmonizeError(tokenId, "[e32]");
}
_;
}
modifier isRunning() {
if (options & OPTIONS_PAUSED_MASK != 0) {
revert HarmonizeError(0, "[st15]");
}
_;
}
function getOwner() external view returns (address) {
return contractOwner;
}
function getPayee() external view onlyContractOwner returns (address) {
return payee;
}
function getServiceAccount()
external
view
onlyContractOwner
returns (address)
{
return serviceAccount;
}
function getContentManager()
external
view
onlyContractOwner
returns (address)
{
return contentManager;
}
/**Reverts with [st25] if the address is 0, this contract, or msg.sender
@param newOwner Address of new contractOwner
*/
function transferOwnership(
address newOwner
) external nonReentrant onlyContractOwner {
if (
newOwner == address(0) ||
newOwner == address(this) ||
newOwner == msg.sender
) {
revert HarmonizeError(0, "[st25]");
}
contractOwner = newOwner;
}
/** Support for allowed external contracts.
@param tokenId Id of token to find
@return address of token owner *in this contract*
*/
function extGetTokenOwner(
uint256 tokenId
) external view onlyAllowedContracts(tokenId) returns (address) {
return ownerOf(tokenId);
}
/** Delete the specified account from allowedContracts.
Nothing happens if the account is not found.
@param account Address to delete
*/
function deleteAllowedContract(
address account
) external nonReentrant onlyContractOwner {
if (
account == address(0) ||
account == address(this) ||
account == msg.sender
) {
revert HarmonizeError(0, "[st4]");
}
uint256 contractIx = 0;
bool found = false;
uint256 contractsLength = allowedContracts.length;
for (
contractIx = 0;
contractIx < contractsLength && contractIx < MAX_ALLOWED_CONTRACTS;
contractIx++
) {
if (allowedContracts[contractIx] == account) {
found = true;
break;
}
}
if (found) {
delete allowedContracts[contractIx];
}
}
/** Add an account to the list of allowedContracts.
- Reverts with [st2] if account is 0, this contract, or msg.sender.
@param account (Presumably) contract address
*/
function setAllowedContract(address account) external onlyContractOwner {
if (
account == address(0) ||
account == address(this) ||
account == msg.sender
) {
revert HarmonizeError(0, "[st2]");
}
allowedContracts.push(account);
}
/** Lock a token. This should be used carefully. The main purpose
is to prevent modification to a token ownership during, e.g., an Auction.
@param tokenId Id of token to lock or unlock
@param locked If true, add an entry in lockedTokens; otherwise delete it
*/
function setTokenLock(
uint256 tokenId,
bool locked
) external onlyContractOwnerOrServiceAccount {
if (locked) {
lockedTokens[tokenId] = locked;
} else {
delete lockedTokens[tokenId];
}
}
/** Sets the offset in seconds added to the current block timestamp
when creating MediaSafe for a token. If set to 0
this should disable creating MediaSafe.
@param offset In seconds. May be 0
*/
function setStorageExpirationOffset(
uint256 offset
) external onlyContractOwnerOrContentManager(0) {
storageExpirationOffset = offset;
}
/** Delete the specified account from validAccounts.
If the account does not exist, nothing happens.
@param account Address to delete
*/
function deleteValidAccount(
address account
) external nonReentrant onlyContractOwnerOrServiceAccount {
delete validAccounts[account];
}
/** Note Gas used 67000
Store the specified Ethereum account address so that
said account can call the mint function. Any existing
entry is overwritten.
Reverts with [st11] if the account address is 0, the sender, or this contract.
@param account Ethereum account.
@param harmonizeAccountHi First 32 bytes of encrypted Harmonize account id
@param harmonizeAccountLo Last 16 bytes
*/
function setValidAccount(
address account,
bytes32 harmonizeAccountHi,
bytes16 harmonizeAccountLo
) external nonReentrant onlyContractOwnerOrServiceAccount {
if (
account == address(0) ||
account == address(this) ||
account == msg.sender
) {
revert HarmonizeError(0, "[st11]");
}
validAccounts[account] = HarmonizeAccount({
accountHi: harmonizeAccountHi,
accountLo: harmonizeAccountLo
});
}
/**
Reverts with [st26] if the specified account is 0, this contract, or the msg.sender
@param payeeAccount Non-0 address of the Payee
*/
function setPayee(
address payeeAccount
) external nonReentrant onlyContractOwner {
if (
payeeAccount == address(0) ||
payeeAccount == address(this) ||
payeeAccount == msg.sender
) {
revert HarmonizeError(0, "[st26]");
}
payee = payeeAccount;
}
/**
Reverts with [st21] if the specified account is 0, this contract, or the msg.sender
@param stManager Non-0 address of the Content Manager
*/
function setContentManager(
address stManager
) external nonReentrant onlyContractOwner {
if (
stManager == address(0) ||
stManager == address(this) ||
stManager == msg.sender
) {
revert HarmonizeError(0, "[st21]");
}
contentManager = stManager;
}
/**
Reverts with [st22] if the specified account is 0, this contract, or the msg.sender
@param svcAccount Non-0 address of the Service Account
*/
function setServiceAccount(
address svcAccount
) external nonReentrant onlyContractOwner {
if (
svcAccount == address(0) ||
svcAccount == address(this) ||
svcAccount == msg.sender
) {
revert HarmonizeError(0, "[st22]");
}
serviceAccount = svcAccount;
}
/** Burn, but only by the contract owner, is supported as a last resort for bad tokens.
This will:
1) delete the tokenOwner from ownedTokens
2) delete any associated TokenParameters before the burn
and no payments will be made.
@param tokenOwner Address of token owner
@param tokenId ID of token to burn.
*/
function burn(
address tokenOwner,
uint256 tokenId
) external nonReentrant onlyContractOwner {
deleteToken(tokenOwner, tokenId);
delete tokenMediaSafe[tokenId];
delete tokenParameters[tokenId];
delete nftPartners[tokenId];
_burn(tokenId);
}
/** Delete the specified token for the owner. This does not
* burn the token, and should only be used when transferring
* ownership.
*
Note that a delete only sets the specified ownedTokens element to 0, so the
ownedTokens array length does not change.
If tokenId is not owned by tokenOwner [e51] is thrown.
Note that this only needs to iterate through the ownedTokens owned by
tokenOwner and not the entire ownedTokens mapping.
@param tokenOwner Address of token owner
@param tokenId ID of token to delete.
*/
function deleteToken(address tokenOwner, uint256 tokenId) internal {
if (ownerOf(tokenId) != tokenOwner) {
revert HarmonizeError(tokenId, "[e51]");
}
uint256 tokensLength = ownedTokens[tokenOwner].length;
for (uint256 i = 0; i < tokensLength; i++) {
if (ownedTokens[tokenOwner][i] == tokenId) {
console.log(
"delete token %s for tokenOwner %s",
tokenId,
tokenOwner
);
delete ownedTokens[tokenOwner][i];
break;
}
}
}
event Options(uint256 options);
function getOptions() external view returns (uint256) {
return options;
}
/** Set the contract options.
@param opts As described above
*/
function setOptions(uint256 opts) external onlyContractOwner {
options = opts;
emit Options(options);
}
/**
@dev Emit this event when making a payment of any type to any account. The "from" for the payment is
assumed to be msg.sender.
@param tokenId ID of token for which payment occurred. 0 for a mint
@param from Address of payor
@param to Address of payment recepient
@param amount Amount of payment in wei
@param paymentType Type of payment
*/
event Payment(
uint256 tokenId,
address from,
address to,
uint256 amount,
string paymentType
);
/** Send ether from msg.sender using call.
Note that the specified amount has to be included in the transaction
as msg.value.
Note that slither gives a red error "sends eth to arbitrary user". This
is ignored because:
1- The payment is to the payee account
2- This defaults to the contract owner
3- And can only be changed by the contract owner
and therefore payee is not an arbitrary user.
Emits Payment
@param tokenId ID of token for which payment occurred
@param amount Wei
@param paymentType Used as Require string if payment fails.
*/
function payPayee(
uint256 tokenId,
uint256 amount,
string memory paymentType
) internal {
console.log("payPayee amount %s type %s", amount, paymentType);
address payable wallet = payable(payee);
/* We tried to make this conditional with an emitEvent bool parameter to avoid
sliter reentrancy warning but it still gave the warning presumably because
it is not actually executing the contract code */
emit Payment(tokenId, msg.sender, payee, amount, paymentType);
//This fails if you don't have enough eth in msg.value
(bool sent, ) = wallet.call{value: amount}(abi.encode(paymentType));
if (!sent) {
revert HarmonizeError(tokenId, paymentType);
}
}
/**
Same as payPayee but with no event to reduce sliter reentrancy warnings,
@param tokenId ID of token for which payment occurred
@param amount Wei
@param paymentType Used as Require string if payment fails.
*/
function payPayeeNoEvent(
uint256 tokenId,
uint256 amount,
string memory paymentType
) internal {
address payable wallet = payable(payee);
(bool sent, ) = wallet.call{value: amount}(abi.encode(paymentType));
if (!sent) {
revert HarmonizeError(tokenId, paymentType);
}
}
/** Send ether from msg.sender using call.
Note that the specified amount has to be included in the transaction
as msg.value.
When calling this from a loop, set revertOnFailure false. The caller will
therefore execute all calls in the loop, with an event sent for each
payment that fails.
Note that this function does not emit the Payment event.
@param tokenId ID of token for which payment occurred
@param to Recipient
@param amount Wei
@param paymentType Used as Require string if payment fails.
@param revertOnFailure If true and the wallet call fails then revert with HarmonizeError
*/
function payNoEvent(
uint256 tokenId,
address to,
uint256 amount,
string memory paymentType,
bool revertOnFailure
) internal {
address payable wallet = payable(to);
//This fails if you don't have enough eth in msg.value
(bool sent, ) = wallet.call{value: amount}(abi.encode(paymentType));
if (!sent && revertOnFailure) {
revert HarmonizeError(tokenId, paymentType);
}
}
/** Pay the mint fee, if any. If the configure mint fee is 0, no action occurs.
- Reverts with [e10] if the msg.value is less than the mintFeeWei.
@param tokenId Token ID for which payment is made.
*/
function payMintFee(uint256 tokenId) private {
uint256 mintFeeWei = ((options >> OPTIONS_MINT_FEE_SHIFT) &
OPTIONS_MINT_FEE_MASK) * (10 ** 12);
if (mintFeeWei > 0) {
if (msg.value < mintFeeWei) {
revert HarmonizeError(tokenId, "[e10]");
}
payPayee(tokenId, mintFeeWei, "[p1]");
}
}
/** Pay the mediaSafeFee, if any. If the configured fee is 0,
no action occurs.
Note this needs to specify the expiration date
- Reverts with [e60] if the msg.value is less than the mediaSafeFee.
@param tokenId Token ID for which payment is made.
*/
function payMediaSafeFee(uint256 tokenId) private {
uint256 mediaSafeFee = ((options >> OPTIONS_MEDIA_SAFE_FEE_SHIFT) &
OPTIONS_MEDIA_SAFE_FEE_MASK) * (10 ** 12);
if (mediaSafeFee > 0) {
if (msg.value < mediaSafeFee) {
revert HarmonizeError(tokenId, "[e60]");
}
payPayee(tokenId, mediaSafeFee, "[p6]");
}
}
/** Extend the expiration of the MediaSafe for the specified token.
The storageExpirationOffset is added to the block.timestamp. The
mediaSafeFee, if any, must be paid.
- Reverts with [ms10] if there is no MediaSafe for the token
@param tokenId Id of token to extend expiration
*/
function extendMediaSafe(
uint256 tokenId
) external payable onlyUnlockedToken(tokenId) onlyTokenOwner(tokenId) {
if (tokenMediaSafe[tokenId].storageExpiration == 0) {
revert HarmonizeError(tokenId, "[ms10]");
}
tokenMediaSafe[tokenId].storageExpiration =
block.timestamp +
storageExpirationOffset;
payMediaSafeFee(tokenId);
}
/**
Get the purchase fee, if any, for the specified price.
@param price In wei
@return purchase fee in wei
*/
function getPurchaseFee(uint256 price) internal view returns (uint256) {
uint256 purchaseFee = 0;
uint256 purchaseFeePercentage = ((options >>
OPTIONS_PURCHASE_FEE_SHIFT) & OPTIONS_PURCHASE_FEE_MASK);
if (purchaseFeePercentage != 0) {
purchaseFee = (price * purchaseFeePercentage) / 1000;
console.log(
"getPurchaseFee percentage %s fee %s",
purchaseFeePercentage,
purchaseFee
);
}
return purchaseFee;
}
function getTransactionFee() internal view returns (uint256) {
return
((options >> OPTIONS_TRANSACTION_FEE_SHIFT) &
OPTIONS_TRANSACTION_FEE_MASK) * (10 ** 12);
}
/**
Transaction fees are only valid on actions that have no value: setPrice and transferToken.
If there is a transactionFee, the msg.value must be at least equal to this value,
which is then paid to the payee.
@param tokenId Token id
*/
function payTransactionFee(uint256 tokenId) public payable {
uint256 transactionFee = getTransactionFee();
if (transactionFee > 0) {
if (msg.value < transactionFee) {
revert HarmonizeError(tokenId, "[e35]");
}
payPayee(tokenId, transactionFee, "[p5]");
}
}
/**
If partners has entries, the addresses are checked and revert with:
[e4] if the address is 0, or this contract or this sender
[e5] if the address balance is 0
[e6] if the address has been specified more than once in the partners array
@param tokenId Id of token for which Partner array will be set
@param partners Array of Partner that may be empty
*/
function setPartners(uint256 tokenId, Partner[] memory partners) private {
if (partners.length != 0) {
for (uint256 i; i < partners.length; i++) {
address addr = partners[i].partnerAddress;
if (
addr == address(0) ||
addr == address(this) ||
addr == msg.sender
) {
revert HarmonizeError(tokenId, "[e4]");
}
if (addr.balance <= 0) {
revert HarmonizeError(tokenId, "[e5]");
}
for (uint256 j; j < partners.length; j++) {
if (j != i && addr == partners[j].partnerAddress) {
revert HarmonizeError(tokenId, "[e6]");
}
}
nftPartners[tokenId].push(partners[i]);
}
}
}
/** Create a HARMONIZE token with specified tokenId. This
should be a UUID (to ensure uniqueness) then converted to a uint256
before calling this method.
Reverts:
[e1] if hash is 0
[e2] if the price exceeds MAX_PRICE_GWEI
[e3] if the length of the partners array exceeds configured max partners
[e11] if msg.sender is not listed in validAccounts
Note that we cannot reliably check if the address is a contract inside Solidity, and so
the caller should do this.
A TokenParameters is created using the msg.sender as the minter. This preserves
the address of the minter even after ownership changes.
-streamingRights. A value of 1 grants streamingRights to any new owner for the life of this token
-contentRights. If not 0, a MediaSafe will be created and assigned to the token.
This requires the payment of the mediaSafeFee, if any.
@param tokenId Id of token to mint
@param price64 Sale price in gwei. May be 0. Reverts with [e2] if > MAX_PRICE_GWEI
@param hash Required.The SHA256 hash of the media associated with this NFT
Reverts with [e1] if not provided
@param mediaIdHi First 23-byte optional string to associate with this NFT. ISRC is recommended. May be empty.
@param mediaIdLo Second 12 bytes of mediaId
@param titleHi First 32 bytes of the token title
@param titleLo Second 32 bytes of the token title
@param streamingRights Token streaming rights. May be 0.
@param contentLicense If not 0, the 1-based index into the CC... values. Non-0 results in creation
of MediaSafe for this token
@param licenseExt Up to 31 bytes of user-specified license info
@param partners Array of partners. May be an empty array.
*/
function mint(
uint256 tokenId,
uint64 price64,
uint256 hash,
bytes23 mediaIdHi,
bytes12 mediaIdLo,
bytes32 titleHi,
bytes32 titleLo,
uint8 streamingRights,
uint8 contentLicense,
bytes31 licenseExt,
Partner[] calldata partners
) external payable nonReentrant isRunning {
if (validAccounts[msg.sender].accountHi == bytes32(0)) {
revert HarmonizeError(tokenId, "[e11]");
}
if (hash == 0) {
revert HarmonizeError(tokenId, "[e1]");
}
if (price64 > MAX_PRICE_GWEI) {
revert HarmonizeError(tokenId, "[e2]");
}
uint256 maxPartners = (options >> OPTIONS_MAX_PARTNERS_SHIFT) &
OPTIONS_MAX_PARTNERS_MASK;
if (partners.length > maxPartners) {
revert HarmonizeError(tokenId, "[e3]");
}
ownedTokens[msg.sender].push(tokenId);
if (contentLicense != 0) {
setMediaSafe(tokenId, contentLicense, licenseExt);
}
tokenParameters[tokenId] = TokenParameters({
titleHi: titleHi,
titleLo: titleLo,
price: price64,
mediaHash: hash,
mediaIdHi: mediaIdHi,
mediaIdLo: mediaIdLo,
minter: msg.sender,
streamingRights: streamingRights
});
setPartners(tokenId, partners);
_safeMint(msg.sender, tokenId);
if (contentLicense != 0) {
payMediaSafeFee(tokenId);
}
payMintFee(tokenId);
}
/** Set one token sale price. A price is only set if
msg.sender is the token owner; otherwise [e30] is thrown.
If there is a defined transactionFee, it must be included in msg.value.
Emits a SetPrice event.
@param tokenId ID of token that will have price set
@param price64 64 bit price in gwei for each token. A 0 means not for sale.
*/
function setPrice(
uint256 tokenId,
uint64 price64
)
external
payable
nonReentrant
isRunning
onlyUnlockedToken(tokenId)
onlyTokenOwner(tokenId)
{
TokenParameters storage parameter = tokenParameters[tokenId];
parameter.price = price64;
payTransactionFee(tokenId);
emit SetPrice(msg.sender, tokenId, price64 * (10 ** 9));
}
/**
* Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
Note: this cannot be tagged nonReentrant because it is called back by several nonReentrant
methods (e.g., mint).
This hook is called from the OpenZeppelin ERC721 public transfer methods. It ensures
that payments occur before any transfers occur, no matter who calls the contract.
Note that this is also called from the internal _mint and _burn methods, in which case none of
the payments mechanisms apply. A _mint is defined by a tokenOwner of 0. A _burn is defined by
both to and auth of 0. In either case we just call super._update.
Note additionally that only the token owner is allowed to transfer (not sell) a token.
In this case the sender only pays the
transactionFee and all other payments are bypassed. A _transfer is defined by a non-0 to and
an auth of msg.sender. See transferFrom in OpenZeppeling ERC721.
Note that for a purchase, to is msg.sender, tokenId is the token to transfer, and auth is 0.
The token owner must be specified to retrieve the price, and if the price
is <=0, it means the token is either not for sale, or not owned by the owner.
Amount Paid
===
The amount paid is specified in msg.value. Except as noted above, this may be greater than
(but not less than) the token price. For auctions this means the open price is the token price,
and then the final price can be greater.
Shareholders are always paid a fixed portion based on number of shares held and
total percentage of token offered in the issue.
Token owner and partners are the same for purposes of payout -- whatever is left after
royalty, purchaseFee and shareholders is divided among owner/partners according to percentage.
Percentages are only specified for partners and anything after that goes to the token owner.
Payments are made in this order:
1) When payment mechanisms are bypassed, a transaction fee is paid to the contract owner
2) Otherwise netProceeds of (msg.value-purchaseFee) is calculated
3) Then if there are partners they are paid on netProceeds-royalty
4) Delete the partners
5) Then the tokenOwner is paid on netProceeds-royalty-partnerPayout
6) Finally the purchaseFee is paid to the contract owner by the token owner
If everything in here succeeds, the price for the token is set to 0. This means
the token is not for sale until the new owner sets a price.
Reverts with [e40] if to is the address of this contract, or the msg.value is < the token price.
Note that both transfer and purchase set the token price to 0.
* @param to Address purchasing the token
* @param tokenId uint256 token ID
* @param auth Owner of the token from whom the token is transferred
*/
function _update(
address to,
uint256 tokenId,
address auth
) internal virtual override(ERC721) isRunning returns (address) {
console.log("Update to %s tokenId %s auth %s", to, tokenId, auth);
address tokenOwner = _ownerOf(tokenId);
if (to != address(0) && tokenOwner == address(0)) {
console.log("------->MINT");
return super._update(to, tokenId, auth); //mint
}
if (to == address(0) && auth == address(0)) {
//burn
console.log("------->BURN");
return super._update(to, tokenId, auth);
}
if (to != address(0) && auth == msg.sender) {
//transfer
console.log("------->TRANSFER");
//Set token price to 0
tokenParameters[tokenId].price = 0;
address updateReturn = super._update(to, tokenId, auth);
payTransactionFee(tokenId);
return updateReturn;
} else {
//purchase
/* Get the price bits from the price field, then because they are in gwei,
multiply by 1 billion to get wei */
TokenParameters storage parameter = tokenParameters[tokenId];
uint256 price = parameter.price * 10 ** 9;
console.log(
"------->PURCHASE, msg.value %s price %s",
msg.value,
price
);
if (to == address(this) || msg.value < price) {
revert HarmonizeError(tokenId, "[e40]");
}
address updateReturn = super._update(to, tokenId, address(0));
//Set token price to 0 so that after transfer it must be priced to be saleable
tokenParameters[tokenId].price = 0;
/* 2) The seller and partners always get the full token sale price */
uint256 netProceeds = price;
/* 4) Pay partners */
Payouts memory partnerPayouts = this.calculatePartnerPayout(
tokenId,
netProceeds
);
delete nftPartners[tokenId];
netProceeds -= partnerPayouts.totalPayout;
/* Emit Payment events before payment calls to avoid slither reentrancy warning */
emit Payment(tokenId, msg.sender, tokenOwner, netProceeds, "[p10]");
uint256 purchaseFee = getPurchaseFee(price);
if (purchaseFee > 0) {
emit Payment(tokenId, msg.sender, payee, purchaseFee, "[p11]");
}
if (partnerPayouts.totalPayout != 0) {
fractionalPayoutEvents(tokenId, partnerPayouts, "[p50]");
}
/* 6) Pay the tokenOwner whatever is left (except purchase fee) */
payNoEvent(tokenId, tokenOwner, netProceeds, "[p10]", true);
/* 7) Pay the purchaseFee to the payee */
if (purchaseFee > 0) {
payPayeeNoEvent(tokenId, purchaseFee, "[p11]");
}
if (partnerPayouts.totalPayout != 0) {
fractionalPayout(tokenId, partnerPayouts, "[p50]");
}
return updateReturn;
}
}
/** Add MediaSafe to the specified token if the former does not
already exist. The storageExpiration is set to storageExpirationOffset
from now. The msg.sender, who must be the token owner,
must also be the minter. This means the function
is not valid once a token has transferred ownership.
This function also calls payMediaSafeFee.
- Reverts with [ms3] if MediaSafe exists for this token
- Reverts with [ms4] if the passed contentRights are 0
- Reverts with [ms5] if the msg.sender is not the token minter
@param tokenId Id of token to set
@param contentLicense 1-based index into LICENSE_CODES
@param licenseExt Optional 31 bytes of license info
*/
function addMediaSafe(
uint256 tokenId,
uint8 contentLicense,
bytes31 licenseExt
) external payable onlyUnlockedToken(tokenId) onlyTokenOwner(tokenId) {
if (tokenMediaSafe[tokenId].storageExpiration != 0) {
revert HarmonizeError(tokenId, "[ms3]");
} else if (contentLicense == 0) {
revert HarmonizeError(tokenId, "[ms4]");
} else if (tokenParameters[tokenId].minter != msg.sender) {
revert HarmonizeError(tokenId, "[ms5]");
} else {
tokenMediaSafe[tokenId] = MediaSafe({
storageExpiration: block.timestamp + storageExpirationOffset,
contentLicense: contentLicense,
licenseExt: licenseExt
});
payMediaSafeFee(tokenId);
}
}
/** Delete the MediaSafe for the token
@param tokenId Id of token
*/
function deleteMediaSafe(
uint256 tokenId
) external onlyContractOwnerOrContentManager(tokenId) {
delete (tokenMediaSafe[tokenId]);
}
/** Emitted from requestMed...
// [truncated — 60178 bytes total]
console.sol 1552 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
library console {
address constant CONSOLE_ADDRESS =
0x000000000000000000636F6e736F6c652e6c6f67;
function _sendLogPayloadImplementation(bytes memory payload) internal view {
address consoleAddress = CONSOLE_ADDRESS;
/// @solidity memory-safe-assembly
assembly {
pop(
staticcall(
gas(),
consoleAddress,
add(payload, 32),
mload(payload),
0,
0
)
)
}
}
function _castToPure(
function(bytes memory) internal view fnIn
) internal pure returns (function(bytes memory) pure fnOut) {
assembly {
fnOut := fnIn
}
}
function _sendLogPayload(bytes memory payload) internal pure {
_castToPure(_sendLogPayloadImplementation)(payload);
}
function log() internal pure {
_sendLogPayload(abi.encodeWithSignature("log()"));
}
function logInt(int256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
}
function logUint(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function logString(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function logBool(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function logAddress(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function logBytes(bytes memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
}
function logBytes1(bytes1 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
}
function logBytes2(bytes2 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
}
function logBytes3(bytes3 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
}
function logBytes4(bytes4 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
}
function logBytes5(bytes5 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
}
function logBytes6(bytes6 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
}
function logBytes7(bytes7 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
}
function logBytes8(bytes8 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
}
function logBytes9(bytes9 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
}
function logBytes10(bytes10 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
}
function logBytes11(bytes11 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
}
function logBytes12(bytes12 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
}
function logBytes13(bytes13 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
}
function logBytes14(bytes14 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
}
function logBytes15(bytes15 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
}
function logBytes16(bytes16 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
}
function logBytes17(bytes17 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
}
function logBytes18(bytes18 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
}
function logBytes19(bytes19 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
}
function logBytes20(bytes20 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
}
function logBytes21(bytes21 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
}
function logBytes22(bytes22 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
}
function logBytes23(bytes23 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
}
function logBytes24(bytes24 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
}
function logBytes25(bytes25 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
}
function logBytes26(bytes26 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
}
function logBytes27(bytes27 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
}
function logBytes28(bytes28 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
}
function logBytes29(bytes29 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
}
function logBytes30(bytes30 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
}
function logBytes31(bytes31 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
}
function logBytes32(bytes32 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
}
function log(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function log(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function log(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function log(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function log(uint256 p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256)", p0, p1));
}
function log(uint256 p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string)", p0, p1));
}
function log(uint256 p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool)", p0, p1));
}
function log(uint256 p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address)", p0, p1));
}
function log(string memory p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
}
function log(string memory p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
}
function log(string memory p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
}
function log(string memory p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
}
function log(bool p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256)", p0, p1));
}
function log(bool p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
}
function log(bool p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
}
function log(bool p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
}
function log(address p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256)", p0, p1));
}
function log(address p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
}
function log(address p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
}
function log(address p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
}
function log(uint256 p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address)", p0, p1, p2));
}
function log(uint256 p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256)", p0, p1, p2));
}
function log(uint256 p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string)", p0, p1, p2));
}
function log(uint256 p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool)", p0, p1, p2));
}
function log(uint256 p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address)", p0, p1, p2));
}
function log(uint256 p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256)", p0, p1, p2));
}
function log(uint256 p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string)", p0, p1, p2));
}
function log(uint256 p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool)", p0, p1, p2));
}
function log(uint256 p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address)", p0, p1, p2));
}
function log(string memory p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256)", p0, p1, p2));
}
function log(string memory p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
function log(string memory p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
}
function log(string memory p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
}
function log(string memory p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256)", p0, p1, p2));
}
function log(string memory p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
}
function log(string memory p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
}
function log(string memory p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
}
function log(string memory p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256)", p0, p1, p2));
}
function log(string memory p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
}
function log(string memory p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
}
function log(string memory p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
}
function log(bool p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256)", p0, p1, p2));
}
function log(bool p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string)", p0, p1, p2));
}
function log(bool p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool)", p0, p1, p2));
}
function log(bool p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address)", p0, p1, p2));
}
function log(bool p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256)", p0, p1, p2));
}
function log(bool p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
}
function log(bool p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
}
function log(bool p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
}
function log(bool p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256)", p0, p1, p2));
}
function log(bool p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
}
function log(bool p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
}
function log(bool p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
}
function log(bool p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256)", p0, p1, p2));
}
function log(bool p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
}
function log(bool p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
}
function log(bool p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
}
function log(address p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256)", p0, p1, p2));
}
function log(address p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string)", p0, p1, p2));
}
function log(address p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool)", p0, p1, p2));
}
function log(address p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address)", p0, p1, p2));
}
function log(address p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256)", p0, p1, p2));
}
function log(address p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
}
function log(address p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
}
function log(address p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
}
function log(address p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256)", p0, p1, p2));
}
function log(address p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
}
function log(address p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
}
function log(address p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
}
function log(address p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256)", p0, p1, p2));
}
function log(address p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
}
function log(address p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
}
function log(address p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1,...
// [truncated — 69001 bytes total]
Read Contract
LICENSE_CODES 0xc45c5264 → bytes16
VERSION 0xffa1ad74 → uint256
balanceOf 0x70a08231 → uint256
calculatePartnerPayout 0xf4b2652e → tuple
extGetTokenOwner 0x35f1013c → address
getAllowedContracts 0x538741c5 → address[]
getApproved 0x081812fc → address
getContentManager 0x2c2dae4a → address
getMediaSafe 0x4e79b701 → tuple
getOptions 0xcc2ee196 → uint256
getOwnedTokens 0xd9d61655 → uint256[]
getOwner 0x893d20e8 → address
getPartners 0xa8cbf238 → tuple[]
getPayee 0xcd446735 → address
getPrice 0xe7572230 → uint256
getServiceAccount 0x8a999417 → address
getStorageExpirationOffset 0xf5954d83 → uint256
getTokenLock 0xb0b5babe → bool
getTokenParameters 0xbc7dd87e → tuple
getValidAccount 0x8eda900f → tuple
isApprovedForAll 0xe985e9c5 → bool
name 0x06fdde03 → string
ownerOf 0x6352211e → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenURI 0xc87b56dd → string
Write Contract 26 functions
These functions modify contract state and require a wallet transaction to execute.
addMediaSafe 0x22e21b41
uint256 tokenId
uint8 contentLicense
bytes31 licenseExt
approve 0x095ea7b3
address to
uint256 tokenId
burn 0x9dc29fac
address tokenOwner
uint256 tokenId
deleteAllowedContract 0x70072f11
address account
deleteMediaSafe 0x234be6e1
uint256 tokenId
deleteValidAccount 0x3567809b
address account
extendMediaSafe 0xd07558d3
uint256 tokenId
mint 0x6b79ea69
uint256 tokenId
uint64 price64
uint256 hash
bytes23 mediaIdHi
bytes12 mediaIdLo
bytes32 titleHi
bytes32 titleLo
uint8 streamingRights
uint8 contentLicense
bytes31 licenseExt
tuple[] partners
payTransactionFee 0xa15454ba
uint256 tokenId
purchaseToken 0x1cc2c911
address tokenOwner
uint256 tokenId
requestMediaSafe 0xf52125ad
uint256 tokenId
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes data
setAllowedContract 0x86e32ed0
address account
setApprovalForAll 0xa22cb465
address operator
bool approved
setContentManager 0xac9fe7ef
address stManager
setOptions 0xe1a44749
uint256 opts
setPayee 0x410459ad
address payeeAccount
setPrice 0x2ba27019
uint256 tokenId
uint64 price64
setServiceAccount 0xa96ec5d8
address svcAccount
setStorageExpirationOffset 0x60514869
uint256 offset
setTokenLock 0xe68f3bd8
uint256 tokenId
bool locked
setValidAccount 0x1b8f81c7
address account
bytes32 harmonizeAccountHi
bytes16 harmonizeAccountLo
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
transferToken 0x1072cbea
address newOwner
uint256 tokenId
Recent Transactions
No transactions found for this address