@merkl/api 0.16.33 → 0.16.35

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.
Files changed (78) hide show
  1. package/dist/src/backgroundJobs/index.js +0 -4
  2. package/dist/src/backgroundJobs/jobs/opportunityUpdater.js +3 -0
  3. package/dist/src/eden/index.d.ts +659 -446
  4. package/dist/src/entities/opportunity.d.ts +3 -1
  5. package/dist/src/index.d.ts +137 -118
  6. package/dist/src/jobs/etl/prices.js +9 -2
  7. package/dist/src/libs/deprecated-merklv3/index.js +1 -1
  8. package/dist/src/modules/v4/boost/boost.controller.js +1 -1
  9. package/dist/src/modules/v4/cache/cache.repository.d.ts +1 -0
  10. package/dist/src/modules/v4/cache/cache.repository.js +19 -0
  11. package/dist/src/modules/v4/campaign/campaign.service.d.ts +0 -5
  12. package/dist/src/modules/v4/campaign/campaign.service.js +0 -5
  13. package/dist/src/modules/v4/opportunity/opportunity.controller.d.ts +120 -57
  14. package/dist/src/modules/v4/opportunity/opportunity.controller.js +1 -1
  15. package/dist/src/modules/v4/opportunity/opportunity.converter.d.ts +9 -0
  16. package/dist/src/modules/v4/opportunity/opportunity.converter.js +153 -0
  17. package/dist/src/modules/v4/opportunity/opportunity.model.d.ts +3 -1
  18. package/dist/src/modules/v4/opportunity/opportunity.model.js +2 -0
  19. package/dist/src/modules/v4/opportunity/opportunity.repository.d.ts +18 -210
  20. package/dist/src/modules/v4/opportunity/opportunity.repository.js +76 -113
  21. package/dist/src/modules/v4/opportunity/opportunity.service.d.ts +219 -64
  22. package/dist/src/modules/v4/opportunity/opportunity.service.js +19 -21
  23. package/dist/src/modules/v4/reward/{subservices/converter.d.ts → reward.converter.d.ts} +3 -3
  24. package/dist/src/modules/v4/reward/{subservices/converter.js → reward.converter.js} +1 -1
  25. package/dist/src/modules/v4/router.d.ts +121 -58
  26. package/dist/src/modules/v4/status/status.controller.d.ts +1 -1
  27. package/dist/src/modules/v4/status/status.service.d.ts +1 -1
  28. package/dist/src/modules/v4/status/status.service.js +6 -4
  29. package/dist/src/routes/v3/app.js +1 -0
  30. package/dist/src/routes/v3/blacklist.js +1 -0
  31. package/dist/src/routes/v3/campaign/delay.js +1 -0
  32. package/dist/src/routes/v3/campaignClaims.d.ts +3 -1
  33. package/dist/src/routes/v3/campaignClaims.js +4 -13
  34. package/dist/src/routes/v3/campaignUnclaimed.js +1 -0
  35. package/dist/src/routes/v3/campaignsForMainParameter.d.ts +9 -1
  36. package/dist/src/routes/v3/campaignsForMainParameter.js +17 -7
  37. package/dist/src/routes/v3/campaignsRewardsReport.js +1 -0
  38. package/dist/src/routes/v3/claims.d.ts +3 -1
  39. package/dist/src/routes/v3/claims.js +4 -33
  40. package/dist/src/routes/v3/opportunity.d.ts +7 -7
  41. package/dist/src/routes/v3/opportunity.js +12 -13
  42. package/dist/src/routes/v3/recipients.js +1 -0
  43. package/dist/src/routes/v3/rewards.js +2 -1
  44. package/dist/src/routes/v3/rewardsReport.js +1 -0
  45. package/dist/src/routes/v3/router.d.ts +16 -60
  46. package/dist/src/routes/v3/router.js +0 -6
  47. package/dist/src/routes/v3/userRewards.js +2 -1
  48. package/dist/src/types/returnTypes.d.ts +0 -8
  49. package/dist/src/utils/camelToKebabCase.d.ts +2 -0
  50. package/dist/src/utils/camelToKebabCase.js +9 -0
  51. package/dist/tsconfig.package.tsbuildinfo +1 -1
  52. package/package.json +1 -1
  53. package/dist/src/backgroundJobs/jobs/priceUpdater.d.ts +0 -37
  54. package/dist/src/backgroundJobs/jobs/priceUpdater.js +0 -21
  55. package/dist/src/backgroundJobs/jobs/sync.d.ts +0 -40
  56. package/dist/src/backgroundJobs/jobs/sync.js +0 -33
  57. package/dist/src/routes/v3/campaignReport.d.ts +0 -43
  58. package/dist/src/routes/v3/campaignReport.js +0 -22
  59. package/dist/src/routes/v3/campaignsInfo.d.ts +0 -41
  60. package/dist/src/routes/v3/campaignsInfo.js +0 -54
  61. package/dist/src/routes/v3/exports/campaigns.d.ts +0 -43
  62. package/dist/src/routes/v3/exports/campaigns.js +0 -28
  63. package/dist/src/routes/v3/tokenUnclaimed.d.ts +0 -44
  64. package/dist/src/routes/v3/tokenUnclaimed.js +0 -24
  65. package/dist/src/utils/queries/campaignsForMainParameter.d.ts +0 -2
  66. package/dist/src/utils/queries/campaignsForMainParameter.js +0 -23
  67. package/dist/src/utils/queries/claimsOverTime.d.ts +0 -8
  68. package/dist/src/utils/queries/claimsOverTime.js +0 -111
  69. package/dist/src/utils/queries/endingCampaigns.d.ts +0 -10
  70. package/dist/src/utils/queries/endingCampaigns.js +0 -21
  71. package/dist/src/utils/queries/futureCampaigns.d.ts +0 -3
  72. package/dist/src/utils/queries/futureCampaigns.js +0 -19
  73. package/dist/src/utils/queries/mainParameterCampaigns.d.ts +0 -5
  74. package/dist/src/utils/queries/mainParameterCampaigns.js +0 -11
  75. package/dist/src/utils/queries/rewardsAmount.d.ts +0 -10
  76. package/dist/src/utils/queries/rewardsAmount.js +0 -106
  77. package/dist/src/utils/queries/unclaimed.d.ts +0 -11
  78. package/dist/src/utils/queries/unclaimed.js +0 -81
