@defisaver/positions-sdk 2.0.12 → 2.0.14-dev-portfolio

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 (170) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/CLAUDE.md +32 -0
  4. package/README.md +64 -64
  5. package/cjs/aaveV2/index.js +1 -0
  6. package/cjs/aaveV3/index.d.ts +12 -0
  7. package/cjs/aaveV3/index.js +93 -1
  8. package/cjs/claiming/aaveV3.d.ts +9 -0
  9. package/cjs/claiming/aaveV3.js +148 -0
  10. package/cjs/claiming/compV3.d.ts +15 -0
  11. package/cjs/claiming/compV3.js +34 -0
  12. package/cjs/claiming/index.d.ts +6 -0
  13. package/cjs/claiming/index.js +46 -0
  14. package/cjs/claiming/king.d.ts +4 -0
  15. package/cjs/claiming/king.js +72 -0
  16. package/cjs/claiming/morphoBlue.d.ts +6 -0
  17. package/cjs/claiming/morphoBlue.js +113 -0
  18. package/cjs/claiming/spark.d.ts +6 -0
  19. package/cjs/claiming/spark.js +188 -0
  20. package/cjs/config/contracts.d.ts +2667 -0
  21. package/cjs/config/contracts.js +103 -2
  22. package/cjs/constants/index.d.ts +4 -0
  23. package/cjs/constants/index.js +6 -2
  24. package/cjs/contracts.d.ts +2882 -23
  25. package/cjs/contracts.js +10 -1
  26. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  27. package/cjs/index.d.ts +2 -1
  28. package/cjs/index.js +3 -1
  29. package/cjs/liquity/index.d.ts +11 -0
  30. package/cjs/liquity/index.js +39 -1
  31. package/cjs/liquityV2/index.d.ts +8 -0
  32. package/cjs/liquityV2/index.js +161 -0
  33. package/cjs/markets/aave/marketAssets.js +1 -1
  34. package/cjs/markets/compound/marketsAssets.js +2 -2
  35. package/cjs/markets/spark/marketAssets.js +1 -1
  36. package/cjs/morphoBlue/index.d.ts +5 -0
  37. package/cjs/morphoBlue/index.js +38 -4
  38. package/cjs/portfolio/index.d.ts +6 -1
  39. package/cjs/portfolio/index.js +256 -10
  40. package/cjs/services/utils.d.ts +5 -0
  41. package/cjs/services/utils.js +33 -1
  42. package/cjs/services/viem.d.ts +12 -12
  43. package/cjs/spark/index.js +1 -0
  44. package/cjs/staking/staking.js +3 -1
  45. package/cjs/types/claiming.d.ts +93 -0
  46. package/cjs/types/claiming.js +27 -0
  47. package/cjs/umbrella/index.d.ts +5 -0
  48. package/cjs/umbrella/index.js +50 -0
  49. package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
  50. package/cjs/umbrella/umbrellaUtils.js +34 -0
  51. package/esm/aaveV2/index.js +1 -0
  52. package/esm/aaveV3/index.d.ts +12 -0
  53. package/esm/aaveV3/index.js +91 -1
  54. package/esm/claiming/aaveV3.d.ts +9 -0
  55. package/esm/claiming/aaveV3.js +139 -0
  56. package/esm/claiming/compV3.d.ts +15 -0
  57. package/esm/claiming/compV3.js +30 -0
  58. package/esm/claiming/index.d.ts +6 -0
  59. package/esm/claiming/index.js +6 -0
  60. package/esm/claiming/king.d.ts +4 -0
  61. package/esm/claiming/king.js +64 -0
  62. package/esm/claiming/morphoBlue.d.ts +6 -0
  63. package/esm/claiming/morphoBlue.js +104 -0
  64. package/esm/claiming/spark.d.ts +6 -0
  65. package/esm/claiming/spark.js +179 -0
  66. package/esm/config/contracts.d.ts +2667 -0
  67. package/esm/config/contracts.js +102 -1
  68. package/esm/constants/index.d.ts +4 -0
  69. package/esm/constants/index.js +5 -1
  70. package/esm/contracts.d.ts +2882 -23
  71. package/esm/contracts.js +9 -0
  72. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  73. package/esm/index.d.ts +2 -1
  74. package/esm/index.js +2 -1
  75. package/esm/liquity/index.d.ts +11 -0
  76. package/esm/liquity/index.js +38 -1
  77. package/esm/liquityV2/index.d.ts +8 -0
  78. package/esm/liquityV2/index.js +162 -1
  79. package/esm/markets/aave/marketAssets.js +1 -1
  80. package/esm/markets/compound/marketsAssets.js +2 -2
  81. package/esm/markets/spark/marketAssets.js +1 -1
  82. package/esm/morphoBlue/index.d.ts +5 -0
  83. package/esm/morphoBlue/index.js +38 -5
  84. package/esm/portfolio/index.d.ts +6 -1
  85. package/esm/portfolio/index.js +260 -14
  86. package/esm/services/utils.d.ts +5 -0
  87. package/esm/services/utils.js +31 -0
  88. package/esm/services/viem.d.ts +12 -12
  89. package/esm/spark/index.js +1 -0
  90. package/esm/staking/staking.js +3 -1
  91. package/esm/types/claiming.d.ts +93 -0
  92. package/esm/types/claiming.js +24 -0
  93. package/esm/umbrella/index.d.ts +5 -0
  94. package/esm/umbrella/index.js +46 -0
  95. package/esm/umbrella/umbrellaUtils.d.ts +22 -0
  96. package/esm/umbrella/umbrellaUtils.js +28 -0
  97. package/package.json +47 -47
  98. package/src/aaveV2/index.ts +237 -236
  99. package/src/aaveV3/index.ts +586 -488
  100. package/src/claiming/aaveV3.ts +163 -0
  101. package/src/claiming/compV3.ts +23 -0
  102. package/src/claiming/index.ts +13 -0
  103. package/src/claiming/king.ts +66 -0
  104. package/src/claiming/morphoBlue.ts +119 -0
  105. package/src/claiming/spark.ts +226 -0
  106. package/src/compoundV2/index.ts +240 -240
  107. package/src/compoundV3/index.ts +270 -270
  108. package/src/config/contracts.ts +1208 -1108
  109. package/src/constants/index.ts +10 -6
  110. package/src/contracts.ts +121 -108
  111. package/src/curveUsd/index.ts +250 -250
  112. package/src/eulerV2/index.ts +314 -314
  113. package/src/exchange/index.ts +25 -25
  114. package/src/fluid/index.ts +1568 -1568
  115. package/src/helpers/aaveHelpers/index.ts +170 -170
  116. package/src/helpers/compoundHelpers/index.ts +261 -261
  117. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  118. package/src/helpers/eulerHelpers/index.ts +259 -259
  119. package/src/helpers/fluidHelpers/index.ts +324 -324
  120. package/src/helpers/index.ts +10 -10
  121. package/src/helpers/liquityV2Helpers/index.ts +80 -80
  122. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  123. package/src/helpers/makerHelpers/index.ts +52 -52
  124. package/src/helpers/morphoBlueHelpers/index.ts +390 -390
  125. package/src/helpers/sparkHelpers/index.ts +155 -155
  126. package/src/index.ts +47 -45
  127. package/src/liquity/index.ts +160 -105
  128. package/src/liquityV2/index.ts +583 -408
  129. package/src/llamaLend/index.ts +296 -296
  130. package/src/maker/index.ts +223 -223
  131. package/src/markets/aave/index.ts +116 -116
  132. package/src/markets/aave/marketAssets.ts +49 -49
  133. package/src/markets/compound/index.ts +227 -227
  134. package/src/markets/compound/marketsAssets.ts +90 -90
  135. package/src/markets/curveUsd/index.ts +69 -69
  136. package/src/markets/euler/index.ts +26 -26
  137. package/src/markets/fluid/index.ts +2456 -2456
  138. package/src/markets/index.ts +25 -25
  139. package/src/markets/liquityV2/index.ts +102 -102
  140. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  141. package/src/markets/llamaLend/index.ts +235 -235
  142. package/src/markets/morphoBlue/index.ts +895 -895
  143. package/src/markets/spark/index.ts +29 -29
  144. package/src/markets/spark/marketAssets.ts +11 -11
  145. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  146. package/src/morphoBlue/index.ts +259 -222
  147. package/src/portfolio/index.ts +533 -285
  148. package/src/services/priceService.ts +159 -159
  149. package/src/services/utils.ts +100 -64
  150. package/src/services/viem.ts +32 -32
  151. package/src/setup.ts +8 -8
  152. package/src/spark/index.ts +457 -456
  153. package/src/staking/staking.ts +194 -193
  154. package/src/types/aave.ts +194 -194
  155. package/src/types/claiming.ts +109 -0
  156. package/src/types/common.ts +88 -88
  157. package/src/types/compound.ts +136 -136
  158. package/src/types/curveUsd.ts +121 -121
  159. package/src/types/euler.ts +174 -174
  160. package/src/types/fluid.ts +450 -450
  161. package/src/types/index.ts +11 -11
  162. package/src/types/liquity.ts +30 -30
  163. package/src/types/liquityV2.ts +126 -126
  164. package/src/types/llamaLend.ts +157 -157
  165. package/src/types/maker.ts +63 -63
  166. package/src/types/morphoBlue.ts +194 -194
  167. package/src/types/portfolio.ts +60 -60
  168. package/src/types/spark.ts +137 -137
  169. package/src/umbrella/index.ts +70 -0
  170. package/src/umbrella/umbrellaUtils.ts +30 -0
