Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume the assets held by the wrapper are the loan #12

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/erc7399
Submodule erc7399 updated 1 files
+8 −7 src/IERC7399.sol
2 changes: 1 addition & 1 deletion lib/prb-test
16 changes: 5 additions & 11 deletions src/uniswapV3/UniswapV3Wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, data);
delete _activePool;
pool.flash(address(this), amount0, amount1, abi.encode(asset0, asset1, pool.fee(), amount, data));
}

/// @inheritdoc IUniswapV3FlashCallback
Expand All @@ -106,13 +101,12 @@ 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 = address(fee0 > 0 ? IUniswapV3Pool(msg.sender).token0() : IUniswapV3Pool(msg.sender).token1());
uint256 amount = ERC20(asset).balanceOf(address(this));

bridgeToCallback(asset, amount, fee, params);
bridgeToCallback(asset, amount, fee, data);
}

function _repayTo() internal view override returns (address) {
Expand Down
8 changes: 6 additions & 2 deletions test/UniswapV3Wrapper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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), "")
});
}
}
Loading