@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
@@ -114,6 +114,26 @@ export type MerklOpportunity = {
114
114
  };
115
115
  };
116
116
 
117
+ /** One entry of Merkl's campaign listing: a campaign plus the opportunity it rewards. */
118
+ export type MerklCampaignListItem = MerklCampaign & {
119
+ opportunityId: string;
120
+ type: string;
121
+ rewardToken?: MerklOpportunity['rewardsRecord']['breakdowns'][number]['token'];
122
+ };
123
+
124
+ /** One bucket of an opportunity's APR history (`apr` is the last value recorded in the bucket). */
125
+ export type MerklAprRecord = {
126
+ timestamp: string;
127
+ date: string;
128
+ apr: number;
129
+ open: number;
130
+ min: number;
131
+ max: number;
132
+ avg: number;
133
+ samples: number;
134
+ hasUntrustedContribution: boolean;
135
+ };
136
+
117
137
  export type MerkleRewardInfo = { apy: string; rewardTokenSymbol: string, description: string, identifier: string };
118
138
  export type MerkleRewardMap = Record<EthAddress, { supply?: MerkleRewardInfo; borrow?: MerkleRewardInfo }>;
119
139
 
@@ -241,6 +241,9 @@ export interface MorphoBluePositionData {
241
241
  supplyShares: string,
242
242
  borrowShares: string,
243
243
  exposure: string,
244
+ // Set by getMorphoBlueAggregatedPositionData. Optional, so objects built by hand still type-check.
245
+ minCollRatio?: string,
246
+ collLiquidationRatio?: string,
244
247
  }
245
248
 
