@aiquant/minswap-sdk
v0.0.0
Published
Query Minswap data and build transactions
Maintainers
Readme
Minswap SDK (CommonJS & ESM)
Official fork of the Minswap SDK with dual build support for CommonJS (CJS) and ECMAScript Modules (ESM).
This package provides both the CommonJS and ESM distributions of the Minswap SDK, ensuring compatibility across Node.js environments that do and do not use ES Modules.
Overview
The Minswap open-source SDK offers off-chain tooling to interact with the Minswap DEX. It supports:
- Stableswap
- AMM V1
- AMM V2
- LBE V2
Features include pool price feeds, trade simulations, transaction builders, and historical data access.
Features
- [x] Pool price feed
- [x] Historical pool data
- [x] Calculate trade price & impact
- [x] Build and submit orders via Lucid
- [x] Syncer for liquidity pool data
Install
Choose the package that matches your project setup:
| Build | Install Command | Usage |
| ----- | ---------------------------------- | -------------------------------------------------- |
| CJS | npm install @aiquant/minswap-sdk | const { ... } = require("@aiquant/minswap-sdk"); |
| ESM | npm install @aiquant/minswap-sdk | import { ... } from "@aiquant/minswap-sdk"; |
| PNPM | pnpm add @aiquant/minswap-sdk | Supports both CJS & ESM |
| Yarn | yarn add @aiquant/minswap-sdk | Supports both CJS & ESM |
Usage Examples
Example 1: Get Current MIN/ADA Price
import { BlockFrostAPI } from "@blockfrost/blockfrost-js";
import { BlockfrostAdapter } from "@aiquant/minswap-sdk"; // forked package
const api = new BlockfrostAdapter({
blockFrost: new BlockFrostAPI({
projectId: "<your_project_id>",
network: "mainnet",
}),
});
const [adaPerMin, minPerAda] = await api.getPoolPrice({ pool: await api.getV1PoolById({ id: "<poolId>" }) });
console.log(`ADA/MIN: ${adaPerMin.toString()}, MIN/ADA: ${minPerAda.toString()}`);Example 2: Historical Price History
import { BlockFrostAPI } from "@blockfrost/blockfrost-js";
import { BlockfrostAdapter, NetworkId } from "@aiquant/minswap-sdk";
const api = new BlockfrostAdapter({ /* ... */ });
const history = await api.getPoolHistory({ id: "<poolId>" });
for (const point of history) {
const pool = await api.getPoolInTx({ txHash: point.txHash });
const [priceA, priceB] = await api.getPoolPrice({ pool, decimalsA: 6, decimalsB: 6 });
console.log(`${point.time}: ADA/MIN=${priceA}, MIN/ADA=${priceB}`);
}Example 3: Build & Submit Swap Order
import { Lucid, Blockfrost } from "@aiquant/lucid-cardano";
import { BlockfrostAdapter, Dex } from "@aiquant/minswap-sdk";
const lucid = await Lucid.new(new Blockfrost("...", "<id>"), "Mainnet");
const adapter = new BlockfrostAdapter({ /* ... */ });
const { poolState, poolDatum } = await api.getPoolById({ id: "<poolId>" });
const dex = new Dex(lucid);
const tx = await dex.buildSwapExactOutTx({ /* parameters */ }).sign().complete();
const hash = await tx.submit();
console.log("Swap tx hash:", hash);Contributing
Contributions welcome! Please see our CONTRIBUTING.md.
License
MIT © Minswap Labs
