@merkl/api 0.16.36 → 0.16.38
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/backgroundJobs/jobs/opportunityUpdater.js +2 -0
- package/dist/src/modules/v4/cache/cache.service.d.ts +1 -0
- package/dist/src/modules/v4/cache/cache.service.js +4 -0
- package/dist/src/modules/v4/opportunity/opportunity.converter.d.ts +1 -0
- package/dist/src/modules/v4/opportunity/opportunity.converter.js +26 -7
- package/dist/src/routes/v3/opportunity.js +3 -1
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -54,7 +54,9 @@ export const opportunityUpdater = (app) => {
|
|
54
54
|
await Redis.safeSet("OpportunitiesWithTest", opportunitiesWithTest);
|
55
55
|
log.info("✅ opportunity cache updated successfully");
|
56
56
|
await OpportunityConvertorService.setV3Opportunities(true, false, undefined, undefined);
|
57
|
+
log.info("✅ opportunity v3 cache updated successfully");
|
57
58
|
await OpportunityConvertorService.setV3Opportunities(true, true, undefined, undefined);
|
59
|
+
log.info("✅ opportunity v3 test cache updated successfully");
|
58
60
|
return new Response(JSON.stringify({
|
59
61
|
status: "success",
|
60
62
|
all: getUpdateBreakdown(opportunities),
|
@@ -3,6 +3,7 @@ export declare abstract class CacheService {
|
|
3
3
|
private static encoder;
|
4
4
|
private static decoder;
|
5
5
|
static wrap<Fn extends (...args: Args) => Promise<unknown>, Args extends unknown[], T extends Awaited<ReturnType<Fn>>>(ttl: number, fn: Fn, ...args: Args): Promise<T>;
|
6
|
+
static keyAndTTL<Fn extends (...args: Args) => Promise<unknown>, Args extends unknown[], T extends Awaited<ReturnType<Fn>>>(fn: Fn, ...args: Args): Promise<[string, number]>;
|
6
7
|
static set<Fn extends (...args: Args) => Promise<unknown>, Args extends unknown[], T extends Awaited<ReturnType<Fn>>>(ttl: number, fn: Fn, ...args: Args): Promise<T>;
|
7
8
|
static get<Fn extends (...args: Args) => Promise<unknown>, Args extends unknown[], T extends Awaited<ReturnType<Fn>>>(fn: Fn, args: Args): Promise<T | null>;
|
8
9
|
}
|
@@ -29,6 +29,10 @@ export class CacheService {
|
|
29
29
|
await CacheRepository.set(ttl, key, compressed);
|
30
30
|
return result;
|
31
31
|
}
|
32
|
+
static async keyAndTTL(fn, ...args) {
|
33
|
+
const key = CacheService.#hashKey(fn, args);
|
34
|
+
return [key, await CacheRepository.ttl(key)];
|
35
|
+
}
|
32
36
|
static async set(ttl, fn, ...args) {
|
33
37
|
const key = CacheService.#hashKey(fn, args);
|
34
38
|
const result = await fn(...args);
|
@@ -5,5 +5,6 @@ export declare abstract class OpportunityConvertorService {
|
|
5
5
|
static convertV4CampaignToV3<C extends ValidCampaign>(campaignType: C, campaign: Awaited<ReturnType<(typeof OpportunityService)["findMany"]>>[number]["campaigns"][number], opportunity: Awaited<ReturnType<(typeof OpportunityService)["findMany"]>>[number]): CampaignParameters<C>;
|
6
6
|
static convertV4toV3(opportunity: Awaited<ReturnType<(typeof OpportunityService)["findMany"]>>[number], withCampaigns?: boolean): OpportunityV3;
|
7
7
|
static setV3Opportunities(showCampaigns: boolean, test: boolean | undefined, identifier: string | undefined, chainId: string | undefined): Promise<{}>;
|
8
|
+
static logKeyAndTTLV3Opportunities(showCampaigns: boolean, test: boolean | undefined, identifier: string | undefined, chainId: string | undefined): Promise<void>;
|
8
9
|
static wrapV3Opportunities(showCampaigns: boolean, test: boolean | undefined, identifier: string | undefined, chainId: string | undefined): Promise<{}>;
|
9
10
|
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { kebabToPascalCase } from "../../../utils/camelToKebabCase";
|
2
|
+
import { log } from "../../../utils/logger";
|
2
3
|
import { Campaign as CampaignEnum, EAprBreakdownType, opportunityActions, } from "@sdk";
|
3
4
|
import moment from "moment";
|
4
5
|
import { CacheService } from "../cache";
|
@@ -130,13 +131,27 @@ export class OpportunityConvertorService {
|
|
130
131
|
};
|
131
132
|
}
|
132
133
|
static async #extractV3Opportunities(showCampaigns, test, identifier, chainId) {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
134
|
+
let opportunities = [];
|
135
|
+
let page = 0;
|
136
|
+
while (true) {
|
137
|
+
try {
|
138
|
+
const opportunitiesPage = await OpportunityService.findMany({
|
139
|
+
items: 100, // HARDCODED LIMIT
|
140
|
+
page,
|
141
|
+
test,
|
142
|
+
identifier,
|
143
|
+
chainId,
|
144
|
+
campaigns: true,
|
145
|
+
});
|
146
|
+
opportunities = opportunities.concat(opportunitiesPage);
|
147
|
+
if (opportunitiesPage.length === 0)
|
148
|
+
break;
|
149
|
+
}
|
150
|
+
catch {
|
151
|
+
break;
|
152
|
+
}
|
153
|
+
page++;
|
154
|
+
}
|
140
155
|
const res = {};
|
141
156
|
for (const opportunity of opportunities) {
|
142
157
|
const opportunityV3 = OpportunityConvertorService.convertV4toV3(opportunity, showCampaigns);
|
@@ -147,6 +162,10 @@ export class OpportunityConvertorService {
|
|
147
162
|
static async setV3Opportunities(showCampaigns, test, identifier, chainId) {
|
148
163
|
return await CacheService.set(TTLPresets.MIN_5, OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
149
164
|
}
|
165
|
+
static async logKeyAndTTLV3Opportunities(showCampaigns, test, identifier, chainId) {
|
166
|
+
const [key, ttl] = await CacheService.keyAndTTL(OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
167
|
+
log.info(`Key: ${key}, TTL: ${ttl}`);
|
168
|
+
}
|
150
169
|
static async wrapV3Opportunities(showCampaigns, test, identifier, chainId) {
|
151
170
|
return await CacheService.wrap(TTLPresets.MIN_30, OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
152
171
|
}
|
@@ -27,6 +27,7 @@ export const response = t.Record(t.TemplateLiteral([param.Type.type, t.Literal("
|
|
27
27
|
export default (app) => {
|
28
28
|
return app.get("/opportunity", async ({ query: { campaigns: showCampaigns, ...filters } }) => {
|
29
29
|
if (process.env.FF_OPPORTUNITY === "true" || !!filters.testTokens) {
|
30
|
+
await OpportunityConvertorService.logKeyAndTTLV3Opportunities(showCampaigns ?? false, !!filters.testTokens ? filters.testTokens : undefined, !!filters.mainParameter ? filters.mainParameter : undefined, !!filters.chainId ? filters.chainId.toString() : undefined);
|
30
31
|
return await OpportunityConvertorService.wrapV3Opportunities(showCampaigns ?? false, !!filters.testTokens ? filters.testTokens : undefined, !!filters.mainParameter ? filters.mainParameter : undefined, !!filters.chainId ? filters.chainId.toString() : undefined);
|
31
32
|
}
|
32
33
|
const opportunities = await Redis.get(filters?.testTokens ? "OpportunitiesWithTest" : "Opportunities");
|
@@ -57,7 +58,8 @@ export default (app) => {
|
|
57
58
|
transform({ query }) {
|
58
59
|
query.chainId = !query.chainId ? undefined : Number.parseInt(query.chainId.toString());
|
59
60
|
query.type = !query.type ? undefined : Number.parseInt(query.type.toString());
|
60
|
-
query.campaigns =
|
61
|
+
query.campaigns =
|
62
|
+
query.campaigns === false || query.testTokens?.toString() === "false" ? false : !!query.campaigns;
|
61
63
|
query.testTokens =
|
62
64
|
query.testTokens === false || query.testTokens?.toString() === "false" ? false : !!query.testTokens;
|
63
65
|
},
|