@defisaver/positions-sdk 2.1.48 → 2.1.49-aave-v4-dev-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 +167 -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/helpers/aaveV4Helpers/index.d.ts +9 -0
- package/cjs/helpers/aaveV4Helpers/index.js +57 -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/aave/marketAssets.js +1 -1
- package/cjs/markets/aaveV4/index.d.ts +7 -0
- package/cjs/markets/aaveV4/index.js +22 -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/staking/staking.js +5 -1
- package/cjs/types/aaveV4.d.ts +129 -0
- package/cjs/types/aaveV4.js +11 -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 +158 -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/helpers/aaveV4Helpers/index.d.ts +9 -0
- package/esm/helpers/aaveV4Helpers/index.js +49 -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/aave/marketAssets.js +1 -1
- package/esm/markets/aaveV4/index.d.ts +7 -0
- package/esm/markets/aaveV4/index.js +16 -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/staking/staking.js +5 -1
- package/esm/types/aaveV4.d.ts +129 -0
- package/esm/types/aaveV4.js +8 -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 +169 -0
- package/src/config/contracts.ts +8 -0
- package/src/contracts.ts +3 -1
- package/src/helpers/aaveV4Helpers/index.ts +69 -0
- package/src/helpers/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/markets/aave/marketAssets.ts +1 -1
- package/src/markets/aaveV4/index.ts +19 -0
- package/src/markets/index.ts +1 -0
- package/src/moneymarket/moneymarketCommonService.ts +1 -1
- package/src/portfolio/index.ts +20 -0
- package/src/staking/staking.ts +3 -1
- package/src/types/aaveV4.ts +142 -0
- package/src/types/index.ts +2 -1
- package/src/types/portfolio.ts +4 -0
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');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets } from '../../types';
|
|
2
|
+
import { NetworkNumber } from '../../types/common';
|
|
3
|
+
export declare const aaveV4GetCollateralFactor: (assetData: AaveV4ReserveAssetData, usedAssetData: AaveV4UsedReserveAsset, useUserCollateralFactor?: boolean) => number;
|
|
4
|
+
export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData, network, useUserCollateralFactor, }: {
|
|
5
|
+
usedAssets: AaveV4UsedReserveAssets;
|
|
6
|
+
assetsData: AaveV4AssetsData;
|
|
7
|
+
network: NetworkNumber;
|
|
8
|
+
useUserCollateralFactor?: boolean;
|
|
9
|
+
}) => AaveV4AggregatedPositionData;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
3
|
+
export const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
|
|
4
|
+
export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useUserCollateralFactor = false, }) => {
|
|
5
|
+
var _a;
|
|
6
|
+
const payload = {};
|
|
7
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
8
|
+
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
9
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(aaveV4GetCollateralFactor(assetsData[`${symbol}-${reserveId}`], usedAssets[`${symbol}-${reserveId}`], useUserCollateralFactor)));
|
|
10
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
11
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
12
|
+
payload.drawnUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ drawnUsd }) => drawnUsd);
|
|
13
|
+
payload.premiumUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ premiumUsd }) => premiumUsd);
|
|
14
|
+
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
15
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
16
|
+
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
17
|
+
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
18
|
+
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
19
|
+
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
20
|
+
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
21
|
+
payload.leveragedType = leveragedType;
|
|
22
|
+
payload.leveragedAsset = leveragedAsset;
|
|
23
|
+
payload.liquidationPrice = '';
|
|
24
|
+
if (leveragedType !== '') {
|
|
25
|
+
const leveragedAssetData = Object.values(assetsData).find((asset) => asset.symbol === leveragedAsset);
|
|
26
|
+
let assetPrice = (leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0';
|
|
27
|
+
if (leveragedType === 'lsd-leverage') {
|
|
28
|
+
// Treat ETH like a stablecoin in a long stETH position
|
|
29
|
+
const ethPrice = ((_a = Object.values(assetsData).find((asset) => asset.symbol === 'ETH')) === null || _a === void 0 ? void 0 : _a.price) || '0';
|
|
30
|
+
payload.leveragedLsdAssetRatio = new Dec((leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0').div(ethPrice).toDP(18).toString();
|
|
31
|
+
assetPrice = new Dec(assetPrice).div(ethPrice).toString();
|
|
32
|
+
}
|
|
33
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
34
|
+
}
|
|
35
|
+
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
36
|
+
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
37
|
+
// payload.healthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
38
|
+
payload.minHealthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowLimitUsd).toDP(4).toString();
|
|
39
|
+
// TODO: Re-implement netApy calculation
|
|
40
|
+
// const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({
|
|
41
|
+
// usedAssets,
|
|
42
|
+
// assetsData,
|
|
43
|
+
// optionalData: { healthRatio: payload.healthRatio },
|
|
44
|
+
// });
|
|
45
|
+
payload.netApy = '0';
|
|
46
|
+
payload.incentiveUsd = '0';
|
|
47
|
+
payload.totalInterestUsd = '0';
|
|
48
|
+
return payload;
|
|
49
|
+
};
|
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, };
|
|
@@ -15,7 +15,7 @@ export const aaveV3AssetsDefaultMarketOpt = [
|
|
|
15
15
|
export const aaveV3AssetsDefaultMarketArb = ['DAI', 'LINK', 'USDC.e', 'WBTC', 'ETH', 'USDT', 'AAVE', 'EURS', 'wstETH', 'MAI', 'rETH', 'LUSD', 'USDC', 'FRAX', 'ARB', 'weETH', 'GHO', 'ezETH', 'rsETH', 'tBTC'];
|
|
16
16
|
export const aaveV3AssetsDefaultMarketBase = ['ETH', 'cbETH', 'USDbC', 'wstETH', 'USDC', 'weETH', 'cbBTC', 'ezETH', 'GHO', 'wrsETH', 'LBTC', 'EURC', 'AAVE', 'tBTC'];
|
|
17
17
|
export const aaveV3AssetsDefaultMarketLinea = ['ETH', 'USDC', 'weETH', 'ezETH', 'USDT', 'wstETH', 'wrsETH', 'WBTC', 'mUSD'];
|
|
18
|
-
export const aaveV3AssetsDefaultMarketPlasma = ['ETH', 'USDT', 'sUSDe', 'USDe', 'weETH', 'XAUt', 'PT USDe Jan', 'PT sUSDe Jan', 'wrsETH', 'wstETH', 'syrupUSDT', 'XPL'];
|
|
18
|
+
export const aaveV3AssetsDefaultMarketPlasma = ['ETH', 'USDT', 'sUSDe', 'USDe', 'weETH', 'XAUt', 'PT USDe Jan', 'PT sUSDe Jan', 'wrsETH', 'wstETH', 'syrupUSDT', 'XPL', 'PT USDe Apr', 'PT sUSDe Apr'];
|
|
19
19
|
// @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
|
|
20
20
|
export const aaveV3AssetsDefaultMarket = {
|
|
21
21
|
[NetworkNumber.Eth]: aaveV3AssetsDefaultMarketEth,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AaveV4SpokeInfo, AaveV4SpokesType } from '../../types';
|
|
2
|
+
import { NetworkNumber } from '../../types/common';
|
|
3
|
+
export declare const AAVE_V4_CORE_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
|
|
4
|
+
export declare const AaveV4Spokes: (networkId: NetworkNumber) => {
|
|
5
|
+
readonly aave_v4_core_spoke: AaveV4SpokeInfo;
|
|
6
|
+
};
|
|
7
|
+
export declare const getAaveV4SpokeTypeInfo: (type: AaveV4SpokesType, network?: NetworkNumber) => AaveV4SpokeInfo;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AaveV4SpokesType } from '../../types';
|
|
2
|
+
import { NetworkNumber } from '../../types/common';
|
|
3
|
+
export const AAVE_V4_CORE_SPOKE = (networkId) => ({
|
|
4
|
+
chainIds: [NetworkNumber.Eth],
|
|
5
|
+
label: 'Core Spoke',
|
|
6
|
+
value: AaveV4SpokesType.AaveV4CoreSpoke,
|
|
7
|
+
url: 'core',
|
|
8
|
+
address: '0xBa97c5E52cd5BC3D7950Ae70779F8FfE92d40CdC',
|
|
9
|
+
hubs: [
|
|
10
|
+
'0xaD905aD5EA5B98cD50AE40Cfe368344686a21366',
|
|
11
|
+
],
|
|
12
|
+
});
|
|
13
|
+
export const AaveV4Spokes = (networkId) => ({
|
|
14
|
+
[AaveV4SpokesType.AaveV4CoreSpoke]: AAVE_V4_CORE_SPOKE(networkId),
|
|
15
|
+
});
|
|
16
|
+
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';
|
|
@@ -20,7 +20,7 @@ export const STABLE_ASSETS = [
|
|
|
20
20
|
'DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'USDA',
|
|
21
21
|
'USDe', 'sUSDe', 'USDS', 'sUSDS', 'USR', 'EURC', 'BOLD', 'BOLD Legacy', 'RLUSD', 'PT sUSDe July', 'PT eUSDe May',
|
|
22
22
|
'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',
|
|
23
|
-
'PT sUSDe Feb', 'PT USDe Feb',
|
|
23
|
+
'PT sUSDe Feb', 'PT USDe Feb', 'PT USDe Apr', 'PT sUSDe Apr',
|
|
24
24
|
];
|
|
25
25
|
export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
26
26
|
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, network, defaultProvider, addresses, summerFiAddresses) {
|
|
38
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
40
|
const isMainnet = network === NetworkNumber.Eth;
|
|
@@ -50,6 +51,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
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 client = getViemProvider(provider, network, {
|
|
54
56
|
batch: {
|
|
55
57
|
multicall: {
|
|
@@ -75,6 +77,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
75
77
|
const crvUsdMarketsData = {};
|
|
76
78
|
const llamaLendMarketsData = {};
|
|
77
79
|
const liquityV2MarketsData = {};
|
|
80
|
+
const aaveV4SpokesData = {};
|
|
78
81
|
const markets = {
|
|
79
82
|
morphoMarketsData,
|
|
80
83
|
compoundV3MarketsData,
|
|
@@ -86,6 +89,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
86
89
|
crvUsdMarketsData,
|
|
87
90
|
llamaLendMarketsData,
|
|
88
91
|
liquityV2MarketsData,
|
|
92
|
+
aaveV4SpokesData,
|
|
89
93
|
};
|
|
90
94
|
const positions = {};
|
|
91
95
|
const stakingPositions = {};
|
|
@@ -94,6 +98,7 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
94
98
|
for (const address of allAddresses) {
|
|
95
99
|
positions[address.toLowerCase()] = {
|
|
96
100
|
aaveV3: {},
|
|
101
|
+
aaveV4: {},
|
|
97
102
|
morphoBlue: {},
|
|
98
103
|
compoundV3: {},
|
|
99
104
|
spark: {},
|
|
@@ -159,6 +164,10 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
159
164
|
const marketData = yield _getAaveV3MarketData(client, network, market);
|
|
160
165
|
aaveV3MarketsData[market.value] = marketData;
|
|
161
166
|
})),
|
|
167
|
+
...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const spokeData = yield _getAaveV4SpokeData(client, network, spoke);
|
|
169
|
+
aaveV4SpokesData[spoke.value] = spokeData;
|
|
170
|
+
})),
|
|
162
171
|
...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
163
172
|
const marketData = yield _getAaveV2MarketsData(client, network, market);
|
|
164
173
|
aaveV2MarketsData[market.value] = marketData;
|
|
@@ -428,6 +437,17 @@ export function getPortfolioData(provider, network, defaultProvider, addresses,
|
|
|
428
437
|
positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
429
438
|
}
|
|
430
439
|
}))).flat(),
|
|
440
|
+
...aaveV4Spokes.map((spoke) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
441
|
+
try {
|
|
442
|
+
const accData = yield _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
|
|
443
|
+
if (new Dec(accData.suppliedUsd).gt(0))
|
|
444
|
+
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
|
|
445
|
+
}
|
|
446
|
+
catch (error) {
|
|
447
|
+
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
448
|
+
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
449
|
+
}
|
|
450
|
+
}))).flat(),
|
|
431
451
|
...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
432
452
|
try {
|
|
433
453
|
const [accDataPromise, earnDataPromise] = yield Promise.allSettled([
|
package/esm/staking/staking.js
CHANGED
|
@@ -66,7 +66,7 @@ export const STAKING_ASSETS = [
|
|
|
66
66
|
'cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH',
|
|
67
67
|
'ezETH', 'ETHx', 'rsETH', 'pufETH', 'wrsETH', 'wsuperOETHb', 'sUSDS', 'tETH', 'PT sUSDe Sep', 'PT USDe Sep',
|
|
68
68
|
'PT sUSDe Nov', 'PT USDe Nov', 'PT USDe Jan', 'PT sUSDe Jan', 'wrsETH', 'wstETH', 'syrupUSDT', 'syrupUSDC', 'wstUSR',
|
|
69
|
-
'PT sUSDe Feb', 'PT USDe Feb',
|
|
69
|
+
'PT sUSDe Feb', 'PT USDe Feb', 'PT USDe Apr', 'PT sUSDe Apr',
|
|
70
70
|
];
|
|
71
71
|
export const getStakingApy = memoize((asset_1, ...args_1) => __awaiter(void 0, [asset_1, ...args_1], void 0, function* (asset, network = NetworkNumber.Eth) {
|
|
72
72
|
try {
|
|
@@ -130,6 +130,10 @@ export const getStakingApy = memoize((asset_1, ...args_1) => __awaiter(void 0, [
|
|
|
130
130
|
return yield getApyFromDfsApi('PT sUSDe Feb', network);
|
|
131
131
|
if (asset === 'PT USDe Feb')
|
|
132
132
|
return yield getApyFromDfsApi('PT USDe Feb', network);
|
|
133
|
+
if (asset === 'PT sUSDe Apr')
|
|
134
|
+
return yield getApyFromDfsApi('PT sUSDe Apr', network);
|
|
135
|
+
if (asset === 'PT USDe Apr')
|
|
136
|
+
return yield getApyFromDfsApi('PT USDe Apr', network);
|
|
133
137
|
}
|
|
134
138
|
catch (e) {
|
|
135
139
|
console.error(`Failed to fetch APY for ${asset}`);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { EthAddress, IncentiveData, NetworkNumber } from './common';
|
|
2
|
+
export declare enum AaveV4SpokesType {
|
|
3
|
+
AaveV4CoreSpoke = "aave_v4_core_spoke"
|
|
4
|
+
}
|
|
5
|
+
export declare enum AaveV4HubsType {
|
|
6
|
+
AaveV4CoreHub = "aave_v4_core_hub"
|
|
7
|
+
}
|
|
8
|
+
export interface AaveV4SpokeInfo {
|
|
9
|
+
chainIds: NetworkNumber[];
|
|
10
|
+
label: string;
|
|
11
|
+
value: AaveV4SpokesType;
|
|
12
|
+
url: string;
|
|
13
|
+
address: EthAddress;
|
|
14
|
+
hubs: EthAddress[];
|
|
15
|
+
}
|
|
16
|
+
export interface AaveV4HubAssetOnChainData {
|
|
17
|
+
assetId: number;
|
|
18
|
+
drawnRate: bigint;
|
|
19
|
+
}
|
|
20
|
+
export interface AaveV4HubOnChainData {
|
|
21
|
+
assets: Record<number, AaveV4HubAssetOnChainData>;
|
|
22
|
+
}
|
|
23
|
+
export interface AaveV4ReserveAssetOnChain {
|
|
24
|
+
underlying: EthAddress;
|
|
25
|
+
hub: EthAddress;
|
|
26
|
+
assetId: number;
|
|
27
|
+
decimals: number;
|
|
28
|
+
paused: boolean;
|
|
29
|
+
frozen: boolean;
|
|
30
|
+
borrowable: boolean;
|
|
31
|
+
collateralRisk: number;
|
|
32
|
+
collateralFactor: number;
|
|
33
|
+
maxLiquidationBonus: number;
|
|
34
|
+
liquidationFee: number;
|
|
35
|
+
price: bigint;
|
|
36
|
+
totalSupplied: bigint;
|
|
37
|
+
totalDrawn: bigint;
|
|
38
|
+
totalPremium: bigint;
|
|
39
|
+
totalDebt: bigint;
|
|
40
|
+
supplyCap: bigint;
|
|
41
|
+
borrowCap: bigint;
|
|
42
|
+
deficitRay: bigint;
|
|
43
|
+
spokeActive: boolean;
|
|
44
|
+
spokePaused: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface AaveV4ReserveAssetData {
|
|
47
|
+
symbol: string;
|
|
48
|
+
underlying: EthAddress;
|
|
49
|
+
hub: EthAddress;
|
|
50
|
+
assetId: number;
|
|
51
|
+
reserveId: number;
|
|
52
|
+
paused: boolean;
|
|
53
|
+
frozen: boolean;
|
|
54
|
+
borrowable: boolean;
|
|
55
|
+
collateralRisk: number;
|
|
56
|
+
collateralFactor: number;
|
|
57
|
+
liquidationFee: number;
|
|
58
|
+
price: string;
|
|
59
|
+
totalSupplied: string;
|
|
60
|
+
totalDrawn: string;
|
|
61
|
+
totalPremium: string;
|
|
62
|
+
totalDebt: string;
|
|
63
|
+
supplyCap: string;
|
|
64
|
+
borrowCap: string;
|
|
65
|
+
spokeActive: boolean;
|
|
66
|
+
spokePaused: boolean;
|
|
67
|
+
drawnRate: string;
|
|
68
|
+
supplyRate: string;
|
|
69
|
+
supplyIncentives: IncentiveData[];
|
|
70
|
+
borrowIncentives: IncentiveData[];
|
|
71
|
+
canBeBorrowed: boolean;
|
|
72
|
+
canBeSupplied: boolean;
|
|
73
|
+
canBeWithdrawn: boolean;
|
|
74
|
+
canBePayBacked: boolean;
|
|
75
|
+
utilization: string;
|
|
76
|
+
}
|
|
77
|
+
export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
|
|
78
|
+
export interface AaveV4SpokeData {
|
|
79
|
+
assetsData: AaveV4AssetsData;
|
|
80
|
+
oracle: EthAddress;
|
|
81
|
+
oracleDecimals: number;
|
|
82
|
+
address: EthAddress;
|
|
83
|
+
}
|
|
84
|
+
export interface AaveV4UsedReserveAsset {
|
|
85
|
+
symbol: string;
|
|
86
|
+
assetId: number;
|
|
87
|
+
reserveId: number;
|
|
88
|
+
supplied: string;
|
|
89
|
+
suppliedUsd: string;
|
|
90
|
+
drawn: string;
|
|
91
|
+
drawnUsd: string;
|
|
92
|
+
premium: string;
|
|
93
|
+
premiumUsd: string;
|
|
94
|
+
borrowed: string;
|
|
95
|
+
borrowedUsd: string;
|
|
96
|
+
isSupplied: boolean;
|
|
97
|
+
isBorrowed: boolean;
|
|
98
|
+
collateral: boolean;
|
|
99
|
+
collateralFactor: number;
|
|
100
|
+
}
|
|
101
|
+
export interface AaveV4AggregatedPositionData {
|
|
102
|
+
suppliedUsd: string;
|
|
103
|
+
suppliedCollateralUsd: string;
|
|
104
|
+
borrowLimitUsd: string;
|
|
105
|
+
liquidationLimitUsd: string;
|
|
106
|
+
borrowedUsd: string;
|
|
107
|
+
drawnUsd: string;
|
|
108
|
+
premiumUsd: string;
|
|
109
|
+
leftToBorrowUsd: string;
|
|
110
|
+
ratio: string;
|
|
111
|
+
collRatio: string;
|
|
112
|
+
liqRatio: string;
|
|
113
|
+
liqPercent: string;
|
|
114
|
+
leveragedType: string;
|
|
115
|
+
leveragedAsset: string;
|
|
116
|
+
liquidationPrice: string;
|
|
117
|
+
leveragedLsdAssetRatio?: string;
|
|
118
|
+
minCollRatio: string;
|
|
119
|
+
collLiquidationRatio: string;
|
|
120
|
+
minHealthRatio: string;
|
|
121
|
+
netApy: string;
|
|
122
|
+
incentiveUsd: string;
|
|
123
|
+
totalInterestUsd: string;
|
|
124
|
+
}
|
|
125
|
+
export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
|
|
126
|
+
export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
|
|
127
|
+
usedAssets: AaveV4UsedReserveAssets;
|
|
128
|
+
healthFactor: string;
|
|
129
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var AaveV4SpokesType;
|
|
2
|
+
(function (AaveV4SpokesType) {
|
|
3
|
+
AaveV4SpokesType["AaveV4CoreSpoke"] = "aave_v4_core_spoke";
|
|
4
|
+
})(AaveV4SpokesType || (AaveV4SpokesType = {}));
|
|
5
|
+
export var AaveV4HubsType;
|
|
6
|
+
(function (AaveV4HubsType) {
|
|
7
|
+
AaveV4HubsType["AaveV4CoreHub"] = "aave_v4_core_hub";
|
|
8
|
+
})(AaveV4HubsType || (AaveV4HubsType = {}));
|
package/esm/types/index.d.ts
CHANGED
package/esm/types/index.js
CHANGED
package/esm/types/portfolio.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
|
|
2
3
|
import { EthAddress } from './common';
|
|
3
4
|
import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
4
5
|
import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
@@ -51,6 +52,9 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
51
52
|
[key: string]: FluidVaultData;
|
|
52
53
|
};
|
|
53
54
|
};
|
|
55
|
+
aaveV4: {
|
|
56
|
+
[key in AaveV4SpokesType]?: PortfolioProtocolData<AaveV4AccountData>;
|
|
57
|
+
};
|
|
54
58
|
}
|
|
55
59
|
export interface PortfolioPositionsData {
|
|
56
60
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.49-aave-v4-dev-1-dev",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "",
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@defisaver/tokens": "^1.7.
|
|
24
|
+
"@defisaver/tokens": "^1.7.19",
|
|
25
25
|
"@types/lodash": "^4.17.15",
|
|
26
26
|
"@types/memoizee": "^0.4.12",
|
|
27
27
|
"decimal.js": "^10.6.0",
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
3
|
+
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
|
+
import { getViemProvider } from '../services/viem';
|
|
5
|
+
import {
|
|
6
|
+
AaveV4AccountData,
|
|
7
|
+
AaveV4HubAssetOnChainData,
|
|
8
|
+
AaveV4HubOnChainData,
|
|
9
|
+
AaveV4ReserveAssetData, AaveV4ReserveAssetOnChain, AaveV4SpokeData, AaveV4SpokeInfo,
|
|
10
|
+
AaveV4UsedReserveAssets,
|
|
11
|
+
} from '../types';
|
|
12
|
+
import {
|
|
13
|
+
EthAddress, EthereumProvider, IncentiveData, IncentiveKind, NetworkNumber,
|
|
14
|
+
} from '../types/common';
|
|
15
|
+
import { AaveV4ViewContractViem } from '../contracts';
|
|
16
|
+
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
17
|
+
import { wethToEth } from '../services/utils';
|
|
18
|
+
import { aaveV4GetAggregatedPositionData } from '../helpers/aaveV4Helpers';
|
|
19
|
+
|
|
20
|
+
const fetchHubData = async (viewContract: ReturnType<typeof AaveV4ViewContractViem>, hubAddress: EthAddress): Promise<AaveV4HubOnChainData> => {
|
|
21
|
+
const hubData = await viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
22
|
+
return {
|
|
23
|
+
assets: hubData.reduce((acc: Record<number, AaveV4HubAssetOnChainData>, assetOnChainData) => {
|
|
24
|
+
acc[assetOnChainData.assetId] = {
|
|
25
|
+
assetId: assetOnChainData.assetId,
|
|
26
|
+
drawnRate: assetOnChainData.drawnRate,
|
|
27
|
+
};
|
|
28
|
+
return acc;
|
|
29
|
+
}, {}),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAsset: AaveV4HubAssetOnChainData, reserveId: number, oracleDecimals: number, network: NetworkNumber): Promise<AaveV4ReserveAssetData> => {
|
|
34
|
+
const assetInfo = getAssetInfoByAddress(reserveAsset.underlying, network);
|
|
35
|
+
const symbol = wethToEth(assetInfo.symbol);
|
|
36
|
+
|
|
37
|
+
const isStakingAsset = STAKING_ASSETS.includes(symbol);
|
|
38
|
+
const supplyIncentives: IncentiveData[] = [];
|
|
39
|
+
const borrowIncentives: IncentiveData[] = [];
|
|
40
|
+
|
|
41
|
+
if (isStakingAsset) {
|
|
42
|
+
const yieldApy = await getStakingApy(symbol, network as NetworkNumber);
|
|
43
|
+
supplyIncentives.push({
|
|
44
|
+
apy: yieldApy,
|
|
45
|
+
token: symbol,
|
|
46
|
+
incentiveKind: IncentiveKind.Staking,
|
|
47
|
+
description: `Native ${symbol} yield.`,
|
|
48
|
+
});
|
|
49
|
+
if (reserveAsset.borrowable) {
|
|
50
|
+
// when borrowing assets whose value increases over time
|
|
51
|
+
borrowIncentives.push({
|
|
52
|
+
apy: new Dec(yieldApy).mul(-1).toString(),
|
|
53
|
+
token: symbol,
|
|
54
|
+
incentiveKind: IncentiveKind.Reward,
|
|
55
|
+
description: `Due to the native yield of ${symbol}, the value of the debt would increase over time.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return ({
|
|
61
|
+
symbol,
|
|
62
|
+
underlying: reserveAsset.underlying,
|
|
63
|
+
hub: reserveAsset.hub,
|
|
64
|
+
assetId: reserveAsset.assetId,
|
|
65
|
+
reserveId,
|
|
66
|
+
paused: reserveAsset.paused,
|
|
67
|
+
frozen: reserveAsset.frozen,
|
|
68
|
+
borrowable: reserveAsset.borrowable,
|
|
69
|
+
collateralRisk: new Dec(reserveAsset.collateralRisk).div(10000).toNumber(),
|
|
70
|
+
collateralFactor: new Dec(reserveAsset.collateralFactor).div(10000).toNumber(),
|
|
71
|
+
liquidationFee: new Dec(reserveAsset.liquidationFee).div(10000).toNumber(),
|
|
72
|
+
price: new Dec(reserveAsset.price).div(new Dec(10).pow(oracleDecimals)).toString(),
|
|
73
|
+
totalSupplied: assetAmountInEth(reserveAsset.totalSupplied.toString(), symbol),
|
|
74
|
+
totalDrawn: assetAmountInEth(reserveAsset.totalDrawn.toString(), symbol),
|
|
75
|
+
totalPremium: assetAmountInEth(reserveAsset.totalPremium.toString(), symbol),
|
|
76
|
+
totalDebt: assetAmountInEth(reserveAsset.totalDebt.toString(), symbol),
|
|
77
|
+
supplyCap: assetAmountInEth(reserveAsset.supplyCap.toString(), symbol),
|
|
78
|
+
borrowCap: assetAmountInEth(reserveAsset.borrowCap.toString(), symbol),
|
|
79
|
+
spokeActive: reserveAsset.spokeActive,
|
|
80
|
+
spokePaused: reserveAsset.spokePaused,
|
|
81
|
+
drawnRate: new Dec(hubAsset.drawnRate).div(new Dec(10).pow(27)).toString(),
|
|
82
|
+
supplyRate: '0', // To be implemented
|
|
83
|
+
supplyIncentives,
|
|
84
|
+
borrowIncentives,
|
|
85
|
+
canBeBorrowed: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused && !reserveAsset.frozen,
|
|
86
|
+
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused && !reserveAsset.frozen,
|
|
87
|
+
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
88
|
+
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
89
|
+
utilization: new Dec(reserveAsset.totalDrawn.toString()).times(100).div(new Dec(reserveAsset.totalSupplied.toString())).toString(),
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export async function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4SpokeData> {
|
|
94
|
+
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
95
|
+
|
|
96
|
+
const hubsData: Record<EthAddress, AaveV4HubOnChainData> = {};
|
|
97
|
+
const [spokeData] = await Promise.all([
|
|
98
|
+
viewContract.read.getSpokeDataFull([market.address]),
|
|
99
|
+
...market.hubs.map(async (hubAddress) => {
|
|
100
|
+
hubsData[hubAddress] = await fetchHubData(viewContract, hubAddress);
|
|
101
|
+
}),
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
const reserveAssetsArray = await Promise.all(spokeData[1].map(async (reserveAssetOnChain: AaveV4ReserveAssetOnChain, index: number) => formatReserveAsset(reserveAssetOnChain, hubsData[reserveAssetOnChain.hub].assets[reserveAssetOnChain.assetId], index, +spokeData[0].oracleDecimals.toString(), network)));
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
assetsData: reserveAssetsArray.reduce((acc: Record<string, AaveV4ReserveAssetData>, reserveAsset: AaveV4ReserveAssetData) => {
|
|
108
|
+
acc[`${reserveAsset.symbol}-${reserveAsset.reserveId}`] = reserveAsset;
|
|
109
|
+
return acc;
|
|
110
|
+
}, {}),
|
|
111
|
+
oracle: spokeData[0].oracle,
|
|
112
|
+
oracleDecimals: +spokeData[0].oracleDecimals.toString(),
|
|
113
|
+
address: market.address,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4SpokeData> {
|
|
118
|
+
return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4AccountData> {
|
|
122
|
+
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
123
|
+
|
|
124
|
+
const loanData = await viewContract.read.getLoanData([spokeData.address, address]);
|
|
125
|
+
|
|
126
|
+
const healthFactor = new Dec(loanData.healthFactor).div(1e18).toString();
|
|
127
|
+
const usedAssets = loanData.reserves.reduce((acc: AaveV4UsedReserveAssets, usedReserveAsset) => {
|
|
128
|
+
const identifier = `${wethToEth(getAssetInfoByAddress(usedReserveAsset.underlying, network).symbol)}-${+usedReserveAsset.reserveId.toString()}`;
|
|
129
|
+
const reserveData = spokeData.assetsData[identifier];
|
|
130
|
+
const price = reserveData.price;
|
|
131
|
+
const supplied = assetAmountInEth(usedReserveAsset.supplied.toString(), reserveData.symbol);
|
|
132
|
+
const drawn = assetAmountInEth(usedReserveAsset.drawn.toString(), reserveData.symbol);
|
|
133
|
+
const premium = assetAmountInEth(usedReserveAsset.premium.toString(), reserveData.symbol);
|
|
134
|
+
const borrowed = assetAmountInEth(usedReserveAsset.totalDebt.toString(), reserveData.symbol);
|
|
135
|
+
acc[identifier] = {
|
|
136
|
+
symbol: reserveData.symbol,
|
|
137
|
+
assetId: reserveData.assetId,
|
|
138
|
+
reserveId: +usedReserveAsset.reserveId.toString(),
|
|
139
|
+
supplied,
|
|
140
|
+
suppliedUsd: new Dec(supplied).mul(price).toString(),
|
|
141
|
+
drawn,
|
|
142
|
+
drawnUsd: new Dec(drawn).mul(price).toString(),
|
|
143
|
+
premium,
|
|
144
|
+
premiumUsd: new Dec(premium).mul(price).toString(),
|
|
145
|
+
borrowed,
|
|
146
|
+
borrowedUsd: new Dec(borrowed).mul(price).toString(),
|
|
147
|
+
isSupplied: !new Dec(supplied).eq(0),
|
|
148
|
+
isBorrowed: usedReserveAsset.isBorrowing,
|
|
149
|
+
collateral: usedReserveAsset.isUsingAsCollateral,
|
|
150
|
+
collateralFactor: new Dec(usedReserveAsset.collateralFactor).div(10000).toNumber(),
|
|
151
|
+
};
|
|
152
|
+
return acc;
|
|
153
|
+
}, {});
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
usedAssets,
|
|
157
|
+
healthFactor,
|
|
158
|
+
...aaveV4GetAggregatedPositionData({
|
|
159
|
+
usedAssets,
|
|
160
|
+
assetsData: spokeData.assetsData,
|
|
161
|
+
network,
|
|
162
|
+
useUserCollateralFactor: true,
|
|
163
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function getAaveV4AccountData(provider: EthereumProvider, network: NetworkNumber, marketData: AaveV4SpokeData, address: EthAddress, blockNumber: 'latest' | number = 'latest'): Promise<any> {
|
|
168
|
+
return _getAaveV4AccountData(getViemProvider(provider, network), network, marketData, address, blockNumber);
|
|
169
|
+
}
|