@moonwell-fi/moonwell-sdk
Version:
TypeScript Interface for Moonwell
55 lines • 2.65 kB
TypeScript
import type { MoonwellClient } from "../client/createMoonwellClient.js";
import type { Environment } from "../environments/index.js";
export { Amount } from "./amount.js";
export { BaseError, HttpRequestError } from "./error.js";
export type { HttpRequestErrorType } from "./error.js";
export { getBlockNumberAtTimestamp } from "./getBlockNumberAtTimestamp.js";
export type { MultichainReturnType } from "./types.js";
export declare const SECONDS_PER_DAY = 86400;
export declare const DAYS_PER_YEAR = 365;
export declare const perDay: (value: number) => number;
export declare function isStartOfDay(timestamp: number): boolean;
export declare const calculateApy: (value: number) => number;
export type SnapshotPeriod = "1M" | "3M" | "1Y" | "ALL";
export type SnapshotGranularity = "6h" | "1d" | "7d" | "14d" | "30d";
/**
* Filter snapshots to keep every Nth data point based on granularity.
* "6h" and "1d" are handled natively by the API — no client-side filtering applied.
* Coarser granularities (7d, 14d, 30d) fetch "1d" from the API and thin here.
*
* Callers must sort snapshots ascending by timestamp before calling this function.
* Always keeps index 0, N, 2N, … so the oldest data point is always retained.
*/
export declare function applyGranularity<T extends {
timestamp: number;
}>(snapshots: T[], granularity: SnapshotGranularity): T[];
/**
* Map a SnapshotGranularity to the value passed to the lunar indexer API.
* "6h" is natively supported; coarser granularities (7d, 14d, 30d) are not,
* so we fetch "1d" and thin client-side via applyGranularity.
*/
export declare function toApiGranularity(granularity: SnapshotGranularity): "6h" | "1d";
/**
* Calculate start/end times and display granularity based on period or custom timestamps.
* Priority: custom timestamps > period > default (365 days)
*
* Granularity per period:
* 1M → 6h (4 data points per day, API-native)
* 3M → 1d (one data point per day)
* 1Y → 7d (one data point every 7 days, client-side filtered)
* ALL → 14d (one data point every 14 days, client-side filtered)
*/
export declare function calculateTimeRange(period?: SnapshotPeriod, startTime?: number, endTime?: number): {
startTime: number;
endTime: number;
granularity: SnapshotGranularity;
};
export declare const getEnvironmentFromArgs: (client: MoonwellClient, args?: {
chainId?: number;
network?: any;
}) => Environment | undefined;
export declare const getEnvironmentsFromArgs: (client: MoonwellClient, args?: {
chainId?: number;
network?: any;
}, onlyWithDeployment?: boolean) => Environment[];
//# sourceMappingURL=index.d.ts.map