@pump-fun/pump-sdk 1.22.1 → 1.24.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/src/sdk.ts CHANGED
@@ -16,7 +16,16 @@ import pumpIdl from "./idl/pump.json";
16
16
  import { Pump } from "./idl/pump";
17
17
  import BN from "bn.js";
18
18
 
19
- import { bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, getGlobalParamsPda, getMayhemStatePda, getSolVaultPda, getTokenVaultPda, pumpPoolAuthorityPda } from "./pda";
19
+ import {
20
+ bondingCurvePda,
21
+ canonicalPumpPoolPda,
22
+ creatorVaultPda,
23
+ getGlobalParamsPda,
24
+ getMayhemStatePda,
25
+ getSolVaultPda,
26
+ getTokenVaultPda,
27
+ pumpPoolAuthorityPda,
28
+ } from "./pda";
20
29
  import {
21
30
  BondingCurve,
22
31
  FeeConfig,
@@ -30,30 +39,30 @@ import { OFFLINE_PUMP_PROGRAM } from "./onlineSdk";
30
39
  export function getPumpProgram(connection: Connection): Program<Pump> {
31
40
  return new Program(
32
41
  pumpIdl as Pump,
33
- new AnchorProvider(connection, null as any, {}),
42
+ new AnchorProvider(connection, null as any, {})
34
43
  );
35
44
  }
36
45
 
37
46
  export const PUMP_PROGRAM_ID = new PublicKey(
38
- "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P",
47
+ "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
39
48
  );
40
49
 
41
50
  export const PUMP_AMM_PROGRAM_ID = new PublicKey(
42
- "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
51
+ "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"
43
52
  );
44
53
 
45
54
  export const MAYHEM_PROGRAM_ID = new PublicKey(
46
- "MAyhSmzXzV1pTf7LsNkrNwkWKTo4ougAJ1PPg47MD4e",
55
+ "MAyhSmzXzV1pTf7LsNkrNwkWKTo4ougAJ1PPg47MD4e"
47
56
  );
48
57
 
49
58
  export const PUMP_FEE_PROGRAM_ID = new PublicKey(
50
- "pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ",
59
+ "pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ"
51
60
  );
52
61
 
53
62
  export const BONDING_CURVE_NEW_SIZE = 151;
54
63
 
55
64
  export const PUMP_TOKEN_MINT = new PublicKey(
56
- "pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn",
65
+ "pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn"
57
66
  );
58
67
 
59
68
  export class PumpSdk {
@@ -66,28 +75,39 @@ export class PumpSdk {
66
75
  decodeGlobal(accountInfo: AccountInfo<Buffer>): Global {
67
76
  return this.offlinePumpProgram.coder.accounts.decode<Global>(
68
77
  "global",
69
- accountInfo.data,
78
+ accountInfo.data
70
79
  );
71
80
  }
72
81
 
73
82
  decodeFeeConfig(accountInfo: AccountInfo<Buffer>): FeeConfig {
74
83
  return this.offlinePumpProgram.coder.accounts.decode<FeeConfig>(
75
84
  "feeConfig",
76
- accountInfo.data,
85
+ accountInfo.data
77
86
  );
78
87
  }
79
88
 
80
89
  decodeBondingCurve(accountInfo: AccountInfo<Buffer>): BondingCurve {
81
90
  return this.offlinePumpProgram.coder.accounts.decode<BondingCurve>(
82
91
  "bondingCurve",
83
- accountInfo.data,
92
+ accountInfo.data
84
93
  );
85
94
  }
86
95
 
87
96
  decodeBondingCurveNullable(
88
- accountInfo: AccountInfo<Buffer>,
97
+ accountInfo: AccountInfo<Buffer>
89
98
  ): BondingCurve | null {
90
99
  try {
100
+ let data = accountInfo.data;
101
+ // Ensure buffer is at least 82 bytes
102
+ if (data.length < 82) {
103
+ const padded = Buffer.alloc(82);
104
+ data.copy(padded);
105
+ accountInfo = {
106
+ ...accountInfo,
107
+ data: padded,
108
+ };
109
+ }
110
+
91
111
  return this.decodeBondingCurve(accountInfo);
92
112
  } catch (e) {
93
113
  console.warn("Failed to decode bonding curve", e);
@@ -96,25 +116,25 @@ export class PumpSdk {
96
116
  }
97
117
 
98
118
  decodeGlobalVolumeAccumulator(
99
- accountInfo: AccountInfo<Buffer>,
119
+ accountInfo: AccountInfo<Buffer>
100
120
  ): GlobalVolumeAccumulator {
101
121
  return this.offlinePumpProgram.coder.accounts.decode<GlobalVolumeAccumulator>(
102
122
  "globalVolumeAccumulator",
103
- accountInfo.data,
123
+ accountInfo.data
104
124
  );
105
125
  }
106
126
 
107
127
  decodeUserVolumeAccumulator(
108
- accountInfo: AccountInfo<Buffer>,
128
+ accountInfo: AccountInfo<Buffer>
109
129
  ): UserVolumeAccumulator {
110
130
  return this.offlinePumpProgram.coder.accounts.decode<UserVolumeAccumulator>(
111
131
  "userVolumeAccumulator",
112
- accountInfo.data,
132
+ accountInfo.data
113
133
  );
114
134
  }
115
135
 
116
136
  decodeUserVolumeAccumulatorNullable(
117
- accountInfo: AccountInfo<Buffer>,
137
+ accountInfo: AccountInfo<Buffer>
118
138
  ): UserVolumeAccumulator | null {
119
139
  try {
120
140
  return this.decodeUserVolumeAccumulator(accountInfo);
@@ -159,7 +179,7 @@ export class PumpSdk {
159
179
  uri,
160
180
  creator,
161
181
  user,
162
- mayhemMode
182
+ mayhemMode,
163
183
  }: {
164
184
  mint: PublicKey;
165
185
  name: string;
@@ -214,11 +234,16 @@ export class PumpSdk {
214
234
  await this.extendAccountInstruction({
215
235
  account: bondingCurvePda(mint),
216
236
  user,
217
- }),
237
+ })
218
238
  );
219
239
  }
220
240
 
221
- const associatedUser = getAssociatedTokenAddressSync(mint, user, true, tokenProgram);
241
+ const associatedUser = getAssociatedTokenAddressSync(
242
+ mint,
243
+ user,
244
+ true,
245
+ tokenProgram
246
+ );
222
247
 
223
248
  if (!associatedUserAccountInfo) {
224
249
  instructions.push(
@@ -228,7 +253,7 @@ export class PumpSdk {
228
253
  user,
229
254
  mint,
230
255
  tokenProgram
231
- ),
256
+ )
232
257
  );
233
258
  }
234
259
 
@@ -244,7 +269,7 @@ export class PumpSdk {
244
269
  slippage,
245
270
  tokenProgram,
246
271
  mayhemMode: bondingCurve.isMayhemMode,
247
- }),
272
+ })
248
273
  );
