@defisaver/positions-sdk 0.0.80 → 0.0.81

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 (64) hide show
  1. package/README.md +63 -63
  2. package/cjs/aaveV3/index.js +4 -7
  3. package/cjs/spark/index.js +57 -48
  4. package/esm/aaveV3/index.js +4 -7
  5. package/esm/spark/index.js +58 -49
  6. package/package.json +41 -41
  7. package/src/aaveV2/index.ts +227 -227
  8. package/src/aaveV3/index.ts +559 -562
  9. package/src/assets/index.ts +60 -60
  10. package/src/chickenBonds/index.ts +123 -123
  11. package/src/compoundV2/index.ts +219 -219
  12. package/src/compoundV3/index.ts +273 -273
  13. package/src/config/contracts.js +848 -848
  14. package/src/constants/index.ts +5 -5
  15. package/src/contracts.ts +128 -128
  16. package/src/curveUsd/index.ts +229 -229
  17. package/src/exchange/index.ts +17 -17
  18. package/src/helpers/aaveHelpers/index.ts +134 -134
  19. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  20. package/src/helpers/compoundHelpers/index.ts +181 -181
  21. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  22. package/src/helpers/index.ts +7 -7
  23. package/src/helpers/llamaLendHelpers/index.ts +45 -45
  24. package/src/helpers/makerHelpers/index.ts +94 -94
  25. package/src/helpers/morphoBlueHelpers/index.ts +56 -56
  26. package/src/helpers/sparkHelpers/index.ts +106 -106
  27. package/src/index.ts +46 -46
  28. package/src/liquity/index.ts +116 -116
  29. package/src/llamaLend/index.ts +268 -268
  30. package/src/maker/index.ts +117 -117
  31. package/src/markets/aave/index.ts +80 -80
  32. package/src/markets/aave/marketAssets.ts +25 -25
  33. package/src/markets/compound/index.ts +142 -142
  34. package/src/markets/compound/marketsAssets.ts +50 -50
  35. package/src/markets/curveUsd/index.ts +69 -69
  36. package/src/markets/index.ts +5 -5
  37. package/src/markets/llamaLend/contractAddresses.ts +95 -95
  38. package/src/markets/llamaLend/index.ts +150 -150
  39. package/src/markets/morphoBlue/index.ts +462 -462
  40. package/src/markets/spark/index.ts +29 -29
  41. package/src/markets/spark/marketAssets.ts +10 -10
  42. package/src/moneymarket/moneymarketCommonService.ts +75 -75
  43. package/src/morphoAaveV2/index.ts +256 -256
  44. package/src/morphoAaveV3/index.ts +619 -619
  45. package/src/morphoBlue/index.ts +162 -162
  46. package/src/multicall/index.ts +22 -22
  47. package/src/services/dsrService.ts +15 -15
  48. package/src/services/priceService.ts +21 -21
  49. package/src/services/utils.ts +51 -51
  50. package/src/setup.ts +8 -8
  51. package/src/spark/index.ts +433 -422
  52. package/src/staking/staking.ts +198 -198
  53. package/src/types/aave.ts +256 -256
  54. package/src/types/chickenBonds.ts +45 -45
  55. package/src/types/common.ts +84 -84
  56. package/src/types/compound.ts +128 -128
  57. package/src/types/curveUsd.ts +118 -118
  58. package/src/types/index.ts +8 -8
  59. package/src/types/liquity.ts +30 -30
  60. package/src/types/llamaLend.ts +143 -143
  61. package/src/types/maker.ts +50 -50
  62. package/src/types/morphoBlue.ts +129 -129
  63. package/src/types/spark.ts +106 -106
  64. package/yarn-error.log +0 -64
package/README.md CHANGED
@@ -1,63 +1,63 @@
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)
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)
@@ -139,13 +139,13 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
139
139
  let discountRateOnBorrow = '0';
140
140
  if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
141
141
  const facilitatorBucket = yield ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
142
- const availableFacilitatorCap = (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
143
142
  borrowCap = decimal_js_1.default.min(borrowCap, (0, tokens_1.assetAmountInEth)(facilitatorBucket[0], 'GHO')).toString();
144
143
  discountRateOnBorrow = (0, exports.aaveV3CalculateDiscountRate)(tokenMarket.totalBorrow.toString(), '3160881469228662060510133', // stkAAVE total supply
145
144
  discountRate, minDiscountTokenBalance, minGhoBalanceForDiscount, ghoDiscountedPerDiscountToken);
146
145
  }
