@minswap/sdk-v2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/index.cjs +4641 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8734 -0
- package/dist/index.d.ts +8734 -0
- package/dist/index.js +4558 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@minswap/sdk-v2` are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
|
|
5
|
+
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [1.0.0] - 2026-07-28
|
|
8
|
+
|
|
9
|
+
Initial release. A clean, standalone TypeScript client for the Minswap API,
|
|
10
|
+
migrated from [`@minswap/sdk`](https://github.com/minswap/sdk) (v1) — the legacy
|
|
11
|
+
Lucid transaction builder is intentionally left behind. This package is only the
|
|
12
|
+
new API client.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **`MinswapSdk`** root client. Construct once, reach each area through its module.
|
|
17
|
+
- **Reads** — `token` (lookup, listing, OHLC, trade history), `pool` (listing,
|
|
18
|
+
lookup, charts, events), `portfolio` (a wallet's LP / farm / staking positions),
|
|
19
|
+
`order` (DEX order history across protocols).
|
|
20
|
+
- **`aggregator`** — swap `estimate`, `buildTx`, `submitTx`, `cancelOrders`,
|
|
21
|
+
`getPendingOrders`. The only submit path in the SDK.
|
|
22
|
+
- **`liquidity`** — client-side **add / remove / zap-in / zap-out** across
|
|
23
|
+
**DEX V2**, **DEX V1**, and **Stableswap**. Callers pass only a pair (or LP
|
|
24
|
+
token) + amount + slippage; the SDK resolves the pool and version, decodes
|
|
25
|
+
on-chain state, computes minimums, and returns unsigned order CBOR. Amounts
|
|
26
|
+
accept raw base units or decimal-normalized form (LP token is always raw).
|
|
27
|
+
- **`farm`** — `list`, `getPositions`, `deposit`, `withdraw`, `harvest`,
|
|
28
|
+
`emergencyWithdraw`, with automatic first-deposit vs. add and partial vs. full
|
|
29
|
+
withdraw routing.
|
|
30
|
+
- **`staking`** — MIN staking `list`, `getPositions`, `stake`, `unstake`, with
|
|
31
|
+
automatic tiered vs. flexible routing.
|
|
32
|
+
- **`RpcProvider`** interface plus a ready-made **`KupoRpcProvider`** for the
|
|
33
|
+
wallet UTxOs that liquidity, farm, and staking actions require; `selectCollateral`
|
|
34
|
+
and related helpers.
|
|
35
|
+
- **Optional peer** `@minswap/internal-sdk` (Node-only, lazily loaded) for the
|
|
36
|
+
Kupo → CBOR path and client-side liquidity order assembly.
|
|
37
|
+
- Typed **`MinswapError`** (`code` → typed `details`) for every failure; Zod
|
|
38
|
+
validation at the trust boundary; camelCase responses mapped from the backends'
|
|
39
|
+
snake_case.
|
|
40
|
+
- Pagination helpers (`paginate`, `collect`) and token-id converters
|
|
41
|
+
(`coinIdToAssetUnit`, `assetUnitToCoinId`, `coinIdToInputAsset`).
|
|
42
|
+
- **Packaging** — dual ESM + CJS builds with `.d.ts` types; tree-shakeable;
|
|
43
|
+
`@minswap/internal-sdk` kept external so it is never required at import time.
|
|
44
|
+
|
|
45
|
+
### Notes
|
|
46
|
+
|
|
47
|
+
- The SDK **never signs or submits** — action methods return CBOR for the caller
|
|
48
|
+
to sign. Server-partially-signed CBOR (aggregator cancel, farm/staking) must be
|
|
49
|
+
`partialSign`-ed and assembled, not replaced.
|
|
50
|
+
- On failure the SDK always **throws** a typed error; it never returns `null`.
|
|
51
|
+
- Liquidity orders are built client-side and verified **byte-identical** to the
|
|
52
|
+
production `@minswap/sdk` builder (order address + value + datum) across all
|
|
53
|
+
ops × pool versions.
|
|
54
|
+
- mainnet only; every endpoint is overridable via config.
|
|
55
|
+
|
|
56
|
+
[1.0.0]: https://github.com/minswap/minswap-sdk-v2/releases/tag/v1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Minswap
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @minswap/sdk-v2
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for the Minswap API. Construct one instance and reach each area
|
|
4
|
+
through its module: tokens, pools, aggregator swaps, liquidity (add/remove/zap),
|
|
5
|
+
farms, MIN staking, portfolio, and orders.
|
|
6
|
+
|
|
7
|
+
The SDK is an API client — it **never signs or submits transactions**. Action
|
|
8
|
+
methods return CBOR for you to sign with your own wallet.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm add @minswap/sdk-v2
|
|
14
|
+
# or: npm install @minswap/sdk-v2
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Runs in Node and the browser on native `fetch`; no heavyweight chain library is
|
|
18
|
+
pulled in. Farm and staking actions need a wallet's UTxOs — see
|
|
19
|
+
[Chain access](#chain-access) — which is the only part that may need extra
|
|
20
|
+
setup.
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { MinswapSdk } from "@minswap/sdk-v2";
|
|
26
|
+
|
|
27
|
+
const sdk = new MinswapSdk();
|
|
28
|
+
|
|
29
|
+
// Reads
|
|
30
|
+
const ada = await sdk.token.getById("lovelace");
|
|
31
|
+
const pools = await sdk.pool.list({ sortBy: "tvl_usd", limit: 20 });
|
|
32
|
+
const positions = await sdk.portfolio.getDefi("addr1...");
|
|
33
|
+
|
|
34
|
+
// Aggregator swap: quote, build, sign yourself, submit
|
|
35
|
+
const quote = await sdk.aggregator.estimate({
|
|
36
|
+
amount: "1000000",
|
|
37
|
+
tokenIn: "lovelace",
|
|
38
|
+
tokenOut: "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6.4d494e",
|
|
39
|
+
slippage: 0.5,
|
|
40
|
+
});
|
|
41
|
+
const { cbor } = await sdk.aggregator.buildTx({
|
|
42
|
+
sender: "addr1...",
|
|
43
|
+
estimate: { amount: "1000000", tokenIn: "lovelace", tokenOut: quote.tokenOut, slippage: 0.5 },
|
|
44
|
+
minAmountOut: quote.minAmountOut,
|
|
45
|
+
});
|
|
46
|
+
// sign `cbor` with your wallet, then:
|
|
47
|
+
// await sdk.aggregator.submitTx({ cbor, witnessSet });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const sdk = new MinswapSdk({
|
|
54
|
+
network: "mainnet", // default
|
|
55
|
+
currency: "USD", // or "ADA"; per-call overridable
|
|
56
|
+
apiKey: process.env.MINSWAP_API_KEY, // raises the rate limit
|
|
57
|
+
timeoutMs: 30_000,
|
|
58
|
+
retry: { retries: 2, baseDelayMs: 300 },
|
|
59
|
+
// endpoints: { appApiUrl, aggregatorApiUrl, keyAppApiUrl }, // for staging/local
|
|
60
|
+
// fetch: customFetch, // inject for tests or non-global fetch
|
|
61
|
+
// rpcProvider, // required only by farm/staking actions
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Modules
|
|
66
|
+
|
|
67
|
+
| Module | What it does |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `sdk.token` | `getById`, `getByIds`, `list`, `getOhlc`, `getTradeHistory` |
|
|
70
|
+
| `sdk.pool` | `list`, `getById`, `getByIds`, `getOhlc`, `getEvents` |
|
|
71
|
+
| `sdk.portfolio` | `getDefi` — a wallet's LP, farm, and staking positions |
|
|
72
|
+
| `sdk.order` | `getHistory` — DEX order history across protocols |
|
|
73
|
+
| `sdk.aggregator` | `estimate`, `buildTx`, `submitTx`, `cancelOrders`, `getPendingOrders` |
|
|
74
|
+
| `sdk.liquidity` | `addLiquidity`, `removeLiquidity`, `zapIn`, `zapOut` — across DEX V2, V1, Stableswap |
|
|
75
|
+
| `sdk.farm` | `list`, `getPositions`, `deposit`, `withdraw`, `harvest`, `emergencyWithdraw` |
|
|
76
|
+
| `sdk.staking` | `list`, `getPositions`, `stake`, `unstake` |
|
|
77
|
+
|
|
78
|
+
`farm.deposit` and `farm.withdraw` branch for you — a first deposit versus adding
|
|
79
|
+
to a stake, a partial withdrawal versus withdrawing all — based on your current
|
|
80
|
+
position. `staking` routes tiered versus flexible automatically. `liquidity`
|
|
81
|
+
resolves the pool and version from a pair (or LP token) + amount + slippage;
|
|
82
|
+
orders are built **client-side** and need the optional `@minswap/internal-sdk`
|
|
83
|
+
peer (see [Chain access](#chain-access)).
|
|
84
|
+
|
|
85
|
+
## Documentation
|
|
86
|
+
|
|
87
|
+
Per-module reference, each with every function, description, usage, and examples:
|
|
88
|
+
|
|
89
|
+
- [Overview & shared concepts](./docs/README.md) — coinIds, amounts, config, pagination, errors, signing
|
|
90
|
+
- [`sdk.token`](./docs/token.md) · [`sdk.pool`](./docs/pool.md) · [`sdk.portfolio`](./docs/portfolio.md) · [`sdk.order`](./docs/order.md)
|
|
91
|
+
- [`sdk.aggregator`](./docs/aggregator.md) · [`sdk.liquidity`](./docs/liquidity.md) · [`sdk.farm`](./docs/farm.md) · [`sdk.staking`](./docs/staking.md)
|
|
92
|
+
- [Chain access (`RpcProvider` / Kupo)](./docs/chain-access.md)
|
|
93
|
+
|
|
94
|
+
## Chain access
|
|
95
|
+
|
|
96
|
+
Farm and staking actions build transactions that spend the wallet's UTxOs, so
|
|
97
|
+
the SDK needs to know what the wallet holds. Supply an `RpcProvider`:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { MinswapSdk, KupoRpcProvider } from "@minswap/sdk-v2";
|
|
101
|
+
|
|
102
|
+
const sdk = new MinswapSdk({
|
|
103
|
+
rpcProvider: new KupoRpcProvider({ url: "https://your-kupo:1442" }),
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`KupoRpcProvider` turns Kupo UTxOs into the CBOR the API expects. That requires a
|
|
108
|
+
Cardano serializer, which it loads from the optional peer dependency
|
|
109
|
+
[`@minswap/internal-sdk`](https://www.npmjs.com/package/@minswap/internal-sdk):
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
pnpm add @minswap/internal-sdk
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
That serializer ships Node-targeted WebAssembly, so `KupoRpcProvider`'s default
|
|
116
|
+
path is Node-only. In a browser, either supply your own `KupoSerializer`, or
|
|
117
|
+
implement the small `RpcProvider` interface against a server that returns
|
|
118
|
+
already-serialized UTxOs. Reads (token, pool, portfolio, order, aggregator
|
|
119
|
+
quotes) never need any of this.
|
|
120
|
+
|
|
121
|
+
## Errors
|
|
122
|
+
|
|
123
|
+
Every failure throws a `MinswapError` with a typed `code` and matching `details`:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { MinswapError, MinswapErrorCode } from "@minswap/sdk-v2";
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
await sdk.token.getById(id);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
if (MinswapError.is(e, MinswapErrorCode.RATE_LIMITED)) {
|
|
132
|
+
// e.details.retryAfterMs is typed here
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Nothing returns `null` to signal an error. Responses are validated at the
|
|
138
|
+
boundary, so a backend change surfaces as a located `PARSE_ERROR` rather than a
|
|
139
|
+
silent `undefined`.
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
pnpm install
|
|
145
|
+
pnpm test # vitest (hermetic — fake fetch, no network)
|
|
146
|
+
pnpm run type-check
|
|
147
|
+
pnpm run lint
|
|
148
|
+
pnpm run build # tsup -> dist (ESM + CJS + .d.ts)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT
|