Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x4bd0F1886010253a18BBb401a788d8972c155b9d
Balance 0 ETH
Nonce 1
Code Size 13681 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

13681 bytes
0x608080604052600436101561001357600080fd5b600090813560e01c908162be3656146129ff5750806301ffc9a7146129a857806306fdde03146128eb578063095ea7b3146128415780630cfd5bbb146127a85780630e5ff0f31461274a578063179397f71461272157806318160ddd146127035780631cdd02211461231e578063229f3e291461230057806323b872dd146122205780632be095611461210a5780632df700ac14612024578063313ce567146120085780633737bcb414611fea5780633a81104d14611fc157806342445bae14611fa857806342966c6814611ef55780634ada218b14611ecf5780635d6b17a214611ea957806360d938dc14611e8957806370a0823114611e51578063715018a614611dea57806379ba509714611d625780638156b1ec14611b98578063847e7fe614611b7457806387dba908146118ba5780638a7b1501146118935780638da5cb5b1461186a57806395d89b4114611761578063a9059cbb1461172f578063b199e7e714611709578063b3e20c5e146116e8578063c3e46ab314611274578063c55bf0391461122d578063d1fe8484146111cb578063d3179ec2146110a1578063d48b6fb014610d30578063d89135cd14610d12578063dd62ed3e14610cbd578063dfac55c714610c94578063e30c397814610c6b578063f0883d10146108f4578063f2fde38b14610886578063f468fa07146108605763fd1f3e811461021a57600080fd5b346104535760603660031901126104535760043580151581036104795761023f612db0565b600d54156108515760ff600a5460a01c16610842576040516370a0823160e01b81523060048201526020816024816000805160206134fc8339815191525afa90811561055f578391610810575b506c02863c1f5cdae42f95400000008110156107f957600d5442106107ea57600b555b600b5460021c901561056a57604051636eb1769f60e11b8152306004820152735c47902c8c80779cb99235e42c354e53f38c3b0d60248201526020816044816000805160206134fc8339815191525afa801561055f5782908490610524575b6103189250612b49565b828060405192602084019063095ea7b360e01b8252735c47902c8c80779cb99235e42c354e53f38c3b0d602486015260448501526044845261035b606485612b28565b835190826000805160206134fc8339815191525af161037861345b565b816104f5575b50806104dd575b1561047d575b50735c47902c8c80779cb99235e42c354e53f38c3b0d3b1561047957816040516302c190dd60e61b8152826004820152818160248183735c47902c8c80779cb99235e42c354e53f38c3b0d5af1801561045657610464575b50506103f2905b600b54612b6c565b600b55600a805460ff60a01b1916600160a01b17905560085481906001600160a01b0316803b1561046157818091600460405180948193639d77126d60e01b83525af18015610456576104425750f35b8161044c91612b28565b6104535780f35b80fd5b6040513d84823e3d90fd5b50fd5b8161046e91612b28565b6104795781386103e3565b5080fd5b6104d7906104c360405163095ea7b360e01b6020820152735c47902c8c80779cb99235e42c354e53f38c3b0d6024820152856044820152604481526104c3606482612b28565b6000805160206134fc833981519152613304565b3861038b565b506000805160206134fc8339815191523b1515610385565b805180159250821561050a575b50503861037e565b61051d9250602080918301019101612dd9565b3880610502565b50506020813d602011610557575b8161053f60209383612b28565b810103126105525781610318915161030e565b600080fd5b3d9150610532565b6040513d85823e3d90fd5b6040519061057782612b0c565b6000805160206134fc8339815191528252735c47902c8c80779cb99235e42c354e53f38c3b0d6020830152612710604083015230606083015260443560808301528060a083015260243560c08301528260e0830152604051636eb1769f60e11b815230600482015273e592427a0aece92de3edee1f18e0157c0586156460248201526020816044816000805160206134fc8339815191525afa9081156107df5784916107ab575b506106bc9261062f83602093612b49565b8580604051928584019063095ea7b360e01b825273e592427a0aece92de3edee1f18e0157c058615646024860152604485015260448452610671606485612b28565b835190826000805160206134fc8339815191525af161068e61345b565b8161077e575b5080610766575b1561071b575b506040518094819263414bf38960e01b8352600483016130d6565b03818673e592427a0aece92de3edee1f18e0157c058615645af191821561055f576103f2926106ec575b506103ea565b61070d9060203d602011610714575b6107058183612b28565b810190612b79565b50386106e6565b503d6106fb565b610760906104c360405163095ea7b360e01b8682015273e592427a0aece92de3edee1f18e0157c058615646024820152886044820152604481526104c3606482612b28565b386106a1565b506000805160206134fc8339815191523b151561069b565b8051801592508215610793575b505038610694565b6107a4925081018501908501612dd9565b388061078b565b90506020813d6020116107d7575b816107c660209383612b28565b8101031261055257516106bc61061e565b3d91506107b9565b6040513d86823e3d90fd5b63b18aee0b60e01b8352600483fd5b506c02863c1f5cdae42f9540000000600b556102af565b90506020813d60201161083a575b8161082b60209383612b28565b8101031261055257513861028c565b3d915061081e565b632b0039c760e21b8252600482fd5b6335c33e8160e01b8252600482fd5b5034610453578060031936011261045357602060ff600a5460a81c166040519015158152f35b5034610453576020366003190112610453576108a0612a6d565b6108a8612db0565b600680546001600160a01b0319166001600160a01b039283169081179091556005549091167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227008380a380f35b506108fe36612ac5565b90600d54421015610c5c578015610c4d57600a5460a01c60ff1615610c46576009546001600160a01b0316915b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc23b15610c4257604051630d0e30db60e41b8152849081816004813473c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25af1801561045657610c2d575b50506040519261098c84612b0c565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc284526000805160206134fc8339815191526020850152612710604085015260018060a01b0316606084015260808301523460a083015260c08201528160e0820152604051636eb1769f60e11b815230600482015273e592427a0aece92de3edee1f18e0157c05861564602482015260208160448173c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25afa90811561055f578391610bf9575b50610adf91610a4c6020923490612b49565b8480604051928584019063095ea7b360e01b825273e592427a0aece92de3edee1f18e0157c058615646024860152604485015260448452610a8e606485612b28565b8351908273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25af1610ab161345b565b81610bcc575b5080610bae575b15610b49575b506040518093819263414bf38960e01b8352600483016130d6565b03818573e592427a0aece92de3edee1f18e0157c058615645af18015610456578290610b15575b610b1291503390612ff3565b80f35b506020813d602011610b41575b81610b2f60209383612b28565b8101031261055257610b129051610b06565b3d9150610b22565b610ba890610b8e60405163095ea7b360e01b8682015273e592427a0aece92de3edee1f18e0157c05861564602482015287604482015260448152610b8e606482612b28565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2613304565b38610ac4565b5073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc23b1515610abe565b8051801592508215610be1575b505038610ab7565b610bf2925081018501908501612dd9565b3880610bd9565b90506020813d602011610c25575b81610c1460209383612b28565b810103126105525751610adf610a3a565b3d9150610c07565b81610c3791612b28565b610c4257833861097d565b8380fd5b309161092b565b63af458c0760e01b8352600483fd5b6335c33e8160e01b8352600483fd5b50346104535780600319360112610453576006546040516001600160a01b039091168152602090f35b5034610453578060031936011261045357600a546040516001600160a01b039091168152602090f35b5034610453576040366003190112610453576040610cd9612a6d565b91610ce2612a83565b9260018060a01b031681526001602052209060018060a01b03166000526020526020604060002054604051908152f35b50346104535780600319360112610453576020600c54604051908152f35b503461045357610d3f36612ac5565b9190610d49612db0565b600a5460ff8160a01c1615908115611093575b5061084257600b5460ff600e5460401c1690811561107f570492604051636eb1769f60e11b815230600482015260008051602061351c83398151915260248201526020816044816000805160206134fc8339815191525afa80156107df5785908590611049575b610dcd9250612b49565b838060405192602084019063095ea7b360e01b825260008051602061351c8339815191526024860152604485015260448452610e0a606485612b28565b835190826000805160206134fc8339815191525af1610e2761345b565b8161101a575b5080611002575b15610fbc575b5060405193610e4a606086612b28565b6002855260208501946040368737805115610fa8576000805160206134fc8339815191528652805160011015610fa85773e9a53c43a0b58706e67341c4055de861e29ee943604082015260008051602061351c8339815191523b15610fa45760405193635c11d79560e01b855260a48501926004860152602485015260a060448501525180915260c483019490845b818110610f8557505050818084958593306064840152608483015203818360008051602061351c8339815191525af1801561045657610f70575b505060105460ff811660ff8114610f5c57600160ff910116809160ff19161760105560ff600e5460401c1614610f465780f35b600a805460ff60a81b1916600160a81b17905580f35b634e487b7160e01b83526011600452602483fd5b81610f7a91612b28565b610453578038610f13565b82516001600160a01b0316875260209687019690920191600101610ed9565b8480fd5b634e487b7160e01b85526032600452602485fd5b610ffc906104c360405163095ea7b360e01b602082015260008051602061351c8339815191526024820152866044820152604481526104c3606482612b28565b38610e3a565b506000805160206134fc8339815191523b1515610e34565b805180159250821561102f575b505038610e2d565b6110429250602080918301019101612dd9565b3880611027565b50506020813d602011611077575b8161106460209383612b28565b810103126105525784610dcd9151610dc3565b3d9150611057565b634e487b7160e01b84526012600452602484fd5b60ff915060a81c1638610d5c565b503461045357602036600319011261045357600435600d544210156108515780156111bc57600a5460a01c60ff16156111b15760095461115790839081906001600160a01b03165b6040516323b872dd60e01b602082019081523360248301526001600160a01b03909216604482015260648082018790528152611126608482612b28565b5190826000805160206134fc8339815191525af161114261345b565b906000805160206134fc83398151915261349a565b8051908115159182611196575b505061117557610b12903390612ff3565b635274afe760e01b82526000805160206134fc833981519152600452602482fd5b6111a99250602080918301019101612dd9565b153880611164565b6111578280306110e9565b63af458c0760e01b8252600482fd5b50346104535760203660031901126104535760043560ff8116808203611229576111f3612db0565b8015610c4d576014106108425760ff600a5460a01c166108425760ff60401b600e549160401b169060ff60401b191617600e5580f35b8280fd5b503461045357604036600319011261045357611247612a83565b6008546001600160a01b0316330361126657610b129060043590612d51565b6282b42960e81b8252600482fd5b50346104535760603660031901126104535761128e612db0565b60ff600a5460a81c161580156116d9575b6116ca576040516370a0823160e01b815230600482015260208160248173e9a53c43a0b58706e67341c4055de861e29ee9435afa8015610456578290611697575b60039150046040516370a0823160e01b8152306004820152602081602481735c47902c8c80779cb99235e42c354e53f38c3b0d5afa90811561055f578391611665575b5061132d82612e5e565b604051636eb1769f60e11b815230600482015260008051602061351c8339815191526024820152602081604481735c47902c8c80779cb99235e42c354e53f38c3b0d5afa80156107df578290859061162f575b61138a9250612b49565b838060405192602084019063095ea7b360e01b825260008051602061351c83398151915260248601526044850152604484526113c7606485612b28565b83519082735c47902c8c80779cb99235e42c354e53f38c3b0d5af16113ea61345b565b81611600575b50806115e2575b1561159c575b5060405162e8e33760e81b815273e9a53c43a0b58706e67341c4055de861e29ee9436004820152735c47902c8c80779cb99235e42c354e53f38c3b0d6024820152826044820152816064820152600435608482015260243560a48201528360c482015260443560e4820152606081610104818760008051602061351c8339815191525af19283156107df5784918594611568575b5080821061152c575b50508082106114b7575b8261010061ff0019601054161760105580f35b61150b6114d26115259360018060a01b03600a541693612b6c565b60405163a9059cbb60e01b60208201526001600160a01b039093166024840152604483015281606481015b03601f198101835282612b28565b735c47902c8c80779cb99235e42c354e53f38c3b0d613304565b38806114a4565b6115476114d26115619360018060a01b03600a541693612b6c565b73e9a53c43a0b58706e67341c4055de861e29ee943613304565b388061149a565b90935061158d915060603d606011611595575b6115858183612b28565b810190612d36565b509238611491565b503d61157b565b6115dc9061150b60405163095ea7b360e01b602082015260008051602061351c83398151915260248201528660448201526044815261150b606482612b28565b386113fd565b50735c47902c8c80779cb99235e42c354e53f38c3b0d3b15156113f7565b8051801592508215611615575b5050386113f0565b6116289250602080918301019101612dd9565b388061160d565b50506020813d60201161165d575b8161164a60209383612b28565b81010312610552578161138a9151611380565b3d915061163d565b90506020813d60201161168f575b8161168060209383612b28565b81010312610552575138611323565b3d9150611673565b506020813d6020116116c2575b816116b160209383612b28565b8101031261055257600390516112e0565b3d91506116a4565b632b0039c760e21b8152600490fd5b5060ff60105460081c1661129f565b5034610453578060031936011261045357602060ff60105416604051908152f35b5034610453578060031936011261045357602060ff60105460081c166040519015158152f35b50346104535760403660031901126104535761175661174c612a6d565b6024359033612df1565b602060405160018152f35b50346104535780600319360112610453576040519080600454908160011c91600181168015611860575b60208410811461184c5783865290811561182557506001146117c8575b6117c4846117b881860382612b28565b60405191829182612a24565b0390f35b600481527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b939250905b80821061180b575090915081016020016117b8826117a8565b9192600181602092548385880101520191019092916117f2565b60ff191660208087019190915292151560051b850190920192506117b891508390506117a8565b634e487b7160e01b83526022600452602483fd5b92607f169261178b565b50346104535780600319360112610453576005546040516001600160a01b039091168152602090f35b503461045357806003193601126104535760206001600160401b03600e5416604051908152f35b5034610453576060366003190112610453576118d4612a6d565b906118dd612aaf565b6044356001600160401b03811690818103610c4257906001600160401b03919082600e5416809111611b6c575b5016916001600160401b03821683036001600160401b038111611b58576001600160401b0390949194169261194761194185612c75565b94612ca7565b926001600160a01b039092169185905b6001600160401b03811683811015611a2b57808852600f60205260408820856040519161198383612adb565b60018154916001600160401b03828060a01b0384169384875260a01c16602086015201546040840152146119c5575b50506001016001600160401b0316611957565b6001600160401b0384166001600160401b038114611a17576001926001600160401b0394928585611a1094019716916119fe838d612d0c565b52611a09828b612d0c565b5288612d0c565b50916119b2565b634e487b7160e01b8a52601160045260248afd5b876001600160401b0384168888611a4183612c75565b611a4a84612ca7565b92855b6001600160401b03811686811015611aa3576001600160401b0391611a9b8284611a7960019588612d0c565b5116611a858289612d0c565b52611a908189612d0c565b51611a09828b612d0c565b500116611a4d565b87848760405192839260408401604085528151809152602060608601920190835b818110611b36575050508381036020850152602080845192838152019301915b818110611af2575050500390f35b825180516001600160a01b031685526020818101516001600160401b0316818701526040918201519186019190915286955060609094019390920191600101611ae4565b82516001600160401b0316845287965060209384019390920191600101611ac4565b634e487b7160e01b82526011600452602482fd5b90503861190a565b5034610453578060031936011261045357602060ff600e5460401c16604051908152f35b503461045357608036600319011261045357611bb2612a6d565b90611bbb612a83565b6044356001600160a01b038116939091848303610c42576064356001600160a01b0381169590869003610fa457611bf0612db0565b600854956001600160a01b038716611d53576001600160a01b038416918215611d44576001600160a01b0384168015611d35578115611d35578215611d35578388996001600160601b0360a01b16176008556001600160601b0360a01b60075416176007556001600160601b0360a01b60095416176009556001600160601b0360a01b600a541617600a55803b15610fa45760405163243dcf4f60e21b81526001600160a01b039283166004820152918416602483015284908290604490829084905af19081156107df578491611d1c575b50506007546001600160a01b031691823b15611d175760405163243dcf4f60e21b81526001600160a01b039283166004820152911660248201529082908290604490829084905af18015610456576104425750f35b505050fd5b81611d2691612b28565b611d31578238611cc2565b5050fd5b63d92e233d60e01b8852600488fd5b63d92e233d60e01b8752600487fd5b632b0039c760e21b8652600486fd5b5034610453578060031936011261045357600654336001600160a01b0390911603611dd757600680546001600160a01b0319908116909155600580543392811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b63118cdaa760e01b815233600452602490fd5b5034610453578060031936011261045357611e03612db0565b600680546001600160a01b031990811690915560058054918216905581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5034610453576020366003190112610453576020906040906001600160a01b03611e79612a6d565b1681528083522054604051908152f35b50346104535780600319360112610453576020600d546040519042108152f35b5034610453578060031936011261045357602060ff600a5460a01c166040519015158152f35b5034610453578060031936011261045357602060ff600a5460b01c166040519015158152f35b503461045357602036600319011261045357600435611f1681600c54612b49565b600c553315611f9457600a5460b01c60ff16611f89573033148015611f81575b15611f4657610b12908233613372565b60405162461bcd60e51b8152602060048201526013602482015272151c98591a5b99c81a5cc8191a5cd8589b1959606a1b6044820152606490fd5b506000611f36565b610b12908233613372565b634b637e8f60e11b82526004829052602482fd5b5034610453578060031936011261045357610b12612b88565b50346104535780600319360112610453576008546040516001600160a01b039091168152602090f35b50346104535780600319360112610453576020600b54604051908152f35b5034610453578060031936011261045357602060405160128152f35b50346104535760403660031901126104535761203e612a99565b612046612aaf565b9180916001600160401b03600e5416806001600160401b03861611612102575b505b6001600160401b0381166001600160401b0385168110156120f7578252600f6020526040808320815161209a81612adb565b60018254926001600160401b03828060a01b0385169485855260a01c166020840152015492839101526120da575b506001016001600160401b0316612068565b6120ef6001916001600160401b039395612b49565b9391506120c8565b602084604051908152f35b935038612066565b5034610453578060031936011261045357612123612db0565b6008546001600160a01b03169081158015612215575b6116ca576224ea00420191824211611b5857828293600d55813b15611d3157829160248392604051958693849263f1bf9a3760e01b845260048401525af18015612208576121f8575b6007549091506001600160a01b0316803b156104615781809160046040518094819363e8148a3760e01b83525af18015610456576121e3575b50807f452a344f03203071e1daf66e007976c85cb2380deabf1c91f3c4fb1fca41204991a180f35b816121ed91612b28565b6104535780386121bb565b61220191612b28565b3881612182565b50604051903d90823e3d90fd5b50600d541515612139565b50346104535760603660031901126104535761223a612a6d565b612242612a83565b6001600160a01b03821680845260016020818152604080872033885290915285205460443594929091820161227e575b50506117569350612df1565b8482106122e55780156122d15733156122bd5760408686926117569852600160205281812060018060a01b033316825260205220910390553880612272565b634a1406b160e11b86526004869052602486fd5b63e602df0560e01b86526004869052602486fd5b6064868684637dc7a0d960e11b835233600452602452604452fd5b50346104535780600319360112610453576020600d54604051908152f35b5034610453578060031936011261045357612337612db0565b60ff60105460081c161580156126f4575b6116ca5761235c600b546003810490612b6c565b6040516370a0823160e01b8152306004820152829060208160248173e9a53c43a0b58706e67341c4055de861e29ee9435afa9081156104565782916126c2575b506123a5613153565b9190156124b0576020906123bd6123ed949584612d51565b60405163a9059cbb60e01b81526001600160a01b0384166004820152602481019190915292839081906044820190565b03818673e9a53c43a0b58706e67341c4055de861e29ee9435af191821561055f57602092612485575b506040516335313c2160e11b81526004810184905292839160249183916001600160a01b03165af1801561045657612466575b505b600a805460ff60b01b1916600160b01b179055610b12612b88565b61247e9060203d602011610714576107058183612b28565b5038612449565b6124a490833d85116124a9575b61249c8183612b28565b810190612dd9565b612416565b503d612492565b9150506124bd8230612d51565b604051636eb1769f60e11b815230600482015260008051602061351c8339815191526024820152602081604481305afa80156107df578390859061268c575b6125069250612b49565b838060405192602084019063095ea7b360e01b825260008051602061351c8339815191526024860152604485015260448452612543606485612b28565b83519082305af161255261345b565b8161265d575b5080612653575b15612607575b5061256f81612e5e565b6040519162e8e33760e81b835230600484015273e9a53c43a0b58706e67341c4055de861e29ee9436024840152806044840152816064840152608483015260a48201528160c48201524260e4820152606081610104818560008051602061351c8339815191525af18015610456576125e8575b5061244b565b6126009060603d606011611595576115858183612b28565b50506125e2565b61264d9061264760405163095ea7b360e01b602082015260008051602061351c833981519152602482015286604482015260448152612647606482612b28565b30613304565b38612565565b50303b151561255f565b8051801592508215612672575b505038612558565b6126859250602080918301019101612dd9565b388061266a565b50506020813d6020116126ba575b816126a760209383612b28565b81010312610c42578261250691516124fc565b3d915061269a565b90506020813d6020116126ec575b816126dd60209383612b28565b8101031261047957513861239c565b3d91506126d0565b5060ff600a5460b01c16612348565b50346104535780600319360112610453576020600254604051908152f35b50346104535780600319360112610453576009546040516001600160a01b039091168152602090f35b50346104535760203660031901126104535760406060916001600160401b03612771612a99565b168152600f60205220600181549101546001600160401b036040519260018060a01b038116845260a01c1660208301526040820152f35b5034610453576020366003190112610453576001600160401b036127ca612a99565b168152600f602052604081208054336001600160a01b03821603612833576001600160401b039060a01c166202a3008101809111610f5c5742106128245780546001600160a01b031916815560010154610b129033612d51565b63b0782df760e01b8252600482fd5b6282b42960e81b8352600483fd5b50346104535760403660031901126104535761285b612a6d565b6024359033156128d7576001600160a01b03169182156128c35760408291338152600160205281812085825260205220556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b634a1406b160e11b81526004819052602490fd5b63e602df0560e01b83526004839052602483fd5b50346104535780600319360112610453576040519080600354908160011c9160018116801561299e575b60208410811461184c578386529081156118255750600114612941576117c4846117b881860382612b28565b600381527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b939250905b808210612984575090915081016020016117b8826117a8565b91926001816020925483858801015201910190929161296b565b92607f1692612915565b50346104535760203660031901126104535760043563ffffffff60e01b8116809103610479576020906301ffc9a760e01b81149081156129ee575b506040519015158152f35b6336372b0760e01b149050826129e3565b9050346104795781600319360112610479576007546001600160a01b03168152602090f35b91909160208152825180602083015260005b818110612a57575060409293506000838284010152601f8019910116010190565b8060208092870101516040828601015201612a36565b600435906001600160a01b038216820361055257565b602435906001600160a01b038216820361055257565b600435906001600160401b038216820361055257565b602435906001600160401b038216820361055257565b6040906003190112610552576004359060243590565b606081019081106001600160401b03821117612af657604052565b634e487b7160e01b600052604160045260246000fd5b61010081019081106001600160401b03821117612af657604052565b90601f801991011681019081106001600160401b03821117612af657604052565b91908201809211612b5657565b634e487b7160e01b600052601160045260246000fd5b91908203918211612b5657565b90816020910312610552575190565b60ff600a5460b01c1615612c4d576040516370a0823160e01b81523060048201526020816024816000805160206134fc8339815191525afa8015612c4157600090612c0d575b60095460405163a9059cbb60e01b60208201526001600160a01b0390911660248201526044810191909152612c0b91506104c381606481016114fd565b565b506020813d602011612c39575b81612c2760209383612b28565b8101031261055257612c0b9051612bce565b3d9150612c1a565b6040513d6000823e3d90fd5b632b0039c760e21b60005260046000fd5b6001600160401b038111612af65760051b60200190565b90612c7f82612c5e565b612c8c6040519182612b28565b8281528092612c9d601f1991612c5e565b0190602036910137565b90612cb182612c5e565b612cbe6040519182612b28565b8281528092612ccf601f1991612c5e565b019060005b828110612ce057505050565b602090604051612cef81612adb565b600081526000838201526000604082015282828501015201612cd4565b8051821015612d205760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b90816060910312610552578051916040602083015192015190565b906001600160a01b03821615612d9a57600a5460b01c60ff16612d8f5730158015612d87575b15611f4657612c0b916000613372565b506001612d77565b612c0b916000613372565b63ec442f0560e01b600052600060045260246000fd5b6005546001600160a01b03163303612dc457565b63118cdaa760e01b6000523360045260246000fd5b90816020910312610552575180151581036105525790565b91906001600160a01b0383168015612e48576001600160a01b03821615612d9a57600a5460b01c60ff16612e3e5730148015612e36575b15611f4657612c0b92613372565b506000612e28565b50612c0b92613372565b634b637e8f60e11b600052600060045260246000fd5b604051636eb1769f60e11b815230600482015260008051602061351c83398151915260248201529060208260448173e9a53c43a0b58706e67341c4055de861e29ee9435afa8015612c4157600090612fbf575b612ebb9250612b49565b60008060405192602084019063095ea7b360e01b825260008051602061351c8339815191526024860152604485015260448452612ef9606485612b28565b8351908273e9a53c43a0b58706e67341c4055de861e29ee9435af1612f1c61345b565b81612f90575b5080612f72575b15612f315750565b612c0b9061154760405163095ea7b360e01b602082015260008051602061351c83398151915260248201526000604482015260448152611547606482612b28565b5073e9a53c43a0b58706e67341c4055de861e29ee9433b1515612f29565b8051801592508215612fa5575b505038612f22565b612fb89250602080918301019101612dd9565b3880612f9d565b506020823d602011612feb575b81612fd960209383612b28565b8101031261055257612ebb9151612eb1565b3d9150612fcc565b9060016040519161300383612adb565b818060a01b031692838352602083016001600160401b0342168152604084019182526001600160401b03600e5416600052600f602052604060002093838060a01b039051166001600160601b0360a01b855416178455518354906001600160401b0360a01b9060a01b16906001600160401b0360a01b1916178355519101556001600160401b036001600e54927ff41fc64ac2e44a186b5759e6bef6e465e623a8c3611b6ee6fb92a347589656446040848616928151908152836020820152a10116906001600160401b03191617600e55565b81516001600160a01b03908116825260208084015182169083015260408084015162ffffff16908301526060808401518216908301526080808401519083015260a0808401519083015260c0808401519083015260e09283015116918101919091526101000190565b51906001600160701b038216820361055257565b60405163e6a4390560e01b815230600482015273e9a53c43a0b58706e67341c4055de861e29ee943602482015290602082604481735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f5afa918215612c415760009081936132c0575b506001600160a01b03831680156132bb57803b156104795760405160016209351760e01b03198152828160048183865af1801561055f576132a3575b50606060049160405192838092630240bc6b60e21b82525afa9081156104565782908392613244575b506001600160701b03168061323d57506001600160701b03168061323757509190565b90509190565b9150509190565b9150506060813d60601161329b575b8161326060609383612b28565b81010312610479576132718161313f565b604061327f6020840161313f565b92015163ffffffff811603611229576001600160701b03613214565b3d9150613253565b826132b360049394606093612b28565b9291506131eb565b509190565b9092506020813d6020116132fc575b816132dc60209383612b28565b8101031261122957516001600160a01b03811681036112295791386131af565b3d91506132cf565b60008061332d9260018060a01b03169360208151910182865af161332661345b565b908361349a565b8051908115159182613357575b50506133435750565b635274afe760e01b60005260045260246000fd5b61336a9250602080918301019101612dd9565b15388061333a565b6001600160a01b031690816133ee5760207fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef916133b185600254612b49565b6002555b6001600160a01b031693846133d65780600254036002555b604051908152a3565b846000526000825260406000208181540190556133cd565b81600052600060205260406000205483811061343e577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91846020928560005260008452036040600020556133b5565b91905063391434e360e21b60005260045260245260445260646000fd5b3d15613495573d906001600160401b038211612af65760405191613489601f8201601f191660200184612b28565b82523d6000602084013e565b606090565b906134c057508051156134af57805190602001fd5b630a12f52160e11b60005260046000fd5b815115806134f2575b6134d1575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b156134c956fe000000000000000000000000f19308f923582a6f7c465e5ce7a9dc1bec6665b10000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488da26469706673582212205462dabd05af124a5b46ef13482b6b88cccc0dfd0ddb26897b1f3cc19bdd464864736f6c634300081a0033

