> ## Documentation Index
> Fetch the complete documentation index at: https://partner.tren.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# Amount Conventions and Base Units

> Every amount in the Trench Partner API is an integer string in base units. Lamports for SOL, 1e6 units for tokens, plus priority fee and tip minimums.

Every amount in the Partner API is sent as an integer string in base units, rather than as a number or a decimal value.

```json theme={null}
{ "maxSolIn": "100000000" }   // correct
{ "maxSolIn": 0.1 }           // rejected
{ "maxSolIn": "0.1" }         // rejected
```

## Units

| Value  | Unit           | Example                 |
| ------ | -------------- | ----------------------- |
| SOL    | Lamports       | `"100000000"` = 0.1 SOL |
| Tokens | 1e6 base units | `"1000000"` = 1 token   |

## Fee Minimums

Every write endpoint takes both fee fields, and this applies to trades and governance operations alike.

| Field                 | Minimum   |
| --------------------- | --------- |
| `priorityFeeLamports` | 1,000     |
| `tipLamports`         | 1,000,000 |

A value below either minimum causes the request to fail with `400 invalid_input`.

## Slippage Bounds

The `minTokensOut` field on a buy and `minSolOut` on a sell provide slippage protection when you set the bound yourself, and both are expressed in the same base units as the rest of the request. Sending `slippageBps` instead leaves them out entirely, since Trench then derives the bound from a quote.

<Warning>
  Setting either field to `"0"` disables slippage protection entirely, which means the trade will fill at whatever price the venue offers when it executes. Sending `slippageBps` instead has Trench derive the bound from a quote taken at execution, which avoids the problem altogether.
</Warning>

## Working With Base Units

We recommend using integers or bigints throughout, since floating-point arithmetic on lamports loses precision at balances users realistically hold.

<CodeGroup>
  ```javascript Node.js theme={null}
  const LAMPORTS_PER_SOL = 1_000_000_000n;
  const TOKEN_UNITS = 1_000_000n;

  const solToLamports = (sol) => BigInt(Math.round(sol * 1e9)).toString();
  const tokensToUnits = (tokens) => BigInt(Math.round(tokens * 1e6)).toString();

  // Apply a 1% slippage tolerance to a quote of 5,000 tokens.
  const withSlippage = (units, bps) => ((units * BigInt(10_000 - bps)) / 10_000n).toString();

  const body = {
    mint,
    maxSolIn: solToLamports(0.1),
    minTokensOut: withSlippage(5000n * TOKEN_UNITS, 100),
    priorityFeeLamports: "20000",
    tipLamports: "1000000",
  };
  ```

  ```python Python theme={null}
  from decimal import Decimal

  LAMPORTS_PER_SOL = 1_000_000_000
  TOKEN_UNITS = 1_000_000

  def sol_to_lamports(sol: str) -> str:
      return str(int(Decimal(sol) * LAMPORTS_PER_SOL))

  def tokens_to_units(tokens: str) -> str:
      return str(int(Decimal(tokens) * TOKEN_UNITS))

  def with_slippage(units: int, bps: int) -> str:
      return str(units * (10_000 - bps) // 10_000)

  body = {
      "mint": mint,
      "maxSolIn": sol_to_lamports("0.1"),
      "minTokensOut": with_slippage(5000 * TOKEN_UNITS, 100),
      "priorityFeeLamports": "20000",
      "tipLamports": "1000000",
  }
  ```
</CodeGroup>

<Tip>
  Amounts are returned as strings as well, so parse them into bigints rather than floats before doing any arithmetic on the response.
</Tip>
