@moonwell-fi/moonwell-sdk
Version:
TypeScript Interface for Moonwell
42 lines • 1.55 kB
JavaScript
import dayjs from "dayjs";
export { Amount } from "./amount.js";
export { BaseError, HttpRequestError } from "./error.js";
export const SECONDS_PER_DAY = 86400;
export const DAYS_PER_YEAR = 365;
export const perDay = (value) => value * SECONDS_PER_DAY;
export function isStartOfDay(timestamp) {
const startOfDay = dayjs
.utc(timestamp * 1000)
.startOf("day")
.unix();
return startOfDay === timestamp;
}
export const calculateApy = (value) => ((value * SECONDS_PER_DAY + 1) ** DAYS_PER_YEAR - 1) * 100;
export const getEnvironmentFromArgs = (client, args) => {
if (args) {
const { chainId, network } = args;
if (chainId) {
return Object.values(client.environments).find((env) => env.chainId === chainId);
}
if (network) {
return client.environments[network];
}
}
return undefined;
};
export const getEnvironmentsFromArgs = (client, args, onlyWithDeployment) => {
const onlyEnvironmentsWithDeployment = onlyWithDeployment !== undefined ? onlyWithDeployment : true;
if (args) {
const { chainId, network } = args;
if (chainId) {
return [
Object.values(client.environments).find((env) => env.chainId === chainId),
];
}
if (network) {
return [client.environments[network]];
}
}
return Object.values(client.environments).filter((r) => onlyEnvironmentsWithDeployment ? r.contracts.views !== undefined : true);
};
//# sourceMappingURL=index.js.map