@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
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FluidVaultType = exports.FluidBaseDepositToken = exports.FluidArbitrumDepositToken = exports.FluidMainnetDepositToken = exports.FluidBaseVersions = exports.FluidArbitrumVersion = exports.FluidMainnetVersion = void 0;
4
+ const common_1 = require("./common");
5
+ var FluidMainnetVersion;
6
+ (function (FluidMainnetVersion) {
7
+ FluidMainnetVersion["ETH_USDC_1"] = "ETH_USDC_1";
8
+ FluidMainnetVersion["ETH_USDT_2"] = "ETH_USDT_2";
9
+ FluidMainnetVersion["WSTETH_ETH_3"] = "WSTETH_ETH_3";
10
+ FluidMainnetVersion["WSTETH_USDC_4"] = "WSTETH_USDC_4";
11
+ FluidMainnetVersion["WSTETH_USDT_5"] = "WSTETH_USDT_5";
12
+ FluidMainnetVersion["WEETH_WSTETH_6"] = "WEETH_WSTETH_6";
13
+ FluidMainnetVersion["SUSDE_USDC_7"] = "SUSDE_USDC_7";
14
+ FluidMainnetVersion["SUSDE_USDT_8"] = "SUSDE_USDT_8";
15
+ FluidMainnetVersion["WEETH_USDC_9"] = "WEETH_USDC_9";
16
+ FluidMainnetVersion["WEETH_USDT_10"] = "WEETH_USDT_10";
17
+ FluidMainnetVersion["ETH_USDC_11"] = "ETH_USDC_11";
18
+ FluidMainnetVersion["ETH_USDT_12"] = "ETH_USDT_12";
19
+ FluidMainnetVersion["WSTETH_ETH_13"] = "WSTETH_ETH_13";
20
+ FluidMainnetVersion["WSTETH_USDC_14"] = "WSTETH_USDC_14";
21
+ FluidMainnetVersion["WSTETH_USDT_15"] = "WSTETH_USDT_15";
22
+ FluidMainnetVersion["WEETH_WSTETH_16"] = "WEETH_WSTETH_16";
23
+ FluidMainnetVersion["SUSDE_USDC_17"] = "SUSDE_USDC_17";
24
+ FluidMainnetVersion["SUSDE_USDT_18"] = "SUSDE_USDT_18";
25
+ FluidMainnetVersion["WEETH_USDC_19"] = "WEETH_USDC_19";
26
+ FluidMainnetVersion["WEETH_USDT_20"] = "WEETH_USDT_20";
27
+ FluidMainnetVersion["WBTC_USDC_21"] = "WBTC_USDC_21";
28
+ FluidMainnetVersion["WBTC_USDT_22"] = "WBTC_USDT_22";
29
+ FluidMainnetVersion["WBTC_ETH_23"] = "WBTC_ETH_23";
30
+ FluidMainnetVersion["ETH_WBTC_24"] = "ETH_WBTC_24";
31
+ FluidMainnetVersion["WSTETH_WBTC_25"] = "WSTETH_WBTC_25";
32
+ FluidMainnetVersion["WEETH_WBTC_26"] = "WEETH_WBTC_26";
33
+ FluidMainnetVersion["WEETHS_WSTETH_27"] = "WEETHS_WSTETH_27";
34
+ FluidMainnetVersion["CBBTC_ETH_28"] = "CBBTC_ETH_28";
35
+ FluidMainnetVersion["CBBTC_USDC_29"] = "CBBTC_USDC_29";
36
+ FluidMainnetVersion["CBBTC_USDT_30"] = "CBBTC_USDT_30";
37
+ FluidMainnetVersion["ETH_CBBTC_31"] = "ETH_CBBTC_31";
38
+ FluidMainnetVersion["WEETH_CBBTC_32"] = "WEETH_CBBTC_32";
39
+ FluidMainnetVersion["WSTETH_CBBTC_33"] = "WSTETH_CBBTC_33";
40
+ FluidMainnetVersion["WSTETH_ETH_WSTETH_ETH_44"] = "WSTETH_ETH_WSTETH_ETH_44";
41
+ FluidMainnetVersion["ETH_USDC_USDT_45"] = "ETH_USDC_USDT_45";
42
+ FluidMainnetVersion["WSTETH_USDC_USDT_46"] = "WSTETH_USDC_USDT_46";
43
+ FluidMainnetVersion["WEETH_USDC_USDT_47"] = "WEETH_USDC_USDT_47";
44
+ FluidMainnetVersion["WBTC_USDC_USDT_48"] = "WBTC_USDC_USDT_48";
45
+ FluidMainnetVersion["CBBTC_USDC_USDT_49"] = "CBBTC_USDC_USDT_49";
46
+ FluidMainnetVersion["SUSDE_USDC_USDT_50"] = "SUSDE_USDC_USDT_50";
47
+ FluidMainnetVersion["WBTC_CBBTC_WBTC_CBBTC_51"] = "WBTC_CBBTC_WBTC_CBBTC_51";
48
+ FluidMainnetVersion["WBTC_CBBTC_USDC_52"] = "WBTC_CBBTC_USDC_52";
49
+ FluidMainnetVersion["WBTC_CBBTC_USDT_53"] = "WBTC_CBBTC_USDT_53";
50
+ FluidMainnetVersion["ETH_GHO_54"] = "ETH_GHO_54";
51
+ FluidMainnetVersion["WSTETH_GHO_55"] = "WSTETH_GHO_55";
52
+ FluidMainnetVersion["SUSDE_GHO_56"] = "SUSDE_GHO_56";
53
+ FluidMainnetVersion["WEETH_GHO_57"] = "WEETH_GHO_57";
54
+ FluidMainnetVersion["SUSDS_GHO_58"] = "SUSDS_GHO_58";
55
+ FluidMainnetVersion["WBTC_GHO_59"] = "WBTC_GHO_59";
56
+ FluidMainnetVersion["CBBTC_GHO_60"] = "CBBTC_GHO_60";
57
+ FluidMainnetVersion["GHO_USDC_GHO_USDC_61"] = "GHO_USDC_GHO_USDC_61";
58
+ FluidMainnetVersion["WEETH_ETH_WSTETH_74"] = "WEETH_ETH_WSTETH_74";
59
+ FluidMainnetVersion["USDC_ETH_USDC_ETH_77"] = "USDC_ETH_USDC_ETH_77";
60
+ FluidMainnetVersion["RSETH_ETH_WSTETH_78"] = "RSETH_ETH_WSTETH_78";
61
+ FluidMainnetVersion["RSETH_WSTETH_79"] = "RSETH_WSTETH_79";
62
+ FluidMainnetVersion["WEETHS_ETH_WSTETH_80"] = "WEETHS_ETH_WSTETH_80";
63
+ })(FluidMainnetVersion || (exports.FluidMainnetVersion = FluidMainnetVersion = {}));
64
+ var FluidArbitrumVersion;
65
+ (function (FluidArbitrumVersion) {
66
+ FluidArbitrumVersion["ETH_USDC_1_ARB"] = "ETH_USDC_1_ARB";
67
+ FluidArbitrumVersion["ETH_USDT_2_ARB"] = "ETH_USDT_2_ARB";
68
+ FluidArbitrumVersion["WSTETH_USDC_3_ARB"] = "WSTETH_USDC_3_ARB";
69
+ FluidArbitrumVersion["WSTETH_USDT_4_ARB"] = "WSTETH_USDT_4_ARB";
70
+ FluidArbitrumVersion["WSTETH_ETH_5_ARB"] = "WSTETH_ETH_5_ARB";
71
+ FluidArbitrumVersion["WEETH_WSTETH_6_ARB"] = "WEETH_WSTETH_6_ARB";
72
+ FluidArbitrumVersion["WEETH_USDC_7_ARB"] = "WEETH_USDC_7_ARB";
73
+ FluidArbitrumVersion["WEETH_USDT_8_ARB"] = "WEETH_USDT_8_ARB";
74
+ FluidArbitrumVersion["ETH_ARB_9_ARB"] = "ETH_ARB_9_ARB";
75
+ FluidArbitrumVersion["ARB_USDC_10_ARB"] = "ARB_USDC_10_ARB";
76
+ FluidArbitrumVersion["ARB_USDT_11_ARB"] = "ARB_USDT_11_ARB";
77
+ FluidArbitrumVersion["WSTETH_ETH_WSTETH_ETH_16_ARB"] = "WSTETH_ETH_WSTETH_ETH_16_ARB";
78
+ FluidArbitrumVersion["WEETH_ETH_WSTETH_17_ARB"] = "WEETH_ETH_WSTETH_17_ARB";
79
+ })(FluidArbitrumVersion || (exports.FluidArbitrumVersion = FluidArbitrumVersion = {}));
80
+ var FluidBaseVersions;
81
+ (function (FluidBaseVersions) {
82
+ FluidBaseVersions["ETH_USDC_1_BASE"] = "ETH_USDC_1_BASE";
83
+ FluidBaseVersions["WSTETH_USDC_2_BASE"] = "WSTETH_USDC_2_BASE";
84
+ FluidBaseVersions["WSTETH_ETH_3_BASE"] = "WSTETH_ETH_3_BASE";
85
+ FluidBaseVersions["WEETH_WSTETH_4_BASE"] = "WEETH_WSTETH_4_BASE";
86
+ FluidBaseVersions["WEETH_USDC_5_BASE"] = "WEETH_USDC_5_BASE";
87
+ FluidBaseVersions["CBETH_USDC_6_BASE"] = "CBETH_USDC_6_BASE";
88
+ FluidBaseVersions["CBBTC_USDC_7_BASE"] = "CBBTC_USDC_7_BASE";
89
+ FluidBaseVersions["CBBTC_EURC_8_BASE"] = "CBBTC_EURC_8_BASE";
90
+ FluidBaseVersions["CBETH_EURC_9_BASE"] = "CBETH_EURC_9_BASE";
91
+ FluidBaseVersions["ETH_EURC_10_BASE"] = "ETH_EURC_10_BASE";
92
+ FluidBaseVersions["WEETH_EURC_11_BASE"] = "WEETH_EURC_11_BASE";
93
+ FluidBaseVersions["WSTETH_EURC_12_BASE"] = "WSTETH_EURC_12_BASE";
94
+ FluidBaseVersions["CBBTC_ETH_13_BASE"] = "CBBTC_ETH_13_BASE";
95
+ FluidBaseVersions["ETH_CBBTC_14_BASE"] = "ETH_CBBTC_14_BASE";
96
+ FluidBaseVersions["WEETH_CBBTC_15_BASE"] = "WEETH_CBBTC_15_BASE";
97
+ FluidBaseVersions["WSTETH_CBBTC_16_BASE"] = "WSTETH_CBBTC_16_BASE";
98
+ })(FluidBaseVersions || (exports.FluidBaseVersions = FluidBaseVersions = {}));
99
+ var FluidMainnetDepositToken;
100
+ (function (FluidMainnetDepositToken) {
101
+ FluidMainnetDepositToken["ETH"] = "ETH";
102
+ FluidMainnetDepositToken["wstETH"] = "wstETH";
103
+ FluidMainnetDepositToken["USDC"] = "USDC";
104
+ FluidMainnetDepositToken["USDT"] = "USDT";
105
+ FluidMainnetDepositToken["GHO"] = "GHO";
106
+ })(FluidMainnetDepositToken || (exports.FluidMainnetDepositToken = FluidMainnetDepositToken = {}));
107
+ var FluidArbitrumDepositToken;
108
+ (function (FluidArbitrumDepositToken) {
109
+ FluidArbitrumDepositToken["ETH"] = "ETH";
110
+ FluidArbitrumDepositToken["wstETH"] = "wstETH";
111
+ FluidArbitrumDepositToken["USDC"] = "USDC";
112
+ FluidArbitrumDepositToken["USDT"] = "USDT";
113
+ FluidArbitrumDepositToken["ARB"] = "ARB";
114
+ })(FluidArbitrumDepositToken || (exports.FluidArbitrumDepositToken = FluidArbitrumDepositToken = {}));
115
+ var FluidBaseDepositToken;
116
+ (function (FluidBaseDepositToken) {
117
+ FluidBaseDepositToken["ETH"] = "ETH";
118
+ FluidBaseDepositToken["USDC"] = "USDC";
119
+ FluidBaseDepositToken["wstETH"] = "wstETH";
120
+ FluidBaseDepositToken["EURC"] = "EURC";
121
+ })(FluidBaseDepositToken || (exports.FluidBaseDepositToken = FluidBaseDepositToken = {}));
122
+ var FluidVaultType;
123
+ (function (FluidVaultType) {
124
+ FluidVaultType["T1"] = "T1";
125
+ FluidVaultType["T2"] = "T2";
126
+ FluidVaultType["T3"] = "T3";
127
+ FluidVaultType["T4"] = "T4";
128
+ FluidVaultType["Unknown"] = "Unknown";
129
+ })(FluidVaultType || (exports.FluidVaultType = FluidVaultType = {}));
@@ -9,3 +9,4 @@ export * from './chickenBonds';
9
9
  export * from './morphoBlue';
