Address Contract Partially Verified
Address
0x9F4594F157F610Ea51F3B86cd9bE023F7b11dc08
Balance
0 ETH
Nonce
4
Code Size
16478 bytes
Creator
0xe3C1B523...9A1b at tx 0x04b5fc21...7ffc81
Indexed Transactions
0
Contract Bytecode
16478 bytes
0x6080604052600436101561001257600080fd5b60003560e01c8062fdd58e146101e657806301ffc9a7146101e15780630e89341c146101dc5780631b2ef1ca146101d75780631ffbee64146101d25780632eb2c2d6146101cd5780634e1273f4146101c857806351cff8d9146101c357806354fd4d50146101be5780635d05125b146101b9578063715018a6146101b457806379ba5097146101af57806384252fb7146101aa57806387d81789146101a55780638c0e8349146101a05780638da5cb5b1461019b5780639507d39a14610196578063a22cb46514610191578063a38d93491461018c578063b564434114610187578063b6cb8dfe14610182578063c4a0d4651461017d578063c622969814610178578063e30c397814610173578063e8a3d4851461016e578063e985e9c514610169578063f242432a14610164578063f2fde38b1461015f5763f5298aca1461015a57600080fd5b611c3d565b611b90565b6119d2565b611938565b6117ab565b611759565b6116c1565b6115ff565b6114e8565b61148e565b6113dd565b61128a565b6111d0565b6110bc565b611080565b610ff1565b610f3a565b610e54565b610dab565b610d6f565b610d30565b610ce9565b610c10565b610a00565b6107c6565b610612565b6104aa565b610340565b61029d565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361020e57565b600080fd5b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361020e57565b6084359073ffffffffffffffffffffffffffffffffffffffff8216820361020e57565b60a4359073ffffffffffffffffffffffffffffffffffffffff8216820361020e57565b359073ffffffffffffffffffffffffffffffffffffffff8216820361020e57565b3461020e5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57602061030d6102d96101eb565b6024356000526002835260406000209073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b54604051908152f35b7fffffffff0000000000000000000000000000000000000000000000000000000081160361020e57565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e5760207fffffffff0000000000000000000000000000000000000000000000000000000060043561039e81610316565b167fd9b67a26000000000000000000000000000000000000000000000000000000008114908115610406575b81156103dc575b506040519015158152f35b7f01ffc9a700000000000000000000000000000000000000000000000000000000915014386103d1565b7f0e89341c00000000000000000000000000000000000000000000000000000000811491506103ca565b60005b8381106104435750506000910152565b8181015183820152602001610433565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f60209361048f81518092818752878088019101610430565b0116010190565b9060206104a7928181520190610453565b90565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57600435600a5481116105e857600081610507610502610599946000526008602052604060002090565b61210d565b9061056361054a61054a61052a610525606087015163ffffffff1690565b61078a565b905473ffffffffffffffffffffffffffffffffffffffff9160031b1c1690565b73ffffffffffffffffffffffffffffffffffffffff1690565b906040518095819482937fa2f31bf300000000000000000000000000000000000000000000000000000000845260048401612242565b03915afa80156105e3576105bc916000916105c0575b5060405191829182610496565b0390f35b6105dd91503d806000833e6105d5818361089b565b8101906121e3565b386105af565b61230e565b60046040517f9430a17e000000000000000000000000000000000000000000000000000000008152fd5b3461020e5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57600435602435600a5482116105e85761068b61067e600361066c856000526008602052604060002090565b015460401c67ffffffffffffffff1690565b67ffffffffffffffff1690565b42116107315761054a7f160ecdf0b6c0a56992b4f6fad717f85f3b0bba236ec571bf26ca5cf4fe61101e916107046106cd85600052600c602052604060002090565b6106fb6106de846001840154612349565b9485925473ffffffffffffffffffffffffffffffffffffffff1690565b3090339061318f565b61071761070f61235c565b828633613257565b6040805192835260208301919091523390820152606090a2005b60046040517f589ed34b000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6009548110156107c15760096000527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0190600090565b61075b565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e5760043560095481101561020e5773ffffffffffffffffffffffffffffffffffffffff60209160096000527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af015416604051908152f35b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6020810190811067ffffffffffffffff82111761089657604052565b61084b565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761089657604052565b604051906040820182811067ffffffffffffffff82111761089657604052565b67ffffffffffffffff81116108965760051b60200190565b9080601f8301121561020e57602090823561092e816108fc565b9361093c604051958661089b565b81855260208086019260051b82010192831161020e57602001905b828210610965575050505090565b81358152908301908301610957565b67ffffffffffffffff811161089657601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b9291926109ba82610974565b916109c8604051938461089b565b82948184528183011161020e578281602093846000960137010152565b9080601f8301121561020e578160206104a7933591016109ae565b3461020e5760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57610a376101eb565b610a3f610213565b906044359167ffffffffffffffff9081841161020e57610a6460049436908601610914565b9060643583811161020e57610a7c9036908701610914565b9260843590811161020e57610a9490369087016109e5565b9373ffffffffffffffffffffffffffffffffffffffff808216903382141580610b89575b610b3657831615610b055715610ad457610ad295506138ba565b005b6024866000604051917f01a83514000000000000000000000000000000000000000000000000000000008352820152fd5b6024876000604051917f57f447ce000000000000000000000000000000000000000000000000000000008352820152fd5b604080517fe237d92200000000000000000000000000000000000000000000000000000000815233818b0190815273ffffffffffffffffffffffffffffffffffffffff8616602082015290918291010390fd5b5081600052600360205260ff610bc33360406000209073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b541615610ab8565b90815180825260208080930193019160005b828110610beb575050505090565b835185529381019392810192600101610bdd565b9060206104a7928181520190610bcb565b3461020e5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e5760043567ffffffffffffffff80821161020e573660238301121561020e578160040135610c6b816108fc565b92610c79604051948561089b565b8184526020916024602086019160051b8301019136831161020e57602401905b828210610cd2578560243586811161020e576105bc91610cc0610cc6923690600401610914565b90612383565b60405191829182610bff565b838091610cde8461027c565b815201910190610c99565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57610ad2610d236101eb565b610d2b6132a8565b61246f565b3461020e5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e576020604051650a015eb427b08152f35b3461020e5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e576020600b54604051908152f35b3461020e576000807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610e5157610de36132a8565b8073ffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffff0000000000000000000000000000000000000000806001541660015582549081168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b3461020e5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e573373ffffffffffffffffffffffffffffffffffffffff6001541603610eab57610ad233613330565b60246040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152fd5b9181601f8401121561020e5782359167ffffffffffffffff831161020e576020838186019501011161020e57565b9181601f8401121561020e5782359167ffffffffffffffff831161020e576020808501948460051b01011161020e57565b3461020e5760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e5767ffffffffffffffff60043581811161020e57610f8a903690600401610edb565b60243583811161020e57610fa2903690600401610edb565b9060443585811161020e57610fbb903690600401610edb565b9060643596871161020e57610fd7610ad2973690600401610f09565b949093610fe2610236565b96610feb610259565b98612c67565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57600435600052600c6020526040600020600173ffffffffffffffffffffffffffffffffffffffff825416910154906105bc604051928392836020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b3461020e5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e576020600a54604051908152f35b3461020e5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57602073ffffffffffffffffffffffffffffffffffffffff60005416604051908152f35b90815180825260208080930193019160005b82811061112e575050505090565b835173ffffffffffffffffffffffffffffffffffffffff1685529381019392810192600101611120565b9590936111b060c0969998946111a267ffffffffffffffff956111946fffffffffffffffffffffffffffffffff9960e08d5260e08d0190610453565b908b820360208d0152610453565b9089820360408b015261110e565b9863ffffffff80921660608901521660808701521660a085015216910152565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e576004356000526008602052604060002060038101546105bc63ffffffff92604051936112368561122f8185611ff0565b038661089b565b6112566002604051936112508561122f8160018501611ff0565b016120a4565b936040519586958260801c9467ffffffffffffffff8460401c1694808560201c1694169288611158565b8015150361020e57565b3461020e5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e576112c16101eb565b6024356112cd81611280565b73ffffffffffffffffffffffffffffffffffffffff821691821561138d576113229033600052600360205260406000209073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541660ff831515161790557f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160405180611388339482919091602081019215159052565b0390a3005b60246040517fced3e10000000000000000000000000000000000000000000000000000000000815260006004820152fd5b608435906fffffffffffffffffffffffffffffffff8216820361020e57565b3461020e5760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e5767ffffffffffffffff60043581811161020e5761142d903690600401610edb565b60243583811161020e57611445903690600401610edb565b9360443590811161020e5761145e903690600401610f09565b6064359163ffffffff8316830361020e57610ad29661147b6113be565b94611484610259565b9660c43598612e41565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e576004356000526008602052602067ffffffffffffffff60036040600020015460401c16604051908152f35b3461020e5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e5760043560243567ffffffffffffffff811161020e5761153a903690600401610f09565b91906044359161154983611280565b6115516132a8565b600a548111156115d65760005260086020526002604060002001918254151590816115ce575b506115c0575b60005b60ff81169084821015610ad2576115b66115b06115ab6115a46115bb958988612a7e565b36916109ae565b6133a5565b85612bfc565b612a6d565b611580565b6115c98261316b565b61157d565b905038611577565b60046040517ea5a1f5000000000000000000000000000000000000000000000000000000008152fd5b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e576116366101eb565b61163e6132a8565b61164781612ade565b600954907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82019182116116bc578160209273ffffffffffffffffffffffffffffffffffffffff60405193167fbe12a6cdcfa8711b87484030475533b479a18855d1d39eb97f1f0f3fd6e111ff600080a38152f35b61231a565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57600435600a5481116105e857600052600c6020526040600020600173ffffffffffffffffffffffffffffffffffffffff825416910154906105bc604051928392836020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b3461020e5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57602073ffffffffffffffffffffffffffffffffffffffff60015416604051908152f35b3461020e576000807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610e51576040517f033918d3000000000000000000000000000000000000000000000000000000008152818160208060048301526080602483015261181e60a48301611e01565b906118656118567fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc9384868203016044870152611ed4565b83858203016064860152611f62565b918383030160848401526020600754928381520191600785527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c6889185905b82821061190457505050508190038173c1f6a976906283a6ef713ab4439c8e79faf188a35af49081156105e357826105bc93926118e9575b505060405191829182610496565b6118fd92503d8091833e6105d5818361089b565b38806118db565b835473ffffffffffffffffffffffffffffffffffffffff1685528896508795509384019360019384019391909101906118a3565b3461020e5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57602060ff6119c66119766101eb565b73ffffffffffffffffffffffffffffffffffffffff611993610213565b91166000526003845260406000209073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b54166040519015158152f35b3461020e5760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57611a096101eb565b611a11610213565b60843567ffffffffffffffff811161020e57611a319036906004016109e5565b9073ffffffffffffffffffffffffffffffffffffffff808416903382141580611b4e575b611b0157821615611ad05715611a9f57610ad292611a976064356044359160405192600184526020840152604083019160018352606084015260808301604052565b9290916138ba565b60246040517f01a8351400000000000000000000000000000000000000000000000000000000815260006004820152fd5b60246040517f57f447ce00000000000000000000000000000000000000000000000000000000815260006004820152fd5b6040517fe237d92200000000000000000000000000000000000000000000000000000000815233600482015273ffffffffffffffffffffffffffffffffffffffff86166024820152604490fd5b5081600052600360205260ff611b883360406000209073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b541615611a55565b3461020e5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57611bc76101eb565b611bcf6132a8565b73ffffffffffffffffffffffffffffffffffffffff80911690817fffffffffffffffffffffffff00000000000000000000000000000000000000006001541617600155600054167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b3461020e5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261020e57611c746101eb565b73ffffffffffffffffffffffffffffffffffffffff81163381141580611d32575b611ce55715611a9f57610ad290611cd06044356024359160405192600184526020840152604083019160018352606084015260808301604052565b916000604051611cdf8161087a565b52613550565b6040517fe237d92200000000000000000000000000000000000000000000000000000000815233600482015273ffffffffffffffffffffffffffffffffffffffff83166024820152604490fd5b5080600052600360205260ff611d6c3360406000209073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b541615611c95565b611daa91600052600260205260406000209073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b5490565b90600182811c92168015611df7575b6020831014611dc857565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f1691611dbd565b60045460009291611e1182611dae565b80825291602090600190818116908115611e905750600114611e34575b50505050565b9293945060046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b926000935b858510611e7d575050506020925001019038808080611e2e565b8054858501840152938201938101611e63565b91505060209495507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0091509291921683830152151560051b01019038808080611e2e565b60055460009291611ee482611dae565b80825291602090600190818116908115611e905750600114611f065750505050565b9293945060056000527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0926000935b858510611f4f575050506020925001019038808080611e2e565b8054858501840152938201938101611f35565b60065460009291611f7282611dae565b80825291602090600190818116908115611e905750600114611f945750505050565b9293945060066000527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f926000935b858510611fdd575050506020925001019038808080611e2e565b8054858501840152938201938101611fc3565b805460009392611fff82611dae565b918282526020936001916001811690816000146120675750600114612026575b5050505050565b90939495506000929192528360002092846000945b8386106120535750505050010190388080808061201f565b80548587018301529401938590820161203b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168685015250505090151560051b01019150388080808061201f565b90604051918281549182825260209260208301916000526020600020936000905b8282106120dd575050506120db9250038361089b565b565b855473ffffffffffffffffffffffffffffffffffffffff16845260019586019588955093810193909101906120c5565b906040519160e083019267ffffffffffffffff9181851083861117610896576120db926121db600360c0938860405285986121757fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff208861216d8486611ff0565b03018261089b565b86526040516121928161218b8160018601611ff0565b038261089b565b60208701526121a3600282016120a4565b6040870152015463ffffffff8082166060870152602082901c166080860152918260401c1660a085019067ffffffffffffffff169052565b60801c910152565b60208183031261020e5780519067ffffffffffffffff821161020e570181601f8201121561020e57805161221681610974565b92612224604051948561089b565b8184526020828401011161020e576104a79160208085019101610430565b6104a79181526040602082015261010060c06122bd61226e865160e06040870152610120860190610453565b6122a86020880151917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc09283888303016060890152610453565b9060408801519086830301608087015261110e565b94606081015163ffffffff80911660a0860152608082015116828501526122f560a082015160e086019067ffffffffffffffff169052565b01516fffffffffffffffffffffffffffffffff16910152565b6040513d6000823e3d90fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b818102929181159184041417156116bc57565b604051906123698261087a565b60008252565b80518210156107c15760209160051b010190565b919091805183518082036124255750508051906123b86123a2836108fc565b926123b0604051948561089b565b8084526108fc565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe06020920136602085013760005b815181101561241d578061240c60019260051b85808287010151918a01015190611d74565b612416828761236f565b52016123e7565b509193505050565b6040517f5b05999100000000000000000000000000000000000000000000000000000000815260048101919091526024810191909152604490fd5b9081602091031261020e575190565b73ffffffffffffffffffffffffffffffffffffffff809116908115612559576040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290602082602481865afa9182156105e357600092612528575b508115612523578161250e7f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b659361251e9360005416866132c9565b6040519081529081906020820190565b0390a2565b505050565b61254b91925060203d602011612552575b612543818361089b565b810190612460565b90386124d3565b503d612539565b60046040517f56e7ec5f000000000000000000000000000000000000000000000000000000008152fd5b81811061258e575050565b60008155600101612583565b90601f82116125a7575050565b6120db9160046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b906020601f840160051c830193106125f1575b601f0160051c0190612583565b90915081906125e4565b90601f8211612608575050565b6120db9160056000527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0906020601f840160051c830193106125f157601f0160051c0190612583565b90601f821161265e575050565b6120db9160066000527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f906020601f840160051c830193106125f157601f0160051c0190612583565b9190601f81116126b657505050565b6120db926000526020600020906020601f840160051c830193106125f157601f0160051c0190612583565b919067ffffffffffffffff81116108965761270681612701600554611dae565b6125fb565b6000601f82116001146127645781906127549394600092612759575b50507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161790565b600555565b013590503880612722565b60056000527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08216937f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db091805b86811061280757508360019596106127cf575b505050811b01600555565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88560031b161c199101351690553880806127c4565b909260206001819286860135815501940191016127b1565b919067ffffffffffffffff8111610896576128448161283f600654611dae565b612651565b6000601f821160011461289657819061289193946000926127595750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161790565b600655565b60066000527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08216937ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f91805b8681106129395750836001959610612901575b505050811b01600655565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88560031b161c199101351690553880806128f6565b909260206001819286860135815501940191016128e3565b90929167ffffffffffffffff811161089657612977816129718454611dae565b846126a7565b6000601f82116001146129c95781906129c59394956000926127595750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161790565b9055565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08216946129fc84600052602060002090565b91805b878110612a55575083600195969710612a1d575b505050811b019055565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88560031b161c19910135169055388080612a13565b909260206001819286860135815501940191016129ff565b60ff1660ff81146116bc5760010190565b91908110156107c15760051b810135907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18136030182121561020e57019081359167ffffffffffffffff831161020e57602001823603811361020e579190565b60095490680100000000000000008210156108965760018201806009558210156107c1576120db9160096000527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af019073ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055565b60075490680100000000000000008210156108965760018201806007558210156107c1576120db9160076000527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c688019073ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055565b80546801000000000000000081101561089657600181018083558110156107c15773ffffffffffffffffffffffffffffffffffffffff9160005260206000200191167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055565b9995969799600b54612e175767ffffffffffffffff821161089657612c9682612c91600454611dae565b61259a565b600090601f8311600114612d4d5782612cfb97969593612cf69593612cee936000926127595750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161790565b6004556126e1565b61281f565b60005b60ff811684811015612d2c57906115b6612d226115ab6115a4612d27958989612a7e565b612b6d565b612cfe565b5050936120db939250612d3f9150612ade565b612d4843600b55565b613330565b60046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08416815b818110612dff5750926001928592612cfb9a999896612cf6989610612dc7575b505050811b016004556126e1565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88560031b161c19910135169055388080612db9565b91936020600181928787013581550195019201612d99565b60046040517f5daa87a0000000000000000000000000000000000000000000000000000000008152fd5b9598929197939896909496612e546132a8565b600954612e6c612e638361310c565b63ffffffff1690565b116130e25773ffffffffffffffffffffffffffffffffffffffff85161561255957612ed7612fd793612ecb61306598612eae612ea9600a54613121565b600a55565b612ec4600a546000526008602052604060002090565b9a8b612951565b60019a60018a01612951565b6003870180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffff164360201b67ffffffff000000001617815590612f9690612f65612f2461067e4261314e565b84547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff1660409190911b6fffffffffffffffff000000000000000016178455565b829063ffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000825416179055565b906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b612ffe612fe26108dc565b73ffffffffffffffffffffffffffffffffffffffff9093168352565b6020820152613019600a54600052600c602052604060002090565b90602060019173ffffffffffffffffffffffffffffffffffffffff8151167fffffffffffffffffffffffff00000000000000000000000000000000000000008554161784550151910155565b81613084575b505050506120db600a5461307d61235c565b903361320b565b6002019283546130d4575b6000835b61309e575b5061306b565b60ff811690838210156130ce576115b66130c26115ab6115a46130c8958888612a7e565b87612bfc565b83613093565b50613098565b6130dd8461316b565b61308f565b60046040517fa9a25f67000000000000000000000000000000000000000000000000000000008152fd5b90600163ffffffff809316019182116116bc57565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146116bc5760010190565b906201518082018092116116bc57565b919082018092116116bc57565b8054600082558061317a575050565b6120db91600052602060002090810190612583565b9290604051927f23b872dd00000000000000000000000000000000000000000000000000000000602085015273ffffffffffffffffffffffffffffffffffffffff809216602485015216604483015260648201526064815260a081019181831067ffffffffffffffff841117610896576120db926040526134ae565b91909173ffffffffffffffffffffffffffffffffffffffff811615611ad0576120db92604051906001825260208201526040810191600183526001606083015260808201604052613728565b9092919273ffffffffffffffffffffffffffffffffffffffff821615611ad0576120db936132a260405192600184526020840152604083019160018352606084015260808301604052565b91613728565b73ffffffffffffffffffffffffffffffffffffffff600054163303610eab57565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff9290921660248301526044808301939093529181526120db9161332b60648361089b565b6134ae565b7fffffffffffffffffffffffff000000000000000000000000000000000000000090816001541660015560005473ffffffffffffffffffffffffffffffffffffffff8092168093821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b604051906133db6021836020810193600085526133cb8151809260208686019101610430565b810103600181018552018361089b565b61342c602b604051809361341c60208301967f600b5981380380925939f3000000000000000000000000000000000000000000885251809285850190610430565b810103600b81018452018261089b565b51906000f09073ffffffffffffffffffffffffffffffffffffffff82161561345057565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4445504c4f594d454e545f4641494c45440000000000000000000000000000006044820152fd5b60008073ffffffffffffffffffffffffffffffffffffffff6134e593169360208151910182865af16134de613bda565b9083613f88565b805190811515918261352c575b50506134fb5750565b602490604051907f5274afe70000000000000000000000000000000000000000000000000000000082526004820152fd5b819250906020918101031261020e576020015161354881611280565b1538806134f2565b929190805182519081810361242557505060005b815181101561366d578060051b6020808285010151918501015173ffffffffffffffffffffffffffffffffffffffff87166135a4575b5050600101613564565b6135e1876135bc846000526002602052604060002090565b9073ffffffffffffffffffffffffffffffffffffffff16600052602052604060002090565b5481811061361057876135bc60019594936136089303936000526002602052604060002090565b55903861359a565b6040517f03dee4c500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8916600482015260248101919091526044810182905260648101839052608490fd5b50906000929391600181511484146136dc5760209081015191810151604080519384529183015273ffffffffffffffffffffffffffffffffffffffff929092169133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291819081015b0390a4565b909173ffffffffffffffffffffffffffffffffffffffff7f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb916136d76040519283921695339583613b07565b90805183519081810361242557505060005b81518110156137ab578060019160051b84602080838701015192880101519173ffffffffffffffffffffffffffffffffffffffff821661377e575b5050500161373a565b6137a1916135bc613799926000526002602052604060002090565b91825461315e565b9055388481613775565b508051919392916001036138665760208181015183820151604080519283529282015273ffffffffffffffffffffffffffffffffffffffff86169160009133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291a45b73ffffffffffffffffffffffffffffffffffffffff84166138305750505050565b8051600103613857579060208061384e959301519101519133613eea565b38808080611e2e565b6138619333613c0a565b61384e565b604051600073ffffffffffffffffffffffffffffffffffffffff8616917f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb3391806138b2888883613b07565b0390a461380f565b94919091815184519081810361242557505060005b82518110156139ed578060051b90602080838601015192870101518573ffffffffffffffffffffffffffffffffffffffff93848b16613941575b600194821661391c575b505050016138cf565b613937916135bc613799926000526002602052604060002090565b9055388581613913565b919293905061395e8a6135bc846000526002602052604060002090565b5483811061399057918791846001969594036139888d6135bc856000526002602052604060002090565b559450613909565b6040517f03dee4c500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8c16600482015260248101919091526044810184905260648101839052608490fd5b509491939290936001855114600014613ab15760208581015183820151604080519283529282015273ffffffffffffffffffffffffffffffffffffffff838116929086169133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291a45b73ffffffffffffffffffffffffffffffffffffffff8116613a7a575050505050565b8451600103613aa057602080613a969601519201519233613f38565b388080808061201f565b613aac94919233613d8f565b613a96565b73ffffffffffffffffffffffffffffffffffffffff604051818316918516907f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb339180613aff888c83613b07565b0390a4613a58565b9091613b1e6104a793604084526040840190610bcb565b916020818403910152610bcb565b9081602091031261020e57516104a781610316565b92613b7e6104a7959373ffffffffffffffffffffffffffffffffffffffff613b8c941686526000602087015260a0604087015260a0860190610bcb565b908482036060860152610bcb565b916080818403910152610453565b93906104a79593613b7e91613b8c9473ffffffffffffffffffffffffffffffffffffffff809216885216602087015260a0604087015260a0860190610bcb565b3d15613c05573d90613beb82610974565b91613bf9604051938461089b565b82523d6000602084013e565b606090565b9293919093843b613c1c575050505050565b602091613c5860405194859384937fbc197c81000000000000000000000000000000000000000000000000000000009889865260048601613b41565b0381600073ffffffffffffffffffffffffffffffffffffffff88165af160009181613d5e575b50613ce35782613c8c613bda565b8051919082613cdc576040517f57f447ce00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83166004820152602490fd5b9050602001fd5b7fffffffff000000000000000000000000000000000000000000000000000000001603613d155750388080808061201f565b6040517f57f447ce00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff919091166004820152602490fd5b613d8191925060203d602011613d88575b613d79818361089b565b810190613b2c565b9038613c7e565b503d613d6f565b939290949194853b613da4575b505050505050565b613de060209360405195869485947fbc197c8100000000000000000000000000000000000000000000000000000000998a875260048701613b9a565b0381600073ffffffffffffffffffffffffffffffffffffffff88165af160009181613e47575b50613e145782613c8c613bda565b7fffffffff000000000000000000000000000000000000000000000000000000001603613d155750388080808080613d9c565b613e6191925060203d602011613d8857613d79818361089b565b9038613e06565b909260a09273ffffffffffffffffffffffffffffffffffffffff6104a7969516835260006020840152604083015260608201528160808201520190610453565b91926104a795949160a09473ffffffffffffffffffffffffffffffffffffffff8092168552166020840152604083015260608201528160808201520190610453565b9293919093843b613efc575050505050565b602091613c5860405194859384937ff23a6e61000000000000000000000000000000000000000000000000000000009889865260048601613e68565b939290949194853b613f4c57505050505050565b613de060209360405195869485947ff23a6e6100000000000000000000000000000000000000000000000000000000998a875260048701613ea8565b90613fc75750805115613f9d57805190602001fd5b60046040517f1425ea42000000000000000000000000000000000000000000000000000000008152fd5b8151158061401f575b613fd8575090565b60249073ffffffffffffffffffffffffffffffffffffffff604051917f9996b315000000000000000000000000000000000000000000000000000000008352166004820152fd5b50803b15613fd056fea26469706673582212205d4134c57528bf1900466c0c9311e70dd3071ca49cfc57c0f322cbd82b2e94e064736f6c63430008180033
Verified Source Code Partial Match
Compiler: v0.8.24+commit.e11b9ed9
EVM: paris
Optimization: Yes (100000 runs)
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Ownable2Step.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
draft-IERC6093.sol 161 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 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 ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-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 ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 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);
}
IERC1155.sol 127 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the value of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155Received} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external;
}
IERC1155Receiver.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
IERC1155MetadataURI.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.20;
import {IERC1155} from "../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*/
interface IERC1155MetadataURI is IERC1155 {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
Arrays.sol 127 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Arrays.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using StorageSlot for bytes32;
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* `array` is expected to be sorted in ascending order, and to contain no
* repeated elements.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
}
Base64.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.2) (utils/Base64.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to operate with Base64 strings.
*/
library Base64 {
/**
* @dev Base64 Encoding/Decoding Table
*/
string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* @dev Converts a `bytes` to its Bytes64 `string` representation.
*/
function encode(bytes memory data) internal pure returns (string memory) {
/**
* Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
* https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
*/
if (data.length == 0) return "";
// Loads the table into memory
string memory table = _TABLE;
// Encoding takes 3 bytes chunks of binary data from `bytes` data parameter
// and split into 4 numbers of 6 bits.
// The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up
// - `data.length + 2` -> Round up
// - `/ 3` -> Number of 3-bytes chunks
// - `4 *` -> 4 characters for each chunk
string memory result = new string(4 * ((data.length + 2) / 3));
/// @solidity memory-safe-assembly
assembly {
// Prepare the lookup table (skip the first "length" byte)
let tablePtr := add(table, 1)
// Prepare result pointer, jump over length
let resultPtr := add(result, 0x20)
let dataPtr := data
let endPtr := add(data, mload(data))
// In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
// set it to zero to make sure no dirty bytes are read in that section.
let afterPtr := add(endPtr, 0x20)
let afterCache := mload(afterPtr)
mstore(afterPtr, 0x00)
// Run over the input, 3 bytes at a time
for {
} lt(dataPtr, endPtr) {
} {
// Advance 3 bytes
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
// To write each character, shift the 3 byte (24 bits) chunk
// 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
// and apply logical AND with 0x3F to bitmask the least significant 6 bits.
// Use this as an index into the lookup table, mload an entire word
// so the desired character is in the least significant byte, and
// mstore8 this least significant byte into the result and continue.
mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
}
// Reset the value that was cached
mstore(afterPtr, afterCache)
// When data `bytes` is not exactly 3 bytes long
// it is padded with `=` characters at the end
switch mod(mload(data), 3)
case 1 {
mstore8(sub(resultPtr, 1), 0x3d)
mstore8(sub(resultPtr, 2), 0x3d)
}
case 2 {
mstore8(sub(resultPtr, 1), 0x3d)
}
}
return result;
}
}
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;
}
}
StorageSlot.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
Strings.sol 94 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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 ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
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.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
ERC1155.sol 399 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import { IERC1155MetadataURI } from "@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
import { IERC165, ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import { Arrays } from "@openzeppelin/contracts/utils/Arrays.sol";
import { IERC1155Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
/**
* @dev Minimal implementation of the basic standard multi-token based on the OpenZeppelin contracts.
* See https://eips.ethereum.org/EIPS/eip-1155
*/
abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors, Ownable2Step {
using Arrays for uint256[];
using Arrays for address[];
mapping(uint256 id => mapping(address account => uint256)) private _balances;
mapping(address account => mapping(address operator => bool)) private _operatorApprovals;
constructor() Ownable(msg.sender) {}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256 /* id */) external view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC1155-balanceOf}.
*/
function balanceOf(address account, uint256 id) public view virtual returns (uint256) {
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
) public view virtual returns (uint256[] memory) {
if (accounts.length != ids.length) {
revert ERC1155InvalidArrayLength(ids.length, accounts.length);
}
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts.unsafeMemoryAccess(i), ids.unsafeMemoryAccess(i));
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeTransferFrom(from, to, id, value, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeBatchTransferFrom(from, to, ids, values, data);
}
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from`
* (or `to`) is the zero address.
*
* Emits a {TransferSingle} event if the arrays contain one element, and {TransferBatch} otherwise.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement either {IERC1155Receiver-onERC1155Received}
* or {IERC1155Receiver-onERC1155BatchReceived} and return the acceptance magic value.
* - `ids` and `values` must have the same length.
*
* NOTE: The ERC-1155 acceptance check is not performed in this function. See {_updateWithAcceptanceCheck} instead.
*/
function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal virtual {
if (ids.length != values.length) {
revert ERC1155InvalidArrayLength(ids.length, values.length);
}
address operator = _msgSender();
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids.unsafeMemoryAccess(i);
uint256 value = values.unsafeMemoryAccess(i);
if (from != address(0)) {
uint256 fromBalance = _balances[id][from];
if (fromBalance < value) {
revert ERC1155InsufficientBalance(from, fromBalance, value, id);
}
unchecked {
// Overflow not possible: value <= fromBalance
_balances[id][from] = fromBalance - value;
}
}
if (to != address(0)) {
_balances[id][to] += value;
}
}
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
emit TransferSingle(operator, from, to, id, value);
} else {
emit TransferBatch(operator, from, to, ids, values);
}
}
/**
* @dev Version of {_update} that performs the token acceptance check by calling
* {IERC1155Receiver-onERC1155Received} or {IERC1155Receiver-onERC1155BatchReceived} on the receiver address if it
* contains code (eg. is a smart contract at the moment of execution).
*
* IMPORTANT: Overriding this function is discouraged because it poses a reentrancy risk from the receiver. So any
* update to the contract state after this function would break the check-effect-interaction pattern. Consider
* overriding {_update} instead.
*/
function _updateWithAcceptanceCheck(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal virtual {
_update(from, to, ids, values);
if (to != address(0)) {
address operator = _msgSender();
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
_doSafeTransferAcceptanceCheck(operator, from, to, id, value, data);
} else {
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, values, data);
}
}
}
/**
* @dev Transfers a `value` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
* - `ids` and `values` must have the same length.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev Creates a `value` amount of tokens of type `id`, and assigns them to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
/**
* @dev Destroys a `value` amount of tokens of type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
*/
function _burn(address from, uint256 id, uint256 value) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the zero address.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC1155InvalidOperator(address(0));
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Performs an acceptance check by calling {IERC1155-onERC1155Received} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 value,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Performs a batch acceptance check by calling {IERC1155-onERC1155BatchReceived} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Creates an array in memory with only one value for each of the elements provided.
*/
function _asSingletonArrays(
uint256 element1,
uint256 element2
) private pure returns (uint256[] memory array1, uint256[] memory array2) {
/// @solidity memory-safe-assembly
assembly {
// Load the free memory pointer
array1 := mload(0x40)
// Set array length to 1
mstore(array1, 1)
// Store the single element at the next word after the length (where content starts)
mstore(add(array1, 0x20), element1)
// Repeat for next array locating it right after the first array
array2 := add(array1, 0x40)
mstore(array2, 1)
mstore(add(array2, 0x20), element2)
// Update the free memory pointer by pointing after the second array
mstore(0x40, add(array2, 0x40))
}
}
}
MintViaERC20.sol 265 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { ERC1155 } from "./ERC1155.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IRenderer } from "./interfaces/IRenderer.sol";
import { ContractMetadata } from "./libraries/ContractMetadata.sol";
import { SSTORE2 } from "./libraries/SSTORE2.sol";
import { Token } from "./types/Token.sol";
/// @notice To mint is a human right, with ERC20 tokens.
/// @author Visualize Value
contract MintViaERC20 is ERC1155 {
using SafeERC20 for IERC20;
/// @notice Inaugural ERC20 version
uint public constant version = 11001000110000;
/// @notice Holds information about this collection.
ContractMetadata.Data private metadata;
/// @notice Holds the metadata for each token within this collection.
mapping(uint => Token) private tokens;
/// @notice The token metadata renderers registered with this collection.
address[] public renderers;
/// @notice The most recently minted token id.
uint public latestTokenId;
/// @notice Ethereum block height of when this collection was created.
uint public initBlock;
/// @notice Each mint is open for 24 hours.
uint constant MINT_DURATION = 24 hours;
/// @notice Payment configuration for tokens
struct PaymentConfig {
address token; // ERC20 token address
uint256 price; // Price in the token's smallest unit
}
/// @notice Payment configuration for each token
mapping(uint => PaymentConfig) public payments;
/// @dev Emitted when the artist registers a new Renderer contract.
event NewRenderer(address indexed renderer, uint indexed index);
/// @dev Emitted when a collector mints a token. Price arg used for UI backwards compat.
event NewMint(uint indexed tokenId, uint mintPrice, uint amount, address minter);
/// @dev Emitted when the artist withdraws tokens from the contract.
event Withdrawal(address indexed token, uint amount);
/// @dev Thrown on the attempt to reinitialize the contract.
error Initialized();
/// @dev Thrown when trying to mint a piece after the mint window.
error MintClosed();
/// @dev Thrown when trying to mint a non existent token.
error NonExistentToken();
/// @dev Thrown when trying to change an existing token.
error TokenAlreadyMinted();
/// @dev Thrown when trying to create a token with a non existent renderer assigned.
error NonExistentRenderer();
/// @dev Thrown when the withdrawal fails.
error WithdrawalFailed();
/// @dev Thrown when the ERC20 transfer fails.
error ERC20TransferFailed();
/// @dev Thrown when payment token is invalid (zero address).
error InvalidPaymentToken();
/// @notice Initializes the collection contract.
function init(
string calldata contractName,
string calldata contractSymbol,
string calldata contractDescription,
bytes[] calldata contractImage,
address renderer,
address owner
) external {
if (initBlock > 0) revert Initialized();
// Initialize with metadata.
metadata.name = contractName;
metadata.symbol = contractSymbol;
metadata.description = contractDescription;
// Write the contract image to storage.
for (uint8 i = 0; i < contractImage.length; i++) {
metadata.image.push(SSTORE2.write(contractImage[i]));
}
// Set the initial renderer
renderers.push(renderer);
// Setting the initialization block height prevents reinitialization
initBlock = block.number;
_transferOwnership(owner);
}
/// @notice Lets the artist create a new token with ERC20 payment.
function create(
string calldata tokenName,
string calldata tokenDescription,
bytes[] calldata tokenArtifact,
uint32 tokenRenderer,
uint128 tokenData,
address paymentToken,
uint256 price
) public onlyOwner {
if (renderers.length < tokenRenderer + 1) revert NonExistentRenderer();
if (paymentToken == address(0)) revert InvalidPaymentToken();
++ latestTokenId;
Token storage token = tokens[latestTokenId];
token.name = tokenName;
token.description = tokenDescription;
token.mintedBlock = uint32(block.number);
token.closeAt = uint64(block.timestamp + MINT_DURATION);
token.renderer = tokenRenderer;
token.data = tokenData;
// Set payment config for this token
payments[latestTokenId] = PaymentConfig({
token: paymentToken,
price: price
});
if (tokenArtifact.length > 0) {
// Clear previously prepared artifact data.
if (token.artifact.length > 0) {
delete token.artifact;
}
// Write the token artifact to storage.
for (uint8 i = 0; i < tokenArtifact.length; i++) {
token.artifact.push(SSTORE2.write(tokenArtifact[i]));
}
}
_mint(msg.sender, latestTokenId, 1, "");
}
/// @notice Lets the artist prepare artifacts that are too large to store in a single transaction.
function prepareArtifact(uint tokenId, bytes[] calldata tokenArtifact, bool clear) external onlyOwner {
if (tokenId <= latestTokenId) revert TokenAlreadyMinted();
Token storage token = tokens[tokenId];
if (token.artifact.length > 0 && clear) { delete token.artifact; }
// Write the token artifact to storage.
for (uint8 i = 0; i < tokenArtifact.length; i++) {
token.artifact.push(SSTORE2.write(tokenArtifact[i]));
}
}
/// @notice Get the bare token data for a given id.
function get(uint tokenId) external view returns (
string memory name,
string memory description,
address[] memory artifact,
uint32 renderer,
uint32 mintedBlock,
uint64 closeAt,
uint128 data
) {
Token storage token = tokens[tokenId];
return (
token.name,
token.description,
token.artifact,
token.renderer,
token.mintedBlock,
token.closeAt,
token.data
);
}
/// @notice Get the payment configuration for a token.
function getPaymentConfig(uint tokenId) external view returns (address token, uint256 price) {
if (tokenId > latestTokenId) revert NonExistentToken();
PaymentConfig storage config = payments[tokenId];
return (config.token, config.price);
}
/// @notice Lets collectors purchase a token during its mint window.
function mint(uint tokenId, uint amount) external {
if (tokenId > latestTokenId) revert NonExistentToken();
if (mintOpenUntil(tokenId) < block.timestamp) revert MintClosed();
PaymentConfig storage config = payments[tokenId];
uint mintPrice = config.price * amount;
// Transfer ERC20 tokens from the sender to this contract using SafeERC20
IERC20(config.token).safeTransferFrom(msg.sender, address(this), mintPrice);
_mint(msg.sender, tokenId, amount, "");
emit NewMint(tokenId, mintPrice, amount, msg.sender);
}
/// @notice Check until when a mint is open.
function mintOpenUntil(uint tokenId) public view returns (uint) {
return tokens[tokenId].closeAt;
}
/// @notice Lets the artist register a new renderer to use for future mints.
function registerRenderer(address renderer) external onlyOwner returns (uint) {
renderers.push(renderer);
uint index = renderers.length - 1;
emit NewRenderer(renderer, index);
return index;
}
/// @notice Lets the artist withdraw specific ERC20 tokens from the contract.
function withdraw(address token) external onlyOwner {
if (token == address(0)) revert InvalidPaymentToken();
uint balance = IERC20(token).balanceOf(address(this));
if (balance == 0) return;
// Use SafeERC20 for transfer
IERC20(token).safeTransfer(owner(), balance);
emit Withdrawal(token, balance);
}
/// @notice Get the metadata for a given token id.
function uri(uint tokenId) external override view returns (string memory) {
if (tokenId > latestTokenId) revert NonExistentToken();
Token memory token = tokens[tokenId];
return IRenderer(renderers[token.renderer]).uri(tokenId, token);
}
/// @notice Get the metadata for this collection contract.
function contractURI() public view returns (string memory) {
return ContractMetadata.uri(metadata);
}
/// @notice Burn a given token & amount.
function burn(address account, uint256 tokenId, uint256 amount) external {
if (account != msg.sender && !isApprovedForAll(account, msg.sender)) {
revert ERC1155MissingApprovalForAll(msg.sender, account);
}
_burn(account, tokenId, amount);
}
}
IRenderer.sol 16 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { Token } from "../types/Token.sol";
interface IRenderer {
function name () external pure returns (string memory);
function version () external pure returns (uint version);
function uri (uint tokenId, Token calldata token) external view returns (string memory);
function imageURI (uint tokenId, Token calldata token) external view returns (string memory);
function animationURI (uint tokenId, Token calldata token) external view returns (string memory);
}
ContractMetadata.sol 41 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol";
import { SSTORE2 } from "./SSTORE2.sol";
library ContractMetadata {
struct Data {
string name;
string symbol;
string description;
address[] image;
}
function uri (Data memory data) external view returns (string memory) {
bytes memory dataURI = abi.encodePacked(
'{',
'"name": "', data.name, '",',
'"symbol": "', data.symbol, '",',
'"description": "', data.description, '",',
'"image": "', image(data), '"',
'}'
);
return string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(dataURI)
)
);
}
function image (Data memory data) internal view returns (bytes memory content) {
for (uint8 i = 0; i < data.image.length; i++) {
content = abi.encodePacked(content, SSTORE2.read(data.image[i]));
}
}
}
SSTORE2.sol 101 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Read and write to persistent storage at a fraction of the cost.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SSTORE2.sol)
/// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol)
library SSTORE2 {
uint256 internal constant DATA_OFFSET = 1; // We skip the first byte as it's a STOP opcode to ensure the contract can't be called.
/*//////////////////////////////////////////////////////////////
WRITE LOGIC
//////////////////////////////////////////////////////////////*/
function write(bytes memory data) internal returns (address pointer) {
// Prefix the bytecode with a STOP opcode to ensure it cannot be called.
bytes memory runtimeCode = abi.encodePacked(hex"00", data);
bytes memory creationCode = abi.encodePacked(
//---------------------------------------------------------------------------------------------------------------//
// Opcode | Opcode + Arguments | Description | Stack View //
//---------------------------------------------------------------------------------------------------------------//
// 0x60 | 0x600B | PUSH1 11 | codeOffset //
// 0x59 | 0x59 | MSIZE | 0 codeOffset //
// 0x81 | 0x81 | DUP2 | codeOffset 0 codeOffset //
// 0x38 | 0x38 | CODESIZE | codeSize codeOffset 0 codeOffset //
// 0x03 | 0x03 | SUB | (codeSize - codeOffset) 0 codeOffset //
// 0x80 | 0x80 | DUP | (codeSize - codeOffset) (codeSize - codeOffset) 0 codeOffset //
// 0x92 | 0x92 | SWAP3 | codeOffset (codeSize - codeOffset) 0 (codeSize - codeOffset) //
// 0x59 | 0x59 | MSIZE | 0 codeOffset (codeSize - codeOffset) 0 (codeSize - codeOffset) //
// 0x39 | 0x39 | CODECOPY | 0 (codeSize - codeOffset) //
// 0xf3 | 0xf3 | RETURN | //
//---------------------------------------------------------------------------------------------------------------//
hex"60_0B_59_81_38_03_80_92_59_39_F3", // Returns all code in the contract except for the first 11 (0B in hex) bytes.
runtimeCode // The bytecode we want the contract to have after deployment. Capped at 1 byte less than the code size limit.
);
/// @solidity memory-safe-assembly
assembly {
// Deploy a new contract with the generated creation code.
// We start 32 bytes into the code to avoid copying the byte length.
pointer := create(0, add(creationCode, 32), mload(creationCode))
}
require(pointer != address(0), "DEPLOYMENT_FAILED");
}
/*//////////////////////////////////////////////////////////////
READ LOGIC
//////////////////////////////////////////////////////////////*/
function read(address pointer) internal view returns (bytes memory) {
return readBytecode(pointer, DATA_OFFSET, pointer.code.length - DATA_OFFSET);
}
function read(address pointer, uint256 start) internal view returns (bytes memory) {
start += DATA_OFFSET;
return readBytecode(pointer, start, pointer.code.length - start);
}
function read(
address pointer,
uint256 start,
uint256 end
) internal view returns (bytes memory) {
start += DATA_OFFSET;
end += DATA_OFFSET;
require(pointer.code.length >= end, "OUT_OF_BOUNDS");
return readBytecode(pointer, start, end - start);
}
/*//////////////////////////////////////////////////////////////
INTERNAL HELPER LOGIC
//////////////////////////////////////////////////////////////*/
function readBytecode(
address pointer,
uint256 start,
uint256 size
) private view returns (bytes memory data) {
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
data := mload(0x40)
// Update the free memory pointer to prevent overriding our data.
// We use and(x, not(31)) as a cheaper equivalent to sub(x, mod(x, 32)).
// Adding 31 to size and running the result through the logic above ensures
// the memory pointer remains word-aligned, following the Solidity convention.
mstore(0x40, add(data, and(add(add(size, 32), 31), not(31))))
// Store the size of the data in the first 32 byte chunk of free memory.
mstore(data, size)
// Copy the code into memory right after the 32 bytes we used to store the size.
extcodecopy(pointer, add(data, 32), start, size)
}
}
}
Token.sol 12 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
struct Token {
string name; // token name
string description; // token description
address[] artifact; // artifact pointers (image/artwork) data
uint32 renderer; // index of renderer contract address
uint32 mintedBlock; // creation block height of the token
uint64 closeAt; // timestamp of mint completion
uint128 data; // optional data for renderers
}
Read Contract
balanceOf 0x00fdd58e → uint256
balanceOfBatch 0x4e1273f4 → uint256[]
contractURI 0xe8a3d485 → string
get 0x9507d39a → string, string, address[], uint32, uint32, uint64, uint128
getPaymentConfig 0xc6229698 → address, uint256
initBlock 0x5d05125b → uint256
isApprovedForAll 0xe985e9c5 → bool
latestTokenId 0x8c0e8349 → uint256
mintOpenUntil 0xb5644341 → uint256
owner 0x8da5cb5b → address
payments 0x87d81789 → address, uint256
pendingOwner 0xe30c3978 → address
renderers 0x1ffbee64 → address
supportsInterface 0x01ffc9a7 → bool
uri 0x0e89341c → string
version 0x54fd4d50 → uint256
Write Contract 13 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
burn 0xf5298aca
address account
uint256 tokenId
uint256 amount
create 0xa38d9349
string tokenName
string tokenDescription
bytes[] tokenArtifact
uint32 tokenRenderer
uint128 tokenData
address paymentToken
uint256 price
init 0x84252fb7
string contractName
string contractSymbol
string contractDescription
bytes[] contractImage
address renderer
address owner
mint 0x1b2ef1ca
uint256 tokenId
uint256 amount
prepareArtifact 0xb6cb8dfe
uint256 tokenId
bytes[] tokenArtifact
bool clear
registerRenderer 0xc4a0d465
address renderer
returns: uint256
renounceOwnership 0x715018a6
No parameters
safeBatchTransferFrom 0x2eb2c2d6
address from
address to
uint256[] ids
uint256[] values
bytes data
safeTransferFrom 0xf242432a
address from
address to
uint256 id
uint256 value
bytes data
setApprovalForAll 0xa22cb465
address operator
bool approved
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x51cff8d9
address token
Recent Transactions
No transactions found for this address