Skip to content

Commit

Permalink
fix(hardhat): fix uniswapV2LikeExactInput with eth input
Browse files Browse the repository at this point in the history
  • Loading branch information
xykota committed Nov 9, 2023
1 parent d491fef commit d30086a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/hardhat/contracts/facets/UniV2LikeFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ contract UniV2LikeFacet is IUniV2Like {
tokens[0] = address(s.weth);
}

if (isFromEth) {
params.tokens[0] = address(s.weth);
}

uint256 tokenOutBalancePrev = isToEth
? address(this).balance
: IERC20(tokens[poolLength]).balanceOf(address(this));
Expand Down
38 changes: 38 additions & 0 deletions packages/hardhat/test/foundry/UniV2LikeFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,44 @@ contract UniV2LikeFacetTest is UniV2LikeFacetTestBase {
);
}

function testFork_uniswapV2LikeExactInput_sushiEthToUsdc() public {
deal(user, 1 ether);

address pool = getPair(
Mainnet.SUSHISWAP_V2_FACTORY,
address(Mainnet.WETH),
address(Mainnet.USDC)
);

address[] memory pools = new address[](1);
pools[0] = pool;

address[] memory tokens = new address[](2);
tokens[0] = address(0);
tokens[1] = address(Mainnet.USDC);

uint16[] memory poolFeesBps = new uint16[](2);
poolFeesBps[0] = 30;
poolFeesBps[1] = 30;

vm.prank(user);
facet.uniswapV2LikeExactInput{value: 1 ether}(
IUniV2Like.ExactInputParams({
amountIn: 1 ether,
amountOut: 1830 * (10 ** 6),
recipient: user,
slippageBps: 50,
feeBps: 10,
deadline: deadline,
partner: address(0),
tokens: tokens,
pools: pools,
poolFeesBps: poolFeesBps
}),
emptyPermitParams
);
}

function testFork_uniswapV2LikeExactInputSingle_sushiWethToUsdc() public {
address pool = getPair(
Mainnet.SUSHISWAP_V2_FACTORY,
Expand Down

0 comments on commit d30086a

Please sign in to comment.