@meteora-ag/cp-amm-sdk 1.0.11-rc.1 → 1.0.11-rc.3

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
@@ -6372,6 +6372,28 @@ var getUnClaimReward = (poolState, positionState) => {
6372
6372
  rewards: positionState.rewardInfos.length > 0 ? positionState.rewardInfos.map((item) => item.rewardPendings) : []
6373
6373
  };
6374
6374
  };
6375
+ function getRewardInfo(poolState, positionState, rewardIndex, periodTime) {
6376
+ const poolReward = poolState.rewardInfos[rewardIndex];
6377
+ const userRewardInfo = positionState.rewardInfos[rewardIndex];
6378
+ const rewardPerTokenStore = new BN6(
6379
+ Buffer.from(poolReward.rewardPerTokenStored).reverse()
6380
+ );
6381
+ const userRewardPerTokenCheckPoint = new BN6(
6382
+ Buffer.from(userRewardInfo.rewardPerTokenCheckpoint).reverse()
6383
+ );
6384
+ const totalPositionLiquidity = positionState.unlockedLiquidity.add(positionState.vestedLiquidity).add(positionState.permanentLockedLiquidity);
6385
+ const newReward = totalPositionLiquidity.mul(rewardPerTokenStore.sub(userRewardPerTokenCheckPoint)).shrn(192);
6386
+ const totalRewardPerPeriod = poolReward.rewardRate.mul(periodTime);
6387
+ const rewardPerTokenStorePerPeriod = totalRewardPerPeriod.shln(128).div(poolState.liquidity);
6388
+ const totalUserRewardPerPeriod = totalPositionLiquidity.mul(rewardPerTokenStorePerPeriod).shrn(192);
6389
+ const totalReward = poolReward.rewardRate.mul(poolReward.rewardDuration).shrn(64);
6390
+ const totalRewardDistributed = rewardPerTokenStore.mul(poolState.liquidity).shrn(192);
6391
+ return {
6392
+ rewardPendings: userRewardInfo.rewardPendings.add(newReward),
6393
+ totalUserRewardPerPeriod,
6394
+ rewardBalance: totalReward.sub(totalRewardDistributed)
6395
+ };
6396
+ }
6375
6397
 
6376
6398
  // src/helpers/accountFilters.ts
6377
6399
  var positionByPoolFilter = (pool) => {
@@ -8532,7 +8554,6 @@ var CpAmm = class {
8532
8554
  rewardMintProgram
8533
8555
  } = params;
8534
8556
  const rewardVault = deriveRewardVaultAddress(pool, rewardIndex);
8535
- const tokenProgram = rewardMintProgram ? rewardMintProgram : (yield this._program.provider.connection.getAccountInfo(rewardMint)).owner;
8536
8557
  return yield this._program.methods.initializeReward(rewardIndex, rewardDuration, funder).accountsPartial({
8537
8558
  poolAuthority: this.poolAuthority,
8538
8559
  pool,
@@ -8540,7 +8561,7 @@ var CpAmm = class {
8540
8561
  rewardMint,
8541
8562
  signer: creator,
8542
8563
  payer,
8543
- tokenProgram
8564
+ tokenProgram: rewardMintProgram
8544
8565
  }).transaction();
8545
8566
  });
8546
8567
  }
@@ -8562,6 +8583,7 @@ var CpAmm = class {
8562
8583
  amount,
8563
8584
  rewardMintProgram
8564
8585
  } = params;
8586
+ const rewardVault = deriveRewardVaultAddress(pool, rewardIndex);
8565
8587
  const initializeRewardTx = yield this.initializeReward({
8566
8588
  rewardIndex,
8567
8589
  rewardDuration,
@@ -8577,7 +8599,10 @@ var CpAmm = class {
8577
8599
  carryForward,
8578
8600
  pool,
8579
8601
  funder: payer,
8580
- amount
8602
+ amount,
8603
+ rewardMint,
8604
+ rewardVault,
8605
+ rewardMintProgram
8581
8606
  });
8582
8607
  return new Transaction().add(initializeRewardTx).add(fundRewardTx);
8583
8608
  });
@@ -8617,22 +8642,27 @@ var CpAmm = class {
8617
8642
  */
8618
8643
  fundReward(params) {
8619
8644
  return __async(this, null, function* () {
8620
- const { rewardIndex, carryForward, pool, funder, amount } = params;
8621
- const poolState = yield this.fetchPoolState(pool);
8622
- const rewardInfo = poolState.rewardInfos[rewardIndex];
8623
- const { vault, mint } = rewardInfo;
8624
- const tokenProgram = getTokenProgram(rewardIndex);
8645
+ const {
8646
+ rewardIndex,
8647
+ carryForward,
8648
+ pool,
8649
+ funder,
8650
+ amount,
8651
+ rewardMint,
8652
+ rewardVault,
8653
+ rewardMintProgram
8654
+ } = params;
8625
8655
  const preInstructions = [];
8626
8656
  const { ataPubkey: funderTokenAccount, ix: createFunderTokenAccountIx } = yield getOrCreateATAInstruction(
8627
8657
  this._program.provider.connection,
8628
- mint,
8658
+ rewardMint,
8629
8659
  funder,
8630
8660
  funder,
8631
8661
  true,
8632
- tokenProgram
8662
+ rewardMintProgram
8633
8663
  );
8634
8664
  createFunderTokenAccountIx && preInstructions.push(createFunderTokenAccountIx);
8635
- if (mint.equals(NATIVE_MINT2) && !amount.isZero()) {
8665
+ if (rewardMint.equals(NATIVE_MINT2) && !amount.isZero()) {
8636
8666
  const wrapSOLIx = wrapSOLInstruction(
8637
8667
  funder,
8638
8668
  funderTokenAccount,
@@ -8642,11 +8672,11 @@ var CpAmm = class {
8642
8672
  }
8643
8673
  return yield this._program.methods.fundReward(rewardIndex, amount, carryForward).accountsPartial({
8644
8674
  pool,
8645
- rewardVault: vault,
8646
- rewardMint: mint,
8675
+ rewardVault,
8676
+ rewardMint,
8647
8677
  funderTokenAccount,
8648
8678
  funder,
8649
- tokenProgram
8679
+ tokenProgram: rewardMintProgram
8650
8680
  }).transaction();
8651
8681
  });
8652
8682
  }
@@ -8985,6 +9015,7 @@ export {
8985
9015
  getOrCreateATAInstruction,
8986
9016
  getPriceFromSqrtPrice,
8987
9017
  getPriceImpact,
9018
+ getRewardInfo,
8988
9019
  getSecondKey,
8989
9020
  getSimulationComputeUnits,
8990
9021
  getSqrtPriceFromPrice,