@send-fun/sdk 1.1.0 → 1.2.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.
Files changed (50) hide show
  1. package/README.md +8 -9
  2. package/dist/index.cjs +526 -98
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +595 -93
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +595 -93
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +526 -98
  9. package/dist/index.mjs.map +1 -1
  10. package/package.json +1 -1
  11. package/src/dex/generated/accounts/globalConfig.ts +39 -2
  12. package/src/dex/generated/accounts/pool.ts +41 -2
  13. package/src/dex/generated/accounts/rewardAccrual.ts +39 -2
  14. package/src/dex/generated/index.ts +1 -0
  15. package/src/dex/generated/shared/index.ts +52 -0
  16. package/src/dex/trade.ts +12 -13
  17. package/src/launchpad/create.ts +8 -8
  18. package/src/launchpad/generated/accounts/bondingCurve.ts +39 -2
  19. package/src/launchpad/generated/accounts/globalConfig.ts +39 -2
  20. package/src/launchpad/generated/accounts/rewardAccrual.ts +39 -2
  21. package/src/launchpad/generated/index.ts +1 -0
  22. package/src/launchpad/generated/shared/index.ts +52 -0
  23. package/src/launchpad/migrate.ts +1 -1
  24. package/src/launchpad/trade.ts +15 -15
  25. package/src/math/amm.ts +40 -33
  26. package/src/math/fee-decay.ts +3 -2
  27. package/src/math/fees.ts +4 -2
  28. package/src/math/internal.ts +1 -1
  29. package/src/nexus/fee-helpers.ts +5 -3
  30. package/src/nexus/generated/accounts/altRegistry.ts +41 -2
  31. package/src/nexus/generated/accounts/creatorFeeConfig.ts +39 -2
  32. package/src/nexus/generated/accounts/feePreset.ts +41 -2
  33. package/src/nexus/generated/accounts/globalConfig.ts +39 -2
  34. package/src/nexus/generated/accounts/partnerConfig.ts +39 -2
  35. package/src/nexus/generated/accounts/partnerMetadata.ts +39 -2
  36. package/src/nexus/generated/accounts/rewardState.ts +41 -2
  37. package/src/nexus/generated/accounts/stakingConfig.ts +39 -2
  38. package/src/nexus/generated/accounts/userRewardDebt.ts +39 -2
  39. package/src/nexus/generated/accounts/userStakePosition.ts +39 -2
  40. package/src/nexus/generated/index.ts +1 -0
  41. package/src/nexus/generated/shared/index.ts +52 -0
  42. package/src/nexus/staking.ts +45 -41
  43. package/src/platform.ts +2 -2
  44. package/src/transfer-fee.ts +19 -17
  45. package/src/utils/chunk.ts +1 -1
  46. package/src/utils/creator-hash.ts +6 -3
  47. package/src/utils/index.ts +2 -0
  48. package/src/utils/mint-info.ts +8 -7
  49. package/src/utils/partner.ts +1 -1
  50. package/src/utils/pda.ts +1 -1
package/dist/index.cjs CHANGED
@@ -30,22 +30,55 @@ var constants_exports = /* @__PURE__ */ __exportAll({
30
30
  SEND_DEX_PROGRAM_ADDRESS: () => SEND_DEX_PROGRAM_ADDRESS,
31
31
  SEND_LAUNCHPAD_PROGRAM_ADDRESS: () => SEND_LAUNCHPAD_PROGRAM_ADDRESS,
32
32
  SEND_NEXUS_PROGRAM_ADDRESS: () => SEND_NEXUS_PROGRAM_ADDRESS,
33
- SYSTEM_PROGRAM_ADDRESS: () => SYSTEM_PROGRAM_ADDRESS,
33
+ SYSTEM_PROGRAM_ADDRESS: () => SYSTEM_PROGRAM_ADDRESS$3,
34
34
  TOKEN_2022_PROGRAM_ADDRESS: () => TOKEN_2022_PROGRAM_ADDRESS,
35
35
  TOKEN_DECIMALS: () => 6,
36
36
  TOKEN_PROGRAM_ADDRESS: () => TOKEN_PROGRAM_ADDRESS,
37
37
  USDC_MINT: () => USDC_MINT,
38
38
  WSOL_MINT: () => WSOL_MINT
39
39
  });
