@defisaver/positions-sdk 2.1.152-shifter-v2-dev-dev → 2.1.153-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/fluid/index.d.ts +0 -2
- package/cjs/fluid/index.js +1 -36
- package/cjs/maker/index.d.ts +2 -7
- package/cjs/maker/index.js +10 -27
- package/cjs/markets/index.d.ts +0 -1
- package/cjs/markets/index.js +1 -3
- package/cjs/portfolio/index.d.ts +1 -5
- package/cjs/portfolio/index.js +0 -287
- package/cjs/types/portfolio.d.ts +10 -26
- package/esm/fluid/index.d.ts +0 -2
- package/esm/fluid/index.js +0 -33
- package/esm/maker/index.d.ts +2 -7
- package/esm/maker/index.js +11 -26
- package/esm/markets/index.d.ts +0 -1
- package/esm/markets/index.js +0 -1
- package/esm/portfolio/index.d.ts +1 -5
- package/esm/portfolio/index.js +3 -289
- package/esm/types/portfolio.d.ts +10 -26
- package/package.json +1 -1
- package/src/fluid/index.ts +0 -40
- package/src/maker/index.ts +28 -56
- package/src/markets/index.ts +1 -2
- package/src/portfolio/index.ts +2 -270
- package/src/types/portfolio.ts +12 -31
- package/cjs/markets/maker/index.d.ts +0 -1
- package/cjs/markets/maker/index.js +0 -13
- package/esm/markets/maker/index.d.ts +0 -1
- package/esm/markets/maker/index.js +0 -10
- package/src/markets/maker/index.ts +0 -10
package/esm/maker/index.js
CHANGED
|
@@ -8,9 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
|
-
import { assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
|
|
11
|
+
import { assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset, } from '@defisaver/tokens';
|
|
12
12
|
import { getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem, } from '../contracts';
|
|
13
|
-
import { CdpType
|
|
13
|
+
import { CdpType } from '../types';
|
|
14
14
|
import { wethToEth } from '../services/utils';
|
|
15
15
|
import { parseCollateralInfo } from '../helpers/makerHelpers';
|
|
16
16
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
@@ -80,37 +80,22 @@ export const _getUserCdps = (provider, network, userAddress) => __awaiter(void 0
|
|
|
80
80
|
return parsedStandardCdps;
|
|
81
81
|
});
|
|
82
82
|
export const getUserCdps = (provider, network, userAddress) => __awaiter(void 0, void 0, void 0, function* () { return _getUserCdps(getViemProvider(provider, network), network, userAddress); });
|
|
83
|
-
export const
|
|
83
|
+
export const _getMakerCdpData = (provider, network, cdp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
84
|
const vatContract = McdVatContractViem(provider, network);
|
|
85
85
|
const spotterContract = McdSpotterContractViem(provider, network);
|
|
86
86
|
const dogContract = McdDogContractViem(provider, network);
|
|
87
87
|
const jugContract = McdJugContractViem(provider, network);
|
|
88
|
-
const par = yield
|
|
89
|
-
const ilksInfo = yield Promise.all(ilkLabels.map((ilkLabel) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
-
const ilk = stringToBytes(ilkLabel);
|
|
91
|
-
const [[_, mat], [artGlobal, rate, spot, line], [duty], futureRate, chop,] = yield Promise.all([
|
|
92
|
-
spotterContract.read.ilks([ilk]),
|
|
93
|
-
vatContract.read.ilks([ilk]),
|
|
94
|
-
jugContract.read.ilks([ilk]),
|
|
95
|
-
jugContract.read.drip([ilk]),
|
|
96
|
-
dogContract.read.chop([ilk]),
|
|
97
|
-
]);
|
|
98
|
-
return parseCollateralInfo(ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), duty.toString(), futureRate.toString(), chop.toString());
|
|
99
|
-
})));
|
|
100
|
-
return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
|
|
101
|
-
});
|
|
102
|
-
export const getMakerIlksData = (provider, network, ilkLabels) => __awaiter(void 0, void 0, void 0, function* () { return _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels); });
|
|
103
|
-
/**
|
|
104
|
-
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
105
|
-
*/
|
|
106
|
-
export const _getMakerCdpData = (provider, network, cdp, ilkInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
-
const vatContract = McdVatContractViem(provider, network);
|
|
108
|
-
const [[ink, art], coll, fetchedIlkInfo,] = yield Promise.all([
|
|
88
|
+
const [[ink, art], coll, par, [_, mat], [artGlobal, rate, spot, line], [duty], futureRate, chop,] = yield Promise.all([
|
|
109
89
|
vatContract.read.urns([cdp.ilk, cdp.urn]),
|
|
110
90
|
vatContract.read.gem([cdp.ilk, cdp.urn]),
|
|
111
|
-
|
|
91
|
+
spotterContract.read.par(),
|
|
92
|
+
spotterContract.read.ilks([cdp.ilk]),
|
|
93
|
+
vatContract.read.ilks([cdp.ilk]),
|
|
94
|
+
jugContract.read.ilks([cdp.ilk]),
|
|
95
|
+
jugContract.read.drip([cdp.ilk]),
|
|
96
|
+
dogContract.read.chop([cdp.ilk]),
|
|
112
97
|
]);
|
|
113
|
-
const collInfo =
|
|
98
|
+
const collInfo = parseCollateralInfo(cdp.ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), duty.toString(), futureRate.toString(), chop.toString());
|
|
114
99
|
const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
|
|
115
100
|
const collateralUsd = new Dec(collateral).mul(collInfo.assetPrice).toString();
|
|
116
101
|
const debt = new Dec(art).times(collInfo.currentRate).div(1e27).floor()
|
package/esm/markets/index.d.ts
CHANGED
|
@@ -8,4 +8,3 @@ export { LlamaLendMarkets } from './llamaLend';
|
|
|
8
8
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
9
9
|
export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
|
|
10
10
|
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
11
|
-
export { MakerActiveIlks } from './maker';
|
package/esm/markets/index.js
CHANGED
|
@@ -8,4 +8,3 @@ export { LlamaLendMarkets } from './llamaLend';
|
|
|
8
8
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
9
9
|
export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
|
|
10
10
|
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
11
|
-
export { MakerActiveIlks } from './maker';
|
package/esm/portfolio/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
-
import {
|
|
2
|
+
import { PortfolioPositionsData } from '../types';
|
|
3
3
|
export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
|
|
4
4
|
positions: PortfolioPositionsData;
|
|
5
5
|
stakingPositions: any;
|
|
6
6
|
rewardsData: any;
|
|
7
7
|
markets: any;
|
|
8
8
|
}>;
|
|
9
|
-
export declare function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
|
|
10
|
-
positions: PortfolioPositionsData;
|
|
11
|
-
markets: PortfolioMarketsData;
|
|
12
|
-
}>;
|
|
13
9
|
export * from './discovery';
|
package/esm/portfolio/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { NetworkNumber } from '../types/common';
|
|
12
|
-
import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LiquityV2Markets, LlamaLendMarkets,
|
|
12
|
+
import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, MorphoMidnightMarkets, SparkMarkets, } from '../markets';
|
|
13
13
|
import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData, getMorphoEarn } from '../morphoBlue';
|
|
14
14
|
import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
|
|
15
15
|
import { AaveVersions, CompoundVersions, } from '../types';
|
|
@@ -19,13 +19,13 @@ import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
|
19
19
|
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
20
20
|
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
21
21
|
import { ZERO_ADDRESS } from '../constants';
|
|
22
|
-
import { _getMakerCdpData,
|
|
22
|
+
import { _getMakerCdpData, _getUserCdps } from '../maker';
|
|
23
23
|
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
24
24
|
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
25
25
|
import { getViemProvider } from '../services/viem';
|
|
26
26
|
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
27
27
|
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
28
|
-
import {
|
|
28
|
+
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
29
29
|
import { getUmbrellaData } from '../umbrella';
|
|
30
30
|
import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
31
31
|
import { getCompoundV3Rewards } from '../claiming/compV3';
|
|
@@ -603,290 +603,4 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
|
|
|
603
603
|
};
|
|
604
604
|
});
|
|
605
605
|
}
|
|
606
|
-
export function getShifterPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
|
|
607
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
|
|
608
|
-
const isMainnet = network === NetworkNumber.Eth;
|
|
609
|
-
const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
|
|
610
|
-
const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
611
|
-
const morphoMidnightMarkets = Object.values(MorphoMidnightMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
612
|
-
const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
|
|
613
|
-
const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
614
|
-
const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
615
|
-
const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
616
|
-
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
617
|
-
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
618
|
-
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
619
|
-
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
620
|
-
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
621
|
-
const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 2500000 } } }];
|
|
622
|
-
const client = getViemProvider(provider, ...args);
|
|
623
|
-
const defaultClient = getViemProvider(defaultProvider, ...args);
|
|
624
|
-
const markets = {
|
|
625
|
-
morphoMarketsData: {},
|
|
626
|
-
morphoMidnightMarketsData: {},
|
|
627
|
-
compoundV3MarketsData: {},
|
|
628
|
-
sparkMarketsData: {},
|
|
629
|
-
aaveV3MarketsData: {},
|
|
630
|
-
aaveV2MarketsData: {},
|
|
631
|
-
compoundV2MarketsData: {},
|
|
632
|
-
crvUsdMarketsData: {},
|
|
633
|
-
llamaLendMarketsData: {},
|
|
634
|
-
liquityV2MarketsData: {},
|
|
635
|
-
aaveV4SpokesData: {},
|
|
636
|
-
fluidMarketsData: {},
|
|
637
|
-
makerMarketsData: {},
|
|
638
|
-
};
|
|
639
|
-
const makerCdps = {};
|
|
640
|
-
const positions = {};
|
|
641
|
-
for (const address of addresses) {
|
|
642
|
-
positions[address.toLowerCase()] = {
|
|
643
|
-
aaveV3: {},
|
|
644
|
-
aaveV4: {},
|
|
645
|
-
morphoBlue: {},
|
|
646
|
-
morphoMidnight: {},
|
|
647
|
-
compoundV3: {},
|
|
648
|
-
spark: {},
|
|
649
|
-
maker: {},
|
|
650
|
-
aaveV2: {},
|
|
651
|
-
compoundV2: {},
|
|
652
|
-
liquity: {},
|
|
653
|
-
crvUsd: {},
|
|
654
|
-
llamaLend: {},
|
|
655
|
-
fluid: {
|
|
656
|
-
error: '',
|
|
657
|
-
data: {},
|
|
658
|
-
},
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
yield Promise.allSettled([
|
|
662
|
-
// === MARKET DATA (needs to be fetched first) ===
|
|
663
|
-
...morphoMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
664
|
-
markets.morphoMarketsData[market.value] = yield _getMorphoBluePortfolioMarketData(client, network, market);
|
|
665
|
-
})),
|
|
666
|
-
...morphoMidnightMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
667
|
-
markets.morphoMidnightMarketsData[market.value] = yield _getMorphoMidnightMarketData(client, network, market);
|
|
668
|
-
})),
|
|
669
|
-
...compoundV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
670
|
-
markets.compoundV3MarketsData[market.value] = yield _getCompoundV3MarketsData(client, network, market, defaultClient);
|
|
671
|
-
})),
|
|
672
|
-
...sparkMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
673
|
-
markets.sparkMarketsData[market.value] = yield _getSparkMarketsData(client, network, market);
|
|
674
|
-
})),
|
|
675
|
-
...aaveV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
676
|
-
markets.aaveV3MarketsData[market.value] = yield _getAaveV3MarketData(client, network, market);
|
|
677
|
-
})),
|
|
678
|
-
...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
|
|
679
|
-
markets.aaveV4SpokesData[spoke.value] = yield _getAaveV4SpokeData(client, network, spoke);
|
|
680
|
-
})),
|
|
681
|
-
...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
682
|
-
markets.aaveV2MarketsData[market.value] = yield _getAaveV2MarketsData(client, network, market);
|
|
683
|
-
})),
|
|
684
|
-
...compoundV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
685
|
-
markets.compoundV2MarketsData[market.value] = yield _getCompoundV2MarketsData(client, network);
|
|
686
|
-
})),
|
|
687
|
-
...crvUsdMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
688
|
-
markets.crvUsdMarketsData[market.value] = yield _getCurveUsdGlobalData(client, network, market);
|
|
689
|
-
})),
|
|
690
|
-
...llamaLendMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
691
|
-
markets.llamaLendMarketsData[market.value] = yield _getLlamaLendGlobalData(client, network, market);
|
|
692
|
-
})),
|
|
693
|
-
...liquityV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
694
|
-
markets.liquityV2MarketsData[market.value] = yield _getLiquityV2MarketData(client, network, market);
|
|
695
|
-
})),
|
|
696
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
697
|
-
if (!isFluidSupported)
|
|
698
|
-
return;
|
|
699
|
-
try {
|
|
700
|
-
markets.fluidMarketsData = yield _getAllFluidMarketDataPortfolio(client, network);
|
|
701
|
-
}
|
|
702
|
-
catch (error) {
|
|
703
|
-
console.error('Error fetching Fluid markets data:', error);
|
|
704
|
-
}
|
|
705
|
-
}))(),
|
|
706
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
707
|
-
if (!isMainnet)
|
|
708
|
-
return; // Maker CDPs are only available on mainnet
|
|
709
|
-
try {
|
|
710
|
-
markets.makerMarketsData = yield _getMakerIlksData(client, network, MakerActiveIlks);
|
|
711
|
-
}
|
|
712
|
-
catch (error) {
|
|
713
|
-
console.error('Error fetching Maker ilks data:', error);
|
|
714
|
-
}
|
|
715
|
-
}))(),
|
|
716
|
-
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
717
|
-
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
718
|
-
if (!isMainnet)
|
|
719
|
-
return; // Maker CDPs are only available on mainnet
|
|
720
|
-
const makerCdp = yield _getUserCdps(client, network, address);
|
|
721
|
-
makerCdps[address.toLowerCase()] = makerCdp;
|
|
722
|
-
})),
|
|
723
|
-
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
724
|
-
try {
|
|
725
|
-
if (!isFluidSupported)
|
|
726
|
-
return; // Fluid is not available on Optimism
|
|
727
|
-
const userPositions = (yield _getUserPositionsPortfolio(client, network, address));
|
|
728
|
-
for (const position of userPositions) {
|
|
729
|
-
if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
|
|
730
|
-
positions[address.toLowerCase()].fluid.data[position.userData.nftId] = position.userData;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
catch (error) {
|
|
735
|
-
console.error(`Error fetching Fluid positions for address ${address}:`, error);
|
|
736
|
-
positions[address.toLowerCase()].fluid = {
|
|
737
|
-
error: `Error fetching Fluid positions for address ${address}`,
|
|
738
|
-
data: {},
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
})),
|
|
742
|
-
]);
|
|
743
|
-
yield Promise.all([
|
|
744
|
-
...aaveV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
745
|
-
try {
|
|
746
|
-
const accData = yield _getAaveV3AccountData(client, network, address, Object.assign({ selectedMarket: market }, markets.aaveV3MarketsData[market.value]));
|
|
747
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
748
|
-
positions[address.toLowerCase()].aaveV3[market.value] = { error: '', data: accData };
|
|
749
|
-
}
|
|
750
|
-
catch (error) {
|
|
751
|
-
console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
|
|
752
|
-
positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
753
|
-
}
|
|
754
|
-
}))).flat(),
|
|
755
|
-
...aaveV4Spokes.map((spoke) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
756
|
-
try {
|
|
757
|
-
const accData = yield _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address);
|
|
758
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
759
|
-
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
|
|
760
|
-
}
|
|
761
|
-
catch (error) {
|
|
762
|
-
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
763
|
-
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
764
|
-
}
|
|
765
|
-
}))).flat(),
|
|
766
|
-
...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
767
|
-
try {
|
|
768
|
-
const accData = yield _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value]);
|
|
769
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
770
|
-
positions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: accData };
|
|
771
|
-
}
|
|
772
|
-
catch (error) {
|
|
773
|
-
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
|
|
774
|
-
positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
775
|
-
}
|
|
776
|
-
}))).flat(),
|
|
777
|
-
...morphoMidnightMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
778
|
-
try {
|
|
779
|
-
const accData = yield _getMorphoMidnightAccountData(client, network, address, market, markets.morphoMidnightMarketsData[market.value]);
|
|
780
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
781
|
-
positions[address.toLowerCase()].morphoMidnight[market.value] = { error: '', data: accData };
|
|
782
|
-
}
|
|
783
|
-
catch (error) {
|
|
784
|
-
console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
|
|
785
|
-
positions[address.toLowerCase()].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
|
|
786
|
-
}
|
|
787
|
-
}))).flat(),
|
|
788
|
-
...compoundV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
789
|
-
try {
|
|
790
|
-
const accData = yield _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData });
|
|
791
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
792
|
-
positions[address.toLowerCase()].compoundV3[market.value] = { error: '', data: accData };
|
|
793
|
-
}
|
|
794
|
-
catch (error) {
|
|
795
|
-
console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
|
|
796
|
-
positions[address.toLowerCase()].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
797
|
-
}
|
|
798
|
-
}))).flat(),
|
|
799
|
-
...sparkMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
800
|
-
try {
|
|
801
|
-
const accData = yield _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData });
|
|
802
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
803
|
-
positions[address.toLowerCase()].spark[market.value] = { error: '', data: accData };
|
|
804
|
-
}
|
|
805
|
-
catch (error) {
|
|
806
|
-
console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
|
|
807
|
-
positions[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
808
|
-
}
|
|
809
|
-
}))).flat(),
|
|
810
|
-
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
811
|
-
var _a;
|
|
812
|
-
return (_a = makerCdps[address.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
813
|
-
try {
|
|
814
|
-
// reuse ilk data fetched for the markets payload; ilks outside the active set are fetched on demand
|
|
815
|
-
const cdpData = yield _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]);
|
|
816
|
-
if (cdpData) {
|
|
817
|
-
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
catch (error) {
|
|
821
|
-
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
822
|
-
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
823
|
-
}
|
|
824
|
-
}));
|
|
825
|
-
})).flat(),
|
|
826
|
-
...aaveV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
827
|
-
try {
|
|
828
|
-
const accData = yield _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market);
|
|
829
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
830
|
-
positions[address.toLowerCase()].aaveV2[market.value] = { error: '', data: accData };
|
|
831
|
-
}
|
|
832
|
-
catch (error) {
|
|
833
|
-
console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
|
|
834
|
-
positions[address.toLowerCase()].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
|
|
835
|
-
}
|
|
836
|
-
}))).flat(),
|
|
837
|
-
...compoundV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
838
|
-
try {
|
|
839
|
-
const accData = yield _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData);
|
|
840
|
-
if (new Dec(accData.suppliedUsd).gt(0))
|
|
841
|
-
positions[address.toLowerCase()].compoundV2[market.value] = { error: '', data: accData };
|
|
842
|
-
}
|
|
843
|
-
catch (error) {
|
|
844
|
-
console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
|
|
845
|
-
positions[address.toLowerCase()].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
|
|
846
|
-
}
|
|
847
|
-
}))).flat(),
|
|
848
|
-
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
849
|
-
try {
|
|
850
|
-
if (!isMainnet)
|
|
851
|
-
return; // Liquity trove info is only available on mainnet
|
|
852
|
-
const troveInfo = yield _getLiquityTroveInfo(client, network, address);
|
|
853
|
-
if (new Dec(troveInfo.collateral).gt(0))
|
|
854
|
-
positions[address.toLowerCase()].liquity = { error: '', data: troveInfo };
|
|
855
|
-
}
|
|
856
|
-
catch (error) {
|
|
857
|
-
console.error(`Error fetching Liquity trove info for address ${address}:`, error);
|
|
858
|
-
positions[address.toLowerCase()].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
|
|
859
|
-
}
|
|
860
|
-
})),
|
|
861
|
-
...crvUsdMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
862
|
-
try {
|
|
863
|
-
const accData = yield _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand);
|
|
864
|
-
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
865
|
-
positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: markets.crvUsdMarketsData[market.value].borrowRate }) };
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
catch (error) {
|
|
869
|
-
console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
|
|
870
|
-
positions[address.toLowerCase()].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
|
|
871
|
-
}
|
|
872
|
-
}))).flat(),
|
|
873
|
-
...llamaLendMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
874
|
-
try {
|
|
875
|
-
const accData = yield _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value]);
|
|
876
|
-
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
877
|
-
positions[address.toLowerCase()].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: markets.llamaLendMarketsData[market.value].borrowRate }) };
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
catch (error) {
|
|
881
|
-
console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
|
|
882
|
-
positions[address.toLowerCase()].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
883
|
-
}
|
|
884
|
-
}))).flat(),
|
|
885
|
-
]);
|
|
886
|
-
return {
|
|
887
|
-
positions,
|
|
888
|
-
markets,
|
|
889
|
-
};
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
606
|
export * from './discovery';
|
package/esm/types/portfolio.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AaveV4AccountData,
|
|
1
|
+
import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
|
|
3
3
|
import { EthAddress } from './common';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
5
|
+
import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
6
|
+
import { FluidVaultData } from './fluid';
|
|
7
7
|
import { LiquityTroveInfo } from './liquity';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
|
|
8
|
+
import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
9
|
+
import { CdpData } from './maker';
|
|
10
|
+
import { MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
11
|
+
import { MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
12
|
+
import { SparkPositionData, SparkVersions } from './spark';
|
|
14
13
|
export interface PortfolioProtocolData<T> {
|
|
15
14
|
error: string;
|
|
16
15
|
data: T | null;
|
|
@@ -60,18 +59,3 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
60
59
|
export interface PortfolioPositionsData {
|
|
61
60
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
|
62
61
|
}
|
|
63
|
-
export interface PortfolioMarketsData {
|
|
64
|
-
morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
|
|
65
|
-
morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
|
|
66
|
-
compoundV3MarketsData: Record<string, CompoundV3MarketsData>;
|
|
67
|
-
sparkMarketsData: Record<string, SparkMarketsData>;
|
|
68
|
-
aaveV3MarketsData: Record<string, AaveV3MarketData>;
|
|
69
|
-
aaveV2MarketsData: Record<string, AaveV2MarketData>;
|
|
70
|
-
compoundV2MarketsData: Record<string, CompoundV2MarketsData>;
|
|
71
|
-
crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData>;
|
|
72
|
-
llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
|
|
73
|
-
liquityV2MarketsData: Record<string, LiquityV2MarketData>;
|
|
74
|
-
aaveV4SpokesData: Record<string, AaveV4SpokeData>;
|
|
75
|
-
fluidMarketsData: Record<string, FluidMarketData>;
|
|
76
|
-
makerMarketsData: Record<string, IlkInfo>;
|
|
77
|
-
}
|
package/package.json
CHANGED
package/src/fluid/index.ts
CHANGED
|
@@ -1830,43 +1830,3 @@ export const _getUserPositionsPortfolio = async (provider: PublicClient, network
|
|
|
1830
1830
|
userData: userData[i],
|
|
1831
1831
|
})).filter(md => md.marketData !== undefined);
|
|
1832
1832
|
};
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
export const _getAllFluidMarketDataPortfolio = async (provider: PublicClient, network: NetworkNumber): Promise<Record<string, FluidMarketData>> => {
|
|
1836
|
-
const versions = getFluidVersionsDataForNetwork(network);
|
|
1837
|
-
if (versions.length === 0) return {};
|
|
1838
|
-
|
|
1839
|
-
const view = FluidViewContractViem(provider, network);
|
|
1840
|
-
const vaultsData = await Promise.all(versions.map((version) => view.read.getVaultData([version.marketAddress])));
|
|
1841
|
-
|
|
1842
|
-
const tokens = Array.from(new Set(vaultsData.map((vaultData) => {
|
|
1843
|
-
const vaultTokens = [getAssetInfoByAddress(vaultData.supplyToken0, network).symbol, getAssetInfoByAddress(vaultData.borrowToken0, network).symbol];
|
|
1844
|
-
if (vaultData.supplyToken1 && !compareAddresses(ZERO_ADDRESS, vaultData.supplyToken1)) vaultTokens.push(getAssetInfoByAddress(vaultData.supplyToken1, network).symbol);
|
|
1845
|
-
if (vaultData.borrowToken1 && !compareAddresses(ZERO_ADDRESS, vaultData.borrowToken1)) vaultTokens.push(getAssetInfoByAddress(vaultData.borrowToken1, network).symbol);
|
|
1846
|
-
return vaultTokens;
|
|
1847
|
-
}).flat()));
|
|
1848
|
-
|
|
1849
|
-
// ETH and WBTC needed for other tokens prices
|
|
1850
|
-
if (!tokens.includes('ETH')) tokens.push('ETH');
|
|
1851
|
-
if (!tokens.includes('WBTC')) tokens.push('WBTC');
|
|
1852
|
-
|
|
1853
|
-
const [tokenPrices, merklCampaigns] = await Promise.all([
|
|
1854
|
-
getTokensPricesForPortfolio(tokens, provider, network),
|
|
1855
|
-
getFluidMerklCampaigns(network),
|
|
1856
|
-
]);
|
|
1857
|
-
|
|
1858
|
-
const parsedMarketsData = await Promise.all(vaultsData.map(async (vaultData) => parseMarketData(provider, vaultData, network, tokenPrices)));
|
|
1859
|
-
|
|
1860
|
-
const marketsData: Record<string, FluidMarketData> = {};
|
|
1861
|
-
parsedMarketsData.forEach((marketData, i) => {
|
|
1862
|
-
if (!marketData) return;
|
|
1863
|
-
marketsData[versions[i].value] = attachFluidMerklIncentives(marketData, merklCampaigns);
|
|
1864
|
-
});
|
|
1865
|
-
|
|
1866
|
-
return marketsData;
|
|
1867
|
-
};
|
|
1868
|
-
|
|
1869
|
-
export const getAllFluidMarketDataPortfolio = async (
|
|
1870
|
-
provider: EthereumProvider,
|
|
1871
|
-
network: NetworkNumber,
|
|
1872
|
-
): Promise<Record<string, FluidMarketData>> => _getAllFluidMarketDataPortfolio(getViemProvider(provider, network, { batch: { multicall: true } }), network);
|
package/src/maker/index.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import {
|
|
3
|
-
assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
|
|
3
|
+
assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
|
|
4
4
|
} from '@defisaver/tokens';
|
|
5
5
|
import { Client, PublicClient } from 'viem';
|
|
6
6
|
import {
|
|
7
|
-
Blockish, EthAddress, EthereumProvider,
|
|
7
|
+
Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances,
|
|
8
8
|
} from '../types/common';
|
|
9
9
|
import {
|
|
10
10
|
getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem,
|
|
11
11
|
} from '../contracts';
|
|
12
|
-
import {
|
|
13
|
-
CdpData, CdpInfo, CdpType, IlkInfo,
|
|
14
|
-
} from '../types';
|
|
12
|
+
import { CdpData, CdpInfo, CdpType } from '../types';
|
|
15
13
|
import { wethToEth } from '../services/utils';
|
|
16
14
|
import { parseCollateralInfo } from '../helpers/makerHelpers';
|
|
17
15
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
@@ -131,70 +129,44 @@ export const getUserCdps = async (
|
|
|
131
129
|
userAddress: EthAddress,
|
|
132
130
|
): Promise<CdpInfo[]> => _getUserCdps(getViemProvider(provider, network), network, userAddress);
|
|
133
131
|
|
|
134
|
-
export const
|
|
132
|
+
export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo): Promise<CdpData> => {
|
|
135
133
|
const vatContract = McdVatContractViem(provider, network);
|
|
136
134
|
const spotterContract = McdSpotterContractViem(provider, network);
|
|
137
135
|
const dogContract = McdDogContractViem(provider, network);
|
|
138
136
|
const jugContract = McdJugContractViem(provider, network);
|
|
139
137
|
|
|
140
|
-
const par = await spotterContract.read.par();
|
|
141
|
-
|
|
142
|
-
const ilksInfo = await Promise.all(ilkLabels.map(async (ilkLabel) => {
|
|
143
|
-
const ilk = stringToBytes(ilkLabel) as HexString;
|
|
144
|
-
const [
|
|
145
|
-
[_, mat],
|
|
146
|
-
[artGlobal, rate, spot, line],
|
|
147
|
-
[duty],
|
|
148
|
-
futureRate,
|
|
149
|
-
chop,
|
|
150
|
-
] = await Promise.all([
|
|
151
|
-
spotterContract.read.ilks([ilk]),
|
|
152
|
-
vatContract.read.ilks([ilk]),
|
|
153
|
-
jugContract.read.ilks([ilk]),
|
|
154
|
-
jugContract.read.drip([ilk]),
|
|
155
|
-
dogContract.read.chop([ilk]),
|
|
156
|
-
]);
|
|
157
|
-
|
|
158
|
-
return parseCollateralInfo(
|
|
159
|
-
ilk,
|
|
160
|
-
par.toString(),
|
|
161
|
-
mat.toString(),
|
|
162
|
-
artGlobal.toString(),
|
|
163
|
-
rate.toString(),
|
|
164
|
-
spot.toString(),
|
|
165
|
-
line.toString(),
|
|
166
|
-
duty.toString(),
|
|
167
|
-
futureRate.toString(),
|
|
168
|
-
chop.toString(),
|
|
169
|
-
);
|
|
170
|
-
}));
|
|
171
|
-
|
|
172
|
-
return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
export const getMakerIlksData = async (
|
|
176
|
-
provider: EthereumProvider,
|
|
177
|
-
network: NetworkNumber,
|
|
178
|
-
ilkLabels: string[],
|
|
179
|
-
): Promise<Record<string, IlkInfo>> => _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels);
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
183
|
-
*/
|
|
184
|
-
export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo, ilkInfo?: IlkInfo): Promise<CdpData> => {
|
|
185
|
-
const vatContract = McdVatContractViem(provider, network);
|
|
186
|
-
|
|
187
138
|
const [
|
|
188
139
|
[ink, art],
|
|
189
140
|
coll,
|
|
190
|
-
|
|
141
|
+
par,
|
|
142
|
+
[_, mat],
|
|
143
|
+
[artGlobal, rate, spot, line],
|
|
144
|
+
[duty],
|
|
145
|
+
futureRate,
|
|
146
|
+
chop,
|
|
191
147
|
] = await Promise.all([
|
|
192
148
|
vatContract.read.urns([cdp.ilk, cdp.urn]),
|
|
193
149
|
vatContract.read.gem([cdp.ilk, cdp.urn]),
|
|
194
|
-
|
|
150
|
+
spotterContract.read.par(),
|
|
151
|
+
spotterContract.read.ilks([cdp.ilk]),
|
|
152
|
+
vatContract.read.ilks([cdp.ilk]),
|
|
153
|
+
jugContract.read.ilks([cdp.ilk]),
|
|
154
|
+
jugContract.read.drip([cdp.ilk]),
|
|
155
|
+
dogContract.read.chop([cdp.ilk]),
|
|
195
156
|
]);
|
|
196
157
|
|
|
197
|
-
const collInfo =
|
|
158
|
+
const collInfo = parseCollateralInfo(
|
|
159
|
+
cdp.ilk,
|
|
160
|
+
par.toString(),
|
|
161
|
+
mat.toString(),
|
|
162
|
+
artGlobal.toString(),
|
|
163
|
+
rate.toString(),
|
|
164
|
+
spot.toString(),
|
|
165
|
+
line.toString(),
|
|
166
|
+
duty.toString(),
|
|
167
|
+
futureRate.toString(),
|
|
168
|
+
chop.toString(),
|
|
169
|
+
);
|
|
198
170
|
|
|
199
171
|
const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
|
|
200
172
|
|
package/src/markets/index.ts
CHANGED
|
@@ -30,5 +30,4 @@ export {
|
|
|
30
30
|
getFTokenAddress,
|
|
31
31
|
getFluidMarketInfoByAddress,
|
|
32
32
|
} from './fluid';
|
|
33
|
-
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
34
|
-
export { MakerActiveIlks } from './maker';
|
|
33
|
+
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|