@pump-fun/pump-sdk 1.18.4 → 1.18.6

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
@@ -1,41 +1,29 @@
1
1
  import { AnchorProvider, Program } from "@coral-xyz/anchor";
2
- import { PumpAmmAdminSdk, PumpAmmSdk } from "@pump-fun/pump-swap-sdk";
2
+ import { PUMP_AMM_SDK } from "@pump-fun/pump-swap-sdk";
3
3
  import {
4
4
  createAssociatedTokenAccountIdempotentInstruction,
5
5
  getAssociatedTokenAddressSync,
6
- NATIVE_MINT,
7
- TOKEN_2022_PROGRAM_ID,
8
- TOKEN_PROGRAM_ID,
9
6
  } from "@solana/spl-token";
10
7
  import {
11
8
  AccountInfo,
12
9
  Connection,
13
10
  PublicKey,
14
- PublicKeyInitData,
15
11
  TransactionInstruction,
16
12
  } from "@solana/web3.js";
17
13
  import pumpIdl from "./idl/pump.json";
18
14
  import { Pump } from "./idl/pump";
19
15
  import BN from "bn.js";
20
16
 
21
- import {
22
- bondingCurvePda,
23
- creatorVaultPda,
24
- pumpFeeConfigPda,
25
- globalPda,
26
- globalVolumeAccumulatorPda,
27
- userVolumeAccumulatorPda,
28
- } from "./pda";
17
+ import { bondingCurvePda, creatorVaultPda } from "./pda";
29
18
  import {
30
19
  BondingCurve,
31
20
  FeeConfig,
32
21
  Global,
33
22
  GlobalVolumeAccumulator,
34
23
  UserVolumeAccumulator,
35
- UserVolumeAccumulatorTotalStats,
36
24
  } from "./state";
37
- import { currentDayTokens, totalUnclaimedTokens } from "./tokenIncentives";
38
25
  import { getStaticRandomFeeRecipient } from "./bondingCurve";
26
+ import { OFFLINE_PUMP_PROGRAM } from "./onlineSdk";
39
27
 
