Options
All
  • Public
  • Public/Protected
  • All
Menu

@tracer-protocol/pools-js

Index

Type aliases

CommitEventData: { amount: BigNumber; appropriateIntervalId: number; blockNumber: number; commitType: RawCommitType; fromAggregateBalance: boolean; mintingFee: string; payForClaim: boolean; settlementTokenDecimals: number; timestamp: number; txHash: string; user: string }

Type declaration

  • amount: BigNumber
  • appropriateIntervalId: number
  • blockNumber: number
  • commitType: RawCommitType
  • fromAggregateBalance: boolean
  • mintingFee: string
  • payForClaim: boolean
  • settlementTokenDecimals: number
  • timestamp: number
  • txHash: string
  • user: string
CommitsExecutedData: { blockNumber: number; burningFee: string; timestamp: number; txHash: string; updateIntervalId: number }

Type declaration

  • blockNumber: number
  • burningFee: string
  • timestamp: number
  • txHash: string
  • updateIntervalId: number
ExpectedPoolState: { currentLongBalance: BigNumber; currentLongSupply: BigNumber; currentShortBalance: BigNumber; currentShortSupply: BigNumber; currentSkew: BigNumber; expectedLongBalance: BigNumber; expectedLongSupply: BigNumber; expectedLongTokenPrice: BigNumber; expectedOraclePrice: BigNumber; expectedShortBalance: BigNumber; expectedShortSupply: BigNumber; expectedShortTokenPrice: BigNumber; expectedSkew: BigNumber; lastOraclePrice: BigNumber; pendingCommits: TotalPoolCommitmentsBN[]; timestamp: number; totalNetPendingLong: BigNumber; totalNetPendingShort: BigNumber }

Type declaration

  • currentLongBalance: BigNumber
  • currentLongSupply: BigNumber
  • currentShortBalance: BigNumber
  • currentShortSupply: BigNumber
  • currentSkew: BigNumber
  • expectedLongBalance: BigNumber
  • expectedLongSupply: BigNumber
  • expectedLongTokenPrice: BigNumber
  • expectedOraclePrice: BigNumber
  • expectedShortBalance: BigNumber
  • expectedShortSupply: BigNumber
  • expectedShortTokenPrice: BigNumber
  • expectedSkew: BigNumber
  • lastOraclePrice: BigNumber
  • pendingCommits: TotalPoolCommitmentsBN[]
  • timestamp: number
  • totalNetPendingLong: BigNumber
  • totalNetPendingShort: BigNumber
ExpectedPoolStateWithUpdateIntervalId: ExpectedPoolState & { updateIntervalId: BigNumber }
KnownNetwork: typeof NETWORKS[KnownNetworkKeys]
MultiplePoolWatcherConstructorArgs: { poolAddresses: string[] } & PoolWatcherArgs
OraclePriceTransformer: (lastPrice: BigNumber, currentPrice: BigNumber) => BigNumber

Type declaration

    • (lastPrice: BigNumber, currentPrice: BigNumber): BigNumber
    • Parameters

      • lastPrice: BigNumber
      • currentPrice: BigNumber

      Returns BigNumber

PendingAmounts: { burn: BigNumber; mint: BigNumber }

Holds burn and mint pending amounts PendingAmounts.mint is the amount of quote token pending in the shadow pools PendingAmounts.burn is the amount of to be burned pool tokens in the shadow pools

Type declaration

  • burn: BigNumber
  • mint: BigNumber
PoolStatePreview: { currentLongBalance: BigNumber; currentLongSupply: BigNumber; currentLongTokenPrice: BigNumber; currentPendingLongTokenBurn: BigNumber; currentPendingShortTokenBurn: BigNumber; currentShortBalance: BigNumber; currentShortSupply: BigNumber; currentShortTokenPrice: BigNumber; currentSkew: BigNumber; expectedLongBalance: BigNumber; expectedLongSupply: BigNumber; expectedLongTokenPrice: BigNumber; expectedOraclePrice: BigNumber; expectedPendingLongTokenBurn: BigNumber; expectedPendingShortTokenBurn: BigNumber; expectedShortBalance: BigNumber; expectedShortSupply: BigNumber; expectedShortTokenPrice: BigNumber; expectedSkew: BigNumber; lastOraclePrice: BigNumber; pendingCommits: TotalPoolCommitmentsBN[]; timestamp: number; totalNetPendingLong: BigNumber; totalNetPendingShort: BigNumber }

