@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/types/aaveV4.d.ts
CHANGED
|
@@ -44,6 +44,11 @@ export interface AaveV4SpokeInfo {
|
|
|
44
44
|
value: AaveV4SpokesType;
|
|
45
45
|
url: string;
|
|
46
46
|
address: EthAddress;
|
|
47
|
+
/**
|
|
48
|
+
* Known hub addresses, used only to prefetch hub data in parallel with the spoke data.
|
|
49
|
+
* The on-chain reserves are the source of truth — hubs found there but missing here are
|
|
50
|
+
* fetched dynamically, so this list going stale can't break spoke loading.
|
|
51
|
+
*/
|
|
47
52
|
hubs: EthAddress[];
|
|
48
53
|
}
|
|
49
54
|
export interface AaveV4SpokeData {
|
package/esm/aaveV4/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getViemProvider } from '../services/viem';
|
|
|
13
13
|
import { IncentiveKind, } from '../types';
|
|
14
14
|
import { AaveV4ViewContractViem } from '../contracts';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
|
-
import { isMaxUint, wethToEth, wethToEthByAddress } from '../services/utils';
|
|
16
|
+
import { isMaxUint, shortenAddress, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
17
17
|
import { aaveV4GetAggregatedPositionData, calcUserRiskPremiumBps } from '../helpers/aaveV4Helpers';
|
|
18
18
|
import { findAaveV4SpokeByAddress, getAaveV4HubByAddress } from '../markets/aaveV4';
|
|
19
19
|
import { aprToApy } from '../moneymarket';
|
|
@@ -39,16 +39,16 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
|
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
41
|
const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f;
|
|
42
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
43
|
const assetInfo = getAssetInfoByAddress(reserveAsset.underlying, network);
|
|
44
44
|
// `@defisaver/tokens` returns a placeholder ('?', decimals NaN) when the underlying is not in the
|
|
45
45
|
// tokens package. Flag it so consumers can render it read-only instead of feeding NaN into amounts.
|
|
46
46
|
const isUnsupported = assetInfo.symbol === '?';
|
|
47
47
|
const symbol = wethToEth(assetInfo.symbol);
|
|
48
|
+
// The hub registry only provides display metadata — a hub missing from it (newly deployed by
|
|
49
|
+
// Aave, SDK not yet updated) must not prevent the reserve from loading, so fall back to a
|
|
50
|
+
// generated label instead of failing.
|
|
48
51
|
const hubInfo = getAaveV4HubByAddress(network, reserveAsset.hub);
|
|
49
|
-
if (!hubInfo) {
|
|
50
|
-
throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
|
|
51
|
-
}
|
|
52
52
|
const isStakingAsset = STAKING_ASSETS.includes(symbol);
|
|
53
53
|
const supplyIncentives = [];
|
|
54
54
|
const borrowIncentives = [];
|
|
@@ -108,8 +108,8 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
108
108
|
decimals: reserveAsset.decimals,
|
|
109
109
|
isUnsupported,
|
|
110
110
|
underlying: reserveAsset.underlying,
|
|
111
|
-
hub: hubInfo.address,
|
|
112
|
-
hubName: hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label
|
|
111
|
+
hub: (_g = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.address) !== null && _g !== void 0 ? _g : reserveAsset.hub,
|
|
112
|
+
hubName: (_h = hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label) !== null && _h !== void 0 ? _h : `Hub ${shortenAddress(reserveAsset.hub)}`,
|
|
113
113
|
assetId: reserveAsset.assetId,
|
|
114
114
|
reserveId,
|
|
115
115
|
paused: reserveAsset.paused,
|
|
@@ -147,14 +147,30 @@ export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
|
147
147
|
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
148
148
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
149
149
|
const hubsData = {};
|
|
150
|
+
const loadHubData = (hubAddress) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
hubsData[hubAddress.toLowerCase()] = yield fetchHubData(viewContract, hubAddress);
|
|
152
|
+
});
|
|
153
|
+
// market.hubs is only a prefetch hint (lets known hubs load in parallel with the spoke data), so
|
|
154
|
+
// failures are tolerated here — any hub the reserves actually reference is (re)fetched below.
|
|
150
155
|
const [spokeData, merklCampaigns] = yield Promise.all([
|
|
151
156
|
viewContract.read.getSpokeDataFull([market.address]),
|
|
152
157
|
getAaveV4MerkleCampaigns(network),
|
|
153
|
-
...market.hubs.map((hubAddress) =>
|
|
154
|
-
hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
|
|
155
|
-
})),
|
|
158
|
+
...market.hubs.map((hubAddress) => loadHubData(hubAddress).catch(() => { })),
|
|
156
159
|
]);
|
|
157
|
-
|
|
160
|
+
// The on-chain reserves are the source of truth for which hubs the spoke uses — fetch any hub
|
|
161
|
+
// the prefetch didn't cover, so an asset listed from a hub unknown to the SDK can't break the spoke.
|
|
162
|
+
const missingHubs = [...new Set(spokeData[1].map((reserveAsset) => reserveAsset.hub.toLowerCase()))]
|
|
163
|
+
.filter((hubAddress) => !hubsData[hubAddress]);
|
|
164
|
+
yield Promise.all(missingHubs.map(loadHubData));
|
|
165
|
+
const reserveAssetsArray = (yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
var _a;
|
|
167
|
+
const hubAsset = (_a = hubsData[reserveAssetOnChain.hub.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.assets[reserveAssetOnChain.assetId];
|
|
168
|
+
// A reserve whose hub-side asset data can't be resolved is skipped instead of failing the
|
|
169
|
+
// whole spoke (position math degrades for that one asset only).
|
|
170
|
+
if (!hubAsset)
|
|
171
|
+
return null;
|
|
172
|
+
return formatReserveAsset(reserveAssetOnChain, hubAsset, index, +spokeData[0].oracleDecimals.toString(), network);
|
|
173
|
+
})))).filter((asset) => asset !== null);
|
|
158
174
|
const enrichedAssets = reserveAssetsArray.map((asset) => attachAaveV4MerklIncentives(asset, market.address, merklCampaigns));
|
|
159
175
|
return {
|
|
160
176
|
assetsData: enrichedAssets.reduce((acc, reserveAsset) => {
|