@moonwell-fi/moonwell-sdk
Version:
TypeScript Interface for Moonwell
62 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAccountMarketPortfolio = getAccountMarketPortfolio;
const lunarIndexerTransform_js_1 = require("./lunarIndexerTransform.js");
async function getAccountMarketPortfolio(client, args) {
let environment;
const environments = Object.values(client.environments);
if (args.chainId) {
environment = environments.find((env) => env.chainId === args.chainId);
}
else if (args.network && typeof args.network === "string") {
const envValue = client.environments[args.network];
if (envValue) {
environment = envValue;
}
}
else {
environment = environments.find((env) => env.lunarIndexerUrl);
}
if (!environment) {
throw new Error("Environment not found");
}
const lunarIndexerUrl = environment.lunarIndexerUrl;
if (!lunarIndexerUrl) {
throw new Error("Lunar Indexer URL not configured for this environment. Account market portfolio requires lunar-indexer.");
}
const options = {
startTime: args.startTime,
endTime: args.endTime,
};
if (args.chainId !== undefined) {
options.chainId = args.chainId;
}
if (args.marketId !== undefined) {
options.marketId = args.marketId;
}
if (args.granularity !== undefined) {
options.granularity = args.granularity;
}
const response = await (0, lunarIndexerTransform_js_1.fetchAccountMarketPortfolioFromIndexer)(lunarIndexerUrl, args.accountAddress, options);
const { morphoMarkets } = environment.config;
const positions = response.positions.map((position) => ({
timestamp: position.timestamp,
markets: position.markets.map((market) => {
const marketKey = Object.keys(morphoMarkets).find((key) => morphoMarkets[key].id.toLowerCase() ===
market.marketId.toLowerCase());
return {
chainId: market.chainId,
marketId: market.marketId,
marketKey: marketKey || market.marketId,
supplyShares: market.supplyShares,
borrowShares: market.borrowShares,
collateral: market.collateral,
};
}),
}));
return {
account: response.account,
positions,
};
}
//# sourceMappingURL=getAccountMarketPortfolio.js.map