Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xDf021D215EbB9eBFaB6163550cef0B30A8426768
Balance 0 ETH
Nonce 1
Code Size 10714 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

10714 bytes
0x6080604052600436101561001a575b3615610018575f80fd5b005b5f5f3560e01c8063103c10da14611d8257806316c38b3c14611d175780633b016d12146115f75780634782f779146115735780634aa4a4fc146115445780634b0bddd2146114525780635c975abb1461142f5780635fc3ea0b1461134f5780636b9d22ed14610f165780636d1ea3fa14610ed7578063701380e314610d81578063735de9f714610d525780637a78be0a14610cb75780637e6a340014610c52578063873ffadd14610a855780638aa5eff4146102c2578063a249d2e9146101a15763c4d66de8146100eb575061000e565b3461019e57602036600319011261019e57610104611f4b565b60025460ff8160081c166101425761ff001916610100176002556001600160a01b031681526001602081905260408220805460ff1916909117905580f35b60405162461bcd60e51b815260206004820152602e60248201527f436f6e747261637420696e7374616e63652068617320616c726561647920626560448201526d195b881a5b9a5d1a585b1a5e995960921b6064820152608490fd5b80fd5b503461019e57602036600319011261019e576004356001600160401b0381116102be5760206101d581923690600401611f1b565b604051928184925191829101835e8101600481520301902060405190828154906101fe82611f77565b8085529160018116908115610296575060011461025d575b50506102278261024e940383611ea9565b600181015490600260018060a01b0391015416604051938493606085526060850190611faf565b91602084015260408301520390f35b909350818152602081205b84821061028057508201602001925061022782610216565b6001816020925483858801015201910190610268565b61024e965085925060209150926102279360ff191682840152151560051b8201019450610216565b5080fd5b503461019e5760e036600319011261019e576004356001600160401b0381116102be576102f3903690600401611f1b565b6024356001600160401b038111610a8157610312903690600401611f1b565b61031a611f61565b608435926064359161032a611f39565b60c4356001600160401b038111610a7d5736602382011215610a7d5761035a903690602481600401359101611ee5565b9360ff600254161580610a51575b6103719061205d565b61037f6002895414156120a0565b6002885560405191845192602081818801958087835e81016003815203019020956040519260a084018481106001600160401b03821117610a3d57604090815288546001600160a01b0390811680875260018b015482166020880190815260028c01549388019384526003909b0154918216606088015260a09190911c60ff1615156080870152909896906104159015156120ec565b6001600160a01b038116808d52600560205260408d20546104389060ff16612207565b875161045790610452906001600160a01b03168b8e612257565b61212b565b60e084805181010312610a395760405160e081018181106001600160401b03821117610a255760405261048c60208601612243565b80825261049b60408701612243565b95602083019687526060810151926040810193845260808201516060820190815260a08301519160ff83168303610960576080810192835260e060c08501519460a0830195865201519460c08201958652339060018060a01b0316036109e85789516001600160a01b031630036109a3578886511061096757519851945190519151925193516001600160a01b03998a1699909560ff9094169316863b15610960576040519963d505accf60e01b8b5260048b015260248a015260448901526064880152608487015260a486015260c48501528c808560e48183865af1948515610953578d95610934575b505087516001600160a01b03161461075b57976105bb602094612710946105c2946106159c60018060a01b038c511690612617565b518a612177565b85519351919004926001600160a01b0391821691166105e1848b61218a565b60405163a9059cbb60e01b81526001600160a01b0390931660048401526024830152909687919082908c9082906044820190565b03925af19182156107505761068a95602093610735575b5060018060a01b038451169060036040519187518091845e82018181528290038501909120015460405163a9059cbb60e01b81526001600160a01b0390911660048201526024810192909252909485919082908a9082906044820190565b03925af190811561072a576106b29386926106fd575b50516001600160a01b031691846123b3565b6106bb81612197565b7f64a2739e90a1ceaed855b4315cee68f13d112f711fb0304a77f9518e932786ca60405160208152806106f333956020830190611faf565b0390a46001815580f35b61071e9060203d602011610723575b6107168183611ea9565b8101906121b3565b6106a0565b503d61070c565b6040513d88823e3d90fd5b61074b90843d8611610723576107168183611ea9565b61062c565b6040513d8a823e3d90fd5b50505050509050610819925061271061078d600260405160208187518088835e81016003815203019020015487612177565b046020604051600185518086845e820191600383528381838060a01b03940301902001541660405185518086835e600390820190815281900383019020546001600160a01b0316906107df848a61218a565b6040516323b872dd60e01b81523360048201526001600160a01b0390931660248401526044830152909586919082908b9082906064820190565b03925af1908115610929576108aa9460209261090e575b50604051600185518086845e820191600383528481838060a01b039403019020015416604051600386518087845e8201818152829003850190912001546040516323b872dd60e01b81523360048201526001600160a01b0390911660248201526044810192909252909485919082908a9082906064820190565b03925af190811561072a576108ec9386926108f1575b5060016040519184518091845e82019160038352602081838060a01b03940301902001541691846123b3565b6106b2565b6109099060203d602011610723576107168183611ea9565b6108c0565b61092490833d8511610723576107168183611ea9565b610830565b6040513d89823e3d90fd5b819295509061094291611ea9565b61094f578a928c5f610586565b8b80fd5b50604051903d90823e3d90fd5b5050508f80fd5b60405162461bcd60e51b81526020600482015260146024820152735065726d69742076616c756520746f6f206c6f7760601b6044820152606490fd5b60405162461bcd60e51b815260206004820152601760248201527f5065726d6974207370656e646572206d69736d617463680000000000000000006044820152606490fd5b60405162461bcd60e51b81526020600482015260156024820152740a0cae4dad2e840deeedccae440dad2e6dac2e8c6d605b1b6044820152606490fd5b634e487b7160e01b8f52604160045260248ffd5b8c80fd5b634e487b7160e01b8c52604160045260248cfd5b5061037160ff6003604051602081895180838c01835e810184815203019020015460a01c169050610368565b8780fd5b8280fd5b503461019e5760c036600319011261019e576004356001600160401b0381116102be57610ab6903690600401611f1b565b6024356001600160a01b0381168103610a8157610ad1611f61565b608435916001600160a01b0383168303610c4e5760a435918215158303610c4a57600392610bce913388526001602052610b1160ff60408a205416611fd3565b60405193875194602081818b01978089835e8101898152030190209060018060a01b03166001600160601b0360a01b82541617905560016040516020818a518089835e8101898152030190200180546001600160a01b0319166001600160a01b0390921691909117905560405186516002908086845e820191868352602081606435940301902001558360405160208189518088835e81018481520301902001805460ff60a01b191691151560a01b60ff60a01b16919091179055565b6020604051809286518091835e8101848152030190200180546001600160a01b0319166001600160a01b039092169190911790557fad9348b18a3705f80b3ee598b34e1bee8cfe73dc3b70da67b91e346fd495cb9f610c44610c2f83612197565b92604051918291602083526020830190611faf565b0390a280f35b8580fd5b8480fd5b503461019e57604036600319011261019e57610cb4610c6f611f4b565b610c77611e7e565b903384526001602052610c9060ff604086205416611fd3565b60018060a01b031683526005602052604083209060ff801983541691151516179055565b80f35b503461019e57602036600319011261019e57600435906001600160401b03821161019e5760a0602080610ced3660048701611f1b565b604051928184925191829101835e8101600381520301902060ff600180841b0382541691600180851b0360018201541690600360028201549101549160405194855260208501526040840152600180851b0381166060840152831c1615156080820152f35b503461019e578060031936011261019e57602060405173e592427a0aece92de3edee1f18e0157c058615648152f35b503461019e57602036600319011261019e576004356001600160401b0381116102be57610db2903690600401611f1b565b3382526001602052610dca60ff604084205416611fd3565b6003604051610dfc83519160208501928084835e81018481528190036020019020546001600160a01b03161515612018565b60405160208185518085835e8101858152030190206001600160601b0360a01b8154169055600160405160208186518086835e810186815203019020016001600160601b0360a01b815416905583600260405160208187518087835e81018781520301902001558160405160208186518086835e8101848152030190200160ff60a01b1981541690556020604051809285518091835e8101848152030190200180546001600160a01b03191690557f9070b6352c7286c4745501d64d2f7ed13e22e1e5753074b73770c6042ade9b95610c44610c2f83612197565b503461019e57602036600319011261019e5760209060ff906040906001600160a01b03610f02611f4b565b168152600584522054166040519015158152f35b503461019e5760c036600319011261019e576004356001600160401b0381116102be57610f47903690600401611f1b565b6024356001600160401b038111610a8157610f66903690600401611f1b565b610f6e611f61565b60843592606435610f7d611f39565b9260ff600254161580611323575b610f949061205d565b610fa26002885414156120a0565b6002875560405191610fda84519360208601948086835e60039082019081528190036020019020546001600160a01b031615156120ec565b6001600160a01b038216808952600560205260408920549092906110009060ff16612207565b604051636eb1769f60e11b8152336004820152306024820152602081604481875afa80156113185783918b916112df575b501015806112d4575b1561129057879261107161045260405160018951808a845e82019160038352602081838060a01b039403019020015416888b612257565b604051600187518088845e82019160038352602081838060a01b03940301902001541614155f14611262579161117b95916110cf93604051600188518089845e82019160038352602081838060a01b03940301902001541690612617565b6127106110f5600260405160208187518088835e81016003815203019020015487612177565b046020604051600185518086845e820191600383528381838060a01b03940301902001541660405185518086835e600390820190815281900383019020546001600160a01b031690611147848a61218a565b60405163a9059cbb60e01b81526001600160a01b0390931660048401526024830152909586919082908b9082906044820190565b03925af19081156109295761120694602092611247575b50604051600185518086845e820191600383528481838060a01b039403019020015416604051600386518087845e82018181528290038501909120015460405163a9059cbb60e01b81526001600160a01b0390911660048201526024810192909252909485919082908a9082906044820190565b03925af190811561072a576106b29386926108f1575060016040519184518091845e82019160038352602081838060a01b03940301902001541691846123b3565b61125d90833d8511610723576107168183611ea9565b611192565b505050610819925061271061078d600260405160208187518088835e81016003815203019020015487612177565b606460405162461bcd60e51b815260206004820152602060248201527f496e73756666696369656e7420616c6c6f77616e636520617070726f76616c2e6044820152fd5b50600a82101561103a565b9150506020813d602011611310575b816112fb60209383611ea9565b8101031261130c578290515f611031565b5f80fd5b3d91506112ee565b6040513d8c823e3d90fd5b50610f9460ff6003604051602081885180838b01835e810184815203019020015460a01c169050610f8b565b503461019e57606036600319011261019e576113e4602061136e611f4b565b6024359061137a611f61565b903386526001845261139260ff604088205416611fd3565b6001600160a01b038116151580611426575b6113ad906121cb565b60405163a9059cbb60e01b81526001600160a01b039091166004820152602481019290925290928391908290869082906044820190565b03926001600160a01b03165af1801561141b576113ff575080f35b6114179060203d602011610723576107168183611ea9565b5080f35b6040513d84823e3d90fd5b508215156113a4565b503461019e578060031936011261019e57602060ff600254166040519015158152f35b503461019e57604036600319011261019e5761146c611f4b565b611474611e7e565b90338352600160205261148d60ff604085205416611fd3565b6001600160a01b03169030821480159061153a575b8015611531575b156114f95781835260016020526114cf81604085209060ff801983541691151516179055565b1515907f2713f2974d0fed89877842821cf1565b6c81396d34d6222e2a349cd6334bf4ed8380a380f35b60405162461bcd60e51b815260206004820152601060248201526f24b73b30b634b21030b2323932b9b99760811b6044820152606490fd5b508115156114a9565b50338214156114a2565b503461019e578060031936011261019e57602060405173c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28152f35b503461019e57604036600319011261019e5780808080611591611f4b565b6024359033835260016020526115ad60ff604085205416611fd3565b6001600160a01b0316801515806115ee575b6115c8906121cb565b8282156115e5575bf1156115d95780f35b604051903d90823e3d90fd5b506108fc6115d0565b508115156115bf565b50608036600319011261130c576004356001600160401b03811161130c57611623903690600401611f1b565b6024356001600160401b03811161130c57611642903690600401611f1b565b604435916064359062ffffff821680920361130c5760ff600254161580611ceb575b61166d9061205d565b61167b60025f5414156120a0565b60025f556103e8341115611cb457604051916116bd82519360208401948086835e60039082019081528190036020019020546001600160a01b031615156120ec565b6116ed610452604051600185518088845e82019160038352602081838060a01b0394030190200154168487612257565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2604051600184518087845e82019160038352602081838060a01b03940301902001541614155f146119c857604051600183518086845e82019160038352602081838060a01b039403019020015416851561198357341561193e57611766344761218a565b91600642019182421161192a576117de926020926040519261178784611e8d565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2845284840152604083015230606083015260808201528760a08201523460c08201525f60e082015260405180938192631b67c43360e31b83526004830161257f565b03813473e592427a0aece92de3edee1f18e0157c058615645af180156118f0576118fb575b5073e592427a0aece92de3edee1f18e0157c058615643b1561130c57604051630910874560e11b81525f816004818373e592427a0aece92de3edee1f18e0157c058615645af180156118f0576118da575b5085808061186381944761218a565b335af161186e6125e8565b50156118a55761117b916127106110f5600260405160208187518088835e81016003815203019020015487612177565b6001815580f35b60405162461bcd60e51b815260206004820152600d60248201526c1c99599d5b990819985a5b1959609a1b6044820152606490fd5b61186396505f6118e991611ea9565b5f95611854565b6040513d5f823e3d90fd5b6020813d602011611922575b8161191460209383611ea9565b8101031261130c5751611803565b3d9150611907565b634e487b7160e01b5f52601160045260245ffd5b60405162461bcd60e51b815260206004820152601a60248201527f4d7573742070617373206e6f6e20302045544820616d6f756e740000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601a60248201527f4d7573742070617373206e6f6e2030206f757420616d6f756e740000000000006044820152606490fd5b509192506127106119f2600260405160208187518088835e81016003815203019020015434612177565b04905f80808060405187518087835e60039082019081528190036020019020546001600160a01b0316611a25873461218a565b90828215611cab575bf1156118f0575f808093819360036040519188518091845e820181815282900360200190912001546001600160a01b0316828215611ca2575bf1156118f057604051906001835192602081818701958087835e810160048152030190200154155f14611c7457604051600184518085845e82019160048352602081349403019020015560405160208185518086835e81016004815203019020908051906001600160401b038211611c6057611ae38354611f77565b601f8111611c1b575b50602090601f8311600114611bb4576002949392915f9183611ba9575b50508160011b915f199060031b1c19161790555b6020604051809285518091835e810160048152030190200173c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160601b0360a01b8254161790555b611b6581612197565b9060405191602083527f64a2739e90a1ceaed855b4315cee68f13d112f711fb0304a77f9518e932786ca349380611ba133956020830190611faf565b0390a461189e565b015190505f80611b09565b90601f19831691845f52815f20925f5b818110611c03575091600193918560029897969410611beb575b505050811b019055611b1d565b01515f1960f88460031b161c191690555f8080611bde565b92936020600181928786015181550195019301611bc4565b835f5260205f20601f840160051c81019160208510611c56575b601f0160051c01905b818110611c4b5750611aec565b5f8155600101611c3e565b9091508190611c35565b634e487b7160e01b5f52604160045260245ffd5b506001906020604051809285518091835e8101600481520301902001611c9b3482546123a6565b9055611b5c565b506108fc611a67565b506108fc611a2e565b60405162461bcd60e51b815260206004820152600f60248201526e125b9d985b1a590814185e5b595b9d608a1b6044820152606490fd5b5061166d60ff6003604051602081865180838901835e810184815203019020015460a01c169050611664565b3461130c57602036600319011261130c5760043580151580910361130c57335f526001602052611d4d60ff60405f205416611fd3565b60ff196002541660ff8216176002557f0e2fb031ee032dc02d8011dc50b816eb450cf856abd8261680dac74f72165bd25f80a2005b3461130c57604036600319011261130c576004356001600160401b03811161130c573660238201121561130c5780600401356001600160401b03811161130c576024820191602482369201011161130c576020916003611e5692611de4611e7e565b948593335f5260018252611dfe60ff60405f205416611fd3565b611e266040518483823780850186815281900384019020546001600160a01b03161515612018565b82604051938492833781018481520301902001805460ff60a01b191691151560a01b60ff60a01b16919091179055565b15157fb5e8bdcf84e472fc1cf080b5d79b2ea6ac38d9416481ed71b112935d8b6516615f80a2005b60243590811515820361130c57565b61010081019081106001600160401b03821117611c6057604052565b90601f801991011681019081106001600160401b03821117611c6057604052565b6001600160401b038111611c6057601f01601f191660200190565b929192611ef182611eca565b91611eff6040519384611ea9565b82948184528183011161130c578281602093845f960137010152565b9080601f8301121561130c57816020611f3693359101611ee5565b90565b60a4359062ffffff8216820361130c57565b600435906001600160a01b038216820361130c57565b604435906001600160a01b038216820361130c57565b90600182811c92168015611fa5575b6020831014611f9157565b634e487b7160e01b5f52602260045260245ffd5b91607f1691611f86565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b15611fda57565b60405162461bcd60e51b8152602060048201526016602482015275155cd95c881a5cc81b9bdd08185d5d1a1bdc9a5e995960521b6044820152606490fd5b1561201f57565b60405162461bcd60e51b815260206004820152601660248201527513595c98da185b9d08191bd95cdb89dd08195e1a5cdd60521b6044820152606490fd5b1561206457565b60405162461bcd60e51b81526020600482015260146024820152732830bcb6b2b73a399030b932903830bab9b2b21760611b6044820152606490fd5b156120a757565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b156120f357565b60405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a590813595c98da185b9d60821b6044820152606490fd5b1561213257565b60405162461bcd60e51b815260206004820152601a60248201527f5061796d656e742064657374696e6174696f6e206572726f72210000000000006044820152606490fd5b8181029291811591840414171561192a57565b9190820391821161192a57565b602090604051918183925191829101835e81015f815203902090565b9081602091031261130c5751801515810361130c5790565b156121d257565b60405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081a5b9c1d5d609a1b6044820152606490fd5b1561220e57565b60405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2102a37b5b2b760991b6044820152606490fd5b51906001600160a01b038216820361130c57565b604051815160208301949391906002908087845e600490830190815282900360200190912001546001600160a01b03166122945750505050600190565b6020815191012060405160208184518088835e810160048152030190206040515f91818154936122c385611f77565b9283835260208301956001811690815f146123875750600114612343575b506122ee92500382611ea9565b51902014928361230b575b5050505f1461230757600190565b5f90565b60029192935060405192518091845e600490830190815282900360200190912001546001600160a01b039182169116145f80806122f9565b90505f9291925260205f20905f915b81831061236b5750509060206122ee928201015f6122e1565b6020919350806001915483858801015201910190918392612352565b60ff19168752506122ee93151560051b830160200191505f90506122e1565b9190820180921161192a57565b90604051926001835194602081818701978089835e810160048152030190200154155f1461255157600160405160208186518089835e81016004815203019020015560405160208184518087835e81016004815203019020908051906001600160401b038211611c60576124278354611f77565b601f811161250c575b50602090601f83116001146124a25791806020949260029796945f92612497575b50508160011b915f199060031b1c19161790555b604051928391518091835e81016004815203019020019060018060a01b03166001600160601b0360a01b825416179055565b015190505f80612451565b90601f19831691845f52815f20925f5b8181106124f45750926001928592600299989660209896106124dc575b505050811b019055612465565b01515f1960f88460031b161c191690555f80806124cf565b929360206001819287860151815501950193016124b2565b835f5260205f20601f840160051c81019160208510612547575b601f0160051c01905b81811061253c5750612430565b5f815560010161252f565b9091508190612526565b93505061257b916020600192604051928391518091835e81016004815203019020019182546123a6565b9055565b81516001600160a01b03908116825260208084015182169083015260408084015162ffffff16908301526060808401518216908301526080808401519083015260a0808401519083015260c0808401519083015260e09283015116918101919091526101000190565b3d15612612573d906125f982611eca565b916126076040519384611ea9565b82523d5f602084013e565b606090565b6040516323b872dd60e01b6020820190815233602483015230604483015260648201859052939591939192915f9182919061265f81608481015b03601f198101835282611ea9565b519082875af161266d6125e8565b81612975575b501561294a575f80604051602081019063095ea7b360e01b825273e592427a0aece92de3edee1f18e0157c058615646024820152886044820152604481526126bc606482611ea9565b519082875af16126ca6125e8565b8161291b575b501561288e57600b42019384421161192a5761274d9462ffffff602094604051946126fa86611e8d565b60018060a01b038816865260018060a01b031686860152166040840152306060840152608083015260a08201528460c08201525f60e082015260405180948192631b67c43360e31b83526004830161257f565b03815f73e592427a0aece92de3edee1f18e0157c058615645af19182156118f0575f926128e7575b505f80604051602081019063095ea7b360e01b825273e592427a0aece92de3edee1f18e0157c058615646024820152826044820152604481526127b9606482611ea9565b519082855af16127c76125e8565b816128b8575b501561288e578282106127df57505050565b6127ec5f9392849361218a565b60405163a9059cbb60e01b602082019081523360248301526044820192909252839061281b8160648101612651565b51925af16128276125e8565b8161285f575b501561283557565b60405162461bcd60e51b815260206004820152600260248201526114d560f21b6044820152606490fd5b8051801592508215612874575b50505f61282d565b61288792506020809183010191016121b3565b5f8061286c565b60405162461bcd60e51b8152602060048201526002602482015261534160f01b6044820152606490fd5b80518015925082156128cd575b50505f6127cd565b6128e092506020809183010191016121b3565b5f806128c5565b9091506020813d602011612913575b8161290360209383611ea9565b8101031261130c5751905f612775565b3d91506128f6565b8051801592508215612930575b50505f6126d0565b61294392506020809183010191016121b3565b5f80612928565b60405162461bcd60e51b815260206004820152600360248201526229aa2360e91b6044820152606490fd5b805180159250821561298a575b50505f612673565b61299d92506020809183010191016121b3565b5f8061298256fea264697066735822122052514123a0e4d43f633f972f42094c7fced32d0ffbc49a1c4d429327aa8cc30864736f6c634300081e0033

