@defisaver/positions-sdk 2.1.161 → 2.1.162

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.
@@ -41,7 +41,10 @@ const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
41
41
  : !usedAssetsValues.filter(u => u.isBorrowed && !e.borrowAssets.includes(u.symbol)).length;
42
42
  const afterEnteringCategory = (0, aaveHelpers_1.aaveAnyGetAggregatedPositionData)(Object.assign(Object.assign({}, extractedState), { usedAssets, eModeCategory: e.id }));
43
43
  const willStayOverCollateralized = new decimal_js_1.default(afterEnteringCategory.ratio === 'NaN' ? '0' : afterEnteringCategory.ratio).eq(0) || new decimal_js_1.default(afterEnteringCategory.ratio).gt(afterEnteringCategory.liqPercent);
44
- const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized];
44
+ const collateralOnlyFromCategory = e.id === 0 || !e.isolated
45
+ ? true
46
+ : !usedAssetsValues.filter(u => u.isSupplied && u.collateral && !e.collateralAssets.includes(u.symbol)).length;
47
+ const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized, collateralOnlyFromCategory];
45
48
  categoriesMapping[e.id] = {
46
49
  enteringTerms,
47
50
  canEnterCategory: !enteringTerms.includes(false),
@@ -59,6 +62,7 @@ const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
59
62
  exports.aaveV3EmodeCategoriesMapping = aaveV3EmodeCategoriesMapping;
60
63
  function _getAaveV3MarketData(provider_1, network_1, market_1) {
61
64
  return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
65
+ var _a;
62
66
  const _addresses = market.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.getWrappedNativeAssetFromUnwrapped)(a), network).address);
63
67
  const loanInfoContract = (0, contracts_1.AaveV3ViewContractViem)(provider, network);
64
68
  const aaveIncentivesContract = (0, contracts_1.AaveIncentiveDataProviderV3ContractViem)(provider, network);
@@ -92,6 +96,7 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
92
96
  borrowableBitmap: eModesInfo[i].borrowableBitmap.toString(),
93
97
  collateralBitmap: eModesInfo[i].collateralBitmap.toString(),
94
98
  ltvzeroBitmap: eModesInfo[i].ltvzeroBitmap.toString(),
99
+ isolated: (_a = eModesInfo[i].isolated) !== null && _a !== void 0 ? _a : false,
95
100
  borrowAssets: [],
96
101
  collateralAssets: [],
97
102
  ltvZeroAssets: [],
@@ -307,6 +312,7 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
307
312
  collateralAssets: assetsData.map((a) => a.symbol),
308
313
  borrowAssets: assetsData.map((a) => a.symbol),
309
314
  ltvZeroAssets: [],
315
+ isolated: false,
310
316
  };
311
317
  return { assetsData: payload, eModeCategoriesData };
312
318
  });
@@ -1,4 +1,4 @@
1
- import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions } from '../../types';
1
+ import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions, EModeCategoriesData } from '../../types';
2
2
  import { EthereumProvider, NetworkNumber } from '../../types/common';
3
3
  export declare const AAVE_V3_MARKETS: AaveVersions[];
