@merkl/api 0.16.43 → 0.16.44

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.
@@ -105,20 +105,11 @@ export const OpportunityController = new Elysia({
105
105
  if (!params.id.includes("-"))
106
106
  return await OpportunityService.getUniqueWithCampaignsOrThrow(params.id, query.test ?? false);
107
107
  const [chainId, type, identifier] = params.id.split("-");
108
- const oppWithCampaigns = await OpportunityService.getUniqueWithCampaignsOrThrow({
108
+ return await OpportunityService.getUniqueWithCampaignsOrThrow({
109
109
  chainId: +chainId,
110
110
  type: type,
111
111
  identifier,
112
112
  }, query.test ?? false);
113
- // Todo: need to be refactor Parsing issue
114
- const campaignsFormatted = oppWithCampaigns.campaigns.map(campaign => {
115
- if (!campaign.distributionChain)
116
- return campaign;
117
- const distributionChain = campaign.distributionChain;
118
- const { Explorer } = distributionChain;
119
- return { ...campaign, distributionChain: { ...campaign.distributionChain, explorers: Explorer } };
120
- });
121
- return { ...oppWithCampaigns, campaigns: campaignsFormatted };
122
113
  }
123
114
  catch (err) {
124
115
  if (err.code && err.code === "P2025")
@@ -1,7 +1,7 @@
1
1
  import { type CreateCampaignModel, type GetCampaignQueryModel } from "../campaign";
2
2
  import { Prisma } from "../../../../database/api/.generated";
3
3
  import { type ChainId, type MerklChainId } from "@sdk";
4
- import type { CreateOpportunityModel, GetOpportunitiesQueryModel, LightOpportunityFromDB, OpportunityResourceModel, OpportunityUnique, OpportunityWithCampaignsResourceModel, UpdateOpportunityModel } from "./opportunity.model";
4
+ import type { CreateOpportunityModel, GetOpportunitiesQueryModel, LightOpportunityFromDB, OpportunityResourceModel, OpportunityUnique, UpdateOpportunityModel } from "./opportunity.model";
5
5
  import { OpportunityRepository } from "./opportunity.repository";
6
6
  export declare abstract class OpportunityService {
7
7
  #private;
@@ -123,40 +123,44 @@ export declare abstract class OpportunityService {
123
123
  * @returns opportunities
124
124
  */
125
125
  static findManyByCampaigns(where: GetCampaignQueryModel): Promise<{
126
- apr: number;
127
- aprRecord: {
126
+ protocol?: {
127
+ name: string;
128
+ url: string;
129
+ description: string;
130
+ id: string;
131
+ tags: string[];
132
+ icon: string;
133
+ } | null | undefined;
134
+ depositUrl?: string | undefined;
135
+ aprRecord?: {
136
+ timestamp: string | bigint;
128
137
  cumulated: number;
129
- timestamp: bigint;
130
138
  breakdowns: {
131
- type: import("../../../../database/api/.generated").$Enums.AprType;
139
+ type: "CAMPAIGN" | "TOKEN" | "PROTOCOL";
132
140
  id: number;
133
141
  identifier: string;
134
142
  value: number;
135
143
  aprRecordId: string;
136
144
  }[];
137
- };
138
- tvlRecord: {
139
- id: string;
145
+ } | undefined;
146
+ tvlRecord?: {
140
147
  total: number;
141
- timestamp: bigint;
148
+ timestamp: string | bigint;
142
149
  breakdowns: {
143
- type: import("../../../../database/api/.generated").$Enums.TvlType;
150
+ type: "TOKEN" | "PROTOCOL";
144
151
  id: number;
145
152
  identifier: string;
146
153
  value: number;
147
154
  tvlRecordId: string;
148
155
  }[];
149
- };
150
- rewardsRecord: {
151
- id: string;
156
+ } | undefined;
157
+ rewardsRecord?: {
152
158
  total: number;
153
- timestamp: bigint;
159
+ id: string;
160
+ timestamp: string | bigint;
154
161
  breakdowns: {
155
- id: number;
156
- value: number;
157
- campaignId: string;
158
- dailyRewardsRecordId: string;
159
162
  token: {
163
+ price?: number | null | undefined;
160
164
  symbol: string;
161
165
  name: string | null;
162
166
  id: string;
@@ -164,17 +168,20 @@ export declare abstract class OpportunityService {
164
168
  chainId: number;
165
169
  address: string;
166
170
  decimals: number;
167
- displaySymbol: string;
168
171
  verified: boolean;
169
172
  isTest: boolean;
170
- price: number | null;
171
173
  };
172
- amount: bigint;
174
+ id: number;
175
+ value: number;
176
+ campaignId: string;
177
+ amount: string | bigint;
178
+ dailyRewardsRecordId: string;
173
179
  }[];
174
- };
175
- id: string;
176
- depositUrl: string | undefined;
177
- tokens: ({
180
+ } | undefined;
181
+ name: string;
182
+ type: string;
183
+ tokens: {
184
+ price?: number | null | undefined;
178
185
  symbol: string;
179
186
  name: string | null;
180
187
  id: string;
@@ -184,33 +191,197 @@ export declare abstract class OpportunityService {
184
191
  decimals: number;
185
192
  verified: boolean;
186
193
  isTest: boolean;
187
- } & {
188
- price?: number | null | undefined;
189
- })[];
194
+ }[];
195
+ id: string;
196
+ status: string;
197
+ tags: string[];
198
+ identifier: string;
190
199
  chain: {
191
200
  name: string;
192
201
  id: number;
193
202
  icon: string;
194
203
  };
195
- protocol: {
204
+ chainId: number;
205
+ action: string;
206
+ tvl: number;
207
+ apr: number;
208
+ dailyRewards: number;
209
+ campaigns: {
210
+ campaignStatus?: {
211
+ error?: string | undefined;
212
+ details?: any;
213
+ status: string;
214
+ campaignId: string;
215
+ computedUntil: string | bigint;
216
+ processingStarted: string | bigint;
217
+ } | undefined;
218
+ distributionChain?: {
219
+ name: string;
220
+ id: number;
221
+ icon: string;
222
+ } | undefined;
223
+ type: string;
224
+ id: string;
225
+ params: any;
226
+ subType: number | null;
227
+ chain: {
228
+ name: string;
229
+ id: number;
230
+ icon: string;
231
+ };
232
+ startTimestamp: string | bigint;
233
+ endTimestamp: string | bigint;
234
+ computeChainId: number;
235
+ distributionChainId: number;
236
+ campaignId: string;
237
+ rewardTokenId: string;
238
+ amount: string;
239
+ opportunityId: string;
240
+ creatorAddress: string;
241
+ rewardToken: {
242
+ price?: number | null | undefined;
243
+ symbol: string;
244
+ name: string | null;
245
+ id: string;
246
+ icon: string;
247
+ chainId: number;
248
+ address: string;
249
+ decimals: number;
250
+ verified: boolean;
251
+ isTest: boolean;
252
+ };
253
+ }[];
254
+ }[]>;
255
+ static getUniqueWithCampaignsOrThrow(opportunityId: string | OpportunityUnique, withTest?: boolean): Promise<{
256
+ protocol?: {
196
257
  name: string;
197
258
  url: string;
198
259
  description: string;
199
260
  id: string;
200
261
  tags: string[];
201
262
  icon: string;
263
+ } | null | undefined;
264
+ depositUrl?: string | undefined;
265
+ aprRecord?: {
266
+ timestamp: string | bigint;
267
+ cumulated: number;
268
+ breakdowns: {
269
+ type: "CAMPAIGN" | "TOKEN" | "PROTOCOL";
270
+ id: number;
271
+ identifier: string;
272
+ value: number;
273
+ aprRecordId: string;
274
+ }[];
275
+ } | undefined;
276
+ tvlRecord?: {
277
+ total: number;
278
+ timestamp: string | bigint;
279
+ breakdowns: {
280
+ type: "TOKEN" | "PROTOCOL";
281
+ id: number;
282
+ identifier: string;
283
+ value: number;
284
+ tvlRecordId: string;
285
+ }[];
286
+ } | undefined;
287
+ rewardsRecord?: {
288
+ total: number;
289
+ id: string;
290
+ timestamp: string | bigint;
291
+ breakdowns: {
292
+ token: {
293
+ price?: number | null | undefined;
294
+ symbol: string;
295
+ name: string | null;
296
+ id: string;
297
+ icon: string;
298
+ chainId: number;
299
+ address: string;
300
+ decimals: number;
301
+ verified: boolean;
302
+ isTest: boolean;
303
+ };
304
+ id: number;
305
+ value: number;
306
+ campaignId: string;
307
+ amount: string | bigint;
308
+ dailyRewardsRecordId: string;
309
+ }[];
202
310
  } | undefined;
203
311
  name: string;
204
312
  type: string;
205
- status: import("../../../../database/api/.generated").$Enums.Status;
313
+ tokens: {
314
+ price?: number | null | undefined;
315
+ symbol: string;
316
+ name: string | null;
317
+ id: string;
318
+ icon: string;
319
+ chainId: number;
320
+ address: string;
321
+ decimals: number;
322
+ verified: boolean;
323
+ isTest: boolean;
324
+ }[];
325
+ id: string;
326
+ status: string;
206
327
  tags: string[];
207
328
  identifier: string;
329
+ chain: {
330
+ name: string;
331
+ id: number;
332
+ icon: string;
333
+ };
208
334
  chainId: number;
209
- action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
335
+ action: string;
210
336
  tvl: number;
337
+ apr: number;
211
338
  dailyRewards: number;
212
- }[]>;
213
- static getUniqueWithCampaignsOrThrow(opportunityId: string | OpportunityUnique, withTest?: boolean): Promise<OpportunityWithCampaignsResourceModel>;
339
+ campaigns: {
340
+ campaignStatus?: {
341
+ error?: string | undefined;
342
+ details?: any;
343
+ status: string;
344
+ campaignId: string;
345
+ computedUntil: string | bigint;
346
+ processingStarted: string | bigint;
347
+ } | undefined;
348
+ distributionChain?: {
349
+ name: string;
350
+ id: number;
351
+ icon: string;
352
+ } | undefined;
353
+ type: string;
354
+ id: string;
355
+ params: any;
356
+ subType: number | null;
357
+ chain: {
358
+ name: string;
359
+ id: number;
360
+ icon: string;
361
+ };
362
+ startTimestamp: string | bigint;
363
+ endTimestamp: string | bigint;
364
+ computeChainId: number;
365
+ distributionChainId: number;
366
+ campaignId: string;
367
+ rewardTokenId: string;
368
+ amount: string;
369
+ opportunityId: string;
370
+ creatorAddress: string;
371
+ rewardToken: {
372
+ price?: number | null | undefined;
373
+ symbol: string;
374
+ name: string | null;
375
+ id: string;
376
+ icon: string;
377
+ chainId: number;
378
+ address: string;
379
+ decimals: number;
380
+ verified: boolean;
381
+ isTest: boolean;
382
+ };
383
+ }[];
384
+ }>;
214
385
  static getUniqueOrThrow(opportunityId: string | OpportunityUnique, withTest?: boolean): Promise<OpportunityResourceModel>;
215
386
  /**
216
387
  * Get the list of opportunities satisfying the query
@@ -267,6 +438,57 @@ export declare abstract class OpportunityService {
267
438
  amount: bigint;
268
439
  }[];
269
440
  };
441
+ campaigns: {
442
+ params: any;
443
+ chain: {
444
+ name: string;
445
+ id: number;
446
+ icon: string;
447
+ };
448
+ rewardToken: {
449
+ symbol: string;
450
+ name: string | null;
451
+ id: string;
452
+ icon: string;
453
+ chainId: number;
454
+ address: string;
455
+ decimals: number;
456
+ verified: boolean;
457
+ isTest: boolean;
458
+ } & {
459
+ price?: number | null | undefined;
460
+ };
461
+ distributionChain: {
462
+ name: string;
463
+ id: number;
464
+ icon: string;
465
+ } | undefined;
466
+ campaignStatus: {
467
+ error: string;
468
+ details: Prisma.JsonValue;
469
+ status: import("../../../../database/api/.generated").$Enums.RunStatus;
470
+ campaignId: string;
471
+ computedUntil: bigint;
472
+ processingStarted: bigint;
473
+ };
474
+ creatorAddress: string;
475
+ Creator: {
476
+ tags: string[];
477
+ address: string;
478
+ creatorId: string | null;
479
+ };
480
+ type: string;
481
+ id: string;
482
+ subType: number | null;
483
+ startTimestamp: bigint;
484
+ endTimestamp: bigint;
485
+ computeChainId: number;
486
+ distributionChainId: number;
487
+ campaignId: string;
488
+ rewardTokenId: string;
489
+ amount: string;
490
+ opportunityId: string;
491
+ }[] | undefined;
270
492
  id: string;
271
493
  depositUrl: string | undefined;
272
494
  tokens: ({
@@ -312,7 +534,7 @@ export declare abstract class OpportunityService {
312
534
  * @returns the number of opportunities
313
535
  */
314
536
  static countMany(query: GetOpportunitiesQueryModel): Promise<number>;
315
- static findLiveWithFirstCampaign(chainId: MerklChainId): Promise<({
537
+ static findLiveWithFirstCampaign(chainId: MerklChainId): Promise<{
316
538
  apr: number;
317
539
  aprRecord: {
318
540
  cumulated: number;
@@ -362,44 +584,6 @@ export declare abstract class OpportunityService {
362
584
  amount: bigint;
363
585
  }[];
364
586
  };
365
- id: string;
366
- depositUrl: string | undefined;
367
- tokens: ({
368
- symbol: string;
369
- name: string | null;
370
- id: string;
371
- icon: string;
372
- chainId: number;
373
- address: string;
374
- decimals: number;
375
- verified: boolean;
376
- isTest: boolean;
377
- } & {
378
- price?: number | null | undefined;
379
- })[];
380
- chain: {
381
- name: string;
382
- id: number;
383
- icon: string;
384
- };
385
- protocol: {
386
- name: string;
387
- url: string;
388
- description: string;
389
- id: string;
390
- tags: string[];
391
- icon: string;
392
- } | undefined;
393
- name: string;
394
- type: string;
395
- status: import("../../../../database/api/.generated").$Enums.Status;
396
- tags: string[];
397
- identifier: string;
398
- chainId: number;
399
- action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
400
- tvl: number;
401
- dailyRewards: number;
402
- } & {
403
587
  campaigns: {
404
588
  params: any;
405
589
  chain: {
@@ -450,8 +634,45 @@ export declare abstract class OpportunityService {
450
634
  rewardTokenId: string;
451
635
  amount: string;
452
636
  opportunityId: string;
453
- }[];
454
- })[]>;
637
+ }[] | undefined;
638
+ id: string;
639
+ depositUrl: string | undefined;
640
+ tokens: ({
641
+ symbol: string;
642
+ name: string | null;
643
+ id: string;
644
+ icon: string;
645
+ chainId: number;
646
+ address: string;
647
+ decimals: number;
648
+ verified: boolean;
649
+ isTest: boolean;
650
+ } & {
651
+ price?: number | null | undefined;
652
+ })[];
653
+ chain: {
654
+ name: string;
655
+ id: number;
656
+ icon: string;
657
+ };
658
+ protocol: {
659
+ name: string;
660
+ url: string;
661
+ description: string;
662
+ id: string;
663
+ tags: string[];
664
+ icon: string;
665
+ } | undefined;
666
+ name: string;
667
+ type: string;
668
+ status: import("../../../../database/api/.generated").$Enums.Status;
669
+ tags: string[];
670
+ identifier: string;
671
+ chainId: number;
672
+ action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
673
+ tvl: number;
674
+ dailyRewards: number;
675
+ }[]>;
455
676
  static getAllIds(): Promise<{
456
677
  id: string;
457
678
  }[]>;
@@ -505,6 +726,57 @@ export declare abstract class OpportunityService {
505
726
  amount: bigint;
506
727
  }[];
507
728
  };
729
+ campaigns: {
730
+ params: any;
731
+ chain: {
732
+ name: string;
733
+ id: number;
734
+ icon: string;
735
+ };
736
+ rewardToken: {
737
+ symbol: string;
738
+ name: string | null;
739
+ id: string;
740
+ icon: string;
741
+ chainId: number;
742
+ address: string;
743
+ decimals: number;
744
+ verified: boolean;
745
+ isTest: boolean;
746
+ } & {
747
+ price?: number | null | undefined;
748
+ };
749
+ distributionChain: {
750
+ name: string;
751
+ id: number;
752
+ icon: string;
753
+ } | undefined;
754
+ campaignStatus: {
755
+ error: string;
756
+ details: Prisma.JsonValue;
757
+ status: import("../../../../database/api/.generated").$Enums.RunStatus;
758
+ campaignId: string;
759
+ computedUntil: bigint;
760
+ processingStarted: bigint;
761
+ };
762
+ creatorAddress: string;
763
+ Creator: {
764
+ tags: string[];
765
+ address: string;
766
+ creatorId: string | null;
767
+ };
768
+ type: string;
769
+ id: string;
770
+ subType: number | null;
771
+ startTimestamp: bigint;
772
+ endTimestamp: bigint;
773
+ computeChainId: number;
774
+ distributionChainId: number;
775
+ campaignId: string;
776
+ rewardTokenId: string;
777
+ amount: string;
778
+ opportunityId: string;
779
+ }[] | undefined;
508
780
  id: string;
509
781
  depositUrl: string | undefined;
510
782
  tokens: ({
@@ -271,7 +271,7 @@ export class OpportunityService {
271
271
  static async findMany(query) {
272
272
  return await CacheService.wrap(TTLPresets.MIN_5, async (query) => {
273
273
  const opportunities = await OpportunityRepository.findMany(query);
274
- return opportunities.map(OpportunityService.formatResponse);
274
+ return opportunities.map(c => OpportunityService.formatResponse(c));
275
275
  }, query);
276
276
  }
277
277
  /**
@@ -288,8 +288,7 @@ export class OpportunityService {
288
288
  return await CacheService.wrap(TTLPresets.MIN_10, async (chainId) => {
289
289
  const opportunities = await OpportunityRepository.findLiveWithFirstCampaign(chainId);
290
290
  return opportunities.map(o => {
291
- const formatted = OpportunityService.formatResponse(o);
292
- return Object.assign(formatted, { campaigns: o.Campaigns.map(CampaignService.format) });
291
+ return OpportunityService.formatResponse(o);
293
292
  });
294
293
  }, chainId);
295
294
  });
@@ -299,22 +298,21 @@ export class OpportunityService {
299
298
  }
300
299
  static formatResponse(opportunity) {
301
300
  const { DailyRewardsRecords, AprRecords, TvlRecords, Campaigns, ...opp } = opportunity;
301
+ const aprRecord = opp.status === "LIVE"
302
+ ? (AprRecords?.map(({ cumulated, timestamp, AprBreakdown: breakdowns }) => ({
303
+ cumulated,
304
+ timestamp,
305
+ breakdowns,
306
+ }))?.[0] ?? undefined)
307
+ : {
308
+ cumulated: 0,
309
+ timestamp: AprRecords?.[0]?.timestamp ?? 0n,
310
+ breakdowns: !AprRecords?.[0]?.AprBreakdown?.[0] ? [] : [{ ...AprRecords?.[0]?.AprBreakdown[0], value: 0 }],
311
+ };
302
312
  const formated = {
303
313
  ...OpportunityService.formatResponseBase(opp),
304
314
  apr: opp.status === "LIVE" ? opp.apr : 0,
305
- aprRecord: opp.status === "LIVE"
306
- ? (AprRecords?.map(({ cumulated, timestamp, AprBreakdown: breakdowns }) => ({
307
- cumulated,
308
- timestamp,
309
- breakdowns,
310
- }))?.[0] ?? undefined)
311
- : {
312
- cumulated: 0,
313
- timestamp: AprRecords?.[0]?.timestamp ?? 0n,
314
- breakdowns: !AprRecords?.[0]?.AprBreakdown?.[0]
315
- ? []
316
- : [{ ...AprRecords?.[0]?.AprBreakdown?.[0], value: 0 }],
317
- },
315
+ aprRecord,
318
316
  tvlRecord: TvlRecords?.map(({ id, total, timestamp, TvlBreakdown: breakdowns }) => ({
319
317
  id,
320
318
  total,
@@ -333,10 +331,12 @@ export class OpportunityService {
333
331
  };
334
332
  }),
335
333
  }))?.[0] ?? undefined,
334
+ campaigns: !!Campaigns ? Campaigns?.map(c => CampaignService.format(c)) : undefined,
336
335
  //TODO: change this to accomodate all return types
337
336
  };
338
- if (Campaigns)
339
- Object.assign(formated, { campaigns: Campaigns.map(c => CampaignService.format(c)) });
337
+ // biome-ignore lint/performance/noDelete: <explanation>
338
+ if (!Campaigns)
339
+ delete formated.campaigns;
340
340
  return formated;
341
341
  }
342
342
  static formatResponseBase(opportunity) {