@defisaver/positions-sdk 0.0.165 → 0.0.166-dev-liquity-v2

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 (117) 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/helpers/index.d.ts +1 -0
  9. package/cjs/helpers/index.js +2 -1
  10. package/cjs/helpers/liquityV2Helpers/index.d.ts +12 -0
  11. package/cjs/helpers/liquityV2Helpers/index.js +53 -0
  12. package/cjs/index.d.ts +2 -1
  13. package/cjs/index.js +3 -1
  14. package/cjs/liquityV2/index.d.ts +10 -0
  15. package/cjs/liquityV2/index.js +94 -0
  16. package/cjs/markets/index.d.ts +1 -0
  17. package/cjs/markets/index.js +3 -1
  18. package/cjs/markets/liquityV2/index.d.ts +8 -0
  19. package/cjs/markets/liquityV2/index.js +34 -0
  20. package/cjs/staking/staking.d.ts +1 -0
  21. package/cjs/staking/staking.js +10 -2
  22. package/cjs/types/contracts/generated/LiquityV2View.d.ts +222 -0
  23. package/cjs/types/contracts/generated/LiquityV2View.js +5 -0
  24. package/cjs/types/contracts/generated/index.d.ts +1 -0
  25. package/cjs/types/index.d.ts +1 -0
  26. package/cjs/types/index.js +1 -0
  27. package/cjs/types/liquityV2.d.ts +73 -0
  28. package/cjs/types/liquityV2.js +8 -0
  29. package/esm/config/contracts.d.ts +43 -0
  30. package/esm/config/contracts.js +6 -0
  31. package/esm/contracts.d.ts +1 -0
  32. package/esm/contracts.js +1 -0
  33. package/esm/helpers/index.d.ts +1 -0
  34. package/esm/helpers/index.js +1 -0
  35. package/esm/helpers/liquityV2Helpers/index.d.ts +12 -0
  36. package/esm/helpers/liquityV2Helpers/index.js +45 -0
  37. package/esm/index.d.ts +2 -1
  38. package/esm/index.js +2 -1
  39. package/esm/liquityV2/index.d.ts +10 -0
  40. package/esm/liquityV2/index.js +86 -0
  41. package/esm/markets/index.d.ts +1 -0
  42. package/esm/markets/index.js +1 -0
  43. package/esm/markets/liquityV2/index.d.ts +8 -0
  44. package/esm/markets/liquityV2/index.js +28 -0
  45. package/esm/staking/staking.d.ts +1 -0
  46. package/esm/staking/staking.js +8 -1
  47. package/esm/types/contracts/generated/LiquityV2View.d.ts +222 -0
  48. package/esm/types/contracts/generated/LiquityV2View.js +4 -0
  49. package/esm/types/contracts/generated/index.d.ts +1 -0
  50. package/esm/types/index.d.ts +1 -0
  51. package/esm/types/index.js +1 -0
  52. package/esm/types/liquityV2.d.ts +73 -0
  53. package/esm/types/liquityV2.js +5 -0
  54. package/package.json +49 -48
  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 -1034
  62. package/src/constants/index.ts +6 -6
  63. package/src/contracts.ts +130 -128
  64. package/src/curveUsd/index.ts +229 -229
  65. package/src/exchange/index.ts +17 -17
  66. package/src/helpers/aaveHelpers/index.ts +194 -194
  67. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  68. package/src/helpers/compoundHelpers/index.ts +246 -246
  69. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  70. package/src/helpers/index.ts +9 -8
  71. package/src/helpers/liquityV2Helpers/index.ts +69 -0
  72. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  73. package/src/helpers/makerHelpers/index.ts +94 -94
  74. package/src/helpers/morphoBlueHelpers/index.ts +115 -115
  75. package/src/helpers/sparkHelpers/index.ts +150 -150
  76. package/src/index.ts +48 -46
  77. package/src/liquity/index.ts +116 -116
  78. package/src/liquityV2/index.ts +111 -0
  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/index.ts +23 -22
  87. package/src/markets/liquityV2/index.ts +31 -0
  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 +54 -54
  101. package/src/setup.ts +8 -8
  102. package/src/spark/index.ts +424 -424
  103. package/src/staking/staking.ts +218 -211
  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/LiquityV2View.ts +280 -0
  109. package/src/types/contracts/generated/index.ts +1 -0
  110. package/src/types/curveUsd.ts +118 -118
  111. package/src/types/index.ts +9 -8
  112. package/src/types/liquity.ts +30 -30
  113. package/src/types/liquityV2.ts +79 -0
  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