4
4
  export declare const isAaveV2: ({ selectedMarket }: {
@@ -15,6 +15,14 @@ export declare const aaveV3IsInSiloedMode: ({ usedAssets, assetsData }: {
15
15
  usedAssets: AaveV3UsedAssets;
16
16
  assetsData: AaveV3AssetsData;
17
17
  }) => boolean;
18
+ export declare const aaveV3IsEmodeIsolated: ({ eModeCategory, eModeCategoriesData }: {
19
+ eModeCategory: number;
20
+ eModeCategoriesData?: EModeCategoriesData;
21
+ }) => boolean;
22
+ export declare const aaveV3CanBeCollateralInEmode: ({ eModeCategory, eModeCategoriesData }: {
23
+ eModeCategory: number;
24
+ eModeCategoriesData?: EModeCategoriesData;
25
+ }, _asset: string) => boolean;
18
26
  export declare const aaveAnyGetCollSuppliedAssets: ({ usedAssets }: {
19
27
  usedAssets: AaveV3UsedAssets;
20
28
  }) => AaveV3UsedAsset[];
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getAaveUnderlyingSymbol = exports.getApyAfterValuesEstimation = exports.aaveAnyGetAggregatedPositionData = exports.aaveAnyGetUserReserveLtvAndLltv = exports.aaveAnyGetEmodeMutableProps = exports.aaveAnyGetSuppliableAsCollAssets = exports.aaveAnyGetSuppliableAssets = exports.aaveAnyGetCollSuppliedAssets = exports.aaveV3IsInSiloedMode = exports.aaveV3IsInIsolationMode = exports.isAaveV3 = exports.isAaveV2 = exports.AAVE_V3_MARKETS = void 0;
26
+ exports.getAaveUnderlyingSymbol = exports.getApyAfterValuesEstimation = exports.aaveAnyGetAggregatedPositionData = exports.aaveAnyGetUserReserveLtvAndLltv = exports.aaveAnyGetEmodeMutableProps = exports.aaveAnyGetSuppliableAsCollAssets = exports.aaveAnyGetSuppliableAssets = exports.aaveAnyGetCollSuppliedAssets = exports.aaveV3CanBeCollateralInEmode = exports.aaveV3IsEmodeIsolated = exports.aaveV3IsInSiloedMode = exports.aaveV3IsInIsolationMode = exports.isAaveV3 = exports.isAaveV2 = exports.AAVE_V3_MARKETS = void 0;
27
27
  const decimal_js_1 = __importDefault(require("decimal.js"));
28
28
  const tokens_1 = require("@defisaver/tokens");
29
29
  const types_1 = require("../../types");
@@ -43,6 +43,14 @@ const aaveV3IsInIsolationMode = ({ usedAssets, assetsData }) => Object.values(us
43
43
  exports.aaveV3IsInIsolationMode = aaveV3IsInIsolationMode;
44
44
  const aaveV3IsInSiloedMode = ({ usedAssets, assetsData }) => Object.values(usedAssets).some(({ symbol, debt }) => debt && assetsData[symbol].isSiloed);
45
45
  exports.aaveV3IsInSiloedMode = aaveV3IsInSiloedMode;
46
+ const aaveV3IsEmodeIsolated = ({ eModeCategory, eModeCategoriesData }) => { var _a; return eModeCategory !== 0 && !!((_a = eModeCategoriesData === null || eModeCategoriesData === void 0 ? void 0 : eModeCategoriesData[eModeCategory]) === null || _a === void 0 ? void 0 : _a.isolated); };
47
+ exports.aaveV3IsEmodeIsolated = aaveV3IsEmodeIsolated;
48
+ const aaveV3CanBeCollateralInEmode = ({ eModeCategory, eModeCategoriesData }, _asset) => {
49
+ if (!(0, exports.aaveV3IsEmodeIsolated)({ eModeCategory, eModeCategoriesData }))
50
+ return true;
51
+ return eModeCategoriesData[eModeCategory].collateralAssets.includes((0, utils_1.getNativeAssetFromWrapped)(_asset));
52
+ };
53
+ exports.aaveV3CanBeCollateralInEmode = aaveV3CanBeCollateralInEmode;
46
54
  const aaveAnyGetCollSuppliedAssets = ({ usedAssets }) => Object.values(usedAssets)
47
55
  .filter(({ isSupplied, collateral }) => isSupplied && collateral);
48
56
  exports.aaveAnyGetCollSuppliedAssets = aaveAnyGetCollSuppliedAssets;
@@ -51,13 +59,16 @@ const aaveAnyGetSuppliableAssets = (_a) => {
51
59
  const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
52
60
  const collAccountAssets = (0, exports.aaveAnyGetCollSuppliedAssets)(data);
53
61
  const marketAssets = Object.values(assetsData);
54
- if (collAccountAssets.length === 0 || !(0, exports.isAaveV3)(data))
62
+ if (!(0, exports.isAaveV3)(data))
55
63
  return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: true }));
64
+ const canBeCollateralInEmode = (symbol) => (0, exports.aaveV3CanBeCollateralInEmode)(data, symbol);
65
+ if (collAccountAssets.length === 0)
66
+ return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: canBeCollateralInEmode(symbol) }));
56
67
  if ((0, exports.aaveV3IsInIsolationMode)(data)) {
57
68
  const collAsset = collAccountAssets[0].symbol;
58
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset }));
69
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset && canBeCollateralInEmode(symbol) }));
59
70
  }
60
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated }));
71
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated && canBeCollateralInEmode(symbol) }));
61
72
  };
62
73
  exports.aaveAnyGetSuppliableAssets = aaveAnyGetSuppliableAssets;
