@defisaver/positions-sdk 2.1.174 → 2.1.175-looping-2-dev-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.d.ts +4 -4
- package/cjs/aaveV2/index.js +7 -7
- package/cjs/aaveV3/index.d.ts +5 -14
- package/cjs/aaveV3/index.js +14 -10
- package/cjs/aaveV3/merkl.d.ts +5 -1
- package/cjs/aaveV3/merkl.js +8 -3
- package/cjs/aaveV3/sgho.d.ts +2 -16
- package/cjs/aaveV4/index.d.ts +4 -3
- package/cjs/aaveV4/index.js +19 -16
- package/cjs/aaveV4/lend.d.ts +2 -43
- package/cjs/aaveV4/merkl.d.ts +10 -2
- package/cjs/aaveV4/merkl.js +15 -6
- package/cjs/claiming/aaveV3.d.ts +3 -3
- package/cjs/claiming/aaveV3.js +5 -4
- package/cjs/claiming/ethena.d.ts +2 -1
- package/cjs/claiming/king.d.ts +3 -2
- package/cjs/claiming/king.js +3 -2
- package/cjs/claiming/spark.d.ts +4 -4
- package/cjs/claiming/spark.js +8 -7
- package/cjs/claiming/uniswap.d.ts +2 -2
- package/cjs/claiming/uniswap.js +3 -2
- package/cjs/compoundV2/index.d.ts +4 -4
- package/cjs/compoundV2/index.js +9 -9
- package/cjs/compoundV3/index.d.ts +5 -4
- package/cjs/compoundV3/index.js +17 -13
- package/cjs/compoundV3/merkl.d.ts +1 -1
- package/cjs/compoundV3/merkl.js +2 -5
- package/cjs/curveUsd/index.d.ts +5 -5
- package/cjs/curveUsd/index.js +17 -17
- package/cjs/fluid/index.d.ts +23 -66
- package/cjs/fluid/index.js +75 -72
- package/cjs/fluid/merkl.d.ts +5 -3
- package/cjs/fluid/merkl.js +11 -6
- package/cjs/helpers/aaveHelpers/index.js +1 -1
- package/cjs/helpers/aaveV4Helpers/index.js +14 -2
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/helpers/curveUsdHelpers/index.js +1 -1
- package/cjs/helpers/fluidHelpers/index.js +1 -1
- package/cjs/helpers/liquityV2Helpers/index.js +1 -1
- package/cjs/helpers/llamaLendHelpers/index.js +1 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
- package/cjs/helpers/morphoMidnightHelpers/index.js +1 -1
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/liquity/index.d.ts +5 -15
- package/cjs/liquity/index.js +23 -23
- package/cjs/liquityV2/index.d.ts +16 -31
- package/cjs/liquityV2/index.js +96 -78
- package/cjs/llamaLend/index.d.ts +5 -5
- package/cjs/llamaLend/index.js +13 -13
- package/cjs/maker/index.d.ts +6 -6
- package/cjs/maker/index.js +16 -16
- package/cjs/moneymarket/moneymarketCommonService.js +13 -2
- package/cjs/morphoBlue/index.d.ts +7 -7
- package/cjs/morphoBlue/index.js +28 -26
- package/cjs/morphoBlue/merkl.d.ts +5 -3
- package/cjs/morphoBlue/merkl.js +6 -8
- package/cjs/morphoMidnight/index.d.ts +5 -5
- package/cjs/morphoMidnight/index.js +18 -18
- package/cjs/portfolio/customDeFiData.d.ts +3 -0
- package/cjs/portfolio/customDeFiData.js +267 -0
- package/cjs/portfolio/index.d.ts +17 -8
- package/cjs/portfolio/index.js +459 -520
- package/cjs/portfolio/lendingProtocols.d.ts +184 -0
- package/cjs/portfolio/lendingProtocols.js +196 -0
- package/cjs/savings/index.d.ts +8 -2
- package/cjs/savings/index.js +33 -4
- package/cjs/services/merkl.d.ts +46 -2
- package/cjs/services/merkl.js +190 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -2
- package/cjs/services/viem.js +27 -1
- package/cjs/spark/index.d.ts +4 -4
- package/cjs/spark/index.js +9 -9
- package/cjs/types/aave.d.ts +98 -2
- package/cjs/types/aaveV4.d.ts +45 -0
- package/cjs/types/common.d.ts +1 -0
- package/cjs/types/common.js +1 -0
- package/cjs/types/compound.d.ts +26 -2
- package/cjs/types/curveUsd.d.ts +9 -1
- package/cjs/types/fluid.d.ts +13 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquity.d.ts +12 -0
- package/cjs/types/liquityV2.d.ts +24 -0
- package/cjs/types/llamaLend.d.ts +12 -1
- package/cjs/types/merkl.d.ts +18 -0
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/portfolio.d.ts +162 -5
- package/cjs/types/portfolio.js +18 -0
- package/cjs/types/savings/index.d.ts +9 -1
- package/cjs/types/spark.d.ts +21 -1
- package/cjs/umbrella/index.d.ts +3 -4
- package/cjs/umbrella/index.js +5 -4
- package/esm/aaveV2/index.d.ts +4 -4
- package/esm/aaveV2/index.js +8 -8
- package/esm/aaveV3/index.d.ts +5 -14
- package/esm/aaveV3/index.js +15 -11
- package/esm/aaveV3/merkl.d.ts +5 -1
- package/esm/aaveV3/merkl.js +9 -4
- package/esm/aaveV3/sgho.d.ts +2 -16
- package/esm/aaveV4/index.d.ts +4 -3
- package/esm/aaveV4/index.js +20 -17
- package/esm/aaveV4/lend.d.ts +2 -43
- package/esm/aaveV4/merkl.d.ts +10 -2
- package/esm/aaveV4/merkl.js +16 -7
- package/esm/claiming/aaveV3.d.ts +3 -3
- package/esm/claiming/aaveV3.js +6 -5
- package/esm/claiming/ethena.d.ts +2 -1
- package/esm/claiming/king.d.ts +3 -2
- package/esm/claiming/king.js +3 -2
- package/esm/claiming/spark.d.ts +4 -4
- package/esm/claiming/spark.js +9 -8
- package/esm/claiming/uniswap.d.ts +2 -2
- package/esm/claiming/uniswap.js +3 -2
- package/esm/compoundV2/index.d.ts +4 -4
- package/esm/compoundV2/index.js +9 -9
- package/esm/compoundV3/index.d.ts +5 -4
- package/esm/compoundV3/index.js +19 -15
- package/esm/compoundV3/merkl.d.ts +1 -1
- package/esm/compoundV3/merkl.js +3 -6
- package/esm/curveUsd/index.d.ts +5 -5
- package/esm/curveUsd/index.js +17 -17
- package/esm/fluid/index.d.ts +23 -66
- package/esm/fluid/index.js +76 -73
- package/esm/fluid/merkl.d.ts +5 -3
- package/esm/fluid/merkl.js +12 -7
- package/esm/helpers/aaveHelpers/index.js +1 -1
- package/esm/helpers/aaveV4Helpers/index.js +15 -3
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/curveUsdHelpers/index.js +1 -1
- package/esm/helpers/fluidHelpers/index.js +1 -1
- package/esm/helpers/liquityV2Helpers/index.js +1 -1
- package/esm/helpers/llamaLendHelpers/index.js +1 -1
- package/esm/helpers/morphoBlueHelpers/index.js +1 -1
- package/esm/helpers/morphoMidnightHelpers/index.js +1 -1
- package/esm/helpers/sparkHelpers/index.js +1 -1
- package/esm/liquity/index.d.ts +5 -15
- package/esm/liquity/index.js +23 -23
- package/esm/liquityV2/index.d.ts +16 -31
- package/esm/liquityV2/index.js +95 -78
- package/esm/llamaLend/index.d.ts +5 -5
- package/esm/llamaLend/index.js +13 -13
- package/esm/maker/index.d.ts +6 -6
- package/esm/maker/index.js +16 -16
- package/esm/moneymarket/moneymarketCommonService.js +13 -2
- package/esm/morphoBlue/index.d.ts +7 -7
- package/esm/morphoBlue/index.js +29 -27
- package/esm/morphoBlue/merkl.d.ts +5 -3
- package/esm/morphoBlue/merkl.js +7 -9
- package/esm/morphoMidnight/index.d.ts +5 -5
- package/esm/morphoMidnight/index.js +18 -18
- package/esm/portfolio/customDeFiData.d.ts +3 -0
- package/esm/portfolio/customDeFiData.js +261 -0
- package/esm/portfolio/index.d.ts +17 -8
- package/esm/portfolio/index.js +459 -522
- package/esm/portfolio/lendingProtocols.d.ts +184 -0
- package/esm/portfolio/lendingProtocols.js +189 -0
- package/esm/savings/index.d.ts +8 -2
- package/esm/savings/index.js +31 -3
- package/esm/services/merkl.d.ts +46 -2
- package/esm/services/merkl.js +180 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -2
- package/esm/services/viem.js +25 -0
- package/esm/spark/index.d.ts +4 -4
- package/esm/spark/index.js +10 -10
- package/esm/types/aave.d.ts +98 -2
- package/esm/types/aaveV4.d.ts +45 -0
- package/esm/types/common.d.ts +1 -0
- package/esm/types/common.js +1 -0
- package/esm/types/compound.d.ts +26 -2
- package/esm/types/curveUsd.d.ts +9 -1
- package/esm/types/fluid.d.ts +13 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquity.d.ts +12 -0
- package/esm/types/liquityV2.d.ts +24 -0
- package/esm/types/llamaLend.d.ts +12 -1
- package/esm/types/merkl.d.ts +18 -0
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/portfolio.d.ts +162 -5
- package/esm/types/portfolio.js +17 -1
- package/esm/types/savings/index.d.ts +9 -1
- package/esm/types/spark.d.ts +21 -1
- package/esm/umbrella/index.d.ts +3 -4
- package/esm/umbrella/index.js +5 -4
- package/package.json +1 -1
- package/src/aaveV2/index.ts +7 -7
- package/src/aaveV3/index.ts +16 -11
- package/src/aaveV3/merkl.ts +9 -4
- package/src/aaveV3/sgho.ts +2 -17
- package/src/aaveV4/index.ts +19 -16
- package/src/aaveV4/lend.ts +2 -48
- package/src/aaveV4/merkl.ts +16 -7
- package/src/claiming/aaveV3.ts +9 -5
- package/src/claiming/ethena.ts +5 -5
- package/src/claiming/king.ts +8 -5
- package/src/claiming/spark.ts +15 -10
- package/src/claiming/uniswap.ts +4 -3
- package/src/compoundV2/index.ts +10 -9
- package/src/compoundV3/index.ts +20 -14
- package/src/compoundV3/merkl.ts +5 -4
- package/src/curveUsd/index.ts +19 -17
- package/src/fluid/index.ts +91 -72
- package/src/fluid/merkl.ts +12 -7
- package/src/helpers/aaveHelpers/index.ts +1 -1
- package/src/helpers/aaveV4Helpers/index.ts +16 -2
- package/src/helpers/compoundHelpers/index.ts +2 -2
- package/src/helpers/curveUsdHelpers/index.ts +1 -1
- package/src/helpers/fluidHelpers/index.ts +1 -1
- package/src/helpers/liquityV2Helpers/index.ts +1 -1
- package/src/helpers/llamaLendHelpers/index.ts +1 -1
- package/src/helpers/morphoBlueHelpers/index.ts +1 -1
- package/src/helpers/morphoMidnightHelpers/index.ts +1 -1
- package/src/helpers/sparkHelpers/index.ts +1 -1
- package/src/liquity/index.ts +24 -24
- package/src/liquityV2/index.ts +110 -76
- package/src/llamaLend/index.ts +15 -13
- package/src/maker/index.ts +19 -16
- package/src/moneymarket/moneymarketCommonService.ts +14 -2
- package/src/morphoBlue/index.ts +23 -20
- package/src/morphoBlue/merkl.ts +9 -6
- package/src/morphoMidnight/index.ts +13 -13
- package/src/portfolio/customDeFiData.ts +385 -0
- package/src/portfolio/index.ts +307 -331
- package/src/portfolio/lendingProtocols.ts +281 -0
- package/src/savings/index.ts +41 -4
- package/src/services/merkl.ts +209 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +16 -0
- package/src/spark/index.ts +11 -8
- package/src/types/aave.ts +104 -1
- package/src/types/aaveV4.ts +50 -0
- package/src/types/common.ts +1 -0
- package/src/types/compound.ts +38 -2
- package/src/types/curveUsd.ts +17 -1
- package/src/types/fluid.ts +14 -0
- package/src/types/index.ts +1 -0
- package/src/types/liquity.ts +13 -1
- package/src/types/liquityV2.ts +26 -1
- package/src/types/llamaLend.ts +19 -1
- package/src/types/merkl.ts +20 -0
- package/src/types/morphoBlue.ts +3 -0
- package/src/types/portfolio.ts +191 -5
- package/src/types/savings/index.ts +12 -1
- package/src/types/spark.ts +25 -1
- package/src/umbrella/index.ts +7 -5
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getCustomDeFiData = getCustomDeFiData;
|
|
16
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
|
+
const common_1 = require("../types/common");
|
|
18
|
+
const markets_1 = require("../markets");
|
|
19
|
+
const types_1 = require("../types");
|
|
20
|
+
const viem_1 = require("../services/viem");
|
|
21
|
+
const constants_1 = require("../constants");
|
|
22
|
+
const aaveV2_1 = require("../aaveV2");
|
|
23
|
+
const aaveV3_1 = require("../aaveV3");
|
|
24
|
+
const aaveV4_1 = require("../aaveV4");
|
|
25
|
+
const compoundV2_1 = require("../compoundV2");
|
|
26
|
+
const compoundV3_1 = require("../compoundV3");
|
|
27
|
+
const spark_1 = require("../spark");
|
|
28
|
+
const curveUsd_1 = require("../curveUsd");
|
|
29
|
+
const llamaLend_1 = require("../llamaLend");
|
|
30
|
+
const morphoBlue_1 = require("../morphoBlue");
|
|
31
|
+
const morphoMidnight_1 = require("../morphoMidnight");
|
|
32
|
+
const maker_1 = require("../maker");
|
|
33
|
+
const liquity_1 = require("../liquity");
|
|
34
|
+
const liquityV2_1 = require("../liquityV2");
|
|
35
|
+
const fluid_1 = require("../fluid");
|
|
36
|
+
const umbrella_1 = require("../umbrella");
|
|
37
|
+
const aaveV3_2 = require("../claiming/aaveV3");
|
|
38
|
+
const spark_2 = require("../claiming/spark");
|
|
39
|
+
const king_1 = require("../claiming/king");
|
|
40
|
+
const ethena_1 = require("../claiming/ethena");
|
|
41
|
+
const uniswap_1 = require("../claiming/uniswap");
|
|
42
|
+
const lower = (address) => address.toLowerCase();
|
|
43
|
+
const positive = (value) => new decimal_js_1.default(value || '0').gt(0);
|
|
44
|
+
const supported = (list, network) => (Object.values(list).filter((m) => m.chainIds.includes(network)));
|
|
45
|
+
function getCustomDeFiData(provider_1, network_1, defaultProvider_1, addresses_1) {
|
|
46
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, options = {}) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const { protocols = Object.values(types_1.PortfolioProtocol), fetchStaking = false, fetchRewards = false, returnEmptyEModePositions = false, fetchFluidMarkets = false, isSim = false, } = options;
|
|
49
|
+
// JSON-RPC body ends up ~4x the calldata cap; 250k keeps it under the ~2.5MB provider limit.
|
|
50
|
+
const batchSize = (_a = options.batchSize) !== null && _a !== void 0 ? _a : (isSim ? 2000 : 250000);
|
|
51
|
+
const has = (protocol) => protocols.includes(protocol);
|
|
52
|
+
const isMainnet = network === common_1.NetworkNumber.Eth;
|
|
53
|
+
const isFluidSupported = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Base, common_1.NetworkNumber.Plasma].includes(network);
|
|
54
|
+
const client = (0, viem_1.getViemProvider)(provider, network, { batch: { multicall: { batchSize } } });
|
|
55
|
+
const defaultClient = (0, viem_1.getViemProvider)(defaultProvider, network, { batch: { multicall: { batchSize } } });
|
|
56
|
+
// Every fetch below takes the block explicitly and passes it to each of its contract reads.
|
|
57
|
+
// Time-keyed sources (Merkl rewards) need the block's timestamp instead, resolved once here (no
|
|
58
|
+
// RPC call for 'latest') and handed to the market fetches so they don't each look it up.
|
|
59
|
+
const blockNumber = (_b = options.blockNumber) !== null && _b !== void 0 ? _b : 'latest';
|
|
60
|
+
const blockTimestamp = yield (0, viem_1.getBlockTimestamp)(client, blockNumber);
|
|
61
|
+
const aaveV3Markets = has(types_1.PortfolioProtocol.AaveV3)
|
|
62
|
+
? [types_1.AaveVersions.AaveV3, types_1.AaveVersions.AaveV3Lido, types_1.AaveVersions.AaveV3Etherfi].map((v) => (0, markets_1.AaveMarkets)(network)[v]).filter((m) => m.chainIds.includes(network))
|
|
63
|
+
: [];
|
|
64
|
+
const aaveV2Markets = has(types_1.PortfolioProtocol.AaveV2) ? [(0, markets_1.AaveMarkets)(network)[types_1.AaveVersions.AaveV2]].filter((m) => m.chainIds.includes(network)) : [];
|
|
65
|
+
const aaveV4Spokes = has(types_1.PortfolioProtocol.AaveV4) ? supported((0, markets_1.AaveV4Spokes)(network), network) : [];
|
|
66
|
+
const compoundV3Markets = has(types_1.PortfolioProtocol.CompoundV3) ? supported((0, markets_1.CompoundMarkets)(network), network).filter((m) => m.value !== types_1.CompoundVersions.CompoundV2) : [];
|
|
67
|
+
const compoundV2Markets = has(types_1.PortfolioProtocol.CompoundV2) ? [(0, markets_1.CompoundMarkets)(network)[types_1.CompoundVersions.CompoundV2]].filter((m) => m.chainIds.includes(network)) : [];
|
|
68
|
+
const sparkMarkets = has(types_1.PortfolioProtocol.Spark) ? supported((0, markets_1.SparkMarkets)(network), network) : [];
|
|
69
|
+
const morphoMarkets = has(types_1.PortfolioProtocol.MorphoBlue) ? supported((0, markets_1.MorphoBlueMarkets)(network), network) : [];
|
|
70
|
+
const morphoMidnightMarkets = has(types_1.PortfolioProtocol.MorphoMidnight) ? supported((0, markets_1.MorphoMidnightMarkets)(network), network) : [];
|
|
71
|
+
const crvUsdMarkets = has(types_1.PortfolioProtocol.CrvUsd) ? supported((0, markets_1.CrvUsdMarkets)(network), network) : [];
|
|
72
|
+
const llamaLendMarkets = has(types_1.PortfolioProtocol.LlamaLend) && [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb].includes(network) ? supported((0, markets_1.LlamaLendMarkets)(network), network) : [];
|
|
73
|
+
const liquityV2Markets = has(types_1.PortfolioProtocol.LiquityV2) && isMainnet ? Object.values((0, markets_1.LiquityV2Markets)(network)) : [];
|
|
74
|
+
const liquityV2StakingMarkets = liquityV2Markets.filter((m) => !m.isLegacy);
|
|
75
|
+
const fetchMaker = has(types_1.PortfolioProtocol.Maker) && isMainnet;
|
|
76
|
+
const fetchLiquity = has(types_1.PortfolioProtocol.Liquity) && isMainnet;
|
|
77
|
+
const fetchFluid = has(types_1.PortfolioProtocol.Fluid) && isFluidSupported;
|
|
78
|
+
const markets = {
|
|
79
|
+
morphoMarketsData: {},
|
|
80
|
+
morphoMidnightMarketsData: {},
|
|
81
|
+
compoundV3MarketsData: {},
|
|
82
|
+
sparkMarketsData: {},
|
|
83
|
+
aaveV3MarketsData: {},
|
|
84
|
+
aaveV2MarketsData: {},
|
|
85
|
+
compoundV2MarketsData: {},
|
|
86
|
+
crvUsdMarketsData: {},
|
|
87
|
+
llamaLendMarketsData: {},
|
|
88
|
+
liquityV2MarketsData: {},
|
|
89
|
+
aaveV4SpokesData: {},
|
|
90
|
+
fluidMarketsData: {},
|
|
91
|
+
makerMarketsData: {},
|
|
92
|
+
};
|
|
93
|
+
const makerCdps = {};
|
|
94
|
+
const positions = {};
|
|
95
|
+
const stakingPositions = {};
|
|
96
|
+
const rewardsData = {};
|
|
97
|
+
for (const address of addresses) {
|
|
98
|
+
positions[lower(address)] = {
|
|
99
|
+
aaveV3: {},
|
|
100
|
+
aaveV4: {},
|
|
101
|
+
morphoBlue: {},
|
|
102
|
+
morphoMidnight: {},
|
|
103
|
+
compoundV3: {},
|
|
104
|
+
spark: {},
|
|
105
|
+
maker: {},
|
|
106
|
+
aaveV2: {},
|
|
107
|
+
compoundV2: {},
|
|
108
|
+
liquity: {},
|
|
109
|
+
crvUsd: {},
|
|
110
|
+
llamaLend: {},
|
|
111
|
+
fluid: { error: '', data: {} },
|
|
112
|
+
};
|
|
113
|
+
if (fetchStaking) {
|
|
114
|
+
stakingPositions[lower(address)] = {
|
|
115
|
+
aaveV3: {}, morphoBlue: {}, liquity: {}, liquityV2: {}, fluid: { error: '', data: {} },
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (fetchRewards) {
|
|
119
|
+
rewardsData[lower(address)] = {
|
|
120
|
+
merkl: {}, aaveV3: {}, spark: {}, spk: {}, king: {}, ethena: {}, uniswap: {},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const run = (label, fetch, store, onError) => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
try {
|
|
126
|
+
store(yield fetch());
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error(`Error fetching ${label}:`, error);
|
|
130
|
+
onError({ error: `Error fetching ${label}`, data: null });
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const perAddress = (list, task) => list.map((m) => addresses.map((a) => task(m, a))).flat();
|
|
134
|
+
const batchRewards = (key, label, fetch, enabled = true) => (() => __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
if (!enabled) {
|
|
136
|
+
for (const address of addresses)
|
|
137
|
+
rewardsData[lower(address)][key] = { error: '', data: [] };
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const result = yield fetch();
|
|
142
|
+
for (const address of addresses)
|
|
143
|
+
rewardsData[lower(address)][key] = { error: '', data: result[lower(address)] || [] };
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error(`Error fetching ${label}:`, error);
|
|
147
|
+
for (const address of addresses)
|
|
148
|
+
rewardsData[lower(address)][key] = { error: `Error fetching ${label}`, data: null };
|
|
149
|
+
}
|
|
150
|
+
}))();
|
|
151
|
+
yield Promise.allSettled([
|
|
152
|
+
...morphoMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.morphoMarketsData[m.value] = yield (0, morphoBlue_1._getMorphoBluePortfolioMarketData)(client, network, m, blockNumber); })),
|
|
153
|
+
...morphoMidnightMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.morphoMidnightMarketsData[m.value] = yield (0, morphoMidnight_1._getMorphoMidnightMarketData)(client, network, m, blockNumber); })),
|
|
154
|
+
...compoundV3Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.compoundV3MarketsData[m.value] = yield (0, compoundV3_1._getCompoundV3MarketsData)(client, network, m, defaultClient, blockNumber, blockTimestamp); })),
|
|
155
|
+
...sparkMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.sparkMarketsData[m.value] = yield (0, spark_1._getSparkMarketsData)(client, network, m, blockNumber); })),
|
|
156
|
+
...aaveV3Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.aaveV3MarketsData[m.value] = yield (0, aaveV3_1._getAaveV3MarketData)(client, network, m, blockNumber, blockTimestamp); })),
|
|
157
|
+
...aaveV4Spokes.map((s) => __awaiter(this, void 0, void 0, function* () { markets.aaveV4SpokesData[s.value] = yield (0, aaveV4_1._getAaveV4SpokeData)(client, network, s, blockNumber, blockTimestamp); })),
|
|
158
|
+
...aaveV2Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.aaveV2MarketsData[m.value] = yield (0, aaveV2_1._getAaveV2MarketsData)(client, network, m, blockNumber); })),
|
|
159
|
+
...compoundV2Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.compoundV2MarketsData[m.value] = yield (0, compoundV2_1._getCompoundV2MarketsData)(client, network, blockNumber); })),
|
|
160
|
+
...crvUsdMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.crvUsdMarketsData[m.value] = yield (0, curveUsd_1._getCurveUsdGlobalData)(client, network, m, blockNumber); })),
|
|
161
|
+
...llamaLendMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.llamaLendMarketsData[m.value] = yield (0, llamaLend_1._getLlamaLendGlobalData)(client, network, m, blockNumber); })),
|
|
162
|
+
...liquityV2Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.liquityV2MarketsData[m.value] = yield (0, liquityV2_1._getLiquityV2MarketData)(client, network, m, blockNumber); })),
|
|
163
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
if (!fetchFluid || !fetchFluidMarkets)
|
|
165
|
+
return;
|
|
166
|
+
try {
|
|
167
|
+
markets.fluidMarketsData = yield (0, fluid_1._getAllFluidMarketDataPortfolio)(client, network, blockNumber, blockTimestamp);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.error('Error fetching Fluid markets data:', error);
|
|
171
|
+
}
|
|
172
|
+
}))(),
|
|
173
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
if (!fetchMaker)
|
|
175
|
+
return;
|
|
176
|
+
try {
|
|
177
|
+
markets.makerMarketsData = yield (0, maker_1._getMakerIlksData)(client, network, markets_1.MakerActiveIlks, blockNumber);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error('Error fetching Maker ilks data:', error);
|
|
181
|
+
}
|
|
182
|
+
}))(),
|
|
183
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
if (!fetchMaker)
|
|
185
|
+
return;
|
|
186
|
+
makerCdps[lower(address)] = yield (0, maker_1._getUserCdps)(client, network, address, blockNumber);
|
|
187
|
+
})),
|
|
188
|
+
...addresses.map((address) => fetchFluid && run(`Fluid positions for address ${address}`, () => (0, fluid_1._getUserPositionsPortfolio)(client, network, address, blockNumber), (userPositions) => {
|
|
189
|
+
for (const position of userPositions) {
|
|
190
|
+
if (position.userData && positive(position.userData.suppliedUsd))
|
|
191
|
+
positions[lower(address)].fluid.data[position.userData.nftId] = position.userData;
|
|
192
|
+
}
|
|
193
|
+
}, (err) => { positions[lower(address)].fluid = { error: err.error, data: {} }; })),
|
|
194
|
+
...(fetchStaking ? [
|
|
195
|
+
...addresses.map((address) => fetchFluid && run(`Fluid lend data for address ${address}`, () => (0, fluid_1._getAllUserEarnPositionsWithFTokens)(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].fluid = data; }, (err) => { stakingPositions[lower(address)].fluid = err; })),
|
|
196
|
+
...addresses.map((address) => fetchLiquity && run(`Liquity staking data for address ${address}`, () => (0, liquity_1.getLiquityStakingData)(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].liquity = data; }, (err) => { stakingPositions[lower(address)].liquity = err; })),
|
|
197
|
+
...addresses.map((address) => has(types_1.PortfolioProtocol.AaveV3) && isMainnet && run(`Aave V3 staking data for address ${address}`, () => (0, aaveV3_1.getStakeAaveData)(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].aaveV3 = data; }, (err) => { stakingPositions[lower(address)].aaveV3 = err; })),
|
|
198
|
+
...addresses.map((address) => has(types_1.PortfolioProtocol.AaveV3) && isMainnet && run(`Umbrella staking data for address ${address}`, () => (0, umbrella_1.getUmbrellaData)(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].umbrella = data; }, (err) => { stakingPositions[lower(address)].umbrella = err; })),
|
|
199
|
+
...perAddress(liquityV2StakingMarkets, (market, address) => run(`Liquity V2 staking data for address ${address}, market ${market.value}`, () => (0, liquityV2_1.getLiquityV2Staking)(client, network, market.value, address, blockNumber), (data) => { stakingPositions[lower(address)].liquityV2[market.value] = { error: '', data }; }, (err) => { stakingPositions[lower(address)].liquityV2[market.value] = err; })),
|
|
200
|
+
] : []),
|
|
201
|
+
...(fetchRewards ? [
|
|
202
|
+
batchRewards('king', 'King rewards data', () => (0, king_1.getKingRewards)(client, network, addresses, blockNumber), isMainnet),
|
|
203
|
+
batchRewards('uniswap', 'Uniswap rewards data', () => (0, uniswap_1.getUniswapRewards)(client, network, addresses, blockNumber), isMainnet),
|
|
204
|
+
batchRewards('spk', 'Spark Airdrop rewards data', () => (0, spark_2.fetchSparkAirdropRewards)(client, network, addresses, blockNumber), isMainnet && has(types_1.PortfolioProtocol.Spark)),
|
|
205
|
+
batchRewards('ethena', 'Ethena Airdrop rewards data', () => (0, ethena_1.fetchEthenaAirdropRewards)(addresses), isMainnet),
|
|
206
|
+
...addresses.map((address) => run(`Merkl rewards data for address ${address}`, () => (0, aaveV3_2.getMerklUnclaimedRewards)(address, network), (data) => { rewardsData[lower(address)].merkl = { error: '', data }; }, (err) => { rewardsData[lower(address)].merkl = err; })),
|
|
207
|
+
...perAddress(aaveV3Markets, (market, address) => run(`Aave V3 rewards data for address ${address}, market ${market.value}`, () => (0, aaveV3_2.getUnclaimedRewardsForAllMarkets)(client, network, address, market.providerAddress, blockNumber), (data) => { rewardsData[lower(address)].aaveV3[market.value] = { error: '', data }; }, (err) => { rewardsData[lower(address)].aaveV3[market.value] = err; })),
|
|
208
|
+
...perAddress(sparkMarkets, (market, address) => {
|
|
209
|
+
if (!isMainnet) {
|
|
210
|
+
rewardsData[lower(address)].spark[market.value] = { error: '', data: [] };
|
|
211
|
+
return Promise.resolve();
|
|
212
|
+
}
|
|
213
|
+
return run(`Spark rewards data for address ${address}, market ${market.value}`, () => (0, spark_2.fetchSparkRewards)(client, network, address, market.providerAddress, blockNumber), (data) => { rewardsData[lower(address)].spark[market.value] = { error: '', data }; }, (err) => { rewardsData[lower(address)].spark[market.value] = err; });
|
|
214
|
+
}),
|
|
215
|
+
] : []),
|
|
216
|
+
]);
|
|
217
|
+
yield Promise.all([
|
|
218
|
+
...perAddress(aaveV3Markets, (market, address) => run(`AaveV3 account data for address ${address} on market ${market.value}`, () => (0, aaveV3_1._getAaveV3AccountData)(client, network, address, Object.assign({ selectedMarket: market }, markets.aaveV3MarketsData[market.value]), blockNumber), (data) => { if (returnEmptyEModePositions || positive(data.suppliedUsd))
|
|
219
|
+
positions[lower(address)].aaveV3[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].aaveV3[market.value] = err; })),
|
|
220
|
+
...perAddress(sparkMarkets, (market, address) => run(`Spark account data for address ${address} on market ${market.value}`, () => (0, spark_1._getSparkAccountData)(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData }, blockNumber), (data) => { if (returnEmptyEModePositions || positive(data.suppliedUsd))
|
|
221
|
+
positions[lower(address)].spark[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].spark[market.value] = err; })),
|
|
222
|
+
...perAddress(aaveV4Spokes, (spoke, address) => run(`AaveV4 account data for address ${address} on spoke ${spoke.value}`, () => (0, aaveV4_1._getAaveV4AccountData)(client, network, markets.aaveV4SpokesData[spoke.value], address, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
223
|
+
positions[lower(address)].aaveV4[spoke.value] = { error: '', data }; }, (err) => { positions[lower(address)].aaveV4[spoke.value] = err; })),
|
|
224
|
+
...perAddress(morphoMarkets, (market, address) => run(`MorphoBlue account data for address ${address} on market ${market.value}`, () => (0, morphoBlue_1._getMorphoBlueAccountData)(client, network, address, market, markets.morphoMarketsData[market.value], blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
225
|
+
positions[lower(address)].morphoBlue[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].morphoBlue[market.value] = err; })),
|
|
226
|
+
...(fetchStaking ? perAddress(morphoMarkets, (market, address) => run(`MorphoBlue earn data for address ${address} on market ${market.value}`, () => (0, morphoBlue_1.getMorphoEarn)(client, network, address, market, markets.morphoMarketsData[market.value], blockNumber), (data) => { if (data && positive(data.amount))
|
|
227
|
+
stakingPositions[lower(address)].morphoBlue[market.value] = { error: '', data }; }, (err) => { stakingPositions[lower(address)].morphoBlue[market.value] = err; })) : []),
|
|
228
|
+
...perAddress(morphoMidnightMarkets, (market, address) => {
|
|
229
|
+
var _a;
|
|
230
|
+
if (!((_a = markets.morphoMidnightMarketsData[market.value]) === null || _a === void 0 ? void 0 : _a.isCreated))
|
|
231
|
+
return Promise.resolve();
|
|
232
|
+
return run(`MorphoMidnight account data for address ${address} on market ${market.value}`, () => (0, morphoMidnight_1._getMorphoMidnightAccountData)(client, network, address, market, markets.morphoMidnightMarketsData[market.value], blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
233
|
+
positions[lower(address)].morphoMidnight[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].morphoMidnight[market.value] = err; });
|
|
234
|
+
}),
|
|
235
|
+
...perAddress(compoundV3Markets, (market, address) => run(`CompoundV3 account data for address ${address} on market ${market.value}`, () => (0, compoundV3_1._getCompoundV3AccountData)(client, network, address, constants_1.ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData }, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
236
|
+
positions[lower(address)].compoundV3[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].compoundV3[market.value] = err; })),
|
|
237
|
+
...perAddress(compoundV2Markets, (market, address) => run(`CompoundV2 account data for address ${address}`, () => (0, compoundV2_1._getCompoundV2AccountData)(client, network, address, markets.compoundV2MarketsData[market.value].assetsData, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
238
|
+
positions[lower(address)].compoundV2[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].compoundV2[market.value] = err; })),
|
|
239
|
+
...perAddress(aaveV2Markets, (market, address) => run(`AaveV2 account data for address ${address}`, () => (0, aaveV2_1._getAaveV2AccountData)(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
240
|
+
positions[lower(address)].aaveV2[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].aaveV2[market.value] = err; })),
|
|
241
|
+
...perAddress(crvUsdMarkets, (market, address) => run(`Curve USD account data for address ${address} on market ${market.value}`, () => (0, curveUsd_1._getCurveUsdUserData)(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate, blockNumber), (data) => { if (positive(data.suppliedUsd) || positive(data.borrowedUsd))
|
|
242
|
+
positions[lower(address)].crvUsd[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].crvUsd[market.value] = err; })),
|
|
243
|
+
...perAddress(llamaLendMarkets, (market, address) => run(`LlamaLend account data for address ${address} on market ${market.value}`, () => (0, llamaLend_1._getLlamaLendUserData)(client, network, address, market, markets.llamaLendMarketsData[market.value], blockNumber), (data) => {
|
|
244
|
+
if (positive(data.suppliedUsd) || positive(data.borrowedUsd)) {
|
|
245
|
+
positions[lower(address)].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, data), { borrowRate: markets.llamaLendMarketsData[market.value].borrowRate }) };
|
|
246
|
+
}
|
|
247
|
+
}, (err) => { positions[lower(address)].llamaLend[market.value] = err; })),
|
|
248
|
+
...addresses.map((address) => (makerCdps[lower(address)] || []).map((cdpInfo) => run(`Maker CDP data for address ${address} with ID ${cdpInfo.id}`, () => (0, maker_1._getMakerCdpData)(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel], blockNumber), (data) => { if (data)
|
|
249
|
+
positions[lower(address)].maker[cdpInfo.id] = { error: '', data }; }, (err) => { positions[lower(address)].maker[cdpInfo.id] = err; }))).flat(),
|
|
250
|
+
...addresses.map((address) => fetchLiquity && run(`Liquity trove info for address ${address}`, () => (0, liquity_1._getLiquityTroveInfo)(client, network, address, blockNumber), (data) => { if (positive(data.collateral))
|
|
251
|
+
positions[lower(address)].liquity = { error: '', data }; }, (err) => { positions[lower(address)].liquity = err; })),
|
|
252
|
+
...(fetchStaking && has(types_1.PortfolioProtocol.LiquityV2) ? addresses.map((address) => {
|
|
253
|
+
if (!isMainnet) {
|
|
254
|
+
stakingPositions[lower(address)].liquityV2SBoldYBold = { error: '', data: null };
|
|
255
|
+
return Promise.resolve();
|
|
256
|
+
}
|
|
257
|
+
return run(`sBold/yBold data for address ${address}`, () => (0, liquityV2_1.getLiquitySAndYBold)(client, network, stakingPositions[lower(address)].liquityV2, address, blockNumber), (data) => { stakingPositions[lower(address)].liquityV2SBoldYBold = { error: '', data }; }, (err) => { stakingPositions[lower(address)].liquityV2SBoldYBold = err; });
|
|
258
|
+
}) : []),
|
|
259
|
+
]);
|
|
260
|
+
return {
|
|
261
|
+
positions,
|
|
262
|
+
stakingPositions,
|
|
263
|
+
rewardsData,
|
|
264
|
+
markets,
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
}
|
package/cjs/portfolio/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
-
import { PortfolioMarketsData, PortfolioPositionsData } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { PortfolioData, PortfolioDataOptions, PortfolioMarketsData, PortfolioMarketsResult, PortfolioPositionsData, PortfolioUserData, ShifterPortfolioMarketsData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Every market the portfolio reads on a network — the markets half of getPortfolioData, for a caller that keeps
|
|
5
|
+
* markets apart from what it reads per address (a cache shared by many addresses). A market that fails is left out
|
|
6
|
+
* of `markets` and named in `errors`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPortfolioMarketsData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, isSim?: boolean): Promise<PortfolioMarketsResult>;
|
|
9
|
+
/**
|
|
10
|
+
* What the portfolio reads per address — the other half of getPortfolioData — against `markets` from
|
|
11
|
+
* getPortfolioMarketsData. `markets` can be a promise: reads that do not need a market (Maker, Fluid, Liquity, staking,
|
|
12
|
+
* rewards) start at once, and each read on a market waits for it. A position on a market missing from `markets` is an
|
|
13
|
+
* entry with an error.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPortfolioUserData(provider: EthereumProvider, network: NetworkNumber, addresses: EthAddress[], markets: PortfolioMarketsData | Promise<PortfolioMarketsData>, isSim?: boolean, options?: PortfolioDataOptions): Promise<PortfolioUserData>;
|
|
16
|
+
export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean, options?: PortfolioDataOptions): Promise<PortfolioData>;
|
|
9
17
|
export declare function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
|
|
10
18
|
positions: PortfolioPositionsData;
|
|
11
|
-
markets:
|
|
19
|
+
markets: ShifterPortfolioMarketsData;
|
|
12
20
|
}>;
|
|
13
21
|
export * from './discovery';
|
|
22
|
+
export * from './customDeFiData';
|
|
14
23
|
export { getWalletLendingSummaries } from './lendingSummaries';
|