@defisaver/positions-sdk 2.1.1 → 2.1.3
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.
- package/cjs/aaveV2/index.js +1 -0
- package/cjs/aaveV3/index.d.ts +12 -0
- package/cjs/aaveV3/index.js +93 -1
- package/cjs/claiming/aaveV3.d.ts +5 -0
- package/cjs/claiming/aaveV3.js +139 -0
- package/cjs/claiming/compV3.d.ts +15 -0
- package/cjs/claiming/compV3.js +34 -0
- package/cjs/claiming/index.d.ts +6 -0
- package/cjs/claiming/index.js +46 -0
- package/cjs/claiming/king.d.ts +4 -0
- package/cjs/claiming/king.js +72 -0
- package/cjs/claiming/morphoBlue.d.ts +5 -0
- package/cjs/claiming/morphoBlue.js +113 -0
- package/cjs/claiming/spark.d.ts +6 -0
- package/cjs/claiming/spark.js +188 -0
- package/cjs/config/contracts.d.ts +2681 -0
- package/cjs/config/contracts.js +103 -2
- package/cjs/constants/index.d.ts +4 -0
- package/cjs/constants/index.js +6 -2
- package/cjs/contracts.d.ts +3027 -23
- package/cjs/contracts.js +10 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +4 -0
- package/cjs/helpers/aaveHelpers/index.js +25 -8
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/cjs/helpers/morphoBlueHelpers/index.js +7 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/liquity/index.d.ts +11 -0
- package/cjs/liquity/index.js +39 -1
- package/cjs/liquityV2/index.d.ts +35 -0
- package/cjs/liquityV2/index.js +142 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +35 -0
- package/cjs/portfolio/index.d.ts +6 -1
- package/cjs/portfolio/index.js +293 -10
- package/cjs/services/utils.d.ts +5 -0
- package/cjs/services/utils.js +33 -1
- package/cjs/services/viem.d.ts +12 -12
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/eligibility.d.ts +4 -2
- package/cjs/staking/eligibility.js +3 -4
- package/cjs/staking/staking.d.ts +2 -1
- package/cjs/staking/staking.js +3 -3
- package/cjs/types/claiming.d.ts +93 -0
- package/cjs/types/claiming.js +27 -0
- package/cjs/types/common.d.ts +1 -1
- package/cjs/types/common.js +1 -1
- package/cjs/umbrella/index.d.ts +5 -0
- package/cjs/umbrella/index.js +50 -0
- package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
- package/cjs/umbrella/umbrellaUtils.js +34 -0
- package/esm/aaveV2/index.js +1 -0
- package/esm/aaveV3/index.d.ts +12 -0
- package/esm/aaveV3/index.js +91 -1
- package/esm/claiming/aaveV3.d.ts +5 -0
- package/esm/claiming/aaveV3.js +132 -0
- package/esm/claiming/compV3.d.ts +15 -0
- package/esm/claiming/compV3.js +30 -0
- package/esm/claiming/index.d.ts +6 -0
- package/esm/claiming/index.js +6 -0
- package/esm/claiming/king.d.ts +4 -0
- package/esm/claiming/king.js +64 -0
- package/esm/claiming/morphoBlue.d.ts +5 -0
- package/esm/claiming/morphoBlue.js +105 -0
- package/esm/claiming/spark.d.ts +6 -0
- package/esm/claiming/spark.js +179 -0
- package/esm/config/contracts.d.ts +2681 -0
- package/esm/config/contracts.js +102 -1
- package/esm/constants/index.d.ts +4 -0
- package/esm/constants/index.js +5 -1
- package/esm/contracts.d.ts +3027 -23
- package/esm/contracts.js +9 -0
- package/esm/helpers/aaveHelpers/index.d.ts +4 -0
- package/esm/helpers/aaveHelpers/index.js +23 -7
- package/esm/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/esm/helpers/morphoBlueHelpers/index.js +6 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/liquity/index.d.ts +11 -0
- package/esm/liquity/index.js +38 -1
- package/esm/liquityV2/index.d.ts +35 -0
- package/esm/liquityV2/index.js +142 -3
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +35 -1
- package/esm/portfolio/index.d.ts +6 -1
- package/esm/portfolio/index.js +298 -15
- package/esm/services/utils.d.ts +5 -0
- package/esm/services/utils.js +31 -0
- package/esm/services/viem.d.ts +12 -12
- package/esm/spark/index.js +1 -0
- package/esm/staking/eligibility.d.ts +4 -2
- package/esm/staking/eligibility.js +3 -4
- package/esm/staking/staking.d.ts +2 -1
- package/esm/staking/staking.js +3 -3
- package/esm/types/claiming.d.ts +93 -0
- package/esm/types/claiming.js +24 -0
- package/esm/types/common.d.ts +1 -1
- package/esm/types/common.js +1 -1
- package/esm/umbrella/index.d.ts +5 -0
- package/esm/umbrella/index.js +46 -0
- package/esm/umbrella/umbrellaUtils.d.ts +22 -0
- package/esm/umbrella/umbrellaUtils.js +28 -0
- package/package.json +1 -1
- package/src/aaveV2/index.ts +2 -1
- package/src/aaveV3/index.ts +100 -2
- package/src/claiming/aaveV3.ts +155 -0
- package/src/claiming/compV3.ts +23 -0
- package/src/claiming/index.ts +13 -0
- package/src/claiming/king.ts +66 -0
- package/src/claiming/morphoBlue.ts +119 -0
- package/src/claiming/spark.ts +226 -0
- package/src/config/contracts.ts +104 -4
- package/src/constants/index.ts +5 -1
- package/src/contracts.ts +14 -1
- package/src/helpers/aaveHelpers/index.ts +24 -7
- package/src/helpers/morphoBlueHelpers/index.ts +7 -2
- package/src/index.ts +2 -0
- package/src/liquity/index.ts +57 -2
- package/src/liquityV2/index.ts +244 -4
- package/src/morphoBlue/index.ts +40 -2
- package/src/portfolio/index.ts +300 -15
- package/src/services/utils.ts +37 -1
- package/src/spark/index.ts +2 -1
- package/src/staking/eligibility.ts +3 -4
- package/src/staking/staking.ts +4 -4
- package/src/types/claiming.ts +109 -0
- package/src/types/common.ts +1 -1
- package/src/umbrella/index.ts +70 -0
- package/src/umbrella/umbrellaUtils.ts +30 -0
package/src/liquityV2/index.ts
CHANGED
|
@@ -2,10 +2,13 @@ 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,
|
|
5
|
+
createViemContractFromConfigFunc,
|
|
6
|
+
LiquityV2LegacyViewContractViem,
|
|
7
|
+
LiquityV2sBoldVaultViem,
|
|
8
|
+
LiquityV2ViewContractViem,
|
|
6
9
|
} from '../contracts';
|
|
7
10
|
import {
|
|
8
|
-
EthAddress, EthereumProvider, IncentiveKind, NetworkNumber,
|
|
11
|
+
EthAddress, EthereumProvider, IncentiveKind, NetworkNumber, HexString,
|
|
9
12
|
} from '../types/common';
|
|
10
13
|
import {
|
|
11
14
|
LIQUITY_V2_TROVE_STATUS_ENUM,
|
|
@@ -14,11 +17,25 @@ import {
|
|
|
14
17
|
} from '../types';
|
|
15
18
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
19
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
17
|
-
import {
|
|
18
|
-
|
|
20
|
+
import {
|
|
21
|
+
compareAddresses,
|
|
22
|
+
ethToWeth,
|
|
23
|
+
getEthAmountForDecimals,
|
|
24
|
+
MAXUINT,
|
|
25
|
+
} from '../services/utils';
|
|
26
|
+
import { SECONDS_PER_YEAR, ZERO_ADDRESS } from '../constants';
|
|
19
27
|
import { LiquityV2Markets } from '../markets';
|
|
20
28
|
import { getViemProvider } from '../services/viem';
|
|
21
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
|
+
|
|
22
39
|
const getLiquityV2ViewContract = (provider: Client, network: NetworkNumber, isLegacy: boolean) => {
|
|
23
40
|
if (isLegacy) return LiquityV2LegacyViewContractViem(provider, network);
|
|
24
41
|
return LiquityV2ViewContractViem(provider, network);
|
|
@@ -416,3 +433,226 @@ export const getLiquityV2ClaimableCollateral = async (collSurplusPoolAddress: Et
|
|
|
416
433
|
const claimableCollateral = await collSurplusPoolContract.read.getCollateral([account]);
|
|
417
434
|
return claimableCollateral.toString();
|
|
418
435
|
};
|
|
436
|
+
|
|
437
|
+
const stabilityPoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
|
|
438
|
+
[LiquityV2Versions.LiquityV2Eth]: '0x5721cbbd64fc7Ae3Ef44A0A3F9a790A9264Cf9BF',
|
|
439
|
+
[LiquityV2Versions.LiquityV2WstEth]: '0x9502b7c397e9aa22fe9db7ef7daf21cd2aebe56b',
|
|
440
|
+
[LiquityV2Versions.LiquityV2REth]: '0xd442e41019b7f5c4dd78f50dc03726c446148695',
|
|
441
|
+
[LiquityV2Versions.LiquityV2EthLegacy]: ZERO_ADDRESS,
|
|
442
|
+
[LiquityV2Versions.LiquityV2REthLegacy]: ZERO_ADDRESS,
|
|
443
|
+
[LiquityV2Versions.LiquityV2WstEthLegacy]: ZERO_ADDRESS,
|
|
444
|
+
};
|
|
445
|
+
const activePoolAddrForMarket: Record<LiquityV2Versions, EthAddress> = {
|
|
446
|
+
[LiquityV2Versions.LiquityV2Eth]: '0xeB5A8C825582965f1d84606E078620a84ab16AfE',
|
|
447
|
+
[LiquityV2Versions.LiquityV2WstEth]: '0x531a8f99c70d6a56a7cee02d6b4281650d7919a0',
|
|
448
|
+
[LiquityV2Versions.LiquityV2REth]: '0x9074d72cc82dad1e13e454755aa8f144c479532f',
|
|
449
|
+
[LiquityV2Versions.LiquityV2EthLegacy]: ZERO_ADDRESS,
|
|
450
|
+
[LiquityV2Versions.LiquityV2WstEthLegacy]: ZERO_ADDRESS,
|
|
451
|
+
[LiquityV2Versions.LiquityV2REthLegacy]: ZERO_ADDRESS,
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
function ceilDiv(a: string, b: string) {
|
|
455
|
+
return new Dec(a).add(new Dec(b).sub(1)).div(b).toString();
|
|
456
|
+
}
|
|
457
|
+
const SP_YIELD_SPLIT = new Dec(75).mul(10 ** 16).toString(); // 75%
|
|
458
|
+
|
|
459
|
+
const calcPendingSPYield = (
|
|
460
|
+
aggWeightedDebtSum: string,
|
|
461
|
+
lastAggUpdateTime: string,
|
|
462
|
+
currentTime: string,
|
|
463
|
+
) => {
|
|
464
|
+
const a = new Dec(aggWeightedDebtSum).mul(
|
|
465
|
+
new Dec(currentTime).sub(new Dec(lastAggUpdateTime)),
|
|
466
|
+
).toString();
|
|
467
|
+
const b = new Dec(SECONDS_PER_YEAR).mul(1000).mul(1e18).toString();
|
|
468
|
+
return new Dec(ceilDiv(a, b)).mul(SP_YIELD_SPLIT).div(1e18).toString();
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
const calculateStabilityPoolApy = (
|
|
473
|
+
spYieldGainParams: SPYieldGainParameters,
|
|
474
|
+
) => {
|
|
475
|
+
const {
|
|
476
|
+
aggWeightedDebtSum, totalBoldDeposits, lastAggUpdateTime, yieldGainsPending,
|
|
477
|
+
} = spYieldGainParams;
|
|
478
|
+
|
|
479
|
+
if (new Dec(totalBoldDeposits).eq(0)) {
|
|
480
|
+
return '0';
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const now = Date.now().toString();
|
|
484
|
+
const lastAggUpdateTimeScaled = new Dec(lastAggUpdateTime).mul(1000).toString();
|
|
485
|
+
|
|
486
|
+
const pendingSPYield = new Dec(calcPendingSPYield(
|
|
487
|
+
aggWeightedDebtSum,
|
|
488
|
+
lastAggUpdateTimeScaled,
|
|
489
|
+
now,
|
|
490
|
+
)).add(yieldGainsPending).toString();
|
|
491
|
+
|
|
492
|
+
const annualizedYield = new Dec(pendingSPYield).mul(SECONDS_PER_YEAR).mul(1000).div(new Dec(now).minus(lastAggUpdateTimeScaled))
|
|
493
|
+
.toString();
|
|
494
|
+
return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
const getYBoldApyApi = async () => {
|
|
498
|
+
try {
|
|
499
|
+
const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
|
|
500
|
+
|
|
501
|
+
const yBoldData = await fetch(url)
|
|
502
|
+
.then(res => res.json())
|
|
503
|
+
.catch(console.error);
|
|
504
|
+
|
|
505
|
+
return new Dec(yBoldData.apr.netAPR).mul(100).toString();
|
|
506
|
+
} catch (error) {
|
|
507
|
+
console.error('External API Failure: YBold ', error);
|
|
508
|
+
return '0';
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
export type sBoldYieldParameters = {
|
|
513
|
+
WETH: string;
|
|
514
|
+
wsETH: string;
|
|
515
|
+
rETH: string;
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
const calculateSPApy = (
|
|
519
|
+
spYieldGainParams: sBoldYieldParameters, spAPYs: { apyEth: Dec.Value; apyWstEth: Dec.Value; apyREth: Dec.Value; },
|
|
520
|
+
) => {
|
|
521
|
+
const {
|
|
522
|
+
WETH, wsETH, rETH,
|
|
523
|
+
} = spYieldGainParams;
|
|
524
|
+
|
|
525
|
+
const apy = new Dec(WETH).mul(spAPYs.apyEth).add(new Dec(wsETH).mul(spAPYs.apyWstEth)).add(new Dec(rETH).mul(spAPYs.apyREth))
|
|
526
|
+
.toString();
|
|
527
|
+
return apy;
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => {
|
|
531
|
+
const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
|
|
532
|
+
const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
|
|
533
|
+
|
|
534
|
+
const debtTokenInfo = getAssetInfo(LiquityV2Markets(network)[market].debtToken, network);
|
|
535
|
+
const debtTokenContract = createViemContractFromConfigFunc('Erc20', debtTokenInfo.address as HexString)(provider, network);
|
|
536
|
+
|
|
537
|
+
const [
|
|
538
|
+
stabilityRewardColl,
|
|
539
|
+
stabilityRewardYield,
|
|
540
|
+
compoundedBoldDeposit,
|
|
541
|
+
totalBoldDeposits,
|
|
542
|
+
P,
|
|
543
|
+
currentScale,
|
|
544
|
+
yieldGainsPending,
|
|
545
|
+
debtTokenBalance,
|
|
546
|
+
|
|
547
|
+
aggWeightedDebtSum,
|
|
548
|
+
lastAggUpdateTime,
|
|
549
|
+
] = await Promise.all([
|
|
550
|
+
stabilityPoolView.read.getDepositorCollGain([user]),
|
|
551
|
+
stabilityPoolView.read.getDepositorYieldGain([user]),
|
|
552
|
+
stabilityPoolView.read.getCompoundedBoldDeposit([user]),
|
|
553
|
+
stabilityPoolView.read.getTotalBoldDeposits(),
|
|
554
|
+
stabilityPoolView.read.P(),
|
|
555
|
+
stabilityPoolView.read.currentScale(),
|
|
556
|
+
stabilityPoolView.read.getYieldGainsPending(),
|
|
557
|
+
debtTokenContract.read.balanceOf([user]),
|
|
558
|
+
|
|
559
|
+
activePoolView.read.aggWeightedDebtSum(),
|
|
560
|
+
activePoolView.read.lastAggUpdateTime(),
|
|
561
|
+
]);
|
|
562
|
+
|
|
563
|
+
const stabilityPoolYieldParams: SPYieldGainParameters = {
|
|
564
|
+
aggWeightedDebtSum: aggWeightedDebtSum.toString(),
|
|
565
|
+
lastAggUpdateTime: lastAggUpdateTime.toString(),
|
|
566
|
+
P: P.toString(),
|
|
567
|
+
currentScale: currentScale.toString(),
|
|
568
|
+
yieldGainsPending: yieldGainsPending.toString(),
|
|
569
|
+
totalBoldDeposits: totalBoldDeposits.toString(),
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const stabilityPoolApy = calculateStabilityPoolApy(stabilityPoolYieldParams);
|
|
573
|
+
|
|
574
|
+
const stakedBOLDBalanceForUser = getEthAmountForDecimals(compoundedBoldDeposit.toString(), 18);
|
|
575
|
+
const stabilityRewardCollForUser = getEthAmountForDecimals(stabilityRewardColl.toString(), 18);
|
|
576
|
+
const stabilityRewardYieldForUser = getEthAmountForDecimals(stabilityRewardYield.toString(), 18);
|
|
577
|
+
|
|
578
|
+
return {
|
|
579
|
+
totalBOLDDeposited: getEthAmountForDecimals(totalBoldDeposits.toString(), 18),
|
|
580
|
+
stakedBOLDBalance: stakedBOLDBalanceForUser,
|
|
581
|
+
stabilityRewardColl: stabilityRewardCollForUser,
|
|
582
|
+
stabilityRewardYield: stabilityRewardYieldForUser,
|
|
583
|
+
showStakingBalances: !!(+stakedBOLDBalanceForUser || +stabilityRewardCollForUser || +stabilityRewardYieldForUser),
|
|
584
|
+
debtTokenBalance: getEthAmountForDecimals(debtTokenBalance.toString(), debtTokenInfo.decimals),
|
|
585
|
+
stabilityPoolApy,
|
|
586
|
+
};
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => {
|
|
590
|
+
const sBold = LiquityV2sBoldVaultViem(provider, network);
|
|
591
|
+
const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
|
|
592
|
+
const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
|
|
593
|
+
const spAPYs = {
|
|
594
|
+
apyEth: markets[LiquityV2Versions.LiquityV2Eth].data.stabilityPoolApy,
|
|
595
|
+
apyWstEth: markets[LiquityV2Versions.LiquityV2WstEth].data.stabilityPoolApy,
|
|
596
|
+
apyREth: markets[LiquityV2Versions.LiquityV2REth].data.stabilityPoolApy,
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
const [
|
|
600
|
+
sBoldTotalAssets,
|
|
601
|
+
sBoldConvertToShares,
|
|
602
|
+
sBoldMaxWithdraw,
|
|
603
|
+
|
|
604
|
+
wethApy,
|
|
605
|
+
wsETHApy,
|
|
606
|
+
rETHApy,
|
|
607
|
+
|
|
608
|
+
yBoldTotalAssets,
|
|
609
|
+
yBoldMaxWithdraw,
|
|
610
|
+
stYBoldConvertToShares,
|
|
611
|
+
|
|
612
|
+
yBoldApy,
|
|
613
|
+
|
|
614
|
+
sBoldBalance,
|
|
615
|
+
yBoldBalance,
|
|
616
|
+
stYBoldBalance,
|
|
617
|
+
] = await Promise.all([
|
|
618
|
+
sBold.read.totalAssets(),
|
|
619
|
+
sBold.read.convertToShares([BigInt(1e18)]),
|
|
620
|
+
sBold.read.maxWithdraw([user]),
|
|
621
|
+
|
|
622
|
+
sBold.read.sps([BigInt(0)]),
|
|
623
|
+
sBold.read.sps([BigInt(1)]),
|
|
624
|
+
sBold.read.sps([BigInt(2)]),
|
|
625
|
+
|
|
626
|
+
yBold.read.totalAssets(),
|
|
627
|
+
yBold.read.maxWithdraw([user]),
|
|
628
|
+
stYBold.read.convertToShares([BigInt(1e18)]),
|
|
629
|
+
getYBoldApyApi(),
|
|
630
|
+
|
|
631
|
+
sBold.read.balanceOf([user]),
|
|
632
|
+
yBold.read.balanceOf([user]),
|
|
633
|
+
stYBold.read.balanceOf([user]),
|
|
634
|
+
]);
|
|
635
|
+
|
|
636
|
+
const spMarketRes = {
|
|
637
|
+
WETH: new Dec(wethApy[1]).div(10000).toString(),
|
|
638
|
+
wsETH: new Dec(wsETHApy[1]).div(10000).toString(),
|
|
639
|
+
rETH: new Dec(rETHApy[1]).div(10000).toString(),
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
const spApy = calculateSPApy(spMarketRes, spAPYs);
|
|
643
|
+
|
|
644
|
+
return {
|
|
645
|
+
spApy,
|
|
646
|
+
yBoldApy,
|
|
647
|
+
totalBoldDepositedSBold: assetAmountInEth(sBoldTotalAssets.toString(), 'sBOLD'),
|
|
648
|
+
boldRateSBold: assetAmountInEth(sBoldConvertToShares.toString(), 'sBOLD'),
|
|
649
|
+
maxWithdrawSBold: assetAmountInEth(sBoldMaxWithdraw.toString(), 'sBOLD'),
|
|
650
|
+
totalBoldDepositedYBold: assetAmountInEth(yBoldTotalAssets.toString(), 'yBOLD'),
|
|
651
|
+
boldRateYBold: assetAmountInEth(stYBoldConvertToShares.toString(), 'yBOLD'),
|
|
652
|
+
maxWithdrawYBold: assetAmountInEth(yBoldMaxWithdraw.toString(), 'yBOLD'),
|
|
653
|
+
|
|
654
|
+
sBoldBalance: assetAmountInEth(sBoldBalance.toString(), 'sBOLD'),
|
|
655
|
+
yBoldBalance: assetAmountInEth(yBoldBalance.toString(), 'yBOLD'),
|
|
656
|
+
stYBoldBalance: assetAmountInEth(stYBoldBalance.toString(), 'yBOLD'),
|
|
657
|
+
};
|
|
658
|
+
};
|
package/src/morphoBlue/index.ts
CHANGED
|
@@ -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, IncentiveKind, MMUsedAssets, NetworkNumber, PositionBalances,
|
|
5
|
+
Blockish, EthAddress, EthereumProvider, IncentiveKind, MMUsedAssets, NetworkNumber, PositionBalances, MMAssetsData,
|
|
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,
|
|
@@ -234,4 +234,42 @@ export async function _getMorphoBlueAccountData(provider: Client, network: Netwo
|
|
|
234
234
|
|
|
235
235
|
export async function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData> {
|
|
236
236
|
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export async function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<{ apy: string, amount: string, amountUsd: string }> {
|
|
240
|
+
const {
|
|
241
|
+
loanToken, collateralToken, oracle, irm, lltv,
|
|
242
|
+
} = selectedMarket;
|
|
243
|
+
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
244
|
+
|
|
245
|
+
const viewContract = MorphoBlueViewContractViem(provider, network);
|
|
246
|
+
const loanInfo = (await viewContract.read.getUserInfo([
|
|
247
|
+
{
|
|
248
|
+
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
249
|
+
},
|
|
250
|
+
account]));
|
|
251
|
+
|
|
252
|
+
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
253
|
+
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
254
|
+
const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
|
|
255
|
+
const usedAssets: MMUsedAssets = {
|
|
256
|
+
[marketInfo.loanToken]: {
|
|
257
|
+
symbol: loanTokenInfo.symbol,
|
|
258
|
+
supplied: loanTokenSupplied,
|
|
259
|
+
borrowed: '0',
|
|
260
|
+
isSupplied: new Dec(loanInfo.suppliedInAssets.toString()).gt(0),
|
|
261
|
+
isBorrowed: false,
|
|
262
|
+
collateral: false,
|
|
263
|
+
suppliedUsd: loanTokenSuppliedUsd,
|
|
264
|
+
borrowedUsd: '0',
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const { netApy } = calculateNetApy({ usedAssets, assetsData: marketInfo.assetsData as unknown as MMAssetsData });
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
apy: netApy,
|
|
272
|
+
amount: loanTokenSupplied,
|
|
273
|
+
amountUsd: loanTokenSuppliedUsd,
|
|
274
|
+
};
|
|
237
275
|
}
|