@clawdvault/sdk 0.1.1 → 0.1.2
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 +284 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @clawdvault/sdk
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@clawdvault/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
3
6
|
TypeScript SDK for [ClawdVault](https://clawdvault.com) - a pump.fun-style token launchpad on Solana.
|
|
4
7
|
|
|
5
8
|
## Features
|
|
@@ -36,6 +39,12 @@ const quote = await client.getQuote({
|
|
|
36
39
|
type: 'buy',
|
|
37
40
|
amount: 0.1
|
|
38
41
|
});
|
|
42
|
+
|
|
43
|
+
// Get SOL/USD price
|
|
44
|
+
const { price } = await client.getSolPrice();
|
|
45
|
+
|
|
46
|
+
// Get top holders
|
|
47
|
+
const { holders } = await client.getHolders('TOKEN_MINT_ADDRESS');
|
|
39
48
|
```
|
|
40
49
|
|
|
41
50
|
### Write Operations (Wallet Required)
|
|
@@ -43,9 +52,12 @@ const quote = await client.getQuote({
|
|
|
43
52
|
```typescript
|
|
44
53
|
import { createClient, KeypairSigner } from '@clawdvault/sdk';
|
|
45
54
|
|
|
46
|
-
// Load wallet from file
|
|
55
|
+
// Load wallet from file
|
|
47
56
|
const signer = KeypairSigner.fromFile('/path/to/wallet.json');
|
|
48
|
-
//
|
|
57
|
+
// Or from environment variable
|
|
58
|
+
const signer = KeypairSigner.fromEnv('SOLANA_PRIVATE_KEY');
|
|
59
|
+
// Or from base58 string
|
|
60
|
+
const signer = new KeypairSigner('base58_private_key');
|
|
49
61
|
|
|
50
62
|
const client = createClient({ signer });
|
|
51
63
|
|
|
@@ -55,26 +67,64 @@ const result = await client.createToken({
|
|
|
55
67
|
symbol: 'MYTOK',
|
|
56
68
|
description: 'A cool token',
|
|
57
69
|
image: 'https://example.com/image.png',
|
|
58
|
-
initialBuy: 0.1 // Optional initial buy in SOL
|
|
70
|
+
initialBuy: 0.1, // Optional initial buy in SOL
|
|
71
|
+
twitter: 'https://twitter.com/mytoken',
|
|
72
|
+
website: 'https://mytoken.io'
|
|
59
73
|
});
|
|
60
74
|
|
|
75
|
+
console.log('Token created:', result.mint);
|
|
76
|
+
|
|
61
77
|
// Buy tokens with 0.1 SOL
|
|
62
78
|
const buyResult = await client.buy('TOKEN_MINT_ADDRESS', 0.1);
|
|
79
|
+
console.log('Bought tokens, tx:', buyResult.signature);
|
|
63
80
|
|
|
64
81
|
// Sell tokens
|
|
65
82
|
const sellResult = await client.sell('TOKEN_MINT_ADDRESS', 1000000); // 1M tokens
|
|
66
83
|
|
|
67
84
|
// Sell percentage of holdings
|
|
68
85
|
const sellPercentResult = await client.sellPercent('TOKEN_MINT_ADDRESS', 50);
|
|
86
|
+
|
|
87
|
+
// Check your balance
|
|
88
|
+
const { balance } = await client.getMyBalance('TOKEN_MINT_ADDRESS');
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Smart Trading (Auto-Routes for Graduated Tokens)
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// smartBuy automatically uses Jupiter for graduated tokens
|
|
95
|
+
const result = await client.smartBuy('TOKEN_MINT_ADDRESS', 0.5);
|
|
96
|
+
|
|
97
|
+
// Check if token uses Jupiter
|
|
98
|
+
const { graduated } = await client.getJupiterStatus('TOKEN_MINT_ADDRESS');
|
|
99
|
+
if (graduated) {
|
|
100
|
+
console.log('Token graduated - using Jupiter DEX');
|
|
101
|
+
}
|
|
69
102
|
```
|
|
70
103
|
|
|
71
104
|
## Configuration
|
|
72
105
|
|
|
73
106
|
```typescript
|
|
74
107
|
const client = createClient({
|
|
75
|
-
|
|
76
|
-
|
|
108
|
+
// Optional: custom API endpoint
|
|
109
|
+
baseUrl: 'https://clawdvault.com/api',
|
|
110
|
+
|
|
111
|
+
// Optional: wallet signer (can also use setSigner() later)
|
|
112
|
+
signer: mySigner,
|
|
113
|
+
|
|
114
|
+
// Optional: session token for authenticated endpoints
|
|
115
|
+
sessionToken: 'your-session-token',
|
|
116
|
+
|
|
117
|
+
// Optional: global error handler
|
|
118
|
+
onError: (error) => {
|
|
119
|
+
console.error('API Error:', error.message);
|
|
120
|
+
}
|
|
77
121
|
});
|
|
122
|
+
|
|
123
|
+
// Add signer later
|
|
124
|
+
client.setSigner(newSigner);
|
|
125
|
+
|
|
126
|
+
// Get connected wallet address
|
|
127
|
+
const address = client.getWalletAddress(); // returns string | null
|
|
78
128
|
```
|
|
79
129
|
|
|
80
130
|
## Browser Usage with Phantom Wallet
|
|
@@ -82,6 +132,7 @@ const client = createClient({
|
|
|
82
132
|
```typescript
|
|
83
133
|
import { createClient, PhantomSigner } from '@clawdvault/sdk';
|
|
84
134
|
|
|
135
|
+
// Connect to Phantom (will prompt user)
|
|
85
136
|
const phantomSigner = await PhantomSigner.fromWindow();
|
|
86
137
|
const client = createClient({ signer: phantomSigner });
|
|
87
138
|
|
|
@@ -91,7 +142,234 @@ const result = await client.buy('TOKEN_MINT_ADDRESS', 0.1);
|
|
|
91
142
|
|
|
92
143
|
## API Reference
|
|
93
144
|
|
|
94
|
-
|
|
145
|
+
### Token Operations
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
// List tokens with filters
|
|
149
|
+
const { tokens } = await client.listTokens({
|
|
150
|
+
sort: 'market_cap', // 'created_at' | 'market_cap' | 'volume' | 'price'
|
|
151
|
+
limit: 20,
|
|
152
|
+
page: 1,
|
|
153
|
+
graduated: false // filter by graduation status
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Get single token
|
|
157
|
+
const { token, trades } = await client.getToken('MINT_ADDRESS');
|
|
158
|
+
|
|
159
|
+
// Get Metaplex metadata
|
|
160
|
+
const metadata = await client.getMetadata('MINT_ADDRESS');
|
|
161
|
+
|
|
162
|
+
// Create new token
|
|
163
|
+
const result = await client.createToken({
|
|
164
|
+
name: 'Token Name',
|
|
165
|
+
symbol: 'SYMBOL',
|
|
166
|
+
description: 'Description',
|
|
167
|
+
image: 'https://...', // or upload first with uploadImage()
|
|
168
|
+
initialBuy: 0.1, // optional
|
|
169
|
+
twitter: 'https://twitter.com/...',
|
|
170
|
+
telegram: 'https://t.me/...',
|
|
171
|
+
website: 'https://...'
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Trading Operations
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// Get quote (no wallet required)
|
|
179
|
+
const quote = await client.getQuote({
|
|
180
|
+
mint: 'MINT_ADDRESS',
|
|
181
|
+
type: 'buy', // or 'sell'
|
|
182
|
+
amount: 0.1
|
|
183
|
+
});
|
|
184
|
+
console.log('Expected tokens:', quote.expectedAmount);
|
|
185
|
+
console.log('Price impact:', quote.priceImpact);
|
|
186
|
+
|
|
187
|
+
// Buy on bonding curve
|
|
188
|
+
const buyResult = await client.buy('MINT', 0.1, 0.01); // 1% slippage
|
|
189
|
+
|
|
190
|
+
// Sell on bonding curve
|
|
191
|
+
const sellResult = await client.sell('MINT', 1000000, 0.01);
|
|
192
|
+
|
|
193
|
+
// Sell percentage
|
|
194
|
+
const result = await client.sellPercent('MINT', 50, 0.01); // sell 50%
|
|
195
|
+
|
|
196
|
+
// Smart trading (auto-routes to Jupiter for graduated tokens)
|
|
197
|
+
const smartBuy = await client.smartBuy('MINT', 0.5, 0.01);
|
|
198
|
+
const smartSell = await client.smartSell('MINT', 1000000, 0.01);
|
|
199
|
+
|
|
200
|
+
// Jupiter-specific (for graduated tokens)
|
|
201
|
+
const jupBuy = await client.buyJupiter('MINT', 0.5, 50); // 50 bps = 0.5%
|
|
202
|
+
const jupSell = await client.sellJupiter('MINT', 1000000, 50);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Price & Market Data
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Trade history
|
|
209
|
+
const { trades } = await client.getTrades({
|
|
210
|
+
mint: 'MINT_ADDRESS',
|
|
211
|
+
limit: 50
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// OHLCV candles
|
|
215
|
+
const { candles } = await client.getCandles({
|
|
216
|
+
mint: 'MINT_ADDRESS',
|
|
217
|
+
interval: '1m', // '1m' | '5m' | '15m' | '1h' | '4h' | '1d'
|
|
218
|
+
limit: 100
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// On-chain stats
|
|
222
|
+
const stats = await client.getStats('MINT_ADDRESS');
|
|
223
|
+
|
|
224
|
+
// Top holders
|
|
225
|
+
const { holders } = await client.getHolders('MINT_ADDRESS');
|
|
226
|
+
|
|
227
|
+
// Token balance
|
|
228
|
+
const { balance } = await client.getBalance('WALLET_ADDRESS', 'MINT_ADDRESS');
|
|
229
|
+
const { balance: myBalance } = await client.getMyBalance('MINT_ADDRESS');
|
|
230
|
+
|
|
231
|
+
// SOL/USD price
|
|
232
|
+
const { price } = await client.getSolPrice();
|
|
233
|
+
|
|
234
|
+
// Graduation status
|
|
235
|
+
const status = await client.getGraduationStatus('MINT_ADDRESS');
|
|
236
|
+
const jupStatus = await client.getJupiterStatus('MINT_ADDRESS');
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Chat & Social
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
// Get chat messages
|
|
243
|
+
const { messages } = await client.getChat({
|
|
244
|
+
mint: 'MINT_ADDRESS',
|
|
245
|
+
limit: 50
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// Send message (requires auth)
|
|
249
|
+
await client.sendChat({
|
|
250
|
+
mint: 'MINT_ADDRESS',
|
|
251
|
+
content: 'Hello world!'
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Reactions
|
|
255
|
+
await client.addReaction('MESSAGE_ID', '🚀');
|
|
256
|
+
await client.removeReaction('MESSAGE_ID', '🚀');
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### User & Auth
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
// Get profile
|
|
263
|
+
const profile = await client.getProfile('WALLET_ADDRESS');
|
|
264
|
+
|
|
265
|
+
// Update profile
|
|
266
|
+
await client.updateProfile({
|
|
267
|
+
username: 'newname',
|
|
268
|
+
bio: 'New bio'
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// Session management
|
|
272
|
+
const { token } = await client.createSession();
|
|
273
|
+
client.setSessionToken(token);
|
|
274
|
+
const { valid } = await client.validateSession();
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### File Upload
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
// Upload from file path (Node.js)
|
|
281
|
+
const { url } = await client.uploadImageFromPath('./logo.png');
|
|
282
|
+
|
|
283
|
+
// Upload from Buffer/File
|
|
284
|
+
const { url } = await client.uploadImage(buffer, 'logo.png');
|
|
285
|
+
|
|
286
|
+
// Use in token creation
|
|
287
|
+
await client.createToken({
|
|
288
|
+
name: 'My Token',
|
|
289
|
+
symbol: 'MTK',
|
|
290
|
+
image: url // use uploaded URL
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Error Handling
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import { createClient, KeypairSigner } from '@clawdvault/sdk';
|
|
298
|
+
|
|
299
|
+
const client = createClient({
|
|
300
|
+
signer: KeypairSigner.fromEnv(),
|
|
301
|
+
onError: (error) => {
|
|
302
|
+
// Global error handler
|
|
303
|
+
console.error('API Error:', error.message);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// Try/catch for specific handling
|
|
308
|
+
try {
|
|
309
|
+
const result = await client.buy('MINT_ADDRESS', 0.1);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
// error.status - HTTP status code (404, 400, 500, etc.)
|
|
312
|
+
// error.response - parsed response body
|
|
313
|
+
// error.message - error message
|
|
314
|
+
|
|
315
|
+
if (error.status === 404) {
|
|
316
|
+
console.log('Token not found');
|
|
317
|
+
} else if (error.status === 400) {
|
|
318
|
+
console.log('Bad request:', error.response?.error);
|
|
319
|
+
} else if (error.message.includes('Signer required')) {
|
|
320
|
+
console.log('Wallet not connected');
|
|
321
|
+
} else if (error.message.includes('No tokens to sell')) {
|
|
322
|
+
console.log('Zero balance');
|
|
323
|
+
} else {
|
|
324
|
+
console.log('Unexpected error:', error.message);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## TypeScript Types
|
|
330
|
+
|
|
331
|
+
All types are exported for use in your application:
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
import type {
|
|
335
|
+
Token,
|
|
336
|
+
Trade,
|
|
337
|
+
QuoteResponse,
|
|
338
|
+
TokenListParams,
|
|
339
|
+
ExecuteTradeResponse,
|
|
340
|
+
// ... many more
|
|
341
|
+
} from '@clawdvault/sdk';
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Constants
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
import { PROGRAM_ID, DEFAULT_BASE_URL } from '@clawdvault/sdk';
|
|
348
|
+
|
|
349
|
+
console.log(PROGRAM_ID); // 'GUyF2TVe32Cid4iGVt2F6wPYDhLSVmTUZBj2974outYM'
|
|
350
|
+
console.log(DEFAULT_BASE_URL); // 'https://clawdvault.com/api'
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## Troubleshooting
|
|
354
|
+
|
|
355
|
+
### "Signer required" error
|
|
356
|
+
Write operations (buy, sell, createToken) need a wallet signer:
|
|
357
|
+
```typescript
|
|
358
|
+
const signer = KeypairSigner.fromFile('~/.config/solana/id.json');
|
|
359
|
+
const client = createClient({ signer });
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### "Phantom wallet not found"
|
|
363
|
+
- Install the Phantom browser extension
|
|
364
|
+
- Page must be served over HTTPS (or localhost)
|
|
365
|
+
|
|
366
|
+
### Transaction failures
|
|
367
|
+
- Increase slippage: `client.buy(mint, sol, 0.05)` (5%)
|
|
368
|
+
- Check SOL balance for fees
|
|
369
|
+
- Token price may have moved
|
|
370
|
+
|
|
371
|
+
### "No tokens to sell"
|
|
372
|
+
Call `getMyBalance()` to verify you have tokens before selling.
|
|
95
373
|
|
|
96
374
|
## License
|
|
97
375
|
|