pump-trader 1.0.1 → 1.0.3

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.
@@ -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, tokenProgramId: PublicKey): TransactionInstruction;
162
+ createAmmSellInstruction(poolInfo: PoolInfo, userBaseAta: PublicKey, userQuoteAta: PublicKey, baseAmountIn: bigint, minQuoteAmountOut: bigint, tokenProgramId: PublicKey): 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 };