@merkl/api 0.16.24 → 0.16.26

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.
@@ -231,6 +231,7 @@ export class CampaignRepository {
231
231
  },
232
232
  OR: [
233
233
  {
234
+ startTimestamp: { gt: 1735686000 }, // Cutoff for feature release, 01/01/2025
234
235
  // First case: the campaign has no status so was never processed
235
236
  CampaignStatus: {
236
237
  none: {
@@ -8,6 +8,8 @@ import { TokenService } from "../token/token.service";
8
8
  import { InvalidParameter } from "../../../utils/error";
9
9
  import { executeSimple } from "../../../utils/execute";
10
10
  import { log } from "../../../utils/logger";
11
+ import { apiDbClient } from "../../../utils/prisma";
12
+ import { RunStatus } from "../../../../database/api/.generated";
11
13
  import { Campaign as CampaignEnum, NETWORK_LABELS, } from "@sdk";
12
14
  import { utils } from "ethers";
13
15
  import moment from "moment";
@@ -155,9 +157,20 @@ export class CampaignService {
155
157
  return await CampaignRepository.findUniqueOrThrow(id);
156
158
  }
157
159
  static async findCampaignsToProcess(distributionChainId) {
160
+ await apiDbClient.campaignStatus.updateMany({
161
+ data: {
162
+ status: RunStatus.FAILED,
163
+ },
164
+ where: {
165
+ Campaign: {
166
+ distributionChainId: 1,
167
+ },
168
+ status: RunStatus.PROCESSING,
169
+ },
170
+ });
158
171
  return (await CampaignRepository.findCampaignsToProcess(distributionChainId))
159
- .filter(campaign => campaign.endTimestamp > (campaign?.CampaignStatus?.[0]?.computedUntil ?? 0))
160
- ?.sort((a, b) => Number((a.CampaignStatus?.[0]?.processingStarted ?? 0) - (b.CampaignStatus?.[0]?.processingStarted ?? 0)));
172
+ .filter(campaign => campaign.endTimestamp > (campaign?.CampaignStatus?.[0]?.computedUntil ?? 0n))
173
+ ?.sort((a, b) => Number((a.CampaignStatus?.[0]?.processingStarted ?? 0n) - (b.CampaignStatus?.[0]?.processingStarted ?? 0n)));
161
174
  }
162
175
  static async findNextCampaignToProcess(chainId) {
163
176
  const campaigns = await CampaignService.findCampaignsToProcess(chainId);
@@ -73,7 +73,8 @@ export class ReferralService {
73
73
  return referralStatus === 1;
74
74
  }
75
75
  static generateCode(chainId, key, address) {
76
- return Bun.hash([chainId, key, address].join("-")).toString().slice(0, 12);
76
+ const digits = [chainId, key, address, 4, 5, 6].map(() => Math.floor(Math.random() * 10)).join("");
77
+ return `${key.toUpperCase()}-${digits}`;
77
78
  }
78
79
  static async getCode(chainId, key, address) {
79
80
  const referralContractAddress = ReferralService.getReferralContract(chainId);