Address Contract Partially Verified
Address
0x973568CbFc44aFE4d213e27C9512f7811a4577eb
Balance
0 ETH
Nonce
1
Code Size
24444 bytes
Creator
0x5e83ceBD...ee45 at tx 0x8914f238...fa2cd2
Indexed Transactions
0
Contract Bytecode
24444 bytes
0x60806040526004361061038c5760003560e01c80637b2d3e69116101dc578063b607bc3011610102578063e2748429116100a0578063f2fde38b1161006f578063f2fde38b14610c0d578063f60c715814610c2d578063f8c8765e14610c4d578063f92b41bd14610c6d57600080fd5b8063e274842914610b7d578063e949580e14610b9d578063f0fd108414610bd8578063f163d71214610bf857600080fd5b8063c6e4fc93116100dc578063c6e4fc9314610afc578063cbaaccb414610b1c578063d4a6a2fd14610b3c578063d8a531a614610b5d57600080fd5b8063b607bc3014610a7d578063bc5800e514610abc578063bfca66c914610adc57600080fd5b8063920123391161017a578063ad3cb1cc11610149578063ad3cb1cc146109df578063af26974514610a10578063b21185b314610a30578063b4ab6cf114610a5057600080fd5b8063920123391461095257806397520f74146109725780639762891714610992578063ab14dee4146109b257600080fd5b806385c23195116101b657806385c23195146108b557806385eab8c6146108d55780638ad0838d146108f55780638da5cb5b1461091557600080fd5b80637b2d3e69146108545780638110c50f146108745780638131fd161461089557600080fd5b8063474954c3116102c15780635f03b6b21161025f5780636d5bc5ca1161022e5780636d5bc5ca146107725780636e35d395146107d3578063715018a61461081f57806373417b091461083457600080fd5b80635f03b6b2146106fc578063675151b2146107125780636acf6eac146107325780636afffd901461075257600080fd5b806351ca0ffa1161029b57806351ca0ffa1461061257806351fa7cc21461063457806352d1902d146106c6578063564b81ef146106e957600080fd5b8063474954c3146105a05780634d9c41a7146105c05780634f1ef286146105ff57600080fd5b80633284c3b11161032e578063416b3e1e11610308578063416b3e1e1461051f578063427fa2041461053f5780634451d89f14610560578063468169b31461058057600080fd5b80633284c3b1146104a057806332e52ae1146104c05780633c11bdd6146104e057600080fd5b8063232275c11161036a578063232275c1146103f3578063238ac933146104135780632f1521581461045057806330f899531461047057600080fd5b806319a8b4a0146103915780631b878f71146103b35780631d671c5b146103d3575b600080fd5b34801561039d57600080fd5b506103b16103ac366004614e33565b610c9a565b005b3480156103bf57600080fd5b506103b16103ce366004614e87565b610dc2565b3480156103df57600080fd5b506103b16103ee366004614ec0565b610e4a565b3480156103ff57600080fd5b506103b161040e366004614f01565b610fa6565b34801561041f57600080fd5b50600d54610433906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561045c57600080fd5b506103b161046b366004614f9a565b6110e4565b34801561047c57600080fd5b5061049061048b366004615098565b6113a6565b6040519015158152602001610447565b3480156104ac57600080fd5b506104906104bb366004615098565b611522565b3480156104cc57600080fd5b506103b16104db366004614e87565b61154b565b3480156104ec57600080fd5b506105006104fb366004615114565b61169a565b604080516001600160801b039093168352602083019190915201610447565b34801561052b57600080fd5b5061050061053a366004615145565b6117e5565b34801561054b57600080fd5b5060065461049090600160a81b900460ff1681565b34801561056c57600080fd5b50600654610433906001600160a01b031681565b34801561058c57600080fd5b506103b161059b366004615171565b611990565b3480156105ac57600080fd5b506103b16105bb366004615114565b6119dd565b3480156105cc57600080fd5b506007546105e790600160401b90046001600160801b031681565b6040516001600160801b039091168152602001610447565b6103b161060d36600461523d565b611ab6565b34801561061e57600080fd5b50610627611ad5565b60405161044791906152a6565b34801561064057600080fd5b5061069361064f366004615114565b6009602090815260009283526040808420909152908252902080546001909101546001600160801b0380831692600160801b90819004821692808316929190041684565b604080516001600160801b0395861681529385166020850152918416918301919091529091166060820152608001610447565b3480156106d257600080fd5b506106db611b63565b604051908152602001610447565b3480156106f557600080fd5b50466106db565b34801561070857600080fd5b506106db60055481565b34801561071e57600080fd5b506103b161072d3660046152e7565b611b80565b34801561073e57600080fd5b506103b161074d36600461534e565b611c53565b34801561075e57600080fd5b506103b161076d3660046153c5565b611e16565b34801561077e57600080fd5b506107b361078d3660046153f1565b600b602052600090815260409020546001600160801b0380821691600160801b90041682565b604080516001600160801b03938416815292909116602083015201610447565b3480156107df57600080fd5b506107b36107ee366004615145565b60086020908152600092835260408084209091529082529020546001600160801b0380821691600160801b90041682565b34801561082b57600080fd5b506103b1611e9d565b34801561084057600080fd5b506103b161084f36600461540a565b611eb1565b34801561086057600080fd5b506103b161086f3660046153f1565b611f06565b34801561088057600080fd5b5060065461049090600160b01b900460ff1681565b3480156108a157600080fd5b50600154610433906001600160a01b031681565b3480156108c157600080fd5b50600454610433906001600160a01b031681565b3480156108e157600080fd5b506103b16108f036600461546b565b611f43565b34801561090157600080fd5b506105e7610910366004614f9a565b612106565b34801561092157600080fd5b507f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b0316610433565b34801561095e57600080fd5b506103b161096d3660046154d6565b61216e565b34801561097e57600080fd5b506103b161098d366004615171565b612235565b34801561099e57600080fd5b506103b16109ad3660046152e7565b6122e8565b3480156109be57600080fd5b506109d26109cd36600461551d565b6123da565b6040516104479190615538565b3480156109eb57600080fd5b50610627604051806040016040528060058152602001640352e302e360dc1b81525081565b348015610a1c57600080fd5b50600054610433906001600160a01b031681565b348015610a3c57600080fd5b506103b1610a4b366004614e87565b612498565b348015610a5c57600080fd5b50610a70610a6b366004615590565b6124ee565b60405161044791906155d1565b348015610a8957600080fd5b50600654610aa490600160b81b90046001600160401b031681565b6040516001600160401b039091168152602001610447565b348015610ac857600080fd5b50610500610ad7366004615114565b6128eb565b348015610ae857600080fd5b50610433610af73660046153f1565b6129f7565b348015610b0857600080fd5b506103b1610b17366004615688565b612a21565b348015610b2857600080fd5b506103b1610b373660046156bd565b612a33565b348015610b4857600080fd5b5060065461049090600160a01b900460ff1681565b348015610b6957600080fd5b50600354610433906001600160a01b031681565b348015610b8957600080fd5b50600754610aa4906001600160401b031681565b348015610ba957600080fd5b50610490610bb83660046156f2565b8051602081830181018051600c8252928201919093012091525460ff1681565b348015610be457600080fd5b506103b1610bf3366004614e33565b612ae5565b348015610c0457600080fd5b506103b1612be3565b348015610c1957600080fd5b506103b1610c28366004614e87565b612c6e565b348015610c3957600080fd5b506103b1610c48366004615726565b612cac565b348015610c5957600080fd5b506103b1610c6836600461575f565b612fac565b348015610c7957600080fd5b506106db610c8836600461551d565b600a6020526000908152604090205481565b610ca26132bd565b600654600160a01b900460ff161580610cbb5750600554155b80610cc7575060055442105b15610ce557604051633c21f90f60e01b815260040160405180910390fd5b6006546001600160a01b0316610d0e5760405163206d376f60e01b815260040160405180910390fd5b6001546001600160a01b0316336001600160a01b031614610d41576040516282b42960e81b815260040160405180910390fd5b6000610d80848484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506132f592505050565b6006546001600160801b03919091169150610da5906001600160a01b0316858361337f565b50610dbd6001600080516020615f2783398151915255565b505050565b610dca6133f2565b600654600160b01b900460ff1615610df557604051639a8d50df60e01b815260040160405180910390fd5b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527fef1cd24a01120da2689be4a7980f64da049419dcd5866a87bff7b5d978a5078c906020015b60405180910390a150565b610e526133f2565b600654600754600160b81b9091046001600160401b0390811691600160401b90046001600160801b03169084161580610e9e5750612710610e9385846157c6565b6001600160401b0316115b80610ebb5750806001600160801b0316836001600160801b031611155b15610ed957604051630a6428c360e11b815260040160405180910390fd5b600780546001600160401b038481166001600160c01b031990921691909117600160401b6001600160801b0387160217909155600680548692601791610f28918591600160b81b9004166157c6565b82546101009290920a6001600160401b0381810219909316918316021790915560065460075460408051600160b81b9093049093168252600160401b90046001600160801b031660208201527f9192c0214a8cdbd582aaaecda67c8e54fb3c6c1b5762e9abf01d78bf9681cf5992500160405180910390a150505050565b610fae6133f2565b848381141580610fbe5750808214155b15610fdc5760405163a121188760e01b815260040160405180910390fd5b60005b818110156110da57858582818110610ff957610ff96157e6565b905060200201602081019061100e91906157fc565b600860008a8a85818110611024576110246157e6565b90506020020160208101906110399190614e87565b6001600160a01b03166001600160a01b03168152602001908152602001600020600086868581811061106d5761106d6157e6565b9050602002016020810190611082919061551d565b600581111561109357611093615817565b60058111156110a4576110a4615817565b8152602081019190915260400160002080546001600160801b0319166001600160801b0392909216919091179055600101610fdf565b5050505050505050565b600254839081106111085760405163017e9c7d60e41b815260040160405180910390fd5b6111106133f2565b624f1a00600554611121919061582d565b421161114057604051632e9cc64960e21b815260040160405180910390fd5b6000848152600b602052604090208280158061119057508484600081811061116a5761116a6157e6565b905060200201602081019061117f91906157fc565b82546001600160801b039182169116115b156111ae57604051633be4064960e01b815260040160405180910390fd5b6000805b828110156113115780156112495786866111cd600184615840565b8181106111dc576111dc6157e6565b90506020020160208101906111f191906157fc565b6001600160801b031687878381811061120c5761120c6157e6565b905060200201602081019061122191906157fc565b6001600160801b0316101561124957604051633be4064960e01b815260040160405180910390fd5b60008881526009602052604081208189898581811061126a5761126a6157e6565b905060200201602081019061127f91906157fc565b6001600160801b03908116825260208083019390935260409182016000908120835160808101855281548085168252600160801b90819004851696820187905260019092015480851695820195909552930490911660608301819052919350916112e99190615853565b90506001600160801b03811615611307576113048185615873565b93505b50506001016111b2565b50858561131f600185615840565b81811061132e5761132e6157e6565b905060200201602081019061134391906157fc565b83546001600160801b0319166001600160801b039182161780855582918591601091611379918591600160801b90910416615873565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555050505050505050565b600d546040516000916001600160a01b0316906114569061141a906113d190339087906020016158af565b604051602081830303815290604052805190602001207f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c91909152603c902090565b86868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061344d92505050565b6001600160a01b0316146114a55760405162461bcd60e51b8152602060048201526011602482015270696e76616c6964207369676e617475726560781b60448201526064015b60405180910390fd5b600c84846040516114b79291906158e7565b9081526040519081900360200190205460ff16156115175760405162461bcd60e51b815260206004820152601a60248201527f7369676e61747572652063616e6e6f7420626520726575736564000000000000604482015260640161149c565b5060015b9392505050565b600d546040516000916001600160a01b0316906114569061141a906113d19086906020016158f7565b6115536133f2565b600654600160a81b900460ff161561157e57604051636507689f60e01b815260040160405180910390fd5b624f1a0060055461158f919061582d565b42116115ae57604051632e9cc64960e21b815260040160405180910390fd5b6001600160a01b0381166115d557604051633be4064960e01b815260040160405180910390fd5b6000805b600254811015611649576000818152600b602052604090208054600160801b90046001600160801b0316801561163f57600654611629906001600160a01b0316866001600160801b03841661337f565b61163c6001600160801b0382168561582d565b93505b50506001016115d9565b506006805460ff60a81b1916600160a81b179055604080518281524260208201527f51c3c049b061ef6ad9b287a90842a19c63db19253589bf999293790b4adffa1491015b60405180910390a15050565b6006546000908190600160a01b900460ff1615806116b85750600554155b806116c4575060055442105b156116e257604051633c21f90f60e01b815260040160405180910390fd5b6006546001600160a01b031661170b5760405163206d376f60e01b815260040160405180910390fd5b6002548490811061172f5760405163017e9c7d60e41b815260040160405180910390fd5b6000858152600960209081526040808320878452825291829020825160808101845281546001600160801b038082168352600160801b9182900481169483019490945260019092015480841694820194909452920416606082015261179381613479565b6006549094506001600160401b03600160b81b90910416612710146117b95760006117da565b6007546117da90624f1a0090600160401b90046001600160801b031661582d565b925050509250929050565b6006546000908190600160a01b900460ff1615806118035750600554155b8061180f575060055442105b1561182d57604051633c21f90f60e01b815260040160405180910390fd5b6006546001600160a01b03166118565760405163206d376f60e01b815260040160405180910390fd5b6000600a600085600581111561186e5761186e615817565b600581111561187f5761187f615817565b815260200190815260200160002060010180549050905061192260086000876001600160a01b03166001600160a01b0316815260200190815260200160002060008660058111156118d2576118d2615817565b60058111156118e3576118e3615817565b815260208082019290925260409081016000208151808301909252546001600160801b038082168352600160801b909104169181019190915285613533565b9250600084600581111561193857611938615817565b146119755762278d0061194c8260b4615913565b6119599062015180615913565b600554611966919061582d565b611970919061582d565b611986565b62278d00600554611986919061582d565b9150509250929050565b848314801561199e57508481145b6119ba5760405162461bcd60e51b815260040161149c9061592a565b6119c987878787878787612235565b6119d4878585612ae5565b50505050505050565b6119e56133f2565b6006546001600160a01b0316611a0e5760405163206d376f60e01b815260040160405180910390fd5b81600003611a2f57604051630a6428c360e11b815260040160405180910390fd5b80600003611a5057604051630a6428c360e11b815260040160405180910390fd5b611a68336006546001600160a01b03169030856137d9565b60058190556006805460ff60a01b1916600160a01b17905560408051838152602081018390527f5ba5bfb53e85b015ce3b9ccbb1c00fe1fbee62fe700c131b5835bed2982a73d0910161168e565b611abe613812565b611ac7826138b7565b611ad182826138ea565b5050565b600e8054611ae290615961565b80601f0160208091040260200160405190810160405280929190818152602001828054611b0e90615961565b8015611b5b5780601f10611b3057610100808354040283529160200191611b5b565b820191906000526020600020905b815481529060010190602001808311611b3e57829003601f168201915b505050505081565b6000611b6d6139a7565b50600080516020615f0783398151915290565b611b886132bd565b600654600160a01b900460ff161580611ba15750600554155b80611bad575060055442105b15611bcb57604051633c21f90f60e01b815260040160405180910390fd5b6006546001600160a01b0316611bf45760405163206d376f60e01b815260040160405180910390fd5b6000611bff856139f0565b90506000611c0f82868686613b4a565b6006546001600160801b03919091169150611c34906001600160a01b0316838361337f565b5050611c4d6001600080516020615f2783398151915255565b50505050565b6000611c5e866139f0565b6001600160a01b0381166000908152600860205260408120919250856005811115611c8b57611c8b615817565b6005811115611c9c57611c9c615817565b81526020810191909152604001600020546001600160801b031615611cfb5760405162461bcd60e51b815260206004820152601560248201527410db185a5b58589b1948185b1c9958591e481cd95d605a1b604482015260640161149c565b6000600e611d11876001600160801b0316613c6b565b611d2b876005811115611d2657611d26615817565b613c6b565b611d3446613c6b565b611d3d30613c6b565b604051602001611d51959493929190615a0b565b6040516020818303038152906040529050611d6d8484836113a6565b506001600c8585604051611d829291906158e7565b9081526040805160209281900383019020805460ff1916931515939093179092556001600160a01b038416600090815260089091529081208791876005811115611dce57611dce615817565b6005811115611ddf57611ddf615817565b8152602081019190915260400160002080546001600160801b0319166001600160801b039290921691909117905550505050505050565b611e1e6133f2565b6006546001600160a01b0316611e475760405163206d376f60e01b815260040160405180910390fd5b600654611e5e906001600160a01b0316838361337f565b604080516001600160a01b0384168152602081018390527f4353f051398deb19bad16ba01c2250d186a65981b71a1c9cd7ef86f65cd25960910161168e565b611ea56133f2565b611eaf6000613cfd565b565b611eb96133f2565b60068054821515600160a01b0260ff60a01b199091161790556040517f7d9bc7474aa5661520727056d5036520e3004dfa67eebc8ea98dd139b044aae190610e3f90831515815260200190565b611f0e6133f2565b60058190556040518181527f964c90bd7629d544979f969dfe29b81336f2721db971a878cca932fd2a5b86ad90602001610e3f565b828114611f625760405162461bcd60e51b815260040161149c9061592a565b60005b838110156120fb576000858583818110611f8157611f816157e6565b9050608002016000013590506000868684818110611fa157611fa16157e6565b9050608002016020013590506000878785818110611fc157611fc16157e6565b9050608002016040016020810190611fd991906157fc565b90506000888886818110611fef57611fef6157e6565b905060800201606001602081019061200791906157fc565b905036600088888881811061201e5761201e6157e6565b90506020028101906120309190615aa1565b915091506000600e61204188613c6b565b61204a88613c6b565b61205c886001600160801b0316613c6b565b61206e886001600160801b0316613c6b565b61207746613c6b565b61208030613c6b565b6040516020016120969796959493929190615ae7565b60405160208183030381529060405290506120b2838383611522565b506001600c84846040516120c79291906158e7565b908152604051908190036020019020805491151560ff199092169190911790555050506001949094019350611f6592505050565b50611c4d8484613d6e565b6000805b828110156121665760006121368686868581811061212a5761212a6157e6565b9050602002013561169a565b509050806001600160801b0316600003612150575061215e565b61215a8184615873565b9250505b60010161210a565b509392505050565b6121766133f2565b6001600160a01b0383166121cc5760405162461bcd60e51b815260206004820152601760248201527f5f7369676e65722073686f756c64206e6f742062652030000000000000000000604482015260640161149c565b600d80546001600160a01b0319166001600160a01b038516179055600e6121f4828483615c0d565b507f91aa25cae04634ee896b374dca60a793204082970a8967624866b381095da9b283838360405161222893929190615ccc565b60405180910390a1505050565b848314801561224357508481145b61225f5760405162461bcd60e51b815260040161149c9061592a565b60005b838110156110da576122e088888884818110612280576122806157e6565b905060200201602081019061229591906157fc565b8787858181106122a7576122a76157e6565b90506020020160208101906122bc919061551d565b8686868181106122ce576122ce6157e6565b905060200281019061074d9190615aa1565b600101612262565b6122f06132bd565b600654600160a01b900460ff1615806123095750600554155b80612315575060055442105b1561233357604051633c21f90f60e01b815260040160405180910390fd5b6006546001600160a01b031661235c5760405163206d376f60e01b815260040160405180910390fd5b6001546001600160a01b0316336001600160a01b03161461238f576040516282b42960e81b815260040160405180910390fd5b600061239d85858585613b4a565b6006546001600160801b039190911691506123c2906001600160a01b0316868361337f565b50611c4d6001600080516020615f2783398151915255565b604080518082019091526000815260606020820152600a600083600581111561240557612405615817565b600581111561241657612416615817565b8152602001908152602001600020604051806040016040529081600082015481526020016001820180548060200260200160405190810160405280929190818152602001828054801561248857602002820191906000526020600020905b815481526020019060010190808311612474575b5050505050815250509050919050565b6124a06133f2565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f3d2fa335e1b3b6a3bd407f2f0792f840681697b303f66e46d6ca77f62636632c90602001610e3f565b6060600082815b818110156125445785858281811061250f5761250f6157e6565b90506020028101906125219190615d0c565b61252f906020810190615d22565b61253a91508461582d565b92506001016124f5565b50816001600160401b0381111561255d5761255d61500d565b6040519080825280602002602001820160405280156125dc57816020015b604080516101408101825260008082526020808301829052928201819052606082018190526080820181905260a0820181905260c0820181905260e082018190526101008201819052610120820152825260001990920191018161257b5790505b5092506000805b828110156128e15760008787838181106125ff576125ff6157e6565b90506020028101906126119190615d0c565b3590506000888884818110612628576126286157e6565b905060200281019061263a9190615d0c565b612648906020810190615d22565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201829052509394505050505b81518110156128d6576000806126ab8585858151811061269e5761269e6157e6565b602002602001015161169a565b915091506000806126d5878787815181106126c8576126c86157e6565b60200260200101516128eb565b915091506040518061014001604052808881526020018787815181106126fd576126fd6157e6565b60200260200101518152602001856001600160801b03168152602001848152602001600960008a81526020019081526020016000206000898981518110612746576127466157e6565b60209081029190910181015182528181019290925260409081016000908120546001600160801b031684528b8152600983529081208a5193909201928a908a908110612794576127946157e6565b6020026020010151815260200190815260200160002060010160009054906101000a90046001600160801b03166001600160801b03168152602001836001600160801b03168152602001828152602001600960008a8152602001908152602001600020600089898151811061280b5761280b6157e6565b6020026020010151815260200190815260200160002060000160109054906101000a90046001600160801b03166001600160801b03168152602001600960008a8152602001908152602001600020600089898151811061286d5761286d6157e6565b602090810291909101810151825281019190915260400160002060010154600160801b90046001600160801b031690528c8a6128a881615d6b565b9b50815181106128ba576128ba6157e6565b602002602001018190525050505050808060010191505061267c565b5050506001016125e3565b5050505092915050565b6006546000908190600160a01b900460ff1615806129095750600554155b80612915575060055442105b1561293357604051633c21f90f60e01b815260040160405180910390fd5b6006546001600160a01b031661295c5760405163206d376f60e01b815260040160405180910390fd5b600254849081106129805760405163017e9c7d60e41b815260040160405180910390fd5b6000858152600960209081526040808320878452825291829020825160808101845281546001600160801b038082168352600160801b918290048116948301949094526001909201548084169482019490945292041660608201526129e481613e8d565b9350624f1a006005546117da919061582d565b60028181548110612a0757600080fd5b6000918252602090912001546001600160a01b0316905081565b612a296133f2565b611ad18282613d6e565b612a3b6133f2565b600083815260096020908152604080832085845290915281208054839290612a6d9084906001600160801b0316615873565b82546101009290920a6001600160801b038181021990931691831602179091556000858152600960209081526040808320878452825291829020548251888152918201879052909216908201527f39fd505972d80ed67ab0942151362990601c9c1d28ca49134865138bf4d0893a9150606001612228565b612aed6132bd565b600654600160a01b900460ff161580612b065750600554155b80612b12575060055442105b15612b3057604051633c21f90f60e01b815260040160405180910390fd5b6006546001600160a01b0316612b595760405163206d376f60e01b815260040160405180910390fd5b6000612b64846139f0565b90506000612ba5828585808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506132f592505050565b6006546001600160801b03919091169150612bca906001600160a01b0316838361337f565b5050610dbd6001600080516020615f2783398151915255565b612beb6133f2565b600654600160b01b900460ff1615612c1657604051639a8d50df60e01b815260040160405180910390fd5b6006805460ff60b01b1916600160b01b179055600080546001600160a01b03191681556040519081527fef1cd24a01120da2689be4a7980f64da049419dcd5866a87bff7b5d978a5078c9060200160405180910390a1565b612c766133f2565b6001600160a01b038116612ca057604051631e4fbdf760e01b81526000600482015260240161149c565b612ca981613cfd565b50565b612cb46133f2565b600654600160a01b900460ff1615612cdf5760405163f1a3368f60e01b815260040160405180910390fd5b80838114612d005760405163a121188760e01b815260040160405180910390fd5b60005b81811015612f7b57838382818110612d1d57612d1d6157e6565b9050602002810190612d2f9190615d0c565b612d3d906020810190615d22565b9050848483818110612d5157612d516157e6565b9050602002810190612d639190615d0c565b3510612dcd5760405162461bcd60e51b815260206004820152603360248201527f5374617274206379636c652073686f756c6420626520736d616c6c65722074686044820152720c2dc40d8dec6d6aae084a0e65cd8cadccee8d606b1b606482015260840161149c565b6000848483818110612de157612de16157e6565b9050602002810190612df39190615d0c565b612e01906020810190615d22565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201829052509394505050505b8151811015612ee457612710828281518110612e5357612e536157e6565b60200260200101511115612e7a57604051630a6428c360e11b815260040160405180910390fd5b8015612edc5781612e8c600183615840565b81518110612e9c57612e9c6157e6565b6020026020010151828281518110612eb657612eb66157e6565b602002602001015111612edc57604051630a6428c360e11b815260040160405180910390fd5b600101612e35565b50848483818110612ef757612ef76157e6565b9050602002810190612f099190615d0c565b600a6000898986818110612f1f57612f1f6157e6565b9050602002016020810190612f34919061551d565b6005811115612f4557612f45615817565b6005811115612f5657612f56615817565b81526020019081526020016000208181612f709190615d84565b505050600101612d03565b506040517f9f3def91475ff17701f8c108d79b21c495e90c3ad9bccb265a6510720a832d7790600090a15050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b0316600081158015612ff15750825b90506000826001600160401b0316600114801561300d5750303b155b90508115801561301b575080155b156130395760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561306357845460ff60401b1916600160401b1785555b6001600160a01b0389166130c45760405162461bcd60e51b815260206004820152602260248201527f5f636c61696d546f6b656e416464726573732073686f756c64206e6f74206265604482015261020360f41b606482015260840161149c565b6001600160a01b03881661311a5760405162461bcd60e51b815260206004820152601b60248201527f5f6b7a67416464726573732073686f756c64206e6f7420626520300000000000604482015260640161149c565b6001600160a01b0387166131705760405162461bcd60e51b815260206004820152601c60248201527f5f6b75627a416464726573732073686f756c64206e6f74206265203000000000604482015260640161149c565b6001600160a01b0386166131c65760405162461bcd60e51b815260206004820152601c60248201527f5f7967707a416464726573732073686f756c64206e6f74206265203000000000604482015260640161149c565b6131ce613f06565b6131d733613f0e565b6131df613f16565b600380546001600160a01b03199081166d76a84fef008cdabe6409d2fe638b1782556004805482166c447e69651d841bd8d104bed493179055600680546001600160a01b038d811691909316179055604080516060810182528b831681528a83166020820152918916908201526132599160029190614d62565b50600080546001600160a01b0319163317905583156132b257845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050505050565b600080516020615f278339815191528054600119016132ef57604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b60006133018383613f1e565b9050806001600160801b031660000361332d576040516358c45ad560e01b815260040160405180910390fd5b604080516001600160801b03831681524260208201526001600160a01b038516917f7a61a2933ee34cf5cca59f8cd920eb077db0bd64d01b5f67c1387e2e4f0a81ec910160405180910390a292915050565b6040516001600160a01b03838116602483015260448201839052610dbd91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061402e565b6001600080516020615f2783398151915255565b336134247f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b031614611eaf5760405163118cdaa760e01b815233600482015260240161149c565b60008060008061345d8686614091565b92509250925061346d82826140de565b50909150505b92915050565b600654600090600160b81b90046001600160401b031680820361349f5750600092915050565b61271081036134d9576007546134c99062278d0090600160401b90046001600160801b031661582d565b4211156134d95750600092915050565b825160408401516001600160801b03821615806135085750816001600160801b0316816001600160801b031610155b1561351857506000949350505050565b61352a61352483614197565b82614213565b95945050505050565b81516020830151600091906001600160801b03821615806135665750816001600160801b0316816001600160801b031610155b1561357657600092505050613473565b600084600581111561358a5761358a615817565b036135ba5762278d006005546135a0919061582d565b4211156135b257600092505050613473565b509050613473565b6000600a60008660058111156135d2576135d2615817565b60058111156135e3576135e3615817565b8152602001908152602001600020604051806040016040529081600082015481526020016001820180548060200260200160405190810160405280929190818152602001828054801561365557602002820191906000526020600020905b815481526020019060010190808311613641575b5050505050815250509050600081602001515190508060000361368b57604051630a6428c360e11b815260040160405180910390fd5b62278d0061369a8260b4615913565b6136a79062015180615913565b6005546136b4919061582d565b6136be919061582d565b4211156136d2576000945050505050613473565b600062015180600554426136e69190615840565b6136f09190615e4a565b905060006136ff60b483615e4a565b9050600188600581111561371557613715615817565b148015613722575060b482105b156137365760009650505050505050613473565b6000600589600581111561374c5761374c615817565b1415801561375b575060048210155b9050600060058a600581111561377357613773615817565b148015613781575060068310155b9050818061378c5750805b156137aa5761379b8888614213565b98505050505050505050613473565b6137ca6137c487878b6137be88600161582d565b89614240565b88614213565b9b9a5050505050505050505050565b6040516001600160a01b038481166024830152838116604483015260648201839052611c4d9186918216906323b872dd906084016133ac565b306001600160a01b037f000000000000000000000000973568cbfc44afe4d213e27c9512f7811a4577eb16148061389957507f000000000000000000000000973568cbfc44afe4d213e27c9512f7811a4577eb6001600160a01b031661388d600080516020615f07833981519152546001600160a01b031690565b6001600160a01b031614155b15611eaf5760405163703e46dd60e11b815260040160405180910390fd5b6000546001600160a01b0316336001600160a01b031614612ca9576040516282b42960e81b815260040160405180910390fd5b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015613944575060408051601f3d908101601f1916820190925261394191810190615e5e565b60015b61396c57604051634c9c8ce360e01b81526001600160a01b038316600482015260240161149c565b600080516020615f07833981519152811461399d57604051632a87526960e21b81526004810182905260240161149c565b610dbd83836142e1565b306001600160a01b037f000000000000000000000000973568cbfc44afe4d213e27c9512f7811a4577eb1614611eaf5760405163703e46dd60e11b815260040160405180910390fd5b60006001600160a01b038216613a065733613473565b6004546000906001600160a01b031663e839bd53336040516001600160e01b031960e084901b1681526001600160a01b039182166004820152908616602482015260006044820152606401602060405180830381865afa158015613a6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a929190615e77565b90508015613aa1575090919050565b6003546001600160a01b0316639c395bc2336040516001600160e01b031960e084901b1681526001600160a01b0391821660048201529086166024820152604401602060405180830381865afa158015613aff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b239190615e77565b905080613b4357604051632d618d8160e21b815260040160405180910390fd5b5090919050565b6000613b57858585614337565b90508115613bed576001600160a01b03851660009081526008602090815260408083208380528252808320815180830190925280546001600160801b038082168452600160801b9091041692820192909252909190613bb69082613533565b90506001600160801b03811615613bea5781546001600160801b03600160801b808304821684018216029116178255918201915b50505b806001600160801b0316600003613c17576040516358c45ad560e01b815260040160405180910390fd5b604080516001600160801b03831681524260208201526001600160a01b038716917f6bae97ad4b952cdee3720ed0ea228b5eb79d5adb4475c05d9f3f6539627d8e2a910160405180910390a2949350505050565b60606000613c78836145fd565b60010190506000816001600160401b03811115613c9757613c9761500d565b6040519080825280601f01601f191660200182016040528015613cc1576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a8504945084613ccb57509392505050565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3505050565b60005b81811015610dbd576000838383818110613d8d57613d8d6157e6565b9050608002016000013590506000848484818110613dad57613dad6157e6565b9050608002016020013590506000858585818110613dcd57613dcd6157e6565b9050608002016040016020810190613de591906157fc565b90506000868686818110613dfb57613dfb6157e6565b9050608002016060016020810190613e1391906157fc565b60008581526009602090815260408083208784528252918290206001600160801b03848116600160801b029087161790558151878152908101869052600197909701969192507f6765cbdf175c095017f6961e716b812497f2e6022d292faa2aaf88591434190c910160405180910390a150505050613d71565b60208101516060820151600091906001600160801b0382161580613ec35750816001600160801b0316816001600160801b031610155b15613ed2575060009392505050565b624f1a00600554613ee3919061582d565b421115613ef4575060009392505050565b613efe8282614213565b949350505050565b6133de6146d5565b612c766146d5565b611eaf6146d5565b6000805b8251811015614027576001600160a01b038416600090815260086020526040812084518290869085908110613f5957613f596157e6565b60200260200101516005811115613f7257613f72615817565b6005811115613f8357613f83615817565b815260208082019290925260409081016000908120825180840190935280546001600160801b038082168552600160801b9091041693830193909352865192935091613fe99190879086908110613fdc57613fdc6157e6565b6020026020010151613533565b90506001600160801b0381161561401d5781546001600160801b03600160801b808304821684018216029116178255928301925b5050600101613f22565b5092915050565b60006140436001600160a01b0384168361471e565b905080516000141580156140685750808060200190518101906140669190615e77565b155b15610dbd57604051635274afe760e01b81526001600160a01b038416600482015260240161149c565b600080600083516041036140cb5760208401516040850151606086015160001a6140bd8882858561472c565b9550955095505050506140d7565b50508151600091506002905b9250925092565b60008260038111156140f2576140f2615817565b036140fb575050565b600182600381111561410f5761410f615817565b0361412d5760405163f645eedf60e01b815260040160405180910390fd5b600282600381111561414157614141615817565b036141625760405163fce698f760e01b81526004810182905260240161149c565b600382600381111561417657614176615817565b03611ad1576040516335e2f38360e21b81526004810182905260240161149c565b600754600090600160401b90046001600160801b031642106141f5576006546141f090612710906141d890600160b81b90046001600160401b031685615e94565b6001600160801b03166141eb9190615e4a565b6147fb565b613473565b60075461347390612710906141d8906001600160401b031685615e94565b6000816001600160801b0316836001600160801b031611156142375781830361151b565b60009392505050565b84516000908310156142545750600061352a565b8483111561426357508261352a565b600085841461428f5786602001518481518110614282576142826157e6565b6020026020010151614293565b6127105b90506142d68588602001516001876142ab9190615840565b815181106142bb576142bb6157e6565b60200260200101518360b4876142d19190615ebf565b614825565b979650505050505050565b6142ea826148c7565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a280511561432f57610dbd828261492c565b611ad1614999565b6000805b8281101561216657366000858584818110614358576143586157e6565b905060200281019061436a9190615ed3565b614378906020810190615d22565b91509150366000878786818110614391576143916157e6565b90506020028101906143a39190615ed3565b6143b1906040810190615d22565b915091503660008989888181106143ca576143ca6157e6565b90506020028101906143dc9190615ed3565b6143ea906060810190615d22565b90925090508483811415806143ff5750808214155b1561441d5760405163a121188760e01b815260040160405180910390fd5b60008b8b8a818110614431576144316157e6565b90506020028101906144439190615ed3565b35905060005b828110156145e9576000878783818110614465576144656157e6565b905060200201602081019061447a919061540a565b15614519576144a28f848c8c86818110614496576144966157e6565b905060200201356149b8565b90506001600160801b0381161561451957600083815260096020526040812082918c8c868181106144d5576144d56157e6565b6020908102929092013583525081019190915260400160002060010180546001600160801b031981166001600160801b0391821693909301169190911790559a8b019a5b85858381811061452b5761452b6157e6565b9050602002016020810190614540919061540a565b156145e0576145688f848c8c8681811061455c5761455c6157e6565b90506020020135614afc565b90506001600160801b038116156145e057600083815260096020526040812082918c8c8681811061459b5761459b6157e6565b6020908102929092013583525081019190915260400160002060010180546001600160801b03600160801b8083048216909401811690930292169190911790559a8b019a5b50600101614449565b50886001019850505050505050505061433b565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061463c5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310614668576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061468657662386f26fc10000830492506010015b6305f5e100831061469e576305f5e100830492506008015b61271083106146b257612710830492506004015b606483106146c4576064830492506002015b600a83106134735760010192915050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16611eaf57604051631afcd79f60e31b815260040160405180910390fd5b606061151b83836000614c40565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561476757506000915060039050826147f1565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa1580156147bb573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166147e7575060009250600191508290506147f1565b9250600091508190505b9450945094915050565b6000600160801b82106148215760405163ede341c760e01b815260040160405180910390fd5b5090565b60008160000361485957614852612710614848866001600160801b038916615913565b6141eb9190615e4a565b9050613efe565b61352a60b46127108461486c8888615840565b61487f906001600160801b038b16615913565b6148899190615913565b6148939190615e4a565b61489d9190615e4a565b6127106148b3876001600160801b038a16615913565b6148bd9190615e4a565b6141eb919061582d565b806001600160a01b03163b6000036148fd57604051634c9c8ce360e01b81526001600160a01b038216600482015260240161149c565b600080516020615f0783398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060600080846001600160a01b03168460405161494991906158f7565b600060405180830381855af49150503d8060008114614984576040519150601f19603f3d011682016040523d82523d6000602084013e614989565b606091505b509150915061352a858383614cdd565b3415611eaf5760405163b398979f60e01b815260040160405180910390fd5b600254600090839081106149df5760405163017e9c7d60e41b815260040160405180910390fd5b846001600160a01b0316600285815481106149fc576149fc6157e6565b6000918252602090912001546040516331a9108f60e11b8152600481018690526001600160a01b0390911690636352211e90602401602060405180830381865afa158015614a4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a729190615ee9565b6001600160a01b031614614a98576040516282b42960e81b815260040160405180910390fd5b6000848152600960209081526040808320868452825291829020825160808101845281546001600160801b038082168352600160801b9182900481169483019490945260019092015480841694820194909452920416606082015261352a90613479565b60025460009083908110614b235760405163017e9c7d60e41b815260040160405180910390fd5b846001600160a01b031660028581548110614b4057614b406157e6565b6000918252602090912001546040516331a9108f60e11b8152600481018690526001600160a01b0390911690636352211e90602401602060405180830381865afa158015614b92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bb69190615ee9565b6001600160a01b031614614bdc576040516282b42960e81b815260040160405180910390fd5b6000848152600960209081526040808320868452825291829020825160808101845281546001600160801b038082168352600160801b9182900481169483019490945260019092015480841694820194909452920416606082015261352a90613e8d565b606081471015614c655760405163cd78605960e01b815230600482015260240161149c565b600080856001600160a01b03168486604051614c8191906158f7565b60006040518083038185875af1925050503d8060008114614cbe576040519150601f19603f3d011682016040523d82523d6000602084013e614cc3565b606091505b5091509150614cd3868383614cdd565b9695505050505050565b606082614cf257614ced82614d39565b61151b565b8151158015614d0957506001600160a01b0384163b155b15614d3257604051639996b31560e01b81526001600160a01b038516600482015260240161149c565b508061151b565b805115614d495780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b828054828255906000526020600020908101928215614db7579160200282015b82811115614db757825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190614d82565b506148219291505b808211156148215760008155600101614dbf565b6001600160a01b0381168114612ca957600080fd5b60008083601f840112614dfa57600080fd5b5081356001600160401b03811115614e1157600080fd5b6020830191508360208260051b8501011115614e2c57600080fd5b9250929050565b600080600060408486031215614e4857600080fd5b8335614e5381614dd3565b925060208401356001600160401b03811115614e6e57600080fd5b614e7a86828701614de8565b9497909650939450505050565b600060208284031215614e9957600080fd5b813561151b81614dd3565b80356001600160801b0381168114614ebb57600080fd5b919050565b60008060408385031215614ed357600080fd5b82356001600160401b0381168114614eea57600080fd5b9150614ef860208401614ea4565b90509250929050565b60008060008060008060608789031215614f1a57600080fd5b86356001600160401b0380821115614f3157600080fd5b614f3d8a838b01614de8565b90985096506020890135915080821115614f5657600080fd5b614f628a838b01614de8565b90965094506040890135915080821115614f7b57600080fd5b50614f8889828a01614de8565b979a9699509497509295939492505050565b600080600060408486031215614faf57600080fd5b8335925060208401356001600160401b03811115614e6e57600080fd5b60008083601f840112614fde57600080fd5b5081356001600160401b03811115614ff557600080fd5b602083019150836020828501011115614e2c57600080fd5b634e487b7160e01b600052604160045260246000fd5b60006001600160401b038084111561503d5761503d61500d565b604051601f8501601f19908116603f011681019082821181831017156150655761506561500d565b8160405280935085815286868601111561507e57600080fd5b858560208301376000602087830101525050509392505050565b6000806000604084860312156150ad57600080fd5b83356001600160401b03808211156150c457600080fd5b6150d087838801614fcc565b909550935060208601359150808211156150e957600080fd5b508401601f810186136150fb57600080fd5b61510a86823560208401615023565b9150509250925092565b6000806040838503121561512757600080fd5b50508035926020909101359150565b803560068110614ebb57600080fd5b6000806040838503121561515857600080fd5b823561516381614dd3565b9150614ef860208401615136565b60008060008060008060006080888a03121561518c57600080fd5b873561519781614dd3565b965060208801356001600160401b03808211156151b357600080fd5b6151bf8b838c01614de8565b909850965060408a01359150808211156151d857600080fd5b6151e48b838c01614de8565b909650945060608a01359150808211156151fd57600080fd5b5061520a8a828b01614de8565b989b979a50959850939692959293505050565b600082601f83011261522e57600080fd5b61151b83833560208501615023565b6000806040838503121561525057600080fd5b823561525b81614dd3565b915060208301356001600160401b0381111561527657600080fd5b6119868582860161521d565b60005b8381101561529d578181015183820152602001615285565b50506000910152565b60208152600082518060208401526152c5816040850160208701615282565b601f01601f19169190910160400192915050565b8015158114612ca957600080fd5b600080600080606085870312156152fd57600080fd5b843561530881614dd3565b935060208501356001600160401b0381111561532357600080fd5b61532f87828801614de8565b9094509250506040850135615343816152d9565b939692955090935050565b60008060008060006080868803121561536657600080fd5b853561537181614dd3565b945061537f60208701614ea4565b935061538d60408701615136565b925060608601356001600160401b038111156153a857600080fd5b6153b488828901614fcc565b969995985093965092949392505050565b600080604083850312156153d857600080fd5b82356153e381614dd3565b946020939093013593505050565b60006020828403121561540357600080fd5b5035919050565b60006020828403121561541c57600080fd5b813561151b816152d9565b60008083601f84011261543957600080fd5b5081356001600160401b0381111561545057600080fd5b6020830191508360208260071b8501011115614e2c57600080fd5b6000806000806040858703121561548157600080fd5b84356001600160401b038082111561549857600080fd5b6154a488838901615427565b909650945060208701359150808211156154bd57600080fd5b506154ca87828801614de8565b95989497509550505050565b6000806000604084860312156154eb57600080fd5b83356154f681614dd3565b925060208401356001600160401b0381111561551157600080fd5b614e7a86828701614fcc565b60006020828403121561552f57600080fd5b61151b82615136565b60208082528251828201528281015160408084015280516060840181905260009291820190839060808601905b808310156155855783518252928401926001929092019190840190615565565b509695505050505050565b600080602083850312156155a357600080fd5b82356001600160401b038111156155b957600080fd5b6155c585828601614de8565b90969095509350505050565b602080825282518282018190526000919060409081850190868401855b8281101561567b578151805185528681015187860152858101516001600160801b03908116878701526060808301519087015260808083015182169087015260a08083015182169087015260c08083015182169087015260e080830151908701526101008083015182169087015261012091820151169085015261014090930192908501906001016155ee565b5091979650505050505050565b6000806020838503121561569b57600080fd5b82356001600160401b038111156156b157600080fd5b6155c585828601615427565b6000806000606084860312156156d257600080fd5b83359250602084013591506156e960408501614ea4565b90509250925092565b60006020828403121561570457600080fd5b81356001600160401b0381111561571a57600080fd5b613efe8482850161521d565b6000806000806040858703121561573c57600080fd5b84356001600160401b038082111561575357600080fd5b6154a488838901614de8565b6000806000806080858703121561577557600080fd5b843561578081614dd3565b9350602085013561579081614dd3565b925060408501356157a081614dd3565b9150606085013561534381614dd3565b634e487b7160e01b600052601160045260246000fd5b6001600160401b03818116838216019080821115614027576140276157b0565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561580e57600080fd5b61151b82614ea4565b634e487b7160e01b600052602160045260246000fd5b80820180821115613473576134736157b0565b81810381811115613473576134736157b0565b6001600160801b03828116828216039080821115614027576140276157b0565b6001600160801b03818116838216019080821115614027576140276157b0565b600081516158a5818560208601615282565b9290920192915050565b6bffffffffffffffffffffffff198360601b168152600082516158d9816014850160208701615282565b919091016014019392505050565b8183823760009101908152919050565b60008251615909818460208701615282565b9190910192915050565b8082028115828204841417613473576134736157b0565b60208082526019908201527f696e636f6e73697374616e7420696e707574206c656e67746800000000000000604082015260600190565b600181811c9082168061597557607f821691505b60208210810361599557634e487b7160e01b600052602260045260246000fd5b50919050565b600081546159a881615961565b600182811680156159c057600181146159d5576128e1565b60ff19841687528215158302870194506128e1565b8560005260208060002060005b858110156159fb5781548a8201529084019082016159e2565b5050509590910195945050505050565b6000615a17828861599b565b652d736362752d60d01b81528651615a36816006840160208b01615282565b808201915050602d60f81b8060068301528651615a5a816007850160208b01615282565b600792019182018190528551615a77816008850160208a01615282565b60089201918201528351615a92816009840160208801615282565b01600901979650505050505050565b6000808335601e19843603018112615ab857600080fd5b8301803591506001600160401b03821115615ad257600080fd5b602001915036819003821315614e2c57600080fd5b6000615af3828a61599b565b662d736e6362752d60c81b81528851615b13816007840160208d01615282565b808201915050602d60f81b8060078301528851615b37816008850160208d01615282565b600892019182018190528751615b54816009850160208c01615282565b600992019182018190528651615b7181600a850160208b01615282565b600a9201918201528451615b8c81600b840160208901615282565b01615b9d600b8201602d60f81b9052565b615baa600c820185615893565b9a9950505050505050505050565b5b81811015611ad15760008155600101615bb9565b601f821115610dbd57806000526020600020601f840160051c81016020851015615bf45750805b615c06601f850160051c830182615bb8565b5050505050565b6001600160401b03831115615c2457615c2461500d565b615c3883615c328354615961565b83615bcd565b6000601f841160018114615c6c5760008515615c545750838201355b600019600387901b1c1916600186901b178355615c06565b600083815260209020601f19861690835b82811015615c9d5786850135825560209485019460019092019101615c7d565b5086821015615cba5760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b6001600160a01b03841681526040602082018190528101829052818360608301376000818301606090810191909152601f909201601f1916010192915050565b60008235603e1983360301811261590957600080fd5b6000808335601e19843603018112615d3957600080fd5b8301803591506001600160401b03821115615d5357600080fd5b6020019150600581901b3603821315614e2c57600080fd5b600060018201615d7d57615d7d6157b0565b5060010190565b813581556001808201602080850135601e19863603018112615da557600080fd5b850180356001600160401b03811115615dbd57600080fd5b6020820191508060051b3603821315615dd557600080fd5b600160401b811115615de957615de961500d565b835481855580821015615e0f57846000526020600020615e0d828201848301615bb8565b505b50600093845260208420935b818110156110da57823585820155918301918501615e1b565b634e487b7160e01b600052601260045260246000fd5b600082615e5957615e59615e34565b500490565b600060208284031215615e7057600080fd5b5051919050565b600060208284031215615e8957600080fd5b815161151b816152d9565b6001600160801b03818116838216028082169190828114615eb757615eb76157b0565b505092915050565b600082615ece57615ece615e34565b500690565b60008235607e1983360301811261590957600080fd5b600060208284031215615efb57600080fd5b815161151b81614dd356fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220f2893ee070f6baab61f4f55788abb83acc79840513de8daab48d773a4330423364736f6c63430008180033
Verified Source Code Partial Match
Compiler: v0.8.24+commit.e11b9ed9
EVM: paris
Optimization: Yes (200 runs)
WellClaim.sol 1133 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IDelegationRegistry} from "./interfaces/IDelegationRegistry.sol";
import {IDelegateRegistry} from "./interfaces/IDelegateRegistry.sol";
import "./interfaces/IWellClaim.sol";
// import "hardhat/console.sol";
/// @title A contract for claiming $WELL over a parameterized vesting schedule
contract WellClaim is
IWellClaim,
Initializable,
UUPSUpgradeable,
ReentrancyGuardUpgradeable,
OwnableUpgradeable
{
using SafeERC20 for IERC20;
uint256 private constant _BASIS_POINTS = 10_000;
uint256 private constant _LOCK_UP_SLOT = 180;
uint256 private constant _END_CYCLE = 4;
uint256 private constant _END_CYCLE_CONTRIBUTORS = 6;
uint256 private constant _MAX_CLAIM_PERIOD = 30 days;
uint256 private constant _MAX_NFT_REWARDS_CLAIM_PERIOD = 60 days;
address public upgrader; // to be set
address public multiClaim; // to be set
IERC721[] public nftCollections;
IDelegationRegistry public dc;
IDelegateRegistry public dcV2;
uint256 public claimStartDate;
IERC20 public claimToken;
bool public claimActive;
// bool public claimTokenDeposited;
bool public unclaimedNFTRewardsWithdrawn;
bool public upgraderRenounced;
uint64 public currentNFTUnlockedBP;
uint64 public previousNFTUnlockedBP;
uint128 public currentNFTUnlockTimestamp;
mapping(address userAddress => mapping(ClaimType claimType => ClaimData userClaimData))
public usersClaimData;
mapping(uint256 collectionId => mapping(uint256 tokenId => NFTClaimData userClaimData))
public nftUsersClaimData;
mapping(ClaimType claimType => ClaimSchedule claimSchedule)
public claimScheduleOf;
mapping(uint256 collectionId => UnclaimedNFTRewards)
public unclaimedNftRewards;
mapping(bytes signature => bool) public usedSignatures;
address public signer;
string public signatureActionPrefix;
// required by the OZ UUPS module
function _authorizeUpgrade(address) internal override onlyUpgrader {}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(
address _claimTokenAddress,
address _kzgAddress,
address _kubzAddress,
address _ygpzAddress
) external initializer {
require(_claimTokenAddress != address(0), "_claimTokenAddress should not be 0");
require(_kzgAddress != address(0), "_kzgAddress should not be 0");
require(_kubzAddress != address(0), "_kubzAddress should not be 0");
require(_ygpzAddress != address(0), "_ygpzAddress should not be 0");
ReentrancyGuardUpgradeable.__ReentrancyGuard_init_unchained();
OwnableUpgradeable.__Ownable_init_unchained(msg.sender);
UUPSUpgradeable.__UUPSUpgradeable_init();
dc = IDelegationRegistry(0x00000000000076A84feF008CDAbe6409d2FE638B);
dcV2 = IDelegateRegistry(0x00000000000000447e69651d841bD8D104Bed493);
claimToken = IERC20(_claimTokenAddress);
nftCollections = [
IERC721(_kzgAddress),
IERC721(_kubzAddress),
IERC721(_ygpzAddress)
];
upgrader = msg.sender;
}
/// @notice Claim token by claimTypes according to the vesting schedule after claim starts, user won't be able to claim after the allocated $WELL are fully vested for _MAX_CLAIM_PERIOD
/// @dev ONLY presaleClaim, ecosystem and contributor contract; Verify claim data and transfer claim token to user if needed, should not be called by NFT holder,
/// emit { UserClaimed } event for amount claimed
/// @param _vault Vault address of delegate.xyz; pass address(0) if not using delegate wallet
/// @param _claimTypes Array of ClaimType to claim
function claim(
address _vault,
ClaimType[] calldata _claimTypes
) public nonReentrant onlyValidClaimSetup {
address requester = _getRequester(_vault);
uint256 totalClaimable = _claim(requester, _claimTypes);
claimToken.safeTransfer(requester, totalClaimable);
}
/// @notice Claim OPTIONALLY on NFTAirdrop/NFTRewards/WalletRewards token by all eligible NFTs according to the vesting schedule after claim starts, user won't be able to claim after the allocated $WELL are fully vested for _MAX_CLAIM_PERIOD
/// @dev ONLY nftClaim contract; ONLY related to NFT claimTypes(i.e. NFTRewards & WalletRewards); Verify claim data and transfer claim token to NFT owner if needed, emit { BulkClaimedInNFTs } event for amount claimed
/// @param _vault Vault address of delegate.xyz; pass address(0) if not using delegate wallet
/// @param _nftCollectionClaimRequests Array of NFTCollectionClaimRequest that consists collection ID of the NFT, token ID(s) the owner owns, array of booleans to indicate NFTAirdrop/NFTRewards claim for each token ID
function claimInNFTs(
address _vault,
NFTCollectionClaimRequest[] calldata _nftCollectionClaimRequests,
bool _withWalletRewards
) external nonReentrant onlyValidClaimSetup {
// console.log(block.timestamp);
address requester = _getRequester(_vault);
uint256 totalClaimable = _claimInNFTs(
requester,
_nftCollectionClaimRequests,
_withWalletRewards
);
claimToken.safeTransfer(requester, totalClaimable);
}
// ===================
// Multicall Functions
// ===================
/// @notice Claim token by claimTypes according to the vesting schedule after claim starts
/// @dev Verify caller is multiClaim, claim data and transfer claim token to _requester if needed, should not be called by NFT holder
/// emit { UserClaimed } event for amount claimed
/// @param _requester address of eligible claim wallet
/// @param _claimTypes Array of ClaimType to claim
function claimFromMulti(
address _requester,
ClaimType[] calldata _claimTypes
) external nonReentrant onlyValidClaimSetup onlyMultiClaim {
uint256 totalClaimable = _claim(_requester, _claimTypes);
claimToken.safeTransfer(_requester, totalClaimable);
}
/// @notice Bulk claim token by claimTypes and eligible NFTs according to the vesting schedule after claim starts
/// @dev Verify caller is multiClaim, claim data and transfer claim token to NFT owner if needed, emit { BulkClaimedInNFTs } event for amount claimed
/// @param _requester address of eligible holder wallet
/// @param _nftCollectionClaimRequests Array of NFTCollectionClaimRequest that consists collection ID of the NFT, token ID(s) the owner owns, array of booleans to indicate NFTAirdrop/NFTRewards claim for each token ID
function claimInNFTsFromMulti(
address _requester,
NFTCollectionClaimRequest[] calldata _nftCollectionClaimRequests,
bool _withWalletRewards
) external nonReentrant onlyValidClaimSetup onlyMultiClaim {
uint256 totalClaimable = _claimInNFTs(
_requester,
_nftCollectionClaimRequests,
_withWalletRewards
);
claimToken.safeTransfer(_requester, totalClaimable);
}
/// @notice Support both v1 and v2 delegate wallet during the v1 to v2 migration
/// @dev Given _vault (cold wallet) address, verify whether _msgSender() is a permitted delegate to operate on behalf of it
/// @param _vault Address to verify against _msgSender
function _getRequester(address _vault) private view returns (address) {
if (_vault == address(0)) return _msgSender();
bool isDelegateValid = dcV2.checkDelegateForAll(
_msgSender(),
_vault,
""
);
if (isDelegateValid) return _vault;
isDelegateValid = dc.checkDelegateForAll(_msgSender(), _vault);
if (!isDelegateValid) revert InvalidDelegate();
return _vault;
}
function _claim(
address _requester,
ClaimType[] memory _claimTypes
) internal returns (uint128 amountClaimed) {
amountClaimed = _executeClaim(_requester, _claimTypes);
if (amountClaimed == 0) revert NoClaimableToken();
emit UserClaimed(_requester, amountClaimed, block.timestamp);
}
function _claimInNFTs(
address _requester,
NFTCollectionClaimRequest[] calldata _nftCollectionClaimRequests,
bool _withWalletRewards
) internal returns (uint128 amountClaimed) {
amountClaimed = _executeClaimInNFTs(
_requester,
_nftCollectionClaimRequests
);
if (_withWalletRewards) {
ClaimData storage userClaimData = usersClaimData[_requester][
ClaimType.WalletRewards
];
uint128 claimable = _calculateClaimable(
userClaimData,
ClaimType.WalletRewards
);
if (claimable > 0) {
/// @dev assume no overflow as the max amountClaimed amount won't exceed uint128 throughout the whole life cycle
unchecked {
userClaimData.claimed += claimable;
amountClaimed += claimable;
}
}
}
if (amountClaimed == 0) revert NoClaimableToken();
emit ClaimedInNFTs(_requester, amountClaimed, block.timestamp);
}
/// @dev Update `claimed` in usersClaimData for the given ClaimTypes
/// @param _requester Address of the claimer
/// @param _claimTypes Array of ClaimType to claim
/// @return totalClaimable Amount of total claimable calculated from the given ClaimTypes
function _executeClaim(
address _requester,
ClaimType[] memory _claimTypes
) private returns (uint128 totalClaimable) {
for (uint256 i; i < _claimTypes.length; i++) {
ClaimData storage userClaimData = usersClaimData[_requester][
_claimTypes[i]
];
uint128 claimable = _calculateClaimable(
userClaimData,
_claimTypes[i]
);
if (claimable > 0) {
/// @dev assume no overflow as the max totalClaimable amount won't exceed uint128 throughout the whole life cycle
unchecked {
userClaimData.claimed += claimable;
totalClaimable += claimable;
}
}
}
}
/// @dev Update `airdropClaimed` AND/OR `rewardsClaimed` based on the booleans passed in nftUsersClaimData for the given NFT Collection ID and token ID(s)
/// @param _requester Address of the claimer
/// @param _nftCollectionClaimRequests Array of NFTCollectionClaimRequest that consists collection ID of the NFT, token ID(s) the owner owns, array of booleans to indicate NFTAirdrop/NFTRewards claim for each token ID
/// @return totalNFTClaimable Amount of total NFT claimable calculated from the given NFT Collection ID and token ID(s)
function _executeClaimInNFTs(
address _requester,
NFTCollectionClaimRequest[] calldata _nftCollectionClaimRequests
) private returns (uint128 totalNFTClaimable) {
for (uint256 i; i < _nftCollectionClaimRequests.length; ) {
uint256[] calldata tokenIds = _nftCollectionClaimRequests[i]
.tokenIds;
bool[] calldata withNFTAirdropList = _nftCollectionClaimRequests[i]
.withNFTAirdropList;
bool[] calldata withNFTRewardsList = _nftCollectionClaimRequests[i]
.withNFTRewardsList;
uint256 len = tokenIds.length;
if (
len != withNFTAirdropList.length ||
len != withNFTRewardsList.length
) {
revert MismatchedArrays();
}
uint256 collectionId = _nftCollectionClaimRequests[i].collectionId;
for (uint256 j; j < len; ) {
uint128 claimable;
if (withNFTAirdropList[j]) {
claimable = _verifyNFTClaim(
_requester,
collectionId,
tokenIds[j]
);
if (claimable > 0) {
/// @dev assume no overflow as the max claimable amount won't exceed uint128
unchecked {
nftUsersClaimData[collectionId][tokenIds[j]]
.airdropClaimed += claimable;
totalNFTClaimable += claimable;
}
}
}
if (withNFTRewardsList[j]) {
claimable = _verifyNFTRewardClaim(
_requester,
collectionId,
tokenIds[j]
);
if (claimable > 0) {
unchecked {
nftUsersClaimData[collectionId][tokenIds[j]]
.rewardsClaimed += claimable;
totalNFTClaimable += claimable;
}
}
}
unchecked {
++j;
}
}
unchecked {
++i;
}
}
}
/// @dev Verify if the caller owns the NFT, and return the correct amount of claimable token
/// @param _requester Address of the claimer
/// @param _collectionId Collection ID of the NFT
/// @param _tokenId Token ID that the owner owns
function _verifyNFTClaim(
address _requester,
uint256 _collectionId,
uint256 _tokenId
) private view onlyValidCollectionId(_collectionId) returns (uint128) {
if (nftCollections[_collectionId].ownerOf(_tokenId) != _requester)
revert Unauthorized();
return
_calculateNFTClaimable(nftUsersClaimData[_collectionId][_tokenId]);
}
function _verifyNFTRewardClaim(
address _requester,
uint256 _collectionId,
uint256 _tokenId
) private view onlyValidCollectionId(_collectionId) returns (uint128) {
if (nftCollections[_collectionId].ownerOf(_tokenId) != _requester)
revert Unauthorized();
return
_calculateNFTRewardsClaimable(
nftUsersClaimData[_collectionId][_tokenId]
);
}
function _calculateClaimable(
ClaimData memory _userClaimdata,
ClaimType _claimType
) private view returns (uint128) {
uint128 totalClaimable = _userClaimdata.totalClaimable;
uint128 claimed = _userClaimdata.claimed;
if (totalClaimable == 0 || claimed >= totalClaimable) return 0;
// for WalletRewards claim will expire after _MAX_CLAIM_PERIOD has passed since claim starts
if (_claimType == ClaimType.WalletRewards) {
if (block.timestamp > claimStartDate + _MAX_CLAIM_PERIOD) {
return 0;
}
return totalClaimable;
}
ClaimSchedule memory claimSchedule = claimScheduleOf[_claimType];
uint256 numOfLockUpBPs = claimSchedule.lockUpBPs.length;
if (numOfLockUpBPs == 0) revert InvalidClaimSetup();
// claim will expire after the allocated $WELL are fully vested for _MAX_CLAIM_PERIOD
if (
block.timestamp >
claimStartDate +
_LOCK_UP_SLOT *
numOfLockUpBPs *
1 days +
_MAX_CLAIM_PERIOD
) {
return 0;
}
uint256 daysElapsed = (block.timestamp - claimStartDate) / 1 days;
// count the cycles passed to distinguish which cycle's 180 days is elapsed
uint256 cyclesPassed = daysElapsed / _LOCK_UP_SLOT;
// PrivatePresale first cycle unlocked amount locks up until the start of next cycle and allows instant claim
if (
_claimType == ClaimType.SeedPresale &&
daysElapsed < _LOCK_UP_SLOT
) return 0;
// Contributors has a different number of cycles, other claim types share the same one
bool isClaimTypeFullyVested = _claimType != ClaimType.Contributors &&
cyclesPassed >= _END_CYCLE;
bool isContributorFullyVested = _claimType == ClaimType.Contributors &&
cyclesPassed >= _END_CYCLE_CONTRIBUTORS;
if (isClaimTypeFullyVested || isContributorFullyVested) {
return _calculateRemainClaimable(totalClaimable, claimed);
}
// cyclesPassed + 1 because we want to calculate the current cycle's (with < 180 days elapsed) unlocked amount
return
_calculateRemainClaimable(
_calculateUnlockedAmount(
claimSchedule,
numOfLockUpBPs,
totalClaimable,
cyclesPassed + 1,
daysElapsed
),
claimed
);
}
function _calculateNFTClaimable(
NFTClaimData memory _nftUserClaimdata
) private view returns (uint128) {
uint256 currentNFTUnlockedBP_ = currentNFTUnlockedBP;
// console.log("BP");
// console.log(currentNFTUnlockedBP_);
if (currentNFTUnlockedBP_ == 0) return 0;
// claim will expire after the allocated $WELL are fully vested for _MAX_CLAIM_PERIOD
if (currentNFTUnlockedBP_ == _BASIS_POINTS) {
if (
block.timestamp > currentNFTUnlockTimestamp + _MAX_CLAIM_PERIOD
) {
return 0;
}
}
uint128 airdropTotalClaimable = _nftUserClaimdata.airdropTotalClaimable;
uint128 airdropClaimed = _nftUserClaimdata.airdropClaimed;
if (
airdropTotalClaimable == 0 ||
airdropClaimed >= airdropTotalClaimable
) return 0;
return
_calculateRemainClaimable(
_calculateNFTUnlockedAmount(airdropTotalClaimable),
airdropClaimed
);
}
function _calculateNFTRewardsClaimable(
NFTClaimData memory _nftUserClaimdata
) private view returns (uint128) {
uint128 rewardsTotalClaimable = _nftUserClaimdata.rewardsTotalClaimable;
uint128 rewardsClaimed = _nftUserClaimdata.rewardsClaimed;
if (
rewardsTotalClaimable == 0 ||
rewardsClaimed >= rewardsTotalClaimable
) return 0;
if (block.timestamp > claimStartDate + _MAX_NFT_REWARDS_CLAIM_PERIOD) {
return 0;
}
return _calculateRemainClaimable(rewardsTotalClaimable, rewardsClaimed);
}
function _calculateRemainClaimable(
uint128 _totalClaimable,
uint128 _claimed
) private pure returns (uint128) {
/// @dev assume no underflow because we already return zero when _claimed is >= _totalClaimable
unchecked {
return _totalClaimable <= _claimed ? 0 : _totalClaimable - _claimed;
}
}
function _calculateUnlockedAmount(
ClaimSchedule memory _claimSchedule,
uint256 _numOfLockUpBPs,
uint128 _totalClaimable,
uint256 _currentCycle,
uint256 _daysElapsed
) private pure returns (uint128) {
if (_currentCycle < _claimSchedule.startCycle) return 0;
if (_currentCycle > _numOfLockUpBPs) return _totalClaimable;
// _currentCycle == _numOfLockUpBPs means _currentCycle is the last one
uint256 currentUnlockedBP = _currentCycle == _numOfLockUpBPs
? _BASIS_POINTS
: _claimSchedule.lockUpBPs[_currentCycle];
return
_calculateUnlockedAmountByDaysElapsed(
_totalClaimable,
_claimSchedule.lockUpBPs[_currentCycle - 1],
currentUnlockedBP,
_daysElapsed % _LOCK_UP_SLOT
);
}
function _calculateUnlockedAmountByDaysElapsed(
uint128 _totalClaimable,
uint256 _previousUnlockedBP,
uint256 _currentUnlockedBP,
uint256 _daysElapsedForCurrentCycle
) private pure returns (uint128) {
if (_daysElapsedForCurrentCycle == 0) {
return
_toUint128(
(_totalClaimable * _previousUnlockedBP) / _BASIS_POINTS
);
}
return
_toUint128(
(_totalClaimable * _previousUnlockedBP) /
_BASIS_POINTS +
(_totalClaimable *
(_currentUnlockedBP - _previousUnlockedBP) *
_daysElapsedForCurrentCycle) /
_BASIS_POINTS /
_LOCK_UP_SLOT
);
}
function _calculateNFTUnlockedAmount(
uint128 _totalClaimable
) private view returns (uint128) {
return
block.timestamp < currentNFTUnlockTimestamp
? _toUint128(
(_totalClaimable * previousNFTUnlockedBP) / _BASIS_POINTS
)
: _toUint128(
(_totalClaimable * currentNFTUnlockedBP) / _BASIS_POINTS
);
}
function _toUint128(uint256 value) private pure returns (uint128) {
if (value >= 1 << 128) revert Uint128Overflow();
return uint128(value);
}
// ====================
// Validation Modifiers
// ====================
modifier onlyUpgrader() {
if (_msgSender() != upgrader) revert Unauthorized();
_;
}
modifier onlyMultiClaim() {
if (_msgSender() != multiClaim) revert Unauthorized();
_;
}
modifier onlyClaimNotOpen() {
if (claimActive) revert ClaimNotClosed();
_;
}
modifier onlyValidClaimSetup() {
if (
!claimActive ||
claimStartDate == 0 ||
block.timestamp < claimStartDate
) revert ClaimNotAvailable();
if (address(claimToken) == address(0)) revert ClaimTokenZeroAddress();
_;
}
modifier onlyValidCollectionId(uint256 _collectionId) {
if (_collectionId >= nftCollections.length)
revert InvalidCollectionId();
_;
}
// ==============
// Claimable Settings
// ==============
// ============ Signer System ============
function setupSigner(
address _signer,
string calldata _signatureActionPrefix
) external onlyOwner {
require(_signer != address(0), "_signer should not be 0");
signer = _signer;
signatureActionPrefix = _signatureActionPrefix;
emit SignerUpdated(_signer, _signatureActionPrefix);
}
function checkValidity(
bytes calldata signature,
string memory action
) public view returns (bool) {
require(
ECDSA.recover(
MessageHashUtils.toEthSignedMessageHash(
keccak256(abi.encodePacked(msg.sender, action))
),
signature
) == signer,
"invalid signature"
);
require(
usedSignatures[signature] == false,
"signature cannot be reused"
);
return true;
}
function checkValidityWithoutSender(
bytes calldata signature,
string memory action
) public view returns (bool) {
require(
ECDSA.recover(
MessageHashUtils.toEthSignedMessageHash(
keccak256(abi.encodePacked(action))
),
signature
) == signer,
"invalid signature"
);
require(
usedSignatures[signature] == false,
"signature cannot be reused"
);
return true;
}
function getChainID() public view returns (uint256) {
uint256 id;
assembly {
id := chainid()
}
return id;
}
function setClaimableByUser(
address _vault,
uint128 _claimable,
ClaimType _claimType,
bytes calldata signature
) public {
address requester = _getRequester(_vault);
require(
usersClaimData[requester][_claimType].totalClaimable == 0,
"Claimable already set"
);
string memory action = string.concat(
signatureActionPrefix,
"-scbu-",
Strings.toString(_claimable),
"-",
Strings.toString(uint256(_claimType)),
"-",
Strings.toString(getChainID()),
"-",
Strings.toString((uint160(address(this))))
);
checkValidity(signature, action);
usedSignatures[signature] = true;
usersClaimData[requester][_claimType].totalClaimable = _claimable;
}
function setClaimableByUserMultiple(
address _vault,
uint128[] calldata _claimables,
ClaimType[] calldata _claimTypes,
bytes[] calldata signatures
) public {
require(_claimables.length == _claimTypes.length && _claimables.length == signatures.length, "inconsistant input length");
for (uint256 i; i < _claimTypes.length; i++) {
setClaimableByUser(_vault, _claimables[i], _claimTypes[i], signatures[i]);
}
}
function claimAfterSetClaimableByUserMultiple(
address _vault,
uint128[] calldata _claimables,
ClaimType[] calldata _claimTypes,
bytes[] calldata signatures
) external {
require(_claimables.length == _claimTypes.length && _claimables.length == signatures.length, "inconsistant input length");
setClaimableByUserMultiple(_vault, _claimables, _claimTypes, signatures);
claim(_vault, _claimTypes);
}
function setNFTClaimablesByUser(
NFTClaimable[] calldata _nftClaimables,
bytes[] calldata signatures
) external {
require(_nftClaimables.length == signatures.length, "inconsistant input length");
for (uint256 i; i < _nftClaimables.length; ) {
uint256 collectionId = _nftClaimables[i].collectionId;
uint256 tokenId = _nftClaimables[i].tokenId;
uint128 airdropAmount = _nftClaimables[i].airdropTotalClaimable;
uint128 rewardsAmount = _nftClaimables[i].rewardsTotalClaimable;
bytes calldata signature = signatures[i];
string memory action = string.concat(
signatureActionPrefix,
"-sncbu-",
Strings.toString(collectionId),
"-",
Strings.toString(tokenId),
"-",
Strings.toString(airdropAmount),
"-",
Strings.toString(rewardsAmount),
"-",
Strings.toString(getChainID()),
"-",
Strings.toString((uint160(address(this))))
);
// console.log(action);
checkValidityWithoutSender(signature, action);
usedSignatures[signature] = true;
unchecked {
++i;
}
}
_setNFTClaimables(_nftClaimables);
}
// ============ Signer System End ============
/// @dev Set `totalClaimable` in usersClaimData for claim type(s)
/// @param _addresses Array of addresses eligible for the claim
/// @param _claimables Array of amounts of claim token
/// @param _claimTypes Array of ClaimType
function setClaimables(
address[] calldata _addresses,
uint128[] calldata _claimables,
ClaimType[] calldata _claimTypes
) external onlyOwner {
uint256 len = _addresses.length;
if (len != _claimables.length || len != _claimTypes.length)
revert MismatchedArrays();
for (uint256 i; i < len; ) {
usersClaimData[_addresses[i]][_claimTypes[i]]
.totalClaimable = _claimables[i];
unchecked {
++i;
}
}
}
/// @dev Set `airdropTotalClaimable` and `rewardsTotalClaimable` in nftUsersClaimData for token ID(s) of respective collection ID
/// @param _nftClaimables Array of NFTClaimable which consists of collectionId, tokenId and amount of claim token
function setNFTClaimables(
NFTClaimable[] calldata _nftClaimables
) external onlyOwner {
_setNFTClaimables(_nftClaimables);
}
function _setNFTClaimables(
NFTClaimable[] calldata _nftClaimables
) internal {
for (uint256 i; i < _nftClaimables.length; ) {
uint256 collectionId = _nftClaimables[i].collectionId;
uint256 tokenId = _nftClaimables[i].tokenId;
uint128 airdropAmount = _nftClaimables[i].airdropTotalClaimable;
uint128 rewardsAmount = _nftClaimables[i].rewardsTotalClaimable;
nftUsersClaimData[collectionId][tokenId]
.airdropTotalClaimable = airdropAmount;
nftUsersClaimData[collectionId][tokenId]
.rewardsTotalClaimable = rewardsAmount;
unchecked {
++i;
}
emit NFTClaimablesUpdated(collectionId, tokenId);
}
}
/// @dev Add new unlock percentage in Basis Points(BP) for NFT holders to instant claim until _BASIS_POINTS is reached
/// @param _additionalNFTUnlockedBP Additional unlocked BP, only add up the currentNFTUnlockedBP
/// @param _newUnlockTimestamp Timestamp for new unlocked BP to take effect
function addNFTUnlockedBPAndSetUnlockTs(
uint64 _additionalNFTUnlockedBP,
uint128 _newUnlockTimestamp
) external onlyOwner {
uint64 currentNFTUnlockedBP_ = currentNFTUnlockedBP;
uint128 currentNFTUnlockTimestamp_ = currentNFTUnlockTimestamp;
if (
_additionalNFTUnlockedBP == 0 ||
currentNFTUnlockedBP_ + _additionalNFTUnlockedBP > _BASIS_POINTS ||
_newUnlockTimestamp <= currentNFTUnlockTimestamp_
) revert InvalidClaimSetup();
previousNFTUnlockedBP = currentNFTUnlockedBP_;
currentNFTUnlockTimestamp = _newUnlockTimestamp;
currentNFTUnlockedBP += _additionalNFTUnlockedBP;
emit NFTUnlockedBPAndUnlockTsUpdated(currentNFTUnlockedBP, currentNFTUnlockTimestamp);
}
/// @dev Set the unclaimedNFTRewards mapping in order to withdraw unclaimed NFTRewards after they are expired
/// @param _collectionId Respective collection ID with unclaimed NFTRewards
/// @param _unclaimTokenIds Array of token IDs with NFTRewards that are left unclaimed
function setUnclaimedNFTRewards(
uint256 _collectionId,
uint128[] calldata _unclaimTokenIds
) external onlyValidCollectionId(_collectionId) onlyOwner {
if (block.timestamp <= claimStartDate + _MAX_NFT_REWARDS_CLAIM_PERIOD)
revert NFTRewardsNotExpired();
UnclaimedNFTRewards storage _unclaimedNftRewards = unclaimedNftRewards[
_collectionId
];
uint256 len = _unclaimTokenIds.length;
if (len == 0 || _unclaimedNftRewards.lastTokenId > _unclaimTokenIds[0])
revert InvalidWithdrawalSetup();
uint128 totalRewardsUnclaimed;
for (uint256 i; i < len; ) {
// ensure the next tokenId is bigger than the prev one
if (i != 0) {
if (_unclaimTokenIds[i] < _unclaimTokenIds[i - 1])
revert InvalidWithdrawalSetup();
}
NFTClaimData memory nftUserClaimData = nftUsersClaimData[
_collectionId
][_unclaimTokenIds[i]];
uint128 rewardsUnclaimed = nftUserClaimData.rewardsTotalClaimable -
nftUserClaimData.rewardsClaimed;
if (rewardsUnclaimed > 0) totalRewardsUnclaimed += rewardsUnclaimed;
unchecked {
++i;
}
}
_unclaimedNftRewards.lastTokenId = _unclaimTokenIds[len - 1];
_unclaimedNftRewards.totalUnclaimed += totalRewardsUnclaimed;
}
/// @dev Set `airdropTotalClaimable` in nftUsersClaimData specifically for single token ID of a newly revealed NFT
/// @param _tokenId Token ID of the newly revealed NFT
/// @param _additionalAirdropTotalClaimable Additional airdropTotalClaimable, only add up since a base amount will be set for unrevealed NFT
function setRevealedNFTClaimable(
uint256 _collectionId,
uint256 _tokenId,
uint128 _additionalAirdropTotalClaimable
) external onlyOwner {
nftUsersClaimData[_collectionId][_tokenId]
.airdropTotalClaimable += _additionalAirdropTotalClaimable;
emit RevealedNFTClaimableUpdated(_collectionId, _tokenId, nftUsersClaimData[_collectionId][_tokenId].airdropTotalClaimable);
}
// ==============
// Claim Settings
// ==============
/// @dev Deposit claim token to contract and start the claim, to be called ONCE only
/// @param _tokenAmount Amount of claim token to be deposited
/// @param _claimStartDate Unix timestamp of the claim start date
function depositClaimTokenAndStartClaim(
uint256 _tokenAmount,
uint256 _claimStartDate
) external onlyOwner {
// if (claimTokenDeposited) revert AlreadyDeposited();
if (address(claimToken) == address(0)) revert ClaimTokenZeroAddress();
if (_tokenAmount == 0) revert InvalidClaimSetup();
if (_claimStartDate == 0) revert InvalidClaimSetup();
claimToken.safeTransferFrom(_msgSender(), address(this), _tokenAmount);
claimStartDate = _claimStartDate;
claimActive = true;
// claimTokenDeposited = true;
emit ClaimTokenDepositedAndClaimStarted(_tokenAmount, _claimStartDate);
}
/// @dev Withdraw claim token from contract only when claim is not open
/// @param _receiver Address to receive the token
/// @param _amount Amount of claim token to be withdrawn
function withdrawClaimToken(
address _receiver,
uint256 _amount
) external onlyOwner {
if (address(claimToken) == address(0)) revert ClaimTokenZeroAddress();
claimToken.safeTransfer(_receiver, _amount);
emit ClaimTokenWithdrawn(_receiver, _amount);
}
/// @dev Withdraw unclaimed NFTRewards after they are expired when _MAX_NFT_REWARDS_CLAIM_PERIOD has passed since claim starts, to be called ONCE only
/// @param _receiver Address to receive the token
function withdrawUnclaimedNFTRewards(address _receiver) external onlyOwner {
if (unclaimedNFTRewardsWithdrawn) revert AlreadyWithdrawn();
if (block.timestamp <= claimStartDate + _MAX_NFT_REWARDS_CLAIM_PERIOD)
revert NFTRewardsNotExpired();
if (_receiver == address(0)) revert InvalidWithdrawalSetup();
uint256 totalWithdrawn;
for (uint256 i; i < nftCollections.length; ) {
UnclaimedNFTRewards
storage _unclaimedNftRewards = unclaimedNftRewards[i];
uint128 unclaimed = _unclaimedNftRewards.totalUnclaimed;
if (unclaimed > 0) {
claimToken.safeTransfer(_receiver, unclaimed);
totalWithdrawn += unclaimed;
}
unchecked {
++i;
}
}
unclaimedNFTRewardsWithdrawn = true;
emit UnclaimedNFTRewardsWithdrawn(totalWithdrawn, block.timestamp);
}
/// @dev Set claim schedule(s) for claim type(s)
/// @param _claimTypes Array of ClaimType
/// @param _claimSchedules Array of ClaimSchedule for each claim type
function setClaimSchedules(
ClaimType[] calldata _claimTypes,
ClaimSchedule[] calldata _claimSchedules
) external onlyOwner onlyClaimNotOpen {
uint256 len = _claimSchedules.length;
if (_claimTypes.length != len) revert MismatchedArrays();
for (uint256 i; i < len; ) {
require(_claimSchedules[i].startCycle < _claimSchedules[i].lockUpBPs.length, "Start cycle should be smaller than lockUpBPs.length");
uint256[] memory lockUpBPs = _claimSchedules[i].lockUpBPs;
for (uint256 j; j < lockUpBPs.length; ) {
if (lockUpBPs[j] > _BASIS_POINTS) revert InvalidClaimSetup();
// ensure the accumulated lockupBP is bigger than the prev one
if (j != 0) {
if (lockUpBPs[j] <= lockUpBPs[j - 1])
revert InvalidClaimSetup();
}
unchecked {
++j;
}
}
claimScheduleOf[_claimTypes[i]] = _claimSchedules[i];
unchecked {
++i;
}
}
emit ClaimSchedulesUpdated();
}
/// @dev Start/stop the claim
/// @param _claimActive New boolean to indicate active or not
function setClaimActive(bool _claimActive) external onlyOwner {
claimActive = _claimActive;
emit ClaimStatusUpdated(_claimActive);
}
/// @dev Set the new claim start date, allow flexibility on setting as past date to unlock claim earlier
/// @param _claimStartDate New date to start the claim
function setClaimStartDate(uint256 _claimStartDate) external onlyOwner {
claimStartDate = _claimStartDate;
emit ClaimStartDateUpdated(_claimStartDate);
}
/// @dev Set the new MultiClaim contract address
/// @param _multiClaim New MultiClaim contract address
function setMultiClaimAddress(address _multiClaim) external onlyOwner {
multiClaim = _multiClaim;
emit MultiClaimAddressUpdated(_multiClaim);
}
/// @dev Set the new UUPS proxy upgrader, allow setting address(0) to disable upgradeability
/// @param _upgrader New upgrader
function setUpgrader(address _upgrader) external onlyOwner {
if (upgraderRenounced) revert UpgraderRenounced();
upgrader = _upgrader;
emit UpgraderUpdated(_upgrader);
}
// /// @notice Renounce the upgradibility of this contract
function renounceUpgrader() external onlyOwner {
if (upgraderRenounced) revert UpgraderRenounced();
upgraderRenounced = true;
upgrader = address(0);
emit UpgraderUpdated(address(0));
}
// =======
// Getters
// =======
/// @notice Get claim info of a user after claim starts
/// @param _user Address of user
/// @return claimableAmount Amount of claimable tokens for a user
/// @return claimableExpiry Timestamp of the claim expiry date for the respective _claimType
function getClaimInfo(
address _user,
ClaimType _claimType
)
public
view
onlyValidClaimSetup
returns (uint128 claimableAmount, uint256 claimableExpiry)
{
uint256 numOfLockUpBPs = claimScheduleOf[_claimType].lockUpBPs.length;
claimableAmount = _calculateClaimable(
usersClaimData[_user][_claimType],
_claimType
);
claimableExpiry = _claimType == ClaimType.WalletRewards
? claimStartDate + _MAX_CLAIM_PERIOD
: claimStartDate +
_LOCK_UP_SLOT *
numOfLockUpBPs *
1 days +
_MAX_CLAIM_PERIOD;
}
/// @notice Get claim info of one eligible NFT after claiming starts
/// @param _collectionId Address of the eligible NFT
/// @param _tokenId Token ID that the owner owns
/// @return claimableAmount Amount of claimable tokens for the NFT
/// @return claimableExpiry Timestamp of the claim expiry date for NFT airdrop
function getClaimInfoByNFT(
uint256 _collectionId,
uint256 _tokenId
)
public
view
onlyValidClaimSetup
onlyValidCollectionId(_collectionId)
returns (uint128 claimableAmount, uint256 claimableExpiry)
{
NFTClaimData memory nftUserClaimData = nftUsersClaimData[_collectionId][
_tokenId
];
claimableAmount = _calculateNFTClaimable(nftUserClaimData);
claimableExpiry = currentNFTUnlockedBP == _BASIS_POINTS
? currentNFTUnlockTimestamp + _MAX_NFT_REWARDS_CLAIM_PERIOD
: 0;
}
/// @notice Get rewards claim info of one eligible NFT after claiming starts
/// @param _collectionId Address of the eligible NFT
/// @param _tokenId Token ID that the owner owns
/// @return claimableAmount Amount of claimable tokens for the NFT
/// @return claimableExpiry Timestamp of the claim expiry date for NFT rewards
function getRewardsClaimInfoByNFT(
uint256 _collectionId,
uint256 _tokenId
)
public
view
onlyValidClaimSetup
onlyValidCollectionId(_collectionId)
returns (uint128 claimableAmount, uint256 claimableExpiry)
{
NFTClaimData memory nftUserClaimData = nftUsersClaimData[_collectionId][
_tokenId
];
claimableAmount = _calculateNFTRewardsClaimable(nftUserClaimData);
claimableExpiry = claimStartDate + _MAX_NFT_REWARDS_CLAIM_PERIOD;
}
/// @notice Get total amounts of claimable tokens of multiple tokenIds in one eligible collection after claiming starts
/// @param _collectionId ID of NFT collection
/// @param _tokenIds Array of all token IDs the owner owns in that collection
function getTotalClaimableAmountsByNFTs(
uint256 _collectionId,
uint256[] calldata _tokenIds
) public view returns (uint128 totalClaimable) {
for (uint256 i; i < _tokenIds.length; i++) {
(uint128 claimable, ) = getClaimInfoByNFT(
_collectionId,
_tokenIds[i]
);
if (claimable == 0) continue;
totalClaimable += claimable;
}
}
/// @notice Get user claim data of multiple tokenIds in multiple eligible collections
/// @param _nftCollectionsInfo Array of NFTCollectionInfo with collectionId and tokenId(s)
/// @return collectionClaimInfo Array of CollectionClaimData that includes claim data for each tokenId of respective collection
function getUserClaimDataByCollections(
NFTCollectionInfo[] calldata _nftCollectionsInfo
) public view returns (CollectionClaimData[] memory collectionClaimInfo) {
uint256 numOfTokenIds;
uint256 len = _nftCollectionsInfo.length;
for (uint256 i = 0; i < len; i++) {
numOfTokenIds += _nftCollectionsInfo[i].tokenIds.length;
}
collectionClaimInfo = new CollectionClaimData[](numOfTokenIds);
uint256 activeId = 0;
for (uint256 i; i < len; i++) {
uint256 collectionId = _nftCollectionsInfo[i].collectionId;
uint256[] memory tokenIds = _nftCollectionsInfo[i].tokenIds;
for (uint256 j; j < tokenIds.length; j++) {
(
uint128 airdropClaimable,
uint256 airdropClaimableExpiry
) = getClaimInfoByNFT(collectionId, tokenIds[j]);
(
uint128 rewardsClaimable,
uint256 rewardClaimableExpiry
) = getRewardsClaimInfoByNFT(collectionId, tokenIds[j]);
collectionClaimInfo[activeId++] = CollectionClaimData(
collectionId,
tokenIds[j],
airdropClaimable,
airdropClaimableExpiry,
nftUsersClaimData[collectionId][tokenIds[j]]
.airdropTotalClaimable,
nftUsersClaimData[collectionId][tokenIds[j]].airdropClaimed,
rewardsClaimable,
rewardClaimableExpiry,
nftUsersClaimData[collectionId][tokenIds[j]]
.rewardsTotalClaimable,
nftUsersClaimData[collectionId][tokenIds[j]].rewardsClaimed
);
}
}
}
/// @notice Get the claim schedule of a certain claim type
function getClaimSchedule(
ClaimType _claimType
) public view returns (ClaimSchedule memory) {
return claimScheduleOf[_claimType];
}
}
Errors.sol 18 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; error ClaimNotAvailable(); error ClaimNotClosed(); error NFTRewardsNotExpired(); error UpgraderRenounced(); error ClaimTokenZeroAddress(); error AlreadyDeposited(); error AlreadyWithdrawn(); error InvalidClaimSetup(); error InvalidWithdrawalSetup(); error InvalidCollectionId(); error InvalidDelegate(); error NoClaimableToken(); error MismatchedArrays(); error Unauthorized(); error Uint128Overflow();
Structs.sol 65 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
enum ClaimType {
WalletRewards,
SeedPresale,
CommunityPresale,
PrivatePresale,
Ecosystem,
Contributors
}
struct ClaimData {
uint128 totalClaimable;
uint128 claimed;
}
struct NFTClaimData {
uint128 airdropTotalClaimable;
uint128 rewardsTotalClaimable;
uint128 airdropClaimed;
uint128 rewardsClaimed;
}
struct ClaimSchedule {
uint256 startCycle;
uint256[] lockUpBPs;
}
struct NFTClaimable {
uint256 collectionId;
uint256 tokenId;
uint128 airdropTotalClaimable;
uint128 rewardsTotalClaimable;
}
struct NFTCollectionInfo {
uint256 collectionId;
uint256[] tokenIds;
}
struct NFTCollectionClaimRequest {
uint256 collectionId;
uint256[] tokenIds;
bool[] withNFTAirdropList;
bool[] withNFTRewardsList;
}
struct CollectionClaimData {
uint256 collectionId;
uint256 tokenId;
uint128 airdropClaimable;
uint256 airdropClaimableExpiry;
uint128 airdropTotalClaimable;
uint128 airdropClaimed;
uint128 rewardsClaimable;
uint256 rewardsClaimableExpiry;
uint128 rewardsTotalClaimable;
uint128 rewardsClaimed;
}
struct UnclaimedNFTRewards {
uint128 lastTokenId;
uint128 totalUnclaimed;
}
IWellClaim.sol 121 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "../lib/Errors.sol";
import "../lib/Structs.sol";
interface IWellClaim {
event UserClaimed(address indexed user, uint128 amount, uint256 claimedAt);
event ClaimedInNFTs(
address indexed owner,
uint128 amount,
uint256 claimedAt
);
event ClaimStatusUpdated(bool claimActive);
event UpgraderUpdated(address newUpgrader);
event UnclaimedNFTRewardsWithdrawn(
uint256 totalWithdrawn,
uint256 withdrawnAt
);
event ClaimTokenDepositedAndClaimStarted(
uint256 tokenAmount,
uint256 claimStartDate
);
event SignerUpdated(address newSigner, string newsignatureActionPrefix);
event ClaimSchedulesUpdated();
event ClaimStartDateUpdated(uint256 claimStartDate);
event MultiClaimAddressUpdated(address newAddress);
event RevealedNFTClaimableUpdated(
uint256 collectionId,
uint256 tokenId,
uint128 newAirdropTotalClaimable
);
event NFTClaimablesUpdated(
uint256 collectionId,
uint256 tokenId
);
event NFTUnlockedBPAndUnlockTsUpdated(
uint64 additionalNFTUnlockedBP,
uint128 newUnlockTimestamp
);
event ClaimTokenWithdrawn(
address receiver,
uint256 amount
);
function claim(address _vault, ClaimType[] calldata _claimTypes) external;
function claimInNFTs(
address _vault,
NFTCollectionClaimRequest[] calldata _nftCollectionClaimRequests,
bool _withWalletRewards
) external;
function claimFromMulti(
address _requester,
ClaimType[] calldata _claimTypes
) external;
function claimInNFTsFromMulti(
address _requester,
NFTCollectionClaimRequest[] calldata _nftCollectionClaimRequests,
bool _withWalletRewards
) external;
function setClaimables(
address[] calldata _addresses,
uint128[] calldata _claimables,
ClaimType[] calldata _claimTypes
) external;
function setNFTClaimables(NFTClaimable[] calldata _nftClaimables) external;
function addNFTUnlockedBPAndSetUnlockTs(
uint64 _additionalNFTUnlockedBP,
uint128 _newUnlockedBPEffectiveTs
) external;
function setUnclaimedNFTRewards(
uint256 _collectionId,
uint128[] calldata _unclaimTokenIds
) external;
function setRevealedNFTClaimable(
uint256 _collectionId,
uint256 _tokenId,
uint128 _additionalAirdropTotalClaimable
) external;
function depositClaimTokenAndStartClaim(
uint256 _tokenAmount,
uint256 _claimStartDate
) external;
function withdrawClaimToken(address _receiver, uint256 _amount) external;
function withdrawUnclaimedNFTRewards(address _receiver) external;
function setClaimSchedules(
ClaimType[] calldata _claimTypes,
ClaimSchedule[] calldata _claimSchedules
) external;
function setClaimActive(bool _claimActive) external;
function setClaimStartDate(uint256 _claimStartDate) external;
function setMultiClaimAddress(address _multiClaim) external;
function getClaimInfo(
address _user,
ClaimType _claimType
) external returns (uint128 claimableAmount, uint256 claimableExpiry);
function getClaimInfoByNFT(
uint256 _collectionId,
uint256 _tokenId
) external returns (uint128 claimableAmount, uint256 claimableExpiry);
function getRewardsClaimInfoByNFT(
uint256 _collectionId,
uint256 _tokenId
) external returns (uint128 claimableAmount, uint256 claimableExpiry);
function getTotalClaimableAmountsByNFTs(
uint256 _collectionId,
uint256[] calldata _tokenIds
) external returns (uint128 totalClaimable);
function getUserClaimDataByCollections(
NFTCollectionInfo[] calldata _nftCollectionInfo
) external returns (CollectionClaimData[] memory collectionClaimInfo);
function getClaimSchedule(
ClaimType _claimType
) external returns (ClaimSchedule memory);
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
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));
}
}
IDelegateRegistry.sol 266 lines
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.13;
/**
* @title IDelegateRegistry
* @custom:version 2.0
* @custom:author foobar (0xfoobar)
* @notice A standalone immutable registry storing delegated permissions from one address to another
*/
interface IDelegateRegistry {
/// @notice Delegation type, NONE is used when a delegation does not exist or is revoked
enum DelegationType {
NONE,
ALL,
CONTRACT,
ERC721,
ERC20,
ERC1155
}
/// @notice Struct for returning delegations
struct Delegation {
DelegationType type_;
address to;
address from;
bytes32 rights;
address contract_;
uint256 tokenId;
uint256 amount;
}
/// @notice Emitted when an address delegates or revokes rights for their entire wallet
event DelegateAll(address indexed from, address indexed to, bytes32 rights, bool enable);
/// @notice Emitted when an address delegates or revokes rights for a contract address
event DelegateContract(
address indexed from, address indexed to, address indexed contract_, bytes32 rights, bool enable
);
/// @notice Emitted when an address delegates or revokes rights for an ERC721 tokenId
event DelegateERC721(
address indexed from,
address indexed to,
address indexed contract_,
uint256 tokenId,
bytes32 rights,
bool enable
);
/// @notice Emitted when an address delegates or revokes rights for an amount of ERC20 tokens
event DelegateERC20(
address indexed from, address indexed to, address indexed contract_, bytes32 rights, uint256 amount
);
/// @notice Emitted when an address delegates or revokes rights for an amount of an ERC1155 tokenId
event DelegateERC1155(
address indexed from,
address indexed to,
address indexed contract_,
uint256 tokenId,
bytes32 rights,
uint256 amount
);
/// @notice Thrown if multicall calldata is malformed
error MulticallFailed();
/**
* ----------- WRITE -----------
*/
/**
* @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
* @param data The encoded function data for each of the calls to make to this contract
* @return results The results from each of the calls passed in via data
*/
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
/**
* @notice Allow the delegate to act on behalf of `msg.sender` for all contracts
* @param to The address to act as delegate
* @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
* @param enable Whether to enable or disable this delegation, true delegates and false revokes
* @return delegationHash The unique identifier of the delegation
*/
function delegateAll(address to, bytes32 rights, bool enable) external payable returns (bytes32 delegationHash);
/**
* @notice Allow the delegate to act on behalf of `msg.sender` for a specific contract
* @param to The address to act as delegate
* @param contract_ The contract whose rights are being delegated
* @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
* @param enable Whether to enable or disable this delegation, true delegates and false revokes
* @return delegationHash The unique identifier of the delegation
*/
function delegateContract(address to, address contract_, bytes32 rights, bool enable)
external
payable
returns (bytes32 delegationHash);
/**
* @notice Allow the delegate to act on behalf of `msg.sender` for a specific ERC721 token
* @param to The address to act as delegate
* @param contract_ The contract whose rights are being delegated
* @param tokenId The token id to delegate
* @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
* @param enable Whether to enable or disable this delegation, true delegates and false revokes
* @return delegationHash The unique identifier of the delegation
*/
function delegateERC721(address to, address contract_, uint256 tokenId, bytes32 rights, bool enable)
external
payable
returns (bytes32 delegationHash);
/**
* @notice Allow the delegate to act on behalf of `msg.sender` for a specific amount of ERC20 tokens
* @dev The actual amount is not encoded in the hash, just the existence of a amount (since it is an upper bound)
* @param to The address to act as delegate
* @param contract_ The address for the fungible token contract
* @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
* @param amount The amount to delegate, > 0 delegates and 0 revokes
* @return delegationHash The unique identifier of the delegation
*/
function delegateERC20(address to, address contract_, bytes32 rights, uint256 amount)
external
payable
returns (bytes32 delegationHash);
/**
* @notice Allow the delegate to act on behalf of `msg.sender` for a specific amount of ERC1155 tokens
* @dev The actual amount is not encoded in the hash, just the existence of a amount (since it is an upper bound)
* @param to The address to act as delegate
* @param contract_ The address of the contract that holds the token
* @param tokenId The token id to delegate
* @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
* @param amount The amount of that token id to delegate, > 0 delegates and 0 revokes
* @return delegationHash The unique identifier of the delegation
*/
function delegateERC1155(address to, address contract_, uint256 tokenId, bytes32 rights, uint256 amount)
external
payable
returns (bytes32 delegationHash);
/**
* ----------- CHECKS -----------
*/
/**
* @notice Check if `to` is a delegate of `from` for the entire wallet
* @param to The potential delegate address
* @param from The potential address who delegated rights
* @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
* @return valid Whether delegate is granted to act on the from's behalf
*/
function checkDelegateForAll(address to, address from, bytes32 rights) external view returns (bool);
/**
* @notice Check if `to` is a delegate of `from` for the specified `contract_` or the entire wallet
* @param to The delegated address to check
* @param contract_ The specific contract address being checked
* @param from The cold wallet who issued the delegation
* @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
* @return valid Whether delegate is granted to act on from's behalf for entire wallet or that specific contract
*/
function checkDelegateForContract(address to, address from, address contract_, bytes32 rights)
external
view
returns (bool);
/**
* @notice Check if `to` is a delegate of `from` for the specific `contract` and `tokenId`, the entire `contract_`, or the entire wallet
* @param to The delegated address to check
* @param contract_ The specific contract address being checked
* @param tokenId The token id for the token to delegating
* @param from The wallet that issued the delegation
* @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
* @return valid Whether delegate is granted to act on from's behalf for entire wallet, that contract, or that specific tokenId
*/
function checkDelegateForERC721(address to, address from, address contract_, uint256 tokenId, bytes32 rights)
external
view
returns (bool);
/**
* @notice Returns the amount of ERC20 tokens the delegate is granted rights to act on the behalf of
* @param to The delegated address to check
* @param contract_ The address of the token contract
* @param from The cold wallet who issued the delegation
* @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
* @return balance The delegated balance, which will be 0 if the delegation does not exist
*/
function checkDelegateForERC20(address to, address from, address contract_, bytes32 rights)
external
view
returns (uint256);
/**
* @notice Returns the amount of a ERC1155 tokens the delegate is granted rights to act on the behalf of
* @param to The delegated address to check
* @param contract_ The address of the token contract
* @param tokenId The token id to check the delegated amount of
* @param from The cold wallet who issued the delegation
* @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
* @return balance The delegated balance, which will be 0 if the delegation does not exist
*/
function checkDelegateForERC1155(address to, address from, address contract_, uint256 tokenId, bytes32 rights)
external
view
returns (uint256);
/**
* ----------- ENUMERATIONS -----------
*/
/**
* @notice Returns all enabled delegations a given delegate has received
* @param to The address to retrieve delegations for
* @return delegations Array of Delegation structs
*/
function getIncomingDelegations(address to) external view returns (Delegation[] memory delegations);
/**
* @notice Returns all enabled delegations an address has given out
* @param from The address to retrieve delegations for
* @return delegations Array of Delegation structs
*/
function getOutgoingDelegations(address from) external view returns (Delegation[] memory delegations);
/**
* @notice Returns all hashes associated with enabled delegations an address has received
* @param to The address to retrieve incoming delegation hashes for
* @return delegationHashes Array of delegation hashes
*/
function getIncomingDelegationHashes(address to) external view returns (bytes32[] memory delegationHashes);
/**
* @notice Returns all hashes associated with enabled delegations an address has given out
* @param from The address to retrieve outgoing delegation hashes for
* @return delegationHashes Array of delegation hashes
*/
function getOutgoingDelegationHashes(address from) external view returns (bytes32[] memory delegationHashes);
/**
* @notice Returns the delegations for a given array of delegation hashes
* @param delegationHashes is an array of hashes that correspond to delegations
* @return delegations Array of Delegation structs, return empty structs for nonexistent or revoked delegations
*/
function getDelegationsFromHashes(bytes32[] calldata delegationHashes)
external
view
returns (Delegation[] memory delegations);
/**
* ----------- STORAGE ACCESS -----------
*/
/**
* @notice Allows external contracts to read arbitrary storage slots
*/
function readSlot(bytes32 location) external view returns (bytes32);
/**
* @notice Allows external contracts to read an arbitrary array of storage slots
*/
function readSlots(bytes32[] calldata locations) external view returns (bytes32[] memory);
}
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;
}
}
IDelegationRegistry.sol 184 lines
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.17;
/**
* @title An immutable registry contract to be deployed as a standalone primitive
* @dev See EIP-5639, new project launches can read previous cold wallet -> hot wallet delegations
* from here and integrate those permissions into their flow
*/
interface IDelegationRegistry {
/// @notice Delegation type
enum DelegationType {
NONE,
ALL,
CONTRACT,
TOKEN
}
/// @notice Info about a single delegation, used for onchain enumeration
struct DelegationInfo {
DelegationType type_;
address vault;
address delegate;
address contract_;
uint256 tokenId;
}
/// @notice Info about a single contract-level delegation
struct ContractDelegation {
address contract_;
address delegate;
}
/// @notice Info about a single token-level delegation
struct TokenDelegation {
address contract_;
uint256 tokenId;
address delegate;
}
/// @notice Emitted when a user delegates their entire wallet
event DelegateForAll(address vault, address delegate, bool value);
/// @notice Emitted when a user delegates a specific contract
event DelegateForContract(address vault, address delegate, address contract_, bool value);
/// @notice Emitted when a user delegates a specific token
event DelegateForToken(address vault, address delegate, address contract_, uint256 tokenId, bool value);
/// @notice Emitted when a user revokes all delegations
event RevokeAllDelegates(address vault);
/// @notice Emitted when a user revoes all delegations for a given delegate
event RevokeDelegate(address vault, address delegate);
/**
* ----------- WRITE -----------
*/
/**
* @notice Allow the delegate to act on your behalf for all contracts
* @param delegate The hotwallet to act on your behalf
* @param value Whether to enable or disable delegation for this address, true for setting and false for revoking
*/
function delegateForAll(address delegate, bool value) external;
/**
* @notice Allow the delegate to act on your behalf for a specific contract
* @param delegate The hotwallet to act on your behalf
* @param contract_ The address for the contract you're delegating
* @param value Whether to enable or disable delegation for this address, true for setting and false for revoking
*/
function delegateForContract(address delegate, address contract_, bool value) external;
/**
* @notice Allow the delegate to act on your behalf for a specific token
* @param delegate The hotwallet to act on your behalf
* @param contract_ The address for the contract you're delegating
* @param tokenId The token id for the token you're delegating
* @param value Whether to enable or disable delegation for this address, true for setting and false for revoking
*/
function delegateForToken(address delegate, address contract_, uint256 tokenId, bool value) external;
/**
* @notice Revoke all delegates
*/
function revokeAllDelegates() external;
/**
* @notice Revoke a specific delegate for all their permissions
* @param delegate The hotwallet to revoke
*/
function revokeDelegate(address delegate) external;
/**
* @notice Remove yourself as a delegate for a specific vault
* @param vault The vault which delegated to the msg.sender, and should be removed
*/
function revokeSelf(address vault) external;
/**
* ----------- READ -----------
*/
/**
* @notice Returns all active delegations a given delegate is able to claim on behalf of
* @param delegate The delegate that you would like to retrieve delegations for
* @return info Array of DelegationInfo structs
*/
function getDelegationsByDelegate(address delegate) external view returns (DelegationInfo[] memory);
/**
* @notice Returns an array of wallet-level delegates for a given vault
* @param vault The cold wallet who issued the delegation
* @return addresses Array of wallet-level delegates for a given vault
*/
function getDelegatesForAll(address vault) external view returns (address[] memory);
/**
* @notice Returns an array of contract-level delegates for a given vault and contract
* @param vault The cold wallet who issued the delegation
* @param contract_ The address for the contract you're delegating
* @return addresses Array of contract-level delegates for a given vault and contract
*/
function getDelegatesForContract(address vault, address contract_) external view returns (address[] memory);
/**
* @notice Returns an array of contract-level delegates for a given vault's token
* @param vault The cold wallet who issued the delegation
* @param contract_ The address for the contract holding the token
* @param tokenId The token id for the token you're delegating
* @return addresses Array of contract-level delegates for a given vault's token
*/
function getDelegatesForToken(address vault, address contract_, uint256 tokenId)
external
view
returns (address[] memory);
/**
* @notice Returns all contract-level delegations for a given vault
* @param vault The cold wallet who issued the delegations
* @return delegations Array of ContractDelegation structs
*/
function getContractLevelDelegations(address vault)
external
view
returns (ContractDelegation[] memory delegations);
/**
* @notice Returns all token-level delegations for a given vault
* @param vault The cold wallet who issued the delegations
* @return delegations Array of TokenDelegation structs
*/
function getTokenLevelDelegations(address vault) external view returns (TokenDelegation[] memory delegations);
/**
* @notice Returns true if the address is delegated to act on the entire vault
* @param delegate The hotwallet to act on your behalf
* @param vault The cold wallet who issued the delegation
*/
function checkDelegateForAll(address delegate, address vault) external view returns (bool);
/**
* @notice Returns true if the address is delegated to act on your behalf for a token contract or an entire vault
* @param delegate The hotwallet to act on your behalf
* @param contract_ The address for the contract you're delegating
* @param vault The cold wallet who issued the delegation
*/
function checkDelegateForContract(address delegate, address vault, address contract_)
external
view
returns (bool);
/**
* @notice Returns true if the address is delegated to act on your behalf for a specific token, the token's contract or an entire vault
* @param delegate The hotwallet to act on your behalf
* @param contract_ The address for the contract you're delegating
* @param tokenId The token id for the token you're delegating
* @param vault The cold wallet who issued the delegation
*/
function checkDelegateForToken(address delegate, address vault, address contract_, uint256 tokenId)
external
view
returns (bool);
}
StorageSlot.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
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);
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.20;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
IERC721.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
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);
}
}
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
ERC1967Utils.sol 193 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.20;
import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*/
library ERC1967Utils {
// We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
// This will be fixed in Solidity 0.8.21. At that point we should remove these events.
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
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);
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
MessageHashUtils.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}
ContextUpgradeable.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
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;
}
}
OwnableUpgradeable.sol 119 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @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.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
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) {
OwnableStorage storage $ = _getOwnableStorage();
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 {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Initializable.sol 228 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
UUPSUpgradeable.sol 153 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.20;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC1967-compliant implementation pointing to self.
* See {_onlyProxy}.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}
ReentrancyGuardUpgradeable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ReentrancyGuardUpgradeable is Initializable {
// 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;
/// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
struct ReentrancyGuardStorage {
uint256 _status;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
assembly {
$.slot := ReentrancyGuardStorageLocation
}
}
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
$._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 {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// 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 {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// 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) {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
return $._status == ENTERED;
}
}
Read Contract
UPGRADE_INTERFACE_VERSION 0xad3cb1cc → string
checkValidity 0x30f89953 → bool
checkValidityWithoutSender 0x3284c3b1 → bool
claimActive 0xd4a6a2fd → bool
claimScheduleOf 0xf92b41bd → uint256
claimStartDate 0x5f03b6b2 → uint256
claimToken 0x4451d89f → address
currentNFTUnlockTimestamp 0x4d9c41a7 → uint128
currentNFTUnlockedBP 0xb607bc30 → uint64
dc 0xd8a531a6 → address
dcV2 0x85c23195 → address
getChainID 0x564b81ef → uint256
getClaimInfo 0x416b3e1e → uint128, uint256
getClaimInfoByNFT 0x3c11bdd6 → uint128, uint256
getClaimSchedule 0xab14dee4 → tuple
getRewardsClaimInfoByNFT 0xbc5800e5 → uint128, uint256
getTotalClaimableAmountsByNFTs 0x8ad0838d → uint128
getUserClaimDataByCollections 0x1395fbe0 → tuple[]
multiClaim 0x8131fd16 → address
nftCollections 0xbfca66c9 → address
nftUsersClaimData 0x51fa7cc2 → uint128, uint128, uint128, uint128
owner 0x8da5cb5b → address
previousNFTUnlockedBP 0xe2748429 → uint64
proxiableUUID 0x52d1902d → bytes32
signatureActionPrefix 0x51ca0ffa → string
signer 0x238ac933 → address
unclaimedNFTRewardsWithdrawn 0x427fa204 → bool
unclaimedNftRewards 0x6d5bc5ca → uint128, uint128
upgrader 0xaf269745 → address
upgraderRenounced 0x8110c50f → bool
usedSignatures 0xe949580e → bool
usersClaimData 0x6e35d395 → uint128, uint128
Write Contract 27 functions
These functions modify contract state and require a wallet transaction to execute.
addNFTUnlockedBPAndSetUnlockTs 0x1d671c5b
uint64 _additionalNFTUnlockedBP
uint128 _newUnlockTimestamp
claim 0xf0fd1084
address _vault
uint8[] _claimTypes
claimAfterSetClaimableByUserMultiple 0x468169b3
address _vault
uint128[] _claimables
uint8[] _claimTypes
bytes[] signatures
claimFromMulti 0x19a8b4a0
address _requester
uint8[] _claimTypes
claimInNFTs 0x627e7f68
address _vault
tuple[] _nftCollectionClaimRequests
bool _withWalletRewards
claimInNFTsFromMulti 0x6a0e3ca0
address _requester
tuple[] _nftCollectionClaimRequests
bool _withWalletRewards
depositClaimTokenAndStartClaim 0x474954c3
uint256 _tokenAmount
uint256 _claimStartDate
initialize 0xf8c8765e
address _claimTokenAddress
address _kzgAddress
address _kubzAddress
address _ygpzAddress
renounceOwnership 0x715018a6
No parameters
renounceUpgrader 0xf163d712
No parameters
setClaimActive 0x73417b09
bool _claimActive
setClaimSchedules 0xb23e42b8
uint8[] _claimTypes
tuple[] _claimSchedules
setClaimStartDate 0x7b2d3e69
uint256 _claimStartDate
setClaimableByUser 0x6acf6eac
address _vault
uint128 _claimable
uint8 _claimType
bytes signature
setClaimableByUserMultiple 0x97520f74
address _vault
uint128[] _claimables
uint8[] _claimTypes
bytes[] signatures
setClaimables 0x232275c1
address[] _addresses
uint128[] _claimables
uint8[] _claimTypes
setMultiClaimAddress 0xb21185b3
address _multiClaim
setNFTClaimables 0xa5a5ecac
tuple[] _nftClaimables
setNFTClaimablesByUser 0xc2ff238c
tuple[] _nftClaimables
bytes[] signatures
setRevealedNFTClaimable 0xcbaaccb4
uint256 _collectionId
uint256 _tokenId
uint128 _additionalAirdropTotalClaimable
setUnclaimedNFTRewards 0x2f152158
uint256 _collectionId
uint128[] _unclaimTokenIds
setUpgrader 0x1b878f71
address _upgrader
setupSigner 0x92012339
address _signer
string _signatureActionPrefix
transferOwnership 0xf2fde38b
address newOwner
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
withdrawClaimToken 0x6afffd90
address _receiver
uint256 _amount
withdrawUnclaimedNFTRewards 0x32e52ae1
address _receiver
Recent Transactions
No transactions found for this address