40
- const SYSTEM_PROGRAM_ADDRESS = (0, _solana_kit.address)("11111111111111111111111111111111");
40
+ const SYSTEM_PROGRAM_ADDRESS$3 = (0, _solana_kit.address)("11111111111111111111111111111111");
41
41
  const TOKEN_PROGRAM_ADDRESS = (0, _solana_kit.address)("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
42
42
  const TOKEN_2022_PROGRAM_ADDRESS = (0, _solana_kit.address)("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
43
43
  const ASSOCIATED_TOKEN_PROGRAM_ADDRESS = (0, _solana_kit.address)("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
44
44
  const WSOL_MINT = (0, _solana_kit.address)("So11111111111111111111111111111111111111112");
45
45
  const USDC_MINT = (0, _solana_kit.address)("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
46
- const DEFAULT_PARTNER = SYSTEM_PROGRAM_ADDRESS;
46
+ const DEFAULT_PARTNER = SYSTEM_PROGRAM_ADDRESS$3;
47
47
  const PYTH_SOL_USD_PRICE_ACCOUNT = (0, _solana_kit.address)("7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE");
48
48
  //#endregion
49
+ //#region src/dex/generated/shared/index.ts
50
+ /** The System Program, which owns every address nobody has created an account at yet. */
51
+ const SYSTEM_PROGRAM_ADDRESS$2 = "11111111111111111111111111111111";
52
+ /**
53
+ * Whether an encoded account was created on-chain, rather than merely sent lamports.
54
+ *
55
+ * Anyone can send lamports to an address before its account is created, which leaves it on-chain,
56
+ * owned by the System Program, with no data. This returns `false` for that shape, as it does for an
57
+ * account that does not exist. Any other existing account counts as created, whoever owns it; the
58
+ * `decode*` functions still check the owner.
59
+ *
60
+ * The generated `fetchMaybe*` and `fetchAllMaybe*` helpers apply this rule themselves. Apply it to
61
+ * accounts you fetch or receive another way (subscriptions, batch loaders, caches) before passing
62
+ * them to a `decode*` function, which throws for a lamports-only account: an account passed to it as
63
+ * existing must never come back as the non-existing variant typed as an `Account`.
64
+ *
65
+ * Only a `true` result narrows the type. A lamports-only account is still `exists: true` at runtime,
66
+ * so a `false` result leaves the type unchanged instead of narrowing it to the non-existing variant.
67
+ * The `uncreated` property in the narrowed type is never present; it exists only to prevent that.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const maybeAccount = decodeMyAccount(
72
+ * accountIsCreated(encodedAccount) ? encodedAccount : { address: encodedAccount.address, exists: false },
73
+ * );
74
+ * ```
75
+ */
76
+ function accountIsCreated$2(account) {
77
+ const maybeAccount = account;
78
+ if ("exists" in maybeAccount && !maybeAccount.exists) return false;
79
+ return !(maybeAccount.programAddress === SYSTEM_PROGRAM_ADDRESS$2 && maybeAccount.data.length === 0);
80
+ }
81
+ //#endregion
49
82
  //#region src/dex/generated/accounts/globalConfig.ts
50
83
  /**
51
84
  * This code was AUTOGENERATED using the Codama library.
@@ -113,21 +146,40 @@ function decodeGlobalConfig$2(encodedAccount) {
113
146
  }
114
147
  return (0, _solana_kit.decodeAccount)(encodedAccount, getGlobalConfigDecoder$2());
115
148
  }
149
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
116
150
  async function fetchGlobalConfig$2(rpc, address, config) {
117
151
  const maybeAccount = await fetchMaybeGlobalConfig$2(rpc, address, config);
118
152
  (0, _solana_kit.assertAccountExists)(maybeAccount);
119
153
  return maybeAccount;
120
154
  }
155
+ /**
156
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
157
+ * account or only lamports (see {@link accountIsCreated}).
158
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
159
+ */
121
160
  async function fetchMaybeGlobalConfig$2(rpc, address, config) {
122
- return decodeGlobalConfig$2(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
161
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
162
+ return decodeGlobalConfig$2(accountIsCreated$2(maybeAccount) ? maybeAccount : {
163
+ address,
164
+ exists: false
165
+ });
123
166
  }
167
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
124
168
  async function fetchAllGlobalConfig$2(rpc, addresses, config) {
125
169
  const maybeAccounts = await fetchAllMaybeGlobalConfig$2(rpc, addresses, config);
126
170
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
127
171
  return maybeAccounts;
128
172
  }
173
+ /**
174
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
175
+ * no account or only lamports (see {@link accountIsCreated}).
176
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
177
+ */
129
178
  async function fetchAllMaybeGlobalConfig$2(rpc, addresses, config) {
130
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$2(maybeAccount));
179
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$2(accountIsCreated$2(maybeAccount) ? maybeAccount : {
180
+ address: maybeAccount.address,
181
+ exists: false
182
+ }));
131
183
  }
132
184
  function getGlobalConfigSize$1() {
133
185
  return 139;
@@ -288,21 +340,40 @@ function decodePool(encodedAccount) {
288
340
  }
289
341
  return (0, _solana_kit.decodeAccount)(encodedAccount, getPoolDecoder());
290
342
  }
343
+ /** Fetches a `Pool` account, throwing when it does not exist or only holds lamports. */
291
344
  async function fetchPool(rpc, address, config) {
292
345
  const maybeAccount = await fetchMaybePool(rpc, address, config);
293
346
  (0, _solana_kit.assertAccountExists)(maybeAccount);
294
347
  return maybeAccount;
295
348
  }
349
+ /**
350
+ * Fetches a `Pool` account, or the non-existing variant when the address holds no
351
+ * account or only lamports (see {@link accountIsCreated}).
352
+ * {@link decodePool} throws for a lamports-only account instead.
353
+ */
296
354
  async function fetchMaybePool(rpc, address, config) {
297
- return decodePool(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
355
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
356
+ return decodePool(accountIsCreated$2(maybeAccount) ? maybeAccount : {
357
+ address,
358
+ exists: false
359
+ });
298
360
  }
361
+ /** Fetches `Pool` accounts, throwing when any does not exist or only holds lamports. */
299
362
  async function fetchAllPool(rpc, addresses, config) {
300
363
  const maybeAccounts = await fetchAllMaybePool(rpc, addresses, config);
301
364
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
302
365
  return maybeAccounts;
303
366
  }
367
+ /**
368
+ * Fetches `Pool` accounts, with the non-existing variant for each address that holds
369
+ * no account or only lamports (see {@link accountIsCreated}).
370
+ * {@link decodePool} throws for a lamports-only account instead.
371
+ */
304
372
  async function fetchAllMaybePool(rpc, addresses, config) {
305
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodePool(maybeAccount));
373
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodePool(accountIsCreated$2(maybeAccount) ? maybeAccount : {
374
+ address: maybeAccount.address,
375
+ exists: false
376
+ }));
306
377
  }
307
378
  function getPoolSize() {
308
379
  return 389;
@@ -375,21 +446,40 @@ function decodeRewardAccrual$1(encodedAccount) {
375
446
  }
376
447
  return (0, _solana_kit.decodeAccount)(encodedAccount, getRewardAccrualDecoder$1());
377
448
  }
449
+ /** Fetches a `RewardAccrual` account, throwing when it does not exist or only holds lamports. */
378
450
  async function fetchRewardAccrual$1(rpc, address, config) {
379
451
  const maybeAccount = await fetchMaybeRewardAccrual$1(rpc, address, config);
380
452
  (0, _solana_kit.assertAccountExists)(maybeAccount);
381
453
  return maybeAccount;
382
454
  }
455
+ /**
456
+ * Fetches a `RewardAccrual` account, or the non-existing variant when the address holds no
457
+ * account or only lamports (see {@link accountIsCreated}).
458
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
459
+ */
383
460
  async function fetchMaybeRewardAccrual$1(rpc, address, config) {
384
- return decodeRewardAccrual$1(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
461
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
462
+ return decodeRewardAccrual$1(accountIsCreated$2(maybeAccount) ? maybeAccount : {
463
+ address,
464
+ exists: false
465
+ });
385
466
  }
467
+ /** Fetches `RewardAccrual` accounts, throwing when any does not exist or only holds lamports. */
386
468
  async function fetchAllRewardAccrual$1(rpc, addresses, config) {
387
469
  const maybeAccounts = await fetchAllMaybeRewardAccrual$1(rpc, addresses, config);
388
470
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
389
471
  return maybeAccounts;
390
472
  }
473
+ /**
474
+ * Fetches `RewardAccrual` accounts, with the non-existing variant for each address that holds
475
+ * no account or only lamports (see {@link accountIsCreated}).
476
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
477
+ */
391
478
  async function fetchAllMaybeRewardAccrual$1(rpc, addresses, config) {
392
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual$1(maybeAccount));
479
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual$1(accountIsCreated$2(maybeAccount) ? maybeAccount : {
480
+ address: maybeAccount.address,
481
+ exists: false
482
+ }));
393
483
  }
394
484
  function getRewardAccrualSize$1() {
395
485
  return 130;
@@ -3449,12 +3539,11 @@ var amm_exports = /* @__PURE__ */ __exportAll({
3449
3539
  });
3450
3540
  const BPS_DIVISOR = 10000n;
3451
3541
  const U64_MAX = 18446744073709551615n;
3452
- /** Each call mirrors a `u64::try_from` in the Rust twin; drop one and an oversized leg fails in the encoder. */
3453
3542
  function assertU64(label, value) {
3454
3543
  if (value > U64_MAX) throw new RangeError(`${label}: overflows u64`);
3455
3544
  return value;
3456
3545
  }
3457
- /** No transfer lands exactly the requested amount; approximating one hands the program a bound it rejects. */
3546
+ /** Thrown when no transfer delivers exactly `amount` after the transfer fee. */
3458
3547
  var TransferFeeNotSettleableError = class extends RangeError {
3459
3548
  amount;
3460
3549
  mintFee;
@@ -3469,7 +3558,8 @@ function assertMintFee(fee) {
3469
3558
  assertBps("MintFee", "bps", fee.bps);
3470
3559
  if (fee.maximumFee < 0n || fee.maximumFee > U64_MAX) throw new RangeError("MintFee: maximumFee must fit a u64");
3471
3560
  }
3472
- /** Rounds up, then caps (SPL's order); swapping them lets a split booking over-credit. */
3561
+ /** Returns the transfer fee on `amount`. Rounds up, then caps at `maximumFee`, in SPL's order.
3562
+ * Returns 0 without `fee`. Throws `RangeError` if `fee` is out of range. */
3473
3563
  function feeOn(amount, fee) {
3474
3564
  if (fee === void 0) return 0n;
3475
3565
  assertMintFee(fee);
@@ -3477,11 +3567,11 @@ function feeOn(amount, fee) {
3477
3567
  const raw = ceilDiv(amount * BigInt(fee.bps), BPS_DIVISOR);
3478
3568
  return raw < fee.maximumFee ? raw : fee.maximumFee;
3479
3569
  }
3480
- /** What lands when `amount` is sent; use `grossUp` to land an exact amount. */
3570
+ /** Returns what the recipient receives when `amount` is sent. `grossUp` is the inverse. */
3481
3571
  function amountAfterFee(amount, fee) {
3482
3572
  return amount - feeOn(amount, fee);
3483
3573
  }
3484
- /** Line-for-line mirror of SPL's `TransferFee::calculate_pre_fee_amount`; `undefined` when no u64 answer exists. */
3574
+ /** Matches SPL `TransferFee::calculate_pre_fee_amount`. `undefined` if the result does not fit a u64. */
3485
3575
  function preFeeAmount(amount, fee) {
3486
3576
  const bps = BigInt(fee.bps);
3487
3577
  if (bps === 0n) return amount;
@@ -3497,7 +3587,8 @@ function preFeeAmount(amount, fee) {
3497
3587
  }
3498
3588
  return rawPreFee > U64_MAX ? void 0 : rawPreFee;
3499
3589
  }
3500
- /** What must be sent for exactly `amount` to land; throws {@link TransferFeeNotSettleableError} if none does. */
3590
+ /** Returns the amount to send so that exactly `amount` arrives. Returns `amount` without `fee`.
3591
+ * Throws {@link TransferFeeNotSettleableError} if no such amount exists. */
3501
3592
  function grossUp(amount, fee) {
3502
3593
  if (fee === void 0) return amount;
3503
3594
  assertMintFee(fee);
@@ -3520,7 +3611,8 @@ function sqrtBigInt(value) {
3520
3611
  }
3521
3612
  return x;
3522
3613
  }
3523
- /** Output rounds down (the new reserve rounds up), so `k` never shrinks. */
3614
+ /** Returns the constant-product output for `amountIn`, rounded down. Throws `RangeError` on a zero
3615
+ * reserve, a zero `amountIn`, a zero output, or an output past u64. */
3524
3616
  function calculateOutput(reserveIn, reserveOut, amountIn) {
3525
3617
  if (reserveIn === 0n || reserveOut === 0n) throw new RangeError("calculateOutput: insufficient liquidity");
3526
3618
  if (amountIn === 0n) throw new RangeError("calculateOutput: invalid amount");
@@ -3530,7 +3622,8 @@ function calculateOutput(reserveIn, reserveOut, amountIn) {
3530
3622
  if (amountOut === 0n) throw new RangeError("calculateOutput: insufficient liquidity");
3531
3623
  return assertU64("calculateOutput", amountOut);
3532
3624
  }
3533
- /** Required input rounds up so the user pays enough. */
3625
+ /** Returns the input needed for `amountOut`, rounded up. Throws `RangeError` on a zero reserve, a zero
3626
+ * `amountOut`, an `amountOut` not below `reserveOut`, or an input past u64. */
3534
3627
  function calculateInputForOutput(reserveIn, reserveOut, amountOut) {
3535
3628
  if (reserveIn === 0n || reserveOut === 0n) throw new RangeError("calculateInputForOutput: insufficient liquidity");
3536
3629
  if (amountOut === 0n || amountOut >= reserveOut) throw new RangeError("calculateInputForOutput: invalid amount");
@@ -3593,7 +3686,9 @@ function buyQuote(legs, quoteTransferFee, baseFee) {
3593
3686
  quoteFromUser: legs.quoteAmount
3594
3687
  };
3595
3688
  }
3596
- /** Guard with `calculateSlippageUp(quoteAmount, bps)`; it already carries the quote mint's cut. */
3689
+ /** Quotes a buy where the buyer receives `baseAmountOut`. With `baseReserveCap`, the vault sends at
3690
+ * most the cap. Guard with `calculateSlippageUp(quoteAmount, bps)`. `quoteAmount` includes the quote
3691
+ * mint's transfer fee. */
3597
3692
  function buyExactOut$2(params) {
3598
3693
  assertBps("buyExactOut", "feeBps", params.feeBps);
3599
3694
  if (params.baseAmountOut === 0n) throw new RangeError("buyExactOut: invalid amount");
@@ -3606,7 +3701,8 @@ function buyExactOut$2(params) {
3606
3701
  quoteAmount: quoteFromUser
3607
3702
  }, quoteFromUser - legs.quoteAmount, params.baseFee);
3608
3703
  }
3609
- /** Guard with `calculateSlippageDown(baseToUser, bps)`, not `baseAmount`: the program bounds what the buyer nets. */
3704
+ /** Quotes a buy that spends `quoteAmountIn`. Guard with `calculateSlippageDown(baseToUser, bps)`, not
3705
+ * `baseAmount`. The program checks the minimum against what the buyer receives. */
3610
3706
  function buyExactIn$2(params) {
3611
3707
  assertBps("buyExactIn", "feeBps", params.feeBps);
3612
3708
  if (params.quoteAmountIn === 0n) throw new RangeError("buyExactIn: invalid amount");
@@ -3625,7 +3721,7 @@ function buyExactIn$2(params) {
3625
3721
  quoteAmount: quoteFromUser
3626
3722
  }, quoteFromUser - capped.quoteAmount, params.baseFee);
3627
3723
  }
3628
- /** Guard with `calculateSlippageDown(quoteToUser, bps)`, not `quoteAmount`. */
3724
+ /** Quotes a sell of `baseAmountIn`. Guard with `calculateSlippageDown(quoteToUser, bps)`, not `quoteAmount`. */
3629
3725
  function sellExactIn$2(params) {
3630
3726
  assertBps("sellExactIn", "feeBps", params.feeBps);
3631
3727
  if (params.baseAmountIn === 0n) throw new RangeError("sellExactIn: invalid amount");
@@ -3643,7 +3739,8 @@ function sellExactIn$2(params) {
3643
3739
  quoteToUser: legs.quoteAmount - quoteTransferFee
3644
3740
  };
3645
3741
  }
3646
- /** Guard with `calculateSlippageUp(baseFromUser, bps)`, which already carries the base mint's cut. */
3742
+ /** Quotes a sell where the seller receives `quoteAmountOut`. Guard with
3743
+ * `calculateSlippageUp(baseFromUser, bps)`. `baseFromUser` includes the base mint's transfer fee. */
3647
3744
  function sellExactOut$2(params) {
3648
3745
  assertBps("sellExactOut", "feeBps", params.feeBps);
3649
3746
  if (params.quoteAmountOut === 0n) throw new RangeError("sellExactOut: invalid amount");
@@ -3668,17 +3765,17 @@ function calculateSlippageDown(amount, slippageBps) {
3668
3765
  assertBps("calculateSlippageDown", "slippageBps", slippageBps);
3669
3766
  return assertU64("calculateSlippageDown", floorDiv(amount * (BPS_DIVISOR - BigInt(slippageBps)), BPS_DIVISOR));
3670
3767
  }
3671
- /** Floors, as the program's `isqrt` does. */
3768
+ /** Returns `sqrt(quoteAmount * baseAmount)`, rounded down. */
3672
3769
  function calculateInitialLp(quoteAmount, baseAmount) {
3673
3770
  return sqrtBigInt(quoteAmount * baseAmount);
3674
3771
  }
3675
- /** Floating-point quote per base, for display only. */
3772
+ /** Returns the price of one base token in quote tokens, as a float. For display only. */
3676
3773
  function calculatePrice(params) {
3677
3774
  const { quoteReserves, baseReserves, quoteDecimals, baseDecimals } = params;
3678
3775
  if (baseReserves === 0n) return 0;
3679
3776
  return Number(quoteReserves) / Number(baseReserves) * 10 ** (baseDecimals - quoteDecimals);
3680
3777
  }
3681
- /** Market cap in raw quote-token units. */
3778
+ /** Returns the market cap in raw quote units. */
3682
3779
  function calculateMarketCap(params) {
3683
3780
  const { quoteReserves, baseReserves, baseSupply } = params;
3684
3781
  if (baseReserves === 0n) return 0n;
@@ -3696,7 +3793,7 @@ var trade_exports$1 = /* @__PURE__ */ __exportAll({
3696
3793
  sellExactIn: () => sellExactIn$1,
3697
3794
  sellExactOut: () => sellExactOut$1
3698
3795
  });
3699
- /** `baseAmountOut` is net to the buyer: the program reads `amount` as `base_to_user`. */
3796
+ /** `baseAmountOut` is the base the buyer receives, after the base mint's transfer fee. */
3700
3797
  async function buyExactOut$1(params) {
3701
3798
  const quote = buyExactOut$2({
3702
3799
  reserveQuote: params.quoteReserves,
@@ -3754,7 +3851,7 @@ async function sellExactIn$1(params) {
3754
3851
  quote
3755
3852
  };
3756
3853
  }
3757
- /** `quoteAmountOut` is net to the seller: the program reads `amount` as `quote_to_user`. */
3854
+ /** `quoteAmountOut` is the quote the seller receives, after the quote mint's transfer fee. */
3758
3855
  async function sellExactOut$1(params) {
3759
3856
  const quote = sellExactOut$2({
3760
3857
  reserveQuote: params.quoteReserves,
@@ -3828,6 +3925,39 @@ var dex_exports = /* @__PURE__ */ __exportAll({
3828
3925
  types: () => types_exports$2
3829
3926
  });
3830
3927
  //#endregion
3928
+ //#region src/launchpad/generated/shared/index.ts
3929
+ /** The System Program, which owns every address nobody has created an account at yet. */
3930
+ const SYSTEM_PROGRAM_ADDRESS$1 = "11111111111111111111111111111111";
3931
+ /**
3932
+ * Whether an encoded account was created on-chain, rather than merely sent lamports.
3933
+ *
3934
+ * Anyone can send lamports to an address before its account is created, which leaves it on-chain,
3935
+ * owned by the System Program, with no data. This returns `false` for that shape, as it does for an
3936
+ * account that does not exist. Any other existing account counts as created, whoever owns it; the
3937
+ * `decode*` functions still check the owner.
3938
+ *
3939
+ * The generated `fetchMaybe*` and `fetchAllMaybe*` helpers apply this rule themselves. Apply it to
3940
+ * accounts you fetch or receive another way (subscriptions, batch loaders, caches) before passing
3941
+ * them to a `decode*` function, which throws for a lamports-only account: an account passed to it as
3942
+ * existing must never come back as the non-existing variant typed as an `Account`.
3943
+ *
3944
+ * Only a `true` result narrows the type. A lamports-only account is still `exists: true` at runtime,
3945
+ * so a `false` result leaves the type unchanged instead of narrowing it to the non-existing variant.
3946
+ * The `uncreated` property in the narrowed type is never present; it exists only to prevent that.
3947
+ *
3948
+ * @example
3949
+ * ```ts
3950
+ * const maybeAccount = decodeMyAccount(
3951
+ * accountIsCreated(encodedAccount) ? encodedAccount : { address: encodedAccount.address, exists: false },
3952
+ * );
3953
+ * ```
3954
+ */
3955
+ function accountIsCreated$1(account) {
3956
+ const maybeAccount = account;
3957
+ if ("exists" in maybeAccount && !maybeAccount.exists) return false;
3958
+ return !(maybeAccount.programAddress === SYSTEM_PROGRAM_ADDRESS$1 && maybeAccount.data.length === 0);
3959
+ }
3960
+ //#endregion
3831
3961
  //#region src/launchpad/generated/types/bondingCurveStatus.ts
3832
3962
  /**
3833
3963
  * This code was AUTOGENERATED using the Codama library.
@@ -3993,21 +4123,40 @@ function decodeBondingCurve(encodedAccount) {
3993
4123
  }
3994
4124
  return (0, _solana_kit.decodeAccount)(encodedAccount, getBondingCurveDecoder());
3995
4125
  }
4126
+ /** Fetches a `BondingCurve` account, throwing when it does not exist or only holds lamports. */
3996
4127
  async function fetchBondingCurve(rpc, address, config) {
3997
4128
  const maybeAccount = await fetchMaybeBondingCurve(rpc, address, config);
3998
4129
  (0, _solana_kit.assertAccountExists)(maybeAccount);
3999
4130
  return maybeAccount;
4000
4131
  }
4132
+ /**
4133
+ * Fetches a `BondingCurve` account, or the non-existing variant when the address holds no
4134
+ * account or only lamports (see {@link accountIsCreated}).
4135
+ * {@link decodeBondingCurve} throws for a lamports-only account instead.
4136
+ */
4001
4137
  async function fetchMaybeBondingCurve(rpc, address, config) {
4002
- return decodeBondingCurve(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
4138
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
4139
+ return decodeBondingCurve(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4140
+ address,
4141
+ exists: false
4142
+ });
4003
4143
  }
4144
+ /** Fetches `BondingCurve` accounts, throwing when any does not exist or only holds lamports. */
4004
4145
  async function fetchAllBondingCurve(rpc, addresses, config) {
4005
4146
  const maybeAccounts = await fetchAllMaybeBondingCurve(rpc, addresses, config);
4006
4147
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
4007
4148
  return maybeAccounts;
4008
4149
  }
4150
+ /**
4151
+ * Fetches `BondingCurve` accounts, with the non-existing variant for each address that holds
4152
+ * no account or only lamports (see {@link accountIsCreated}).
4153
+ * {@link decodeBondingCurve} throws for a lamports-only account instead.
4154
+ */
4009
4155
  async function fetchAllMaybeBondingCurve(rpc, addresses, config) {
4010
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeBondingCurve(maybeAccount));
4156
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeBondingCurve(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4157
+ address: maybeAccount.address,
4158
+ exists: false
4159
+ }));
4011
4160
  }
4012
4161
  function getBondingCurveSize() {
4013
4162
  return 421;
@@ -4090,21 +4239,40 @@ function decodeGlobalConfig$1(encodedAccount) {
4090
4239
  }
4091
4240
  return (0, _solana_kit.decodeAccount)(encodedAccount, getGlobalConfigDecoder$1());
4092
4241
  }
4242
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
4093
4243
  async function fetchGlobalConfig$1(rpc, address, config) {
4094
4244
  const maybeAccount = await fetchMaybeGlobalConfig$1(rpc, address, config);
4095
4245
  (0, _solana_kit.assertAccountExists)(maybeAccount);
4096
4246
  return maybeAccount;
4097
4247
  }
4248
+ /**
4249
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
4250
+ * account or only lamports (see {@link accountIsCreated}).
4251
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
4252
+ */
4098
4253
  async function fetchMaybeGlobalConfig$1(rpc, address, config) {
4099
- return decodeGlobalConfig$1(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
4254
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
4255
+ return decodeGlobalConfig$1(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4256
+ address,
4257
+ exists: false
4258
+ });
4100
4259
  }
4260
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
4101
4261
  async function fetchAllGlobalConfig$1(rpc, addresses, config) {
4102
4262
  const maybeAccounts = await fetchAllMaybeGlobalConfig$1(rpc, addresses, config);
4103
4263
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
4104
4264
  return maybeAccounts;
4105
4265
  }
4266
+ /**
4267
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
4268
+ * no account or only lamports (see {@link accountIsCreated}).
4269
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
4270
+ */
4106
4271
  async function fetchAllMaybeGlobalConfig$1(rpc, addresses, config) {
4107
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$1(maybeAccount));
4272
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$1(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4273
+ address: maybeAccount.address,
4274
+ exists: false
4275
+ }));
4108
4276
  }
4109
4277
  function getGlobalConfigSize() {
4110
4278
  return 179;
@@ -4177,21 +4345,40 @@ function decodeRewardAccrual(encodedAccount) {
4177
4345
  }
4178
4346
  return (0, _solana_kit.decodeAccount)(encodedAccount, getRewardAccrualDecoder());
4179
4347
  }
4348
+ /** Fetches a `RewardAccrual` account, throwing when it does not exist or only holds lamports. */
4180
4349
  async function fetchRewardAccrual(rpc, address, config) {
4181
4350
  const maybeAccount = await fetchMaybeRewardAccrual(rpc, address, config);
4182
4351
  (0, _solana_kit.assertAccountExists)(maybeAccount);
4183
4352
  return maybeAccount;
4184
4353
  }
4354
+ /**
4355
+ * Fetches a `RewardAccrual` account, or the non-existing variant when the address holds no
4356
+ * account or only lamports (see {@link accountIsCreated}).
4357
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
4358
+ */
4185
4359
  async function fetchMaybeRewardAccrual(rpc, address, config) {
4186
- return decodeRewardAccrual(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
4360
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
4361
+ return decodeRewardAccrual(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4362
+ address,
4363
+ exists: false
4364
+ });
4187
4365
  }
4366
+ /** Fetches `RewardAccrual` accounts, throwing when any does not exist or only holds lamports. */
4188
4367
  async function fetchAllRewardAccrual(rpc, addresses, config) {
4189
4368
  const maybeAccounts = await fetchAllMaybeRewardAccrual(rpc, addresses, config);
4190
4369
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
4191
4370
  return maybeAccounts;
4192
4371
  }
4372
+ /**
4373
+ * Fetches `RewardAccrual` accounts, with the non-existing variant for each address that holds
4374
+ * no account or only lamports (see {@link accountIsCreated}).
4375
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
4376
+ */
4193
4377
  async function fetchAllMaybeRewardAccrual(rpc, addresses, config) {
4194
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual(maybeAccount));
4378
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4379
+ address: maybeAccount.address,
4380
+ exists: false
4381
+ }));
4195
4382
  }
