pinpet-sdk 0.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 ADDED
@@ -0,0 +1,674 @@
1
+ # SpinPet SDK
2
+
3
+ A JavaScript SDK for interacting with SpinPet protocol-related Solana Anchor smart contracts. The SDK supports both Node.js and browser environments, providing modular functionality for trading, token management, order management, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install pinpet-sdk
9
+ ```
10
+
11
+ **NPM Package**: https://www.npmjs.com/package/pinpet-sdk
12
+
13
+ ## Table of Contents
14
+
15
+ 1. [SDK Initialization](#sdk-initialization)
16
+ 2. [Core Configuration](#core-configuration)
17
+ 3. [Trading Module - Trading Functions](#trading-module---trading-functions)
18
+ 4. [Fast Module - Data Retrieval](#fast-module---data-retrieval)
19
+ 5. [Token Module - Token Management](#token-module---token-management)
20
+ 6. [Param Module - Parameter Management](#param-module---parameter-management)
21
+ 7. [Simulator Module - Trading Simulation](#simulator-module---trading-simulation)
22
+ 8. [Chain Module - On-chain Data Queries](#chain-module---on-chain-data-queries)
23
+ 9. [Utility Methods](#utility-methods)
24
+ 10. [Unified Data Interface Documentation](#unified-data-interface-documentation)
25
+
26
+ ---
27
+
28
+ ## SDK Initialization
29
+
30
+ ### Constructor
31
+
32
+ ```javascript
33
+ new PinPetSdk(connection, programId, options)
34
+ ```
35
+
36
+ **Parameters:**
37
+ - `connection` *(Connection)*: Solana connection instance
38
+ - `programId` *(PublicKey|string)*: Program ID
39
+ - `options` *(Object)*: Optional configuration parameters
40
+
41
+ **options Configuration:**
42
+ ```javascript
43
+ {
44
+ fee_recipient: "4nffmKaNrex34LkJ99RLxMt2BbgXeopUi8kJnom3YWbv", // Fee recipient account
45
+ base_fee_recipient: "8fJpd2nteqkTEnXf4tG6d1MnP9p71KMCV4puc9vaq6kv", // Base fee recipient account
46
+ params_account: "DVRnPDW1MvUhRhDfE1kU6aGHoQoufBCmQNbqUH4WFgUd", // Parameters account
47
+ spin_fast_api_url: "http://192.168.18.36:8080", // FastAPI URL
48
+ defaultDataSource: "fast", // Default data source, "fast" or "chain"
49
+ commitment: "confirmed", // Commitment level
50
+ preflightCommitment: "processed", // Preflight commitment level
51
+ skipPreflight: false, // Whether to skip preflight
52
+ maxRetries: 3, // Maximum retry count
53
+ debug_log_path: null // Debug log path (optional)
54
+ }
55
+ ```
56
+
57
+ **Example:**
58
+ ```javascript
59
+ const { Connection, PublicKey } = require('@solana/web3.js');
60
+ const { PinPetSdk, getDefaultOptions, SPINPET_PROGRAM_ID } = require('pinpet-sdk');
61
+
62
+ // Create connection
63
+ const connection = new Connection('http://localhost:8899', 'confirmed');
64
+
65
+ // Get default configuration
66
+ const options = getDefaultOptions('LOCALNET');
67
+
68
+ // Initialize SDK (Note: wallet parameter is no longer required)
69
+ const sdk = new PinPetSdk(
70
+ connection,
71
+ SPINPET_PROGRAM_ID,
72
+ {
73
+ ...options, // Include network-specific configuration
74
+ defaultDataSource: 'fast' // 'fast' or 'chain'
75
+ }
76
+ );
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Core Configuration
82
+
83
+ ### Constant Configuration
84
+
85
+ - `sdk.MAX_ORDERS_COUNT`: 10 - Maximum orders processed per transaction
86
+ - `sdk.FIND_MAX_ORDERS_COUNT`: 1000 - Maximum orders fetched when querying
87
+ - `sdk.SUGGEST_LIQ_RATIO`: 975 - Suggested liquidity ratio when insufficient, in basis points (1000=100%)
88
+
89
+ ### Unified Data Interface
90
+
91
+ SDK provides `sdk.data` unified data interface that automatically routes to fast or chain modules based on `defaultDataSource` configuration:
92
+
93
+ ```javascript
94
+ // Get orders using default data source
95
+ const ordersData = await sdk.data.orders(mint, { type: 'down_orders' });
96
+
97
+ // Temporarily specify data source
98
+ const ordersData = await sdk.data.orders(mint, {
99
+ type: 'down_orders',
100
+ dataSource: 'chain' // Temporarily use chain data source
101
+ });
102
+
103
+ // Get price data
104
+ const price = await sdk.data.price(mint);
105
+
106
+ // Get user orders
107
+ const userOrders = await sdk.data.user_orders(user, mint, {
108
+ page: 1,
109
+ limit: 200,
110
+ order_by: 'start_time_desc'
111
+ });
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Trading Module - Trading Functions
117
+
118
+ ### sdk.trading.buy() - Buy Tokens
119
+
120
+ ```javascript
121
+ await sdk.trading.buy(params, options)
122
+ ```
123
+
124
+ **Parameters:**
125
+ - `params.mintAccount` *(string|PublicKey)*: Token mint account address
126
+ - `params.buyTokenAmount` *(anchor.BN)*: Amount of tokens to purchase
127
+ - `params.maxSolAmount` *(anchor.BN)*: Maximum SOL to spend
128
+ - `params.payer` *(PublicKey)*: Payer public key
129
+ - `options.computeUnits` *(number)*: Compute units limit, default 1400000
130
+
131
+ **Return Value:**
132
+ ```javascript
133
+ {
134
+ transaction: Transaction, // Transaction object
135
+ signers: [], // Signers array (empty array, only payer signature needed)
136
+ accounts: { // Related account information
137
+ mint: PublicKey,
138
+ curveAccount: PublicKey,
139
+ poolTokenAccount: PublicKey,
140
+ poolSolAccount: PublicKey,
141
+ userTokenAccount: PublicKey,
142
+ payer: PublicKey
143
+ },
144
+ orderData: { // Order data information
145
+ ordersUsed: number, // Number of orders used
146
+ lpPairsCount: number, // LP pairs count
147
+ lpPairs: Array, // LP pairs array
148
+ orderAccounts: Array // Order accounts array
149
+ }
150
+ }
151
+ ```
152
+
153
+ **Example:**
154
+ ```javascript
155
+ const result = await sdk.trading.buy({
156
+ mintAccount: "HZBos3RNhExDcAtzmdKXhTd4sVcQFBiT3FDBgmBBMk7",
157
+ buyTokenAmount: new anchor.BN("1000000000"), // 1 token (assuming 9 decimals)
158
+ maxSolAmount: new anchor.BN("2000000000"), // 2 SOL
159
+ payer: wallet.publicKey
160
+ });
161
+
162
+ // Sign and send transaction
163
+ const signature = await connection.sendTransaction(result.transaction, [wallet.payer]);
164
+ ```
165
+
166
+ ### sdk.trading.sell() - Sell Tokens
167
+
168
+ ```javascript
169
+ await sdk.trading.sell(params, options)
170
+ ```
171
+
172
+ **Parameters:**
173
+ - `params.mintAccount` *(string|PublicKey)*: Token mint account address
174
+ - `params.sellTokenAmount` *(anchor.BN)*: Amount of tokens to sell
175
+ - `params.minSolOutput` *(anchor.BN)*: Minimum SOL output
176
+ - `params.payer` *(PublicKey)*: Payer public key
177
+ - `options.computeUnits` *(number)*: Compute units limit, default 1400000
178
+
179
+ **Return Value:** Same as `buy()` method
180
+
181
+ ### sdk.trading.long() - Margin Long
182
+
183
+ ```javascript
184
+ await sdk.trading.long(params, options)
185
+ ```
186
+
187
+ **Parameters:**
188
+ - `params.mintAccount` *(string|PublicKey)*: Token mint account address
189
+ - `params.buyTokenAmount` *(anchor.BN)*: Amount of tokens to purchase
190
+ - `params.maxSolAmount` *(anchor.BN)*: Maximum SOL to spend
191
+ - `params.marginSol` *(anchor.BN)*: Margin amount
192
+ - `params.closePrice` *(anchor.BN)*: Close price
193
+ - `params.prevOrder` *(PublicKey|null)*: Previous order
194
+ - `params.nextOrder` *(PublicKey|null)*: Next order
195
+ - `params.payer` *(PublicKey)*: Payer public key
196
+ - `options.computeUnits` *(number)*: Compute units limit, default 1400000
197
+
198
+ ### sdk.trading.short() - Margin Short
199
+
200
+ ```javascript
201
+ await sdk.trading.short(params, options)
202
+ ```
203
+
204
+ ### sdk.trading.closeLong() - Close Long Position
205
+
206
+ ```javascript
207
+ await sdk.trading.closeLong(params, options)
208
+ ```
209
+
210
+ ### sdk.trading.closeShort() - Close Short Position
211
+
212
+ ```javascript
213
+ await sdk.trading.closeShort(params, options)
214
+ ```
215
+
216
+ ---
217
+
218
+ ## Fast Module - Data Retrieval
219
+
220
+ ### sdk.fast.mints() - Get Token List
221
+
222
+ ```javascript
223
+ await sdk.fast.mints(options)
224
+ ```
225
+
226
+ **Parameters:**
227
+ - `options.page` *(number)*: Page number, default 1
228
+ - `options.limit` *(number)*: Items per page, default 10
229
+ - `options.sort_by` *(string)*: Sort method, default 'slot_asc'
230
+
231
+ ### sdk.fast.mint_info() - Get Token Details
232
+
233
+ ```javascript
234
+ await sdk.fast.mint_info(mint)
235
+ ```
236
+
237
+ **Parameters:**
238
+ - `mint` *(string|Array)*: Token address or array of addresses
239
+
240
+ ### sdk.fast.orders() - Get Order Data
241
+
242
+ ```javascript
243
+ await sdk.fast.orders(mint, options)
244
+ ```
245
+
246
+ **Parameters:**
247
+ - `mint` *(string)*: Token address
248
+ - `options.type` *(string)*: Order type, "up_orders" (short) or "down_orders" (long)
249
+ - `options.page` *(number)*: Page number, default 1
250
+ - `options.limit` *(number)*: Items per page, default 500
251
+
252
+ ### sdk.fast.price() - Get Token Price
253
+
254
+ ```javascript
255
+ await sdk.fast.price(mint)
256
+ ```
257
+
258
+ **Parameters:**
259
+ - `mint` *(string)*: Token address
260
+
261
+ **Return Value:**
262
+ - `string`: Latest price string
263
+
264
+ ### sdk.fast.user_orders() - Get User Orders
265
+
266
+ ```javascript
267
+ await sdk.fast.user_orders(user, mint, options)
268
+ ```
269
+
270
+ **Parameters:**
271
+ - `user` *(string)*: User address
272
+ - `mint` *(string)*: Token address
273
+ - `options.page` *(number)*: Page number, default 1
274
+ - `options.limit` *(number)*: Items per page, default 200
275
+ - `options.order_by` *(string)*: Sort method, default 'start_time_desc'
276
+
277
+ ---
278
+
279
+ ## Token Module - Token Management
280
+
281
+ ### sdk.token.create() - Create New Token
282
+
283
+ ```javascript
284
+ await sdk.token.create(params)
285
+ ```
286
+
287
+ **Parameters:**
288
+ - `params.mint` *(Keypair)*: Token mint keypair
289
+ - `params.name` *(string)*: Token name
290
+ - `params.symbol` *(string)*: Token symbol
291
+ - `params.uri` *(string)*: Metadata URI
292
+ - `params.payer` *(PublicKey)*: Creator public key
293
+
294
+ ---
295
+
296
+ ## Param Module - Parameter Management
297
+
298
+ ### sdk.param.createParams() - Create Partner Parameters
299
+
300
+ ```javascript
301
+ await sdk.param.createParams(params)
302
+ ```
303
+
304
+ **Parameters:**
305
+ - `params.partner` *(PublicKey)*: Partner public key
306
+
307
+ ### sdk.param.getParams() - Get Partner Parameters
308
+
309
+ ```javascript
310
+ await sdk.param.getParams(partner)
311
+ ```
312
+
313
+ ### sdk.param.getAdmin() - Get Admin Account
314
+
315
+ ```javascript
316
+ await sdk.param.getAdmin()
317
+ ```
318
+
319
+ ---
320
+
321
+ ## Simulator Module - Trading Simulation
322
+
323
+ ### sdk.simulator.simulateTokenBuy() - Simulate Token Buy Transaction
324
+
325
+ This function simulates a token buy transaction for a specified token amount by analyzing existing short orders (up_orders) to calculate liquidity requirements, price impact, and feasibility analysis.
326
+
327
+ ```javascript
328
+ await sdk.simulator.simulateTokenBuy(mint, buyTokenAmount, passOrder)
329
+ ```
330
+
331
+ **Parameters:**
332
+ - `mint` *(string)*: Token mint account address
333
+ - `buyTokenAmount` *(bigint|string|number)*: Target purchase token amount (u64 format, precision 10^6)
334
+ - `passOrder` *(string|null)*: Optional skip order PDA address
335
+
336
+ **Return Value:**
337
+ ```javascript
338
+ {
339
+ // Complete liquidity calculation result
340
+ liqResult: {
341
+ free_lp_sol_amount_sum: bigint, // Total available free liquidity SOL amount
342
+ free_lp_token_amount_sum: bigint, // Total available free liquidity token amount
343
+ lock_lp_sol_amount_sum: bigint, // Total locked liquidity SOL amount
344
+ lock_lp_token_amount_sum: bigint, // Total locked liquidity token amount
345
+ has_infinite_lp: boolean, // Whether includes infinite liquidity
346
+ pass_order_id: number, // Skipped order index position in array
347
+ force_close_num: number, // Number of orders requiring force closure
348
+ ideal_lp_sol_amount: bigint, // Ideal SOL usage amount
349
+ real_lp_sol_amount: bigint // Actual SOL usage amount
350
+ },
351
+
352
+ // Transaction completion analysis
353
+ completion: string, // Purchase completion percentage
354
+
355
+ // Price slippage analysis
356
+ slippage: string, // Price slippage percentage
357
+
358
+ // Suggested trading parameters
359
+ suggestedTokenAmount: string, // Suggested token purchase amount
360
+ suggestedSolAmount: string // Suggested SOL amount needed
361
+ }
362
+ ```
363
+
364
+ ### sdk.simulator.simulateTokenSell() - Simulate Token Sell Transaction
365
+
366
+ This function simulates a token sell transaction for a specified token amount by analyzing existing long orders (down_orders).
367
+
368
+ ```javascript
369
+ await sdk.simulator.simulateTokenSell(mint, sellTokenAmount, passOrder)
370
+ ```
371
+
372
+ ### sdk.simulator.simulateLongStopLoss() - Simulate Long Stop Loss Analysis
373
+
374
+ This function simulates stop loss price calculation for long positions by analyzing existing order linked lists.
375
+
376
+ ```javascript
377
+ await sdk.simulator.simulateLongStopLoss(mint, buyTokenAmount, stopLossPrice, lastPrice, ordersData)
378
+ ```
379
+
380
+ ### sdk.simulator.simulateSellStopLoss() - Simulate Short Stop Loss Analysis
381
+
382
+ This function simulates stop loss price calculation for short positions by analyzing existing short order linked lists.
383
+
384
+ ```javascript
385
+ await sdk.simulator.simulateSellStopLoss(mint, sellTokenAmount, stopLossPrice, lastPrice, ordersData)
386
+ ```
387
+
388
+ ---
389
+
390
+ ## Chain Module - On-chain Data Queries
391
+
392
+ Chain module provides functionality to read account data directly from the Solana blockchain. When auxiliary servers are unavailable, this module can be used to obtain real-time on-chain data including liquidity pool status, account balances, etc.
393
+
394
+ ### sdk.chain.getCurveAccount() - Get Complete Liquidity Pool Data
395
+
396
+ This is the core method of the Chain module, used to get complete lending liquidity pool account data for a specified token.
397
+
398
+ ```javascript
399
+ await sdk.chain.getCurveAccount(mint)
400
+ ```
401
+
402
+ **Parameters:**
403
+ - `mint` *(string|PublicKey)*: Token mint account address
404
+
405
+ **Return Value:**
406
+ ```javascript
407
+ {
408
+ // Core Reserve Data
409
+ lpTokenReserve: bigint, // LP Token reserve amount
410
+ lpSolReserve: bigint, // LP SOL reserve amount
411
+ price: bigint, // Current token price
412
+ borrowTokenReserve: bigint, // Borrow Token reserve amount
413
+ borrowSolReserve: bigint, // Borrow SOL reserve amount
414
+
415
+ // Fee and Parameter Configuration
416
+ swapFee: number, // Swap fee rate in basis points
417
+ borrowFee: number, // Borrow fee rate in basis points
418
+ feeDiscountFlag: boolean, // Fee discount flag
419
+ feeSplit: number, // Fee split ratio
420
+ borrowDuration: number, // Borrow duration in seconds
421
+ bump: number, // curve_account PDA bump seed
422
+
423
+ // Account Addresses
424
+ baseFeeRecipient: string, // Base fee recipient address
425
+ feeRecipient: string, // Fee recipient address
426
+ mint: string, // Token mint account address
427
+ upHead: string|null, // Up orders linked list head
428
+ downHead: string|null, // Down orders linked list head
429
+ poolTokenAccount: string, // Pool token account address
430
+ poolSolAccount: string, // Pool SOL account address
431
+
432
+ // Balance Information
433
+ baseFeeRecipientBalance: number, // Base fee recipient SOL balance
434
+ feeRecipientBalance: number, // Fee recipient SOL balance
435
+ poolTokenBalance: bigint, // Pool token account token balance
436
+ poolSolBalance: number, // Pool SOL account SOL balance
437
+
438
+ // Metadata
439
+ _metadata: {
440
+ accountAddress: string, // curve_account complete address
441
+ mintAddress: string // Input token mint address
442
+ }
443
+ }
444
+ ```
445
+
446
+ ### sdk.chain.getCurveAccountBatch() - Batch Get Liquidity Pool Data
447
+
448
+ ```javascript
449
+ await sdk.chain.getCurveAccountBatch(mints)
450
+ ```
451
+
452
+ ### sdk.chain.getCurveAccountAddress() - Calculate Liquidity Pool Address
453
+
454
+ ```javascript
455
+ sdk.chain.getCurveAccountAddress(mint)
456
+ ```
457
+
458
+ ---
459
+
460
+ ## Utility Methods
461
+
462
+ ### SDK Built-in Utility Methods
463
+
464
+ SDK provides convenient utility methods that can be called directly through SDK instance:
465
+
466
+ #### sdk.buildLpPairs() - Build LP Pairs Array
467
+
468
+ ```javascript
469
+ sdk.buildLpPairs(orders, direction, price)
470
+ ```
471
+
472
+ #### sdk.buildOrderAccounts() - Build Order Accounts Array
473
+
474
+ ```javascript
475
+ sdk.buildOrderAccounts(orders)
476
+ ```
477
+
478
+ #### sdk.findPrevNext() - Find Previous and Next Order Nodes
479
+
480
+ ```javascript
481
+ sdk.findPrevNext(orders, findOrderPda)
482
+ ```
483
+
484
+ #### sdk.findOrderIndex() - Get Order Position in Array
485
+
486
+ ```javascript
487
+ sdk.findOrderIndex(orders, targetOrderPda)
488
+ ```
489
+
490
+ ### Network Configuration
491
+
492
+ ```javascript
493
+ const { getDefaultOptions } = require('pinpet-sdk');
494
+
495
+ // Get default configuration
496
+ const options = getDefaultOptions('MAINNET'); // 'MAINNET' | 'TESTNET' | 'LOCALNET'
497
+ ```
498
+
499
+ **Available Networks:**
500
+ - `MAINNET`: Mainnet configuration
501
+ - `TESTNET`: Testnet configuration
502
+ - `LOCALNET`: Local network configuration
503
+
504
+ ---
505
+
506
+ ## Unified Data Interface Documentation
507
+
508
+ ### Data Source Configuration
509
+
510
+ SDK supports two data sources:
511
+
512
+ 1. **fast** - API data source (default): Fast data retrieval through FastAPI server, fast but requires API service dependency
513
+ 2. **chain** - On-chain data source: Direct blockchain data reading, more reliable but may have delays
514
+
515
+ ### Configuration Methods
516
+
517
+ ```javascript
518
+ // Global configuration of default data source
519
+ const sdk = new PinPetSdk(connection, programId, {
520
+ ...options,
521
+ defaultDataSource: 'fast' // or 'chain'
522
+ });
523
+
524
+ // Use default data source
525
+ const ordersData = await sdk.data.orders(mint, { type: 'down_orders' });
526
+
527
+ // Temporarily specify data source
528
+ const ordersData = await sdk.data.orders(mint, {
529
+ type: 'down_orders',
530
+ dataSource: 'chain' // Temporarily use chain data source
531
+ });
532
+ ```
533
+
534
+ ### Core Unified Interfaces
535
+
536
+ #### sdk.data.orders() - Get Order Data (Unified Interface)
537
+
538
+ ```javascript
539
+ await sdk.data.orders(mint, options)
540
+ ```
541
+
542
+ **Parameters:**
543
+ - `mint` *(string)*: Token mint account address
544
+ - `options` *(Object)*: Query options
545
+
546
+ **options Parameters:**
547
+ ```javascript
548
+ {
549
+ type: "down_orders" | "up_orders", // Required: Order type
550
+ // "down_orders" = Long orders (buy low)
551
+ // "up_orders" = Short orders (sell high)
552
+
553
+ page: number, // Optional: Page number, default 1
554
+ limit: number, // Optional: Items per page, default 500
555
+ dataSource: "fast" | "chain" // Optional: Temporarily specify data source
556
+ }
557
+ ```
558
+
559
+ #### sdk.data.price() - Get Price Data (Unified Interface)
560
+
561
+ ```javascript
562
+ await sdk.data.price(mint, options)
563
+ ```
564
+
565
+ **Parameters:**
566
+ - `mint` *(string)*: Token mint account address
567
+ - `options` *(Object, optional)*: Query options
568
+
569
+ **Return Value:**
570
+ - **Type**: `string`
571
+ - **Format**: u128 price string
572
+ - **Example**: `"13514066072452801812769"`
573
+
574
+ #### sdk.data.user_orders() - Get User Orders (Unified Interface)
575
+
576
+ ```javascript
577
+ await sdk.data.user_orders(user, mint, options)
578
+ ```
579
+
580
+ **Parameters:**
581
+ - `user` *(string)*: User wallet address
582
+ - `mint` *(string)*: Token mint account address
583
+ - `options` *(Object, optional)*: Query options
584
+
585
+ ---
586
+
587
+ ## Complete Usage Example
588
+
589
+ ```javascript
590
+ const { Connection, PublicKey } = require('@solana/web3.js');
591
+ const anchor = require('@coral-xyz/anchor');
592
+ const { PinPetSdk, getDefaultOptions, SPINPET_PROGRAM_ID } = require('pinpet-sdk');
593
+
594
+ async function example() {
595
+ // 1. Create connection
596
+ const connection = new Connection('http://localhost:8899', 'confirmed');
597
+
598
+ // 2. Get default configuration
599
+ const options = getDefaultOptions('LOCALNET');
600
+
601
+ // 3. Initialize SDK (Note: wallet parameter removed)
602
+ const sdk = new PinPetSdk(connection, SPINPET_PROGRAM_ID, {
603
+ ...options,
604
+ defaultDataSource: 'fast'
605
+ });
606
+
607
+ // 4. Use various features
608
+
609
+ // Get token list
610
+ const mints = await sdk.fast.mints();
611
+ console.log('Token list:', mints.data.mints);
612
+
613
+ // Get token details
614
+ const mintInfo = await sdk.fast.mint_info(mints.data.mints[0]);
615
+ console.log('Token details:', mintInfo.data.details[0]);
616
+
617
+ // Use unified data interface to get orders and price
618
+ const ordersData = await sdk.data.orders(mints.data.mints[0], { type: 'down_orders' });
619
+ const price = await sdk.data.price(mints.data.mints[0]);
620
+
621
+ // Simulate buy
622
+ const buyAnalysis = await sdk.simulator.simulateTokenBuy(
623
+ mints.data.mints[0],
624
+ '1000000000' // 1 token
625
+ );
626
+ console.log('Buy analysis:', buyAnalysis);
627
+
628
+ // Execute buy transaction (needs to provide payer parameter)
629
+ const buyResult = await sdk.trading.buy({
630
+ mintAccount: mints.data.mints[0],
631
+ buyTokenAmount: new anchor.BN("1000000000"),
632
+ maxSolAmount: new anchor.BN("2000000000"),
633
+ payer: yourWalletPublicKey // Need to provide payer public key
634
+ });
635
+
636
+ // Sign and send transaction (needs external wallet signature)
637
+ const signature = await connection.sendTransaction(buyResult.transaction, [yourWalletKeypair]);
638
+ console.log('Transaction signature:', signature);
639
+ }
640
+ ```
641
+
642
+ ---
643
+
644
+ ## Important Notes
645
+
646
+ 1. **SDK Initialization**: Starting from the new version, the SDK constructor no longer requires the `wallet` parameter. The `payer` parameter needs to be provided in each method during transactions.
647
+
648
+ 2. **Numerical Precision**: All amount-related parameters need to use `anchor.BN` type. Note that SOL precision is 10^9, token precision is usually 10^6 or 10^9.
649
+
650
+ 3. **Transaction Signing**: The `transaction` object returned by SDK needs to be signed and sent by users themselves. SDK does not automatically execute transactions. Supports various wallet adapters.
651
+
652
+ 4. **Data Source Selection**: Global data source can be configured through `defaultDataSource`, or temporarily specified through `dataSource` parameter in specific methods.
653
+
654
+ 5. **Order Queries**: Before executing close operations, order data needs to be obtained first through `sdk.data.orders()` or corresponding modules, and processed using utility methods.
655
+
656
+ 6. **Network Configuration**: Different network environments require corresponding configuration parameters. It's recommended to use `getDefaultOptions()` to get them.
657
+
658
+ 7. **Error Handling**: All async methods may throw exceptions. It's recommended to use try-catch for error handling.
659
+
660
+ 8. **Debug Features**: Debug logging can be enabled through `debug_log_path` configuration for easier problem tracking during development.
661
+
662
+ ---
663
+
664
+ ## License
665
+
666
+ MIT
667
+
668
+ ## Contributing
669
+
670
+ Please refer to the contributing guidelines in the repository.
671
+
672
+ ## Support
673
+
674
+ For issues and questions, please visit the [GitHub repository](https://github.com/your-repo/pinpet-sdk).