@merkl/api 0.20.52 → 0.20.53

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.
@@ -14,9 +14,18 @@ export class AccountingRepository {
14
14
  where: {
15
15
  fromTokenId,
16
16
  NOT: {
17
- recipient: {
18
- equals: apiDbClient.dump.fields.multisig,
19
- },
17
+ OR: [
18
+ {
19
+ recipient: {
20
+ equals: apiDbClient.dump.fields.multisig,
21
+ },
22
+ },
23
+ {
24
+ recipient: {
25
+ equals: "0xb08AB4332AD871F89da24df4751968A61e58013c",
26
+ },
27
+ },
28
+ ],
20
29
  },
21
30
  },
22
31
  });
@@ -38,9 +47,18 @@ export class AccountingRepository {
38
47
  static async getForMultisigBetweenDates(startDate, endDate) {
39
48
  return await apiDbClient.dump.findMany({
40
49
  where: {
41
- recipient: {
42
- equals: apiDbClient.dump.fields.multisig,
43
- },
50
+ OR: [
51
+ {
52
+ recipient: {
53
+ equals: apiDbClient.dump.fields.multisig,
54
+ },
55
+ },
56
+ {
57
+ recipient: {
58
+ equals: "0xb08AB4332AD871F89da24df4751968A61e58013c",
59
+ },
60
+ },
61
+ ],
44
62
  datetime: {
45
63
  gte: startDate,
46
64
  lt: endDate,
@@ -51,9 +69,18 @@ export class AccountingRepository {
51
69
  static async getForMultisig() {
52
70
  return await apiDbClient.dump.findMany({
53
71
  where: {
54
- recipient: {
55
- equals: apiDbClient.dump.fields.multisig,
56
- },
72
+ OR: [
73
+ {
74
+ recipient: {
75
+ equals: apiDbClient.dump.fields.multisig,
76
+ },
77
+ },
78
+ {
79
+ recipient: {
80
+ equals: "0xb08AB4332AD871F89da24df4751968A61e58013c",
81
+ },
82
+ },
83
+ ],
57
84
  },
58
85
  });
59
86
  }
@@ -61,9 +88,18 @@ export class AccountingRepository {
61
88
  return await apiDbClient.dump.findMany({
62
89
  where: {
63
90
  chainId,
64
- recipient: {
65
- equals: apiDbClient.dump.fields.multisig,
66
- },
91
+ OR: [
92
+ {
93
+ recipient: {
94
+ equals: apiDbClient.dump.fields.multisig,
95
+ },
96
+ },
97
+ {
98
+ recipient: {
99
+ equals: "0xb08AB4332AD871F89da24df4751968A61e58013c",
100
+ },
101
+ },
102
+ ],
67
103
  },
68
104
  });
69
105
  }
@@ -75,9 +111,18 @@ export class AccountingRepository {
75
111
  gte: startDate,
76
112
  lte: endDate,
77
113
  },
78
- recipient: {
79
- equals: apiDbClient.dump.fields.multisig,
80
- },
114
+ OR: [
115
+ {
116
+ recipient: {
117
+ equals: apiDbClient.dump.fields.multisig,
118
+ },
119
+ },
120
+ {
121
+ recipient: {
122
+ equals: "0xb08AB4332AD871F89da24df4751968A61e58013c",
123
+ },
124
+ },
125
+ ],
81
126
  },
82
127
  });
83
128
  }
@@ -90,9 +135,18 @@ export class AccountingRepository {
90
135
  lte: endDate,
91
136
  },
92
137
  NOT: {
93
- recipient: {
94
- equals: apiDbClient.dump.fields.multisig,
95
- },
138
+ OR: [
139
+ {
140
+ recipient: {
141
+ equals: apiDbClient.dump.fields.multisig,
142
+ },
143
+ },
144
+ {
145
+ recipient: {
146
+ equals: "0xb08AB4332AD871F89da24df4751968A61e58013c",
147
+ },
148
+ },
149
+ ],
96
150
  },
97
151
  },
98
152
  });
