Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x262fBcb8dC672fD4a8471d9e25367e5Eb4901974
Balance 0 ETH
Nonce 1
Code Size 16351 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

16351 bytes
0x608060405234801561001057600080fd5b50600436106102685760003560e01c8063984bd4b211610151578063d3649d6c116100c3578063e029159211610087578063e02915921461058e578063ec87621c146105a1578063ef925399146105b6578063f25f4b56146105c9578063f7b2bf68146105e1578063fe62c28b1461063357600080fd5b8063d3649d6c14610541578063d547741f1461054a578063d73792a91461055d578063d9caed1214610566578063e026faa71461057957600080fd5b8063ac37b22611610115578063ac37b226146104e4578063ae7cabbd1461050b578063affed0e014610513578063b049cec71461051c578063b46c31a41461052f578063cfae73071461053857600080fd5b8063984bd4b21461049b5780639a48e7f9146104ae5780639debb3bd146104c1578063a217fddf146104c9578063a427b242146104d157600080fd5b80633f4ba83a116101ea5780637233a666116101ae5780637233a666146103f957806382bfefc81461040e5780638456cb591461044d57806390d49b9d1461045557806391d148541461046857806397901c5a1461047b57600080fd5b80633f4ba83a1461038c578063416553261461039457806352f7c988146103bb5780635c975abb146103ce5780635f282ba4146103d957600080fd5b8063248a9ca311610231578063248a9ca3146102f95780632aaf5ed51461032a5780632cf267011461033d5780632f2ff15d1461036657806336568abe1461037957600080fd5b8062f54e801461026d57806301ffc9a71461028257806314538128146102aa578063179ff4b2146102d15780631e12ef29146102e6575b600080fd5b61028061027b366004613265565b61063c565b005b6102956102903660046132d0565b610818565b60405190151581526020015b60405180910390f35b6102bd6102b836600461330f565b61084f565b6040516102a198979695949392919061338b565b6102d9610a52565b6040516102a191906133fd565b6102806102f436600461344a565b610ab4565b61031c61030736600461348b565b60009081526020819052604090206001015490565b6040519081526020016102a1565b6102806103383660046134a4565b610b69565b61031c61034b3660046134ef565b6001600160a01b031660009081526007602052604090205490565b61028061037436600461350c565b610d61565b61028061038736600461350c565b610d8b565b610280610e09565b61031c7fcb87858191633bd77793d261daabf61ecc1356b8074c6678235852edf88a10dc81565b6102806103c936600461353c565b610e34565b60015460ff16610295565b6103ec6103e736600461355e565b610f35565b6040516102a19190613593565b6104016112cc565b6040516102a19190613676565b6104357f0000000000000000000000009506d37f70eb4c3d79c398d326c871abbf10521d81565b6040516001600160a01b0390911681526020016102a1565b6102806112fc565b6102806104633660046134ef565b611324565b61029561047636600461350c565b611412565b61031c61048936600461348b565b60096020526000908152604090205481565b6102806104a9366004613689565b61143b565b6104356104bc36600461348b565b61189c565b61031c606481565b61031c600081565b6102806104df36600461348b565b6118c6565b61031c7f65766d2e3100000000000000000000000000000000000000000000000000000081565b600c5461031c565b61031c60055481565b61029561052a36600461373a565b61192e565b61031c60045481565b61031c60035481565b61031c60025481565b61028061055836600461350c565b61194c565b61031c61271081565b61028061057436600461376f565b611971565b610581611994565b6040516102a191906137b0565b61028061059c36600461388a565b6119a0565b61031c600080516020613f8a83398151915281565b6103ec6105c43660046134ef565b611f34565b6001546104359061010090046001600160a01b031681565b61031c6105ef3660046138ed565b825160208185018101805160088252928201958201959095209190945282518084018501805192815290850193850193909320925291526000908152604090205481565b61031c60065481565b600080516020613f8a83398151915261065481612309565b8382146106945760405162461bcd60e51b8152602060048201526009602482015268189859081a5b9c1d5d60ba1b60448201526064015b60405180910390fd5b60005b84811015610810576106d78686838181106106b4576106b4613959565b90506020028101906106c6919061396f565b6106cf916139b5565b600a90612313565b6107235760405162461bcd60e51b815260206004820152601c60248201527f436861696e20697320616c726561647920696e20746865206c69737400000000604482015260640161068b565b600086868381811061073757610737613959565b9050602002810190610749919061396f565b610752916139b5565b9050600085858481811061076857610768613959565b90506020020135600a61077b9190613acd565b600083815260096020526040902054909150156107f45760008281526009602052604090205481146107ef5760405162461bcd60e51b815260206004820152601f60248201527f63616e6e6f74206d6f64696679207468652065786368616e6765207261746500604482015260640161068b565b610806565b60008281526009602052604090208190555b5050600101610697565b505050505050565b60006001600160e01b03198216637965db0b60e01b148061084957506301ffc9a760e01b6001600160e01b03198316145b92915050565b6007602052816000526040600020818154811061086b57600080fd5b600091825260209091206008909102018054600182015460028301546003840180549396509194506001600160a01b031692916108a790613ad9565b80601f01602080910402602001604051908101604052809291908181526020018280546108d390613ad9565b80156109205780601f106108f557610100808354040283529160200191610920565b820191906000526020600020905b81548152906001019060200180831161090357829003601f168201915b50505050509080600401805461093590613ad9565b80601f016020809104026020016040519081016040528092919081815260200182805461096190613ad9565b80156109ae5780601f10610983576101008083540402835291602001916109ae565b820191906000526020600020905b81548152906001019060200180831161099157829003601f168201915b5050505050908060050180546109c390613ad9565b80601f01602080910402602001604051908101604052809291908181526020018280546109ef90613ad9565b8015610a3c5780601f10610a1157610100808354040283529160200191610a3c565b820191906000526020600020905b815481529060010190602001808311610a1f57829003601f168201915b5050505050908060060154908060070154905088565b6060600c805480602002602001604051908101604052809291908181526020018280548015610aaa57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610a8c575b5050505050905090565b600080516020613f8a833981519152610acc81612309565b60005b82811015610b6357610b0f848483818110610aec57610aec613959565b9050602002810190610afe919061396f565b610b07916139b5565b600a9061231f565b610b5b5760405162461bcd60e51b815260206004820152601c60248201527f436861696e206973206e6f7420696e20746865206c6973742079657400000000604482015260640161068b565b600101610acf565b50505050565b600080516020613f8a833981519152610b8181612309565b6000839003610bc05760405162461bcd60e51b815260206004820152600b60248201526a4e6f2072656c617965727360a81b604482015260640161068b565b6064831115610c055760405162461bcd60e51b8152602060048201526011602482015270546f6f206d616e792072656c617965727360781b604482015260640161068b565b81600003610c3e5760405162461bcd60e51b81526020600482015260066024820152651816b7b316a760d11b604482015260640161068b565b82821115610c775760405162461bcd60e51b81526020600482015260066024820152652716b7b316a760d11b604482015260640161068b565b60005b83811015610d4b5760005b84811015610d425780821480610cf95750858582818110610ca857610ca8613959565b9050602002016020810190610cbd91906134ef565b6001600160a01b0316868684818110610cd857610cd8613959565b9050602002016020810190610ced91906134ef565b6001600160a01b031614155b610d3a5760405162461bcd60e51b81526020600482015260126024820152714475706c69636174652072656c617965727360701b604482015260640161068b565b600101610c85565b50600101610c7a565b50610d58600c85856131a9565b50506006555050565b600082815260208190526040902060010154610d7c81612309565b610d86838361232b565b505050565b6001600160a01b0381163314610dfb5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161068b565b610e0582826123af565b5050565b610e11612414565b600080516020613f8a833981519152610e2981612309565b610e3161245f565b50565b600080516020613f8a833981519152610e4c81612309565b82600354141580610e5f57508160045414155b610ea35760405162461bcd60e51b8152602060048201526015602482015274466565206e756d657261746f72207265706561747360581b604482015260640161068b565b6127108310610ee65760405162461bcd60e51b815260206004820152600f60248201526e08ccaca40d2e640e8dede40d0d2ced608b1b604482015260640161068b565b6127108210610f295760405162461bcd60e51b815260206004820152600f60248201526e08ccaca40d2e640e8dede40d0d2ced608b1b604482015260640161068b565b50600391909155600455565b6001600160a01b038316600090815260076020526040902054606090610f5b8385613b13565b811015610f9d5760405162461bcd60e51b815260206004820152601060248201526f189859081bd9999cd95d0bdb1a5b5a5d60821b604482015260640161068b565b826001600160401b03811115610fb557610fb56137e8565b60405190808252806020026020018201604052801561103757816020015b611024604051806101000160405280600081526020016000815260200160006001600160a01b0316815260200160608152602001606081526020016060815260200160008152602001600081525090565b815260200190600190039081610fd35790505b50915060005b838110156112c3576001600160a01b03861660009081526007602052604090206110678287613b13565b8154811061107757611077613959565b90600052602060002090600802016040518061010001604052908160008201548152602001600182015481526020016002820160009054906101000a90046001600160a01b03166001600160a01b03166001600160a01b031681526020016003820180546110e490613ad9565b80601f016020809104026020016040519081016040528092919081815260200182805461111090613ad9565b801561115d5780601f106111325761010080835404028352916020019161115d565b820191906000526020600020905b81548152906001019060200180831161114057829003601f168201915b5050505050815260200160048201805461117690613ad9565b80601f01602080910402602001604051908101604052809291908181526020018280546111a290613ad9565b80156111ef5780601f106111c4576101008083540402835291602001916111ef565b820191906000526020600020905b8154815290600101906020018083116111d257829003601f168201915b5050505050815260200160058201805461120890613ad9565b80601f016020809104026020016040519081016040528092919081815260200182805461123490613ad9565b80156112815780601f1061125657610100808354040283529160200191611281565b820191906000526020600020905b81548152906001019060200180831161126457829003601f168201915b50505050508152602001600682015481526020016007820154815250508382815181106112b0576112b0613959565b602090810291909101015260010161103d565b50509392505050565b60606112f77f65766d2e310000000000000000000000000000000000000000000000000000006124b1565b905090565b61130461251c565b600080516020613f8a83398151915261131c81612309565b610e31612562565b600080516020613f8a83398151915261133c81612309565b6001546001600160a01b0380841661010090920416036113935760405162461bcd60e51b81526020600482015260126024820152714665652077616c6c6574207265706561747360701b604482015260640161068b565b6001600160a01b0382166113e95760405162461bcd60e51b815260206004820152601a60248201527f4665652077616c6c6574206973207a65726f2061646472657373000000000000604482015260640161068b565b50600180546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61144361251c565b61145361052a606085018561396f565b61149f5760405162461bcd60e51b815260206004820152601760248201527f4e6f7420737570706f727465642066726f6d436861696e000000000000000000604482015260640161068b565b60086114ae606085018561396f565b6040516114bc929190613b26565b90815260200160405180910390208380602001906114da919061396f565b6040516114e8929190613b26565b90815260200160405180910390206000846080013581526020019081526020016000205460001461155b5760405162461bcd60e51b815260206004820152601b60248201527f5369676e617475726520616c72656164792066756c66696c6c65640000000000604482015260640161068b565b600c5481146115a45760405162461bcd60e51b8152602060048201526015602482015274084c2c840e6d2cedcc2e8eae4cae640d8cadccee8d605b1b604482015260640161068b565b60006115b76115b285613b36565b61259d565b90506000805b838110156116a8578484828181106115d7576115d7613959565b90506020028101906115e9919061396f565b90506000036115fa576001016115bd565b600c818154811061160d5761160d613959565b6000918252602090912001546001600160a01b031661164f8487878581811061163857611638613959565b905060200281019061164a919061396f565b612684565b6001600160a01b03161461169c576116668161219f565b6040516020016116769190613be6565b60408051601f198184030181529082905262461bcd60e51b825261068b91600401613676565b600191820191016115bd565b506006548110156116f15760405162461bcd60e51b81526020600482015260136024820152724e6f7420656e6f7567682072656c617965727360681b604482015260640161068b565b436008611701606088018861396f565b60405161170f929190613b26565b908152602001604051809103902086806020019061172d919061396f565b60405161173b929190613b26565b908152604080516020928190038301902060808901356000908152925281209190915560098161176e606089018961396f565b611777916139b5565b815260208101919091526040016000908120549150611797828835613c24565b90506000612710600454836117ac9190613c24565b6117b69190613c51565b90506117da6117cb60608a0160408b016134ef565b6117d58385613c65565b6126ce565b80156117fb576001546117fb9061010090046001600160a01b0316826126ce565b61180b6060890160408a016134ef565b6001600160a01b031661182160208a018a61396f565b60405161182f929190613b26565b6040519081900390207f1a82954c00ba4231b18dbc7d7d5187028cfc140ac6efedeeb60397b8710a9d9361186660608c018c61396f565b61186e6112cc565b6118788789613c65565b8960405161188a959493929190613ca1565b60405180910390a35050505050505050565b600c81815481106118ac57600080fd5b6000918252602090912001546001600160a01b0316905081565b600080516020613f8a8339815191526118de81612309565b81600254036119285760405162461bcd60e51b81526020600482015260166024820152754c696d6974207065722073656e64207265706561747360501b604482015260640161068b565b50600255565b600061194561193d83856139b5565b600a906126f9565b9392505050565b60008281526020819052604090206001015461196781612309565b610d8683836123af565b600080516020613f8a83398151915261198981612309565b610b63848484612711565b60606112f7600a612774565b6119a861251c565b836000036119e55760405162461bcd60e51b815260206004820152600a6024820152690416d6f756e74203d20360b41b604482015260640161068b565b600254841115611a375760405162461bcd60e51b815260206004820152601960248201527f416d6f756e74206973206d6f7265207468616e206c696d697400000000000000604482015260640161068b565b8251600003611a805760405162461bcd60e51b81526020600482015260156024820152744669656c6420746f5573657220697320656d70747960581b604482015260640161068b565b611a8a828261192e565b611acf5760405162461bcd60e51b815260206004820152601660248201527510da185a5b881a5cc81b9bdd081cdd5c1c1bdc9d195960521b604482015260640161068b565b6000600981611ade84866139b5565b81526020019081526020016000205490508085611afb9190613cdc565b15611b595760405162461bcd60e51b815260206004820152602860248201527f416d6f756e74206973206e6f7420646976697369626c652062792065786368616044820152676e6765207261746560c01b606482015260840161068b565b612710611b668287613c51565b1015611bb45760405162461bcd60e51b815260206004820152601860248201527f616d6f756e74203c206665652064656e6f6d696e61746f720000000000000000604482015260640161068b565b6040516370a0823160e01b81523060048201526000907f0000000000000000000000009506d37f70eb4c3d79c398d326c871abbf10521d6001600160a01b0316906370a0823190602401602060405180830381865afa158015611c1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3f9190613cf0565b9050611c4b3387612781565b6040516370a0823160e01b81523060048201526000907f0000000000000000000000009506d37f70eb4c3d79c398d326c871abbf10521d6001600160a01b0316906370a0823190602401602060405180830381865afa158015611cb2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cd69190613cf0565b905086611ce38383613c65565b14611d1c5760405162461bcd60e51b81526020600482015260096024820152683130b2103a37b5b2b760b91b604482015260640161068b565b505060008161271060035488611d329190613c24565b611d3c9190613c51565b611d469190613c51565b90508015611d6d57600154611d6d9061010090046001600160a01b03166117d58484613c24565b336000908152600760205260409081902081516101008101909252908083611d95868b613c51565b611d9f9190613c65565b815242602082015233604082015260608101889052608001611dbf6112cc565b815260200186868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525093855250506005805460209094019392909150611e1283613d09565b909155508152436020918201528254600180820185556000948552938290208351600890920201908155908201519281019290925560408101516002830180546001600160a01b0319166001600160a01b0390921691909117905560608101519091906003820190611e849082613d68565b5060808201516004820190611e999082613d68565b5060a08201516005820190611eae9082613d68565b5060c0820151816006015560e08201518160070155505084604051611ed39190613e27565b60405180910390207f39ca9eb9de2c42145bdc9525fbfac365c3f8e2abdf97dd94e64ec1258365b9f733611f056112cc565b8787611f11878d613c65565b88604051611f2496959493929190613e43565b60405180910390a2505050505050565b6001600160a01b0381166000908152600760209081526040808320805482518185028101850190935280835260609492939192909184015b828210156121945760008481526020908190206040805161010081018252600886029092018054835260018101549383019390935260028301546001600160a01b031690820152600382018054919291606084019190611fcb90613ad9565b80601f0160208091040260200160405190810160405280929190818152602001828054611ff790613ad9565b80156120445780601f1061201957610100808354040283529160200191612044565b820191906000526020600020905b81548152906001019060200180831161202757829003601f168201915b5050505050815260200160048201805461205d90613ad9565b80601f016020809104026020016040519081016040528092919081815260200182805461208990613ad9565b80156120d65780601f106120ab576101008083540402835291602001916120d6565b820191906000526020600020905b8154815290600101906020018083116120b957829003601f168201915b505050505081526020016005820180546120ef90613ad9565b80601f016020809104026020016040519081016040528092919081815260200182805461211b90613ad9565b80156121685780601f1061213d57610100808354040283529160200191612168565b820191906000526020600020905b81548152906001019060200180831161214b57829003601f168201915b505050505081526020016006820154815260200160078201548152505081526020019060010190611f6c565b505050509050919050565b606060006121ac83612231565b60010190506000816001600160401b038111156121cb576121cb6137e8565b6040519080825280601f01601f1916602001820160405280156121f5576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846121ff57509392505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106122705772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef8100000000831061229c576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106122ba57662386f26fc10000830492506010015b6305f5e10083106122d2576305f5e100830492506008015b61271083106122e657612710830492506004015b606483106122f8576064830492506002015b600a83106108495760010192915050565b610e3181336127ad565b600061194583836127e0565b6000611945838361282f565b6123358282611412565b610e05576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561236b3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6123b98282611412565b15610e05576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff1661245d5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161068b565b565b612467612414565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b606060005b828160ff16602081106124cb576124cb613959565b1a60f81b6001600160f81b031916158015906124ea575060208160ff16105b1561250157806124f981613e90565b9150506124b6565b60405191506040820160405280825282602083015250919050565b60015460ff161561245d5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161068b565b61256a61251c565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833612494565b60006108497fcb87858191633bd77793d261daabf61ecc1356b8074c6678235852edf88a10dc836000015184602001516040516020016125dd9190613e27565b604051602081830303815290604052805190602001208560400151866060015160405160200161260d9190613e27565b60405160208183030381529060405280519060200120876080015160405160200161266996959493929190958652602086019490945260408501929092526001600160a01b03166060840152608083015260a082015260c00190565b60405160208183030381529060405280519060200120612922565b60006126c68484848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061297092505050565b949350505050565b610e057f0000000000000000000000009506d37f70eb4c3d79c398d326c871abbf10521d8383612711565b60008181526001830160205260408120541515611945565b6040516001600160a01b038316602482015260448101829052610d8690849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612994565b6060600061194583612a66565b610e057f0000000000000000000000009506d37f70eb4c3d79c398d326c871abbf10521d833084612ac2565b6127b78282611412565b610e05576127c481612afa565b6127cf836020612b0c565b604051602001611676929190613eaf565b600081815260018301602052604081205461282757508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610849565b506000610849565b60008181526001830160205260408120548015612918576000612853600183613c65565b855490915060009061286790600190613c65565b90508181146128cc57600086600001828154811061288757612887613959565b90600052602060002001549050808760000184815481106128aa576128aa613959565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806128dd576128dd613f24565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610849565b6000915050610849565b600061084961292f612ca7565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b600080600061297f8585612dce565b9150915061298c81612e13565b509392505050565b60006129e9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612f5d9092919063ffffffff16565b805190915015610d865780806020019051810190612a079190613f3a565b610d865760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161068b565b606081600001805480602002602001604051908101604052809291908181526020018280548015612ab657602002820191906000526020600020905b815481526020019060010190808311612aa2575b50505050509050919050565b6040516001600160a01b0380851660248301528316604482015260648101829052610b639085906323b872dd60e01b9060840161273d565b60606108496001600160a01b03831660145b60606000612b1b836002613c24565b612b26906002613b13565b6001600160401b03811115612b3d57612b3d6137e8565b6040519080825280601f01601f191660200182016040528015612b67576020820181803683370190505b509050600360fc1b81600081518110612b8257612b82613959565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612bb157612bb1613959565b60200101906001600160f81b031916908160001a9053506000612bd5846002613c24565b612be0906001613b13565b90505b6001811115612c58576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612c1457612c14613959565b1a60f81b828281518110612c2a57612c2a613959565b60200101906001600160f81b031916908160001a90535060049490941c93612c5181613f5c565b9050612be3565b5083156119455760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161068b565b6000306001600160a01b037f000000000000000000000000262fbcb8dc672fd4a8471d9e25367e5eb490197416148015612d0057507f000000000000000000000000000000000000000000000000000000000000000146145b15612d2a57507f2b93cb42933f872ff22df4e780dff96159a43943cd28cc992be6ac33fd64576d90565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527f9ae07bc5b995cfa8b0340c8b63e566d5c884d873bdddb1069de56e4a87caf345828401527fe6bbd6277e1bf288eed5e8d1780f9a50b239e86b153736bceebccf4ea79d90b360608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6000808251604103612e045760208301516040840151606085015160001a612df887828585612f6c565b94509450505050612e0c565b506000905060025b9250929050565b6000816004811115612e2757612e27613f73565b03612e2f5750565b6001816004811115612e4357612e43613f73565b03612e905760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161068b565b6002816004811115612ea457612ea4613f73565b03612ef15760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161068b565b6003816004811115612f0557612f05613f73565b03610e315760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b606482015260840161068b565b60606126c68484600085613030565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115612fa35750600090506003613027565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612ff7573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661302057600060019250925050613027565b9150600090505b94509492505050565b6060824710156130915760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161068b565b600080866001600160a01b031685876040516130ad9190613e27565b60006040518083038185875af1925050503d80600081146130ea576040519150601f19603f3d011682016040523d82523d6000602084013e6130ef565b606091505b50915091506131008783838761310b565b979650505050505050565b6060831561317a578251600003613173576001600160a01b0385163b6131735760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161068b565b50816126c6565b6126c6838381511561318f5781518083602001fd5b8060405162461bcd60e51b815260040161068b9190613676565b8280548282559060005260206000209081019282156131fc579160200282015b828111156131fc5781546001600160a01b0319166001600160a01b038435161782556020909201916001909101906131c9565b5061320892915061320c565b5090565b5b80821115613208576000815560010161320d565b60008083601f84011261323357600080fd5b5081356001600160401b0381111561324a57600080fd5b6020830191508360208260051b8501011115612e0c57600080fd5b6000806000806040858703121561327b57600080fd5b84356001600160401b038082111561329257600080fd5b61329e88838901613221565b909650945060208701359150808211156132b757600080fd5b506132c487828801613221565b95989497509550505050565b6000602082840312156132e257600080fd5b81356001600160e01b03198116811461194557600080fd5b6001600160a01b0381168114610e3157600080fd5b6000806040838503121561332257600080fd5b823561332d816132fa565b946020939093013593505050565b60005b8381101561335657818101518382015260200161333e565b50506000910152565b6000815180845261337781602086016020860161333b565b601f01601f19169290920160200192915050565b888152602081018890526001600160a01b0387166040820152610100606082018190526000906133bd8382018961335f565b905082810360808401526133d1818861335f565b905082810360a08401526133e5818761335f565b60c0840195909552505060e001529695505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561343e5783516001600160a01b031683529284019291840191600101613419565b50909695505050505050565b6000806020838503121561345d57600080fd5b82356001600160401b0381111561347357600080fd5b61347f85828601613221565b90969095509350505050565b60006020828403121561349d57600080fd5b5035919050565b6000806000604084860312156134b957600080fd5b83356001600160401b038111156134cf57600080fd5b6134db86828701613221565b909790965060209590950135949350505050565b60006020828403121561350157600080fd5b8135611945816132fa565b6000806040838503121561351f57600080fd5b823591506020830135613531816132fa565b809150509250929050565b6000806040838503121561354f57600080fd5b50508035926020909101359150565b60008060006060848603121561357357600080fd5b833561357e816132fa565b95602085013595506040909401359392505050565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b8381101561366857888303603f190185528151805184528781015188850152868101516001600160a01b03811688860152610100905060608083015182828801526136078388018261335f565b9250505060808083015186830382880152613622838261335f565b9250505060a0808301518683038288015261363d838261335f565b60c0858101519089015260e094850151949097019390935250505093860193908601906001016135ba565b509098975050505050505050565b602081526000611945602083018461335f565b60008060006040848603121561369e57600080fd5b83356001600160401b03808211156136b557600080fd5b9085019060a082880312156136c957600080fd5b909350602085013590808211156136df57600080fd5b506136ec86828701613221565b9497909650939450505050565b60008083601f84011261370b57600080fd5b5081356001600160401b0381111561372257600080fd5b602083019150836020828501011115612e0c57600080fd5b6000806020838503121561374d57600080fd5b82356001600160401b0381111561376357600080fd5b61347f858286016136f9565b60008060006060848603121561378457600080fd5b833561378f816132fa565b9250602084013561379f816132fa565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b8181101561343e578351835292840192918401916001016137cc565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261380f57600080fd5b81356001600160401b0380821115613829576138296137e8565b604051601f8301601f19908116603f01168101908282118183101715613851576138516137e8565b8160405283815286602085880101111561386a57600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600080606085870312156138a057600080fd5b8435935060208501356001600160401b03808211156138be57600080fd5b6138ca888389016137fe565b945060408701359150808211156138e057600080fd5b506132c4878288016136f9565b60008060006060848603121561390257600080fd5b83356001600160401b038082111561391957600080fd5b613925878388016137fe565b9450602086013591508082111561393b57600080fd5b50613948868287016137fe565b925050604084013590509250925092565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261398657600080fd5b8301803591506001600160401b038211156139a057600080fd5b602001915036819003821315612e0c57600080fd5b8035602083101561084957600019602084900360031b1b1692915050565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115613a24578160001904821115613a0a57613a0a6139d3565b80851615613a1757918102915b93841c93908002906139ee565b509250929050565b600082613a3b57506001610849565b81613a4857506000610849565b8160018114613a5e5760028114613a6857613a84565b6001915050610849565b60ff841115613a7957613a796139d3565b50506001821b610849565b5060208310610133831016604e8410600b8410161715613aa7575081810a610849565b613ab183836139e9565b8060001904821115613ac557613ac56139d3565b029392505050565b60006119458383613a2c565b600181811c90821680613aed57607f821691505b602082108103613b0d57634e487b7160e01b600052602260045260246000fd5b50919050565b80820180821115610849576108496139d3565b8183823760009101908152919050565b600060a08236031215613b4857600080fd5b60405160a081016001600160401b038282108183111715613b6b57613b6b6137e8565b81604052843583526020850135915080821115613b8757600080fd5b613b93368387016137fe565b602084015260408501359150613ba8826132fa565b8160408401526060850135915080821115613bc257600080fd5b50613bcf368286016137fe565b606083015250608092830135928101929092525090565b75084c2c840e6d2cedcc2e8eae4ca40c2e840d2dcc8caf60531b815260008251613c1781601685016020870161333b565b9190910160160192915050565b8082028115828204841417610849576108496139d3565b634e487b7160e01b600052601260045260246000fd5b600082613c6057613c60613c3b565b500490565b81810381811115610849576108496139d3565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b608081526000613cb5608083018789613c78565b8281036020840152613cc7818761335f565b60408401959095525050606001529392505050565b600082613ceb57613ceb613c3b565b500690565b600060208284031215613d0257600080fd5b5051919050565b600060018201613d1b57613d1b6139d3565b5060010190565b601f821115610d8657600081815260208120601f850160051c81016020861015613d495750805b601f850160051c820191505b8181101561081057828155600101613d55565b81516001600160401b03811115613d8157613d816137e8565b613d9581613d8f8454613ad9565b84613d22565b602080601f831160018114613dca5760008415613db25750858301515b600019600386901b1c1916600185901b178555610810565b600085815260208120601f198616915b82811015613df957888601518255948401946001909101908401613dda565b5085821015613e175787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60008251613e3981846020870161333b565b9190910192915050565b6001600160a01b038716815260a060208201819052600090613e679083018861335f565b8281036040840152613e7a818789613c78565b6060840195909552505060800152949350505050565b600060ff821660ff8103613ea657613ea66139d3565b60010192915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351613ee781601785016020880161333b565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351613f1881602884016020880161333b565b01602801949350505050565b634e487b7160e01b600052603160045260246000fd5b600060208284031215613f4c57600080fd5b8151801515811461194557600080fd5b600081613f6b57613f6b6139d3565b506000190190565b634e487b7160e01b600052602160045260246000fdfe241ecf16d79d0f8dbfb92cbc07fe17840425976cf0667f022fe9877caa831b08a26469706673582212206824ed0b6442d163e718809ffae55bc053d3b34df70ae6502ba3a48f48c9a78664736f6c63430008120033

