@pump-fun/pump-sdk 1.18.5 → 1.18.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pump-fun/pump-sdk",
3
- "version": "1.18.5",
3
+ "version": "1.18.7",
4
4
  "description": "Pump Bonding Curve SDK",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/pump-fun/pump-sdk#readme",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@coral-xyz/anchor": "^0.31.1",
42
- "@pump-fun/pump-swap-sdk": "^1.7.2",
42
+ "@pump-fun/pump-swap-sdk": "^1.7.7",
43
43
  "@solana/spl-token": "^0.4.13",
44
44
  "@solana/web3.js": "^1.98.2",
45
45
  "bn.js": "^5.2.2",
package/src/index.ts CHANGED
@@ -11,24 +11,16 @@ export {
11
11
  newBondingCurve,
12
12
  bondingCurveMarketCap,
13
13
  } from "./bondingCurve";
14
- export {
15
- globalPda,
16
- bondingCurvePda,
17
- creatorVaultPda,
18
- pumpFeeConfigPda,
19
- pumpPoolAuthorityPda,
20
- CANONICAL_POOL_INDEX,
21
- canonicalPumpPoolPda,
22
- globalVolumeAccumulatorPda,
23
- userVolumeAccumulatorPda,
24
- } from "./pda";
14
+ export * from "./pda";
25
15
  export {
26
16
  getPumpProgram,
27
17
  PUMP_PROGRAM_ID,
28
18
  PUMP_AMM_PROGRAM_ID,
29
19
  BONDING_CURVE_NEW_SIZE,
30
20
  PumpSdk,
21
+ PUMP_SDK,
31
22
  } from "./sdk";