63
74
  const aaveAnyGetSuppliableAsCollAssets = (_a) => {
@@ -69,12 +80,15 @@ const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData, asset
69
80
  const asset = (0, utils_1.getNativeAssetFromWrapped)(_asset);
70
81
  const assetData = assetsData[asset];
71
82
  const eModeCategoryData = (eModeCategoriesData === null || eModeCategoriesData === void 0 ? void 0 : eModeCategoriesData[eModeCategory]) || {
72
- collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0',
83
+ collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0', isolated: false,
73
84
  };
74
85
  if (eModeCategory === 0
75
86
  || !eModeCategoryData.collateralAssets.includes(asset)
76
87
  || new decimal_js_1.default(eModeCategoryData.collateralFactor || 0).eq(0)) {
77
88
  const { liquidationRatio, collateralFactor } = assetData;
89
+ if (eModeCategory !== 0 && eModeCategoryData.isolated && !eModeCategoryData.collateralAssets.includes(asset)) {
90
+ return ({ liquidationRatio, collateralFactor: '0' });
91
+ }
78
92
  return ({ liquidationRatio, collateralFactor });
79
93
  }
80
94
  if (eModeCategoryData.ltvZeroAssets.includes(asset))
@@ -110,7 +124,10 @@ const aaveAnyGetUserReserveLtvAndLltv = ({ eModeCategory, eModeCategoriesData, a
110
124
  || !eModeCategoryData
111
125
  || !eModeCategoryData.collateralAssets.includes(asset)
112
126
  || new decimal_js_1.default(eModeCategoryData.collateralFactor || 0).eq(0)) {
113
- return { ltv: assetData.collateralFactor, lltv: assetData.liquidationRatio };
127
+ const ltv = eModeCategory !== 0 && (eModeCategoryData === null || eModeCategoryData === void 0 ? void 0 : eModeCategoryData.isolated) && !eModeCategoryData.collateralAssets.includes(asset)
128
+ ? '0'
129
+ : assetData.collateralFactor;
130
+ return { ltv, lltv: assetData.liquidationRatio };
114
131
  }
115
132
  const ltv = eModeCategoryData.ltvZeroAssets.includes(asset) ? '0' : eModeCategoryData.collateralFactor;
116
133
  return { ltv, lltv: eModeCategoryData.liquidationRatio };
@@ -88,6 +88,7 @@ const _getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(vo
88
88
  collateralAssets: eModeCategoriesData[emodeCategoryId] ? [...eModeCategoriesData[emodeCategoryId].collateralAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
89
89
  borrowAssets: eModeCategoriesData[emodeCategoryId] ? [...eModeCategoriesData[emodeCategoryId].borrowAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
90
90
  ltvZeroAssets: [],
91
+ isolated: false,
91
92
  };
92
93
  return ({
93
94
  symbol: selectedMarket.assets[i],
@@ -40,6 +40,7 @@ export interface EModeCategoryData {
40
40
  borrowAssets: string[];
41
41
  ltvzeroBitmap?: string;
42
42
  ltvZeroAssets: string[];
43
+ isolated: boolean;
43
44
  }
44
45
  export interface EModeCategoryDataMapping {
45
46
  enteringTerms: boolean[];
@@ -31,7 +31,10 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
31
31
  : !usedAssetsValues.filter(u => u.isBorrowed && !e.borrowAssets.includes(u.symbol)).length;
32
32
  const afterEnteringCategory = aaveAnyGetAggregatedPositionData(Object.assign(Object.assign({}, extractedState), { usedAssets, eModeCategory: e.id }));
33
33
  const willStayOverCollateralized = new Dec(afterEnteringCategory.ratio === 'NaN' ? '0' : afterEnteringCategory.ratio).eq(0) || new Dec(afterEnteringCategory.ratio).gt(afterEnteringCategory.liqPercent);
34
- const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized];
34
+ const collateralOnlyFromCategory = e.id === 0 || !e.isolated
35
+ ? true
36
+ : !usedAssetsValues.filter(u => u.isSupplied && u.collateral && !e.collateralAssets.includes(u.symbol)).length;
37
+ const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized, collateralOnlyFromCategory];
35
38
  categoriesMapping[e.id] = {
36
39
  enteringTerms,
37
40
  canEnterCategory: !enteringTerms.includes(false),
@@ -48,6 +51,7 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
48
51
  };
49
52
  export function _getAaveV3MarketData(provider_1, network_1, market_1) {
50
53
  return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
54
+ var _a;
51
55
  const _addresses = market.assets.map(a => getAssetInfo(getWrappedNativeAssetFromUnwrapped(a), network).address);
52
56
  const loanInfoContract = AaveV3ViewContractViem(provider, network);
53
57
  const aaveIncentivesContract = AaveIncentiveDataProviderV3ContractViem(provider, network);
@@ -81,6 +85,7 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
81
85
  borrowableBitmap: eModesInfo[i].borrowableBitmap.toString(),
82
86
  collateralBitmap: eModesInfo[i].collateralBitmap.toString(),
83
87
  ltvzeroBitmap: eModesInfo[i].ltvzeroBitmap.toString(),
88
+ isolated: (_a = eModesInfo[i].isolated) !== null && _a !== void 0 ? _a : false,
84
89
  borrowAssets: [],
85
90
  collateralAssets: [],
86
91
  ltvZeroAssets: [],
@@ -296,6 +301,7 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
296
301
  collateralAssets: assetsData.map((a) => a.symbol),
297
302
  borrowAssets: assetsData.map((a) => a.symbol),
298
303
  ltvZeroAssets: [],
304
+ isolated: false,
299
305
  };
300
306
  return { assetsData: payload, eModeCategoriesData };
301
307
  });
@@ -1,4 +1,4 @@
1
- import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions } from '../../types';
1
+ import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions, EModeCategoriesData } from '../../types';
2
2
  import { EthereumProvider, NetworkNumber } from '../../types/common';
3
3
  export declare const AAVE_V3_MARKETS: AaveVersions[];
4
4
  export declare const isAaveV2: ({ selectedMarket }: {
@@ -15,6 +15,14 @@ export declare const aaveV3IsInSiloedMode: ({ usedAssets, assetsData }: {
15
15
  usedAssets: AaveV3UsedAssets;
16
16
  assetsData: AaveV3AssetsData;
17
17
  }) => boolean;
18
+ export declare const aaveV3IsEmodeIsolated: ({ eModeCategory, eModeCategoriesData }: {
19
+ eModeCategory: number;
20
+ eModeCategoriesData?: EModeCategoriesData;
21
+ }) => boolean;
22
+ export declare const aaveV3CanBeCollateralInEmode: ({ eModeCategory, eModeCategoriesData }: {
23
+ eModeCategory: number;
24
+ eModeCategoriesData?: EModeCategoriesData;
25
+ }, _asset: string) => boolean;
18
26
  export declare const aaveAnyGetCollSuppliedAssets: ({ usedAssets }: {
19
27
  usedAssets: AaveV3UsedAssets;
20
28
  }) => AaveV3UsedAsset[];
@@ -33,6 +33,12 @@ export const isAaveV2 = ({ selectedMarket }) => selectedMarket.value === AaveVer
33
33
  export const isAaveV3 = ({ selectedMarket }) => AAVE_V3_MARKETS.includes(selectedMarket.value);
34
34
  export const aaveV3IsInIsolationMode = ({ usedAssets, assetsData }) => Object.values(usedAssets).some(({ symbol, collateral }) => collateral && assetsData[symbol].isIsolated);
35
35
  export const aaveV3IsInSiloedMode = ({ usedAssets, assetsData }) => Object.values(usedAssets).some(({ symbol, debt }) => debt && assetsData[symbol].isSiloed);
36
+ export const aaveV3IsEmodeIsolated = ({ eModeCategory, eModeCategoriesData }) => { var _a; return eModeCategory !== 0 && !!((_a = eModeCategoriesData === null || eModeCategoriesData === void 0 ? void 0 : eModeCategoriesData[eModeCategory]) === null || _a === void 0 ? void 0 : _a.isolated); };
37
+ export const aaveV3CanBeCollateralInEmode = ({ eModeCategory, eModeCategoriesData }, _asset) => {
38
+ if (!aaveV3IsEmodeIsolated({ eModeCategory, eModeCategoriesData }))
39
+ return true;
40
+ return eModeCategoriesData[eModeCategory].collateralAssets.includes(getNativeAssetFromWrapped(_asset));
41
+ };
36
42
  export const aaveAnyGetCollSuppliedAssets = ({ usedAssets }) => Object.values(usedAssets)
37
43
  .filter(({ isSupplied, collateral }) => isSupplied && collateral);
38
44
  export const aaveAnyGetSuppliableAssets = (_a) => {
@@ -40,13 +46,16 @@ export const aaveAnyGetSuppliableAssets = (_a) => {
40
46
  const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
41
47
  const collAccountAssets = aaveAnyGetCollSuppliedAssets(data);
42
48
  const marketAssets = Object.values(assetsData);
43
- if (collAccountAssets.length === 0 || !isAaveV3(data))
49
+ if (!isAaveV3(data))
44
50
  return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: true }));
51
+ const canBeCollateralInEmode = (symbol) => aaveV3CanBeCollateralInEmode(data, symbol);
52
+ if (collAccountAssets.length === 0)
53
+ return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: canBeCollateralInEmode(symbol) }));
45
54
  if (aaveV3IsInIsolationMode(data)) {
46
55
  const collAsset = collAccountAssets[0].symbol;
47
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset }));
56
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset && canBeCollateralInEmode(symbol) }));
48
57
  }
