@meteora-ag/cp-amm-sdk 1.0.11-rc.5 → 1.0.11-rc.7
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.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +56 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6372,30 +6372,67 @@ var getUnClaimReward = (poolState, positionState) => {
|
|
|
6372
6372
|
rewards: positionState.rewardInfos.length > 0 ? positionState.rewardInfos.map((item) => item.rewardPendings) : []
|
|
6373
6373
|
};
|
|
6374
6374
|
};
|
|
6375
|
-
function
|
|
6376
|
-
const
|
|
6377
|
-
|
|
6378
|
-
|
|
6375
|
+
function getRewardPerTokenStore(poolReward, poolLiquidity, currentTime) {
|
|
6376
|
+
const lastTimeRewardApplicable = BN6.min(
|
|
6377
|
+
currentTime,
|
|
6378
|
+
poolReward.rewardDurationEnd
|
|
6379
|
+
);
|
|
6379
6380
|
const timePeriod = lastTimeRewardApplicable.sub(poolReward.lastUpdateTime);
|
|
6380
6381
|
const currentTotalReward = timePeriod.mul(poolReward.rewardRate);
|
|
6381
|
-
const rewardPerTokenStore = currentTotalReward.shln(128).div(
|
|
6382
|
+
const rewardPerTokenStore = currentTotalReward.shln(128).div(poolLiquidity);
|
|
6383
|
+
const totalRewardPerTokenStore = new BN6(
|
|
6384
|
+
Buffer.from(poolReward.rewardPerTokenStored).reverse()
|
|
6385
|
+
).add(rewardPerTokenStore);
|
|
6386
|
+
return totalRewardPerTokenStore;
|
|
6387
|
+
}
|
|
6388
|
+
function getRewardPerPeriod(poolReward, currentTime, periodTime) {
|
|
6389
|
+
const timeRewardAppicable = currentTime.add(periodTime);
|
|
6390
|
+
const period = timeRewardAppicable <= poolReward.rewardDurationEnd ? periodTime : poolReward.rewardDurationEnd.sub(currentTime);
|
|
6391
|
+
const rewardPerPeriod = poolReward.rewardRate.mul(period);
|
|
6392
|
+
return rewardPerPeriod;
|
|
6393
|
+
}
|
|
6394
|
+
function getRewardInfo(poolState, rewardIndex, periodTime, currentTime) {
|
|
6395
|
+
const poolReward = poolState.rewardInfos[rewardIndex];
|
|
6396
|
+
const totalReward = poolReward.rewardRate.mul(poolReward.rewardDuration).shrn(64);
|
|
6397
|
+
const rewardPerTokenStore = getRewardPerTokenStore(
|
|
6398
|
+
poolReward,
|
|
6399
|
+
poolState.liquidity,
|
|
6400
|
+
currentTime
|
|
6401
|
+
);
|
|
6402
|
+
const totalRewardDistributed = rewardPerTokenStore.mul(poolState.liquidity).shrn(192);
|
|
6403
|
+
const rewardPerPeriod = getRewardPerPeriod(
|
|
6404
|
+
poolReward,
|
|
6405
|
+
currentTime,
|
|
6406
|
+
periodTime
|
|
6407
|
+
);
|
|
6408
|
+
return {
|
|
6409
|
+
rewardPerPeriod: rewardPerPeriod.shrn(64),
|
|
6410
|
+
rewardBalance: totalReward.sub(totalRewardDistributed)
|
|
6411
|
+
};
|
|
6412
|
+
}
|
|
6413
|
+
function getUserRewardPending(poolState, positionState, rewardIndex, currentTime, periodTime) {
|
|
6414
|
+
const poolReward = poolState.rewardInfos[rewardIndex];
|
|
6415
|
+
const userRewardInfo = positionState.rewardInfos[rewardIndex];
|
|
6416
|
+
const rewardPerTokenStore = getRewardPerTokenStore(
|
|
6417
|
+
poolReward,
|
|
6418
|
+
poolState.liquidity,
|
|
6419
|
+
currentTime
|
|
6420
|
+
);
|
|
6421
|
+
const totalPositionLiquidity = positionState.unlockedLiquidity.add(positionState.vestedLiquidity).add(positionState.permanentLockedLiquidity);
|
|
6382
6422
|
const userRewardPerTokenCheckPoint = new BN6(
|
|
6383
6423
|
Buffer.from(userRewardInfo.rewardPerTokenCheckpoint).reverse()
|
|
6384
6424
|
);
|
|
6385
|
-
const totalPositionLiquidity = positionState.unlockedLiquidity.add(positionState.vestedLiquidity).add(positionState.permanentLockedLiquidity);
|
|
6386
6425
|
const newReward = totalPositionLiquidity.mul(rewardPerTokenStore.sub(userRewardPerTokenCheckPoint)).shrn(192);
|
|
6387
|
-
const
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6426
|
+
const rewardPerPeriod = getRewardPerPeriod(
|
|
6427
|
+
poolReward,
|
|
6428
|
+
currentTime,
|
|
6429
|
+
periodTime
|
|
6430
|
+
);
|
|
6431
|
+
const rewardPerTokenStorePerPeriod = rewardPerPeriod.shln(128).div(poolState.liquidity);
|
|
6432
|
+
const userRewardPerPeriod = totalPositionLiquidity.mul(rewardPerTokenStorePerPeriod).shrn(192);
|
|
6394
6433
|
return {
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
totalPoolRewardPerPeriod: totalRewardPerPeriod.shrn(64),
|
|
6398
|
-
rewardBalance: totalReward.sub(totalRewardDistributed)
|
|
6434
|
+
userPendingReward: userRewardInfo.rewardPendings.add(newReward),
|
|
6435
|
+
userRewardPerPeriod
|
|
6399
6436
|
};
|
|
6400
6437
|
}
|
|
6401
6438
|
|
|
@@ -9028,6 +9065,7 @@ export {
|
|
|
9028
9065
|
getTokenProgram,
|
|
9029
9066
|
getTotalLockedLiquidity,
|
|
9030
9067
|
getUnClaimReward,
|
|
9068
|
+
getUserRewardPending,
|
|
9031
9069
|
isVestingComplete,
|
|
9032
9070
|
mulDiv,
|
|
9033
9071
|
positionByPoolFilter,
|