@@ -169,182 +169,13 @@ export declare abstract class OpportunityRepository {
169
169
  apr: number;
170
170
  dailyRewards: number;
171
171
  }) | null>;
172
- static findUniqueOrThrow(id: string, withTest?: boolean): Promise<{
172
+ static findUniqueOrThrow(id: string, withTest?: boolean, withCampaigns?: boolean): Promise<{
173
173
  Chain: {
174
174
  name: string;
175
175
  id: number;
176
176
  icon: string;
177
177
  };
178
- Tokens: {
179
- symbol: string;
180
- name: string | null;
181
- id: string;
182
- icon: string;
183
- chainId: number;
184
- address: string;
185
- decimals: number;
186
- displaySymbol: string;
187
- verified: boolean;
188
- isTest: boolean;
189
- price: number | null;
190
- }[];
191
- Protocols: {
192
- name: string;
193
- url: string;
194
- description: string;
195
- id: string;
196
- tags: string[];
197
- icon: string;
198
- }[];
199
- MainProtocol: {
200
- name: string;
201
- url: string;
202
- description: string;
203
- id: string;
204
- tags: string[];
205
- icon: string;
206
- } | null;
207
- TvlRecords: ({
208
- TvlBreakdown: {
209
- type: import("../../../../database/api/.generated").$Enums.TvlType;
210
- id: number;
211
- identifier: string;
212
- value: number;
213
- tvlRecordId: string;
214
- }[];
215
- } & {
216
- total: number;
217
- id: string;
218
- timestamp: bigint;
219
- opportunityId: string;
220
- })[];
221
- AprRecords: ({
222
- AprBreakdown: {
223
- type: import("../../../../database/api/.generated").$Enums.AprType;
224
- id: number;
225
- identifier: string;
226
- value: number;
227
- aprRecordId: string;
228
- }[];
229
- } & {
230
- id: string;
231
- timestamp: bigint;
232
- opportunityId: string;
233
- cumulated: number;
234
- })[];
235
- DailyRewardsRecords: ({
236
- DailyRewardsBreakdown: ({
237
- Campaign: {
238
- startTimestamp: bigint;
239
- endTimestamp: bigint;
240
- amount: string;
241
- RewardToken: {
242
- symbol: string;
243
- name: string | null;
244
- id: string;
245
- icon: string;
246
- chainId: number;
247
- address: string;
248
- decimals: number;
249
- displaySymbol: string;
250
- verified: boolean;
251
- isTest: boolean;
252
- price: number | null;
253
- };
254
- CampaignStatus: {
255
- error: string;
256
- details: Prisma.JsonValue;
257
- status: import("../../../../database/api/.generated").$Enums.RunStatus;
258
- campaignId: string;
259
- computedUntil: bigint;
260
- processingStarted: bigint;
261
- }[];
262
- };
263
- } & {
264
- id: number;
265
- value: number;
266
- campaignId: string;
267
- dailyRewardsRecordId: string;
268
- })[];
269
- } & {
270
- total: number;
271
- id: string;
272
- timestamp: bigint;
273
- opportunityId: string;
274
- })[];
275
- } & {
276
- name: string;
277
- type: string;
278
- id: string;
279
- status: import("../../../../database/api/.generated").$Enums.Status;
280
- tags: string[];
281
- identifier: string;
282
- chainId: number;
283
- action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
284
- depositUrl: string | null;
285
- mainProtocolId: string | null;
286
- tvl: number;
287
- apr: number;
288
- dailyRewards: number;
289
- }>;
290
- static findUniqueOrThrowWithCampaigns(id: string, withTest: boolean): Promise<{
291
- Chain: {
292
- Explorer: {
293
- type: import("../../../../database/api/.generated").$Enums.ExplorerType;
294
- url: string;
295
- id: string;
296
- chainId: number;
297
- }[];
298
- } & {
299
- name: string;
300
- id: number;
301
- icon: string;
302
- };
303
- Campaigns: ({
304
- ComputeChain: {
305
- name: string;
306
- id: number;
307
- icon: string;
308
- };
309
- DistributionChain: {
310
- Explorer: {
311
- type: import("../../../../database/api/.generated").$Enums.ExplorerType;
312
- url: string;
313
- id: string;
314
- chainId: number;
315
- }[];
316
- } & {
317
- name: string;
318
- id: number;
319
- icon: string;
320
- };
321
- RewardToken: {
322
- symbol: string;
323
- name: string | null;
324
- id: string;
325
- icon: string;
326
- chainId: number;
327
- address: string;
328
- decimals: number;
329
- displaySymbol: string;
330
- verified: boolean;
331
- isTest: boolean;
332
- price: number | null;
333
- };
334
- Creator: {
335
- tags: string[];
336
- address: string;
337
- creatorId: string | null;
338
- };
339
- CampaignStatus: {
340
- error: string;
341
- details: Prisma.JsonValue;
342
- status: import("../../../../database/api/.generated").$Enums.RunStatus;
343
- campaignId: string;
344
- computedUntil: bigint;
345
- processingStarted: bigint;
346
- }[];
347
- } & {
178
+ Campaigns: {
348
179
  type: string;
349
180
  id: string;
350
181
  params: Prisma.JsonValue;
@@ -358,7 +189,7 @@ export declare abstract class OpportunityRepository {
358
189
  amount: string;
359
190
  opportunityId: string;
360
191
  creatorAddress: string;
361
- })[];
192
+ }[];
362
193
  Tokens: {
363
194
  symbol: string;
364
195
  name: string | null;
@@ -660,22 +491,13 @@ export declare abstract class OpportunityRepository {
660
491
  apr: number;
661
492
  dailyRewards: number;
662
493
  })[]>;
663
- static findManyWithCampaigns(filters: Prisma.OpportunityFindManyArgs): Promise<({
664
- Campaigns: ({
665
- RewardToken: {
666
- symbol: string;
667
- name: string | null;
668
- id: string;
669
- icon: string;
670
- chainId: number;
671
- address: string;
672
- decimals: number;
673
- displaySymbol: string;
674
- verified: boolean;
675
- isTest: boolean;
676
- price: number | null;
677
- };
678
- } & {
494
+ static findMany(query: GetOpportunitiesQueryModel): Promise<({
495
+ Chain: {
496
+ name: string;
497
+ id: number;
498
+ icon: string;
499
+ };
500
+ Campaigns: {
679
501
  type: string;
680
502
  id: string;
681
503
  params: Prisma.JsonValue;
@@ -689,28 +511,7 @@ export declare abstract class OpportunityRepository {
689
511
  amount: string;
690
512
  opportunityId: string;
691
513
  creatorAddress: string;
692
- })[];
693
- } & {
694
- name: string;
695
- type: string;
696
- id: string;
697
- status: import("../../../../database/api/.generated").$Enums.Status;
698
- tags: string[];
699
- identifier: string;
700
- chainId: number;
701
- action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
702
- depositUrl: string | null;
703
- mainProtocolId: string | null;
704
- tvl: number;
705
- apr: number;
706
- dailyRewards: number;
707
- })[]>;
708
- static findMany(query: GetOpportunitiesQueryModel): Promise<({
709
- Chain: {
710
- name: string;
711
- id: number;
712
- icon: string;
713
- };
514
+ }[];
714
515
  Tokens: {
715
516
  symbol: string;
716
517
  name: string | null;
@@ -836,6 +637,13 @@ export declare abstract class OpportunityRepository {
836
637
  icon: string;
837
638
  };
838
639
  DistributionChain: {
640
+ Explorer: {
641
+ type: import("../../../../database/api/.generated").$Enums.ExplorerType;
642
+ url: string;
643
+ id: string;
644
+ chainId: number;
645
+ }[];
646
+ } & {
839
647
  name: string;
840
648
  id: number;
841
649
  icon: string;
@@ -6,6 +6,47 @@ import { ProtocolService } from "../protocol";
6
6
  import { RewardService } from "../reward";
7
7
  import { TvlService } from "../tvl";
8
8
  export class OpportunityRepository {
9
+ static #transformQueryToPrismaFilters(query) {
10
+ const { page: _page, items: _items, ...filters } = query;
11
+ //TODO: abstract away query to not be strictly equal to controller
12
+ const chainIds = query.chainId?.split(",").map(n => Number.parseInt(n));
13
+ const actions = query.action?.split(",");
14
+ const status = query.status?.split(",");
15
+ const tokens = query.tokens?.split(",");
16
+ const types = query.type?.split(",");
17
+ const protocols = query.mainProtocolId?.split(",");
18
+ const sort = (query.sort === "rewards" ? "dailyRewards" : query.sort) ?? "dailyRewards";
19
+ const order = query.order ?? "desc";
20
+ const test = query.test ?? false;
21
+ const creatorAddress = query.creatorAddress ?? null;
22
+ const identifier = query.identifier ?? null;
23
+ const orderBy = {
24
+ [sort]: order,
25
+ };
26
+ return {
27
+ orderBy,
28
+ where: {
29
+ tags: !filters.tags ? undefined : { has: filters.tags },
30
+ type: !filters.type ? undefined : { in: types },
31
+ tvl: filters.minimumTvl ? { gte: filters.minimumTvl } : undefined,
32
+ chainId: !chainIds ? undefined : { in: chainIds },
33
+ name: !filters.name ? undefined : { contains: filters.name, mode: "insensitive" },
34
+ action: !actions ? undefined : { in: actions },
35
+ status: !status ? undefined : { in: status },
36
+ mainProtocolId: !protocols ? undefined : { in: protocols },
37
+ identifier: !identifier ? undefined : { contains: identifier, mode: "insensitive" },
38
+ Campaigns: test || !creatorAddress
39
+ ? undefined
40
+ : {
41
+ some: {
42
+ RewardToken: !test ? { isTest: false } : undefined,
43
+ creatorAddress: creatorAddress ? creatorAddress : undefined,
44
+ },
45
+ },
46
+ Tokens: { some: { symbol: { in: tokens } } },
47
+ },
48
+ };
49
+ }
9
50
  static #getRecordInclusion(withTest = true) {
10
51
  return {
11
52
  AprRecords: {
@@ -44,6 +85,31 @@ export class OpportunityRepository {
44
85
  },
45
86
  };
46
87
  }
88
+ static #getCampaignInclusion(withTest = true) {
89
+ return {
90
+ orderBy: {
91
+ endTimestamp: "desc",
92
+ },
93
+ where: withTest
94
+ ? undefined
95
+ : {
96
+ RewardToken: {
97
+ isTest: false,
98
+ },
99
+ },
100
+ include: {
101
+ RewardToken: true,
102
+ ComputeChain: true,
103
+ DistributionChain: {
104
+ include: {
105
+ Explorer: true,
106
+ },
107
+ },
108
+ Creator: true,
109
+ CampaignStatus: true, // [][0]
110
+ },
111
+ };
112
+ }
47
113
  static async create(newOpp, upsert = false) {
48
114
  if (!!newOpp.mainProtocol) {
49
115
  let mainProtocol = await apiDbClient.protocol.findUnique({ where: { id: newOpp.mainProtocol } });
@@ -125,10 +191,11 @@ export class OpportunityRepository {
125
191
  where: { id },
126
192
  });
127
193
  }
128
- static async findUniqueOrThrow(id, withTest = true) {
194
+ static async findUniqueOrThrow(id, withTest = true, withCampaigns = false) {
129
195
  return await apiDbClient.opportunity.findUniqueOrThrow({
130
196
  include: {
131
197
  ...OpportunityRepository.#getRecordInclusion(withTest),
198
+ Campaigns: withCampaigns ? OpportunityRepository.#getCampaignInclusion(withTest) : undefined,
132
199
  Chain: true,
133
200
  MainProtocol: true,
134
201
  Protocols: true,
@@ -139,46 +206,6 @@ export class OpportunityRepository {
139
206
  where: { id },
140
207
  });
141
208
  }
142
- static async findUniqueOrThrowWithCampaigns(id, withTest) {
143
- const b = await apiDbClient.opportunity.findUniqueOrThrow({
144
- include: {
145
- ...OpportunityRepository.#getRecordInclusion(withTest),
146
- Chain: {
147
- include: {
148
- Explorer: true,
149
- },
150
- },
151
- Campaigns: {
152
- where: withTest
153
- ? undefined
154
- : {
155
- RewardToken: {
156
- isTest: false,
157
- },
158
- },
159
- include: {
160
- RewardToken: true,
161
- ComputeChain: true,
162
- DistributionChain: {
163
- include: {
164
- Explorer: true,
165
- },
166
- },
167
- Creator: true,
168
- CampaignStatus: true, // [][0]
169
- },
170
- orderBy: {
171
- endTimestamp: "desc",
172
- },
173
- },
174
- MainProtocol: true,
175
- Protocols: true,
176
- Tokens: true,
177
- },
178
- where: { id },
179
- });
180
- return b;
181
- }
182
209
  /**
183
210
  * Gets opportunities and campaigns for which filtered on campaigns
184
211
  * @param filters
@@ -193,6 +220,7 @@ export class OpportunityRepository {
193
220
  },
194
221
  include: {
195
222
  ...OpportunityRepository.#getRecordInclusion(),
223
+ Campaigns: OpportunityRepository.#getCampaignInclusion(true),
196
224
  Chain: {
197
225
  include: {
198
226
  Explorer: true,
@@ -201,92 +229,23 @@ export class OpportunityRepository {
201
229
  MainProtocol: true,
202
230
  Protocols: true,
203
231
  Tokens: true,
204
- Campaigns: {
205
- where,
206
- include: {
207
- RewardToken: true,
208
- ComputeChain: true,
209
- DistributionChain: {
210
- include: {
211
- Explorer: true,
212
- },
213
- },
214
- Creator: true,
215
- CampaignStatus: true, // [][0]
216
- },
217
- orderBy: {
218
- endTimestamp: "desc",
219
- },
220
- },
221
232
  },
222
233
  });
223
234
  }
224
- static async findManyWithCampaigns(filters) {
225
- return await apiDbClient.opportunity.findMany({
226
- ...filters,
227
- include: {
228
- Campaigns: {
229
- include: {
230
- RewardToken: true,
231
- },
232
- orderBy: {
233
- endTimestamp: "desc",
234
- },
235
- },
236
- },
237
- });
238
- }
239
- static #transformQueryToPrismaFilters(query) {
240
- const { page: _page, items: _items, ...filters } = query;
241
- //TODO: abstract away query to not be strictly equal to controller
242
- const chainIds = query.chainId?.split(",").map(n => Number.parseInt(n));
243
- const actions = query.action?.split(",");
244
- const status = query.status?.split(",");
245
- const tokens = query.tokens?.split(",");
246
- const types = query.type?.split(",");
247
- const protocols = query.mainProtocolId?.split(",");
248
- const sort = (query.sort === "rewards" ? "dailyRewards" : query.sort) ?? "dailyRewards";
249
- const order = query.order ?? "desc";
250
- const test = query.test ?? false;
251
- const creatorAddress = query.creatorAddress ?? null;
252
- const orderBy = {
253
- [sort]: order,
254
- };
255
- return {
256
- orderBy,
257
- where: {
258
- tags: !filters.tags ? undefined : { has: filters.tags },
259
- type: !filters.type ? undefined : { in: types },
260
- tvl: filters.minimumTvl ? { gte: filters.minimumTvl } : undefined,
261
- chainId: !chainIds ? undefined : { in: chainIds },
262
- name: !filters.name ? undefined : { contains: filters.name, mode: "insensitive" },
263
- action: !actions ? undefined : { in: actions },
264
- status: !status ? undefined : { in: status },
265
- mainProtocolId: !protocols ? undefined : { in: protocols },
266
- Campaigns: test || !creatorAddress
267
- ? undefined
268
- : {
269
- some: {
270
- RewardToken: !test ? { isTest: false } : undefined,
271
- creatorAddress: creatorAddress ? creatorAddress : undefined,
272
- },
273
- },
274
- Tokens: { some: { symbol: { in: tokens } } },
275
- },
276
- };
277
- }
278
235
  static async findMany(query) {
279
236
  // pagination by offset; might have to change to cursor based for performance
280
237
  const { page: _page, items: _items } = query;
281
238
  const page = _page ? _page : 0;
282
239
  const items = _items ? _items : 20;
283
240
  const withTest = query.test ?? false;
241
+ const withCampaigns = query.campaigns ?? false;
284
242
  const args = OpportunityRepository.#transformQueryToPrismaFilters(query);
285
243
  return await apiDbClient.opportunity.findMany({
286
244
  take: items,
287
245
  skip: page * items,
288
246
  include: {
289
247
  ...OpportunityRepository.#getRecordInclusion(withTest),
248
+ Campaigns: withCampaigns ? OpportunityRepository.#getCampaignInclusion(withTest) : undefined,
290
249
  MainProtocol: true,
291
250
  Chain: true,
292
251
  Protocols: true,
@@ -306,7 +265,11 @@ export class OpportunityRepository {
306
265
  include: {
307
266
  RewardToken: true,
308
267
  ComputeChain: true,
309
- DistributionChain: true,
268
+ DistributionChain: {
269
+ include: {
270
+ Explorer: true,
271
+ },
272
+ },
310
273
  CampaignStatus: true,
311
274
  Creator: true,
312
275
  },