@defisaver/positions-sdk 2.1.52-dev → 2.1.52-dev-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/fluid/index.d.ts +3 -3
- package/cjs/helpers/aaveHelpers/index.js +15 -5
- package/cjs/helpers/compoundHelpers/index.js +1 -1
- package/cjs/helpers/eulerHelpers/index.d.ts +2 -2
- package/cjs/helpers/eulerHelpers/index.js +6 -5
- package/cjs/helpers/fluidHelpers/index.js +2 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/cjs/moneymarket/moneymarketCommonService.js +8 -7
- package/cjs/types/aave.d.ts +2 -2
- package/cjs/types/common.d.ts +8 -0
- package/cjs/types/common.js +10 -1
- package/cjs/types/compound.d.ts +2 -2
- package/cjs/types/curveUsd.d.ts +2 -2
- package/cjs/types/euler.d.ts +2 -2
- package/cjs/types/fluid.d.ts +2 -2
- package/cjs/types/liquityV2.d.ts +3 -3
- package/cjs/types/llamaLend.d.ts +2 -2
- package/cjs/types/morphoBlue.d.ts +3 -3
- package/cjs/types/spark.d.ts +2 -2
- package/esm/fluid/index.d.ts +3 -3
- package/esm/helpers/aaveHelpers/index.js +15 -5
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/eulerHelpers/index.d.ts +2 -2
- package/esm/helpers/eulerHelpers/index.js +6 -5
- package/esm/helpers/fluidHelpers/index.js +2 -1
- package/esm/helpers/morphoBlueHelpers/index.js +2 -2
- package/esm/helpers/sparkHelpers/index.js +2 -2
- package/esm/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/esm/moneymarket/moneymarketCommonService.js +8 -7
- package/esm/types/aave.d.ts +2 -2
- package/esm/types/common.d.ts +8 -0
- package/esm/types/common.js +9 -0
- package/esm/types/compound.d.ts +2 -2
- package/esm/types/curveUsd.d.ts +2 -2
- package/esm/types/euler.d.ts +2 -2
- package/esm/types/fluid.d.ts +2 -2
- package/esm/types/fluid.js +1 -1
- package/esm/types/liquityV2.d.ts +3 -3
- package/esm/types/llamaLend.d.ts +2 -2
- package/esm/types/morphoBlue.d.ts +3 -3
- package/esm/types/spark.d.ts +2 -2
- package/package.json +1 -1
- package/src/helpers/aaveHelpers/index.ts +16 -6
- package/src/helpers/compoundHelpers/index.ts +2 -2
- package/src/helpers/eulerHelpers/index.ts +6 -6
- package/src/helpers/fluidHelpers/index.ts +2 -2
- package/src/helpers/morphoBlueHelpers/index.ts +2 -2
- package/src/helpers/sparkHelpers/index.ts +4 -2
- package/src/moneymarket/moneymarketCommonService.ts +9 -9
- package/src/types/aave.ts +2 -1
- package/src/types/common.ts +9 -0
- package/src/types/compound.ts +2 -1
- package/src/types/curveUsd.ts +2 -2
- package/src/types/euler.ts +2 -1
- package/src/types/fluid.ts +4 -2
- package/src/types/liquityV2.ts +5 -3
- package/src/types/llamaLend.ts +4 -2
- package/src/types/morphoBlue.ts +3 -3
- package/src/types/spark.ts +2 -1
|
@@ -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 { NetworkNumber, } from '../../types/common';
|
|
14
|
+
import { LeverageType, 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,7 +45,7 @@ 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 ===
|
|
48
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
49
49
|
// Treat ETH like a stablecoin in a long stETH position
|
|
50
50
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
51
51
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
@@ -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 { NetworkNumber } from '../../types/common';
|
|
27
|
+
import { LeverageType, 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,7 +81,7 @@ 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 ===
|
|
84
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
85
85
|
// Treat ETH like a stablecoin in a long stETH position
|
|
86
86
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
87
87
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { MMUsedAssets } from '../types/common';
|
|
1
|
+
import { LeverageType, MMUsedAssets } from '../types/common';
|
|
2
2
|
export declare const getAssetsTotal: (assets: object, filter: any, transform: any) => any;
|
|
3
3
|
export declare const calcLongLiqPrice: (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
4
4
|
export declare const calcShortLiqPrice: (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
5
|
-
export declare const calcLeverageLiqPrice: (leverageType:
|
|
5
|
+
export declare const calcLeverageLiqPrice: (leverageType: LeverageType, assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => string;
|
|
6
6
|
export declare const calculateBorrowingAssetLimit: (assetBorrowedUsd: string, borrowLimitUsd: string) => string;
|
|
7
7
|
export declare const STABLE_ASSETS: string[];
|
|
8
8
|
export declare const isLeveragedPos: (usedAssets: MMUsedAssets, dustLimit?: number) => {
|
|
9
|
-
leveragedType:
|
|
9
|
+
leveragedType: LeverageType;
|
|
10
10
|
leveragedAsset: string;
|
|
11
11
|
};
|
|
12
12
|
export declare const aprToApy: (interest: string | number, frequency?: number) => string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
3
|
+
import { LeverageType } from '../types/common';
|
|
3
4
|
export const getAssetsTotal = (assets, filter, transform) => Object.values(assets)
|
|
4
5
|
.filter(filter)
|
|
5
6
|
.map(transform)
|
|
@@ -8,9 +9,9 @@ export const getAssetsTotal = (assets, filter, transform) => Object.values(asset
|
|
|
8
9
|
export const calcLongLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => new Dec(assetPrice).mul(borrowedUsd).div(borrowLimitUsd).toString();
|
|
9
10
|
export const calcShortLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => new Dec(assetPrice).div(borrowedUsd).mul(borrowLimitUsd).toString();
|
|
10
11
|
export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimitUsd) => {
|
|
11
|
-
if (leverageType ===
|
|
12
|
+
if (leverageType === LeverageType.Short || leverageType === LeverageType.VolatilePairReverse)
|
|
12
13
|
return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
13
|
-
if (leverageType ===
|
|
14
|
+
if (leverageType === LeverageType.Long || leverageType === LeverageType.LsdLeverage || leverageType === LeverageType.VolatilePair)
|
|
14
15
|
return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
15
16
|
console.error('invalid leverageType', leverageType);
|
|
16
17
|
return '0';
|
|
@@ -52,30 +53,30 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
52
53
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
53
54
|
if (isLong) {
|
|
54
55
|
return {
|
|
55
|
-
leveragedType:
|
|
56
|
+
leveragedType: LeverageType.Long,
|
|
56
57
|
leveragedAsset: longAsset,
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
if (isShort) {
|
|
60
61
|
return {
|
|
61
|
-
leveragedType:
|
|
62
|
+
leveragedType: LeverageType.Short,
|
|
62
63
|
leveragedAsset: shortAsset,
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
if (isLsdLeveraged) {
|
|
66
67
|
return {
|
|
67
|
-
leveragedType:
|
|
68
|
+
leveragedType: LeverageType.LsdLeverage,
|
|
68
69
|
leveragedAsset: longAsset,
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
if (isVolatilePair) {
|
|
72
73
|
return {
|
|
73
|
-
leveragedType:
|
|
74
|
+
leveragedType: LeverageType.VolatilePair,
|
|
74
75
|
leveragedAsset: longAsset,
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
78
|
return {
|
|
78
|
-
leveragedType:
|
|
79
|
+
leveragedType: LeverageType.None,
|
|
79
80
|
leveragedAsset: '',
|
|
80
81
|
};
|
|
81
82
|
};
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IncentiveData, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
1
|
+
import { IncentiveData, LeverageType, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
2
|
export declare enum AaveVersions {
|
|
3
3
|
AaveV1 = "v1",
|
|
4
4
|
AaveV2 = "v2default",
|
|
@@ -161,7 +161,7 @@ export interface AaveV3AggregatedPositionData {
|
|
|
161
161
|
totalInterestUsd: string;
|
|
162
162
|
liqRatio: string;
|
|
163
163
|
liqPercent: string;
|
|
164
|
-
leveragedType:
|
|
164
|
+
leveragedType: LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
leveragedLsdAssetRatio?: string;
|
|
167
167
|
liquidationPrice?: string;
|
package/esm/types/common.d.ts
CHANGED
|
@@ -8,6 +8,14 @@ export declare enum IncentiveEligibilityId {
|
|
|
8
8
|
AaveV3ArbitrumETHLSBorrow = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351",
|
|
9
9
|
AaveV3EthenaLiquidLeveragePlasma = "0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL"
|
|
10
10
|
}
|
|
11
|
+
export declare enum LeverageType {
|
|
12
|
+
Long = "long",
|
|
13
|
+
Short = "short",
|
|
14
|
+
LsdLeverage = "lsd-leverage",
|
|
15
|
+
VolatilePair = "volatile-pair",
|
|
16
|
+
VolatilePairReverse = "volatile-pair-reverse",
|
|
17
|
+
None = ""
|
|
18
|
+
}
|
|
11
19
|
export interface IncentiveData {
|
|
12
20
|
token: string;
|
|
13
21
|
apy: string;
|
package/esm/types/common.js
CHANGED
|
@@ -10,6 +10,15 @@ 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["LsdLeverage"] = "lsd-leverage";
|
|
18
|
+
LeverageType["VolatilePair"] = "volatile-pair";
|
|
19
|
+
LeverageType["VolatilePairReverse"] = "volatile-pair-reverse";
|
|
20
|
+
LeverageType["None"] = "";
|
|
21
|
+
})(LeverageType || (LeverageType = {}));
|
|
13
22
|
export var NetworkNumber;
|
|
14
23
|
(function (NetworkNumber) {
|
|
15
24
|
NetworkNumber[NetworkNumber["Eth"] = 1] = "Eth";
|
package/esm/types/compound.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, LeverageType, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
|
|
2
2
|
export declare enum CompoundVersions {
|
|
3
3
|
'CompoundV2' = "v2",
|
|
4
4
|
'CompoundV3USDC' = "v3-USDC",
|
|
@@ -94,7 +94,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
94
94
|
totalInterestUsd: string;
|
|
95
95
|
liqRatio: string;
|
|
96
96
|
liqPercent: string;
|
|
97
|
-
leveragedType:
|
|
97
|
+
leveragedType: LeverageType;
|
|
98
98
|
leveragedAsset?: string;
|
|
99
99
|
leveragedLsdAssetRatio?: string;
|
|
100
100
|
liquidationPrice?: string;
|
package/esm/types/curveUsd.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
export declare enum CrvUSDVersions {
|
|
3
3
|
'crvUSDwstETH' = "wstETH",
|
|
4
4
|
'crvUSDWBTC' = "WBTC",
|
|
@@ -71,7 +71,7 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
71
71
|
borrowLimitUsd: string;
|
|
72
72
|
minAllowedRatio: number;
|
|
73
73
|
collFactor: string;
|
|
74
|
-
leveragedType:
|
|
74
|
+
leveragedType: LeverageType;
|
|
75
75
|
leveragedAsset?: string;
|
|
76
76
|
liquidationPrice?: string;
|
|
77
77
|
}
|
package/esm/types/euler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, MMPositionData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, MMPositionData, NetworkNumber } from './common';
|
|
2
2
|
export declare enum EulerV2Versions {
|
|
3
3
|
eUSDC2 = "eUSDC-2",
|
|
4
4
|
eWETH2 = "eWETH-2"
|
|
@@ -141,7 +141,7 @@ export interface EulerV2AggregatedPositionData {
|
|
|
141
141
|
totalInterestUsd: string;
|
|
142
142
|
liqRatio: string;
|
|
143
143
|
liqPercent: string;
|
|
144
|
-
leveragedType:
|
|
144
|
+
leveragedType: LeverageType;
|
|
145
145
|
leveragedAsset?: string;
|
|
146
146
|
leveragedLsdAssetRatio?: string;
|
|
147
147
|
liquidationPrice?: string;
|
package/esm/types/fluid.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
export interface FluidMarketInfo {
|
|
3
3
|
chainIds: number[];
|
|
4
4
|
label: string;
|
|
@@ -323,7 +323,7 @@ export interface FluidAggregatedVaultData {
|
|
|
323
323
|
collRatio: string;
|
|
324
324
|
minRatio: string;
|
|
325
325
|
totalInterestUsd: string;
|
|
326
|
-
leveragedType?:
|
|
326
|
+
leveragedType?: LeverageType;
|
|
327
327
|
leveragedAsset?: string;
|
|
328
328
|
liquidationPrice?: string;
|
|
329
329
|
leveragedLsdAssetRatio?: string;
|
package/esm/types/fluid.js
CHANGED
package/esm/types/liquityV2.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
export declare enum LiquityV2Versions {
|
|
3
3
|
LiquityV2Eth = "liquityv2eth",
|
|
4
4
|
LiquityV2WstEth = "liquityv2wsteth",
|
|
@@ -88,7 +88,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
88
88
|
netApy: string;
|
|
89
89
|
incentiveUsd: string;
|
|
90
90
|
totalInterestUsd: string;
|
|
91
|
-
leveragedType:
|
|
91
|
+
leveragedType: LeverageType;
|
|
92
92
|
leveragedAsset: string;
|
|
93
93
|
liquidationPrice: string;
|
|
94
94
|
ratio: string;
|
|
@@ -110,7 +110,7 @@ export interface LiquityV2TroveData {
|
|
|
110
110
|
totalInterestUsd: string;
|
|
111
111
|
interestBatchManager: EthAddress;
|
|
112
112
|
troveStatus: string;
|
|
113
|
-
leveragedType:
|
|
113
|
+
leveragedType: LeverageType;
|
|
114
114
|
leveragedAsset: string;
|
|
115
115
|
liquidationPrice: string;
|
|
116
116
|
debtInFront: string;
|
package/esm/types/llamaLend.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
import { BandData, UserBandData } from './curveUsd';
|
|
3
3
|
export declare enum LLVersionsEth {
|
|
4
4
|
LLWstethCrvusd = "llamaLendwstETHcrvUSD",
|
|
@@ -112,7 +112,7 @@ export interface LlamaLendAggregatedPositionData {
|
|
|
112
112
|
borrowLimitUsd: string;
|
|
113
113
|
minAllowedRatio: number;
|
|
114
114
|
collFactor: string;
|
|
115
|
-
leveragedType:
|
|
115
|
+
leveragedType: LeverageType;
|
|
116
116
|
leveragedAsset?: string;
|
|
117
117
|
liquidationPrice?: string;
|
|
118
118
|
netApy: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, IncentiveData, MMUsedAssets, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, IncentiveData, LeverageType, MMUsedAssets, NetworkNumber } from './common';
|
|
2
2
|
export declare enum MorphoBlueVersions {
|
|
3
3
|
MorphoBlueWstEthUSDC = "morphobluewstethusdc",// wstETH/USDC
|
|
4
4
|
MorphoBlueSDAIUSDC = "morphobluesdaiusdc",// sDAI/USDC
|
|
@@ -121,7 +121,7 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
121
121
|
totalInterestUsd: string;
|
|
122
122
|
ltv: string;
|
|
123
123
|
ratio: string;
|
|
124
|
-
leveragedType:
|
|
124
|
+
leveragedType: LeverageType;
|
|
125
125
|
leveragedAsset?: string;
|
|
126
126
|
leveragedLsdAssetRatio?: string;
|
|
127
127
|
liquidationPrice?: string;
|
|
@@ -142,7 +142,7 @@ export interface MorphoBluePositionData {
|
|
|
142
142
|
totalInterestUsd: string;
|
|
143
143
|
ltv: string;
|
|
144
144
|
ratio: string;
|
|
145
|
-
leveragedType:
|
|
145
|
+
leveragedType: LeverageType;
|
|
146
146
|
leveragedAsset?: string;
|
|
147
147
|
leveragedLsdAssetRatio?: string;
|
|
148
148
|
liquidationPrice?: string;
|
package/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,7 +90,7 @@ export interface SparkAggregatedPositionData {
|
|
|
90
90
|
totalInterestUsd: string;
|
|
91
91
|
liqRatio: string;
|
|
92
92
|
liqPercent: string;
|
|
93
|
-
leveragedType:
|
|
93
|
+
leveragedType: LeverageType;
|
|
94
94
|
leveragedAsset?: string;
|
|
95
95
|
leveragedLsdAssetRatio?: string;
|
|
96
96
|
liquidationPrice?: string;
|
package/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,26 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
115
117
|
payload.liquidationPrice = '';
|
|
116
118
|
if (leveragedType !== '') {
|
|
117
119
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
118
|
-
if (leveragedType ===
|
|
120
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
119
121
|
// Treat ETH like a stablecoin in a long stETH position
|
|
120
122
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
121
123
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
122
124
|
}
|
|
123
|
-
if (leveragedType ===
|
|
125
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
124
126
|
const borrowedAsset = (Object.values(usedAssets) as AaveV3UsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
125
127
|
const borrowedAssetPrice = data.assetsData[borrowedAsset!.symbol].price;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
129
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
130
|
+
if (isReverse) {
|
|
131
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
132
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
133
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
134
|
+
} else {
|
|
135
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
136
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
137
|
+
}
|
|
128
138
|
}
|
|
129
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
139
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
130
140
|
}
|
|
131
141
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
132
142
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -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,7 +189,7 @@ export const getCompoundV3AggregatedData = ({
|
|
|
189
189
|
if (leveragedType !== '') {
|
|
190
190
|
payload.leveragedAsset = leveragedAsset;
|
|
191
191
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
192
|
-
if (leveragedType ===
|
|
192
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
193
193
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toString();
|
|
194
194
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
195
195
|
}
|
|
@@ -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,
|
|
@@ -48,27 +48,27 @@ export const isLeveragedPos = (usedAssets: EulerV2UsedAssets, dustLimit = 5) =>
|
|
|
48
48
|
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
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
63
|
if (isLsdLeveraged) {
|
|
64
64
|
return {
|
|
65
|
-
leveragedType:
|
|
65
|
+
leveragedType: LeverageType.LsdLeverage,
|
|
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,7 +99,7 @@ export const getEulerV2AggregatedData = ({
|
|
|
99
99
|
if (leveragedType !== '') {
|
|
100
100
|
payload.leveragedAsset = leveragedAsset;
|
|
101
101
|
let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
102
|
-
if (leveragedType ===
|
|
102
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
103
103
|
const ethAsset = Object.values(assetsData).find((asset) => ['WETH', 'ETH'].includes(asset.symbol));
|
|
104
104
|
if (ethAsset) {
|
|
105
105
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedVault.toLowerCase()].price).div(ethAsset.price).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,7 +84,7 @@ borrowShares?: string,
|
|
|
84
84
|
if (leveragedType !== '') {
|
|
85
85
|
payload.leveragedAsset = leveragedAsset;
|
|
86
86
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
87
|
-
if (leveragedType ===
|
|
87
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
88
88
|
// Treat ETH like a stablecoin in a long stETH position
|
|
89
89
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
90
90
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).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, MMUsedAssets, NetworkNumber,
|
|
9
9
|
} from '../../types/common';
|
|
10
10
|
import {
|
|
11
11
|
MorphoBlueAggregatedPositionData, MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo,
|
|
@@ -58,7 +58,7 @@ 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 ===
|
|
61
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
62
62
|
// Treat ETH like a stablecoin in a long stETH position
|
|
63
63
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
64
64
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
@@ -10,7 +10,9 @@ import {
|
|
|
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,7 +107,7 @@ 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 ===
|
|
110
|
+
if (leveragedType === LeverageType.LsdLeverage) {
|
|
109
111
|
// Treat ETH like a stablecoin in a long stETH position
|
|
110
112
|
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
111
113
|
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).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.LsdLeverage || leverageType === LeverageType.VolatilePair) return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
17
17
|
console.error('invalid leverageType', leverageType);
|
|
18
18
|
return '0';
|
|
19
19
|
};
|
|
@@ -57,30 +57,30 @@ export const isLeveragedPos = (usedAssets: MMUsedAssets, dustLimit = 5) => {
|
|
|
57
57
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
58
58
|
if (isLong) {
|
|
59
59
|
return {
|
|
60
|
-
leveragedType:
|
|
60
|
+
leveragedType: LeverageType.Long,
|
|
61
61
|
leveragedAsset: longAsset,
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
if (isShort) {
|
|
65
65
|
return {
|
|
66
|
-
leveragedType:
|
|
66
|
+
leveragedType: LeverageType.Short,
|
|
67
67
|
leveragedAsset: shortAsset,
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
if (isLsdLeveraged) {
|
|
71
71
|
return {
|
|
72
|
-
leveragedType:
|
|
72
|
+
leveragedType: LeverageType.LsdLeverage,
|
|
73
73
|
leveragedAsset: longAsset,
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
if (isVolatilePair) {
|
|
77
77
|
return {
|
|
78
|
-
leveragedType:
|
|
78
|
+
leveragedType: LeverageType.VolatilePair,
|
|
79
79
|
leveragedAsset: longAsset,
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
return {
|
|
83
|
-
leveragedType:
|
|
83
|
+
leveragedType: LeverageType.None,
|
|
84
84
|
leveragedAsset: '',
|
|
85
85
|
};
|
|
86
86
|
};
|
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,7 +178,7 @@ 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
183
|
leveragedLsdAssetRatio?: string,
|
|
183
184
|
liquidationPrice?: string,
|
package/src/types/common.ts
CHANGED
|
@@ -10,6 +10,15 @@ export enum IncentiveEligibilityId {
|
|
|
10
10
|
AaveV3EthenaLiquidLeveragePlasma = '0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL',
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export enum LeverageType {
|
|
14
|
+
Long = 'long',
|
|
15
|
+
Short = 'short',
|
|
16
|
+
LsdLeverage = 'lsd-leverage',
|
|
17
|
+
VolatilePair = 'volatile-pair',
|
|
18
|
+
VolatilePairReverse = 'volatile-pair-reverse',
|
|
19
|
+
None = '',
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
export interface IncentiveData {
|
|
14
23
|
token: string,
|
|
15
24
|
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,7 +114,7 @@ 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
|
leveragedLsdAssetRatio?: string,
|
|
119
120
|
liquidationPrice?: string,
|
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,7 +166,7 @@ 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
|
leveragedLsdAssetRatio?: string,
|
|
171
172
|
liquidationPrice?: string,
|