Skip to content

Red Snwapper

RedSnwapper is a facade for the execution router contracts (RouteProcessor), and handles single & multi token swaps.

Functions

snwap

function snwap(
  IERC20 tokenIn,
  uint amountIn,
  address recipient,
  IERC20 tokenOut,
  uint amountOutMin,
  address executor,
  bytes calldata executorData
) external payable returns (uint amountOut)
  1. Transfers amountIn of tokenIn to executor.
  2. Launches executor with executorData and value = msg.value.
  3. Checks that recipient's tokenOut balance increased by at least amountOutMin.

Parameters

NameTypeDescription
tokenInIERC20The token being swapped
amountInuintThe amount of tokenIn to swap (0 means take from contract balance)
recipientaddressThe address receiving the swapped tokens
tokenOutIERC20The token to receive after the swap
amountOutMinuintMinimum amount of tokenOut that must be received
executoraddressThe contract that will execute the swap logic
executorDatabytesData payload passed to the executor

Return Values

NameTypeDescription
amountOutuintThe actual amount of tokenOut received

snwapMultiple

function snwapMultiple(
  InputToken[] calldata inputTokens,
  OutputToken[] calldata outputTokens,
  Executor[] calldata executors
) external payable returns (uint[] memory amountOut)
  1. Transfers each of the inputTokens to inputTokens[i].transferTo.
  2. Launches all specified executors.
  3. Checks that the final recipient's tokenOut balance(s) are each at least their corresponding amountOutMin.

Parameters

NameTypeDescription
inputTokensInputToken[]Array of input token structs, each describing what token to transfer
outputTokensOutputToken[]Array of output token structs, each describing the expected output
executorsExecutor[]Array of executor structs to be launched sequentially

Return Values

NameTypeDescription
amountOutuint[] memoryActual amounts of each output token received

Deployments

NetworkAddress
ETHEREUM0xac4c6e212a361c968f1725b4d055b47e63f80b75
OP MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
CRONOS MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
ROOTSTOCK MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
BNB SMART CHAIN0xac4c6e212a361c968f1725b4d055b47e63f80b75
GNOSIS0xac4c6e212a361c968f1725b4d055b47e63f80b75
THUNDERCORE MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
FUSE0xac4c6e212a361c968f1725b4d055b47e63f80b75
POLYGON0xac4c6e212a361c968f1725b4d055b47e63f80b75
SONIC0xac4c6e212a361c968f1725b4d055b47e63f80b75
MANTA PACIFIC MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
BITTORRENT0xac4c6e212a361c968f1725b4d055b47e63f80b75
FANTOM0xac4c6e212a361c968f1725b4d055b47e63f80b75
BOBA NETWORK0xac4c6e212a361c968f1725b4d055b47e63f80b75
FILECOIN MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
ZKSYNC ERA0x35e98c2b3894d71d3d4d7edb8b30e4f36e2f9179
HYPEREVM0xac4c6e212a361c968f1725b4d055b47e63f80b75
METIS0xac4c6e212a361c968f1725b4d055b47e63f80b75
POLYGON ZKEVM0xac4c6e212a361c968f1725b4d055b47e63f80b75
CORE DAO0xac4c6e212a361c968f1725b4d055b47e63f80b75
KAVA EVM0xac4c6e212a361c968f1725b4d055b47e63f80b75
MANTLE0xac4c6e212a361c968f1725b4d055b47e63f80b75
ZETACHAIN0xac4c6e212a361c968f1725b4d055b47e63f80b75
BASE0xac4c6e212a361c968f1725b4d055b47e63f80b75
PLASMA0xac4c6e212a361c968f1725b4d055b47e63f80b75
HAQQ MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
APE CHAIN0xac4c6e212a361c968f1725b4d055b47e63f80b75
MODE MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
ARBITRUM ONE0xac4c6e212a361c968f1725b4d055b47e63f80b75
ARBITRUM NOVA0xac4c6e212a361c968f1725b4d055b47e63f80b75
CELO0xac4c6e212a361c968f1725b4d055b47e63f80b75
HEMI0xac4c6e212a361c968f1725b4d055b47e63f80b75
AVALANCHE0xac4c6e212a361c968f1725b4d055b47e63f80b75
BOBA BNB0xac4c6e212a361c968f1725b4d055b47e63f80b75
LINEA MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
BERACHAIN0xac4c6e212a361c968f1725b4d055b47e63f80b75
BLAST0xac4c6e212a361c968f1725b4d055b47e63f80b75
TATARA0xac4c6e212a361c968f1725b4d055b47e63f80b75
TAIKO MAINNET0xac4c6e212a361c968f1725b4d055b47e63f80b75
SCROLL0xac4c6e212a361c968f1725b4d055b47e63f80b75
KATANA0xac4c6e212a361c968f1725b4d055b47e63f80b75
ZKLINK NOVA0x35e98c2b3894d71d3d4d7edb8b30e4f36e2f9179
SEPOLIA0xac4c6e212a361c968f1725b4d055b47e63f80b75
HARMONY ONE0xac4c6e212a361c968f1725b4d055b47e63f80b75
SKALE EUROPA HUB0xac4c6e212a361c968f1725b4d055b47e63f80b75

Examples

Using a contract to call RedSnwapper

Below is an example Solidity contract that can be used to call RedSnwapper.

It expects "self" as the source parameter when calling the API, and will pre-fund RedSnwapper with the input tokens before executing the swap. In case "sender" is used as the source, the contract can be simplified by removing the token transfer logic, although an approve call is still be needed.

The source parameter is disregarded when the input token is native (ETH), in which case the contract must be pre-funded with enough ETH to cover the swap.

contract RedSnwapperProxy {
  constant address NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
  constant address RED_SNWAPPER = 0xac4c6e212a361c968f1725b4d055b47e63f80b75;
 
  function swap(bytes calldata data) external payable returns (uint256 amountOut) {
    // Skip the first 4 bytes (function selector), decode the input token and amountIn
    (address tokenIn, uint256 amountIn) = abi.decode(data[4:], (address, uint256));
 
    // If the "source" parameter used to call the API is "self", we need to pre-fund the contract
    uint256 nativeAmount = 0;
    if (tokenIn == NATIVE) {
      require(msg.value >= amountIn, "Not enough ETH sent");
      nativeAmount = amountIn;
    } else {
      IERC20(tokenIn).transfer(RED_SNWAPPER, amountIn);
    }
 
    // Call RedSnwapper
    (bool success, bytes memory returnData) = RED_SNWAPPER.call{value: nativeAmount}(data);
    require(success, "RedSnwapper call failed");
 
    amountOut = abi.decode(returnData, (uint256));
  }
}