|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | + |
| 3 | +pragma solidity ^0.8.0; |
| 4 | + |
| 5 | +import "../data/DataStore.sol"; |
| 6 | +import "../event/EventEmitter.sol"; |
| 7 | +import "../exchange/IOrderHandler.sol"; |
| 8 | +import "../order/OrderVault.sol"; |
| 9 | +import "../router/Router.sol"; |
| 10 | +import "../router/relay/GelatoRelayRouter.sol"; |
| 11 | + |
| 12 | +contract MockGelatoRelayRouter is GelatoRelayRouter { |
| 13 | + struct Nested { |
| 14 | + uint256 foo; |
| 15 | + bool bar; |
| 16 | + } |
| 17 | + |
| 18 | + constructor( |
| 19 | + Router _router, |
| 20 | + DataStore _dataStore, |
| 21 | + EventEmitter _eventEmitter, |
| 22 | + Oracle _oracle, |
| 23 | + IOrderHandler _orderHandler, |
| 24 | + OrderVault _orderVault |
| 25 | + ) |
| 26 | + GelatoRelayRouter(_router, _dataStore, _eventEmitter, _oracle, _orderHandler, _orderVault) |
| 27 | + {} |
| 28 | + |
| 29 | + function testCancelOrderSignature( |
| 30 | + RelayParams calldata relayParams, |
| 31 | + bytes32 key, |
| 32 | + address account, |
| 33 | + bytes calldata signature, |
| 34 | + uint256 userNonce, |
| 35 | + uint256 deadline, |
| 36 | + uint256 chainId |
| 37 | + ) external view { |
| 38 | + bytes32 structHash = _getCancelOrderStructHash(relayParams, key, userNonce, deadline); |
| 39 | + _handleSignature(structHash, signature, account, chainId); |
| 40 | + } |
| 41 | + |
| 42 | + function testSimpleSignature(address account, bytes calldata signature, uint256 chainId) external view { |
| 43 | + bytes32 structHash = keccak256(abi.encode(keccak256(bytes("PrimaryStruct(address account)")), account)); |
| 44 | + _handleSignature(structHash, signature, account, chainId); |
| 45 | + } |
| 46 | + |
| 47 | + function testNestedSignature( |
| 48 | + Nested memory nested, |
| 49 | + address account, |
| 50 | + bytes calldata signature, |
| 51 | + uint256 chainId |
| 52 | + ) external view { |
| 53 | + bytes32 nestedStructHash = keccak256( |
| 54 | + abi.encode(keccak256(bytes("Nested(uint256 foo,bool bar)")), nested.foo, nested.bar) |
| 55 | + ); |
| 56 | + bytes32 structHash = keccak256( |
| 57 | + abi.encode( |
| 58 | + keccak256(bytes("PrimaryStruct(address account,Nested nested)Nested(uint256 foo,bool bar)")), |
| 59 | + account, |
| 60 | + nestedStructHash |
| 61 | + ) |
| 62 | + ); |
| 63 | + _handleSignature(structHash, signature, account, chainId); |
| 64 | + } |
| 65 | + |
| 66 | + function testArraySignature( |
| 67 | + address[] memory array, |
| 68 | + address account, |
| 69 | + bytes calldata signature, |
| 70 | + uint256 chainId |
| 71 | + ) external view { |
| 72 | + bytes32 structHash = keccak256( |
| 73 | + abi.encode( |
| 74 | + keccak256(bytes("PrimaryStruct(address account,address[] array)")), |
| 75 | + account, |
| 76 | + keccak256(abi.encodePacked(array)) |
| 77 | + ) |
| 78 | + ); |
| 79 | + _handleSignature(structHash, signature, account, chainId); |
| 80 | + } |
| 81 | + |
| 82 | + function _handleSignature( |
| 83 | + bytes32 structHash, |
| 84 | + bytes calldata signature, |
| 85 | + address account, |
| 86 | + uint256 chainId |
| 87 | + ) internal view { |
| 88 | + bytes32 domainSeparator = _getDomainSeparator(chainId); |
| 89 | + bytes32 digest = ECDSA.toTypedDataHash(domainSeparator, structHash); |
| 90 | + |
| 91 | + _validateSignature(digest, signature, account); |
| 92 | + } |
| 93 | +} |
0 commit comments