246
249
  export interface MorphoBlueEarnData {
@@ -1,18 +1,31 @@
1
1
  import {
2
- AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions,
2
+ AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions, StakeAaveData, UmbrellaStakingData,
3
3
  } from './aave';
4
4
  import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
5
+ import {
6
+ AaveRewardsClaimableToken,
7
+ EthenaAirdropClaimableToken,
8
+ KingRewardsClaimableToken,
9
+ MerklRewardsClaimableToken,
10
+ SparkAirdropClaimableToken,
11
+ SparkRewardsClaimableToken,
12
+ UniswapAirdropClaimableToken,
13
+ } from './claiming';
5
14
  import { EthAddress } from './common';
6
15
  import {
7
16
  CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions,
8
17
  } from './compound';
9
18
  import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
10
- import { FluidMarketData, FluidVaultData } from './fluid';
11
- import { LiquityTroveInfo } from './liquity';
12
- import { LiquityV2MarketData, LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
19
+ import { FluidEarnPositionData, FluidMarketData, FluidVaultData } from './fluid';
20
+ import { LiquityStakingData, LiquityTroveInfo } from './liquity';
21
+ import {
22
+ LiquityV2MarketData, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2TroveData, LiquityV2Versions,
23
+ } from './liquityV2';
13
24
  import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
14
25
  import { CdpData, IlkInfo } from './maker';
15
- import { MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
26
+ import {
27
+ MorphoBlueEarnData, MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions,
28
+ } from './morphoBlue';
16
29
  import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
17
30
  import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
18
31
 
@@ -21,6 +34,35 @@ export interface PortfolioProtocolData<T> {
21
34
  data: T | null,
22
35
  }
23
36
 
37
+ /** A failed fetch of a protocol that, when it succeeds, getPortfolioData returns unwrapped rather than as `{ error, data }`. */
38
+ export interface PortfolioProtocolError {
39
+ error: string,
40
+ data: null,
41
+ }
42
+
43
+ /** What getPortfolioData reads besides markets. */
44
+ export interface PortfolioDataOptions {
45
+ /** positions (lending); default true. With false it comes back as {} and no lending position is read. */
46
+ positions?: boolean,
47
+ /** stakingPositions; default true. With false it comes back as {} and no staking source is read. */
48
+ staking?: boolean,
49
+ /** rewardsData; default true. With false it comes back as {} and no rewards source is read. */
50
+ rewards?: boolean,
51
+ /**
52
+ * Liquity V2 troves in positions[address].liquityV2; default false, as the DeFi Saver app reads them on its own.
53
+ * Mainnet only: elsewhere liquityV2 is {}. Needs positions.
54
+ */
55
+ liquityV2?: boolean,
56
+ }
57
+
58
+ /** One Liquity V2 market's troves of an address, by trove id — with an error when the ids or any trove failed to load. */
59
+ export interface PortfolioLiquityV2Troves {
60
+ error: string,
61
+ data: {
62
+ [troveId: string]: LiquityV2TroveData;
63
+ },
64
+ }
65
+
24
66
  export interface PortfolioPositionsDataForAddress {
25
67
  aaveV3: {
26
68
  [key in AaveVersions]?: PortfolioProtocolData<AaveV3PositionData>;
@@ -62,11 +104,111 @@ export interface PortfolioPositionsDataForAddress {
62
104
  aaveV4: {
63
105
  [key in AaveV4SpokesType]?: PortfolioProtocolData<AaveV4AccountData>;
64
106
  };
107
+ /** Only with the liquityV2 option. Every trove the address holds, by market. */
108
+ liquityV2?: {
109
+ [key in LiquityV2Versions]?: PortfolioLiquityV2Troves;
110
+ };
65
111
  }
66
112
 
67
113
  export interface PortfolioPositionsData {
68
114
  [key: EthAddress]: PortfolioPositionsDataForAddress;
69
115
  }
116
+
117
+ export enum PortfolioProtocol {
118
+ AaveV2 = 'aaveV2',
119
+ AaveV3 = 'aaveV3',
120
+ AaveV4 = 'aaveV4',
121
+ CompoundV2 = 'compoundV2',
122
+ CompoundV3 = 'compoundV3',
123
+ Spark = 'spark',
124
+ MorphoBlue = 'morphoBlue',
125
+ MorphoMidnight = 'morphoMidnight',
126
+ CrvUsd = 'crvUsd',
127
+ LlamaLend = 'llamaLend',
128
+ Maker = 'maker',
129
+ Liquity = 'liquity',
130
+ LiquityV2 = 'liquityV2',
131
+ Fluid = 'fluid',
132
+ }
133
+
134
+ export interface CustomDeFiDataOptions {
135
+ /** Defaults to every protocol. */
136
+ protocols?: PortfolioProtocol[];
137
+ fetchStaking?: boolean;
138
+ fetchRewards?: boolean;
139
+ /** Keep Aave V3 / Spark positions with no supply so the eMode category is available. */
140
+ returnEmptyEModePositions?: boolean;
141
+ fetchFluidMarkets?: boolean;
142
+ isSim?: boolean;
143
+ /** viem multicall calldata cap in bytes; defaults to 250k (2k when isSim). */
144
+ batchSize?: number;
145
+ /** Every read is made at this block; defaults to latest. */
146
+ blockNumber?: number;
147
+ }
148
+
149
+ export interface CustomDeFiData {
150
+ positions: PortfolioPositionsData;
151
+ stakingPositions: Record<string, any>;
152
+ rewardsData: Record<string, any>;
153
+ /** Includes Fluid's and Maker's markets, filled when their protocols (and fetchFluidMarkets) are requested. */
154
+ markets: ShifterPortfolioMarketsData;
155
+ }
156
+
157
+ /**
158
+ * The staking positions getPortfolioData returns for an address. The shapes are uneven, and the DeFi Saver app
159
+ * parses them as they are: a protocol read once per address comes back unwrapped on success, as
160
+ * `{ error, data: null }` on failure, and as {} (or Fluid's `{ error: '', data: {} }`) on a network it is not read on.
161
+ */
162
+ export interface PortfolioStakingPositionsDataForAddress {
163
+ /** stkAAVE, stkGHO and sGHO; mainnet only. */
164
+ aaveV3: StakeAaveData | PortfolioProtocolError | {};
165
+ /** Morpho Blue supply without a borrow (Earn), by market; only markets with a deposit or an error. */
166
+ morphoBlue: {
167
+ [key in MorphoBlueVersions]?: PortfolioProtocolData<MorphoBlueEarnData>;
168
+ };
169
+ // Never filled; kept so the shape does not change under the app.
170
+ compoundV3: Record<string, never>;
171
+ spark: Record<string, never>;
172
+ aaveV2: Record<string, never>;
173
+ compoundV2: Record<string, never>;
174
+ /** LQTY staking and the LUSD stability pool; mainnet only. */
175
+ liquity: LiquityStakingData | PortfolioProtocolError | {};
176
+ /** Stability pool deposits, by market; mainnet only, legacy markets left out. */
177
+ liquityV2: {
178
+ [key in LiquityV2Versions]?: PortfolioProtocolData<LiquityV2StakingData>;
179
+ };
180
+ /** Fluid lending (fToken) deposits; `{ error: '', data: {} }` on a network without Fluid. */
181
+ fluid: FluidEarnPositionData[] | PortfolioProtocolError | { error: string, data: Record<string, never> };
182
+ /** Umbrella stakes; absent off mainnet. */
183
+ umbrella?: UmbrellaStakingData | PortfolioProtocolError;
184
+ /** sBOLD, yBOLD and stYBOLD; data is null off mainnet. */
185
+ liquityV2SBoldYBold: PortfolioProtocolData<LiquityV2SBoldYBoldData>;
186
+ }
187
+
188
+ // A Record rather than an interface: the app casts getPortfolioData's result to its own Record<string, …> type, and an
189
+ // interface with an address index signature is not comparable to one.
190
+ export type PortfolioStakingPositionsData = Record<EthAddress, PortfolioStakingPositionsDataForAddress>;
191
+
192
+ /** The claimable rewards getPortfolioData returns for an address. Off mainnet only Merkl and Aave V3 are read. */
193
+ export interface PortfolioRewardsDataForAddress {
194
+ merkl: PortfolioProtocolData<MerklRewardsClaimableToken[]>;
195
+ aaveV3: {
196
+ [key in AaveVersions]?: PortfolioProtocolData<AaveRewardsClaimableToken[]>;
197
+ };
198
+ spark: {
199
+ [key in SparkVersions]?: PortfolioProtocolData<SparkRewardsClaimableToken[]>;
200
+ };
201
+ /** The SPK airdrop. */
202
+ spk: PortfolioProtocolData<SparkAirdropClaimableToken[]>;
203
+ king: PortfolioProtocolData<KingRewardsClaimableToken[]>;
204
+ /** {} off mainnet. */
205
+ ethena: PortfolioProtocolData<EthenaAirdropClaimableToken[]> | {};
206
+ uniswap: PortfolioProtocolData<UniswapAirdropClaimableToken[]>;
207
+ }
208
+
209
+ export type PortfolioRewardsData = Record<EthAddress, PortfolioRewardsDataForAddress>;
210
+
211
+ /** The `markets` getPortfolioData returns: every market it read, by protocol, keyed by market or spoke. */
70
212
  export interface PortfolioMarketsData {
71
213
  morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
72
214
  morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
@@ -79,6 +221,50 @@ export interface PortfolioMarketsData {
79
221
  llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
80
222
  liquityV2MarketsData: Record<string, LiquityV2MarketData>;
81
223
  aaveV4SpokesData: Record<string, AaveV4SpokeData>;
224
+ }
225
+
226
+ /**
227
+ * The `markets` getShifterPortfolioData returns: the portfolio's markets, plus Fluid's and Maker's, which the shifter
228
+ * offers as destinations. Kept apart from PortfolioMarketsData, which getPortfolioData does not fill these into.
229
+ */
230
+ export interface ShifterPortfolioMarketsData extends PortfolioMarketsData {
82
231
  fluidMarketsData: Record<string, FluidMarketData>;
83
232
  makerMarketsData: Record<string, IlkInfo>;
84
233
  }
234
+
235
+ /** The markets that could not be read, by their key in PortfolioMarketsData, then by market or spoke: the error. */
236
+ export type PortfolioMarketsErrors = {
237
+ [key in keyof PortfolioMarketsData]?: Record<string, string>;
238
+ };
239
+
240
+ /**
241
+ * What the portfolio fetch could not read and has no `{ error, data }` entry of its own to report it in. A key is
242
+ * present only when something under it failed; {} when everything was read.
243
+ */
244
+ export interface PortfolioErrors {
245
+ /** Markets missing from `markets`; every position on such a market is an entry with an error. */
246
+ markets?: PortfolioMarketsErrors;
247
+ /** Addresses whose Maker vault list could not be read: their `maker` is {}, which would otherwise read as "no vaults". */
248
+ makerCdps?: Record<EthAddress, string>;
249
+ }
250
+
251
+ /** getPortfolioMarketsData's result. */
252
+ export interface PortfolioMarketsResult {
253
+ /** Every market read; one that failed is missing and named in `errors`. */
254
+ markets: PortfolioMarketsData;
255
+ errors: PortfolioMarketsErrors;
256
+ }
257
+
258
+ /** getPortfolioUserData's result: what is read per address. */
259
+ export interface PortfolioUserData {
260
+ positions: PortfolioPositionsData;
261
+ stakingPositions: PortfolioStakingPositionsData;
262
+ rewardsData: PortfolioRewardsData;
263
+ errors: Pick<PortfolioErrors, 'makerCdps'>;
264
+ }
265
+
266
+ /** getPortfolioData's result. */
267
+ export interface PortfolioData extends Omit<PortfolioUserData, 'errors'> {
268
+ markets: PortfolioMarketsData;
269
+ errors: PortfolioErrors;
270
+ }
@@ -23,4 +23,15 @@ export interface SavingsVaultData {
23
23
  optionType: string,
24
24
  }
25
25
 
26
- export type SavingsData = Partial<Record<MorphoVaultType | YearnVaultType | MakerDsrType | SkySavingsType | SparkSavingsVaultType | SummerVaultType | YearnV3VaultType, SavingsVaultData>>;
26
+ /** The key of every savings vault getSavingsData reads. */
27
+ export type SavingsVaultKey = MorphoVaultType | YearnVaultType | MakerDsrType | SkySavingsType | SparkSavingsVaultType | SummerVaultType | YearnV3VaultType;
28
+
29
+ export type SavingsData = Partial<Record<SavingsVaultKey, SavingsVaultData>>;
30
+
31
+ /** Why each vault that was read for a network came back without data. */
32
+ export type SavingsErrors = Partial<Record<SavingsVaultKey, string>>;
33
+
34
+ export interface SavingsDataWithErrors {
35
+ data: SavingsData,
36
+ errors: SavingsErrors,
37
+ }
@@ -57,6 +57,22 @@ export interface SparkAssetData extends MMAssetData {
57
57
  eModeCategory: number,
58
58
  liquidationBonus: string,
59
59
  liquidationRatio: string,
60
+ // Set by _getSparkMarketsData. Optional, so objects built by hand still type-check.
61
+ debtCeilingForIsolationMode?: string,
62
+ isSiloed?: boolean,
63
+ isolationModeTotalDebt?: string,
64
+ isolationModeBorrowingEnabled?: boolean,
65
+ assetId?: number,
66
+ borrowRateStable?: string,
67
+ supplyCap?: string,
68
+ isInactive?: boolean,
69
+ isFrozen?: boolean,
70
+ isPaused?: boolean,
71
+ canBeWithdrawn?: boolean,
72
+ canBePayBacked?: boolean,
73
+ disabledStableBorrowing?: boolean,
74
+ isFlashLoanEnabled?: boolean,
75
+ aTokenAddress?: EthAddress,
60
76
  }
61
77
 
62
78
  export interface SparkAssetsData {
@@ -116,7 +132,15 @@ export interface SparkAggregatedPositionData {
116
132
  exposure: string,
117
133
  }
118
134
 
119
- export interface SparkPositionData extends MMPositionData {
135
+ /**
136
+ * Fields sparkGetAggregatedPositionData adds to every Spark position at runtime, on top of those declared below.
137
+ * Optional, so code that builds a position by hand keeps compiling.
138
+ */
139
+ export type SparkPositionAggregatedFields = Partial<Omit<SparkAggregatedPositionData,
140
+ | keyof MMPositionData | 'ratio' | 'collRatio' | 'suppliedUsd' | 'borrowedUsd' | 'borrowLimitUsd'
141
+ | 'suppliedCollateralUsd' | 'incentiveUsd' | 'totalInterestUsd'>>;
142
+
143
+ export interface SparkPositionData extends MMPositionData, SparkPositionAggregatedFields {
120
144
  ratio: string,
121
145
  minRatio: string,
122
146
  collRatio: string,
@@ -1,19 +1,21 @@
1
1
  import { Client } from 'viem';
2
2
  import { AaveUmbrellaViewViem, AaveV3ViewContractViem } from '../contracts';
3
- import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { Blockish, EthAddress, NetworkNumber } from '../types/common';
4
+ import { UmbrellaStakingData } from '../types/aave';
4
5
  import { compareAddresses, convertHybridArraysToObjects, getEthAmountForDecimals } from '../services/utils';
6
+ import { setViemBlockNumber } from '../services/viem';
5
7
  import { findMatching, tokenEntries } from './umbrellaUtils';
6
8
 
7
9
  const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
8
10
  const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
9
11
 
10
- export const getUmbrellaData = async (provider: Client, network: NetworkNumber, address: EthAddress) => {
12
+ export const getUmbrellaData = async (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber: Blockish = 'latest'): Promise<UmbrellaStakingData> => {
11
13
  const umbrellaView = AaveUmbrellaViewViem(provider, network);
12
14
  const aaveV3View = AaveV3ViewContractViem(provider, network);
13
15
  const [tokensAggregatedData, additionalUmbrellaStakingData, userAggregatedData] = await Promise.all([
14
- umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle]),
15
- aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address]),
16
- umbrellaView.read.getUserAggregatedData([umbrella, address]),
16
+ umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle], setViemBlockNumber(blockNumber)),
17
+ aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address], setViemBlockNumber(blockNumber)),
18
+ umbrellaView.read.getUserAggregatedData([umbrella, address], setViemBlockNumber(blockNumber)),
17
19
  ]);
18
20
 
19
21
  return Object.fromEntries(