@defisaver/positions-sdk 1.0.11-fluid-dev9 → 1.0.11-fluid-dev11

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.
Files changed (78) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +69 -69
  4. package/cjs/config/contracts.js +2 -2
  5. package/cjs/fluid/index.js +33 -8
  6. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  7. package/esm/config/contracts.js +2 -2
  8. package/esm/fluid/index.js +33 -8
  9. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  10. package/package.json +54 -54
  11. package/src/aaveV2/index.ts +227 -227
  12. package/src/aaveV3/index.ts +624 -624
  13. package/src/assets/index.ts +60 -60
  14. package/src/chickenBonds/index.ts +123 -123
  15. package/src/compoundV2/index.ts +220 -220
  16. package/src/compoundV3/index.ts +291 -291
  17. package/src/config/contracts.js +1155 -1155
  18. package/src/constants/index.ts +6 -6
  19. package/src/contracts.ts +135 -135
  20. package/src/curveUsd/index.ts +239 -239
  21. package/src/eulerV2/index.ts +303 -303
  22. package/src/exchange/index.ts +17 -17
  23. package/src/fluid/index.ts +1261 -1224
  24. package/src/helpers/aaveHelpers/index.ts +203 -203
  25. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  26. package/src/helpers/compoundHelpers/index.ts +248 -248
  27. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  28. package/src/helpers/eulerHelpers/index.ts +234 -234
  29. package/src/helpers/fluidHelpers/index.ts +294 -294
  30. package/src/helpers/index.ts +11 -11
  31. package/src/helpers/liquityV2Helpers/index.ts +80 -80
  32. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  33. package/src/helpers/makerHelpers/index.ts +94 -94
  34. package/src/helpers/morphoBlueHelpers/index.ts +367 -367
  35. package/src/helpers/sparkHelpers/index.ts +154 -154
  36. package/src/index.ts +52 -52
  37. package/src/liquity/index.ts +116 -116
  38. package/src/liquityV2/index.ts +295 -295
  39. package/src/llamaLend/index.ts +275 -275
  40. package/src/maker/index.ts +117 -117
  41. package/src/markets/aave/index.ts +152 -152
  42. package/src/markets/aave/marketAssets.ts +46 -46
  43. package/src/markets/compound/index.ts +213 -213
  44. package/src/markets/compound/marketsAssets.ts +82 -82
  45. package/src/markets/curveUsd/index.ts +69 -69
  46. package/src/markets/euler/index.ts +26 -26
  47. package/src/markets/fluid/index.ts +2454 -2454
  48. package/src/markets/index.ts +27 -27
  49. package/src/markets/liquityV2/index.ts +54 -54
  50. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  51. package/src/markets/llamaLend/index.ts +235 -235
  52. package/src/markets/morphoBlue/index.ts +895 -895
  53. package/src/markets/spark/index.ts +29 -29
  54. package/src/markets/spark/marketAssets.ts +10 -10
  55. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  56. package/src/morphoAaveV2/index.ts +256 -256
  57. package/src/morphoAaveV3/index.ts +630 -630
  58. package/src/morphoBlue/index.ts +202 -202
  59. package/src/multicall/index.ts +33 -33
  60. package/src/services/priceService.ts +130 -130
  61. package/src/services/utils.ts +59 -59
  62. package/src/setup.ts +8 -8
  63. package/src/spark/index.ts +460 -460
  64. package/src/staking/staking.ts +217 -217
  65. package/src/types/aave.ts +275 -275
  66. package/src/types/chickenBonds.ts +45 -45
  67. package/src/types/common.ts +84 -84
  68. package/src/types/compound.ts +133 -133
  69. package/src/types/curveUsd.ts +119 -119
  70. package/src/types/euler.ts +173 -173
  71. package/src/types/fluid.ts +325 -325
  72. package/src/types/index.ts +11 -11
  73. package/src/types/liquity.ts +30 -30
  74. package/src/types/liquityV2.ts +119 -119
  75. package/src/types/llamaLend.ts +155 -155
  76. package/src/types/maker.ts +50 -50
  77. package/src/types/morphoBlue.ts +194 -194
  78. 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
