@defisaver/positions-sdk 2.1.160-shifter-v2-dev → 2.1.161-portfolio-api-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 (118) hide show
  1. package/cjs/aaveV2/index.js +0 -2
  2. package/cjs/curveUsd/index.d.ts +2 -5
  3. package/cjs/curveUsd/index.js +15 -30
  4. package/cjs/fluid/index.d.ts +0 -5
  5. package/cjs/fluid/index.js +1 -36
  6. package/cjs/helpers/aaveHelpers/index.js +0 -3
  7. package/cjs/helpers/aaveV4Helpers/index.js +0 -1
  8. package/cjs/helpers/compoundHelpers/index.js +0 -2
  9. package/cjs/helpers/curveUsdHelpers/index.d.ts +1 -3
  10. package/cjs/helpers/curveUsdHelpers/index.js +2 -16
  11. package/cjs/helpers/fluidHelpers/index.js +0 -1
  12. package/cjs/helpers/liquityV2Helpers/index.js +0 -1
  13. package/cjs/helpers/llamaLendHelpers/index.js +0 -2
  14. package/cjs/helpers/makerHelpers/index.d.ts +1 -1
  15. package/cjs/helpers/makerHelpers/index.js +2 -2
  16. package/cjs/helpers/morphoBlueHelpers/index.js +0 -2
  17. package/cjs/helpers/morphoMidnightHelpers/index.js +0 -2
  18. package/cjs/helpers/sparkHelpers/index.js +0 -1
  19. package/cjs/liquity/index.js +2 -16
  20. package/cjs/maker/index.d.ts +2 -7
  21. package/cjs/maker/index.js +12 -45
  22. package/cjs/markets/index.d.ts +0 -1
  23. package/cjs/markets/index.js +1 -3
  24. package/cjs/portfolio/index.d.ts +1 -5
  25. package/cjs/portfolio/index.js +7 -277
  26. package/cjs/staking/staking.d.ts +0 -20
  27. package/cjs/staking/staking.js +1 -19
  28. package/cjs/types/aave.d.ts +15 -4
  29. package/cjs/types/aaveV4.d.ts +0 -1
  30. package/cjs/types/compound.d.ts +26 -4
  31. package/cjs/types/curveUsd.d.ts +9 -7
  32. package/cjs/types/fluid.d.ts +0 -1
  33. package/cjs/types/liquity.d.ts +0 -4
  34. package/cjs/types/liquityV2.d.ts +0 -2
  35. package/cjs/types/llamaLend.d.ts +12 -1
  36. package/cjs/types/maker.d.ts +0 -4
  37. package/cjs/types/morphoBlue.d.ts +2 -2
  38. package/cjs/types/morphoMidnight.d.ts +0 -1
  39. package/cjs/types/portfolio.d.ts +10 -26
  40. package/cjs/types/spark.d.ts +21 -3
  41. package/esm/aaveV2/index.js +0 -2
  42. package/esm/curveUsd/index.d.ts +2 -5
  43. package/esm/curveUsd/index.js +15 -30
  44. package/esm/fluid/index.d.ts +0 -5
  45. package/esm/fluid/index.js +0 -33
  46. package/esm/helpers/aaveHelpers/index.js +0 -3
  47. package/esm/helpers/aaveV4Helpers/index.js +0 -1
  48. package/esm/helpers/compoundHelpers/index.js +0 -2
  49. package/esm/helpers/curveUsdHelpers/index.d.ts +1 -3
  50. package/esm/helpers/curveUsdHelpers/index.js +2 -16
  51. package/esm/helpers/fluidHelpers/index.js +0 -1
  52. package/esm/helpers/liquityV2Helpers/index.js +0 -1
  53. package/esm/helpers/llamaLendHelpers/index.js +0 -2
  54. package/esm/helpers/makerHelpers/index.d.ts +1 -1
  55. package/esm/helpers/makerHelpers/index.js +2 -2
  56. package/esm/helpers/morphoBlueHelpers/index.js +0 -2
  57. package/esm/helpers/morphoMidnightHelpers/index.js +0 -2
  58. package/esm/helpers/sparkHelpers/index.js +0 -1
  59. package/esm/liquity/index.js +2 -16
  60. package/esm/maker/index.d.ts +2 -7
  61. package/esm/maker/index.js +13 -44
  62. package/esm/markets/index.d.ts +0 -1
  63. package/esm/markets/index.js +0 -1
  64. package/esm/portfolio/index.d.ts +1 -5
  65. package/esm/portfolio/index.js +10 -279
  66. package/esm/staking/staking.d.ts +0 -20
  67. package/esm/staking/staking.js +0 -17
  68. package/esm/types/aave.d.ts +15 -4
  69. package/esm/types/aaveV4.d.ts +0 -1
  70. package/esm/types/compound.d.ts +26 -4
  71. package/esm/types/curveUsd.d.ts +9 -7
  72. package/esm/types/fluid.d.ts +0 -1
  73. package/esm/types/liquity.d.ts +0 -4
  74. package/esm/types/liquityV2.d.ts +0 -2
  75. package/esm/types/llamaLend.d.ts +12 -1
  76. package/esm/types/maker.d.ts +0 -4
  77. package/esm/types/morphoBlue.d.ts +2 -2
  78. package/esm/types/morphoMidnight.d.ts +0 -1
  79. package/esm/types/portfolio.d.ts +10 -26
  80. package/esm/types/spark.d.ts +21 -3
  81. package/package.json +1 -1
  82. package/src/aaveV2/index.ts +0 -2
  83. package/src/curveUsd/index.ts +16 -33
  84. package/src/fluid/index.ts +0 -40
  85. package/src/helpers/aaveHelpers/index.ts +0 -3
  86. package/src/helpers/aaveV4Helpers/index.ts +0 -1
  87. package/src/helpers/compoundHelpers/index.ts +0 -2
  88. package/src/helpers/curveUsdHelpers/index.ts +2 -23
  89. package/src/helpers/fluidHelpers/index.ts +0 -1
  90. package/src/helpers/liquityV2Helpers/index.ts +0 -1
  91. package/src/helpers/llamaLendHelpers/index.ts +0 -2
  92. package/src/helpers/makerHelpers/index.ts +1 -2
  93. package/src/helpers/morphoBlueHelpers/index.ts +0 -2
  94. package/src/helpers/morphoMidnightHelpers/index.ts +0 -2
  95. package/src/helpers/sparkHelpers/index.ts +0 -1
  96. package/src/liquity/index.ts +2 -17
  97. package/src/maker/index.ts +29 -77
  98. package/src/markets/index.ts +1 -2
  99. package/src/portfolio/index.ts +8 -261
  100. package/src/staking/staking.ts +0 -28
  101. package/src/types/aave.ts +18 -4
  102. package/src/types/aaveV4.ts +0 -1
  103. package/src/types/compound.ts +38 -4
  104. package/src/types/curveUsd.ts +17 -8
  105. package/src/types/fluid.ts +0 -1
  106. package/src/types/liquity.ts +0 -6
  107. package/src/types/liquityV2.ts +0 -2
  108. package/src/types/llamaLend.ts +19 -1
  109. package/src/types/maker.ts +0 -6
  110. package/src/types/morphoBlue.ts +3 -2
  111. package/src/types/morphoMidnight.ts +0 -1
  112. package/src/types/portfolio.ts +12 -31
  113. package/src/types/spark.ts +25 -3
  114. package/cjs/markets/maker/index.d.ts +0 -1
  115. package/cjs/markets/maker/index.js +0 -13
  116. package/esm/markets/maker/index.d.ts +0 -1
  117. package/esm/markets/maker/index.js +0 -10
  118. package/src/markets/maker/index.ts +0 -10
