@pump-fun/pump-sdk 1.18.7 → 1.18.8
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 +88 -108
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +88 -108
- package/package.json +1 -1
- package/src/bondingCurve.ts +4 -1
- package/src/fees.ts +0 -25
- package/src/index.ts +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -6526,22 +6526,88 @@ var pump_default = {
|
|
|
6526
6526
|
]
|
|
6527
6527
|
};
|
|
6528
6528
|
|
|
6529
|
-
// src/
|
|
6529
|
+
// src/bondingCurve.ts
|
|
6530
6530
|
import BN2 from "bn.js";
|
|
6531
6531
|
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
6532
6532
|
|
|
6533
|
-
// src/
|
|
6533
|
+
// src/fees.ts
|
|
6534
6534
|
import BN from "bn.js";
|
|
6535
6535
|
import { PublicKey } from "@solana/web3.js";
|
|
6536
|
+
function getFee({
|
|
6537
|
+
global,
|
|
6538
|
+
feeConfig,
|
|
6539
|
+
mintSupply,
|
|
6540
|
+
bondingCurve,
|
|
6541
|
+
amount,
|
|
6542
|
+
isNewBondingCurve
|
|
6543
|
+
}) {
|
|
6544
|
+
const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
|
|
6545
|
+
const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
|
|
6546
|
+
global,
|
|
6547
|
+
feeConfig,
|
|
6548
|
+
mintSupply,
|
|
6549
|
+
virtualSolReserves,
|
|
6550
|
+
virtualTokenReserves
|
|
6551
|
+
});
|
|
6552
|
+
return fee(amount, protocolFeeBps).add(
|
|
6553
|
+
isNewBondingCurve || !PublicKey.default.equals(bondingCurve.creator) ? fee(amount, creatorFeeBps) : new BN(0)
|
|
6554
|
+
);
|
|
6555
|
+
}
|
|
6556
|
+
function computeFeesBps({
|
|
6557
|
+
global,
|
|
6558
|
+
feeConfig,
|
|
6559
|
+
mintSupply,
|
|
6560
|
+
virtualSolReserves,
|
|
6561
|
+
virtualTokenReserves
|
|
6562
|
+
}) {
|
|
6563
|
+
if (feeConfig != null) {
|
|
6564
|
+
const marketCap = bondingCurveMarketCap({
|
|
6565
|
+
mintSupply,
|
|
6566
|
+
virtualSolReserves,
|
|
6567
|
+
virtualTokenReserves
|
|
6568
|
+
});
|
|
6569
|
+
return calculateFeeTier({
|
|
6570
|
+
feeTiers: feeConfig.feeTiers,
|
|
6571
|
+
marketCap
|
|
6572
|
+
});
|
|
6573
|
+
}
|
|
6574
|
+
return {
|
|
6575
|
+
protocolFeeBps: global.feeBasisPoints,
|
|
6576
|
+
creatorFeeBps: global.creatorFeeBasisPoints
|
|
6577
|
+
};
|
|
6578
|
+
}
|
|
6579
|
+
function calculateFeeTier({
|
|
6580
|
+
feeTiers,
|
|
6581
|
+
marketCap
|
|
6582
|
+
}) {
|
|
6583
|
+
const firstTier = feeTiers[0];
|
|
6584
|
+
if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
|
|
6585
|
+
return firstTier.fees;
|
|
6586
|
+
}
|
|
6587
|
+
for (const tier of feeTiers.slice().reverse()) {
|
|
6588
|
+
if (marketCap.gte(tier.marketCapLamportsThreshold)) {
|
|
6589
|
+
return tier.fees;
|
|
6590
|
+
}
|
|
6591
|
+
}
|
|
6592
|
+
return firstTier.fees;
|
|
6593
|
+
}
|
|
6594
|
+
function fee(amount, feeBasisPoints) {
|
|
6595
|
+
return ceilDiv(amount.mul(feeBasisPoints), new BN(1e4));
|
|
6596
|
+
}
|
|
6597
|
+
function ceilDiv(a, b) {
|
|
6598
|
+
return a.add(b.subn(1)).div(b);
|
|
6599
|
+
}
|
|
6600
|
+
|
|
6601
|
+
// src/bondingCurve.ts
|
|
6536
6602
|
function newBondingCurve(global) {
|
|
6537
6603
|
return {
|
|
6538
6604
|
virtualTokenReserves: global.initialVirtualTokenReserves,
|
|
6539
6605
|
virtualSolReserves: global.initialVirtualSolReserves,
|
|
6540
6606
|
realTokenReserves: global.initialRealTokenReserves,
|
|
6541
|
-
realSolReserves: new
|
|
6607
|
+
realSolReserves: new BN2(0),
|
|
6542
6608
|
tokenTotalSupply: global.tokenTotalSupply,
|
|
6543
6609
|
complete: false,
|
|
6544
|
-
creator:
|
|
6610
|
+
creator: PublicKey2.default
|
|
6545
6611
|
};
|
|
6546
6612
|
}
|
|
6547
6613
|
function getBuySolAmountFromTokenAmountQuote({
|
|
@@ -6549,7 +6615,7 @@ function getBuySolAmountFromTokenAmountQuote({
|
|
|
6549
6615
|
virtualTokenReserves,
|
|
6550
6616
|
virtualSolReserves
|
|
6551
6617
|
}) {
|
|
6552
|
-
return minAmount.mul(virtualSolReserves).div(virtualTokenReserves.sub(minAmount)).add(new
|
|
6618
|
+
return minAmount.mul(virtualSolReserves).div(virtualTokenReserves.sub(minAmount)).add(new BN2(1));
|
|
6553
6619
|
}
|
|
6554
6620
|
function getBuyTokenAmountFromSolAmountQuote({
|
|
6555
6621
|
inputAmount,
|
|
@@ -6572,8 +6638,8 @@ function getBuyTokenAmountFromSolAmount({
|
|
|
6572
6638
|
bondingCurve,
|
|
6573
6639
|
amount
|
|
6574
6640
|
}) {
|
|
6575
|
-
if (amount.eq(new
|
|
6576
|
-
return new
|
|
6641
|
+
if (amount.eq(new BN2(0))) {
|
|
6642
|
+
return new BN2(0);
|
|
6577
6643
|
}
|
|
6578
6644
|
let isNewBondingCurve = false;
|
|
6579
6645
|
if (bondingCurve === null || mintSupply === null) {
|
|
@@ -6581,8 +6647,8 @@ function getBuyTokenAmountFromSolAmount({
|
|
|
6581
6647
|
mintSupply = global.tokenTotalSupply;
|
|
6582
6648
|
isNewBondingCurve = true;
|
|
6583
6649
|
}
|
|
6584
|
-
if (bondingCurve.virtualTokenReserves.eq(new
|
|
6585
|
-
return new
|
|
6650
|
+
if (bondingCurve.virtualTokenReserves.eq(new BN2(0))) {
|
|
6651
|
+
return new BN2(0);
|
|
6586
6652
|
}
|
|
6587
6653
|
const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
|
|
6588
6654
|
const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
|
|
@@ -6593,15 +6659,15 @@ function getBuyTokenAmountFromSolAmount({
|
|
|
6593
6659
|
virtualTokenReserves
|
|
6594
6660
|
});
|
|
6595
6661
|
const totalFeeBasisPoints = protocolFeeBps.add(
|
|
6596
|
-
isNewBondingCurve || !
|
|
6662
|
+
isNewBondingCurve || !PublicKey2.default.equals(bondingCurve.creator) ? creatorFeeBps : new BN2(0)
|
|
6597
6663
|
);
|
|
6598
|
-
const inputAmount = amount.muln(1e4).div(totalFeeBasisPoints.addn(1e4));
|
|
6664
|
+
const inputAmount = amount.subn(1).muln(1e4).div(totalFeeBasisPoints.addn(1e4));
|
|
6599
6665
|
const tokensReceived = getBuyTokenAmountFromSolAmountQuote({
|
|
6600
6666
|
inputAmount,
|
|
6601
6667
|
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
6602
6668
|
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
6603
6669
|
});
|
|
6604
|
-
return
|
|
6670
|
+
return BN2.min(tokensReceived, bondingCurve.realTokenReserves);
|
|
6605
6671
|
}
|
|
6606
6672
|
function getBuySolAmountFromTokenAmount({
|
|
6607
6673
|
global,
|
|
@@ -6610,8 +6676,8 @@ function getBuySolAmountFromTokenAmount({
|
|
|
6610
6676
|
bondingCurve,
|
|
6611
6677
|
amount
|
|
6612
6678
|
}) {
|
|
6613
|
-
if (amount.eq(new
|
|
6614
|
-
return new
|
|
6679
|
+
if (amount.eq(new BN2(0))) {
|
|
6680
|
+
return new BN2(0);
|
|
6615
6681
|
}
|
|
6616
6682
|
let isNewBondingCurve = false;
|
|
6617
6683
|
if (bondingCurve === null || mintSupply === null) {
|
|
@@ -6619,10 +6685,10 @@ function getBuySolAmountFromTokenAmount({
|
|
|
6619
6685
|
mintSupply = global.tokenTotalSupply;
|
|
6620
6686
|
isNewBondingCurve = true;
|
|
6621
6687
|
}
|
|
6622
|
-
if (bondingCurve.virtualTokenReserves.eq(new
|
|
6623
|
-
return new
|
|
6688
|
+
if (bondingCurve.virtualTokenReserves.eq(new BN2(0))) {
|
|
6689
|
+
return new BN2(0);
|
|
6624
6690
|
}
|
|
6625
|
-
const minAmount =
|
|
6691
|
+
const minAmount = BN2.min(amount, bondingCurve.realTokenReserves);
|
|
6626
6692
|
const solCost = getBuySolAmountFromTokenAmountQuote({
|
|
6627
6693
|
minAmount,
|
|
6628
6694
|
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
@@ -6646,11 +6712,11 @@ function getSellSolAmountFromTokenAmount({
|
|
|
6646
6712
|
bondingCurve,
|
|
6647
6713
|
amount
|
|
6648
6714
|
}) {
|
|
6649
|
-
if (amount.eq(new
|
|
6650
|
-
return new
|
|
6715
|
+
if (amount.eq(new BN2(0))) {
|
|
6716
|
+
return new BN2(0);
|
|
6651
6717
|
}
|
|
6652
|
-
if (bondingCurve.virtualTokenReserves.eq(new
|
|
6653
|
-
return new
|
|
6718
|
+
if (bondingCurve.virtualTokenReserves.eq(new BN2(0))) {
|
|
6719
|
+
return new BN2(0);
|
|
6654
6720
|
}
|
|
6655
6721
|
const solCost = getSellSolAmountFromTokenAmountQuote({
|
|
6656
6722
|
inputAmount: amount,
|
|
@@ -6670,7 +6736,7 @@ function getSellSolAmountFromTokenAmount({
|
|
|
6670
6736
|
}
|
|
6671
6737
|
function getStaticRandomFeeRecipient() {
|
|
6672
6738
|
const randomIndex = Math.floor(Math.random() * CURRENT_FEE_RECIPIENTS.length);
|
|
6673
|
-
return new
|
|
6739
|
+
return new PublicKey2(CURRENT_FEE_RECIPIENTS[randomIndex]);
|
|
6674
6740
|
}
|
|
6675
6741
|
var CURRENT_FEE_RECIPIENTS = [
|
|
6676
6742
|
"62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV",
|
|
@@ -6693,91 +6759,6 @@ function bondingCurveMarketCap({
|
|
|
6693
6759
|
return virtualSolReserves.mul(mintSupply).div(virtualTokenReserves);
|
|
6694
6760
|
}
|
|
6695
6761
|
|
|
6696
|
-
// src/fees.ts
|
|
6697
|
-
function createFeeConfigFromGlobalConfig(globalConfig) {
|
|
6698
|
-
let fees = {
|
|
6699
|
-
lpFeeBps: new BN2(0),
|
|
6700
|
-
// unused for pump
|
|
6701
|
-
protocolFeeBps: globalConfig.feeBasisPoints,
|
|
6702
|
-
creatorFeeBps: globalConfig.creatorFeeBasisPoints
|
|
6703
|
-
};
|
|
6704
|
-
return {
|
|
6705
|
-
admin: globalConfig.authority,
|
|
6706
|
-
flatFees: fees,
|
|
6707
|
-
feeTiers: [
|
|
6708
|
-
{
|
|
6709
|
-
marketCapLamportsThreshold: new BN2(0),
|
|
6710
|
-
// unused for pump
|
|
6711
|
-
fees
|
|
6712
|
-
}
|
|
6713
|
-
]
|
|
6714
|
-
};
|
|
6715
|
-
}
|
|
6716
|
-
function getFee({
|
|
6717
|
-
global,
|
|
6718
|
-
feeConfig,
|
|
6719
|
-
mintSupply,
|
|
6720
|
-
bondingCurve,
|
|
6721
|
-
amount,
|
|
6722
|
-
isNewBondingCurve
|
|
6723
|
-
}) {
|
|
6724
|
-
const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
|
|
6725
|
-
const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
|
|
6726
|
-
global,
|
|
6727
|
-
feeConfig,
|
|
6728
|
-
mintSupply,
|
|
6729
|
-
virtualSolReserves,
|
|
6730
|
-
virtualTokenReserves
|
|
6731
|
-
});
|
|
6732
|
-
return fee(amount, protocolFeeBps).add(
|
|
6733
|
-
isNewBondingCurve || !PublicKey2.default.equals(bondingCurve.creator) ? fee(amount, creatorFeeBps) : new BN2(0)
|
|
6734
|
-
);
|
|
6735
|
-
}
|
|
6736
|
-
function computeFeesBps({
|
|
6737
|
-
global,
|
|
6738
|
-
feeConfig,
|
|
6739
|
-
mintSupply,
|
|
6740
|
-
virtualSolReserves,
|
|
6741
|
-
virtualTokenReserves
|
|
6742
|
-
}) {
|
|
6743
|
-
if (feeConfig != null) {
|
|
6744
|
-
const marketCap = bondingCurveMarketCap({
|
|
6745
|
-
mintSupply,
|
|
6746
|
-
virtualSolReserves,
|
|
6747
|
-
virtualTokenReserves
|
|
6748
|
-
});
|
|
6749
|
-
return calculateFeeTier({
|
|
6750
|
-
feeTiers: feeConfig.feeTiers,
|
|
6751
|
-
marketCap
|
|
6752
|
-
});
|
|
6753
|
-
}
|
|
6754
|
-
return {
|
|
6755
|
-
protocolFeeBps: global.feeBasisPoints,
|
|
6756
|
-
creatorFeeBps: global.creatorFeeBasisPoints
|
|
6757
|
-
};
|
|
6758
|
-
}
|
|
6759
|
-
function calculateFeeTier({
|
|
6760
|
-
feeTiers,
|
|
6761
|
-
marketCap
|
|
6762
|
-
}) {
|
|
6763
|
-
const firstTier = feeTiers[0];
|
|
6764
|
-
if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
|
|
6765
|
-
return firstTier.fees;
|
|
6766
|
-
}
|
|
6767
|
-
for (const tier of feeTiers.slice().reverse()) {
|
|
6768
|
-
if (marketCap.gte(tier.marketCapLamportsThreshold)) {
|
|
6769
|
-
return tier.fees;
|
|
6770
|
-
}
|
|
6771
|
-
}
|
|
6772
|
-
return firstTier.fees;
|
|
6773
|
-
}
|
|
6774
|
-
function fee(amount, feeBasisPoints) {
|
|
6775
|
-
return ceilDiv(amount.mul(feeBasisPoints), new BN2(1e4));
|
|
6776
|
-
}
|
|
6777
|
-
function ceilDiv(a, b) {
|
|
6778
|
-
return a.add(b.subn(1)).div(b);
|
|
6779
|
-
}
|
|
6780
|
-
|
|
6781
6762
|
// src/pda.ts
|
|
6782
6763
|
import { PublicKey as PublicKey5 } from "@solana/web3.js";
|
|
6783
6764
|
import { NATIVE_MINT as NATIVE_MINT2 } from "@solana/spl-token";
|
|
@@ -7540,7 +7521,6 @@ export {
|
|
|
7540
7521
|
bondingCurveMarketCap,
|
|
7541
7522
|
bondingCurvePda,
|
|
7542
7523
|
canonicalPumpPoolPda,
|
|
7543
|
-
createFeeConfigFromGlobalConfig,
|
|
7544
7524
|
creatorVaultPda,
|
|
7545
7525
|
currentDayTokens,
|
|
7546
7526
|
getBuySolAmountFromTokenAmount,
|
package/dist/index.d.mts
CHANGED
|
@@ -9537,8 +9537,6 @@ interface Fees {
|
|
|
9537
9537
|
creatorFeeBps: BN;
|
|
9538
9538
|
}
|
|
9539
9539
|
|
|
9540
|
-
declare function createFeeConfigFromGlobalConfig(globalConfig: Global): FeeConfig;
|
|
9541
|
-
|
|
9542
9540
|
declare function newBondingCurve(global: Global): BondingCurve;
|
|
9543
9541
|
declare function getBuySolAmountFromTokenAmountQuote({ minAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9544
9542
|
minAmount: BN;
|
|
@@ -9729,4 +9727,4 @@ declare class OnlinePumpSdk {
|
|
|
9729
9727
|
declare function totalUnclaimedTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9730
9728
|
declare function currentDayTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9731
9729
|
|
|
9732
|
-
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type FeeConfig, GLOBAL_PDA, GLOBAL_VOLUME_ACCUMULATOR_PDA, type Global, type GlobalVolumeAccumulator, OnlinePumpSdk, PUMP_AMM_PROGRAM_ID, PUMP_FEE_CONFIG_PDA, PUMP_PROGRAM_ID, PUMP_SDK, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurveMarketCap, bondingCurvePda, canonicalPumpPoolPda,
|
|
9730
|
+
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type FeeConfig, GLOBAL_PDA, GLOBAL_VOLUME_ACCUMULATOR_PDA, type Global, type GlobalVolumeAccumulator, OnlinePumpSdk, PUMP_AMM_PROGRAM_ID, PUMP_FEE_CONFIG_PDA, PUMP_PROGRAM_ID, PUMP_SDK, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurveMarketCap, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, currentDayTokens, getBuySolAmountFromTokenAmount, getBuySolAmountFromTokenAmountQuote, getBuyTokenAmountFromSolAmount, getBuyTokenAmountFromSolAmountQuote, getPumpProgram, getSellSolAmountFromTokenAmount, getSellSolAmountFromTokenAmountQuote, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, totalUnclaimedTokens, userVolumeAccumulatorPda };
|
package/dist/index.d.ts
CHANGED
|
@@ -9537,8 +9537,6 @@ interface Fees {
|
|
|
9537
9537
|
creatorFeeBps: BN;
|
|
9538
9538
|
}
|
|
9539
9539
|
|
|
9540
|
-
declare function createFeeConfigFromGlobalConfig(globalConfig: Global): FeeConfig;
|
|
9541
|
-
|
|
9542
9540
|
declare function newBondingCurve(global: Global): BondingCurve;
|
|
9543
9541
|
declare function getBuySolAmountFromTokenAmountQuote({ minAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9544
9542
|
minAmount: BN;
|
|
@@ -9729,4 +9727,4 @@ declare class OnlinePumpSdk {
|
|
|
9729
9727
|
declare function totalUnclaimedTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9730
9728
|
declare function currentDayTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9731
9729
|
|
|
9732
|
-
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type FeeConfig, GLOBAL_PDA, GLOBAL_VOLUME_ACCUMULATOR_PDA, type Global, type GlobalVolumeAccumulator, OnlinePumpSdk, PUMP_AMM_PROGRAM_ID, PUMP_FEE_CONFIG_PDA, PUMP_PROGRAM_ID, PUMP_SDK, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurveMarketCap, bondingCurvePda, canonicalPumpPoolPda,
|
|
9730
|
+
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type FeeConfig, GLOBAL_PDA, GLOBAL_VOLUME_ACCUMULATOR_PDA, type Global, type GlobalVolumeAccumulator, OnlinePumpSdk, PUMP_AMM_PROGRAM_ID, PUMP_FEE_CONFIG_PDA, PUMP_PROGRAM_ID, PUMP_SDK, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurveMarketCap, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, currentDayTokens, getBuySolAmountFromTokenAmount, getBuySolAmountFromTokenAmountQuote, getBuyTokenAmountFromSolAmount, getBuyTokenAmountFromSolAmountQuote, getPumpProgram, getSellSolAmountFromTokenAmount, getSellSolAmountFromTokenAmountQuote, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, totalUnclaimedTokens, userVolumeAccumulatorPda };
|
package/dist/index.js
CHANGED
|
@@ -1823,7 +1823,6 @@ __export(index_exports, {
|
|
|
1823
1823
|
bondingCurveMarketCap: () => bondingCurveMarketCap,
|
|
1824
1824
|
bondingCurvePda: () => bondingCurvePda,
|
|
1825
1825
|
canonicalPumpPoolPda: () => canonicalPumpPoolPda,
|
|
1826
|
-
createFeeConfigFromGlobalConfig: () => createFeeConfigFromGlobalConfig,
|
|
1827
1826
|
creatorVaultPda: () => creatorVaultPda,
|
|
1828
1827
|
currentDayTokens: () => currentDayTokens,
|
|
1829
1828
|
getBuySolAmountFromTokenAmount: () => getBuySolAmountFromTokenAmount,
|
|
@@ -6566,22 +6565,88 @@ var pump_default = {
|
|
|
6566
6565
|
]
|
|
6567
6566
|
};
|
|
6568
6567
|
|
|
6569
|
-
// src/
|
|
6568
|
+
// src/bondingCurve.ts
|
|
6570
6569
|
var import_bn2 = __toESM(require("bn.js"));
|
|
6571
6570
|
var import_web32 = require("@solana/web3.js");
|
|
6572
6571
|
|
|
6573
|
-
// src/
|
|
6572
|
+
// src/fees.ts
|
|
6574
6573
|
var import_bn = __toESM(require("bn.js"));
|
|
6575
6574
|
var import_web3 = require("@solana/web3.js");
|
|
6575
|
+
function getFee({
|
|
6576
|
+
global,
|
|
6577
|
+
feeConfig,
|
|
6578
|
+
mintSupply,
|
|
6579
|
+
bondingCurve,
|
|
6580
|
+
amount,
|
|
6581
|
+
isNewBondingCurve
|
|
6582
|
+
}) {
|
|
6583
|
+
const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
|
|
6584
|
+
const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
|
|
6585
|
+
global,
|
|
6586
|
+
feeConfig,
|
|
6587
|
+
mintSupply,
|
|
6588
|
+
virtualSolReserves,
|
|
6589
|
+
virtualTokenReserves
|
|
6590
|
+
});
|
|
6591
|
+
return fee(amount, protocolFeeBps).add(
|
|
6592
|
+
isNewBondingCurve || !import_web3.PublicKey.default.equals(bondingCurve.creator) ? fee(amount, creatorFeeBps) : new import_bn.default(0)
|
|
6593
|
+
);
|
|
6594
|
+
}
|
|
6595
|
+
function computeFeesBps({
|
|
6596
|
+
global,
|
|
6597
|
+
feeConfig,
|
|
6598
|
+
mintSupply,
|
|
6599
|
+
virtualSolReserves,
|
|
6600
|
+
virtualTokenReserves
|
|
6601
|
+
}) {
|
|
6602
|
+
if (feeConfig != null) {
|
|
6603
|
+
const marketCap = bondingCurveMarketCap({
|
|
6604
|
+
mintSupply,
|
|
6605
|
+
virtualSolReserves,
|
|
6606
|
+
virtualTokenReserves
|
|
6607
|
+
});
|
|
6608
|
+
return calculateFeeTier({
|
|
6609
|
+
feeTiers: feeConfig.feeTiers,
|
|
6610
|
+
marketCap
|
|
6611
|
+
});
|
|
6612
|
+
}
|
|
6613
|
+
return {
|
|
6614
|
+
protocolFeeBps: global.feeBasisPoints,
|
|
6615
|
+
creatorFeeBps: global.creatorFeeBasisPoints
|
|
6616
|
+
};
|
|
6617
|
+
}
|
|
6618
|
+
function calculateFeeTier({
|
|
6619
|
+
feeTiers,
|
|
6620
|
+
marketCap
|
|
6621
|
+
}) {
|
|
6622
|
+
const firstTier = feeTiers[0];
|
|
6623
|
+
if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
|
|
6624
|
+
return firstTier.fees;
|
|
6625
|
+
}
|
|
6626
|
+
for (const tier of feeTiers.slice().reverse()) {
|
|
6627
|
+
if (marketCap.gte(tier.marketCapLamportsThreshold)) {
|
|
6628
|
+
return tier.fees;
|
|
6629
|
+
}
|
|
6630
|
+
}
|
|
6631
|
+
return firstTier.fees;
|
|
6632
|
+
}
|
|
6633
|
+
function fee(amount, feeBasisPoints) {
|
|
6634
|
+
return ceilDiv(amount.mul(feeBasisPoints), new import_bn.default(1e4));
|
|
6635
|
+
}
|
|
6636
|
+
function ceilDiv(a, b) {
|
|
6637
|
+
return a.add(b.subn(1)).div(b);
|
|
6638
|
+
}
|
|
6639
|
+
|
|
6640
|
+
// src/bondingCurve.ts
|
|
6576
6641
|
function newBondingCurve(global) {
|
|
6577
6642
|
return {
|
|
6578
6643
|
virtualTokenReserves: global.initialVirtualTokenReserves,
|
|
6579
6644
|
virtualSolReserves: global.initialVirtualSolReserves,
|
|
6580
6645
|
realTokenReserves: global.initialRealTokenReserves,
|
|
6581
|
-
realSolReserves: new
|
|
6646
|
+
realSolReserves: new import_bn2.default(0),
|
|
6582
6647
|
tokenTotalSupply: global.tokenTotalSupply,
|
|
6583
6648
|
complete: false,
|
|
6584
|
-
creator:
|
|
6649
|
+
creator: import_web32.PublicKey.default
|
|
6585
6650
|
};
|
|
6586
6651
|
}
|
|
6587
6652
|
function getBuySolAmountFromTokenAmountQuote({
|
|
@@ -6589,7 +6654,7 @@ function getBuySolAmountFromTokenAmountQuote({
|
|
|
6589
6654
|
virtualTokenReserves,
|
|
6590
6655
|
virtualSolReserves
|
|
6591
6656
|
}) {
|
|
6592
|
-
return minAmount.mul(virtualSolReserves).div(virtualTokenReserves.sub(minAmount)).add(new
|
|
6657
|
+
return minAmount.mul(virtualSolReserves).div(virtualTokenReserves.sub(minAmount)).add(new import_bn2.default(1));
|
|
6593
6658
|
}
|
|
6594
6659
|
function getBuyTokenAmountFromSolAmountQuote({
|
|
6595
6660
|
inputAmount,
|
|
@@ -6612,8 +6677,8 @@ function getBuyTokenAmountFromSolAmount({
|
|
|
6612
6677
|
bondingCurve,
|
|
6613
6678
|
amount
|
|
6614
6679
|
}) {
|
|
6615
|
-
if (amount.eq(new
|
|
6616
|
-
return new
|
|
6680
|
+
if (amount.eq(new import_bn2.default(0))) {
|
|
6681
|
+
return new import_bn2.default(0);
|
|
6617
6682
|
}
|
|
6618
6683
|
let isNewBondingCurve = false;
|
|
6619
6684
|
if (bondingCurve === null || mintSupply === null) {
|
|
@@ -6621,8 +6686,8 @@ function getBuyTokenAmountFromSolAmount({
|
|
|
6621
6686
|
mintSupply = global.tokenTotalSupply;
|
|
6622
6687
|
isNewBondingCurve = true;
|
|
6623
6688
|
}
|
|
6624
|
-
if (bondingCurve.virtualTokenReserves.eq(new
|
|
6625
|
-
return new
|
|
6689
|
+
if (bondingCurve.virtualTokenReserves.eq(new import_bn2.default(0))) {
|
|
6690
|
+
return new import_bn2.default(0);
|
|
6626
6691
|
}
|
|
6627
6692
|
const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
|
|
6628
6693
|
const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
|
|
@@ -6633,15 +6698,15 @@ function getBuyTokenAmountFromSolAmount({
|
|
|
6633
6698
|
virtualTokenReserves
|
|
6634
6699
|
});
|
|
6635
6700
|
const totalFeeBasisPoints = protocolFeeBps.add(
|
|
6636
|
-
isNewBondingCurve || !
|
|
6701
|
+
isNewBondingCurve || !import_web32.PublicKey.default.equals(bondingCurve.creator) ? creatorFeeBps : new import_bn2.default(0)
|
|
6637
6702
|
);
|
|
6638
|
-
const inputAmount = amount.muln(1e4).div(totalFeeBasisPoints.addn(1e4));
|
|
6703
|
+
const inputAmount = amount.subn(1).muln(1e4).div(totalFeeBasisPoints.addn(1e4));
|
|
6639
6704
|
const tokensReceived = getBuyTokenAmountFromSolAmountQuote({
|
|
6640
6705
|
inputAmount,
|
|
6641
6706
|
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
6642
6707
|
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
6643
6708
|
});
|
|
6644
|
-
return
|
|
6709
|
+
return import_bn2.default.min(tokensReceived, bondingCurve.realTokenReserves);
|
|
6645
6710
|
}
|
|
6646
6711
|
function getBuySolAmountFromTokenAmount({
|
|
6647
6712
|
global,
|
|
@@ -6650,8 +6715,8 @@ function getBuySolAmountFromTokenAmount({
|
|
|
6650
6715
|
bondingCurve,
|
|
6651
6716
|
amount
|
|
6652
6717
|
}) {
|
|
6653
|
-
if (amount.eq(new
|
|
6654
|
-
return new
|
|
6718
|
+
if (amount.eq(new import_bn2.default(0))) {
|
|
6719
|
+
return new import_bn2.default(0);
|
|
6655
6720
|
}
|
|
6656
6721
|
let isNewBondingCurve = false;
|
|
6657
6722
|
if (bondingCurve === null || mintSupply === null) {
|
|
@@ -6659,10 +6724,10 @@ function getBuySolAmountFromTokenAmount({
|
|
|
6659
6724
|
mintSupply = global.tokenTotalSupply;
|
|
6660
6725
|
isNewBondingCurve = true;
|
|
6661
6726
|
}
|
|
6662
|
-
if (bondingCurve.virtualTokenReserves.eq(new
|
|
6663
|
-
return new
|
|
6727
|
+
if (bondingCurve.virtualTokenReserves.eq(new import_bn2.default(0))) {
|
|
6728
|
+
return new import_bn2.default(0);
|
|
6664
6729
|
}
|
|
6665
|
-
const minAmount =
|
|
6730
|
+
const minAmount = import_bn2.default.min(amount, bondingCurve.realTokenReserves);
|
|
6666
6731
|
const solCost = getBuySolAmountFromTokenAmountQuote({
|
|
6667
6732
|
minAmount,
|
|
6668
6733
|
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
@@ -6686,11 +6751,11 @@ function getSellSolAmountFromTokenAmount({
|
|
|
6686
6751
|
bondingCurve,
|
|
6687
6752
|
amount
|
|
6688
6753
|
}) {
|
|
6689
|
-
if (amount.eq(new
|
|
6690
|
-
return new
|
|
6754
|
+
if (amount.eq(new import_bn2.default(0))) {
|
|
6755
|
+
return new import_bn2.default(0);
|
|
6691
6756
|
}
|
|
6692
|
-
if (bondingCurve.virtualTokenReserves.eq(new
|
|
6693
|
-
return new
|
|
6757
|
+
if (bondingCurve.virtualTokenReserves.eq(new import_bn2.default(0))) {
|
|
6758
|
+
return new import_bn2.default(0);
|
|
6694
6759
|
}
|
|
6695
6760
|
const solCost = getSellSolAmountFromTokenAmountQuote({
|
|
6696
6761
|
inputAmount: amount,
|
|
@@ -6710,7 +6775,7 @@ function getSellSolAmountFromTokenAmount({
|
|
|
6710
6775
|
}
|
|
6711
6776
|
function getStaticRandomFeeRecipient() {
|
|
6712
6777
|
const randomIndex = Math.floor(Math.random() * CURRENT_FEE_RECIPIENTS.length);
|
|
6713
|
-
return new
|
|
6778
|
+
return new import_web32.PublicKey(CURRENT_FEE_RECIPIENTS[randomIndex]);
|
|
6714
6779
|
}
|
|
6715
6780
|
var CURRENT_FEE_RECIPIENTS = [
|
|
6716
6781
|
"62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV",
|
|
@@ -6733,91 +6798,6 @@ function bondingCurveMarketCap({
|
|
|
6733
6798
|
return virtualSolReserves.mul(mintSupply).div(virtualTokenReserves);
|
|
6734
6799
|
}
|
|
6735
6800
|
|
|
6736
|
-
// src/fees.ts
|
|
6737
|
-
function createFeeConfigFromGlobalConfig(globalConfig) {
|
|
6738
|
-
let fees = {
|
|
6739
|
-
lpFeeBps: new import_bn2.default(0),
|
|
6740
|
-
// unused for pump
|
|
6741
|
-
protocolFeeBps: globalConfig.feeBasisPoints,
|
|
6742
|
-
creatorFeeBps: globalConfig.creatorFeeBasisPoints
|
|
6743
|
-
};
|
|
6744
|
-
return {
|
|
6745
|
-
admin: globalConfig.authority,
|
|
6746
|
-
flatFees: fees,
|
|
6747
|
-
feeTiers: [
|
|
6748
|
-
{
|
|
6749
|
-
marketCapLamportsThreshold: new import_bn2.default(0),
|
|
6750
|
-
// unused for pump
|
|
6751
|
-
fees
|
|
6752
|
-
}
|
|
6753
|
-
]
|
|
6754
|
-
};
|
|
6755
|
-
}
|
|
6756
|
-
function getFee({
|
|
6757
|
-
global,
|
|
6758
|
-
feeConfig,
|
|
6759
|
-
mintSupply,
|
|
6760
|
-
bondingCurve,
|
|
6761
|
-
amount,
|
|
6762
|
-
isNewBondingCurve
|
|
6763
|
-
}) {
|
|
6764
|
-
const { virtualSolReserves, virtualTokenReserves } = bondingCurve;
|
|
6765
|
-
const { protocolFeeBps, creatorFeeBps } = computeFeesBps({
|
|
6766
|
-
global,
|
|
6767
|
-
feeConfig,
|
|
6768
|
-
mintSupply,
|
|
6769
|
-
virtualSolReserves,
|
|
6770
|
-
virtualTokenReserves
|
|
6771
|
-
});
|
|
6772
|
-
return fee(amount, protocolFeeBps).add(
|
|
6773
|
-
isNewBondingCurve || !import_web32.PublicKey.default.equals(bondingCurve.creator) ? fee(amount, creatorFeeBps) : new import_bn2.default(0)
|
|
6774
|
-
);
|
|
6775
|
-
}
|
|
6776
|
-
function computeFeesBps({
|
|
6777
|
-
global,
|
|
6778
|
-
feeConfig,
|
|
6779
|
-
mintSupply,
|
|
6780
|
-
virtualSolReserves,
|
|
6781
|
-
virtualTokenReserves
|
|
6782
|
-
}) {
|
|
6783
|
-
if (feeConfig != null) {
|
|
6784
|
-
const marketCap = bondingCurveMarketCap({
|
|
6785
|
-
mintSupply,
|
|
6786
|
-
virtualSolReserves,
|
|
6787
|
-
virtualTokenReserves
|
|
6788
|
-
});
|
|
6789
|
-
return calculateFeeTier({
|
|
6790
|
-
feeTiers: feeConfig.feeTiers,
|
|
6791
|
-
marketCap
|
|
6792
|
-
});
|
|
6793
|
-
}
|
|
6794
|
-
return {
|
|
6795
|
-
protocolFeeBps: global.feeBasisPoints,
|
|
6796
|
-
creatorFeeBps: global.creatorFeeBasisPoints
|
|
6797
|
-
};
|
|
6798
|
-
}
|
|
6799
|
-
function calculateFeeTier({
|
|
6800
|
-
feeTiers,
|
|
6801
|
-
marketCap
|
|
6802
|
-
}) {
|
|
6803
|
-
const firstTier = feeTiers[0];
|
|
6804
|
-
if (marketCap.lt(firstTier.marketCapLamportsThreshold)) {
|
|
6805
|
-
return firstTier.fees;
|
|
6806
|
-
}
|
|
6807
|
-
for (const tier of feeTiers.slice().reverse()) {
|
|
6808
|
-
if (marketCap.gte(tier.marketCapLamportsThreshold)) {
|
|
6809
|
-
return tier.fees;
|
|
6810
|
-
}
|
|
6811
|
-
}
|
|
6812
|
-
return firstTier.fees;
|
|
6813
|
-
}
|
|
6814
|
-
function fee(amount, feeBasisPoints) {
|
|
6815
|
-
return ceilDiv(amount.mul(feeBasisPoints), new import_bn2.default(1e4));
|
|
6816
|
-
}
|
|
6817
|
-
function ceilDiv(a, b) {
|
|
6818
|
-
return a.add(b.subn(1)).div(b);
|
|
6819
|
-
}
|
|
6820
|
-
|
|
6821
6801
|
// src/pda.ts
|
|
6822
6802
|
var import_web35 = require("@solana/web3.js");
|
|
6823
6803
|
var import_spl_token3 = require("@solana/spl-token");
|
package/package.json
CHANGED
package/src/bondingCurve.ts
CHANGED
|
@@ -103,7 +103,10 @@ export function getBuyTokenAmountFromSolAmount({
|
|
|
103
103
|
: new BN(0),
|
|
104
104
|
);
|
|
105
105
|
|
|
106
|
-
const inputAmount = amount
|
|
106
|
+
const inputAmount = amount
|
|
107
|
+
.subn(1)
|
|
108
|
+
.muln(10_000)
|
|
109
|
+
.div(totalFeeBasisPoints.addn(10_000));
|
|
107
110
|
|
|
108
111
|
const tokensReceived = getBuyTokenAmountFromSolAmountQuote({
|
|
109
112
|
inputAmount,
|
package/src/fees.ts
CHANGED
|
@@ -8,31 +8,6 @@ export interface CalculatedFeesBps {
|
|
|
8
8
|
creatorFeeBps: BN;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export interface CalculatedFees {
|
|
12
|
-
protocolFee: BN;
|
|
13
|
-
creatorFee: BN;
|
|
14
|
-
}
|
|
15
|
-
|
|
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
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
11
|
export function getFee({
|
|
37
12
|
global,
|
|
38
13
|
feeConfig,
|