@blazephoenix/sdk 0.4.0 → 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/README.md +136 -135
- package/dist/index.cjs +6292 -412
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3973 -430
- package/dist/index.d.ts +3973 -430
- package/dist/index.js +6243 -407
- package/dist/index.js.map +1 -1
- package/package.json +10 -11
package/README.md
CHANGED
|
@@ -1,184 +1,185 @@
|
|
|
1
1
|
# @blazephoenix/sdk
|
|
2
2
|
|
|
3
3
|
Official TypeScript SDK for **[BlazePhoenix](https://blazephoenix.xyz)** — the on-chain
|
|
4
|
-
DEX aggregator on **Base · Ethereum · Optimism · Arbitrum**.
|
|
4
|
+
DEX aggregator on **Base · Ethereum · Optimism · Arbitrum · Robinhood Chain**.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
> Live docs & playground: **https://blazephoenix.xyz/?tab=api**
|
|
6
|
+
**1.x runs 100% on YOUR RPC.** Every quote is an `eth_call` from your process to your
|
|
7
|
+
node, against the Quoter contract that settles the swap. There is no BlazePhoenix API
|
|
8
|
+
in the read path, no key, and the package ships no RPC endpoints (a test enforces it).
|
|
9
|
+
We don't pay for your reads, and you don't depend on our servers being up.
|
|
11
10
|
|
|
12
11
|
```bash
|
|
13
|
-
npm i
|
|
14
|
-
#
|
|
15
|
-
# optional (only for the on-chain module: quoteOnChain / watchFills / getFills):
|
|
16
|
-
npm i viem
|
|
12
|
+
npm i @blazephoenix/sdk viem
|
|
13
|
+
# or straight from GitHub (builds on install): npm i github:blazephoenixxyz-crypto/SDK viem
|
|
17
14
|
```
|
|
18
15
|
|
|
19
|
-
## Quote →
|
|
16
|
+
## Quote → build → execute
|
|
20
17
|
|
|
21
18
|
```ts
|
|
22
|
-
import { BlazePhoenix
|
|
23
|
-
|
|
24
|
-
const blaze = new BlazePhoenix(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const q = await blaze.quote({
|
|
28
|
-
chain: 'base', // 8453 | 'base' | 1 | 'eth' | 10 | 42161 …
|
|
29
|
-
tokenIn: 'WETH', // 0x-address, ETH/WETH/USDC/BZPX — or ANY traded
|
|
30
|
-
// symbol ('TOSHI', 'DEGEN'…): resolved to the
|
|
31
|
-
// deepest-liquidity token, echoed in q.resolved
|
|
32
|
-
tokenOut: 'USDC',
|
|
33
|
-
amountIn,
|
|
34
|
-
recipient: '0xYOU', // ← makes the API return ready-to-send calldata
|
|
35
|
-
slippageBps: 50,
|
|
19
|
+
import { BlazePhoenix } from '@blazephoenix/sdk';
|
|
20
|
+
|
|
21
|
+
const blaze = new BlazePhoenix({
|
|
22
|
+
rpc: { base: process.env.BASE_RPC_URL }, // YOUR node — any provider's free tier is enough
|
|
36
23
|
});
|
|
37
24
|
|
|
38
|
-
//
|
|
39
|
-
await
|
|
40
|
-
//
|
|
41
|
-
|
|
25
|
+
// 1) the Quoter's preview, read on your node ("amount" is human units)
|
|
26
|
+
const q = await blaze.quote({ chain: 'base', tokenIn: 'WETH', tokenOut: 'USDC', amount: '1.5' });
|
|
27
|
+
q.amountOut; // net output after the 0.28% fee (bigint, base units)
|
|
28
|
+
q.checks.verdict; // Phoenix Check: ok | caution | danger | blocked (fails closed)
|
|
29
|
+
q.version; // protocol version that answered ('1.0.0' today, '2.0.0' once deployed)
|
|
30
|
+
|
|
31
|
+
// 2) the swap transaction(s): verified calldata + the approval step if needed
|
|
32
|
+
const plan = await blaze.buildSwap({
|
|
33
|
+
chain: 'base', tokenIn: 'WETH', tokenOut: 'USDC', amount: '1.5',
|
|
34
|
+
recipient: me, from: me, // `from` enables the allowance check
|
|
35
|
+
slippageBps: 50, // default 50; never below the on-chain floor
|
|
36
|
+
});
|
|
37
|
+
plan.steps; // [approve?, swap] — { chainId, to, data, value }
|
|
38
|
+
plan.minOut; // the minimum the Router will enforce for you
|
|
39
|
+
plan.encodedBy; // 'quoter' on 2.x (the Quoter's own bytes, verified) · 'sdk' on 1.x
|
|
40
|
+
|
|
41
|
+
// 3) optional: dry-run on your node, then execute with YOUR wallet
|
|
42
|
+
await blaze.simulate(plan, me); // { ok, amountOut } or the decoded revert
|
|
43
|
+
const res = await blaze.execute({ wallet, plan }); // approve → simulate → swap → receipt
|
|
44
|
+
res.amountOut; // realised, from the Router's Swap event
|
|
42
45
|
```
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
`execute` takes a viem `WalletClient`. The SDK never asks for, stores or touches a key.
|
|
48
|
+
|
|
49
|
+
## Your RPC, your way
|
|
45
50
|
|
|
46
51
|
```ts
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
new BlazePhoenix({ rpc: 'https://your-base-node.example/KEY' }); // one node — its own chain
|
|
53
|
+
new BlazePhoenix({ rpc: ['https://node-a.example', 'https://node-b.example'] }); // your fallback order
|
|
54
|
+
new BlazePhoenix({ rpc: window.ethereum }); // the user's wallet (EIP-1193)
|
|
55
|
+
new BlazePhoenix({ rpc: http('https://…', { batch: true }) }); // any viem Transport
|
|
56
|
+
new BlazePhoenix({ rpc: { base: '…', eth: ['…', '…'], arbitrum: provider } }); // per chain
|
|
57
|
+
new BlazePhoenix(); // reads BLAZEPHOENIX_RPC_BASE / _ETHEREUM / _OPTIMISM / _ARBITRUM / _ROBINHOOD
|
|
58
|
+
// (comma-separated for fallback) or BLAZEPHOENIX_RPC_URL
|
|
52
59
|
```
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
- Each node is asked for `eth_chainId` once. Quoting Base contracts on an Ethereum node
|
|
62
|
+
throws `rpc_chain_mismatch` instead of returning garbage.
|
|
63
|
+
- With a single node, `chain` may be omitted: the node's own chain is used.
|
|
64
|
+
- A chain without a configured node throws `rpc_required` — nothing silently falls back
|
|
65
|
+
to someone else's infrastructure.
|
|
66
|
+
- `https://` and `wss://` only (`http://` allowed for `localhost` — your anvil/geth).
|
|
67
|
+
URLs are redacted in every error message, because keys live in them.
|
|
55
68
|
|
|
56
|
-
|
|
57
|
-
import { deepLink } from '@blazephoenix/sdk';
|
|
69
|
+
## Versions — pick yours
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
// → https://blazephoenix.xyz/?tab=swap&chain=8453&in=ETH&out=BZPX&amt=0.5
|
|
61
|
-
```
|
|
71
|
+
Protocol versions are deployments, not SDK versions:
|
|
62
72
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(bring your own node for production throughput). Still zero providers and zero
|
|
68
|
-
keys shipped — enforced by tests.
|
|
73
|
+
| version | status | what it is |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `1.0.0` | **live** on all five chains | the generation deployed at launch |
|
|
76
|
+
| `2.0.0` | pending | the final Core / Hub / Solver / Quoter / Router from [BlazePhoenix-Dex](https://github.com/blazephoenixxyz-crypto/Blaze-Phoenix-Dex) (`VERSION()` = `"2.0.0"`) |
|
|
69
77
|
|
|
70
78
|
```ts
|
|
71
|
-
|
|
79
|
+
new BlazePhoenix({ rpc, version: 'latest' }); // default: newest version deployed on each chain
|
|
80
|
+
new BlazePhoenix({ rpc, version: '1' }); // stay on 1.x
|
|
81
|
+
await blaze.quote({ ...req, version: '2.0.0' }); // per call
|
|
82
|
+
```
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
The SDK adapts to what each version can do (`featuresOf(version)`):
|
|
85
|
+
|
|
86
|
+
| capability | 1.x | 2.x |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| preview + Router calldata in ONE call (`previewAndEncode`) | — (encoded by the SDK) | ✅ verified field by field |
|
|
89
|
+
| native ETH in, no pre-wrap (`swapExactInNative`) | wrap first: `buildWrapTx` | ✅ |
|
|
90
|
+
| solve + execute in the same tx (`mode: 'best'` → `swapBestExactIn`) | — | ✅ |
|
|
91
|
+
| on-chain `batchQuote` | parallel previews | ✅ chunked |
|
|
92
|
+
| `ExecutionProof` on every fill (quoted vs realised vs floor) | — | ✅ |
|
|
93
|
+
|
|
94
|
+
### New deployments reach you without a new SDK release
|
|
95
|
+
|
|
96
|
+
The registry has three layers:
|
|
97
|
+
|
|
98
|
+
1. **Embedded** — shipped in the package. Non-zero addresses are **pins**: nothing fetched
|
|
99
|
+
at runtime can move them.
|
|
100
|
+
2. **Remote** — `GET https://blazephoenix.xyz/api/deployments` (static JSON, refreshed every
|
|
101
|
+
10 min in the background; the first lookup waits at most 3 s). It can only fill what the
|
|
102
|
+
snapshot doesn't know — e.g. the 2.0.0 addresses the day they are deployed — and only for
|
|
103
|
+
versions that can be verified on-chain (2.x+). Every remote-sourced set is **verified on
|
|
104
|
+
your RPC before first use**:
|
|
105
|
+
code at every address, `VERSION()` matches, and the Quoter, Router and Solver all point at
|
|
106
|
+
the same Hub and Solver. Anything else fails closed (`deployment_unverified`).
|
|
107
|
+
3. **Your overrides** — always win:
|
|
79
108
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
```ts
|
|
110
|
+
new BlazePhoenix({
|
|
111
|
+
rpc,
|
|
112
|
+
contracts: { base: { router: '0x…', quoter: '0x…', version: '2.0.0' } }, // your fork / audit target
|
|
113
|
+
registry: { mode: 'embedded' }, // never touch the network for addresses
|
|
83
114
|
});
|
|
115
|
+
await blaze.deployments(); // the chains × versions table this client sees
|
|
116
|
+
await blaze.verifyDeployment({ chain: 'base' }); // run the on-chain checks yourself
|
|
84
117
|
```
|
|
85
118
|
|
|
86
|
-
|
|
87
|
-
the input for the **quoted-vs-executed verification pattern** documented on the
|
|
88
|
-
API page: re-run each fill's quote at its block and compare with the executed
|
|
89
|
-
amount the event recorded. Verify us, don't trust us.
|
|
90
|
-
|
|
91
|
-
## Resilient by default (v0.3.0)
|
|
119
|
+
## Why the calldata can be trusted
|
|
92
120
|
|
|
93
|
-
|
|
121
|
+
On 2.x, `Quoter.previewAndEncode` returns the preview **and** the exact `swapExactIn` bytes that
|
|
122
|
+
execute it. The Quoter's own source says what that is worth — *"a compromised Quoter fools the
|
|
123
|
+
interface"* — so the SDK never forwards those bytes blind. It decodes them with the Router ABI
|
|
124
|
+
and refuses (`calldata_mismatch`) unless the amount, recipient, deadline, the route
|
|
125
|
+
(identical to the previewed one, connecting tokenIn → tokenOut) and a minimum at least the
|
|
126
|
+
on-chain floor all match what you asked. Your slippage then only ever **tightens** that minimum.
|
|
94
127
|
|
|
95
|
-
|
|
96
|
-
- preview quotes ride a **1s micro-cache** (`cacheTtlMs`; never applied to
|
|
97
|
-
`recipient`/`exact` requests — execution data stays fresh, always)
|
|
98
|
-
- transient failures (network, 429, 502–504) **retry with backoff** and honour
|
|
99
|
-
the server's `retry-after` (`retries`, default 2)
|
|
128
|
+
## More
|
|
100
129
|
|
|
101
130
|
```ts
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
131
|
+
await blaze.quoteExact(req); // previewPlanExact: every concentrated leg dry-run on the pool
|
|
132
|
+
await blaze.quoteBatch([req1, req2]); // per-item { ok, quote } | { ok:false, error }
|
|
133
|
+
await blaze.getFills({ chain: 'base', lookbackBlocks: 5_000n }); // Swap (+ ExecutionProof on 2.x)
|
|
134
|
+
const stop = await blaze.watchFills({ chain: 'base', onFill: console.log });
|
|
135
|
+
await blaze.tokenInfo('base', '0x…'); // symbol / name / decimals
|
|
136
|
+
await blaze.solvency(); // the staking engine's proof-of-solvency (Base)
|
|
137
|
+
toJSON(quote); // bigint → string, for HTTP / queues / LLMs
|
|
108
138
|
```
|
|
109
139
|
|
|
110
|
-
|
|
140
|
+
Pure helpers (no RPC): `buildApproveTx`, `buildWrapTx`, `buildUnwrapTx`, `permit2TypedData`,
|
|
141
|
+
`encodeSwapExactInWithPermit2`, `encodeSwapExactIn`, `verifySwapExactIn`, `minOutFor`,
|
|
142
|
+
`decodeBlazeError`, `toBaseUnits`, `fromBaseUnits`, `deepLink`.
|
|
111
143
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
The famous trading bots custody your funds; this one can't lose what it never
|
|
116
|
-
touches.
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
npm i grammy viem
|
|
120
|
-
BOT_TOKEN=... RPC_URL=https://your-base-rpc npx tsx examples/phoenix-bot.ts
|
|
121
|
-
```
|
|
144
|
+
Tokens: `0x` addresses, or the universal symbols `ETH` (native), `WETH`, `USDC` (the chain's
|
|
145
|
+
dollar asset — USDG on Robinhood), `BZPX`. Anything else: pass the address. The SDK never
|
|
146
|
+
guesses a token from a ticker.
|
|
122
147
|
|
|
123
148
|
## Errors
|
|
124
149
|
|
|
125
|
-
|
|
150
|
+
Every failure is a `BlazeError` with a stable `code`; protocol reverts carry `revert`
|
|
151
|
+
(`RouterE` / `QuoterE` / `SolverE` / `HubE` + the reason from the contract's own source):
|
|
126
152
|
|
|
127
153
|
| code | meaning |
|
|
128
154
|
|---|---|
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
155
|
+
| `rpc_required` | no node configured for that chain |
|
|
156
|
+
| `rpc_chain_mismatch` | the node serves a different chain |
|
|
157
|
+
| `rpc_error` | your node failed (network, rate limit) |
|
|
158
|
+
| `no_route` | the Solver found no executable path (`SolverE(5)`) or the quote reverted |
|
|
159
|
+
| `not_executable` | the Quoter says the route cannot settle now (`canExecute = false`) |
|
|
160
|
+
| `calldata_mismatch` | Quoter bytes did not match your request — refused |
|
|
161
|
+
| `deployment_unverified` | a registry deployment failed on-chain verification |
|
|
162
|
+
| `unsupported_by_version` | e.g. native ETH input on a 1.x Router |
|
|
163
|
+
| `not_deployed` / `bad_request` / `wallet_chain_mismatch` / `reverted` | as named |
|
|
132
164
|
|
|
133
|
-
##
|
|
165
|
+
## MCP (AI agents)
|
|
134
166
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
- Manifest (contracts / token / event topics): `GET https://blazephoenix.xyz/api/manifest`
|
|
138
|
-
- Examples: [`examples/`](examples) — plain quote, Telegram bot, fill watcher
|
|
139
|
-
- Protocol fee: 0.28% on quoted output; **execution surplus is fee-exempt → user**
|
|
167
|
+
[`@blazephoenix/mcp`](https://github.com/blazephoenixxyz-crypto/blazephoenix-mcp) wraps this SDK as
|
|
168
|
+
a local MCP server — the agent's tools run on your machine, on your RPC.
|
|
140
169
|
|
|
141
|
-
##
|
|
170
|
+
## Examples
|
|
142
171
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
[full proof-of-solvency report](https://blazephoenix.xyz/solvency)
|
|
172
|
+
[`examples/`](examples): `quote.ts`, `watch-fills.ts`, `telegram-bot.ts`, and
|
|
173
|
+
[`phoenix-bot.ts`](examples/phoenix-bot.ts) — a complete zero-custody Telegram bot on your own nodes.
|
|
146
174
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
| Ethereum (1) | Quoter | [`0x4a20AA0912388ff7A9221Ab6BFC224cc20Baa0c3`](https://etherscan.io/address/0x4a20AA0912388ff7A9221Ab6BFC224cc20Baa0c3) |
|
|
155
|
-
| Optimism (10) | Router | [`0x7262e7483ab6f0db7b8f90eC3a9de3B02Ab36F6A`](https://optimistic.etherscan.io/address/0x7262e7483ab6f0db7b8f90eC3a9de3B02Ab36F6A) |
|
|
156
|
-
| Optimism (10) | Quoter | [`0xfB18EF6f62A0278A273Af4b7A46b454F9E482dc2`](https://optimistic.etherscan.io/address/0xfB18EF6f62A0278A273Af4b7A46b454F9E482dc2) |
|
|
157
|
-
| Arbitrum (42161) | Router | [`0x7262e7483ab6f0db7b8f90eC3a9de3B02Ab36F6A`](https://arbiscan.io/address/0x7262e7483ab6f0db7b8f90eC3a9de3B02Ab36F6A) |
|
|
158
|
-
| Arbitrum (42161) | Quoter | [`0xfB18EF6f62A0278A273Af4b7A46b454F9E482dc2`](https://arbiscan.io/address/0xfB18EF6f62A0278A273Af4b7A46b454F9E482dc2) |
|
|
159
|
-
|
|
160
|
-
Always cross-check against the live manifest: `https://blazephoenix.xyz/api/manifest`.
|
|
161
|
-
|
|
162
|
-
## Learn the engineering
|
|
163
|
-
|
|
164
|
-
The protocol is documented from the deployed bytecode — every article ends with
|
|
165
|
-
a command to reproduce its claims:
|
|
166
|
-
|
|
167
|
-
- **The mathematics** (every formula; the originals are ours): https://blazephoenix.xyz/learn/the-mathematics
|
|
168
|
-
- **Integrate any bot** (keyless / keyed / ethers / viem / Python / AI-agent): https://blazephoenix.xyz/learn/integrate-any-bot
|
|
169
|
-
- **Web 2.5 vs Web 3.0** (the decision on-chain, not just settlement): https://blazephoenix.xyz/learn/web25-vs-web30
|
|
170
|
-
- **Machine-readable measured cases**: https://blazephoenix.xyz/measured-cases.json
|
|
171
|
-
- **Agent guide**: https://blazephoenix.xyz/llms.txt
|
|
172
|
-
|
|
173
|
-
## Citing BlazePhoenix
|
|
174
|
-
|
|
175
|
-
This repository ships a `CITATION.cff`, so GitHub shows a **“Cite this
|
|
176
|
-
repository”** button. Please cite with attribution and a link — the protocol's
|
|
177
|
-
original constructions (the Iron Law Φ, the Vitality Field Ψ, the
|
|
178
|
-
Capital-Anchored Filter, the Master Conservation Identity) are © 2026
|
|
179
|
-
BlazePhoenix.
|
|
175
|
+
## Regenerating the ABIs
|
|
176
|
+
|
|
177
|
+
The protocol ABIs are compiled from the Solidity sources, never written by hand:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
npm i --no-save solc@0.8.36 && npm run gen:abis # expects ../Blaze-Phoenix-Dex
|
|
181
|
+
```
|
|
180
182
|
|
|
181
183
|
## License
|
|
182
184
|
|
|
183
|
-
MIT —
|
|
184
|
-
(The BlazePhoenix protocol and site carry their own licenses.)
|
|
185
|
+
MIT — deliberately permissive so anyone can integrate. The protocol contracts are BUSL-1.1.
|