@defisaver/positions-sdk 0.0.145 → 0.0.147
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/aaveV3/index.js +2 -4
- package/cjs/helpers/aaveHelpers/index.d.ts +3 -3
- package/cjs/helpers/aaveHelpers/index.js +6 -6
- package/cjs/markets/aave/index.js +2 -0
- package/cjs/markets/aave/marketAssets.js +1 -1
- package/cjs/morphoAaveV3/index.d.ts +2 -2
- package/cjs/morphoAaveV3/index.js +31 -17
- package/cjs/services/utils.d.ts +1 -0
- package/cjs/services/utils.js +4 -1
- package/cjs/types/aave.d.ts +5 -2
- package/esm/aaveV3/index.js +1 -3
- package/esm/helpers/aaveHelpers/index.d.ts +3 -3
- package/esm/helpers/aaveHelpers/index.js +6 -6
- package/esm/markets/aave/index.js +2 -0
- package/esm/markets/aave/marketAssets.js +1 -1
- package/esm/morphoAaveV3/index.d.ts +2 -2
- package/esm/morphoAaveV3/index.js +32 -18
- package/esm/services/utils.d.ts +1 -0
- package/esm/services/utils.js +2 -0
- package/esm/types/aave.d.ts +5 -2
- package/package.json +2 -2
- package/src/aaveV3/index.ts +1 -3
- package/src/helpers/aaveHelpers/index.ts +5 -6
- package/src/markets/aave/index.ts +2 -0
- package/src/markets/aave/marketAssets.ts +1 -1
- package/src/morphoAaveV3/index.ts +34 -19
- package/src/services/utils.ts +3 -0
- package/src/types/aave.ts +2 -3
package/cjs/aaveV3/index.js
CHANGED
|
@@ -72,8 +72,6 @@ const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
72
72
|
return categoriesMapping;
|
|
73
73
|
};
|
|
74
74
|
exports.aaveV3EmodeCategoriesMapping = aaveV3EmodeCategoriesMapping;
|
|
75
|
-
// eslint-disable-next-line no-bitwise
|
|
76
|
-
const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
77
75
|
function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
78
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
77
|
const _addresses = market.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a), network).address);
|
|
@@ -153,9 +151,9 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
153
151
|
const nativeAsset = symbol === 'GHO';
|
|
154
152
|
// eslint-disable-next-line guard-for-in
|
|
155
153
|
for (const eModeIndex in eModeCategoriesData) {
|
|
156
|
-
if (isEnabledOnBitmap(Number(eModeCategoriesData[eModeIndex].collateralBitmap), Number(tokenMarket.assetId)))
|
|
154
|
+
if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoriesData[eModeIndex].collateralBitmap), Number(tokenMarket.assetId)))
|
|
157
155
|
eModeCategoriesData[eModeIndex].collateralAssets.push(symbol);
|
|
158
|
-
if (isEnabledOnBitmap(Number(eModeCategoriesData[eModeIndex].borrowableBitmap), Number(tokenMarket.assetId)))
|
|
156
|
+
if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoriesData[eModeIndex].borrowableBitmap), Number(tokenMarket.assetId)))
|
|
159
157
|
eModeCategoriesData[eModeIndex].borrowAssets.push(symbol);
|
|
160
158
|
}
|
|
161
159
|
let borrowCap = tokenMarket.borrowCap;
|
|
@@ -28,11 +28,11 @@ export declare const aaveV3IsInSiloedMode: ({ usedAssets, assetsData }: {
|
|
|
28
28
|
export declare const aaveAnyGetCollSuppliedAssets: ({ usedAssets }: {
|
|
29
29
|
usedAssets: AaveV3UsedAssets;
|
|
30
30
|
}) => import("../../types").AaveV3UsedAsset[];
|
|
31
|
-
export declare const aaveAnyGetSuppliableAssets: ({ usedAssets, eModeCategory,
|
|
31
|
+
export declare const aaveAnyGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => {
|
|
32
32
|
symbol: string;
|
|
33
33
|
canBeCollateral: boolean;
|
|
34
34
|
}[];
|
|
35
|
-
export declare const aaveAnyGetSuppliableAsCollAssets: ({ usedAssets, eModeCategory,
|
|
35
|
+
export declare const aaveAnyGetSuppliableAsCollAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => {
|
|
36
36
|
symbol: string;
|
|
37
37
|
canBeCollateral: boolean;
|
|
38
38
|
}[];
|
|
@@ -40,7 +40,7 @@ export declare const aaveAnyGetEmodeMutableProps: ({ eModeCategory, eModeCategor
|
|
|
40
40
|
liquidationRatio: any;
|
|
41
41
|
collateralFactor: any;
|
|
42
42
|
};
|
|
43
|
-
export declare const aaveAnyGetAggregatedPositionData: ({ usedAssets, eModeCategory,
|
|
43
|
+
export declare const aaveAnyGetAggregatedPositionData: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => AaveV3AggregatedPositionData;
|
|
44
44
|
export declare const getApyAfterValuesEstimation: (selectedMarket: AaveMarketInfo, actions: [{
|
|
45
45
|
action: string;
|
|
46
46
|
amount: string;
|
|
@@ -51,8 +51,8 @@ const aaveAnyGetCollSuppliedAssets = ({ usedAssets }) => Object.values(usedAsset
|
|
|
51
51
|
.filter(({ isSupplied, collateral }) => isSupplied && collateral);
|
|
52
52
|
exports.aaveAnyGetCollSuppliedAssets = aaveAnyGetCollSuppliedAssets;
|
|
53
53
|
const aaveAnyGetSuppliableAssets = (_a) => {
|
|
54
|
-
var { usedAssets, eModeCategory,
|
|
55
|
-
const data = Object.assign({ usedAssets, eModeCategory,
|
|
54
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
55
|
+
const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
|
|
56
56
|
const collAccountAssets = (0, exports.aaveAnyGetCollSuppliedAssets)(data);
|
|
57
57
|
const marketAssets = Object.values(assetsData);
|
|
58
58
|
if ((0, exports.isMorphoAave)({ selectedMarket })) {
|
|
@@ -68,8 +68,8 @@ const aaveAnyGetSuppliableAssets = (_a) => {
|
|
|
68
68
|
};
|
|
69
69
|
exports.aaveAnyGetSuppliableAssets = aaveAnyGetSuppliableAssets;
|
|
70
70
|
const aaveAnyGetSuppliableAsCollAssets = (_a) => {
|
|
71
|
-
var { usedAssets, eModeCategory,
|
|
72
|
-
return (0, exports.aaveAnyGetSuppliableAssets)(Object.assign({ usedAssets, eModeCategory,
|
|
71
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
72
|
+
return (0, exports.aaveAnyGetSuppliableAssets)(Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest)).filter(({ canBeCollateral }) => canBeCollateral);
|
|
73
73
|
};
|
|
74
74
|
exports.aaveAnyGetSuppliableAsCollAssets = aaveAnyGetSuppliableAsCollAssets;
|
|
75
75
|
const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData, assetsData, }, _asset) => {
|
|
@@ -87,8 +87,8 @@ const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData, asset
|
|
|
87
87
|
};
|
|
88
88
|
exports.aaveAnyGetEmodeMutableProps = aaveAnyGetEmodeMutableProps;
|
|
89
89
|
const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
90
|
-
var { usedAssets, eModeCategory,
|
|
91
|
-
const data = Object.assign({ usedAssets, eModeCategory,
|
|
90
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
91
|
+
const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
|
|
92
92
|
const payload = {};
|
|
93
93
|
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
94
94
|
payload.suppliedCollateralUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
@@ -119,6 +119,8 @@ const MORPHO_AAVE_V3_ETH = (networkId = common_1.NetworkNumber.Eth) => ({
|
|
|
119
119
|
providerAddress: (0, contracts_1.getConfigContractAddress)('AaveV3PoolAddressesProvider', networkId),
|
|
120
120
|
protocolData: 'AaveV3ProtocolDataProvider',
|
|
121
121
|
protocolDataAddress: (0, contracts_1.getConfigContractAddress)('AaveV3ProtocolDataProvider', networkId),
|
|
122
|
+
aaveLendingPool: 'AaveV3LendingPool',
|
|
123
|
+
aaveLendingPoolAddress: (0, contracts_1.getConfigContractAddress)('AaveV3LendingPool', networkId),
|
|
122
124
|
lendingPool: 'MorphoAaveV3ProxyEthMarket',
|
|
123
125
|
lendingPoolAddress: (0, contracts_1.getConfigContractAddress)('MorphoAaveV3ProxyEthMarket', 1),
|
|
124
126
|
// icon: SvgAdapter(protocolIcons.morpho),
|
|
@@ -10,7 +10,7 @@ exports.aaveV1AssetsDefaultMarket = [
|
|
|
10
10
|
exports.aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', 'UNI', 'AAVE', 'BAT', 'BUSD', 'DAI', 'ENJ', 'KNCL', 'LINK', 'MANA', 'MKR', 'REN', 'SNX', 'SUSD', 'TUSD', 'USDC', 'CRV', 'GUSD', 'BAL', 'xSUSHI', 'RENFIL', 'RAI', 'AMPL', 'USDP', 'DPI', 'FRAX', 'FEI', 'stETH', 'ENS', 'UST', 'CVX', '1INCH', 'LUSD'];
|
|
11
11
|
exports.morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WBTC', 'stETH', 'CRV'];
|
|
12
12
|
exports.morphoAaveV3AssetEthMarket = [
|
|
13
|
-
'ETH', 'wstETH', '
|
|
13
|
+
'ETH', 'wstETH', 'USDC', 'WBTC', 'rETH', 'cbETH', 'USDT',
|
|
14
14
|
];
|
|
15
15
|
exports.aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS'];
|
|
16
16
|
exports.aaveV3AssetsDefaultMarketOpt = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
2
|
import { Blockish, EthAddress, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
|
-
import { MorphoAaveV3AssetsData, MorphoAaveV3MarketData, MorphoAaveV3MarketInfo, MorphoAaveV3PositionData } from '../types';
|
|
3
|
+
import { EModeCategoriesData, MorphoAaveV3AssetsData, MorphoAaveV3MarketData, MorphoAaveV3MarketInfo, MorphoAaveV3PositionData } from '../types';
|
|
4
4
|
export declare const getMorphoAaveV3MarketsData: (web3: Web3, network: NetworkNumber, selectedMarket: MorphoAaveV3MarketInfo, mainnetWeb3: Web3) => Promise<MorphoAaveV3MarketData>;
|
|
5
5
|
export declare const getMorphoAaveV3AccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
6
|
-
export declare const getMorphoAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: string, assetsData: MorphoAaveV3AssetsData, delegator: string, selectedMarket: MorphoAaveV3MarketInfo) => Promise<MorphoAaveV3PositionData>;
|
|
6
|
+
export declare const getMorphoAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: string, assetsData: MorphoAaveV3AssetsData, eModeCategoriesData: EModeCategoriesData, delegator: string, selectedMarket: MorphoAaveV3MarketInfo) => Promise<MorphoAaveV3PositionData>;
|
|
7
7
|
export declare const getMorphoAaveV3FullPositionData: (web3: Web3, network: NetworkNumber, address: string, delegator: string, market: MorphoAaveV3MarketInfo, mainnetWeb3: Web3) => Promise<MorphoAaveV3PositionData>;
|
|
@@ -80,9 +80,10 @@ const computeMorphoMarketData = (loanInfo, morphoMarketData, aaveIndexes) => {
|
|
|
80
80
|
const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
81
|
// @ts-ignore
|
|
82
82
|
const lendingPoolContract = (0, contracts_1.createContractWrapper)(web3, network, selectedMarket.lendingPool, selectedMarket.lendingPoolAddress);
|
|
83
|
+
const aaveLendingPoolContract = (0, contracts_1.createContractWrapper)(web3, network, selectedMarket.aaveLendingPool, selectedMarket.aaveLendingPoolAddress);
|
|
83
84
|
const _addresses = selectedMarket.assets.map((a) => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a)).address);
|
|
84
85
|
const splitStart = Math.floor(_addresses.length / 2);
|
|
85
|
-
const loanInfoCallsToSkip =
|
|
86
|
+
const loanInfoCallsToSkip = 3; // skipping getFullTokensInfo calls at the start of multicallArray
|
|
86
87
|
const AaveV3ViewAddress = (0, contracts_1.getConfigContractAddress)('AaveV3View', network);
|
|
87
88
|
const AaveV3ViewAbi = (0, contracts_1.getConfigContractAbi)('AaveV3View');
|
|
88
89
|
const multicallArray = [
|
|
@@ -96,20 +97,37 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
96
97
|
abiItem: (0, utils_1.getAbiItem)(AaveV3ViewAbi, 'getFullTokensInfo'),
|
|
97
98
|
params: [selectedMarket.providerAddress, _addresses.slice(splitStart, _addresses.length)],
|
|
98
99
|
},
|
|
100
|
+
{
|
|
101
|
+
target: AaveV3ViewAddress,
|
|
102
|
+
abiItem: (0, utils_1.getAbiItem)(AaveV3ViewAbi, 'getAllEmodes'),
|
|
103
|
+
params: [selectedMarket.providerAddress],
|
|
104
|
+
},
|
|
99
105
|
...(_addresses.map((underlyingAddress) => ([{
|
|
100
106
|
target: lendingPoolContract.options.address,
|
|
101
107
|
abiItem: (0, utils_1.getAbiItem)(lendingPoolContract.options.jsonInterface, 'market'),
|
|
102
108
|
params: [underlyingAddress],
|
|
103
109
|
},
|
|
104
110
|
{
|
|
105
|
-
target:
|
|
111
|
+
target: aaveLendingPoolContract.options.address,
|
|
106
112
|
// @ts-ignore
|
|
107
|
-
abiItem: (0, utils_1.getAbiItem)((0, contracts_1.getConfigContractAbi)(selectedMarket.
|
|
113
|
+
abiItem: (0, utils_1.getAbiItem)((0, contracts_1.getConfigContractAbi)(selectedMarket.aaveLendingPool), 'getReserveData'),
|
|
108
114
|
params: [underlyingAddress],
|
|
109
115
|
}]))).flat(),
|
|
110
116
|
];
|
|
111
117
|
const multicallResponse = yield (0, multicall_1.multicall)(multicallArray, web3, network);
|
|
112
118
|
const loanInfo = [...multicallResponse[0][0], ...multicallResponse[1][0]];
|
|
119
|
+
// Morpho Aave V3 ETH optimizer is hardcoded to use e mode category 1
|
|
120
|
+
const eModeCategoryData = {
|
|
121
|
+
label: multicallResponse[2][0][0].label,
|
|
122
|
+
id: 1,
|
|
123
|
+
liquidationBonus: new decimal_js_1.default(multicallResponse[2][0][0].liquidationBonus).div(10000).toString(),
|
|
124
|
+
liquidationRatio: new decimal_js_1.default(multicallResponse[2][0][0].liquidationThreshold).div(10000).toString(),
|
|
125
|
+
collateralFactor: new decimal_js_1.default(multicallResponse[2][0][0].ltv).div(10000).toString(),
|
|
126
|
+
borrowableBitmap: multicallResponse[2][0][0].borrowableBitmap,
|
|
127
|
+
collateralBitmap: multicallResponse[2][0][0].collateralBitmap,
|
|
128
|
+
borrowAssets: [],
|
|
129
|
+
collateralAssets: [],
|
|
130
|
+
};
|
|
113
131
|
const IVariableDebtTokenAbi = (0, contracts_1.getConfigContractAbi)('IVariableDebtToken');
|
|
114
132
|
const IATokenAbi = (0, contracts_1.getConfigContractAbi)('IAToken');
|
|
115
133
|
const scaledBalanceMulticall = [
|
|
@@ -140,13 +158,16 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
140
158
|
const assetsData = yield Promise.all(loanInfo.map((info, i) => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
159
|
var _a, _b, _c, _d, _e, _f;
|
|
142
160
|
const morphoMarketData = Object.assign(Object.assign({}, multicallResponse[(2 * i) + loanInfoCallsToSkip][0]), { scaledMorphoBorrowOnPool: scaledBalanceResponse.value[2 * i][0], scaledMorphoSupplyOnPool: scaledBalanceResponse.value[(2 * i) + 1][0] });
|
|
143
|
-
const marketData = computeMorphoMarketData(info, morphoMarketData, multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)]);
|
|
161
|
+
const marketData = computeMorphoMarketData(info, morphoMarketData, multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)][0]);
|
|
144
162
|
const { symbol, address } = (0, tokens_1.getAssetInfoByAddress)((0, utils_1.wethToEthByAddress)(marketData.underlyingTokenAddress));
|
|
163
|
+
if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoryData.collateralBitmap), Number(info.assetId)) && marketData.isCollateral)
|
|
164
|
+
eModeCategoryData.collateralAssets.push(symbol);
|
|
165
|
+
if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoryData.borrowableBitmap), Number(info.assetId)))
|
|
166
|
+
eModeCategoryData.borrowAssets.push(symbol);
|
|
145
167
|
const data = {
|
|
146
168
|
symbol,
|
|
147
169
|
morphoMarketData,
|
|
148
170
|
hasDelta: new decimal_js_1.default(marketData.p2pSupplyAPY).minus(marketData.p2pBorrowAPY).gte(0.3),
|
|
149
|
-
eModeCategory: +marketData.emodeCategory,
|
|
150
171
|
aTokenAddress: marketData.aTokenAddress,
|
|
151
172
|
underlyingTokenAddress: address,
|
|
152
173
|
price: new decimal_js_1.default(marketData.price.toString()).div(1e8).toString(),
|
|
@@ -197,13 +218,6 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
197
218
|
.div(new decimal_js_1.default(marketData.totalSupply.toString()))
|
|
198
219
|
.times(100)
|
|
199
220
|
.toString(),
|
|
200
|
-
eModeCategoryData: {
|
|
201
|
-
label: marketData.label,
|
|
202
|
-
liquidationBonus: new decimal_js_1.default(marketData.liquidationBonus).div(10000).toString(),
|
|
203
|
-
liquidationRatio: new decimal_js_1.default(marketData.liquidationThreshold).div(10000).toString(),
|
|
204
|
-
collateralFactor: new decimal_js_1.default(marketData.ltv).div(10000).toString(),
|
|
205
|
-
priceSource: marketData.priceSource,
|
|
206
|
-
},
|
|
207
221
|
incentiveSupplyToken: 'MORPHO',
|
|
208
222
|
incentiveBorrowToken: 'MORPHO',
|
|
209
223
|
incentiveSupplyApy: ((_c = (_a = morphoRewardsData === null || morphoRewardsData === void 0 ? void 0 : morphoRewardsData.markets) === null || _a === void 0 ? void 0 : _a[(_b = marketData.underlyingTokenAddress) === null || _b === void 0 ? void 0 : _b.toLowerCase()]) === null || _c === void 0 ? void 0 : _c.morphoRatePerSecondSupplySide) || '0',
|
|
@@ -240,7 +254,7 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
240
254
|
.forEach((assetData, i) => {
|
|
241
255
|
payload[assetData.symbol] = Object.assign(Object.assign({}, assetData), { sortIndex: i });
|
|
242
256
|
});
|
|
243
|
-
return { assetsData: payload };
|
|
257
|
+
return { assetsData: payload, eModeCategoriesData: { 1: eModeCategoryData } };
|
|
244
258
|
});
|
|
245
259
|
exports.getMorphoAaveV3MarketsData = getMorphoAaveV3MarketsData;
|
|
246
260
|
const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -316,7 +330,7 @@ const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapping, ad
|
|
|
316
330
|
return balances;
|
|
317
331
|
});
|
|
318
332
|
exports.getMorphoAaveV3AccountBalances = getMorphoAaveV3AccountBalances;
|
|
319
|
-
const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegator, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
+
const getMorphoAaveV3AccountData = (web3, network, address, assetsData, eModeCategoriesData, delegator, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
320
334
|
var _g;
|
|
321
335
|
if (!address) {
|
|
322
336
|
throw new Error('No address provided.');
|
|
@@ -387,7 +401,6 @@ const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegato
|
|
|
387
401
|
if (new decimal_js_1.default(supplied).gt(0) || new decimal_js_1.default(borrowed).gt(0)) {
|
|
388
402
|
payload.usedAssets[symbol] = {
|
|
389
403
|
symbol,
|
|
390
|
-
eModeCategory: market.eModeCategory,
|
|
391
404
|
supplied,
|
|
392
405
|
suppliedP2P,
|
|
393
406
|
suppliedPool,
|
|
@@ -421,8 +434,9 @@ const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegato
|
|
|
421
434
|
};
|
|
422
435
|
}
|
|
423
436
|
});
|
|
437
|
+
payload.eModeCategory = eModeCategory;
|
|
424
438
|
payload = Object.assign(Object.assign({}, payload), (0, aaveHelpers_1.aaveAnyGetAggregatedPositionData)({
|
|
425
|
-
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket,
|
|
439
|
+
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket, eModeCategoriesData,
|
|
426
440
|
}));
|
|
427
441
|
// Calculate borrow limits per asset
|
|
428
442
|
Object.values(payload.usedAssets).forEach((item) => {
|
|
@@ -436,7 +450,7 @@ const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegato
|
|
|
436
450
|
exports.getMorphoAaveV3AccountData = getMorphoAaveV3AccountData;
|
|
437
451
|
const getMorphoAaveV3FullPositionData = (web3, network, address, delegator, market, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
438
452
|
const marketData = yield (0, exports.getMorphoAaveV3MarketsData)(web3, network, market, mainnetWeb3);
|
|
439
|
-
const positionData = yield (0, exports.getMorphoAaveV3AccountData)(web3, network, address, marketData.assetsData, delegator, market);
|
|
453
|
+
const positionData = yield (0, exports.getMorphoAaveV3AccountData)(web3, network, address, marketData.assetsData, marketData.eModeCategoriesData, delegator, market);
|
|
440
454
|
return positionData;
|
|
441
455
|
});
|
|
442
456
|
exports.getMorphoAaveV3FullPositionData = getMorphoAaveV3FullPositionData;
|
package/cjs/services/utils.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare const bytesToString: (hex: string) => string;
|
|
|
19
19
|
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
20
20
|
*/
|
|
21
21
|
export declare const mapRange: (input: number | string, minInput: number | string, maxInput: number | string, minOutput: number | string, maxOutput: number | string) => number;
|
|
22
|
+
export declare const isEnabledOnBitmap: (bitmap: number, assetId: number) => bigint;
|
package/cjs/services/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.mapRange = exports.bytesToString = exports.ethToWethByAddress = exports.wethToEthByAddress = exports.handleWbtcLegacy = exports.getEthAmountForDecimals = exports.getWeiAmountForDecimals = exports.compareAddresses = exports.isAddress = exports.ADDRESS_REGEX = exports.getAbiItem = exports.wstEthToStEth = exports.stEthToWstEth = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.isLayer2Network = void 0;
|
|
6
|
+
exports.isEnabledOnBitmap = exports.mapRange = exports.bytesToString = exports.ethToWethByAddress = exports.wethToEthByAddress = exports.handleWbtcLegacy = exports.getEthAmountForDecimals = exports.getWeiAmountForDecimals = exports.compareAddresses = exports.isAddress = exports.ADDRESS_REGEX = exports.getAbiItem = exports.wstEthToStEth = exports.stEthToWstEth = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.isLayer2Network = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const tokens_1 = require("@defisaver/tokens");
|
|
9
9
|
const common_1 = require("../types/common");
|
|
@@ -53,3 +53,6 @@ const mapRange = (input, minInput, maxInput, minOutput, maxOutput) => {
|
|
|
53
53
|
return new decimal_js_1.default(minOutput).plus(new decimal_js_1.default(slope).mul(new decimal_js_1.default(input).minus(minInput))).toDP(2).toNumber();
|
|
54
54
|
};
|
|
55
55
|
exports.mapRange = mapRange;
|
|
56
|
+
// eslint-disable-next-line no-bitwise
|
|
57
|
+
const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
58
|
+
exports.isEnabledOnBitmap = isEnabledOnBitmap;
|
package/cjs/types/aave.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ export type AaveV3MarketData = {
|
|
|
111
111
|
export type MorphoAaveV3AssetsData = AaveAssetsData<MorphoAaveV3AssetData>;
|
|
112
112
|
export type MorphoAaveV3MarketData = {
|
|
113
113
|
assetsData: MorphoAaveV3AssetsData;
|
|
114
|
+
eModeCategoriesData: EModeCategoriesData;
|
|
114
115
|
};
|
|
115
116
|
export interface AaveUsedAsset extends MMUsedAsset {
|
|
116
117
|
stableBorrowRate: string;
|
|
@@ -139,7 +140,6 @@ export interface MorphoAaveV2UsedAsset extends Omit<AaveV2UsedAsset, 'debt'> {
|
|
|
139
140
|
}
|
|
140
141
|
export interface AaveV3UsedAsset extends AaveUsedAsset {
|
|
141
142
|
discountedBorrowRate: string;
|
|
142
|
-
eModeCategory: number;
|
|
143
143
|
supplyRate: string;
|
|
144
144
|
borrowRate: string;
|
|
145
145
|
interestMode: string;
|
|
@@ -234,5 +234,8 @@ export interface AaveHelperCommon {
|
|
|
234
234
|
network?: NetworkNumber;
|
|
235
235
|
}
|
|
236
236
|
export type MorphoAaveV2MarketInfo = Omit<AaveMarketInfo, 'provider' | 'lendingPool' | 'protocolData' | 'protocolDataAddress'>;
|
|
237
|
-
export type MorphoAaveV3MarketInfo = Omit<AaveMarketInfo, 'provider'
|
|
237
|
+
export type MorphoAaveV3MarketInfo = Omit<AaveMarketInfo, 'provider'> & {
|
|
238
|
+
aaveLendingPool: 'AaveV3LendingPool';
|
|
239
|
+
aaveLendingPoolAddress: string;
|
|
240
|
+
};
|
|
238
241
|
export type MorphoAaveMarketInfo = MorphoAaveV2MarketInfo | MorphoAaveV3MarketInfo;
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
12
12
|
import { AaveIncentiveDataProviderV3Contract, AaveV3ViewContract, createContractWrapper, getConfigContractAbi, getConfigContractAddress, GhoTokenContract, } from '../contracts';
|
|
13
|
-
import { addToObjectIf, ethToWeth, getAbiItem, isLayer2Network, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
13
|
+
import { addToObjectIf, ethToWeth, getAbiItem, isEnabledOnBitmap, isLayer2Network, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
14
14
|
import { NetworkNumber, } from '../types/common';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
16
|
import { multicall } from '../multicall';
|
|
@@ -63,8 +63,6 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
63
63
|
});
|
|
64
64
|
return categoriesMapping;
|
|
65
65
|
};
|
|
66
|
-
// eslint-disable-next-line no-bitwise
|
|
67
|
-
const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
68
66
|
export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
69
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
68
|
const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a), network).address);
|
|
@@ -28,11 +28,11 @@ export declare const aaveV3IsInSiloedMode: ({ usedAssets, assetsData }: {
|
|
|
28
28
|
export declare const aaveAnyGetCollSuppliedAssets: ({ usedAssets }: {
|
|
29
29
|
usedAssets: AaveV3UsedAssets;
|
|
30
30
|
}) => import("../../types").AaveV3UsedAsset[];
|
|
31
|
-
export declare const aaveAnyGetSuppliableAssets: ({ usedAssets, eModeCategory,
|
|
31
|
+
export declare const aaveAnyGetSuppliableAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => {
|
|
32
32
|
symbol: string;
|
|
33
33
|
canBeCollateral: boolean;
|
|
34
34
|
}[];
|
|
35
|
-
export declare const aaveAnyGetSuppliableAsCollAssets: ({ usedAssets, eModeCategory,
|
|
35
|
+
export declare const aaveAnyGetSuppliableAsCollAssets: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => {
|
|
36
36
|
symbol: string;
|
|
37
37
|
canBeCollateral: boolean;
|
|
38
38
|
}[];
|
|
@@ -40,7 +40,7 @@ export declare const aaveAnyGetEmodeMutableProps: ({ eModeCategory, eModeCategor
|
|
|
40
40
|
liquidationRatio: any;
|
|
41
41
|
collateralFactor: any;
|
|
42
42
|
};
|
|
43
|
-
export declare const aaveAnyGetAggregatedPositionData: ({ usedAssets, eModeCategory,
|
|
43
|
+
export declare const aaveAnyGetAggregatedPositionData: ({ usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => AaveV3AggregatedPositionData;
|
|
44
44
|
export declare const getApyAfterValuesEstimation: (selectedMarket: AaveMarketInfo, actions: [{
|
|
45
45
|
action: string;
|
|
46
46
|
amount: string;
|
|
@@ -37,8 +37,8 @@ export const aaveV3IsInSiloedMode = ({ usedAssets, assetsData }) => Object.value
|
|
|
37
37
|
export const aaveAnyGetCollSuppliedAssets = ({ usedAssets }) => Object.values(usedAssets)
|
|
38
38
|
.filter(({ isSupplied, collateral }) => isSupplied && collateral);
|
|
39
39
|
export const aaveAnyGetSuppliableAssets = (_a) => {
|
|
40
|
-
var { usedAssets, eModeCategory,
|
|
41
|
-
const data = Object.assign({ usedAssets, eModeCategory,
|
|
40
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
41
|
+
const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
|
|
42
42
|
const collAccountAssets = aaveAnyGetCollSuppliedAssets(data);
|
|
43
43
|
const marketAssets = Object.values(assetsData);
|
|
44
44
|
if (isMorphoAave({ selectedMarket })) {
|
|
@@ -53,8 +53,8 @@ export const aaveAnyGetSuppliableAssets = (_a) => {
|
|
|
53
53
|
return marketAssets.filter(d => d.canBeSupplied).map(({ symbol, isIsolated }) => ({ symbol, canBeCollateral: !isIsolated }));
|
|
54
54
|
};
|
|
55
55
|
export const aaveAnyGetSuppliableAsCollAssets = (_a) => {
|
|
56
|
-
var { usedAssets, eModeCategory,
|
|
57
|
-
return aaveAnyGetSuppliableAssets(Object.assign({ usedAssets, eModeCategory,
|
|
56
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
57
|
+
return aaveAnyGetSuppliableAssets(Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest)).filter(({ canBeCollateral }) => canBeCollateral);
|
|
58
58
|
};
|
|
59
59
|
export const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData, assetsData, }, _asset) => {
|
|
60
60
|
const asset = wethToEth(_asset);
|
|
@@ -70,8 +70,8 @@ export const aaveAnyGetEmodeMutableProps = ({ eModeCategory, eModeCategoriesData
|
|
|
70
70
|
return ({ liquidationRatio, collateralFactor });
|
|
71
71
|
};
|
|
72
72
|
export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
73
|
-
var { usedAssets, eModeCategory,
|
|
74
|
-
const data = Object.assign({ usedAssets, eModeCategory,
|
|
73
|
+
var { usedAssets, eModeCategory, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "assetsData", "selectedMarket", "network"]);
|
|
74
|
+
const data = Object.assign({ usedAssets, eModeCategory, assetsData, selectedMarket, network }, rest);
|
|
75
75
|
const payload = {};
|
|
76
76
|
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
77
77
|
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
@@ -108,6 +108,8 @@ export const MORPHO_AAVE_V3_ETH = (networkId = NetworkNumber.Eth) => ({
|
|
|
108
108
|
providerAddress: getConfigContractAddress('AaveV3PoolAddressesProvider', networkId),
|
|
109
109
|
protocolData: 'AaveV3ProtocolDataProvider',
|
|
110
110
|
protocolDataAddress: getConfigContractAddress('AaveV3ProtocolDataProvider', networkId),
|
|
111
|
+
aaveLendingPool: 'AaveV3LendingPool',
|
|
112
|
+
aaveLendingPoolAddress: getConfigContractAddress('AaveV3LendingPool', networkId),
|
|
111
113
|
lendingPool: 'MorphoAaveV3ProxyEthMarket',
|
|
112
114
|
lendingPoolAddress: getConfigContractAddress('MorphoAaveV3ProxyEthMarket', 1),
|
|
113
115
|
// icon: SvgAdapter(protocolIcons.morpho),
|
|
@@ -7,7 +7,7 @@ export const aaveV1AssetsDefaultMarket = [
|
|
|
7
7
|
export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', 'UNI', 'AAVE', 'BAT', 'BUSD', 'DAI', 'ENJ', 'KNCL', 'LINK', 'MANA', 'MKR', 'REN', 'SNX', 'SUSD', 'TUSD', 'USDC', 'CRV', 'GUSD', 'BAL', 'xSUSHI', 'RENFIL', 'RAI', 'AMPL', 'USDP', 'DPI', 'FRAX', 'FEI', 'stETH', 'ENS', 'UST', 'CVX', '1INCH', 'LUSD'];
|
|
8
8
|
export const morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WBTC', 'stETH', 'CRV'];
|
|
9
9
|
export const morphoAaveV3AssetEthMarket = [
|
|
10
|
-
'ETH', 'wstETH', '
|
|
10
|
+
'ETH', 'wstETH', 'USDC', 'WBTC', 'rETH', 'cbETH', 'USDT',
|
|
11
11
|
];
|
|
12
12
|
export const aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS'];
|
|
13
13
|
export const aaveV3AssetsDefaultMarketOpt = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
2
|
import { Blockish, EthAddress, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
|
-
import { MorphoAaveV3AssetsData, MorphoAaveV3MarketData, MorphoAaveV3MarketInfo, MorphoAaveV3PositionData } from '../types';
|
|
3
|
+
import { EModeCategoriesData, MorphoAaveV3AssetsData, MorphoAaveV3MarketData, MorphoAaveV3MarketInfo, MorphoAaveV3PositionData } from '../types';
|
|
4
4
|
export declare const getMorphoAaveV3MarketsData: (web3: Web3, network: NetworkNumber, selectedMarket: MorphoAaveV3MarketInfo, mainnetWeb3: Web3) => Promise<MorphoAaveV3MarketData>;
|
|
5
5
|
export declare const getMorphoAaveV3AccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
6
|
-
export declare const getMorphoAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: string, assetsData: MorphoAaveV3AssetsData, delegator: string, selectedMarket: MorphoAaveV3MarketInfo) => Promise<MorphoAaveV3PositionData>;
|
|
6
|
+
export declare const getMorphoAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: string, assetsData: MorphoAaveV3AssetsData, eModeCategoriesData: EModeCategoriesData, delegator: string, selectedMarket: MorphoAaveV3MarketInfo) => Promise<MorphoAaveV3PositionData>;
|
|
7
7
|
export declare const getMorphoAaveV3FullPositionData: (web3: Web3, network: NetworkNumber, address: string, delegator: string, market: MorphoAaveV3MarketInfo, mainnetWeb3: Web3) => Promise<MorphoAaveV3PositionData>;
|
|
@@ -13,7 +13,7 @@ import PoolInterestRates from '@morpho-org/morpho-aave-v3-sdk/lib/maths/PoolInte
|
|
|
13
13
|
import P2PInterestRates from '@morpho-org/morpho-aave-v3-sdk/lib/maths/P2PInterestRates';
|
|
14
14
|
import { BigNumber } from '@ethersproject/bignumber';
|
|
15
15
|
import Dec from 'decimal.js';
|
|
16
|
-
import { ethToWeth, ethToWethByAddress, getAbiItem, wethToEthByAddress, } from '../services/utils';
|
|
16
|
+
import { ethToWeth, ethToWethByAddress, getAbiItem, isEnabledOnBitmap, wethToEthByAddress, } from '../services/utils';
|
|
17
17
|
import { createContractWrapper, getConfigContractAbi, getConfigContractAddress, } from '../contracts';
|
|
18
18
|
import { multicall } from '../multicall';
|
|
19
19
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
@@ -74,9 +74,10 @@ const computeMorphoMarketData = (loanInfo, morphoMarketData, aaveIndexes) => {
|
|
|
74
74
|
export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
75
|
// @ts-ignore
|
|
76
76
|
const lendingPoolContract = createContractWrapper(web3, network, selectedMarket.lendingPool, selectedMarket.lendingPoolAddress);
|
|
77
|
+
const aaveLendingPoolContract = createContractWrapper(web3, network, selectedMarket.aaveLendingPool, selectedMarket.aaveLendingPoolAddress);
|
|
77
78
|
const _addresses = selectedMarket.assets.map((a) => getAssetInfo(ethToWeth(a)).address);
|
|
78
79
|
const splitStart = Math.floor(_addresses.length / 2);
|
|
79
|
-
const loanInfoCallsToSkip =
|
|
80
|
+
const loanInfoCallsToSkip = 3; // skipping getFullTokensInfo calls at the start of multicallArray
|
|
80
81
|
const AaveV3ViewAddress = getConfigContractAddress('AaveV3View', network);
|
|
81
82
|
const AaveV3ViewAbi = getConfigContractAbi('AaveV3View');
|
|
82
83
|
const multicallArray = [
|
|
@@ -90,20 +91,37 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
90
91
|
abiItem: getAbiItem(AaveV3ViewAbi, 'getFullTokensInfo'),
|
|
91
92
|
params: [selectedMarket.providerAddress, _addresses.slice(splitStart, _addresses.length)],
|
|
92
93
|
},
|
|
94
|
+
{
|
|
95
|
+
target: AaveV3ViewAddress,
|
|
96
|
+
abiItem: getAbiItem(AaveV3ViewAbi, 'getAllEmodes'),
|
|
97
|
+
params: [selectedMarket.providerAddress],
|
|
98
|
+
},
|
|
93
99
|
...(_addresses.map((underlyingAddress) => ([{
|
|
94
100
|
target: lendingPoolContract.options.address,
|
|
95
101
|
abiItem: getAbiItem(lendingPoolContract.options.jsonInterface, 'market'),
|
|
96
102
|
params: [underlyingAddress],
|
|
97
103
|
},
|
|
98
104
|
{
|
|
99
|
-
target:
|
|
105
|
+
target: aaveLendingPoolContract.options.address,
|
|
100
106
|
// @ts-ignore
|
|
101
|
-
abiItem: getAbiItem(getConfigContractAbi(selectedMarket.
|
|
107
|
+
abiItem: getAbiItem(getConfigContractAbi(selectedMarket.aaveLendingPool), 'getReserveData'),
|
|
102
108
|
params: [underlyingAddress],
|
|
103
109
|
}]))).flat(),
|
|
104
110
|
];
|
|
105
111
|
const multicallResponse = yield multicall(multicallArray, web3, network);
|
|
106
112
|
const loanInfo = [...multicallResponse[0][0], ...multicallResponse[1][0]];
|
|
113
|
+
// Morpho Aave V3 ETH optimizer is hardcoded to use e mode category 1
|
|
114
|
+
const eModeCategoryData = {
|
|
115
|
+
label: multicallResponse[2][0][0].label,
|
|
116
|
+
id: 1,
|
|
117
|
+
liquidationBonus: new Dec(multicallResponse[2][0][0].liquidationBonus).div(10000).toString(),
|
|
118
|
+
liquidationRatio: new Dec(multicallResponse[2][0][0].liquidationThreshold).div(10000).toString(),
|
|
119
|
+
collateralFactor: new Dec(multicallResponse[2][0][0].ltv).div(10000).toString(),
|
|
120
|
+
borrowableBitmap: multicallResponse[2][0][0].borrowableBitmap,
|
|
121
|
+
collateralBitmap: multicallResponse[2][0][0].collateralBitmap,
|
|
122
|
+
borrowAssets: [],
|
|
123
|
+
collateralAssets: [],
|
|
124
|
+
};
|
|
107
125
|
const IVariableDebtTokenAbi = getConfigContractAbi('IVariableDebtToken');
|
|
108
126
|
const IATokenAbi = getConfigContractAbi('IAToken');
|
|
109
127
|
const scaledBalanceMulticall = [
|
|
@@ -134,13 +152,16 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
134
152
|
const assetsData = yield Promise.all(loanInfo.map((info, i) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
153
|
var _a, _b, _c, _d, _e, _f;
|
|
136
154
|
const morphoMarketData = Object.assign(Object.assign({}, multicallResponse[(2 * i) + loanInfoCallsToSkip][0]), { scaledMorphoBorrowOnPool: scaledBalanceResponse.value[2 * i][0], scaledMorphoSupplyOnPool: scaledBalanceResponse.value[(2 * i) + 1][0] });
|
|
137
|
-
const marketData = computeMorphoMarketData(info, morphoMarketData, multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)]);
|
|
155
|
+
const marketData = computeMorphoMarketData(info, morphoMarketData, multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)][0]);
|
|
138
156
|
const { symbol, address } = getAssetInfoByAddress(wethToEthByAddress(marketData.underlyingTokenAddress));
|
|
157
|
+
if (isEnabledOnBitmap(Number(eModeCategoryData.collateralBitmap), Number(info.assetId)) && marketData.isCollateral)
|
|
158
|
+
eModeCategoryData.collateralAssets.push(symbol);
|
|
159
|
+
if (isEnabledOnBitmap(Number(eModeCategoryData.borrowableBitmap), Number(info.assetId)))
|
|
160
|
+
eModeCategoryData.borrowAssets.push(symbol);
|
|
139
161
|
const data = {
|
|
140
162
|
symbol,
|
|
141
163
|
morphoMarketData,
|
|
142
164
|
hasDelta: new Dec(marketData.p2pSupplyAPY).minus(marketData.p2pBorrowAPY).gte(0.3),
|
|
143
|
-
eModeCategory: +marketData.emodeCategory,
|
|
144
165
|
aTokenAddress: marketData.aTokenAddress,
|
|
145
166
|
underlyingTokenAddress: address,
|
|
146
167
|
price: new Dec(marketData.price.toString()).div(1e8).toString(),
|
|
@@ -191,13 +212,6 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
191
212
|
.div(new Dec(marketData.totalSupply.toString()))
|
|
192
213
|
.times(100)
|
|
193
214
|
.toString(),
|
|
194
|
-
eModeCategoryData: {
|
|
195
|
-
label: marketData.label,
|
|
196
|
-
liquidationBonus: new Dec(marketData.liquidationBonus).div(10000).toString(),
|
|
197
|
-
liquidationRatio: new Dec(marketData.liquidationThreshold).div(10000).toString(),
|
|
198
|
-
collateralFactor: new Dec(marketData.ltv).div(10000).toString(),
|
|
199
|
-
priceSource: marketData.priceSource,
|
|
200
|
-
},
|
|
201
215
|
incentiveSupplyToken: 'MORPHO',
|
|
202
216
|
incentiveBorrowToken: 'MORPHO',
|
|
203
217
|
incentiveSupplyApy: ((_c = (_a = morphoRewardsData === null || morphoRewardsData === void 0 ? void 0 : morphoRewardsData.markets) === null || _a === void 0 ? void 0 : _a[(_b = marketData.underlyingTokenAddress) === null || _b === void 0 ? void 0 : _b.toLowerCase()]) === null || _c === void 0 ? void 0 : _c.morphoRatePerSecondSupplySide) || '0',
|
|
@@ -234,7 +248,7 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
234
248
|
.forEach((assetData, i) => {
|
|
235
249
|
payload[assetData.symbol] = Object.assign(Object.assign({}, assetData), { sortIndex: i });
|
|
236
250
|
});
|
|
237
|
-
return { assetsData: payload };
|
|
251
|
+
return { assetsData: payload, eModeCategoriesData: { 1: eModeCategoryData } };
|
|
238
252
|
});
|
|
239
253
|
export const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
254
|
let balances = {
|
|
@@ -308,7 +322,7 @@ export const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapp
|
|
|
308
322
|
});
|
|
309
323
|
return balances;
|
|
310
324
|
});
|
|
311
|
-
export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegator, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
325
|
+
export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, eModeCategoriesData, delegator, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
312
326
|
var _g;
|
|
313
327
|
if (!address) {
|
|
314
328
|
throw new Error('No address provided.');
|
|
@@ -379,7 +393,6 @@ export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, d
|
|
|
379
393
|
if (new Dec(supplied).gt(0) || new Dec(borrowed).gt(0)) {
|
|
380
394
|
payload.usedAssets[symbol] = {
|
|
381
395
|
symbol,
|
|
382
|
-
eModeCategory: market.eModeCategory,
|
|
383
396
|
supplied,
|
|
384
397
|
suppliedP2P,
|
|
385
398
|
suppliedPool,
|
|
@@ -413,8 +426,9 @@ export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, d
|
|
|
413
426
|
};
|
|
414
427
|
}
|
|
415
428
|
});
|
|
429
|
+
payload.eModeCategory = eModeCategory;
|
|
416
430
|
payload = Object.assign(Object.assign({}, payload), aaveAnyGetAggregatedPositionData({
|
|
417
|
-
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket,
|
|
431
|
+
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket, eModeCategoriesData,
|
|
418
432
|
}));
|
|
419
433
|
// Calculate borrow limits per asset
|
|
420
434
|
Object.values(payload.usedAssets).forEach((item) => {
|
|
@@ -427,6 +441,6 @@ export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, d
|
|
|
427
441
|
});
|
|
428
442
|
export const getMorphoAaveV3FullPositionData = (web3, network, address, delegator, market, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
429
443
|
const marketData = yield getMorphoAaveV3MarketsData(web3, network, market, mainnetWeb3);
|
|
430
|
-
const positionData = yield getMorphoAaveV3AccountData(web3, network, address, marketData.assetsData, delegator, market);
|
|
444
|
+
const positionData = yield getMorphoAaveV3AccountData(web3, network, address, marketData.assetsData, marketData.eModeCategoriesData, delegator, market);
|
|
431
445
|
return positionData;
|
|
432
446
|
});
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare const bytesToString: (hex: string) => string;
|
|
|
19
19
|
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
20
20
|
*/
|
|
21
21
|
export declare const mapRange: (input: number | string, minInput: number | string, maxInput: number | string, minOutput: number | string, maxOutput: number | string) => number;
|
|
22
|
+
export declare const isEnabledOnBitmap: (bitmap: number, assetId: number) => bigint;
|
package/esm/services/utils.js
CHANGED
|
@@ -31,3 +31,5 @@ export const mapRange = (input, minInput, maxInput, minOutput, maxOutput) => {
|
|
|
31
31
|
// output = output_start + slope * (input - input_start)
|
|
32
32
|
return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
|
|
33
33
|
};
|
|
34
|
+
// eslint-disable-next-line no-bitwise
|
|
35
|
+
export const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ export type AaveV3MarketData = {
|
|
|
111
111
|
export type MorphoAaveV3AssetsData = AaveAssetsData<MorphoAaveV3AssetData>;
|
|
112
112
|
export type MorphoAaveV3MarketData = {
|
|
113
113
|
assetsData: MorphoAaveV3AssetsData;
|
|
114
|
+
eModeCategoriesData: EModeCategoriesData;
|
|
114
115
|
};
|
|
115
116
|
export interface AaveUsedAsset extends MMUsedAsset {
|
|
116
117
|
stableBorrowRate: string;
|
|
@@ -139,7 +140,6 @@ export interface MorphoAaveV2UsedAsset extends Omit<AaveV2UsedAsset, 'debt'> {
|
|
|
139
140
|
}
|
|
140
141
|
export interface AaveV3UsedAsset extends AaveUsedAsset {
|
|
141
142
|
discountedBorrowRate: string;
|
|
142
|
-
eModeCategory: number;
|
|
143
143
|
supplyRate: string;
|
|
144
144
|
borrowRate: string;
|
|
145
145
|
interestMode: string;
|
|
@@ -234,5 +234,8 @@ export interface AaveHelperCommon {
|
|
|
234
234
|
network?: NetworkNumber;
|
|
235
235
|
}
|
|
236
236
|
export type MorphoAaveV2MarketInfo = Omit<AaveMarketInfo, 'provider' | 'lendingPool' | 'protocolData' | 'protocolDataAddress'>;
|
|
237
|
-
export type MorphoAaveV3MarketInfo = Omit<AaveMarketInfo, 'provider'
|
|
237
|
+
export type MorphoAaveV3MarketInfo = Omit<AaveMarketInfo, 'provider'> & {
|
|
238
|
+
aaveLendingPool: 'AaveV3LendingPool';
|
|
239
|
+
aaveLendingPoolAddress: string;
|
|
240
|
+
};
|
|
238
241
|
export type MorphoAaveMarketInfo = MorphoAaveV2MarketInfo | MorphoAaveV3MarketInfo;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.147",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
|
|
13
13
|
"lint": "eslint src/ --fix",
|
|
14
14
|
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
|
-
"test": "mocha tests
|
|
15
|
+
"test": "mocha tests/*",
|
|
16
16
|
"test:debugger": "mocha --inspect-brk tests/*",
|
|
17
17
|
"build-test": "npm run build && mocha tests/*"
|
|
18
18
|
},
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
GhoTokenContract,
|
|
11
11
|
} from '../contracts';
|
|
12
12
|
import {
|
|
13
|
-
addToObjectIf, ethToWeth, getAbiItem, isLayer2Network, wethToEth, wethToEthByAddress,
|
|
13
|
+
addToObjectIf, ethToWeth, getAbiItem, isEnabledOnBitmap, isLayer2Network, wethToEth, wethToEthByAddress,
|
|
14
14
|
} from '../services/utils';
|
|
15
15
|
import {
|
|
16
16
|
AaveMarketInfo,
|
|
@@ -102,8 +102,6 @@ export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: Aa
|
|
|
102
102
|
return categoriesMapping;
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
// eslint-disable-next-line no-bitwise
|
|
106
|
-
const isEnabledOnBitmap = (bitmap: number, assetId: number) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
107
105
|
export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, market: AaveMarketInfo, defaultWeb3: Web3): Promise<AaveV3MarketData> {
|
|
108
106
|
const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a), network).address);
|
|
109
107
|
|
|
@@ -29,10 +29,10 @@ export const aaveAnyGetCollSuppliedAssets = ({ usedAssets }: { usedAssets: AaveV
|
|
|
29
29
|
.filter(({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral);
|
|
30
30
|
|
|
31
31
|
export const aaveAnyGetSuppliableAssets = ({
|
|
32
|
-
usedAssets, eModeCategory,
|
|
32
|
+
usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest
|
|
33
33
|
}: AaveHelperCommon) => {
|
|
34
34
|
const data = {
|
|
35
|
-
usedAssets, eModeCategory,
|
|
35
|
+
usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest,
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
const collAccountAssets = aaveAnyGetCollSuppliedAssets(data);
|
|
@@ -54,9 +54,9 @@ export const aaveAnyGetSuppliableAssets = ({
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export const aaveAnyGetSuppliableAsCollAssets = ({
|
|
57
|
-
usedAssets, eModeCategory,
|
|
57
|
+
usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest
|
|
58
58
|
}: AaveHelperCommon) => aaveAnyGetSuppliableAssets({
|
|
59
|
-
usedAssets, eModeCategory,
|
|
59
|
+
usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest,
|
|
60
60
|
}).filter(({ canBeCollateral }) => canBeCollateral);
|
|
61
61
|
|
|
62
62
|
export const aaveAnyGetEmodeMutableProps = (
|
|
@@ -85,14 +85,13 @@ export const aaveAnyGetEmodeMutableProps = (
|
|
|
85
85
|
export const aaveAnyGetAggregatedPositionData = ({
|
|
86
86
|
usedAssets,
|
|
87
87
|
eModeCategory,
|
|
88
|
-
eModeCategories,
|
|
89
88
|
assetsData,
|
|
90
89
|
selectedMarket,
|
|
91
90
|
network,
|
|
92
91
|
...rest
|
|
93
92
|
}: AaveHelperCommon): AaveV3AggregatedPositionData => {
|
|
94
93
|
const data = {
|
|
95
|
-
usedAssets, eModeCategory,
|
|
94
|
+
usedAssets, eModeCategory, assetsData, selectedMarket, network, ...rest,
|
|
96
95
|
};
|
|
97
96
|
const payload = {} as AaveV3AggregatedPositionData;
|
|
98
97
|
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
@@ -127,6 +127,8 @@ export const MORPHO_AAVE_V3_ETH = (networkId: NetworkNumber = NetworkNumber.Eth)
|
|
|
127
127
|
providerAddress: getConfigContractAddress('AaveV3PoolAddressesProvider', networkId), // TODO - check if used and if value is good?
|
|
128
128
|
protocolData: 'AaveV3ProtocolDataProvider',
|
|
129
129
|
protocolDataAddress: getConfigContractAddress('AaveV3ProtocolDataProvider', networkId),
|
|
130
|
+
aaveLendingPool: 'AaveV3LendingPool',
|
|
131
|
+
aaveLendingPoolAddress: getConfigContractAddress('AaveV3LendingPool', networkId),
|
|
130
132
|
lendingPool: 'MorphoAaveV3ProxyEthMarket',
|
|
131
133
|
lendingPoolAddress: getConfigContractAddress('MorphoAaveV3ProxyEthMarket', 1),
|
|
132
134
|
// icon: SvgAdapter(protocolIcons.morpho),
|
|
@@ -10,7 +10,7 @@ export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', '
|
|
|
10
10
|
export const morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WBTC', 'stETH', 'CRV'];
|
|
11
11
|
|
|
12
12
|
export const morphoAaveV3AssetEthMarket = [
|
|
13
|
-
'ETH', 'wstETH', '
|
|
13
|
+
'ETH', 'wstETH', 'USDC', 'WBTC', 'rETH', 'cbETH', 'USDT',
|
|
14
14
|
];
|
|
15
15
|
|
|
16
16
|
export const aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS'];
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
12
12
|
} from '../types/common';
|
|
13
13
|
import {
|
|
14
|
-
ethToWeth, ethToWethByAddress, getAbiItem, isLayer2Network, wethToEthByAddress,
|
|
14
|
+
ethToWeth, ethToWethByAddress, getAbiItem, isEnabledOnBitmap, isLayer2Network, wethToEthByAddress,
|
|
15
15
|
} from '../services/utils';
|
|
16
16
|
import {
|
|
17
17
|
createContractWrapper,
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
import { multicall } from '../multicall';
|
|
22
22
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
23
23
|
import {
|
|
24
|
+
EModeCategoriesData,
|
|
25
|
+
EModeCategoryData,
|
|
24
26
|
MorphoAaveV3AssetData, MorphoAaveV3AssetsData, MorphoAaveV3MarketData, MorphoAaveV3MarketInfo, MorphoAaveV3PositionData,
|
|
25
27
|
} from '../types';
|
|
26
28
|
import { getDsrApy } from '../services/dsrService';
|
|
@@ -139,11 +141,12 @@ const computeMorphoMarketData = (
|
|
|
139
141
|
export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: MorphoAaveV3MarketInfo, mainnetWeb3: Web3): Promise<MorphoAaveV3MarketData> => {
|
|
140
142
|
// @ts-ignore
|
|
141
143
|
const lendingPoolContract = createContractWrapper(web3, network, selectedMarket.lendingPool, selectedMarket.lendingPoolAddress);
|
|
144
|
+
const aaveLendingPoolContract = createContractWrapper(web3, network, selectedMarket.aaveLendingPool, selectedMarket.aaveLendingPoolAddress);
|
|
142
145
|
|
|
143
146
|
const _addresses = selectedMarket.assets.map((a: string) => getAssetInfo(ethToWeth(a)).address);
|
|
144
147
|
|
|
145
148
|
const splitStart = Math.floor(_addresses.length / 2);
|
|
146
|
-
const loanInfoCallsToSkip =
|
|
149
|
+
const loanInfoCallsToSkip = 3; // skipping getFullTokensInfo calls at the start of multicallArray
|
|
147
150
|
|
|
148
151
|
const AaveV3ViewAddress = getConfigContractAddress('AaveV3View', network);
|
|
149
152
|
const AaveV3ViewAbi = getConfigContractAbi('AaveV3View');
|
|
@@ -159,6 +162,11 @@ export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
159
162
|
abiItem: getAbiItem(AaveV3ViewAbi, 'getFullTokensInfo'),
|
|
160
163
|
params: [selectedMarket.providerAddress, _addresses.slice(splitStart, _addresses.length)],
|
|
161
164
|
},
|
|
165
|
+
{
|
|
166
|
+
target: AaveV3ViewAddress,
|
|
167
|
+
abiItem: getAbiItem(AaveV3ViewAbi, 'getAllEmodes'),
|
|
168
|
+
params: [selectedMarket.providerAddress],
|
|
169
|
+
},
|
|
162
170
|
...(_addresses.map((underlyingAddress: string) => (
|
|
163
171
|
[{
|
|
164
172
|
target: lendingPoolContract.options.address,
|
|
@@ -166,9 +174,9 @@ export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
166
174
|
params: [underlyingAddress],
|
|
167
175
|
},
|
|
168
176
|
{
|
|
169
|
-
target:
|
|
177
|
+
target: aaveLendingPoolContract.options.address, // TODO: aave refactor add to Aave view
|
|
170
178
|
// @ts-ignore
|
|
171
|
-
abiItem: getAbiItem(getConfigContractAbi(selectedMarket.
|
|
179
|
+
abiItem: getAbiItem(getConfigContractAbi(selectedMarket.aaveLendingPool), 'getReserveData'),
|
|
172
180
|
params: [underlyingAddress],
|
|
173
181
|
}]
|
|
174
182
|
))).flat(),
|
|
@@ -176,6 +184,18 @@ export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
176
184
|
|
|
177
185
|
const multicallResponse = await multicall(multicallArray, web3, network);
|
|
178
186
|
const loanInfo = [...multicallResponse[0][0], ...multicallResponse[1][0]];
|
|
187
|
+
// Morpho Aave V3 ETH optimizer is hardcoded to use e mode category 1
|
|
188
|
+
const eModeCategoryData: EModeCategoryData = {
|
|
189
|
+
label: multicallResponse[2][0][0].label,
|
|
190
|
+
id: 1,
|
|
191
|
+
liquidationBonus: new Dec(multicallResponse[2][0][0].liquidationBonus).div(10000).toString(),
|
|
192
|
+
liquidationRatio: new Dec(multicallResponse[2][0][0].liquidationThreshold).div(10000).toString(),
|
|
193
|
+
collateralFactor: new Dec(multicallResponse[2][0][0].ltv).div(10000).toString(),
|
|
194
|
+
borrowableBitmap: multicallResponse[2][0][0].borrowableBitmap,
|
|
195
|
+
collateralBitmap: multicallResponse[2][0][0].collateralBitmap,
|
|
196
|
+
borrowAssets: [],
|
|
197
|
+
collateralAssets: [],
|
|
198
|
+
};
|
|
179
199
|
|
|
180
200
|
const IVariableDebtTokenAbi = getConfigContractAbi('IVariableDebtToken');
|
|
181
201
|
const IATokenAbi = getConfigContractAbi('IAToken');
|
|
@@ -218,16 +238,19 @@ export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
218
238
|
const marketData = computeMorphoMarketData(
|
|
219
239
|
info,
|
|
220
240
|
morphoMarketData,
|
|
221
|
-
multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)],
|
|
241
|
+
multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)][0],
|
|
222
242
|
);
|
|
223
243
|
|
|
224
244
|
const { symbol, address } = getAssetInfoByAddress(wethToEthByAddress(marketData.underlyingTokenAddress));
|
|
225
245
|
|
|
246
|
+
|
|
247
|
+
if (isEnabledOnBitmap(Number(eModeCategoryData.collateralBitmap), Number(info.assetId)) && marketData.isCollateral) eModeCategoryData.collateralAssets.push(symbol);
|
|
248
|
+
if (isEnabledOnBitmap(Number(eModeCategoryData.borrowableBitmap), Number(info.assetId))) eModeCategoryData.borrowAssets.push(symbol);
|
|
249
|
+
|
|
226
250
|
const data = {
|
|
227
251
|
symbol,
|
|
228
252
|
morphoMarketData,
|
|
229
253
|
hasDelta: new Dec(marketData.p2pSupplyAPY).minus(marketData.p2pBorrowAPY).gte(0.3),
|
|
230
|
-
eModeCategory: +marketData.emodeCategory,
|
|
231
254
|
aTokenAddress: marketData.aTokenAddress,
|
|
232
255
|
underlyingTokenAddress: address,
|
|
233
256
|
price: new Dec(marketData.price.toString()).div(1e8).toString(), // is actually price in USD
|
|
@@ -281,15 +304,6 @@ export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
281
304
|
.div(new Dec(marketData.totalSupply.toString()))
|
|
282
305
|
.times(100)
|
|
283
306
|
.toString(),
|
|
284
|
-
|
|
285
|
-
eModeCategoryData: {
|
|
286
|
-
label: marketData.label,
|
|
287
|
-
liquidationBonus: new Dec(marketData.liquidationBonus).div(10000).toString(),
|
|
288
|
-
liquidationRatio: new Dec(marketData.liquidationThreshold).div(10000).toString(),
|
|
289
|
-
collateralFactor: new Dec(marketData.ltv).div(10000).toString(),
|
|
290
|
-
priceSource: marketData.priceSource,
|
|
291
|
-
},
|
|
292
|
-
|
|
293
307
|
incentiveSupplyToken: 'MORPHO',
|
|
294
308
|
incentiveBorrowToken: 'MORPHO',
|
|
295
309
|
incentiveSupplyApy: morphoRewardsData?.markets?.[marketData.underlyingTokenAddress?.toLowerCase()]?.morphoRatePerSecondSupplySide || '0',
|
|
@@ -332,7 +346,7 @@ export const getMorphoAaveV3MarketsData = async (web3: Web3, network: NetworkNum
|
|
|
332
346
|
payload[assetData.symbol] = { ...assetData, sortIndex: i };
|
|
333
347
|
});
|
|
334
348
|
|
|
335
|
-
return { assetsData: payload };
|
|
349
|
+
return { assetsData: payload, eModeCategoriesData: { 1: eModeCategoryData } };
|
|
336
350
|
};
|
|
337
351
|
|
|
338
352
|
export const getMorphoAaveV3AccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
|
|
@@ -445,6 +459,7 @@ export const getMorphoAaveV3AccountData = async (
|
|
|
445
459
|
network: NetworkNumber,
|
|
446
460
|
address: string,
|
|
447
461
|
assetsData: MorphoAaveV3AssetsData,
|
|
462
|
+
eModeCategoriesData: EModeCategoriesData,
|
|
448
463
|
delegator: string,
|
|
449
464
|
selectedMarket: MorphoAaveV3MarketInfo,
|
|
450
465
|
): Promise<MorphoAaveV3PositionData> => {
|
|
@@ -554,7 +569,6 @@ export const getMorphoAaveV3AccountData = async (
|
|
|
554
569
|
if (new Dec(supplied).gt(0) || new Dec(borrowed).gt(0)) {
|
|
555
570
|
payload.usedAssets[symbol] = {
|
|
556
571
|
symbol,
|
|
557
|
-
eModeCategory: market.eModeCategory,
|
|
558
572
|
supplied,
|
|
559
573
|
suppliedP2P,
|
|
560
574
|
suppliedPool,
|
|
@@ -590,10 +604,11 @@ export const getMorphoAaveV3AccountData = async (
|
|
|
590
604
|
}
|
|
591
605
|
});
|
|
592
606
|
|
|
607
|
+
payload.eModeCategory = eModeCategory;
|
|
593
608
|
payload = {
|
|
594
609
|
...payload,
|
|
595
610
|
...aaveAnyGetAggregatedPositionData({
|
|
596
|
-
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket,
|
|
611
|
+
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket, eModeCategoriesData,
|
|
597
612
|
}),
|
|
598
613
|
};
|
|
599
614
|
|
|
@@ -610,6 +625,6 @@ export const getMorphoAaveV3AccountData = async (
|
|
|
610
625
|
|
|
611
626
|
export const getMorphoAaveV3FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, delegator: string, market: MorphoAaveV3MarketInfo, mainnetWeb3: Web3): Promise<MorphoAaveV3PositionData> => {
|
|
612
627
|
const marketData = await getMorphoAaveV3MarketsData(web3, network, market, mainnetWeb3);
|
|
613
|
-
const positionData = await getMorphoAaveV3AccountData(web3, network, address, marketData.assetsData, delegator, market);
|
|
628
|
+
const positionData = await getMorphoAaveV3AccountData(web3, network, address, marketData.assetsData, marketData.eModeCategoriesData, delegator, market);
|
|
614
629
|
return positionData;
|
|
615
630
|
};
|
package/src/services/utils.ts
CHANGED
|
@@ -49,3 +49,6 @@ export const mapRange = (input: number | string, minInput: number | string, maxI
|
|
|
49
49
|
return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
// eslint-disable-next-line no-bitwise
|
|
53
|
+
export const isEnabledOnBitmap = (bitmap: number, assetId: number) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
54
|
+
|
package/src/types/aave.ts
CHANGED
|
@@ -122,7 +122,7 @@ export type AaveV3MarketData = { assetsData: AaveV3AssetsData, eModeCategoriesDa
|
|
|
122
122
|
|
|
123
123
|
export type MorphoAaveV3AssetsData = AaveAssetsData<MorphoAaveV3AssetData>;
|
|
124
124
|
|
|
125
|
-
export type MorphoAaveV3MarketData = { assetsData: MorphoAaveV3AssetsData };
|
|
125
|
+
export type MorphoAaveV3MarketData = { assetsData: MorphoAaveV3AssetsData, eModeCategoriesData: EModeCategoriesData };
|
|
126
126
|
|
|
127
127
|
export interface AaveUsedAsset extends MMUsedAsset {
|
|
128
128
|
stableBorrowRate: string,
|
|
@@ -153,7 +153,6 @@ export interface MorphoAaveV2UsedAsset extends Omit<AaveV2UsedAsset, 'debt'> {
|
|
|
153
153
|
}
|
|
154
154
|
export interface AaveV3UsedAsset extends AaveUsedAsset {
|
|
155
155
|
discountedBorrowRate: string,
|
|
156
|
-
eModeCategory: number,
|
|
157
156
|
supplyRate: string,
|
|
158
157
|
borrowRate: string,
|
|
159
158
|
interestMode: string,
|
|
@@ -258,6 +257,6 @@ export interface AaveHelperCommon {
|
|
|
258
257
|
|
|
259
258
|
export type MorphoAaveV2MarketInfo = Omit<AaveMarketInfo, 'provider' | 'lendingPool' | 'protocolData' | 'protocolDataAddress'>;
|
|
260
259
|
|
|
261
|
-
export type MorphoAaveV3MarketInfo = Omit<AaveMarketInfo, 'provider'
|
|
260
|
+
export type MorphoAaveV3MarketInfo = Omit<AaveMarketInfo, 'provider'> & { aaveLendingPool: 'AaveV3LendingPool', aaveLendingPoolAddress: string };
|
|
262
261
|
|
|
263
262
|
export type MorphoAaveMarketInfo = MorphoAaveV2MarketInfo | MorphoAaveV3MarketInfo;
|