Verified Source Code Full Match

Compiler: v0.8.26+commit.8a97fa7a EVM: paris Optimization: Yes (200 runs)
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);
    }
}
Ownable2Step.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

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

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

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}
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);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

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

pragma solidity ^0.8.20;

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

pragma solidity ^0.8.20;

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

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

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

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

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

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

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

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

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

        emit Transfer(from, to, value);
    }

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
IERC20Permit.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
        external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success,) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(address target, bool success, bytes memory returndata)
        internal
        view
        returns (bytes memory)
    {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
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;
    }
}
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);
}
EnumerableSet.sol 378 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position is the index of the value in the `values` array plus 1.
        // Position 0 is used to mean a value is not in the set.
        mapping(bytes32 value => uint256) _positions;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._positions[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

            if (valueIndex != lastIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._positions[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}
IUniswapV2Factory.sol 17 lines
pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint256);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint256) external view returns (address pair);
    function allPairsLength() external view returns (uint256);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}
IUniswapV2Pair.sol 53 lines
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Transfer(address indexed from, address indexed to, uint256 value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint256);
    function balanceOf(address owner) external view returns (uint256);
    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 value) external returns (bool);
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint256);

    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
        external;

    event Mint(address indexed sender, uint256 amount0, uint256 amount1);
    event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint256 amount0In,
        uint256 amount1In,
        uint256 amount0Out,
        uint256 amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint256);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint256);
    function price1CumulativeLast() external view returns (uint256);
    function kLast() external view returns (uint256);

    function mint(address to) external returns (uint256 liquidity);
    function burn(address to) external returns (uint256 amount0, uint256 amount1);
    function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
