@defisaver/positions-sdk 0.0.97 → 0.0.99

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 (74) hide show
  1. package/README.md +63 -63
  2. package/cjs/config/contracts.d.ts +45 -1
  3. package/cjs/config/contracts.js +3 -3
  4. package/cjs/helpers/morphoBlueHelpers/index.d.ts +9 -2
  5. package/cjs/helpers/morphoBlueHelpers/index.js +66 -1
  6. package/cjs/morphoBlue/index.d.ts +2 -1
  7. package/cjs/morphoBlue/index.js +33 -28
  8. package/cjs/types/contracts/generated/MorphoBlueView.d.ts +61 -0
  9. package/esm/config/contracts.d.ts +45 -1
  10. package/esm/config/contracts.js +3 -3
  11. package/esm/helpers/morphoBlueHelpers/index.d.ts +9 -2
  12. package/esm/helpers/morphoBlueHelpers/index.js +62 -0
  13. package/esm/morphoBlue/index.d.ts +2 -1
  14. package/esm/morphoBlue/index.js +32 -28
  15. package/esm/types/contracts/generated/MorphoBlueView.d.ts +61 -0
  16. package/package.json +40 -40
  17. package/src/aaveV2/index.ts +227 -227
  18. package/src/aaveV3/index.ts +558 -558
  19. package/src/assets/index.ts +60 -60
  20. package/src/chickenBonds/index.ts +123 -123
  21. package/src/compoundV2/index.ts +219 -219
  22. package/src/compoundV3/index.ts +266 -266
  23. package/src/config/contracts.js +848 -848
  24. package/src/constants/index.ts +5 -5
  25. package/src/contracts.ts +128 -128
  26. package/src/curveUsd/index.ts +229 -229
  27. package/src/exchange/index.ts +17 -17
  28. package/src/helpers/aaveHelpers/index.ts +134 -134
  29. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  30. package/src/helpers/compoundHelpers/index.ts +181 -181
  31. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  32. package/src/helpers/index.ts +7 -7
  33. package/src/helpers/llamaLendHelpers/index.ts +45 -45
  34. package/src/helpers/makerHelpers/index.ts +94 -94
  35. package/src/helpers/morphoBlueHelpers/index.ts +117 -56
  36. package/src/helpers/sparkHelpers/index.ts +106 -106
  37. package/src/index.ts +46 -46
  38. package/src/liquity/index.ts +116 -116
  39. package/src/llamaLend/index.ts +268 -268
  40. package/src/maker/index.ts +117 -117
  41. package/src/markets/aave/index.ts +80 -80
  42. package/src/markets/aave/marketAssets.ts +24 -24
  43. package/src/markets/compound/index.ts +142 -142
  44. package/src/markets/compound/marketsAssets.ts +50 -50
  45. package/src/markets/curveUsd/index.ts +69 -69
  46. package/src/markets/index.ts +5 -5
  47. package/src/markets/llamaLend/contractAddresses.ts +95 -95
  48. package/src/markets/llamaLend/index.ts +150 -150
  49. package/src/markets/morphoBlue/index.ts +611 -611
  50. package/src/markets/spark/index.ts +29 -29
  51. package/src/markets/spark/marketAssets.ts +10 -10
  52. package/src/moneymarket/moneymarketCommonService.ts +76 -76
  53. package/src/morphoAaveV2/index.ts +256 -256
  54. package/src/morphoAaveV3/index.ts +612 -612
  55. package/src/morphoBlue/index.ts +171 -162
  56. package/src/multicall/index.ts +22 -22
  57. package/src/services/dsrService.ts +15 -15
  58. package/src/services/priceService.ts +21 -21
  59. package/src/services/utils.ts +51 -51
  60. package/src/setup.ts +8 -8
  61. package/src/spark/index.ts +424 -424
  62. package/src/staking/staking.ts +187 -187
  63. package/src/types/aave.ts +256 -256
  64. package/src/types/chickenBonds.ts +45 -45
  65. package/src/types/common.ts +84 -84
  66. package/src/types/compound.ts +128 -128
  67. package/src/types/contracts/generated/MorphoBlueView.ts +87 -0
  68. package/src/types/curveUsd.ts +118 -118
  69. package/src/types/index.ts +8 -8
  70. package/src/types/liquity.ts +30 -30
  71. package/src/types/llamaLend.ts +143 -143
  72. package/src/types/maker.ts +50 -50
  73. package/src/types/morphoBlue.ts +139 -139
  74. package/src/types/spark.ts +106 -106
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)
@@ -4457,6 +4457,32 @@ export namespace USDCPriceFeed {
4457
4457
  export namespace MorphoBlueView {
4458
4458
  let abi_66: ({
4459
4459
  inputs: {
4460
+ components: ({
4461
+ components: {
4462
+ internalType: string;
4463
+ name: string;
4464
+ type: string;
4465
+ }[];
4466
+ internalType: string;
4467
+ name: string;
4468
+ type: string;
4469
+ } | {
4470
+ internalType: string;
4471
+ name: string;
4472
+ type: string;
4473
+ components?: undefined;
4474
+ })[];
4475
+ internalType: string;
4476
+ name: string;
4477
+ type: string;
4478
+ }[];
4479
+ name: string;
4480
+ outputs: ({
4481
+ internalType: string;
4482
+ name: string;
4483
+ type: string;
4484
+ components?: undefined;
4485
+ } | {
4460
4486
  components: {
4461
4487
  internalType: string;
4462
4488
  name: string;
@@ -4465,7 +4491,25 @@ export namespace MorphoBlueView {
4465
4491
  internalType: string;
4466
4492
  name: string;
4467
4493
  type: string;
4468
- }[];
4494
+ })[];
4495
+ stateMutability: string;
4496
+ type: string;
4497
+ } | {
4498
+ inputs: ({
4499
+ internalType: string;
4500
+ name: string;
4501
+ type: string;
4502
+ components?: undefined;
4503
+ } | {
4504
+ components: {
4505
+ internalType: string;
4506
+ name: string;
4507
+ type: string;
4508
+ }[];
4509
+ internalType: string;
4510
+ name: string;
4511
+ type: string;
4512
+ })[];
4469
4513
  name: string;
4470
4514
  outputs: {
4471
4515
  internalType: string;
@@ -819,13 +819,13 @@ module.exports = {
819
819
  }
820
820
  },
821
821
  "MorphoBlueView": {
822
- "abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
822
+ "abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "bool", "name": "isBorrowOperation", "type": "bool" }, { "internalType": "uint256", "name": "liquidityAdded", "type": "uint256" }, { "internalType": "uint256", "name": "liquidityRemoved", "type": "uint256" }], "internalType": "struct MorphoBlueView.LiquidityChangeParams", "name": "params", "type": "tuple" }], "name": "getApyAfterValuesEstimation", "outputs": [{ "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "components": [{ "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint128", "name": "lastUpdate", "type": "uint128" }, { "internalType": "uint128", "name": "fee", "type": "uint128" }], "internalType": "struct Market", "name": "market", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatio", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingId", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingParams", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
823
823
  "networks": {
824
824
  "1": {
825
- "address": "0xE29175a86B60138403a9534A391acaDb19f1E9a6",
825
+ "address": "0x10B621823D4f3E85fBDF759e252598e4e097C1fd",
826
826
  },
827
827
  "8453": {
828
- "address": "0xDBCACF59C5063da8B15481F88E7D70E13c92f2a1",
828
+ "address": "0x53c0E962bd0AC53928ca04703238b2ec2894195B",
829
829
  }
830
830
  }
831
831
  },
@@ -1,7 +1,14 @@
1
- import { MMUsedAssets } from '../../types/common';
2
- import { MorphoBlueAggregatedPositionData, MorphoBlueAssetsData, MorphoBlueMarketInfo } from '../../types';
1
+ import Web3 from 'web3';
2
+ import { MMUsedAssets, NetworkNumber } from '../../types/common';
3
+ import { MorphoBlueAggregatedPositionData, MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo } from '../../types';
3
4
  export declare const getMorphoBlueAggregatedPositionData: ({ usedAssets, assetsData, marketInfo }: {
4
5
  usedAssets: MMUsedAssets;
5
6
  assetsData: MorphoBlueAssetsData;
6
7
  marketInfo: MorphoBlueMarketInfo;
7
8
  }) => MorphoBlueAggregatedPositionData;
9
+ export declare const getSupplyRate: (totalSupplyAssets: string, totalBorrowAssets: string, borrowRate: string, fee: string) => string;
10
+ export declare const getBorrowRate: (borrowRate: string, totalBorrowShares: string) => string;
11
+ export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMarketData, action: string, amount: string, asset: string, web3: Web3, network: NetworkNumber) => Promise<{
12
+ borrowRate: string;
13
+ supplyRate: string;
14
+ }>;
@@ -1,12 +1,24 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getMorphoBlueAggregatedPositionData = void 0;
15
+ exports.getApyAfterValuesEstimation = exports.getBorrowRate = exports.getSupplyRate = exports.getMorphoBlueAggregatedPositionData = void 0;
7
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const tokens_1 = require("@defisaver/tokens");
8
18
  const moneymarket_1 = require("../../moneymarket");
9
19
  const staking_1 = require("../../staking");
20
+ const constants_1 = require("../../constants");
21
+ const contracts_1 = require("../../contracts");
10
22
  const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, marketInfo }) => {
11
23
  var _a, _b, _c, _d, _e, _f;
12
24
  const payload = {};
@@ -46,3 +58,56 @@ const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, marketInf
46
58
  return payload;
47
59
  };
48
60
  exports.getMorphoBlueAggregatedPositionData = getMorphoBlueAggregatedPositionData;
61
+ const compound = (ratePerSeconds) => {
62
+ const compounding = new decimal_js_1.default(ratePerSeconds).mul(constants_1.SECONDS_PER_YEAR).toString();
63
+ const apyNumber = Math.expm1(new decimal_js_1.default(compounding).div(constants_1.WAD).toNumber());
64
+ return new decimal_js_1.default(apyNumber).mul(constants_1.WAD).floor().toString();
65
+ };
66
+ const getSupplyRate = (totalSupplyAssets, totalBorrowAssets, borrowRate, fee) => {
67
+ if (totalBorrowAssets === '0' || totalSupplyAssets === '0') {
68
+ return '0';
69
+ }
70
+ const utillization = new decimal_js_1.default(totalBorrowAssets).mul(constants_1.WAD).div(totalSupplyAssets).ceil()
71
+ .toString();
72
+ const supplyRate = new decimal_js_1.default(utillization).mul(borrowRate).div(constants_1.WAD).ceil()
73
+ .toString();
74
+ const ratePerSecond = new decimal_js_1.default(supplyRate).mul(new decimal_js_1.default(constants_1.WAD).minus(fee)).div(constants_1.WAD).ceil()
75
+ .toString();
76
+ return new decimal_js_1.default(compound(ratePerSecond)).div(1e18).mul(100).toString();
77
+ };
78
+ exports.getSupplyRate = getSupplyRate;
79
+ const getBorrowRate = (borrowRate, totalBorrowShares) => {
80
+ if (totalBorrowShares === '0') {
81
+ return '0';
82
+ }
83
+ return new decimal_js_1.default(compound(borrowRate)).div(1e18).mul(100).toString();
84
+ };
85
+ exports.getBorrowRate = getBorrowRate;
86
+ const borrowOperations = ['borrow', 'payback'];
87
+ const getApyAfterValuesEstimation = (selectedMarket, action, amount, asset, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
88
+ const morphoBlueViewContract = (0, contracts_1.MorphoBlueViewContract)(web3, network);
89
+ const lltvInWei = (0, tokens_1.assetAmountInWei)(selectedMarket.lltv, 'ETH');
90
+ const marketData = [selectedMarket.loanToken, selectedMarket.collateralToken, selectedMarket.oracle, selectedMarket.irm, lltvInWei];
91
+ const isBorrowOperation = borrowOperations.includes(action);
92
+ const amountInWei = (0, tokens_1.assetAmountInWei)(amount, asset);
93
+ let liquidityAdded;
94
+ let liquidityRemoved;
95
+ if (isBorrowOperation) {
96
+ liquidityAdded = action === 'payback' ? amountInWei : '0';
97
+ liquidityRemoved = action === 'borrow' ? amountInWei : '0';
98
+ }
99
+ else {
100
+ liquidityAdded = action === 'collateral' ? amountInWei : '0';
101
+ liquidityRemoved = action === 'withdraw' ? amountInWei : '0';
102
+ }
103
+ const data = yield morphoBlueViewContract.methods.getApyAfterValuesEstimation([
104
+ marketData,
105
+ isBorrowOperation,
106
+ liquidityAdded,
107
+ liquidityRemoved,
108
+ ]).call();
109
+ const borrowRate = (0, exports.getBorrowRate)(data.borrowRate, data.market.totalBorrowShares);
110
+ const supplyRate = (0, exports.getSupplyRate)(data.market.totalSupplyAssets, data.market.totalBorrowAssets, data.borrowRate, data.market.fee);
111
+ return { borrowRate, supplyRate };
112
+ });
113
+ exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
@@ -1,5 +1,6 @@
1
1
  import Web3 from 'web3';
2
- import { NetworkNumber } from '../types/common';
2
+ import { Blockish, EthAddress, NetworkNumber, PositionBalances } from '../types/common';
3
3
  import { MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBluePositionData } from '../types';
4
4
  export declare function getMorphoBlueMarketData(web3: Web3, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, mainnetWeb3: Web3): Promise<MorphoBlueMarketInfo>;
5
+ export declare const getMorphoBlueAccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
5
6
  export declare function getMorphoBlueAccountData(web3: Web3, network: NetworkNumber, account: string, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getMorphoBlueAccountData = exports.getMorphoBlueMarketData = void 0;
15
+ exports.getMorphoBlueAccountData = exports.getMorphoBlueAccountBalances = exports.getMorphoBlueMarketData = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const tokens_1 = require("@defisaver/tokens");
18
18
  const common_1 = require("../types/common");
@@ -21,29 +21,6 @@ const constants_1 = require("../constants");
21
21
  const staking_1 = require("../staking");
22
22
  const utils_1 = require("../services/utils");
23
23
  const morphoBlueHelpers_1 = require("../helpers/morphoBlueHelpers");
24
- const compound = (ratePerSeconds) => {
25
- const compounding = new decimal_js_1.default(ratePerSeconds).mul(constants_1.SECONDS_PER_YEAR).toString();
26
- const apyNumber = Math.expm1(new decimal_js_1.default(compounding).div(constants_1.WAD).toNumber());
27
- return new decimal_js_1.default(apyNumber).mul(constants_1.WAD).floor().toString();
28
- };
29
- const getSupplyRate = (totalSupplyAssets, totalBorrowAssets, borrowRate, fee) => {
30
- if (totalBorrowAssets === '0' || totalSupplyAssets === '0') {
31
- return 0;
32
- }
33
- const utillization = new decimal_js_1.default(totalBorrowAssets).mul(constants_1.WAD).div(totalSupplyAssets).ceil()
34
- .toString();
35
- const supplyRate = new decimal_js_1.default(utillization).mul(borrowRate).div(constants_1.WAD).ceil()
36
- .toString();
37
- const ratePerSecond = new decimal_js_1.default(supplyRate).mul(new decimal_js_1.default(constants_1.WAD).minus(fee)).div(constants_1.WAD).ceil()
38
- .toString();
39
- return compound(ratePerSecond);
40
- };
41
- const getBorrowRate = (borrowRate, totalBorrowShares) => {
42
- if (totalBorrowShares === '0') {
43
- return 0;
44
- }
45
- return compound(borrowRate);
46
- };
47
24
  function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
48
25
  return __awaiter(this, void 0, void 0, function* () {
49
26
  const { loanToken, collateralToken, oracle, irm, lltv, oracleType, } = selectedMarket;
@@ -61,8 +38,8 @@ function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
61
38
  loanTokenInfo.symbol === 'USDA' ? '100000000' : feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, constants_1.USD_QUOTE).call(),
62
39
  morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
63
40
  ]);
64
- const supplyRate = getSupplyRate(marketInfo.totalSupplyAssets, marketInfo.totalBorrowAssets, marketInfo.borrowRate, marketInfo.fee);
65
- const compoundedBorrowRate = getBorrowRate(marketInfo.borrowRate, marketInfo.totalBorrowShares);
41
+ const supplyRate = (0, morphoBlueHelpers_1.getSupplyRate)(marketInfo.totalSupplyAssets, marketInfo.totalBorrowAssets, marketInfo.borrowRate, marketInfo.fee);
42
+ const compoundedBorrowRate = (0, morphoBlueHelpers_1.getBorrowRate)(marketInfo.borrowRate, marketInfo.totalBorrowShares);
66
43
  const utillization = new decimal_js_1.default(marketInfo.totalBorrowAssets).div(marketInfo.totalSupplyAssets).mul(100).toString();
67
44
  const oracleScaleFactor = new decimal_js_1.default(36).add(loanTokenInfo.decimals).sub(collateralTokenInfo.decimals).toString();
68
45
  const oracleScale = new decimal_js_1.default(10).pow(oracleScaleFactor).toString();
@@ -73,8 +50,8 @@ function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
73
50
  symbol: (0, utils_1.wethToEth)(loanTokenInfo.symbol),
74
51
  address: loanToken,
75
52
  price: new decimal_js_1.default(loanTokenPrice).div(1e8).toString(),
76
- supplyRate: new decimal_js_1.default(supplyRate).div(constants_1.WAD).mul(100).toString(),
77
- borrowRate: new decimal_js_1.default(compoundedBorrowRate).div(constants_1.WAD).mul(100).toString(),
53
+ supplyRate,
54
+ borrowRate: compoundedBorrowRate,
78
55
  totalSupply: new decimal_js_1.default(marketInfo.totalSupplyAssets).div(scale).toString(),
79
56
  totalBorrow: new decimal_js_1.default(marketInfo.totalBorrowAssets).div(scale).toString(),
80
57
  canBeSupplied: true,
@@ -108,6 +85,34 @@ function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
108
85
  });
