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 🙏

© 2025 – Pkg Stats / Ryan Hefner

agg-swap-client

v0.2.1

Published

Aggregator Swap API Client SDK

Readme

agg-swap-client

TypeScript SDK 用于与 Aggregator Swap API 交互,支持多链资产交换和价格查询。

安装

npm install agg-swap-client

功能特性

  • 完整的 TypeScript 类型支持
  • 支持多链资产交换(Solana、Ethereum、Base 等)
  • 简洁易用的 API 接口
  • 基于 Axios 的 HTTP 请求
  • 新增: 支持获取每个网络的稳定币信息

版本更新

v0.2.0 - 稳定币功能更新

  • 新增: Chain 接口中添加 stableToken 字段
  • 更新: Chain 接口中 key 字段更名为 id,以匹配服务端 API
  • 更新: Chain 接口中 chainId 字段支持字符串类型(如 Solana 的 'solana')
  • 移除: nativeToken 中的 priceUSD 字段,与服务端保持一致

使用示例

创建客户端实例

import { SwapApiClient } from 'agg-swap-client';

// 创建客户端实例,指定 API 服务器地址
const client = new SwapApiClient('http://your-api-url');

获取支持的链(包含稳定币信息)

// 获取所有支持的区块链信息
const chains = await client.getChains();
console.log(chains);

// 每个链现在包含稳定币信息
chains.forEach(chain => {
  console.log(`${chain.name} 的主要稳定币: ${chain.stableToken.symbol} (${chain.stableToken.name})`);
  console.log(`稳定币地址: ${chain.stableToken.address}`);
  console.log(`稳定币精度: ${chain.stableToken.decimals}`);
});

// 示例输出:
// Ethereum 的主要稳定币: USDC (USD Coin)
// 稳定币地址: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
// 稳定币精度: 6

获取特定链的稳定币信息

// 获取 Ethereum 链信息
const ethereum = chains.find(chain => chain.id === '1');
if (ethereum) {
  const stableToken = ethereum.stableToken;
  console.log(`Ethereum 稳定币: ${stableToken.symbol}`);
  console.log(`合约地址: ${stableToken.address}`);
  console.log(`精度: ${stableToken.decimals}`);
}

// 获取 Solana 链信息
const solana = chains.find(chain => chain.id === 'solana');
if (solana) {
  const stableToken = solana.stableToken;
  console.log(`Solana 稳定币: ${stableToken.symbol}`);
  console.log(`合约地址: ${stableToken.address}`);
  console.log(`精度: ${stableToken.decimals}`);
}

获取代币列表

// 获取 Solana 链上的代币列表
const tokens = await client.getTokens('solana');

// 搜索特定代币
const searchResult = await client.searchTokens('ethereum', 'usdc');

获取代币信息

// 获取 Solana 上 USDC 代币的详细信息
const token = await client.getToken('sol', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');

获取交换报价

// 获取 SOL 到 USDC 的交换报价
const quote = await client.getQuotation({
  fromChain: 'sol',
  toChain: 'sol',
  fromTokenAddress: 'So11111111111111111111111111111111111111112',
  toTokenAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
  fromAmount: '1000000000',
  fromAddress: 'YourFromAddress',
  toAddress: 'YourToAddress',
  slippage: 0.1
});

// 访问交易请求数据
if (quote.transactionRequest) {
  // 检查是否是 EVM 交易
  if ('to' in quote.transactionRequest) {
    console.log('EVM Transaction:', {
      to: quote.transactionRequest.to,
      from: quote.transactionRequest.from,
      data: quote.transactionRequest.data,
      value: quote.transactionRequest.value
    });
  }
  // 检查是否是 Solana 交易
  else if ('data' in quote.transactionRequest) {
    console.log('Solana Transaction Data:', quote.transactionRequest.data);
  }
}

获取代币价格

// 获取 SOL 代币的 USD 价格
const price = await client.getTokenPrice('So11111111111111111111111111111111111111112', 'sol');

获取 Gas 价格

// 获取 Solana 链的 Gas 价格
const gasPrice = await client.getGasPrice('sol');

API 参考

SwapApiClient

构造函数

constructor(baseURL: string = 'http://localhost:3000')

创建一个新的 SwapApiClient 实例。

方法

  • getChains(): Promise<LiFiChain[]> 获取所有支持的区块链信息。

  • getTokens(chains: string, searchTerm?: string): Promise<LiFiTokensResponse> 获取指定链上的代币列表,可选搜索关键词。

  • getToken(chain: string, token: string): Promise<LiFiToken> 获取特定代币的详细信息。

  • getQuotation(params: QuotationParams): Promise<LiFiQuoteResponse> 获取代币交换报价和可用路由。

  • getTokenPrice(token: string, chain: string): Promise<string> 获取代币的 USD 价格。

  • getGasPrice(chain: string): Promise<string> 获取特定链的 Gas 价格。

类型定义

所有类型定义都从包中导出:

import {
  LiFiChain,
  LiFiToken,
  LiFiTokensResponse,
  LiFiQuoteResponse,
  LiFiStep,
  EVMTransactionRequest,
  SolanaTransactionRequest
} from 'agg-swap-client';

主要类型

  • LiFiChain: 区块链信息
  • LiFiToken: 代币信息
  • LiFiTokensResponse: 代币列表响应
  • LiFiQuoteResponse: 交换报价响应
  • EVMTransactionRequest: EVM 交易请求
  • SolanaTransactionRequest: Solana 交易请求

开发

# 安装依赖
npm install

# 构建
npm run build

# 测试
npm run test

许可证

MIT