Verified Source Code Full Match

Compiler: v0.8.30+commit.73712a01 EVM: prague Optimization: Yes (200 runs)
POSv1-2.sol 283 lines
pragma solidity ^0.8.23;
// SPDX-License-Identifier: MIT
/*
    Designed by Gradam
*/
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

interface IUniswapRouter is ISwapRouter {
    function refundETH() external payable;
}

contract PaymentPortal is Context, ReentrancyGuard {
    mapping(address => bool) admin;
    address public constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    IUniswapRouter public constant uniswapRouter = IUniswapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
    bool public paused = false;
    bool private initialized;

    struct payment {
        string merchant;
        uint256 amount;
        IERC20 currency;
    }

    struct PermitCallData {
        address owner;
        address spender;
        uint256 value;
        uint256 deadline;
        uint8 v;
        bytes32 r;
        bytes32 s;
    }

    modifier onlyAdmin {
        require(admin[msg.sender], "User is not authorized");
        _;
    }

    modifier isPaused(string memory merchant) {
        require(!paused && Merchants[merchant].active, "Payments are paused.");
        _;
    }

    struct merchantData {
        address wallet;
        address tokenOut;
        uint feePercent;
        address feeDest;
        bool active;
    }
    mapping(string => merchantData) public Merchants;
    mapping(string => payment) public Payments;
    mapping(IERC20 => bool) public approvedTokens;
    event PaymentProcessed(string indexed IDindex, address indexed sender, uint256 indexed amount, string ID);


    function initialize(address _admin) public {
        require(!initialized, "Contract instance has already been initialized");
        initialized = true;
        admin[_admin] = true;
    } 

    /*
        Public
    */

    function sendETH(string memory merchant, string memory objectID, uint amountOut, uint24 poolFee) public isPaused(merchant) nonReentrant payable {
        require(msg.value > 1000, "Invalid Payment");
        require(Merchants[merchant].wallet != address(0), "Invalid Merchant");
        require(checkPrevious(objectID, merchant, IERC20(Merchants[merchant].tokenOut)), "Payment destination error!");

        if (Merchants[merchant].tokenOut != WETH9){
            convertEthToExact(Merchants[merchant].tokenOut, amountOut, poolFee);
            uint256 feeAmount = (amountOut * Merchants[merchant].feePercent) / 10000;
            IERC20(Merchants[merchant].tokenOut).transfer(Merchants[merchant].wallet, amountOut - feeAmount);
            IERC20(Merchants[merchant].tokenOut).transfer(Merchants[merchant].feeDest, feeAmount);
            pushToPayments(objectID, merchant, amountOut, IERC20(Merchants[merchant].tokenOut));
            emit PaymentProcessed(objectID, msg.sender, amountOut, objectID);
        } else {
            uint256 feeAmount = (msg.value * Merchants[merchant].feePercent) / 10000;
            payable(Merchants[merchant].wallet).transfer(msg.value-feeAmount);
            payable(Merchants[merchant].feeDest).transfer(feeAmount);
            pushToPayments(objectID, merchant, msg.value, IERC20(WETH9));
            emit PaymentProcessed(objectID, msg.sender, msg.value, objectID);
        }

    }

    function sendERC20(string memory merchant, string memory objectID, address token, uint256 amountInMax, uint amountOut, uint24 poolFee) public isPaused(merchant) nonReentrant {
        require(Merchants[merchant].wallet != address(0), "Invalid Merchant");
        require(approvedTokens[IERC20(token)], "Invalid Token");
        require(IERC20(token).allowance(msg.sender, address(this)) >= amountInMax && amountInMax >= 10, "Insufficient allowance approval.");
        require(checkPrevious(objectID, merchant, IERC20(Merchants[merchant].tokenOut)), "Payment destination error!");

        if (token != Merchants[merchant].tokenOut){
            convetERC20forExactERC20(token, Merchants[merchant].tokenOut, amountInMax, amountOut, poolFee);

            uint256 feeAmount = (amountOut * Merchants[merchant].feePercent) / 10000;
            IERC20(Merchants[merchant].tokenOut).transfer(Merchants[merchant].wallet, amountOut - feeAmount);
            IERC20(Merchants[merchant].tokenOut).transfer(Merchants[merchant].feeDest, feeAmount);
            pushToPayments(objectID, merchant, amountOut, IERC20(Merchants[merchant].tokenOut));
        } else {
            uint256 feeAmount = (amountOut * Merchants[merchant].feePercent) / 10000;
            IERC20(Merchants[merchant].tokenOut).transferFrom(msg.sender, Merchants[merchant].wallet, amountOut - feeAmount);
            IERC20(Merchants[merchant].tokenOut).transferFrom(msg.sender, Merchants[merchant].feeDest, feeAmount);
            pushToPayments(objectID, merchant, amountOut, IERC20(Merchants[merchant].tokenOut));
        }


        emit PaymentProcessed(objectID, msg.sender, amountOut, objectID);
    }
    function sendERC20Permit(string memory merchant, string memory objectID, address token, uint256 amountInMax, uint amountOut, uint24 poolFee, bytes memory p) public isPaused(merchant) nonReentrant {
        merchantData memory merch = Merchants[merchant];
        require(merch.wallet != address(0), "Invalid Merchant");
        require(approvedTokens[IERC20(token)], "Invalid Token");
        require(checkPrevious(objectID, merchant, IERC20(merch.tokenOut)), "Payment destination error!");
        
        PermitCallData memory permitData = abi.decode(p, (PermitCallData));
        require(permitData.owner == msg.sender, "Permit owner mismatch");
        require(permitData.spender == address(this), "Permit spender mismatch");
        require(permitData.value >= amountInMax, "Permit value too low");
        ERC20Permit(token).permit(permitData.owner, permitData.spender, permitData.value, permitData.deadline, permitData.v, permitData.r, permitData.s);
        
        if (token != merch.tokenOut){
            convetERC20forExactERC20(token, merch.tokenOut, amountInMax, amountOut, poolFee);

            uint256 feeAmount = (amountOut * merch.feePercent) / 10000;
            IERC20(merch.tokenOut).transfer(merch.wallet, amountOut - feeAmount);
            IERC20(merch.tokenOut).transfer(Merchants[merchant].feeDest, feeAmount);
            pushToPayments(objectID, merchant, amountOut, IERC20(merch.tokenOut));
        } else {
            uint256 feeAmount = (amountOut * Merchants[merchant].feePercent) / 10000;
            IERC20(Merchants[merchant].tokenOut).transferFrom(msg.sender, Merchants[merchant].wallet, amountOut - feeAmount);
            IERC20(Merchants[merchant].tokenOut).transferFrom(msg.sender, Merchants[merchant].feeDest, feeAmount);
            pushToPayments(objectID, merchant, amountOut, IERC20(Merchants[merchant].tokenOut));
        }

        emit PaymentProcessed(objectID, msg.sender, amountOut, objectID);
    }


    /*
        Internal
    */

    function checkPrevious(string memory objectID, string memory merchant, IERC20 currency) internal view returns (bool) {
        if (Payments[objectID].currency == IERC20(address(0))) {
            return true;
        } else if (keccak256(bytes(merchant)) == keccak256(bytes(Payments[objectID].merchant)) && Payments[objectID].currency == currency) {
            return true;
        } else {
            return false;
        }
    }

    function pushToPayments(string memory objectID, string memory merchant, uint256 amount, IERC20 currency) internal {
        if (Payments[objectID].amount == 0){
            Payments[objectID].amount = amount;
            Payments[objectID].merchant = merchant;
            Payments[objectID].currency = currency;
        } else {
            Payments[objectID].amount += amount;
        }
    }

    function convertEthToExact(address tokenOut, uint256 tokenAmountOut, uint24 poolFee) internal  {
        require(tokenAmountOut > 0, "Must pass non 0 out amount");
        require(msg.value > 0, "Must pass non 0 ETH amount");


        uint preBalance = address(this).balance - msg.value;
        ISwapRouter.ExactOutputSingleParams memory params = ISwapRouter.ExactOutputSingleParams({
        tokenIn: WETH9,
        tokenOut: tokenOut,

        fee: poolFee,
        recipient: address(this),
        deadline: block.timestamp + 6,
        amountOut: tokenAmountOut,
        amountInMaximum: msg.value,
        sqrtPriceLimitX96: 0
        });

        uniswapRouter.exactOutputSingle{ value: msg.value }(params);
        uniswapRouter.refundETH();

        // refund leftover ETH to user
        (bool success,) = msg.sender.call{ value: (address(this).balance - preBalance) }("");
        require(success, "refund failed");
    }

    function convetERC20forExactERC20(address tokenIn, address tokenOut, uint256 amountInMaximum, uint256 exactOutputUSDC, uint24 poolFee) internal {
        TransferHelper.safeTransferFrom(tokenIn, msg.sender, address(this), amountInMaximum);
        TransferHelper.safeApprove(tokenIn, address(uniswapRouter), amountInMaximum);

        ISwapRouter.ExactOutputSingleParams memory params =
        ISwapRouter.ExactOutputSingleParams({
        tokenIn: tokenIn,
        tokenOut: tokenOut,
        fee: poolFee,
        recipient: address(this),
        deadline: block.timestamp+11,
        amountOut: exactOutputUSDC,
        amountInMaximum: amountInMaximum,
        sqrtPriceLimitX96: 0
        });

        uint256 amountUsed = uniswapRouter.exactOutputSingle(params);
        TransferHelper.safeApprove(tokenIn, address(uniswapRouter), 0);

        // Returns the unused tokens to the sender.
        if (amountUsed < amountInMaximum) {
            uint256 remaining = amountInMaximum - amountUsed;
            TransferHelper.safeTransfer(tokenIn, msg.sender, remaining);
        }
    }

    receive() payable external {}


    /*
        Setter
    */
    event MerchantModified(string indexed merchantIndex, string merchant);
    function setMerchant(string memory merchant, address wallet, address payoutToken, uint feePercent, address feeDest, bool active) external onlyAdmin {
        Merchants[merchant].wallet = wallet;
        Merchants[merchant].tokenOut = payoutToken;
        Merchants[merchant].feePercent = feePercent;
        Merchants[merchant].active = active;
        Merchants[merchant].feeDest = feeDest;

        emit MerchantModified(merchant, merchant);
    }
    event MerchantDeleted(string indexed merchantIndex, string merchant);
    function deleteMerchant(string memory merchant) external onlyAdmin {
        require(Merchants[merchant].wallet != address(0), "Merchant doesn't exist");
        Merchants[merchant].wallet = address(0);
        Merchants[merchant].tokenOut = address(0);
        Merchants[merchant].feePercent = 0;
        Merchants[merchant].active = false;
        Merchants[merchant].feeDest = address(0);
        emit MerchantDeleted(merchant, merchant);
    }

    function setApprovedToken(address token, bool state) public onlyAdmin {
        approvedTokens[IERC20(token)] = state;
    }

    function withdrawETH(address user, uint256 amount) public onlyAdmin {
        require(user != address(0) && amount > 0, "Invalid input");
        payable(user).transfer(amount);
    }

    function withdrawERC20(address user, uint256 amount, IERC20 token) public onlyAdmin {
        require(user != address(0) && amount > 0, "Invalid input");
        token.transfer(user, amount);
    }

    event Paused(bool indexed state);
    function setPaused(bool state) public onlyAdmin {
        paused = state;
        emit Paused(state);
    }
    
    event MerchantPaused(bool indexed state);
    function setMerchantPause(string calldata merchant, bool state) public onlyAdmin {
        require(Merchants[merchant].wallet != address(0), "Merchant doesn't exist");
        Merchants[merchant].active = state;
        emit MerchantPaused(state);
    }

    event PermissionSet(address indexed user, bool indexed state);
    function setAdmin(address user, bool state) public onlyAdmin {
        require(user != address(this) || user != msg.sender || user != address(0), "Invalid address.");
        admin[user] = state;
        emit PermissionSet(user, state);
    }
}
ERC20Permit.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Permit.sol)

