@moonwell-fi/moonwell-sdk
Version:
TypeScript Interface for Moonwell
41 lines (35 loc) • 1.38 kB
text/typescript
import type { Address, Chain } from "viem";
import type { MoonwellClient } from "../../../client/createMoonwellClient.js";
import { getEnvironmentsFromArgs } from "../../../common/index.js";
import type { OptionalNetworkParameterType } from "../../../common/types.js";
import type { MorphoVaultUserPosition } from "../../../types/morphoUserPosition.js";
import { getMorphoVaultUserPositionsData } from "./common.js";
export type GetMorphoVaultUserPositionsParameters<
environments,
network extends Chain | undefined,
> = OptionalNetworkParameterType<environments, network> & {
userAddress: Address;
};
export type GetMorphoVaultUserPositionsReturnType = Promise<
MorphoVaultUserPosition[]
>;
export async function getMorphoVaultUserPositions<
environments,
Network extends Chain | undefined,
>(
client: MoonwellClient,
args: GetMorphoVaultUserPositionsParameters<environments, Network>,
): GetMorphoVaultUserPositionsReturnType {
const environments = getEnvironmentsFromArgs(client, args);
const environmentsUserPositions = await Promise.all(
environments
.filter((environment) => environment.contracts.morphoViews !== undefined)
.map((environment) => {
return getMorphoVaultUserPositionsData({
environment,
account: args.userAddress,
});
}),
);
return environmentsUserPositions.flat();
}