@merkl/api 0.16.43 → 0.16.45

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")
@@ -52,6 +52,7 @@ export declare abstract class OpportunityRepository {
52
52
  computeChainId: number;
53
53
  distributionChainId: number;
54
54
  campaignId: string;
55
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
55
56
  rewardTokenId: string;
56
57
  amount: string;
57
58
  opportunityId: string;
@@ -185,6 +186,7 @@ export declare abstract class OpportunityRepository {
185
186
  computeChainId: number;
186
187
  distributionChainId: number;
187
188
  campaignId: string;
189
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
188
190
  rewardTokenId: string;
189
191
  amount: string;
190
192
  opportunityId: string;
@@ -374,6 +376,7 @@ export declare abstract class OpportunityRepository {
374
376
  computeChainId: number;
375
377
  distributionChainId: number;
376
378
  campaignId: string;
379
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
377
380
  rewardTokenId: string;
378
381
  amount: string;
379
382
  opportunityId: string;
@@ -507,6 +510,7 @@ export declare abstract class OpportunityRepository {
507
510
  computeChainId: number;
508
511
  distributionChainId: number;
509
512
  campaignId: string;
513
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
510
514
  rewardTokenId: string;
511
515
  amount: string;
512
516
  opportunityId: string;
@@ -684,6 +688,7 @@ export declare abstract class OpportunityRepository {
684
688
  computeChainId: number;
685
689
  distributionChainId: number;
686
690
  campaignId: string;
691
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
687
692
  rewardTokenId: string;
688
693
  amount: string;
689
694
  opportunityId: string;
@@ -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,58 @@ 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
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
489
+ rewardTokenId: string;
490
+ amount: string;
491
+ opportunityId: string;
492
+ }[] | undefined;
270
493
  id: string;
271
494
  depositUrl: string | undefined;
272
495
  tokens: ({
@@ -312,7 +535,7 @@ export declare abstract class OpportunityService {
312
535
  * @returns the number of opportunities
313
536
  */
314
537
  static countMany(query: GetOpportunitiesQueryModel): Promise<number>;
315
- static findLiveWithFirstCampaign(chainId: MerklChainId): Promise<({
538
+ static findLiveWithFirstCampaign(chainId: MerklChainId): Promise<{
316
539
  apr: number;
317
540
  aprRecord: {
318
541
  cumulated: number;
@@ -362,44 +585,6 @@ export declare abstract class OpportunityService {
362
585
  amount: bigint;
363
586
  }[];
364
587
  };
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
588
  campaigns: {
404
589
  params: any;
405
590
  chain: {
@@ -447,11 +632,49 @@ export declare abstract class OpportunityService {
447
632
  computeChainId: number;
448
633
  distributionChainId: number;
449
634
  campaignId: string;
635
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
450
636
  rewardTokenId: string;
451
637
  amount: string;
452
638
  opportunityId: string;
453
- }[];
454
- })[]>;
639
+ }[] | undefined;
640
+ id: string;
641
+ depositUrl: string | undefined;
642
+ tokens: ({
643
+ symbol: string;
644
+ name: string | null;
645
+ id: string;
646
+ icon: string;
647
+ chainId: number;
648
+ address: string;
649
+ decimals: number;
650
+ verified: boolean;
651
+ isTest: boolean;
652
+ } & {
653
+ price?: number | null | undefined;
654
+ })[];
655
+ chain: {
656
+ name: string;
657
+ id: number;
658
+ icon: string;
659
+ };
660
+ protocol: {
661
+ name: string;
662
+ url: string;
663
+ description: string;
664
+ id: string;
665
+ tags: string[];
666
+ icon: string;
667
+ } | undefined;
668
+ name: string;
669
+ type: string;
670
+ status: import("../../../../database/api/.generated").$Enums.Status;
671
+ tags: string[];
672
+ identifier: string;
673
+ chainId: number;
674
+ action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
675
+ tvl: number;
676
+ dailyRewards: number;
677
+ }[]>;
455
678
  static getAllIds(): Promise<{
456
679
  id: string;
457
680
  }[]>;
@@ -505,6 +728,58 @@ export declare abstract class OpportunityService {
505
728
  amount: bigint;
506
729
  }[];
507
730
  };
731
+ campaigns: {
732
+ params: any;
733
+ chain: {
734
+ name: string;
735
+ id: number;
736
+ icon: string;
737
+ };
738
+ rewardToken: {
739
+ symbol: string;
740
+ name: string | null;
741
+ id: string;
742
+ icon: string;
743
+ chainId: number;
744
+ address: string;
745
+ decimals: number;
746
+ verified: boolean;
747
+ isTest: boolean;
748
+ } & {
749
+ price?: number | null | undefined;
750
+ };
751
+ distributionChain: {
752
+ name: string;
753
+ id: number;
754
+ icon: string;
755
+ } | undefined;
756
+ campaignStatus: {
757
+ error: string;
758
+ details: Prisma.JsonValue;
759
+ status: import("../../../../database/api/.generated").$Enums.RunStatus;
760
+ campaignId: string;
761
+ computedUntil: bigint;
762
+ processingStarted: bigint;
763
+ };
764
+ creatorAddress: string;
765
+ Creator: {
766
+ tags: string[];
767
+ address: string;
768
+ creatorId: string | null;
769
+ };
770
+ type: string;
771
+ id: string;
772
+ subType: number | null;
773
+ startTimestamp: bigint;
774
+ endTimestamp: bigint;
775
+ computeChainId: number;
776
+ distributionChainId: number;
777
+ campaignId: string;
778
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
779
+ rewardTokenId: string;
780
+ amount: string;
781
+ opportunityId: string;
782
+ }[] | undefined;
508
783
  id: string;
509
784
  depositUrl: string | undefined;
510
785
  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) {
@@ -37,6 +37,7 @@ export declare abstract class ProtocolRepository {
37
37
  computeChainId: number;
38
38
  distributionChainId: number;
39
39
  campaignId: string;
40
+ distributionType: import("../../../../database/api/.generated").$Enums.DistributionType;
40
41
  rewardTokenId: string;
41
42
  amount: string;
42
43
  opportunityId: string;