ALTAIR ← For operators Play the demo ES

Altair — Wallet integration

This document is for whoever connects the game to an operator's wallet. It explains what the game needs from the money system and what has to be written to plug it in.

Spanish version: WALLET.es.md.

Status

The integration is written and tested against a wallet that fails on purpose. What is left for your specification is a configuration file, not code.

The distinction matters, because it is the difference between days and weeks. The names differ between aggregators — routes, authentication, field names, error codes, rollback semantics. The mechanics do not: the idempotent retry, what to do when a response is lost, and why a doubtful bet is cancelled while a doubtful win is never cancelled are the same in every seamless specification.

So the mechanics live in backend/src/game/carteraRemota.ts, and the names live in a JSON file (backend/operador.ejemplo.json). Send the specification and the work is translating vocabulary, with the accounting already proven.

The interface

backend/src/game/cartera.ts

interface Cartera {
  saldo(userId): Promise<number>;                      // balance
  apostar(movimiento): Promise<{ aplicado, saldo }>;   // debit
  pagar(movimiento): Promise<{ aplicado, saldo }>;     // credit
  anular(referencia): Promise<void>;                   // rollback
}

A movement carries:

FieldPurpose
referenciaIdentifies the operation. Idempotency.
userIdPlayer
rondaReconciliation on the operator's side
slotWhich of the two bets
importeMinor units, integer, positive
monedaISO code

The one thing that cannot be added later

The idempotent reference.

Locally, a charge either happens or it does not. Against a remote API there is a third case: the request goes out, the charge is applied and the response is lost. The retry is mandatory, and without a reference it is indistinguishable from the first attempt — so it charges twice.

That is why the reference is generated from the start, even though nothing needs it today:

apuesta:1042:usr_abc:1          (bet)
premio:1042:usr_abc:1           (win)
premio-parcial:1042:usr_abc:1   (partial win)

The partial cash-out carries its own reference on purpose: if it shared the final one, idempotency would take the second payment for a retry and the player would lose half their win.

In the local implementation this rests on a unique index on Transaction.referencia — not on an in-memory check, which two simultaneous requests would slip past.

What connecting to your wallet takes

That is the whole change. The specification is validated at start-up rather than on the first bet, so a mistyped field refuses to boot instead of surfacing at three in the morning with players inside. Neither betManager nor gameManager is touched, and with no OPERADOR_ESPEC the game keeps running on its own balances.

Several production environments

If you run separate productions — say Europe and rest of world, Asia and Latin America — each one gets its own base URL, its own credentials and its own operator name in a single specification file (operador.entornos.ejemplo.json). You open the game with &env=asia; the session token is redeemed against that environment only, the player is bound to it, and every bet, win, rollback and queued retry for that player goes only there. The same player in two environments is two separate records with two balances, as on your side. Secrets are not written in the file: ${NAME} is replaced at start-up by the environment variable NAME, and a missing one stops the server from starting rather than sending the placeholder as a key.

The decisions the mechanics already make

A doubtful bet is cancelled; a doubtful win never is. If the response to a debit is lost, the same reference is retried — that is what it is for: if the first attempt did arrive, you answer already processed instead of charging again. If the retries run out, the bet is refused and a rollback is sent for that reference, rollback first and error afterwards, so a process restart in between cannot leave a player charged with no bet. A credit is different: cancelling a win the whole round's chat watched happen is the one mistake that cannot be undone, so an uncertain credit is retried and never rolled back.

Retries are limited to what leaves the outcome unknown — connection dropped, timeout, 5xx, 429 — with growing back-off. A 4xx that means something (insufficient funds, duplicate reference, malformed request) is not retried: the answer would be identical and the player would just wait longer.

What is still unknown after that is persisted and retried for 72 hours. A win whose response never came, or the rollback of a doubtful bet that did not get through either, is written to the database before the game gives up, so a restart or a deploy cannot lose it. A separate loop retries it with the same reference on a growing schedule: immediately, then after 10 s, 30 s, 1 min, 3 min, 5 min, 10 min, 30 min and 1 h, then every hour up to 72 hours — about 80 attempts. A bet is never retried later: the round has already started, so it is rolled back. Anything still unsettled, and anything your wallet refuses with a meaningful 4xx, appears in GET /operator/pendientes with its reference, to be settled by hand.

Every bet is closed explicitly, if you want it. The final cash-out carries a round-end flag set to true; the partial cash-out carries it set to false, because another movement of the same bet follows. A lost bet sends nothing by default; with premioCeroEnPerdidas it is closed with a win of 0 and the round-end flag, under the bet's own win reference, so it is idempotent like everything else. Each movement can also carry its reason — BET, CASHOUT, AUTO_CASHOUT, PARTIAL_CASHOUT, LOSS, REFUND or ADJUSTMENT — under whatever field name your specification uses.

