Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xB01b6a7EF8560017AA59A990e39f26b8df29F80f
Balance 0 ETH
Nonce 1
Code Size 22281 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

22281 bytes
0x60806040526004361061042b575f3560e01c8063744140cb1161022b578063c5ab3ba611610129578063dd62ed3e116100b3578063f4644f4111610078578063f4644f4114610e03578063f780bc1a14610e2e578063fb29d01514610e4d578063fd4fc0bd14610e60578063fdc3d8d714610e8b575f5ffd5b8063dd62ed3e14610d37578063dd63769914610d6d578063dfabc03314610d8c578063e985e9c514610dab578063f2fde38b14610de4575f5ffd5b8063d505accf116100f9578063d505accf14610c81578063d56c538314610ca0578063d96ca0b914610ccb578063dc07b61714610cea578063dc48646214610cfe575f5ffd5b8063c5ab3ba614610bf5578063c6e672b914610c09578063c879b96914610c28578063c87b56dd14610c62575f5ffd5b806395d89b41116101b5578063b15680731161017a578063b156807314610b2b578063b1ab931714610b57578063b3f9ea3414610b83578063b88d4fde14610bb7578063c30f4a5a14610bd6575f5ffd5b806395d89b4114610a91578063976a843514610aa5578063a089320a14610ad8578063a22cb46514610aed578063a9059cbb14610b0c575f5ffd5b806389fb4c66116101fb57806389fb4c66146109f15780638a696e5014610a055780638d97767214610a245780638da5cb5b14610a55578063947abb9d14610a72575f5ffd5b8063744140cb1461096957806377465ade146109885780637d6e1578146109a75780637ecebe00146109c6575f5ffd5b80632ae0268a116103385780634d631360116102c257806368e8fe6d1161028757806368e8fe6d146108c95780636e8f624b146108f457806370a082311461090b57806370dba90b14610936578063715018a614610955575f5ffd5b80634d631360146108435780634d966072146108575780634f02c420146108765780636352211e1461088b578063669b797a146108aa575f5ffd5b80633bb7bf1d116103085780633bb7bf1d1461078857806342842e0e146107a75780634313b9e5146107c657806349bd5a5e1461080b5780634af57f9d1461082f575f5ffd5b80632ae0268a146106de5780632dd7c65814610710578063313ce5671461072f5780633644e51514610774575f5ffd5b806309c862cd116103b957806318160ddd1161038957806318160ddd1461060c5780631ac5cfe5146106215780631c199e211461065b57806321030ff21461068657806323b872dd146106bf575f5ffd5b806309c862cd1461059057806309f0ef65146105af57806310d0c303146105ce578063135ffd40146105ed575f5ffd5b806304fe2b34116103ff57806304fe2b34146104ea57806306fdde03146104fd578063081812fc14610511578063095ea7b31461055d57806309674eb01461057c575f5ffd5b80627730401461042f57806301612c401461045857806301ffc9a71461047957806302519da3146104a8575b5f5ffd5b61044261043d366004614a11565b610ea0565b60405161044f9190614ab2565b60405180910390f35b348015610463575f5ffd5b50610477610472366004614ac4565b610fc3565b005b348015610484575f5ffd5b50610498610493366004614af9565b61118f565b604051901515815260200161044f565b3480156104b3575f5ffd5b506104dc6104c2366004614b14565b6001600160a01b03165f9081526009602052604090205490565b60405190815260200161044f565b6104dc6104f8366004614b2f565b6111c5565b348015610508575f5ffd5b506104426112cd565b34801561051c575f5ffd5b5061054561052b366004614b76565b600b6020525f90815260409020546001600160a01b031681565b6040516001600160a01b03909116815260200161044f565b348015610568575f5ffd5b50610498610577366004614b8d565b611359565b348015610587575f5ffd5b506104dc6113ce565b34801561059b575f5ffd5b506104776105aa366004614bb7565b6113de565b3480156105ba575f5ffd5b506104986105c9366004614b14565b611622565b3480156105d9575f5ffd5b506104dc6105e8366004614ac4565b611652565b3480156105f8575f5ffd5b50610477610607366004614ac4565b61167d565b348015610617575f5ffd5b506104dc60065481565b34801561062c575f5ffd5b5061064061063b366004614ac4565b611732565b6040805193845260208401929092529082015260600161044f565b348015610666575f5ffd5b506104dc610675366004614b76565b60126020525f908152604090205481565b348015610691575f5ffd5b506104986106a0366004614be0565b601160209081525f928352604080842090915290825290205460ff1681565b3480156106ca575f5ffd5b506104986106d9366004614c0e565b611770565b3480156106e9575f5ffd5b506106fd6106f8366004614ac4565b6117e7565b60405161044f9796959493929190614c4c565b34801561071b575f5ffd5b5061054561072a366004614b76565b6118c3565b34801561073a575f5ffd5b506107627f000000000000000000000000000000000000000000000000000000000000001281565b60405160ff909116815260200161044f565b34801561077f575f5ffd5b506104dc6119a7565b348015610793575f5ffd5b506104776107a2366004614c0e565b6119fc565b3480156107b2575f5ffd5b506104776107c1366004614c0e565b611ad4565b3480156107d1575f5ffd5b506107e56107e0366004614b76565b611af3565b604080516001600160a01b0394851681529390921660208401529082015260600161044f565b348015610816575f5ffd5b506021546105459061010090046001600160a01b031681565b34801561083a575f5ffd5b50610477611b31565b34801561084e575f5ffd5b50610477611b48565b348015610862575f5ffd5b50610498610871366004614b8d565b611b5f565b348015610881575f5ffd5b506104dc60075481565b348015610896575f5ffd5b506105456108a5366004614b76565b611bea565b3480156108b5575f5ffd5b506104776108c4366004614bb7565b611c67565b3480156108d4575f5ffd5b506104dc6108e3366004614b76565b601d6020525f908152604090205481565b3480156108ff575f5ffd5b506104dc600160ff1b81565b348015610916575f5ffd5b506104dc610925366004614b14565b60096020525f908152604090205481565b348015610941575f5ffd5b50610477610950366004614cac565b611f2f565b348015610960575f5ffd5b50610477611ff4565b348015610974575f5ffd5b50610477610983366004614ac4565b612007565b348015610993575f5ffd5b506104986109a2366004614ac4565b6120c0565b3480156109b2575f5ffd5b506104dc6109c1366004614ce7565b6122e9565b3480156109d1575f5ffd5b506104dc6109e0366004614b14565b60106020525f908152604090205481565b3480156109fc575f5ffd5b506006546104dc565b348015610a10575f5ffd5b50610477610a1f366004614d6d565b612516565b348015610a2f575f5ffd5b50610a43610a3e366004614b76565b61257e565b60405161044f96959493929190614d86565b348015610a60575f5ffd5b506001546001600160a01b0316610545565b348015610a7d575f5ffd5b50610442610a8c366004614a11565b612646565b348015610a9c575f5ffd5b506104426127a1565b348015610ab0575f5ffd5b506104dc7f0000000000000000000000000000000000000000000000000de0b6b3a764000081565b348015610ae3575f5ffd5b506104dc6103e881565b348015610af8575f5ffd5b50610477610b07366004614dcc565b6127ae565b348015610b17575f5ffd5b50610498610b26366004614b8d565b612840565b348015610b36575f5ffd5b50610b4a610b45366004614bb7565b612873565b60405161044f9190614dff565b348015610b62575f5ffd5b50610b76610b71366004614b14565b612a19565b60405161044f9190614e5d565b348015610b8e575f5ffd5b506104dc610b9d366004614b14565b6001600160a01b03165f908152600e602052604090205490565b348015610bc2575f5ffd5b50610477610bd1366004614f39565b612b14565b348015610be1575f5ffd5b50610477610bf0366004614fb3565b612c07565b348015610c00575f5ffd5b506007546104dc565b348015610c14575f5ffd5b50610477610c23366004614dcc565b612c1b565b348015610c33575f5ffd5b50610640610c42366004614b76565b60176020525f908152604090208054600182015460029092015490919083565b348015610c6d575f5ffd5b50610442610c7c366004614b76565b612c2d565b348015610c8c575f5ffd5b50610477610c9b366004614ff7565b612c61565b348015610cab575f5ffd5b506104dc610cba366004614b76565b60086020525f908152604090205481565b348015610cd6575f5ffd5b50610498610ce5366004614c0e565b612e9e565b348015610cf5575f5ffd5b50610477612f7b565b348015610d09575f5ffd5b50610498610d18366004614ac4565b601b60209081525f928352604080842090915290825290205460ff1681565b348015610d42575f5ffd5b506104dc610d51366004615061565b600a60209081525f928352604080842090915290825290205481565b348015610d78575f5ffd5b50610477610d87366004614c0e565b612f8b565b348015610d97575f5ffd5b50610498610da6366004614b8d565b6130f9565b348015610db6575f5ffd5b50610498610dc5366004615061565b600c60209081525f928352604080842090915290825290205460ff1681565b348015610def575f5ffd5b50610477610dfe366004614b14565b6131e1565b348015610e0e575f5ffd5b506104dc610e1d366004614b76565b601a6020525f908152604090205481565b348015610e39575f5ffd5b50610b76610e48366004614ac4565b61321b565b610477610e5b36600461508d565b6132ba565b348015610e6b575f5ffd5b506104dc610e7a366004614b76565b60136020525f908152604090205481565b348015610e96575f5ffd5b506104dc60165481565b6060610eaa61360c565b610ed5610ebb600160ff1b896150c2565b5f908152600d60205260409020546001600160a01b031690565b6001600160a01b0316336001600160a01b031614610f305760405162461bcd60e51b81526020600482015260136024820152722737ba103a3432903a37b5b2b71037bbb732b960691b60448201526064015b60405180910390fd5b610f39876118c3565b6001600160a01b0316635194544787878787876040518663ffffffff1660e01b8152600401610f6c9594939291906150fd565b5f604051808303815f875af1158015610f87573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610fae9190810190615139565b9050610fb960015f55565b9695505050505050565b5f818152601560205260409020546064116110205760405162461bcd60e51b815260206004820152601860248201527f546f6f206d616e79207461736b7320666f72206167656e7400000000000000006044820152606401610f27565b33611032610ebb600160ff1b846150c2565b6001600160a01b03161461107a5760405162461bcd60e51b815260206004820152600f60248201526e2737ba1030b3b2b73a1037bbb732b960891b6044820152606401610f27565b5f828152601460205260409020600481015460ff16156110d55760405162461bcd60e51b815260206004820152601660248201527515185cdac8185b1c9958591e4818dbdb5c1b195d195960521b6044820152606401610f27565b8060030154421061111f5760405162461bcd60e51b815260206004820152601460248201527315185cdac8191958591b1a5b99481c185cdcd95960621b6044820152606401610f27565b5f82815260156020908152604080832080546001818101835591855283852001879055868452601b8352818420868552909252808320805460ff191690921790915551839185917f25e5c814bf9313a0efe86f97f5d6ad2921089c376aa35ab12fc2c495546755ee9190a3505050565b5f6001600160e01b0319821663caf91ff560e01b14806111bf57506001600160e01b031982166301ffc9a760e01b145b92915050565b5f6111ce61360c565b42821161121d5760405162461bcd60e51b815260206004820152601e60248201527f446561646c696e65206d75737420626520696e207468652066757475726500006044820152606401610f27565b601680545f918261122d836151ad565b909155505f8181526014602052604090209091508061124d868883615248565b506001810180546001600160a01b031916339081179091553460028301556003820185905560048201805460ff1916905560405183907f5b2493258cbc7169ad9389516998320ce25dc27637cea28ddd0d033af122bfa6906112b2908a908a90615301565b60405180910390a35090506112c660015f55565b9392505050565b600480546112da906151c5565b80601f0160208091040260200160405190810160405280929190818152602001828054611306906151c5565b80156113515780601f1061132857610100808354040283529160200191611351565b820191905f5260205f20905b81548152906001019060200180831161133457829003601f168201915b505050505081565b5f600160ff1b82106113765761136f8383611b5f565b90506111bf565b61138c611387600160ff1b846150c2565b613634565b156113bb575f61139c84846130f9565b9050806113b5576113ad8484611b5f565b9150506111bf565b506113c5565b61136f8383611b5f565b50600192915050565b5f6113d9600261364b565b905090565b6007548211156114305760405162461bcd60e51b815260206004820152601e60248201527f526563697069656e7420746f6b656e20646f6573206e6f7420657869737400006044820152606401610f27565b5f61143a846118c3565b5f848152601860205260409020549091506103e81161149b5760405162461bcd60e51b815260206004820152601f60248201527f546f6f206d616e79206d6573736167657320666f7220726563697069656e74006044820152606401610f27565b5f848152600860205260409020546103e8116115035760405162461bcd60e51b815260206004820152602160248201527f53656e646572206861732073656e7420746f6f206d616e79206d6573736167656044820152607360f81b6064820152608401610f27565b336001600160a01b038216148061153257505f84815260116020908152604080832033845290915290205460ff165b8061155557503361154a610ebb600160ff1b876150c2565b6001600160a01b0316145b6115715760405162461bcd60e51b8152600401610f2790615314565b5f838152601860209081526040808320815160608101835288815280840187815242828501908152835460018181018655948852868820935160039091029093019283559051928201929092559051600290910155868352600890915281208054916115dc836151ad565b919050555082847f58f76f0de54ae383f9426c81a1ebabe061a939ba8307bfc74426e84ea67be1db8460405161161491815260200190565b60405180910390a350505050565b5f6001600160a01b03821615806111bf5750506001600160a01b03165f908152600f602052604090205460ff1690565b6015602052815f5260405f20818154811061166b575f80fd5b905f5260205f20015f91509150505481565b3361168f610ebb600160ff1b856150c2565b6001600160a01b031614806116bc57505f82815260116020908152604080832033845290915290205460ff165b6116d85760405162461bcd60e51b8152600401610f2790615314565b5f828152601960209081526040808320848452825291829020600601805460ff19169055905182815283917fb06cc13dfc427822729928fa6cfdbdefc78e001061fe9d6a6c634484e77ebb6b910160405180910390a25050565b6018602052815f5260405f20818154811061174b575f80fd5b5f91825260209091206003909102018054600182015460029092015490935090915083565b5f611782611387600160ff1b846150c2565b156117d257611798610ebb600160ff1b846150c2565b6001600160a01b0316846001600160a01b0316146117c2576117bb848484612e9e565b90506112c6565b6117cd848484612f8b565b6117dd565b6117bb848484612e9e565b5060019392505050565b601960209081525f92835260408084209091529082529020805460018201546002830180546001600160a01b03909316939192611823906151c5565b80601f016020809104026020016040519081016040528092919081815260200182805461184f906151c5565b801561189a5780601f106118715761010080835404028352916020019161189a565b820191905f5260205f20905b81548152906001019060200180831161187d57829003601f168201915b505050600384015460048501546005860154600690960154949560ff9283169591945092501687565b5f818152601d6020526040812054601c805483929081106118e6576118e661533c565b5f9182526020918290206040805160608101825260039390930290910180546001600160a01b039081168085526001830154909116948401859052600290910154838301819052915163246a002160e01b8152600481019190915260248101919091524660448201523060648201526084810186905290925063246a00219060a401602060405180830381865afa158015611983573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112c69190615350565b5f7f000000000000000000000000000000000000000000000000000000000000000146146119d7576113d961368e565b507f45ea0d21ef07f74143cc30ad6335aa59cf794048ea4014c43b79f672da9bbfba90565b611a04613727565b604080516060810182526001600160a01b03938416815293831660208501908152908401918252601c80546001810182555f91909152935160039094027f0e4562a10381dec21b205ed72637e6b1b523bdd0e4d4d50af5cd23dd4500a211810180549585166001600160a01b031996871617905590517f0e4562a10381dec21b205ed72637e6b1b523bdd0e4d4d50af5cd23dd4500a2128201805491909416941693909317909155517f0e4562a10381dec21b205ed72637e6b1b523bdd0e4d4d50af5cd23dd4500a21390910155565b611aee83838360405180602001604052805f815250612b14565b505050565b601c8181548110611b02575f80fd5b5f9182526020909120600390910201805460018201546002909201546001600160a01b03918216935091169083565b611b39613727565b601f805460ff19166001179055565b611b50613727565b6021805460ff19166001179055565b5f6001600160a01b038316611b8757604051635461585f60e01b815260040160405180910390fd5b335f818152600a602090815260408083206001600160a01b03881680855290835292819020869055518581529192917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350600192915050565b5f611bf9600160ff1b836150c2565b5f818152600d60205260409020549092506001600160a01b03169050611c1e82613634565b611c3b576040516307ed98ed60e31b815260040160405180910390fd5b6001600160a01b038116611c625760405163c5723b5160e01b815260040160405180910390fd5b919050565b611c6f61360c565b5f611c79836118c3565b9050336001600160a01b0382161480611caa57505f83815260116020908152604080832033845290915290205460ff165b80611ccd575033611cc2610ebb600160ff1b866150c2565b6001600160a01b0316145b611ce95760405162461bcd60e51b8152600401610f2790615314565b5f848152601460209081526040808320601b83528184208785529092529091205460ff16611d595760405162461bcd60e51b815260206004820152601a60248201527f4167656e74206e6f742061737369676e656420746f207461736b0000000000006044820152606401610f27565b600481015460ff1615611da75760405162461bcd60e51b815260206004820152601660248201527515185cdac8185b1c9958591e4818dbdb5c1b195d195960521b6044820152606401610f27565b8060030154421115611df25760405162461bcd60e51b815260206004820152601460248201527315185cdac8191958591b1a5b99481c185cdcd95960621b6044820152606401610f27565b60048101805460ff19166001179055600581018390555f848152601760205260408120805490918290611e24836151ad565b91905055508160020154816001015f828254611e4091906150c2565b9091555050426002808301919091558201546040515f916001600160a01b038616918381818185875af1925050503d805f8114611e98576040519150601f19603f3d011682016040523d82523d5f602084013e611e9d565b606091505b5050905080611ee75760405162461bcd60e51b815260206004820152601660248201527514995dd85c99081d1c985b9cd9995c8819985a5b195960521b6044820152606401610f27565b85877f339ba61d0494cd9480ac692252c889cdd0184f891856a80a25fc39c7d9f88f7e87604051611f1a91815260200190565b60405180910390a350505050611aee60015f55565b33611f41610ebb600160ff1b866150c2565b6001600160a01b031614611f895760405162461bcd60e51b815260206004820152600f60248201526e2737ba103a37b5b2b71037bbb732b960891b6044820152606401610f27565b5f8381526011602090815260408083206001600160a01b03861680855290835292819020805460ff1916851515908117909155905190815285917fdaaa206caa4ddb9f2b93bf33507d65bc89857c7c11bf52bfbfe83c83043ba6b291015b60405180910390a3505050565b611ffc613727565b6120055f613754565b565b33612019610ebb600160ff1b846150c2565b6001600160a01b0316146120615760405162461bcd60e51b815260206004820152600f60248201526e2737ba103a37b5b2b71037bbb732b960891b6044820152606401610f27565b601c5482106120a25760405162461bcd60e51b815260206004820152600d60248201526c0496e76616c696420736574757609c1b6044820152606401610f27565b5f818152601d602052604090208290556120bc82826137a5565b5050565b5f6120c961360c565b5f8381526019602090815260408083208584529091529020600681015460ff166121295760405162461bcd60e51b8152602060048201526011602482015270416374696f6e206e6f742061637469766560781b6044820152606401610f27565b806004015442101561217d5760405162461bcd60e51b815260206004820152601760248201527f4e6f74207965742074696d6520746f20657865637574650000000000000000006044820152606401610f27565b5f612187856118c3565b825460018401546003850154604051635194544760e01b81529394506001600160a01b03808616946351945447946121cf94921692600289019160ff9091169060040161536b565b5f604051808303815f875af192505050801561220c57506040513d5f823e601f3d908101601f191682016040526122099190810190615139565b60015b612218575f925061221e565b50600192505b5f826005015411801561222e5750825b1561228f57600582015461224290426150c2565b6004830181905560405186917f7d2b37830491f9385a6dbe76832e1224c5f344498e963836ef2ffd590aaa986a9161228291888252602082015260400190565b60405180910390a26122a2565b82156122a25760068201805460ff191690555b60408051858152841515602082015286917f2abcaabda6b6086dffe7c6dba92c8208fba28f2ad62bb562e3ea785849be5e7f910160405180910390a250506111bf60015f55565b5f336122fc610ebb600160ff1b8c6150c2565b6001600160a01b0316148061232957505f89815260116020908152604080832033845290915290205460ff165b6123455760405162461bcd60e51b8152600401610f2790615314565b4283116123a05760405162461bcd60e51b8152602060048201526024808201527f457865637574696f6e2074696d65206d75737420626520696e207468652066756044820152637475726560e01b6064820152608401610f27565b5f898152601a60205260408120805490826123ba836151ad565b9190505590506040518060e001604052808a6001600160a01b0316815260200189815260200188888080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92018290525093855250505060ff8816602080840191909152604080840189905260608401889052600160809094018490528e835260198252808320868452825291829020845181546001600160a01b0319166001600160a01b03909116178155908401519281019290925582015160028201906124899082615416565b50606082015160038201805460ff90921660ff199283161790556080830151600483015560a0830151600583015560c090920151600690910180549115159190921617905560408051828152602081018690528b917f7d2b37830491f9385a6dbe76832e1224c5f344498e963836ef2ffd590aaa986a910160405180910390a29998505050505050505050565b60215460ff166125725760405162461bcd60e51b815260206004820152602160248201527f506c65617365207761697420756e74696c206665617475726520656e61626c656044820152601960fa1b6064820152608401610f27565b61257b816138ca565b50565b60146020525f9081526040902080548190612598906151c5565b80601f01602080910402602001604051908101604052809291908181526020018280546125c4906151c5565b801561260f5780601f106125e65761010080835404028352916020019161260f565b820191905f5260205f20905b8154815290600101906020018083116125f257829003601f168201915b50505050600183015460028401546003850154600486015460059096015494956001600160a01b03909316949193509160ff169086565b606061265061360c565b5f87815260116020908152604080832033845290915290205460ff166126af5760405162461bcd60e51b81526020600482015260146024820152731059d95b9d081b9bdd08185d5d1a1bdc9a5e995960621b6044820152606401610f27565b5f8781526013602052604081204290556126c8886118c3565b905033887f389089e27675162c5830a44541b405635429787635f585fa156f33768cc66d8d6126fa60045f898b6154d0565b612703916154f7565b6040516001600160e01b0319909116815260200160405180910390a3604051635194544760e01b81526001600160a01b03821690635194544790612753908a908a908a908a908a906004016150fd565b5f604051808303815f875af115801561276e573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526127959190810190615139565b915050610fb960015f55565b600580546112da906151c5565b6001600160a01b0382166127d55760405163ccea9e6f60e01b815260040160405180910390fd5b335f818152600c602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b5f6001600160a01b03831661286857604051634e46966960e11b815260040160405180910390fd5b6112c63384846138d4565b6060606482116128835781612886565b60645b5f858152601860205260409020549092508084106128f057604080515f80825260208201909252906128e7565b6128d460405180606001604052805f81526020015f81526020015f81525090565b8152602001906001900390816128b35790505b509150506112c6565b5f6128fb84866150c2565b9050818111156129085750805b5f612913868361552d565b90505f816001600160401b0381111561292e5761292e614e94565b60405190808252806020026020018201604052801561298057816020015b61296d60405180606001604052805f81526020015f81526020015f81525090565b81526020019060019003908161294c5790505b5090505f5b82811015612a0d575f8981526018602052604090206129a4828a6150c2565b815481106129b4576129b461533c565b905f5260205f2090600302016040518060600160405290815f8201548152602001600182015481526020016002820154815250508282815181106129fa576129fa61533c565b6020908102919091010152600101612985565b50979650505050505050565b6001600160a01b0381165f908152600e6020526040812054606091906001600160401b03811115612a4c57612a4c614e94565b604051908082528060200260200182016040528015612a75578160200160208202803683370190505b5090505f5b6001600160a01b0384165f908152600e6020526040902054811015612b0d576001600160a01b0384165f908152600e60205260409020805482908110612ac257612ac261533c565b905f5260205f2090601091828204019190066002029054906101000a900461ffff1661ffff16828281518110612afa57612afa61533c565b6020908102919091010152600101612a7a565b5092915050565b612b25611387600160ff1b846150c2565b612b42576040516307ed98ed60e31b815260040160405180910390fd5b612b4d848484611770565b506001600160a01b0383163b15801590612be35750604051630a85bd0160e11b808252906001600160a01b0385169063150b7a0290612b96903390899088908890600401615540565b6020604051808303815f875af1158015612bb2573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612bd69190615572565b6001600160e01b03191614155b15612c0157604051633da6393160e01b815260040160405180910390fd5b50505050565b612c0f613727565b601e6120bc8282615416565b612c23613727565b6120bc82826139a7565b6060601e612c3a83613a15565b604051602001612c4b9291906155fb565b6040516020818303038152906040529050919050565b42841015612c82576040516305787bdf60e01b815260040160405180910390fd5b612c8b85613634565b15612ca9576040516303e7c1bd60e31b815260040160405180910390fd5b6001600160a01b038616612cd057604051635461585f60e01b815260040160405180910390fd5b5f6001612cdb6119a7565b6001600160a01b038a81165f8181526010602090815260409182902080546001810190915582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98184015280840194909452938d166060840152608083018c905260a083019390935260c08083018b90528151808403909101815260e08301909152805192019190912061190160f01b6101008301526101028201929092526101228101919091526101420160408051601f1981840301815282825280516020918201205f84529083018083525260ff871690820152606081018590526080810184905260a0016020604051602081039080840390855afa158015612de3573d5f5f3e3d5ffd5b5050604051601f1901519150506001600160a01b0381161580612e185750876001600160a01b0316816001600160a01b031614155b15612e3657604051632057875960e21b815260040160405180910390fd5b6001600160a01b039081165f908152600a602090815260408083208a8516808552908352928190208990555188815291928a16917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050505050565b5f6001600160a01b038416612ec657604051636edaef2f60e11b815260040160405180910390fd5b6001600160a01b038316612eed57604051634e46966960e11b815260040160405180910390fd5b6001600160a01b0384165f908152600a602090815260408083203384529091529020545f198114612f675782811015612f39576040516313be252b60e01b815260040160405180910390fd5b612f43838261552d565b6001600160a01b0386165f908152600a602090815260408083203384529091529020555b612f728585856138d4565b95945050505050565b612f83613727565b600654602055565b612f99600160ff1b826150c2565b90506001600160a01b038316612fc257604051636edaef2f60e11b815260040160405180910390fd5b6001600160a01b038216612fe957604051634e46966960e11b815260040160405180910390fd5b5f818152600d60205260409020546001600160a01b03848116911614613021576040516282b42960e81b815260040160405180910390fd5b336001600160a01b0384161480159061305d57506001600160a01b0383165f908152600c6020908152604080832033845290915290205460ff16155b801561307f57505f818152600b60205260409020546001600160a01b03163314155b1561309c576040516282b42960e81b815260040160405180910390fd5b6130a582611622565b156130c357604051635ce7539760e01b815260040160405180910390fd5b6130ee83837f0000000000000000000000000000000000000000000000000de0b6b3a7640000613aa4565b611aee838383613b50565b5f613108600160ff1b836150c2565b5f818152600d60205260409020549092506001600160a01b031633811480159061315557506001600160a01b0381165f908152600c6020908152604080832033845290915290205460ff16155b15613163575f9150506111bf565b5f838152600b6020526040902080546001600160a01b0319166001600160a01b038616179055613197600160ff1b8461552d565b846001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45060019392505050565b6131e9613727565b6001600160a01b03811661321257604051631e4fbdf760e01b81525f6004820152602401610f27565b61257b81613754565b60605f826001600160401b0381111561323657613236614e94565b60405190808252806020026020018201604052801561325f578160200160208202803683370190505b509050835b61326e84866150c2565b8110156132b257613280600282613db4565b61ffff168261328f878461552d565b8151811061329f5761329f61533c565b6020908102919091010152600101613264565b509392505050565b6132c2613727565b600654156133055760405162461bcd60e51b815260206004820152601060248201526f105b1c9958591e481b185d5b98da195960821b6044820152606401610f27565b6133103060016139a7565b5f61333b7f0000000000000000000000000000000000000000000000000de0b6b3a76400008461561d565b6020819055905061334c3082613e63565b305f908152600a602090815260408083207f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b0316845290915290205f199055811561354a577f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133f4573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906134189190615350565b6001600160a01b031663c9c65396307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015613483573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906134a79190615350565b6040516001600160e01b031960e085901b1681526001600160a01b039283166004820152911660248201526044016020604051808303815f875af11580156134f1573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906135159190615350565b60218054610100600160a81b0319166101006001600160a01b039384168102919091179182905561354a9291041660016139a7565b60405163f305d71960e01b8152306004820152602481018290525f6044820181905260648201523360848201524260a48201527f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b03169063f305d71990349060c40160606040518083038185885af11580156135cf573d5f5f3e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906135f49190615634565b5050506064816136049190615673565b602055505050565b60025f540361362e57604051633ee5aeb560e01b815260040160405180910390fd5b60025f55565b5f600160ff1b821180156111bf5750505f19141590565b54600f196001600160401b038083166010908102600160401b850483168203600160c01b8604841601600160801b90950483169091029390930192909203011690565b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60046040516136bf9190615692565b6040805191829003822060208301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b6001546001600160a01b031633146120055760405163118cdaa760e01b8152336004820152602401610f27565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f601c83815481106137b9576137b961533c565b5f9182526020918290206040805160608101825260039390930290910180546001600160a01b0390811680855260018301549091169484018590526002909101548383018190529151638a54c52f60e01b81526004810191909152602481019190915246604482015230606482015260848101859052909250638a54c52f9060a4016020604051808303815f875af1925050508015613875575060408051601f3d908101601f1916820190925261387291810190615350565b60015b612c0157805160408083015181518581526001600160a01b03909316602084015282820152517fa270d820fae88ac2cdc56236bb65d488686ef9c572896ea62d95d0875a6666389181900360600190a1505050565b61257b33826139a7565b601f545f9060ff166138eb576138eb8360016139a7565b6021546001600160a01b0384811661010090920416148015906139115750600654602054105b801561392557506001600160a01b03831615155b15613994576001600160a01b0383165f9081526009602052604081205460205490915061395284836150c2565b11156139925760405162461bcd60e51b815260206004820152600f60248201526e546f6f206d616e7920746f6b656e7360881b6044820152606401610f27565b505b61399f848484613ec7565b949350505050565b6001600160a01b0382166139ce5760405163a41e3d3f60e01b815260040160405180910390fd5b80156139e2576139dd8261433b565b6139eb565b6139eb8261436e565b6001600160a01b03919091165f908152600f60205260409020805460ff1916911515919091179055565b60605f613a21836143f8565b60010190505f816001600160401b03811115613a3f57613a3f614e94565b6040519080825280601f01601f191660200182016040528015613a69576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a8504945084613a7357509392505050565b6001600160a01b038316613ace578060065f828254613ac391906150c2565b90915550613afb9050565b6001600160a01b0383165f9081526009602052604081208054839290613af590849061552d565b90915550505b6001600160a01b038083165f81815260096020526040908190208054850190555190918516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611fe79085815260200190565b6001600160a01b03831615613cae575f818152600b6020908152604080832080546001600160a01b03191690556001600160a01b0386168352600e90915281208054613b9e9060019061552d565b81548110613bae57613bae61533c565b5f9182526020909120601082040154613bdb91600f166002026101000a900461ffff16600160ff1b6150c2565b9050818114613c5c575f828152600d602052604081205460a01c6001600160a01b0386165f908152600e602052604090208054919250839183908110613c2357613c2361533c565b905f5260205f2090601091828204019190066002026101000a81548161ffff021916908361ffff160217905550613c5a82826144cf565b505b6001600160a01b0384165f908152600e60205260409020805480613c8257613c8261569d565b5f8281526020902060105f1990920191820401805461ffff6002600f8516026101000a02191690559055505b6001600160a01b03821615613d52575f818152600d6020526040902080546001600160a01b0319166001600160a01b0384160190556001600160a01b0382165f818152600e60209081526040822080546001808201835582855292842060108204018054600f9092166002026101000a61ffff8181021990931692881602919091179055929091529054613d4d918391613d48919061552d565b6144cf565b613d61565b5f818152600d60205260408120555b613d6f600160ff1b8261552d565b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b5f613dbe8361364b565b613dc990601061561d565b8210613de85760405163580821e760e01b815260040160405180910390fd5b6112c6600184015f601085046010808789546001600160401b03600160401b909104811692909106919091011681613e2257613e2261565f565b88549190046001600160401b03808316919091019290920182168352602083019390935260409091015f205491601091600160401b90910416850106614539565b6001600160a01b038216613e8a57604051634e46966960e11b815260040160405180910390fd5b600160ff1b81600654613e9d91906150c2565b1115613ebc5760405163303b682f60e01b815260040160405180910390fd5b611aee5f83836138d4565b6001600160a01b038381165f90815260096020526040808220549285168252812054909190613ef7868686613aa4565b5f613f0187611622565b90505f613f0d87611622565b9050818015613f195750805b61432d578115614010575f613f4e7f0000000000000000000000000000000000000000000000000de0b6b3a764000085615673565b6001600160a01b0389165f90815260096020526040902054613f91907f0000000000000000000000000000000000000000000000000de0b6b3a764000090615673565b613f9b919061552d565b90506032811115613fee5760405162461bcd60e51b815260206004820152601e60248201527f52657472696576616c2062617463682073697a6520746f6f206c6172676500006044820152606401610f27565b5f5b818110156140095761400189614563565b600101613ff0565b505061432d565b80156140fb576001600160a01b0388165f90815260096020526040812054614059907f0000000000000000000000000000000000000000000000000de0b6b3a764000090615673565b6140837f0000000000000000000000000000000000000000000000000de0b6b3a764000087615673565b61408d919061552d565b905060328111156140e05760405162461bcd60e51b815260206004820152601f60248201527f5769746864726177616c2062617463682073697a6520746f6f206c61726765006044820152606401610f27565b5f5b81811015614009576140f38a61467c565b6001016140e2565b5f6141267f0000000000000000000000000000000000000000000000000de0b6b3a764000088615673565b905060328111156141705760405162461bcd60e51b815260206004820152601460248201527342617463682073697a6520746f6f206c6172676560601b6044820152606401610f27565b5f5b81811015614210576001600160a01b038a165f908152600e602052604081205461419e9060019061552d565b6001600160a01b038c165f908152600e6020526040812080549293509091839081106141cc576141cc61533c565b5f91825260209091206010820401546141f991600f166002026101000a900461ffff16600160ff1b6150c2565b90506142068c8c83613b50565b5050600101614172565b50807f0000000000000000000000000000000000000000000000000de0b6b3a76400006142518b6001600160a01b03165f9081526009602052604090205490565b61425b9190615673565b6142857f0000000000000000000000000000000000000000000000000de0b6b3a764000088615673565b61428f919061552d565b111561429e5761429e8961467c565b806142c97f0000000000000000000000000000000000000000000000000de0b6b3a764000086615673565b7f0000000000000000000000000000000000000000000000000de0b6b3a76400006143088b6001600160a01b03165f9081526009602052604090205490565b6143129190615673565b61431c919061552d565b111561432b5761432b88614563565b505b506001979650505050505050565b6001600160a01b0381165f908152600e6020526040812054905b81811015611aee576143668361467c565b600101614355565b6001600160a01b0381165f908152600960205260408120546143b1907f0000000000000000000000000000000000000000000000000de0b6b3a764000090615673565b90505f6143d2836001600160a01b03165f908152600e602052604090205490565b90505f5b6143e0828461552d565b811015612c01576143f084614563565b6001016143d6565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106144365772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310614462576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061448057662386f26fc10000830492506010015b6305f5e1008310614498576305f5e100830492506008015b61271083106144ac57612710830492506004015b606483106144be576064830492506002015b600a83106111bf5760010192915050565b5f828152600d60205260409020546bffffffffffffffffffffffff82111561450a57604051633f2cd0e360e21b815260040160405180910390fd5b5f928352600d60205260409092206001600160a01b039290921660a09190911b6001600160a01b031916019055565b5f6145458260106156b1565b6001600160401b03166145578361471d565b8416901c905092915050565b6001600160a01b03811661458a57604051634e46966960e11b815260040160405180910390fd5b5f614595600261473e565b6145bc576145a3600261477f565b6145b59061ffff16600160ff1b6150c2565b905061463b565b60075f81546145ca906151ad565b909155506007546001016145f15760405163303b682f60e01b815260040160405180910390fd5b60075461460290600160ff1b6150c2565b601c549091505f906146169060019061552d565b600780545f908152601d60205260409020829055549091506146399082906137a5565b505b5f818152600d60205260409020546001600160a01b031680156146715760405163119b4fd360e11b815260040160405180910390fd5b611aee818484613b50565b6001600160a01b0381166146a357604051636edaef2f60e11b815260040160405180910390fd5b6001600160a01b0381165f908152600e6020526040812080546146c89060019061552d565b815481106146d8576146d861533c565b5f918252602090912060108204015461470591600f166002026101000a900461ffff16600160ff1b6150c2565b9050614712825f83613b50565b6120bc60028261488c565b5f6147298260106156b1565b6001600160401b031661ffff901b9050919050565b80545f90600160c01b81046001600160401b03908116600160401b909204161480156111bf575050546001600160401b03808216600160801b909204161490565b80545f906001600160401b03600160801b8204811691600160c01b810482169116821480156147c1575083546001600160401b03828116600160401b90920416145b156147df576040516375e52f4f60e01b815260040160405180910390fd5b806001600160401b03165f036147fa57505f1901600f6147fe565b5f19015b6001600160401b0382165f9081526001850160205260409020546148228183614539565b935061482f81835f614977565b6001600160401b039384165f81815260018801602052604090209190915585546fffffffffffffffffffffffffffffffff16600160801b9091026001600160c01b031617600160c01b929093169190910291909117909255919050565b81546001600160401b0380821691600160401b9004165f8190036148b557505f1901600f6148b9565b5f19015b83546001600160401b03838116600160801b909204161480156148ef575083546001600160401b03828116600160c01b90920416145b1561490d57604051638acb5f2760e01b815260040160405180910390fd5b6001600160401b0382165f908152600185016020526040902054614932908285614977565b6001600160401b039283165f81815260018701602052604090209190915584546fffffffffffffffffffffffffffffffff191617600160401b91909216021790915550565b5f6149838360106156b1565b6001600160401b03168261ffff16901b61499c8461471d565b19851661399f91906150c2565b6001600160a01b038116811461257b575f5ffd5b5f5f83601f8401126149cd575f5ffd5b5081356001600160401b038111156149e3575f5ffd5b6020830191508360208285010111156149fa575f5ffd5b9250929050565b803560ff81168114611c62575f5ffd5b5f5f5f5f5f5f60a08789031215614a26575f5ffd5b863595506020870135614a38816149a9565b94506040870135935060608701356001600160401b03811115614a59575f5ffd5b614a6589828a016149bd565b9094509250614a78905060808801614a01565b90509295509295509295565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f6112c66020830184614a84565b5f5f60408385031215614ad5575f5ffd5b50508035926020909101359150565b6001600160e01b03198116811461257b575f5ffd5b5f60208284031215614b09575f5ffd5b81356112c681614ae4565b5f60208284031215614b24575f5ffd5b81356112c6816149a9565b5f5f5f60408486031215614b41575f5ffd5b83356001600160401b03811115614b56575f5ffd5b614b62868287016149bd565b909790965060209590950135949350505050565b5f60208284031215614b86575f5ffd5b5035919050565b5f5f60408385031215614b9e575f5ffd5b8235614ba9816149a9565b946020939093013593505050565b5f5f5f60608486031215614bc9575f5ffd5b505081359360208301359350604090920135919050565b5f5f60408385031215614bf1575f5ffd5b823591506020830135614c03816149a9565b809150509250929050565b5f5f5f60608486031215614c20575f5ffd5b8335614c2b816149a9565b92506020840135614c3b816149a9565b929592945050506040919091013590565b60018060a01b038816815286602082015260e060408201525f614c7260e0830188614a84565b905060ff861660608301528460808301528360a083015282151560c083015298975050505050505050565b80358015158114611c62575f5ffd5b5f5f5f60608486031215614cbe575f5ffd5b833592506020840135614cd0816149a9565b9150614cde60408501614c9d565b90509250925092565b5f5f5f5f5f5f5f5f60e0898b031215614cfe575f5ffd5b883597506020890135614d10816149a9565b96506040890135955060608901356001600160401b03811115614d31575f5ffd5b614d3d8b828c016149bd565b9096509450614d50905060808a01614a01565b979a969950949793969295929450505060a08201359160c0013590565b5f60208284031215614d7d575f5ffd5b6112c682614c9d565b60c081525f614d9860c0830189614a84565b6001600160a01b0397909716602083015250604081019490945260608401929092521515608083015260a090910152919050565b5f5f60408385031215614ddd575f5ffd5b8235614de8816149a9565b9150614df660208401614c9d565b90509250929050565b602080825282518282018190525f918401906040840190835b81811015614e5257835180518452602081015160208501526040810151604085015250606083019250602084019350600181019050614e18565b509095945050505050565b602080825282518282018190525f918401906040840190835b81811015614e52578351835260209384019390920191600101614e76565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b0381118282101715614ed057614ed0614e94565b604052919050565b5f6001600160401b03821115614ef057614ef0614e94565b50601f01601f191660200190565b5f614f10614f0b84614ed8565b614ea8565b9050828152838383011115614f23575f5ffd5b828260208301375f602084830101529392505050565b5f5f5f5f60808587031215614f4c575f5ffd5b8435614f57816149a9565b93506020850135614f67816149a9565b92506040850135915060608501356001600160401b03811115614f88575f5ffd5b8501601f81018713614f98575f5ffd5b614fa787823560208401614efe565b91505092959194509250565b5f60208284031215614fc3575f5ffd5b81356001600160401b03811115614fd8575f5ffd5b8201601f81018413614fe8575f5ffd5b61399f84823560208401614efe565b5f5f5f5f5f5f5f60e0888a03121561500d575f5ffd5b8735615018816149a9565b96506020880135615028816149a9565b9550604088013594506060880135935061504460808901614a01565b9699959850939692959460a0840135945060c09093013592915050565b5f5f60408385031215615072575f5ffd5b823561507d816149a9565b91506020830135614c03816149a9565b5f5f6040838503121561509e575f5ffd5b82359150614df660208401614c9d565b634e487b7160e01b5f52601160045260245ffd5b808201808211156111bf576111bf6150ae565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b60018060a01b0386168152846020820152608060408201525f6151246080830185876150d5565b905060ff831660608301529695505050505050565b5f60208284031215615149575f5ffd5b81516001600160401b0381111561515e575f5ffd5b8201601f8101841361516e575f5ffd5b805161517c614f0b82614ed8565b818152856020838501011115615190575f5ffd5b8160208401602083015e5f91810160200191909152949350505050565b5f600182016151be576151be6150ae565b5060010190565b600181811c908216806151d957607f821691505b6020821081036151f757634e487b7160e01b5f52602260045260245ffd5b50919050565b601f821115611aee57805f5260205f20601f840160051c810160208510156152225750805b601f840160051c820191505b81811015615241575f815560010161522e565b5050505050565b6001600160401b0383111561525f5761525f614e94565b6152738361526d83546151c5565b836151fd565b5f601f8411600181146152a4575f851561528d5750838201355b5f19600387901b1c1916600186901b178355615241565b5f83815260208120601f198716915b828110156152d357868501358255602094850194600190920191016152b3565b50868210156152ef575f1960f88860031b161c19848701351681555b505060018560011b0183555050505050565b602081525f61399f6020830184866150d5565b6020808252600e908201526d139bdd08185d5d1a1bdc9a5e995960921b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215615360575f5ffd5b81516112c6816149a9565b6001600160a01b0385168152602081018490526080604082015282545f908190615394816151c5565b806080860152600182165f81146153b257600181146153ce576153ff565b60ff19831660a087015260a082151560051b87010193506153ff565b875f5260205f205f5b838110156153f657815488820160a001526001909101906020016153d7565b870160a0019450505b50505060ff84166060840152905095945050505050565b81516001600160401b0381111561542f5761542f614e94565b6154438161543d84546151c5565b846151fd565b6020601f821160018114615475575f831561545e5750848201515b5f19600385901b1c1916600184901b178455615241565b5f84815260208120601f198516915b828110156154a45787850151825560209485019460019092019101615484565b50848210156154c157868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f5f858511156154de575f5ffd5b838611156154ea575f5ffd5b5050820193919092039150565b80356001600160e01b03198116906004841015612b0d576001600160e01b031960049490940360031b84901b1690921692915050565b818103818111156111bf576111bf6150ae565b6001600160a01b03858116825284166020820152604081018390526080606082018190525f90610fb990830184614a84565b5f60208284031215615582575f5ffd5b81516112c681614ae4565b5f8154615599816151c5565b6001821680156155b057600181146155c5576155f2565b60ff19831686528115158202860193506155f2565b845f5260205f205f5b838110156155ea578154888201526001909101906020016155ce565b505081860193505b50505092915050565b5f615606828561558d565b83518060208601835e5f9101908152949350505050565b80820281158282048414176111bf576111bf6150ae565b5f5f5f60608486031215615646575f5ffd5b5050815160208301516040909301519094929350919050565b634e487b7160e01b5f52601260045260245ffd5b5f8261568d57634e487b7160e01b5f52601260045260245ffd5b500490565b5f6112c6828461558d565b634e487b7160e01b5f52603160045260245ffd5b6001600160401b038181168382160290811690818114612b0d57612b0d6150ae56fea264697066735822122017ad13792872ae57a07f96a15ab44c6a649f5f56ed53091f159b927d1f8acffb64736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: cancun Optimization: Yes (200 runs)
ERCAI.sol 2522 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin/contracts/utils/Create2.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/**
 * @title IERC6551Account
 * @dev Interface for ERC6551 token bound accounts
 */
