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/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/program.d.ts +19 -0
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +11 -1
- package/dist/program.js.map +1 -1
- package/dist/tokens.d.ts +21 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +84 -1
- package/dist/tokens.js.map +1 -1
- package/dist/torch_market.json +2882 -416
- package/dist/transactions.d.ts +77 -4
- package/dist/transactions.d.ts.map +1 -1
- package/dist/transactions.js +253 -21
- package/dist/transactions.js.map +1 -1
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -3
- package/readme.md +202 -63
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "torchsdk",
|
|
3
|
-
"version": "
|
|
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
|
|
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,
|
|
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
|
-
##
|
|
7
|
+
## Design
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
pnpm add torchsdk
|
|
11
|
-
```
|
|
9
|
+
for in depth sdk design, refer to [design.md](./design.md).
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## Audit
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
for sdk audit, refer to [audit.md](./audit.md).
|
|
16
14
|
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
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
|
|
70
|
-
| `getSellQuote(connection, mint, tokenAmount)` | Simulate a sell
|
|
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
|
|
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
|
|
81
|
-
| `buildStarTransaction(connection, params)` | Star a token (
|
|
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
|
|
84
|
-
| `buildLiquidateTransaction(connection, params)` | Liquidate
|
|
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
|
|
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
|
-
{
|
|
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
|
-
{
|
|
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
|
-
//
|
|
112
|
-
{
|
|
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
|
-
//
|
|
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
|
|
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:
|
|
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
|
|