@defisaver/positions-sdk 1.0.11-fluid-dev10 → 1.0.11-fluid-dev12
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/fluid/index.js +60 -20
- package/cjs/helpers/fluidHelpers/index.js +21 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/types/fluid.d.ts +4 -0
- package/esm/fluid/index.js +60 -20
- package/esm/helpers/fluidHelpers/index.js +21 -2
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/types/fluid.d.ts +4 -0
- package/package.json +54 -54
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +624 -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 +1155 -1155
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +135 -135
- 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 +1289 -1241
- 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 -294
- 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 +295 -295
- 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 +46 -46
- 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 +2454 -2454
- package/src/markets/index.ts +27 -27
- package/src/markets/liquityV2/index.ts +54 -54
- 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 +130 -130
- 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 +217 -217
- 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 -325
- package/src/types/index.ts +11 -11
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +119 -119
- 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/fluid/index.js
CHANGED
|
@@ -120,6 +120,30 @@ const getTokenPriceFromChainlink = (asset, network, web3) => __awaiter(void 0, v
|
|
|
120
120
|
}
|
|
121
121
|
return new decimal_js_1.default(loanTokenPrice).div(1e8).toString();
|
|
122
122
|
});
|
|
123
|
+
const getMarketRateForDex = (token1PerShare, token0PerShare, rate0, rate1, price0, price1) => {
|
|
124
|
+
const token0PerShareUsd = new decimal_js_1.default(token0PerShare).mul(price0).toString();
|
|
125
|
+
const token1PerShareUsd = new decimal_js_1.default(token1PerShare).mul(price1).toString();
|
|
126
|
+
const sharesCombinedUsd = new decimal_js_1.default(token0PerShareUsd).plus(token1PerShareUsd);
|
|
127
|
+
const rate0PerShare = new decimal_js_1.default(rate0).mul(token0PerShareUsd).div(sharesCombinedUsd).toString();
|
|
128
|
+
const rate1PerShare = new decimal_js_1.default(rate1).mul(token1PerShareUsd).div(sharesCombinedUsd).toString();
|
|
129
|
+
return new decimal_js_1.default(rate0PerShare).plus(rate1PerShare).toString();
|
|
130
|
+
};
|
|
131
|
+
const getAdditionalMarketRateForDex = (token1PerShare, token0PerShare, incentiveSupplyRate0, incentiveSupplyRate1, price0, price1) => {
|
|
132
|
+
const token0PerShareUsd = new decimal_js_1.default(token0PerShare).mul(price0).toString();
|
|
133
|
+
const token1PerShareUsd = new decimal_js_1.default(token1PerShare).mul(price1).toString();
|
|
134
|
+
const sharesCombinedUsd = new decimal_js_1.default(token0PerShareUsd).plus(token1PerShareUsd);
|
|
135
|
+
const rate0PerShare = incentiveSupplyRate0 ? new decimal_js_1.default(incentiveSupplyRate0).mul(token0PerShareUsd).div(sharesCombinedUsd).toString() : 0;
|
|
136
|
+
const rate1PerShare = incentiveSupplyRate1 ? new decimal_js_1.default(incentiveSupplyRate1).mul(token1PerShareUsd).div(sharesCombinedUsd).toString() : 0;
|
|
137
|
+
return new decimal_js_1.default(rate0PerShare).plus(rate1PerShare).toString();
|
|
138
|
+
};
|
|
139
|
+
const getTradingApy = (poolAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const res = yield fetch(`https://api.fluid.instadapp.io/v2/1/dexes/${poolAddress}/apy`);
|
|
141
|
+
if (!res.ok) {
|
|
142
|
+
return '0';
|
|
143
|
+
}
|
|
144
|
+
const data = yield res.json();
|
|
145
|
+
return new decimal_js_1.default(data.tradingApy).div(100).toString();
|
|
146
|
+
});
|
|
123
147
|
const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
148
|
const collAsset = (0, tokens_1.getAssetInfoByAddress)(data.supplyToken0, network);
|
|
125
149
|
const debtAsset = (0, tokens_1.getAssetInfoByAddress)(data.borrowToken0, network);
|
|
@@ -144,6 +168,7 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
144
168
|
collAssetData.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collAsset.symbol, mainnetWeb3);
|
|
145
169
|
collAssetData.incentiveSupplyToken = collAsset.symbol;
|
|
146
170
|
}
|
|
171
|
+
const incentiveSupplyRate = collAssetData.incentiveSupplyApy;
|
|
147
172
|
const debtAssetData = {
|
|
148
173
|
symbol: debtAsset.symbol,
|
|
149
174
|
address: debtAsset.address,
|
|
@@ -159,10 +184,7 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
159
184
|
debtAssetData.incentiveBorrowApy = yield (0, staking_1.getStakingApy)(debtAsset.symbol, mainnetWeb3);
|
|
160
185
|
debtAssetData.incentiveBorrowToken = debtAsset.symbol;
|
|
161
186
|
}
|
|
162
|
-
|
|
163
|
-
debtAssetData.incentiveBorrowApy = yield (0, staking_1.getStakingApy)(debtAsset.symbol, mainnetWeb3);
|
|
164
|
-
debtAssetData.incentiveBorrowToken = debtAsset.symbol;
|
|
165
|
-
}
|
|
187
|
+
const incentiveBorrowRate = debtAssetData.incentiveBorrowApy;
|
|
166
188
|
const assetsData = {
|
|
167
189
|
[collAsset.symbol]: collAssetData,
|
|
168
190
|
[debtAsset.symbol]: debtAssetData,
|
|
@@ -206,6 +228,8 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
206
228
|
liquidationMaxLimit,
|
|
207
229
|
borrowRate,
|
|
208
230
|
supplyRate,
|
|
231
|
+
incentiveSupplyRate,
|
|
232
|
+
incentiveBorrowRate,
|
|
209
233
|
oraclePrice,
|
|
210
234
|
};
|
|
211
235
|
return {
|
|
@@ -213,12 +237,6 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
213
237
|
marketData,
|
|
214
238
|
};
|
|
215
239
|
});
|
|
216
|
-
const getMarketRateForDex = (token1PerShare, token0PerShare, rate0, rate1) => {
|
|
217
|
-
const sharesCombined = new decimal_js_1.default(token1PerShare).plus(token0PerShare);
|
|
218
|
-
const rate0PerShare = new decimal_js_1.default(rate0).mul(token0PerShare).div(sharesCombined).toString();
|
|
219
|
-
const rate1PerShare = new decimal_js_1.default(rate1).mul(token1PerShare).div(sharesCombined).toString();
|
|
220
|
-
return new decimal_js_1.default(rate0PerShare).plus(rate1PerShare).toString();
|
|
221
|
-
};
|
|
222
240
|
const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
241
|
const collAsset0 = (0, tokens_1.getAssetInfoByAddress)(data.supplyToken0, network);
|
|
224
242
|
const collAsset1 = (0, tokens_1.getAssetInfoByAddress)(data.supplyToken1, network);
|
|
@@ -257,11 +275,13 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
257
275
|
tokenPerSupplyShare: token1PerSupplyShare,
|
|
258
276
|
supplyReserves: reservesSupplyToken1,
|
|
259
277
|
};
|
|
260
|
-
if (staking_1.STAKING_ASSETS.includes(
|
|
261
|
-
|
|
262
|
-
|
|
278
|
+
if (staking_1.STAKING_ASSETS.includes(collSecondAssetData.symbol)) {
|
|
279
|
+
collSecondAssetData.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collAsset1.symbol, mainnetWeb3);
|
|
280
|
+
collSecondAssetData.incentiveSupplyToken = collAsset1.symbol;
|
|
263
281
|
}
|
|
264
|
-
const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1);
|
|
282
|
+
const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1, collFirstAssetData.price, collSecondAssetData.price);
|
|
283
|
+
const incentiveSupplyRate = getAdditionalMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, collFirstAssetData.incentiveSupplyApy, collSecondAssetData.incentiveSupplyApy, collFirstAssetData.price, collSecondAssetData.price);
|
|
284
|
+
const tradingSupplyRate = yield getTradingApy(data.dexSupplyData.dexPool);
|
|
265
285
|
const borrowRate = new decimal_js_1.default(data.borrowRateVault).div(100).toString();
|
|
266
286
|
const debtAssetData = {
|
|
267
287
|
symbol: debtAsset.symbol,
|
|
@@ -275,6 +295,7 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
275
295
|
debtAssetData.incentiveBorrowApy = yield (0, staking_1.getStakingApy)(debtAsset.symbol, mainnetWeb3);
|
|
276
296
|
debtAssetData.incentiveBorrowToken = debtAsset.symbol;
|
|
277
297
|
}
|
|
298
|
+
const incentiveBorrowRate = debtAssetData.incentiveBorrowApy;
|
|
278
299
|
const assetsData = [
|
|
279
300
|
[collAsset0.symbol, collFirstAssetData],
|
|
280
301
|
[collAsset1.symbol, collSecondAssetData],
|
|
@@ -323,17 +344,21 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
323
344
|
liquidationMaxLimit,
|
|
324
345
|
borrowRate,
|
|
325
346
|
supplyRate: marketSupplyRate,
|
|
347
|
+
incentiveSupplyRate,
|
|
348
|
+
incentiveBorrowRate,
|
|
326
349
|
totalSupplyToken0,
|
|
327
350
|
totalSupplyToken1,
|
|
328
351
|
withdrawableToken0,
|
|
329
352
|
withdrawableToken1,
|
|
330
353
|
withdrawableUSD,
|
|
331
354
|
withdrawable: withdrawableShares,
|
|
332
|
-
|
|
355
|
+
withdrawableDex: new decimal_js_1.default(maxSupplyShares).minus(totalSupplyShares).toString(),
|
|
333
356
|
maxSupplyShares,
|
|
334
357
|
maxSupplySharesUsd,
|
|
335
358
|
collDexFee: supplyDexFee,
|
|
336
359
|
oraclePrice,
|
|
360
|
+
tradingSupplyRate,
|
|
361
|
+
tradingBorrowRate: '0',
|
|
337
362
|
};
|
|
338
363
|
return {
|
|
339
364
|
assetsData,
|
|
@@ -363,6 +388,7 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
363
388
|
collAssetData.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collAsset.symbol, mainnetWeb3);
|
|
364
389
|
collAssetData.incentiveSupplyToken = collAsset.symbol;
|
|
365
390
|
}
|
|
391
|
+
const incentiveSupplyRate = collAssetData.incentiveSupplyApy;
|
|
366
392
|
const debtAsset0Data = {
|
|
367
393
|
symbol: debtAsset0.symbol,
|
|
368
394
|
address: debtAsset0.address,
|
|
@@ -395,7 +421,9 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
395
421
|
debtAsset1Data.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(debtAsset1.symbol, mainnetWeb3);
|
|
396
422
|
debtAsset1Data.incentiveSupplyToken = debtAsset1.symbol;
|
|
397
423
|
}
|
|
398
|
-
const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1);
|
|
424
|
+
const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1, debtAsset0Data.price, debtAsset1Data.price);
|
|
425
|
+
const incentiveBorrowRate = getAdditionalMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, debtAsset0Data.incentiveSupplyApy, debtAsset1Data.incentiveSupplyApy, debtAsset0Data.price, debtAsset1Data.price);
|
|
426
|
+
const tradingBorrowRate = yield getTradingApy(data.dexBorrowData.dexPool);
|
|
399
427
|
const assetsData = [
|
|
400
428
|
[collAsset.symbol, collAssetData],
|
|
401
429
|
[debtAsset0.symbol, debtAsset0Data],
|
|
@@ -439,6 +467,10 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
439
467
|
liquidationMaxLimit,
|
|
440
468
|
borrowRate: marketBorrowRate,
|
|
441
469
|
supplyRate,
|
|
470
|
+
incentiveBorrowRate,
|
|
471
|
+
incentiveSupplyRate,
|
|
472
|
+
tradingBorrowRate,
|
|
473
|
+
tradingSupplyRate: '0',
|
|
442
474
|
borrowableToken0,
|
|
443
475
|
borrowableToken1,
|
|
444
476
|
totalBorrowToken0,
|
|
@@ -534,8 +566,13 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
534
566
|
debtAsset1Data.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(debtAsset1.symbol, mainnetWeb3);
|
|
535
567
|
debtAsset1Data.incentiveSupplyToken = debtAsset1.symbol;
|
|
536
568
|
}
|
|
537
|
-
const
|
|
538
|
-
const
|
|
569
|
+
const marketInfo = (0, markets_1.getFluidMarketInfoById)(+data.vaultId, network);
|
|
570
|
+
const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1, debtAsset0Data.price, debtAsset1Data.price);
|
|
571
|
+
const incentiveBorrowRate = getAdditionalMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, debtAsset0Data.incentiveSupplyApy, debtAsset1Data.incentiveSupplyApy, debtAsset0Data.price, debtAsset1Data.price);
|
|
572
|
+
const tradingBorrowRate = yield getTradingApy(data.dexBorrowData.dexPool);
|
|
573
|
+
const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1, collAsset0Data.price, collAsset1Data.price);
|
|
574
|
+
const incentiveSupplyRate = getAdditionalMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, collAsset0Data.incentiveSupplyApy, collAsset1Data.incentiveSupplyApy, collAsset0Data.price, collAsset1Data.price);
|
|
575
|
+
const tradingSupplyRate = yield getTradingApy(data.dexSupplyData.dexPool);
|
|
539
576
|
const assetsData = [
|
|
540
577
|
[collAsset0.symbol, collAsset0Data],
|
|
541
578
|
[collAsset1.symbol, collAsset1Data],
|
|
@@ -543,7 +580,6 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
543
580
|
[debtAsset1.symbol, debtAsset1Data],
|
|
544
581
|
]
|
|
545
582
|
.reduce((acc, [symbol, partialData]) => (Object.assign(Object.assign({}, acc), { [symbol]: (0, fluidHelpers_1.mergeAssetData)(acc[symbol], partialData) })), {});
|
|
546
|
-
const marketInfo = (0, markets_1.getFluidMarketInfoById)(+data.vaultId, network);
|
|
547
583
|
const liqRatio = new decimal_js_1.default(data.liquidationThreshold).div(100).toString();
|
|
548
584
|
const liquidationMaxLimit = new decimal_js_1.default(data.liquidationMaxLimit).div(100).toString();
|
|
549
585
|
const liqFactor = new decimal_js_1.default(data.liquidationThreshold).div(10000).toString();
|
|
@@ -581,7 +617,9 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
581
617
|
totalBorrowVaultUsd,
|
|
582
618
|
liquidationMaxLimit,
|
|
583
619
|
borrowRate: marketBorrowRate,
|
|
620
|
+
incentiveBorrowRate,
|
|
584
621
|
supplyRate: marketSupplyRate,
|
|
622
|
+
incentiveSupplyRate,
|
|
585
623
|
borrowableToken0,
|
|
586
624
|
borrowableToken1,
|
|
587
625
|
totalBorrowToken0,
|
|
@@ -598,13 +636,15 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
598
636
|
withdrawableToken1,
|
|
599
637
|
withdrawableUSD,
|
|
600
638
|
withdrawable: withdrawableShares,
|
|
601
|
-
|
|
639
|
+
withdrawableDex: new decimal_js_1.default(maxSupplyShares).minus(totalSupplyShares).toString(),
|
|
602
640
|
maxSupplyShares,
|
|
603
641
|
maxSupplySharesUsd,
|
|
604
642
|
collDexFee: supplyDexFee,
|
|
605
643
|
collSharePrice,
|
|
606
644
|
debtSharePrice,
|
|
607
645
|
oraclePrice,
|
|
646
|
+
tradingBorrowRate,
|
|
647
|
+
tradingSupplyRate,
|
|
608
648
|
};
|
|
609
649
|
return {
|
|
610
650
|
assetsData,
|
|
@@ -10,6 +10,24 @@ const types_1 = require("../../types");
|
|
|
10
10
|
const moneymarket_1 = require("../../moneymarket");
|
|
11
11
|
const staking_1 = require("../../staking");
|
|
12
12
|
const utils_1 = require("../../services/utils");
|
|
13
|
+
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }) => {
|
|
14
|
+
const { borrowRate, supplyRate, incentiveBorrowRate, incentiveSupplyRate, tradingBorrowRate, tradingSupplyRate, } = marketData;
|
|
15
|
+
const totalBorrowRate = new decimal_js_1.default(borrowRate).minus(tradingBorrowRate || '0').toString();
|
|
16
|
+
const totalSupplyRate = new decimal_js_1.default(supplyRate).add(tradingSupplyRate || '0').toString();
|
|
17
|
+
const borrowIncentive = new decimal_js_1.default(incentiveBorrowRate || '0').mul(borrowedUsd).div(100).toString();
|
|
18
|
+
const supplyIncentive = new decimal_js_1.default(incentiveSupplyRate || '0').mul(suppliedUsd).div(100).toString();
|
|
19
|
+
const incentiveUsd = new decimal_js_1.default(supplyIncentive).minus(borrowIncentive).toString();
|
|
20
|
+
const borrowInterest = new decimal_js_1.default(totalBorrowRate).mul(borrowedUsd).div(100).toString();
|
|
21
|
+
const supplyInterest = new decimal_js_1.default(totalSupplyRate).mul(suppliedUsd).div(100).toString();
|
|
22
|
+
const totalInterestUsd = new decimal_js_1.default(supplyInterest).add(incentiveUsd).minus(borrowInterest).toString();
|
|
23
|
+
const balance = new decimal_js_1.default(suppliedUsd).sub(borrowedUsd).toString();
|
|
24
|
+
const netApy = new decimal_js_1.default(totalInterestUsd).div(balance).times(100).toString();
|
|
25
|
+
return {
|
|
26
|
+
netApy,
|
|
27
|
+
incentiveUsd,
|
|
28
|
+
totalInterestUsd,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
13
31
|
const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, }, supplyShares, borrowShares) => {
|
|
14
32
|
const payload = {};
|
|
15
33
|
payload.suppliedUsd = [types_1.FluidVaultType.T1, types_1.FluidVaultType.T3].includes(marketData.vaultType)
|
|
@@ -18,7 +36,8 @@ const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, }, supplyS
|
|
|
18
36
|
payload.borrowedUsd = [types_1.FluidVaultType.T1, types_1.FluidVaultType.T2].includes(marketData.vaultType)
|
|
19
37
|
? (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd)
|
|
20
38
|
: new decimal_js_1.default(marketData.debtSharePrice).mul(borrowShares).toString();
|
|
21
|
-
const
|
|
39
|
+
const isDex = [types_1.FluidVaultType.T2, types_1.FluidVaultType.T3, types_1.FluidVaultType.T4].includes(marketData.vaultType);
|
|
40
|
+
const { netApy, incentiveUsd, totalInterestUsd } = isDex ? calculateNetApyDex({ marketData, suppliedUsd: payload.suppliedUsd, borrowedUsd: payload.borrowedUsd }) : (0, staking_1.calculateNetApy)({ usedAssets, assetsData: assetsData });
|
|
22
41
|
payload.netApy = netApy;
|
|
23
42
|
payload.incentiveUsd = incentiveUsd;
|
|
24
43
|
payload.totalInterestUsd = totalInterestUsd;
|
|
@@ -51,7 +70,7 @@ exports.getFluidAggregatedData = getFluidAggregatedData;
|
|
|
51
70
|
const parseDexSupplyData = (dexSupplyData, collAsset0, collAsset1) => {
|
|
52
71
|
const { dexPool, // address of the dex pool
|
|
53
72
|
dexId, // id of the dex pool
|
|
54
|
-
fee: _fee, // fee of the dex pool
|
|
73
|
+
fee: _fee, // fee of the dex pool (Only used as swap fees)
|
|
55
74
|
lastStoredPrice, // last stored price of the dex pool
|
|
56
75
|
centerPrice, // center price of the dex pool
|
|
57
76
|
token0Utilization, // token0 utilization
|
|
@@ -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/types/fluid.d.ts
CHANGED
|
@@ -241,6 +241,8 @@ export interface InnerFluidMarketData {
|
|
|
241
241
|
borrowRate: string;
|
|
242
242
|
liquidationMaxLimit: string;
|
|
243
243
|
oraclePrice: string;
|
|
244
|
+
incentiveBorrowRate?: string;
|
|
245
|
+
incentiveSupplyRate?: string;
|
|
244
246
|
collSharePrice?: string;
|
|
245
247
|
maxSupplyShares?: string;
|
|
246
248
|
maxSupplySharesUsd?: string;
|
|
@@ -259,6 +261,8 @@ export interface InnerFluidMarketData {
|
|
|
259
261
|
totalBorrowToken0?: string;
|
|
260
262
|
totalBorrowToken1?: string;
|
|
261
263
|
borrowDexFee?: string;
|
|
264
|
+
tradingBorrowRate?: string;
|
|
265
|
+
tradingSupplyRate?: string;
|
|
262
266
|
}
|
|
263
267
|
export interface FluidMarketData {
|
|
264
268
|
assetsData: FluidAssetsData;
|