@defisaver/positions-sdk 2.1.174 → 2.1.175-looping-2-dev-dev

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 (249) hide show
  1. package/cjs/aaveV2/index.d.ts +4 -4
  2. package/cjs/aaveV2/index.js +7 -7
  3. package/cjs/aaveV3/index.d.ts +5 -14
  4. package/cjs/aaveV3/index.js +14 -10
  5. package/cjs/aaveV3/merkl.d.ts +5 -1
  6. package/cjs/aaveV3/merkl.js +8 -3
  7. package/cjs/aaveV3/sgho.d.ts +2 -16
  8. package/cjs/aaveV4/index.d.ts +4 -3
  9. package/cjs/aaveV4/index.js +19 -16
  10. package/cjs/aaveV4/lend.d.ts +2 -43
  11. package/cjs/aaveV4/merkl.d.ts +10 -2
  12. package/cjs/aaveV4/merkl.js +15 -6
  13. package/cjs/claiming/aaveV3.d.ts +3 -3
  14. package/cjs/claiming/aaveV3.js +5 -4
  15. package/cjs/claiming/ethena.d.ts +2 -1
  16. package/cjs/claiming/king.d.ts +3 -2
  17. package/cjs/claiming/king.js +3 -2
  18. package/cjs/claiming/spark.d.ts +4 -4
  19. package/cjs/claiming/spark.js +8 -7
  20. package/cjs/claiming/uniswap.d.ts +2 -2
  21. package/cjs/claiming/uniswap.js +3 -2
  22. package/cjs/compoundV2/index.d.ts +4 -4
  23. package/cjs/compoundV2/index.js +9 -9
  24. package/cjs/compoundV3/index.d.ts +5 -4
  25. package/cjs/compoundV3/index.js +17 -13
  26. package/cjs/compoundV3/merkl.d.ts +1 -1
  27. package/cjs/compoundV3/merkl.js +2 -5
  28. package/cjs/curveUsd/index.d.ts +5 -5
  29. package/cjs/curveUsd/index.js +17 -17
  30. package/cjs/fluid/index.d.ts +23 -66
  31. package/cjs/fluid/index.js +75 -72
  32. package/cjs/fluid/merkl.d.ts +5 -3
  33. package/cjs/fluid/merkl.js +11 -6
  34. package/cjs/helpers/aaveHelpers/index.js +1 -1
  35. package/cjs/helpers/aaveV4Helpers/index.js +14 -2
  36. package/cjs/helpers/compoundHelpers/index.js +2 -2
  37. package/cjs/helpers/curveUsdHelpers/index.js +1 -1
  38. package/cjs/helpers/fluidHelpers/index.js +1 -1
  39. package/cjs/helpers/liquityV2Helpers/index.js +1 -1
  40. package/cjs/helpers/llamaLendHelpers/index.js +1 -1
  41. package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
  42. package/cjs/helpers/morphoMidnightHelpers/index.js +1 -1
  43. package/cjs/helpers/sparkHelpers/index.js +1 -1
  44. package/cjs/liquity/index.d.ts +5 -15
  45. package/cjs/liquity/index.js +23 -23
  46. package/cjs/liquityV2/index.d.ts +16 -31
  47. package/cjs/liquityV2/index.js +96 -78
  48. package/cjs/llamaLend/index.d.ts +5 -5
  49. package/cjs/llamaLend/index.js +13 -13
  50. package/cjs/maker/index.d.ts +6 -6
  51. package/cjs/maker/index.js +16 -16
  52. package/cjs/moneymarket/moneymarketCommonService.js +13 -2
  53. package/cjs/morphoBlue/index.d.ts +7 -7
  54. package/cjs/morphoBlue/index.js +28 -26
  55. package/cjs/morphoBlue/merkl.d.ts +5 -3
  56. package/cjs/morphoBlue/merkl.js +6 -8
  57. package/cjs/morphoMidnight/index.d.ts +5 -5
  58. package/cjs/morphoMidnight/index.js +18 -18
  59. package/cjs/portfolio/customDeFiData.d.ts +3 -0
  60. package/cjs/portfolio/customDeFiData.js +267 -0
  61. package/cjs/portfolio/index.d.ts +17 -8
  62. package/cjs/portfolio/index.js +459 -520
  63. package/cjs/portfolio/lendingProtocols.d.ts +184 -0
  64. package/cjs/portfolio/lendingProtocols.js +196 -0
  65. package/cjs/savings/index.d.ts +8 -2
  66. package/cjs/savings/index.js +33 -4
  67. package/cjs/services/merkl.d.ts +46 -2
  68. package/cjs/services/merkl.js +190 -19
  69. package/cjs/services/priceService.d.ts +12 -12
  70. package/cjs/services/priceService.js +30 -29
  71. package/cjs/services/viem.d.ts +10 -2
  72. package/cjs/services/viem.js +27 -1
  73. package/cjs/spark/index.d.ts +4 -4
  74. package/cjs/spark/index.js +9 -9
  75. package/cjs/types/aave.d.ts +98 -2
  76. package/cjs/types/aaveV4.d.ts +45 -0
  77. package/cjs/types/common.d.ts +1 -0
  78. package/cjs/types/common.js +1 -0
  79. package/cjs/types/compound.d.ts +26 -2
  80. package/cjs/types/curveUsd.d.ts +9 -1
  81. package/cjs/types/fluid.d.ts +13 -0
  82. package/cjs/types/index.d.ts +1 -0
  83. package/cjs/types/index.js +1 -0
  84. package/cjs/types/liquity.d.ts +12 -0
  85. package/cjs/types/liquityV2.d.ts +24 -0
  86. package/cjs/types/llamaLend.d.ts +12 -1
  87. package/cjs/types/merkl.d.ts +18 -0
  88. package/cjs/types/morphoBlue.d.ts +2 -0
  89. package/cjs/types/portfolio.d.ts +162 -5
  90. package/cjs/types/portfolio.js +18 -0
  91. package/cjs/types/savings/index.d.ts +9 -1
  92. package/cjs/types/spark.d.ts +21 -1
  93. package/cjs/umbrella/index.d.ts +3 -4
  94. package/cjs/umbrella/index.js +5 -4
  95. package/esm/aaveV2/index.d.ts +4 -4
  96. package/esm/aaveV2/index.js +8 -8
  97. package/esm/aaveV3/index.d.ts +5 -14
  98. package/esm/aaveV3/index.js +15 -11
  99. package/esm/aaveV3/merkl.d.ts +5 -1
  100. package/esm/aaveV3/merkl.js +9 -4
  101. package/esm/aaveV3/sgho.d.ts +2 -16
  102. package/esm/aaveV4/index.d.ts +4 -3
  103. package/esm/aaveV4/index.js +20 -17
  104. package/esm/aaveV4/lend.d.ts +2 -43
  105. package/esm/aaveV4/merkl.d.ts +10 -2
  106. package/esm/aaveV4/merkl.js +16 -7
  107. package/esm/claiming/aaveV3.d.ts +3 -3
  108. package/esm/claiming/aaveV3.js +6 -5
  109. package/esm/claiming/ethena.d.ts +2 -1
  110. package/esm/claiming/king.d.ts +3 -2
  111. package/esm/claiming/king.js +3 -2
  112. package/esm/claiming/spark.d.ts +4 -4
  113. package/esm/claiming/spark.js +9 -8
  114. package/esm/claiming/uniswap.d.ts +2 -2
  115. package/esm/claiming/uniswap.js +3 -2
  116. package/esm/compoundV2/index.d.ts +4 -4
  117. package/esm/compoundV2/index.js +9 -9
  118. package/esm/compoundV3/index.d.ts +5 -4
  119. package/esm/compoundV3/index.js +19 -15
  120. package/esm/compoundV3/merkl.d.ts +1 -1
  121. package/esm/compoundV3/merkl.js +3 -6
  122. package/esm/curveUsd/index.d.ts +5 -5
  123. package/esm/curveUsd/index.js +17 -17
  124. package/esm/fluid/index.d.ts +23 -66
  125. package/esm/fluid/index.js +76 -73
  126. package/esm/fluid/merkl.d.ts +5 -3
  127. package/esm/fluid/merkl.js +12 -7
  128. package/esm/helpers/aaveHelpers/index.js +1 -1
  129. package/esm/helpers/aaveV4Helpers/index.js +15 -3
  130. package/esm/helpers/compoundHelpers/index.js +2 -2
  131. package/esm/helpers/curveUsdHelpers/index.js +1 -1
  132. package/esm/helpers/fluidHelpers/index.js +1 -1
  133. package/esm/helpers/liquityV2Helpers/index.js +1 -1
  134. package/esm/helpers/llamaLendHelpers/index.js +1 -1
  135. package/esm/helpers/morphoBlueHelpers/index.js +1 -1
  136. package/esm/helpers/morphoMidnightHelpers/index.js +1 -1
  137. package/esm/helpers/sparkHelpers/index.js +1 -1
  138. package/esm/liquity/index.d.ts +5 -15
  139. package/esm/liquity/index.js +23 -23
  140. package/esm/liquityV2/index.d.ts +16 -31
  141. package/esm/liquityV2/index.js +95 -78
  142. package/esm/llamaLend/index.d.ts +5 -5
  143. package/esm/llamaLend/index.js +13 -13
  144. package/esm/maker/index.d.ts +6 -6
  145. package/esm/maker/index.js +16 -16
  146. package/esm/moneymarket/moneymarketCommonService.js +13 -2
  147. package/esm/morphoBlue/index.d.ts +7 -7
  148. package/esm/morphoBlue/index.js +29 -27
  149. package/esm/morphoBlue/merkl.d.ts +5 -3
  150. package/esm/morphoBlue/merkl.js +7 -9
  151. package/esm/morphoMidnight/index.d.ts +5 -5
  152. package/esm/morphoMidnight/index.js +18 -18
  153. package/esm/portfolio/customDeFiData.d.ts +3 -0
  154. package/esm/portfolio/customDeFiData.js +261 -0
  155. package/esm/portfolio/index.d.ts +17 -8
  156. package/esm/portfolio/index.js +459 -522
  157. package/esm/portfolio/lendingProtocols.d.ts +184 -0
  158. package/esm/portfolio/lendingProtocols.js +189 -0
  159. package/esm/savings/index.d.ts +8 -2
  160. package/esm/savings/index.js +31 -3
  161. package/esm/services/merkl.d.ts +46 -2
  162. package/esm/services/merkl.js +180 -18
  163. package/esm/services/priceService.d.ts +12 -12
  164. package/esm/services/priceService.js +31 -30
  165. package/esm/services/viem.d.ts +10 -2
  166. package/esm/services/viem.js +25 -0
  167. package/esm/spark/index.d.ts +4 -4
  168. package/esm/spark/index.js +10 -10
  169. package/esm/types/aave.d.ts +98 -2
  170. package/esm/types/aaveV4.d.ts +45 -0
  171. package/esm/types/common.d.ts +1 -0
  172. package/esm/types/common.js +1 -0
  173. package/esm/types/compound.d.ts +26 -2
  174. package/esm/types/curveUsd.d.ts +9 -1
  175. package/esm/types/fluid.d.ts +13 -0
  176. package/esm/types/index.d.ts +1 -0
  177. package/esm/types/index.js +1 -0
  178. package/esm/types/liquity.d.ts +12 -0
  179. package/esm/types/liquityV2.d.ts +24 -0
  180. package/esm/types/llamaLend.d.ts +12 -1
  181. package/esm/types/merkl.d.ts +18 -0
  182. package/esm/types/morphoBlue.d.ts +2 -0
  183. package/esm/types/portfolio.d.ts +162 -5
  184. package/esm/types/portfolio.js +17 -1
  185. package/esm/types/savings/index.d.ts +9 -1
  186. package/esm/types/spark.d.ts +21 -1
  187. package/esm/umbrella/index.d.ts +3 -4
  188. package/esm/umbrella/index.js +5 -4
  189. package/package.json +1 -1
  190. package/src/aaveV2/index.ts +7 -7
  191. package/src/aaveV3/index.ts +16 -11
  192. package/src/aaveV3/merkl.ts +9 -4
  193. package/src/aaveV3/sgho.ts +2 -17
  194. package/src/aaveV4/index.ts +19 -16
  195. package/src/aaveV4/lend.ts +2 -48
  196. package/src/aaveV4/merkl.ts +16 -7
  197. package/src/claiming/aaveV3.ts +9 -5
  198. package/src/claiming/ethena.ts +5 -5
  199. package/src/claiming/king.ts +8 -5
  200. package/src/claiming/spark.ts +15 -10
  201. package/src/claiming/uniswap.ts +4 -3
  202. package/src/compoundV2/index.ts +10 -9
  203. package/src/compoundV3/index.ts +20 -14
  204. package/src/compoundV3/merkl.ts +5 -4
  205. package/src/curveUsd/index.ts +19 -17
  206. package/src/fluid/index.ts +91 -72
  207. package/src/fluid/merkl.ts +12 -7
  208. package/src/helpers/aaveHelpers/index.ts +1 -1
  209. package/src/helpers/aaveV4Helpers/index.ts +16 -2
  210. package/src/helpers/compoundHelpers/index.ts +2 -2
  211. package/src/helpers/curveUsdHelpers/index.ts +1 -1
  212. package/src/helpers/fluidHelpers/index.ts +1 -1
  213. package/src/helpers/liquityV2Helpers/index.ts +1 -1
  214. package/src/helpers/llamaLendHelpers/index.ts +1 -1
  215. package/src/helpers/morphoBlueHelpers/index.ts +1 -1
  216. package/src/helpers/morphoMidnightHelpers/index.ts +1 -1
  217. package/src/helpers/sparkHelpers/index.ts +1 -1
  218. package/src/liquity/index.ts +24 -24
  219. package/src/liquityV2/index.ts +110 -76
  220. package/src/llamaLend/index.ts +15 -13
  221. package/src/maker/index.ts +19 -16
  222. package/src/moneymarket/moneymarketCommonService.ts +14 -2
  223. package/src/morphoBlue/index.ts +23 -20
  224. package/src/morphoBlue/merkl.ts +9 -6
  225. package/src/morphoMidnight/index.ts +13 -13
  226. package/src/portfolio/customDeFiData.ts +385 -0
  227. package/src/portfolio/index.ts +307 -331
  228. package/src/portfolio/lendingProtocols.ts +281 -0
  229. package/src/savings/index.ts +41 -4
  230. package/src/services/merkl.ts +209 -19
  231. package/src/services/priceService.ts +33 -30
  232. package/src/services/viem.ts +16 -0
  233. package/src/spark/index.ts +11 -8
  234. package/src/types/aave.ts +104 -1
  235. package/src/types/aaveV4.ts +50 -0
  236. package/src/types/common.ts +1 -0
  237. package/src/types/compound.ts +38 -2
  238. package/src/types/curveUsd.ts +17 -1
  239. package/src/types/fluid.ts +14 -0
  240. package/src/types/index.ts +1 -0
  241. package/src/types/liquity.ts +13 -1
  242. package/src/types/liquityV2.ts +26 -1
  243. package/src/types/llamaLend.ts +19 -1
  244. package/src/types/merkl.ts +20 -0
  245. package/src/types/morphoBlue.ts +3 -0
  246. package/src/types/portfolio.ts +191 -5
  247. package/src/types/savings/index.ts +12 -1
  248. package/src/types/spark.ts +25 -1
  249. package/src/umbrella/index.ts +7 -5
