Raindex SDK Documentation
    Preparing search index...

    Class RaindexVault

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

    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 raindex 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}`
    ordersAsInput: RaindexOrderAsIO[]
    ordersAsOutput: RaindexOrderAsIO[]
    owner: `0x${string}`
    raindex: `0x${string}`
    vaultId: bigint
    vaultType: undefined | RaindexVaultType

    Methods

    • Returns void

    • Returns void

    • Gets the current ERC20 allowance for a vault

      Determines how much the raindex 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)

    • Fetches balance change history for a vault

      Retrieves chronological list of deposits, withdrawals, and trades affecting a vault's balance. Optionally filter by balance change type.

      // Fetch all balance changes
      const result = await vault.getBalanceChanges();
      if (result.error) {
      console.error("Error fetching history:", result.error.readableMsg);
      return;
      }
      const changes = result.value;

      // Fetch only deposits and withdrawals
      const filteredResult = await vault.getBalanceChanges(1, ["deposit", "withdrawal"]);

      Parameters

      • Optionalpage: null | number

        Optional page number (default to 1)

      • Optionalfilter_types: null | VaultBalanceChangeFilter[]

        Optional filter types array (deposit, withdrawal, takeOrder, clear, clearBounty)

      Returns Promise<WasmEncodedResult<RaindexVaultBalanceChange[]>>

      Array of balance change events

    • Generates every transaction calldata associated with a vault in a single call

      Produces the approval (when needed), deposit and withdraw calldata for the vault in one method so callers don't have to invoke them separately. The on-chain allowance is read only once.

      The returned approval is undefined when the raindex contract already has a sufficient allowance to spend the requested amount, in which case no approval transaction is needed.

      const result = await vault.getCalldatas("10.5");
      if (result.error) {
      console.error("Cannot generate calldatas:", result.error.readableMsg);
      return;
      }
      const { approval, deposit, withdraw } = result.value;
      // `approval` is undefined when no approval is needed

      Parameters

      • amount: Float

        Amount in Float value

      Returns Promise<WasmEncodedResult<RaindexVaultCalldatas>>

      Approval (when needed), deposit and withdraw calldata for the amount

    • 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

    • Normalizes an amount to the largest token-decimal amount that can be withdrawn.

      Converts the provided [Float] through this vault token's fixed-decimal precision, truncating any sub-token-base-unit dust, then returns it as a [Float] that can be safely encoded for withdraw calldata.

      Parameters

      • amount: Float

        Amount in Float value

      Returns WasmEncodedResult<Float>

      Float amount normalized to this vault token's withdrawable precision