@defisaver/positions-sdk 2.1.137 → 2.1.138

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 (76) hide show
  1. package/cjs/aaveV4/index.js +26 -10
  2. package/cjs/config/contracts.d.ts +0 -938
  3. package/cjs/config/contracts.js +1 -8
  4. package/cjs/contracts.d.ts +0 -23433
  5. package/cjs/contracts.js +2 -3
  6. package/cjs/helpers/index.d.ts +0 -1
  7. package/cjs/helpers/index.js +1 -2
  8. package/cjs/index.d.ts +1 -2
  9. package/cjs/index.js +1 -3
  10. package/cjs/markets/index.d.ts +0 -1
  11. package/cjs/markets/index.js +1 -3
  12. package/cjs/portfolio/discovery.d.ts +1 -1
  13. package/cjs/portfolio/discovery.js +1 -1
  14. package/cjs/portfolio/index.js +0 -32
  15. package/cjs/services/utils.d.ts +1 -0
  16. package/cjs/services/utils.js +3 -1
  17. package/cjs/staking/staking.js +1 -2
  18. package/cjs/types/aaveV4.d.ts +5 -0
  19. package/cjs/types/index.d.ts +0 -1
  20. package/cjs/types/index.js +0 -1
  21. package/cjs/types/portfolio.d.ts +0 -4
  22. package/esm/aaveV4/index.js +27 -11
  23. package/esm/config/contracts.d.ts +0 -938
  24. package/esm/config/contracts.js +0 -6
  25. package/esm/contracts.d.ts +0 -23433
  26. package/esm/contracts.js +0 -1
  27. package/esm/helpers/index.d.ts +0 -1
  28. package/esm/helpers/index.js +0 -1
  29. package/esm/index.d.ts +1 -2
  30. package/esm/index.js +1 -2
  31. package/esm/markets/index.d.ts +0 -1
  32. package/esm/markets/index.js +0 -1
  33. package/esm/portfolio/discovery.d.ts +1 -1
  34. package/esm/portfolio/discovery.js +1 -1
  35. package/esm/portfolio/index.js +1 -33
  36. package/esm/services/utils.d.ts +1 -0
  37. package/esm/services/utils.js +1 -0
  38. package/esm/staking/staking.js +1 -2
  39. package/esm/types/aaveV4.d.ts +5 -0
  40. package/esm/types/index.d.ts +0 -1
  41. package/esm/types/index.js +0 -1
  42. package/esm/types/portfolio.d.ts +0 -4
  43. package/package.json +1 -1
  44. package/src/aaveV4/index.ts +29 -11
  45. package/src/config/contracts.ts +0 -6
  46. package/src/contracts.ts +0 -1
  47. package/src/helpers/index.ts +0 -1
  48. package/src/index.ts +0 -2
  49. package/src/markets/index.ts +0 -1
  50. package/src/portfolio/discovery.ts +1 -1
  51. package/src/portfolio/index.ts +0 -33
  52. package/src/services/utils.ts +2 -0
  53. package/src/staking/staking.ts +1 -2
  54. package/src/types/aaveV4.ts +5 -0
  55. package/src/types/index.ts +0 -1
  56. package/src/types/portfolio.ts +0 -4
  57. package/cjs/eulerV2/index.d.ts +0 -47
  58. package/cjs/eulerV2/index.js +0 -225
  59. package/cjs/helpers/eulerHelpers/index.d.ts +0 -22
  60. package/cjs/helpers/eulerHelpers/index.js +0 -231
  61. package/cjs/markets/euler/index.d.ts +0 -8
  62. package/cjs/markets/euler/index.js +0 -30
  63. package/cjs/types/euler.d.ts +0 -153
  64. package/cjs/types/euler.js +0 -14
  65. package/esm/eulerV2/index.d.ts +0 -47
  66. package/esm/eulerV2/index.js +0 -215
  67. package/esm/helpers/eulerHelpers/index.d.ts +0 -22
  68. package/esm/helpers/eulerHelpers/index.js +0 -218
  69. package/esm/markets/euler/index.d.ts +0 -8
  70. package/esm/markets/euler/index.js +0 -24
  71. package/esm/types/euler.d.ts +0 -153
  72. package/esm/types/euler.js +0 -11
  73. package/src/eulerV2/index.ts +0 -331
  74. package/src/helpers/eulerHelpers/index.ts +0 -232
  75. package/src/markets/euler/index.ts +0 -27
  76. package/src/types/euler.ts +0 -178
@@ -84,16 +84,16 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
84
84
  };
85
85
  });
86
86
  const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
