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

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 (125) 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 +38 -0
  9. package/cjs/fluid/index.js +163 -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 +174 -0
  19. package/cjs/markets/fluid/index.js +1286 -0
  20. package/cjs/markets/index.d.ts +1 -0
  21. package/cjs/markets/index.js +3 -1
  22. package/cjs/types/contracts/generated/FluidView.d.ts +318 -0
  23. package/cjs/types/contracts/generated/FluidView.js +5 -0
  24. package/cjs/types/contracts/generated/index.d.ts +1 -0
  25. package/cjs/types/fluid.d.ts +225 -0
  26. package/cjs/types/fluid.js +129 -0
  27. package/cjs/types/index.d.ts +1 -0
  28. package/cjs/types/index.js +1 -0
  29. package/esm/config/contracts.d.ts +43 -0
  30. package/esm/config/contracts.js +6 -0
  31. package/esm/contracts.d.ts +1 -0
  32. package/esm/contracts.js +1 -0
  33. package/esm/fluid/index.d.ts +38 -0
  34. package/esm/fluid/index.js +153 -0
  35. package/esm/helpers/fluidHelpers/index.d.ts +6 -0
  36. package/esm/helpers/fluidHelpers/index.js +33 -0
  37. package/esm/helpers/index.d.ts +1 -0
  38. package/esm/helpers/index.js +1 -0
  39. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  40. package/esm/index.d.ts +2 -1
  41. package/esm/index.js +2 -1
  42. package/esm/markets/aave/marketAssets.js +1 -1
  43. package/esm/markets/fluid/index.d.ts +174 -0
  44. package/esm/markets/fluid/index.js +1196 -0
  45. package/esm/markets/index.d.ts +1 -0
  46. package/esm/markets/index.js +1 -0
  47. package/esm/types/contracts/generated/FluidView.d.ts +318 -0
  48. package/esm/types/contracts/generated/FluidView.js +4 -0
  49. package/esm/types/contracts/generated/index.d.ts +1 -0
  50. package/esm/types/fluid.d.ts +225 -0
  51. package/esm/types/fluid.js +126 -0
  52. package/esm/types/index.d.ts +1 -0
  53. package/esm/types/index.js +1 -0
  54. package/package.json +49 -49
  55. package/src/aaveV2/index.ts +227 -227
  56. package/src/aaveV3/index.ts +625 -625
  57. package/src/assets/index.ts +60 -60
  58. package/src/chickenBonds/index.ts +123 -123
  59. package/src/compoundV2/index.ts +220 -220
  60. package/src/compoundV3/index.ts +291 -291
  61. package/src/config/contracts.js +1115 -1109
  62. package/src/constants/index.ts +6 -6
  63. package/src/contracts.ts +134 -133
  64. package/src/curveUsd/index.ts +229 -229
  65. package/src/eulerV2/index.ts +303 -303
  66. package/src/exchange/index.ts +17 -17
  67. package/src/fluid/index.ts +220 -0
  68. package/src/helpers/aaveHelpers/index.ts +198 -198
  69. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  70. package/src/helpers/compoundHelpers/index.ts +246 -246
  71. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  72. package/src/helpers/eulerHelpers/index.ts +232 -232
  73. package/src/helpers/fluidHelpers/index.ts +54 -0
  74. package/src/helpers/index.ts +11 -10
  75. package/src/helpers/liquityV2Helpers/index.ts +79 -79
  76. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  77. package/src/helpers/makerHelpers/index.ts +94 -94
  78. package/src/helpers/morphoBlueHelpers/index.ts +365 -365
  79. package/src/helpers/sparkHelpers/index.ts +150 -150
  80. package/src/index.ts +52 -50
  81. package/src/liquity/index.ts +116 -116
  82. package/src/liquityV2/index.ts +227 -227
  83. package/src/llamaLend/index.ts +275 -275
  84. package/src/maker/index.ts +117 -117
  85. package/src/markets/aave/index.ts +152 -152
  86. package/src/markets/aave/marketAssets.ts +44 -44
  87. package/src/markets/compound/index.ts +213 -213
  88. package/src/markets/compound/marketsAssets.ts +82 -82
  89. package/src/markets/curveUsd/index.ts +69 -69
  90. package/src/markets/euler/index.ts +26 -26
  91. package/src/markets/fluid/index.ts +1290 -0
  92. package/src/markets/index.ts +25 -24
  93. package/src/markets/liquityV2/index.ts +43 -43
  94. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  95. package/src/markets/llamaLend/index.ts +235 -235
  96. package/src/markets/morphoBlue/index.ts +895 -895
  97. package/src/markets/spark/index.ts +29 -29
  98. package/src/markets/spark/marketAssets.ts +10 -10
  99. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  100. package/src/morphoAaveV2/index.ts +256 -256
  101. package/src/morphoAaveV3/index.ts +631 -631
  102. package/src/morphoBlue/index.ts +204 -204
  103. package/src/multicall/index.ts +22 -22
  104. package/src/services/dsrService.ts +15 -15
  105. package/src/services/priceService.ts +62 -62
  106. package/src/services/utils.ts +56 -56
  107. package/src/setup.ts +8 -8
  108. package/src/spark/index.ts +461 -461
  109. package/src/staking/staking.ts +220 -220
  110. package/src/types/aave.ts +271 -271
  111. package/src/types/chickenBonds.ts +45 -45
  112. package/src/types/common.ts +84 -84
  113. package/src/types/compound.ts +131 -131
  114. package/src/types/contracts/generated/FluidView.ts +399 -0
  115. package/src/types/contracts/generated/index.ts +1 -0
  116. package/src/types/curveUsd.ts +118 -118
  117. package/src/types/euler.ts +171 -171
  118. package/src/types/fluid.ts +240 -0
  119. package/src/types/index.ts +12 -11
  120. package/src/types/liquity.ts +30 -30
  121. package/src/types/liquityV2.ts +118 -118
  122. package/src/types/llamaLend.ts +155 -155
  123. package/src/types/maker.ts +50 -50
  124. package/src/types/morphoBlue.ts +192 -192
  125. 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
