@defisaver/positions-sdk 1.0.11-fluid-dev11 → 1.0.11-fluid-dev13
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/config/contracts.d.ts +113 -53
- package/cjs/config/contracts.js +10 -0
- package/cjs/contracts.d.ts +1 -0
- package/cjs/contracts.js +2 -1
- package/cjs/fluid/index.js +80 -28
- package/cjs/helpers/fluidHelpers/index.js +21 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/markets/fluid/index.d.ts +0 -2
- package/cjs/markets/fluid/index.js +26 -24
- package/cjs/services/priceService.d.ts +2 -0
- package/cjs/services/priceService.js +13 -1
- package/cjs/types/contracts/generated/BTCPriceFeed.d.ts +135 -0
- package/cjs/types/contracts/generated/BTCPriceFeed.js +5 -0
- package/cjs/types/contracts/generated/index.d.ts +1 -0
- package/cjs/types/fluid.d.ts +4 -0
- package/esm/config/contracts.d.ts +113 -53
- package/esm/config/contracts.js +10 -0
- package/esm/contracts.d.ts +1 -0
- package/esm/contracts.js +1 -0
- package/esm/fluid/index.js +81 -29
- package/esm/helpers/fluidHelpers/index.js +21 -2
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/markets/fluid/index.d.ts +0 -2
- package/esm/markets/fluid/index.js +24 -21
- package/esm/services/priceService.d.ts +2 -0
- package/esm/services/priceService.js +11 -1
- package/esm/types/contracts/generated/BTCPriceFeed.d.ts +135 -0
- package/esm/types/contracts/generated/BTCPriceFeed.js +4 -0
- package/esm/types/contracts/generated/index.d.ts +1 -0
- 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 +1165 -1155
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +136 -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 +1320 -1261
- 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 +2456 -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 +143 -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/contracts/generated/BTCPriceFeed.ts +202 -0
- package/src/types/contracts/generated/index.ts +1 -0
- 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/esm/fluid/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { getFluidAggregatedData, mergeAssetData, mergeUsedAssets, parseDexBorrow
|
|
|
17
17
|
import { chunkAndMulticall } from '../multicall';
|
|
18
18
|
import { getFluidMarketInfoById, getFluidVersionsDataForNetwork, getFTokenAddress } from '../markets';
|
|
19
19
|
import { USD_QUOTE } from '../constants';
|
|
20
|
-
import { getChainlinkAssetAddress, getWeETHChainLinkPriceCalls, getWstETHChainLinkPriceCalls, getWstETHPriceFluid, parseWeETHPriceCalls, parseWstETHPriceCalls, } from '../services/priceService';
|
|
20
|
+
import { getChainlinkAssetAddress, getWeETHChainLinkPriceCalls, getWstETHChainLinkPriceCalls, getWstETHPriceFluid, parseWeETHPriceCalls, parseWstETHPriceCalls, getEthPriceForFluid, getBTCPriceForFluid, } from '../services/priceService';
|
|
21
21
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
22
22
|
export const EMPTY_USED_ASSET = {
|
|
23
23
|
isSupplied: false,
|
|
@@ -41,6 +41,9 @@ const parseVaultType = (vaultType) => {
|
|
|
41
41
|
const getChainLinkPricesForTokens = (tokens, network, web3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
42
|
const isMainnet = isMainnetNetwork(network);
|
|
43
43
|
const noDuplicateTokens = new Array(...new Set(tokens));
|
|
44
|
+
// TODO: this needs to be refactored
|
|
45
|
+
const ethPriceChainlink = yield getEthPriceForFluid(web3, network);
|
|
46
|
+
const btcPriceChainlink = yield getBTCPriceForFluid(web3, network);
|
|
44
47
|
const calls = noDuplicateTokens.flatMap((address) => {
|
|
45
48
|
const assetInfo = getAssetInfoByAddress(address, network);
|
|
46
49
|
const isTokenUSDA = assetInfo.symbol === 'USDA';
|
|
@@ -80,6 +83,27 @@ const getChainLinkPricesForTokens = (tokens, network, web3) => __awaiter(void 0,
|
|
|
80
83
|
acc[token] = new Dec(ethPrice).mul(wstETHRate).toString();
|
|
81
84
|
break;
|
|
82
85
|
}
|
|
86
|
+
// TODO: These addresses do not have chainlink feeds, so we need to handle them separately, this is hotfix
|
|
87
|
+
case 'ezETH': {
|
|
88
|
+
acc[token] = new Dec(ethPriceChainlink).mul(1.049).toString();
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'rsETH': {
|
|
92
|
+
acc[token] = new Dec(ethPriceChainlink).mul(1.0454).toString();
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'weETHs': {
|
|
96
|
+
acc[token] = new Dec(ethPriceChainlink).mul(1.026).toString();
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 'LBTC': {
|
|
100
|
+
acc[token] = new Dec(btcPriceChainlink).toString();
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case 'sUSDS': {
|
|
104
|
+
acc[token] = new Dec('105276929').toString();
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
83
107
|
case 'weETH': {
|
|
84
108
|
const { ethPrice, weETHRate, } = parseWeETHPriceCalls(prices[i + offset][0], prices[i + offset + 1], prices[i + offset + 2][0]);
|
|
85
109
|
offset += 2;
|
|
@@ -94,6 +118,9 @@ const getChainLinkPricesForTokens = (tokens, network, web3) => __awaiter(void 0,
|
|
|
94
118
|
}, {});
|
|
95
119
|
});
|
|
96
120
|
const getTokenPriceFromChainlink = (asset, network, web3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
if (asset.symbol === 'sUSDS') {
|
|
122
|
+
return new Dec('105276929').div(1e8).toString();
|
|
123
|
+
}
|
|
97
124
|
const isTokenUSDA = asset.symbol === 'USDA';
|
|
98
125
|
const isMainnet = isMainnetNetwork(network);
|
|
99
126
|
const loanTokenFeedAddress = getChainlinkAssetAddress(asset.symbol, network);
|
|
@@ -114,6 +141,30 @@ const getTokenPriceFromChainlink = (asset, network, web3) => __awaiter(void 0, v
|
|
|
114
141
|
}
|
|
115
142
|
return new Dec(loanTokenPrice).div(1e8).toString();
|
|
116
143
|
});
|
|
144
|
+
const getMarketRateForDex = (token1PerShare, token0PerShare, rate0, rate1, price0, price1) => {
|
|
145
|
+
const token0PerShareUsd = new Dec(token0PerShare).mul(price0).toString();
|
|
146
|
+
const token1PerShareUsd = new Dec(token1PerShare).mul(price1).toString();
|
|
147
|
+
const sharesCombinedUsd = new Dec(token0PerShareUsd).plus(token1PerShareUsd);
|
|
148
|
+
const rate0PerShare = new Dec(rate0).mul(token0PerShareUsd).div(sharesCombinedUsd).toString();
|
|
149
|
+
const rate1PerShare = new Dec(rate1).mul(token1PerShareUsd).div(sharesCombinedUsd).toString();
|
|
150
|
+
return new Dec(rate0PerShare).plus(rate1PerShare).toString();
|
|
151
|
+
};
|
|
152
|
+
const getAdditionalMarketRateForDex = (token1PerShare, token0PerShare, incentiveSupplyRate0, incentiveSupplyRate1, price0, price1) => {
|
|
153
|
+
const token0PerShareUsd = new Dec(token0PerShare).mul(price0).toString();
|
|
154
|
+
const token1PerShareUsd = new Dec(token1PerShare).mul(price1).toString();
|
|
155
|
+
const sharesCombinedUsd = new Dec(token0PerShareUsd).plus(token1PerShareUsd);
|
|
156
|
+
const rate0PerShare = incentiveSupplyRate0 ? new Dec(incentiveSupplyRate0).mul(token0PerShareUsd).div(sharesCombinedUsd).toString() : 0;
|
|
157
|
+
const rate1PerShare = incentiveSupplyRate1 ? new Dec(incentiveSupplyRate1).mul(token1PerShareUsd).div(sharesCombinedUsd).toString() : 0;
|
|
158
|
+
return new Dec(rate0PerShare).plus(rate1PerShare).toString();
|
|
159
|
+
};
|
|
160
|
+
const getTradingApy = (poolAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
const res = yield fetch(`https://api.fluid.instadapp.io/v2/1/dexes/${poolAddress}/apy`);
|
|
162
|
+
if (!res.ok) {
|
|
163
|
+
return '0';
|
|
164
|
+
}
|
|
165
|
+
const data = yield res.json();
|
|
166
|
+
return new Dec(data.tradingApy).div(100).toString();
|
|
167
|
+
});
|
|
117
168
|
const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
169
|
const collAsset = getAssetInfoByAddress(data.supplyToken0, network);
|
|
119
170
|
const debtAsset = getAssetInfoByAddress(data.borrowToken0, network);
|
|
@@ -138,6 +189,7 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
138
189
|
collAssetData.incentiveSupplyApy = yield getStakingApy(collAsset.symbol, mainnetWeb3);
|
|
139
190
|
collAssetData.incentiveSupplyToken = collAsset.symbol;
|
|
140
191
|
}
|
|
192
|
+
const incentiveSupplyRate = collAssetData.incentiveSupplyApy;
|
|
141
193
|
const debtAssetData = {
|
|
142
194
|
symbol: debtAsset.symbol,
|
|
143
195
|
address: debtAsset.address,
|
|
@@ -153,10 +205,7 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
153
205
|
debtAssetData.incentiveBorrowApy = yield getStakingApy(debtAsset.symbol, mainnetWeb3);
|
|
154
206
|
debtAssetData.incentiveBorrowToken = debtAsset.symbol;
|
|
155
207
|
}
|
|
156
|
-
|
|
157
|
-
debtAssetData.incentiveBorrowApy = yield getStakingApy(debtAsset.symbol, mainnetWeb3);
|
|
158
|
-
debtAssetData.incentiveBorrowToken = debtAsset.symbol;
|
|
159
|
-
}
|
|
208
|
+
const incentiveBorrowRate = debtAssetData.incentiveBorrowApy;
|
|
160
209
|
const assetsData = {
|
|
161
210
|
[collAsset.symbol]: collAssetData,
|
|
162
211
|
[debtAsset.symbol]: debtAssetData,
|
|
@@ -200,6 +249,8 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
200
249
|
liquidationMaxLimit,
|
|
201
250
|
borrowRate,
|
|
202
251
|
supplyRate,
|
|
252
|
+
incentiveSupplyRate,
|
|
253
|
+
incentiveBorrowRate,
|
|
203
254
|
oraclePrice,
|
|
204
255
|
};
|
|
205
256
|
return {
|
|
@@ -207,19 +258,6 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
207
258
|
marketData,
|
|
208
259
|
};
|
|
209
260
|
});
|
|
210
|
-
const getMarketRateForDex = (token1PerShare, token0PerShare, rate0, rate1) => {
|
|
211
|
-
const sharesCombined = new Dec(token1PerShare).plus(token0PerShare);
|
|
212
|
-
const rate0PerShare = new Dec(rate0).mul(token0PerShare).div(sharesCombined).toString();
|
|
213
|
-
const rate1PerShare = new Dec(rate1).mul(token1PerShare).div(sharesCombined).toString();
|
|
214
|
-
return new Dec(rate0PerShare).plus(rate1PerShare).toString();
|
|
215
|
-
};
|
|
216
|
-
const getAdditionalMarketRateForDex = (token1PerShare, token0PerShare, incentiveSupplyRate0, incentiveSupplyRate1) => {
|
|
217
|
-
console.log(incentiveSupplyRate0, incentiveSupplyRate1);
|
|
218
|
-
const sharesCombined = new Dec(token1PerShare).plus(token0PerShare);
|
|
219
|
-
const rate0PerShare = incentiveSupplyRate0 ? new Dec(incentiveSupplyRate0).mul(token0PerShare).div(sharesCombined).toString() : 0;
|
|
220
|
-
const rate1PerShare = incentiveSupplyRate1 ? new Dec(incentiveSupplyRate1).mul(token1PerShare).div(sharesCombined).toString() : 0;
|
|
221
|
-
return new Dec(rate0PerShare).plus(rate1PerShare).toString();
|
|
222
|
-
};
|
|
223
261
|
const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
262
|
const collAsset0 = getAssetInfoByAddress(data.supplyToken0, network);
|
|
225
263
|
const collAsset1 = getAssetInfoByAddress(data.supplyToken1, network);
|
|
@@ -262,8 +300,9 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
262
300
|
collSecondAssetData.incentiveSupplyApy = yield getStakingApy(collAsset1.symbol, mainnetWeb3);
|
|
263
301
|
collSecondAssetData.incentiveSupplyToken = collAsset1.symbol;
|
|
264
302
|
}
|
|
265
|
-
const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1);
|
|
266
|
-
const incentiveSupplyRate = getAdditionalMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, collFirstAssetData.incentiveSupplyApy, collSecondAssetData.incentiveSupplyApy);
|
|
303
|
+
const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1, collFirstAssetData.price, collSecondAssetData.price);
|
|
304
|
+
const incentiveSupplyRate = getAdditionalMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, collFirstAssetData.incentiveSupplyApy, collSecondAssetData.incentiveSupplyApy, collFirstAssetData.price, collSecondAssetData.price);
|
|
305
|
+
const tradingSupplyRate = yield getTradingApy(data.dexSupplyData.dexPool);
|
|
267
306
|
const borrowRate = new Dec(data.borrowRateVault).div(100).toString();
|
|
268
307
|
const debtAssetData = {
|
|
269
308
|
symbol: debtAsset.symbol,
|
|
@@ -277,6 +316,7 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
277
316
|
debtAssetData.incentiveBorrowApy = yield getStakingApy(debtAsset.symbol, mainnetWeb3);
|
|
278
317
|
debtAssetData.incentiveBorrowToken = debtAsset.symbol;
|
|
279
318
|
}
|
|
319
|
+
const incentiveBorrowRate = debtAssetData.incentiveBorrowApy;
|
|
280
320
|
const assetsData = [
|
|
281
321
|
[collAsset0.symbol, collFirstAssetData],
|
|
282
322
|
[collAsset1.symbol, collSecondAssetData],
|
|
@@ -326,17 +366,20 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
326
366
|
borrowRate,
|
|
327
367
|
supplyRate: marketSupplyRate,
|
|
328
368
|
incentiveSupplyRate,
|
|
369
|
+
incentiveBorrowRate,
|
|
329
370
|
totalSupplyToken0,
|
|
330
371
|
totalSupplyToken1,
|
|
331
372
|
withdrawableToken0,
|
|
332
373
|
withdrawableToken1,
|
|
333
374
|
withdrawableUSD,
|
|
334
375
|
withdrawable: withdrawableShares,
|
|
335
|
-
|
|
376
|
+
withdrawableDex: new Dec(maxSupplyShares).minus(totalSupplyShares).toString(),
|
|
336
377
|
maxSupplyShares,
|
|
337
378
|
maxSupplySharesUsd,
|
|
338
379
|
collDexFee: supplyDexFee,
|
|
339
380
|
oraclePrice,
|
|
381
|
+
tradingSupplyRate,
|
|
382
|
+
tradingBorrowRate: '0',
|
|
340
383
|
};
|
|
341
384
|
return {
|
|
342
385
|
assetsData,
|
|
@@ -366,6 +409,7 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
366
409
|
collAssetData.incentiveSupplyApy = yield getStakingApy(collAsset.symbol, mainnetWeb3);
|
|
367
410
|
collAssetData.incentiveSupplyToken = collAsset.symbol;
|
|
368
411
|
}
|
|
412
|
+
const incentiveSupplyRate = collAssetData.incentiveSupplyApy;
|
|
369
413
|
const debtAsset0Data = {
|
|
370
414
|
symbol: debtAsset0.symbol,
|
|
371
415
|
address: debtAsset0.address,
|
|
@@ -398,8 +442,9 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
398
442
|
debtAsset1Data.incentiveSupplyApy = yield getStakingApy(debtAsset1.symbol, mainnetWeb3);
|
|
399
443
|
debtAsset1Data.incentiveSupplyToken = debtAsset1.symbol;
|
|
400
444
|
}
|
|
401
|
-
const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1);
|
|
402
|
-
const incentiveBorrowRate = getAdditionalMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, debtAsset0Data.incentiveSupplyApy, debtAsset1Data.incentiveSupplyApy);
|
|
445
|
+
const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1, debtAsset0Data.price, debtAsset1Data.price);
|
|
446
|
+
const incentiveBorrowRate = getAdditionalMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, debtAsset0Data.incentiveSupplyApy, debtAsset1Data.incentiveSupplyApy, debtAsset0Data.price, debtAsset1Data.price);
|
|
447
|
+
const tradingBorrowRate = yield getTradingApy(data.dexBorrowData.dexPool);
|
|
403
448
|
const assetsData = [
|
|
404
449
|
[collAsset.symbol, collAssetData],
|
|
405
450
|
[debtAsset0.symbol, debtAsset0Data],
|
|
@@ -444,6 +489,9 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
444
489
|
borrowRate: marketBorrowRate,
|
|
445
490
|
supplyRate,
|
|
446
491
|
incentiveBorrowRate,
|
|
492
|
+
incentiveSupplyRate,
|
|
493
|
+
tradingBorrowRate,
|
|
494
|
+
tradingSupplyRate: '0',
|
|
447
495
|
borrowableToken0,
|
|
448
496
|
borrowableToken1,
|
|
449
497
|
totalBorrowToken0,
|
|
@@ -539,10 +587,13 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
539
587
|
debtAsset1Data.incentiveSupplyApy = yield getStakingApy(debtAsset1.symbol, mainnetWeb3);
|
|
540
588
|
debtAsset1Data.incentiveSupplyToken = debtAsset1.symbol;
|
|
541
589
|
}
|
|
542
|
-
const
|
|
543
|
-
const
|
|
544
|
-
const
|
|
545
|
-
const
|
|
590
|
+
const marketInfo = getFluidMarketInfoById(+data.vaultId, network);
|
|
591
|
+
const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1, debtAsset0Data.price, debtAsset1Data.price);
|
|
592
|
+
const incentiveBorrowRate = getAdditionalMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, debtAsset0Data.incentiveSupplyApy, debtAsset1Data.incentiveSupplyApy, debtAsset0Data.price, debtAsset1Data.price);
|
|
593
|
+
const tradingBorrowRate = yield getTradingApy(data.dexBorrowData.dexPool);
|
|
594
|
+
const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1, collAsset0Data.price, collAsset1Data.price);
|
|
595
|
+
const incentiveSupplyRate = getAdditionalMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, collAsset0Data.incentiveSupplyApy, collAsset1Data.incentiveSupplyApy, collAsset0Data.price, collAsset1Data.price);
|
|
596
|
+
const tradingSupplyRate = yield getTradingApy(data.dexSupplyData.dexPool);
|
|
546
597
|
const assetsData = [
|
|
547
598
|
[collAsset0.symbol, collAsset0Data],
|
|
548
599
|
[collAsset1.symbol, collAsset1Data],
|
|
@@ -550,7 +601,6 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
550
601
|
[debtAsset1.symbol, debtAsset1Data],
|
|
551
602
|
]
|
|
552
603
|
.reduce((acc, [symbol, partialData]) => (Object.assign(Object.assign({}, acc), { [symbol]: mergeAssetData(acc[symbol], partialData) })), {});
|
|
553
|
-
const marketInfo = getFluidMarketInfoById(+data.vaultId, network);
|
|
554
604
|
const liqRatio = new Dec(data.liquidationThreshold).div(100).toString();
|
|
555
605
|
const liquidationMaxLimit = new Dec(data.liquidationMaxLimit).div(100).toString();
|
|
556
606
|
const liqFactor = new Dec(data.liquidationThreshold).div(10000).toString();
|
|
@@ -607,13 +657,15 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
|
|
|
607
657
|
withdrawableToken1,
|
|
608
658
|
withdrawableUSD,
|
|
609
659
|
withdrawable: withdrawableShares,
|
|
610
|
-
|
|
660
|
+
withdrawableDex: new Dec(maxSupplyShares).minus(totalSupplyShares).toString(),
|
|
611
661
|
maxSupplyShares,
|
|
612
662
|
maxSupplySharesUsd,
|
|
613
663
|
collDexFee: supplyDexFee,
|
|
614
664
|
collSharePrice,
|
|
615
665
|
debtSharePrice,
|
|
616
666
|
oraclePrice,
|
|
667
|
+
tradingBorrowRate,
|
|
668
|
+
tradingSupplyRate,
|
|
617
669
|
};
|
|
618
670
|
return {
|
|
619
671
|
assetsData,
|
|
@@ -4,6 +4,24 @@ import { FluidVaultType, } from '../../types';
|
|
|
4
4
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
5
5
|
import { calculateNetApy } from '../../staking';
|
|
6
6
|
import { getEthAmountForDecimals } from '../../services/utils';
|
|
7
|
+
const calculateNetApyDex = ({ marketData, suppliedUsd, borrowedUsd }) => {
|
|
8
|
+
const { borrowRate, supplyRate, incentiveBorrowRate, incentiveSupplyRate, tradingBorrowRate, tradingSupplyRate, } = marketData;
|
|
9
|
+
const totalBorrowRate = new Dec(borrowRate).minus(tradingBorrowRate || '0').toString();
|
|
10
|
+
const totalSupplyRate = new Dec(supplyRate).add(tradingSupplyRate || '0').toString();
|
|
11
|
+
const borrowIncentive = new Dec(incentiveBorrowRate || '0').mul(borrowedUsd).div(100).toString();
|
|
12
|
+
const supplyIncentive = new Dec(incentiveSupplyRate || '0').mul(suppliedUsd).div(100).toString();
|
|
13
|
+
const incentiveUsd = new Dec(supplyIncentive).minus(borrowIncentive).toString();
|
|
14
|
+
const borrowInterest = new Dec(totalBorrowRate).mul(borrowedUsd).div(100).toString();
|
|
15
|
+
const supplyInterest = new Dec(totalSupplyRate).mul(suppliedUsd).div(100).toString();
|
|
16
|
+
const totalInterestUsd = new Dec(supplyInterest).add(incentiveUsd).minus(borrowInterest).toString();
|
|
17
|
+
const balance = new Dec(suppliedUsd).sub(borrowedUsd).toString();
|
|
18
|
+
const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
|
|
19
|
+
return {
|
|
20
|
+
netApy,
|
|
21
|
+
incentiveUsd,
|
|
22
|
+
totalInterestUsd,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
7
25
|
export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, }, supplyShares, borrowShares) => {
|
|
8
26
|
const payload = {};
|
|
9
27
|
payload.suppliedUsd = [FluidVaultType.T1, FluidVaultType.T3].includes(marketData.vaultType)
|
|
@@ -12,7 +30,8 @@ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, },
|
|
|
12
30
|
payload.borrowedUsd = [FluidVaultType.T1, FluidVaultType.T2].includes(marketData.vaultType)
|
|
13
31
|
? getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd)
|
|
14
32
|
: new Dec(marketData.debtSharePrice).mul(borrowShares).toString();
|
|
15
|
-
const
|
|
33
|
+
const isDex = [FluidVaultType.T2, FluidVaultType.T3, FluidVaultType.T4].includes(marketData.vaultType);
|
|
34
|
+
const { netApy, incentiveUsd, totalInterestUsd } = isDex ? calculateNetApyDex({ marketData, suppliedUsd: payload.suppliedUsd, borrowedUsd: payload.borrowedUsd }) : calculateNetApy({ usedAssets, assetsData: assetsData });
|
|
16
35
|
payload.netApy = netApy;
|
|
17
36
|
payload.incentiveUsd = incentiveUsd;
|
|
18
37
|
payload.totalInterestUsd = totalInterestUsd;
|
|
@@ -44,7 +63,7 @@ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, },
|
|
|
44
63
|
export const parseDexSupplyData = (dexSupplyData, collAsset0, collAsset1) => {
|
|
45
64
|
const { dexPool, // address of the dex pool
|
|
46
65
|
dexId, // id of the dex pool
|
|
47
|
-
fee: _fee, // fee of the dex pool
|
|
66
|
+
fee: _fee, // fee of the dex pool (Only used as swap fees)
|
|
48
67
|
lastStoredPrice, // last stored price of the dex pool
|
|
49
68
|
centerPrice, // center price of the dex pool
|
|
50
69
|
token0Utilization, // token0 utilization
|
|
@@ -107,73 +107,73 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, web3, netwo
|
|
|
107
107
|
return { borrowRate, supplyRate };
|
|
108
108
|
});
|
|
109
109
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
110
|
-
const MARKET_QUERY = `
|
|
111
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
112
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
113
|
-
reallocatableLiquidityAssets
|
|
114
|
-
targetBorrowUtilization
|
|
115
|
-
loanAsset {
|
|
116
|
-
address
|
|
117
|
-
decimals
|
|
118
|
-
priceUsd
|
|
119
|
-
}
|
|
120
|
-
state {
|
|
121
|
-
liquidityAssets
|
|
122
|
-
borrowAssets
|
|
123
|
-
supplyAssets
|
|
124
|
-
}
|
|
125
|
-
publicAllocatorSharedLiquidity {
|
|
126
|
-
assets
|
|
127
|
-
vault {
|
|
128
|
-
address
|
|
129
|
-
name
|
|
130
|
-
}
|
|
131
|
-
allocationMarket {
|
|
132
|
-
uniqueKey
|
|
133
|
-
loanAsset {
|
|
134
|
-
address
|
|
135
|
-
}
|
|
136
|
-
collateralAsset {
|
|
137
|
-
address
|
|
138
|
-
}
|
|
139
|
-
irmAddress
|
|
140
|
-
oracle {
|
|
141
|
-
address
|
|
142
|
-
}
|
|
143
|
-
lltv
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
loanAsset {
|
|
147
|
-
address
|
|
148
|
-
}
|
|
149
|
-
collateralAsset {
|
|
150
|
-
address
|
|
151
|
-
}
|
|
152
|
-
oracle {
|
|
153
|
-
address
|
|
154
|
-
}
|
|
155
|
-
irmAddress
|
|
156
|
-
lltv
|
|
157
|
-
}
|
|
158
|
-
}
|
|
110
|
+
const MARKET_QUERY = `
|
|
111
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
112
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
113
|
+
reallocatableLiquidityAssets
|
|
114
|
+
targetBorrowUtilization
|
|
115
|
+
loanAsset {
|
|
116
|
+
address
|
|
117
|
+
decimals
|
|
118
|
+
priceUsd
|
|
119
|
+
}
|
|
120
|
+
state {
|
|
121
|
+
liquidityAssets
|
|
122
|
+
borrowAssets
|
|
123
|
+
supplyAssets
|
|
124
|
+
}
|
|
125
|
+
publicAllocatorSharedLiquidity {
|
|
126
|
+
assets
|
|
127
|
+
vault {
|
|
128
|
+
address
|
|
129
|
+
name
|
|
130
|
+
}
|
|
131
|
+
allocationMarket {
|
|
132
|
+
uniqueKey
|
|
133
|
+
loanAsset {
|
|
134
|
+
address
|
|
135
|
+
}
|
|
136
|
+
collateralAsset {
|
|
137
|
+
address
|
|
138
|
+
}
|
|
139
|
+
irmAddress
|
|
140
|
+
oracle {
|
|
141
|
+
address
|
|
142
|
+
}
|
|
143
|
+
lltv
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
loanAsset {
|
|
147
|
+
address
|
|
148
|
+
}
|
|
149
|
+
collateralAsset {
|
|
150
|
+
address
|
|
151
|
+
}
|
|
152
|
+
oracle {
|
|
153
|
+
address
|
|
154
|
+
}
|
|
155
|
+
irmAddress
|
|
156
|
+
lltv
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
159
|
`;
|
|
160
|
-
const REWARDS_QUERY = `
|
|
161
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
162
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
163
|
-
uniqueKey
|
|
164
|
-
state {
|
|
165
|
-
rewards {
|
|
166
|
-
amountPerSuppliedToken
|
|
167
|
-
supplyApr
|
|
168
|
-
amountPerBorrowedToken
|
|
169
|
-
borrowApr
|
|
170
|
-
asset {
|
|
171
|
-
address
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
160
|
+
const REWARDS_QUERY = `
|
|
161
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
162
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
163
|
+
uniqueKey
|
|
164
|
+
state {
|
|
165
|
+
rewards {
|
|
166
|
+
amountPerSuppliedToken
|
|
167
|
+
supplyApr
|
|
168
|
+
amountPerBorrowedToken
|
|
169
|
+
borrowApr
|
|
170
|
+
asset {
|
|
171
|
+
address
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
177
|
`;
|
|
178
178
|
/**
|
|
179
179
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
|
@@ -95,7 +95,6 @@ export declare const FLUID_ETH_USDC_USDT_23_ARB: (networkId?: NetworkNumber) =>
|
|
|
95
95
|
export declare const FLUID_WSTETH_USDC_USDT_24_ARB: (networkId?: NetworkNumber) => FluidMarketInfo;
|
|
96
96
|
export declare const FLUID_WEETH_USDC_USDT_25_ARB: (networkId?: NetworkNumber) => FluidMarketInfo;
|
|
97
97
|
export declare const FLUID_WBTC_USDC_USDT_26_ARB: (networkId?: NetworkNumber) => FluidMarketInfo;
|
|
98
|
-
export declare const FLUID_SUSDS_USDC_USDT_30_ARB: (networkId?: NetworkNumber) => FluidMarketInfo;
|
|
99
98
|
export declare const FLUID_ETH_USDC_1_BASE: (networkId?: NetworkNumber) => FluidMarketInfo;
|
|
100
99
|
export declare const FLUID_WSTETH_USDC_2_BASE: (networkId?: NetworkNumber) => FluidMarketInfo;
|
|
101
100
|
export declare const FLUID_WSTETH_ETH_3_BASE: (networkId?: NetworkNumber) => FluidMarketInfo;
|
|
@@ -213,7 +212,6 @@ export declare const FluidMarkets: (networkId: NetworkNumber) => {
|
|
|
213
212
|
FLUID_WSTETH_USDC_USDT_24_ARB: FluidMarketInfo;
|
|
214
213
|
FLUID_WEETH_USDC_USDT_25_ARB: FluidMarketInfo;
|
|
215
214
|
FLUID_WBTC_USDC_USDT_26_ARB: FluidMarketInfo;
|
|
216
|
-
FLUID_SUSDS_USDC_USDT_30_ARB: FluidMarketInfo;
|
|
217
215
|
FLUID_ETH_USDC_1_BASE: FluidMarketInfo;
|
|
218
216
|
FLUID_WSTETH_USDC_2_BASE: FluidMarketInfo;
|
|
219
217
|
FLUID_WSTETH_ETH_3_BASE: FluidMarketInfo;
|
|
@@ -1759,25 +1759,28 @@ export const FLUID_WBTC_USDC_USDT_26_ARB = (networkId = NetworkNumber.Eth) => ({
|
|
|
1759
1759
|
debtAsset0: 'USDC',
|
|
1760
1760
|
debtAsset1: 'USDT',
|
|
1761
1761
|
});
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1762
|
+
// TODO: This issue is due to sUSDS price fetching via multicall on arbi fails and it's not handled correctly
|
|
1763
|
+
/*
|
|
1764
|
+
export const FLUID_SUSDS_USDC_USDT_30_ARB = (networkId: NetworkNumber = NetworkNumber.Eth): FluidMarketInfo => ({
|
|
1765
|
+
stableBased: true,
|
|
1766
|
+
btcBased: false,
|
|
1767
|
+
wstETHBased: false,
|
|
1768
|
+
ethBased: false,
|
|
1769
|
+
type: FluidVaultType.T3,
|
|
1770
|
+
id: 30,
|
|
1771
|
+
chainIds: [NetworkNumber.Arb],
|
|
1772
|
+
label: '#30 (sUSDS / USDC-USDT)',
|
|
1773
|
+
shortLabel: 'sUSDS/USDC-USDT',
|
|
1774
|
+
value: FluidArbitrumVersion.FLUID_SUSDS_USDC_USDT_30_ARB,
|
|
1775
|
+
url: 'susds_usdc_usdt_30_arb',
|
|
1776
|
+
marketAddress: '0xE6b5D1CdC4935295c84772C4700932b4BFC93274',
|
|
1777
|
+
hasSmartCollateral: false,
|
|
1778
|
+
hasSmartDebt: true,
|
|
1779
|
+
collateralAsset0: 'sUSDS',
|
|
1780
|
+
debtAsset0: 'USDC',
|
|
1781
|
+
debtAsset1: 'USDT',
|
|
1782
|
+
});
|
|
1783
|
+
*/
|
|
1781
1784
|
export const FLUID_ETH_USDC_1_BASE = (networkId = NetworkNumber.Eth) => ({
|
|
1782
1785
|
stableBased: true,
|
|
1783
1786
|
btcBased: false,
|
|
@@ -2082,7 +2085,7 @@ export const FLUID_ETH_SUSDS_17_BASE = (networkId = NetworkNumber.Eth) => ({
|
|
|
2082
2085
|
hasSmartCollateral: false,
|
|
2083
2086
|
hasSmartDebt: false,
|
|
2084
2087
|
collateralAsset0: 'ETH',
|
|
2085
|
-
debtAsset0: '
|
|
2088
|
+
debtAsset0: 'sUSDS',
|
|
2086
2089
|
});
|
|
2087
2090
|
export const FLUID_WSTETH_SUSDS_18_BASE = (networkId = NetworkNumber.Eth) => ({
|
|
2088
2091
|
stableBased: true,
|
|
@@ -2253,7 +2256,7 @@ export const FluidMarkets = (networkId) => ({
|
|
|
2253
2256
|
[FluidArbitrumVersion.FLUID_WSTETH_USDC_USDT_24_ARB]: FLUID_WSTETH_USDC_USDT_24_ARB(networkId),
|
|
2254
2257
|
[FluidArbitrumVersion.FLUID_WEETH_USDC_USDT_25_ARB]: FLUID_WEETH_USDC_USDT_25_ARB(networkId),
|
|
2255
2258
|
[FluidArbitrumVersion.FLUID_WBTC_USDC_USDT_26_ARB]: FLUID_WBTC_USDC_USDT_26_ARB(networkId),
|
|
2256
|
-
[FluidArbitrumVersion.FLUID_SUSDS_USDC_USDT_30_ARB]: FLUID_SUSDS_USDC_USDT_30_ARB(networkId),
|
|
2259
|
+
// [FluidArbitrumVersion.FLUID_SUSDS_USDC_USDT_30_ARB]: FLUID_SUSDS_USDC_USDT_30_ARB(networkId),
|
|
2257
2260
|
// base
|
|
2258
2261
|
[FluidBaseVersions.FLUID_ETH_USDC_1_BASE]: FLUID_ETH_USDC_1_BASE(networkId),
|
|
2259
2262
|
[FluidBaseVersions.FLUID_WSTETH_USDC_2_BASE]: FLUID_WSTETH_USDC_2_BASE(networkId),
|
|
@@ -28,4 +28,6 @@ export declare const parseWeETHPriceCalls: (_ethPrice: string, weETHrate: {
|
|
|
28
28
|
weETHRate: string;
|
|
29
29
|
};
|
|
30
30
|
export declare const getWstETHPriceFluid: (web3: Web3, network: NetworkNumber) => Promise<string>;
|
|
31
|
+
export declare const getBTCPriceForFluid: (web3: Web3, network: NetworkNumber) => Promise<string>;
|
|
32
|
+
export declare const getEthPriceForFluid: (web3: Web3, network: NetworkNumber) => Promise<string>;
|
|
31
33
|
export declare const getChainlinkAssetAddress: (symbol: string, network: NetworkNumber) => string;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
12
|
-
import { COMPPriceFeedContract, ETHPriceFeedContract, USDCPriceFeedContract, WeETHPriceFeedContract, WstETHPriceFeedContract, } from '../contracts';
|
|
12
|
+
import { COMPPriceFeedContract, ETHPriceFeedContract, BTCPriceFeedContract, USDCPriceFeedContract, WeETHPriceFeedContract, WstETHPriceFeedContract, } from '../contracts';
|
|
13
13
|
import { NetworkNumber } from '../types/common';
|
|
14
14
|
import { multicall } from '../multicall';
|
|
15
15
|
import { getEthAmountForDecimals } from './utils';
|
|
@@ -109,6 +109,16 @@ export const getWstETHPriceFluid = (web3, network) => __awaiter(void 0, void 0,
|
|
|
109
109
|
const { ethPrice, wstETHRate } = parseWstETHPriceCalls(multicallRes[0][0], multicallRes[1], multicallRes[2][0]);
|
|
110
110
|
return new Dec(ethPrice).mul(wstETHRate).toString();
|
|
111
111
|
});
|
|
112
|
+
export const getBTCPriceForFluid = (web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const contract = BTCPriceFeedContract(web3, network);
|
|
114
|
+
const price = yield contract.methods.latestAnswer().call();
|
|
115
|
+
return new Dec(price).div(1e8).toString();
|
|
116
|
+
});
|
|
117
|
+
export const getEthPriceForFluid = (web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
const contract = ETHPriceFeedContract(web3, network);
|
|
119
|
+
const price = yield contract.methods.latestAnswer().call();
|
|
120
|
+
return new Dec(price).div(1e8).toString();
|
|
121
|
+
});
|
|
112
122
|
// chainlink price feed available only on mainnet
|
|
113
123
|
export const getChainlinkAssetAddress = (symbol, network) => {
|
|
114
124
|
// Chainlink only has BTC/USD feed so we use that for BTC derivatives
|