@merkl/api 0.10.133 → 0.10.135

Sign up to get free protection for your applications and to get access to all the features.
@@ -378,6 +378,31 @@ declare const eden: {
378
378
  200: number;
379
379
  }>>;
380
380
  };
381
+ aggregate: ((params: {
382
+ field: string | number;
383
+ }) => {
384
+ get: (options: {
385
+ headers?: Record<string, unknown> | undefined;
386
+ query: {
387
+ sort?: undefined;
388
+ name?: string | undefined;
389
+ tokens?: string | undefined;
390
+ status?: string | undefined;
391
+ items?: number | undefined;
392
+ tags?: string | undefined;
393
+ chainId?: string | undefined;
394
+ page?: number | undefined;
395
+ action?: string | undefined;
396
+ mainProtocolId?: string | undefined;
397
+ order?: undefined;
398
+ };
399
+ fetch?: RequestInit | undefined;
400
+ }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
401
+ 200: {
402
+ sum: File;
403
+ };
404
+ }>>;
405
+ }) & {};
381
406
  };
382
407
  campaigns: {
383
408
  index: {
@@ -2215,6 +2240,38 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
2215
2240
  };
2216
2241
  };
2217
2242
  };
2243
+ } & {
2244
+ opportunities: {
2245
+ aggregate: {
2246
+ ":field": {
2247
+ get: {
2248
+ body: unknown;
2249
+ params: {
2250
+ field: never;
2251
+ };
2252
+ query: {
2253
+ sort?: undefined;
2254
+ name?: string | undefined;
2255
+ tokens?: string | undefined;
2256
+ status?: string | undefined;
2257
+ items?: number | undefined;
2258
+ tags?: string | undefined;
2259
+ chainId?: string | undefined;
2260
+ page?: number | undefined;
2261
+ action?: string | undefined;
2262
+ mainProtocolId?: string | undefined;
2263
+ order?: undefined;
2264
+ };
2265
+ headers: unknown;
2266
+ response: {
2267
+ 200: {
2268
+ sum: File;
2269
+ };
2270
+ };
2271
+ };
2272
+ };
2273
+ };
2274
+ };
2218
2275
  };
2219
2276
  } & {
2220
2277
  v4: {
@@ -4379,6 +4436,31 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
4379
4436
  200: number;
4380
4437
  }>>;
4381
4438
  };
4439
+ aggregate: ((params: {
4440
+ field: string | number;
4441
+ }) => {
4442
+ get: (options: {
4443
+ headers?: Record<string, unknown> | undefined;
4444
+ query: {
4445
+ sort?: undefined;
4446
+ name?: string | undefined;
4447
+ tokens?: string | undefined;
4448
+ status?: string | undefined;
4449
+ items?: number | undefined;
4450
+ tags?: string | undefined;
4451
+ chainId?: string | undefined;
4452
+ page?: number | undefined;
4453
+ action?: string | undefined;
4454
+ mainProtocolId?: string | undefined;
4455
+ order?: undefined;
4456
+ };
4457
+ fetch?: RequestInit | undefined;
4458
+ }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
4459
+ 200: {
4460
+ sum: File;
4461
+ };
4462
+ }>>;
4463
+ }) & {};
4382
4464
  };
4383
4465
  campaigns: {
4384
4466
  index: {
@@ -435,6 +435,38 @@ declare const app: Elysia<"", false, {
435
435
  };
436
436
  };
437
437
  };
438
+ } & {
439
+ opportunities: {
440
+ aggregate: {
441
+ ":field": {
442
+ get: {
443
+ body: unknown;
444
+ params: {
445
+ field: never;
446
+ };
447
+ query: {
448
+ sort?: undefined;
449
+ name?: string | undefined;
450
+ tokens?: string | undefined;
451
+ status?: string | undefined;
452
+ items?: number | undefined;
453
+ tags?: string | undefined;
454
+ chainId?: string | undefined;
455
+ page?: number | undefined;
456
+ action?: string | undefined;
457
+ mainProtocolId?: string | undefined;
458
+ order?: undefined;
459
+ };
460
+ headers: unknown;
461
+ response: {
462
+ 200: {
463
+ sum: File;
464
+ };
465
+ };
466
+ };
467
+ };
468
+ };
469
+ };
438
470
  };
