pinpet-sdk 2.0.8 → 2.0.10

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/index.d.ts CHANGED
@@ -309,15 +309,38 @@ export declare class CurveAMM {
309
309
  static readonly MAX_U128_PRICE: bigint;
310
310
  static readonly MIN_U128_PRICE: bigint;
311
311
 
312
+ // Price conversion methods
312
313
  static u128ToDecimal(price: bigint | string | number): any;
313
314
  static decimalToU128(price: any): bigint | null;
314
315
  static decimalToU128Ceil(price: any): bigint | null;
316
+ static u64ToDecimal(price: bigint | string | number): any;
317
+ static decimalToU64(price: any): bigint | null;
318
+ static decimalToU64Ceil(price: any): bigint | null;
319
+
320
+ // Token amount conversion methods
321
+ static tokenDecimalToU64(amount: any): bigint | null;
322
+ static tokenDecimalToU64Ceil(amount: any): bigint | null;
323
+ static u64ToTokenDecimal(amount: bigint | string | number): any;
324
+
325
+ // SOL amount conversion methods
326
+ static solDecimalToU64(amount: any): bigint | null;
327
+ static solDecimalToU64Ceil(amount: any): bigint | null;
328
+ static u64ToSolDecimal(amount: bigint | string | number): any;
329
+
330
+ // Initial price and K calculation
331
+ static calculateInitialK(): any;
332
+ static getInitialPrice(): bigint | null;
333
+
334
+ // AMM calculation methods
335
+ static calculateReservesByPrice(price: any, k: any): [any, any] | null;
315
336
  static buyFromPriceToPrice(startLowPrice: bigint | string | number, endHighPrice: bigint | string | number): [bigint, bigint] | null;
316
337
  static sellFromPriceToPrice(startHighPrice: bigint | string | number, endLowPrice: bigint | string | number): [bigint, bigint] | null;
317
338
  static buyFromPriceWithSolInput(startLowPrice: bigint | string | number, solInputAmount: bigint | string | number): [bigint, bigint] | null;
318
339
  static sellFromPriceWithTokenInput(startHighPrice: bigint | string | number, tokenInputAmount: bigint | string | number): [bigint, bigint] | null;
319
340
  static buyFromPriceWithTokenOutput(startLowPrice: bigint | string | number, tokenOutputAmount: bigint | string | number): [bigint, bigint] | null;
320
341
  static sellFromPriceWithSolOutput(startHighPrice: bigint | string | number, solOutputAmount: bigint | string | number): [bigint, bigint] | null;
342
+
343
+ // Fee and price display methods
321
344
  static calculateAmountAfterFee(amount: bigint | string | number, fee: number): bigint | null;
322
345
  static formatPriceForDisplay(price: bigint | string | number, decimalPlaces?: number): string;
323
346
  static createPriceDisplayString(price: bigint | string | number, decimalPlaces?: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinpet-sdk",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "Solana PinPet.fun SDK",
5
5
  "main": "dist/pinpet-sdk.cjs.js",
6
6
  "module": "dist/pinpet-sdk.esm.js",
@@ -309,15 +309,38 @@ export declare class CurveAMM {
309
309
  static readonly MAX_U128_PRICE: bigint;
310
310
  static readonly MIN_U128_PRICE: bigint;
311
311
 
312
+ // Price conversion methods
312
313
  static u128ToDecimal(price: bigint | string | number): any;
313
314
  static decimalToU128(price: any): bigint | null;
314
315
  static decimalToU128Ceil(price: any): bigint | null;
316
+ static u64ToDecimal(price: bigint | string | number): any;
317
+ static decimalToU64(price: any): bigint | null;
318
+ static decimalToU64Ceil(price: any): bigint | null;
319
+
320
+ // Token amount conversion methods
321
+ static tokenDecimalToU64(amount: any): bigint | null;
322
+ static tokenDecimalToU64Ceil(amount: any): bigint | null;
323
+ static u64ToTokenDecimal(amount: bigint | string | number): any;
324
+
325
+ // SOL amount conversion methods
326
+ static solDecimalToU64(amount: any): bigint | null;
327
+ static solDecimalToU64Ceil(amount: any): bigint | null;
328
+ static u64ToSolDecimal(amount: bigint | string | number): any;
329
+
330
+ // Initial price and K calculation
331
+ static calculateInitialK(): any;
332
+ static getInitialPrice(): bigint | null;
333
+
334
+ // AMM calculation methods
335
+ static calculateReservesByPrice(price: any, k: any): [any, any] | null;
315
336
  static buyFromPriceToPrice(startLowPrice: bigint | string | number, endHighPrice: bigint | string | number): [bigint, bigint] | null;
316
337
  static sellFromPriceToPrice(startHighPrice: bigint | string | number, endLowPrice: bigint | string | number): [bigint, bigint] | null;
317
338
  static buyFromPriceWithSolInput(startLowPrice: bigint | string | number, solInputAmount: bigint | string | number): [bigint, bigint] | null;
318
339
  static sellFromPriceWithTokenInput(startHighPrice: bigint | string | number, tokenInputAmount: bigint | string | number): [bigint, bigint] | null;
319
340
  static buyFromPriceWithTokenOutput(startLowPrice: bigint | string | number, tokenOutputAmount: bigint | string | number): [bigint, bigint] | null;
320
341
  static sellFromPriceWithSolOutput(startHighPrice: bigint | string | number, solOutputAmount: bigint | string | number): [bigint, bigint] | null;
342
+
343
+ // Fee and price display methods
321
344
  static calculateAmountAfterFee(amount: bigint | string | number, fee: number): bigint | null;
322
345
  static formatPriceForDisplay(price: bigint | string | number, decimalPlaces?: number): string;
323
346
  static createPriceDisplayString(price: bigint | string | number, decimalPlaces?: number): string;
@@ -1,339 +0,0 @@
1
- import { Connection, PublicKey, Transaction, Keypair } from '@solana/web3.js';
2
- import { BN, Wallet, Program } from '@coral-xyz/anchor';
3
-
4
- // ========================= 基础类型定义 =========================
5
-
6
- export type DataSourceType = 'fast' | 'chain';
7
-
8
- export interface NetworkConfig {
9
- name: string;
10
- defaultDataSource: DataSourceType;
11
- solanaEndpoint: string;
12
- spin_fast_api_url: string;
13
- fee_recipient: string;
14
- base_fee_recipient: string;
15
- params_account: string;
16
- }
17
-
18
- export interface PinPetSdkOptions {
19
- defaultDataSource?: DataSourceType;
20
- solanaEndpoint?: string;
21
- spin_fast_api_url?: string;
22
- fee_recipient?: string;
23
- base_fee_recipient?: string;
24
- params_account?: string;
25
- }
26
-
27
- // ========================= 订单和交易相关类型 =========================
28
-
29
- export interface OrderData {
30
- order_pda: string;
31
- user: string;
32
- mint: string;
33
- order_type: string;
34
- lock_lp_sol_amount: string;
35
- lock_lp_token_amount: string;
36
- lock_lp_start_price: string;
37
- lock_lp_end_price: string;
38
- margin_sol_amount: string;
39
- borrow_amount: string;
40
- position_asset_amount: string;
41
- created_at?: string;
42
- updated_at?: string;
43
- }
44
-
45
- export interface LpPair {
46
- solAmount: BN;
47
- tokenAmount: BN;
48
- }
49
-
50
- export interface TransactionResult {
51
- transaction: Transaction;
52
- signers: Keypair[];
53
- accounts: Record<string, PublicKey>;
54
- orderData?: {
55
- ordersUsed: number;
56
- lpPairsCount: number;
57
- lpPairs: LpPair[];
58
- orderAccounts: (string | null)[];
59
- [key: string]: any;
60
- };
61
- }
62
-
63
- export interface OrdersResponse {
64
- data: {
65
- orders: OrderData[];
66
- total?: number;
67
- page?: number;
68
- limit?: number;
69
- };
70
- }
71
-
72
- export interface PriceResponse {
73
- price: string;
74
- price_u128: string;
75
- [key: string]: any;
76
- }
77
-
78
- export interface MintInfo {
79
- mint: string;
80
- name?: string;
81
- symbol?: string;
82
- decimals: number;
83
- total_supply?: string;
84
- [key: string]: any;
85
- }
86
-
87
- // ========================= 交易参数类型 =========================
88
-
89
- export interface BuyParams {
90
- mintAccount: string | PublicKey;
91
- buyTokenAmount: BN;
92
- maxSolAmount: BN;
93
- payer: PublicKey;
94
- }
95
-
96
- export interface SellParams {
97
- mintAccount: string | PublicKey;
98
- sellTokenAmount: BN;
99
- minSolOutput: BN;
100
- payer: PublicKey;
101
- }
102
-
103
- export interface LongParams {
104
- mintAccount: string | PublicKey;
105
- buyTokenAmount: BN;
106
- maxSolAmount: BN;
107
- marginSol: BN;
108
- closePrice: BN;
109
- prevOrder?: PublicKey | null;
110
- nextOrder?: PublicKey | null;
111
- payer: PublicKey;
112
- }
113
-
114
- export interface ShortParams {
115
- mintAccount: string | PublicKey;
116
- borrowSellTokenAmount: BN;
117
- minSolOutput: BN;
118
- marginSol: BN;
119
- closePrice: BN;
120
- prevOrder?: PublicKey | null;
121
- nextOrder?: PublicKey | null;
122
- payer: PublicKey;
123
- }
124
-
125
- export interface CloseLongParams {
126
- mintAccount: string | PublicKey;
127
- closeOrder: string | PublicKey;
128
- sellTokenAmount: BN;
129
- minSolOutput: BN;
130
- payer: PublicKey;
131
- }
132
-
133
- export interface CloseShortParams {
134
- mintAccount: string | PublicKey;
135
- closeOrder: string | PublicKey;
136
- buyTokenAmount: BN;
137
- maxSolAmount: BN;
138
- payer: PublicKey;
139
- }
140
-
141
- export interface TransactionOptions {
142
- computeUnits?: number;
143
- }
144
-
145
- // ========================= 查询参数类型 =========================
146
-
147
- export interface OrdersQueryOptions {
148
- type?: 'up_orders' | 'down_orders';
149
- limit?: number;
150
- page?: number;
151
- dataSource?: DataSourceType;
152
- }
153
-
154
- export interface PriceQueryOptions {
155
- dataSource?: DataSourceType;
156
- }
157
-
158
- export interface UserOrdersQueryOptions {
159
- type?: 'up_orders' | 'down_orders';
160
- limit?: number;
161
- page?: number;
162
- dataSource?: DataSourceType;
163
- }
164
-
165
- // ========================= 模拟器相关类型 =========================
166
-
167
- export interface SimulationResult {
168
- liqResult: {
169
- free_lp_sol_amount_sum: bigint;
170
- free_lp_token_amount_sum: bigint;
171
- lock_lp_sol_amount_sum: bigint;
172
- lock_lp_token_amount_sum: bigint;
173
- has_infinite_lp: boolean;
174
- pass_order_id: number;
175
- force_close_num: number;
176
- ideal_lp_sol_amount: bigint;
177
- real_lp_sol_amount: bigint;
178
- };
179
- completion: string;
180
- slippage: string;
181
- suggestedTokenAmount: string;
182
- suggestedSolAmount: string;
183
- }
184
-
185
- // ========================= 工具类相关类型 =========================
186
-
187
- export interface FindPrevNextResult {
188
- prevOrder: OrderData | null;
189
- nextOrder: OrderData | null;
190
- }
191
-
192
- export interface ValidationResult {
193
- valid: boolean;
194
- errors: string[];
195
- warnings: string[];
196
- }
197
-
198
- // ========================= 模块接口定义 =========================
199
-
200
- export interface TradingModule {
201
- buy(params: BuyParams, options?: TransactionOptions): Promise<TransactionResult>;
202
- sell(params: SellParams, options?: TransactionOptions): Promise<TransactionResult>;
203
- long(params: LongParams, options?: TransactionOptions): Promise<TransactionResult>;
204
- short(params: ShortParams, options?: TransactionOptions): Promise<TransactionResult>;
205
- closeLong(params: CloseLongParams, options?: TransactionOptions): Promise<TransactionResult>;
206
- closeShort(params: CloseShortParams, options?: TransactionOptions): Promise<TransactionResult>;
207
- }
208
-
209
- export interface FastModule {
210
- mints(options?: any): Promise<any>;
211
- mint_info(mint: string): Promise<MintInfo>;
212
- orders(mint: string, options?: OrdersQueryOptions): Promise<OrdersResponse>;
213
- price(mint: string, options?: PriceQueryOptions): Promise<PriceResponse>;
214
- user_orders(user: string, mint: string, options?: UserOrdersQueryOptions): Promise<OrdersResponse>;
215
- }
216
-
217
- export interface ChainModule {
218
- getCurveAccount(mint: string): Promise<any>;
219
- orders(mint: string, options?: OrdersQueryOptions): Promise<OrdersResponse>;
220
- price(mint: string, options?: PriceQueryOptions): Promise<PriceResponse>;
221
- }
222
-
223
- export interface TokenModule {
224
- create(params: any): Promise<TransactionResult>;
225
- }
226
-
227
- export interface ParamModule {
228
- createParams(params: any): Promise<TransactionResult>;
229
- getParams(partner: string): Promise<any>;
230
- getAdmin(): Promise<any>;
231
- }
232
-
233
- export interface SimulatorModule {
234
- simulateTokenBuy(mint: string, buyTokenAmount: bigint | string | number, passOrder?: string | null): Promise<SimulationResult>;
235
- simulateTokenSell(mint: string, sellTokenAmount: bigint | string | number, passOrder?: string | null): Promise<SimulationResult>;
236
- simulateLongStopLoss(mint: string, buyTokenAmount: bigint | string | number, stopLossPrice: bigint | string | number, lastPrice?: any, ordersData?: any): Promise<any>;
237
- simulateSellStopLoss(mint: string, sellTokenAmount: bigint | string | number, stopLossPrice: bigint | string | number, lastPrice?: any, ordersData?: any): Promise<any>;
238
- }
239
-
240
- // ========================= 数据接口类型 =========================
241
-
242
- export interface DataInterface {
243
- orders(mint: string, options?: OrdersQueryOptions): Promise<OrdersResponse>;
244
- price(mint: string, options?: PriceQueryOptions): Promise<PriceResponse>;
245
- }
246
-
247
- // ========================= 主 SDK 类型定义 =========================
248
-
249
- export declare class PinPetSdk {
250
- connection: Connection;
251
- programId: PublicKey;
252
- program: Program;
253
- options: PinPetSdkOptions;
254
- defaultDataSource: DataSourceType;
255
- feeRecipient: PublicKey;
256
- baseFeeRecipient: PublicKey;
257
- paramsAccount: PublicKey;
258
- spinFastApiUrl: string;
259
-
260
- // 常量
261
- readonly MAX_ORDERS_COUNT: number;
262
- readonly FIND_MAX_ORDERS_COUNT: number;
263
- readonly SUGGEST_LIQ_RATIO: number;
264
-
265
- // 模块
266
- trading: TradingModule;
267
- fast: FastModule;
268
- chain: ChainModule;
269
- token: TokenModule;
270
- param: ParamModule;
271
- simulator: SimulatorModule;
272
- data: DataInterface;
273
-
274
- constructor(
275
- connection: Connection,
276
- programId: string | PublicKey,
277
- options?: PinPetSdkOptions
278
- );
279
-
280
- // OrderUtils 快捷方法
281
- buildLpPairs(orders: OrderData[], direction: string, price: any, maxCount?: number): LpPair[];
282
- buildOrderAccounts(orders: OrderData[], maxCount?: number): (string | null)[];
283
- findPrevNext(orders: OrderData[], findOrderPda: string): FindPrevNextResult;
284
- findOrderIndex(orders: OrderData[], targetOrderPda: string | PublicKey | null): number;
285
- }
286
-
287
- // ========================= 工具类导出 =========================
288
-
289
- export declare class OrderUtils {
290
- static buildLpPairs(orders: OrderData[], direction: string, price: any, maxCount?: number): LpPair[];
291
- static buildOrderAccounts(orders: OrderData[], maxCount?: number): (string | null)[];
292
- static findPrevNext(orders: OrderData[], findOrderPda: string): FindPrevNextResult;
293
- static findOrderIndex(orders: OrderData[], targetOrderPda: string | PublicKey | null): number;
294
- static validateOrdersFormat(orders: OrderData[], throwOnError?: boolean): boolean | ValidationResult;
295
- }
296
-
297
- export declare class CurveAMM {
298
- static readonly INITIAL_SOL_RESERVE_DECIMAL: any;
299
- static readonly INITIAL_TOKEN_RESERVE_DECIMAL: any;
300
- static readonly INITIAL_K_DECIMAL: any;
301
- static readonly INITIAL_MIN_PRICE_DECIMAL: any;
302
- static readonly PRICE_PRECISION_FACTOR_DECIMAL: any;
303
- static readonly TOKEN_PRECISION_FACTOR_DECIMAL: any;
304
- static readonly SOL_PRECISION_FACTOR_DECIMAL: any;
305
- static readonly MAX_U128_PRICE: bigint;
306
- static readonly MIN_U128_PRICE: bigint;
307
-
308
- static u128ToDecimal(price: bigint | string | number): any;
309
- static decimalToU128(price: any): bigint | null;
310
- static decimalToU128Ceil(price: any): bigint | null;
311
- static buyFromPriceToPrice(startLowPrice: bigint | string | number, endHighPrice: bigint | string | number): [bigint, bigint] | null;
312
- static sellFromPriceToPrice(startHighPrice: bigint | string | number, endLowPrice: bigint | string | number): [bigint, bigint] | null;
313
- static buyFromPriceWithSolInput(startLowPrice: bigint | string | number, solInputAmount: bigint | string | number): [bigint, bigint] | null;
314
- static sellFromPriceWithTokenInput(startHighPrice: bigint | string | number, tokenInputAmount: bigint | string | number): [bigint, bigint] | null;
315
- static buyFromPriceWithTokenOutput(startLowPrice: bigint | string | number, tokenOutputAmount: bigint | string | number): [bigint, bigint] | null;
316
- static sellFromPriceWithSolOutput(startHighPrice: bigint | string | number, solOutputAmount: bigint | string | number): [bigint, bigint] | null;
317
- static calculateAmountAfterFee(amount: bigint | string | number, fee: number): bigint | null;
318
- static formatPriceForDisplay(price: bigint | string | number, decimalPlaces?: number): string;
319
- static createPriceDisplayString(price: bigint | string | number, decimalPlaces?: number): string;
320
- static calculatePoolPrice(lpTokenReserve: bigint | string | number | BN, lpSolReserve: bigint | string | number | BN): string | null;
321
- }
322
-
323
- // ========================= 常量和函数导出 =========================
324
-
325
- export declare const SPINPET_PROGRAM_ID: string;
326
-
327
- export declare function getDefaultOptions(networkName?: 'MAINNET' | 'DEVNET' | 'LOCALNET'): NetworkConfig;
328
-
329
- // ========================= 模块类导出 =========================
330
-
331
- export declare class TradingModule implements TradingModule {}
332
- export declare class FastModule implements FastModule {}
333
- export declare class ChainModule implements ChainModule {}
334
- export declare class TokenModule implements TokenModule {}
335
- export declare class ParamModule implements ParamModule {}
336
- export declare class SimulatorModule implements SimulatorModule {}
337
-
338
- // 默认导出
339
- export default PinPetSdk;