@merkl/api 0.18.12 → 0.18.13

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.
@@ -7088,9 +7088,8 @@ declare const eden: {
7088
7088
  };
7089
7089
  fetch?: RequestInit | undefined;
7090
7090
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
7091
- 200: {
7092
- [x: string]: Record<string, any>;
7093
- };
7091
+ [x: string]: any;
7092
+ 200: any;
7094
7093
  }>>;
7095
7094
  };
7096
7095
  campaignsForMainParameter: {
@@ -12031,9 +12030,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
12031
12030
  };
12032
12031
  headers: unknown;
12033
12032
  response: {
12034
- 200: {
12035
- [x: string]: Record<string, any>;
12036
- };
12033
+ [x: string]: any;
12034
+ 200: any;
12037
12035
  };
12038
12036
  };
12039
12037
  };
@@ -19798,9 +19796,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
19798
19796
  };
19799
19797
  fetch?: RequestInit | undefined;
19800
19798
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
19801
- 200: {
19802
- [x: string]: Record<string, any>;
19803
- };
19799
+ [x: string]: any;
19800
+ 200: any;
19804
19801
  }>>;
19805
19802
  };
19806
19803
  campaignsForMainParameter: {
@@ -4416,9 +4416,8 @@ declare const app: Elysia<"", false, {
4416
4416
  };
4417
4417
  headers: unknown;
4418
4418
  response: {
4419
- 200: {
4420
- [x: string]: Record<string, any>;
4421
- };
4419
+ [x: string]: any;
4420
+ 200: any;
4422
4421
  };
4423
4422
  };
4424
4423
  };
@@ -41,9 +41,8 @@ declare const _default: (app: Elysia) => Elysia<"", false, {
41
41
  };
42
42
  headers: unknown;
43
43
  response: {
44
- 200: {
45
- [x: string]: Record<string, any>;
46
- };
44
+ [x: string]: any;
45
+ 200: any;
47
46
  };
48
47
  };
49
48
  };
@@ -1,3 +1,5 @@
1
+ import { Redis } from "@/cache";
2
+ import { removeTestTokens } from "@/entities/campaign";
1
3
  import { CampaignService } from "@/modules/v4/campaign";
2
4
  import { OpportunityConvertorService } from "@/modules/v4/opportunity/opportunity.converter";
3
5
  import { ANGLE_NETWORKS, Campaign as CampaignEnum, ChainId, isSupportedChain, registry, } from "@sdk";
@@ -68,30 +70,66 @@ export default (app) => app.get("/campaigns", async ({ query }) => {
68
70
  throw new UnsupportedNetwork(chainId);
69
71
  }
70
72
  }
71
- const campaigns = await CampaignService.findMany({
72
- distributionChainIds: chainIds,
73
- types: !types.length ? undefined : types.map(type => CampaignEnum[type]),
74
- status: query.live ? "LIVE" : undefined,
75
- creatorTag: query.creatorTag,
76
- test: !hideTestTokens,
77
- withOpportunity: true,
78
- });
79
- const res = {};
80
- for (const campaign of campaigns) {
81
- if (!res[campaign.distributionChainId]) {
82
- res[campaign.distributionChainId] = {};
73
+ if (process.env.FF_OPPORTUNITY === "true") {
74
+ const campaigns = await CampaignService.findMany({
75
+ distributionChainIds: chainIds,
76
+ types: !types.length ? undefined : types.map(type => CampaignEnum[type]),
77
+ status: query.live ? "LIVE" : undefined,
78
+ creatorTag: query.creatorTag,
79
+ test: !hideTestTokens,
80
+ withOpportunity: true,
81
+ });
82
+ const res = {};
83
+ for (const campaign of campaigns) {
84
+ if (!res[campaign.distributionChainId]) {
85
+ res[campaign.distributionChainId] = {};
86
+ }
87
+ const opportunityIdentifier = campaign.Opportunity.identifier;
88
+ const campaignType = CampaignEnum[campaign.type];
89
+ if (!res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`]) {
90
+ res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`] = {
91
+ ...OpportunityConvertorService.convertV4CampaignToV3(campaignType, campaign, opportunityIdentifier),
92
+ apr: campaign.Opportunity.apr,
93
+ tvl: campaign.Opportunity.tvl,
94
+ };
95
+ }
83
96
  }
84
- const opportunityIdentifier = campaign.Opportunity.identifier;
85
- const campaignType = CampaignEnum[campaign.type];
86
- if (!res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`]) {
87
- res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`] = {
88
- ...OpportunityConvertorService.convertV4CampaignToV3(campaignType, campaign, opportunityIdentifier),
89
- apr: campaign.Opportunity.apr,
90
- tvl: campaign.Opportunity.tvl,
91
- };
97
+ return res;
98
+ }
99
+ const campaignCachePrefix = query.live === true ? "LiveCampaigns" : "Campaigns";
100
+ const dynamicData = (await Redis.getManyWithArgs(campaignCachePrefix, chainIds)).reduce((prev, allData, index) => {
101
+ if (!!allData) {
102
+ prev[chainIds[index]] = Object.keys(allData).reduce((acc, curr) => {
103
+ if ((types.length === 0 || types.includes(Number.parseInt(curr.split("_")[0]))) &&
104
+ (!hideTestTokens || removeTestTokens(allData[curr]))) {
105
+ acc[curr] = allData[curr];
106
+ }
107
+ return acc;
108
+ }, {});
109
+ }
110
+ return prev;
111
+ }, {});
112
+ // Remove everything that doesn't contain the creator tag
113
+ if (!!query.creatorTag) {
114
+ for (const c of Object.keys(dynamicData)) {
115
+ for (const type_mainParam of Object.keys(dynamicData[c])) {
116
+ for (const campaignId of Object.keys(dynamicData[c][type_mainParam])) {
117
+ if (!dynamicData[c][type_mainParam][campaignId]?.tags?.includes(query.creatorTag)) {
118
+ delete dynamicData[c][type_mainParam][campaignId];
119
+ }
120
+ }
121
+ // Delete the type_mainParam if it's empty
122
+ if (Object.keys(dynamicData[c][type_mainParam]).length === 0) {
123
+ delete dynamicData[c][type_mainParam];
124
+ }
125
+ }
126
+ // Delete the c if it's empty
127
+ if (Object.keys(dynamicData[c]).length === 0) {
128
+ delete dynamicData[c];
129
+ }
92
130
  }
93
131
  }
94
- return res;
132
+ return dynamicData;
95
133
  }, {
96
134
  query,
97
135
  tags: ["Campaigns"],
@@ -82,9 +82,8 @@ export declare const v3: Elysia<"/v3", false, {
82
82
  };
83
83
  headers: unknown;
84
84
  response: {
85
- 200: {
86
- [x: string]: Record<string, any>;
87
- };
85
+ [x: string]: any;
86
+ 200: any;
88
87
  };
89
88
  };
90
89
  };