Verified Source Code Full Match

Compiler: v0.8.18+commit.87f61d96 EVM: paris Optimization: Yes (200 runs)
BridgeAssist.sol 511 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.18;

import '@openzeppelin/contracts/access/AccessControl.sol';
import '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts/security/Pausable.sol';
import '@openzeppelin/contracts/utils/Strings.sol';
import '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';
import '@openzeppelin/contracts/utils/cryptography/EIP712.sol';

/// @title BridgeAssist
/// @author gotbit
/// @dev Contract for sending tokens between chains assisted by a relayer,
/// supporting fee on send/fulfill, supporting multiple chains including
/// non-EVM blockchains, with a configurable limit per send and exchange rate
/// between chains.
contract BridgeAssist is AccessControl, Pausable, EIP712 {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    struct Transaction {
        uint256 amount;
        uint256 timestamp;
        address fromUser;
        string toUser; // can be a solana address
        string fromChain;
        string toChain;
        uint256 nonce;
        uint256 block;
    }

    struct FulfillTx {
        uint256 amount;
        string fromUser; // can be a solana address
        address toUser;
        string fromChain;
        uint256 nonce;
    }

    bytes32 public constant FULFILL_TX_TYPEHASH =
        keccak256(
            'FulfillTx(uint256 amount,string fromUser,address toUser,string fromChain,uint256 nonce)'
        );
    bytes32 public constant MANAGER_ROLE = keccak256('MANAGER_ROLE');
    uint256 public constant FEE_DENOMINATOR = 10000;
    uint256 public constant MAX_RELAYERS = 100;
    bytes32 public immutable CURRENT_CHAIN_B32;
    IERC20 public immutable TOKEN;

    address public feeWallet;
    uint256 public limitPerSend; // maximum amount of tokens that can be sent in 1 tx
    uint256 public feeSend;
    uint256 public feeFulfill;
    uint256 public nonce;
    uint256 public relayerConsensusThreshold;

    mapping(address => Transaction[]) public transactions;
    mapping(string => mapping(string => mapping(uint256 => uint256))) public fulfilledAt;
    mapping(bytes32 => uint256) public exchangeRateFrom;

    EnumerableSet.Bytes32Set private availableChainsToSend;
    address[] public relayers;

    event SentTokens(
        address fromUser,
        string indexed toUser,
        string fromChain,
        string toChain,
        uint256 amount,
        uint256 exchangeRate
    );

    event FulfilledTokens(
        string indexed fromUser,
        address indexed toUser,
        string fromChain,
        string toChain,
        uint256 amount,
        uint256 exchangeRate
    );

    /// @param relayers_ list of relayers with NO DUPLICATES!!
    /// the check is not done for gas efficiency reasons
    constructor(
        IERC20 token,
        uint256 limitPerSend_,
        address feeWallet_,
        uint256 feeSend_,
        uint256 feeFulfill_,
        address owner,
        address[] memory relayers_,
        uint256 relayerConsensusThreshold_
    ) EIP712('BridgeAssist', '1.0') {
        require(address(token) != address(0), 'Token is zero address');
        require(feeWallet_ != address(0), 'Fee wallet is zero address');
        require(feeSend_ < FEE_DENOMINATOR, 'Fee send is too high');
        require(feeFulfill_ < FEE_DENOMINATOR, 'Fee fulfill is too high');
        require(owner != address(0), 'Owner is zero address');
        require(relayers_.length != 0, 'No relayers');
        require(relayers_.length <= MAX_RELAYERS, 'Too many relayers');
        require(relayerConsensusThreshold_ != 0, '0-of-N');
        require(relayerConsensusThreshold_ <= relayers_.length, 'N-of-N');

        for (uint256 i = 0; i < relayers_.length; ) {
          for (uint256 j = 0; j < relayers_.length; ) {
            require(i == j || relayers_[i] != relayers_[j], 'Duplicate relayers');
            unchecked {++j;}
          }
          unchecked {++i;}
        }
        
        TOKEN = token;
        limitPerSend = limitPerSend_;
        feeWallet = feeWallet_;
        feeSend = feeSend_;
        feeFulfill = feeFulfill_;
        relayers = relayers_;
        relayerConsensusThreshold = relayerConsensusThreshold_;

        _grantRole(DEFAULT_ADMIN_ROLE, owner);
        CURRENT_CHAIN_B32 = bytes32(
            bytes.concat('evm.', bytes(Strings.toString(uint256(block.chainid))))
        );
    }

    /// @dev sends the user's tokens to another chain
    /// @param amount amount of tokens being sent
    /// @param toUser address of user on target chain
    /// @param toChain name of target chain (e.g. "evm.97", "sol.mainnet-beta")
    function send(
        uint256 amount,
        string memory toUser, // marked as memory to prevent "stack too deep"
        string calldata toChain
    ) external whenNotPaused {
        require(amount != 0, 'Amount = 0');
        require(amount <= limitPerSend, 'Amount is more than limit');
        require(bytes(toUser).length != 0, 'Field toUser is empty');
        require(isSupportedChain(toChain), 'Chain is not supported');

        uint256 exchangeRate = exchangeRateFrom[bytes32(bytes(toChain))];
        require(amount % exchangeRate == 0, 'Amount is not divisible by exchange rate');
        // minimum amount to make sure satisfactory amount of fee is taken
        require(amount / exchangeRate >= FEE_DENOMINATOR, 'amount < fee denominator');

        {
          uint256 balanceBefore = TOKEN.balanceOf(address(this));
          _receiveTokens(msg.sender, amount);
          uint256 balanceAfter = TOKEN.balanceOf(address(this));

          require(balanceAfter - balanceBefore == amount, 'bad token');
        }

        // the fee recipient eats the precision loss
        uint256 currentFee = (amount * feeSend) / FEE_DENOMINATOR / exchangeRate;
        if (currentFee != 0) _dispenseTokens(feeWallet, currentFee * exchangeRate);

        transactions[msg.sender].push(
            Transaction({
                fromUser: msg.sender,
                toUser: toUser,
                amount: amount / exchangeRate - currentFee,
                // No logic of the system relies on this timestamp,
                // it's only needed for displaying on the frontend
                timestamp: block.timestamp,
                fromChain: CURRENT_CHAIN(),
                toChain: toChain,
                nonce: nonce++,
                block: block.number
            })
        );
        emit SentTokens(
            msg.sender,
            toUser,
            CURRENT_CHAIN(),
            toChain,
            // amount emitted is different than amount in the struct
            // because this is the amount that actually gets sent on this chain
            // it doesn't matter that much anyways since you can always get
            // the exchangeRate and do all the calculations yourself
            (amount - currentFee),
            exchangeRate
        );
    }

    /// @dev fulfills a bridge transaction from another chain
    /// @param transaction bridge transaction to fulfill
    /// @param signatures signatures for `transaction` signed by `relayers` where
    /// `signatures[i]` is either a signature by `relayers[i]` or an empty array
    function fulfill(FulfillTx calldata transaction, bytes[] calldata signatures)
        external
        whenNotPaused
    {
        require(isSupportedChain(transaction.fromChain), 'Not supported fromChain');
        require(
          fulfilledAt[transaction.fromChain][transaction.fromUser][transaction.nonce] == 0,
          'Signature already fulfilled'
        );
        require(signatures.length == relayers.length, 'Bad signatures length');

        bytes32 hashedData = _hashTransaction(transaction);
        uint256 relayerConsensus = 0;

        for (uint256 i = 0; i < signatures.length; ) {
          if (signatures[i].length == 0) {
            unchecked {++i;}
            continue;
          }
          if (_verify(hashedData, signatures[i]) != relayers[i]) {
            revert(string.concat('Bad signature at index', Strings.toString(i)));
          }
          unchecked {
            ++relayerConsensus;
            ++i;
          }
        }

        require(relayerConsensus >= relayerConsensusThreshold, 'Not enough relayers');

        fulfilledAt[transaction.fromChain][transaction.fromUser][transaction.nonce] = block.number;

        uint256 exchangeRate = exchangeRateFrom[bytes32(bytes(transaction.fromChain))];
        uint256 amount = transaction.amount * exchangeRate;
        uint256 currentFee = (amount * feeFulfill) / FEE_DENOMINATOR;

        _dispenseTokens(transaction.toUser, amount - currentFee);
        if (currentFee != 0) _dispenseTokens(feeWallet, currentFee);

        emit FulfilledTokens(
            transaction.fromUser,
            transaction.toUser,
            transaction.fromChain,
            CURRENT_CHAIN(),
            // amount emitted is different than amount in the struct
            // because this is the amount that actually gets sent on this chain
            // it doesn't matter that much anyways since you can always get
            // the exchangeRate and do all the calculations yourself
            amount - currentFee,
            exchangeRate
        );
    }

    /// @dev add chains to the whitelist
    /// @param chains chains to add
    /// @param exchangeRatesFromPow exchange rates for `chains` as a power of 10.
    ///     exchange rate is a multiplier that fixes the difference
    ///     between decimals on different chains
    function addChains(string[] calldata chains, uint256[] calldata exchangeRatesFromPow)
        external
        onlyRole(MANAGER_ROLE)
    {
        require(chains.length == exchangeRatesFromPow.length, 'bad input');

        for (uint256 i; i < chains.length; ) {
            require(
                availableChainsToSend.add(bytes32(bytes(chains[i]))),
                'Chain is already in the list'
            );

            bytes32 chain = bytes32(bytes(chains[i]));
            // implicitly reverts on overflow
            uint256 exchangeRate = 10 ** exchangeRatesFromPow[i];

            if (exchangeRateFrom[chain] != 0) {
              require(exchangeRateFrom[chain] == exchangeRate, 'cannot modify the exchange rate');
            } else {
              exchangeRateFrom[chain] = exchangeRate;
            }
            unchecked {
                ++i;
            }
        }
    }

    /// @dev set the list of relayers and the consensus threshold used for fulfilling
    /// @param relayers_ list of relayers with NO DUPLICATES!!
    /// there is no check for that for gas efficiency reasons
    /// @param relayerConsensusThreshold_ number of relayers required to agree to fulfill a transaction
    function setRelayers(address[] calldata relayers_, uint256 relayerConsensusThreshold_) external onlyRole(MANAGER_ROLE) {
        require(relayers_.length != 0, 'No relayers');
        require(relayers_.length <= MAX_RELAYERS, 'Too many relayers');
        require(relayerConsensusThreshold_ != 0, '0-of-N');
        require(relayerConsensusThreshold_ <= relayers_.length, 'N-of-N');

        for (uint256 i = 0; i < relayers_.length; ) {
          for (uint256 j = 0; j < relayers_.length; ) {
            require(i == j || relayers_[i] != relayers_[j], 'Duplicate relayers');
            unchecked {++j;}
          }
          unchecked {++i;}
        }

        relayers = relayers_;
        relayerConsensusThreshold = relayerConsensusThreshold_;
    }

    /// @dev remove chains from the whitelist
    /// @param chains chains to remove
    function removeChains(string[] calldata chains)
        external
        onlyRole(MANAGER_ROLE)
    {
        for (uint256 i; i < chains.length; ) {
            require(
                availableChainsToSend.remove(bytes32(bytes(chains[i]))),
                'Chain is not in the list yet'
            );
            unchecked {
                ++i;
            }
        }
    }

    /// @dev set fees for send and fulfill
    /// @param feeSend_ fee for send as numerator over FEE_DENOMINATOR
    /// @param feeFulfill_ fee for fulfill as numerator over FEE_DENOMINATOR
    function setFee(uint256 feeSend_, uint256 feeFulfill_)
        external
        onlyRole(MANAGER_ROLE)
    {
        require(
            feeSend != feeSend_ || feeFulfill != feeFulfill_,
            'Fee numerator repeats'
        );
        require(feeSend_ < FEE_DENOMINATOR, 'Fee is too high');
        require(feeFulfill_ < FEE_DENOMINATOR, 'Fee is too high');
        feeSend = feeSend_;
        feeFulfill = feeFulfill_;
    }

    /// @dev sets the wallet where fees are sent
    /// @param feeWallet_ fee wallet
    function setFeeWallet(address feeWallet_) external onlyRole(MANAGER_ROLE) {
        require(feeWallet != feeWallet_, 'Fee wallet repeats');
        require(feeWallet_ != address(0), 'Fee wallet is zero address');
        feeWallet = feeWallet_;
    }

    /// @dev sets the maximum amount of tokens that can be sent in one transaction
    /// @param limitPerSend_ limit value
    function setLimitPerSend(uint256 limitPerSend_)
        external
        onlyRole(MANAGER_ROLE)
    {
        require(limitPerSend != limitPerSend_, 'Limit per send repeats');
        limitPerSend = limitPerSend_;
    }

    /// @dev withdraw tokens from bridge
    /// @param token token to withdraw
    /// @param to the address the tokens will be sent
    /// @param amount amount to withdraw
    function withdraw(
        IERC20 token,
        address to,
        uint256 amount
    ) external onlyRole(MANAGER_ROLE) {
        SafeERC20.safeTransfer(token, to, amount);
    }

    /// @dev pausing the contract
    function pause() external whenNotPaused onlyRole(MANAGER_ROLE) {
        _pause();
    }

    /// @dev unpausing the contract
    function unpause() external whenPaused onlyRole(MANAGER_ROLE) {
        _unpause();
    }

    /// @dev getting a slice of list of user transactions
    /// @param user_ user
    /// @param offset_ start index
    /// @param limit_ length of array
    /// @return transactions_ list of user transactions
    function getUserTransactionsSlice(
        address user_,
        uint256 offset_,
        uint256 limit_
    ) external view returns (Transaction[] memory transactions_) {
        uint256 length = transactions[user_].length;
        require(length >= offset_ + limit_, 'bad offset/limit');

        transactions_ = new Transaction[](limit_);
        for (uint256 i; i < limit_; ) {
            transactions_[i] = transactions[user_][offset_ + i];
            unchecked {
                ++i;
            }
        }
    }

    /// @dev returns a list of bridge transactions sent by `user`
    ///   from the current chain
    /// @param user sender address
    /// @return list of transactions
    function getUserTransactions(address user)
        external
        view
        returns (Transaction[] memory)
    {
        return transactions[user];
    }

    /// @dev returns the amount of bridge transactions sent by `user`
    ///   from the current chain
    /// @param user user
    /// @return amount of transactions
    function getUserTransactionsAmount(address user)
        external
        view
        returns (uint256)
    {
        return transactions[user].length;
    }

    /// @dev getting a list of supported chains
    /// @return list of supported chains
    function supportedChainList() external view returns (bytes32[] memory) {
        return availableChainsToSend.values();
    }

    /// @return amount of relayers
    function relayersLength() external view returns (uint256) {
      return relayers.length;
    }

    /// @return list of relayers
    function getRelayers() external view returns (address[] memory) {
      return relayers;
    }

    /// @dev getting if chain is supported
    /// @return is chain supported
    function isSupportedChain(string calldata chain) public view returns (bool) {
        return availableChainsToSend.contains(bytes32(bytes(chain)));
    }

    /// @dev Returns the current chain name as a string.
    /// @return name of the current chain
    function CURRENT_CHAIN() public view returns (string memory) {
        return _toString(CURRENT_CHAIN_B32);
    }

    /// @dev receive `amount` of tokens from address `user`
    /// @param from address to take tokens from
    /// @param amount amount of tokens to take
    function _receiveTokens(address from, uint256 amount) private {
        SafeERC20.safeTransferFrom(TOKEN, from, address(this), amount);
    }

    /// @dev dispense `amount` of tokens to address `to`
    /// @param to address to dispense tokens to
    /// @param amount amount of tokens to dispense
    function _dispenseTokens(address to, uint256 amount) private {
        SafeERC20.safeTransfer(TOKEN, to, amount);
    }

    /// @dev hashes `Transaction` structure with EIP-712 standard
    /// @param transaction `Transaction` structure
    /// @return hash hashed `Transaction` structure
    function _hashTransaction(FulfillTx memory transaction)
        private
        view
        returns (bytes32)
    {
        return
            _hashTypedDataV4(
                keccak256(
                    abi.encode(
                        FULFILL_TX_TYPEHASH,
                        transaction.amount,
                        keccak256(abi.encodePacked(transaction.fromUser)),
                        transaction.toUser,
                        keccak256(abi.encodePacked(transaction.fromChain)),
                        transaction.nonce
                    )
                )
            );
    }

    /// @dev verify whether `signature` of `data` is valid and return the signer address
    /// @param data keccak256 hash of the signed data
    /// @param signature signature of `data`
    /// @return the signer address
    function _verify(bytes32 data, bytes calldata signature)
        private
        pure
        returns (address)
    {
        return ECDSA.recover(data, signature);
    }

    /// @dev converts a null-terminated 32-byte string to a variable length string
    /// @param source null-terminated 32-byte string
    /// @return result a variable length null-terminated string
    function _toString(bytes32 source) private pure returns (string memory result) {
        uint8 length = 0;
        while (source[length] != 0 && length < 32) {
            length++;
        }
        assembly {
            result := mload(0x40)
            // new "memory end" including padding (the string isn't larger than 32 bytes)
            mstore(0x40, add(result, 0x40))
            // store length in memory
            mstore(result, length)
            // write actual data
            mstore(add(result, 0x20), source)
        }
    }
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [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://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

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

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return 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);
        }
    }
}
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;
    }
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _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) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        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] = _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);
    }
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}
Pausable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
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);
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(account),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}
ECDSA.sol 213 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (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 // Deprecated in v4.8
    }

    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");
        }
    }

    /**
     * @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 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));
    }
}
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);
    }
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

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

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

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

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    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");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    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");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
EnumerableSet.sol 378 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [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;
    }
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

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

Read Contract

CURRENT_CHAIN 0x7233a666 → string
CURRENT_CHAIN_B32 0xac37b226 → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
FEE_DENOMINATOR 0xd73792a9 → uint256
FULFILL_TX_TYPEHASH 0x41655326 → bytes32
MANAGER_ROLE 0xec87621c → bytes32
MAX_RELAYERS 0x9debb3bd → uint256
TOKEN 0x82bfefc8 → address
exchangeRateFrom 0x97901c5a → uint256
feeFulfill 0xb46c31a4 → uint256
feeSend 0xcfae7307 → uint256
feeWallet 0xf25f4b56 → address
fulfilledAt 0xf7b2bf68 → uint256
getRelayers 0x179ff4b2 → address[]
getRoleAdmin 0x248a9ca3 → bytes32
getUserTransactions 0xef925399 → tuple[]
getUserTransactionsAmount 0x2cf26701 → uint256
getUserTransactionsSlice 0x5f282ba4 → tuple[]
hasRole 0x91d14854 → bool
isSupportedChain 0xb049cec7 → bool
limitPerSend 0xd3649d6c → uint256
nonce 0xaffed0e0 → uint256
paused 0x5c975abb → bool
relayerConsensusThreshold 0xfe62c28b → uint256
relayers 0x9a48e7f9 → address
relayersLength 0xae7cabbd → uint256
supportedChainList 0xe026faa7 → bytes32[]
supportsInterface 0x01ffc9a7 → bool
transactions 0x14538128 → uint256, uint256, address, string, string, string, uint256, uint256

Write Contract 14 functions

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

addChains 0x00f54e80
string[] chains
uint256[] exchangeRatesFromPow
fulfill 0x39118bf4
tuple transaction
bytes[] signatures
grantRole 0x2f2ff15d
bytes32 role
address account
pause 0x8456cb59
No parameters
removeChains 0x1e12ef29
string[] chains
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
send 0xe0291592
uint256 amount
string toUser
string toChain
setFee 0x52f7c988
uint256 feeSend_
uint256 feeFulfill_
setFeeWallet 0x90d49b9d
address feeWallet_
setLimitPerSend 0xa427b242
uint256 limitPerSend_
setRelayers 0x2aaf5ed5
address[] relayers_
uint256 relayerConsensusThreshold_
unpause 0x3f4ba83a
No parameters
withdraw 0xd9caed12
address token
address to
uint256 amount

Recent Transactions

No transactions found for this address