Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xC062F79adCC6458070fA17934B1666c02611204b
Balance 0 ETH
Nonce 1
Code Size 11151 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

11151 bytes
0x608060405234801561000f575f80fd5b5060043610610148575f3560e01c80637c6f73eb116100bf578063bf7d911911610079578063bf7d91191461034a578063c1be66771461036c578063c54e44eb1461037f578063cf59d5631461039a578063e0bab4c4146103b5578063f887ea40146103d0575f80fd5b80637c6f73eb1461028a5780637fad9e17146102a057806389a30271146102a857806398e2d462146102c3578063a5ece9411461030f578063ad5c464814610336575f80fd5b80632b72c4c0116101105780632b72c4c0146101fc5780632e1a7d4d146102065780633aaa01761461021957806347e7ef241461023c5780636ca669161461024f578063742fe1f814610277575f80fd5b80630516c86a1461014c5780630fd9eeeb1461017557806318089a0c146101a85780631bb879ca146101c55780632a6bc2dd146101dc575b5f80fd5b61015f61015a3660046126f2565b6103e4565b60405161016c9190612712565b60405180910390f35b610190732ba64efb7a4ec8983e22a49c81fa216ac33f383a81565b6040516001600160a01b03909116815260200161016c565b6101b06104e9565b6040805192835260208301919091520161016c565b6101ce60025481565b60405190815260200161016c565b6101ef6101ea366004612770565b610500565b60405161016c9190612789565b6102046105b5565b005b61020461021436600461280b565b6106a7565b61022c610227366004612822565b6111c1565b604051901515815260200161016c565b61020461024a366004612822565b6111ef565b6101ce61025d366004612770565b6001600160a01b03165f9081526020819052604090205490565b610204610285366004612822565b611d59565b610292611f3c565b60405161016c92919061284a565b6101ce6120f4565b61019073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6102d66102d1366004612822565b612104565b604080516001600160a01b03909716875260208701959095529385019290925260608401526080830152151560a082015260c00161016c565b6101907f0000000000000000000000002ce909655de53c1308f9d3dac32c2105c37db60e81565b6101905f80516020612b1a83398151915281565b61022c610358366004612770565b60016020525f908152604090205460ff1681565b6102d661037a366004612822565b6121bb565b61019073dac17f958d2ee523a2206206994597c13d831ec781565b610190735f98805a4e8be255a32880fdec7f6728c6568ba081565b610190736b175474e89094c44da98b954eedeac495271d0f81565b6101905f80516020612b3a83398151915281565b60606103f06003612217565b82106104395760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b60448201526064015b60405180910390fd5b5f61044484846128e2565b61044f9060016128f5565b67ffffffffffffffff81111561046757610467612908565b604051908082528060200260200182016040528015610490578160200160208202803683370190505b509050835b8381116104df576104a7600382612220565b826104b287846128e2565b815181106104c2576104c261291c565b6020908102919091010152806104d781612930565b915050610495565b5090505b92915050565b5f806104f56003612217565b915060025490509091565b6001600160a01b0381165f90815260208181526040808320805482518185028101850190935280835260609492939192909184015b828210156105aa575f8481526020908190206040805160c0810182526006860290920180546001600160a01b031683526001808201548486015260028201549284019290925260038101546060840152600481015460808401526005015460ff16151560a08301529083529092019101610535565b505050509050919050565b336001600160a01b037f0000000000000000000000002ce909655de53c1308f9d3dac32c2105c37db60e161461061c5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610430565b600254806106615760405162461bcd60e51b81526020600482015260126024820152714e6f2066756e647320617661696c61626c6560701b6044820152606401610430565b5f6002556106a4732ba64efb7a4ec8983e22a49c81fa216ac33f383a7f0000000000000000000000002ce909655de53c1308f9d3dac32c2105c37db60e83612232565b50565b335f9081526020819052604090205481106106d45760405162461bcd60e51b815260040161043090612948565b335f9081526020819052604081208054839081106106f4576106f461291c565b905f5260205f20906006020190505f8160010154116107555760405162461bcd60e51b815260206004820152601760248201527f4e6f20706f736974696f6e20746f2077697468647261770000000000000000006044820152606401610430565b600581015460ff166110c75780546001600160a01b031673a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4814806107aa575080546001600160a01b031673dac17f958d2ee523a2206206994597c13d831ec7145b15610b3c57604051636eb1769f60e11b81525f90732ba64efb7a4ec8983e22a49c81fa216ac33f383a9063dd62ed3e906107f79030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa158015610812573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108369190612992565b9050816002015481101561087f575f1961087d5f80516020612b3a83398151915261086184846128e2565b732ba64efb7a4ec8983e22a49c81fa216ac33f383a919061229a565b505b6040805160a081019091525f90806108be732ba64efb7a4ec8983e22a49c81fa216ac33f383a60645f80516020612b1a83398151915260c085016129a9565b60408051601f198184030181529181529082523060208301524282820152600286015460608301525f60809092018290525163c04b8d5960e01b8152919250905f80516020612b3a8339815191529063c04b8d5990610921908590600401612a2c565b6020604051808303815f875af115801561093d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109619190612992565b604051636eb1769f60e11b81529091505f80516020612b1a8339815191529063dd62ed3e906109a39030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa1580156109be573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109e29190612992565b925080831015610a20575f19610a1e5f80516020612b3a833981519152610a0986846128e2565b5f80516020612b1a833981519152919061229a565b505b6040805160a0810190915284548190610a57905f80516020612b1a833981519152906064906001600160a01b031660c085016129a9565b6040516020818303038152906040528152602001306001600160a01b0316815260200142815260200182815260200185600101546002610a979190612a83565b905260405163c04b8d5960e01b81529092505f80516020612b3a8339815191529063c04b8d5990610acc908590600401612a2c565b6020604051808303815f875af1158015610ae8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b0c9190612992565b50610b343385600101546002610b229190612a83565b86546001600160a01b03169190612232565b5050506110ee565b80546001600160a01b0316735f98805a4e8be255a32880fdec7f6728c6568ba01480610b85575080546001600160a01b0316736b175474e89094c44da98b954eedeac495271d0f145b156110c257604051636eb1769f60e11b81525f90732ba64efb7a4ec8983e22a49c81fa216ac33f383a9063dd62ed3e90610bd29030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa158015610bed573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c119190612992565b90508160020154811015610c3e575f19610c3c5f80516020612b3a83398151915261086184846128e2565b505b6040805160a081019091525f9080610c7d732ba64efb7a4ec8983e22a49c81fa216ac33f383a60645f80516020612b1a83398151915260c085016129a9565b60408051601f198184030181529181529082523060208301524282820152600286015460608301525f60809092018290525163c04b8d5960e01b8152919250905f80516020612b3a8339815191529063c04b8d5990610ce0908590600401612a2c565b6020604051808303815f875af1158015610cfc573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d209190612992565b604051636eb1769f60e11b81529091505f80516020612b1a8339815191529063dd62ed3e90610d629030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa158015610d7d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610da19190612992565b925080831015610dca575f19610dc85f80516020612b3a833981519152610a0986846128e2565b505b6040805160a0810190915280610e075f80516020612b1a833981519152606473a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4860c085016129a9565b60408051601f198184030181529181529082523060208301524282820152606082018490525f60809092018290525163c04b8d5960e01b8152919350905f80516020612b3a8339815191529063c04b8d5990610e67908690600401612a2c565b6020604051808303815f875af1158015610e83573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ea79190612992565b604051636eb1769f60e11b815290915073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb489063dd62ed3e90610ef09030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa158015610f0b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f2f9190612992565b935080841015610f74575f19610f725f80516020612b3a833981519152610f5687846128e2565b73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48919061229a565b505b84546064906001600160a01b0316735f98805a4e8be255a32880fdec7f6728c6568b9f1901610fa257506101f45b6040805160a0810190915286548190610fdf9073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb489085906001600160a01b031660c085016129a9565b6040516020818303038152906040528152602001306001600160a01b031681526020014281526020018381526020018760010154600261101f9190612a83565b905260405163c04b8d5960e01b81529094505f80516020612b3a8339815191529063c04b8d5990611054908790600401612a2c565b6020604051808303815f875af1158015611070573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110949190612992565b506110bc33876001015460026110aa9190612a83565b88546001600160a01b03169190612232565b50505050505b6110ee565b6110ee33826001015460026110dc9190612a83565b83546001600160a01b03169190612232565b600181015433907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d590611122906002612a83565b60405190815260200160405180910390a26001600160601b03193360601b166001600160601b03831617611157600382612348565b50335f9081526020819052604090208054849081106111785761117861291c565b5f9182526020822060069091020180546001600160a01b03191681556001810182905560028101829055600381018290556004810191909155600501805460ff19169055505050565b5f6001600160601b0319606084901b166001600160601b038316176111e7600382612353565b949350505050565b6001600160a01b0382165f9081526001602052604090205460ff1661124f5760405162461bcd60e51b81526020600482015260166024820152752ab739bab83837b93a32b21039ba30b13632b1b7b4b760511b6044820152606401610430565b5f811161129e5760405162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e20300000006044820152606401610430565b6112b36001600160a01b03831633308461236a565b5f6001600160a01b03831673dac17f958d2ee523a2206206994597c13d831ec714806112fb57506001600160a01b03831673a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48145b1561162057604051636eb1769f60e11b81525f906001600160a01b0385169063dd62ed3e9061133d9030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa158015611358573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061137c9190612992565b9050828110156113b6575f196113b45f80516020612b3a8339815191526113a384846128e2565b6001600160a01b038816919061229a565b505b6040805160a081019091525f90806113e18760645f80516020612b1a83398151915260c085016129a9565b60408051601f198184030181529181529082523060208301524282820152606082018790525f60809092018290525163c04b8d5960e01b8152919250905f80516020612b3a8339815191529063c04b8d5990611441908590600401612a2c565b6020604051808303815f875af115801561145d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114819190612992565b604051636eb1769f60e11b81529091505f80516020612b1a8339815191529063dd62ed3e906114c39030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa1580156114de573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115029190612992565b92508483101561152b575f196115295f80516020612b3a833981519152610a0986846128e2565b505b6040805160a08101909152806115685f80516020612b1a8339815191526064732ba64efb7a4ec8983e22a49c81fa216ac33f383a60c085016129a9565b6040516020818303038152906040528152602001306001600160a01b031681526020014281526020018281526020015f81525091505f80516020612b3a8339815191526001600160a01b031663c04b8d59836040518263ffffffff1660e01b81526004016115d69190612a2c565b6020604051808303815f875af11580156115f2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116169190612992565b9350505050611b39565b6001600160a01b038316735f98805a4e8be255a32880fdec7f6728c6568ba0148061166757506001600160a01b038316736b175474e89094c44da98b954eedeac495271d0f145b15611b3957604051636eb1769f60e11b81525f906001600160a01b0385169063dd62ed3e906116a99030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa1580156116c4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116e89190612992565b905082811015611711575f1961170f5f80516020612b3a8339815191526113a384846128e2565b505b6064735f98805a4e8be255a32880fdec7f6728c6568b9f196001600160a01b0386160161173d57506101f45b6040805160a081019091525f908061176e888573a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4860c085016129a9565b60408051601f198184030181529181529082523060208301524282820152606082018890525f60809092018290525163c04b8d5960e01b8152919250905f80516020612b3a8339815191529063c04b8d59906117ce908590600401612a2c565b6020604051808303815f875af11580156117ea573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061180e9190612992565b604051636eb1769f60e11b815290915073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb489063dd62ed3e906118579030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa158015611872573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118969190612992565b9350858410156118bf575f196118bd5f80516020612b3a833981519152610f5687846128e2565b505b6040805160a08101909152806118fc73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4860645f80516020612b1a83398151915260c085016129a9565b60408051601f198184030181529181529082523060208301524282820152606082018490525f60809092018290525163c04b8d5960e01b8152919350905f80516020612b3a8339815191529063c04b8d599061195c908690600401612a2c565b6020604051808303815f875af1158015611978573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061199c9190612992565b604051636eb1769f60e11b81529091505f80516020612b1a8339815191529063dd62ed3e906119de9030905f80516020612b3a83398151915290600401612978565b602060405180830381865afa1580156119f9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a1d9190612992565b945086851015611a46575f19611a445f80516020612b3a833981519152610a0988846128e2565b505b6040805160a0810190915280611a835f80516020612b1a8339815191526064732ba64efb7a4ec8983e22a49c81fa216ac33f383a60c085016129a9565b6040516020818303038152906040528152602001306001600160a01b031681526020014281526020018281526020015f81525092505f80516020612b3a8339815191526001600160a01b031663c04b8d59846040518263ffffffff1660e01b8152600401611af19190612a2c565b6020604051808303815f875af1158015611b0d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b319190612992565b955050505050505b5f6064611b4783600f612a83565b611b519190612a9a565b90505f6064611b6184600f612a83565b611b6b9190612a9a565b90505f81611b7984866128e2565b611b8391906128e2565b90508260025f828254611b9691906128f5565b9091555050335f9081526020818152604091829020825160c0810184526001600160a01b038a1681529182018890529181018390526060810186611be289670de0b6b3a7640000612a83565b611bec9190612a9a565b8152602001620f424087611c088a670de0b6b3a7640000612a83565b611c129190612a9a565b611c1f90622b98b7612a83565b611c299190612a9a565b81525f6020918201819052835460018082018655948252828220845160069092020180546001600160a01b0319166001600160a01b0390921691909117815583830151818601556040808501516002830155606085015160038301556080850151600483015560a0909401516005909101805460ff191691151591909117905533815290819052908120549091611cbf916128e2565b90506001600160601b03193360601b166001600160601b03821617611ce56003826123a2565b50335f818152602081905260409020547ff5681f9d0db1b911ac18ee83d515a1cf1051853a9eae418316a2fdf7dea427c5908a908a90611d27906001906128e2565b604080516001600160a01b03909416845260208401929092529082015260600160405180910390a25050505050505050565b6001600160a01b0382165f908152602081905260409020548110611d8f5760405162461bcd60e51b815260040161043090612948565b6001600160a01b0382165f908152602081905260408120805483908110611db857611db861291c565b905f5260205f20906006020190505f816001015411611e195760405162461bcd60e51b815260206004820152601760248201527f506f736974696f6e20646f6573206e6f742065786973740000000000000000006044820152606401610430565b600581015460ff1615611e6e5760405162461bcd60e51b815260206004820152601760248201527f506f736974696f6e20616c726561647920636c6f7365640000000000000000006044820152606401610430565b611e97333083600101546002611e849190612a83565b84546001600160a01b031692919061236a565b6002810154611ebd90732ba64efb7a4ec8983e22a49c81fa216ac33f383a903390612232565b60058101805460ff191660011790556001600160601b0319606084901b166001600160601b03831617611ef1600382612348565b5060408051338152602081018590526001600160a01b038616917f8b60ee59fde7fe878d00e7ff88684e1f938c140af42c1a7f62e7ca182dfc620c910160405180910390a250505050565b60408051600480825260a0820190925260609182915f9160208201608080368337505060408051600480825260a082019092529293505f92915060208201608080368337019050509050735f98805a4e8be255a32880fdec7f6728c6568ba073dac17f958d2ee523a2206206994597c13d831ec773a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48736b175474e89094c44da98b954eedeac495271d0f855f81518110611fec57611fec61291c565b60200260200101866001815181106120065761200661291c565b60200260200101876002815181106120205761202061291c565b602002602001018860038151811061203a5761203a61291c565b6001600160a01b0395861660209182029290920101529383169093529281169091529190911690525f5b60048110156120ea5760015f8483815181106120825761208261291c565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f9054906101000a900460ff168282815181106120c8576120c861291c565b91151560209283029190910190910152806120e281612930565b915050612064565b5090939092509050565b5f6120ff6003612217565b905090565b6001600160a01b0382165f908152602081905260408120548190819081908190819087106121445760405162461bcd60e51b815260040161043090612948565b6001600160a01b0388165f90815260208190526040812080548990811061216d5761216d61291c565b5f9182526020909120600690910201805460018201546002830154600384015460048501546005909501546001600160a01b039094169e929d50909b50995091975060ff1695509350505050565b5f602052815f5260405f2081815481106121d3575f80fd5b5f9182526020909120600690910201805460018201546002830154600384015460048501546005909501546001600160a01b03909416965091945092909160ff1686565b5f6104e3825490565b5f61222b83836123ad565b9392505050565b6040516001600160a01b03831660248201526044810182905261229590849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526123d3565b505050565b604051636eb1769f60e11b81525f906001600160a01b0385169063dd62ed3e906122ca9030908790600401612978565b602060405180830381865afa1580156122e5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123099190612992565b90506123428463095ea7b360e01b8561232286866128f5565b6040516001600160a01b039092166024830152604482015260640161225e565b50505050565b5f61222b83836124a6565b5f818152600183016020526040812054151561222b565b6040516001600160a01b03808516602483015283166044820152606481018290526123429085906323b872dd60e01b9060840161225e565b5f61222b8383612589565b5f825f0182815481106123c2576123c261291c565b905f5260205f200154905092915050565b5f612427826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166125d59092919063ffffffff16565b905080515f14806124475750808060200190518101906124479190612ab9565b6122955760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610430565b5f8181526001830160205260408120548015612580575f6124c86001836128e2565b85549091505f906124db906001906128e2565b905081811461253a575f865f0182815481106124f9576124f961291c565b905f5260205f200154905080875f0184815481106125195761251961291c565b5f918252602080832090910192909255918252600188019052604090208390555b855486908061254b5761254b612ad8565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f9055600193505050506104e3565b5f9150506104e3565b5f8181526001830160205260408120546125ce57508154600181810184555f8481526020808220909301849055845484825282860190935260409020919091556104e3565b505f6104e3565b60606111e784845f85855f80866001600160a01b031685876040516125fa9190612aec565b5f6040518083038185875af1925050503d805f8114612634576040519150601f19603f3d011682016040523d82523d5f602084013e612639565b606091505b509150915061264a87838387612655565b979650505050505050565b606083156126c35782515f036126bc576001600160a01b0385163b6126bc5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610430565b50816111e7565b6111e783838151156126d85781518083602001fd5b8060405162461bcd60e51b81526004016104309190612b07565b5f8060408385031215612703575f80fd5b50508035926020909101359150565b602080825282518282018190525f9190848201906040850190845b818110156127495783518352928401929184019160010161272d565b50909695505050505050565b80356001600160a01b038116811461276b575f80fd5b919050565b5f60208284031215612780575f80fd5b61222b82612755565b602080825282518282018190525f919060409081850190868401855b828110156127fe57815180516001600160a01b0316855286810151878601528581015186860152606080820151908601526080808201519086015260a09081015115159085015260c090930192908501906001016127a5565b5091979650505050505050565b5f6020828403121561281b575f80fd5b5035919050565b5f8060408385031215612833575f80fd5b61283c83612755565b946020939093013593505050565b604080825283519082018190525f906020906060840190828701845b8281101561288b5781516001600160a01b031684529284019290840190600101612866565b505050838103828501528451808252858301918301905f5b818110156128c15783511515835292840192918401916001016128a3565b5090979650505050505050565b634e487b7160e01b5f52601160045260245ffd5b818103818111156104e3576104e36128ce565b808201808211156104e3576104e36128ce565b634e487b7160e01b5f52604160045260245ffd5b634e487b7160e01b5f52603260045260245ffd5b5f60018201612941576129416128ce565b5060010190565b602080825260169082015275092dcecc2d8d2c840e0dee6d2e8d2dedc40d2dcc8caf60531b604082015260600190565b6001600160a01b0392831681529116602082015260400190565b5f602082840312156129a2575f80fd5b5051919050565b606093841b6001600160601b0319908116825260e89390931b6001600160e81b0319166014820152921b166017820152602b0190565b5f5b838110156129f95781810151838201526020016129e1565b50505f910152565b5f8151808452612a188160208601602086016129df565b601f01601f19169290920160200192915050565b602081525f825160a06020840152612a4760c0840182612a01565b905060018060a01b0360208501511660408401526040840151606084015260608401516080840152608084015160a08401528091505092915050565b80820281158282048414176104e3576104e36128ce565b5f82612ab457634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215612ac9575f80fd5b8151801515811461222b575f80fd5b634e487b7160e01b5f52603160045260245ffd5b5f8251612afd8184602087016129df565b9190910192915050565b602081525f61222b6020830184612a0156fe000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564a2646970667358221220cd20cbc47e2ac8826dfdf20766439cbbd46941fb9b8b421a7fc609cf25cdc23d64736f6c63430008150033

