@defisaver/positions-sdk 2.1.52-dev-2 → 2.1.52-dev-3
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 +0 -5
- package/cjs/helpers/compoundHelpers/index.js +15 -18
- package/cjs/helpers/eulerHelpers/index.js +17 -10
- package/cjs/helpers/fluidHelpers/index.js +15 -5
- package/cjs/helpers/morphoBlueHelpers/index.js +15 -5
- package/cjs/helpers/sparkHelpers/index.d.ts +2 -2
- package/cjs/helpers/sparkHelpers/index.js +15 -5
- package/cjs/moneymarket/moneymarketCommonService.js +1 -9
- package/cjs/types/aave.d.ts +0 -1
- package/cjs/types/common.d.ts +0 -1
- package/cjs/types/common.js +0 -1
- package/cjs/types/compound.d.ts +1 -1
- package/cjs/types/euler.d.ts +1 -1
- package/cjs/types/fluid.d.ts +1 -1
- package/cjs/types/morphoBlue.d.ts +2 -2
- package/cjs/types/spark.d.ts +1 -1
- package/esm/fluid/index.d.ts +3 -3
- package/esm/helpers/aaveHelpers/index.js +0 -5
- package/esm/helpers/compoundHelpers/index.js +15 -18
- package/esm/helpers/eulerHelpers/index.js +17 -10
- package/esm/helpers/fluidHelpers/index.js +15 -5
- package/esm/helpers/morphoBlueHelpers/index.js +15 -5
- package/esm/helpers/sparkHelpers/index.d.ts +2 -2
- package/esm/helpers/sparkHelpers/index.js +15 -5
- package/esm/moneymarket/moneymarketCommonService.js +1 -9
- package/esm/types/aave.d.ts +0 -1
- package/esm/types/common.d.ts +0 -1
- package/esm/types/common.js +0 -1
- package/esm/types/compound.d.ts +1 -1
- package/esm/types/euler.d.ts +1 -1
- package/esm/types/fluid.d.ts +1 -1
- package/esm/types/morphoBlue.d.ts +2 -2
- package/esm/types/spark.d.ts +1 -1
- package/package.json +1 -1
- package/src/helpers/aaveHelpers/index.ts +0 -5
- package/src/helpers/compoundHelpers/index.ts +15 -22
- package/src/helpers/eulerHelpers/index.ts +17 -10
- package/src/helpers/fluidHelpers/index.ts +14 -5
- package/src/helpers/morphoBlueHelpers/index.ts +15 -6
- package/src/helpers/sparkHelpers/index.ts +15 -6
- package/src/moneymarket/moneymarketCommonService.ts +1 -9
- package/src/types/aave.ts +0 -1
- package/src/types/common.ts +0 -1
- package/src/types/compound.ts +1 -1
- package/src/types/euler.ts +1 -1
- package/src/types/fluid.ts +1 -1
- package/src/types/morphoBlue.ts +2 -2
- package/src/types/spark.ts +1 -1
package/cjs/fluid/index.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ export declare const _getUserPositions: (provider: PublicClient, network: Networ
|
|
|
133
133
|
leveragedType?: import("../types/common").LeverageType;
|
|
134
134
|
leveragedAsset?: string;
|
|
135
135
|
liquidationPrice?: string;
|
|
136
|
-
|
|
136
|
+
currentVolatilePairRatio?: string;
|
|
137
137
|
minCollRatio?: string;
|
|
138
138
|
collLiquidationRatio?: string;
|
|
139
139
|
owner: string;
|
|
@@ -164,7 +164,7 @@ export declare const getUserPositions: (provider: EthereumProvider, network: Net
|
|
|
164
164
|
leveragedType?: import("../types/common").LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
liquidationPrice?: string;
|
|
167
|
-
|
|
167
|
+
currentVolatilePairRatio?: string;
|
|
168
168
|
minCollRatio?: string;
|
|
169
169
|
collLiquidationRatio?: string;
|
|
170
170
|
owner: string;
|
|
@@ -195,7 +195,7 @@ export declare const _getUserPositionsPortfolio: (provider: PublicClient, networ
|
|
|
195
195
|
leveragedType?: import("../types/common").LeverageType;
|
|
196
196
|
leveragedAsset?: string;
|
|
197
197
|
liquidationPrice?: string;
|
|
198
|
-
|
|
198
|
+
currentVolatilePairRatio?: string;
|
|
199
199
|
minCollRatio?: string;
|
|
200
200
|
collLiquidationRatio?: string;
|
|
201
201
|
owner: string;
|
|
@@ -104,11 +104,6 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
104
104
|
payload.liquidationPrice = '';
|
|
105
105
|
if (leveragedType !== '') {
|
|
106
106
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
107
|
-
if (leveragedType === common_1.LeverageType.LsdLeverage) {
|
|
108
|
-
// Treat ETH like a stablecoin in a long stETH position
|
|
109
|
-
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
110
|
-
assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
|
|
111
|
-
}
|
|
112
107
|
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
113
108
|
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
114
109
|
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
@@ -150,28 +150,25 @@ const getCompoundV3AggregatedData = (_a) => {
|
|
|
150
150
|
if (leveragedType !== '') {
|
|
151
151
|
payload.leveragedAsset = leveragedAsset;
|
|
152
152
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
153
|
-
if (leveragedType === common_1.LeverageType.
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
154
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
155
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
156
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
157
|
+
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
158
|
+
if (isReverse) {
|
|
159
|
+
payload.leveragedType = common_1.LeverageType.VolatilePairReverse;
|
|
160
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
161
|
+
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(borrowedAssetPrice).toString();
|
|
165
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
166
|
+
}
|
|
156
167
|
}
|
|
157
|
-
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
168
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
158
169
|
}
|
|
159
170
|
payload.minCollRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
160
171
|
payload.collLiquidationRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
161
|
-
// TO DO: handle strategies
|
|
162
|
-
/* const subscribedStrategies = rest.compoundStrategies
|
|
163
|
-
? compoundV3GetSubscribedStrategies({ selectedMarket, compoundStrategies: rest.compoundStrategies })
|
|
164
|
-
: []; */
|
|
165
|
-
// TODO possibly move to global helper, since every protocol has the same graphData?
|
|
166
|
-
// payload.ratioTooLow = false;
|
|
167
|
-
// payload.ratioTooHigh = false;
|
|
168
|
-
// TO DO: handle strategies
|
|
169
|
-
/* if (subscribedStrategies.length) {
|
|
170
|
-
subscribedStrategies.forEach(({ graphData }) => {
|
|
171
|
-
payload.ratioTooLow = parseFloat(payload.ratio) < parseFloat(graphData.minRatio);
|
|
172
|
-
payload.ratioTooHigh = graphData.boostEnabled && parseFloat(payload.ratio) > parseFloat(graphData.maxRatio);
|
|
173
|
-
});
|
|
174
|
-
} */
|
|
175
172
|
return payload;
|
|
176
173
|
};
|
|
177
174
|
exports.getCompoundV3AggregatedData = getCompoundV3AggregatedData;
|
|
@@ -60,8 +60,7 @@ const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
60
60
|
});
|
|
61
61
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
62
62
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
63
|
-
|
|
64
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
63
|
+
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
65
64
|
if (isLong) {
|
|
66
65
|
return {
|
|
67
66
|
leveragedType: common_1.LeverageType.Long,
|
|
@@ -76,9 +75,9 @@ const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
76
75
|
leveragedVault: leverageAssetVault,
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
|
-
if (
|
|
78
|
+
if (isVolatilePair) {
|
|
80
79
|
return {
|
|
81
|
-
leveragedType: common_1.LeverageType.
|
|
80
|
+
leveragedType: common_1.LeverageType.VolatilePair,
|
|
82
81
|
leveragedAsset: longAsset,
|
|
83
82
|
leveragedVault: leverageAssetVault,
|
|
84
83
|
};
|
|
@@ -114,14 +113,22 @@ const getEulerV2AggregatedData = (_a) => {
|
|
|
114
113
|
if (leveragedType !== '') {
|
|
115
114
|
payload.leveragedAsset = leveragedAsset;
|
|
116
115
|
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
117
|
-
if (leveragedType === common_1.LeverageType.
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
117
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
118
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.vaultAddress.toLowerCase()].price;
|
|
119
|
+
const leveragedAssetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
120
|
+
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
121
|
+
if (isReverse) {
|
|
122
|
+
payload.leveragedType = common_1.LeverageType.VolatilePairReverse;
|
|
123
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
124
|
+
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(borrowedAssetPrice).toString();
|
|
128
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
122
129
|
}
|
|
123
130
|
}
|
|
124
|
-
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
131
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
125
132
|
}
|
|
126
133
|
payload.minCollRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
127
134
|
payload.collLiquidationRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -56,12 +56,22 @@ const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, }, supplyS
|
|
|
56
56
|
if (leveragedType !== '') {
|
|
57
57
|
payload.leveragedAsset = leveragedAsset;
|
|
58
58
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
59
|
-
if (leveragedType === common_1.LeverageType.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
60
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
61
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
62
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
63
|
+
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
64
|
+
if (isReverse) {
|
|
65
|
+
payload.leveragedType = common_1.LeverageType.VolatilePairReverse;
|
|
66
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
67
|
+
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(borrowedAssetPrice).toString();
|
|
71
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
72
|
+
}
|
|
63
73
|
}
|
|
64
|
-
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
74
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
65
75
|
}
|
|
66
76
|
payload.minCollRatio = new decimal_js_1.default(payload.suppliedUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
67
77
|
payload.collLiquidationRatio = new decimal_js_1.default(payload.suppliedUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -51,12 +51,22 @@ const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, marketInf
|
|
|
51
51
|
if (leveragedType !== '') {
|
|
52
52
|
payload.leveragedAsset = leveragedAsset;
|
|
53
53
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
54
|
-
if (leveragedType === common_1.LeverageType.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
55
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
56
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
57
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
58
|
+
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
59
|
+
if (isReverse) {
|
|
60
|
+
payload.leveragedType = common_1.LeverageType.VolatilePairReverse;
|
|
61
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
62
|
+
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(borrowedAssetPrice).toString();
|
|
66
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
67
|
+
}
|
|
58
68
|
}
|
|
59
|
-
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
69
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
60
70
|
}
|
|
61
71
|
payload.minCollRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
62
72
|
payload.collLiquidationRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAssets } from '../../types';
|
|
1
|
+
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAsset, SparkUsedAssets } from '../../types';
|
|
2
2
|
import { EthereumProvider } from '../../types/common';
|
|
3
3
|
export declare const sparkIsInIsolationMode: ({ usedAssets, assetsData }: {
|
|
4
4
|
usedAssets: SparkUsedAssets;
|
|
@@ -6,7 +6,7 @@ export declare const sparkIsInIsolationMode: ({ usedAssets, assetsData }: {
|
|
|
6
6
|
}) => boolean;
|
|
7
7
|
export declare const sparkGetCollSuppliedAssets: ({ usedAssets }: {
|
|
8
8
|
usedAssets: SparkUsedAssets;
|
|
9
|
-
}) =>
|
|
9
|
+
}) => SparkUsedAsset[];
|
|
10
10
|
export declare const sparkGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: SparkHelperCommon) => {
|
|
11
11
|
symbol: string;
|
|
12
12
|
canBeCollateral: boolean;
|
|
@@ -92,12 +92,22 @@ 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 === common_1.LeverageType.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if (leveragedType === common_1.LeverageType.VolatilePair) {
|
|
96
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
97
|
+
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
98
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
99
|
+
const isReverse = new decimal_js_1.default(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
100
|
+
if (isReverse) {
|
|
101
|
+
payload.leveragedType = common_1.LeverageType.VolatilePairReverse;
|
|
102
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
103
|
+
assetPrice = new decimal_js_1.default(borrowedAssetPrice).div(assetPrice).toString();
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(borrowedAssetPrice).toString();
|
|
107
|
+
payload.currentVolatilePairRatio = new decimal_js_1.default(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
108
|
+
}
|
|
99
109
|
}
|
|
100
|
-
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
110
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
101
111
|
}
|
|
102
112
|
payload.minCollRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
103
113
|
payload.collLiquidationRatio = new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -20,7 +20,7 @@ exports.calcShortLiqPrice = calcShortLiqPrice;
|
|
|
20
20
|
const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimitUsd) => {
|
|
21
21
|
if (leverageType === common_1.LeverageType.Short || leverageType === common_1.LeverageType.VolatilePairReverse)
|
|
22
22
|
return (0, exports.calcShortLiqPrice)(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
23
|
-
if (leverageType === common_1.LeverageType.Long || leverageType === common_1.LeverageType.
|
|
23
|
+
if (leverageType === common_1.LeverageType.Long || leverageType === common_1.LeverageType.VolatilePair)
|
|
24
24
|
return (0, exports.calcLongLiqPrice)(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
25
25
|
console.error('invalid leverageType', leverageType);
|
|
26
26
|
return '0';
|
|
@@ -59,8 +59,6 @@ const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
59
59
|
});
|
|
60
60
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
61
61
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
62
|
-
// lsd -> liquid staking derivative
|
|
63
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH', 'ezETH', 'weETH'].includes(longAsset);
|
|
64
62
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
65
63
|
if (isLong) {
|
|
66
64
|
return {
|
|
@@ -74,12 +72,6 @@ const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
74
72
|
leveragedAsset: shortAsset,
|
|
75
73
|
};
|
|
76
74
|
}
|
|
77
|
-
if (isLsdLeveraged) {
|
|
78
|
-
return {
|
|
79
|
-
leveragedType: common_1.LeverageType.LsdLeverage,
|
|
80
|
-
leveragedAsset: longAsset,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
75
|
if (isVolatilePair) {
|
|
84
76
|
return {
|
|
85
77
|
leveragedType: common_1.LeverageType.VolatilePair,
|
package/cjs/types/aave.d.ts
CHANGED
|
@@ -163,7 +163,6 @@ export interface AaveV3AggregatedPositionData {
|
|
|
163
163
|
liqPercent: string;
|
|
164
164
|
leveragedType: LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
|
-
leveragedLsdAssetRatio?: string;
|
|
167
166
|
liquidationPrice?: string;
|
|
168
167
|
minCollRatio?: string;
|
|
169
168
|
collLiquidationRatio?: string;
|
package/cjs/types/common.d.ts
CHANGED
package/cjs/types/common.js
CHANGED
|
@@ -17,7 +17,6 @@ var LeverageType;
|
|
|
17
17
|
(function (LeverageType) {
|
|
18
18
|
LeverageType["Long"] = "long";
|
|
19
19
|
LeverageType["Short"] = "short";
|
|
20
|
-
LeverageType["LsdLeverage"] = "lsd-leverage";
|
|
21
20
|
LeverageType["VolatilePair"] = "volatile-pair";
|
|
22
21
|
LeverageType["VolatilePairReverse"] = "volatile-pair-reverse";
|
|
23
22
|
LeverageType["None"] = "";
|
package/cjs/types/compound.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
96
96
|
liqPercent: string;
|
|
97
97
|
leveragedType: LeverageType;
|
|
98
98
|
leveragedAsset?: string;
|
|
99
|
-
|
|
99
|
+
currentVolatilePairRatio?: string;
|
|
100
100
|
liquidationPrice?: string;
|
|
101
101
|
minRatio: string;
|
|
102
102
|
debtTooLow: boolean;
|
package/cjs/types/euler.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ export interface EulerV2AggregatedPositionData {
|
|
|
143
143
|
liqPercent: string;
|
|
144
144
|
leveragedType: LeverageType;
|
|
145
145
|
leveragedAsset?: string;
|
|
146
|
-
|
|
146
|
+
currentVolatilePairRatio?: string;
|
|
147
147
|
liquidationPrice?: string;
|
|
148
148
|
minRatio: string;
|
|
149
149
|
minDebt: string;
|
package/cjs/types/fluid.d.ts
CHANGED
|
@@ -326,7 +326,7 @@ export interface FluidAggregatedVaultData {
|
|
|
326
326
|
leveragedType?: LeverageType;
|
|
327
327
|
leveragedAsset?: string;
|
|
328
328
|
liquidationPrice?: string;
|
|
329
|
-
|
|
329
|
+
currentVolatilePairRatio?: string;
|
|
330
330
|
minCollRatio?: string;
|
|
331
331
|
collLiquidationRatio?: string;
|
|
332
332
|
}
|
|
@@ -123,7 +123,7 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
123
123
|
ratio: string;
|
|
124
124
|
leveragedType: LeverageType;
|
|
125
125
|
leveragedAsset?: string;
|
|
126
|
-
|
|
126
|
+
currentVolatilePairRatio?: string;
|
|
127
127
|
liquidationPrice?: string;
|
|
128
128
|
minCollRatio?: string;
|
|
129
129
|
collLiquidationRatio?: string;
|
|
@@ -144,7 +144,7 @@ export interface MorphoBluePositionData {
|
|
|
144
144
|
ratio: string;
|
|
145
145
|
leveragedType: LeverageType;
|
|
146
146
|
leveragedAsset?: string;
|
|
147
|
-
|
|
147
|
+
currentVolatilePairRatio?: string;
|
|
148
148
|
liquidationPrice?: string;
|
|
149
149
|
supplyShares: string;
|
|
150
150
|
borrowShares: string;
|
package/cjs/types/spark.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ export interface SparkAggregatedPositionData {
|
|
|
92
92
|
liqPercent: string;
|
|
93
93
|
leveragedType: LeverageType;
|
|
94
94
|
leveragedAsset?: string;
|
|
95
|
-
|
|
95
|
+
currentVolatilePairRatio?: string;
|
|
96
96
|
liquidationPrice?: string;
|
|
97
97
|
minCollRatio: string;
|
|
98
98
|
collLiquidationRatio: string;
|
package/esm/fluid/index.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ export declare const _getUserPositions: (provider: PublicClient, network: Networ
|
|
|
133
133
|
leveragedType?: import("../types/common").LeverageType;
|
|
134
134
|
leveragedAsset?: string;
|
|
135
135
|
liquidationPrice?: string;
|
|
136
|
-
|
|
136
|
+
currentVolatilePairRatio?: string;
|
|
137
137
|
minCollRatio?: string;
|
|
138
138
|
collLiquidationRatio?: string;
|
|
139
139
|
owner: string;
|
|
@@ -164,7 +164,7 @@ export declare const getUserPositions: (provider: EthereumProvider, network: Net
|
|
|
164
164
|
leveragedType?: import("../types/common").LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
liquidationPrice?: string;
|
|
167
|
-
|
|
167
|
+
currentVolatilePairRatio?: string;
|
|
168
168
|
minCollRatio?: string;
|
|
169
169
|
collLiquidationRatio?: string;
|
|
170
170
|
owner: string;
|
|
@@ -195,7 +195,7 @@ export declare const _getUserPositionsPortfolio: (provider: PublicClient, networ
|
|
|
195
195
|
leveragedType?: import("../types/common").LeverageType;
|
|
196
196
|
leveragedAsset?: string;
|
|
197
197
|
liquidationPrice?: string;
|
|
198
|
-
|
|
198
|
+
currentVolatilePairRatio?: string;
|
|
199
199
|
minCollRatio?: string;
|
|
200
200
|
collLiquidationRatio?: string;
|
|
201
201
|
owner: string;
|
|
@@ -90,11 +90,6 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
90
90
|
payload.liquidationPrice = '';
|
|
91
91
|
if (leveragedType !== '') {
|
|
92
92
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
93
|
-
if (leveragedType === LeverageType.LsdLeverage) {
|
|
94
|
-
// Treat ETH like a stablecoin in a long stETH position
|
|
95
|
-
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
96
|
-
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
97
|
-
}
|
|
98
93
|
if (leveragedType === LeverageType.VolatilePair) {
|
|
99
94
|
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
100
95
|
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
@@ -140,28 +140,25 @@ export const getCompoundV3AggregatedData = (_a) => {
|
|
|
140
140
|
if (leveragedType !== '') {
|
|
141
141
|
payload.leveragedAsset = leveragedAsset;
|
|
142
142
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
143
|
-
if (leveragedType === LeverageType.
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
144
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
145
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
146
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
147
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
148
|
+
if (isReverse) {
|
|
149
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
150
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
151
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
155
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
156
|
+
}
|
|
146
157
|
}
|
|
147
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
158
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
148
159
|
}
|
|
149
160
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
150
161
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
151
|
-
// TO DO: handle strategies
|
|
152
|
-
/* const subscribedStrategies = rest.compoundStrategies
|
|
153
|
-
? compoundV3GetSubscribedStrategies({ selectedMarket, compoundStrategies: rest.compoundStrategies })
|
|
154
|
-
: []; */
|
|
155
|
-
// TODO possibly move to global helper, since every protocol has the same graphData?
|
|
156
|
-
// payload.ratioTooLow = false;
|
|
157
|
-
// payload.ratioTooHigh = false;
|
|
158
|
-
// TO DO: handle strategies
|
|
159
|
-
/* if (subscribedStrategies.length) {
|
|
160
|
-
subscribedStrategies.forEach(({ graphData }) => {
|
|
161
|
-
payload.ratioTooLow = parseFloat(payload.ratio) < parseFloat(graphData.minRatio);
|
|
162
|
-
payload.ratioTooHigh = graphData.boostEnabled && parseFloat(payload.ratio) > parseFloat(graphData.maxRatio);
|
|
163
|
-
});
|
|
164
|
-
} */
|
|
165
162
|
return payload;
|
|
166
163
|
};
|
|
167
164
|
export const getApyAfterValuesEstimationCompoundV2 = (actions, provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -54,8 +54,7 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
54
54
|
});
|
|
55
55
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
56
56
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
57
|
-
|
|
58
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
57
|
+
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
59
58
|
if (isLong) {
|
|
60
59
|
return {
|
|
61
60
|
leveragedType: LeverageType.Long,
|
|
@@ -70,9 +69,9 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
70
69
|
leveragedVault: leverageAssetVault,
|
|
71
70
|
};
|
|
72
71
|
}
|
|
73
|
-
if (
|
|
72
|
+
if (isVolatilePair) {
|
|
74
73
|
return {
|
|
75
|
-
leveragedType: LeverageType.
|
|
74
|
+
leveragedType: LeverageType.VolatilePair,
|
|
76
75
|
leveragedAsset: longAsset,
|
|
77
76
|
leveragedVault: leverageAssetVault,
|
|
78
77
|
};
|
|
@@ -107,14 +106,22 @@ export const getEulerV2AggregatedData = (_a) => {
|
|
|
107
106
|
if (leveragedType !== '') {
|
|
108
107
|
payload.leveragedAsset = leveragedAsset;
|
|
109
108
|
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
110
|
-
if (leveragedType === LeverageType.
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
110
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
111
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.vaultAddress.toLowerCase()].price;
|
|
112
|
+
const leveragedAssetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
113
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
114
|
+
if (isReverse) {
|
|
115
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
116
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
117
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
121
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
124
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
118
125
|
}
|
|
119
126
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
120
127
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -50,12 +50,22 @@ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, },
|
|
|
50
50
|
if (leveragedType !== '') {
|
|
51
51
|
payload.leveragedAsset = leveragedAsset;
|
|
52
52
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
53
|
-
if (leveragedType === LeverageType.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
54
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
55
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
56
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
57
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
58
|
+
if (isReverse) {
|
|
59
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
60
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
61
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
65
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
66
|
+
}
|
|
57
67
|
}
|
|
58
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
68
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
59
69
|
}
|
|
60
70
|
payload.minCollRatio = new Dec(payload.suppliedUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
61
71
|
payload.collLiquidationRatio = new Dec(payload.suppliedUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -45,12 +45,22 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
45
45
|
if (leveragedType !== '') {
|
|
46
46
|
payload.leveragedAsset = leveragedAsset;
|
|
47
47
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
48
|
-
if (leveragedType === LeverageType.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
49
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
50
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
51
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
52
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
53
|
+
if (isReverse) {
|
|
54
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
55
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
56
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
60
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
61
|
+
}
|
|
52
62
|
}
|
|
53
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
63
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
54
64
|
}
|
|
55
65
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
56
66
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAssets } from '../../types';
|
|
1
|
+
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAsset, SparkUsedAssets } from '../../types';
|
|
2
2
|
import { EthereumProvider } from '../../types/common';
|
|
3
3
|
export declare const sparkIsInIsolationMode: ({ usedAssets, assetsData }: {
|
|
4
4
|
usedAssets: SparkUsedAssets;
|
|
@@ -6,7 +6,7 @@ export declare const sparkIsInIsolationMode: ({ usedAssets, assetsData }: {
|
|
|
6
6
|
}) => boolean;
|
|
7
7
|
export declare const sparkGetCollSuppliedAssets: ({ usedAssets }: {
|
|
8
8
|
usedAssets: SparkUsedAssets;
|
|
9
|
-
}) =>
|
|
9
|
+
}) => SparkUsedAsset[];
|
|
10
10
|
export declare const sparkGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: SparkHelperCommon) => {
|
|
11
11
|
symbol: string;
|
|
12
12
|
canBeCollateral: boolean;
|
|
@@ -81,12 +81,22 @@ export const sparkGetAggregatedPositionData = (_a) => {
|
|
|
81
81
|
if (leveragedType !== '') {
|
|
82
82
|
payload.leveragedAsset = leveragedAsset;
|
|
83
83
|
let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
|
|
84
|
-
if (leveragedType === LeverageType.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
85
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
86
|
+
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
87
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
88
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
89
|
+
if (isReverse) {
|
|
90
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
91
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
92
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
96
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
97
|
+
}
|
|
88
98
|
}
|
|
89
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
99
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
90
100
|
}
|
|
91
101
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
92
102
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -11,7 +11,7 @@ export const calcShortLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => ne
|
|
|
11
11
|
export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimitUsd) => {
|
|
12
12
|
if (leverageType === LeverageType.Short || leverageType === LeverageType.VolatilePairReverse)
|
|
13
13
|
return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
14
|
-
if (leverageType === LeverageType.Long || leverageType === LeverageType.
|
|
14
|
+
if (leverageType === LeverageType.Long || leverageType === LeverageType.VolatilePair)
|
|
15
15
|
return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
16
16
|
console.error('invalid leverageType', leverageType);
|
|
17
17
|
return '0';
|
|
@@ -48,8 +48,6 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
48
48
|
});
|
|
49
49
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
50
50
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
51
|
-
// lsd -> liquid staking derivative
|
|
52
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH', 'ezETH', 'weETH'].includes(longAsset);
|
|
53
51
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
54
52
|
if (isLong) {
|
|
55
53
|
return {
|
|
@@ -63,12 +61,6 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
63
61
|
leveragedAsset: shortAsset,
|
|
64
62
|
};
|
|
65
63
|
}
|
|
66
|
-
if (isLsdLeveraged) {
|
|
67
|
-
return {
|
|
68
|
-
leveragedType: LeverageType.LsdLeverage,
|
|
69
|
-
leveragedAsset: longAsset,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
64
|
if (isVolatilePair) {
|
|
73
65
|
return {
|
|
74
66
|
leveragedType: LeverageType.VolatilePair,
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -163,7 +163,6 @@ export interface AaveV3AggregatedPositionData {
|
|
|
163
163
|
liqPercent: string;
|
|
164
164
|
leveragedType: LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
|
-
leveragedLsdAssetRatio?: string;
|
|
167
166
|
liquidationPrice?: string;
|
|
168
167
|
minCollRatio?: string;
|
|
169
168
|
collLiquidationRatio?: string;
|
package/esm/types/common.d.ts
CHANGED
package/esm/types/common.js
CHANGED
|
@@ -14,7 +14,6 @@ export var LeverageType;
|
|
|
14
14
|
(function (LeverageType) {
|
|
15
15
|
LeverageType["Long"] = "long";
|
|
16
16
|
LeverageType["Short"] = "short";
|
|
17
|
-
LeverageType["LsdLeverage"] = "lsd-leverage";
|
|
18
17
|
LeverageType["VolatilePair"] = "volatile-pair";
|
|
19
18
|
LeverageType["VolatilePairReverse"] = "volatile-pair-reverse";
|
|
20
19
|
LeverageType["None"] = "";
|
package/esm/types/compound.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
96
96
|
liqPercent: string;
|
|
97
97
|
leveragedType: LeverageType;
|
|
98
98
|
leveragedAsset?: string;
|
|
99
|
-
|
|
99
|
+
currentVolatilePairRatio?: string;
|
|
100
100
|
liquidationPrice?: string;
|
|
101
101
|
minRatio: string;
|
|
102
102
|
debtTooLow: boolean;
|
package/esm/types/euler.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ export interface EulerV2AggregatedPositionData {
|
|
|
143
143
|
liqPercent: string;
|
|
144
144
|
leveragedType: LeverageType;
|
|
145
145
|
leveragedAsset?: string;
|
|
146
|
-
|
|
146
|
+
currentVolatilePairRatio?: string;
|
|
147
147
|
liquidationPrice?: string;
|
|
148
148
|
minRatio: string;
|
|
149
149
|
minDebt: string;
|
package/esm/types/fluid.d.ts
CHANGED
|
@@ -326,7 +326,7 @@ export interface FluidAggregatedVaultData {
|
|
|
326
326
|
leveragedType?: LeverageType;
|
|
327
327
|
leveragedAsset?: string;
|
|
328
328
|
liquidationPrice?: string;
|
|
329
|
-
|
|
329
|
+
currentVolatilePairRatio?: string;
|
|
330
330
|
minCollRatio?: string;
|
|
331
331
|
collLiquidationRatio?: string;
|
|
332
332
|
}
|
|
@@ -123,7 +123,7 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
123
123
|
ratio: string;
|
|
124
124
|
leveragedType: LeverageType;
|
|
125
125
|
leveragedAsset?: string;
|
|
126
|
-
|
|
126
|
+
currentVolatilePairRatio?: string;
|
|
127
127
|
liquidationPrice?: string;
|
|
128
128
|
minCollRatio?: string;
|
|
129
129
|
collLiquidationRatio?: string;
|
|
@@ -144,7 +144,7 @@ export interface MorphoBluePositionData {
|
|
|
144
144
|
ratio: string;
|
|
145
145
|
leveragedType: LeverageType;
|
|
146
146
|
leveragedAsset?: string;
|
|
147
|
-
|
|
147
|
+
currentVolatilePairRatio?: string;
|
|
148
148
|
liquidationPrice?: string;
|
|
149
149
|
supplyShares: string;
|
|
150
150
|
borrowShares: string;
|
package/esm/types/spark.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ export interface SparkAggregatedPositionData {
|
|
|
92
92
|
liqPercent: string;
|
|
93
93
|
leveragedType: LeverageType;
|
|
94
94
|
leveragedAsset?: string;
|
|
95
|
-
|
|
95
|
+
currentVolatilePairRatio?: string;
|
|
96
96
|
liquidationPrice?: string;
|
|
97
97
|
minCollRatio: string;
|
|
98
98
|
collLiquidationRatio: string;
|
package/package.json
CHANGED
|
@@ -117,11 +117,6 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
117
117
|
payload.liquidationPrice = '';
|
|
118
118
|
if (leveragedType !== '') {
|
|
119
119
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
120
|
-
if (leveragedType === LeverageType.LsdLeverage) {
|
|
121
|
-
// Treat ETH like a stablecoin in a long stETH position
|
|
122
|
-
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
123
|
-
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
124
|
-
}
|
|
125
120
|
if (leveragedType === LeverageType.VolatilePair) {
|
|
126
121
|
const borrowedAsset = (Object.values(usedAssets) as AaveV3UsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
127
122
|
const borrowedAssetPrice = data.assetsData[borrowedAsset!.symbol].price;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
3
|
import {
|
|
4
|
-
BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarketData, CompoundV2AssetsData, CompoundV2UsedAssets, CompoundV3AssetData, CompoundV3AssetsData, CompoundV3UsedAssets, CompoundVersions,
|
|
4
|
+
BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarketData, CompoundV2AssetsData, CompoundV2UsedAssets, CompoundV3AssetData, CompoundV3AssetsData, CompoundV3UsedAsset, CompoundV3UsedAssets, CompoundVersions,
|
|
5
5
|
} from '../../types';
|
|
6
6
|
import {
|
|
7
7
|
addToArrayIf, getEthAmountForDecimals, handleWbtcLegacy, wethToEth,
|
|
@@ -189,32 +189,25 @@ export const getCompoundV3AggregatedData = ({
|
|
|
189
189
|
if (leveragedType !== '') {
|
|
190
190
|
payload.leveragedAsset = leveragedAsset;
|
|
191
191
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
192
|
-
if (leveragedType === LeverageType.
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
193
|
+
const borrowedAsset = (Object.values(usedAssets) as CompoundV3UsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
194
|
+
const borrowedAssetPrice = assetsData[borrowedAsset!.symbol].price;
|
|
195
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
196
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
197
|
+
if (isReverse) {
|
|
198
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
199
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
200
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
201
|
+
} else {
|
|
202
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
203
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
204
|
+
}
|
|
195
205
|
}
|
|
196
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
206
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
197
207
|
}
|
|
198
208
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
199
209
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
200
210
|
|
|
201
|
-
// TO DO: handle strategies
|
|
202
|
-
/* const subscribedStrategies = rest.compoundStrategies
|
|
203
|
-
? compoundV3GetSubscribedStrategies({ selectedMarket, compoundStrategies: rest.compoundStrategies })
|
|
204
|
-
: []; */
|
|
205
|
-
|
|
206
|
-
// TODO possibly move to global helper, since every protocol has the same graphData?
|
|
207
|
-
// payload.ratioTooLow = false;
|
|
208
|
-
// payload.ratioTooHigh = false;
|
|
209
|
-
|
|
210
|
-
// TO DO: handle strategies
|
|
211
|
-
/* if (subscribedStrategies.length) {
|
|
212
|
-
subscribedStrategies.forEach(({ graphData }) => {
|
|
213
|
-
payload.ratioTooLow = parseFloat(payload.ratio) < parseFloat(graphData.minRatio);
|
|
214
|
-
payload.ratioTooHigh = graphData.boostEnabled && parseFloat(payload.ratio) > parseFloat(graphData.maxRatio);
|
|
215
|
-
});
|
|
216
|
-
} */
|
|
217
|
-
|
|
218
211
|
return payload;
|
|
219
212
|
};
|
|
220
213
|
|
|
@@ -10,6 +10,7 @@ import { calculateNetApy } from '../../staking';
|
|
|
10
10
|
import {
|
|
11
11
|
EulerV2AggregatedPositionData,
|
|
12
12
|
EulerV2AssetsData,
|
|
13
|
+
EulerV2UsedAsset,
|
|
13
14
|
EulerV2UsedAssets,
|
|
14
15
|
} from '../../types';
|
|
15
16
|
import { EulerV2ViewContractViem } from '../../contracts';
|
|
@@ -44,8 +45,7 @@ export const isLeveragedPos = (usedAssets: EulerV2UsedAssets, dustLimit = 5) =>
|
|
|
44
45
|
});
|
|
45
46
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
46
47
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
47
|
-
|
|
48
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
48
|
+
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
49
49
|
if (isLong) {
|
|
50
50
|
return {
|
|
51
51
|
leveragedType: LeverageType.Long,
|
|
@@ -60,9 +60,9 @@ export const isLeveragedPos = (usedAssets: EulerV2UsedAssets, dustLimit = 5) =>
|
|
|
60
60
|
leveragedVault: leverageAssetVault,
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
if (
|
|
63
|
+
if (isVolatilePair) {
|
|
64
64
|
return {
|
|
65
|
-
leveragedType: LeverageType.
|
|
65
|
+
leveragedType: LeverageType.VolatilePair,
|
|
66
66
|
leveragedAsset: longAsset,
|
|
67
67
|
leveragedVault: leverageAssetVault,
|
|
68
68
|
};
|
|
@@ -99,14 +99,21 @@ export const getEulerV2AggregatedData = ({
|
|
|
99
99
|
if (leveragedType !== '') {
|
|
100
100
|
payload.leveragedAsset = leveragedAsset;
|
|
101
101
|
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
102
|
-
if (leveragedType === LeverageType.
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
103
|
+
const borrowedAsset = (Object.values(usedAssets) as EulerV2UsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
104
|
+
const borrowedAssetPrice = assetsData[borrowedAsset!.vaultAddress.toLowerCase()].price;
|
|
105
|
+
const leveragedAssetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
106
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
107
|
+
if (isReverse) {
|
|
108
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
109
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
110
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
111
|
+
} else {
|
|
112
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
113
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
116
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
110
117
|
}
|
|
111
118
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
112
119
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -84,12 +84,21 @@ borrowShares?: string,
|
|
|
84
84
|
if (leveragedType !== '') {
|
|
85
85
|
payload.leveragedAsset = leveragedAsset;
|
|
86
86
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
87
|
-
if (leveragedType === LeverageType.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
88
|
+
const borrowedAsset = (Object.values(usedAssets) as FluidUsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
89
|
+
const borrowedAssetPrice = assetsData[borrowedAsset!.symbol].price;
|
|
90
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
91
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
92
|
+
if (isReverse) {
|
|
93
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
94
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
95
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
96
|
+
} else {
|
|
97
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
98
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
101
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
payload.minCollRatio = new Dec(payload.suppliedUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from '../../moneymarket';
|
|
6
6
|
import { calculateNetApy } from '../../staking';
|
|
7
7
|
import {
|
|
8
|
-
EthereumProvider, LeverageType, MMAssetsData, MMUsedAssets, NetworkNumber,
|
|
8
|
+
EthereumProvider, LeverageType, MMAssetsData, MMUsedAsset, MMUsedAssets, NetworkNumber,
|
|
9
9
|
} from '../../types/common';
|
|
10
10
|
import {
|
|
11
11
|
MorphoBlueAggregatedPositionData, MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo,
|
|
@@ -58,12 +58,21 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
58
58
|
if (leveragedType !== '') {
|
|
59
59
|
payload.leveragedAsset = leveragedAsset;
|
|
60
60
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
61
|
-
if (leveragedType === LeverageType.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
62
|
+
const borrowedAsset = (Object.values(usedAssets) as MMUsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
63
|
+
const borrowedAssetPrice = assetsData[borrowedAsset!.symbol].price;
|
|
64
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
65
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
66
|
+
if (isReverse) {
|
|
67
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
68
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
69
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
70
|
+
} else {
|
|
71
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
72
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
75
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
67
76
|
}
|
|
68
77
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
69
78
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from '../../moneymarket';
|
|
6
6
|
import {
|
|
7
7
|
SparkAggregatedPositionData,
|
|
8
|
-
SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAssets,
|
|
8
|
+
SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAsset, SparkUsedAssets,
|
|
9
9
|
} from '../../types';
|
|
10
10
|
import { calculateNetApy } from '../../staking';
|
|
11
11
|
import { ethToWeth, getNativeAssetFromWrapped, wethToEth } from '../../services/utils';
|
|
@@ -107,12 +107,21 @@ export const sparkGetAggregatedPositionData = ({
|
|
|
107
107
|
if (leveragedType !== '') {
|
|
108
108
|
payload.leveragedAsset = leveragedAsset;
|
|
109
109
|
let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
|
|
110
|
-
if (leveragedType === LeverageType.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
111
|
+
const borrowedAsset = (Object.values(usedAssets) as SparkUsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
112
|
+
const borrowedAssetPrice = data.assetsData[borrowedAsset!.symbol].price;
|
|
113
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
114
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
115
|
+
if (isReverse) {
|
|
116
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
117
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
118
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
119
|
+
} else {
|
|
120
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
121
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
122
|
+
}
|
|
114
123
|
}
|
|
115
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
124
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
116
125
|
}
|
|
117
126
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
118
127
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -13,7 +13,7 @@ export const calcShortLiqPrice = (assetPrice: string, borrowedUsd: string, borro
|
|
|
13
13
|
|
|
14
14
|
export const calcLeverageLiqPrice = (leverageType: LeverageType, assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => {
|
|
15
15
|
if (leverageType === LeverageType.Short || leverageType === LeverageType.VolatilePairReverse) return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
16
|
-
if (leverageType === LeverageType.Long || leverageType === LeverageType.
|
|
16
|
+
if (leverageType === LeverageType.Long || leverageType === LeverageType.VolatilePair) return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
17
17
|
console.error('invalid leverageType', leverageType);
|
|
18
18
|
return '0';
|
|
19
19
|
};
|
|
@@ -52,8 +52,6 @@ export const isLeveragedPos = (usedAssets: MMUsedAssets, dustLimit = 5) => {
|
|
|
52
52
|
});
|
|
53
53
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
54
54
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
55
|
-
// lsd -> liquid staking derivative
|
|
56
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH', 'ezETH', 'weETH'].includes(longAsset);
|
|
57
55
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
58
56
|
if (isLong) {
|
|
59
57
|
return {
|
|
@@ -67,12 +65,6 @@ export const isLeveragedPos = (usedAssets: MMUsedAssets, dustLimit = 5) => {
|
|
|
67
65
|
leveragedAsset: shortAsset,
|
|
68
66
|
};
|
|
69
67
|
}
|
|
70
|
-
if (isLsdLeveraged) {
|
|
71
|
-
return {
|
|
72
|
-
leveragedType: LeverageType.LsdLeverage,
|
|
73
|
-
leveragedAsset: longAsset,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
68
|
if (isVolatilePair) {
|
|
77
69
|
return {
|
|
78
70
|
leveragedType: LeverageType.VolatilePair,
|
package/src/types/aave.ts
CHANGED
|
@@ -180,7 +180,6 @@ export interface AaveV3AggregatedPositionData {
|
|
|
180
180
|
liqPercent: string,
|
|
181
181
|
leveragedType: LeverageType,
|
|
182
182
|
leveragedAsset?: string,
|
|
183
|
-
leveragedLsdAssetRatio?: string,
|
|
184
183
|
liquidationPrice?: string,
|
|
185
184
|
minCollRatio?: string,
|
|
186
185
|
collLiquidationRatio?: string,
|
package/src/types/common.ts
CHANGED
package/src/types/compound.ts
CHANGED
|
@@ -116,7 +116,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
116
116
|
liqPercent: string,
|
|
117
117
|
leveragedType: LeverageType,
|
|
118
118
|
leveragedAsset?: string,
|
|
119
|
-
|
|
119
|
+
currentVolatilePairRatio?: string,
|
|
120
120
|
liquidationPrice?: string,
|
|
121
121
|
minRatio: string,
|
|
122
122
|
debtTooLow: boolean,
|
package/src/types/euler.ts
CHANGED
|
@@ -168,7 +168,7 @@ export interface EulerV2AggregatedPositionData {
|
|
|
168
168
|
liqPercent: string,
|
|
169
169
|
leveragedType: LeverageType,
|
|
170
170
|
leveragedAsset?: string,
|
|
171
|
-
|
|
171
|
+
currentVolatilePairRatio?: string,
|
|
172
172
|
liquidationPrice?: string,
|
|
173
173
|
minRatio: string,
|
|
174
174
|
minDebt: string,
|
package/src/types/fluid.ts
CHANGED
|
@@ -347,7 +347,7 @@ export interface FluidAggregatedVaultData {
|
|
|
347
347
|
leveragedType?: LeverageType,
|
|
348
348
|
leveragedAsset?: string,
|
|
349
349
|
liquidationPrice?: string,
|
|
350
|
-
|
|
350
|
+
currentVolatilePairRatio?: string,
|
|
351
351
|
minCollRatio?: string,
|
|
352
352
|
collLiquidationRatio?: string,
|
|
353
353
|
}
|
package/src/types/morphoBlue.ts
CHANGED
|
@@ -142,7 +142,7 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
142
142
|
ratio: string,
|
|
143
143
|
leveragedType: LeverageType,
|
|
144
144
|
leveragedAsset?: string,
|
|
145
|
-
|
|
145
|
+
currentVolatilePairRatio?: string,
|
|
146
146
|
liquidationPrice?: string,
|
|
147
147
|
minCollRatio?: string,
|
|
148
148
|
collLiquidationRatio?: string,
|
|
@@ -164,7 +164,7 @@ export interface MorphoBluePositionData {
|
|
|
164
164
|
ratio: string,
|
|
165
165
|
leveragedType: LeverageType,
|
|
166
166
|
leveragedAsset?: string,
|
|
167
|
-
|
|
167
|
+
currentVolatilePairRatio?: string,
|
|
168
168
|
liquidationPrice?: string,
|
|
169
169
|
supplyShares: string,
|
|
170
170
|
borrowShares: string,
|
package/src/types/spark.ts
CHANGED
|
@@ -106,7 +106,7 @@ export interface SparkAggregatedPositionData {
|
|
|
106
106
|
liqPercent: string,
|
|
107
107
|
leveragedType: LeverageType,
|
|
108
108
|
leveragedAsset?: string,
|
|
109
|
-
|
|
109
|
+
currentVolatilePairRatio?: string,
|
|
110
110
|
liquidationPrice?: string,
|
|
111
111
|
minCollRatio: string,
|
|
112
112
|
collLiquidationRatio: string,
|