Address Contract Verified
Address
0x487b7A29FeA0462024C25D9DE3e20E8b86De7730
Balance
0 ETH
Nonce
1
Code Size
12769 bytes
Creator
0x030839C3...3D41 at tx 0xf4e769f2...edf8d5
Indexed Transactions
0
Contract Bytecode
12769 bytes
0x608060405234801561001057600080fd5b50600436106102275760003560e01c806370a0823111610130578063c87b56dd116100b8578063e64a21f31161007c578063e64a21f314610571578063e985e9c514610584578063f2fde38b146105c0578063f301e3d0146105d3578063fd712bbe146105e657600080fd5b8063c87b56dd146104a2578063cf2c86d7146104b5578063cf8088b9146104c8578063d578ceab146104db578063d7d67576146104e457600080fd5b80638da5cb5b116100ff5780638da5cb5b1461043d57806395d89b411461044e578063a22cb46514610456578063b6d238d814610464578063b88d4fde1461048f57600080fd5b806370a08231146103e6578063715018a6146103f9578063848e736514610401578063884336511461042a57600080fd5b806323b872dd116101b357806342842e0e1161018257806342842e0e146103785780634f6ccce71461038b5780635e9196ad1461039e5780636352211e146103b157806369dc9ff3146103c457600080fd5b806323b872dd146103375780632e17de781461034a5780632f745c591461035d578063372500ab1461037057600080fd5b8063095ea7b3116101fa578063095ea7b3146102cd5780630c51b88f146102dd578063150b7a02146102f05780631772188e1461031c57806318160ddd1461032f57600080fd5b806301ffc9a71461022c57806303865eae1461025457806306fdde031461028d578063081812fc146102a2575b600080fd5b61023f61023a366004612d2f565b6105f9565b60405190151581526020015b60405180910390f35b61027f610262366004612c90565b601060209081526000928352604080842090915290825290205481565b60405190815260200161024b565b61029561060a565b60405161024b9190612f13565b6102b56102b0366004612d69565b61069c565b6040516001600160a01b03909116815260200161024b565b6102db610227366004612c90565b005b6102db6102eb366004612cba565b610736565b6103036102fe3660046129d0565b610b18565b6040516001600160e01b0319909116815260200161024b565b61027f61032a366004612d69565b610bac565b60095461027f565b6102db610345366004612994565b610cdd565b6102db610358366004612d69565b610d13565b61027f61036b366004612c90565b610fb4565b6102db61104a565b6102db610386366004612994565b611081565b61027f610399366004612d69565b61109c565b6102db6103ac366004612c32565b61112f565b6102b56103bf366004612d69565b611235565b6103d76103d2366004612946565b6112ac565b60405161024b93929190612ede565b61027f6103f4366004612946565b611365565b6102db6113ec565b6102b561040f366004612d69565b6013602052600090815260409020546001600160a01b031681565b6102db610438366004612be4565b611422565b600b546001600160a01b03166102b5565b61029561147b565b6102db610227366004612b41565b61027f610472366004612c90565b601160209081526000928352604080842090915290825290205481565b6102db61049d366004612a6b565b61148a565b6102956104b0366004612d69565b6114c2565b6102db6104c3366004612d69565b6115b3565b6102db6104d6366004612946565b611748565b61027f60145481565b61053b6104f2366004612c90565b600e60209081526000928352604080842090915290825290208054600182015460028301546003840154600485015460059095015493949293919290916001600160a01b031686565b60408051968752602087019590955293850192909252606084015260808301526001600160a01b031660a082015260c00161024b565b6102db61057f366004612ced565b61182c565b61023f610592366004612961565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6102db6105ce366004612946565b61186a565b6102db6105e1366004612ae7565b611902565b6102db6105f4366004612b6b565b611942565b600061060482611a23565b92915050565b606060008054610619906130bd565b80601f0160208091040260200160405190810160405280929190818152602001828054610645906130bd565b80156106925780601f1061066757610100808354040283529160200191610692565b820191906000526020600020905b81548152906001019060200180831161067557829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661071a5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b6001600160a01b0383166000908152601260205260409020805460ff1661079f5760405162461bcd60e51b815260206004820152601c60248201527f746f6b656e20636f6e7472616374206973206e6f7420616374697665000000006044820152606401610711565b60018210156107e95760405162461bcd60e51b81526020600482015260166024820152751a5b9d985b1a59081b5a5b9a5b5d5b481c195c9a5bd960521b6044820152606401610711565b60006107f8836224ea0061305b565b610802904261302f565b90506000805b6002840154811015610870578484600201828154811061082a5761082a613169565b9060005260206000200154141561085e5783600301818154811061085057610850613169565b906000526020600020015491505b80610868816130f8565b915050610808565b50806108b55760405162461bcd60e51b81526020600482015260146024820152731a5b9d985b1a59081cdd185ad9481c195c9a5bd960621b6044820152606401610711565b6040518060c00160405280868152602001428152602001838152602001828152602001858152602001336001600160a01b0316815250600e6000886001600160a01b03166001600160a01b03168152602001908152602001600020600061091b600c5490565b8152602080820192909252604090810160009081208451815584840151600182015584830151600282015560608501516003820155608085015160048083019190915560a090950151600590910180546001600160a01b0319166001600160a01b039283161790558a81168252601084528282208a83529093528181205585549051632142170760e11b8152339381019390935230602484015260448301889052610100900416906342842e0e90606401600060405180830381600087803b1580156109e657600080fd5b505af11580156109fa573d6000803e3d6000fd5b5050506001600160a01b0387166000908152600f602090815260408083203384529091529020610a2b915086611a48565b50600c546001600160a01b0387166000908152601160209081526040808320898452909152902055610a6533610a60600c5490565b611a5b565b8560136000610a73600c5490565b815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055507f3f2c357944e938881625b91afe18fca2fba3e7748e8a8418d9209d1f926d526e610acf600c5490565b604080519182526001600160a01b038916602083015281018790523360608201526080810184905260a00160405180910390a1610b10600c80546001019055565b505050505050565b60006001600160a01b0386163014610b815760405162461bcd60e51b815260206004820152602660248201527f746f6b656e206d757374206265207374616b6564206f766572207374616b65206044820152651b595d1a1bd960d21b6064820152608401610711565b507f150b7a023d4804d13e8c85fb27262cb750cf6ba9f9dd3bb30d90f482ceeb4b1f95945050505050565b6000818152601360209081526040808320546001600160a01b03908116808552600e84528285208686529093529083206005810154909116610c305760405162461bcd60e51b815260206004820152601e60248201527f63616e6e6f7420717565727920616e20756e7374616b656420746f6b656e00006044820152606401610711565b600062093a8082600101548360020154610c4a919061307a565b610c549190613047565b9050600062093a80836001015442610c6c919061307a565b610c769190613047565b6001600160a01b03851660009081526010602090815260408083208a8452909152902054600385015491925090600490848411610cb35783610cb5565b845b610cbf919061305b565b610cc99190613047565b610cd3919061307a565b9695505050505050565b610ce73382611ba9565b610d035760405162461bcd60e51b815260040161071190612fad565b610d0e838383611ca0565b505050565b6000818152600260205260409020546001600160a01b0316610d775760405162461bcd60e51b815260206004820152601c60248201527f717565727920666f72206e6f6e206578697374656e7420746f6b656e000000006044820152606401610711565b6000818152601360209081526040808320546001600160a01b0390811680855260128452828520600e855283862087875290945291909320600581015491939091163314610e075760405162461bcd60e51b815260206004820152601a60248201527f63616c6c6572206e6f74206f776e73207468697320746f6b656e0000000000006044820152606401610711565b80600201544211610e5a5760405162461bcd60e51b815260206004820181905260248201527f7374616b656420706572696f6420646964206e6f742066696e697368207965746044820152606401610711565b610e63846115b3565b81548154604051632142170760e11b815230600482015233602482015260448101919091526101009091046001600160a01b0316906342842e0e90606401600060405180830381600087803b158015610ebb57600080fd5b505af1158015610ecf573d6000803e3d6000fd5b505082546001600160a01b0386166000908152600f602090815260408083203384529091529020610f0293509150611e4b565b50610f0c84611e57565b8054604080518681526001600160a01b038616602082015280820192909252336060830152517f673aec720ee2ccd5cc92d732180f629159861b27945322f146ad2429c5928fcc9181900360800190a150506001600160a01b03166000908152600e60209081526040808320938352929052908120818155600181018290556002810182905560038101829055600481019190915560050180546001600160a01b0319169055565b6000610fbf83611365565b82106110215760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610711565b506001600160a01b03919091166000908152600760209081526040808320938352929052205490565b60005b6110576015611e60565b81101561107e5761106c6104d6601583611e6a565b80611076816130f8565b91505061104d565b50565b610d0e8383836040518060200160405280600081525061148a565b60006110a760095490565b821061110a5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610711565b6009828154811061111d5761111d613169565b90600052602060002001549050919050565b600b546001600160a01b031633146111595760405162461bcd60e51b815260040161071190612f78565b6040805160a08101825260018082526001600160a01b0387811660208085018281528587018a8152606087018a905260808701899052600093845260128352969092208551815493516001600160a81b0319909416901515610100600160a81b031916176101009390941692909202929092178155935180519394936111e69385019291909101906126c7565b506060820151805161120291600284019160209091019061274b565b506080820151805161121e91600384019160209091019061274b565b5061122e91506015905085611e76565b5050505050565b6000818152600260205260408120546001600160a01b0316806106045760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610711565b6012602052600090815260409020805460018201805460ff8316936101009093046001600160a01b03169291906112e2906130bd565b80601f016020809104026020016040519081016040528092919081815260200182805461130e906130bd565b801561135b5780601f106113305761010080835404028352916020019161135b565b820191906000526020600020905b81548152906001019060200180831161133e57829003601f168201915b5050505050905083565b60006001600160a01b0382166113d05760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610711565b506001600160a01b031660009081526003602052604090205490565b600b546001600160a01b031633146114165760405162461bcd60e51b815260040161071190612f78565b6114206000611e8b565b565b600b546001600160a01b0316331461144c5760405162461bcd60e51b815260040161071190612f78565b6001600160a01b03821660009081526012602090815260409091208251610d0e926001909201918401906126c7565b606060018054610619906130bd565b6114943383611ba9565b6114b05760405162461bcd60e51b815260040161071190612fad565b6114bc84848484611edd565b50505050565b6000818152600260205260409020546060906001600160a01b03166115295760405162461bcd60e51b815260206004820152601c60248201527f717565727920666f72206e6f6e206578697374656e7420746f6b656e000000006044820152606401610711565b6000828152601360209081526040808320546001600160a01b031680845260128352818420600e845282852087865290935292208054600183019061156d90611f10565b61157a8360010154611f10565b6115878460020154611f10565b60405160200161159a9493929190612dca565b6040516020818303038152906040529350505050919050565b6000818152601360209081526040808320546001600160a01b03908116808552600e8452828520868652909352922060058101549192909116331461163a5760405162461bcd60e51b815260206004820152601f60248201527f63616c6c657220646964206e6f74207374616b65207468697320746f6b656e006044820152606401610711565b600061164584610bac565b905080156114bc57600d546040516340c10f1960e01b8152336004820152602481018390526001600160a01b03909116906340c10f1990604401600060405180830381600087803b15801561169957600080fd5b505af11580156116ad573d6000803e3d6000fd5b505050506001600160a01b0383166000908152601060209081526040808320878452909152812080548392906116e490849061302f565b9250508190555080601460008282546116fd919061302f565b9091555050604080518581523360208201529081018290527f2dec7e6b69254a25372fd22ba57a1ddc51e9dd40dec3d2da9e3f894754b8eea19060600160405180910390a150505050565b6001600160a01b0381166000908152600f6020908152604080832033845290915281209061177582611e60565b9050600081116117d55760405162461bcd60e51b815260206004820152602560248201527f63616c6c657220646f6573206e6f74206861766520616e79207374616b6564206044820152643a37b5b2b760d91b6064820152608401610711565b60005b818110156114bc576001600160a01b038416600090815260116020526040812061181a916118068685611e6a565b8152602001908152602001600020546115b3565b80611824816130f8565b9150506117d8565b60005b81811015610d0e5761185883838381811061184c5761184c613169565b90506020020135610d13565b80611862816130f8565b91505061182f565b600b546001600160a01b031633146118945760405162461bcd60e51b815260040161071190612f78565b6001600160a01b0381166118f95760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610711565b61107e81611e8b565b60005b8281101561122e576119308585858481811061192357611923613169565b9050602002013584610736565b8061193a816130f8565b915050611905565b600b546001600160a01b0316331461196c5760405162461bcd60e51b815260040161071190612f78565b61197760158561200e565b6119b85760405162461bcd60e51b815260206004820152601260248201527118dbdb9d1c9858dd081b9bdd08185919195960721b6044820152606401610711565b6001600160a01b0384166000908152601260209081526040909120805460ff191685151517815583516119f39260029092019185019061274b565b506001600160a01b0384166000908152601260209081526040909120825161122e9260039092019184019061274b565b60006001600160e01b0319821663780e9d6360e01b1480610604575061060482612030565b6000611a548383612080565b9392505050565b6001600160a01b038216611ab15760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610711565b6000818152600260205260409020546001600160a01b031615611b165760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610711565b611b22600083836120cf565b6001600160a01b0382166000908152600360205260408120805460019290611b4b90849061302f565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6000818152600260205260408120546001600160a01b0316611c225760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610711565b6000611c2d83611235565b9050806001600160a01b0316846001600160a01b03161480611c685750836001600160a01b0316611c5d8461069c565b6001600160a01b0316145b80611c9857506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611cb382611235565b6001600160a01b031614611d1b5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610711565b6001600160a01b038216611d7d5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610711565b611d888383836120cf565b611d93600082612100565b6001600160a01b0383166000908152600360205260408120805460019290611dbc90849061307a565b90915550506001600160a01b0382166000908152600360205260408120805460019290611dea90849061302f565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6000611a54838361216e565b61107e81612261565b6000610604825490565b6000611a5483836122a1565b6000611a54836001600160a01b038416612080565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b611ee8848484611ca0565b611ef4848484846122cb565b6114bc5760405162461bcd60e51b815260040161071190612f26565b606081611f345750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611f5e5780611f48816130f8565b9150611f579050600a83613047565b9150611f38565b60008167ffffffffffffffff811115611f7957611f7961317f565b6040519080825280601f01601f191660200182016040528015611fa3576020820181803683370190505b5090505b8415611c9857611fb860018361307a565b9150611fc5600a86613113565b611fd090603061302f565b60f81b818381518110611fe557611fe5613169565b60200101906001600160f81b031916908160001a905350612007600a86613047565b9450611fa7565b6001600160a01b03811660009081526001830160205260408120541515611a54565b60006001600160e01b031982166380ac58cd60e01b148061206157506001600160e01b03198216635b5e139f60e01b145b8061060457506301ffc9a760e01b6001600160e01b0319831614610604565b60008181526001830160205260408120546120c757508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610604565b506000610604565b6001600160a01b03821615806120ec57506001600160a01b038316155b6120f557600080fd5b610d0e8383836123d8565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061213582611235565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600183016020526040812054801561225757600061219260018361307a565b85549091506000906121a69060019061307a565b905081811461220b5760008660000182815481106121c6576121c6613169565b90600052602060002001549050808760000184815481106121e9576121e9613169565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061221c5761221c613153565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610604565b6000915050610604565b61226a81612490565b60008181526006602052604090208054612283906130bd565b15905061107e57600081815260066020526040812061107e91612785565b60008260000182815481106122b8576122b8613169565b9060005260206000200154905092915050565b60006001600160a01b0384163b156123cd57604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061230f903390899088908890600401612eab565b602060405180830381600087803b15801561232957600080fd5b505af1925050508015612359575060408051601f3d908101601f1916820190925261235691810190612d4c565b60015b6123b3573d808015612387576040519150601f19603f3d011682016040523d82523d6000602084013e61238c565b606091505b5080516123ab5760405162461bcd60e51b815260040161071190612f26565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611c98565b506001949350505050565b6001600160a01b0383166124335761242e81600980546000838152600a60205260408120829055600182018355919091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0155565b612456565b816001600160a01b0316836001600160a01b031614612456576124568382612537565b6001600160a01b03821661246d57610d0e816125d4565b826001600160a01b0316826001600160a01b031614610d0e57610d0e8282612683565b600061249b82611235565b90506124a9816000846120cf565b6124b4600083612100565b6001600160a01b03811660009081526003602052604081208054600192906124dd90849061307a565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6000600161254484611365565b61254e919061307a565b6000838152600860205260409020549091508082146125a1576001600160a01b03841660009081526007602090815260408083208584528252808320548484528184208190558352600890915290208190555b5060009182526008602090815260408084208490556001600160a01b039094168352600781528383209183525290812055565b6009546000906125e69060019061307a565b6000838152600a60205260408120546009805493945090928490811061260e5761260e613169565b90600052602060002001549050806009838154811061262f5761262f613169565b6000918252602080832090910192909255828152600a9091526040808220849055858252812055600980548061266757612667613153565b6001900381819060005260206000200160009055905550505050565b600061268e83611365565b6001600160a01b039093166000908152600760209081526040808320868452825280832085905593825260089052919091209190915550565b8280546126d3906130bd565b90600052602060002090601f0160209004810192826126f5576000855561273b565b82601f1061270e57805160ff191683800117855561273b565b8280016001018555821561273b579182015b8281111561273b578251825591602001919060010190612720565b506127479291506127bb565b5090565b82805482825590600052602060002090810192821561273b579160200282018281111561273b578251825591602001919060010190612720565b508054612791906130bd565b6000825580601f106127a1575050565b601f01602090049060005260206000209081019061107e91905b5b8082111561274757600081556001016127bc565b600067ffffffffffffffff8311156127ea576127ea61317f565b6127fd601f8401601f1916602001612ffe565b905082815283838301111561281157600080fd5b828260208301376000602084830101529392505050565b80356001600160a01b038116811461283f57600080fd5b919050565b60008083601f84011261285657600080fd5b50813567ffffffffffffffff81111561286e57600080fd5b6020830191508360208260051b850101111561288957600080fd5b9250929050565b600082601f8301126128a157600080fd5b8135602067ffffffffffffffff8211156128bd576128bd61317f565b8160051b6128cc828201612ffe565b8381528281019086840183880185018910156128e757600080fd5b600093505b8584101561290a5780358352600193909301929184019184016128ec565b50979650505050505050565b8035801515811461283f57600080fd5b600082601f83011261293757600080fd5b611a54838335602085016127d0565b60006020828403121561295857600080fd5b611a5482612828565b6000806040838503121561297457600080fd5b61297d83612828565b915061298b60208401612828565b90509250929050565b6000806000606084860312156129a957600080fd5b6129b284612828565b92506129c060208501612828565b9150604084013590509250925092565b6000806000806000608086880312156129e857600080fd5b6129f186612828565b94506129ff60208701612828565b935060408601359250606086013567ffffffffffffffff80821115612a2357600080fd5b818801915088601f830112612a3757600080fd5b813581811115612a4657600080fd5b896020828501011115612a5857600080fd5b9699959850939650602001949392505050565b60008060008060808587031215612a8157600080fd5b612a8a85612828565b9350612a9860208601612828565b925060408501359150606085013567ffffffffffffffff811115612abb57600080fd5b8501601f81018713612acc57600080fd5b612adb878235602084016127d0565b91505092959194509250565b60008060008060608587031215612afd57600080fd5b612b0685612828565b9350602085013567ffffffffffffffff811115612b2257600080fd5b612b2e87828801612844565b9598909750949560400135949350505050565b60008060408385031215612b5457600080fd5b612b5d83612828565b915061298b60208401612916565b60008060008060808587031215612b8157600080fd5b612b8a85612828565b9350612b9860208601612916565b9250604085013567ffffffffffffffff80821115612bb557600080fd5b612bc188838901612890565b93506060870135915080821115612bd757600080fd5b50612adb87828801612890565b60008060408385031215612bf757600080fd5b612c0083612828565b9150602083013567ffffffffffffffff811115612c1c57600080fd5b612c2885828601612926565b9150509250929050565b60008060008060808587031215612c4857600080fd5b612c5185612828565b9350602085013567ffffffffffffffff80821115612c6e57600080fd5b612c7a88838901612926565b94506040870135915080821115612bb557600080fd5b60008060408385031215612ca357600080fd5b612cac83612828565b946020939093013593505050565b600080600060608486031215612ccf57600080fd5b612cd884612828565b95602085013595506040909401359392505050565b60008060208385031215612d0057600080fd5b823567ffffffffffffffff811115612d1757600080fd5b612d2385828601612844565b90969095509350505050565b600060208284031215612d4157600080fd5b8135611a5481613195565b600060208284031215612d5e57600080fd5b8151611a5481613195565b600060208284031215612d7b57600080fd5b5035919050565b60008151808452612d9a816020860160208601613091565b601f01601f19169290920160200192915050565b60008151612dc0818560208601613091565b9290920192915050565b600080865481600182811c915080831680612de657607f831692505b6020808410821415612e0657634e487b7160e01b86526022600452602486fd5b818015612e1a5760018114612e2b57612e58565b60ff19861689528489019650612e58565b60008d81526020902060005b86811015612e505781548b820152908501908301612e37565b505084890196505b505050505050612ea0612e9a612e8a612e84612e74858b612dae565b633f73613d60e01b815260040190565b88612dae565b632672613d60e01b815260040190565b85612dae565b979650505050505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090610cd390830184612d82565b83151581526001600160a01b0383166020820152606060408201819052600090612f0a90830184612d82565b95945050505050565b602081526000611a546020830184612d82565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b604051601f8201601f1916810167ffffffffffffffff811182821017156130275761302761317f565b604052919050565b6000821982111561304257613042613127565b500190565b6000826130565761305661313d565b500490565b600081600019048311821515161561307557613075613127565b500290565b60008282101561308c5761308c613127565b500390565b60005b838110156130ac578181015183820152602001613094565b838111156114bc5750506000910152565b600181811c908216806130d157607f821691505b602082108114156130f257634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561310c5761310c613127565b5060010190565b6000826131225761312261313d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461107e57600080fdfea26469706673582212202489d39b48a7d28587cef74d58881e872f4f411620198b18c1c11c7910cadb0864736f6c63430008070033
Verified Source Code Full Match
Compiler: v0.8.7+commit.e28d00a7
EVM: london
Optimization: Yes (200 runs)
base64.sol 130 lines
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0; /// @title Base64 /// @author Brecht Devos - <[email protected]> /// @notice Provides functions for encoding/decoding base64 library Base64 { string internal constant TABLE_ENCODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; bytes internal constant TABLE_DECODE = hex"0000000000000000000000000000000000000000000000000000000000000000" hex"00000000000000000000003e0000003f3435363738393a3b3c3d000000000000" hex"00000102030405060708090a0b0c0d0e0f101112131415161718190000000000" hex"001a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132330000000000"; function encode(bytes memory data) internal pure returns (string memory) { if (data.length == 0) return ''; // load the table into memory string memory table = TABLE_ENCODE; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((data.length + 2) / 3); // add some extra buffer at the end required for the writing string memory result = new string(encodedLen + 32); assembly { // set the actual output length mstore(result, encodedLen) // prepare the lookup table let tablePtr := add(table, 1) // input ptr let dataPtr := data let endPtr := add(dataPtr, mload(data)) // result ptr, jump over length let resultPtr := add(result, 32) // run over the input, 3 bytes at a time for {} lt(dataPtr, endPtr) {} { // read 3 bytes dataPtr := add(dataPtr, 3) let input := mload(dataPtr) // write 4 characters mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F)))) resultPtr := add(resultPtr, 1) mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F)))) resultPtr := add(resultPtr, 1) mstore8(resultPtr, mload(add(tablePtr, and(shr( 6, input), 0x3F)))) resultPtr := add(resultPtr, 1) mstore8(resultPtr, mload(add(tablePtr, and( input, 0x3F)))) resultPtr := add(resultPtr, 1) } // padding with '=' switch mod(mload(data), 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } } return result; } function decode(string memory _data) internal pure returns (bytes memory) { bytes memory data = bytes(_data); if (data.length == 0) return new bytes(0); require(data.length % 4 == 0, "invalid base64 decoder input"); // load the table into memory bytes memory table = TABLE_DECODE; // every 4 characters represent 3 bytes uint256 decodedLen = (data.length / 4) * 3; // add some extra buffer at the end required for the writing bytes memory result = new bytes(decodedLen + 32); assembly { // padding with '=' let lastBytes := mload(add(data, mload(data))) if eq(and(lastBytes, 0xFF), 0x3d) { decodedLen := sub(decodedLen, 1) if eq(and(lastBytes, 0xFFFF), 0x3d3d) { decodedLen := sub(decodedLen, 1) } } // set the actual output length mstore(result, decodedLen) // prepare the lookup table let tablePtr := add(table, 1) // input ptr let dataPtr := data let endPtr := add(dataPtr, mload(data)) // result ptr, jump over length let resultPtr := add(result, 32) // run over the input, 4 characters at a time for {} lt(dataPtr, endPtr) {} { // read 4 characters dataPtr := add(dataPtr, 4) let input := mload(dataPtr) // write 3 bytes let output := add( add( shl(18, and(mload(add(tablePtr, and(shr(24, input), 0xFF))), 0xFF)), shl(12, and(mload(add(tablePtr, and(shr(16, input), 0xFF))), 0xFF))), add( shl( 6, and(mload(add(tablePtr, and(shr( 8, input), 0xFF))), 0xFF)), and(mload(add(tablePtr, and( input , 0xFF))), 0xFF) ) ) mstore(resultPtr, shl(232, output)) resultPtr := add(resultPtr, 3) } } return result; } }
IShowBiz.sol 6 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
interface IShowBiz {
function mint(address to, uint256 amount) external;
}
DHStaking.sol 235 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.7;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "base64-sol/base64.sol";
import "./IShowBiz.sol";
contract DHStaking is ERC721, ERC721URIStorage, ERC721Enumerable, Ownable {
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
using Strings for uint256;
using Counters for Counters.Counter;
Counters.Counter _tokenIdCounter;
IShowBiz _showBiz = IShowBiz(0x136209a516D1C2660F045e70634c9d95D64325F9);
struct StakedToken {
uint tokenId;
uint stakedAt;
uint endsAt;
uint monthlyRewards;
uint months;
address owner;
}
struct PartnerContract {
bool active;
IERC721 instance;
string baseURI;
uint[] availablePeriods;
uint[] monthlyRewards;
}
mapping(address => mapping(uint => StakedToken)) public localTokenIdToStakedToken;
mapping(address => mapping(address => EnumerableSet.UintSet)) addressToStakedTokensSet;
mapping(address => mapping(uint => uint)) public localTokenIdToClaimedRewards;
mapping(address => mapping(uint => uint)) public tokenIdToLocalTokenId;
mapping(address => PartnerContract) public contracts;
mapping(uint => address) public localTokenIdToContract;
uint public totalClaimedRewards;
EnumerableSet.AddressSet activeContracts;
event Stake(uint tokenId, address contractAddress, uint contractTokenId, address owner, uint endsAt);
event Unstake(uint tokenId, address contractAddress, uint contractTokenId, address owner);
event ClaimTokenRewards(uint tokenId, address owner, uint rewards);
constructor() ERC721("Staked DeadHeads", "sDEAD") { }
function onERC721Received(address operator, address, uint256, bytes calldata) external returns(bytes4) {
require(operator == address(this), "token must be staked over stake method");
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}
function stake(address contractAddress, uint tokenId, uint months) public {
PartnerContract storage _contract = contracts[contractAddress];
require(_contract.active, "token contract is not active");
require(months >= 1, "invalid minimum period");
uint endsAt = block.timestamp + months * 28 days;
uint monthlyRewards = 0;
for (uint i = 0; i < _contract.availablePeriods.length; i++) {
if (_contract.availablePeriods[i] == months) {
monthlyRewards = _contract.monthlyRewards[i];
}
}
require(monthlyRewards != 0, "invalid stake period");
localTokenIdToStakedToken[contractAddress][_tokenIdCounter.current()] = StakedToken({
tokenId: tokenId,
stakedAt: block.timestamp,
endsAt: endsAt,
monthlyRewards: monthlyRewards,
months: months,
owner: msg.sender
});
localTokenIdToClaimedRewards[contractAddress][tokenId] = 0;
_contract.instance.safeTransferFrom(msg.sender, address(this), tokenId);
addressToStakedTokensSet[contractAddress][msg.sender].add(tokenId);
tokenIdToLocalTokenId[contractAddress][tokenId] = _tokenIdCounter.current();
_mint(msg.sender, _tokenIdCounter.current());
localTokenIdToContract[_tokenIdCounter.current()] = contractAddress;
emit Stake(_tokenIdCounter.current(), contractAddress, tokenId, msg.sender, endsAt);
_tokenIdCounter.increment();
}
function stakeBatch(address contractAddress, uint[] calldata tokenIds, uint months) external {
for (uint i = 0; i < tokenIds.length; i++) {
stake(contractAddress, tokenIds[i], months);
}
}
function unclaimedRewards(uint localTokenId) public view returns (uint) {
address tokenContract = localTokenIdToContract[localTokenId];
StakedToken storage stakedToken = localTokenIdToStakedToken[tokenContract][localTokenId];
require(stakedToken.owner != address(0), "cannot query an unstaked token");
uint rewardLimit = (stakedToken.endsAt - stakedToken.stakedAt) / 7 days;
uint rewardsUntilNow = (block.timestamp - stakedToken.stakedAt) / 7 days;
return (rewardsUntilNow > rewardLimit ? rewardLimit : rewardsUntilNow)
* stakedToken.monthlyRewards / 4 - localTokenIdToClaimedRewards[tokenContract][localTokenId];
}
function claimTokenRewards(uint localTokenId) public {
address tokenContract = localTokenIdToContract[localTokenId];
StakedToken storage stakedToken = localTokenIdToStakedToken[tokenContract][localTokenId];
require(stakedToken.owner == msg.sender, "caller did not stake this token");
uint _unclaimedRewards = unclaimedRewards(localTokenId);
if (_unclaimedRewards > 0) {
_showBiz.mint(msg.sender, _unclaimedRewards);
localTokenIdToClaimedRewards[tokenContract][localTokenId] += _unclaimedRewards;
totalClaimedRewards += _unclaimedRewards;
emit ClaimTokenRewards(localTokenId, msg.sender, _unclaimedRewards);
}
}
function claimContractRewards(address contractAddress) public {
EnumerableSet.UintSet storage stakedTokens = addressToStakedTokensSet[contractAddress][msg.sender];
uint totalStakedTokens = stakedTokens.length();
require(totalStakedTokens > 0, "caller does not have any staked token");
for (uint i = 0; i < totalStakedTokens; i++) {
claimTokenRewards(tokenIdToLocalTokenId[contractAddress][stakedTokens.at(i)]);
}
}
function claimRewards() public {
for (uint i = 0; i < activeContracts.length(); i++) {
claimContractRewards(activeContracts.at(i));
}
}
function unstake(uint localTokenId) public {
require(_exists(localTokenId), "query for non existent token");
address tokenContract = localTokenIdToContract[localTokenId];
PartnerContract storage _contract = contracts[tokenContract];
StakedToken storage stakedToken = localTokenIdToStakedToken[tokenContract][localTokenId];
require(stakedToken.owner == msg.sender, "caller not owns this token");
require(block.timestamp > stakedToken.endsAt, "staked period did not finish yet");
claimTokenRewards(localTokenId);
_contract.instance.safeTransferFrom(address(this), msg.sender, stakedToken.tokenId);
addressToStakedTokensSet[tokenContract][msg.sender].remove(stakedToken.tokenId);
_burn(localTokenId);
emit Unstake(localTokenId, tokenContract, stakedToken.tokenId, msg.sender);
delete localTokenIdToStakedToken[tokenContract][localTokenId];
}
function unstakeBatch(uint[] calldata tokenIds) external {
for (uint i = 0; i < tokenIds.length; i++) {
unstake(tokenIds[i]);
}
}
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}
function tokenURI(uint256 localTokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) {
require(_exists(localTokenId), "query for non existent token");
address tokenContract = localTokenIdToContract[localTokenId];
PartnerContract storage _contract = contracts[tokenContract];
StakedToken storage token = localTokenIdToStakedToken[tokenContract][localTokenId];
return string(abi.encodePacked(_contract.baseURI, token.tokenId.toString(), '?sa=', token.stakedAt.toString(), '&ra=', token.endsAt.toString()));
}
function addContract(address contractAddress, string memory baseURI, uint[] memory availablePeriods, uint[] memory monthlyRewards) public onlyOwner {
contracts[contractAddress] = PartnerContract(
true,
IERC721(contractAddress),
baseURI,
availablePeriods,
monthlyRewards
);
activeContracts.add(contractAddress);
}
function updateContract(address contractAddress, bool active, uint[] memory availablePeriods, uint[] memory monthlyRewards) public onlyOwner {
require(activeContracts.contains(contractAddress), "contract not added");
contracts[contractAddress].active = active;
contracts[contractAddress].availablePeriods = availablePeriods;
contracts[contractAddress].monthlyRewards = monthlyRewards;
}
function setBaseURI(address contractAddress, string memory baseURI) public onlyOwner {
contracts[contractAddress].baseURI = baseURI;
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) {
require(to == address(0) || from == address(0));
super._beforeTokenTransfer(from, to, tokenId);
}
function approve(address, uint256) public virtual override {
revert();
}
function setApprovalForAll(address, bool) public virtual override {
revert();
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Address.sol 216 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// 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
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol 23 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Strings.sol 66 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
Ownable.sol 71 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Counters.sol 42 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
ERC721.sol 411 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
IERC721.sol 142 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* 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 Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns 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);
/**
* @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;
}
ERC165.sol 28 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 24 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
EnumerableSet.sol 356 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
IERC721Receiver.sol 26 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
IERC721Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
ERC721Enumerable.sol 162 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
ERC721URIStorage.sol 66 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC721.sol";
/**
* @dev ERC721 token with storage based token URI management.
*/
abstract contract ERC721URIStorage is ERC721 {
using Strings for uint256;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return super.tokenURI(tokenId);
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual override {
super._burn(tokenId);
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
}
IERC721Enumerable.sol 28 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
Read Contract
balanceOf 0x70a08231 → uint256
contracts 0x69dc9ff3 → bool, address, string
getApproved 0x081812fc → address
isApprovedForAll 0xe985e9c5 → bool
localTokenIdToClaimedRewards 0x03865eae → uint256
localTokenIdToContract 0x848e7365 → address
localTokenIdToStakedToken 0xd7d67576 → uint256, uint256, uint256, uint256, uint256, address
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenByIndex 0x4f6ccce7 → uint256
tokenIdToLocalTokenId 0xb6d238d8 → uint256
tokenOfOwnerByIndex 0x2f745c59 → uint256
tokenURI 0xc87b56dd → string
totalClaimedRewards 0xd578ceab → uint256
totalSupply 0x18160ddd → uint256
unclaimedRewards 0x1772188e → uint256
Write Contract 18 functions
These functions modify contract state and require a wallet transaction to execute.
addContract 0x5e9196ad
address contractAddress
string baseURI
uint256[] availablePeriods
uint256[] monthlyRewards
approve 0x095ea7b3
address
uint256
claimContractRewards 0xcf8088b9
address contractAddress
claimRewards 0x372500ab
No parameters
claimTokenRewards 0xcf2c86d7
uint256 localTokenId
onERC721Received 0x150b7a02
address operator
address
uint256
bytes
returns: bytes4
renounceOwnership 0x715018a6
No parameters
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setApprovalForAll 0xa22cb465
address
bool
setBaseURI 0x88433651
address contractAddress
string baseURI
stake 0x0c51b88f
address contractAddress
uint256 tokenId
uint256 months
stakeBatch 0xf301e3d0
address contractAddress
uint256[] tokenIds
uint256 months
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
unstake 0x2e17de78
uint256 localTokenId
unstakeBatch 0xe64a21f3
uint256[] tokenIds
updateContract 0xfd712bbe
address contractAddress
bool active
uint256[] availablePeriods
uint256[] monthlyRewards
Recent Transactions
No transactions found for this address