@defisaver/positions-sdk 2.1.166 → 2.1.168

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 (88) hide show
  1. package/cjs/aaveV2/index.js +8 -29
  2. package/cjs/aaveV3/index.js +2 -31
  3. package/cjs/aaveV4/index.d.ts +25 -0
  4. package/cjs/aaveV4/index.js +4 -1
  5. package/cjs/compoundV2/index.d.ts +1 -1
  6. package/cjs/compoundV2/index.js +2 -2
  7. package/cjs/curveUsd/index.d.ts +1 -1
  8. package/cjs/curveUsd/index.js +6 -1
  9. package/cjs/fluid/index.js +13 -12
  10. package/cjs/helpers/aaveBalances.d.ts +5 -0
  11. package/cjs/helpers/aaveBalances.js +51 -0
  12. package/cjs/helpers/fluidBalances.d.ts +6 -0
  13. package/cjs/helpers/fluidBalances.js +36 -0
  14. package/cjs/liquityV2/index.d.ts +8 -0
  15. package/cjs/liquityV2/index.js +3 -3
  16. package/cjs/llamaLend/index.d.ts +1 -1
  17. package/cjs/llamaLend/index.js +6 -1
  18. package/cjs/markets/morphoBlue/index.d.ts +0 -2
  19. package/cjs/markets/morphoBlue/index.js +3 -20
  20. package/cjs/morphoMidnight/index.d.ts +1 -1
  21. package/cjs/morphoMidnight/index.js +6 -1
  22. package/cjs/portfolio/index.d.ts +1 -0
  23. package/cjs/portfolio/index.js +3 -0
  24. package/cjs/portfolio/lendingSummaries.d.ts +7 -0
  25. package/cjs/portfolio/lendingSummaries.js +262 -0
  26. package/cjs/portfolio/lendingSummaryTransport.d.ts +8 -0
  27. package/cjs/portfolio/lendingSummaryTransport.js +109 -0
  28. package/cjs/spark/index.js +2 -31
  29. package/cjs/types/index.d.ts +1 -0
  30. package/cjs/types/index.js +1 -0
  31. package/cjs/types/lendingSummary.d.ts +34 -0
  32. package/cjs/types/lendingSummary.js +2 -0
  33. package/cjs/types/morphoBlue.d.ts +0 -1
  34. package/cjs/types/morphoBlue.js +0 -1
  35. package/esm/aaveV2/index.js +11 -32
  36. package/esm/aaveV3/index.js +3 -32
  37. package/esm/aaveV4/index.d.ts +25 -0
  38. package/esm/aaveV4/index.js +3 -1
  39. package/esm/compoundV2/index.d.ts +1 -1
  40. package/esm/compoundV2/index.js +2 -2
  41. package/esm/curveUsd/index.d.ts +1 -1
  42. package/esm/curveUsd/index.js +6 -1
  43. package/esm/fluid/index.js +13 -12
  44. package/esm/helpers/aaveBalances.d.ts +5 -0
  45. package/esm/helpers/aaveBalances.js +45 -0
  46. package/esm/helpers/fluidBalances.d.ts +6 -0
  47. package/esm/helpers/fluidBalances.js +28 -0
  48. package/esm/liquityV2/index.d.ts +8 -0
  49. package/esm/liquityV2/index.js +1 -1
  50. package/esm/llamaLend/index.d.ts +1 -1
  51. package/esm/llamaLend/index.js +6 -1
  52. package/esm/markets/morphoBlue/index.d.ts +0 -2
  53. package/esm/markets/morphoBlue/index.js +0 -16
  54. package/esm/morphoMidnight/index.d.ts +1 -1
  55. package/esm/morphoMidnight/index.js +6 -1
  56. package/esm/portfolio/index.d.ts +1 -0
  57. package/esm/portfolio/index.js +1 -0
  58. package/esm/portfolio/lendingSummaries.d.ts +7 -0
  59. package/esm/portfolio/lendingSummaries.js +256 -0
  60. package/esm/portfolio/lendingSummaryTransport.d.ts +8 -0
  61. package/esm/portfolio/lendingSummaryTransport.js +104 -0
  62. package/esm/spark/index.js +4 -33
  63. package/esm/types/index.d.ts +1 -0
  64. package/esm/types/index.js +1 -0
  65. package/esm/types/lendingSummary.d.ts +34 -0
  66. package/esm/types/lendingSummary.js +1 -0
  67. package/esm/types/morphoBlue.d.ts +0 -1
  68. package/esm/types/morphoBlue.js +0 -1
  69. package/package.json +1 -1
  70. package/src/aaveV2/index.ts +8 -48
  71. package/src/aaveV3/index.ts +2 -48
  72. package/src/aaveV4/index.ts +6 -1
  73. package/src/compoundV2/index.ts +2 -2
  74. package/src/curveUsd/index.ts +6 -1
  75. package/src/fluid/index.ts +13 -12
  76. package/src/helpers/aaveBalances.ts +41 -0
  77. package/src/helpers/fluidBalances.ts +34 -0
  78. package/src/liquityV2/index.ts +1 -1
  79. package/src/llamaLend/index.ts +6 -1
  80. package/src/markets/morphoBlue/index.ts +0 -16
  81. package/src/morphoMidnight/index.ts +6 -1
  82. package/src/portfolio/index.ts +2 -0
  83. package/src/portfolio/lendingSummaries.ts +216 -0
  84. package/src/portfolio/lendingSummaryTransport.ts +84 -0
  85. package/src/spark/index.ts +3 -49
  86. package/src/types/index.ts +2 -1
  87. package/src/types/lendingSummary.ts +41 -0
  88. package/src/types/morphoBlue.ts +0 -1
