@gabox-labs/sdk 0.7.1 → 0.9.0

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/llms.txt CHANGED
@@ -20,6 +20,10 @@
20
20
  - `createClient({ cluster: 'devnet' })` once; pass it to every function.
21
21
  - Builders return a kit transaction message. You sign and send.
22
22
  - All amounts are bigint. The coin has 6 decimals. A pack is 1,000,000 tokens.
23
+ - One purchase opens 1 to 5 packs in one trade, with one draw and one randomness request; the
24
+ callback settles them in order. `buyPacks` returns the draw address and its nonce.
25
+ - A prize the callback cannot pay is owed, never lost: `claimPrize` pays it later, and `settle`
26
+ reproduces every pack's result from the published randomness.
23
27
  - Gabox charges no fee. Every price already includes Raydium's own fees.
24
28
  - A machine is priced in one quote asset, wrapped SOL by default; any quote Raydium enabled works.
25
29
  - Buyers pay in SOL either way: a WSOL pool wraps it, any other pool swaps it in the same
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gabox-labs/sdk",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "The Solana Kit SDK for gabox: generated instruction builders, PDAs, Raydium LaunchLab and CPMM venue accounts, and the pack flow.",
6
6
  "license": "MIT",
@@ -7,8 +7,9 @@ description: Integrate Gabox machines on Solana with @gabox-labs/sdk and @solana
7
7
 
8
8
  Gabox binds a prize machine to a brand-new Raydium LaunchLab coin. The coin trades on its LaunchLab
9
9
  curve until it raises the pinned amount, then Raydium migrates it into a Raydium CPMM pool. Gabox
10
- delivers awards and closes draw accounts itself; there is no Ready, claim or sell-prize flow, and no
11
- referral program.
10
+ settles every pack of a purchase in the oracle's callback and pays the purchaser's coin account
11
+ itself; a claim exists only for a prize the callback could not pay (`paid: false`). There is no
12
+ sell-prize flow and no referral program.
12
13
 
13
14
  Use only devnet clients today. Pass `GaboxClient` first to every chain function; all amounts are
14
15
  `bigint`.
@@ -32,24 +33,30 @@ machine's seed is always paid by its creator, in the machine's own quote token,
32
33
  has no `payWith` and the creator must hold `maxSeedQuoteIn` of that token first.
33
34
 
34
35
  ```ts
35
- import { buyPack, createClient, getOffer } from '@gabox-labs/sdk';
36
+ import { buyPacks, createClient, getOffer } from '@gabox-labs/sdk';
36
37
 
37
38
  const gabox = createClient({ cluster: 'devnet' });
38
- const offer = await getOffer(gabox, mint, { user: purchaser.address });
39
- const message = await buyPack(gabox, {
39
+ const offer = await getOffer(gabox, mint, { user: purchaser.address, count: 3 });
40
+ const { message, draw } = await buyPacks(gabox, {
40
41
  mint,
41
42
  purchaser,
43
+ count: 3,
42
44
  maxQuoteIn: (offer.quoteAmount * 102n) / 100n,
43
- minMaximum: (offer.maximum * 98n) / 100n,
45
+ minFirstMaximum: (offer.maximum * 98n) / 100n,
44
46
  maxNativeDebit: 100_000_000n,
45
47
  });
46
48
  ```
47
49
 
48
- `offer.quoteAmount` is the exact venue price for one pack, in the pool's quote token;
49
- `offer.solAmount` is the same price in lamports, with `offer.quoteDecimals` and `offer.quoteSymbol`
50
- for showing it. `maxQuoteIn` is the slippage cap in the quote token, and the amount put in the
51
- buyer's quote account first. `maxNativeDebit` is a separate cap on the lamports the handler watches:
52
- the VRF request and any venue account rent.
50
+ One purchase opens 1 to 5 packs (`MAX_BATCH_SIZE`) in one trade with one draw and one randomness
51
+ request; `buyPack` is the one-pack form. `offer.quoteAmount` is the exact venue price for the whole
52
+ purchase, in the pool's quote token; `offer.solAmount` is the same price in lamports, with
53
+ `offer.quoteDecimals` and `offer.quoteSymbol` for showing it. `offer.prizes` and `offer.maximum`
54
+ are the first pack's table; `offer.perPackCaps` is the top prize each later pack keeps in the worst
55
+ case, and a screen should show it. `maxQuoteIn` is the slippage cap in the quote token, and the
56
+ amount put in the buyer's quote account first. `minFirstMaximum` is the floor on the first pack's
57
+ top prize. `maxNativeDebit` is a separate cap on the lamports the handler watches: the VRF request
58
+ and any venue account rent. The draw is named by a random nonce the builder returns; never reuse
59
+ the nonce of a purchase that may have landed.
53
60
 
