@pump-fun/pump-sdk 1.15.0 → 1.16.0-devnet.1
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 +140 -28
- package/dist/index.d.mts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +140 -28
- package/package.json +1 -1
- package/src/bondingCurve.ts +74 -10
- package/src/index.ts +3 -0
- package/src/sdk.ts +125 -33
package/dist/esm/index.js
CHANGED
|
@@ -4524,6 +4524,27 @@ function newBondingCurve(global) {
|
|
|
4524
4524
|
creator: PublicKey.default
|
|
4525
4525
|
};
|
|
4526
4526
|
}
|
|
4527
|
+
function getBuySolAmountFromTokenAmountQuote({
|
|
4528
|
+
minAmount,
|
|
4529
|
+
virtualTokenReserves,
|
|
4530
|
+
virtualSolReserves
|
|
4531
|
+
}) {
|
|
4532
|
+
return minAmount.mul(virtualSolReserves).div(virtualTokenReserves.sub(minAmount)).add(new BN(1));
|
|
4533
|
+
}
|
|
4534
|
+
function getBuyTokenAmountFromSolAmountQuote({
|
|
4535
|
+
inputAmount,
|
|
4536
|
+
virtualTokenReserves,
|
|
4537
|
+
virtualSolReserves
|
|
4538
|
+
}) {
|
|
4539
|
+
return inputAmount.mul(virtualTokenReserves).div(virtualSolReserves.add(inputAmount));
|
|
4540
|
+
}
|
|
4541
|
+
function getSellTokenAmountFromSolAmountQuote({
|
|
4542
|
+
inputAmount,
|
|
4543
|
+
virtualTokenReserves,
|
|
4544
|
+
virtualSolReserves
|
|
4545
|
+
}) {
|
|
4546
|
+
return inputAmount.mul(virtualSolReserves).div(virtualTokenReserves.add(inputAmount));
|
|
4547
|
+
}
|
|
4527
4548
|
function getBuyTokenAmountFromSolAmount(global, bondingCurve, amount) {
|
|
4528
4549
|
if (amount.eq(new BN(0))) {
|
|
4529
4550
|
return new BN(0);
|
|
@@ -4540,7 +4561,11 @@ function getBuyTokenAmountFromSolAmount(global, bondingCurve, amount) {
|
|
|
4540
4561
|
isNewBondingCurve || !PublicKey.default.equals(bondingCurve.creator) ? global.creatorFeeBasisPoints : new BN(0)
|
|
4541
4562
|
);
|
|
4542
4563
|
const inputAmount = amount.muln(1e4).div(totalFeeBasisPoints.addn(1e4));
|
|
4543
|
-
const tokensReceived =
|
|
4564
|
+
const tokensReceived = getBuyTokenAmountFromSolAmountQuote({
|
|
4565
|
+
inputAmount,
|
|
4566
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
4567
|
+
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
4568
|
+
});
|
|
4544
4569
|
return BN.min(tokensReceived, bondingCurve.realTokenReserves);
|
|
4545
4570
|
}
|
|
4546
4571
|
function getBuySolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
@@ -4556,7 +4581,11 @@ function getBuySolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
|
4556
4581
|
return new BN(0);
|
|
4557
4582
|
}
|
|
4558
4583
|
const minAmount = BN.min(amount, bondingCurve.realTokenReserves);
|
|
4559
|
-
const solCost =
|
|
4584
|
+
const solCost = getBuySolAmountFromTokenAmountQuote({
|
|
4585
|
+
minAmount,
|
|
4586
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
4587
|
+
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
4588
|
+
});
|
|
4560
4589
|
return solCost.add(getFee(global, bondingCurve, solCost, isNewBondingCurve));
|
|
4561
4590
|
}
|
|
4562
4591
|
function getSellSolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
@@ -4566,9 +4595,27 @@ function getSellSolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
|
4566
4595
|
if (bondingCurve.virtualTokenReserves.eq(new BN(0))) {
|
|
4567
4596
|
return new BN(0);
|
|
4568
4597
|
}
|
|
4569
|
-
const solCost =
|
|
4598
|
+
const solCost = getSellTokenAmountFromSolAmountQuote({
|
|
4599
|
+
inputAmount: amount,
|
|
4600
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
4601
|
+
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
4602
|
+
});
|
|
4570
4603
|
return solCost.sub(getFee(global, bondingCurve, solCost, false));
|
|
4571
4604
|
}
|
|
4605
|
+
function getStaticRandomFeeRecipient() {
|
|
4606
|
+
const randomIndex = Math.floor(Math.random() * CURRENT_FEE_RECIPIENTS.length);
|
|
4607
|
+
return new PublicKey(CURRENT_FEE_RECIPIENTS[randomIndex]);
|
|
4608
|
+
}
|
|
4609
|
+
var CURRENT_FEE_RECIPIENTS = [
|
|
4610
|
+
"62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV",
|
|
4611
|
+
"7VtfL8fvgNfhz17qKRMjzQEXgbdpnHHHQRh54R9jP2RJ",
|
|
4612
|
+
"7hTckgnGnLQR6sdH7YkqFTAA7VwTfYFaZ6EhEsU3saCX",
|
|
4613
|
+
"9rPYyANsfQZw3DnDmKE3YCQF5E8oD89UXoHn9JFEhJUz",
|
|
4614
|
+
"AVmoTthdrX6tKt4nDjco2D775W2YK3sDhxPcMmzUAmTY",
|
|
4615
|
+
"CebN5WGQ4jvEPvsVU4EoHEpgzq1VV7AbicfhtW4xC9iM",
|
|
4616
|
+
"FWsW1xNtWscwNmKv6wVsU1iTzRN6wmmk3MjxRP5tT7hz",
|
|
4617
|
+
"G5UZAVbAf46s7cKWoyKu8kYTip9DGTpbLZ2qa9Aq69dP"
|
|
4618
|
+
];
|
|
4572
4619
|
|
|
4573
4620
|
// src/pda.ts
|
|
4574
4621
|
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
@@ -4883,19 +4930,17 @@ var PumpSdk = class {
|
|
|
4883
4930
|
solAmount,
|
|
4884
4931
|
slippage
|
|
4885
4932
|
}) {
|
|
4886
|
-
return await this.
|
|
4933
|
+
return await this.getBuyInstructionInternal({
|
|
4934
|
+
user,
|
|
4935
|
+
associatedUser,
|
|
4936
|
+
mint,
|
|
4937
|
+
creator,
|
|
4938
|
+
feeRecipient: getFeeRecipient(global),
|
|
4887
4939
|
amount,
|
|
4888
|
-
solAmount.add(
|
|
4940
|
+
solAmount: solAmount.add(
|
|
4889
4941
|
solAmount.mul(new BN3(Math.floor(slippage * 10))).div(new BN3(1e3))
|
|
4890
|
-
)
|
|
4891
|
-
|
|
4892
|
-
).accountsPartial({
|
|
4893
|
-
feeRecipient: getFeeRecipient(global),
|
|
4894
|
-
mint,
|
|
4895
|
-
associatedUser,
|
|
4896
|
-
user,
|
|
4897
|
-
creatorVault: creatorVaultPda(creator)
|
|
4898
|
-
}).instruction();
|
|
4942
|
+
)
|
|
4943
|
+
});
|
|
4899
4944
|
}
|
|
4900
4945
|
async sellInstructions({
|
|
4901
4946
|
global,
|
|
@@ -4917,18 +4962,16 @@ var PumpSdk = class {
|
|
|
4917
4962
|
);
|
|
4918
4963
|
}
|
|
4919
4964
|
instructions.push(
|
|
4920
|
-
await this.
|
|
4965
|
+
await this.getSellInstructionInternal({
|
|
4966
|
+
user,
|
|
4967
|
+
mint,
|
|
4968
|
+
creator: bondingCurve.creator,
|
|
4969
|
+
feeRecipient: getFeeRecipient(global),
|
|
4921
4970
|
amount,
|
|
4922
|
-
solAmount.sub(
|
|
4971
|
+
solAmount: solAmount.sub(
|
|
4923
4972
|
solAmount.mul(new BN3(Math.floor(slippage * 10))).div(new BN3(1e3))
|
|
4924
4973
|
)
|
|
4925
|
-
)
|
|
4926
|
-
feeRecipient: getFeeRecipient(global),
|
|
4927
|
-
mint,
|
|
4928
|
-
associatedUser: getAssociatedTokenAddressSync(mint, user, true),
|
|
4929
|
-
user,
|
|
4930
|
-
creatorVault: creatorVaultPda(bondingCurve.creator)
|
|
4931
|
-
}).instruction()
|
|
4974
|
+
})
|
|
4932
4975
|
);
|
|
4933
4976
|
return instructions;
|
|
4934
4977
|
}
|
|
@@ -5153,6 +5196,72 @@ var PumpSdk = class {
|
|
|
5153
5196
|
async closeUserVolumeAccumulator(user) {
|
|
5154
5197
|
return await this.offlinePumpProgram.methods.closeUserVolumeAccumulator().accountsPartial({ user }).instruction();
|
|
5155
5198
|
}
|
|
5199
|
+
async getBuyInstructionRaw({
|
|
5200
|
+
user,
|
|
5201
|
+
mint,
|
|
5202
|
+
creator,
|
|
5203
|
+
amount,
|
|
5204
|
+
solAmount
|
|
5205
|
+
}) {
|
|
5206
|
+
return await this.getBuyInstructionInternal({
|
|
5207
|
+
user,
|
|
5208
|
+
associatedUser: getAssociatedTokenAddressSync(mint, user, true),
|
|
5209
|
+
mint,
|
|
5210
|
+
creator,
|
|
5211
|
+
feeRecipient: getStaticRandomFeeRecipient(),
|
|
5212
|
+
amount,
|
|
5213
|
+
solAmount
|
|
5214
|
+
});
|
|
5215
|
+
}
|
|
5216
|
+
async getBuyInstructionInternal({
|
|
5217
|
+
user,
|
|
5218
|
+
associatedUser,
|
|
5219
|
+
mint,
|
|
5220
|
+
creator,
|
|
5221
|
+
feeRecipient,
|
|
5222
|
+
amount,
|
|
5223
|
+
solAmount
|
|
5224
|
+
}) {
|
|
5225
|
+
return await this.offlinePumpProgram.methods.buy(amount, solAmount, { 0: true }).accountsPartial({
|
|
5226
|
+
feeRecipient,
|
|
5227
|
+
mint,
|
|
5228
|
+
associatedUser,
|
|
5229
|
+
user,
|
|
5230
|
+
creatorVault: creatorVaultPda(creator)
|
|
5231
|
+
}).instruction();
|
|
5232
|
+
}
|
|
5233
|
+
async getSellInstructionRaw({
|
|
5234
|
+
user,
|
|
5235
|
+
mint,
|
|
5236
|
+
creator,
|
|
5237
|
+
amount,
|
|
5238
|
+
solAmount
|
|
5239
|
+
}) {
|
|
5240
|
+
return await this.getSellInstructionInternal({
|
|
5241
|
+
user,
|
|
5242
|
+
mint,
|
|
5243
|
+
creator,
|
|
5244
|
+
feeRecipient: getStaticRandomFeeRecipient(),
|
|
5245
|
+
amount,
|
|
5246
|
+
solAmount
|
|
5247
|
+
});
|
|
5248
|
+
}
|
|
5249
|
+
async getSellInstructionInternal({
|
|
5250
|
+
user,
|
|
5251
|
+
mint,
|
|
5252
|
+
creator,
|
|
5253
|
+
feeRecipient,
|
|
5254
|
+
amount,
|
|
5255
|
+
solAmount
|
|
5256
|
+
}) {
|
|
5257
|
+
return await this.offlinePumpProgram.methods.sell(amount, solAmount).accountsPartial({
|
|
5258
|
+
feeRecipient,
|
|
5259
|
+
mint,
|
|
5260
|
+
associatedUser: getAssociatedTokenAddressSync(mint, user, true),
|
|
5261
|
+
user,
|
|
5262
|
+
creatorVault: creatorVaultPda(creator)
|
|
5263
|
+
}).instruction();
|
|
5264
|
+
}
|
|
5156
5265
|
};
|
|
5157
5266
|
function getFeeRecipient(global) {
|
|
5158
5267
|
const feeRecipients = [global.feeRecipient, ...global.feeRecipients];
|
|
@@ -5181,15 +5290,15 @@ function creatorVaultPda(creator) {
|
|
|
5181
5290
|
);
|
|
5182
5291
|
return creatorVault;
|
|
5183
5292
|
}
|
|
5184
|
-
function
|
|
5293
|
+
function pumpPoolAuthorityPda(mint) {
|
|
5185
5294
|
return PublicKey3.findProgramAddressSync(
|
|
5186
5295
|
[Buffer.from("pool-authority"), mint.toBuffer()],
|
|
5187
5296
|
PUMP_PROGRAM_ID
|
|
5188
5297
|
);
|
|
5189
5298
|
}
|
|
5190
5299
|
var CANONICAL_POOL_INDEX = 0;
|
|
5191
|
-
function
|
|
5192
|
-
const [pumpPoolAuthority] =
|
|
5300
|
+
function canonicalPumpPoolPda(mint) {
|
|
5301
|
+
const [pumpPoolAuthority] = pumpPoolAuthorityPda(mint);
|
|
5193
5302
|
return poolPda(
|
|
5194
5303
|
CANONICAL_POOL_INDEX,
|
|
5195
5304
|
pumpPoolAuthority,
|
|
@@ -5217,18 +5326,21 @@ export {
|
|
|
5217
5326
|
PUMP_PROGRAM_ID,
|
|
5218
5327
|
PumpSdk,
|
|
5219
5328
|
bondingCurvePda,
|
|
5220
|
-
|
|
5329
|
+
canonicalPumpPoolPda,
|
|
5221
5330
|
creatorVaultPda,
|
|
5222
5331
|
currentDayTokens,
|
|
5223
5332
|
getBuySolAmountFromTokenAmount,
|
|
5333
|
+
getBuySolAmountFromTokenAmountQuote,
|
|
5224
5334
|
getBuyTokenAmountFromSolAmount,
|
|
5335
|
+
getBuyTokenAmountFromSolAmountQuote,
|
|
5225
5336
|
getPumpProgram,
|
|
5226
5337
|
getSellSolAmountFromTokenAmount,
|
|
5338
|
+
getSellTokenAmountFromSolAmountQuote,
|
|
5227
5339
|
globalPda,
|
|
5228
5340
|
globalVolumeAccumulatorPda,
|
|
5229
5341
|
newBondingCurve,
|
|
5230
5342
|
pump_default as pumpIdl,
|
|
5231
|
-
|
|
5343
|
+
pumpPoolAuthorityPda,
|
|
5232
5344
|
totalUnclaimedTokens,
|
|
5233
5345
|
userVolumeAccumulatorPda
|
|
5234
5346
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -9075,6 +9075,21 @@ interface UserVolumeAccumulatorTotalStats {
|
|
|
9075
9075
|
}
|
|
9076
9076
|
|
|
9077
9077
|
declare function newBondingCurve(global: Global): BondingCurve;
|
|
9078
|
+
declare function getBuySolAmountFromTokenAmountQuote({ minAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9079
|
+
minAmount: BN;
|
|
9080
|
+
virtualTokenReserves: BN;
|
|
9081
|
+
virtualSolReserves: BN;
|
|
9082
|
+
}): BN;
|
|
9083
|
+
declare function getBuyTokenAmountFromSolAmountQuote({ inputAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9084
|
+
inputAmount: BN;
|
|
9085
|
+
virtualTokenReserves: BN;
|
|
9086
|
+
virtualSolReserves: BN;
|
|
9087
|
+
}): BN;
|
|
9088
|
+
declare function getSellTokenAmountFromSolAmountQuote({ inputAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9089
|
+
inputAmount: BN;
|
|
9090
|
+
virtualTokenReserves: BN;
|
|
9091
|
+
virtualSolReserves: BN;
|
|
9092
|
+
}): BN;
|
|
9078
9093
|
declare function getBuyTokenAmountFromSolAmount(global: Global, bondingCurve: BondingCurve | null, amount: BN): BN;
|
|
9079
9094
|
declare function getBuySolAmountFromTokenAmount(global: Global, bondingCurve: BondingCurve | null, amount: BN): BN;
|
|
9080
9095
|
declare function getSellSolAmountFromTokenAmount(global: Global, bondingCurve: BondingCurve, amount: BN): BN;
|
|
@@ -9191,9 +9206,25 @@ declare class PumpSdk {
|
|
|
9191
9206
|
user: PublicKey;
|
|
9192
9207
|
}): Promise<TransactionInstruction>;
|
|
9193
9208
|
closeUserVolumeAccumulator(user: PublicKey): Promise<TransactionInstruction>;
|
|
9209
|
+
getBuyInstructionRaw({ user, mint, creator, amount, solAmount, }: {
|
|
9210
|
+
user: PublicKey;
|
|
9211
|
+
mint: PublicKey;
|
|
9212
|
+
creator: PublicKey;
|
|
9213
|
+
amount: BN;
|
|
9214
|
+
solAmount: BN;
|
|
9215
|
+
}): Promise<TransactionInstruction>;
|
|
9216
|
+
private getBuyInstructionInternal;
|
|
9217
|
+
getSellInstructionRaw({ user, mint, creator, amount, solAmount, }: {
|
|
9218
|
+
user: PublicKey;
|
|
9219
|
+
mint: PublicKey;
|
|
9220
|
+
creator: PublicKey;
|
|
9221
|
+
amount: BN;
|
|
9222
|
+
solAmount: BN;
|
|
9223
|
+
}): Promise<TransactionInstruction>;
|
|
9224
|
+
private getSellInstructionInternal;
|
|
9194
9225
|
}
|
|
9195
9226
|
|
|
9196
9227
|
declare function totalUnclaimedTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9197
9228
|
declare function currentDayTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9198
9229
|
|
|
9199
|
-
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type Global, type GlobalVolumeAccumulator, PUMP_AMM_PROGRAM_ID, PUMP_PROGRAM_ID, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, currentDayTokens, getBuySolAmountFromTokenAmount, getBuyTokenAmountFromSolAmount, getPumpProgram, getSellSolAmountFromTokenAmount, globalPda, globalVolumeAccumulatorPda, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, totalUnclaimedTokens, userVolumeAccumulatorPda };
|
|
9230
|
+
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type Global, type GlobalVolumeAccumulator, PUMP_AMM_PROGRAM_ID, PUMP_PROGRAM_ID, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, currentDayTokens, getBuySolAmountFromTokenAmount, getBuySolAmountFromTokenAmountQuote, getBuyTokenAmountFromSolAmount, getBuyTokenAmountFromSolAmountQuote, getPumpProgram, getSellSolAmountFromTokenAmount, getSellTokenAmountFromSolAmountQuote, globalPda, globalVolumeAccumulatorPda, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, totalUnclaimedTokens, userVolumeAccumulatorPda };
|
package/dist/index.d.ts
CHANGED
|
@@ -9075,6 +9075,21 @@ interface UserVolumeAccumulatorTotalStats {
|
|
|
9075
9075
|
}
|
|
9076
9076
|
|
|
9077
9077
|
declare function newBondingCurve(global: Global): BondingCurve;
|
|
9078
|
+
declare function getBuySolAmountFromTokenAmountQuote({ minAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9079
|
+
minAmount: BN;
|
|
9080
|
+
virtualTokenReserves: BN;
|
|
9081
|
+
virtualSolReserves: BN;
|
|
9082
|
+
}): BN;
|
|
9083
|
+
declare function getBuyTokenAmountFromSolAmountQuote({ inputAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9084
|
+
inputAmount: BN;
|
|
9085
|
+
virtualTokenReserves: BN;
|
|
9086
|
+
virtualSolReserves: BN;
|
|
9087
|
+
}): BN;
|
|
9088
|
+
declare function getSellTokenAmountFromSolAmountQuote({ inputAmount, virtualTokenReserves, virtualSolReserves, }: {
|
|
9089
|
+
inputAmount: BN;
|
|
9090
|
+
virtualTokenReserves: BN;
|
|
9091
|
+
virtualSolReserves: BN;
|
|
9092
|
+
}): BN;
|
|
9078
9093
|
declare function getBuyTokenAmountFromSolAmount(global: Global, bondingCurve: BondingCurve | null, amount: BN): BN;
|
|
9079
9094
|
declare function getBuySolAmountFromTokenAmount(global: Global, bondingCurve: BondingCurve | null, amount: BN): BN;
|
|
9080
9095
|
declare function getSellSolAmountFromTokenAmount(global: Global, bondingCurve: BondingCurve, amount: BN): BN;
|
|
@@ -9191,9 +9206,25 @@ declare class PumpSdk {
|
|
|
9191
9206
|
user: PublicKey;
|
|
9192
9207
|
}): Promise<TransactionInstruction>;
|
|
9193
9208
|
closeUserVolumeAccumulator(user: PublicKey): Promise<TransactionInstruction>;
|
|
9209
|
+
getBuyInstructionRaw({ user, mint, creator, amount, solAmount, }: {
|
|
9210
|
+
user: PublicKey;
|
|
9211
|
+
mint: PublicKey;
|
|
9212
|
+
creator: PublicKey;
|
|
9213
|
+
amount: BN;
|
|
9214
|
+
solAmount: BN;
|
|
9215
|
+
}): Promise<TransactionInstruction>;
|
|
9216
|
+
private getBuyInstructionInternal;
|
|
9217
|
+
getSellInstructionRaw({ user, mint, creator, amount, solAmount, }: {
|
|
9218
|
+
user: PublicKey;
|
|
9219
|
+
mint: PublicKey;
|
|
9220
|
+
creator: PublicKey;
|
|
9221
|
+
amount: BN;
|
|
9222
|
+
solAmount: BN;
|
|
9223
|
+
}): Promise<TransactionInstruction>;
|
|
9224
|
+
private getSellInstructionInternal;
|
|
9194
9225
|
}
|
|
9195
9226
|
|
|
9196
9227
|
declare function totalUnclaimedTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9197
9228
|
declare function currentDayTokens(globalVolumeAccumulator: GlobalVolumeAccumulator, userVolumeAccumulator: UserVolumeAccumulator, currentTimestamp?: number): BN;
|
|
9198
9229
|
|
|
9199
|
-
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type Global, type GlobalVolumeAccumulator, PUMP_AMM_PROGRAM_ID, PUMP_PROGRAM_ID, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, currentDayTokens, getBuySolAmountFromTokenAmount, getBuyTokenAmountFromSolAmount, getPumpProgram, getSellSolAmountFromTokenAmount, globalPda, globalVolumeAccumulatorPda, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, totalUnclaimedTokens, userVolumeAccumulatorPda };
|
|
9230
|
+
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type Global, type GlobalVolumeAccumulator, PUMP_AMM_PROGRAM_ID, PUMP_PROGRAM_ID, type Pump, PumpSdk, type UserVolumeAccumulator, type UserVolumeAccumulatorTotalStats, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, currentDayTokens, getBuySolAmountFromTokenAmount, getBuySolAmountFromTokenAmountQuote, getBuyTokenAmountFromSolAmount, getBuyTokenAmountFromSolAmountQuote, getPumpProgram, getSellSolAmountFromTokenAmount, getSellTokenAmountFromSolAmountQuote, globalPda, globalVolumeAccumulatorPda, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, totalUnclaimedTokens, userVolumeAccumulatorPda };
|
package/dist/index.js
CHANGED
|
@@ -36,18 +36,21 @@ __export(index_exports, {
|
|
|
36
36
|
PUMP_PROGRAM_ID: () => PUMP_PROGRAM_ID,
|
|
37
37
|
PumpSdk: () => PumpSdk,
|
|
38
38
|
bondingCurvePda: () => bondingCurvePda,
|
|
39
|
-
canonicalPumpPoolPda: () =>
|
|
39
|
+
canonicalPumpPoolPda: () => canonicalPumpPoolPda,
|
|
40
40
|
creatorVaultPda: () => creatorVaultPda,
|
|
41
41
|
currentDayTokens: () => currentDayTokens,
|
|
42
42
|
getBuySolAmountFromTokenAmount: () => getBuySolAmountFromTokenAmount,
|
|
43
|
+
getBuySolAmountFromTokenAmountQuote: () => getBuySolAmountFromTokenAmountQuote,
|
|
43
44
|
getBuyTokenAmountFromSolAmount: () => getBuyTokenAmountFromSolAmount,
|
|
45
|
+
getBuyTokenAmountFromSolAmountQuote: () => getBuyTokenAmountFromSolAmountQuote,
|
|
44
46
|
getPumpProgram: () => getPumpProgram,
|
|
45
47
|
getSellSolAmountFromTokenAmount: () => getSellSolAmountFromTokenAmount,
|
|
48
|
+
getSellTokenAmountFromSolAmountQuote: () => getSellTokenAmountFromSolAmountQuote,
|
|
46
49
|
globalPda: () => globalPda,
|
|
47
50
|
globalVolumeAccumulatorPda: () => globalVolumeAccumulatorPda,
|
|
48
51
|
newBondingCurve: () => newBondingCurve,
|
|
49
52
|
pumpIdl: () => pump_default,
|
|
50
|
-
pumpPoolAuthorityPda: () =>
|
|
53
|
+
pumpPoolAuthorityPda: () => pumpPoolAuthorityPda,
|
|
51
54
|
totalUnclaimedTokens: () => totalUnclaimedTokens,
|
|
52
55
|
userVolumeAccumulatorPda: () => userVolumeAccumulatorPda
|
|
53
56
|
});
|
|
@@ -4579,6 +4582,27 @@ function newBondingCurve(global) {
|
|
|
4579
4582
|
creator: import_web3.PublicKey.default
|
|
4580
4583
|
};
|
|
4581
4584
|
}
|
|
4585
|
+
function getBuySolAmountFromTokenAmountQuote({
|
|
4586
|
+
minAmount,
|
|
4587
|
+
virtualTokenReserves,
|
|
4588
|
+
virtualSolReserves
|
|
4589
|
+
}) {
|
|
4590
|
+
return minAmount.mul(virtualSolReserves).div(virtualTokenReserves.sub(minAmount)).add(new import_bn.default(1));
|
|
4591
|
+
}
|
|
4592
|
+
function getBuyTokenAmountFromSolAmountQuote({
|
|
4593
|
+
inputAmount,
|
|
4594
|
+
virtualTokenReserves,
|
|
4595
|
+
virtualSolReserves
|
|
4596
|
+
}) {
|
|
4597
|
+
return inputAmount.mul(virtualTokenReserves).div(virtualSolReserves.add(inputAmount));
|
|
4598
|
+
}
|
|
4599
|
+
function getSellTokenAmountFromSolAmountQuote({
|
|
4600
|
+
inputAmount,
|
|
4601
|
+
virtualTokenReserves,
|
|
4602
|
+
virtualSolReserves
|
|
4603
|
+
}) {
|
|
4604
|
+
return inputAmount.mul(virtualSolReserves).div(virtualTokenReserves.add(inputAmount));
|
|
4605
|
+
}
|
|
4582
4606
|
function getBuyTokenAmountFromSolAmount(global, bondingCurve, amount) {
|
|
4583
4607
|
if (amount.eq(new import_bn.default(0))) {
|
|
4584
4608
|
return new import_bn.default(0);
|
|
@@ -4595,7 +4619,11 @@ function getBuyTokenAmountFromSolAmount(global, bondingCurve, amount) {
|
|
|
4595
4619
|
isNewBondingCurve || !import_web3.PublicKey.default.equals(bondingCurve.creator) ? global.creatorFeeBasisPoints : new import_bn.default(0)
|
|
4596
4620
|
);
|
|
4597
4621
|
const inputAmount = amount.muln(1e4).div(totalFeeBasisPoints.addn(1e4));
|
|
4598
|
-
const tokensReceived =
|
|
4622
|
+
const tokensReceived = getBuyTokenAmountFromSolAmountQuote({
|
|
4623
|
+
inputAmount,
|
|
4624
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
4625
|
+
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
4626
|
+
});
|
|
4599
4627
|
return import_bn.default.min(tokensReceived, bondingCurve.realTokenReserves);
|
|
4600
4628
|
}
|
|
4601
4629
|
function getBuySolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
@@ -4611,7 +4639,11 @@ function getBuySolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
|
4611
4639
|
return new import_bn.default(0);
|
|
4612
4640
|
}
|
|
4613
4641
|
const minAmount = import_bn.default.min(amount, bondingCurve.realTokenReserves);
|
|
4614
|
-
const solCost =
|
|
4642
|
+
const solCost = getBuySolAmountFromTokenAmountQuote({
|
|
4643
|
+
minAmount,
|
|
4644
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
4645
|
+
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
4646
|
+
});
|
|
4615
4647
|
return solCost.add(getFee(global, bondingCurve, solCost, isNewBondingCurve));
|
|
4616
4648
|
}
|
|
4617
4649
|
function getSellSolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
@@ -4621,9 +4653,27 @@ function getSellSolAmountFromTokenAmount(global, bondingCurve, amount) {
|
|
|
4621
4653
|
if (bondingCurve.virtualTokenReserves.eq(new import_bn.default(0))) {
|
|
4622
4654
|
return new import_bn.default(0);
|
|
4623
4655
|
}
|
|
4624
|
-
const solCost =
|
|
4656
|
+
const solCost = getSellTokenAmountFromSolAmountQuote({
|
|
4657
|
+
inputAmount: amount,
|
|
4658
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
4659
|
+
virtualSolReserves: bondingCurve.virtualSolReserves
|
|
4660
|
+
});
|
|
4625
4661
|
return solCost.sub(getFee(global, bondingCurve, solCost, false));
|
|
4626
4662
|
}
|
|
4663
|
+
function getStaticRandomFeeRecipient() {
|
|
4664
|
+
const randomIndex = Math.floor(Math.random() * CURRENT_FEE_RECIPIENTS.length);
|
|
4665
|
+
return new import_web3.PublicKey(CURRENT_FEE_RECIPIENTS[randomIndex]);
|
|
4666
|
+
}
|
|
4667
|
+
var CURRENT_FEE_RECIPIENTS = [
|
|
4668
|
+
"62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV",
|
|
4669
|
+
"7VtfL8fvgNfhz17qKRMjzQEXgbdpnHHHQRh54R9jP2RJ",
|
|
4670
|
+
"7hTckgnGnLQR6sdH7YkqFTAA7VwTfYFaZ6EhEsU3saCX",
|
|
4671
|
+
"9rPYyANsfQZw3DnDmKE3YCQF5E8oD89UXoHn9JFEhJUz",
|
|
4672
|
+
"AVmoTthdrX6tKt4nDjco2D775W2YK3sDhxPcMmzUAmTY",
|
|
4673
|
+
"CebN5WGQ4jvEPvsVU4EoHEpgzq1VV7AbicfhtW4xC9iM",
|
|
4674
|
+
"FWsW1xNtWscwNmKv6wVsU1iTzRN6wmmk3MjxRP5tT7hz",
|
|
4675
|
+
"G5UZAVbAf46s7cKWoyKu8kYTip9DGTpbLZ2qa9Aq69dP"
|
|
4676
|
+
];
|
|
4627
4677
|
|
|
4628
4678
|
// src/pda.ts
|
|
4629
4679
|
var import_web33 = require("@solana/web3.js");
|
|
@@ -4930,19 +4980,17 @@ var PumpSdk = class {
|
|
|
4930
4980
|
solAmount,
|
|
4931
4981
|
slippage
|
|
4932
4982
|
}) {
|
|
4933
|
-
return await this.
|
|
4983
|
+
return await this.getBuyInstructionInternal({
|
|
4984
|
+
user,
|
|
4985
|
+
associatedUser,
|
|
4986
|
+
mint,
|
|
4987
|
+
creator,
|
|
4988
|
+
feeRecipient: getFeeRecipient(global),
|
|
4934
4989
|
amount,
|
|
4935
|
-
solAmount.add(
|
|
4990
|
+
solAmount: solAmount.add(
|
|
4936
4991
|
solAmount.mul(new import_bn3.default(Math.floor(slippage * 10))).div(new import_bn3.default(1e3))
|
|
4937
|
-
)
|
|
4938
|
-
|
|
4939
|
-
).accountsPartial({
|
|
4940
|
-
feeRecipient: getFeeRecipient(global),
|
|
4941
|
-
mint,
|
|
4942
|
-
associatedUser,
|
|
4943
|
-
user,
|
|
4944
|
-
creatorVault: creatorVaultPda(creator)
|
|
4945
|
-
}).instruction();
|
|
4992
|
+
)
|
|
4993
|
+
});
|
|
4946
4994
|
}
|
|
4947
4995
|
async sellInstructions({
|
|
4948
4996
|
global,
|
|
@@ -4964,18 +5012,16 @@ var PumpSdk = class {
|
|
|
4964
5012
|
);
|
|
4965
5013
|
}
|
|
4966
5014
|
instructions.push(
|
|
4967
|
-
await this.
|
|
5015
|
+
await this.getSellInstructionInternal({
|
|
5016
|
+
user,
|
|
5017
|
+
mint,
|
|
5018
|
+
creator: bondingCurve.creator,
|
|
5019
|
+
feeRecipient: getFeeRecipient(global),
|
|
4968
5020
|
amount,
|
|
4969
|
-
solAmount.sub(
|
|
5021
|
+
solAmount: solAmount.sub(
|
|
4970
5022
|
solAmount.mul(new import_bn3.default(Math.floor(slippage * 10))).div(new import_bn3.default(1e3))
|
|
4971
5023
|
)
|
|
4972
|
-
)
|
|
4973
|
-
feeRecipient: getFeeRecipient(global),
|
|
4974
|
-
mint,
|
|
4975
|
-
associatedUser: (0, import_spl_token.getAssociatedTokenAddressSync)(mint, user, true),
|
|
4976
|
-
user,
|
|
4977
|
-
creatorVault: creatorVaultPda(bondingCurve.creator)
|
|
4978
|
-
}).instruction()
|
|
5024
|
+
})
|
|
4979
5025
|
);
|
|
4980
5026
|
return instructions;
|
|
4981
5027
|
}
|
|
@@ -5200,6 +5246,72 @@ var PumpSdk = class {
|
|
|
5200
5246
|
async closeUserVolumeAccumulator(user) {
|
|
5201
5247
|
return await this.offlinePumpProgram.methods.closeUserVolumeAccumulator().accountsPartial({ user }).instruction();
|
|
5202
5248
|
}
|
|
5249
|
+
async getBuyInstructionRaw({
|
|
5250
|
+
user,
|
|
5251
|
+
mint,
|
|
5252
|
+
creator,
|
|
5253
|
+
amount,
|
|
5254
|
+
solAmount
|
|
5255
|
+
}) {
|
|
5256
|
+
return await this.getBuyInstructionInternal({
|
|
5257
|
+
user,
|
|
5258
|
+
associatedUser: (0, import_spl_token.getAssociatedTokenAddressSync)(mint, user, true),
|
|
5259
|
+
mint,
|
|
5260
|
+
creator,
|
|
5261
|
+
feeRecipient: getStaticRandomFeeRecipient(),
|
|
5262
|
+
amount,
|
|
5263
|
+
solAmount
|
|
5264
|
+
});
|
|
5265
|
+
}
|
|
5266
|
+
async getBuyInstructionInternal({
|
|
5267
|
+
user,
|
|
5268
|
+
associatedUser,
|
|
5269
|
+
mint,
|
|
5270
|
+
creator,
|
|
5271
|
+
feeRecipient,
|
|
5272
|
+
amount,
|
|
5273
|
+
solAmount
|
|
5274
|
+
}) {
|
|
5275
|
+
return await this.offlinePumpProgram.methods.buy(amount, solAmount, { 0: true }).accountsPartial({
|
|
5276
|
+
feeRecipient,
|
|
5277
|
+
mint,
|
|
5278
|
+
associatedUser,
|
|
5279
|
+
user,
|
|
5280
|
+
creatorVault: creatorVaultPda(creator)
|
|
5281
|
+
}).instruction();
|
|
5282
|
+
}
|
|
5283
|
+
async getSellInstructionRaw({
|
|
5284
|
+
user,
|
|
5285
|
+
mint,
|
|
5286
|
+
creator,
|
|
5287
|
+
amount,
|
|
5288
|
+
solAmount
|
|
5289
|
+
}) {
|
|
5290
|
+
return await this.getSellInstructionInternal({
|
|
5291
|
+
user,
|
|
5292
|
+
mint,
|
|
5293
|
+
creator,
|
|
5294
|
+
feeRecipient: getStaticRandomFeeRecipient(),
|
|
5295
|
+
amount,
|
|
5296
|
+
solAmount
|
|
5297
|
+
});
|
|
5298
|
+
}
|
|
5299
|
+
async getSellInstructionInternal({
|
|
5300
|
+
user,
|
|
5301
|
+
mint,
|
|
5302
|
+
creator,
|
|
5303
|
+
feeRecipient,
|
|
5304
|
+
amount,
|
|
5305
|
+
solAmount
|
|
5306
|
+
}) {
|
|
5307
|
+
return await this.offlinePumpProgram.methods.sell(amount, solAmount).accountsPartial({
|
|
5308
|
+
feeRecipient,
|
|
5309
|
+
mint,
|
|
5310
|
+
associatedUser: (0, import_spl_token.getAssociatedTokenAddressSync)(mint, user, true),
|
|
5311
|
+
user,
|
|
5312
|
+
creatorVault: creatorVaultPda(creator)
|
|
5313
|
+
}).instruction();
|
|
5314
|
+
}
|
|
5203
5315
|
};
|
|
5204
5316
|
function getFeeRecipient(global) {
|
|
5205
5317
|
const feeRecipients = [global.feeRecipient, ...global.feeRecipients];
|
|
@@ -5228,15 +5340,15 @@ function creatorVaultPda(creator) {
|
|
|
5228
5340
|
);
|
|
5229
5341
|
return creatorVault;
|
|
5230
5342
|
}
|
|
5231
|
-
function
|
|
5343
|
+
function pumpPoolAuthorityPda(mint) {
|
|
5232
5344
|
return import_web33.PublicKey.findProgramAddressSync(
|
|
5233
5345
|
[Buffer.from("pool-authority"), mint.toBuffer()],
|
|
5234
5346
|
PUMP_PROGRAM_ID
|
|
5235
5347
|
);
|
|
5236
5348
|
}
|
|
5237
5349
|
var CANONICAL_POOL_INDEX = 0;
|
|
5238
|
-
function
|
|
5239
|
-
const [pumpPoolAuthority] =
|
|
5350
|
+
function canonicalPumpPoolPda(mint) {
|
|
5351
|
+
const [pumpPoolAuthority] = pumpPoolAuthorityPda(mint);
|
|
5240
5352
|
return (0, import_pump_swap_sdk2.poolPda)(
|
|
5241
5353
|
CANONICAL_POOL_INDEX,
|
|
5242
5354
|
pumpPoolAuthority,
|
package/package.json
CHANGED
package/src/bondingCurve.ts
CHANGED
|
@@ -35,6 +35,49 @@ export function newBondingCurve(global: Global): BondingCurve {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
export function getBuySolAmountFromTokenAmountQuote({
|
|
39
|
+
minAmount,
|
|
40
|
+
virtualTokenReserves,
|
|
41
|
+
virtualSolReserves,
|
|
42
|
+
}: {
|
|
43
|
+
minAmount: BN;
|
|
44
|
+
virtualTokenReserves: BN;
|
|
45
|
+
virtualSolReserves: BN;
|
|
46
|
+
}): BN {
|
|
47
|
+
return minAmount
|
|
48
|
+
.mul(virtualSolReserves)
|
|
49
|
+
.div(virtualTokenReserves.sub(minAmount))
|
|
50
|
+
.add(new BN(1));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getBuyTokenAmountFromSolAmountQuote({
|
|
54
|
+
inputAmount,
|
|
55
|
+
virtualTokenReserves,
|
|
56
|
+
virtualSolReserves,
|
|
57
|
+
}: {
|
|
58
|
+
inputAmount: BN;
|
|
59
|
+
virtualTokenReserves: BN;
|
|
60
|
+
virtualSolReserves: BN;
|
|
61
|
+
}): BN {
|
|
62
|
+
return inputAmount
|
|
63
|
+
.mul(virtualTokenReserves)
|
|
64
|
+
.div(virtualSolReserves.add(inputAmount));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getSellTokenAmountFromSolAmountQuote({
|
|
68
|
+
inputAmount,
|
|
69
|
+
virtualTokenReserves,
|
|
70
|
+
virtualSolReserves,
|
|
71
|
+
}: {
|
|
72
|
+
inputAmount: BN;
|
|
73
|
+
virtualTokenReserves: BN;
|
|
74
|
+
virtualSolReserves: BN;
|
|
75
|
+
}): BN {
|
|
76
|
+
return inputAmount
|
|
77
|
+
.mul(virtualSolReserves)
|
|
78
|
+
.div(virtualTokenReserves.add(inputAmount));
|
|
79
|
+
}
|
|
80
|
+
|
|
38
81
|
export function getBuyTokenAmountFromSolAmount(
|
|
39
82
|
global: Global,
|
|
40
83
|
bondingCurve: BondingCurve | null,
|
|
@@ -64,9 +107,11 @@ export function getBuyTokenAmountFromSolAmount(
|
|
|
64
107
|
|
|
65
108
|
const inputAmount = amount.muln(10_000).div(totalFeeBasisPoints.addn(10_000));
|
|
66
109
|
|
|
67
|
-
const tokensReceived =
|
|
68
|
-
|
|
69
|
-
|
|
110
|
+
const tokensReceived = getBuyTokenAmountFromSolAmountQuote({
|
|
111
|
+
inputAmount,
|
|
112
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
113
|
+
virtualSolReserves: bondingCurve.virtualSolReserves,
|
|
114
|
+
});
|
|
70
115
|
|
|
71
116
|
return BN.min(tokensReceived, bondingCurve.realTokenReserves);
|
|
72
117
|
}
|
|
@@ -94,10 +139,11 @@ export function getBuySolAmountFromTokenAmount(
|
|
|
94
139
|
|
|
95
140
|
const minAmount = BN.min(amount, bondingCurve.realTokenReserves);
|
|
96
141
|
|
|
97
|
-
const solCost =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.
|
|
142
|
+
const solCost = getBuySolAmountFromTokenAmountQuote({
|
|
143
|
+
minAmount,
|
|
144
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
145
|
+
virtualSolReserves: bondingCurve.virtualSolReserves,
|
|
146
|
+
});
|
|
101
147
|
|
|
102
148
|
return solCost.add(getFee(global, bondingCurve, solCost, isNewBondingCurve));
|
|
103
149
|
}
|
|
@@ -116,9 +162,27 @@ export function getSellSolAmountFromTokenAmount(
|
|
|
116
162
|
return new BN(0);
|
|
117
163
|
}
|
|
118
164
|
|
|
119
|
-
const solCost =
|
|
120
|
-
|
|
121
|
-
|
|
165
|
+
const solCost = getSellTokenAmountFromSolAmountQuote({
|
|
166
|
+
inputAmount: amount,
|
|
167
|
+
virtualTokenReserves: bondingCurve.virtualTokenReserves,
|
|
168
|
+
virtualSolReserves: bondingCurve.virtualSolReserves,
|
|
169
|
+
});
|
|
122
170
|
|
|
123
171
|
return solCost.sub(getFee(global, bondingCurve, solCost, false));
|
|
124
172
|
}
|
|
173
|
+
|
|
174
|
+
export function getStaticRandomFeeRecipient(): PublicKey {
|
|
175
|
+
const randomIndex = Math.floor(Math.random() * CURRENT_FEE_RECIPIENTS.length);
|
|
176
|
+
return new PublicKey(CURRENT_FEE_RECIPIENTS[randomIndex]);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const CURRENT_FEE_RECIPIENTS = [
|
|
180
|
+
"62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV",
|
|
181
|
+
"7VtfL8fvgNfhz17qKRMjzQEXgbdpnHHHQRh54R9jP2RJ",
|
|
182
|
+
"7hTckgnGnLQR6sdH7YkqFTAA7VwTfYFaZ6EhEsU3saCX",
|
|
183
|
+
"9rPYyANsfQZw3DnDmKE3YCQF5E8oD89UXoHn9JFEhJUz",
|
|
184
|
+
"AVmoTthdrX6tKt4nDjco2D775W2YK3sDhxPcMmzUAmTY",
|
|
185
|
+
"CebN5WGQ4jvEPvsVU4EoHEpgzq1VV7AbicfhtW4xC9iM",
|
|
186
|
+
"FWsW1xNtWscwNmKv6wVsU1iTzRN6wmmk3MjxRP5tT7hz",
|
|
187
|
+
"G5UZAVbAf46s7cKWoyKu8kYTip9DGTpbLZ2qa9Aq69dP",
|
|
188
|
+
];
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,9 @@ export { Pump } from "./idl/pump";
|
|
|
2
2
|
export { default as pumpIdl } from "./idl/pump.json";
|
|
3
3
|
export {
|
|
4
4
|
getBuyTokenAmountFromSolAmount,
|
|
5
|
+
getBuySolAmountFromTokenAmountQuote,
|
|
6
|
+
getBuyTokenAmountFromSolAmountQuote,
|
|
7
|
+
getSellTokenAmountFromSolAmountQuote,
|
|
5
8
|
getBuySolAmountFromTokenAmount,
|
|
6
9
|
getSellSolAmountFromTokenAmount,
|
|
7
10
|
newBondingCurve,
|
package/src/sdk.ts
CHANGED
|
@@ -20,10 +20,8 @@ import BN from "bn.js";
|
|
|
20
20
|
|
|
21
21
|
import {
|
|
22
22
|
bondingCurvePda,
|
|
23
|
-
canonicalPumpPoolPda,
|
|
24
23
|
creatorVaultPda,
|
|
25
24
|
globalPda,
|
|
26
|
-
pumpPoolAuthorityPda,
|
|
27
25
|
globalVolumeAccumulatorPda,
|
|
28
26
|
userVolumeAccumulatorPda,
|
|
29
27
|
} from "./pda";
|
|
@@ -35,6 +33,7 @@ import {
|
|
|
35
33
|
UserVolumeAccumulatorTotalStats,
|
|
36
34
|
} from "./state";
|
|
37
35
|
import { currentDayTokens, totalUnclaimedTokens } from "./tokenIncentives";
|
|
36
|
+
import { getStaticRandomFeeRecipient } from "./bondingCurve";
|
|
38
37
|
|
|
39
38
|
export function getPumpProgram(connection: Connection): Program<Pump> {
|
|
40
39
|
return new Program(
|
|
@@ -355,22 +354,17 @@ export class PumpSdk {
|
|
|
355
354
|
solAmount: BN;
|
|
356
355
|
slippage: number;
|
|
357
356
|
}) {
|
|
358
|
-
return await this.
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
associatedUser,
|
|
370
|
-
user,
|
|
371
|
-
creatorVault: creatorVaultPda(creator),
|
|
372
|
-
})
|
|
373
|
-
.instruction();
|
|
357
|
+
return await this.getBuyInstructionInternal({
|
|
358
|
+
user,
|
|
359
|
+
associatedUser,
|
|
360
|
+
mint,
|
|
361
|
+
creator,
|
|
362
|
+
feeRecipient: getFeeRecipient(global),
|
|
363
|
+
amount,
|
|
364
|
+
solAmount: solAmount.add(
|
|
365
|
+
solAmount.mul(new BN(Math.floor(slippage * 10))).div(new BN(1000)),
|
|
366
|
+
),
|
|
367
|
+
});
|
|
374
368
|
}
|
|
375
369
|
|
|
376
370
|
async sellInstructions({
|
|
@@ -404,21 +398,16 @@ export class PumpSdk {
|
|
|
404
398
|
}
|
|
405
399
|
|
|
406
400
|
instructions.push(
|
|
407
|
-
await this.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
associatedUser: getAssociatedTokenAddressSync(mint, user, true),
|
|
418
|
-
user,
|
|
419
|
-
creatorVault: creatorVaultPda(bondingCurve.creator),
|
|
420
|
-
})
|
|
421
|
-
.instruction(),
|
|
401
|
+
await this.getSellInstructionInternal({
|
|
402
|
+
user,
|
|
403
|
+
mint,
|
|
404
|
+
creator: bondingCurve.creator,
|
|
405
|
+
feeRecipient: getFeeRecipient(global),
|
|
406
|
+
amount,
|
|
407
|
+
solAmount: solAmount.sub(
|
|
408
|
+
solAmount.mul(new BN(Math.floor(slippage * 10))).div(new BN(1000)),
|
|
409
|
+
),
|
|
410
|
+
}),
|
|
422
411
|
);
|
|
423
412
|
|
|
424
413
|
return instructions;
|
|
@@ -769,6 +758,109 @@ export class PumpSdk {
|
|
|
769
758
|
.accountsPartial({ user })
|
|
770
759
|
.instruction();
|
|
771
760
|
}
|
|
761
|
+
|
|
762
|
+
async getBuyInstructionRaw({
|
|
763
|
+
user,
|
|
764
|
+
mint,
|
|
765
|
+
creator,
|
|
766
|
+
amount,
|
|
767
|
+
solAmount,
|
|
768
|
+
}: {
|
|
769
|
+
user: PublicKey;
|
|
770
|
+
mint: PublicKey;
|
|
771
|
+
creator: PublicKey;
|
|
772
|
+
amount: BN;
|
|
773
|
+
solAmount: BN;
|
|
774
|
+
}): Promise<TransactionInstruction> {
|
|
775
|
+
return await this.getBuyInstructionInternal({
|
|
776
|
+
user,
|
|
777
|
+
associatedUser: getAssociatedTokenAddressSync(mint, user, true),
|
|
778
|
+
mint,
|
|
779
|
+
creator,
|
|
780
|
+
feeRecipient: getStaticRandomFeeRecipient(),
|
|
781
|
+
amount,
|
|
782
|
+
solAmount,
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
private async getBuyInstructionInternal({
|
|
787
|
+
user,
|
|
788
|
+
associatedUser,
|
|
789
|
+
mint,
|
|
790
|
+
creator,
|
|
791
|
+
feeRecipient,
|
|
792
|
+
amount,
|
|
793
|
+
solAmount,
|
|
794
|
+
}: {
|
|
795
|
+
user: PublicKey;
|
|
796
|
+
associatedUser: PublicKey;
|
|
797
|
+
mint: PublicKey;
|
|
798
|
+
creator: PublicKey;
|
|
799
|
+
feeRecipient: PublicKey;
|
|
800
|
+
amount: BN;
|
|
801
|
+
solAmount: BN;
|
|
802
|
+
}): Promise<TransactionInstruction> {
|
|
803
|
+
return await this.offlinePumpProgram.methods
|
|
804
|
+
.buy(amount, solAmount, { 0: true })
|
|
805
|
+
.accountsPartial({
|
|
806
|
+
feeRecipient,
|
|
807
|
+
mint,
|
|
808
|
+
associatedUser,
|
|
809
|
+
user,
|
|
810
|
+
creatorVault: creatorVaultPda(creator),
|
|
811
|
+
})
|
|
812
|
+
.instruction();
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
async getSellInstructionRaw({
|
|
816
|
+
user,
|
|
817
|
+
mint,
|
|
818
|
+
creator,
|
|
819
|
+
amount,
|
|
820
|
+
solAmount,
|
|
821
|
+
}: {
|
|
822
|
+
user: PublicKey;
|
|
823
|
+
mint: PublicKey;
|
|
824
|
+
creator: PublicKey;
|
|
825
|
+
amount: BN;
|
|
826
|
+
solAmount: BN;
|
|
827
|
+
}): Promise<TransactionInstruction> {
|
|
828
|
+
return await this.getSellInstructionInternal({
|
|
829
|
+
user,
|
|
830
|
+
mint,
|
|
831
|
+
creator,
|
|
832
|
+
feeRecipient: getStaticRandomFeeRecipient(),
|
|
833
|
+
amount,
|
|
834
|
+
solAmount,
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
private async getSellInstructionInternal({
|
|
839
|
+
user,
|
|
840
|
+
mint,
|
|
841
|
+
creator,
|
|
842
|
+
feeRecipient,
|
|
843
|
+
amount,
|
|
844
|
+
solAmount,
|
|
845
|
+
}: {
|
|
846
|
+
user: PublicKey;
|
|
847
|
+
mint: PublicKey;
|
|
848
|
+
creator: PublicKey;
|
|
849
|
+
feeRecipient: PublicKey;
|
|
850
|
+
amount: BN;
|
|
851
|
+
solAmount: BN;
|
|
852
|
+
}): Promise<TransactionInstruction> {
|
|
853
|
+
return await this.offlinePumpProgram.methods
|
|
854
|
+
.sell(amount, solAmount)
|
|
855
|
+
.accountsPartial({
|
|
856
|
+
feeRecipient,
|
|
857
|
+
mint,
|
|
858
|
+
associatedUser: getAssociatedTokenAddressSync(mint, user, true),
|
|
859
|
+
user,
|
|
860
|
+
creatorVault: creatorVaultPda(creator),
|
|
861
|
+
})
|
|
862
|
+
.instruction();
|
|
863
|
+
}
|
|
772
864
|
}
|
|
773
865
|
|
|
774
866
|
function getFeeRecipient(global: Global): PublicKey {
|