Address Contract Partially Verified
Address
0x614d5475FE81ef4b6Dd8093b5C73EfEEE03167e0
Balance
0 ETH
Nonce
2
Code Size
24568 bytes
Creator
0x1d05cf6c...5ad6 at tx 0x6e54a6b9...86faf9
Indexed Transactions
0
Contract Bytecode
24568 bytes
0x60806040526004361061039b5760003560e01c806370a08231116101dc578063b88d4fde11610102578063eb5c60f2116100a0578063f4e638be1161006f578063f4e638be14610b93578063fa35e4e214610bbb578063fbfa77cf14610bdb578063fe43658d14610bfb57600080fd5b8063eb5c60f214610af6578063eee608a414610b23578063f07e7fd014610b53578063f2fde38b14610b7357600080fd5b8063dc78ac1c116100dc578063dc78ac1c14610a62578063e8a3d48514610a82578063e91e13a914610a97578063e985e9c514610aad57600080fd5b8063b88d4fde14610a0d578063b9b8311a14610a2d578063c87b56dd14610a4257600080fd5b80638ef79e911161017a578063a07c7ce411610149578063a07c7ce41461099e578063a22cb465146109b8578063ab221792146109d8578063b66a0e5d146109f857600080fd5b80638ef79e9114610925578063926ce44e1461094557806395d89b41146109725780639cd7d65c1461098757600080fd5b80637f06ee06116101b65780637f06ee061461088d5780638462151c146108ba5780638cba1c67146108e75780638da5cb5b1461090757600080fd5b806370a0823114610838578063715018a614610858578063771ac3031461086d57600080fd5b806332f37c2e116102c1578063504c05ea1161025f57806363e602301161022e57806363e602301461079757806365a46e08146107d85780636817031b146107f85780636c19e7831461081857600080fd5b8063504c05ea14610714578063530da8ef1461074357806355367ba9146107625780636352211e1461077757600080fd5b806341a5626a1161029b57806341a5626a1461069e57806342842e0e146106be5780634bf365df146106de5780634e99b800146106ff57600080fd5b806332f37c2e1461064957806333e364cb146106695780633c352b0d1461067e57600080fd5b8063167ddf6e1161033957806323aed2281161030857806323aed228146105d857806323b872dd146105f65780632977e4b3146106165780632f745c591461062957600080fd5b8063167ddf6e1461053b57806318160ddd1461057657806321fe0c641461059a578063238ac933146105ba57600080fd5b8063081812fc11610375578063081812fc146104a3578063095ea7b3146104db578063114ba8ee146104fb5780631623528f1461051b57600080fd5b806301ffc9a71461042c578063031205061461046157806306fdde031461048157600080fd5b3661042757600e546001600160a01b031633146104255760405162461bcd60e51b815260206004820152603c60248201527f466572616c66696c6545786869626974696f6e56343a206f6e6c79206163636560448201527f70742066756e642066726f6d207661756c7420636f6e74726163742e0000000060648201526084015b60405180910390fd5b005b600080fd5b34801561043857600080fd5b5061044c6104473660046149dd565b610c1b565b60405190151581526020015b60405180910390f35b34801561046d57600080fd5b5061042561047c366004614a1d565b610c6d565b34801561048d57600080fd5b50610496610c96565b6040516104589190614a88565b3480156104af57600080fd5b506104c36104be366004614a9b565b610d28565b6040516001600160a01b039091168152602001610458565b3480156104e757600080fd5b506104256104f6366004614ab4565b610d4f565b34801561050757600080fd5b50610425610516366004614a1d565b610d68565b34801561052757600080fd5b50610425610536366004614a1d565b610d92565b34801561054757600080fd5b5061055b610556366004614a9b565b610e3b565b60408051825181526020928301519281019290925201610458565b34801561058257600080fd5b5061058c600c5481565b604051908152602001610458565b3480156105a657600080fd5b506104256105b5366004614bb2565b610e9e565b3480156105c657600080fd5b506009546001600160a01b03166104c3565b3480156105e457600080fd5b50600d5462010000900460ff1661044c565b34801561060257600080fd5b50610425610611366004614be6565b610f88565b610425610624366004614c22565b610fdb565b34801561063557600080fd5b5061058c610644366004614ab4565b611618565b34801561065557600080fd5b50610425610664366004614cda565b6116c2565b34801561067557600080fd5b50610425611851565b34801561068a57600080fd5b50610425610699366004614cda565b611914565b3480156106aa57600080fd5b506104256106b9366004614cda565b611aad565b3480156106ca57600080fd5b506104256106d9366004614be6565b611c91565b3480156106ea57600080fd5b50600d5461044c906301000000900460ff1681565b34801561070b57600080fd5b50610496611cde565b34801561072057600080fd5b5061073461072f366004614a9b565b611d6c565b60405161045893929190614d45565b34801561074f57600080fd5b50600d5461044c90610100900460ff1681565b34801561076e57600080fd5b50610425611f26565b34801561078357600080fd5b506104c3610792366004614a9b565b611fda565b3480156107a357600080fd5b506104966040518060400160405280601581526020017411995c985b199a5b19515e1a1a589a5d1a5bdb958d605a1b81525081565b3480156107e457600080fd5b506104256107f3366004614d7e565b61200f565b34801561080457600080fd5b50610425610813366004614a1d565b61230d565b34801561082457600080fd5b50610425610833366004614a1d565b6123a3565b34801561084457600080fd5b5061058c610853366004614a1d565b61242e565b34801561086457600080fd5b506104256124b4565b34801561087957600080fd5b50610425610888366004614e3f565b6124c8565b34801561089957600080fd5b5061058c6108a8366004614a9b565b60009081526010602052604090205490565b3480156108c657600080fd5b506108da6108d5366004614a1d565b6126e5565b6040516104589190614eba565b3480156108f357600080fd5b50610425610902366004614efe565b612751565b34801561091357600080fd5b506006546001600160a01b03166104c3565b34801561093157600080fd5b50610425610940366004614ff2565b612880565b34801561095157600080fd5b5061058c610960366004614a1d565b60146020526000908152604090205481565b34801561097e57600080fd5b506104966128ef565b34801561099357600080fd5b5061058c6201194081565b3480156109aa57600080fd5b50600d5461044c9060ff1681565b3480156109c457600080fd5b506104256109d336600461503f565b6128fe565b3480156109e457600080fd5b506104966109f3366004614a9b565b612912565b348015610a0457600080fd5b5061042561295f565b348015610a1957600080fd5b50610425610a28366004615076565b61297c565b348015610a3957600080fd5b506104256129ca565b348015610a4e57600080fd5b50610496610a5d366004614a9b565b612a6b565b348015610a6e57600080fd5b50610425610a7d366004614a1d565b612d7d565b348015610a8e57600080fd5b50610496612da9565b348015610aa357600080fd5b5061058c615dc081565b348015610ab957600080fd5b5061044c610ac83660046150f1565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b348015610b0257600080fd5b5061058c610b11366004614a9b565b6000908152600f602052604090205490565b348015610b2f57600080fd5b5061044c610b3e366004614a1d565b60076020526000908152604090205460ff1681565b348015610b5f57600080fd5b506008546104c3906001600160a01b031681565b348015610b7f57600080fd5b50610425610b8e366004614a1d565b612db6565b348015610b9f57600080fd5b50600d546104c39064010000000090046001600160a01b031681565b348015610bc757600080fd5b50610425610bd6366004614cda565b612e2f565b348015610be757600080fd5b50600e546104c3906001600160a01b031681565b348015610c0757600080fd5b50610496610c16366004614a9b565b613029565b60006001600160e01b031982166380ac58cd60e01b1480610c4c57506001600160e01b03198216635b5e139f60e01b145b80610c6757506301ffc9a760e01b6001600160e01b03198316145b92915050565b610c75613042565b6001600160a01b03166000908152600760205260409020805460ff19169055565b606060008054610ca590615124565b80601f0160208091040260200160405190810160405280929190818152602001828054610cd190615124565b8015610d1e5780601f10610cf357610100808354040283529160200191610d1e565b820191906000526020600020905b815481529060010190602001808311610d0157829003601f168201915b5050505050905090565b6000610d338261309c565b506000908152600460205260409020546001600160a01b031690565b81610d59816130c1565b610d638383613193565b505050565b610d70613042565b600880546001600160a01b0319166001600160a01b0392909216919091179055565b610d9a613042565b6001600160a01b038116610e0d5760405162461bcd60e51b815260206004820152603460248201527f466572616c66696c6545786869626974696f6e56343a20636f737452656365696044820152737665725f206973207a65726f206164647265737360601b606482015260840161041c565b600d80546001600160a01b0390921664010000000002640100000000600160c01b0319909216919091179055565b6040805180820190915260008082526020820152610e58826132a3565b610e745760405162461bcd60e51b815260040161041c90615158565b50600090815260116020908152604091829020825180840190935280548352600101549082015290565b600d5460ff16610f055760405162461bcd60e51b815260206004820152602c60248201527f466572616c66696c6545786869626974696f6e56343a20746f6b656e2069732060448201526b6e6f74206275726e61626c6560a01b606482015260840161041c565b60005b8151811015610f8457610f3433838381518110610f2757610f2761518f565b60200260200101516132c0565b610f505760405162461bcd60e51b815260040161041c906151a5565b610f72828281518110610f6557610f6561518f565b602002602001015161333f565b80610f7c81615208565b915050610f08565b5050565b826001600160a01b0381163314610fa257610fa2336130c1565b306001600160a01b03841603610fca5760405162461bcd60e51b815260040161041c90615221565b610fd5848484613415565b50505050565b600d5462010000900460ff166110465760405162461bcd60e51b815260206004820152602a60248201527f466572616c66696c6545786869626974696f6e56343a2073616c65206973206e6044820152691bdd081cdd185c9d195960b21b606482015260840161041c565b61104e613446565b611057816134c1565b61106760e0820160c0830161527e565b6110d657803534146110d15760405162461bcd60e51b815260206004820152602d60248201527f466572616c66696c6545786869626974696f6e56343a20696e76616c6964207060448201526c185e5b595b9d08185b5bdd5b9d609a1b606482015260840161041c565b61113f565b600e54604051632eeee16360e01b81526001600160a01b0390911690632eeee1639061110c908790879087908790600401615487565b600060405180830381600087803b15801561112657600080fd5b505af115801561113a573d6000803e3d6000fd5b505050505b6000463083604051602001611156939291906154af565b60405160208183030381529060405280519060200120905061117a8186868661361a565b61119757604051638baa579f60e01b815260040160405180910390fd5b60006020830135833511156111d1576111b360808401846154e2565b90506111c46020850135853561552b565b6111ce919061553e565b90505b60008060005b6111e460808701876154e2565b90508110156115385761123a306112016080890160608a01614a1d565b61120e60808a018a6154e2565b8581811061121e5761121e61518f565b9050602002013560405180602001604052806000815250613672565b600061124960a08801886154e2565b838181106112595761125961518f565b905060200281019061126b9190615560565b808060200260200160405190810160405280939291908181526020016000905b828210156112b7576112a8604083028601368190038101906155a9565b8152602001906001019061128b565b50505050509050600085905060005b8251811080156112d65750600082115b156113bb576000601460008584815181106112f3576112f361518f565b6020026020010151600001516001600160a01b03166001600160a01b031681526020019081526020016000205490506000838210156113325781611334565b835b905061134081886155ff565b965080601460008786815181106113595761135961518f565b6020026020010151600001516001600160a01b03166001600160a01b031681526020019081526020016000206000828254611394919061552b565b909155506113a49050818561552b565b9350505080806113b390615208565b9150506112c6565b5080156114b75760005b82518110156114b55760008382815181106113e2576113e261518f565b602002602001015160000151905060006127108584815181106114075761140761518f565b6020026020010151602001518561141e9190615612565b611428919061553e565b600d549091506001600160a01b0364010000000090910481169083160361145c5761145381886155ff565b965050506114a3565b61146681896155ff565b6040519098506001600160a01b0383169082156108fc029083906000818181858888f1935050505015801561149f573d6000803e3d6000fd5b5050505b806114ad81615208565b9150506113c5565b505b6114c460808901896154e2565b848181106114d4576114d461518f565b905060200201358860600160208101906114ee9190614a1d565b6001600160a01b03167f0475389cd69b8d3163620b43283bf74e8fc71020c3c6cef2a529b5c405e9687f60405160405180910390a35050808061153090615208565b9150506111d7565b5061154381836155ff565b6115526020870135873561552b565b10156115b55760405162461bcd60e51b815260206004820152602c60248201527f466572616c66696c6545786869626974696f6e56343a20746f74616c2062707360448201526b0206f7665722031302c3030360a41b606482015260840161041c565b60006115c283873561552b565b9050801561160d57600d546040516401000000009091046001600160a01b0316906108fc8315029083906000818181858888f1935050505015801561160b573d6000803e3d6000fd5b505b505050505050505050565b60006116238361242e565b82106116855760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b606482015260840161041c565b6001600160a01b03831660009081526012602052604090208054839081106116af576116af61518f565b9060005260206000200154905092915050565b3360009081526007602052604090205460ff16806116ea57506006546001600160a01b031633145b6116f357600080fd5b8281146117135760405163ab3a7f9960e01b815260040160405180910390fd5b60005b8181101561175b576117538383838181106117335761173361518f565b90506020028101906117459190615629565b61174e90615649565b6136a5565b600101611716565b506117668484613708565b60005b8381101561184a578282828181106117835761178361518f565b90506020028101906117959190615629565b601760008787858181106117ab576117ab61518f565b90506020020135815260200190815260200160002081816117cc9190615855565b9050508484828181106117e1576117e161518f565b905060200201357fac24f5d052fdb3e47d0446513e40bbf8afcfd59e1bd778f60c1f53da4212ead684848481811061181b5761181b61518f565b905060200281019061182d9190615629565b60405161183a91906159bc565b60405180910390a2600101611769565b5050505050565b611859613042565b600d546301000000900460ff16156118835760405162461bcd60e51b815260040161041c90615a32565b600d5462010000900460ff16156118f95760405162461bcd60e51b815260206004820152603460248201527f466572616c66696c6545786869626974696f6e56343a205f73656c6c696e6720604482015273726571756972656420746f2062652066616c736560601b606482015260840161041c565b611901613446565b600d805462ff0000191662010000179055565b61191c613042565b82811461193c576040516313086eff60e21b815260040160405180910390fd5b60005b8381101561184a57600085858381811061195b5761195b61518f565b90506020020160208101906119709190614a1d565b6001600160a01b03160361199757604051630107349760e51b815260040160405180910390fd5b8282828181106119a9576119a961518f565b905060200201356000036119d057604051636745f8fb60e01b815260040160405180910390fd5b6000601460008787858181106119e8576119e861518f565b90506020020160208101906119fd9190614a1d565b6001600160a01b03166001600160a01b03168152602001908152602001600020541115611a3d576040516328547bdf60e01b815260040160405180910390fd5b828282818110611a4f57611a4f61518f565b9050602002013560146000878785818110611a6c57611a6c61518f565b9050602002016020810190611a819190614a1d565b6001600160a01b0316815260208101919091526040016000205580611aa581615208565b91505061193f565b611ab5613042565b828114611ad5576040516313086eff60e21b815260040160405180910390fd5b60005b8381101561184a576000838383818110611af457611af461518f565b9050602002016020810190611b099190614a1d565b6001600160a01b031603611b3057604051630107349760e51b815260040160405180910390fd5b600060146000858585818110611b4857611b4861518f565b9050602002016020810190611b5d9190614a1d565b6001600160a01b03166001600160a01b03168152602001908152602001600020541115611b9d576040516328547bdf60e01b815260040160405180910390fd5b60146000868684818110611bb357611bb361518f565b9050602002016020810190611bc89190614a1d565b6001600160a01b03166001600160a01b031681526020019081526020016000205460146000858585818110611bff57611bff61518f565b9050602002016020810190611c149190614a1d565b6001600160a01b03166001600160a01b031681526020019081526020016000208190555060146000868684818110611c4e57611c4e61518f565b9050602002016020810190611c639190614a1d565b6001600160a01b03168152602081019190915260400160009081205580611c8981615208565b915050611ad8565b826001600160a01b0381163314611cab57611cab336130c1565b306001600160a01b03841603611cd35760405162461bcd60e51b815260040161041c90615221565b610fd58484846137fa565b600a8054611ceb90615124565b80601f0160208091040260200160405190810160405280929190818152602001828054611d1790615124565b8015611d645780601f10611d3957610100808354040283529160200191611d64565b820191906000526020600020905b815481529060010190602001808311611d4757829003601f168201915b505050505081565b601760205260009081526040902080548190611d8790615124565b80601f0160208091040260200160405190810160405280929190818152602001828054611db390615124565b8015611e005780601f10611dd557610100808354040283529160200191611e00565b820191906000526020600020905b815481529060010190602001808311611de357829003601f168201915b505050505090806001018054611e1590615124565b80601f0160208091040260200160405190810160405280929190818152602001828054611e4190615124565b8015611e8e5780601f10611e6357610100808354040283529160200191611e8e565b820191906000526020600020905b815481529060010190602001808311611e7157829003601f168201915b505050505090806002018054611ea390615124565b80601f0160208091040260200160405190810160405280929190818152602001828054611ecf90615124565b8015611f1c5780601f10611ef157610100808354040283529160200191611f1c565b820191906000526020600020905b815481529060010190602001808311611eff57829003601f168201915b5050505050905083565b611f2e613042565b600d546301000000900460ff1615611f585760405162461bcd60e51b815260040161041c90615a32565b600d5462010000900460ff16611fcc5760405162461bcd60e51b815260206004820152603360248201527f466572616c66696c6545786869626974696f6e56343a205f73656c6c696e6720604482015272726571756972656420746f206265207472756560681b606482015260840161041c565b600d805462ff000019169055565b6000818152600260205260408120546001600160a01b031680610c675760405162461bcd60e51b815260040161041c90615158565b612017613042565b60008251118015612029575060008151115b6120a95760405162461bcd60e51b815260206004820152604560248201527f466572616c66696c6545786869626974696f6e56343a2073657269657349647360448201527f206f7220726563697069656e74416464726573736573206c656e677468206973606482015264207a65726f60d81b608482015260a40161041c565b80518251146121355760405162461bcd60e51b815260206004820152604c60248201527f466572616c66696c6545786869626974696f6e56343a2073657269657349647360448201527f206c656e67746820697320646966666572656e742066726f6d2072656369706960648201526b656e7441646472657373657360a01b608482015260a40161041c565b61213d611f26565b3060008181526012602090815260408083208054825181850281018501909352808352919290919083018282801561219457602002820191906000526020600020905b815481526020019060010190808311612180575b5050505050905060005b81518110156122905760008282815181106121bb576121bb61518f565b602090810291909101810151600081815260118352604080822081518083019092528054825260010154938101939093529092505b87518161ffff16101561227a57878161ffff16815181106122135761221361518f565b6020026020010151826000015103612268576000878261ffff168151811061223d5761223d61518f565b6020026020010151905061226287828660405180602001604052806000815250613672565b5061227a565b8061227281615a86565b9150506121f0565b505050808061228890615208565b91505061219e565b5061229a8261242e565b15610fd55760405162461bcd60e51b815260206004820152603c60248201527f466572616c66696c6545786869626974696f6e56343a20546f6b656e20666f7260448201527f2073616c652062616c616e63652068617320746f206265207a65726f00000000606482015260840161041c565b612315613042565b6001600160a01b0381166123815760405162461bcd60e51b815260206004820152602d60248201527f466572616c66696c6545786869626974696f6e56343a207661756c745f20697360448201526c207a65726f206164647265737360981b606482015260840161041c565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b6123ab613042565b6001600160a01b03811661240c5760405162461bcd60e51b815260206004820152602260248201527f45434453415369676e3a207369676e65725f206973207a65726f206164647265604482015261737360f01b606482015260840161041c565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b60006001600160a01b0382166124985760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b606482015260840161041c565b506001600160a01b031660009081526003602052604090205490565b6124bc613042565b6124c66000613815565b565b3360009081526007602052604090205460ff16806124f057506006546001600160a01b031633145b6124f957600080fd5b6000838152600f6020526040902054839061252a57604051630e17b51760e41b81526004810182905260240161041c565b600082900361254c576040516328f5a3ff60e01b815260040160405180910390fd5b6201194082111561257057604051635d3c714b60e11b815260040160405180910390fd5b600084815260156020526040902054156125c757600084815260156020526040812061259b91614995565b60405184907f5642c40d50e2073be9e5183e69e9c92f89328520b1a18fcd0d109b25434bd9d290600090a25b60005b828110156126945760006125de828561552b565b9050615dc08111156125ef5750615dc05b600061264886848761260186836155ff565b9261260e93929190615aa7565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061386792505050565b60008881526015602090815260408220805460018101825590835291200180546001600160a01b0319166001600160a01b038316179055905061268b82846155ff565b925050506125ca565b847f0bfaeb43f2350d013eaed4cf979fcf8c33f3471f9a6a69b312882034d3134bbb601560008881526020019081526020016000206040516126d69190615ad1565b60405180910390a25050505050565b6001600160a01b03811660009081526012602090815260409182902080548351818402810184019094528084526060939283018282801561274557602002820191906000526020600020905b815481526020019060010190808311612731575b50505050509050919050565b3360009081526007602052604090205460ff168061277957506006546001600160a01b031633145b61278257600080fd5b600d546301000000900460ff166127f95760405162461bcd60e51b815260206004820152603560248201527f466572616c66696c6545786869626974696f6e56343a20636f6e747261637420604482015274191bd95cdb89dd08185b1b1bddc81d1bc81b5a5b9d605a1b606482015260840161041c565b60005b81811015610d635761286e8383838181106128195761281961518f565b905060600201600001358484848181106128355761283561518f565b905060600201602001358585858181106128515761285161518f565b90506060020160400160208101906128699190614a1d565b6138c6565b8061287881615208565b9150506127fc565b612888613042565b60008151116128e35760405162461bcd60e51b815260206004820152602160248201527f4552433732314d657461646174613a20626173655552495f20697320656d70746044820152607960f81b606482015260840161041c565b600a610f848282615b15565b606060018054610ca590615124565b81612908816130c1565b610d638383613a48565b60608161292d816000908152600f6020526040902054151590565b61294d57604051630e17b51760e41b81526004810182905260240161041c565b61295683613a53565b91505b50919050565b612967613042565b600d805463ff000000191690556124c6611851565b836001600160a01b038116331461299657612996336130c1565b306001600160a01b038516036129be5760405162461bcd60e51b815260040161041c90615221565b61184a85858585613b33565b6129d2613042565b6129da611f26565b30600090815260126020908152604080832080548251818502810185019093528083529192909190830182828015612a3157602002820191906000526020600020905b815481526020019060010190808311612a1d575b5050505050905060005b8151811015610f8457612a59828281518110610f6557610f6561518f565b80612a6381615208565b915050612a3b565b6060612a76826132a3565b612a965760405163401e26ff60e01b81526004810183905260240161041c565b600082815260116020526040902054612abd81600090815260156020526040902054151590565b612aca5761295683613b65565b6000612ad582613a53565b9050600060176000868152602001908152602001600020604051806060016040529081600082018054612b0790615124565b80601f0160208091040260200160405190810160405280929190818152602001828054612b3390615124565b8015612b805780601f10612b5557610100808354040283529160200191612b80565b820191906000526020600020905b815481529060010190602001808311612b6357829003601f168201915b50505050508152602001600182018054612b9990615124565b80601f0160208091040260200160405190810160405280929190818152602001828054612bc590615124565b8015612c125780601f10612be757610100808354040283529160200191612c12565b820191906000526020600020905b815481529060010190602001808311612bf557829003601f168201915b50505050508152602001600282018054612c2b90615124565b80601f0160208091040260200160405190810160405280929190818152602001828054612c5790615124565b8015612ca45780601f10612c7957610100808354040283529160200191612ca4565b820191906000526020600020905b815481529060010190602001808311612c8757829003601f168201915b50505050508152505090506000601660008581526020019081526020016000208260400151604051602001612cda929190615c41565b60408051601f198184030181529082905260208401518451636b985f3160e01b845291935073c26220de03166947e9cfc170a03da09ecc5b646592636b985f3192612d2e9288929091908790600401615c73565b600060405180830381865af4158015612d4b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612d739190810190615cfb565b9695505050505050565b612d85613042565b6001600160a01b03166000908152600760205260409020805460ff19166001179055565b600b8054611ceb90615124565b612dbe613042565b6001600160a01b038116612e235760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161041c565b612e2c81613815565b50565b3360009081526007602052604090205460ff1680612e5757506006546001600160a01b031633145b612e6057600080fd5b828114612e805760405163ab3a7f9960e01b815260040160405180910390fd5b60005b83811015612f3a57828282818110612e9d57612e9d61518f565b9050602002810190612eaf91906156f3565b9050600003612ed157604051634f45b8fd60e01b815260040160405180910390fd5b612f32838383818110612ee657612ee661518f565b9050602002810190612ef891906156f3565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613c7392505050565b600101612e83565b50612f458484613d03565b60005b8381101561184a57828282818110612f6257612f6261518f565b9050602002810190612f7491906156f3565b60166000888886818110612f8a57612f8a61518f565b9050602002013581526020019081526020016000209182612fac92919061579c565b50848482818110612fbf57612fbf61518f565b905060200201357fa4154606c7e38a6a299a31a214bf3468d191c48e6308a1e849932d2c5aba56b9848484818110612ff957612ff961518f565b905060200281019061300b91906156f3565b604051613019929190615d43565b60405180910390a2600101612f48565b60166020526000908152604090208054611ceb90615124565b6006546001600160a01b031633146124c65760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161041c565b6130a5816132a3565b612e2c5760405162461bcd60e51b815260040161041c90615158565b6008546001600160a01b03163b15612e2c57600854604051633185c44d60e21b81523060048201526001600160a01b0383811660248301529091169063c617113490604401602060405180830381865afa158015613123573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131479190615d57565b612e2c5760405162461bcd60e51b815260206004820152601760248201527f6f70657261746f72206973206e6f7420616c6c6f776564000000000000000000604482015260640161041c565b600061319e82611fda565b9050806001600160a01b0316836001600160a01b03160361320b5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b606482015260840161041c565b336001600160a01b038216148061322757506132278133610ac8565b6132995760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c000000606482015260840161041c565b610d638383613dee565b6000908152600260205260409020546001600160a01b0316151590565b6000806132cc83611fda565b9050806001600160a01b0316846001600160a01b0316148061331357506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b806133375750836001600160a01b031661332c84610d28565b6001600160a01b0316145b949350505050565b613348816132a3565b6133645760405162461bcd60e51b815260040161041c90615158565b600081815260116020908152604080832081518083018352815480825260019283015482860152855260109093529083208054929391929091906133a990849061552b565b925050819055506001600c60008282546133c3919061552b565b90915550506000828152601160205260408120818155600101556133e682613e5c565b60405182907fbde7938970372996ff103863625e348ef2bf8f38a5b02181be75aafef17c23d590600090a25050565b61341f33826132c0565b61343b5760405162461bcd60e51b815260040161041c906151a5565b610d63838383613eff565b60006134513061242e565b905060008111612e2c5760405162461bcd60e51b815260206004820152603560248201527f466572616c66696c6545786869626974696f6e56343a204e6f20746f6b656e206044820152741bdddb995908189e481d1a194818dbdb9d1c9858dd605a1b606482015260840161041c565b60006134d060808301836154e2565b90501161352b5760405162461bcd60e51b8152602060048201526024808201527f466572616c66696c6553616c65446174613a20746f6b656e49647320697320656044820152636d70747960e01b606482015260840161041c565b61353860a08201826154e2565b905061354760808301836154e2565b9050146135bc5760405162461bcd60e51b815260206004820152603d60248201527f466572616c66696c6553616c65446174613a20746f6b656e49647320616e642060448201527f726576656e7565536861726573206c656e677468206d69736d61746368000000606482015260840161041c565b42816040013511612e2c5760405162461bcd60e51b815260206004820152602260248201527f466572616c66696c6553616c65446174613a2073616c65206973206578706972604482015261195960f21b606482015260840161041c565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c859052603c8120819061365790848787614070565b6009546001600160a01b039081169116149695505050505050565b61367d848484613eff565b61368984848484614098565b610fd55760405162461bcd60e51b815260040161041c90615d74565b80515115806136b75750602081015151155b806136c55750604081015151155b156136e357604051634f45b8fd60e01b815260040160405180910390fd5b80516136ee90613c73565b6136fb8160200151613c73565b612e2c8160400151613c73565b600081900361372a576040516316ee9d3b60e11b815260040160405180910390fd5b60005b81811015610d635761375683838381811061374a5761374a61518f565b905060200201356132a3565b61378f5782828281811061376c5761376c61518f565b9050602002013560405163401e26ff60e01b815260040161041c91815260200190565b6137d5601160008585858181106137a8576137a861518f565b90506020020135815260200190815260200160002060000154600090815260156020526040902054151590565b6137f25760405163466fcd5560e11b815260040160405180910390fd5b60010161372d565b610d638383836040518060200160405280600081525061297c565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000806138928360405160200161387e9190615dc6565b604051602081830303815290604052614196565b90508051602082016000f091506001600160a01b0382166129595760405163046a55db60e11b815260040160405180910390fd5b6000838152600f602052604090205415156138e0846141ac565b6040516020016138f09190615dec565b6040516020818303038152906040529061391d5760405162461bcd60e51b815260040161041c9190614a88565b506000838152600f6020908152604080832054601090925290912054106139985760405162461bcd60e51b815260206004820152602960248201527f466572616c66696c6545786869626974696f6e56343a206e6f20736c6f747320604482015268617661696c61626c6560b81b606482015260840161041c565b6001600c60008282546139ab91906155ff565b909155505060008381526010602052604081208054600192906139cf9084906155ff565b9091555050604080518082018252848152602080820185815260008681526011909252929020905181559051600190910155613a0b818361423f565b8183826001600160a01b03167f407d7da1d3b2b1871fbfa2b5b1c4657a3cc5711d3023c552798551c7ee301eea60405160405180910390a4505050565b610f843383836143ba565b600081815260156020908152604091829020805483518184028101840190945280845260609392830182828015613ab357602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613a95575b5050604051630b09269f60e41b8152738930d48776b7ff4797bf56f3c43f5bed43912aad9463b09269f09450613aee93509150600401615e49565b600060405180830381865af4158015613b0b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c679190810190615cfb565b613b3d33836132c0565b613b595760405162461bcd60e51b815260040161041c906151a5565b610fd584848484613672565b60606000600a8054613b7690615124565b905011613bd45760405162461bcd60e51b815260206004820152602660248201527f4552433732314d657461646174613a205f746f6b656e4261736555524920697360448201526520656d70747960d01b606482015260840161041c565b613bdd826132a3565b613c415760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b606482015260840161041c565b600a613c4c836141ac565b604051602001613c5d929190615e8a565b6040516020818303038152906040529050919050565b8060005b8151811015610d63576000828281518110613c9457613c9461518f565b01602001516001600160f81b0319169050601160f91b811480613cc45750601760fa1b6001600160f81b03198216145b80613cdc5750600160fd1b6001600160f81b03198216105b15613cfa5760405163a2a50ced60e01b815260040160405180910390fd5b50600101613c77565b6000819003613d25576040516316ee9d3b60e11b815260040160405180910390fd5b60005b81811015610d6357613d60838383818110613d4557613d4561518f565b905060200201356000908152600f6020526040902054151590565b613d9957828282818110613d7657613d7661518f565b90506020020135604051630e17b51760e41b815260040161041c91815260200190565b613dc9838383818110613dae57613dae61518f565b90506020020135600090815260156020526040902054151590565b613de65760405163466fcd5560e11b815260040160405180910390fd5b600101613d28565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190613e2382611fda565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000613e6782611fda565b9050613e77816000846001614488565b613e8082611fda565b600083815260046020908152604080832080546001600160a01b03199081169091556001600160a01b0385168085526003845282852080546000190190558785526002909352818420805490911690555192935084927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b826001600160a01b0316613f1282611fda565b6001600160a01b031614613f385760405162461bcd60e51b815260040161041c90615eb0565b6001600160a01b038216613f9a5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b606482015260840161041c565b613fa78383836001614488565b826001600160a01b0316613fba82611fda565b6001600160a01b031614613fe05760405162461bcd60e51b815260040161041c90615eb0565b600081815260046020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260038552838620805460001901905590871680865283862080546001019055868652600290945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60008060006140818787878761459f565b9150915061408e81614663565b5095945050505050565b60006001600160a01b0384163b1561418e57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906140dc903390899088908890600401615ef5565b6020604051808303816000875af1925050508015614117575060408051601f3d908101601f1916820190925261411491810190615f28565b60015b614174573d808015614145576040519150601f19603f3d011682016040523d82523d6000602084013e61414a565b606091505b50805160000361416c5760405162461bcd60e51b815260040161041c90615d74565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050613337565b506001613337565b6060815182604051602001613c5d929190615f45565b606060006141b9836147ad565b60010190506000816001600160401b038111156141d8576141d8614ade565b6040519080825280601f01601f191660200182016040528015614202576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461420c575b509392505050565b6001600160a01b0382166142955760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604482015260640161041c565b61429e816132a3565b156142eb5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015260640161041c565b6142f9600083836001614488565b614302816132a3565b1561434f5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015260640161041c565b6001600160a01b038216600081815260036020908152604080832080546001019055848352600290915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b816001600160a01b0316836001600160a01b03160361441b5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604482015260640161041c565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b60018111156144f75760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b606482015260840161041c565b816001600160a01b038516158015906145225750836001600160a01b0316856001600160a01b031614155b15614531576145318582614885565b6001600160a01b0384161580159061455b5750846001600160a01b0316846001600160a01b031614155b1561184a576001600160a01b03841660009081526012602090815260408083208054600181018255908452828420810185905584845260139092529091205561184a565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156145d6575060009050600361465a565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561462a573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166146535760006001925092505061465a565b9150600090505b94509492505050565b600081600481111561467757614677615f96565b0361467f5750565b600181600481111561469357614693615f96565b036146e05760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161041c565b60028160048111156146f4576146f4615f96565b036147415760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161041c565b600381600481111561475557614755615f96565b03612e2c5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b606482015260840161041c565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106147ec5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310614818576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061483657662386f26fc10000830492506010015b6305f5e100831061484e576305f5e100830492506008015b612710831061486257612710830492506004015b60648310614874576064830492506002015b600a8310610c675760010192915050565b600060016148928461242e565b61489c919061552b565b600083815260136020526040902054909150808214614943576001600160a01b03841660009081526012602052604081208054849081106148df576148df61518f565b906000526020600020015490508060126000876001600160a01b03166001600160a01b0316815260200190815260200160002083815481106149235761492361518f565b600091825260208083209091019290925591825260139052604090208190555b60008381526013602090815260408083208390556001600160a01b03871683526012909152902080548061497957614979615fac565b6001900381819060005260206000200160009055905550505050565b5080546000825590600052602060002090810190612e2c91905b808211156149c357600081556001016149af565b5090565b6001600160e01b031981168114612e2c57600080fd5b6000602082840312156149ef57600080fd5b81356149fa816149c7565b9392505050565b80356001600160a01b0381168114614a1857600080fd5b919050565b600060208284031215614a2f57600080fd5b6149fa82614a01565b60005b83811015614a53578181015183820152602001614a3b565b50506000910152565b60008151808452614a74816020860160208601614a38565b601f01601f19169290920160200192915050565b6020815260006149fa6020830184614a5c565b600060208284031215614aad57600080fd5b5035919050565b60008060408385031215614ac757600080fd5b614ad083614a01565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715614b1c57614b1c614ade565b604052919050565b60006001600160401b03821115614b3d57614b3d614ade565b5060051b60200190565b600082601f830112614b5857600080fd5b81356020614b6d614b6883614b24565b614af4565b82815260059290921b84018101918181019086841115614b8c57600080fd5b8286015b84811015614ba75780358352918301918301614b90565b509695505050505050565b600060208284031215614bc457600080fd5b81356001600160401b03811115614bda57600080fd5b61333784828501614b47565b600080600060608486031215614bfb57600080fd5b614c0484614a01565b9250614c1260208501614a01565b9150604084013590509250925092565b60008060008060808587031215614c3857600080fd5b8435935060208501359250604085013560ff81168114614c5757600080fd5b915060608501356001600160401b03811115614c7257600080fd5b850160e08188031215614c8457600080fd5b939692955090935050565b60008083601f840112614ca157600080fd5b5081356001600160401b03811115614cb857600080fd5b6020830191508360208260051b8501011115614cd357600080fd5b9250929050565b60008060008060408587031215614cf057600080fd5b84356001600160401b0380821115614d0757600080fd5b614d1388838901614c8f565b90965094506020870135915080821115614d2c57600080fd5b50614d3987828801614c8f565b95989497509550505050565b606081526000614d586060830186614a5c565b8281036020840152614d6a8186614a5c565b90508281036040840152612d738185614a5c565b60008060408385031215614d9157600080fd5b82356001600160401b0380821115614da857600080fd5b614db486838701614b47565b9350602091508185013581811115614dcb57600080fd5b85019050601f81018613614dde57600080fd5b8035614dec614b6882614b24565b81815260059190911b82018301908381019088831115614e0b57600080fd5b928401925b82841015614e3057614e2184614a01565b82529284019290840190614e10565b80955050505050509250929050565b600080600060408486031215614e5457600080fd5b8335925060208401356001600160401b0380821115614e7257600080fd5b818601915086601f830112614e8657600080fd5b813581811115614e9557600080fd5b876020828501011115614ea757600080fd5b6020830194508093505050509250925092565b6020808252825182820181905260009190848201906040850190845b81811015614ef257835183529284019291840191600101614ed6565b50909695505050505050565b60008060208385031215614f1157600080fd5b82356001600160401b0380821115614f2857600080fd5b818501915085601f830112614f3c57600080fd5b813581811115614f4b57600080fd5b866020606083028501011115614f6057600080fd5b60209290920196919550909350505050565b60006001600160401b03821115614f8b57614f8b614ade565b50601f01601f191660200190565b6000614fa7614b6884614f72565b9050828152838383011115614fbb57600080fd5b828260208301376000602084830101529392505050565b600082601f830112614fe357600080fd5b6149fa83833560208501614f99565b60006020828403121561500457600080fd5b81356001600160401b0381111561501a57600080fd5b61333784828501614fd2565b8015158114612e2c57600080fd5b8035614a1881615026565b6000806040838503121561505257600080fd5b61505b83614a01565b9150602083013561506b81615026565b809150509250929050565b6000806000806080858703121561508c57600080fd5b61509585614a01565b93506150a360208601614a01565b92506040850135915060608501356001600160401b038111156150c557600080fd5b8501601f810187136150d657600080fd5b6150e587823560208401614f99565b91505092959194509250565b6000806040838503121561510457600080fd5b61510d83614a01565b915061511b60208401614a01565b90509250929050565b600181811c9082168061513857607f821691505b60208210810361295957634e487b7160e01b600052602260045260246000fd5b60208082526018908201527f4552433732313a20696e76616c696420746f6b656e2049440000000000000000604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6020808252602d908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526c1c881bdc88185c1c1c9bdd9959609a1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b60006001820161521a5761521a6151f2565b5060010190565b6020808252603e908201527f466572616c66696c6545786869626974696f6e56343a20436f6e74726163742060408201527f69736e277420616c6c6f77656420746f207265636569766520746f6b656e0000606082015260800190565b60006020828403121561529057600080fd5b81356149fa81615026565b6000808335601e198436030181126152b257600080fd5b83016020810192503590506001600160401b038111156152d157600080fd5b8060051b3603821315614cd357600080fd5b8183526000602080850194508260005b85811015615329576001600160a01b0361530c83614a01565b1687528183013583880152604096870196909101906001016152f3565b509495945050505050565b60008383855260208086019550808560051b8301018460005b878110156153bf57848303601f19018952813536889003601e1901811261537357600080fd5b870184810190356001600160401b0381111561538e57600080fd5b8060061b36038213156153a057600080fd5b6153ab8582846152e3565b9a86019a945050509083019060010161534d565b5090979650505050505050565b8035825260208082013590830152604080820135908301526001600160a01b036153f860608301614a01565b166060830152600061540d608083018361529b565b60e06080860181905285018190526101006001600160fb1b0382111561543257600080fd5b8160051b9150818382880137818601925061545060a086018661529b565b9250818785030160a08801526154698285018483615334565b935050505061547a60c08401615034565b80151560c0860152614237565b84815283602082015260ff83166040820152608060608201526000612d7360808301846153cc565b8381526001600160a01b03831660208201526060604082018190526000906154d9908301846153cc565b95945050505050565b6000808335601e198436030181126154f957600080fd5b8301803591506001600160401b0382111561551357600080fd5b6020019150600581901b3603821315614cd357600080fd5b81810381811115610c6757610c676151f2565b60008261555b57634e487b7160e01b600052601260045260246000fd5b500490565b6000808335601e1984360301811261557757600080fd5b8301803591506001600160401b0382111561559157600080fd5b6020019150600681901b3603821315614cd357600080fd5b6000604082840312156155bb57600080fd5b604051604081018181106001600160401b03821117156155dd576155dd614ade565b6040526155e983614a01565b8152602083013560208201528091505092915050565b80820180821115610c6757610c676151f2565b8082028115828204841417610c6757610c676151f2565b60008235605e1983360301811261563f57600080fd5b9190910192915050565b60006060823603121561565b57600080fd5b604051606081016001600160401b03828210818311171561567e5761567e614ade565b81604052843591508082111561569357600080fd5b61569f36838701614fd2565b835260208501359150808211156156b557600080fd5b6156c136838701614fd2565b602084015260408501359150808211156156da57600080fd5b506156e736828601614fd2565b60408301525092915050565b6000808335601e1984360301811261570a57600080fd5b8301803591506001600160401b0382111561572457600080fd5b602001915036819003821315614cd357600080fd5b601f821115610d6357600081815260208120601f850160051c810160208610156157605750805b601f850160051c820191505b8181101561577f5782815560010161576c565b505050505050565b600019600383901b1c191660019190911b1790565b6001600160401b038311156157b3576157b3614ade565b6157c7836157c18354615124565b83615739565b6000601f8411600181146157f557600085156157e35750838201355b6157ed8682615787565b84555061184a565b600083815260209020601f19861690835b828110156158265786850135825560209485019460019092019101615806565b50868210156158435760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b61585f82836156f3565b6001600160401b0381111561587657615876614ade565b61588a816158848554615124565b85615739565b6000601f8211600181146158b857600083156158a65750838201355b6158b08482615787565b865550615912565b600085815260209020601f19841690835b828110156158e957868501358255602094850194600190920191016158c9565b50848210156159065760001960f88660031b161c19848701351681555b505060018360011b0185555b5050505061592360208301836156f3565b61593181836001860161579c565b505061594060408301836156f3565b610fd581836002860161579c565b6000808335601e1984360301811261596557600080fd5b83016020810192503590506001600160401b0381111561598457600080fd5b803603821315614cd357600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6020815260006159cc838461594e565b606060208501526159e1608085018284615993565b9150506159f1602085018561594e565b601f1980868503016040870152615a09848385615993565b9350615a18604088018861594e565b935091508086850301606087015250612d73838383615993565b60208082526034908201527f466572616c66696c6545786869626974696f6e56343a206d696e7461626c6520604082015273726571756972656420746f2062652066616c736560601b606082015260800190565b600061ffff808316818103615a9d57615a9d6151f2565b6001019392505050565b60008085851115615ab757600080fd5b83861115615ac457600080fd5b5050820193919092039150565b6020808252825482820181905260008481528281209092916040850190845b81811015614ef25783546001600160a01b031683526001938401939285019201615af0565b81516001600160401b03811115615b2e57615b2e614ade565b615b4281615b3c8454615124565b84615739565b602080601f831160018114615b715760008415615b5f5750858301515b615b698582615787565b86555061577f565b600085815260208120601f198616915b82811015615ba057888601518255948401946001909101908401615b81565b5085821015615bbe5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60008154615bdb81615124565b60018281168015615bf35760018114615c0857615c37565b60ff1984168752821515830287019450615c37565b8560005260208060002060005b85811015615c2e5781548a820152908401908201615c15565b50505082870194505b5050505092915050565b6000615c4d8285615bce565b600160fd1b81528351615c67816001840160208801614a38565b01600101949350505050565b608081526000615c866080830187614a5c565b8281036020840152615c988187614a5c565b90508281036040840152615cac8186614a5c565b90508281036060840152615cc08185614a5c565b979650505050505050565b6000615cd9614b6884614f72565b9050828152838383011115615ced57600080fd5b6149fa836020830184614a38565b600060208284031215615d0d57600080fd5b81516001600160401b03811115615d2357600080fd5b8201601f81018413615d3457600080fd5b61333784825160208401615ccb565b602081526000613337602083018486615993565b600060208284031215615d6957600080fd5b81516149fa81615026565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6000815260008251615ddf816001850160208701614a38565b9190910160010192915050565b7f466572616c66696c6545786869626974696f6e56343a2073657269657349642081526e03237b2b9b713ba1032bc34b9ba1d1608d1b602082015260008251615e3c81602f850160208701614a38565b91909101602f0192915050565b6020808252825182820181905260009190848201906040850190845b81811015614ef25783516001600160a01b031683529284019291840191600101615e65565b6000615e968285615bce565b602f60f81b81528351615c67816001840160208801614a38565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612d7390830184614a5c565b600060208284031215615f3a57600080fd5b81516149fa816149c7565b606360f81b815260e083901b6001600160e01b03191660018201526880600e6000396000f360b81b60058201528151600090615f8881600e850160208701614a38565b91909101600e019392505050565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603160045260246000fdfea26469706673582212206fa676be15fae8af8ffc9d9219e258e54c569d7a2bc236749c70f9b42fb913d364736f6c63430008110033
Verified Source Code Partial Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: Yes (200 runs)
FeralfileArtworkV4_4.sol 375 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {FeralfileExhibitionV4_1} from "./FeralfileArtworkV4_1.sol";
import {SSTORE2} from "@0xsequence/sstore2/contracts/SSTORE2.sol";
import {RendererStorageV0} from "./RendererStorageV0.sol";
import {LibBytes} from "./LibBytes.sol";
/**
* @title FeralfileExhibitionV4_4
* @author Feral File
* @notice Advanced NFT exhibition contract with on-chain metadata rendering capabilities.
* Extends FeralfileExhibitionV4_1 to support dynamic token metadata generation using SSTORE2-stored HTML/JavaScript renderers,
* enabling fully decentralized generative and interactive digital art with immutable on-chain storage.
* @dev This contract extends FeralfileExhibitionV4_1 with on-chain renderer functionality.
* Uses SSTORE2 for efficient storage of renderer code (up to 72KB) in 24KB chunks.
* Supports both traditional IPFS metadata tokens and renderer-based tokens within the same exhibition.
* Renderer tokens require series-level renderer code, series names, and token-specific rendering data (imageURI, textureURI, tokenName) to generate dynamic metadata.
*/
contract FeralfileExhibitionV4_4 is FeralfileExhibitionV4_1 {
using RendererStorageV0 for bytes;
using LibBytes for address[];
//----------------------------------------------------------
// Constants
//----------------------------------------------------------
uint256 public constant CHUNK_SIZE = 24000; // Single SSTORE2 write up to 24,576 bytes
uint256 public constant RENDERER_BLOB_MAX_SIZE = 72000; // 3x CHUNK_SIZE (24,000) costs around 15.5M gas as target block gas limit
//----------------------------------------------------------
// Structs
//----------------------------------------------------------
struct RendererTokenData {
string imageURI;
string textureURI;
string tokenName;
}
//----------------------------------------------------------
// Errors
//----------------------------------------------------------
error ErrSeriesDoesNotExist(uint256 seriesId);
error ErrTokenDoesNotExist(uint256 tokenId);
error ErrLengthMismatch();
error ErrEmptyArray();
error ErrEmptyString();
error ErrEmptyBytes();
error ErrSeriesHasNoRenderer();
error ErrRendererBlobTooLarge();
error ErrUnsupportedCharacters();
//----------------------------------------------------------
// Events
//----------------------------------------------------------
event NewSeriesName(uint256 indexed seriesId, string name);
event NewSeriesRenderer(uint256 indexed seriesId, address[] pointers);
event DeleteSeriesRenderer(uint256 indexed seriesId);
event NewRendererTokenData(uint256 indexed tokenId, RendererTokenData data);
//----------------------------------------------------------
// State Variables
//----------------------------------------------------------
/**
* @dev A mapping of series IDs to a list of addresses that can be used to render the series
*/
mapping(uint256 => address[]) private _seriesRendererPointers;
/**
* @dev A mapping of series IDs to the name of the series
*/
mapping(uint256 => string) public seriesNames;
/**
* @dev A mapping of token IDs to the data used to render the token
*/
mapping(uint256 => RendererTokenData) public rendererTokenData;
constructor(
string memory name_,
string memory symbol_,
bool burnable_,
bool bridgeable_,
address signer_,
address vault_,
address costReceiver_,
string memory contractURI_,
uint256[] memory seriesIds_,
uint256[] memory seriesMaxSupplies_
)
FeralfileExhibitionV4_1(
name_,
symbol_,
burnable_,
bridgeable_,
signer_,
vault_,
costReceiver_,
contractURI_,
seriesIds_,
seriesMaxSupplies_
)
{}
//----------------------------------------------------------
// Modifiers
//----------------------------------------------------------
modifier seriesExists(uint256 seriesId) {
if (!_checkSeriesExists(seriesId)) {
revert ErrSeriesDoesNotExist(seriesId);
}
_;
}
//----------------------------------------------------------
// External Functions
//----------------------------------------------------------
/// @notice Set the series renderer for a series
/// @param seriesId The series ID to set
/// @param blob The renderer bytes
function setSeriesRenderer(
uint256 seriesId,
bytes calldata blob
) external onlyAuthorized seriesExists(seriesId) {
if (blob.length == 0) {
revert ErrEmptyBytes();
}
if (blob.length > RENDERER_BLOB_MAX_SIZE) {
revert ErrRendererBlobTooLarge();
}
// cleanup the old renderer
if (_seriesRendererPointers[seriesId].length > 0) {
delete _seriesRendererPointers[seriesId];
emit DeleteSeriesRenderer(seriesId);
}
// store the new renderer
uint256 offset = 0;
while (offset < blob.length) {
uint256 len = blob.length - offset;
if (len > CHUNK_SIZE) len = CHUNK_SIZE;
// copy slice to new bytes
address ptr = SSTORE2.write(blob[offset:offset + len]);
_seriesRendererPointers[seriesId].push(ptr);
offset += len;
}
emit NewSeriesRenderer(seriesId, _seriesRendererPointers[seriesId]);
}
/// @notice Get the series renderer from the SSTORE2 pointers
/// @param seriesId The series ID to read
/// @return renderer The renderer bytes
function getSeriesRenderer(
uint256 seriesId
) external view seriesExists(seriesId) returns (string memory) {
return string(_readSeriesRenderer(seriesId));
}
/// @notice Get the token URI
/// @param tokenId The token ID to read
/// @return uri The token URI
function tokenURI(
uint256 tokenId
) public view override returns (string memory) {
// validate token exists
if (!_exists(tokenId)) {
revert ErrTokenDoesNotExist(tokenId);
}
// validate token is a renderer token
uint256 seriesId = _allArtworks[tokenId].seriesId;
if (!_hasRenderer(seriesId)) {
return super.tokenURI(tokenId);
}
// read renderer
bytes memory renderer = _readSeriesRenderer(seriesId);
RendererTokenData memory data = rendererTokenData[tokenId];
string memory name = string(
abi.encodePacked(seriesNames[seriesId], " ", data.tokenName)
);
return renderer.tokenURI(data.textureURI, data.imageURI, name);
}
/// @notice Set the names for a list of series IDs
/// @param seriesIds The series IDs to set
/// @param names The names to set
function setSeriesNames(
uint256[] calldata seriesIds,
string[] calldata names
) external onlyAuthorized {
// validate lengths match
if (seriesIds.length != names.length) {
revert ErrLengthMismatch();
}
for (uint256 i = 0; i < seriesIds.length; ) {
// validate name is not empty
if (bytes(names[i]).length == 0) {
revert ErrEmptyString();
}
// validate name does not contain unsupported characters
checkForUnsupportedCharacters(names[i]);
unchecked {
++i;
}
}
// validate series exists and has a renderer
_validateRendererSeries(seriesIds);
// set names
for (uint256 i = 0; i < seriesIds.length; ) {
seriesNames[seriesIds[i]] = names[i];
// emit event
emit NewSeriesName(seriesIds[i], names[i]);
unchecked {
++i;
}
}
}
/// @notice Set the renderer token data for a list of token IDs
/// @param tokenIds The token IDs to set
/// @param data The renderer token data to set
function setRendererTokenData(
uint256[] calldata tokenIds,
RendererTokenData[] calldata data
) external onlyAuthorized {
// validate lengths match
if (tokenIds.length != data.length) {
revert ErrLengthMismatch();
}
for (uint256 i = 0; i < data.length; ) {
// validate token data is not empty
_validateRendererTokenData(data[i]);
unchecked {
++i;
}
}
// validate tokens are renderer tokens
_validateRendererTokens(tokenIds);
// set renderer token data
for (uint256 i = 0; i < tokenIds.length; ) {
rendererTokenData[tokenIds[i]] = data[i];
// emit event
emit NewRendererTokenData(tokenIds[i], data[i]);
unchecked {
++i;
}
}
}
//----------------------------------------------------------
// Internal Functions
//----------------------------------------------------------
/// @notice Read the series renderer from the SSTORE2 pointers
/// @param seriesId The series ID to read
/// @return renderer The renderer bytes
function _readSeriesRenderer(
uint256 seriesId
) private view returns (bytes memory renderer) {
return _seriesRendererPointers[seriesId].sstore2Join();
}
/// @notice Check if the series has a renderer
/// @param seriesId The series ID to check
/// @return hasRenderer True if the series has a renderer, false otherwise
function _hasRenderer(uint256 seriesId) private view returns (bool) {
return _seriesRendererPointers[seriesId].length > 0;
}
/// @notice Check if the series exists
/// @param seriesId The series ID to check
/// @return exists True if the series exists, false otherwise
function _checkSeriesExists(uint256 seriesId) private view returns (bool) {
return _seriesMaxSupplies[seriesId] > 0;
}
/// @notice Validate the tokens are renderer tokens
/// @param tokenIds The token IDs to validate
function _validateRendererTokens(uint256[] calldata tokenIds) private view {
if (tokenIds.length == 0) {
revert ErrEmptyArray();
}
for (uint256 i = 0; i < tokenIds.length; ) {
if (!_exists(tokenIds[i])) {
revert ErrTokenDoesNotExist(tokenIds[i]);
}
if (!_hasRenderer(_allArtworks[tokenIds[i]].seriesId)) {
revert ErrSeriesHasNoRenderer();
}
unchecked {
++i;
}
}
}
/// @notice Validate the series are renderer series
/// @param seriesIds The series IDs to validate
function _validateRendererSeries(
uint256[] calldata seriesIds
) private view {
if (seriesIds.length == 0) {
revert ErrEmptyArray();
}
for (uint256 i = 0; i < seriesIds.length; ) {
if (!_checkSeriesExists(seriesIds[i])) {
revert ErrSeriesDoesNotExist(seriesIds[i]);
}
if (!_hasRenderer(seriesIds[i])) {
revert ErrSeriesHasNoRenderer();
}
unchecked {
++i;
}
}
}
/// @notice Validate the renderer token data
/// @param data The renderer token data to validate
function _validateRendererTokenData(
RendererTokenData memory data
) private pure {
if (
bytes(data.imageURI).length == 0 ||
bytes(data.textureURI).length == 0 ||
bytes(data.tokenName).length == 0
) {
revert ErrEmptyString();
}
// check for unsupported characters
checkForUnsupportedCharacters(data.imageURI);
checkForUnsupportedCharacters(data.textureURI);
checkForUnsupportedCharacters(data.tokenName);
}
/// @notice Check if a string contains unsupported characters that shouldn't be in a JSON string
/// @param str The string to check
function checkForUnsupportedCharacters(string memory str) internal pure {
bytes memory strBytes = bytes(str);
for (uint256 i = 0; i < strBytes.length; ) {
// check for double quote ("), backslash (\), and control characters
bytes1 b = strBytes[i];
if (b == 0x22 || b == 0x5C || b < 0x20) {
revert ErrUnsupportedCharacters();
}
unchecked {
++i;
}
}
}
}
IOperatorFilterRegistry.sol 29 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
interface IOperatorFilterRegistry {
function isOperatorAllowed(address registrant, address operator) external view returns (bool);
function register(address registrant) external;
function registerAndSubscribe(address registrant, address subscription) external;
function registerAndCopyEntries(address registrant, address registrantToCopy) external;
function unregister(address addr) external;
function updateOperator(address registrant, address operator, bool filtered) external;
function updateOperators(address registrant, address[] calldata operators, bool filtered) external;
function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;
function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;
function subscribe(address registrant, address registrantToSubscribe) external;
function unsubscribe(address registrant, bool copyExistingEntries) external;
function subscriptionOf(address addr) external returns (address registrant);
function subscribers(address registrant) external returns (address[] memory);
function subscriberAt(address registrant, uint256 index) external returns (address);
function copyEntriesOf(address registrant, address registrantToCopy) external;
function isOperatorFiltered(address registrant, address operator) external returns (bool);
function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);
function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);
function filteredOperators(address addr) external returns (address[] memory);
function filteredCodeHashes(address addr) external returns (bytes32[] memory);
function filteredOperatorAt(address registrant, uint256 index) external returns (address);
function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);
function isRegistered(address addr) external returns (bool);
function codeHashOf(address addr) external returns (bytes32);
}
UpdateableOperatorFilterer.sol 76 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {IOperatorFilterRegistry} from "./operator-filter-registry/IOperatorFilterRegistry.sol";
import "./Authorizable.sol";
/**
* @title UpdateableOperatorFilterer
* @notice Abstract contract whose constructor automatically registers and optionally subscribes to or copies another
* registrant's entries in the OperatorFilterRegistry.
* @dev This smart contract is meant to be inherited by token contracts so they can use the following:
* - `onlyAllowedOperator` modifier for `transferFrom` and `safeTransferFrom` methods.
* - `onlyAllowedOperatorApproval` modifier for `approve` and `setApprovalForAll` methods.
*/
abstract contract UpdateableOperatorFilterer is Authorizable {
error OperatorNotAllowed(address operator);
address constant DEFAULT_OPERATOR_FILTER_REGISTRY_ADDRESS =
address(0x000000000000AAeB6D7670E522A718067333cd4E);
address constant DEFAULT_SUBSCRIPTION =
address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
IOperatorFilterRegistry public OperatorFilterRegistry =
IOperatorFilterRegistry(DEFAULT_OPERATOR_FILTER_REGISTRY_ADDRESS);
constructor() {
if (address(OperatorFilterRegistry).code.length > 0) {
OperatorFilterRegistry.registerAndSubscribe(
address(this),
DEFAULT_SUBSCRIPTION
);
}
}
modifier onlyAllowedOperator(address from) virtual {
// Allow spending tokens from addresses with balance
// Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred
// from an EOA.
if (from != msg.sender) {
_checkFilterOperator(msg.sender);
}
_;
}
modifier onlyAllowedOperatorApproval(address operator) virtual {
_checkFilterOperator(operator);
_;
}
function _checkFilterOperator(address operator) internal view virtual {
// Check registry code length to facilitate testing in environments without a deployed registry.
if (address(OperatorFilterRegistry).code.length > 0) {
require(
OperatorFilterRegistry.isOperatorAllowed(
address(this),
operator
),
"operator is not allowed"
);
}
}
/**
* @notice update the operator filter registry
*/
function updateOperatorFilterRegistry(address operatorFilterRegisterAddress)
external
onlyOwner
{
OperatorFilterRegistry = IOperatorFilterRegistry(
operatorFilterRegisterAddress
);
}
}
RendererStorageV0.sol 122 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";
library RendererStorageV0 {
//----------------------------------------------------------
// Errors
//----------------------------------------------------------
error ErrEmptyField();
//----------------------------------------------------------
// Constants
//----------------------------------------------------------
bytes private constant PLACEHOLDER = bytes("{{TEXTURE_JSON}}");
/// @notice Generate the token URI for a renderer
/// @param renderer The renderer bytes
/// @param textureURI The texture URI
/// @param imageURI The image URI
/// @param tokenName The token name
/// @return The token URI
function tokenURI(
bytes memory renderer,
string memory textureURI,
string memory imageURI,
string memory tokenName
) public pure returns (string memory) {
if (
renderer.length == 0 ||
bytes(textureURI).length == 0 ||
bytes(imageURI).length == 0 ||
bytes(tokenName).length == 0
) {
revert ErrEmptyField();
}
// inject the texture URI into the renderer
bytes memory patchedRenderer = _injectTexture(renderer, textureURI);
string memory rendererB64 = Base64.encode(patchedRenderer);
// prettier-ignore
bytes memory json = abi.encodePacked(
"{\"animation_url\":\"data:text/html;base64,",
rendererB64,
"\",\"image\":\"",
imageURI,
"\",\"name\":\"",
tokenName,
"\"}"
);
return
string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(json)
)
);
}
/// @notice Replace the first `{{TEXTURE_JSON}}` occurrence with the provided url.
/// @param renderer The renderer bytes to modify
/// @param url The URL to inject
/// @return The modified renderer bytes
function _injectTexture(
bytes memory renderer,
string memory url
) internal pure returns (bytes memory) {
bytes memory urlBytes = bytes(url);
uint256 rendererLen = renderer.length;
uint256 placeholderLen = PLACEHOLDER.length;
// Early return for edge cases
if (rendererLen < placeholderLen || urlBytes.length == 0) {
return renderer;
}
// Find placeholder with optimized search
uint256 pos = type(uint256).max;
uint256 searchLimit = rendererLen - placeholderLen + 1;
for (uint256 i = 0; i < searchLimit; i++) {
// Quick first-byte check
if (renderer[i] == PLACEHOLDER[0]) {
// Full comparison only if first byte matches
bool found = true;
for (uint256 j = 1; j < placeholderLen; j++) {
if (renderer[i + j] != PLACEHOLDER[j]) {
found = false;
break;
}
}
if (found) {
pos = i;
break;
}
}
}
// No placeholder found
if (pos == type(uint256).max) {
return renderer;
}
// Efficient concatenation using bytes.concat
bytes memory prefix = new bytes(pos);
bytes memory suffix = new bytes(rendererLen - pos - placeholderLen);
// Copy prefix and suffix
for (uint256 i = 0; i < pos; i++) {
prefix[i] = renderer[i];
}
uint256 suffixStart = pos + placeholderLen;
for (uint256 i = 0; i < suffix.length; i++) {
suffix[i] = renderer[suffixStart + i];
}
return bytes.concat(prefix, urlBytes, suffix);
}
}
LibBytes.sol 80 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {SSTORE2} from "@0xsequence/sstore2/contracts/SSTORE2.sol";
library LibBytes {
//----------------------------------------------------------
// Errors
//----------------------------------------------------------
error ErrEmptySSTORE2Pointer();
error ErrOutOfBounds();
/// @notice Copy bytes from src to dest
/// @param dest The destination bytes
/// @param destOffset The offset to copy to
/// @param src The source bytes
/// @param len The length to copy
function memcpy(
bytes memory dest,
uint256 destOffset,
bytes memory src,
uint256 len
) public view {
if (len == 0) return;
if (destOffset + len > dest.length) {
revert ErrOutOfBounds();
}
assembly {
if iszero(
staticcall(
gas(),
4,
add(src, 32),
len,
add(add(dest, 32), destOffset),
len
)
) {
revert(0, 0)
}
}
}
/// @notice Join SSTORE2 chunks into a single bytes array
/// @param pointers The SSTORE2 pointers to join
/// @return The joined bytes array
function sstore2Join(
address[] memory pointers
) public view returns (bytes memory) {
if (pointers.length == 0) {
return new bytes(0);
}
uint256 total;
for (uint256 i = 0; i < pointers.length; ) {
uint256 length = pointers[i].code.length;
if (length <= 1) {
revert ErrEmptySSTORE2Pointer();
}
total += length - 1; // skip STOP byte
unchecked {
++i;
}
}
bytes memory result = new bytes(total);
uint256 offset;
for (uint256 i = 0; i < pointers.length; ) {
bytes memory chunk = SSTORE2.read(pointers[i]);
uint256 length = chunk.length;
memcpy(result, offset, chunk, length);
offset += length;
unchecked {
++i;
}
}
return result;
}
}
IFeralfileVault.sol 20 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./IFeralfileSaleData.sol";
import "./ECDSASigner.sol";
interface IFeralfileVault is IFeralfileSaleData {
function payForSale(
bytes32 r_,
bytes32 s_,
uint8 v_,
SaleData calldata saleData_
) external;
function withdrawFund(uint256 weiAmount) external;
receive() external payable;
}
IFeralfileSaleData.sol 19 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
interface IFeralfileSaleData {
struct RevenueShare {
address recipient;
uint256 bps;
}
struct SaleData {
uint256 price; // in wei
uint256 cost; // in wei
uint256 expiryTime;
address destination;
uint256[] tokenIds;
RevenueShare[][] revenueShares; // address and royalty bps (500 means 5%)
bool payByVaultContract; // get eth from vault contract, used by credit card pay that proxy by ITX
}
}
FeralfileSaleData.sol 21 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "./IFeralfileSaleData.sol";
contract FeralfileSaleData is IFeralfileSaleData {
function validateSaleData(SaleData calldata saleData_) internal view {
require(
saleData_.tokenIds.length > 0,
"FeralfileSaleData: tokenIds is empty"
);
require(
saleData_.tokenIds.length == saleData_.revenueShares.length,
"FeralfileSaleData: tokenIds and revenueShares length mismatch"
);
require(
saleData_.expiryTime > block.timestamp,
"FeralfileSaleData: sale is expired"
);
}
}
FeralfileArtworkV4_1.sol 184 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "./FeralfileArtworkV4.sol";
contract FeralfileExhibitionV4_1 is FeralfileExhibitionV4 {
mapping(address => uint256) public advances;
error InvalidAdvanceAddressesAndAmounts();
error InvalidAdvanceAddress();
error InvalidAdvanceAmount();
error InvalidSignature();
error AdvanceAddressAlreadyUsed();
constructor(
string memory name_,
string memory symbol_,
bool burnable_,
bool bridgeable_,
address signer_,
address vault_,
address costReceiver_,
string memory contractURI_,
uint256[] memory seriesIds_,
uint256[] memory seriesMaxSupplies_
)
FeralfileExhibitionV4(
name_,
symbol_,
burnable_,
bridgeable_,
signer_,
vault_,
costReceiver_,
contractURI_,
seriesIds_,
seriesMaxSupplies_
)
{}
/// @notice set advances setting
/// @param addresses_ - the addresses to set advances
/// @param amounts_ - the amounts to set advances
function setAdvanceSetting(
address[] calldata addresses_,
uint256[] calldata amounts_
) external onlyOwner {
if (addresses_.length != amounts_.length) {
revert InvalidAdvanceAddressesAndAmounts();
}
for (uint256 i = 0; i < addresses_.length; i++) {
if (addresses_[i] == address(0)) {
revert InvalidAdvanceAddress();
}
if (amounts_[i] == 0) {
revert InvalidAdvanceAmount();
}
if (advances[addresses_[i]] > 0) {
revert AdvanceAddressAlreadyUsed();
}
advances[addresses_[i]] = amounts_[i];
}
}
/// @notice replace advance addresses
/// @param oldAddresses_ - the old addresses to replace
/// @param newAddresses_ - the new addresses to replace
function replaceAdvanceAddresses(
address[] calldata oldAddresses_,
address[] calldata newAddresses_
) external onlyOwner {
if (oldAddresses_.length != newAddresses_.length) {
revert InvalidAdvanceAddressesAndAmounts();
}
for (uint256 i = 0; i < oldAddresses_.length; i++) {
if (newAddresses_[i] == address(0)) {
revert InvalidAdvanceAddress();
}
if (advances[newAddresses_[i]] > 0) {
revert AdvanceAddressAlreadyUsed();
}
advances[newAddresses_[i]] = advances[oldAddresses_[i]];
delete advances[oldAddresses_[i]];
}
}
/// @notice pay to get artworks to a destination address. The pricing, costs and other details is included in the saleData
/// @param r_ - part of signature for validating parameters integrity
/// @param s_ - part of signature for validating parameters integrity
/// @param v_ - part of signature for validating parameters integrity
/// @param saleData_ - the sale data
function buyArtworks(
bytes32 r_,
bytes32 s_,
uint8 v_,
SaleData calldata saleData_
) external payable override virtual {
require(_selling, "FeralfileExhibitionV4: sale is not started");
super._checkContractOwnedToken();
validateSaleData(saleData_);
saleData_.payByVaultContract
? vault.payForSale(r_, s_, v_, saleData_)
: require(
saleData_.price == msg.value,
"FeralfileExhibitionV4: invalid payment amount"
);
bytes32 message = keccak256(
abi.encode(block.chainid, address(this), saleData_)
);
if (!isValidSignature(message, r_, s_, v_)) {
revert InvalidSignature();
}
uint256 itemRevenue;
if (saleData_.price > saleData_.cost) {
itemRevenue =
(saleData_.price - saleData_.cost) /
saleData_.tokenIds.length;
}
uint256 distributedRevenue;
uint256 platformRevenue;
for (uint256 i = 0; i < saleData_.tokenIds.length; i++) {
// send NFT
_safeTransfer(
address(this),
saleData_.destination,
saleData_.tokenIds[i],
""
);
// distribute royalty
RevenueShare[] memory revenueShares = saleData_.revenueShares[i];
uint256 remainingRev = itemRevenue;
// deduct advances payment from revenue
for (
uint256 j = 0;
j < revenueShares.length && remainingRev > 0;
j++
) {
uint256 remainingAdvanceAmount = advances[
revenueShares[j].recipient
];
uint256 rev = remainingAdvanceAmount >= remainingRev
? remainingRev
: remainingAdvanceAmount;
platformRevenue += rev;
advances[revenueShares[j].recipient] -= rev;
remainingRev -= rev;
}
// distribute revenue
if (remainingRev > 0) {
for (uint256 j = 0; j < revenueShares.length; j++) {
address recipient = revenueShares[j].recipient;
uint256 rev = (remainingRev * revenueShares[j].bps) / 10000;
if (recipient == costReceiver) {
platformRevenue += rev;
continue;
}
distributedRevenue += rev;
payable(recipient).transfer(rev);
}
}
emit BuyArtwork(saleData_.destination, saleData_.tokenIds[i]);
}
require(
saleData_.price - saleData_.cost >=
distributedRevenue + platformRevenue,
"FeralfileExhibitionV4: total bps over 10,000"
);
// Transfer cost, platform revenue and remaining funds
uint256 leftOver = saleData_.price - distributedRevenue;
if (leftOver > 0) {
payable(costReceiver).transfer(leftOver);
}
}
}
FeralfileArtworkV4.sol 629 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./Authorizable.sol";
import "./UpdateableOperatorFilterer.sol";
import "./FeralfileSaleData.sol";
import "./ECDSASigner.sol";
import "./IFeralfileVault.sol";
contract FeralfileExhibitionV4 is
ERC721,
Authorizable,
UpdateableOperatorFilterer,
FeralfileSaleData,
ECDSASigner
{
using Strings for uint256;
struct Artwork {
uint256 seriesId;
uint256 tokenId;
}
struct MintData {
uint256 seriesId;
uint256 tokenId;
address owner;
}
// version code of contract
string public constant codeVersion = "FeralfileExhibitionV4";
// token base URI
string public tokenBaseURI;
// contract URI
string public contractURI;
// total supply
uint256 public totalSupply;
// burnable
bool public burnable;
// bridgeable
bool public bridgeable;
// selling
bool internal _selling;
// mintable
bool public mintable = true;
// cost receiver
address public costReceiver;
// vault contract instance
IFeralfileVault public vault;
// series max supplies
mapping(uint256 => uint256) internal _seriesMaxSupplies;
// series total supplies
mapping(uint256 => uint256) internal _seriesTotalSupplies;
// all artworks
mapping(uint256 => Artwork) internal _allArtworks;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
constructor(
string memory name_,
string memory symbol_,
bool burnable_,
bool bridgeable_,
address signer_,
address vault_,
address costReceiver_,
string memory contractURI_,
uint256[] memory seriesIds_,
uint256[] memory seriesMaxSupplies_
) ERC721(name_, symbol_) ECDSASigner(signer_) {
// validations
require(
bytes(name_).length > 0,
"FeralfileExhibitionV4: name_ is empty"
);
require(
bytes(symbol_).length > 0,
"FeralfileExhibitionV4: symbol_ is empty"
);
require(
vault_ != address(0),
"FeralfileExhibitionV4: vaultAddress_ is zero address"
);
require(
costReceiver_ != address(0),
"FeralfileExhibitionV4: costReceiver_ is zero address"
);
require(
bytes(contractURI_).length > 0,
"FeralfileExhibitionV4: contractURI_ is empty"
);
require(
seriesIds_.length > 0,
"FeralfileExhibitionV4: seriesIds_ is empty"
);
require(
seriesMaxSupplies_.length > 0,
"FeralfileExhibitionV4: _seriesMaxSupplies is empty"
);
require(
seriesIds_.length == seriesMaxSupplies_.length,
"FeralfileExhibitionV4: seriesMaxSupplies_ and seriesIds_ lengths are not the same"
);
burnable = burnable_;
bridgeable = bridgeable_;
costReceiver = costReceiver_;
vault = IFeralfileVault(payable(vault_));
contractURI = contractURI_;
// initialize max supply map
for (uint256 i = 0; i < seriesIds_.length; i++) {
require(
_seriesMaxSupplies[seriesIds_[i]] == 0,
"FeralfileExhibitionV4: duplicate seriesId"
);
require(
seriesMaxSupplies_[i] > 0,
"FeralfileExhibitionV4: zero max supply"
);
_seriesMaxSupplies[seriesIds_[i]] = seriesMaxSupplies_[i];
}
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(
address owner,
uint256 index
) external view returns (uint256) {
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/// @notice Get token ID from owner
function tokensOfOwner(
address owner
) external view returns (uint256[] memory) {
return _ownedTokens[owner];
}
/// @notice Get series max supply
/// @param seriesId a series ID
/// @return uint256 the max supply
function seriesMaxSupply(
uint256 seriesId
) external view virtual returns (uint256) {
return _seriesMaxSupplies[seriesId];
}
/// @notice Get series total supply
/// @param seriesId a series ID
/// @return uint256 the total supply
function seriesTotalSupply(
uint256 seriesId
) external view virtual returns (uint256) {
return _seriesTotalSupplies[seriesId];
}
/// @notice Get artwork data
/// @param tokenId a token ID representing the artwork
/// @return Artwork the Artwork object
function getArtwork(
uint256 tokenId
) external view virtual returns (Artwork memory) {
require(_exists(tokenId), "ERC721: invalid token ID");
return _allArtworks[tokenId];
}
/// @notice Set vault contract
/// @dev don't allow to set vault as zero address
function setVault(address vault_) external virtual onlyOwner {
require(
vault_ != address(0),
"FeralfileExhibitionV4: vault_ is zero address"
);
vault = IFeralfileVault(payable(vault_));
}
/// @notice Return flag _selling;
function selling() external view returns (bool) {
return _selling;
}
function _checkContractOwnedToken() internal view {
uint256 balance = balanceOf(address(this));
require(
balance > 0,
"FeralfileExhibitionV4: No token owned by the contract"
);
}
/// @notice Start token sale
function startSale() external onlyOwner {
mintable = false;
resumeSale();
}
/// @notice Resume token sale
function resumeSale() public onlyOwner {
require(
!mintable,
"FeralfileExhibitionV4: mintable required to be false"
);
require(
!_selling,
"FeralfileExhibitionV4: _selling required to be false"
);
_checkContractOwnedToken();
_selling = true;
}
/// @notice Pause token sale
function pauseSale() public onlyOwner {
require(
!mintable,
"FeralfileExhibitionV4: mintable required to be false"
);
require(
_selling,
"FeralfileExhibitionV4: _selling required to be true"
);
_selling = false;
}
/// @notice Stop token sale and burn remaining tokens
function stopSaleAndBurn() external onlyOwner {
pauseSale();
// burn remaining tokens
uint256[] memory tokenIds = _ownedTokens[address(this)];
for (uint256 i = 0; i < tokenIds.length; i++) {
_burnArtwork(tokenIds[i]);
}
}
/// @notice Stop token selling and transfer remaining tokens back to the underlying addresses
function stopSaleAndTransfer(
uint256[] memory seriesIds,
address[] memory recipientAddresses
) external onlyOwner {
require(
seriesIds.length > 0 && recipientAddresses.length > 0,
"FeralfileExhibitionV4: seriesIds or recipientAddresses length is zero"
);
require(
seriesIds.length == recipientAddresses.length,
"FeralfileExhibitionV4: seriesIds length is different from recipientAddresses"
);
pauseSale();
// transfer tokens back to the addresses
address from = address(this);
uint256[] memory tokenIds = _ownedTokens[from];
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
Artwork memory artwork = _allArtworks[tokenId];
for (uint16 j = 0; j < seriesIds.length; j++) {
if (artwork.seriesId == seriesIds[j]) {
address to = recipientAddresses[j];
_safeTransfer(from, to, tokenId, "");
break;
}
}
}
require(
balanceOf(from) == 0,
"FeralfileExhibitionV4: Token for sale balance has to be zero"
);
}
/// @dev override for OperatorFilterRegistry
function setApprovalForAll(
address operator,
bool approved
) public override(ERC721) onlyAllowedOperatorApproval(operator) {
super.setApprovalForAll(operator, approved);
}
/// @dev override for OperatorFilterRegistry
function approve(
address operator,
uint256 tokenId
) public override(ERC721) onlyAllowedOperatorApproval(operator) {
super.approve(operator, tokenId);
}
/// @dev override for OperatorFilterRegistry
function transferFrom(
address from,
address to,
uint256 tokenId
) public override(ERC721) onlyAllowedOperator(from) {
require(
to != address(this),
"FeralfileExhibitionV4: Contract isn't allowed to receive token"
);
super.transferFrom(from, to, tokenId);
}
/// @dev override for OperatorFilterRegistry
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public override(ERC721) onlyAllowedOperator(from) {
require(
to != address(this),
"FeralfileExhibitionV4: Contract isn't allowed to receive token"
);
super.safeTransferFrom(from, to, tokenId);
}
/// @dev override for OperatorFilterRegistry
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
) public override(ERC721) onlyAllowedOperator(from) {
require(
to != address(this),
"FeralfileExhibitionV4: Contract isn't allowed to receive token"
);
super.safeTransferFrom(from, to, tokenId, data);
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
require(
bytes(tokenBaseURI).length > 0,
"ERC721Metadata: _tokenBaseURI is empty"
);
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
return string(abi.encodePacked(tokenBaseURI, "/", tokenId.toString()));
}
/// @notice Update the base URI for all tokens
function setTokenBaseURI(string memory baseURI_) external onlyOwner {
require(
bytes(baseURI_).length > 0,
"ERC721Metadata: baseURI_ is empty"
);
tokenBaseURI = baseURI_;
}
/// @notice the cost receiver address
/// @param costReceiver_ - the address of cost receiver
function setCostReceiver(address costReceiver_) external onlyOwner {
require(
costReceiver_ != address(0),
"FeralfileExhibitionV4: costReceiver_ is zero address"
);
costReceiver = costReceiver_;
}
/// @notice pay to get artworks to a destination address. The pricing, costs and other details is included in the saleData
/// @param r_ - part of signature for validating parameters integrity
/// @param s_ - part of signature for validating parameters integrity
/// @param v_ - part of signature for validating parameters integrity
/// @param saleData_ - the sale data
function buyArtworks(
bytes32 r_,
bytes32 s_,
uint8 v_,
SaleData calldata saleData_
) external payable virtual {
require(_selling, "FeralfileExhibitionV4: sale is not started");
_checkContractOwnedToken();
validateSaleData(saleData_);
saleData_.payByVaultContract
? vault.payForSale(r_, s_, v_, saleData_)
: require(
saleData_.price == msg.value,
"FeralfileExhibitionV4: invalid payment amount"
);
bytes32 message = keccak256(
abi.encode(block.chainid, address(this), saleData_)
);
require(
isValidSignature(message, r_, s_, v_),
"FeralfileExhibitionV4: invalid signature"
);
uint256 itemRevenue;
if (saleData_.price > saleData_.cost) {
itemRevenue =
(saleData_.price - saleData_.cost) /
saleData_.tokenIds.length;
}
uint256 distributedRevenue;
uint256 platformRevenue;
for (uint256 i = 0; i < saleData_.tokenIds.length; i++) {
// send NFT
_safeTransfer(
address(this),
saleData_.destination,
saleData_.tokenIds[i],
""
);
if (itemRevenue > 0) {
// distribute royalty
for (
uint256 j = 0;
j < saleData_.revenueShares[i].length;
j++
) {
uint256 rev = (itemRevenue *
saleData_.revenueShares[i][j].bps) / 10000;
if (
saleData_.revenueShares[i][j].recipient == costReceiver
) {
platformRevenue += rev;
continue;
}
distributedRevenue += rev;
payable(saleData_.revenueShares[i][j].recipient).transfer(
rev
);
}
}
emit BuyArtwork(saleData_.destination, saleData_.tokenIds[i]);
}
require(
saleData_.price - saleData_.cost >=
distributedRevenue + platformRevenue,
"FeralfileExhibitionV4: total bps over 10,000"
);
// Transfer cost, platform revenue and remaining funds
uint256 leftOver = saleData_.price - distributedRevenue;
if (leftOver > 0) {
payable(costReceiver).transfer(leftOver);
}
}
/// @notice utility function for checking the series exists
function _seriesExists(uint256 seriesId) private view returns (bool) {
return _seriesMaxSupplies[seriesId] > 0;
}
/// @dev Modify from ERC721Enumerable
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (batchSize > 1) {
// Will only trigger during construction. Batch transferring (minting) is not available afterwards.
revert("ERC721Enumerable: consecutive transfers not supported");
}
uint256 tokenId = firstTokenId;
if (from != address(0) && from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to != address(0) && to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/// @dev Modify from ERC721Enumerable
function _removeTokenFromOwnerEnumeration(
address from,
uint256 tokenId
) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
delete _ownedTokensIndex[tokenId];
_ownedTokens[from].pop();
}
/// @dev Modify from ERC721Enumerable
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256[] storage tokens = _ownedTokens[to];
uint256 length = tokens.length;
tokens.push(tokenId);
_ownedTokensIndex[tokenId] = length;
}
/// @notice Mint new collection of Artwork
/// @dev the function iterates over the array of MintData to call the internal function _mintArtwork
/// @param data an array of MintData
function mintArtworks(
MintData[] calldata data
) external virtual onlyAuthorized {
require(
mintable,
"FeralfileExhibitionV4: contract doesn't allow to mint"
);
for (uint256 i = 0; i < data.length; i++) {
_mintArtwork(data[i].seriesId, data[i].tokenId, data[i].owner);
}
}
function _mintArtwork(
uint256 seriesId,
uint256 tokenId,
address owner
) internal {
// pre-condition checks
require(
_seriesExists(seriesId),
string(
abi.encodePacked(
"FeralfileExhibitionV4: seriesId doesn't exist: ",
Strings.toString(seriesId)
)
)
);
require(
_seriesTotalSupplies[seriesId] < _seriesMaxSupplies[seriesId],
"FeralfileExhibitionV4: no slots available"
);
// mint
totalSupply += 1;
_seriesTotalSupplies[seriesId] += 1;
_allArtworks[tokenId] = Artwork(seriesId, tokenId);
_mint(owner, tokenId);
// emit event
emit NewArtwork(owner, seriesId, tokenId);
}
/// @notice Burn a collection of artworks
/// @dev the function iterates over the array of token ID to call the internal function _burnArtwork
/// @param tokenIds an array of token ID
function burnArtworks(uint256[] memory tokenIds) external {
require(burnable, "FeralfileExhibitionV4: token is not burnable");
for (uint256 i = 0; i < tokenIds.length; i++) {
require(
_isApprovedOrOwner(_msgSender(), tokenIds[i]),
"ERC721: caller is not token owner or approved"
);
_burnArtwork(tokenIds[i]);
}
}
function _burnArtwork(uint256 tokenId) internal {
require(_exists(tokenId), "ERC721: invalid token ID");
// burn artwork
Artwork memory artwork = _allArtworks[tokenId];
_seriesTotalSupplies[artwork.seriesId] -= 1;
totalSupply -= 1;
delete _allArtworks[tokenId];
_burn(tokenId);
// emit event
emit BurnArtwork(tokenId);
}
/// @notice able to receive fund from vault contract
receive() external payable {
require(
msg.sender == address(vault),
"FeralfileExhibitionV4: only accept fund from vault contract."
);
}
/// @notice Event emitted when new Artwork has been minted
event NewArtwork(
address indexed owner,
uint256 indexed seriesId,
uint256 indexed tokenId
);
/// @notice Event emitted when Artwork has been burned
event BurnArtwork(uint256 indexed tokenId);
/// @notice Event emitted when Artwork has been sold
event BuyArtwork(address indexed buyer, uint256 indexed tokenId);
}
ECDSASigner.sol 46 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract ECDSASigner is Ownable {
address private _signer;
constructor(address signer_) {
require(signer_ != address(0), "ECDSASign: signer_ is zero address");
_signer = signer_;
}
/// @notice isValidSignature validates a message by ecrecover to ensure
// it is signed by signer.
/// @param message_ - the raw message for signing
/// @param r_ - part of signature for validating parameters integrity
/// @param s_ - part of signature for validating parameters integrity
/// @param v_ - part of signature for validating parameters integrity
function isValidSignature(
bytes32 message_,
bytes32 r_,
bytes32 s_,
uint8 v_
) internal view returns (bool) {
address reqSigner = ECDSA.recover(
ECDSA.toEthSignedMessageHash(message_),
v_,
r_,
s_
);
return reqSigner == _signer;
}
/// @notice set the signer
/// @param signer_ - the address of signer
function setSigner(address signer_) external onlyOwner {
require(signer_ != address(0), "ECDSASign: signer_ is zero address");
_signer = signer_;
}
function signer() external view returns (address) {
return _signer;
}
}
Authorizable.sol 23 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";
contract Authorizable is Ownable {
mapping(address => bool) public trustees;
constructor() {}
modifier onlyAuthorized() {
require(trustees[msg.sender] || msg.sender == owner());
_;
}
function addTrustee(address _trustee) public onlyOwner {
trustees[_trustee] = true;
}
function removeTrustee(address _trustee) public onlyOwner {
delete trustees[_trustee];
}
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @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);
}
}
}
Math.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @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 up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (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; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
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.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 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.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
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 (rounding == Rounding.Up && 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 down.
*
* 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
ECDSA.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
Strings.sol 85 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @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), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(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) {
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] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
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 keccak256(bytes(a)) == keccak256(bytes(b));
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Base64.sol 101 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.6) (utils/Base64.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides a set of functions to operate with Base64 strings.
*
* _Available since v4.5._
*/
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;
}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
}
}
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
IERC721Receiver.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
IERC721.sol 132 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
ERC721.sol 466 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _ownerOf(tokenId);
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not token owner or approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_safeTransfer(from, to, tokenId, data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _ownerOf(tokenId) != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId, 1);
// Check that tokenId was not minted by `_beforeTokenTransfer` hook
require(!_exists(tokenId), "ERC721: token already minted");
unchecked {
// Will not overflow unless all 2**256 token ids are minted to the same owner.
// Given that tokens are minted one by one, it is impossible in practice that
// this ever happens. Might change if we allow batch minting.
// The ERC fails to describe this case.
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId, 1);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId, 1);
// Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
owner = ERC721.ownerOf(tokenId);
// Clear approvals
delete _tokenApprovals[tokenId];
unchecked {
// Cannot overflow, as that would require more tokens to be burned/transferred
// out than the owner initially received through minting and transferring in.
_balances[owner] -= 1;
}
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId, 1);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId, 1);
// Check that tokenId was not transferred by `_beforeTokenTransfer` hook
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
// Clear approvals from the previous owner
delete _tokenApprovals[tokenId];
unchecked {
// `_balances[from]` cannot overflow for the same reason as described in `_burn`:
// `from`'s balance is the number of token held, which is at least one before the current
// transfer.
// `_balances[to]` could overflow in the conditions described in `_mint`. That would require
// all 2**256 token ids to be minted, which in practice is impossible.
_balances[from] -= 1;
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId, 1);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
* - When `from` is zero, the tokens will be minted for `to`.
* - When `to` is zero, ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
* - When `from` is zero, the tokens were minted for `to`.
* - When `to` is zero, ``from``'s tokens were burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
* being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
* that `ownerOf(tokenId)` is `a`.
*/
// solhint-disable-next-line func-name-mixedcase
function __unsafe_increaseBalance(address account, uint256 amount) internal {
_balances[account] += amount;
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @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 {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_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);
}
}
Bytecode.sol 78 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library Bytecode {
error InvalidCodeAtRange(uint256 _size, uint256 _start, uint256 _end);
/**
@notice Generate a creation code that results on a contract with `_code` as bytecode
@param _code The returning value of the resulting `creationCode`
@return creationCode (constructor) for new contract
*/
function creationCodeFor(bytes memory _code) internal pure returns (bytes memory) {
/*
0x00 0x63 0x63XXXXXX PUSH4 _code.length size
0x01 0x80 0x80 DUP1 size size
0x02 0x60 0x600e PUSH1 14 14 size size
0x03 0x60 0x6000 PUSH1 00 0 14 size size
0x04 0x39 0x39 CODECOPY size
0x05 0x60 0x6000 PUSH1 00 0 size
0x06 0xf3 0xf3 RETURN
<CODE>
*/
return abi.encodePacked(
hex"63",
uint32(_code.length),
hex"80_60_0E_60_00_39_60_00_F3",
_code
);
}
/**
@notice Returns the size of the code on a given address
@param _addr Address that may or may not contain code
@return size of the code on the given `_addr`
*/
function codeSize(address _addr) internal view returns (uint256 size) {
assembly { size := extcodesize(_addr) }
}
/**
@notice Returns the code of a given address
@dev It will fail if `_end < _start`
@param _addr Address that may or may not contain code
@param _start number of bytes of code to skip on read
@param _end index before which to end extraction
@return oCode read from `_addr` deployed bytecode
Forked from: https://gist.github.com/KardanovIR/fe98661df9338c842b4a30306d507fbd
*/
function codeAt(address _addr, uint256 _start, uint256 _end) internal view returns (bytes memory oCode) {
uint256 csize = codeSize(_addr);
if (csize == 0) return bytes("");
if (_start > csize) return bytes("");
if (_end < _start) revert InvalidCodeAtRange(csize, _start, _end);
unchecked {
uint256 reqSize = _end - _start;
uint256 maxSize = csize - _start;
uint256 size = maxSize < reqSize ? maxSize : reqSize;
assembly {
// allocate output byte array - this could also be done without assembly
// by using o_code = new bytes(size)
oCode := mload(0x40)
// new "memory end" including padding
mstore(0x40, add(oCode, and(add(add(size, 0x20), 0x1f), not(0x1f))))
// store length in memory
mstore(oCode, size)
// actually retrieve the code, this needs assembly
extcodecopy(_addr, add(oCode, 0x20), _start, size)
}
}
}
}
SSTORE2.sol 70 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./utils/Bytecode.sol"; /** @title A key-value storage with auto-generated keys for storing chunks of data with a lower write & read cost. @author Agustin Aguilar <[email protected]> Readme: https://github.com/0xsequence/sstore2#readme */ library SSTORE2 { error WriteError(); /** @notice Stores `_data` and returns `pointer` as key for later retrieval @dev The pointer is a contract address with `_data` as code @param _data to be written @return pointer Pointer to the written `_data` */ function write(bytes memory _data) internal returns (address pointer) { // Append 00 to _data so contract can't be called // Build init code bytes memory code = Bytecode.creationCodeFor( abi.encodePacked( hex'00', _data ) ); // Deploy contract using create assembly { pointer := create(0, add(code, 32), mload(code)) } // Address MUST be non-zero if (pointer == address(0)) revert WriteError(); } /** @notice Reads the contents of the `_pointer` code as data, skips the first byte @dev The function is intended for reading pointers generated by `write` @param _pointer to be read @return data read from `_pointer` contract */ function read(address _pointer) internal view returns (bytes memory) { return Bytecode.codeAt(_pointer, 1, type(uint256).max); } /** @notice Reads the contents of the `_pointer` code as data, skips the first byte @dev The function is intended for reading pointers generated by `write` @param _pointer to be read @param _start number of bytes to skip @return data read from `_pointer` contract */ function read(address _pointer, uint256 _start) internal view returns (bytes memory) { return Bytecode.codeAt(_pointer, _start + 1, type(uint256).max); } /** @notice Reads the contents of the `_pointer` code as data, skips the first byte @dev The function is intended for reading pointers generated by `write` @param _pointer to be read @param _start number of bytes to skip @param _end index before which to end extraction @return data read from `_pointer` contract */ function read(address _pointer, uint256 _start, uint256 _end) internal view returns (bytes memory) { return Bytecode.codeAt(_pointer, _start + 1, _end + 1); } }
Read Contract
CHUNK_SIZE 0xe91e13a9 → uint256
OperatorFilterRegistry 0xf07e7fd0 → address
RENDERER_BLOB_MAX_SIZE 0x9cd7d65c → uint256
advances 0x926ce44e → uint256
balanceOf 0x70a08231 → uint256
bridgeable 0x530da8ef → bool
burnable 0xa07c7ce4 → bool
codeVersion 0x63e60230 → string
contractURI 0xe8a3d485 → string
costReceiver 0xf4e638be → address
getApproved 0x081812fc → address
getArtwork 0x167ddf6e → tuple
getSeriesRenderer 0xab221792 → string
isApprovedForAll 0xe985e9c5 → bool
mintable 0x4bf365df → bool
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
rendererTokenData 0x504c05ea → string, string, string
selling 0x23aed228 → bool
seriesMaxSupply 0xeb5c60f2 → uint256
seriesNames 0xfe43658d → string
seriesTotalSupply 0x7f06ee06 → uint256
signer 0x238ac933 → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenBaseURI 0x4e99b800 → string
tokenOfOwnerByIndex 0x2f745c59 → uint256
tokenURI 0xc87b56dd → string
tokensOfOwner 0x8462151c → uint256[]
totalSupply 0x18160ddd → uint256
trustees 0xeee608a4 → bool
vault 0xfbfa77cf → address
Write Contract 27 functions
These functions modify contract state and require a wallet transaction to execute.
addTrustee 0xdc78ac1c
address _trustee
approve 0x095ea7b3
address operator
uint256 tokenId
burnArtworks 0x21fe0c64
uint256[] tokenIds
buyArtworks 0x36a84ec9
bytes32 r_
bytes32 s_
uint8 v_
tuple saleData_
mintArtworks 0xe6c88c62
tuple[] data
pauseSale 0x55367ba9
No parameters
removeTrustee 0x03120506
address _trustee
renounceOwnership 0x715018a6
No parameters
replaceAdvanceAddresses 0x41a5626a
address[] oldAddresses_
address[] newAddresses_
resumeSale 0x33e364cb
No parameters
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes data
setAdvanceSetting 0x3c352b0d
address[] addresses_
uint256[] amounts_
setApprovalForAll 0xa22cb465
address operator
bool approved
setCostReceiver 0x1623528f
address costReceiver_
setRendererTokenData 0x6128cbb3
uint256[] tokenIds
tuple[] data
setSeriesNames 0xfa35e4e2
uint256[] seriesIds
string[] names
setSeriesRenderer 0x771ac303
uint256 seriesId
bytes blob
setSigner 0x6c19e783
address signer_
setTokenBaseURI 0x8ef79e91
string baseURI_
setVault 0x6817031b
address vault_
startSale 0xb66a0e5d
No parameters
stopSaleAndBurn 0xb9b8311a
No parameters
stopSaleAndTransfer 0x65a46e08
uint256[] seriesIds
address[] recipientAddresses
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
updateOperatorFilterRegistry 0x114ba8ee
address operatorFilterRegisterAddress
Recent Transactions
No transactions found for this address