正在確認登入狀態。
TypeScript/JavaScript SDK for Haystack Order Router - smart order routing and DEX aggregation on Algorand
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 README ↗Note: This package was formerly known as
@txnlab/deflex. If you're migrating from the old package, see the migration guide.
This repository contains the Haystack Router SDK and example implementations for integrating Haystack Order Router into your applications.
TypeScript/JavaScript SDK for Haystack Order Router - smart order routing and DEX aggregation on Algorand.
The examples directory contains complete working implementations:
Simple React application demonstrating basic Haystack Router SDK integration.
Advanced React application showcasing TanStack Query integration.
Command-line tool for executing swaps without a browser.
This is a pnpm workspace monorepo. All packages and examples share dependencies and can reference each other.
^22.22.2 || >=24.15Install all dependencies:
pnpm install
Build the SDK package:
pnpm build
Each example can be run independently. Navigate to the example directory and follow its README:
# React
cd examples/react
pnpm dev
# React Query
cd examples/react-query
pnpm dev
# Node.js CLI
cd examples/node-cli
pnpm dev
Install the SDK in your project:
npm install @txnlab/haystack-router algosdk
Basic usage:
import { RouterClient } from '@txnlab/haystack-router'
import { useWallet } from '@txnlab/use-wallet-react'
const { activeAddress, transactionSigner } = useWallet()
// Initialize client
const router = new RouterClient({
apiKey: '1b72df7e-1131-4449-8ce1-29b79dd3f51e', // Free tier (60 requests/min)
})
// Get quote
const quote = await router.newQuote({
fromASAID: 0, // ALGO
toASAID: 31566704, // USDC
amount: 1_000_000, // 1 ALGO
address: activeAddress,
})
// Execute swap
const swap = await router.newSwap({
quote,
address: activeAddress,
signer: transactionSigner,
slippage: 1, // 1%
})
const result = await swap.execute()
Run SDK tests:
pnpm test
Run tests with coverage:
pnpm test:coverage
Root-level scripts:
pnpm build - Build the SDK packagepnpm test - Run SDK testspnpm test:watch - Run tests in watch modepnpm test:coverage - Run tests with coveragepnpm lint - Lint SDK codepnpm format - Check code formattingpnpm format:fix - Fix code formattingpnpm typecheck - Type check SDKpnpm ci - Run all CI checks (build, lint, format, test)pnpm release - Release a new versionContributions are welcome! The monorepo structure makes it easy to:
packages/haystack/All examples reference the SDK using "@txnlab/haystack-router": "workspace:*" in their package.json.
MIT - see LICENSE for details
Built by TxnLab