Retries can differ per route. Some aggregators do not accept a retried debit and want a rollback at the first doubt. reintentosPorRuta in the specification file sets it per operation — { "apostar": 0 } rolls a doubtful bet back at once, while wins keep their retries.

Currency exponents are respected. The game works in integer minor units. If your wallet speaks decimals, the conversion happens in one place and uses each currency's own exponent: the yen and the West African CFA franc have none and the Kuwaiti dinar has three, so dividing by 100 everywhere would move the decimal point by two places in exactly the markets where crash is played. Decimal amounts travel as strings, so 12.34 cannot reach your ledger as 12.339999999999998.

Decisions already made

Money and the leaderboard travel separately. They used to be updated in a single transaction, which is correct while the balance lives in our own table. With an operator wallet they are two different systems and cannot be atomic; pretending otherwise would hide the problem. Money wins: if the credit fails, the leaderboard is not touched. If the credit succeeds and the leaderboard does not, a statistic is lost, not a win.

A rollback is an opposing entry, not a deletion. The ledger is never rewritten: deleting would leave a hole in reconciliation with the operator that nobody could explain.

Insufficient funds is not an error. apostar returns aplicado: false, it does not throw. Running out of money is a normal case in the game.

How a player from your casino gets in

The launch URL is live. Your casino opens, in the player's browser:

https://api.starfallxgames.com/launch?token=...&currency=NGN&lang=en

The token is handed straight back to you to be redeemed — it is never decoded, read or logged here, because whoever controls that URL would otherwise control which player gets charged. Your answer says who the player is, in which currency, and the game opens with that identity. The session token then travels in the URL fragment, which never reaches a server, never appears in logs and never leaks through a Referer header.

The player's row is keyed by your operator name and your player id, so the same player always returns to the same record, and two tabs opened at once cannot split their balance into two. The balance column stays at zero on our side: the authoritative balance is yours.

sesion in the specification file says what your redemption endpoint is called and where the player id, currency, balance and nickname live in your answer.

Operator reporting

Protected by ADMIN_KEY (header x-operator-key or ?key=):

GET /operator/cuadre?dias=30Daily reconciliation: staked, paid, refunded, GGR, observed RTP — plus three integrity checks
GET /operator/buscar?ronda=NEverything about a round: bets, movements and seeds to verify it
GET /operator/buscar?jugador=emailThe same for a player, to settle disputes
GET /operator/buscar?referencia=RThe status of one transaction by its reference: applied, pending, rejected, rolled back or not found — with what your wallet answered, its retries and the local ledger
GET /operator/pendientesEverything not yet settled with your wallet: still being retried, or closed after 72 hours or a refusal

With an operator wallet the money does not go through our ledger, so every call to your wallet and how it ended is kept in a journal of its own. That is what the reference lookup reads first.

And one public endpoint, with no key: GET /games, the game list — id, type, RTP, volatility, maximum multiplier, features, languages, and every currency with its minimum bet, maximum bet and maximum win, read from the same tables the game uses.

Both accept &operador= as a filter. Today it returns nothing because the column is empty; it gets populated with the integration.

The three checks in the reconciliation are the part that matters, because a report that only adds things up detects nothing:

Refunds are not GGR. They are undone bets, and counting them as revenue would inflate the result with money that was never the house's.

Tests

The remote wallet is tested against an operator that breaks on demand. backend/src/game/operadorFalso.ts is a wallet that can apply a charge and then drop the response, time out, return 500 or cut the connection before applying anything — the failure that decides whether a player is charged twice, and the one you cannot provoke against a sandbox. carteraRemota.test.ts covers, among 30 cases:

colaReintentos.test.ts covers the 72-hour schedule: a win left pending while the operator is down enters once when it comes back; a win that did land, with its response lost, is not credited twice; a pending win is never rolled back; a queued entry survives a process restart; and the schedule adds up to 79 attempts inside the 72 hours.

To see it with your own eyes rather than read it, npm run operador:falso starts that wallet, prints the command to run the game against it, and takes tragar, timeout, 500 or red from the keyboard to break the network on the exact bet you choose while you watch the screen.

backend/src/game/cartera.test.ts exercises the local implementation against a real database, because idempotency rests on the unique index and a fake double would only prove that the fake is idempotent.

It covers: repeated charge, repeated payment, double rollback, rollback of something that never happened, and insufficient funds. And it checks first that the database is connected — without that, a connection failure left the other tests passing on nothing.

cd backend && npm test