@blazephoenix/sdk 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BlazePhoenix (blazephoenixxyz-crypto)
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,184 @@
1
+ # @blazephoenix/sdk
2
+
3
+ Official TypeScript SDK for **[BlazePhoenix](https://blazephoenix.xyz)** — the on-chain
4
+ DEX aggregator on **Base · Ethereum · Optimism · Arbitrum**.
5
+
6
+ Every number the API serves is computed **on-chain** by the Quoter contract
7
+ (`previewPlan`) — your bot, your frontend and the site itself all read the same truth.
8
+ **No API key. No signup. Open CORS.**
9
+
10
+ > Live docs & playground: **https://blazephoenix.xyz/?tab=api**
11
+
12
+ ```bash
13
+ npm i github:blazephoenixxyz-crypto/SDK # builds on install — no registry needed
14
+ # (or, once published to npm:) npm i @blazephoenix/sdk
15
+ # optional (only for the on-chain module: quoteOnChain / watchFills / getFills):
16
+ npm i viem
17
+ ```
18
+
19
+ ## Quote → approve → send (the whole loop)
20
+
21
+ ```ts
22
+ import { BlazePhoenix, buildSwapTx, buildApproveTx, toBaseUnits } from '@blazephoenix/sdk';
23
+
24
+ const blaze = new BlazePhoenix();
25
+ const amountIn = toBaseUnits('1.5', 18); // "1.5" WETH → 1500000000000000000n
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,
36
+ });
37
+
38
+ // once per token: allow the Router to pull tokenIn (exact amount — or MAX_UINT256)
39
+ await wallet.sendTransaction(buildApproveTx({ chain: 'base', token: q.tokenIn, amount: amountIn }));
40
+ // then execute exactly what was quoted:
41
+ await wallet.sendTransaction(buildSwapTx(q)); // { to, data, value }
42
+ ```
43
+
44
+ ## Batch quotes (screeners / arb loops)
45
+
46
+ ```ts
47
+ const { results } = await blaze.quoteBatch([
48
+ { chain: 'base', tokenIn: 'WETH', tokenOut: 'USDC', amountIn: 10n ** 18n },
49
+ { chain: 'base', tokenIn: 'WETH', tokenOut: 'BZPX', amountIn: 10n ** 18n },
50
+ { chain: 'arbitrum', tokenIn: 'WETH', tokenOut: 'USDC', amountIn: 10n ** 18n },
51
+ ]); // one round-trip (max 10), per-item errors inline
52
+ ```
53
+
54
+ ## Deep links (bot buttons / referral posts)
55
+
56
+ ```ts
57
+ import { deepLink } from '@blazephoenix/sdk';
58
+
59
+ deepLink({ chain: 'base', tokenIn: 'ETH', tokenOut: 'BZPX', amount: '0.5' });
60
+ // → https://blazephoenix.xyz/?tab=swap&chain=8453&in=ETH&out=BZPX&amt=0.5
61
+ ```
62
+
63
+ ## On-chain module (optional `viem` peer)
64
+
65
+ Zero middlemen — same numbers, straight from the chain. **RPC optional since
66
+ v0.4.0**: omit `rpcUrl` and the SDK falls back across public keyless endpoints
67
+ (bring your own node for production throughput). Still zero providers and zero
68
+ keys shipped — enforced by tests.
69
+
70
+ ```ts
71
+ import { quoteOnChain, watchFills, getFills } from '@blazephoenix/sdk';
72
+
73
+ const { preview } = await quoteOnChain({
74
+ chain: 'base', rpcUrl: RPC,
75
+ tokenIn: '0x4200000000000000000000000000000000000006',
76
+ tokenOut: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
77
+ amountIn: 10n ** 18n,
78
+ });
79
+
80
+ const unwatch = await watchFills({
81
+ chain: 'base', rpcUrl: RPC,
82
+ onFill: (f) => console.log(f.txHash, f.amountIn, '→', f.amountOut),
83
+ });
84
+ ```
85
+
86
+ `getFills({ chain, rpcUrl, fromBlock, toBlock })` gives you the raw fill history —
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)
92
+
93
+ Every call ships the same meta-patterns the BlazePhoenix edge runs — no config:
94
+
95
+ - identical concurrent calls **coalesce into one request** (singleflight)
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)
100
+
101
+ ```ts
102
+ // a price loop in one line — overlap-safe, stop() when done:
103
+ import { pollQuote } from '@blazephoenix/sdk';
104
+ const stop = pollQuote(blaze,
105
+ { chain: 'base', tokenIn: 'WETH', tokenOut: 'USDC', amountIn: 10n ** 18n },
106
+ (q) => console.log('WETH→USDC', q.amountOut),
107
+ { intervalMs: 4000 });
108
+ ```
109
+
110
+ ## 🔥 Phoenix Bot — zero-custody Telegram bot
111
+
112
+ [`examples/phoenix-bot.ts`](examples/phoenix-bot.ts) is a complete Telegram bot
113
+ with a difference: **it never holds a key**. It quotes on-chain truth, streams
114
+ real fills (`/watch`), and executes by deep-linking users into their OWN wallet.
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
+ ```
122
+
123
+ ## Errors
124
+
125
+ HTTP-level failures throw `BlazeApiError` with a stable `code`:
126
+
127
+ | code | meaning |
128
+ |---|---|
129
+ | `bad_*` (400) | invalid parameter — message names the field |
130
+ | `no_route` (422) | Quoter reverted: no executable route for this pair/size |
131
+ | `rpc_unreachable` (502) | all upstream RPCs failed — retry shortly |
132
+
133
+ ## Reference
134
+
135
+ - REST endpoint: `GET https://blazephoenix.xyz/api/quote`
136
+ - Batch: `POST https://blazephoenix.xyz/api/quote/batch`
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**
140
+
141
+ ## Deployed contracts (verified)
142
+
143
+ ![solvency](https://img.shields.io/endpoint?url=https%3A%2F%2Fblazephoenix.xyz%2Fapi%2Fbadge)
144
+ — live `isSolvent()` read from the Base staking contract ·
145
+ [full proof-of-solvency report](https://blazephoenix.xyz/solvency)
146
+
147
+ | Chain | Contract | Address |
148
+ |---|---|---|
149
+ | Base (8453) | Router | [`0x2a779f9Be49aac57495A8B6467Cc325a8a47Eb9f`](https://basescan.org/address/0x2a779f9Be49aac57495A8B6467Cc325a8a47Eb9f) |
150
+ | Base (8453) | Quoter | [`0x4cEF0615614B212895F45Aa1D4833B16666E18d3`](https://basescan.org/address/0x4cEF0615614B212895F45Aa1D4833B16666E18d3) |
151
+ | Base (8453) | Staking | [`0x3f60C7aa0c36a78D200405feBE143d2Cf3fA0c77`](https://basescan.org/address/0x3f60C7aa0c36a78D200405feBE143d2Cf3fA0c77) |
152
+ | Base (8453) | BZPX token | [`0x23113e72165a034265Ab8Bf2277CCB7a85Cb7483`](https://basescan.org/address/0x23113e72165a034265Ab8Bf2277CCB7a85Cb7483) |
153
+ | Ethereum (1) | Router | [`0xE1aE5f49013920CF71De8CED4043e14C4d63416b`](https://etherscan.io/address/0xE1aE5f49013920CF71De8CED4043e14C4d63416b) |
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.
180
+
181
+ ## License
182
+
183
+ MIT — the SDK is deliberately permissive so anyone can integrate.
184
+ (The BlazePhoenix protocol and site carry their own licenses.)