@merkl/api 0.20.98 → 0.20.100

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 (26) hide show
  1. package/dist/src/eden/index.d.ts +337 -12
  2. package/dist/src/engine/campaignTVL/factory.js +2 -0
  3. package/dist/src/engine/campaignTVL/implementations/UniswapV4.d.ts +7 -0
  4. package/dist/src/engine/campaignTVL/implementations/UniswapV4.js +87 -0
  5. package/dist/src/index.d.ts +121 -4
  6. package/dist/src/modules/v4/campaign/campaign.test.controller.d.ts +36 -2
  7. package/dist/src/modules/v4/campaign/campaign.test.controller.js +2 -2
  8. package/dist/src/modules/v4/dynamicData/dynamicData.service.js +1 -11
  9. package/dist/src/modules/v4/opportunity/opportunity.controller.d.ts +36 -2
  10. package/dist/src/modules/v4/opportunity/opportunity.repository.js +2 -0
  11. package/dist/src/modules/v4/opportunity/opportunity.service.d.ts +54 -3
  12. package/dist/src/modules/v4/opportunity/opportunity.service.js +4 -1
  13. package/dist/src/modules/v4/programPayload/programPayload.controller.d.ts +1 -0
  14. package/dist/src/modules/v4/programPayload/programPayload.model.d.ts +1 -0
  15. package/dist/src/modules/v4/programPayload/programPayload.model.js +1 -0
  16. package/dist/src/modules/v4/router.d.ts +121 -4
  17. package/dist/src/modules/v4/router.js +3 -1
  18. package/dist/src/modules/v4/token/token.service.js +18 -9
  19. package/dist/src/modules/v4/turtle/turtle.controller.d.ts +68 -0
  20. package/dist/src/modules/v4/turtle/turtle.controller.js +20 -0
  21. package/dist/src/modules/v4/turtle/turtle.repository.d.ts +14 -0
  22. package/dist/src/modules/v4/turtle/turtle.repository.js +40 -0
  23. package/dist/src/modules/v4/turtle/turtle.service.d.ts +17 -0
  24. package/dist/src/modules/v4/turtle/turtle.service.js +28 -0
  25. package/dist/tsconfig.package.tsbuildinfo +1 -1
  26. package/package.json +1 -1
@@ -143,6 +143,23 @@ declare const eden: {
143
143
  fetch?: RequestInit | undefined;
144
144
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
145
145
  200: {
146
+ id: string;
147
+ name: string;
148
+ type: string;
149
+ status: import("@db/api").$Enums.Status;
150
+ tags: string[];
151
+ identifier: string;
152
+ action: import("@db/api").$Enums.OpportunityAction;
153
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
154
+ chainId: number;
155
+ depositUrl: string | null;
156
+ explorerAddress: string | null;
157
+ mainProtocolId: string | null;
158
+ tvl: number;
159
+ apr: number;
160
+ dailyRewards: number;
161
+ lastCampaignCreatedAt: Date;
162
+ } | {
146
163
  id: string;
147
164
  chainId: number;
148
165
  type: string;
@@ -169,7 +186,7 @@ declare const eden: {
169
186
  depositUrl: any;
170
187
  explorerAddress: string | undefined;
171
188
  tags: string[];
172
- };
189
+ } | null;
173
190
  }>>;
174
191
  };
