@defisaver/positions-sdk 2.1.52-dev → 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 +6 -6
- package/cjs/helpers/aaveHelpers/index.js +14 -9
- package/cjs/helpers/compoundHelpers/index.js +15 -18
- package/cjs/helpers/eulerHelpers/index.d.ts +2 -2
- package/cjs/helpers/eulerHelpers/index.js +21 -13
- package/cjs/helpers/fluidHelpers/index.js +16 -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.d.ts +3 -3
- package/cjs/moneymarket/moneymarketCommonService.js +7 -14
- package/cjs/types/aave.d.ts +2 -3
- package/cjs/types/common.d.ts +7 -0
- package/cjs/types/common.js +9 -1
- package/cjs/types/compound.d.ts +3 -3
- package/cjs/types/curveUsd.d.ts +2 -2
- package/cjs/types/euler.d.ts +3 -3
- package/cjs/types/fluid.d.ts +3 -3
- package/cjs/types/liquityV2.d.ts +3 -3
- package/cjs/types/llamaLend.d.ts +2 -2
- package/cjs/types/morphoBlue.d.ts +5 -5
- package/cjs/types/spark.d.ts +3 -3
- package/esm/fluid/index.d.ts +6 -6
- package/esm/helpers/aaveHelpers/index.js +14 -9
- package/esm/helpers/compoundHelpers/index.js +16 -19
- package/esm/helpers/eulerHelpers/index.d.ts +2 -2
- package/esm/helpers/eulerHelpers/index.js +21 -13
- package/esm/helpers/fluidHelpers/index.js +16 -5
- package/esm/helpers/morphoBlueHelpers/index.js +16 -6
- package/esm/helpers/sparkHelpers/index.d.ts +2 -2
- package/esm/helpers/sparkHelpers/index.js +16 -6
- package/esm/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/esm/moneymarket/moneymarketCommonService.js +7 -14
- package/esm/types/aave.d.ts +2 -3
- package/esm/types/common.d.ts +7 -0
- package/esm/types/common.js +8 -0
- package/esm/types/compound.d.ts +3 -3
- package/esm/types/curveUsd.d.ts +2 -2
- package/esm/types/euler.d.ts +3 -3
- package/esm/types/fluid.d.ts +3 -3
- 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 +5 -5
- package/esm/types/spark.d.ts +3 -3
- package/package.json +1 -1
- package/src/helpers/aaveHelpers/index.ts +15 -10
- package/src/helpers/compoundHelpers/index.ts +16 -23
- package/src/helpers/eulerHelpers/index.ts +21 -14
- package/src/helpers/fluidHelpers/index.ts +15 -6
- package/src/helpers/morphoBlueHelpers/index.ts +15 -6
- package/src/helpers/sparkHelpers/index.ts +18 -7
- package/src/moneymarket/moneymarketCommonService.ts +8 -16
- package/src/types/aave.ts +2 -2
- package/src/types/common.ts +8 -0
- package/src/types/compound.ts +3 -2
- package/src/types/curveUsd.ts +2 -2
- package/src/types/euler.ts +3 -2
- package/src/types/fluid.ts +5 -3
- package/src/types/liquityV2.ts +5 -3
- package/src/types/llamaLend.ts +4 -2
- package/src/types/morphoBlue.ts +5 -5
- package/src/types/spark.ts +3 -2
package/esm/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,9 +90,9 @@ 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
|
+
currentVolatilePairRatio?: string;
|
|
96
96
|
liquidationPrice?: string;
|
|
97
97
|
minCollRatio: string;
|
|
98
98
|
collLiquidationRatio: string;
|
package/package.json
CHANGED
|
@@ -10,7 +10,9 @@ import {
|
|
|
10
10
|
} from '../../moneymarket';
|
|
11
11
|
import { calculateNetApy } from '../../staking';
|
|
12
12
|
import { borrowOperations } from '../../constants';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
EthAddress, EthereumProvider, LeverageType, NetworkNumber,
|
|
15
|
+
} from '../../types/common';
|
|
14
16
|
import { AaveLoanInfoV2ContractViem, AaveV3ViewContractViem } from '../../contracts';
|
|
15
17
|
import { getViemProvider } from '../../services/viem';
|
|
16
18
|
|
|
@@ -115,18 +117,21 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
115
117
|
payload.liquidationPrice = '';
|
|
116
118
|
if (leveragedType !== '') {
|
|
117
119
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
118
|
-
if (leveragedType ===
|
|
119
|
-
// Treat ETH like a stablecoin in a long stETH position
|
|
120
|
-
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
121
|
-
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
122
|
-
}
|
|
123
|
-
if (leveragedType === 'volatile-pair') {
|
|
120
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
124
121
|
const borrowedAsset = (Object.values(usedAssets) as AaveV3UsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
125
122
|
const borrowedAssetPrice = data.assetsData[borrowedAsset!.symbol].price;
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
124
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
125
|
+
if (isReverse) {
|
|
126
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
127
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
128
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
129
|
+
} else {
|
|
130
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
131
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
132
|
+
}
|
|
128
133
|
}
|
|
129
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
134
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
130
135
|
}
|
|
131
136
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
132
137
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -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,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '../../moneymarket';
|
|
13
13
|
import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../../staking';
|
|
14
14
|
import {
|
|
15
|
-
EthAddress, EthereumProvider, IncentiveData, IncentiveKind, NetworkNumber,
|
|
15
|
+
EthAddress, EthereumProvider, IncentiveData, IncentiveKind, LeverageType, NetworkNumber,
|
|
16
16
|
} from '../../types/common';
|
|
17
17
|
import { CompoundLoanInfoContractViem, CompV3ViewContractViem } from '../../contracts';
|
|
18
18
|
import { getViemProvider } from '../../services/viem';
|
|
@@ -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 ===
|
|
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
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { assetAmountInWei } from '@defisaver/tokens';
|
|
3
3
|
import {
|
|
4
|
-
EthAddress, EthereumProvider, MMAssetsData, NetworkNumber,
|
|
4
|
+
EthAddress, EthereumProvider, LeverageType, MMAssetsData, NetworkNumber,
|
|
5
5
|
} from '../../types/common';
|
|
6
6
|
import {
|
|
7
7
|
calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS,
|
|
@@ -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,31 +45,30 @@ 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
|
-
leveragedType:
|
|
51
|
+
leveragedType: LeverageType.Long,
|
|
52
52
|
leveragedAsset: longAsset,
|
|
53
53
|
leveragedVault: leverageAssetVault,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
if (isShort) {
|
|
57
57
|
return {
|
|
58
|
-
leveragedType:
|
|
58
|
+
leveragedType: LeverageType.Short,
|
|
59
59
|
leveragedAsset: shortAsset,
|
|
60
60
|
leveragedVault: leverageAssetVault,
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
if (
|
|
63
|
+
if (isVolatilePair) {
|
|
64
64
|
return {
|
|
65
|
-
leveragedType:
|
|
65
|
+
leveragedType: LeverageType.VolatilePair,
|
|
66
66
|
leveragedAsset: longAsset,
|
|
67
67
|
leveragedVault: leverageAssetVault,
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
return {
|
|
71
|
-
leveragedType:
|
|
71
|
+
leveragedType: LeverageType.None,
|
|
72
72
|
leveragedAsset: '',
|
|
73
73
|
leveragedVault: '',
|
|
74
74
|
};
|
|
@@ -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 ===
|
|
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();
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '../../types';
|
|
10
10
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
11
11
|
import { calculateNetApy } from '../../staking';
|
|
12
|
-
import { MMAssetsData } from '../../types/common';
|
|
12
|
+
import { LeverageType, MMAssetsData } from '../../types/common';
|
|
13
13
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
14
14
|
|
|
15
15
|
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }: { marketData: InnerFluidMarketData, suppliedUsd: string, borrowedUsd: string }) => {
|
|
@@ -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 ===
|
|
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, 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 ===
|
|
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,12 +5,14 @@ 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';
|
|
12
12
|
import { SparkViewContractViem } from '../../contracts';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
EthAddress, EthereumProvider, LeverageType, NetworkNumber,
|
|
15
|
+
} from '../../types/common';
|
|
14
16
|
import { borrowOperations } from '../../constants';
|
|
15
17
|
import { getViemProvider } from '../../services/viem';
|
|
16
18
|
|
|
@@ -105,12 +107,21 @@ export const sparkGetAggregatedPositionData = ({
|
|
|
105
107
|
if (leveragedType !== '') {
|
|
106
108
|
payload.leveragedAsset = leveragedAsset;
|
|
107
109
|
let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
|
|
108
|
-
if (leveragedType ===
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
}
|
|
112
123
|
}
|
|
113
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
124
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
114
125
|
}
|
|
115
126
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
116
127
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
3
|
-
import { MMUsedAssets } from '../types/common';
|
|
3
|
+
import { LeverageType, MMUsedAssets } from '../types/common';
|
|
4
4
|
|
|
5
5
|
export const getAssetsTotal = (assets: object, filter: any, transform: any) => (Object.values(assets) as any)
|
|
6
6
|
.filter(filter)
|
|
@@ -11,9 +11,9 @@ export const getAssetsTotal = (assets: object, filter: any, transform: any) => (
|
|
|
11
11
|
export const calcLongLiqPrice = (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => new Dec(assetPrice).mul(borrowedUsd).div(borrowLimitUsd).toString();
|
|
12
12
|
export const calcShortLiqPrice = (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => new Dec(assetPrice).div(borrowedUsd).mul(borrowLimitUsd).toString();
|
|
13
13
|
|
|
14
|
-
export const calcLeverageLiqPrice = (leverageType:
|
|
15
|
-
if (leverageType ===
|
|
16
|
-
if (leverageType ===
|
|
14
|
+
export const calcLeverageLiqPrice = (leverageType: LeverageType, assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => {
|
|
15
|
+
if (leverageType === LeverageType.Short || leverageType === LeverageType.VolatilePairReverse) return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
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,35 +52,27 @@ 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 {
|
|
60
|
-
leveragedType:
|
|
58
|
+
leveragedType: LeverageType.Long,
|
|
61
59
|
leveragedAsset: longAsset,
|
|
62
60
|
};
|
|
63
61
|
}
|
|
64
62
|
if (isShort) {
|
|
65
63
|
return {
|
|
66
|
-
leveragedType:
|
|
64
|
+
leveragedType: LeverageType.Short,
|
|
67
65
|
leveragedAsset: shortAsset,
|
|
68
66
|
};
|
|
69
67
|
}
|
|
70
|
-
if (isLsdLeveraged) {
|
|
71
|
-
return {
|
|
72
|
-
leveragedType: 'lsd-leverage',
|
|
73
|
-
leveragedAsset: longAsset,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
68
|
if (isVolatilePair) {
|
|
77
69
|
return {
|
|
78
|
-
leveragedType:
|
|
70
|
+
leveragedType: LeverageType.VolatilePair,
|
|
79
71
|
leveragedAsset: longAsset,
|
|
80
72
|
};
|
|
81
73
|
}
|
|
82
74
|
return {
|
|
83
|
-
leveragedType:
|
|
75
|
+
leveragedType: LeverageType.None,
|
|
84
76
|
leveragedAsset: '',
|
|
85
77
|
};
|
|
86
78
|
};
|
package/src/types/aave.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
IncentiveData,
|
|
3
|
+
LeverageType,
|
|
3
4
|
MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber,
|
|
4
5
|
} from './common';
|
|
5
6
|
|
|
@@ -177,9 +178,8 @@ export interface AaveV3AggregatedPositionData {
|
|
|
177
178
|
totalInterestUsd: string,
|
|
178
179
|
liqRatio: string,
|
|
179
180
|
liqPercent: string,
|
|
180
|
-
leveragedType:
|
|
181
|
+
leveragedType: LeverageType,
|
|
181
182
|
leveragedAsset?: string,
|
|
182
|
-
leveragedLsdAssetRatio?: string,
|
|
183
183
|
liquidationPrice?: string,
|
|
184
184
|
minCollRatio?: string,
|
|
185
185
|
collLiquidationRatio?: string,
|
package/src/types/common.ts
CHANGED
|
@@ -10,6 +10,14 @@ export enum IncentiveEligibilityId {
|
|
|
10
10
|
AaveV3EthenaLiquidLeveragePlasma = '0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL',
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export enum LeverageType {
|
|
14
|
+
Long = 'long',
|
|
15
|
+
Short = 'short',
|
|
16
|
+
VolatilePair = 'volatile-pair',
|
|
17
|
+
VolatilePairReverse = 'volatile-pair-reverse',
|
|
18
|
+
None = '',
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
export interface IncentiveData {
|
|
14
22
|
token: string,
|
|
15
23
|
apy: string,
|
package/src/types/compound.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EthAddress,
|
|
3
|
+
LeverageType,
|
|
3
4
|
MMAssetData,
|
|
4
5
|
MMPositionData,
|
|
5
6
|
MMUsedAsset,
|
|
@@ -113,9 +114,9 @@ export interface CompoundAggregatedPositionData {
|
|
|
113
114
|
totalInterestUsd: string,
|
|
114
115
|
liqRatio: string,
|
|
115
116
|
liqPercent: string,
|
|
116
|
-
leveragedType:
|
|
117
|
+
leveragedType: LeverageType,
|
|
117
118
|
leveragedAsset?: string,
|
|
118
|
-
|
|
119
|
+
currentVolatilePairRatio?: string,
|
|
119
120
|
liquidationPrice?: string,
|
|
120
121
|
minRatio: string,
|
|
121
122
|
debtTooLow: boolean,
|
package/src/types/curveUsd.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
|
|
3
3
|
export enum CrvUSDVersions {
|
|
4
4
|
'crvUSDwstETH' = 'wstETH',
|
|
@@ -78,7 +78,7 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
78
78
|
borrowLimitUsd: string,
|
|
79
79
|
minAllowedRatio: number,
|
|
80
80
|
collFactor: string,
|
|
81
|
-
leveragedType:
|
|
81
|
+
leveragedType: LeverageType,
|
|
82
82
|
leveragedAsset?: string,
|
|
83
83
|
liquidationPrice?: string,
|
|
84
84
|
}
|
package/src/types/euler.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EthAddress,
|
|
3
3
|
IncentiveData,
|
|
4
|
+
LeverageType,
|
|
4
5
|
MMPositionData, NetworkNumber,
|
|
5
6
|
} from './common';
|
|
6
7
|
|
|
@@ -165,9 +166,9 @@ export interface EulerV2AggregatedPositionData {
|
|
|
165
166
|
totalInterestUsd: string,
|
|
166
167
|
liqRatio: string,
|
|
167
168
|
liqPercent: string,
|
|
168
|
-
leveragedType:
|
|
169
|
+
leveragedType: LeverageType,
|
|
169
170
|
leveragedAsset?: string,
|
|
170
|
-
|
|
171
|
+
currentVolatilePairRatio?: string,
|
|
171
172
|
liquidationPrice?: string,
|
|
172
173
|
minRatio: string,
|
|
173
174
|
minDebt: string,
|
package/src/types/fluid.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EthAddress, IncentiveData, LeverageType, NetworkNumber,
|
|
3
|
+
} from './common';
|
|
2
4
|
|
|
3
5
|
export interface FluidMarketInfo {
|
|
4
6
|
chainIds: number[]
|
|
@@ -342,10 +344,10 @@ export interface FluidAggregatedVaultData {
|
|
|
342
344
|
collRatio: string,
|
|
343
345
|
minRatio: string
|
|
344
346
|
totalInterestUsd: string,
|
|
345
|
-
leveragedType?:
|
|
347
|
+
leveragedType?: LeverageType,
|
|
346
348
|
leveragedAsset?: string,
|
|
347
349
|
liquidationPrice?: string,
|
|
348
|
-
|
|
350
|
+
currentVolatilePairRatio?: string,
|
|
349
351
|
minCollRatio?: string,
|
|
350
352
|
collLiquidationRatio?: string,
|
|
351
353
|
}
|
package/src/types/liquityV2.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EthAddress, IncentiveData, LeverageType, NetworkNumber,
|
|
3
|
+
} from './common';
|
|
2
4
|
|
|
3
5
|
export enum LiquityV2Versions {
|
|
4
6
|
LiquityV2Eth = 'liquityv2eth',
|
|
@@ -96,7 +98,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
96
98
|
netApy: string,
|
|
97
99
|
incentiveUsd: string,
|
|
98
100
|
totalInterestUsd: string,
|
|
99
|
-
leveragedType:
|
|
101
|
+
leveragedType: LeverageType,
|
|
100
102
|
leveragedAsset: string,
|
|
101
103
|
liquidationPrice: string,
|
|
102
104
|
ratio: string,
|
|
@@ -119,7 +121,7 @@ export interface LiquityV2TroveData {
|
|
|
119
121
|
totalInterestUsd: string,
|
|
120
122
|
interestBatchManager: EthAddress,
|
|
121
123
|
troveStatus: string,
|
|
122
|
-
leveragedType:
|
|
124
|
+
leveragedType: LeverageType,
|
|
123
125
|
leveragedAsset: string,
|
|
124
126
|
liquidationPrice: string,
|
|
125
127
|
debtInFront: string,
|
package/src/types/llamaLend.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EthAddress, IncentiveData, LeverageType, NetworkNumber,
|
|
3
|
+
} from './common';
|
|
2
4
|
import { BandData, UserBandData } from './curveUsd';
|
|
3
5
|
|
|
4
6
|
export enum LLVersionsEth {
|
|
@@ -110,7 +112,7 @@ export interface LlamaLendAggregatedPositionData {
|
|
|
110
112
|
borrowLimitUsd: string,
|
|
111
113
|
minAllowedRatio: number,
|
|
112
114
|
collFactor: string,
|
|
113
|
-
leveragedType:
|
|
115
|
+
leveragedType: LeverageType,
|
|
114
116
|
leveragedAsset?: string,
|
|
115
117
|
liquidationPrice?: string,
|
|
116
118
|
netApy: string,
|
package/src/types/morphoBlue.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EthAddress, IncentiveData, MMUsedAssets, NetworkNumber,
|
|
2
|
+
EthAddress, IncentiveData, LeverageType, MMUsedAssets, NetworkNumber,
|
|
3
3
|
} from './common';
|
|
4
4
|
|
|
5
5
|
export enum MorphoBlueVersions {
|
|
@@ -140,9 +140,9 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
140
140
|
totalInterestUsd: string,
|
|
141
141
|
ltv: string,
|
|
142
142
|
ratio: string,
|
|
143
|
-
leveragedType:
|
|
143
|
+
leveragedType: LeverageType,
|
|
144
144
|
leveragedAsset?: string,
|
|
145
|
-
|
|
145
|
+
currentVolatilePairRatio?: string,
|
|
146
146
|
liquidationPrice?: string,
|
|
147
147
|
minCollRatio?: string,
|
|
148
148
|
collLiquidationRatio?: string,
|
|
@@ -162,9 +162,9 @@ export interface MorphoBluePositionData {
|
|
|
162
162
|
totalInterestUsd: string,
|
|
163
163
|
ltv: string,
|
|
164
164
|
ratio: string,
|
|
165
|
-
leveragedType:
|
|
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
|
@@ -2,6 +2,7 @@ import { EModeCategoriesData } from './aave';
|
|
|
2
2
|
import {
|
|
3
3
|
EthAddress,
|
|
4
4
|
IncentiveData,
|
|
5
|
+
LeverageType,
|
|
5
6
|
MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber,
|
|
6
7
|
} from './common';
|
|
7
8
|
|
|
@@ -103,9 +104,9 @@ export interface SparkAggregatedPositionData {
|
|
|
103
104
|
totalInterestUsd: string,
|
|
104
105
|
liqRatio: string,
|
|
105
106
|
liqPercent: string,
|
|
106
|
-
leveragedType:
|
|
107
|
+
leveragedType: LeverageType,
|
|
107
108
|
leveragedAsset?: string,
|
|
108
|
-
|
|
109
|
+
currentVolatilePairRatio?: string,
|
|
109
110
|
liquidationPrice?: string,
|
|
110
111
|
minCollRatio: string,
|
|
111
112
|
collLiquidationRatio: string,
|