@meteora-ag/cp-amm-sdk 1.0.11-rc.0 → 1.0.11-rc.2

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/index.mjs CHANGED
@@ -6097,10 +6097,10 @@ function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeContr
6097
6097
  return vFee.add(new BN5(99999999999)).div(new BN5(1e11));
6098
6098
  }
6099
6099
  function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFrequency, feeSchedulerMode, cliffFeeNumerator, reductionFactor, dynamicFeeParams) {
6100
- if (Number(periodFrequency) == 0 || new BN5(currentPoint).lt(activationPoint)) {
6100
+ if (Number(periodFrequency) == 0) {
6101
6101
  return cliffFeeNumerator;
6102
6102
  }
6103
- const period = BN5.min(
6103
+ const period = new BN5(currentPoint).lt(activationPoint) ? new BN5(numberOfPeriod) : BN5.min(
6104
6104
  new BN5(numberOfPeriod),
6105
6105
  new BN5(currentPoint).sub(activationPoint).div(periodFrequency)
6106
6106
  );
@@ -8532,7 +8532,6 @@ var CpAmm = class {
8532
8532
  rewardMintProgram
8533
8533
  } = params;
8534
8534
  const rewardVault = deriveRewardVaultAddress(pool, rewardIndex);
8535
- const tokenProgram = rewardMintProgram ? rewardMintProgram : (yield this._program.provider.connection.getAccountInfo(rewardMint)).owner;
8536
8535
  return yield this._program.methods.initializeReward(rewardIndex, rewardDuration, funder).accountsPartial({
8537
8536
  poolAuthority: this.poolAuthority,
8538
8537
  pool,
@@ -8540,10 +8539,52 @@ var CpAmm = class {
8540
8539
  rewardMint,
8541
8540
  signer: creator,
8542
8541
  payer,
8543
- tokenProgram
8542
+ tokenProgram: rewardMintProgram
8544
8543
  }).transaction();
8545
8544
  });
8546
8545
  }
8546
+ /**
8547
+ * Builds a transaction to initialize reward and fund reward
8548
+ * @param {InitializeAndFundReward} params
8549
+ * @returns Transaction builder.
8550
+ */
8551
+ initializeAndFundReward(params) {
8552
+ return __async(this, null, function* () {
8553
+ const {
8554
+ rewardIndex,
8555
+ rewardDuration,
8556
+ pool,
8557
+ creator,
8558
+ payer,
8559
+ rewardMint,
8560
+ carryForward,
8561
+ amount,
8562
+ rewardMintProgram
8563
+ } = params;
8564
+ const rewardVault = deriveRewardVaultAddress(pool, rewardIndex);
8565
+ const initializeRewardTx = yield this.initializeReward({
8566
+ rewardIndex,
8567
+ rewardDuration,
8568
+ funder: payer,
8569
+ pool,
8570
+ creator,
8571
+ payer,
8572
+ rewardMint,
8573
+ rewardMintProgram
8574
+ });
8575
+ const fundRewardTx = yield this.fundReward({
8576
+ rewardIndex,
8577
+ carryForward,
8578
+ pool,
8579
+ funder: payer,
8580
+ amount,
8581
+ rewardMint,
8582
+ rewardVault,
8583
+ rewardMintProgram
8584
+ });
8585
+ return new Transaction().add(initializeRewardTx).add(fundRewardTx);
8586
+ });
8587
+ }
8547
8588
  /**
8548
8589
  * Builds a transaction to update reward duration.
8549
8590
  * @param {UpdateRewardDurationParams} params - Parameters including pool and new duration.
@@ -8579,22 +8620,27 @@ var CpAmm = class {
8579
8620
  */
8580
8621
  fundReward(params) {
8581
8622
  return __async(this, null, function* () {
8582
- const { rewardIndex, carryForward, pool, funder, amount } = params;
8583
- const poolState = yield this.fetchPoolState(pool);
8584
- const rewardInfo = poolState.rewardInfos[rewardIndex];
8585
- const { vault, mint } = rewardInfo;
8586
- const tokenProgram = getTokenProgram(rewardIndex);
8623
+ const {
8624
+ rewardIndex,
8625
+ carryForward,
8626
+ pool,
8627
+ funder,
8628
+ amount,
8629
+ rewardMint,
8630
+ rewardVault,
8631
+ rewardMintProgram
8632
+ } = params;
8587
8633
  const preInstructions = [];
8588
8634
  const { ataPubkey: funderTokenAccount, ix: createFunderTokenAccountIx } = yield getOrCreateATAInstruction(
8589
8635
  this._program.provider.connection,
8590
- mint,
8636
+ rewardMint,
8591
8637
  funder,
8592
8638
  funder,
8593
8639
  true,
8594
- tokenProgram
8640
+ rewardMintProgram
8595
8641
  );
8596
8642
  createFunderTokenAccountIx && preInstructions.push(createFunderTokenAccountIx);
8597
- if (mint.equals(NATIVE_MINT2) && !amount.isZero()) {
8643
+ if (rewardMint.equals(NATIVE_MINT2) && !amount.isZero()) {
8598
8644
  const wrapSOLIx = wrapSOLInstruction(
8599
8645
  funder,
8600
8646
  funderTokenAccount,
@@ -8604,11 +8650,11 @@ var CpAmm = class {
8604
8650
  }
8605
8651
  return yield this._program.methods.fundReward(rewardIndex, amount, carryForward).accountsPartial({
8606
8652
  pool,
8607
- rewardVault: vault,
8608
- rewardMint: mint,
8653
+ rewardVault,
8654
+ rewardMint,
8609
8655
  funderTokenAccount,
8610
8656
  funder,
8611
- tokenProgram
8657
+ tokenProgram: rewardMintProgram
8612
8658
  }).transaction();
8613
8659
  });
8614
8660
  }