Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
extra exactOut ETH test
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz committed Sep 27, 2023
1 parent bf79df4 commit f8e453a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/forge/SwapERC20CallParameters.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

Expand Down
8 changes: 8 additions & 0 deletions test/forge/interop.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
17 changes: 17 additions & 0 deletions test/uniswapTrades.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f8e453a

Please sign in to comment.