@defisaver/positions-sdk 2.1.52-dev-3 → 2.1.52
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.d.ts +2 -2
- package/cjs/helpers/aaveHelpers/index.js +5 -16
- package/cjs/helpers/compoundHelpers/index.js +18 -15
- package/cjs/helpers/eulerHelpers/index.d.ts +2 -2
- package/cjs/helpers/eulerHelpers/index.js +13 -21
- package/cjs/helpers/fluidHelpers/index.js +5 -16
- package/cjs/helpers/morphoBlueHelpers/index.js +5 -15
- package/cjs/helpers/sparkHelpers/index.d.ts +2 -2
- package/cjs/helpers/sparkHelpers/index.js +5 -15
- package/cjs/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/cjs/moneymarket/moneymarketCommonService.js +9 -9
- package/cjs/types/aave.d.ts +3 -3
- package/cjs/types/common.d.ts +0 -7
- package/cjs/types/common.js +1 -9
- 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.d.ts +2 -2
- package/esm/helpers/aaveHelpers/index.js +5 -16
- package/esm/helpers/compoundHelpers/index.js +19 -16
- package/esm/helpers/eulerHelpers/index.d.ts +2 -2
- package/esm/helpers/eulerHelpers/index.js +13 -21
- package/esm/helpers/fluidHelpers/index.js +5 -16
- package/esm/helpers/morphoBlueHelpers/index.js +6 -16
- package/esm/helpers/sparkHelpers/index.d.ts +2 -2
- package/esm/helpers/sparkHelpers/index.js +6 -16
- package/esm/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/esm/moneymarket/moneymarketCommonService.js +9 -9
- package/esm/types/aave.d.ts +3 -3
- package/esm/types/common.d.ts +0 -7
- package/esm/types/common.js +0 -8
- 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 +2 -2
- package/src/helpers/aaveHelpers/index.ts +7 -18
- package/src/helpers/compoundHelpers/index.ts +23 -16
- package/src/helpers/eulerHelpers/index.ts +14 -21
- package/src/helpers/fluidHelpers/index.ts +6 -15
- package/src/helpers/morphoBlueHelpers/index.ts +6 -15
- package/src/helpers/sparkHelpers/index.ts +7 -18
- package/src/moneymarket/moneymarketCommonService.ts +11 -10
- package/src/types/aave.ts +2 -3
- package/src/types/common.ts +0 -8
- package/src/types/compound.ts +2 -3
- package/src/types/curveUsd.ts +2 -2
- package/src/types/euler.ts +2 -3
- package/src/types/fluid.ts +3 -5
- package/src/types/liquityV2.ts +3 -5
- package/src/types/llamaLend.ts +2 -4
- package/src/types/morphoBlue.ts +5 -5
- package/src/types/spark.ts +2 -3
package/esm/fluid/index.d.ts
CHANGED
|
@@ -130,10 +130,10 @@ export declare const _getUserPositions: (provider: PublicClient, network: Networ
|
|
|
130
130
|
collRatio: string;
|
|
131
131
|
minRatio: string;
|
|
132
132
|
totalInterestUsd: string;
|
|
133
|
-
leveragedType?:
|
|
133
|
+
leveragedType?: string;
|
|
134
134
|
leveragedAsset?: string;
|
|
135
135
|
liquidationPrice?: string;
|
|
136
|
-
|
|
136
|
+
leveragedLsdAssetRatio?: string;
|
|
137
137
|
minCollRatio?: string;
|
|
138
138
|
collLiquidationRatio?: string;
|
|
139
139
|
owner: string;
|
|
@@ -161,10 +161,10 @@ export declare const getUserPositions: (provider: EthereumProvider, network: Net
|
|
|
161
161
|
collRatio: string;
|
|
162
162
|
minRatio: string;
|
|
163
163
|
totalInterestUsd: string;
|
|
164
|
-
leveragedType?:
|
|
164
|
+
leveragedType?: string;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
liquidationPrice?: string;
|
|
167
|
-
|
|
167
|
+
leveragedLsdAssetRatio?: string;
|
|
168
168
|
minCollRatio?: string;
|
|
169
169
|
collLiquidationRatio?: string;
|
|
170
170
|
owner: string;
|
|
@@ -192,10 +192,10 @@ export declare const _getUserPositionsPortfolio: (provider: PublicClient, networ
|
|
|
192
192
|
collRatio: string;
|
|
193
193
|
minRatio: string;
|
|
194
194
|
totalInterestUsd: string;
|
|
195
|
-
leveragedType?:
|
|
195
|
+
leveragedType?: string;
|
|
196
196
|
leveragedAsset?: string;
|
|
197
197
|
liquidationPrice?: string;
|
|
198
|
-
|
|
198
|
+
leveragedLsdAssetRatio?: string;
|
|
199
199
|
minCollRatio?: string;
|
|
200
200
|
collLiquidationRatio?: string;
|
|
201
201
|
owner: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData,
|
|
1
|
+
import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAssets, AaveVersions } from '../../types';
|
|
2
2
|
import { EthereumProvider, NetworkNumber } from '../../types/common';
|
|
3
3
|
export declare const AAVE_V3_MARKETS: AaveVersions[];
|
|
4
4
|
export declare const isAaveV2: ({ selectedMarket }: {
|
|
@@ -17,7 +17,7 @@ export declare const aaveV3IsInSiloedMode: ({ usedAssets, assetsData }: {
|
|
|
17
17
|
}) => boolean;
|
|
18
18
|
export declare const aaveAnyGetCollSuppliedAssets: ({ usedAssets }: {
|
|
19
19
|
usedAssets: AaveV3UsedAssets;
|
|
20
|
-
}) => AaveV3UsedAsset[];
|
|
20
|
+
}) => import("../../types").AaveV3UsedAsset[];
|
|
21
21
|
export declare const aaveAnyGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => {
|
|
22
22
|
symbol: string;
|
|
23
23
|
canBeCollateral: boolean;
|
|
@@ -25,7 +25,6 @@ import { getNativeAssetFromWrapped, getWrappedNativeAssetFromUnwrapped } from '.
|
|
|
25
25
|
import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
26
26
|
import { calculateNetApy } from '../../staking';
|
|
27
27
|
import { borrowOperations } from '../../constants';
|
|
28
|
-
import { LeverageType, } from '../../types/common';
|
|
29
28
|
import { AaveLoanInfoV2ContractViem, AaveV3ViewContractViem } from '../../contracts';
|
|
30
29
|
import { getViemProvider } from '../../services/viem';
|
|
31
30
|
export const AAVE_V3_MARKETS = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi];
|
|
@@ -90,22 +89,12 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
90
89
|
payload.liquidationPrice = '';
|
|
91
90
|
if (leveragedType !== '') {
|
|
92
91
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
93
|
-
if (leveragedType ===
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
98
|
-
if (isReverse) {
|
|
99
|
-
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
100
|
-
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
101
|
-
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
105
|
-
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
106
|
-
}
|
|
92
|
+
if (leveragedType === 'lsd-leverage') {
|
|
93
|
+
// Treat ETH like a stablecoin in a long stETH position
|
|
94
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
95
|
+
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
107
96
|
}
|
|
108
|
-
payload.liquidationPrice = calcLeverageLiqPrice(
|
|
97
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
109
98
|
}
|
|
110
99
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
111
100
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -25,7 +25,7 @@ import { addToArrayIf, getEthAmountForDecimals, handleWbtcLegacy, wethToEth, } f
|
|
|
25
25
|
import { BLOCKS_IN_A_YEAR, borrowOperations, SECONDS_PER_YEAR } from '../../constants';
|
|
26
26
|
import { aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
27
27
|
import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../../staking';
|
|
28
|
-
import { IncentiveKind,
|
|
28
|
+
import { IncentiveKind, NetworkNumber, } from '../../types/common';
|
|
29
29
|
import { CompoundLoanInfoContractViem, CompV3ViewContractViem } from '../../contracts';
|
|
30
30
|
import { getViemProvider } from '../../services/viem';
|
|
31
31
|
export const formatMarketData = (data, network, baseAssetPrice) => {
|
|
@@ -140,25 +140,28 @@ export const getCompoundV3AggregatedData = (_a) => {
|
|
|
140
140
|
if (leveragedType !== '') {
|
|
141
141
|
payload.leveragedAsset = leveragedAsset;
|
|
142
142
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
143
|
-
if (leveragedType ===
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
}
|
|
143
|
+
if (leveragedType === 'lsd-leverage') {
|
|
144
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toString();
|
|
145
|
+
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
157
146
|
}
|
|
158
|
-
payload.liquidationPrice = calcLeverageLiqPrice(
|
|
147
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
159
148
|
}
|
|
160
149
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
161
150
|
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
|
+
} */
|
|
162
165
|
return payload;
|
|
163
166
|
};
|
|
164
167
|
export const getApyAfterValuesEstimationCompoundV2 = (actions, provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EthAddress, EthereumProvider,
|
|
1
|
+
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
2
2
|
import { EulerV2AggregatedPositionData, EulerV2AssetsData, EulerV2UsedAssets } from '../../types';
|
|
3
3
|
export declare const isLeveragedPos: (usedAssets: EulerV2UsedAssets, dustLimit?: number) => {
|
|
4
|
-
leveragedType:
|
|
4
|
+
leveragedType: string;
|
|
5
5
|
leveragedAsset: string;
|
|
6
6
|
leveragedVault: string;
|
|
7
7
|
};
|
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
};
|
|
21
21
|
import Dec from 'decimal.js';
|
|
22
22
|
import { assetAmountInWei } from '@defisaver/tokens';
|
|
23
|
-
import { LeverageType, } from '../../types/common';
|
|
24
23
|
import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
|
|
25
24
|
import { calculateNetApy } from '../../staking';
|
|
26
25
|
import { EulerV2ViewContractViem } from '../../contracts';
|
|
@@ -54,30 +53,31 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
54
53
|
});
|
|
55
54
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
56
55
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
57
|
-
|
|
56
|
+
// lsd -> liquid staking derivative
|
|
57
|
+
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
58
58
|
if (isLong) {
|
|
59
59
|
return {
|
|
60
|
-
leveragedType:
|
|
60
|
+
leveragedType: 'long',
|
|
61
61
|
leveragedAsset: longAsset,
|
|
62
62
|
leveragedVault: leverageAssetVault,
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
if (isShort) {
|
|
66
66
|
return {
|
|
67
|
-
leveragedType:
|
|
67
|
+
leveragedType: 'short',
|
|
68
68
|
leveragedAsset: shortAsset,
|
|
69
69
|
leveragedVault: leverageAssetVault,
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
if (
|
|
72
|
+
if (isLsdLeveraged) {
|
|
73
73
|
return {
|
|
74
|
-
leveragedType:
|
|
74
|
+
leveragedType: 'lsd-leverage',
|
|
75
75
|
leveragedAsset: longAsset,
|
|
76
76
|
leveragedVault: leverageAssetVault,
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
return {
|
|
80
|
-
leveragedType:
|
|
80
|
+
leveragedType: '',
|
|
81
81
|
leveragedAsset: '',
|
|
82
82
|
leveragedVault: '',
|
|
83
83
|
};
|
|
@@ -106,22 +106,14 @@ export const getEulerV2AggregatedData = (_a) => {
|
|
|
106
106
|
if (leveragedType !== '') {
|
|
107
107
|
payload.leveragedAsset = leveragedAsset;
|
|
108
108
|
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
109
|
-
if (leveragedType ===
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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();
|
|
109
|
+
if (leveragedType === 'lsd-leverage') {
|
|
110
|
+
const ethAsset = Object.values(assetsData).find((asset) => ['WETH', 'ETH'].includes(asset.symbol));
|
|
111
|
+
if (ethAsset) {
|
|
112
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedVault.toLowerCase()].price).div(ethAsset.price).toString();
|
|
113
|
+
assetPrice = new Dec(assetPrice).div(ethAsset.price).toString();
|
|
122
114
|
}
|
|
123
115
|
}
|
|
124
|
-
payload.liquidationPrice = calcLeverageLiqPrice(
|
|
116
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
125
117
|
}
|
|
126
118
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
127
119
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -3,7 +3,6 @@ import { assetAmountInEth } from '@defisaver/tokens';
|
|
|
3
3
|
import { FluidVaultType, } from '../../types';
|
|
4
4
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
5
5
|
import { calculateNetApy } from '../../staking';
|
|
6
|
-
import { LeverageType } from '../../types/common';
|
|
7
6
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
8
7
|
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }) => {
|
|
9
8
|
const { borrowRate, supplyRate, incentiveBorrowRate, incentiveSupplyRate, tradingBorrowRate, tradingSupplyRate, } = marketData;
|
|
@@ -50,22 +49,12 @@ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, },
|
|
|
50
49
|
if (leveragedType !== '') {
|
|
51
50
|
payload.leveragedAsset = leveragedAsset;
|
|
52
51
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
53
|
-
if (leveragedType ===
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
}
|
|
52
|
+
if (leveragedType === 'lsd-leverage') {
|
|
53
|
+
// Treat ETH like a stablecoin in a long stETH position
|
|
54
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
55
|
+
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
67
56
|
}
|
|
68
|
-
payload.liquidationPrice = calcLeverageLiqPrice(
|
|
57
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
69
58
|
}
|
|
70
59
|
payload.minCollRatio = new Dec(payload.suppliedUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
71
60
|
payload.collLiquidationRatio = new Dec(payload.suppliedUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -11,7 +11,7 @@ import Dec from 'decimal.js';
|
|
|
11
11
|
import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
12
12
|
import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
13
13
|
import { calculateNetApy } from '../../staking';
|
|
14
|
-
import {
|
|
14
|
+
import { NetworkNumber, } from '../../types/common';
|
|
15
15
|
import { borrowOperations, SECONDS_PER_YEAR, WAD } from '../../constants';
|
|
16
16
|
import { MorphoBlueViewContractViem } from '../../contracts';
|
|
17
17
|
import { compareAddresses, DEFAULT_TIMEOUT, wethToEth } from '../../services/utils';
|
|
@@ -45,22 +45,12 @@ 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 ===
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
}
|
|
48
|
+
if (leveragedType === 'lsd-leverage') {
|
|
49
|
+
// Treat ETH like a stablecoin in a long stETH position
|
|
50
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
51
|
+
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
62
52
|
}
|
|
63
|
-
payload.liquidationPrice = calcLeverageLiqPrice(
|
|
53
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
64
54
|
}
|
|
65
55
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
66
56
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData,
|
|
1
|
+
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData, 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
|
-
}) => SparkUsedAsset[];
|
|
9
|
+
}) => import("../../types").SparkUsedAsset[];
|
|
10
10
|
export declare const sparkGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: SparkHelperCommon) => {
|
|
11
11
|
symbol: string;
|
|
12
12
|
canBeCollateral: boolean;
|
|
@@ -24,7 +24,7 @@ import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos, } from
|
|
|
24
24
|
import { calculateNetApy } from '../../staking';
|
|
25
25
|
import { ethToWeth, getNativeAssetFromWrapped, wethToEth } from '../../services/utils';
|
|
26
26
|
import { SparkViewContractViem } from '../../contracts';
|
|
27
|
-
import {
|
|
27
|
+
import { NetworkNumber } from '../../types/common';
|
|
28
28
|
import { borrowOperations } from '../../constants';
|
|
29
29
|
import { getViemProvider } from '../../services/viem';
|
|
30
30
|
export const sparkIsInIsolationMode = ({ usedAssets, assetsData }) => Object.values(usedAssets).some(({ symbol, collateral }) => collateral && assetsData[symbol].isIsolated);
|
|
@@ -81,22 +81,12 @@ 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 ===
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
}
|
|
84
|
+
if (leveragedType === 'lsd-leverage') {
|
|
85
|
+
// Treat ETH like a stablecoin in a long stETH position
|
|
86
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
87
|
+
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
98
88
|
}
|
|
99
|
-
payload.liquidationPrice = calcLeverageLiqPrice(
|
|
89
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
100
90
|
}
|
|
101
91
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
102
92
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MMUsedAssets } from '../types/common';
|
|
2
2
|
export declare const getAssetsTotal: (assets: object, filter: any, transform: any) => any;
|
|
3
3
|
export declare const calcLongLiqPrice: (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
4
4
|
export declare const calcShortLiqPrice: (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
5
|
-
export declare const calcLeverageLiqPrice: (leverageType:
|
|
5
|
+
export declare const calcLeverageLiqPrice: (leverageType: string, assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
6
6
|
export declare const calculateBorrowingAssetLimit: (assetBorrowedUsd: string, borrowLimitUsd: string) => string;
|
|
7
7
|
export declare const STABLE_ASSETS: string[];
|
|
8
8
|
export declare const isLeveragedPos: (usedAssets: MMUsedAssets, dustLimit?: number) => {
|
|
9
|
-
leveragedType:
|
|
9
|
+
leveragedType: string;
|
|
10
10
|
leveragedAsset: string;
|
|
11
11
|
};
|
|
12
12
|
export declare const aprToApy: (interest: string | number, frequency?: number) => string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
3
|
-
import { LeverageType } from '../types/common';
|
|
4
3
|
export const getAssetsTotal = (assets, filter, transform) => Object.values(assets)
|
|
5
4
|
.filter(filter)
|
|
6
5
|
.map(transform)
|
|
@@ -9,9 +8,9 @@ export const getAssetsTotal = (assets, filter, transform) => Object.values(asset
|
|
|
9
8
|
export const calcLongLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => new Dec(assetPrice).mul(borrowedUsd).div(borrowLimitUsd).toString();
|
|
10
9
|
export const calcShortLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => new Dec(assetPrice).div(borrowedUsd).mul(borrowLimitUsd).toString();
|
|
11
10
|
export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimitUsd) => {
|
|
12
|
-
if (leverageType ===
|
|
11
|
+
if (leverageType === 'short')
|
|
13
12
|
return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
14
|
-
if (leverageType ===
|
|
13
|
+
if (leverageType === 'long' || leverageType === 'lsd-leverage')
|
|
15
14
|
return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
16
15
|
console.error('invalid leverageType', leverageType);
|
|
17
16
|
return '0';
|
|
@@ -48,27 +47,28 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
48
47
|
});
|
|
49
48
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
50
49
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
51
|
-
|
|
50
|
+
// lsd -> liquid staking derivative
|
|
51
|
+
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH', 'ezETH', 'weETH'].includes(longAsset);
|
|
52
52
|
if (isLong) {
|
|
53
53
|
return {
|
|
54
|
-
leveragedType:
|
|
54
|
+
leveragedType: 'long',
|
|
55
55
|
leveragedAsset: longAsset,
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
if (isShort) {
|
|
59
59
|
return {
|
|
60
|
-
leveragedType:
|
|
60
|
+
leveragedType: 'short',
|
|
61
61
|
leveragedAsset: shortAsset,
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
if (
|
|
64
|
+
if (isLsdLeveraged) {
|
|
65
65
|
return {
|
|
66
|
-
leveragedType:
|
|
66
|
+
leveragedType: 'lsd-leverage',
|
|
67
67
|
leveragedAsset: longAsset,
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
return {
|
|
71
|
-
leveragedType:
|
|
71
|
+
leveragedType: '',
|
|
72
72
|
leveragedAsset: '',
|
|
73
73
|
};
|
|
74
74
|
};
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IncentiveData,
|
|
1
|
+
import { IncentiveData, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
2
|
export declare enum AaveVersions {
|
|
3
3
|
AaveV1 = "v1",
|
|
4
4
|
AaveV2 = "v2default",
|
|
@@ -161,14 +161,14 @@ export interface AaveV3AggregatedPositionData {
|
|
|
161
161
|
totalInterestUsd: string;
|
|
162
162
|
liqRatio: string;
|
|
163
163
|
liqPercent: string;
|
|
164
|
-
leveragedType:
|
|
164
|
+
leveragedType: string;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
|
+
leveragedLsdAssetRatio?: string;
|
|
166
167
|
liquidationPrice?: string;
|
|
167
168
|
minCollRatio?: string;
|
|
168
169
|
collLiquidationRatio?: string;
|
|
169
170
|
healthRatio?: string;
|
|
170
171
|
minHealthRatio?: string;
|
|
171
|
-
currentVolatilePairRatio?: string;
|
|
172
172
|
}
|
|
173
173
|
export interface AaveHelperCommon {
|
|
174
174
|
usedAssets: any;
|
package/esm/types/common.d.ts
CHANGED
|
@@ -8,13 +8,6 @@ export declare enum IncentiveEligibilityId {
|
|
|
8
8
|
AaveV3ArbitrumETHLSBorrow = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351",
|
|
9
9
|
AaveV3EthenaLiquidLeveragePlasma = "0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL"
|
|
10
10
|
}
|
|
11
|
-
export declare enum LeverageType {
|
|
12
|
-
Long = "long",
|
|
13
|
-
Short = "short",
|
|
14
|
-
VolatilePair = "volatile-pair",
|
|
15
|
-
VolatilePairReverse = "volatile-pair-reverse",
|
|
16
|
-
None = ""
|
|
17
|
-
}
|
|
18
11
|
export interface IncentiveData {
|
|
19
12
|
token: string;
|
|
20
13
|
apy: string;
|
package/esm/types/common.js
CHANGED
|
@@ -10,14 +10,6 @@ export var IncentiveEligibilityId;
|
|
|
10
10
|
IncentiveEligibilityId["AaveV3ArbitrumETHLSBorrow"] = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351";
|
|
11
11
|
IncentiveEligibilityId["AaveV3EthenaLiquidLeveragePlasma"] = "0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL";
|
|
12
12
|
})(IncentiveEligibilityId || (IncentiveEligibilityId = {}));
|
|
13
|
-
export var LeverageType;
|
|
14
|
-
(function (LeverageType) {
|
|
15
|
-
LeverageType["Long"] = "long";
|
|
16
|
-
LeverageType["Short"] = "short";
|
|
17
|
-
LeverageType["VolatilePair"] = "volatile-pair";
|
|
18
|
-
LeverageType["VolatilePairReverse"] = "volatile-pair-reverse";
|
|
19
|
-
LeverageType["None"] = "";
|
|
20
|
-
})(LeverageType || (LeverageType = {}));
|
|
21
13
|
export var NetworkNumber;
|
|
22
14
|
(function (NetworkNumber) {
|
|
23
15
|
NetworkNumber[NetworkNumber["Eth"] = 1] = "Eth";
|
package/esm/types/compound.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress,
|
|
1
|
+
import { EthAddress, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
2
|
export declare enum CompoundVersions {
|
|
3
3
|
'CompoundV2' = "v2",
|
|
4
4
|
'CompoundV3USDC' = "v3-USDC",
|
|
@@ -94,9 +94,9 @@ export interface CompoundAggregatedPositionData {
|
|
|
94
94
|
totalInterestUsd: string;
|
|
95
95
|
liqRatio: string;
|
|
96
96
|
liqPercent: string;
|
|
97
|
-
leveragedType:
|
|
97
|
+
leveragedType: string;
|
|
98
98
|
leveragedAsset?: string;
|
|
99
|
-
|
|
99
|
+
leveragedLsdAssetRatio?: string;
|
|
100
100
|
liquidationPrice?: string;
|
|
101
101
|
minRatio: string;
|
|
102
102
|
debtTooLow: boolean;
|
package/esm/types/curveUsd.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress,
|
|
1
|
+
import { EthAddress, NetworkNumber } from './common';
|
|
2
2
|
export declare enum CrvUSDVersions {
|
|
3
3
|
'crvUSDwstETH' = "wstETH",
|
|
4
4
|
'crvUSDWBTC' = "WBTC",
|
|
@@ -71,7 +71,7 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
71
71
|
borrowLimitUsd: string;
|
|
72
72
|
minAllowedRatio: number;
|
|
73
73
|
collFactor: string;
|
|
74
|
-
leveragedType:
|
|
74
|
+
leveragedType: string;
|
|
75
75
|
leveragedAsset?: string;
|
|
76
76
|
liquidationPrice?: string;
|
|
77
77
|
}
|
package/esm/types/euler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData,
|
|
1
|
+
import { EthAddress, IncentiveData, MMPositionData, NetworkNumber } from './common';
|
|
2
2
|
export declare enum EulerV2Versions {
|
|
3
3
|
eUSDC2 = "eUSDC-2",
|
|
4
4
|
eWETH2 = "eWETH-2"
|
|
@@ -141,9 +141,9 @@ export interface EulerV2AggregatedPositionData {
|
|
|
141
141
|
totalInterestUsd: string;
|
|
142
142
|
liqRatio: string;
|
|
143
143
|
liqPercent: string;
|
|
144
|
-
leveragedType:
|
|
144
|
+
leveragedType: string;
|
|
145
145
|
leveragedAsset?: string;
|
|
146
|
-
|
|
146
|
+
leveragedLsdAssetRatio?: string;
|
|
147
147
|
liquidationPrice?: string;
|
|
148
148
|
minRatio: string;
|
|
149
149
|
minDebt: string;
|
package/esm/types/fluid.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData,
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
2
|
export interface FluidMarketInfo {
|
|
3
3
|
chainIds: number[];
|
|
4
4
|
label: string;
|
|
@@ -323,10 +323,10 @@ export interface FluidAggregatedVaultData {
|
|
|
323
323
|
collRatio: string;
|
|
324
324
|
minRatio: string;
|
|
325
325
|
totalInterestUsd: string;
|
|
326
|
-
leveragedType?:
|
|
326
|
+
leveragedType?: string;
|
|
327
327
|
leveragedAsset?: string;
|
|
328
328
|
liquidationPrice?: string;
|
|
329
|
-
|
|
329
|
+
leveragedLsdAssetRatio?: string;
|
|
330
330
|
minCollRatio?: string;
|
|
331
331
|
collLiquidationRatio?: string;
|
|
332
332
|
}
|
package/esm/types/fluid.js
CHANGED
package/esm/types/liquityV2.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData,
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
2
|
export declare enum LiquityV2Versions {
|
|
3
3
|
LiquityV2Eth = "liquityv2eth",
|
|
4
4
|
LiquityV2WstEth = "liquityv2wsteth",
|
|
@@ -88,7 +88,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
88
88
|
netApy: string;
|
|
89
89
|
incentiveUsd: string;
|
|
90
90
|
totalInterestUsd: string;
|
|
91
|
-
leveragedType:
|
|
91
|
+
leveragedType: string;
|
|
92
92
|
leveragedAsset: string;
|
|
93
93
|
liquidationPrice: string;
|
|
94
94
|
ratio: string;
|
|
@@ -110,7 +110,7 @@ export interface LiquityV2TroveData {
|
|
|
110
110
|
totalInterestUsd: string;
|
|
111
111
|
interestBatchManager: EthAddress;
|
|
112
112
|
troveStatus: string;
|
|
113
|
-
leveragedType:
|
|
113
|
+
leveragedType: string;
|
|
114
114
|
leveragedAsset: string;
|
|
115
115
|
liquidationPrice: string;
|
|
116
116
|
debtInFront: string;
|
package/esm/types/llamaLend.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData,
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
2
|
import { BandData, UserBandData } from './curveUsd';
|
|
3
3
|
export declare enum LLVersionsEth {
|
|
4
4
|
LLWstethCrvusd = "llamaLendwstETHcrvUSD",
|
|
@@ -112,7 +112,7 @@ export interface LlamaLendAggregatedPositionData {
|
|
|
112
112
|
borrowLimitUsd: string;
|
|
113
113
|
minAllowedRatio: number;
|
|
114
114
|
collFactor: string;
|
|
115
|
-
leveragedType:
|
|
115
|
+
leveragedType: string;
|
|
116
116
|
leveragedAsset?: string;
|
|
117
117
|
liquidationPrice?: string;
|
|
118
118
|
netApy: string;
|