40
28
  export function getPumpProgram(connection: Connection): Program<Pump> {
41
29
  return new Program(
@@ -63,24 +51,10 @@ export const PUMP_TOKEN_MINT = new PublicKey(
63
51
  );
64
52
 
65
53
  export class PumpSdk {
66
- private readonly connection: Connection;
67
- private readonly pumpProgram: Program<Pump>;
68
54
  private readonly offlinePumpProgram: Program<Pump>;
69
- private readonly pumpAmmSdk: PumpAmmSdk;
70
- private readonly pumpAmmAdminSdk: PumpAmmAdminSdk;
71
-
72
- constructor(connection: Connection) {
73
- this.connection = connection;
74
-
75
- this.pumpProgram = getPumpProgram(connection);
76
- this.offlinePumpProgram = getPumpProgram(null as any as Connection);
77
-
78
- this.pumpAmmSdk = new PumpAmmSdk(connection);
79
- this.pumpAmmAdminSdk = new PumpAmmAdminSdk(connection);
80
- }
81
55
 
82
- programId(): PublicKey {
83
- return this.offlinePumpProgram.programId;
56
+ constructor() {
57
+ this.offlinePumpProgram = OFFLINE_PUMP_PROGRAM;
84
58
  }
85
59
 
86
60
  decodeGlobal(accountInfo: AccountInfo<Buffer>): Global {
@@ -144,105 +118,6 @@ export class PumpSdk {
144
118
  }
145
119
  }
146
120
 
147
- async fetchGlobal(): Promise<Global> {
148
- return await this.pumpProgram.account.global.fetch(globalPda());
149
- }
150
-
151
- async fetchFeeConfig(): Promise<FeeConfig> {
152
- return await this.pumpProgram.account.feeConfig.fetch(pumpFeeConfigPda());
153
- }
154
-
155
- async fetchBondingCurve(mint: PublicKeyInitData): Promise<BondingCurve> {
156
- return await this.pumpProgram.account.bondingCurve.fetch(
157
- bondingCurvePda(mint),
158
- );
159
- }
160
-
161
- async fetchBuyState(mint: PublicKey, user: PublicKey) {
162
- const [bondingCurveAccountInfo, associatedUserAccountInfo] =
163
- await this.connection.getMultipleAccountsInfo([
164
- bondingCurvePda(mint),
165
- getAssociatedTokenAddressSync(mint, user, true),
166
- ]);
167
-
168
- if (!bondingCurveAccountInfo) {
169
- throw new Error(
170
- `Bonding curve account not found for mint: ${mint.toBase58()}`,
171
- );
172
- }
173
-
174
- const bondingCurve = this.decodeBondingCurve(bondingCurveAccountInfo);
175
- return { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo };
176
- }
177
-
178
- async fetchSellState(mint: PublicKey, user: PublicKey) {
179
- const [bondingCurveAccountInfo, associatedUserAccountInfo] =
180
- await this.connection.getMultipleAccountsInfo([
181
- bondingCurvePda(mint),
182
- getAssociatedTokenAddressSync(mint, user, true),
183
- ]);
184
-
185
- if (!bondingCurveAccountInfo) {
186
- throw new Error(
187
- `Bonding curve account not found for mint: ${mint.toBase58()}`,
188
- );
189
- }
190
-
191
- if (!associatedUserAccountInfo) {
192
- throw new Error(
193
- `Associated token account not found for mint: ${mint.toBase58()} and user: ${user.toBase58()}`,
194
- );
195
- }
196
-
197
- const bondingCurve = this.decodeBondingCurve(bondingCurveAccountInfo);
198
- return { bondingCurveAccountInfo, bondingCurve };
199
- }
200
-
201
- async fetchGlobalVolumeAccumulator(): Promise<GlobalVolumeAccumulator> {
202
- return await this.pumpProgram.account.globalVolumeAccumulator.fetch(
203
- globalVolumeAccumulatorPda()[0],
204
- );
205
- }
206
-
207
- async fetchUserVolumeAccumulator(
208
- user: PublicKey,
209
- ): Promise<UserVolumeAccumulator | null> {
210
- return await this.pumpProgram.account.userVolumeAccumulator.fetchNullable(
211
- userVolumeAccumulatorPda(user)[0],
212
- );
213
- }
214
-
215
- async fetchUserVolumeAccumulatorTotalStats(
216
- user: PublicKey,
217
- ): Promise<UserVolumeAccumulatorTotalStats> {
218
- const userVolumeAccumulator = (await this.fetchUserVolumeAccumulator(
219
- user,
220
- )) ?? {
221
- totalUnclaimedTokens: new BN(0),
222
- totalClaimedTokens: new BN(0),
223
- currentSolVolume: new BN(0),
224
- };
225
-
226
- const userVolumeAccumulatorAmm =
227
- (await this.pumpAmmSdk.fetchUserVolumeAccumulator(user)) ?? {
228
- totalUnclaimedTokens: new BN(0),
229
- totalClaimedTokens: new BN(0),
230
- currentSolVolume: new BN(0),
231
- };
232
-
233
- return {
234
- totalUnclaimedTokens: userVolumeAccumulator.totalUnclaimedTokens.add(
235
- userVolumeAccumulatorAmm.totalUnclaimedTokens,
236
- ),
237
- totalClaimedTokens: userVolumeAccumulator.totalClaimedTokens.add(
238
- userVolumeAccumulatorAmm.totalClaimedTokens,
239
- ),
240
- currentSolVolume: userVolumeAccumulator.currentSolVolume.add(
241
- userVolumeAccumulatorAmm.currentSolVolume,
242
- ),
243
- };
244
- }
245
-
246
121
  async createInstruction({
247
122
  mint,
248
123
  name,
@@ -488,266 +363,6 @@ export class PumpSdk {
488
363
  .instruction();
489
364
  }
490
365
 
491
- async collectCoinCreatorFeeInstructions(
492
- coinCreator: PublicKey,
493
- ): Promise<TransactionInstruction[]> {
494
- let quoteMint = NATIVE_MINT;
495
- let quoteTokenProgram = TOKEN_PROGRAM_ID;
496
-
497
- let coinCreatorVaultAuthority =
498
- this.pumpAmmSdk.coinCreatorVaultAuthorityPda(coinCreator);
499
- let coinCreatorVaultAta = this.pumpAmmSdk.coinCreatorVaultAta(
500
- coinCreatorVaultAuthority,
501
- quoteMint,
502
- quoteTokenProgram,
503
- );
504
-
505
- let coinCreatorTokenAccount = getAssociatedTokenAddressSync(
506
- quoteMint,
507
- coinCreator,
508
- true,
509
- quoteTokenProgram,
510
- );
511
- const [coinCreatorVaultAtaAccountInfo, coinCreatorTokenAccountInfo] =
512
- await this.connection.getMultipleAccountsInfo([
513
- coinCreatorVaultAta,
514
- coinCreatorTokenAccount,
515
- ]);
516
-
517
- return [
518
- await this.offlinePumpProgram.methods
519
- .collectCreatorFee()
520
- .accountsPartial({
521
- creator: coinCreator,
522
- })
523
- .instruction(),
524
- ...(await this.pumpAmmSdk.collectCoinCreatorFee({
525
- coinCreator,
526
- quoteMint,
527
- quoteTokenProgram,
528
- coinCreatorVaultAuthority,
529
- coinCreatorVaultAta,
530
- coinCreatorTokenAccount,
531
- coinCreatorVaultAtaAccountInfo,
532
- coinCreatorTokenAccountInfo,
533
- })),
534
- ];
535
- }
536
-
537
- async adminSetCoinCreatorInstructions(
538
- newCoinCreator: PublicKey,
539
- mint: PublicKey,
540
- ): Promise<TransactionInstruction[]> {
541
- const global = await this.fetchGlobal();
542
-
543
- return [
544
- await this.offlinePumpProgram.methods
545
- .adminSetCreator(newCoinCreator)
546
- .accountsPartial({
547
- adminSetCreatorAuthority: global.adminSetCreatorAuthority,
548
- mint,
549
- })
550
- .instruction(),
551
- await this.pumpAmmAdminSdk.adminSetCoinCreator(mint, newCoinCreator),
552
- ];
553
- }
554
-
555
- async getCreatorVaultBalance(creator: PublicKey): Promise<BN> {
556
- const creatorVault = creatorVaultPda(creator);
557
- const accountInfo = await this.connection.getAccountInfo(creatorVault);
558
-
559
- if (accountInfo === null) {
560
- return new BN(0);
561
- }
562
-
563
- const rentExemptionLamports =
564
- await this.connection.getMinimumBalanceForRentExemption(
565
- accountInfo.data.length,
566
- );
567
-
568
- if (accountInfo.lamports < rentExemptionLamports) {
569
- return new BN(0);
570
- }
571
-
572
- return new BN(accountInfo.lamports - rentExemptionLamports);
573
- }
574
-
575
- async getCreatorVaultBalanceBothPrograms(creator: PublicKey): Promise<BN> {
576
- const balance = await this.getCreatorVaultBalance(creator);
577
- const ammBalance =
578
- await this.pumpAmmSdk.getCoinCreatorVaultBalance(creator);
579
- return balance.add(ammBalance);
580
- }
581
-
582
- async adminUpdateTokenIncentives(
583
- startTime: BN,
584
- endTime: BN,
585
- dayNumber: BN,
586
- tokenSupplyPerDay: BN,
587
- secondsInADay: BN = new BN(86_400),
588
- mint: PublicKey = PUMP_TOKEN_MINT,
589
- tokenProgram: PublicKey = TOKEN_2022_PROGRAM_ID,
590
- ): Promise<TransactionInstruction> {
591
- const { authority } = await this.fetchGlobal();
592
-
593
- return await this.offlinePumpProgram.methods
594
- .adminUpdateTokenIncentives(
595
- startTime,
596
- endTime,
597
- secondsInADay,
598
- dayNumber,
599
- tokenSupplyPerDay,
600
- )
601
- .accountsPartial({
602
- authority,
603
- mint,
604
- tokenProgram,
605
- })
606
- .instruction();
607
- }
608
-
609
- async adminUpdateTokenIncentivesBothPrograms(
610
- startTime: BN,
611
- endTime: BN,
612
- dayNumber: BN,
613
- tokenSupplyPerDay: BN,
614
- secondsInADay: BN = new BN(86_400),
615
- mint: PublicKey = PUMP_TOKEN_MINT,
616
- tokenProgram: PublicKey = TOKEN_2022_PROGRAM_ID,
617
- ): Promise<TransactionInstruction[]> {
618
- return [
619
- await this.adminUpdateTokenIncentives(
620
- startTime,
621
- endTime,
622
- dayNumber,
623
- tokenSupplyPerDay,
624
- secondsInADay,
625
- mint,
626
- tokenProgram,
627
- ),
628
- await this.pumpAmmAdminSdk.adminUpdateTokenIncentives(
629
- startTime,
630
- endTime,
631
- dayNumber,
632
- tokenSupplyPerDay,
633
- secondsInADay,
634
- mint,
635
- tokenProgram,
636
- ),
637
- ];
638
- }
639
-
640
- async claimTokenIncentives(
641
- user: PublicKey,
642
- payer: PublicKey,
643
- ): Promise<TransactionInstruction[]> {
644
- const { mint } = await this.fetchGlobalVolumeAccumulator();
645
-
646
- if (mint.equals(PublicKey.default)) {
647
- return [];
648
- }
649
-
650
- const [mintAccountInfo, userAccumulatorAccountInfo] =
651
- await this.connection.getMultipleAccountsInfo([
652
- mint,
653
- userVolumeAccumulatorPda(user)[0],
654
- ]);
655
-
656
- if (!mintAccountInfo) {
657
- return [];
658
- }
659
-
660
- if (!userAccumulatorAccountInfo) {
661
- return [];
662
- }
663
-
664
- return [
665
- await this.offlinePumpProgram.methods
666
- .claimTokenIncentives()
667
- .accountsPartial({
668
- user,
669
- payer,
670
- mint,
671
- tokenProgram: mintAccountInfo.owner,
672
- })
673
- .instruction(),
674
- ];
675
- }
676
-
677
- async claimTokenIncentivesBothPrograms(
678
- user: PublicKey,
679
- payer: PublicKey,
680
- ): Promise<TransactionInstruction[]> {
681
- return [
682
- ...(await this.claimTokenIncentives(user, payer)),
683
- ...(await this.pumpAmmSdk.claimTokenIncentives(user, payer)),
684
- ];
685
- }
686
-
687
- async getTotalUnclaimedTokens(user: PublicKey): Promise<BN> {
688
- const [
689
- globalVolumeAccumulatorAccountInfo,
690
- userVolumeAccumulatorAccountInfo,
691
- ] = await this.connection.getMultipleAccountsInfo([
692
- globalVolumeAccumulatorPda()[0],
693
- userVolumeAccumulatorPda(user)[0],
694
- ]);
695
-
696
- if (
697
- !globalVolumeAccumulatorAccountInfo ||
698
- !userVolumeAccumulatorAccountInfo
699
- ) {
700
- return new BN(0);
701
- }
702
-
703
- const globalVolumeAccumulator = this.decodeGlobalVolumeAccumulator(
704
- globalVolumeAccumulatorAccountInfo,
705
- );
706
- const userVolumeAccumulator = this.decodeUserVolumeAccumulator(
707
- userVolumeAccumulatorAccountInfo,
708
- );
709
-
710
- return totalUnclaimedTokens(globalVolumeAccumulator, userVolumeAccumulator);
711
- }
712
-
713
- async getTotalUnclaimedTokensBothPrograms(user: PublicKey): Promise<BN> {
714
- return (await this.getTotalUnclaimedTokens(user)).add(
715
- await this.pumpAmmSdk.getTotalUnclaimedTokens(user),
716
- );
717
- }
718
-
719
- async getCurrentDayTokens(user: PublicKey): Promise<BN> {
720
- const [
721
- globalVolumeAccumulatorAccountInfo,
722
- userVolumeAccumulatorAccountInfo,
723
- ] = await this.connection.getMultipleAccountsInfo([
724
- globalVolumeAccumulatorPda()[0],
725
- userVolumeAccumulatorPda(user)[0],
726
- ]);
727
-
728
- if (
729
- !globalVolumeAccumulatorAccountInfo ||
730
- !userVolumeAccumulatorAccountInfo
731
- ) {
732
- return new BN(0);
733
- }
734
-
735
- const globalVolumeAccumulator = this.decodeGlobalVolumeAccumulator(
736
- globalVolumeAccumulatorAccountInfo,
737
- );
738
- const userVolumeAccumulator = this.decodeUserVolumeAccumulator(
739
- userVolumeAccumulatorAccountInfo,
740
- );
741
-
742
- return currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator);
743
- }
744
-
745
- async getCurrentDayTokensBothPrograms(user: PublicKey): Promise<BN> {
746
- return (await this.getCurrentDayTokens(user)).add(
747
- await this.pumpAmmSdk.getCurrentDayTokens(user),
748
- );
749
- }
750
-
751
366
  async syncUserVolumeAccumulator(
752
367
  user: PublicKey,
753
368
  ): Promise<TransactionInstruction> {
@@ -762,7 +377,7 @@ export class PumpSdk {
762
377
  ): Promise<TransactionInstruction[]> {
763
378
  return [
764
379
  await this.syncUserVolumeAccumulator(user),
765
- await this.pumpAmmSdk.syncUserVolumeAccumulator(user),
380
+ await PUMP_AMM_SDK.syncUserVolumeAccumulator(user),
766
381
  ];
767
382
  }
768
383
 
@@ -914,7 +529,9 @@ export class PumpSdk {
914
529
  }
915
530
  }
916
531
 
917
- function getFeeRecipient(global: Global): PublicKey {
532
+ export const PUMP_SDK = new PumpSdk();
533
+
534
+ export function getFeeRecipient(global: Global): PublicKey {
918
535
  const feeRecipients = [global.feeRecipient, ...global.feeRecipients];
919
536
  return feeRecipients[Math.floor(Math.random() * feeRecipients.length)];
920
537
  }