@defisaver/positions-sdk 2.1.153 → 2.1.154-shifter-v2-dev
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 +2 -0
- package/cjs/fluid/index.d.ts +5 -0
- package/cjs/fluid/index.js +36 -1
- package/cjs/helpers/aaveHelpers/index.js +3 -0
- package/cjs/helpers/aaveV4Helpers/index.js +1 -0
- package/cjs/helpers/compoundHelpers/index.js +2 -0
- package/cjs/helpers/curveUsdHelpers/index.js +2 -0
- package/cjs/helpers/fluidHelpers/index.js +1 -0
- package/cjs/helpers/liquityV2Helpers/index.js +1 -0
- package/cjs/helpers/llamaLendHelpers/index.js +2 -0
- package/cjs/helpers/makerHelpers/index.d.ts +1 -1
- package/cjs/helpers/makerHelpers/index.js +2 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +2 -0
- package/cjs/helpers/morphoMidnightHelpers/index.js +2 -0
- package/cjs/helpers/sparkHelpers/index.js +1 -0
- package/cjs/liquity/index.js +8 -1
- package/cjs/maker/index.d.ts +7 -2
- package/cjs/maker/index.js +32 -12
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/maker/index.d.ts +1 -0
- package/cjs/markets/maker/index.js +13 -0
- package/cjs/markets/spark/marketAssets.js +1 -1
- package/cjs/portfolio/index.d.ts +5 -1
- package/cjs/portfolio/index.js +287 -0
- package/cjs/types/aave.d.ts +2 -0
- package/cjs/types/aaveV4.d.ts +1 -0
- package/cjs/types/compound.d.ts +2 -0
- package/cjs/types/fluid.d.ts +1 -0
- package/cjs/types/liquity.d.ts +1 -0
- package/cjs/types/liquityV2.d.ts +2 -0
- package/cjs/types/maker.d.ts +1 -0
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/morphoMidnight.d.ts +1 -0
- package/cjs/types/portfolio.d.ts +26 -10
- package/cjs/types/spark.d.ts +2 -0
- package/esm/aaveV2/index.js +2 -0
- package/esm/fluid/index.d.ts +5 -0
- package/esm/fluid/index.js +33 -0
- package/esm/helpers/aaveHelpers/index.js +3 -0
- package/esm/helpers/aaveV4Helpers/index.js +1 -0
- package/esm/helpers/compoundHelpers/index.js +2 -0
- package/esm/helpers/curveUsdHelpers/index.js +2 -0
- package/esm/helpers/fluidHelpers/index.js +1 -0
- package/esm/helpers/liquityV2Helpers/index.js +1 -0
- package/esm/helpers/llamaLendHelpers/index.js +2 -0
- package/esm/helpers/makerHelpers/index.d.ts +1 -1
- package/esm/helpers/makerHelpers/index.js +2 -2
- package/esm/helpers/morphoBlueHelpers/index.js +2 -0
- package/esm/helpers/morphoMidnightHelpers/index.js +2 -0
- package/esm/helpers/sparkHelpers/index.js +1 -0
- package/esm/liquity/index.js +8 -1
- package/esm/maker/index.d.ts +7 -2
- package/esm/maker/index.js +31 -13
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/maker/index.d.ts +1 -0
- package/esm/markets/maker/index.js +10 -0
- package/esm/markets/spark/marketAssets.js +1 -1
- package/esm/portfolio/index.d.ts +5 -1
- package/esm/portfolio/index.js +289 -3
- package/esm/types/aave.d.ts +2 -0
- package/esm/types/aaveV4.d.ts +1 -0
- package/esm/types/compound.d.ts +2 -0
- package/esm/types/fluid.d.ts +1 -0
- package/esm/types/liquity.d.ts +1 -0
- package/esm/types/liquityV2.d.ts +2 -0
- package/esm/types/maker.d.ts +1 -0
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/morphoMidnight.d.ts +1 -0
- package/esm/types/portfolio.d.ts +26 -10
- package/esm/types/spark.d.ts +2 -0
- package/package.json +1 -1
- package/src/aaveV2/index.ts +2 -0
- package/src/fluid/index.ts +40 -0
- package/src/helpers/aaveHelpers/index.ts +3 -0
- package/src/helpers/aaveV4Helpers/index.ts +1 -0
- package/src/helpers/compoundHelpers/index.ts +2 -0
- package/src/helpers/curveUsdHelpers/index.ts +2 -0
- package/src/helpers/fluidHelpers/index.ts +1 -0
- package/src/helpers/liquityV2Helpers/index.ts +1 -0
- package/src/helpers/llamaLendHelpers/index.ts +2 -0
- package/src/helpers/makerHelpers/index.ts +2 -1
- package/src/helpers/morphoBlueHelpers/index.ts +2 -0
- package/src/helpers/morphoMidnightHelpers/index.ts +2 -0
- package/src/helpers/sparkHelpers/index.ts +1 -0
- package/src/liquity/index.ts +8 -1
- package/src/maker/index.ts +62 -29
- package/src/markets/index.ts +2 -1
- package/src/markets/maker/index.ts +10 -0
- package/src/markets/spark/marketAssets.ts +1 -1
- package/src/portfolio/index.ts +270 -2
- package/src/types/aave.ts +3 -0
- package/src/types/aaveV4.ts +1 -0
- package/src/types/compound.ts +2 -0
- package/src/types/fluid.ts +1 -0
- package/src/types/liquity.ts +2 -0
- package/src/types/liquityV2.ts +2 -0
- package/src/types/maker.ts +2 -0
- package/src/types/morphoBlue.ts +2 -0
- package/src/types/morphoMidnight.ts +1 -0
- package/src/types/portfolio.ts +31 -12
- package/src/types/spark.ts +2 -0
package/src/portfolio/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CrvUsdMarkets,
|
|
8
8
|
LiquityV2Markets,
|
|
9
9
|
LlamaLendMarkets,
|
|
10
|
+
MakerActiveIlks,
|
|
10
11
|
MorphoBlueMarkets,
|
|
11
12
|
MorphoMidnightMarkets,
|
|
12
13
|
SparkMarkets,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
LlamaLendGlobalMarketData,
|
|
28
29
|
MorphoBlueMarketInfo,
|
|
29
30
|
MorphoMidnightMarketInfo,
|
|
31
|
+
PortfolioMarketsData,
|
|
30
32
|
PortfolioPositionsData,
|
|
31
33
|
SparkMarketsData,
|
|
32
34
|
} from '../types';
|
|
@@ -36,13 +38,13 @@ import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
|
36
38
|
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
37
39
|
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
38
40
|
import { ZERO_ADDRESS } from '../constants';
|
|
39
|
-
import { _getMakerCdpData, _getUserCdps } from '../maker';
|
|
41
|
+
import { _getMakerCdpData, _getMakerIlksData, _getUserCdps } from '../maker';
|
|
40
42
|
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
41
43
|
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
42
44
|
import { getViemProvider } from '../services/viem';
|
|
43
45
|
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
44
46
|
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
45
|
-
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
47
|
+
import { _getAllFluidMarketDataPortfolio, _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
46
48
|
import { getUmbrellaData } from '../umbrella';
|
|
47
49
|
import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
48
50
|
import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
@@ -584,4 +586,270 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
584
586
|
};
|
|
585
587
|
}
|
|
586
588
|
|
|
589
|
+
|
|
590
|
+
export async function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
|
|
591
|
+
positions: PortfolioPositionsData;
|
|
592
|
+
markets: PortfolioMarketsData;
|
|
593
|
+
}> {
|
|
594
|
+
const isMainnet = network === NetworkNumber.Eth;
|
|
595
|
+
const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
|
|
596
|
+
|
|
597
|
+
const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
598
|
+
const morphoMidnightMarkets = Object.values(MorphoMidnightMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
599
|
+
const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
|
|
600
|
+
const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
601
|
+
const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
602
|
+
const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
603
|
+
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
604
|
+
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
605
|
+
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
606
|
+
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
607
|
+
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
608
|
+
|
|
609
|
+
const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 2_000 : 2_500_000 } } }];
|
|
610
|
+
const client = getViemProvider(provider, ...args);
|
|
611
|
+
const defaultClient = getViemProvider(defaultProvider, ...args);
|
|
612
|
+
|
|
613
|
+
const markets: PortfolioMarketsData = {
|
|
614
|
+
morphoMarketsData: {},
|
|
615
|
+
morphoMidnightMarketsData: {},
|
|
616
|
+
compoundV3MarketsData: {},
|
|
617
|
+
sparkMarketsData: {},
|
|
618
|
+
aaveV3MarketsData: {},
|
|
619
|
+
aaveV2MarketsData: {},
|
|
620
|
+
compoundV2MarketsData: {},
|
|
621
|
+
crvUsdMarketsData: {},
|
|
622
|
+
llamaLendMarketsData: {},
|
|
623
|
+
liquityV2MarketsData: {},
|
|
624
|
+
aaveV4SpokesData: {},
|
|
625
|
+
fluidMarketsData: {},
|
|
626
|
+
makerMarketsData: {},
|
|
627
|
+
};
|
|
628
|
+
const makerCdps: Record<string, CdpInfo[]> = {};
|
|
629
|
+
|
|
630
|
+
const positions: PortfolioPositionsData = {};
|
|
631
|
+
|
|
632
|
+
for (const address of addresses) {
|
|
633
|
+
positions[address.toLowerCase() as EthAddress] = {
|
|
634
|
+
aaveV3: {},
|
|
635
|
+
aaveV4: {},
|
|
636
|
+
morphoBlue: {},
|
|
637
|
+
morphoMidnight: {},
|
|
638
|
+
compoundV3: {},
|
|
639
|
+
spark: {},
|
|
640
|
+
maker: {},
|
|
641
|
+
aaveV2: {},
|
|
642
|
+
compoundV2: {},
|
|
643
|
+
liquity: {},
|
|
644
|
+
crvUsd: {},
|
|
645
|
+
llamaLend: {},
|
|
646
|
+
fluid: {
|
|
647
|
+
error: '',
|
|
648
|
+
data: {},
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
await Promise.allSettled([
|
|
654
|
+
// === MARKET DATA (needs to be fetched first) ===
|
|
655
|
+
...morphoMarkets.map(async (market) => {
|
|
656
|
+
markets.morphoMarketsData[market.value] = await _getMorphoBluePortfolioMarketData(client, network, market);
|
|
657
|
+
}),
|
|
658
|
+
...morphoMidnightMarkets.map(async (market) => {
|
|
659
|
+
markets.morphoMidnightMarketsData[market.value] = await _getMorphoMidnightMarketData(client, network, market);
|
|
660
|
+
}),
|
|
661
|
+
...compoundV3Markets.map(async (market) => {
|
|
662
|
+
markets.compoundV3MarketsData[market.value] = await _getCompoundV3MarketsData(client, network, market, defaultClient);
|
|
663
|
+
}),
|
|
664
|
+
...sparkMarkets.map(async (market) => {
|
|
665
|
+
markets.sparkMarketsData[market.value] = await _getSparkMarketsData(client, network, market);
|
|
666
|
+
}),
|
|
667
|
+
...aaveV3Markets.map(async (market) => {
|
|
668
|
+
markets.aaveV3MarketsData[market.value] = await _getAaveV3MarketData(client, network, market);
|
|
669
|
+
}),
|
|
670
|
+
...aaveV4Spokes.map(async (spoke) => {
|
|
671
|
+
markets.aaveV4SpokesData[spoke.value] = await _getAaveV4SpokeData(client, network, spoke);
|
|
672
|
+
}),
|
|
673
|
+
...aaveV2Markets.map(async (market) => {
|
|
674
|
+
markets.aaveV2MarketsData[market.value] = await _getAaveV2MarketsData(client, network, market);
|
|
675
|
+
}),
|
|
676
|
+
...compoundV2Markets.map(async (market) => {
|
|
677
|
+
markets.compoundV2MarketsData[market.value] = await _getCompoundV2MarketsData(client, network);
|
|
678
|
+
}),
|
|
679
|
+
...crvUsdMarkets.map(async (market) => {
|
|
680
|
+
markets.crvUsdMarketsData[market.value] = await _getCurveUsdGlobalData(client, network, market);
|
|
681
|
+
}),
|
|
682
|
+
...llamaLendMarkets.map(async (market) => {
|
|
683
|
+
markets.llamaLendMarketsData[market.value] = await _getLlamaLendGlobalData(client, network, market);
|
|
684
|
+
}),
|
|
685
|
+
...liquityV2Markets.map(async (market) => {
|
|
686
|
+
markets.liquityV2MarketsData[market.value] = await _getLiquityV2MarketData(client, network, market);
|
|
687
|
+
}),
|
|
688
|
+
(async () => {
|
|
689
|
+
if (!isFluidSupported) return;
|
|
690
|
+
try {
|
|
691
|
+
markets.fluidMarketsData = await _getAllFluidMarketDataPortfolio(client, network);
|
|
692
|
+
} catch (error) {
|
|
693
|
+
console.error('Error fetching Fluid markets data:', error);
|
|
694
|
+
}
|
|
695
|
+
})(),
|
|
696
|
+
(async () => {
|
|
697
|
+
if (!isMainnet) return; // Maker CDPs are only available on mainnet
|
|
698
|
+
try {
|
|
699
|
+
markets.makerMarketsData = await _getMakerIlksData(client, network, MakerActiveIlks);
|
|
700
|
+
} catch (error) {
|
|
701
|
+
console.error('Error fetching Maker ilks data:', error);
|
|
702
|
+
}
|
|
703
|
+
})(),
|
|
704
|
+
|
|
705
|
+
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
706
|
+
...addresses.map(async (address) => {
|
|
707
|
+
if (!isMainnet) return; // Maker CDPs are only available on mainnet
|
|
708
|
+
const makerCdp = await _getUserCdps(client, network, address);
|
|
709
|
+
makerCdps[address.toLowerCase() as EthAddress] = makerCdp;
|
|
710
|
+
}),
|
|
711
|
+
...addresses.map(async (address) => {
|
|
712
|
+
try {
|
|
713
|
+
if (!isFluidSupported) return; // Fluid is not available on Optimism
|
|
714
|
+
const userPositions = (await _getUserPositionsPortfolio(client, network, address));
|
|
715
|
+
for (const position of userPositions) {
|
|
716
|
+
if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
|
|
717
|
+
positions[address.toLowerCase() as EthAddress].fluid.data[position.userData.nftId] = position.userData;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
} catch (error) {
|
|
721
|
+
console.error(`Error fetching Fluid positions for address ${address}:`, error);
|
|
722
|
+
positions[address.toLowerCase() as EthAddress].fluid = {
|
|
723
|
+
error: `Error fetching Fluid positions for address ${address}`,
|
|
724
|
+
data: {},
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
}),
|
|
728
|
+
]);
|
|
729
|
+
|
|
730
|
+
await Promise.all([
|
|
731
|
+
...aaveV3Markets.map((market) => addresses.map(async (address) => {
|
|
732
|
+
try {
|
|
733
|
+
const accData = await _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...markets.aaveV3MarketsData[market.value] });
|
|
734
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: accData };
|
|
735
|
+
} catch (error) {
|
|
736
|
+
console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
|
|
737
|
+
positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
738
|
+
}
|
|
739
|
+
})).flat(),
|
|
740
|
+
...aaveV4Spokes.map((spoke) => addresses.map(async (address) => {
|
|
741
|
+
try {
|
|
742
|
+
const accData = await _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address);
|
|
743
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
|
|
744
|
+
} catch (error) {
|
|
745
|
+
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
746
|
+
positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
747
|
+
}
|
|
748
|
+
})).flat(),
|
|
749
|
+
...morphoMarkets.map((market) => addresses.map(async (address) => {
|
|
750
|
+
try {
|
|
751
|
+
const accData = await _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value]);
|
|
752
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: '', data: accData };
|
|
753
|
+
} catch (error) {
|
|
754
|
+
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
|
|
755
|
+
positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
756
|
+
}
|
|
757
|
+
})).flat(),
|
|
758
|
+
...morphoMidnightMarkets.map((market) => addresses.map(async (address) => {
|
|
759
|
+
try {
|
|
760
|
+
const accData = await _getMorphoMidnightAccountData(client, network, address, market, markets.morphoMidnightMarketsData[market.value]);
|
|
761
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: '', data: accData };
|
|
762
|
+
} catch (error) {
|
|
763
|
+
console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
|
|
764
|
+
positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
|
|
765
|
+
}
|
|
766
|
+
})).flat(),
|
|
767
|
+
...compoundV3Markets.map((market) => addresses.map(async (address) => {
|
|
768
|
+
try {
|
|
769
|
+
const accData = await _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData });
|
|
770
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: '', data: accData };
|
|
771
|
+
} catch (error) {
|
|
772
|
+
console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
|
|
773
|
+
positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
774
|
+
}
|
|
775
|
+
})).flat(),
|
|
776
|
+
...sparkMarkets.map((market) => addresses.map(async (address) => {
|
|
777
|
+
try {
|
|
778
|
+
const accData = await _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData });
|
|
779
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: accData };
|
|
780
|
+
} catch (error) {
|
|
781
|
+
console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
|
|
782
|
+
positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
783
|
+
}
|
|
784
|
+
})).flat(),
|
|
785
|
+
...addresses.map(async (address) => makerCdps[address.toLowerCase() as EthAddress]?.map(async (cdpInfo) => {
|
|
786
|
+
try {
|
|
787
|
+
// reuse ilk data fetched for the markets payload; ilks outside the active set are fetched on demand
|
|
788
|
+
const cdpData = await _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]);
|
|
789
|
+
if (cdpData) {
|
|
790
|
+
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
791
|
+
}
|
|
792
|
+
} catch (error) {
|
|
793
|
+
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
794
|
+
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
795
|
+
}
|
|
796
|
+
})).flat(),
|
|
797
|
+
...aaveV2Markets.map((market) => addresses.map(async (address) => {
|
|
798
|
+
try {
|
|
799
|
+
const accData = await _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market);
|
|
800
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: '', data: accData };
|
|
801
|
+
} catch (error) {
|
|
802
|
+
console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
|
|
803
|
+
positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
|
|
804
|
+
}
|
|
805
|
+
})).flat(),
|
|
806
|
+
...compoundV2Markets.map((market) => addresses.map(async (address) => {
|
|
807
|
+
try {
|
|
808
|
+
const accData = await _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData);
|
|
809
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: '', data: accData };
|
|
810
|
+
} catch (error) {
|
|
811
|
+
console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
|
|
812
|
+
positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
|
|
813
|
+
}
|
|
814
|
+
})).flat(),
|
|
815
|
+
...addresses.map(async (address) => {
|
|
816
|
+
try {
|
|
817
|
+
if (!isMainnet) return; // Liquity trove info is only available on mainnet
|
|
818
|
+
const troveInfo = await _getLiquityTroveInfo(client, network, address);
|
|
819
|
+
if (new Dec(troveInfo.collateral).gt(0)) positions[address.toLowerCase() as EthAddress].liquity = { error: '', data: troveInfo };
|
|
820
|
+
} catch (error) {
|
|
821
|
+
console.error(`Error fetching Liquity trove info for address ${address}:`, error);
|
|
822
|
+
positions[address.toLowerCase() as EthAddress].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
|
|
823
|
+
}
|
|
824
|
+
}),
|
|
825
|
+
...crvUsdMarkets.map((market) => addresses.map(async (address) => {
|
|
826
|
+
try {
|
|
827
|
+
const accData = await _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand);
|
|
828
|
+
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
829
|
+
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: '', data: { ...accData, borrowRate: markets.crvUsdMarketsData[market.value].borrowRate } };
|
|
830
|
+
}
|
|
831
|
+
} catch (error) {
|
|
832
|
+
console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
|
|
833
|
+
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
|
|
834
|
+
}
|
|
835
|
+
})).flat(),
|
|
836
|
+
...llamaLendMarkets.map((market) => addresses.map(async (address) => {
|
|
837
|
+
try {
|
|
838
|
+
const accData = await _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value]);
|
|
839
|
+
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
840
|
+
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: '', data: { ...accData, borrowRate: markets.llamaLendMarketsData[market.value].borrowRate } };
|
|
841
|
+
}
|
|
842
|
+
} catch (error) {
|
|
843
|
+
console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
|
|
844
|
+
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
845
|
+
}
|
|
846
|
+
})).flat(),
|
|
847
|
+
]);
|
|
848
|
+
|
|
849
|
+
return {
|
|
850
|
+
positions,
|
|
851
|
+
markets,
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
|
|
587
855
|
export * from './discovery';
|
package/src/types/aave.ts
CHANGED
|
@@ -143,6 +143,8 @@ export interface AavePositionData extends MMPositionData {
|
|
|
143
143
|
collRatio: string,
|
|
144
144
|
// Safety ratio as evaluated by automation bots (LTV-0 collateral credited at LLTV - 5%). Aave v3 only.
|
|
145
145
|
safetyRatioWithLtvZeroFallback?: string,
|
|
146
|
+
// Normalised safety ratio (100 = liquidation on every protocol). Aave v3: the LTV-0 fallback ratio, Aave v2: `ratio`.
|
|
147
|
+
safetyRatio?: string,
|
|
146
148
|
suppliedUsd: string,
|
|
147
149
|
borrowedUsd: string,
|
|
148
150
|
borrowLimitUsd: string,
|
|
@@ -177,6 +179,7 @@ export interface AaveV3AggregatedPositionData {
|
|
|
177
179
|
collRatio: string,
|
|
178
180
|
borrowLimitWithLtvZeroFallbackUsd: string,
|
|
179
181
|
safetyRatioWithLtvZeroFallback: string,
|
|
182
|
+
safetyRatio: string,
|
|
180
183
|
netApy: string,
|
|
181
184
|
incentiveUsd: string,
|
|
182
185
|
totalInterestUsd: string,
|
package/src/types/aaveV4.ts
CHANGED
package/src/types/compound.ts
CHANGED
|
@@ -112,6 +112,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
112
112
|
leftToBorrowUsd: string,
|
|
113
113
|
ratio: string,
|
|
114
114
|
collRatio: string,
|
|
115
|
+
safetyRatio: string,
|
|
115
116
|
netApy: string,
|
|
116
117
|
incentiveUsd: string,
|
|
117
118
|
totalInterestUsd: string,
|
|
@@ -132,6 +133,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
132
133
|
export interface CompoundPositionData extends MMPositionData {
|
|
133
134
|
ratio: string,
|
|
134
135
|
minRatio: string,
|
|
136
|
+
safetyRatio?: string,
|
|
135
137
|
suppliedUsd: string,
|
|
136
138
|
borrowedUsd: string,
|
|
137
139
|
borrowLimitUsd: string,
|
package/src/types/fluid.ts
CHANGED
package/src/types/liquity.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface LiquityTroveInfo {
|
|
|
26
26
|
totalETH: string,
|
|
27
27
|
totalLUSD: string,
|
|
28
28
|
minCollateralRatio: number,
|
|
29
|
+
// Collateral ratio rebased so 100 sits on `minCollateralRatio` (normalised safety ratio).
|
|
30
|
+
safetyRatio: string,
|
|
29
31
|
priceForRecovery: string,
|
|
30
32
|
debtInFront: string,
|
|
31
33
|
exposure: string,
|
package/src/types/liquityV2.ts
CHANGED
|
@@ -104,6 +104,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
104
104
|
liquidationPrice: string,
|
|
105
105
|
ratio: string,
|
|
106
106
|
collRatio: string,
|
|
107
|
+
safetyRatio: string,
|
|
107
108
|
exposure: string,
|
|
108
109
|
}
|
|
109
110
|
|
|
@@ -112,6 +113,7 @@ export interface LiquityV2TroveData {
|
|
|
112
113
|
troveId: string,
|
|
113
114
|
ratio: string,
|
|
114
115
|
collRatio: string,
|
|
116
|
+
safetyRatio?: string,
|
|
115
117
|
liqRatio: string,
|
|
116
118
|
borrowLimitRatio: string,
|
|
117
119
|
interestRate: string,
|
package/src/types/maker.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface CdpData {
|
|
|
47
47
|
debtAssetMarketPrice: string,
|
|
48
48
|
liquidationPrice: string,
|
|
49
49
|
ratio: string,
|
|
50
|
+
// Collateral ratio rebased so 100 sits on `liqPercent` (normalised safety ratio).
|
|
51
|
+
safetyRatio: string,
|
|
50
52
|
liqRatio: string,
|
|
51
53
|
liqPercent: number,
|
|
52
54
|
assetPrice: string,
|
package/src/types/morphoBlue.ts
CHANGED
|
@@ -206,6 +206,7 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
206
206
|
totalInterestUsd: string,
|
|
207
207
|
ltv: string,
|
|
208
208
|
ratio: string,
|
|
209
|
+
safetyRatio: string, // borrowLimitUsd / borrowedUsd as a percentage (100 = liquidation)
|
|
209
210
|
leveragedType: LeverageType,
|
|
210
211
|
leveragedAsset?: string,
|
|
211
212
|
currentVolatilePairRatio?: string,
|
|
@@ -229,6 +230,7 @@ export interface MorphoBluePositionData {
|
|
|
229
230
|
totalInterestUsd: string,
|
|
230
231
|
ltv: string,
|
|
231
232
|
ratio: string,
|
|
233
|
+
safetyRatio?: string,
|
|
232
234
|
leveragedType: LeverageType,
|
|
233
235
|
leveragedAsset?: string,
|
|
234
236
|
currentVolatilePairRatio?: string,
|
|
@@ -190,6 +190,7 @@ export interface MorphoMidnightAggregatedPositionData {
|
|
|
190
190
|
ltv: string,
|
|
191
191
|
ratio: string, // health ratio as a percentage (from MidnightView.ratio, 1e18-scaled)
|
|
192
192
|
healthRatio: string, // liquidationLimitUsd / borrowedUsd
|
|
193
|
+
safetyRatio: string, // borrowLimitUsd / borrowedUsd as a percentage (100 = liquidation)
|
|
193
194
|
leveragedType: LeverageType,
|
|
194
195
|
leveragedAsset?: string,
|
|
195
196
|
currentVolatilePairRatio?: string,
|
package/src/types/portfolio.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions,
|
|
3
|
+
} from './aave';
|
|
4
|
+
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
|
|
3
5
|
import { EthAddress } from './common';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import {
|
|
7
|
+
CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions,
|
|
8
|
+
} from './compound';
|
|
9
|
+
import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
10
|
+
import { FluidMarketData, FluidVaultData } from './fluid';
|
|
7
11
|
import { LiquityTroveInfo } from './liquity';
|
|
8
|
-
import { LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
|
|
9
|
-
import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
10
|
-
import { CdpData } from './maker';
|
|
11
|
-
import { MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
12
|
-
import { MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
13
|
-
import { SparkPositionData, SparkVersions } from './spark';
|
|
12
|
+
import { LiquityV2MarketData, LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
|
|
13
|
+
import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
14
|
+
import { CdpData, IlkInfo } from './maker';
|
|
15
|
+
import { MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
16
|
+
import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
17
|
+
import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
|
|
14
18
|
|
|
15
19
|
export interface PortfolioProtocolData<T> {
|
|
16
20
|
error: string,
|
|
@@ -62,4 +66,19 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
62
66
|
|
|
63
67
|
export interface PortfolioPositionsData {
|
|
64
68
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
|
65
|
-
}
|
|
69
|
+
}
|
|
70
|
+
export interface PortfolioMarketsData {
|
|
71
|
+
morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
|
|
72
|
+
morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
|
|
73
|
+
compoundV3MarketsData: Record<string, CompoundV3MarketsData>;
|
|
74
|
+
sparkMarketsData: Record<string, SparkMarketsData>;
|
|
75
|
+
aaveV3MarketsData: Record<string, AaveV3MarketData>;
|
|
76
|
+
aaveV2MarketsData: Record<string, AaveV2MarketData>;
|
|
77
|
+
compoundV2MarketsData: Record<string, CompoundV2MarketsData>;
|
|
78
|
+
crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData>;
|
|
79
|
+
llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
|
|
80
|
+
liquityV2MarketsData: Record<string, LiquityV2MarketData>;
|
|
81
|
+
aaveV4SpokesData: Record<string, AaveV4SpokeData>;
|
|
82
|
+
fluidMarketsData: Record<string, FluidMarketData>;
|
|
83
|
+
makerMarketsData: Record<string, IlkInfo>;
|
|
84
|
+
}
|
package/src/types/spark.ts
CHANGED
|
@@ -99,6 +99,7 @@ export interface SparkAggregatedPositionData {
|
|
|
99
99
|
leftToBorrowUsd: string,
|
|
100
100
|
ratio: string,
|
|
101
101
|
collRatio: string,
|
|
102
|
+
safetyRatio: string,
|
|
102
103
|
netApy: string,
|
|
103
104
|
incentiveUsd: string,
|
|
104
105
|
totalInterestUsd: string,
|
|
@@ -119,6 +120,7 @@ export interface SparkPositionData extends MMPositionData {
|
|
|
119
120
|
ratio: string,
|
|
120
121
|
minRatio: string,
|
|
121
122
|
collRatio: string,
|
|
123
|
+
safetyRatio?: string,
|
|
122
124
|
suppliedUsd: string,
|
|
123
125
|
borrowedUsd: string,
|
|
124
126
|
borrowLimitUsd: string,
|