@defisaver/positions-sdk 0.0.166-dev4-liquity-v2 → 0.0.166-dev4

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 (142) 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 +32 -3
  5. package/cjs/config/contracts.js +3 -3
  6. package/cjs/contracts.d.ts +1 -1
  7. package/cjs/contracts.js +2 -2
  8. package/cjs/eulerV2/index.d.ts +41 -0
  9. package/cjs/eulerV2/index.js +218 -0
  10. package/cjs/helpers/eulerHelpers/index.d.ts +27 -0
  11. package/cjs/helpers/eulerHelpers/index.js +232 -0
  12. package/cjs/helpers/index.d.ts +1 -1
  13. package/cjs/helpers/index.js +2 -2
  14. package/cjs/index.d.ts +2 -2
  15. package/cjs/index.js +3 -3
  16. package/cjs/markets/euler/index.d.ts +8 -0
  17. package/cjs/markets/euler/index.js +30 -0
  18. package/cjs/markets/index.d.ts +1 -1
  19. package/cjs/markets/index.js +3 -3
  20. package/cjs/moneymarket/moneymarketCommonService.js +1 -1
  21. package/cjs/services/utils.d.ts +2 -0
  22. package/cjs/services/utils.js +4 -1
  23. package/cjs/types/contracts/generated/EulerV2View.d.ts +345 -0
  24. package/cjs/types/contracts/generated/index.d.ts +1 -1
  25. package/cjs/types/euler.d.ts +149 -0
  26. package/cjs/types/euler.js +14 -0
  27. package/cjs/types/index.d.ts +1 -1
  28. package/cjs/types/index.js +1 -1
  29. package/esm/config/contracts.d.ts +32 -3
  30. package/esm/config/contracts.js +3 -3
  31. package/esm/contracts.d.ts +1 -1
  32. package/esm/contracts.js +1 -1
  33. package/esm/eulerV2/index.d.ts +41 -0
  34. package/esm/eulerV2/index.js +210 -0
  35. package/esm/helpers/eulerHelpers/index.d.ts +27 -0
  36. package/esm/helpers/eulerHelpers/index.js +219 -0
  37. package/esm/helpers/index.d.ts +1 -1
  38. package/esm/helpers/index.js +1 -1
  39. package/esm/index.d.ts +2 -2
  40. package/esm/index.js +2 -2
  41. package/esm/markets/euler/index.d.ts +8 -0
  42. package/esm/markets/euler/index.js +24 -0
  43. package/esm/markets/index.d.ts +1 -1
  44. package/esm/markets/index.js +1 -1
  45. package/esm/moneymarket/moneymarketCommonService.js +1 -1
  46. package/esm/services/utils.d.ts +2 -0
  47. package/esm/services/utils.js +2 -0
  48. package/esm/types/contracts/generated/EulerV2View.d.ts +345 -0
  49. package/esm/types/contracts/generated/index.d.ts +1 -1
  50. package/esm/types/euler.d.ts +149 -0
  51. package/esm/types/euler.js +11 -0
  52. package/esm/types/index.d.ts +1 -1
  53. package/esm/types/index.js +1 -1
  54. package/package.json +49 -49
  55. package/src/aaveV2/index.ts +227 -227
  56. package/src/aaveV3/index.ts +590 -590
  57. package/src/assets/index.ts +60 -60
  58. package/src/chickenBonds/index.ts +123 -123
  59. package/src/compoundV2/index.ts +219 -219
  60. package/src/compoundV3/index.ts +281 -281
  61. package/src/config/contracts.js +1040 -1040
  62. package/src/constants/index.ts +6 -6
  63. package/src/contracts.ts +130 -130
  64. package/src/curveUsd/index.ts +229 -229
  65. package/src/eulerV2/index.ts +301 -0
  66. package/src/exchange/index.ts +17 -17
  67. package/src/helpers/aaveHelpers/index.ts +194 -194
  68. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  69. package/src/helpers/compoundHelpers/index.ts +246 -246
  70. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  71. package/src/helpers/eulerHelpers/index.ts +231 -0
  72. package/src/helpers/index.ts +9 -9
  73. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  74. package/src/helpers/makerHelpers/index.ts +94 -94
  75. package/src/helpers/morphoBlueHelpers/index.ts +115 -115
  76. package/src/helpers/sparkHelpers/index.ts +150 -150
  77. package/src/index.ts +48 -48
  78. package/src/liquity/index.ts +116 -116
  79. package/src/llamaLend/index.ts +275 -275
  80. package/src/maker/index.ts +117 -117
  81. package/src/markets/aave/index.ts +152 -152
  82. package/src/markets/aave/marketAssets.ts +46 -46
  83. package/src/markets/compound/index.ts +173 -173
  84. package/src/markets/compound/marketsAssets.ts +64 -64
  85. package/src/markets/curveUsd/index.ts +69 -69
  86. package/src/markets/euler/index.ts +27 -0
  87. package/src/markets/index.ts +24 -23
  88. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  89. package/src/markets/llamaLend/index.ts +235 -235
  90. package/src/markets/morphoBlue/index.ts +728 -728
  91. package/src/markets/spark/index.ts +29 -29
  92. package/src/markets/spark/marketAssets.ts +10 -10
  93. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  94. package/src/morphoAaveV2/index.ts +256 -256
  95. package/src/morphoAaveV3/index.ts +630 -630
  96. package/src/morphoBlue/index.ts +171 -171
  97. package/src/multicall/index.ts +22 -22
  98. package/src/services/dsrService.ts +15 -15
  99. package/src/services/priceService.ts +21 -21
  100. package/src/services/utils.ts +57 -54
  101. package/src/setup.ts +8 -8
  102. package/src/spark/index.ts +424 -424
  103. package/src/staking/staking.ts +218 -218
  104. package/src/types/aave.ts +262 -262
  105. package/src/types/chickenBonds.ts +45 -45
  106. package/src/types/common.ts +84 -84
  107. package/src/types/compound.ts +129 -129
  108. package/src/types/contracts/generated/EulerV2View.ts +446 -0
  109. package/src/types/contracts/generated/index.ts +1 -1
  110. package/src/types/curveUsd.ts +118 -118
  111. package/src/types/euler.ts +172 -0
  112. package/src/types/index.ts +10 -10
  113. package/src/types/liquity.ts +30 -30
  114. package/src/types/llamaLend.ts +155 -155
  115. package/src/types/maker.ts +50 -50
  116. package/src/types/morphoBlue.ts +146 -146
  117. package/src/types/spark.ts +127 -127
  118. package/cjs/helpers/liquityV2Helpers/index.d.ts +0 -12
  119. package/cjs/helpers/liquityV2Helpers/index.js +0 -62
  120. package/cjs/liquityV2/index.d.ts +0 -10
  121. package/cjs/liquityV2/index.js +0 -99
  122. package/cjs/markets/liquityV2/index.d.ts +0 -8
  123. package/cjs/markets/liquityV2/index.js +0 -34
  124. package/cjs/types/contracts/generated/LiquityV2View.d.ts +0 -222
  125. package/cjs/types/liquityV2.d.ts +0 -84
  126. package/cjs/types/liquityV2.js +0 -8
  127. package/esm/helpers/liquityV2Helpers/index.d.ts +0 -12
  128. package/esm/helpers/liquityV2Helpers/index.js +0 -54
  129. package/esm/liquityV2/index.d.ts +0 -10
  130. package/esm/liquityV2/index.js +0 -91
  131. package/esm/markets/liquityV2/index.d.ts +0 -8
  132. package/esm/markets/liquityV2/index.js +0 -28
  133. package/esm/types/contracts/generated/LiquityV2View.d.ts +0 -222
  134. package/esm/types/liquityV2.d.ts +0 -84
  135. package/esm/types/liquityV2.js +0 -5
  136. package/src/helpers/liquityV2Helpers/index.ts +0 -79
  137. package/src/liquityV2/index.ts +0 -116
  138. package/src/markets/liquityV2/index.ts +0 -31
  139. package/src/types/contracts/generated/LiquityV2View.ts +0 -280
  140. package/src/types/liquityV2.ts +0 -90
  141. /package/cjs/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
  142. /package/esm/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