@@ -1148,8 +1148,8 @@ module.exports = {
1148
1148
  "abi": [{ "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }, { "internalType": "uint256", "name": "_token0Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_token1Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_maxSharesAmount", "type": "uint256" }], "name": "estimateBorrow", "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }, { "internalType": "uint256", "name": "_token0Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_token1Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_minSharesAmount", "type": "uint256" }], "name": "estimateDeposit", "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], "stateMutability": "payable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_nftId", "type": "uint256" }, { "internalType": "uint256", "name": "_minToken0AmountToAccept", "type": "uint256" }, { "internalType": "uint256", "name": "_minToken1AmountToAccept", "type": "uint256" }], "name": "estimateDexPositionCollateralInOneToken", "outputs": [{ "internalType": "uint256", "name": "collateral", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_nftId", "type": "uint256" }, { "internalType": "uint256", "name": "_maxToken0AmountToPayback", "type": "uint256" }, { "internalType": "uint256", "name": "_maxToken1AmountToPayback", "type": "uint256" }], "name": "estimateDexPositionDebtInOneToken", "outputs": [{ "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }, { "internalType": "uint256", "name": "_token0Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_token1Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_minSharesAmount", "type": "uint256" }], "name": "estimatePayback", "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }, { "internalType": "uint256", "name": "_token0Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_token1Amount", "type": "uint256" }, { "internalType": "uint256", "name": "_maxSharesAmount", "type": "uint256" }], "name": "estimateWithdraw", "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "getAllFTokens", "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "getAllFTokensData", "outputs": [{ "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "bool", "name": "isNativeUnderlying", "type": "bool" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "symbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "address", "name": "asset", "type": "address" }, { "internalType": "uint256", "name": "totalAssets", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupply", "type": "uint256" }, { "internalType": "uint256", "name": "convertToShares", "type": "uint256" }, { "internalType": "uint256", "name": "convertToAssets", "type": "uint256" }, { "internalType": "uint256", "name": "rewardsRate", "type": "uint256" }, { "internalType": "uint256", "name": "supplyRate", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawable", "type": "uint256" }, { "internalType": "bool", "name": "modeWithInterest", "type": "bool" }, { "internalType": "uint256", "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "expandDuration", "type": "uint256" }], "internalType": "struct FluidView.FTokenData[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }], "name": "getAllUserEarnPositionsWithFTokens", "outputs": [{ "components": [{ "internalType": "uint256", "name": "fTokenShares", "type": "uint256" }, { "internalType": "uint256", "name": "underlyingAssets", "type": "uint256" }, { "internalType": "uint256", "name": "underlyingBalance", "type": "uint256" }, { "internalType": "uint256", "name": "allowance", "type": "uint256" }], "internalType": "struct FluidView.UserEarnPosition[]", "name": "userPositions", "type": "tuple[]" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "bool", "name": "isNativeUnderlying", "type": "bool" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "symbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "address", "name": "asset", "type": "address" }, { "internalType": "uint256", "name": "totalAssets", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupply", "type": "uint256" }, { "internalType": "uint256", "name": "convertToShares", "type": "uint256" }, { "internalType": "uint256", "name": "convertToAssets", "type": "uint256" }, { "internalType": "uint256", "name": "rewardsRate", "type": "uint256" }, { "internalType": "uint256", "name": "supplyRate", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawable", "type": "uint256" }, { "internalType": "bool", "name": "modeWithInterest", "type": "bool" }, { "internalType": "uint256", "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "expandDuration", "type": "uint256" }], "internalType": "struct FluidView.FTokenData[]", "name": "fTokensData", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }], "name": "getDexShareRates", "outputs": [{ "internalType": "uint256", "name": "token0PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token0PerBorrowShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerBorrowShare", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_fToken", "type": "address" }], "name": "getFTokenData", "outputs": [{ "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "bool", "name": "isNativeUnderlying", "type": "bool" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "symbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "address", "name": "asset", "type": "address" }, { "internalType": "uint256", "name": "totalAssets", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupply", "type": "uint256" }, { "internalType": "uint256", "name": "convertToShares", "type": "uint256" }, { "internalType": "uint256", "name": "convertToAssets", "type": "uint256" }, { "internalType": "uint256", "name": "rewardsRate", "type": "uint256" }, { "internalType": "uint256", "name": "supplyRate", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawable", "type": "uint256" }, { "internalType": "bool", "name": "modeWithInterest", "type": "bool" }, { "internalType": "uint256", "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "expandDuration", "type": "uint256" }], "internalType": "struct FluidView.FTokenData", "name": "fTokenData", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_nftId", "type": "uint256" }], "name": "getPositionByNftId", "outputs": [{ "components": [{ "internalType": "uint256", "name": "nftId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "bool", "name": "isLiquidated", "type": "bool" }, { "internalType": "bool", "name": "isSupplyPosition", "type": "bool" }, { "internalType": "uint256", "name": "supply", "type": "uint256" }, { "internalType": "uint256", "name": "borrow", "type": "uint256" }, { "internalType": "uint256", "name": "ratio", "type": "uint256" }, { "internalType": "int256", "name": "tick", "type": "int256" }, { "internalType": "uint256", "name": "tickId", "type": "uint256" }], "internalType": "struct FluidView.UserPosition", "name": "position", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "vault", "type": "address" }, { "internalType": "uint256", "name": "vaultId", "type": "uint256" }, { "internalType": "uint256", "name": "vaultType", "type": "uint256" }, { "internalType": "bool", "name": "isSmartColl", "type": "bool" }, { "internalType": "bool", "name": "isSmartDebt", "type": "bool" }, { "internalType": "address", "name": "supplyToken0", "type": "address" }, { "internalType": "address", "name": "supplyToken1", "type": "address" }, { "internalType": "address", "name": "borrowToken0", "type": "address" }, { "internalType": "address", "name": "borrowToken1", "type": "address" }, { "internalType": "uint256", "name": "supplyToken0Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken1Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken0Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken1Decimals", "type": "uint256" }, { "internalType": "uint16", "name": "collateralFactor", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationThreshold", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationMaxLimit", "type": "uint16" }, { "internalType": "uint16", "name": "withdrawalGap", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationPenalty", "type": "uint16" }, { "internalType": "uint16", "name": "borrowFee", "type": "uint16" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "uint256", "name": "oraclePriceOperate", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePriceLiquidate", "type": "uint256" }, { "internalType": "uint256", "name": "vaultSupplyExchangePrice", "type": "uint256" }, { "internalType": "uint256", "name": "vaultBorrowExchangePrice", "type": "uint256" }, { "internalType": "int256", "name": "supplyRateVault", "type": "int256" }, { "internalType": "int256", "name": "borrowRateVault", "type": "int256" }, { "internalType": "int256", "name": "rewardsOrFeeRateSupply", "type": "int256" }, { "internalType": "int256", "name": "rewardsOrFeeRateBorrow", "type": "int256" }, { "internalType": "uint256", "name": "totalPositions", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyVault", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrowVault", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawableUntilLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "baseWithdrawalLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawExpandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawExpandDuration", "type": "uint256" }, { "internalType": "uint256", "name": "borrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowableUntilLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "borrowLimitUtilization", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowExpandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "borrowExpandDuration", "type": "uint256" }, { "internalType": "uint256", "name": "baseBorrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "minimumBorrowing", "type": "uint256" }, { "components": [{ "internalType": "address", "name": "dexPool", "type": "address" }, { "internalType": "uint256", "name": "dexId", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "lastStoredPrice", "type": "uint256" }, { "internalType": "uint256", "name": "centerPrice", "type": "uint256" }, { "internalType": "uint256", "name": "token0Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "token1Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "maxSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "token0Supplied", "type": "uint256" }, { "internalType": "uint256", "name": "token1Supplied", "type": "uint256" }, { "internalType": "uint256", "name": "sharesWithdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token0Withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token1Withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token0PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token0SupplyRate", "type": "uint256" }, { "internalType": "uint256", "name": "token1SupplyRate", "type": "uint256" }, { "internalType": "address", "name": "quoteToken", "type": "address" }, { "internalType": "uint256", "name": "quoteTokensPerShare", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken0Reserves", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken1Reserves", "type": "uint256" }], "internalType": "struct FluidView.DexSupplyData", "name": "dexSupplyData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "dexPool", "type": "address" }, { "internalType": "uint256", "name": "dexId", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "lastStoredPrice", "type": "uint256" }, { "internalType": "uint256", "name": "centerPrice", "type": "uint256" }, { "internalType": "uint256", "name": "token0Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "token1Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "token0Borrowed", "type": "uint256" }, { "internalType": "uint256", "name": "token1Borrowed", "type": "uint256" }, { "internalType": "uint256", "name": "sharesBorrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token0Borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token1Borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token0PerBorrowShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerBorrowShare", "type": "uint256" }, { "internalType": "uint256", "name": "token0BorrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "token1BorrowRate", "type": "uint256" }, { "internalType": "address", "name": "quoteToken", "type": "address" }, { "internalType": "uint256", "name": "quoteTokensPerShare", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken0Reserves", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken1Reserves", "type": "uint256" }], "internalType": "struct FluidView.DexBorrowData", "name": "dexBorrowData", "type": "tuple" }], "internalType": "struct FluidView.VaultData", "name": "vault", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_nftId", "type": "uint256" }], "name": "getRatio", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_fToken", "type": "address" }, { "internalType": "address", "name": "_user", "type": "address" }], "name": "getUserEarnPosition", "outputs": [{ "components": [{ "internalType": "uint256", "name": "fTokenShares", "type": "uint256" }, { "internalType": "uint256", "name": "underlyingAssets", "type": "uint256" }, { "internalType": "uint256", "name": "underlyingBalance", "type": "uint256" }, { "internalType": "uint256", "name": "allowance", "type": "uint256" }], "internalType": "struct FluidView.UserEarnPosition", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_fToken", "type": "address" }, { "internalType": "address", "name": "_user", "type": "address" }], "name": "getUserEarnPositionWithFToken", "outputs": [{ "components": [{ "internalType": "uint256", "name": "fTokenShares", "type": "uint256" }, { "internalType": "uint256", "name": "underlyingAssets", "type": "uint256" }, { "internalType": "uint256", "name": "underlyingBalance", "type": "uint256" }, { "internalType": "uint256", "name": "allowance", "type": "uint256" }], "internalType": "struct FluidView.UserEarnPosition", "name": "userPosition", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "bool", "name": "isNativeUnderlying", "type": "bool" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "symbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "address", "name": "asset", "type": "address" }, { "internalType": "uint256", "name": "totalAssets", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupply", "type": "uint256" }, { "internalType": "uint256", "name": "convertToShares", "type": "uint256" }, { "internalType": "uint256", "name": "convertToAssets", "type": "uint256" }, { "internalType": "uint256", "name": "rewardsRate", "type": "uint256" }, { "internalType": "uint256", "name": "supplyRate", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawable", "type": "uint256" }, { "internalType": "bool", "name": "modeWithInterest", "type": "bool" }, { "internalType": "uint256", "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "expandDuration", "type": "uint256" }], "internalType": "struct FluidView.FTokenData", "name": "fTokenData", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }], "name": "getUserNftIds", "outputs": [{ "internalType": "uint256[]", "name": "", "type": "uint256[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }], "name": "getUserNftIdsWithVaultIds", "outputs": [{ "components": [{ "internalType": "uint256", "name": "nftId", "type": "uint256" }, { "internalType": "uint256", "name": "vaultId", "type": "uint256" }, { "internalType": "address", "name": "vaultAddr", "type": "address" }], "internalType": "struct FluidView.NftWithVault[]", "name": "retVal", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }], "name": "getUserPositions", "outputs": [{ "components": [{ "internalType": "uint256", "name": "nftId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "bool", "name": "isLiquidated", "type": "bool" }, { "internalType": "bool", "name": "isSupplyPosition", "type": "bool" }, { "internalType": "uint256", "name": "supply", "type": "uint256" }, { "internalType": "uint256", "name": "borrow", "type": "uint256" }, { "internalType": "uint256", "name": "ratio", "type": "uint256" }, { "internalType": "int256", "name": "tick", "type": "int256" }, { "internalType": "uint256", "name": "tickId", "type": "uint256" }], "internalType": "struct FluidView.UserPosition[]", "name": "positions", "type": "tuple[]" }, { "components": [{ "internalType": "address", "name": "vault", "type": "address" }, { "internalType": "uint256", "name": "vaultId", "type": "uint256" }, { "internalType": "uint256", "name": "vaultType", "type": "uint256" }, { "internalType": "bool", "name": "isSmartColl", "type": "bool" }, { "internalType": "bool", "name": "isSmartDebt", "type": "bool" }, { "internalType": "address", "name": "supplyToken0", "type": "address" }, { "internalType": "address", "name": "supplyToken1", "type": "address" }, { "internalType": "address", "name": "borrowToken0", "type": "address" }, { "internalType": "address", "name": "borrowToken1", "type": "address" }, { "internalType": "uint256", "name": "supplyToken0Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken1Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken0Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken1Decimals", "type": "uint256" }, { "internalType": "uint16", "name": "collateralFactor", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationThreshold", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationMaxLimit", "type": "uint16" }, { "internalType": "uint16", "name": "withdrawalGap", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationPenalty", "type": "uint16" }, { "internalType": "uint16", "name": "borrowFee", "type": "uint16" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "uint256", "name": "oraclePriceOperate", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePriceLiquidate", "type": "uint256" }, { "internalType": "uint256", "name": "vaultSupplyExchangePrice", "type": "uint256" }, { "internalType": "uint256", "name": "vaultBorrowExchangePrice", "type": "uint256" }, { "internalType": "int256", "name": "supplyRateVault", "type": "int256" }, { "internalType": "int256", "name": "borrowRateVault", "type": "int256" }, { "internalType": "int256", "name": "rewardsOrFeeRateSupply", "type": "int256" }, { "internalType": "int256", "name": "rewardsOrFeeRateBorrow", "type": "int256" }, { "internalType": "uint256", "name": "totalPositions", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyVault", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrowVault", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawableUntilLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "baseWithdrawalLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawExpandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawExpandDuration", "type": "uint256" }, { "internalType": "uint256", "name": "borrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowableUntilLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "borrowLimitUtilization", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowExpandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "borrowExpandDuration", "type": "uint256" }, { "internalType": "uint256", "name": "baseBorrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "minimumBorrowing", "type": "uint256" }, { "components": [{ "internalType": "address", "name": "dexPool", "type": "address" }, { "internalType": "uint256", "name": "dexId", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "lastStoredPrice", "type": "uint256" }, { "internalType": "uint256", "name": "centerPrice", "type": "uint256" }, { "internalType": "uint256", "name": "token0Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "token1Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "maxSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "token0Supplied", "type": "uint256" }, { "internalType": "uint256", "name": "token1Supplied", "type": "uint256" }, { "internalType": "uint256", "name": "sharesWithdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token0Withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token1Withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token0PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token0SupplyRate", "type": "uint256" }, { "internalType": "uint256", "name": "token1SupplyRate", "type": "uint256" }, { "internalType": "address", "name": "quoteToken", "type": "address" }, { "internalType": "uint256", "name": "quoteTokensPerShare", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken0Reserves", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken1Reserves", "type": "uint256" }], "internalType": "struct FluidView.DexSupplyData", "name": "dexSupplyData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "dexPool", "type": "address" }, { "internalType": "uint256", "name": "dexId", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "lastStoredPrice", "type": "uint256" }, { "internalType": "uint256", "name": "centerPrice", "type": "uint256" }, { "internalType": "uint256", "name": "token0Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "token1Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "token0Borrowed", "type": "uint256" }, { "internalType": "uint256", "name": "token1Borrowed", "type": "uint256" }, { "internalType": "uint256", "name": "sharesBorrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token0Borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token1Borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token0PerBorrowShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerBorrowShare", "type": "uint256" }, { "internalType": "uint256", "name": "token0BorrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "token1BorrowRate", "type": "uint256" }, { "internalType": "address", "name": "quoteToken", "type": "address" }, { "internalType": "uint256", "name": "quoteTokensPerShare", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken0Reserves", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken1Reserves", "type": "uint256" }], "internalType": "struct FluidView.DexBorrowData", "name": "dexBorrowData", "type": "tuple" }], "internalType": "struct FluidView.VaultData[]", "name": "vaults", "type": "tuple[]" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }], "name": "getVaultData", "outputs": [{ "components": [{ "internalType": "address", "name": "vault", "type": "address" }, { "internalType": "uint256", "name": "vaultId", "type": "uint256" }, { "internalType": "uint256", "name": "vaultType", "type": "uint256" }, { "internalType": "bool", "name": "isSmartColl", "type": "bool" }, { "internalType": "bool", "name": "isSmartDebt", "type": "bool" }, { "internalType": "address", "name": "supplyToken0", "type": "address" }, { "internalType": "address", "name": "supplyToken1", "type": "address" }, { "internalType": "address", "name": "borrowToken0", "type": "address" }, { "internalType": "address", "name": "borrowToken1", "type": "address" }, { "internalType": "uint256", "name": "supplyToken0Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken1Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken0Decimals", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken1Decimals", "type": "uint256" }, { "internalType": "uint16", "name": "collateralFactor", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationThreshold", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationMaxLimit", "type": "uint16" }, { "internalType": "uint16", "name": "withdrawalGap", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationPenalty", "type": "uint16" }, { "internalType": "uint16", "name": "borrowFee", "type": "uint16" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "uint256", "name": "oraclePriceOperate", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePriceLiquidate", "type": "uint256" }, { "internalType": "uint256", "name": "vaultSupplyExchangePrice", "type": "uint256" }, { "internalType": "uint256", "name": "vaultBorrowExchangePrice", "type": "uint256" }, { "internalType": "int256", "name": "supplyRateVault", "type": "int256" }, { "internalType": "int256", "name": "borrowRateVault", "type": "int256" }, { "internalType": "int256", "name": "rewardsOrFeeRateSupply", "type": "int256" }, { "internalType": "int256", "name": "rewardsOrFeeRateBorrow", "type": "int256" }, { "internalType": "uint256", "name": "totalPositions", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyVault", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrowVault", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawableUntilLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "baseWithdrawalLimit", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawExpandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "withdrawExpandDuration", "type": "uint256" }, { "internalType": "uint256", "name": "borrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowableUntilLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "borrowLimitUtilization", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowExpandPercent", "type": "uint256" }, { "internalType": "uint256", "name": "borrowExpandDuration", "type": "uint256" }, { "internalType": "uint256", "name": "baseBorrowLimit", "type": "uint256" }, { "internalType": "uint256", "name": "minimumBorrowing", "type": "uint256" }, { "components": [{ "internalType": "address", "name": "dexPool", "type": "address" }, { "internalType": "uint256", "name": "dexId", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "lastStoredPrice", "type": "uint256" }, { "internalType": "uint256", "name": "centerPrice", "type": "uint256" }, { "internalType": "uint256", "name": "token0Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "token1Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "maxSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "token0Supplied", "type": "uint256" }, { "internalType": "uint256", "name": "token1Supplied", "type": "uint256" }, { "internalType": "uint256", "name": "sharesWithdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token0Withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token1Withdrawable", "type": "uint256" }, { "internalType": "uint256", "name": "token0PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerSupplyShare", "type": "uint256" }, { "internalType": "uint256", "name": "token0SupplyRate", "type": "uint256" }, { "internalType": "uint256", "name": "token1SupplyRate", "type": "uint256" }, { "internalType": "address", "name": "quoteToken", "type": "address" }, { "internalType": "uint256", "name": "quoteTokensPerShare", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken0Reserves", "type": "uint256" }, { "internalType": "uint256", "name": "supplyToken1Reserves", "type": "uint256" }], "internalType": "struct FluidView.DexSupplyData", "name": "dexSupplyData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "dexPool", "type": "address" }, { "internalType": "uint256", "name": "dexId", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "lastStoredPrice", "type": "uint256" }, { "internalType": "uint256", "name": "centerPrice", "type": "uint256" }, { "internalType": "uint256", "name": "token0Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "token1Utilization", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "token0Borrowed", "type": "uint256" }, { "internalType": "uint256", "name": "token1Borrowed", "type": "uint256" }, { "internalType": "uint256", "name": "sharesBorrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token0Borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token1Borrowable", "type": "uint256" }, { "internalType": "uint256", "name": "token0PerBorrowShare", "type": "uint256" }, { "internalType": "uint256", "name": "token1PerBorrowShare", "type": "uint256" }, { "internalType": "uint256", "name": "token0BorrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "token1BorrowRate", "type": "uint256" }, { "internalType": "address", "name": "quoteToken", "type": "address" }, { "internalType": "uint256", "name": "quoteTokensPerShare", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken0Reserves", "type": "uint256" }, { "internalType": "uint256", "name": "borrowToken1Reserves", "type": "uint256" }], "internalType": "struct FluidView.DexBorrowData", "name": "dexBorrowData", "type": "tuple" }], "internalType": "struct FluidView.VaultData", "name": "vaultData", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }],
