@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
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import memoize from 'memoizee';
11
11
  import { aprToApy } from '../moneymarket';
12
- import { fetchAllMerklOpportunities } from '../services/merkl';
12
+ import { fetchMerklOpportunities } from '../services/merkl';
13
13
  import { IncentiveKind, IncentiveSource, OpportunityStatus, } from '../types';
14
14
  /**
15
15
  * Merkl tags Fluid vault-scoped reward campaigns via the opportunity `type` field:
@@ -63,23 +63,28 @@ export const buildFluidMerklRewardMap = (opportunities, chainId) => {
63
63
  return result;
64
64
  };
65
65
  /**
66
- * Fetches live vault-scoped Fluid campaigns for the chain, keyed by vault address. Never throws —
67
- * on any failure it returns an empty map, so Merkl being down can't break market data.
66
+ * Fetches live vault-scoped Fluid campaigns for the chain, keyed by vault address. With
67
+ * `asOfTimestamp` (unix seconds) the campaigns and APRs are the ones Merkl had at that moment
68
+ * instead. Never throws — on any failure it returns an empty map, so Merkl being down can't break
69
+ * market data.
68
70
  */
69
- export const getFluidMerklCampaigns = memoize((chainId) => __awaiter(void 0, void 0, void 0, function* () {
71
+ export const getFluidMerklCampaigns = memoize((chainId, asOfTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
70
72
  try {
71
- const opportunities = yield fetchAllMerklOpportunities({
73
+ const opportunities = yield fetchMerklOpportunities({
72
74
  mainProtocolId: 'fluid',
75
+ chainId: chainId.toString(),
73
76
  type: Object.values(FluidMerklOpportunityType).join(','),
74
77
  status: OpportunityStatus.LIVE,
75
- });
78
+ }, asOfTimestamp);
76
79
  return buildFluidMerklRewardMap(opportunities, chainId);
77
80
  }
78
81
  catch (e) {
79
82
  console.error('Failed to fetch Fluid Merkl campaigns', e);
80
83
  return {};
81
84
  }
82
- }), { promise: true, maxAge: 60 * 1000 });
85
+ // memoizee keys on the declared arity, which excludes optional params — `length: 2` keeps the
86
+ // timestamp in the cache key so a historical lookup never serves (or is served by) the live one
87
+ }), { promise: true, maxAge: 60 * 1000, length: 2 });
83
88
  /**
84
89
  * Appends the vault's Merkl campaigns to its assets' incentive arrays — supply rewards on every
85
90
  * suppliable asset and borrow rewards on every borrowable one. Smart collateral/debt vaults hold
@@ -149,7 +149,7 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
149
149
  payload.leveragedType = leveragedType;
150
150
  payload.leveragedAsset = leveragedAsset;
151
151
  payload.liquidationPrice = '';
152
- if (leveragedType !== '') {
152
+ if (leveragedAsset !== '') {
153
153
  let assetPrice = data.assetsData[leveragedAsset].price;
154
154
  if (leveragedType === LeverageType.VolatilePair) {
155
155
  const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import Dec from 'decimal.js';
11
11
  import { assetAmountInWei } from '@defisaver/tokens';
12
- import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
12
+ import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, getExposure, STABLE_ASSETS, } from '../../moneymarket';
13
13
  import { calculateInterestEarned } from '../../staking';
14
14
  import { IncentiveSide, LeverageType, } from '../../types';
15
15
  import { borrowOperations } from '../../constants';
@@ -151,12 +151,15 @@ export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
151
151
  let supplyUnstable = 0;
152
152
  let longAsset = '';
153
153
  let shortAsset = '';
154
+ let stableCollAsset = '';
154
155
  Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, reserveId, }) => {
155
156
  const spokeAsset = `${symbol}-${reserveId}`;
156
157
  const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
157
158
  const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
158
- if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
159
+ if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral) {
159
160
  supplyStable += 1;
161
+ stableCollAsset = spokeAsset;
162
+ }
160
163
  if (isBorrowed && STABLE_ASSETS.includes(symbol))
161
164
  borrowStable += 1;
162
165
  if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
@@ -171,6 +174,7 @@ export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
171
174
  const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
172
175
  const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
173
176
  const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
177
+ const isStablePair = supplyStable > 0 && borrowStable > 0 && supplyUnstable === 0 && borrowUnstable === 0;
174
178
  if (isLong) {
175
179
  return {
176
180
  leveragedType: LeverageType.Long,
@@ -189,6 +193,13 @@ export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
189
193
  leveragedAsset: longAsset,
190
194
  };
191
195
  }
196
+ if (isStablePair) {
197
+ return {
198
+ leveragedType: LeverageType.StablePair,
199
+ // with multiple stable collaterals there is no single leveraged asset (and no liquidation price)
200
+ leveragedAsset: supplyStable === 1 ? stableCollAsset : '',
201
+ };
202
+ }
192
203
  return {
193
204
  leveragedType: LeverageType.None,
194
205
  leveragedAsset: '',
@@ -215,7 +226,7 @@ export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, networ
215
226
  payload.leveragedType = leveragedType;
216
227
  payload.leveragedAsset = leveragedAsset;
217
228
  payload.liquidationPrice = '';
218
- if (leveragedType !== '') {
229
+ if (leveragedAsset !== '') {
219
230
  const leveragedAssetData = assetsData[leveragedAsset];
220
231
  let assetPrice = (leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0';
221
232
  if (leveragedType === LeverageType.VolatilePair) {
@@ -239,6 +250,7 @@ export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, networ
239
250
  payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
240
251
  payload.healthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
241
252
  payload.minHealthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowLimitUsd).toDP(4).toString();
253
+ payload.exposure = getExposure(payload.borrowedUsd, payload.suppliedUsd);
242
254
  const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApyAaveV4({ usedAssets, assetsData });
243
255
  payload.netApy = netApy;
244
256
  payload.incentiveUsd = incentiveUsd;
@@ -108,7 +108,7 @@ export const getCompoundV2AggregatedData = (_a) => {
108
108
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
109
109
  payload.leveragedType = leveragedType;
110
110
  payload.liquidationPrice = '';
111
- if (leveragedType !== '') {
111
+ if (leveragedAsset !== '') {
112
112
  payload.leveragedAsset = leveragedAsset;
113
113
  const assetPrice = assetsData[handleWbtcLegacy(leveragedAsset)].price;
114
114
  payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
@@ -142,7 +142,7 @@ export const getCompoundV3AggregatedData = (_a) => {
142
142
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets, selectedMarket.value === CompoundVersions.CompoundV3ETH ? 0.001 : 5);
143
143
  payload.leveragedType = leveragedType;
144
144
  payload.liquidationPrice = '';
145
- if (leveragedType !== '') {
145
+ if (leveragedAsset !== '') {
146
146
  payload.leveragedAsset = leveragedAsset;
147
147
  let assetPrice = assetsData[leveragedAsset].price;
148
148
  if (leveragedType === LeverageType.VolatilePair) {
@@ -38,7 +38,7 @@ export const getCrvUsdAggregatedData = (_a) => {
38
38
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
39
39
  payload.leveragedType = leveragedType;
40
40
  payload.liquidationPrice = '';
41
- if (leveragedType !== '') {
41
+ if (leveragedAsset !== '') {
42
42
  payload.leveragedAsset = leveragedAsset;
43
43
  payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
44
44
  }
@@ -82,7 +82,7 @@ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, },
82
82
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
83
83
  payload.leveragedType = leveragedType;
84
84
  payload.liquidationPrice = '';
85
- if (leveragedType !== '') {
85
+ if (leveragedAsset !== '') {
86
86
  payload.leveragedAsset = leveragedAsset;
87
87
  let assetPrice = assetsData[leveragedAsset].price;
88
88
  if (leveragedType === LeverageType.VolatilePair) {
@@ -50,7 +50,7 @@ export const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData, min
50
50
  payload.leveragedType = leveragedType;
51
51
  payload.leveragedAsset = leveragedAsset;
52
52
  payload.liquidationPrice = '';
53
- if (leveragedType !== '') {
53
+ if (leveragedAsset !== '') {
54
54
  const assetPrice = assetsData[leveragedAsset].price;
55
55
  payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
56
56
  }
@@ -45,7 +45,7 @@ export const getLlamaLendAggregatedData = (_a) => {
45
45
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
46
46
  payload.leveragedType = leveragedType;
47
47
  payload.liquidationPrice = '';
48
- if (leveragedType !== '') {
48
+ if (leveragedAsset !== '') {
49
49
  payload.leveragedAsset = leveragedAsset;
50
50
  payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
51
51
  }
@@ -45,7 +45,7 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
45
45
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
46
46
  payload.leveragedType = leveragedType;
47
47
  payload.liquidationPrice = '';
48
- if (leveragedType !== '') {
48
+ if (leveragedAsset !== '') {
49
49
  payload.leveragedAsset = leveragedAsset;
50
50
  let assetPrice = assetsData[leveragedAsset].price;
51
51
  if (leveragedType === LeverageType.VolatilePair) {
@@ -63,7 +63,7 @@ export const getMorphoMidnightAggregatedPositionData = ({ usedAssets, assetsData
63
63
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
64
64
  payload.leveragedType = leveragedType;
65
65
  payload.liquidationPrice = '';
66
- if (leveragedType !== '') {
66
+ if (leveragedAsset !== '') {
67
67
  payload.leveragedAsset = leveragedAsset;
68
68
  let assetPrice = assetsData[leveragedAsset].price;
69
69
  if (leveragedType === LeverageType.VolatilePair) {
@@ -80,7 +80,7 @@ export const sparkGetAggregatedPositionData = (_a) => {
80
80
  const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
81
81
  payload.leveragedType = leveragedType;
82
82
  payload.liquidationPrice = '';
83
- if (leveragedType !== '') {
83
+ if (leveragedAsset !== '') {
84
84
  payload.leveragedAsset = leveragedAsset;
85
85
  let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
86
86
  if (leveragedType === LeverageType.VolatilePair) {
@@ -1,21 +1,11 @@
1
1
  import { Client } from 'viem';
2
2
  import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
3
- import { LiquityTroveInfo } from '../types';
3
+ import { LiquityStakingData, LiquityTroveInfo } from '../types';
4
4
  export declare const LIQUITY_NORMAL_MODE_RATIO = 110;
5
5
  export declare const LIQUITY_RECOVERY_MODE_RATIO = 150;
6
6
  export declare const _getLiquityAccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
7
7
  export declare const getLiquityAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
8
- export declare const getDebtInFront: (provider: EthereumProvider, address: EthAddress) => Promise<string>;
9
- export declare const _getLiquityTroveInfo: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
10
- export declare const getLiquityTroveInfo: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
11
- export declare const getLiquityStakingData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
12
- totalLUSDDeposited: string;
13
- totalLQTYStaked: string;
14
- stakedLQTY: string;
15
- stakedLUSDBalance: string;
16
- rewardETH: string;
17
- rewardLUSD: string;
18
- stabilityRewardETH: string;
19
- stabilityRewardLQTY: string;
20
- showStakingBalances: boolean;
21
- }>;
8
+ export declare const getDebtInFront: (provider: EthereumProvider, address: EthAddress, blockNumber?: Blockish) => Promise<string>;
9
+ export declare const _getLiquityTroveInfo: (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber?: Blockish) => Promise<LiquityTroveInfo>;
10
+ export declare const getLiquityTroveInfo: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, blockNumber?: Blockish) => Promise<LiquityTroveInfo>;
11
+ export declare const getLiquityStakingData: (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber?: Blockish) => Promise<LiquityStakingData>;
@@ -40,33 +40,33 @@ export const _getLiquityAccountBalances = (provider, network, block, addressMapp
40
40
  return balances;
41
41
  });
42
42
  export const getLiquityAccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () { return _getLiquityAccountBalances(getViemProvider(provider, network), network, block, addressMapping, address); });
43
- const _getDebtInFront = (viewContract_1, address_1, ...args_1) => __awaiter(void 0, [viewContract_1, address_1, ...args_1], void 0, function* (viewContract, address, accumulatedSum = '0', iterations = 2000) {
44
- const res = yield viewContract.read.getDebtInFront([address, accumulatedSum, iterations]);
43
+ const _getDebtInFront = (viewContract_1, address_1, ...args_1) => __awaiter(void 0, [viewContract_1, address_1, ...args_1], void 0, function* (viewContract, address, accumulatedSum = '0', iterations = 2000, blockNumber = 'latest') {
44
+ const res = yield viewContract.read.getDebtInFront([address, accumulatedSum, iterations], setViemBlockNumber(blockNumber));
45
45
  const debt = res[1].toString();
46
46
  const next = res[0];
47
47
  if (next === ZERO_ADDRESS)
48
48
  return assetAmountInEth(debt, 'LUSD');
49
- return _getDebtInFront(viewContract, next, debt, iterations);
49
+ return _getDebtInFront(viewContract, next, debt, iterations, blockNumber);
50
50
  });
51
- export const getDebtInFront = (provider, address) => __awaiter(void 0, void 0, void 0, function* () {
51
+ export const getDebtInFront = (provider_1, address_1, ...args_1) => __awaiter(void 0, [provider_1, address_1, ...args_1], void 0, function* (provider, address, blockNumber = 'latest') {
52
52
  const client = getViemProvider(provider, NetworkNumber.Eth);
53
53
  const viewContract = LiquityViewContractViem(client, NetworkNumber.Eth);
54
- return _getDebtInFront(viewContract, address);
54
+ return _getDebtInFront(viewContract, address, '0', 2000, blockNumber);
55
55
  });
56
- export const _getLiquityTroveInfo = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
56
+ export const _getLiquityTroveInfo = (provider_1, network_1, address_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, ...args_1], void 0, function* (provider, network, address, blockNumber = 'latest') {
57
57
  const viewContract = LiquityViewContractViem(provider, network);
58
58
  const collSurplusPoolContract = LiquityCollSurplusPoolContractViem(provider, network);
59
59
  const troveManagerContract = LiquityTroveManagerContractViem(provider, network);
60
60
  const priceFeedContract = LiquityPriceFeedContractViem(provider, network);
61
61
  const activePoolContract = LiquityActivePoolContractViem(provider, network);
62
62
  const [troveInfo, collSurplusInfo, borrowingRateWithDecay, assetPrice, totalETH, totalLUSD, debtInFront,] = yield Promise.all([
63
- viewContract.read.getTroveInfo([address]),
64
- collSurplusPoolContract.read.getCollateral([address]),
65
- troveManagerContract.read.getBorrowingRateWithDecay(),
66
- priceFeedContract.read.fetchPrice(),
67
- activePoolContract.read.getETH(),
68
- activePoolContract.read.getLUSDDebt(),
69
- _getDebtInFront(viewContract, address),
63
+ viewContract.read.getTroveInfo([address], setViemBlockNumber(blockNumber)),
64
+ collSurplusPoolContract.read.getCollateral([address], setViemBlockNumber(blockNumber)),
65
+ troveManagerContract.read.getBorrowingRateWithDecay(setViemBlockNumber(blockNumber)),
66
+ priceFeedContract.read.fetchPrice(setViemBlockNumber(blockNumber)),
67
+ activePoolContract.read.getETH(setViemBlockNumber(blockNumber)),
68
+ activePoolContract.read.getLUSDDebt(setViemBlockNumber(blockNumber)),
69
+ _getDebtInFront(viewContract, address, '0', 2000, blockNumber),
70
70
  ]);
71
71
  const recoveryMode = troveInfo[6];
72
72
  const minCollateralRatio = recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO;
@@ -100,19 +100,19 @@ export const _getLiquityTroveInfo = (provider, network, address) => __awaiter(vo
100
100
  };
101
101
  return payload;
102
102
  });
103
- export const getLiquityTroveInfo = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () { return _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address); });
104
- export const getLiquityStakingData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
103
+ export const getLiquityTroveInfo = (provider_1, network_1, address_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, ...args_1], void 0, function* (provider, network, address, blockNumber = 'latest') { return _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address, blockNumber); });
104
+ export const getLiquityStakingData = (provider_1, network_1, address_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, ...args_1], void 0, function* (provider, network, address, blockNumber = 'latest') {
105
105
  const lqtyStakingView = LiquityLQTYStakingViem(provider, network);
106
106
  const stabilityPoolView = LiquityStabilityPoolViem(provider, network);
107
107
  const [stakes, pendingETHGain, pendingLUSDGain, totalLQTYStakes, stabilityPoolETHGain, stabilityPoolLQTYGain, compoundedLUSDDeposit, totalLUSDDeposits,] = yield Promise.all([
108
- lqtyStakingView.read.stakes([address]),
109
- lqtyStakingView.read.getPendingETHGain([address]),
110
- lqtyStakingView.read.getPendingLUSDGain([address]),
111
- lqtyStakingView.read.totalLQTYStaked(),
112
- stabilityPoolView.read.getDepositorETHGain([address]),
113
- stabilityPoolView.read.getDepositorLQTYGain([address]),
114
- stabilityPoolView.read.getCompoundedLUSDDeposit([address]),
115
- stabilityPoolView.read.getTotalLUSDDeposits(),
108
+ lqtyStakingView.read.stakes([address], setViemBlockNumber(blockNumber)),
109
+ lqtyStakingView.read.getPendingETHGain([address], setViemBlockNumber(blockNumber)),
110
+ lqtyStakingView.read.getPendingLUSDGain([address], setViemBlockNumber(blockNumber)),
111
+ lqtyStakingView.read.totalLQTYStaked(setViemBlockNumber(blockNumber)),
112
+ stabilityPoolView.read.getDepositorETHGain([address], setViemBlockNumber(blockNumber)),
113
+ stabilityPoolView.read.getDepositorLQTYGain([address], setViemBlockNumber(blockNumber)),
114
+ stabilityPoolView.read.getCompoundedLUSDDeposit([address], setViemBlockNumber(blockNumber)),
115
+ stabilityPoolView.read.getTotalLUSDDeposits(setViemBlockNumber(blockNumber)),
116
116
  ]);
117
117
  const totalLUSDDeposited = getEthAmountForDecimals(totalLUSDDeposits, 18);
118
118
  const totalLQTYStaked = getEthAmountForDecimals(totalLQTYStakes, 18);
@@ -1,6 +1,6 @@
1
1
  import { Client, PublicClient } from 'viem';
2
- import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
- import { LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2Versions } from '../types';
2
+ import { Blockish, EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
+ import { LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2TroveData, LiquityV2Versions } from '../types';
4
4
  export type SPYieldGainParameters = {
5
5
  P: string;
6
6
  aggWeightedDebtSum: string;
@@ -9,8 +9,8 @@ export type SPYieldGainParameters = {
9
9
  totalBoldDeposits: string;
10
10
  yieldGainsPending: string;
11
11
  };
12
- export declare const _getLiquityV2MarketData: (provider: Client, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo) => Promise<LiquityV2MarketData>;
13
- export declare const getLiquityV2MarketData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo) => Promise<LiquityV2MarketData>;
12
+ export declare const _getLiquityV2MarketData: (provider: Client, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, blockNumber?: Blockish) => Promise<LiquityV2MarketData>;
13
+ export declare const getLiquityV2MarketData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, blockNumber?: Blockish) => Promise<LiquityV2MarketData>;
14
14
  export declare const nftContractCreationBlockMapping: {
15
15
  liquityv2eth: number;
16
16
  liquityv2wsteth: number;
@@ -19,6 +19,11 @@ export declare const nftContractCreationBlockMapping: {
19
19
  liquityv2wstethlegacy: number;
20
20
  liquityv2rethlegacy: number;
21
21
  };
22
+ /**
23
+ * The trove ids of several accounts in one market: the market's NFT transfers are read once for all of them, rather
24
+ * than once per account as _getLiquityV2UserTroveIds does.
25
+ */
26
+ export declare const _getLiquityV2UsersTroveIds: (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, accounts: EthAddress[]) => Promise<Record<EthAddress, string[]>>;
22
27
  export declare const _getLiquityV2UserTroveIds: (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress) => Promise<{
23
28
  troves: {
24
29
  troveId: string;
@@ -32,45 +37,25 @@ export declare const getLiquityV2UserTroveIds: (provider: EthereumProvider, netw
32
37
  nextFreeTroveIndex: string;
33
38
  }>;
34
39
  export declare const calculateDebtInFrontLiquityV2: (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, allMarketsUnbackedDebts: Record<LiquityV2Versions, string>, interestRateDebtInFront: string) => string;
35
- export declare const getDebtInFrontForInterestRateIncludingNewDebtLiquityV2: (newDebt: string, markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, interestRate: string) => Promise<string>;
36
- export declare const getDebtInFrontForInterestRateLiquityV2: (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: EthereumProvider, network: NetworkNumber, isLegacy: boolean, interestRate: string, debtInFrontBeingMoved?: string) => Promise<string>;
40
+ export declare const getDebtInFrontForInterestRateIncludingNewDebtLiquityV2: (newDebt: string, markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, interestRate: string, blockNumber?: Blockish) => Promise<string>;
41
+ export declare const getDebtInFrontForInterestRateLiquityV2: (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: EthereumProvider, network: NetworkNumber, isLegacy: boolean, interestRate: string, debtInFrontBeingMoved?: string, blockNumber?: Blockish) => Promise<string>;
37
42
  export declare const _getLiquityV2TroveData: (provider: Client, network: NetworkNumber, { selectedMarket, assetsData, troveId, allMarketsData, }: {
38
43
  selectedMarket: LiquityV2MarketInfo;
39
44
  assetsData: LiquityV2AssetsData;
40
45
  troveId: string;
41
46
  allMarketsData: Record<LiquityV2Versions, LiquityV2MarketData>;
42
- }, fetchDebtInFront?: boolean) => Promise<LiquityV2TroveData>;
47
+ }, fetchDebtInFront?: boolean, blockNumber?: Blockish) => Promise<LiquityV2TroveData>;
43
48
  export declare const getLiquityV2TroveData: (provider: EthereumProvider, network: NetworkNumber, { selectedMarket, assetsData, troveId, allMarketsData, }: {
44
49
  selectedMarket: LiquityV2MarketInfo;
45
50
  assetsData: LiquityV2AssetsData;
46
51
  troveId: string;
47
52
  allMarketsData: Record<LiquityV2Versions, LiquityV2MarketData>;
48
- }, fetchDebtInFront?: boolean) => Promise<LiquityV2TroveData>;
49
- export declare const getLiquityV2ClaimableCollateral: (collSurplusPoolAddress: EthAddress, account: EthAddress, provider: EthereumProvider, network: NetworkNumber) => Promise<string>;
53
+ }, fetchDebtInFront?: boolean, blockNumber?: Blockish) => Promise<LiquityV2TroveData>;
54
+ export declare const getLiquityV2ClaimableCollateral: (collSurplusPoolAddress: EthAddress, account: EthAddress, provider: EthereumProvider, network: NetworkNumber, blockNumber?: Blockish) => Promise<string>;
50
55
  export type sBoldYieldParameters = {
51
56
  WETH: string;
52
57
  wsETH: string;
53
58
  rETH: string;
54
59
  };
55
- export declare const getLiquityV2Staking: (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => Promise<{
56
- totalBOLDDeposited: string;
57
- stakedBOLDBalance: string;
58
- stabilityRewardColl: string;
59
- stabilityRewardYield: string;
60
- showStakingBalances: boolean;
61
- debtTokenBalance: string;
62
- stabilityPoolApy: string;
63
- }>;
64
- export declare const getLiquitySAndYBold: (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => Promise<{
65
- spApy: string;
66
- yBoldApy: string;
67
- totalBoldDepositedSBold: string;
68
- boldRateSBold: string;
69
- maxWithdrawSBold: string;
70
- totalBoldDepositedYBold: string;
71
- boldRateYBold: string;
72
- maxWithdrawYBold: string;
73
- sBoldBalance: string;
74
- yBoldBalance: string;
75
- stYBoldBalance: string;
76
- }>;
60
+ export declare const getLiquityV2Staking: (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress, blockNumber?: Blockish) => Promise<LiquityV2StakingData>;
61
+ export declare const getLiquitySAndYBold: (provider: Client, network: NetworkNumber, markets: any, user: EthAddress, blockNumber?: Blockish) => Promise<LiquityV2SBoldYBoldData>;