@defisaver/positions-sdk 1.0.21 → 1.0.22-dev-aave-v3.4
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 +69 -69
- package/cjs/aaveV3/index.d.ts +2 -2
- package/cjs/aaveV3/index.js +47 -64
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/liquityV2/index.d.ts +10 -1
- package/cjs/liquityV2/index.js +12 -2
- package/cjs/staking/staking.js +1 -3
- package/cjs/types/aave.d.ts +3 -3
- package/esm/aaveV3/index.d.ts +2 -2
- package/esm/aaveV3/index.js +49 -66
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/liquityV2/index.d.ts +10 -1
- package/esm/liquityV2/index.js +12 -2
- package/esm/staking/staking.js +1 -3
- package/esm/types/aave.d.ts +3 -3
- package/package.json +54 -54
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +543 -624
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +220 -220
- package/src/compoundV3/index.ts +291 -291
- package/src/config/contracts.js +1173 -1173
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +138 -138
- package/src/curveUsd/index.ts +239 -239
- package/src/eulerV2/index.ts +303 -303
- package/src/exchange/index.ts +17 -17
- package/src/fluid/index.ts +1348 -1348
- package/src/helpers/aaveHelpers/index.ts +203 -203
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +248 -248
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +234 -234
- package/src/helpers/fluidHelpers/index.ts +325 -325
- package/src/helpers/index.ts +11 -11
- package/src/helpers/liquityV2Helpers/index.ts +80 -80
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +367 -367
- package/src/helpers/sparkHelpers/index.ts +154 -154
- package/src/index.ts +52 -52
- package/src/liquity/index.ts +116 -116
- package/src/liquityV2/index.ts +327 -317
- 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 +47 -47
- package/src/markets/compound/index.ts +213 -213
- package/src/markets/compound/marketsAssets.ts +82 -82
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2456 -2456
- package/src/markets/index.ts +27 -27
- 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 +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +630 -630
- package/src/morphoBlue/index.ts +202 -202
- package/src/multicall/index.ts +33 -33
- package/src/services/priceService.ts +143 -143
- package/src/services/utils.ts +59 -59
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +460 -460
- package/src/staking/staking.ts +219 -221
- package/src/types/aave.ts +275 -275
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +133 -133
- package/src/types/curveUsd.ts +119 -119
- package/src/types/euler.ts +173 -173
- package/src/types/fluid.ts +330 -330
- package/src/types/index.ts +11 -11
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +126 -126
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +194 -194
- package/src/types/spark.ts +135 -135
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,69 +1,69 @@
|
|
|
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)
|
|
64
|
-
|
|
65
|
-
## Testing
|
|
66
|
-
|
|
67
|
-
`npm run test` - Run all tests
|
|
68
|
-
|
|
69
|
-
`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
|
+
- [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)
|
|
64
|
+
|
|
65
|
+
## Testing
|
|
66
|
+
|
|
67
|
+
`npm run test` - Run all tests
|
|
68
|
+
|
|
69
|
+
`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/aaveV3/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const aaveV3CalculateDiscountRate: (debtBalance: string, discount
|
|
|
6
6
|
export declare const aaveV3EmodeCategoriesMapping: (extractedState: any, usedAssets: AaveV3UsedAssets) => {
|
|
7
7
|
[key: number]: EModeCategoryDataMapping;
|
|
8
8
|
};
|
|
9
|
-
export declare function getAaveV3MarketData(web3: Web3, network: NetworkNumber, market: AaveMarketInfo, defaultWeb3: Web3
|
|
9
|
+
export declare function getAaveV3MarketData(web3: Web3, network: NetworkNumber, market: AaveMarketInfo, defaultWeb3: Web3): Promise<AaveV3MarketData>;
|
|
10
10
|
export declare const EMPTY_AAVE_DATA: {
|
|
11
11
|
usedAssets: {};
|
|
12
12
|
suppliedUsd: string;
|
|
@@ -29,5 +29,5 @@ export declare const EMPTY_AAVE_DATA: {
|
|
|
29
29
|
suppliedCollateralUsd: string;
|
|
30
30
|
};
|
|
31
31
|
export declare const getAaveV3AccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
32
|
-
export declare const getAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: EthAddress, extractedState: any
|
|
32
|
+
export declare const getAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: EthAddress, extractedState: any) => Promise<AaveV3PositionData>;
|
|
33
33
|
export declare const getAaveV3FullPositionData: (web3: Web3, network: NetworkNumber, address: string, market: AaveMarketInfo, mainnetWeb3: Web3) => Promise<AaveV3PositionData>;
|
package/cjs/aaveV3/index.js
CHANGED
|
@@ -72,50 +72,18 @@ const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
72
72
|
return categoriesMapping;
|
|
73
73
|
};
|
|
74
74
|
exports.aaveV3EmodeCategoriesMapping = aaveV3EmodeCategoriesMapping;
|
|
75
|
-
function getAaveV3MarketData(web3, network, market, defaultWeb3
|
|
75
|
+
function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
76
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
77
|
const _addresses = market.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a), network).address);
|
|
78
78
|
const isL2 = (0, utils_1.isLayer2Network)(network);
|
|
79
79
|
const loanInfoContract = (0, contracts_1.AaveV3ViewContract)(web3, network);
|
|
80
80
|
const aaveIncentivesContract = (0, contracts_1.AaveIncentiveDataProviderV3Contract)(web3, network);
|
|
81
81
|
const marketAddress = market.providerAddress;
|
|
82
|
-
const GhoDiscountRateStrategyAddress = (0, contracts_1.getConfigContractAddress)('GhoDiscountRateStrategy', common_1.NetworkNumber.Eth);
|
|
83
|
-
const GhoDiscountRateStrategyAbi = (0, contracts_1.getConfigContractAbi)('GhoDiscountRateStrategy');
|
|
84
|
-
const GhoTokenAbi = (0, contracts_1.getConfigContractAbi)('GHO');
|
|
85
|
-
const multicallCallsObject = [
|
|
86
|
-
{
|
|
87
|
-
target: GhoDiscountRateStrategyAddress,
|
|
88
|
-
abiItem: (0, utils_1.getAbiItem)(GhoDiscountRateStrategyAbi, 'GHO_DISCOUNTED_PER_DISCOUNT_TOKEN'),
|
|
89
|
-
params: [],
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
target: GhoDiscountRateStrategyAddress,
|
|
93
|
-
abiItem: (0, utils_1.getAbiItem)(GhoDiscountRateStrategyAbi, 'DISCOUNT_RATE'),
|
|
94
|
-
params: [],
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
target: GhoDiscountRateStrategyAddress,
|
|
98
|
-
abiItem: (0, utils_1.getAbiItem)(GhoDiscountRateStrategyAbi, 'MIN_DISCOUNT_TOKEN_BALANCE'),
|
|
99
|
-
params: [],
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
target: GhoDiscountRateStrategyAddress,
|
|
103
|
-
abiItem: (0, utils_1.getAbiItem)(GhoDiscountRateStrategyAbi, 'MIN_DEBT_TOKEN_BALANCE'),
|
|
104
|
-
params: [],
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
target: (0, tokens_1.getAssetInfo)('GHO', network).address,
|
|
108
|
-
abiItem: (0, utils_1.getAbiItem)(GhoTokenAbi, 'getFacilitatorsList'),
|
|
109
|
-
params: [],
|
|
110
|
-
},
|
|
111
|
-
];
|
|
112
|
-
const ghoContract = (0, contracts_1.GhoTokenContract)(web3, network);
|
|
113
82
|
// eslint-disable-next-line prefer-const
|
|
114
|
-
let [loanInfo, eModesInfo, isBorrowAllowed
|
|
115
|
-
loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(
|
|
116
|
-
loanInfoContract.methods.getAllEmodes(marketAddress).call(
|
|
117
|
-
loanInfoContract.methods.isBorrowAllowed(marketAddress).call(
|
|
118
|
-
isL2 ? [{ 0: null }, { 0: null }, { 0: null }, { 0: null }, { 0: null }] : (0, multicall_1.multicall)(multicallCallsObject, web3, network, blockNumber),
|
|
83
|
+
let [loanInfo, eModesInfo, isBorrowAllowed] = yield Promise.all([
|
|
84
|
+
loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(),
|
|
85
|
+
loanInfoContract.methods.getAllEmodes(marketAddress).call(),
|
|
86
|
+
loanInfoContract.methods.isBorrowAllowed(marketAddress).call(), // Used on L2s check for PriceOracleSentinel (mainnet will always return true)
|
|
119
87
|
]);
|
|
120
88
|
isBorrowAllowed = (0, utils_1.isLayer2Network)(network) ? isBorrowAllowed : true;
|
|
121
89
|
const eModeCategoriesData = {};
|
|
@@ -134,7 +102,6 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3, blockNumber = '
|
|
|
134
102
|
collateralAssets: [],
|
|
135
103
|
};
|
|
136
104
|
}
|
|
137
|
-
const [{ 0: ghoDiscountedPerDiscountToken }, { 0: discountRate }, { 0: minDiscountTokenBalance }, { 0: minGhoBalanceForDiscount }, { 0: facilitatorsList },] = multiRes;
|
|
138
105
|
let rewardInfo = null;
|
|
139
106
|
const networksWithIncentives = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Opt];
|
|
140
107
|
if (networksWithIncentives.includes(network)) {
|
|
@@ -148,7 +115,6 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3, blockNumber = '
|
|
|
148
115
|
const assetsData = yield Promise.all(loanInfo
|
|
149
116
|
.map((tokenMarket, i) => __awaiter(this, void 0, void 0, function* () {
|
|
150
117
|
const symbol = market.assets[i];
|
|
151
|
-
const nativeAsset = symbol === 'GHO' && network === common_1.NetworkNumber.Eth && market.value === 'v3default';
|
|
152
118
|
// eslint-disable-next-line guard-for-in
|
|
153
119
|
for (const eModeIndex in eModeCategoriesData) {
|
|
154
120
|
if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoriesData[eModeIndex].collateralBitmap), Number(tokenMarket.assetId)))
|
|
@@ -156,16 +122,10 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3, blockNumber = '
|
|
|
156
122
|
if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoriesData[eModeIndex].borrowableBitmap), Number(tokenMarket.assetId)))
|
|
157
123
|
eModeCategoriesData[eModeIndex].borrowAssets.push(symbol);
|
|
158
124
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
|
|
162
|
-
const facilitatorBucket = yield ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
|
|
163
|
-
borrowCap = decimal_js_1.default.min(borrowCap, (0, tokens_1.assetAmountInEth)(facilitatorBucket[0], 'GHO')).toString();
|
|
164
|
-
discountRateOnBorrow = (0, exports.aaveV3CalculateDiscountRate)(tokenMarket.totalBorrow.toString(), '3160881469228662060510133', // stkAAVE total supply
|
|
165
|
-
discountRate, minDiscountTokenBalance, minGhoBalanceForDiscount, ghoDiscountedPerDiscountToken);
|
|
166
|
-
}
|
|
125
|
+
const borrowCap = tokenMarket.borrowCap;
|
|
126
|
+
const discountRateOnBorrow = '0';
|
|
167
127
|
const borrowCapInWei = new decimal_js_1.default((0, tokens_1.assetAmountInWei)(borrowCap.toString(), symbol));
|
|
168
|
-
let marketLiquidity = borrowCapInWei.lt(new decimal_js_1.default(tokenMarket.totalSupply))
|
|
128
|
+
let marketLiquidity = borrowCapInWei.lt(new decimal_js_1.default(tokenMarket.totalSupply))
|
|
169
129
|
? (0, tokens_1.assetAmountInEth)(borrowCapInWei
|
|
170
130
|
.sub(tokenMarket.totalBorrow.toString())
|
|
171
131
|
.toString(), symbol)
|
|
@@ -175,14 +135,42 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3, blockNumber = '
|
|
|
175
135
|
if (new decimal_js_1.default(marketLiquidity).lt(0)) {
|
|
176
136
|
marketLiquidity = '0';
|
|
177
137
|
}
|
|
178
|
-
return (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
138
|
+
return ({
|
|
139
|
+
symbol,
|
|
140
|
+
isIsolated: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).gt(0),
|
|
141
|
+
debtCeilingForIsolationMode: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).div(100).toString(),
|
|
142
|
+
isSiloed: tokenMarket.isSiloedForBorrowing,
|
|
143
|
+
isolationModeTotalDebt: new decimal_js_1.default(tokenMarket.isolationModeTotalDebt).div(100).toString(),
|
|
144
|
+
assetId: Number(tokenMarket.assetId),
|
|
145
|
+
underlyingTokenAddress: tokenMarket.underlyingTokenAddress,
|
|
146
|
+
supplyRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenMarket.supplyRate.toString()).div(1e25).toString()),
|
|
147
|
+
borrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).toString()),
|
|
148
|
+
borrowRateDiscounted: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).toString()),
|
|
149
|
+
borrowRateStable: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenMarket.borrowRateStable.toString()).div(1e25).toString()),
|
|
150
|
+
collateralFactor: new decimal_js_1.default(tokenMarket.collateralFactor.toString()).div(10000).toString(),
|
|
151
|
+
liquidationBonus: new decimal_js_1.default(tokenMarket.liquidationBonus.toString()).div(10000).toString(),
|
|
152
|
+
liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationRatio.toString()).div(10000).toString(),
|
|
153
|
+
marketLiquidity,
|
|
154
|
+
utilization: new decimal_js_1.default(tokenMarket.totalBorrow.toString()).times(100).div(new decimal_js_1.default(tokenMarket.totalSupply.toString())).toString(),
|
|
155
|
+
usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled,
|
|
156
|
+
supplyCap: tokenMarket.supplyCap,
|
|
157
|
+
borrowCap,
|
|
158
|
+
totalSupply: (0, tokens_1.assetAmountInEth)(tokenMarket.totalSupply.toString(), symbol),
|
|
159
|
+
isInactive: !tokenMarket.isActive,
|
|
160
|
+
isFrozen: tokenMarket.isFrozen,
|
|
161
|
+
isPaused: tokenMarket.isPaused,
|
|
162
|
+
canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed,
|
|
163
|
+
canBeSupplied: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen,
|
|
164
|
+
canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused,
|
|
165
|
+
canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused,
|
|
166
|
+
disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled,
|
|
167
|
+
totalBorrow: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrow.toString(), symbol),
|
|
168
|
+
totalBorrowVar: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrowVar.toString(), symbol),
|
|
169
|
+
price: new decimal_js_1.default(tokenMarket.price.toString()).div(1e8).toString(),
|
|
170
|
+
isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled,
|
|
171
|
+
isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled,
|
|
172
|
+
aTokenAddress: tokenMarket.aTokenAddress,
|
|
173
|
+
});
|
|
186
174
|
})));
|
|
187
175
|
// Get incentives data
|
|
188
176
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -361,7 +349,7 @@ const getAaveV3AccountBalances = (web3, network, block, addressMapping, address)
|
|
|
361
349
|
return balances;
|
|
362
350
|
});
|
|
363
351
|
exports.getAaveV3AccountBalances = getAaveV3AccountBalances;
|
|
364
|
-
const getAaveV3AccountData = (web3, network, address, extractedState
|
|
352
|
+
const getAaveV3AccountData = (web3, network, address, extractedState) => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
353
|
const { selectedMarket: market, assetsData, eModeCategoriesData, } = extractedState;
|
|
366
354
|
let payload = Object.assign(Object.assign({}, exports.EMPTY_AAVE_DATA), { lastUpdated: Date.now() });
|
|
367
355
|
if (!address) {
|
|
@@ -395,7 +383,7 @@ const getAaveV3AccountData = (web3, network, address, extractedState, blockNumbe
|
|
|
395
383
|
},
|
|
396
384
|
];
|
|
397
385
|
const [multicallRes, { 0: stkAaveBalance }] = yield Promise.all([
|
|
398
|
-
(0, multicall_1.multicall)(multicallData, web3, network
|
|
386
|
+
(0, multicall_1.multicall)(multicallData, web3, network),
|
|
399
387
|
isL2 ? { 0: '0' } : (0, assets_1.getAssetsBalances)(['stkAAVE'], address, network, web3),
|
|
400
388
|
{ 0: '0' },
|
|
401
389
|
]);
|
|
@@ -423,13 +411,8 @@ const getAaveV3AccountData = (web3, network, address, extractedState, blockNumbe
|
|
|
423
411
|
}
|
|
424
412
|
if (!usedAssets[asset])
|
|
425
413
|
usedAssets[asset] = {};
|
|
426
|
-
const nativeAsset = asset === 'GHO' && network === common_1.NetworkNumber.Eth && market.value === 'v3default';
|
|
427
|
-
let discountRateOnBorrow = '0';
|
|
428
414
|
const borrowed = new decimal_js_1.default(borrowedStable).add(borrowedVariable).toString();
|
|
429
|
-
|
|
430
|
-
discountRateOnBorrow = (0, exports.aaveV3CalculateDiscountRate)((0, tokens_1.assetAmountInWei)(borrowed, 'GHO'), (0, tokens_1.assetAmountInWei)(stkAaveBalance, 'stkAAVE'), assetsData[asset].discountData.discountRate, assetsData[asset].discountData.minDiscountTokenBalance, assetsData[asset].discountData.minGhoBalanceForDiscount, assetsData[asset].discountData.ghoDiscountedPerDiscountToken);
|
|
431
|
-
}
|
|
432
|
-
usedAssets[asset] = Object.assign(Object.assign({}, usedAssets[asset]), { symbol: asset, supplied, suppliedUsd: new decimal_js_1.default(supplied).mul(assetsData[asset].price).toString(), isSupplied, collateral: enabledAsCollateral, stableBorrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenInfo.stableBorrowRate).div(1e25).toString()), discountedBorrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(assetsData[asset].borrowRate).mul(1 - parseFloat(discountRateOnBorrow)).toString()), borrowedStable,
|
|
415
|
+
usedAssets[asset] = Object.assign(Object.assign({}, usedAssets[asset]), { symbol: asset, supplied, suppliedUsd: new decimal_js_1.default(supplied).mul(assetsData[asset].price).toString(), isSupplied, collateral: enabledAsCollateral, stableBorrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(tokenInfo.stableBorrowRate).div(1e25).toString()), discountedBorrowRate: (0, moneymarket_1.aprToApy)(assetsData[asset].borrowRate), borrowedStable,
|
|
433
416
|
borrowedVariable, borrowedUsdStable: new decimal_js_1.default(borrowedStable).mul(assetsData[asset].price).toString(), borrowedUsdVariable: new decimal_js_1.default(borrowedVariable).mul(assetsData[asset].price).toString(), borrowed, borrowedUsd: new decimal_js_1.default(new decimal_js_1.default(borrowedVariable).add(borrowedStable)).mul(assetsData[asset].price).toString(), isBorrowed,
|
|
434
417
|
interestMode });
|
|
435
418
|
}));
|
|
@@ -117,73 +117,73 @@ const getApyAfterValuesEstimation = (selectedMarket, actions, web3, network) =>
|
|
|
117
117
|
});
|
|
118
118
|
exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
|
|
119
119
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
120
|
-
const MARKET_QUERY = `
|
|
121
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
122
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
123
|
-
reallocatableLiquidityAssets
|
|
124
|
-
targetBorrowUtilization
|
|
125
|
-
loanAsset {
|
|
126
|
-
address
|
|
127
|
-
decimals
|
|
128
|
-
priceUsd
|
|
129
|
-
}
|
|
130
|
-
state {
|
|
131
|
-
liquidityAssets
|
|
132
|
-
borrowAssets
|
|
133
|
-
supplyAssets
|
|
134
|
-
}
|
|
135
|
-
publicAllocatorSharedLiquidity {
|
|
136
|
-
assets
|
|
137
|
-
vault {
|
|
138
|
-
address
|
|
139
|
-
name
|
|
140
|
-
}
|
|
141
|
-
allocationMarket {
|
|
142
|
-
uniqueKey
|
|
143
|
-
loanAsset {
|
|
144
|
-
address
|
|
145
|
-
}
|
|
146
|
-
collateralAsset {
|
|
147
|
-
address
|
|
148
|
-
}
|
|
149
|
-
irmAddress
|
|
150
|
-
oracle {
|
|
151
|
-
address
|
|
152
|
-
}
|
|
153
|
-
lltv
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
loanAsset {
|
|
157
|
-
address
|
|
158
|
-
}
|
|
159
|
-
collateralAsset {
|
|
160
|
-
address
|
|
161
|
-
}
|
|
162
|
-
oracle {
|
|
163
|
-
address
|
|
164
|
-
}
|
|
165
|
-
irmAddress
|
|
166
|
-
lltv
|
|
167
|
-
}
|
|
168
|
-
}
|
|
120
|
+
const MARKET_QUERY = `
|
|
121
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
122
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
123
|
+
reallocatableLiquidityAssets
|
|
124
|
+
targetBorrowUtilization
|
|
125
|
+
loanAsset {
|
|
126
|
+
address
|
|
127
|
+
decimals
|
|
128
|
+
priceUsd
|
|
129
|
+
}
|
|
130
|
+
state {
|
|
131
|
+
liquidityAssets
|
|
132
|
+
borrowAssets
|
|
133
|
+
supplyAssets
|
|
134
|
+
}
|
|
135
|
+
publicAllocatorSharedLiquidity {
|
|
136
|
+
assets
|
|
137
|
+
vault {
|
|
138
|
+
address
|
|
139
|
+
name
|
|
140
|
+
}
|
|
141
|
+
allocationMarket {
|
|
142
|
+
uniqueKey
|
|
143
|
+
loanAsset {
|
|
144
|
+
address
|
|
145
|
+
}
|
|
146
|
+
collateralAsset {
|
|
147
|
+
address
|
|
148
|
+
}
|
|
149
|
+
irmAddress
|
|
150
|
+
oracle {
|
|
151
|
+
address
|
|
152
|
+
}
|
|
153
|
+
lltv
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
loanAsset {
|
|
157
|
+
address
|
|
158
|
+
}
|
|
159
|
+
collateralAsset {
|
|
160
|
+
address
|
|
161
|
+
}
|
|
162
|
+
oracle {
|
|
163
|
+
address
|
|
164
|
+
}
|
|
165
|
+
irmAddress
|
|
166
|
+
lltv
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
169
|
`;
|
|
170
|
-
const REWARDS_QUERY = `
|
|
171
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
172
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
173
|
-
uniqueKey
|
|
174
|
-
state {
|
|
175
|
-
rewards {
|
|
176
|
-
amountPerSuppliedToken
|
|
177
|
-
supplyApr
|
|
178
|
-
amountPerBorrowedToken
|
|
179
|
-
borrowApr
|
|
180
|
-
asset {
|
|
181
|
-
address
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
170
|
+
const REWARDS_QUERY = `
|
|
171
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
172
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
173
|
+
uniqueKey
|
|
174
|
+
state {
|
|
175
|
+
rewards {
|
|
176
|
+
amountPerSuppliedToken
|
|
177
|
+
supplyApr
|
|
178
|
+
amountPerBorrowedToken
|
|
179
|
+
borrowApr
|
|
180
|
+
asset {
|
|
181
|
+
address
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
187
|
`;
|
|
188
188
|
/**
|
|
189
189
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
package/cjs/liquityV2/index.d.ts
CHANGED
|
@@ -13,7 +13,16 @@ export declare const getDebtInFrontForInterestRateSingleMarketLiquityV2: (viewCo
|
|
|
13
13
|
export declare const getAllMarketsUnbackedDebts: (markets: Record<LiquityV2Versions, LiquityV2MarketData>, web3: Web3, network: NetworkNumber) => Promise<Record<LiquityV2Versions, string>>;
|
|
14
14
|
export declare const calculateDebtInFrontLiquityV2: (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, allMarketsUnbackedDebts: Record<LiquityV2Versions, string>, interestRateDebtInFront: string) => string;
|
|
15
15
|
export declare const getDebtInFrontLiquityV2: (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, web3: Web3, network: NetworkNumber, viewContract: any, troveId: string) => Promise<string>;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @param markets
|
|
18
|
+
* @param selectedMarket
|
|
19
|
+
* @param web3
|
|
20
|
+
* @param network
|
|
21
|
+
* @param viewContract
|
|
22
|
+
* @param interestRate
|
|
23
|
+
* @param debtInFrontBeingMoved - amound of debt being repositioned if interest rate is being increased (prevents including it as debt in front)
|
|
24
|
+
*/
|
|
25
|
+
export declare const getDebtInFrontForInterestRateLiquityV2: (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, web3: Web3, network: NetworkNumber, viewContract: any, interestRate: string, debtInFrontBeingMoved?: string) => Promise<string>;
|
|
17
26
|
export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, troveId, allMarketsData, }: {
|
|
18
27
|
selectedMarket: LiquityV2MarketInfo;
|
|
19
28
|
assetsData: LiquityV2AssetsData;
|
package/cjs/liquityV2/index.js
CHANGED
|
@@ -207,9 +207,19 @@ const getDebtInFrontLiquityV2 = (markets, selectedMarket, web3, network, viewCon
|
|
|
207
207
|
return (0, exports.calculateDebtInFrontLiquityV2)(markets, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
208
208
|
});
|
|
209
209
|
exports.getDebtInFrontLiquityV2 = getDebtInFrontLiquityV2;
|
|
210
|
-
|
|
210
|
+
/**
|
|
211
|
+
* @param markets
|
|
212
|
+
* @param selectedMarket
|
|
213
|
+
* @param web3
|
|
214
|
+
* @param network
|
|
215
|
+
* @param viewContract
|
|
216
|
+
* @param interestRate
|
|
217
|
+
* @param debtInFrontBeingMoved - amound of debt being repositioned if interest rate is being increased (prevents including it as debt in front)
|
|
218
|
+
*/
|
|
219
|
+
const getDebtInFrontForInterestRateLiquityV2 = (markets, selectedMarket, web3, network, viewContract, interestRate, debtInFrontBeingMoved = '0') => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
220
|
const allMarketsUnbackedDebts = yield (0, exports.getAllMarketsUnbackedDebts)(markets, web3, network);
|
|
212
|
-
const interestRateDebtInFront = new decimal_js_1.default(yield (0, exports.getDebtInFrontForInterestRateSingleMarketLiquityV2)(viewContract, (0, markets_1.LiquityV2Markets)(network)[selectedMarket].marketAddress, interestRate))
|
|
221
|
+
const interestRateDebtInFront = new decimal_js_1.default(yield (0, exports.getDebtInFrontForInterestRateSingleMarketLiquityV2)(viewContract, (0, markets_1.LiquityV2Markets)(network)[selectedMarket].marketAddress, interestRate))
|
|
222
|
+
.sub(debtInFrontBeingMoved);
|
|
213
223
|
return (0, exports.calculateDebtInFrontLiquityV2)(markets, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
214
224
|
});
|
|
215
225
|
exports.getDebtInFrontForInterestRateLiquityV2 = getDebtInFrontForInterestRateLiquityV2;
|
package/cjs/staking/staking.js
CHANGED
|
@@ -194,9 +194,7 @@ const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false }) => {
|
|
|
194
194
|
acc.borrowedUsd = new decimal_js_1.default(acc.borrowedUsd).add(amount).toString();
|
|
195
195
|
const rate = isMorpho
|
|
196
196
|
? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
|
|
197
|
-
: (usedAsset.
|
|
198
|
-
? usedAsset.discountedBorrowRate
|
|
199
|
-
: ((usedAsset === null || usedAsset === void 0 ? void 0 : usedAsset.interestMode) === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
|
|
197
|
+
: ((usedAsset === null || usedAsset === void 0 ? void 0 : usedAsset.interestMode) === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
|
|
200
198
|
const borrowInterest = (0, exports.calculateInterestEarned)(amount, rate, 'year', true);
|
|
201
199
|
acc.borrowInterest = new decimal_js_1.default(acc.borrowInterest).sub(borrowInterest.toString()).toString();
|
|
202
200
|
if (assetData.incentiveBorrowApy) {
|
package/cjs/types/aave.d.ts
CHANGED
|
@@ -81,8 +81,8 @@ export interface IncentiveData {
|
|
|
81
81
|
export interface AaveV3AssetData extends AaveAssetData {
|
|
82
82
|
isIsolated: boolean;
|
|
83
83
|
isSiloed: boolean;
|
|
84
|
-
nativeAsset
|
|
85
|
-
discountData
|
|
84
|
+
nativeAsset?: boolean;
|
|
85
|
+
discountData?: DiscountData;
|
|
86
86
|
debtCeilingForIsolationMode: string;
|
|
87
87
|
isolationModeTotalDebt: string;
|
|
88
88
|
borrowRateDiscounted: string;
|
|
@@ -92,7 +92,7 @@ export interface AaveV3AssetData extends AaveAssetData {
|
|
|
92
92
|
isFrozen: boolean;
|
|
93
93
|
isPaused: boolean;
|
|
94
94
|
isFlashLoanEnabled: boolean;
|
|
95
|
-
assetId: string | null;
|
|
95
|
+
assetId: string | number | null;
|
|
96
96
|
liquidationBonus: string;
|
|
97
97
|
supplyIncentives?: IncentiveData[];
|
|
98
98
|
borrowIncentives?: IncentiveData[];
|
package/esm/aaveV3/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const aaveV3CalculateDiscountRate: (debtBalance: string, discount
|
|
|
6
6
|
export declare const aaveV3EmodeCategoriesMapping: (extractedState: any, usedAssets: AaveV3UsedAssets) => {
|
|
7
7
|
[key: number]: EModeCategoryDataMapping;
|
|
8
8
|
};
|
|
9
|
-
export declare function getAaveV3MarketData(web3: Web3, network: NetworkNumber, market: AaveMarketInfo, defaultWeb3: Web3
|
|
9
|
+
export declare function getAaveV3MarketData(web3: Web3, network: NetworkNumber, market: AaveMarketInfo, defaultWeb3: Web3): Promise<AaveV3MarketData>;
|
|
10
10
|
export declare const EMPTY_AAVE_DATA: {
|
|
11
11
|
usedAssets: {};
|
|
12
12
|
suppliedUsd: string;
|
|
@@ -29,5 +29,5 @@ export declare const EMPTY_AAVE_DATA: {
|
|
|
29
29
|
suppliedCollateralUsd: string;
|
|
30
30
|
};
|
|
31
31
|
export declare const getAaveV3AccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
32
|
-
export declare const getAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: EthAddress, extractedState: any
|
|
32
|
+
export declare const getAaveV3AccountData: (web3: Web3, network: NetworkNumber, address: EthAddress, extractedState: any) => Promise<AaveV3PositionData>;
|
|
33
33
|
export declare const getAaveV3FullPositionData: (web3: Web3, network: NetworkNumber, address: string, market: AaveMarketInfo, mainnetWeb3: Web3) => Promise<AaveV3PositionData>;
|