@defisaver/positions-sdk 2.0.14-dev-portfolio → 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.
- package/cjs/config/contracts.d.ts +14 -0
- package/cjs/config/contracts.js +1 -1
- package/cjs/contracts.d.ts +145 -0
- package/cjs/liquityV2/index.d.ts +27 -0
- package/cjs/liquityV2/index.js +136 -162
- package/cjs/portfolio/index.js +39 -0
- package/esm/config/contracts.d.ts +14 -0
- package/esm/config/contracts.js +1 -1
- package/esm/contracts.d.ts +145 -0
- package/esm/liquityV2/index.d.ts +27 -0
- package/esm/liquityV2/index.js +137 -165
- package/esm/portfolio/index.js +40 -1
- package/package.json +1 -1
- package/src/config/contracts.ts +1 -1
- package/src/liquityV2/index.ts +226 -164
- package/src/portfolio/index.ts +39 -0
package/src/liquityV2/index.ts
CHANGED
|
@@ -4,9 +4,12 @@ import { Client, PublicClient } from 'viem';
|
|
|
4
4
|
import {
|
|
5
5
|
createViemContractFromConfigFunc,
|
|
6
6
|
LiquityV2LegacyViewContractViem,
|
|
7
|
+
LiquityV2sBoldVaultViem,
|
|
7
8
|
LiquityV2ViewContractViem,
|
|
8
9
|
} from '../contracts';
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
EthAddress, EthereumProvider, HexString, NetworkNumber,
|
|
12
|
+
} from '../types/common';
|
|
10
13
|
import {
|
|
11
14
|
LIQUITY_V2_TROVE_STATUS_ENUM,
|
|
12
15
|
LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2UsedAssets,
|
|
@@ -15,9 +18,12 @@ import {
|
|
|
15
18
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
19
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
17
20
|
import {
|
|
18
|
-
compareAddresses,
|
|
21
|
+
compareAddresses,
|
|
22
|
+
ethToWeth,
|
|
23
|
+
getEthAmountForDecimals,
|
|
24
|
+
MAXUINT,
|
|
19
25
|
} from '../services/utils';
|
|
20
|
-
import { ZERO_ADDRESS } from '../constants';
|
|
26
|
+
import { SECONDS_PER_YEAR, ZERO_ADDRESS } from '../constants';
|
|
21
27
|
import { LiquityV2Markets } from '../markets';
|
|
22
28
|
import { getViemProvider } from '../services/viem';
|
|
23
29
|
|
|
@@ -420,164 +426,220 @@ export const getLiquityV2ClaimableCollateral = async (collSurplusPoolAddress: Et
|
|
|
420
426
|
return claimableCollateral.toString();
|
|
421
427
|
};
|
|
422
428
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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
|
+
};
|
package/src/portfolio/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
CompoundMarkets,
|
|
6
6
|
CrvUsdMarkets,
|
|
7
7
|
EulerV2Markets,
|
|
8
|
+
LiquityV2Markets,
|
|
8
9
|
LlamaLendMarkets,
|
|
9
10
|
MorphoBlueMarkets,
|
|
10
11
|
SparkMarkets,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
CompoundVersions,
|
|
21
22
|
CrvUSDGlobalMarketData,
|
|
22
23
|
EulerV2FullMarketData,
|
|
24
|
+
LiquityV2MarketData,
|
|
23
25
|
LlamaLendGlobalMarketData,
|
|
24
26
|
MorphoBlueMarketInfo,
|
|
25
27
|
PortfolioPositionsData,
|
|
@@ -37,6 +39,7 @@ import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
|
37
39
|
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
38
40
|
import { getViemProvider } from '../services/viem';
|
|
39
41
|
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
42
|
+
import { getLiquityV2Staking, _getLiquityV2MarketData, getLiquitySAndYBold } from '../liquityV2';
|
|
40
43
|
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
41
44
|
import { getEulerV2SubAccounts } from '../helpers/eulerHelpers';
|
|
42
45
|
import { getUmbrellaData } from '../umbrella';
|
|
@@ -64,6 +67,8 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
64
67
|
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
65
68
|
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
66
69
|
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
70
|
+
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
71
|
+
const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
|
|
67
72
|
|
|
68
73
|
const client = getViemProvider(provider, network, {
|
|
69
74
|
batch: {
|
|
@@ -90,6 +95,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
90
95
|
const compoundV2MarketsData: Record<string, CompoundV2MarketsData> = {};
|
|
91
96
|
const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
|
|
92
97
|
const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
|
|
98
|
+
const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
|
|
93
99
|
|
|
94
100
|
const markets = {
|
|
95
101
|
morphoMarketsData,
|
|
@@ -101,6 +107,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
101
107
|
compoundV2MarketsData,
|
|
102
108
|
crvUsdMarketsData,
|
|
103
109
|
llamaLendMarketsData,
|
|
110
|
+
liquityV2MarketsData,
|
|
104
111
|
};
|
|
105
112
|
|
|
106
113
|
const positions: PortfolioPositionsData = {};
|
|
@@ -138,6 +145,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
138
145
|
aaveV2: {},
|
|
139
146
|
compoundV2: {},
|
|
140
147
|
liquity: {},
|
|
148
|
+
liquityV2: {},
|
|
141
149
|
fluid: {
|
|
142
150
|
error: '',
|
|
143
151
|
data: {},
|
|
@@ -193,6 +201,10 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
193
201
|
const marketData = await _getLlamaLendGlobalData(client, network, market);
|
|
194
202
|
llamaLendMarketsData[market.value] = marketData;
|
|
195
203
|
}),
|
|
204
|
+
...liquityV2Markets.map(async (market) => {
|
|
205
|
+
const marketData = await _getLiquityV2MarketData(client, network, market);
|
|
206
|
+
liquityV2MarketsData[market.value] = marketData;
|
|
207
|
+
}),
|
|
196
208
|
|
|
197
209
|
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
198
210
|
...addresses.map(async (address) => {
|
|
@@ -258,6 +270,20 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
258
270
|
stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
|
|
259
271
|
}
|
|
260
272
|
}),
|
|
273
|
+
// Liquity V2 staking
|
|
274
|
+
...liquityV2MarketsStaking.map(market => addresses.map(async (address) => {
|
|
275
|
+
try {
|
|
276
|
+
if (!isMainnet) {
|
|
277
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const liquityV2StakingData = await getLiquityV2Staking(client, network, market.value, address);
|
|
281
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
|
|
284
|
+
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
|
|
285
|
+
}
|
|
286
|
+
})).flat(),
|
|
261
287
|
|
|
262
288
|
// === REWARDS DATA (independent of market data) ===
|
|
263
289
|
// Batch King rewards
|
|
@@ -522,6 +548,19 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
522
548
|
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
523
549
|
}
|
|
524
550
|
})).flat(),
|
|
551
|
+
// liquity sBold/yBold and staking options
|
|
552
|
+
...addresses.map(async (address) => {
|
|
553
|
+
try {
|
|
554
|
+
if (!isMainnet) {
|
|
555
|
+
stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data: null };
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const data = await getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
|
|
559
|
+
stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data };
|
|
560
|
+
} catch (error) {
|
|
561
|
+
console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
|
|
562
|
+
}
|
|
563
|
+
}),
|
|
525
564
|
]);
|
|
526
565
|
|
|
527
566
|
return {
|