175
192
  post: (body: unknown, options: {
@@ -180,6 +197,23 @@ declare const eden: {
180
197
  fetch?: RequestInit | undefined;
181
198
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
182
199
  200: {
200
+ id: string;
201
+ name: string;
202
+ type: string;
203
+ status: import("@db/api").$Enums.Status;
204
+ tags: string[];
205
+ identifier: string;
206
+ action: import("@db/api").$Enums.OpportunityAction;
207
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
208
+ chainId: number;
209
+ depositUrl: string | null;
210
+ explorerAddress: string | null;
211
+ mainProtocolId: string | null;
212
+ tvl: number;
213
+ apr: number;
214
+ dailyRewards: number;
215
+ lastCampaignCreatedAt: Date;
216
+ } | {
183
217
  id: string;
184
218
  chainId: number;
185
219
  type: string;
@@ -206,7 +240,7 @@ declare const eden: {
206
240
  depositUrl: any;
207
241
  explorerAddress: string | undefined;
208
242
  tags: string[];
209
- };
243
+ } | null;
210
244
  }>>;
211
245
  get: (options: {
212
246
  headers?: Record<string, unknown> | undefined;
@@ -1587,6 +1621,23 @@ declare const eden: {
1587
1621
  fetch?: RequestInit | undefined;
1588
1622
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
1589
1623
  200: {
1624
+ id: string;
1625
+ name: string;
1626
+ type: string;
1627
+ status: import("@db/api").$Enums.Status;
1628
+ tags: string[];
1629
+ identifier: string;
1630
+ action: import("@db/api").$Enums.OpportunityAction;
1631
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
1632
+ chainId: number;
1633
+ depositUrl: string | null;
1634
+ explorerAddress: string | null;
1635
+ mainProtocolId: string | null;
1636
+ tvl: number;
1637
+ apr: number;
1638
+ dailyRewards: number;
1639
+ lastCampaignCreatedAt: Date;
1640
+ } | {
1590
1641
  id: string;
1591
1642
  chainId: number;
1592
1643
  type: string;
@@ -1613,7 +1664,7 @@ declare const eden: {
1613
1664
  depositUrl: any;
1614
1665
  explorerAddress: string | undefined;
1615
1666
  tags: string[];
1616
- };
1667
+ } | null;
1617
1668
  }>>;
1618
1669
  get: (options: {
1619
1670
  headers: {
@@ -1626,6 +1677,23 @@ declare const eden: {
1626
1677
  fetch?: RequestInit | undefined;
1627
1678
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
1628
1679
  200: {
1680
+ id: string;
1681
+ name: string;
1682
+ type: string;
1683
+ status: import("@db/api").$Enums.Status;
1684
+ tags: string[];
1685
+ identifier: string;
1686
+ action: import("@db/api").$Enums.OpportunityAction;
1687
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
1688
+ chainId: number;
1689
+ depositUrl: string | null;
1690
+ explorerAddress: string | null;
1691
+ mainProtocolId: string | null;
1692
+ tvl: number;
1693
+ apr: number;
1694
+ dailyRewards: number;
1695
+ lastCampaignCreatedAt: Date;
1696
+ } | {
1629
1697
  id: string;
1630
1698
  chainId: number;
1631
1699
  type: string;
@@ -1652,7 +1720,7 @@ declare const eden: {
1652
1720
  depositUrl: any;
1653
1721
  explorerAddress: string | undefined;
1654
1722
  tags: string[];
1655
- };
1723
+ } | null;
1656
1724
  }>>;
1657
1725
  };
1658
1726
  };
@@ -3680,6 +3748,7 @@ declare const eden: {
3680
3748
  blacklist?: string[] | undefined;
3681
3749
  poolAddress?: string | undefined;
3682
3750
  contract?: string | undefined;
3751
+ tokenId?: string | undefined;
3683
3752
  marketId?: string | undefined;
3684
3753
  strategy?: string | undefined;
3685
3754
  poolId?: string | undefined;
@@ -4112,6 +4181,41 @@ declare const eden: {
4112
4181
  }>>;
4113
4182
  }) & {};
4114
4183
  };
4184
+ turtle: {
4185
+ tac: ((params: {
4186
+ address: string | number;
4187
+ }) => {
4188
+ get: (options?: {
4189
+ headers?: Record<string, unknown> | undefined;
4190
+ query?: Record<string, unknown> | undefined;
4191
+ fetch?: RequestInit | undefined;
4192
+ } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
4193
+ 200: {
4194
+ [x: string]: {
4195
+ vaultSymbol: string;
4196
+ balance: number;
4197
+ maxBalance: number;
4198
+ turtle: number;
4199
+ };
4200
+ };
4201
+ }>>;
4202
+ }) & {
4203
+ total: {
4204
+ get: (options?: {
4205
+ headers?: Record<string, unknown> | undefined;
4206
+ query?: Record<string, unknown> | undefined;
4207
+ fetch?: RequestInit | undefined;
4208
+ } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
4209
+ 200: {
4210
+ total: number;
4211
+ breakdown: {
4212
+ [key: string]: number;
4213
+ };
4214
+ };
4215
+ }>>;
4216
+ };
4217
+ };
4218
+ };
4115
4219
  };
4116
4220
  v3: {
4117
4221
  app: {
@@ -5000,6 +5104,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5000
5104
  };
5001
5105
  response: {
5002
5106
  200: {
5107
+ id: string;
5108
+ name: string;
5109
+ type: string;
5110
+ status: import("@db/api").$Enums.Status;
5111
+ tags: string[];
5112
+ identifier: string;
5113
+ action: import("@db/api").$Enums.OpportunityAction;
5114
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
5115
+ chainId: number;
5116
+ depositUrl: string | null;
5117
+ explorerAddress: string | null;
5118
+ mainProtocolId: string | null;
5119
+ tvl: number;
5120
+ apr: number;
5121
+ dailyRewards: number;
5122
+ lastCampaignCreatedAt: Date;
5123
+ } | {
5003
5124
  id: string;
5004
5125
  chainId: number;
5005
5126
  type: string;
@@ -5026,7 +5147,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5026
5147
  depositUrl: any;
5027
5148
  explorerAddress: string | undefined;
5028
5149
  tags: string[];
5029
- };
5150
+ } | null;
5030
5151
  };
5031
5152
  };
5032
5153
  };