4196
4383
  function getRewardAccrualSize() {
4197
4384
  return 130;
@@ -4515,7 +4702,8 @@ var pdas_exports$1 = /* @__PURE__ */ __exportAll({
4515
4702
  //#endregion
4516
4703
  //#region src/utils/creator-hash.ts
4517
4704
  const MAX_CREATOR_PLATFORM_LEN = 32;
4518
- /** SHA-256 of the LE-u32-length-prefixed platform and id. Frozen: it seeds live PDAs. */
4705
+ /** Returns the SHA-256 of `creatorPlatform` and `creatorId`, each prefixed with its byte length as a
4706
+ * little-endian u32. Throws `RangeError` if `creatorPlatform` is more than 32 bytes. */
4519
4707
  async function creatorHashFromId(creatorPlatform, creatorId) {
4520
4708
  const encoder = new TextEncoder();
4521
4709
  const platformBuf = encoder.encode(creatorPlatform);
@@ -4533,7 +4721,8 @@ async function creatorHashFromId(creatorPlatform, creatorId) {
4533
4721
  const hash = new Uint8Array(await crypto.subtle.digest("SHA-256", buf));
4534
4722
  return (0, _solana_kit.getAddressDecoder)().decode(hash);
4535
4723
  }
4536
- /** NUL-pads `text` to `length` bytes, the on-chain `CreatorFeeConfig.platformId` form; throws RangeError if longer. */
4724
+ /** Pads `text` with NUL bytes to `length` bytes, the form of `CreatorFeeConfig.platformId`.
4725
+ * Throws `RangeError` if `text` is longer. */
4537
4726
  function encodeCreatorId(text, length) {
4538
4727
  const bytes = new TextEncoder().encode(text);
4539
4728
  if (bytes.length > length) throw new RangeError(`text exceeds ${length} bytes (got ${bytes.length})`);
@@ -4541,7 +4730,8 @@ function encodeCreatorId(text, length) {
4541
4730
  out.set(bytes, 0);
4542
4731
  return out;
4543
4732
  }
4544
- /** Strips NUL padding. Pass this, never the padded array, to {@link creatorHashFromId}: the hash is length-prefixed. */
4733
+ /** Removes the trailing NUL bytes and decodes the rest as UTF-8. Pass the result, not the padded
4734
+ * bytes, to {@link creatorHashFromId}. */
4545
4735
  function decodeCreatorId(bytes) {
4546
4736
  let end = bytes.length;
4547
4737
  while (end > 0 && bytes[end - 1] === 0) end -= 1;
@@ -6487,7 +6677,8 @@ var trade_exports = /* @__PURE__ */ __exportAll({
6487
6677
  sellExactIn: () => sellExactIn,
6488
6678
  sellExactOut: () => sellExactOut
6489
6679
  });
6490
- /** `baseAmountOut` is net to the buyer: the program reads `amount` as `base_to_user`. */
6680
+ /** `baseAmountOut` is the base the buyer receives, after the base mint's transfer fee.
6681
+ * The buy is capped at the curve's supply left. Read the result from `quote.baseToUser`. */
6491
6682
  async function buyExactOut(params) {
6492
6683
  const quote = buyExactOut$2({
6493
6684
  reserveQuote: params.virtualQuoteReserves,
@@ -6547,7 +6738,7 @@ async function sellExactIn(params) {
6547
6738
  quote
6548
6739
  };
6549
6740
  }
6550
- /** `quoteAmountOut` is net to the seller: the program reads `amount` as `quote_to_user`. */
6741
+ /** `quoteAmountOut` is the quote the seller receives, after the quote mint's transfer fee. */
6551
6742
  async function sellExactOut(params) {
6552
6743
  const quote = sellExactOut$2({
6553
6744
  reserveQuote: params.virtualQuoteReserves,
@@ -6595,7 +6786,7 @@ async function buildSellExactOutInstruction(params) {
6595
6786
  maxAmountIn: params.maxAmountIn
6596
6787
  });
6597
6788
  }
6598
- /** Percent of the curve's real base sold (0-100); 100 is the migration threshold. */
6789
+ /** Returns the percent of the curve's real base sold, from 0 to 100. At 100 the curve can migrate. */
6599
6790
  function calculateBondingCurveProgress(params) {
6600
6791
  const { realBaseReserves, initialRealBase } = params;
6601
6792
  if (initialRealBase === 0n) return 100;
@@ -8530,7 +8721,7 @@ var plugins_exports$1 = /* @__PURE__ */ __exportAll({ sendLaunchpadProgram: () =
8530
8721
  //#endregion
8531
8722
  //#region src/utils/pda.ts
8532
8723
  const addressEncoder = (0, _solana_kit.getAddressEncoder)();
8533
- /** Seed order is [wallet, tokenProgram, mint], not the parameter order. */
8724
+ /** Derives the associated token account of `wallet` for `mint` under `tokenProgram`. */
8534
8725
  async function findAssociatedTokenPda(wallet, mint, tokenProgram = TOKEN_PROGRAM_ADDRESS) {
8535
8726
  return await (0, _solana_kit.getProgramDerivedAddress)({
8536
8727
  programAddress: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
@@ -8586,7 +8777,8 @@ var launchpad_exports = /* @__PURE__ */ __exportAll({
8586
8777
  //#endregion
8587
8778
  //#region src/math/fee-decay.ts
8588
8779
  var fee_decay_exports = /* @__PURE__ */ __exportAll({ calculateFeeDecayPremium: () => calculateFeeDecayPremium });
8589
- /** Premium in bps, rounded up. */
8780
+ /** Returns the fee decay premium in bps, rounded up. The premium falls quadratically from
8781
+ * `decayStartBps - standardFeeBps` at creation to 0 after `decaySeconds`. */
8590
8782
  function calculateFeeDecayPremium(params) {
8591
8783
  const { currentTimestamp, createdAtTimestamp, decaySeconds, decayStartBps, standardFeeBps } = params;
8592
8784
  if (decaySeconds === 0) return 0n;
@@ -8607,7 +8799,9 @@ function calculateFeeDecayPremium(params) {
8607
8799
  //#endregion
8608
8800
  //#region src/math/fees.ts
8609
8801
  var fees_exports = /* @__PURE__ */ __exportAll({ splitFeeAmount: () => splitFeeAmount });
8610
- /** LP/creator round down; protocol absorbs the decay premium and all remainders. */
8802
+ /** Splits `feeAmount` into protocol, LP and creator shares. LP and creator round down. Protocol gets
8803
+ * the decay premium and all remainders. Throws `RangeError` on a negative or non-integer input,
8804
+ * a zero total bps, or `protocolBps + lpBps` above `baseTotalBps`. */
8611
8805
  function splitFeeAmount(args) {
8612
8806
  const { feeAmount } = args;
8613
8807
  const protocolBps = toBps(args.protocolBps, "protocolBps");
@@ -8653,6 +8847,39 @@ var math_exports = /* @__PURE__ */ __exportAll({
8653
8847
  fees: () => fees_exports
8654
8848
  });
8655
8849
  //#endregion
8850
+ //#region src/nexus/generated/shared/index.ts
8851
+ /** The System Program, which owns every address nobody has created an account at yet. */
8852
+ const SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
8853
+ /**
8854
+ * Whether an encoded account was created on-chain, rather than merely sent lamports.
8855
+ *
8856
+ * Anyone can send lamports to an address before its account is created, which leaves it on-chain,
8857
+ * owned by the System Program, with no data. This returns `false` for that shape, as it does for an
8858
+ * account that does not exist. Any other existing account counts as created, whoever owns it; the
8859
+ * `decode*` functions still check the owner.
8860
+ *
8861
+ * The generated `fetchMaybe*` and `fetchAllMaybe*` helpers apply this rule themselves. Apply it to
8862
+ * accounts you fetch or receive another way (subscriptions, batch loaders, caches) before passing
8863
+ * them to a `decode*` function, which throws for a lamports-only account: an account passed to it as
8864
+ * existing must never come back as the non-existing variant typed as an `Account`.
8865
+ *
8866
+ * Only a `true` result narrows the type. A lamports-only account is still `exists: true` at runtime,
8867
+ * so a `false` result leaves the type unchanged instead of narrowing it to the non-existing variant.
8868
+ * The `uncreated` property in the narrowed type is never present; it exists only to prevent that.
8869
+ *
8870
+ * @example
8871
+ * ```ts
8872
+ * const maybeAccount = decodeMyAccount(
8873
+ * accountIsCreated(encodedAccount) ? encodedAccount : { address: encodedAccount.address, exists: false },
8874
+ * );
8875
+ * ```
8876
+ */
8877
+ function accountIsCreated(account) {
8878
+ const maybeAccount = account;
8879
+ if ("exists" in maybeAccount && !maybeAccount.exists) return false;
8880
+ return !(maybeAccount.programAddress === SYSTEM_PROGRAM_ADDRESS && maybeAccount.data.length === 0);
8881
+ }
8882
+ //#endregion
8656
8883
  //#region src/nexus/generated/accounts/altRegistry.ts
8657
8884
  /**
8658
8885
  * This code was AUTOGENERATED using the Codama library.
@@ -8716,21 +8943,40 @@ function decodeAltRegistry(encodedAccount) {
8716
8943
  }
8717
8944
  return (0, _solana_kit.decodeAccount)(encodedAccount, getAltRegistryDecoder());
8718
8945
  }
8946
+ /** Fetches a `AltRegistry` account, throwing when it does not exist or only holds lamports. */
8719
8947
  async function fetchAltRegistry(rpc, address, config) {
8720
8948
  const maybeAccount = await fetchMaybeAltRegistry(rpc, address, config);
8721
8949
  (0, _solana_kit.assertAccountExists)(maybeAccount);
8722
8950
  return maybeAccount;
8723
8951
  }
8952
+ /**
8953
+ * Fetches a `AltRegistry` account, or the non-existing variant when the address holds no
8954
+ * account or only lamports (see {@link accountIsCreated}).
8955
+ * {@link decodeAltRegistry} throws for a lamports-only account instead.
8956
+ */
8724
8957
  async function fetchMaybeAltRegistry(rpc, address, config) {
8725
- return decodeAltRegistry(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
8958
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
8959
+ return decodeAltRegistry(accountIsCreated(maybeAccount) ? maybeAccount : {
8960
+ address,
8961
+ exists: false
8962
+ });
8726
8963
  }
8964
+ /** Fetches `AltRegistry` accounts, throwing when any does not exist or only holds lamports. */
8727
8965
  async function fetchAllAltRegistry(rpc, addresses, config) {
8728
8966
  const maybeAccounts = await fetchAllMaybeAltRegistry(rpc, addresses, config);
8729
8967
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
8730
8968
  return maybeAccounts;
8731
8969
  }
8970
+ /**
8971
+ * Fetches `AltRegistry` accounts, with the non-existing variant for each address that holds
8972
+ * no account or only lamports (see {@link accountIsCreated}).
8973
+ * {@link decodeAltRegistry} throws for a lamports-only account instead.
8974
+ */
8732
8975
  async function fetchAllMaybeAltRegistry(rpc, addresses, config) {
8733
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeAltRegistry(maybeAccount));
8976
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeAltRegistry(accountIsCreated(maybeAccount) ? maybeAccount : {
8977
+ address: maybeAccount.address,
8978
+ exists: false
8979
+ }));
8734
8980
  }
8735
8981
  function getAltRegistrySize() {
8736
8982
  return 74;
@@ -8803,21 +9049,40 @@ function decodeCreatorFeeConfig(encodedAccount) {
8803
9049
  }
8804
9050
  return (0, _solana_kit.decodeAccount)(encodedAccount, getCreatorFeeConfigDecoder());
8805
9051
  }
9052
+ /** Fetches a `CreatorFeeConfig` account, throwing when it does not exist or only holds lamports. */
8806
9053
  async function fetchCreatorFeeConfig(rpc, address, config) {
8807
9054
  const maybeAccount = await fetchMaybeCreatorFeeConfig(rpc, address, config);
8808
9055
  (0, _solana_kit.assertAccountExists)(maybeAccount);
8809
9056
  return maybeAccount;
8810
9057
  }
9058
+ /**
9059
+ * Fetches a `CreatorFeeConfig` account, or the non-existing variant when the address holds no
9060
+ * account or only lamports (see {@link accountIsCreated}).
9061
+ * {@link decodeCreatorFeeConfig} throws for a lamports-only account instead.
9062
+ */
8811
9063
  async function fetchMaybeCreatorFeeConfig(rpc, address, config) {
8812
- return decodeCreatorFeeConfig(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9064
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9065
+ return decodeCreatorFeeConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9066
+ address,
9067
+ exists: false
9068
+ });
8813
9069
  }
9070
+ /** Fetches `CreatorFeeConfig` accounts, throwing when any does not exist or only holds lamports. */
8814
9071
  async function fetchAllCreatorFeeConfig(rpc, addresses, config) {
8815
9072
  const maybeAccounts = await fetchAllMaybeCreatorFeeConfig(rpc, addresses, config);
8816
9073
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
8817
9074
  return maybeAccounts;
8818
9075
  }
9076
+ /**
9077
+ * Fetches `CreatorFeeConfig` accounts, with the non-existing variant for each address that holds
9078
+ * no account or only lamports (see {@link accountIsCreated}).
9079
+ * {@link decodeCreatorFeeConfig} throws for a lamports-only account instead.
9080
+ */
8819
9081
  async function fetchAllMaybeCreatorFeeConfig(rpc, addresses, config) {
8820
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeCreatorFeeConfig(maybeAccount));
9082
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeCreatorFeeConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9083
+ address: maybeAccount.address,
9084
+ exists: false
9085
+ }));
8821
9086
  }
8822
9087
  function getCreatorFeeConfigSize() {
8823
9088
  return 151;
@@ -9045,21 +9310,40 @@ function decodeFeePreset(encodedAccount) {
9045
9310
  }
9046
9311
  return (0, _solana_kit.decodeAccount)(encodedAccount, getFeePresetDecoder());
9047
9312
  }
9313
+ /** Fetches a `FeePreset` account, throwing when it does not exist or only holds lamports. */
9048
9314
  async function fetchFeePreset(rpc, address, config) {
9049
9315
  const maybeAccount = await fetchMaybeFeePreset(rpc, address, config);
9050
9316
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9051
9317
  return maybeAccount;
9052
9318
  }
9319
+ /**
9320
+ * Fetches a `FeePreset` account, or the non-existing variant when the address holds no
9321
+ * account or only lamports (see {@link accountIsCreated}).
9322
+ * {@link decodeFeePreset} throws for a lamports-only account instead.
9323
+ */
9053
9324
  async function fetchMaybeFeePreset(rpc, address, config) {
9054
- return decodeFeePreset(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9325
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9326
+ return decodeFeePreset(accountIsCreated(maybeAccount) ? maybeAccount : {
9327
+ address,
9328
+ exists: false
9329
+ });
9055
9330
  }
9331
+ /** Fetches `FeePreset` accounts, throwing when any does not exist or only holds lamports. */
9056
9332
  async function fetchAllFeePreset(rpc, addresses, config) {
9057
9333
  const maybeAccounts = await fetchAllMaybeFeePreset(rpc, addresses, config);
9058
9334
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9059
9335
  return maybeAccounts;
9060
9336
  }
9337
+ /**
9338
+ * Fetches `FeePreset` accounts, with the non-existing variant for each address that holds
9339
+ * no account or only lamports (see {@link accountIsCreated}).
9340
+ * {@link decodeFeePreset} throws for a lamports-only account instead.
9341
+ */
9061
9342
  async function fetchAllMaybeFeePreset(rpc, addresses, config) {
9062
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeFeePreset(maybeAccount));
9343
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeFeePreset(accountIsCreated(maybeAccount) ? maybeAccount : {
9344
+ address: maybeAccount.address,
9345
+ exists: false
9346
+ }));
9063
9347
  }
9064
9348
  //#endregion
9065
9349
  //#region src/nexus/generated/accounts/globalConfig.ts
@@ -9129,21 +9413,40 @@ function decodeGlobalConfig(encodedAccount) {
9129
9413
  }
9130
9414
  return (0, _solana_kit.decodeAccount)(encodedAccount, getGlobalConfigDecoder());
9131
9415
  }
9416
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
9132
9417
  async function fetchGlobalConfig(rpc, address, config) {
9133
9418
  const maybeAccount = await fetchMaybeGlobalConfig(rpc, address, config);
9134
9419
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9135
9420
  return maybeAccount;
9136
9421
  }
9422
+ /**
9423
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
9424
+ * account or only lamports (see {@link accountIsCreated}).
9425
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
9426
+ */
9137
9427
  async function fetchMaybeGlobalConfig(rpc, address, config) {
9138
- return decodeGlobalConfig(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9428
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9429
+ return decodeGlobalConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9430
+ address,
9431
+ exists: false
9432
+ });
9139
9433
  }
9434
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
9140
9435
  async function fetchAllGlobalConfig(rpc, addresses, config) {
9141
9436
  const maybeAccounts = await fetchAllMaybeGlobalConfig(rpc, addresses, config);
9142
9437
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9143
9438
  return maybeAccounts;
9144
9439
  }
9440
+ /**
9441
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
9442
+ * no account or only lamports (see {@link accountIsCreated}).
9443
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
9444
+ */
9145
9445
  async function fetchAllMaybeGlobalConfig(rpc, addresses, config) {
9146
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig(maybeAccount));
9446
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9447
+ address: maybeAccount.address,
9448
+ exists: false
9449
+ }));
9147
9450
  }
9148
9451
  //#endregion
9149
9452
  //#region src/nexus/generated/accounts/partnerConfig.ts
@@ -9219,21 +9522,40 @@ function decodePartnerConfig(encodedAccount) {
9219
9522
  }
9220
9523
  return (0, _solana_kit.decodeAccount)(encodedAccount, getPartnerConfigDecoder());
9221
9524
  }
9525
+ /** Fetches a `PartnerConfig` account, throwing when it does not exist or only holds lamports. */
9222
9526
  async function fetchPartnerConfig(rpc, address, config) {
9223
9527
  const maybeAccount = await fetchMaybePartnerConfig(rpc, address, config);
9224
9528
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9225
9529
  return maybeAccount;
9226
9530
  }
9531
+ /**
9532
+ * Fetches a `PartnerConfig` account, or the non-existing variant when the address holds no
9533
+ * account or only lamports (see {@link accountIsCreated}).
9534
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
9535
+ */
9227
9536
  async function fetchMaybePartnerConfig(rpc, address, config) {
9228
- return decodePartnerConfig(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9537
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9538
+ return decodePartnerConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9539
+ address,
9540
+ exists: false
9541
+ });
9229
9542
  }
9543
+ /** Fetches `PartnerConfig` accounts, throwing when any does not exist or only holds lamports. */
9230
9544
  async function fetchAllPartnerConfig(rpc, addresses, config) {
9231
9545
  const maybeAccounts = await fetchAllMaybePartnerConfig(rpc, addresses, config);
9232
9546
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9233
9547
  return maybeAccounts;
9234
9548
  }
9549
+ /**
9550
+ * Fetches `PartnerConfig` accounts, with the non-existing variant for each address that holds
9551
+ * no account or only lamports (see {@link accountIsCreated}).
9552
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
9553
+ */
9235
9554
  async function fetchAllMaybePartnerConfig(rpc, addresses, config) {
9236
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodePartnerConfig(maybeAccount));
9555
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodePartnerConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9556
+ address: maybeAccount.address,
9557
+ exists: false
9558
+ }));
9237
9559
  }
9238
9560
  function getPartnerConfigSize() {
9239
9561
  return 173;
@@ -9312,21 +9634,40 @@ function decodePartnerMetadata(encodedAccount) {
9312
9634
  }
9313
9635
  return (0, _solana_kit.decodeAccount)(encodedAccount, getPartnerMetadataDecoder());
9314
9636
  }
9637
+ /** Fetches a `PartnerMetadata` account, throwing when it does not exist or only holds lamports. */
9315
9638
  async function fetchPartnerMetadata(rpc, address, config) {
9316
9639
  const maybeAccount = await fetchMaybePartnerMetadata(rpc, address, config);
9317
9640
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9318
9641
  return maybeAccount;
9319
9642
  }
9643
+ /**
9644
+ * Fetches a `PartnerMetadata` account, or the non-existing variant when the address holds no
9645
+ * account or only lamports (see {@link accountIsCreated}).
9646
+ * {@link decodePartnerMetadata} throws for a lamports-only account instead.
9647
+ */
9320
9648
  async function fetchMaybePartnerMetadata(rpc, address, config) {
9321
- return decodePartnerMetadata(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9649
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9650
+ return decodePartnerMetadata(accountIsCreated(maybeAccount) ? maybeAccount : {
9651
+ address,
9652
+ exists: false
9653
+ });
9322
9654
  }
9655
+ /** Fetches `PartnerMetadata` accounts, throwing when any does not exist or only holds lamports. */
9323
9656
  async function fetchAllPartnerMetadata(rpc, addresses, config) {
9324
9657
  const maybeAccounts = await fetchAllMaybePartnerMetadata(rpc, addresses, config);
9325
9658
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9326
9659
  return maybeAccounts;
9327
9660
  }
9661
+ /**
9662
+ * Fetches `PartnerMetadata` accounts, with the non-existing variant for each address that holds
9663
+ * no account or only lamports (see {@link accountIsCreated}).
9664
+ * {@link decodePartnerMetadata} throws for a lamports-only account instead.
9665
+ */
9328
9666
  async function fetchAllMaybePartnerMetadata(rpc, addresses, config) {
9329
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodePartnerMetadata(maybeAccount));
9667
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodePartnerMetadata(accountIsCreated(maybeAccount) ? maybeAccount : {
9668
+ address: maybeAccount.address,
9669
+ exists: false
9670
+ }));
9330
9671
  }
