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

@galacticcouncil/sdk

v10.7.1

Published

Galactic off-chain routing & optimization of orders across pools for best price execution

Readme

Galactic SDK

npm version

Hydration SDK built on top of @polkadot{.js} (Pjs).

Table of contents:

Installation

Install with npm:

npm install @galacticcouncil/sdk

Troubleshooting

Version 8.x

⚠️ Important: In the 8.x release, we upgraded @polkadot/api to version 16.x.

See the changelog for details.

Version 2.x

As of v2.x .wasm files are no longer embedded in bundle but rather deferred to improve load performance & decrease module size (esm only).

For more details visit TROUBLESHOOTING.md

Usage

Use createSdkContext to quickly set up all components of the SDK — pool context, trading logic, client access, and transaction building — in a single call.

import { createSdkContext } from '@galacticcouncil/sdk';
import { ApiPromise, WsProvider } from '@polkadot/api';

const ws = 'wss://hydration-rpc.n.dwellir.com';
const wsProvider = new WsProvider(ws, 2_500, {}, 60_000, 102400, 10 * 60_000);

const api = await ApiPromise.create({
  provider: wsProvider,
});

const sdk = await createSdkContext(api);

// Don't forget to cleanup resources when DONE
sdk.destroy();
api.disconnect();

It handles all necessary setup under the hood. Just plug in your ApiPromise, and you're ready to interact with registry, accounts, pools, router, and more.

⚠️ Note: Make sure to keep only single instance of context per session.

Components

api

  • aave: AaveUtils — Aave-related utilities.
  • router: TradeRouter — Off-chain optimization of trades across pools for best price execution.
  • scheduler: TradeScheduler — Trade orders scheduling.

client

  • asset: AssetClient — Registry metadata and lookup.
  • balance: BalanceClient — Account balance tracking.
  • evm: EvmClient — Interacts with EVM.

ctx

  • pool: PoolService — Internal stateful pool context. Initialized with support for:
    • Aave
    • Omnipool
    • Stableswap
    • XYK pools
    • LBP pools

tx

  • TxBuilderFactory — Factory for generating submittable transaction using fluent APIs.

destroy()

Gracefully cleans up SDK resources. Always call before exiting to avoid memory leaks or stale subscriptions.

API Reference

AaveUtils

| Method | Description | | :----- | :----------- | | getSummary(user: string): AaveSummary | Returns market summary. | | getHealthFactor(user: string): number | Calculate HF. | | getHealthFactorAfterWithdraw(user: string, reserve:string, withdrawAmount: string): number | Calculate HF after withdraw. | | getHealthFactorAfterSupply(user: string, reserve:string, supplyAmount: string): number | Calculate HF after supply. | | getMaxWithdraw(user: string, reserve:string): Amount | Get max possible safe withdraw. |

➡️ For type definitions visit types.ts

TradeRouter

| Method | Description | | :----- | :----------- | | getPools(): PoolBase[] | Returns the current list of available pools. | | getAllPaths(tokenIn: string, tokenOut: string): Hop[][] | Computes possible routes between two assets. | | getAllAssets(): PoolBase[] | Lists all assets that are tradeable through the router. | | getAssetPairs(token: string): Asset[] | Lists all assets given token is tradeable with. | | getBestSell(tokenIn: string, tokenOut: string, amountIn: bigint \| string): Trade | Find the best sell trade for given input amount. | | getBestBuy(tokenIn: string, tokenOut: string, amountOut: bigint \| string): Trade | Find the best buy trade for given output amount. | | getBuy(tokenIn: string, tokenOut: string, amountOut: bigint \| string, route?: Hop[]): Trade | Calculate a buy using a specific route (optional). | | getSell(tokenIn: string, tokenOut: string, amountIn: bigint \| string, route?: Hop[]): Trade | Calculate a sell using a specific route (optional). | | getBestSpotPrice(tokenIn: string, tokenOut: string): Amount | Get the current spot price between two tokens. | | getMostLiquidRoute(tokenIn: string, tokenOut: string): Hop[] | Find the route with the highest liquidity between two tokens. |

➡️ For type definitions visit types.ts

TradeScheduler

| Method | Description | | :----- | :----------- | | getDcaOrder(assetIn: string, assetOut: string, amountInTotal: string, duration: number): TradeDcaOrder | Calculate DCA order. | | getTwapBuyOrder(assetIn: string, assetOut: string, amountInTotal: string): TradeOrder | Calculate TWAP buy order. | | getTwapSellOrder(assetIn: string, assetOut: string, amountInTotal: string): TradeOrder | Calculate TWAP sell order. |

➡️ For type definitions visit types.ts

AssetClient

| Method | Description | | :----- | :----------- | | getOnChainAssets(includeInvalid?: boolean, external?: ExternalAsset[]): Promise<Asset[]> | Returns assets with metadata from registry. |

➡️ For type definitions visit types.ts

Examples

All examples assume SDK has been initialized, see

TradeRouter

Calculate sell of 1 DOT for HDX & build tx with 5% slippage (default to 1% if not specified)

const { api, tx } = sdk;

const trade = await api.router.getBestSell("5", "10", "10");
const tradeTx = await tx.trade(trade)
  .withBeneficiary(BENEFICIARY)
  .withSlippage(5)
  .build();
console.log(trade.toHuman());
console.log('Transaction hash:', tradeTx.hex);

AssetClient

Get default on-chain data.

const { client } = sdk;

const assets = await client.asset.getOnChainAssets();
console.log(assets);

To demonstrate more full working examples on real chain see script section.

Run: $ npx tsx ./test/script/examples/<examplePackage>/<exampleName>.ts with valid example package & name.