@defisaver/positions-sdk 2.1.51 → 2.1.52-aave-v4-1-dev
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/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 +15 -5
- 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 +16 -0
- package/cjs/markets/aaveV4/index.js +59 -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/types/aave.d.ts +3 -3
- package/cjs/types/aaveV4.d.ts +139 -0
- package/cjs/types/aaveV4.js +13 -0
- package/cjs/types/common.d.ts +8 -1
- package/cjs/types/common.js +10 -2
- 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 +16 -6
- 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 +16 -0
- package/esm/markets/aaveV4/index.js +47 -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/types/aave.d.ts +3 -3
- package/esm/types/aaveV4.d.ts +139 -0
- package/esm/types/aaveV4.js +10 -0
- package/esm/types/common.d.ts +8 -1
- package/esm/types/common.js +9 -1
- 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 +1 -1
- package/src/aaveV4/index.ts +176 -0
- package/src/config/contracts.ts +8 -0
- package/src/contracts.ts +3 -1
- package/src/helpers/aaveHelpers/index.ts +18 -7
- package/src/helpers/aaveV4Helpers/index.ts +128 -0
- package/src/helpers/compoundHelpers/index.ts +16 -23
- package/src/helpers/eulerHelpers/index.ts +21 -14
- package/src/helpers/fluidHelpers/index.ts +15 -6
- package/src/helpers/index.ts +1 -0
- package/src/helpers/morphoBlueHelpers/index.ts +15 -6
- package/src/helpers/sparkHelpers/index.ts +18 -7
- package/src/index.ts +2 -0
- package/src/markets/aaveV4/index.ts +68 -0
- package/src/markets/index.ts +6 -1
- package/src/moneymarket/moneymarketCommonService.ts +10 -11
- package/src/portfolio/index.ts +20 -0
- package/src/types/aave.ts +3 -2
- package/src/types/aaveV4.ts +155 -0
- package/src/types/common.ts +9 -1
- package/src/types/compound.ts +3 -2
- package/src/types/curveUsd.ts +2 -2
- package/src/types/euler.ts +3 -2
- package/src/types/fluid.ts +5 -3
- package/src/types/index.ts +3 -1
- package/src/types/liquityV2.ts +5 -3
- package/src/types/llamaLend.ts +4 -2
- package/src/types/morphoBlue.ts +5 -5
- package/src/types/portfolio.ts +4 -0
- package/src/types/spark.ts +3 -2
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '../../types';
|
|
10
10
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
11
11
|
import { calculateNetApy } from '../../staking';
|
|
12
|
-
import { MMAssetsData } from '../../types/common';
|
|
12
|
+
import { LeverageType, MMAssetsData } from '../../types/common';
|
|
13
13
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
14
14
|
|
|
15
15
|
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }: { marketData: InnerFluidMarketData, suppliedUsd: string, borrowedUsd: string }) => {
|
|
@@ -84,12 +84,21 @@ borrowShares?: string,
|
|
|
84
84
|
if (leveragedType !== '') {
|
|
85
85
|
payload.leveragedAsset = leveragedAsset;
|
|
86
86
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
87
|
-
if (leveragedType ===
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
88
|
+
const borrowedAsset = (Object.values(usedAssets) as FluidUsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
89
|
+
const borrowedAssetPrice = assetsData[borrowedAsset!.symbol].price;
|
|
90
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
91
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
92
|
+
if (isReverse) {
|
|
93
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
94
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
95
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
96
|
+
} else {
|
|
97
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
98
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
101
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
payload.minCollRatio = new Dec(payload.suppliedUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
package/src/helpers/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from '../../moneymarket';
|
|
6
6
|
import { calculateNetApy } from '../../staking';
|
|
7
7
|
import {
|
|
8
|
-
EthereumProvider, MMAssetsData, MMUsedAssets, NetworkNumber,
|
|
8
|
+
EthereumProvider, LeverageType, MMAssetsData, MMUsedAsset, MMUsedAssets, NetworkNumber,
|
|
9
9
|
} from '../../types/common';
|
|
10
10
|
import {
|
|
11
11
|
MorphoBlueAggregatedPositionData, MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo,
|
|
@@ -58,12 +58,21 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
58
58
|
if (leveragedType !== '') {
|
|
59
59
|
payload.leveragedAsset = leveragedAsset;
|
|
60
60
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
61
|
-
if (leveragedType ===
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
62
|
+
const borrowedAsset = (Object.values(usedAssets) as MMUsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
63
|
+
const borrowedAssetPrice = assetsData[borrowedAsset!.symbol].price;
|
|
64
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
65
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
66
|
+
if (isReverse) {
|
|
67
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
68
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
69
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
70
|
+
} else {
|
|
71
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
72
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
75
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
67
76
|
}
|
|
68
77
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
69
78
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
@@ -5,12 +5,14 @@ import {
|
|
|
5
5
|
} from '../../moneymarket';
|
|
6
6
|
import {
|
|
7
7
|
SparkAggregatedPositionData,
|
|
8
|
-
SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAssets,
|
|
8
|
+
SparkAssetsData, SparkHelperCommon, SparkMarketData, SparkUsedAsset, SparkUsedAssets,
|
|
9
9
|
} from '../../types';
|
|
10
10
|
import { calculateNetApy } from '../../staking';
|
|
11
11
|
import { ethToWeth, getNativeAssetFromWrapped, wethToEth } from '../../services/utils';
|
|
12
12
|
import { SparkViewContractViem } from '../../contracts';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
EthAddress, EthereumProvider, LeverageType, NetworkNumber,
|
|
15
|
+
} from '../../types/common';
|
|
14
16
|
import { borrowOperations } from '../../constants';
|
|
15
17
|
import { getViemProvider } from '../../services/viem';
|
|
16
18
|
|
|
@@ -105,12 +107,21 @@ export const sparkGetAggregatedPositionData = ({
|
|
|
105
107
|
if (leveragedType !== '') {
|
|
106
108
|
payload.leveragedAsset = leveragedAsset;
|
|
107
109
|
let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
|
|
108
|
-
if (leveragedType ===
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
111
|
+
const borrowedAsset = (Object.values(usedAssets) as SparkUsedAsset[]).find(({ borrowedUsd }: { borrowedUsd: string }) => +borrowedUsd > 0);
|
|
112
|
+
const borrowedAssetPrice = data.assetsData[borrowedAsset!.symbol].price;
|
|
113
|
+
const leveragedAssetPrice = data.assetsData[leveragedAsset].price;
|
|
114
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
115
|
+
if (isReverse) {
|
|
116
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
117
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
118
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
119
|
+
} else {
|
|
120
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
121
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
122
|
+
}
|
|
112
123
|
}
|
|
113
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
124
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
114
125
|
}
|
|
115
126
|
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
116
127
|
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import './setup';
|
|
2
2
|
|
|
3
3
|
import * as fluid from './fluid';
|
|
4
|
+
import * as aaveV4 from './aaveV4';
|
|
4
5
|
import * as aaveV3 from './aaveV3';
|
|
5
6
|
import * as aaveV2 from './aaveV2';
|
|
6
7
|
import * as compoundV3 from './compoundV3';
|
|
@@ -27,6 +28,7 @@ export * from './types';
|
|
|
27
28
|
export {
|
|
28
29
|
aaveV2,
|
|
29
30
|
aaveV3,
|
|
31
|
+
aaveV4,
|
|
30
32
|
compoundV2,
|
|
31
33
|
compoundV3,
|
|
32
34
|
spark,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AaveV4HubInfo,
|
|
3
|
+
AaveV4HubsType,
|
|
4
|
+
AaveV4SpokeInfo,
|
|
5
|
+
AaveV4SpokesType,
|
|
6
|
+
NetworkNumber,
|
|
7
|
+
} from '../../types';
|
|
8
|
+
|
|
9
|
+
// HUBS
|
|
10
|
+
|
|
11
|
+
export const AAVE_V4_CORE_HUB = (networkId: NetworkNumber): AaveV4HubInfo => ({
|
|
12
|
+
chainIds: [NetworkNumber.Eth],
|
|
13
|
+
label: 'Core Hub',
|
|
14
|
+
value: AaveV4HubsType.AaveV4CoreHub,
|
|
15
|
+
address: '0xaD905aD5EA5B98cD50AE40Cfe368344686a21366',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const AAVE_V4_YIELD_SEEKING_HUB = (networkId: NetworkNumber): AaveV4HubInfo => ({
|
|
19
|
+
chainIds: [NetworkNumber.Eth],
|
|
20
|
+
label: 'Yield Seeking Hub',
|
|
21
|
+
value: AaveV4HubsType.AaveV4YieldSeekingHub,
|
|
22
|
+
address: '0x86F37ba3b480c5fE22A7eb1ba2B2D49c94089FBB',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const AaveV4Hubs = (networkId: NetworkNumber) => ({
|
|
26
|
+
[AaveV4HubsType.AaveV4CoreHub]: AAVE_V4_CORE_HUB(networkId),
|
|
27
|
+
[AaveV4HubsType.AaveV4YieldSeekingHub]: AAVE_V4_YIELD_SEEKING_HUB(networkId),
|
|
28
|
+
}) as const;
|
|
29
|
+
|
|
30
|
+
export const getAaveV4HubTypeInfo = (type: AaveV4HubsType, network?: NetworkNumber) => ({ ...AaveV4Hubs(network ?? NetworkNumber.Eth) }[type]);
|
|
31
|
+
|
|
32
|
+
export const getAaveV4HubByAddress = (networkId: NetworkNumber, address: string): AaveV4HubInfo | undefined => Object.values(AaveV4Hubs(networkId)).find(
|
|
33
|
+
hub => hub.address.toLowerCase() === address.toLowerCase(),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// SPOKES
|
|
37
|
+
|
|
38
|
+
export const AAVE_V4_CORE_SPOKE = (networkId: NetworkNumber): AaveV4SpokeInfo => ({
|
|
39
|
+
chainIds: [NetworkNumber.Eth],
|
|
40
|
+
label: 'Core Spoke',
|
|
41
|
+
value: AaveV4SpokesType.AaveV4CoreSpoke,
|
|
42
|
+
url: 'core',
|
|
43
|
+
address: '0xBa97c5E52cd5BC3D7950Ae70779F8FfE92d40CdC',
|
|
44
|
+
hubs: [
|
|
45
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const AAVE_V4_YIELD_SEEKING_SPOKE = (networkId: NetworkNumber): AaveV4SpokeInfo => ({
|
|
50
|
+
chainIds: [NetworkNumber.Eth],
|
|
51
|
+
label: 'Yield Seeking Spoke',
|
|
52
|
+
value: AaveV4SpokesType.AaveV4YieldSeekingSpoke,
|
|
53
|
+
url: 'yield-seeking',
|
|
54
|
+
address: '0x2559e4e04f2ca7180e5f20c2872d22ec89601b56',
|
|
55
|
+
hubs: [
|
|
56
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
57
|
+
AAVE_V4_YIELD_SEEKING_HUB(NetworkNumber.Eth).address,
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const AaveV4Spokes = (networkId: NetworkNumber) => ({
|
|
62
|
+
[AaveV4SpokesType.AaveV4CoreSpoke]: AAVE_V4_CORE_SPOKE(networkId),
|
|
63
|
+
[AaveV4SpokesType.AaveV4YieldSeekingSpoke]: AAVE_V4_YIELD_SEEKING_SPOKE(networkId),
|
|
64
|
+
}) as const;
|
|
65
|
+
|
|
66
|
+
export const getAaveV4SpokeTypeInfo = (type: AaveV4SpokesType, network?: NetworkNumber) => ({ ...AaveV4Spokes(network ?? NetworkNumber.Eth) }[type]);
|
|
67
|
+
|
|
68
|
+
|
package/src/markets/index.ts
CHANGED
|
@@ -21,5 +21,10 @@ export { LlamaLendMarkets } from './llamaLend';
|
|
|
21
21
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
22
22
|
export { EulerV2Markets } from './euler';
|
|
23
23
|
export {
|
|
24
|
-
FluidMarkets,
|
|
24
|
+
FluidMarkets,
|
|
25
|
+
getFluidVersionsDataForNetwork,
|
|
26
|
+
getFluidMarketInfoById,
|
|
27
|
+
getFTokenAddress,
|
|
28
|
+
getFluidMarketInfoByAddress,
|
|
25
29
|
} from './fluid';
|
|
30
|
+
export { AaveV4Spokes } from './aaveV4';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { BLOCKS_IN_A_YEAR } from '../constants';
|
|
3
|
-
import { MMUsedAssets } from '../types/common';
|
|
3
|
+
import { LeverageType, MMUsedAssets } from '../types/common';
|
|
4
4
|
|
|
5
5
|
export const getAssetsTotal = (assets: object, filter: any, transform: any) => (Object.values(assets) as any)
|
|
6
6
|
.filter(filter)
|
|
@@ -11,9 +11,9 @@ export const getAssetsTotal = (assets: object, filter: any, transform: any) => (
|
|
|
11
11
|
export const calcLongLiqPrice = (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => new Dec(assetPrice).mul(borrowedUsd).div(borrowLimitUsd).toString();
|
|
12
12
|
export const calcShortLiqPrice = (assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => new Dec(assetPrice).div(borrowedUsd).mul(borrowLimitUsd).toString();
|
|
13
13
|
|
|
14
|
-
export const calcLeverageLiqPrice = (leverageType:
|
|
15
|
-
if (leverageType ===
|
|
16
|
-
if (leverageType ===
|
|
14
|
+
export const calcLeverageLiqPrice = (leverageType: LeverageType, assetPrice: string, borrowedUsd: string, borrowLimitUsd: string) => {
|
|
15
|
+
if (leverageType === LeverageType.Short || leverageType === LeverageType.VolatilePairReverse) return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
16
|
+
if (leverageType === LeverageType.Long || leverageType === LeverageType.VolatilePair) return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
17
17
|
console.error('invalid leverageType', leverageType);
|
|
18
18
|
return '0';
|
|
19
19
|
};
|
|
@@ -52,28 +52,27 @@ export const isLeveragedPos = (usedAssets: MMUsedAssets, dustLimit = 5) => {
|
|
|
52
52
|
});
|
|
53
53
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
54
54
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
55
|
-
|
|
56
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH', 'ezETH', 'weETH'].includes(longAsset);
|
|
55
|
+
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
57
56
|
if (isLong) {
|
|
58
57
|
return {
|
|
59
|
-
leveragedType:
|
|
58
|
+
leveragedType: LeverageType.Long,
|
|
60
59
|
leveragedAsset: longAsset,
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
62
|
if (isShort) {
|
|
64
63
|
return {
|
|
65
|
-
leveragedType:
|
|
64
|
+
leveragedType: LeverageType.Short,
|
|
66
65
|
leveragedAsset: shortAsset,
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
if (
|
|
68
|
+
if (isVolatilePair) {
|
|
70
69
|
return {
|
|
71
|
-
leveragedType:
|
|
70
|
+
leveragedType: LeverageType.VolatilePair,
|
|
72
71
|
leveragedAsset: longAsset,
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
74
|
return {
|
|
76
|
-
leveragedType:
|
|
75
|
+
leveragedType: LeverageType.None,
|
|
77
76
|
leveragedAsset: '',
|
|
78
77
|
};
|
|
79
78
|
};
|
package/src/portfolio/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
3
|
import {
|
|
4
4
|
AaveMarkets,
|
|
5
|
+
AaveV4Spokes,
|
|
5
6
|
CompoundMarkets,
|
|
6
7
|
CrvUsdMarkets,
|
|
7
8
|
EulerV2Markets,
|
|
@@ -14,6 +15,7 @@ import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } fr
|
|
|
14
15
|
import {
|
|
15
16
|
AaveV2MarketData,
|
|
16
17
|
AaveV3MarketData,
|
|
18
|
+
AaveV4SpokeData,
|
|
17
19
|
AaveVersions,
|
|
18
20
|
CdpInfo,
|
|
19
21
|
CompoundV2MarketsData,
|
|
@@ -49,6 +51,7 @@ import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
|
49
51
|
import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
|
|
50
52
|
import { getKingRewards } from '../claiming/king';
|
|
51
53
|
import { fetchEthenaAirdropRewards } from '../claiming/ethena';
|
|
54
|
+
import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
|
|
52
55
|
|
|
53
56
|
export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
|
|
54
57
|
positions: PortfolioPositionsData;
|
|
@@ -71,6 +74,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
71
74
|
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
72
75
|
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
73
76
|
const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
|
|
77
|
+
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
74
78
|
|
|
75
79
|
const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 500_000 : 2_500_000 } } }];
|
|
76
80
|
const client = getViemProvider(provider, ...args);
|
|
@@ -87,6 +91,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
87
91
|
const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
|
|
88
92
|
const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
|
|
89
93
|
const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
|
|
94
|
+
const aaveV4SpokesData: Record<string, AaveV4SpokeData> = {};
|
|
90
95
|
|
|
91
96
|
const markets = {
|
|
92
97
|
morphoMarketsData,
|
|
@@ -99,6 +104,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
99
104
|
crvUsdMarketsData,
|
|
100
105
|
llamaLendMarketsData,
|
|
101
106
|
liquityV2MarketsData,
|
|
107
|
+
aaveV4SpokesData,
|
|
102
108
|
};
|
|
103
109
|
|
|
104
110
|
const positions: PortfolioPositionsData = {};
|
|
@@ -109,6 +115,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
109
115
|
for (const address of allAddresses) {
|
|
110
116
|
positions[address.toLowerCase() as EthAddress] = {
|
|
111
117
|
aaveV3: {},
|
|
118
|
+
aaveV4: {},
|
|
112
119
|
morphoBlue: {},
|
|
113
120
|
compoundV3: {},
|
|
114
121
|
spark: {},
|
|
@@ -177,6 +184,10 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
177
184
|
const marketData = await _getAaveV3MarketData(client, network, market);
|
|
178
185
|
aaveV3MarketsData[market.value] = marketData;
|
|
179
186
|
}),
|
|
187
|
+
...aaveV4Spokes.map(async (spoke) => {
|
|
188
|
+
const spokeData = await _getAaveV4SpokeData(client, network, spoke);
|
|
189
|
+
aaveV4SpokesData[spoke.value] = spokeData;
|
|
190
|
+
}),
|
|
180
191
|
...aaveV2Markets.map(async (market) => {
|
|
181
192
|
const marketData = await _getAaveV2MarketsData(client, network, market);
|
|
182
193
|
aaveV2MarketsData[market.value] = marketData;
|
|
@@ -429,6 +440,15 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
429
440
|
positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
430
441
|
}
|
|
431
442
|
})).flat(),
|
|
443
|
+
...aaveV4Spokes.map((spoke) => allAddresses.map(async (address) => {
|
|
444
|
+
try {
|
|
445
|
+
const accData = await _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
|
|
446
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
|
|
447
|
+
} catch (error) {
|
|
448
|
+
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
449
|
+
positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
450
|
+
}
|
|
451
|
+
})).flat(),
|
|
432
452
|
...morphoMarkets.map((market) => addresses.map(async (address) => {
|
|
433
453
|
try {
|
|
434
454
|
const [accDataPromise, earnDataPromise] = await Promise.allSettled([
|
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,14 +178,14 @@ export interface AaveV3AggregatedPositionData {
|
|
|
177
178
|
totalInterestUsd: string,
|
|
178
179
|
liqRatio: string,
|
|
179
180
|
liqPercent: string,
|
|
180
|
-
leveragedType:
|
|
181
|
+
leveragedType: LeverageType,
|
|
181
182
|
leveragedAsset?: string,
|
|
182
|
-
leveragedLsdAssetRatio?: string,
|
|
183
183
|
liquidationPrice?: string,
|
|
184
184
|
minCollRatio?: string,
|
|
185
185
|
collLiquidationRatio?: string,
|
|
186
186
|
healthRatio?: string,
|
|
187
187
|
minHealthRatio?: string,
|
|
188
|
+
currentVolatilePairRatio?: string,
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
export interface AaveHelperCommon {
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EthAddress, IncentiveData, LeverageType, NetworkNumber,
|
|
3
|
+
} from './common';
|
|
4
|
+
|
|
5
|
+
export enum AaveV4SpokesType {
|
|
6
|
+
AaveV4CoreSpoke = 'aave_v4_core_spoke',
|
|
7
|
+
AaveV4YieldSeekingSpoke = 'aave_v4_yield_seeking_spoke',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum AaveV4HubsType {
|
|
11
|
+
AaveV4CoreHub = 'aave_v4_core_hub',
|
|
12
|
+
AaveV4YieldSeekingHub = 'aave_v4_yield_seeking_hub',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AaveV4SpokeInfo {
|
|
16
|
+
chainIds: NetworkNumber[],
|
|
17
|
+
label: string,
|
|
18
|
+
value: AaveV4SpokesType,
|
|
19
|
+
url: string,
|
|
20
|
+
address: EthAddress,
|
|
21
|
+
hubs: EthAddress[],
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AaveV4HubInfo {
|
|
25
|
+
chainIds: NetworkNumber[],
|
|
26
|
+
label: string,
|
|
27
|
+
value: AaveV4HubsType,
|
|
28
|
+
address: EthAddress,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AaveV4HubAssetOnChainData {
|
|
32
|
+
assetId: number,
|
|
33
|
+
drawnRate: bigint,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AaveV4HubOnChainData {
|
|
37
|
+
assets: Record<number, AaveV4HubAssetOnChainData>,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AaveV4ReserveAssetOnChain {
|
|
41
|
+
underlying: EthAddress,
|
|
42
|
+
hub: EthAddress,
|
|
43
|
+
assetId: number,
|
|
44
|
+
decimals: number,
|
|
45
|
+
paused: boolean,
|
|
46
|
+
frozen: boolean,
|
|
47
|
+
borrowable: boolean,
|
|
48
|
+
collateralRisk: number,
|
|
49
|
+
collateralFactor: number,
|
|
50
|
+
maxLiquidationBonus: number,
|
|
51
|
+
liquidationFee: number,
|
|
52
|
+
price: bigint,
|
|
53
|
+
totalSupplied: bigint,
|
|
54
|
+
totalDrawn: bigint,
|
|
55
|
+
totalPremium: bigint,
|
|
56
|
+
totalDebt: bigint,
|
|
57
|
+
supplyCap: bigint,
|
|
58
|
+
borrowCap: bigint,
|
|
59
|
+
deficitRay: bigint,
|
|
60
|
+
spokeActive: boolean,
|
|
61
|
+
spokePaused: boolean
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface AaveV4ReserveAssetData {
|
|
65
|
+
symbol: string,
|
|
66
|
+
underlying: EthAddress,
|
|
67
|
+
hub: EthAddress,
|
|
68
|
+
hubName: string,
|
|
69
|
+
assetId: number,
|
|
70
|
+
reserveId: number,
|
|
71
|
+
paused: boolean,
|
|
72
|
+
frozen: boolean,
|
|
73
|
+
borrowable: boolean,
|
|
74
|
+
collateralRisk: number,
|
|
75
|
+
collateralFactor: number,
|
|
76
|
+
liquidationFee: number,
|
|
77
|
+
price: string,
|
|
78
|
+
totalSupplied: string,
|
|
79
|
+
totalDrawn: string,
|
|
80
|
+
totalPremium: string,
|
|
81
|
+
totalDebt: string,
|
|
82
|
+
supplyCap: string,
|
|
83
|
+
borrowCap: string,
|
|
84
|
+
spokeActive: boolean,
|
|
85
|
+
spokePaused: boolean,
|
|
86
|
+
drawnRate: string,
|
|
87
|
+
supplyRate: string,
|
|
88
|
+
supplyIncentives: IncentiveData[];
|
|
89
|
+
borrowIncentives: IncentiveData[];
|
|
90
|
+
canBeBorrowed: boolean;
|
|
91
|
+
canBeSupplied: boolean;
|
|
92
|
+
canBeWithdrawn: boolean;
|
|
93
|
+
canBePayBacked: boolean;
|
|
94
|
+
utilization: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
|
|
98
|
+
|
|
99
|
+
export interface AaveV4SpokeData {
|
|
100
|
+
assetsData: AaveV4AssetsData,
|
|
101
|
+
oracle: EthAddress,
|
|
102
|
+
oracleDecimals: number,
|
|
103
|
+
address: EthAddress,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface AaveV4UsedReserveAsset {
|
|
107
|
+
symbol: string,
|
|
108
|
+
hubName: string,
|
|
109
|
+
assetId: number,
|
|
110
|
+
reserveId: number,
|
|
111
|
+
supplied: string,
|
|
112
|
+
suppliedUsd: string,
|
|
113
|
+
drawn: string,
|
|
114
|
+
drawnUsd: string,
|
|
115
|
+
premium: string,
|
|
116
|
+
premiumUsd: string,
|
|
117
|
+
borrowed: string,
|
|
118
|
+
borrowedUsd: string,
|
|
119
|
+
isSupplied: boolean,
|
|
120
|
+
isBorrowed: boolean,
|
|
121
|
+
collateral: boolean,
|
|
122
|
+
collateralFactor: number,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface AaveV4AggregatedPositionData {
|
|
126
|
+
suppliedUsd: string,
|
|
127
|
+
suppliedCollateralUsd: string,
|
|
128
|
+
borrowLimitUsd: string,
|
|
129
|
+
liquidationLimitUsd: string,
|
|
130
|
+
borrowedUsd: string,
|
|
131
|
+
drawnUsd: string,
|
|
132
|
+
premiumUsd: string,
|
|
133
|
+
leftToBorrowUsd: string,
|
|
134
|
+
ratio: string,
|
|
135
|
+
collRatio: string,
|
|
136
|
+
liqRatio: string,
|
|
137
|
+
liqPercent: string,
|
|
138
|
+
leveragedType: LeverageType,
|
|
139
|
+
leveragedAsset: string,
|
|
140
|
+
liquidationPrice: string,
|
|
141
|
+
minCollRatio: string,
|
|
142
|
+
collLiquidationRatio: string,
|
|
143
|
+
minHealthRatio: string,
|
|
144
|
+
netApy: string,
|
|
145
|
+
incentiveUsd: string,
|
|
146
|
+
totalInterestUsd: string,
|
|
147
|
+
currentVolatilePairRatio?: string,
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
|
|
151
|
+
|
|
152
|
+
export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
|
|
153
|
+
usedAssets: AaveV4UsedReserveAssets,
|
|
154
|
+
healthFactor: string,
|
|
155
|
+
}
|
package/src/types/common.ts
CHANGED
|
@@ -4,12 +4,20 @@ export enum IncentiveKind {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export enum IncentiveEligibilityId {
|
|
7
|
-
AaveV3EthenaLiquidLeverage = '
|
|
7
|
+
AaveV3EthenaLiquidLeverage = '0x8014e0076e5393e62c49a7134070d8fccc922e46BORROW_BL',
|
|
8
8
|
AaveV3ArbitrumEthSupply = '0x5d16261c6715a653248269861bbacf68a9774cde',
|
|
9
9
|
AaveV3ArbitrumETHLSBorrow = '0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351',
|
|
10
10
|
AaveV3EthenaLiquidLeveragePlasma = '0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL',
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export enum LeverageType {
|
|
14
|
+
Long = 'long',
|
|
15
|
+
Short = 'short',
|
|
16
|
+
VolatilePair = 'volatile-pair',
|
|
17
|
+
VolatilePairReverse = 'volatile-pair-reverse',
|
|
18
|
+
None = '',
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
export interface IncentiveData {
|
|
14
22
|
token: string,
|
|
15
23
|
apy: string,
|
package/src/types/compound.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EthAddress,
|
|
3
|
+
LeverageType,
|
|
3
4
|
MMAssetData,
|
|
4
5
|
MMPositionData,
|
|
5
6
|
MMUsedAsset,
|
|
@@ -113,9 +114,9 @@ export interface CompoundAggregatedPositionData {
|
|
|
113
114
|
totalInterestUsd: string,
|
|
114
115
|
liqRatio: string,
|
|
115
116
|
liqPercent: string,
|
|
116
|
-
leveragedType:
|
|
117
|
+
leveragedType: LeverageType,
|
|
117
118
|
leveragedAsset?: string,
|
|
118
|
-
|
|
119
|
+
currentVolatilePairRatio?: string,
|
|
119
120
|
liquidationPrice?: string,
|
|
120
121
|
minRatio: string,
|
|
121
122
|
debtTooLow: boolean,
|
package/src/types/curveUsd.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EthAddress, NetworkNumber } from './common';
|
|
1
|
+
import { EthAddress, LeverageType, NetworkNumber } from './common';
|
|
2
2
|
|
|
3
3
|
export enum CrvUSDVersions {
|
|
4
4
|
'crvUSDwstETH' = 'wstETH',
|
|
@@ -78,7 +78,7 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
78
78
|
borrowLimitUsd: string,
|
|
79
79
|
minAllowedRatio: number,
|
|
80
80
|
collFactor: string,
|
|
81
|
-
leveragedType:
|
|
81
|
+
leveragedType: LeverageType,
|
|
82
82
|
leveragedAsset?: string,
|
|
83
83
|
liquidationPrice?: string,
|
|
84
84
|
}
|
package/src/types/euler.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EthAddress,
|
|
3
3
|
IncentiveData,
|
|
4
|
+
LeverageType,
|
|
4
5
|
MMPositionData, NetworkNumber,
|
|
5
6
|
} from './common';
|
|
6
7
|
|
|
@@ -165,9 +166,9 @@ export interface EulerV2AggregatedPositionData {
|
|
|
165
166
|
totalInterestUsd: string,
|
|
166
167
|
liqRatio: string,
|
|
167
168
|
liqPercent: string,
|
|
168
|
-
leveragedType:
|
|
169
|
+
leveragedType: LeverageType,
|
|
169
170
|
leveragedAsset?: string,
|
|
170
|
-
|
|
171
|
+
currentVolatilePairRatio?: string,
|
|
171
172
|
liquidationPrice?: string,
|
|
172
173
|
minRatio: string,
|
|
173
174
|
minDebt: string,
|
package/src/types/fluid.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EthAddress, IncentiveData, LeverageType, NetworkNumber,
|
|
3
|
+
} from './common';
|
|
2
4
|
|
|
3
5
|
export interface FluidMarketInfo {
|
|
4
6
|
chainIds: number[]
|
|
@@ -342,10 +344,10 @@ export interface FluidAggregatedVaultData {
|
|
|
342
344
|
collRatio: string,
|
|
343
345
|
minRatio: string
|
|
344
346
|
totalInterestUsd: string,
|
|
345
|
-
leveragedType?:
|
|
347
|
+
leveragedType?: LeverageType,
|
|
346
348
|
leveragedAsset?: string,
|
|
347
349
|
liquidationPrice?: string,
|
|
348
|
-
|
|
350
|
+
currentVolatilePairRatio?: string,
|
|
349
351
|
minCollRatio?: string,
|
|
350
352
|
collLiquidationRatio?: string,
|
|
351
353
|
}
|
package/src/types/index.ts
CHANGED