147
- let marketLiquidity = nativeAsset
148
- ? (0, tokens_1.assetAmountInEth)(new decimal_js_1.default((0, tokens_1.assetAmountInWei)(borrowCap.toString(), 'GHO'))
146
+ const borrowCapInWei = new decimal_js_1.default((0, tokens_1.assetAmountInWei)(borrowCap.toString(), symbol));
147
+ let marketLiquidity = borrowCapInWei.lt(new decimal_js_1.default(tokenMarket.totalSupply)) || nativeAsset
148
+ ? (0, tokens_1.assetAmountInEth)(borrowCapInWei
149
149
  .sub(tokenMarket.totalBorrow.toString())
150
150
  .toString(), symbol)
151
151
  : (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(tokenMarket.totalSupply.toString())
@@ -161,10 +161,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
161
161
  minDiscountTokenBalance,
162
162
  minGhoBalanceForDiscount,
163
163
  },
164
- })), { symbol, isIsolated: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new decimal_js_1.default(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new decimal_js_1.default(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new decimal_js_1.default(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new decimal_js_1.default(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new decimal_js_1.default(tokenMarket.totalBorrow.toString())
165
- .div(new decimal_js_1.default(tokenMarket.totalSupply.toString()))
166
- .times(100)
167
- .toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: (0, tokens_1.assetAmountInEth)(tokenMarket.totalSupply.toString(), symbol), isInactive: !tokenMarket.isActive, isFrozen: tokenMarket.isFrozen, isPaused: tokenMarket.isPaused, canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed, canBeSupplied: !nativeAsset && tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen, canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused, canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused, disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled, totalBorrow: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrowVar.toString(), symbol), price: new decimal_js_1.default(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, eModeCategoryData: {
164
+ })), { symbol, isIsolated: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new decimal_js_1.default(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new decimal_js_1.default(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new decimal_js_1.default(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new decimal_js_1.default(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new decimal_js_1.default(tokenMarket.totalBorrow.toString()).times(100).div(new decimal_js_1.default(tokenMarket.totalSupply.toString())).toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: (0, tokens_1.assetAmountInEth)(tokenMarket.totalSupply.toString(), symbol), isInactive: !tokenMarket.isActive, isFrozen: tokenMarket.isFrozen, isPaused: tokenMarket.isPaused, canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed, canBeSupplied: !nativeAsset && tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen, canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused, canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused, disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled, totalBorrow: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrowVar.toString(), symbol), price: new decimal_js_1.default(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, eModeCategoryData: {
168
165
  label: tokenMarket.label,
169
166
  liquidationBonus: new decimal_js_1.default(tokenMarket.liquidationBonus).div(10000).toString(),
170
167
  liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationThreshold).div(10000).toString(),
@@ -66,54 +66,63 @@ const getSparkMarketsData = (web3, network, selectedMarket, mainnetWeb3) => __aw
66
66
  }
67
67
  const loanInfoContract = (0, contracts_1.SparkViewContract)(web3, network);
68
68
  const loanInfo = yield loanInfoContract.methods.getFullTokensInfo(marketAddress, selectedMarket.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a)).address)).call();
69
- const assetsData = loanInfo
70
- .map((market, i) => ({
71
- symbol: selectedMarket.assets[i],
72
- isIsolated: new decimal_js_1.default(market.debtCeilingForIsolationMode).gt(0),
73
- debtCeilingForIsolationMode: new decimal_js_1.default(market.debtCeilingForIsolationMode).div(100).toString(),
74
- isSiloed: market.isSiloedForBorrowing,
75
- eModeCategory: +market.emodeCategory,
76
- isolationModeTotalDebt: new decimal_js_1.default(market.isolationModeTotalDebt).div(100).toString(),
77
- assetId: Number(market.assetId),
78
- underlyingTokenAddress: market.underlyingTokenAddress,
79
- supplyRate: new decimal_js_1.default(market.supplyRate.toString()).div(1e25).toString(),
80
- borrowRate: new decimal_js_1.default(market.borrowRateVariable.toString()).div(1e25).toString(),
81
- borrowRateStable: new decimal_js_1.default(market.borrowRateStable.toString()).div(1e25).toString(),
82
- collateralFactor: new decimal_js_1.default(market.collateralFactor.toString()).div(10000).toString(),
83
- liquidationRatio: new decimal_js_1.default(market.liquidationRatio.toString()).div(10000).toString(),
84
- marketLiquidity: (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(market.totalSupply.toString())
85
- .sub(market.totalBorrow.toString())
86
- .toString(), selectedMarket.assets[i]),
87
- utilization: new decimal_js_1.default(market.totalBorrow.toString())
88
- .div(new decimal_js_1.default(market.totalSupply.toString()))
89
- .times(100)
90
- .toString(),
91
- usageAsCollateralEnabled: market.usageAsCollateralEnabled,
92
- supplyCap: market.supplyCap,
93
- borrowCap: market.borrowCap,
94
- totalSupply: (0, tokens_1.assetAmountInEth)(market.totalSupply.toString(), selectedMarket.assets[i]),
95
- isInactive: !market.isActive,
96
- isFrozen: market.isFrozen,
97
- isPaused: market.isPaused,
98
- canBeBorrowed: market.isActive && !market.isPaused && !market.isFrozen && market.borrowingEnabled,
99
- canBeSupplied: market.isActive && !market.isPaused && !market.isFrozen,
100
- canBeWithdrawn: market.isActive && !market.isPaused,
101
- canBePayBacked: market.isActive && !market.isPaused,
102
- disabledStableBorrowing: !market.stableBorrowRateEnabled,
103
- totalBorrow: (0, tokens_1.assetAmountInEth)(market.totalBorrow.toString(), selectedMarket.assets[i]),
104
- totalBorrowVar: (0, tokens_1.assetAmountInEth)(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
105
- price: new decimal_js_1.default(market.price.toString()).div(1e8).toString(),
106
- isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
107
- isFlashLoanEnabled: market.isFlashLoanEnabled,
108
- aTokenAddress: market.aTokenAddress,
109
- eModeCategoryData: {
110
- label: market.label,
111
- liquidationBonus: new decimal_js_1.default(market.liquidationBonus).div(10000).toString(),
112
- liquidationRatio: new decimal_js_1.default(market.liquidationThreshold).div(10000).toString(),
113
- collateralFactor: new decimal_js_1.default(market.ltv).div(10000).toString(),
114
- priceSource: market.priceSource,
115
- },
116
- }));
69
+ const assetsData = yield Promise.all(loanInfo
70
+ .map((market, i) => __awaiter(void 0, void 0, void 0, function* () {
71
+ const symbol = selectedMarket.assets[i];
72
+ const borrowCapInWei = new decimal_js_1.default((0, tokens_1.assetAmountInWei)(market.borrowCap.toString(), symbol));
73
+ let marketLiquidity = borrowCapInWei.lt(new decimal_js_1.default(market.totalSupply))
74
+ ? (0, tokens_1.assetAmountInEth)(borrowCapInWei
75
+ .sub(market.totalBorrow.toString())
76
+ .toString(), symbol)
77
+ : (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(market.totalSupply.toString())
78
+ .sub(market.totalBorrow.toString())
79
+ .toString(), symbol);
80
+ if (new decimal_js_1.default(marketLiquidity).lt(0)) {
81
+ marketLiquidity = '0';
82
+ }
83
+ return ({
84
+ symbol: selectedMarket.assets[i],
85
+ isIsolated: new decimal_js_1.default(market.debtCeilingForIsolationMode).gt(0),
86
+ debtCeilingForIsolationMode: new decimal_js_1.default(market.debtCeilingForIsolationMode).div(100).toString(),
87
+ isSiloed: market.isSiloedForBorrowing,
88
+ eModeCategory: +market.emodeCategory,
89
+ isolationModeTotalDebt: new decimal_js_1.default(market.isolationModeTotalDebt).div(100).toString(),
90
+ assetId: Number(market.assetId),
91
+ underlyingTokenAddress: market.underlyingTokenAddress,
92
+ supplyRate: new decimal_js_1.default(market.supplyRate.toString()).div(1e25).toString(),
93
+ borrowRate: new decimal_js_1.default(market.borrowRateVariable.toString()).div(1e25).toString(),
94
+ borrowRateStable: new decimal_js_1.default(market.borrowRateStable.toString()).div(1e25).toString(),
95
+ collateralFactor: new decimal_js_1.default(market.collateralFactor.toString()).div(10000).toString(),
96
+ liquidationRatio: new decimal_js_1.default(market.liquidationRatio.toString()).div(10000).toString(),
97
+ marketLiquidity,
98
+ utilization: new decimal_js_1.default(market.totalBorrow.toString()).times(100).div(new decimal_js_1.default(market.totalSupply.toString())).toString(),
99
+ usageAsCollateralEnabled: market.usageAsCollateralEnabled,
100
+ supplyCap: market.supplyCap,
101
+ borrowCap: market.borrowCap,
102
+ totalSupply: (0, tokens_1.assetAmountInEth)(market.totalSupply.toString(), selectedMarket.assets[i]),
103
+ isInactive: !market.isActive,
104
+ isFrozen: market.isFrozen,
105
+ isPaused: market.isPaused,
106
+ canBeBorrowed: market.isActive && !market.isPaused && !market.isFrozen && market.borrowingEnabled,
107
+ canBeSupplied: market.isActive && !market.isPaused && !market.isFrozen,
108
+ canBeWithdrawn: market.isActive && !market.isPaused,
109
+ canBePayBacked: market.isActive && !market.isPaused,
110
+ disabledStableBorrowing: !market.stableBorrowRateEnabled,
111
+ totalBorrow: (0, tokens_1.assetAmountInEth)(market.totalBorrow.toString(), selectedMarket.assets[i]),
112
+ totalBorrowVar: (0, tokens_1.assetAmountInEth)(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
113
+ price: new decimal_js_1.default(market.price.toString()).div(1e8).toString(),
114
+ isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
115
+ isFlashLoanEnabled: market.isFlashLoanEnabled,
116
+ aTokenAddress: market.aTokenAddress,
117
+ eModeCategoryData: {
118
+ label: market.label,
119
+ liquidationBonus: new decimal_js_1.default(market.liquidationBonus).div(10000).toString(),
120
+ liquidationRatio: new decimal_js_1.default(market.liquidationThreshold).div(10000).toString(),
121
+ collateralFactor: new decimal_js_1.default(market.ltv).div(10000).toString(),
122
+ priceSource: market.priceSource,
123
+ },
124
+ });
125
+ })));
117
126
  yield Promise.all(assetsData.map((market) => __awaiter(void 0, void 0, void 0, function* () {
118
127
  /* eslint-disable no-param-reassign */
119
128
  const rewardForMarket = rewardInfo[market.underlyingTokenAddress];
@@ -130,13 +130,13 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
130
130
  let discountRateOnBorrow = '0';
131
131
  if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
132
132
  const facilitatorBucket = yield ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
133
- const availableFacilitatorCap = assetAmountInEth(new Dec(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
134
133
  borrowCap = Dec.min(borrowCap, assetAmountInEth(facilitatorBucket[0], 'GHO')).toString();
135
134
  discountRateOnBorrow = aaveV3CalculateDiscountRate(tokenMarket.totalBorrow.toString(), '3160881469228662060510133', // stkAAVE total supply
136
135
  discountRate, minDiscountTokenBalance, minGhoBalanceForDiscount, ghoDiscountedPerDiscountToken);
137
136
  }
138
- let marketLiquidity = nativeAsset
139
- ? assetAmountInEth(new Dec(assetAmountInWei(borrowCap.toString(), 'GHO'))
137
+ const borrowCapInWei = new Dec(assetAmountInWei(borrowCap.toString(), symbol));
138
+ let marketLiquidity = borrowCapInWei.lt(new Dec(tokenMarket.totalSupply)) || nativeAsset
139
+ ? assetAmountInEth(borrowCapInWei
140
140
  .sub(tokenMarket.totalBorrow.toString())
141
141
  .toString(), symbol)
142
142
  : assetAmountInEth(new Dec(tokenMarket.totalSupply.toString())
@@ -152,10 +152,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
152
152
  minDiscountTokenBalance,
153
153
  minGhoBalanceForDiscount,
154
154
  },
155
- })), { symbol, isIsolated: new Dec(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new Dec(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new Dec(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new Dec(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new Dec(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new Dec(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new Dec(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new Dec(tokenMarket.totalBorrow.toString())
156
- .div(new Dec(tokenMarket.totalSupply.toString()))
157
- .times(100)
158
- .toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: assetAmountInEth(tokenMarket.totalSupply.toString(), symbol), isInactive: !tokenMarket.isActive, isFrozen: tokenMarket.isFrozen, isPaused: tokenMarket.isPaused, canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed, canBeSupplied: !nativeAsset && tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen, canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused, canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused, disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled, totalBorrow: assetAmountInEth(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: assetAmountInEth(tokenMarket.totalBorrowVar.toString(), symbol), price: new Dec(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, eModeCategoryData: {
155
+ })), { symbol, isIsolated: new Dec(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new Dec(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new Dec(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new Dec(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new Dec(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new Dec(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new Dec(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new Dec(tokenMarket.totalBorrow.toString()).times(100).div(new Dec(tokenMarket.totalSupply.toString())).toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: assetAmountInEth(tokenMarket.totalSupply.toString(), symbol), isInactive: !tokenMarket.isActive, isFrozen: tokenMarket.isFrozen, isPaused: tokenMarket.isPaused, canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed, canBeSupplied: !nativeAsset && tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen, canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused, canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused, disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled, totalBorrow: assetAmountInEth(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: assetAmountInEth(tokenMarket.totalBorrowVar.toString(), symbol), price: new Dec(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, eModeCategoryData: {
159
156
  label: tokenMarket.label,
160
157
  liquidationBonus: new Dec(tokenMarket.liquidationBonus).div(10000).toString(),
161
158
  liquidationRatio: new Dec(tokenMarket.liquidationThreshold).div(10000).toString(),
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
- import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
11
+ import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
12
12
  import { ethToWeth, getAbiItem, isLayer2Network, wethToEth, wethToEthByAddress, } from '../services/utils';
13
13
  import { calculateNetApy, getCbETHApr, getREthApr, getStETHApr, } from '../staking';
14
14
  import { getDsrApy } from '../services/dsrService';
@@ -59,54 +59,63 @@ export const getSparkMarketsData = (web3, network, selectedMarket, mainnetWeb3)
59
59
  }
60
60
  const loanInfoContract = SparkViewContract(web3, network);
61
61
  const loanInfo = yield loanInfoContract.methods.getFullTokensInfo(marketAddress, selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address)).call();
62
- const assetsData = loanInfo
63
- .map((market, i) => ({
64
- symbol: selectedMarket.assets[i],
65
- isIsolated: new Dec(market.debtCeilingForIsolationMode).gt(0),
66
- debtCeilingForIsolationMode: new Dec(market.debtCeilingForIsolationMode).div(100).toString(),
67
- isSiloed: market.isSiloedForBorrowing,
68
- eModeCategory: +market.emodeCategory,
69
- isolationModeTotalDebt: new Dec(market.isolationModeTotalDebt).div(100).toString(),
70
- assetId: Number(market.assetId),
71
- underlyingTokenAddress: market.underlyingTokenAddress,
72
- supplyRate: new Dec(market.supplyRate.toString()).div(1e25).toString(),
73
- borrowRate: new Dec(market.borrowRateVariable.toString()).div(1e25).toString(),
74
- borrowRateStable: new Dec(market.borrowRateStable.toString()).div(1e25).toString(),
75
- collateralFactor: new Dec(market.collateralFactor.toString()).div(10000).toString(),
76
- liquidationRatio: new Dec(market.liquidationRatio.toString()).div(10000).toString(),
77
- marketLiquidity: assetAmountInEth(new Dec(market.totalSupply.toString())
78
- .sub(market.totalBorrow.toString())
79
- .toString(), selectedMarket.assets[i]),
80
- utilization: new Dec(market.totalBorrow.toString())
81
- .div(new Dec(market.totalSupply.toString()))
82
- .times(100)
83
- .toString(),
84
- usageAsCollateralEnabled: market.usageAsCollateralEnabled,
85
- supplyCap: market.supplyCap,
86
- borrowCap: market.borrowCap,
87
- totalSupply: assetAmountInEth(market.totalSupply.toString(), selectedMarket.assets[i]),
88
- isInactive: !market.isActive,
89
- isFrozen: market.isFrozen,
90
- isPaused: market.isPaused,
91
- canBeBorrowed: market.isActive && !market.isPaused && !market.isFrozen && market.borrowingEnabled,
92
- canBeSupplied: market.isActive && !market.isPaused && !market.isFrozen,
93
- canBeWithdrawn: market.isActive && !market.isPaused,
94
- canBePayBacked: market.isActive && !market.isPaused,
95
- disabledStableBorrowing: !market.stableBorrowRateEnabled,
96
- totalBorrow: assetAmountInEth(market.totalBorrow.toString(), selectedMarket.assets[i]),
97
- totalBorrowVar: assetAmountInEth(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
98
- price: new Dec(market.price.toString()).div(1e8).toString(),
99
- isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
100
- isFlashLoanEnabled: market.isFlashLoanEnabled,
101
- aTokenAddress: market.aTokenAddress,
102
- eModeCategoryData: {
103
- label: market.label,
104
- liquidationBonus: new Dec(market.liquidationBonus).div(10000).toString(),
105
- liquidationRatio: new Dec(market.liquidationThreshold).div(10000).toString(),
106
- collateralFactor: new Dec(market.ltv).div(10000).toString(),
107
- priceSource: market.priceSource,
108
- },
109
- }));
62
+ const assetsData = yield Promise.all(loanInfo
63
+ .map((market, i) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const symbol = selectedMarket.assets[i];
65
+ const borrowCapInWei = new Dec(assetAmountInWei(market.borrowCap.toString(), symbol));
66
+ let marketLiquidity = borrowCapInWei.lt(new Dec(market.totalSupply))
67
+ ? assetAmountInEth(borrowCapInWei
68
+ .sub(market.totalBorrow.toString())
69
+ .toString(), symbol)
70
+ : assetAmountInEth(new Dec(market.totalSupply.toString())
71
+ .sub(market.totalBorrow.toString())
72
+ .toString(), symbol);
73
+ if (new Dec(marketLiquidity).lt(0)) {
74
+ marketLiquidity = '0';
75
+ }
76
+ return ({
77
+ symbol: selectedMarket.assets[i],
78
+ isIsolated: new Dec(market.debtCeilingForIsolationMode).gt(0),
79
+ debtCeilingForIsolationMode: new Dec(market.debtCeilingForIsolationMode).div(100).toString(),
80
+ isSiloed: market.isSiloedForBorrowing,
81
+ eModeCategory: +market.emodeCategory,
82
+ isolationModeTotalDebt: new Dec(market.isolationModeTotalDebt).div(100).toString(),
83
+ assetId: Number(market.assetId),
84
+ underlyingTokenAddress: market.underlyingTokenAddress,
85
+ supplyRate: new Dec(market.supplyRate.toString()).div(1e25).toString(),
86
+ borrowRate: new Dec(market.borrowRateVariable.toString()).div(1e25).toString(),
87
+ borrowRateStable: new Dec(market.borrowRateStable.toString()).div(1e25).toString(),
88
+ collateralFactor: new Dec(market.collateralFactor.toString()).div(10000).toString(),
89
+ liquidationRatio: new Dec(market.liquidationRatio.toString()).div(10000).toString(),
90
+ marketLiquidity,
91
+ utilization: new Dec(market.totalBorrow.toString()).times(100).div(new Dec(market.totalSupply.toString())).toString(),
92
+ usageAsCollateralEnabled: market.usageAsCollateralEnabled,
93
+ supplyCap: market.supplyCap,
94
+ borrowCap: market.borrowCap,
95
+ totalSupply: assetAmountInEth(market.totalSupply.toString(), selectedMarket.assets[i]),
96
+ isInactive: !market.isActive,
97
+ isFrozen: market.isFrozen,
98
+ isPaused: market.isPaused,
99
+ canBeBorrowed: market.isActive && !market.isPaused && !market.isFrozen && market.borrowingEnabled,
100
+ canBeSupplied: market.isActive && !market.isPaused && !market.isFrozen,
101
+ canBeWithdrawn: market.isActive && !market.isPaused,
102
+ canBePayBacked: market.isActive && !market.isPaused,
103
+ disabledStableBorrowing: !market.stableBorrowRateEnabled,
104
+ totalBorrow: assetAmountInEth(market.totalBorrow.toString(), selectedMarket.assets[i]),
105
+ totalBorrowVar: assetAmountInEth(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
106
+ price: new Dec(market.price.toString()).div(1e8).toString(),
107
+ isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
108
+ isFlashLoanEnabled: market.isFlashLoanEnabled,
109
+ aTokenAddress: market.aTokenAddress,
110
+ eModeCategoryData: {
111
+ label: market.label,
112
+ liquidationBonus: new Dec(market.liquidationBonus).div(10000).toString(),
113
+ liquidationRatio: new Dec(market.liquidationThreshold).div(10000).toString(),
114
+ collateralFactor: new Dec(market.ltv).div(10000).toString(),
115
+ priceSource: market.priceSource,
116
+ },
117
+ });
118
+ })));
110
119
  yield Promise.all(assetsData.map((market) => __awaiter(void 0, void 0, void 0, function* () {
111
120
  /* eslint-disable no-param-reassign */
112
121
  const rewardForMarket = rewardInfo[market.underlyingTokenAddress];
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@defisaver/positions-sdk",
3
- "version": "0.0.80",
4
- "description": "",
5
- "main": "./cjs/index.js",
6
- "module": "./esm/index.js",
7
- "types": "./esm/index.d.ts",
8
- "scripts": {
9
- "build:esm": "rm -rf esm && tsc -p tsconfig.json",
10
- "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
11
- "build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
12
- "dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
13
- "lint": "eslint src/ --fix",
14
- "generate-contracts": "node scripts/generateContracts.js",
15
- "test": "mocha tests/*",
16
- "build-test": "npm run build && mocha tests/*"
17
- },
18
- "keywords": [],
19
- "author": "",
20
- "license": "ISC",
21
- "dependencies": {
22
- "@defisaver/tokens": "^1.5.22",
23
- "@ethersproject/bignumber": "^5.7.0",
24
- "@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
25
- "@stakewise/v3-sdk": "^1.3.0",
26
- "decimal.js": "^10.4.3"
27
- },
28
- "devDependencies": {
29
- "@defisaver/eslint-config": "^1.0.1",
30
- "chai": "^4.3.8",
31
- "dotenv": "^16.3.1",
32
- "eslint": "^8.49.0",
33
- "mocha": "^10.2.0",
34
- "typechain": "^8.3.1",
35
- "typechain-target-web3-v1-3mihai3": "^6.0.2",
36
- "typescript": "^5.2.2"
37
- },
38
- "peerDependencies": {
39
- "web3": "^1.10.2"
40
- }
41
- }
1
+ {
2
+ "name": "@defisaver/positions-sdk",
3
+ "version": "0.0.81",
4
+ "description": "",
5
+ "main": "./cjs/index.js",
6
+ "module": "./esm/index.js",
7
+ "types": "./esm/index.d.ts",
8
+ "scripts": {
9
+ "build:esm": "rm -rf esm && tsc -p tsconfig.json",
10
+ "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
11
+ "build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
12
+ "dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
13
+ "lint": "eslint src/ --fix",
14
+ "generate-contracts": "node scripts/generateContracts.js",
15
+ "test": "mocha tests/*",
16
+ "build-test": "npm run build && mocha tests/*"
17
+ },
18
+ "keywords": [],
19
+ "author": "",
20
+ "license": "ISC",
21
+ "dependencies": {
22
+ "@defisaver/tokens": "^1.5.22",
23
+ "@ethersproject/bignumber": "^5.7.0",
24
+ "@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
25
+ "@stakewise/v3-sdk": "^1.3.0",
26
+ "decimal.js": "^10.4.3"
27
+ },
28
+ "devDependencies": {
29
+ "@defisaver/eslint-config": "^1.0.1",
30
+ "chai": "^4.3.8",
31
+ "dotenv": "^16.3.1",
32
+ "eslint": "^8.49.0",
33
+ "mocha": "^10.2.0",
34
+ "typechain": "^8.3.1",
35
+ "typechain-target-web3-v1-3mihai3": "^6.0.2",
36
+ "typescript": "^5.2.2"
37
+ },
38
+ "peerDependencies": {
39
+ "web3": "^1.10.2"
40
+ }
41
+ }