1149
1149
  "networks": {
1150
1150
  "1": { "address": "0xc8df052bD7A8d76a34c09e758Dff3c6298C0115c" },
1151
- "8453": { "address": "0x5835CaDbA8843CD6d6d55782908351E9c74221aD" },
1152
- "42161": { "address": "0x2d51BB6Ac5c1eC8DD6432e1FF980fC864B626e01" }
1151
+ "8453": { "address": "0x6cd4D6af4F292817eA2A2311F099dF26cd015028" },
1152
+ "42161": { "address": "0xf9e6d5568887ac8eC6fA33B7eefD2A176A958e71" }
1153
1153
  }
1154
1154
  }
1155
1155
  };
@@ -213,6 +213,19 @@ const parseT1MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
213
213
  marketData,
214
214
  };
215
215
  });
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
+ const getAdditionalMarketRateForDex = (token1PerShare, token0PerShare, incentiveSupplyRate0, incentiveSupplyRate1) => {
223
+ console.log(incentiveSupplyRate0, incentiveSupplyRate1);
224
+ const sharesCombined = new decimal_js_1.default(token1PerShare).plus(token0PerShare);
225
+ const rate0PerShare = incentiveSupplyRate0 ? new decimal_js_1.default(incentiveSupplyRate0).mul(token0PerShare).div(sharesCombined).toString() : 0;
226
+ const rate1PerShare = incentiveSupplyRate1 ? new decimal_js_1.default(incentiveSupplyRate1).mul(token1PerShare).div(sharesCombined).toString() : 0;
227
+ return new decimal_js_1.default(rate0PerShare).plus(rate1PerShare).toString();
228
+ };
216
229
  const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
