From 87606b34ee23f421d42873216b05fce8a64d2e9d Mon Sep 17 00:00:00 2001 From: alcueca Date: Mon, 7 Aug 2023 07:08:16 +0100 Subject: [PATCH 1/2] Don't assume the assets held by the wrapper are the loan --- src/uniswapV3/UniswapV3Wrapper.sol | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/uniswapV3/UniswapV3Wrapper.sol b/src/uniswapV3/UniswapV3Wrapper.sol index 4440462..c97773c 100644 --- a/src/uniswapV3/UniswapV3Wrapper.sol +++ b/src/uniswapV3/UniswapV3Wrapper.sol @@ -93,7 +93,7 @@ contract UniswapV3Wrapper is BaseWrapper, IUniswapV3FlashCallback { uint256 amount1 = asset == asset1 ? amount : 0; _activePool = pool; - pool.flash(address(this), amount0, amount1, data); + pool.flash(address(this), amount0, amount1, abi.encode(asset, amount, data)); delete _activePool; } @@ -109,10 +109,9 @@ contract UniswapV3Wrapper is BaseWrapper, IUniswapV3FlashCallback { require(msg.sender == address(_activePool), "UniswapV3Wrapper: Only active pool"); uint256 fee = fee0 > 0 ? fee0 : fee1; - address asset = address(fee0 > 0 ? IUniswapV3Pool(msg.sender).token0() : IUniswapV3Pool(msg.sender).token1()); - uint256 amount = ERC20(asset).balanceOf(address(this)); + (address asset, uint256 amount, bytes memory data) = abi.decode(params, (address, uint256, bytes)); - bridgeToCallback(asset, amount, fee, params); + bridgeToCallback(asset, amount, fee, data); } function _repayTo() internal view override returns (address) { From c995bcf8d8d42dd181a0d8018f57bb16b4c7d751 Mon Sep 17 00:00:00 2001 From: alcueca Date: Tue, 8 Aug 2023 22:33:40 +0100 Subject: [PATCH 2/2] remove `_activePool` --- lib/erc7399 | 2 +- lib/prb-test | 2 +- lib/solmate | 2 +- src/uniswapV3/UniswapV3Wrapper.sol | 13 ++++--------- test/UniswapV3Wrapper.t.sol | 8 ++++++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/erc7399 b/lib/erc7399 index 69a1944..501ffde 160000 --- a/lib/erc7399 +++ b/lib/erc7399 @@ -1 +1 @@ -Subproject commit 69a194426d8d954e958b8723538bb09e4edd84b4 +Subproject commit 501ffde75d80e34915a4884ecd24cd59222b60d2 diff --git a/lib/prb-test b/lib/prb-test index 1e9ead2..8d76ad6 160000 --- a/lib/prb-test +++ b/lib/prb-test @@ -1 +1 @@ -Subproject commit 1e9ead2f7bfaedda3038081c16484b0d7d0b2712 +Subproject commit 8d76ad63d1bfa0b16bb880cfe4620a9e7e6aaa19 diff --git a/lib/solmate b/lib/solmate index bfc9c25..fadb2e2 160000 --- a/lib/solmate +++ b/lib/solmate @@ -1 +1 @@ -Subproject commit bfc9c25865a274a7827fea5abf6e4fb64fc64e6c +Subproject commit fadb2e2778adbf01c80275bfb99e5c14969d964b diff --git a/src/uniswapV3/UniswapV3Wrapper.sol b/src/uniswapV3/UniswapV3Wrapper.sol index c97773c..dda3880 100644 --- a/src/uniswapV3/UniswapV3Wrapper.sol +++ b/src/uniswapV3/UniswapV3Wrapper.sol @@ -15,9 +15,6 @@ contract UniswapV3Wrapper is BaseWrapper, IUniswapV3FlashCallback { // CONSTANTS address public immutable factory; - // ACCESS CONTROL - IUniswapV3Pool internal _activePool; - // DEFAULT ASSETS address weth; address usdc; @@ -92,9 +89,7 @@ contract UniswapV3Wrapper is BaseWrapper, IUniswapV3FlashCallback { uint256 amount0 = asset == asset0 ? amount : 0; uint256 amount1 = asset == asset1 ? amount : 0; - _activePool = pool; - pool.flash(address(this), amount0, amount1, abi.encode(asset, amount, data)); - delete _activePool; + pool.flash(address(this), amount0, amount1, abi.encode(asset0, asset1, pool.fee(), amount, data)); } /// @inheritdoc IUniswapV3FlashCallback @@ -106,11 +101,11 @@ contract UniswapV3Wrapper is BaseWrapper, IUniswapV3FlashCallback { external override { - require(msg.sender == address(_activePool), "UniswapV3Wrapper: Only active pool"); + (address asset, address other, uint24 feeTier, uint256 amount, bytes memory data) = + abi.decode(params, (address, address, uint24, uint256, bytes)); + require(msg.sender == address(_pool(asset, other, feeTier)), "UniswapV3Wrapper: Unknown pool"); uint256 fee = fee0 > 0 ? fee0 : fee1; - (address asset, uint256 amount, bytes memory data) = abi.decode(params, (address, uint256, bytes)); - bridgeToCallback(asset, amount, fee, data); } diff --git a/test/UniswapV3Wrapper.t.sol b/test/UniswapV3Wrapper.t.sol index 4256f07..333e310 100644 --- a/test/UniswapV3Wrapper.t.sol +++ b/test/UniswapV3Wrapper.t.sol @@ -81,7 +81,11 @@ contract UniswapV3WrapperTest is PRBTest, StdCheats { } function test_uniswapV3FlashCallback_permissions() public { - vm.expectRevert("UniswapV3Wrapper: Only active pool"); - wrapper.uniswapV3FlashCallback({ fee0: 0, fee1: 0, params: "" }); + vm.expectRevert("UniswapV3Wrapper: Unknown pool"); + wrapper.uniswapV3FlashCallback({ + fee0: 0, + fee1: 0, + params: abi.encode(address(usdc), address(usdt), uint24(0.0005e6), uint256(0), "") + }); } }