Verified Source Code Partial Match

Compiler: v0.8.21+commit.d9974bed EVM: shanghai Optimization: Yes (200 runs)
DoubleUp.sol 1432 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount) external returns (bool);
}

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

pragma abicoder v2;

/// @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);
}

/**
 * @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 of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

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

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

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

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

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

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

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

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

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

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}

/**
 * @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 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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 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);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @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.encodeWithSelector(token.approve.selector, spender, value);

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

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @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.isContract(address(token));
    }
}

contract DoubleUp {
    using SafeERC20 for IERC20;

    struct Position {
        address stablecoin;
        uint256 originalAmount;
        uint256 wbglAmount;
        uint256 buyPrice;
        uint256 sellPrice;
        bool closed;
    }

    mapping(address => Position[]) public positions;
    address public constant WBGL = 0x2bA64EFB7A4Ec8983E22A49c81fa216AC33f383A;
    address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; // all is swapped through WETH (most liquid)

    address public constant LUSD = 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0;
    address public constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
    address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
    address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
    
    ISwapRouter public constant router = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564); // Mainnet UNI router
    address public immutable marketingAddress;
    
    // Supported stablecoins: LUSD, USDT, USDC, DAI
    mapping(address => bool) public supportedStablecoins;
    
    // Marketing balance tracking (WBGL only)
    uint256 public marketingBalanceWBGL;
    
    using EnumerableSet for EnumerableSet.Bytes32Set;
    EnumerableSet.Bytes32Set private activePositions;
    
    event Deposited(address indexed user, address stablecoin, uint256 amount, uint256 positionIndex);
    event PositionClosed(address indexed user, address closer, uint256 positionIndex);
    event Withdrawn(address indexed user, uint256 amount);

    constructor(address _marketingAddress) {
        supportedStablecoins[LUSD] = true;
        supportedStablecoins[USDT] = true;
        supportedStablecoins[USDC] = true;
        supportedStablecoins[DAI] = true;
        
        marketingAddress = _marketingAddress;
    }

    function deposit(address stablecoin, uint256 amount) external {
        require(supportedStablecoins[stablecoin], "Unsupported stablecoin");
        require(amount > 0, "Amount must be greater than 0");
        
        // Transfer stablecoins from user
        IERC20(stablecoin).safeTransferFrom(msg.sender, address(this), amount);

        // Swap full amount to WBGL using Uniswap V3
        uint256 amountOut;

        if (stablecoin == USDT || stablecoin == USDC) {
            // First swap stablecoin to WETH
            uint256 allowance = IERC20(stablecoin).allowance(address(this), address(router));
            if (allowance < amount) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(stablecoin).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    stablecoin,
                    uint24(100), // 0.3% fee - adjust based on your pool's fee tier
                    WETH
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: amount,
                amountOutMinimum: 0
            });

            uint256 wethOut = ISwapRouter(router).exactInput(params);
            allowance = IERC20(WETH).allowance(address(this), address(router));
            if (allowance < amount) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(WETH).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap WETH to WBGL
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WETH,
                    uint24(100), // 0.01% fee
                    WBGL
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: wethOut,
                amountOutMinimum: 0
            });

            amountOut = ISwapRouter(router).exactInput(params);

        } else if (stablecoin == LUSD || stablecoin == DAI) {
            // First swap LUSD to USDC
            uint256 allowance = IERC20(stablecoin).allowance(address(this), address(router));
            if (allowance < amount) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(stablecoin).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            uint24 poolFee = 100;
            if (stablecoin == LUSD) {
                poolFee = 500;
            }
            ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    stablecoin,
                    poolFee,
                    USDC
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: amount,
                amountOutMinimum: 0
            });

            uint256 usdcOut = ISwapRouter(router).exactInput(params);

            allowance = IERC20(USDC).allowance(address(this), address(router));
            if (allowance < amount) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(USDC).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap USDC to WETH
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    USDC,
                    uint24(100), // 0.01% fee
                    WETH
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: usdcOut,
                amountOutMinimum: 0
            });

            uint256 wethOut = ISwapRouter(router).exactInput(params);

            allowance = IERC20(WETH).allowance(address(this), address(router));
            if (allowance < amount) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(WETH).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap WETH to WBGL
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WETH,
                    uint24(100), // 0.01% fee
                    WBGL
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: wethOut,
                amountOutMinimum: 0
            });

            amountOut = ISwapRouter(router).exactInput(params);
        }

        // Calculate allocations
        uint256 marketingWBGL = (amountOut * 15) / 100;
        uint256 frozenWBGL = (amountOut * 15) / 100;
        uint256 positionWBGL = amountOut - marketingWBGL - frozenWBGL;

        // Track marketing allocation
        marketingBalanceWBGL += marketingWBGL;

        // Store new position in array
        positions[msg.sender].push(Position({
            stablecoin: stablecoin,
            originalAmount: amount, // Use full deposit amount in stables
            wbglAmount: positionWBGL,
            buyPrice: amount * 1e18 / amountOut, // Price per WBGL
            sellPrice: (amount * 1e18 / amountOut * 2857143) / 1000000, // 2.857143x of buyPrice
            closed: false
        }));

        // Track position in activePositions
        uint96 positionIndex = uint96(positions[msg.sender].length - 1);
        bytes32 positionId = bytes32(bytes20(msg.sender)) | bytes32(uint256(positionIndex));
        activePositions.add(positionId);
        emit Deposited(msg.sender, stablecoin, amount, positions[msg.sender].length - 1);
    }

    function closePosition(address user, uint256 positionIndex) external {
        require(positionIndex < positions[user].length, "Invalid position index");
        Position storage position = positions[user][positionIndex];
        require(position.originalAmount > 0, "Position does not exist");
        require(!position.closed, "Position already closed");

        // Transfer required stablecoins from closer
        IERC20(position.stablecoin).safeTransferFrom(
            msg.sender,
            address(this),
            position.originalAmount * 2
        );

        // Transfer WBGL to closer
        IERC20(WBGL).safeTransfer(msg.sender, position.wbglAmount);
        
        position.closed = true;
        bytes32 positionId = bytes32(bytes20(user)) | bytes32(uint256(uint96(positionIndex)));
        activePositions.remove(positionId);
        emit PositionClosed(user, msg.sender, positionIndex);
    }

    function withdraw(uint256 positionIndex) external {
        require(positionIndex < positions[msg.sender].length, "Invalid position index");
        Position storage position = positions[msg.sender][positionIndex];
        require(position.originalAmount > 0, "No position to withdraw");

        if (!position.closed) {

            if (position.stablecoin == USDC || position.stablecoin == USDT) {
                // Attempt to swap WBGL back to stablecoin using Uniswap V3
                uint256 allowance = IERC20(WBGL).allowance(address(this), address(router));
                if (allowance < position.wbglAmount) {
                    uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                    IERC20(WBGL).safeIncreaseAllowance(address(router), newAllowance - allowance);
                }

                ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
                    path: abi.encodePacked(
                        WBGL,
                        uint24(100),
                        WETH
                    ),
                    recipient: address(this),
  ...

// [truncated — 57972 bytes total]

Read Contract

DAI 0xe0bab4c4 → address
LUSD 0xcf59d563 → address
USDC 0x89a30271 → address
USDT 0xc54e44eb → address
WBGL 0x0fd9eeeb → address
WETH 0xad5c4648 → address
getContractStatistics 0x18089a0c → uint256, uint256
getOpenPositionAddresses 0x0516c86a → bytes32[]
getOpenPositionCount 0x7fad9e17 → uint256
getPositionDetails 0x98e2d462 → address, uint256, uint256, uint256, uint256, bool
getSupportedStablecoins 0x7c6f73eb → address[], bool[]
getUserPositions 0x2a6bc2dd → tuple[]
getUserPositionsLength 0x6ca66916 → uint256
isPositionOpen 0x3aaa0176 → bool
marketingAddress 0xa5ece941 → address
marketingBalanceWBGL 0x1bb879ca → uint256
positions 0xc1be6677 → address, uint256, uint256, uint256, uint256, bool
router 0xf887ea40 → address
supportedStablecoins 0xbf7d9119 → bool

Write Contract 4 functions

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

closePosition 0x742fe1f8
address user
uint256 positionIndex
deposit 0x47e7ef24
address stablecoin
uint256 amount
withdraw 0x2e1a7d4d
uint256 positionIndex
withdrawMarketingFunds 0x2b72c4c0
No parameters

Token Balances (1)

View Transfers →
USDT 2

Recent Transactions

No transactions found for this address