interface IERC6551Account {
    receive() external payable;

    function token()
        external
        view
        returns (uint256 chainId, address tokenContract, uint256 tokenId);

    function state() external view returns (uint256);

    function isValidSigner(
        address signer,
        bytes calldata context
    ) external view returns (bytes4 magicValue);
}

/**
 * @title IERC6551Executable
 * @dev Interface for ERC6551 execution
 */
interface IERC6551Executable {
    function execute(
        address to,
        uint256 value,
        bytes calldata data,
        uint8 operation
    ) external payable returns (bytes memory);
}

/**
 * @title ERC6551BytecodeLib
 * @dev Library for ERC6551 bytecode operations
 */
library ERC6551BytecodeLib {
    /**
     * @dev Returns the creation code of the token bound account for a non-fungible token.
     *
     * @return result The creation code of the token bound account
     */
    function getCreationCode(
        address implementation,
        bytes32 salt,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId
    ) internal pure returns (bytes memory result) {
        assembly {
            result := mload(0x40) // Grab the free memory pointer
            // Layout the variables and bytecode backwards
            mstore(add(result, 0xb7), tokenId)
            mstore(add(result, 0x97), shr(96, shl(96, tokenContract)))
            mstore(add(result, 0x77), chainId)
            mstore(add(result, 0x57), salt)
            mstore(add(result, 0x37), 0x5af43d82803e903d91602b57fd5bf3)
            mstore(add(result, 0x28), implementation)
            mstore(
                add(result, 0x14),
                0x3d60ad80600a3d3981f3363d3d373d3d3d363d73
            )
            mstore(result, 0xb7) // Store the length
            mstore(0x40, add(result, 0xd7)) // Allocate the memory
        }
    }

    /**
     * @dev Returns the create2 address computed from `salt`, `bytecodeHash`, `deployer`.
     *
     * @return result The create2 address computed from `salt`, `bytecodeHash`, `deployer`
     */
    function computeAddress(
        bytes32 salt,
        bytes32 bytecodeHash,
        address deployer
    ) internal pure returns (address result) {
        assembly {
            result := mload(0x40) // Grab the free memory pointer
            mstore8(result, 0xff)
            mstore(add(result, 0x35), bytecodeHash)
            mstore(add(result, 0x01), shl(96, deployer))
            mstore(add(result, 0x15), salt)
            result := keccak256(result, 0x55)
        }
    }
}