@@ -8,14 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
- import { assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset, stringToBytes, } from '@defisaver/tokens';
11
+ import { assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset, } from '@defisaver/tokens';
12
12
  import { getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem, } from '../contracts';
13
- import { CdpType, } from '../types';
13
+ import { CdpType } from '../types';
14
14
  import { wethToEth } from '../services/utils';
15
15
  import { parseCollateralInfo } from '../helpers/makerHelpers';
16
16
  import { getViemProvider, setViemBlockNumber } from '../services/viem';
17
17
  import { getExposure } from '../moneymarket';
18
- import { calculateNetApyFromRates, getStakingApy, STAKING_ASSETS } from '../staking';
19
18
  export const _getMakerAccountBalances = (provider, network, block, addressMapping, cdpId, _managerAddress) => __awaiter(void 0, void 0, void 0, function* () {
20
19
  let balances = {
21
20
  collateral: {},
@@ -39,7 +38,7 @@ export const _getMakerAccountBalances = (provider, network, block, addressMappin
39
38
  // [urn, owner, userAddr, ilk, collateral, debt]
40
39
  const cdpInfo = yield viewContract.read.getCdpInfo((needsIlk ? [managerAddress, cdpId, ilk] : [cdpId]), setViemBlockNumber(block));
41
40
  cdpInfo.ilk = cdpInfo[3];
42
- const [par, [_, mat], [artGlobal, rate, spot, line, dust], [duty], futureRate, chop,] = yield Promise.all([
41
+ const [par, [_, mat], [artGlobal, rate, spot, line], [duty], futureRate, chop,] = yield Promise.all([
43
42
  spotterContract.read.par(setViemBlockNumber(block)),
44
43
  spotterContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
45
44
  vatContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
@@ -47,7 +46,7 @@ export const _getMakerAccountBalances = (provider, network, block, addressMappin
47
46
  jugContract.read.drip(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
48
47
  dogContract.read.chop(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
49
48
  ]);
50
- const ilkInfo = parseCollateralInfo(needsIlk ? ilk : cdpInfo.ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), dust.toString(), duty.toString(), futureRate.toString(), chop.toString());
49
+ const ilkInfo = parseCollateralInfo(needsIlk ? ilk : cdpInfo.ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), duty.toString(), futureRate.toString(), chop.toString());
51
50
  const collateral = cdpInfo[4];
52
51
  const debt = cdpInfo[5];
53
52
  const asset = wethToEth(ilkToAsset(needsIlk ? ilk : cdpInfo.ilk));
@@ -81,38 +80,22 @@ export const _getUserCdps = (provider, network, userAddress) => __awaiter(void 0
81
80
  return parsedStandardCdps;
82
81
  });
83
82
  export const getUserCdps = (provider, network, userAddress) => __awaiter(void 0, void 0, void 0, function* () { return _getUserCdps(getViemProvider(provider, network), network, userAddress); });
84
- export const _getMakerIlksData = (provider, network, ilkLabels) => __awaiter(void 0, void 0, void 0, function* () {
83
+ export const _getMakerCdpData = (provider, network, cdp) => __awaiter(void 0, void 0, void 0, function* () {
85
84
  const vatContract = McdVatContractViem(provider, network);
86
85
  const spotterContract = McdSpotterContractViem(provider, network);
87
86
  const dogContract = McdDogContractViem(provider, network);
88
87
  const jugContract = McdJugContractViem(provider, network);
89
- const par = yield spotterContract.read.par();
90
- const ilksInfo = yield Promise.all(ilkLabels.map((ilkLabel) => __awaiter(void 0, void 0, void 0, function* () {
91
- const ilk = stringToBytes(ilkLabel);
92
- const [[_, mat], [artGlobal, rate, spot, line, dust], [duty], futureRate, chop,] = yield Promise.all([
93
- spotterContract.read.ilks([ilk]),
94
- vatContract.read.ilks([ilk]),
95
- jugContract.read.ilks([ilk]),
96
- jugContract.read.drip([ilk]),
97
- dogContract.read.chop([ilk]),
98
- ]);
99
- return parseCollateralInfo(ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), dust.toString(), duty.toString(), futureRate.toString(), chop.toString());
100
- })));
101
- return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
102
- });
103
- export const getMakerIlksData = (provider, network, ilkLabels) => __awaiter(void 0, void 0, void 0, function* () { return _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels); });
104
- /**
105
- * @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
106
- */
107
- export const _getMakerCdpData = (provider, network, cdp, ilkInfo) => __awaiter(void 0, void 0, void 0, function* () {
108
- const vatContract = McdVatContractViem(provider, network);
109
- const [[ink, art], coll, fetchedIlkInfo, collStakingApy,] = yield Promise.all([
88
+ const [[ink, art], coll, par, [_, mat], [artGlobal, rate, spot, line], [duty], futureRate, chop,] = yield Promise.all([
110
89
  vatContract.read.urns([cdp.ilk, cdp.urn]),
111
90
  vatContract.read.gem([cdp.ilk, cdp.urn]),
112
- ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel]).then((ilks) => ilks[cdp.ilkLabel]),
113
- STAKING_ASSETS.includes(cdp.asset) ? getStakingApy(cdp.asset) : Promise.resolve('0'),
91
+ spotterContract.read.par(),
92
+ spotterContract.read.ilks([cdp.ilk]),
93
+ vatContract.read.ilks([cdp.ilk]),
94
+ jugContract.read.ilks([cdp.ilk]),
95
+ jugContract.read.drip([cdp.ilk]),
96
+ dogContract.read.chop([cdp.ilk]),
114
97
  ]);
115
- const collInfo = fetchedIlkInfo;
98
+ const collInfo = parseCollateralInfo(cdp.ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), duty.toString(), futureRate.toString(), chop.toString());
116
99
  const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
117
100
  const collateralUsd = new Dec(collateral).mul(collInfo.assetPrice).toString();
118
101
  const debt = new Dec(art).times(collInfo.currentRate).div(1e27).floor()
@@ -124,17 +107,7 @@ export const _getMakerCdpData = (provider, network, cdp, ilkInfo) => __awaiter(v
124
107
  .toString();
125
108
  if (new Dec(debt).eq(0))
126
109
  ratio = '0';
127
- // Collateral ratio rebased so 100 sits on the ilk's liquidation ratio (normalised safety ratio).
128
- const safetyRatio = +collInfo.liqPercent > 0 ? new Dec(ratio).div(collInfo.liqPercent).mul(100).toString() : '0';
129
110
  const debtTooLow = new Dec(debt).gt(0) && new Dec(assetAmountInEth(debt, 'DAI')).lt(collInfo.minDebt);
130
- // DAI debt accrues the ilk's stability fee. Collateral earns nothing inside the vault, except for the
131
- // native yield of staked collateral (e.g. wstETH), which is tracked as an incentive.
132
- const { netApy, totalInterestUsd, incentiveUsd } = calculateNetApyFromRates({
133
- suppliedUsd: collateralUsd,
134
- borrowedUsd: assetAmountInEth(debt, 'DAI'),
135
- borrowRate: collInfo.stabilityFee.toString(),
136
- incentives: [{ apy: collStakingApy, amountUsd: collateralUsd }],
137
- });
138
111
  return {
139
112
  owner: cdp.owner,
140
113
  id: cdp.id.toString(),
@@ -153,7 +126,6 @@ export const _getMakerCdpData = (provider, network, cdp, ilkInfo) => __awaiter(v
153
126
  debtAssetMarketPrice: '1',
154
127
  liquidationPrice,
155
128
  ratio,
156
- safetyRatio,
157
129
  liqRatio: collInfo.liqRatio.toString(),
158
130
  liqPercent: parseFloat(collInfo.liqPercent.toString()),
159
131
  assetPrice: collInfo.assetPrice,
@@ -169,9 +141,6 @@ export const _getMakerCdpData = (provider, network, cdp, ilkInfo) => __awaiter(v
169
141
  liquidationFee: collInfo.liquidationFee,
170
142
  lastUpdated: Date.now(),
171
143
  exposure: getExposure(assetAmountInEth(debt, 'DAI'), collateralUsd),
172
- netApy,
173
- totalInterestUsd,
174
- incentiveUsd,
175
144
  };
176
145
  });
177
146
  export const getMakerCdpData = (provider, network, cdp) => __awaiter(void 0, void 0, void 0, function* () { return _getMakerCdpData(getViemProvider(provider, network), network, cdp); });
@@ -8,4 +8,3 @@ export { LlamaLendMarkets } from './llamaLend';
8
8
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
9
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
10
10
  export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
11
- export { MakerActiveIlks } from './maker';
@@ -8,4 +8,3 @@ export { LlamaLendMarkets } from './llamaLend';
8
8
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
9
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
10
10
  export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
11
- export { MakerActiveIlks } from './maker';
@@ -1,13 +1,9 @@
1
1
  import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
2
- import { PortfolioMarketsData, PortfolioPositionsData } from '../types';
2
+ import { PortfolioPositionsData } from '../types';
3
3
  export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
4
4
  positions: PortfolioPositionsData;
5
5
  stakingPositions: any;
6
6
  rewardsData: any;
7
7
  markets: any;
8
8
  }>;
9
- export declare function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
10
- positions: PortfolioPositionsData;
11
- markets: PortfolioMarketsData;
12
- }>;
13
9
  export * from './discovery';
@@ -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 { NetworkNumber } from '../types/common';
12
- import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LiquityV2Markets, LlamaLendMarkets, MakerActiveIlks, MorphoBlueMarkets, MorphoMidnightMarkets, SparkMarkets, } from '../markets';
12
+ import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, MorphoMidnightMarkets, SparkMarkets, } from '../markets';
13
13
  import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData, getMorphoEarn } from '../morphoBlue';
14
14
  import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
15
15
  import { AaveVersions, CompoundVersions, } from '../types';
@@ -19,13 +19,13 @@ import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
19
19
  import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
20
20
  import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
21
21
  import { ZERO_ADDRESS } from '../constants';
22
- import { _getMakerCdpData, _getMakerIlksData, _getUserCdps } from '../maker';
22
+ import { _getMakerCdpData, _getUserCdps } from '../maker';
23
23
  import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
24
24
  import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
25
25
  import { getViemProvider } from '../services/viem';
26
26
  import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
27
27
  import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
28
- import { _getAllFluidMarketDataPortfolio, _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
28
+ import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
29
29
  import { getUmbrellaData } from '../umbrella';
30
30
  import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
31
31
  import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
@@ -501,9 +501,11 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
501
501
  positions[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
502
502
  }
503
503
  }))).flat(),