439
471
  } & {
440
472
  v4: {
@@ -20,11 +20,13 @@ export async function CompoundDynamicData(_chainId, campaigns) {
20
20
  target: campaign.campaignParameters.targetToken,
21
21
  });
22
22
  }
23
- calls.push({
24
- allowFailure: true,
25
- callData: CTokenInterface.encodeFunctionData("totalBorrows"),
26
- target: campaign.campaignParameters.targetToken,
27
- });
23
+ else {
24
+ calls.push({
25
+ allowFailure: true,
26
+ callData: CTokenInterface.encodeFunctionData("totalBorrows"),
27
+ target: campaign.campaignParameters.targetToken,
28
+ });
29
+ }
28
30
  }
29
31
  }
30
32
  return {
@@ -408,6 +408,38 @@ export declare const OpportunityController: Elysia<"/opportunities", false, {
408
408
  };
409
409
  };
410
410
  };
411
+ } & {
412
+ opportunities: {
413
+ aggregate: {
414
+ ":field": {
415
+ get: {
416
+ body: unknown;
417
+ params: {
418
+ field: never;
419
+ };
420
+ query: {
421
+ sort?: undefined;
422
+ name?: string | undefined;
423
+ tokens?: string | undefined;
424
+ status?: string | undefined;
425
+ items?: number | undefined;
426
+ tags?: string | undefined;
427
+ chainId?: string | undefined;
428
+ page?: number | undefined;
429
+ action?: string | undefined;
430
+ mainProtocolId?: string | undefined;
431
+ order?: undefined;
432
+ };
433
+ headers: unknown;
434
+ response: {
435
+ 200: {
436
+ sum: File;
437
+ };
438
+ };
439
+ };
440
+ };
441
+ };
442
+ };
411
443
  }, {
412
444
  derive: {};
413
445
  resolve: {};
@@ -1,7 +1,7 @@
1
1
  import { NotFoundError } from "../../../errors";
2
2
  import { AuthorizationHeadersDto, TokenAuthGuard } from "../../../guards/TokenAuth.guard";
3
3
  import Elysia from "elysia";
4
- import { CreateOpportunityDto, GetOpportunitiesQueryDto, OpportunityUniqueDto } from "./opportunity.model";
4
+ import { CreateOpportunityDto, GetOpportunitiesQueryDto, OpportunityAggregateFieldDto, OpportunityUniqueDto, } from "./opportunity.model";
5
5
  import { OpportunityService } from "./opportunity.service";
6
6
  import { transformId } from "./transform-id.pipe";
7
7
  import { validateId } from "./validate-id.pipe";
@@ -60,4 +60,9 @@ export const OpportunityController = new Elysia({ prefix: "/opportunities", deta
60
60
  query: GetOpportunitiesQueryDto,
61
61
  })
62
62
  // ─── Get Opportunities Count ─────────────────────────────────────────
63
- .get("/count", async ({ query }) => await OpportunityService.countMany(query), { query: GetOpportunitiesQueryDto });
63
+ .get("/count", async ({ query }) => await OpportunityService.countMany(query), { query: GetOpportunitiesQueryDto })
64
+ // ─── Get Aggregate fields ─────────────────────────────────────────
65
+ .get("/aggregate/:field", async ({ query, params }) => await OpportunityService.aggregate(query, params.field), {
66
+ params: OpportunityAggregateFieldDto,
67
+ query: GetOpportunitiesQueryDto,
68
+ });
@@ -107,7 +107,11 @@ export declare const CreateOpportunityDto: import("@sinclair/typebox").TObject<{
107
107
  protocols: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
108
108
  mainProtocol: import("@sinclair/typebox").TString;
109
109
  }>;
110
+ export declare const OpportunityAggregateFieldDto: import("@sinclair/typebox").TObject<{
111
+ field: import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"dailyRewards">[]>;
112
+ }>;
110
113
  export type GetOpportunitiesQueryEntity = typeof GetOpportunitiesQueryDto.static;
111
114
  export type CreateOpportunityModel = typeof CreateOpportunityDto.static & {
112
115
  id: string;
113
116
  };
117
+ export type OpportunityAggregateField = typeof OpportunityAggregateFieldDto.static;
@@ -34,3 +34,6 @@ export const CreateOpportunityDto = t.Object({
34
34
  protocols: t.Array(t.String()),
35
35
  mainProtocol: t.String(),
36
36
  });
37
+ export const OpportunityAggregateFieldDto = t.Object({
38
+ field: t.Union(["dailyRewards"].map(v => t.Literal(v))),
39
+ });
@@ -1,4 +1,4 @@
1
- import type { Prisma, Status } from "../../../../database/api/.generated";
1
+ import { type Prisma, Status } from "../../../../database/api/.generated";
2
2
  import { type AprRecord } from "../apr";
3
3
  import { type DailyRewardsRecord } from "../reward";
4
4
  import { type TvlRecord } from "../tvl";
@@ -462,18 +462,7 @@ export declare abstract class OpportunityRepository {
462
462
  apr: number;
463
463
  dailyRewards: number;
464
464
  }>;
465
- static updateApr(id: string, apr: number): Promise<{
466
- name: string;
467
- type: import("../../../../database/api/.generated").$Enums.CampaignType;
468
- id: string;
469
- status: import("../../../../database/api/.generated").$Enums.Status;
470
- tags: string[];
471
- identifier: string;
472
- chainId: number;
473
- action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
474
- mainProtocolId: string | null;
475
- tvl: number;
476
- apr: number;
477
- dailyRewards: number;
465
+ static aggregateSum(field: keyof Prisma.OpportunitySumAggregateInputType, query: GetOpportunitiesQueryEntity): Promise<{
466
+ sum: never;
478
467
  }>;
479
468
  }
@@ -1,4 +1,5 @@
1
1
  import { apiDbClient } from "../../../utils/prisma";
2
+ import { Status } from "../../../../database/api/.generated";
2
3
  import { AprService } from "../apr";
3
4
  import { RewardService } from "../reward";
4
5
  import { TvlService } from "../tvl";
@@ -209,9 +210,18 @@ export class OpportunityRepository {
209
210
  };
210
211
  }
