For the complete documentation index, see llms.txt. This page is also available as Markdown.

Deposits

Deposits are submitted directly to on-chain contracts through DepositClient.

Unlike orders and other exchange actions, deposits do not use the Exchange HTTP API.

A deposit integration requires:

  • An EVM wallet

  • A JSON-RPC provider

  • The correct chain ID

  • A configured or discoverable deposit-ledger contract

  • Settlement tokens in the connected wallet

Create a deposit client

import { createDepositClient } from "@gammaswap/v2-exchange-sdk";
import { Wallet } from "ethers";

const wallet = new Wallet(
  process.env.PRIVATE_KEY!,
);

const deposit = createDepositClient({
  rpcUrl: process.env.RPC_URL!,
  wallet,
  chainId: "84532",
});

The client connects the wallet to the configured RPC provider.

Before performing reads or transactions, it checks that the RPC network matches chainId.

Contract configuration

The deposit-ledger address can be resolved from the SDK’s default contracts for the selected chain.

It can also be supplied directly:

Custom contract overrides can be supplied with contracts:

Settlement-token decimals are currently required to be six:

Discover deposit contracts

Read the settlement-token address:

Response:

Read the Permit2 address:

Response:

Read the account-ledger address:

Response:

Parse a deposit amount

Deposit amounts use human decimal strings.

Response:

The settlement token uses six decimal places.

Additional examples:

Response:

Response:

Check the token balance

Read the connected wallet’s settlement-token balance:

Response:

This represents 250 settlement tokens when the token uses six decimals.

Read another owner’s balance:

Check token allowance

Response:

An owner and spender can also be supplied explicitly.

Approve the deposit ledger

The deposit ledger must have sufficient token allowance before it can transfer settlement tokens.

This method submits an on-chain token-approval transaction.

The exact approval input and returned transaction type are not included in the supplied SDK documentation. These fields should be copied from the SDK’s exported TypeScript definitions.

Approve Permit2

Permit-based deposits require an appropriate Permit2 token allowance.

This method submits an on-chain token-approval transaction.

The exact approval input and returned transaction type are not included in the supplied SDK documentation.

Submit a deposit

The method logs the deposit txId by default.

Disable transaction-ID logging with:

The exact deposit input and return type are not included in the supplied SDK documentation. They should be documented from the SDK’s exported TypeScript definitions.

Sign a deposit permit

signDepositPermit creates a signed Permit2 authorization without submitting a transaction.

Keep the signed permit with the deposit request that will consume it.

The exact returned permit structure is not included in the supplied SDK documentation.

Deposit with a permit

This method submits an on-chain deposit using the signed Permit2 authorization.

The exact input and return type should be copied from the SDK’s exported TypeScript definitions.

Check deposit state

Read the pending balance:

Read the processed balance:

Read the number of pending deposits:

Read the next pending deposit ID:

Read the processed-deposit index:

Read the minimum required block wait:

Check whether the next deposit can be processed:

Response:

  1. Create DepositClient.

  2. Verify the RPC network and chain ID.

  3. Read the settlement-token and deposit-ledger addresses.

  4. Parse the human deposit amount.

  5. Check the wallet’s settlement-token balance.

  6. Check the required token allowance.

  7. Approve the deposit ledger or Permit2 if necessary.

  8. Submit deposit or depositWithPermit.

  9. Record the transaction hash or deposit ID returned by the SDK.

  10. Monitor pending and processed deposit state.

Error handling

Deposit operations can fail because of:

  • RPC connection failures

  • Incorrect chain ID

  • Insufficient token balance

  • Insufficient allowance

  • Invalid amount precision

  • Wallet signature rejection

  • Contract reverts

  • Permit expiration or invalid permit data

Handle transaction failures through the error objects returned by the configured EVM provider and wallet.

Last updated