UNPKG

@tracer-protocol/pools-js

Version:

Javascript library for interacting with Tracer's Perpetual Pools

76 lines (75 loc) 2.83 kB
import { PoolToken as PoolTokenContract } from "@tracer-protocol/perpetual-pools-contracts/types"; import BigNumber from "bignumber.js"; import { providers as MCProvider } from '@0xsequence/multicall'; import { ethers } from "ethers"; import { SideEnum } from ".."; import { IToken } from "./token"; /** * PoolToken class constructor inputs */ export interface IPoolToken extends IToken { pool: string; side: SideEnum; } export default class PoolToken { _contract?: PoolTokenContract; address: string; provider: ethers.providers.Provider | ethers.Signer | undefined; multicallProvider: MCProvider.MulticallProvider | ethers.Signer | undefined; name: string; symbol: string; decimals: number; pool: string; side: SideEnum; supply: BigNumber; /** * @private */ private constructor(); /** * Replacement constructor pattern to support async initialisations * @param tokenINfo {@link IPoolToken | IPoolToken interface props} * @returns a Promise containing an initialised PoolToken class ready to be used */ static Create: (tokenInfo: IPoolToken) => Promise<PoolToken>; /** * Creates an empty PoolToken that can be used as a default * @returns default constructed pool token */ static CreateDefault: () => PoolToken; /** * Private initialisation function called in {@link PoolToken.Create} * @param tokenInfo {@link IPoolToken | IPoolToken interface props} */ private init; /** * Fetch an accounts balance for this token * @param account Account to check balance of * @returns The accounts balance formatted in a BigNumber */ fetchBalance: (account: string) => Promise<BigNumber>; /** * Fetch an accounts allowance for a given spender * @param account Account to check allowance * @param spender Spender of the accounts tokens * @returns the allowance the account has given to the spender address to spend this pool token */ fetchAllowance: (spender: string, account: string) => Promise<BigNumber>; /** * Fetch and set the total token supply * @returns most up to date token supply */ fetchSupply: () => Promise<BigNumber>; /** * Approve a spender to spend the signers accounts pool tokens * @param spender the address of the contract that will spend the pool tokens * @param amount the amount the signer is allowing the spender to spend * @returns an ethers transaction */ approve: (spender: string, amount: number | BigNumber) => Promise<ethers.ContractTransaction>; /** * Replaces the provider and connects the contract instance * @param provider The new provider to connect to */ connect: (provider: ethers.providers.Provider | ethers.Signer) => void; }