49
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated }));
58
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated && canBeCollateralInEmode(symbol) }));
50
59
  };
51
60
  export const aaveAnyGetSuppliableAsCollAssets = (_a) => {
52
61
  var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
@@ -56,12 +65,15 @@ export const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData
56
65
  const asset = getNativeAssetFromWrapped(_asset);
57
66
  const assetData = assetsData[asset];
58
67
  const eModeCategoryData = (eModeCategoriesData === null || eModeCategoriesData === void 0 ? void 0 : eModeCategoriesData[eModeCategory]) || {
59
- collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0',
68
+ collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0', isolated: false,
60
69
  };
61
70
  if (eModeCategory === 0
62
71
  || !eModeCategoryData.collateralAssets.includes(asset)
63
72
  || new Dec(eModeCategoryData.collateralFactor || 0).eq(0)) {
64
73
  const { liquidationRatio, collateralFactor } = assetData;
74
+ if (eModeCategory !== 0 && eModeCategoryData.isolated && !eModeCategoryData.collateralAssets.includes(asset)) {
75
+ return ({ liquidationRatio, collateralFactor: '0' });
76
+ }
65
77
  return ({ liquidationRatio, collateralFactor });
66
78
  }
67
79
  if (eModeCategoryData.ltvZeroAssets.includes(asset))
@@ -96,7 +108,10 @@ export const aaveAnyGetUserReserveLtvAndLltv = ({ eModeCategory, eModeCategories
96
108
  || !eModeCategoryData
97
109
  || !eModeCategoryData.collateralAssets.includes(asset)
98
110
  || new Dec(eModeCategoryData.collateralFactor || 0).eq(0)) {
99
- return { ltv: assetData.collateralFactor, lltv: assetData.liquidationRatio };
111
+ const ltv = eModeCategory !== 0 && (eModeCategoryData === null || eModeCategoryData === void 0 ? void 0 : eModeCategoryData.isolated) && !eModeCategoryData.collateralAssets.includes(asset)
112
+ ? '0'
113
+ : assetData.collateralFactor;
114
+ return { ltv, lltv: assetData.liquidationRatio };
100
115
  }
101
116
  const ltv = eModeCategoryData.ltvZeroAssets.includes(asset) ? '0' : eModeCategoryData.collateralFactor;
102
117
  return { ltv, lltv: eModeCategoryData.liquidationRatio };
@@ -81,6 +81,7 @@ export const _getSparkMarketsData = (provider, network, selectedMarket) => __awa
81
81
  collateralAssets: eModeCategoriesData[emodeCategoryId] ? [...eModeCategoriesData[emodeCategoryId].collateralAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
82
82
  borrowAssets: eModeCategoriesData[emodeCategoryId] ? [...eModeCategoriesData[emodeCategoryId].borrowAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
83
83
  ltvZeroAssets: [],
84
+ isolated: false,
84
85
  };
85
86
  return ({
86
87
  symbol: selectedMarket.assets[i],
@@ -40,6 +40,7 @@ export interface EModeCategoryData {
40
40
  borrowAssets: string[];
41
41
  ltvzeroBitmap?: string;
42
42
  ltvZeroAssets: string[];
43
+ isolated: boolean;
43
44
  }
44
45
  export interface EModeCategoryDataMapping {
45
46
  enteringTerms: boolean[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.161",
3
+ "version": "2.1.162",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -61,7 +61,10 @@ export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: Aa
61
61
  ...extractedState, usedAssets, eModeCategory: e.id,
62
62
  });
63
63
  const willStayOverCollateralized = new Dec(afterEnteringCategory.ratio === 'NaN' ? '0' : afterEnteringCategory.ratio).eq(0) || new Dec(afterEnteringCategory.ratio).gt(afterEnteringCategory.liqPercent);
64
- const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized];
64
+ const collateralOnlyFromCategory = e.id === 0 || !e.isolated
65
+ ? true
66
+ : !usedAssetsValues.filter(u => u.isSupplied && u.collateral && !e.collateralAssets.includes(u.symbol)).length;
67
+ const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized, collateralOnlyFromCategory];
65
68
  categoriesMapping[e.id] = {
66
69
  enteringTerms,
67
70
  canEnterCategory: !enteringTerms.includes(false),
@@ -118,6 +121,7 @@ export async function _getAaveV3MarketData(provider: Client, network: NetworkNum
118
121
  borrowableBitmap: eModesInfo[i].borrowableBitmap.toString(),
119
122
  collateralBitmap: eModesInfo[i].collateralBitmap.toString(),
120
123
  ltvzeroBitmap: eModesInfo[i].ltvzeroBitmap.toString(),
124
+ isolated: eModesInfo[i].isolated ?? false,
121
125
  borrowAssets: [],
122
126
  collateralAssets: [],
123
127
  ltvZeroAssets: [],
@@ -345,6 +349,7 @@ export async function _getAaveV3MarketData(provider: Client, network: NetworkNum
345
349
  collateralAssets: assetsData.map((a) => a.symbol),
346
350
  borrowAssets: assetsData.map((a) => a.symbol),
347
351
  ltvZeroAssets: [],
352
+ isolated: false,
348
353
  };
349
354
 
350
355
  return { assetsData: payload, eModeCategoriesData };
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
2
2
  import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
3
3
  import { Client } from 'viem';
4
4
  import {
5
- AaveAssetData, AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions,
5
+ AaveAssetData, AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, AaveV3UsedAssets, AaveVersions, EModeCategoriesData,
6
6
  } from '../../types';
7
7
  import { getNativeAssetFromWrapped, getWrappedNativeAssetFromUnwrapped } from '../../services/utils';
8
8
  import {
@@ -24,6 +24,13 @@ export const isAaveV3 = ({ selectedMarket }: { selectedMarket: Partial<AaveMarke
24
24
  export const aaveV3IsInIsolationMode = ({ usedAssets, assetsData }: { usedAssets: AaveV3UsedAssets, assetsData: AaveV3AssetsData }) => Object.values(usedAssets).some(({ symbol, collateral }) => collateral && assetsData[symbol].isIsolated);
25
25
  export const aaveV3IsInSiloedMode = ({ usedAssets, assetsData }: { usedAssets: AaveV3UsedAssets, assetsData: AaveV3AssetsData }) => Object.values(usedAssets).some(({ symbol, debt }) => debt && assetsData[symbol].isSiloed);
26
26
 
27
+ export const aaveV3IsEmodeIsolated = ({ eModeCategory, eModeCategoriesData }: { eModeCategory: number, eModeCategoriesData?: EModeCategoriesData }) => eModeCategory !== 0 && !!eModeCategoriesData?.[eModeCategory]?.isolated;
28
+
29
+ export const aaveV3CanBeCollateralInEmode = ({ eModeCategory, eModeCategoriesData }: { eModeCategory: number, eModeCategoriesData?: EModeCategoriesData }, _asset: string) => {
30
+ if (!aaveV3IsEmodeIsolated({ eModeCategory, eModeCategoriesData })) return true;
31
+ return eModeCategoriesData![eModeCategory].collateralAssets.includes(getNativeAssetFromWrapped(_asset));
32
+ };
33
+
27
34
  export const aaveAnyGetCollSuppliedAssets = ({ usedAssets }: { usedAssets: AaveV3UsedAssets }) => Object.values(usedAssets)
28
35
  .filter(({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral);
29
36
 
@@ -37,14 +44,18 @@ export const aaveAnyGetSuppliableAssets = ({
37
44
  const collAccountAssets = aaveAnyGetCollSuppliedAssets(data);
38
45
  const marketAssets = Object.values(assetsData) as AaveAssetData[];
39
46
 
40
- if (collAccountAssets.length === 0 || !isAaveV3(data)) return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: true }));
47
+ if (!isAaveV3(data)) return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: true }));
48
+
49
+ const canBeCollateralInEmode = (symbol: string) => aaveV3CanBeCollateralInEmode(data, symbol);
50
+
51
+ if (collAccountAssets.length === 0) return marketAssets.filter(({ canBeSupplied }) => canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: canBeCollateralInEmode(symbol) }));
41
52
 
42
53
  if (aaveV3IsInIsolationMode(data)) {
43
54
  const collAsset = collAccountAssets[0].symbol;
44
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset }));
55
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol }) => ({ symbol, canBeCollateral: symbol === collAsset && canBeCollateralInEmode(symbol) }));
45
56
  }