9331
9672
  //#endregion
9332
9673
  //#region src/nexus/generated/accounts/rewardState.ts
@@ -9406,21 +9747,40 @@ function decodeRewardState(encodedAccount) {
9406
9747
  }
9407
9748
  return (0, _solana_kit.decodeAccount)(encodedAccount, getRewardStateDecoder());
9408
9749
  }
9750
+ /** Fetches a `RewardState` account, throwing when it does not exist or only holds lamports. */
9409
9751
  async function fetchRewardState(rpc, address, config) {
9410
9752
  const maybeAccount = await fetchMaybeRewardState(rpc, address, config);
9411
9753
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9412
9754
  return maybeAccount;
9413
9755
  }
9756
+ /**
9757
+ * Fetches a `RewardState` account, or the non-existing variant when the address holds no
9758
+ * account or only lamports (see {@link accountIsCreated}).
9759
+ * {@link decodeRewardState} throws for a lamports-only account instead.
9760
+ */
9414
9761
  async function fetchMaybeRewardState(rpc, address, config) {
9415
- return decodeRewardState(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9762
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9763
+ return decodeRewardState(accountIsCreated(maybeAccount) ? maybeAccount : {
9764
+ address,
9765
+ exists: false
9766
+ });
9416
9767
  }
9768
+ /** Fetches `RewardState` accounts, throwing when any does not exist or only holds lamports. */
9417
9769
  async function fetchAllRewardState(rpc, addresses, config) {
9418
9770
  const maybeAccounts = await fetchAllMaybeRewardState(rpc, addresses, config);
9419
9771
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9420
9772
  return maybeAccounts;
9421
9773
  }
9774
+ /**
9775
+ * Fetches `RewardState` accounts, with the non-existing variant for each address that holds
9776
+ * no account or only lamports (see {@link accountIsCreated}).
9777
+ * {@link decodeRewardState} throws for a lamports-only account instead.
9778
+ */
9422
9779
  async function fetchAllMaybeRewardState(rpc, addresses, config) {
9423
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeRewardState(maybeAccount));
9780
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeRewardState(accountIsCreated(maybeAccount) ? maybeAccount : {
9781
+ address: maybeAccount.address,
9782
+ exists: false
9783
+ }));
9424
9784
  }
