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

@swarm-markets/trading-sdk

v1.0.3

Published

Swarm Trading SDK with smart routing between Market Maker and Cross-Chain Access

Readme

@swarm/trading-sdk

Unified Swarm Trading SDK with smart routing between Market Maker and Cross-Chain Access platforms.

Installation

pnpm add @swarm/trading-sdk

Features

  • Smart Routing: Automatically selects the best platform based on price, availability, and strategy
  • Platform Aggregation: Compare quotes from multiple platforms
  • Automatic Fallback: Falls back to alternative platform if primary fails
  • Unified Interface: Single API for all trading operations

Quick Start

import { TradingClient, Network, RoutingStrategy } from "@swarm/trading-sdk";

const client = new TradingClient({
  network: Network.POLYGON,
  privateKey: "0x...",
  rpqApiKey: "your-api-key",
  userEmail: "[email protected]",
  routingStrategy: RoutingStrategy.BEST_PRICE,
});

await client.initialize();

// Execute trade with smart routing
const result = await client.trade({
  fromToken: "0xUSDC...",
  toToken: "0xRWA...",
  fromAmount: 100,
  toTokenSymbol: "AAPL",
  userEmail: "[email protected]",
});

console.log(`Trade executed via: ${result.source}`);
console.log(`Transaction: ${result.txHash}`);

await client.close();

Routing Strategies

| Strategy | Description | | -------------------------- | ------------------------------------------------------ | | BEST_PRICE | Select platform with best price (default) | | CROSS_CHAIN_ACCESS_FIRST | Try Cross-Chain Access first, fallback to Market Maker | | MARKET_MAKER_FIRST | Try Market Maker first, fallback to Cross-Chain Access | | CROSS_CHAIN_ACCESS_ONLY | Only use Cross-Chain Access | | MARKET_MAKER_ONLY | Only use Market Maker |

API

TradingClient

Main client with smart routing.

const client = new TradingClient({
  network: Network.POLYGON, // Required: Network to trade on
  privateKey: "0x...", // Required: Private key for signing
  rpqApiKey: "your-api-key", // Required: RPQ Service API key
  userEmail: "[email protected]", // Optional: User email
  rpcUrl: "https://...", // Optional: Custom RPC URL
  routingStrategy: RoutingStrategy.BEST_PRICE, // Optional: Default strategy
});

Methods

  • initialize() - Initialize both underlying clients
  • close() - Close and cleanup resources
  • getQuotes(params) - Get quotes from all platforms
  • trade(options) - Execute trade with smart routing

Getting Quotes

const quotes = await client.getQuotes({
  fromToken: "0xUSDC...",
  toToken: "0xRWA...",
  fromAmount: 100,
  toTokenSymbol: "AAPL",
});

console.log("Market Maker:", quotes.market_maker?.rate);
console.log("Cross-Chain Access:", quotes.cross_chain_access?.rate);

Trade Options

const result = await client.trade({
  fromToken: "0xUSDC...", // Token to sell
  toToken: "0xRWA...", // Token to buy
  userEmail: "[email protected]", // User email for notifications
  fromAmount: 100, // Amount to sell (or use toAmount)
  toTokenSymbol: "AAPL", // Stock symbol (required for Cross-Chain Access)
  routingStrategy: RoutingStrategy.BEST_PRICE, // Override default strategy
});

Direct Platform Access

You can also access underlying clients directly:

// Market Maker operations
const mmQuote = await client.marketMakerClient.getQuote(
  "0xFromToken",
  "0xToToken",
  100
);

// Cross-Chain Access operations
const ccaQuote = await client.crossChainAccessClient.getQuote("AAPL");

Error Handling

import {
  TradingException,
  NoLiquidityException,
  AllPlatformsFailedException,
} from '@swarm/trading-sdk';

try {
  await client.trade({...});
} catch (error) {
  if (error instanceof NoLiquidityException) {
    console.log('No liquidity available on any platform');
  } else if (error instanceof AllPlatformsFailedException) {
    console.log('All platforms failed:', error.message);
  }
}

Supported Networks

  • Ethereum (Chain ID: 1)
  • Polygon (Chain ID: 137)
  • Base (Chain ID: 8453)
  • BSC (Chain ID: 56)

License

MIT