@@ -0,0 +1,184 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { AaveMarketInfo, AaveV4SpokeInfo, CompoundMarketData, CrvUSDMarketData, LlamaLendMarketData, MorphoBlueMarketData, MorphoMidnightMarketData, PortfolioMarketsData, PortfolioPositionsData, PortfolioPositionsDataForAddress, PortfolioProtocolData, SparkMarketData } from '../types';
4
+ /**
5
+ * The lending protocols the portfolio reads the same way — a market's data, then each address's position on it — one
6
+ * entry each. Adding such a protocol is its types (its key in PortfolioPositionsDataForAddress and in
7
+ * PortfolioMarketsData) and its entry in LENDING_PROTOCOLS; the portfolio reads, errors and options follow. Maker,
8
+ * Liquity, Fluid and Liquity V2 have shapes of their own and are read by their own code in ./index.ts.
9
+ */
10
+ /** What a position read gets. */
11
+ export interface PortfolioReadContext {
12
+ client: Client;
13
+ network: NetworkNumber;
14
+ }
15
+ /** What a market read gets: also the default client, on Ethereum (Compound V3 reads its prices there). */
16
+ export interface PortfolioMarketsReadContext extends PortfolioReadContext {
17
+ defaultClient: Client;
18
+ }
19
+ type PositionKey = keyof PortfolioPositionsDataForAddress;
20
+ type MarketsKey = keyof PortfolioMarketsData;
21
+ type PositionsOf<K extends PositionKey> = NonNullable<PortfolioPositionsDataForAddress[K]>;
22
+ /** The data of one of a protocol's positions: what positions[address][K][market] holds as `{ error, data }`. */
23
+ export type LendingPositionData<K extends PositionKey> = NonNullable<PositionsOf<K>[keyof PositionsOf<K>]> extends PortfolioProtocolData<infer D> ? D : never;
24
+ export interface LendingProtocol<K extends PositionKey, M extends MarketsKey, Market extends {
25
+ value: string;
26
+ }> {
27
+ /** Its key in PortfolioMarketsData. */
28
+ marketsKey: M;
29
+ /** Its name in error messages. */
30
+ label: string;
31
+ /** Its markets on a network; none where it is not deployed. */
32
+ markets: (network: NetworkNumber) => Market[];
33
+ readMarket: (context: PortfolioMarketsReadContext, market: Market) => Promise<PortfolioMarketsData[M][string]>;
34
+ /** An address's position on a market; undefined when the market can hold none. */
35
+ readPosition: (context: PortfolioReadContext, address: EthAddress, market: Market, marketData: PortfolioMarketsData[M][string]) => Promise<LendingPositionData<K> | undefined>;
36
+ /** Whether there is a position to list: an address without one gets no entry for that market. */
37
+ holds: (position: LendingPositionData<K>) => boolean;
38
+ }
39
+ /**
40
+ * A market's data, or a throw that the caller's catch turns into the position's error entry: read against a missing
41
+ * market, a position would otherwise come back empty and read as "no position".
42
+ */
43
+ export declare const requireMarket: <T>(marketsData: Record<string, T>, market: string) => T;
44
+ export declare const aaveV3Lending: {
45
+ key: "aaveV3";
46
+ marketsKey: "aaveV3MarketsData";
47
+ markets: (network: NetworkNumber) => AaveMarketInfo[];
48
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
49
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
50
+ };
51
+ export declare const aaveV4Lending: {
52
+ key: "aaveV4";
53
+ marketsKey: "aaveV4SpokesData";
54
+ markets: (network: NetworkNumber) => AaveV4SpokeInfo[];
55
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
56
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
57
+ };
58
+ export declare const morphoBlueLending: {
59
+ key: "morphoBlue";
60
+ marketsKey: "morphoMarketsData";
61
+ markets: (network: NetworkNumber) => MorphoBlueMarketData[];
62
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
63
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
64
+ };
65
+ export declare const morphoMidnightLending: {
66
+ key: "morphoMidnight";
67
+ marketsKey: "morphoMidnightMarketsData";
68
+ markets: (network: NetworkNumber) => MorphoMidnightMarketData[];
69
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
70
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
71
+ };
72
+ export declare const compoundV3Lending: {
73
+ key: "compoundV3";
74
+ marketsKey: "compoundV3MarketsData";
75
+ markets: (network: NetworkNumber) => CompoundMarketData[];
76
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
77
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
78
+ };
79
+ export declare const sparkLending: {
80
+ key: "spark";
81
+ marketsKey: "sparkMarketsData";
82
+ markets: (network: NetworkNumber) => SparkMarketData[];
83
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
84
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
85
+ };
86
+ export declare const aaveV2Lending: {
87
+ key: "aaveV2";
88
+ marketsKey: "aaveV2MarketsData";
89
+ markets: (network: NetworkNumber) => AaveMarketInfo[];
90
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
91
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
92
+ };
93
+ export declare const compoundV2Lending: {
94
+ key: "compoundV2";
95
+ marketsKey: "compoundV2MarketsData";
96
+ markets: (network: NetworkNumber) => CompoundMarketData[];
97
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
98
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
99
+ };
100
+ export declare const crvUsdLending: {
101
+ key: "crvUsd";
102
+ marketsKey: "crvUsdMarketsData";
103
+ markets: (network: NetworkNumber) => CrvUSDMarketData[];
104
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
105
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
106
+ };
107
+ export declare const llamaLendLending: {
108
+ key: "llamaLend";
109
+ marketsKey: "llamaLendMarketsData";
110
+ markets: (network: NetworkNumber) => LlamaLendMarketData[];
111
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
112
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
113
+ };
114
+ /** Every lending protocol read through its entry, in the order positions list them. */
115
+ export declare const LENDING_PROTOCOLS: readonly [{
116
+ key: "aaveV3";
117
+ marketsKey: "aaveV3MarketsData";
118
+ markets: (network: NetworkNumber) => AaveMarketInfo[];
119
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
120
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
121
+ }, {
122
+ key: "aaveV4";
123
+ marketsKey: "aaveV4SpokesData";
124
+ markets: (network: NetworkNumber) => AaveV4SpokeInfo[];
125
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
126
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
127
+ }, {
128
+ key: "morphoBlue";
129
+ marketsKey: "morphoMarketsData";
130
+ markets: (network: NetworkNumber) => MorphoBlueMarketData[];
131
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
132
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
133
+ }, {
134
+ key: "morphoMidnight";
135
+ marketsKey: "morphoMidnightMarketsData";
136
+ markets: (network: NetworkNumber) => MorphoMidnightMarketData[];
137
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
138
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
139
+ }, {
140
+ key: "compoundV3";
141
+ marketsKey: "compoundV3MarketsData";
142
+ markets: (network: NetworkNumber) => CompoundMarketData[];
143
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
144
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
145
+ }, {
146
+ key: "spark";
147
+ marketsKey: "sparkMarketsData";
148
+ markets: (network: NetworkNumber) => SparkMarketData[];
149
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
150
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
151
+ }, {
152
+ key: "aaveV2";
153
+ marketsKey: "aaveV2MarketsData";
154
+ markets: (network: NetworkNumber) => AaveMarketInfo[];
155
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
156
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
157
+ }, {
158
+ key: "compoundV2";
159
+ marketsKey: "compoundV2MarketsData";
160
+ markets: (network: NetworkNumber) => CompoundMarketData[];
161
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
162
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
163
+ }, {
164
+ key: "crvUsd";
165
+ marketsKey: "crvUsdMarketsData";
166
+ markets: (network: NetworkNumber) => CrvUSDMarketData[];
167
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
168
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
169
+ }, {
170
+ key: "llamaLend";
171
+ marketsKey: "llamaLendMarketsData";
172
+ markets: (network: NetworkNumber) => LlamaLendMarketData[];
173
+ readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise<Record<string, string>>;
174
+ readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise<PortfolioMarketsData>, positions: PortfolioPositionsData) => Promise<void>[];
175
+ }];
176
+ export type LendingKey = typeof LENDING_PROTOCOLS[number]['key'];
177
+ /** The keys ./index.ts reads with code of its own. */
178
+ export type SpecialPositionKey = 'maker' | 'liquity' | 'fluid' | 'liquityV2';
179
+ type SpecialMarketsKey = 'liquityV2MarketsData';
180
+ type UnreadPositionKey = Exclude<PositionKey, LendingKey | SpecialPositionKey>;
181
+ type UnreadMarketsKey = Exclude<MarketsKey, typeof LENDING_PROTOCOLS[number]['marketsKey'] | SpecialMarketsKey>;
182
+ export declare const EVERY_POSITION_KEY_IS_READ: [UnreadPositionKey] extends [never] ? true : UnreadPositionKey;
183
+ export declare const EVERY_MARKETS_KEY_IS_READ: [UnreadMarketsKey] extends [never] ? true : UnreadMarketsKey;
184
+ export {};
@@ -0,0 +1,189 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Dec from 'decimal.js';
11
+ import { NetworkNumber } from '../types/common';
12
+ import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LlamaLendMarkets, MorphoBlueMarkets, MorphoMidnightMarkets, SparkMarkets, } from '../markets';
13
+ import { AaveVersions, CompoundVersions, } from '../types';
14
+ import { _getAaveV3AccountData, _getAaveV3MarketData } from '../aaveV3';
15
+ import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
16
+ import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
17
+ import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
18
+ import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
19
+ import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
20
+ import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
21
+ import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData } from '../morphoBlue';
22
+ import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
23
+ import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
24
+ import { ZERO_ADDRESS } from '../constants';
25
+ /**
26
+ * A market's data, or a throw that the caller's catch turns into the position's error entry: read against a missing
27
+ * market, a position would otherwise come back empty and read as "no position".
28
+ */
29
+ export const requireMarket = (marketsData, market) => {
30
+ const marketData = marketsData[market];
31
+ if (!marketData)
32
+ throw new Error(`Market data for ${market} is not available`);
33
+ return marketData;
34
+ };
35
+ /** requireMarket for one protocol's key, typed by that key's market data. */
36
+ const requireMarketOf = (marketsData, key, market) => {
37
+ // TypeScript reads marketsData[key][market] as any protocol's market data; the key's own is what is stored there.
38
+ const marketData = marketsData[key][market];
39
+ if (!marketData)
40
+ throw new Error(`Market data for ${market} is not available`);
41
+ return marketData;
42
+ };
43
+ /** A protocol's entry with its reads, typed by its own market and position types. */
44
+ const lendingProtocol = (key, protocol) => {
45
+ /** Every market of the protocol into `markets`; resolves to the ones that failed (left out), with their errors. */
46
+ const readMarkets = (context, markets) => __awaiter(void 0, void 0, void 0, function* () {
47
+ const protocolMarkets = markets[protocol.marketsKey];
48
+ const failed = {};
49
+ yield Promise.all(protocol.markets(context.network).map((market) => __awaiter(void 0, void 0, void 0, function* () {
50
+ try {
51
+ protocolMarkets[market.value] = yield protocol.readMarket(context, market);
52
+ }
53
+ catch (error) {
54
+ console.error(`Error fetching ${protocol.marketsKey} for market ${market.value}:`, error);
55
+ failed[market.value] = `Error fetching ${protocol.marketsKey} for market ${market.value}`;
56
+ }
57
+ })));
58
+ return failed;
59
+ });
60
+ /**
61
+ * Every address's position on every market into `positions`, each read once its market is in: an entry with the data
62
+ * where the address holds a position, an entry with an error where the read or its market failed, none otherwise.
63
+ */
64
+ const readPositions = (context, addresses, marketsData, positions) => protocol.markets(context.network).flatMap((market) => addresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
65
+ // Keyed by the protocol's market type in PortfolioPositionsDataForAddress; written here by market.value.
66
+ const byMarket = positions[address.toLowerCase()][key];
67
+ try {
68
+ const marketData = requireMarketOf(yield marketsData, protocol.marketsKey, market.value);
69
+ const position = yield protocol.readPosition(context, address, market, marketData);
70
+ if (position && protocol.holds(position))
71
+ byMarket[market.value] = { error: '', data: position };
72
+ }
73
+ catch (error) {
74
+ console.error(`Error fetching ${protocol.label} account data for address ${address} on market ${market.value}:`, error);
75
+ byMarket[market.value] = { error: `Error fetching ${protocol.label} account data for address ${address} on market ${market.value}`, data: null };
76
+ }
77
+ })));
78
+ return {
79
+ key, marketsKey: protocol.marketsKey, markets: protocol.markets, readMarkets, readPositions,
80
+ };
81
+ };
82
+ const onNetwork = (network, markets) => markets.filter((market) => market.chainIds.includes(network));
83
+ const suppliesAnything = (position) => new Dec(position.suppliedUsd).gt(0);
84
+ const suppliesOrBorrowsAnything = (position) => new Dec(position.suppliedUsd).gt(0) || new Dec(position.borrowedUsd).gt(0);
85
+ export const aaveV3Lending = lendingProtocol('aaveV3', {
86
+ marketsKey: 'aaveV3MarketsData',
87
+ label: 'AaveV3',
88
+ markets: (network) => onNetwork(network, [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version])),
89
+ readMarket: ({ client, network }, market) => _getAaveV3MarketData(client, network, market),
90
+ readPosition: ({ client, network }, address, market, marketData) => _getAaveV3AccountData(client, network, address, Object.assign({ selectedMarket: market }, marketData)),
91
+ holds: suppliesAnything,
92
+ });
93
+ export const aaveV4Lending = lendingProtocol('aaveV4', {
94
+ marketsKey: 'aaveV4SpokesData',
95
+ label: 'AaveV4',
96
+ markets: (network) => onNetwork(network, Object.values(AaveV4Spokes(network))),
97
+ readMarket: ({ client, network }, spoke) => _getAaveV4SpokeData(client, network, spoke),
98
+ readPosition: ({ client, network }, address, _spoke, spokeData) => _getAaveV4AccountData(client, network, spokeData, address),
99
+ holds: suppliesAnything,
100
+ });
101
+ export const morphoBlueLending = lendingProtocol('morphoBlue', {
102
+ marketsKey: 'morphoMarketsData',
103
+ label: 'MorphoBlue',
104
+ markets: (network) => onNetwork(network, Object.values(MorphoBlueMarkets(network))),
105
+ readMarket: ({ client, network }, market) => _getMorphoBluePortfolioMarketData(client, network, market),
106
+ readPosition: ({ client, network }, address, market, marketData) => _getMorphoBlueAccountData(client, network, address, market, marketData),
107
+ holds: suppliesAnything,
108
+ });
109
+ export const morphoMidnightLending = lendingProtocol('morphoMidnight', {
110
+ marketsKey: 'morphoMidnightMarketsData',
111
+ label: 'MorphoMidnight',
112
+ markets: (network) => onNetwork(network, Object.values(MorphoMidnightMarkets(network))),
113
+ readMarket: ({ client, network }, market) => _getMorphoMidnightMarketData(client, network, market),
114
+ // Markets are created lazily on the first position, so an uncreated one can hold no position.
115
+ readPosition: (_a, address_1, market_1, marketData_1) => __awaiter(void 0, [_a, address_1, market_1, marketData_1], void 0, function* ({ client, network }, address, market, marketData) {
116
+ return (marketData.isCreated
117
+ ? _getMorphoMidnightAccountData(client, network, address, market, marketData)
118
+ : undefined);
119
+ }),
120
+ holds: suppliesAnything,
121
+ });
122
+ export const compoundV3Lending = lendingProtocol('compoundV3', {
123
+ marketsKey: 'compoundV3MarketsData',
124
+ label: 'CompoundV3',
125
+ markets: (network) => onNetwork(network, Object.values(CompoundMarkets(network)).filter((market) => market.value !== CompoundVersions.CompoundV2)),
126
+ readMarket: ({ client, defaultClient, network }, market) => _getCompoundV3MarketsData(client, network, market, defaultClient),
127
+ readPosition: ({ client, network }, address, market, marketData) => _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: marketData.assetsData }),
128
+ holds: suppliesAnything,
129
+ });
130
+ export const sparkLending = lendingProtocol('spark', {
131
+ marketsKey: 'sparkMarketsData',
132
+ label: 'Spark',
133
+ markets: (network) => onNetwork(network, Object.values(SparkMarkets(network))),
134
+ readMarket: ({ client, network }, market) => _getSparkMarketsData(client, network, market),
135
+ readPosition: ({ client, network }, address, market, marketData) => _getSparkAccountData(client, network, address, {
136
+ selectedMarket: market, assetsData: marketData.assetsData, eModeCategoriesData: marketData.eModeCategoriesData,
137
+ }),
138
+ holds: suppliesAnything,
139
+ });
140
+ export const aaveV2Lending = lendingProtocol('aaveV2', {
141
+ marketsKey: 'aaveV2MarketsData',
142
+ label: 'AaveV2',
143
+ markets: (network) => onNetwork(network, [AaveMarkets(network)[AaveVersions.AaveV2]]),
144
+ readMarket: ({ client, network }, market) => _getAaveV2MarketsData(client, network, market),
145
+ readPosition: ({ client, network }, address, market, marketData) => _getAaveV2AccountData(client, network, address, marketData.assetsData, market),
146
+ holds: suppliesAnything,
147
+ });
148
+ export const compoundV2Lending = lendingProtocol('compoundV2', {
149
+ marketsKey: 'compoundV2MarketsData',
150
+ label: 'CompoundV2',
151
+ markets: (network) => onNetwork(network, [CompoundMarkets(network)[CompoundVersions.CompoundV2]]),
152
+ readMarket: ({ client, network }) => _getCompoundV2MarketsData(client, network),
153
+ readPosition: ({ client, network }, address, _market, marketData) => _getCompoundV2AccountData(client, network, address, marketData.assetsData),
154
+ holds: suppliesAnything,
155
+ });
156
+ export const crvUsdLending = lendingProtocol('crvUsd', {
157
+ marketsKey: 'crvUsdMarketsData',
158
+ label: 'Curve USD',
159
+ markets: (network) => onNetwork(network, Object.values(CrvUsdMarkets(network))),
160
+ readMarket: ({ client, network }, market) => _getCurveUsdGlobalData(client, network, market),
161
+ // The market's borrow rate is passed in, so the read does not fetch it again.
162
+ readPosition: ({ client, network }, address, market, marketData) => _getCurveUsdUserData(client, network, address, market, marketData.activeBand, marketData.borrowRate),
163
+ holds: suppliesOrBorrowsAnything,
164
+ });
165
+ export const llamaLendLending = lendingProtocol('llamaLend', {
166
+ marketsKey: 'llamaLendMarketsData',
167
+ label: 'LlamaLend',
168
+ markets: (network) => ([NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? onNetwork(network, Object.values(LlamaLendMarkets(network))) : []),
169
+ readMarket: ({ client, network }, market) => _getLlamaLendGlobalData(client, network, market),
170
+ readPosition: (_a, address_1, market_1, marketData_1) => __awaiter(void 0, [_a, address_1, market_1, marketData_1], void 0, function* ({ client, network }, address, market, marketData) {
171
+ return (Object.assign(Object.assign({}, yield _getLlamaLendUserData(client, network, address, market, marketData)), { borrowRate: marketData.borrowRate }));
172
+ }),
173
+ holds: suppliesOrBorrowsAnything,
174
+ });
175
+ /** Every lending protocol read through its entry, in the order positions list them. */
176
+ export const LENDING_PROTOCOLS = [
177
+ aaveV3Lending,
178
+ aaveV4Lending,
179
+ morphoBlueLending,
180
+ morphoMidnightLending,
181
+ compoundV3Lending,
182
+ sparkLending,
183
+ aaveV2Lending,
184
+ compoundV2Lending,
185
+ crvUsdLending,
186
+ llamaLendLending,
187
+ ];
188
+ export const EVERY_POSITION_KEY_IS_READ = true;
189
+ export const EVERY_MARKETS_KEY_IS_READ = true;
@@ -1,4 +1,4 @@
1
- import { MakerDsrType, MorphoVaultType, SkySavingsType, SparkSavingsVaultType, SummerVaultType, YearnV3VaultType, YearnVaultType } from '../types';
1
+ import { SavingsData, SavingsDataWithErrors } from '../types';
2
2
  import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
3
  import * as morphoVaults from './morphoVaults';
4
4
  import * as yearnVaults from './yearnVaults';
@@ -8,4 +8,10 @@ import * as sparkSavingsVaults from './sparkSavingsVaults';
8
8
  import * as summerVaults from './summerVaults';
9
9
  import * as yearnV3Vaults from './yearnV3Vaults';
10
10
  export { morphoVaults, yearnVaults, makerDsr, skyOptions, sparkSavingsVaults, summerVaults, yearnV3Vaults, };
11
- export declare const getSavingsData: (provider: EthereumProvider, network: NetworkNumber, accounts: EthAddress[]) => Promise<Partial<Record<MakerDsrType | MorphoVaultType | SkySavingsType | SparkSavingsVaultType | SummerVaultType | YearnV3VaultType | YearnVaultType, import("../types").SavingsVaultData>>>;
11
+ /**
12
+ * Every savings vault of a network for the given accounts, and, for each vault that came back without data, why — so
13
+ * a vault that failed is never mistaken for one the accounts have nothing in.
14
+ */
15
+ export declare const getSavingsDataWithErrors: (provider: EthereumProvider, network: NetworkNumber, accounts: EthAddress[]) => Promise<SavingsDataWithErrors>;
16
+ /** Every savings vault of a network for the given accounts. A vault that failed is left out: use getSavingsDataWithErrors to tell why. */
17
+ export declare const getSavingsData: (provider: EthereumProvider, network: NetworkNumber, accounts: EthAddress[]) => Promise<SavingsData>;
@@ -17,7 +17,12 @@ import * as sparkSavingsVaults from './sparkSavingsVaults';
17
17
  import * as summerVaults from './summerVaults';
18
18
  import * as yearnV3Vaults from './yearnV3Vaults';
19
19
  export { morphoVaults, yearnVaults, makerDsr, skyOptions, sparkSavingsVaults, summerVaults, yearnV3Vaults, };
20
- export const getSavingsData = (provider, network, accounts) => __awaiter(void 0, void 0, void 0, function* () {
20
+ /**
21
+ * Every savings vault of a network for the given accounts, and, for each vault that came back without data, why — so
22
+ * a vault that failed is never mistaken for one the accounts have nothing in.
23
+ */
24
+ export const getSavingsDataWithErrors = (provider, network, accounts) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const isMainnet = network === NetworkNumber.Eth;
21
26
  const morphoVaultsList = Object.keys(morphoVaults.morphoVaultsOptions.MORPHO_VAULTS)
22
27
  .filter((key) => morphoVaults.morphoVaultsOptions.getMorphoVault(key).network === network);
23
28
  const yearnVaultsList = Object.keys(yearnVaults.yearnVaultsOptions.YEARN_VAULTS);
@@ -25,7 +30,16 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
25
30
  const yearnV3VaultsList = Object.keys(yearnV3Vaults.yearnV3VaultsOptions.YEARN_V3_VAULTS);
26
31
  const summerVaultsList = Object.keys(summerVaults.summerVaultsOptions.SUMMER_VAULTS)
27
32
  .filter((key) => summerVaults.summerVaultsOptions.getSummerVault(key).network === network);
33
+ // Every vault read on this network, so one left without data or an error can still be reported.
34
+ const vaultKeys = [
35
+ ...morphoVaultsList,
36
+ ...(isMainnet ? [
37
+ ...yearnVaultsList, ...sparkSavingsVaultsList, ...yearnV3VaultsList, MakerDsrType.MakerDsrVault, SkySavingsType.SkySavings,
38
+ ] : []),
39
+ ...summerVaultsList,
40
+ ];
28
41
  const savingsData = {};
42
+ const errors = {};
29
43
  yield Promise.all([
30
44
  ...(morphoVaultsList.length ? [
31
45
  (() => __awaiter(void 0, void 0, void 0, function* () {
@@ -36,10 +50,11 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
36
50
  }
37
51
  catch (err) {
38
52
  console.error('[getSavingsData] Error fetching morpho vaults:', err);
53
+ morphoVaultsList.forEach((vaultKey) => { errors[vaultKey] = `Error fetching morpho vault ${vaultKey}`; });
39
54
  }
40
55
  }))(),
41
56
  ] : []),
42
- ...(network === NetworkNumber.Eth ? [
57
+ ...(isMainnet ? [
43
58
  ...yearnVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
44
59
  try {
45
60
  const vault = yearnVaults.yearnVaultsOptions.getYearnVault(vaultKey);
@@ -48,6 +63,7 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
48
63
  }
49
64
  catch (err) {
50
65
  console.error(`[getSavingsData] Error fetching yearn vault ${vaultKey}:`, err);
66
+ errors[vaultKey] = `Error fetching yearn vault ${vaultKey}`;
51
67
  }
52
68
  })),
53
69
  ...sparkSavingsVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
@@ -58,6 +74,7 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
58
74
  }
59
75
  catch (err) {
60
76
  console.error(`[getSavingsData] Error fetching spark savings vault ${vaultKey}:`, err);
77
+ errors[vaultKey] = `Error fetching spark savings vault ${vaultKey}`;
61
78
  }
62
79
  })),
63
80
  ...yearnV3VaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
@@ -68,6 +85,7 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
68
85
  }