package/esm/contracts.js CHANGED
@@ -80,3 +80,12 @@ export const LiquityActivePoolContractViem = createViemContractFromConfigFunc('L
80
80
  export const LiquityV2ViewContractViem = createViemContractFromConfigFunc('LiquityV2View');
81
81
  export const LiquityV2LegacyViewContractViem = createViemContractFromConfigFunc('LiquityV2LegacyView');
82
82
  export const FluidViewContractViem = createViemContractFromConfigFunc('FluidView');
83
+ export const AaveIncentivesControllerViem = createViemContractFromConfigFunc('AaveIncentivesController');
84
+ export const AaveUmbrellaViewViem = createViemContractFromConfigFunc('AaveUmbrellaView');
85
+ export const LiquityLQTYStakingViem = createViemContractFromConfigFunc('LiquityLQTYStaking');
86
+ export const LiquityStabilityPoolViem = createViemContractFromConfigFunc('LiquityStabilityPool');
87
+ export const UUPSViem = createViemContractFromConfigFunc('UUPS');
88
+ export const SparkRewardsControllerViem = createViemContractFromConfigFunc('SparkRewardsController');
89
+ export const AaveRewardsControllerViem = createViemContractFromConfigFunc('AaveRewardsController');
90
+ export const LiquityV2sBoldVaultViem = createViemContractFromConfigFunc('LiquityV2sBoldVault');
91
+ export const StkAAVEViem = createViemContractFromConfigFunc('StkAAVE');
@@ -118,73 +118,73 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, n
118
118
  return { borrowRate, supplyRate };
119
119
  });
