@merkl/api 0.21.19 → 0.21.20

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.
@@ -256,6 +256,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
256
256
  query: {
257
257
  status?: "NONE" | "PAST" | "LIVE" | "SOON" | undefined;
258
258
  type?: string | undefined;
259
+ id?: string | undefined;
259
260
  items?: number | undefined;
260
261
  subType?: number | undefined;
261
262
  page?: number | undefined;
@@ -483,7 +484,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
483
484
  timestamp: bigint;
484
485
  walletCount: number;
485
486
  }[];
486
- tvlInflowPerDollar: bigint;
487
+ tvlInflowPerDollar: number;
487
488
  };
488
489
  };
489
490
  };
@@ -577,6 +578,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
577
578
  query: {
578
579
  status?: "NONE" | "PAST" | "LIVE" | "SOON" | undefined;
579
580
  type?: string | undefined;
581
+ id?: string | undefined;
580
582
  items?: number | undefined;
581
583
  subType?: number | undefined;
582
584
  page?: number | undefined;
@@ -694,6 +696,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
694
696
  query: {
695
697
  status?: "NONE" | "PAST" | "LIVE" | "SOON" | undefined;
696
698
  type?: string | undefined;
699
+ id?: string | undefined;
697
700
  items?: number | undefined;
698
701
  subType?: number | undefined;
699
702
  page?: number | undefined;
@@ -733,6 +736,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
733
736
  query: {
734
737
  status?: "NONE" | "PAST" | "LIVE" | "SOON" | undefined;
735
738
  type?: string | undefined;
739
+ id?: string | undefined;
736
740
  items?: number | undefined;
737
741
  subType?: number | undefined;
738
742
  page?: number | undefined;
@@ -777,6 +781,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
777
781
  query: {
778
782
  status?: "NONE" | "PAST" | "LIVE" | "SOON" | undefined;
779
783
  type?: string | undefined;
784
+ id?: string | undefined;
780
785
  items?: number | undefined;
781
786
  subType?: number | undefined;
782
787
  page?: number | undefined;
@@ -822,6 +827,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
822
827
  query: {
823
828
  status?: "NONE" | "PAST" | "LIVE" | "SOON" | undefined;
824
829
  type?: string | undefined;
830
+ id?: string | undefined;
825
831
  items?: number | undefined;
826
832
  subType?: number | undefined;
827
833
  page?: number | undefined;
@@ -872,6 +878,7 @@ export declare const CampaignController: Elysia<"/campaigns", false, {
872
878
  query: {
873
879
  status?: "NONE" | "PAST" | "LIVE" | "SOON" | undefined;
874
880
  type?: string | undefined;
881
+ id?: string | undefined;
875
882
  items?: number | undefined;
876
883
  subType?: number | undefined;
877
884
  page?: number | undefined;
@@ -145,6 +145,7 @@ export declare const UpdateMetaDataCampaignDto: import("@sinclair/typebox").TObj
145
145
  url: import("@sinclair/typebox").TString;
146
146
  }>;
147
147
  export declare const GetCampaignQueryDto: import("@sinclair/typebox").TObject<{
148
+ id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
148
149
  creatorTag: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
149
150
  creatorAddress: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
150
151
  creatorId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -90,6 +90,7 @@ export const UpdateMetaDataCampaignDto = t.Object({
90
90
  url: t.String(),
91
91
  });
92
92
  export const GetCampaignQueryDto = t.Object({
93
+ id: t.Optional(t.String()),
93
94
  creatorTag: t.Optional(t.String({ description: "Filter campaigns created by a user who has a specific tag" })),
94
95
  creatorAddress: t.Optional(t.String()),
95
96
  creatorId: t.Optional(t.String({ description: "Filter campaigns created by a user who is registered as a merkl creator" })),
@@ -24,6 +24,9 @@ export declare abstract class CampaignRepository {
24
24
  gt?: undefined;
25
25
  gte?: undefined;
26
26
  };
27
+ OR: {
28
+ id: string;
29
+ }[] | undefined;
27
30
  distributionChainId: {
28
31
  in: number[];
29
32
  } | undefined;
@@ -101,6 +104,9 @@ export declare abstract class CampaignRepository {
101
104
  gte?: undefined;
102
105
  };
103
106
  startTimestamp?: undefined;
107
+ OR: {
108
+ id: string;
109
+ }[] | undefined;
104
110
  distributionChainId: {
105
111
  in: number[];
106
112
  } | undefined;
@@ -179,6 +185,9 @@ export declare abstract class CampaignRepository {
179
185
  gte?: undefined;
180
186
  };
181
187
  endTimestamp?: undefined;
188
+ OR: {
189
+ id: string;
190
+ }[] | undefined;
182
191
  distributionChainId: {
183
192
  in: number[];
184
193
  } | undefined;
@@ -260,6 +269,9 @@ export declare abstract class CampaignRepository {
260
269
  lte?: undefined;
261
270
  gt?: undefined;
262
271
  } | undefined;
272
+ OR: {
273
+ id: string;
274
+ }[] | undefined;
263
275
  distributionChainId: {
264
276
  in: number[];
265
277
  } | undefined;
@@ -871,6 +883,12 @@ export declare abstract class CampaignRepository {
871
883
  total: number;
872
884
  timestamp: bigint;
873
885
  }[]>;
886
+ static getWalletCount(campaign: {
887
+ id: string;
888
+ opportunityId: string;
889
+ startTimestamp: bigint;
890
+ endTimestamp: bigint;
891
+ }): Promise<number>;
874
892
  static getWalletCountOverTime(campaign: {
875
893
  id: string;
876
894
  opportunityId: string;
@@ -7,7 +7,7 @@ import { MAX_COMPUTE_JOB_TIME } from "@sdk";
7
7
  import moment from "moment";
8
8
  export class CampaignRepository {
9
9
  static transformQueryToPrismaFilters(query) {
10
- const { creatorTag, creatorId, creatorAddress, chainId, distributionChainIds, endTimestamp, opportunityId, mainParameter, campaignId, startTimestamp, status, subType, type, types, tokenAddress, tokenSymbol, test, createdAfter, point, rootCampaignId, parentCampaignId, } = query;
10
+ const { id, creatorTag, creatorId, creatorAddress, chainId, distributionChainIds, endTimestamp, opportunityId, mainParameter, campaignId, startTimestamp, status, subType, type, types, tokenAddress, tokenSymbol, test, createdAfter, point, rootCampaignId, parentCampaignId, } = query;
11
11
  const getTagFilter = () => {
12
12
  if (creatorTag && creatorId)
13
13
  return {
@@ -38,6 +38,7 @@ export class CampaignRepository {
38
38
  };
39
39
  return {
40
40
  where: {
41
+ OR: id ? id.split(",").map(id => ({ id: id })) : undefined,
41
42
  distributionChainId: !!distributionChainIds
42
43
  ? {
43
44
  in: distributionChainIds,
@@ -495,6 +496,19 @@ export class CampaignRepository {
495
496
  select: { timestamp: true, total: true },
496
497
  });
497
498
  }
499
+ static async getWalletCount(campaign) {
500
+ const rewardBreakdowns = await apiDbClient.rewardBreakdown.findMany({
501
+ where: {
502
+ campaignId: campaign.id,
503
+ Reward: { MerklRoot: { timestamp: { gte: campaign.startTimestamp, lte: campaign.endTimestamp } } },
504
+ },
505
+ select: { Reward: { select: { recipient: true, MerklRoot: { select: { timestamp: true } } } } },
506
+ });
507
+ const walletCount = new Set();
508
+ for (const { Reward } of rewardBreakdowns)
509
+ walletCount.add(Reward.recipient);
510
+ return walletCount.size;
511
+ }
498
512
  static async getWalletCountOverTime(campaign) {
499
513
  const rewardBreakdowns = await apiDbClient.rewardBreakdown.findMany({
500
514
  where: {
@@ -963,6 +963,7 @@ export declare abstract class CampaignService {
963
963
  endTimestamp: any;
964
964
  params: string;
965
965
  };
966
+ static getWalletCount(campaignId: CampaignUnique | string): Promise<number>;
966
967
  static getMetrics(campaignId: CampaignUnique | string): Promise<{
967
968
  tvlRecords: {
968
969
  total: number;
@@ -980,6 +981,6 @@ export declare abstract class CampaignService {
980
981
  timestamp: bigint;
981
982
  walletCount: number;
982
983
  }[];
983
- tvlInflowPerDollar: bigint;
984
+ tvlInflowPerDollar: number;
984
985
  }>;
985
986
  }
@@ -387,6 +387,11 @@ export class CampaignService {
387
387
  params: JSON.stringify(fakeCampaign.campaignParameters),
388
388
  };
389
389
  }
390
+ static async getWalletCount(campaignId) {
391
+ const id = typeof campaignId === "string" ? campaignId : CampaignService.hashId(campaignId);
392
+ const campaign = await CampaignRepository.findUniqueOrThrow(id, false);
393
+ return await CampaignRepository.getWalletCount(campaign);
394
+ }
390
395
  static async getMetrics(campaignId) {
391
396
  const id = typeof campaignId === "string" ? campaignId : CampaignService.hashId(campaignId);
392
397
  const campaign = await CampaignRepository.findUniqueOrThrow(id, false);
@@ -396,16 +401,16 @@ export class CampaignService {
396
401
  CampaignRepository.getDailyRewardsRecords(campaign),
397
402
  CampaignRepository.getWalletCountOverTime(campaign),
398
403
  ]);
404
+ console.log("tvlRecords", tvlRecords);
399
405
  return {
400
406
  tvlRecords,
401
407
  aprRecords,
402
408
  dailyRewardsRecords,
403
409
  walletCount,
404
410
  tvlInflowPerDollar: tvlRecords.length > 1
405
- ? (BigInt(tvlRecords[tvlRecords.length - 1].total) - BigInt(tvlRecords[0].total)) /
406
- ((BigInt(campaign.amount) / BigInt(10 ** campaign.RewardToken.decimals)) *
407
- BigInt(campaign.RewardToken.price ?? 1))
408
- : 0n,
411
+ ? (tvlRecords[tvlRecords.length - 1].total - tvlRecords[0].total) /
412
+ ((Number(campaign.amount) / 10 ** campaign.RewardToken.decimals) * (campaign.RewardToken.price ?? 1))
413
+ : 0,
409
414
  };
410
415
  }
411
416
  }
@@ -157,7 +157,8 @@ export declare const CreatorController: Elysia<"/creators", false, {
157
157
  pastCampaigns: number;
158
158
  liveCampaigns: number;
159
159
  futureCampaigns: number;
160
- incentivizedTvl: number;
160
+ totalTvl: number;
161
+ totalWallets: number;
161
162
  totalCampaigns: number;
162
163
  creatorId: string | null;
163
164
  };
@@ -334,7 +335,7 @@ export declare const CreatorController: Elysia<"/creators", false, {
334
335
  timestamp: bigint;
335
336
  walletCount: number;
336
337
  }[];
337
- tvlInflowPerDollar: bigint;
338
+ tvlInflowPerDollar: number;
338
339
  };
339
340
  };
340
341
  };
@@ -66,7 +66,8 @@ export declare abstract class CreatorService {
66
66
  pastCampaigns: number;
67
67
  liveCampaigns: number;
68
68
  futureCampaigns: number;
69
- incentivizedTvl: number;
69
+ totalTvl: number;
70
+ totalWallets: number;
70
71
  totalCampaigns: number;
71
72
  creatorId: string | null;
72
73
  }>;
@@ -207,7 +208,7 @@ export declare abstract class CreatorService {
207
208
  timestamp: bigint;
208
209
  walletCount: number;
209
210
  }[];
210
- tvlInflowPerDollar: bigint;
211
+ tvlInflowPerDollar: number;
211
212
  }>;
212
213
  static updateRebate(id: Creator["model"]["id"], rebate: UpdateCreatorRebateDto["rebate"]): Promise<{
213
214
  name: string;
@@ -54,12 +54,19 @@ export class CreatorService {
54
54
  CampaignService.getFutureCampaigns({ creatorAddress }),
55
55
  CreatorService.getCreatorIdFromAddress(creatorAddress),
56
56
  ]);
57
- const incentivizedTvl = liveCampaigns.reduce((acc, campaign) => acc + campaign.Opportunity.tvl, 0);
57
+ const totalTvl = liveCampaigns.reduce((acc, campaign) => acc + campaign.Opportunity.tvl, 0);
58
+ // let totalWallets = 0;
59
+ const promises = [];
60
+ for (const campaign of liveCampaigns)
61
+ promises.push(CampaignService.getWalletCount(campaign.id));
62
+ const results = await Promise.all(promises);
63
+ const totalWallets = results.reduce((acc, walletCount) => acc + walletCount, 0);
58
64
  return {
59
65
  pastCampaigns: pastCampaigns.length,
60
66
  liveCampaigns: liveCampaigns.length,
61
67
  futureCampaigns: futureCampaigns.length,
62
- incentivizedTvl,
68
+ totalTvl,
69
+ totalWallets,
63
70
  totalCampaigns: pastCampaigns.length + liveCampaigns.length + futureCampaigns.length,
64
71
  creatorId,
65
72
  };
@@ -145,16 +145,8 @@ export class DynamicDataService {
145
145
  else {
146
146
  aprCampaignValue = (campaignDailyValue * 365 * 100) / record.tvl;
147
147
  }
148
- let lastEligibilityRatio = 1;
149
- if (!!campaignParameters.hooks?.length) {
150
- lastEligibilityRatio =
151
- (await ComputedValueService.findCampaignValue(Bun.hash(`${record.campaign.chainId}${record.campaign.campaignId}`).toString(), "averageBoost"))?.averageBoost ?? 1;
152
- }
153
- const forfeitingBoost = 1;
154
- if (!!campaignParameters.hooks?.length) {
155
- lastEligibilityRatio =
156
- (await ComputedValueService.findCampaignValue(Bun.hash(`${record.campaign.chainId}${record.campaign.campaignId}`).toString(), "forfeitingBoost"))?.forfeitingBoost ?? 1;
157
- }
148
+ const lastEligibilityRatio = (await ComputedValueService.findCampaignValue(Bun.hash(`${record.campaign.chainId}${record.campaign.campaignId}`).toString(), "averageBoost"))?.averageBoost ?? 1;
149
+ const forfeitingBoost = (await ComputedValueService.findCampaignValue(Bun.hash(`${record.campaign.chainId}${record.campaign.campaignId}`).toString(), "forfeitingBoost"))?.forfeitingBoost ?? 1;
158
150
  aprCampaignValue = aprCampaignValue * lastEligibilityRatio * forfeitingBoost;
159
151
  if (aprCampaignValue === Number.POSITIVE_INFINITY)
160
152
  aprCampaignValue = 10_001;