@defisaver/positions-sdk 0.0.200 → 0.0.201-fluid-dev-1

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 (135) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +69 -69
  4. package/cjs/config/contracts.d.ts +43 -0
  5. package/cjs/config/contracts.js +6 -0
  6. package/cjs/contracts.d.ts +1 -0
  7. package/cjs/contracts.js +2 -1
  8. package/cjs/fluid/index.d.ts +39 -0
  9. package/cjs/fluid/index.js +216 -0
  10. package/cjs/helpers/fluidHelpers/index.d.ts +6 -0
  11. package/cjs/helpers/fluidHelpers/index.js +40 -0
  12. package/cjs/helpers/index.d.ts +1 -0
  13. package/cjs/helpers/index.js +2 -1
  14. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  15. package/cjs/index.d.ts +2 -1
  16. package/cjs/index.js +3 -1
  17. package/cjs/markets/aave/marketAssets.js +1 -1
  18. package/cjs/markets/fluid/index.d.ts +176 -0
  19. package/cjs/markets/fluid/index.js +1630 -0
  20. package/cjs/markets/index.d.ts +1 -0
  21. package/cjs/markets/index.js +5 -1
  22. package/cjs/morphoBlue/index.js +1 -2
  23. package/cjs/multicall/index.d.ts +1 -0
  24. package/cjs/multicall/index.js +8 -1
  25. package/cjs/services/utils.d.ts +1 -0
  26. package/cjs/services/utils.js +3 -1
  27. package/cjs/types/contracts/generated/FluidView.d.ts +276 -0
  28. package/cjs/types/contracts/generated/FluidView.js +5 -0
  29. package/cjs/types/contracts/generated/index.d.ts +1 -0
  30. package/cjs/types/fluid.d.ts +236 -0
  31. package/cjs/types/fluid.js +129 -0
  32. package/cjs/types/index.d.ts +1 -0
  33. package/cjs/types/index.js +1 -0
  34. package/esm/config/contracts.d.ts +43 -0
  35. package/esm/config/contracts.js +6 -0
  36. package/esm/contracts.d.ts +1 -0
  37. package/esm/contracts.js +1 -0
  38. package/esm/fluid/index.d.ts +39 -0
  39. package/esm/fluid/index.js +205 -0
  40. package/esm/helpers/fluidHelpers/index.d.ts +6 -0
  41. package/esm/helpers/fluidHelpers/index.js +33 -0
  42. package/esm/helpers/index.d.ts +1 -0
  43. package/esm/helpers/index.js +1 -0
  44. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  45. package/esm/index.d.ts +2 -1
  46. package/esm/index.js +2 -1
  47. package/esm/markets/aave/marketAssets.js +1 -1
  48. package/esm/markets/fluid/index.d.ts +176 -0
  49. package/esm/markets/fluid/index.js +1538 -0
  50. package/esm/markets/index.d.ts +1 -0
  51. package/esm/markets/index.js +1 -0
  52. package/esm/morphoBlue/index.js +1 -2
  53. package/esm/multicall/index.d.ts +1 -0
  54. package/esm/multicall/index.js +6 -0
  55. package/esm/services/utils.d.ts +1 -0
  56. package/esm/services/utils.js +1 -0
  57. package/esm/types/contracts/generated/FluidView.d.ts +276 -0
  58. package/esm/types/contracts/generated/FluidView.js +4 -0
  59. package/esm/types/contracts/generated/index.d.ts +1 -0
  60. package/esm/types/fluid.d.ts +236 -0
  61. package/esm/types/fluid.js +126 -0
  62. package/esm/types/index.d.ts +1 -0
  63. package/esm/types/index.js +1 -0
  64. package/package.json +51 -49
  65. package/src/aaveV2/index.ts +227 -227
  66. package/src/aaveV3/index.ts +625 -625
  67. package/src/assets/index.ts +60 -60
  68. package/src/chickenBonds/index.ts +123 -123
  69. package/src/compoundV2/index.ts +220 -220
  70. package/src/compoundV3/index.ts +291 -291
  71. package/src/config/contracts.js +1115 -1109
  72. package/src/constants/index.ts +6 -6
  73. package/src/contracts.ts +134 -133
  74. package/src/curveUsd/index.ts +229 -229
  75. package/src/eulerV2/index.ts +303 -303
  76. package/src/exchange/index.ts +17 -17
  77. package/src/fluid/index.ts +277 -0
  78. package/src/helpers/aaveHelpers/index.ts +198 -198
  79. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  80. package/src/helpers/compoundHelpers/index.ts +246 -246
  81. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  82. package/src/helpers/eulerHelpers/index.ts +232 -232
  83. package/src/helpers/fluidHelpers/index.ts +54 -0
  84. package/src/helpers/index.ts +11 -10
  85. package/src/helpers/liquityV2Helpers/index.ts +79 -79
  86. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  87. package/src/helpers/makerHelpers/index.ts +94 -94
  88. package/src/helpers/morphoBlueHelpers/index.ts +365 -365
  89. package/src/helpers/sparkHelpers/index.ts +150 -150
  90. package/src/index.ts +52 -50
  91. package/src/liquity/index.ts +116 -116
  92. package/src/liquityV2/index.ts +227 -227
  93. package/src/llamaLend/index.ts +275 -275
  94. package/src/maker/index.ts +117 -117
  95. package/src/markets/aave/index.ts +152 -152
  96. package/src/markets/aave/marketAssets.ts +44 -44
  97. package/src/markets/compound/index.ts +213 -213
  98. package/src/markets/compound/marketsAssets.ts +82 -82
  99. package/src/markets/curveUsd/index.ts +69 -69
  100. package/src/markets/euler/index.ts +26 -26
  101. package/src/markets/fluid/index.ts +1635 -0
  102. package/src/markets/index.ts +25 -24
  103. package/src/markets/liquityV2/index.ts +43 -43
  104. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  105. package/src/markets/llamaLend/index.ts +235 -235
  106. package/src/markets/morphoBlue/index.ts +895 -895
  107. package/src/markets/spark/index.ts +29 -29
  108. package/src/markets/spark/marketAssets.ts +10 -10
  109. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  110. package/src/morphoAaveV2/index.ts +256 -256
  111. package/src/morphoAaveV3/index.ts +631 -631
  112. package/src/morphoBlue/index.ts +202 -204
  113. package/src/multicall/index.ts +32 -23
  114. package/src/services/dsrService.ts +15 -15
  115. package/src/services/priceService.ts +62 -62
  116. package/src/services/utils.ts +59 -57
  117. package/src/setup.ts +8 -8
  118. package/src/spark/index.ts +461 -461
  119. package/src/staking/staking.ts +220 -220
  120. package/src/types/aave.ts +271 -271
  121. package/src/types/chickenBonds.ts +45 -45
  122. package/src/types/common.ts +84 -84
  123. package/src/types/compound.ts +131 -131
  124. package/src/types/contracts/generated/FluidView.ts +317 -0
  125. package/src/types/contracts/generated/index.ts +1 -0
  126. package/src/types/curveUsd.ts +118 -118
  127. package/src/types/euler.ts +171 -171
  128. package/src/types/fluid.ts +251 -0
  129. package/src/types/index.ts +12 -11
  130. package/src/types/liquity.ts +30 -30
  131. package/src/types/liquityV2.ts +118 -118
  132. package/src/types/llamaLend.ts +155 -155
  133. package/src/types/maker.ts +50 -50
  134. package/src/types/morphoBlue.ts +192 -192
  135. package/src/types/spark.ts +131 -131
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
@@ -7599,3 +7599,46 @@ export namespace EulerV2View {
7599
7599
  };