IUniswapV2Router01.sol 121 lines
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);
    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountA, uint256 amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountToken, uint256 amountETH);
    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
    function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline)
        external
        payable
        returns (uint256[] memory amounts);
    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
    function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline)
        external
        payable
        returns (uint256[] memory amounts);

    function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);
    function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
        external
        pure
        returns (uint256 amountOut);
    function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut)
        external
        pure
        returns (uint256 amountIn);
    function getAmountsOut(uint256 amountIn, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);
    function getAmountsIn(uint256 amountOut, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);
}
IUniswapV2Router02.sol 47 lines
pragma solidity >=0.6.2;

import "./IUniswapV2Router01.sol";

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
}
IUniswapV3SwapCallback.sol 17 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external;
}
ISwapRouter.sol 67 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol";

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
IStaxNFT.sol 14 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

interface IStaxNFT {
    function startMint(uint256 _presaleEnd) external;
    function setDirectTransfer() external;
    function setProtocolAddresses(address _vault, address _bank) external;
    function updateCycle() external returns (uint32 cycle, uint256 totalMultipliers);
    function getPackedTokenData(uint256 tokenId, address account) external view returns (uint256, uint32);
    function batchGetPackedTokenData(uint256[] memory tokenIds, address account)
        external
        view
        returns (uint256[] memory data, uint32);
}
IStaxVault.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