pragma solidity ^0.8.20;

import {IERC20Permit} from "./IERC20Permit.sol";
import {ERC20} from "../ERC20.sol";
import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
import {Nonces} from "../../../utils/Nonces.sol";

/**
 * @dev Implementation 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.
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
    bytes32 private constant PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

    /**
     * @dev Permit deadline has expired.
     */
    error ERC2612ExpiredSignature(uint256 deadline);

    /**
     * @dev Mismatched signature.
     */
    error ERC2612InvalidSigner(address signer, address owner);

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) EIP712(name, "1") {}

    /**
     * @inheritdoc IERC20Permit
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        if (block.timestamp > deadline) {
            revert ERC2612ExpiredSignature(deadline);
        }

        bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        if (signer != owner) {
            revert ERC2612InvalidSigner(signer, owner);
        }

        _approve(owner, spender, value);
    }

    /**
     * @inheritdoc IERC20Permit
     */
    function nonces(address owner) public view virtual override(IERC20Permit, Nonces) returns (uint256) {
        return super.nonces(owner);
    }

    /**
     * @inheritdoc IERC20Permit
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
        return _domainSeparatorV4();
    }
}
TransferHelper.sol 60 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

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

library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) =
            token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

    /// @notice Transfers tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
    }

    /// @notice Transfers ETH to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'STE');
    }
}
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);
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
ERC20.sol 383 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.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}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * 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.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * 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 override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override 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 value {ERC20} uses, unless this function is
     * 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 override returns (uint8) {
        return 18;
    }

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

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override 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 `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

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

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` 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 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        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 `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `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.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` 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.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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);
}
IUniswapV3SwapCallback.sol 21 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;
}
Nonces.sol 46 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;

/**
 * @dev Provides tracking nonces for addresses. Nonces will only increment.
 */