Type declaration

  • currentLongBalance: BigNumber
  • currentLongSupply: BigNumber
  • currentLongTokenPrice: BigNumber
  • currentPendingLongTokenBurn: BigNumber
  • currentPendingShortTokenBurn: BigNumber
  • currentShortBalance: BigNumber
  • currentShortSupply: BigNumber
  • currentShortTokenPrice: BigNumber
  • currentSkew: BigNumber
  • expectedLongBalance: BigNumber
  • expectedLongSupply: BigNumber
  • expectedLongTokenPrice: BigNumber
  • expectedOraclePrice: BigNumber
  • expectedPendingLongTokenBurn: BigNumber
  • expectedPendingShortTokenBurn: BigNumber
  • expectedShortBalance: BigNumber
  • expectedShortSupply: BigNumber
  • expectedShortTokenPrice: BigNumber
  • expectedSkew: BigNumber
  • lastOraclePrice: BigNumber
  • pendingCommits: TotalPoolCommitmentsBN[]
  • timestamp: number
  • totalNetPendingLong: BigNumber
  • totalNetPendingShort: BigNumber
PoolStatePreviewInputs: { currentOraclePrice: BigNumber; fee: BigNumber; lastOraclePrice: BigNumber; leverage: BigNumber; longBalance: BigNumber; longTokenSupply: BigNumber; oraclePriceTransformer: OraclePriceTransformer; pendingCommits: TotalPoolCommitmentsBN[]; pendingLongTokenBurn: BigNumber; pendingShortTokenBurn: BigNumber; shortBalance: BigNumber; shortTokenSupply: BigNumber }

Type declaration

  • currentOraclePrice: BigNumber
  • fee: BigNumber
  • lastOraclePrice: BigNumber
  • leverage: BigNumber
  • longBalance: BigNumber
  • longTokenSupply: BigNumber
  • oraclePriceTransformer: OraclePriceTransformer
  • pendingCommits: TotalPoolCommitmentsBN[]
  • pendingLongTokenBurn: BigNumber
  • pendingShortTokenBurn: BigNumber
  • shortBalance: BigNumber
  • shortTokenSupply: BigNumber
PoolWatcherConstructorArgs: SpecificPool & PoolWatcherArgs
RawCommitType: 0 | 1 | 2 | 3 | 4 | 5
SpecificPool: { poolAddress: string }

Type declaration

  • poolAddress: string
StaticTokenInfo: { address: string; decimals: number; name: string; symbol: string }

ERC20 token info which is static and not going to change

Type declaration

  • address: string
  • decimals: number
  • name: string
  • symbol: string
TotalPoolCommitments: Awaited<ReturnType<PoolCommitter["totalPoolCommitments"]>>
TotalPoolCommitmentsBN: { longBurnPoolTokens: BigNumber; longBurnShortMintPoolTokens: BigNumber; longMintSettlement: BigNumber; shortBurnLongMintPoolTokens: BigNumber; shortBurnPoolTokens: BigNumber; shortMintSettlement: BigNumber }

Type declaration

  • longBurnPoolTokens: BigNumber
  • longBurnShortMintPoolTokens: BigNumber
  • longMintSettlement: BigNumber
  • shortBurnLongMintPoolTokens: BigNumber
  • shortBurnPoolTokens: BigNumber
  • shortMintSettlement: BigNumber
UpkeepEventData: { blockNumber: number; data: string; endPrice: BigNumber; poolAddress: string; startPrice: BigNumber; timestamp: number; txHash: string }

Type declaration

  • blockNumber: number
  • data: string
  • endPrice: BigNumber
  • poolAddress: string
  • startPrice: BigNumber
  • timestamp: number
  • txHash: string
WatchedPool: { address: string; committerInstance: PoolCommitter; frontRunningInterval: number; keeperInstance: PoolKeeper; lastPriceTimestamp: number; sdkInstance: Pool; updateInterval: number }