109
86
  }
110
87
  exports.getMorphoBlueMarketData = getMorphoBlueMarketData;
88
+ const getMorphoBlueAccountBalances = (web3, network, block, addressMapping, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
89
+ let balances = {
90
+ collateral: {},
91
+ debt: {},
92
+ };
93
+ if (!address) {
94
+ return balances;
95
+ }
96
+ const viewContract = (0, contracts_1.MorphoBlueViewContract)(web3, network, block);
97
+ const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
98
+ const lltvInWei = new decimal_js_1.default(lltv).mul(constants_1.WAD).toString();
99
+ const marketObject = {
100
+ loanToken, collateralToken, oracle, irm, lltv: lltvInWei,
101
+ };
102
+ const loanInfo = yield viewContract.methods.getUserInfo(marketObject, address).call({}, block);
103
+ const loanTokenInfo = (0, tokens_1.getAssetInfoByAddress)(selectedMarket.loanToken, network);
104
+ const collateralTokenInfo = (0, tokens_1.getAssetInfoByAddress)(selectedMarket.collateralToken, network);
105
+ balances = {
106
+ collateral: {
107
+ [addressMapping ? collateralTokenInfo.address.toLowerCase() : (0, utils_1.wethToEth)(collateralTokenInfo.symbol)]: (0, tokens_1.assetAmountInEth)(loanInfo.collateral, collateralTokenInfo.symbol),
108
+ },
109
+ debt: {
110
+ [addressMapping ? loanTokenInfo.address.toLowerCase() : (0, utils_1.wethToEth)(loanTokenInfo.symbol)]: (0, tokens_1.assetAmountInEth)(loanInfo.borrowedInAssets, loanTokenInfo.symbol),
111
+ },
112
+ };
113
+ return balances;
114
+ });
115
+ exports.getMorphoBlueAccountBalances = getMorphoBlueAccountBalances;
111
116
  function getMorphoBlueAccountData(web3, network, account, selectedMarket, marketInfo) {
112
117
  return __awaiter(this, void 0, void 0, function* () {
113
118
  const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
@@ -31,7 +31,58 @@ export type MarketParamsStructOutputStruct = {
31
31
  lltv: string;
32
32
  };
33
33
  export type MarketParamsStructOutput = MarketParamsStructOutputArray & MarketParamsStructOutputStruct;
34
+ export type MarketStruct = [
35
+ number | string | BN,
36
+ number | string | BN,
37
+ number | string | BN,
38
+ number | string | BN,
39
+ number | string | BN,
40
+ number | string | BN
41
+ ] | {
42
+ totalSupplyAssets: number | string | BN;
43
+ totalSupplyShares: number | string | BN;
44
+ totalBorrowAssets: number | string | BN;
45
+ totalBorrowShares: number | string | BN;
46
+ lastUpdate: number | string | BN;
47
+ fee: number | string | BN;
48
+ };
49
+ export type MarketStructOutputArray = [
50
+ string,
51
+ string,
52
+ string,
53
+ string,
54
+ string,
55
+ string
56
+ ];
57
+ export type MarketStructOutputStruct = {
58
+ totalSupplyAssets: string;
59
+ totalSupplyShares: string;
60
+ totalBorrowAssets: string;
61
+ totalBorrowShares: string;
62
+ lastUpdate: string;
63
+ fee: string;
64
+ };
65
+ export type MarketStructOutput = MarketStructOutputArray & MarketStructOutputStruct;
34
66
  export declare namespace MorphoBlueView {
67
+ type LiquidityChangeParamsStruct = [MarketParamsStruct, boolean, number | string | BN, number | string | BN] | {
68
+ marketParams: MarketParamsStruct;
69
+ isBorrowOperation: boolean;
70
+ liquidityAdded: number | string | BN;
71
+ liquidityRemoved: number | string | BN;
72
+ };
73
+ type LiquidityChangeParamsStructOutputArray = [
74
+ MarketParamsStructOutput,
75
+ boolean,
76
+ string,
77
+ string
78
+ ];
79
+ type LiquidityChangeParamsStructOutputStruct = {
80
+ marketParams: MarketParamsStructOutput;
81
+ isBorrowOperation: boolean;
82
+ liquidityAdded: string;
83
+ liquidityRemoved: string;
84
+ };
85
+ type LiquidityChangeParamsStructOutput = LiquidityChangeParamsStructOutputArray & LiquidityChangeParamsStructOutputStruct;
35
86
  type MarketInfoStruct = [
36
87
  string | number[],
37
88
  number | string | BN,
@@ -110,9 +161,19 @@ export interface MorphoBlueView extends BaseContract {
110
161
  clone(): MorphoBlueView;
111
162
  methods: {
112
163
  MORPHO_BLUE_ADDRESS(): NonPayableTransactionObject<string>;
164
+ getApyAfterValuesEstimation(params: MorphoBlueView.LiquidityChangeParamsStruct): NonPayableTransactionObject<[
165
+ string,
166
+ MarketStructOutput
167
+ ] & {
168
+ borrowRate: string;
169
+ market: MarketStructOutput;
170
+ }>;
113
171
  getMarketId(marketParams: MarketParamsStruct): NonPayableTransactionObject<string>;
114
172
  getMarketInfo(marketParams: MarketParamsStruct): NonPayableTransactionObject<MorphoBlueView.MarketInfoStructOutput>;
115
173
  getMarketInfoNotTuple(loanToken: string, collToken: string, oracle: string, irm: string, lltv: number | string | BN): NonPayableTransactionObject<MorphoBlueView.MarketInfoStructOutput>;
174
+ getRatio(marketId: string | number[], marketParams: MarketParamsStruct, owner: string): NonPayableTransactionObject<string>;
175
+ getRatioUsingId(marketId: string | number[], owner: string): NonPayableTransactionObject<string>;
176
+ getRatioUsingParams(marketParams: MarketParamsStruct, owner: string): NonPayableTransactionObject<string>;
116
177
  getUserInfo(marketParams: MarketParamsStruct, owner: string): NonPayableTransactionObject<MorphoBlueView.PositionInfoStructOutput>;
117
178
  morphoBlue(): NonPayableTransactionObject<string>;
118
179
  };
@@ -4457,6 +4457,32 @@ export namespace USDCPriceFeed {
4457
4457
  export namespace MorphoBlueView {
4458
4458
  let abi_66: ({
4459
4459
  inputs: {
4460
+ components: ({
4461
+ components: {
4462
+ internalType: string;
4463
+ name: string;
4464
+ type: string;
4465
+ }[];
4466
+ internalType: string;
4467
+ name: string;
4468
+ type: string;
4469
+ } | {
4470
+ internalType: string;
4471
+ name: string;
4472
+ type: string;
4473
+ components?: undefined;
4474
+ })[];
4475
+ internalType: string;
4476
+ name: string;
4477
+ type: string;
4478
+ }[];
4479
+ name: string;
4480
+ outputs: ({
4481
+ internalType: string;
4482
+ name: string;
4483
+ type: string;
4484
+ components?: undefined;
4485
+ } | {
4460
4486
  components: {
4461
4487
  internalType: string;
4462
4488
  name: string;
@@ -4465,7 +4491,25 @@ export namespace MorphoBlueView {
4465
4491
  internalType: string;
4466
4492
  name: string;
4467
4493
  type: string;
4468
- }[];
4494
+ })[];
4495
+ stateMutability: string;
4496
+ type: string;
4497
+ } | {
4498
+ inputs: ({
4499
+ internalType: string;
4500
+ name: string;
4501
+ type: string;
4502
+ components?: undefined;
4503
+ } | {
4504
+ components: {
4505
+ internalType: string;
4506
+ name: string;
4507
+ type: string;
4508
+ }[];
4509
+ internalType: string;
4510
+ name: string;
4511
+ type: string;
4512
+ })[];
4469
4513
  name: string;
4470
4514
  outputs: {
4471
4515
  internalType: string;