# Quote joining the queue

`POST /collateral/join/check` · Lithos client API · Collateral Market · requires the `api_key` header

Source: https://lithosprotocol.org/docs/api/check-collateral-join

What creating `count` positions costs right now: principal per position, network fee per join, and the permit for each. Permits escalate because each join lengthens the queue the next one is priced from.

`priorityFeeEachNanoErgs` is the ERG added to the box above the floor, so it raises `principalEachNanoErgs` one for one. A miner spends whichever collateral box pays it most, so a fee buys a place ahead of the boxes offering nothing. Past `breakEvenPriorityFeeNanoErgs` the 3 ERG coinbase no longer covers the principal and `netAtCoinbaseEachNanoErgs` goes negative — the rest then has to come from the transaction fees of the block the box is mined against.

Also reports whether the join would be accepted: check `manualJoinAllowed` and `blockedReason` before enabling a send control, and send no more than `fitting` positions. While `emission.autoCollateralize` is on, every quote is blocked with `AUTO_COLLATERALIZE`: the client's own pass owns joining, so turn it off to join by hand. Requires an `api_key`, since the quote names this wallet's lender addresses and its shortfall.

## Request body

`CollateralJoinCheckRequest`, application/json.

- `count` (integer · int32): Positions to create, each under its own key
- `priorityFeeEachNanoErgs` (string): nanoERG each position adds above the 2.915 ERG floor. Part of it goes to whichever miner spends the collateral box, which is what buys the position priority. Omitted or '0' posts at the floor; anything else is at least minPriorityFeeNanoErgs.

## Responses

### 200: Quote for the requested number of positions

`CollateralJoinQuote`

- `count` (integer · int32, required)
- `principalEachNanoErgs` (string, required): What one position locks up: the 2915000000 floor plus the whole priority fee. Identical for every position in the quote. Decimal string.
- `priorityFeeEachNanoErgs` (string, required): The fee this quote was priced at, echoed back. Decimal string.
- `minPriorityFeeNanoErgs` (string, required): The smallest non-zero fee that may be posted. Fixed at 1000000 (0.001 ERG); below it the block's finder is left too little to be worth the output it is paid in.
- `breakEvenPriorityFeeNanoErgs` (string, required): The largest fee the 3 ERG coinbase repays on its own, which is the whole spread a lender earns. Fixed at 85000000. A fee above it is accepted; the difference then has to come from the mined block's transaction fees.
- `netAtCoinbaseEachNanoErgs` (string, required): Block reward minus principal, per position, before the mined block's own fees. **Signed** — negative above breakEvenPriorityFeeNanoErgs. Decimal string.
- `txFeeEachNanoErgs` (string, required): Network fee per join transaction. Decimal string.
- `permitsLit` (string[], required): Permit for each position, in join order. Each join lengthens the queue, so these escalate. Decimal strings. 
- `permitTotalLit` (string, required): Sum of `permitsLit`. Decimal string.
- `totalNanoErgs` (string, required): Total ERG leaving the wallet — principals plus fees. Decimal string.
- `firstPosition` (integer · int64, required): Queue position the first join takes; the rest follow consecutively
- `emissionTipBoxId` (string, required): Emission box the quote was made against. Send back as `expectedEmissionBoxId`.
- `affordNow` (boolean, required): Whether the wallet can cover it today
- `shortfallNanoErgs` (string, required): How much short the wallet is when `affordNow` is false. Decimal string.
- `ownRoomLeft` (integer · int32, required): Positions the configured exposure budget would still allow after this
- `manualJoinAllowed` (boolean, required): Whether `POST /collateral/join` will accept this join. Disable the send control when false. The join endpoint checks the same conditions itself, so a quote taken before a configuration change does not license the send. 
- `blockedReason` (string, one of AUTO_COLLATERALIZE, BUDGET_EXHAUSTED, WALLET_LOCKED, NO_LENDER_KEYS, INSUFFICIENT_FUNDS): Why `manualJoinAllowed` is false; absent when it is true. Only the first applicable reason is reported, in the order listed above. `AUTO_COLLATERALIZE` — the client joins on its own timer and refuses manual joins. `BUDGET_EXHAUSTED` — `maxOwnCollateral` leaves room for fewer positions than requested. `WALLET_LOCKED` — new keys are needed, but the node wallet could not be unlocked to derive them. `NO_LENDER_KEYS` — `fitting` is below `keysRequired`. `INSUFFICIENT_FUNDS` — the wallet cannot cover `totalNanoErgs`. 
- `lenderAddresses` (string[], required): The lender keys this join would use, in join order, matching `permitsLit` index for index. Shorter than `count` when the join would derive new keys to make up the difference; those addresses do not exist yet and cannot be named in advance. Empty when `blockedReason` is `NO_LENDER_KEYS`. 
- `freeLenderKeys` (integer · int32, required): Keys with status FREE at the moment of quoting
- `keysRequired` (integer · int32, required): Keys this join consumes — one per position, so equal to `count`
- `keysDerivable` (integer · int32, required): Keys the join may still derive through the node wallet, below `emission.maxLenderKeys`. The client unlocks the node wallet itself when a derivation needs it. 
- `fitting` (integer · int32, required): Positions a join would accept right now: the smaller of the room under `maxOwnCollateral` and the free keys plus those that can be derived. A join asking for more is refused whole. 

### 400: Malformed body, or a count outside 1..25.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 503: Node or wallet unavailable. Retry.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### default: Error

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

## Example request

```bash
curl -X POST "http://localhost:9000/collateral/join/check" \
  -H "api_key: $LITHOS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "count": 3, "priorityFeeEachNanoErgs": "10000000" }'
```

## Example response

```json
{
  "count": 3,
  "principalEachNanoErgs": "2925000000",
  "priorityFeeEachNanoErgs": "10000000",
  "minPriorityFeeNanoErgs": "1000000",
  "breakEvenPriorityFeeNanoErgs": "85000000",
  "netAtCoinbaseEachNanoErgs": "60000000",
  "txFeeEachNanoErgs": "1000000",
  "permitsLit": [
    "19370000000",
    "19380000000",
    "19390000000"
  ],
  "permitTotalLit": "58140000000",
  "totalNanoErgs": "8748000000",
  "firstPosition": 1247,
  "emissionTipBoxId": "88c297f99da7172f6aa20efbead69aa40e2b7734a1873d66ca1db6b19d214db6",
  "affordNow": true,
  "shortfallNanoErgs": "0",
  "ownRoomLeft": 4,
  "manualJoinAllowed": true,
  "blockedReason": "AUTO_COLLATERALIZE",
  "lenderAddresses": [
    "3WwbQFz3vgi8ChY9dM1haQLGDeQYe5U9z98bwWW4TqxxEAvyYu5y"
  ],
  "freeLenderKeys": 4,
  "keysRequired": 3,
  "keysDerivable": 28,
  "fitting": 3
}
```
