@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.
package/dist/src/eden/index.d.ts
CHANGED
@@ -7088,9 +7088,8 @@ declare const eden: {
|
|
7088
7088
|
};
|
7089
7089
|
fetch?: RequestInit | undefined;
|
7090
7090
|
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
7091
|
-
|
7092
|
-
|
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
|
-
|
12035
|
-
|
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
|
-
|
19802
|
-
|
19803
|
-
};
|
19799
|
+
[x: string]: any;
|
19800
|
+
200: any;
|
19804
19801
|
}>>;
|
19805
19802
|
};
|
19806
19803
|
campaignsForMainParameter: {
|
package/dist/src/index.d.ts
CHANGED
@@ -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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
132
|
+
return dynamicData;
|
95
133
|
}, {
|
96
134
|
query,
|
97
135
|
tags: ["Campaigns"],
|