npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

assetscooper-multicall-swap-sdk

v2.0.1

Published

A Multicall Swap SDK powered by Uniswap V3 for performing batch token swaps with liquidity checks, slippage tolerance, and approval handling.

Readme

AssetScooper MulticallSwap SDK powered by Uniswap V3

The AssetScooper MulticallSwap SDK simplifies token swaps across multiple pools using Uniswap V3's advanced functionality. With support for multicall transactions, token approvals, and slippage control, this SDK enables efficient and customizable token swaps for developers.

Features

  • Multicall Transactions: Batch multiple swaps into a single transaction for efficiency.
  • Slippage Management: Define slippage tolerance for precise token swaps.
  • Dynamic Pool Fee Discovery: Automatically identify the best pool fee tier for swaps.
  • Approval Management: Automatically handle token approvals when needed.
  • Liquidity Check: Ensure pools have sufficient liquidity before performing swaps.

Installation

npm install assetscooper-multicallswap-sdk
# or
yarn add assetscooper-multicallswap-sdk

Usage

Here's how to get started with the SDK:

Import and Initialize
import { ethers } from "ethers";
import { MulticallSwap } from "assetscooper-multicallswap-sdk";

// Setup signer, router, and factory addresses
const provider = new ethers.JsonRpcProvider("<RPC_URL>");
const signer = provider.getSigner("<YOUR_WALLET_ADDRESS>");
const routerAddress = "<UNISWAP_ROUTER_ADDRESS>";
const factoryAddress = "<UNISWAP_FACTORY_ADDRESS>";

// Initialize the MulticallSwap class
const multicallSwap = new MulticallSwap(signer, routerAddress, factoryAddress);
Perform Token Swaps

To perform multiple token swaps, provide an array of SwapParam objects:

const swapParams = [
  {
    tokenIn: "<TOKEN_IN_ADDRESS>",
    tokenOut: "<TOKEN_OUT_ADDRESS>",
    amountIn: ethers.parseUnits("1", 18), // 1 token (adjust decimals)
    amountOutMinimum: ethers.parseUnits("0.95", 18), // Adjust for slippage
    deadline: Math.floor(Date.now() / 1000) + 60 * 10, // 10-minute deadline
    slippageTolerance: 0.01, // 1% slippage
  },
  {
    tokenIn: "<ANOTHER_TOKEN_IN_ADDRESS>",
    tokenOut: "<ANOTHER_TOKEN_OUT_ADDRESS>",
    amountIn: ethers.parseUnits("2", 6), // Adjust for decimals
    amountOutMinimum: ethers.parseUnits("1.9", 6), // Adjust for slippage
    deadline: Math.floor(Date.now() / 1000) + 60 * 10, // 10-minute deadline
    slippageTolerance: 0.01, // 1% slippage
  },
];

// Perform the swaps
await multicallSwap.performSwaps(swapParams);
Error Handling

The SDK provides robust error handling for common issues:

  • Insufficient Balance: Checks if the wallet has enough tokens for the swap.
  • Expired Deadlines: Ensures the transaction deadline is valid.
  • Liquidity Issues: Verifies if the target pool has sufficient liquidity.

performSwaps

async performSwaps(params: SwapParam[]): Promise<void>

params: An array of SwapParam objects containing swap details.

  • SwapParam Fields:

-tokenIn: Address of the input token. -tokenOut: Address of the output token. -amountIn: Amount of input tokens.

  • amountOutMinimum: Minimum acceptable amount of output tokens. -deadline: UNIX timestamp for transaction expiry. -slippageTolerance: Percentage of slippage allowed.

Key Methods

  performSwaps(params: SwapParam[])

Executes multiple swaps via a single transaction. Ensures the following:

  • Deadlines are valid.
  • The user has sufficient token balances.
  • Approvals are granted for required amounts.
  • Pools exist and have sufficient liquidity.
  • Slippage is calculated and applied.
  needsApproval(amountIn: bigint, tokenIn: string)

Checks if token approval is needed for the specified amount.

  approveToken(amountIn: bigint, tokenIn: string)

Approves the token for the Uniswap Router.

  getPoolFee(tokenIn: string, tokenOut: string)

Determines the appropriate fee tier for the swap (e.g., 0.05%, 0.3%, or 1%).

  poolExistsWithLiquidity(tokenIn: string, tokenOut: string, fee: number)

Verifies if a liquidity pool exists and has sufficient liquidity.

Example Usage with the SDK

import { MulticallSwap } from "multicall-swap-sdk";
import { ethers } from "ethers";

async function main() {
  //your RPC URL with your API KEY - you can make use of base for example
  const provider = new ethers.JsonRpcProvider(
    "https://mainnet.infura.io/v3/YOUR_INFURA_KEY"
  );
  const signer = provider.getSigner(YOUR_WALLET_ADDRESS);

  const multicallSwap = new MulticallSwap(signer);

  const params = [
    {
      tokenIn: "0x50c5725949a6f0c72e6c4a641f24049a917db0cb", // DAI
      tokenOut: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
      recipient: YOUR_WALLET_ADDRESS,
      fee: 3000,
      deadline: Math.floor(Date.now() / 1000) + 60 * 20,
      amountIn: BigInt("1000000000000000000"),
      amountOutMinimum: BigInt("0"),
      slippageTolerance: 0.01,
    },
  ];

  await multicallSwap.performSwaps(params);
}

main();

Contributing

We welcome contributions to improve this SDK! To contribute, please follow these steps:

  • Fork the repository.
  • Create a new branch (git checkout -b feature-name).
  • Commit your changes (git commit -m 'Add feature').
  • Push the branch (git push origin feature-name).
  • Create a pull request and wait for a review.