#Queue service
This page specifies the queue that orders pool transactions. The service id is sequencer. The WebSocket path is /seq/v1 and the pool snapshot is GET /seq/v1/pools/:tokenId. It is for wallets and bots that buy, sell, harvest, or swap.
The queue only decides order. It does not hold PRL and it does not set the price. The client builds and signs the transaction from the turn message. The pool still moves only when the Pearl node accepts a transaction that satisfies the script. Curve behavior here has been exercised on a local test chain. There is no external audit yet.
A plain HTTP GET /seq/v1 (no WebSocket upgrade) returns 426 with an ApiError body, code bad_request.
#Rules
- One ticket is one transaction. After
rejected, that ticket is dead. Send a newjoin. - After
turn, the client signs and sendssubmitbeforedeadlineMselapses. The default allowance is5,000ms, measured from receipt. The transaction spends thepoolOutpointfrom that turn and uses itsstep,poolValue, andcontext. - The
joinmessage has no price-limit field. Ifstep(or, after harvest,ammState) is outside the client's range, the client sendsleaveinstead ofsubmit. - A pearl can have at most
25unconfirmed pool transactions in a block. The server only emitsturnwhenchainDepthis24or less. The default when the chain is full is to keep the ticket queued and sendturnafter the next block. A deployment can instead reject withchain_full. buy,sell, andgraduateapply only while the pearl is on the curve.swapapplies only after it is harvested (status"amm").
sequenceDiagram
participant C as Client
participant S as Queue
participant N as Pearl node
C->>S: join
S-->>C: queued
S-->>C: turn
alt Price moved too far
C->>S: leave
else Signed before deadlineMs
C->>S: submit rawTx
S->>N: broadcast
alt Node accepts
S-->>C: accepted
else Timeout, stale pool, bad transaction, or node refusal
S-->>C: rejected
end
endWhile a ticket waits, the server may send queued again with a smaller position. position 0 means that ticket is next.
#Connect
Local URL: ws://127.0.0.1:3002/seq/v1.
| Limit | Default |
|---|---|
| Joins per address | 10 per minute |
| Joins per IP | 30 per minute |
| Open tickets for one address on one pearl | 1 |
| Open tickets per IP | 5 |
| Inbound frames per connection | 20 per second. Excess closes the socket with code 1008 |
| Message size | 64 KiB. Larger closes with code 1009 |
| Binary frame | Closed with code 1003 |
| Idle connection | 60 seconds without a protocol pong or an inbound frame, then the socket is terminated |
| Protocol ping | Every 20 seconds |
| Hello | A socket that neither sends join nor resumes within 10 seconds closes with code 4002 |
| Connections | 20,000 total, 1,000 per IP. Past that the handshake is HTTP 503 with Retry-After: 1 |
| Origin | Default allows localhost only. Other origins get HTTP 403 on the upgrade |
A refused join is a rejected frame with reason "bad_request" and an empty ticket, not an HTTP 429. The message text can change.
{ "type": "ping" } returns an application-level { "type": "pong" }. That is separate from the protocol ping.
#Client messages
#join
| Field | Type | Rule |
|---|---|---|
type | "join" | Required |
reqId | string | Client id, at most 64 characters. The same reqId, pearl, and address resumes an open ticket |
tokenId | outpoint | Pearl id, "txid:vout" |
intent | string | "buy", "sell", "graduate", or "swap" |
lots | integer | Curve buy or sell: 1, 2, 5, 10, 20, or 50. graduate: 0. swap: one of 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 |
address | address | P2TR address that signs |
side | "buy" or "sell" | Required when intent is "swap". Omit it otherwise |
lots is how many layers this order moves. On the curve, one layer is 1,000,000 tokens. A swap's lots uses the harvested-market sizes above, not the curve set.
{
"type": "join",
"reqId": "req-1763741200-1",
"tokenId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
"intent": "buy",
"lots": 5,
"address": "tprl1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
}{
"type": "join",
"reqId": "req-1763741200-2",
"tokenId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
"intent": "swap",
"side": "buy",
"lots": 8,
"address": "tprl1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
}#submit
rawTx is lowercase hex of the signed transaction. It must spend the poolOutpoint from the current turn.
{
"type": "submit",
"ticket": "tkt_01JEXAMPLE",
"rawTx": "020000000001"
}The hex above is only long enough to show the field. A real transaction is the full serialization.
#leave
{ "type": "leave", "ticket": "tkt_01JEXAMPLE" }leave is valid while the ticket is queued or during a turn. An unknown ticket returns rejected with reason "bad_request".
#ping
{ "type": "ping" }#Server messages
#queued
{
"type": "queued",
"reqId": "req-1763741200-1",
"ticket": "tkt_01JEXAMPLE",
"position": 2
}#turn
Build the transaction from this message. Curve turns include phase "curve" with ammState and ammReserveTokens set to null. Harvested-market turns set phase to "amm" and fill both AMM fields. step on an AMM turn stays at 800.
| Field | Type | Meaning |
|---|---|---|
ticket | string | The ticket to submit or leave |
poolOutpoint | outpoint | The pool output this transaction must spend |
step | integer 0 through 800 | Curve layers already sold |
poolValue | GrainStr | Pool PRL in grains |
deadlineMs | positive integer | Milliseconds left to submit. Default 5000 |
phase | "curve" or "amm" | Present on turns from the running service |
ammState | integer or null | Harvested-market state, from -1,610 to 4,607. null on the curve |
ammReserveTokens | integer or null | Whole tokens in the pool after harvest. null on the curve |
context.chainDepth | integer 0 through 24 | Unconfirmed pool transactions already ahead of this one |
context.feeRate | positive number | Suggested miner fee in grains per virtual byte, so the unconfirmed chain can be mined together |
context.poolTxHex | hex or null | Raw hex of the transaction that created the pool output. Non-null when that transaction is still unconfirmed. A PSBT needs it |
context.prevTxs | map of txid to hex, optional | Earlier transactions the signer needs: the launch reveal, the pool transaction, and the inventory source. Absent when the service cannot load them. The map does not include the token output spent on a sell |
{
"type": "turn",
"ticket": "tkt_01JEXAMPLE",
"poolOutpoint": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc:0",
"step": 5,
"poolValue": "10000",
"deadlineMs": 5000,
"phase": "curve",
"ammState": null,
"ammReserveTokens": null,
"context": {
"chainDepth": 0,
"feeRate": 1,
"poolTxHex": null
}
}poolValue "10000" is the default initial pool (0.0001 PRL). A live turn replaces it with the current pool.
#accepted
{
"type": "accepted",
"ticket": "tkt_01JEXAMPLE",
"txid": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
"seq": 16
}seq increases per pearl. It is not a WebSocket resume cursor. Confirmation and drop show up on the indexer feed.
#rejected
{
"type": "rejected",
"ticket": "tkt_01JEXAMPLE",
"reason": "deadline",
"message": "no submit within 5000 ms"
}message is diagnostic. Branch on reason.
reason | When | Client action |
|---|---|---|
deadline | No submit before deadlineMs | Tell the user. join again if they still want the trade |
stale_pool | The transaction does not spend the turn's poolOutpoint | Fix the builder and join again |
invalid_tx | The transaction does not decode or does not match the curve or script rules | Rebuild from the latest turn |
node_rejected | The Pearl node refused the broadcast. message includes the node text | Check the miner fee and whether an input is already spent |
chain_full | The unconfirmed chain is already 25 and this deployment rejects instead of waiting | Wait for the next block, then join again |
graduated | A curve buy, sell, or graduate arrived after the pearl was harvested | Stop curve orders. Use swap on the harvested pool |
slippage | An internal limit, if one is configured, was exceeded. The public join body cannot set that limit | Send leave when the turn is outside the client's own range |
bad_request | Bad JSON, schema failure, unknown ticket, or a join rate limit | Fix the message or wait, then retry |
A join that fails before a ticket exists uses "ticket": "".
#pong
{ "type": "pong" }The socket does not emit a separate frame when a turn is revoked or when a broadcast transaction later confirms. If the pool moves during a turn, submit can come back rejected with stale_pool or invalid_tx. The client joins again. Confirmation status comes from the WebSocket feed or GET /api/v1/tx/:txid.
#GET /seq/v1/pools/:tokenId
Returns the queue's current view of one pearl, including unconfirmed depth and how many tickets are waiting.
| Parameter | In | Rule |
|---|---|---|
tokenId | path | Outpoint. Apply encodeURIComponent |
GET /seq/v1/pools/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%3A1 HTTP/1.1
Host: 127.0.0.1:3002200 body, curve example. phase "amm" fills ammState and ammReserveTokens the same way a turn does. chainDepth here can be 25. queueLength counts waiting tickets.
{
"tokenId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
"phase": "curve",
"ammState": null,
"ammReserveTokens": null,
"poolOutpoint": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc:0",
"step": 5,
"poolValue": "10000",
"confirmedStep": 0,
"chainDepth": 1,
"queueLength": 2
}The response sets Cache-Control: no-store.
| Status | code | When |
|---|---|---|
400 | bad_request | tokenId is not an outpoint |
404 | not_found | The queue does not know this pearl yet |
429 | rate_limited | This IP is over the read limit |
500 | internal | The in-memory snapshot failed the schema |
Rate limit: 300 reads per minute per IP. This 429 does not set Retry-After. Back off for about a minute.
#Resume
If the socket drops, the client has 30 seconds to reconnect to /seq/v1?ticket=<ticket>. The server replays queued and, if a turn is still inside its deadline, a turn whose deadlineMs is the time left. A finished ticket replays the last accepted or rejected. A missing ticket returns rejected with reason "bad_request".
Sending join again with the same tokenId, address, and reqId also rebinds an open ticket. A second connection for that ticket closes the previous socket with code 4000.
#Next
Watch the broadcast transaction on the WebSocket feed. Load pearl and trade history from the Indexer HTTP API.