DocumentationAPI Reference~1382 words
Source: docs/api/SEQUENCER.en.md

#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

  1. One ticket is one transaction. After rejected, that ticket is dead. Send a new join.
  2. After turn, the client signs and sends submit before deadlineMs elapses. The default allowance is 5,000 ms, measured from receipt. The transaction spends the poolOutpoint from that turn and uses its step, poolValue, and context.
  3. The join message has no price-limit field. If step (or, after harvest, ammState) is outside the client's range, the client sends leave instead of submit.
  4. A pearl can have at most 25 unconfirmed pool transactions in a block. The server only emits turn when chainDepth is 24 or less. The default when the chain is full is to keep the ticket queued and send turn after the next block. A deployment can instead reject with chain_full.
  5. buy, sell, and graduate apply only while the pearl is on the curve. swap applies only after it is harvested (status "amm").
mermaid
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
    end

While 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.

LimitDefault
Joins per address10 per minute
Joins per IP30 per minute
Open tickets for one address on one pearl1
Open tickets per IP5
Inbound frames per connection20 per second. Excess closes the socket with code 1008
Message size64 KiB. Larger closes with code 1009
Binary frameClosed with code 1003
Idle connection60 seconds without a protocol pong or an inbound frame, then the socket is terminated
Protocol pingEvery 20 seconds
HelloA socket that neither sends join nor resumes within 10 seconds closes with code 4002
Connections20,000 total, 1,000 per IP. Past that the handshake is HTTP 503 with Retry-After: 1
OriginDefault 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

FieldTypeRule
type"join"Required
reqIdstringClient id, at most 64 characters. The same reqId, pearl, and address resumes an open ticket
tokenIdoutpointPearl id, "txid:vout"
intentstring"buy", "sell", "graduate", or "swap"
lotsintegerCurve 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
addressaddressP2TR 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.

json
{
  "type": "join",
  "reqId": "req-1763741200-1",
  "tokenId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
  "intent": "buy",
  "lots": 5,
  "address": "tprl1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
}
json
{
  "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.

json
{
  "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

json
{ "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

json
{ "type": "ping" }

#Server messages

#queued

json
{
  "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.

FieldTypeMeaning
ticketstringThe ticket to submit or leave
poolOutpointoutpointThe pool output this transaction must spend
stepinteger 0 through 800Curve layers already sold
poolValueGrainStrPool PRL in grains
deadlineMspositive integerMilliseconds left to submit. Default 5000
phase"curve" or "amm"Present on turns from the running service
ammStateinteger or nullHarvested-market state, from -1,610 to 4,607. null on the curve
ammReserveTokensinteger or nullWhole tokens in the pool after harvest. null on the curve
context.chainDepthinteger 0 through 24Unconfirmed pool transactions already ahead of this one
context.feeRatepositive numberSuggested miner fee in grains per virtual byte, so the unconfirmed chain can be mined together
context.poolTxHexhex or nullRaw hex of the transaction that created the pool output. Non-null when that transaction is still unconfirmed. A PSBT needs it
context.prevTxsmap of txid to hex, optionalEarlier 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
json
{
  "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

json
{
  "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

json
{
  "type": "rejected",
  "ticket": "tkt_01JEXAMPLE",
  "reason": "deadline",
  "message": "no submit within 5000 ms"
}

message is diagnostic. Branch on reason.

reasonWhenClient action
deadlineNo submit before deadlineMsTell the user. join again if they still want the trade
stale_poolThe transaction does not spend the turn's poolOutpointFix the builder and join again
invalid_txThe transaction does not decode or does not match the curve or script rulesRebuild from the latest turn
node_rejectedThe Pearl node refused the broadcast. message includes the node textCheck the miner fee and whether an input is already spent
chain_fullThe unconfirmed chain is already 25 and this deployment rejects instead of waitingWait for the next block, then join again
graduatedA curve buy, sell, or graduate arrived after the pearl was harvestedStop curve orders. Use swap on the harvested pool
slippageAn internal limit, if one is configured, was exceeded. The public join body cannot set that limitSend leave when the turn is outside the client's own range
bad_requestBad JSON, schema failure, unknown ticket, or a join rate limitFix the message or wait, then retry

A join that fails before a ticket exists uses "ticket": "".

#pong

json
{ "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.

ParameterInRule
tokenIdpathOutpoint. Apply encodeURIComponent
http
GET /seq/v1/pools/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%3A1 HTTP/1.1
Host: 127.0.0.1:3002

200 body, curve example. phase "amm" fills ammState and ammReserveTokens the same way a turn does. chainDepth here can be 25. queueLength counts waiting tickets.

json
{
  "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.

StatuscodeWhen
400bad_requesttokenId is not an outpoint
404not_foundThe queue does not know this pearl yet
429rate_limitedThis IP is over the read limit
500internalThe 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.

NACRE · The first keyless launchpad on Pearl