9425
9785
  function getRewardStateSize() {
9426
9786
  return 196;
@@ -9495,21 +9855,40 @@ function decodeStakingConfig(encodedAccount) {
9495
9855
  }
9496
9856
  return (0, _solana_kit.decodeAccount)(encodedAccount, getStakingConfigDecoder());
9497
9857
  }
9858
+ /** Fetches a `StakingConfig` account, throwing when it does not exist or only holds lamports. */
9498
9859
  async function fetchStakingConfig(rpc, address, config) {
9499
9860
  const maybeAccount = await fetchMaybeStakingConfig(rpc, address, config);
9500
9861
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9501
9862
  return maybeAccount;
9502
9863
  }
9864
+ /**
9865
+ * Fetches a `StakingConfig` account, or the non-existing variant when the address holds no
9866
+ * account or only lamports (see {@link accountIsCreated}).
9867
+ * {@link decodeStakingConfig} throws for a lamports-only account instead.
9868
+ */
9503
9869
  async function fetchMaybeStakingConfig(rpc, address, config) {
9504
- return decodeStakingConfig(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9870
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9871
+ return decodeStakingConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9872
+ address,
9873
+ exists: false
9874
+ });
9505
9875
  }
9876
+ /** Fetches `StakingConfig` accounts, throwing when any does not exist or only holds lamports. */
9506
9877
  async function fetchAllStakingConfig(rpc, addresses, config) {
9507
9878
  const maybeAccounts = await fetchAllMaybeStakingConfig(rpc, addresses, config);
9508
9879
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9509
9880
  return maybeAccounts;
9510
9881
  }