@@ -5047,6 +5168,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5047
5168
  };
5048
5169
  response: {
5049
5170
  200: {
5171
+ id: string;
5172
+ name: string;
5173
+ type: string;
5174
+ status: import("@db/api").$Enums.Status;
5175
+ tags: string[];
5176
+ identifier: string;
5177
+ action: import("@db/api").$Enums.OpportunityAction;
5178
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
5179
+ chainId: number;
5180
+ depositUrl: string | null;
5181
+ explorerAddress: string | null;
5182
+ mainProtocolId: string | null;
5183
+ tvl: number;
5184
+ apr: number;
5185
+ dailyRewards: number;
5186
+ lastCampaignCreatedAt: Date;
5187
+ } | {
5050
5188
  id: string;
5051
5189
  chainId: number;
5052
5190
  type: string;
@@ -5073,7 +5211,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
5073
5211
  depositUrl: any;
5074
5212
  explorerAddress: string | undefined;
5075
5213
  tags: string[];
5076
- };
5214
+ } | null;
5077
5215
  };
5078
5216
  };
5079
5217
  };
@@ -6710,6 +6848,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
6710
6848
  };
6711
6849
  response: {
6712
6850
  200: {
6851
+ id: string;
6852
+ name: string;
6853
+ type: string;
6854
+ status: import("@db/api").$Enums.Status;
6855
+ tags: string[];
6856
+ identifier: string;
6857
+ action: import("@db/api").$Enums.OpportunityAction;
6858
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
6859
+ chainId: number;
6860
+ depositUrl: string | null;
6861
+ explorerAddress: string | null;
6862
+ mainProtocolId: string | null;
6863
+ tvl: number;
6864
+ apr: number;
6865
+ dailyRewards: number;
6866
+ lastCampaignCreatedAt: Date;
6867
+ } | {
6713
6868
  id: string;
6714
6869
  chainId: number;
6715
6870
  type: string;
@@ -6736,7 +6891,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
6736
6891
  depositUrl: any;
6737
6892
  explorerAddress: string | undefined;
6738
6893
  tags: string[];
6739
- };
6894
+ } | null;
6740
6895
  };
6741
6896
  };
6742
6897
  };
@@ -6756,6 +6911,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
6756
6911
  };
6757
6912
  response: {
6758
6913
  200: {
6914
+ id: string;
6915
+ name: string;
6916
+ type: string;
6917
+ status: import("@db/api").$Enums.Status;
6918
+ tags: string[];
6919
+ identifier: string;
6920
+ action: import("@db/api").$Enums.OpportunityAction;
6921
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
6922
+ chainId: number;
6923
+ depositUrl: string | null;
6924
+ explorerAddress: string | null;
6925
+ mainProtocolId: string | null;
6926
+ tvl: number;
6927
+ apr: number;
6928
+ dailyRewards: number;
6929
+ lastCampaignCreatedAt: Date;
6930
+ } | {
6759
6931
  id: string;
6760
6932
  chainId: number;
6761
6933
  type: string;
@@ -6782,7 +6954,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
6782
6954
  depositUrl: any;
6783
6955
  explorerAddress: string | undefined;
6784
6956
  tags: string[];
6785
- };
6957
+ } | null;
6786
6958
  };
6787
6959
  };
6788
6960
  };
@@ -9310,6 +9482,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
9310
9482
  blacklist?: string[] | undefined;
9311
9483
  poolAddress?: string | undefined;
9312
9484
  contract?: string | undefined;
9485
+ tokenId?: string | undefined;
9313
9486
  marketId?: string | undefined;
9314
9487
  strategy?: string | undefined;
