@defisaver/positions-sdk 2.1.108 → 2.1.109-ltv-0-automations-dev
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/helpers/aaveHelpers/index.d.ts +11 -0
- package/cjs/helpers/aaveHelpers/index.js +39 -1
- package/cjs/helpers/aaveV4Helpers/index.d.ts +1 -0
- package/cjs/helpers/aaveV4Helpers/index.js +1 -0
- package/cjs/types/aave.d.ts +3 -0
- package/esm/helpers/aaveHelpers/index.d.ts +11 -0
- package/esm/helpers/aaveHelpers/index.js +37 -0
- package/esm/helpers/aaveV4Helpers/index.d.ts +1 -0
- package/esm/helpers/aaveV4Helpers/index.js +1 -0
- package/esm/types/aave.d.ts +3 -0
- package/package.json +1 -1
- package/src/helpers/aaveHelpers/index.ts +54 -0
- package/src/helpers/aaveV4Helpers/index.ts +2 -1
- package/src/types/aave.ts +4 -0
|
@@ -30,6 +30,17 @@ export declare const aaveAnyGetEmodeMutableProps: ({ eModeCategory, eModeCategor
|
|
|
30
30
|
liquidationRatio: any;
|
|
31
31
|
collateralFactor: any;
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* @description Per-asset effective LTV and liquidation threshold (LLTV) for the user, eMode-aware.
|
|
35
|
+
* Mirrors AaveV3View._getUserReserveLtvAndLltv: an asset in the active eMode's ltv-zero set has
|
|
36
|
+
* ltv 0 but KEEPS the eMode liquidation threshold (liquidations only consider LLTV). The returned
|
|
37
|
+
* `ltv` is identical to aaveAnyGetEmodeMutableProps().collateralFactor in every branch, so a ratio
|
|
38
|
+
* built on this matches the regular safety ratio whenever no collateral is LTV-0.
|
|
39
|
+
*/
|
|
40
|
+
export declare const aaveAnyGetUserReserveLtvAndLltv: ({ eModeCategory, eModeCategoriesData, assetsData, }: AaveHelperCommon, _asset: string) => {
|
|
41
|
+
ltv: string;
|
|
42
|
+
lltv: string;
|
|
43
|
+
};
|
|
33
44
|
export declare const aaveAnyGetAggregatedPositionData: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => AaveV3AggregatedPositionData;
|
|
34
45
|
export declare const getApyAfterValuesEstimation: (selectedMarket: AaveMarketInfo, actions: [{
|
|
35
46
|
action: string;
|
|
@@ -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.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.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");
|
|
@@ -83,6 +83,33 @@ const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData, asset
|
|
|
83
83
|
return ({ liquidationRatio, collateralFactor });
|
|
84
84
|
};
|
|
85
85
|
exports.aaveAnyGetEmodeMutableProps = aaveAnyGetEmodeMutableProps;
|
|
86
|
+
/**
|
|
87
|
+
* @description Offset subtracted from the liquidation threshold (LLTV) when crediting LTV-0 collateral
|
|
88
|
+
* in the safety-ratio fallback. Matches AaveV3View.getSafetyRatioWithLtvZeroFallback ('LLTV - 5%').
|
|
89
|
+
* Values are fractions (e.g. 0.8), so 5% === 0.05.
|
|
90
|
+
*/
|
|
91
|
+
const LTV_ZERO_FALLBACK_LLTV_OFFSET = '0.05';
|
|
92
|
+
/**
|
|
93
|
+
* @description Per-asset effective LTV and liquidation threshold (LLTV) for the user, eMode-aware.
|
|
94
|
+
* Mirrors AaveV3View._getUserReserveLtvAndLltv: an asset in the active eMode's ltv-zero set has
|
|
95
|
+
* ltv 0 but KEEPS the eMode liquidation threshold (liquidations only consider LLTV). The returned
|
|
96
|
+
* `ltv` is identical to aaveAnyGetEmodeMutableProps().collateralFactor in every branch, so a ratio
|
|
97
|
+
* built on this matches the regular safety ratio whenever no collateral is LTV-0.
|
|
98
|
+
*/
|
|
99
|
+
const aaveAnyGetUserReserveLtvAndLltv = ({ eModeCategory, eModeCategoriesData, assetsData, }, _asset) => {
|
|
100
|
+
const asset = (0, utils_1.getNativeAssetFromWrapped)(_asset);
|
|
101
|
+
const assetData = assetsData[asset];
|
|
102
|
+
const eModeCategoryData = eModeCategoriesData === null || eModeCategoriesData === void 0 ? void 0 : eModeCategoriesData[eModeCategory];
|
|
103
|
+
if (eModeCategory === 0
|
|
104
|
+
|| !eModeCategoryData
|
|
105
|
+
|| !eModeCategoryData.collateralAssets.includes(asset)
|
|
106
|
+
|| new decimal_js_1.default(eModeCategoryData.collateralFactor || 0).eq(0)) {
|
|
107
|
+
return { ltv: assetData.collateralFactor, lltv: assetData.liquidationRatio };
|
|
108
|
+
}
|
|
109
|
+
const ltv = eModeCategoryData.ltvZeroAssets.includes(asset) ? '0' : eModeCategoryData.collateralFactor;
|
|
110
|
+
return { ltv, lltv: eModeCategoryData.liquidationRatio };
|
|
111
|
+
};
|
|
112
|
+
exports.aaveAnyGetUserReserveLtvAndLltv = aaveAnyGetUserReserveLtvAndLltv;
|
|
86
113
|
const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
87
114
|
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
88
115
|
const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
|
|
@@ -96,6 +123,17 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
96
123
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
97
124
|
payload.ratio = +payload.suppliedUsd ? new decimal_js_1.default(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
98
125
|
payload.collRatio = +payload.suppliedUsd ? new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
126
|
+
// Safety ratio as evaluated by the automation bots: LTV-0 collateral is credited at (LLTV - 5%)
|
|
127
|
+
// instead of 0 (AaveV3View.getSafetyRatioWithLtvZeroFallback). Equals `ratio` when no collateral
|
|
128
|
+
// is LTV-0. Computed off-chain here so it is available for after-value simulations too.
|
|
129
|
+
payload.borrowLimitWithLtvZeroFallbackUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
130
|
+
const { ltv, lltv } = (0, exports.aaveAnyGetUserReserveLtvAndLltv)(data, symbol);
|
|
131
|
+
const effectiveLtv = new decimal_js_1.default(ltv).eq(0)
|
|
132
|
+
? decimal_js_1.default.max(0, new decimal_js_1.default(lltv).sub(LTV_ZERO_FALLBACK_LLTV_OFFSET))
|
|
133
|
+
: new decimal_js_1.default(ltv);
|
|
134
|
+
return new decimal_js_1.default(suppliedUsd).mul(effectiveLtv);
|
|
135
|
+
});
|
|
136
|
+
payload.safetyRatioWithLtvZeroFallback = +payload.suppliedUsd ? new decimal_js_1.default(payload.borrowLimitWithLtvZeroFallbackUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
99
137
|
payload.liqRatio = new decimal_js_1.default(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
100
138
|
payload.liqPercent = new decimal_js_1.default(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
101
139
|
const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
|
|
@@ -264,6 +264,7 @@ const getAaveV4ApyAfterValuesEstimationInner = (selectedSpoke, assetsData, actio
|
|
|
264
264
|
rates[`${assetData === null || assetData === void 0 ? void 0 : assetData.symbol}-${assetData === null || assetData === void 0 ? void 0 : assetData.reserveId}`] = {
|
|
265
265
|
borrowRate: (0, moneymarket_1.aprToApy)(borrowApr.toString()),
|
|
266
266
|
supplyRate: (0, moneymarket_1.aprToApy)(supplyApr.toString()),
|
|
267
|
+
drawnRate: drawnRate.toString(),
|
|
267
268
|
};
|
|
268
269
|
});
|
|
269
270
|
return rates;
|
package/cjs/types/aave.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ export interface AavePositionData extends MMPositionData {
|
|
|
125
125
|
ratio: string;
|
|
126
126
|
minRatio: string;
|
|
127
127
|
collRatio: string;
|
|
128
|
+
safetyRatioWithLtvZeroFallback?: string;
|
|
128
129
|
suppliedUsd: string;
|
|
129
130
|
borrowedUsd: string;
|
|
130
131
|
borrowLimitUsd: string;
|
|
@@ -156,6 +157,8 @@ export interface AaveV3AggregatedPositionData {
|
|
|
156
157
|
leftToBorrowUsd: string;
|
|
157
158
|
ratio: string;
|
|
158
159
|
collRatio: string;
|
|
160
|
+
borrowLimitWithLtvZeroFallbackUsd: string;
|
|
161
|
+
safetyRatioWithLtvZeroFallback: string;
|
|
159
162
|
netApy: string;
|
|
160
163
|
incentiveUsd: string;
|
|
161
164
|
totalInterestUsd: string;
|
|
@@ -30,6 +30,17 @@ export declare const aaveAnyGetEmodeMutableProps: ({ eModeCategory, eModeCategor
|
|
|
30
30
|
liquidationRatio: any;
|
|
31
31
|
collateralFactor: any;
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* @description Per-asset effective LTV and liquidation threshold (LLTV) for the user, eMode-aware.
|
|
35
|
+
* Mirrors AaveV3View._getUserReserveLtvAndLltv: an asset in the active eMode's ltv-zero set has
|
|
36
|
+
* ltv 0 but KEEPS the eMode liquidation threshold (liquidations only consider LLTV). The returned
|
|
37
|
+
* `ltv` is identical to aaveAnyGetEmodeMutableProps().collateralFactor in every branch, so a ratio
|
|
38
|
+
* built on this matches the regular safety ratio whenever no collateral is LTV-0.
|
|
39
|
+
*/
|
|
40
|
+
export declare const aaveAnyGetUserReserveLtvAndLltv: ({ eModeCategory, eModeCategoriesData, assetsData, }: AaveHelperCommon, _asset: string) => {
|
|
41
|
+
ltv: string;
|
|
42
|
+
lltv: string;
|
|
43
|
+
};
|
|
33
44
|
export declare const aaveAnyGetAggregatedPositionData: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => AaveV3AggregatedPositionData;
|
|
34
45
|
export declare const getApyAfterValuesEstimation: (selectedMarket: AaveMarketInfo, actions: [{
|
|
35
46
|
action: string;
|
|
@@ -69,6 +69,32 @@ export const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData
|
|
|
69
69
|
const { liquidationRatio, collateralFactor } = eModeCategoryData;
|
|
70
70
|
return ({ liquidationRatio, collateralFactor });
|
|
71
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* @description Offset subtracted from the liquidation threshold (LLTV) when crediting LTV-0 collateral
|
|
74
|
+
* in the safety-ratio fallback. Matches AaveV3View.getSafetyRatioWithLtvZeroFallback ('LLTV - 5%').
|
|
75
|
+
* Values are fractions (e.g. 0.8), so 5% === 0.05.
|
|
76
|
+
*/
|
|
77
|
+
const LTV_ZERO_FALLBACK_LLTV_OFFSET = '0.05';
|
|
78
|
+
/**
|
|
79
|
+
* @description Per-asset effective LTV and liquidation threshold (LLTV) for the user, eMode-aware.
|
|
80
|
+
* Mirrors AaveV3View._getUserReserveLtvAndLltv: an asset in the active eMode's ltv-zero set has
|
|
81
|
+
* ltv 0 but KEEPS the eMode liquidation threshold (liquidations only consider LLTV). The returned
|
|
82
|
+
* `ltv` is identical to aaveAnyGetEmodeMutableProps().collateralFactor in every branch, so a ratio
|
|
83
|
+
* built on this matches the regular safety ratio whenever no collateral is LTV-0.
|
|
84
|
+
*/
|
|
85
|
+
export const aaveAnyGetUserReserveLtvAndLltv = ({ eModeCategory, eModeCategoriesData, assetsData, }, _asset) => {
|
|
86
|
+
const asset = getNativeAssetFromWrapped(_asset);
|
|
87
|
+
const assetData = assetsData[asset];
|
|
88
|
+
const eModeCategoryData = eModeCategoriesData === null || eModeCategoriesData === void 0 ? void 0 : eModeCategoriesData[eModeCategory];
|
|
89
|
+
if (eModeCategory === 0
|
|
90
|
+
|| !eModeCategoryData
|
|
91
|
+
|| !eModeCategoryData.collateralAssets.includes(asset)
|
|
92
|
+
|| new Dec(eModeCategoryData.collateralFactor || 0).eq(0)) {
|
|
93
|
+
return { ltv: assetData.collateralFactor, lltv: assetData.liquidationRatio };
|
|
94
|
+
}
|
|
95
|
+
const ltv = eModeCategoryData.ltvZeroAssets.includes(asset) ? '0' : eModeCategoryData.collateralFactor;
|
|
96
|
+
return { ltv, lltv: eModeCategoryData.liquidationRatio };
|
|
97
|
+
};
|
|
72
98
|
export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
73
99
|
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
74
100
|
const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
|
|
@@ -82,6 +108,17 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
82
108
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
83
109
|
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
84
110
|
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
111
|
+
// Safety ratio as evaluated by the automation bots: LTV-0 collateral is credited at (LLTV - 5%)
|
|
112
|
+
// instead of 0 (AaveV3View.getSafetyRatioWithLtvZeroFallback). Equals `ratio` when no collateral
|
|
113
|
+
// is LTV-0. Computed off-chain here so it is available for after-value simulations too.
|
|
114
|
+
payload.borrowLimitWithLtvZeroFallbackUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
115
|
+
const { ltv, lltv } = aaveAnyGetUserReserveLtvAndLltv(data, symbol);
|
|
116
|
+
const effectiveLtv = new Dec(ltv).eq(0)
|
|
117
|
+
? Dec.max(0, new Dec(lltv).sub(LTV_ZERO_FALLBACK_LLTV_OFFSET))
|
|
118
|
+
: new Dec(ltv);
|
|
119
|
+
return new Dec(suppliedUsd).mul(effectiveLtv);
|
|
120
|
+
});
|
|
121
|
+
payload.safetyRatioWithLtvZeroFallback = +payload.suppliedUsd ? new Dec(payload.borrowLimitWithLtvZeroFallbackUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
85
122
|
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
86
123
|
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
87
124
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
@@ -253,6 +253,7 @@ const getAaveV4ApyAfterValuesEstimationInner = (selectedSpoke, assetsData, actio
|
|
|
253
253
|
rates[`${assetData === null || assetData === void 0 ? void 0 : assetData.symbol}-${assetData === null || assetData === void 0 ? void 0 : assetData.reserveId}`] = {
|
|
254
254
|
borrowRate: aprToApy(borrowApr.toString()),
|
|
255
255
|
supplyRate: aprToApy(supplyApr.toString()),
|
|
256
|
+
drawnRate: drawnRate.toString(),
|
|
256
257
|
};
|
|
257
258
|
});
|
|
258
259
|
return rates;
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ export interface AavePositionData extends MMPositionData {
|
|
|
125
125
|
ratio: string;
|
|
126
126
|
minRatio: string;
|
|
127
127
|
collRatio: string;
|
|
128
|
+
safetyRatioWithLtvZeroFallback?: string;
|
|
128
129
|
suppliedUsd: string;
|
|
129
130
|
borrowedUsd: string;
|
|
130
131
|
borrowLimitUsd: string;
|
|
@@ -156,6 +157,8 @@ export interface AaveV3AggregatedPositionData {
|
|
|
156
157
|
leftToBorrowUsd: string;
|
|
157
158
|
ratio: string;
|
|
158
159
|
collRatio: string;
|
|
160
|
+
borrowLimitWithLtvZeroFallbackUsd: string;
|
|
161
|
+
safetyRatioWithLtvZeroFallback: string;
|
|
159
162
|
netApy: string;
|
|
160
163
|
incentiveUsd: string;
|
|
161
164
|
totalInterestUsd: string;
|
package/package.json
CHANGED
|
@@ -80,6 +80,45 @@ export const aaveAnyGetEmodeMutableProps = (
|
|
|
80
80
|
return ({ liquidationRatio, collateralFactor });
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* @description Offset subtracted from the liquidation threshold (LLTV) when crediting LTV-0 collateral
|
|
85
|
+
* in the safety-ratio fallback. Matches AaveV3View.getSafetyRatioWithLtvZeroFallback ('LLTV - 5%').
|
|
86
|
+
* Values are fractions (e.g. 0.8), so 5% === 0.05.
|
|
87
|
+
*/
|
|
88
|
+
const LTV_ZERO_FALLBACK_LLTV_OFFSET = '0.05';
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @description Per-asset effective LTV and liquidation threshold (LLTV) for the user, eMode-aware.
|
|
92
|
+
* Mirrors AaveV3View._getUserReserveLtvAndLltv: an asset in the active eMode's ltv-zero set has
|
|
93
|
+
* ltv 0 but KEEPS the eMode liquidation threshold (liquidations only consider LLTV). The returned
|
|
94
|
+
* `ltv` is identical to aaveAnyGetEmodeMutableProps().collateralFactor in every branch, so a ratio
|
|
95
|
+
* built on this matches the regular safety ratio whenever no collateral is LTV-0.
|
|
96
|
+
*/
|
|
97
|
+
export const aaveAnyGetUserReserveLtvAndLltv = (
|
|
98
|
+
{
|
|
99
|
+
eModeCategory,
|
|
100
|
+
eModeCategoriesData,
|
|
101
|
+
assetsData,
|
|
102
|
+
}: AaveHelperCommon,
|
|
103
|
+
_asset: string,
|
|
104
|
+
): { ltv: string, lltv: string } => {
|
|
105
|
+
const asset = getNativeAssetFromWrapped(_asset);
|
|
106
|
+
const assetData = assetsData[asset];
|
|
107
|
+
const eModeCategoryData = eModeCategoriesData?.[eModeCategory];
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
eModeCategory === 0
|
|
111
|
+
|| !eModeCategoryData
|
|
112
|
+
|| !eModeCategoryData.collateralAssets.includes(asset)
|
|
113
|
+
|| new Dec(eModeCategoryData.collateralFactor || 0).eq(0)
|
|
114
|
+
) {
|
|
115
|
+
return { ltv: assetData.collateralFactor, lltv: assetData.liquidationRatio };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const ltv = eModeCategoryData.ltvZeroAssets.includes(asset) ? '0' : eModeCategoryData.collateralFactor;
|
|
119
|
+
return { ltv, lltv: eModeCategoryData.liquidationRatio };
|
|
120
|
+
};
|
|
121
|
+
|
|
83
122
|
export const aaveAnyGetAggregatedPositionData = ({
|
|
84
123
|
usedAssets,
|
|
85
124
|
eModeCategory,
|
|
@@ -109,6 +148,21 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
109
148
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
110
149
|
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
111
150
|
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
151
|
+
// Safety ratio as evaluated by the automation bots: LTV-0 collateral is credited at (LLTV - 5%)
|
|
152
|
+
// instead of 0 (AaveV3View.getSafetyRatioWithLtvZeroFallback). Equals `ratio` when no collateral
|
|
153
|
+
// is LTV-0. Computed off-chain here so it is available for after-value simulations too.
|
|
154
|
+
payload.borrowLimitWithLtvZeroFallbackUsd = getAssetsTotal(
|
|
155
|
+
usedAssets,
|
|
156
|
+
({ isSupplied, collateral }: { isSupplied: boolean, collateral: string }) => isSupplied && collateral,
|
|
157
|
+
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => {
|
|
158
|
+
const { ltv, lltv } = aaveAnyGetUserReserveLtvAndLltv(data, symbol);
|
|
159
|
+
const effectiveLtv = new Dec(ltv).eq(0)
|
|
160
|
+
? Dec.max(0, new Dec(lltv).sub(LTV_ZERO_FALLBACK_LLTV_OFFSET))
|
|
161
|
+
: new Dec(ltv);
|
|
162
|
+
return new Dec(suppliedUsd).mul(effectiveLtv);
|
|
163
|
+
},
|
|
164
|
+
);
|
|
165
|
+
payload.safetyRatioWithLtvZeroFallback = +payload.suppliedUsd ? new Dec(payload.borrowLimitWithLtvZeroFallbackUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
112
166
|
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
113
167
|
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
114
168
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
@@ -296,7 +296,7 @@ const getAaveV4ApyAfterValuesEstimationInner = async (selectedSpoke: AaveV4Spoke
|
|
|
296
296
|
const viewContract = AaveV4ViewContractViem(client, network);
|
|
297
297
|
const data = await viewContract.read.getApyAfterValuesEstimation([selectedSpoke.address, params]);
|
|
298
298
|
|
|
299
|
-
const rates: { [key: string]: { supplyRate: string, borrowRate: string } } = {};
|
|
299
|
+
const rates: { [key: string]: { supplyRate: string, borrowRate: string, drawnRate: string } } = {};
|
|
300
300
|
data.forEach((item: any) => {
|
|
301
301
|
const {
|
|
302
302
|
hubDrawnRateEstimation, hubTotalDrawnEstimation, hubTotalLiquidityEstimation, hubSwept, reserveId,
|
|
@@ -316,6 +316,7 @@ const getAaveV4ApyAfterValuesEstimationInner = async (selectedSpoke: AaveV4Spoke
|
|
|
316
316
|
rates[`${assetData?.symbol}-${assetData?.reserveId}`] = {
|
|
317
317
|
borrowRate: aprToApy(borrowApr.toString()),
|
|
318
318
|
supplyRate: aprToApy(supplyApr.toString()),
|
|
319
|
+
drawnRate: drawnRate.toString(),
|
|
319
320
|
};
|
|
320
321
|
});
|
|
321
322
|
return rates;
|
package/src/types/aave.ts
CHANGED
|
@@ -141,6 +141,8 @@ export interface AavePositionData extends MMPositionData {
|
|
|
141
141
|
ratio: string,
|
|
142
142
|
minRatio: string,
|
|
143
143
|
collRatio: string,
|
|
144
|
+
// Safety ratio as evaluated by automation bots (LTV-0 collateral credited at LLTV - 5%). Aave v3 only.
|
|
145
|
+
safetyRatioWithLtvZeroFallback?: string,
|
|
144
146
|
suppliedUsd: string,
|
|
145
147
|
borrowedUsd: string,
|
|
146
148
|
borrowLimitUsd: string,
|
|
@@ -173,6 +175,8 @@ export interface AaveV3AggregatedPositionData {
|
|
|
173
175
|
leftToBorrowUsd: string,
|
|
174
176
|
ratio: string,
|
|
175
177
|
collRatio: string,
|
|
178
|
+
borrowLimitWithLtvZeroFallbackUsd: string,
|
|
179
|
+
safetyRatioWithLtvZeroFallback: string,
|
|
176
180
|
netApy: string,
|
|
177
181
|
incentiveUsd: string,
|
|
178
182
|
totalInterestUsd: string,
|