/**
 * @title ERC6551AccountLib
 * @dev Library for ERC6551 account operations
 */
library ERC6551AccountLib {
    function computeAddress(
        address registry,
        address _implementation,
        bytes32 _salt,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId
    ) internal pure returns (address) {
        bytes32 bytecodeHash = keccak256(
            ERC6551BytecodeLib.getCreationCode(
                _implementation,
                _salt,
                chainId,
                tokenContract,
                tokenId
            )
        );

        return Create2.computeAddress(_salt, bytecodeHash, registry);
    }

    function isERC6551Account(
        address account,
        address expectedImplementation,
        address registry
    ) internal view returns (bool) {
        // invalid bytecode size
        if (account.code.length != 0xAD) return false;

        address _implementation = implementation(account);

        // implementation does not exist
        if (_implementation.code.length == 0) return false;

        // invalid implementation
        if (_implementation != expectedImplementation) return false;

        (
            bytes32 _salt,
            uint256 chainId,
            address tokenContract,
            uint256 tokenId
        ) = context(account);

        return
            account ==
            computeAddress(
                registry,
                _implementation,
                _salt,
                chainId,
                tokenContract,
                tokenId
            );
    }

    function implementation(
        address account
    ) internal view returns (address _implementation) {
        assembly {
            // copy proxy implementation (0x14 bytes)
            extcodecopy(account, 0xC, 0xA, 0x14)
            _implementation := mload(0x00)
        }
    }

    function implementation() internal view returns (address _implementation) {
        return implementation(address(this));
    }

    function token(
        address account
    ) internal view returns (uint256, address, uint256) {
        bytes memory encodedData = new bytes(0x60);

        assembly {
            // copy 0x60 bytes from end of context
            extcodecopy(account, add(encodedData, 0x20), 0x4d, 0x60)
        }

        return abi.decode(encodedData, (uint256, address, uint256));
    }

    function token() internal view returns (uint256, address, uint256) {
        return token(address(this));
    }

    function salt(address account) internal view returns (bytes32) {
        bytes memory encodedData = new bytes(0x20);

        assembly {
            // copy 0x20 bytes from beginning of context
            extcodecopy(account, add(encodedData, 0x20), 0x2d, 0x20)
        }

        return abi.decode(encodedData, (bytes32));
    }

    function salt() internal view returns (bytes32) {
        return salt(address(this));
    }

    function context(
        address account
    ) internal view returns (bytes32, uint256, address, uint256) {
        bytes memory encodedData = new bytes(0x80);

        assembly {
            // copy full context (0x80 bytes)
            extcodecopy(account, add(encodedData, 0x20), 0x2D, 0x80)
        }

        return abi.decode(encodedData, (bytes32, uint256, address, uint256));
    }

    function context()
        internal
        view
        returns (bytes32, uint256, address, uint256)
    {
        return context(address(this));
    }
}