211
212
  static async updateStatus(id, status) {
213
+ if (status === Status.PAST)
214
+ return await apiDbClient.opportunity.update({ where: { id }, data: { status, apr: 0, dailyRewards: 0 } });
212
215
  return await apiDbClient.opportunity.update({ where: { id }, data: { status } });
213
216
  }
214
- static async updateApr(id, apr) {
215
- return await apiDbClient.opportunity.update({ where: { id }, data: { apr } });
217
+ static async aggregateSum(field, query) {
218
+ const args = OpportunityRepository.#transformQueryToPrismaFilters(query);
219
+ const result = await apiDbClient.opportunity.aggregate({
220
+ _sum: {
221
+ [field]: true,
222
+ },
223
+ ...args,
224
+ });
225
+ return { sum: result._sum[field] ?? null };
216
226
  }
217
227
  }
@@ -1,4 +1,5 @@
1
1
  import { type CreateCampaignModel } from "../campaign";
2
+ import { Prisma } from "../../../../database/api/.generated";
2
3
  import type { ChainId } from "@sdk";
3
4
  import type { CreateOpportunityModel, GetOpportunitiesQueryEntity, LightOpportunityFromDB, OpportunityMetadata, OpportunityUnique } from "./opportunity.model";
4
5
  import { OpportunityRepository } from "./opportunity.repository";
@@ -438,4 +439,7 @@ export declare abstract class OpportunityService {
438
439
  apr: number;
439
440
  dailyRewards: number;
440
441
  };
442
+ static aggregate(query: GetOpportunitiesQueryEntity, field: keyof Prisma.OpportunitySumAggregateInputType): Promise<{
443
+ sum: never;
444
+ }>;
441
445
  }
@@ -84,7 +84,6 @@ export class OpportunityService {
84
84
  for (const opp of opportunities) {
85
85
  const { live: activeCampaigns, soon: futureCampaigns } = CampaignService.splitOnStatus(opp.Campaigns);
86
86
  if (activeCampaigns.length === 0) {
87
- await OpportunityRepository.updateApr(opp.id, 0);
88
87
  await OpportunityRepository.updateStatus(opp.id, futureCampaigns.length === 0 ? "PAST" : "SOON").catch(err => log.error("Cannot update opportunity status to PAST", err, "opportunities"));
89
88
  }
90
89
  if (opp.status !== "LIVE" && activeCampaigns.length !== 0)
@@ -177,4 +176,7 @@ export class OpportunityService {
177
176
  protocol: MainProtocol ?? undefined,
178
177
  };
179
178
  }
179
+ static aggregate(query, field) {
180
+ return OpportunityRepository.aggregateSum(field, query);
181
+ }
180
182
  }