10
10
  export * from './llamaLend';
11
11
  export * from './euler';
12
+ export * from './fluid';
@@ -25,3 +25,4 @@ __exportStar(require("./chickenBonds"), exports);
25
25
  __exportStar(require("./morphoBlue"), exports);
26
26
  __exportStar(require("./llamaLend"), exports);
27
27
  __exportStar(require("./euler"), exports);
28
+ __exportStar(require("./fluid"), exports);
@@ -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
+ }
@@ -1104,5 +1104,11 @@ module.exports = {
1104
1104
  "networks": {
1105
1105
  "1": { "address": "0x8932E46Ecf96b5Fe033F5e27Ab6dC755Cb668967" }
1106
1106
  }
1107
+ },
1108
+ "FluidView": {
1109
+ "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" }],
1110
+ "networks": {
1111
+ "1": { "address": "0x72B2A658d2009fF3c3e133d3a042fFE705808aC5" }
1112
+ }
1107
1113
  }
1108
1114
  };
@@ -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/esm/contracts.js CHANGED
@@ -81,3 +81,4 @@ export const MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueVi
81
81
  export const LlamaLendViewContract = createContractFromConfigFunc('LlamaLendView');
82
82
  export const LiquityV2ViewContract = createContractFromConfigFunc('LiquityV2View');