interface IStaxVault {
    function setProtocolAddresses(address _staxNft, address _staxBank) external;
    function handleStartPresale() external;
}
ITitanOnBurn.sol 6 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface ITitanOnBurn {
    function onBurn(address user, uint256 amount) external;
}
ITITANX.sol 42 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface ITITANX is IERC20 {
    enum StakeStatus {
        ACTIVE,
        ENDED,
        BURNED
    }

    struct UserStakeInfo {
        uint152 titanAmount;
        uint128 shares;
        uint16 numOfDays;
        uint48 stakeStartTs;
        uint48 maturityTs;
        StakeStatus status;
    }

    struct UserStake {
        uint256 sId;
        uint256 globalStakeId;
        UserStakeInfo stakeInfo;
    }

    function startStake(uint256 amount, uint256 numOfDays) external;
    function endStake(uint256 id) external;
    function claimUserAvailableETHPayouts() external;
    function burnTokensToPayAddress(
        address user,
        uint256 amount,
        uint256 userRebatePercentage,
        uint256 rewardPaybackPercentage,
        address rewardPaybackAddress
    ) external;
    function getUserStakeInfo(address user, uint256 id) external view returns (UserStakeInfo memory);
    function getUserETHClaimableTotal(address user) external view returns (uint256 reward);
    function getUserStakes(address user) external view returns (UserStake[] memory);
    function triggerPayouts() external;
}
IWETH9.sol 13 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/interfaces/IERC20.sol";

