# Amount Units

How the API expects and returns token and fiat amounts.

## Overview

Crypto amounts you send are **integer strings in the token's smallest unit**. Fiat amounts are decimals. Responses are not uniform: some return amounts as strings, others as JSON numbers — check each endpoint's response.

## Crypto Amounts

Multiply the human amount by 10decimals. [List Tokens](https://docs.aureahub.com/docs/tokens-list.md) returns each token's `decimals`.

- ETH and xDAI: 18 decimals — 1 = `"1000000000000000000"`.
- EUR.e (Monerium, Gnosis): 18 decimals — 1 = `"1000000000000000000"`.
- USDC: 6 decimals — 1 = `"1000000"`.
- SOL: 9 decimals (lamports) — 1 = `"1000000000"`. SPL tokens use their mint's decimals.

| Field | Format |
| --- | --- |
| POST /v1/transactions/ — amount | Integer string, smallest unit |
| POST /v1/swap/approve — amount | Integer string, smallest unit |
| POST /v1/swap/sign-permit, POST /v1/swap/execute-gasless — amounts | Integer string, smallest unit (wei) |
| POST /v1/swap/quote — fromAmount | The pattern also accepts decimals, but Aurea passes the value to LI.FI unchanged, and LI.FI expects the smallest unit: send an integer string |
| POST /v1/aave/* — amounts | Integer string in wei (18 decimals for EUR.e) |
| POST /v1/ramp/bank/payout/initiate — cryptoAmount | Integer string, converted with 6 decimals for every currency |

> ⚠️ Never send a decimal such as `"1.5"` where the smallest unit is expected, and send integer amounts as strings: JSON numbers lose precision above 253.

## Fiat Amounts

| Field | Format |
| --- | --- |
| POST /v1/ramp/bank/payin/checkout — fiatAmount | Decimal string with at most 2 decimals, e.g. "50.00" |
| POST /v1/ramp/bank/payout/initiate (response) — fiatAmount, exchangeRate | Strings; fiatAmount has 2 decimals |
| GET /v1/ramp/bank/payin/deposits — fiatAmount | JSON number |
| GET /v1/ramp/bank/payin/transactions — fiatAmount, cryptoAmount, exchangeRate | JSON numbers |
| GET /v1/ramp/bank/payin/transactions — fiatFeeAmount, fiatRate, networkFee, breakdown[].amount | Exact decimal text without trailing zeros, e.g. "0.8840880389680685" |
| GET /v1/ramp/bank/payin/deposits and /transactions — refunds[].amount | Exact decimal text without trailing zeros |
| POST /v1/ramp/bank/payin/sandbox/simulate-deposit — amount | JSON number, at most 15000 |
| GET /v1/portfolio/performance — changeEur, totalEur, totalUsd | JSON numbers |

## Conversion Helpers

```typescript
// Human -> smallest unit (extra decimal digits are truncated)
export function toSmallest(amount: string | number, decimals: number): string {
  const s = String(amount).trim();
  const neg = s.startsWith('-');
  const [i, f = ''] = (neg ? s.slice(1) : s).split('.');
  const frac = (f + '0'.repeat(decimals)).slice(0, decimals);
  const raw  = (BigInt(i || '0') * 10n ** BigInt(decimals)) + BigInt(frac || '0');
  return (neg ? -raw : raw).toString();
}

// Smallest unit -> human
export function fromSmallest(value: string | bigint, decimals: number): string {
  const n = typeof value === 'bigint' ? value : BigInt(value);
  const neg = n < 0n;
  const abs = neg ? -n : n;
  const base = 10n ** BigInt(decimals);
  const whole = abs / base;
  const frac  = (abs % base).toString().padStart(decimals, '0').replace(/0+$/, '');
  const out = frac.length ? `${whole}.${frac}` : whole.toString();
  return neg ? '-' + out : out;
}

toSmallest('1.5', 6);         // "1500000"               (USDC)
toSmallest('10', 18);         // "10000000000000000000"  (EUR.e)
fromSmallest('1500000', 6);   // "1.5"
```

---

Web version: https://docs.aureahub.com/#amounts