23
+ export { OnlinePumpSdk } from "./onlineSdk";
32
24
  export {
33
25
  FeeConfig,
34
26
  Global,
@@ -0,0 +1,428 @@
1
+ import { Program } from "@coral-xyz/anchor";
2
+ import {
3
+ coinCreatorVaultAtaPda,
4
+ coinCreatorVaultAuthorityPda,
5
+ OnlinePumpAmmSdk,
6
+ PUMP_AMM_SDK,
7
+ PumpAmmAdminSdk,
8
+ } from "@pump-fun/pump-swap-sdk";
9
+ import {
10
+ getAssociatedTokenAddressSync,
11
+ NATIVE_MINT,
12
+ TOKEN_2022_PROGRAM_ID,
13
+ TOKEN_PROGRAM_ID,
14
+ } from "@solana/spl-token";
15
+ import {
16
+ Connection,
17
+ PublicKey,
18
+ PublicKeyInitData,
19
+ TransactionInstruction,
20
+ } from "@solana/web3.js";
21
+ import { Pump } from "./idl/pump";
22
+ import BN from "bn.js";
23
+
24
+ import {
25
+ bondingCurvePda,
26
+ creatorVaultPda,
27
+ GLOBAL_PDA,
28
+ GLOBAL_VOLUME_ACCUMULATOR_PDA,
29
+ PUMP_FEE_CONFIG_PDA,
30
+ userVolumeAccumulatorPda,
31
+ } from "./pda";
32
+ import {
33
+ BondingCurve,
34
+ FeeConfig,
35
+ Global,
36
+ GlobalVolumeAccumulator,
37
+ UserVolumeAccumulator,
38
+ UserVolumeAccumulatorTotalStats,
39
+ } from "./state";
40
+ import { currentDayTokens, totalUnclaimedTokens } from "./tokenIncentives";
41
+ import { getPumpProgram, PUMP_SDK, PUMP_TOKEN_MINT } from "./sdk";
42
+
43
+ export const OFFLINE_PUMP_PROGRAM = getPumpProgram(null as any as Connection);
44
+
45
+ export class OnlinePumpSdk {
46
+ private readonly connection: Connection;
47
+ private readonly pumpProgram: Program<Pump>;
48
+ private readonly offlinePumpProgram: Program<Pump>;
49
+ private readonly pumpAmmSdk: OnlinePumpAmmSdk;
50
+ private readonly pumpAmmAdminSdk: PumpAmmAdminSdk;
51
+
52
+ constructor(connection: Connection) {
53
+ this.connection = connection;
54
+
55
+ this.pumpProgram = getPumpProgram(connection);
56
+ this.offlinePumpProgram = OFFLINE_PUMP_PROGRAM;
57
+
58
+ this.pumpAmmSdk = new OnlinePumpAmmSdk(connection);
59
+ this.pumpAmmAdminSdk = new PumpAmmAdminSdk(connection);
60
+ }
61
+
62
+ async fetchGlobal(): Promise<Global> {
63
+ return await this.pumpProgram.account.global.fetch(GLOBAL_PDA);
64
+ }
65
+
66
+ async fetchFeeConfig(): Promise<FeeConfig> {
67
+ return await this.pumpProgram.account.feeConfig.fetch(PUMP_FEE_CONFIG_PDA);
68
+ }
69
+
70
+ async fetchBondingCurve(mint: PublicKeyInitData): Promise<BondingCurve> {
71
+ return await this.pumpProgram.account.bondingCurve.fetch(
72
+ bondingCurvePda(mint),
73
+ );
74
+ }
75
+
76
+ async fetchBuyState(mint: PublicKey, user: PublicKey) {
77
+ const [bondingCurveAccountInfo, associatedUserAccountInfo] =
78
+ await this.connection.getMultipleAccountsInfo([
79
+ bondingCurvePda(mint),
80
+ getAssociatedTokenAddressSync(mint, user, true),
81
+ ]);
82
+
83
+ if (!bondingCurveAccountInfo) {
84
+ throw new Error(
85
+ `Bonding curve account not found for mint: ${mint.toBase58()}`,
86
+ );
87
+ }
88
+
89
+ const bondingCurve = PUMP_SDK.decodeBondingCurve(bondingCurveAccountInfo);
90
+ return { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo };
91
+ }
92
+
93
+ async fetchSellState(mint: PublicKey, user: PublicKey) {
94
+ const [bondingCurveAccountInfo, associatedUserAccountInfo] =
95
+ await this.connection.getMultipleAccountsInfo([
96
+ bondingCurvePda(mint),
97
+ getAssociatedTokenAddressSync(mint, user, true),
98
+ ]);
99
+
100
+ if (!bondingCurveAccountInfo) {
101
+ throw new Error(
102
+ `Bonding curve account not found for mint: ${mint.toBase58()}`,
103
+ );
104
+ }
105
+
106
+ if (!associatedUserAccountInfo) {
107
+ throw new Error(
108
+ `Associated token account not found for mint: ${mint.toBase58()} and user: ${user.toBase58()}`,
109
+ );
110
+ }
111
+
112
+ const bondingCurve = PUMP_SDK.decodeBondingCurve(bondingCurveAccountInfo);
113
+ return { bondingCurveAccountInfo, bondingCurve };
114
+ }
115
+
116
+ async fetchGlobalVolumeAccumulator(): Promise<GlobalVolumeAccumulator> {
117
+ return await this.pumpProgram.account.globalVolumeAccumulator.fetch(
118
+ GLOBAL_VOLUME_ACCUMULATOR_PDA,
119
+ );
120
+ }
121
+
122
+ async fetchUserVolumeAccumulator(
123
+ user: PublicKey,
124
+ ): Promise<UserVolumeAccumulator | null> {
125
+ return await this.pumpProgram.account.userVolumeAccumulator.fetchNullable(
126
+ userVolumeAccumulatorPda(user),
127
+ );
128
+ }
129
+
130
+ async fetchUserVolumeAccumulatorTotalStats(
131
+ user: PublicKey,
132
+ ): Promise<UserVolumeAccumulatorTotalStats> {
133
+ const userVolumeAccumulator = (await this.fetchUserVolumeAccumulator(
134
+ user,
135
+ )) ?? {
136
+ totalUnclaimedTokens: new BN(0),
137
+ totalClaimedTokens: new BN(0),
138
+ currentSolVolume: new BN(0),
139
+ };
140
+
141
+ const userVolumeAccumulatorAmm =
142
+ (await this.pumpAmmSdk.fetchUserVolumeAccumulator(user)) ?? {
143
+ totalUnclaimedTokens: new BN(0),
144
+ totalClaimedTokens: new BN(0),
145
+ currentSolVolume: new BN(0),
146
+ };
147
+
148
+ return {
149
+ totalUnclaimedTokens: userVolumeAccumulator.totalUnclaimedTokens.add(
150
+ userVolumeAccumulatorAmm.totalUnclaimedTokens,
151
+ ),
152
+ totalClaimedTokens: userVolumeAccumulator.totalClaimedTokens.add(
153
+ userVolumeAccumulatorAmm.totalClaimedTokens,
154
+ ),
155
+ currentSolVolume: userVolumeAccumulator.currentSolVolume.add(
156
+ userVolumeAccumulatorAmm.currentSolVolume,
157
+ ),
158
+ };
159
+ }
160
+
161
+ async collectCoinCreatorFeeInstructions(
162
+ coinCreator: PublicKey,
163
+ ): Promise<TransactionInstruction[]> {
164
+ let quoteMint = NATIVE_MINT;
165
+ let quoteTokenProgram = TOKEN_PROGRAM_ID;
166
+
167
+ let coinCreatorVaultAuthority = coinCreatorVaultAuthorityPda(coinCreator);
168
+ let coinCreatorVaultAta = coinCreatorVaultAtaPda(
169
+ coinCreatorVaultAuthority,
170
+ quoteMint,
171
+ quoteTokenProgram,
172
+ );
173
+
174
+ let coinCreatorTokenAccount = getAssociatedTokenAddressSync(
175
+ quoteMint,
176
+ coinCreator,
177
+ true,
178
+ quoteTokenProgram,
179
+ );
180
+ const [coinCreatorVaultAtaAccountInfo, coinCreatorTokenAccountInfo] =
181
+ await this.connection.getMultipleAccountsInfo([
182
+ coinCreatorVaultAta,
183
+ coinCreatorTokenAccount,
184
+ ]);
185
+
186
+ return [
187
+ await this.offlinePumpProgram.methods
188
+ .collectCreatorFee()
189
+ .accountsPartial({
190
+ creator: coinCreator,
191
+ })
192
+ .instruction(),
193
+ ...(await PUMP_AMM_SDK.collectCoinCreatorFee({
194
+ coinCreator,
195
+ quoteMint,
196
+ quoteTokenProgram,
197
+ coinCreatorVaultAuthority,
198
+ coinCreatorVaultAta,
199
+ coinCreatorTokenAccount,
200
+ coinCreatorVaultAtaAccountInfo,
201
+ coinCreatorTokenAccountInfo,
202
+ })),
203
+ ];
204
+ }
205
+
206
+ async adminSetCoinCreatorInstructions(
207
+ newCoinCreator: PublicKey,
208
+ mint: PublicKey,
209
+ ): Promise<TransactionInstruction[]> {
210
+ const global = await this.fetchGlobal();
211
+
212
+ return [
213
+ await this.offlinePumpProgram.methods
214
+ .adminSetCreator(newCoinCreator)
215
+ .accountsPartial({
216
+ adminSetCreatorAuthority: global.adminSetCreatorAuthority,
217
+ mint,
218
+ })
219
+ .instruction(),
220
+ await this.pumpAmmAdminSdk.adminSetCoinCreator(mint, newCoinCreator),
221
+ ];
222
+ }
223
+
224
+ async getCreatorVaultBalance(creator: PublicKey): Promise<BN> {
225
+ const creatorVault = creatorVaultPda(creator);
226
+ const accountInfo = await this.connection.getAccountInfo(creatorVault);
227
+
228
+ if (accountInfo === null) {
229
+ return new BN(0);
230
+ }
231
+
232
+ const rentExemptionLamports =
233
+ await this.connection.getMinimumBalanceForRentExemption(
234
+ accountInfo.data.length,
235
+ );
236
+
237
+ if (accountInfo.lamports < rentExemptionLamports) {
238
+ return new BN(0);
239
+ }
240
+
241
+ return new BN(accountInfo.lamports - rentExemptionLamports);
242
+ }
243
+
244
+ async getCreatorVaultBalanceBothPrograms(creator: PublicKey): Promise<BN> {
245
+ const balance = await this.getCreatorVaultBalance(creator);
246
+ const ammBalance =
247
+ await this.pumpAmmSdk.getCoinCreatorVaultBalance(creator);
248
+ return balance.add(ammBalance);
249
+ }
250
+
251
+ async adminUpdateTokenIncentives(
252
+ startTime: BN,
253
+ endTime: BN,
254
+ dayNumber: BN,
255
+ tokenSupplyPerDay: BN,
256
+ secondsInADay: BN = new BN(86_400),
257
+ mint: PublicKey = PUMP_TOKEN_MINT,
258
+ tokenProgram: PublicKey = TOKEN_2022_PROGRAM_ID,
259
+ ): Promise<TransactionInstruction> {
260
+ const { authority } = await this.fetchGlobal();
261
+
262
+ return await this.offlinePumpProgram.methods
263
+ .adminUpdateTokenIncentives(
264
+ startTime,
265
+ endTime,
266
+ secondsInADay,
267
+ dayNumber,
268
+ tokenSupplyPerDay,
269
+ )
270
+ .accountsPartial({
271
+ authority,
272
+ mint,
273
+ tokenProgram,
274
+ })
275
+ .instruction();
276
+ }
277
+
278
+ async adminUpdateTokenIncentivesBothPrograms(
279
+ startTime: BN,
280
+ endTime: BN,
281
+ dayNumber: BN,
282
+ tokenSupplyPerDay: BN,
283
+ secondsInADay: BN = new BN(86_400),
284
+ mint: PublicKey = PUMP_TOKEN_MINT,
285
+ tokenProgram: PublicKey = TOKEN_2022_PROGRAM_ID,
286
+ ): Promise<TransactionInstruction[]> {
287
+ return [
288
+ await this.adminUpdateTokenIncentives(
289
+ startTime,
290
+ endTime,
291
+ dayNumber,
292
+ tokenSupplyPerDay,
293
+ secondsInADay,
294
+ mint,
295
+ tokenProgram,
296
+ ),
297
+ await this.pumpAmmAdminSdk.adminUpdateTokenIncentives(
298
+ startTime,
299
+ endTime,
300
+ dayNumber,
301
+ tokenSupplyPerDay,
302
+ secondsInADay,
303
+ mint,
304
+ tokenProgram,
305
+ ),
306
+ ];
307
+ }
308
+
309
+ async claimTokenIncentives(
310
+ user: PublicKey,
311
+ payer: PublicKey,
312
+ ): Promise<TransactionInstruction[]> {
313
+ const { mint } = await this.fetchGlobalVolumeAccumulator();
314
+
315
+ if (mint.equals(PublicKey.default)) {
316
+ return [];
317
+ }
318
+
319
+ const [mintAccountInfo, userAccumulatorAccountInfo] =
320
+ await this.connection.getMultipleAccountsInfo([
321
+ mint,
322
+ userVolumeAccumulatorPda(user),
323
+ ]);
324
+
325
+ if (!mintAccountInfo) {
326
+ return [];
327
+ }
328
+
329
+ if (!userAccumulatorAccountInfo) {
330
+ return [];
331
+ }
332
+
333
+ return [
334
+ await this.offlinePumpProgram.methods
335
+ .claimTokenIncentives()
336
+ .accountsPartial({
337
+ user,
338
+ payer,
339
+ mint,
340
+ tokenProgram: mintAccountInfo.owner,
341
+ })
342
+ .instruction(),
343
+ ];
344
+ }
345
+
346
+ async claimTokenIncentivesBothPrograms(
347
+ user: PublicKey,
348
+ payer: PublicKey,
349
+ ): Promise<TransactionInstruction[]> {
350
+ return [
351
+ ...(await this.claimTokenIncentives(user, payer)),
352
+ ...(await this.pumpAmmSdk.claimTokenIncentives(user, payer)),
353
+ ];
354
+ }
355
+
356
+ async getTotalUnclaimedTokens(user: PublicKey): Promise<BN> {
357
+ const [
358
+ globalVolumeAccumulatorAccountInfo,
359
+ userVolumeAccumulatorAccountInfo,
360
+ ] = await this.connection.getMultipleAccountsInfo([
361
+ GLOBAL_VOLUME_ACCUMULATOR_PDA,
362
+ userVolumeAccumulatorPda(user),
363
+ ]);
364
+
365
+ if (
366
+ !globalVolumeAccumulatorAccountInfo ||
367
+ !userVolumeAccumulatorAccountInfo
368
+ ) {
369
+ return new BN(0);
370
+ }
371
+
372
+ const globalVolumeAccumulator = PUMP_SDK.decodeGlobalVolumeAccumulator(
373
+ globalVolumeAccumulatorAccountInfo,
374
+ );
375
+ const userVolumeAccumulator = PUMP_SDK.decodeUserVolumeAccumulator(
376
+ userVolumeAccumulatorAccountInfo,
377
+ );
378
+
379
+ return totalUnclaimedTokens(globalVolumeAccumulator, userVolumeAccumulator);
380
+ }
381
+
382
+ async getTotalUnclaimedTokensBothPrograms(user: PublicKey): Promise<BN> {
383
+ return (await this.getTotalUnclaimedTokens(user)).add(
384
+ await this.pumpAmmSdk.getTotalUnclaimedTokens(user),
385
+ );
386
+ }
387
+
388
+ async getCurrentDayTokens(user: PublicKey): Promise<BN> {
389
+ const [
390
+ globalVolumeAccumulatorAccountInfo,
391
+ userVolumeAccumulatorAccountInfo,
392
+ ] = await this.connection.getMultipleAccountsInfo([
393
+ GLOBAL_VOLUME_ACCUMULATOR_PDA,
394
+ userVolumeAccumulatorPda(user),
395
+ ]);
396
+
397
+ if (
398
+ !globalVolumeAccumulatorAccountInfo ||
399
+ !userVolumeAccumulatorAccountInfo
400
+ ) {
401
+ return new BN(0);
402
+ }
403
+
404
+ const globalVolumeAccumulator = PUMP_SDK.decodeGlobalVolumeAccumulator(
405
+ globalVolumeAccumulatorAccountInfo,
406
+ );
407
+ const userVolumeAccumulator = PUMP_SDK.decodeUserVolumeAccumulator(
408
+ userVolumeAccumulatorAccountInfo,
409
+ );
410
+
411
+ return currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator);
412
+ }
413
+
414
+ async getCurrentDayTokensBothPrograms(user: PublicKey): Promise<BN> {
415
+ return (await this.getCurrentDayTokens(user)).add(
416
+ await this.pumpAmmSdk.getCurrentDayTokens(user),
417
+ );
418
+ }
419
+
420
+ async syncUserVolumeAccumulatorBothPrograms(
421
+ user: PublicKey,
422
+ ): Promise<TransactionInstruction[]> {
423
+ return [
424
+ await PUMP_SDK.syncUserVolumeAccumulator(user),
425
+ await PUMP_AMM_SDK.syncUserVolumeAccumulator(user),
426
+ ];
427
+ }
428
+ }
package/src/pda.ts CHANGED
@@ -1,74 +1,46 @@
1
1
  import { PublicKey, PublicKeyInitData } from "@solana/web3.js";
