@defisaver/positions-sdk 1.0.11-dev → 1.0.11-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 (109) 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 +113 -49
  5. package/cjs/config/contracts.js +10 -2
  6. package/cjs/contracts.d.ts +1 -0
  7. package/cjs/contracts.js +2 -1
  8. package/cjs/fluid/index.d.ts +2 -0
  9. package/cjs/fluid/index.js +636 -13
  10. package/cjs/helpers/fluidHelpers/index.d.ts +59 -2
  11. package/cjs/helpers/fluidHelpers/index.js +142 -4
  12. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  13. package/cjs/markets/fluid/index.js +276 -245
  14. package/cjs/services/priceService.d.ts +23 -0
  15. package/cjs/services/priceService.js +44 -5
  16. package/cjs/types/contracts/generated/FluidView.d.ts +220 -3
  17. package/cjs/types/contracts/generated/WeETHPriceFeed.d.ts +135 -0
  18. package/cjs/types/contracts/generated/WeETHPriceFeed.js +5 -0
  19. package/cjs/types/contracts/generated/index.d.ts +1 -0
  20. package/cjs/types/fluid.d.ts +39 -10
  21. package/esm/config/contracts.d.ts +113 -49
  22. package/esm/config/contracts.js +10 -2
  23. package/esm/contracts.d.ts +1 -0
  24. package/esm/contracts.js +1 -0
  25. package/esm/fluid/index.d.ts +2 -0
  26. package/esm/fluid/index.js +639 -16
  27. package/esm/helpers/fluidHelpers/index.d.ts +59 -2
  28. package/esm/helpers/fluidHelpers/index.js +137 -3
  29. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  30. package/esm/markets/fluid/index.js +276 -245
  31. package/esm/services/priceService.d.ts +23 -0
  32. package/esm/services/priceService.js +40 -5
  33. package/esm/types/contracts/generated/FluidView.d.ts +220 -3
  34. package/esm/types/contracts/generated/WeETHPriceFeed.d.ts +135 -0
  35. package/esm/types/contracts/generated/WeETHPriceFeed.js +4 -0
  36. package/esm/types/contracts/generated/index.d.ts +1 -0
  37. package/esm/types/fluid.d.ts +39 -10
  38. package/package.json +54 -54
  39. package/src/aaveV2/index.ts +227 -227
  40. package/src/aaveV3/index.ts +624 -624
  41. package/src/assets/index.ts +60 -60
  42. package/src/chickenBonds/index.ts +123 -123
  43. package/src/compoundV2/index.ts +220 -220
  44. package/src/compoundV3/index.ts +291 -291
  45. package/src/config/contracts.js +1155 -1147
  46. package/src/constants/index.ts +6 -6
  47. package/src/contracts.ts +135 -134
  48. package/src/curveUsd/index.ts +239 -239
  49. package/src/eulerV2/index.ts +303 -303
  50. package/src/exchange/index.ts +17 -17
  51. package/src/fluid/index.ts +1216 -354
  52. package/src/helpers/aaveHelpers/index.ts +203 -203
  53. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  54. package/src/helpers/compoundHelpers/index.ts +248 -248
  55. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  56. package/src/helpers/eulerHelpers/index.ts +234 -234
  57. package/src/helpers/fluidHelpers/index.ts +295 -57
  58. package/src/helpers/index.ts +11 -11
  59. package/src/helpers/liquityV2Helpers/index.ts +80 -80
  60. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  61. package/src/helpers/makerHelpers/index.ts +94 -94
  62. package/src/helpers/morphoBlueHelpers/index.ts +367 -367
  63. package/src/helpers/sparkHelpers/index.ts +154 -154
  64. package/src/index.ts +52 -52
  65. package/src/liquity/index.ts +116 -116
  66. package/src/liquityV2/index.ts +295 -295
  67. package/src/llamaLend/index.ts +275 -275
  68. package/src/maker/index.ts +117 -117
  69. package/src/markets/aave/index.ts +152 -152
  70. package/src/markets/aave/marketAssets.ts +46 -46
  71. package/src/markets/compound/index.ts +213 -213
  72. package/src/markets/compound/marketsAssets.ts +82 -82
  73. package/src/markets/curveUsd/index.ts +69 -69
  74. package/src/markets/euler/index.ts +26 -26
  75. package/src/markets/fluid/index.ts +2043 -2012
  76. package/src/markets/index.ts +27 -27
  77. package/src/markets/liquityV2/index.ts +54 -54
  78. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  79. package/src/markets/llamaLend/index.ts +235 -235
  80. package/src/markets/morphoBlue/index.ts +895 -895
  81. package/src/markets/spark/index.ts +29 -29
  82. package/src/markets/spark/marketAssets.ts +10 -10
  83. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  84. package/src/morphoAaveV2/index.ts +256 -256
  85. package/src/morphoAaveV3/index.ts +630 -630
  86. package/src/morphoBlue/index.ts +202 -202
  87. package/src/multicall/index.ts +33 -33
  88. package/src/services/priceService.ts +130 -91
  89. package/src/services/utils.ts +59 -59
  90. package/src/setup.ts +8 -8
  91. package/src/spark/index.ts +460 -460
  92. package/src/staking/staking.ts +217 -217
  93. package/src/types/aave.ts +275 -275
  94. package/src/types/chickenBonds.ts +45 -45
  95. package/src/types/common.ts +84 -84
  96. package/src/types/compound.ts +133 -133
  97. package/src/types/contracts/generated/FluidView.ts +263 -2
  98. package/src/types/contracts/generated/WeETHPriceFeed.ts +202 -0
  99. package/src/types/contracts/generated/index.ts +1 -0
  100. package/src/types/curveUsd.ts +119 -119
  101. package/src/types/euler.ts +173 -173
  102. package/src/types/fluid.ts +299 -268
  103. package/src/types/index.ts +11 -11
  104. package/src/types/liquity.ts +30 -30
  105. package/src/types/liquityV2.ts +119 -119
  106. package/src/types/llamaLend.ts +155 -155
  107. package/src/types/maker.ts +50 -50
  108. package/src/types/morphoBlue.ts +194 -194
  109. package/src/types/spark.ts +135 -135
