@defisaver/positions-sdk 2.1.109 → 2.1.110

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.
@@ -1,9 +1,11 @@
1
1
  import { Client } from 'viem';
2
- import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber } from '../types';
2
+ import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber, Blockish, PositionBalances } from '../types';
3
3
  export * as lend from './lend';
4
4
  export { getAaveV4MerkleCampaigns } from './merkl';
5
5
  export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
6
6
  export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
7
7
  export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
8
8
  export declare function getAaveV4AccountData(provider: EthereumProvider, network: NetworkNumber, marketData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<any>;
9
+ export declare const _getAaveV4AccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, spokeAddress: EthAddress, spokeData?: AaveV4SpokeData) => Promise<PositionBalances>;
10
+ export declare const getAaveV4AccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, spokeAddress: EthAddress, spokeData?: AaveV4SpokeData) => Promise<PositionBalances>;
9
11
  export declare function getAaveV4UnderlyingFromReserveId(provider: EthereumProvider, network: NetworkNumber, spoke: EthAddress, reserveId: number): Promise<any>;
@@ -45,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
45
45
  return (mod && mod.__esModule) ? mod : { "default": mod };
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.getAaveV4MerkleCampaigns = exports.lend = void 0;
48
+ exports.getAaveV4AccountBalances = exports._getAaveV4AccountBalances = exports.getAaveV4MerkleCampaigns = exports.lend = void 0;
49
49
  exports._getAaveV4SpokeData = _getAaveV4SpokeData;
50
50
  exports.getAaveV4SpokeData = getAaveV4SpokeData;
51
51
  exports._getAaveV4AccountData = _getAaveV4AccountData;
@@ -285,6 +285,46 @@ function getAaveV4AccountData(provider_1, network_1, marketData_1, address_1) {
285
285
  return _getAaveV4AccountData((0, viem_1.getViemProvider)(provider, network), network, marketData, address, blockNumber);
286
286
  });
287
287
  }
