feat: support multi swap decoding
This commit is contained in:
@@ -9,9 +9,7 @@ import {console} from "forge-std/console.sol";
|
||||
contract UniswapV4ExecutorExposed is UniswapV4Executor {
|
||||
constructor(IPoolManager _poolManager) UniswapV4Executor(_poolManager) {}
|
||||
|
||||
function decodeData(
|
||||
bytes calldata data
|
||||
)
|
||||
function decodeData(bytes calldata data)
|
||||
external
|
||||
pure
|
||||
returns (
|
||||
@@ -20,7 +18,10 @@ contract UniswapV4ExecutorExposed is UniswapV4Executor {
|
||||
uint24 fee,
|
||||
address receiver,
|
||||
bool zeroForOne,
|
||||
uint24 tickSpacing
|
||||
uint24 tickSpacing,
|
||||
bool isExactInput,
|
||||
bool isSingle,
|
||||
uint256 amount
|
||||
)
|
||||
{
|
||||
return _decodeData(data);
|
||||
@@ -38,14 +39,14 @@ contract UniswapV4ExecutorTest is Test, Constants {
|
||||
function setUp() public {
|
||||
uint256 forkBlock = 21817316;
|
||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||
uniswapV4Exposed = new UniswapV4ExecutorExposed(
|
||||
IPoolManager(poolManager)
|
||||
);
|
||||
uniswapV4Exposed =
|
||||
new UniswapV4ExecutorExposed(IPoolManager(poolManager));
|
||||
}
|
||||
|
||||
function testDecodeParamsUniswapV4() public view {
|
||||
uint24 expectedPoolFee = 500;
|
||||
address expectedReceiver = address(2);
|
||||
uint128 expectedAmount = 100;
|
||||
|
||||
bytes memory data = _encodeExactInputSingle(
|
||||
USDE_ADDR,
|
||||
@@ -54,7 +55,7 @@ contract UniswapV4ExecutorTest is Test, Constants {
|
||||
expectedReceiver,
|
||||
false,
|
||||
1,
|
||||
100 // amountIn doesn't matter for this test
|
||||
expectedAmount
|
||||
);
|
||||
|
||||
(
|
||||
@@ -63,7 +64,10 @@ contract UniswapV4ExecutorTest is Test, Constants {
|
||||
uint24 fee,
|
||||
address receiver,
|
||||
bool zeroForOne,
|
||||
uint24 tickSpacing
|
||||
uint24 tickSpacing,
|
||||
bool isExactInput,
|
||||
bool isSingle,
|
||||
uint256 amount
|
||||
) = uniswapV4Exposed.decodeData(data);
|
||||
|
||||
assertEq(tokenIn, USDE_ADDR);
|
||||
@@ -72,6 +76,9 @@ contract UniswapV4ExecutorTest is Test, Constants {
|
||||
assertEq(receiver, expectedReceiver);
|
||||
assertEq(zeroForOne, false);
|
||||
assertEq(tickSpacing, 1);
|
||||
assertTrue(isExactInput);
|
||||
assertTrue(isSingle);
|
||||
assertEq(amount, expectedAmount);
|
||||
}
|
||||
|
||||
function testSwapUniswapV4() public {
|
||||
@@ -79,21 +86,14 @@ contract UniswapV4ExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 100 ether;
|
||||
deal(USDE_ADDR, address(uniswapV4Exposed), amountIn);
|
||||
uint256 usdeBalanceBeforePool = USDE.balanceOf(poolManager);
|
||||
uint256 usdeBalanceBeforeSwapExecutor = USDE.balanceOf(
|
||||
address(uniswapV4Exposed)
|
||||
);
|
||||
uint256 usdeBalanceBeforeSwapExecutor =
|
||||
USDE.balanceOf(address(uniswapV4Exposed));
|
||||
assertEq(usdeBalanceBeforeSwapExecutor, amountIn);
|
||||
uint256 usdtBalanceBeforeSwapBob = USDT.balanceOf(address(BOB));
|
||||
assertEq(usdtBalanceBeforeSwapBob, 0);
|
||||
|
||||
bytes memory data = _encodeExactInputSingle(
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
100,
|
||||
BOB,
|
||||
true,
|
||||
1,
|
||||
uint128(amountIn)
|
||||
USDE_ADDR, USDT_ADDR, 100, BOB, true, 1, uint128(amountIn)
|
||||
);
|
||||
|
||||
uint256 amountOut = uniswapV4Exposed.swap(amountIn, data);
|
||||
|
||||
Reference in New Issue
Block a user