@defisaver/positions-sdk 2.1.137-audit-dev → 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.
- package/cjs/aaveV4/index.js +26 -10
- package/cjs/contracts.d.ts +2129 -1886
- package/cjs/savings/morphoVaults/index.js +2 -19
- package/cjs/services/utils.d.ts +1 -0
- package/cjs/services/utils.js +3 -1
- package/cjs/services/viem.d.ts +2679 -918
- package/cjs/types/aaveV4.d.ts +5 -0
- package/esm/aaveV4/index.js +27 -11
- package/esm/contracts.d.ts +2129 -1886
- package/esm/savings/morphoVaults/index.js +2 -19
- package/esm/services/utils.d.ts +1 -0
- package/esm/services/utils.js +1 -0
- package/esm/services/viem.d.ts +2667 -916
- package/esm/types/aaveV4.d.ts +5 -0
- package/package.json +2 -9
- package/src/aaveV4/index.ts +29 -11
- package/src/contracts.ts +2 -2
- package/src/savings/morphoVaults/index.ts +2 -18
- package/src/services/utils.ts +2 -0
- package/src/types/aaveV4.ts +5 -0
package/cjs/aaveV4/index.js
CHANGED
|
@@ -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) =>
|
|
199
|
-
hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
|
|
200
|
-
})),
|
|
203
|
+
...market.hubs.map((hubAddress) => loadHubData(hubAddress).catch(() => { })),
|
|
201
204
|
]);
|
|
202
|
-
|
|
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) => {
|