@@ -1,11 +1,12 @@
1
1
  import Dec from 'decimal.js';
2
2
  import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
3
3
  import { Client } from 'viem';
4
+ import { getAaveLikeBalances } from '../helpers/aaveBalances';
4
5
  import {
5
6
  Blockish, EthAddress, EthereumProvider, IncentiveKind, NetworkNumber, PositionBalances,
6
7
  } from '../types/common';
7
8
  import {
8
- ethToWeth, wethToEth, wethToEthByAddress,
9
+ ethToWeth, wethToEth,
9
10
  } from '../services/utils';
10
11
  import {
11
12
  calculateNetApy, getStakingApy, STAKING_ASSETS,
@@ -269,54 +270,7 @@ export const EMPTY_SPARK_DATA = {
269
270
  };
270
271
 
271
272
  export const _getSparkAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
272
- let balances: PositionBalances = {
273
- collateral: {},
274
- debt: {},
275
- };
276
-
277
- if (!address) {
278
- return balances;
279
- }
280
-
281
- const loanInfoContract = SparkViewContractViem(provider, network, block);
282
-
283
- const market = SPARK_V1(network);
284
- const marketAddress = market.providerAddress;
285
- // @ts-ignore
286
- const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
287
-
288
- // @ts-ignore
289
- const reserveTokens = await protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block)) as { symbol: string, tokenAddress: EthAddress }[];
290
- const symbols = reserveTokens.map(({ symbol }: { symbol: string }) => symbol);
291
- const _addresses = reserveTokens.map(({ tokenAddress }: { tokenAddress: EthAddress }) => tokenAddress);
292
-
293
-
294
- // split addresses in half to avoid gas limit by multicall
295
- const middleAddressIndex = Math.floor(_addresses.length / 2);
296
-
297
- const [tokenBalances1, tokenBalances2] = await Promise.all([
298
- loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(0, middleAddressIndex)], setViemBlockNumber(block)),
299
- loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(middleAddressIndex, _addresses.length)], setViemBlockNumber(block)),
300
- ]);
301
-
302
- const loanInfo = [...tokenBalances1, ...tokenBalances2];
303
-
304
- loanInfo.forEach((tokenInfo: any, i: number) => {
305
- const asset = wethToEth(symbols[i]);
306
- const assetAddr = wethToEthByAddress(_addresses[i], network).toLowerCase();
307
-
308
- balances = {
309
- collateral: {
310
- ...balances.collateral,
311
- [addressMapping ? assetAddr : asset]: tokenInfo.balance.toString(),
312
- },
313
- debt: {
314
- ...balances.debt,
315
- [addressMapping ? assetAddr : asset]: new Dec(tokenInfo.borrowsStable.toString()).add(tokenInfo.borrowsVariable.toString()).toString(),
316
- },
317
- };
318
- });
319
-
273
+ const balances = await getAaveLikeBalances(provider, network, block, addressMapping, address, SPARK_V1(network), 'SparkView');
320
274
  return balances;
