@defisaver/positions-sdk 2.1.162 → 2.1.164
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/curveUsd/index.d.ts +5 -2
- package/cjs/curveUsd/index.js +30 -15
- 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.d.ts +3 -1
- package/cjs/helpers/curveUsdHelpers/index.js +15 -2
- package/cjs/helpers/fluidHelpers/index.js +1 -0
- package/cjs/helpers/liquityV2Helpers/index.js +1 -0
- package/cjs/helpers/llamaLendHelpers/index.js +1 -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 +15 -2
- package/cjs/maker/index.d.ts +7 -2
- package/cjs/maker/index.js +44 -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/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/cjs/moneymarket/moneymarketCommonService.js +13 -1
- package/cjs/portfolio/index.d.ts +5 -1
- package/cjs/portfolio/index.js +282 -16
- package/cjs/staking/staking.d.ts +20 -0
- package/cjs/staking/staking.js +19 -1
- 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/curveUsd.d.ts +6 -0
- package/cjs/types/fluid.d.ts +1 -0
- package/cjs/types/liquity.d.ts +4 -0
- package/cjs/types/liquityV2.d.ts +2 -0
- package/cjs/types/maker.d.ts +4 -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/curveUsd/index.d.ts +5 -2
- package/esm/curveUsd/index.js +30 -15
- 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.d.ts +3 -1
- package/esm/helpers/curveUsdHelpers/index.js +16 -3
- package/esm/helpers/fluidHelpers/index.js +1 -0
- package/esm/helpers/liquityV2Helpers/index.js +1 -0
- package/esm/helpers/llamaLendHelpers/index.js +2 -1
- 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 +16 -3
- package/esm/maker/index.d.ts +7 -2
- package/esm/maker/index.js +44 -14
- 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/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/esm/moneymarket/moneymarketCommonService.js +11 -0
- package/esm/portfolio/index.d.ts +5 -1
- package/esm/portfolio/index.js +284 -19
- package/esm/staking/staking.d.ts +20 -0
- package/esm/staking/staking.js +17 -0
- 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/curveUsd.d.ts +6 -0
- package/esm/types/fluid.d.ts +1 -0
- package/esm/types/liquity.d.ts +4 -0
- package/esm/types/liquityV2.d.ts +2 -0
- package/esm/types/maker.d.ts +4 -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/curveUsd/index.ts +33 -16
- 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 +23 -3
- package/src/helpers/fluidHelpers/index.ts +1 -0
- package/src/helpers/liquityV2Helpers/index.ts +1 -0
- package/src/helpers/llamaLendHelpers/index.ts +2 -1
- 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 +17 -3
- package/src/maker/index.ts +77 -30
- package/src/markets/index.ts +2 -1
- package/src/markets/maker/index.ts +10 -0
- package/src/moneymarket/moneymarketCommonService.ts +15 -0
- package/src/portfolio/index.ts +262 -5
- package/src/staking/staking.ts +28 -0
- package/src/types/aave.ts +3 -0
- package/src/types/aaveV4.ts +1 -0
- package/src/types/compound.ts +2 -0
- package/src/types/curveUsd.ts +7 -0
- package/src/types/fluid.ts +1 -0
- package/src/types/liquity.ts +6 -0
- package/src/types/liquityV2.ts +2 -0
- package/src/types/maker.ts +6 -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
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getExposure = exports.aprToApy = exports.isLeveragedPos = exports.STABLE_ASSETS = exports.calculateBorrowingAssetLimit = exports.calcLeverageLiqPrice = exports.calcShortLiqPrice = exports.calcLongLiqPrice = exports.getAssetsTotal = void 0;
|
|
6
|
+
exports.getSafetyRatioFromCollateralRatio = exports.getExposure = exports.aprToApy = exports.isLeveragedPos = exports.STABLE_ASSETS = exports.calculateBorrowingAssetLimit = exports.calcLeverageLiqPrice = exports.calcShortLiqPrice = exports.calcLongLiqPrice = exports.getAssetsTotal = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const constants_1 = require("../constants");
|
|
9
9
|
const common_1 = require("../types/common");
|
|
@@ -102,3 +102,15 @@ const getExposure = (borrowedUsd, suppliedUsd) => {
|
|
|
102
102
|
return new decimal_js_1.default(suppliedUsd).div(balanceUsd).toDecimalPlaces(2).toString();
|
|
103
103
|
};
|
|
104
104
|
exports.getExposure = getExposure;
|
|
105
|
+
/**
|
|
106
|
+
* A collateral ratio rebased so that 100 means "sitting exactly on the liquidation ratio": the scale the
|
|
107
|
+
* shared `safetyRatio` field assumes. Protocols that liquidate on a raw collateral ratio (Maker at the ilk's
|
|
108
|
+
* liquidation ratio, Liquity at 110%, crvUSD/LlamaLend at the band-derived minimum) pass through here.
|
|
109
|
+
*
|
|
110
|
+
* Yields '0' when the liquidation ratio isn't available (or is 0), the "no signal" value consumers already recognise.
|
|
111
|
+
* Mirrors `getSafetyRatioFromCollateralRatio` on the client.
|
|
112
|
+
*/
|
|
113
|
+
const getSafetyRatioFromCollateralRatio = (collateralRatio, liquidationRatio) => (+(liquidationRatio !== null && liquidationRatio !== void 0 ? liquidationRatio : 0) > 0
|
|
114
|
+
? new decimal_js_1.default(collateralRatio || 0).div(liquidationRatio).mul(100).toString()
|
|
115
|
+
: '0');
|
|
116
|
+
exports.getSafetyRatioFromCollateralRatio = getSafetyRatioFromCollateralRatio;
|
package/cjs/portfolio/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
-
import { PortfolioPositionsData } from '../types';
|
|
2
|
+
import { PortfolioMarketsData, 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
|
+
}>;
|
|
9
13
|
export * from './discovery';
|
package/cjs/portfolio/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.getPortfolioData = getPortfolioData;
|
|
30
|
+
exports.getShifterPortfolioData = getShifterPortfolioData;
|
|
30
31
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
32
|
const common_1 = require("../types/common");
|
|
32
33
|
const markets_1 = require("../markets");
|
|
@@ -521,21 +522,18 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
|
|
|
521
522
|
positions[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
522
523
|
}
|
|
523
524
|
}))).flat(),
|
|
524
|
-
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
if (cdpData) {
|
|
530
|
-
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
catch (error) {
|
|
534
|
-
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
535
|
-
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
525
|
+
...addresses.map((address) => (makerCdps[address.toLowerCase()] || []).map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
526
|
+
try {
|
|
527
|
+
const cdpData = yield (0, maker_1._getMakerCdpData)(client, network, cdpInfo);
|
|
528
|
+
if (cdpData) {
|
|
529
|
+
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
536
530
|
}
|
|
537
|
-
}
|
|
538
|
-
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
534
|
+
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
535
|
+
}
|
|
536
|
+
}))).flat(),
|
|
539
537
|
...aaveV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
540
538
|
try {
|
|
541
539
|
const accData = yield (0, aaveV2_1._getAaveV2AccountData)(client, network, address, aaveV2MarketsData[market.value].assetsData, market);
|
|
@@ -573,9 +571,9 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
|
|
|
573
571
|
})),
|
|
574
572
|
...crvUsdMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
575
573
|
try {
|
|
576
|
-
const accData = yield (0, curveUsd_1._getCurveUsdUserData)(client, network, address, market, crvUsdMarketsData[market.value].activeBand);
|
|
574
|
+
const accData = yield (0, curveUsd_1._getCurveUsdUserData)(client, network, address, market, crvUsdMarketsData[market.value].activeBand, crvUsdMarketsData[market.value].borrowRate);
|
|
577
575
|
if (new decimal_js_1.default(accData.suppliedUsd).gt(0) || new decimal_js_1.default(accData.borrowedUsd).gt(0)) {
|
|
578
|
-
positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data:
|
|
576
|
+
positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: accData };
|
|
579
577
|
}
|
|
580
578
|
}
|
|
581
579
|
catch (error) {
|
|
@@ -619,4 +617,272 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
|
|
|
619
617
|
};
|
|
620
618
|
});
|
|
621
619
|
}
|
|
620
|
+
function getShifterPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
|
|
621
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
|
|
622
|
+
const isMainnet = network === common_1.NetworkNumber.Eth;
|
|
623
|
+
const isFluidSupported = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Base, common_1.NetworkNumber.Plasma].includes(network);
|
|
624
|
+
const morphoMarkets = Object.values((0, markets_1.MorphoBlueMarkets)(network)).filter((market) => market.chainIds.includes(network));
|
|
625
|
+
const compoundV3Markets = Object.values((0, markets_1.CompoundMarkets)(network)).filter((market) => market.chainIds.includes(network) && market.value !== types_1.CompoundVersions.CompoundV2);
|
|
626
|
+
const sparkMarkets = Object.values((0, markets_1.SparkMarkets)(network)).filter((market) => market.chainIds.includes(network));
|
|
627
|
+
const aaveV3Markets = [types_1.AaveVersions.AaveV3, types_1.AaveVersions.AaveV3Lido, types_1.AaveVersions.AaveV3Etherfi].map((version) => (0, markets_1.AaveMarkets)(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
628
|
+
const aaveV2Markets = [types_1.AaveVersions.AaveV2].map((version) => (0, markets_1.AaveMarkets)(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
629
|
+
const compoundV2Markets = [types_1.CompoundVersions.CompoundV2].map((version) => (0, markets_1.CompoundMarkets)(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
630
|
+
const crvUsdMarkets = Object.values((0, markets_1.CrvUsdMarkets)(network)).filter((market) => market.chainIds.includes(network));
|
|
631
|
+
const llamaLendMarkets = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb].includes(network) ? Object.values((0, markets_1.LlamaLendMarkets)(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
632
|
+
const liquityV2Markets = [common_1.NetworkNumber.Eth].includes(network) ? Object.values((0, markets_1.LiquityV2Markets)(network)) : [];
|
|
633
|
+
const aaveV4Spokes = Object.values((0, markets_1.AaveV4Spokes)(network)).filter((market) => market.chainIds.includes(network));
|
|
634
|
+
const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 2500000 } } }];
|
|
635
|
+
const client = (0, viem_1.getViemProvider)(provider, ...args);
|
|
636
|
+
const defaultClient = (0, viem_1.getViemProvider)(defaultProvider, ...args);
|
|
637
|
+
const markets = {
|
|
638
|
+
morphoMarketsData: {},
|
|
639
|
+
morphoMidnightMarketsData: {}, // Morpho Midnight is not fetched for the shifter; key kept so the payload shape is stable
|
|
640
|
+
compoundV3MarketsData: {},
|
|
641
|
+
sparkMarketsData: {},
|
|
642
|
+
aaveV3MarketsData: {},
|
|
643
|
+
aaveV2MarketsData: {},
|
|
644
|
+
compoundV2MarketsData: {},
|
|
645
|
+
crvUsdMarketsData: {},
|
|
646
|
+
llamaLendMarketsData: {},
|
|
647
|
+
liquityV2MarketsData: {},
|
|
648
|
+
aaveV4SpokesData: {},
|
|
649
|
+
fluidMarketsData: {},
|
|
650
|
+
makerMarketsData: {},
|
|
651
|
+
};
|
|
652
|
+
const makerCdps = {};
|
|
653
|
+
const positions = {};
|
|
654
|
+
for (const address of addresses) {
|
|
655
|
+
positions[address.toLowerCase()] = {
|
|
656
|
+
aaveV3: {},
|
|
657
|
+
aaveV4: {},
|
|
658
|
+
morphoBlue: {},
|
|
659
|
+
morphoMidnight: {}, // not fetched for the shifter (see markets above)
|
|
660
|
+
compoundV3: {},
|
|
661
|
+
spark: {},
|
|
662
|
+
maker: {},
|
|
663
|
+
aaveV2: {},
|
|
664
|
+
compoundV2: {},
|
|
665
|
+
liquity: {},
|
|
666
|
+
crvUsd: {},
|
|
667
|
+
llamaLend: {},
|
|
668
|
+
fluid: {
|
|
669
|
+
error: '',
|
|
670
|
+
data: {},
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
yield Promise.allSettled([
|
|
675
|
+
// === MARKET DATA (needs to be fetched first) ===
|
|
676
|
+
...morphoMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
677
|
+
markets.morphoMarketsData[market.value] = yield (0, morphoBlue_1._getMorphoBluePortfolioMarketData)(client, network, market);
|
|
678
|
+
})),
|
|
679
|
+
...compoundV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
680
|
+
markets.compoundV3MarketsData[market.value] = yield (0, compoundV3_1._getCompoundV3MarketsData)(client, network, market, defaultClient);
|
|
681
|
+
})),
|
|
682
|
+
...sparkMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
683
|
+
markets.sparkMarketsData[market.value] = yield (0, spark_1._getSparkMarketsData)(client, network, market);
|
|
684
|
+
})),
|
|
685
|
+
...aaveV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
686
|
+
markets.aaveV3MarketsData[market.value] = yield (0, aaveV3_1._getAaveV3MarketData)(client, network, market);
|
|
687
|
+
})),
|
|
688
|
+
...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
|
|
689
|
+
markets.aaveV4SpokesData[spoke.value] = yield (0, aaveV4_1._getAaveV4SpokeData)(client, network, spoke);
|
|
690
|
+
})),
|
|
691
|
+
...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
692
|
+
markets.aaveV2MarketsData[market.value] = yield (0, aaveV2_1._getAaveV2MarketsData)(client, network, market);
|
|
693
|
+
})),
|
|
694
|
+
...compoundV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
695
|
+
markets.compoundV2MarketsData[market.value] = yield (0, compoundV2_1._getCompoundV2MarketsData)(client, network);
|
|
696
|
+
})),
|
|
697
|
+
...crvUsdMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
698
|
+
markets.crvUsdMarketsData[market.value] = yield (0, curveUsd_1._getCurveUsdGlobalData)(client, network, market);
|
|
699
|
+
})),
|
|
700
|
+
...llamaLendMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
701
|
+
markets.llamaLendMarketsData[market.value] = yield (0, llamaLend_1._getLlamaLendGlobalData)(client, network, market);
|
|
702
|
+
})),
|
|
703
|
+
...liquityV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
|
|
704
|
+
markets.liquityV2MarketsData[market.value] = yield (0, liquityV2_1._getLiquityV2MarketData)(client, network, market);
|
|
705
|
+
})),
|
|
706
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
707
|
+
if (!isFluidSupported)
|
|
708
|
+
return;
|
|
709
|
+
try {
|
|
710
|
+
markets.fluidMarketsData = yield (0, fluid_1._getAllFluidMarketDataPortfolio)(client, network);
|
|
711
|
+
}
|
|
712
|
+
catch (error) {
|
|
713
|
+
console.error('Error fetching Fluid markets data:', error);
|
|
714
|
+
}
|
|
715
|
+
}))(),
|
|
716
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
717
|
+
if (!isMainnet)
|
|
718
|
+
return; // Maker CDPs are only available on mainnet
|
|
719
|
+
try {
|
|
720
|
+
markets.makerMarketsData = yield (0, maker_1._getMakerIlksData)(client, network, markets_1.MakerActiveIlks);
|
|
721
|
+
}
|
|
722
|
+
catch (error) {
|
|
723
|
+
console.error('Error fetching Maker ilks data:', error);
|
|
724
|
+
}
|
|
725
|
+
}))(),
|
|
726
|
+
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
727
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
728
|
+
if (!isMainnet)
|
|
729
|
+
return; // Maker CDPs are only available on mainnet
|
|
730
|
+
const makerCdp = yield (0, maker_1._getUserCdps)(client, network, address);
|
|
731
|
+
makerCdps[address.toLowerCase()] = makerCdp;
|
|
732
|
+
})),
|
|
733
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
734
|
+
try {
|
|
735
|
+
if (!isFluidSupported)
|
|
736
|
+
return; // Fluid is not available on Optimism
|
|
737
|
+
const userPositions = (yield (0, fluid_1._getUserPositionsPortfolio)(client, network, address));
|
|
738
|
+
for (const position of userPositions) {
|
|
739
|
+
if (position.userData && new decimal_js_1.default(position.userData.suppliedUsd).gt(0)) {
|
|
740
|
+
positions[address.toLowerCase()].fluid.data[position.userData.nftId] = position.userData;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
catch (error) {
|
|
745
|
+
console.error(`Error fetching Fluid positions for address ${address}:`, error);
|
|
746
|
+
positions[address.toLowerCase()].fluid = {
|
|
747
|
+
error: `Error fetching Fluid positions for address ${address}`,
|
|
748
|
+
data: {},
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
})),
|
|
752
|
+
]);
|
|
753
|
+
yield Promise.all([
|
|
754
|
+
...aaveV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
755
|
+
try {
|
|
756
|
+
const accData = yield (0, aaveV3_1._getAaveV3AccountData)(client, network, address, Object.assign({ selectedMarket: market }, markets.aaveV3MarketsData[market.value]));
|
|
757
|
+
// Always store the position (even with no supply) so the eMode category is available to the shifter
|
|
758
|
+
positions[address.toLowerCase()].aaveV3[market.value] = { error: '', data: accData };
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
|
|
762
|
+
positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
763
|
+
}
|
|
764
|
+
}))).flat(),
|
|
765
|
+
...aaveV4Spokes.map((spoke) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
766
|
+
try {
|
|
767
|
+
const accData = yield (0, aaveV4_1._getAaveV4AccountData)(client, network, markets.aaveV4SpokesData[spoke.value], address);
|
|
768
|
+
if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
|
|
769
|
+
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
|
|
770
|
+
}
|
|
771
|
+
catch (error) {
|
|
772
|
+
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
773
|
+
positions[address.toLowerCase()].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
774
|
+
}
|
|
775
|
+
}))).flat(),
|
|
776
|
+
...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
777
|
+
try {
|
|
778
|
+
const accData = yield (0, morphoBlue_1._getMorphoBlueAccountData)(client, network, address, market, markets.morphoMarketsData[market.value]);
|
|
779
|
+
if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
|
|
780
|
+
positions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: accData };
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
|
|
784
|
+
positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
785
|
+
}
|
|
786
|
+
}))).flat(),
|
|
787
|
+
...compoundV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
788
|
+
try {
|
|
789
|
+
const accData = yield (0, compoundV3_1._getCompoundV3AccountData)(client, network, address, constants_1.ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData });
|
|
790
|
+
if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
|
|
791
|
+
positions[address.toLowerCase()].compoundV3[market.value] = { error: '', data: accData };
|
|
792
|
+
}
|
|
793
|
+
catch (error) {
|
|
794
|
+
console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
|
|
795
|
+
positions[address.toLowerCase()].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
796
|
+
}
|
|
797
|
+
}))).flat(),
|
|
798
|
+
...sparkMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
799
|
+
try {
|
|
800
|
+
const accData = yield (0, spark_1._getSparkAccountData)(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData });
|
|
801
|
+
// Always store the position (even with no supply) so the eMode category is available to the shifter
|
|
802
|
+
positions[address.toLowerCase()].spark[market.value] = { error: '', data: accData };
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
|
|
806
|
+
positions[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
807
|
+
}
|
|
808
|
+
}))).flat(),
|
|
809
|
+
...addresses.map((address) => (makerCdps[address.toLowerCase()] || []).map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
810
|
+
try {
|
|
811
|
+
// reuse ilk data fetched for the markets payload; ilks outside the active set are fetched on demand
|
|
812
|
+
const cdpData = yield (0, maker_1._getMakerCdpData)(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]);
|
|
813
|
+
if (cdpData) {
|
|
814
|
+
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
catch (error) {
|
|
818
|
+
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
819
|
+
positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
820
|
+
}
|
|
821
|
+
}))).flat(),
|
|
822
|
+
...aaveV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
823
|
+
try {
|
|
824
|
+
const accData = yield (0, aaveV2_1._getAaveV2AccountData)(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market);
|
|
825
|
+
if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
|
|
826
|
+
positions[address.toLowerCase()].aaveV2[market.value] = { error: '', data: accData };
|
|
827
|
+
}
|
|
828
|
+
catch (error) {
|
|
829
|
+
console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
|
|
830
|
+
positions[address.toLowerCase()].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
|
|
831
|
+
}
|
|
832
|
+
}))).flat(),
|
|
833
|
+
...compoundV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
834
|
+
try {
|
|
835
|
+
const accData = yield (0, compoundV2_1._getCompoundV2AccountData)(client, network, address, markets.compoundV2MarketsData[market.value].assetsData);
|
|
836
|
+
if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
|
|
837
|
+
positions[address.toLowerCase()].compoundV2[market.value] = { error: '', data: accData };
|
|
838
|
+
}
|
|
839
|
+
catch (error) {
|
|
840
|
+
console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
|
|
841
|
+
positions[address.toLowerCase()].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
|
|
842
|
+
}
|
|
843
|
+
}))).flat(),
|
|
844
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
845
|
+
try {
|
|
846
|
+
if (!isMainnet)
|
|
847
|
+
return; // Liquity trove info is only available on mainnet
|
|
848
|
+
const troveInfo = yield (0, liquity_1._getLiquityTroveInfo)(client, network, address);
|
|
849
|
+
if (new decimal_js_1.default(troveInfo.collateral).gt(0))
|
|
850
|
+
positions[address.toLowerCase()].liquity = { error: '', data: troveInfo };
|
|
851
|
+
}
|
|
852
|
+
catch (error) {
|
|
853
|
+
console.error(`Error fetching Liquity trove info for address ${address}:`, error);
|
|
854
|
+
positions[address.toLowerCase()].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
|
|
855
|
+
}
|
|
856
|
+
})),
|
|
857
|
+
...crvUsdMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
858
|
+
try {
|
|
859
|
+
const accData = yield (0, curveUsd_1._getCurveUsdUserData)(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate);
|
|
860
|
+
if (new decimal_js_1.default(accData.suppliedUsd).gt(0) || new decimal_js_1.default(accData.borrowedUsd).gt(0)) {
|
|
861
|
+
positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: accData };
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
catch (error) {
|
|
865
|
+
console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
|
|
866
|
+
positions[address.toLowerCase()].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
|
|
867
|
+
}
|
|
868
|
+
}))).flat(),
|
|
869
|
+
...llamaLendMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
870
|
+
try {
|
|
871
|
+
const accData = yield (0, llamaLend_1._getLlamaLendUserData)(client, network, address, market, markets.llamaLendMarketsData[market.value]);
|
|
872
|
+
if (new decimal_js_1.default(accData.suppliedUsd).gt(0) || new decimal_js_1.default(accData.borrowedUsd).gt(0)) {
|
|
873
|
+
positions[address.toLowerCase()].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: markets.llamaLendMarketsData[market.value].borrowRate }) };
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
catch (error) {
|
|
877
|
+
console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
|
|
878
|
+
positions[address.toLowerCase()].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
879
|
+
}
|
|
880
|
+
}))).flat(),
|
|
881
|
+
]);
|
|
882
|
+
return {
|
|
883
|
+
positions,
|
|
884
|
+
markets,
|
|
885
|
+
};
|
|
886
|
+
});
|
|
887
|
+
}
|
|
622
888
|
__exportStar(require("./discovery"), exports);
|
package/cjs/staking/staking.d.ts
CHANGED
|
@@ -3,6 +3,26 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
|
|
|
3
3
|
export declare const STAKING_ASSETS: string[];
|
|
4
4
|
export declare const getStakingApy: ((asset: string, network?: number) => Promise<string>) & memoize.Memoized<(asset: string, network?: number) => Promise<string>>;
|
|
5
5
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
6
|
+
/**
|
|
7
|
+
* Net APY for positions that have a single known borrow rate (and optionally a single supply rate)
|
|
8
|
+
* instead of per-asset `assetsData` to feed into `calculateNetApy` (Maker, crvUSD, Liquity v1).
|
|
9
|
+
* All rates are yearly percentages that are already compounded. `incentives` are extra yields
|
|
10
|
+
* (e.g. the native staking yield of the collateral) applied to their own USD base and summed into `incentiveUsd`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const calculateNetApyFromRates: ({ suppliedUsd, borrowedUsd, supplyRate, borrowRate, incentives, }: {
|
|
13
|
+
suppliedUsd: string;
|
|
14
|
+
borrowedUsd: string;
|
|
15
|
+
supplyRate?: string;
|
|
16
|
+
borrowRate?: string;
|
|
17
|
+
incentives?: {
|
|
18
|
+
apy: string;
|
|
19
|
+
amountUsd: string;
|
|
20
|
+
}[];
|
|
21
|
+
}) => {
|
|
22
|
+
netApy: string;
|
|
23
|
+
totalInterestUsd: string;
|
|
24
|
+
incentiveUsd: string;
|
|
25
|
+
};
|
|
6
26
|
export declare const calculateNetApy: ({ usedAssets, assetsData, optionalData, }: {
|
|
7
27
|
usedAssets: MMUsedAssets;
|
|
8
28
|
assetsData: MMAssetsData;
|
package/cjs/staking/staking.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = void 0;
|
|
15
|
+
exports.calculateNetApy = exports.calculateNetApyFromRates = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
18
18
|
const common_1 = require("../types/common");
|
|
@@ -189,6 +189,24 @@ const calculateInterestEarned = (principal, interest, type, apy = false) => {
|
|
|
189
189
|
return (+principal * (Math.pow(((1 + (+interest / 100) / constants_1.BLOCKS_IN_A_YEAR)), (constants_1.BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
|
|
190
190
|
};
|
|
191
191
|
exports.calculateInterestEarned = calculateInterestEarned;
|
|
192
|
+
/**
|
|
193
|
+
* Net APY for positions that have a single known borrow rate (and optionally a single supply rate)
|
|
194
|
+
* instead of per-asset `assetsData` to feed into `calculateNetApy` (Maker, crvUSD, Liquity v1).
|
|
195
|
+
* All rates are yearly percentages that are already compounded. `incentives` are extra yields
|
|
196
|
+
* (e.g. the native staking yield of the collateral) applied to their own USD base and summed into `incentiveUsd`.
|
|
197
|
+
*/
|
|
198
|
+
const calculateNetApyFromRates = ({ suppliedUsd, borrowedUsd, supplyRate = '0', borrowRate = '0', incentives = [], }) => {
|
|
199
|
+
const supplyInterest = new decimal_js_1.default((0, exports.calculateInterestEarned)(suppliedUsd, supplyRate, 'year', true));
|
|
200
|
+
const borrowInterest = new decimal_js_1.default((0, exports.calculateInterestEarned)(borrowedUsd, borrowRate, 'year', true));
|
|
201
|
+
const incentiveUsd = incentives
|
|
202
|
+
.reduce((acc, { apy, amountUsd }) => acc.add((0, exports.calculateInterestEarned)(amountUsd, apy, 'year', true)), new decimal_js_1.default(0))
|
|
203
|
+
.toString();
|
|
204
|
+
const totalInterestUsd = supplyInterest.sub(borrowInterest).add(incentiveUsd).toString();
|
|
205
|
+
const balance = new decimal_js_1.default(suppliedUsd).sub(borrowedUsd);
|
|
206
|
+
const netApy = balance.isZero() ? '0' : new decimal_js_1.default(totalInterestUsd).div(balance).times(100).toString();
|
|
207
|
+
return { netApy, totalInterestUsd, incentiveUsd };
|
|
208
|
+
};
|
|
209
|
+
exports.calculateNetApyFromRates = calculateNetApyFromRates;
|
|
192
210
|
const calculateNetApy = ({ usedAssets, assetsData, optionalData, }) => {
|
|
193
211
|
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
194
212
|
const acc = Object.assign({}, _acc);
|
package/cjs/types/aave.d.ts
CHANGED
|
@@ -127,6 +127,7 @@ export interface AavePositionData extends MMPositionData {
|
|
|
127
127
|
minRatio: string;
|
|
128
128
|
collRatio: string;
|
|
129
129
|
safetyRatioWithLtvZeroFallback?: string;
|
|
130
|
+
safetyRatio?: string;
|
|
130
131
|
suppliedUsd: string;
|
|
131
132
|
borrowedUsd: string;
|
|
132
133
|
borrowLimitUsd: string;
|
|
@@ -160,6 +161,7 @@ export interface AaveV3AggregatedPositionData {
|
|
|
160
161
|
collRatio: string;
|
|
161
162
|
borrowLimitWithLtvZeroFallbackUsd: string;
|
|
162
163
|
safetyRatioWithLtvZeroFallback: string;
|
|
164
|
+
safetyRatio: string;
|
|
163
165
|
netApy: string;
|
|
164
166
|
incentiveUsd: string;
|
|
165
167
|
totalInterestUsd: string;
|
package/cjs/types/aaveV4.d.ts
CHANGED
package/cjs/types/compound.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
96
96
|
leftToBorrowUsd: string;
|
|
97
97
|
ratio: string;
|
|
98
98
|
collRatio: string;
|
|
99
|
+
safetyRatio: string;
|
|
99
100
|
netApy: string;
|
|
100
101
|
incentiveUsd: string;
|
|
101
102
|
totalInterestUsd: string;
|
|
@@ -115,6 +116,7 @@ export interface CompoundAggregatedPositionData {
|
|
|
115
116
|
export interface CompoundPositionData extends MMPositionData {
|
|
116
117
|
ratio: string;
|
|
117
118
|
minRatio: string;
|
|
119
|
+
safetyRatio?: string;
|
|
118
120
|
suppliedUsd: string;
|
|
119
121
|
borrowedUsd: string;
|
|
120
122
|
borrowLimitUsd: string;
|
package/cjs/types/curveUsd.d.ts
CHANGED
|
@@ -73,6 +73,9 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
73
73
|
collFactor: string;
|
|
74
74
|
leveragedType: LeverageType;
|
|
75
75
|
exposure: string;
|
|
76
|
+
netApy: string;
|
|
77
|
+
totalInterestUsd: string;
|
|
78
|
+
incentiveUsd: string;
|
|
76
79
|
leveragedAsset?: string;
|
|
77
80
|
liquidationPrice?: string;
|
|
78
81
|
}
|
|
@@ -113,4 +116,7 @@ export interface CrvUSDUserData {
|
|
|
113
116
|
collateralPrice: string;
|
|
114
117
|
collRatio: string;
|
|
115
118
|
exposure: string;
|
|
119
|
+
netApy: string;
|
|
120
|
+
totalInterestUsd: string;
|
|
121
|
+
incentiveUsd: string;
|
|
116
122
|
}
|
package/cjs/types/fluid.d.ts
CHANGED
package/cjs/types/liquity.d.ts
CHANGED
|
@@ -24,7 +24,11 @@ export interface LiquityTroveInfo {
|
|
|
24
24
|
totalETH: string;
|
|
25
25
|
totalLUSD: string;
|
|
26
26
|
minCollateralRatio: number;
|
|
27
|
+
safetyRatio: string;
|
|
27
28
|
priceForRecovery: string;
|
|
28
29
|
debtInFront: string;
|
|
29
30
|
exposure: string;
|
|
31
|
+
netApy: string;
|
|
32
|
+
totalInterestUsd: string;
|
|
33
|
+
incentiveUsd: string;
|
|
30
34
|
}
|
package/cjs/types/liquityV2.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
94
94
|
liquidationPrice: string;
|
|
95
95
|
ratio: string;
|
|
96
96
|
collRatio: string;
|
|
97
|
+
safetyRatio: string;
|
|
97
98
|
exposure: string;
|
|
98
99
|
}
|
|
99
100
|
export interface LiquityV2TroveData {
|
|
@@ -101,6 +102,7 @@ export interface LiquityV2TroveData {
|
|
|
101
102
|
troveId: string;
|
|
102
103
|
ratio: string;
|
|
103
104
|
collRatio: string;
|
|
105
|
+
safetyRatio?: string;
|
|
104
106
|
liqRatio: string;
|
|
105
107
|
borrowLimitRatio: string;
|
|
106
108
|
interestRate: string;
|
package/cjs/types/maker.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export interface CdpData {
|
|
|
43
43
|
debtAssetMarketPrice: string;
|
|
44
44
|
liquidationPrice: string;
|
|
45
45
|
ratio: string;
|
|
46
|
+
safetyRatio: string;
|
|
46
47
|
liqRatio: string;
|
|
47
48
|
liqPercent: number;
|
|
48
49
|
assetPrice: string;
|
|
@@ -58,4 +59,7 @@ export interface CdpData {
|
|
|
58
59
|
liquidationFee: string;
|
|
59
60
|
lastUpdated: number;
|
|
60
61
|
exposure: string;
|
|
62
|
+
netApy: string;
|
|
63
|
+
totalInterestUsd: string;
|
|
64
|
+
incentiveUsd: string;
|
|
61
65
|
}
|
|
@@ -185,6 +185,7 @@ export interface MorphoBlueAggregatedPositionData {
|
|
|
185
185
|
totalInterestUsd: string;
|
|
186
186
|
ltv: string;
|
|
187
187
|
ratio: string;
|
|
188
|
+
safetyRatio: string;
|
|
188
189
|
leveragedType: LeverageType;
|
|
189
190
|
leveragedAsset?: string;
|
|
190
191
|
currentVolatilePairRatio?: string;
|
|
@@ -207,6 +208,7 @@ export interface MorphoBluePositionData {
|
|
|
207
208
|
totalInterestUsd: string;
|
|
208
209
|
ltv: string;
|
|
209
210
|
ratio: string;
|
|
211
|
+
safetyRatio?: string;
|
|
210
212
|
leveragedType: LeverageType;
|
|
211
213
|
leveragedAsset?: string;
|
|
212
214
|
currentVolatilePairRatio?: string;
|
package/cjs/types/portfolio.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
|
|
2
|
-
import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
|
|
1
|
+
import { AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions } from './aave';
|
|
2
|
+
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
|
|
3
3
|
import { EthAddress } from './common';
|
|
4
|
-
import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
5
|
-
import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
6
|
-
import { FluidVaultData } from './fluid';
|
|
4
|
+
import { CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions } from './compound';
|
|
5
|
+
import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
6
|
+
import { FluidMarketData, FluidVaultData } from './fluid';
|
|
7
7
|
import { LiquityTroveInfo } from './liquity';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { LiquityV2MarketData } from './liquityV2';
|
|
9
|
+
import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
10
|
+
import { CdpData, IlkInfo } from './maker';
|
|
11
|
+
import { MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
12
|
+
import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
13
|
+
import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
|
|
13
14
|
export interface PortfolioProtocolData<T> {
|
|
14
15
|
error: string;
|
|
15
16
|
data: T | null;
|
|
@@ -59,3 +60,18 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
59
60
|
export interface PortfolioPositionsData {
|
|
60
61
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
|
61
62
|
}
|
|
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/cjs/types/spark.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export interface SparkAggregatedPositionData {
|
|
|
85
85
|
leftToBorrowUsd: string;
|
|
86
86
|
ratio: string;
|
|
87
87
|
collRatio: string;
|
|
88
|
+
safetyRatio: string;
|
|
88
89
|
netApy: string;
|
|
89
90
|
incentiveUsd: string;
|
|
90
91
|
totalInterestUsd: string;
|
|
@@ -104,6 +105,7 @@ export interface SparkPositionData extends MMPositionData {
|
|
|
104
105
|
ratio: string;
|
|
105
106
|
minRatio: string;
|
|
106
107
|
collRatio: string;
|
|
108
|
+
safetyRatio?: string;
|
|
107
109
|
suppliedUsd: string;
|
|
108
110
|
borrowedUsd: string;
|
|
109
111
|
borrowLimitUsd: string;
|
package/esm/aaveV2/index.js
CHANGED
|
@@ -167,6 +167,8 @@ export const _getAaveV2AccountData = (provider, network, address, assetsData, ma
|
|
|
167
167
|
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
168
168
|
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
169
169
|
: '0';
|
|
170
|
+
// Aave v2 has no LTV-0 fallback (AaveV3View only), so its safety ratio is the plain ratio.
|
|
171
|
+
payload.safetyRatio = payload.ratio;
|
|
170
172
|
// Calculate borrow limits per asset
|
|
171
173
|
Object.values(payload.usedAssets).forEach((item) => {
|
|
172
174
|
if (item.isBorrowed) {
|