Raindex SDK Documentation
    Preparing search index...

    Class RaindexVault

    Represents a vault with balance and token information within a given orderbook.

    A vault is a fundamental component that holds tokens and participates in order execution. Each vault has a unique identifier, current balance, associated token metadata, and belongs to a specific orderbook contract on the blockchain.

    Vaults can serve different roles in relation to orders - they can provide tokens (input), receive tokens (output), or both (input/output), depending on the trading algorithm.

    Index

    Properties

    balance: Float
    chainId: number
    formattedBalance: string
    id: `0x${string}`
    orderbook: `0x${string}`
    ordersAsInput: RaindexOrderAsIO[]
    ordersAsOutput: RaindexOrderAsIO[]
    owner: `0x${string}`
    vaultId: bigint
    vaultType: undefined | RaindexVaultType

    Methods

    • Returns void

    • Gets the current ERC20 allowance for a vault

      Determines how much the orderbook contract is currently approved to spend on behalf of the vault owner.

      const result = await vault.getAllowance();
      if (result.error) {
      console.error("Cannot check allowance:", result.error.readableMsg);
      return;
      }
      const allowance = result.value;
      // Do something with the allowance

      Returns Promise<WasmEncodedResult<string>>

      Current allowance amount in token's smallest unit (e.g., "1000000000000000000" for 1 token with 18 decimals)

    • Generates ERC20 approval calldata for vault deposits

      Creates the contract calldata needed to approve the orderbook contract to spend tokens for a vault deposit, but only if additional approval is needed.

      const result = await vault.getApprovalCalldata("20.75");
      if (result.error) {
      console.error("Approval error:", result.error.readableMsg);
      return;
      }
      const calldata = result.value;
      // Do something with the calldata

      Parameters

      • amount: Float

        Amount requiring approval in Float value

      Returns Promise<WasmEncodedResult<`0x${string}`>>

      Encoded approval calldata as hex string

    • Fetches balance change history for a vault

      Retrieves chronological list of deposits, withdrawals, and trades affecting a vault's balance.

      const result = await vault.getBalanceChanges();
      if (result.error) {
      console.error("Error fetching history:", result.error.readableMsg);
      return;
      }
      const changes = result.value;
      // Do something with the changes

      Parameters

      • Optionalpage: null | number

        Optional page number (default to 1)

      Returns Promise<WasmEncodedResult<RaindexVaultBalanceChange[]>>

      Array of balance change events

    • Generates transaction calldata for depositing tokens into a vault

      Creates the contract calldata needed to deposit a specified amount of tokens into a vault.

      const result = await vault.getDepositCalldata(vault, "10.5");
      if (result.error) {
      console.error("Cannot generate deposit:", result.error.readableMsg);
      return;
      }
      const calldata = result.value;
      // Do something with the calldata

      Parameters

      • amount: Float

        Amount to deposit in Float value

      Returns Promise<WasmEncodedResult<`0x${string}`>>

      Encoded transaction calldata as hex string

    • Fetches the balance of the owner for this vault

      Retrieves the current balance of the vault owner. The returned balance is an object containing both raw and formatted values.

      const result = await vault.getOwnerBalance();
      if (result.error) {
      console.error("Error fetching balance:", result.error.readableMsg);
      return;
      }
      const accountBalance = result.value;
      console.log("Raw balance:", accountBalance.balance);
      console.log("Formatted balance:", accountBalance.formattedBalance);

      Returns Promise<WasmEncodedResult<AccountBalance>>

      Owner balance in both raw and human-readable format

    • Generates transaction calldata for withdrawing tokens from a vault

      Creates the contract calldata needed to withdraw a specified amount of tokens from a vault.

      const result = await vault.getWithdrawCalldata("55.2");
      if (result.error) {
      console.error("Cannot generate withdrawal:", result.error.readableMsg);
      return;
      }
      const calldata = result.value;
      // Do something with the calldata

      Parameters

      • amount: Float

        Amount to withdraw in Float value

      Returns Promise<WasmEncodedResult<`0x${string}`>>

      Encoded transaction calldata as hex string