@merkl/api 0.20.150 → 0.20.151

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.
@@ -1,4 +1,3 @@
1
- import type { CacheKeys } from "@/cache/keys";
2
1
  import type { LightOpportunityFromDB, Opportunity } from "@/modules/v4/opportunity/opportunity.model";
3
2
  import type { Chain } from "@db/api";
4
3
  import { type CampaignDynamicData, Campaign as CampaignType, type ChainId, type MerklChainId } from "@sdk";
@@ -668,7 +667,7 @@ export declare abstract class RewardService {
668
667
  })[];
669
668
  })[];
670
669
  static findManyRootsOnChain(chainId: ChainId): Promise<string[]>;
671
- static checkLastClaim(chainId: number, user: string, roots: CacheKeys["CurrentRoot"]["returns"], rewards: Awaited<ReturnType<(typeof RewardService)["getByRecipient"]>>): Promise<({
670
+ static checkLastClaim(chainId: number, user: string, rewards: Awaited<ReturnType<(typeof RewardService)["getByRecipient"]>>): Promise<({
672
671
  RewardToken: {
673
672
  symbol: string;
674
673
  id: string;
@@ -190,21 +190,22 @@ export class RewardService {
190
190
  static async findManyRootsOnChain(chainId) {
191
191
  return await CacheService.wrap(TTLPresets.MIN_10, RewardRepository.findManyRootsWithRewardOnChain, chainId);
192
192
  }
193
- static async checkLastClaim(chainId, user, roots, rewards) {
193
+ static async checkLastClaim(chainId, user, rewards) {
194
+ // Fetch the root of the last claim for each reward token
194
195
  const claims = await DistributorService(chainId).claimedMultiple(user, rewards.map(reward => reward.RewardToken.address));
195
196
  const rootsWithRewardOnChain = await RewardService.findManyRootsOnChain(chainId);
196
197
  for (const [index, reward] of rewards.entries()) {
197
198
  const tokenId = TokenService.hashId(reward.RewardToken);
198
199
  const merklRootClaimedOn = claims[index].merkleRoot;
199
200
  // -> claim is on the current root (chainData.merklRoot) -> claimed === accumulated
200
- if (merklRootClaimedOn === roots.live) {
201
+ if (merklRootClaimedOn === reward.root) {
201
202
  reward.claimed = reward.amount;
202
203
  await RewardRepository.updateRewardClaimed(user, tokenId, reward.amount);
203
204
  for (const breakdown of reward.Breakdown) {
204
205
  if (BigInt(breakdown.claimed) === BigInt(breakdown.amount))
205
206
  continue;
206
207
  breakdown.claimed = breakdown.amount; // Set unclaim to 0
207
- await RewardRepository.updateBreakdownClaimed(user, tokenId, reward.Breakdown[0].campaignId, reward.Breakdown[0].reason, reward.Breakdown[0].amount);
208
+ await RewardRepository.updateBreakdownClaimed(user, tokenId, breakdown.campaignId, breakdown.reason, breakdown.amount);
208
209
  }
209
210
  }
210
211
  // -> claim is on a tree we have in db -> claimed === accumulated of the rewards of lastTree
@@ -247,14 +248,14 @@ export class RewardService {
247
248
  const rewards = (await RewardService.getByRecipient(user, merkleRoots.map(({ live }) => live), withToken, withTestTokens)).filter(reward => chainIds.includes(reward.RewardToken.chainId) &&
248
249
  (claimableOnly ? BigInt(reward.amount) - BigInt(reward.claimed) > 0n : true));
249
250
  const promises = [];
250
- for (const [index, chainId] of chainIds.entries()) {
251
+ for (const chainId of chainIds) {
251
252
  const chain = chains.find(chain => chain.id === chainId);
252
253
  if (!chain)
253
254
  throw new Error(`Chain ${chainId} not found`);
254
255
  const chainRewards = rewards.filter(reward => reward.RewardToken.chainId === chainId);
255
256
  /** Check when the last claim happened */
256
257
  if (chain.id === connectedChainId && chainRewards.length > 0) {
257
- promises.push(RewardService.checkLastClaim(chainId, user, merkleRoots[index], chainRewards).then(r => {
258
+ promises.push(RewardService.checkLastClaim(chainId, user, chainRewards).then(r => {
258
259
  return { chain, rewards: r };
259
260
  }));
260
261
  }