@defisaver/positions-sdk 2.1.52 → 2.1.53-aave-v4
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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +64 -64
- package/cjs/aaveV4/index.d.ts +7 -0
- package/cjs/aaveV4/index.js +174 -0
- package/cjs/config/contracts.d.ts +1277 -0
- package/cjs/config/contracts.js +9 -0
- package/cjs/contracts.d.ts +23120 -0
- package/cjs/contracts.js +2 -1
- package/cjs/fluid/index.d.ts +6 -6
- package/cjs/helpers/aaveHelpers/index.d.ts +2 -2
- package/cjs/helpers/aaveHelpers/index.js +16 -5
- package/cjs/helpers/aaveV4Helpers/index.d.ts +13 -0
- package/cjs/helpers/aaveV4Helpers/index.js +117 -0
- 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/index.d.ts +1 -0
- package/cjs/helpers/index.js +2 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +81 -71
- package/cjs/helpers/sparkHelpers/index.d.ts +2 -2
- package/cjs/helpers/sparkHelpers/index.js +15 -5
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/markets/aaveV4/index.d.ts +13 -0
- package/cjs/markets/aaveV4/index.js +39 -0
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/cjs/moneymarket/moneymarketCommonService.js +9 -9
- package/cjs/portfolio/index.js +20 -0
- package/cjs/savings/morphoVaults/index.js +17 -17
- package/cjs/types/aave.d.ts +3 -3
- package/cjs/types/aaveV4.d.ts +137 -0
- package/cjs/types/aaveV4.js +11 -0
- 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/index.d.ts +2 -0
- package/cjs/types/index.js +2 -0
- 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/portfolio.d.ts +4 -0
- package/cjs/types/spark.d.ts +3 -3
- package/esm/aaveV4/index.d.ts +7 -0
- package/esm/aaveV4/index.js +165 -0
- package/esm/config/contracts.d.ts +1277 -0
- package/esm/config/contracts.js +8 -0
- package/esm/contracts.d.ts +23120 -0
- package/esm/contracts.js +1 -0
- package/esm/fluid/index.d.ts +6 -6
- package/esm/helpers/aaveHelpers/index.d.ts +2 -2
- package/esm/helpers/aaveHelpers/index.js +16 -5
- package/esm/helpers/aaveV4Helpers/index.d.ts +13 -0
- package/esm/helpers/aaveV4Helpers/index.js +108 -0
- 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/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/morphoBlueHelpers/index.js +82 -72
- package/esm/helpers/sparkHelpers/index.d.ts +2 -2
- package/esm/helpers/sparkHelpers/index.js +16 -6
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/markets/aaveV4/index.d.ts +13 -0
- package/esm/markets/aaveV4/index.js +29 -0
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/esm/moneymarket/moneymarketCommonService.js +9 -9
- package/esm/portfolio/index.js +21 -1
- package/esm/savings/morphoVaults/index.js +17 -17
- package/esm/types/aave.d.ts +3 -3
- package/esm/types/aaveV4.d.ts +137 -0
- package/esm/types/aaveV4.js +8 -0
- 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/index.d.ts +2 -0
- package/esm/types/index.js +2 -0
- 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/portfolio.d.ts +4 -0
- package/esm/types/spark.d.ts +3 -3
- package/package.json +48 -48
- package/src/aaveV2/index.ts +240 -240
- package/src/aaveV3/index.ts +635 -635
- package/src/aaveV3/merit.ts +97 -97
- package/src/aaveV3/merkl.ts +74 -74
- package/src/aaveV4/index.ts +176 -0
- package/src/claiming/aaveV3.ts +154 -154
- package/src/claiming/compV3.ts +22 -22
- package/src/claiming/ethena.ts +61 -61
- package/src/claiming/index.ts +12 -12
- package/src/claiming/king.ts +66 -66
- package/src/claiming/morphoBlue.ts +118 -118
- package/src/claiming/spark.ts +225 -225
- package/src/compoundV2/index.ts +244 -244
- package/src/compoundV3/index.ts +274 -274
- package/src/config/contracts.ts +1328 -1320
- package/src/constants/index.ts +10 -10
- package/src/contracts.ts +174 -172
- package/src/curveUsd/index.ts +254 -254
- package/src/eulerV2/index.ts +324 -324
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1800 -1800
- package/src/helpers/aaveHelpers/index.ts +202 -191
- package/src/helpers/aaveV4Helpers/index.ts +128 -0
- package/src/helpers/compoundHelpers/index.ts +276 -283
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +229 -222
- package/src/helpers/fluidHelpers/index.ts +335 -326
- package/src/helpers/index.ts +11 -10
- package/src/helpers/liquityV2Helpers/index.ts +82 -82
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +52 -52
- package/src/helpers/morphoBlueHelpers/index.ts +405 -396
- package/src/helpers/sparkHelpers/index.ts +169 -158
- package/src/index.ts +51 -49
- package/src/liquity/index.ts +159 -159
- package/src/liquityV2/index.ts +703 -703
- package/src/llamaLend/index.ts +305 -305
- package/src/maker/index.ts +223 -223
- package/src/markets/aave/index.ts +118 -118
- package/src/markets/aave/marketAssets.ts +54 -54
- package/src/markets/aaveV4/index.ts +42 -0
- package/src/markets/compound/index.ts +243 -243
- package/src/markets/compound/marketsAssets.ts +97 -97
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2900 -2900
- package/src/markets/index.ts +26 -25
- package/src/markets/liquityV2/index.ts +102 -102
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +988 -988
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +12 -12
- package/src/moneymarket/moneymarketCommonService.ts +84 -85
- package/src/morphoBlue/index.ts +274 -274
- package/src/portfolio/index.ts +606 -586
- package/src/savings/index.ts +95 -95
- package/src/savings/makerDsr/index.ts +53 -53
- package/src/savings/makerDsr/options.ts +9 -9
- package/src/savings/morphoVaults/index.ts +80 -80
- package/src/savings/morphoVaults/options.ts +193 -193
- package/src/savings/skyOptions/index.ts +95 -95
- package/src/savings/skyOptions/options.ts +10 -10
- package/src/savings/sparkSavingsVaults/index.ts +60 -60
- package/src/savings/sparkSavingsVaults/options.ts +35 -35
- package/src/savings/yearnV3Vaults/index.ts +61 -61
- package/src/savings/yearnV3Vaults/options.ts +55 -55
- package/src/savings/yearnVaults/index.ts +73 -73
- package/src/savings/yearnVaults/options.ts +32 -32
- package/src/services/priceService.ts +278 -278
- package/src/services/utils.ts +115 -115
- package/src/services/viem.ts +57 -57
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +459 -459
- package/src/staking/eligibility.ts +53 -53
- package/src/staking/index.ts +1 -1
- package/src/staking/staking.ts +192 -192
- package/src/types/aave.ts +199 -198
- package/src/types/aaveV4.ts +153 -0
- package/src/types/claiming.ts +114 -114
- package/src/types/common.ts +115 -107
- package/src/types/compound.ts +145 -144
- package/src/types/curveUsd.ts +123 -123
- package/src/types/euler.ts +176 -175
- package/src/types/fluid.ts +485 -483
- package/src/types/index.ts +17 -15
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +128 -126
- package/src/types/llamaLend.ts +161 -159
- package/src/types/maker.ts +63 -63
- package/src/types/merit.ts +1 -1
- package/src/types/merkl.ts +70 -70
- package/src/types/morphoBlue.ts +202 -202
- package/src/types/portfolio.ts +64 -60
- package/src/types/savings/index.ts +23 -23
- package/src/types/savings/makerDsr.ts +13 -13
- package/src/types/savings/morphoVaults.ts +32 -32
- package/src/types/savings/sky.ts +14 -14
- package/src/types/savings/sparkSavingsVaults.ts +15 -15
- package/src/types/savings/yearnV3Vaults.ts +17 -17
- package/src/types/savings/yearnVaults.ts +14 -14
- package/src/types/spark.ts +135 -134
- package/src/umbrella/index.ts +69 -69
- package/src/umbrella/umbrellaUtils.ts +29 -29
package/esm/contracts.js
CHANGED
|
@@ -132,3 +132,4 @@ export const StkAAVEViem = createViemContractFromConfigFunc('StkAAVE');
|
|
|
132
132
|
export const YearnViewContractViem = createViemContractFromConfigFunc('YearnView');
|
|
133
133
|
export const MakerDsrContractViem = createViemContractFromConfigFunc('MakerDsr');
|
|
134
134
|
export const SkySavingsContractView = createViemContractFromConfigFunc('SkySavings');
|
|
135
|
+
export const AaveV4ViewContractViem = createViemContractFromConfigFunc('AaveV4View');
|
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?: import("../types").LeverageType;
|
|
134
134
|
leveragedAsset?: string;
|
|
135
135
|
liquidationPrice?: string;
|
|
136
|
-
|
|
136
|
+
currentVolatilePairRatio?: string;
|
|
137
137
|
minCollRatio?: string;
|
|
138
138
|
collLiquidationRatio?: string;
|
|
139
139
|
owner: string;
|
|
@@ -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?: import("../types").LeverageType;
|
|
165
165
|
leveragedAsset?: string;
|
|
166
166
|
liquidationPrice?: string;
|
|
167
|
-
|
|
167
|
+
currentVolatilePairRatio?: string;
|
|
168
168
|
minCollRatio?: string;
|
|
169
169
|
collLiquidationRatio?: string;
|
|
170
170
|
owner: string;
|
|
@@ -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?: import("../types").LeverageType;
|
|
196
196
|
leveragedAsset?: string;
|
|
197
197
|
liquidationPrice?: string;
|
|
198
|
-
|
|
198
|
+
currentVolatilePairRatio?: string;
|
|
199
199
|
minCollRatio?: string;
|
|
200
200
|
collLiquidationRatio?: string;
|
|
201
201
|
owner: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAssets, AaveVersions } from '../../types';
|
|
1
|
+
import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAsset, 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
|
-
}) =>
|
|
20
|
+
}) => AaveV3UsedAsset[];
|
|
21
21
|
export declare const aaveAnyGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => {
|
|
22
22
|
symbol: string;
|
|
23
23
|
canBeCollateral: boolean;
|
|
@@ -25,6 +25,7 @@ import { getNativeAssetFromWrapped, getWrappedNativeAssetFromUnwrapped } from '.
|
|
|
25
25
|
import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
26
26
|
import { calculateNetApy } from '../../staking';
|
|
27
27
|
import { borrowOperations } from '../../constants';
|
|
28
|
+
import { LeverageType, } from '../../types/common';
|
|
28
29
|
import { AaveLoanInfoV2ContractViem, AaveV3ViewContractViem } from '../../contracts';
|
|
29
30
|
import { getViemProvider } from '../../services/viem';
|
|
30
31
|
export const AAVE_V3_MARKETS = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi];
|
|
@@ -89,12 +90,22 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
89
90
|
payload.liquidationPrice = '';
|
|
90
91
|
if (leveragedType !== '') {
|
|
91
92
|
let assetPrice = data.assetsData[leveragedAsset].price;
|
|
92
|
-
if (leveragedType ===
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
94
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
95
|
+
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
96
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
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
|
+
}
|
|
96
107
|
}
|
|
97
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
108
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
98
109
|
}
|
|
99
110
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
100
111
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets } from '../../types';
|
|
2
|
+
import { LeverageType, NetworkNumber } from '../../types/common';
|
|
3
|
+
export declare const aaveV4GetCollateralFactor: (assetData: AaveV4ReserveAssetData, usedAssetData: AaveV4UsedReserveAsset, useUserCollateralFactor?: boolean) => number;
|
|
4
|
+
export declare const isLeveragedPosAaveV4: (usedAssets: AaveV4UsedReserveAssets, dustLimit?: number) => {
|
|
5
|
+
leveragedType: LeverageType;
|
|
6
|
+
leveragedAsset: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData, network, useUserCollateralFactor, }: {
|
|
9
|
+
usedAssets: AaveV4UsedReserveAssets;
|
|
10
|
+
assetsData: AaveV4AssetsData;
|
|
11
|
+
network: NetworkNumber;
|
|
12
|
+
useUserCollateralFactor?: boolean;
|
|
13
|
+
}) => AaveV4AggregatedPositionData;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS } from '../../moneymarket';
|
|
3
|
+
import { LeverageType } from '../../types/common';
|
|
4
|
+
export const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
|
|
5
|
+
export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
6
|
+
let borrowUnstable = 0;
|
|
7
|
+
let supplyStable = 0;
|
|
8
|
+
let borrowStable = 0;
|
|
9
|
+
let supplyUnstable = 0;
|
|
10
|
+
let longAsset = '';
|
|
11
|
+
let shortAsset = '';
|
|
12
|
+
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, reserveId, }) => {
|
|
13
|
+
const spokeAsset = `${symbol}-${reserveId}`;
|
|
14
|
+
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
15
|
+
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
16
|
+
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
17
|
+
supplyStable += 1;
|
|
18
|
+
if (isBorrowed && STABLE_ASSETS.includes(symbol))
|
|
19
|
+
borrowStable += 1;
|
|
20
|
+
if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
|
|
21
|
+
borrowUnstable += 1;
|
|
22
|
+
shortAsset = spokeAsset;
|
|
23
|
+
}
|
|
24
|
+
if (isSupplied && !STABLE_ASSETS.includes(symbol) && collateral) {
|
|
25
|
+
supplyUnstable += 1;
|
|
26
|
+
longAsset = spokeAsset;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
30
|
+
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
31
|
+
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
32
|
+
if (isLong) {
|
|
33
|
+
return {
|
|
34
|
+
leveragedType: LeverageType.Long,
|
|
35
|
+
leveragedAsset: longAsset,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (isShort) {
|
|
39
|
+
return {
|
|
40
|
+
leveragedType: LeverageType.Short,
|
|
41
|
+
leveragedAsset: shortAsset,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (isVolatilePair) {
|
|
45
|
+
return {
|
|
46
|
+
leveragedType: LeverageType.VolatilePair,
|
|
47
|
+
leveragedAsset: longAsset,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
leveragedType: LeverageType.None,
|
|
52
|
+
leveragedAsset: '',
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useUserCollateralFactor = false, }) => {
|
|
56
|
+
const payload = {};
|
|
57
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
58
|
+
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
59
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(aaveV4GetCollateralFactor(assetsData[`${symbol}-${reserveId}`], usedAssets[`${symbol}-${reserveId}`], useUserCollateralFactor)));
|
|
60
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
61
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
62
|
+
payload.drawnUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ drawnUsd }) => drawnUsd);
|
|
63
|
+
payload.premiumUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ premiumUsd }) => premiumUsd);
|
|
64
|
+
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
65
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
66
|
+
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
67
|
+
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
68
|
+
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
69
|
+
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
70
|
+
const { leveragedType, leveragedAsset } = isLeveragedPosAaveV4(usedAssets);
|
|
71
|
+
payload.leveragedType = leveragedType;
|
|
72
|
+
payload.leveragedAsset = leveragedAsset;
|
|
73
|
+
payload.liquidationPrice = '';
|
|
74
|
+
if (leveragedType !== '') {
|
|
75
|
+
const leveragedAssetData = assetsData[leveragedAsset];
|
|
76
|
+
let assetPrice = (leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0';
|
|
77
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
78
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
79
|
+
const borrowedAssetPrice = assetsData[`${borrowedAsset.symbol}-${borrowedAsset.reserveId}`].price;
|
|
80
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
81
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
82
|
+
if (isReverse) {
|
|
83
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
84
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
85
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
89
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
93
|
+
}
|
|
94
|
+
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
95
|
+
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
96
|
+
// payload.healthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
97
|
+
payload.minHealthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowLimitUsd).toDP(4).toString();
|
|
98
|
+
// TODO: Re-implement netApy calculation
|
|
99
|
+
// const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({
|
|
100
|
+
// usedAssets,
|
|
101
|
+
// assetsData,
|
|
102
|
+
// optionalData: { healthRatio: payload.healthRatio },
|
|
103
|
+
// });
|
|
104
|
+
payload.netApy = '0';
|
|
105
|
+
payload.incentiveUsd = '0';
|
|
106
|
+
payload.totalInterestUsd = '0';
|
|
107
|
+
return payload;
|
|
108
|
+
};
|
|
@@ -25,7 +25,7 @@ import { addToArrayIf, getEthAmountForDecimals, handleWbtcLegacy, wethToEth, } f
|
|
|
25
25
|
import { BLOCKS_IN_A_YEAR, borrowOperations, SECONDS_PER_YEAR } from '../../constants';
|
|
26
26
|
import { aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
27
27
|
import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../../staking';
|
|
28
|
-
import { IncentiveKind, NetworkNumber, } from '../../types/common';
|
|
28
|
+
import { IncentiveKind, LeverageType, NetworkNumber, } from '../../types/common';
|
|
29
29
|
import { CompoundLoanInfoContractViem, CompV3ViewContractViem } from '../../contracts';
|
|
30
30
|
import { getViemProvider } from '../../services/viem';
|
|
31
31
|
export const formatMarketData = (data, network, baseAssetPrice) => {
|
|
@@ -140,28 +140,25 @@ export const getCompoundV3AggregatedData = (_a) => {
|
|
|
140
140
|
if (leveragedType !== '') {
|
|
141
141
|
payload.leveragedAsset = leveragedAsset;
|
|
142
142
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
143
|
-
if (leveragedType ===
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
144
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
145
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
146
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
147
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
148
|
+
if (isReverse) {
|
|
149
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
150
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
151
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
155
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
156
|
+
}
|
|
146
157
|
}
|
|
147
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
158
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
148
159
|
}
|
|
149
160
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
150
161
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
151
|
-
// TO DO: handle strategies
|
|
152
|
-
/* const subscribedStrategies = rest.compoundStrategies
|
|
153
|
-
? compoundV3GetSubscribedStrategies({ selectedMarket, compoundStrategies: rest.compoundStrategies })
|
|
154
|
-
: []; */
|
|
155
|
-
// TODO possibly move to global helper, since every protocol has the same graphData?
|
|
156
|
-
// payload.ratioTooLow = false;
|
|
157
|
-
// payload.ratioTooHigh = false;
|
|
158
|
-
// TO DO: handle strategies
|
|
159
|
-
/* if (subscribedStrategies.length) {
|
|
160
|
-
subscribedStrategies.forEach(({ graphData }) => {
|
|
161
|
-
payload.ratioTooLow = parseFloat(payload.ratio) < parseFloat(graphData.minRatio);
|
|
162
|
-
payload.ratioTooHigh = graphData.boostEnabled && parseFloat(payload.ratio) > parseFloat(graphData.maxRatio);
|
|
163
|
-
});
|
|
164
|
-
} */
|
|
165
162
|
return payload;
|
|
166
163
|
};
|
|
167
164
|
export const getApyAfterValuesEstimationCompoundV2 = (actions, provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
1
|
+
import { EthAddress, EthereumProvider, LeverageType, NetworkNumber } from '../../types/common';
|
|
2
2
|
import { EulerV2AggregatedPositionData, EulerV2AssetsData, EulerV2UsedAssets } from '../../types';
|
|
3
3
|
export declare const isLeveragedPos: (usedAssets: EulerV2UsedAssets, dustLimit?: number) => {
|
|
4
|
-
leveragedType:
|
|
4
|
+
leveragedType: LeverageType;
|
|
5
5
|
leveragedAsset: string;
|
|
6
6
|
leveragedVault: string;
|
|
7
7
|
};
|
|
@@ -20,6 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
};
|
|
21
21
|
import Dec from 'decimal.js';
|
|
22
22
|
import { assetAmountInWei } from '@defisaver/tokens';
|
|
23
|
+
import { LeverageType, } from '../../types/common';
|
|
23
24
|
import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
|
|
24
25
|
import { calculateNetApy } from '../../staking';
|
|
25
26
|
import { EulerV2ViewContractViem } from '../../contracts';
|
|
@@ -53,31 +54,30 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
53
54
|
});
|
|
54
55
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
55
56
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
56
|
-
|
|
57
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
|
|
57
|
+
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
58
58
|
if (isLong) {
|
|
59
59
|
return {
|
|
60
|
-
leveragedType:
|
|
60
|
+
leveragedType: LeverageType.Long,
|
|
61
61
|
leveragedAsset: longAsset,
|
|
62
62
|
leveragedVault: leverageAssetVault,
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
if (isShort) {
|
|
66
66
|
return {
|
|
67
|
-
leveragedType:
|
|
67
|
+
leveragedType: LeverageType.Short,
|
|
68
68
|
leveragedAsset: shortAsset,
|
|
69
69
|
leveragedVault: leverageAssetVault,
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
if (
|
|
72
|
+
if (isVolatilePair) {
|
|
73
73
|
return {
|
|
74
|
-
leveragedType:
|
|
74
|
+
leveragedType: LeverageType.VolatilePair,
|
|
75
75
|
leveragedAsset: longAsset,
|
|
76
76
|
leveragedVault: leverageAssetVault,
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
return {
|
|
80
|
-
leveragedType:
|
|
80
|
+
leveragedType: LeverageType.None,
|
|
81
81
|
leveragedAsset: '',
|
|
82
82
|
leveragedVault: '',
|
|
83
83
|
};
|
|
@@ -106,14 +106,22 @@ 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
|
-
|
|
109
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
110
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
111
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.vaultAddress.toLowerCase()].price;
|
|
112
|
+
const leveragedAssetPrice = assetsData[leveragedVault.toLowerCase()].price;
|
|
113
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
114
|
+
if (isReverse) {
|
|
115
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
116
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
117
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
121
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
114
122
|
}
|
|
115
123
|
}
|
|
116
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
124
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
117
125
|
}
|
|
118
126
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
119
127
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -3,6 +3,7 @@ import { assetAmountInEth } from '@defisaver/tokens';
|
|
|
3
3
|
import { FluidVaultType, } from '../../types';
|
|
4
4
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
5
5
|
import { calculateNetApy } from '../../staking';
|
|
6
|
+
import { LeverageType } from '../../types/common';
|
|
6
7
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
7
8
|
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }) => {
|
|
8
9
|
const { borrowRate, supplyRate, incentiveBorrowRate, incentiveSupplyRate, tradingBorrowRate, tradingSupplyRate, } = marketData;
|
|
@@ -49,12 +50,22 @@ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, },
|
|
|
49
50
|
if (leveragedType !== '') {
|
|
50
51
|
payload.leveragedAsset = leveragedAsset;
|
|
51
52
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
52
|
-
if (leveragedType ===
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
54
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
55
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
56
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
57
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
58
|
+
if (isReverse) {
|
|
59
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
60
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
61
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
65
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
66
|
+
}
|
|
56
67
|
}
|
|
57
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
68
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
58
69
|
}
|
|
59
70
|
payload.minCollRatio = new Dec(payload.suppliedUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
60
71
|
payload.collLiquidationRatio = new Dec(payload.suppliedUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
package/esm/helpers/index.d.ts
CHANGED
package/esm/helpers/index.js
CHANGED
|
@@ -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,12 +45,22 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
45
45
|
if (leveragedType !== '') {
|
|
46
46
|
payload.leveragedAsset = leveragedAsset;
|
|
47
47
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
48
|
-
if (leveragedType ===
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
49
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
50
|
+
const borrowedAssetPrice = assetsData[borrowedAsset.symbol].price;
|
|
51
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
52
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
53
|
+
if (isReverse) {
|
|
54
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
55
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
56
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
60
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
61
|
+
}
|
|
52
62
|
}
|
|
53
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
63
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
54
64
|
}
|
|
55
65
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
56
66
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -118,73 +128,73 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, n
|
|
|
118
128
|
return { borrowRate, supplyRate };
|
|
119
129
|
});
|
|
120
130
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
121
|
-
const MARKET_QUERY = `
|
|
122
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
123
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
124
|
-
reallocatableLiquidityAssets
|
|
125
|
-
targetBorrowUtilization
|
|
126
|
-
loanAsset {
|
|
127
|
-
address
|
|
128
|
-
decimals
|
|
129
|
-
priceUsd
|
|
130
|
-
}
|
|
131
|
-
state {
|
|
132
|
-
liquidityAssets
|
|
133
|
-
borrowAssets
|
|
134
|
-
supplyAssets
|
|
135
|
-
}
|
|
136
|
-
publicAllocatorSharedLiquidity {
|
|
137
|
-
assets
|
|
138
|
-
vault {
|
|
139
|
-
address
|
|
140
|
-
name
|
|
141
|
-
}
|
|
142
|
-
allocationMarket {
|
|
143
|
-
uniqueKey
|
|
144
|
-
loanAsset {
|
|
145
|
-
address
|
|
146
|
-
}
|
|
147
|
-
collateralAsset {
|
|
148
|
-
address
|
|
149
|
-
}
|
|
150
|
-
irmAddress
|
|
151
|
-
oracle {
|
|
152
|
-
address
|
|
153
|
-
}
|
|
154
|
-
lltv
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
loanAsset {
|
|
158
|
-
address
|
|
159
|
-
}
|
|
160
|
-
collateralAsset {
|
|
161
|
-
address
|
|
162
|
-
}
|
|
163
|
-
oracle {
|
|
164
|
-
address
|
|
165
|
-
}
|
|
166
|
-
irmAddress
|
|
167
|
-
lltv
|
|
168
|
-
}
|
|
169
|
-
}
|
|
131
|
+
const MARKET_QUERY = `
|
|
132
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
133
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
134
|
+
reallocatableLiquidityAssets
|
|
135
|
+
targetBorrowUtilization
|
|
136
|
+
loanAsset {
|
|
137
|
+
address
|
|
138
|
+
decimals
|
|
139
|
+
priceUsd
|
|
140
|
+
}
|
|
141
|
+
state {
|
|
142
|
+
liquidityAssets
|
|
143
|
+
borrowAssets
|
|
144
|
+
supplyAssets
|
|
145
|
+
}
|
|
146
|
+
publicAllocatorSharedLiquidity {
|
|
147
|
+
assets
|
|
148
|
+
vault {
|
|
149
|
+
address
|
|
150
|
+
name
|
|
151
|
+
}
|
|
152
|
+
allocationMarket {
|
|
153
|
+
uniqueKey
|
|
154
|
+
loanAsset {
|
|
155
|
+
address
|
|
156
|
+
}
|
|
157
|
+
collateralAsset {
|
|
158
|
+
address
|
|
159
|
+
}
|
|
160
|
+
irmAddress
|
|
161
|
+
oracle {
|
|
162
|
+
address
|
|
163
|
+
}
|
|
164
|
+
lltv
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
loanAsset {
|
|
168
|
+
address
|
|
169
|
+
}
|
|
170
|
+
collateralAsset {
|
|
171
|
+
address
|
|
172
|
+
}
|
|
173
|
+
oracle {
|
|
174
|
+
address
|
|
175
|
+
}
|
|
176
|
+
irmAddress
|
|
177
|
+
lltv
|
|
178
|
+
}
|
|
179
|
+
}
|
|
170
180
|
`;
|
|
171
|
-
const REWARDS_QUERY = `
|
|
172
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
173
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
174
|
-
uniqueKey
|
|
175
|
-
state {
|
|
176
|
-
rewards {
|
|
177
|
-
amountPerSuppliedToken
|
|
178
|
-
supplyApr
|
|
179
|
-
amountPerBorrowedToken
|
|
180
|
-
borrowApr
|
|
181
|
-
asset {
|
|
182
|
-
address
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
181
|
+
const REWARDS_QUERY = `
|
|
182
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
183
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
184
|
+
uniqueKey
|
|
185
|
+
state {
|
|
186
|
+
rewards {
|
|
187
|
+
amountPerSuppliedToken
|
|
188
|
+
supplyApr
|
|
189
|
+
amountPerBorrowedToken
|
|
190
|
+
borrowApr
|
|
191
|
+
asset {
|
|
192
|
+
address
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
188
198
|
`;
|
|
189
199
|
/**
|
|
190
200
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAssets } from '../../types';
|
|
1
|
+
import { SparkAggregatedPositionData, SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAsset, SparkUsedAssets } from '../../types';
|
|
2
2
|
import { EthereumProvider } from '../../types/common';
|
|
3
3
|
export declare const sparkIsInIsolationMode: ({ usedAssets, assetsData }: {
|
|
4
4
|
usedAssets: SparkUsedAssets;
|
|
@@ -6,7 +6,7 @@ export declare const sparkIsInIsolationMode: ({ usedAssets, assetsData }: {
|
|
|
6
6
|
}) => boolean;
|
|
7
7
|
export declare const sparkGetCollSuppliedAssets: ({ usedAssets }: {
|
|
8
8
|
usedAssets: SparkUsedAssets;
|
|
9
|
-
}) =>
|
|
9
|
+
}) => SparkUsedAsset[];
|
|
10
10
|
export declare const sparkGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: SparkHelperCommon) => {
|
|
11
11
|
symbol: string;
|
|
12
12
|
canBeCollateral: boolean;
|
|
@@ -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,12 +81,22 @@ export const sparkGetAggregatedPositionData = (_a) => {
|
|
|
81
81
|
if (leveragedType !== '') {
|
|
82
82
|
payload.leveragedAsset = leveragedAsset;
|
|
83
83
|
let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
|
|
84
|
-
if (leveragedType ===
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
85
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
86
|
+
const borrowedAssetPrice = data.assetsData[borrowedAsset.symbol].price;
|
|
87
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
88
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
89
|
+
if (isReverse) {
|
|
90
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
91
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
92
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
96
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
97
|
+
}
|
|
88
98
|
}
|
|
89
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
99
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
90
100
|
}
|
|
91
101
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
92
102
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|