@@ -1,95 +1,95 @@
1
- import Web3 from 'web3';
2
- import Dec from 'decimal.js';
3
- import { Blockish, NetworkNumber } from '../../types/common';
4
- import {
5
- McdDogContract, McdJugContract, McdSpotterContract, McdVatContract,
6
- } from '../../contracts';
7
- import { multicall } from '../../multicall';
8
- import { SECONDS_PER_YEAR } from '../../constants';
9
- import { bytesToString } from '../../services/utils';
10
- import { IlkInfo } from '../../types';
11
-
12
- export const getUnclaimedCollateral = async (web3: Web3, network: NetworkNumber, urn: string, ilk: string) => {
13
- const vatContract = McdVatContract(web3, network);
14
- const coll = await vatContract.methods.gem(ilk, urn).call();
15
- return coll;
16
- };
17
-
18
- export const getCollateralInfo = async (ilk: string, web3: Web3, network: NetworkNumber, block: Blockish = 'latest'): Promise<IlkInfo> => {
19
- const spotterContract = McdSpotterContract(web3, network);
20
- const vatContract = McdVatContract(web3, network);
21
- const dogContract = McdDogContract(web3, network);
22
- const jugContract = McdJugContract(web3, network);
23
-
24
- const multicallData = [
25
- {
26
- target: spotterContract.options.address,
27
- abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'par'),
28
- params: [],
29
- },
30
- {
31
- target: spotterContract.options.address,
32
- abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
33
- params: [ilk],
34
- },
35
- {
36
- target: vatContract.options.address,
37
- abiItem: vatContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
38
- params: [ilk],
39
- },
40
- {
41
- target: jugContract.options.address,
42
- abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
43
- params: [ilk],
44
- },
45
- {
46
- target: jugContract.options.address,
47
- abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'drip'),
48
- params: [ilk],
49
- },
50
- {
51
- target: dogContract.options.address,
52
- abiItem: dogContract.options.jsonInterface.find(({ name }) => name === 'chop'),
53
- params: [ilk],
54
- },
55
- ];
56
-
57
- const multiRes = await multicall(multicallData, web3, network, block);
58
-
59
- const par = new Dec(multiRes[0][0].toString()).div(1e27).toString();
60
- const mat = new Dec(multiRes[1][1].toString()).div(1e27).toString();
61
- const art = new Dec(multiRes[2][0].toString()).toString();
62
- const rate = new Dec(multiRes[2][1].toString()).toString();
63
- const spot = new Dec(multiRes[2][2].toString()).div(1e27).toString();
64
- const line = new Dec(multiRes[2][3].toString()).div(1e45).toString();
65
- const dust = new Dec(multiRes[2][1].toString()).div(1e45).toString();
66
- const duty = new Dec(multiRes[3][0].toString()).toString();
67
- const futureRate = new Dec(multiRes[4][0].toString()).toString();
68
- const chop = new Dec(multiRes[5][0].toString()).div(1e18).toString();
69
-
70
- const stabilityFee = new Dec(duty.toString())
71
- .div(1e27)
72
- .pow(SECONDS_PER_YEAR)
73
- .minus(1)
74
- .mul(100)
75
- .toNumber();
76
- const liquidationFee = new Dec(chop).mul(100).sub(100).toString();
77
- const globalDebtCurrent = new Dec(art).div(1e18).mul(new Dec(futureRate).div(1e27)).toString();
78
- const globalDebtCeiling = line;
79
- const creatableDebt = new Dec(globalDebtCeiling).sub(globalDebtCurrent).toString();
80
-
81
- return {
82
- ilkLabel: bytesToString(ilk),
83
- currentRate: rate,
84
- futureRate,
85
- minDebt: dust,
86
- globalDebtCurrent,
87
- globalDebtCeiling,
88
- assetPrice: new Dec(spot).times(par).times(mat).toString(),
89
- liqRatio: mat,
90
- liqPercent: +mat * 100,
91
- stabilityFee,
92
- liquidationFee: new Dec(liquidationFee).lt(0) ? '0' : liquidationFee,
93
- creatableDebt,
94
- };
1
+ import Web3 from 'web3';
2
+ import Dec from 'decimal.js';
3
+ import { Blockish, NetworkNumber } from '../../types/common';
4
+ import {
5
+ McdDogContract, McdJugContract, McdSpotterContract, McdVatContract,
6
+ } from '../../contracts';
7
+ import { multicall } from '../../multicall';
8
+ import { SECONDS_PER_YEAR } from '../../constants';
9
+ import { bytesToString } from '../../services/utils';
10
+ import { IlkInfo } from '../../types';
11
+
12
+ export const getUnclaimedCollateral = async (web3: Web3, network: NetworkNumber, urn: string, ilk: string) => {
13
+ const vatContract = McdVatContract(web3, network);
14
+ const coll = await vatContract.methods.gem(ilk, urn).call();
15
+ return coll;
16
+ };
17
+
18
+ export const getCollateralInfo = async (ilk: string, web3: Web3, network: NetworkNumber, block: Blockish = 'latest'): Promise<IlkInfo> => {
19
+ const spotterContract = McdSpotterContract(web3, network);
20
+ const vatContract = McdVatContract(web3, network);
21
+ const dogContract = McdDogContract(web3, network);
22
+ const jugContract = McdJugContract(web3, network);
23
+
24
+ const multicallData = [
25
+ {
26
+ target: spotterContract.options.address,
27
+ abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'par'),
28
+ params: [],
29
+ },
30
+ {
31
+ target: spotterContract.options.address,
32
+ abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
33
+ params: [ilk],
34
+ },
35
+ {
36
+ target: vatContract.options.address,
37
+ abiItem: vatContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
38
+ params: [ilk],
39
+ },
40
+ {
41
+ target: jugContract.options.address,
42
+ abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
43
+ params: [ilk],
44
+ },
45
+ {
46
+ target: jugContract.options.address,
47
+ abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'drip'),
48
+ params: [ilk],
49
+ },
50
+ {
51
+ target: dogContract.options.address,
52
+ abiItem: dogContract.options.jsonInterface.find(({ name }) => name === 'chop'),
53
+ params: [ilk],
54
+ },
55
+ ];
56
+
57
+ const multiRes = await multicall(multicallData, web3, network, block);
58
+
59
+ const par = new Dec(multiRes[0][0].toString()).div(1e27).toString();
60
+ const mat = new Dec(multiRes[1][1].toString()).div(1e27).toString();
61
+ const art = new Dec(multiRes[2][0].toString()).toString();
62
+ const rate = new Dec(multiRes[2][1].toString()).toString();
63
+ const spot = new Dec(multiRes[2][2].toString()).div(1e27).toString();
64
+ const line = new Dec(multiRes[2][3].toString()).div(1e45).toString();
65
+ const dust = new Dec(multiRes[2][1].toString()).div(1e45).toString();
66
+ const duty = new Dec(multiRes[3][0].toString()).toString();
67
+ const futureRate = new Dec(multiRes[4][0].toString()).toString();
68
+ const chop = new Dec(multiRes[5][0].toString()).div(1e18).toString();
69
+
70
+ const stabilityFee = new Dec(duty.toString())
71
+ .div(1e27)
72
+ .pow(SECONDS_PER_YEAR)
73
+ .minus(1)
74
+ .mul(100)
75
+ .toNumber();
76
+ const liquidationFee = new Dec(chop).mul(100).sub(100).toString();
77
+ const globalDebtCurrent = new Dec(art).div(1e18).mul(new Dec(futureRate).div(1e27)).toString();
78
+ const globalDebtCeiling = line;
79
+ const creatableDebt = new Dec(globalDebtCeiling).sub(globalDebtCurrent).toString();
80
+
81
+ return {
82
+ ilkLabel: bytesToString(ilk),
83
+ currentRate: rate,
84
+ futureRate,
85
+ minDebt: dust,
86
+ globalDebtCurrent,
87
+ globalDebtCeiling,
88
+ assetPrice: new Dec(spot).times(par).times(mat).toString(),
89
+ liqRatio: mat,
90
+ liqPercent: +mat * 100,
91
+ stabilityFee,
92
+ liquidationFee: new Dec(liquidationFee).lt(0) ? '0' : liquidationFee,
93
+ creatableDebt,
94
+ };
95
95
  };