@defisaver/positions-sdk 2.0.13 → 2.0.14-dev-portfolio1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CLAUDE.md +32 -0
  2. package/cjs/aaveV2/index.js +1 -0
  3. package/cjs/aaveV3/index.d.ts +12 -0
  4. package/cjs/aaveV3/index.js +93 -1
  5. package/cjs/claiming/aaveV3.d.ts +9 -0
  6. package/cjs/claiming/aaveV3.js +148 -0
  7. package/cjs/claiming/compV3.d.ts +15 -0
  8. package/cjs/claiming/compV3.js +34 -0
  9. package/cjs/claiming/index.d.ts +6 -0
  10. package/cjs/claiming/index.js +46 -0
  11. package/cjs/claiming/king.d.ts +4 -0
  12. package/cjs/claiming/king.js +72 -0
  13. package/cjs/claiming/morphoBlue.d.ts +6 -0
  14. package/cjs/claiming/morphoBlue.js +113 -0
  15. package/cjs/claiming/spark.d.ts +6 -0
  16. package/cjs/claiming/spark.js +188 -0
  17. package/cjs/config/contracts.d.ts +2681 -0
  18. package/cjs/config/contracts.js +103 -2
  19. package/cjs/constants/index.d.ts +4 -0
  20. package/cjs/constants/index.js +6 -2
  21. package/cjs/contracts.d.ts +3027 -23
  22. package/cjs/contracts.js +10 -1
  23. package/cjs/index.d.ts +2 -1
  24. package/cjs/index.js +3 -1
  25. package/cjs/liquity/index.d.ts +11 -0
  26. package/cjs/liquity/index.js +39 -1
  27. package/cjs/liquityV2/index.d.ts +35 -0
  28. package/cjs/liquityV2/index.js +136 -1
  29. package/cjs/markets/aave/marketAssets.js +1 -1
  30. package/cjs/markets/compound/marketsAssets.js +2 -2
  31. package/cjs/markets/spark/marketAssets.js +1 -1
  32. package/cjs/morphoBlue/index.d.ts +5 -0
  33. package/cjs/morphoBlue/index.js +38 -4
  34. package/cjs/portfolio/index.d.ts +6 -1
  35. package/cjs/portfolio/index.js +295 -10
  36. package/cjs/services/utils.d.ts +5 -0
  37. package/cjs/services/utils.js +33 -1
  38. package/cjs/services/viem.d.ts +12 -12
  39. package/cjs/spark/index.js +1 -0
  40. package/cjs/staking/staking.js +3 -1
  41. package/cjs/types/claiming.d.ts +93 -0
  42. package/cjs/types/claiming.js +27 -0
  43. package/cjs/umbrella/index.d.ts +5 -0
  44. package/cjs/umbrella/index.js +50 -0
  45. package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
  46. package/cjs/umbrella/umbrellaUtils.js +34 -0
  47. package/esm/aaveV2/index.js +1 -0
  48. package/esm/aaveV3/index.d.ts +12 -0
  49. package/esm/aaveV3/index.js +91 -1
  50. package/esm/claiming/aaveV3.d.ts +9 -0
  51. package/esm/claiming/aaveV3.js +139 -0
  52. package/esm/claiming/compV3.d.ts +15 -0
  53. package/esm/claiming/compV3.js +30 -0
  54. package/esm/claiming/index.d.ts +6 -0
  55. package/esm/claiming/index.js +6 -0
  56. package/esm/claiming/king.d.ts +4 -0
  57. package/esm/claiming/king.js +64 -0
  58. package/esm/claiming/morphoBlue.d.ts +6 -0
  59. package/esm/claiming/morphoBlue.js +104 -0
  60. package/esm/claiming/spark.d.ts +6 -0
  61. package/esm/claiming/spark.js +179 -0
  62. package/esm/config/contracts.d.ts +2681 -0
  63. package/esm/config/contracts.js +102 -1
  64. package/esm/constants/index.d.ts +4 -0
  65. package/esm/constants/index.js +5 -1
  66. package/esm/contracts.d.ts +3027 -23
  67. package/esm/contracts.js +9 -0
  68. package/esm/index.d.ts +2 -1
  69. package/esm/index.js +2 -1
  70. package/esm/liquity/index.d.ts +11 -0
  71. package/esm/liquity/index.js +38 -1
  72. package/esm/liquityV2/index.d.ts +35 -0
  73. package/esm/liquityV2/index.js +137 -4
  74. package/esm/markets/aave/marketAssets.js +1 -1
  75. package/esm/markets/compound/marketsAssets.js +2 -2
  76. package/esm/markets/spark/marketAssets.js +1 -1
  77. package/esm/morphoBlue/index.d.ts +5 -0
  78. package/esm/morphoBlue/index.js +38 -5
  79. package/esm/portfolio/index.d.ts +6 -1
  80. package/esm/portfolio/index.js +300 -15
  81. package/esm/services/utils.d.ts +5 -0
  82. package/esm/services/utils.js +31 -0
  83. package/esm/services/viem.d.ts +12 -12
  84. package/esm/spark/index.js +1 -0
  85. package/esm/staking/staking.js +3 -1
  86. package/esm/types/claiming.d.ts +93 -0
  87. package/esm/types/claiming.js +24 -0
  88. package/esm/umbrella/index.d.ts +5 -0
  89. package/esm/umbrella/index.js +46 -0
  90. package/esm/umbrella/umbrellaUtils.d.ts +22 -0
  91. package/esm/umbrella/umbrellaUtils.js +28 -0
  92. package/package.json +2 -2
  93. package/src/aaveV2/index.ts +2 -1
  94. package/src/aaveV3/index.ts +100 -2
  95. package/src/claiming/aaveV3.ts +163 -0
  96. package/src/claiming/compV3.ts +23 -0
  97. package/src/claiming/index.ts +13 -0
  98. package/src/claiming/king.ts +66 -0
  99. package/src/claiming/morphoBlue.ts +119 -0
  100. package/src/claiming/spark.ts +226 -0
  101. package/src/config/contracts.ts +105 -5
  102. package/src/constants/index.ts +5 -1
  103. package/src/contracts.ts +14 -1
  104. package/src/index.ts +2 -0
  105. package/src/liquity/index.ts +57 -2
  106. package/src/liquityV2/index.ts +241 -4
  107. package/src/markets/aave/marketAssets.ts +1 -1
  108. package/src/markets/compound/marketsAssets.ts +2 -2
  109. package/src/markets/spark/marketAssets.ts +1 -1
  110. package/src/morphoBlue/index.ts +43 -6
  111. package/src/portfolio/index.ts +302 -15
  112. package/src/services/utils.ts +37 -1
  113. package/src/spark/index.ts +2 -1
  114. package/src/staking/staking.ts +2 -1
  115. package/src/types/claiming.ts +109 -0
  116. package/src/umbrella/index.ts +70 -0
  117. package/src/umbrella/umbrellaUtils.ts +30 -0
