Skip to content

Commit

Permalink
Swap Router tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wirew0lf committed Aug 22, 2024
1 parent 70c4c12 commit 6d3e91f
Show file tree
Hide file tree
Showing 3 changed files with 519 additions and 227 deletions.
11 changes: 6 additions & 5 deletions AxelarHandler/src/AxelarHandler.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;

import {console} from "forge-std/console.sol";

import {IWETH} from "./interfaces/IWETH.sol";

import {IAxelarGasService} from "lib/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol";
Expand Down Expand Up @@ -361,14 +363,12 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,

/// @notice Internal function called by the AxelarExecutor when a GMP call is made to this contract.
/// @notice Receives the tokens and unwraps them if it's wrapped native currency.
/// @param sourceChain the name of the chain where the GMP message originated.
/// @param sourceAddress the address where the GMP message originated.
/// @param sourceChain the payload that was sent along with the GMP message.
/// @param payload the payload that was sent along with the GMP message.
/// @param tokenSymbol the symbol of the tokens received.
/// @param amount the amount of tokens received.
function _executeWithToken(
string calldata sourceChain,
string calldata sourceAddress,
string calldata, // sourceChain
string calldata, // sourceAddress
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
Expand Down Expand Up @@ -403,6 +403,7 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,
}
} else if (command == Commands.MultiSwap) {
(address destination, bool unwrapOut, bytes[] memory swaps) = abi.decode(data, (address, bool, bytes[]));
console.log("debug");

try SkipSwapRouter.multiSwap(swapRouter, destination, tokenIn, amount, swaps) returns (
IERC20 tokenOut, uint256 amountOut
Expand Down
12 changes: 6 additions & 6 deletions AxelarHandler/src/libraries/SkipSwapRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ library SkipSwapRouter {
router.exactInputSingle(params);
} else if (command == SwapCommands.ExactInput) {
ISwapRouter02.ExactInputParams memory params;
// params.path = _fixPath(address(inputToken), tokenOut, swapData);
params.path = _fixPath(address(inputToken), tokenOut, swapData);
params.path = swapData;
params.recipient = address(this);
params.amountIn = amountIn;
params.amountOutMinimum = amountOut;

router.exactInput(params);
} else if (command == SwapCommands.ExactTokensForTokens) {
//address[] memory path = _fixPath(address(inputToken), tokenOut, abi.decode(swapData, (address[])));
address[] memory path = _fixPath(address(inputToken), tokenOut, abi.decode(swapData, (address[])));

router.swapExactTokensForTokens(amountIn, amountOut, abi.decode(swapData, (address[])), address(this));
router.swapExactTokensForTokens(amountIn, amountOut, path, address(this));
} else if (command == SwapCommands.ExactOutputSingle) {
ISwapRouter02.ExactOutputSingleParams memory params;
params.tokenIn = address(inputToken);
Expand All @@ -91,17 +91,17 @@ library SkipSwapRouter {
router.exactOutputSingle(params);
} else if (command == SwapCommands.ExactOutput) {
ISwapRouter02.ExactOutputParams memory params;
// params.path = _fixPath(tokenOut, address(inputToken), swapData);
params.path = _fixPath(tokenOut, address(inputToken), swapData);
params.path = swapData;
params.recipient = address(this);
params.amountInMaximum = amountIn;
params.amountOut = amountOut;

router.exactOutput(params);
} else if (command == SwapCommands.TokensForExactTokens) {
//address[] memory path = _fixPath(tokenOut, address(inputToken), abi.decode(swapData, (address[])));
address[] memory path = _fixPath(address(inputToken), address(tokenOut), abi.decode(swapData, (address[])));

router.swapTokensForExactTokens(amountOut, amountIn, abi.decode(swapData, (address[])), address(this));
router.swapTokensForExactTokens(amountOut, amountIn, path, address(this));
}

outputAmount = outputToken.balanceOf(address(this)) - preBalOut;
Expand Down
Loading

0 comments on commit 6d3e91f

Please sign in to comment.