@merkl/api 0.10.215 → 0.10.216

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.
@@ -2084,13 +2084,15 @@ declare const eden: {
2084
2084
  claims: ((params: {
2085
2085
  address: string | number;
2086
2086
  }) => {
2087
- get: (options?: {
2087
+ get: (options: {
2088
2088
  headers?: Record<string, unknown> | undefined;
2089
- query?: Record<string, unknown> | undefined;
2089
+ query: {
2090
+ chainIds?: number[] | undefined;
2091
+ };
2090
2092
  fetch?: RequestInit | undefined;
2091
- } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
2093
+ }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
2092
2094
  200: (import("../modules/v4/claims").ClaimModel & {
2093
- token: import("../modules/v4").Token["model"];
2095
+ token: import("../modules/v4").Token["model"] | null;
2094
2096
  })[];
2095
2097
  }>>;
2096
2098
  }) & {};
@@ -2207,9 +2209,9 @@ declare const eden: {
2207
2209
  headers?: Record<string, unknown> | undefined;
2208
2210
  query: {
2209
2211
  types?: string | number | string[] | number[] | undefined;
2212
+ chainIds?: string | string[] | undefined;
2210
2213
  creatorTag?: string | undefined;
2211
2214
  live?: boolean | undefined;
2212
- chainIds?: string | string[] | undefined;
2213
2215
  hideTestTokens?: string | undefined;
2214
2216
  };
2215
2217
  fetch?: RequestInit | undefined;
@@ -2276,8 +2278,8 @@ declare const eden: {
2276
2278
  get: (options: {
2277
2279
  headers?: Record<string, unknown> | undefined;
2278
2280
  query: {
2279
- creatorTag?: string | undefined;
2280
2281
  chainIds?: string | string[] | undefined;
2282
+ creatorTag?: string | undefined;
2281
2283
  byReason?: boolean | undefined;
2282
2284
  user: string;
2283
2285
  };
@@ -2577,8 +2579,8 @@ declare const eden: {
2577
2579
  get: (options: {
2578
2580
  headers?: Record<string, unknown> | undefined;
2579
2581
  query: {
2580
- creatorTag?: string | undefined;
2581
2582
  chainIds?: string | string[] | undefined;
2583
+ creatorTag?: string | undefined;
2582
2584
  user: string;
2583
2585
  };
2584
2586
  fetch?: RequestInit | undefined;
@@ -5335,11 +5337,13 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5335
5337
  params: {
5336
5338
  address: string;
5337
5339
  };
5338
- query: unknown;
5340
+ query: {
5341
+ chainIds?: number[] | undefined;
5342
+ };
5339
5343
  headers: unknown;
5340
5344
  response: {
5341
5345
  200: (import("../modules/v4/claims").ClaimModel & {
5342
- token: import("../modules/v4").Token["model"];
5346
+ token: import("../modules/v4").Token["model"] | null;
5343
5347
  })[];
5344
5348
  };
5345
5349
  };
@@ -5495,9 +5499,9 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5495
5499
  params: {};
5496
5500
  query: {
5497
5501
  types?: string | number | string[] | number[] | undefined;
5502
+ chainIds?: string | string[] | undefined;
5498
5503
  creatorTag?: string | undefined;
5499
5504
  live?: boolean | undefined;
5500
- chainIds?: string | string[] | undefined;
5501
5505
  hideTestTokens?: string | undefined;
5502
5506
  };
5503
5507
  headers: unknown;
@@ -5589,8 +5593,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5589
5593
  body: unknown;
5590
5594
  params: {};
5591
5595
  query: {
5592
- creatorTag?: string | undefined;
5593
5596
  chainIds?: string | string[] | undefined;
5597
+ creatorTag?: string | undefined;
5594
5598
  byReason?: boolean | undefined;
5595
5599
  user: string;
5596
5600
  };
@@ -5990,8 +5994,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5990
5994
  body: unknown;
5991
5995
  params: {};
5992
5996
  query: {
5993
- creatorTag?: string | undefined;
5994
5997
  chainIds?: string | string[] | undefined;
5998
+ creatorTag?: string | undefined;
5995
5999
  user: string;
5996
6000
  };
5997
6001
  headers: unknown;
@@ -8262,13 +8266,15 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
8262
8266
  claims: ((params: {
8263
8267
  address: string | number;
8264
8268
  }) => {
8265
- get: (options?: {
8269
+ get: (options: {
8266
8270
  headers?: Record<string, unknown> | undefined;
8267
- query?: Record<string, unknown> | undefined;
8271
+ query: {
8272
+ chainIds?: number[] | undefined;
8273
+ };
8268
8274
  fetch?: RequestInit | undefined;
8269
- } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
8275
+ }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
8270
8276
  200: (import("../modules/v4/claims").ClaimModel & {
8271
- token: import("../modules/v4").Token["model"];
8277
+ token: import("../modules/v4").Token["model"] | null;
8272
8278
  })[];
8273
8279
  }>>;
8274
8280
  }) & {};
@@ -8385,9 +8391,9 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
8385
8391
  headers?: Record<string, unknown> | undefined;
8386
8392
  query: {
8387
8393
  types?: string | number | string[] | number[] | undefined;
8394
+ chainIds?: string | string[] | undefined;
8388
8395
  creatorTag?: string | undefined;
8389
8396
  live?: boolean | undefined;
8390
- chainIds?: string | string[] | undefined;
8391
8397
  hideTestTokens?: string | undefined;
8392
8398
  };
8393
8399
  fetch?: RequestInit | undefined;
@@ -8454,8 +8460,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
8454
8460
  get: (options: {
8455
8461
  headers?: Record<string, unknown> | undefined;
8456
8462
  query: {
8457
- creatorTag?: string | undefined;
8458
8463
  chainIds?: string | string[] | undefined;
8464
+ creatorTag?: string | undefined;
8459
8465
  byReason?: boolean | undefined;
8460
8466
  user: string;
8461
8467
  };
@@ -8755,8 +8761,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
8755
8761
  get: (options: {
8756
8762
  headers?: Record<string, unknown> | undefined;
8757
8763
  query: {
8758
- creatorTag?: string | undefined;
8759
8764
  chainIds?: string | string[] | undefined;
8765
+ creatorTag?: string | undefined;
8760
8766
  user: string;
8761
8767
  };
8762
8768
  fetch?: RequestInit | undefined;
@@ -2599,11 +2599,13 @@ declare const app: Elysia<"", false, {
2599
2599
  params: {
2600
2600
  address: string;
2601
2601
  };
2602
- query: unknown;
2602
+ query: {
2603
+ chainIds?: number[] | undefined;
2604
+ };
2603
2605
  headers: unknown;
2604
2606
  response: {
2605
2607
  200: (import("./modules/v4/claims").ClaimModel & {
2606
- token: import("./modules/v4").Token["model"];
2608
+ token: import("./modules/v4").Token["model"] | null;
2607
2609
  })[];
2608
2610
  };
2609
2611
  };
@@ -2759,9 +2761,9 @@ declare const app: Elysia<"", false, {
2759
2761
  params: {};
2760
2762
  query: {
2761
2763
  types?: string | number | string[] | number[] | undefined;
2764
+ chainIds?: string | string[] | undefined;
2762
2765
  creatorTag?: string | undefined;
2763
2766
  live?: boolean | undefined;
2764
- chainIds?: string | string[] | undefined;
2765
2767
  hideTestTokens?: string | undefined;
2766
2768
  };
2767
2769
  headers: unknown;
@@ -2853,8 +2855,8 @@ declare const app: Elysia<"", false, {
2853
2855
  body: unknown;
2854
2856
  params: {};
2855
2857
  query: {
2856
- creatorTag?: string | undefined;
2857
2858
  chainIds?: string | string[] | undefined;
2859
+ creatorTag?: string | undefined;
2858
2860
  byReason?: boolean | undefined;
2859
2861
  user: string;
2860
2862
  };
@@ -3254,8 +3256,8 @@ declare const app: Elysia<"", false, {
3254
3256
  body: unknown;
3255
3257
  params: {};
3256
3258
  query: {
3257
- creatorTag?: string | undefined;
3258
3259
  chainIds?: string | string[] | undefined;
3260
+ creatorTag?: string | undefined;
3259
3261
  user: string;
3260
3262
  };
3261
3263
  headers: unknown;
@@ -16,9 +16,15 @@ export declare const GetChainQueryDto: import("@sinclair/typebox").TObject<{
16
16
  export declare const ChainUniqueDto: import("@sinclair/typebox").TObject<{
17
17
  chainId: import("@sinclair/typebox").TNumber;
18
18
  }>;
19
+ export declare const ChainUniqueOptionalDto: import("@sinclair/typebox").TObject<{
20
+ chainId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
21
+ }>;
19
22
  export declare const ChainArrayDto: import("@sinclair/typebox").TObject<{
20
23
  chainId: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TArray<import("@sinclair/typebox").TNumber>]>, number[]>;
21
24
  }>;
25
+ export declare const ChainArrayOptionalDto: import("@sinclair/typebox").TObject<{
26
+ chainIds: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TArray<import("@sinclair/typebox").TNumber>]>, number[]>>;
27
+ }>;
22
28
  export declare const CreateChainExplorerDto: import("@sinclair/typebox").TObject<{
23
29
  type: import("@sinclair/typebox").TEnum<{
24
30
  ETHERSCAN: "ETHERSCAN";
@@ -12,6 +12,9 @@ export const GetChainQueryDto = t.Object({
12
12
  export const ChainUniqueDto = t.Object({
13
13
  chainId: t.Numeric(),
14
14
  });
15
+ export const ChainUniqueOptionalDto = t.Object({
16
+ chainId: t.Optional(t.Numeric()),
17
+ });
15
18
  export const ChainArrayDto = t.Object({
16
19
  chainId: t
17
20
  .Transform(t.Union([t.String(), t.Array(t.Numeric())]))
@@ -20,6 +23,14 @@ export const ChainArrayDto = t.Object({
20
23
  }, {
21
24
  description: "A required comma separated list of chain ids.<br>You can get the list of all supported chains by calling [GET /v4/chains](#tag/chains/GET/v4/chains/)",
22
25
  });
26
+ export const ChainArrayOptionalDto = t.Object({
27
+ chainIds: t.Optional(t
28
+ .Transform(t.Union([t.String(), t.Array(t.Numeric())]))
29
+ .Decode(value => (typeof value === "string" ? value.split(",").map(v => Number.parseInt(v)) : value))
30
+ .Encode(value => [...value])),
31
+ }, {
32
+ description: "A required comma separated list of chain ids.<br>You can get the list of all supported chains by calling [GET /v4/chains](#tag/chains/GET/v4/chains/)",
33
+ });
23
34
  export const CreateChainExplorerDto = t.Object({
24
35
  type: t.Enum(ExplorerType),
25
36
  chainId: t.Number(),
@@ -19,11 +19,13 @@ export declare const ClaimController: Elysia<"/claims", false, {
19
19
  params: {
20
20
  address: string;
21
21
  };
22
- query: unknown;
22
+ query: {
23
+ chainIds?: number[] | undefined;
24
+ };
23
25
  headers: unknown;
24
26
  response: {
25
27
  200: (import("./claims.model").ClaimModel & {
26
- token: import("..").Token["model"];
28
+ token: import("..").Token["model"] | null;
27
29
  })[];
28
30
  };
29
31
  };
@@ -1,13 +1,18 @@
1
- import { throwOnInvalidRequiredAddress } from "../../../utils/throw";
1
+ import { throwOnInvalidRequiredAddress, throwOnUnsupportedChainId } from "../../../utils/throw";
2
2
  import Elysia from "elysia";
3
+ import { ChainArrayOptionalDto } from "../chain";
3
4
  import { UserUniqueDto } from "../user";
4
5
  import { ClaimService } from "./claims.service";
5
6
  // ─── Claim Controller ───────────────────────────────────────────────────────
6
- export const ClaimController = new Elysia({ prefix: "/claims", detail: { tags: ["Claims"], hide: true } })
7
+ export const ClaimController = new Elysia({ prefix: "/claims", detail: { tags: ["Claims"] } })
7
8
  // ─── Get Historical Claims ────────────────────────────────────────────
8
- .get("/:address", async ({ params }) => await ClaimService.getHistoricalClaims(params), {
9
+ .get("/:address", async ({ params, query }) => await ClaimService.getHistoricalClaims(params, query.chainIds), {
9
10
  params: UserUniqueDto,
10
- beforeHandle: ({ params }) => {
11
+ query: ChainArrayOptionalDto,
12
+ beforeHandle: ({ params, query }) => {
11
13
  params.address = throwOnInvalidRequiredAddress(params.address);
14
+ for (const chainId of query?.chainIds ?? []) {
15
+ throwOnUnsupportedChainId(chainId);
16
+ }
12
17
  },
13
18
  });
@@ -1,8 +1,9 @@
1
+ import type { ChainId } from "@sdk";
1
2
  import type { Token } from "../token";
2
3
  import type { UserUniqueModel } from "../user";
3
4
  import type { ClaimModel } from "./claims.model";
4
5
  export declare abstract class ClaimService {
5
- static getHistoricalClaims(params: UserUniqueModel): Promise<(ClaimModel & {
6
- token: Token["model"];
6
+ static getHistoricalClaims(params: UserUniqueModel, chainFilter?: ChainId[]): Promise<(ClaimModel & {
7
+ token: Token["model"] | null;
7
8
  })[]>;
8
9
  }
@@ -3,27 +3,36 @@ import { RewardService } from "../reward";
3
3
  import { ClaimRepository } from "./claims.repository";
4
4
  export class ClaimService {
5
5
  // ─── Get Historical Claims ─────────────────────────────────────────────────
6
- static async getHistoricalClaims(params) {
6
+ static async getHistoricalClaims(params, chainFilter = []) {
7
7
  const roots = (await MerklRootService.fetchAll()).map(r => r.live);
8
- const rewards = await RewardService.getByRecipient(params.address, roots, true);
8
+ const rewards = await RewardService.getByRecipient(params.address, roots, true, chainFilter);
9
+ const filteredRewards = chainFilter.length
10
+ ? rewards.filter(reward => chainFilter.includes(reward.RewardToken.chainId))
11
+ : rewards;
9
12
  const chainIds = [];
10
- for (const reward of rewards) {
13
+ for (const reward of filteredRewards) {
11
14
  if (!chainIds.includes(reward.RewardToken.chainId)) {
12
15
  chainIds.push(reward.RewardToken.chainId);
13
16
  }
14
17
  }
15
- const tokens = rewards.reduce((acc, reward) => {
18
+ const tokens = filteredRewards.reduce((acc, reward) => {
16
19
  acc[reward.RewardToken.address.toLowerCase()] = reward.RewardToken;
17
20
  return acc;
18
21
  }, {});
19
22
  const promises = await Promise.allSettled(chainIds.map(chainId => ClaimRepository.fetch(chainId, params.address)));
20
- const claims = await promises
23
+ const claims = promises
21
24
  .filter(p => p.status === "fulfilled")
22
- .flatMap(p => p.value)
25
+ .flatMap(p => p.value ?? []) // null/undefined claim arrays
26
+ .filter(claim => {
27
+ // Ensure the claim's token exists and matches the chainFilter
28
+ const token = claim?.token ? tokens[claim.token.toLowerCase()] : null;
29
+ return token && (!chainFilter.length || chainFilter.includes(token.chainId));
30
+ })
23
31
  .map(claim => {
32
+ const token = claim?.token ? tokens[claim.token.toLowerCase()] : null;
24
33
  return {
25
34
  ...claim,
26
- token: tokens[claim.token.toLowerCase()],
35
+ token,
27
36
  };
28
37
  });
29
38
  return claims.sort((a, b) => Number(b.timestamp) - Number(a.timestamp));
@@ -1,9 +1,10 @@
1
1
  import type { Prisma } from "../../../../database/api/.generated";
2
+ import type { ChainId } from "@sdk";
2
3
  import type { BreakdownForCampaignsRaw, CampaignIdModel, CampaignIdWithoutPageModel, CreateManyBreakdownModel, CreateManyRewardModel, PendingEntity } from "./reward.model";
3
4
  export declare abstract class RewardRepository {
4
5
  static createManyReward(rewards: CreateManyRewardModel): Promise<Prisma.BatchPayload>;
5
6
  static createManyBreakdown(data: CreateManyBreakdownModel): Promise<Prisma.BatchPayload>;
6
- static getByRecipient(recipient: string, roots: string[], withToken: boolean): Promise<({
7
+ static getByRecipient(recipient: string, roots: string[], withToken: boolean, chainFilter?: ChainId[]): Promise<({
7
8
  RewardToken: {
8
9
  symbol: string;
9
10
  name: string | null;
@@ -52,13 +52,14 @@ export class RewardRepository {
52
52
  data: breakdownsToCreate,
53
53
  });
54
54
  }
55
- static async getByRecipient(recipient, roots, withToken) {
55
+ static async getByRecipient(recipient, roots, withToken, chainFilter) {
56
56
  return await apiDbClient.reward.findMany({
57
57
  where: {
58
58
  root: {
59
59
  in: roots,
60
60
  },
61
61
  recipient,
62
+ ...(!!chainFilter?.length ? { RewardToken: { chainId: { in: chainFilter } } } : undefined),
62
63
  },
63
64
  include: {
64
65
  Breakdown: {
@@ -156,7 +156,7 @@ export declare abstract class RewardService {
156
156
  proofs: string[];
157
157
  }[];
158
158
  static createManyBreakdown(data: CreateManyBreakdownModel): Promise<import("../../../../database/api/.generated").Prisma.BatchPayload | undefined>;
159
- static getByRecipient(recipient: string, roots: string[], withToken?: boolean): Promise<({
159
+ static getByRecipient(recipient: string, roots: string[], withToken?: boolean, chainFilter?: ChainId[]): Promise<({
160
160
  RewardToken: {
161
161
  symbol: string;
162
162
  name: string | null;
@@ -83,8 +83,8 @@ export class RewardService {
83
83
  log.error(`createManyBreakdown - error creating many breakdowns for campaigns ${foundCampaigns.join(", ")}`, e);
84
84
  }
85
85
  }
86
- static async getByRecipient(recipient, roots, withToken = false) {
87
- return await RewardRepository.getByRecipient(recipient, roots, withToken);
86
+ static async getByRecipient(recipient, roots, withToken = false, chainFilter) {
87
+ return RewardRepository.getByRecipient(recipient, roots, withToken, chainFilter);
88
88
  }
89
89
  /**
90
90
  * Groups a breakdown array by their corresponding opportunities
@@ -174,7 +174,9 @@ export class RewardService {
174
174
  }
175
175
  static async getUserRewardsByChain(user, withToken, chainFilter = [], connectedChainId = null) {
176
176
  const chains = await ChainService.findMany();
177
- let chainIds = chains.map(({ id }) => id).filter(id => !chainFilter.length || chainFilter.includes(id));
177
+ let chainIds = !chainFilter || !chainFilter.length
178
+ ? chains.map(({ id }) => id)
179
+ : chains.map(({ id }) => id).filter(id => chainFilter.includes(id));
178
180
  /** Check if the user is blacklisted */
179
181
  const isBlacklisted = !!(await BlacklistService.isBlacklisted(user));
180
182
  const res = [];
@@ -2477,11 +2477,13 @@ export declare const v4: Elysia<"/v4", false, {
2477
2477
  params: {
2478
2478
  address: string;
2479
2479
  };
2480
- query: unknown;
2480
+ query: {
2481
+ chainIds?: number[] | undefined;
2482
+ };
2481
2483
  headers: unknown;
2482
2484
  response: {
2483
2485
  200: (import("./claims").ClaimModel & {
2484
- token: import("./token").Token["model"];
2486
+ token: import("./token").Token["model"] | null;
2485
2487
  })[];
2486
2488
  };
2487
2489
  };
@@ -26,9 +26,9 @@ declare const _default: (app: Elysia) => Elysia<"", false, {
26
26
  params: {};
27
27
  query: {
28
28
  types?: string | number | string[] | number[] | undefined;
29
+ chainIds?: string | string[] | undefined;
29
30
  creatorTag?: string | undefined;
30
31
  live?: boolean | undefined;
31
- chainIds?: string | string[] | undefined;
32
32
  hideTestTokens?: string | undefined;
33
33
  };
34
34
  headers: unknown;
@@ -23,8 +23,8 @@ declare const _default: (app: Elysia) => Elysia<"", false, {
23
23
  body: unknown;
24
24
  params: {};
25
25
  query: {
26
- creatorTag?: string | undefined;
27
26
  chainIds?: string | string[] | undefined;
27
+ creatorTag?: string | undefined;
28
28
  byReason?: boolean | undefined;
29
29
  user: string;
30
30
  };
@@ -22,8 +22,8 @@ declare const _default: (app: Elysia) => Elysia<"", false, {
22
22
  body: unknown;
23
23
  params: {};
24
24
  query: {
25
- creatorTag?: string | undefined;
26
25
  chainIds?: string | string[] | undefined;
26
+ creatorTag?: string | undefined;
27
27
  user: string;
28
28
  };
29
29
  headers: unknown;
@@ -87,9 +87,9 @@ export declare const v3: Elysia<"/v3", false, {
87
87
  params: {};
88
88
  query: {
89
89
  types?: string | number | string[] | number[] | undefined;
90
+ chainIds?: string | string[] | undefined;
90
91
  creatorTag?: string | undefined;
91
92
  live?: boolean | undefined;
92
- chainIds?: string | string[] | undefined;
93
93
  hideTestTokens?: string | undefined;
94
94
  };
95
95
  headers: unknown;
@@ -181,8 +181,8 @@ export declare const v3: Elysia<"/v3", false, {
181
181
  body: unknown;
182
182
  params: {};
183
183
  query: {
184
- creatorTag?: string | undefined;
185
184
  chainIds?: string | string[] | undefined;
185
+ creatorTag?: string | undefined;
186
186
  byReason?: boolean | undefined;
187
187
  user: string;
188
188
  };
@@ -582,8 +582,8 @@ export declare const v3: Elysia<"/v3", false, {
582
582
  body: unknown;
583
583
  params: {};
584
584
  query: {
585
- creatorTag?: string | undefined;
586
585
  chainIds?: string | string[] | undefined;
586
+ creatorTag?: string | undefined;
587
587
  user: string;
588
588
  };
589
589
  headers: unknown;