/**
 * @title ERC6551Account
 * @dev Implementation of the ERC6551 token bound account
 */
contract ERC6551Account is
    IERC165,
    IERC1271,
    IERC6551Account,
    IERC6551Executable,
    IERC721Receiver,
    IERC1155Receiver
{
    uint256 public state;

    receive() external payable {}

    function execute(
        address to,
        uint256 value,
        bytes calldata data,
        uint8 operation
    ) external payable virtual returns (bytes memory result) {
        require(_isValidSigner(msg.sender), "Invalid signer");
        require(operation == 0, "Only call operations are supported");

        ++state;

        bool success;
        (success, result) = to.call{value: value}(data);

        if (!success) {
            assembly {
                revert(add(result, 32), mload(result))
            }
        }
    }

    function isValidSigner(
        address signer,
        bytes calldata
    ) external view virtual returns (bytes4) {
        if (_isValidSigner(signer)) {
            return IERC6551Account.isValidSigner.selector;
        }

        return bytes4(0);
    }

    function isValidSignature(
        bytes32 hash,
        bytes memory signature
    ) external view virtual returns (bytes4 magicValue) {
        bool isValid = SignatureChecker.isValidSignatureNow(
            owner(),
            hash,
            signature
        );

        if (isValid) {
            return IERC1271.isValidSignature.selector;
        }

        return bytes4(0);
    }

    function onERC721Received(
        address,
        address,
        uint256 receivedTokenId,
        bytes memory
    ) external view virtual returns (bytes4) {
        _revertIfOwnershipCycle(msg.sender, receivedTokenId);
        return IERC721Receiver.onERC721Received.selector;
    }

    function onERC1155Received(
        address,
        address,
        uint256,
        uint256,
        bytes memory
    ) external view virtual returns (bytes4) {
        return IERC1155Receiver.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes memory
    ) external pure virtual returns (bytes4) {
        return IERC1155Receiver.onERC1155BatchReceived.selector;
    }

    function supportsInterface(
        bytes4 interfaceId
    ) public pure virtual returns (bool) {
        return (interfaceId == type(IERC6551Account).interfaceId ||
            interfaceId == type(IERC6551Executable).interfaceId ||
            interfaceId == type(IERC1155Receiver).interfaceId ||
            interfaceId == type(IERC721Receiver).interfaceId ||
            interfaceId == type(IERC165).interfaceId);
    }

    function token()
        public
        view
        virtual
        override
        returns (uint256, address, uint256)
    {
        return ERC6551AccountLib.token();
    }

    function owner() public view virtual returns (address) {
        (uint256 chainId, address contractAddress, uint256 tokenId) = token();
        if (chainId != block.chainid) return address(0);
        return IERCAI(contractAddress).ownerOf(tokenId);
    }

    function _isValidSigner(
        address signer
    ) internal view virtual returns (bool) {
        return signer == owner();
    }

    /**
     * @dev Helper method to check if a received token is in the ownership chain of the wallet.
     * @param receivedTokenAddress The address of the token being received.
     * @param receivedTokenId The ID of the token being received.
     */
    function _revertIfOwnershipCycle(
        address receivedTokenAddress,
        uint256 receivedTokenId
    ) internal view virtual {
        (
            uint256 _chainId,
            address _contractAddress,
            uint256 _tokenId
        ) = token();
        require(
            _chainId != block.chainid ||
                receivedTokenAddress != _contractAddress ||
                receivedTokenId != _tokenId,
            "Cannot own yourself"
        );

        address currentOwner = owner();
        require(currentOwner != address(this), "Token in ownership chain");
        uint256 depth = 0;
        while (currentOwner.code.length > 0) {
            try IERC6551Account(payable(currentOwner)).token() returns (
                uint256 chainId,
                address contractAddress,
                uint256 tokenId
            ) {
                require(
                    chainId != block.chainid ||
                        contractAddress != receivedTokenAddress ||
                        tokenId != receivedTokenId,
                    "Token in ownership chain"
                );
                // Advance up the ownership chain
                currentOwner = IERCAI(contractAddress).ownerOf(tokenId);
                require(
                    currentOwner != address(this),
                    "Token in ownership chain"
                );
            } catch {
                break;
            }
            unchecked {
                ++depth;
            }
            if (depth == 5) revert("Ownership chain too deep");
        }
    }
}