321
275
  };
322
276
 
@@ -14,4 +14,5 @@ export * from './merit';
14
14
  export * from './merkl';
15
15
  export * from './savings';
16
16
  export * from './common';
17
- export * from './aaveV4';
17
+ export * from './aaveV4';
18
+ export * from './lendingSummary';
@@ -0,0 +1,41 @@
1
+ import { EthAddress, NetworkNumber } from './common';
2
+
3
+ export type LendingSummaryPosition = {
4
+ id: string;
5
+ protocol: string;
6
+ /** Estimated decimal USD values; null means unavailable, never a verified zero. */
7
+ suppliedUsd: string | null;
8
+ debtUsd: string | null;
9
+ };
10
+
11
+ export type WalletLendingSummary = {
12
+ status: 'complete' | 'partial' | 'failed';
13
+ positions: LendingSummaryPosition[];
14
+ protocols: string[];
15
+ /** Sum of known supply values; check valuationComplete before ranking by value. */
16
+ suppliedUsd: string;
17
+ valuationComplete: boolean;
18
+ errors: string[];
19
+ };
20
+
21
+ /** Resolve distinct token addresses to USD prices keyed by lowercase address.
22
+ * Native tokens use their wrapped address. Missing/invalid prices remain unavailable.
23
+ * Prices are current market estimates; balances may come from a historical/fork snapshot.
24
+ */
25
+ export type LendingSummaryPriceResolver = (
26
+ network: NetworkNumber, tokens: EthAddress[], signal?: AbortSignal,
27
+ ) => Promise<Record<string, string>>;
28
+
29
+ export type LendingSummaryOptions = {
30
+ resolvePrices: LendingSummaryPriceResolver;
31
+ signal?: AbortSignal;
32
+ /** Defaults to a snapshot of the provider's latest block. */
33
+ blockNumber?: bigint;
34
+ /** Use the smaller 2 KB calldata limit required by simulation providers. */
35
+ isSim?: boolean;
36
+ };
37
+
38
+ export type WalletLendingSummaries = {
39
+ summaries: Record<string, WalletLendingSummary>;
40
+ rateLimited: boolean;
41
+ };
@@ -6,7 +6,6 @@ export enum MorphoBlueVersions {
6
6
  // MAINNET
7
7
  MorphoBlueMKRDAI_777 = 'morphobluemkrdai_777', // MKR/DAI
8
8
  MorphoBlueWoEthEth_860 = 'morphobluewoetheth_860', // woETH/ETH
9
- MorphoBlueOsEthEth_860 = 'morphoblueosetheth_860', // osETH/ETH
10
9
  MorphoBlueWeEthEth_860 = 'morphoblueweetheth_860', // weETH/ETH
11
10
  MorphoBlueWstEthUSDC = 'morphobluewstethusdc', // wstETH/USDC
12
11
  MorphoBlueSDAIUSDC = 'morphobluesdaiusdc', // sDAI/USDC