@gabox-labs/sdk 0.7.0 → 0.8.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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Dt as POOL_DISCRIMINATOR, I as getFundPrizesInstruction, Ot as decodePool, Rt as DRAW_DISCRIMINATOR, W as getExpireDrawInstruction, _t as decodeWalletActivity, b as getRetryDrawInstruction, ft as findPoolPda, gt as WALLET_ACTIVITY_DISCRIMINATOR, ht as findActivityPda, k as getInitializePoolInstructionAsync, mt as findDrawPda, p as getSellTokensInstructionAsync, pt as findIdentityPda, st as getBuyPackInstructionAsync, zt as decodeDraw } from "./gabox-DGTCh34U.js";
2
- import { $ as computeBudgetInstructions, $t as launchlabVaultAddress, B as fetchQuoteAsset, Bt as vaultAddress, Cn as PACK_TOKENS, Dn as VRF_DEFAULT_QUEUE, E as cpmmSwapBaseOutput, En as TIMEOUT_SLOTS, Et as decodeCpmmPool, Ft as activityAddress, G as readAccounts, H as fetchQuoteDisplay, Ht as ata, I as launchlabBuyAccounts, In as LAUNCH_DECIMALS, It as associatedTokenAddress, J as COMPUTE_BUDGET_PROGRAM_ADDRESS, K as BUY_PACK_COMPUTE_UNITS, Kn as ASSOCIATED_TOKEN_PROGRAM_ADDRESS, Kt as creatorFeeVaultAddress, Lt as drawAddress, Nt as tokenAccountAmount, O as curveBuyExactOut, On as VRF_PROGRAM_ADDRESS, Q as REDEEM_COMPUTE_UNITS, Qt as launchlabPoolAddress, Rt as poolAddress, S as wsolAccountFor, Sn as MAX_ATTEMPTS, T as cpmmSwapBaseInput, Tn as SLOT_HASHES_SYSVAR, Tt as decodeCpmmAmmConfig, Vt as vrfIdentityAddress, Wn as raydiumIds, X as DEFAULT_COMPUTE_UNIT_LIMIT, Xn as CPMM_SWAP_BASE_INPUT, Y as CREATE_MACHINE_COMPUTE_UNITS, Z as MAX_COMPUTE_UNIT_LIMIT, Zn as CPMM_SWAP_BASE_OUTPUT, _n as validatePack, _t as tiersOf, an as MAX_MULTIPLIER_BPS, at as POOL_MINT_OFFSET, b as resolveVenue, bn as IDENTITY_SEED, c as getLaunchInstruction, cn as TIERS, cr as METAPLEX_PROGRAM_ADDRESS, ct as fetchPoolByMint, dn as maxMultiplierBps, dt as fetchWalletActivity, et as getSetComputeUnitLimitInstruction, f as creatorFeeOnInput, fn as quote, ft as listDraws, gn as uncappedMaximum, gr as WSOL_MINT, gt as quotePool, hn as tierAmount, hr as TOKEN_PROGRAM_ADDRESS, ht as listPools, in as GaboxMathError, it as POOL_CREATOR_OFFSET, l as buildMessage, ln as averageMultiplierBps, lr as PLATFORM_ADMIN, lt as fetchPoolInventory, m as fetchCurveSettings, mn as seedTokens, mt as listDrawsByPurchaser, nn as BPS, nt as DRAW_POOL_OFFSET, on as MIN_SEED_MULTIPLIER_BPS, ot as fetchDraw, pn as resolveReservation, pr as SYSTEM_PROGRAM_ADDRESS, pt as listDrawsByPool, q as CLAIM_COMPUTE_UNITS, rn as DEFAULT_TIERS, rt as DRAW_PURCHASER_OFFSET, sn as TICKETS, sr as LAUNCH_TOTAL_BASE_SELL, st as fetchPoolAt, t as raydium_exports, tn as platformFeeVaultAddress, tt as getSetComputeUnitPriceInstruction, u as withRemainingAccounts, un as choose, ut as fetchVaultBalance, v as newCurveReserves, vn as validateTiers, wn as RETRY_SLOTS, xn as INSTRUCTIONS_SYSVAR, y as quoteAccountFor, yn as GABOX_PROGRAM_ID, z as order, zt as scopedVrfIdentityAddress } from "./raydium-CU-tZzIk.js";
2
+ import { $ as readAccounts, $t as vrfIdentityAddress, A as wsolAccountFor, An as tierAmount, Bn as SLOT_HASHES_SYSVAR, Cn as TIERS, Ct as listDrawsByPurchaser, D as quoteAccountFor, Dn as quote, Dr as PLATFORM_ADMIN, E as newCurveReserves, En as maxMultiplierBps, Er as METAPLEX_PROGRAM_ADDRESS, Et as tiersOf, Fn as IDENTITY_SEED, Gt as tokenAccountAmount, Hn as VRF_DEFAULT_QUEUE, I as curveBuyExactOut, In as INSTRUCTIONS_SYSVAR, It as decodeCpmmAmmConfig, J as fetchQuoteAsset, Jt as associatedTokenAddress, Ln as MAX_ATTEMPTS, Lt as decodeCpmmPool, Mn as validatePack, N as cpmmSwapBaseInput, Nn as validateTiers, Nr as TOKEN_PROGRAM_ADDRESS, O as resolveVenue, On as resolveReservation, P as cpmmSwapBaseOutput, Pn as GABOX_PROGRAM_ID, Pr as WSOL_MINT, Qt as vaultAddress, Rn as PACK_TOKENS, S as fetchCurveSettings, Sn as TICKETS, St as listDrawsByPool, Tn as choose, Tr as LAUNCH_TOTAL_BASE_SELL, Tt as quotePool, Un as VRF_PROGRAM_ADDRESS, Vn as TIMEOUT_SLOTS, W as launchlabBuyAccounts, X as fetchQuoteDisplay, Xt as poolAddress, Yt as drawAddress, Zn as LAUNCH_DECIMALS, Zt as scopedVrfIdentityAddress, _ as buildMessage, _n as BPS, _t as fetchPoolByMint, at as HARVEST_COMPUTE_UNITS, b as creatorFeeOnInput, bn as MAX_MULTIPLIER_BPS, bt as fetchWalletActivity, ct as computeBudgetInstructions, dn as launchlabVaultAddress, dt as DRAW_POOL_OFFSET, en as ata, et as BUY_PACK_COMPUTE_UNITS, ft as DRAW_PURCHASER_OFFSET, g as getLaunchInstruction, gt as fetchPoolAt, hn as platformFeeVaultAddress, ht as fetchDraw, in as creatorFeeVaultAddress, it as DEFAULT_COMPUTE_UNIT_LIMIT, jn as uncappedMaximum, jr as SYSTEM_PROGRAM_ADDRESS, kn as seedTokens, lr as ASSOCIATED_TOKEN_PROGRAM_ADDRESS, lt as getSetComputeUnitLimitInstruction, mr as CPMM_SWAP_BASE_OUTPUT, mt as POOL_MINT_OFFSET, nt as COMPUTE_BUDGET_PROGRAM_ADDRESS, ot as MAX_COMPUTE_UNIT_LIMIT, pr as CPMM_SWAP_BASE_INPUT, pt as POOL_CREATOR_OFFSET, q as order, qt as activityAddress, rt as CREATE_MACHINE_COMPUTE_UNITS, sr as raydiumIds, st as REDEEM_COMPUTE_UNITS, t as raydium_exports, tt as CLAIM_COMPUTE_UNITS, un as launchlabPoolAddress, ut as getSetComputeUnitPriceInstruction, v as withRemainingAccounts, vn as DEFAULT_TIERS, vt as fetchPoolInventory, wn as averageMultiplierBps, wt as listPools, xn as MIN_SEED_MULTIPLIER_BPS, xt as listDraws, yn as GaboxMathError, yt as fetchVaultBalance, zn as RETRY_SLOTS } from "./raydium-DIF1WOvI.js";
3
3
  import { DRAW_RESOLVED_EVENT_DISCRIMINATOR, PACK_BOUGHT_EVENT_DISCRIMINATOR, POOL_CREATED_EVENT_DISCRIMINATOR, PRIZES_FUNDED_EVENT_DISCRIMINATOR, RANDOMNESS_RETRIED_EVENT_DISCRIMINATOR, TOKENS_SOLD_EVENT_DISCRIMINATOR, getDrawResolvedEventDecoder, getPackBoughtEventDecoder, getPoolCreatedEventDecoder, getPrizesFundedEventDecoder, getRandomnessRetriedEventDecoder, getTokensSoldEventDecoder, t as generated_exports } from "./generated/index.js";
