> For the complete documentation index, see [llms.txt](https://docs.gammaswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gammaswap.com/developers/guides/deposits.md).

# 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

```ts
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:

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

Custom contract overrides can be supplied with `contracts`:

```ts
const deposit = createDepositClient({
  rpcUrl: process.env.RPC_URL!,
  wallet,
  chainId: "84532",
  contracts: {
    // Chain-specific contract overrides
  },
});
```

Settlement-token decimals are currently required to be six:

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

### Discover deposit contracts

Read the settlement-token address:

```ts
const settlementToken =
  await deposit.getSettlementToken();
```

Response:

```ts
"0x2222222222222222222222222222222222222222"
```

Read the Permit2 address:

```ts
const permit2 = await deposit.getPermit2();
```

Response:

```ts
"0x3333333333333333333333333333333333333333"
```

Read the account-ledger address:

```ts
const accountLedger =
  await deposit.getAccountLedger();
```

Response:

```ts
"0x4444444444444444444444444444444444444444"
```

### Parse a deposit amount

Deposit amounts use human decimal strings.

```ts
const amount = deposit.parseAmount("100.25");
```

Response:

```ts
100250000n
```

The settlement token uses six decimal places.

Additional examples:

```ts
deposit.parseAmount("1");
```

Response:

```ts
1000000n
```

```ts
deposit.parseAmount("0.01");
```

Response:

```ts
10000n
```

### Check the token balance

Read the connected wallet’s settlement-token balance:

```ts
const balance =
  await deposit.getSettlementTokenBalance();
```

Response:

```ts
250000000n
```

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

Read another owner’s balance:

```ts
const balance =
  await deposit.getSettlementTokenBalance(
    "0x5555555555555555555555555555555555555555",
  );
```

### Check token allowance

```ts
const allowance =
  await deposit.getSettlementTokenAllowance();
```

Response:

```ts
1000000000n
```

An owner and spender can also be supplied explicitly.

```ts
const allowance =
  await deposit.getSettlementTokenAllowance(
    "0x3333333333333333333333333333333333333333",
    wallet.address,
  );
```

### Approve the deposit ledger

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

```ts
const result =
  await deposit.approveDepositLedger({
    // Approval input
  });
```

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.

```ts
const result =
  await deposit.approvePermit2({
    // Approval input
  });
```

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

```ts
const result = await deposit.deposit({
  // Deposit input
});
```

The method logs the deposit `txId` by default.

Disable transaction-ID logging with:

```ts
const result = await deposit.deposit({
  // Deposit input
  logTxId: false,
});
```

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.

```ts
const permit =
  await deposit.signDepositPermit({
    // Permit input
  });
```

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

```ts
const result =
  await deposit.depositWithPermit({
    // Deposit and signed permit input
  });
```

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:

```ts
const pendingBalance =
  await deposit.getPendingBalance();
```

Read the processed balance:

```ts
const processedBalance =
  await deposit.getProcessedBalance();
```

Read the number of pending deposits:

```ts
const pendingCount =
  await deposit.getPendingDepositCount();
```

Read the next pending deposit ID:

```ts
const nextDepositId =
  await deposit.getNextPendingDepositId();
```

Read the processed-deposit index:

```ts
const processedIndex =
  await deposit.getProcessedDepositIndex();
```

Read the minimum required block wait:

```ts
const minBlockWait =
  await deposit.getMinBlockWait();
```

Check whether the next deposit can be processed:

```ts
const canProcess =
  await deposit.canProcessNext();
```

Response:

```ts
true
```

### Recommended deposit flow

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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gammaswap.com/developers/guides/deposits.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