83
83
  export const EulerV2ViewContract = createContractFromConfigFunc('EulerV2View');
84
+ export const 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,205 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Dec from 'decimal.js';
11
+ import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
12
+ import { NetworkNumber } from '../types/common';
13
+ import { FluidVaultType, } from '../types';
14
+ import { DFSFeedRegistryContract, FeedRegistryContract, FluidViewContract } from '../contracts';
15
+ import { getEthAmountForDecimals, isMainnetNetwork } from '../services/utils';
16
+ import { getFluidAggregatedData } from '../helpers/fluidHelpers';
17
+ import { chunkAndMulticall } from '../multicall';
18
+ import { getFluidMarketInfoById, getFluidVersionsDataForNetwork } from '../markets/fluid';
19
+ import { USD_QUOTE } from '../constants';
20
+ import { getChainlinkAssetAddress, getWstETHPrice } from '../services/priceService';
21
+ export const EMPTY_USED_ASSET = {
22
+ isSupplied: false,
23
+ isBorrowed: false,
24
+ supplied: '0',
25
+ suppliedUsd: '0',
26
+ borrowed: '0',
27
+ borrowedUsd: '0',
28
+ symbol: '',
29
+ collateral: false,
30
+ };
31
+ const parseVaultType = (vaultType) => {
32
+ switch (vaultType) {
33
+ case 10000: return FluidVaultType.T1;
34
+ case 20000: return FluidVaultType.T2;
35
+ case 30000: return FluidVaultType.T3;
36
+ case 40000: return FluidVaultType.T4;
37
+ default: return FluidVaultType.Unknown;
38
+ }
39
+ };
40
+ const parseMarketData = (web3, data, network) => __awaiter(void 0, void 0, void 0, function* () {
41
+ const collAsset = getAssetInfoByAddress(data.supplyToken0);
42
+ const debtAsset = getAssetInfoByAddress(data.borrowToken0);
43
+ const supplyRate = new Dec(data.supplyRateVault).div(100).toString();
44
+ const borrowRate = new Dec(data.borrowRateVault).div(100).toString();
45
+ const oracleScaleFactor = new Dec(27).add(debtAsset.decimals).sub(collAsset.decimals).toString();
46
+ const oracleScale = new Dec(10).pow(oracleScaleFactor).toString();
47
+ const oraclePrice = new Dec(data.oraclePriceOperate).div(oracleScale).toString();
48
+ const isTokenUSDA = debtAsset.symbol === 'USDA';
49
+ const isMainnet = isMainnetNetwork(network);
50
+ const loanTokenFeedAddress = getChainlinkAssetAddress(debtAsset.symbol, network);
51
+ let loanTokenPrice;
52
+ if (debtAsset.symbol === 'wstETH') {
53
+ // need to handle wstETH for l2s inside getWstETHPrice
54
+ loanTokenPrice = yield getWstETHPrice(web3);
55
+ }
56
+ else if (isMainnet) {
57
+ const feedRegistryContract = FeedRegistryContract(web3, NetworkNumber.Eth);
58
+ loanTokenPrice = isTokenUSDA ? '100000000' : yield feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, USD_QUOTE).call();
59
+ }
60
+ else {
61
+ // Currently only base network is supported
62
+ const feedRegistryContract = DFSFeedRegistryContract(web3, network);
63
+ const roundPriceData = isTokenUSDA ? { answer: '100000000' } : yield feedRegistryContract.methods.latestRoundData(loanTokenFeedAddress, USD_QUOTE).call();
64
+ loanTokenPrice = roundPriceData.answer;
65
+ }
66
+ const debtPriceParsed = new Dec(loanTokenPrice).div(1e8).toString();
67
+ const collAssetData = {
68
+ symbol: collAsset.symbol,
69
+ address: collAsset.address,
70
+ price: new Dec(debtPriceParsed).mul(oraclePrice).toString(),
71
+ totalSupply: data.totalSupplyVault,
72
+ totalBorrow: data.totalBorrowVault,
73
+ canBeSupplied: true,
74
+ canBeBorrowed: false,
75
+ supplyRate,
76
+ borrowRate: '0',
77
+ };
78
+ const debtAssetData = {
79
+ symbol: debtAsset.symbol,
80
+ address: debtAsset.address,
81
+ price: debtPriceParsed,
82
+ totalSupply: data.totalSupplyVault,
83
+ totalBorrow: data.totalBorrowVault,
84
+ canBeSupplied: false,
85
+ canBeBorrowed: true,
86
+ supplyRate: '0',
87
+ borrowRate,
88
+ };
89
+ const assetsData = {
90
+ [collAsset.symbol]: collAssetData,
91
+ [debtAsset.symbol]: debtAssetData,
92
+ };
93
+ const marketInfo = getFluidMarketInfoById(+data.vaultId, network);
94
+ const totalSupplyVault = getEthAmountForDecimals(data.totalSupplyVault, collAsset.decimals);
95
+ const totalBorrowVault = getEthAmountForDecimals(data.totalBorrowVault, debtAsset.decimals);
96
+ const liqRatio = new Dec(data.liquidationThreshold).div(100).toString();
97
+ const liqFactor = new Dec(data.liquidationThreshold).div(10000).toString();
98
+ const marketData = {
99
+ vaultId: +data.vaultId,
100
+ vaultValue: marketInfo === null || marketInfo === void 0 ? void 0 : marketInfo.value,
101
+ isSmartColl: data.isSmartColl,
102
+ isSmartDebt: data.isSmartDebt,
103
+ marketAddress: data.vault,
104
+ vaultType: parseVaultType(+data.vaultType),
105
+ oracle: data.oracle,
106
+ liquidationPenaltyPercent: new Dec(data.liquidationPenalty).div(100).toString(),
107
+ collFactor: new Dec(data.collateralFactor).div(10000).toString(),
108
+ liquidationRatio: liqRatio,
109
+ liqFactor,
110
+ minRatio: new Dec(1).div(liqFactor).mul(100).toString(),
111
+ collAsset0: collAsset.symbol,
112
+ debtAsset0: debtAsset.symbol,
113
+ totalPositions: data.totalPositions,
114
+ totalSupplyVault,
115
+ totalBorrowVault,
116
+ totalSupplyVaultUsd: new Dec(totalSupplyVault).mul(collAssetData.price).toString(),
117
+ totalBorrowVaultUsd: new Dec(totalSupplyVault).mul(debtAssetData.price).toString(),
118
+ withdrawalLimit: getEthAmountForDecimals(data.withdrawalLimit, collAsset.decimals),
119
+ withdrawableUntilLimit: getEthAmountForDecimals(data.withdrawableUntilLimit, collAsset.decimals),
120
+ withdrawable: getEthAmountForDecimals(data.withdrawable, collAsset.decimals),
121
+ borrowLimit: getEthAmountForDecimals(data.borrowLimit, debtAsset.decimals),
122
+ borrowableUntilLimit: getEthAmountForDecimals(data.borrowableUntilLimit, debtAsset.decimals),
123
+ borrowable: getEthAmountForDecimals(data.borrowable, debtAsset.decimals),
124
+ borrowLimitUtilization: getEthAmountForDecimals(data.borrowLimitUtilization, debtAsset.decimals),
125
+ maxBorrowLimit: getEthAmountForDecimals(data.maxBorrowLimit, debtAsset.decimals),
126
+ baseBorrowLimit: getEthAmountForDecimals(data.baseBorrowLimit, debtAsset.decimals),
127
+ minimumBorrowing: getEthAmountForDecimals(data.minimumBorrowing, debtAsset.decimals),
128
+ borrowRate,
129
+ supplyRate,
130
+ };
131
+ return {
132
+ assetsData,
133
+ marketData,
134
+ };
135
+ });
136
+ export const EMPTY_FLUID_DATA = {
137
+ usedAssets: {},
138
+ suppliedUsd: '0',
139
+ borrowedUsd: '0',
140
+ borrowLimitUsd: '0',
141
+ leftToBorrowUsd: '0',
142
+ ratio: '0',
143
+ minRatio: '0',
144
+ netApy: '0',
145
+ incentiveUsd: '0',
146
+ totalInterestUsd: '0',
147
+ isSubscribedToAutomation: false,
148
+ automationResubscribeRequired: false,
149
+ lastUpdated: Date.now(),
150
+ };
151
+ const parseUserData = (userPositionData, vaultData) => {
152
+ const { assetsData, marketData, } = vaultData;
153
+ const payload = Object.assign(Object.assign({ owner: userPositionData.owner, vaultId: marketData.vaultId }, EMPTY_FLUID_DATA), { lastUpdated: Date.now() });
154
+ const collAsset = getAssetInfo(marketData.collAsset0);
155
+ const debtAsset = getAssetInfo(marketData.debtAsset0);
156
+ const supplied = getEthAmountForDecimals(userPositionData.supply, collAsset.decimals);
157
+ const borrowed = getEthAmountForDecimals(userPositionData.borrow, debtAsset.decimals);
158
+ const collUsedAsset = Object.assign(Object.assign({}, EMPTY_USED_ASSET), { symbol: collAsset.symbol, collateral: true, supplied, suppliedUsd: new Dec(supplied).mul(assetsData[collAsset.symbol].price).toString(), isSupplied: new Dec(supplied).gt(0) });
159
+ const debtUsedAsset = Object.assign(Object.assign({}, EMPTY_USED_ASSET), { symbol: debtAsset.symbol, collateral: false, borrowed, borrowedUsd: new Dec(borrowed).mul(assetsData[debtAsset.symbol].price).toString(), isBorrowed: new Dec(borrowed).gt(0) });
160
+ const usedAssets = {
161
+ [collAsset.symbol]: collUsedAsset,
162
+ [debtAsset.symbol]: debtUsedAsset,
163
+ };
164
+ return Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), getFluidAggregatedData({
165
+ usedAssets,
166
+ assetsData,
167
+ marketData,
168
+ }));
169
+ };
170
+ export const getFluidMarketData = (web3, network, market) => __awaiter(void 0, void 0, void 0, function* () {
171
+ const view = FluidViewContract(web3, network);
172
+ const data = yield view.methods.getVaultData(market.marketAddress).call();
173
+ return parseMarketData(web3, data, network);
174
+ });
175
+ export const getFluidVaultIdsForUser = (web3, network, user) => __awaiter(void 0, void 0, void 0, function* () {
176
+ const view = FluidViewContract(web3, network);
177
+ return view.methods.getUserNftIds(user).call();
178
+ });
179
+ export const getFluidPosition = (web3, network, vaultId, extractedState) => __awaiter(void 0, void 0, void 0, function* () {
180
+ const view = FluidViewContract(web3, network);
181
+ const data = yield view.methods.getPositionByNftId(vaultId).call();
182
+ const userPositionData = data[0];
183
+ return parseUserData(userPositionData, extractedState);
184
+ });
185
+ export const getFluidPositionWithMarket = (web3, network, vaultId) => __awaiter(void 0, void 0, void 0, function* () {
186
+ const view = FluidViewContract(web3, network);
187
+ const data = yield view.methods.getPositionByNftId(vaultId).call();
188
+ const marketData = yield parseMarketData(web3, data.vault, network);
189
+ const userData = parseUserData(data.position, marketData);
190
+ return {
191
+ userData,
192
+ marketData,
193
+ };
194
+ });
195
+ export const getAllFluidMarketDataChunked = (network, web3) => __awaiter(void 0, void 0, void 0, function* () {
196
+ const versions = getFluidVersionsDataForNetwork(network);
197
+ const view = FluidViewContract(web3, network);
198
+ const calls = versions.map((version) => ({
199
+ target: view.options.address,
200
+ abiItem: view.options.jsonInterface.find((item) => item.name === 'getVaultData'),
201
+ params: [version.marketAddress],
202
+ }));
203
+ const data = yield chunkAndMulticall(calls, 10, 'latest', web3, network);
204
+ return Promise.all(data.map((item, i) => __awaiter(void 0, void 0, void 0, function* () { return parseMarketData(web3, item.vaultData, network); })));
205
+ });
@@ -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,33 @@
1
+ import Dec from 'decimal.js';
2
+ import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
3
+ import { calculateNetApy } from '../../staking';
4
+ export const getFluidAggregatedData = ({ usedAssets, assetsData, marketData, }) => {
5
+ const payload = {};
6
+ payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
7
+ payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
8
+ const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({ usedAssets, assetsData: assetsData });
9
+ payload.netApy = netApy;
10
+ payload.incentiveUsd = incentiveUsd;
11
+ payload.totalInterestUsd = totalInterestUsd;
12
+ const collFactor = marketData.collFactor;
13
+ const liqRatio = marketData.liquidationRatio;
14
+ payload.borrowLimitUsd = new Dec(payload.suppliedUsd).mul(collFactor).toString();
15
+ payload.liquidationLimitUsd = new Dec(payload.suppliedUsd).mul(liqRatio).div(100).toString();
16
+ const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
17
+ payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
18
+ payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
19
+ payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
20
+ const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
21
+ payload.leveragedType = leveragedType;
22
+ if (leveragedType !== '') {
23
+ payload.leveragedAsset = leveragedAsset;
24
+ let assetPrice = assetsData[leveragedAsset].price;
25
+ if (leveragedType === 'lsd-leverage') {
26
+ // Treat ETH like a stablecoin in a long stETH position
27
+ payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
28
+ assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
29
+ }
30
+ payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
31
+ }
32
+ return payload;
33
+ };
@@ -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';
@@ -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';