abstract contract Nonces {
    /**
     * @dev The nonce used for an `account` is not the expected current nonce.
     */
    error InvalidAccountNonce(address account, uint256 currentNonce);

    mapping(address account => uint256) private _nonces;

    /**
     * @dev Returns the next unused nonce for an address.
     */
    function nonces(address owner) public view virtual returns (uint256) {
        return _nonces[owner];
    }

    /**
     * @dev Consumes a nonce.
     *
     * Returns the current value and increments nonce.
     */
    function _useNonce(address owner) internal virtual returns (uint256) {
        // For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
        // decremented or reset. This guarantees that the nonce never overflows.
        unchecked {
            // It is important to do x++ and not ++x here.
            return _nonces[owner]++;
        }
    }

    /**
     * @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
     */
    function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
        uint256 current = _useNonce(owner);
        if (nonce != current) {
            revert InvalidAccountNonce(owner, current);
        }
    }
}
EIP712.sol 104 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;
    address private immutable _CACHED_THIS;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;

    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _CACHED_THIS = address(this);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }
}
ECDSA.sol 218 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

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

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

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
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);
}
Strings.sol 75 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

Read Contract

Merchants 0x7a78be0a → address, address, uint256, address, bool
Payments 0xa249d2e9 → string, uint256, address
WETH9 0x4aa4a4fc → address
approvedTokens 0x6d1ea3fa → bool
paused 0x5c975abb → bool
uniswapRouter 0x735de9f7 → address

Write Contract 12 functions

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

deleteMerchant 0x701380e3
string merchant
initialize 0xc4d66de8
address _admin
sendERC20 0x6b9d22ed
string merchant
string objectID
address token
uint256 amountInMax
uint256 amountOut
uint24 poolFee
sendERC20Permit 0x8aa5eff4
string merchant
string objectID
address token
uint256 amountInMax
uint256 amountOut
uint24 poolFee
bytes p
sendETH 0x3b016d12
string merchant
string objectID
uint256 amountOut
uint24 poolFee
setAdmin 0x4b0bddd2
address user
bool state
setApprovedToken 0x7e6a3400
address token
bool state
setMerchant 0x873ffadd
string merchant
address wallet
address payoutToken
uint256 feePercent
address feeDest
bool active
setMerchantPause 0x103c10da
string merchant
bool state
setPaused 0x16c38b3c
bool state
withdrawERC20 0x5fc3ea0b
address user
uint256 amount
address token
withdrawETH 0x4782f779
address user
uint256 amount

Recent Transactions

No transactions found for this address