@merkl/api 0.10.259 → 0.10.260

Sign up to get free protection for your applications and to get access to all the features.
@@ -130,11 +130,13 @@ declare const eden: {
130
130
  tags: string[];
131
131
  };
132
132
  }>>;
133
- get: (options?: {
133
+ get: (options: {
134
134
  headers?: Record<string, unknown> | undefined;
135
- query?: Record<string, unknown> | undefined;
135
+ query: {
136
+ test?: boolean | undefined;
137
+ };
136
138
  fetch?: RequestInit | undefined;
137
- } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
139
+ }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
138
140
  200: {
139
141
  protocol?: {
140
142
  name: string;
@@ -2151,7 +2153,7 @@ declare const eden: {
2151
2153
  fetch?: RequestInit | undefined;
2152
2154
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
2153
2155
  200: (import("../modules/v4/claims").ClaimModel & {
2154
- token: import("../modules/v4").Token["model"] | null;
2156
+ token?: import("../modules/v4").Token["model"];
2155
2157
  })[];
2156
2158
  }>>;
2157
2159
  }) & {};
@@ -3180,7 +3182,9 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
3180
3182
  params: {
3181
3183
  id: string;
3182
3184
  };
3183
- query: unknown;
3185
+ query: {
3186
+ test?: boolean | undefined;
3187
+ };
3184
3188
  headers: unknown;
3185
3189
  response: {
3186
3190
  200: {
@@ -5471,7 +5475,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5471
5475
  headers: unknown;
5472
5476
  response: {
5473
5477
  200: (import("../modules/v4/claims").ClaimModel & {
5474
- token: import("../modules/v4").Token["model"] | null;
5478
+ token?: import("../modules/v4").Token["model"];
5475
5479
  })[];
5476
5480
  };
5477
5481
  };
@@ -6441,11 +6445,13 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
6441
6445
  tags: string[];
6442
6446
  };
6443
6447
  }>>;
6444
- get: (options?: {
6448
+ get: (options: {
6445
6449
  headers?: Record<string, unknown> | undefined;
6446
- query?: Record<string, unknown> | undefined;
6450
+ query: {
6451
+ test?: boolean | undefined;
6452
+ };
6447
6453
  fetch?: RequestInit | undefined;
6448
- } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
6454
+ }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
6449
6455
  200: {
6450
6456
  protocol?: {
6451
6457
  name: string;
@@ -8462,7 +8468,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
8462
8468
  fetch?: RequestInit | undefined;
8463
8469
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
8464
8470
  200: (import("../modules/v4/claims").ClaimModel & {
8465
- token: import("../modules/v4").Token["model"] | null;
8471
+ token?: import("../modules/v4").Token["model"];
8466
8472
  })[];
8467
8473
  }>>;
8468
8474
  }) & {};
@@ -382,7 +382,9 @@ declare const app: Elysia<"", false, {
382
382
  params: {
383
383
  id: string;
384
384
  };
385
- query: unknown;
385
+ query: {
386
+ test?: boolean | undefined;
387
+ };
386
388
  headers: unknown;
387
389
  response: {
388
390
  200: {
@@ -2673,7 +2675,7 @@ declare const app: Elysia<"", false, {
2673
2675
  headers: unknown;
2674
2676
  response: {
2675
2677
  200: (import("./modules/v4/claims").ClaimModel & {
2676
- token: import("./modules/v4").Token["model"] | null;
2678
+ token?: import("./modules/v4").Token["model"];
2677
2679
  })[];
2678
2680
  };
2679
2681
  };
@@ -25,7 +25,7 @@ export declare const ClaimController: Elysia<"/claims", false, {
25
25
  headers: unknown;
26
26
  response: {
27
27
  200: (import("./claims.model").ClaimModel & {
28
- token: import("..").Token["model"] | null;
28
+ token?: import("..").Token["model"];
29
29
  })[];
30
30
  };
31
31
  };
@@ -4,6 +4,6 @@ import type { UserUniqueModel } from "../user";
4
4
  import type { ClaimModel } from "./claims.model";
5
5
  export declare abstract class ClaimService {
6
6
  static getHistoricalClaims(params: UserUniqueModel, chainFilter?: ChainId[]): Promise<(ClaimModel & {
7
- token: Token["model"] | null;
7
+ token?: Token["model"];
8
8
  })[]>;
9
9
  }
@@ -25,11 +25,11 @@ export class ClaimService {
25
25
  .flatMap(p => p.value ?? []) // null/undefined claim arrays
26
26
  .filter(claim => {
27
27
  // Ensure the claim's token exists and matches the chainFilter
28
- const token = claim?.token ? tokens[claim.token.toLowerCase()] : null;
28
+ const token = claim?.token ? tokens[claim.token.toLowerCase()] : undefined;
29
29
  return token && (!chainFilter.length || chainFilter.includes(token.chainId));
30
30
  })
31
31
  .map(claim => {
32
- const token = claim?.token ? tokens[claim.token.toLowerCase()] : null;
32
+ const token = claim?.token ? tokens[claim.token.toLowerCase()] : undefined;
33
33
  return {
34
34
  ...claim,
35
35
  token,
@@ -251,7 +251,9 @@ export declare const OpportunityController: Elysia<"/opportunities", false, {
251
251
  params: {
252
252
  id: string;
253
253
  };
254
- query: unknown;
254
+ query: {
255
+ test?: boolean | undefined;
256
+ };
255
257
  headers: unknown;
256
258
  response: {
257
259
  200: {
@@ -2,7 +2,7 @@ import { HttpErrorDto, NotFoundError, NotFoundErrorDto } from "../../../errors";
2
2
  import { BackOfficeGuard } from "../../../guards/BackOffice.guard";
3
3
  import { AuthorizationHeadersDto, TokenAuthGuard } from "../../../guards/TokenAuth.guard";
4
4
  import Elysia, { t } from "elysia";
5
- import { CreateOpportunityDto, GetOpportunitiesQueryDto, OpportunityAggregateFieldDto, OpportunityIdDto, OpportunityResourceDto, OpportunityUniqueDto, OpportunityWithCampaignsResourceDto, UpdateOpportunityDto, } from "./opportunity.model";
5
+ import { CreateOpportunityDto, GetOpportunitiesQueryDto, GetOpportunityQueryDto, OpportunityAggregateFieldDto, OpportunityIdDto, OpportunityResourceDto, OpportunityUniqueDto, OpportunityWithCampaignsResourceDto, UpdateOpportunityDto, } from "./opportunity.model";
6
6
  import { OpportunityService } from "./opportunity.service";
7
7
  import { transformId } from "./transform-id.pipe";
8
8
  import { validateId } from "./validate-id.pipe";
@@ -59,16 +59,16 @@ export const OpportunityController = new Elysia({
59
59
  response: { 200: t.Number() },
60
60
  })
61
61
  // ─── Get An Opportunity By Id ────────────────────────────────────────
62
- .get("/:id", async ({ params }) => {
62
+ .get("/:id", async ({ params, query }) => {
63
63
  try {
64
64
  if (!params.id.includes("-"))
65
- return await OpportunityService.getUniqueOrThrow(params.id);
65
+ return await OpportunityService.getUniqueOrThrow(params.id, query.test ?? false);
66
66
  const [chainId, type, identifier] = params.id.split("-");
67
67
  return await OpportunityService.getUniqueOrThrow({
68
68
  chainId: +chainId,
69
69
  type: type,
70
70
  identifier,
71
- });
71
+ }, query.test ?? false);
72
72
  }
73
73
  catch (err) {
74
74
  if (err.code && err.code === "P2025")
@@ -77,6 +77,7 @@ export const OpportunityController = new Elysia({
77
77
  }
78
78
  }, {
79
79
  params: OpportunityUniqueDto,
80
+ query: GetOpportunityQueryDto,
80
81
  transform: transformId,
81
82
  beforeHandle: validateId,
82
83
  response: {
@@ -291,6 +291,9 @@ export declare const GetOpportunitiesQueryDto: import("@sinclair/typebox").TObje
291
291
  page: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
292
292
  items: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
293
293
  }>;
294
+ export declare const GetOpportunityQueryDto: import("@sinclair/typebox").TObject<{
295
+ test: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
296
+ }>;
294
297
  export declare const CreateOpportunityDto: import("@sinclair/typebox").TObject<{
295
298
  chainId: import("@sinclair/typebox").TNumber;
296
299
  type: import("@sinclair/typebox").TEnum<{
@@ -347,6 +350,7 @@ export declare const UpdateOpportunityDto: import("@sinclair/typebox").TObject<{
347
350
  tags: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
348
351
  }>;
349
352
  export type GetOpportunitiesQueryModel = typeof GetOpportunitiesQueryDto.static;
353
+ export type GetOpportunityQueryModel = typeof GetOpportunityQueryDto.static;
350
354
  export type CreateOpportunityModel = typeof CreateOpportunityDto.static & {
351
355
  id: string;
352
356
  };
@@ -70,6 +70,9 @@ export const GetOpportunitiesQueryDto = t.Object({
70
70
  page: t.Optional(t.Numeric({ description: "0-indexed page number", default: 0 })),
71
71
  items: t.Optional(t.Numeric({ description: "Number of items returned by page", default: 20 })), // items per page
72
72
  });
73
+ export const GetOpportunityQueryDto = t.Object({
74
+ test: t.Optional(t.Boolean({ description: "Include test campaigns" })),
75
+ });
73
76
  export const CreateOpportunityDto = t.Object({
74
77
  chainId: t.Number(),
75
78
  type: t.Enum(CampaignType),
@@ -168,7 +168,7 @@ export declare abstract class OpportunityRepository {
168
168
  apr: number;
169
169
  dailyRewards: number;
170
170
  }) | null>;
171
- static findUniqueOrThrow(id: string): Promise<{
171
+ static findUniqueOrThrow(id: string, withTest?: boolean): Promise<{
172
172
  Chain: {
173
173
  name: string;
174
174
  id: number;
@@ -6,7 +6,7 @@ import { ProtocolService } from "../protocol";
6
6
  import { RewardService } from "../reward";
7
7
  import { TvlService } from "../tvl";
8
8
  export class OpportunityRepository {
9
- static #getRecordInclusion() {
9
+ static #getRecordInclusion(withTest = true) {
10
10
  return {
11
11
  AprRecords: {
12
12
  take: 1,
@@ -23,6 +23,11 @@ export class OpportunityRepository {
23
23
  orderBy: { timestamp: "desc" },
24
24
  include: {
25
25
  DailyRewardsBreakdown: {
26
+ where: {
27
+ Campaign: {
28
+ RewardToken: { isTest: withTest },
29
+ },
30
+ },
26
31
  include: {
27
32
  Campaign: {
28
33
  select: {
@@ -120,10 +125,10 @@ export class OpportunityRepository {
120
125
  where: { id },
121
126
  });
122
127
  }
123
- static async findUniqueOrThrow(id) {
128
+ static async findUniqueOrThrow(id, withTest = true) {
124
129
  return await apiDbClient.opportunity.findUniqueOrThrow({
125
130
  include: {
126
- ...OpportunityRepository.#getRecordInclusion(),
131
+ ...OpportunityRepository.#getRecordInclusion(withTest),
127
132
  Chain: true,
128
133
  MainProtocol: true,
129
134
  Protocols: true,
@@ -241,7 +246,7 @@ export class OpportunityRepository {
241
246
  take: items,
242
247
  skip: page * items,
243
248
  include: {
244
- ...OpportunityRepository.#getRecordInclusion(),
249
+ ...OpportunityRepository.#getRecordInclusion(test),
245
250
  MainProtocol: true,
246
251
  Chain: true,
247
252
  Protocols: true,
@@ -1,9 +1,10 @@
1
1
  import { type CreateCampaignModel } from "../campaign";
2
2
  import { Prisma } from "../../../../database/api/.generated";
3
3
  import type { ChainId, MerklChainId } from "@sdk";
4
- import type { CreateOpportunityModel, GetOpportunitiesQueryModel, LightOpportunityFromDB, OpportunityMetadata, OpportunityResourceModel, OpportunityUnique, OpportunityWithCampaignsResourceModel, UpdateOpportunityModel } from "./opportunity.model";
4
+ import type { CreateOpportunityModel, GetOpportunitiesQueryModel, LightOpportunityFromDB, OpportunityResourceModel, OpportunityUnique, OpportunityWithCampaignsResourceModel, UpdateOpportunityModel } from "./opportunity.model";
5
5
  import { OpportunityRepository } from "./opportunity.repository";
6
6
  export declare abstract class OpportunityService {
7
+ #private;
7
8
  static hashId(opportunity: OpportunityUnique): string;
8
9
  /**
9
10
  * create an opportunity without campaigns
@@ -78,15 +79,9 @@ export declare abstract class OpportunityService {
78
79
  depositUrl: any;
79
80
  tags: string[];
80
81
  }>;
81
- /**
82
- * build/fetch metadata of a campaign's opportunity
83
- * @param campaign
84
- * @returns {OpportunityMetadata}
85
- */
86
- static getMetadata(campaign: Omit<CreateCampaignModel, "id">): Promise<OpportunityMetadata>;
87
82
  static updateMetadata(chain: ChainId): Promise<void>;
88
83
  static getUniqueWithCampaignsOrThrow(opportunityId: string | OpportunityUnique): Promise<OpportunityWithCampaignsResourceModel>;
89
- static getUniqueOrThrow(opportunityId: string | OpportunityUnique): Promise<OpportunityResourceModel>;
84
+ static getUniqueOrThrow(opportunityId: string | OpportunityUnique, withTest?: boolean): Promise<OpportunityResourceModel>;
90
85
  /**
91
86
  * Get the list of opportunities satisfying the query
92
87
  * @param query
@@ -34,9 +34,56 @@ export class OpportunityService {
34
34
  const id = OpportunityService.hashId(newOpp);
35
35
  return await OpportunityRepository.create({ ...newOpp, id });
36
36
  }
37
+ /**
38
+ * build/fetch metadata of a campaign's opportunity
39
+ * @param campaign
40
+ * @returns {OpportunityMetadata}
41
+ */
42
+ static async #getMetadata(campaign) {
43
+ const campaignType = CampaignService.getTypeFromV3(campaign.type);
44
+ const campaignParams = JSON.parse(campaign.params);
45
+ const chainId = campaign.computeChainId === 0 ? campaign.chainId : campaign.computeChainId;
46
+ switch (campaignType) {
47
+ case "CLAMM":
48
+ return getClammMetadata(chainId, campaignParams);
49
+ case "ERC20":
50
+ return getErc20Metadata(chainId, campaign.chainId, // distributionChainId
51
+ campaign.campaignId, campaign.rewardTokenAddress, campaign.amount, campaignParams);
52
+ case "ERC20_SNAPSHOT":
53
+ return getErc20SnapshotMetadata(chainId, campaignParams);
54
+ case "JSON_AIRDROP":
55
+ return getJsonAirdropMetadata(chainId, campaign.creator, campaignParams);
56
+ case "SILO":
57
+ return getSiloMetadata(chainId, campaign.subType, campaignParams);
58
+ case "RADIANT":
59
+ return getRadiantMetadata(chainId, campaign.subType, campaignParams);
60
+ case "MORPHO":
61
+ return getMorphoMetadata(chainId, campaign.subType, campaignParams);
62
+ case "DOLOMITE":
63
+ return getDolomiteMetadata(chainId, campaign.subType, campaignParams);
64
+ case "BADGER":
65
+ return getBadgerMetadata(chainId, campaignParams);
66
+ case "COMPOUND":
67
+ return getCompoundMetadata(chainId, campaign.subType, campaignParams);
68
+ case "AJNA":
69
+ return getAjnaMetadata(chainId, campaign.subType, campaignParams);
70
+ case "EIGENLAYER":
71
+ return getEigenLayerMetadata(chainId, campaignParams);
72
+ case "EULER":
73
+ return getEulerMetadata(chainId, campaign.campaignId, campaign.subType, campaign.rewardTokenAddress, campaign.amount, campaignParams);
74
+ case "INVALID":
75
+ return {
76
+ name: "Invalid Campaigns",
77
+ action: OpportunityAction.INVALID,
78
+ tokens: [],
79
+ };
80
+ default:
81
+ throw "UNKNOWN CAMPAIGN TYPE";
82
+ }
83
+ }
37
84
  static async createFromCampaign(campaign, upsert = false) {
38
85
  const campaignType = CampaignService.getTypeFromV3(campaign.type);
39
- const metadata = await OpportunityService.getMetadata(campaign);
86
+ const metadata = await OpportunityService.#getMetadata(campaign);
40
87
  metadata.tags = [...((await UserService.findUnique(campaign.creator))?.tags ?? []), ...(campaign?.tags ?? [])];
41
88
  const opportunityId = OpportunityService.hashId({
42
89
  chainId: campaign.computeChainId,
@@ -89,53 +136,6 @@ export class OpportunityService {
89
136
  }, true // Upserting
90
137
  );
91
138
  }
92
- /**
93
- * build/fetch metadata of a campaign's opportunity
94
- * @param campaign
95
- * @returns {OpportunityMetadata}
96
- */
97
- static async getMetadata(campaign) {
98
- const campaignType = CampaignService.getTypeFromV3(campaign.type);
99
- const campaignParams = JSON.parse(campaign.params);
100
- const chainId = campaign.computeChainId === 0 ? campaign.chainId : campaign.computeChainId;
101
- switch (campaignType) {
102
- case "CLAMM":
103
- return getClammMetadata(chainId, campaignParams);
104
- case "ERC20":
105
- return getErc20Metadata(chainId, campaign.chainId, // distributionChainId
106
- campaign.campaignId, campaign.rewardTokenAddress, campaign.amount, campaignParams);
107
- case "ERC20_SNAPSHOT":
108
- return getErc20SnapshotMetadata(chainId, campaignParams);
109
- case "JSON_AIRDROP":
110
- return getJsonAirdropMetadata(chainId, campaign.creator, campaignParams);
111
- case "SILO":
112
- return getSiloMetadata(chainId, campaign.subType, campaignParams);
113
- case "RADIANT":
114
- return getRadiantMetadata(chainId, campaign.subType, campaignParams);
115
- case "MORPHO":
116
- return getMorphoMetadata(chainId, campaign.subType, campaignParams);
117
- case "DOLOMITE":
118
- return getDolomiteMetadata(chainId, campaign.subType, campaignParams);
119
- case "BADGER":
120
- return getBadgerMetadata(chainId, campaignParams);
121
- case "COMPOUND":
122
- return getCompoundMetadata(chainId, campaign.subType, campaignParams);
123
- case "AJNA":
124
- return getAjnaMetadata(chainId, campaign.subType, campaignParams);
125
- case "EIGENLAYER":
126
- return getEigenLayerMetadata(chainId, campaignParams);
127
- case "EULER":
128
- return getEulerMetadata(chainId, campaign.campaignId, campaign.subType, campaign.rewardTokenAddress, campaign.amount, campaignParams);
129
- case "INVALID":
130
- return {
131
- name: "Invalid Campaigns",
132
- action: OpportunityAction.INVALID,
133
- tokens: [],
134
- };
135
- default:
136
- throw "UNKNOWN CAMPAIGN TYPE";
137
- }
138
- }
139
139
  static async updateMetadata(chain) {
140
140
  try {
141
141
  const opportunities = await OpportunityRepository.findManyWithCampaigns({
@@ -163,9 +163,9 @@ export class OpportunityService {
163
163
  const formatted = OpportunityService.formatResponse(opportunity);
164
164
  return Object.assign(formatted, { campaigns: Campaigns.map(CampaignService.format) });
165
165
  }
166
- static async getUniqueOrThrow(opportunityId) {
166
+ static async getUniqueOrThrow(opportunityId, withTest = false) {
167
167
  const id = typeof opportunityId === "string" ? opportunityId : OpportunityService.hashId(opportunityId);
168
- const opportunity = await OpportunityRepository.findUniqueOrThrow(id);
168
+ const opportunity = await OpportunityRepository.findUniqueOrThrow(id, withTest);
169
169
  return OpportunityService.formatResponse(opportunity);
170
170
  }
171
171
  /**
@@ -260,7 +260,9 @@ export declare const v4: Elysia<"/v4", false, {
260
260
  params: {
261
261
  id: string;
262
262
  };
263
- query: unknown;
263
+ query: {
264
+ test?: boolean | undefined;
265
+ };
264
266
  headers: unknown;
265
267
  response: {
266
268
  200: {
@@ -2551,7 +2553,7 @@ export declare const v4: Elysia<"/v4", false, {
2551
2553
  headers: unknown;
2552
2554
  response: {
2553
2555
  200: (import("./claims").ClaimModel & {
2554
- token: import("./token").Token["model"] | null;
2556
+ token?: import("./token").Token["model"];
2555
2557
  })[];
2556
2558
  };
2557
2559
  };