@gabox-labs/sdk 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/README.md +511 -0
- package/dist/gaboxV2-CV2XltqC.js +3347 -0
- package/dist/gaboxV2-CV2XltqC.js.map +1 -0
- package/dist/generated/index.d.ts +1468 -0
- package/dist/generated/index.js +795 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/index-BxvSkzCO.d.ts +471 -0
- package/dist/index.d.ts +823 -0
- package/dist/index.js +1763 -0
- package/dist/index.js.map +1 -0
- package/dist/pump/index.d.ts +2 -0
- package/dist/pump/index.js +2 -0
- package/dist/pump-D0K_0uiC.js +1531 -0
- package/dist/pump-D0K_0uiC.js.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/llms.txt +22 -0
- package/package.json +97 -0
- package/skills/gabox-sdk/SKILL.md +163 -0
- package/skills/gabox-sdk/references/api.md +149 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# `@gabox-labs/sdk` API reference
|
|
2
|
+
|
|
3
|
+
Every function that reads or writes the chain takes `client: GaboxClient` first. Every builder
|
|
4
|
+
returns `Promise<GaboxTransactionMessage>`: a version 0 kit message with the fee payer and a fresh
|
|
5
|
+
blockhash set, ready for `signTransactionMessageWithSigners`. All amounts are `bigint`.
|
|
6
|
+
|
|
7
|
+
## Client (`src/rpc.ts`)
|
|
8
|
+
|
|
9
|
+
| function / type | signature | notes |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `createClient` | `(config: ClientConfig) => GaboxClient` | the init step. Throws if the URL contradicts the cluster |
|
|
12
|
+
| `ClientConfig` | `{ cluster: Cluster; url?: string; wsUrl?: string; addressLookupTables?: AddressesByLookupTableAddress }` | `cluster` is required |
|
|
13
|
+
| `GaboxClient` | `{ cluster; url; wsUrl; rpc: GaboxRpc; rpcSubscriptions: GaboxRpcSubscriptions; addressLookupTables }` | a plain object; spread to replace `rpc` |
|
|
14
|
+
| `Cluster` | `'devnet' \| 'mainnet-beta' \| 'localnet'` | |
|
|
15
|
+
| `CLUSTER_ENDPOINTS` | `Record<Cluster, { url; wsUrl }>` | the defaults |
|
|
16
|
+
| `clusterNamedBy` | `(url: string) => Cluster \| 'testnet' \| null` | substring check |
|
|
17
|
+
| `assertClusterUrl` | `(cluster: Cluster, url: string) => void` | the guard, exported for scripts |
|
|
18
|
+
| `websocketUrlFor` | `(url: string) => string` | `https`→`wss`, `http`→`ws` |
|
|
19
|
+
| `defaultAddressLookupTables` | `(cluster: Cluster) => AddressesByLookupTableAddress` | devnet's shared table; `{}` elsewhere |
|
|
20
|
+
| `GaboxRpc`, `GaboxRpcSubscriptions` | kit `Rpc<SolanaRpcApi>`, `RpcSubscriptions<SolanaRpcSubscriptionsApi>` | |
|
|
21
|
+
|
|
22
|
+
## Offers and prices (`src/offer.ts`)
|
|
23
|
+
|
|
24
|
+
| function | signature | notes |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| `getOffer` | `(client, mint: Address, options?: { user?: Address; venue?: VenueKind }) => Promise<PackOffer>` | two reads: pool + vault, then the venue. Throws if the mint has no machine |
|
|
27
|
+
| `offerFromState` | `(inventory: PoolInventory, venue: VenueKind, quoteLamports: bigint) => PackOffer` | pure |
|
|
28
|
+
| `seedShortfall` | `(offer: PackOffer) => bigint` | tokens that would uncap the top prize |
|
|
29
|
+
|
|
30
|
+
`PackOffer` fields: `mint`, `pool`, `packTokens`, `quoteLamports`, `feeBps`, `feeLamports`,
|
|
31
|
+
`protocolLamports`, `seedLamports`, `seedTokens`, `venue`, `prizes: Prize[]`, `maximum`, `minimum`,
|
|
32
|
+
`uncapped`, `inventory`, `reserved`, `free`, `isFirstPack`, `isSeeded`, `maxMultiplierBps`,
|
|
33
|
+
`averageMultiplierBps`.
|
|
34
|
+
|
|
35
|
+
## Transaction builders (`src/tx/`, `src/referral.ts`)
|
|
36
|
+
|
|
37
|
+
| function | input | signers |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `createMachine` | `{ creator; mintKeypair; name; symbol; uri; feeBps: number; riskProfile: RiskProfile; jackpotBps: number; maxSeedLamports: bigint; feeRecipientIndex?; buybackRecipientIndex? }` | creator, mintKeypair |
|
|
40
|
+
| `seedCostEstimate` | `(client, jackpotBps: number, riskProfile: RiskProfile) => Promise<{ tiers: Tier[]; seedTokens: bigint; lamports: bigint }>` | read only |
|
|
41
|
+
| `buyPack` | `{ mint; purchaser; maxQuoteIn: bigint; minMaximum: bigint; maxTotalDebit: bigint; seq?: bigint; venue?; wrapLamports?; cashback?; referrer?: Address }` | purchaser |
|
|
42
|
+
| `sellTokens` | `{ mint; seller; amount: bigint; minQuoteOutput: bigint; venue? }` | seller |
|
|
43
|
+
| `fundPrizes` | `{ mint; funder; amount: bigint; source?: Address }` | funder |
|
|
44
|
+
| `fundPrizesWithBuy` | `{ mint; funder; tokens: bigint; maxQuoteIn: bigint; venue?; wrapLamports? }` | funder |
|
|
45
|
+
| `retryDraw` | `{ payer; pool; draw; maxVrfDebit: bigint }` | payer (anyone) |
|
|
46
|
+
| `expireDraw` | `{ payer; pool; draw }` | payer (anyone) |
|
|
47
|
+
| `bindReferrer` | `(client, referee: TransactionSigner, referrer: Address, options?) ` | referee |
|
|
48
|
+
| `claimReferral` | `(client, referrer: TransactionSigner, pool: Address, options?)` | referrer |
|
|
49
|
+
| `claimPrize`, `sellPrize`, `quoteSellPrize` | legacy draws only (created before automatic delivery) | purchaser |
|
|
50
|
+
| `buildMessage` | `(client, feePayer, instructions: Instruction[], options: BuildOptions)` | assemble your own |
|
|
51
|
+
|
|
52
|
+
Every input also accepts `BuildOptions`: `computeUnitLimit?: number`, `computeUnitPrice?: number | bigint`
|
|
53
|
+
(micro-lamports per unit), `addressLookupTables?`.
|
|
54
|
+
|
|
55
|
+
`drawAvailability(client, draw) => Promise<DrawAvailability | null>` returns
|
|
56
|
+
`{ status, attempts, slotsUntilRetry, slotsUntilExpiry, canRetry, canExpire }`.
|
|
57
|
+
|
|
58
|
+
## Readers (`src/accounts.ts`, `src/events.ts`)
|
|
59
|
+
|
|
60
|
+
| function | returns |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `fetchPoolByMint(client, mint)` | `Pool \| null` |
|
|
63
|
+
| `fetchPoolAt(client, poolAddress)` | `Pool \| null` |
|
|
64
|
+
| `fetchPoolInventory(client, mint)` | `{ pool, poolAddress, vault, inventory, reserved, free } \| null` |
|
|
65
|
+
| `fetchVaultBalance(client, mint)` | `bigint` |
|
|
66
|
+
| `fetchDraw(client, drawAddress)` | `Draw \| null` (null once delivered and closed) |
|
|
67
|
+
| `fetchReferralReward(client, pool, referrer)` | `Referral \| null` |
|
|
68
|
+
| `listPools(client)` | `{ address, data: Pool }[]` |
|
|
69
|
+
| `listDraws(client, { pool?, purchaser? })` | `{ address, data: Draw }[]` |
|
|
70
|
+
| `listDrawsByPool(client, pool)`, `listDrawsByPurchaser(client, wallet)` | same |
|
|
71
|
+
| `listReferralLinksByReferrer(client, referrer)` | `{ address, data: ReferralLink }[]` |
|
|
72
|
+
| `resolveReferral(client, purchaser, pool)` | `{ link, referrer, referral } \| null` |
|
|
73
|
+
| `fetchEvents(client, signature)` | `GaboxEvent[]` |
|
|
74
|
+
| `decodeEvents(logs: string[])`, `decodeEvent(bytes)` | pure |
|
|
75
|
+
| `watchDraw(client, drawAddress, { signal?, onChange? })` | `Promise<Draw>` resolves on delivery |
|
|
76
|
+
|
|
77
|
+
`Pool` fields: `creator`, `mint`, `tokenProgram`, `vault`, `bump`, `packTokens`, `feeBps`,
|
|
78
|
+
`seedLamports`, `seedTokens`, `tiers: Tier[]`, `nextSeq`, `reserved`.
|
|
79
|
+
|
|
80
|
+
`Draw` fields: `pool`, `purchaser`, `seq`, `status: DrawStatus` (`Pending | Ready`), `requestSlot`,
|
|
81
|
+
`lastAttemptSlot`, `attempts`, `maximum`, `minimum`, `prizes`, `amount`, `randomness`, `timedOut`.
|
|
82
|
+
|
|
83
|
+
`GaboxEvent` is a union on `name`: `PoolCreated`, `PrizesFunded`, `PackBought`, `RandomnessRetried`,
|
|
84
|
+
`DrawResolved`, `PrizeRedeemed`, `TokensSold`. `PackBought.data` has `pool`, `seq`, `purchaser`,
|
|
85
|
+
`venue`, `tokensBought`, `venueDebit`, `feeLamports`, `referralLamports`, `protocolLamports`,
|
|
86
|
+
`vrfDebit`, `prizes`. `DrawResolved.data` has `pool`, `seq`, `purchaser`, `amount`, `randomness`,
|
|
87
|
+
`timedOut`.
|
|
88
|
+
|
|
89
|
+
## Addresses (`src/pdas.ts`), all async
|
|
90
|
+
|
|
91
|
+
`poolAddress(mint)`, `drawAddress(pool, seq)`, `vaultAddress(mint, tokenProgram?)`,
|
|
92
|
+
`associatedTokenAddress(owner, mint, tokenProgram?)`, `referralLinkAddress(referee)`,
|
|
93
|
+
`referralAddress(pool, referrer)`, `feeCollectorWsolAddress()`, `vrfIdentityAddress()`.
|
|
94
|
+
Also the generated `findPoolPda`, `findDrawPda`, `findReferralLinkPda`, `findIdentityPda`.
|
|
95
|
+
|
|
96
|
+
## Math (`src/math.ts`), pure
|
|
97
|
+
|
|
98
|
+
| function | signature |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `share` | `(amount: bigint, bps: bigint) => bigint` |
|
|
101
|
+
| `jackpotTiers` | `(jackpotBps: number, profile: RiskProfile) => Tier[]` |
|
|
102
|
+
| `seedTokens` | `(packTokens: bigint, tiers: Tier[]) => bigint` |
|
|
103
|
+
| `quote` | `(base: bigint, tiers: Tier[], inventory: bigint, reserved: bigint) => Offer` |
|
|
104
|
+
| `uncappedMaximum` | `(base: bigint, tiers: Tier[]) => bigint` |
|
|
105
|
+
| `tierAmount` | `(base: bigint, multiplierBps: number) => bigint` |
|
|
106
|
+
| `choose` | `(prizes: Prize[], ticket: number) => bigint` |
|
|
107
|
+
| `maxMultiplierBps`, `averageMultiplierBps` | `(tiers: Tier[]) => number` |
|
|
108
|
+
| `validateTiers`, `validatePack` | throw `GaboxMathError` on a bad table |
|
|
109
|
+
|
|
110
|
+
Types: `Tier = { multiplierBps: number; tickets: number }`, `Prize = { amount: bigint; tickets: number }`,
|
|
111
|
+
`Offer = { prizes: Prize[]; maximum: bigint; minimum: bigint }`,
|
|
112
|
+
`RiskProfile = 'conservative' | 'balanced' | 'jackpot'`. Constants `BPS = 10_000n`, `TICKETS = 65_536`,
|
|
113
|
+
`TIERS = 8`.
|
|
114
|
+
|
|
115
|
+
## Constants (`src/ids.ts`)
|
|
116
|
+
|
|
117
|
+
`GABOX_PROGRAM_ID`, `PACK_TOKENS`, `PROTOCOL_FEE_BPS` (`100n`), `MAX_FEE_BPS` (`100`),
|
|
118
|
+
`REFERRAL_FEE_BPS` (`100n`), `RETRY_SLOTS` (`300n`), `MAX_ATTEMPTS` (`3`), `TIMEOUT_SLOTS`
|
|
119
|
+
(`216_000n`), `WSOL_MINT`, `TOKEN_PROGRAM_ADDRESS`, `TOKEN_2022_PROGRAM_ADDRESS`,
|
|
120
|
+
`ASSOCIATED_TOKEN_PROGRAM_ADDRESS`, `PUMP_PROGRAM_ADDRESS`, `PUMP_SWAP_PROGRAM_ADDRESS`,
|
|
121
|
+
`VRF_PROGRAM_ADDRESS`, `VRF_DEFAULT_QUEUE`.
|
|
122
|
+
|
|
123
|
+
## Venue layer (`pump` namespace, `@gabox-labs/sdk/pump`)
|
|
124
|
+
|
|
125
|
+
| function | signature |
|
|
126
|
+
| --- | --- |
|
|
127
|
+
| `resolveVenue` | `(client, { mint; user; venue?; feeRecipientIndex?; buybackRecipientIndex? }) => Promise<ResolvedVenue>` |
|
|
128
|
+
| `curveQuote` | `(client, mint, tokens: bigint, { user?, venue? }?) => Promise<bigint>` lamports to buy `tokens` |
|
|
129
|
+
| `sellQuote` | `(client, mint, tokens: bigint, { user?, venue? }?) => Promise<bigint>` lamports a sale returns |
|
|
130
|
+
| `newCurveBuyCost` | `(client, tokens: bigint) => Promise<bigint>` on a fresh curve |
|
|
131
|
+
| `wsolAccountFor` | `(user: Address) => Address` |
|
|
132
|
+
| `tokenAccountAmount` | `(data: Uint8Array) => bigint` |
|
|
133
|
+
|
|
134
|
+
`ResolvedVenue`: `{ kind: 'pump' | 'pumpswap'; program; mint; tokenProgram; complete; creator;
|
|
135
|
+
buyAccounts; sellAccounts; quoteBuy(tokens); quoteSell(tokens) }`. `VenueKind = 'pump' | 'pumpswap'`.
|
|
136
|
+
|
|
137
|
+
## Generated client (`generated` namespace, `@gabox-labs/sdk/generated`)
|
|
138
|
+
|
|
139
|
+
Codama output for `@solana/kit`: `get*Instruction` builders, `fetch*` / `decode*` account readers
|
|
140
|
+
(these take a kit `Rpc`, i.e. `gabox.rpc`), event codecs, PDAs, and errors:
|
|
141
|
+
|
|
142
|
+
- `isGaboxV2Error(error, transactionMessage, code?)` — narrows a kit `SolanaError`.
|
|
143
|
+
- `getGaboxV2ErrorMessage(code)` — readable outside `NODE_ENV=production`.
|
|
144
|
+
- `GABOX_V2_ERROR__*` codes, from `6000`: `ARITHMETIC`, `INVALID_DISTRIBUTION`,
|
|
145
|
+
`UNFUNDED_EXPECTATION`, `UNSUPPORTED_MINT`, `INSOLVENT_INVENTORY`, `PRIZE_CAP_CHANGED`,
|
|
146
|
+
`PACK_TOO_SMALL`, `JACKPOT_BELOW_ONE_PACK`, `INVALID_VENUE`, `INCORRECT_TOKEN_DELTA`,
|
|
147
|
+
`SLIPPAGE_EXCEEDED`, `NOT_PENDING`, `NOT_READY`, `RETRY_TOO_SOON`, `RETRY_UNAVAILABLE`,
|
|
148
|
+
`NOT_EXPIRED`, `ZERO_AMOUNT`, `INVALID_FEE`, `COIN_NOT_CREATED_HERE`, `INVALID_REFERRAL`,
|
|
149
|
+
`NOTHING_OWED_TO_REFERRER`, `INVALID_FEE_COLLECTOR`.
|