/// @title Interface for WETH9
interface IWETH9 is IERC20 {
    /// @notice Deposit ether to get wrapped ether
    function deposit() external payable;

    /// @notice Withdraw wrapped ether to get ether
    function withdraw(uint256) external;
}
IX28.sol 9 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/interfaces/IERC20.sol";

interface IX28 is IERC20 {
    function mintX28withTitanX(uint256 amount) external;
    function decimals() external view returns (uint256);
}
constants.sol 89 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import "../interfaces/ITitanOnBurn.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";

// ===================== Contract Addresses =====================================

address constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address constant TITANX = 0xF19308F923582A6f7c465e5CE7a9Dc1BEC6665B1;
address constant X28 = 0x5c47902c8C80779CB99235E42C354E53F38C3B0d;
address constant HYPER = 0xE2cfD7a01ec63875cd9Da6C7c1B7025166c2fA2F;
address constant HELIOS = 0x2614f29C39dE46468A921Fd0b41fdd99A01f2EDf;
address constant BLAZE = 0xfcd7cceE4071aA4ecFAC1683b7CC0aFeCAF42A36;
address constant FLUX = 0xBFDE5ac4f5Adb419A931a5bF64B0f3BB5a623d06;
address constant E280 = 0xe9A53C43a0B58706e67341C4055de861e29Ee943;

address constant BLAZE_STAKING = 0xBc0043bc5b0c394D9d05d49768f9548F8CF9587b;
address constant FLUX_STAKING = 0xd605a87187563C94c577a6E57e4a36eC8433B9aE;

address constant TITANX_WETH_POOL = 0xc45A81BC23A64eA556ab4CdF08A86B61cdcEEA8b;
address constant TITANX_X28_POOL = 0x99f60479da6A49D55eBA34893958cdAACc710eE9;
address constant TITANX_HYPER_POOL = 0x14d725edB1299fF560d96f42462f0234B65B00AF;
address constant TITANX_HELIOS_POOL = 0x2C83C54C5612BfD62a78124D4A0eA001278a689c;
address constant INFERNO = 0x00F116ac0c304C570daAA68FA6c30a86A04B5C5F;
address constant TITANX_INFERNO_POOL = 0x1E90B67149e688DfB95fD73Acacd8ADefd16d88D;
address constant INFERNO_FLUX_POOL = 0x09848D115e085942E6fa9D85b6B6C73fb0E63CB1;


// ===================== MINT ===================================================

uint256 constant PRESALE_LENGTH = 28 days;
uint256 constant COOLDOWN_PERIOD = 48 hours;
uint256 constant LP_POOL_SIZE = 200_000_000_000 ether;

uint8 constant PERCENTAGE_BASE = 100;
uint16 constant BPS_BASE = 100_00;

uint256 constant COMMON_BASE_PRICE = 100_000_000 ether;
uint256 constant RARE_BASE_PRICE = 1_000_000_000 ether;
uint256 constant LEGENDARY_BASE_PRICE = 10_000_000_000 ether;

uint16 constant COMMON_BASE_MULTIPLIER = 10;
uint16 constant RARE_BASE_MULTIPLIER = 100;
uint16 constant LEGENDARY_BASE_MULTIPLIER = 1000;

// ===================== NFT ===================================================

uint8 constant NFT_CLAIM_COOLDOWN = 2;
uint256 constant BITPOS_NFT_TIER = 0;
uint256 constant BITMASK_NFT_TIER = (1 << 8) - 1;

