@tracer-protocol/pools-js
Version:
Javascript library for interacting with Tracer's Perpetual Pools
69 lines (68 loc) • 2.45 kB
TypeScript
import { SMAOracle as SMAOracleContract, ChainlinkOracleWrapper } from "@tracer-protocol/perpetual-pools-contracts/types";
import BigNumber from "bignumber.js";
import { providers as MCProvider } from '@0xsequence/multicall';
import { ethers } from "ethers";
import { OracleClass, IContract } from "../types";
/**
* SMAOracle class constructor inputs
*/
export interface ISMAOracle extends IContract, SMAOracleInfo {
}
/**
* SMAOracle constructor props
* Only `address` is required, additional props are encouraged
* to reduce the number of RPC calls
*/
export interface SMAOracleInfo {
address: string;
}
/**
* SMAOracle class for interacting with ERC20 tokens
* The constructor is private so must be instantiated with {@linkcode SMAOracle.Create}
*/
export default class SMAOracle implements OracleClass<SMAOracleContract> {
_contract?: SMAOracleContract;
_underlyingOracle?: ChainlinkOracleWrapper;
address: string;
provider: ethers.providers.Provider | ethers.Signer | undefined;
multicallProvider: MCProvider.MulticallProvider | ethers.Signer | undefined;
updateInterval: number;
numPeriods: number;
type: 'SMA' | 'Spot' | undefined;
/**
* @private
*/
private constructor();
/**
* Replacement constructor pattern to support async initialisations
* @param tokenINfo {@link ISMAOracle | ISMAOracle interface props}
* @returns a Promise containing an initialised SMAOracle class ready to be used
*/
static Create: (oracleInfo: ISMAOracle) => Promise<SMAOracle>;
/**
* Creates an empty SMAOracle that can be used as a default
* @returns default constructed token
*/
static CreateDefault: () => SMAOracle;
/**
* Private initialisation function called in {@link SMAOracle.Create}
* @private
* @param oracleInfo {@link ISMAOracle | ISMAOracle interface props}
*/
private init;
/**
* get the latest SMA price
* @returns the average of the most recent price data points
*/
getPrice: () => Promise<BigNumber>;
/**
* get the current underlying spot price
* @returns the current price reported by the underlying price oracle
*/
getSpotPrice: () => Promise<BigNumber>;
/**
* Replaces the provider and connects the contract instance
* @param provider The new provider to connect to
*/
connect: (provider: ethers.providers.Provider | ethers.Signer) => void;
}