54
61
  For creation use `createMachine` with `name`, `symbol`, `uri`, `maxSeedQuoteIn` and
55
62
  `maxSeedNativeDebit`. Metaplex limits the three strings to 32, 10 and 200 UTF-8 bytes. Add
@@ -69,9 +76,10 @@ sweeps every coin they launched against that quote, and
69
76
  `raydium.collectCreatorFee(client, { mint, creator })` for one graduated coin.
70
77
  `raydium.fetchCreatorFees` reads both, per quote asset.
71
78
 
72
- `buyPack` keeps a per-wallet `WalletActivity` account (`fetchWalletActivity(client, wallet)`, `null`
79
+ `buyPacks` keeps a per-wallet `WalletActivity` account (`fetchWalletActivity(client, wallet)`, `null`
73
80
  before a wallet's first purchase); it resolves the account itself.
74
81
 
75
- Use `fetchEvents` and `findResolvedDraw` for final delivery, and `retryDraw` or `expireDraw` for
82
+ Use `fetchEvents` and `findResolvedDraw` for final delivery (`paid: false` means the prize waits in the
83
+ vault: `claimPrize` pays it, `fetchOwedDraws` lists it, `settleDraw` proves it), and `retryDraw` or `expireDraw` for
76
84
  permissionless recovery. `fundPrizes` moves coins a funder already holds into the irrevocable prize
77
85
  vault. See `references/api.md` and the package README for complete signatures.
@@ -11,8 +11,9 @@ CPMM after. Both settle in the pool's own quote asset, which defaults to wrapped
11
11
  | `createClient({ cluster: 'devnet', ... })` | `GaboxClient` |
12
12
  | `fetchPoolByMint(client, mint)` | `Pool \| null` |
13
13
  | `fetchPoolInventory(client, mint)` | pool, vault inventory, reservations, free inventory |
14
- | `getOffer(client, mint, options?)` | current `PackOffer` |
15
- | `listPools(client)` / `listDrawsByPurchaser(client, wallet)` | current account scans |
14
+ | `getOffer(client, mint, { count?, user?, venue? })` | current `PackOffer` for `count` packs (default 1) |
15
+ | `listPools(client)` / `listDrawsByPurchaser(client, wallet)` / `fetchOwedDraws(client, wallet)` | current account scans; the last one lists settled draws a wallet is still owed |
16
+ | `drawAvailability(client, draw)` | `settled`, `owed`, and which of deliver, retry, expire and claim can still happen |
16
17
  | `fetchWalletActivity(client, wallet)` | `WalletActivity \| null`, a buyer's lifetime `packsBought`/`nativeSpent` |
17
18
 
18
19
  `Pool` records `creator`, `mint`, `vault`, `quoteMint`, `packTokens`, `seedQuoteAmount`, `tiers`,
@@ -20,10 +21,16 @@ CPMM after. Both settle in the pool's own quote asset, which defaults to wrapped
20
21
  `quoteTokenProgram` (classic SPL Token or Token-2022). It stores no base token program, because the
21
22
  coin is always classic SPL Token, and no fee, because Gabox charges none.
22
23
 
23
- `PackOffer` gives `quoteAmount` (the whole pack price in the quote token, the venue's fees
24
- included), `quoteMint`, `quoteDecimals`, `quoteSymbol`, `solAmount` (the same price in lamports
25
- through the route provider, or `null`), `venue` (`'launchlab'` or `'cpmm'`), the frozen prize table,
26
- `maximum`, `minimum`, `uncapped`, the inventory numbers and `isSeeded`.
24
+ `PackOffer` gives `count`, `quoteAmount` (the whole purchase price in the quote token, the venue's
25
+ fees included), `quoteMint`, `quoteDecimals`, `quoteSymbol`, `solAmount` (the same price in
26
+ lamports through the route provider, or `null`), `venue` (`'launchlab'` or `'cpmm'`), the first
27
+ pack's prize table with `maximum`, `minimum` and `uncapped`, `perPackCaps` (the worst-case top
28
+ prize of each pack), `batchReserved` (what the purchase adds to `pool.reserved`), the inventory
29
+ numbers with `freeSnapshot`, and `isSeeded`.
30
+
31
+ `Draw` records the purchase: `purchaser`, `nonce`, `seqStart`, `count`, the snapshot (`tiers`,
32
+ `packTokens`, `freeSnapshot`, `reserved`), the attempt slots, and after settlement `settled`,
33
+ `randomness`, `timedOut` and `owed`.
27
34
 
28
35
  ## Builders
29
36
 
@@ -32,18 +39,23 @@ Each returns a kit transaction message. Nothing here signs or sends.
32
39
  | Function | Input highlights |
33
40
  | --- | --- |
34
41
  | `createMachine` | `name`, `symbol`, `uri`, `tiers?`, `quote?`, `raise?`, `maxSeedQuoteIn`, `maxSeedNativeDebit`, `extraSeedTokens?` |
35
- | `buyPack` | `maxQuoteIn`, `minMaximum`, `maxNativeDebit`, `payWith?`, `venue?`, `seq?` |
42
+ | `buyPacks` | `count` (1 to 5), `nonce?`, `maxQuoteIn`, `minFirstMaximum`, `maxNativeDebit`, `payWith?`, `venue?`; returns `{ message, draw, nonce, seqStart, count }` |
43
+ | `buyPack` | the same with `count: 1` and `minMaximum`; same result shape |
36
44
  | `fundPrizes` | donate coins the funder already holds into the prize vault |
37
45
  | `sellTokens` | `amount`, `minQuoteOutput`, `maxNativeDebit`, `receive?`, `venue?` |
38
- | `retryDraw` / `expireDraw` | permissionless recovery |
46
+ | `retryDraw` / `expireDraw` | permissionless recovery of a pending draw |
47
+ | `claimPrize` | `payer`, `draw`; pays an owed prize to the purchaser's ATA, creating it if needed; anyone may send it |
48
+ | `claimPrizeTo` | `purchaser`, `draw`, `destination`; the purchaser pays their own owed prize to a coin account they own |
39
49
  | `raydium.claimCreatorFee` | `creator`, `quoteMint?`; sweeps every coin that wallet launched against that quote |
40
50
  | `raydium.collectCreatorFee` | `mint`, `creator`; one graduated coin's CPMM creator fee |
51
+ | `raydium.claimPlatformFee` | `feeWallet`, `quoteMint?`; the platform's curve share on that quote, signed by the platform fee wallet |
52
+ | `raydium.harvestLockedFees` | `owner`, `position`, `feeLp?`; one graduated coin's locked-LP fees, signed by the fee NFT holder |
41
53
 
42
54
  On a WSOL pool every builder wraps the SOL its trade needs into the wallet's WSOL account and closes
43
55
  that account afterwards, so the wallet spends and receives plain SOL. Closing unwraps any WSOL the
44
56
  wallet already held.
45
57
 
46
- On any other pool the wallet's quote account is created if missing, and `buyPack`'s `payWith: 'sol'`
58
+ On any other pool the wallet's quote account is created if missing, and `buyPacks`'s `payWith: 'sol'`
47
59
  (the default) prepends a swap that turns SOL into the quote token. `receive: 'sol'` appends the
48
60
  reverse after a sale. `payWith: 'quote'` and `receive: 'quote'` skip the swap. The swap and the
49
61
  Gabox instruction always share one transaction.
@@ -58,7 +70,7 @@ top prize when that pays less than 3x. A table's top tier can be at most 20x. `e
58
70
  (default `0n`) adds more in the same trade. `seedCostEstimate` returns `seedTokens`,
59
71
  `extraSeedTokens`, `totalSeedTokens` and the exact `quoteAmount` a fresh curve would charge.
60
72
 
61
- `buyPack` also resolves a per-wallet `WalletActivity` account (`findActivityPda({ purchaser })` or
73
+ `buyPacks` also resolves a per-wallet `WalletActivity` account (`findActivityPda({ purchaser })` or
62
74
  `activityAddress(wallet)`); callers do not pass it. It does not create the purchaser's coin account
63
75
  either: the program declares it `init_if_needed`, so Anchor does that and the purchaser pays its rent
64
76
  once.
@@ -86,6 +98,9 @@ route provider, for a display.
86
98
  | `raydium.findCpmmPool(client, { mint, creator, cpswapConfig, quoteMint? })` | the migrated CPMM pool, proved from its own data |
87
99
  | `raydium.fetchCurveSettings(client, quoteConfig)` | the fee rates, the migrate fee and the CPMM fee tier, read from chain |
88
100
  | `raydium.fetchCreatorFees(client, { creator, mint?, quoteMint? })` | `{ quoteMint, curveQuote, cpmmQuote, cpmmTokens }` |
101
+ | `raydium.fetchPlatformFees(client, { quoteMint? })` | `{ quoteMint, curveQuote }`, the platform's LaunchLab vault for that quote |
102
+ | `raydium.fetchLockedPositions(client, owner)` | `LockedPosition[]`: one per fee NFT the wallet holds, with `poolAddress`, `pool`, `claimableLp`, `claimableToken0`, `claimableToken1` |
103
+ | `raydium.lockedFeeLp(lock, pool)` | the LP a locked position may withdraw now, from `lastK`, `lastLp`, the vaults and the LP supply |
89
104
  | `raydium.fetchQuoteConfig(client, mint)` | LaunchLab's global config for a quote, or `null` |
90
105
  | `raydium.isQuoteSupported(client, mint)` | can a machine be priced in this mint? |
91
106
  | `raydium.fetchQuoteAsset(client, mint)` | the config, token program, decimals, symbol and minimum raise |
@@ -106,6 +121,15 @@ coin graduates.
106
121
 
107
122
  ## Math and low-level builders
108
123
 
124
+ The batch settlement is a port of `programs/gabox/src/math.rs`. `reserveFor(count, packTokens,
125
+ uncappedMax, free)` is what a purchase adds to `pool.reserved`; `perPackCaps(tiers, packTokens,
126
+ free, count)` is the worst-case top prize of each pack; `chooseIndex(tiers, ticket)` maps a 16-bit
127
+ ticket to a tier; `settleWith(tiers, packTokens, freeSnapshot, count, tickets, timedOut)` settles a
128
+ batch in order from explicit tickets. `settle({ tiers, packTokens, freeSnapshot, count, pool,
129
+ seqStart, randomness, timedOut? })` derives the tickets from the oracle's randomness (`ticketFor`,
130
+ sha256 through WebCrypto, so it is async), and `settleDraw(draw)` runs it from an owed draw's
131
+ account alone. `MAX_BATCH_SIZE` is 5.
132
+
109
133
  `raydium.curve` exports exact bigint ports of Raydium's own math: `curveBuyExactOut`,
110
134
  `curveBuyExactIn`, `curveSellExactIn`, `initialCurve`, `cpmmSwapBaseOutput`, `cpmmSwapBaseInput`, and
111
135
  the `ceilDivRate` / `preFeeAmount` helpers they are built from. Every rounding step matches
@@ -152,11 +176,16 @@ the buyer's quote account.
152
176
 
153
177
  ## Events
154
178
 
155
- `decodeEvents` and `fetchEvents` return only `PoolCreated`, `PrizesFunded`, `PackBought`,
156
- `RandomnessRetried`, `DrawResolved` and `TokensSold`. None carries a Gabox fee field any more.
157
- `PackBought` reports `quoteMint`, `quoteDebit` (what the venue charged, in that token),
158
- `nativeDebit` (venue account rent), `vrfNativeDebit` and `totalNativeDebit`.
159
-
160
- Delivery closes a draw atomically; use `findResolvedDraw` rather than a Ready or claim flow. It
161
- searches a bounded recent signature history, so production indexers should persist `DrawResolved`
162
- events as the authoritative history.
179
+ `decodeEvents` and `fetchEvents` return only `PoolCreated`, `PrizesFunded`, `PacksBought`,
180
+ `RandomnessRetried`, `DrawResolved`, `PrizeClaimed` and `TokensSold`. None carries a Gabox fee
181
+ field. `PacksBought` reports the `draw`, `seqStart` and `count` of the purchase, `quoteMint`,
182
+ `quoteDebit` (what the venue charged for the whole batch, in that token), `nativeDebit` (venue
183
+ account rent), `vrfNativeDebit`, `totalNativeDebit`, `freeSnapshot`, `reserved` and the first
184
+ pack's table as `firstPrizes`. `DrawResolved` reports `total`, one `results` entry per pack (`tier`,
185
+ `amount`), the `randomness`, `timedOut` and `paid`. `PrizeClaimed` reports the `amount`, the
186
+ `payer` and the `destination`.
187
+
188
+ A paid delivery closes the draw atomically; an owed one (`paid: false`) leaves it open and settled
189
+ until a claim closes it. `findResolvedDraw` finds a draw's `DrawResolved` event through the draw
190
+ address's own history. It searches a bounded recent signature history, so production indexers
191
+ should persist the events as the authoritative history, and `settle` lets anyone check them.