9315
9488
  poolId?: string | undefined;
@@ -9868,6 +10041,54 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
9868
10041
  };
9869
10042
  };
9870
10043
  };
10044
+ } & {
10045
+ v4: {
10046
+ turtle: {
10047
+ tac: {
10048
+ total: {
10049
+ get: {
10050
+ body: unknown;
10051
+ params: {};
10052
+ query: unknown;
10053
+ headers: unknown;
10054
+ response: {
10055
+ 200: {
10056
+ total: number;
10057
+ breakdown: {
10058
+ [key: string]: number;
10059
+ };
10060
+ };
10061
+ };
10062
+ };
10063
+ };
10064
+ };
10065
+ };
10066
+ } & {
10067
+ turtle: {
10068
+ tac: {
10069
+ ":address": {
10070
+ get: {
10071
+ body: unknown;
10072
+ params: {
10073
+ address: string;
10074
+ };
10075
+ query: unknown;
10076
+ headers: unknown;
10077
+ response: {
10078
+ 200: {
10079
+ [x: string]: {
10080
+ vaultSymbol: string;
10081
+ balance: number;
10082
+ maxBalance: number;
10083
+ turtle: number;
10084
+ };
10085
+ };
10086
+ };
10087
+ };
10088
+ };
10089
+ };
10090
+ };
10091
+ };
9871
10092
  } & {
9872
10093
  v3: {
9873
10094
  app: {
@@ -10824,6 +11045,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
10824
11045
  fetch?: RequestInit | undefined;
10825
11046
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
10826
11047
  200: {
11048
+ id: string;
11049
+ name: string;
11050
+ type: string;
11051
+ status: import("@db/api").$Enums.Status;
11052
+ tags: string[];
11053
+ identifier: string;
11054
+ action: import("@db/api").$Enums.OpportunityAction;
11055
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
11056
+ chainId: number;
11057
+ depositUrl: string | null;
11058
+ explorerAddress: string | null;
11059
+ mainProtocolId: string | null;
11060
+ tvl: number;
11061
+ apr: number;
11062
+ dailyRewards: number;
11063
+ lastCampaignCreatedAt: Date;
11064
+ } | {
10827
11065
  id: string;
10828
11066
  chainId: number;
10829
11067
  type: string;
@@ -10850,7 +11088,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
10850
11088
  depositUrl: any;
10851
11089
  explorerAddress: string | undefined;
10852
11090
  tags: string[];
10853
- };
11091
+ } | null;
10854
11092
  }>>;
10855
11093
  };
10856
11094
  post: (body: unknown, options: {
@@ -10861,6 +11099,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
10861
11099
  fetch?: RequestInit | undefined;
10862
11100
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
10863
11101
  200: {
11102
+ id: string;
11103
+ name: string;
11104
+ type: string;
11105
+ status: import("@db/api").$Enums.Status;
11106
+ tags: string[];
11107
+ identifier: string;
11108
+ action: import("@db/api").$Enums.OpportunityAction;
11109
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
11110
+ chainId: number;
11111
+ depositUrl: string | null;
11112
+ explorerAddress: string | null;
11113
+ mainProtocolId: string | null;
11114
+ tvl: number;
11115
+ apr: number;
11116
+ dailyRewards: number;
11117
+ lastCampaignCreatedAt: Date;
11118
+ } | {
10864
11119
  id: string;
10865
11120
  chainId: number;
10866
11121
  type: string;
@@ -10887,7 +11142,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
10887
11142
  depositUrl: any;
10888
11143
  explorerAddress: string | undefined;
10889
11144
  tags: string[];
10890
- };
11145
+ } | null;
10891
11146
  }>>;
10892
11147
  get: (options: {
10893
11148
  headers?: Record<string, unknown> | undefined;
@@ -12268,6 +12523,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
12268
12523
  fetch?: RequestInit | undefined;
12269
12524
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
12270
12525
  200: {
12526
+ id: string;
12527
+ name: string;
12528
+ type: string;
12529
+ status: import("@db/api").$Enums.Status;
12530
+ tags: string[];
12531
+ identifier: string;
12532
+ action: import("@db/api").$Enums.OpportunityAction;
12533
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
12534
+ chainId: number;
12535
+ depositUrl: string | null;
12536
+ explorerAddress: string | null;
12537
+ mainProtocolId: string | null;
12538
+ tvl: number;
12539
+ apr: number;
12540
+ dailyRewards: number;
12541
+ lastCampaignCreatedAt: Date;
12542
+ } | {
12271
12543
  id: string;
12272
12544
  chainId: number;
12273
12545
  type: string;
@@ -12294,7 +12566,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
12294
12566
  depositUrl: any;
12295
12567
  explorerAddress: string | undefined;
12296
12568
  tags: string[];
12297
- };
12569
+ } | null;
12298
12570
  }>>;