4
4
  import { AccountRole, address, createNoopSigner, createSolanaRpc, createSolanaRpcSubscriptions, getAddressDecoder, getBase64Encoder, getU64Encoder } from "@solana/kit";
5
5
  import { getCloseAccountInstruction, getCreateAssociatedTokenIdempotentInstruction, getSyncNativeInstruction } from "@solana-program/token";
@@ -1060,6 +1060,9 @@ function unwrapWsol(owner, account) {
1060
1060
  * transaction, before `buy_pack`. A sale does the reverse afterwards. `routeQuoteIn` and
1061
1061
  * `routeQuoteOut` build those, and `assertRouteIsSafe` checks the result before it is used.
1062
1062
  *
1063
+ * The third shape belongs to packs only. A machine's seed is always paid by its creator, in the
1064
+ * machine's own quote token, so `createMachine` uses `quoteLegFromWallet` and never swaps.
1065
+ *
1063
1066
  * Nothing here ever splits the work across two transactions. A swap that settles separately would
1064
1067
  * leave the wallet holding a token it never asked for whenever the second half failed.
1065
1068
  */
@@ -1074,13 +1077,16 @@ function createQuoteAccount(owner, venue) {
1074
1077
  });
1075
1078
  }
1076
1079
  /**
1077
- * The leg that puts `maxQuoteIn` of the quote token in the buyer's quote account.
1080
+ * The leg for a wallet that already holds what it is about to spend. No swap.
1078
1081
  *
1079
- * `payWith` decides where it comes from. On a WSOL pool the choice makes no difference: the quote
1080
- * token is SOL either way, so the builder wraps it.
1082
+ * A WSOL pool is the one case where "already holds it" means lamports, so those are wrapped and the
1083
+ * account is closed again afterwards. Any other quote only needs its account to exist; closing it
1084
+ * would throw away a real balance.
1085
+ *
1086
+ * `createMachine` uses this and nothing else: the seed is always the creator's own money, in the
1087
+ * machine's quote token.
1081
1088
  */
