Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Tonic

Index

Constructors

  • new Tonic(account: Account, contractId: string): Tonic

Properties

account: Account
contractId: string

Accessors

  • get contract(): TonicContract

Methods

  • buildSwapParams(tokenId: string, amount: BN, swaps: SwapParamsV1[]): FunctionCallOptions
  • cancelAllOrders(market_id: string): Promise<{ executionOutcome: FinalExecutionOutcome; response: unknown }>
  • Cancel all orders in a market.

    Parameters

    • market_id: string

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: unknown }>

  • cancelOrder(market_id: string, order_id: string): Promise<{ executionOutcome: FinalExecutionOutcome; response: unknown }>
  • Cancel an order.

    Parameters

    • market_id: string
    • order_id: string

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: unknown }>

  • cancelOrders(marketId: string, orderIds: string[]): Promise<{ executionOutcome: FinalExecutionOutcome; response: ActionResultV1[] }>
  • Cancel multiple orders in a market. Use Tonic.executeBatch to cancel orders in multiple markets.

    Parameters

    • marketId: string
    • orderIds: string[]

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: ActionResultV1[] }>

  • createMarket(params: { baseTokenId: string; baseTokenLotSize: string; makerRebateBaseRate: number; quoteTokenId: string; quoteTokenLotSize: string; takerFeeBaseRate: number }): Promise<{ executionOutcome: FinalExecutionOutcome; response: string }>
  • Create a market

    Parameters

    • params: { baseTokenId: string; baseTokenLotSize: string; makerRebateBaseRate: number; quoteTokenId: string; quoteTokenLotSize: string; takerFeeBaseRate: number }
      • baseTokenId: string
      • baseTokenLotSize: string
      • makerRebateBaseRate: number
      • quoteTokenId: string
      • quoteTokenLotSize: string
      • takerFeeBaseRate: number

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: string }>

  • deposit(tokenId: string, amount: BN): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>
  • Deposit NEP 141 tokens or native NEAR. For native NEAR, the tokenId must be 'NEAR'.

    The amount must be decimal-aware, eg, to deposit 1 NEAR (24 decimals), use

    import { decimalToBn } from '@tonic-foundation/utils';
    // Deposit 1 NEAR
    tonic.deposit('NEAR', decimalToBn(1, 24))
    // Deposit 1 USDC
    tonic.deposit('usdc.example.testnet', decimalToBn(1, 6))

    Parameters

    • tokenId: string
    • amount: BN

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>

  • depositFt(tokenId: string, amount: BN, msg: string | { action: "Swap"; params: SwapParamsV1[] }): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>
  • Deposit NEP-141 token.

    Parameters

    • tokenId: string
    • amount: BN
    • msg: string | { action: "Swap"; params: SwapParamsV1[] }

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>

  • depositNear(amount: BN): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>
  • Deposit native NEAR.

    Parameters

    • amount: BN

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>

  • executeBatch(batch: PrepareBatch): Promise<{ executionOutcome: FinalExecutionOutcome; response: ActionResultV1[] }>
  • Execute batch actions. See the example in the "examples" directory for more information.

    Parameters

    • batch: PrepareBatch

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: ActionResultV1[] }>

  • Return available exchange balances with decimals as a map of { tokenId => balance }. "Available balance" is balance not currently locked in an open order. For example, an account with 1 USDC available would see

    await tonic.getBalances() // { usdc.example.testnet: BN<1000000> }
    

    Returns Promise<ExchangeBalances>

  • getMarket(marketId: string): Promise<Market>
  • getOrder(market_id: string, order_id: string): Promise<null | OpenLimitOrder>
  • getOrderbook(market_id: string, depth?: number): Promise<Orderbook>
  • Get the orderbook. Orders are returned with decimals (eg, 1 USDC is returned as 1000000). The format of each order is [price, open quantity].

    Parameters

    • market_id: string
    • depth: number = 12

      Number of price levels to fetch, default 12

    Returns Promise<Orderbook>

  • listMarkets(offset?: number, limit?: number): Promise<MarketViewV1[]>
  • List markets in order of creation.

    Parameters

    • offset: number = 0
    • limit: number = 100

    Returns Promise<MarketViewV1[]>

  • placeOrder(market_id: string, order: NewOrderParamsV1): Promise<{ executionOutcome: FinalExecutionOutcome; response: OrderResultV1 }>
  • Place an order. This is a relatively low-level method that works with lot-aware values. Client applications may use Market.placeOrder instead for a higher-level interface.

    Parameters

    • market_id: string
    • order: NewOrderParamsV1

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: OrderResultV1 }>

  • storageDeposit(params: StorageDepositArgs): Promise<{ executionOutcome: FinalExecutionOutcome; result: StorageBalance<BN> }>
  • Deposit NEAR for storage staking. We recommend depositing 0.1 NEAR at a time to give users some room to place orders.

    Pass amount as a decimal amount of NEAR to deposit, eg, 0.1.

    Passing registrationOnly causes deposit in excess of the minimum required balance to be refunded. The minimum balance is computed at runtime, so it's recommended to pass at least 0.01 NEAR to avoid issues.

    The account to deposit for can be specified with accountId. Omit it to deposit for the caller's account.

    Parameters

    • params: StorageDepositArgs

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; result: StorageBalance<BN> }>

  • swap(tokenId: string, amount: BN, swaps: SwapParamsV1[]): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>
  • Parameters

    • tokenId: string
    • amount: BN
    • swaps: SwapParamsV1[]

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>

  • swapNear(amount: BN, swaps: SwapParamsV1[]): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>
  • Parameters

    • amount: BN
    • swaps: SwapParamsV1[]

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>

  • withdraw(tokenId: string, amount: BN): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>
  • Withdraw NEP 141 tokens or native NEAR. For native NEAR, the tokenId must be 'NEAR'.

    The amount must be decimal-aware, eg,

    import { decimalToBn } from '@tonic-foundation/utils';
    // Withdraw 1 NEAR
    tonic.withdraw('NEAR', decimalToBn(1, 24))
    // Withdraw 1 USDC
    tonic.withdraw('usdc.example.testnet', decimalToBn(1, 6))

    Parameters

    • tokenId: string
    • amount: BN

    Returns Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>

  • withdrawFt(tokenId: string, amount: BN): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>
  • withdrawNear(amount: BN): Promise<{ executionOutcome: FinalExecutionOutcome; response: any }>

Generated using TypeDoc