7600
7600
  export { networks_84 as networks };
7601
7601
  }
7602
+ export namespace FluidView {
7603
+ let abi_85: ({
7604
+ inputs: {
7605
+ internalType: string;
7606
+ name: string;
7607
+ type: string;
7608
+ }[];
7609
+ name: string;
7610
+ outputs: {
7611
+ components: {
7612
+ internalType: string;
7613
+ name: string;
7614
+ type: string;
7615
+ }[];
7616
+ internalType: string;
7617
+ name: string;
7618
+ type: string;
7619
+ }[];
7620
+ stateMutability: string;
7621
+ type: string;
7622
+ } | {
7623
+ inputs: {
7624
+ internalType: string;
7625
+ name: string;
7626
+ type: string;
7627
+ }[];
7628
+ name: string;
7629
+ outputs: {
7630
+ internalType: string;
7631
+ name: string;
7632
+ type: string;
7633
+ }[];
7634
+ stateMutability: string;
7635
+ type: string;
7636
+ })[];
7637
+ export { abi_85 as abi };
7638
+ let networks_85: {
7639
+ "1": {
7640
+ address: string;
7641
+ };
7642
+ };
7643
+ export { networks_85 as networks };
7644
+ }
@@ -1105,5 +1105,11 @@ module.exports = {
1105
1105
  "networks": {
1106
1106
  "1": { "address": "0x8932E46Ecf96b5Fe033F5e27Ab6dC755Cb668967" }
1107
1107
  }
1108
+ },
1109
+ "FluidView": {
1110
+ "abi": [{ "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" }], "internalType": "struct FluidView.VaultData", "name": "vault", "type": "tuple" }], "stateMutability": "view", "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": "_user", "type": "address" }], "name": "getUserNftIds", "outputs": [{ "internalType": "uint256[]", "name": "", "type": "uint256[]" }], "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" }], "internalType": "struct FluidView.VaultData[]", "name": "vaults", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256[]", "name": "_ids", "type": "uint256[]" }, { "internalType": "bool", "name": "_fetchAll", "type": "bool" }], "name": "getVaultAddresses", "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], "stateMutability": "view", "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" }], "internalType": "struct FluidView.VaultData", "name": "vaultData", "type": "tuple" }], "stateMutability": "view", "type": "function" }],
1111
+ "networks": {
1112
+ "1": { "address": "0x72B2A658d2009fF3c3e133d3a042fFE705808aC5" }
1113
+ }
1108
1114
  }
