|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import { Test } from "forge-std/Test.sol"; |
| 5 | +import { MockSpokePool } from "../../../../contracts/test/MockSpokePool.sol"; |
| 6 | +import { WETH9 } from "../../../../contracts/external/WETH9.sol"; |
| 7 | +import { AddressToBytes32 } from "../../../../contracts/libraries/AddressConverters.sol"; |
| 8 | +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; |
| 9 | + |
| 10 | +// Deprecated interface used to show that we can still call deposit() on the spoke, which should route internally to the |
| 11 | +// colliding function interface selector on depositDeprecated_5947912356 enabling legacy deposits to still work without |
| 12 | +// breaking interface changes. |
| 13 | +interface DeprecatedSpokePoolInterface { |
| 14 | + function deposit( |
| 15 | + address recipient, |
| 16 | + address originToken, |
| 17 | + uint256 amount, |
| 18 | + uint256 destinationChainId, |
| 19 | + int64 relayerFeePct, |
| 20 | + uint32 quoteTimestamp, |
| 21 | + bytes memory message, |
| 22 | + uint256 |
| 23 | + ) external payable; |
| 24 | +} |
| 25 | + |
| 26 | +contract SpokePoolOverloadedDeprecatedMethodsTest is Test { |
| 27 | + using AddressToBytes32 for address; |
| 28 | + |
| 29 | + MockSpokePool spokePool; |
| 30 | + WETH9 mockWETH; |
| 31 | + |
| 32 | + address depositor; |
| 33 | + address owner; |
| 34 | + |
| 35 | + uint256 destinationChainId = 10; |
| 36 | + uint256 depositAmount = 0.5 * (10**18); |
| 37 | + |
| 38 | + function setUp() public { |
| 39 | + mockWETH = new WETH9(); |
| 40 | + |
| 41 | + depositor = vm.addr(1); |
| 42 | + owner = vm.addr(2); |
| 43 | + |
| 44 | + vm.startPrank(owner); |
| 45 | + ERC1967Proxy proxy = new ERC1967Proxy( |
| 46 | + address(new MockSpokePool(address(mockWETH))), |
| 47 | + abi.encodeCall(MockSpokePool.initialize, (0, owner, address(420))) |
| 48 | + ); |
| 49 | + spokePool = MockSpokePool(payable(proxy)); |
| 50 | + |
| 51 | + spokePool.setEnableRoute(address(mockWETH), destinationChainId, true); |
| 52 | + |
| 53 | + vm.stopPrank(); |
| 54 | + |
| 55 | + deal(depositor, depositAmount * 2); |
| 56 | + |
| 57 | + vm.startPrank(depositor); |
| 58 | + mockWETH.deposit{ value: depositAmount }(); |
| 59 | + mockWETH.approve(address(spokePool), depositAmount); |
| 60 | + vm.stopPrank(); |
| 61 | + } |
| 62 | + |
| 63 | + function testDeprecatedDeposit() public { |
| 64 | + // Here, we are calling the deprecated deposit method, as defined in the deprecated interface. This should, in |
| 65 | + // theory, collide with the function selector depositDeprecated_5947912356, thereby calling the legacy deposit |
| 66 | + // method on the spoke pool, while using the old old deposit function signature. |
| 67 | + vm.startPrank(depositor); |
| 68 | + DeprecatedSpokePoolInterface(address(spokePool)).deposit( |
| 69 | + depositor, // recipient |
| 70 | + address(mockWETH), // originToken |
| 71 | + depositAmount, // amount |
| 72 | + destinationChainId, // destinationChainId |
| 73 | + 0, // relayerFeePct |
| 74 | + uint32(block.timestamp), // quoteTimestamp |
| 75 | + bytes(""), // message |
| 76 | + 0 // maxCount |
| 77 | + ); |
| 78 | + |
| 79 | + // Test depositing native ETH directly |
| 80 | + DeprecatedSpokePoolInterface(address(spokePool)).deposit{ value: depositAmount }( |
| 81 | + depositor, // recipient |
| 82 | + address(mockWETH), // originToken - still WETH address for native deposits |
| 83 | + depositAmount, // amount |
| 84 | + destinationChainId, // destinationChainId |
| 85 | + 0, // relayerFeePct |
| 86 | + uint32(block.timestamp), // quoteTimestamp |
| 87 | + bytes(""), // message |
| 88 | + 0 // maxCount |
| 89 | + ); |
| 90 | + vm.stopPrank(); |
| 91 | + } |
| 92 | + |
| 93 | + function testBytes32Deposit() public { |
| 94 | + vm.prank(depositor); |
| 95 | + // Show the bytes32 variant of the new deposit method works. |
| 96 | + spokePool.deposit( |
| 97 | + address(depositor).toBytes32(), // depositor |
| 98 | + address(depositor).toBytes32(), // recipient |
| 99 | + address(mockWETH).toBytes32(), // inputToken |
| 100 | + address(mockWETH).toBytes32(), // outputToken |
| 101 | + depositAmount, // inputAmount |
| 102 | + 0, // outputAmount |
| 103 | + destinationChainId, // destinationChainId |
| 104 | + bytes32(0), // exclusiveRelayer |
| 105 | + uint32(block.timestamp), // quoteTimestamp |
| 106 | + uint32(block.timestamp + 1 hours), // fillDeadline |
| 107 | + 0, // exclusivityParameter |
| 108 | + bytes("") // message |
| 109 | + ); |
| 110 | + } |
| 111 | + |
| 112 | + function testAddressDeposit() public { |
| 113 | + // Show the address variant of the new deposit method works. |
| 114 | + vm.prank(depositor); |
| 115 | + spokePool.depositV3( |
| 116 | + depositor, // depositor |
| 117 | + depositor, // recipient |
| 118 | + address(mockWETH), // inputToken |
| 119 | + address(mockWETH), // outputToken |
| 120 | + depositAmount, // inputAmount |
| 121 | + 0, // outputAmount |
| 122 | + destinationChainId, // destinationChainId |
| 123 | + address(0), // exclusiveRelayer |
| 124 | + uint32(block.timestamp), // quoteTimestamp |
| 125 | + uint32(block.timestamp + 1 hours), // fillDeadline |
| 126 | + 0, // exclusivityParameter |
| 127 | + bytes("") // message |
| 128 | + ); |
| 129 | + } |
| 130 | +} |
0 commit comments