217
230
  const collAsset0 = (0, tokens_1.getAssetInfoByAddress)(data.supplyToken0, network);
218
231
  const collAsset1 = (0, tokens_1.getAssetInfoByAddress)(data.supplyToken1, network);
@@ -251,15 +264,17 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
251
264
  tokenPerSupplyShare: token1PerSupplyShare,
252
265
  supplyReserves: reservesSupplyToken1,
253
266
  };
254
- if (staking_1.STAKING_ASSETS.includes(collFirstAssetData.symbol)) {
255
- collFirstAssetData.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collAsset1.symbol, mainnetWeb3);
256
- collFirstAssetData.incentiveSupplyToken = collAsset1.symbol;
267
+ if (staking_1.STAKING_ASSETS.includes(collSecondAssetData.symbol)) {
268
+ collSecondAssetData.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collAsset1.symbol, mainnetWeb3);
269
+ collSecondAssetData.incentiveSupplyToken = collAsset1.symbol;
257
270
  }
271
+ const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1);
272
+ const incentiveSupplyRate = getAdditionalMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, collFirstAssetData.incentiveSupplyApy, collSecondAssetData.incentiveSupplyApy);
258
273
  const borrowRate = new decimal_js_1.default(data.borrowRateVault).div(100).toString();
259
274
  const debtAssetData = {
260
275
  symbol: debtAsset.symbol,
261
- address: debtAsset.address,
262
276
  price: prices[debtAsset.address],
277
+ address: debtAsset.address,
263
278
  totalBorrow: data.totalBorrowVault,
264
279
  canBeBorrowed: true,
265
280
  borrowRate,
@@ -315,7 +330,8 @@ const parseT2MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
315
330
  minimumBorrowing: (0, utils_1.getEthAmountForDecimals)(data.minimumBorrowing, debtAsset.decimals),
316
331
  liquidationMaxLimit,
317
332
  borrowRate,
318
- supplyRate: '0',
333
+ supplyRate: marketSupplyRate,
334
+ incentiveSupplyRate,
319
335
  totalSupplyToken0,
320
336
  totalSupplyToken1,
321
337
  withdrawableToken0,
@@ -388,6 +404,8 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
388
404
  debtAsset1Data.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(debtAsset1.symbol, mainnetWeb3);
389
405
  debtAsset1Data.incentiveSupplyToken = debtAsset1.symbol;
390
406
  }