2
2
  import { NATIVE_MINT } from "@solana/spl-token";
3
- import { poolPda } from "@pump-fun/pump-swap-sdk";
4
- import {
5
- PUMP_AMM_PROGRAM_ID,
6
- PUMP_FEE_PROGRAM_ID,
7
- PUMP_PROGRAM_ID,
8
- } from "./sdk";
3
+ import { poolPda, pumpFeePda, pumpPda } from "@pump-fun/pump-swap-sdk";
4
+ import { PUMP_PROGRAM_ID } from "./sdk";
5
+ import { Buffer } from "buffer";
9
6
 
10
- export function globalPda(): PublicKey {
11
- const [globalPda] = PublicKey.findProgramAddressSync(
12
- [Buffer.from("global")],
13
- PUMP_PROGRAM_ID,
14
- );
15
- return globalPda;
16
- }
7
+ export const GLOBAL_PDA = pumpPda([Buffer.from("global")]);
17
8
 
18
- export function pumpFeeConfigPda(): PublicKey {
19
- return PublicKey.findProgramAddressSync(
20
- [Buffer.from("fee_config"), PUMP_PROGRAM_ID.toBuffer()],
21
- PUMP_FEE_PROGRAM_ID,
22
- )[0];
23
- }
9
+ export const PUMP_FEE_CONFIG_PDA = pumpFeePda([
10
+ Buffer.from("fee_config"),
11
+ PUMP_PROGRAM_ID.toBuffer(),
12
+ ]);
13
+
14
+ export const GLOBAL_VOLUME_ACCUMULATOR_PDA = pumpPda([
15
+ Buffer.from("global_volume_accumulator"),
16
+ ]);
24
17
 
