Address Contract Verified
Address
0x89327a03bd7BAaCDf9c60ffeB60A0eD70c26d14C
Balance
0 ETH
Nonce
1
Code Size
19942 bytes
Creator
0xa623977E...773e at tx 0xc217cc94...227df9
Indexed Transactions
0
Contract Bytecode
19942 bytes
0x6080604052600436106103be575f3560e01c806361c6d720116101f4578063a22cb46511610113578063d1c2babb116100a8578063ea4643b711610078578063ea4643b714610b0a578063ef2f0ddd14610b24578063f2fde38b14610b43578063fd37aaf514610b62578063feb309ad14610b81575f5ffd5b8063d1c2babb14610a9a578063d538762814610ab9578063ddff5b1c14610ad8578063e985e9c514610aeb575f5ffd5b8063b8be499b116100e3578063b8be499b14610a04578063c04a283614610a1d578063c87b56dd14610a66578063c976dcfa14610a85575f5ffd5b8063a22cb46514610979578063ab39f08a14610998578063aeefe31f146109c6578063b88d4fde146109e5575f5ffd5b8063865f8cae116101895780639843eae3116101595780639843eae31461090c57806399ee1998146109255780639ae7e12914610951578063a0712d6814610966575f5ffd5b8063865f8cae1461089d5780638688160f146108bc5780638da5cb5b146108db57806395d89b41146108f8575f5ffd5b8063715018a6116101c4578063715018a6146108375780637e36b7ee1461084b5780637ecc2b561461086a5780638295784d1461087e575f5ffd5b806361c6d7201461079d5780636352211e146107c857806366469a3a146107e757806370a0823114610818575f5ffd5b8063330c4ce0116102e057806342842e0e11610275578063514e721311610245578063514e72131461072c57806353139a981461074b57806355f804b31461076a5780635b88349d14610789575f5ffd5b806342842e0e146106b55780634bfeb203146106d45780634f0c5400146106f35780634f6ccce71461070d575f5ffd5b80633ad05024116102b05780633ad050241461065a5780633ccfd60b1461066e5780633e75475f146106825780634224654214610696575f5ffd5b8063330c4ce0146105f35780633719e3b01461060857806339895ee51461061c5780633a61785a1461063b575f5ffd5b80630fcf2e751161035657806318160ddd1161032657806318160ddd1461058c57806323b872dd146105a05780632f745c59146105bf57806332cb6b0c146105de575f5ffd5b80630fcf2e75146105055780631015207f146105235780631363e2961461054257806314ed66be1461056d575f5ffd5b8063081812fc11610391578063081812fc1461046f578063095ea7b3146104a6578063098ecb82146104c75780630a578c9b146104e6575f5ffd5b806301ffc9a7146103c257806304737a01146103f657806305c58df21461041557806306fdde031461044e575b5f5ffd5b3480156103cd575f5ffd5b506103e16103dc366004614138565b610b95565b60405190151581526020015b60405180910390f35b348015610401575f5ffd5b50600d546103e19062010000900460ff1681565b348015610420575f5ffd5b5061044061042f366004614153565b60176020525f908152604090205481565b6040519081526020016103ed565b348015610459575f5ffd5b50610462610ba5565b6040516103ed9190614198565b34801561047a575f5ffd5b5061048e610489366004614153565b610c34565b6040516001600160a01b0390911681526020016103ed565b3480156104b1575f5ffd5b506104c56104c03660046141c5565b610c5b565b005b3480156104d2575f5ffd5b506104c56104e13660046141ed565b610c6a565b3480156104f1575f5ffd5b506104c5610500366004614153565b610c94565b348015610510575f5ffd5b50600d546103e190610100900460ff1681565b34801561052e575f5ffd5b506104c561053d366004614215565b610ef8565b34801561054d575f5ffd5b5061044061055c366004614153565b601a6020525f908152604090205481565b348015610578575f5ffd5b506104c5610587366004614283565b610f75565b348015610597575f5ffd5b50600854610440565b3480156105ab575f5ffd5b506104c56105ba3660046142ca565b611165565b3480156105ca575f5ffd5b506104406105d93660046141c5565b6111ee565b3480156105e9575f5ffd5b50610440614e2081565b3480156105fe575f5ffd5b5061044060115481565b348015610613575f5ffd5b506104c5611251565b348015610627575f5ffd5b506104c56106363660046143ab565b6112bd565b348015610646575f5ffd5b506104c56106553660046143f6565b61143b565b348015610665575f5ffd5b50610440601481565b348015610679575f5ffd5b506104c561161c565b34801561068d575f5ffd5b506104c5611666565b3480156106a1575f5ffd5b506104c56106b0366004614416565b6116b6565b3480156106c0575f5ffd5b506104c56106cf3660046142ca565b6117b2565b3480156106df575f5ffd5b506104c56106ee366004614486565b6117cc565b3480156106fe575f5ffd5b506104406611c37937e0800081565b348015610718575f5ffd5b50610440610727366004614153565b6118cb565b348015610737575f5ffd5b506104c56107463660046144c4565b611920565b348015610756575f5ffd5b50610440610765366004614153565b611c33565b348015610775575f5ffd5b506104c5610784366004614549565b611cc2565b348015610794575f5ffd5b506104c5611d11565b3480156107a8575f5ffd5b506104406107b7366004614153565b5f908152601a602052604090205490565b3480156107d3575f5ffd5b5061048e6107e2366004614153565b611e9e565b3480156107f2575f5ffd5b50610806610801366004614153565b611ea8565b6040516103ed9695949392919061457a565b348015610823575f5ffd5b506104406108323660046141ed565b611fef565b348015610842575f5ffd5b506104c5612034565b348015610856575f5ffd5b506104c56108653660046145c2565b612045565b348015610875575f5ffd5b50610440612385565b348015610889575f5ffd5b506104c5610898366004614615565b6123ad565b3480156108a8575f5ffd5b50601c5461048e906001600160a01b031681565b3480156108c7575f5ffd5b506104c56108d63660046143f6565b61245d565b3480156108e6575f5ffd5b50600a546001600160a01b031661048e565b348015610903575f5ffd5b50610462612618565b348015610917575f5ffd5b50600d546103e19060ff1681565b348015610930575f5ffd5b5061094461093f366004614153565b612627565b6040516103ed9190614664565b34801561095c575f5ffd5b5061044060135481565b6104c5610974366004614153565b6126ba565b348015610984575f5ffd5b506104c56109933660046146a6565b6128f4565b3480156109a3575f5ffd5b506103e16109b23660046141ed565b600c6020525f908152604090205460ff1681565b3480156109d1575f5ffd5b506104406109e03660046141ed565b6128ff565b3480156109f0575f5ffd5b506104c56109ff3660046146ce565b61294a565b348015610a0f575f5ffd5b50600f546103e19060ff1681565b348015610a28575f5ffd5b50610a54610a373660046141ed565b6001600160a01b03165f9081526014602052604090205460ff1690565b60405160ff90911681526020016103ed565b348015610a71575f5ffd5b50610462610a80366004614153565b612961565b348015610a90575f5ffd5b5061044060125481565b348015610aa5575f5ffd5b506104c5610ab43660046143f6565b6129c6565b348015610ac4575f5ffd5b506104c5610ad33660046144c4565b612d2f565b6104c5610ae6366004614744565b613196565b348015610af6575f5ffd5b506103e1610b0536600461475d565b6133b8565b348015610b15575f5ffd5b50610440660aa87bee53800081565b348015610b2f575f5ffd5b506104c5610b3e366004614153565b6133e5565b348015610b4e575f5ffd5b506104c5610b5d3660046141ed565b613471565b348015610b6d575f5ffd5b50610462610b7c366004614153565b6134ae565b348015610b8c575f5ffd5b506104c561354b565b5f610b9f8261359b565b92915050565b60605f8054610bb390614785565b80601f0160208091040260200160405190810160405280929190818152602001828054610bdf90614785565b8015610c2a5780601f10610c0157610100808354040283529160200191610c2a565b820191905f5260205f20905b815481529060010190602001808311610c0d57829003601f168201915b5050505050905090565b5f610c3e826135bf565b505f828152600460205260409020546001600160a01b0316610b9f565b610c668282336135f7565b5050565b610c72613604565b601c80546001600160a01b0319166001600160a01b0392909216919091179055565b33610c9e82611e9e565b6001600160a01b031614610ccd5760405162461bcd60e51b8152600401610cc4906147bd565b60405180910390fd5b5f818152601a602052604081205490819003610d245760405162461bcd60e51b81526020600482015260166024820152752a37b5b2b71034b9903737ba1034b710309031b630b760511b6044820152606401610cc4565b5f818152601960205260408120905b6002820154811015610de15783826002018281548110610d5557610d556147ed565b905f5260205f20015403610dd957600282018054610d7590600190614815565b81548110610d8557610d856147ed565b905f5260205f200154826002018281548110610da357610da36147ed565b5f9182526020909120015560028201805480610dc157610dc1614828565b600190038181905f5260205f20015f90559055610de1565b600101610d33565b505f838152601a602052604080822082905551849184917fce1117b21c9ba17420aa9ab6272b2d98144540fe7f0f72a148858de68302d8bb9190a382816001015403610ef3575f5b6002820154811015610e71575f601a5f846002018481548110610e4e57610e4e6147ed565b5f9182526020808320909101548352820192909252604001902055600101610e29565b505f82815260196020526040812090610e8a8282614074565b600182015f9055600282015f610ea091906140ab565b60038201805460ff19169055610eb9600483015f614074565b505f60058201819055600690910181905560405183917f4c242e6d45720b045c82a63ad3c1f23fc0eb90e55e7f5c2398c2071aae498cba91a25b505050565b610f00613604565b600d805461ff0019166101008315158102919091179182905560ff91041615610f315760128290555f601355610f36565b5f6012555b6040805183815282151560208201527f6302b78058afe801a7e5f830fa64cac6e9080b3d48af2e0e1089c67ee403e40491015b60405180910390a15050565b33610f7f84611e9e565b6001600160a01b031614610fd55760405162461bcd60e51b815260206004820152601760248201527f596f75206d757374206f776e207468697320746f6b656e0000000000000000006044820152606401610cc4565b5f83815260176020526040902054600211156110455760405162461bcd60e51b815260206004820152602960248201527f4f6e6c79206c6576656c20322b20746f6b656e732063616e20736574206120736044820152686f756c70687261736560b81b6064820152608401610cc4565b601e60115410156110b05760405162461bcd60e51b815260206004820152602f60248201527f536f756c706872617365206973206c6f636b656420756e74696c20333020746f60448201526e1ad95b9cc8185c9948189d5c9b9959608a1b6064820152608401610cc4565b606481111561110d5760405162461bcd60e51b8152602060048201526024808201527f50687261736520746f6f206c6f6e6720286d61782031303020636861726163746044820152636572732960e01b6064820152608401610cc4565b5f838152601860205260409020611125828483614880565b50827f17b8c0bbdf876dc646941a587baf1efbfa60d2ee47a2c9c133938acffbe511da8383604051611158929190614961565b60405180910390a2505050565b6001600160a01b03821661118e57604051633250574960e11b81525f6004820152602401610cc4565b5f61119a838333613631565b9050836001600160a01b0316816001600160a01b0316146111e8576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610cc4565b50505050565b5f6111f883611fef565b82106112295760405163295f44f760e21b81526001600160a01b038416600482015260248101839052604401610cc4565b506001600160a01b03919091165f908152600660209081526040808320938352929052205490565b611259613604565b600d805460ff62010000808304821615810262ff00001990931692909217928390556040517fc98eda9f99bb20fb05980ede400112f7c904d3dc00e9a25b801f12597cf0a84c936112b39390049091161515815260200190565b60405180910390a1565b336112c784611e9e565b6001600160a01b03161461130d5760405162461bcd60e51b815260206004820152600d60248201526c2737ba103a34329037bbb732b960991b6044820152606401610cc4565b8161131784611c33565b10156113595760405162461bcd60e51b81526020600482015260116024820152704e6f7420656e6f75676820706f696e747360781b6044820152606401610cc4565b5f61136384611c33565b905061136f8382614815565b5f8581526016602090815260408083209390935560159052818120429055815160018082528184019093529091816020015b604080518082019091525f80825260208201528152602001906001900390816113a1579050509050604051806040016040528086815260200185815250815f815181106113f0576113f06147ed565b60200260200101819052507fb9e9fa6ba77e65f7c991c80b6b33b54d2647daa9482806437bf43c7c32ca756a818460405161142c929190614974565b60405180910390a15050505050565b3361144583611e9e565b6001600160a01b03161461146b5760405162461bcd60e51b8152600401610cc4906147bd565b5f8181526019602052604090206003015460ff1661149b5760405162461bcd60e51b8152600401610cc4906149d7565b5f828152601a6020526040902054156114f05760405162461bcd60e51b81526020600482015260176024820152762a37b5b2b71030b63932b0b23c9034b710309031b630b760491b6044820152606401610cc4565b5f8181526019602090815260408083206006015485845260179092529091205410156115685760405162461bcd60e51b815260206004820152602160248201527f546f6b656e206c6576656c20746f6f206c6f7720666f72207468697320636c616044820152603760f91b6064820152608401610cc4565b5f8181526019602052604090206005810154600290910154106115bc5760405162461bcd60e51b815260206004820152600c60248201526b10db185b881a5cc8199d5b1b60a21b6044820152606401610cc4565b5f818152601960209081526040808320600201805460018101825590845282842001859055848352601a90915280822083905551839183917fd9035e4efd560b357b0e7f589bd437e658aea2c7d8aa9f6203a97b09c696c02e9190a35050565b611624613604565b61162c613645565b6040514790339082156108fc029083905f818181858888f19350505050158015611658573d5f5f3e3d5ffd5b50506116646001600b55565b565b61166e613604565b600d805460ff8082161560ff1990921682179092556040519116151581527fd024a173b8e0dea475abe2b57a44724763789dce73058107136f0836c47d7e92906020016112b3565b601c546001600160a01b031633146117055760405162461bcd60e51b8152602060048201526012602482015271139bdd08185dd85c990818dbdb9d1c9858dd60721b6044820152606401610cc4565b826001600160a01b031661171883611e9e565b6001600160a01b03161461175e5760405162461bcd60e51b815260206004820152600d60248201526c4d757374206f776e20466f787960981b6044820152606401610cc4565b5f828152601660205260408120805483929061177b908490614a04565b909155505060405181815282907f6d5a14e5058ca79fb1bf12ea7338abf5f1d511695d355ee90dcc8162a73e39e690602001611158565b610ef383838360405180602001604052805f81525061294a565b6117d4613604565b806118195760405162461bcd60e51b81526020600482015260156024820152744261642061697264726f70206c6973742073697a6560581b6044820152606401610cc4565b5f5b81811015611899575f838383818110611836576118366147ed565b905060200201602081019061184b91906141ed565b6001600160a01b0381165f908152600c602052604090205490915060ff16611890576001600160a01b0381165f908152600c60205260409020805460ff191660011790555b5060010161181b565b507f3ffbd63c2d828ce51ba33f874d3c27e8b7100f178820db64cc97d7e511dd41688282604051610f69929190614a5d565b5f6118d560085490565b82106118fd5760405163295f44f760e21b81525f600482015260248101839052604401610cc4565b60088281548110611910576119106147ed565b905f5260205f2001549050919050565b5f8781526019602052604090206003015460ff166119505760405162461bcd60e51b8152600401610cc4906149d7565b5f878152601960205260409020600101543361196b82611e9e565b6001600160a01b0316146119d25760405162461bcd60e51b815260206004820152602860248201527f4f6e6c792074686520636c616e206c65616465722063616e207570646174652060448201526773657474696e677360c01b6064820152608401610cc4565b8515611a135760208611156119f95760405162461bcd60e51b8152600401610cc490614a70565b5f888152601960205260409020611a11878983614880565b505b8315611a8857610100841115611a6b5760405162461bcd60e51b815260206004820152601e60248201527f4465736372697074696f6e20746f6f206c6f6e6720286d6178203235362900006044820152606401610cc4565b5f888152601960205260409020600401611a86858783614880565b505b8215611af45760018310158015611aa0575060038311155b611ae05760405162461bcd60e51b8152602060048201526011602482015270125b9d985b1a59081b5a5b881b195d995b607a1b6044820152606401610cc4565b5f8881526019602052604090206006018390555b8115611bd1575f88815260196020526040902060020154821015611b6c5760405162461bcd60e51b815260206004820152602960248201527f43616e6e6f7420736574206d61784d656d626572732062656c6f772063757272604482015268195b9d0818dbdd5b9d60ba1b6064820152608401610cc4565b6064821115611bbd5760405162461bcd60e51b815260206004820152601a60248201527f4d6178206d656d62657273206c696d69742065786365656465640000000000006044820152606401610cc4565b5f8881526019602052604090206005018290555b5f88815260196020526040908190206006810154600582015492518b937fa1d3c5125c22c3e6a0222ff1bb7ffd228133c6aac374e10d5c0cb18d150d07cb93611c21939092600484019290614b30565b60405180910390a25050505050505050565b5f611c3d826135bf565b505f82815260176020526040812054906002829003611c5e57506001611c6a565b81600303611c6a575060025b5f8481526015602052604081205482906201518090611c899042614815565b611c939190614b68565b611c9d9190614b87565b5f86815260166020526040902054909150611cb9908290614a04565b95945050505050565b611cca613604565b600e611cd68282614b9e565b507f6741b2fc379fad678116fe3d4d4b9a1a184ab53ba36b86ad0fa66340b1ab41ad81604051611d069190614198565b60405180910390a150565b611d19613645565b600d5460ff16611d635760405162461bcd60e51b815260206004820152601560248201527441697264726f70206973206e6f742061637469766560581b6044820152606401610cc4565b335f908152600c602052604090205460ff16611dc15760405162461bcd60e51b815260206004820152601860248201527f4e6f7420656c696769626c6520666f722061697264726f7000000000000000006044820152606401610cc4565b611dcb600161369e565b611e0d5760405162461bcd60e51b815260206004820152601360248201527213585e081cdd5c1c1b1e48195e18d959591959606a1b6044820152606401610cc4565b335f908152600c60205260408120805460ff19169055601054600854611e339190614a04565b5f8181526017602090815260408083206001905560168252808320839055601590915290204290559050611e6733826136cb565b604051819033907f650e45f04ef8a0c267b2f78d983913f69ae3a353b2b32de5429307522be0ab55905f90a3506116646001600b55565b5f610b9f826135bf565b60196020525f9081526040902080548190611ec290614785565b80601f0160208091040260200160405190810160405280929190818152602001828054611eee90614785565b8015611f395780601f10611f1057610100808354040283529160200191611f39565b820191905f5260205f20905b815481529060010190602001808311611f1c57829003601f168201915b50505050600183015460038401546004850180549495929460ff909216935090611f6290614785565b80601f0160208091040260200160405190810160405280929190818152602001828054611f8e90614785565b8015611fd95780601f10611fb057610100808354040283529160200191611fd9565b820191905f5260205f20905b815481529060010190602001808311611fbc57829003601f168201915b5050505050908060050154908060060154905086565b5f6001600160a01b038216612019576040516322718ad960e21b81525f6004820152602401610cc4565b506001600160a01b03165f9081526003602052604090205490565b61203c613604565b6116645f6136e4565b5f61204f33611fef565b90505f81116120a05760405162461bcd60e51b815260206004820152601d60248201527f596f7520646f6e2774206f776e20616e7920466f787920746f6b656e730000006044820152606401610cc4565b5f6120aa336128ff565b9050838110156120fc5760405162461bcd60e51b815260206004820152601760248201527f4e6f7420656e6f75676820746f74616c20706f696e74730000000000000000006044820152606401610cc4565b835f836001600160401b0381111561211657612116614304565b60405190808252806020026020018201604052801561215a57816020015b604080518082019091525f80825260208201528152602001906001900390816121345790505b5090505f805b858110801561216e57505f84115b15612236575f61217e33836111ee565b90505f61218a82611c33565b9050805f0361219a575050612224565b5f868210156121a957816121ab565b865b90506121b78183614815565b5f8481526016602090815260408083209390935560158152908290204290558151808301909252848252810182905286518790879081106121fa576121fa6147ed565b6020026020010181905250848061221090614c58565b955061221e90508188614815565b96505050505b8061222e81614c58565b915050612160565b5082156122985760405162461bcd60e51b815260206004820152602a60248201527f496e7465726e616c206572726f723a204e6f7420656e6f75676820706f696e746044820152691cc81919591d58dd195960b21b6064820152608401610cc4565b5f816001600160401b038111156122b1576122b1614304565b6040519080825280602002602001820160405280156122f557816020015b604080518082019091525f80825260208201528152602001906001900390816122cf5790505b5090505f5b8281101561234157838181518110612314576123146147ed565b602002602001015182828151811061232e5761232e6147ed565b60209081029190910101526001016122fa565b507fb9e9fa6ba77e65f7c991c80b6b33b54d2647daa9482806437bf43c7c32ca756a8188604051612373929190614974565b60405180910390a15050505050505050565b5f61238f60085490565b60115461239e90614e20614815565b6123a89190614815565b905090565b6123b5613604565b5f5b8281101561241c578160145f8686858181106123d5576123d56147ed565b90506020020160208101906123ea91906141ed565b6001600160a01b0316815260208101919091526040015f20805460ff191660ff929092169190911790556001016123b7565b507f91af198cc59a19d7364c9d7473ea7bf155518f41613a8b2bb612051dbc9ad9cb83838360405161245093929190614c70565b60405180910390a1505050565b5f8281526019602052604090206003015460ff1661248d5760405162461bcd60e51b8152600401610cc4906149d7565b5f82815260196020526040902060010154336124a882611e9e565b6001600160a01b0316146125135760405162461bcd60e51b815260206004820152602c60248201527f4f6e6c792074686520636c616e206c65616465722063616e207472616e73666560448201526b072206c6561646572736869760a41b6064820152608401610cc4565b5f828152601a6020526040902054831461256f5760405162461bcd60e51b815260206004820181905260248201527f4e6577206c6561646572206d757374206265206120636c616e206d656d6265726044820152606401610cc4565b5f828152601760205260409020546003146125cc5760405162461bcd60e51b815260206004820152601a60248201527f4e6577206c6561646572206d757374206265206c6576656c20330000000000006044820152606401610cc4565b5f83815260196020908152604091829020600101849055815183815290810184905284917f55086b0d01b7c3fed9da6058a2809beb8bb0847e132db58c11a9e7ecc5bbb7049101611158565b606060018054610bb390614785565b5f8181526019602052604090206003015460609060ff1661265a5760405162461bcd60e51b8152600401610cc4906149d7565b5f82815260196020908152604091829020600201805483518184028101840190945280845290918301828280156126ae57602002820191905f5260205f20905b81548152602001906001019080831161269a575b50505050509050919050565b5f6126cc826611c37937e08000614b87565b600d54909150610100900460ff166127265760405162461bcd60e51b815260206004820181905260248201527f53616c65206d7573742062652061637469766520746f206d696e7420466f78796044820152606401610cc4565b60148211156127925760405162461bcd60e51b815260206004820152603260248201527f43616e206f6e6c79206d696e742061206c696d69746564206e756d626572206f6044820152716620746f6b656e7320617420612074696d6560701b6064820152608401610cc4565b61279b8261369e565b6127b75760405162461bcd60e51b8152600401610cc490614c96565b348111156128075760405162461bcd60e51b815260206004820152601f60248201527f45746865722076616c75652073656e74206973206e6f7420636f7272656374006044820152606401610cc4565b6012541561287a57601254826013546128209190614a04565b111561287a5760405162461bcd60e51b815260206004820152602360248201527f4d696e74696e67206c696d697420666f7220746869732073616c6520726561636044820152621a195960ea1b6064820152608401610cc4565b5f5b828110156128d9575f60105461289160085490565b61289b9190614a04565b5f8181526017602090815260408083206001905560168252808320603290556015909152902042905590506128d033826136cb565b5060010161287c565b508160135f8282546128eb9190614a04565b90915550505050565b610c66338383613735565b5f5f61290a83611fef565b90505f805b82811015612942575f61292286836111ee565b905061292d81611c33565b6129379084614a04565b92505060010161290f565b509392505050565b612955848484611165565b6111e8848484846137d3565b606061296c826135bf565b505f6129766138f9565b90505f8151116129945760405180602001604052805f8152506129bf565b8061299e84613908565b6040516020016129af929190614ce2565b6040516020818303038152906040525b9392505050565b336129d083611e9e565b6001600160a01b031614612a1e5760405162461bcd60e51b8152602060048201526015602482015274596f75206d757374206f776e20746f6b656e49643160581b6044820152606401610cc4565b33612a2882611e9e565b6001600160a01b031614612a765760405162461bcd60e51b81526020600482015260156024820152742cb7ba9036bab9ba1037bbb7103a37b5b2b724b21960591b6044820152606401610cc4565b808203612ac55760405162461bcd60e51b815260206004820152601b60248201527f43616e6e6f74206d65726765207468652073616d6520746f6b656e00000000006044820152606401610cc4565b5f8281526017602052604090205460011480612aee57505f818152601760205260409020546001145b612b515760405162461bcd60e51b815260206004820152602e60248201527f4174206c65617374206f6e65206f66207468652074776f20746f6b656e73206d60448201526d757374206265206c6576656c203160901b6064820152608401610cc4565b5f828152601760205260409020546003118015612b7b57505f818152601760205260409020546003115b612bc75760405162461bcd60e51b815260206004820181905260248201527f41206c6576656c203320746f6b656e2063616e6e6f74206265206d65726765646044820152606401610cc4565b5f612bd183611c33565b90505f612bdd83611c33565b5f848152601760205260408082205487835290822054929350909111612c10575f84815260176020526040902054612c1f565b5f858152601760205260409020545b905080612c2b81614c58565b915050612c3785613997565b612c4084613997565b600260105f828254612c529190614a04565b92505081905550600160115f828254612c6b9190614a04565b90915550506010545f90612c7e60085490565b612c889190614a04565b5f81815260176020526040812084905590915060028314612caa5760fa612cad565b60645b60ff16905080612cbd8587614a04565b612cc79190614a04565b5f83815260166020908152604080832093909355601581529082902042905590518381528791899133917fb3ce851d16b3bbec3774d5631a3893dfa2a80e067cfad265dd594402ac3d6096910160405180910390a4612d2633836136cb565b50505050505050565b60646011541015612d975760405162461bcd60e51b815260206004820152602c60248201527f436c616e7320617265206c6f636b656420756e74696c2031303020746f6b656e60448201526b1cc8185c9948189d5c9b995960a21b6064820152608401610cc4565b33612da188611e9e565b6001600160a01b031614612dc75760405162461bcd60e51b8152600401610cc4906147bd565b5f87815260176020526040902054600314612e305760405162461bcd60e51b8152602060048201526024808201527f4f6e6c79206c6576656c203320746f6b656e732063616e2063726561746520636044820152636c616e7360e01b6064820152608401610cc4565b5f878152601a602052604090205415612e855760405162461bcd60e51b81526020600482015260176024820152762a37b5b2b71030b63932b0b23c9034b710309031b630b760491b6044820152606401610cc4565b60018210158015612e97575060038211155b612ed75760405162461bcd60e51b8152602060048201526011602482015270125b9d985b1a59081b5a5b881b195d995b607a1b6044820152606401610cc4565b8415801590612ee7575060208511155b612f035760405162461bcd60e51b8152600401610cc490614a70565b610100831115612f555760405162461bcd60e51b815260206004820152601e60248201527f4465736372697074696f6e20746f6f206c6f6e6720286d6178203235362900006044820152606401610cc4565b60018110158015612f67575060648111155b612faa5760405162461bcd60e51b8152602060048201526014602482015273125b9d985b1a59081b595b58995c881b1a5b5a5d60621b6044820152606401610cc4565b612fdb87601e6040518060400160405280600d81526020016c21b630b71031b932b0ba34b7b760991b8152506112bd565b601b80545f9182612feb83614c58565b90915550604080516101006020601f8b01819004028201810190925260e081018981529293509182918a908a90819085018382808284375f92018290525093855250505060208083018c905260408051928352828201815280840192909252600160608401528151601f890182900482028101820190925287825260809092019188908890819084018382808284375f920182905250938552505050602080830186905260409283018790528482526019905220815181906130ad9082614b9e565b506020828101516001830155604083015180516130d092600285019201906140c6565b50606082015160038201805460ff1916911515919091179055608082015160048201906130fd9082614b9e565b5060a0820151600582015560c0909101516006909101555f8181526019602090815260408083206002018054600181018255908452828420018b90558a8352601a9091529081902082905551889082907fe31f10dbc8c9050baa69fd523932ee340126bc567ca3e776bc9021a54bedb58a90613184908b908b908b908b908b908b90614d0c565b60405180910390a35050505050505050565b600d545f9062010000900460ff16156131c4576131bd60ff8316660aa87bee538000614b87565b90506131db565b6131d860ff83166611c37937e08000614b87565b90505b600f5460ff1661322d5760405162461bcd60e51b815260206004820152601860248201527f416c6c6f77206c697374206973206e6f742061637469766500000000000000006044820152606401610cc4565b335f9081526014602052604090205460ff908116908316111561329d5760405162461bcd60e51b815260206004820152602260248201527f4578636565646564206d617820617661696c61626c6520746f20707572636861604482015261736560f01b6064820152608401610cc4565b6132a98260ff1661369e565b6132c55760405162461bcd60e51b8152600401610cc490614c96565b348111156133155760405162461bcd60e51b815260206004820152601f60248201527f45746865722076616c75652073656e74206973206e6f7420636f7272656374006044820152606401610cc4565b5f5b8260ff16811015610ef3575f60105461332f60085490565b6133399190614a04565b335f908152601460205260408120805492935060ff909216919061335c83614d48565b91906101000a81548160ff021916908360ff160217905550506133a58160325f918252601760209081526040808420600190556016825280842092909255601590529020429055565b6133af33826136cb565b50600101613317565b6001600160a01b039182165f90815260056020908152604080832093909416825291909152205460ff1690565b6133ed613604565b6133f68161369e565b6134125760405162461bcd60e51b8152600401610cc490614c96565b5f5b81811015610c66575f60105461342960085490565b6134339190614a04565b5f81815260176020908152604080832060019055601682528083206032905560159091529020429055905061346833826136cb565b50600101613414565b613479613604565b6001600160a01b0381166134a257604051631e4fbdf760e01b81525f6004820152602401610cc4565b6134ab816136e4565b50565b60606134b9826135bf565b505f82815260186020526040902080546134d290614785565b80601f01602080910402602001604051908101604052809291908181526020018280546134fe90614785565b80156126ae5780601f10613520576101008083540402835291602001916126ae565b820191905f5260205f20905b81548152906001019060200180831161352c5750939695505050505050565b613553613604565b600f805460ff8082161560ff1990921682179092556040519116151581527fbd536af1bad8b98419adb99846296e4e615e6f1643b95f1eecf263313a141407906020016112b3565b5f6001600160e01b0319821663780e9d6360e01b1480610b9f5750610b9f826139cf565b5f818152600260205260408120546001600160a01b031680610b9f57604051637e27328960e01b815260048101849052602401610cc4565b610ef38383836001613a1e565b600a546001600160a01b031633146116645760405163118cdaa760e01b8152336004820152602401610cc4565b5f61363d848484613b22565b949350505050565b6002600b54036136975760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610cc4565b6002600b55565b5f601154614e206136af9190614815565b826136b960085490565b6136c39190614a04565b111592915050565b610c66828260405180602001604052805f815250613bed565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b6001600160a01b03821661376757604051630b61174360e31b81526001600160a01b0383166004820152602401610cc4565b6001600160a01b038381165f81815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b0383163b156111e857604051630a85bd0160e11b81526001600160a01b0384169063150b7a0290613815903390889087908790600401614d63565b6020604051808303815f875af192505050801561384f575060408051601f3d908101601f1916820190925261384c91810190614d95565b60015b6138b6573d80801561387c576040519150601f19603f3d011682016040523d82523d5f602084013e613881565b606091505b5080515f036138ae57604051633250574960e11b81526001600160a01b0385166004820152602401610cc4565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b146138f257604051633250574960e11b81526001600160a01b0385166004820152602401610cc4565b5050505050565b6060600e8054610bb390614785565b60605f61391483613c03565b60010190505f816001600160401b0381111561393257613932614304565b6040519080825280601f01601f19166020018201604052801561395c576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461396657509392505050565b5f6139a35f835f613631565b90506001600160a01b038116610c6657604051637e27328960e01b815260048101839052602401610cc4565b5f6001600160e01b031982166380ac58cd60e01b14806139ff57506001600160e01b03198216635b5e139f60e01b145b80610b9f57506301ffc9a760e01b6001600160e01b0319831614610b9f565b8080613a3257506001600160a01b03821615155b15613af3575f613a41846135bf565b90506001600160a01b03831615801590613a6d5750826001600160a01b0316816001600160a01b031614155b8015613a805750613a7e81846133b8565b155b15613aa95760405163a9fbf51f60e01b81526001600160a01b0384166004820152602401610cc4565b8115613af15783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260046020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b5f5f613b2f858585613cda565b90506001600160a01b038116613b8b57613b8684600880545f838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b613bae565b846001600160a01b0316816001600160a01b031614613bae57613bae8185613dcc565b6001600160a01b038516613bca57613bc584613e59565b61363d565b846001600160a01b0316816001600160a01b03161461363d5761363d8585613f00565b613bf78383613f4e565b610ef35f8484846137d3565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310613c415772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310613c6d576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310613c8b57662386f26fc10000830492506010015b6305f5e1008310613ca3576305f5e100830492506008015b6127108310613cb757612710830492506004015b60648310613cc9576064830492506002015b600a8310610b9f5760010192915050565b5f828152600260205260408120546001600160a01b0390811690831615613d0657613d06818486613faf565b6001600160a01b03811615613d4057613d215f855f5f613a1e565b6001600160a01b0381165f90815260036020526040902080545f190190555b6001600160a01b03851615613d6e576001600160a01b0385165f908152600360205260409020805460010190555b5f8481526002602052604080822080546001600160a01b0319166001600160a01b0389811691821790925591518793918516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4949350505050565b5f613dd683611fef565b5f83815260076020526040902054909150808214613e27576001600160a01b0384165f9081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b505f9182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b6008545f90613e6a90600190614815565b5f8381526009602052604081205460088054939450909284908110613e9157613e916147ed565b905f5260205f20015490508060088381548110613eb057613eb06147ed565b5f918252602080832090910192909255828152600990915260408082208490558582528120556008805480613ee757613ee7614828565b600190038181905f5260205f20015f9055905550505050565b5f6001613f0c84611fef565b613f169190614815565b6001600160a01b039093165f908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b038216613f7757604051633250574960e11b81525f6004820152602401610cc4565b5f613f8383835f613631565b90506001600160a01b03811615610ef3576040516339e3563760e11b81525f6004820152602401610cc4565b613fba838383614013565b610ef3576001600160a01b038316613fe857604051637e27328960e01b815260048101829052602401610cc4565b60405163177e802f60e01b81526001600160a01b038316600482015260248101829052604401610cc4565b5f6001600160a01b0383161580159061363d5750826001600160a01b0316846001600160a01b0316148061404c575061404c84846133b8565b8061363d5750505f908152600460205260409020546001600160a01b03908116911614919050565b50805461408090614785565b5f825580601f1061408f575050565b601f0160209004905f5260205f20908101906134ab919061410f565b5080545f8255905f5260205f20908101906134ab919061410f565b828054828255905f5260205f209081019282156140ff579160200282015b828111156140ff5782518255916020019190600101906140e4565b5061410b92915061410f565b5090565b5b8082111561410b575f8155600101614110565b6001600160e01b0319811681146134ab575f5ffd5b5f60208284031215614148575f5ffd5b81356129bf81614123565b5f60208284031215614163575f5ffd5b5035919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f6129bf602083018461416a565b80356001600160a01b03811681146141c0575f5ffd5b919050565b5f5f604083850312156141d6575f5ffd5b6141df836141aa565b946020939093013593505050565b5f602082840312156141fd575f5ffd5b6129bf826141aa565b803580151581146141c0575f5ffd5b5f5f60408385031215614226575f5ffd5b8235915061423660208401614206565b90509250929050565b5f5f83601f84011261424f575f5ffd5b5081356001600160401b03811115614265575f5ffd5b60208301915083602082850101111561427c575f5ffd5b9250929050565b5f5f5f60408486031215614295575f5ffd5b8335925060208401356001600160401b038111156142b1575f5ffd5b6142bd8682870161423f565b9497909650939450505050565b5f5f5f606084860312156142dc575f5ffd5b6142e5846141aa565b92506142f3602085016141aa565b929592945050506040919091013590565b634e487b7160e01b5f52604160045260245ffd5b5f5f6001600160401b0384111561433157614331614304565b50604051601f19601f85018116603f011681018181106001600160401b038211171561435f5761435f614304565b604052838152905080828401851015614376575f5ffd5b838360208301375f60208583010152509392505050565b5f82601f83011261439c575f5ffd5b6129bf83833560208501614318565b5f5f5f606084860312156143bd575f5ffd5b833592506020840135915060408401356001600160401b038111156143e0575f5ffd5b6143ec8682870161438d565b9150509250925092565b5f5f60408385031215614407575f5ffd5b50508035926020909101359150565b5f5f5f60608486031215614428575f5ffd5b614431846141aa565b95602085013595506040909401359392505050565b5f5f83601f840112614456575f5ffd5b5081356001600160401b0381111561446c575f5ffd5b6020830191508360208260051b850101111561427c575f5ffd5b5f5f60208385031215614497575f5ffd5b82356001600160401b038111156144ac575f5ffd5b6144b885828601614446565b90969095509350505050565b5f5f5f5f5f5f5f60a0888a0312156144da575f5ffd5b8735965060208801356001600160401b038111156144f6575f5ffd5b6145028a828b0161423f565b90975095505060408801356001600160401b03811115614520575f5ffd5b61452c8a828b0161423f565b989b979a5095989597966060870135966080013595509350505050565b5f60208284031215614559575f5ffd5b81356001600160401b0381111561456e575f5ffd5b61363d8482850161438d565b60c081525f61458c60c083018961416a565b876020840152861515604084015282810360608401526145ac818761416a565b6080840195909552505060a00152949350505050565b5f5f604083850312156145d3575f5ffd5b8235915060208301356001600160401b038111156145ef575f5ffd5b6145fb8582860161438d565b9150509250929050565b803560ff811681146141c0575f5ffd5b5f5f5f60408486031215614627575f5ffd5b83356001600160401b0381111561463c575f5ffd5b61464886828701614446565b909450925061465b905060208501614605565b90509250925092565b602080825282518282018190525f918401906040840190835b8181101561469b57835183526020938401939092019160010161467d565b509095945050505050565b5f5f604083850312156146b7575f5ffd5b6146c0836141aa565b915061423660208401614206565b5f5f5f5f608085870312156146e1575f5ffd5b6146ea856141aa565b93506146f8602086016141aa565b92506040850135915060608501356001600160401b03811115614719575f5ffd5b8501601f81018713614729575f5ffd5b61473887823560208401614318565b91505092959194509250565b5f60208284031215614754575f5ffd5b6129bf82614605565b5f5f6040838503121561476e575f5ffd5b614777836141aa565b9150614236602084016141aa565b600181811c9082168061479957607f821691505b6020821081036147b757634e487b7160e01b5f52602260045260245ffd5b50919050565b6020808252601690820152752cb7ba9036bab9ba1037bbb7103a3432903a37b5b2b760511b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b81810381811115610b9f57610b9f614801565b634e487b7160e01b5f52603160045260245ffd5b601f821115610ef357805f5260205f20601f840160051c810160208510156148615750805b601f840160051c820191505b818110156138f2575f815560010161486d565b6001600160401b0383111561489757614897614304565b6148ab836148a58354614785565b8361483c565b5f601f8411600181146148dc575f85156148c55750838201355b5f19600387901b1c1916600186901b1783556138f2565b5f83815260208120601f198716915b8281101561490b57868501358255602094850194600190920191016148eb565b5086821015614927575f1960f88860031b161c19848701351681555b505060018560011b0183555050505050565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b602081525f61363d602083018486614939565b604080825283519082018190525f9060208501906060840190835b818110156149b957835180518452602090810151818501529093019260409092019160010161498f565b505083810360208501526149cd818661416a565b9695505050505050565b60208082526013908201527210db185b88191bd95cc81b9bdd08195e1a5cdd606a1b604082015260600190565b80820180821115610b9f57610b9f614801565b8183526020830192505f815f5b84811015614a53576001600160a01b03614a3d836141aa565b1686526020958601959190910190600101614a24565b5093949350505050565b602081525f61363d602083018486614a17565b60208082526021908201527f436c616e206e616d65206d75737420626520312d3332206368617261637465726040820152607360f81b606082015260800190565b5f8154614abd81614785565b808552600182168015614ad75760018114614af357614b27565b60ff1983166020870152602082151560051b8701019350614b27565b845f5260205f205f5b83811015614b1e5781546020828a010152600182019150602081019050614afc565b87016020019450505b50505092915050565b608081525f614b426080830187614ab1565b8281036020840152614b548187614ab1565b604084019590955250506060015292915050565b5f82614b8257634e487b7160e01b5f52601260045260245ffd5b500490565b8082028115828204841417610b9f57610b9f614801565b81516001600160401b03811115614bb757614bb7614304565b614bcb81614bc58454614785565b8461483c565b6020601f821160018114614bfd575f8315614be65750848201515b5f19600385901b1c1916600184901b1784556138f2565b5f84815260208120601f198516915b82811015614c2c5787850151825560209485019460019092019101614c0c565b5084821015614c4957868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f60018201614c6957614c69614801565b5060010190565b604081525f614c83604083018587614a17565b905060ff83166020830152949350505050565b6020808252818101527f507572636861736520776f756c6420657863656564206d617820746f6b656e73604082015260600190565b5f81518060208401855e5f93019283525090919050565b5f614cf6614cf08386614ccb565b84614ccb565b64173539b7b760d91b8152600501949350505050565b608081525f614d1f60808301888a614939565b8281036020840152614d32818789614939565b6040840195909552505060600152949350505050565b5f60ff821680614d5a57614d5a614801565b5f190192915050565b6001600160a01b03858116825284166020820152604081018390526080606082018190525f906149cd9083018461416a565b5f60208284031215614da5575f5ffd5b81516129bf8161412356fea264697066735822122017203c9845fd52f18b4c8933f43d29df4115ed4f9dce3ddb704959269354826664736f6c634300081c0033
Verified Source Code Full Match
Compiler: v0.8.28+commit.7893614a
EVM: cancun
Optimization: Yes (200 runs)
FoxyClan.sol 745 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
/**
* @title FoxyClan contract
* @dev Extends ERC721 Non-Fungible Token Standard basic implementation
*/
contract FoxyClan is ERC721, ERC721Enumerable, Ownable, ReentrancyGuard {
event AirdropClaimed(address indexed user, uint256 indexed tokenId);
event Merge(address indexed owner, uint256 indexed tokenIdBurned1, uint256 indexed tokenIdBurned2, uint256 newTokenId);
event FoxyPointsSpent(FoxyPointsSpend[] spentPoints, string usage);
event ClanCreated(uint256 indexed clanId, uint256 indexed leaderTokenId, string name, string description, uint256 minLevel, uint256 maxMembers);
event ClanUpdated(uint256 indexed clanId, string name, string description, uint256 minLevel, uint256 maxMembers);
event ClanMemberJoined(uint256 indexed clanId, uint256 indexed tokenId);
event ClanMemberLeft(uint256 indexed clanId, uint256 indexed tokenId);
event ClanDisbanded(uint256 indexed clanId);
event ClanLeadershipTransferred(uint256 indexed clanId, uint256 oldLeaderTokenId, uint256 newLeaderTokenId);
event SoulphraseSet(uint256 indexed tokenId, string phrase);
event FoxyPointsAwardRedeemed(uint256 indexed tokenId, uint256 amount);
event AirdropListAdded(address[] addresses);
event AirdropStateFlipped(bool newState);
event BaseURIUpdated(string newURI);
event PublicSaleStateFlipped(uint256 maxMintAmount, bool newState);
event PrivateSaleStateFlipped(bool newState);
event AllowListStateFlipped(bool newState);
event AllowListSet(address[] addresses, uint8 numAllowed);
mapping(address => bool) public airdropEligible;
bool public airdropActive = false;
bool public publicSaleIsActive = false;
bool public privateSaleIsActive = false;
string private _BaseURI;
bool public allowListIsActive = false;
uint256 public constant MAX_SUPPLY = 20000;
uint256 private _tokenIdOffset = 0; // Offset used to skip token IDs after burns (prevents ID reuse)
uint256 public burnedToken = 0; // Tracks the net permanent reduction from MAX_SUPPLY (e.g., a merge burns 2 and mints 1 ⇒ burnedToken += 1). Used in _canMint/availableSupply so merges don’t affect remaining supply.
uint256 public constant maxPublicFoxyMint = 20;
uint256 public constant publicFoxyPrice = 0.005 ether;
uint256 public constant privateFoxyPrice = 0.003 ether;
uint256 public saleMintLimit = 0;
uint256 public currentSaleMinted = 0;
mapping(address => uint8) private _AllowList;
mapping(uint256 => uint256) private _pointsTimestamp;
mapping(uint256 => uint256) private _foxyPoints;
mapping (uint256 => uint256) public level;
mapping(uint256 => string) private _soulphrases;
mapping(uint256 => Clan) public clans;
mapping(uint256 => uint256) public tokenClan;
uint256 private _clanIdCounter = 1;
address public awardContract;
struct FoxyPointsSpend {
uint256 tokenId;
uint256 amount;
}
struct Clan {
string name;
uint256 leaderTokenId;
uint256[] members;
bool exists;
string description;
uint256 maxMembers;
uint256 minLevel;
}
constructor() ERC721("FoxyClan", "FOXY") Ownable(msg.sender) {}
/**
* @dev Internal helper to check if a given number of tokens can be minted
* without exceeding the adjusted MAX_SUPPLY (taking burned tokens into account).
* Used in all minting-related functions to enforce supply limits.
* @param amount The number of tokens intended to be minted.
* @return A boolean indicating whether the minting is allowed.
*/
function _canMint(uint256 amount) internal view returns (bool) {
return totalSupply() + amount <= MAX_SUPPLY - burnedToken;
}
/**
* @dev Returns the number of tokens still available for minting,
* accounting for both total supply and burned tokens.
* @return The number of NFTs that can still be minted before reaching the supply cap.
*/
function availableSupply() public view returns (uint256) {
return MAX_SUPPLY - burnedToken - totalSupply();
}
function addAirdropAddresses(address[] calldata addresses) external onlyOwner {
require(addresses.length > 0, "Bad airdrop list size");
for (uint256 i = 0; i < addresses.length; i++) {
address addr = addresses[i];
if (!airdropEligible[addr]) {
airdropEligible[addr] = true;
}
}
emit AirdropListAdded(addresses);
}
function flipAirdropState() external onlyOwner {
airdropActive = !airdropActive;
emit AirdropStateFlipped(airdropActive);
}
/**
* @dev Allows an eligible address to claim one free airdropped Foxy token.
*
* Requirements:
* - The airdrop must be active.
* - The caller must be in the airdrop list (eligibility is one-time only).
* - Claiming must not exceed the adjusted max supply.
*
* Behavior:
* - Marks the caller as no longer eligible (airdrop can be claimed only once).
* - Mints a new token initialized with level 1 and 0 Foxy Points
* (unlike paid mints, which start with 50 points).
* - Emits an `AirdropClaimed` event.
*
* Security:
* - Uses `nonReentrant` to prevent potential reentrancy via the ERC721 `_safeMint` hook.
*/
function claimAirdrop() external nonReentrant {
require(airdropActive, "Airdrop is not active");
require(airdropEligible[msg.sender], "Not eligible for airdrop");
require(_canMint(1), "Max supply exceeded");
airdropEligible[msg.sender] = false;
uint256 tokenId = totalSupply() + _tokenIdOffset;
tokenInitialization(tokenId, 0);
_safeMint(msg.sender, tokenId);
emit AirdropClaimed(msg.sender, tokenId);
}
/**
* @dev Returns the current Foxy Points for a specific token.
* Foxy Points accumulate daily based on the token's level:
* - Level 1: no passive gain
* - Level 2: +1 point/day
* - Level 3: +2 points/day
* @param tokenId The ID of the token to query.
* @return The total Foxy Points available for the token.
*/
function getTokenPoints(uint256 tokenId) public view returns (uint256) {
_requireOwned(tokenId);
uint256 levelValue = level[tokenId];
uint256 dailyGain = 0;
if (levelValue == 2) {
dailyGain = 1;
} else if (levelValue == 3) {
dailyGain = 2;
}
uint256 accumulatedPoints = ((block.timestamp - _pointsTimestamp[tokenId]) / 1 days) * dailyGain;
return _foxyPoints[tokenId] + accumulatedPoints;
}
/**
* @dev Returns the total Foxy Points across all tokens owned by an address.
* @param owner The address to check.
* @return The sum of all Foxy Points held by the owner's tokens.
*/
function getUserPoints(address owner) public view returns (uint256) {
uint256 balance = balanceOf(owner);
uint256 totalPoints = 0;
for (uint256 i = 0; i < balance; i++) {
uint256 tokenId = tokenOfOwnerByIndex(owner, i);
totalPoints += getTokenPoints(tokenId);
}
return totalPoints;
}
/**
* @dev Spends a specific amount of Foxy Points from a single token.
* Emits a `FoxyPointsSpent` event containing one entry (the token ID and points spent) and a usage description.
* Only the token's owner can call this function.
* @param tokenId The token from which to deduct Foxy Points.
* @param amount The number of points to deduct.
* @param usage A string describing the purpose of the point deduction.
*/
function spendFoxyPoints(uint256 tokenId, uint256 amount, string memory usage) public {
require(ownerOf(tokenId) == msg.sender, "Not the owner");
require(getTokenPoints(tokenId) >= amount, "Not enough points");
uint256 updatedPoints = getTokenPoints(tokenId);
_foxyPoints[tokenId] = updatedPoints - amount;
_pointsTimestamp[tokenId] = block.timestamp;
FoxyPointsSpend[] memory spent = new FoxyPointsSpend[](1);
spent[0] = FoxyPointsSpend(tokenId, amount);
emit FoxyPointsSpent(spent, usage);
}
/**
* @dev Spends Foxy Points from all tokens owned by the caller.
* Distributes the deduction across multiple tokens if needed.
* Emits a single FoxyPointsSpent event containing the list of deductions per token.
* Reverts if total available points are insufficient.
* @param amount The total number of points to spend.
* @param usage The reason for spending the points.
*/
function spendFoxyPointsFromCollection(uint256 amount, string memory usage) public {
uint256 balance = balanceOf(msg.sender);
require(balance > 0, "You don't own any Foxy tokens");
uint256 totalAvailable = getUserPoints(msg.sender);
require(totalAvailable >= amount, "Not enough total points");
uint256 remaining = amount;
FoxyPointsSpend[] memory spent = new FoxyPointsSpend[](balance);
uint256 index = 0;
for (uint256 i = 0; i < balance && remaining > 0; i++) {
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, i);
uint256 available = getTokenPoints(tokenId);
if (available == 0) continue;
uint256 toSpend = available >= remaining ? remaining : available;
_foxyPoints[tokenId] = available - toSpend;
_pointsTimestamp[tokenId] = block.timestamp;
spent[index] = FoxyPointsSpend(tokenId, toSpend);
index++;
remaining -= toSpend;
}
require(remaining == 0, "Internal error: Not enough points deducted");
FoxyPointsSpend[] memory finalSpent = new FoxyPointsSpend[](index);
for (uint256 j = 0; j < index; j++) {
finalSpent[j] = spent[j];
}
emit FoxyPointsSpent(finalSpent, usage);
}
function setBaseURI(string memory uri) external onlyOwner() {
_BaseURI = uri;
emit BaseURIUpdated(uri);
}
function _baseURI() internal view override returns (string memory) {
return _BaseURI;
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
_requireOwned(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, Strings.toString(tokenId), ".json")) : "";
}
function flipPublicSaleState(uint256 maxMintAmount, bool state) external onlyOwner {
publicSaleIsActive = state;
if (publicSaleIsActive) {
saleMintLimit = maxMintAmount;
currentSaleMinted = 0;
} else {
saleMintLimit = 0;
}
emit PublicSaleStateFlipped(maxMintAmount, state);
}
function flipPrivateSaleState() external onlyOwner {
privateSaleIsActive = !privateSaleIsActive;
emit PrivateSaleStateFlipped(privateSaleIsActive);
}
function flipAllowListState() external onlyOwner {
allowListIsActive = !allowListIsActive;
emit AllowListStateFlipped(allowListIsActive);
}
/**
* @dev Sets the allow list for addresses and their corresponding mint limits.
* @param addresses An array of addresses that will be allowed to mint FoxyClan nfts.
* @param numAllowedToMint The number of tokens allowed to be minted for each address.
*/
function setAllowList(address[] calldata addresses, uint8 numAllowedToMint) external onlyOwner {
for (uint256 i = 0; i < addresses.length; i++) {
_AllowList[addresses[i]] = numAllowedToMint;
}
emit AllowListSet(addresses, numAllowedToMint);
}
/**
* @dev Returns the number of tokens available to mint for a specific address.
* @param addr The address to check.
* @return The number of tokens available to mint for a specific address.
*/
function numAvailableToMint(address addr) external view returns (uint8) {
return _AllowList[addr];
}
/**
* @dev Mints a specified number of tokens for a user on the allowlist.
* This function is used during allowlist sales (either public or private).
* Each minted token is initialized with level 1 and 50 Foxy Points.
*/
function mintAllowList(uint8 numberOfTokens) external payable {
uint256 costToMint;
if (privateSaleIsActive) {
costToMint = privateFoxyPrice * numberOfTokens;
} else {
costToMint = publicFoxyPrice * numberOfTokens;
}
require(allowListIsActive, "Allow list is not active");
require(numberOfTokens <= _AllowList[msg.sender], "Exceeded max available to purchase");
require(_canMint(numberOfTokens), "Purchase would exceed max tokens");
require(costToMint <= msg.value, "Ether value sent is not correct");
for (uint256 i = 0; i < numberOfTokens; i++) {
uint256 tokenId = totalSupply() + _tokenIdOffset;
_AllowList[msg.sender] --;
tokenInitialization(tokenId, 50);
_safeMint(msg.sender, tokenId);
}
}
/**
* @dev Mints tokens during the public sale phase.
* Each minted token is initialized with level 1 and 50 Foxy Points.
*/
function mint(uint256 numberOfTokens) public payable {
uint256 costToMint = publicFoxyPrice * numberOfTokens;
require(publicSaleIsActive, "Sale must be active to mint Foxy");
require(numberOfTokens <= maxPublicFoxyMint, "Can only mint a limited number of tokens at a time");
require(_canMint(numberOfTokens), "Purchase would exceed max tokens");
require(costToMint <= msg.value, "Ether value sent is not correct");
if (saleMintLimit > 0) {
require(currentSaleMinted + numberOfTokens <= saleMintLimit, "Minting limit for this sale reached");
}
for (uint256 i = 0; i < numberOfTokens; i++) {
uint256 tokenId = totalSupply() + _tokenIdOffset;
tokenInitialization(tokenId, 50);
_safeMint(msg.sender, tokenId);
}
currentSaleMinted += numberOfTokens;
}
/**
* @dev Merges two owned tokens into a new one with upgraded level and combined FoxyPoints.
*
* Requirements:
* - Caller must own both tokens.
* - Tokens must be different.
* - At least one of the tokens must be level 1.
* - Both tokens must be level strictly lower than 3.
*
* Behavior:
* - Burns the two source tokens.
* - Mints a new token with:
* - Level increased by 1, based on the highest level among the two.
* - FoxyPoints from both tokens combined, plus a merge bonus (100 for level 2, 250 for level 3).
* - A fresh timestamp for point accumulation tracking.
* - Increments `_tokenIdOffset` by 2 to maintain correct token indexing.
* - Increments `burnedToken` by 1, since one token is permanently removed from supply.
* - Emits a `Merge` event with the old and new token IDs.
*/
function merge(uint256 tokenId1, uint256 tokenId2) external {
require(ownerOf(tokenId1) == msg.sender, "You must own tokenId1");
require(ownerOf(tokenId2) == msg.sender, "You must own tokenId2");
require(tokenId1 != tokenId2, "Cannot merge the same token");
require(level[tokenId1] == 1 || level[tokenId2] == 1, "At least one of the two tokens must be level 1");
require(level[tokenId1] < 3 && level[tokenId2] < 3, "A level 3 token cannot be merged");
uint256 tokenPoints1 = getTokenPoints(tokenId1);
uint256 tokenPoints2 = getTokenPoints(tokenId2);
uint256 newLevel = level[tokenId1] > level[tokenId2]
? level[tokenId1]
: level[tokenId2];
newLevel++;
_burn(tokenId1);
_burn(tokenId2);
_tokenIdOffset += 2;
burnedToken += 1;
uint256 tokenId = totalSupply() + _tokenIdOffset;
level[tokenId] = newLevel;
uint256 mergePoints = level[tokenId] == 2 ? 100 : 250;
_foxyPoints[tokenId] = tokenPoints1 + tokenPoints2 + mergePoints;
_pointsTimestamp[tokenId] = block.timestamp;
emit Merge(msg.sender, tokenId1, tokenId2, tokenId);
_safeMint(msg.sender, tokenId);
}
/**
* @dev Initializes a newly minted token with default values.
* Sets the level to 1, assigns the initial amount of Foxy Points,
* and records the current timestamp to start point accumulation tracking.
*/
function tokenInitialization(uint256 tokenId, uint256 initialPoints) internal {
level[tokenId] = 1;
_foxyPoints[tokenId] = initialPoints;
_pointsTimestamp[tokenId] = block.timestamp;
}
/**
* @dev Allows the owner of a level 2+ token to set a soulphrase.
* This feature is only available once at least 30 tokens have been burned.
* @param tokenId The token to assign the phrase to.
* @param phrase The phrase to be stored in the token.
*/
function setSoulphrase(uint256 tokenId, string calldata phrase) external {
require(ownerOf(tokenId) == msg.sender, "You must own this token");
require(level[tokenId] >= 2, "Only level 2+ tokens can set a soulphrase");
require(burnedToken >= 30, "Soulphrase is locked until 30 tokens are burned");
require(bytes(phrase).length <= 100, "Phrase too long (max 100 characters)");
_soulphrases[tokenId] = phrase;
emit SoulphraseSet(tokenId, phrase);
}
function getSoulphrase(uint256 tokenId) public view returns (string memory) {
_requireOwned(tokenId);
return _soulphrases[tokenId];
}
/**
* @dev Creates a new clan. Only a level 3 token can be used to create one.
* This feature is only available once at least 100 tokens have been burned.
* Requires 30 Foxy Points from the token used.
* @param tokenId The token used to create the clan (must be level 3).
* @param name The name of the clan.
*/
function createClan(
uint256 tokenId,
string calldata name,
string calldata description,
uint256 minLevel,
uint256 maxMembers
) external {
require(burnedToken >= 100, "Clans are locked until 100 tokens are burned");
require(ownerOf(tokenId) == msg.sender, "You must own the token");
require(level[tokenId] == 3, "Only level 3 tokens can create clans");
require(tokenClan[tokenId] == 0, "Token already in a clan");
require(minLevel >= 1 && minLevel <= 3, "Invalid min level");
require(bytes(name).length > 0 && bytes(name).length <= 32, "Clan name must be 1-32 characters");
require(bytes(description).length <= 256, "Description too long (max 256)");
require(maxMembers >= 1 && maxMembers <= 100, "Invalid member limit");
spendFoxyPoints(tokenId, 30, "Clan creation");
uint256 clanId = _clanIdCounter++;
clans[clanId] = Clan({
name: name,
description: description,
leaderTokenId: tokenId,
members: new uint256 [](0),
exists: true,
minLevel: minLevel,
maxMembers: maxMembers
});
clans[clanId].members.push(tokenId);
tokenClan[tokenId] = clanId;
emit ClanCreated(clanId, tokenId, name, description, minLevel, maxMembers);
}
/**
* @dev Allows the clan leader to update various clan settings: name, description, minimum level, and maximum members.
*
* Requirements:
* - The clan must exist.
* - The caller must be the owner of the leader token.
* - `name` must be between 1 and 32 characters if provided.
* - `description` must be at most 256 characters if provided.
* - `minLevel` must be between 1 and 3 if set (non-zero).
* - `maxMembers` must not be less than the current number of members and cannot exceed 100 if set (non-zero).
*
* @param clanId The ID of the clan to update.
* @param name The new name for the clan (optional, set only if not empty).
* @param description The new description for the clan (optional, set only if not empty).
* @param minLevel The new minimum level required to join the clan (optional, set only if not zero).
* @param maxMembers The new maximum number of members allowed in the clan (optional, set only if not zero).
*/
function updateClanSettings(
uint256 clanId,
string calldata name,
string calldata description,
uint256 minLevel,
uint256 maxMembers
) external {
require(clans[clanId].exists, "Clan does not exist");
uint256 leaderToken = clans[clanId].leaderTokenId;
require(ownerOf(leaderToken) == msg.sender, "Only the clan leader can update settings");
if (bytes(name).length > 0) {
require(bytes(name).length <= 32, "Clan name must be 1-32 characters");
clans[clanId].name = name;
}
if (bytes(description).length > 0) {
require(bytes(description).length <= 256, "Description too long (max 256)");
clans[clanId].description = description;
}
if (minLevel != 0) {
require(minLevel >= 1 && minLevel <= 3, "Invalid min level");
clans[clanId].minLevel = minLevel;
}
if (maxMembers != 0) {
require(maxMembers >= clans[clanId].members.length, "Cannot set maxMembers below current count");
require(maxMembers <= 100, "Max members limit exceeded");
clans[clanId].maxMembers = maxMembers;
}
emit ClanUpdated(clanId, clans[clanId].name, clans[clanId].description, clans[clanId].minLevel, clans[clanId].maxMembers);
}
/**
* @dev Adds a token to a clan.
* Requirements:
* - Caller must own the token.
* - The clan must exist and not be full.
* - The token must not already be in a clan and must meet the clan’s min level.
*
* Records the clan membership for the token and emits a `ClanMemberJoined` event.
*
* @param tokenId Token joining the clan.
* @param clanId ID of the clan to join.
*/
function joinClan(uint256 tokenId, uint256 clanId) external {
require(ownerOf(tokenId) == msg.sender, "You must own the token");
require(clans[clanId].exists, "Clan does not exist");
require(tokenClan[tokenId] == 0, "Token already in a clan");
require(level[tokenId] >= clans[clanId].minLevel, "Token level too low for this clan");
require(clans[clanId].members.length < clans[clanId].maxMembers, "Clan is full");
clans[clanId].members.push(tokenId);
tokenClan[tokenId] = clanId;
emit ClanMemberJoined(clanId, tokenId);
}
/**
* @dev Allows a token to leave its current clan.
*
* Requirements:
* - Caller must be the owner of the token.
* - The token must currently belong to a clan.
*
* Behavior:
* - Removes the token from the clan’s member list and clears its clan association.
* - Emits a `ClanMemberLeft` event.
* - If the token leaving is the clan leader:
* - All remaining members are detached (their `tokenClan` is reset to 0).
* - The clan is permanently deleted.
* - A `ClanDisbanded` event is emitted.
*/
function leaveClan(uint256 tokenId) external {
require(ownerOf(tokenId) == msg.sender, "You must own the token");
uint256 clanId = tokenClan[tokenId];
require(clanId != 0, "Token is not in a clan");
Clan storage clan = clans[clanId];
for (uint256 i = 0; i < clan.members.length; i++) {
if (clan.members[i] == tokenId) {
clan.members[i] = clan.members[clan.members.length - 1];
clan.members.pop();
break;
}
}
tokenClan[tokenId] = 0;
emit ClanMemberLeft(clanId, tokenId);
if (clan.leaderTokenId == tokenId) {
for (uint256 i = 0; i < clan.members.length; i++) {
tokenClan[clan.members[i]] = 0;
}
delete clans[clanId];
emit ClanDisbanded(clanId);
}
}
/**
* @dev Transfers leadership of a clan to another member.
*
* Requirements:
* - The clan must exist.
* - The caller must be the current leader of the clan.
* - The new leader token must belong to the same clan.
* - The new leader token must be of level 3.
*
* Emits a `ClanLeadershipTransferred` event.
*
* @param clanId The ID of the clan whose leadership is being transferred.
* @param newLeaderTokenId The token ID of the member who will become the new leader.
*/
function transferClanLeadership(uint256 clanId, uint256 newLeaderTokenId) external {
require(clans[clanId].exists, "Clan does not exist");
uint256 currentLeaderTokenId = clans[clanId].leaderTokenId;
require(ownerOf(currentLeaderTokenId) == msg.sender, "Only the clan leader can transfer leadership");
require(tokenClan[newLeaderTokenId] == clanId, "New leader must be a clan member");
require(level[newLeaderTokenId] == 3, "New leader must be level 3");
clans[clanId].leaderTokenId = newLeaderTokenId;
emit ClanLeadershipTransferred(clanId, currentLeaderTokenId, newLeaderTokenId);
}
function getClanMembers(uint256 clanId) public view returns (uint256[] memory) {
require(clans[clanId].exists, "Clan does not exist");
return clans[clanId].members;
}
function getClanOfToken(uint256 tokenId) public view returns (uint256) {
return tokenClan[tokenId];
}
function setAwardContract(address c) external onlyOwner {
awardContract = c;
}
/**
* @dev Grants bonus Foxy Points to a token.
* Can only be called by the `awardContract`, and the `user` must own the token.
* Increases the token’s points by `pts` and emits a `FoxyPointsAwardRedeemed` event.
*
* @param user Current owner of the token.
* @param tokenId Token receiving the points.
* @param pts Amount of points to add.
*/
function addFoxyPointsFromAward(address user, uint256 tokenId, uint256 pts) external {
require(msg.sender == awardContract, "Not award contract");
require(ownerOf(tokenId) == user, "Must own Foxy");
_foxyPoints[tokenId] += pts;
emit FoxyPointsAwardRedeemed(tokenId, pts);
}
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
function _update(address to, uint256 tokenId, address auth) internal override(ERC721, ERC721Enumerable) returns (address) {
return super._update(to, tokenId, auth);
}
function _increaseBalance(address account, uint128 amount) internal override(ERC721, ERC721Enumerable) {
return super._increaseBalance(account, amount);
}
/**
* @dev Reserves a specified number of tokens for the contract owner.
* This function allow the creator to keep a certain number of tokens
* for future uses, such as giveaways, collaborations or special events.
*/
function reserveFoxy(uint256 n) public onlyOwner {
require(_canMint(n), "Purchase would exceed max tokens");
for (uint256 i = 0; i < n; i++) {
uint256 tokenId = totalSupply() + _tokenIdOffset;
tokenInitialization(tokenId, 50);
_safeMint(msg.sender, tokenId);
}
}
function withdraw() public onlyOwner nonReentrant {
uint balance = address(this).balance;
payable(msg.sender).transfer(balance);
}
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
ERC721Enumerable.sol 173 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.20;
import {ERC721} from "../ERC721.sol";
import {IERC721Enumerable} from "./IERC721Enumerable.sol";
import {IERC165} from "../../../utils/introspection/ERC165.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.
*
* CAUTION: `ERC721` extensions that implement custom `balanceOf` logic, such as `ERC721Consecutive`,
* interfere with enumerability and should not be used together with `ERC721Enumerable`.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
mapping(address owner => mapping(uint256 index => uint256)) private _ownedTokens;
mapping(uint256 tokenId => uint256) private _ownedTokensIndex;
uint256[] private _allTokens;
mapping(uint256 tokenId => uint256) private _allTokensIndex;
/**
* @dev An `owner`'s token query was out of bounds for `index`.
*
* NOTE: The owner being `address(0)` indicates a global out of bounds index.
*/
error ERC721OutOfBoundsIndex(address owner, uint256 index);
/**
* @dev Batch mint is not allowed.
*/
error ERC721EnumerableForbiddenBatchMint();
/**
* @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 returns (uint256) {
if (index >= balanceOf(owner)) {
revert ERC721OutOfBoundsIndex(owner, index);
}
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual returns (uint256) {
if (index >= totalSupply()) {
revert ERC721OutOfBoundsIndex(address(0), index);
}
return _allTokens[index];
}
/**
* @dev See {ERC721-_update}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address) {
address previousOwner = super._update(to, tokenId, auth);
if (previousOwner == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (previousOwner != to) {
_removeTokenFromOwnerEnumeration(previousOwner, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (previousOwner != to) {
_addTokenToOwnerEnumeration(to, tokenId);
}
return previousOwner;
}
/**
* @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 = balanceOf(to) - 1;
_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 = balanceOf(from);
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();
}
/**
* See {ERC721-_increaseBalance}. We need that to account tokens that were minted in batch
*/
function _increaseBalance(address account, uint128 amount) internal virtual override {
if (amount > 0) {
revert ERC721EnumerableForbiddenBatchMint();
}
super._increaseBalance(account, amount);
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
ERC721.sol 483 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "./IERC721.sol";
import {IERC721Receiver} from "./IERC721Receiver.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {Strings} from "../../utils/Strings.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {IERC721Errors} from "../../interfaces/draft-IERC6093.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}.
*/
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
mapping(uint256 tokenId => address) private _owners;
mapping(address owner => uint256) private _balances;
mapping(uint256 tokenId => address) private _tokenApprovals;
mapping(address owner => mapping(address operator => 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 returns (uint256) {
if (owner == address(0)) {
revert ERC721InvalidOwner(address(0));
}
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual returns (address) {
return _requireOwned(tokenId);
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual {
_approve(to, tokenId, _msgSender());
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual returns (address) {
_requireOwned(tokenId);
return _getApproved(tokenId);
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
// Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
address previousOwner = _update(to, tokenId, _msgSender());
if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
transferFrom(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*
* IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
* core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
* consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
* `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
*/
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
return _tokenApprovals[tokenId];
}
/**
* @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
* particular (ignoring whether it is owned by `owner`).
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
return
spender != address(0) &&
(owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
}
/**
* @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
* Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
* the `spender` for the specific `tokenId`.
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else {
revert ERC721InsufficientApproval(spender, tokenId);
}
}
}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
* a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
*
* WARNING: Increasing an account's balance using this function tends to be paired with an override of the
* {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
* remain consistent with one another.
*/
function _increaseBalance(address account, uint128 value) internal virtual {
unchecked {
_balances[account] += value;
}
}
/**
* @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
*
* Emits a {Transfer} event.
*
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
address from = _ownerOf(tokenId);
// Perform (optional) operator check
if (auth != address(0)) {
_checkAuthorized(from, auth, tokenId);
}
// Execute the update
if (from != address(0)) {
// Clear approval. No need to re-authorize or emit the Approval event
_approve(address(0), tokenId, address(0), false);
unchecked {
_balances[from] -= 1;
}
}
if (to != address(0)) {
unchecked {
_balances[to] += 1;
}
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
return from;
}
/**
* @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 {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner != address(0)) {
revert ERC721InvalidSender(address(0));
}
}
/**
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
*
* 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 {
_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);
_checkOnERC721Received(address(0), to, tokenId, data);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal {
address previousOwner = _update(address(0), tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(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 {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
* are aware of the ERC721 standard 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 like {safeTransferFrom} in the sense that it invokes
* {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `tokenId` token must exist and be owned by `from`.
* - `to` cannot be the zero address.
* - `from` cannot be the zero address.
* - 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) internal {
_safeTransfer(from, to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
* either the owner of the token, or approved to operate on all tokens held by this owner.
*
* Emits an {Approval} event.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address to, uint256 tokenId, address auth) internal {
_approve(to, tokenId, auth, true);
}
/**
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
* emitted in the context of transfers.
*/
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
// Avoid reading the owner unless necessary
if (emitEvent || auth != address(0)) {
address owner = _requireOwned(tokenId);
// We do not use _isAuthorized because single-token approvals should not be able to call approve
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
revert ERC721InvalidApprover(auth);
}
if (emitEvent) {
emit Approval(owner, to, tokenId);
}
}
_tokenApprovals[tokenId] = to;
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Requirements:
* - operator can't be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC721InvalidOperator(operator);
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
* Returns the owner.
*
* Overrides to ownership logic should be done to {_ownerOf}.
*/
function _requireOwned(uint256 tokenId) internal view returns (address) {
address owner = _ownerOf(tokenId);
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
return owner;
}
/**
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
* recipient doesn't accept the token transfer. 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
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
if (to.code.length > 0) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
if (retval != IERC721Receiver.onERC721Received.selector) {
revert ERC721InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
revert ERC721InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC721Enumerable.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../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);
/**
* @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);
}
draft-IERC6093.sol 161 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
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));
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
IERC721Receiver.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
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);
}
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);
}
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);
}
}
}
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;
}
}
Read Contract
MAX_SUPPLY 0x32cb6b0c → uint256
airdropActive 0x9843eae3 → bool
airdropEligible 0xab39f08a → bool
allowListIsActive 0xb8be499b → bool
availableSupply 0x7ecc2b56 → uint256
awardContract 0x865f8cae → address
balanceOf 0x70a08231 → uint256
burnedToken 0x330c4ce0 → uint256
clans 0x66469a3a → string, uint256, bool, string, uint256, uint256
currentSaleMinted 0x9ae7e129 → uint256
getApproved 0x081812fc → address
getClanMembers 0x99ee1998 → uint256[]
getClanOfToken 0x61c6d720 → uint256
getSoulphrase 0xfd37aaf5 → string
getTokenPoints 0x53139a98 → uint256
getUserPoints 0xaeefe31f → uint256
isApprovedForAll 0xe985e9c5 → bool
level 0x05c58df2 → uint256
maxPublicFoxyMint 0x3ad05024 → uint256
name 0x06fdde03 → string
numAvailableToMint 0xc04a2836 → uint8
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
privateFoxyPrice 0xea4643b7 → uint256
privateSaleIsActive 0x04737a01 → bool
publicFoxyPrice 0x4f0c5400 → uint256
publicSaleIsActive 0x0fcf2e75 → bool
saleMintLimit 0xc976dcfa → uint256
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenByIndex 0x4f6ccce7 → uint256
tokenClan 0x1363e296 → uint256
tokenOfOwnerByIndex 0x2f745c59 → uint256
tokenURI 0xc87b56dd → string
totalSupply 0x18160ddd → uint256
Write Contract 30 functions
These functions modify contract state and require a wallet transaction to execute.
addAirdropAddresses 0x4bfeb203
address[] addresses
addFoxyPointsFromAward 0x42246542
address user
uint256 tokenId
uint256 pts
approve 0x095ea7b3
address to
uint256 tokenId
claimAirdrop 0x5b88349d
No parameters
createClan 0xd5387628
uint256 tokenId
string name
string description
uint256 minLevel
uint256 maxMembers
flipAirdropState 0x3e75475f
No parameters
flipAllowListState 0xfeb309ad
No parameters
flipPrivateSaleState 0x3719e3b0
No parameters
flipPublicSaleState 0x1015207f
uint256 maxMintAmount
bool state
joinClan 0x3a61785a
uint256 tokenId
uint256 clanId
leaveClan 0x0a578c9b
uint256 tokenId
merge 0xd1c2babb
uint256 tokenId1
uint256 tokenId2
mint 0xa0712d68
uint256 numberOfTokens
mintAllowList 0xddff5b1c
uint8 numberOfTokens
renounceOwnership 0x715018a6
No parameters
reserveFoxy 0xef2f0ddd
uint256 n
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes data
setAllowList 0x8295784d
address[] addresses
uint8 numAllowedToMint
setApprovalForAll 0xa22cb465
address operator
bool approved
setAwardContract 0x098ecb82
address c
setBaseURI 0x55f804b3
string uri
setSoulphrase 0x14ed66be
uint256 tokenId
string phrase
spendFoxyPoints 0x39895ee5
uint256 tokenId
uint256 amount
string usage
spendFoxyPointsFromCollection 0x7e36b7ee
uint256 amount
string usage
transferClanLeadership 0x8688160f
uint256 clanId
uint256 newLeaderTokenId
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
updateClanSettings 0x514e7213
uint256 clanId
string name
string description
uint256 minLevel
uint256 maxMembers
withdraw 0x3ccfd60b
No parameters
Recent Transactions
No transactions found for this address