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

bfx-sdk

v0.0.1-beta

Published

Off-chain quoting and swap building for BFX liquidity pools. Designed for DEX aggregators — compute quotes locally in microseconds without an RPC call, then build the swap transaction when ready.

Readme

bfx-sdk

Off-chain quoting and swap building for BFX liquidity pools. Designed for DEX aggregators — compute quotes locally in microseconds without an RPC call, then build the swap transaction when ready.

Supports both single-hop swaps (USDC ↔ EURC) and multi-hop swaps (EURC ↔ XSGD via USDC). The SDK handles routing automatically — you only specify the tokens you want to trade.

Installation

npm install bfx-sdk

Usage

Initialisation

import { BFX } from "bfx-sdk";

const bfx = new BFX("https://your-rpc-url.com");

Discover pools

// all available pools
const pools = await bfx.getAllPoolsInfo();
// [
//   { address: "0x80ba...", token0: { address: "0x60a3...", symbol: "EURC" }, token1: { address: "0x8335...", symbol: "USDC" } },
//   { address: "0xbBb1...", token0: { address: "0x0a4c...", symbol: "XSGD" }, token1: { address: "0x8335...", symbol: "USDC" } },
// ]

// single pool by address
const pool = await bfx.getPoolInfo("0x80ba6376c0Ea9A14C1d4411C3639e87d441A6b72");

// single pool by token pair
const pool = await bfx.getPoolInfoByTokens(USDC, EURC);

Load pool state

Must be called before quote(), buildSwap(), or getPoolState().

Pass the two tokens you want to trade — the SDK figures out the routing automatically:

const USDC = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
const EURC = "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42";
const XSGD = "0xd3d31bc27e3f0b3f9d0f63f3feba50a8cfed5b63";

// Single-hop — loads one pool, returns one entry
const [eurcUsdc] = await bfx.loadPoolState(USDC, EURC);

// Multi-hop — loads two pools automatically, returns two entries
const [eurcUsdc, xsgdUsdc] = await bfx.loadPoolState(EURC, XSGD);

Quote

// amounts are in raw token units (6 decimals for USDC/EURC/XSGD)
const result = bfx.quote(USDC, EURC, 1_000_000n); // 1 USDC → EURC

console.log(result.amountOut);     // how many EURC you receive (bigint)
console.log(result.fee);           // fee taken on the final leg (bigint)
console.log(result.priceImpactBps); // price impact in basis points
console.log(result.effectivePrice); // output per 1 input, scaled by 1e18
console.log(result.hops);          // breakdown per hop — one entry for single-hop, two for multi-hop

Multi-hop quote — identical call:

const result = bfx.quote(EURC, XSGD, 1_000_000n); // 1 EURC → XSGD
// result.hops[0] → { tokenIn: EURC, tokenOut: USDC, amountIn, amountOut, fee }
// result.hops[1] → { tokenIn: USDC, tokenOut: XSGD, amountIn, amountOut, fee }

Build a swap transaction

const tx = bfx.buildSwap({
  tokenIn: USDC,
  tokenOut: EURC,
  amountIn: 1_000_000n,
  minAmountOut: 900_000n,                          // slippage tolerance
  recipient: "0xYourAddress",
  deadline: Math.floor(Date.now() / 1000) + 1200, // 20 min from now
});

// tx.to    — curve address (single-hop) or Router address (multi-hop)
// tx.data  — encoded originSwap() calldata
// tx.value — always 0n for token swaps

// wagmi
await sendTransaction({ to: tx.to, data: tx.data, value: tx.value });

// ethers
await signer.sendTransaction({ to: tx.to, data: tx.data, value: tx.value });

Read live pool state

The state returned by loadPoolState is a one-time snapshot. To read the current state after events have updated it:

const state = bfx.getPoolState(USDC, EURC);
console.log(state.reserveA); // always reflects the latest on-chain state

Cleanup

Call stop() to unsubscribe from all events when done:

bfx.stop();

Amount format

All amounts use raw token units as bigint:

1_000_000n;  // 1 USDC or 1 EURC  (6 decimals)
10_000_000n; // 10 USDC or 10 EURC

To convert from a string or ethers BigNumber:

BigInt("1000000");
BigInt(ethBigNumber.toString());