@drift-labs/sdk
Version:
SDK for Drift Protocol
24 lines (23 loc) • 1.33 kB
TypeScript
/// <reference types="bn.js" />
import { BN } from '@coral-xyz/anchor';
export declare function clampBN(x: BN, min: BN, max: BN): BN;
export declare const squareRootBN: (n: BN) => BN;
export declare const divCeil: (a: BN, b: BN) => BN;
export declare const sigNum: (x: BN) => BN;
/**
* calculates the time remaining until the next update based on a rounded, "on-the-hour" update schedule
* this schedule is used for Perpetual Funding Rate and Revenue -> Insurance Updates
* @param now: current blockchain unix timestamp
* @param lastUpdateTs: the unix timestamp of the last update
* @param updatePeriod: desired interval between updates (in seconds)
* @returns: timeRemainingUntilUpdate (in seconds)
*/
export declare function timeRemainingUntilUpdate(now: BN, lastUpdateTs: BN, updatePeriod: BN): BN;
export declare const checkSameDate: (dateString1: string, dateString2: string) => boolean;
export declare function isBNSafe(number: number): boolean;
/**
* Converts a number to BN makes sure the number is safe to convert to BN (that it does not overflow number after multiplying by precision)
* @param number the number to convert to BN
* @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from drift sdk)
*/
export declare function numberToSafeBN(number: number, precision: BN): BN;