@@ -417,6 +417,38 @@ export declare const v4: Elysia<"/v4", false, {
417
417
  };
418
418
  };
419
419
  };
420
+ } & {
421
+ opportunities: {
422
+ aggregate: {
423
+ ":field": {
424
+ get: {
425
+ body: unknown;
426
+ params: {
427
+ field: never;
428
+ };
429
+ query: {
430
+ sort?: undefined;
431
+ name?: string | undefined;
432
+ tokens?: string | undefined;
433
+ status?: string | undefined;
434
+ items?: number | undefined;
435
+ tags?: string | undefined;
436
+ chainId?: string | undefined;
437
+ page?: number | undefined;
438
+ action?: string | undefined;
439
+ mainProtocolId?: string | undefined;
440
+ order?: undefined;
441
+ };
442
+ headers: unknown;
443
+ response: {
444
+ 200: {
445
+ sum: File;
446
+ };
447
+ };
448
+ };
449
+ };
450
+ };
451
+ };
420
452
  };
421
453
  } & {
422
454
  v4: {
@@ -443,6 +443,38 @@ declare const _default: (app: App) => import("elysia").default<"", false, {
443
443
  };
444
444
  };
445
445
  };
446
+ } & {
447
+ opportunities: {
448
+ aggregate: {
449
+ ":field": {
450
+ get: {
451
+ body: unknown;
452
+ params: {
453
+ field: never;
454
+ };
455
+ query: {
456
+ sort?: undefined;
457
+ name?: string | undefined;
458
+ tokens?: string | undefined;
459
+ status?: string | undefined;
460
+ items?: number | undefined;
461
+ tags?: string | undefined;
462
+ chainId?: string | undefined;
463
+ page?: number | undefined;
464
+ action?: string | undefined;
465
+ mainProtocolId?: string | undefined;
466
+ order?: undefined;
467
+ };
468
+ headers: unknown;
469
+ response: {
470
+ 200: {
471
+ sum: File;
472
+ };
473
+ };
474
+ };
475
+ };
476
+ };
477
+ };
446
478
  };
447
479
  } & {
448
480
  v4: {
@@ -441,6 +441,38 @@ declare const _default: (app: App) => import("elysia").default<"", false, {
441
441
  };
442
442
  };
443
443
  };
444
+ } & {
445
+ opportunities: {
446
+ aggregate: {
447
+ ":field": {
448
+ get: {
449
+ body: unknown;
450
+ params: {
451
+ field: never;
452
+ };
453
+ query: {
454
+ sort?: undefined;
455
+ name?: string | undefined;
456
+ tokens?: string | undefined;
457
+ status?: string | undefined;
458
+ items?: number | undefined;
459
+ tags?: string | undefined;
460
+ chainId?: string | undefined;
461
+ page?: number | undefined;
462
+ action?: string | undefined;
463
+ mainProtocolId?: string | undefined;
464
+ order?: undefined;
465
+ };
466
+ headers: unknown;
467
+ response: {
468
+ 200: {
469
+ sum: File;
470
+ };
471
+ };
472
+ };
473
+ };
474
+ };
475
+ };
444
476
  };
445
477
  } & {
446
478
  v4: {
@@ -444,6 +444,38 @@ declare const _default: (app: App) => import("elysia").default<"", false, {
444
444
  };
445
445
  };
446
446
  };
447
+ } & {
448
+ opportunities: {
449
+ aggregate: {
450
+ ":field": {
451
+ get: {
452
+ body: unknown;
453
+ params: {
454
+ field: never;
455
+ };
456
+ query: {
457
+ sort?: undefined;
458
+ name?: string | undefined;
459
+ tokens?: string | undefined;
460
+ status?: string | undefined;
461
+ items?: number | undefined;
462
+ tags?: string | undefined;
463
+ chainId?: string | undefined;
464
+ page?: number | undefined;
465
+ action?: string | undefined;
466
+ mainProtocolId?: string | undefined;
467
+ order?: undefined;
468
+ };
469
+ headers: unknown;
470
+ response: {
471
+ 200: {
472
+ sum: File;
473
+ };
474
+ };
475
+ };
476
+ };
477
+ };
478
+ };
447
479
  };
