@defisaver/positions-sdk 0.0.146 → 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/README.md +63 -63
- 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/marketAssets.js +1 -1
- package/cjs/morphoAaveV3/index.d.ts +2 -2
- package/cjs/morphoAaveV3/index.js +27 -14
- package/cjs/services/utils.d.ts +1 -0
- package/cjs/services/utils.js +4 -1
- package/cjs/types/aave.d.ts +1 -1
- 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/marketAssets.js +1 -1
- package/esm/morphoAaveV3/index.d.ts +2 -2
- package/esm/morphoAaveV3/index.js +28 -15
- package/esm/services/utils.d.ts +1 -0
- package/esm/services/utils.js +2 -0
- package/esm/types/aave.d.ts +1 -1
- package/package.json +41 -41
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +582 -584
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +281 -281
- package/src/config/contracts.js +1034 -1034
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +128 -128
- package/src/curveUsd/index.ts +229 -229
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +194 -195
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +246 -246
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/index.ts +7 -7
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +115 -115
- package/src/helpers/sparkHelpers/index.ts +150 -150
- package/src/index.ts +46 -46
- package/src/liquity/index.ts +116 -116
- package/src/llamaLend/index.ts +275 -275
- package/src/maker/index.ts +117 -117
- package/src/markets/aave/index.ts +152 -152
- package/src/markets/aave/marketAssets.ts +48 -48
- package/src/markets/compound/index.ts +173 -173
- package/src/markets/compound/marketsAssets.ts +64 -64
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +21 -21
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +691 -691
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +76 -76
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +630 -616
- package/src/morphoBlue/index.ts +171 -171
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +54 -51
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +424 -424
- package/src/staking/staking.ts +189 -189
- package/src/types/aave.ts +262 -263
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +129 -129
- package/src/types/curveUsd.ts +118 -118
- package/src/types/index.ts +8 -8
- package/src/types/liquity.ts +30 -30
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +144 -144
- package/src/types/spark.ts +127 -127
package/README.md
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
# DeFi Saver Positions SDK
|
|
2
|
-
|
|
3
|
-
Supported protocols:
|
|
4
|
-
- [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
|
|
5
|
-
- [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
|
|
6
|
-
- [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
|
|
7
|
-
- [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
|
|
8
|
-
- [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
|
|
9
|
-
- [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
|
|
10
|
-
- [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
|
|
11
|
-
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
12
|
-
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
13
|
-
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
14
|
-
- [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
|
|
15
|
-
|
|
16
|
-
## Setup
|
|
17
|
-
Supported Node version is v10.
|
|
18
|
-
|
|
19
|
-
- run `npm install` (first time)
|
|
20
|
-
- run `npm run build`
|
|
21
|
-
|
|
22
|
-
`build` command will generate contracts and build ejs and esm folders
|
|
23
|
-
|
|
24
|
-
## How to use
|
|
25
|
-
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
26
|
-
|
|
27
|
-
This is a Compound V3 example, and every other protocol is similar
|
|
28
|
-
```js
|
|
29
|
-
import Web3 from 'web3';
|
|
30
|
-
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// every protocol has market data and user data getters
|
|
34
|
-
const {
|
|
35
|
-
getCompoundV3MarketsData,
|
|
36
|
-
getCompoundV3AccountData,
|
|
37
|
-
} = compoundV3;
|
|
38
|
-
|
|
39
|
-
const provider = 'Your RPC provider';
|
|
40
|
-
const web3 = new Web3(provider);
|
|
41
|
-
|
|
42
|
-
const user = '0x123...';
|
|
43
|
-
|
|
44
|
-
const { assetsData } = await getCompoundV3MarketsData(
|
|
45
|
-
web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
46
|
-
1, // network
|
|
47
|
-
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
48
|
-
web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const userData = await getCompoundV3AccountData(
|
|
52
|
-
web3,
|
|
53
|
-
1, // network
|
|
54
|
-
userAddress, // EOA or DSProxy
|
|
55
|
-
'', // proxy address of the user, or just empty string if checking for EOA
|
|
56
|
-
{
|
|
57
|
-
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
58
|
-
assetsData,
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
1
|
+
# DeFi Saver Positions SDK
|
|
2
|
+
|
|
3
|
+
Supported protocols:
|
|
4
|
+
- [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
|
|
5
|
+
- [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
|
|
6
|
+
- [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
|
|
7
|
+
- [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
|
|
8
|
+
- [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
|
|
9
|
+
- [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
|
|
10
|
+
- [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
|
|
11
|
+
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
12
|
+
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
13
|
+
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
14
|
+
- [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
|
|
15
|
+
|
|
16
|
+
## Setup
|
|
17
|
+
Supported Node version is v10.
|
|
18
|
+
|
|
19
|
+
- run `npm install` (first time)
|
|
20
|
+
- run `npm run build`
|
|
21
|
+
|
|
22
|
+
`build` command will generate contracts and build ejs and esm folders
|
|
23
|
+
|
|
24
|
+
## How to use
|
|
25
|
+
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
26
|
+
|
|
27
|
+
This is a Compound V3 example, and every other protocol is similar
|
|
28
|
+
```js
|
|
29
|
+
import Web3 from 'web3';
|
|
30
|
+
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// every protocol has market data and user data getters
|
|
34
|
+
const {
|
|
35
|
+
getCompoundV3MarketsData,
|
|
36
|
+
getCompoundV3AccountData,
|
|
37
|
+
} = compoundV3;
|
|
38
|
+
|
|
39
|
+
const provider = 'Your RPC provider';
|
|
40
|
+
const web3 = new Web3(provider);
|
|
41
|
+
|
|
42
|
+
const user = '0x123...';
|
|
43
|
+
|
|
44
|
+
const { assetsData } = await getCompoundV3MarketsData(
|
|
45
|
+
web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
46
|
+
1, // network
|
|
47
|
+
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
48
|
+
web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const userData = await getCompoundV3AccountData(
|
|
52
|
+
web3,
|
|
53
|
+
1, // network
|
|
54
|
+
userAddress, // EOA or DSProxy
|
|
55
|
+
'', // proxy address of the user, or just empty string if checking for EOA
|
|
56
|
+
{
|
|
57
|
+
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
58
|
+
assetsData,
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
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);
|
|
@@ -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>;
|
|
@@ -83,7 +83,7 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
83
83
|
const aaveLendingPoolContract = (0, contracts_1.createContractWrapper)(web3, network, selectedMarket.aaveLendingPool, selectedMarket.aaveLendingPoolAddress);
|
|
84
84
|
const _addresses = selectedMarket.assets.map((a) => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a)).address);
|
|
85
85
|
const splitStart = Math.floor(_addresses.length / 2);
|
|
86
|
-
const loanInfoCallsToSkip =
|
|
86
|
+
const loanInfoCallsToSkip = 3; // skipping getFullTokensInfo calls at the start of multicallArray
|
|
87
87
|
const AaveV3ViewAddress = (0, contracts_1.getConfigContractAddress)('AaveV3View', network);
|
|
88
88
|
const AaveV3ViewAbi = (0, contracts_1.getConfigContractAbi)('AaveV3View');
|
|
89
89
|
const multicallArray = [
|
|
@@ -97,6 +97,11 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
97
97
|
abiItem: (0, utils_1.getAbiItem)(AaveV3ViewAbi, 'getFullTokensInfo'),
|
|
98
98
|
params: [selectedMarket.providerAddress, _addresses.slice(splitStart, _addresses.length)],
|
|
99
99
|
},
|
|
100
|
+
{
|
|
101
|
+
target: AaveV3ViewAddress,
|
|
102
|
+
abiItem: (0, utils_1.getAbiItem)(AaveV3ViewAbi, 'getAllEmodes'),
|
|
103
|
+
params: [selectedMarket.providerAddress],
|
|
104
|
+
},
|
|
100
105
|
...(_addresses.map((underlyingAddress) => ([{
|
|
101
106
|
target: lendingPoolContract.options.address,
|
|
102
107
|
abiItem: (0, utils_1.getAbiItem)(lendingPoolContract.options.jsonInterface, 'market'),
|
|
@@ -111,6 +116,18 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
111
116
|
];
|
|
112
117
|
const multicallResponse = yield (0, multicall_1.multicall)(multicallArray, web3, network);
|
|
113
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
|
+
};
|
|
114
131
|
const IVariableDebtTokenAbi = (0, contracts_1.getConfigContractAbi)('IVariableDebtToken');
|
|
115
132
|
const IATokenAbi = (0, contracts_1.getConfigContractAbi)('IAToken');
|
|
116
133
|
const scaledBalanceMulticall = [
|
|
@@ -143,11 +160,14 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
143
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] });
|
|
144
161
|
const marketData = computeMorphoMarketData(info, morphoMarketData, multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)][0]);
|
|
145
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);
|
|
146
167
|
const data = {
|
|
147
168
|
symbol,
|
|
148
169
|
morphoMarketData,
|
|
149
170
|
hasDelta: new decimal_js_1.default(marketData.p2pSupplyAPY).minus(marketData.p2pBorrowAPY).gte(0.3),
|
|
150
|
-
eModeCategory: +marketData.emodeCategory,
|
|
151
171
|
aTokenAddress: marketData.aTokenAddress,
|
|
152
172
|
underlyingTokenAddress: address,
|
|
153
173
|
price: new decimal_js_1.default(marketData.price.toString()).div(1e8).toString(),
|
|
@@ -198,13 +218,6 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
198
218
|
.div(new decimal_js_1.default(marketData.totalSupply.toString()))
|
|
199
219
|
.times(100)
|
|
200
220
|
.toString(),
|
|
201
|
-
eModeCategoryData: {
|
|
202
|
-
label: marketData.label,
|
|
203
|
-
liquidationBonus: new decimal_js_1.default(marketData.liquidationBonus).div(10000).toString(),
|
|
204
|
-
liquidationRatio: new decimal_js_1.default(marketData.liquidationThreshold).div(10000).toString(),
|
|
205
|
-
collateralFactor: new decimal_js_1.default(marketData.ltv).div(10000).toString(),
|
|
206
|
-
priceSource: marketData.priceSource,
|
|
207
|
-
},
|
|
208
221
|
incentiveSupplyToken: 'MORPHO',
|
|
209
222
|
incentiveBorrowToken: 'MORPHO',
|
|
210
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',
|
|
@@ -241,7 +254,7 @@ const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainnetWeb3)
|
|
|
241
254
|
.forEach((assetData, i) => {
|
|
242
255
|
payload[assetData.symbol] = Object.assign(Object.assign({}, assetData), { sortIndex: i });
|
|
243
256
|
});
|
|
244
|
-
return { assetsData: payload };
|
|
257
|
+
return { assetsData: payload, eModeCategoriesData: { 1: eModeCategoryData } };
|
|
245
258
|
});
|
|
246
259
|
exports.getMorphoAaveV3MarketsData = getMorphoAaveV3MarketsData;
|
|
247
260
|
const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -317,7 +330,7 @@ const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapping, ad
|
|
|
317
330
|
return balances;
|
|
318
331
|
});
|
|
319
332
|
exports.getMorphoAaveV3AccountBalances = getMorphoAaveV3AccountBalances;
|
|
320
|
-
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* () {
|
|
321
334
|
var _g;
|
|
322
335
|
if (!address) {
|
|
323
336
|
throw new Error('No address provided.');
|
|
@@ -388,7 +401,6 @@ const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegato
|
|
|
388
401
|
if (new decimal_js_1.default(supplied).gt(0) || new decimal_js_1.default(borrowed).gt(0)) {
|
|
389
402
|
payload.usedAssets[symbol] = {
|
|
390
403
|
symbol,
|
|
391
|
-
eModeCategory: market.eModeCategory,
|
|
392
404
|
supplied,
|
|
393
405
|
suppliedP2P,
|
|
394
406
|
suppliedPool,
|
|
@@ -422,8 +434,9 @@ const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegato
|
|
|
422
434
|
};
|
|
423
435
|
}
|
|
424
436
|
});
|
|
437
|
+
payload.eModeCategory = eModeCategory;
|
|
425
438
|
payload = Object.assign(Object.assign({}, payload), (0, aaveHelpers_1.aaveAnyGetAggregatedPositionData)({
|
|
426
|
-
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket,
|
|
439
|
+
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket, eModeCategoriesData,
|
|
427
440
|
}));
|
|
428
441
|
// Calculate borrow limits per asset
|
|
429
442
|
Object.values(payload.usedAssets).forEach((item) => {
|
|
@@ -437,7 +450,7 @@ const getMorphoAaveV3AccountData = (web3, network, address, assetsData, delegato
|
|
|
437
450
|
exports.getMorphoAaveV3AccountData = getMorphoAaveV3AccountData;
|
|
438
451
|
const getMorphoAaveV3FullPositionData = (web3, network, address, delegator, market, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
439
452
|
const marketData = yield (0, exports.getMorphoAaveV3MarketsData)(web3, network, market, mainnetWeb3);
|
|
440
|
-
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);
|
|
441
454
|
return positionData;
|
|
442
455
|
});
|
|
443
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;
|
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);
|
|
@@ -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';
|
|
@@ -77,7 +77,7 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
77
77
|
const aaveLendingPoolContract = createContractWrapper(web3, network, selectedMarket.aaveLendingPool, selectedMarket.aaveLendingPoolAddress);
|
|
78
78
|
const _addresses = selectedMarket.assets.map((a) => getAssetInfo(ethToWeth(a)).address);
|
|
79
79
|
const splitStart = Math.floor(_addresses.length / 2);
|
|
80
|
-
const loanInfoCallsToSkip =
|
|
80
|
+
const loanInfoCallsToSkip = 3; // skipping getFullTokensInfo calls at the start of multicallArray
|
|
81
81
|
const AaveV3ViewAddress = getConfigContractAddress('AaveV3View', network);
|
|
82
82
|
const AaveV3ViewAbi = getConfigContractAbi('AaveV3View');
|
|
83
83
|
const multicallArray = [
|
|
@@ -91,6 +91,11 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
91
91
|
abiItem: getAbiItem(AaveV3ViewAbi, 'getFullTokensInfo'),
|
|
92
92
|
params: [selectedMarket.providerAddress, _addresses.slice(splitStart, _addresses.length)],
|
|
93
93
|
},
|
|
94
|
+
{
|
|
95
|
+
target: AaveV3ViewAddress,
|
|
96
|
+
abiItem: getAbiItem(AaveV3ViewAbi, 'getAllEmodes'),
|
|
97
|
+
params: [selectedMarket.providerAddress],
|
|
98
|
+
},
|
|
94
99
|
...(_addresses.map((underlyingAddress) => ([{
|
|
95
100
|
target: lendingPoolContract.options.address,
|
|
96
101
|
abiItem: getAbiItem(lendingPoolContract.options.jsonInterface, 'market'),
|
|
@@ -105,6 +110,18 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
105
110
|
];
|
|
106
111
|
const multicallResponse = yield multicall(multicallArray, web3, network);
|
|
107
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
|
+
};
|
|
108
125
|
const IVariableDebtTokenAbi = getConfigContractAbi('IVariableDebtToken');
|
|
109
126
|
const IATokenAbi = getConfigContractAbi('IAToken');
|
|
110
127
|
const scaledBalanceMulticall = [
|
|
@@ -137,11 +154,14 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
137
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] });
|
|
138
155
|
const marketData = computeMorphoMarketData(info, morphoMarketData, multicallResponse[(2 * i) + (loanInfoCallsToSkip + 1)][0]);
|
|
139
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);
|
|
140
161
|
const data = {
|
|
141
162
|
symbol,
|
|
142
163
|
morphoMarketData,
|
|
143
164
|
hasDelta: new Dec(marketData.p2pSupplyAPY).minus(marketData.p2pBorrowAPY).gte(0.3),
|
|
144
|
-
eModeCategory: +marketData.emodeCategory,
|
|
145
165
|
aTokenAddress: marketData.aTokenAddress,
|
|
146
166
|
underlyingTokenAddress: address,
|
|
147
167
|
price: new Dec(marketData.price.toString()).div(1e8).toString(),
|
|
@@ -192,13 +212,6 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
192
212
|
.div(new Dec(marketData.totalSupply.toString()))
|
|
193
213
|
.times(100)
|
|
194
214
|
.toString(),
|
|
195
|
-
eModeCategoryData: {
|
|
196
|
-
label: marketData.label,
|
|
197
|
-
liquidationBonus: new Dec(marketData.liquidationBonus).div(10000).toString(),
|
|
198
|
-
liquidationRatio: new Dec(marketData.liquidationThreshold).div(10000).toString(),
|
|
199
|
-
collateralFactor: new Dec(marketData.ltv).div(10000).toString(),
|
|
200
|
-
priceSource: marketData.priceSource,
|
|
201
|
-
},
|
|
202
215
|
incentiveSupplyToken: 'MORPHO',
|
|
203
216
|
incentiveBorrowToken: 'MORPHO',
|
|
204
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',
|
|
@@ -235,7 +248,7 @@ export const getMorphoAaveV3MarketsData = (web3, network, selectedMarket, mainne
|
|
|
235
248
|
.forEach((assetData, i) => {
|
|
236
249
|
payload[assetData.symbol] = Object.assign(Object.assign({}, assetData), { sortIndex: i });
|
|
237
250
|
});
|
|
238
|
-
return { assetsData: payload };
|
|
251
|
+
return { assetsData: payload, eModeCategoriesData: { 1: eModeCategoryData } };
|
|
239
252
|
});
|
|
240
253
|
export const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
241
254
|
let balances = {
|
|
@@ -309,7 +322,7 @@ export const getMorphoAaveV3AccountBalances = (web3, network, block, addressMapp
|
|
|
309
322
|
});
|
|
310
323
|
return balances;
|
|
311
324
|
});
|
|
312
|
-
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* () {
|
|
313
326
|
var _g;
|
|
314
327
|
if (!address) {
|
|
315
328
|
throw new Error('No address provided.');
|
|
@@ -380,7 +393,6 @@ export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, d
|
|
|
380
393
|
if (new Dec(supplied).gt(0) || new Dec(borrowed).gt(0)) {
|
|
381
394
|
payload.usedAssets[symbol] = {
|
|
382
395
|
symbol,
|
|
383
|
-
eModeCategory: market.eModeCategory,
|
|
384
396
|
supplied,
|
|
385
397
|
suppliedP2P,
|
|
386
398
|
suppliedPool,
|
|
@@ -414,8 +426,9 @@ export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, d
|
|
|
414
426
|
};
|
|
415
427
|
}
|
|
416
428
|
});
|
|
429
|
+
payload.eModeCategory = eModeCategory;
|
|
417
430
|
payload = Object.assign(Object.assign({}, payload), aaveAnyGetAggregatedPositionData({
|
|
418
|
-
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket,
|
|
431
|
+
usedAssets: payload.usedAssets, assetsData, eModeCategory, selectedMarket, eModeCategoriesData,
|
|
419
432
|
}));
|
|
420
433
|
// Calculate borrow limits per asset
|
|
421
434
|
Object.values(payload.usedAssets).forEach((item) => {
|
|
@@ -428,6 +441,6 @@ export const getMorphoAaveV3AccountData = (web3, network, address, assetsData, d
|
|
|
428
441
|
});
|
|
429
442
|
export const getMorphoAaveV3FullPositionData = (web3, network, address, delegator, market, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
430
443
|
const marketData = yield getMorphoAaveV3MarketsData(web3, network, market, mainnetWeb3);
|
|
431
|
-
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);
|
|
432
445
|
return positionData;
|
|
433
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;
|