249
274
 
250
275
  return instructions;
@@ -273,9 +298,22 @@ export class PumpSdk {
273
298
  solAmount: BN;
274
299
  mayhemMode: boolean;
275
300
  }): Promise<TransactionInstruction[]> {
276
- const associatedUser = getAssociatedTokenAddressSync(mint, user, true, TOKEN_2022_PROGRAM_ID);
301
+ const associatedUser = getAssociatedTokenAddressSync(
302
+ mint,
303
+ user,
304
+ true,
305
+ TOKEN_2022_PROGRAM_ID
306
+ );
277
307
  return [
278
- await this.createV2Instruction({ mint, name, symbol, uri, creator, user, mayhemMode }),
308
+ await this.createV2Instruction({
309
+ mint,
310
+ name,
311
+ symbol,
312
+ uri,
313
+ creator,
314
+ user,
315
+ mayhemMode,
316
+ }),
279
317
  await this.extendAccountInstruction({
280
318
  account: bondingCurvePda(mint),
281
319
  user,
@@ -285,7 +323,7 @@ export class PumpSdk {
285
323
  associatedUser,
286
324
  user,
287
325
  mint,
288
- TOKEN_2022_PROGRAM_ID,
326
+ TOKEN_2022_PROGRAM_ID
289
327
  ),
290
328
  await this.buyInstruction({
291
329
  global,
@@ -337,7 +375,7 @@ export class PumpSdk {
337
375
  user,
338
376
  associatedUser,
339
377
  user,
340
- mint,
378
+ mint
341
379
  ),
342
380
  await this.buyInstruction({
343
381
  global,
@@ -385,7 +423,7 @@ export class PumpSdk {
385
423
  feeRecipient: getFeeRecipient(global, mayhemMode),
386
424
  amount,
387
425
  solAmount: solAmount.add(
388
- solAmount.mul(new BN(Math.floor(slippage * 10))).div(new BN(1000)),
426
+ solAmount.mul(new BN(Math.floor(slippage * 10))).div(new BN(1000))
389
427
  ),
390
428
  tokenProgram,
391
429
  });
@@ -401,7 +439,7 @@ export class PumpSdk {
401
439
  solAmount,
402
440
  slippage,
403
441
  tokenProgram = TOKEN_PROGRAM_ID,
404
- mayhemMode = false
442
+ mayhemMode = false,
405
443
  }: {
406
444
  global: Global;
407
445
  bondingCurveAccountInfo: AccountInfo<Buffer>;
@@ -421,7 +459,7 @@ export class PumpSdk {
421
459
  await this.extendAccountInstruction({
422
460
  account: bondingCurvePda(mint),
423
461
  user,
424
- }),
462
+ })
425
463
  );
426
464
  }
427
465
 
@@ -433,10 +471,10 @@ export class PumpSdk {
433
471
  feeRecipient: getFeeRecipient(global, mayhemMode),
434
472
  amount,
435
473
  solAmount: solAmount.sub(
436
- solAmount.mul(new BN(Math.floor(slippage * 10))).div(new BN(1000)),
474
+ solAmount.mul(new BN(Math.floor(slippage * 10))).div(new BN(1000))
437
475
  ),
438
476
  tokenProgram,
439
- }),
477
+ })
440
478
  );
441
479
 
442
480
  return instructions;
@@ -462,21 +500,36 @@ export class PumpSdk {
462
500
  withdrawAuthority,
463
501
  mint,
464
502
  user,
465
- tokenProgram = TOKEN_PROGRAM_ID
503
+ tokenProgram = TOKEN_PROGRAM_ID,
466
504
  }: {
467
505
  withdrawAuthority: PublicKey;
468
506
  mint: PublicKey;
469
507
  user: PublicKey;
470
508
  tokenProgram: PublicKey;
471
509
  }): Promise<TransactionInstruction> {
472
- const bondingCurve = bondingCurvePda(mint)
473
- const associatedBondingCurve = getAssociatedTokenAddressSync(mint, bondingCurve, true, tokenProgram)
510
+ const bondingCurve = bondingCurvePda(mint);
511
+ const associatedBondingCurve = getAssociatedTokenAddressSync(
512
+ mint,
513
+ bondingCurve,
514
+ true,
515
+ tokenProgram
516
+ );
474
517
 
475
518
  const poolAuthority = pumpPoolAuthorityPda(mint);
476
- const poolAuthorityMintAccount = getAssociatedTokenAddressSync(mint, poolAuthority, true, tokenProgram)
519
+ const poolAuthorityMintAccount = getAssociatedTokenAddressSync(
520
+ mint,
521
+ poolAuthority,
522
+ true,
523
+ tokenProgram
524
+ );
477
525
 
478
526
  const pool = canonicalPumpPoolPda(mint);
479
- const poolBaseTokenAccount = getAssociatedTokenAddressSync(mint, pool, true, tokenProgram)
527
+ const poolBaseTokenAccount = getAssociatedTokenAddressSync(
528
+ mint,
529
+ pool,
530
+ true,
531
+ tokenProgram
532
+ );
480
533
  return this.offlinePumpProgram.methods
481
534
  .migrate()
482
535
  .accountsPartial({
@@ -485,13 +538,13 @@ export class PumpSdk {
485
538
  withdrawAuthority,
486
539
  associatedBondingCurve,
487
540
  poolAuthorityMintAccount,
488
- poolBaseTokenAccount
541
+ poolBaseTokenAccount,
489
542
  })
490
543
  .instruction();
491
544
  }
492
545
 
493
546
  async syncUserVolumeAccumulator(
494
- user: PublicKey,
547
+ user: PublicKey
495
548
  ): Promise<TransactionInstruction> {
496
549
  return await this.offlinePumpProgram.methods
497
550
  .syncUserVolumeAccumulator()
@@ -500,7 +553,7 @@ export class PumpSdk {
500
553
  }
501
554
 
502
555
  async syncUserVolumeAccumulatorBothPrograms(
503
- user: PublicKey,
556
+ user: PublicKey
504
557
  ): Promise<TransactionInstruction[]> {
505
558
  return [
506
559
  await this.syncUserVolumeAccumulator(user),
@@ -540,7 +593,7 @@ export class PumpSdk {
540
593
  }
541
594
 
542
595
  async closeUserVolumeAccumulator(
543
- user: PublicKey,
596
+ user: PublicKey
544
597
  ): Promise<TransactionInstruction> {
545
598
  return await this.offlinePumpProgram.methods
546
599
  .closeUserVolumeAccumulator()
@@ -567,7 +620,12 @@ export class PumpSdk {
567
620
  }): Promise<TransactionInstruction> {
568
621
  return await this.getBuyInstructionInternal({
569
622
  user,
570
- associatedUser: getAssociatedTokenAddressSync(mint, user, true, tokenProgram),
623
+ associatedUser: getAssociatedTokenAddressSync(
624
+ mint,
625
+ user,
626
+ true,
627
+ tokenProgram
628
+ ),
571
629
  mint,
572
630
  creator,
573
631
  feeRecipient,
@@ -632,7 +690,7 @@ export class PumpSdk {
632
690
  feeRecipient,
633
691
  amount,
634
692
  solAmount,
635
- tokenProgram
693
+ tokenProgram,
636
694
  });
637
695
  }
638
696
 
@@ -658,10 +716,15 @@ export class PumpSdk {
658
716
  .accountsPartial({
659
717
  feeRecipient,
660
718
  mint,
661
- associatedUser: getAssociatedTokenAddressSync(mint, user, true, tokenProgram),
719
+ associatedUser: getAssociatedTokenAddressSync(
720
+ mint,
721
+ user,
722
+ true,
723
+ tokenProgram
724
+ ),
662
725
  user,
663
726
  creatorVault: creatorVaultPda(creator),
664
- tokenProgram: tokenProgram
727
+ tokenProgram: tokenProgram,
665
728
  })
666
729
  .instruction();
667
730
  }
@@ -669,12 +732,18 @@ export class PumpSdk {
669
732
 
670
733
  export const PUMP_SDK = new PumpSdk();
671
734
 
672
- export function getFeeRecipient(global: Global, mayhemMode: boolean): PublicKey {
735
+ export function getFeeRecipient(
736
+ global: Global,
737
+ mayhemMode: boolean
738
+ ): PublicKey {
673
739
  if (mayhemMode) {
674
- const feeRecipients = [global.reservedFeeRecipient, ...global.reservedFeeRecipients];
740
+ const feeRecipients = [
741
+ global.reservedFeeRecipient,
742
+ ...global.reservedFeeRecipients,
743
+ ];
675
744
  return feeRecipients[Math.floor(Math.random() * feeRecipients.length)];
676
745
  } else {
677
- const feeRecipients = [global.feeRecipient, ...global.feeRecipients,];
746
+ const feeRecipients = [global.feeRecipient, ...global.feeRecipients];
678
747
  return feeRecipients[Math.floor(Math.random() * feeRecipients.length)];
679
748
  }
680
749
  }