package/.mocharc.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "require": "ts-node/register",
3
- "extension": ["ts"]
4
- }
1
+ {
2
+ "require": "ts-node/register",
3
+ "extension": ["ts"]
4
+ }
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- v20.17.0
1
+ v20.17.0
package/README.md CHANGED
@@ -1,69 +1,69 @@
1
- # DeFi Saver Positions SDK
2
-
3
- Supported protocols:
4
- - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
- - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
- - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
- - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
- - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
- - [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
10
- - [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
11
- - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
12
- - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
13
- - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
14
- - [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
15
-
16
- ## Setup
17
- Supported Node version is v10.
18
-
19
- - run `npm install` (first time)
20
- - run `npm run build`
21
-
22
- `build` command will generate contracts and build ejs and esm folders
23
-
24
- ## How to use
25
- [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
26
-
27
- This is a Compound V3 example, and every other protocol is similar
28
- ```js
29
- import Web3 from 'web3';
30
- import { compoundV3 } from '@defisaver/positions-sdk';
31
-
32
-
33
- // every protocol has market data and user data getters
34
- const {
35
- getCompoundV3MarketsData,
36
- getCompoundV3AccountData,
37
- } = compoundV3;
38
-
39
- const provider = 'Your RPC provider';
40
- const web3 = new Web3(provider);
41
-
42
- const user = '0x123...';
43
-
44
- const { assetsData } = await getCompoundV3MarketsData(
45
- web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
46
- 1, // network
47
- selectedMarket, // market object like in /src/markets/compound/index.ts
48
- web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
49
- );
50
-
51
- const userData = await getCompoundV3AccountData(
52
- web3,
53
- 1, // network
54
- userAddress, // EOA or DSProxy
55
- '', // proxy address of the user, or just empty string if checking for EOA
56
- {
57
- selectedMarket, // market object as in /src/markets/compound/index.ts
58
- assetsData,
59
- }
60
- );
61
- ```
62
-
63
- More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
64
-
65
- ## Testing
66
-
67
- `npm run test` - Run all tests
68
-
69
- `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
1
+ # DeFi Saver Positions SDK
2
+
3
+ Supported protocols:
4
+ - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
+ - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
+ - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
+ - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
+ - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
+ - [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
10
+ - [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
11
+ - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
12
+ - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
13
+ - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
14
+ - [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
15
+
16
+ ## Setup
17
+ Supported Node version is v10.
18
+
19
+ - run `npm install` (first time)
20
+ - run `npm run build`
21
+
22
+ `build` command will generate contracts and build ejs and esm folders
23
+
24
+ ## How to use
25
+ [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
26
+
27
+ This is a Compound V3 example, and every other protocol is similar
28
+ ```js
29
+ import Web3 from 'web3';
30
+ import { compoundV3 } from '@defisaver/positions-sdk';
31
+
32
+
33
+ // every protocol has market data and user data getters
34
+ const {
35
+ getCompoundV3MarketsData,
36
+ getCompoundV3AccountData,
37
+ } = compoundV3;
38
+
39
+ const provider = 'Your RPC provider';
40
+ const web3 = new Web3(provider);
41
+
42
+ const user = '0x123...';
43
+
44
+ const { assetsData } = await getCompoundV3MarketsData(
45
+ web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
46
+ 1, // network
47
+ selectedMarket, // market object like in /src/markets/compound/index.ts
48
+ web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
49
+ );
50
+
51
+ const userData = await getCompoundV3AccountData(
52
+ web3,
53
+ 1, // network
54
+ userAddress, // EOA or DSProxy
55
+ '', // proxy address of the user, or just empty string if checking for EOA
56
+ {
57
+ selectedMarket, // market object as in /src/markets/compound/index.ts
58
+ assetsData,
59
+ }
60
+ );
61
+ ```
62
+
63
+ More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
64
+
65
+ ## Testing
66
+
67
+ `npm run test` - Run all tests
68
+
69
+ `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
@@ -6696,3 +6696,46 @@ export namespace LlamaLendControllerAbi {
6696
6696
  let networks_76: {};
6697
6697
  export { networks_76 as networks };
6698
6698
  }
6699
+ export namespace LiquityV2View {
6700
+ let abi_77: ({
6701
+ inputs: {
6702
+ internalType: string;
6703
+ name: string;
6704
+ type: string;
6705
+ }[];
6706
+ name: string;
6707
+ outputs: {
6708
+ internalType: string;
6709
+ name: string;
6710
+ type: string;
6711
+ }[];
6712
+ stateMutability: string;
6713
+ type: string;
6714
+ } | {
6715
+ inputs: {
6716
+ internalType: string;
6717
+ name: string;
6718
+ type: string;
6719
+ }[];
6720
+ name: string;
6721
+ outputs: {
6722
+ components: {
6723
+ internalType: string;
6724
+ name: string;
6725
+ type: string;
6726
+ }[];
6727
+ internalType: string;
6728
+ name: string;
6729
+ type: string;
6730
+ }[];
6731
+ stateMutability: string;
6732
+ type: string;
6733
+ })[];
6734
+ export { abi_77 as abi };
6735
+ let networks_77: {
6736
+ "1": {
6737
+ address: string;
6738
+ };
6739
+ };
6740
+ export { networks_77 as networks };
6741
+ }
@@ -1031,4 +1031,10 @@ module.exports = {
1031
1031
  "abi": [{ "name": "UserState", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral", "type": "uint256", "indexed": false }, { "name": "debt", "type": "uint256", "indexed": false }, { "name": "n1", "type": "int256", "indexed": false }, { "name": "n2", "type": "int256", "indexed": false }, { "name": "liquidation_discount", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "Borrow", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral_increase", "type": "uint256", "indexed": false }, { "name": "loan_increase", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "Repay", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral_decrease", "type": "uint256", "indexed": false }, { "name": "loan_decrease", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "RemoveCollateral", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral_decrease", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "Liquidate", "inputs": [{ "name": "liquidator", "type": "address", "indexed": true }, { "name": "user", "type": "address", "indexed": true }, { "name": "collateral_received", "type": "uint256", "indexed": false }, { "name": "stablecoin_received", "type": "uint256", "indexed": false }, { "name": "debt", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "SetMonetaryPolicy", "inputs": [{ "name": "monetary_policy", "type": "address", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "SetBorrowingDiscounts", "inputs": [{ "name": "loan_discount", "type": "uint256", "indexed": false }, { "name": "liquidation_discount", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "CollectFees", "inputs": [{ "name": "amount", "type": "uint256", "indexed": false }, { "name": "new_supply", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "stateMutability": "nonpayable", "type": "constructor", "inputs": [{ "name": "collateral_token", "type": "address" }, { "name": "monetary_policy", "type": "address" }, { "name": "loan_discount", "type": "uint256" }, { "name": "liquidation_discount", "type": "uint256" }, { "name": "amm", "type": "address" }], "outputs": [] }, { "stateMutability": "pure", "type": "function", "name": "factory", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "pure", "type": "function", "name": "amm", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "pure", "type": "function", "name": "collateral_token", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "pure", "type": "function", "name": "borrowed_token", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "save_rate", "inputs": [], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "debt", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "loan_exists", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "bool" }] }, { "stateMutability": "view", "type": "function", "name": "total_debt", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "max_borrowable", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "max_borrowable", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "N", "type": "uint256" }, { "name": "current_debt", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "min_collateral", "inputs": [{ "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "calculate_debt_n1", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "create_loan", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "create_loan_extended", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }, { "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "add_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "add_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "_for", "type": "address" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "remove_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "remove_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "use_eth", "type": "bool" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "borrow_more", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "borrow_more_extended", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }, { "name": "_for", "type": "address" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }, { "name": "_for", "type": "address" }, { "name": "max_active_band", "type": "int256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }, { "name": "_for", "type": "address" }, { "name": "max_active_band", "type": "int256" }, { "name": "use_eth", "type": "bool" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay_extended", "inputs": [{ "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "health_calculator", "inputs": [{ "name": "user", "type": "address" }, { "name": "d_collateral", "type": "int256" }, { "name": "d_debt", "type": "int256" }, { "name": "full", "type": "bool" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "view", "type": "function", "name": "health_calculator", "inputs": [{ "name": "user", "type": "address" }, { "name": "d_collateral", "type": "int256" }, { "name": "d_debt", "type": "int256" }, { "name": "full", "type": "bool" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "liquidate", "inputs": [{ "name": "user", "type": "address" }, { "name": "min_x", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "liquidate", "inputs": [{ "name": "user", "type": "address" }, { "name": "min_x", "type": "uint256" }, { "name": "use_eth", "type": "bool" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "liquidate_extended", "inputs": [{ "name": "user", "type": "address" }, { "name": "min_x", "type": "uint256" }, { "name": "frac", "type": "uint256" }, { "name": "use_eth", "type": "bool" }, { "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "tokens_to_liquidate", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "tokens_to_liquidate", "inputs": [{ "name": "user", "type": "address" }, { "name": "frac", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "health", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "view", "type": "function", "name": "health", "inputs": [{ "name": "user", "type": "address" }, { "name": "full", "type": "bool" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "view", "type": "function", "name": "users_to_liquidate", "inputs": [], "outputs": [{ "name": "", "type": "tuple[]", "components": [{ "name": "user", "type": "address" }, { "name": "x", "type": "uint256" }, { "name": "y", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "health", "type": "int256" }] }] }, { "stateMutability": "view", "type": "function", "name": "users_to_liquidate", "inputs": [{ "name": "_from", "type": "uint256" }], "outputs": [{ "name": "", "type": "tuple[]", "components": [{ "name": "user", "type": "address" }, { "name": "x", "type": "uint256" }, { "name": "y", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "health", "type": "int256" }] }] }, { "stateMutability": "view", "type": "function", "name": "users_to_liquidate", "inputs": [{ "name": "_from", "type": "uint256" }, { "name": "_limit", "type": "uint256" }], "outputs": [{ "name": "", "type": "tuple[]", "components": [{ "name": "user", "type": "address" }, { "name": "x", "type": "uint256" }, { "name": "y", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "health", "type": "int256" }] }] }, { "stateMutability": "view", "type": "function", "name": "amm_price", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "user_prices", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256[2]" }] }, { "stateMutability": "view", "type": "function", "name": "user_state", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256[4]" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_amm_fee", "inputs": [{ "name": "fee", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_amm_admin_fee", "inputs": [{ "name": "fee", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_monetary_policy", "inputs": [{ "name": "monetary_policy", "type": "address" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_borrowing_discounts", "inputs": [{ "name": "loan_discount", "type": "uint256" }, { "name": "liquidation_discount", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_callback", "inputs": [{ "name": "cb", "type": "address" }], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "admin_fees", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "collect_fees", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "check_lock", "inputs": [], "outputs": [{ "name": "", "type": "bool" }] }, { "stateMutability": "view", "type": "function", "name": "liquidation_discounts", "inputs": [{ "name": "arg0", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "loans", "inputs": [{ "name": "arg0", "type": "uint256" }], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "view", "type": "function", "name": "loan_ix", "inputs": [{ "name": "arg0", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "n_loans", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "minted", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "redeemed", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "monetary_policy", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "view", "type": "function", "name": "liquidation_discount", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "loan_discount", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }],
1032
1032
  "networks": {}
1033
1033
  },
1034
+ "LiquityV2View": {
1035
+ "abi": [{ "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_prevId", "type": "uint256" }, { "internalType": "uint256", "name": "_nextId", "type": "uint256" }], "name": "findInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getApproxHint", "outputs": [{ "internalType": "uint256", "name": "hintId", "type": "uint256" }, { "internalType": "uint256", "name": "diff", "type": "uint256" }, { "internalType": "uint256", "name": "latestRandomSeed", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getDebtInFront", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }, { "internalType": "uint256", "name": "_targetIR", "type": "uint256" }], "name": "getDebtInFrontByInterestRate", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_numTroves", "type": "uint256" }], "name": "getDebtInFrontByTroveNum", "outputs": [{ "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "address", "name": "_depositor", "type": "address" }], "name": "getDepositorInfo", "outputs": [{ "internalType": "uint256", "name": "compoundedBOLD", "type": "uint256" }, { "internalType": "uint256", "name": "collGain", "type": "uint256" }, { "internalType": "uint256", "name": "boldGain", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "getMarketData", "outputs": [{ "components": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "CCR", "type": "uint256" }, { "internalType": "uint256", "name": "MCR", "type": "uint256" }, { "internalType": "uint256", "name": "SCR", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_SP", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_REDISTRIBUTION", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemColl", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemDebt", "type": "uint256" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "troveNFT", "type": "address" }, { "internalType": "address", "name": "borrowerOperations", "type": "address" }, { "internalType": "address", "name": "troveManager", "type": "address" }, { "internalType": "address", "name": "stabilityPool", "type": "address" }, { "internalType": "address", "name": "sortedTroves", "type": "address" }, { "internalType": "address", "name": "collSurplusPool", "type": "address" }, { "internalType": "address", "name": "hintHelpers", "type": "address" }, { "internalType": "address", "name": "priceFeed", "type": "address" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "bool", "name": "isShutDown", "type": "bool" }], "internalType": "struct LiquityV2View.MarketData", "name": "data", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getNumOfTrovesInFrontOfTrove", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "numTroves", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }], "name": "getTroveInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "enum ITroveManager.Status", "name": "status", "type": "uint8" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "uint256", "name": "TCRatio", "type": "uint256" }, { "internalType": "uint256", "name": "annualInterestRate", "type": "uint256" }, { "internalType": "address", "name": "interestBatchManager", "type": "address" }, { "internalType": "uint256", "name": "batchDebtShares", "type": "uint256" }], "internalType": "struct LiquityV2View.TroveData", "name": "trove", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getTrovePosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "isShutDown", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }],
1036
+ "networks": {
1037
+ "1": { "address": "0x88bBa5Ce5cE20286Cf866b9f310354FFB701A296" },
1038
+ }
1039
+ }
1034
1040
  };
@@ -45,3 +45,4 @@ export declare const USDCPriceFeedContract: (web3: Web3, network: NetworkNumber,
45
45
  export declare const FeedRegistryContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.FeedRegistry;
46
46
  export declare const MorphoBlueViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.MorphoBlueView;
47
47
  export declare const LlamaLendViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.LlamaLendView;
48
+ export declare const LiquityV2ViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.LiquityV2View;
package/cjs/contracts.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.FeedRegistryContract = exports.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
6
+ exports.LiquityV2ViewContract = exports.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.FeedRegistryContract = exports.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
7
7
  const contracts_1 = __importDefault(require("./config/contracts"));
8
8
  const contractConfig = contracts_1.default;
9
9
  const getConfigContractAddress = (name, network, block) => {
@@ -87,3 +87,4 @@ exports.USDCPriceFeedContract = createContractFromConfigFunc('USDCPriceFeed');
87
87
  exports.FeedRegistryContract = createContractFromConfigFunc('FeedRegistry');
88
88
  exports.MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueView');
89
89
  exports.LlamaLendViewContract = createContractFromConfigFunc('LlamaLendView');
90
+ exports.LiquityV2ViewContract = createContractFromConfigFunc('LiquityV2View');
@@ -6,3 +6,4 @@ export * as makerHelpers from './makerHelpers';
6
6
  export * as chickenBondsHelpers from './chickenBondsHelpers';
7
7
  export * as morphoBlueHelpers from './morphoBlueHelpers';
8
8
  export * as llamaLendHelpers from './llamaLendHelpers';
9
+ export * as liquityV2Helpers from './liquityV2Helpers';
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.llamaLendHelpers = exports.morphoBlueHelpers = exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
26
+ exports.liquityV2Helpers = exports.llamaLendHelpers = exports.morphoBlueHelpers = exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
27
27
  exports.aaveHelpers = __importStar(require("./aaveHelpers"));
28
28
  exports.compoundHelpers = __importStar(require("./compoundHelpers"));
29
29
  exports.sparkHelpers = __importStar(require("./sparkHelpers"));
@@ -32,3 +32,4 @@ exports.makerHelpers = __importStar(require("./makerHelpers"));
32
32
  exports.chickenBondsHelpers = __importStar(require("./chickenBondsHelpers"));
33
33
  exports.morphoBlueHelpers = __importStar(require("./morphoBlueHelpers"));
34
34
  exports.llamaLendHelpers = __importStar(require("./llamaLendHelpers"));
35
+ exports.liquityV2Helpers = __importStar(require("./liquityV2Helpers"));
@@ -0,0 +1,12 @@
1
+ import { LiquityV2AggregatedTroveData, LiquityV2AssetsData, LiquityV2UsedAssets } from '../../types';
2
+ export declare const calculateNetApyLiquityV2: (usedAssets: LiquityV2UsedAssets, assetsData: LiquityV2AssetsData, interestRate: string) => {
3
+ netApy: string;
4
+ totalInterestUsd: string;
5
+ incentiveUsd: string;
6
+ };
7
+ export declare const getLiquityV2AggregatedPositionData: ({ usedAssets, assetsData, minRatio, interestRate, }: {
8
+ usedAssets: LiquityV2UsedAssets;
9
+ assetsData: LiquityV2AssetsData;
10
+ minRatio: string;
11
+ interestRate: string;
12
+ }) => LiquityV2AggregatedTroveData;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLiquityV2AggregatedPositionData = exports.calculateNetApyLiquityV2 = void 0;
7
+ const decimal_js_1 = __importDefault(require("decimal.js"));
8
+ const moneymarket_1 = require("../../moneymarket");
9
+ const staking_1 = require("../../staking");
10
+ const calculateNetApyLiquityV2 = (usedAssets, assetsData, interestRate) => {
11
+ const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
12
+ const acc = Object.assign({}, _acc);
13
+ const assetData = assetsData[usedAsset.symbol];
14
+ if (usedAsset.suppliedUsd) {
15
+ const amount = usedAsset.suppliedUsd;
16
+ acc.suppliedUsd = new decimal_js_1.default(acc.suppliedUsd).add(amount).toString();
17
+ if (assetData.incentiveSupplyApy) {
18
+ const incentiveInterest = (0, staking_1.calculateInterestEarned)(amount, assetData.incentiveSupplyApy, 'year', true);
19
+ acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
20
+ }
21
+ }
22
+ if (usedAsset.borrowedUsd) {
23
+ const amount = usedAsset.borrowedUsd;
24
+ acc.borrowedUsd = new decimal_js_1.default(acc.borrowedUsd).add(amount).toString();
25
+ const rate = interestRate;
26
+ const borrowInterest = (0, staking_1.calculateInterestEarned)(amount, rate, 'year', true);
27
+ acc.borrowInterest = new decimal_js_1.default(acc.borrowInterest).sub(borrowInterest.toString()).toString();
28
+ }
29
+ return acc;
30
+ }, {
31
+ borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
32
+ });
33
+ const { borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd, } = sumValues;
34
+ const totalInterestUsd = new decimal_js_1.default(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
35
+ const balance = new decimal_js_1.default(suppliedUsd).sub(borrowedUsd);
36
+ const netApy = new decimal_js_1.default(totalInterestUsd).div(balance).times(100).toString();
37
+ return { netApy, totalInterestUsd, incentiveUsd };
38
+ };
39
+ exports.calculateNetApyLiquityV2 = calculateNetApyLiquityV2;
40
+ const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData, minRatio, interestRate, }) => {
41
+ const payload = {};
42
+ payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, (usedAsset) => usedAsset, ({ suppliedUsd }) => suppliedUsd);
43
+ payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, (usedAsset) => usedAsset, ({ borrowedUsd }) => borrowedUsd);
44
+ payload.borrowLimitUsd = new decimal_js_1.default(payload.suppliedUsd).div(minRatio).mul(100).toString();
45
+ const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
46
+ payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
47
+ const { netApy, incentiveUsd, totalInterestUsd } = (0, exports.calculateNetApyLiquityV2)(usedAssets, assetsData, interestRate);
48
+ payload.netApy = netApy;
49
+ payload.incentiveUsd = incentiveUsd;
50
+ payload.totalInterestUsd = totalInterestUsd;
51
+ return payload;
52
+ };
53
+ exports.getLiquityV2AggregatedPositionData = getLiquityV2AggregatedPositionData;
package/cjs/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import * as compoundV2 from './compoundV2';
8
8
  import * as spark from './spark';
9
9
  import * as curveUsd from './curveUsd';
10
10
  import * as liquity from './liquity';
11
+ import * as liquityV2 from './liquityV2';
11
12
  import * as maker from './maker';
12
13
  import * as staking from './staking';
13
14
  import * as multicall from './multicall';
@@ -19,4 +20,4 @@ import * as exchange from './exchange';
19
20
  import * as morphoBlue from './morphoBlue';
20
21
  import * as llamaLend from './llamaLend';
21
22
  export * from './types';
22
- export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, llamaLend, };
23
+ export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, llamaLend, };
package/cjs/index.js CHANGED
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.llamaLend = exports.morphoBlue = exports.helpers = exports.markets = exports.moneymarket = exports.multicall = exports.staking = exports.exchange = exports.chickenBonds = exports.maker = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.morphoAaveV3 = exports.morphoAaveV2 = exports.aaveV3 = exports.aaveV2 = void 0;
29
+ exports.llamaLend = exports.morphoBlue = exports.helpers = exports.markets = exports.moneymarket = exports.multicall = exports.staking = exports.exchange = exports.chickenBonds = exports.maker = exports.liquityV2 = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.morphoAaveV3 = exports.morphoAaveV2 = exports.aaveV3 = exports.aaveV2 = void 0;
30
30
  require("./setup");
31
31
  const aaveV3 = __importStar(require("./aaveV3"));
32
32
  exports.aaveV3 = aaveV3;
@@ -46,6 +46,8 @@ const curveUsd = __importStar(require("./curveUsd"));
46
46
  exports.curveUsd = curveUsd;
47
47
  const liquity = __importStar(require("./liquity"));
48
48
  exports.liquity = liquity;
49
+ const liquityV2 = __importStar(require("./liquityV2"));
50
+ exports.liquityV2 = liquityV2;
49
51
  const maker = __importStar(require("./maker"));
50
52
  exports.maker = maker;
51
53
  const staking = __importStar(require("./staking"));
@@ -0,0 +1,10 @@
1
+ import Web3 from 'web3';
2
+ import { NetworkNumber } from '../types/common';
3
+ import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
4
+ export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
5
+ export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
6
+ selectedMarket: LiquityV2MarketInfo;
7
+ assetsData: LiquityV2AssetsData;
8
+ marketData: InnerLiquityV2MarketData;
9
+ troveId: string;
10
+ }) => Promise<LiquityV2TroveData>;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getLiquityV2TroveData = exports.getLiquityV2MarketData = void 0;
16
+ const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const tokens_1 = require("@defisaver/tokens");
18
+ const contracts_1 = require("../contracts");
19
+ const types_1 = require("../types");
20
+ const staking_1 = require("../staking");
21
+ const liquityV2Helpers_1 = require("../helpers/liquityV2Helpers");
22
+ const utils_1 = require("../services/utils");
23
+ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
25
+ const { marketAddress, debtToken, collateralToken } = selectedMarket;
26
+ const data = yield viewContract.methods.getMarketData(marketAddress).call();
27
+ const assetsData = {};
28
+ assetsData[debtToken] = {
29
+ symbol: debtToken,
30
+ address: (0, tokens_1.getAssetInfo)(debtToken, network).address,
31
+ price: '1',
32
+ totalSupply: '0',
33
+ totalBorrow: (0, tokens_1.assetAmountInEth)(data.entireSystemDebt),
34
+ canBeSupplied: false,
35
+ canBeBorrowed: true,
36
+ };
37
+ assetsData[collateralToken] = {
38
+ symbol: collateralToken,
39
+ address: (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(collateralToken), network).address,
40
+ price: (0, tokens_1.assetAmountInEth)(data.collPrice),
41
+ totalSupply: (0, tokens_1.assetAmountInEth)(data.entireSystemColl),
42
+ totalBorrow: '0',
43
+ canBeSupplied: true,
44
+ canBeBorrowed: false,
45
+ };
46
+ if (staking_1.STAKING_ASSETS.includes(collateralToken)) {
47
+ assetsData[collateralToken].incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collateralToken, mainnetWeb3);
48
+ assetsData[collateralToken].incentiveSupplyToken = collateralToken;
49
+ }
50
+ const minRatio = new decimal_js_1.default(data.MCR).div(1e16).toString();
51
+ return { assetsData, marketData: { minRatio } };
52
+ });
53
+ exports.getLiquityV2MarketData = getLiquityV2MarketData;
54
+ const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, marketData, troveId, }) => __awaiter(void 0, void 0, void 0, function* () {
55
+ const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
56
+ const { minRatio } = marketData;
57
+ const { collateralToken, marketAddress, debtToken } = selectedMarket;
58
+ const data = yield viewContract.methods.getTroveInfo(marketAddress, troveId).call();
59
+ const usedAssets = {};
60
+ const debtAssetData = assetsData[debtToken];
61
+ const borrowed = (0, tokens_1.assetAmountInEth)(data.debtAmount);
62
+ usedAssets[debtToken] = {
63
+ symbol: debtToken,
64
+ address: debtAssetData.address,
65
+ price: debtAssetData.price,
66
+ supplied: '0',
67
+ suppliedUsd: '0',
68
+ borrowed,
69
+ borrowedUsd: new decimal_js_1.default(borrowed).mul(debtAssetData.price).toString(),
70
+ };
71
+ const collAssetData = assetsData[collateralToken];
72
+ const suppliedColl = (0, tokens_1.assetAmountInEth)(data.collAmount);
73
+ usedAssets[collateralToken] = {
74
+ symbol: collateralToken,
75
+ address: collAssetData.address,
76
+ price: collAssetData.price,
77
+ supplied: suppliedColl,
78
+ suppliedUsd: new decimal_js_1.default(suppliedColl).mul(collAssetData.price).toString(),
79
+ borrowed: '0',
80
+ borrowedUsd: '0',
81
+ };
82
+ const ratio = new decimal_js_1.default(data.TCRatio).div(1e16).toString();
83
+ const interestRate = new decimal_js_1.default(data.annualInterestRate).div(1e16).toString();
84
+ const interestBatchManager = data.interestBatchManager;
85
+ const payload = Object.assign({ usedAssets,
86
+ troveId,
87
+ ratio,
88
+ interestRate,
89
+ interestBatchManager, troveStatus: types_1.LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, (0, liquityV2Helpers_1.getLiquityV2AggregatedPositionData)({
90
+ usedAssets, assetsData, minRatio, interestRate,
91
+ }));
92
+ return payload;
93
+ });
94
+ exports.getLiquityV2TroveData = getLiquityV2TroveData;
@@ -4,3 +4,4 @@ export { SparkMarkets } from './spark';
4
4
  export { CrvUsdMarkets } from './curveUsd';
5
5
  export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
6
6
  export { LlamaLendMarkets } from './llamaLend';
7
+ export { LiquityV2Markets } from './liquityV2';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LlamaLendMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.morphoAaveV3AssetEthMarket = exports.morphoAaveV2AssetDefaultMarket = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
3
+ exports.LiquityV2Markets = exports.LlamaLendMarkets = exports.findMorphoBlueMarket = exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.v3USDTCollAssets = exports.v3USDCeCollAssets = exports.v3USDCCollAssets = exports.v3USDbCCollAssets = exports.v3ETHCollAssets = exports.compoundV2CollateralAssets = exports.CompoundMarkets = exports.getAaveV3MarketByMarketAddress = exports.morphoAaveV3AssetEthMarket = exports.morphoAaveV2AssetDefaultMarket = exports.aaveV3AssetsDefaultMarket = exports.aaveV2AssetsDefaultMarket = exports.aaveV1AssetsDefaultMarket = exports.AaveMarkets = void 0;
4
4
  var aave_1 = require("./aave");
5
5
  Object.defineProperty(exports, "AaveMarkets", { enumerable: true, get: function () { return aave_1.AaveMarkets; } });
6
6
  Object.defineProperty(exports, "aaveV1AssetsDefaultMarket", { enumerable: true, get: function () { return aave_1.aaveV1AssetsDefaultMarket; } });
@@ -26,3 +26,5 @@ Object.defineProperty(exports, "MorphoBlueMarkets", { enumerable: true, get: fun
26
26
  Object.defineProperty(exports, "findMorphoBlueMarket", { enumerable: true, get: function () { return morphoBlue_1.findMorphoBlueMarket; } });
27
27
  var llamaLend_1 = require("./llamaLend");
28
28
  Object.defineProperty(exports, "LlamaLendMarkets", { enumerable: true, get: function () { return llamaLend_1.LlamaLendMarkets; } });
29
+ var liquityV2_1 = require("./liquityV2");
30
+ Object.defineProperty(exports, "LiquityV2Markets", { enumerable: true, get: function () { return liquityV2_1.LiquityV2Markets; } });
@@ -0,0 +1,8 @@
1
+ import { NetworkNumber } from '../../types/common';
2
+ import { LiquityV2MarketInfo } from '../../types/liquityV2';
3
+ export declare const LIQUITY_V2_ETH_MARKET: (networkId?: NetworkNumber) => LiquityV2MarketInfo;
4
+ export declare const LIQUITY_V2_WSTETH_MARKET: (networkId?: NetworkNumber) => LiquityV2MarketInfo;
5
+ export declare const LiquityV2Markets: (networkId: NetworkNumber) => {
6
+ readonly liquityv2eth: LiquityV2MarketInfo;
7
+ readonly liquityv2wsteth: LiquityV2MarketInfo;
8
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LiquityV2Markets = exports.LIQUITY_V2_WSTETH_MARKET = exports.LIQUITY_V2_ETH_MARKET = void 0;
4
+ const common_1 = require("../../types/common");
5
+ const liquityV2_1 = require("../../types/liquityV2");
6
+ const LIQUITY_V2_ETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
7
+ chainIds: [1],
8
+ label: 'Liquity V2 ETH',
9
+ shortLabel: 'ETH',
10
+ value: liquityV2_1.LiquityV2Versions.LiquityV2Eth,
11
+ url: 'eth',
12
+ debtToken: 'BOLD',
13
+ collateralToken: 'ETH',
14
+ marketAddress: '0xd7199b16945f1ebaa0b301bf3d05bf489caa408b',
15
+ protocolName: 'liquity-v2',
16
+ });
17
+ exports.LIQUITY_V2_ETH_MARKET = LIQUITY_V2_ETH_MARKET;
18
+ const LIQUITY_V2_WSTETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
19
+ chainIds: [1],
20
+ label: 'Liquity V2 wstETH',
21
+ shortLabel: 'wstETH',
22
+ value: liquityV2_1.LiquityV2Versions.LiquityV2WstEth,
23
+ url: 'wsteth',
24
+ debtToken: 'BOLD',
25
+ collateralToken: 'wstETH',
26
+ marketAddress: '0x0d22113a543826eeaf2ae0fc9d10aea66efba156',
27
+ protocolName: 'liquity-v2',
28
+ });
29
+ exports.LIQUITY_V2_WSTETH_MARKET = LIQUITY_V2_WSTETH_MARKET;
30
+ const LiquityV2Markets = (networkId) => ({
31
+ [liquityV2_1.LiquityV2Versions.LiquityV2Eth]: (0, exports.LIQUITY_V2_ETH_MARKET)(networkId),
32
+ [liquityV2_1.LiquityV2Versions.LiquityV2WstEth]: (0, exports.LIQUITY_V2_WSTETH_MARKET)(networkId),
33
+ });
34
+ exports.LiquityV2Markets = LiquityV2Markets;