+ internalType: string;
7612
+ name: string;
7613
+ type: string;
7614
+ }[];
7615
+ stateMutability: string;
7616
+ type: string;
7617
+ } | {
7618
+ inputs: {
7619
+ internalType: string;
7620
+ name: string;
7621
+ type: string;
7622
+ }[];
7623
+ name: string;
7624
+ outputs: {
7625
+ components: {
7626
+ internalType: string;
7627
+ name: string;
7628
+ type: string;
7629
+ }[];
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": [], "name": "feedRegistry", "outputs": [{ "internalType": "contract IFeedRegistry", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveTokenPriceInETH", "outputs": [{ "internalType": "uint256", "name": "price", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveTokenPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveV3TokenPriceInETH", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveV3TokenPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "price", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getAddrForChainlinkOracle", "outputs": [{ "internalType": "address", "name": "tokenAddrForChainlinkUsage", "type": "address" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getChainlinkPriceInETH", "outputs": [{ "internalType": "int256", "name": "chainlinkPriceInETH", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }, { "internalType": "bool", "name": "_useFallback", "type": "bool" }], "name": "getChainlinkPriceInUSD", "outputs": [{ "internalType": "int256", "name": "chainlinkPriceInUSD", "type": "int256" }], "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": "priceOfSupplyToken0InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfSupplyToken1InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfBorrowToken0InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfBorrowToken1InUSD", "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": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getPriceInETH", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "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": "_inputTokenAddr", "type": "address" }, { "internalType": "uint80", "name": "_roundId", "type": "uint80" }, { "internalType": "contract IAggregatorV3", "name": "aggregator", "type": "address" }], "name": "getRoundInfo", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "updateTimestamp", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }, { "internalType": "uint80", "name": "_roundId", "type": "uint80" }], "name": "getRoundInfo", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "updateTimestamp", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getSparkTokenPriceInETH", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getSparkTokenPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "price", "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": "priceOfSupplyToken0InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfSupplyToken1InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfBorrowToken0InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfBorrowToken1InUSD", "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": "priceOfSupplyToken0InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfSupplyToken1InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfBorrowToken0InUSD", "type": "uint256" }, { "internalType": "uint256", "name": "priceOfBorrowToken1InUSD", "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" }, { "inputs": [{ "internalType": "int256", "name": "_btcPrice", "type": "int256" }], "name": "getWBtcPrice", "outputs": [{ "internalType": "int256", "name": "wBtcPrice", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "int256", "name": "_stEthPrice", "type": "int256" }], "name": "getWStEthPrice", "outputs": [{ "internalType": "int256", "name": "wStEthPrice", "type": "int256" }], "stateMutability": "view", "type": "function" }],
1111
+ "networks": {
1112
+ "1": { "address": "0xBAc6dc3edB72Bc705Ab4e31F2a2151Fe06550D9B" }
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,38 @@
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
+ }>;
@@ -0,0 +1,163 @@
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.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 types_1 = require("../types");
19
+ const contracts_1 = require("../contracts");
20
+ const utils_1 = require("../services/utils");
21
+ const fluidHelpers_1 = require("../helpers/fluidHelpers");
22
+ exports.EMPTY_USED_ASSET = {
23
+ isSupplied: false,
24
+ isBorrowed: false,
25
+ supplied: '0',
26
+ suppliedUsd: '0',
27
+ borrowed: '0',
28
+ borrowedUsd: '0',
29
+ symbol: '',
30
+ collateral: false,
31
+ };
32
+ const parseVaultType = (vaultType) => {
33
+ switch (vaultType) {
34
+ case 10000: return types_1.FluidVaultType.T1;
35
+ case 20000: return types_1.FluidVaultType.T2;
36
+ case 30000: return types_1.FluidVaultType.T3;
37
+ case 40000: return types_1.FluidVaultType.T4;
38
+ default: return types_1.FluidVaultType.Unknown;
39
+ }
40
+ };
41
+ const parseMarketData = (data) => {
42
+ const collAsset = (0, tokens_1.getAssetInfoByAddress)(data.supplyToken0);
43
+ const debtAsset = (0, tokens_1.getAssetInfoByAddress)(data.borrowToken0);
44
+ const collAssetData = {
45
+ symbol: collAsset.symbol,
46
+ address: collAsset.address,
47
+ price: (0, utils_1.getEthAmountForDecimals)(data.priceOfSupplyToken0InUSD, 8),
48
+ totalSupply: data.totalSupplyVault,
49
+ totalBorrow: data.totalBorrowVault,
50
+ canBeSupplied: true,
51
+ canBeBorrowed: false,
52
+ supplyRate: new decimal_js_1.default(data.supplyRateVault).div(100).toString(),
53
+ borrowRate: '0',
54
+ };
55
+ const debtAssetData = {
56
+ symbol: debtAsset.symbol,
57
+ address: debtAsset.address,
58
+ price: (0, utils_1.getEthAmountForDecimals)(data.priceOfBorrowToken0InUSD, 8),
59
+ totalSupply: data.totalSupplyVault,
60
+ totalBorrow: data.totalBorrowVault,
61
+ canBeSupplied: false,
62
+ canBeBorrowed: true,
63
+ supplyRate: '0',
64
+ borrowRate: new decimal_js_1.default(data.borrowRateVault).div(100).toString(),
65
+ };
66
+ const assetsData = {
67
+ [collAsset.symbol]: collAssetData,
68
+ [debtAsset.symbol]: debtAssetData,
69
+ };
70
+ const marketData = {
71
+ vaultId: +data.vaultId,
72
+ isSmartColl: data.isSmartColl,
73
+ isSmartDebt: data.isSmartDebt,
74
+ marketAddress: data.vault,
75
+ vaultType: parseVaultType(+data.vaultType),
76
+ oracle: data.oracle,
77
+ liquidationPenaltyPercent: new decimal_js_1.default(data.liquidationPenalty).div(100).toString(),
78
+ collFactor: new decimal_js_1.default(data.collateralFactor).div(10000).toString(),
79
+ liquidationRatio: new decimal_js_1.default(data.liquidationThreshold).div(100).toString(),
80
+ collAsset0: collAsset.symbol,
81
+ debtAsset0: debtAsset.symbol,
82
+ totalPositions: data.totalPositions,
83
+ totalSupplyVault: (0, utils_1.getEthAmountForDecimals)(data.totalSupplyVault, collAsset.decimals),
84
+ totalBorrowVault: (0, utils_1.getEthAmountForDecimals)(data.totalBorrowVault, debtAsset.decimals),
85
+ withdrawalLimit: (0, utils_1.getEthAmountForDecimals)(data.withdrawalLimit, collAsset.decimals),
86
+ withdrawableUntilLimit: (0, utils_1.getEthAmountForDecimals)(data.withdrawableUntilLimit, collAsset.decimals),
87
+ withdrawable: (0, utils_1.getEthAmountForDecimals)(data.withdrawable, collAsset.decimals),
88
+ borrowLimit: (0, utils_1.getEthAmountForDecimals)(data.borrowLimit, debtAsset.decimals),
89
+ borrowableUntilLimit: (0, utils_1.getEthAmountForDecimals)(data.borrowableUntilLimit, debtAsset.decimals),
90
+ borrowable: (0, utils_1.getEthAmountForDecimals)(data.borrowable, debtAsset.decimals),
91
+ borrowLimitUtilization: (0, utils_1.getEthAmountForDecimals)(data.borrowLimitUtilization, debtAsset.decimals),
92
+ maxBorrowLimit: (0, utils_1.getEthAmountForDecimals)(data.maxBorrowLimit, debtAsset.decimals),
93
+ baseBorrowLimit: (0, utils_1.getEthAmountForDecimals)(data.baseBorrowLimit, debtAsset.decimals),
94
+ minimumBorrowing: (0, utils_1.getEthAmountForDecimals)(data.minimumBorrowing, debtAsset.decimals),
95
+ };
96
+ return {
97
+ assetsData,
98
+ marketData,
99
+ };
100
+ };
101
+ exports.EMPTY_FLUID_DATA = {
102
+ usedAssets: {},
103
+ suppliedUsd: '0',
104
+ borrowedUsd: '0',
105
+ borrowLimitUsd: '0',
106
+ leftToBorrowUsd: '0',
107
+ ratio: '0',
108
+ minRatio: '0',
109
+ netApy: '0',
110
+ incentiveUsd: '0',
111
+ totalInterestUsd: '0',
112
+ isSubscribedToAutomation: false,
113
+ automationResubscribeRequired: false,
114
+ lastUpdated: Date.now(),
115
+ };
116
+ const parseUserData = (userPositionData, vaultData) => {
117
+ const { assetsData, marketData, } = vaultData;
118
+ const payload = Object.assign(Object.assign({ owner: userPositionData.owner, vaultId: marketData.vaultId }, exports.EMPTY_FLUID_DATA), { lastUpdated: Date.now() });
119
+ const collAsset = (0, tokens_1.getAssetInfo)(marketData.collAsset0);
120
+ const debtAsset = (0, tokens_1.getAssetInfo)(marketData.debtAsset0);
121
+ const supplied = (0, utils_1.getEthAmountForDecimals)(userPositionData.supply, collAsset.decimals);
122
+ const borrowed = (0, utils_1.getEthAmountForDecimals)(userPositionData.borrow, debtAsset.decimals);
123
+ 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) });
124
+ 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) });
125
+ const usedAssets = {
126
+ [collAsset.symbol]: collUsedAsset,
127
+ [debtAsset.symbol]: debtUsedAsset,
128
+ };
129
+ return Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), (0, fluidHelpers_1.getFluidAggregatedData)({
130
+ usedAssets,
131
+ assetsData,
132
+ marketData,
133
+ }));
134
+ };
135
+ const getFluidMarketData = (web3, network, market) => __awaiter(void 0, void 0, void 0, function* () {
136
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
137
+ const data = yield view.methods.getVaultData(market.marketAddress).call();
138
+ return parseMarketData(data);
139
+ });
140
+ exports.getFluidMarketData = getFluidMarketData;
141
+ const getFluidVaultIdsForUser = (web3, network, user) => __awaiter(void 0, void 0, void 0, function* () {
142
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
143
+ return view.methods.getUserNftIds(user).call();
144
+ });
145
+ exports.getFluidVaultIdsForUser = getFluidVaultIdsForUser;
146
+ const getFluidPosition = (web3, network, vaultId, extractedState) => __awaiter(void 0, void 0, void 0, function* () {
147
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
148
+ const data = yield view.methods.getPositionByNftId(vaultId).call();
149
+ const userPositionData = data[0];
150
+ return parseUserData(userPositionData, extractedState);
151
+ });
152
+ exports.getFluidPosition = getFluidPosition;
153
+ const getFluidPositionWithMarket = (web3, network, vaultId) => __awaiter(void 0, void 0, void 0, function* () {
154
+ const view = (0, contracts_1.FluidViewContract)(web3, network);
155
+ const data = yield view.methods.getPositionByNftId(vaultId).call();
156
+ const marketData = parseMarketData(data.vault);
157
+ const userData = parseUserData(data.position, marketData);
158
+ return {
159
+ userData,
160
+ marketData,
161
+ };
162
+ });
163
+ exports.getFluidPositionWithMarket = getFluidPositionWithMarket;
@@ -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"));