@merkl/api 0.17.4 → 0.17.5
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/jobs/etl/update-dynamic-data.js +12 -0
- package/dist/src/modules/v4/opportunity/opportunity.converter.d.ts +1 -1
- package/dist/src/modules/v4/opportunity/opportunity.converter.js +7 -7
- package/dist/src/modules/v4/token/token.repository.js +3 -1
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -15,6 +15,18 @@ if (!chainId)
|
|
15
15
|
// ─── Update Dynamic Data (APR / TVL / Daily Rewards) ─────────────────────────
|
16
16
|
async function updateDynamicData(liveCampaigns, campaignType) {
|
17
17
|
try {
|
18
|
+
// Input: list of campaigns of same type
|
19
|
+
// Output: for each campaign, APR, TVL, Daily Rewards
|
20
|
+
// Constraint: needs to use multicalls to reduce RPC calls and speed
|
21
|
+
// - Needs to be robust to a single campaign's call failing
|
22
|
+
// - Needs to be quite easy for the engine team to setup new campaign types
|
23
|
+
// abstract GenericDynamicDataComputer
|
24
|
+
// compute(chainId, type, campaigns) => { apr, tvl, dailyRewards } with breakdowns
|
25
|
+
// UNISWAP V4
|
26
|
+
// Round 1 - (chainId, type, campaigns) -> tokens of the pools
|
27
|
+
// Round 2 - (chainId, type, campaigns, output of previous round) -> balance in tokens of forwarders
|
28
|
+
// Round 3 - ...
|
29
|
+
// Round Final - (chainId, type, campaigns, output of previous round) -> { apr, tvl, dailyRewards }
|
18
30
|
const dynamicData = await executeSimple(chainId, campaignsDynamicData(chainId, liveCampaigns, campaignType));
|
19
31
|
const oppMap = {};
|
20
32
|
for (const data of dynamicData) {
|
@@ -2,7 +2,7 @@ import { type CampaignParameters, type Opportunity as OpportunityV3, type ValidC
|
|
2
2
|
import { OpportunityService } from "./opportunity.service";
|
3
3
|
export declare abstract class OpportunityConvertorService {
|
4
4
|
#private;
|
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>;
|
5
|
+
static convertV4CampaignToV3<C extends ValidCampaign>(campaignType: C, campaign: Exclude<Awaited<ReturnType<(typeof OpportunityService)["findMany"]>>[number]["campaigns"], undefined>[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
8
|
static logKeyAndTTLV3Opportunities(showCampaigns: boolean, test: boolean | undefined, identifier: string | undefined, chainId: string | undefined): Promise<void>;
|
@@ -108,23 +108,23 @@ export class OpportunityConvertorService {
|
|
108
108
|
: undefined,
|
109
109
|
tags: opportunity.tags,
|
110
110
|
rewardTokenIcons: opportunity.campaigns
|
111
|
-
|
111
|
+
?.map(campaign => campaign.rewardToken.symbol)
|
112
112
|
.reduce((acc, curr) => {
|
113
113
|
if (!acc.includes(curr))
|
114
114
|
acc.push(curr);
|
115
115
|
return acc;
|
116
|
-
}, []),
|
116
|
+
}, []) ?? [],
|
117
117
|
campaigns: {
|
118
118
|
type: CampaignEnum[opportunity.type],
|
119
|
-
ids: opportunity.campaigns
|
119
|
+
ids: opportunity.campaigns?.map(campaign => campaign.campaignId) ?? [],
|
120
120
|
active: withCampaigns
|
121
121
|
? opportunity.campaigns
|
122
|
-
|
122
|
+
?.filter(campaign => campaign.startTimestamp < BigInt(now) && BigInt(now) < campaign.endTimestamp)
|
123
123
|
.map(campaign => OpportunityConvertorService.convertV4CampaignToV3(CampaignEnum[campaign.type], campaign, opportunity))
|
124
124
|
: undefined,
|
125
125
|
inactive: withCampaigns
|
126
126
|
? opportunity.campaigns
|
127
|
-
|
127
|
+
?.filter(campaign => !(campaign.startTimestamp < BigInt(now) && BigInt(now) < campaign.endTimestamp))
|
128
128
|
.map(campaign => OpportunityConvertorService.convertV4CampaignToV3(CampaignEnum[campaign.type], campaign, opportunity))
|
129
129
|
: undefined,
|
130
130
|
},
|
@@ -160,13 +160,13 @@ export class OpportunityConvertorService {
|
|
160
160
|
return res;
|
161
161
|
}
|
162
162
|
static async setV3Opportunities(showCampaigns, test, identifier, chainId) {
|
163
|
-
return await CacheService.set(TTLPresets.
|
163
|
+
return await CacheService.set(TTLPresets.MIN_30, OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
164
164
|
}
|
165
165
|
static async logKeyAndTTLV3Opportunities(showCampaigns, test, identifier, chainId) {
|
166
166
|
const [key, ttl] = await CacheService.keyAndTTL(OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
167
167
|
log.info(`Args: ${showCampaigns}, ${test}, ${identifier}, ${chainId}, Key: ${key}, TTL: ${ttl}`);
|
168
168
|
}
|
169
169
|
static async wrapV3Opportunities(showCampaigns, test, identifier, chainId) {
|
170
|
-
return await CacheService.wrap(TTLPresets.
|
170
|
+
return await CacheService.wrap(TTLPresets.MIN_5, OpportunityConvertorService.#extractV3Opportunities, showCampaigns, test, identifier, chainId);
|
171
171
|
}
|
172
172
|
}
|
@@ -50,7 +50,9 @@ export class TokenRepository {
|
|
50
50
|
{ displaySymbol: { equals: query.displaySymbol, mode: "insensitive" } },
|
51
51
|
...ids,
|
52
52
|
]
|
53
|
-
:
|
53
|
+
: ids.length
|
54
|
+
? [...ids]
|
55
|
+
: undefined,
|
54
56
|
address: query.address ? { equals: query.address, mode: "insensitive" } : undefined,
|
55
57
|
chainId: query.chainId ? { equals: query.chainId } : undefined,
|
56
58
|
name: query.name ? { contains: query.name, mode: "insensitive" } : undefined,
|