@@ -4900,26 +4900,83 @@ export declare const v4: Elysia<"/v4", false, {
4900
4900
  get: {
4901
4901
  body: unknown;
4902
4902
  params: {};
4903
- query: {
4903
+ query: unknown;
4904
+ headers: unknown;
4905
+ response: {
4906
+ 200: {
4907
+ [x: string]: {
4908
+ [poolId: string]: UniswapV4PoolType;
4909
+ } | undefined;
4910
+ };
4911
+ };
4912
+ };
4913
+ };
4914
+ };
4915
+ } & {
4916
+ v4pools: {
4917
+ ":chainId": {
4918
+ get: {
4919
+ body: unknown;
4920
+ params: {
4904
4921
  chainId: number;
4905
4922
  };
4923
+ query: unknown;
4906
4924
  headers: unknown;
4907
4925
  response: {
4908
4926
  200: {
4909
- [x: string]: {
4910
- poolId: string;
4911
- poolKey: {
4912
- hooks: string;
4913
- fee: number;
4914
- tickSpacing: number;
4915
- currency0: string;
4916
- currency1: string;
4917
- };
4918
- decimalsCurrency0: number;
4919
- decimalsCurrency1: number;
4920
- symbolCurrency0: string;
4921
- symbolCurrency1: string;
4922
- };
4927
+ [x: string]: any;
4928
+ };
4929
+ };
4930
+ };
4931
+ };
4932
+ };
4933
+ } & {
4934
+ v4: {
4935
+ ":poolId": {
4936
+ get: {
4937
+ body: unknown;
4938
+ params: {
4939
+ poolId: string;
4940
+ };
4941
+ query: unknown;
4942
+ headers: unknown;
4943
+ response: {
4944
+ 200: UniswapV4PoolType[];
4945
+ };
4946
+ };
4947
+ };
4948
+ };
4949
+ } & {
4950
+ v4: {
4951
+ update: {
4952
+ post: {
4953
+ body: unknown;
4954
+ params: {};
4955
+ query: unknown;
4956
+ headers: {
4957
+ authorization: string;
4958
+ };
4959
+ response: {
4960
+ 200: void;
4961
+ };
4962
+ };
4963
+ };
4964
+ };
4965
+ } & {
4966
+ v4: {
4967
+ update: {
4968
+ ":chainId": {
4969
+ post: {
4970
+ body: unknown;
4971
+ params: {
4972
+ chainId: number;
4973
+ };
4974
+ query: unknown;
4975
+ headers: {
4976
+ authorization: string;
4977
+ };
4978
+ response: {
4979
+ 200: void;
4923
4980
  };
4924
4981
  };
4925
4982
  };
@@ -36,26 +36,83 @@ export declare const UniswapController: Elysia<"uniswap", false, {
36
36
  get: {
37
37
  body: unknown;
38
38
  params: {};
39
- query: {
39
+ query: unknown;
40
+ headers: unknown;
41
+ response: {
42
+ 200: {
43
+ [x: string]: {
44
+ [poolId: string]: UniswapV4PoolType;
45
+ } | undefined;
46
+ };
47
+ };
48
+ };
49
+ };
50
+ };
51
+ } & {
52
+ v4pools: {
53
+ ":chainId": {
54
+ get: {
55
+ body: unknown;
56
+ params: {
40
57
  chainId: number;
41
58
  };
59
+ query: unknown;
42
60
  headers: unknown;
43
61
  response: {
44
62
  200: {
45
- [x: string]: {
46
- poolId: string;
47
- poolKey: {
48
- hooks: string;
49
- fee: number;
50
- tickSpacing: number;
51
- currency0: string;
52
- currency1: string;
53
- };
54
- decimalsCurrency0: number;
55
- decimalsCurrency1: number;
56
- symbolCurrency0: string;
57
- symbolCurrency1: string;
58
- };
63
+ [x: string]: any;
64
+ };
65
+ };
66
+ };
67
+ };
68
+ };
69
+ } & {
70
+ v4: {
71
+ ":poolId": {
72
+ get: {
73
+ body: unknown;
74
+ params: {
75
+ poolId: string;
76
+ };
77
+ query: unknown;
78
+ headers: unknown;
79
+ response: {
80
+ 200: UniswapV4PoolType[];
81
+ };
82
+ };
83
+ };
84
+ };
85
+ } & {
86
+ v4: {
87
+ update: {
88
+ post: {
89
+ body: unknown;
90
+ params: {};
91
+ query: unknown;
92
+ headers: {
93
+ authorization: string;
94
+ };
95
+ response: {
96
+ 200: void;
97
+ };
98
+ };
99
+ };
100
+ };
101
+ } & {
102
+ v4: {
103
+ update: {
104
+ ":chainId": {
105
+ post: {
106
+ body: unknown;
107
+ params: {
108
+ chainId: number;
109
+ };
110
+ query: unknown;
111
+ headers: {
112
+ authorization: string;
113
+ };
114
+ response: {
115
+ 200: void;
59
116
  };
60
117
  };
61
118
  };
@@ -1,6 +1,11 @@
1
+ import { AuthorizationHeadersDto, BackOfficeGuard } from "@/guards/BackOffice.guard";
2
+ import { UnsupportedNetwork } from "@/utils/error";
1
3
  import { throwOnInvalidAddress, throwOnInvalidRequiredAddress } from "@/utils/throw";
2
4
  import Elysia, { t } from "elysia";
3
- import { RewardsPerV3PositionDto } from "./uniswap.model";
5
+ import { CacheService } from "../cache";
6
+ import { TTLPresets } from "../cache/cache.model";
7
+ import { ChainUniqueDto } from "../chain/chain.model";
8
+ import { Bytes32Dto, RewardsPerV3PositionDto, UniV4ChainIdArray, UniswapV4PoolDto, } from "./uniswap.model";
4
9
  import { UniswapService } from "./uniswap.service";
5
10
  export const UniswapController = new Elysia({
6
11
  prefix: "uniswap",
@@ -21,14 +26,52 @@ export const UniswapController = new Elysia({
21
26
  });
22
27
  })
23
28
  .group("/v4", app => {
24
- return app.get("/pools", async ({ query }) => {
25
- return await UniswapService.getPoolsByChain(query.chainId);
29
+ return app
30
+ .get(
31
+ // TODO: add pagination
32
+ "/pools", async () => {
33
+ return await CacheService.wrap(TTLPresets.DAY_1, UniswapService.getUniswapV4Pools);
26
34
  }, {
27
- query: t.Object({
28
- chainId: t.Numeric(),
29
- }),
30
35
  detail: {
31
36
  description: "Get Uniswap V4 pools by chain",
32
37
  },
38
+ })
39
+ .get("pools/:chainId", async ({ params }) => {
40
+ return ((await CacheService.wrap(TTLPresets.DAY_1, UniswapService.getUniswapV4Pools))[params.chainId] ?? {});
41
+ }, {
42
+ params: ChainUniqueDto,
43
+ beforeHandle: ({ params }) => {
44
+ if (!UniV4ChainIdArray.includes(params.chainId))
45
+ throw new UnsupportedNetwork(params.chainId);
46
+ },
47
+ response: t.Record(t.String(), // poolId
48
+ UniswapV4PoolDto),
49
+ })
50
+ .get("/:poolId", async ({ params }) => {
51
+ return Object.values(await CacheService.wrap(TTLPresets.DAY_1, UniswapService.getUniswapV4Pools))
52
+ .flatMap(x => (x ? Object.values(x) : []))
53
+ .filter(p => p.poolId === params.poolId);
54
+ }, {
55
+ params: Bytes32Dto,
56
+ response: t.Array(UniswapV4PoolDto),
57
+ })
58
+ .post("/update", async () => {
59
+ await CacheService.set(TTLPresets.DAY_1, UniswapService.getUniswapV4Pools);
60
+ }, {
61
+ headers: AuthorizationHeadersDto,
62
+ beforeHandle: BackOfficeGuard,
63
+ detail: { hide: true },
64
+ })
65
+ .post("/update/:chainId", async ({ params }) => {
66
+ await CacheService.set(TTLPresets.DAY_1, UniswapService.getUniswapV4Pools, params.chainId);
67
+ }, {
68
+ params: ChainUniqueDto,
69
+ headers: AuthorizationHeadersDto,
70
+ beforeHandle: async ({ params, headers }) => {
71
+ await BackOfficeGuard({ headers });
72
+ if (!UniV4ChainIdArray.includes(params.chainId))
73
+ throw new UnsupportedNetwork(params.chainId);
74
+ },
75
+ detail: { hide: true },
33
76
  });
34
77
  });
@@ -1,6 +1,32 @@
1
1
  import type { apiDbClient } from "@db";
2
2
  import type { Prisma } from "@db/api";
3
- import type { MerklChainId, UniswapV4PoolType } from "@sdk";
3
+ import { type MerklChainId, type UniswapV4PoolType } from "@sdk";
4
+ export declare const UniV4ChainIdArray: MerklChainId[];
5
+ export declare enum LoggedEntityType {
6
+ EULER = "EULER_VAULT",
7
+ UNISWAP_V4 = "UNISWAP_V4"
8
+ }
9
+ export type UniV4ChainId = (typeof UniV4ChainIdArray)[number];
10
+ export type UniswapV4PoolsReturnType = {
11
+ [chainId in MerklChainId]?: {
12
+ [poolId: string]: UniswapV4PoolType;
13
+ };
14
+ };
15
+ export type LoggedCreateBody = Prisma.Args<typeof apiDbClient.logged, "createMany">["data"];
16
+ export declare const UniswapV4PoolDto: import("@sinclair/typebox").TObject<{
17
+ chainId: import("@sinclair/typebox").TNumber;
18
+ currency0: import("@sinclair/typebox").TString;
19
+ currency1: import("@sinclair/typebox").TString;
20
+ decimalsCurrency0: import("@sinclair/typebox").TNumber;
21
+ decimalsCurrency1: import("@sinclair/typebox").TNumber;
22
+ hooks: import("@sinclair/typebox").TString;
23
+ fetchedAtBlock: import("@sinclair/typebox").TNumber;
24
+ lpFee: import("@sinclair/typebox").TNumber;
25
+ poolId: import("@sinclair/typebox").TString;
26
+ symbolCurrency0: import("@sinclair/typebox").TString;
27
+ symbolCurrency1: import("@sinclair/typebox").TString;
28
+ tickSpacing: import("@sinclair/typebox").TNumber;
29
+ }>;
4
30
  export declare const Bytes32Dto: import("@sinclair/typebox").TObject<{
5
31
  poolId: import("@sinclair/typebox").TRegExp;
6
32
  }>;
@@ -10,24 +36,17 @@ export declare const RewardsPerV3PositionDto: import("@sinclair/typebox").TObjec
10
36
  positionId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
11
37
  }>;
12
38
  export declare const UniswapV4PoolsDto: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TObject<{
13
- poolKey: import("@sinclair/typebox").TObject<{
14
- currency0: import("@sinclair/typebox").TString;
15
- currency1: import("@sinclair/typebox").TString;
16
- fee: import("@sinclair/typebox").TNumber;
17
- tickSpacing: import("@sinclair/typebox").TNumber;
18
- hooks: import("@sinclair/typebox").TString;
19
- }>;
20
- poolId: import("@sinclair/typebox").TString;
39
+ chainId: import("@sinclair/typebox").TNumber;
40
+ currency0: import("@sinclair/typebox").TString;
41
+ currency1: import("@sinclair/typebox").TString;
21
42
  decimalsCurrency0: import("@sinclair/typebox").TNumber;
22
43
  decimalsCurrency1: import("@sinclair/typebox").TNumber;
44
+ hooks: import("@sinclair/typebox").TString;
45
+ fetchedAtBlock: import("@sinclair/typebox").TNumber;
46
+ lpFee: import("@sinclair/typebox").TNumber;
47
+ poolId: import("@sinclair/typebox").TString;
23
48
  symbolCurrency0: import("@sinclair/typebox").TString;
24
49
  symbolCurrency1: import("@sinclair/typebox").TString;
50
+ tickSpacing: import("@sinclair/typebox").TNumber;
25
51
  }>>;
26
- export type UniswapV4PoolsReturnType = {
27
- [chainId in MerklChainId]?: {
28
- [poolId: string]: UniswapV4PoolType;
29
- };
30
- };
31
- export type UniswapV4PoolsEntity = typeof UniswapV4PoolsDto.static;
32
- export type LoggedCreateBody = Prisma.Args<typeof apiDbClient.logged, "createMany">["data"];
33
52
  export type RewardsPerPositionModel = typeof RewardsPerV3PositionDto.static;
@@ -1,18 +1,32 @@
1
+ import { UniswapV4Addresses } from "@sdk";
1
2
  import { t } from "elysia";
2
- const UniswapV4PoolKeyDto = t.Object({
3
+ export const UniV4ChainIdArray = Object.keys(UniswapV4Addresses).map((x) => Number(x));
4
+ export var LoggedEntityType;
5
+ (function (LoggedEntityType) {
6
+ LoggedEntityType["EULER"] = "EULER_VAULT";
7
+ LoggedEntityType["UNISWAP_V4"] = "UNISWAP_V4";
8
+ })(LoggedEntityType || (LoggedEntityType = {}));
9
+ // DTOs
10
+ // const UniswapV4PoolKeyDto = t.Object({
11
+ // currency0: t.String(),
12
+ // currency1: t.String(),
13
+ // fee: t.Numeric(),
14
+ // tickSpacing: t.Numeric(),
15
+ // hooks: t.String(),
16
+ // });
17
+ export const UniswapV4PoolDto = t.Object({
18
+ chainId: t.Numeric(), // Assuming MerklChainId is a numeric type
3
19
  currency0: t.String(),
4
20
  currency1: t.String(),
5
- fee: t.Numeric(),
6
- tickSpacing: t.Numeric(),
7
- hooks: t.String(),
8
- });
9
- const UniswapV4PoolDto = t.Object({
10
- poolKey: UniswapV4PoolKeyDto,
11
- poolId: t.String(),
12
21
  decimalsCurrency0: t.Numeric(),
13
22
  decimalsCurrency1: t.Numeric(),
23
+ hooks: t.String(),
24
+ fetchedAtBlock: t.Numeric(),
25
+ lpFee: t.Numeric(),
26
+ poolId: t.String(),
14
27
  symbolCurrency0: t.String(),
15
28
  symbolCurrency1: t.String(),
29
+ tickSpacing: t.Numeric(),
16
30
  });
17
31
  export const Bytes32Dto = t.Object({
18
32
  poolId: t.RegExp(/^0x[a-fA-F0-9]{64}$/, {
@@ -1,6 +1,6 @@
1
- import type { LoggedCreateBody } from "./uniswap.model";
1
+ import type { LoggedCreateBody, UniV4ChainId } from "./uniswap.model";
2
2
  export declare abstract class UniswapRepository {
3
- static getStoredPools(): Promise<{
3
+ static getStoredUniswapV4Pools(chainId?: UniV4ChainId): Promise<{
4
4
  id: string;
5
5
  type: import("@db/api").$Enums.LoggedEntityType;
6
6
  address: string | null;
@@ -1,9 +1,9 @@
1
1
  import { apiDbClient } from "@db";
2
2
  import { LoggedEntityType } from "@db/api";
3
3
  export class UniswapRepository {
4
- static async getStoredPools() {
4
+ static async getStoredUniswapV4Pools(chainId) {
5
5
  return await apiDbClient.logged.findMany({
6
- where: { type: LoggedEntityType.UNISWAP_V4 },
6
+ where: { type: LoggedEntityType.UNISWAP_V4, ...(!!chainId && { chainId: chainId }) },
7
7
  });
8
8
  }
9
9
  static async createMany(data) {
@@ -1,23 +1,8 @@
1
1
  import { type MerklChainId } from "@sdk";
2
- import type { RewardsPerPositionModel, UniswapV4PoolsReturnType } from "./uniswap.model";
3
- export declare const PoolManagerInterface: any;
2
+ import { type RewardsPerPositionModel, type UniV4ChainId, type UniswapV4PoolsReturnType } from "./uniswap.model";
4
3
  export declare abstract class UniswapService {
5
4
  static findV3RewardsPerPosition(query: RewardsPerPositionModel): Promise<Record<string, Record<string, any[]>>>;
6
- static getPoolsByChain(chainId: MerklChainId): Promise<{
7
- [x: string]: {
8
- poolId: string;
9
- poolKey: {
10
- hooks: string;
11
- fee: number;
12
- tickSpacing: number;
13
- currency0: string;
14
- currency1: string;
15
- };
16
- decimalsCurrency0: number;
17
- decimalsCurrency1: number;
18
- symbolCurrency0: string;
19
- symbolCurrency1: string;
20
- };
21
- }>;
22
- static getPools(): Promise<UniswapV4PoolsReturnType>;
5
+ static getUniswapV4Pools(chainId?: UniV4ChainId): Promise<UniswapV4PoolsReturnType>;
6
+ /** @deprecated */
7
+ static getUniswapV4PoolsForChain(chainId: MerklChainId): Promise<UniswapV4PoolsReturnType>;
23
8
  }