407
+ const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1);
408
+ const incentiveBorrowRate = getAdditionalMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, debtAsset0Data.incentiveSupplyApy, debtAsset1Data.incentiveSupplyApy);
391
409
  const assetsData = [
392
410
  [collAsset.symbol, collAssetData],
393
411
  [debtAsset0.symbol, debtAsset0Data],
@@ -429,8 +447,9 @@ const parseT3MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
429
447
  withdrawableUntilLimit: (0, utils_1.getEthAmountForDecimals)(data.withdrawableUntilLimit, collAsset.decimals),
430
448
  withdrawable: (0, utils_1.getEthAmountForDecimals)(data.withdrawable, collAsset.decimals),
431
449
  liquidationMaxLimit,
432
- borrowRate: '0',
450
+ borrowRate: marketBorrowRate,
433
451
  supplyRate,
452
+ incentiveBorrowRate,
434
453
  borrowableToken0,
435
454
  borrowableToken1,
436
455
  totalBorrowToken0,
@@ -526,6 +545,10 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
526
545
  debtAsset1Data.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(debtAsset1.symbol, mainnetWeb3);
527
546
  debtAsset1Data.incentiveSupplyToken = debtAsset1.symbol;
528
547
  }
548
+ const marketBorrowRate = getMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, borrowRate0, borrowRate1);
549
+ const incentiveBorrowRate = getAdditionalMarketRateForDex(token1PerBorrowShare, token0PerBorrowShare, debtAsset0Data.incentiveSupplyApy, debtAsset1Data.incentiveSupplyApy);
550
+ const marketSupplyRate = getMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, supplyRate0, supplyRate1);
551
+ const incentiveSupplyRate = getAdditionalMarketRateForDex(token1PerSupplyShare, token0PerSupplyShare, collAsset0Data.incentiveSupplyApy, collAsset1Data.incentiveSupplyApy);
529
552
  const assetsData = [
530
553
  [collAsset0.symbol, collAsset0Data],
531
554
  [collAsset1.symbol, collAsset1Data],
@@ -570,8 +593,10 @@ const parseT4MarketData = (web3, data, network, mainnetWeb3) => __awaiter(void 0
570
593
  totalSupplyVaultUsd,
571
594
  totalBorrowVaultUsd,
572
595
  liquidationMaxLimit,
573
- borrowRate: '0',
574
- supplyRate: '0',
596
+ borrowRate: marketBorrowRate,
597
+ incentiveBorrowRate,
598
+ supplyRate: marketSupplyRate,
599
+ incentiveSupplyRate,
575
600
  borrowableToken0,
576
601
  borrowableToken1,
577
602
  totalBorrowToken0,
@@ -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