@defisaver/positions-sdk 2.1.52-aave-v4 → 2.1.52-dev-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +64 -64
- package/cjs/config/contracts.d.ts +0 -1277
- package/cjs/config/contracts.js +0 -9
- package/cjs/contracts.d.ts +0 -23120
- package/cjs/contracts.js +1 -2
- package/cjs/fluid/index.d.ts +3 -3
- package/cjs/helpers/aaveHelpers/index.d.ts +2 -2
- package/cjs/helpers/aaveHelpers/index.js +18 -2
- package/cjs/helpers/compoundHelpers/index.js +1 -1
- package/cjs/helpers/eulerHelpers/index.d.ts +2 -2
- package/cjs/helpers/eulerHelpers/index.js +6 -5
- package/cjs/helpers/fluidHelpers/index.js +2 -1
- package/cjs/helpers/index.d.ts +0 -1
- package/cjs/helpers/index.js +1 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +67 -67
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/index.d.ts +1 -2
- package/cjs/index.js +1 -3
- package/cjs/markets/index.d.ts +0 -1
- package/cjs/markets/index.js +1 -3
- package/cjs/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/cjs/moneymarket/moneymarketCommonService.js +14 -6
- package/cjs/portfolio/index.js +0 -20
- package/cjs/savings/morphoVaults/index.js +17 -17
- package/cjs/types/aave.d.ts +3 -2
- package/cjs/types/common.d.ts +8 -0
- package/cjs/types/common.js +10 -1
- package/cjs/types/compound.d.ts +2 -2
- package/cjs/types/curveUsd.d.ts +2 -2
- package/cjs/types/euler.d.ts +2 -2
- package/cjs/types/fluid.d.ts +2 -2
- package/cjs/types/index.d.ts +0 -1
- package/cjs/types/index.js +0 -1
- package/cjs/types/liquityV2.d.ts +3 -3
- package/cjs/types/llamaLend.d.ts +2 -2
- package/cjs/types/morphoBlue.d.ts +3 -3
- package/cjs/types/portfolio.d.ts +0 -4
- package/cjs/types/spark.d.ts +2 -2
- package/esm/config/contracts.d.ts +0 -1277
- package/esm/config/contracts.js +0 -8
- package/esm/contracts.d.ts +0 -23120
- package/esm/contracts.js +0 -1
- package/esm/fluid/index.d.ts +3 -3
- package/esm/helpers/aaveHelpers/index.d.ts +2 -2
- package/esm/helpers/aaveHelpers/index.js +18 -2
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/eulerHelpers/index.d.ts +2 -2
- package/esm/helpers/eulerHelpers/index.js +6 -5
- package/esm/helpers/fluidHelpers/index.js +2 -1
- package/esm/helpers/index.d.ts +0 -1
- package/esm/helpers/index.js +0 -1
- package/esm/helpers/morphoBlueHelpers/index.js +68 -68
- package/esm/helpers/sparkHelpers/index.js +2 -2
- package/esm/index.d.ts +1 -2
- package/esm/index.js +1 -2
- package/esm/markets/index.d.ts +0 -1
- package/esm/markets/index.js +0 -1
- package/esm/moneymarket/moneymarketCommonService.d.ts +3 -3
- package/esm/moneymarket/moneymarketCommonService.js +14 -6
- package/esm/portfolio/index.js +1 -21
- package/esm/savings/morphoVaults/index.js +17 -17
- package/esm/types/aave.d.ts +3 -2
- package/esm/types/common.d.ts +8 -0
- package/esm/types/common.js +9 -0
- package/esm/types/compound.d.ts +2 -2
- package/esm/types/curveUsd.d.ts +2 -2
- package/esm/types/euler.d.ts +2 -2
- package/esm/types/fluid.d.ts +2 -2
- package/esm/types/fluid.js +1 -1
- package/esm/types/index.d.ts +0 -1
- package/esm/types/index.js +0 -1
- package/esm/types/liquityV2.d.ts +3 -3
- package/esm/types/llamaLend.d.ts +2 -2
- package/esm/types/morphoBlue.d.ts +3 -3
- package/esm/types/portfolio.d.ts +0 -4
- package/esm/types/spark.d.ts +2 -2
- package/package.json +48 -48
- package/src/aaveV2/index.ts +240 -240
- package/src/aaveV3/index.ts +635 -635
- package/src/aaveV3/merit.ts +97 -97
- package/src/aaveV3/merkl.ts +74 -74
- package/src/claiming/aaveV3.ts +154 -154
- package/src/claiming/compV3.ts +22 -22
- package/src/claiming/ethena.ts +61 -61
- package/src/claiming/index.ts +12 -12
- package/src/claiming/king.ts +66 -66
- package/src/claiming/morphoBlue.ts +118 -118
- package/src/claiming/spark.ts +225 -225
- package/src/compoundV2/index.ts +244 -244
- package/src/compoundV3/index.ts +274 -274
- package/src/config/contracts.ts +1320 -1328
- package/src/constants/index.ts +10 -10
- package/src/contracts.ts +172 -174
- package/src/curveUsd/index.ts +254 -254
- package/src/eulerV2/index.ts +324 -324
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1800 -1800
- package/src/helpers/aaveHelpers/index.ts +207 -191
- package/src/helpers/compoundHelpers/index.ts +283 -283
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +222 -222
- package/src/helpers/fluidHelpers/index.ts +326 -326
- package/src/helpers/index.ts +10 -11
- package/src/helpers/liquityV2Helpers/index.ts +82 -82
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +52 -52
- package/src/helpers/morphoBlueHelpers/index.ts +396 -396
- package/src/helpers/sparkHelpers/index.ts +160 -158
- package/src/index.ts +49 -51
- package/src/liquity/index.ts +159 -159
- package/src/liquityV2/index.ts +703 -703
- package/src/llamaLend/index.ts +305 -305
- package/src/maker/index.ts +223 -223
- package/src/markets/aave/index.ts +118 -118
- package/src/markets/aave/marketAssets.ts +54 -54
- package/src/markets/compound/index.ts +243 -243
- package/src/markets/compound/marketsAssets.ts +97 -97
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2900 -2900
- package/src/markets/index.ts +25 -26
- package/src/markets/liquityV2/index.ts +102 -102
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +988 -988
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +12 -12
- package/src/moneymarket/moneymarketCommonService.ts +92 -85
- package/src/morphoBlue/index.ts +274 -274
- package/src/portfolio/index.ts +586 -606
- package/src/savings/index.ts +95 -95
- package/src/savings/makerDsr/index.ts +53 -53
- package/src/savings/makerDsr/options.ts +9 -9
- package/src/savings/morphoVaults/index.ts +80 -80
- package/src/savings/morphoVaults/options.ts +193 -193
- package/src/savings/skyOptions/index.ts +95 -95
- package/src/savings/skyOptions/options.ts +10 -10
- package/src/savings/sparkSavingsVaults/index.ts +60 -60
- package/src/savings/sparkSavingsVaults/options.ts +35 -35
- package/src/savings/yearnV3Vaults/index.ts +61 -61
- package/src/savings/yearnV3Vaults/options.ts +55 -55
- package/src/savings/yearnVaults/index.ts +73 -73
- package/src/savings/yearnVaults/options.ts +32 -32
- package/src/services/priceService.ts +278 -278
- package/src/services/utils.ts +115 -115
- package/src/services/viem.ts +57 -57
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +459 -459
- package/src/staking/eligibility.ts +53 -53
- package/src/staking/index.ts +1 -1
- package/src/staking/staking.ts +192 -192
- package/src/types/aave.ts +200 -198
- package/src/types/claiming.ts +114 -114
- package/src/types/common.ts +116 -107
- package/src/types/compound.ts +145 -144
- package/src/types/curveUsd.ts +123 -123
- package/src/types/euler.ts +176 -175
- package/src/types/fluid.ts +485 -483
- package/src/types/index.ts +15 -16
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +128 -126
- package/src/types/llamaLend.ts +161 -159
- package/src/types/maker.ts +63 -63
- package/src/types/merit.ts +1 -1
- package/src/types/merkl.ts +70 -70
- package/src/types/morphoBlue.ts +202 -202
- package/src/types/portfolio.ts +60 -64
- package/src/types/savings/index.ts +23 -23
- package/src/types/savings/makerDsr.ts +13 -13
- package/src/types/savings/morphoVaults.ts +32 -32
- package/src/types/savings/sky.ts +14 -14
- package/src/types/savings/sparkSavingsVaults.ts +15 -15
- package/src/types/savings/yearnV3Vaults.ts +17 -17
- package/src/types/savings/yearnVaults.ts +14 -14
- package/src/types/spark.ts +135 -134
- package/src/umbrella/index.ts +69 -69
- package/src/umbrella/umbrellaUtils.ts +29 -29
- package/cjs/aaveV4/index.d.ts +0 -7
- package/cjs/aaveV4/index.js +0 -174
- package/cjs/helpers/aaveV4Helpers/index.d.ts +0 -13
- package/cjs/helpers/aaveV4Helpers/index.js +0 -109
- package/cjs/markets/aaveV4/index.d.ts +0 -13
- package/cjs/markets/aaveV4/index.js +0 -39
- package/cjs/types/aaveV4.d.ts +0 -137
- package/cjs/types/aaveV4.js +0 -11
- package/esm/aaveV4/index.d.ts +0 -7
- package/esm/aaveV4/index.js +0 -165
- package/esm/helpers/aaveV4Helpers/index.d.ts +0 -13
- package/esm/helpers/aaveV4Helpers/index.js +0 -100
- package/esm/markets/aaveV4/index.d.ts +0 -13
- package/esm/markets/aaveV4/index.js +0 -29
- package/esm/types/aaveV4.d.ts +0 -137
- package/esm/types/aaveV4.js +0 -8
- package/src/aaveV4/index.ts +0 -176
- package/src/helpers/aaveV4Helpers/index.ts +0 -121
- package/src/markets/aaveV4/index.ts +0 -42
- package/src/types/aaveV4.ts +0 -151
package/esm/aaveV4/index.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import Dec from 'decimal.js';
|
|
11
|
-
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
12
|
-
import { getViemProvider } from '../services/viem';
|
|
13
|
-
import { IncentiveKind, } from '../types/common';
|
|
14
|
-
import { AaveV4ViewContractViem } from '../contracts';
|
|
15
|
-
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
|
-
import { wethToEth } from '../services/utils';
|
|
17
|
-
import { aaveV4GetAggregatedPositionData } from '../helpers/aaveV4Helpers';
|
|
18
|
-
import { getAaveV4HubByAddress } from '../markets/aaveV4';
|
|
19
|
-
const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
21
|
-
return {
|
|
22
|
-
assets: hubData.reduce((acc, assetOnChainData) => {
|
|
23
|
-
acc[assetOnChainData.assetId] = {
|
|
24
|
-
assetId: assetOnChainData.assetId,
|
|
25
|
-
drawnRate: assetOnChainData.drawnRate,
|
|
26
|
-
};
|
|
27
|
-
return acc;
|
|
28
|
-
}, {}),
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
const assetInfo = getAssetInfoByAddress(reserveAsset.underlying, network);
|
|
33
|
-
const symbol = wethToEth(assetInfo.symbol);
|
|
34
|
-
const hubInfo = getAaveV4HubByAddress(network, reserveAsset.hub);
|
|
35
|
-
if (!hubInfo) {
|
|
36
|
-
throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
|
|
37
|
-
}
|
|
38
|
-
const isStakingAsset = STAKING_ASSETS.includes(symbol);
|
|
39
|
-
const supplyIncentives = [];
|
|
40
|
-
const borrowIncentives = [];
|
|
41
|
-
if (isStakingAsset) {
|
|
42
|
-
const yieldApy = yield getStakingApy(symbol, network);
|
|
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
|
-
return ({
|
|
60
|
-
symbol,
|
|
61
|
-
underlying: reserveAsset.underlying,
|
|
62
|
-
hub: hubInfo.address,
|
|
63
|
-
hubName: hubInfo === null || hubInfo === void 0 ? void 0 : hubInfo.label,
|
|
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
|
-
export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
93
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
94
|
-
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
95
|
-
const hubsData = {};
|
|
96
|
-
const [spokeData] = yield Promise.all([
|
|
97
|
-
viewContract.read.getSpokeDataFull([market.address]),
|
|
98
|
-
...market.hubs.map((hubAddress) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
hubsData[hubAddress] = yield fetchHubData(viewContract, hubAddress);
|
|
100
|
-
})),
|
|
101
|
-
]);
|
|
102
|
-
const reserveAssetsArray = yield Promise.all(spokeData[1].map((reserveAssetOnChain, index) => __awaiter(this, void 0, void 0, function* () { return formatReserveAsset(reserveAssetOnChain, hubsData[reserveAssetOnChain.hub].assets[reserveAssetOnChain.assetId], index, +spokeData[0].oracleDecimals.toString(), network); })));
|
|
103
|
-
return {
|
|
104
|
-
assetsData: reserveAssetsArray.reduce((acc, reserveAsset) => {
|
|
105
|
-
acc[`${reserveAsset.symbol}-${reserveAsset.reserveId}`] = reserveAsset;
|
|
106
|
-
return acc;
|
|
107
|
-
}, {}),
|
|
108
|
-
oracle: spokeData[0].oracle,
|
|
109
|
-
oracleDecimals: +spokeData[0].oracleDecimals.toString(),
|
|
110
|
-
address: market.address,
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
export function getAaveV4SpokeData(provider_1, network_1, spoke_1) {
|
|
115
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, spoke, blockNumber = 'latest') {
|
|
116
|
-
return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
export function _getAaveV4AccountData(provider_1, network_1, spokeData_1, address_1) {
|
|
120
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, spokeData, address, blockNumber = 'latest') {
|
|
121
|
-
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
122
|
-
const loanData = yield viewContract.read.getLoanData([spokeData.address, address]);
|
|
123
|
-
const healthFactor = new Dec(loanData.healthFactor).div(1e18).toString();
|
|
124
|
-
const usedAssets = loanData.reserves.reduce((acc, usedReserveAsset) => {
|
|
125
|
-
const identifier = `${wethToEth(getAssetInfoByAddress(usedReserveAsset.underlying, network).symbol)}-${+usedReserveAsset.reserveId.toString()}`;
|
|
126
|
-
const reserveData = spokeData.assetsData[identifier];
|
|
127
|
-
const price = reserveData.price;
|
|
128
|
-
const supplied = assetAmountInEth(usedReserveAsset.supplied.toString(), reserveData.symbol);
|
|
129
|
-
const drawn = assetAmountInEth(usedReserveAsset.drawn.toString(), reserveData.symbol);
|
|
130
|
-
const premium = assetAmountInEth(usedReserveAsset.premium.toString(), reserveData.symbol);
|
|
131
|
-
const borrowed = assetAmountInEth(usedReserveAsset.totalDebt.toString(), reserveData.symbol);
|
|
132
|
-
acc[identifier] = {
|
|
133
|
-
symbol: reserveData.symbol,
|
|
134
|
-
hubName: reserveData.hubName,
|
|
135
|
-
assetId: reserveData.assetId,
|
|
136
|
-
reserveId: +usedReserveAsset.reserveId.toString(),
|
|
137
|
-
supplied,
|
|
138
|
-
suppliedUsd: new Dec(supplied).mul(price).toString(),
|
|
139
|
-
drawn,
|
|
140
|
-
drawnUsd: new Dec(drawn).mul(price).toString(),
|
|
141
|
-
premium,
|
|
142
|
-
premiumUsd: new Dec(premium).mul(price).toString(),
|
|
143
|
-
borrowed,
|
|
144
|
-
borrowedUsd: new Dec(borrowed).mul(price).toString(),
|
|
145
|
-
isSupplied: !new Dec(supplied).eq(0),
|
|
146
|
-
isBorrowed: usedReserveAsset.isBorrowing,
|
|
147
|
-
collateral: usedReserveAsset.isUsingAsCollateral,
|
|
148
|
-
collateralFactor: new Dec(usedReserveAsset.collateralFactor).div(10000).toNumber(),
|
|
149
|
-
};
|
|
150
|
-
return acc;
|
|
151
|
-
}, {});
|
|
152
|
-
return Object.assign({ usedAssets,
|
|
153
|
-
healthFactor }, aaveV4GetAggregatedPositionData({
|
|
154
|
-
usedAssets,
|
|
155
|
-
assetsData: spokeData.assetsData,
|
|
156
|
-
network,
|
|
157
|
-
useUserCollateralFactor: true,
|
|
158
|
-
}));
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
export function getAaveV4AccountData(provider_1, network_1, marketData_1, address_1) {
|
|
162
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, marketData, address, blockNumber = 'latest') {
|
|
163
|
-
return _getAaveV4AccountData(getViemProvider(provider, network), network, marketData, address, blockNumber);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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 isLeveragedPosAaveV4: (usedAssets: AaveV4UsedReserveAssets, dustLimit?: number) => {
|
|
5
|
-
leveragedType: string;
|
|
6
|
-
leveragedAsset: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData, network, useUserCollateralFactor, }: {
|
|
9
|
-
usedAssets: AaveV4UsedReserveAssets;
|
|
10
|
-
assetsData: AaveV4AssetsData;
|
|
11
|
-
network: NetworkNumber;
|
|
12
|
-
useUserCollateralFactor?: boolean;
|
|
13
|
-
}) => AaveV4AggregatedPositionData;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS } from '../../moneymarket';
|
|
3
|
-
export const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
|
|
4
|
-
export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
5
|
-
let borrowUnstable = 0;
|
|
6
|
-
let supplyStable = 0;
|
|
7
|
-
let borrowStable = 0;
|
|
8
|
-
let supplyUnstable = 0;
|
|
9
|
-
let longAsset = '';
|
|
10
|
-
let shortAsset = '';
|
|
11
|
-
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, reserveId, }) => {
|
|
12
|
-
const spokeAsset = `${symbol}-${reserveId}`;
|
|
13
|
-
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
14
|
-
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
15
|
-
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
16
|
-
supplyStable += 1;
|
|
17
|
-
if (isBorrowed && STABLE_ASSETS.includes(symbol))
|
|
18
|
-
borrowStable += 1;
|
|
19
|
-
if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
|
|
20
|
-
borrowUnstable += 1;
|
|
21
|
-
shortAsset = spokeAsset;
|
|
22
|
-
}
|
|
23
|
-
if (isSupplied && !STABLE_ASSETS.includes(symbol) && collateral) {
|
|
24
|
-
supplyUnstable += 1;
|
|
25
|
-
longAsset = spokeAsset;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
29
|
-
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
30
|
-
// lsd -> liquid staking derivative
|
|
31
|
-
const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH', 'ezETH', 'weETH'].includes(longAsset);
|
|
32
|
-
if (isLong) {
|
|
33
|
-
return {
|
|
34
|
-
leveragedType: 'long',
|
|
35
|
-
leveragedAsset: longAsset,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
if (isShort) {
|
|
39
|
-
return {
|
|
40
|
-
leveragedType: 'short',
|
|
41
|
-
leveragedAsset: shortAsset,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if (isLsdLeveraged) {
|
|
45
|
-
return {
|
|
46
|
-
leveragedType: 'lsd-leverage',
|
|
47
|
-
leveragedAsset: longAsset,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
leveragedType: '',
|
|
52
|
-
leveragedAsset: '',
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useUserCollateralFactor = false, }) => {
|
|
56
|
-
var _a;
|
|
57
|
-
const payload = {};
|
|
58
|
-
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
59
|
-
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
60
|
-
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(aaveV4GetCollateralFactor(assetsData[`${symbol}-${reserveId}`], usedAssets[`${symbol}-${reserveId}`], useUserCollateralFactor)));
|
|
61
|
-
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
62
|
-
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
63
|
-
payload.drawnUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ drawnUsd }) => drawnUsd);
|
|
64
|
-
payload.premiumUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ premiumUsd }) => premiumUsd);
|
|
65
|
-
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
66
|
-
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
67
|
-
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
68
|
-
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
69
|
-
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
70
|
-
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
71
|
-
const { leveragedType, leveragedAsset } = isLeveragedPosAaveV4(usedAssets);
|
|
72
|
-
payload.leveragedType = leveragedType;
|
|
73
|
-
payload.leveragedAsset = leveragedAsset;
|
|
74
|
-
payload.liquidationPrice = '';
|
|
75
|
-
if (leveragedType !== '') {
|
|
76
|
-
const leveragedAssetData = assetsData[leveragedAsset];
|
|
77
|
-
let assetPrice = (leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0';
|
|
78
|
-
if (leveragedType === 'lsd-leverage') {
|
|
79
|
-
// Treat ETH like a stablecoin in a long stETH position
|
|
80
|
-
const ethPrice = ((_a = Object.values(assetsData).find((asset) => asset.symbol === 'ETH')) === null || _a === void 0 ? void 0 : _a.price) || '0';
|
|
81
|
-
payload.leveragedLsdAssetRatio = new Dec((leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0').div(ethPrice).toDP(18).toString();
|
|
82
|
-
assetPrice = new Dec(assetPrice).div(ethPrice).toString();
|
|
83
|
-
}
|
|
84
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
85
|
-
}
|
|
86
|
-
payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
|
|
87
|
-
payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
88
|
-
// payload.healthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
89
|
-
payload.minHealthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowLimitUsd).toDP(4).toString();
|
|
90
|
-
// TODO: Re-implement netApy calculation
|
|
91
|
-
// const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({
|
|
92
|
-
// usedAssets,
|
|
93
|
-
// assetsData,
|
|
94
|
-
// optionalData: { healthRatio: payload.healthRatio },
|
|
95
|
-
// });
|
|
96
|
-
payload.netApy = '0';
|
|
97
|
-
payload.incentiveUsd = '0';
|
|
98
|
-
payload.totalInterestUsd = '0';
|
|
99
|
-
return payload;
|
|
100
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AaveV4HubInfo, AaveV4HubsType, 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;
|
|
8
|
-
export declare const AAVE_V4_CORE_HUB: (networkId: NetworkNumber) => AaveV4HubInfo;
|
|
9
|
-
export declare const AaveV4Hubs: (networkId: NetworkNumber) => {
|
|
10
|
-
readonly aave_v4_core_hub: AaveV4HubInfo;
|
|
11
|
-
};
|
|
12
|
-
export declare const getAaveV4HubTypeInfo: (type: AaveV4HubsType, network?: NetworkNumber) => AaveV4HubInfo;
|
|
13
|
-
export declare const getAaveV4HubByAddress: (networkId: NetworkNumber, address: string) => AaveV4HubInfo | undefined;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AaveV4HubsType, AaveV4SpokesType, } from '../../types';
|
|
2
|
-
import { NetworkNumber } from '../../types/common';
|
|
3
|
-
// SPOKES
|
|
4
|
-
export const AAVE_V4_CORE_SPOKE = (networkId) => ({
|
|
5
|
-
chainIds: [NetworkNumber.Eth],
|
|
6
|
-
label: 'Core Spoke',
|
|
7
|
-
value: AaveV4SpokesType.AaveV4CoreSpoke,
|
|
8
|
-
url: 'core',
|
|
9
|
-
address: '0xBa97c5E52cd5BC3D7950Ae70779F8FfE92d40CdC',
|
|
10
|
-
hubs: [
|
|
11
|
-
'0xaD905aD5EA5B98cD50AE40Cfe368344686a21366',
|
|
12
|
-
],
|
|
13
|
-
});
|
|
14
|
-
export const AaveV4Spokes = (networkId) => ({
|
|
15
|
-
[AaveV4SpokesType.AaveV4CoreSpoke]: AAVE_V4_CORE_SPOKE(networkId),
|
|
16
|
-
});
|
|
17
|
-
export const getAaveV4SpokeTypeInfo = (type, network) => (Object.assign({}, AaveV4Spokes(network !== null && network !== void 0 ? network : NetworkNumber.Eth))[type]);
|
|
18
|
-
// HUBS
|
|
19
|
-
export const AAVE_V4_CORE_HUB = (networkId) => ({
|
|
20
|
-
chainIds: [NetworkNumber.Eth],
|
|
21
|
-
label: 'Core Hub',
|
|
22
|
-
value: AaveV4HubsType.AaveV4CoreHub,
|
|
23
|
-
address: '0xaD905aD5EA5B98cD50AE40Cfe368344686a21366',
|
|
24
|
-
});
|
|
25
|
-
export const AaveV4Hubs = (networkId) => ({
|
|
26
|
-
[AaveV4HubsType.AaveV4CoreHub]: AAVE_V4_CORE_HUB(networkId),
|
|
27
|
-
});
|
|
28
|
-
export const getAaveV4HubTypeInfo = (type, network) => (Object.assign({}, AaveV4Hubs(network !== null && network !== void 0 ? network : NetworkNumber.Eth))[type]);
|
|
29
|
-
export const getAaveV4HubByAddress = (networkId, address) => Object.values(AaveV4Hubs(networkId)).find(hub => hub.address.toLowerCase() === address.toLowerCase());
|
package/esm/types/aaveV4.d.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
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 AaveV4HubInfo {
|
|
17
|
-
chainIds: NetworkNumber[];
|
|
18
|
-
label: string;
|
|
19
|
-
value: AaveV4HubsType;
|
|
20
|
-
address: EthAddress;
|
|
21
|
-
}
|
|
22
|
-
export interface AaveV4HubAssetOnChainData {
|
|
23
|
-
assetId: number;
|
|
24
|
-
drawnRate: bigint;
|
|
25
|
-
}
|
|
26
|
-
export interface AaveV4HubOnChainData {
|
|
27
|
-
assets: Record<number, AaveV4HubAssetOnChainData>;
|
|
28
|
-
}
|
|
29
|
-
export interface AaveV4ReserveAssetOnChain {
|
|
30
|
-
underlying: EthAddress;
|
|
31
|
-
hub: EthAddress;
|
|
32
|
-
assetId: number;
|
|
33
|
-
decimals: number;
|
|
34
|
-
paused: boolean;
|
|
35
|
-
frozen: boolean;
|
|
36
|
-
borrowable: boolean;
|
|
37
|
-
collateralRisk: number;
|
|
38
|
-
collateralFactor: number;
|
|
39
|
-
maxLiquidationBonus: number;
|
|
40
|
-
liquidationFee: number;
|
|
41
|
-
price: bigint;
|
|
42
|
-
totalSupplied: bigint;
|
|
43
|
-
totalDrawn: bigint;
|
|
44
|
-
totalPremium: bigint;
|
|
45
|
-
totalDebt: bigint;
|
|
46
|
-
supplyCap: bigint;
|
|
47
|
-
borrowCap: bigint;
|
|
48
|
-
deficitRay: bigint;
|
|
49
|
-
spokeActive: boolean;
|
|
50
|
-
spokePaused: boolean;
|
|
51
|
-
}
|
|
52
|
-
export interface AaveV4ReserveAssetData {
|
|
53
|
-
symbol: string;
|
|
54
|
-
underlying: EthAddress;
|
|
55
|
-
hub: EthAddress;
|
|
56
|
-
hubName: string;
|
|
57
|
-
assetId: number;
|
|
58
|
-
reserveId: number;
|
|
59
|
-
paused: boolean;
|
|
60
|
-
frozen: boolean;
|
|
61
|
-
borrowable: boolean;
|
|
62
|
-
collateralRisk: number;
|
|
63
|
-
collateralFactor: number;
|
|
64
|
-
liquidationFee: number;
|
|
65
|
-
price: string;
|
|
66
|
-
totalSupplied: string;
|
|
67
|
-
totalDrawn: string;
|
|
68
|
-
totalPremium: string;
|
|
69
|
-
totalDebt: string;
|
|
70
|
-
supplyCap: string;
|
|
71
|
-
borrowCap: string;
|
|
72
|
-
spokeActive: boolean;
|
|
73
|
-
spokePaused: boolean;
|
|
74
|
-
drawnRate: string;
|
|
75
|
-
supplyRate: string;
|
|
76
|
-
supplyIncentives: IncentiveData[];
|
|
77
|
-
borrowIncentives: IncentiveData[];
|
|
78
|
-
canBeBorrowed: boolean;
|
|
79
|
-
canBeSupplied: boolean;
|
|
80
|
-
canBeWithdrawn: boolean;
|
|
81
|
-
canBePayBacked: boolean;
|
|
82
|
-
utilization: string;
|
|
83
|
-
}
|
|
84
|
-
export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
|
|
85
|
-
export interface AaveV4SpokeData {
|
|
86
|
-
assetsData: AaveV4AssetsData;
|
|
87
|
-
oracle: EthAddress;
|
|
88
|
-
oracleDecimals: number;
|
|
89
|
-
address: EthAddress;
|
|
90
|
-
}
|
|
91
|
-
export interface AaveV4UsedReserveAsset {
|
|
92
|
-
symbol: string;
|
|
93
|
-
hubName: string;
|
|
94
|
-
assetId: number;
|
|
95
|
-
reserveId: number;
|
|
96
|
-
supplied: string;
|
|
97
|
-
suppliedUsd: string;
|
|
98
|
-
drawn: string;
|
|
99
|
-
drawnUsd: string;
|
|
100
|
-
premium: string;
|
|
101
|
-
premiumUsd: string;
|
|
102
|
-
borrowed: string;
|
|
103
|
-
borrowedUsd: string;
|
|
104
|
-
isSupplied: boolean;
|
|
105
|
-
isBorrowed: boolean;
|
|
106
|
-
collateral: boolean;
|
|
107
|
-
collateralFactor: number;
|
|
108
|
-
}
|
|
109
|
-
export interface AaveV4AggregatedPositionData {
|
|
110
|
-
suppliedUsd: string;
|
|
111
|
-
suppliedCollateralUsd: string;
|
|
112
|
-
borrowLimitUsd: string;
|
|
113
|
-
liquidationLimitUsd: string;
|
|
114
|
-
borrowedUsd: string;
|
|
115
|
-
drawnUsd: string;
|
|
116
|
-
premiumUsd: string;
|
|
117
|
-
leftToBorrowUsd: string;
|
|
118
|
-
ratio: string;
|
|
119
|
-
collRatio: string;
|
|
120
|
-
liqRatio: string;
|
|
121
|
-
liqPercent: string;
|
|
122
|
-
leveragedType: string;
|
|
123
|
-
leveragedAsset: string;
|
|
124
|
-
liquidationPrice: string;
|
|
125
|
-
leveragedLsdAssetRatio?: string;
|
|
126
|
-
minCollRatio: string;
|
|
127
|
-
collLiquidationRatio: string;
|
|
128
|
-
minHealthRatio: string;
|
|
129
|
-
netApy: string;
|
|
130
|
-
incentiveUsd: string;
|
|
131
|
-
totalInterestUsd: string;
|
|
132
|
-
}
|
|
133
|
-
export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
|
|
134
|
-
export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
|
|
135
|
-
usedAssets: AaveV4UsedReserveAssets;
|
|
136
|
-
healthFactor: string;
|
|
137
|
-
}
|
package/esm/types/aaveV4.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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/src/aaveV4/index.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
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
|
-
import { getAaveV4HubByAddress } from '../markets/aaveV4';
|
|
20
|
-
|
|
21
|
-
const fetchHubData = async (viewContract: ReturnType<typeof AaveV4ViewContractViem>, hubAddress: EthAddress): Promise<AaveV4HubOnChainData> => {
|
|
22
|
-
const hubData = await viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
23
|
-
return {
|
|
24
|
-
assets: hubData.reduce((acc: Record<number, AaveV4HubAssetOnChainData>, assetOnChainData) => {
|
|
25
|
-
acc[assetOnChainData.assetId] = {
|
|
26
|
-
assetId: assetOnChainData.assetId,
|
|
27
|
-
drawnRate: assetOnChainData.drawnRate,
|
|
28
|
-
};
|
|
29
|
-
return acc;
|
|
30
|
-
}, {}),
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAsset: AaveV4HubAssetOnChainData, reserveId: number, oracleDecimals: number, network: NetworkNumber): Promise<AaveV4ReserveAssetData> => {
|
|
35
|
-
const assetInfo = getAssetInfoByAddress(reserveAsset.underlying, network);
|
|
36
|
-
const symbol = wethToEth(assetInfo.symbol);
|
|
37
|
-
const hubInfo = getAaveV4HubByAddress(network, reserveAsset.hub);
|
|
38
|
-
if (!hubInfo) {
|
|
39
|
-
throw new Error(`Hub not found with address: ${reserveAsset.hub}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const isStakingAsset = STAKING_ASSETS.includes(symbol);
|
|
43
|
-
const supplyIncentives: IncentiveData[] = [];
|
|
44
|
-
const borrowIncentives: IncentiveData[] = [];
|
|
45
|
-
|
|
46
|
-
if (isStakingAsset) {
|
|
47
|
-
const yieldApy = await getStakingApy(symbol, network as NetworkNumber);
|
|
48
|
-
supplyIncentives.push({
|
|
49
|
-
apy: yieldApy,
|
|
50
|
-
token: symbol,
|
|
51
|
-
incentiveKind: IncentiveKind.Staking,
|
|
52
|
-
description: `Native ${symbol} yield.`,
|
|
53
|
-
});
|
|
54
|
-
if (reserveAsset.borrowable) {
|
|
55
|
-
// when borrowing assets whose value increases over time
|
|
56
|
-
borrowIncentives.push({
|
|
57
|
-
apy: new Dec(yieldApy).mul(-1).toString(),
|
|
58
|
-
token: symbol,
|
|
59
|
-
incentiveKind: IncentiveKind.Reward,
|
|
60
|
-
description: `Due to the native yield of ${symbol}, the value of the debt would increase over time.`,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return ({
|
|
66
|
-
symbol,
|
|
67
|
-
underlying: reserveAsset.underlying,
|
|
68
|
-
hub: hubInfo.address,
|
|
69
|
-
hubName: hubInfo?.label,
|
|
70
|
-
assetId: reserveAsset.assetId,
|
|
71
|
-
reserveId,
|
|
72
|
-
paused: reserveAsset.paused,
|
|
73
|
-
frozen: reserveAsset.frozen,
|
|
74
|
-
borrowable: reserveAsset.borrowable,
|
|
75
|
-
collateralRisk: new Dec(reserveAsset.collateralRisk).div(10000).toNumber(),
|
|
76
|
-
collateralFactor: new Dec(reserveAsset.collateralFactor).div(10000).toNumber(),
|
|
77
|
-
liquidationFee: new Dec(reserveAsset.liquidationFee).div(10000).toNumber(),
|
|
78
|
-
price: new Dec(reserveAsset.price).div(new Dec(10).pow(oracleDecimals)).toString(),
|
|
79
|
-
totalSupplied: assetAmountInEth(reserveAsset.totalSupplied.toString(), symbol),
|
|
80
|
-
totalDrawn: assetAmountInEth(reserveAsset.totalDrawn.toString(), symbol),
|
|
81
|
-
totalPremium: assetAmountInEth(reserveAsset.totalPremium.toString(), symbol),
|
|
82
|
-
totalDebt: assetAmountInEth(reserveAsset.totalDebt.toString(), symbol),
|
|
83
|
-
supplyCap: assetAmountInEth(reserveAsset.supplyCap.toString(), symbol),
|
|
84
|
-
borrowCap: assetAmountInEth(reserveAsset.borrowCap.toString(), symbol),
|
|
85
|
-
spokeActive: reserveAsset.spokeActive,
|
|
86
|
-
spokePaused: reserveAsset.spokePaused,
|
|
87
|
-
drawnRate: new Dec(hubAsset.drawnRate).div(new Dec(10).pow(27)).toString(),
|
|
88
|
-
supplyRate: '0', // To be implemented
|
|
89
|
-
supplyIncentives,
|
|
90
|
-
borrowIncentives,
|
|
91
|
-
canBeBorrowed: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused && !reserveAsset.frozen,
|
|
92
|
-
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused && !reserveAsset.frozen,
|
|
93
|
-
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
94
|
-
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
95
|
-
utilization: new Dec(reserveAsset.totalDrawn.toString()).times(100).div(new Dec(reserveAsset.totalSupplied.toString())).toString(),
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export async function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4SpokeData> {
|
|
100
|
-
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
101
|
-
|
|
102
|
-
const hubsData: Record<EthAddress, AaveV4HubOnChainData> = {};
|
|
103
|
-
const [spokeData] = await Promise.all([
|
|
104
|
-
viewContract.read.getSpokeDataFull([market.address]),
|
|
105
|
-
...market.hubs.map(async (hubAddress) => {
|
|
106
|
-
hubsData[hubAddress] = await fetchHubData(viewContract, hubAddress);
|
|
107
|
-
}),
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
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)));
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
assetsData: reserveAssetsArray.reduce((acc: Record<string, AaveV4ReserveAssetData>, reserveAsset: AaveV4ReserveAssetData) => {
|
|
114
|
-
acc[`${reserveAsset.symbol}-${reserveAsset.reserveId}`] = reserveAsset;
|
|
115
|
-
return acc;
|
|
116
|
-
}, {}),
|
|
117
|
-
oracle: spokeData[0].oracle,
|
|
118
|
-
oracleDecimals: +spokeData[0].oracleDecimals.toString(),
|
|
119
|
-
address: market.address,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export async function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4SpokeData> {
|
|
124
|
-
return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4AccountData> {
|
|
128
|
-
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
129
|
-
|
|
130
|
-
const loanData = await viewContract.read.getLoanData([spokeData.address, address]);
|
|
131
|
-
|
|
132
|
-
const healthFactor = new Dec(loanData.healthFactor).div(1e18).toString();
|
|
133
|
-
const usedAssets = loanData.reserves.reduce((acc: AaveV4UsedReserveAssets, usedReserveAsset) => {
|
|
134
|
-
const identifier = `${wethToEth(getAssetInfoByAddress(usedReserveAsset.underlying, network).symbol)}-${+usedReserveAsset.reserveId.toString()}`;
|
|
135
|
-
const reserveData = spokeData.assetsData[identifier];
|
|
136
|
-
const price = reserveData.price;
|
|
137
|
-
const supplied = assetAmountInEth(usedReserveAsset.supplied.toString(), reserveData.symbol);
|
|
138
|
-
const drawn = assetAmountInEth(usedReserveAsset.drawn.toString(), reserveData.symbol);
|
|
139
|
-
const premium = assetAmountInEth(usedReserveAsset.premium.toString(), reserveData.symbol);
|
|
140
|
-
const borrowed = assetAmountInEth(usedReserveAsset.totalDebt.toString(), reserveData.symbol);
|
|
141
|
-
acc[identifier] = {
|
|
142
|
-
symbol: reserveData.symbol,
|
|
143
|
-
hubName: reserveData.hubName,
|
|
144
|
-
assetId: reserveData.assetId,
|
|
145
|
-
reserveId: +usedReserveAsset.reserveId.toString(),
|
|
146
|
-
supplied,
|
|
147
|
-
suppliedUsd: new Dec(supplied).mul(price).toString(),
|
|
148
|
-
drawn,
|
|
149
|
-
drawnUsd: new Dec(drawn).mul(price).toString(),
|
|
150
|
-
premium,
|
|
151
|
-
premiumUsd: new Dec(premium).mul(price).toString(),
|
|
152
|
-
borrowed,
|
|
153
|
-
borrowedUsd: new Dec(borrowed).mul(price).toString(),
|
|
154
|
-
isSupplied: !new Dec(supplied).eq(0),
|
|
155
|
-
isBorrowed: usedReserveAsset.isBorrowing,
|
|
156
|
-
collateral: usedReserveAsset.isUsingAsCollateral,
|
|
157
|
-
collateralFactor: new Dec(usedReserveAsset.collateralFactor).div(10000).toNumber(),
|
|
158
|
-
};
|
|
159
|
-
return acc;
|
|
160
|
-
}, {});
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
usedAssets,
|
|
164
|
-
healthFactor,
|
|
165
|
-
...aaveV4GetAggregatedPositionData({
|
|
166
|
-
usedAssets,
|
|
167
|
-
assetsData: spokeData.assetsData,
|
|
168
|
-
network,
|
|
169
|
-
useUserCollateralFactor: true,
|
|
170
|
-
}),
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export async function getAaveV4AccountData(provider: EthereumProvider, network: NetworkNumber, marketData: AaveV4SpokeData, address: EthAddress, blockNumber: 'latest' | number = 'latest'): Promise<any> {
|
|
175
|
-
return _getAaveV4AccountData(getViemProvider(provider, network), network, marketData, address, blockNumber);
|
|
176
|
-
}
|