12299
12571
  get: (options: {
12300
12572
  headers: {
@@ -12307,6 +12579,23 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
12307
12579
  fetch?: RequestInit | undefined;
12308
12580
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
12309
12581
  200: {
12582
+ id: string;
12583
+ name: string;
12584
+ type: string;
12585
+ status: import("@db/api").$Enums.Status;
12586
+ tags: string[];
12587
+ identifier: string;
12588
+ action: import("@db/api").$Enums.OpportunityAction;
12589
+ manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
12590
+ chainId: number;
12591
+ depositUrl: string | null;
12592
+ explorerAddress: string | null;
12593
+ mainProtocolId: string | null;
12594
+ tvl: number;
12595
+ apr: number;
12596
+ dailyRewards: number;
12597
+ lastCampaignCreatedAt: Date;
12598
+ } | {
12310
12599
  id: string;
12311
12600
  chainId: number;
12312
12601
  type: string;
@@ -12333,7 +12622,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
12333
12622
  depositUrl: any;
12334
12623
  explorerAddress: string | undefined;
12335
12624
  tags: string[];
12336
- };
12625
+ } | null;
12337
12626
  }>>;
12338
12627
  };
12339
12628
  };
@@ -14361,6 +14650,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
14361
14650
  blacklist?: string[] | undefined;
14362
14651
  poolAddress?: string | undefined;
14363
14652
  contract?: string | undefined;
14653
+ tokenId?: string | undefined;
14364
14654
  marketId?: string | undefined;
14365
14655
  strategy?: string | undefined;
14366
14656
  poolId?: string | undefined;
@@ -14793,6 +15083,41 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
14793
15083
  }>>;
14794
15084
  }) & {};
14795
15085
  };
15086
+ turtle: {
15087
+ tac: ((params: {
15088
+ address: string | number;
15089
+ }) => {
15090
+ get: (options?: {
15091
+ headers?: Record<string, unknown> | undefined;
15092
+ query?: Record<string, unknown> | undefined;
15093
+ fetch?: RequestInit | undefined;
15094
+ } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
15095
+ 200: {
15096
+ [x: string]: {
15097
+ vaultSymbol: string;
15098
+ balance: number;
15099
+ maxBalance: number;
15100
+ turtle: number;
15101
+ };
15102
+ };
15103
+ }>>;
15104
+ }) & {
15105
+ total: {
15106
+ get: (options?: {
15107
+ headers?: Record<string, unknown> | undefined;
15108
+ query?: Record<string, unknown> | undefined;
15109
+ fetch?: RequestInit | undefined;
15110
+ } | undefined) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
15111
+ 200: {
15112
+ total: number;
15113
+ breakdown: {
15114
+ [key: string]: number;
15115
+ };
15116
+ };
15117
+ }>>;
15118
+ };
15119
+ };
15120
+ };
14796
15121
  };