87
- var _a, _b, _c, _d, _e, _f;
87
+ var _a, _b, _c, _d, _e, _f, _g, _h;
88
88
  const assetInfo = (0, tokens_1.getAssetInfoByAddress)(reserveAsset.underlying, network);
89
89
  // `@defisaver/tokens` returns a placeholder ('?', decimals NaN) when the underlying is not in the
90
90
  // tokens package. Flag it so consumers can render it read-only instead of feeding NaN into amounts.
91
91
  const isUnsupported = assetInfo.symbol === '?';
92
92
  const symbol = (0, utils_1.wethToEth)(assetInfo.symbol);
93
+ // The hub registry only provides display metadata — a hub missing from it (newly deployed by
94
+ // Aave, SDK not yet updated) must not prevent the reserve from loading, so fall back to a
95
+ // generated label instead of failing.
93
96
  const hubInfo = (0, aaveV4_1.getAaveV4HubByAddress)(network, reserveAsset.hub);
94
- if (!hubInfo) {
95
- throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
96
- }
97
97
  const isStakingAsset = staking_1.STAKING_ASSETS.includes(symbol);
98
98
  const supplyIncentives = [];
99
99
  const borrowIncentives = [];
@@ -153,8 +153,8 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
153
153
  decimals: reserveAsset.decimals,
154
154
  isUnsupported,
155
155
  underlying: reserveAsset.underlying,
156
- hub: hubInfo.address,
157
- hubName: hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label,
156
+ hub: (_g = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.address) !== null && _g !== void 0 ? _g : reserveAsset.hub,
157
+ hubName: (_h = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label) !== null && _h !== void 0 ? _h : `Hub ${(0, utils_1.shortenAddress)(reserveAsset.hub)}`,
158
158
  assetId: reserveAsset.assetId,
159
159
  reserveId,
160
160
  paused: reserveAsset.paused,
@@ -192,14 +192,30 @@ function _getAaveV4SpokeData(provider_1, network_1, market_1) {
192
192
  return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
193
193
  const viewContract = (0, contracts_1.AaveV4ViewContractViem)(provider, network, blockNumber);
194
194
  const hubsData = {};
195
+ const loadHubData = (hubAddress) => __awaiter(this, void 0, void 0, function* () {
196
+ hubsData[hubAddress.toLowerCase()] = yield fetchHubData(viewContract, hubAddress);
197
+ });
198
+ // market.hubs is only a prefetch hint (lets known hubs load in parallel with the spoke data), so
199
+ // failures are tolerated here — any hub the reserves actually reference is (re)fetched below.
195
200
  const [spokeData, merklCampaigns] = yield Promise.all([
196
201
  viewContract.read.getSpokeDataFull([market.address]),
197
202
  (0, merkl_1.getAaveV4MerkleCampaigns)(network),
198
- ...market.hubs.map((hubAddress) => __awaiter(this, void 0, void 0, function* () {
199
- hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
200
- })),
203
+ ...market.hubs.map((hubAddress) => loadHubData(hubAddress).catch(() => { })),
201
204
  ]);
202
- const reserveAssetsArray = yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () { return formatReserveAsset(reserveAssetOnChain, hubsData[reserveAssetOnChain.hub].assets[reserveAssetOnChain.assetId], index, +spokeData[0].oracleDecimals.toString(), network); })));
205
+ // The on-chain reserves are the source of truth for which hubs the spoke uses fetch any hub
206
+ // the prefetch didn't cover, so an asset listed from a hub unknown to the SDK can't break the spoke.
207
+ const missingHubs = [...new Set(spokeData[1].map((reserveAsset) => reserveAsset.hub.toLowerCase()))]
208
+ .filter((hubAddress) => !hubsData[hubAddress]);
209
+ yield Promise.all(missingHubs.map(loadHubData));
210
+ const reserveAssetsArray = (yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () {
211
+ var _a;
212
+ const hubAsset = (_a = hubsData[reserveAssetOnChain.hub.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.assets[reserveAssetOnChain.assetId];
213
+ // A reserve whose hub-side asset data can't be resolved is skipped instead of failing the
214
+ // whole spoke (position math degrades for that one asset only).
215
+ if (!hubAsset)
216
+ return null;
217
+ return formatReserveAsset(reserveAssetOnChain, hubAsset, index, +spokeData[0].oracleDecimals.toString(), network);
218
+ })))).filter((asset) => asset !== null);
203
219
  const enrichedAssets = reserveAssetsArray.map((asset) => (0, merkl_1.attachAaveV4MerklIncentives)(asset, market.address, merklCampaigns));
204
220
  return {
205
221
  assetsData: enrichedAssets.reduce((acc, reserveAsset) => {