/**
 * @title IERC6551Registry
 * @dev Interface for ERC6551 registry
 */
interface IERC6551Registry {
    /**
     * @dev The registry MUST emit the ERC6551AccountCreated event upon successful account creation.
     */
    event ERC6551AccountCreated(
        address account,
        address indexed implementation,
        bytes32 salt,
        uint256 chainId,
        address indexed tokenContract,
        uint256 indexed tokenId
    );

    /**
     * @dev The registry MUST revert with AccountCreationFailed error if the create2 operation fails.
     */
    error AccountCreationFailed();

    /**
     * @dev Creates a token bound account for a non-fungible token.
     *
     * If account has already been created, returns the account address without calling create2.
     *
     * Emits ERC6551AccountCreated event.
     *
     * @return account The address of the token bound account
     */
    function createAccount(
        address implementation,
        bytes32 salt,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId
    ) external returns (address account);

    /**
     * @dev Returns the computed token bound account address for a non-fungible token.
     *
     * @return account The address of the token bound account
     */
    function account(
        address implementation,
        bytes32 salt,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId
    ) external view returns (address account);
}

/**
 * @title ERC6551Registry
 * @dev Implementation of the ERC6551 registry
 */
contract ERC6551Registry is IERC6551Registry, Ownable {
    constructor() Ownable(msg.sender) {}

    function createAccount(
        address implementation,
        bytes32 salt,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId
    ) external returns (address) {
        assembly {
            // Memory Layout:
            // ----
            // 0x00   0xff                           (1 byte)
            // 0x01   registry (address)             (20 bytes)
            // 0x15   salt (bytes32)                 (32 bytes)
            // 0x35   Bytecode Hash (bytes32)        (32 bytes)
            // ----
            // 0x55   ERC-1167 Constructor + Header  (20 bytes)
            // 0x69   implementation (address)       (20 bytes)
            // 0x5D   ERC-1167 Footer                (15 bytes)
            // 0x8C   salt (uint256)                 (32 bytes)
            // 0xAC   chainId (uint256)              (32 bytes)
            // 0xCC   tokenContract (address)        (32 bytes)
            // 0xEC   tokenId (uint256)              (32 bytes)

            // Silence unused variable warnings
            pop(chainId)

            // Copy bytecode + constant data to memory
            calldatacopy(0x8c, 0x24, 0x80) // salt, chainId, tokenContract, tokenId
            mstore(0x6c, 0x5af43d82803e903d91602b57fd5bf3) // ERC-1167 footer
            mstore(0x5d, implementation) // implementation
            mstore(0x49, 0x3d60ad80600a3d3981f3363d3d373d3d3d363d73) // ERC-1167 constructor + header

            // Copy create2 computation data to memory
            mstore8(0x00, 0xff) // 0xFF
            mstore(0x35, keccak256(0x55, 0xb7)) // keccak256(bytecode)
            mstore(0x01, shl(96, address())) // registry address
            mstore(0x15, salt) // salt

            // Compute account address
            let computed := keccak256(0x00, 0x55)

            // If the account has not yet been deployed
            if iszero(extcodesize(computed)) {
                // Deploy account contract
                let deployed := create2(0, 0x55, 0xb7, salt)

                // Revert if the deployment fails
                if iszero(deployed) {
                    mstore(0x00, 0x20188a59) // `AccountCreationFailed()`
                    revert(0x1c, 0x04)
                }

                // Store account address in memory before salt and chainId
                mstore(0x6c, deployed)

                // Emit the ERC6551AccountCreated event
                log4(
                    0x6c,
                    0x60,
                    // `ERC6551AccountCreated(address,address,bytes32,uint256,address,uint256)`
                    0x79f19b3655ee38b1ce526556b7731a20c8f218fbda4a3990b6cc4172fdf88722,
                    implementation,
                    tokenContract,
                    tokenId
                )

                // Return the account address
                return(0x6c, 0x20)
            }

            // Otherwise, return the computed account address
            mstore(0x00, shr(96, shl(96, computed)))
            return(0x00, 0x20)
        }
    }

    function cid() external view returns (uint256) {
        return block.chainid;
    }

    function account(
        address implementation,
        bytes32 salt,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId
    ) external view returns (address) {
        assembly {
            // Silence unused variable warnings
            pop(chainId)
            pop(tokenContract)
            pop(tokenId)

            // Copy bytecode + constant data to memory
            calldatacopy(0x8c, 0x24, 0x80) // salt, chainId, tokenContract, tokenId
            mstore(0x6c, 0x5af43d82803e903d91602b57fd5bf3) // ERC-1167 footer
            mstore(0x5d, implementation) // implementation
            mstore(0x49, 0x3d60ad80600a3d3981f3363d3d373d3d3d363d73) // ERC-1167 constructor + header

            // Copy create2 computation data to memory
            mstore8(0x00, 0xff) // 0xFF
            mstore(0x35, keccak256(0x55, 0xb7)) // keccak256(bytecode)
            mstore(0x01, shl(96, address())) // registry address
            mstore(0x15, salt) // salt

            // Store computed account address in memory
            mstore(0x00, shr(96, shl(96, keccak256(0x00, 0x55))))

            // Return computed account address
            return(0x00, 0x20)
        }
    }
}

/**
 * @title IERCAI
 * @dev Interface for ERCAI token
 */