504
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
504
+ // flatMap, not map: each CDP's fetch has to be one of the awaited promises, or getPortfolioData can return
505
+ // before a vault's data lands and the vault is missing from the result.
506
+ ...addresses.flatMap((address) => {
505
507
  var _a;
506
- return (_a = makerCdps[address.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
508
+ return ((_a = makerCdps[address.toLowerCase()]) !== null && _a !== void 0 ? _a : []).map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
507
509
  try {
508
510
  const cdpData = yield _getMakerCdpData(client, network, cdpInfo);
509
511
  if (cdpData) {
@@ -515,7 +517,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
515
517
  positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
516
518
  }
517
519
  }));
518
- })).flat(),
520
+ }),
519
521
  ...aaveV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
520
522
  try {
521
523
  const accData = yield _getAaveV2AccountData(client, network, address, aaveV2MarketsData[market.value].assetsData, market);
@@ -553,9 +555,9 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
553
555
  })),
554
556
  ...crvUsdMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
555
557
  try {
556
- const accData = yield _getCurveUsdUserData(client, network, address, market, crvUsdMarketsData[market.value].activeBand, crvUsdMarketsData[market.value].borrowRate);
558
+ const accData = yield _getCurveUsdUserData(client, network, address, market, crvUsdMarketsData[market.value].activeBand);
557
559
  if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
558
- positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: accData };
560
+ positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: crvUsdMarketsData[market.value].borrowRate }) };
559
561
  }