uint256 constant BITPOS_MULTIPLIER = 8;
uint256 constant BITMASK_MULTIPLIER = (1 << 16) - 1;

uint256 constant BITPOS_MINT_CYCLE = 24;
uint256 constant BITMASK_MINT_CYCLE = (1 << 32) - 1;

uint256 constant BITPOS_BURN_CYCLE = 56;
uint256 constant BITMASK_BURN_CYCLE = (1 << 32) - 1;

uint256 constant BITPOS_BURN_ADDRESS = 88;
uint256 constant BITMASK_BURN_ADDRESS = (1 << 160) - 1;

// ===================== VAULT ==================================================

uint256 constant CYCLE_COOLDOWN = 9 days;

uint16 constant BANK_ALLOCATION_BPS = 80_00;
uint64 constant GENESIS_BASE_BPS = 8_00 * uint64(BPS_BASE);
uint64 constant HOLDER_BASE_BPS = 10_00 * uint64(BPS_BASE);
uint64 constant DIANOND_BASE_BPS = 2_00 * uint64(BPS_BASE);
uint16 constant DIAMOND_HAND_PAYOUT_BPS = 8_00;
uint16 constant CYCLE_COMPOUND_REDUCTION = 2_00;

// ===================== UNISWAP Interface ======================================

address constant UNISWAP_V2_FACTORY = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
address constant UNISWAP_V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address constant UNISWAP_V3_ROUTER = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
uint24 constant POOL_FEE_1PERCENT = 10000;

// ===================== Interface IDs ==========================================

bytes4 constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
bytes4 constant INTERFACE_ID_ERC20 = type(IERC20).interfaceId;
bytes4 constant INTERFACE_ID_ERC721 = 0x80ac58cd;
bytes4 constant INTERFACE_ID_ERC721Metadata = 0x5b5e139f;
bytes4 constant INTERFACE_ID_ITITANONBURN = type(ITitanOnBurn).interfaceId;
Stax.sol 428 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC165.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "./interfaces/IStaxNFT.sol";
import "./interfaces/IStaxVault.sol";
import "./interfaces/ITITANX.sol";
import "./interfaces/IX28.sol";
import "./interfaces/IWETH9.sol";
import "./lib/constants.sol";