448
480
  } & {
449
481
  v4: {
@@ -435,6 +435,38 @@ declare const _default: (app: App) => import("elysia").default<"", false, {
435
435
  };
436
436
  };
437
437
  };
438
+ } & {
439
+ opportunities: {
440
+ aggregate: {
441
+ ":field": {
442
+ get: {
443
+ body: unknown;
444
+ params: {
445
+ field: never;
446
+ };
447
+ query: {
448
+ sort?: undefined;
449
+ name?: string | undefined;
450
+ tokens?: string | undefined;
451
+ status?: string | undefined;
452
+ items?: number | undefined;
453
+ tags?: string | undefined;
454
+ chainId?: string | undefined;
455
+ page?: number | undefined;
456
+ action?: string | undefined;
457
+ mainProtocolId?: string | undefined;
458
+ order?: undefined;
459
+ };
460
+ headers: unknown;
461
+ response: {
462
+ 200: {
463
+ sum: File;
464
+ };
465
+ };
466
+ };
467
+ };
468
+ };
469
+ };
438
470
  };
439
471
  } & {
440
472
  v4: {
@@ -440,6 +440,38 @@ declare const _default: (app: App) => import("elysia").default<"", false, {
440
440
  };
441
441
  };
442
442
  };
443
+ } & {
444
+ opportunities: {
445
+ aggregate: {
446
+ ":field": {
447
+ get: {
448
+ body: unknown;
449
+ params: {
450
+ field: never;
451
+ };
452
+ query: {
453
+ sort?: undefined;
454
+ name?: string | undefined;
455
+ tokens?: string | undefined;
456
+ status?: string | undefined;
457
+ items?: number | undefined;
458
+ tags?: string | undefined;
459
+ chainId?: string | undefined;
460
+ page?: number | undefined;
461
+ action?: string | undefined;
462
+ mainProtocolId?: string | undefined;
463
+ order?: undefined;
464
+ };
465
+ headers: unknown;
466
+ response: {
467
+ 200: {
468
+ sum: File;
469
+ };
470
+ };
471
+ };
472
+ };
473
+ };
474
+ };
443
475
  };
444
476
  } & {
445
477
  v4: {
@@ -458,6 +458,38 @@ declare const _default: (app: App) => import("elysia").default<"", false, {
458
458
  };
459
459
  };
460
460
  };
461
+ } & {
462
+ opportunities: {
463
+ aggregate: {
464
+ ":field": {
465
+ get: {
466
+ body: unknown;
467
+ params: {
468
+ field: never;
469
+ };
470
+ query: {
471
+ sort?: undefined;
472
+ name?: string | undefined;
473
+ tokens?: string | undefined;
474
+ status?: string | undefined;
475
+ items?: number | undefined;
476
+ tags?: string | undefined;
477
+ chainId?: string | undefined;
478
+ page?: number | undefined;
479
+ action?: string | undefined;
480
+ mainProtocolId?: string | undefined;
481
+ order?: undefined;
482
+ };
483
+ headers: unknown;
484
+ response: {
485
+ 200: {
486
+ sum: File;
487
+ };
488
+ };
489
+ };
490
+ };
491
+ };
492
+ };
461
493
  };
462
494
  } & {
463
495
  v4: {
@@ -459,6 +459,38 @@ declare const _default: (app: App) => import("elysia").default<"", false, {
459
459
  };
460
460
  };
461
461
  };
462
+ } & {
463
+ opportunities: {
464
+ aggregate: {
465
+ ":field": {
466
+ get: {
467
+ body: unknown;
468
+ params: {
469
+ field: never;
470
+ };
471
+ query: {
472
+ sort?: undefined;
473
+ name?: string | undefined;
474
+ tokens?: string | undefined;
475
+ status?: string | undefined;
476
+ items?: number | undefined;
477
+ tags?: string | undefined;
478
+ chainId?: string | undefined;
479
+ page?: number | undefined;
480
+ action?: string | undefined;
481
+ mainProtocolId?: string | undefined;
482
+ order?: undefined;
483
+ };
484
+ headers: unknown;
485
+ response: {
486
+ 200: {
487
+ sum: File;
488
+ };
489
+ };
490
+ };
491
+ };
492
+ };
493
+ };
462
494
  };
463
495
  } & {
464
496
  v4: {