@solana/kit and a client generated from Fade’s IDL. The wallet acts in every role: app, payer, funder and beneficiary. That is a developer setup: in production the app is the integrator’s own server, the funder and beneficiary are its own accounts, and its customers never deal with Fade.
Requirements: Node 20 or later, a devnet keypair with about 0.02 devnet SOL and some devnet USDC. Claim both from the faucet in app.fade.finance, or call the faucet API (step 2).
1
Install and generate the client
generate.mjs
src/generated/fade with a builder for every instruction (getOpenTicketInstructionAsync, …), account fetchers (fetchConfig, fetchMaybeTicket, …), PDA helpers, error codes and event decoders.2
Get devnet USDC
The faucet sends 1 000 devnet USDC, and a little SOL when the wallet has almost none. One claim per wallet and per IP every 5 minutes.If the wallet still lacks SOL, use faucet.solana.com.
3
Set up the connection
src/fade.ts
cfg anyway, so the code says which deployment it targets.4
Build a payout table
Probabilities are integers in billionths and must sum to exactly 1 000 000 000. Multipliers are integers in basis points: 10 000 is 1×. Compute in
bigint, never in floating point.src/payout-table.ts
allOrNothing(1_000_000n, 10_000_000n, 200n) returns [{ p: 98_000_000n, m: 100_000n }, { p: 902_000_000n, m: 0n }]: 10× at 9.8 %, a 2 % margin, the smallest a payout table can declare. More shapes and the sizing rules are on Payout tables.5
Open the ticket
src/open.ts
config, vault, integrator, vaultUsdc, ticket, vrfPayer and the VRF’s network state for you. If a check fails, sending throws with the program’s error; see Errors.6
Hand it to a keeper
The randomness request and the settlement are permissionless. The public keeper sends both:Even without the
src/keeper.ts
POST, the keeper sweeps for open tickets about every 30 seconds; posting just starts it at once.7
Run it
src/main.ts
outcome is the index of the payout table row that was drawn: 0 is the 10× row here, 1 is nothing. A payout is in USDC base units and has already reached the beneficiary.Settling without a keeper
Anyone may send the two remaining steps, including your own server. Request the randomness from two slots after the open, wait for the VRF to fulfil, then settle. The VRF accounts below are described on Randomness.src/settle-yourself.ts
T_SETTLE (150 slots), settle_ticket is impossible and anyone may call expire_ticket instead. See Settlement and keepers.
Reading the result
- From the keeper:
GET /v1/tickets/:addressreturnsoutcome,payoutand the settle signature. - From the chain: the ticket account closes at settlement. The settle transaction carries a
TicketSettledevent withoutcome,payoutandpending(true when the payout was parked because the beneficiary could not receive). See Events for decoding. - While open:
fetchMaybeTicketreturns the stored payout table,status(Open,RequestedorPayoutPending),openSlot,expirySlot, the boundrandomnessaccount and the reserved liability.
Next
- Size payouts against the vault: Payout tables.
- Who pays which SOL and gets it back: Margin and shares.
- Run your own keeper: Settlement and keepers.