560
562
  }
561
563
  catch (error) {
@@ -599,275 +601,4 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
599
601
  };
600
602
  });
601
603
  }
602
- export function getShifterPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
603
- return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
604
- const isMainnet = network === NetworkNumber.Eth;
605
- const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
606
- const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
607
- const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
608
- const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
609
- const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
610
- const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
611
- const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
612
- const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
613
- const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
614
- const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
615
- const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
616
- const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 2500000 } } }];
617
- const client = getViemProvider(provider, ...args);
618
- const defaultClient = getViemProvider(defaultProvider, ...args);
619
- const markets = {
620
- morphoMarketsData: {},
621
- morphoMidnightMarketsData: {}, // Morpho Midnight is not fetched for the shifter; key kept so the payload shape is stable
622
- compoundV3MarketsData: {},
623
- sparkMarketsData: {},
624
- aaveV3MarketsData: {},
625
- aaveV2MarketsData: {},
626
- compoundV2MarketsData: {},
627
- crvUsdMarketsData: {},
628
- llamaLendMarketsData: {},
629
- liquityV2MarketsData: {},
630
- aaveV4SpokesData: {},
631
- fluidMarketsData: {},
632
- makerMarketsData: {},
633
- };
634
- const makerCdps = {};
635
- const positions = {};
636
- for (const address of addresses) {
637
- positions[address.toLowerCase()] = {
638
- aaveV3: {},
639
- aaveV4: {},
640
- morphoBlue: {},
641
- morphoMidnight: {}, // not fetched for the shifter (see markets above)
642
- compoundV3: {},
643
- spark: {},
644
- maker: {},
645
- aaveV2: {},
646
- compoundV2: {},
647
- liquity: {},
648
- crvUsd: {},
649
- llamaLend: {},
650
- fluid: {
651
- error: '',
652
- data: {},
653
- },
654
- };
655
- }
656
- yield Promise.allSettled([
657
- // === MARKET DATA (needs to be fetched first) ===
658
- ...morphoMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
659
- markets.morphoMarketsData[market.value] = yield _getMorphoBluePortfolioMarketData(client, network, market);
660
- })),
661
- ...compoundV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
662
- markets.compoundV3MarketsData[market.value] = yield _getCompoundV3MarketsData(client, network, market, defaultClient);
663
- })),
664
- ...sparkMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
665
- markets.sparkMarketsData[market.value] = yield _getSparkMarketsData(client, network, market);
666
- })),
667
- ...aaveV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
668
- markets.aaveV3MarketsData[market.value] = yield _getAaveV3MarketData(client, network, market);
669
- })),
670
- ...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
671
- markets.aaveV4SpokesData[spoke.value] = yield _getAaveV4SpokeData(client, network, spoke);
672
- })),
673
- ...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
674
- markets.aaveV2MarketsData[market.value] = yield _getAaveV2MarketsData(client, network, market);
675
- })),
676
- ...compoundV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
677
- markets.compoundV2MarketsData[market.value] = yield _getCompoundV2MarketsData(client, network);
678
- })),
679
- ...crvUsdMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
680
- markets.crvUsdMarketsData[market.value] = yield _getCurveUsdGlobalData(client, network, market);
681
- })),
682
- ...llamaLendMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
683
- markets.llamaLendMarketsData[market.value] = yield _getLlamaLendGlobalData(client, network, market);
684
- })),
685
- ...liquityV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
686
- markets.liquityV2MarketsData[market.value] = yield _getLiquityV2MarketData(client, network, market);
687
- })),
688
- (() => __awaiter(this, void 0, void 0, function* () {
689
- if (!isFluidSupported)
690
- return;
691
- try {
692
- markets.fluidMarketsData = yield _getAllFluidMarketDataPortfolio(client, network);
693
- }
694
- catch (error) {
695
- console.error('Error fetching Fluid markets data:', error);
696
- }
697
- }))(),
698
- (() => __awaiter(this, void 0, void 0, function* () {
699
- if (!isMainnet)
700
- return; // Maker CDPs are only available on mainnet
701
- try {
702
- markets.makerMarketsData = yield _getMakerIlksData(client, network, MakerActiveIlks);
703
- }
704
- catch (error) {
705
- console.error('Error fetching Maker ilks data:', error);
706
- }
707
- }))(),
708
- // === INDEPENDENT USER DATA (doesn't depend on market data) ===
709
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
710
- if (!isMainnet)
711
- return; // Maker CDPs are only available on mainnet
712
- const makerCdp = yield _getUserCdps(client, network, address);
713
- makerCdps[address.toLowerCase()] = makerCdp;
714
- })),
715
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
716
- try {
717
- if (!isFluidSupported)
718
- return; // Fluid is not available on Optimism
719
- const userPositions = (yield _getUserPositionsPortfolio(client, network, address));
720
- for (const position of userPositions) {
721
- if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
722
- positions[address.toLowerCase()].fluid.data[position.userData.nftId] = position.userData;
723
- }
724
- }
725
- }
726
- catch (error) {
727
- console.error(`Error fetching Fluid positions for address ${address}:`, error);
728
- positions[address.toLowerCase()].fluid = {
729
- error: `Error fetching Fluid positions for address ${address}`,
730
- data: {},
731
- };
732
- }
733
- })),
734
- ]);
735
- yield Promise.all([
736
- ...aaveV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
737
- try {
738
- const accData = yield _getAaveV3AccountData(client, network, address, Object.assign({ selectedMarket: market }, markets.aaveV3MarketsData[market.value]));
739
- if (new Dec(accData.suppliedUsd).gt(0))
740
- positions[address.toLowerCase()].aaveV3[market.value] = { error: '', data: accData };
741
- }
742
- catch (error) {
743
- console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
744
- positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
745
- }
746
- }))).flat(),
747
- ...aaveV4Spokes.map((spoke) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
748
- try {
749
- const accData = yield _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address);
750
- if (new Dec(accData.suppliedUsd).gt(0))
751
- positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
752
- }
753
- catch (error) {
754
- console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
755
- positions[address.toLowerCase()].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
756
- }
757
- }))).flat(),
758
- ...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
759
- try {
760
- const accData = yield _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value]);
761
- if (new Dec(accData.suppliedUsd).gt(0))
762
- positions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: accData };
763
- }
764
- catch (error) {
765
- console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
766
- positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
767
- }
768
- }))).flat(),
769
- ...compoundV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
770
- try {
771
- const accData = yield _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData });
772
- if (new Dec(accData.suppliedUsd).gt(0))
773
- positions[address.toLowerCase()].compoundV3[market.value] = { error: '', data: accData };
774
- }
775
- catch (error) {
776
- console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
777
- positions[address.toLowerCase()].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
778
- }
779
- }))).flat(),
780
- ...sparkMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
781
- try {
782
- const accData = yield _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData });
783
- if (new Dec(accData.suppliedUsd).gt(0))
784
- positions[address.toLowerCase()].spark[market.value] = { error: '', data: accData };
785
- }
786
- catch (error) {
787
- console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
788
- positions[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
789
- }
790
- }))).flat(),
791
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
792
- var _a;
793
- return (_a = makerCdps[address.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
794
- try {
795
- // reuse ilk data fetched for the markets payload; ilks outside the active set are fetched on demand
796
- const cdpData = yield _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]);
797
- if (cdpData) {
798
- positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
799
- }
800
- }
801
- catch (error) {
802
- console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
803
- positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
804
- }
805
- }));
806
- })).flat(),
807
- ...aaveV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
808
- try {
809
- const accData = yield _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market);
810
- if (new Dec(accData.suppliedUsd).gt(0))
811
- positions[address.toLowerCase()].aaveV2[market.value] = { error: '', data: accData };
812
- }
813
- catch (error) {
814
- console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
815
- positions[address.toLowerCase()].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
816
- }
817
- }))).flat(),
818
- ...compoundV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
819
- try {
820
- const accData = yield _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData);
821
- if (new Dec(accData.suppliedUsd).gt(0))
822
- positions[address.toLowerCase()].compoundV2[market.value] = { error: '', data: accData };
823
- }
824
- catch (error) {
825
- console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
826
- positions[address.toLowerCase()].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
827
- }
828
- }))).flat(),
829
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
830
- try {
831
- if (!isMainnet)
832
- return; // Liquity trove info is only available on mainnet
833
- const troveInfo = yield _getLiquityTroveInfo(client, network, address);
834
- if (new Dec(troveInfo.collateral).gt(0))
835
- positions[address.toLowerCase()].liquity = { error: '', data: troveInfo };
836
- }
837
- catch (error) {
838
- console.error(`Error fetching Liquity trove info for address ${address}:`, error);
839
- positions[address.toLowerCase()].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
840
- }
841
- })),
842
- ...crvUsdMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
843
- try {
844
- const accData = yield _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate);
845
- if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
846
- positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: accData };
847
- }
848
- }
849
- catch (error) {
850
- console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
851
- positions[address.toLowerCase()].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
852
- }
853
- }))).flat(),
854
- ...llamaLendMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
855
- try {
856
- const accData = yield _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value]);
857
- if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
858
- positions[address.toLowerCase()].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: markets.llamaLendMarketsData[market.value].borrowRate }) };
859
- }
860
- }
861
- catch (error) {
862
- console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
863
- positions[address.toLowerCase()].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
864
- }
865
- }))).flat(),
866
- ]);
867
- return {
868
- positions,
869
- markets,
870
- };
871
- });
872
- }
873
604
  export * from './discovery';
