diff --git a/test/forge/SwapERC20CallParameters.t.sol b/test/forge/SwapERC20CallParameters.t.sol index 66e5b346..bf9ca41a 100644 --- a/test/forge/SwapERC20CallParameters.t.sol +++ b/test/forge/SwapERC20CallParameters.t.sol @@ -244,7 +244,7 @@ contract SwapERC20CallParametersTest is Test, Interop, DeployRouter { assertEq(address(router).balance, 0); } - function testV2ExactOutputSingleNativeWithFlatFee() public { + function testV2ExactOutputSingleNativeInputWithFlatFee() public { MethodParameters memory params = readFixture(json, "._UNISWAP_V2_ETH_FOR_1000_USDC_WITH_FLAT_FEE"); uint256 outputAmount = 1000 * ONE_USDC; @@ -263,6 +263,27 @@ contract SwapERC20CallParametersTest is Test, Interop, DeployRouter { assertEq(address(router).balance, 0); } + function testV2ExactOutputSingleNativeOutputWithFlatFee() public { + MethodParameters memory params = readFixture(json, "._UNISWAP_V2_USCD_FOR_10_ETH_WITH_FLAT_FEE"); + + deal(address(USDC), from, BALANCE); + USDC.approve(address(permit2), BALANCE); + permit2.approve(address(USDC), address(router), uint160(BALANCE), uint48(block.timestamp + 1000)); + + uint256 outputAmount = 10 ether; + uint256 feeAmount = 5 ether; + + assertEq(WETH.balanceOf(FEE_RECIPIENT), 0); + uint256 recipientBalanceBefore = RECIPIENT.balance; + + (bool success,) = address(router).call{value: params.value}(params.data); + require(success, "call failed"); + assertGt(RECIPIENT.balance - recipientBalanceBefore, outputAmount); // tiny imprecision with exactOut + assertEq(WETH.balanceOf(FEE_RECIPIENT), feeAmount); + assertEq(WETH.balanceOf(address(router)), 0); + assertEq(address(router).balance, 0); + } + function testV2ExactOutputSingleERC20() public { MethodParameters memory params = readFixture(json, "._UNISWAP_V2_USDC_FOR_1_ETH"); diff --git a/test/forge/interop.json b/test/forge/interop.json index 407886ec..592fc43e 100644 --- a/test/forge/interop.json +++ b/test/forge/interop.json @@ -234,5 +234,13 @@ "_UNISWAP_V3_1_ETH_FOR_USDC_WITH_FLAT_FEE": { "calldata": "0x24856bc30000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000040b000504000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000044f7ce0000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb8a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000000000000000000000000000000000000000000000000000044f7ce00", "value": "1000000000000000000" + }, + "_UNISWAP_V2_USCD_FOR_1_ETH_WITH_FLAT_FEE": { + "calldata": "0x24856bc300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000309050c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000d02ab486cedc0000000000000000000000000000000000000000000000000000000000047ab1042900000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000000000000000000000000000000000004563918244f400000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000000000000000000000000000000000000000000008ac7230489e80000", + "value": "0" + }, + "_UNISWAP_V2_USCD_FOR_10_ETH_WITH_FLAT_FEE": { + "calldata": "0x24856bc300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000309050c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000d02ab486cedc0000000000000000000000000000000000000000000000000000000000047ab1042900000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000000000000000000000000000000000004563918244f400000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000000000000000000000000000000000000000000008ac7230489e80000", + "value": "0" } } diff --git a/test/uniswapTrades.test.ts b/test/uniswapTrades.test.ts index 16eadce7..d4037234 100644 --- a/test/uniswapTrades.test.ts +++ b/test/uniswapTrades.test.ts @@ -268,6 +268,23 @@ describe('Uniswap', () => { expect(methodParameters.value).to.eq(methodParametersV2.value) }) + it('encodes a single exactOutput USDC->ETH swap, with a flat fee', async () => { + const outputUSDC = utils.parseUnits('15', 18).toString() + const trade = new V2Trade( + new RouteV2([WETH_USDC_V2], USDC, ETHER), + CurrencyAmount.fromRawAmount(ETHER, outputUSDC), + TradeType.EXACT_OUTPUT + ) + const feeOptions: FlatFeeOptions = { amount: utils.parseUnits('5', 18), recipient: TEST_FEE_RECIPIENT_ADDRESS } + const opts = swapOptions({ flatFee: feeOptions }) + const methodParameters = SwapRouter.swapERC20CallParameters(buildTrade([trade]), opts) + const methodParametersV2 = SwapRouter.swapCallParameters(new UniswapTrade(buildTrade([trade]), opts)) + registerFixture('_UNISWAP_V2_USCD_FOR_10_ETH_WITH_FLAT_FEE', methodParametersV2) + expect(hexToDecimalString(methodParameters.value)).to.equal('0') + expect(methodParameters.calldata).to.eq(methodParametersV2.calldata) + expect(methodParameters.value).to.eq(methodParametersV2.value) + }) + it('encodes a single exactOutput USDC->ETH swap', async () => { const outputETH = utils.parseEther('1').toString() const trade = new V2Trade(