torchsdk 4.0.1 → 4.1.1

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 CHANGED
@@ -1,370 +1,174 @@
1
1
  # Torch SDK
2
2
 
3
- TypeScript SDK for [Torch Market](https://torch.market) — the fair-launch token protocol on Solana.
3
+ TypeScript SDK for [Torch Market](https://torch.market).
4
4
 
5
- Read on-chain state, build transactions, and interact with bonding curves, vaults, governance, lending, and the SAID Protocol all directly via Solana RPC. No API middleman.
5
+ Every token launched on Torch gets a bonding curve for price discovery, a community treasury funded by trading, and a lending market that activates after migration to Raydium. The SDK is the primary way to interact with the protocol it builds transactions locally from the on-chain Anchor IDL, reads all state directly from Solana RPC, and handles routing between bonding curves and DEX pools automatically. No API server. No middleman.
6
6
 
7
- ## Design
8
-
9
- for in depth sdk design, refer to [design.md](./design.md).
10
-
11
- ## Audit
12
-
13
- for sdk audit, refer to [audit.md](./audit.md).
14
-
15
- ## Versioning
16
-
17
- SDK version tracks the on-chain program IDL version.
18
-
19
- ## v4.0.0 + v4.0.1
20
-
21
- - **V4.0 Simplified Tiers & Reduced Fees** — Removed 50 SOL (Spark) tier from token creation (existing tokens unaffected). Treasury SOL rate reduced from 20%→5% to 12.5%→4%. Protocol fee reduced from 1% to 0.5%. Constants-only change — no new instructions, no state migration. IDL updated to v4.0.0. 48 Kani proofs all passing.
22
-
23
- ## v3.7.35
24
-
25
- - **`getBorrowQuote`** — New quote function computes maximum borrowable SOL for a given collateral amount on a migrated token. Returns the binding constraint across LTV cap, pool available liquidity, and per-user cap — plus full breakdown of all three limits. Accounts for Token-2022 transfer fee (4 bps). New type: `BorrowQuoteResult`.
26
- - **`getMessages` post-migration support** — Now fetches memos from both bonding curve transactions and Raydium pool transactions. Also checks inner instructions (for vault swap memos). Results merged, deduped by signature, and sorted newest-first. No signature or return type changes.
27
- - **E2E test updates** — Borrow sections in `test_e2e.ts` and `test_devnet_e2e.ts` now use `getBorrowQuote` instead of inline constraint calculations.
28
-
29
- ## v3.7.32
30
-
31
- - **Post Migration Accounts** export helper.
32
-
33
- ## v3.7.31
34
-
35
- - **Vault Swap Messages** add token memos to vault swaps post migration.
36
-
37
- ### v3.7.30
38
-
39
- - **V35 Community Token Option** — Token creators can now choose between **community token** (default: 0% creator fees, entire 0.04% transfer fee proceeds go to treasury) or **creator token** (opt-in: 0.2%→1% bonding SOL share + 15% post-migration fee swap share). Choice is permanent and set at creation via `community_token` parameter on `buildCreateTokenTransaction`. New tokens default to community mode. No new instructions, no new accounts, no state layout changes. Stars unaffected — community token creators can still receive star payouts. IDL updated to v3.7.10. 46 Kani proofs (2 new: community token buy conservation, community token swap fees conservation).
40
-
41
- ### v3.7.29
42
-
43
- - **V36 Lending Cap** new lending cap on token treasuries per user based on collateral size.
44
-
45
- ### v3.7.24 + v3.7.25
46
-
47
- - **V35 Optional Account Param On Sells** on bond non-voting accounts can sell.
48
-
49
- ### v3.7.23
50
-
51
- - **V34 Creator Fee Structure** creator rewards have been introduced, with pre and post migration rewards designed to reward good creators.
52
-
53
- ### v3.7.22
7
+ ## Install
54
8
 
55
- - **V33 Buyback Removal + Lending Cap Increase** — `buildAutoBuybackTransaction` removed (~180 lines of SDK code). The on-chain `execute_auto_buyback` instruction was removed in V33 (program v3.7.7, 27 instructions). Treasury simplified to: fee harvest → sell high → SOL → lending yield + epoch rewards. Lending utilization cap increased from 50% to 70%. `AutoBuybackParams` type removed. IDL updated to v3.7.7. 39 Kani proofs all passing. Binary size reduced ~6% (850 KB → 804 KB).
56
- - **V32 Protocol Fee Change**
9
+ ```bash
10
+ pnpm add torchsdk
11
+ ```
57
12
 
58
- ### v3.7.20
13
+ Peer dependency: `@solana/web3.js ^1.98.0`
59
14
 
60
- - **Legacy Tokens** - blacklisted tokens now marked legacy and withdraw only.
15
+ ## How It Works
61
16
 
62
- ### v3.7.18
17
+ ```
18
+ 1. Get a quote → getBuyQuote / getSellQuote
19
+ 2. Build a tx → buildBuyTransaction / buildSellTransaction
20
+ 3. Sign and send → your wallet / keypair
21
+ ```
63
22
 
64
- - **V31 Zero-Burn Migration** — IDL updated to v3.7.5 (program v3.7.5). CURVE_SUPPLY 750M → 700M, TREASURY_LOCK_TOKENS 250M → 300M. Zero tokens burned at migration — vault remainder exactly equals price-matched pool allocation. Transfer fee 0.1% → 0.25% for new tokens. Vote return now redirects to treasury lock (community reserve) instead of Raydium LP. `buildMigrateTransaction` passes `treasuryLock` PDA and `treasuryLockTokenAccount` to the new on-chain context. 38 Kani proofs all passing (including 3 new zero-excess-burn proofs and Flame price-match proof). All three tiers (Spark/Flame/Torch) preserved.
23
+ The SDK is VersionedTransaction-native. All transaction builders return v0 transactions compressed with Address Lookup Tables for smaller tx sizes and more headroom.
65
24
 
66
- ### v3.7.17
25
+ | Network | ALT Address |
26
+ |---------|-------------|
27
+ | Mainnet | `GQzbU32oN3znZa3uWFKGc9cBukpQbYYJSirKstMuFF3i` |
28
+ | Devnet | `3umSStZSLJNk5QstxeQB12a2MSDh4o8RgSzT76gigJ8P` |
67
29
 
68
- - **`getAllLoanPositions`** New SDK function scans all on-chain LoanPosition accounts for a given mint. Returns active positions with computed health status (collateral value, LTV, health), sorted liquidatable-first. Fetches Raydium pool price once (not per-position) for efficient valuation. New types: `LoanPositionWithKey` (extends `LoanPositionInfo` with `borrower` address), `AllLoanPositionsResult`.
30
+ Quotes work across both bonding curve and DEX the `source` field tells you which. Pass the quote into the transaction builder and the SDK handles routing and slippage protection automatically.
69
31
 
70
- ### v3.7.16
32
+ ```typescript
33
+ import { Connection } from "@solana/web3.js";
34
+ import { getBuyQuote, buildBuyTransaction } from "torchsdk";
71
35
 
72
- - **V29 On-Chain Metadata** — Metaplex `buildAddMetadataTransaction` removed (temporary backfill complete — all active tokens now use Token-2022 metadata extensions). New `getTokenMetadata(connection, mint)` read-only function returns `{ name, symbol, uri, mint }` from on-chain Token-2022 metadata. Transfer fee updated from 1% to 0.1% on-chain. IDL updated to v3.7.4 (28 instructions).
36
+ const connection = new Connection("https://api.mainnet-beta.solana.com");
73
37
 
74
- ### v3.7.10
38
+ // Works on any token — bonding or migrated
39
+ const quote = await getBuyQuote(connection, mint, 100_000_000); // 0.1 SOL
40
+ console.log(`${quote.tokens_to_user / 1e6} tokens, source: ${quote.source}`);
75
41
 
76
- - **V20 Swap Fees to SOL** — New `buildSwapFeesToSolTransaction` bundles `create_idempotent(treasury_wsol)` + `harvest_fees` + `swap_fees_to_sol` in one atomic transaction. Sells harvested Token-2022 transfer fee tokens back to SOL via Raydium CPMM. Treasury PDA signs the swap, WSOL unwrapped to SOL, proceeds added to `treasury.sol_balance` and tracked in `treasury.harvested_fees`. Set `harvest=false` to skip harvest if already done separately. New type: `SwapFeesToSolParams`.
77
- - **Vault ordering bug fix** — Fixed `validate_pool_accounts` vault ordering in `swap_fees_to_sol` handler. Vaults are now passed in pool order (by mint pubkey) instead of swap direction, preventing false validation failures for tokens where `mint < WSOL` (~2.6% of tokens).
78
- - **28 instructions** — IDL updated to v3.7.10 (28 instructions, up from 27). *(27 instructions as of v3.7.22 — buyback removed in V33)*
42
+ const { transaction } = await buildBuyTransaction(connection, {
43
+ mint,
44
+ buyer: agentWallet,
45
+ amount_sol: 100_000_000,
46
+ slippage_bps: 500, // 5%
47
+ vault: vaultCreator,
48
+ quote, // drives routing + slippage protection
49
+ });
50
+ // sign and send — VersionedTransaction, ALT-compressed
51
+ ```
79
52
 
53
+ ## Torch Vault
80
54
 
81
- <details>
82
- <summary>Older versions (v3.2.0 – v3.7.4)</summary>
55
+ The vault is a full-custody on-chain escrow for AI agents. It holds all SOL and tokens. The agent wallet is a disposable controller that signs transactions but holds nothing of value.
83
56
 
84
- See git history for full changelog. Key milestones: v3.2.0 (full custody vault), v3.3.0 (tiered bonding curves), v3.6.8 (permissionless DEX migration), v3.7.0 (treasury lock + PDA pool validation).
57
+ ```
58
+ Human (hardware wallet) Agent (disposable, ~0.01 SOL for gas)
59
+ ├── createVault() ├── buy(vault=creator) → vault pays
60
+ ├── depositVault(5 SOL) ├── sell(vault=creator) → SOL returns to vault
61
+ ├── linkWallet(agentPubkey) ├── borrow(vault=creator) → SOL to vault
62
+ ├── withdrawVault() ├── repay(vault=creator) → collateral returns
63
+ └── unlinkWallet(agent) └── star(vault=creator) → vault pays
64
+ ```
85
65
 
86
- </details>
66
+ Seven guarantees: full custody, closed economic loop, authority separation, one link per wallet, permissionless deposits, instant revocation, authority-only withdrawals.
87
67
 
88
- ## API Reference
68
+ ## Operations
89
69
 
90
- ### Token Data
70
+ ### Queries (no signing)
91
71
 
92
72
  | Function | Description |
93
73
  |----------|-------------|
94
74
  | `getTokens(connection, params?)` | List tokens with filtering and sorting |
95
- | `getToken(connection, mint)` | Get full token details (metadata, treasury, votes, stars) |
96
- | `getHolders(connection, mint)` | Get token holder list (excludes pools/vaults) |
97
- | `getMessages(connection, mint, limit?)` | Get trade-bundled memos (bonding curve + post-migration DEX) |
98
- | `getLendingInfo(connection, mint)` | Get lending parameters for a migrated token |
99
- | `getTokenMetadata(connection, mint)` | Get on-chain Token-2022 metadata (name, symbol, uri) |
100
- | `getLoanPosition(connection, mint, wallet)` | Get a wallet's loan position |
101
- | `getAllLoanPositions(connection, mint)` | Get all active loan positions for a token (sorted by health) |
102
-
103
- ### Vault Queries
104
-
105
- | Function | Description |
106
- |----------|-------------|
107
- | `getVault(connection, creator)` | Get vault state by creator pubkey |
108
- | `getVaultForWallet(connection, wallet)` | Find vault by any linked wallet (reverse lookup) |
109
- | `getVaultWalletLink(connection, wallet)` | Get link state (which vault, when linked) |
75
+ | `getToken(connection, mint)` | Full token details (price, treasury, votes, status) |
76
+ | `getTokenMetadata(connection, mint)` | On-chain Token-2022 metadata |
77
+ | `getHolders(connection, mint)` | Token holder list |
78
+ | `getMessages(connection, mint, limit?, opts?)` | Trade-bundled memos. `{ enrich: true }` adds SAID verification |
79
+ | `getLendingInfo(connection, mint)` | Lending parameters for migrated tokens |
80
+ | `getLoanPosition(connection, mint, wallet)` | Single loan position |
81
+ | `getAllLoanPositions(connection, mint)` | All positions sorted by liquidation risk |
82
+ | `getVault(connection, creator)` | Vault state |
83
+ | `getVaultForWallet(connection, wallet)` | Reverse lookup — find vault by linked wallet |
84
+ | `getVaultWalletLink(connection, wallet)` | Link state for a wallet |
110
85
 
111
86
  ### Quotes
112
87
 
113
88
  | Function | Description |
114
89
  |----------|-------------|
115
- | `getBuyQuote(connection, mint, solAmount)` | Simulate a buy — expected tokens, fees, price impact |
116
- | `getSellQuote(connection, mint, tokenAmount)` | Simulate a sell — expected SOL, price impact |
117
- | `getBorrowQuote(connection, mint, collateralAmount)` | Max borrowable SOL for given collateral LTV, pool, and per-user caps |
90
+ | `getBuyQuote(connection, mint, solAmount)` | Expected tokens, fees, price impact. Returns `source: 'bonding' \| 'dex'` |
91
+ | `getSellQuote(connection, mint, tokenAmount)` | Expected SOL, price impact. Returns `source: 'bonding' \| 'dex'` |
92
+ | `getBorrowQuote(connection, mint, collateralAmount)` | Max borrowable SOL with breakdown of constraints |
118
93
 
119
- ### Transaction Builders
94
+ ### Trading
120
95
 
121
- All builders return `{ transaction: Transaction, message: string }`. You sign and send.
122
-
123
- #### Trading
96
+ All builders return `{ transaction: VersionedTransaction, message: string }`.
124
97
 
125
98
  | Function | Description |
126
99
  |----------|-------------|
127
- | `buildBuyTransaction(connection, params)` | Buy tokens on bonding curve (vault-funded) |
128
- | `buildDirectBuyTransaction(connection, params)` | Buy tokens (buyer pays directly, no vault) |
129
- | `buildSellTransaction(connection, params)` | Sell tokens back to the bonding curve (vault-routed) |
130
- | `buildVaultSwapTransaction(connection, params)` | Buy/sell migrated tokens on Raydium DEX (vault-routed) |
131
- | `buildMigrateTransaction(connection, params)` | Migrate bonding-complete token to Raydium DEX (permissionless, payer reimbursed by treasury) |
132
- | `buildCreateTokenTransaction(connection, params)` | Launch a new token |
133
- | `buildStarTransaction(connection, params)` | Star a token (0.05 SOL, vault-routed) |
100
+ | `buildBuyTransaction(connection, params)` | Buy tokens via vault. Auto-routes bonding curve or DEX based on quote |
101
+ | `buildDirectBuyTransaction(connection, params)` | Buy without vault (human wallets only) |
102
+ | `buildSellTransaction(connection, params)` | Sell tokens via vault. Auto-routes bonding curve or DEX based on quote |
103
+ | `buildCreateTokenTransaction(connection, params)` | Launch a new token with bonding curve + treasury |
104
+ | `buildStarTransaction(connection, params)` | Star a token (0.02 SOL, sybil-resistant) |
105
+ | `buildMigrateTransaction(connection, params)` | Migrate bonding-complete token to Raydium (permissionless) |
134
106
 
135
- #### Vault Management
107
+ ### Vault Management
136
108
 
137
109
  | Function | Signer | Description |
138
110
  |----------|--------|-------------|
139
111
  | `buildCreateVaultTransaction` | creator | Create vault + auto-link creator |
140
- | `buildDepositVaultTransaction` | depositor | Deposit SOL (permissionless) |
112
+ | `buildDepositVaultTransaction` | anyone | Deposit SOL (permissionless) |
141
113
  | `buildWithdrawVaultTransaction` | authority | Withdraw SOL |
142
- | `buildWithdrawTokensTransaction` | authority | Withdraw tokens from vault ATA |
143
- | `buildLinkWalletTransaction` | authority | Link a wallet to the vault |
144
- | `buildUnlinkWalletTransaction` | authority | Unlink a wallet |
114
+ | `buildWithdrawTokensTransaction` | authority | Withdraw tokens from vault |
115
+ | `buildLinkWalletTransaction` | authority | Link a controller wallet |
116
+ | `buildUnlinkWalletTransaction` | authority | Revoke controller access |
145
117
  | `buildTransferAuthorityTransaction` | authority | Transfer admin control |
146
118
 
147
- #### Lending (Post-Migration)
119
+ ### Lending (post-migration)
148
120
 
149
121
  | Function | Description |
150
122
  |----------|-------------|
151
123
  | `buildBorrowTransaction(connection, params)` | Borrow SOL against token collateral (vault-routed) |
152
- | `buildRepayTransaction(connection, params)` | Repay SOL debt (vault-routed) |
153
- | `buildLiquidateTransaction(connection, params)` | Liquidate underwater position (vault-routed) |
154
- | `buildClaimProtocolRewardsTransaction(connection, params)` | Claim protocol trading rewards (vault-routed) |
124
+ | `buildRepayTransaction(connection, params)` | Repay debt (vault-routed) |
125
+ | `buildLiquidateTransaction(connection, params)` | Liquidate underwater position (>65% LTV) |
126
+ | `buildClaimProtocolRewardsTransaction(connection, params)` | Claim epoch trading rewards (vault-routed) |
155
127
 
156
- #### Treasury Cranks (Permissionless)
128
+ ### Treasury Cranks (permissionless)
157
129
 
158
130
  | Function | Description |
159
131
  |----------|-------------|
160
- | `buildHarvestFeesTransaction(connection, params)` | Harvest Token-2022 transfer fees into treasury. Auto-discovers source accounts or accepts explicit list. |
161
- | `buildSwapFeesToSolTransaction(connection, params)` | Swap harvested transfer fee tokens to SOL via Raydium. Bundles harvest + swap in one atomic tx. |
132
+ | `buildHarvestFeesTransaction(connection, params)` | Harvest Token-2022 transfer fees into treasury |
133
+ | `buildSwapFeesToSolTransaction(connection, params)` | Swap harvested tokens to SOL via Raydium |
134
+ | `buildReclaimFailedTokenTransaction(connection, params)` | Reclaim tokens inactive 7+ days |
162
135
 
163
136
  ### SAID Protocol
164
137
 
165
138
  | Function | Description |
166
139
  |----------|-------------|
167
- | `verifySaid(wallet)` | Check SAID verification status and trust tier |
168
- | `confirmTransaction(connection, signature, wallet)` | Confirm tx on-chain for reputation tracking |
169
-
170
- ## Install
171
-
172
- ```bash
173
- pnpm add torchsdk
174
- ```
175
-
176
- Peer dependency: `@solana/web3.js ^1.98.0`
177
-
178
- ## Quick Start
179
-
180
- ```typescript
181
- import { Connection } from "@solana/web3.js";
182
- import {
183
- getTokens,
184
- getToken,
185
- buildBuyTransaction,
186
- buildDirectBuyTransaction,
187
- buildSellTransaction,
188
- buildCreateVaultTransaction,
189
- buildDepositVaultTransaction,
190
- buildLinkWalletTransaction,
191
- getVault,
192
- confirmTransaction,
193
- } from "torchsdk";
194
-
195
- const connection = new Connection("https://api.mainnet-beta.solana.com");
196
- ```
197
-
198
- ### Set Up a Vault
199
-
200
- ```typescript
201
- // 1. Create vault (user wallet)
202
- const { transaction: createTx } = await buildCreateVaultTransaction(connection, {
203
- creator: userWallet,
204
- });
205
- // sign and send createTx...
206
-
207
- // 2. Deposit SOL
208
- const { transaction: depositTx } = await buildDepositVaultTransaction(connection, {
209
- depositor: userWallet,
210
- vault_creator: userWallet,
211
- amount_sol: 5_000_000_000, // 5 SOL
212
- });
213
- // sign and send depositTx...
214
-
215
- // 3. Link an agent wallet
216
- const { transaction: linkTx } = await buildLinkWalletTransaction(connection, {
217
- authority: userWallet,
218
- vault_creator: userWallet,
219
- wallet_to_link: agentWallet,
220
- });
221
- // sign and send linkTx...
222
- ```
223
-
224
- ### Trade with Vault
225
-
226
- ```typescript
227
- // Agent buys tokens — vault pays
228
- const { transaction, message } = await buildBuyTransaction(connection, {
229
- mint: "TOKEN_MINT_ADDRESS",
230
- buyer: agentWallet,
231
- amount_sol: 100_000_000, // 0.1 SOL (in lamports)
232
- slippage_bps: 500, // 5% slippage
233
- vote: "burn", // governance vote on first buy
234
- vault: userWallet, // vault creator key → vault pays
235
- });
236
- // agent signs and sends...
237
-
238
- // Check vault balance
239
- const vault = await getVault(connection, userWallet);
240
- console.log(`Vault: ${vault.sol_balance} SOL, ${vault.linked_wallets} wallets`);
241
- ```
242
-
243
- ### Direct Buy (No Vault — Human Use Only)
244
-
245
- ```typescript
246
- // Buyer pays directly from their wallet — no vault safety
247
- const { transaction } = await buildDirectBuyTransaction(connection, {
248
- mint: "TOKEN_MINT_ADDRESS",
249
- buyer: walletAddress,
250
- amount_sol: 100_000_000,
251
- slippage_bps: 500,
252
- vote: "burn",
253
- });
254
- ```
255
-
256
- ## Transaction Params
257
-
258
- ```typescript
259
- // Buy (vault-funded — recommended for agents)
260
- {
261
- mint: string,
262
- buyer: string,
263
- amount_sol: number, // lamports
264
- slippage_bps?: number, // default 100 (1%)
265
- vote?: "burn" | "return", // required on first buy
266
- message?: string, // optional SPL Memo (max 500 chars)
267
- vault: string, // vault creator pubkey (required)
268
- }
269
-
270
- // Direct Buy (no vault — human use only)
271
- {
272
- mint: string,
273
- buyer: string,
274
- amount_sol: number, // lamports
275
- slippage_bps?: number, // default 100 (1%)
276
- vote?: "burn" | "return", // required on first buy
277
- message?: string, // optional SPL Memo (max 500 chars)
278
- }
279
-
280
- // Sell
281
- {
282
- mint: string,
283
- seller: string,
284
- amount_tokens: number, // raw units (with decimals)
285
- slippage_bps?: number,
286
- message?: string,
287
- }
288
-
289
- // Create Token
290
- { creator: string, name: string, symbol: string, metadata_uri: string, sol_target?: number, community_token?: boolean }
291
- // sol_target: 100_000_000_000 (Flame), 200_000_000_000 (Torch, default). Spark (50 SOL) removed in V4.0.
292
- // community_token: true (default) = 0% creator fees, false = creator gets 0.2%→1% bonding + 15% fee swap
293
-
294
- // Star
295
- { mint: string, user: string }
296
-
297
- // Vault
298
- { creator: string } // create
299
- { depositor: string, vault_creator: string, amount_sol: number } // deposit
300
- { authority: string, vault_creator: string, amount_sol: number } // withdraw
301
- { authority: string, vault_creator: string, wallet_to_link: string } // link
302
- { authority: string, vault_creator: string, wallet_to_unlink: string } // unlink
303
- { authority: string, vault_creator: string, new_authority: string } // transfer
304
-
305
- // Vault Swap (DEX trading for migrated tokens)
306
- { mint: string, signer: string, vault_creator: string, amount_in: number, minimum_amount_out: number, is_buy: boolean }
307
-
308
- // Lending (all support optional vault?: string for vault routing)
309
- { mint: string, borrower: string, collateral_amount: number, sol_to_borrow: number, vault?: string }
310
- { mint: string, borrower: string, sol_amount: number, vault?: string }
311
- { mint: string, liquidator: string, borrower: string, vault?: string }
312
-
313
- // Migrate (permissionless — anyone can trigger for bonding-complete tokens, treasury reimburses payer)
314
- { mint: string, payer: string }
315
-
316
- // Swap Fees to SOL (permissionless — bundles harvest + swap, treasury reimburses)
317
- { mint: string, payer: string, minimum_amount_out?: number, harvest?: boolean, sources?: string[] }
318
-
319
- // Rewards (optional vault routing)
320
- { user: string, vault?: string } // claim protocol rewards
321
- ```
140
+ | `verifySaid(wallet)` | Check verification status and trust tier |
141
+ | `confirmTransaction(connection, sig, wallet)` | Report tx for reputation tracking |
322
142
 
323
143
  ## Network Configuration
324
144
 
325
- The SDK detects the network at runtime. No rebuild needed to switch between mainnet and devnet.
326
-
327
145
  ```typescript
328
- // Browser: set before SDK calls (e.g., in a network switcher)
146
+ // Browser
329
147
  (globalThis as any).__TORCH_NETWORK__ = 'devnet'
330
148
 
331
- // Node.js: set via environment variable
149
+ // Node.js
332
150
  // TORCH_NETWORK=devnet npx tsx your-script.ts
333
151
  ```
334
152
 
335
- The SDK checks `globalThis.__TORCH_NETWORK__` first (for browser runtime switching), then falls back to `process.env.TORCH_NETWORK`. When set to `'devnet'`, all Raydium addresses automatically switch to devnet versions.
336
-
337
- ## Vault Safety Model
338
-
339
- The Torch Vault provides protocol-level full custody for AI agent interaction:
340
-
341
- | Property | Guarantee |
342
- |----------|-----------|
343
- | **Full custody** | Vault holds all SOL and all tokens. Controller wallet holds nothing. |
344
- | **Closed loop** | All operations return value to the vault. No leakage to controller. |
345
- | **Authority separation** | Creator (immutable PDA seed) vs Authority (transferable admin). Agent wallets get *usage* rights, not ownership. |
346
- | **One link per wallet** | A wallet can only belong to one vault. PDA uniqueness enforces this. |
347
- | **Permissionless deposits** | Anyone can top up any vault. Hardware wallet deposits, agent spends. |
348
- | **Instant revocation** | Authority can unlink a wallet at any time. |
349
- | **Authority-only withdrawals** | Only the vault authority can withdraw SOL or tokens. Controllers cannot extract value. |
350
-
351
- ## Running the E2E Test
352
-
353
- The test runs the full lifecycle against a [Surfpool](https://github.com/txtx/surfpool) mainnet fork.
153
+ ## Testing
354
154
 
355
155
  ```bash
356
- # Start a local Solana fork
156
+ # Mainnet fork (Surfpool)
357
157
  surfpool start --network mainnet --no-tui
358
-
359
- # Run the test
360
158
  npx tsx tests/test_e2e.ts
361
- ```
362
159
 
363
- Expected output: `RESULTS: 35 passed, 0 failed`
160
+ # Devnet
161
+ TORCH_NETWORK=devnet npx tsx tests/test_devnet_e2e.ts
162
+ ```
364
163
 
365
- Test coverage: create token, vault lifecycle (create/deposit/query/withdraw/withdraw tokens), buy (direct + vault), link/unlink wallet, sell, star, messages, confirm, full bonding to graduation (100/200 SOL tiers), permissionless Raydium migration (V26 two-step), harvest transfer fees (auto-discovery), swap fees to SOL (harvest + Raydium swap in one tx), borrow, repay, vault swap (buy + sell on Raydium DEX), vault-routed liquidation, protocol reward claims (epoch volume + vault-routed claim).
164
+ ## Links
366
165
 
367
- A separate devnet E2E test (`tests/test_devnet_e2e.ts`) validates the full lifecycle against Solana devnet with `TORCH_NETWORK=devnet`. A tiers test (`tests/test_tiers.ts`) validates the full lifecycle across graduation tiers (Flame/Torch) including harvest and lending.
166
+ - [torch.market](https://torch.market)
167
+ - [SDK source](https://github.com/mrsirg97-rgb/torchsdk)
168
+ - [npm](https://www.npmjs.com/package/torchsdk)
169
+ - [Design doc](./design.md)
170
+ - [SDK audit](./audit.md)
171
+ - Program ID: `8hbUkonssSEEtkqzwM7ZcZrD9evacM92TcWSooVF4BeT`
368
172
 
369
173
  ## License
370
174