25
18
  export function bondingCurvePda(mint: PublicKeyInitData): PublicKey {
26
- const [bondingCurvePda] = PublicKey.findProgramAddressSync(
27
- [Buffer.from("bonding-curve"), new PublicKey(mint).toBuffer()],
28
- PUMP_PROGRAM_ID,
29
- );
30
- return bondingCurvePda;
19
+ return pumpPda([
20
+ Buffer.from("bonding-curve"),
21
+ new PublicKey(mint).toBuffer(),
22
+ ]);
31
23
  }
32
24
 
33
25
  export function creatorVaultPda(creator: PublicKey) {
34
- const [creatorVault] = PublicKey.findProgramAddressSync(
35
- [Buffer.from("creator-vault"), creator.toBuffer()],
36
- PUMP_PROGRAM_ID,
37
- );
38
- return creatorVault;
26
+ return pumpPda([Buffer.from("creator-vault"), creator.toBuffer()]);
39
27
  }
40
28
 
41
- export function pumpPoolAuthorityPda(mint: PublicKey): [PublicKey, number] {
42
- return PublicKey.findProgramAddressSync(
43
- [Buffer.from("pool-authority"), mint.toBuffer()],
44
- PUMP_PROGRAM_ID,
45
- );
29
+ export function pumpPoolAuthorityPda(mint: PublicKey): PublicKey {
30
+ return pumpPda([Buffer.from("pool-authority"), mint.toBuffer()]);
46
31
  }
47
32
 
48
33
  export const CANONICAL_POOL_INDEX = 0;
49
34
 
50
- export function canonicalPumpPoolPda(mint: PublicKey): [PublicKey, number] {
51
- const [pumpPoolAuthority] = pumpPoolAuthorityPda(mint);
52
-
35
+ export function canonicalPumpPoolPda(mint: PublicKey): PublicKey {
53
36
  return poolPda(
54
37
  CANONICAL_POOL_INDEX,
55
- pumpPoolAuthority,
38
+ pumpPoolAuthorityPda(mint),
56
39
  mint,
57
40
  NATIVE_MINT,
58
- PUMP_AMM_PROGRAM_ID,
59
- );
60
- }
61
-
62
- export function globalVolumeAccumulatorPda(): [PublicKey, number] {
63
- return PublicKey.findProgramAddressSync(
64
- [Buffer.from("global_volume_accumulator")],
65
- PUMP_PROGRAM_ID,
66
41
  );
67
42
  }
68
43
 
69
- export function userVolumeAccumulatorPda(user: PublicKey): [PublicKey, number] {
70
- return PublicKey.findProgramAddressSync(
71
- [Buffer.from("user_volume_accumulator"), user.toBuffer()],
72
- PUMP_PROGRAM_ID,
73
- );
44
+ export function userVolumeAccumulatorPda(user: PublicKey): PublicKey {
45
+ return pumpPda([Buffer.from("user_volume_accumulator"), user.toBuffer()]);
74
46
  }