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

@masterpeach/aggregator-sdk

v0.2.0

Published

TypeScript SDK for DEX Aggregator on BSC

Readme

Peach Aggregator SDK

TypeScript SDK for route discovery and PeachExecutionRouter swaps on BSC.

Install

npm install @masterpeach/aggregator-sdk ethers

Version 0.2.0 replaces the legacy swap and Permit2 AllowanceTransfer APIs. getQuote() is display-only; migrate execution to prepareSwap(), simulateSwap(), and executeSwap(). For delegated swaps, use the Permit2 Witness flow below. See the frontend integration guide for the complete migration workflow.

Initialize

Deployment addresses come from Aggregator responses. They do not need to be passed to the constructor.

import { BSC_MAINNET_CONFIG, PeachClient } from '@masterpeach/aggregator-sdk';
import { ethers } from 'ethers';

const provider = new ethers.BrowserProvider(window.ethereum);
const client = new PeachClient(BSC_MAINNET_CONFIG, provider, {
  api: { baseUrl: 'https://api.cipheron.org' },
});

Display Quote

getQuote() only calls GET /router/find_routes. Its result is for display and route inspection; it does not contain executable calldata.

const quote = await client.getQuote({
  srcToken,
  dstToken,
  amountIn,
  options: {
    depth: 3,
    splitCount: 5,
    providers: ['PANCAKEV3'], // optional; omit for the server's enabled set
  },
});

console.log(quote.amountOut, quote.route, quote.gasEstimate);

The SDK treats provider names as open strings. New Aggregator providers do not require an SDK release.

Direct Allowance

Use this flow when payer === executor. The recipient may be independent.

const signer = await provider.getSigner();
const executor = await signer.getAddress();

const prepared = await client.prepareDirectSwap({
  from: srcToken,
  target: dstToken,
  amount: amountIn,
  executor,
  recipient,
  slippageBps: 50,
  deadlineSecs: 300,
});

const approval = await client.buildDirectApprovalRequest(prepared, executor);
if (approval) {
  const approvalTx = await signer.sendTransaction(approval.tx);
  await approvalTx.wait();
}

const swapTx = await client.executeSwap(prepared, signer);
await swapTx.wait();

For ERC20 input, approval is granted to prepared.approvalSpender, which is validated against the server-built ExecutionPlan. Native input needs no ERC20 approval.

To preflight the exact server transaction after approval, call simulateSwap(prepared, executor) and read receipt.userAmountOut.

Permit2 Witness

Use this flow when payer !== executor. The payer signs the typed data and the executor sends the final transaction.

const prepared = await client.prepareDelegatedSwap({
  from: srcToken,
  target: dstToken,
  amount: amountIn,
  payer,
  executor,
  recipient,
  slippageBps: 50,
  deadlineSecs: 300,
});

const payerSignature = await client.signPayerAuthorization(
  prepared,
  payerSigner,
);
const ready = await client.buildDelegatedSwap(prepared, payerSignature);
const swapTx = await client.executeSwap(ready, executorSigner);
await swapTx.wait();

The payer must first grant the input token's base ERC20 allowance to Permit2. Use checkPermit2BaseAllowance() to inspect it.

Unified Preparation

prepareSwap() chooses the mode from the roles:

const prepared = await client.prepareSwap({
  from,
  target,
  amount,
  payer,
  executor,
  recipient,
  slippageBps: 50,
});

if (prepared.executionMode === 'DIRECT_ALLOWANCE') {
  // optional ERC20 approval, then executeSwap(prepared, executorSigner)
} else {
  // signPayerAuthorization(), buildDelegatedSwap(), then executeSwap()
}

Native Tokens

Use NATIVE_TOKEN_ADDRESS or set nativeIn/nativeOut on prepareSwap(). The SDK sends WBNB to the API and validates the returned native mode and transaction value.

Custom Fees

Display quotes can project a fee using QuoteOptions.customFee. The executable request must carry the same fee explicitly:

const prepared = await client.prepareSwap({
  from,
  target,
  amount,
  payer,
  executor,
  recipient,
  customFeeBps: 20,
  customFeeReceiver: feeReceiver,
});

The SDK validates the server response and sends its to, data, and value unchanged. Changing slippage, deadline, roles, fee, or route requires a new prepareSwap() request.

Security Checks

Before returning or sending a transaction, the SDK validates:

  • execution mode and status
  • payer, executor, recipient, chain, token, and native mode
  • legacy Router response metadata and the ExecutionRouter transaction target
  • calldata selector, canonical encoding, plan hash, and route hash
  • the settlement-policy hash bound into the signed ExecutionPlan
  • Aggregator and payer signatures where applicable
  • transaction target and native value

Documentation

License

MIT