pump-trader 1.0.0 → 1.0.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 CHANGED
@@ -162,9 +162,31 @@ console.log(completed); // 是否完成内盘
162
162
 
163
163
  ### 查询余额
164
164
 
165
+ #### 查询单个代币余额
166
+
167
+ ```javascript
168
+ // 查询指定代币的余额
169
+ const balance = await trader.tokenBalance(tokenAddr);
170
+ console.log(balance); // 返回数字,例如:123.45
171
+ ```
172
+
173
+ #### 查询所有代币余额
174
+
175
+ ```javascript
176
+ // 查询账户所有的代币(余额 > 0)
177
+ const allTokens = await trader.tokenBalance();
178
+
179
+ // 返回数组:[{ mint, amount, decimals, uiAmount }, ...]
180
+ allTokens.forEach((token) => {
181
+ console.log(`${token.mint}: ${token.uiAmount}`);
182
+ });
183
+ ```
184
+
185
+ #### 使用专用方法
186
+
165
187
  ```javascript
166
- // 代币余额
167
- const tokenBalance = await trader.tokenBalance(tokenAddr);
188
+ // 直接调用方法查询所有代币
189
+ const allBalances = await trader.getAllTokenBalances();
168
190
 
169
191
  // SOL 余额
170
192
  const solBalance = await trader.solBalance();
@@ -0,0 +1,177 @@
1
+ import { Connection, PublicKey, Transaction, TransactionInstruction, Keypair } from "@solana/web3.js";
2
+ interface TradeOptions {
3
+ maxSolPerTx: bigint;
4
+ slippage: {
5
+ base: number;
6
+ max?: number;
7
+ min?: number;
8
+ impactFactor?: number;
9
+ };
10
+ priority: {
11
+ base: number;
12
+ enableRandom?: boolean;
13
+ randomRange?: number;
14
+ };
15
+ }
16
+ interface PendingTransaction {
17
+ signature: string;
18
+ lastValidBlockHeight: number;
19
+ index: number;
20
+ }
21
+ interface FailedTransaction {
22
+ index: number;
23
+ error: string;
24
+ }
25
+ interface TradeResult {
26
+ pendingTransactions: PendingTransaction[];
27
+ failedTransactions: FailedTransaction[];
28
+ }
29
+ interface BondingCurveState {
30
+ virtualTokenReserves: bigint;
31
+ virtualSolReserves: bigint;
32
+ realTokenReserves: bigint;
33
+ realSolReserves: bigint;
34
+ tokenTotalSupply: bigint;
35
+ complete: boolean;
36
+ }
37
+ interface BondingInfo {
38
+ bonding: PublicKey;
39
+ state: BondingCurveState;
40
+ creator: PublicKey;
41
+ }
42
+ interface PoolReserves {
43
+ baseAmount: bigint;
44
+ quoteAmount: bigint;
45
+ baseDecimals: number;
46
+ quoteDecimals: number;
47
+ }
48
+ interface TradeEvent {
49
+ mint: string;
50
+ solAmount: bigint;
51
+ tokenAmount: bigint;
52
+ isBuy: boolean;
53
+ user: string;
54
+ timestamp: number;
55
+ signature: string;
56
+ }
57
+ interface GlobalState {
58
+ initialized: boolean;
59
+ authority: PublicKey;
60
+ feeRecipient: PublicKey;
61
+ withdrawAuthority: PublicKey;
62
+ initialVirtualTokenReserves: bigint;
63
+ initialVirtualSolReserves: bigint;
64
+ initialRealTokenReserves: bigint;
65
+ tokenTotalSupply: bigint;
66
+ feeBasisPoints: bigint;
67
+ }
68
+ interface TokenProgramType {
69
+ type: "TOKEN_PROGRAM_ID" | "TOKEN_2022_PROGRAM_ID";
70
+ programId: PublicKey;
71
+ }
72
+ interface PoolInfo {
73
+ pool: PublicKey;
74
+ poolAuthority: PublicKey;
75
+ poolKeys: any;
76
+ globalConfig: any;
77
+ }
78
+ interface MetadataInfo {
79
+ name: string;
80
+ symbol: string;
81
+ uri: string;
82
+ }
83
+ export declare class PumpTrader {
84
+ private connection;
85
+ private wallet;
86
+ private global;
87
+ private globalState;
88
+ private tokenProgramCache;
89
+ constructor(rpc: string, privateKey: string);
90
+ /**
91
+ * 自动检测代币使用的 token program
92
+ */
93
+ detectTokenProgram(tokenAddr: string): Promise<TokenProgramType>;
94
+ /**
95
+ * 检测代币是否在外盘 (AMM)
96
+ */
97
+ isAmmCompleted(tokenAddr: string): Promise<boolean>;
98
+ /**
99
+ * 自动判断应该使用内盘还是外盘
100
+ */
101
+ getTradeMode(tokenAddr: string): Promise<"bonding" | "amm">;
102
+ loadGlobal(): Promise<GlobalState>;
103
+ getBondingPda(mint: PublicKey): PublicKey;
104
+ loadBonding(mint: PublicKey): Promise<BondingInfo>;
105
+ calcBuy(solIn: bigint, state: BondingCurveState): bigint;
106
+ calcSell(tokenIn: bigint, state: BondingCurveState): bigint;
107
+ calculateAmmBuyOutput(quoteIn: bigint, reserves: PoolReserves): bigint;
108
+ calculateAmmSellOutput(baseIn: bigint, reserves: PoolReserves): bigint;
109
+ getPriceAndStatus(tokenAddr: string): Promise<{
110
+ price: number;
111
+ completed: boolean;
112
+ }>;
113
+ getAmmPrice(mint: PublicKey): Promise<number>;
114
+ /**
115
+ * 查询代币余额
116
+ * @param tokenAddr - 代币地址(可选),如果不传则返回所有代币
117
+ * @returns 如果传入地址则返回该代币的余额数字,否则返回所有代币的详细信息
118
+ */
119
+ tokenBalance(tokenAddr?: string): Promise<number | Array<{
120
+ mint: string;
121
+ amount: number;
122
+ decimals: number;
123
+ uiAmount: number;
124
+ }>>;
125
+ /**
126
+ * 获取账户所有代币余额(仅显示余额 > 0 的)
127
+ * @returns 代币信息数组,包含mint地址、余额等信息
128
+ */
129
+ getAllTokenBalances(): Promise<Array<{
130
+ mint: string;
131
+ amount: number;
132
+ decimals: number;
133
+ uiAmount: number;
134
+ }>>;
135
+ solBalance(): Promise<number>;
136
+ ensureAta(tx: Transaction, mint: PublicKey, tokenProgram?: PublicKey): Promise<PublicKey>;
137
+ ensureWSOLAta(tx: Transaction, owner: PublicKey, mode: "buy" | "sell", lamports?: bigint): Promise<PublicKey>;
138
+ genPriority(priorityOpt: any): number;
139
+ calcSlippage({ tradeSize, reserve, slippageOpt }: any): number;
140
+ splitByMax(total: bigint, max: bigint): bigint[];
141
+ splitIntoN(total: bigint, n: number): bigint[];
142
+ /**
143
+ * 自动判断内盘/外盘并执行买入
144
+ */
145
+ autoBuy(tokenAddr: string, totalSolIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult>;
146
+ /**
147
+ * 自动判断内盘/外盘并执行卖出
148
+ */
149
+ autoSell(tokenAddr: string, totalTokenIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult>;
150
+ buy(tokenAddr: string, totalSolIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult>;
151
+ sell(tokenAddr: string, totalTokenIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult>;
152
+ ammBuy(tokenAddr: string, totalSolIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult>;
153
+ ammSell(tokenAddr: string, totalTokenIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult>;
154
+ getAmmPoolInfo(mint: PublicKey): Promise<PoolInfo>;
155
+ parseAmmGlobalConfig(data: Buffer, address: PublicKey): {
156
+ address: PublicKey;
157
+ admin: PublicKey;
158
+ protocolFeeRecipients: PublicKey[];
159
+ };
160
+ getAmmPoolReserves(poolKeys: any): Promise<PoolReserves>;
161
+ createAmmBuyInstruction(poolInfo: PoolInfo, userBaseAta: PublicKey, userQuoteAta: PublicKey, baseAmountOut: bigint, maxQuoteAmountIn: bigint): TransactionInstruction;
162
+ createAmmSellInstruction(poolInfo: PoolInfo, userBaseAta: PublicKey, userQuoteAta: PublicKey, baseAmountIn: bigint, minQuoteAmountOut: bigint): TransactionInstruction;
163
+ confirmTransactionWithPolling(signature: string, lastValidBlockHeight: number, maxAttempts?: number, delayMs?: number): Promise<string>;
164
+ listenTrades(callback: (event: TradeEvent) => void, mintFilter?: PublicKey | null): number;
165
+ fetchMeta(tokenAddr: string): Promise<MetadataInfo | null>;
166
+ getWallet(): Keypair;
167
+ getConnection(): Connection;
168
+ /**
169
+ * 清除token program缓存
170
+ */
171
+ clearTokenProgramCache(tokenAddr: string): void;
172
+ /**
173
+ * 获取缓存的token program信息
174
+ */
175
+ getCachedTokenProgram(tokenAddr: string): TokenProgramType | undefined;
176
+ }
177
+ export type { TradeOptions, PendingTransaction, FailedTransaction, TradeResult, BondingCurveState, BondingInfo, PoolReserves, TradeEvent, GlobalState, TokenProgramType, PoolInfo, MetadataInfo };