14797
15122
  v3: {
14798
15123
  app: {
@@ -1,11 +1,13 @@
1
1
  import { Campaign } from "@sdk";
2
2
  import { AjnaCampaignTVLBuilder } from "./implementations/Ajna";
3
3
  import { AmbiantCampaignTVLBuilder } from "./implementations/Ambiant";
4
+ import { UniswapV4CampaignTVLBuilder } from "./implementations/UniswapV4";
4
5
  // @dev Casts are made to enforce type safety
5
6
  // @dev A type error must be thrown if a new campaign type is added and the corresponding builder is not implemented
6
7
  const map = {
7
8
  [Campaign.AJNA]: new AjnaCampaignTVLBuilder(),
8
9
  [Campaign.AMBIENTPROCESSOR]: new AmbiantCampaignTVLBuilder(),
10
+ [Campaign.UNISWAP_V4]: new UniswapV4CampaignTVLBuilder(),
9
11
  };
10
12
  export const campaignDynamicDataBuilderFactory = (campaignType) => {
11
13
  if (!map[campaignType]) {
@@ -0,0 +1,7 @@
1
+ import { type Campaign, type CampaignParameters, type MerklChainId } from "@sdk";
2
+ import type { CampaignTVLBuilder, TVLData } from "../interface";
3
+ type campaignType = Campaign.UNISWAP_V4;
4
+ export declare class UniswapV4CampaignTVLBuilder implements CampaignTVLBuilder<campaignType> {
5
+ build(chainId: MerklChainId, campaigns: CampaignParameters<campaignType>[]): Promise<TVLData>;
6
+ }
7
+ export {};
@@ -0,0 +1,87 @@
1
+ import { BucketService } from "@/modules/v4/bucket/bucket.service";
2
+ import { TokenService } from "@/modules/v4/token/token.service";
3
+ import { engineDbClient } from "@db";
4
+ import { TvlType } from "@db/api";
5
+ import { BN2Number, ChainInteractionService, NETWORK_LABELS, } from "@sdk";
6
+ import { log } from "../../../utils/logger";
7
+ /**
8
+ * Compute TVL
9
+ * @dev important: using the most recent state save with current prices
10
+ * it's only an estimate
11
+ */
12
+ async function computeUniV4PoolTVLFromMostRecentStateSave(chainId, poolID) {
13
+ let stateSave;
14
+ let blockNumber;
15
+ let states = {};
16
+ try {
17
+ const currentBlock = await ChainInteractionService(chainId).getBlockNumber();
18
+ const mostRecentStateSave = await engineDbClient.stateSave.findFirst({
19
+ where: {
20
+ id: `UniswapV4_${chainId}_${poolID}`,
21
+ blockNumber: {
22
+ lte: currentBlock,
23
+ },
24
+ },
25
+ orderBy: {
26
+ blockNumber: "desc",
27
+ },
28
+ });
29
+ stateSave = mostRecentStateSave.state;
30
+ blockNumber = mostRecentStateSave?.blockNumber;
31
+ states = stateSave.states;
32
+ }
33
+ catch {
34
+ log.warn(`merklDynamic data - failed to read a recent state of pool ${poolID} on ${NETWORK_LABELS[chainId]}`);
35
+ return { amount0: 0n, amount1: 0n, blockNumber: blockNumber ?? 0 };
36
+ }
37
+ const { fileName } = states;
38
+ // Bucket service
39
+ let amount0 = 0n;
40
+ let amount1 = 0n;
41
+ try {
42
+ const bucket = new BucketService("merkl-production-states", "merkl-production");
43
+ const storedStates = JSON.parse(await bucket.pull(fileName));
44
+ for (const [_, { value, params: _params }] of Object.entries(storedStates)) {
45
+ amount0 += BigInt(value.amount0);
46
+ amount1 += BigInt(value.amount1);
47
+ }
48
+ }
49
+ catch {
50
+ log.warn(`merklDynamic data - failed to decode state of pool ${poolID} on ${NETWORK_LABELS[chainId]}`);
51
+ }
52
+ return { amount0, amount1, blockNumber: blockNumber };
53
+ }
54
+ export class UniswapV4CampaignTVLBuilder {
55
+ async build(chainId, campaigns) {
56
+ const tvls = [];
57
+ for (const campaign of campaigns) {
58
+ const { amount0: poolBalanceToken0, amount1: poolBalanceToken1 } = await computeUniV4PoolTVLFromMostRecentStateSave(chainId, campaign.campaignParameters.poolId);
59
+ const token0Id = TokenService.hashId({
60
+ chainId,
61
+ address: campaign.campaignParameters.currency0,
62
+ });
63
+ const token1Id = TokenService.hashId({
64
+ chainId,
65
+ address: campaign.campaignParameters.currency1,
66
+ });
67
+ tvls.push({
68
+ campaign,
69
+ tvl: (await TokenService.getValueByTokenId(token0Id, poolBalanceToken0)) +
70
+ (await TokenService.getValueByTokenId(token1Id, poolBalanceToken1)),
71
+ tvlBreakdown: [
72
+ {
73
+ identifier: token0Id,
74
+ type: TvlType.TOKEN,
75
+ value: BN2Number(poolBalanceToken0, campaign.campaignParameters.decimalsCurrency0),
76
+ },
77
+ {
78
+ identifier: token1Id,
79
+ type: TvlType.TOKEN,
80
+ value: BN2Number(poolBalanceToken1, campaign.campaignParameters.decimalsCurrency1),
81
+ },
82
+ ],
83
+ });
84
+ }
85
+ return tvls;
86
+ }
87
+ }