torchsdk 1.0.7 → 2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "torchsdk",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
4
  "description": "Torch Market SDK — AI agent toolkit for Solana fair-launch tokens",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,8 +12,7 @@
12
12
  "clean": "rm -rf dist",
13
13
  "prepublishOnly": "npm run clean && npm run build",
14
14
  "deploy:ipfs": "npm run build && ipfs add -r dist",
15
- "format": "prettier --write src/",
16
- "format:test": "prettier --write tests/"
15
+ "format": "prettier --write src/ tests/"
17
16
  },
18
17
  "dependencies": {
19
18
  "@coral-xyz/anchor": "^0.32.1",
package/readme.md CHANGED
@@ -1,54 +1,40 @@
1
1
  # Torch SDK
2
2
 
3
- TypeScript SDK for building on [Torch Market](https://torch.market) — the fair-launch DAO launchpad on Solana.
3
+ TypeScript SDK for [Torch Market](https://torch.market) — the fair-launch token protocol on Solana.
4
4
 
5
- Read on-chain state, build transactions, and interact with bonding curves, community treasuries, governance, lending, and the SAID Protocol — all directly via Solana RPC. No API middleman.
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.
6
6
 
7
- ## Install
7
+ ## Design
8
8
 
9
- ```bash
10
- pnpm add torchsdk
11
- ```
9
+ for in depth sdk design, refer to [design.md](./design.md).
12
10
 
13
- Peer dependency: `@solana/web3.js ^1.98.0`
11
+ ## Audit
14
12
 
15
- ## Quick Start
13
+ for sdk audit, refer to [audit.md](./audit.md).
16
14
 
17
- ```typescript
18
- import { Connection } from "@solana/web3.js";
19
- import {
20
- getTokens,
21
- getToken,
22
- buildBuyTransaction,
23
- buildSellTransaction,
24
- confirmTransaction,
25
- } from "torchsdk";
15
+ ## What's New in v2.0.0
26
16
 
27
- const connection = new Connection("https://api.mainnet-beta.solana.com");
28
-
29
- // List tokens on bonding curves
30
- const { tokens } = await getTokens(connection, { status: "bonding", sort: "volume" });
17
+ **Torch Vault** an on-chain SOL escrow for safe AI agent interaction.
31
18
 
32
- // Get full token details
33
- const token = await getToken(connection, "So11111111111111111111111111111111111111112");
19
+ The vault is a spending cap. You deposit SOL, link an agent wallet, and the agent buys tokens using the vault's funds. The agent can't withdraw, can't transfer SOL arbitrarily — it can only spend through the `buy` instruction. You (the authority) retain full control: withdraw anytime, unlink wallets, transfer authority.
34
20
 
35
- // Buy tokens on a bonding curve (with optional on-chain message)
36
- const { transaction, message } = await buildBuyTransaction(connection, {
37
- mint: "TOKEN_MINT_ADDRESS",
38
- buyer: "YOUR_WALLET_ADDRESS",
39
- amount_sol: 100_000_000, // 0.1 SOL (in lamports)
40
- slippage_bps: 500, // 5% slippage
41
- vote: "burn", // vote to burn treasury tokens on migration
42
- message: "gm", // optional bundled as SPL Memo in the same tx
43
- });
44
-
45
- // Sign and send the transaction with your wallet...
46
-
47
- // Confirm for SAID Protocol reputation
48
- const result = await confirmTransaction(connection, signature, walletAddress);
49
- // result.event_type: "trade_complete" | "token_launch" | "governance_vote"
21
+ ```
22
+ User (hardware wallet)
23
+ ├── createVault() → vault created, user auto-linked
24
+ ├── depositVault(5 SOL) → vault funded
25
+ ├── linkWallet(agent) → agent can use vault for buys
26
+
27
+ Agent (hot wallet, ~0.01 SOL for fees)
28
+ ├── buy(vault=user) → vault pays, agent receives tokens
29
+ ├── sell() → agent sells tokens, keeps SOL
30
+
31
+ User
32
+ ├── withdrawVault() → pull remaining SOL
33
+ └── unlinkWallet(agent) → revoke agent access
50
34
  ```
51
35
 
36
+ Multiple wallets can share one vault. Deposit from a hardware wallet, trade from a hot wallet and an agent — all backed by the same SOL pool.
37
+
52
38
  ## API Reference
53
39
 
54
40
  ### Token Data
@@ -56,82 +42,235 @@ const result = await confirmTransaction(connection, signature, walletAddress);
56
42
  | Function | Description |
57
43
  |----------|-------------|
58
44
  | `getTokens(connection, params?)` | List tokens with filtering and sorting |
59
- | `getToken(connection, mint)` | Get full token details |
60
- | `getHolders(connection, mint)` | Get token holder list |
61
- | `getMessages(connection, mint, limit?)` | Get trade-bundled messages for a token |
45
+ | `getToken(connection, mint)` | Get full token details (metadata, treasury, votes, stars) |
46
+ | `getHolders(connection, mint)` | Get token holder list (excludes pools/vaults) |
47
+ | `getMessages(connection, mint, limit?)` | Get trade-bundled memos for a token |
62
48
  | `getLendingInfo(connection, mint)` | Get lending parameters for a migrated token |
63
49
  | `getLoanPosition(connection, mint, wallet)` | Get a wallet's loan position |
64
50
 
51
+ ### Vault Queries
52
+
53
+ | Function | Description |
54
+ |----------|-------------|
55
+ | `getVault(connection, creator)` | Get vault state by creator pubkey |
56
+ | `getVaultForWallet(connection, wallet)` | Find vault by any linked wallet (reverse lookup) |
57
+ | `getVaultWalletLink(connection, wallet)` | Get link state (which vault, when linked) |
58
+
65
59
  ### Quotes
66
60
 
67
61
  | Function | Description |
68
62
  |----------|-------------|
69
- | `getBuyQuote(connection, mint, solAmount)` | Simulate a buy and get expected output |
70
- | `getSellQuote(connection, mint, tokenAmount)` | Simulate a sell and get expected output |
63
+ | `getBuyQuote(connection, mint, solAmount)` | Simulate a buy expected tokens, fees, price impact |
64
+ | `getSellQuote(connection, mint, tokenAmount)` | Simulate a sell expected SOL, price impact |
71
65
 
72
66
  ### Transaction Builders
73
67
 
74
68
  All builders return `{ transaction: Transaction, message: string }`. You sign and send.
75
69
 
70
+ #### Trading
71
+
76
72
  | Function | Description |
77
73
  |----------|-------------|
78
- | `buildBuyTransaction(connection, params)` | Buy tokens on the bonding curve |
74
+ | `buildBuyTransaction(connection, params)` | Buy tokens (vault-funded, requires vault) |
75
+ | `buildDirectBuyTransaction(connection, params)` | Buy tokens (buyer pays directly, no vault) |
79
76
  | `buildSellTransaction(connection, params)` | Sell tokens back to the bonding curve |
80
- | `buildCreateTokenTransaction(connection, params)` | Launch a new token with bonding curve + treasury |
81
- | `buildStarTransaction(connection, params)` | Star a token (sybil-resistant support signal) |
77
+ | `buildCreateTokenTransaction(connection, params)` | Launch a new token |
78
+ | `buildStarTransaction(connection, params)` | Star a token (0.05 SOL) |
79
+
80
+ #### Vault Management
81
+
82
+ | Function | Signer | Description |
83
+ |----------|--------|-------------|
84
+ | `buildCreateVaultTransaction` | creator | Create vault + auto-link creator |
85
+ | `buildDepositVaultTransaction` | depositor | Deposit SOL (permissionless) |
86
+ | `buildWithdrawVaultTransaction` | authority | Withdraw SOL |
87
+ | `buildLinkWalletTransaction` | authority | Link a wallet to the vault |
88
+ | `buildUnlinkWalletTransaction` | authority | Unlink a wallet |
89
+ | `buildTransferAuthorityTransaction` | authority | Transfer admin control |
90
+
91
+ #### Lending (Post-Migration)
92
+
93
+ | Function | Description |
94
+ |----------|-------------|
82
95
  | `buildBorrowTransaction(connection, params)` | Borrow SOL against token collateral |
83
- | `buildRepayTransaction(connection, params)` | Repay a loan |
84
- | `buildLiquidateTransaction(connection, params)` | Liquidate an underwater position |
96
+ | `buildRepayTransaction(connection, params)` | Repay SOL debt |
97
+ | `buildLiquidateTransaction(connection, params)` | Liquidate underwater position |
85
98
 
86
99
  ### SAID Protocol
87
100
 
88
101
  | Function | Description |
89
102
  |----------|-------------|
90
103
  | `verifySaid(wallet)` | Check SAID verification status and trust tier |
91
- | `confirmTransaction(connection, signature, wallet)` | Confirm a tx on-chain for reputation tracking |
104
+ | `confirmTransaction(connection, signature, wallet)` | Confirm tx on-chain for reputation tracking |
105
+
106
+ ## Install
107
+
108
+ ```bash
109
+ pnpm add torchsdk
110
+ ```
111
+
112
+ Peer dependency: `@solana/web3.js ^1.98.0`
113
+
114
+ ## Quick Start
115
+
116
+ ```typescript
117
+ import { Connection } from "@solana/web3.js";
118
+ import {
119
+ getTokens,
120
+ getToken,
121
+ buildBuyTransaction,
122
+ buildDirectBuyTransaction,
123
+ buildSellTransaction,
124
+ buildCreateVaultTransaction,
125
+ buildDepositVaultTransaction,
126
+ buildLinkWalletTransaction,
127
+ getVault,
128
+ confirmTransaction,
129
+ } from "torchsdk";
130
+
131
+ const connection = new Connection("https://api.mainnet-beta.solana.com");
132
+ ```
133
+
134
+ ### Set Up a Vault
135
+
136
+ ```typescript
137
+ // 1. Create vault (user wallet)
138
+ const { transaction: createTx } = await buildCreateVaultTransaction(connection, {
139
+ creator: userWallet,
140
+ });
141
+ // sign and send createTx...
142
+
143
+ // 2. Deposit SOL
144
+ const { transaction: depositTx } = await buildDepositVaultTransaction(connection, {
145
+ depositor: userWallet,
146
+ vault_creator: userWallet,
147
+ amount_sol: 5_000_000_000, // 5 SOL
148
+ });
149
+ // sign and send depositTx...
150
+
151
+ // 3. Link an agent wallet
152
+ const { transaction: linkTx } = await buildLinkWalletTransaction(connection, {
153
+ authority: userWallet,
154
+ vault_creator: userWallet,
155
+ wallet_to_link: agentWallet,
156
+ });
157
+ // sign and send linkTx...
158
+ ```
159
+
160
+ ### Trade with Vault
161
+
162
+ ```typescript
163
+ // Agent buys tokens — vault pays
164
+ const { transaction, message } = await buildBuyTransaction(connection, {
165
+ mint: "TOKEN_MINT_ADDRESS",
166
+ buyer: agentWallet,
167
+ amount_sol: 100_000_000, // 0.1 SOL (in lamports)
168
+ slippage_bps: 500, // 5% slippage
169
+ vote: "burn", // governance vote on first buy
170
+ vault: userWallet, // vault creator key → vault pays
171
+ });
172
+ // agent signs and sends...
173
+
174
+ // Check vault balance
175
+ const vault = await getVault(connection, userWallet);
176
+ console.log(`Vault: ${vault.sol_balance} SOL, ${vault.linked_wallets} wallets`);
177
+ ```
178
+
179
+ ### Direct Buy (No Vault — Human Use Only)
180
+
181
+ ```typescript
182
+ // Buyer pays directly from their wallet — no vault safety
183
+ const { transaction } = await buildDirectBuyTransaction(connection, {
184
+ mint: "TOKEN_MINT_ADDRESS",
185
+ buyer: walletAddress,
186
+ amount_sol: 100_000_000,
187
+ slippage_bps: 500,
188
+ vote: "burn",
189
+ });
190
+ ```
92
191
 
93
192
  ## Transaction Params
94
193
 
95
194
  ```typescript
96
- // Buy
97
- { mint: string, buyer: string, amount_sol: number, slippage_bps?: number, vote?: "burn" | "return", message?: string }
195
+ // Buy (vault-funded — recommended for agents)
196
+ {
197
+ mint: string,
198
+ buyer: string,
199
+ amount_sol: number, // lamports
200
+ slippage_bps?: number, // default 100 (1%)
201
+ vote?: "burn" | "return", // required on first buy
202
+ message?: string, // optional SPL Memo (max 500 chars)
203
+ vault: string, // vault creator pubkey (required)
204
+ }
205
+
206
+ // Direct Buy (no vault — human use only)
207
+ {
208
+ mint: string,
209
+ buyer: string,
210
+ amount_sol: number, // lamports
211
+ slippage_bps?: number, // default 100 (1%)
212
+ vote?: "burn" | "return", // required on first buy
213
+ message?: string, // optional SPL Memo (max 500 chars)
214
+ }
98
215
 
99
216
  // Sell
100
- { mint: string, seller: string, amount_tokens: number, slippage_bps?: number, message?: string }
217
+ {
218
+ mint: string,
219
+ seller: string,
220
+ amount_tokens: number, // raw units (with decimals)
221
+ slippage_bps?: number,
222
+ message?: string,
223
+ }
101
224
 
102
225
  // Create Token
103
226
  { creator: string, name: string, symbol: string, metadata_uri: string }
104
227
 
105
- // Vote
106
- { mint: string, voter: string, vote: "burn" | "return" }
107
-
108
228
  // Star
109
229
  { mint: string, user: string }
110
230
 
111
- // Borrow
112
- { mint: string, borrower: string, collateral_amount: number, sol_to_borrow: number }
231
+ // Vault
232
+ { creator: string } // create
233
+ { depositor: string, vault_creator: string, amount_sol: number } // deposit
234
+ { authority: string, vault_creator: string, amount_sol: number } // withdraw
235
+ { authority: string, vault_creator: string, wallet_to_link: string } // link
236
+ { authority: string, vault_creator: string, wallet_to_unlink: string } // unlink
237
+ { authority: string, vault_creator: string, new_authority: string } // transfer
113
238
 
114
- // Repay
239
+ // Lending
240
+ { mint: string, borrower: string, collateral_amount: number, sol_to_borrow: number }
115
241
  { mint: string, borrower: string, sol_amount: number }
116
-
117
- // Liquidate
118
242
  { mint: string, liquidator: string, borrower: string }
119
243
  ```
120
244
 
245
+ ## Vault Safety Model
246
+
247
+ The Torch Vault provides protocol-level safety for AI agent interaction:
248
+
249
+ | Property | Guarantee |
250
+ |----------|-----------|
251
+ | **Spending cap** | Vault balance is finite. Agent can't spend more than what's deposited. |
252
+ | **Buy-only** | Vault SOL can only flow through the `buy` instruction. No arbitrary transfers. |
253
+ | **Authority separation** | Creator (immutable PDA seed) vs Authority (transferable admin). Agent wallets get *usage* rights, not ownership. |
254
+ | **One link per wallet** | A wallet can only belong to one vault. PDA uniqueness enforces this. |
255
+ | **Permissionless deposits** | Anyone can top up any vault. Hardware wallet deposits, agent spends. |
256
+ | **Instant revocation** | Authority can unlink a wallet at any time. |
257
+ | **Token custody** | Tokens go to the buyer's wallet, not the vault. The agent holds its own tokens. |
258
+
121
259
  ## Running the E2E Test
122
260
 
123
- The test runs the full lifecycle against a [Surfpool](https://github.com/txtx/surfpool) mainnet fork: create, buy, sell, star, message, confirm, bond to completion, migrate to Raydium, borrow, and repay.
261
+ The test runs the full lifecycle against a [Surfpool](https://github.com/txtx/surfpool) mainnet fork.
124
262
 
125
263
  ```bash
126
264
  # Start a local Solana fork
127
265
  surfpool start --network mainnet --no-tui
128
266
 
129
267
  # Run the test
130
- cd packages/sdk
131
268
  npx tsx tests/test_e2e.ts
132
269
  ```
133
270
 
134
- Expected output: `RESULTS: 13 passed, 0 failed`
271
+ Expected output: `RESULTS: 22 passed, 0 failed`
272
+
273
+ Test coverage: create token, vault lifecycle (create/deposit/query/withdraw), buy (direct + vault), link/unlink wallet, sell, star, messages, confirm, full bonding to 200 SOL, Raydium migration, borrow, repay.
135
274
 
136
275
  ## License
137
276