UNPKG

@tracer-protocol/pools-js

Version:

Javascript library for interacting with Tracer's Perpetual Pools

83 lines (82 loc) 3.36 kB
import { PoolCommitter } from "@tracer-protocol/perpetual-pools-contracts/types"; import BigNumber from "bignumber.js"; import { providers as MCProvider } from '@0xsequence/multicall'; import { ethers } from "ethers"; import { CommitEnum, IContract, PendingAmounts } from "../types"; /** * PoolCommitter class constructor inputs */ export interface IPoolCommitter extends IContract { settlementTokenDecimals: number; } export declare const defaultCommitter: { readonly pendingLong: { readonly mint: BigNumber; readonly burn: BigNumber; }; readonly pendingShort: { readonly mint: BigNumber; readonly burn: BigNumber; }; readonly settlementTokenDecimals: 18; readonly mintingFee: BigNumber; readonly burningFee: BigNumber; }; /** * Interface for interacting with the PoolComitter. * Can be used standalone, but is always initialised within a * {@linkcode Pool} * The constructor is private so must be instantiated with {@linkcode Committer.Create} */ export default class Committer { _contract?: PoolCommitter; address: string; provider: ethers.providers.Provider | ethers.Signer | undefined; multicallProvider: MCProvider.MulticallProvider | ethers.Signer | undefined; settlementTokenDecimals: number; mintingFee: BigNumber; burningFee: BigNumber; pendingLong: PendingAmounts; pendingShort: PendingAmounts; private constructor(); /** * Replacement constructor pattern to support async initialisations * @param committerInfo {@link IPoolCommitter | IPoolCommitter interface props} * @returns a Promise containing an initialised Committer class ready to be used */ static Create: (committerInfo: IPoolCommitter) => Promise<Committer>; /** * Creates an empty committer that can be used as a default */ static CreateDefault: () => Committer; /** * Private initialisation function called in {@link Committer.Create} * @param committerInfo {@link IPoolCommitter | IPoolCommitter interface props} */ private init; /** * Submits a commit * @param type 1 of 4 commit types. These values are (0, 1, 2, 3) => (shortMint, shortBurn, longMint, longBurn) * @param amount either a number or BigNumber representing the amount of tokens * @param payForClaim * @param fromAggregateBalances is true when the user wants to pay from balances yet to be claimed, * false if they want to use the balances within their wallet * to be committed if burning, or the amount of quote token to use to mint new tokens */ commit: (type: CommitEnum, amount: number | BigNumber, payForClaim: boolean, fromAggregateBalances: boolean) => Promise<ethers.ContractTransaction>; /** * Updates all shadow pool balances. * Calls {@linkcode Committer.fetchShadowPool} for each of the commit types. * As such this will also set the internal state of the Class * @returns all refetched shadow pool balances */ fetchAllShadowPools: () => Promise<{ pendingLong: PendingAmounts; pendingShort: PendingAmounts; }>; /** * Replaces the provider and connects the contract instance * @param provider The new provider to connect to */ connect: (provider: ethers.providers.Provider | ethers.Signer) => void; }