interface IERCAI is IERC165 {
    error NotFound();
    error InvalidTokenId();
    error AlreadyExists();
    error InvalidRecipient();
    error InvalidSender();
    error InvalidSpender();
    error InvalidOperator();
    error UnsafeRecipient();
    error RecipientIsERC721TransferExempt();
    error Unauthorized();
    error InsufficientAllowance();
    error DecimalsTooLow();
    error PermitDeadlineExpired();
    error InvalidSigner();
    error InvalidApproval();
    error OwnedIndexOverflow();
    error MintLimitReached();
    error InvalidExemption();

    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);

    function totalSupply() external view returns (uint256);

    function erc20TotalSupply() external view returns (uint256);

    function erc721TotalSupply() external view returns (uint256);

    function balanceOf(address owner_) external view returns (uint256);

    function erc721BalanceOf(address owner_) external view returns (uint256);

    function erc20BalanceOf(address owner_) external view returns (uint256);

    function erc721TransferExempt(
        address account_
    ) external view returns (bool);

    function isApprovedForAll(
        address owner_,
        address operator_
    ) external view returns (bool);

    function allowance(
        address owner_,
        address spender_
    ) external view returns (uint256);

    function owned(address owner_) external view returns (uint256[] memory);

    function ownerOf(uint256 id_) external view returns (address erc721Owner);

    function tokenURI(uint256 id_) external view returns (string memory);

    function approve(
        address spender_,
        uint256 valueOrId_
    ) external returns (bool);

    function erc20Approve(
        address spender_,
        uint256 value_
    ) external returns (bool);

    function erc721Approve(
        address spender_,
        uint256 id_
    ) external returns (bool);

    function setApprovalForAll(address operator_, bool approved_) external;

    function transferFrom(
        address from_,
        address to_,
        uint256 valueOrId_
    ) external returns (bool);

    function erc20TransferFrom(
        address from_,
        address to_,
        uint256 value_
    ) external returns (bool);

    function erc721TransferFrom(
        address from_,
        address to_,
        uint256 id_
    ) external;

    function transfer(address to_, uint256 amount_) external returns (bool);

    function getERC721QueueLength() external view returns (uint256);

    function getERC721TokensInQueue(
        uint256 start_,
        uint256 count_
    ) external view returns (uint256[] memory);

    function setSelfERC721TransferExempt(bool state_) external;

    function safeTransferFrom(address from_, address to_, uint256 id_) external;

    function safeTransferFrom(
        address from_,
        address to_,
        uint256 id_,
        bytes calldata data_
    ) external;

    function DOMAIN_SEPARATOR() external view returns (bytes32);

    function permit(
        address owner_,
        address spender_,
        uint256 value_,
        uint256 deadline_,
        uint8 v_,
        bytes32 r_,
        bytes32 s_
    ) external;
}

/**
 * @title PackedDoubleEndedQueue
 * @dev Library for managing double-ended queues with packed uint16 values
 */
library PackedDoubleEndedQueue {
    uint128 constant SLOT_MASK = (1 << 64) - 1;
    uint128 constant INDEX_MASK = SLOT_MASK << 64;

    uint256 constant SLOT_DATA_MASK = (1 << 16) - 1;

    /**
     * @dev An operation (e.g. {front}) couldn't be completed due to the queue being empty.
     */
    error QueueEmpty();

    /**
     * @dev A push operation couldn't be completed due to the queue being full.
     */
    error QueueFull();

    /**
     * @dev An operation (e.g. {at}) couldn't be completed due to an index being out of bounds.
     */
    error QueueOutOfBounds();

    /**
     * @dev Invalid slot.
     */
    error InvalidSlot();

    /**
     * @dev Indices and slots are 64 bits to fit within a single storage slot.
     *
     * Struct members have an underscore prefix indicating that they are "private" and should not be read or written to
     * directly. Use the functions provided below instead. Modifying the struct manually may violate assumptions and
     * lead to unexpected behavior.
     *
     * The first item is at data[begin] and the last item is at data[end - 1]. This range can wrap around.
     */
    struct Uint16Deque {
        uint64 _beginIndex;
        uint64 _beginSlot;
        uint64 _endIndex;
        uint64 _endSlot;
        mapping(uint64 index => uint256) _data;
    }

    /**
     * @dev Removes the item at the end of the queue and returns it.
     *
     * Reverts with {QueueEmpty} if the queue is empty.
     */
    function popBack(
        Uint16Deque storage deque
    ) internal returns (uint16 value) {
        unchecked {
            uint64 backIndex = deque._endIndex;
            uint64 backSlot = deque._endSlot;

            if (backIndex == deque._beginIndex && backSlot == deque._beginSlot)
                revert QueueEmpty();

            if (backSlot == 0) {
                --backIndex;
                backSlot = 15;
            } else {
                --backSlot;
            }

            uint256 data = deque._data[backIndex];

            value = _getEntry(data, backSlot);
            deque._data[backIndex] = _setData(data, backSlot, 0);

            deque._endIndex = backIndex;
            deque._endSlot = backSlot;
        }
    }

    /**
     * @dev Inserts an item at the beginning of the queue.
     *
     * Reverts with {QueueFull} if the queue is full.
     */
    function pushFront(Uint16Deque storage deque, uint16 value_) internal {
        unchecked {
            uint64 frontIndex = deque._beginIndex;
            uint64 frontSlot = deque._beginSlot;

            if (frontSlot == 0) {
                --frontIndex;
                frontSlot = 15;
            } else {
                --frontSlot;
            }

            if (frontIndex == deque._endIndex && frontSlot == deque._endSlot)
                revert QueueFull();

            deque._data[frontIndex] = _setData(
                deque._data[frontIndex],
                frontSlot,
                value_
            );
            deque._beginIndex = frontIndex;
            deque._beginSlot = frontSlot;
        }
    }

    /**
     * @dev Return the item at a position in the queue given by `index`, with the first item at 0 and last item at
     * `length(deque) - 1`.
     *
     * Reverts with `QueueOutOfBounds` if the index is out of bounds.
     */
    function at(
        Uint16Deque storage deque,
        uint256 index_
    ) internal view returns (uint16 value) {
        if (index_ >= length(deque) * 16) revert QueueOutOfBounds();

        unchecked {
            return
                _getEntry(
                    deque._data[
                        deque._beginIndex +
                            uint64(deque._beginSlot + (index_ % 16)) /
                            16 +
                            uint64(index_ / 16)
                    ],
                    uint64(((deque._beginSlot + index_) % 16))
                );
        }
    }

    /**
     * @dev Returns the number of items in the queue.
     */
    function length(Uint16Deque storage deque) internal view returns (uint256) {
        unchecked {
            return
                (16 - deque._beginSlot) +
                deque._endSlot +
                deque._endIndex *
                16 -
                deque._beginIndex *
                16 -
                16;
        }
    }

    /**
     * @dev Returns true if the queue is empty.
     */
    function empty(Uint16Deque storage deque) internal view returns (bool) {
        return
            deque._endSlot == deque._beginSlot &&
            deque._endIndex == deque._beginIndex;
    }

    function _setData(
        uint256 data_,
        uint64 slot_,
        uint16 value
    ) private pure returns (uint256) {
        return
            (data_ & (~_getSlotMask(slot_))) + (uint256(value) << (16 * slot_));
    }

    function _getEntry(
        uint256 data,
        uint64 slot_
    ) private pure returns (uint16) {
        return uint16((data & _getSlotMask(slot_)) >> (16 * slot_));
    }

    function _getSlotMask(uint64 slot_) private pure returns (uint256) {
        return SLOT_DATA_MASK << (slot_ * 16);
    }
}

/**
 * @title ERC721Events
 * @dev Events for ERC721 token standard
 */
library ERC721Events {
    event ApprovalForAll(
        address indexed owner,
        address indexed operator,
        bool approved
    );
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 indexed id
    );
    event Transfer(
        address indexed from,
        address indexed to,
        uint256 indexed id
    );
}

/**
 * @title ERC20Events
 * @dev Events for ERC20 token standard
 */
library ERC20Events {
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
    event Transfer(address indexed from, address indexed to, uint256 amount);
}


