pump-trader 1.0.8 → 1.1.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/dist/index.d.ts +1 -0
- package/dist/index.js +12 -11
- package/index.js +16 -13
- package/index.ts +16 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -158,6 +158,7 @@ export declare class PumpTrader {
|
|
|
158
158
|
protocolFeeRecipients: PublicKey[];
|
|
159
159
|
};
|
|
160
160
|
getAmmPoolReserves(poolKeys: any): Promise<PoolReserves>;
|
|
161
|
+
deriveAmmPoolV2(baseMint: PublicKey): PublicKey;
|
|
161
162
|
createAmmBuyInstruction(poolInfo: PoolInfo, userBaseAta: PublicKey, userQuoteAta: PublicKey, baseAmountOut: bigint, maxQuoteAmountIn: bigint, tokenProgramId: PublicKey): TransactionInstruction;
|
|
162
163
|
createAmmSellInstruction(poolInfo: PoolInfo, userBaseAta: PublicKey, userQuoteAta: PublicKey, baseAmountIn: bigint, minQuoteAmountOut: bigint, tokenProgramId: PublicKey): TransactionInstruction;
|
|
163
164
|
confirmTransactionWithPolling(signature: string, lastValidBlockHeight: number, maxAttempts?: number, delayMs?: number): Promise<string>;
|
package/dist/index.js
CHANGED
|
@@ -605,6 +605,7 @@ class PumpTrader {
|
|
|
605
605
|
async ammBuy(tokenAddr, totalSolIn, tradeOpt) {
|
|
606
606
|
const mint = new web3_js_1.PublicKey(tokenAddr);
|
|
607
607
|
const poolInfo = await this.getAmmPoolInfo(mint);
|
|
608
|
+
const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
|
|
608
609
|
const solChunks = this.splitByMax(totalSolIn, tradeOpt.maxSolPerTx);
|
|
609
610
|
const tokenProgram = await this.detectTokenProgram(tokenAddr);
|
|
610
611
|
const pendingTransactions = [];
|
|
@@ -612,16 +613,13 @@ class PumpTrader {
|
|
|
612
613
|
for (let i = 0; i < solChunks.length; i++) {
|
|
613
614
|
try {
|
|
614
615
|
const solIn = solChunks[i];
|
|
615
|
-
const
|
|
616
|
-
const
|
|
616
|
+
const baseAmountOut = this.calculateAmmBuyOutput(solIn, reserves);
|
|
617
|
+
const slippageBps = this.calcSlippage({
|
|
617
618
|
tradeSize: solIn,
|
|
618
619
|
reserve: reserves.quoteAmount,
|
|
619
620
|
slippageOpt: tradeOpt.slippage
|
|
620
621
|
});
|
|
621
|
-
const slippageBps = Math.max(0, Math.min(rawSlippageBps, 9000));
|
|
622
622
|
const maxQuoteIn = (solIn * BigInt(10_000 + slippageBps)) / 10000n;
|
|
623
|
-
const estimatedBaseOut = this.calculateAmmBuyOutput(solIn, reserves);
|
|
624
|
-
const baseAmountOut = ((estimatedBaseOut * BigInt(10_000 - slippageBps)) / 10000n) || 1n;
|
|
625
623
|
const priority = this.genPriority(tradeOpt.priority);
|
|
626
624
|
const tx = new web3_js_1.Transaction().add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 300_000 }), web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priority }));
|
|
627
625
|
const userBaseAta = await this.ensureAta(tx, poolInfo.poolKeys.baseMint, tokenProgram.programId);
|
|
@@ -750,11 +748,13 @@ class PumpTrader {
|
|
|
750
748
|
quoteDecimals: quoteInfo.value.decimals
|
|
751
749
|
};
|
|
752
750
|
}
|
|
751
|
+
deriveAmmPoolV2(baseMint) {
|
|
752
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("pool-v2"), baseMint.toBuffer()], PROGRAM_IDS.PUMP_AMM)[0];
|
|
753
|
+
}
|
|
753
754
|
/* ---------- AMM 指令构建 ---------- */
|
|
754
755
|
createAmmBuyInstruction(poolInfo, userBaseAta, userQuoteAta, baseAmountOut, maxQuoteAmountIn, tokenProgramId) {
|
|
755
756
|
const { pool, poolKeys, globalConfig } = poolInfo;
|
|
756
|
-
const
|
|
757
|
-
const [bondingCurveV2] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("bonding-curve-v2"), bondingCurveV2Mint.toBuffer()], PROGRAM_IDS.PUMP);
|
|
757
|
+
const poolV2 = this.deriveAmmPoolV2(poolKeys.baseMint);
|
|
758
758
|
const [eventAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("__event_authority")], PROGRAM_IDS.PUMP_AMM);
|
|
759
759
|
const [coinCreatorVaultAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("creator_vault"), poolKeys.coinCreator.toBuffer()], PROGRAM_IDS.PUMP_AMM);
|
|
760
760
|
const coinCreatorVaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(SOL_MINT, coinCreatorVaultAuthority, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
@@ -789,19 +789,19 @@ class PumpTrader {
|
|
|
789
789
|
{ pubkey: userVolumeAccumulator, isSigner: false, isWritable: true },
|
|
790
790
|
{ pubkey: feeConfig, isSigner: false, isWritable: false },
|
|
791
791
|
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
|
|
792
|
-
{ pubkey:
|
|
792
|
+
{ pubkey: poolV2, isSigner: false, isWritable: false }
|
|
793
793
|
],
|
|
794
794
|
data: Buffer.concat([
|
|
795
795
|
DISCRIMINATORS.BUY,
|
|
796
796
|
u64(baseAmountOut),
|
|
797
797
|
u64(maxQuoteAmountIn),
|
|
798
|
-
|
|
799
|
-
Buffer.from([1])
|
|
798
|
+
Buffer.from([1, 1])
|
|
800
799
|
])
|
|
801
800
|
});
|
|
802
801
|
}
|
|
803
802
|
createAmmSellInstruction(poolInfo, userBaseAta, userQuoteAta, baseAmountIn, minQuoteAmountOut, tokenProgramId) {
|
|
804
803
|
const { pool, poolKeys, globalConfig } = poolInfo;
|
|
804
|
+
const poolV2 = this.deriveAmmPoolV2(poolKeys.baseMint);
|
|
805
805
|
const [eventAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("__event_authority")], PROGRAM_IDS.PUMP_AMM);
|
|
806
806
|
const [coinCreatorVaultAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("creator_vault"), poolKeys.coinCreator.toBuffer()], PROGRAM_IDS.PUMP_AMM);
|
|
807
807
|
const coinCreatorVaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(SOL_MINT, coinCreatorVaultAuthority, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
@@ -831,7 +831,8 @@ class PumpTrader {
|
|
|
831
831
|
{ pubkey: coinCreatorVaultAta, isSigner: false, isWritable: true },
|
|
832
832
|
{ pubkey: coinCreatorVaultAuthority, isSigner: false, isWritable: false },
|
|
833
833
|
{ pubkey: feeConfig, isSigner: false, isWritable: false },
|
|
834
|
-
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
|
|
834
|
+
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
|
|
835
|
+
{ pubkey: poolV2, isSigner: false, isWritable: false }
|
|
835
836
|
],
|
|
836
837
|
data: Buffer.concat([
|
|
837
838
|
DISCRIMINATORS.SELL,
|
package/index.js
CHANGED
|
@@ -836,6 +836,7 @@ export class PumpTrader {
|
|
|
836
836
|
async ammBuy(tokenAddr, totalSolIn, tradeOpt) {
|
|
837
837
|
const mint = new PublicKey(tokenAddr);
|
|
838
838
|
const poolInfo = await this.getAmmPoolInfo(mint);
|
|
839
|
+
const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
|
|
839
840
|
const solChunks = this.splitByMax(totalSolIn, tradeOpt.maxSolPerTx);
|
|
840
841
|
const tokenProgram = await this.detectTokenProgram(tokenAddr);
|
|
841
842
|
const pendingTransactions = [];
|
|
@@ -844,16 +845,13 @@ export class PumpTrader {
|
|
|
844
845
|
for (let i = 0; i < solChunks.length; i++) {
|
|
845
846
|
try {
|
|
846
847
|
const solIn = solChunks[i];
|
|
847
|
-
const
|
|
848
|
-
const
|
|
848
|
+
const baseAmountOut = this.calculateAmmBuyOutput(solIn, reserves);
|
|
849
|
+
const slippageBps = this.calcSlippage({
|
|
849
850
|
tradeSize: solIn,
|
|
850
851
|
reserve: reserves.quoteAmount,
|
|
851
852
|
slippageOpt: tradeOpt.slippage
|
|
852
853
|
});
|
|
853
|
-
const slippageBps = Math.max(0, Math.min(rawSlippageBps, 9000));
|
|
854
854
|
const maxQuoteIn = (solIn * BigInt(10_000 + slippageBps)) / 10_000n;
|
|
855
|
-
const estimatedBaseOut = this.calculateAmmBuyOutput(solIn, reserves);
|
|
856
|
-
const baseAmountOut = ((estimatedBaseOut * BigInt(10_000 - slippageBps)) / 10_000n) || 1n;
|
|
857
855
|
const priority = this.genPriority(tradeOpt.priority);
|
|
858
856
|
|
|
859
857
|
const tx = new Transaction().add(
|
|
@@ -1066,15 +1064,18 @@ export class PumpTrader {
|
|
|
1066
1064
|
};
|
|
1067
1065
|
}
|
|
1068
1066
|
|
|
1067
|
+
deriveAmmPoolV2(baseMint) {
|
|
1068
|
+
return PublicKey.findProgramAddressSync(
|
|
1069
|
+
[Buffer.from("pool-v2"), baseMint.toBuffer()],
|
|
1070
|
+
PROGRAM_IDS.PUMP_AMM
|
|
1071
|
+
)[0];
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1069
1074
|
/* ---------- AMM 指令构建 ---------- */
|
|
1070
1075
|
|
|
1071
1076
|
createAmmBuyInstruction(poolInfo, userBaseAta, userQuoteAta, baseAmountOut, maxQuoteAmountIn, tokenProgramId) {
|
|
1072
1077
|
const { pool, poolKeys, globalConfig } = poolInfo;
|
|
1073
|
-
const
|
|
1074
|
-
const [bondingCurveV2] = PublicKey.findProgramAddressSync(
|
|
1075
|
-
[Buffer.from("bonding-curve-v2"), bondingCurveV2Mint.toBuffer()],
|
|
1076
|
-
PROGRAM_IDS.PUMP
|
|
1077
|
-
);
|
|
1078
|
+
const poolV2 = this.deriveAmmPoolV2(poolKeys.baseMint);
|
|
1078
1079
|
|
|
1079
1080
|
const [eventAuthority] = PublicKey.findProgramAddressSync(
|
|
1080
1081
|
[Buffer.from("__event_authority")],
|
|
@@ -1144,19 +1145,20 @@ export class PumpTrader {
|
|
|
1144
1145
|
{ pubkey: userVolumeAccumulator, isSigner: false, isWritable: true },
|
|
1145
1146
|
{ pubkey: feeConfig, isSigner: false, isWritable: false },
|
|
1146
1147
|
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
|
|
1147
|
-
{ pubkey:
|
|
1148
|
+
{ pubkey: poolV2, isSigner: false, isWritable: false }
|
|
1148
1149
|
],
|
|
1149
1150
|
data: Buffer.concat([
|
|
1150
1151
|
DISCRIMINATORS.BUY,
|
|
1151
1152
|
u64(baseAmountOut),
|
|
1152
1153
|
u64(maxQuoteAmountIn),
|
|
1153
|
-
Buffer.from([1])
|
|
1154
|
+
Buffer.from([1, 1])
|
|
1154
1155
|
])
|
|
1155
1156
|
});
|
|
1156
1157
|
}
|
|
1157
1158
|
|
|
1158
1159
|
createAmmSellInstruction(poolInfo, userBaseAta, userQuoteAta, baseAmountIn, minQuoteAmountOut, tokenProgramId) {
|
|
1159
1160
|
const { pool, poolKeys, globalConfig } = poolInfo;
|
|
1161
|
+
const poolV2 = this.deriveAmmPoolV2(poolKeys.baseMint);
|
|
1160
1162
|
|
|
1161
1163
|
const [eventAuthority] = PublicKey.findProgramAddressSync(
|
|
1162
1164
|
[Buffer.from("__event_authority")],
|
|
@@ -1213,7 +1215,8 @@ export class PumpTrader {
|
|
|
1213
1215
|
{ pubkey: coinCreatorVaultAta, isSigner: false, isWritable: true },
|
|
1214
1216
|
{ pubkey: coinCreatorVaultAuthority, isSigner: false, isWritable: false },
|
|
1215
1217
|
{ pubkey: feeConfig, isSigner: false, isWritable: false },
|
|
1216
|
-
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
|
|
1218
|
+
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
|
|
1219
|
+
{ pubkey: poolV2, isSigner: false, isWritable: false }
|
|
1217
1220
|
],
|
|
1218
1221
|
data: Buffer.concat([
|
|
1219
1222
|
DISCRIMINATORS.SELL,
|
package/index.ts
CHANGED
|
@@ -943,6 +943,7 @@ export class PumpTrader {
|
|
|
943
943
|
async ammBuy(tokenAddr: string, totalSolIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult> {
|
|
944
944
|
const mint = new PublicKey(tokenAddr);
|
|
945
945
|
const poolInfo = await this.getAmmPoolInfo(mint);
|
|
946
|
+
const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
|
|
946
947
|
const solChunks = this.splitByMax(totalSolIn, tradeOpt.maxSolPerTx);
|
|
947
948
|
const tokenProgram = await this.detectTokenProgram(tokenAddr);
|
|
948
949
|
const pendingTransactions: PendingTransaction[] = [];
|
|
@@ -951,16 +952,13 @@ export class PumpTrader {
|
|
|
951
952
|
for (let i = 0; i < solChunks.length; i++) {
|
|
952
953
|
try {
|
|
953
954
|
const solIn = solChunks[i];
|
|
954
|
-
const
|
|
955
|
-
const
|
|
955
|
+
const baseAmountOut = this.calculateAmmBuyOutput(solIn, reserves);
|
|
956
|
+
const slippageBps = this.calcSlippage({
|
|
956
957
|
tradeSize: solIn,
|
|
957
958
|
reserve: reserves.quoteAmount,
|
|
958
959
|
slippageOpt: tradeOpt.slippage
|
|
959
960
|
});
|
|
960
|
-
const slippageBps = Math.max(0, Math.min(rawSlippageBps, 9000));
|
|
961
961
|
const maxQuoteIn = (solIn * BigInt(10_000 + slippageBps)) / 10_000n;
|
|
962
|
-
const estimatedBaseOut = this.calculateAmmBuyOutput(solIn, reserves);
|
|
963
|
-
const baseAmountOut = ((estimatedBaseOut * BigInt(10_000 - slippageBps)) / 10_000n) || 1n;
|
|
964
962
|
const priority = this.genPriority(tradeOpt.priority);
|
|
965
963
|
|
|
966
964
|
const tx = new Transaction().add(
|
|
@@ -1172,6 +1170,13 @@ export class PumpTrader {
|
|
|
1172
1170
|
};
|
|
1173
1171
|
}
|
|
1174
1172
|
|
|
1173
|
+
deriveAmmPoolV2(baseMint: PublicKey): PublicKey {
|
|
1174
|
+
return PublicKey.findProgramAddressSync(
|
|
1175
|
+
[Buffer.from("pool-v2"), baseMint.toBuffer()],
|
|
1176
|
+
PROGRAM_IDS.PUMP_AMM
|
|
1177
|
+
)[0];
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1175
1180
|
/* ---------- AMM 指令构建 ---------- */
|
|
1176
1181
|
|
|
1177
1182
|
createAmmBuyInstruction(
|
|
@@ -1183,11 +1188,7 @@ export class PumpTrader {
|
|
|
1183
1188
|
tokenProgramId: PublicKey
|
|
1184
1189
|
): TransactionInstruction {
|
|
1185
1190
|
const { pool, poolKeys, globalConfig } = poolInfo;
|
|
1186
|
-
const
|
|
1187
|
-
const [bondingCurveV2] = PublicKey.findProgramAddressSync(
|
|
1188
|
-
[Buffer.from("bonding-curve-v2"), bondingCurveV2Mint.toBuffer()],
|
|
1189
|
-
PROGRAM_IDS.PUMP
|
|
1190
|
-
);
|
|
1191
|
+
const poolV2 = this.deriveAmmPoolV2(poolKeys.baseMint);
|
|
1191
1192
|
|
|
1192
1193
|
const [eventAuthority] = PublicKey.findProgramAddressSync(
|
|
1193
1194
|
[Buffer.from("__event_authority")],
|
|
@@ -1257,14 +1258,13 @@ export class PumpTrader {
|
|
|
1257
1258
|
{ pubkey: userVolumeAccumulator, isSigner: false, isWritable: true },
|
|
1258
1259
|
{ pubkey: feeConfig, isSigner: false, isWritable: false },
|
|
1259
1260
|
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
|
|
1260
|
-
{ pubkey:
|
|
1261
|
+
{ pubkey: poolV2, isSigner: false, isWritable: false }
|
|
1261
1262
|
],
|
|
1262
1263
|
data: Buffer.concat([
|
|
1263
1264
|
DISCRIMINATORS.BUY,
|
|
1264
1265
|
u64(baseAmountOut),
|
|
1265
1266
|
u64(maxQuoteAmountIn),
|
|
1266
|
-
|
|
1267
|
-
Buffer.from([1])
|
|
1267
|
+
Buffer.from([1, 1])
|
|
1268
1268
|
])
|
|
1269
1269
|
});
|
|
1270
1270
|
}
|
|
@@ -1278,6 +1278,7 @@ export class PumpTrader {
|
|
|
1278
1278
|
tokenProgramId: PublicKey
|
|
1279
1279
|
): TransactionInstruction {
|
|
1280
1280
|
const { pool, poolKeys, globalConfig } = poolInfo;
|
|
1281
|
+
const poolV2 = this.deriveAmmPoolV2(poolKeys.baseMint);
|
|
1281
1282
|
|
|
1282
1283
|
const [eventAuthority] = PublicKey.findProgramAddressSync(
|
|
1283
1284
|
[Buffer.from("__event_authority")],
|
|
@@ -1334,7 +1335,8 @@ export class PumpTrader {
|
|
|
1334
1335
|
{ pubkey: coinCreatorVaultAta, isSigner: false, isWritable: true },
|
|
1335
1336
|
{ pubkey: coinCreatorVaultAuthority, isSigner: false, isWritable: false },
|
|
1336
1337
|
{ pubkey: feeConfig, isSigner: false, isWritable: false },
|
|
1337
|
-
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
|
|
1338
|
+
{ pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
|
|
1339
|
+
{ pubkey: poolV2, isSigner: false, isWritable: false }
|
|
1338
1340
|
],
|
|
1339
1341
|
data: Buffer.concat([
|
|
1340
1342
|
DISCRIMINATORS.SELL,
|