pinpet-sdk 2.1.34 → 2.2.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/src/index.js CHANGED
@@ -6,7 +6,8 @@
6
6
 
7
7
  // Import main SDK class
8
8
  const PinPetSdk = require('./sdk');
9
- const spinpetIdl = require('./idl/pinpet.json');
9
+ const idlLocalnet = require('./idl/pinpet_localnet.json');
10
+ const idlMain = require('./idl/pinpet_main.json');
10
11
  const { PublicKey } = require('@solana/web3.js');
11
12
 
12
13
  // Import modules (optional, users can also access directly via sdk.trading)
@@ -20,8 +21,13 @@ const { getDefaultOptions } = require('./utils/constants');
20
21
  const OrderUtils = require('./utils/orderUtils');
21
22
  const CurveAMM = require('./utils/curve_amm');
22
23
 
23
- // Import constants (if needed)
24
- const SPINPET_PROGRAM_ID = new PublicKey(spinpetIdl.address); // Replace with actual program ID
24
+ // Program ID constants
25
+ const SPINPET_PROGRAM_ID = new PublicKey(idlMain.address);
26
+
27
+ function getProgramId(network) {
28
+ if (network === 'localnet') return new PublicKey(idlLocalnet.address);
29
+ return new PublicKey(idlMain.address);
30
+ }
25
31
 
26
32
  // Main exports
27
33
  module.exports = {
@@ -30,6 +36,7 @@ module.exports = {
30
36
 
31
37
  // Constants
32
38
  SPINPET_PROGRAM_ID,
39
+ getProgramId,
33
40
 
34
41
  // Configuration utilities
35
42
  getDefaultOptions,
package/src/sdk.js CHANGED
@@ -20,7 +20,13 @@ const ChainModule = require('./modules/chain');
20
20
  const ToolsModule = require('./modules/tools');
21
21
  const OrderUtils = require('./utils/orderUtils');
22
22
  const CurveAMM = require('./utils/curve_amm');
23
- const spinpetIdl = require('./idl/pinpet.json');
23
+ const idlLocalnet = require('./idl/pinpet_localnet.json');
24
+ const idlMain = require('./idl/pinpet_main.json');
25
+
26
+ function getIdlByNetwork(network) {
27
+ if (network === 'localnet') return idlLocalnet;
28
+ return idlMain;
29
+ }
24
30
 
25
31
  /**
26
32
  * SpinPet SDK Main Class
@@ -54,7 +60,8 @@ class PinPetSdk {
54
60
  this.connection = connection;
55
61
  //this.wallet = wallet instanceof anchor.Wallet ? wallet : new anchor.Wallet(wallet);
56
62
  this.programId = typeof programId === 'string' ? new PublicKey(programId) : programId;
57
-
63
+ this.idl = getIdlByNetwork(options.network);
64
+
58
65
  // Initialize account configuration with options
59
66
  this.feeRecipient = this._parsePublicKey(this.options.feeRecipient);
60
67
  this.baseFeeRecipient = this._parsePublicKey(this.options.baseFeeRecipient);
@@ -162,8 +169,7 @@ class PinPetSdk {
162
169
 
163
170
  anchor.setProvider(provider);
164
171
 
165
- // Create program instance using imported IDL
166
- return new anchor.Program(spinpetIdl, this.programId);
172
+ return new anchor.Program(this.idl, this.programId);
167
173
  }
168
174
 
169
175
  // ========== Unified Data Interface Routing Method ==========
@@ -5,8 +5,12 @@ import { BN, Wallet, Program } from '@coral-xyz/anchor';
5
5
 
6
6
  export type DataSourceType = 'fast' | 'chain';
7
7
 
8
+ export type NetworkType = 'mainnet' | 'localnet';
9
+
8
10
  export interface NetworkConfig {
9
11
  name: string;
12
+ network: NetworkType;
13
+ programId: string;
10
14
  defaultDataSource: DataSourceType;
11
15
  solanaEndpoint: string;
12
16
  pinPetFastApiUrl: string;
@@ -16,6 +20,7 @@ export interface NetworkConfig {
16
20
  }
17
21
 
18
22
  export interface PinPetSdkOptions {
23
+ network?: NetworkType;
19
24
  defaultDataSource?: DataSourceType;
20
25
  solanaEndpoint?: string;
21
26
  pinPetFastApiUrl?: string;
@@ -362,7 +367,9 @@ export declare class CurveAMM {
362
367
 
363
368
  // ========================= 常量和函数导出 =========================
364
369
 
365
- export declare const SPINPET_PROGRAM_ID: string;
370
+ export declare const SPINPET_PROGRAM_ID: PublicKey;
371
+
372
+ export declare function getProgramId(network?: NetworkType): PublicKey;
366
373
 
367
374
  export declare function getDefaultOptions(networkName?: 'MAINNET' | 'DEVNET' | 'LOCALNET'): NetworkConfig;
368
375
 
@@ -6,6 +6,8 @@
6
6
  const DEFAULT_NETWORKS = {
7
7
  MAINNET: {
8
8
  name: 'mainnet-beta',
9
+ network: 'mainnet',
10
+ programId: 'CYdRzRacZ5kTc9Ht3U7mFhbsyxG3sZGEzC4cNf2Gjg2W',
9
11
  defaultDataSource: 'fast',
10
12
  solanaEndpoint: 'https://solana-rpc.pinpet.fun',
11
13
  pinPetFastApiUrl: 'https://api.pinpet.fun/',
@@ -15,6 +17,8 @@ const DEFAULT_NETWORKS = {
15
17
  },
16
18
  DEVNET: {
17
19
  name: 'devnet',
20
+ network: 'localnet',
21
+ programId: 'F2FzigE1Z374iDvreiM6hZQe6oGXgomJfv8PyybvUXye',
18
22
  defaultDataSource: 'fast',
19
23
  solanaEndpoint: 'https://lu-ura5lv-fast-devnet.helius-rpc.com',
20
24
  pinPetFastApiUrl: 'https://devtestapi.pinpet.fun',
@@ -24,6 +28,8 @@ const DEFAULT_NETWORKS = {
24
28
  },
25
29
  LOCALNET: {
26
30
  name: 'localnet',
31
+ network: 'localnet',
32
+ programId: 'F2FzigE1Z374iDvreiM6hZQe6oGXgomJfv8PyybvUXye',
27
33
  defaultDataSource: 'fast', // 'fast' or 'chain'
28
34
  solanaEndpoint: 'http://127.0.0.1:8899',
29
35
  pinPetFastApiUrl: 'http://127.0.0.1:3000',
File without changes