@defisaver/positions-sdk 2.1.79 → 2.1.80
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 +245 -0
- package/cjs/aaveV4/lend.d.ts +55 -0
- package/cjs/aaveV4/lend.js +131 -0
- package/cjs/config/contracts.d.ts +1551 -0
- package/cjs/config/contracts.js +9 -0
- package/cjs/contracts.d.ts +32741 -0
- package/cjs/contracts.js +2 -1
- package/cjs/eulerV2/index.d.ts +1 -2
- package/cjs/eulerV2/index.js +4 -5
- package/cjs/helpers/aaveV4Helpers/index.d.ts +25 -0
- package/cjs/helpers/aaveV4Helpers/index.js +233 -0
- package/cjs/helpers/index.d.ts +1 -0
- package/cjs/helpers/index.js +2 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/markets/aaveV4/index.d.ts +34 -0
- package/cjs/markets/aaveV4/index.js +182 -0
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/portfolio/index.js +20 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +3 -3
- package/cjs/types/aaveV4.d.ts +159 -0
- package/cjs/types/aaveV4.js +22 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/portfolio.d.ts +4 -0
- package/esm/aaveV4/index.d.ts +7 -0
- package/esm/aaveV4/index.js +202 -0
- package/esm/aaveV4/lend.d.ts +55 -0
- package/esm/aaveV4/lend.js +124 -0
- package/esm/config/contracts.d.ts +1551 -0
- package/esm/config/contracts.js +8 -0
- package/esm/contracts.d.ts +32741 -0
- package/esm/contracts.js +1 -0
- package/esm/eulerV2/index.d.ts +1 -2
- package/esm/eulerV2/index.js +5 -6
- package/esm/helpers/aaveV4Helpers/index.d.ts +25 -0
- package/esm/helpers/aaveV4Helpers/index.js +221 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/markets/aaveV4/index.d.ts +34 -0
- package/esm/markets/aaveV4/index.js +161 -0
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/portfolio/index.js +21 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +1 -1
- package/esm/types/aaveV4.d.ts +159 -0
- package/esm/types/aaveV4.js +19 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/portfolio.d.ts +4 -0
- package/package.json +2 -2
- package/src/aaveV4/index.ts +223 -0
- package/src/aaveV4/lend.ts +185 -0
- package/src/config/contracts.ts +8 -0
- package/src/contracts.ts +2 -0
- package/src/eulerV2/index.ts +12 -7
- package/src/helpers/aaveV4Helpers/index.ts +291 -0
- package/src/helpers/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/markets/aaveV4/index.ts +191 -0
- package/src/markets/index.ts +6 -1
- package/src/moneymarket/moneymarketCommonService.ts +1 -1
- package/src/portfolio/index.ts +20 -0
- package/src/services/utils.ts +1 -1
- package/src/types/aaveV4.ts +175 -0
- package/src/types/index.ts +2 -1
- package/src/types/portfolio.ts +4 -0
package/esm/contracts.js
CHANGED
|
@@ -140,3 +140,4 @@ export const StkAAVEViem = createViemContractFromConfigFunc('StkAAVE');
|
|
|
140
140
|
export const YearnViewContractViem = createViemContractFromConfigFunc('YearnView');
|
|
141
141
|
export const MakerDsrContractViem = createViemContractFromConfigFunc('MakerDsr');
|
|
142
142
|
export const SkySavingsContractView = createViemContractFromConfigFunc('SkySavings');
|
|
143
|
+
export const AaveV4ViewContractViem = createViemContractFromConfigFunc('AaveV4View');
|
package/esm/eulerV2/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { EthAddress, EthereumProvider, NetworkNumber } from '../types
|
|
3
|
-
import { EulerV2AssetsData, EulerV2FullMarketData, EulerV2Market, EulerV2MarketInfoData, EulerV2PositionData } from '../types';
|
|
2
|
+
import { EulerV2AssetsData, EulerV2FullMarketData, EulerV2Market, EulerV2MarketInfoData, EulerV2PositionData, EthAddress, EthereumProvider, NetworkNumber } from '../types';
|
|
4
3
|
export declare const EMPTY_USED_ASSET: {
|
|
5
4
|
isSupplied: boolean;
|
|
6
5
|
isBorrowed: boolean;
|
package/esm/eulerV2/index.js
CHANGED
|
@@ -9,10 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
12
|
-
import { IncentiveKind, } from '../types/common';
|
|
13
12
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
14
|
-
import { compareAddresses, getEthAmountForDecimals,
|
|
15
|
-
import { EulerV2VaultType, } from '../types';
|
|
13
|
+
import { compareAddresses, getEthAmountForDecimals, isMaxUint, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
14
|
+
import { EulerV2VaultType, IncentiveKind, } from '../types';
|
|
16
15
|
import { getEulerV2AggregatedData, getEulerV2BorrowRate, getEulerV2SupplyRate, getUtilizationRate, } from '../helpers/eulerHelpers';
|
|
17
16
|
import { ZERO_ADDRESS } from '../constants';
|
|
18
17
|
import { EulerV2ViewContractViem } from '../contracts';
|
|
@@ -59,7 +58,7 @@ export const _getEulerV2MarketsData = (provider, network, selectedMarket) => __a
|
|
|
59
58
|
collateralFactor: new Dec(collateral.borrowLTV).div(10000).toString(),
|
|
60
59
|
totalBorrow: getEthAmountForDecimals(collateral.totalBorrows.toString(), decimals), // parse
|
|
61
60
|
cash: getEthAmountForDecimals(collateral.cash.toString(), decimals),
|
|
62
|
-
supplyCap:
|
|
61
|
+
supplyCap: isMaxUint(collateral.supplyCap.toString()) ? collateral.supplyCap.toString() : getEthAmountForDecimals(collateral.supplyCap.toString(), decimals),
|
|
63
62
|
borrowCap: '0',
|
|
64
63
|
price: isInUSD ? assetAmountInEth(collateral.assetPriceInUnit.toString()) : new Dec(assetAmountInEth(collateral.assetPriceInUnit.toString())).mul(usdPrice).toString(), // 1e18 -> price in unitOfAccount (so it could be USD or any other token)
|
|
65
64
|
canBeBorrowed: false,
|
|
@@ -99,8 +98,8 @@ export const _getEulerV2MarketsData = (provider, network, selectedMarket) => __a
|
|
|
99
98
|
decimals,
|
|
100
99
|
totalBorrow: getEthAmountForDecimals(data.totalBorrows.toString(), decimals), // parse
|
|
101
100
|
cash: getEthAmountForDecimals(data.cash.toString(), decimals),
|
|
102
|
-
supplyCap:
|
|
103
|
-
borrowCap:
|
|
101
|
+
supplyCap: isMaxUint(data.supplyCap.toString()) ? data.supplyCap.toString() : getEthAmountForDecimals(data.supplyCap.toString(), decimals),
|
|
102
|
+
borrowCap: isMaxUint(data.supplyCap.toString()) ? data.borrowCap.toString() : getEthAmountForDecimals(data.borrowCap.toString(), decimals),
|
|
104
103
|
price: isInUSD ? assetAmountInEth(data.assetPriceInUnit.toString()) : new Dec(assetAmountInEth(data.assetPriceInUnit.toString())).mul(usdPrice).toString(), // 1e18 -> price in unitOfAccount (so it could be USD or any other token)
|
|
105
104
|
sortIndex: 0,
|
|
106
105
|
canBeBorrowed: true,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets, LeverageType, NetworkNumber } from '../../types';
|
|
2
|
+
export declare const calcUserRiskPremiumBps: (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData) => number;
|
|
3
|
+
export declare const getApyAfterValuesEstimation: (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData) => Record<string, {
|
|
4
|
+
borrowRate: string;
|
|
5
|
+
supplyRate: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const calculateNetApyAaveV4: ({ usedAssets, assetsData, }: {
|
|
8
|
+
usedAssets: AaveV4UsedReserveAssets;
|
|
9
|
+
assetsData: AaveV4AssetsData;
|
|
10
|
+
}) => {
|
|
11
|
+
netApy: string;
|
|
12
|
+
totalInterestUsd: string;
|
|
13
|
+
incentiveUsd: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const aaveV4GetCollateralFactor: (assetData: AaveV4ReserveAssetData, usedAssetData: AaveV4UsedReserveAsset, useUserCollateralFactor?: boolean) => number;
|
|
16
|
+
export declare const isLeveragedPosAaveV4: (usedAssets: AaveV4UsedReserveAssets, dustLimit?: number) => {
|
|
17
|
+
leveragedType: LeverageType;
|
|
18
|
+
leveragedAsset: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData, network, useUserCollateralFactor, }: {
|
|
21
|
+
usedAssets: AaveV4UsedReserveAssets;
|
|
22
|
+
assetsData: AaveV4AssetsData;
|
|
23
|
+
network: NetworkNumber;
|
|
24
|
+
useUserCollateralFactor?: boolean;
|
|
25
|
+
}) => AaveV4AggregatedPositionData;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
|
|
3
|
+
import { calculateInterestEarned } from '../../staking';
|
|
4
|
+
import { LeverageType, } from '../../types';
|
|
5
|
+
export const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
|
|
6
|
+
const collaterals = [];
|
|
7
|
+
const debts = [];
|
|
8
|
+
Object.entries(usedAssets).forEach(([identifier, asset]) => {
|
|
9
|
+
const reserveData = assetsData[identifier];
|
|
10
|
+
if (!reserveData)
|
|
11
|
+
return;
|
|
12
|
+
const borrowedUsdDec = new Dec(asset.borrowedUsd || '0');
|
|
13
|
+
if (asset.isBorrowed && borrowedUsdDec.gt(0)) {
|
|
14
|
+
debts.push({ valueUsd: borrowedUsdDec });
|
|
15
|
+
}
|
|
16
|
+
const suppliedUsdDec = new Dec(asset.suppliedUsd || '0');
|
|
17
|
+
const isActiveCollateral = asset.collateral
|
|
18
|
+
&& asset.isSupplied
|
|
19
|
+
&& asset.collateralFactor > 0
|
|
20
|
+
&& suppliedUsdDec.gt(0);
|
|
21
|
+
if (isActiveCollateral) {
|
|
22
|
+
// collateralRisk is stored as a fraction (e.g. 0.25), convert back to bps
|
|
23
|
+
const riskBps = new Dec(reserveData.collateralRisk).mul(10000).toNumber();
|
|
24
|
+
collaterals.push({
|
|
25
|
+
riskBps,
|
|
26
|
+
valueUsd: suppliedUsdDec,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const totalDebtUsd = debts.reduce((sum, d) => sum.add(d.valueUsd), new Dec(0));
|
|
31
|
+
if (totalDebtUsd.lte(0)) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
// sort by risk ASC, value DESC
|
|
35
|
+
collaterals.sort((a, b) => {
|
|
36
|
+
if (a.riskBps !== b.riskBps)
|
|
37
|
+
return a.riskBps - b.riskBps;
|
|
38
|
+
return b.valueUsd.comparedTo(a.valueUsd);
|
|
39
|
+
});
|
|
40
|
+
let debtLeftToCover = totalDebtUsd;
|
|
41
|
+
let numerator = new Dec(0); // sum(coveredUsd * riskBps)
|
|
42
|
+
let coveredDebt = new Dec(0); // sum(coveredUsd)
|
|
43
|
+
collaterals.forEach(({ riskBps, valueUsd }) => {
|
|
44
|
+
if (debtLeftToCover.lte(0))
|
|
45
|
+
return;
|
|
46
|
+
const coveredUsd = Dec.min(valueUsd, debtLeftToCover);
|
|
47
|
+
numerator = numerator.add(coveredUsd.mul(riskBps));
|
|
48
|
+
coveredDebt = coveredDebt.add(coveredUsd);
|
|
49
|
+
debtLeftToCover = debtLeftToCover.sub(coveredUsd);
|
|
50
|
+
});
|
|
51
|
+
if (coveredDebt.lte(0)) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
const riskPremiumBps = numerator.div(coveredDebt);
|
|
55
|
+
return riskPremiumBps.toNumber();
|
|
56
|
+
};
|
|
57
|
+
export const getApyAfterValuesEstimation = (usedAssets, assetsData) => {
|
|
58
|
+
const riskPremiumBps = calcUserRiskPremiumBps(usedAssets, assetsData);
|
|
59
|
+
const riskPremiumFraction = new Dec(riskPremiumBps).div(10000); // bps to fraction
|
|
60
|
+
const result = {};
|
|
61
|
+
Object.entries(assetsData).forEach(([identifier, assetData]) => {
|
|
62
|
+
const drawnRate = new Dec(assetData.drawnRate);
|
|
63
|
+
const baseBorrowApr = drawnRate.mul(100);
|
|
64
|
+
// finalBorrowRate = baseBorrowRate * (1 + riskPremiumFraction)
|
|
65
|
+
const userBorrowApr = baseBorrowApr.mul(new Dec(1).add(riskPremiumFraction));
|
|
66
|
+
result[identifier] = {
|
|
67
|
+
borrowRate: aprToApy(userBorrowApr.toString()),
|
|
68
|
+
// Supply rate is market-level (not user-specific), use existing value
|
|
69
|
+
supplyRate: assetData.supplyRate,
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
export const calculateNetApyAaveV4 = ({ usedAssets, assetsData, }) => {
|
|
75
|
+
const riskPremiumBps = calcUserRiskPremiumBps(usedAssets, assetsData);
|
|
76
|
+
const riskPremiumFraction = new Dec(riskPremiumBps).div(10000);
|
|
77
|
+
const sumValues = Object.entries(usedAssets).reduce((_acc, [identifier, usedAsset]) => {
|
|
78
|
+
const acc = Object.assign({}, _acc);
|
|
79
|
+
const assetData = assetsData[identifier];
|
|
80
|
+
if (!assetData)
|
|
81
|
+
return acc;
|
|
82
|
+
if (usedAsset.isSupplied) {
|
|
83
|
+
const amount = usedAsset.suppliedUsd;
|
|
84
|
+
acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
|
|
85
|
+
const supplyInterest = calculateInterestEarned(amount, assetData.supplyRate, 'year', true);
|
|
86
|
+
acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
|
|
87
|
+
if (assetData.supplyIncentives) {
|
|
88
|
+
for (const supplyIncentive of assetData.supplyIncentives) {
|
|
89
|
+
const incentiveInterest = calculateInterestEarned(amount, supplyIncentive.apy, 'year', true);
|
|
90
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (usedAsset.isBorrowed) {
|
|
95
|
+
const amount = usedAsset.borrowedUsd;
|
|
96
|
+
acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
|
|
97
|
+
// User borrow rate = baseRate * (1 + riskPremiumFraction)
|
|
98
|
+
const drawnRate = new Dec(assetData.drawnRate);
|
|
99
|
+
const baseBorrowApr = drawnRate.mul(100);
|
|
100
|
+
const userBorrowApr = baseBorrowApr.mul(new Dec(1).add(riskPremiumFraction));
|
|
101
|
+
const userBorrowRate = aprToApy(userBorrowApr.toString());
|
|
102
|
+
const borrowInterest = calculateInterestEarned(amount, userBorrowRate, 'year', true);
|
|
103
|
+
acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
104
|
+
if (assetData.borrowIncentives) {
|
|
105
|
+
for (const borrowIncentive of assetData.borrowIncentives) {
|
|
106
|
+
const incentiveInterest = calculateInterestEarned(amount, borrowIncentive.apy, 'year', true);
|
|
107
|
+
acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return acc;
|
|
112
|
+
}, {
|
|
113
|
+
borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
|
|
114
|
+
});
|
|
115
|
+
const { borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd, } = sumValues;
|
|
116
|
+
const totalInterestUsd = new Dec(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
|
|
117
|
+
const balance = new Dec(suppliedUsd).sub(borrowedUsd);
|
|
118
|
+
const netApy = balance.isZero() ? '0' : new Dec(totalInterestUsd).div(balance).times(100).toString();
|
|
119
|
+
return { netApy, totalInterestUsd, incentiveUsd };
|
|
120
|
+
};
|
|
121
|
+
export const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
|
|
122
|
+
export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
123
|
+
let borrowUnstable = 0;
|
|
124
|
+
let supplyStable = 0;
|
|
125
|
+
let borrowStable = 0;
|
|
126
|
+
let supplyUnstable = 0;
|
|
127
|
+
let longAsset = '';
|
|
128
|
+
let shortAsset = '';
|
|
129
|
+
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, reserveId, }) => {
|
|
130
|
+
const spokeAsset = `${symbol}-${reserveId}`;
|
|
131
|
+
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
132
|
+
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
133
|
+
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
134
|
+
supplyStable += 1;
|
|
135
|
+
if (isBorrowed && STABLE_ASSETS.includes(symbol))
|
|
136
|
+
borrowStable += 1;
|
|
137
|
+
if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
|
|
138
|
+
borrowUnstable += 1;
|
|
139
|
+
shortAsset = spokeAsset;
|
|
140
|
+
}
|
|
141
|
+
if (isSupplied && !STABLE_ASSETS.includes(symbol) && collateral) {
|
|
142
|
+
supplyUnstable += 1;
|
|
143
|
+
longAsset = spokeAsset;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
147
|
+
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
148
|
+
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
149
|
+
if (isLong) {
|
|
150
|
+
return {
|
|
151
|
+
leveragedType: LeverageType.Long,
|
|
152
|
+
leveragedAsset: longAsset,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (isShort) {
|
|
156
|
+
return {
|
|
157
|
+
leveragedType: LeverageType.Short,
|
|
158
|
+
leveragedAsset: shortAsset,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (isVolatilePair) {
|
|
162
|
+
return {
|
|
163
|
+
leveragedType: LeverageType.VolatilePair,
|
|
164
|
+
leveragedAsset: longAsset,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
leveragedType: LeverageType.None,
|
|
169
|
+
leveragedAsset: '',
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useUserCollateralFactor = false, }) => {
|
|
173
|
+
const payload = {};
|
|
174
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
175
|
+
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
176
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(aaveV4GetCollateralFactor(assetsData[`${symbol}-${reserveId}`], usedAssets[`${symbol}-${reserveId}`], useUserCollateralFactor)));
|
|
177
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
178
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
179
|
+
payload.drawnUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ drawnUsd }) => drawnUsd);
|
|
180
|
+
payload.premiumUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ premiumUsd }) => premiumUsd);
|
|
181
|
+
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
182
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
183
|
+
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
184
|
+
payload.minRatio = '100';
|
|
185
|
+
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
186
|
+
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
187
|
+
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
188
|
+
const { leveragedType, leveragedAsset } = isLeveragedPosAaveV4(usedAssets);
|
|
189
|
+
payload.leveragedType = leveragedType;
|
|
190
|
+
payload.leveragedAsset = leveragedAsset;
|
|
191
|
+
payload.liquidationPrice = '';
|
|
192
|
+
if (leveragedType !== '') {
|
|
193
|
+
const leveragedAssetData = assetsData[leveragedAsset];
|
|
194
|
+
let assetPrice = (leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0';
|
|
195
|
+
if (leveragedType === LeverageType.VolatilePair) {
|
|
196
|
+
const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
|
|
197
|
+
const borrowedAssetPrice = assetsData[`${borrowedAsset.symbol}-${borrowedAsset.reserveId}`].price;
|
|
198
|
+
const leveragedAssetPrice = assetsData[leveragedAsset].price;
|
|
199
|
+
const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
|
|
200
|
+
if (isReverse) {
|
|
201
|
+
payload.leveragedType = LeverageType.VolatilePairReverse;
|
|
202
|
+
payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
|
|
203
|
+
assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
|
|
207
|
+
payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
211
|
+
}
|
|
212
|
+
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
213
|
+
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
214
|
+
payload.healthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
215
|
+
payload.minHealthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowLimitUsd).toDP(4).toString();
|
|
216
|
+
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApyAaveV4({ usedAssets, assetsData });
|
|
217
|
+
payload.netApy = netApy;
|
|
218
|
+
payload.incentiveUsd = incentiveUsd;
|
|
219
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
220
|
+
return payload;
|
|
221
|
+
};
|
package/esm/helpers/index.d.ts
CHANGED
package/esm/helpers/index.js
CHANGED
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './setup';
|
|
2
2
|
import * as fluid from './fluid';
|
|
3
|
+
import * as aaveV4 from './aaveV4';
|
|
3
4
|
import * as aaveV3 from './aaveV3';
|
|
4
5
|
import * as aaveV2 from './aaveV2';
|
|
5
6
|
import * as compoundV3 from './compoundV3';
|
|
@@ -21,4 +22,4 @@ import * as portfolio from './portfolio';
|
|
|
21
22
|
import * as claiming from './claiming';
|
|
22
23
|
import * as savings from './savings';
|
|
23
24
|
export * from './types';
|
|
24
|
-
export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
|
25
|
+
export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './setup';
|
|
2
2
|
import * as fluid from './fluid';
|
|
3
|
+
import * as aaveV4 from './aaveV4';
|
|
3
4
|
import * as aaveV3 from './aaveV3';
|
|
4
5
|
import * as aaveV2 from './aaveV2';
|
|
5
6
|
import * as compoundV3 from './compoundV3';
|
|
@@ -21,4 +22,4 @@ import * as portfolio from './portfolio';
|
|
|
21
22
|
import * as claiming from './claiming';
|
|
22
23
|
import * as savings from './savings';
|
|
23
24
|
export * from './types';
|
|
24
|
-
export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
|
25
|
+
export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AaveV4HubInfo, AaveV4HubsType, AaveV4SpokeInfo, AaveV4SpokesType, NetworkNumber } from '../../types';
|
|
2
|
+
export declare const AAVE_V4_CORE_HUB: (networkId: NetworkNumber) => AaveV4HubInfo;
|
|
3
|
+
export declare const AAVE_V4_PLUS_HUB: (networkId: NetworkNumber) => AaveV4HubInfo;
|
|
4
|
+
export declare const AAVE_V4_PRIME_HUB: (networkId: NetworkNumber) => AaveV4HubInfo;
|
|
5
|
+
export declare const AaveV4Hubs: (networkId: NetworkNumber) => {
|
|
6
|
+
readonly aave_v4_core_hub: AaveV4HubInfo;
|
|
7
|
+
readonly aave_v4_plus_hub: AaveV4HubInfo;
|
|
8
|
+
readonly aave_v4_prime_hub: AaveV4HubInfo;
|
|
9
|
+
};
|
|
10
|
+
export declare const getAaveV4HubTypeInfo: (type: AaveV4HubsType, network?: NetworkNumber) => AaveV4HubInfo;
|
|
11
|
+
export declare const getAaveV4HubByAddress: (networkId: NetworkNumber, address: string) => AaveV4HubInfo | undefined;
|
|
12
|
+
export declare const AAVE_V4_BLUECHIP_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
13
|
+
export declare const AAVE_V4_ETHENA_CORRELATED_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
14
|
+
export declare const AAVE_V4_ETHENA_ECOSYSTEM_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
15
|
+
export declare const AAVE_V4_ETHERFI_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
16
|
+
export declare const AAVE_V4_FOREX_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
17
|
+
export declare const AAVE_V4_GOLD_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
18
|
+
export declare const AAVE_V4_KELP_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
19
|
+
export declare const AAVE_V4_LIDO_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
20
|
+
export declare const AAVE_V4_LOMBARD_BTC_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
21
|
+
export declare const AAVE_V4_MAIN_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
22
|
+
export declare const AaveV4Spokes: (networkId: NetworkNumber) => {
|
|
23
|
+
readonly aave_v4_bluechip_spoke: AaveV4SpokeInfo;
|
|
24
|
+
readonly aave_v4_ethena_correlated_spoke: AaveV4SpokeInfo;
|
|
25
|
+
readonly aave_v4_ethena_ecosystem_spoke: AaveV4SpokeInfo;
|
|
26
|
+
readonly aave_v4_etherfi_spoke: AaveV4SpokeInfo;
|
|
27
|
+
readonly aave_v4_forex_spoke: AaveV4SpokeInfo;
|
|
28
|
+
readonly aave_v4_gold_spoke: AaveV4SpokeInfo;
|
|
29
|
+
readonly aave_v4_kelp_spoke: AaveV4SpokeInfo;
|
|
30
|
+
readonly aave_v4_lido_spoke: AaveV4SpokeInfo;
|
|
31
|
+
readonly aave_v4_lombard_btc_spoke: AaveV4SpokeInfo;
|
|
32
|
+
readonly aave_v4_main_spoke: AaveV4SpokeInfo;
|
|
33
|
+
};
|
|
34
|
+
export declare const getAaveV4SpokeTypeInfo: (type: AaveV4SpokesType, network?: NetworkNumber) => AaveV4SpokeInfo;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { AaveV4HubsType, AaveV4SpokesType, NetworkNumber, } from '../../types';
|
|
2
|
+
// HUBS
|
|
3
|
+
export const AAVE_V4_CORE_HUB = (networkId) => ({
|
|
4
|
+
chainIds: [NetworkNumber.Eth],
|
|
5
|
+
label: 'Core Hub',
|
|
6
|
+
value: AaveV4HubsType.AaveV4CoreHub,
|
|
7
|
+
address: '0xCca852Bc40e560adC3b1Cc58CA5b55638ce826c9',
|
|
8
|
+
});
|
|
9
|
+
export const AAVE_V4_PLUS_HUB = (networkId) => ({
|
|
10
|
+
chainIds: [NetworkNumber.Eth],
|
|
11
|
+
label: 'Plus Hub',
|
|
12
|
+
value: AaveV4HubsType.AaveV4PlusHub,
|
|
13
|
+
address: '0x06002e9c4412CB7814a791eA3666D905871E536A',
|
|
14
|
+
});
|
|
15
|
+
export const AAVE_V4_PRIME_HUB = (networkId) => ({
|
|
16
|
+
chainIds: [NetworkNumber.Eth],
|
|
17
|
+
label: 'Prime Hub',
|
|
18
|
+
value: AaveV4HubsType.AaveV4PrimeHub,
|
|
19
|
+
address: '0x943827DCA022D0F354a8a8c332dA1e5Eb9f9F931',
|
|
20
|
+
});
|
|
21
|
+
export const AaveV4Hubs = (networkId) => ({
|
|
22
|
+
[AaveV4HubsType.AaveV4CoreHub]: AAVE_V4_CORE_HUB(networkId),
|
|
23
|
+
[AaveV4HubsType.AaveV4PlusHub]: AAVE_V4_PLUS_HUB(networkId),
|
|
24
|
+
[AaveV4HubsType.AaveV4PrimeHub]: AAVE_V4_PRIME_HUB(networkId),
|
|
25
|
+
});
|
|
26
|
+
export const getAaveV4HubTypeInfo = (type, network) => (Object.assign({}, AaveV4Hubs(network !== null && network !== void 0 ? network : NetworkNumber.Eth))[type]);
|
|
27
|
+
export const getAaveV4HubByAddress = (networkId, address) => Object.values(AaveV4Hubs(networkId)).find(hub => hub.address.toLowerCase() === address.toLowerCase());
|
|
28
|
+
// SPOKES
|
|
29
|
+
export const AAVE_V4_BLUECHIP_SPOKE = (networkId) => ({
|
|
30
|
+
chainIds: [NetworkNumber.Eth],
|
|
31
|
+
label: 'Bluechip',
|
|
32
|
+
value: AaveV4SpokesType.AaveV4BluechipSpoke,
|
|
33
|
+
url: 'bluechip',
|
|
34
|
+
address: '0x973a023A77420ba610f06b3858aD991Df6d85A08',
|
|
35
|
+
hubs: [
|
|
36
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
37
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
38
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
export const AAVE_V4_ETHENA_CORRELATED_SPOKE = (networkId) => ({
|
|
42
|
+
chainIds: [NetworkNumber.Eth],
|
|
43
|
+
label: 'Ethena Correlated',
|
|
44
|
+
value: AaveV4SpokesType.AaveV4EthenaCorrelatedSpoke,
|
|
45
|
+
url: 'ethena-correlated',
|
|
46
|
+
address: '0x58131E79531caB1d52301228d1f7b842F26B9649',
|
|
47
|
+
hubs: [
|
|
48
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
49
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
50
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
export const AAVE_V4_ETHENA_ECOSYSTEM_SPOKE = (networkId) => ({
|
|
54
|
+
chainIds: [NetworkNumber.Eth],
|
|
55
|
+
label: 'Ethena Ecosystem',
|
|
56
|
+
value: AaveV4SpokesType.AaveV4EthenaEcosystemSpoke,
|
|
57
|
+
url: 'ethena-ecosystem',
|
|
58
|
+
address: '0xba1B3D55D249692b669A164024A838309B7508AF',
|
|
59
|
+
hubs: [
|
|
60
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
61
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
62
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
export const AAVE_V4_ETHERFI_SPOKE = (networkId) => ({
|
|
66
|
+
chainIds: [NetworkNumber.Eth],
|
|
67
|
+
label: 'Etherfi',
|
|
68
|
+
value: AaveV4SpokesType.AaveV4EtherfiSpoke,
|
|
69
|
+
url: 'etherfi',
|
|
70
|
+
address: '0xbF10BDfE177dE0336aFD7fcCF80A904E15386219',
|
|
71
|
+
hubs: [
|
|
72
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
73
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
74
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
export const AAVE_V4_FOREX_SPOKE = (networkId) => ({
|
|
78
|
+
chainIds: [NetworkNumber.Eth],
|
|
79
|
+
label: 'Forex',
|
|
80
|
+
value: AaveV4SpokesType.AaveV4ForexSpoke,
|
|
81
|
+
url: 'forex',
|
|
82
|
+
address: '0xD8B93635b8C6d0fF98CbE90b5988E3F2d1Cd9da1',
|
|
83
|
+
hubs: [
|
|
84
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
85
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
86
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
export const AAVE_V4_GOLD_SPOKE = (networkId) => ({
|
|
90
|
+
chainIds: [NetworkNumber.Eth],
|
|
91
|
+
label: 'Gold',
|
|
92
|
+
value: AaveV4SpokesType.AaveV4GoldSpoke,
|
|
93
|
+
url: 'gold',
|
|
94
|
+
address: '0x65407b940966954b23dfA3caA5C0702bB42984DC',
|
|
95
|
+
hubs: [
|
|
96
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
97
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
98
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
export const AAVE_V4_KELP_SPOKE = (networkId) => ({
|
|
102
|
+
chainIds: [NetworkNumber.Eth],
|
|
103
|
+
label: 'Kelp',
|
|
104
|
+
value: AaveV4SpokesType.AaveV4KelpSpoke,
|
|
105
|
+
url: 'kelp',
|
|
106
|
+
address: '0x3131FE68C4722e726fe6B2819ED68e514395B9a4',
|
|
107
|
+
hubs: [
|
|
108
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
109
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
110
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
export const AAVE_V4_LIDO_SPOKE = (networkId) => ({
|
|
114
|
+
chainIds: [NetworkNumber.Eth],
|
|
115
|
+
label: 'Lido',
|
|
116
|
+
value: AaveV4SpokesType.AaveV4LidoSpoke,
|
|
117
|
+
url: 'lido',
|
|
118
|
+
address: '0xe1900480ac69f0B296841Cd01cC37546d92F35Cd',
|
|
119
|
+
hubs: [
|
|
120
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
121
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
122
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
export const AAVE_V4_LOMBARD_BTC_SPOKE = (networkId) => ({
|
|
126
|
+
chainIds: [NetworkNumber.Eth],
|
|
127
|
+
label: 'Lombard BTC',
|
|
128
|
+
value: AaveV4SpokesType.AaveV4LombardBtcSpoke,
|
|
129
|
+
url: 'lombard-btc',
|
|
130
|
+
address: '0x7EC68b5695e803e98a21a9A05d744F28b0a7753D',
|
|
131
|
+
hubs: [
|
|
132
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
133
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
134
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
export const AAVE_V4_MAIN_SPOKE = (networkId) => ({
|
|
138
|
+
chainIds: [NetworkNumber.Eth],
|
|
139
|
+
label: 'Main',
|
|
140
|
+
value: AaveV4SpokesType.AaveV4MainSpoke,
|
|
141
|
+
url: 'main',
|
|
142
|
+
address: '0x94e7A5dCbE816e498b89aB752661904E2F56c485',
|
|
143
|
+
hubs: [
|
|
144
|
+
AAVE_V4_CORE_HUB(NetworkNumber.Eth).address,
|
|
145
|
+
AAVE_V4_PLUS_HUB(NetworkNumber.Eth).address,
|
|
146
|
+
AAVE_V4_PRIME_HUB(NetworkNumber.Eth).address,
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
export const AaveV4Spokes = (networkId) => ({
|
|
150
|
+
[AaveV4SpokesType.AaveV4BluechipSpoke]: AAVE_V4_BLUECHIP_SPOKE(networkId),
|
|
151
|
+
[AaveV4SpokesType.AaveV4EthenaCorrelatedSpoke]: AAVE_V4_ETHENA_CORRELATED_SPOKE(networkId),
|
|
152
|
+
[AaveV4SpokesType.AaveV4EthenaEcosystemSpoke]: AAVE_V4_ETHENA_ECOSYSTEM_SPOKE(networkId),
|
|
153
|
+
[AaveV4SpokesType.AaveV4EtherfiSpoke]: AAVE_V4_ETHERFI_SPOKE(networkId),
|
|
154
|
+
[AaveV4SpokesType.AaveV4ForexSpoke]: AAVE_V4_FOREX_SPOKE(networkId),
|
|
155
|
+
[AaveV4SpokesType.AaveV4GoldSpoke]: AAVE_V4_GOLD_SPOKE(networkId),
|
|
156
|
+
[AaveV4SpokesType.AaveV4KelpSpoke]: AAVE_V4_KELP_SPOKE(networkId),
|
|
157
|
+
[AaveV4SpokesType.AaveV4LidoSpoke]: AAVE_V4_LIDO_SPOKE(networkId),
|
|
158
|
+
[AaveV4SpokesType.AaveV4LombardBtcSpoke]: AAVE_V4_LOMBARD_BTC_SPOKE(networkId),
|
|
159
|
+
[AaveV4SpokesType.AaveV4MainSpoke]: AAVE_V4_MAIN_SPOKE(networkId),
|
|
160
|
+
});
|
|
161
|
+
export const getAaveV4SpokeTypeInfo = (type, network) => (Object.assign({}, AaveV4Spokes(network !== null && network !== void 0 ? network : NetworkNumber.Eth))[type]);
|
package/esm/markets/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export { LlamaLendMarkets } from './llamaLend';
|
|
|
7
7
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
8
8
|
export { EulerV2Markets } from './euler';
|
|
9
9
|
export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
|
|
10
|
+
export { AaveV4Spokes } from './aaveV4';
|
package/esm/markets/index.js
CHANGED
|
@@ -7,3 +7,4 @@ export { LlamaLendMarkets } from './llamaLend';
|
|
|
7
7
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
8
8
|
export { EulerV2Markets } from './euler';
|
|
9
9
|
export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
|
|
10
|
+
export { AaveV4Spokes } from './aaveV4';
|
|
@@ -21,7 +21,7 @@ export const STABLE_ASSETS = [
|
|
|
21
21
|
'DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'USDA',
|
|
22
22
|
'USDe', 'sUSDe', 'USDS', 'sUSDS', 'USR', 'EURC', 'BOLD', 'BOLD Legacy', 'RLUSD', 'PT sUSDe July', 'PT eUSDe May',
|
|
23
23
|
'USDtb', 'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'PT sUSDe Sep', 'PT USDe Sep', 'PT sUSDe Nov', 'PT USDe Nov', 'PT sUSDe Jan', 'PT USDe Jan',
|
|
24
|
-
'PT sUSDe Feb', 'PT USDe Feb', 'PT sUSDe Apr', 'PT USDe Apr', 'PT sUSDe May', 'PT USDe May', 'PT srUSDe Apr',
|
|
24
|
+
'PT sUSDe Feb', 'PT USDe Feb', 'PT sUSDe Apr', 'PT USDe Apr', 'PT sUSDe May', 'PT USDe May', 'PT srUSDe Apr', 'frxUSD',
|
|
25
25
|
];
|
|
26
26
|
export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
27
27
|
let borrowUnstable = 0;
|
package/esm/portfolio/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { NetworkNumber } from '../types/common';
|
|
12
|
-
import { AaveMarkets, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
|
|
12
|
+
import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
|
|
13
13
|
import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } from '../morphoBlue';
|
|
14
14
|
import { AaveVersions, CompoundVersions, } from '../types';
|
|
15
15
|
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
@@ -34,6 +34,7 @@ import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
|
34
34
|
import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
|
|
35
35
|
import { getKingRewards } from '../claiming/king';
|
|
36
36
|
import { fetchEthenaAirdropRewards } from '../claiming/ethena';
|
|
37
|
+
import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
|
|
37
38
|
export function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
|
|
38
39
|
return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
|
|
39
40
|
const isMainnet = network === NetworkNumber.Eth;
|
|
@@ -50,6 +51,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
50
51
|
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
51
52
|
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
52
53
|
const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
|
|
54
|
+
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
53
55
|
const args = [network, { batch: { multicall: { batchSize: isSim ? 500000 : 2500000 } } }];
|
|
54
56
|
const client = getViemProvider(provider, ...args);
|
|
55
57
|
const defaultClient = getViemProvider(defaultProvider, ...args);
|
|
@@ -64,6 +66,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
64
66
|
const crvUsdMarketsData = {};
|
|
65
67
|
const llamaLendMarketsData = {};
|
|
66
68
|
const liquityV2MarketsData = {};
|
|
69
|
+
const aaveV4SpokesData = {};
|
|
67
70
|
const markets = {
|
|
68
71
|
morphoMarketsData,
|
|
69
72
|
compoundV3MarketsData,
|
|
@@ -75,6 +78,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
75
78
|
crvUsdMarketsData,
|
|
76
79
|
llamaLendMarketsData,
|
|
77
80
|
liquityV2MarketsData,
|
|
81
|
+
aaveV4SpokesData,
|
|
78
82
|
};
|
|
79
83
|
const positions = {};
|
|
80
84
|
const stakingPositions = {};
|
|
@@ -83,6 +87,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
83
87
|
for (const address of allAddresses) {
|
|
84
88
|
positions[address.toLowerCase()] = {
|
|
85
89
|
aaveV3: {},
|
|
90
|
+
aaveV4: {},
|
|
86
91
|
morphoBlue: {},
|
|
87
92
|
compoundV3: {},
|
|
88
93
|
spark: {},
|
|
@@ -148,6 +153,10 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
148
153
|
const marketData = yield _getAaveV3MarketData(client, network, market);
|
|
149
154
|
aaveV3MarketsData[market.value] = marketData;
|
|
150
155
|
})),
|
|
156
|
+
...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const spokeData = yield _getAaveV4SpokeData(client, network, spoke);
|
|
158
|
+
aaveV4SpokesData[spoke.value] = spokeData;
|
|
159
|
+
})),
|
|
151
160
|
...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
152
161
|
const marketData = yield _getAaveV2MarketsData(client, network, market);
|
|
153
162
|
aaveV2MarketsData[market.value] = marketData;
|
|
@@ -417,6 +426,17 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
417
426
|
positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
418
427
|
}
|
|
419
428
|
}))).flat(),
|
|
429
|
+
...aaveV4Spokes.map((spoke) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
try {
|
|
431
|
+
const accData = yield _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
|
|
432
|
+
if (new Dec(accData.suppliedUsd).gt(0))
|
|
433
|
+
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
437
|
+
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
438
|
+
}
|
|
439
|
+
}))).flat(),
|
|
420
440
|
...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
421
441
|
try {
|
|
422
442
|
const [accDataPromise, earnDataPromise] = yield Promise.allSettled([
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const bytesToString: (hex: string) => string;
|
|
|
18
18
|
export declare const mapRange: (input: number | string, minInput: number | string, maxInput: number | string, minOutput: number | string, maxOutput: number | string) => number;
|
|
19
19
|
export declare const isEnabledOnBitmap: (bitmap: number, assetId: number) => bigint;
|
|
20
20
|
export declare const MAXUINT: string;
|
|
21
|
-
export declare const
|
|
21
|
+
export declare const isMaxUint: (amount: string) => boolean;
|
|
22
22
|
export declare const isMainnetNetwork: (network: NetworkNumber) => network is NetworkNumber.Eth;
|
|
23
23
|
export declare const DEFAULT_TIMEOUT = 2000;
|
|
24
24
|
export declare const LONGER_TIMEOUT = 5000;
|