46
57
 
47
- return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated }));
58
+ return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated && canBeCollateralInEmode(symbol) }));
48
59
  };
49
60
 
50
61
  export const aaveAnyGetSuppliableAsCollAssets = ({
@@ -62,8 +73,8 @@ export const aaveAnyGetEmodeMutableProps = (
62
73
  const asset = getNativeAssetFromWrapped(_asset);
63
74
 
64
75
  const assetData = assetsData[asset];
65
- const eModeCategoryData: { collateralAssets: string[], collateralFactor: string, liquidationRatio: string, ltvZeroAssets: string[] } = eModeCategoriesData?.[eModeCategory] || {
66
- collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0',
76
+ const eModeCategoryData: { collateralAssets: string[], collateralFactor: string, liquidationRatio: string, ltvZeroAssets: string[], isolated?: boolean } = eModeCategoriesData?.[eModeCategory] || {
77
+ collateralAssets: [], ltvZeroAssets: [], collateralFactor: '0', liquidationRatio: '0', isolated: false,
67
78
  };
68
79
 
69
80
  if (
@@ -72,6 +83,9 @@ export const aaveAnyGetEmodeMutableProps = (
72
83
  || new Dec(eModeCategoryData.collateralFactor || 0).eq(0)
73
84
  ) {
74
85
  const { liquidationRatio, collateralFactor } = assetData;
86
+ if (eModeCategory !== 0 && eModeCategoryData.isolated && !eModeCategoryData.collateralAssets.includes(asset)) {
87
+ return ({ liquidationRatio, collateralFactor: '0' });
88
+ }
75
89
  return ({ liquidationRatio, collateralFactor });
76
90
  }
77
91
  if (eModeCategoryData.ltvZeroAssets.includes(asset)) return ({ liquidationRatio: '0', collateralFactor: '0' });
@@ -118,7 +132,10 @@ export const aaveAnyGetUserReserveLtvAndLltv = (
118
132
  || !eModeCategoryData.collateralAssets.includes(asset)
119
133
  || new Dec(eModeCategoryData.collateralFactor || 0).eq(0)
120
134
  ) {
121
- return { ltv: assetData.collateralFactor, lltv: assetData.liquidationRatio };
135
+ const ltv = eModeCategory !== 0 && eModeCategoryData?.isolated && !eModeCategoryData.collateralAssets.includes(asset)
136
+ ? '0'
137
+ : assetData.collateralFactor;
138
+ return { ltv, lltv: assetData.liquidationRatio };
122
139
  }
123
140
 
124
141
  const ltv = eModeCategoryData.ltvZeroAssets.includes(asset) ? '0' : eModeCategoryData.collateralFactor;
@@ -108,6 +108,7 @@ export const _getSparkMarketsData = async (provider: Client, network: NetworkNum
108
108
  collateralAssets: eModeCategoriesData[emodeCategoryId] ? [...eModeCategoriesData[emodeCategoryId].collateralAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
109
109
  borrowAssets: eModeCategoriesData[emodeCategoryId] ? [...eModeCategoriesData[emodeCategoryId].borrowAssets, selectedMarket.assets[i]] : [selectedMarket.assets[i]],
110
110
  ltvZeroAssets: [],
111
+ isolated: false,
111
112
  };
112
113
 
113
114
  return ({
package/src/types/aave.ts CHANGED
@@ -48,6 +48,7 @@ export interface EModeCategoryData {
48
48
  borrowAssets: string[],
49
49
  ltvzeroBitmap?: string,
50
50
  ltvZeroAssets: string[],
51
+ isolated: boolean,
51
52
  }
52
53
  export interface EModeCategoryDataMapping {
53
54
  enteringTerms: boolean[],