@defisaver/positions-sdk 0.0.98 → 0.0.100

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 (80) hide show
  1. package/README.md +63 -63
  2. package/cjs/config/contracts.d.ts +361 -15
  3. package/cjs/config/contracts.js +37 -15
  4. package/cjs/helpers/morphoBlueHelpers/index.d.ts +9 -2
  5. package/cjs/helpers/morphoBlueHelpers/index.js +66 -1
  6. package/cjs/maker/index.js +1 -1
  7. package/cjs/morphoBlue/index.js +4 -27
  8. package/cjs/types/contracts/generated/AaveV3View.d.ts +29 -2
  9. package/cjs/types/contracts/generated/MorphoBlueView.d.ts +61 -0
  10. package/cjs/types/contracts/generated/SparkView.d.ts +29 -2
  11. package/esm/config/contracts.d.ts +361 -15
  12. package/esm/config/contracts.js +37 -15
  13. package/esm/helpers/morphoBlueHelpers/index.d.ts +9 -2
  14. package/esm/helpers/morphoBlueHelpers/index.js +62 -0
  15. package/esm/maker/index.js +1 -1
  16. package/esm/morphoBlue/index.js +4 -27
  17. package/esm/types/contracts/generated/AaveV3View.d.ts +29 -2
  18. package/esm/types/contracts/generated/MorphoBlueView.d.ts +61 -0
  19. package/esm/types/contracts/generated/SparkView.d.ts +29 -2
  20. package/package.json +41 -40
  21. package/src/aaveV2/index.ts +227 -227
  22. package/src/aaveV3/index.ts +558 -558
  23. package/src/assets/index.ts +60 -60
  24. package/src/chickenBonds/index.ts +123 -123
  25. package/src/compoundV2/index.ts +219 -219
  26. package/src/compoundV3/index.ts +266 -266
  27. package/src/config/contracts.js +871 -848
  28. package/src/constants/index.ts +5 -5
  29. package/src/contracts.ts +128 -128
  30. package/src/curveUsd/index.ts +229 -229
  31. package/src/exchange/index.ts +17 -17
  32. package/src/helpers/aaveHelpers/index.ts +134 -134
  33. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  34. package/src/helpers/compoundHelpers/index.ts +181 -181
  35. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  36. package/src/helpers/index.ts +7 -7
  37. package/src/helpers/llamaLendHelpers/index.ts +45 -45
  38. package/src/helpers/makerHelpers/index.ts +94 -94
  39. package/src/helpers/morphoBlueHelpers/index.ts +117 -56
  40. package/src/helpers/sparkHelpers/index.ts +106 -106
  41. package/src/index.ts +46 -46
  42. package/src/liquity/index.ts +116 -116
  43. package/src/llamaLend/index.ts +268 -268
  44. package/src/maker/index.ts +117 -117
  45. package/src/markets/aave/index.ts +80 -80
  46. package/src/markets/aave/marketAssets.ts +24 -24
  47. package/src/markets/compound/index.ts +142 -142
  48. package/src/markets/compound/marketsAssets.ts +50 -50
  49. package/src/markets/curveUsd/index.ts +69 -69
  50. package/src/markets/index.ts +5 -5
  51. package/src/markets/llamaLend/contractAddresses.ts +95 -95
  52. package/src/markets/llamaLend/index.ts +150 -150
  53. package/src/markets/morphoBlue/index.ts +611 -611
  54. package/src/markets/spark/index.ts +29 -29
  55. package/src/markets/spark/marketAssets.ts +10 -10
  56. package/src/moneymarket/moneymarketCommonService.ts +76 -76
  57. package/src/morphoAaveV2/index.ts +256 -256
  58. package/src/morphoAaveV3/index.ts +612 -612
  59. package/src/morphoBlue/index.ts +171 -199
  60. package/src/multicall/index.ts +22 -22
  61. package/src/services/dsrService.ts +15 -15
  62. package/src/services/priceService.ts +21 -21
  63. package/src/services/utils.ts +51 -51
  64. package/src/setup.ts +8 -8
  65. package/src/spark/index.ts +424 -424
  66. package/src/staking/staking.ts +187 -187
  67. package/src/types/aave.ts +256 -256
  68. package/src/types/chickenBonds.ts +45 -45
  69. package/src/types/common.ts +84 -84
  70. package/src/types/compound.ts +128 -128
  71. package/src/types/contracts/generated/AaveV3View.ts +43 -3
  72. package/src/types/contracts/generated/MorphoBlueView.ts +87 -0
  73. package/src/types/contracts/generated/SparkView.ts +43 -3
  74. package/src/types/curveUsd.ts +118 -118
  75. package/src/types/index.ts +8 -8
  76. package/src/types/liquity.ts +30 -30
  77. package/src/types/llamaLend.ts +143 -143
  78. package/src/types/maker.ts +50 -50
  79. package/src/types/morphoBlue.ts +139 -139
  80. package/src/types/spark.ts +106 -106
