@pump-fun/pump-sdk 1.18.3 → 1.18.4

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/esm/index.js CHANGED
@@ -4829,14 +4829,16 @@ function getBuySolAmountFromTokenAmount({
4829
4829
  virtualTokenReserves: bondingCurve.virtualTokenReserves,
4830
4830
  virtualSolReserves: bondingCurve.virtualSolReserves
4831
4831
  });
4832
- return solCost.add(getFee({
4833
- global,
4834
- feeConfig,
4835
- mintSupply,
4836
- bondingCurve,
4837
- amount: solCost,
4838
- isNewBondingCurve
4839
- }));
4832
+ return solCost.add(
4833
+ getFee({
4834
+ global,
4835
+ feeConfig,
4836
+ mintSupply,
4837
+ bondingCurve,
4838
+ amount: solCost,
4839
+ isNewBondingCurve
4840
+ })
4841
+ );
4840
4842
  }
4841
4843
  function getSellSolAmountFromTokenAmount({
4842
4844
  global,
@@ -4856,14 +4858,16 @@ function getSellSolAmountFromTokenAmount({
4856
4858
  virtualTokenReserves: bondingCurve.virtualTokenReserves,
4857
4859
  virtualSolReserves: bondingCurve.virtualSolReserves
4858
4860
  });
4859
- return solCost.sub(getFee({
4860
- global,
4861
- feeConfig,
4862
- mintSupply,
4863
- bondingCurve,
4864
- amount: solCost,
4865
- isNewBondingCurve: false
4866
- }));
4861
+ return solCost.sub(
4862
+ getFee({
4863
+ global,
4864
+ feeConfig,
4865
+ mintSupply,
4866
+ bondingCurve,
4867
+ amount: solCost,
4868
+ isNewBondingCurve: false
4869
+ })
4870
+ );
4867
4871
  }
4868
4872
  function getStaticRandomFeeRecipient() {
4869
4873
  const randomIndex = Math.floor(Math.random() * CURRENT_FEE_RECIPIENTS.length);
@@ -4953,7 +4957,10 @@ function computeFeesBps({
4953
4957
  creatorFeeBps: global.creatorFeeBasisPoints
4954
4958
  };
4955
4959
  }
4956
- function calculateFeeTier({ feeTiers, marketCap }) {
4960
+ function calculateFeeTier({
4961
+ feeTiers,
4962
+ marketCap
4963
+ }) {
4957
4964
  const firstTier = feeTiers[0];
4958
4965
  if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
4959
4966
  return firstTier.fees;
@@ -5104,6 +5111,14 @@ var PumpSdk = class {
5104
5111
  accountInfo.data
5105
5112
  );
5106
5113
  }
5114
+ decodeBondingCurveNullable(accountInfo) {
5115
+ try {
5116
+ return this.decodeBondingCurve(accountInfo);
5117
+ } catch (e) {
5118
+ console.warn("Failed to decode bonding curve", e);
5119
+ return null;
5120
+ }
5121
+ }
5107
5122
  decodeGlobalVolumeAccumulator(accountInfo) {
5108
5123
  return this.offlinePumpProgram.coder.accounts.decode(
5109
5124
  "globalVolumeAccumulator",
@@ -5116,6 +5131,14 @@ var PumpSdk = class {
5116
5131
  accountInfo.data
5117
5132
  );
5118
5133
  }
5134
+ decodeUserVolumeAccumulatorNullable(accountInfo) {
5135
+ try {
5136
+ return this.decodeUserVolumeAccumulator(accountInfo);
5137
+ } catch (e) {
5138
+ console.warn("Failed to decode user volume accumulator", e);
5139
+ return null;
5140
+ }
5141
+ }
5119
5142
  async fetchGlobal() {
5120
5143
  return await this.pumpProgram.account.global.fetch(globalPda());
5121
5144
  }
package/dist/index.d.mts CHANGED
@@ -9614,8 +9614,10 @@ declare class PumpSdk {
9614
9614
  decodeGlobal(accountInfo: AccountInfo<Buffer>): Global;
9615
9615
  decodeFeeConfig(accountInfo: AccountInfo<Buffer>): FeeConfig;
9616
9616
  decodeBondingCurve(accountInfo: AccountInfo<Buffer>): BondingCurve;
9617
+ decodeBondingCurveNullable(accountInfo: AccountInfo<Buffer>): BondingCurve | null;
9617
9618
  decodeGlobalVolumeAccumulator(accountInfo: AccountInfo<Buffer>): GlobalVolumeAccumulator;
9618
9619
  decodeUserVolumeAccumulator(accountInfo: AccountInfo<Buffer>): UserVolumeAccumulator;
9620
+ decodeUserVolumeAccumulatorNullable(accountInfo: AccountInfo<Buffer>): UserVolumeAccumulator | null;
9619
9621
  fetchGlobal(): Promise<Global>;
9620
9622
  fetchFeeConfig(): Promise<FeeConfig>;
9621
9623
  fetchBondingCurve(mint: PublicKeyInitData): Promise<BondingCurve>;
package/dist/index.d.ts CHANGED
@@ -9614,8 +9614,10 @@ declare class PumpSdk {
9614
9614
  decodeGlobal(accountInfo: AccountInfo<Buffer>): Global;
9615
9615
  decodeFeeConfig(accountInfo: AccountInfo<Buffer>): FeeConfig;
9616
9616
  decodeBondingCurve(accountInfo: AccountInfo<Buffer>): BondingCurve;
9617
+ decodeBondingCurveNullable(accountInfo: AccountInfo<Buffer>): BondingCurve | null;
9617
9618
  decodeGlobalVolumeAccumulator(accountInfo: AccountInfo<Buffer>): GlobalVolumeAccumulator;
9618
9619
  decodeUserVolumeAccumulator(accountInfo: AccountInfo<Buffer>): UserVolumeAccumulator;
9620
+ decodeUserVolumeAccumulatorNullable(accountInfo: AccountInfo<Buffer>): UserVolumeAccumulator | null;
9619
9621
  fetchGlobal(): Promise<Global>;
9620
9622
  fetchFeeConfig(): Promise<FeeConfig>;
9621
9623
  fetchBondingCurve(mint: PublicKeyInitData): Promise<BondingCurve>;
package/dist/index.js CHANGED
@@ -4890,14 +4890,16 @@ function getBuySolAmountFromTokenAmount({
4890
4890
  virtualTokenReserves: bondingCurve.virtualTokenReserves,
4891
4891
  virtualSolReserves: bondingCurve.virtualSolReserves
4892
4892
  });
4893
- return solCost.add(getFee({
4894
- global,
4895
- feeConfig,
4896
- mintSupply,
4897
- bondingCurve,
4898
- amount: solCost,
4899
- isNewBondingCurve
4900
- }));
4893
+ return solCost.add(
4894
+ getFee({
4895
+ global,
4896
+ feeConfig,
4897
+ mintSupply,
4898
+ bondingCurve,
4899
+ amount: solCost,
4900
+ isNewBondingCurve
4901
+ })
4902
+ );
4901
4903
  }
4902
4904
  function getSellSolAmountFromTokenAmount({
4903
4905
  global,
@@ -4917,14 +4919,16 @@ function getSellSolAmountFromTokenAmount({
4917
4919
  virtualTokenReserves: bondingCurve.virtualTokenReserves,
4918
4920
  virtualSolReserves: bondingCurve.virtualSolReserves
4919
4921
  });
4920
- return solCost.sub(getFee({
4921
- global,
4922
- feeConfig,
4923
- mintSupply,
4924
- bondingCurve,
4925
- amount: solCost,
4926
- isNewBondingCurve: false
4927
- }));
4922
+ return solCost.sub(
4923
+ getFee({
4924
+ global,
4925
+ feeConfig,
4926
+ mintSupply,
4927
+ bondingCurve,
4928
+ amount: solCost,
4929
+ isNewBondingCurve: false
4930
+ })
4931
+ );
4928
4932
  }
4929
4933
  function getStaticRandomFeeRecipient() {
4930
4934
  const randomIndex = Math.floor(Math.random() * CURRENT_FEE_RECIPIENTS.length);
@@ -5014,7 +5018,10 @@ function computeFeesBps({
5014
5018
  creatorFeeBps: global.creatorFeeBasisPoints
5015
5019
  };
5016
5020
  }
5017
- function calculateFeeTier({ feeTiers, marketCap }) {
5021
+ function calculateFeeTier({
5022
+ feeTiers,
5023
+ marketCap
5024
+ }) {
5018
5025
  const firstTier = feeTiers[0];
5019
5026
  if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
5020
5027
  return firstTier.fees;
@@ -5157,6 +5164,14 @@ var PumpSdk = class {
5157
5164
  accountInfo.data
5158
5165
  );
5159
5166
  }
5167
+ decodeBondingCurveNullable(accountInfo) {
5168
+ try {
5169
+ return this.decodeBondingCurve(accountInfo);
5170
+ } catch (e) {
5171
+ console.warn("Failed to decode bonding curve", e);
5172
+ return null;
5173
+ }
5174
+ }
5160
5175
  decodeGlobalVolumeAccumulator(accountInfo) {
5161
5176
  return this.offlinePumpProgram.coder.accounts.decode(
5162
5177
  "globalVolumeAccumulator",
@@ -5169,6 +5184,14 @@ var PumpSdk = class {
5169
5184
  accountInfo.data
5170
5185
  );
5171
5186
  }
5187
+ decodeUserVolumeAccumulatorNullable(accountInfo) {
5188
+ try {
5189
+ return this.decodeUserVolumeAccumulator(accountInfo);
5190
+ } catch (e) {
5191
+ console.warn("Failed to decode user volume accumulator", e);
5192
+ return null;
5193
+ }
5194
+ }
5172
5195
  async fetchGlobal() {
5173
5196
  return await this.pumpProgram.account.global.fetch(globalPda());
5174
5197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pump-fun/pump-sdk",
3
- "version": "1.18.3",
3
+ "version": "1.18.4",
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.0",
42
+ "@pump-fun/pump-swap-sdk": "^1.7.1",
43
43
  "@solana/spl-token": "^0.4.13",
44
44
  "@solana/web3.js": "^1.98.2",
45
45
  "bn.js": "^5.2.2",
@@ -152,14 +152,16 @@ export function getBuySolAmountFromTokenAmount({
152
152
  virtualSolReserves: bondingCurve.virtualSolReserves,
153
153
  });
154
154
 
155
- return solCost.add(getFee({
156
- global,
157
- feeConfig,
158
- mintSupply,
159
- bondingCurve,
160
- amount: solCost,
161
- isNewBondingCurve,
162
- }));
155
+ return solCost.add(
156
+ getFee({
157
+ global,
158
+ feeConfig,
159
+ mintSupply,
160
+ bondingCurve,
161
+ amount: solCost,
162
+ isNewBondingCurve,
163
+ }),
164
+ );
163
165
  }
164
166
 
165
167
  export function getSellSolAmountFromTokenAmount({
@@ -190,14 +192,16 @@ export function getSellSolAmountFromTokenAmount({
190
192
  virtualSolReserves: bondingCurve.virtualSolReserves,
191
193
  });
192
194
 
193
- return solCost.sub(getFee({
194
- global,
195
- feeConfig,
196
- mintSupply,
197
- bondingCurve,
198
- amount: solCost,
199
- isNewBondingCurve: false,
200
- }));
195
+ return solCost.sub(
196
+ getFee({
197
+ global,
198
+ feeConfig,
199
+ mintSupply,
200
+ bondingCurve,
201
+ amount: solCost,
202
+ isNewBondingCurve: false,
203
+ }),
204
+ );
201
205
  }
202
206
 
203
207
  export function getStaticRandomFeeRecipient(): PublicKey {
package/src/fees.ts CHANGED
@@ -4,115 +4,125 @@ import { FeeConfig, Global, Fees, BondingCurve, FeeTier } from "./state";
4
4
  import { bondingCurveMarketCap } from "./bondingCurve";
5
5
 
6
6
  export interface CalculatedFeesBps {
7
- protocolFeeBps: BN;
8
- creatorFeeBps: BN;
7
+ protocolFeeBps: BN;
8
+ creatorFeeBps: BN;
9
9
  }
10
10
 
11
11
  export interface CalculatedFees {
12
- protocolFee: BN;
13
- creatorFee: BN;
12
+ protocolFee: BN;
13
+ creatorFee: BN;
14
14
  }
15
15
 
16
- export function createFeeConfigFromGlobalConfig(globalConfig: Global): FeeConfig {
17
- let fees: Fees = {
18
- lpFeeBps: new BN(0), // unused for pump
19
- protocolFeeBps: globalConfig.feeBasisPoints,
20
- creatorFeeBps: globalConfig.creatorFeeBasisPoints,
21
- };
22
- return {
23
- admin: globalConfig.authority,
24
- flatFees: fees,
25
- feeTiers: [
26
- {
27
- marketCapLamportsThreshold: new BN(0), // unused for pump
28
- fees,
29
- },
30
- ],
31
- };
16
+ export function createFeeConfigFromGlobalConfig(
17
+ globalConfig: Global,
18
+ ): FeeConfig {
19
+ let fees: Fees = {
20
+ lpFeeBps: new BN(0), // unused for pump
21
+ protocolFeeBps: globalConfig.feeBasisPoints,
22
+ creatorFeeBps: globalConfig.creatorFeeBasisPoints,
23
+ };
24
+ return {
25
+ admin: globalConfig.authority,
26
+ flatFees: fees,
27
+ feeTiers: [
28
+ {
29
+ marketCapLamportsThreshold: new BN(0), // unused for pump
30
+ fees,
31
+ },
32
+ ],
33
+ };
32
34
  }
33
35
 
34
36
  export function getFee({
35
- global,
36
- feeConfig,
37
- mintSupply,
38
- bondingCurve,
39
- amount,
40
- isNewBondingCurve,
37
+ global,
38
+ feeConfig,
39
+ mintSupply,
40
+ bondingCurve,
41
+ amount,
42
+ isNewBondingCurve,
41
43
  }: {
42
- global: Global;
43
- feeConfig: FeeConfig | null;
44
- mintSupply: BN;
45
- bondingCurve: BondingCurve;
46
- amount: BN;
47
- isNewBondingCurve: boolean;
44
+ global: Global;
45
+ feeConfig: FeeConfig | null;
46
+ mintSupply: BN;
47
+ bondingCurve: BondingCurve;
48
+ amount: BN;
49
+ isNewBondingCurve: boolean;
48
50
  }) {
49
- const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
50
- const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
51
- global,
52
- feeConfig,
53
- mintSupply,
54
- virtualSolReserves,
55
- virtualTokenReserves,
56
- });
57
-
58
- return fee(amount, protocolFeeBps).add(
59
- isNewBondingCurve || !PublicKey.default.equals(bondingCurve.creator) ? fee(amount, creatorFeeBps) : new BN(0)
60
- );
61
- }
62
-
63
- export function computeFeesBps({
51
+ const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
52
+ const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
64
53
  global,
65
54
  feeConfig,
66
55
  mintSupply,
67
56
  virtualSolReserves,
68
57
  virtualTokenReserves,
58
+ });
59
+
60
+ return fee(amount, protocolFeeBps).add(
61
+ isNewBondingCurve || !PublicKey.default.equals(bondingCurve.creator)
62
+ ? fee(amount, creatorFeeBps)
63
+ : new BN(0),
64
+ );
65
+ }
66
+
67
+ export function computeFeesBps({
68
+ global,
69
+ feeConfig,
70
+ mintSupply,
71
+ virtualSolReserves,
72
+ virtualTokenReserves,
69
73
  }: {
70
- global: Global;
71
- feeConfig: FeeConfig | null;
72
- mintSupply: BN;
73
- virtualSolReserves: BN;
74
- virtualTokenReserves: BN;
74
+ global: Global;
75
+ feeConfig: FeeConfig | null;
76
+ mintSupply: BN;
77
+ virtualSolReserves: BN;
78
+ virtualTokenReserves: BN;
75
79
  }): CalculatedFeesBps {
76
- if (feeConfig != null) {
77
- const marketCap = bondingCurveMarketCap({
78
- mintSupply,
79
- virtualSolReserves,
80
- virtualTokenReserves,
81
- });
80
+ if (feeConfig != null) {
81
+ const marketCap = bondingCurveMarketCap({
82
+ mintSupply,
83
+ virtualSolReserves,
84
+ virtualTokenReserves,
85
+ });
82
86
 
83
- return calculateFeeTier({
84
- feeTiers: feeConfig.feeTiers,
85
- marketCap,
86
- });
87
- }
87
+ return calculateFeeTier({
88
+ feeTiers: feeConfig.feeTiers,
89
+ marketCap,
90
+ });
91
+ }
88
92
 
89
- return {
90
- protocolFeeBps: global.feeBasisPoints,
91
- creatorFeeBps: global.creatorFeeBasisPoints,
92
- };
93
+ return {
94
+ protocolFeeBps: global.feeBasisPoints,
95
+ creatorFeeBps: global.creatorFeeBasisPoints,
96
+ };
93
97
  }
94
98
 
95
99
  /// rust reference: pump-fees-math::calculate_fee_tier()
96
- export function calculateFeeTier({ feeTiers, marketCap }: { feeTiers: FeeTier[]; marketCap: BN }): Fees {
97
- const firstTier = feeTiers[0];
100
+ export function calculateFeeTier({
101
+ feeTiers,
102
+ marketCap,
103
+ }: {
104
+ feeTiers: FeeTier[];
105
+ marketCap: BN;
106
+ }): Fees {
107
+ const firstTier = feeTiers[0];
98
108
 
99
- if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
100
- return firstTier.fees;
101
- }
109
+ if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
110
+ return firstTier.fees;
111
+ }
102
112
 
103
- for (const tier of feeTiers.slice().reverse()) {
104
- if (marketCap.gte(tier.marketCapLamportsThreshold)) {
105
- return tier.fees;
106
- }
113
+ for (const tier of feeTiers.slice().reverse()) {
114
+ if (marketCap.gte(tier.marketCapLamportsThreshold)) {
115
+ return tier.fees;
107
116
  }
117
+ }
108
118
 
109
- return firstTier.fees;
119
+ return firstTier.fees;
110
120
  }
111
121
 
112
122
  function fee(amount: BN, feeBasisPoints: BN): BN {
113
- return ceilDiv(amount.mul(feeBasisPoints), new BN(10_000));
123
+ return ceilDiv(amount.mul(feeBasisPoints), new BN(10_000));
114
124
  }
115
125
 
116
126
  function ceilDiv(a: BN, b: BN): BN {
117
- return a.add(b.subn(1)).div(b);
127
+ return a.add(b.subn(1)).div(b);
118
128
  }
package/src/pda.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import { PublicKey, PublicKeyInitData } from "@solana/web3.js";
2
2
  import { NATIVE_MINT } from "@solana/spl-token";
3
3
  import { poolPda } from "@pump-fun/pump-swap-sdk";
4
- import { PUMP_AMM_PROGRAM_ID, PUMP_FEE_PROGRAM_ID, PUMP_PROGRAM_ID } from "./sdk";
4
+ import {
5
+ PUMP_AMM_PROGRAM_ID,
6
+ PUMP_FEE_PROGRAM_ID,
7
+ PUMP_PROGRAM_ID,
8
+ } from "./sdk";
5
9
 
6
10
  export function globalPda(): PublicKey {
7
11
  const [globalPda] = PublicKey.findProgramAddressSync(
package/src/sdk.ts CHANGED
@@ -104,6 +104,17 @@ export class PumpSdk {
104
104
  );
105
105
  }
106
106
 
107
+ decodeBondingCurveNullable(
108
+ accountInfo: AccountInfo<Buffer>,
109
+ ): BondingCurve | null {
110
+ try {
111
+ return this.decodeBondingCurve(accountInfo);
112
+ } catch (e) {
113
+ console.warn("Failed to decode bonding curve", e);
114
+ return null;
115
+ }
116
+ }
117
+
107
118
  decodeGlobalVolumeAccumulator(
108
119
  accountInfo: AccountInfo<Buffer>,
109
120
  ): GlobalVolumeAccumulator {
@@ -121,6 +132,18 @@ export class PumpSdk {
121
132
  accountInfo.data,
122
133
  );
123
134
  }
135
+
136
+ decodeUserVolumeAccumulatorNullable(
137
+ accountInfo: AccountInfo<Buffer>,
138
+ ): UserVolumeAccumulator | null {
139
+ try {
140
+ return this.decodeUserVolumeAccumulator(accountInfo);
141
+ } catch (e) {
142
+ console.warn("Failed to decode user volume accumulator", e);
143
+ return null;
144
+ }
145
+ }
146
+
124
147
  async fetchGlobal(): Promise<Global> {
125
148
  return await this.pumpProgram.account.global.fetch(globalPda());
126
149
  }