120
120
  const API_URL = 'https://blue-api.morpho.org/graphql';
121
- const MARKET_QUERY = `
122
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
123
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
124
- reallocatableLiquidityAssets
125
- targetBorrowUtilization
126
- loanAsset {
127
- address
128
- decimals
129
- priceUsd
130
- }
131
- state {
132
- liquidityAssets
133
- borrowAssets
134
- supplyAssets
135
- }
136
- publicAllocatorSharedLiquidity {
137
- assets
138
- vault {
139
- address
140
- name
141
- }
142
- allocationMarket {
143
- uniqueKey
144
- loanAsset {
145
- address
146
- }
147
- collateralAsset {
148
- address
149
- }
150
- irmAddress
151
- oracle {
152
- address
153
- }
154
- lltv
155
- }
156
- }
157
- loanAsset {
158
- address
159
- }
160
- collateralAsset {
161
- address
162
- }
163
- oracle {
164
- address
165
- }
166
- irmAddress
167
- lltv
168
- }
169
- }
121
+ const MARKET_QUERY = `
122
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
123
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
124
+ reallocatableLiquidityAssets
125
+ targetBorrowUtilization
126
+ loanAsset {
127
+ address
128
+ decimals
129
+ priceUsd
130
+ }
131
+ state {
132
+ liquidityAssets
133
+ borrowAssets
134
+ supplyAssets
135
+ }
136
+ publicAllocatorSharedLiquidity {
137
+ assets
138
+ vault {
139
+ address
140
+ name
141
+ }
142
+ allocationMarket {
143
+ uniqueKey
144
+ loanAsset {
145
+ address
146
+ }
147
+ collateralAsset {
148
+ address
149
+ }
150
+ irmAddress
151
+ oracle {
152
+ address
153
+ }
154
+ lltv
155
+ }
156
+ }
157
+ loanAsset {
158
+ address
159
+ }
160
+ collateralAsset {
161
+ address
162
+ }
163
+ oracle {
164
+ address
165
+ }
166
+ irmAddress
167
+ lltv
168
+ }
169
+ }
170
170
  `;
171
- const REWARDS_QUERY = `
172
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
173
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
174
- uniqueKey
175
- state {
176
- rewards {
177
- amountPerSuppliedToken
178
- supplyApr
179
- amountPerBorrowedToken
180
- borrowApr
181
- asset {
182
- address
183
- }
184
- }
185
- }
186
- }
187
- }
171
+ const REWARDS_QUERY = `
172
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
173
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
174
+ uniqueKey
175
+ state {
176
+ rewards {
177
+ amountPerSuppliedToken
178
+ supplyApr
179
+ amountPerBorrowedToken
180
+ borrowApr
181
+ asset {
182
+ address
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
188
  `;
