@pump-fun/pump-sdk 1.6.1 → 1.7.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 +77 -31
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +77 -31
- package/package.json +2 -2
- package/src/sdk.ts +76 -33
- package/src/tokenIncentives.ts +35 -0
package/dist/esm/index.js
CHANGED
|
@@ -3955,7 +3955,28 @@ import {
|
|
|
3955
3955
|
import {
|
|
3956
3956
|
PublicKey as PublicKey2
|
|
3957
3957
|
} from "@solana/web3.js";
|
|
3958
|
+
import BN3 from "bn.js";
|
|
3959
|
+
|
|
3960
|
+
// src/tokenIncentives.ts
|
|
3958
3961
|
import BN2 from "bn.js";
|
|
3962
|
+
function currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator, currentTimestamp = Date.now() / 1e3) {
|
|
3963
|
+
const { startTime, endTime } = globalVolumeAccumulator;
|
|
3964
|
+
let currentTimestampBn = new BN2(currentTimestamp);
|
|
3965
|
+
if (currentTimestampBn.lt(startTime) || currentTimestampBn.gt(endTime)) {
|
|
3966
|
+
return new BN2(0);
|
|
3967
|
+
}
|
|
3968
|
+
const { secondsInADay, totalTokenSupply, solVolumes } = globalVolumeAccumulator;
|
|
3969
|
+
let currentDayIndex = currentTimestampBn.sub(startTime).div(secondsInADay).toNumber();
|
|
3970
|
+
let currentDayTokenSupply = totalTokenSupply[currentDayIndex];
|
|
3971
|
+
let currentDaySolVolume = solVolumes[currentDayIndex];
|
|
3972
|
+
if (currentDaySolVolume.eqn(0)) {
|
|
3973
|
+
return new BN2(0);
|
|
3974
|
+
}
|
|
3975
|
+
const { currentSolVolume } = userVolumeAccumulator;
|
|
3976
|
+
return currentSolVolume.mul(currentDayTokenSupply).div(currentDaySolVolume);
|
|
3977
|
+
}
|
|
3978
|
+
|
|
3979
|
+
// src/sdk.ts
|
|
3959
3980
|
function getPumpProgram(connection, programId) {
|
|
3960
3981
|
const pumpIdlAddressOverride = { ...pump_default };
|
|
3961
3982
|
pumpIdlAddressOverride.address = programId.toString();
|
|
@@ -4196,7 +4217,7 @@ var PumpSdk = class {
|
|
|
4196
4217
|
return await this.offlinePumpProgram.methods.buy(
|
|
4197
4218
|
amount,
|
|
4198
4219
|
solAmount.add(
|
|
4199
|
-
solAmount.mul(new
|
|
4220
|
+
solAmount.mul(new BN3(Math.floor(slippage * 10))).div(new BN3(1e3))
|
|
4200
4221
|
)
|
|
4201
4222
|
).accountsPartial({
|
|
4202
4223
|
feeRecipient: getFeeRecipient(global),
|
|
@@ -4229,7 +4250,7 @@ var PumpSdk = class {
|
|
|
4229
4250
|
await this.offlinePumpProgram.methods.sell(
|
|
4230
4251
|
amount,
|
|
4231
4252
|
solAmount.sub(
|
|
4232
|
-
solAmount.mul(new
|
|
4253
|
+
solAmount.mul(new BN3(Math.floor(slippage * 10))).div(new BN3(1e3))
|
|
4233
4254
|
)
|
|
4234
4255
|
).accountsPartial({
|
|
4235
4256
|
feeRecipient: getFeeRecipient(global),
|
|
@@ -4311,54 +4332,79 @@ var PumpSdk = class {
|
|
|
4311
4332
|
const creatorVault = this.creatorVaultPda(creator);
|
|
4312
4333
|
const accountInfo = await this.connection.getAccountInfo(creatorVault);
|
|
4313
4334
|
if (accountInfo === null) {
|
|
4314
|
-
return new
|
|
4335
|
+
return new BN3(0);
|
|
4315
4336
|
}
|
|
4316
4337
|
const rentExemptionLamports = await this.connection.getMinimumBalanceForRentExemption(
|
|
4317
4338
|
accountInfo.data.length
|
|
4318
4339
|
);
|
|
4319
4340
|
if (accountInfo.lamports < rentExemptionLamports) {
|
|
4320
|
-
return new
|
|
4341
|
+
return new BN3(0);
|
|
4321
4342
|
}
|
|
4322
|
-
return new
|
|
4343
|
+
return new BN3(accountInfo.lamports - rentExemptionLamports);
|
|
4323
4344
|
}
|
|
4324
|
-
async adminUpdateTokenIncentives(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new
|
|
4325
|
-
const
|
|
4326
|
-
return
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4345
|
+
async adminUpdateTokenIncentives(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new BN3(86400), mint = PUMP_TOKEN_MINT, tokenProgram = TOKEN_2022_PROGRAM_ID) {
|
|
4346
|
+
const { authority } = await this.fetchGlobal();
|
|
4347
|
+
return [
|
|
4348
|
+
await this.offlinePumpProgram.methods.adminUpdateTokenIncentives(
|
|
4349
|
+
startTime,
|
|
4350
|
+
endTime,
|
|
4351
|
+
secondsInADay,
|
|
4352
|
+
dayNumber,
|
|
4353
|
+
tokenSupplyPerDay
|
|
4354
|
+
).accountsPartial({
|
|
4355
|
+
global: this.globalPda(),
|
|
4356
|
+
authority,
|
|
4357
|
+
mint,
|
|
4358
|
+
tokenProgram
|
|
4359
|
+
}).instruction(),
|
|
4360
|
+
await this.pumpAmmAdminSdk.adminUpdateTokenIncentives(
|
|
4361
|
+
startTime,
|
|
4362
|
+
endTime,
|
|
4363
|
+
dayNumber,
|
|
4364
|
+
tokenSupplyPerDay,
|
|
4365
|
+
secondsInADay,
|
|
4366
|
+
mint,
|
|
4367
|
+
tokenProgram
|
|
4368
|
+
)
|
|
4369
|
+
];
|
|
4338
4370
|
}
|
|
4339
4371
|
async claimTokenIncentives(user, payer, mint = PUMP_TOKEN_MINT, tokenProgram = TOKEN_2022_PROGRAM_ID) {
|
|
4340
|
-
const userPumpAta = getAssociatedTokenAddressSync(
|
|
4341
|
-
mint,
|
|
4342
|
-
user,
|
|
4343
|
-
true,
|
|
4344
|
-
tokenProgram
|
|
4345
|
-
);
|
|
4346
4372
|
return [
|
|
4347
|
-
|
|
4348
|
-
payer,
|
|
4349
|
-
userPumpAta,
|
|
4373
|
+
await this.offlinePumpProgram.methods.claimTokenIncentives().accountsPartial({
|
|
4350
4374
|
user,
|
|
4375
|
+
payer,
|
|
4351
4376
|
mint,
|
|
4352
4377
|
tokenProgram
|
|
4353
|
-
),
|
|
4354
|
-
await this.
|
|
4378
|
+
}).instruction(),
|
|
4379
|
+
...await this.pumpAmmSdk.claimTokenIncentives(
|
|
4355
4380
|
user,
|
|
4356
4381
|
payer,
|
|
4357
4382
|
mint,
|
|
4358
4383
|
tokenProgram
|
|
4359
|
-
|
|
4384
|
+
)
|
|
4360
4385
|
];
|
|
4361
4386
|
}
|
|
4387
|
+
async getCurrentDayTokens(user) {
|
|
4388
|
+
const [
|
|
4389
|
+
globalVolumeAccumulatorAccountInfo,
|
|
4390
|
+
userVolumeAccumulatorAccountInfo
|
|
4391
|
+
] = await this.connection.getMultipleAccountsInfo([
|
|
4392
|
+
globalVolumeAccumulatorPda()[0],
|
|
4393
|
+
userVolumeAccumulatorPda(user)[0]
|
|
4394
|
+
]);
|
|
4395
|
+
if (!globalVolumeAccumulatorAccountInfo || !userVolumeAccumulatorAccountInfo) {
|
|
4396
|
+
return new BN3(0);
|
|
4397
|
+
}
|
|
4398
|
+
const globalVolumeAccumulator = this.decodeGlobalVolumeAccumulator(
|
|
4399
|
+
globalVolumeAccumulatorAccountInfo
|
|
4400
|
+
);
|
|
4401
|
+
const userVolumeAccumulator = this.decodeUserVolumeAccumulator(
|
|
4402
|
+
userVolumeAccumulatorAccountInfo
|
|
4403
|
+
);
|
|
4404
|
+
return currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator).add(
|
|
4405
|
+
await this.pumpAmmSdk.getCurrentDayTokens(user)
|
|
4406
|
+
);
|
|
4407
|
+
}
|
|
4362
4408
|
};
|
|
4363
4409
|
function getFeeRecipient(global) {
|
|
4364
4410
|
const feeRecipients = [global.feeRecipient, ...global.feeRecipients];
|
package/dist/index.d.mts
CHANGED
|
@@ -7902,8 +7902,9 @@ declare class PumpSdk {
|
|
|
7902
7902
|
collectCoinCreatorFeeInstructions(coinCreator: PublicKey): Promise<TransactionInstruction[]>;
|
|
7903
7903
|
adminSetCoinCreatorInstructions(newCoinCreator: PublicKey, mint: PublicKey): Promise<TransactionInstruction[]>;
|
|
7904
7904
|
getCreatorVaultBalance(creator: PublicKey): Promise<BN>;
|
|
7905
|
-
adminUpdateTokenIncentives(startTime: BN, endTime: BN, dayNumber: BN, tokenSupplyPerDay: BN, secondsInADay?: BN, mint?: PublicKey, tokenProgram?: PublicKey): Promise<TransactionInstruction>;
|
|
7905
|
+
adminUpdateTokenIncentives(startTime: BN, endTime: BN, dayNumber: BN, tokenSupplyPerDay: BN, secondsInADay?: BN, mint?: PublicKey, tokenProgram?: PublicKey): Promise<TransactionInstruction[]>;
|
|
7906
7906
|
claimTokenIncentives(user: PublicKey, payer: PublicKey, mint?: PublicKey, tokenProgram?: PublicKey): Promise<TransactionInstruction[]>;
|
|
7907
|
+
getCurrentDayTokens(user: PublicKey): Promise<BN>;
|
|
7907
7908
|
}
|
|
7908
7909
|
|
|
7909
7910
|
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type Global, PUMP_AMM_PROGRAM_ID, PUMP_PROGRAM_ID, type Pump, PumpSdk, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, getBuySolAmountFromTokenAmount, getBuyTokenAmountFromSolAmount, getPumpProgram, getSellSolAmountFromTokenAmount, globalPda, globalVolumeAccumulatorPda, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, userVolumeAccumulatorPda };
|
package/dist/index.d.ts
CHANGED
|
@@ -7902,8 +7902,9 @@ declare class PumpSdk {
|
|
|
7902
7902
|
collectCoinCreatorFeeInstructions(coinCreator: PublicKey): Promise<TransactionInstruction[]>;
|
|
7903
7903
|
adminSetCoinCreatorInstructions(newCoinCreator: PublicKey, mint: PublicKey): Promise<TransactionInstruction[]>;
|
|
7904
7904
|
getCreatorVaultBalance(creator: PublicKey): Promise<BN>;
|
|
7905
|
-
adminUpdateTokenIncentives(startTime: BN, endTime: BN, dayNumber: BN, tokenSupplyPerDay: BN, secondsInADay?: BN, mint?: PublicKey, tokenProgram?: PublicKey): Promise<TransactionInstruction>;
|
|
7905
|
+
adminUpdateTokenIncentives(startTime: BN, endTime: BN, dayNumber: BN, tokenSupplyPerDay: BN, secondsInADay?: BN, mint?: PublicKey, tokenProgram?: PublicKey): Promise<TransactionInstruction[]>;
|
|
7906
7906
|
claimTokenIncentives(user: PublicKey, payer: PublicKey, mint?: PublicKey, tokenProgram?: PublicKey): Promise<TransactionInstruction[]>;
|
|
7907
|
+
getCurrentDayTokens(user: PublicKey): Promise<BN>;
|
|
7907
7908
|
}
|
|
7908
7909
|
|
|
7909
7910
|
export { BONDING_CURVE_NEW_SIZE, type BondingCurve, CANONICAL_POOL_INDEX, type Global, PUMP_AMM_PROGRAM_ID, PUMP_PROGRAM_ID, type Pump, PumpSdk, bondingCurvePda, canonicalPumpPoolPda, creatorVaultPda, getBuySolAmountFromTokenAmount, getBuyTokenAmountFromSolAmount, getPumpProgram, getSellSolAmountFromTokenAmount, globalPda, globalVolumeAccumulatorPda, newBondingCurve, pump as pumpIdl, pumpPoolAuthorityPda, userVolumeAccumulatorPda };
|
package/dist/index.js
CHANGED
|
@@ -4000,7 +4000,28 @@ var import_anchor = require("@coral-xyz/anchor");
|
|
|
4000
4000
|
var import_pump_swap_sdk = require("@pump-fun/pump-swap-sdk");
|
|
4001
4001
|
var import_spl_token = require("@solana/spl-token");
|
|
4002
4002
|
var import_web32 = require("@solana/web3.js");
|
|
4003
|
+
var import_bn3 = __toESM(require("bn.js"));
|
|
4004
|
+
|
|
4005
|
+
// src/tokenIncentives.ts
|
|
4003
4006
|
var import_bn2 = __toESM(require("bn.js"));
|
|
4007
|
+
function currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator, currentTimestamp = Date.now() / 1e3) {
|
|
4008
|
+
const { startTime, endTime } = globalVolumeAccumulator;
|
|
4009
|
+
let currentTimestampBn = new import_bn2.default(currentTimestamp);
|
|
4010
|
+
if (currentTimestampBn.lt(startTime) || currentTimestampBn.gt(endTime)) {
|
|
4011
|
+
return new import_bn2.default(0);
|
|
4012
|
+
}
|
|
4013
|
+
const { secondsInADay, totalTokenSupply, solVolumes } = globalVolumeAccumulator;
|
|
4014
|
+
let currentDayIndex = currentTimestampBn.sub(startTime).div(secondsInADay).toNumber();
|
|
4015
|
+
let currentDayTokenSupply = totalTokenSupply[currentDayIndex];
|
|
4016
|
+
let currentDaySolVolume = solVolumes[currentDayIndex];
|
|
4017
|
+
if (currentDaySolVolume.eqn(0)) {
|
|
4018
|
+
return new import_bn2.default(0);
|
|
4019
|
+
}
|
|
4020
|
+
const { currentSolVolume } = userVolumeAccumulator;
|
|
4021
|
+
return currentSolVolume.mul(currentDayTokenSupply).div(currentDaySolVolume);
|
|
4022
|
+
}
|
|
4023
|
+
|
|
4024
|
+
// src/sdk.ts
|
|
4004
4025
|
function getPumpProgram(connection, programId) {
|
|
4005
4026
|
const pumpIdlAddressOverride = { ...pump_default };
|
|
4006
4027
|
pumpIdlAddressOverride.address = programId.toString();
|
|
@@ -4241,7 +4262,7 @@ var PumpSdk = class {
|
|
|
4241
4262
|
return await this.offlinePumpProgram.methods.buy(
|
|
4242
4263
|
amount,
|
|
4243
4264
|
solAmount.add(
|
|
4244
|
-
solAmount.mul(new
|
|
4265
|
+
solAmount.mul(new import_bn3.default(Math.floor(slippage * 10))).div(new import_bn3.default(1e3))
|
|
4245
4266
|
)
|
|
4246
4267
|
).accountsPartial({
|
|
4247
4268
|
feeRecipient: getFeeRecipient(global),
|
|
@@ -4274,7 +4295,7 @@ var PumpSdk = class {
|
|
|
4274
4295
|
await this.offlinePumpProgram.methods.sell(
|
|
4275
4296
|
amount,
|
|
4276
4297
|
solAmount.sub(
|
|
4277
|
-
solAmount.mul(new
|
|
4298
|
+
solAmount.mul(new import_bn3.default(Math.floor(slippage * 10))).div(new import_bn3.default(1e3))
|
|
4278
4299
|
)
|
|
4279
4300
|
).accountsPartial({
|
|
4280
4301
|
feeRecipient: getFeeRecipient(global),
|
|
@@ -4356,54 +4377,79 @@ var PumpSdk = class {
|
|
|
4356
4377
|
const creatorVault = this.creatorVaultPda(creator);
|
|
4357
4378
|
const accountInfo = await this.connection.getAccountInfo(creatorVault);
|
|
4358
4379
|
if (accountInfo === null) {
|
|
4359
|
-
return new
|
|
4380
|
+
return new import_bn3.default(0);
|
|
4360
4381
|
}
|
|
4361
4382
|
const rentExemptionLamports = await this.connection.getMinimumBalanceForRentExemption(
|
|
4362
4383
|
accountInfo.data.length
|
|
4363
4384
|
);
|
|
4364
4385
|
if (accountInfo.lamports < rentExemptionLamports) {
|
|
4365
|
-
return new
|
|
4386
|
+
return new import_bn3.default(0);
|
|
4366
4387
|
}
|
|
4367
|
-
return new
|
|
4388
|
+
return new import_bn3.default(accountInfo.lamports - rentExemptionLamports);
|
|
4368
4389
|
}
|
|
4369
|
-
async adminUpdateTokenIncentives(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new
|
|
4370
|
-
const
|
|
4371
|
-
return
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4390
|
+
async adminUpdateTokenIncentives(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new import_bn3.default(86400), mint = PUMP_TOKEN_MINT, tokenProgram = import_spl_token.TOKEN_2022_PROGRAM_ID) {
|
|
4391
|
+
const { authority } = await this.fetchGlobal();
|
|
4392
|
+
return [
|
|
4393
|
+
await this.offlinePumpProgram.methods.adminUpdateTokenIncentives(
|
|
4394
|
+
startTime,
|
|
4395
|
+
endTime,
|
|
4396
|
+
secondsInADay,
|
|
4397
|
+
dayNumber,
|
|
4398
|
+
tokenSupplyPerDay
|
|
4399
|
+
).accountsPartial({
|
|
4400
|
+
global: this.globalPda(),
|
|
4401
|
+
authority,
|
|
4402
|
+
mint,
|
|
4403
|
+
tokenProgram
|
|
4404
|
+
}).instruction(),
|
|
4405
|
+
await this.pumpAmmAdminSdk.adminUpdateTokenIncentives(
|
|
4406
|
+
startTime,
|
|
4407
|
+
endTime,
|
|
4408
|
+
dayNumber,
|
|
4409
|
+
tokenSupplyPerDay,
|
|
4410
|
+
secondsInADay,
|
|
4411
|
+
mint,
|
|
4412
|
+
tokenProgram
|
|
4413
|
+
)
|
|
4414
|
+
];
|
|
4383
4415
|
}
|
|
4384
4416
|
async claimTokenIncentives(user, payer, mint = PUMP_TOKEN_MINT, tokenProgram = import_spl_token.TOKEN_2022_PROGRAM_ID) {
|
|
4385
|
-
const userPumpAta = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4386
|
-
mint,
|
|
4387
|
-
user,
|
|
4388
|
-
true,
|
|
4389
|
-
tokenProgram
|
|
4390
|
-
);
|
|
4391
4417
|
return [
|
|
4392
|
-
|
|
4393
|
-
payer,
|
|
4394
|
-
userPumpAta,
|
|
4418
|
+
await this.offlinePumpProgram.methods.claimTokenIncentives().accountsPartial({
|
|
4395
4419
|
user,
|
|
4420
|
+
payer,
|
|
4396
4421
|
mint,
|
|
4397
4422
|
tokenProgram
|
|
4398
|
-
),
|
|
4399
|
-
await this.
|
|
4423
|
+
}).instruction(),
|
|
4424
|
+
...await this.pumpAmmSdk.claimTokenIncentives(
|
|
4400
4425
|
user,
|
|
4401
4426
|
payer,
|
|
4402
4427
|
mint,
|
|
4403
4428
|
tokenProgram
|
|
4404
|
-
|
|
4429
|
+
)
|
|
4405
4430
|
];
|
|
4406
4431
|
}
|
|
4432
|
+
async getCurrentDayTokens(user) {
|
|
4433
|
+
const [
|
|
4434
|
+
globalVolumeAccumulatorAccountInfo,
|
|
4435
|
+
userVolumeAccumulatorAccountInfo
|
|
4436
|
+
] = await this.connection.getMultipleAccountsInfo([
|
|
4437
|
+
globalVolumeAccumulatorPda()[0],
|
|
4438
|
+
userVolumeAccumulatorPda(user)[0]
|
|
4439
|
+
]);
|
|
4440
|
+
if (!globalVolumeAccumulatorAccountInfo || !userVolumeAccumulatorAccountInfo) {
|
|
4441
|
+
return new import_bn3.default(0);
|
|
4442
|
+
}
|
|
4443
|
+
const globalVolumeAccumulator = this.decodeGlobalVolumeAccumulator(
|
|
4444
|
+
globalVolumeAccumulatorAccountInfo
|
|
4445
|
+
);
|
|
4446
|
+
const userVolumeAccumulator = this.decodeUserVolumeAccumulator(
|
|
4447
|
+
userVolumeAccumulatorAccountInfo
|
|
4448
|
+
);
|
|
4449
|
+
return currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator).add(
|
|
4450
|
+
await this.pumpAmmSdk.getCurrentDayTokens(user)
|
|
4451
|
+
);
|
|
4452
|
+
}
|
|
4407
4453
|
};
|
|
4408
4454
|
function getFeeRecipient(global) {
|
|
4409
4455
|
const feeRecipients = [global.feeRecipient, ...global.feeRecipients];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pump-fun/pump-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0-devnet.1",
|
|
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": "^0.0.1-beta.
|
|
42
|
+
"@pump-fun/pump-swap-sdk": "^0.0.1-beta.82",
|
|
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/sdk.ts
CHANGED
|
@@ -27,7 +27,13 @@ import {
|
|
|
27
27
|
globalVolumeAccumulatorPda,
|
|
28
28
|
userVolumeAccumulatorPda,
|
|
29
29
|
} from "./pda";
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
BondingCurve,
|
|
32
|
+
Global,
|
|
33
|
+
GlobalVolumeAccumulator,
|
|
34
|
+
UserVolumeAccumulator,
|
|
35
|
+
} from "./state";
|
|
36
|
+
import { currentDayTokens } from "./tokenIncentives";
|
|
31
37
|
|
|
32
38
|
export function getPumpProgram(
|
|
33
39
|
connection: Connection,
|
|
@@ -133,14 +139,18 @@ export class PumpSdk {
|
|
|
133
139
|
);
|
|
134
140
|
}
|
|
135
141
|
|
|
136
|
-
decodeGlobalVolumeAccumulator(
|
|
142
|
+
decodeGlobalVolumeAccumulator(
|
|
143
|
+
accountInfo: AccountInfo<Buffer>,
|
|
144
|
+
): GlobalVolumeAccumulator {
|
|
137
145
|
return this.offlinePumpProgram.coder.accounts.decode<GlobalVolumeAccumulator>(
|
|
138
146
|
"globalVolumeAccumulator",
|
|
139
147
|
accountInfo.data,
|
|
140
148
|
);
|
|
141
149
|
}
|
|
142
150
|
|
|
143
|
-
decodeUserVolumeAccumulator(
|
|
151
|
+
decodeUserVolumeAccumulator(
|
|
152
|
+
accountInfo: AccountInfo<Buffer>,
|
|
153
|
+
): UserVolumeAccumulator {
|
|
144
154
|
return this.offlinePumpProgram.coder.accounts.decode<UserVolumeAccumulator>(
|
|
145
155
|
"userVolumeAccumulator",
|
|
146
156
|
accountInfo.data,
|
|
@@ -202,7 +212,9 @@ export class PumpSdk {
|
|
|
202
212
|
);
|
|
203
213
|
}
|
|
204
214
|
|
|
205
|
-
async fetchUserVolumeAccumulator(
|
|
215
|
+
async fetchUserVolumeAccumulator(
|
|
216
|
+
user: PublicKey,
|
|
217
|
+
): Promise<UserVolumeAccumulator> {
|
|
206
218
|
return await this.pumpProgram.account.userVolumeAccumulator.fetch(
|
|
207
219
|
this.userVolumeAccumulatorPda(user)[0],
|
|
208
220
|
);
|
|
@@ -547,7 +559,7 @@ export class PumpSdk {
|
|
|
547
559
|
return new BN(accountInfo.lamports - rentExemptionLamports);
|
|
548
560
|
}
|
|
549
561
|
|
|
550
|
-
async adminUpdateTokenIncentives(
|
|
562
|
+
async adminUpdateTokenIncentives(
|
|
551
563
|
startTime: BN,
|
|
552
564
|
endTime: BN,
|
|
553
565
|
dayNumber: BN,
|
|
@@ -555,58 +567,89 @@ export class PumpSdk {
|
|
|
555
567
|
secondsInADay: BN = new BN(86400),
|
|
556
568
|
mint: PublicKey = PUMP_TOKEN_MINT,
|
|
557
569
|
tokenProgram: PublicKey = TOKEN_2022_PROGRAM_ID,
|
|
558
|
-
): Promise<TransactionInstruction> {
|
|
559
|
-
const
|
|
570
|
+
): Promise<TransactionInstruction[]> {
|
|
571
|
+
const { authority } = await this.fetchGlobal();
|
|
560
572
|
|
|
561
|
-
return
|
|
562
|
-
.
|
|
573
|
+
return [
|
|
574
|
+
await this.offlinePumpProgram.methods
|
|
575
|
+
.adminUpdateTokenIncentives(
|
|
576
|
+
startTime,
|
|
577
|
+
endTime,
|
|
578
|
+
secondsInADay,
|
|
579
|
+
dayNumber,
|
|
580
|
+
tokenSupplyPerDay,
|
|
581
|
+
)
|
|
582
|
+
.accountsPartial({
|
|
583
|
+
global: this.globalPda(),
|
|
584
|
+
authority,
|
|
585
|
+
mint,
|
|
586
|
+
tokenProgram,
|
|
587
|
+
})
|
|
588
|
+
.instruction(),
|
|
589
|
+
await this.pumpAmmAdminSdk.adminUpdateTokenIncentives(
|
|
563
590
|
startTime,
|
|
564
591
|
endTime,
|
|
565
|
-
secondsInADay,
|
|
566
592
|
dayNumber,
|
|
567
593
|
tokenSupplyPerDay,
|
|
568
|
-
|
|
569
|
-
.accountsPartial({
|
|
570
|
-
global: this.globalPda(),
|
|
571
|
-
authority: global.authority,
|
|
594
|
+
secondsInADay,
|
|
572
595
|
mint,
|
|
573
596
|
tokenProgram,
|
|
574
|
-
|
|
575
|
-
|
|
597
|
+
),
|
|
598
|
+
];
|
|
576
599
|
}
|
|
577
600
|
|
|
578
601
|
async claimTokenIncentives(
|
|
579
602
|
user: PublicKey,
|
|
580
603
|
payer: PublicKey,
|
|
581
604
|
mint: PublicKey = PUMP_TOKEN_MINT,
|
|
582
|
-
tokenProgram: PublicKey = TOKEN_2022_PROGRAM_ID
|
|
605
|
+
tokenProgram: PublicKey = TOKEN_2022_PROGRAM_ID,
|
|
583
606
|
): Promise<TransactionInstruction[]> {
|
|
584
|
-
const userPumpAta = getAssociatedTokenAddressSync(
|
|
585
|
-
mint,
|
|
586
|
-
user,
|
|
587
|
-
true,
|
|
588
|
-
tokenProgram,
|
|
589
|
-
);
|
|
590
|
-
|
|
591
607
|
return [
|
|
592
|
-
createAssociatedTokenAccountIdempotentInstruction(
|
|
593
|
-
payer,
|
|
594
|
-
userPumpAta,
|
|
595
|
-
user,
|
|
596
|
-
mint,
|
|
597
|
-
tokenProgram,
|
|
598
|
-
),
|
|
599
608
|
await this.offlinePumpProgram.methods
|
|
600
609
|
.claimTokenIncentives()
|
|
601
|
-
.accountsPartial({
|
|
610
|
+
.accountsPartial({
|
|
602
611
|
user,
|
|
603
612
|
payer,
|
|
604
613
|
mint,
|
|
605
614
|
tokenProgram,
|
|
606
615
|
})
|
|
607
616
|
.instruction(),
|
|
617
|
+
...(await this.pumpAmmSdk.claimTokenIncentives(
|
|
618
|
+
user,
|
|
619
|
+
payer,
|
|
620
|
+
mint,
|
|
621
|
+
tokenProgram,
|
|
622
|
+
)),
|
|
608
623
|
];
|
|
609
|
-
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
async getCurrentDayTokens(user: PublicKey): Promise<BN> {
|
|
627
|
+
const [
|
|
628
|
+
globalVolumeAccumulatorAccountInfo,
|
|
629
|
+
userVolumeAccumulatorAccountInfo,
|
|
630
|
+
] = await this.connection.getMultipleAccountsInfo([
|
|
631
|
+
globalVolumeAccumulatorPda()[0],
|
|
632
|
+
userVolumeAccumulatorPda(user)[0],
|
|
633
|
+
]);
|
|
634
|
+
|
|
635
|
+
if (
|
|
636
|
+
!globalVolumeAccumulatorAccountInfo ||
|
|
637
|
+
!userVolumeAccumulatorAccountInfo
|
|
638
|
+
) {
|
|
639
|
+
return new BN(0);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const globalVolumeAccumulator = this.decodeGlobalVolumeAccumulator(
|
|
643
|
+
globalVolumeAccumulatorAccountInfo,
|
|
644
|
+
);
|
|
645
|
+
const userVolumeAccumulator = this.decodeUserVolumeAccumulator(
|
|
646
|
+
userVolumeAccumulatorAccountInfo,
|
|
647
|
+
);
|
|
648
|
+
|
|
649
|
+
return currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator).add(
|
|
650
|
+
await this.pumpAmmSdk.getCurrentDayTokens(user),
|
|
651
|
+
);
|
|
652
|
+
}
|
|
610
653
|
}
|
|
611
654
|
|
|
612
655
|
function getFeeRecipient(global: Global): PublicKey {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import { GlobalVolumeAccumulator, UserVolumeAccumulator } from "./state";
|
|
3
|
+
|
|
4
|
+
export function currentDayTokens(
|
|
5
|
+
globalVolumeAccumulator: GlobalVolumeAccumulator,
|
|
6
|
+
userVolumeAccumulator: UserVolumeAccumulator,
|
|
7
|
+
currentTimestamp: number = Date.now() / 1000,
|
|
8
|
+
): BN {
|
|
9
|
+
const { startTime, endTime } = globalVolumeAccumulator;
|
|
10
|
+
|
|
11
|
+
let currentTimestampBn = new BN(currentTimestamp);
|
|
12
|
+
|
|
13
|
+
if (currentTimestampBn.lt(startTime) || currentTimestampBn.gt(endTime)) {
|
|
14
|
+
return new BN(0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { secondsInADay, totalTokenSupply, solVolumes } =
|
|
18
|
+
globalVolumeAccumulator;
|
|
19
|
+
|
|
20
|
+
let currentDayIndex = currentTimestampBn
|
|
21
|
+
.sub(startTime)
|
|
22
|
+
.div(secondsInADay)
|
|
23
|
+
.toNumber();
|
|
24
|
+
|
|
25
|
+
let currentDayTokenSupply = totalTokenSupply[currentDayIndex];
|
|
26
|
+
let currentDaySolVolume = solVolumes[currentDayIndex];
|
|
27
|
+
|
|
28
|
+
if (currentDaySolVolume.eqn(0)) {
|
|
29
|
+
return new BN(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { currentSolVolume } = userVolumeAccumulator;
|
|
33
|
+
|
|
34
|
+
return currentSolVolume.mul(currentDayTokenSupply).div(currentDaySolVolume);
|
|
35
|
+
}
|