1082
- async function quoteLegIn(client, input) {
1083
- const { venue, payer, maxQuoteIn, payWith } = input;
1089
+ async function quoteLegFromWallet(venue, payer, maxQuoteIn) {
1084
1090
  if (venue.quoteMint === "So11111111111111111111111111111111111111112") {
1085
1091
  const wsol = await fundWsol(payer, maxQuoteIn);
1086
1092
  return {
@@ -1092,7 +1098,7 @@ async function quoteLegIn(client, input) {
1092
1098
  computeUnits: 0
1093
1099
  };
1094
1100
  }
1095
- if (payWith === "quote") return {
1101
+ return {
1096
1102
  before: [createQuoteAccount(payer, venue)],
1097
1103
  after: [],
1098
1104
  lookupTables: {},
@@ -1100,6 +1106,16 @@ async function quoteLegIn(client, input) {
1100
1106
  solAmount: null,
1101
1107
  computeUnits: 0
1102
1108
  };
1109
+ }
1110
+ /**
1111
+ * The leg that puts `maxQuoteIn` of the quote token in the buyer's quote account.
1112
+ *
1113
+ * `payWith` decides where it comes from. On a WSOL pool the choice makes no difference: the quote
1114
+ * token is SOL either way, so the builder wraps it.
1115
+ */
1116
+ async function quoteLegIn(client, input) {
1117
+ const { venue, payer, maxQuoteIn, payWith } = input;
1118
+ if (venue.quoteMint === "So11111111111111111111111111111111111111112" || payWith === "quote") return await quoteLegFromWallet(venue, payer, maxQuoteIn);
1103
1119
  const route = await routeQuoteIn(client, providerOf(client, venue.quoteMint), {
1104
1120
  quoteMint: venue.quoteMint,
1105
1121
  amount: maxQuoteIn,
@@ -1325,39 +1341,22 @@ async function createMachine(client, input) {
1325
1341
  maxSeedNativeDebit,
1326
1342
  extraSeedTokens
1327
1343
  });
1328
- const leg = await quoteLegIn(client, {
1329
- venue: {
1330
- quoteMint: quote.mint,
1331
- quoteTokenProgram: quote.tokenProgram,
1332
- userQuoteToken
1333
- },
1334
- payer: creator,
1335
- maxQuoteIn: maxSeedQuoteIn,
1336
- payWith: seed === 0n ? "quote" : input.payWith ?? "sol",
1337
- gaboxAccounts: [
1338
- await poolAddress(mint),
1339
- await vaultAddress(mint),
1340
- await ata(creator.address, mint)
1341
- ]
1342
- });
1344
+ const leg = await quoteLegFromWallet({
1345
+ quoteMint: quote.mint,
1346
+ quoteTokenProgram: quote.tokenProgram,
1347
+ userQuoteToken
1348
+ }, creator, maxSeedQuoteIn);
1343
1349
  const instructions = [
1344
1350
  create,
1345
1351
  ...leg.before,
1346
1352
  withRemainingAccounts(initialize, venueAccounts),
1347
1353
  ...leg.after
1348
1354
  ];
1349
- try {
1350
- return await buildMessage(client, creator, instructions, {
1351
- addressLookupTables: {
1352
- ...input.addressLookupTables ?? client.addressLookupTables,
1353
- ...leg.lookupTables
1354
- },
1355
- computeUnitLimit: input.computeUnitLimit ?? computeUnitsWithRoute(35e4, leg),
1356
- ...input.computeUnitPrice === void 0 ? {} : { computeUnitPrice: input.computeUnitPrice }
1357
- });
1358
- } catch (cause) {
1359
- throw routeSizeHint(cause, leg);
1360
- }
1355
+ return await buildMessage(client, creator, instructions, {
1356
+ addressLookupTables: input.addressLookupTables ?? client.addressLookupTables,
1357
+ computeUnitLimit: input.computeUnitLimit ?? 35e4,
1358
+ ...input.computeUnitPrice === void 0 ? {} : { computeUnitPrice: input.computeUnitPrice }
1359
+ });
1361
1360
  }
1362
1361
  /**
1363
1362
  * What the seed for this table costs, fees included, and how many tokens it is.
@@ -1367,9 +1366,9 @@ async function createMachine(client, input) {
1367
1366
  * same transaction, so this is exact up to a change in Raydium's fee rates between the read and the
1368
1367
  * send.
1369
1368
  *
1370
- * `solAmount` is the same cost in SOL, priced through the client's route provider. It is `null`
1371
- * when the client has no provider, or when no route exists: a devnet client has none unless the
1372
- * caller passes `raydiumCpmmRoute(pool)`.
1369
+ * `solAmount` is what that cost is worth in SOL, priced through the client's route provider. It is
1370
+ * a display: the creator pays in the quote token. It is `null` when the client has no provider, or
1371
+ * when no route exists: a devnet client has none unless the caller passes `raydiumCpmmRoute(pool)`.
1373
1372
  *
1374
1373
  * Defaults to `DEFAULT_TIERS`, wrapped SOL and no extra seed. Throws if `tiers` fails
1375
1374
  * `validateTiers`/`validatePack`, if `extraSeedTokens` is negative, if the total seed is bigger
@@ -1582,6 +1581,6 @@ async function oracleAccounts() {
1582
1581
  };
1583
1582
  }
1584
1583
  //#endregion
1585
- export { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, BPS, BUY_PACK_COMPUTE_UNITS, CLAIM_COMPUTE_UNITS, CLUSTER_ENDPOINTS, COMPUTE_BUDGET_PROGRAM_ADDRESS, CPMM_ROUTE_COMPUTE_UNITS, CPMM_ROUTE_SLIPPAGE_BPS, CREATE_MACHINE_COMPUTE_UNITS, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_TIERS, DEVNET_ADDRESS_LOOKUP_TABLES, DEVNET_HTTP, DEVNET_LOOKUP_TABLE_ADDRESS, DEVNET_LOOKUP_TABLE_ADDRESSES, DEVNET_WS, DRAW_DISCRIMINATOR, DRAW_POOL_OFFSET, DRAW_PURCHASER_OFFSET, EXACT_IN_MARGIN_BPS, GABOX_PROGRAM_ID, GaboxMathError, IDENTITY_SEED, INSTRUCTIONS_SYSVAR, JUPITER_DEFAULT_COMPUTE_UNITS, JUPITER_DEFAULT_SLIPPAGE_BPS, JUPITER_LITE_URL, LAUNCH_DECIMALS, MAX_ATTEMPTS, MAX_COMPUTE_UNIT_LIMIT, MAX_MULTIPLIER_BPS, METAPLEX_PROGRAM_ADDRESS, MIN_SEED_MULTIPLIER_BPS, PACK_TOKENS, PLATFORM_ADMIN, POOL_CREATOR_OFFSET, POOL_DISCRIMINATOR, POOL_MINT_OFFSET, REDEEM_COMPUTE_UNITS, RETRY_SLOTS, SLOT_HASHES_SYSVAR, SYSTEM_PROGRAM_ADDRESS, TICKETS, TIERS, TIMEOUT_SLOTS, TOKEN_PROGRAM_ADDRESS, VRF_DEFAULT_QUEUE, VRF_PROGRAM_ADDRESS, WALLET_ACTIVITY_DISCRIMINATOR, WSOL_MINT, activityAddress, assertClusterUrl, assertRouteIsSafe, associatedTokenAddress, averageMultiplierBps, buildMessage, buyPack, choose, clusterNamedBy, computeBudgetInstructions, computeUnitsOf, computeUnitsWithRoute, createClient, createMachine, createQuoteAccount, decodeDraw, decodeEvent, decodeEvents, decodePool, decodeWalletActivity, defaultAddressLookupTables, defaultRoute, drawAddress, drawAvailability, expireDraw, fetchAddressLookupTables, fetchDraw, fetchEvents, fetchPoolAt, fetchPoolByMint, fetchPoolInventory, fetchVaultBalance, fetchWalletActivity, findActivityPda, findDrawPda, findIdentityPda, findPoolPda, findResolvedDraw, fundPrizes, fundWsol, generated_exports as generated, getOffer, getSetComputeUnitLimitInstruction, getSetComputeUnitPriceInstruction, jupiterRoute, listDraws, listDrawsByPool, listDrawsByPurchaser, listPools, maxMultiplierBps, offerFromState, oracleAccounts, poolAddress, providerOf, quote, quoteLegIn, quoteLegOut, quotePool, raydium_exports as raydium, raydiumCpmmRoute, resolveReservation, retryDraw, routeFrom, routeQuoteIn, routeQuoteOut, routeSizeHint, scopedVrfIdentityAddress, seedCostEstimate, seedShortfall, seedTokens, sellTokens, solPriceOf, tierAmount, tiersOf, uncappedMaximum, unwrapWsol, validatePack, validateTiers, vaultAddress, vrfIdentityAddress, websocketUrlFor, withRemainingAccounts };
1584
+ export { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, BPS, BUY_PACK_COMPUTE_UNITS, CLAIM_COMPUTE_UNITS, CLUSTER_ENDPOINTS, COMPUTE_BUDGET_PROGRAM_ADDRESS, CPMM_ROUTE_COMPUTE_UNITS, CPMM_ROUTE_SLIPPAGE_BPS, CREATE_MACHINE_COMPUTE_UNITS, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_TIERS, DEVNET_ADDRESS_LOOKUP_TABLES, DEVNET_HTTP, DEVNET_LOOKUP_TABLE_ADDRESS, DEVNET_LOOKUP_TABLE_ADDRESSES, DEVNET_WS, DRAW_DISCRIMINATOR, DRAW_POOL_OFFSET, DRAW_PURCHASER_OFFSET, EXACT_IN_MARGIN_BPS, GABOX_PROGRAM_ID, GaboxMathError, HARVEST_COMPUTE_UNITS, IDENTITY_SEED, INSTRUCTIONS_SYSVAR, JUPITER_DEFAULT_COMPUTE_UNITS, JUPITER_DEFAULT_SLIPPAGE_BPS, JUPITER_LITE_URL, LAUNCH_DECIMALS, MAX_ATTEMPTS, MAX_COMPUTE_UNIT_LIMIT, MAX_MULTIPLIER_BPS, METAPLEX_PROGRAM_ADDRESS, MIN_SEED_MULTIPLIER_BPS, PACK_TOKENS, PLATFORM_ADMIN, POOL_CREATOR_OFFSET, POOL_DISCRIMINATOR, POOL_MINT_OFFSET, REDEEM_COMPUTE_UNITS, RETRY_SLOTS, SLOT_HASHES_SYSVAR, SYSTEM_PROGRAM_ADDRESS, TICKETS, TIERS, TIMEOUT_SLOTS, TOKEN_PROGRAM_ADDRESS, VRF_DEFAULT_QUEUE, VRF_PROGRAM_ADDRESS, WALLET_ACTIVITY_DISCRIMINATOR, WSOL_MINT, activityAddress, assertClusterUrl, assertRouteIsSafe, associatedTokenAddress, averageMultiplierBps, buildMessage, buyPack, choose, clusterNamedBy, computeBudgetInstructions, computeUnitsOf, computeUnitsWithRoute, createClient, createMachine, createQuoteAccount, decodeDraw, decodeEvent, decodeEvents, decodePool, decodeWalletActivity, defaultAddressLookupTables, defaultRoute, drawAddress, drawAvailability, expireDraw, fetchAddressLookupTables, fetchDraw, fetchEvents, fetchPoolAt, fetchPoolByMint, fetchPoolInventory, fetchVaultBalance, fetchWalletActivity, findActivityPda, findDrawPda, findIdentityPda, findPoolPda, findResolvedDraw, fundPrizes, fundWsol, generated_exports as generated, getOffer, getSetComputeUnitLimitInstruction, getSetComputeUnitPriceInstruction, jupiterRoute, listDraws, listDrawsByPool, listDrawsByPurchaser, listPools, maxMultiplierBps, offerFromState, oracleAccounts, poolAddress, providerOf, quote, quoteLegFromWallet, quoteLegIn, quoteLegOut, quotePool, raydium_exports as raydium, raydiumCpmmRoute, resolveReservation, retryDraw, routeFrom, routeQuoteIn, routeQuoteOut, routeSizeHint, scopedVrfIdentityAddress, seedCostEstimate, seedShortfall, seedTokens, sellTokens, solPriceOf, tierAmount, tiersOf, uncappedMaximum, unwrapWsol, validatePack, validateTiers, vaultAddress, vrfIdentityAddress, websocketUrlFor, withRemainingAccounts };
1586
1585
 
1587
1586
  //# sourceMappingURL=index.js.map