Type declaration

  • address: string
  • committerInstance: PoolCommitter
  • frontRunningInterval: number
  • keeperInstance: PoolKeeper
  • lastPriceTimestamp: number
  • sdkInstance: Pool
  • updateInterval: number

Variables

EVENT_NAMES: { COMMIT: "COMMIT"; COMMITMENT_WINDOW_ENDED: "COMMITMENT_WINDOW_ENDED"; COMMITMENT_WINDOW_ENDING: "COMMITMENT_WINDOW_ENDING"; COMMITS_EXECUTED: "COMMITS_EXECUTED"; UPKEEP: "UPKEEP" } = ...

Type declaration

  • COMMIT: "COMMIT"
  • COMMITMENT_WINDOW_ENDED: "COMMITMENT_WINDOW_ENDED"
  • COMMITMENT_WINDOW_ENDING: "COMMITMENT_WINDOW_ENDING"
  • COMMITS_EXECUTED: "COMMITS_EXECUTED"
  • UPKEEP: "UPKEEP"
NETWORKS: { ARBITRUM: "42161"; ARBITRUM_RINKEBY: "421611"; KOVAN: "42"; MAINNET: "1"; RINKEBY: "4" } = ...

Type declaration

  • ARBITRUM: "42161"
  • ARBITRUM_RINKEBY: "421611"
  • KOVAN: "42"
  • MAINNET: "1"
  • RINKEBY: "4"
POOL_STATE_HELPER_BY_NETWORK: { 42161: string; 421611: string } = ...

Type declaration

  • 42161: string
  • 421611: string
POOL_SWAP_LIBRARY_BY_NETWORK: { 42161: string; 421611: string } = ...

Type declaration

  • 42161: string
  • 421611: string
SECONDS_PER_LEAP_YEAR: 31622400 = 31622400
TCR_DECIMALS: 18 = 18
TEST_QUOTE_TOKEN: { address: string; decimals: number; name: string; symbol: string } = ...

Type declaration

  • address: string
  • decimals: number
  • name: string
  • symbol: string
TEST_TOKEN_DECIMALS: 18 = 18
USDC_DECIMALS: 6 = 6
defaultCommitter: { burningFee: BigNumber; mintingFee: BigNumber; pendingLong: { burn: BigNumber; mint: BigNumber }; pendingShort: { burn: BigNumber; mint: BigNumber }; settlementTokenDecimals: 18 } = ...

Type declaration

  • burningFee: BigNumber
  • mintingFee: BigNumber
  • pendingLong: { burn: BigNumber; mint: BigNumber }
    • burn: BigNumber
    • mint: BigNumber
  • pendingShort: { burn: BigNumber; mint: BigNumber }
    • burn: BigNumber
    • mint: BigNumber
  • settlementTokenDecimals: 18
deprecatedTokenAddresses: string[] = ...
poolList: Record<KnownNetwork, StaticPoolInfo[]> = ...
poolMap: Record<KnownNetwork, Record<string, StaticPoolInfo>> = ...
poolTokenList: Record<KnownNetwork, Record<string, StaticTokenInfo>> = ...
tokenMap: Record<KnownNetwork, Record<string, StaticTokenInfo>> = ...