9882
+ /**
9883
+ * Fetches `StakingConfig` accounts, with the non-existing variant for each address that holds
9884
+ * no account or only lamports (see {@link accountIsCreated}).
9885
+ * {@link decodeStakingConfig} throws for a lamports-only account instead.
9886
+ */
9511
9887
  async function fetchAllMaybeStakingConfig(rpc, addresses, config) {
9512
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeStakingConfig(maybeAccount));
9888
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeStakingConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9889
+ address: maybeAccount.address,
9890
+ exists: false
9891
+ }));
9513
9892
  }
9514
9893
  function getStakingConfigSize() {
9515
9894
  return 117;
@@ -9592,21 +9971,40 @@ function decodeUserRewardDebt(encodedAccount) {
9592
9971
  }
9593
9972
  return (0, _solana_kit.decodeAccount)(encodedAccount, getUserRewardDebtDecoder());
9594
9973
  }
9974
+ /** Fetches a `UserRewardDebt` account, throwing when it does not exist or only holds lamports. */
9595
9975
  async function fetchUserRewardDebt(rpc, address, config) {
9596
9976
  const maybeAccount = await fetchMaybeUserRewardDebt(rpc, address, config);
9597
9977
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9598
9978
  return maybeAccount;
9599
9979
  }
9980
+ /**
9981
+ * Fetches a `UserRewardDebt` account, or the non-existing variant when the address holds no
9982
+ * account or only lamports (see {@link accountIsCreated}).
9983
+ * {@link decodeUserRewardDebt} throws for a lamports-only account instead.
9984
+ */
9600
9985
  async function fetchMaybeUserRewardDebt(rpc, address, config) {
9601
- return decodeUserRewardDebt(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
9986
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
9987
+ return decodeUserRewardDebt(accountIsCreated(maybeAccount) ? maybeAccount : {
9988
+ address,
9989
+ exists: false
9990
+ });
9602
9991
  }
9992
+ /** Fetches `UserRewardDebt` accounts, throwing when any does not exist or only holds lamports. */
9603
9993
  async function fetchAllUserRewardDebt(rpc, addresses, config) {
9604
9994
  const maybeAccounts = await fetchAllMaybeUserRewardDebt(rpc, addresses, config);
9605
9995
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9606
9996
  return maybeAccounts;
9607
9997
  }
9998
+ /**
9999
+ * Fetches `UserRewardDebt` accounts, with the non-existing variant for each address that holds
10000
+ * no account or only lamports (see {@link accountIsCreated}).
10001
+ * {@link decodeUserRewardDebt} throws for a lamports-only account instead.
10002
+ */
9608
10003
  async function fetchAllMaybeUserRewardDebt(rpc, addresses, config) {
9609
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeUserRewardDebt(maybeAccount));
10004
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeUserRewardDebt(accountIsCreated(maybeAccount) ? maybeAccount : {
10005
+ address: maybeAccount.address,
10006
+ exists: false
10007
+ }));
9610
10008
  }
9611
10009
  function getUserRewardDebtSize() {
9612
10010
  return 182;
@@ -9683,21 +10081,40 @@ function decodeUserStakePosition(encodedAccount) {
9683
10081
  }
9684
10082
  return (0, _solana_kit.decodeAccount)(encodedAccount, getUserStakePositionDecoder());
9685
10083
  }
10084
+ /** Fetches a `UserStakePosition` account, throwing when it does not exist or only holds lamports. */
9686
10085
  async function fetchUserStakePosition(rpc, address, config) {
9687
10086
  const maybeAccount = await fetchMaybeUserStakePosition(rpc, address, config);
9688
10087
  (0, _solana_kit.assertAccountExists)(maybeAccount);
9689
10088
  return maybeAccount;
9690
10089
  }
10090
+ /**
10091
+ * Fetches a `UserStakePosition` account, or the non-existing variant when the address holds no
10092
+ * account or only lamports (see {@link accountIsCreated}).
10093
+ * {@link decodeUserStakePosition} throws for a lamports-only account instead.
10094
+ */
9691
10095
  async function fetchMaybeUserStakePosition(rpc, address, config) {
9692
- return decodeUserStakePosition(await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config));
10096
+ const maybeAccount = await (0, _solana_kit.fetchEncodedAccount)(rpc, address, config);
10097
+ return decodeUserStakePosition(accountIsCreated(maybeAccount) ? maybeAccount : {
10098
+ address,
10099
+ exists: false
10100
+ });
9693
10101
  }
10102
+ /** Fetches `UserStakePosition` accounts, throwing when any does not exist or only holds lamports. */
9694
10103
  async function fetchAllUserStakePosition(rpc, addresses, config) {
9695
10104
  const maybeAccounts = await fetchAllMaybeUserStakePosition(rpc, addresses, config);
9696
10105
  (0, _solana_kit.assertAccountsExist)(maybeAccounts);
9697
10106
  return maybeAccounts;
9698
10107
  }