/// @title Stax Token Contract
contract Stax is ERC20, Ownable2Step, IERC165 {
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.UintSet;

    // -------------------------- STATE VARIABLES -------------------------- //

    struct UserPurchase {
        address account;
        uint64 timestamp;
        uint256 amount;
    }

    address public STAX_VAULT;
    address public STAX_NFT;
    address public STAX_BANK;
    address public STAX_BUY_BURN;

    /// @notice Purchases of ELMNT/X28 tokens are in progress
    bool public lpPurchaseStarted;

    /// @notice Purchases of ELMNT/X28 tokens are done
    bool public lpPurchaseFinished;

    /// @notice Trading is disabled until LP is created. Enables automatically.
    bool public tradingEnabled;

    /// @notice TitanX tokens designated for ELMNT/X28 token purchases.
    uint256 public lpPool;

    /// @notice Total STX tokens burned to date.
    uint256 public totalBurned;

    /// @notice Timestamp in seconds of the presale end date.
    uint256 public presaleEnd;
    
    /// @notice Next Purchae ID to be used.
    uint64 public currentPurchaseId;

    /// @notice Number of purchases required for TitanX/ELMNT swaps.
    /// @dev Can only be changed before the LP purchases start.
    uint8 public purchasesRequired = 15;

    /// @notice Purchase information for a specific purchase ID.
    /// @return account Address of the owner wallet.
    /// @return timestamp The time when the purchase was made (as a Unix timestamp).
    /// @return amount The amount of Stax toknes of the purchase.
    mapping(uint64 purchaseId => UserPurchase) public purchases;

    /// @notice Total number of purchases for TitanX/ELMNT swaps.
    uint8 public lpPurchasesMade;
    /// @notice Is ELMNT liquidity added.
    bool public e280LiquidityAdded;

    // ------------------------------- EVENTS ------------------------------ //

    event MintStarted();
    event Purchase(address account, uint64 purchaseId);

    // ------------------------------- ERRORS ------------------------------ //

    error PresaleInactive();
    error PresaleInProgress();
    error ZeroAddress();
    error ZeroInput();
    error Prohibited();
    error Unauthorized();
    error Cooldown();

    // ------------------------------ MODIFIERS ---------------------------- //

    modifier onlyPresale() {
        if (!isPresaleActive()) revert PresaleInactive();
        _;
    }

    modifier onlyNft() {
        if (msg.sender != STAX_NFT) revert Unauthorized();
        _;
    }

    // ----------------------------- CONSTRUCTOR --------------------------- //

    constructor(address _owner) ERC20("Stax", "STAX") Ownable(_owner) {}

    // --------------------------- PUBLIC FUNCTIONS ------------------------ //

    /// @notice Allows users to purchase tokens during the presale using TitanX tokens.
    /// @param amount The amount of TitanX tokens to spend.
    function purchaseWithTitanX(uint256 amount) external onlyPresale {
        if (amount == 0) revert ZeroInput();
        address receiver = lpPurchaseStarted ? STAX_BANK : address(this);
        IERC20(TITANX).safeTransferFrom(msg.sender, receiver, amount);
        _writePurchaseData(amount, msg.sender);
    }

    /// @notice Allows users to purchase tokens during the presale using ETH.
    /// @param minAmount The minimum amount of Stax tokens to purchase.
    /// @param deadline Deadline for executing the swap.
    function purchaseWithETH(uint256 minAmount, uint256 deadline) external payable onlyPresale {
        if (minAmount == 0) revert ZeroInput();
        address receiver = lpPurchaseStarted ? STAX_BANK : address(this);
        uint256 swappedAmount = _swapETHForTitanX(minAmount, deadline, receiver);
        _writePurchaseData(swappedAmount, msg.sender);
    }

    /// @notice Allows users to claim their purchased tokens after the cooldown period.
    /// @param purchaseId The ID of the purchase to claim.
    function claimPurchase(uint64 purchaseId) external {
        UserPurchase storage purchase = purchases[purchaseId];
        if (purchase.account != msg.sender) revert Unauthorized();
        if (block.timestamp < purchase.timestamp + COOLDOWN_PERIOD) revert Cooldown();
        purchase.account = address(0);
        _mint(msg.sender, purchase.amount);
    }

    /// @notice Handles the claim of the NFT Backing.
    /// @param amount The amount to claim.
    /// @param receiver The address to receive the claimed amount.
    /// @dev This function is only callable by the NFT contract.
    function handleBackingClaim(uint256 amount, address receiver) external onlyNft {
        _mint(receiver, amount);
    }

    /// @notice Transfers TitanX allocation to Stax Bank contract.
    /// @dev Can only be called when there is an allocation for buy and burn.
    function distributeStaxBank() public {
        if (!tradingEnabled) revert Prohibited();
        IERC20 titanX = IERC20(TITANX);
        uint256 allocation = titanX.balanceOf(address(this));
        titanX.safeTransfer(STAX_BANK, allocation);
    }

    /// @notice Burns the specified amount of tokens from the user's balance.
    /// @param value The amount of tokens in wei.
    function burn(uint256 value) public virtual {
        totalBurned += value;
        _burn(msg.sender, value);
    }

    // --------------------- PRESALE MANAGEMENT FUNCTIONS ------------------ //

    /// @notice Starts the presale for the token.
    function startMint() external onlyOwner {
        if (STAX_NFT == address(0) || presaleEnd != 0) revert Prohibited();
        presaleEnd = block.timestamp + PRESALE_LENGTH;
        IStaxNFT(STAX_NFT).startMint(presaleEnd);
        IStaxVault(STAX_VAULT).handleStartPresale();
        emit MintStarted();
    }

    /// @notice Begins the liquidity pool creation process after the presale has either ended or accumulated more than 200B TitanX.
    /// @param x28NativeMint Should X28 be minted. Otherwise a market buy will be performed.
    /// @param minAmountOutX28 Minimum X28 amount to receive from market buy (if applicable).
    /// @param deadline Deadline to perform a market buy (if applicable).
    /// @dev Also transforms TitanX to X28.
    function startLpPurchases(bool x28NativeMint, uint256 minAmountOutX28, uint256 deadline) external onlyOwner {
        if (presaleEnd == 0) revert PresaleInactive();
        if (lpPurchaseStarted) revert Prohibited();
        uint256 availableBalance = IERC20(TITANX).balanceOf(address(this));
        if (availableBalance < LP_POOL_SIZE) {
            if (block.timestamp < presaleEnd) revert PresaleInProgress();
            lpPool = availableBalance;
        } else {
            lpPool = LP_POOL_SIZE;
        }
        uint256 x28Share = lpPool / 4;
        if (x28NativeMint) {
            IERC20(TITANX).safeIncreaseAllowance(X28, x28Share);
            IX28(X28).mintX28withTitanX(x28Share);
        } else {
            _swapTitanXToX28(x28Share, minAmountOutX28, deadline);
        }
        lpPool -= x28Share;
        lpPurchaseStarted = true;
        IStaxNFT(STAX_NFT).setDirectTransfer();
    }

    /// @notice Executes TitanX -> Element 280 swap for future LP creation.
    /// @param minAmountOut Minimum amout to be received after swap.
    /// @param deadline Deadline for executing the swap.
    /// @dev Can only be called by the contract owner during the LP purchase phase.
    function purchaseTokenForLP(uint256 minAmountOut, uint256 deadline) external onlyOwner {
        if (!lpPurchaseStarted || lpPurchaseFinished) revert Prohibited();
        uint256 amount = lpPool / purchasesRequired;
        _swapTitanXtoElmnt(amount, minAmountOut, deadline);
        lpPurchasesMade++;
        if (lpPurchasesMade == purchasesRequired) lpPurchaseFinished = true;
    }

    /// @notice Adds liquidity to X28/E280 LP.
    /// @dev Can only be called by the contract owner after the LP phase has completed.
    function addE280Liquidity(uint256 minE280Amount, uint256 minX28Amount, uint256 deadline) external onlyOwner {
        if (!lpPurchaseFinished || e280LiquidityAdded) revert Prohibited();
        uint256 e280Amount = IERC20(E280).balanceOf(address(this)) / 3;
        uint256 x28Amount = IERC20(X28).balanceOf(address(this));

        IERC20(E280).safeIncreaseAllowance(UNISWAP_V2_ROUTER, e280Amount);
        IERC20(X28).safeIncreaseAllowance(UNISWAP_V2_ROUTER, x28Amount);

        (uint256 usedE280, uint256 usedX28,) = IUniswapV2Router02(UNISWAP_V2_ROUTER).addLiquidity(
            E280, X28, e280Amount, x28Amount, minE280Amount, minX28Amount, address(0), deadline
        );

        if (usedE280 < e280Amount) IERC20(E280).safeTransfer(STAX_BUY_BURN, e280Amount - usedE280);
        if (usedX28 < x28Amount) IERC20(X28).safeTransfer(STAX_BUY_BURN, x28Amount - usedX28);
        e280LiquidityAdded = true;
    }

    /// @notice Deploys the ELMNT/STAX liquidity pool.
    /// @dev Can only be called by the contract owner after the LP phase has completed.
    function deployStaxLP() external onlyOwner {
        if (!e280LiquidityAdded || tradingEnabled) revert Prohibited();
        uint256 staxAmount = lpPool - lpPool / 3;
        uint256 e280Amount = IERC20(E280).balanceOf(address(this));
        _deployStaxLiqudityPool(staxAmount, e280Amount);
        _enableTrading();
        distributeStaxBank();
    }

    // ----------------------- ADMINISTRATIVE FUNCTIONS -------------------- //

    /// @notice Sets the required addresses for the Stax protocol.
    /// @param _staxNft The address of the Stax NFT contract.
    /// @param _staxVault The address of the Stax Vault contract.
    /// @param _staxBank The address of the Stax Bank contract.
    /// @param _staxBuyBurn The address of the Stax Buy & Burn contract.
    /// @dev Can only be set once and can only be called by the owner.
    function setProtocolAddresses(address _staxNft, address _staxVault, address _staxBank, address _staxBuyBurn)
        external
        onlyOwner
    {
        if (STAX_NFT != address(0)) revert Prohibited();
        if (_staxNft == address(0)) revert ZeroAddress();
        if (_staxVault == address(0)) revert ZeroAddress();
        if (_staxBank == address(0)) revert ZeroAddress();
        if (_staxBuyBurn == address(0)) revert ZeroAddress();
        STAX_NFT = _staxNft;
        STAX_VAULT = _staxVault;
        STAX_BANK = _staxBank;
        STAX_BUY_BURN = _staxBuyBurn;
        IStaxNFT(STAX_NFT).setProtocolAddresses(_staxVault, _staxBank);
        IStaxVault(STAX_VAULT).setProtocolAddresses(_staxNft, _staxBank);
    }

    /// @notice Sets the amount of purchases for tokens.
    /// @param amount Number of purchases needed for ELMNT token.
    /// @dev Can only be called by the owner before LP purchases start.
    function setPurchasesRequired(uint8 amount) external onlyOwner {
        if (amount == 0) revert ZeroInput();
        if (amount > 20) revert Prohibited();
        if (lpPurchaseStarted) revert Prohibited();
        purchasesRequired = amount;
    }

    // ---------------------------- VIEW FUNCTIONS ------------------------- //

    /// @notice Checks if the presale is currently active.
    /// @return A boolean indicating whether the presale is still active.
    function isPresaleActive() public view returns (bool) {
        return presaleEnd > block.timestamp;
    }

    /// @notice Returns purchase information made by a specific account.
    /// @param account The address of the account.
    /// @param start Purchase ID to start with.
    /// @param end Purchase ID to stop at (not included).
    /// @return purchaseIds An array of Purchase IDs of the account.
    /// @return userPuchases An array of Purchases of the account.
    /// @dev Should not be called by contracts.
    function purchasesOf(address account, uint64 start, uint64 end) external view returns (uint64[] memory purchaseIds, UserPurchase[] memory userPuchases) {
        if (end > currentPurchaseId) end = currentPurchaseId;
        uint256 length = end - start;
        uint64[] memory _purchaseIds = new uint64[](length);
        UserPurchase[] memory _purchases = new UserPurchase[](length);
        uint64 counter;
        for (uint64 i = start; i < end; i++) {
            UserPurchase memory purchase = purchases[i];
            if (purchase.account == account) {
                uint64 index = counter++;
                _purchaseIds[index] = i;
                _purchases[index] = purchase;
            }
        }
        purchaseIds = new uint64[](counter);
        userPuchases = new UserPurchase[](counter);
        for (uint64 i = 0; i < counter; i++) {
            purchaseIds[i] = _purchaseIds[i];
            userPuchases[i] = _purchases[i];
        }
    }

    /// @notice Returns the sum of the unclaimed Stax tokens.
    /// @param start Purchase ID to start with.
    /// @param end Purchase ID to stop at (not included).
    /// @return total Total sum of unclaimed Stax tokens.
    /// @dev Should not be called by contracts.
    function getUnclaimedTokenAmount(uint64 start, uint64 end) external view returns (uint256 total) {
        if (end > currentPurchaseId) end = currentPurchaseId;
        for (uint64 i = start; i < end; i++) {
            UserPurchase memory purchase = purchases[i];
            if (purchase.account != address(0)) total += purchase.amount;
        }
    }

    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
        return interfaceId == INTERFACE_ID_ERC165 || interfaceId == INTERFACE_ID_ERC20;
    }

    // -------------------------- INTERNAL FUNCTIONS ----------------------- //

    function _enableTrading() internal {
        tradingEnabled = true;
    }

    function _update(address from, address to, uint256 amount) internal override {
        if (!tradingEnabled) {
            if (from == address(this) || from == address(0)) {
                super._update(from, to, amount);
            } else {
                revert("Trading is disabled");
            }
        } else {
            super._update(from, to, amount);
        }
    }

    function _writePurchaseData(uint256 amount, address account) internal {
        purchases[currentPurchaseId] = UserPurchase(account, uint64(block.timestamp), amount);
        emit Purchase(account, currentPurchaseId);
        unchecked {
            currentPurchaseId++;
        }
    }

    function _deployStaxLiqudityPool(uint256 staxAmount, uint256 e280Amount) internal {
        (uint256 pairBalance, address pairAddress) = _checkPoolValidity(E280);
        IERC20 e280 = IERC20(E280);
        if (pairBalance > 0) {
            _mint(pairAddress, staxAmount);
            e280.transfer(pairAddress, e280Amount);
            IUniswapV2Pair(pairAddress).mint(address(0));
        } else {
            _mint(address(this), staxAmount);
            IERC20(address(this)).safeIncreaseAllowance(UNISWAP_V2_ROUTER, staxAmount);
            e280.safeIncreaseAllowance(UNISWAP_V2_ROUTER, e280Amount);
            IUniswapV2Router02(UNISWAP_V2_ROUTER).addLiquidity(
                address(this), E280, staxAmount, e280Amount, staxAmount, e280Amount, address(0), block.timestamp
            );
        }
    }

    function _checkPoolValidity(address target) internal returns (uint256, address) {
        address pairAddress = IUniswapV2Factory(UNISWAP_V2_FACTORY).getPair(address(this), target);
        if (pairAddress == address(0)) return (0, pairAddress);
        IUniswapV2Pair pair = IUniswapV2Pair(pairAddress);

        pair.sync();
        (uint112 reserve0, uint112 reserve1,) = pair.getReserves();
        if (reserve0 != 0) return (reserve0, pairAddress);
        if (reserve1 != 0) return (reserve1, pairAddress);
        return (0, pairAddress);
    }

    function _swapETHForTitanX(uint256 minAmountOut, uint256 deadline, address receiver) internal returns (uint256) {
        IWETH9(WETH9).deposit{value: msg.value}();

        ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
            tokenIn: WETH9,
            tokenOut: TITANX,
            fee: POOL_FEE_1PERCENT,
            recipient: receiver,
            deadline: deadline,
            amountIn: msg.value,
            amountOutMinimum: minAmountOut,
            sqrtPriceLimitX96: 0
        });
        IERC20(WETH9).safeIncreaseAllowance(UNISWAP_V3_ROUTER, msg.value);
        uint256 amountOut = ISwapRouter(UNISWAP_V3_ROUTER).exactInputSingle(params);
        return amountOut;
    }

    function _swapTitanXtoElmnt(uint256 amountIn, uint256 minAmountOut, uint256 deadline) internal {
        IERC20(TITANX).safeIncreaseAllowance(UNISWAP_V2_ROUTER, amountIn);
        address[] memory path = new address[](2);
        path[0] = TITANX;
        path[1] = E280;

        IUniswapV2Router02(UNISWAP_V2_ROUTER).swapExactTokensForTokensSupportingFeeOnTransferTokens(
            amountIn, minAmountOut, path, address(this), deadline
        );
    }

    function _swapTitanXToX28(uint256 amountIn, uint256 minAmountOut, uint256 deadline) internal {
        ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
            tokenIn: TITANX,
            tokenOut: X28,
            fee: POOL_FEE_1PERCENT,
            recipient: address(this),
            deadline: deadline,
            amountIn: amountIn,
            amountOutMinimum: minAmountOut,
            sqrtPriceLimitX96: 0
        });
        IERC20(TITANX).safeIncreaseAllowance(UNISWAP_V3_ROUTER, amountIn);
        ISwapRouter(UNISWAP_V3_ROUTER).exactInputSingle(params);
    }
}