Functions

  • attemptPromiseRecursively<T>(__namedParameters: { attemptCount?: number; interval?: number; maxAttempts?: number; promise: any; retryCheck?: any }): Promise<T>
  • attempt promise until it succeeds or the maximum number of allowed attempts is reached

    Type parameters

    • T

    Parameters

    • __namedParameters: { attemptCount?: number; interval?: number; maxAttempts?: number; promise: any; retryCheck?: any }
      • Optional attemptCount?: number
      • Optional interval?: number
      • Optional maxAttempts?: number
      • promise:function
        • promise(): Promise<T>
        • Returns Promise<T>

      • retryCheck?:function
        • retryCheck(error: unknown): Promise<boolean>
        • Parameters

          • error: unknown

          Returns Promise<boolean>

    Returns Promise<T>

    a promise that will eventually error or resolve to the same type as the original promise

  • calcAPY(apr: BigNumber): BigNumber
  • Calculates the compounding gains

    Parameters

    • apr: BigNumber

      annual percentage rate as a decimal eg 1 is a 100% apr

    Returns BigNumber

    annual percentage yield coumpounded weekly

  • calcBptTokenPrice(usdTokenSupply: BigNumber, tokens?: { reserves: BigNumber; usdPrice: BigNumber }[]): BigNumber
  • Calculates the Balancer LP token price given a list of tokens included in the pool

    Parameters

    • usdTokenSupply: BigNumber
    • Optional tokens: { reserves: BigNumber; usdPrice: BigNumber }[]

      list of tokens included in the balancer pool

    Returns BigNumber

    0 if no tokens are given, if the tokens have no USDC value or if the stakingToken supply is 0 otherwise returns the price of the LP token.

  • calcBptTokenSpotPrice(sellingToken: { balance: BigNumber; weight: BigNumber }, buyingToken: { balance: BigNumber; weight: BigNumber }, swapFee: BigNumber): BigNumber
  • Calculates the trade price between two Balancer tokens. This price is dependent on the reserves deposited on each side within the Balancer pool, as well as the weighting of each.

    Parameters

    • sellingToken: { balance: BigNumber; weight: BigNumber }

      weight and balance of token that is being sold

      • balance: BigNumber
      • weight: BigNumber
    • buyingToken: { balance: BigNumber; weight: BigNumber }

      weight and balance of token that is being bought

      • balance: BigNumber
      • weight: BigNumber
    • swapFee: BigNumber

      percentage swap fee in decimals

    Returns BigNumber

  • calcDirection(oldPrice: BigNumber, newPrice: BigNumber): BigNumber
  • Calcualtes the direction of the price movement

    Parameters

    • oldPrice: BigNumber

      old market price

    • newPrice: BigNumber

      new market price

    Returns BigNumber

    DOWN (2) if oldPrice > newPrice, NO_CHANGE (3) if newPrice = oldPrice, or UP (1) if newPrice > oldPrice

  • calcEffectiveLongGain(shortBalance: BigNumber, longBalance: BigNumber, leverage: BigNumber): BigNumber
  • Calculates the effective multiplier returns for the longs. This amount varies depending on the skew between the long and short balances. Gain and loss refer to whether the pool is receiving tokens from the other pool or transferring tokens to the opposite pool. If there is more balance in the long pool than the short pools, you would expect the short pool to have effectiveLongGain > leverage. Both sides of the pool will always have an effectiveLoss lower limit at leverage, ie you can never have effectiveLoss < leverage.

    Parameters

    • shortBalance: BigNumber

      quote balance of the short pool in quote units (eg USD)

    • longBalance: BigNumber

      quote balance of the long pool in quote units (eg USD)

    • leverage: BigNumber

      pool leverage

    Returns BigNumber

    the effective winning returns to the long pool on next rebalance

  • calcEffectiveShortGain(shortBalance: BigNumber, longBalance: BigNumber, leverage: BigNumber): BigNumber
  • Calculates the effective gains multiplier for the shorts. This amount varies depending on the skew between the long and short balances. Gain and loss refer to whether the pool is receiving tokens from the other pool or transferring tokens to the opposite pool. If there is more balance in the long pool than the short pools, you would expect the short pool to have effectiveLongGain > leverage. The pools effective losses will always have a lower limit at leverage, ie you can never have effectiveLoss < leverage.

    Parameters

    • shortBalance: BigNumber

      quote balance of the short pool in USD

    • longBalance: BigNumber

      quote balance of the long pool in USD

    • leverage: BigNumber

      pool leverage

    Returns BigNumber

    the effective gains to the short pool on next rebalance

  • calcNextValueTransfer(oldPrice: BigNumber, newPrice: BigNumber, leverage: BigNumber, longBalance: BigNumber, shortBalance: BigNumber): { longValueTransfer: BigNumber; shortValueTransfer: BigNumber }
  • Calculates how much value will be transferred between the pools

    Parameters

    • oldPrice: BigNumber

      old market price

    • newPrice: BigNumber

      new market price

    • leverage: BigNumber

      pool leverage

    • longBalance: BigNumber

      quote balance of the long pool in USD

    • shortBalance: BigNumber

      quote balance of the short pool in USD

      returns an object containing longValueTransfer and shortValueTransfer

    Returns { longValueTransfer: BigNumber; shortValueTransfer: BigNumber }

    • longValueTransfer: BigNumber
    • shortValueTransfer: BigNumber
  • calcNotionalValue(tokenPrice: BigNumber, numTokens: BigNumber): BigNumber
  • Calculates the notional value of tokens

    Parameters

    • tokenPrice: BigNumber

      current price of tokens

    • numTokens: BigNumber

      number of tokens

    Returns BigNumber

    notional value of the tokens

  • calcPercentageLossTransfer(oldPrice: BigNumber, newPrice: BigNumber, leverage: BigNumber): BigNumber
  • calculates the expected state of the pool after applying the given pending commits to the given pool state

    Parameters

    Returns PoolStatePreview

    the expected state of the pool

  • calcRatio(oldPrice: BigNumber, newPrice: BigNumber): BigNumber
  • Calculates the ratio of the old price to the new price

    Parameters

    • oldPrice: BigNumber

      old market price

    • newPrice: BigNumber

      new market price

    Returns BigNumber

  • calcRebalanceRate(shortBalance: BigNumber, longBalance: BigNumber): BigNumber
  • Parameters

    • shortBalance: BigNumber
    • longBalance: BigNumber

    Returns BigNumber

  • calcSkew(shortBalance: BigNumber, longBalance: BigNumber): BigNumber
  • Parameters

    • shortBalance: BigNumber
    • longBalance: BigNumber

    Returns BigNumber

  • calcTokenPrice(totalQuoteValue: BigNumber, tokenSupply: BigNumber): BigNumber
  • Calculate the pool tokens price Since totalQuoteValue will generally be in USD the returned amount will also be in USD

    Parameters

    • totalQuoteValue: BigNumber
    • tokenSupply: BigNumber

    Returns BigNumber

  • encodeCommitParams(payForClaim: boolean, fromAggregateBalances: boolean, commitType: CommitEnum, parsedAmount: BigNumber): BytesLike
  • Parameters

    • payForClaim: boolean
    • fromAggregateBalances: boolean
    • commitType: CommitEnum
    • parsedAmount: BigNumber

    Returns BytesLike

  • ethersBNtoBN(ethersBN: BigNumber, decimals?: number): BigNumber
  • Parameters

    • ethersBN: BigNumber
    • Optional decimals: number

    Returns BigNumber

  • getExpectedExecutionTimestamp(frontRunningInterval: number, updateInterval: number, lastUpdate: number, commitCreated: number): number
  • Calculate the expected execution given a commit timestamp, the frontRunningInterval, updateInterval and lastUpdate. This is just an estimate as there is a slight delay between possibleExecution and finalExecutionTimestamp See https://github.com/tracer-protocol/pools-js/blob/updated-calc/src/utils/calculations.ts#L280-L332 for a long clearer sudo codish written version

    Parameters

    • frontRunningInterval: number
    • updateInterval: number
    • lastUpdate: number
    • commitCreated: number

    Returns number

  • movingAveragePriceTransformer(lastPrice: BigNumber, currentPrice: BigNumber): BigNumber
  • Parameters

    • lastPrice: BigNumber
    • currentPrice: BigNumber

    Returns BigNumber

  • pendingCommitsToBN(pendingCommits: [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber] & { longBurnPoolTokens: BigNumber; longBurnShortMintPoolTokens: BigNumber; longMintSettlement: BigNumber; shortBurnLongMintPoolTokens: BigNumber; shortBurnPoolTokens: BigNumber; shortMintSettlement: BigNumber }, decimals?: number): TotalPoolCommitmentsBN
  • Parameters

    • pendingCommits: [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber] & { longBurnPoolTokens: BigNumber; longBurnShortMintPoolTokens: BigNumber; longMintSettlement: BigNumber; shortBurnLongMintPoolTokens: BigNumber; shortBurnPoolTokens: BigNumber; shortMintSettlement: BigNumber }
    • Optional decimals: number

    Returns TotalPoolCommitmentsBN

Generated using TypeDoc