abstract contract ERCAICore is IERCAI, ReentrancyGuard, Ownable {
    using PackedDoubleEndedQueue for PackedDoubleEndedQueue.Uint16Deque;

    // Agent task and performance tracking
    struct Task {
        string description;
        address requester;
        uint256 reward;
        uint256 deadline;
        bool completed;
        bytes32 outcome;
    }

    struct AgentPerformance {
        uint256 tasksCompleted;
        uint256 rewardsEarned;
        uint256 lastActiveTimestamp;
    }

    struct AgentMessage {
        uint256 fromTokenId;
        bytes32 message;
        uint256 timestamp;
    }

    struct ScheduledAction {
        address to;
        uint256 value;
        bytes data;
        uint8 operation;
        uint256 nextExecutionTime;
        uint256 interval; // 0 for one-time, >0 for recurring (in seconds)
        bool active;
    }

    /// @dev The queue of ERC-721 tokens stored in the contract.
    PackedDoubleEndedQueue.Uint16Deque private _storedERC721Ids;

    /// @dev Token name
    string public name;

    /// @dev Token symbol
    string public symbol;

    /// @dev Decimals for ERC-20 representation
    uint8 public immutable decimals;

    /// @dev Units for ERC-20 representation
    uint256 public immutable units;

    /// @dev Total supply in ERC-20 representation
    uint256 public totalSupply;

    /// @dev Current mint counter which also represents the highest
    ///      minted id, monotonically increasing to ensure accurate ownership
    uint256 public minted;

    /// @dev Initial chain id for EIP-2612 support
    uint256 internal immutable _INITIAL_CHAIN_ID;

    uint256 constant MAX_BATCH_SIZE = 50;

    uint256 constant MAX_TASKS_PER_AGENT = 100;

    uint256 constant MAX_MESSAGES_PER_AGENT = 1000;

    /// @dev Initial domain separator for EIP-2612 support
    bytes32 internal immutable _INITIAL_DOMAIN_SEPARATOR;

    mapping(uint256 => uint256) public messagesSentCount; // Tracks messages sent by each token

    /// @dev Balance of user in ERC-20 representation
    mapping(address => uint256) public balanceOf;

    /// @dev Allowance of user in ERC-20 representation
    mapping(address => mapping(address => uint256)) public allowance;

    /// @dev Approval in ERC-721 representaion
    mapping(uint256 => address) public getApproved;

    /// @dev Approval for all in ERC-721 representation
    mapping(address => mapping(address => bool)) public isApprovedForAll;

    /// @dev Packed representation of ownerOf and owned indices
    mapping(uint256 => uint256) internal _ownedData;

    /// @dev Array of owned ids in ERC-721 representation
    mapping(address => uint16[]) internal _owned;

    /// @dev Addresses that are exempt from ERC-721 transfer, typically for gas savings (pairs, routers, etc)
    mapping(address => bool) internal _erc721TransferExempt;

    /// @dev EIP-2612 nonces
    mapping(address => uint256) public nonces;

    /// @dev Address bitmask for packed ownership data
    uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;

    /// @dev Owned index bitmask for packed ownership data
    uint256 private constant _BITMASK_OWNED_INDEX = ((1 << 96) - 1) << 160;

    /// @dev Constant for token id encoding
    uint256 public constant ID_ENCODING_PREFIX = 1 << 255;

    uint256 public constant MAX_SENT_MESSAGES_PER_AGENT = 1000;

    /// @dev Agent authorization system
    mapping(uint256 => mapping(address => bool)) public authorizedAgents;

    /// @dev Agent instruction storage
    mapping(uint256 => bytes32) public agentInstructions;

    /// @dev Agent last action tracking
    mapping(uint256 => uint256) public lastActionTimestamp;

    /// @dev Task management
    mapping(uint256 => Task) public tasks;
    mapping(uint256 => uint256[]) public agentAssignedTasks;
    uint256 public nextTaskId;

    /// @dev Agent performance tracking
    mapping(uint256 => AgentPerformance) public agentPerformance;

    /// @dev Agent communication
    mapping(uint256 => AgentMessage[]) public agentMessages;

    /// @dev Scheduled actions
    mapping(uint256 => mapping(uint256 => ScheduledAction))
        public scheduledActions;
    mapping(uint256 => uint256) public nextActionId;

    mapping(uint256 => mapping(uint256 => bool)) public agentTaskAssignments; // taskId => agentId => isAssigned

    /// @dev struct for changeable 6551 setups
    struct ERCAISetup {
        ERC6551Account implementation;
        ERC6551Registry registry;
        bytes32 salt;
    }

    /// @dev storage for each 6551 setup
    ERCAISetup[] public setup;

    /// @dev 6551 setup set for each NFT
    mapping(uint256 => uint256) public nft_setup_set;

    // Events for agent functionality

    event AccountCreationFailed(
        uint256 tokenId,
        address implementation,
        bytes32 salt
    );

    event TaskCreated(
        uint256 indexed taskId,
        address indexed requester,
        string description
    );
    event TaskAssigned(uint256 indexed taskId, uint256 indexed agentId);
    event TaskCompleted(
        uint256 indexed taskId,
        uint256 indexed agentId,
        bytes32 outcome
    );
    event AgentMessageSent(
        uint256 indexed fromTokenId,
        uint256 indexed toTokenId,
        bytes32 message
    );
    event AgentAuthorized(
        uint256 indexed tokenId,
        address indexed agent,
        bool status
    );
    event AgentActionExecuted(
        uint256 indexed tokenId,
        address indexed executor,
        bytes4 functionSelector
    );
    event ActionScheduled(
        uint256 indexed tokenId,
        uint256 actionId,
        uint256 nextExecutionTime
    );
    event ActionCancelled(uint256 indexed tokenId, uint256 actionId);
    event ActionExecuted(
        uint256 indexed tokenId,
        uint256 actionId,
        bool success
    );

    constructor(string memory name_, string memory symbol_, uint8 decimals_) {
        name = name_;
        symbol = symbol_;

        if (decimals_ < 18) {
            revert DecimalsTooLow();
        }

        decimals = decimals_;
        units = 10 ** decimals;

        // EIP-2612 initialization
        _INITIAL_CHAIN_ID = block.chainid;
        _INITIAL_DOMAIN_SEPARATOR = _computeDomainSeparator();
    }

    /**
     * @notice Get the token bound account address for a token ID
     * @param id_ The token ID
     * @return The token bound account address
     */
    function account(uint256 id_) public view returns (address) {
        ERCAISetup memory s = setup[nft_setup_set[id_]];
        return
            s.registry.account(
                address(s.implementation),
                s.salt,
                block.chainid,
                address(this),
                id_
            );
    }

    /**
     * @notice Execute an action through a token bound account
     * @param id_ The token ID
     * @param to The target address
     * @param value The value to send
     * @param data The call data
     * @param operation The operation type
     * @return result The result of the execution
     */
    function execute(
        uint256 id_,
        address to,
        uint256 value,
        bytes calldata data,
        uint8 operation
    ) external payable nonReentrant returns (bytes memory result) {
        require(
            msg.sender == _getOwnerOf(id_ + ID_ENCODING_PREFIX),
            "Not the token owner"
        );
        return
            ERC6551Account(payable(account(id_))).execute(
                to,
                value,
                data,
                operation
            );
    }

    /**
     * @notice Authorize an agent to act on behalf of a token
     * @param tokenId The token ID
     * @param agent The agent address
     * @param authorized Whether to authorize or deauthorize
     */
    function authorizeAgent(
        uint256 tokenId,
        address agent,
        bool authorized
    ) external {
        require(
            _getOwnerOf(tokenId + ID_ENCODING_PREFIX) == msg.sender,
            "Not token owner"
        );
        authorizedAgents[tokenId][agent] = authorized;
        emit AgentAuthorized(tokenId, agent, authorized);
    }

    /**
     * @notice Execute an action as an authorized agent
     * @param tokenId The token ID
     * @param to The target address
     * @param value The value to send
     * @param data The call data
     * @param operation The operation type
     * @return result The result of the execution
     */
    function executeAsAgent(
        uint256 tokenId,
        address to,
        uint256 value,
        bytes calldata data,
        uint8 operation
    ) external nonReentrant returns (bytes memory result) {
        require(authorizedAgents[tokenId][msg.sender], "Agent not authorized");

        // Update last action timestamp
        lastActionTimestamp[tokenId] = block.timestamp;

        // Execute the action through the token bound account
        address tba = account(tokenId);

        // Emit event for monitoring
        emit AgentActionExecuted(tokenId, msg.sender, bytes4(data[:4]));

        // Execute the call through the token bound account
        return ERC6551Account(payable(tba)).execute(to, value, data, operation);
    }

    /**
     * @notice Create a new task
     * @param description The task description
     * @param deadline The task deadline
     * @return taskId The ID of the created task
     */
    function createTask(
        string calldata description,
        uint256 deadline
    ) external payable nonReentrant returns (uint256) {
        require(deadline > block.timestamp, "Deadline must be in the future");

        uint256 taskId = nextTaskId++;
        Task storage newTask = tasks[taskId];
        newTask.description = description;
        newTask.requester = msg.sender;
        newTask.reward = msg.value;
        newTask.deadline = deadline;
        newTask.completed = false;

        emit TaskCreated(taskId, msg.sender, description);
        return taskId;
    }

    /**
     * @notice Assign a task to an agent
     * @param taskId The task ID
     * @param agentId The agent (token) ID
     */
    function assignTask(uint256 taskId, uint256 agentId) external {
        require(
            agentAssignedTasks[agentId].length < MAX_TASKS_PER_AGENT,
            "Too many tasks for agent"
        );
        require(
            _getOwnerOf(agentId + ID_ENCODING_PREFIX) == msg.sender,
            "Not agent owner"
        );

        Task storage task = tasks[taskId];
        require(!task.completed, "Task already completed");
        require(block.timestamp < task.deadline, "Task deadline passed");

        agentAssignedTasks[agentId].push(taskId);
        agentTaskAssignments[taskId][agentId] = true;

        emit TaskAssigned(taskId, agentId);
    }

    /**
     * @notice Complete a task
     * @param taskId The task ID
     * @param agentId The agent (token) ID
     * @param outcome The task outcome
     */
    function completeTask(
        uint256 taskId,
        uint256 agentId,
        bytes32 outcome
    ) external nonReentrant {
        address tba = account(agentId);
        require(
            msg.sender == tba ||
                authorizedAgents[agentId][msg.sender] ||
                _getOwnerOf(agentId + ID_ENCODING_PREFIX) == msg.sender,
            "Not authorized"
        );

        Task storage task = tasks[taskId];

        require(
            agentTaskAssignments[taskId][agentId],
            "Agent not assigned to task"
        );

        require(!task.completed, "Task already completed");

        require(block.timestamp <= task.deadline, "Task deadline passed");

        // Mark task as completed
        task.completed = true;
        task.outcome = outcome;

        // Update agent performance
        AgentPerformance storage performance = agentPerformance[agentId];
        performance.tasksCompleted++;
        performance.rewardsEarned += task.reward;
        performance.lastActiveTimestamp = block.timestamp;

        // Transfer reward to the token-bound account
        (bool success, ) = tba.call{value: task.reward}("");
        require(success, "Reward transfer failed");

        emit TaskCompleted(taskId, agentId, outcome);
    }

    /**
     * @notice Send a message from one agent to another
     * @param fromTokenId The sender token ID
     * @param toTokenId The recipient token ID
     * @param message The message content
     */
    function sendAgentMessage(
        uint256 fromTokenId,
        uint256 toTokenId,
        bytes32 message
    ) external {
        // Verify recipient exists
        require(toTokenId <= minted, "Recipient token does not exist");
        address fromTba = account(fromTokenId);

        require(
            agentMessages[toTokenId].length < MAX_MESSAGES_PER_AGENT,
            "Too many messages for recipient"
        );

        // Check to limit how many messages a sender can send
        require(
            messagesSentCount[fromTokenId] < MAX_SENT_MESSAGES_PER_AGENT,
            "Sender has sent too many messages"
        );

        require(
            msg.sender == fromTba ||
                authorizedAgents[fromTokenId][msg.sender] ||
                _getOwnerOf(fromTokenId + ID_ENCODING_PREFIX) == msg.sender,
            "Not authorized"
        );

        agentMessages[toTokenId].push(
            AgentMessage({
                fromTokenId: fromTokenId,
                message: message,
                timestamp: block.timestamp
            })
        );

        // Increment the sender's message count
        messagesSentCount[fromTokenId]++;

        emit AgentMessageSent(fromTokenId, toTokenId, message);
    }

    /**
     * @notice Get messages for a token
     * @param tokenId The token ID
     * @param startIndex The starting index
     * @param count The number of messages to return
     * @return messages The requested messages
     */
    function getAgentMessages(
        uint256 tokenId,
        uint256 startIndex,
        uint256 count
    ) external view returns (AgentMessage[] memory) {
        // Limit maximum messages per request
        count = count > 100 ? 100 : count;

        uint256 totalMessages = agentMessages[tokenId].length;

        if (startIndex >= totalMessages) {
            return new AgentMessage[](0);
        }

        uint256 endIndex = startIndex + count;
        if (endIndex > totalMessages) {
            endIndex = totalMessages;
        }

        uint256 resultCount = endIndex - startIndex;
        AgentMessage[] memory messages = new AgentMessage[](resultCount);

        for (uint256 i = 0; i < resultCount; i++) {
            messages[i] = agentMessages[tokenId][startIndex + i];
        }

        return messages;
    }

    /**
     * @notice Schedule an action for future execution
     * @param tokenId The token ID
     * @param to The target address
     * @param value The value to send
     * @param data The call data
     * @param operation The operation type
     * @param executionTime The execution time
     * @param interval The interval for recurring actions (0 for one-time)
     * @return actionId The ID of the scheduled action
     */
    function scheduleAction(
        uint256 tokenId,
        address to,
        uint256 value,
        bytes calldata data,
        uint8 operation,
        uint256 executionTime,
        uint256 interval
    ) external returns (uint256) {
        require(
            _getOwnerOf(tokenId + ID_ENCODING_PREFIX) == msg.sender ||
                authorizedAgents[tokenId][msg.sender],
            "Not authorized"
        );
        require(
            executionTime > block.timestamp,
            "Execution time must be in the future"
        );

        uint256 actionId = nextActionId[tokenId]++;

        scheduledActions[tokenId][actionId] = ScheduledAction({
            to: to,
            value: value,
            data: data,
            operation: operation,
            nextExecutionTime: executionTime,
            interval: interval,
            active: true
        });

        emit ActionScheduled(tokenId, actionId, executionTime);
        return actionId;
    }

    /**
     * @notice Cancel a scheduled action
     * @param tokenId The token ID
     * @param actionId The action ID
     */
    function cancelScheduledAction(uint256 tokenId, uint256 actionId) external {
        require(
            _getOwnerOf(tokenId + ID_ENCODING_PREFIX) == msg.sender ||
                authorizedAgents[tokenId][msg.sender],
            "Not authorized"
        );

        scheduledActions[tokenId][actionId].active = false;
        emit ActionCancelled(tokenId, actionId);
    }

    /**
     * @notice Execute a scheduled action
     * @param tokenId The token ID
     * @param actionId The action ID
     * @return success Whether the execution was successful
     */
    function executeScheduledAction(
        uint256 tokenId,
        uint256 actionId
    ) external nonReentrant returns (bool success) {
        ScheduledAction storage action = scheduledActions[tokenId][actionId];

        require(action.active, "Action not active");
        require(
            block.timestamp >= action.nextExecutionTime,
            "Not yet time to execute"
        );

        address tba = account(tokenId);

        // Attempt to execute the action
        try
            ERC6551Account(payable(tba)).execute(
                action.to,
                action.value,
                action.data,
                action.operation
            )
        {
            success = true;
        } catch {
            success = false;
        }

        // Update for recurring actions
        if (action.interval > 0 && success) {
            action.nextExecutionTime = block.timestamp + action.interval;
            emit ActionScheduled(tokenId, actionId, action.nextExecutionTime);
        } else if (success) {
            // One-time action completed, deactivate
            action.active = false;
        }

        emit ActionExecuted(tokenId, actionId, success);
        return success;
    }

    /// @notice Function to find owner of a given ERC-721 token
    function ownerOf(
        uint256 id_
    ) public view virtual returns (address erc721Owner) {
        id_ += ID_ENCODING_PREFIX;
        erc721Owner = _getOwnerOf(id_);

        if (!_isValidTokenId(id_)) {
            revert InvalidTokenId();
        }

        if (erc721Owner == address(0)) {
            revert NotFound();
        }
    }

    function owned(
        address owner_
    ) public view virtual returns (uint256[] memory) {
        uint256[] memory ownedAsU256 = new uint256[](_owned[owner_].length);

        for (uint256 i = 0; i < _owned[owner_].length; ) {
            ownedAsU256[i] = _owned[owner_][i];

            unchecked {
                ++i;
            }
        }

        return ownedAsU256;
    }

    function erc721BalanceOf(
        address owner_
    ) public view virtual returns (uint256) {
        return _owned[owner_].length;
    }

    function erc20BalanceOf(
        address owner_
    ) public view virtual returns (uint256) {
        return balanceOf[owner_];
    }

    function erc20TotalSupply() public view virtual returns (uint256) {
        return totalSupply;
    }

    function erc721TotalSupply() public view virtual returns (uint256) {
        return minted;
    }

    function getERC721QueueLength() public view virtual returns (uint256) {
        return _storedERC721Ids.length();
    }

    function getERC721TokensInQueue(
        uint256 start_,
        uint256 count_
    ) public view virtual returns (uint256[] memory) {
        uint256[] memory tokensInQueue = new uint256[](count_);

        for (uint256 i = start_; i < start_ + count_; ) {
            tokensInQueue[i - start_] = _storedERC721Ids.at(i);

            unchecked {
                ++i;
            }
        }

        return tokensInQueue;
    }

    /// @notice tokenURI must be implemented by child contract
    function tokenURI(uint256 id_) public view virtual returns (string memory);

    /// @notice Function for token approvals
    /// @dev This function assumes the operator is attempting to approve an ERC-721
    ///      if valueOrId is less than the minted count. Unlike setApprovalForAll,
    ///      spender_ must be allowed to be 0x0 so that approval can be revoked.
    function approve(
        address spender_,
        uint256 valueOrId_
    ) public virtual returns (bool) {
        // The ERC-721 tokens are 1-indexed, so 0 is not a valid id and indicates that
        // operator is attempting to set the ERC-20 allowance to 0.
        if (valueOrId_ >= ID_ENCODING_PREFIX)
            return erc20Approve(spender_, valueOrId_);
        if (_isValidTokenId(valueOrId_ + ID_ENCODING_PREFIX)) {
            bool auth = erc721Approve(spender_, valueOrId_);
            // If ERC-721 exists but sender is not authorised then default to ERC-20
            if (!auth) return erc20Approve(spender_, valueOrId_);
        } else {
            return erc20Approve(spender_, valueOrId_);
        }

        return true;
    }

    function erc721Approve(
        address spender_,
        uint256 id_
    ) public virtual returns (bool) {
        // Intention is to approve as ERC-721 token (id).
        id_ += ID_ENCODING_PREFIX;
        address erc721Owner = _getOwnerOf(id_);

        if (
            msg.sender != erc721Owner &&
            !isApprovedForAll[erc721Owner][msg.sender]
        ) {
            return false;
        }

        getApproved[id_] = spender_;

        emit ERC721Events.Approval(
            erc721Owner,
            spender_,
            id_ - ID_ENCODING_PREFIX
        );

        return true;
    }

    /// @dev Providing type(uint256).max for approval value results in an
    ///      unlimited approval that is not deducted from on transfers.
    function erc20Approve(
        address spender_,
        uint256 value_
    ) public virtual returns (bool) {
        // Prevent granting 0x0 an ERC-20 allowance.
        if (spender_ == address(0)) {
            revert InvalidSpender();
        }

        // Intention is to approve as ERC-20 token (value).
        allowance[msg.sender][spender_] = value_;

        emit ERC20Events.Approval(msg.sender, spender_, value_);

        return true;
    }

    /// @notice Function for ERC-721 approvals
    function setApprovalForAll(
        ...

// [truncated — 79328 bytes total]
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
ERC20.sol 316 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}
IERC1271.sol 17 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1271.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
Strings.sol 94 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
     * representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}