189
189
  /**
190
190
  * Get reallocatable liquidity to a given market and target borrow utilization
package/esm/index.d.ts CHANGED
@@ -18,5 +18,6 @@ import * as morphoBlue from './morphoBlue';
18
18
  import * as llamaLend from './llamaLend';
19
19
  import * as eulerV2 from './eulerV2';
20
20
  import * as portfolio from './portfolio';
21
+ import * as claiming from './claiming';
21
22
  export * from './types';
22
- export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, };
23
+ export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, };
package/esm/index.js CHANGED
@@ -18,5 +18,6 @@ import * as morphoBlue from './morphoBlue';
18
18
  import * as llamaLend from './llamaLend';
19
19
  import * as eulerV2 from './eulerV2';
20
20
  import * as portfolio from './portfolio';
21
+ import * as claiming from './claiming';
21
22
  export * from './types';
22
- export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, };
23
+ export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, };
@@ -8,3 +8,14 @@ export declare const getLiquityAccountBalances: (provider: EthereumProvider, net
8
8
  export declare const getDebtInFront: (provider: EthereumProvider, address: EthAddress) => Promise<string>;
9
9
  export declare const _getLiquityTroveInfo: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
10
10
  export declare const getLiquityTroveInfo: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
11
+ export declare const getLiquityStakingData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
12
+ totalLUSDDeposited: string;
13
+ totalLQTYStaked: string;
14
+ stakedLQTY: string;
15
+ stakedLUSDBalance: string;
16
+ rewardETH: string;
17
+ rewardLUSD: string;
18
+ stabilityRewardETH: string;
19
+ stabilityRewardLQTY: string;
20
+ showStakingBalances: boolean;
21
+ }>;
@@ -10,10 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import Dec from 'decimal.js';
11
11
  import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
12
12
  import { NetworkNumber, } from '../types/common';
13
- import { LiquityActivePoolContractViem, LiquityCollSurplusPoolContractViem, LiquityPriceFeedContractViem, LiquityTroveManagerContractViem, LiquityViewContractViem, } from '../contracts';
13
+ import { LiquityActivePoolContractViem, LiquityCollSurplusPoolContractViem, LiquityLQTYStakingViem, LiquityPriceFeedContractViem, LiquityStabilityPoolViem, LiquityTroveManagerContractViem, LiquityViewContractViem, } from '../contracts';
14
14
  import { LIQUITY_TROVE_STATUS_ENUM } from '../types';
15
15
  import { ZERO_ADDRESS } from '../constants';
16
16
  import { getViemProvider, setViemBlockNumber } from '../services/viem';
17
+ import { getEthAmountForDecimals } from '../services/utils';
17
18
  export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
18
19
  export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
19
20
  export const _getLiquityAccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
@@ -85,3 +86,39 @@ export const _getLiquityTroveInfo = (provider, network, address) => __awaiter(vo
85
86
  return payload;
86
87
  });
87
88
  export const getLiquityTroveInfo = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () { return _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address); });
89
+ export const getLiquityStakingData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
90
+ const lqtyStakingView = LiquityLQTYStakingViem(provider, network);
91
+ const stabilityPoolView = LiquityStabilityPoolViem(provider, network);
92
+ const [stakes, pendingETHGain, pendingLUSDGain, totalLQTYStakes, stabilityPoolETHGain, stabilityPoolLQTYGain, compoundedLUSDDeposit, totalLUSDDeposits,] = yield Promise.all([
93
+ lqtyStakingView.read.stakes([address]),
94
+ lqtyStakingView.read.getPendingETHGain([address]),
95
+ lqtyStakingView.read.getPendingLUSDGain([address]),
96
+ lqtyStakingView.read.totalLQTYStaked(),
97
+ stabilityPoolView.read.getDepositorETHGain([address]),
98
+ stabilityPoolView.read.getDepositorLQTYGain([address]),
99
+ stabilityPoolView.read.getCompoundedLUSDDeposit([address]),
100
+ stabilityPoolView.read.getTotalLUSDDeposits(),
101
+ ]);
102
+ const totalLUSDDeposited = getEthAmountForDecimals(totalLUSDDeposits, 18);
103
+ const totalLQTYStaked = getEthAmountForDecimals(totalLQTYStakes, 18);
104
+ const stakedLQTY = getEthAmountForDecimals(stakes, 18);
105
+ const stakedLUSDBalance = getEthAmountForDecimals(compoundedLUSDDeposit, 18);
106
+ const rewardETH = getEthAmountForDecimals(pendingETHGain, 18);
107
+ const rewardLUSD = getEthAmountForDecimals(pendingLUSDGain, 18);
108
+ const stabilityRewardETH = getEthAmountForDecimals(stabilityPoolETHGain, 18);
109
+ const stabilityRewardLQTY = getEthAmountForDecimals(stabilityPoolLQTYGain, 18);
110
+ const showStakingBalances = !!(+stakedLQTY || +stakedLUSDBalance
111
+ || +rewardETH || +rewardLUSD
112
+ || +stabilityRewardETH || +stabilityRewardLQTY);
113
+ return {
114
+ totalLUSDDeposited,
115
+ totalLQTYStaked,
116
+ stakedLQTY,
117
+ stakedLUSDBalance,
118
+ rewardETH,
119
+ rewardLUSD,
120
+ stabilityRewardETH,
121
+ stabilityRewardLQTY,
122
+ showStakingBalances,
123
+ };
124
+ });
@@ -1,6 +1,14 @@
1
1
  import { Client, PublicClient } from 'viem';
2
2
  import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
3
  import { LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2Versions } from '../types';
4
+ export type SPYieldGainParameters = {
5
+ P: string;
6
+ aggWeightedDebtSum: string;
7
+ currentScale: string;
8
+ lastAggUpdateTime: string;
9
+ totalBoldDeposits: string;
10
+ yieldGainsPending: string;
11
+ };
4
12
  export declare const _getLiquityV2MarketData: (provider: Client, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo) => Promise<LiquityV2MarketData>;
5
13
  export declare const getLiquityV2MarketData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo) => Promise<LiquityV2MarketData>;
6
14
  export declare const _getLiquityV2UserTroveIds: (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress) => Promise<{
@@ -14,7 +14,7 @@ import { NetworkNumber } from '../types/common';
14
14
  import { LIQUITY_V2_TROVE_STATUS_ENUM, LiquityV2Versions, } from '../types';
15
15
  import { getStakingApy, STAKING_ASSETS } from '../staking';
16
16
  import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
17
- import { compareAddresses, ethToWeth, MAXUINT } from '../services/utils';
17
+ import { compareAddresses, ethToWeth, MAXUINT, } from '../services/utils';
18
18
  import { ZERO_ADDRESS } from '../constants';
19
19
  import { LiquityV2Markets } from '../markets';
20
20
  import { getViemProvider } from '../services/viem';
@@ -286,3 +286,164 @@ export const getLiquityV2ClaimableCollateral = (collSurplusPoolAddress, account,
286
286
  const claimableCollateral = yield collSurplusPoolContract.read.getCollateral([account]);
287
287
  return claimableCollateral.toString();
288
288
  });
289
+ // const stabilityPoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
290
+ // [LiquityV2Versions.LiquityV2Eth]: '0x5721cbbd64fc7Ae3Ef44A0A3F9a790A9264Cf9BF',
291
+ // [LiquityV2Versions.LiquityV2WstEth]: '0x9502b7c397e9aa22fe9db7ef7daf21cd2aebe56b',
292
+ // [LiquityV2Versions.LiquityV2REth]: '0xd442e41019b7f5c4dd78f50dc03726c446148695',
293
+ // [LiquityV2Versions.LiquityV2EthLegacy]: '0x',
294
+ // [LiquityV2Versions.LiquityV2REthLegacy]: '0x',
295
+ // [LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
296
+ // };
297
+ // const activePoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
298
+ // [LiquityV2Versions.LiquityV2Eth]: '0xeB5A8C825582965f1d84606E078620a84ab16AfE',
299
+ // [LiquityV2Versions.LiquityV2WstEth]: '0x531a8f99c70d6a56a7cee02d6b4281650d7919a0',
300
+ // [LiquityV2Versions.LiquityV2REth]: '0x9074d72cc82dad1e13e454755aa8f144c479532f',
301
+ // [LiquityV2Versions.LiquityV2EthLegacy]: '0x',
302
+ // [LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
303
+ // [LiquityV2Versions.LiquityV2REthLegacy]: '0x',
304
+ // };
305
+ //
306
+ // function ceilDiv(a: string, b: string) {
307
+ // return new Dec(a).add(new Dec(b).sub(1)).div(b).toString();
308
+ // }
309
+ // const SP_YIELD_SPLIT = new Dec(75).mul(10 ** 16).toString(); // 75%
310
+ //
311
+ // const calcPendingSPYield = (
312
+ // aggWeightedDebtSum: string,
313
+ // lastAggUpdateTime: string,
314
+ // currentTime: string,
315
+ // ) => {
316
+ // const a = new Dec(aggWeightedDebtSum).mul(
317
+ // new Dec(currentTime).sub(new Dec(lastAggUpdateTime)),
318
+ // ).toString();
319
+ // const b = new Dec(SECONDS_PER_YEAR).mul(1000).mul(1e18).toString();
320
+ // return new Dec(ceilDiv(a, b)).mul(SP_YIELD_SPLIT).div(1e18).toString();
321
+ // };
322
+ //
323
+ //
324
+ // const calculateStabilityPoolApy = (
325
+ // spYieldGainParams: SPYieldGainParameters,
326
+ // ) => {
327
+ // const {
328
+ // aggWeightedDebtSum, totalBoldDeposits, lastAggUpdateTime, yieldGainsPending,
329
+ // } = spYieldGainParams;
330
+ //
331
+ // if (new Dec(totalBoldDeposits).eq(0)) {
332
+ // return '0';
333
+ // }
334
+ //
335
+ // const now = Date.now().toString();
336
+ // const lastAggUpdateTimeScaled = new Dec(lastAggUpdateTime).mul(1000).toString();
337
+ //
338
+ // const pendingSPYield = new Dec(calcPendingSPYield(
339
+ // aggWeightedDebtSum,
340
+ // lastAggUpdateTimeScaled,
341
+ // now,
342
+ // )).add(yieldGainsPending).toString();
343
+ //
344
+ // const annualizedYield = new Dec(pendingSPYield).mul(SECONDS_PER_YEAR).mul(1000).div(new Dec(now).minus(lastAggUpdateTimeScaled))
345
+ // .toString();
346
+ // return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
347
+ // };
348
+ //
349
+ // const getYBoldApyApi = async () => {
350
+ // const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
351
+ //
352
+ // const yBoldData = await fetch(url)
353
+ // .then(res => res.json())
354
+ // .catch(console.error);
355
+ //
356
+ // return new Dec(yBoldData.apr.netAPR).mul(100).toString();
357
+ // };
358
+ //
359
+ // export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => {
360
+ // const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
361
+ // const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
362
+ //
363
+ // const sBold = LiquityV2sBoldVaultViem(provider, network);
364
+ // const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
365
+ // const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
366
+ //
367
+ // const debtTokenInfo = getAssetInfo(LiquityV2Markets(network)[market].debtToken);
368
+ // const debtTokenContract = createViemContractFromConfigFunc('Erc20', debtTokenInfo.address)(provider, network);
369
+ //
370
+ // const [
371
+ // stabilityRewardColl,
372
+ // stabilityRewardYield,
373
+ // compoundedBoldDeposit,
374
+ // totalBoldDeposits,
375
+ // P,
376
+ // currentScale,
377
+ // yieldGainsPending,
378
+ // debtTokenBalance,
379
+ //
380
+ // aggWeightedDebtSum,
381
+ // lastAggUpdateTime,
382
+ //
383
+ // sBoldTotalAssets,
384
+ // sBoldConvertToShares,
385
+ // sBoldMaxWithdraw,
386
+ //
387
+ // wethApy,
388
+ // wsETHApy,
389
+ // rETHApy,
390
+ //
391
+ // yBoldTotalAssets,
392
+ // yBoldMaxWithdraw,
393
+ // stYBoldConvertToShares,
394
+ // ] = await Promise.all([
395
+ // stabilityPoolView.read.getDepositorCollGain([user]),
396
+ // stabilityPoolView.read.getDepositorYieldGain([user]),
397
+ // stabilityPoolView.read.getCompoundedBoldDeposit([user]),
398
+ // stabilityPoolView.read.getTotalBoldDeposits(),
399
+ // stabilityPoolView.read.P(),
400
+ // stabilityPoolView.read.currentScale(),
401
+ // stabilityPoolView.read.getYieldGainsPending(),
402
+ // debtTokenContract.read.balanceOf([user]),
403
+ //
404
+ // activePoolView.read.aggWeightedDebtSum(),
405
+ // activePoolView.read.lastAggUpdateTime(),
406
+ //
407
+ // sBold.read.totalAssets(),
408
+ // sBold.read.convertToShares([BigInt(1e18)]),
409
+ // sBold.read.maxWithdraw([user]),
410
+ //
411
+ // sBold.read.sps([BigInt(0)]),
412
+ // sBold.read.sps([BigInt(1)]),
413
+ // sBold.read.sps([BigInt(2)]),
414
+ //
415
+ // yBold.read.totalAssets(),
416
+ // yBold.read.maxWithdraw([user]),
417
+ // stYBold.read.convertToShares([BigInt(1e18)]),
418
+ // ]);
419
+ //
420
+ //
421
+ // const stabilityPoolYieldParams: SPYieldGainParameters = {
422
+ // aggWeightedDebtSum: aggWeightedDebtSum.toString(),
423
+ // lastAggUpdateTime: lastAggUpdateTime.toString(),
424
+ // P: P.toString(),
425
+ // currentScale: currentScale.toString(),
426
+ // yieldGainsPending: yieldGainsPending.toString(),
427
+ // totalBoldDeposits: totalBoldDeposits.toString(),
428
+ // };
429
+ //
430
+ // const stabilityPoolApy = calculateStabilityPoolApy(stabilityPoolYieldParams);
431
+ //
432
+ // const stakedBOLDBalanceForUser = getEthAmountForDecimals(compoundedBoldDeposit.toString(), 18);
433
+ // const stabilityRewardCollForUser = getEthAmountForDecimals(stabilityRewardColl.toString(), 18);
434
+ // const stabilityRewardYieldForUser = getEthAmountForDecimals(stabilityRewardYield.toString(), 18);
435
+ //
436
+ // const accountData = {
437
+ // totalBOLDDeposited: getEthAmountForDecimals(totalBoldDeposits.toString(), 18),
438
+ // stakedBOLDBalance: stakedBOLDBalanceForUser,
439
+ // stabilityRewardColl: stabilityRewardCollForUser,
440
+ // stabilityRewardYield: stabilityRewardYieldForUser,
441
+ // showStakingBalances: !!(+stakedBOLDBalanceForUser || +stabilityRewardCollForUser || +stabilityRewardYieldForUser),
442
+ // debtTokenBalance: getEthAmountForDecimals(debtTokenBalance.toString(), debtTokenInfo.decimals),
443
+ // };
444
+ //
445
+ //
446
+ // const yBoldApy = await getYBoldApyApi();
447
+ //
448
+ // return yBoldApy;
449
+ // };
@@ -7,7 +7,7 @@ export const aaveV1AssetsDefaultMarket = [
7
7
  export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', 'UNI', 'AAVE', 'BAT', 'BUSD', 'DAI', 'ENJ', 'KNCL', 'LINK', 'MANA', 'MKR', 'REN', 'SNX', 'SUSD', 'TUSD', 'USDC', 'CRV', 'GUSD', 'BAL', 'xSUSHI', 'RENFIL', 'RAI', 'AMPL', 'USDP', 'DPI', 'FRAX', 'FEI', 'stETH', 'ENS', 'UST', 'CVX', '1INCH', 'LUSD'];
8
8
  export const aaveV3AssetsDefaultMarketEth = [
9
9
  'ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH', 'USDe', 'ETHx', 'sUSDe', 'tBTC', 'cbBTC', 'USDS', 'rsETH', 'LBTC', 'eBTC', 'RLUSD', 'PT eUSDe May', 'PT sUSDe July', 'USDtb',
10
- 'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov',
10
+ 'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov', 'PT USDe Nov',
11
11
  ];
12
12
  export const aaveV3AssetsDefaultMarketOpt = [
13
13
  'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
@@ -4,7 +4,7 @@ export const compoundV2CollateralAssets = [
4
4
  'cETH', 'cDAI', 'cBAT', 'cZRX', 'cUSDC', 'cWBTC Legacy', 'cWBTC', 'cUSDT',
5
5
  'cTUSD', 'cLINK', 'cUSDP', 'cUNI', 'cCOMP', 'cMKR', 'cSUSHI', 'cAAVE', 'cYFI',
6
6
  ].map((symbol) => getAssetInfo(symbol));
7
- export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD'];
7
+ export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD', 'rsETH'];
8
8
  export const v3USDCCollAssetsArb = ['ARB', 'ETH', 'GMX', 'WBTC', 'wstETH', 'ezETH', 'wUSDM'];
9
9
  export const v3USDCCollAssetsBase = ['cbETH', 'ETH', 'wstETH', 'cbBTC', 'tBTC'];
10
10
  export const v3USDCCollAssetsOpt = ['ETH', 'OP', 'WBTC', 'wstETH'];
@@ -46,7 +46,7 @@ export const v3USDbCCollAssets = {
46
46
  [NetworkNumber.Base]: v3USDbCCollAssetsBase,
47
47
  [NetworkNumber.Linea]: [],
48
48
  };
49
- export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
49
+ export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'wUSDM', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
50
50
  export const v3USDTCollAssetsArb = ['ETH', 'WBTC', 'wstETH', 'ARB', 'GMX'];
51
51
  export const v3USDTCollAssetsOpt = ['ETH', 'WBTC', 'OP', 'wstETH'];
52
52
  // @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
@@ -1,5 +1,5 @@
1
1
  import { NetworkNumber } from '../../types/common';
2
- export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH'];
2
+ export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH', 'PYUSD'];
3
3
  // @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
4
4
  export const sparkAssetsDefaultMarket = {
5
5
  [NetworkNumber.Eth]: sparkAssetsDefaultMarketEth,
@@ -7,3 +7,8 @@ export declare const _getMorphoBlueAccountBalances: (provider: Client, network:
7
7
  export declare const getMorphoBlueAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
8
8
  export declare function _getMorphoBlueAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
9
9
  export declare function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
10
+ export declare function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<{
11
+ apy: string;
12
+ amount: string;
13
+ amountUsd: string;
14
+ }>;
@@ -12,7 +12,7 @@ import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
12
12
  import { NetworkNumber, } from '../types/common';
13
13
  import { DFSFeedRegistryContractViem, FeedRegistryContractViem, MorphoBlueViewContractViem, } from '../contracts';
14
14
  import { USD_QUOTE, WAD } from '../constants';
15
- import { getStakingApy, STAKING_ASSETS } from '../staking';
15
+ import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../staking';
16
16
  import { isMainnetNetwork, wethToEth } from '../services/utils';
17
17
  import { getBorrowRate, getMorphoBlueAggregatedPositionData, getRewardsForMarket, getSupplyRate, } from '../helpers/morphoBlueHelpers';
18
18
  import { getChainlinkAssetAddress } from '../services/priceService';
@@ -155,16 +155,15 @@ export function _getMorphoBlueAccountData(provider, network, account, selectedMa
155
155
  ]));
156
156
  const usedAssets = {};
157
157
  const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
158
- const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
159
158
  const loanTokenBorrowed = assetAmountInEth(loanInfo.borrowedInAssets.toString(), marketInfo.loanToken);
160
159
  usedAssets[marketInfo.loanToken] = {
161
160
  symbol: loanTokenInfo.symbol,
162
- supplied: loanTokenSupplied,
161
+ supplied: '0',
163
162
  borrowed: loanTokenBorrowed,
164
- isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
163
+ isSupplied: false,
165
164
  isBorrowed: new Dec(loanInfo.borrowedInAssets.toString()).gt(0),
166
165
  collateral: false,
167
- suppliedUsd: new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString(),
166
+ suppliedUsd: '0',
168
167
  borrowedUsd: new Dec(loanTokenBorrowed).mul(loanTokenInfo.price).toString(),
169
168
  };
170
169
  const collateralTokenInfo = marketInfo.assetsData[marketInfo.collateralToken];
@@ -187,3 +186,37 @@ export function getMorphoBlueAccountData(provider, network, account, selectedMar
187
186
  return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
188
187
  });
189
188
  }
189
+ export function getMorphoEarn(provider, network, account, selectedMarket, marketInfo) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
192
+ const lltvInWei = new Dec(lltv).mul(WAD).toString();
193
+ const viewContract = MorphoBlueViewContractViem(provider, network);
194
+ const loanInfo = (yield viewContract.read.getUserInfo([
195
+ {
196
+ loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
197
+ },
198
+ account
199
+ ]));
200
+ const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
201
+ const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
202
+ const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
203
+ const usedAssets = {
204
+ [marketInfo.loanToken]: {
205
+ symbol: loanTokenInfo.symbol,
206
+ supplied: loanTokenSupplied,
207
+ borrowed: '0',
208
+ isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
209
+ isBorrowed: false,
210
+ collateral: false,
211
+ suppliedUsd: loanTokenSuppliedUsd,
212
+ borrowedUsd: '0',
213
+ },
214
+ };
215
+ const { netApy } = calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData });
216
+ return {
217
+ apy: netApy,
218
+ amount: loanTokenSupplied,
219
+ amountUsd: loanTokenSuppliedUsd,
220
+ };
221
+ });
222
+ }
@@ -1,3 +1,8 @@
1
1
  import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
2
2
  import { PortfolioPositionsData } from '../types';
3
- export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], summerFiAddresses: EthAddress[]): Promise<PortfolioPositionsData>;
3
+ export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], summerFiAddresses: EthAddress[]): Promise<{
4
+ positions: PortfolioPositionsData;
5
+ stakingPositions: any;
6
+ rewardsData: any;
7
+ markets: any;
8
+ }>;