@defisaver/positions-sdk 2.1.43-aave-v4-dev-5 → 2.1.43-aave-v4-dev-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +64 -64
- package/cjs/aaveV4/index.js +3 -0
- package/cjs/helpers/aaveV4Helpers/index.d.ts +4 -2
- package/cjs/helpers/aaveV4Helpers/index.js +6 -6
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/savings/morphoVaults/index.js +17 -17
- package/cjs/types/aaveV4.d.ts +2 -0
- package/esm/aaveV4/index.js +3 -0
- package/esm/helpers/aaveV4Helpers/index.d.ts +4 -2
- package/esm/helpers/aaveV4Helpers/index.js +4 -5
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/savings/morphoVaults/index.js +17 -17
- package/esm/types/aaveV4.d.ts +2 -0
- package/package.json +48 -48
- package/src/aaveV2/index.ts +240 -240
- package/src/aaveV3/index.ts +625 -625
- package/src/aaveV3/merit.ts +97 -97
- package/src/aaveV3/merkl.ts +74 -74
- package/src/aaveV4/index.ts +168 -165
- package/src/claiming/aaveV3.ts +154 -154
- package/src/claiming/compV3.ts +22 -22
- package/src/claiming/ethena.ts +61 -61
- package/src/claiming/index.ts +12 -12
- package/src/claiming/king.ts +66 -66
- package/src/claiming/morphoBlue.ts +118 -118
- package/src/claiming/spark.ts +225 -225
- package/src/compoundV2/index.ts +244 -244
- package/src/compoundV3/index.ts +274 -274
- package/src/config/contracts.ts +1303 -1303
- package/src/constants/index.ts +10 -10
- package/src/contracts.ts +173 -173
- package/src/curveUsd/index.ts +254 -254
- package/src/eulerV2/index.ts +324 -324
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1800 -1800
- package/src/helpers/aaveHelpers/index.ts +187 -187
- package/src/helpers/aaveV4Helpers/index.ts +68 -67
- package/src/helpers/compoundHelpers/index.ts +283 -283
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +222 -222
- package/src/helpers/fluidHelpers/index.ts +326 -326
- package/src/helpers/index.ts +11 -11
- package/src/helpers/liquityV2Helpers/index.ts +82 -82
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +52 -52
- package/src/helpers/morphoBlueHelpers/index.ts +396 -396
- package/src/helpers/sparkHelpers/index.ts +158 -158
- package/src/index.ts +51 -51
- package/src/liquity/index.ts +159 -159
- package/src/liquityV2/index.ts +703 -703
- package/src/llamaLend/index.ts +305 -305
- package/src/maker/index.ts +223 -223
- package/src/markets/aave/index.ts +118 -118
- package/src/markets/aave/marketAssets.ts +54 -54
- package/src/markets/aaveV4/index.ts +18 -18
- package/src/markets/compound/index.ts +243 -243
- package/src/markets/compound/marketsAssets.ts +97 -97
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2900 -2900
- package/src/markets/index.ts +25 -25
- package/src/markets/liquityV2/index.ts +102 -102
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +971 -971
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +12 -12
- package/src/moneymarket/moneymarketCommonService.ts +85 -85
- package/src/morphoBlue/index.ts +274 -274
- package/src/portfolio/index.ts +618 -618
- package/src/savings/index.ts +95 -95
- package/src/savings/makerDsr/index.ts +53 -53
- package/src/savings/makerDsr/options.ts +9 -9
- package/src/savings/morphoVaults/index.ts +80 -80
- package/src/savings/morphoVaults/options.ts +193 -193
- package/src/savings/skyOptions/index.ts +95 -95
- package/src/savings/skyOptions/options.ts +10 -10
- package/src/savings/sparkSavingsVaults/index.ts +60 -60
- package/src/savings/sparkSavingsVaults/options.ts +35 -35
- package/src/savings/yearnV3Vaults/index.ts +61 -61
- package/src/savings/yearnV3Vaults/options.ts +55 -55
- package/src/savings/yearnVaults/index.ts +73 -73
- package/src/savings/yearnVaults/options.ts +32 -32
- package/src/services/priceService.ts +278 -278
- package/src/services/utils.ts +115 -115
- package/src/services/viem.ts +34 -34
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +458 -458
- package/src/staking/eligibility.ts +53 -53
- package/src/staking/index.ts +1 -1
- package/src/staking/staking.ts +186 -186
- package/src/types/aave.ts +196 -196
- package/src/types/aaveV4.ts +142 -140
- package/src/types/claiming.ts +114 -114
- package/src/types/common.ts +107 -107
- package/src/types/compound.ts +144 -144
- package/src/types/curveUsd.ts +123 -123
- package/src/types/euler.ts +175 -175
- package/src/types/fluid.ts +483 -483
- package/src/types/index.ts +15 -15
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +126 -126
- package/src/types/llamaLend.ts +159 -159
- package/src/types/maker.ts +63 -63
- package/src/types/merit.ts +1 -1
- package/src/types/merkl.ts +70 -70
- package/src/types/morphoBlue.ts +200 -200
- package/src/types/portfolio.ts +64 -64
- package/src/types/savings/index.ts +23 -23
- package/src/types/savings/makerDsr.ts +13 -13
- package/src/types/savings/morphoVaults.ts +32 -32
- package/src/types/savings/sky.ts +14 -14
- package/src/types/savings/sparkSavingsVaults.ts +15 -15
- package/src/types/savings/yearnV3Vaults.ts +17 -17
- package/src/types/savings/yearnVaults.ts +14 -14
- package/src/types/spark.ts +134 -134
- package/src/umbrella/index.ts +69 -69
- package/src/umbrella/umbrellaUtils.ts +29 -29
package/.mocharc.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"require": "ts-node/register",
|
|
3
|
-
"extension": ["ts"]
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"require": "ts-node/register",
|
|
3
|
+
"extension": ["ts"]
|
|
4
|
+
}
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v20.17.0
|
|
1
|
+
v20.17.0
|
package/README.md
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
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
|
-
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
10
|
-
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
11
|
-
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
12
|
-
|
|
13
|
-
## Setup
|
|
14
|
-
Supported Node version is v10.
|
|
15
|
-
|
|
16
|
-
- run `npm install` (first time)
|
|
17
|
-
- run `npm run build`
|
|
18
|
-
|
|
19
|
-
`build` command will generate contracts and build ejs and esm folders
|
|
20
|
-
|
|
21
|
-
## How to use
|
|
22
|
-
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
23
|
-
|
|
24
|
-
This is a Compound V3 example, and every other protocol is similar
|
|
25
|
-
```js
|
|
26
|
-
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// every protocol has market data and user data getters
|
|
30
|
-
const {
|
|
31
|
-
getCompoundV3MarketsData,
|
|
32
|
-
getCompoundV3AccountData,
|
|
33
|
-
} = compoundV3;
|
|
34
|
-
|
|
35
|
-
const provider = 'Your RPC provider';
|
|
36
|
-
|
|
37
|
-
const user = '0x123...';
|
|
38
|
-
|
|
39
|
-
const { assetsData } = await getCompoundV3MarketsData(
|
|
40
|
-
provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
41
|
-
1, // network
|
|
42
|
-
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
43
|
-
provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const userData = await getCompoundV3AccountData(
|
|
47
|
-
provider,
|
|
48
|
-
1, // network
|
|
49
|
-
userAddress, // EOA or DSProxy
|
|
50
|
-
'', // proxy address of the user, or just empty string if checking for EOA
|
|
51
|
-
{
|
|
52
|
-
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
53
|
-
assetsData,
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
59
|
-
|
|
60
|
-
## Testing
|
|
61
|
-
|
|
62
|
-
`npm run test` - Run all tests
|
|
63
|
-
|
|
64
|
-
`npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
|
|
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
|
+
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
10
|
+
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
11
|
+
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
Supported Node version is v10.
|
|
15
|
+
|
|
16
|
+
- run `npm install` (first time)
|
|
17
|
+
- run `npm run build`
|
|
18
|
+
|
|
19
|
+
`build` command will generate contracts and build ejs and esm folders
|
|
20
|
+
|
|
21
|
+
## How to use
|
|
22
|
+
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
23
|
+
|
|
24
|
+
This is a Compound V3 example, and every other protocol is similar
|
|
25
|
+
```js
|
|
26
|
+
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// every protocol has market data and user data getters
|
|
30
|
+
const {
|
|
31
|
+
getCompoundV3MarketsData,
|
|
32
|
+
getCompoundV3AccountData,
|
|
33
|
+
} = compoundV3;
|
|
34
|
+
|
|
35
|
+
const provider = 'Your RPC provider';
|
|
36
|
+
|
|
37
|
+
const user = '0x123...';
|
|
38
|
+
|
|
39
|
+
const { assetsData } = await getCompoundV3MarketsData(
|
|
40
|
+
provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
41
|
+
1, // network
|
|
42
|
+
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
43
|
+
provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const userData = await getCompoundV3AccountData(
|
|
47
|
+
provider,
|
|
48
|
+
1, // network
|
|
49
|
+
userAddress, // EOA or DSProxy
|
|
50
|
+
'', // proxy address of the user, or just empty string if checking for EOA
|
|
51
|
+
{
|
|
52
|
+
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
53
|
+
assetsData,
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
59
|
+
|
|
60
|
+
## Testing
|
|
61
|
+
|
|
62
|
+
`npm run test` - Run all tests
|
|
63
|
+
|
|
64
|
+
`npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
|
package/cjs/aaveV4/index.js
CHANGED
|
@@ -89,6 +89,7 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
89
89
|
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused && !reserveAsset.frozen,
|
|
90
90
|
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
91
91
|
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
92
|
+
utilization: new decimal_js_1.default(reserveAsset.totalDrawn.toString()).times(100).div(new decimal_js_1.default(reserveAsset.totalSupplied.toString())).toString(),
|
|
92
93
|
});
|
|
93
94
|
});
|
|
94
95
|
function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
@@ -146,6 +147,7 @@ function _getAaveV4AccountData(provider_1, network_1, spokeData_1, address_1) {
|
|
|
146
147
|
isSupplied: !new decimal_js_1.default(supplied).eq(0),
|
|
147
148
|
isBorrowed: usedReserveAsset.isBorrowing,
|
|
148
149
|
collateral: usedReserveAsset.isUsingAsCollateral,
|
|
150
|
+
collateralFactor: new decimal_js_1.default(usedReserveAsset.collateralFactor).div(10000).toNumber(),
|
|
149
151
|
};
|
|
150
152
|
return acc;
|
|
151
153
|
}, {});
|
|
@@ -154,6 +156,7 @@ function _getAaveV4AccountData(provider_1, network_1, spokeData_1, address_1) {
|
|
|
154
156
|
usedAssets,
|
|
155
157
|
assetsData: spokeData.assetsData,
|
|
156
158
|
network,
|
|
159
|
+
useUserCollateralFactor: true,
|
|
157
160
|
}));
|
|
158
161
|
});
|
|
159
162
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4UsedReserveAssets } from '../../types';
|
|
1
|
+
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets } from '../../types';
|
|
2
2
|
import { NetworkNumber } from '../../types/common';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const aaveV4GetCollateralFactor: (assetData: AaveV4ReserveAssetData, usedAssetData: AaveV4UsedReserveAsset, useUserCollateralFactor?: boolean) => number;
|
|
4
|
+
export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData, network, useUserCollateralFactor, }: {
|
|
4
5
|
usedAssets: AaveV4UsedReserveAssets;
|
|
5
6
|
assetsData: AaveV4AssetsData;
|
|
6
7
|
network: NetworkNumber;
|
|
8
|
+
useUserCollateralFactor?: boolean;
|
|
7
9
|
}) => AaveV4AggregatedPositionData;
|
|
@@ -3,18 +3,18 @@ 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.aaveV4GetAggregatedPositionData = void 0;
|
|
6
|
+
exports.aaveV4GetAggregatedPositionData = exports.aaveV4GetCollateralFactor = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const moneymarket_1 = require("../../moneymarket");
|
|
9
|
-
const
|
|
9
|
+
const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
|
|
10
|
+
exports.aaveV4GetCollateralFactor = aaveV4GetCollateralFactor;
|
|
11
|
+
const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useUserCollateralFactor = false, }) => {
|
|
10
12
|
var _a;
|
|
11
13
|
const payload = {};
|
|
12
14
|
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
13
15
|
payload.suppliedCollateralUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
14
|
-
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new decimal_js_1.default(suppliedUsd).mul(assetsData[`${symbol}-${reserveId}`]
|
|
15
|
-
payload.liquidationLimitUsd =
|
|
16
|
-
// TODO: Verify if liquidation factor is available in Aave V4, currently using collateralFactor as placeholder
|
|
17
|
-
({ symbol, suppliedUsd, reserveId }) => new decimal_js_1.default(suppliedUsd).mul(assetsData[`${symbol}-${reserveId}`].collateralFactor));
|
|
16
|
+
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new decimal_js_1.default(suppliedUsd).mul((0, exports.aaveV4GetCollateralFactor)(assetsData[`${symbol}-${reserveId}`], usedAssets[`${symbol}-${reserveId}`], useUserCollateralFactor)));
|
|
17
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
18
18
|
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
19
19
|
payload.drawnUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ drawnUsd }) => drawnUsd);
|
|
20
20
|
payload.premiumUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ premiumUsd }) => premiumUsd);
|
|
@@ -128,73 +128,73 @@ const getApyAfterValuesEstimation = (selectedMarket, actions, provider, network)
|
|
|
128
128
|
});
|
|
129
129
|
exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
|
|
130
130
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
131
|
-
const MARKET_QUERY = `
|
|
132
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
133
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
134
|
-
reallocatableLiquidityAssets
|
|
135
|
-
targetBorrowUtilization
|
|
136
|
-
loanAsset {
|
|
137
|
-
address
|
|
138
|
-
decimals
|
|
139
|
-
priceUsd
|
|
140
|
-
}
|
|
141
|
-
state {
|
|
142
|
-
liquidityAssets
|
|
143
|
-
borrowAssets
|
|
144
|
-
supplyAssets
|
|
145
|
-
}
|
|
146
|
-
publicAllocatorSharedLiquidity {
|
|
147
|
-
assets
|
|
148
|
-
vault {
|
|
149
|
-
address
|
|
150
|
-
name
|
|
151
|
-
}
|
|
152
|
-
allocationMarket {
|
|
153
|
-
uniqueKey
|
|
154
|
-
loanAsset {
|
|
155
|
-
address
|
|
156
|
-
}
|
|
157
|
-
collateralAsset {
|
|
158
|
-
address
|
|
159
|
-
}
|
|
160
|
-
irmAddress
|
|
161
|
-
oracle {
|
|
162
|
-
address
|
|
163
|
-
}
|
|
164
|
-
lltv
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
loanAsset {
|
|
168
|
-
address
|
|
169
|
-
}
|
|
170
|
-
collateralAsset {
|
|
171
|
-
address
|
|
172
|
-
}
|
|
173
|
-
oracle {
|
|
174
|
-
address
|
|
175
|
-
}
|
|
176
|
-
irmAddress
|
|
177
|
-
lltv
|
|
178
|
-
}
|
|
179
|
-
}
|
|
131
|
+
const MARKET_QUERY = `
|
|
132
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
133
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
134
|
+
reallocatableLiquidityAssets
|
|
135
|
+
targetBorrowUtilization
|
|
136
|
+
loanAsset {
|
|
137
|
+
address
|
|
138
|
+
decimals
|
|
139
|
+
priceUsd
|
|
140
|
+
}
|
|
141
|
+
state {
|
|
142
|
+
liquidityAssets
|
|
143
|
+
borrowAssets
|
|
144
|
+
supplyAssets
|
|
145
|
+
}
|
|
146
|
+
publicAllocatorSharedLiquidity {
|
|
147
|
+
assets
|
|
148
|
+
vault {
|
|
149
|
+
address
|
|
150
|
+
name
|
|
151
|
+
}
|
|
152
|
+
allocationMarket {
|
|
153
|
+
uniqueKey
|
|
154
|
+
loanAsset {
|
|
155
|
+
address
|
|
156
|
+
}
|
|
157
|
+
collateralAsset {
|
|
158
|
+
address
|
|
159
|
+
}
|
|
160
|
+
irmAddress
|
|
161
|
+
oracle {
|
|
162
|
+
address
|
|
163
|
+
}
|
|
164
|
+
lltv
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
loanAsset {
|
|
168
|
+
address
|
|
169
|
+
}
|
|
170
|
+
collateralAsset {
|
|
171
|
+
address
|
|
172
|
+
}
|
|
173
|
+
oracle {
|
|
174
|
+
address
|
|
175
|
+
}
|
|
176
|
+
irmAddress
|
|
177
|
+
lltv
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
180
|
`;
|
|
181
|
-
const REWARDS_QUERY = `
|
|
182
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
183
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
184
|
-
uniqueKey
|
|
185
|
-
state {
|
|
186
|
-
rewards {
|
|
187
|
-
amountPerSuppliedToken
|
|
188
|
-
supplyApr
|
|
189
|
-
amountPerBorrowedToken
|
|
190
|
-
borrowApr
|
|
191
|
-
asset {
|
|
192
|
-
address
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
181
|
+
const REWARDS_QUERY = `
|
|
182
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
183
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
184
|
+
uniqueKey
|
|
185
|
+
state {
|
|
186
|
+
rewards {
|
|
187
|
+
amountPerSuppliedToken
|
|
188
|
+
supplyApr
|
|
189
|
+
amountPerBorrowedToken
|
|
190
|
+
borrowApr
|
|
191
|
+
asset {
|
|
192
|
+
address
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
198
|
`;
|
|
199
199
|
/**
|
|
200
200
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
|
@@ -54,23 +54,23 @@ const morphoVaultsOptions = __importStar(require("./options"));
|
|
|
54
54
|
exports.morphoVaultsOptions = morphoVaultsOptions;
|
|
55
55
|
const viem_1 = require("../../services/viem");
|
|
56
56
|
const contracts_1 = require("../../contracts");
|
|
57
|
-
const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
|
|
58
|
-
vaultByAddress(chainId: 1, address: "${vaultAddress}") {
|
|
59
|
-
id,
|
|
60
|
-
dailyApy,
|
|
61
|
-
dailyApys {
|
|
62
|
-
apy, netApy
|
|
63
|
-
},
|
|
64
|
-
monthlyApys {
|
|
65
|
-
apy, netApy
|
|
66
|
-
},
|
|
67
|
-
liquidity {
|
|
68
|
-
underlying, usd,
|
|
69
|
-
},
|
|
70
|
-
asset {
|
|
71
|
-
priceUsd
|
|
72
|
-
}
|
|
73
|
-
}
|
|
57
|
+
const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
|
|
58
|
+
vaultByAddress(chainId: 1, address: "${vaultAddress}") {
|
|
59
|
+
id,
|
|
60
|
+
dailyApy,
|
|
61
|
+
dailyApys {
|
|
62
|
+
apy, netApy
|
|
63
|
+
},
|
|
64
|
+
monthlyApys {
|
|
65
|
+
apy, netApy
|
|
66
|
+
},
|
|
67
|
+
liquidity {
|
|
68
|
+
underlying, usd,
|
|
69
|
+
},
|
|
70
|
+
asset {
|
|
71
|
+
priceUsd
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
74
|
}`;
|
|
75
75
|
const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
|
|
76
76
|
const _getMorphoVaultData = (provider, network, morphoVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
package/cjs/types/aaveV4.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export interface AaveV4ReserveAssetData {
|
|
|
72
72
|
canBeSupplied: boolean;
|
|
73
73
|
canBeWithdrawn: boolean;
|
|
74
74
|
canBePayBacked: boolean;
|
|
75
|
+
utilization: string;
|
|
75
76
|
}
|
|
76
77
|
export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
|
|
77
78
|
export interface AaveV4SpokeData {
|
|
@@ -95,6 +96,7 @@ export interface AaveV4UsedReserveAsset {
|
|
|
95
96
|
isSupplied: boolean;
|
|
96
97
|
isBorrowed: boolean;
|
|
97
98
|
collateral: boolean;
|
|
99
|
+
collateralFactor: number;
|
|
98
100
|
}
|
|
99
101
|
export interface AaveV4AggregatedPositionData {
|
|
100
102
|
suppliedUsd: string;
|
package/esm/aaveV4/index.js
CHANGED
|
@@ -80,6 +80,7 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
80
80
|
canBeSupplied: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused && !reserveAsset.frozen,
|
|
81
81
|
canBeWithdrawn: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
82
82
|
canBePayBacked: reserveAsset.spokeActive && !reserveAsset.spokePaused && !reserveAsset.paused,
|
|
83
|
+
utilization: new Dec(reserveAsset.totalDrawn.toString()).times(100).div(new Dec(reserveAsset.totalSupplied.toString())).toString(),
|
|
83
84
|
});
|
|
84
85
|
});
|
|
85
86
|
export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
@@ -137,6 +138,7 @@ export function _getAaveV4AccountData(provider_1, network_1, spokeData_1, addres
|
|
|
137
138
|
isSupplied: !new Dec(supplied).eq(0),
|
|
138
139
|
isBorrowed: usedReserveAsset.isBorrowing,
|
|
139
140
|
collateral: usedReserveAsset.isUsingAsCollateral,
|
|
141
|
+
collateralFactor: new Dec(usedReserveAsset.collateralFactor).div(10000).toNumber(),
|
|
140
142
|
};
|
|
141
143
|
return acc;
|
|
142
144
|
}, {});
|
|
@@ -145,6 +147,7 @@ export function _getAaveV4AccountData(provider_1, network_1, spokeData_1, addres
|
|
|
145
147
|
usedAssets,
|
|
146
148
|
assetsData: spokeData.assetsData,
|
|
147
149
|
network,
|
|
150
|
+
useUserCollateralFactor: true,
|
|
148
151
|
}));
|
|
149
152
|
});
|
|
150
153
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4UsedReserveAssets } from '../../types';
|
|
1
|
+
import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets } from '../../types';
|
|
2
2
|
import { NetworkNumber } from '../../types/common';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const aaveV4GetCollateralFactor: (assetData: AaveV4ReserveAssetData, usedAssetData: AaveV4UsedReserveAsset, useUserCollateralFactor?: boolean) => number;
|
|
4
|
+
export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData, network, useUserCollateralFactor, }: {
|
|
4
5
|
usedAssets: AaveV4UsedReserveAssets;
|
|
5
6
|
assetsData: AaveV4AssetsData;
|
|
6
7
|
network: NetworkNumber;
|
|
8
|
+
useUserCollateralFactor?: boolean;
|
|
7
9
|
}) => AaveV4AggregatedPositionData;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
3
|
-
export const
|
|
3
|
+
export const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
|
|
4
|
+
export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useUserCollateralFactor = false, }) => {
|
|
4
5
|
var _a;
|
|
5
6
|
const payload = {};
|
|
6
7
|
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
7
8
|
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
8
|
-
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(assetsData[`${symbol}-${reserveId}`]
|
|
9
|
-
payload.liquidationLimitUsd =
|
|
10
|
-
// TODO: Verify if liquidation factor is available in Aave V4, currently using collateralFactor as placeholder
|
|
11
|
-
({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(assetsData[`${symbol}-${reserveId}`].collateralFactor));
|
|
9
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(aaveV4GetCollateralFactor(assetsData[`${symbol}-${reserveId}`], usedAssets[`${symbol}-${reserveId}`], useUserCollateralFactor)));
|
|
10
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
12
11
|
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
13
12
|
payload.drawnUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ drawnUsd }) => drawnUsd);
|
|
14
13
|
payload.premiumUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ premiumUsd }) => premiumUsd);
|
|
@@ -118,73 +118,73 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, n
|
|
|
118
118
|
return { borrowRate, supplyRate };
|
|
119
119
|
});
|
|
120
120
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
121
|
-
const MARKET_QUERY = `
|
|
122
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
123
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
124
|
-
reallocatableLiquidityAssets
|
|
125
|
-
targetBorrowUtilization
|
|
126
|
-
loanAsset {
|
|
127
|
-
address
|
|
128
|
-
decimals
|
|
129
|
-
priceUsd
|
|
130
|
-
}
|
|
131
|
-
state {
|
|
132
|
-
liquidityAssets
|
|
133
|
-
borrowAssets
|
|
134
|
-
supplyAssets
|
|
135
|
-
}
|
|
136
|
-
publicAllocatorSharedLiquidity {
|
|
137
|
-
assets
|
|
138
|
-
vault {
|
|
139
|
-
address
|
|
140
|
-
name
|
|
141
|
-
}
|
|
142
|
-
allocationMarket {
|
|
143
|
-
uniqueKey
|
|
144
|
-
loanAsset {
|
|
145
|
-
address
|
|
146
|
-
}
|
|
147
|
-
collateralAsset {
|
|
148
|
-
address
|
|
149
|
-
}
|
|
150
|
-
irmAddress
|
|
151
|
-
oracle {
|
|
152
|
-
address
|
|
153
|
-
}
|
|
154
|
-
lltv
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
loanAsset {
|
|
158
|
-
address
|
|
159
|
-
}
|
|
160
|
-
collateralAsset {
|
|
161
|
-
address
|
|
162
|
-
}
|
|
163
|
-
oracle {
|
|
164
|
-
address
|
|
165
|
-
}
|
|
166
|
-
irmAddress
|
|
167
|
-
lltv
|
|
168
|
-
}
|
|
169
|
-
}
|
|
121
|
+
const MARKET_QUERY = `
|
|
122
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
123
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
124
|
+
reallocatableLiquidityAssets
|
|
125
|
+
targetBorrowUtilization
|
|
126
|
+
loanAsset {
|
|
127
|
+
address
|
|
128
|
+
decimals
|
|
129
|
+
priceUsd
|
|
130
|
+
}
|
|
131
|
+
state {
|
|
132
|
+
liquidityAssets
|
|
133
|
+
borrowAssets
|
|
134
|
+
supplyAssets
|
|
135
|
+
}
|
|
136
|
+
publicAllocatorSharedLiquidity {
|
|
137
|
+
assets
|
|
138
|
+
vault {
|
|
139
|
+
address
|
|
140
|
+
name
|
|
141
|
+
}
|
|
142
|
+
allocationMarket {
|
|
143
|
+
uniqueKey
|
|
144
|
+
loanAsset {
|
|
145
|
+
address
|
|
146
|
+
}
|
|
147
|
+
collateralAsset {
|
|
148
|
+
address
|
|
149
|
+
}
|
|
150
|
+
irmAddress
|
|
151
|
+
oracle {
|
|
152
|
+
address
|
|
153
|
+
}
|
|
154
|
+
lltv
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
loanAsset {
|
|
158
|
+
address
|
|
159
|
+
}
|
|
160
|
+
collateralAsset {
|
|
161
|
+
address
|
|
162
|
+
}
|
|
163
|
+
oracle {
|
|
164
|
+
address
|
|
165
|
+
}
|
|
166
|
+
irmAddress
|
|
167
|
+
lltv
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
170
|
`;
|
|
171
|
-
const REWARDS_QUERY = `
|
|
172
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
173
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
174
|
-
uniqueKey
|
|
175
|
-
state {
|
|
176
|
-
rewards {
|
|
177
|
-
amountPerSuppliedToken
|
|
178
|
-
supplyApr
|
|
179
|
-
amountPerBorrowedToken
|
|
180
|
-
borrowApr
|
|
181
|
-
asset {
|
|
182
|
-
address
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
171
|
+
const REWARDS_QUERY = `
|
|
172
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
173
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
174
|
+
uniqueKey
|
|
175
|
+
state {
|
|
176
|
+
rewards {
|
|
177
|
+
amountPerSuppliedToken
|
|
178
|
+
supplyApr
|
|
179
|
+
amountPerBorrowedToken
|
|
180
|
+
borrowApr
|
|
181
|
+
asset {
|
|
182
|
+
address
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
188
|
`;
|
|
189
189
|
/**
|
|
190
190
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
|
@@ -14,23 +14,23 @@ import * as morphoVaultsOptions from './options';
|
|
|
14
14
|
import { getViemProvider } from '../../services/viem';
|
|
15
15
|
import { getMorphoVaultContractViem } from '../../contracts';
|
|
16
16
|
export { morphoVaultsOptions, };
|
|
17
|
-
const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
|
|
18
|
-
vaultByAddress(chainId: 1, address: "${vaultAddress}") {
|
|
19
|
-
id,
|
|
20
|
-
dailyApy,
|
|
21
|
-
dailyApys {
|
|
22
|
-
apy, netApy
|
|
23
|
-
},
|
|
24
|
-
monthlyApys {
|
|
25
|
-
apy, netApy
|
|
26
|
-
},
|
|
27
|
-
liquidity {
|
|
28
|
-
underlying, usd,
|
|
29
|
-
},
|
|
30
|
-
asset {
|
|
31
|
-
priceUsd
|
|
32
|
-
}
|
|
33
|
-
}
|
|
17
|
+
const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
|
|
18
|
+
vaultByAddress(chainId: 1, address: "${vaultAddress}") {
|
|
19
|
+
id,
|
|
20
|
+
dailyApy,
|
|
21
|
+
dailyApys {
|
|
22
|
+
apy, netApy
|
|
23
|
+
},
|
|
24
|
+
monthlyApys {
|
|
25
|
+
apy, netApy
|
|
26
|
+
},
|
|
27
|
+
liquidity {
|
|
28
|
+
underlying, usd,
|
|
29
|
+
},
|
|
30
|
+
asset {
|
|
31
|
+
priceUsd
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
34
|
}`;
|
|
35
35
|
const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
|
|
36
36
|
export const _getMorphoVaultData = (provider, network, morphoVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
package/esm/types/aaveV4.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export interface AaveV4ReserveAssetData {
|
|
|
72
72
|
canBeSupplied: boolean;
|
|
73
73
|
canBeWithdrawn: boolean;
|
|
74
74
|
canBePayBacked: boolean;
|
|
75
|
+
utilization: string;
|
|
75
76
|
}
|
|
76
77
|
export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
|
|
77
78
|
export interface AaveV4SpokeData {
|
|
@@ -95,6 +96,7 @@ export interface AaveV4UsedReserveAsset {
|
|
|
95
96
|
isSupplied: boolean;
|
|
96
97
|
isBorrowed: boolean;
|
|
97
98
|
collateral: boolean;
|
|
99
|
+
collateralFactor: number;
|
|
98
100
|
}
|
|
99
101
|
export interface AaveV4AggregatedPositionData {
|
|
100
102
|
suppliedUsd: string;
|