package/src/index.ts CHANGED
@@ -1,46 +1,46 @@
1
- import './setup';
2
-
3
- import * as aaveV3 from './aaveV3';
4
- import * as morphoAaveV3 from './morphoAaveV3';
5
- import * as aaveV2 from './aaveV2';
6
- import * as morphoAaveV2 from './morphoAaveV2';
7
- import * as compoundV3 from './compoundV3';
8
- import * as compoundV2 from './compoundV2';
9
- import * as spark from './spark';
10
- import * as curveUsd from './curveUsd';
11
- import * as liquity from './liquity';
12
- import * as maker from './maker';
13
- import * as staking from './staking';
14
- import * as multicall from './multicall';
15
- import * as moneymarket from './moneymarket';
16
- import * as assets from './assets';
17
- import * as markets from './markets';
18
- import * as helpers from './helpers';
19
- import * as chickenBonds from './chickenBonds';
20
- import * as exchange from './exchange';
21
- import * as morphoBlue from './morphoBlue';
22
- import * as llamaLend from './llamaLend';
23
-
24
- export * from './types';
25
-
26
- export {
27
- aaveV2,
28
- aaveV3,
29
- morphoAaveV2,
30
- morphoAaveV3,
31
- compoundV2,
32
- compoundV3,
33
- spark,
34
- curveUsd,
35
- liquity,
36
- maker,
37
- chickenBonds,
38
- exchange,
39
- staking,
40
- multicall,
41
- moneymarket,
42
- markets,
43
- helpers,
44
- morphoBlue,
45
- llamaLend,
46
- };
1
+ import './setup';
2
+
3
+ import * as aaveV3 from './aaveV3';
4
+ import * as morphoAaveV3 from './morphoAaveV3';
5
+ import * as aaveV2 from './aaveV2';
6
+ import * as morphoAaveV2 from './morphoAaveV2';
7
+ import * as compoundV3 from './compoundV3';
8
+ import * as compoundV2 from './compoundV2';
9
+ import * as spark from './spark';
10
+ import * as curveUsd from './curveUsd';
11
+ import * as liquity from './liquity';
12
+ import * as maker from './maker';
13
+ import * as staking from './staking';
14
+ import * as multicall from './multicall';
15
+ import * as moneymarket from './moneymarket';
16
+ import * as assets from './assets';
17
+ import * as markets from './markets';
18
+ import * as helpers from './helpers';
19
+ import * as chickenBonds from './chickenBonds';
20
+ import * as exchange from './exchange';
21
+ import * as morphoBlue from './morphoBlue';
22
+ import * as llamaLend from './llamaLend';
23
+
24
+ export * from './types';
25
+
26
+ export {
27
+ aaveV2,
28
+ aaveV3,
29
+ morphoAaveV2,
30
+ morphoAaveV3,
31
+ compoundV2,
32
+ compoundV3,
33
+ spark,
34
+ curveUsd,
35
+ liquity,
36
+ maker,
37
+ chickenBonds,
38
+ exchange,
39
+ staking,
40
+ multicall,
41
+ moneymarket,
42
+ markets,
43
+ helpers,
44
+ morphoBlue,
45
+ llamaLend,
46
+ };
@@ -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
  };