10108
+ /**
10109
+ * Fetches `UserStakePosition` accounts, with the non-existing variant for each address that holds
10110
+ * no account or only lamports (see {@link accountIsCreated}).
10111
+ * {@link decodeUserStakePosition} throws for a lamports-only account instead.
10112
+ */
9699
10113
  async function fetchAllMaybeUserStakePosition(rpc, addresses, config) {
9700
- return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeUserStakePosition(maybeAccount));
10114
+ return (await (0, _solana_kit.fetchEncodedAccounts)(rpc, addresses, config)).map((maybeAccount) => decodeUserStakePosition(accountIsCreated(maybeAccount) ? maybeAccount : {
10115
+ address: maybeAccount.address,
10116
+ exists: false
10117
+ }));
9701
10118
  }
9702
10119
  function getUserStakePositionSize() {
9703
10120
  return 120;
@@ -12273,7 +12690,8 @@ var fee_helpers_exports = /* @__PURE__ */ __exportAll({
12273
12690
  effectiveFeeBps: () => effectiveFeeBps,
12274
12691
  fetchPartnerFees: () => fetchPartnerFees
12275
12692
  });
12276
- /** Throws if the pair is unregistered. Take `platformConfig` from the market being priced: a partner's fees differ per platform. */
12693
+ /** Fetches the `PartnerConfig` of `partner` on `platformConfig`. Throws if it does not exist.
12694
+ * Use the `platformConfig` of the market you price. A partner's fees differ per platform. */
12277
12695
  async function fetchPartnerFees(rpc, partner, platformConfig) {
12278
12696
  const [partnerPda] = await findPartnerConfigPda({
12279
12697
  partner,
@@ -12283,8 +12701,9 @@ async function fetchPartnerFees(rpc, partner, platformConfig) {
12283
12701
  if (!maybeAccount.exists) throw new Error(`No fee config for partner ${partner} on platform ${platformConfig}`);
12284
12702
  return maybeAccount.data;
12285
12703
  }
12286
- /** The `feeBps` a trade pays: the standard rate plus the decay premium from the market's
12287
- * `createdAt`. Pass `fees.launchpad` for a curve, `fees.dex` for a pool; times in unix seconds. */
12704
+ /** Returns the `feeBps` a trade pays: the standard rate plus the decay premium. `schedule` is the
12705
+ * `PartnerConfig`'s `launchpad` for a curve or `dex` for a pool. `createdAt` is the curve's or
12706
+ * pool's `createdAt`. Both times are in unix seconds. */
12288
12707
  function effectiveFeeBps(schedule, createdAt, now) {
12289
12708
  const standardFeeBps = schedule.protocolFeeBps + schedule.creatorFeeBps + ("lpFeeBps" in schedule ? schedule.lpFeeBps : 0);
12290
12709
  const premium = calculateFeeDecayPremium({
@@ -12300,7 +12719,7 @@ function effectiveFeeBps(schedule, createdAt, now) {
12300
12719
  //#region src/utils/chunk.ts
12301
12720
  /** RPCs reject a `getMultipleAccounts` call past this many addresses. */
12302
12721
  const MAX_ACCOUNTS_PER_REQUEST = 100;
12303
- /** Splits a multi-account read into 100-address calls; results follow `addresses` order. */
12722
+ /** Calls `read` once per 100 addresses. Results follow `addresses` order. */
12304
12723
  async function fetchInChunks(addresses, read) {
12305
12724
  const chunks = [];
12306
12725
  for (let start = 0; start < addresses.length; start += MAX_ACCOUNTS_PER_REQUEST) chunks.push(addresses.slice(start, start + MAX_ACCOUNTS_PER_REQUEST));
@@ -12335,9 +12754,8 @@ function compareAddresses(a, b) {
12335
12754
  if (a > b) return 1;
12336
12755
  return 0;
12337
12756
  }
12338
- /** Registered reward mints, sorted by address. Includes disabled mints: their accrued balance is
12339
- * still owed and the settle gate still counts them. Throws when the sweep disagrees with
12340
- * `StakingConfig.rewardCount` rather than settle a short list. */
12757
+ /** Returns every registered reward mint, disabled mints included, sorted by address.
12758
+ * Throws if the count differs from `StakingConfig.rewardCount`. */
12341
12759
  async function getRewardMints(rpc) {
12342
12760
  const [stakingConfig] = findStakingConfigPda();
12343
12761
  const [accounts, config] = await Promise.all([rpc.getProgramAccounts(SEND_NEXUS_PROGRAM_ADDRESS, {
@@ -12367,7 +12785,8 @@ async function resolveRewardMints(rpc, rewardMints) {
12367
12785
  if (!hasProgramAccounts(rpc)) throw new Error("This RPC has no getProgramAccounts, so the reward registry cannot be read from chain. Pass rewardMints explicitly.");
12368
12786
  return await getRewardMints(rpc);
12369
12787
  }
12370
- /** One idempotent `settle` per mint; a partial mint list leaves `stake` and `unstake` failing `RewardsNotSettled`. */
12788
+ /** Builds one `settle` per reward mint. `source` is the mint list, or an RPC to read it from.
12789
+ * `settle` is idempotent. With a partial list, `stake` and `unstake` fail with `RewardsNotSettled`. */
12371
12790
  async function buildSettleInstructions(source, params) {
12372
12791
  const rewardMints = isRewardMintList(source) ? source : await resolveRewardMints(source, void 0);
12373
12792
  return Promise.all(rewardMints.map((rewardMint) => getSettleInstructionAsync({
@@ -12388,10 +12807,11 @@ async function fetchMissingUserRewardDebts(rpc, user, stakingMint, knownRewardMi
12388
12807
  return addr;
12389
12808
  })), (chunk) => (0, _solana_kit.fetchEncodedAccounts)(rpc, chunk));
12390
12809
  const missingMints = [];
12391
- for (const [index, rewardMint] of rewardMints.entries()) if (!encodedAccounts[index].exists) missingMints.push(rewardMint);
12810
+ for (const [index, rewardMint] of rewardMints.entries()) if (!accountIsCreated(encodedAccounts[index])) missingMints.push(rewardMint);
12392
12811
  return missingMints;
12393
12812
  }
12394
- /** Opens missing `UserRewardDebt`s, then settles every mint; the user never signs, so the stake or unstake after is one wallet prompt. */
12813
+ /** Builds a `create_user_reward_debt` for each missing `UserRewardDebt`, then a `settle` for every
12814
+ * reward mint. The user does not sign these instructions. */
12395
12815
  async function buildStakingPreflightInstructions(rpc, params) {
12396
12816
  const rewardMints = await resolveRewardMints(rpc, params.rewardMints);
12397
12817
  const missingMints = await fetchMissingUserRewardDebts(rpc, params.user, params.stakingMint, rewardMints);
@@ -12404,13 +12824,14 @@ async function buildStakingPreflightInstructions(rpc, params) {
12404
12824
  const settleIxs = await buildSettleInstructions(rewardMints, params);
12405
12825
  return [...createIxs, ...settleIxs];
12406
12826
  }
12407
- /** True once `stake` and `unstake` will pass the `settledCount == rewardCount` gate. */
12827
+ /** Returns true if `stake` and `unstake` pass the `settledCount == rewardCount` check. */
12408
12828
  async function isFullySettled(rpc, user, stakingMint) {
12409
12829
  const [config, position] = await Promise.all([fetchStakingConfigData(rpc), fetchUserStakePositionData(rpc, user, stakingMint)]);
12410
12830
  if (position === null) return config.rewardCount === 0;
12411
12831
  return position.settledCount === config.rewardCount;
12412
12832
  }
12413
- /** Fails `RewardsNotSettled` until every mint is settled at the current `stakeVersion`; run `buildStakingPreflightInstructions` first. */
12833
+ /** The instruction fails with `RewardsNotSettled` until every mint is settled at the current
12834
+ * `stakeVersion`. Run `buildStakingPreflightInstructions` first. */
12414
12835
  async function buildStakeInstruction(params) {
12415
12836
  return getStakeInstructionAsync({
12416
12837
  user: params.user,
@@ -12419,8 +12840,9 @@ async function buildStakeInstruction(params) {
12419
12840
  amount: params.amount
12420
12841
  });
12421
12842
  }
12422
- /** Settle immediately before via `buildStakingPreflightInstructions`: the gate passes on a stale settle,
12423
- * and the window since it is then paid at the post-unstake amount, forfeiting accrual. */
12843
+ /** Run `buildStakingPreflightInstructions` immediately before. The check also passes on an older
12844
+ * settle. Rewards since that settle then accrue on the smaller post-unstake amount, and the
12845
+ * difference is lost. */
12424
12846
  async function buildUnstakeInstruction(params) {
12425
12847
  return getUnstakeInstructionAsync({
12426
12848
  user: params.user,
@@ -12429,8 +12851,8 @@ async function buildUnstakeInstruction(params) {
12429
12851
  amount: params.amount
12430
12852
  });
12431
12853
  }
12432
- /** One `claim` per mint, preceded by `create_user_reward_debt` where the debt is missing:
12433
- * `Claim` requires the account to exist, so one missing debt fails the whole transaction. */
12854
+ /** Builds one `claim` per reward mint. A `create_user_reward_debt` comes before each `claim` whose
12855
+ * `UserRewardDebt` is missing: `claim` fails without it. Throws if a mint has no `RewardState`. */
12434
12856
  async function buildClaimRewardsInstructions(rpc, params) {
12435
12857
  const [stakingConfigAddr] = findStakingConfigPda();
12436
12858
  const rewardMints = await resolveRewardMints(rpc, params.rewardMints);
@@ -12458,13 +12880,13 @@ async function buildClaimRewardsInstructions(rpc, params) {
12458
12880
  const payer = params.payer ?? params.user;
12459
12881
  return (await Promise.all(rewardMints.map(async (rewardMint, index) => {
12460
12882
  const encodedRewardState = fetched[index];
12461
- if (!encodedRewardState.exists) throw new Error(`RewardState not found for mint ${rewardMint}`);
12883
+ if (!accountIsCreated(encodedRewardState)) throw new Error(`RewardState not found for mint ${rewardMint}`);
12462
12884
  const { vault } = rewardStateDecoder.decode(encodedRewardState.data);
12463
12885
  const encodedMint = fetched[rewardMints.length + index];
12464
12886
  const tokenProgram = encodedMint.exists ? encodedMint.programAddress : void 0;
12465
12887
  const [destination] = await findAssociatedTokenPda(params.user.address, rewardMint, tokenProgram);
12466
12888
  const instructions = [];
12467
- if (!fetched[rewardMints.length * 2 + index].exists) instructions.push(await getCreateUserRewardDebtInstructionAsync({
12889
+ if (!accountIsCreated(fetched[rewardMints.length * 2 + index])) instructions.push(await getCreateUserRewardDebtInstructionAsync({
12468
12890
  user: params.user.address,
12469
12891
  payer,
12470
12892
  stakingMint: params.stakingMint,
@@ -12482,7 +12904,8 @@ async function buildClaimRewardsInstructions(rpc, params) {
12482
12904
  return instructions;
12483
12905
  }))).flat();
12484
12906
  }
12485
- /** Accounts for one mint's `withdraw_fees`; call once per mint. */
12907
+ /** Returns the accounts of `withdraw_fees` for one reward mint. Without `tokenProgram`, reads it
12908
+ * from the mint account. Throws if that account does not exist. */
12486
12909
  async function buildWithdrawFeesAccounts(rpc, params) {
12487
12910
  const [stakingConfigAddr] = findStakingConfigPda();
12488
12911
  const tokenProgram = params.tokenProgram ?? (await rpc.getAccountInfo(params.rewardMint, { encoding: "base64" }).send()).value?.owner;
@@ -12515,19 +12938,19 @@ async function fetchUserStakePositionData(rpc, user, stakingMint) {
12515
12938
  const maybePosition = await fetchMaybeUserStakePosition(rpc, positionAddr);
12516
12939
  return maybePosition.exists ? maybePosition.data : null;
12517
12940
  }
12518
- /** Unbound reads as `Pubkey::default()` (the system program address), which `bind_staking_mint`
12519
- * can never store: it requires a token mint. */
12941
+ /** Returns false for the system program address, the value of an unbound staking mint. */
12520
12942
  function isStakingMintBound(stakingMint) {
12521
- return stakingMint !== SYSTEM_PROGRAM_ADDRESS;
12943
+ return stakingMint !== SYSTEM_PROGRAM_ADDRESS$3;
12522
12944
  }
12523
- /** The staking mint is immutable once bound, so this result is safe to cache. */
12945
+ /** Returns the staking mint. Throws if no staking mint is bound. A bound staking mint cannot change. */
12524
12946
  async function fetchSendMint(rpc) {
12525
12947
  const { stakingMint } = await fetchStakingConfigData(rpc);
12526
12948
  if (!isStakingMintBound(stakingMint)) throw new Error("Staking mint not yet bound -- nexus not fully initialized");
12527
12949
  return stakingMint;
12528
12950
  }
12529
- /** One entry per reward mint, in `knownRewardMints` order, else sorted by address. Each amount is in
12530
- * its own mint's base units, so never sum them, and is the vault's debit, not the claimant's credit. */
12951
+ /** Returns one entry per reward mint, in `knownRewardMints` order, else sorted by address. Each amount
12952
+ * is in the raw units of its own mint. Do not add them together. Each amount is what the vault sends,
12953
+ * before the mint's transfer fee. */
12531
12954
  async function fetchPendingRewards(rpc, user, stakingMint, knownRewardMints) {
12532
12955
  const rewardMints = await resolveRewardMints(rpc, knownRewardMints);
12533
12956
  if (rewardMints.length === 0) return [];
@@ -12568,15 +12991,15 @@ async function fetchPendingRewards(rpc, user, stakingMint, knownRewardMints) {
12568
12991
  return pdas.map(({ rewardMint }, index) => {
12569
12992
  const base = index * 3;
12570
12993
  const encodedDebt = encodedAccounts[base];
12571
- const debt = encodedDebt.exists ? userRewardDebtDecoder.decode(encodedDebt.data) : {
12994
+ const debt = accountIsCreated(encodedDebt) ? userRewardDebtDecoder.decode(encodedDebt.data) : {
12572
12995
  owed: 0n,
12573
12996
  accSnapshot: 0n,
12574
12997
  amountSnapshot: stakeAmount
12575
12998
  };
12576
12999
  const encodedLaunchpadAccrual = encodedAccounts[base + 1];
12577
- const launchpadAcc = encodedLaunchpadAccrual.exists ? rewardAccrualDecoder.decode(encodedLaunchpadAccrual.data).accPerToken : 0n;
13000
+ const launchpadAcc = accountIsCreated(encodedLaunchpadAccrual) ? rewardAccrualDecoder.decode(encodedLaunchpadAccrual.data).accPerToken : 0n;
12578
13001
  const encodedDexAccrual = encodedAccounts[base + 2];
12579
- const dexAcc = encodedDexAccrual.exists ? rewardAccrualDecoder.decode(encodedDexAccrual.data).accPerToken : 0n;
13002
+ const dexAcc = accountIsCreated(encodedDexAccrual) ? rewardAccrualDecoder.decode(encodedDexAccrual.data).accPerToken : 0n;
12580
13003
  const basis = debt.amountSnapshot < stakeAmount ? debt.amountSnapshot : stakeAmount;
12581
13004
  const combined = launchpadAcc + dexAcc;
12582
13005
  const accrued = basis * (combined > debt.accSnapshot ? combined - debt.accSnapshot : 0n) / PRECISION;
@@ -12605,9 +13028,9 @@ var platform_exports = /* @__PURE__ */ __exportAll({
12605
13028
  PLATFORM_SEED: () => PLATFORM_SEED,
12606
13029
  findPlatformAddress: () => findPlatformAddress
12607
13030
  });
12608
- /** A platform is only a key, with no on-chain account; it is a PDA so a platform account can later `init` at it. */
13031
+ /** Seed of the platform PDA. A platform has no on-chain account. */
12609
13032
  const PLATFORM_SEED = "platform";
12610
- /** The name is the platform's identity: renaming one orphans every market and partner config under the old key. */
13033
+ /** Derives the platform key for `name` under the nexus program. Each name gives a different platform. */
12611
13034
  async function findPlatformAddress(name) {
12612
13035
  return await (0, _solana_kit.getProgramDerivedAddress)({
12613
13036
  programAddress: SEND_NEXUS_PROGRAM_ADDRESS,
@@ -12649,8 +13072,9 @@ function readEntry(view, start) {
12649
13072
  basisPoints: view.getUint16(start + FEE_BASIS_POINTS, true)
12650
13073
  };
12651
13074
  }
12652
- /** `owner` is the account's program. `undefined` means no fee extension; anything
12653
- * unparseable throws `RangeError` rather than pricing a charging mint free. */
13075
+ /** Decodes the `TransferFeeConfig` extension of a mint. `owner` is the program that owns the account.
13076
+ * Returns `undefined` if the mint has no such extension. Throws `RangeError` if `owner` is not a
13077
+ * token program or `data` is not a valid mint. */
12654
13078
  function decodeTransferFeeConfig(data, owner) {
12655
13079
  if (owner === TOKEN_PROGRAM_ADDRESS) return void 0;
12656
13080
  if (owner !== TOKEN_2022_PROGRAM_ADDRESS) throw new RangeError(`decodeTransferFeeConfig: ${owner} is not a token program`);
@@ -12679,7 +13103,7 @@ function decodeTransferFeeConfig(data, owner) {
12679
13103
  offset = next;
12680
13104
  }
12681
13105
  }
12682
- /** Mirrors SPL `get_epoch_fee`: the newer entry is live from its own epoch on. */
13106
+ /** Returns the fee for `epoch`, as SPL `get_epoch_fee` does. The newer entry applies from its own epoch on. */
12683
13107
  function transferFeeAtEpoch(config, epoch) {
12684
13108
  const entry = epoch >= config.newer.epoch ? config.newer : config.older;
12685
13109
  return {
@@ -12694,8 +13118,9 @@ function mintFeeAtEpoch(data, owner, epoch) {
12694
13118
  function currentEpoch(rpc, commitment) {
12695
13119
  return rpc.getEpochInfo(commitment === void 0 ? void 0 : { commitment }).send().then((info) => info.epoch);
12696
13120
  }
12697
- /** A missing account throws, never reads as fee-free. Valid only for `epoch`, which defaults to
12698
- * the cluster's (a second call). */
13121
+ /** Reads the transfer fee of each mint for `epoch`. The result is valid only for that epoch.
13122
+ * `epoch` defaults to the current cluster epoch, read with `getEpochInfo`. A mint without a
13123
+ * transfer fee maps to `undefined`. Throws if a mint account is missing or does not decode. */
12699
13124
  async function fetchMintFees(rpc, mints, options) {
12700
13125
  const commitment = options?.commitment;
12701
13126
  const [epoch, accounts] = await Promise.all([options?.epoch ?? currentEpoch(rpc, commitment), fetchInChunks(mints, (chunk) => rpc.getMultipleAccounts(chunk, commitment === void 0 ? { encoding: "base64" } : {
@@ -12724,7 +13149,8 @@ function decodeMintInfo(mint, data, owner) {
12724
13149
  tokenProgram: owner
12725
13150
  };
12726
13151
  }
12727
- /** Throws when the mint does not exist or is not owned by a token program. */
13152
+ /** Reads the decimals and token program of `mint`. Throws if the account does not exist, a token
13153
+ * program does not own it, or it is too short for a mint. */
12728
13154
  async function fetchQuoteMintInfo(rpc, mint, commitment) {
12729
13155
  const { value } = await rpc.getAccountInfo(mint, commitment === void 0 ? { encoding: "base64" } : {
12730
13156
  commitment,
@@ -12733,7 +13159,8 @@ async function fetchQuoteMintInfo(rpc, mint, commitment) {
12733
13159
  if (!value) throw new Error(`fetchQuoteMintInfo: no account at ${mint}`);
12734
13160
  return decodeMintInfo(mint, new Uint8Array((0, _solana_kit.getBase64Encoder)().encode(value.data[0])), value.owner);
12735
13161
  }
12736
- /** One round trip per 100 mints; results follow `mints` order. */
13162
+ /** Reads the decimals and token program of each mint. Results follow `mints` order. Throws as
13163
+ * {@link fetchQuoteMintInfo} does. */
12737
13164
  async function fetchQuoteMintInfos(rpc, mints, commitment) {
12738
13165
  if (mints.length === 0) return [];
12739
13166
  const value = await fetchInChunks(mints, (chunk) => rpc.getMultipleAccounts(chunk, commitment === void 0 ? { encoding: "base64" } : {
@@ -12750,6 +13177,7 @@ async function fetchQuoteMintInfos(rpc, mints, commitment) {
12750
13177
  //#endregion
12751
13178
  //#region src/utils/index.ts
12752
13179
  var utils_exports = /* @__PURE__ */ __exportAll({
13180
+ accountIsCreated: () => accountIsCreated,
12753
13181
  creatorHashFromId: () => creatorHashFromId,
12754
13182
  decodeCreatorId: () => decodeCreatorId,
12755
13183
  encodeCreatorId: () => encodeCreatorId,