@galacticcouncil/sdk

中文文档
10.8.0发布于 2026/03/11TypeScriptESM + CJS近 30 天下载 4726

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

原始使用文档
文档目录19 节
  1. Installation
  2. Troubleshooting
  3. Version 8.x
  4. Version 2.x
  5. Usage
  6. Components
  7. api
  8. client
  9. ctx
  10. tx
  11. destroy()
  12. API Reference
  13. AaveUtils
  14. TradeRouter
  15. TradeScheduler
  16. AssetClient
  17. Examples
  18. TradeRouter
  19. AssetClient

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

MethodDescription
getSummary(user: string): AaveSummaryReturns market summary.
getHealthFactor(user: string): numberCalculate HF.
getHealthFactorAfterWithdraw(user: string, reserve:string, withdrawAmount: string): numberCalculate HF after withdraw.
getHealthFactorAfterSupply(user: string, reserve:string, supplyAmount: string): numberCalculate HF after supply.
getMaxWithdraw(user: string, reserve:string): AmountGet max possible safe withdraw.

➡️ For type definitions visit types.ts

TradeRouter

MethodDescription
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): TradeFind the best sell trade for given input amount.
getBestBuy(tokenIn: string, tokenOut: string, amountOut: bigint | string): TradeFind the best buy trade for given output amount.
getBuy(tokenIn: string, tokenOut: string, amountOut: bigint | string, route?: Hop[]): TradeCalculate a buy using a specific route (optional).
getSell(tokenIn: string, tokenOut: string, amountIn: bigint | string, route?: Hop[]): TradeCalculate a sell using a specific route (optional).
getBestSpotPrice(tokenIn: string, tokenOut: string): AmountGet 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

MethodDescription
getDcaOrder(assetIn: string, assetOut: string, amountInTotal: string, duration: number): TradeDcaOrderCalculate DCA order.
getTwapBuyOrder(assetIn: string, assetOut: string, amountInTotal: string): TradeOrderCalculate TWAP buy order.
getTwapSellOrder(assetIn: string, assetOut: string, amountInTotal: string): TradeOrderCalculate TWAP sell order.

➡️ For type definitions visit types.ts

AssetClient

MethodDescription
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.

版本与发布记录

@galacticcouncil/sdk 共发布 224 个版本,首次发布于 2022/09/02;过去 12 个月发布了 14 个版本。

版本发布日期距今
10.8.0latest2026/03/118 个月前
10.8.0-pr293-a9f6dbdbeta2026/03/118 个月前
10.8.0-pr293-6abf00c2026/03/108 个月前
10.7.12026/03/058 个月前
10.7.1-pr288-7ff39342026/03/038 个月前
10.7.02026/02/258 个月前

关于 @galacticcouncil/sdk 的常见问题

@galacticcouncil/sdk 是什么?

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

如何安装 @galacticcouncil/sdk?

在项目目录运行 npm install @galacticcouncil/sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@polkadot/api(~16.4.8)、@polkadot/api-augment(~16.4.8)、@polkadot/types(~16.4.8)、@polkadot/util(~13.5.6)、@polkadot/util-crypto(~13.5.6)、viem(^2.38.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@galacticcouncil/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@galacticcouncil/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@galacticcouncil/sdk 可以商用吗?

@galacticcouncil/sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@galacticcouncil/sdk 的下载量有多少?

根据 npm 官方下载统计,@galacticcouncil/sdk 在 2026/10/16 – 2026/11/14 这 30 天内被下载 4,726 次,日均约 158 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@galacticcouncil/sdk 还在维护吗?

最新版本 10.8.0 发布于 2026/03/11(8 个月前);至今共发布 224 个版本,其中过去 12 个月发布了 14 个;首次发布于 2022/09/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。