69
86
  catch (err) {
70
87
  console.error(`[getSavingsData] Error fetching yearn v3 vault ${vaultKey}:`, err);
88
+ errors[vaultKey] = `Error fetching yearn v3 vault ${vaultKey}`;
71
89
  }
72
90
  })),
73
91
  (() => __awaiter(void 0, void 0, void 0, function* () {
@@ -77,6 +95,7 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
77
95
  }
78
96
  catch (err) {
79
97
  console.error('[getSavingsData] Error fetching maker DSR data:', err);
98
+ errors[MakerDsrType.MakerDsrVault] = 'Error fetching maker DSR data';
80
99
  }
81
100
  }))(),
82
101
  (() => __awaiter(void 0, void 0, void 0, function* () {
@@ -86,6 +105,7 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
86
105
  }
87
106
  catch (err) {
88
107
  console.error('[getSavingsData] Error fetching Sky savings data:', err);
108
+ errors[SkySavingsType.SkySavings] = 'Error fetching Sky savings data';
89
109
  }
90
110
  }))(),
91
111
  ] : []),
@@ -97,8 +117,16 @@ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0,
97
117
  }
98
118
  catch (err) {
99
119
  console.error(`[getSavingsData] Error fetching summer vault ${vaultKey}:`, err);
120
+ errors[vaultKey] = `Error fetching summer vault ${vaultKey}`;
100
121
  }