@@ -3,26 +3,6 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
3
3
  export declare const STAKING_ASSETS: string[];
4
4
  export declare const getStakingApy: ((asset: string, network?: number) => Promise<string>) & memoize.Memoized<(asset: string, network?: number) => Promise<string>>;
5
5
  export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
6
- /**
7
- * Net APY for positions that have a single known borrow rate (and optionally a single supply rate)
8
- * instead of per-asset `assetsData` to feed into `calculateNetApy` (Maker, crvUSD, Liquity v1).
9
- * All rates are yearly percentages that are already compounded. `incentives` are extra yields
10
- * (e.g. the native staking yield of the collateral) applied to their own USD base and summed into `incentiveUsd`.
11
- */
12
- export declare const calculateNetApyFromRates: ({ suppliedUsd, borrowedUsd, supplyRate, borrowRate, incentives, }: {
13
- suppliedUsd: string;
14
- borrowedUsd: string;
15
- supplyRate?: string;
16
- borrowRate?: string;
17
- incentives?: {
18
- apy: string;
19
- amountUsd: string;
20
- }[];
21
- }) => {
22
- netApy: string;
23
- totalInterestUsd: string;
24
- incentiveUsd: string;
25
- };
26
6
  export declare const calculateNetApy: ({ usedAssets, assetsData, optionalData, }: {
27
7
  usedAssets: MMUsedAssets;
28
8
  assetsData: MMAssetsData;
@@ -182,23 +182,6 @@ export const calculateInterestEarned = (principal, interest, type, apy = false)
182
182
  }
183
183
  return (+principal * (Math.pow(((1 + (+interest / 100) / BLOCKS_IN_A_YEAR)), (BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
184
184
  };
185
- /**
186
- * Net APY for positions that have a single known borrow rate (and optionally a single supply rate)
187
- * instead of per-asset `assetsData` to feed into `calculateNetApy` (Maker, crvUSD, Liquity v1).
188
- * All rates are yearly percentages that are already compounded. `incentives` are extra yields
189
- * (e.g. the native staking yield of the collateral) applied to their own USD base and summed into `incentiveUsd`.
190
- */
191
- export const calculateNetApyFromRates = ({ suppliedUsd, borrowedUsd, supplyRate = '0', borrowRate = '0', incentives = [], }) => {
192
- const supplyInterest = new Dec(calculateInterestEarned(suppliedUsd, supplyRate, 'year', true));
193
- const borrowInterest = new Dec(calculateInterestEarned(borrowedUsd, borrowRate, 'year', true));
194
- const incentiveUsd = incentives
195
- .reduce((acc, { apy, amountUsd }) => acc.add(calculateInterestEarned(amountUsd, apy, 'year', true)), new Dec(0))
196
- .toString();
197
- const totalInterestUsd = supplyInterest.sub(borrowInterest).add(incentiveUsd).toString();
198
- const balance = new Dec(suppliedUsd).sub(borrowedUsd);
199
- const netApy = balance.isZero() ? '0' : new Dec(totalInterestUsd).div(balance).times(100).toString();
200
- return { netApy, totalInterestUsd, incentiveUsd };
201
- };
202
185
  export const calculateNetApy = ({ usedAssets, assetsData, optionalData, }) => {
203
186
  const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
204
187
  const acc = Object.assign({}, _acc);
@@ -1,4 +1,4 @@
1
- import { IncentiveData, LeverageType, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
1
+ import { EthAddress, IncentiveData, LeverageType, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
2
2
  export declare enum AaveVersions {
3
3
  AaveV1 = "v1",
4
4
  AaveV2 = "v2default",
@@ -84,6 +84,8 @@ export interface AaveV3AssetData extends AaveAssetData {
84
84
  liquidationBonus: string;
85
85
  supplyIncentives: IncentiveData[];
86
86
  borrowIncentives: IncentiveData[];
87
+ aTokenAddress?: EthAddress;
88
+ vTokenAddress?: EthAddress;
87
89
  }
88
90
  export type EModeCategoriesData = Record<number, EModeCategoryData>;
89
91
  export type AaveAssetsData<T> = {
@@ -121,12 +123,16 @@ export type AaveUsedAssets<T> = {
121
123
  };
122
124
  export type AaveV2UsedAssets = AaveUsedAssets<AaveV2UsedAsset>;
123
125
  export type AaveV3UsedAssets = AaveUsedAssets<AaveV3UsedAsset>;
124
- export interface AavePositionData extends MMPositionData {
126
+ /**
127
+ * Fields aaveAnyGetAggregatedPositionData adds to every Aave V2/V3 position at runtime, on top of those declared
128
+ * below. Optional, so code that builds a position by hand keeps compiling.
129
+ */
130
+ export type AavePositionAggregatedFields = Partial<Omit<AaveV3AggregatedPositionData, keyof MMPositionData | 'ratio' | 'collRatio' | 'safetyRatioWithLtvZeroFallback' | 'suppliedUsd' | 'borrowedUsd' | 'borrowLimitUsd' | 'suppliedCollateralUsd' | 'incentiveUsd' | 'totalInterestUsd'>>;
131
+ export interface AavePositionData extends MMPositionData, AavePositionAggregatedFields {
125
132
  ratio: string;
126
133
  minRatio: string;
127
134
  collRatio: string;
128
135
  safetyRatioWithLtvZeroFallback?: string;
129
- safetyRatio?: string;
130
136
  suppliedUsd: string;
131
137
  borrowedUsd: string;
132
138
  borrowLimitUsd: string;
@@ -139,6 +145,12 @@ export interface AavePositionData extends MMPositionData {
139
145
  }
140
146
  export interface AaveV2PositionData extends AavePositionData {
141
147
  usedAssets: AaveV2UsedAssets;
148
+ eModeCategory?: number;
149
+ isInIsolationMode?: boolean;
150
+ isInSiloedMode?: boolean;
151
+ eModeCategories?: {
152
+ [key: number]: EModeCategoryDataMapping;
153
+ };
142
154
  }
143
155
  export interface AaveV3PositionData extends AavePositionData {
144
156
  usedAssets: AaveV3UsedAssets;
@@ -160,7 +172,6 @@ export interface AaveV3AggregatedPositionData {
160
172
  collRatio: string;
161
173
  borrowLimitWithLtvZeroFallbackUsd: string;
162
174
  safetyRatioWithLtvZeroFallback: string;
163
- safetyRatio: string;
164
175
  netApy: string;
165
176
  incentiveUsd: string;
166
177
  totalInterestUsd: string;
@@ -169,7 +169,6 @@ export interface AaveV4AggregatedPositionData {
169
169
  leftToBorrowUsd: string;
170
170
  ratio: string;
171
171
  collRatio: string;
172
- safetyRatio: string;
173
172
  liqRatio: string;
174
173
  liqPercent: string;
175
174
  leveragedType: LeverageType;