@merkl/api 0.16.37 → 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/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 +5 -1
- package/dist/src/routes/v3/opportunity.js +3 -1
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -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";
|
@@ -142,7 +143,6 @@ export class OpportunityConvertorService {
|
|
142
143
|
chainId,
|
143
144
|
campaigns: true,
|
144
145
|
});
|
145
|
-
console.log(page, opportunitiesPage.length);
|
146
146
|
opportunities = opportunities.concat(opportunitiesPage);
|
147
147
|
if (opportunitiesPage.length === 0)
|
148
148
|
break;
|
@@ -162,6 +162,10 @@ export class OpportunityConvertorService {
|
|
162
162
|
static async setV3Opportunities(showCampaigns, test, identifier, chainId) {
|
163
163
|
return await CacheService.set(TTLPresets.MIN_5, OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
164
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
|
+
}
|
165
169
|
static async wrapV3Opportunities(showCampaigns, test, identifier, chainId) {
|
166
170
|
return await CacheService.wrap(TTLPresets.MIN_30, OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
167
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
|
},
|