101
122
  })),
102
123
  ]);
103
- return savingsData;
124
+ // getMorphoVaultsData leaves out, without throwing, a vault whose on-chain reads failed or that the Morpho API did not return.
125
+ vaultKeys.forEach((vaultKey) => {
126
+ if (!savingsData[vaultKey] && !errors[vaultKey])
127
+ errors[vaultKey] = `No data returned for savings vault ${vaultKey}`;
128
+ });
129
+ return { data: savingsData, errors };
104
130
  });
131
+ /** Every savings vault of a network for the given accounts. A vault that failed is left out: use getSavingsDataWithErrors to tell why. */
132
+ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0, void 0, void 0, function* () { return (yield getSavingsDataWithErrors(provider, network, accounts)).data; });
@@ -1,6 +1,50 @@
1
- import { MerklOpportunity } from '../types';
1
+ import { MerklCampaignListItem, MerklOpportunity } from '../types';
2
2
  /**
3
- * Fetches every page matching the query. Merkl returns 20 opportunities by default, so omitting
3
+ * Fetches every opportunity matching the query. Merkl returns 20 opportunities by default, so omitting
4
4
  * `items` and advancing `page` avoids imposing a client-side maximum on the result set.
5
5
  */
6
6
  export declare const fetchAllMerklOpportunities: (query: Record<string, string>) => Promise<MerklOpportunity[]>;