@@ -2,9 +2,14 @@ import Dec from 'decimal.js';
2
2
  import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
3
3
  import { Client, PublicClient } from 'viem';
4
4
  import {
5
- createViemContractFromConfigFunc, LiquityV2LegacyViewContractViem, LiquityV2ViewContractViem,
5
+ createViemContractFromConfigFunc,
6
+ LiquityV2LegacyViewContractViem,
7
+ LiquityV2sBoldVaultViem,
8
+ LiquityV2ViewContractViem,
6
9
  } from '../contracts';
7
- import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
10
+ import {
11
+ EthAddress, EthereumProvider, HexString, NetworkNumber,
12
+ } from '../types/common';
8
13
  import {
9
14
  LIQUITY_V2_TROVE_STATUS_ENUM,
10
15
  LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2UsedAssets,
@@ -12,11 +17,25 @@ import {
12
17
  } from '../types';
13
18
  import { getStakingApy, STAKING_ASSETS } from '../staking';
14
19
  import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
15
- import { compareAddresses, ethToWeth, MAXUINT } from '../services/utils';
16
- import { ZERO_ADDRESS } from '../constants';
20
+ import {
21
+ compareAddresses,
22
+ ethToWeth,
23
+ getEthAmountForDecimals,
24
+ MAXUINT,
25
+ } from '../services/utils';
26
+ import { SECONDS_PER_YEAR, ZERO_ADDRESS } from '../constants';
17
27
  import { LiquityV2Markets } from '../markets';
18
28
  import { getViemProvider } from '../services/viem';
19
29
 
30
+ export type SPYieldGainParameters = {
31
+ P: string;
32
+ aggWeightedDebtSum: string;
33
+ currentScale: string;
34
+ lastAggUpdateTime: string;
35
+ totalBoldDeposits: string;
36
+ yieldGainsPending: string;
37
+ };
38
+
20
39
  const getLiquityV2ViewContract = (provider: Client, network: NetworkNumber, isLegacy: boolean) => {
21
40
  if (isLegacy) return LiquityV2LegacyViewContractViem(provider, network);
22
41
  return LiquityV2ViewContractViem(provider, network);
@@ -406,3 +425,221 @@ export const getLiquityV2ClaimableCollateral = async (collSurplusPoolAddress: Et
406
425
  const claimableCollateral = await collSurplusPoolContract.read.getCollateral([account]);
407
426
  return claimableCollateral.toString();
408
427
  };
428
+
429
+ const stabilityPoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
430
+ [LiquityV2Versions.LiquityV2Eth]: '0x5721cbbd64fc7Ae3Ef44A0A3F9a790A9264Cf9BF',
431
+ [LiquityV2Versions.LiquityV2WstEth]: '0x9502b7c397e9aa22fe9db7ef7daf21cd2aebe56b',
432
+ [LiquityV2Versions.LiquityV2REth]: '0xd442e41019b7f5c4dd78f50dc03726c446148695',
433
+ [LiquityV2Versions.LiquityV2EthLegacy]: '0x',
434
+ [LiquityV2Versions.LiquityV2REthLegacy]: '0x',
435
+ [LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
436
+ };
437
+ const activePoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
438
+ [LiquityV2Versions.LiquityV2Eth]: '0xeB5A8C825582965f1d84606E078620a84ab16AfE',
439
+ [LiquityV2Versions.LiquityV2WstEth]: '0x531a8f99c70d6a56a7cee02d6b4281650d7919a0',
440
+ [LiquityV2Versions.LiquityV2REth]: '0x9074d72cc82dad1e13e454755aa8f144c479532f',
441
+ [LiquityV2Versions.LiquityV2EthLegacy]: '0x',
442
+ [LiquityV2Versions.LiquityV2WstEthLegacy]: '0x',
443
+ [LiquityV2Versions.LiquityV2REthLegacy]: '0x',
444
+ };
445
+
446
+ function ceilDiv(a: string, b: string) {
447
+ return new Dec(a).add(new Dec(b).sub(1)).div(b).toString();
448
+ }
449
+ const SP_YIELD_SPLIT = new Dec(75).mul(10 ** 16).toString(); // 75%
450
+
451
+ const calcPendingSPYield = (
452
+ aggWeightedDebtSum: string,
453
+ lastAggUpdateTime: string,
454
+ currentTime: string,
455
+ ) => {
456
+ const a = new Dec(aggWeightedDebtSum).mul(
457
+ new Dec(currentTime).sub(new Dec(lastAggUpdateTime)),
458
+ ).toString();
459
+ const b = new Dec(SECONDS_PER_YEAR).mul(1000).mul(1e18).toString();
460
+ return new Dec(ceilDiv(a, b)).mul(SP_YIELD_SPLIT).div(1e18).toString();
461
+ };
462
+
463
+
464
+ const calculateStabilityPoolApy = (
465
+ spYieldGainParams: SPYieldGainParameters,
466
+ ) => {
467
+ const {
468
+ aggWeightedDebtSum, totalBoldDeposits, lastAggUpdateTime, yieldGainsPending,
469
+ } = spYieldGainParams;
470
+
471
+ if (new Dec(totalBoldDeposits).eq(0)) {
472
+ return '0';
473
+ }
474
+
475
+ const now = Date.now().toString();
476
+ const lastAggUpdateTimeScaled = new Dec(lastAggUpdateTime).mul(1000).toString();
477
+
478
+ const pendingSPYield = new Dec(calcPendingSPYield(
479
+ aggWeightedDebtSum,
480
+ lastAggUpdateTimeScaled,
481
+ now,
482
+ )).add(yieldGainsPending).toString();
483
+
484
+ const annualizedYield = new Dec(pendingSPYield).mul(SECONDS_PER_YEAR).mul(1000).div(new Dec(now).minus(lastAggUpdateTimeScaled))
485
+ .toString();
486
+ return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
487
+ };
488
+
489
+ const getYBoldApyApi = async () => {
490
+ const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
491
+
492
+ const yBoldData = await fetch(url)
493
+ .then(res => res.json())
494
+ .catch(console.error);
495
+
496
+ return new Dec(yBoldData.apr.netAPR).mul(100).toString();
497
+ };
498
+
499
+ export type sBoldYieldParameters = {
500
+ WETH: string;
501
+ wsETH: string;
502
+ rETH: string;
503
+ };
504
+
505
+ const calculateSPApy = (
506
+ spYieldGainParams: sBoldYieldParameters, spAPYs: { apyEth: Dec.Value; apyWstEth: Dec.Value; apyREth: Dec.Value; },
507
+ ) => {
508
+ const {
509
+ WETH, wsETH, rETH,
510
+ } = spYieldGainParams;
511
+
512
+ const apy = new Dec(WETH).mul(spAPYs.apyEth).add(new Dec(wsETH).mul(spAPYs.apyWstEth)).add(new Dec(rETH).mul(spAPYs.apyREth))
513
+ .toString();
514
+ return apy;
515
+ };
516
+
517
+ export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => {
518
+ const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
519
+ const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
520
+
521
+ const debtTokenInfo = getAssetInfo(LiquityV2Markets(network)[market].debtToken, network);
522
+ const debtTokenContract = createViemContractFromConfigFunc('Erc20', debtTokenInfo.address as HexString)(provider, network);
523
+
524
+ const [
525
+ stabilityRewardColl,
526
+ stabilityRewardYield,
527
+ compoundedBoldDeposit,
528
+ totalBoldDeposits,
529
+ P,
530
+ currentScale,
531
+ yieldGainsPending,
532
+ debtTokenBalance,
533
+
534
+ aggWeightedDebtSum,
535
+ lastAggUpdateTime,
536
+ ] = await Promise.all([
537
+ stabilityPoolView.read.getDepositorCollGain([user]),
538
+ stabilityPoolView.read.getDepositorYieldGain([user]),
539
+ stabilityPoolView.read.getCompoundedBoldDeposit([user]),
540
+ stabilityPoolView.read.getTotalBoldDeposits(),
541
+ stabilityPoolView.read.P(),
542
+ stabilityPoolView.read.currentScale(),
543
+ stabilityPoolView.read.getYieldGainsPending(),
544
+ debtTokenContract.read.balanceOf([user]),
545
+
546
+ activePoolView.read.aggWeightedDebtSum(),
547
+ activePoolView.read.lastAggUpdateTime(),
548
+ ]);
549
+
550
+ const stabilityPoolYieldParams: SPYieldGainParameters = {
551
+ aggWeightedDebtSum: aggWeightedDebtSum.toString(),
552
+ lastAggUpdateTime: lastAggUpdateTime.toString(),
553
+ P: P.toString(),
554
+ currentScale: currentScale.toString(),
555
+ yieldGainsPending: yieldGainsPending.toString(),
556
+ totalBoldDeposits: totalBoldDeposits.toString(),
557
+ };
558
+
559
+ const stabilityPoolApy = calculateStabilityPoolApy(stabilityPoolYieldParams);
560
+
561
+ const stakedBOLDBalanceForUser = getEthAmountForDecimals(compoundedBoldDeposit.toString(), 18);
562
+ const stabilityRewardCollForUser = getEthAmountForDecimals(stabilityRewardColl.toString(), 18);
563
+ const stabilityRewardYieldForUser = getEthAmountForDecimals(stabilityRewardYield.toString(), 18);
564
+
565
+ return {
566
+ totalBOLDDeposited: getEthAmountForDecimals(totalBoldDeposits.toString(), 18),
567
+ stakedBOLDBalance: stakedBOLDBalanceForUser,
568
+ stabilityRewardColl: stabilityRewardCollForUser,
569
+ stabilityRewardYield: stabilityRewardYieldForUser,
570
+ showStakingBalances: !!(+stakedBOLDBalanceForUser || +stabilityRewardCollForUser || +stabilityRewardYieldForUser),
571
+ debtTokenBalance: getEthAmountForDecimals(debtTokenBalance.toString(), debtTokenInfo.decimals),
572
+ stabilityPoolApy,
573
+ };
574
+ };
575
+
576
+ export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => {
577
+ const sBold = LiquityV2sBoldVaultViem(provider, network);
578
+ const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
579
+ const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
580
+ const spAPYs = {
581
+ apyEth: markets[LiquityV2Versions.LiquityV2Eth].data.stabilityPoolApy,
582
+ apyWstEth: markets[LiquityV2Versions.LiquityV2WstEth].data.stabilityPoolApy,
583
+ apyREth: markets[LiquityV2Versions.LiquityV2REth].data.stabilityPoolApy,
584
+ };
585
+
586
+ const [
587
+ sBoldTotalAssets,
588
+ sBoldConvertToShares,
589
+ sBoldMaxWithdraw,
590
+
591
+ wethApy,
592
+ wsETHApy,
593
+ rETHApy,
594
+
595
+ yBoldTotalAssets,
596
+ yBoldMaxWithdraw,
597
+ stYBoldConvertToShares,
598
+
599
+ yBoldApy,
600
+
601
+ sBoldBalance,
602
+ yBoldBalance,
603
+ stYBoldBalance,
604
+ ] = await Promise.all([
605
+ sBold.read.totalAssets(),
606
+ sBold.read.convertToShares([BigInt(1e18)]),
607
+ sBold.read.maxWithdraw([user]),
608
+
609
+ sBold.read.sps([BigInt(0)]),
610
+ sBold.read.sps([BigInt(1)]),
611
+ sBold.read.sps([BigInt(2)]),
612
+
613
+ yBold.read.totalAssets(),
614
+ yBold.read.maxWithdraw([user]),
615
+ stYBold.read.convertToShares([BigInt(1e18)]),
616
+ getYBoldApyApi(),
617
+
618
+ sBold.read.balanceOf([user]),
619
+ yBold.read.balanceOf([user]),
620
+ stYBold.read.balanceOf([user]),
621
+ ]);
622
+
623
+ const spMarketRes = {
624
+ WETH: new Dec(wethApy[1]).div(10000).toString(),
625
+ wsETH: new Dec(wsETHApy[1]).div(10000).toString(),
626
+ rETH: new Dec(rETHApy[1]).div(10000).toString(),
627
+ };
628
+
629
+ const spApy = calculateSPApy(spMarketRes, spAPYs);
630
+
631
+ return {
632
+ spApy,
633
+ yBoldApy,
634
+ totalBoldDepositedSBold: assetAmountInEth(sBoldTotalAssets.toString(), 'sBOLD'),
635
+ boldRateSBold: assetAmountInEth(sBoldConvertToShares.toString(), 'sBOLD'),
636
+ maxWithdrawSBold: assetAmountInEth(sBoldMaxWithdraw.toString(), 'sBOLD'),
637
+ totalBoldDepositedYBold: assetAmountInEth(yBoldTotalAssets.toString(), 'yBOLD'),
638
+ boldRateYBold: assetAmountInEth(stYBoldConvertToShares.toString(), 'yBOLD'),
639
+ maxWithdrawYBold: assetAmountInEth(yBoldMaxWithdraw.toString(), 'yBOLD'),
640
+
641
+ sBoldBalance: assetAmountInEth(sBoldBalance.toString(), 'sBOLD'),
642
+ yBoldBalance: assetAmountInEth(yBoldBalance.toString(), 'yBOLD'),
643
+ stYBoldBalance: assetAmountInEth(stYBoldBalance.toString(), 'yBOLD'),
644
+ };
645
+ };
@@ -10,7 +10,7 @@ export const aaveV2AssetsDefaultMarket = ['USDT', 'WBTC', 'ETH', 'YFI', 'ZRX', '
10
10
 
11
11
  export const aaveV3AssetsDefaultMarketEth = [
12
12
  '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',
13
- 'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov',
13
+ 'eUSDe', 'PT USDe July', 'PT eUSDe Aug', 'EURC', 'FBTC', 'PT sUSDe Sep', 'PT USDe Sep', 'tETH', 'ezETH', 'XAUt', 'PT sUSDe Nov', 'PT USDe Nov',
14
14
  ];
15
15
  export const aaveV3AssetsDefaultMarketOpt = [
16
16
  'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
@@ -6,7 +6,7 @@ export const compoundV2CollateralAssets: AssetData[] = [
6
6
  'cTUSD', 'cLINK', 'cUSDP', 'cUNI', 'cCOMP', 'cMKR', 'cSUSHI', 'cAAVE', 'cYFI',
7
7
  ].map((symbol) => getAssetInfo(symbol));
8
8
 
9
- export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD'];
9
+ export const v3USDCCollAssetsEth = ['COMP', 'WBTC', 'ETH', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'weETH', 'deUSD', 'sdeUSD', 'rsETH'];
10
10
  export const v3USDCCollAssetsArb = ['ARB', 'ETH', 'GMX', 'WBTC', 'wstETH', 'ezETH', 'wUSDM'];
11
11
  export const v3USDCCollAssetsBase = ['cbETH', 'ETH', 'wstETH', 'cbBTC', 'tBTC'];
12
12
  export const v3USDCCollAssetsOpt = ['ETH', 'OP', 'WBTC', 'wstETH'];
@@ -56,7 +56,7 @@ export const v3USDbCCollAssets = {
56
56
  [NetworkNumber.Linea]: [],
57
57
  };
58
58
 
59
- export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
59
+ export const v3USDTCollAssetsEth = ['COMP', 'ETH', 'WBTC', 'UNI', 'LINK', 'wstETH', 'cbBTC', 'tBTC', 'wUSDM', 'sFRAX', 'mETH', 'weETH', 'sdeUSD', 'deUSD'];
60
60
  export const v3USDTCollAssetsArb = ['ETH', 'WBTC', 'wstETH', 'ARB', 'GMX'];
61
61
  export const v3USDTCollAssetsOpt = ['ETH', 'WBTC', 'OP', 'wstETH'];
62
62
 
@@ -1,6 +1,6 @@
1
1
  import { NetworkNumber } from '../../types/common';
2
2
 
3
- export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH'];
3
+ export const sparkAssetsDefaultMarketEth = ['DAI', 'sDAI', 'USDC', 'ETH', 'wstETH', 'WBTC', 'GNO', 'rETH', 'USDT', 'weETH', 'cbBTC', 'sUSDS', 'USDS', 'LBTC', 'tBTC', 'ezETH', 'rsETH', 'PYUSD'];
4
4
 
5
5
  // @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
6
6
  export const sparkAssetsDefaultMarket = {
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
2
2
  import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
3
3
  import { Client } from 'viem';
4
4
  import {
5
- Blockish, EthAddress, EthereumProvider, MMUsedAssets, NetworkNumber, PositionBalances,
5
+ Blockish, EthAddress, EthereumProvider, MMAssetsData, MMUsedAssets, NetworkNumber, PositionBalances,
6
6
  } from '../types/common';
7
7
  import {
8
8
  DFSFeedRegistryContractViem, FeedRegistryContractViem, MorphoBlueViewContractViem,
@@ -11,7 +11,7 @@ import {
11
11
  MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBluePositionData,
12
12
  } from '../types';
13
13
  import { USD_QUOTE, WAD } from '../constants';
14
- import { getStakingApy, STAKING_ASSETS } from '../staking';
14
+ import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../staking';
15
15
  import { isMainnetNetwork, wethToEth } from '../services/utils';
16
16
  import {
17
17
  getBorrowRate, getMorphoBlueAggregatedPositionData, getRewardsForMarket, getSupplyRate,
@@ -184,16 +184,15 @@ export async function _getMorphoBlueAccountData(provider: Client, network: Netwo
184
184
  const usedAssets: MMUsedAssets = {};
185
185
 
186
186
  const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
187
- const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
188
187
  const loanTokenBorrowed = assetAmountInEth(loanInfo.borrowedInAssets.toString(), marketInfo.loanToken);
189
188
  usedAssets[marketInfo.loanToken] = {
190
189
  symbol: loanTokenInfo.symbol,
191
- supplied: loanTokenSupplied,
190
+ supplied: '0',
192
191
  borrowed: loanTokenBorrowed,
193
- isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
192
+ isSupplied: false,
194
193
  isBorrowed: new Dec(loanInfo.borrowedInAssets.toString()).gt(0),
195
194
  collateral: false,
196
- suppliedUsd: new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString(),
195
+ suppliedUsd: '0',
197
196
  borrowedUsd: new Dec(loanTokenBorrowed).mul(loanTokenInfo.price).toString(),
198
197
  };
199
198
 
@@ -220,4 +219,42 @@ export async function _getMorphoBlueAccountData(provider: Client, network: Netwo
220
219
 
221
220
  export async function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData> {
222
221
  return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
222
+ }
223
+
224
+ export async function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<{ apy: string, amount: string, amountUsd: string }> {
225
+ const {
226
+ loanToken, collateralToken, oracle, irm, lltv,
227
+ } = selectedMarket;
228
+ const lltvInWei = new Dec(lltv).mul(WAD).toString();
229
+
230
+ const viewContract = MorphoBlueViewContractViem(provider, network);
231
+ const loanInfo = (await viewContract.read.getUserInfo([
232
+ {
233
+ loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
234
+ },
235
+ account]));
236
+
237
+ const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
238
+ const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
239
+ const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
240
+ const usedAssets: MMUsedAssets = {
241
+ [marketInfo.loanToken]: {
242
+ symbol: loanTokenInfo.symbol,
243
+ supplied: loanTokenSupplied,
244
+ borrowed: '0',
245
+ isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
246
+ isBorrowed: false,
247
+ collateral: false,
248
+ suppliedUsd: loanTokenSuppliedUsd,
249
+ borrowedUsd: '0',
250
+ },
251
+ };
252
+
253
+ const { netApy } = calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData as unknown as MMAssetsData });
254
+
255
+ return {
256
+ apy: netApy,
257
+ amount: loanTokenSupplied,
258
+ amountUsd: loanTokenSuppliedUsd,
259
+ };
223
260
  }