Read Contract

STAX_BANK 0x179397f7 → address
STAX_BUY_BURN 0xdfac55c7 → address
STAX_NFT 0x3a81104d → address
STAX_VAULT 0x00be3656 → address
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
currentPurchaseId 0x8a7b1501 → uint64
decimals 0x313ce567 → uint8
e280LiquidityAdded 0xb199e7e7 → bool
getUnclaimedTokenAmount 0x2df700ac → uint256
isPresaleActive 0x60d938dc → bool
lpPool 0x3737bcb4 → uint256
lpPurchaseFinished 0xf468fa07 → bool
lpPurchaseStarted 0x5d6b17a2 → bool
lpPurchasesMade 0xb3e20c5e → uint8
name 0x06fdde03 → string
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
presaleEnd 0x229f3e29 → uint256
purchases 0x0e5ff0f3 → address, uint64, uint256
purchasesOf 0x87dba908 → uint64[], tuple[]
purchasesRequired 0x847e7fe6 → uint8
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
totalBurned 0xd89135cd → uint256
totalSupply 0x18160ddd → uint256
tradingEnabled 0x4ada218b → bool

Write Contract 19 functions

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

acceptOwnership 0x79ba5097
No parameters
addE280Liquidity 0xc3e46ab3
uint256 minE280Amount
uint256 minX28Amount
uint256 deadline
approve 0x095ea7b3
address spender
uint256 value
returns: bool
burn 0x42966c68
uint256 value
claimPurchase 0x0cfd5bbb
uint64 purchaseId
deployStaxLP 0x1cdd0221
No parameters
distributeStaxBank 0x42445bae
No parameters
handleBackingClaim 0xc55bf039
uint256 amount
address receiver
purchaseTokenForLP 0xd48b6fb0
uint256 minAmountOut
uint256 deadline
purchaseWithETH 0xf0883d10
uint256 minAmount
uint256 deadline
purchaseWithTitanX 0xd3179ec2
uint256 amount
renounceOwnership 0x715018a6
No parameters
setProtocolAddresses 0x8156b1ec
address _staxNft
address _staxVault
address _staxBank
address _staxBuyBurn
setPurchasesRequired 0xd1fe8484
uint8 amount
startLpPurchases 0xfd1f3e81
bool x28NativeMint
uint256 minAmountOutX28
uint256 deadline
startMint 0x2be09561
No parameters
transfer 0xa9059cbb
address to
uint256 value
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 value
returns: bool
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address