pump-trader 1.1.8 → 1.2.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/dist/index.d.ts +56 -9
- package/dist/index.js +747 -138
- package/index.js +64 -50
- package/index.ts +118 -96
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -22,10 +22,14 @@ import {
|
|
|
22
22
|
} from "@solana/spl-token";
|
|
23
23
|
|
|
24
24
|
import BN from "bn.js";
|
|
25
|
-
import bs58 from "bs58";
|
|
26
|
-
|
|
27
25
|
/* ================= 类型定义 ================= */
|
|
28
26
|
|
|
27
|
+
/** Wallet 接口:兼容 Keypair(自动签名)和前端钱包适配器(弹出确认) */
|
|
28
|
+
export type Wallet = Keypair | {
|
|
29
|
+
publicKey: PublicKey;
|
|
30
|
+
signTransaction<T extends Transaction>(tx: T): Promise<T>;
|
|
31
|
+
};
|
|
32
|
+
|
|
29
33
|
interface TradeOptions {
|
|
30
34
|
maxSolPerTx: bigint;
|
|
31
35
|
slippage: {
|
|
@@ -313,14 +317,16 @@ function parsePoolKeys(data: Buffer) {
|
|
|
313
317
|
|
|
314
318
|
export class PumpTrader {
|
|
315
319
|
private connection: Connection;
|
|
316
|
-
private
|
|
320
|
+
private _wallet: Keypair | { publicKey: PublicKey; signTransaction<T extends Transaction>(tx: T): Promise<T> };
|
|
321
|
+
public publicKey: PublicKey;
|
|
317
322
|
private global: PublicKey;
|
|
318
323
|
private globalState: GlobalState | null;
|
|
319
324
|
private tokenProgramCache: Map<string, TokenProgramType>;
|
|
320
325
|
|
|
321
|
-
constructor(rpc: string,
|
|
326
|
+
constructor(rpc: string, wallet: Wallet) {
|
|
322
327
|
this.connection = new Connection(rpc, "confirmed");
|
|
323
|
-
this.
|
|
328
|
+
this._wallet = wallet;
|
|
329
|
+
this.publicKey = wallet.publicKey;
|
|
324
330
|
this.global = PublicKey.findProgramAddressSync(
|
|
325
331
|
[SEEDS.GLOBAL],
|
|
326
332
|
PROGRAM_IDS.PUMP,
|
|
@@ -329,6 +335,16 @@ export class PumpTrader {
|
|
|
329
335
|
this.tokenProgramCache = new Map();
|
|
330
336
|
}
|
|
331
337
|
|
|
338
|
+
private async signTx(tx: Transaction): Promise<void> {
|
|
339
|
+
if (this._wallet instanceof Keypair) {
|
|
340
|
+
tx.sign(this._wallet);
|
|
341
|
+
} else {
|
|
342
|
+
const signed = await this._wallet.signTransaction(tx);
|
|
343
|
+
// Copy signatures back to the original tx (adapter returns a new tx)
|
|
344
|
+
tx.signatures = signed.signatures;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
332
348
|
/* ---------- Token Program 检测 ---------- */
|
|
333
349
|
|
|
334
350
|
/**
|
|
@@ -741,17 +757,17 @@ export class PumpTrader {
|
|
|
741
757
|
async tokenBalance(tokenAddr?: string): Promise<
|
|
742
758
|
| number
|
|
743
759
|
| Array<{
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
760
|
+
mint: string;
|
|
761
|
+
amount: number;
|
|
762
|
+
decimals: number;
|
|
763
|
+
uiAmount: number;
|
|
764
|
+
}>
|
|
749
765
|
> {
|
|
750
766
|
if (tokenAddr) {
|
|
751
767
|
// 查询单个代币
|
|
752
768
|
const mint = new PublicKey(tokenAddr);
|
|
753
769
|
const tokenAccounts = await this.connection.getParsedTokenAccountsByOwner(
|
|
754
|
-
this.
|
|
770
|
+
this.publicKey,
|
|
755
771
|
{ mint },
|
|
756
772
|
);
|
|
757
773
|
return (
|
|
@@ -772,7 +788,7 @@ export class PumpTrader {
|
|
|
772
788
|
Array<{ mint: string; amount: number; decimals: number; uiAmount: number }>
|
|
773
789
|
> {
|
|
774
790
|
const tokenAccounts = await this.connection.getParsedTokenAccountsByOwner(
|
|
775
|
-
this.
|
|
791
|
+
this.publicKey,
|
|
776
792
|
{ programId: TOKEN_PROGRAM_ID },
|
|
777
793
|
);
|
|
778
794
|
|
|
@@ -792,16 +808,16 @@ export class PumpTrader {
|
|
|
792
808
|
};
|
|
793
809
|
})
|
|
794
810
|
.filter((item) => item !== null) as Array<{
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
811
|
+
mint: string;
|
|
812
|
+
amount: bigint;
|
|
813
|
+
decimals: number;
|
|
814
|
+
uiAmount: number;
|
|
815
|
+
}>;
|
|
800
816
|
|
|
801
817
|
// 同时查询 TOKEN_2022_PROGRAM_ID
|
|
802
818
|
const token2022Accounts =
|
|
803
819
|
await this.connection.getParsedTokenAccountsByOwner(
|
|
804
|
-
this.
|
|
820
|
+
this.publicKey,
|
|
805
821
|
{ programId: TOKEN_2022_PROGRAM_ID },
|
|
806
822
|
);
|
|
807
823
|
|
|
@@ -821,11 +837,11 @@ export class PumpTrader {
|
|
|
821
837
|
};
|
|
822
838
|
})
|
|
823
839
|
.filter((item) => item !== null) as Array<{
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
840
|
+
mint: string;
|
|
841
|
+
amount: bigint;
|
|
842
|
+
decimals: number;
|
|
843
|
+
uiAmount: number;
|
|
844
|
+
}>;
|
|
829
845
|
|
|
830
846
|
// 合并并去重
|
|
831
847
|
const allBalances = [...balances, ...token2022Balances];
|
|
@@ -847,7 +863,7 @@ export class PumpTrader {
|
|
|
847
863
|
}
|
|
848
864
|
|
|
849
865
|
async solBalance(): Promise<number> {
|
|
850
|
-
const balance = await this.connection.getBalance(this.
|
|
866
|
+
const balance = await this.connection.getBalance(this.publicKey);
|
|
851
867
|
return balance / 1e9;
|
|
852
868
|
}
|
|
853
869
|
|
|
@@ -861,7 +877,7 @@ export class PumpTrader {
|
|
|
861
877
|
const program = tokenProgram || TOKEN_2022_PROGRAM_ID;
|
|
862
878
|
const ata = getAssociatedTokenAddressSync(
|
|
863
879
|
mint,
|
|
864
|
-
this.
|
|
880
|
+
this.publicKey,
|
|
865
881
|
false,
|
|
866
882
|
program,
|
|
867
883
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -871,9 +887,9 @@ export class PumpTrader {
|
|
|
871
887
|
if (!acc) {
|
|
872
888
|
tx.add(
|
|
873
889
|
createAssociatedTokenAccountInstruction(
|
|
874
|
-
this.
|
|
890
|
+
this.publicKey,
|
|
875
891
|
ata,
|
|
876
|
-
this.
|
|
892
|
+
this.publicKey,
|
|
877
893
|
mint,
|
|
878
894
|
program,
|
|
879
895
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -1068,7 +1084,7 @@ export class PumpTrader {
|
|
|
1068
1084
|
const [userVolumeAccumulator] = PublicKey.findProgramAddressSync(
|
|
1069
1085
|
[
|
|
1070
1086
|
Buffer.from("user_volume_accumulator"),
|
|
1071
|
-
this.
|
|
1087
|
+
this.publicKey.toBuffer(),
|
|
1072
1088
|
],
|
|
1073
1089
|
PROGRAM_IDS.PUMP,
|
|
1074
1090
|
);
|
|
@@ -1108,7 +1124,7 @@ export class PumpTrader {
|
|
|
1108
1124
|
bonding,
|
|
1109
1125
|
associatedBondingCurve,
|
|
1110
1126
|
userAta,
|
|
1111
|
-
wallet: this.
|
|
1127
|
+
wallet: this.publicKey,
|
|
1112
1128
|
creatorVault,
|
|
1113
1129
|
eventAuthority: PROGRAM_IDS.EVENT_AUTHORITY,
|
|
1114
1130
|
pumpProgram: PROGRAM_IDS.PUMP,
|
|
@@ -1131,8 +1147,8 @@ export class PumpTrader {
|
|
|
1131
1147
|
const { blockhash, lastValidBlockHeight } =
|
|
1132
1148
|
await this.connection.getLatestBlockhash("finalized");
|
|
1133
1149
|
tx.recentBlockhash = blockhash;
|
|
1134
|
-
tx.feePayer = this.
|
|
1135
|
-
|
|
1150
|
+
tx.feePayer = this.publicKey;
|
|
1151
|
+
await this.signTx(tx);
|
|
1136
1152
|
|
|
1137
1153
|
const signature = await this.connection.sendRawTransaction(
|
|
1138
1154
|
tx.serialize(),
|
|
@@ -1177,11 +1193,11 @@ export class PumpTrader {
|
|
|
1177
1193
|
totalSolOut <= tradeOpt.maxSolPerTx
|
|
1178
1194
|
? [totalTokenIn]
|
|
1179
1195
|
: this.splitIntoN(
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1196
|
+
totalTokenIn,
|
|
1197
|
+
Number(
|
|
1198
|
+
(totalSolOut + tradeOpt.maxSolPerTx - 1n) / tradeOpt.maxSolPerTx,
|
|
1199
|
+
),
|
|
1200
|
+
);
|
|
1185
1201
|
|
|
1186
1202
|
const pendingTransactions: PendingTransaction[] = [];
|
|
1187
1203
|
const failedTransactions: FailedTransaction[] = [];
|
|
@@ -1196,7 +1212,7 @@ export class PumpTrader {
|
|
|
1196
1212
|
|
|
1197
1213
|
const userAta = getAssociatedTokenAddressSync(
|
|
1198
1214
|
mint,
|
|
1199
|
-
this.
|
|
1215
|
+
this.publicKey,
|
|
1200
1216
|
false,
|
|
1201
1217
|
tokenProgram.programId,
|
|
1202
1218
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -1215,7 +1231,7 @@ export class PumpTrader {
|
|
|
1215
1231
|
const [userVolumeAccumulator] = PublicKey.findProgramAddressSync(
|
|
1216
1232
|
[
|
|
1217
1233
|
Buffer.from("user_volume_accumulator"),
|
|
1218
|
-
this.
|
|
1234
|
+
this.publicKey.toBuffer(),
|
|
1219
1235
|
],
|
|
1220
1236
|
PROGRAM_IDS.PUMP,
|
|
1221
1237
|
);
|
|
@@ -1248,7 +1264,7 @@ export class PumpTrader {
|
|
|
1248
1264
|
bonding,
|
|
1249
1265
|
associatedBondingCurve,
|
|
1250
1266
|
userAta,
|
|
1251
|
-
wallet: this.
|
|
1267
|
+
wallet: this.publicKey,
|
|
1252
1268
|
creatorVault,
|
|
1253
1269
|
eventAuthority: PROGRAM_IDS.EVENT_AUTHORITY,
|
|
1254
1270
|
pumpProgram: PROGRAM_IDS.PUMP,
|
|
@@ -1271,8 +1287,8 @@ export class PumpTrader {
|
|
|
1271
1287
|
const { blockhash, lastValidBlockHeight } =
|
|
1272
1288
|
await this.connection.getLatestBlockhash("finalized");
|
|
1273
1289
|
tx.recentBlockhash = blockhash;
|
|
1274
|
-
tx.feePayer = this.
|
|
1275
|
-
|
|
1290
|
+
tx.feePayer = this.publicKey;
|
|
1291
|
+
await this.signTx(tx);
|
|
1276
1292
|
|
|
1277
1293
|
const signature = await this.connection.sendRawTransaction(
|
|
1278
1294
|
tx.serialize(),
|
|
@@ -1337,11 +1353,11 @@ export class PumpTrader {
|
|
|
1337
1353
|
);
|
|
1338
1354
|
const userQuoteAta = isSolQuote
|
|
1339
1355
|
? await this.ensureWSOLAta(
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1356
|
+
tx,
|
|
1357
|
+
this.publicKey,
|
|
1358
|
+
"buy",
|
|
1359
|
+
maxQuoteIn,
|
|
1360
|
+
)
|
|
1345
1361
|
: await this.ensureAta(tx, quoteMint, quoteTokenProgramId);
|
|
1346
1362
|
|
|
1347
1363
|
const buyIx = this.createAmmBuyInstruction(
|
|
@@ -1358,8 +1374,8 @@ export class PumpTrader {
|
|
|
1358
1374
|
tx.add(
|
|
1359
1375
|
createCloseAccountInstruction(
|
|
1360
1376
|
userQuoteAta,
|
|
1361
|
-
this.
|
|
1362
|
-
this.
|
|
1377
|
+
this.publicKey,
|
|
1378
|
+
this.publicKey,
|
|
1363
1379
|
),
|
|
1364
1380
|
);
|
|
1365
1381
|
}
|
|
@@ -1367,8 +1383,8 @@ export class PumpTrader {
|
|
|
1367
1383
|
const { blockhash, lastValidBlockHeight } =
|
|
1368
1384
|
await this.connection.getLatestBlockhash("finalized");
|
|
1369
1385
|
tx.recentBlockhash = blockhash;
|
|
1370
|
-
tx.feePayer = this.
|
|
1371
|
-
|
|
1386
|
+
tx.feePayer = this.publicKey;
|
|
1387
|
+
await this.signTx(tx);
|
|
1372
1388
|
|
|
1373
1389
|
const signature = await this.connection.sendRawTransaction(
|
|
1374
1390
|
tx.serialize(),
|
|
@@ -1413,11 +1429,11 @@ export class PumpTrader {
|
|
|
1413
1429
|
totalSolOut <= tradeOpt.maxSolPerTx
|
|
1414
1430
|
? [totalTokenIn]
|
|
1415
1431
|
: this.splitIntoN(
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1432
|
+
totalTokenIn,
|
|
1433
|
+
Number(
|
|
1434
|
+
(totalSolOut + tradeOpt.maxSolPerTx - 1n) / tradeOpt.maxSolPerTx,
|
|
1435
|
+
),
|
|
1436
|
+
);
|
|
1421
1437
|
|
|
1422
1438
|
const pendingTransactions: PendingTransaction[] = [];
|
|
1423
1439
|
const failedTransactions: FailedTransaction[] = [];
|
|
@@ -1445,7 +1461,7 @@ export class PumpTrader {
|
|
|
1445
1461
|
tokenProgram.programId,
|
|
1446
1462
|
);
|
|
1447
1463
|
const userQuoteAta = isSolQuote
|
|
1448
|
-
? await this.ensureWSOLAta(tx, this.
|
|
1464
|
+
? await this.ensureWSOLAta(tx, this.publicKey, "sell")
|
|
1449
1465
|
: await this.ensureAta(tx, quoteMint, quoteTokenProgramId);
|
|
1450
1466
|
|
|
1451
1467
|
const sellIx = this.createAmmSellInstruction(
|
|
@@ -1462,8 +1478,8 @@ export class PumpTrader {
|
|
|
1462
1478
|
tx.add(
|
|
1463
1479
|
createCloseAccountInstruction(
|
|
1464
1480
|
userQuoteAta,
|
|
1465
|
-
this.
|
|
1466
|
-
this.
|
|
1481
|
+
this.publicKey,
|
|
1482
|
+
this.publicKey,
|
|
1467
1483
|
),
|
|
1468
1484
|
);
|
|
1469
1485
|
}
|
|
@@ -1471,8 +1487,8 @@ export class PumpTrader {
|
|
|
1471
1487
|
const { blockhash, lastValidBlockHeight } =
|
|
1472
1488
|
await this.connection.getLatestBlockhash("finalized");
|
|
1473
1489
|
tx.recentBlockhash = blockhash;
|
|
1474
|
-
tx.feePayer = this.
|
|
1475
|
-
|
|
1490
|
+
tx.feePayer = this.publicKey;
|
|
1491
|
+
await this.signTx(tx);
|
|
1476
1492
|
|
|
1477
1493
|
const signature = await this.connection.sendRawTransaction(
|
|
1478
1494
|
tx.serialize(),
|
|
@@ -1623,7 +1639,7 @@ export class PumpTrader {
|
|
|
1623
1639
|
const [userVolumeAccumulator] = PublicKey.findProgramAddressSync(
|
|
1624
1640
|
[
|
|
1625
1641
|
Buffer.from("user_volume_accumulator"),
|
|
1626
|
-
this.
|
|
1642
|
+
this.publicKey.toBuffer(),
|
|
1627
1643
|
],
|
|
1628
1644
|
PROGRAM_IDS.PUMP_AMM,
|
|
1629
1645
|
);
|
|
@@ -1679,7 +1695,7 @@ export class PumpTrader {
|
|
|
1679
1695
|
programId: PROGRAM_IDS.PUMP_AMM,
|
|
1680
1696
|
keys: [
|
|
1681
1697
|
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
1682
|
-
{ pubkey: this.
|
|
1698
|
+
{ pubkey: this.publicKey, isSigner: true, isWritable: true },
|
|
1683
1699
|
{ pubkey: globalConfig.address, isSigner: false, isWritable: false },
|
|
1684
1700
|
{ pubkey: poolKeys.baseMint, isSigner: false, isWritable: false },
|
|
1685
1701
|
{ pubkey: poolKeys.quoteMint, isSigner: false, isWritable: false },
|
|
@@ -1786,7 +1802,7 @@ export class PumpTrader {
|
|
|
1786
1802
|
const [userVolumeAccumulator] = PublicKey.findProgramAddressSync(
|
|
1787
1803
|
[
|
|
1788
1804
|
Buffer.from("user_volume_accumulator"),
|
|
1789
|
-
this.
|
|
1805
|
+
this.publicKey.toBuffer(),
|
|
1790
1806
|
],
|
|
1791
1807
|
PROGRAM_IDS.PUMP_AMM,
|
|
1792
1808
|
);
|
|
@@ -1824,7 +1840,7 @@ export class PumpTrader {
|
|
|
1824
1840
|
programId: PROGRAM_IDS.PUMP_AMM,
|
|
1825
1841
|
keys: [
|
|
1826
1842
|
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
1827
|
-
{ pubkey: this.
|
|
1843
|
+
{ pubkey: this.publicKey, isSigner: true, isWritable: true },
|
|
1828
1844
|
{ pubkey: globalConfig.address, isSigner: false, isWritable: false },
|
|
1829
1845
|
{ pubkey: poolKeys.baseMint, isSigner: false, isWritable: false },
|
|
1830
1846
|
{ pubkey: poolKeys.quoteMint, isSigner: false, isWritable: false },
|
|
@@ -2126,7 +2142,7 @@ export class PumpTrader {
|
|
|
2126
2142
|
const [userVolumeAccumulator] = PublicKey.findProgramAddressSync(
|
|
2127
2143
|
[
|
|
2128
2144
|
Buffer.from("user_volume_accumulator"),
|
|
2129
|
-
this.
|
|
2145
|
+
this.publicKey.toBuffer(),
|
|
2130
2146
|
],
|
|
2131
2147
|
PROGRAM_IDS.PUMP,
|
|
2132
2148
|
);
|
|
@@ -2163,7 +2179,7 @@ export class PumpTrader {
|
|
|
2163
2179
|
|
|
2164
2180
|
const associatedQuoteUser = getAssociatedTokenAddressSync(
|
|
2165
2181
|
quoteMint,
|
|
2166
|
-
this.
|
|
2182
|
+
this.publicKey,
|
|
2167
2183
|
false,
|
|
2168
2184
|
quoteTokenProgramId,
|
|
2169
2185
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2190,7 +2206,7 @@ export class PumpTrader {
|
|
|
2190
2206
|
if (quoteMint.equals(SOL_MINT)) {
|
|
2191
2207
|
await this.ensureWSOLAta(
|
|
2192
2208
|
tx,
|
|
2193
|
-
this.
|
|
2209
|
+
this.publicKey,
|
|
2194
2210
|
"buy",
|
|
2195
2211
|
maxQuoteCost,
|
|
2196
2212
|
);
|
|
@@ -2198,7 +2214,7 @@ export class PumpTrader {
|
|
|
2198
2214
|
// For non-SOL quote (e.g. USDC), ensure user has the quote token ATA
|
|
2199
2215
|
const userQuoteAta = getAssociatedTokenAddressSync(
|
|
2200
2216
|
quoteMint,
|
|
2201
|
-
this.
|
|
2217
|
+
this.publicKey,
|
|
2202
2218
|
false,
|
|
2203
2219
|
quoteTokenProgramId,
|
|
2204
2220
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2207,9 +2223,9 @@ export class PumpTrader {
|
|
|
2207
2223
|
if (!acc) {
|
|
2208
2224
|
tx.add(
|
|
2209
2225
|
createAssociatedTokenAccountInstruction(
|
|
2210
|
-
this.
|
|
2226
|
+
this.publicKey,
|
|
2211
2227
|
userQuoteAta,
|
|
2212
|
-
this.
|
|
2228
|
+
this.publicKey,
|
|
2213
2229
|
quoteMint,
|
|
2214
2230
|
quoteTokenProgramId,
|
|
2215
2231
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2240,7 +2256,7 @@ export class PumpTrader {
|
|
|
2240
2256
|
bondingCurve: bonding,
|
|
2241
2257
|
associatedBaseBondingCurve,
|
|
2242
2258
|
associatedQuoteBondingCurve,
|
|
2243
|
-
user: this.
|
|
2259
|
+
user: this.publicKey,
|
|
2244
2260
|
associatedBaseUser: userBaseAta,
|
|
2245
2261
|
associatedQuoteUser,
|
|
2246
2262
|
creatorVault,
|
|
@@ -2266,7 +2282,7 @@ export class PumpTrader {
|
|
|
2266
2282
|
if (quoteMint.equals(SOL_MINT)) {
|
|
2267
2283
|
const wsolAta = getAssociatedTokenAddressSync(
|
|
2268
2284
|
SOL_MINT,
|
|
2269
|
-
this.
|
|
2285
|
+
this.publicKey,
|
|
2270
2286
|
false,
|
|
2271
2287
|
TOKEN_PROGRAM_ID,
|
|
2272
2288
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2274,8 +2290,8 @@ export class PumpTrader {
|
|
|
2274
2290
|
tx.add(
|
|
2275
2291
|
createCloseAccountInstruction(
|
|
2276
2292
|
wsolAta,
|
|
2277
|
-
this.
|
|
2278
|
-
this.
|
|
2293
|
+
this.publicKey,
|
|
2294
|
+
this.publicKey,
|
|
2279
2295
|
),
|
|
2280
2296
|
);
|
|
2281
2297
|
}
|
|
@@ -2283,8 +2299,8 @@ export class PumpTrader {
|
|
|
2283
2299
|
const { blockhash, lastValidBlockHeight } =
|
|
2284
2300
|
await this.connection.getLatestBlockhash("finalized");
|
|
2285
2301
|
tx.recentBlockhash = blockhash;
|
|
2286
|
-
tx.feePayer = this.
|
|
2287
|
-
|
|
2302
|
+
tx.feePayer = this.publicKey;
|
|
2303
|
+
await this.signTx(tx);
|
|
2288
2304
|
|
|
2289
2305
|
const signature = await this.connection.sendRawTransaction(
|
|
2290
2306
|
tx.serialize(),
|
|
@@ -2328,12 +2344,12 @@ export class PumpTrader {
|
|
|
2328
2344
|
totalQuoteOut <= tradeOpt.maxSolPerTx
|
|
2329
2345
|
? [totalTokenIn]
|
|
2330
2346
|
: this.splitIntoN(
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2347
|
+
totalTokenIn,
|
|
2348
|
+
Number(
|
|
2349
|
+
(totalQuoteOut + tradeOpt.maxSolPerTx - 1n) /
|
|
2350
|
+
tradeOpt.maxSolPerTx,
|
|
2351
|
+
),
|
|
2352
|
+
);
|
|
2337
2353
|
|
|
2338
2354
|
const pendingTransactions: PendingTransaction[] = [];
|
|
2339
2355
|
const failedTransactions: FailedTransaction[] = [];
|
|
@@ -2369,7 +2385,7 @@ export class PumpTrader {
|
|
|
2369
2385
|
const [userVolumeAccumulator] = PublicKey.findProgramAddressSync(
|
|
2370
2386
|
[
|
|
2371
2387
|
Buffer.from("user_volume_accumulator"),
|
|
2372
|
-
this.
|
|
2388
|
+
this.publicKey.toBuffer(),
|
|
2373
2389
|
],
|
|
2374
2390
|
PROGRAM_IDS.PUMP,
|
|
2375
2391
|
);
|
|
@@ -2406,7 +2422,7 @@ export class PumpTrader {
|
|
|
2406
2422
|
|
|
2407
2423
|
const associatedQuoteUser = getAssociatedTokenAddressSync(
|
|
2408
2424
|
quoteMint,
|
|
2409
|
-
this.
|
|
2425
|
+
this.publicKey,
|
|
2410
2426
|
false,
|
|
2411
2427
|
quoteTokenProgramId,
|
|
2412
2428
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2414,7 +2430,7 @@ export class PumpTrader {
|
|
|
2414
2430
|
|
|
2415
2431
|
const userBaseAta = getAssociatedTokenAddressSync(
|
|
2416
2432
|
baseMint,
|
|
2417
|
-
this.
|
|
2433
|
+
this.publicKey,
|
|
2418
2434
|
false,
|
|
2419
2435
|
baseTokenProgram.programId,
|
|
2420
2436
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2441,7 +2457,7 @@ export class PumpTrader {
|
|
|
2441
2457
|
if (!quoteMint.equals(SOL_MINT)) {
|
|
2442
2458
|
const userQuoteAta = getAssociatedTokenAddressSync(
|
|
2443
2459
|
quoteMint,
|
|
2444
|
-
this.
|
|
2460
|
+
this.publicKey,
|
|
2445
2461
|
false,
|
|
2446
2462
|
quoteTokenProgramId,
|
|
2447
2463
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2450,9 +2466,9 @@ export class PumpTrader {
|
|
|
2450
2466
|
if (!acc) {
|
|
2451
2467
|
tx.add(
|
|
2452
2468
|
createAssociatedTokenAccountInstruction(
|
|
2453
|
-
this.
|
|
2469
|
+
this.publicKey,
|
|
2454
2470
|
userQuoteAta,
|
|
2455
|
-
this.
|
|
2471
|
+
this.publicKey,
|
|
2456
2472
|
quoteMint,
|
|
2457
2473
|
quoteTokenProgramId,
|
|
2458
2474
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -2477,7 +2493,7 @@ export class PumpTrader {
|
|
|
2477
2493
|
bondingCurve: bonding,
|
|
2478
2494
|
associatedBaseBondingCurve,
|
|
2479
2495
|
associatedQuoteBondingCurve,
|
|
2480
|
-
user: this.
|
|
2496
|
+
user: this.publicKey,
|
|
2481
2497
|
associatedBaseUser: userBaseAta,
|
|
2482
2498
|
associatedQuoteUser,
|
|
2483
2499
|
creatorVault,
|
|
@@ -2501,8 +2517,8 @@ export class PumpTrader {
|
|
|
2501
2517
|
const { blockhash, lastValidBlockHeight } =
|
|
2502
2518
|
await this.connection.getLatestBlockhash("finalized");
|
|
2503
2519
|
tx.recentBlockhash = blockhash;
|
|
2504
|
-
tx.feePayer = this.
|
|
2505
|
-
|
|
2520
|
+
tx.feePayer = this.publicKey;
|
|
2521
|
+
await this.signTx(tx);
|
|
2506
2522
|
|
|
2507
2523
|
const signature = await this.connection.sendRawTransaction(
|
|
2508
2524
|
tx.serialize(),
|
|
@@ -2591,8 +2607,8 @@ export class PumpTrader {
|
|
|
2591
2607
|
const { blockhash, lastValidBlockHeight } =
|
|
2592
2608
|
await this.connection.getLatestBlockhash("finalized");
|
|
2593
2609
|
tx.recentBlockhash = blockhash;
|
|
2594
|
-
tx.feePayer = this.
|
|
2595
|
-
|
|
2610
|
+
tx.feePayer = this.publicKey;
|
|
2611
|
+
await this.signTx(tx);
|
|
2596
2612
|
|
|
2597
2613
|
const signature = await this.connection.sendRawTransaction(tx.serialize());
|
|
2598
2614
|
await this.confirmTransactionWithPolling(signature, lastValidBlockHeight);
|
|
@@ -2744,9 +2760,15 @@ export class PumpTrader {
|
|
|
2744
2760
|
}
|
|
2745
2761
|
}
|
|
2746
2762
|
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2763
|
+
/**
|
|
2764
|
+
* 获取原始 wallet 对象(Keypair 或前端 WalletAdapter)
|
|
2765
|
+
*/
|
|
2766
|
+
getWallet(): Wallet {
|
|
2767
|
+
return this._wallet;
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
getPublicKey(): PublicKey {
|
|
2771
|
+
return this.publicKey;
|
|
2750
2772
|
}
|
|
2751
2773
|
|
|
2752
2774
|
getConnection() {
|