SignatureChecker.sol 48 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/SignatureChecker.sol)

pragma solidity ^0.8.20;

import {ECDSA} from "./ECDSA.sol";
import {IERC1271} from "../../interfaces/IERC1271.sol";

/**
 * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
 * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like
 * Argent and Safe Wallet (previously Gnosis Safe).
 */
library SignatureChecker {
    /**
     * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
     * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
        (address recovered, ECDSA.RecoverError error, ) = ECDSA.tryRecover(hash, signature);
        return
            (error == ECDSA.RecoverError.NoError && recovered == signer) ||
            isValidERC1271SignatureNow(signer, hash, signature);
    }

    /**
     * @dev Checks if a signature is valid for a given signer and data hash. The signature is validated
     * against the signer smart contract using ERC1271.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidERC1271SignatureNow(
        address signer,
        bytes32 hash,
        bytes memory signature
    ) internal view returns (bool) {
        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeCall(IERC1271.isValidSignature, (hash, signature))
        );
        return (success &&
            result.length >= 32 &&
            abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
    }
}
IERC721Receiver.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.20;

/**
 * @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);
}
IERC1155Receiver.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Interface that must be implemented by smart contracts in order to receive
 * ERC-1155 token transfers.
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @dev Handles the receipt of a single ERC1155 token type. This function is
     * called at the end of a `safeTransferFrom` after the balance has been updated.
     *
     * NOTE: To accept the transfer, this must return
     * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     * (i.e. 0xf23a6e61, or its own function selector).
     *
     * @param operator The address which initiated the transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param id The ID of the token being transferred
     * @param value The amount of tokens being transferred
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @dev Handles the receipt of a multiple ERC1155 token types. This function
     * is called at the end of a `safeBatchTransferFrom` after the balances have
     * been updated.
     *
     * NOTE: To accept the transfer(s), this must return
     * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
     * (i.e. 0xbc197c81, or its own function selector).
     *
     * @param operator The address which initiated the batch transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param ids An array containing ids of each token being transferred (order and length must match values array)
     * @param values An array containing amounts of each token being transferred (order and length must match ids array)
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}
Create2.sol 96 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Create2.sol)

pragma solidity ^0.8.20;

/**
 * @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
 * `CREATE2` can be used to compute in advance the address where a smart
 * contract will be deployed, which allows for interesting new mechanisms known
 * as 'counterfactual interactions'.
 *
 * See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
 * information.
 */
library Create2 {
    /**
     * @dev Not enough balance for performing a CREATE2 deploy.
     */
    error Create2InsufficientBalance(uint256 balance, uint256 needed);

    /**
     * @dev There's no code to deploy.
     */
    error Create2EmptyBytecode();

    /**
     * @dev The deployment failed.
     */
    error Create2FailedDeployment();

    /**
     * @dev Deploys a contract using `CREATE2`. The address where the contract
     * will be deployed can be known in advance via {computeAddress}.
     *
     * The bytecode for a contract can be obtained from Solidity with
     * `type(contractName).creationCode`.
     *
     * Requirements:
     *
     * - `bytecode` must not be empty.
     * - `salt` must have not been used for `bytecode` already.
     * - the factory must have a balance of at least `amount`.
     * - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
     */
    function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
        if (address(this).balance < amount) {
            revert Create2InsufficientBalance(address(this).balance, amount);
        }
        if (bytecode.length == 0) {
            revert Create2EmptyBytecode();
        }
        /// @solidity memory-safe-assembly
        assembly {
            addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
        }
        if (addr == address(0)) {
            revert Create2FailedDeployment();
        }
    }

    /**
     * @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
     * `bytecodeHash` or `salt` will result in a new destination address.
     */
    function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
        return computeAddress(salt, bytecodeHash, address(this));
    }

    /**
     * @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
     * `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
     */
    function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40) // Get free memory pointer

            // |                   | ↓ ptr ...  ↓ ptr + 0x0B (start) ...  ↓ ptr + 0x20 ...  ↓ ptr + 0x40 ...   |
            // |-------------------|---------------------------------------------------------------------------|
            // | bytecodeHash      |                                                        CCCCCCCCCCCCC...CC |
            // | salt              |                                      BBBBBBBBBBBBB...BB                   |
            // | deployer          | 000000...0000AAAAAAAAAAAAAAAAAAA...AA                                     |
            // | 0xFF              |            FF                                                             |
            // |-------------------|---------------------------------------------------------------------------|
            // | memory            | 000000...00FFAAAAAAAAAAAAAAAAAAA...AABBBBBBBBBBBBB...BBCCCCCCCCCCCCC...CC |
            // | keccak(start, 85) |            ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |

            mstore(add(ptr, 0x40), bytecodeHash)
            mstore(add(ptr, 0x20), salt)
            mstore(ptr, deployer) // Right-aligned with 12 preceding garbage bytes
            let start := add(ptr, 0x0b) // The hashed data starts at the final garbage byte which we will set to 0xff
            mstore8(start, 0xff)
            addr := keccak256(start, 85)
        }
    }
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IERC20Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
draft-IERC6093.sol 161 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}
ECDSA.sol 174 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @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
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-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]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        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, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        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]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            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.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // 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, s);
        }

        // 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, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @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, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}

Read Contract

DOMAIN_SEPARATOR 0x3644e515 → bytes32
ID_ENCODING_PREFIX 0x6e8f624b → uint256
MAX_SENT_MESSAGES_PER_AGENT 0xa089320a → uint256
account 0x2dd7c658 → address
agentAssignedTasks 0x10d0c303 → uint256
agentInstructions 0x1c199e21 → bytes32
agentMessages 0x1ac5cfe5 → uint256, bytes32, uint256
agentPerformance 0xc879b969 → uint256, uint256, uint256
agentTaskAssignments 0xdc486462 → bool
allowance 0xdd62ed3e → uint256
authorizedAgents 0x21030ff2 → bool
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
erc20BalanceOf 0x02519da3 → uint256
erc20TotalSupply 0x89fb4c66 → uint256
erc721BalanceOf 0xb3f9ea34 → uint256
erc721TotalSupply 0xc5ab3ba6 → uint256
erc721TransferExempt 0x09f0ef65 → bool
getAgentMessages 0xb1568073 → tuple[]
getApproved 0x081812fc → address
getERC721QueueLength 0x09674eb0 → uint256
getERC721TokensInQueue 0xf780bc1a → uint256[]
isApprovedForAll 0xe985e9c5 → bool
lastActionTimestamp 0xfd4fc0bd → uint256
messagesSentCount 0xd56c5383 → uint256
minted 0x4f02c420 → uint256
name 0x06fdde03 → string
nextActionId 0xf4644f41 → uint256
nextTaskId 0xfdc3d8d7 → uint256
nft_setup_set 0x68e8fe6d → uint256
nonces 0x7ecebe00 → uint256
owned 0xb1ab9317 → uint256[]
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
scheduledActions 0x2ae0268a → address, uint256, bytes, uint8, uint256, uint256, bool
setup 0x4313b9e5 → address, address, bytes32
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tasks 0x8d977672 → string, address, uint256, uint256, bool, bytes32
tokenURI 0xc87b56dd → string
totalSupply 0x18160ddd → uint256
uniswapV2Pair 0x49bd5a5e → address
units 0x976a8435 → uint256

Write Contract 32 functions

These functions modify contract state and require a wallet transaction to execute.

add6551Setup 0x3bb7bf1d
address registry_
address implementation_
bytes32 salt_
allowSelfExempts 0x4d631360
No parameters
approve 0x095ea7b3
address spender_
uint256 valueOrId_
returns: bool
assignTask 0x01612c40
uint256 taskId
uint256 agentId
authorizeAgent 0x70dba90b
uint256 tokenId
address agent
bool authorized
cancelScheduledAction 0x135ffd40
uint256 tokenId
uint256 actionId
completeTask 0x669b797a
uint256 taskId
uint256 agentId
bytes32 outcome
createTask 0x04fe2b34
string description
uint256 deadline
returns: uint256
enableTrading 0xfb29d015
uint256 supply721
bool create
erc20Approve 0x4d966072
address spender_
uint256 value_
returns: bool
erc20TransferFrom 0xd96ca0b9
address from_
address to_
uint256 value_
returns: bool
erc721Approve 0xdfabc033
address spender_
uint256 id_
returns: bool
erc721TransferFrom 0xdd637699
address from_
address to_
uint256 id_
execute 0x00773040
uint256 id_
address to
uint256 value
bytes data
uint8 operation
returns: bytes
executeAsAgent 0x947abb9d
uint256 tokenId
address to
uint256 value
bytes data
uint8 operation
returns: bytes
executeScheduledAction 0x77465ade
uint256 tokenId
uint256 actionId
returns: bool
mintNFTs 0x4af57f9d
No parameters
permit 0xd505accf
address owner_
address spender_
uint256 value_
uint256 deadline_
uint8 v_
bytes32 r_
bytes32 s_
removeMaxWallet 0xdc07b617
No parameters
renounceOwnership 0x715018a6
No parameters
safeTransferFrom 0x42842e0e
address from_
address to_
uint256 id_
safeTransferFrom 0xb88d4fde
address from_
address to_
uint256 id_
bytes data_
scheduleAction 0x7d6e1578
uint256 tokenId
address to
uint256 value
bytes data
uint8 operation
uint256 executionTime
uint256 interval
returns: uint256
sendAgentMessage 0x09c862cd
uint256 fromTokenId
uint256 toTokenId
bytes32 message
setApprovalForAll 0xa22cb465
address operator_
bool approved_
setERC721TransferExempt 0xc6e672b9
address account_
bool value_
setSelfERC721TransferExempt 0x8a696e50
bool state_
transfer 0xa9059cbb
address to_
uint256 value_
returns: bool
transferFrom 0x23b872dd
address from_
address to_
uint256 valueOrId_
returns: bool
transferOwnership 0xf2fde38b
address newOwner
updateURI 0xc30f4a5a
string uri
upgrade6551Setup 0x744140cb
uint256 setupId_
uint256 tokenId_

Recent Transactions

No transactions found for this address