7
+ /** Fetches every campaign matching the query, e.g. `{ mainProtocolId: 'aave', status: 'LIVE,PAST' }`. */
8
+ export declare const fetchAllMerklCampaigns: (query: Record<string, string>) => Promise<MerklCampaignListItem[]>;
9
+ /**
10
+ * Fetches the opportunities with the given Merkl-internal ids, regardless of their current status.
11
+ * Ids Merkl no longer serves (hidden or test campaigns) are simply absent from the result.
12
+ */
13
+ export declare const fetchMerklOpportunitiesByIds: (ids: string[]) => Promise<MerklOpportunity[]>;
14
+ /**
15
+ * Returns the reward APR Merkl recorded for the opportunity at the given unix timestamp (seconds),
16
+ * or `undefined` when no campaign was computing for it then. Records are buckets keyed by their
17
+ * start, newest first, and each carries the last value recorded in the bucket. The hourly bucket of
18
+ * the timestamp's hour is used when Merkl still has it — it keeps hourly history for roughly the
19
+ * last ten weeks — and the daily bucket of the timestamp's day otherwise. Either window is a day
20
+ * wide to tolerate computation gaps and aligned to the bucket, so every block within one hour asks
21
+ * for (and caches) the same records.
22
+ */
23
+ export declare const fetchMerklOpportunityAprAt: (opportunityId: string, timestamp: number) => Promise<number | undefined>;
24
+ /** Drops every cached historical response (campaign lists, opportunities, APR buckets). */
25
+ export declare const clearMerklHistoryCache: () => void;
26
+ /**
27
+ * Reconstructs the opportunities that were live at `timestamp` (unix seconds), shaped like the
28
+ * live listing so the per-protocol reward mappers can consume either without knowing which they got:
29
+ * 1. every LIVE or PAST campaign for the protocol (and chain, when the query names one) is listed
30
+ * once per cache period — the list is block-independent, the exact window check happens here —
31
+ * and the ones whose [start, end] covers the timestamp identify the opportunities rewarded
32
+ * then (the live listing can't: campaigns live then are mostly PAST now and ones live now
33
+ * didn't exist then);
34
+ * 2. those opportunities are loaded by id (works for PAST ones too) and narrowed to `query.type`
35
+ * and `isRelevant`, so no APR history is fetched for opportunities the caller would discard;
36
+ * 3. each one's `apr` is replaced with the value Merkl recorded at the timestamp, and ones with no
37
+ * record then are dropped, since nothing was being computed for them.
38
+ * `status` is forced to LIVE so status filters downstream keep working, `campaigns` carries the
39
+ * covering campaigns, and a reward token breakdown is synthesized from the campaign's reward token
40
+ * when Merkl no longer serves one for the opportunity (it drops them once an opportunity is PAST).
41
+ * `query.status` is ignored: it describes the present, not the requested moment.
42
+ */
43
+ export declare const fetchMerklOpportunitiesAt: (query: Record<string, string>, timestamp: number, isRelevant?: (opportunity: MerklOpportunity) => boolean) => Promise<MerklOpportunity[]>;
44
+ /**
45
+ * Live opportunities when no timestamp is given, otherwise the opportunities as they were at that
46
+ * unix timestamp (seconds) — see `fetchMerklOpportunitiesAt`. `isRelevant` only applies to the
47
+ * historical path, where it saves fetching APR history for opportunities the caller would discard;
48
+ * callers still filter the live listing themselves.
49
+ */
50
+ export declare const fetchMerklOpportunities: (query: Record<string, string>, asOfTimestamp?: number, isRelevant?: (opportunity: MerklOpportunity) => boolean) => Promise<MerklOpportunity[]>;