@@ -1,117 +1,117 @@
1
- import Web3 from 'web3';
2
- import Dec from 'decimal.js';
3
- import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
4
- import {
5
- Blockish, EthAddress, NetworkNumber, PositionBalances,
6
- } from '../types/common';
7
- import {
8
- LiquityActivePoolContract, LiquityCollSurplusPoolContract, LiquityPriceFeedContract, LiquityTroveManagerContract, LiquityViewContract,
9
- } from '../contracts';
10
- import { multicall } from '../multicall';
11
- import { LIQUITY_TROVE_STATUS_ENUM, LiquityTroveInfo } from '../types';
12
- import { ZERO_ADDRESS } from '../constants';
13
-
14
- export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
15
- export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
16
-
17
- export const getLiquityAccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
18
- let balances: PositionBalances = {
19
- collateral: {},
20
- debt: {},
21
- };
22
-
23
- if (!address) {
24
- return balances;
25
- }
26
-
27
- const viewContract = LiquityViewContract(web3, network, block);
28
- const troveInfo = await viewContract.methods.getTroveInfo(address).call({}, block);
29
-
30
- balances = {
31
- collateral: {
32
- [addressMapping ? getAssetInfo('ETH', network).address.toLowerCase() : 'ETH']: troveInfo[1],
33
- },
34
- debt: {
35
- [addressMapping ? getAssetInfo('LUSD', network).address.toLowerCase() : 'LUSD']: troveInfo[2],
36
- },
37
- };
38
-
39
- return balances;
40
- };
41
-
42
- const _getDebtInFront = async (viewContract: any, address: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(address, accumulatedSum, iterations).call();
43
-
44
- export const getDebtInFront = async (viewContract: any, address: string, accumulatedSum = '0', iterations = 2000): Promise<string> => {
45
- const { debt, next } = await _getDebtInFront(viewContract, address, accumulatedSum, iterations);
46
- if (next === ZERO_ADDRESS) return assetAmountInEth(debt, 'LUSD');
47
- return getDebtInFront(viewContract, next, debt, iterations);
48
- };
49
-
50
- export const getLiquityTroveInfo = async (web3: Web3, network: NetworkNumber, address: string): Promise<LiquityTroveInfo> => {
51
- const viewContract = LiquityViewContract(web3, network);
52
- const collSurplusPoolContract = LiquityCollSurplusPoolContract(web3, network);
53
- const troveManagerContract = LiquityTroveManagerContract(web3, network);
54
- const priceFeedContract = LiquityPriceFeedContract(web3, network);
55
- const activePoolContract = LiquityActivePoolContract(web3, network);
56
-
57
- const multicallData = [
58
- {
59
- target: viewContract.options.address,
60
- abiItem: viewContract.options.jsonInterface.find(({ name }) => name === 'getTroveInfo'),
61
- params: [address],
62
- },
63
- {
64
- target: collSurplusPoolContract.options.address,
65
- abiItem: collSurplusPoolContract.options.jsonInterface.find(({ name }) => name === 'getCollateral'),
66
- params: [address],
67
- },
68
- {
69
- target: troveManagerContract.options.address,
70
- abiItem: troveManagerContract.options.jsonInterface.find(({ name }) => name === 'getBorrowingRateWithDecay'),
71
- params: [],
72
- },
73
- {
74
- target: priceFeedContract.options.address,
75
- abiItem: priceFeedContract.options.jsonInterface.find(({ name }) => name === 'fetchPrice'),
76
- params: [],
77
- },
78
- {
79
- target: activePoolContract.options.address,
80
- abiItem: activePoolContract.options.jsonInterface.find(({ name }) => name === 'getETH'),
81
- params: [],
82
- },
83
- {
84
- target: activePoolContract.options.address,
85
- abiItem: activePoolContract.options.jsonInterface.find(({ name }) => name === 'getLUSDDebt'),
86
- params: [],
87
- },
88
- ];
89
-
90
- const [multiRes, debtInFront] = await Promise.all([
91
- multicall(multicallData, web3, network),
92
- getDebtInFront(viewContract, address),
93
- ]);
94
-
95
- const recoveryMode = multiRes[0][6];
96
- const totalETH = multiRes[4][0];
97
- const totalLUSD = multiRes[5][0];
98
-
99
- const payload = {
100
- troveStatus: LIQUITY_TROVE_STATUS_ENUM[+multiRes[0][0].toString()],
101
- collateral: assetAmountInEth(multiRes[0][1]),
102
- debtInAsset: assetAmountInEth(multiRes[0][2]),
103
- TCRatio: assetAmountInEth(multiRes[0][4]),
104
- recoveryMode,
105
- claimableCollateral: assetAmountInEth(multiRes[1][0]),
106
- borrowingRateWithDecay: assetAmountInEth(multiRes[2][0]),
107
- assetPrice: assetAmountInEth(multiRes[3][0]),
108
- totalETH,
109
- totalLUSD,
110
- debtInFront,
111
- minCollateralRatio: recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO,
112
- priceForRecovery: new Dec(recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO).mul(totalLUSD).div(totalETH).div(100)
113
- .toString(),
114
- };
115
-
116
- return payload;
1
+ import Web3 from 'web3';
2
+ import Dec from 'decimal.js';
3
+ import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
4
+ import {
5
+ Blockish, EthAddress, NetworkNumber, PositionBalances,
6
+ } from '../types/common';
7
+ import {
8
+ LiquityActivePoolContract, LiquityCollSurplusPoolContract, LiquityPriceFeedContract, LiquityTroveManagerContract, LiquityViewContract,
9
+ } from '../contracts';
10
+ import { multicall } from '../multicall';
11
+ import { LIQUITY_TROVE_STATUS_ENUM, LiquityTroveInfo } from '../types';
12
+ import { ZERO_ADDRESS } from '../constants';
13
+
14
+ export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
15
+ export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
16
+
17
+ export const getLiquityAccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
18
+ let balances: PositionBalances = {
19
+ collateral: {},
20
+ debt: {},
21
+ };
22
+
23
+ if (!address) {
24
+ return balances;
25
+ }
26
+
27
+ const viewContract = LiquityViewContract(web3, network, block);
28
+ const troveInfo = await viewContract.methods.getTroveInfo(address).call({}, block);
29
+
30
+ balances = {
31
+ collateral: {
32
+ [addressMapping ? getAssetInfo('ETH', network).address.toLowerCase() : 'ETH']: troveInfo[1],
33
+ },
34
+ debt: {
35
+ [addressMapping ? getAssetInfo('LUSD', network).address.toLowerCase() : 'LUSD']: troveInfo[2],
36
+ },
37
+ };
38
+
39
+ return balances;
40
+ };
41
+
42
+ const _getDebtInFront = async (viewContract: any, address: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(address, accumulatedSum, iterations).call();
43
+
44
+ export const getDebtInFront = async (viewContract: any, address: string, accumulatedSum = '0', iterations = 2000): Promise<string> => {
45
+ const { debt, next } = await _getDebtInFront(viewContract, address, accumulatedSum, iterations);
46
+ if (next === ZERO_ADDRESS) return assetAmountInEth(debt, 'LUSD');
47
+ return getDebtInFront(viewContract, next, debt, iterations);
48
+ };
49
+
50
+ export const getLiquityTroveInfo = async (web3: Web3, network: NetworkNumber, address: string): Promise<LiquityTroveInfo> => {
51
+ const viewContract = LiquityViewContract(web3, network);
52
+ const collSurplusPoolContract = LiquityCollSurplusPoolContract(web3, network);
53
+ const troveManagerContract = LiquityTroveManagerContract(web3, network);
54
+ const priceFeedContract = LiquityPriceFeedContract(web3, network);
55
+ const activePoolContract = LiquityActivePoolContract(web3, network);
56
+
57
+ const multicallData = [
58
+ {
59
+ target: viewContract.options.address,
60
+ abiItem: viewContract.options.jsonInterface.find(({ name }) => name === 'getTroveInfo'),
61
+ params: [address],
62
+ },
63
+ {
64
+ target: collSurplusPoolContract.options.address,
65
+ abiItem: collSurplusPoolContract.options.jsonInterface.find(({ name }) => name === 'getCollateral'),
66
+ params: [address],
67
+ },
68
+ {
69
+ target: troveManagerContract.options.address,
70
+ abiItem: troveManagerContract.options.jsonInterface.find(({ name }) => name === 'getBorrowingRateWithDecay'),
71
+ params: [],
72
+ },
73
+ {
74
+ target: priceFeedContract.options.address,
75
+ abiItem: priceFeedContract.options.jsonInterface.find(({ name }) => name === 'fetchPrice'),
76
+ params: [],
77
+ },
78
+ {
79
+ target: activePoolContract.options.address,
80
+ abiItem: activePoolContract.options.jsonInterface.find(({ name }) => name === 'getETH'),
81
+ params: [],
82
+ },
83
+ {
84
+ target: activePoolContract.options.address,
85
+ abiItem: activePoolContract.options.jsonInterface.find(({ name }) => name === 'getLUSDDebt'),
86
+ params: [],
87
+ },
88
+ ];
89
+
90
+ const [multiRes, debtInFront] = await Promise.all([
91
+ multicall(multicallData, web3, network),
92
+ getDebtInFront(viewContract, address),
93
+ ]);
94
+
95
+ const recoveryMode = multiRes[0][6];
96
+ const totalETH = multiRes[4][0];
97
+ const totalLUSD = multiRes[5][0];
98
+
99
+ const payload = {
100
+ troveStatus: LIQUITY_TROVE_STATUS_ENUM[+multiRes[0][0].toString()],
101
+ collateral: assetAmountInEth(multiRes[0][1]),
102
+ debtInAsset: assetAmountInEth(multiRes[0][2]),
103
+ TCRatio: assetAmountInEth(multiRes[0][4]),
104
+ recoveryMode,
105
+ claimableCollateral: assetAmountInEth(multiRes[1][0]),
106
+ borrowingRateWithDecay: assetAmountInEth(multiRes[2][0]),
107
+ assetPrice: assetAmountInEth(multiRes[3][0]),
108
+ totalETH,
109
+ totalLUSD,
110
+ debtInFront,
111
+ minCollateralRatio: recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO,
112
+ priceForRecovery: new Dec(recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO).mul(totalLUSD).div(totalETH).div(100)
113
+ .toString(),
114
+ };
115
+
116
+ return payload;
117
117
  };