@defisaver/positions-sdk 2.1.52-dev → 2.1.52-dev-2
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/fluid/index.d.ts +3 -3
- package/cjs/helpers/aaveHelpers/index.js +15 -5
- package/cjs/helpers/compoundHelpers/index.js +1 -1
- package/cjs/helpers/eulerHelpers/index.d.ts +2 -2
- package/cjs/helpers/eulerHelpers/index.js +6 -5
- package/cjs/helpers/fluidHelpers/index.js +2 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/cjs/moneymarket/moneymarketCommonService.js +8 -7
- package/cjs/types/aave.d.ts +2 -2
- package/cjs/types/common.d.ts +8 -0
- package/cjs/types/common.js +10 -1
- package/cjs/types/compound.d.ts +2 -2
- package/cjs/types/curveUsd.d.ts +2 -2
- package/cjs/types/euler.d.ts +2 -2
- package/cjs/types/fluid.d.ts +2 -2
- package/cjs/types/liquityV2.d.ts +3 -3
- package/cjs/types/llamaLend.d.ts +2 -2
- package/cjs/types/morphoBlue.d.ts +3 -3
- package/cjs/types/spark.d.ts +2 -2
- package/esm/fluid/index.d.ts +3 -3
- package/esm/helpers/aaveHelpers/index.js +15 -5
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/eulerHelpers/index.d.ts +2 -2
- package/esm/helpers/eulerHelpers/index.js +6 -5
- package/esm/helpers/fluidHelpers/index.js +2 -1
- package/esm/helpers/morphoBlueHelpers/index.js +2 -2
- package/esm/helpers/sparkHelpers/index.js +2 -2
- package/esm/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/esm/moneymarket/moneymarketCommonService.js +8 -7
- package/esm/types/aave.d.ts +2 -2
- package/esm/types/common.d.ts +8 -0
- package/esm/types/common.js +9 -0
- package/esm/types/compound.d.ts +2 -2
- package/esm/types/curveUsd.d.ts +2 -2
- package/esm/types/euler.d.ts +2 -2
- package/esm/types/fluid.d.ts +2 -2
- package/esm/types/fluid.js +1 -1
- package/esm/types/liquityV2.d.ts +3 -3
- package/esm/types/llamaLend.d.ts +2 -2
- package/esm/types/morphoBlue.d.ts +3 -3
- package/esm/types/spark.d.ts +2 -2
- package/package.json +1 -1
- package/src/helpers/aaveHelpers/index.ts +16 -6
- package/src/helpers/compoundHelpers/index.ts +2 -2
- package/src/helpers/eulerHelpers/index.ts +6 -6
- package/src/helpers/fluidHelpers/index.ts +2 -2
- package/src/helpers/morphoBlueHelpers/index.ts +2 -2
- package/src/helpers/sparkHelpers/index.ts +4 -2
- package/src/moneymarket/moneymarketCommonService.ts +9 -9
- package/src/types/aave.ts +2 -1
- package/src/types/common.ts +9 -0
- package/src/types/compound.ts +2 -1
- package/src/types/curveUsd.ts +2 -2
- package/src/types/euler.ts +2 -1
- package/src/types/fluid.ts +4 -2
- package/src/types/liquityV2.ts +5 -3
- package/src/types/llamaLend.ts +4 -2
- package/src/types/morphoBlue.ts +3 -3
- package/src/types/spark.ts +2 -1
package/cjs/fluid/index.d.ts
CHANGED
|
@@ -130,7 +130,7 @@ export declare const _getUserPositions: (provider: PublicClient, network: Networ
|
|
|
130
130
|
collRatio: string;
|
|
131
131
|
minRatio: string;
|
|
132
132
|
totalInterestUsd: string;
|
|
133
|
-
leveragedType?:
|
|
133
|
+
leveragedType?: import("../types/common").LeverageType;
|
|
134
134
|
leveragedAsset?: string;
|
|
135
135
|
liquidationPrice?: string;
|
|
136
136
|
leveragedLsdAssetRatio?: string;
|
|
@@ -161,7 +161,7 @@ export declare const getUserPositions: (provider: EthereumProvider, network: Net
|
|
|
161
161
|
collRatio: string;
|
|
162
162
|
minRatio: string;
|
|
163
163
|
totalInterestUsd: string;
|
|
164
|
-
leveragedType?:
|
|
164
|
+
leveragedType?: import("../types/common").LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
liquidationPrice?: string;
|
|
167
167
|
leveragedLsdAssetRatio?: string;
|
|
@@ -192,7 +192,7 @@ export declare const _getUserPositionsPortfolio: (provider: PublicClient, networ
|
|
|
192
192
|
collRatio: string;
|
|
193
193
|
minRatio: string;
|
|
194
194
|
totalInterestUsd: string;
|
|
195
|
-
leveragedType?:
|
|
195
|
+
leveragedType?: import("../types/common").LeverageType;
|
|
196
196
|
leveragedAsset?: string;
|
|
197
197
|
liquidationPrice?: string;
|
|
198
198
|
leveragedLsdAssetRatio?: string;
|
|
@@ -31,6 +31,7 @@ const utils_1 = require("../../services/utils");
|
|
|
31
31
|
const moneymarket_1 = require("../../moneymarket");
|
|
32
32
|
const staking_1 = require("../../staking");
|
|
33
33
|
const constants_1 = require("../../constants");
|
|
34
|
+
const common_1 = require("../../types/common");
|
|
34
35
|
const contracts_1 = require("../../contracts");
|
|
35
36
|
const viem_1 = require("../../services/viem");
|
|
36
37
|
exports.AAVE_V3_MARKETS = [types_1.AaveVersions.AaveV3, types_1.AaveVersions.AaveV3Lido, types_1.AaveVersions.AaveV3Etherfi];
|
|
@@ -103,18 +104,27 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
103
104
|
payload.liquidationPrice = '';
|
|
104
105
|
if (leveragedType !== '') {
|
|
105
106
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
106
|
-
if (leveragedType ===
|
|
107
|
+
if (leveragedType === common_1.LeverageType.LsdLeverage) {
|
|
107
108
|
// Treat ETH like a stablecoin in a long stETH position
|
|
108
109
|
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
109
110
|
assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
|
|
110
111
|
}
|
|
111
|
-
if (leveragedType ===
|
|
112
|
+
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
112
113
|
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
113
114
|
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
116
|
+
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
117
|
+
if (isReverse) {
|
|
118
|
+
payload.leveragedType = common_1.LeverageType.VolatilePairReverse;
|
|
119
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
120
|
+
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(borrowedAssetPrice).toString();
|
|
124
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
125
|
+
}
|
|
116
126
|
}
|
|
117
|
-
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
127
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
118
128
|
}
|
|
119
129
|
payload.minCollRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
120
130
|
payload.collLiquidationRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -150,7 +150,7 @@ const getCompoundV3AggregatedData = (_a) => {
|
|
|
150
150
|
if (leveragedType !== '') {
|
|
151
151
|
payload.leveragedAsset = leveragedAsset;
|
|
152
152
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
153
|
-
if (leveragedType ===
|
|
153
|
+
if (leveragedType === common_1.LeverageType.LsdLeverage) {
|
|
154
154
|
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toString();
|
|
155
155
|
assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
|
|
156
156
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
1
|
+
import { EthAddress, EthereumProvider, LeverageType, NetworkNumber } from '../../types/common';
|
|
2
2
|
import { EulerV2AggregatedPositionData, EulerV2AssetsData, EulerV2UsedAssets } from '../../types';
|
|
3
3
|
export declare const isLeveragedPos: (usedAssets: EulerV2UsedAssets, dustLimit?: number) => {
|
|
4
|
-
leveragedType:
|
|
4
|
+
leveragedType: LeverageType;
|
|
5
5
|
leveragedAsset: string;
|
|
6
6
|
leveragedVault: string;
|
|
7
7
|
};
|
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.getEulerV2SubAccounts = exports.getApyAfterValuesEstimationEulerV2 = exports.getEulerV2SupplyRate = exports.getUtilizationRate = exports.getEulerV2BorrowRate = exports.getEulerV2AggregatedData = exports.isLeveragedPos = void 0;
|
|
27
27
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
28
28
|
const tokens_1 = require("@defisaver/tokens");
|
|
29
|
+
const common_1 = require("../../types/common");
|
|
29
30
|
const moneymarket_1 = require("../../moneymarket");
|
|
30
31
|
const staking_1 = require("../../staking");
|
|
31
32
|
const contracts_1 = require("../../contracts");
|
|
@@ -63,27 +64,27 @@ const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
63
64
|
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
64
65
|
if (isLong) {
|
|
65
66
|
return {
|
|
66
|
-
leveragedType:
|
|
67
|
+
leveragedType: common_1.LeverageType.Long,
|
|
67
68
|
leveragedAsset: longAsset,
|
|
68
69
|
leveragedVault: leverageAssetVault,
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
if (isShort) {
|
|
72
73
|
return {
|
|
73
|
-
leveragedType:
|
|
74
|
+
leveragedType: common_1.LeverageType.Short,
|
|
74
75
|
leveragedAsset: shortAsset,
|
|
75
76
|
leveragedVault: leverageAssetVault,
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
if (isLsdLeveraged) {
|
|
79
80
|
return {
|
|
80
|
-
leveragedType:
|
|
81
|
+
leveragedType: common_1.LeverageType.LsdLeverage,
|
|
81
82
|
leveragedAsset: longAsset,
|
|
82
83
|
leveragedVault: leverageAssetVault,
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
86
|
return {
|
|
86
|
-
leveragedType:
|
|
87
|
+
leveragedType: common_1.LeverageType.None,
|
|
87
88
|
leveragedAsset: '',
|
|
88
89
|
leveragedVault: '',
|
|
89
90
|
};
|
|
@@ -113,7 +114,7 @@ const getEulerV2AggregatedData = (_a) => {
|
|
|
113
114
|
if (leveragedType !== '') {
|
|
114
115
|
payload.leveragedAsset = leveragedAsset;
|
|
115
116
|
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
116
|
-
if (leveragedType ===
|
|
117
|
+
if (leveragedType === common_1.LeverageType.LsdLeverage) {
|
|
117
118
|
const ethAsset = Object.values(assetsData).find((asset) => ['WETH', 'ETH'].includes(asset.symbol));
|
|
118
119
|
if (ethAsset) {
|
|
119
120
|
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedVault.toLowerCase()].price).div(ethAsset.price).toString();
|
|
@@ -9,6 +9,7 @@ const tokens_1 = require("@defisaver/tokens");
|
|
|
9
9
|
const types_1 = require("../../types");
|
|
10
10
|
const moneymarket_1 = require("../../moneymarket");
|
|
11
11
|
const staking_1 = require("../../staking");
|
|
12
|
+
const common_1 = require("../../types/common");
|
|
12
13
|
const utils_1 = require("../../services/utils");
|
|
13
14
|
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }) => {
|
|
14
15
|
const { borrowRate, supplyRate, incentiveBorrowRate, incentiveSupplyRate, tradingBorrowRate, tradingSupplyRate, } = marketData;
|
|
@@ -55,7 +56,7 @@ const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, }, supplyS
|
|
|
55
56
|
if (leveragedType !== '') {
|
|
56
57
|
payload.leveragedAsset = leveragedAsset;
|
|
57
58
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
58
|
-
if (leveragedType ===
|
|
59
|
+
if (leveragedType === common_1.LeverageType.LsdLeverage) {
|
|
59
60
|
// Treat ETH like a stablecoin in a long stETH position
|
|
60
61
|
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
61
62
|
assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
|
|
@@ -51,7 +51,7 @@ const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, marketInf
|
|
|
51
51
|
if (leveragedType !== '') {
|
|
52
52
|
payload.leveragedAsset = leveragedAsset;
|
|
53
53
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
54
|
-
if (leveragedType ===
|
|
54
|
+
if (leveragedType === common_1.LeverageType.LsdLeverage) {
|
|
55
55
|
// Treat ETH like a stablecoin in a long stETH position
|
|
56
56
|
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
57
57
|
assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
|
|
@@ -92,7 +92,7 @@ const sparkGetAggregatedPositionData = (_a) => {
|
|
|
92
92
|
if (leveragedType !== '') {
|
|
93
93
|
payload.leveragedAsset = leveragedAsset;
|
|
94
94
|
let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
|
|
95
|
-
if (leveragedType ===
|
|
95
|
+
if (leveragedType === common_1.LeverageType.LsdLeverage) {
|
|
96
96
|
// Treat ETH like a stablecoin in a long stETH position
|
|
97
97
|
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
98
98
|
assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { MMUsedAssets } from '../types/common';
|
|
1
|
+
import { LeverageType, MMUsedAssets } from '../types/common';
|
|
2
2
|
export declare const getAssetsTotal: (assets: object, filter: any, transform: any) => any;
|
|
3
3
|
export declare const calcLongLiqPrice: (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
4
4
|
export declare const calcShortLiqPrice: (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
5
|
-
export declare const calcLeverageLiqPrice: (leverageType:
|
|
5
|
+
export declare const calcLeverageLiqPrice: (leverageType: LeverageType, assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
6
6
|
export declare const calculateBorrowingAssetLimit: (assetBorrowedUsd: string, borrowLimitUsd: string) => string;
|
|
7
7
|
export declare const STABLE_ASSETS: string[];
|
|
8
8
|
export declare const isLeveragedPos: (usedAssets: MMUsedAssets, dustLimit?: number) => {
|
|
9
|
-
leveragedType:
|
|
9
|
+
leveragedType: LeverageType;
|
|
10
10
|
leveragedAsset: string;
|
|
11
11
|
};
|
|
12
12
|
export declare const aprToApy: (interest: string | number, frequency?: number) => string;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.aprToApy = exports.isLeveragedPos = exports.STABLE_ASSETS = exports.calculateBorrowingAssetLimit = exports.calcLeverageLiqPrice = exports.calcShortLiqPrice = exports.calcLongLiqPrice = exports.getAssetsTotal = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const constants_1 = require("../constants");
|
|
9
|
+
const common_1 = require("../types/common");
|
|
9
10
|
const getAssetsTotal = (assets, filter, transform) => Object.values(assets)
|
|
10
11
|
.filter(filter)
|
|
11
12
|
.map(transform)
|
|
@@ -17,9 +18,9 @@ exports.calcLongLiqPrice = calcLongLiqPrice;
|
|
|
17
18
|
const calcShortLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => new decimal_js_1.default(assetPrice).div(borrowedUsd).mul(borrowLimitUsd).toString();
|
|
18
19
|
exports.calcShortLiqPrice = calcShortLiqPrice;
|
|
19
20
|
const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimitUsd) => {
|
|
20
|
-
if (leverageType ===
|
|
21
|
+
if (leverageType === common_1.LeverageType.Short || leverageType === common_1.LeverageType.VolatilePairReverse)
|
|
21
22
|
return (0, exports.calcShortLiqPrice)(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
22
|
-
if (leverageType ===
|
|
23
|
+
if (leverageType === common_1.LeverageType.Long || leverageType === common_1.LeverageType.LsdLeverage || leverageType === common_1.LeverageType.VolatilePair)
|
|
23
24
|
return (0, exports.calcLongLiqPrice)(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
24
25
|
console.error('invalid leverageType', leverageType);
|
|
25
26
|
return '0';
|
|
@@ -63,30 +64,30 @@ const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
63
64
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
64
65
|
if (isLong) {
|
|
65
66
|
return {
|
|
66
|
-
leveragedType:
|
|
67
|
+
leveragedType: common_1.LeverageType.Long,
|
|
67
68
|
leveragedAsset: longAsset,
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
if (isShort) {
|
|
71
72
|
return {
|
|
72
|
-
leveragedType:
|
|
73
|
+
leveragedType: common_1.LeverageType.Short,
|
|
73
74
|
leveragedAsset: shortAsset,
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
if (isLsdLeveraged) {
|
|
77
78
|
return {
|
|
78
|
-
leveragedType:
|
|
79
|
+
leveragedType: common_1.LeverageType.LsdLeverage,
|
|
79
80
|
leveragedAsset: longAsset,
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
if (isVolatilePair) {
|
|
83
84
|
return {
|
|
84
|
-
leveragedType:
|
|
85
|
+
leveragedType: common_1.LeverageType.VolatilePair,
|
|
85
86
|
leveragedAsset: longAsset,
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
89
|
return {
|
|
89
|
-
leveragedType:
|
|
90
|
+
leveragedType: common_1.LeverageType.None,
|
|
90
91
|
leveragedAsset: '',
|
|
91
92
|
};
|
|
92
93
|
};
|
package/cjs/types/aave.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IncentiveData, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
1
|
+
import { IncentiveData, LeverageType, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
2
|
export declare enum AaveVersions {
|
|
3
3
|
AaveV1 = "v1",
|
|
4
4
|
AaveV2 = "v2default",
|
|
@@ -161,7 +161,7 @@ export interface AaveV3AggregatedPositionData {
|
|
|
161
161
|
totalInterestUsd: string;
|
|
162
162
|
liqRatio: string;
|
|
163
163
|
liqPercent: string;
|
|
164
|
-
leveragedType:
|
|
164
|
+
leveragedType: LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
leveragedLsdAssetRatio?: string;
|
|
167
167
|
liquidationPrice?: string;
|
package/cjs/types/common.d.ts
CHANGED
|
@@ -8,6 +8,14 @@ export declare enum IncentiveEligibilityId {
|
|
|
8
8
|
AaveV3ArbitrumETHLSBorrow = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351",
|
|
9
9
|
AaveV3EthenaLiquidLeveragePlasma = "0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL"
|
|
10
10
|
}
|
|
11
|
+
export declare enum LeverageType {
|
|
12
|
+
Long = "long",
|
|
13
|
+
Short = "short",
|
|
14
|
+
LsdLeverage = "lsd-leverage",
|
|
15
|
+
VolatilePair = "volatile-pair",
|
|
16
|
+
VolatilePairReverse = "volatile-pair-reverse",
|
|
17
|
+
None = ""
|
|
18
|
+
}
|
|
11
19
|
export interface IncentiveData {
|
|
12
20
|
token: string;
|
|
13
21
|
apy: string;
|
package/cjs/types/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NetworkNumber = exports.IncentiveEligibilityId = exports.IncentiveKind = void 0;
|
|
3
|
+
exports.NetworkNumber = exports.LeverageType = exports.IncentiveEligibilityId = exports.IncentiveKind = void 0;
|
|
4
4
|
var IncentiveKind;
|
|
5
5
|
(function (IncentiveKind) {
|
|
6
6
|
IncentiveKind["Staking"] = "staking";
|
|
@@ -13,6 +13,15 @@ var IncentiveEligibilityId;
|
|
|
13
13
|
IncentiveEligibilityId["AaveV3ArbitrumETHLSBorrow"] = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351";
|
|
14
14
|
IncentiveEligibilityId["AaveV3EthenaLiquidLeveragePlasma"] = "0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL";
|
|
15
15
|
})(IncentiveEligibilityId || (exports.IncentiveEligibilityId = IncentiveEligibilityId = {}));
|
|
16
|
+
var LeverageType;
|
|
17
|
+
(function (LeverageType) {
|
|
18
|
+
LeverageType["Long"] = "long";
|
|
19
|
+
LeverageType["Short"] = "short";
|
|
20
|
+
LeverageType["LsdLeverage"] = "lsd-leverage";
|
|
21
|
+
LeverageType["VolatilePair"] = "volatile-pair";
|
|
22
|
+
LeverageType["VolatilePairReverse"] = "volatile-pair-reverse";
|
|
23
|
+
LeverageType["None"] = "";
|
|
24
|
+
})(LeverageType || (exports.LeverageType = LeverageType = {}));
|
|
16
25
|
var NetworkNumber;
|
|
17
26
|
(function (NetworkNumber) {
|
|
18
27
|
NetworkNumber[NetworkNumber["Eth"] = 1] = "Eth";
|
package/cjs/types/compound.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, LeverageType, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
2
|
export declare enum CompoundVersions {
|
|
3
3
|
'CompoundV2' = "v2",
|
|
4
4
|
'CompoundV3USDC' = "v3-USDC",
|
|
@@ -94,7 +94,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
94
94
|
totalInterestUsd: string;
|
|
95
95
|
liqRatio: string;
|
|
96
96
|
liqPercent: string;
|
|
97
|
-
leveragedType:
|
|
97
|
+
leveragedType: LeverageType;
|
|
98
98
|
leveragedAsset?: string;
|
|
99
99
|
leveragedLsdAssetRatio?: string;
|
|
100
100
|
liquidationPrice?: string;
|
package/cjs/types/curveUsd.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
export declare enum CrvUSDVersions {
|
|
3
3
|
'crvUSDwstETH' = "wstETH",
|
|
4
4
|
'crvUSDWBTC' = "WBTC",
|
|
@@ -71,7 +71,7 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
71
71
|
borrowLimitUsd: string;
|
|
72
72
|
minAllowedRatio: number;
|
|
73
73
|
collFactor: string;
|
|
74
|
-
leveragedType:
|
|
74
|
+
leveragedType: LeverageType;
|
|
75
75
|
leveragedAsset?: string;
|
|
76
76
|
liquidationPrice?: string;
|
|
77
77
|
}
|
package/cjs/types/euler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, MMPositionData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, MMPositionData, NetworkNumber } from './common';
|
|
2
2
|
export declare enum EulerV2Versions {
|
|
3
3
|
eUSDC2 = "eUSDC-2",
|
|
4
4
|
eWETH2 = "eWETH-2"
|
|
@@ -141,7 +141,7 @@ export interface EulerV2AggregatedPositionData {
|
|
|
141
141
|
totalInterestUsd: string;
|
|
142
142
|
liqRatio: string;
|
|
143
143
|
liqPercent: string;
|
|
144
|
-
leveragedType:
|
|
144
|
+
leveragedType: LeverageType;
|
|
145
145
|
leveragedAsset?: string;
|
|
146
146
|
leveragedLsdAssetRatio?: string;
|
|
147
147
|
liquidationPrice?: string;
|
package/cjs/types/fluid.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
export interface FluidMarketInfo {
|
|
3
3
|
chainIds: number[];
|
|
4
4
|
label: string;
|
|
@@ -323,7 +323,7 @@ export interface FluidAggregatedVaultData {
|
|
|
323
323
|
collRatio: string;
|
|
324
324
|
minRatio: string;
|
|
325
325
|
totalInterestUsd: string;
|
|
326
|
-
leveragedType?:
|
|
326
|
+
leveragedType?: LeverageType;
|
|
327
327
|
leveragedAsset?: string;
|
|
328
328
|
liquidationPrice?: string;
|
|
329
329
|
leveragedLsdAssetRatio?: string;
|
package/cjs/types/liquityV2.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
export declare enum LiquityV2Versions {
|
|
3
3
|
LiquityV2Eth = "liquityv2eth",
|
|
4
4
|
LiquityV2WstEth = "liquityv2wsteth",
|
|
@@ -88,7 +88,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
88
88
|
netApy: string;
|
|
89
89
|
incentiveUsd: string;
|
|
90
90
|
totalInterestUsd: string;
|
|
91
|
-
leveragedType:
|
|
91
|
+
leveragedType: LeverageType;
|
|
92
92
|
leveragedAsset: string;
|
|
93
93
|
liquidationPrice: string;
|
|
94
94
|
ratio: string;
|
|
@@ -110,7 +110,7 @@ export interface LiquityV2TroveData {
|
|
|
110
110
|
totalInterestUsd: string;
|
|
111
111
|
interestBatchManager: EthAddress;
|
|
112
112
|
troveStatus: string;
|
|
113
|
-
leveragedType:
|
|
113
|
+
leveragedType: LeverageType;
|
|
114
114
|
leveragedAsset: string;
|
|
115
115
|
liquidationPrice: string;
|
|
116
116
|
debtInFront: string;
|
package/cjs/types/llamaLend.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
import { BandData, UserBandData } from './curveUsd';
|
|
3
3
|
export declare enum LLVersionsEth {
|
|
4
4
|
LLWstethCrvusd = "llamaLendwstETHcrvUSD",
|
|
@@ -112,7 +112,7 @@ export interface LlamaLendAggregatedPositionData {
|
|
|
112
112
|
borrowLimitUsd: string;
|
|
113
113
|
minAllowedRatio: number;
|
|
114
114
|
collFactor: string;
|
|
115
|
-
leveragedType:
|
|
115
|
+
leveragedType: LeverageType;
|
|
116
116
|
leveragedAsset?: string;
|
|
117
117
|
liquidationPrice?: string;
|
|
118
118
|
netApy: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, MMUsedAssets, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, MMUsedAssets, NetworkNumber } from './common';
|
|
2
2
|
export declare enum MorphoBlueVersions {
|
|
3
3
|
MorphoBlueWstEthUSDC = "morphobluewstethusdc",// wstETH/USDC
|
|
4
4
|
MorphoBlueSDAIUSDC = "morphobluesdaiusdc",// sDAI/USDC
|
|
@@ -121,7 +121,7 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
121
121
|
totalInterestUsd: string;
|
|
122
122
|
ltv: string;
|
|
123
123
|
ratio: string;
|
|
124
|
-
leveragedType:
|
|
124
|
+
leveragedType: LeverageType;
|
|
125
125
|
leveragedAsset?: string;
|
|
126
126
|
leveragedLsdAssetRatio?: string;
|
|
127
127
|
liquidationPrice?: string;
|
|
@@ -142,7 +142,7 @@ export interface MorphoBluePositionData {
|
|
|
142
142
|
totalInterestUsd: string;
|
|
143
143
|
ltv: string;
|
|
144
144
|
ratio: string;
|
|
145
|
-
leveragedType:
|
|
145
|
+
leveragedType: LeverageType;
|
|
146
146
|
leveragedAsset?: string;
|
|
147
147
|
leveragedLsdAssetRatio?: string;
|
|
148
148
|
liquidationPrice?: string;
|
package/cjs/types/spark.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EModeCategoriesData } from './aave';
|
|
2
|
-
import { EthAddress, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
|
+
import { EthAddress, LeverageType, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
3
3
|
export declare enum SparkVersions {
|
|
4
4
|
SparkV1 = "v1default"
|
|
5
5
|
}
|
|
@@ -90,7 +90,7 @@ export interface SparkAggregatedPositionData {
|
|
|
90
90
|
totalInterestUsd: string;
|
|
91
91
|
liqRatio: string;
|
|
92
92
|
liqPercent: string;
|
|
93
|
-
leveragedType:
|
|
93
|
+
leveragedType: LeverageType;
|
|
94
94
|
leveragedAsset?: string;
|
|
95
95
|
leveragedLsdAssetRatio?: string;
|
|
96
96
|
liquidationPrice?: string;
|
package/esm/fluid/index.d.ts
CHANGED
|
@@ -130,7 +130,7 @@ export declare const _getUserPositions: (provider: PublicClient, network: Networ
|
|
|
130
130
|
collRatio: string;
|
|
131
131
|
minRatio: string;
|
|
132
132
|
totalInterestUsd: string;
|
|
133
|
-
leveragedType?:
|
|
133
|
+
leveragedType?: import("../types/common").LeverageType;
|
|
134
134
|
leveragedAsset?: string;
|
|
135
135
|
liquidationPrice?: string;
|
|
136
136
|
leveragedLsdAssetRatio?: string;
|
|
@@ -161,7 +161,7 @@ export declare const getUserPositions: (provider: EthereumProvider, network: Net
|
|
|
161
161
|
collRatio: string;
|
|
162
162
|
minRatio: string;
|
|
163
163
|
totalInterestUsd: string;
|
|
164
|
-
leveragedType?:
|
|
164
|
+
leveragedType?: import("../types/common").LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
liquidationPrice?: string;
|
|
167
167
|
leveragedLsdAssetRatio?: string;
|
|
@@ -192,7 +192,7 @@ export declare const _getUserPositionsPortfolio: (provider: PublicClient, networ
|
|
|
192
192
|
collRatio: string;
|
|
193
193
|
minRatio: string;
|
|
194
194
|
totalInterestUsd: string;
|
|
195
|
-
leveragedType?:
|
|
195
|
+
leveragedType?: import("../types/common").LeverageType;
|
|
196
196
|
leveragedAsset?: string;
|
|
197
197
|
liquidationPrice?: string;
|
|
198
198
|
leveragedLsdAssetRatio?: string;
|
|
@@ -25,6 +25,7 @@ import { getNativeAssetFromWrapped, getWrappedNativeAssetFromUnwrapped } from '.
|
|
|
25
25
|
import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
26
26
|
import { calculateNetApy } from '../../staking';
|
|
27
27
|
import { borrowOperations } from '../../constants';
|
|
28
|
+
import { LeverageType, } from '../../types/common';
|
|
28
29
|
import { AaveLoanInfoV2ContractViem, AaveV3ViewContractViem } from '../../contracts';
|
|
29
30
|
import { getViemProvider } from '../../services/viem';
|
|
30
31
|
export const AAVE_V3_MARKETS = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi];
|
|
@@ -89,18 +90,27 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
89
90
|
payload.liquidationPrice = '';
|
|
90
91
|
if (leveragedType !== '') {
|
|
91
92
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
92
|
-
if (leveragedType ===
|
|
93
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
93
94
|
// Treat ETH like a stablecoin in a long stETH position
|
|
94
95
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
95
96
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
96
97
|
}
|
|
97
|
-
if (leveragedType ===
|
|
98
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
98
99
|
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
99
100
|
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
102
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
103
|
+
if (isReverse) {
|
|
104
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
105
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
106
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
110
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
113
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
104
114
|
}
|
|
105
115
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
106
116
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -25,7 +25,7 @@ import { addToArrayIf, getEthAmountForDecimals, handleWbtcLegacy, wethToEth, } f
|
|
|
25
25
|
import { BLOCKS_IN_A_YEAR, borrowOperations, SECONDS_PER_YEAR } from '../../constants';
|
|
26
26
|
import { aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
27
27
|
import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../../staking';
|
|
28
|
-
import { IncentiveKind, NetworkNumber, } from '../../types/common';
|
|
28
|
+
import { IncentiveKind, LeverageType, NetworkNumber, } from '../../types/common';
|
|
29
29
|
import { CompoundLoanInfoContractViem, CompV3ViewContractViem } from '../../contracts';
|
|
30
30
|
import { getViemProvider } from '../../services/viem';
|
|
31
31
|
export const formatMarketData = (data, network, baseAssetPrice) => {
|
|
@@ -140,7 +140,7 @@ export const getCompoundV3AggregatedData = (_a) => {
|
|
|
140
140
|
if (leveragedType !== '') {
|
|
141
141
|
payload.leveragedAsset = leveragedAsset;
|
|
142
142
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
143
|
-
if (leveragedType ===
|
|
143
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
144
144
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toString();
|
|
145
145
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
146
146
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
1
|
+
import { EthAddress, EthereumProvider, LeverageType, NetworkNumber } from '../../types/common';
|
|
2
2
|
import { EulerV2AggregatedPositionData, EulerV2AssetsData, EulerV2UsedAssets } from '../../types';
|
|
3
3
|
export declare const isLeveragedPos: (usedAssets: EulerV2UsedAssets, dustLimit?: number) => {
|
|
4
|
-
leveragedType:
|
|
4
|
+
leveragedType: LeverageType;
|
|
5
5
|
leveragedAsset: string;
|
|
6
6
|
leveragedVault: string;
|
|
7
7
|
};
|
|
@@ -20,6 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
};
|
|
21
21
|
import Dec from 'decimal.js';
|
|
22
22
|
import { assetAmountInWei } from '@defisaver/tokens';
|
|
23
|
+
import { LeverageType, } from '../../types/common';
|
|
23
24
|
import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
|
|
24
25
|
import { calculateNetApy } from '../../staking';
|
|
25
26
|
import { EulerV2ViewContractViem } from '../../contracts';
|
|
@@ -57,27 +58,27 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
57
58
|
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
58
59
|
if (isLong) {
|
|
59
60
|
return {
|
|
60
|
-
leveragedType:
|
|
61
|
+
leveragedType: LeverageType.Long,
|
|
61
62
|
leveragedAsset: longAsset,
|
|
62
63
|
leveragedVault: leverageAssetVault,
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
if (isShort) {
|
|
66
67
|
return {
|
|
67
|
-
leveragedType:
|
|
68
|
+
leveragedType: LeverageType.Short,
|
|
68
69
|
leveragedAsset: shortAsset,
|
|
69
70
|
leveragedVault: leverageAssetVault,
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
if (isLsdLeveraged) {
|
|
73
74
|
return {
|
|
74
|
-
leveragedType:
|
|
75
|
+
leveragedType: LeverageType.LsdLeverage,
|
|
75
76
|
leveragedAsset: longAsset,
|
|
76
77
|
leveragedVault: leverageAssetVault,
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
return {
|
|
80
|
-
leveragedType:
|
|
81
|
+
leveragedType: LeverageType.None,
|
|
81
82
|
leveragedAsset: '',
|
|
82
83
|
leveragedVault: '',
|
|
83
84
|
};
|
|
@@ -106,7 +107,7 @@ export const getEulerV2AggregatedData = (_a) => {
|
|
|
106
107
|
if (leveragedType !== '') {
|
|
107
108
|
payload.leveragedAsset = leveragedAsset;
|
|
108
109
|
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
109
|
-
if (leveragedType ===
|
|
110
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
110
111
|
const ethAsset = Object.values(assetsData).find((asset) => ['WETH', 'ETH'].includes(asset.symbol));
|
|
111
112
|
if (ethAsset) {
|
|
112
113
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedVault.toLowerCase()].price).div(ethAsset.price).toString();
|
|
@@ -3,6 +3,7 @@ import { assetAmountInEth } from '@defisaver/tokens';
|
|
|
3
3
|
import { FluidVaultType, } from '../../types';
|
|
4
4
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
5
5
|
import { calculateNetApy } from '../../staking';
|
|
6
|
+
import { LeverageType } from '../../types/common';
|
|
6
7
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
7
8
|
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }) => {
|
|
8
9
|
const { borrowRate, supplyRate, incentiveBorrowRate, incentiveSupplyRate, tradingBorrowRate, tradingSupplyRate, } = marketData;
|
|
@@ -49,7 +50,7 @@ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, },
|
|
|
49
50
|
if (leveragedType !== '') {
|
|
50
51
|
payload.leveragedAsset = leveragedAsset;
|
|
51
52
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
52
|
-
if (leveragedType ===
|
|
53
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
53
54
|
// Treat ETH like a stablecoin in a long stETH position
|
|
54
55
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
55
56
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|