1109
1115
  };
@@ -49,3 +49,4 @@ export declare const MorphoBlueViewContract: (web3: Web3, network: NetworkNumber
49
49
  export declare const LlamaLendViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.LlamaLendView;
50
50
  export declare const LiquityV2ViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.LiquityV2View;
51
51
  export declare const EulerV2ViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.EulerV2View;
52
+ export declare const FluidViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.FluidView;
package/cjs/contracts.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EulerV2ViewContract = exports.LiquityV2ViewContract = exports.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.DFSFeedRegistryContract = exports.FeedRegistryContract = exports.WstETHPriceFeedContract = exports.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
6
+ exports.FluidViewContract = exports.EulerV2ViewContract = exports.LiquityV2ViewContract = exports.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.DFSFeedRegistryContract = exports.FeedRegistryContract = exports.WstETHPriceFeedContract = exports.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
7
7
  const contracts_1 = __importDefault(require("./config/contracts"));
8
8
  const contractConfig = contracts_1.default;
9
9
  const getConfigContractAddress = (name, network, block) => {
@@ -91,3 +91,4 @@ exports.MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueView');
91
91
  exports.LlamaLendViewContract = createContractFromConfigFunc('LlamaLendView');
92
92
  exports.LiquityV2ViewContract = createContractFromConfigFunc('LiquityV2View');
93
93
  exports.EulerV2ViewContract = createContractFromConfigFunc('EulerV2View');
94
+ exports.FluidViewContract = createContractFromConfigFunc('FluidView');
@@ -0,0 +1,39 @@
1
+ import Web3 from 'web3';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { FluidAssetsData, FluidMarketData, FluidMarketInfo, FluidVaultData, InnerFluidMarketData } from '../types';
4
+ export declare const EMPTY_USED_ASSET: {
5
+ isSupplied: boolean;
6
+ isBorrowed: boolean;
7
+ supplied: string;
8
+ suppliedUsd: string;
9
+ borrowed: string;
10
+ borrowedUsd: string;
11
+ symbol: string;
12
+ collateral: boolean;
13
+ };
14
+ export declare const EMPTY_FLUID_DATA: {
15
+ usedAssets: {};
16
+ suppliedUsd: string;
17
+ borrowedUsd: string;
18
+ borrowLimitUsd: string;
19
+ leftToBorrowUsd: string;
20
+ ratio: string;
21
+ minRatio: string;
22
+ netApy: string;
23
+ incentiveUsd: string;
24
+ totalInterestUsd: string;
25
+ isSubscribedToAutomation: boolean;
26
+ automationResubscribeRequired: boolean;
27
+ lastUpdated: number;
28
+ };
29
+ export declare const getFluidMarketData: (web3: Web3, network: NetworkNumber, market: FluidMarketInfo) => Promise<FluidMarketData>;
30
+ export declare const getFluidVaultIdsForUser: (web3: Web3, network: NetworkNumber, user: EthAddress) => Promise<string[]>;
31
+ export declare const getFluidPosition: (web3: Web3, network: NetworkNumber, vaultId: string, extractedState: {
32
+ assetsData: FluidAssetsData;
33
+ marketData: InnerFluidMarketData;
34
+ }) => Promise<FluidVaultData>;
35
+ export declare const getFluidPositionWithMarket: (web3: Web3, network: NetworkNumber, vaultId: string) => Promise<{
36
+ userData: FluidVaultData;
37
+ marketData: FluidMarketData;
38
+ }>;
39
+ export declare const getAllFluidMarketDataChunked: (network: NetworkNumber, web3: Web3) => Promise<FluidMarketData[]>;
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getAllFluidMarketDataChunked = exports.getFluidPositionWithMarket = exports.getFluidPosition = exports.getFluidVaultIdsForUser = exports.getFluidMarketData = exports.EMPTY_FLUID_DATA = exports.EMPTY_USED_ASSET = void 0;
16
+ const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const tokens_1 = require("@defisaver/tokens");
18
+ const common_1 = require("../types/common");
19
+ const types_1 = require("../types");
20
+ const contracts_1 = require("../contracts");
21
+ const utils_1 = require("../services/utils");
22
+ const fluidHelpers_1 = require("../helpers/fluidHelpers");
23
+ const multicall_1 = require("../multicall");
24
+ const fluid_1 = require("../markets/fluid");
25
+ const constants_1 = require("../constants");
26
+ const priceService_1 = require("../services/priceService");
27
+ exports.EMPTY_USED_ASSET = {
28
+ isSupplied: false,
29
+ isBorrowed: false,
30
+ supplied: '0',
31
+ suppliedUsd: '0',
32
+ borrowed: '0',
33
+ borrowedUsd: '0',
34
+ symbol: '',
35
+ collateral: false,
36
+ };
37
+ const parseVaultType = (vaultType) => {
38
+ switch (vaultType) {
39
+ case 10000: return types_1.FluidVaultType.T1;
40
+ case 20000: return types_1.FluidVaultType.T2;
41
+ case 30000: return types_1.FluidVaultType.T3;
42
+ case 40000: return types_1.FluidVaultType.T4;
43
+ default: return types_1.FluidVaultType.Unknown;
44
+ }
45
+ };
46
+ const parseMarketData = (web3, data, network) => __awaiter(void 0, void 0, void 0, function* () {
47
+ const collAsset = (0, tokens_1.getAssetInfoByAddress)(data.supplyToken0);
48
+ const debtAsset = (0, tokens_1.getAssetInfoByAddress)(data.borrowToken0);
49
+ const supplyRate = new decimal_js_1.default(data.supplyRateVault).div(100).toString();
50
+ const borrowRate = new decimal_js_1.default(data.borrowRateVault).div(100).toString();
51
+ const oracleScaleFactor = new decimal_js_1.default(27).add(debtAsset.decimals).sub(collAsset.decimals).toString();
52
+ const oracleScale = new decimal_js_1.default(10).pow(oracleScaleFactor).toString();
53
+ const oraclePrice = new decimal_js_1.default(data.oraclePriceOperate).div(oracleScale).toString();
54
+ const isTokenUSDA = debtAsset.symbol === 'USDA';
55
+ const isMainnet = (0, utils_1.isMainnetNetwork)(network);
56
+ const loanTokenFeedAddress = (0, priceService_1.getChainlinkAssetAddress)(debtAsset.symbol, network);
57
+ let loanTokenPrice;
58
+ if (debtAsset.symbol === 'wstETH') {
59
+ // need to handle wstETH for l2s inside getWstETHPrice
60
+ loanTokenPrice = yield (0, priceService_1.getWstETHPrice)(web3);
61
+ }
62
+ else if (isMainnet) {
63
+ const feedRegistryContract = (0, contracts_1.FeedRegistryContract)(web3, common_1.NetworkNumber.Eth);
64
+ loanTokenPrice = isTokenUSDA ? '100000000' : yield feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, constants_1.USD_QUOTE).call();
65
+ }
66
+ else {
67
+ // Currently only base network is supported
68
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContract)(web3, network);
69
+ const roundPriceData = isTokenUSDA ? { answer: '100000000' } : yield feedRegistryContract.methods.latestRoundData(loanTokenFeedAddress, constants_1.USD_QUOTE).call();
70
+ loanTokenPrice = roundPriceData.answer;
71
+ }
72
+ const debtPriceParsed = new decimal_js_1.default(loanTokenPrice).div(1e8).toString();
73
+ const collAssetData = {
74
+ symbol: collAsset.symbol,
75
+ address: collAsset.address,
76
+ price: new decimal_js_1.default(debtPriceParsed).mul(oraclePrice).toString(),
77
+ totalSupply: data.totalSupplyVault,
78
+ totalBorrow: data.totalBorrowVault,
79
+ canBeSupplied: true,
80
+ canBeBorrowed: false,
81
+ supplyRate,
82
+ borrowRate: '0',
83
+ };
84
+ const debtAssetData = {
85
+ symbol: debtAsset.symbol,
86
+ address: debtAsset.address,
87
+ price: debtPriceParsed,
88
+ totalSupply: data.totalSupplyVault,
89
+ totalBorrow: data.totalBorrowVault,
90
+ canBeSupplied: false,
91
+ canBeBorrowed: true,
92
+ supplyRate: '0',
93
+ borrowRate,
94
+ };
95
+ const assetsData = {
96
+ [collAsset.symbol]: collAssetData,
97
+ [debtAsset.symbol]: debtAssetData,
98
+ };
99
+ const marketInfo = (0, fluid_1.getFluidMarketInfoById)(+data.vaultId, network);
100
+ const totalSupplyVault = (0, utils_1.getEthAmountForDecimals)(data.totalSupplyVault, collAsset.decimals);
101
+ const totalBorrowVault = (0, utils_1.getEthAmountForDecimals)(data.totalBorrowVault, debtAsset.decimals);
102
+ const liqRatio = new decimal_js_1.default(data.liquidationThreshold).div(100).toString();
103
+ const liqFactor = new decimal_js_1.default(data.liquidationThreshold).div(10000).toString();
104
+ const marketData = {
105
+ vaultId: +data.vaultId,
106
+ vaultValue: marketInfo === null || marketInfo === void 0 ? void 0 : marketInfo.value,
107
+ isSmartColl: data.isSmartColl,
108
+ isSmartDebt: data.isSmartDebt,
109
+ marketAddress: data.vault,
110
+ vaultType: parseVaultType(+data.vaultType),
111
+ oracle: data.oracle,
112
+ liquidationPenaltyPercent: new decimal_js_1.default(data.liquidationPenalty).div(100).toString(),
113
+ collFactor: new decimal_js_1.default(data.collateralFactor).div(10000).toString(),
114
+ liquidationRatio: liqRatio,
115
+ liqFactor,
116
+ minRatio: new decimal_js_1.default(1).div(liqFactor).mul(100).toString(),
117
+ collAsset0: collAsset.symbol,
118
+ debtAsset0: debtAsset.symbol,
119
+ totalPositions: data.totalPositions,
120
+ totalSupplyVault,
121
+ totalBorrowVault,
122
+ totalSupplyVaultUsd: new decimal_js_1.default(totalSupplyVault).mul(collAssetData.price).toString(),
123
+ totalBorrowVaultUsd: new decimal_js_1.default(totalSupplyVault).mul(debtAssetData.price).toString(),
124
+ withdrawalLimit: (0, utils_1.getEthAmountForDecimals)(data.withdrawalLimit, collAsset.decimals),
125
+ withdrawableUntilLimit: (0, utils_1.getEthAmountForDecimals)(data.withdrawableUntilLimit, collAsset.decimals),
126
+ withdrawable: (0, utils_1.getEthAmountForDecimals)(data.withdrawable, collAsset.decimals),
127
+ borrowLimit: (0, utils_1.getEthAmountForDecimals)(data.borrowLimit, debtAsset.decimals),
128
+ borrowableUntilLimit: (0, utils_1.getEthAmountForDecimals)(data.borrowableUntilLimit, debtAsset.decimals),
129
+ borrowable: (0, utils_1.getEthAmountForDecimals)(data.borrowable, debtAsset.decimals),
130
+ borrowLimitUtilization: (0, utils_1.getEthAmountForDecimals)(data.borrowLimitUtilization, debtAsset.decimals),
131
+ maxBorrowLimit: (0, utils_1.getEthAmountForDecimals)(data.maxBorrowLimit, debtAsset.decimals),
132
+ baseBorrowLimit: (0, utils_1.getEthAmountForDecimals)(data.baseBorrowLimit, debtAsset.decimals),
133
+ minimumBorrowing: (0, utils_1.getEthAmountForDecimals)(data.minimumBorrowing, debtAsset.decimals),
134
+ borrowRate,
135
+ supplyRate,
136
+ };
137
+ return {
138
+ assetsData,
139
+ marketData,
140
+ };
141
+ });
142
+ exports.EMPTY_FLUID_DATA = {
143
+ usedAssets: {},
144
+ suppliedUsd: '0',
145
+ borrowedUsd: '0',
146
+ borrowLimitUsd: '0',
147
+ leftToBorrowUsd: '0',
148
+ ratio: '0',
149
+ minRatio: '0',
150
+ netApy: '0',
151
+ incentiveUsd: '0',
152
+ totalInterestUsd: '0',
153
+ isSubscribedToAutomation: false,
154
+ automationResubscribeRequired: false,
155
+ lastUpdated: Date.now(),
156
+ };
157
+ const parseUserData = (userPositionData, vaultData) => {
158
+ const { assetsData, marketData, } = vaultData;
159
+ const payload = Object.assign(Object.assign({ owner: userPositionData.owner, vaultId: marketData.vaultId }, exports.EMPTY_FLUID_DATA), { lastUpdated: Date.now() });
160
+ const collAsset = (0, tokens_1.getAssetInfo)(marketData.collAsset0);
161
+ const debtAsset = (0, tokens_1.getAssetInfo)(marketData.debtAsset0);
162
+ const supplied = (0, utils_1.getEthAmountForDecimals)(userPositionData.supply, collAsset.decimals);
163
+ const borrowed = (0, utils_1.getEthAmountForDecimals)(userPositionData.borrow, debtAsset.decimals);
164
+ const collUsedAsset = Object.assign(Object.assign({}, exports.EMPTY_USED_ASSET), { symbol: collAsset.symbol, collateral: true, supplied, suppliedUsd: new decimal_js_1.default(supplied).mul(assetsData[collAsset.symbol].price).toString(), isSupplied: new decimal_js_1.default(supplied).gt(0) });
165
+ const debtUsedAsset = Object.assign(Object.assign({}, exports.EMPTY_USED_ASSET), { symbol: debtAsset.symbol, collateral: false, borrowed, borrowedUsd: new decimal_js_1.default(borrowed).mul(assetsData[debtAsset.symbol].price).toString(), isBorrowed: new decimal_js_1.default(borrowed).gt(0) });
166
+ const usedAssets = {
167
+ [collAsset.symbol]: collUsedAsset,
168
+ [debtAsset.symbol]: debtUsedAsset,
169
+ };
170
+ return Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), (0, fluidHelpers_1.getFluidAggregatedData)({
171
+ usedAssets,
172
+ assetsData,
173
+ marketData,
174
+ }));
175
+ };
176
+ const getFluidMarketData = (web3, network, market) => __awaiter(void 0, void 0, void 0, function* () {
177
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
178
+ const data = yield view.methods.getVaultData(market.marketAddress).call();
179
+ return parseMarketData(web3, data, network);
180
+ });
181
+ exports.getFluidMarketData = getFluidMarketData;
182
+ const getFluidVaultIdsForUser = (web3, network, user) => __awaiter(void 0, void 0, void 0, function* () {
183
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
184
+ return view.methods.getUserNftIds(user).call();
185
+ });
186
+ exports.getFluidVaultIdsForUser = getFluidVaultIdsForUser;
187
+ const getFluidPosition = (web3, network, vaultId, extractedState) => __awaiter(void 0, void 0, void 0, function* () {
188
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
189
+ const data = yield view.methods.getPositionByNftId(vaultId).call();
190
+ const userPositionData = data[0];
191
+ return parseUserData(userPositionData, extractedState);
192
+ });
193
+ exports.getFluidPosition = getFluidPosition;
194
+ const getFluidPositionWithMarket = (web3, network, vaultId) => __awaiter(void 0, void 0, void 0, function* () {
195
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
196
+ const data = yield view.methods.getPositionByNftId(vaultId).call();
197
+ const marketData = yield parseMarketData(web3, data.vault, network);
198
+ const userData = parseUserData(data.position, marketData);
199
+ return {
200
+ userData,
201
+ marketData,
202
+ };
203
+ });
204
+ exports.getFluidPositionWithMarket = getFluidPositionWithMarket;
205
+ const getAllFluidMarketDataChunked = (network, web3) => __awaiter(void 0, void 0, void 0, function* () {
206
+ const versions = (0, fluid_1.getFluidVersionsDataForNetwork)(network);
207
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
208
+ const calls = versions.map((version) => ({
209
+ target: view.options.address,
210
+ abiItem: view.options.jsonInterface.find((item) => item.name === 'getVaultData'),
211
+ params: [version.marketAddress],
212
+ }));
213
+ const data = yield (0, multicall_1.chunkAndMulticall)(calls, 10, 'latest', web3, network);
214
+ return Promise.all(data.map((item, i) => __awaiter(void 0, void 0, void 0, function* () { return parseMarketData(web3, item.vaultData, network); })));
215
+ });
216
+ exports.getAllFluidMarketDataChunked = getAllFluidMarketDataChunked;
@@ -0,0 +1,6 @@
1
+ import { FluidAggregatedVaultData, FluidAssetsData, FluidUsedAssets, InnerFluidMarketData } from '../../types';
2
+ export declare const getFluidAggregatedData: ({ usedAssets, assetsData, marketData, }: {
3
+ usedAssets: FluidUsedAssets;
4
+ marketData: InnerFluidMarketData;
5
+ assetsData: FluidAssetsData;
6
+ }) => FluidAggregatedVaultData;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getFluidAggregatedData = void 0;
7
+ const decimal_js_1 = __importDefault(require("decimal.js"));
8
+ const moneymarket_1 = require("../../moneymarket");
9
+ const staking_1 = require("../../staking");
10
+ const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, }) => {
11
+ const payload = {};
12
+ payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
13
+ payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
14
+ const { netApy, incentiveUsd, totalInterestUsd } = (0, staking_1.calculateNetApy)({ usedAssets, assetsData: assetsData });
15
+ payload.netApy = netApy;
16
+ payload.incentiveUsd = incentiveUsd;
17
+ payload.totalInterestUsd = totalInterestUsd;
18
+ const collFactor = marketData.collFactor;
19
+ const liqRatio = marketData.liquidationRatio;
20
+ payload.borrowLimitUsd = new decimal_js_1.default(payload.suppliedUsd).mul(collFactor).toString();
21
+ payload.liquidationLimitUsd = new decimal_js_1.default(payload.suppliedUsd).mul(liqRatio).div(100).toString();
22
+ const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
23
+ payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
24
+ payload.ratio = +payload.suppliedUsd ? new decimal_js_1.default(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
25
+ payload.collRatio = +payload.suppliedUsd ? new decimal_js_1.default(payload.suppliedUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
26
+ const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
27
+ payload.leveragedType = leveragedType;
28
+ if (leveragedType !== '') {
29
+ payload.leveragedAsset = leveragedAsset;
30
+ let assetPrice = assetsData[leveragedAsset].price;
31
+ if (leveragedType === 'lsd-leverage') {
32
+ // Treat ETH like a stablecoin in a long stETH position
33
+ payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
34
+ assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
35
+ }
36
+ payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
37
+ }
38
+ return payload;
39
+ };
40
+ exports.getFluidAggregatedData = getFluidAggregatedData;
@@ -8,3 +8,4 @@ export * as morphoBlueHelpers from './morphoBlueHelpers';
8
8
  export * as llamaLendHelpers from './llamaLendHelpers';
9
9
  export * as liquityV2Helpers from './liquityV2Helpers';
10
10
  export * as eulerV2Helpers from './eulerHelpers';
11
+ export * as fluidHelpers from './fluidHelpers';
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.eulerV2Helpers = exports.liquityV2Helpers = exports.llamaLendHelpers = exports.morphoBlueHelpers = exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
26
+ exports.fluidHelpers = exports.eulerV2Helpers = exports.liquityV2Helpers = exports.llamaLendHelpers = exports.morphoBlueHelpers = exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
27
27
  exports.aaveHelpers = __importStar(require("./aaveHelpers"));
28
28
  exports.compoundHelpers = __importStar(require("./compoundHelpers"));
29
29
  exports.sparkHelpers = __importStar(require("./sparkHelpers"));
@@ -34,3 +34,4 @@ exports.morphoBlueHelpers = __importStar(require("./morphoBlueHelpers"));
34
34
  exports.llamaLendHelpers = __importStar(require("./llamaLendHelpers"));
35
35
  exports.liquityV2Helpers = __importStar(require("./liquityV2Helpers"));
36
36
  exports.eulerV2Helpers = __importStar(require("./eulerHelpers"));
37
+ exports.fluidHelpers = __importStar(require("./fluidHelpers"));