288
+ const _getAaveV4AccountBalances = (provider, network, block, addressMapping, address, spokeAddress, spokeData) => __awaiter(void 0, void 0, void 0, function* () {
289
+ const balances = {
290
+ collateral: {},
291
+ debt: {},
292
+ };
293
+ if (!address || !spokeAddress) {
294
+ return balances;
295
+ }
296
+ const blockNumber = block === 'latest' ? 'latest' : Number(block);
297
+ let resolvedSpokeData = spokeData;
298
+ if (!resolvedSpokeData) {
299
+ const spokeInfo = (0, aaveV4_1.findAaveV4SpokeByAddress)(network, spokeAddress);
300
+ if (!spokeInfo) {
301
+ return balances;
302
+ }
303
+ resolvedSpokeData = yield _getAaveV4SpokeData(provider, network, spokeInfo, blockNumber);
304
+ }
305
+ const accountData = yield _getAaveV4AccountData(provider, network, resolvedSpokeData, address, blockNumber);
306
+ const finalSpokeData = resolvedSpokeData;
307
+ Object.entries(accountData.usedAssets).forEach(([key, asset]) => {
308
+ const reserveData = finalSpokeData.assetsData[key];
309
+ if (!reserveData)
310
+ return;
311
+ const balanceKey = addressMapping
312
+ ? (0, utils_1.wethToEthByAddress)(reserveData.underlying, network).toLowerCase()
313
+ : (0, utils_1.wethToEth)(asset.symbol);
314
+ if (asset.isSupplied && new decimal_js_1.default(asset.supplied || 0).gt(0)) {
315
+ balances.collateral[balanceKey] = (0, tokens_1.assetAmountInWei)(asset.supplied, asset.symbol);
316
+ }
317
+ if (asset.isBorrowed && new decimal_js_1.default(asset.borrowed || 0).gt(0)) {
318
+ balances.debt[balanceKey] = (0, tokens_1.assetAmountInWei)(asset.borrowed, asset.symbol);
319
+ }
320
+ });
321
+ return balances;
322
+ });
323
+ exports._getAaveV4AccountBalances = _getAaveV4AccountBalances;
324
+ const getAaveV4AccountBalances = (provider, network, block, addressMapping, address, spokeAddress, spokeData) => __awaiter(void 0, void 0, void 0, function* () {
325
+ return (0, exports._getAaveV4AccountBalances)((0, viem_1.getViemProvider)(provider, network), network, block, addressMapping, address, spokeAddress, spokeData);
326
+ });
327
+ exports.getAaveV4AccountBalances = getAaveV4AccountBalances;
288
328
  const _getAaveV4UnderlyingFromReserveId = (provider, network, spoke, reserveId) => __awaiter(void 0, void 0, void 0, function* () {
289
329
  const viewContract = (0, contracts_1.AaveV4ViewContractViem)(provider, network);
290
330
  const reserveData = yield viewContract.read.getReserveData([spoke, BigInt(reserveId)]);
@@ -32,3 +32,4 @@ export declare const AaveV4Spokes: (networkId: NetworkNumber) => {
32
32
  readonly aave_v4_main_spoke: AaveV4SpokeInfo;
33
33
  };
34
34
  export declare const getAaveV4SpokeTypeInfo: (type: AaveV4SpokesType, network?: NetworkNumber) => AaveV4SpokeInfo;
35
+ export declare const findAaveV4SpokeByAddress: (networkId: NetworkNumber, address: string) => AaveV4SpokeInfo | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAaveV4SpokeTypeInfo = exports.AaveV4Spokes = exports.AAVE_V4_MAIN_SPOKE = exports.AAVE_V4_LOMBARD_BTC_SPOKE = exports.AAVE_V4_LIDO_SPOKE = exports.AAVE_V4_KELP_SPOKE = exports.AAVE_V4_GOLD_SPOKE = exports.AAVE_V4_FOREX_SPOKE = exports.AAVE_V4_ETHERFI_SPOKE = exports.AAVE_V4_ETHENA_ECOSYSTEM_SPOKE = exports.AAVE_V4_ETHENA_CORRELATED_SPOKE = exports.AAVE_V4_BLUECHIP_SPOKE = exports.getAaveV4HubByAddress = exports.getAaveV4HubTypeInfo = exports.AaveV4Hubs = exports.AAVE_V4_PRIME_HUB = exports.AAVE_V4_PLUS_HUB = exports.AAVE_V4_CORE_HUB = void 0;
3
+ exports.findAaveV4SpokeByAddress = exports.getAaveV4SpokeTypeInfo = exports.AaveV4Spokes = exports.AAVE_V4_MAIN_SPOKE = exports.AAVE_V4_LOMBARD_BTC_SPOKE = exports.AAVE_V4_LIDO_SPOKE = exports.AAVE_V4_KELP_SPOKE = exports.AAVE_V4_GOLD_SPOKE = exports.AAVE_V4_FOREX_SPOKE = exports.AAVE_V4_ETHERFI_SPOKE = exports.AAVE_V4_ETHENA_ECOSYSTEM_SPOKE = exports.AAVE_V4_ETHENA_CORRELATED_SPOKE = exports.AAVE_V4_BLUECHIP_SPOKE = exports.getAaveV4HubByAddress = exports.getAaveV4HubTypeInfo = exports.AaveV4Hubs = exports.AAVE_V4_PRIME_HUB = exports.AAVE_V4_PLUS_HUB = exports.AAVE_V4_CORE_HUB = void 0;
4
4
  const types_1 = require("../../types");
5
5
  // HUBS
6
6
  const AAVE_V4_CORE_HUB = (networkId) => ({
@@ -180,3 +180,5 @@ const AaveV4Spokes = (networkId) => ({
180
180
  exports.AaveV4Spokes = AaveV4Spokes;
181
181
  const getAaveV4SpokeTypeInfo = (type, network) => (Object.assign({}, (0, exports.AaveV4Spokes)(network !== null && network !== void 0 ? network : types_1.NetworkNumber.Eth))[type]);
182
182
  exports.getAaveV4SpokeTypeInfo = getAaveV4SpokeTypeInfo;
183
+ const findAaveV4SpokeByAddress = (networkId, address) => Object.values((0, exports.AaveV4Spokes)(networkId)).find(spoke => spoke.address.toLowerCase() === address.toLowerCase());
184
+ exports.findAaveV4SpokeByAddress = findAaveV4SpokeByAddress;
@@ -7,4 +7,4 @@ export { LlamaLendMarkets } from './llamaLend';
7
7
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
8
8
  export { EulerV2Markets } from './euler';
9
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
10
- export { AaveV4Spokes } from './aaveV4';
10
+ export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AaveV4Spokes = exports.getFluidMarketInfoByAddress = exports.getFTokenAddress = exports.getFluidMarketInfoById = exports.getFluidVersionsDataForNetwork = exports.FluidMarkets = exports.EulerV2Markets = exports.findLiquityV2MarketByAddress = exports.LiquityV2Markets = exports.LlamaLendMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
3
+ exports.findAaveV4SpokeByAddress = exports.AaveV4Spokes = exports.getFluidMarketInfoByAddress = exports.getFTokenAddress = exports.getFluidMarketInfoById = exports.getFluidVersionsDataForNetwork = exports.FluidMarkets = exports.EulerV2Markets = exports.findLiquityV2MarketByAddress = exports.LiquityV2Markets = exports.LlamaLendMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
4
4
  var aave_1 = require("./aave");
5
5
  Object.defineProperty(exports, "AaveMarkets", { enumerable: true, get: function () { return aave_1.AaveMarkets; } });
6
6
  Object.defineProperty(exports, "aaveV1AssetsDefaultMarket", { enumerable: true, get: function () { return aave_1.aaveV1AssetsDefaultMarket; } });
@@ -37,3 +37,4 @@ Object.defineProperty(exports, "getFTokenAddress", { enumerable: true, get: func
37
37
  Object.defineProperty(exports, "getFluidMarketInfoByAddress", { enumerable: true, get: function () { return fluid_1.getFluidMarketInfoByAddress; } });
38
38
  var aaveV4_1 = require("./aaveV4");
39
39
  Object.defineProperty(exports, "AaveV4Spokes", { enumerable: true, get: function () { return aaveV4_1.AaveV4Spokes; } });
40
+ Object.defineProperty(exports, "findAaveV4SpokeByAddress", { enumerable: true, get: function () { return aaveV4_1.findAaveV4SpokeByAddress; } });
@@ -1,9 +1,11 @@
1
1
  import { Client } from 'viem';
2
- import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber } from '../types';
2
+ import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber, Blockish, PositionBalances } from '../types';
3
3
  export * as lend from './lend';
4
4
  export { getAaveV4MerkleCampaigns } from './merkl';
5
5
  export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
6
6
  export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
7
7
  export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
8
8
  export declare function getAaveV4AccountData(provider: EthereumProvider, network: NetworkNumber, marketData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<any>;
9
+ export declare const _getAaveV4AccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, spokeAddress: EthAddress, spokeData?: AaveV4SpokeData) => Promise<PositionBalances>;
10
+ export declare const getAaveV4AccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, spokeAddress: EthAddress, spokeData?: AaveV4SpokeData) => Promise<PositionBalances>;
9
11
  export declare function getAaveV4UnderlyingFromReserveId(provider: EthereumProvider, network: NetworkNumber, spoke: EthAddress, reserveId: number): Promise<any>;
@@ -8,14 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
- import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
11
+ import { assetAmountInEth, assetAmountInWei, getAssetInfoByAddress } from '@defisaver/tokens';
12
12
  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 } from '../services/utils';
16
+ import { isMaxUint, wethToEth, wethToEthByAddress } from '../services/utils';
17
17
  import { aaveV4GetAggregatedPositionData, calcUserRiskPremiumBps } from '../helpers/aaveV4Helpers';
18
- import { getAaveV4HubByAddress } from '../markets/aaveV4';
18
+ import { findAaveV4SpokeByAddress, getAaveV4HubByAddress } from '../markets/aaveV4';
19
19
  import { aprToApy } from '../moneymarket';
20
20
  import { attachAaveV4MerklIncentives, getAaveV4MerkleCampaigns } from './merkl';
21
21
  export * as lend from './lend';
@@ -240,6 +240,44 @@ export function getAaveV4AccountData(provider_1, network_1, marketData_1, addres
240
240
  return _getAaveV4AccountData(getViemProvider(provider, network), network, marketData, address, blockNumber);
241
241
  });
242
242
  }
243
+ export const _getAaveV4AccountBalances = (provider, network, block, addressMapping, address, spokeAddress, spokeData) => __awaiter(void 0, void 0, void 0, function* () {
244
+ const balances = {
245
+ collateral: {},
246
+ debt: {},
247
+ };
248
+ if (!address || !spokeAddress) {
249
+ return balances;
250
+ }
251
+ const blockNumber = block === 'latest' ? 'latest' : Number(block);
252
+ let resolvedSpokeData = spokeData;
253
+ if (!resolvedSpokeData) {
254
+ const spokeInfo = findAaveV4SpokeByAddress(network, spokeAddress);
255
+ if (!spokeInfo) {
256
+ return balances;
257
+ }
258
+ resolvedSpokeData = yield _getAaveV4SpokeData(provider, network, spokeInfo, blockNumber);
259
+ }
260
+ const accountData = yield _getAaveV4AccountData(provider, network, resolvedSpokeData, address, blockNumber);
261
+ const finalSpokeData = resolvedSpokeData;
262
+ Object.entries(accountData.usedAssets).forEach(([key, asset]) => {
263
+ const reserveData = finalSpokeData.assetsData[key];
264
+ if (!reserveData)
265
+ return;
266
+ const balanceKey = addressMapping
267
+ ? wethToEthByAddress(reserveData.underlying, network).toLowerCase()
268
+ : wethToEth(asset.symbol);
269
+ if (asset.isSupplied && new Dec(asset.supplied || 0).gt(0)) {
270
+ balances.collateral[balanceKey] = assetAmountInWei(asset.supplied, asset.symbol);
271
+ }
272
+ if (asset.isBorrowed && new Dec(asset.borrowed || 0).gt(0)) {
273
+ balances.debt[balanceKey] = assetAmountInWei(asset.borrowed, asset.symbol);
274
+ }
275
+ });
276
+ return balances;
277
+ });
278
+ export const getAaveV4AccountBalances = (provider, network, block, addressMapping, address, spokeAddress, spokeData) => __awaiter(void 0, void 0, void 0, function* () {
279
+ return _getAaveV4AccountBalances(getViemProvider(provider, network), network, block, addressMapping, address, spokeAddress, spokeData);
280
+ });
243
281
  const _getAaveV4UnderlyingFromReserveId = (provider, network, spoke, reserveId) => __awaiter(void 0, void 0, void 0, function* () {
244
282
  const viewContract = AaveV4ViewContractViem(provider, network);
245
283
  const reserveData = yield viewContract.read.getReserveData([spoke, BigInt(reserveId)]);
@@ -32,3 +32,4 @@ export declare const AaveV4Spokes: (networkId: NetworkNumber) => {
32
32
  readonly aave_v4_main_spoke: AaveV4SpokeInfo;
33
33
  };
34
34
  export declare const getAaveV4SpokeTypeInfo: (type: AaveV4SpokesType, network?: NetworkNumber) => AaveV4SpokeInfo;
35
+ export declare const findAaveV4SpokeByAddress: (networkId: NetworkNumber, address: string) => AaveV4SpokeInfo | undefined;
@@ -159,3 +159,4 @@ export const AaveV4Spokes = (networkId) => ({
159
159
  [AaveV4SpokesType.AaveV4MainSpoke]: AAVE_V4_MAIN_SPOKE(networkId),
160
160
  });
161
161
  export const getAaveV4SpokeTypeInfo = (type, network) => (Object.assign({}, AaveV4Spokes(network !== null && network !== void 0 ? network : NetworkNumber.Eth))[type]);
162
+ export const findAaveV4SpokeByAddress = (networkId, address) => Object.values(AaveV4Spokes(networkId)).find(spoke => spoke.address.toLowerCase() === address.toLowerCase());
@@ -7,4 +7,4 @@ export { LlamaLendMarkets } from './llamaLend';
7
7
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
8
8
  export { EulerV2Markets } from './euler';
9
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
10
- export { AaveV4Spokes } from './aaveV4';
10
+ export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
@@ -7,4 +7,4 @@ export { LlamaLendMarkets } from './llamaLend';
7
7
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
8
8
  export { EulerV2Markets } from './euler';
9
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
10
- export { AaveV4Spokes } from './aaveV4';
10
+ export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.109",
3
+ "version": "2.1.110",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -1,6 +1,6 @@
1
1
  import { Client } from 'viem';
2
2
  import Dec from 'decimal.js';
3
- import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
3
+ import { assetAmountInEth, assetAmountInWei, getAssetInfoByAddress } from '@defisaver/tokens';
4
4
  import { getViemProvider } from '../services/viem';
5
5
  import {
6
6
  AaveV4AccountData,
@@ -16,12 +16,14 @@ import {
16
16
  IncentiveData,
17
17
  IncentiveKind,
18
18
  NetworkNumber,
19
+ Blockish,
20
+ PositionBalances,
19
21
  } from '../types';
20
22
  import { AaveV4ViewContractViem } from '../contracts';
21
23
  import { getStakingApy, STAKING_ASSETS } from '../staking';
22
- import { isMaxUint, wethToEth } from '../services/utils';
24
+ import { isMaxUint, wethToEth, wethToEthByAddress } from '../services/utils';
23
25
  import { aaveV4GetAggregatedPositionData, calcUserRiskPremiumBps } from '../helpers/aaveV4Helpers';
24
- import { getAaveV4HubByAddress } from '../markets/aaveV4';
26
+ import { findAaveV4SpokeByAddress, getAaveV4HubByAddress } from '../markets/aaveV4';
25
27
  import { aprToApy } from '../moneymarket';
26
28
  import { attachAaveV4MerklIncentives, getAaveV4MerkleCampaigns } from './merkl';
27
29
 
@@ -259,6 +261,74 @@ export async function getAaveV4AccountData(provider: EthereumProvider, network:
259
261
  return _getAaveV4AccountData(getViemProvider(provider, network), network, marketData, address, blockNumber);
260
262
  }
261
263
 
264
+ export const _getAaveV4AccountBalances = async (
265
+ provider: Client,
266
+ network: NetworkNumber,
267
+ block: Blockish,
268
+ addressMapping: boolean,
269
+ address: EthAddress,
270
+ spokeAddress: EthAddress,
271
+ spokeData?: AaveV4SpokeData,
272
+ ): Promise<PositionBalances> => {
273
+ const balances: PositionBalances = {
274
+ collateral: {},
275
+ debt: {},
276
+ };
277
+
278
+ if (!address || !spokeAddress) {
279
+ return balances;
280
+ }
281
+
282
+ const blockNumber = block === 'latest' ? 'latest' : Number(block);
283
+ let resolvedSpokeData = spokeData;
284
+ if (!resolvedSpokeData) {
285
+ const spokeInfo = findAaveV4SpokeByAddress(network, spokeAddress);
286
+ if (!spokeInfo) {
287
+ return balances;
288
+ }
289
+ resolvedSpokeData = await _getAaveV4SpokeData(provider, network, spokeInfo, blockNumber);
290
+ }
291
+
292
+ const accountData = await _getAaveV4AccountData(provider, network, resolvedSpokeData, address, blockNumber);
293
+ const finalSpokeData = resolvedSpokeData;
294
+
295
+ Object.entries(accountData.usedAssets).forEach(([key, asset]) => {
296
+ const reserveData = finalSpokeData.assetsData[key];
297
+ if (!reserveData) return;
298
+
299
+ const balanceKey = addressMapping
300
+ ? wethToEthByAddress(reserveData.underlying, network).toLowerCase()
301
+ : wethToEth(asset.symbol);
302
+
303
+ if (asset.isSupplied && new Dec(asset.supplied || 0).gt(0)) {
304
+ balances.collateral![balanceKey] = assetAmountInWei(asset.supplied, asset.symbol);
305
+ }
306
+ if (asset.isBorrowed && new Dec(asset.borrowed || 0).gt(0)) {
307
+ balances.debt![balanceKey] = assetAmountInWei(asset.borrowed, asset.symbol);
308
+ }
309
+ });
310
+
311
+ return balances;
312
+ };
313
+
314
+ export const getAaveV4AccountBalances = async (
315
+ provider: EthereumProvider,
316
+ network: NetworkNumber,
317
+ block: Blockish,
318
+ addressMapping: boolean,
319
+ address: EthAddress,
320
+ spokeAddress: EthAddress,
321
+ spokeData?: AaveV4SpokeData,
322
+ ): Promise<PositionBalances> => _getAaveV4AccountBalances(
323
+ getViemProvider(provider, network),
324
+ network,
325
+ block,
326
+ addressMapping,
327
+ address,
328
+ spokeAddress,
329
+ spokeData,
330
+ );
331
+
262
332
  const _getAaveV4UnderlyingFromReserveId = async (provider: Client, network: NetworkNumber, spoke: EthAddress, reserveId: number): Promise<any> => {
263
333
  const viewContract = AaveV4ViewContractViem(provider, network);
264
334
 
@@ -188,4 +188,8 @@ export const AaveV4Spokes = (networkId: NetworkNumber) => ({
188
188
 
189
189
  export const getAaveV4SpokeTypeInfo = (type: AaveV4SpokesType, network?: NetworkNumber) => ({ ...AaveV4Spokes(network ?? NetworkNumber.Eth) }[type]);
190
190
 
191
+ export const findAaveV4SpokeByAddress = (networkId: NetworkNumber, address: string): AaveV4SpokeInfo | undefined => Object.values(AaveV4Spokes(networkId)).find(
192
+ spoke => spoke.address.toLowerCase() === address.toLowerCase(),
193
+ );
194
+
191
195
 
@@ -27,4 +27,4 @@ export {
27
27
  getFTokenAddress,
28
28
  getFluidMarketInfoByAddress,
29
29
  } from './fluid';
30
- export { AaveV4Spokes } from './aaveV4';
30
+ export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';