@send-fun/sdk 1.0.1 → 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 (72) hide show
  1. package/README.md +13 -5
  2. package/dist/index.cjs +797 -369
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +596 -94
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +596 -94
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +527 -99
  9. package/dist/index.mjs.map +1 -1
  10. package/package.json +4 -6
  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/instructions/buyExactIn.ts +1 -1
  16. package/src/dex/generated/instructions/buyExactOut.ts +1 -1
  17. package/src/dex/generated/instructions/claimCreatorFees.ts +1 -1
  18. package/src/dex/generated/instructions/claimProtocolFees.ts +1 -1
  19. package/src/dex/generated/instructions/sellExactIn.ts +1 -1
  20. package/src/dex/generated/instructions/sellExactOut.ts +1 -1
  21. package/src/dex/generated/plugins/sendDex.ts +1 -1
  22. package/src/dex/generated/shared/index.ts +52 -0
  23. package/src/dex/trade.ts +12 -13
  24. package/src/launchpad/create.ts +8 -8
  25. package/src/launchpad/generated/accounts/bondingCurve.ts +39 -2
  26. package/src/launchpad/generated/accounts/globalConfig.ts +39 -2
  27. package/src/launchpad/generated/accounts/rewardAccrual.ts +39 -2
  28. package/src/launchpad/generated/index.ts +1 -0
  29. package/src/launchpad/generated/instructions/buyExactIn.ts +1 -1
  30. package/src/launchpad/generated/instructions/buyExactOut.ts +1 -1
  31. package/src/launchpad/generated/instructions/claimCreatorFees.ts +1 -1
  32. package/src/launchpad/generated/instructions/claimProtocolFees.ts +1 -1
  33. package/src/launchpad/generated/instructions/createToken.ts +1 -1
  34. package/src/launchpad/generated/instructions/migrate.ts +1 -1
  35. package/src/launchpad/generated/instructions/sellExactIn.ts +1 -1
  36. package/src/launchpad/generated/instructions/sellExactOut.ts +1 -1
  37. package/src/launchpad/generated/plugins/sendLaunchpad.ts +1 -1
  38. package/src/launchpad/generated/shared/index.ts +52 -0
  39. package/src/launchpad/migrate.ts +1 -1
  40. package/src/launchpad/trade.ts +15 -15
  41. package/src/math/amm.ts +40 -33
  42. package/src/math/fee-decay.ts +3 -2
  43. package/src/math/fees.ts +4 -2
  44. package/src/math/internal.ts +1 -1
  45. package/src/nexus/fee-helpers.ts +5 -3
  46. package/src/nexus/generated/accounts/altRegistry.ts +41 -2
  47. package/src/nexus/generated/accounts/creatorFeeConfig.ts +39 -2
  48. package/src/nexus/generated/accounts/feePreset.ts +41 -2
  49. package/src/nexus/generated/accounts/globalConfig.ts +39 -2
  50. package/src/nexus/generated/accounts/partnerConfig.ts +39 -2
  51. package/src/nexus/generated/accounts/partnerMetadata.ts +39 -2
  52. package/src/nexus/generated/accounts/rewardState.ts +41 -2
  53. package/src/nexus/generated/accounts/stakingConfig.ts +39 -2
  54. package/src/nexus/generated/accounts/userRewardDebt.ts +39 -2
  55. package/src/nexus/generated/accounts/userStakePosition.ts +39 -2
  56. package/src/nexus/generated/index.ts +1 -0
  57. package/src/nexus/generated/instructions/claim.ts +1 -1
  58. package/src/nexus/generated/instructions/createUserRewardDebt.ts +1 -1
  59. package/src/nexus/generated/instructions/settle.ts +1 -1
  60. package/src/nexus/generated/instructions/stake.ts +1 -1
  61. package/src/nexus/generated/instructions/unstake.ts +1 -1
  62. package/src/nexus/generated/plugins/sendNexus.ts +1 -1
  63. package/src/nexus/generated/shared/index.ts +52 -0
  64. package/src/nexus/staking.ts +45 -41
  65. package/src/platform.ts +2 -2
  66. package/src/transfer-fee.ts +19 -17
  67. package/src/utils/chunk.ts +1 -1
  68. package/src/utils/creator-hash.ts +6 -3
  69. package/src/utils/index.ts +2 -0
  70. package/src/utils/mint-info.ts +8 -7
  71. package/src/utils/partner.ts +1 -1
  72. package/src/utils/pda.ts +1 -1
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, addDecoderSizePrefix, addEncoderSizePrefix, address, assertAccountExists, assertAccountsExist, assertIsInstructionForProgram, assertIsInstructionWithAccounts, combineCodec, containsBytes, decodeAccount, extendClient, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getArrayDecoder, getArrayEncoder, getBase64Encoder, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getEnumDecoder, getEnumEncoder, getI64Decoder, getI64Encoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, getUtf8Decoder, getUtf8Encoder, isProgramError, transformEncoder } from "@solana/kit";
3
- import { addSelfPlanAndSendFunctions, getAccountMetaFactory, getAddressFromResolvedInstructionAccount, getNonNullResolvedInstructionInput } from "@solana/program-client-core";
3
+ import { addSelfPlanAndSendFunctions, getAccountMetaFactory, getAddressFromResolvedInstructionAccount, getNonNullResolvedInstructionInput } from "@solana/kit/program-client-core";
4
4
  //#region src/dex/generated/programs/sendDex.ts
5
5
  const SEND_DEX_PROGRAM_ADDRESS = "84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX";
6
6
  //#endregion
@@ -18,22 +18,55 @@ var constants_exports = /* @__PURE__ */ __exportAll({
18
18
  SEND_DEX_PROGRAM_ADDRESS: () => SEND_DEX_PROGRAM_ADDRESS,
19
19
  SEND_LAUNCHPAD_PROGRAM_ADDRESS: () => SEND_LAUNCHPAD_PROGRAM_ADDRESS,
20
20
  SEND_NEXUS_PROGRAM_ADDRESS: () => SEND_NEXUS_PROGRAM_ADDRESS,
21
- SYSTEM_PROGRAM_ADDRESS: () => SYSTEM_PROGRAM_ADDRESS,
21
+ SYSTEM_PROGRAM_ADDRESS: () => SYSTEM_PROGRAM_ADDRESS$3,
22
22
  TOKEN_2022_PROGRAM_ADDRESS: () => TOKEN_2022_PROGRAM_ADDRESS,
23
23
  TOKEN_DECIMALS: () => 6,
24
24
  TOKEN_PROGRAM_ADDRESS: () => TOKEN_PROGRAM_ADDRESS,
25
25
  USDC_MINT: () => USDC_MINT,
26
26
  WSOL_MINT: () => WSOL_MINT
27
27
  });
28
- const SYSTEM_PROGRAM_ADDRESS = address("11111111111111111111111111111111");
28
+ const SYSTEM_PROGRAM_ADDRESS$3 = address("11111111111111111111111111111111");
29
29
  const TOKEN_PROGRAM_ADDRESS = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
30
30
  const TOKEN_2022_PROGRAM_ADDRESS = address("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
31
31
  const ASSOCIATED_TOKEN_PROGRAM_ADDRESS = address("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
32
32
  const WSOL_MINT = address("So11111111111111111111111111111111111111112");
33
33
  const USDC_MINT = address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
34
- const DEFAULT_PARTNER = SYSTEM_PROGRAM_ADDRESS;
34
+ const DEFAULT_PARTNER = SYSTEM_PROGRAM_ADDRESS$3;
35
35
  const PYTH_SOL_USD_PRICE_ACCOUNT = address("7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE");
36
36
  //#endregion
37
+ //#region src/dex/generated/shared/index.ts
38
+ /** The System Program, which owns every address nobody has created an account at yet. */
39
+ const SYSTEM_PROGRAM_ADDRESS$2 = "11111111111111111111111111111111";
40
+ /**
41
+ * Whether an encoded account was created on-chain, rather than merely sent lamports.
42
+ *
43
+ * Anyone can send lamports to an address before its account is created, which leaves it on-chain,
44
+ * owned by the System Program, with no data. This returns `false` for that shape, as it does for an
45
+ * account that does not exist. Any other existing account counts as created, whoever owns it; the
46
+ * `decode*` functions still check the owner.
47
+ *
48
+ * The generated `fetchMaybe*` and `fetchAllMaybe*` helpers apply this rule themselves. Apply it to
49
+ * accounts you fetch or receive another way (subscriptions, batch loaders, caches) before passing
50
+ * them to a `decode*` function, which throws for a lamports-only account: an account passed to it as
51
+ * existing must never come back as the non-existing variant typed as an `Account`.
52
+ *
53
+ * Only a `true` result narrows the type. A lamports-only account is still `exists: true` at runtime,
54
+ * so a `false` result leaves the type unchanged instead of narrowing it to the non-existing variant.
55
+ * The `uncreated` property in the narrowed type is never present; it exists only to prevent that.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const maybeAccount = decodeMyAccount(
60
+ * accountIsCreated(encodedAccount) ? encodedAccount : { address: encodedAccount.address, exists: false },
61
+ * );
62
+ * ```
63
+ */
64
+ function accountIsCreated$2(account) {
65
+ const maybeAccount = account;
66
+ if ("exists" in maybeAccount && !maybeAccount.exists) return false;
67
+ return !(maybeAccount.programAddress === SYSTEM_PROGRAM_ADDRESS$2 && maybeAccount.data.length === 0);
68
+ }
69
+ //#endregion
37
70
  //#region src/dex/generated/accounts/globalConfig.ts
38
71
  /**
39
72
  * This code was AUTOGENERATED using the Codama library.
@@ -101,21 +134,40 @@ function decodeGlobalConfig$2(encodedAccount) {
101
134
  }
102
135
  return decodeAccount(encodedAccount, getGlobalConfigDecoder$2());
103
136
  }
137
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
104
138
  async function fetchGlobalConfig$2(rpc, address, config) {
105
139
  const maybeAccount = await fetchMaybeGlobalConfig$2(rpc, address, config);
106
140
  assertAccountExists(maybeAccount);
107
141
  return maybeAccount;
108
142
  }
143
+ /**
144
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
145
+ * account or only lamports (see {@link accountIsCreated}).
146
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
147
+ */
109
148
  async function fetchMaybeGlobalConfig$2(rpc, address, config) {
110
- return decodeGlobalConfig$2(await fetchEncodedAccount(rpc, address, config));
149
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
150
+ return decodeGlobalConfig$2(accountIsCreated$2(maybeAccount) ? maybeAccount : {
151
+ address,
152
+ exists: false
153
+ });
111
154
  }
155
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
112
156
  async function fetchAllGlobalConfig$2(rpc, addresses, config) {
113
157
  const maybeAccounts = await fetchAllMaybeGlobalConfig$2(rpc, addresses, config);
114
158
  assertAccountsExist(maybeAccounts);
115
159
  return maybeAccounts;
116
160
  }
161
+ /**
162
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
163
+ * no account or only lamports (see {@link accountIsCreated}).
164
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
165
+ */
117
166
  async function fetchAllMaybeGlobalConfig$2(rpc, addresses, config) {
118
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$2(maybeAccount));
167
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$2(accountIsCreated$2(maybeAccount) ? maybeAccount : {
168
+ address: maybeAccount.address,
169
+ exists: false
170
+ }));
119
171
  }
120
172
  function getGlobalConfigSize$1() {
121
173
  return 139;
@@ -276,21 +328,40 @@ function decodePool(encodedAccount) {
276
328
  }
277
329
  return decodeAccount(encodedAccount, getPoolDecoder());
278
330
  }
331
+ /** Fetches a `Pool` account, throwing when it does not exist or only holds lamports. */
279
332
  async function fetchPool(rpc, address, config) {
280
333
  const maybeAccount = await fetchMaybePool(rpc, address, config);
281
334
  assertAccountExists(maybeAccount);
282
335
  return maybeAccount;
283
336
  }
337
+ /**
338
+ * Fetches a `Pool` account, or the non-existing variant when the address holds no
339
+ * account or only lamports (see {@link accountIsCreated}).
340
+ * {@link decodePool} throws for a lamports-only account instead.
341
+ */
284
342
  async function fetchMaybePool(rpc, address, config) {
285
- return decodePool(await fetchEncodedAccount(rpc, address, config));
343
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
344
+ return decodePool(accountIsCreated$2(maybeAccount) ? maybeAccount : {
345
+ address,
346
+ exists: false
347
+ });
286
348
  }
349
+ /** Fetches `Pool` accounts, throwing when any does not exist or only holds lamports. */
287
350
  async function fetchAllPool(rpc, addresses, config) {
288
351
  const maybeAccounts = await fetchAllMaybePool(rpc, addresses, config);
289
352
  assertAccountsExist(maybeAccounts);
290
353
  return maybeAccounts;
291
354
  }
355
+ /**
356
+ * Fetches `Pool` accounts, with the non-existing variant for each address that holds
357
+ * no account or only lamports (see {@link accountIsCreated}).
358
+ * {@link decodePool} throws for a lamports-only account instead.
359
+ */
292
360
  async function fetchAllMaybePool(rpc, addresses, config) {
293
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodePool(maybeAccount));
361
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodePool(accountIsCreated$2(maybeAccount) ? maybeAccount : {
362
+ address: maybeAccount.address,
363
+ exists: false
364
+ }));
294
365
  }
295
366
  function getPoolSize() {
296
367
  return 389;
@@ -363,21 +434,40 @@ function decodeRewardAccrual$1(encodedAccount) {
363
434
  }
364
435
  return decodeAccount(encodedAccount, getRewardAccrualDecoder$1());
365
436
  }
437
+ /** Fetches a `RewardAccrual` account, throwing when it does not exist or only holds lamports. */
366
438
  async function fetchRewardAccrual$1(rpc, address, config) {
367
439
  const maybeAccount = await fetchMaybeRewardAccrual$1(rpc, address, config);
368
440
  assertAccountExists(maybeAccount);
369
441
  return maybeAccount;
370
442
  }
443
+ /**
444
+ * Fetches a `RewardAccrual` account, or the non-existing variant when the address holds no
445
+ * account or only lamports (see {@link accountIsCreated}).
446
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
447
+ */
371
448
  async function fetchMaybeRewardAccrual$1(rpc, address, config) {
372
- return decodeRewardAccrual$1(await fetchEncodedAccount(rpc, address, config));
449
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
450
+ return decodeRewardAccrual$1(accountIsCreated$2(maybeAccount) ? maybeAccount : {
451
+ address,
452
+ exists: false
453
+ });
373
454
  }
455
+ /** Fetches `RewardAccrual` accounts, throwing when any does not exist or only holds lamports. */
374
456
  async function fetchAllRewardAccrual$1(rpc, addresses, config) {
375
457
  const maybeAccounts = await fetchAllMaybeRewardAccrual$1(rpc, addresses, config);
376
458
  assertAccountsExist(maybeAccounts);
377
459
  return maybeAccounts;
378
460
  }
461
+ /**
462
+ * Fetches `RewardAccrual` accounts, with the non-existing variant for each address that holds
463
+ * no account or only lamports (see {@link accountIsCreated}).
464
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
465
+ */
379
466
  async function fetchAllMaybeRewardAccrual$1(rpc, addresses, config) {
380
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual$1(maybeAccount));
467
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual$1(accountIsCreated$2(maybeAccount) ? maybeAccount : {
468
+ address: maybeAccount.address,
469
+ exists: false
470
+ }));
381
471
  }
382
472
  function getRewardAccrualSize$1() {
383
473
  return 130;
@@ -3437,12 +3527,11 @@ var amm_exports = /* @__PURE__ */ __exportAll({
3437
3527
  });
3438
3528
  const BPS_DIVISOR = 10000n;
3439
3529
  const U64_MAX = 18446744073709551615n;
3440
- /** Each call mirrors a `u64::try_from` in the Rust twin; drop one and an oversized leg fails in the encoder. */
3441
3530
  function assertU64(label, value) {
3442
3531
  if (value > U64_MAX) throw new RangeError(`${label}: overflows u64`);
3443
3532
  return value;
3444
3533
  }
3445
- /** No transfer lands exactly the requested amount; approximating one hands the program a bound it rejects. */
3534
+ /** Thrown when no transfer delivers exactly `amount` after the transfer fee. */
3446
3535
  var TransferFeeNotSettleableError = class extends RangeError {
3447
3536
  amount;
3448
3537
  mintFee;
@@ -3457,7 +3546,8 @@ function assertMintFee(fee) {
3457
3546
  assertBps("MintFee", "bps", fee.bps);
3458
3547
  if (fee.maximumFee < 0n || fee.maximumFee > U64_MAX) throw new RangeError("MintFee: maximumFee must fit a u64");
3459
3548
  }
3460
- /** Rounds up, then caps (SPL's order); swapping them lets a split booking over-credit. */
3549
+ /** Returns the transfer fee on `amount`. Rounds up, then caps at `maximumFee`, in SPL's order.
3550
+ * Returns 0 without `fee`. Throws `RangeError` if `fee` is out of range. */
3461
3551
  function feeOn(amount, fee) {
3462
3552
  if (fee === void 0) return 0n;
3463
3553
  assertMintFee(fee);
@@ -3465,11 +3555,11 @@ function feeOn(amount, fee) {
3465
3555
  const raw = ceilDiv(amount * BigInt(fee.bps), BPS_DIVISOR);
3466
3556
  return raw < fee.maximumFee ? raw : fee.maximumFee;
3467
3557
  }
3468
- /** What lands when `amount` is sent; use `grossUp` to land an exact amount. */
3558
+ /** Returns what the recipient receives when `amount` is sent. `grossUp` is the inverse. */
3469
3559
  function amountAfterFee(amount, fee) {
3470
3560
  return amount - feeOn(amount, fee);
3471
3561
  }
3472
- /** Line-for-line mirror of SPL's `TransferFee::calculate_pre_fee_amount`; `undefined` when no u64 answer exists. */
3562
+ /** Matches SPL `TransferFee::calculate_pre_fee_amount`. `undefined` if the result does not fit a u64. */
3473
3563
  function preFeeAmount(amount, fee) {
3474
3564
  const bps = BigInt(fee.bps);
3475
3565
  if (bps === 0n) return amount;
@@ -3485,7 +3575,8 @@ function preFeeAmount(amount, fee) {
3485
3575
  }
3486
3576
  return rawPreFee > U64_MAX ? void 0 : rawPreFee;
3487
3577
  }
3488
- /** What must be sent for exactly `amount` to land; throws {@link TransferFeeNotSettleableError} if none does. */
3578
+ /** Returns the amount to send so that exactly `amount` arrives. Returns `amount` without `fee`.
3579
+ * Throws {@link TransferFeeNotSettleableError} if no such amount exists. */
3489
3580
  function grossUp(amount, fee) {
3490
3581
  if (fee === void 0) return amount;
3491
3582
  assertMintFee(fee);
@@ -3508,7 +3599,8 @@ function sqrtBigInt(value) {
3508
3599
  }
3509
3600
  return x;
3510
3601
  }
3511
- /** Output rounds down (the new reserve rounds up), so `k` never shrinks. */
3602
+ /** Returns the constant-product output for `amountIn`, rounded down. Throws `RangeError` on a zero
3603
+ * reserve, a zero `amountIn`, a zero output, or an output past u64. */
3512
3604
  function calculateOutput(reserveIn, reserveOut, amountIn) {
3513
3605
  if (reserveIn === 0n || reserveOut === 0n) throw new RangeError("calculateOutput: insufficient liquidity");
3514
3606
  if (amountIn === 0n) throw new RangeError("calculateOutput: invalid amount");
@@ -3518,7 +3610,8 @@ function calculateOutput(reserveIn, reserveOut, amountIn) {
3518
3610
  if (amountOut === 0n) throw new RangeError("calculateOutput: insufficient liquidity");
3519
3611
  return assertU64("calculateOutput", amountOut);
3520
3612
  }
3521
- /** Required input rounds up so the user pays enough. */
3613
+ /** Returns the input needed for `amountOut`, rounded up. Throws `RangeError` on a zero reserve, a zero
3614
+ * `amountOut`, an `amountOut` not below `reserveOut`, or an input past u64. */
3522
3615
  function calculateInputForOutput(reserveIn, reserveOut, amountOut) {
3523
3616
  if (reserveIn === 0n || reserveOut === 0n) throw new RangeError("calculateInputForOutput: insufficient liquidity");
3524
3617
  if (amountOut === 0n || amountOut >= reserveOut) throw new RangeError("calculateInputForOutput: invalid amount");
@@ -3581,7 +3674,9 @@ function buyQuote(legs, quoteTransferFee, baseFee) {
3581
3674
  quoteFromUser: legs.quoteAmount
3582
3675
  };
3583
3676
  }
3584
- /** Guard with `calculateSlippageUp(quoteAmount, bps)`; it already carries the quote mint's cut. */
3677
+ /** Quotes a buy where the buyer receives `baseAmountOut`. With `baseReserveCap`, the vault sends at
3678
+ * most the cap. Guard with `calculateSlippageUp(quoteAmount, bps)`. `quoteAmount` includes the quote
3679
+ * mint's transfer fee. */
3585
3680
  function buyExactOut$2(params) {
3586
3681
  assertBps("buyExactOut", "feeBps", params.feeBps);
3587
3682
  if (params.baseAmountOut === 0n) throw new RangeError("buyExactOut: invalid amount");
@@ -3594,7 +3689,8 @@ function buyExactOut$2(params) {
3594
3689
  quoteAmount: quoteFromUser
3595
3690
  }, quoteFromUser - legs.quoteAmount, params.baseFee);
3596
3691
  }
3597
- /** Guard with `calculateSlippageDown(baseToUser, bps)`, not `baseAmount`: the program bounds what the buyer nets. */
3692
+ /** Quotes a buy that spends `quoteAmountIn`. Guard with `calculateSlippageDown(baseToUser, bps)`, not
3693
+ * `baseAmount`. The program checks the minimum against what the buyer receives. */
3598
3694
  function buyExactIn$2(params) {
3599
3695
  assertBps("buyExactIn", "feeBps", params.feeBps);
3600
3696
  if (params.quoteAmountIn === 0n) throw new RangeError("buyExactIn: invalid amount");
@@ -3613,7 +3709,7 @@ function buyExactIn$2(params) {
3613
3709
  quoteAmount: quoteFromUser
3614
3710
  }, quoteFromUser - capped.quoteAmount, params.baseFee);
3615
3711
  }
3616
- /** Guard with `calculateSlippageDown(quoteToUser, bps)`, not `quoteAmount`. */
3712
+ /** Quotes a sell of `baseAmountIn`. Guard with `calculateSlippageDown(quoteToUser, bps)`, not `quoteAmount`. */
3617
3713
  function sellExactIn$2(params) {
3618
3714
  assertBps("sellExactIn", "feeBps", params.feeBps);
3619
3715
  if (params.baseAmountIn === 0n) throw new RangeError("sellExactIn: invalid amount");
@@ -3631,7 +3727,8 @@ function sellExactIn$2(params) {
3631
3727
  quoteToUser: legs.quoteAmount - quoteTransferFee
3632
3728
  };
3633
3729
  }
3634
- /** Guard with `calculateSlippageUp(baseFromUser, bps)`, which already carries the base mint's cut. */
3730
+ /** Quotes a sell where the seller receives `quoteAmountOut`. Guard with
3731
+ * `calculateSlippageUp(baseFromUser, bps)`. `baseFromUser` includes the base mint's transfer fee. */
3635
3732
  function sellExactOut$2(params) {
3636
3733
  assertBps("sellExactOut", "feeBps", params.feeBps);
3637
3734
  if (params.quoteAmountOut === 0n) throw new RangeError("sellExactOut: invalid amount");
@@ -3656,17 +3753,17 @@ function calculateSlippageDown(amount, slippageBps) {
3656
3753
  assertBps("calculateSlippageDown", "slippageBps", slippageBps);
3657
3754
  return assertU64("calculateSlippageDown", floorDiv(amount * (BPS_DIVISOR - BigInt(slippageBps)), BPS_DIVISOR));
3658
3755
  }
3659
- /** Floors, as the program's `isqrt` does. */
3756
+ /** Returns `sqrt(quoteAmount * baseAmount)`, rounded down. */
3660
3757
  function calculateInitialLp(quoteAmount, baseAmount) {
3661
3758
  return sqrtBigInt(quoteAmount * baseAmount);
3662
3759
  }
3663
- /** Floating-point quote per base, for display only. */
3760
+ /** Returns the price of one base token in quote tokens, as a float. For display only. */
3664
3761
  function calculatePrice(params) {
3665
3762
  const { quoteReserves, baseReserves, quoteDecimals, baseDecimals } = params;
3666
3763
  if (baseReserves === 0n) return 0;
3667
3764
  return Number(quoteReserves) / Number(baseReserves) * 10 ** (baseDecimals - quoteDecimals);
3668
3765
  }
3669
- /** Market cap in raw quote-token units. */
3766
+ /** Returns the market cap in raw quote units. */
3670
3767
  function calculateMarketCap(params) {
3671
3768
  const { quoteReserves, baseReserves, baseSupply } = params;
3672
3769
  if (baseReserves === 0n) return 0n;
@@ -3684,7 +3781,7 @@ var trade_exports$1 = /* @__PURE__ */ __exportAll({
3684
3781
  sellExactIn: () => sellExactIn$1,
3685
3782
  sellExactOut: () => sellExactOut$1
3686
3783
  });
3687
- /** `baseAmountOut` is net to the buyer: the program reads `amount` as `base_to_user`. */
3784
+ /** `baseAmountOut` is the base the buyer receives, after the base mint's transfer fee. */
3688
3785
  async function buyExactOut$1(params) {
3689
3786
  const quote = buyExactOut$2({
3690
3787
  reserveQuote: params.quoteReserves,
@@ -3742,7 +3839,7 @@ async function sellExactIn$1(params) {
3742
3839
  quote
3743
3840
  };
3744
3841
  }
3745
- /** `quoteAmountOut` is net to the seller: the program reads `amount` as `quote_to_user`. */
3842
+ /** `quoteAmountOut` is the quote the seller receives, after the quote mint's transfer fee. */
3746
3843
  async function sellExactOut$1(params) {
3747
3844
  const quote = sellExactOut$2({
3748
3845
  reserveQuote: params.quoteReserves,
@@ -3816,6 +3913,39 @@ var dex_exports = /* @__PURE__ */ __exportAll({
3816
3913
  types: () => types_exports$2
3817
3914
  });
3818
3915
  //#endregion
3916
+ //#region src/launchpad/generated/shared/index.ts
3917
+ /** The System Program, which owns every address nobody has created an account at yet. */
3918
+ const SYSTEM_PROGRAM_ADDRESS$1 = "11111111111111111111111111111111";
3919
+ /**
3920
+ * Whether an encoded account was created on-chain, rather than merely sent lamports.
3921
+ *
3922
+ * Anyone can send lamports to an address before its account is created, which leaves it on-chain,
3923
+ * owned by the System Program, with no data. This returns `false` for that shape, as it does for an
3924
+ * account that does not exist. Any other existing account counts as created, whoever owns it; the
3925
+ * `decode*` functions still check the owner.
3926
+ *
3927
+ * The generated `fetchMaybe*` and `fetchAllMaybe*` helpers apply this rule themselves. Apply it to
3928
+ * accounts you fetch or receive another way (subscriptions, batch loaders, caches) before passing
3929
+ * them to a `decode*` function, which throws for a lamports-only account: an account passed to it as
3930
+ * existing must never come back as the non-existing variant typed as an `Account`.
3931
+ *
3932
+ * Only a `true` result narrows the type. A lamports-only account is still `exists: true` at runtime,
3933
+ * so a `false` result leaves the type unchanged instead of narrowing it to the non-existing variant.
3934
+ * The `uncreated` property in the narrowed type is never present; it exists only to prevent that.
3935
+ *
3936
+ * @example
3937
+ * ```ts
3938
+ * const maybeAccount = decodeMyAccount(
3939
+ * accountIsCreated(encodedAccount) ? encodedAccount : { address: encodedAccount.address, exists: false },
3940
+ * );
3941
+ * ```
3942
+ */
3943
+ function accountIsCreated$1(account) {
3944
+ const maybeAccount = account;
3945
+ if ("exists" in maybeAccount && !maybeAccount.exists) return false;
3946
+ return !(maybeAccount.programAddress === SYSTEM_PROGRAM_ADDRESS$1 && maybeAccount.data.length === 0);
3947
+ }
3948
+ //#endregion
3819
3949
  //#region src/launchpad/generated/types/bondingCurveStatus.ts
3820
3950
  /**
3821
3951
  * This code was AUTOGENERATED using the Codama library.
@@ -3981,21 +4111,40 @@ function decodeBondingCurve(encodedAccount) {
3981
4111
  }
3982
4112
  return decodeAccount(encodedAccount, getBondingCurveDecoder());
3983
4113
  }
4114
+ /** Fetches a `BondingCurve` account, throwing when it does not exist or only holds lamports. */
3984
4115
  async function fetchBondingCurve(rpc, address, config) {
3985
4116
  const maybeAccount = await fetchMaybeBondingCurve(rpc, address, config);
3986
4117
  assertAccountExists(maybeAccount);
3987
4118
  return maybeAccount;
3988
4119
  }
4120
+ /**
4121
+ * Fetches a `BondingCurve` account, or the non-existing variant when the address holds no
4122
+ * account or only lamports (see {@link accountIsCreated}).
4123
+ * {@link decodeBondingCurve} throws for a lamports-only account instead.
4124
+ */
3989
4125
  async function fetchMaybeBondingCurve(rpc, address, config) {
3990
- return decodeBondingCurve(await fetchEncodedAccount(rpc, address, config));
4126
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
4127
+ return decodeBondingCurve(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4128
+ address,
4129
+ exists: false
4130
+ });
3991
4131
  }
4132
+ /** Fetches `BondingCurve` accounts, throwing when any does not exist or only holds lamports. */
3992
4133
  async function fetchAllBondingCurve(rpc, addresses, config) {
3993
4134
  const maybeAccounts = await fetchAllMaybeBondingCurve(rpc, addresses, config);
3994
4135
  assertAccountsExist(maybeAccounts);
3995
4136
  return maybeAccounts;
3996
4137
  }
4138
+ /**
4139
+ * Fetches `BondingCurve` accounts, with the non-existing variant for each address that holds
4140
+ * no account or only lamports (see {@link accountIsCreated}).
4141
+ * {@link decodeBondingCurve} throws for a lamports-only account instead.
4142
+ */
3997
4143
  async function fetchAllMaybeBondingCurve(rpc, addresses, config) {
3998
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeBondingCurve(maybeAccount));
4144
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeBondingCurve(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4145
+ address: maybeAccount.address,
4146
+ exists: false
4147
+ }));
3999
4148
  }
4000
4149
  function getBondingCurveSize() {
4001
4150
  return 421;
@@ -4078,21 +4227,40 @@ function decodeGlobalConfig$1(encodedAccount) {
4078
4227
  }
4079
4228
  return decodeAccount(encodedAccount, getGlobalConfigDecoder$1());
4080
4229
  }
4230
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
4081
4231
  async function fetchGlobalConfig$1(rpc, address, config) {
4082
4232
  const maybeAccount = await fetchMaybeGlobalConfig$1(rpc, address, config);
4083
4233
  assertAccountExists(maybeAccount);
4084
4234
  return maybeAccount;
4085
4235
  }
4236
+ /**
4237
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
4238
+ * account or only lamports (see {@link accountIsCreated}).
4239
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
4240
+ */
4086
4241
  async function fetchMaybeGlobalConfig$1(rpc, address, config) {
4087
- return decodeGlobalConfig$1(await fetchEncodedAccount(rpc, address, config));
4242
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
4243
+ return decodeGlobalConfig$1(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4244
+ address,
4245
+ exists: false
4246
+ });
4088
4247
  }
4248
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
4089
4249
  async function fetchAllGlobalConfig$1(rpc, addresses, config) {
4090
4250
  const maybeAccounts = await fetchAllMaybeGlobalConfig$1(rpc, addresses, config);
4091
4251
  assertAccountsExist(maybeAccounts);
4092
4252
  return maybeAccounts;
4093
4253
  }
4254
+ /**
4255
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
4256
+ * no account or only lamports (see {@link accountIsCreated}).
4257
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
4258
+ */
4094
4259
  async function fetchAllMaybeGlobalConfig$1(rpc, addresses, config) {
4095
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$1(maybeAccount));
4260
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig$1(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4261
+ address: maybeAccount.address,
4262
+ exists: false
4263
+ }));
4096
4264
  }
4097
4265
  function getGlobalConfigSize() {
4098
4266
  return 179;
@@ -4165,21 +4333,40 @@ function decodeRewardAccrual(encodedAccount) {
4165
4333
  }
4166
4334
  return decodeAccount(encodedAccount, getRewardAccrualDecoder());
4167
4335
  }
4336
+ /** Fetches a `RewardAccrual` account, throwing when it does not exist or only holds lamports. */
4168
4337
  async function fetchRewardAccrual(rpc, address, config) {
4169
4338
  const maybeAccount = await fetchMaybeRewardAccrual(rpc, address, config);
4170
4339
  assertAccountExists(maybeAccount);
4171
4340
  return maybeAccount;
4172
4341
  }
4342
+ /**
4343
+ * Fetches a `RewardAccrual` account, or the non-existing variant when the address holds no
4344
+ * account or only lamports (see {@link accountIsCreated}).
4345
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
4346
+ */
4173
4347
  async function fetchMaybeRewardAccrual(rpc, address, config) {
4174
- return decodeRewardAccrual(await fetchEncodedAccount(rpc, address, config));
4348
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
4349
+ return decodeRewardAccrual(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4350
+ address,
4351
+ exists: false
4352
+ });
4175
4353
  }
4354
+ /** Fetches `RewardAccrual` accounts, throwing when any does not exist or only holds lamports. */
4176
4355
  async function fetchAllRewardAccrual(rpc, addresses, config) {
4177
4356
  const maybeAccounts = await fetchAllMaybeRewardAccrual(rpc, addresses, config);
4178
4357
  assertAccountsExist(maybeAccounts);
4179
4358
  return maybeAccounts;
4180
4359
  }
4360
+ /**
4361
+ * Fetches `RewardAccrual` accounts, with the non-existing variant for each address that holds
4362
+ * no account or only lamports (see {@link accountIsCreated}).
4363
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
4364
+ */
4181
4365
  async function fetchAllMaybeRewardAccrual(rpc, addresses, config) {
4182
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual(maybeAccount));
4366
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeRewardAccrual(accountIsCreated$1(maybeAccount) ? maybeAccount : {
4367
+ address: maybeAccount.address,
4368
+ exists: false
4369
+ }));
4183
4370
  }
4184
4371
  function getRewardAccrualSize() {
4185
4372
  return 130;
@@ -4503,7 +4690,8 @@ var pdas_exports$1 = /* @__PURE__ */ __exportAll({
4503
4690
  //#endregion
4504
4691
  //#region src/utils/creator-hash.ts
4505
4692
  const MAX_CREATOR_PLATFORM_LEN = 32;
4506
- /** SHA-256 of the LE-u32-length-prefixed platform and id. Frozen: it seeds live PDAs. */
4693
+ /** Returns the SHA-256 of `creatorPlatform` and `creatorId`, each prefixed with its byte length as a
4694
+ * little-endian u32. Throws `RangeError` if `creatorPlatform` is more than 32 bytes. */
4507
4695
  async function creatorHashFromId(creatorPlatform, creatorId) {
4508
4696
  const encoder = new TextEncoder();
4509
4697
  const platformBuf = encoder.encode(creatorPlatform);
@@ -4521,7 +4709,8 @@ async function creatorHashFromId(creatorPlatform, creatorId) {
4521
4709
  const hash = new Uint8Array(await crypto.subtle.digest("SHA-256", buf));
4522
4710
  return getAddressDecoder().decode(hash);
4523
4711
  }
4524
- /** NUL-pads `text` to `length` bytes, the on-chain `CreatorFeeConfig.platformId` form; throws RangeError if longer. */
4712
+ /** Pads `text` with NUL bytes to `length` bytes, the form of `CreatorFeeConfig.platformId`.
4713
+ * Throws `RangeError` if `text` is longer. */
4525
4714
  function encodeCreatorId(text, length) {
4526
4715
  const bytes = new TextEncoder().encode(text);
4527
4716
  if (bytes.length > length) throw new RangeError(`text exceeds ${length} bytes (got ${bytes.length})`);
@@ -4529,7 +4718,8 @@ function encodeCreatorId(text, length) {
4529
4718
  out.set(bytes, 0);
4530
4719
  return out;
4531
4720
  }
4532
- /** Strips NUL padding. Pass this, never the padded array, to {@link creatorHashFromId}: the hash is length-prefixed. */
4721
+ /** Removes the trailing NUL bytes and decodes the rest as UTF-8. Pass the result, not the padded
4722
+ * bytes, to {@link creatorHashFromId}. */
4533
4723
  function decodeCreatorId(bytes) {
4534
4724
  let end = bytes.length;
4535
4725
  while (end > 0 && bytes[end - 1] === 0) end -= 1;
@@ -6475,7 +6665,8 @@ var trade_exports = /* @__PURE__ */ __exportAll({
6475
6665
  sellExactIn: () => sellExactIn,
6476
6666
  sellExactOut: () => sellExactOut
6477
6667
  });
6478
- /** `baseAmountOut` is net to the buyer: the program reads `amount` as `base_to_user`. */
6668
+ /** `baseAmountOut` is the base the buyer receives, after the base mint's transfer fee.
6669
+ * The buy is capped at the curve's supply left. Read the result from `quote.baseToUser`. */
6479
6670
  async function buyExactOut(params) {
6480
6671
  const quote = buyExactOut$2({
6481
6672
  reserveQuote: params.virtualQuoteReserves,
@@ -6535,7 +6726,7 @@ async function sellExactIn(params) {
6535
6726
  quote
6536
6727
  };
6537
6728
  }
6538
- /** `quoteAmountOut` is net to the seller: the program reads `amount` as `quote_to_user`. */
6729
+ /** `quoteAmountOut` is the quote the seller receives, after the quote mint's transfer fee. */
6539
6730
  async function sellExactOut(params) {
6540
6731
  const quote = sellExactOut$2({
6541
6732
  reserveQuote: params.virtualQuoteReserves,
@@ -6583,7 +6774,7 @@ async function buildSellExactOutInstruction(params) {
6583
6774
  maxAmountIn: params.maxAmountIn
6584
6775
  });
6585
6776
  }
6586
- /** Percent of the curve's real base sold (0-100); 100 is the migration threshold. */
6777
+ /** Returns the percent of the curve's real base sold, from 0 to 100. At 100 the curve can migrate. */
6587
6778
  function calculateBondingCurveProgress(params) {
6588
6779
  const { realBaseReserves, initialRealBase } = params;
6589
6780
  if (initialRealBase === 0n) return 100;
@@ -8518,7 +8709,7 @@ var plugins_exports$1 = /* @__PURE__ */ __exportAll({ sendLaunchpadProgram: () =
8518
8709
  //#endregion
8519
8710
  //#region src/utils/pda.ts
8520
8711
  const addressEncoder = getAddressEncoder();
8521
- /** Seed order is [wallet, tokenProgram, mint], not the parameter order. */
8712
+ /** Derives the associated token account of `wallet` for `mint` under `tokenProgram`. */
8522
8713
  async function findAssociatedTokenPda(wallet, mint, tokenProgram = TOKEN_PROGRAM_ADDRESS) {
8523
8714
  return await getProgramDerivedAddress({
8524
8715
  programAddress: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
@@ -8574,7 +8765,8 @@ var launchpad_exports = /* @__PURE__ */ __exportAll({
8574
8765
  //#endregion
8575
8766
  //#region src/math/fee-decay.ts
8576
8767
  var fee_decay_exports = /* @__PURE__ */ __exportAll({ calculateFeeDecayPremium: () => calculateFeeDecayPremium });
8577
- /** Premium in bps, rounded up. */
8768
+ /** Returns the fee decay premium in bps, rounded up. The premium falls quadratically from
8769
+ * `decayStartBps - standardFeeBps` at creation to 0 after `decaySeconds`. */
8578
8770
  function calculateFeeDecayPremium(params) {
8579
8771
  const { currentTimestamp, createdAtTimestamp, decaySeconds, decayStartBps, standardFeeBps } = params;
8580
8772
  if (decaySeconds === 0) return 0n;
@@ -8595,7 +8787,9 @@ function calculateFeeDecayPremium(params) {
8595
8787
  //#endregion
8596
8788
  //#region src/math/fees.ts
8597
8789
  var fees_exports = /* @__PURE__ */ __exportAll({ splitFeeAmount: () => splitFeeAmount });
8598
- /** LP/creator round down; protocol absorbs the decay premium and all remainders. */
8790
+ /** Splits `feeAmount` into protocol, LP and creator shares. LP and creator round down. Protocol gets
8791
+ * the decay premium and all remainders. Throws `RangeError` on a negative or non-integer input,
8792
+ * a zero total bps, or `protocolBps + lpBps` above `baseTotalBps`. */
8599
8793
  function splitFeeAmount(args) {
8600
8794
  const { feeAmount } = args;
8601
8795
  const protocolBps = toBps(args.protocolBps, "protocolBps");
@@ -8641,6 +8835,39 @@ var math_exports = /* @__PURE__ */ __exportAll({
8641
8835
  fees: () => fees_exports
8642
8836
  });
8643
8837
  //#endregion
8838
+ //#region src/nexus/generated/shared/index.ts
8839
+ /** The System Program, which owns every address nobody has created an account at yet. */
8840
+ const SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
8841
+ /**
8842
+ * Whether an encoded account was created on-chain, rather than merely sent lamports.
8843
+ *
8844
+ * Anyone can send lamports to an address before its account is created, which leaves it on-chain,
8845
+ * owned by the System Program, with no data. This returns `false` for that shape, as it does for an
8846
+ * account that does not exist. Any other existing account counts as created, whoever owns it; the
8847
+ * `decode*` functions still check the owner.
8848
+ *
8849
+ * The generated `fetchMaybe*` and `fetchAllMaybe*` helpers apply this rule themselves. Apply it to
8850
+ * accounts you fetch or receive another way (subscriptions, batch loaders, caches) before passing
8851
+ * them to a `decode*` function, which throws for a lamports-only account: an account passed to it as
8852
+ * existing must never come back as the non-existing variant typed as an `Account`.
8853
+ *
8854
+ * Only a `true` result narrows the type. A lamports-only account is still `exists: true` at runtime,
8855
+ * so a `false` result leaves the type unchanged instead of narrowing it to the non-existing variant.
8856
+ * The `uncreated` property in the narrowed type is never present; it exists only to prevent that.
8857
+ *
8858
+ * @example
8859
+ * ```ts
8860
+ * const maybeAccount = decodeMyAccount(
8861
+ * accountIsCreated(encodedAccount) ? encodedAccount : { address: encodedAccount.address, exists: false },
8862
+ * );
8863
+ * ```
8864
+ */
8865
+ function accountIsCreated(account) {
8866
+ const maybeAccount = account;
8867
+ if ("exists" in maybeAccount && !maybeAccount.exists) return false;
8868
+ return !(maybeAccount.programAddress === SYSTEM_PROGRAM_ADDRESS && maybeAccount.data.length === 0);
8869
+ }
8870
+ //#endregion
8644
8871
  //#region src/nexus/generated/accounts/altRegistry.ts
8645
8872
  /**
8646
8873
  * This code was AUTOGENERATED using the Codama library.
@@ -8704,21 +8931,40 @@ function decodeAltRegistry(encodedAccount) {
8704
8931
  }
8705
8932
  return decodeAccount(encodedAccount, getAltRegistryDecoder());
8706
8933
  }
8934
+ /** Fetches a `AltRegistry` account, throwing when it does not exist or only holds lamports. */
8707
8935
  async function fetchAltRegistry(rpc, address, config) {
8708
8936
  const maybeAccount = await fetchMaybeAltRegistry(rpc, address, config);
8709
8937
  assertAccountExists(maybeAccount);
8710
8938
  return maybeAccount;
8711
8939
  }
8940
+ /**
8941
+ * Fetches a `AltRegistry` account, or the non-existing variant when the address holds no
8942
+ * account or only lamports (see {@link accountIsCreated}).
8943
+ * {@link decodeAltRegistry} throws for a lamports-only account instead.
8944
+ */
8712
8945
  async function fetchMaybeAltRegistry(rpc, address, config) {
8713
- return decodeAltRegistry(await fetchEncodedAccount(rpc, address, config));
8946
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
8947
+ return decodeAltRegistry(accountIsCreated(maybeAccount) ? maybeAccount : {
8948
+ address,
8949
+ exists: false
8950
+ });
8714
8951
  }
8952
+ /** Fetches `AltRegistry` accounts, throwing when any does not exist or only holds lamports. */
8715
8953
  async function fetchAllAltRegistry(rpc, addresses, config) {
8716
8954
  const maybeAccounts = await fetchAllMaybeAltRegistry(rpc, addresses, config);
8717
8955
  assertAccountsExist(maybeAccounts);
8718
8956
  return maybeAccounts;
8719
8957
  }
8958
+ /**
8959
+ * Fetches `AltRegistry` accounts, with the non-existing variant for each address that holds
8960
+ * no account or only lamports (see {@link accountIsCreated}).
8961
+ * {@link decodeAltRegistry} throws for a lamports-only account instead.
8962
+ */
8720
8963
  async function fetchAllMaybeAltRegistry(rpc, addresses, config) {
8721
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeAltRegistry(maybeAccount));
8964
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeAltRegistry(accountIsCreated(maybeAccount) ? maybeAccount : {
8965
+ address: maybeAccount.address,
8966
+ exists: false
8967
+ }));
8722
8968
  }
8723
8969
  function getAltRegistrySize() {
8724
8970
  return 74;
@@ -8791,21 +9037,40 @@ function decodeCreatorFeeConfig(encodedAccount) {
8791
9037
  }
8792
9038
  return decodeAccount(encodedAccount, getCreatorFeeConfigDecoder());
8793
9039
  }
9040
+ /** Fetches a `CreatorFeeConfig` account, throwing when it does not exist or only holds lamports. */
8794
9041
  async function fetchCreatorFeeConfig(rpc, address, config) {
8795
9042
  const maybeAccount = await fetchMaybeCreatorFeeConfig(rpc, address, config);
8796
9043
  assertAccountExists(maybeAccount);
8797
9044
  return maybeAccount;
8798
9045
  }
9046
+ /**
9047
+ * Fetches a `CreatorFeeConfig` account, or the non-existing variant when the address holds no
9048
+ * account or only lamports (see {@link accountIsCreated}).
9049
+ * {@link decodeCreatorFeeConfig} throws for a lamports-only account instead.
9050
+ */
8799
9051
  async function fetchMaybeCreatorFeeConfig(rpc, address, config) {
8800
- return decodeCreatorFeeConfig(await fetchEncodedAccount(rpc, address, config));
9052
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9053
+ return decodeCreatorFeeConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9054
+ address,
9055
+ exists: false
9056
+ });
8801
9057
  }
9058
+ /** Fetches `CreatorFeeConfig` accounts, throwing when any does not exist or only holds lamports. */
8802
9059
  async function fetchAllCreatorFeeConfig(rpc, addresses, config) {
8803
9060
  const maybeAccounts = await fetchAllMaybeCreatorFeeConfig(rpc, addresses, config);
8804
9061
  assertAccountsExist(maybeAccounts);
8805
9062
  return maybeAccounts;
8806
9063
  }
9064
+ /**
9065
+ * Fetches `CreatorFeeConfig` accounts, with the non-existing variant for each address that holds
9066
+ * no account or only lamports (see {@link accountIsCreated}).
9067
+ * {@link decodeCreatorFeeConfig} throws for a lamports-only account instead.
9068
+ */
8807
9069
  async function fetchAllMaybeCreatorFeeConfig(rpc, addresses, config) {
8808
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeCreatorFeeConfig(maybeAccount));
9070
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeCreatorFeeConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9071
+ address: maybeAccount.address,
9072
+ exists: false
9073
+ }));
8809
9074
  }
8810
9075
  function getCreatorFeeConfigSize() {
8811
9076
  return 151;
@@ -9033,21 +9298,40 @@ function decodeFeePreset(encodedAccount) {
9033
9298
  }
9034
9299
  return decodeAccount(encodedAccount, getFeePresetDecoder());
9035
9300
  }
9301
+ /** Fetches a `FeePreset` account, throwing when it does not exist or only holds lamports. */
9036
9302
  async function fetchFeePreset(rpc, address, config) {
9037
9303
  const maybeAccount = await fetchMaybeFeePreset(rpc, address, config);
9038
9304
  assertAccountExists(maybeAccount);
9039
9305
  return maybeAccount;
9040
9306
  }
9307
+ /**
9308
+ * Fetches a `FeePreset` account, or the non-existing variant when the address holds no
9309
+ * account or only lamports (see {@link accountIsCreated}).
9310
+ * {@link decodeFeePreset} throws for a lamports-only account instead.
9311
+ */
9041
9312
  async function fetchMaybeFeePreset(rpc, address, config) {
9042
- return decodeFeePreset(await fetchEncodedAccount(rpc, address, config));
9313
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9314
+ return decodeFeePreset(accountIsCreated(maybeAccount) ? maybeAccount : {
9315
+ address,
9316
+ exists: false
9317
+ });
9043
9318
  }
9319
+ /** Fetches `FeePreset` accounts, throwing when any does not exist or only holds lamports. */
9044
9320
  async function fetchAllFeePreset(rpc, addresses, config) {
9045
9321
  const maybeAccounts = await fetchAllMaybeFeePreset(rpc, addresses, config);
9046
9322
  assertAccountsExist(maybeAccounts);
9047
9323
  return maybeAccounts;
9048
9324
  }
9325
+ /**
9326
+ * Fetches `FeePreset` accounts, with the non-existing variant for each address that holds
9327
+ * no account or only lamports (see {@link accountIsCreated}).
9328
+ * {@link decodeFeePreset} throws for a lamports-only account instead.
9329
+ */
9049
9330
  async function fetchAllMaybeFeePreset(rpc, addresses, config) {
9050
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeFeePreset(maybeAccount));
9331
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeFeePreset(accountIsCreated(maybeAccount) ? maybeAccount : {
9332
+ address: maybeAccount.address,
9333
+ exists: false
9334
+ }));
9051
9335
  }
9052
9336
  //#endregion
9053
9337
  //#region src/nexus/generated/accounts/globalConfig.ts
@@ -9117,21 +9401,40 @@ function decodeGlobalConfig(encodedAccount) {
9117
9401
  }
9118
9402
  return decodeAccount(encodedAccount, getGlobalConfigDecoder());
9119
9403
  }
9404
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
9120
9405
  async function fetchGlobalConfig(rpc, address, config) {
9121
9406
  const maybeAccount = await fetchMaybeGlobalConfig(rpc, address, config);
9122
9407
  assertAccountExists(maybeAccount);
9123
9408
  return maybeAccount;
9124
9409
  }
9410
+ /**
9411
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
9412
+ * account or only lamports (see {@link accountIsCreated}).
9413
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
9414
+ */
9125
9415
  async function fetchMaybeGlobalConfig(rpc, address, config) {
9126
- return decodeGlobalConfig(await fetchEncodedAccount(rpc, address, config));
9416
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9417
+ return decodeGlobalConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9418
+ address,
9419
+ exists: false
9420
+ });
9127
9421
  }
9422
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
9128
9423
  async function fetchAllGlobalConfig(rpc, addresses, config) {
9129
9424
  const maybeAccounts = await fetchAllMaybeGlobalConfig(rpc, addresses, config);
9130
9425
  assertAccountsExist(maybeAccounts);
9131
9426
  return maybeAccounts;
9132
9427
  }
9428
+ /**
9429
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
9430
+ * no account or only lamports (see {@link accountIsCreated}).
9431
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
9432
+ */
9133
9433
  async function fetchAllMaybeGlobalConfig(rpc, addresses, config) {
9134
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig(maybeAccount));
9434
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeGlobalConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9435
+ address: maybeAccount.address,
9436
+ exists: false
9437
+ }));
9135
9438
  }
9136
9439
  //#endregion
9137
9440
  //#region src/nexus/generated/accounts/partnerConfig.ts
@@ -9207,21 +9510,40 @@ function decodePartnerConfig(encodedAccount) {
9207
9510
  }
9208
9511
  return decodeAccount(encodedAccount, getPartnerConfigDecoder());
9209
9512
  }
9513
+ /** Fetches a `PartnerConfig` account, throwing when it does not exist or only holds lamports. */
9210
9514
  async function fetchPartnerConfig(rpc, address, config) {
9211
9515
  const maybeAccount = await fetchMaybePartnerConfig(rpc, address, config);
9212
9516
  assertAccountExists(maybeAccount);
9213
9517
  return maybeAccount;
9214
9518
  }
9519
+ /**
9520
+ * Fetches a `PartnerConfig` account, or the non-existing variant when the address holds no
9521
+ * account or only lamports (see {@link accountIsCreated}).
9522
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
9523
+ */
9215
9524
  async function fetchMaybePartnerConfig(rpc, address, config) {
9216
- return decodePartnerConfig(await fetchEncodedAccount(rpc, address, config));
9525
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9526
+ return decodePartnerConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9527
+ address,
9528
+ exists: false
9529
+ });
9217
9530
  }
9531
+ /** Fetches `PartnerConfig` accounts, throwing when any does not exist or only holds lamports. */
9218
9532
  async function fetchAllPartnerConfig(rpc, addresses, config) {
9219
9533
  const maybeAccounts = await fetchAllMaybePartnerConfig(rpc, addresses, config);
9220
9534
  assertAccountsExist(maybeAccounts);
9221
9535
  return maybeAccounts;
9222
9536
  }
9537
+ /**
9538
+ * Fetches `PartnerConfig` accounts, with the non-existing variant for each address that holds
9539
+ * no account or only lamports (see {@link accountIsCreated}).
9540
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
9541
+ */
9223
9542
  async function fetchAllMaybePartnerConfig(rpc, addresses, config) {
9224
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodePartnerConfig(maybeAccount));
9543
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodePartnerConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9544
+ address: maybeAccount.address,
9545
+ exists: false
9546
+ }));
9225
9547
  }
9226
9548
  function getPartnerConfigSize() {
9227
9549
  return 173;
@@ -9300,21 +9622,40 @@ function decodePartnerMetadata(encodedAccount) {
9300
9622
  }
9301
9623
  return decodeAccount(encodedAccount, getPartnerMetadataDecoder());
9302
9624
  }
9625
+ /** Fetches a `PartnerMetadata` account, throwing when it does not exist or only holds lamports. */
9303
9626
  async function fetchPartnerMetadata(rpc, address, config) {
9304
9627
  const maybeAccount = await fetchMaybePartnerMetadata(rpc, address, config);
9305
9628
  assertAccountExists(maybeAccount);
9306
9629
  return maybeAccount;
9307
9630
  }
9631
+ /**
9632
+ * Fetches a `PartnerMetadata` account, or the non-existing variant when the address holds no
9633
+ * account or only lamports (see {@link accountIsCreated}).
9634
+ * {@link decodePartnerMetadata} throws for a lamports-only account instead.
9635
+ */
9308
9636
  async function fetchMaybePartnerMetadata(rpc, address, config) {
9309
- return decodePartnerMetadata(await fetchEncodedAccount(rpc, address, config));
9637
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9638
+ return decodePartnerMetadata(accountIsCreated(maybeAccount) ? maybeAccount : {
9639
+ address,
9640
+ exists: false
9641
+ });
9310
9642
  }
9643
+ /** Fetches `PartnerMetadata` accounts, throwing when any does not exist or only holds lamports. */
9311
9644
  async function fetchAllPartnerMetadata(rpc, addresses, config) {
9312
9645
  const maybeAccounts = await fetchAllMaybePartnerMetadata(rpc, addresses, config);
9313
9646
  assertAccountsExist(maybeAccounts);
9314
9647
  return maybeAccounts;
9315
9648
  }
9649
+ /**
9650
+ * Fetches `PartnerMetadata` accounts, with the non-existing variant for each address that holds
9651
+ * no account or only lamports (see {@link accountIsCreated}).
9652
+ * {@link decodePartnerMetadata} throws for a lamports-only account instead.
9653
+ */
9316
9654
  async function fetchAllMaybePartnerMetadata(rpc, addresses, config) {
9317
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodePartnerMetadata(maybeAccount));
9655
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodePartnerMetadata(accountIsCreated(maybeAccount) ? maybeAccount : {
9656
+ address: maybeAccount.address,
9657
+ exists: false
9658
+ }));
9318
9659
  }
9319
9660
  //#endregion
9320
9661
  //#region src/nexus/generated/accounts/rewardState.ts
@@ -9394,21 +9735,40 @@ function decodeRewardState(encodedAccount) {
9394
9735
  }
9395
9736
  return decodeAccount(encodedAccount, getRewardStateDecoder());
9396
9737
  }
9738
+ /** Fetches a `RewardState` account, throwing when it does not exist or only holds lamports. */
9397
9739
  async function fetchRewardState(rpc, address, config) {
9398
9740
  const maybeAccount = await fetchMaybeRewardState(rpc, address, config);
9399
9741
  assertAccountExists(maybeAccount);
9400
9742
  return maybeAccount;
9401
9743
  }
9744
+ /**
9745
+ * Fetches a `RewardState` account, or the non-existing variant when the address holds no
9746
+ * account or only lamports (see {@link accountIsCreated}).
9747
+ * {@link decodeRewardState} throws for a lamports-only account instead.
9748
+ */
9402
9749
  async function fetchMaybeRewardState(rpc, address, config) {
9403
- return decodeRewardState(await fetchEncodedAccount(rpc, address, config));
9750
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9751
+ return decodeRewardState(accountIsCreated(maybeAccount) ? maybeAccount : {
9752
+ address,
9753
+ exists: false
9754
+ });
9404
9755
  }
9756
+ /** Fetches `RewardState` accounts, throwing when any does not exist or only holds lamports. */
9405
9757
  async function fetchAllRewardState(rpc, addresses, config) {
9406
9758
  const maybeAccounts = await fetchAllMaybeRewardState(rpc, addresses, config);
9407
9759
  assertAccountsExist(maybeAccounts);
9408
9760
  return maybeAccounts;
9409
9761
  }
9762
+ /**
9763
+ * Fetches `RewardState` accounts, with the non-existing variant for each address that holds
9764
+ * no account or only lamports (see {@link accountIsCreated}).
9765
+ * {@link decodeRewardState} throws for a lamports-only account instead.
9766
+ */
9410
9767
  async function fetchAllMaybeRewardState(rpc, addresses, config) {
9411
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeRewardState(maybeAccount));
9768
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeRewardState(accountIsCreated(maybeAccount) ? maybeAccount : {
9769
+ address: maybeAccount.address,
9770
+ exists: false
9771
+ }));
9412
9772
  }
9413
9773
  function getRewardStateSize() {
9414
9774
  return 196;
@@ -9483,21 +9843,40 @@ function decodeStakingConfig(encodedAccount) {
9483
9843
  }
9484
9844
  return decodeAccount(encodedAccount, getStakingConfigDecoder());
9485
9845
  }
9846
+ /** Fetches a `StakingConfig` account, throwing when it does not exist or only holds lamports. */
9486
9847
  async function fetchStakingConfig(rpc, address, config) {
9487
9848
  const maybeAccount = await fetchMaybeStakingConfig(rpc, address, config);
9488
9849
  assertAccountExists(maybeAccount);
9489
9850
  return maybeAccount;
9490
9851
  }
9852
+ /**
9853
+ * Fetches a `StakingConfig` account, or the non-existing variant when the address holds no
9854
+ * account or only lamports (see {@link accountIsCreated}).
9855
+ * {@link decodeStakingConfig} throws for a lamports-only account instead.
9856
+ */
9491
9857
  async function fetchMaybeStakingConfig(rpc, address, config) {
9492
- return decodeStakingConfig(await fetchEncodedAccount(rpc, address, config));
9858
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9859
+ return decodeStakingConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9860
+ address,
9861
+ exists: false
9862
+ });
9493
9863
  }
9864
+ /** Fetches `StakingConfig` accounts, throwing when any does not exist or only holds lamports. */
9494
9865
  async function fetchAllStakingConfig(rpc, addresses, config) {
9495
9866
  const maybeAccounts = await fetchAllMaybeStakingConfig(rpc, addresses, config);
9496
9867
  assertAccountsExist(maybeAccounts);
9497
9868
  return maybeAccounts;
9498
9869
  }
9870
+ /**
9871
+ * Fetches `StakingConfig` accounts, with the non-existing variant for each address that holds
9872
+ * no account or only lamports (see {@link accountIsCreated}).
9873
+ * {@link decodeStakingConfig} throws for a lamports-only account instead.
9874
+ */
9499
9875
  async function fetchAllMaybeStakingConfig(rpc, addresses, config) {
9500
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeStakingConfig(maybeAccount));
9876
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeStakingConfig(accountIsCreated(maybeAccount) ? maybeAccount : {
9877
+ address: maybeAccount.address,
9878
+ exists: false
9879
+ }));
9501
9880
  }
9502
9881
  function getStakingConfigSize() {
9503
9882
  return 117;
@@ -9580,21 +9959,40 @@ function decodeUserRewardDebt(encodedAccount) {
9580
9959
  }
9581
9960
  return decodeAccount(encodedAccount, getUserRewardDebtDecoder());
9582
9961
  }
9962
+ /** Fetches a `UserRewardDebt` account, throwing when it does not exist or only holds lamports. */
9583
9963
  async function fetchUserRewardDebt(rpc, address, config) {
9584
9964
  const maybeAccount = await fetchMaybeUserRewardDebt(rpc, address, config);
9585
9965
  assertAccountExists(maybeAccount);
9586
9966
  return maybeAccount;
9587
9967
  }
9968
+ /**
9969
+ * Fetches a `UserRewardDebt` account, or the non-existing variant when the address holds no
9970
+ * account or only lamports (see {@link accountIsCreated}).
9971
+ * {@link decodeUserRewardDebt} throws for a lamports-only account instead.
9972
+ */
9588
9973
  async function fetchMaybeUserRewardDebt(rpc, address, config) {
9589
- return decodeUserRewardDebt(await fetchEncodedAccount(rpc, address, config));
9974
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
9975
+ return decodeUserRewardDebt(accountIsCreated(maybeAccount) ? maybeAccount : {
9976
+ address,
9977
+ exists: false
9978
+ });
9590
9979
  }
9980
+ /** Fetches `UserRewardDebt` accounts, throwing when any does not exist or only holds lamports. */
9591
9981
  async function fetchAllUserRewardDebt(rpc, addresses, config) {
9592
9982
  const maybeAccounts = await fetchAllMaybeUserRewardDebt(rpc, addresses, config);
9593
9983
  assertAccountsExist(maybeAccounts);
9594
9984
  return maybeAccounts;
9595
9985
  }
9986
+ /**
9987
+ * Fetches `UserRewardDebt` accounts, with the non-existing variant for each address that holds
9988
+ * no account or only lamports (see {@link accountIsCreated}).
9989
+ * {@link decodeUserRewardDebt} throws for a lamports-only account instead.
9990
+ */
9596
9991
  async function fetchAllMaybeUserRewardDebt(rpc, addresses, config) {
9597
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeUserRewardDebt(maybeAccount));
9992
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeUserRewardDebt(accountIsCreated(maybeAccount) ? maybeAccount : {
9993
+ address: maybeAccount.address,
9994
+ exists: false
9995
+ }));
9598
9996
  }
9599
9997
  function getUserRewardDebtSize() {
9600
9998
  return 182;
@@ -9671,21 +10069,40 @@ function decodeUserStakePosition(encodedAccount) {
9671
10069
  }
9672
10070
  return decodeAccount(encodedAccount, getUserStakePositionDecoder());
9673
10071
  }
10072
+ /** Fetches a `UserStakePosition` account, throwing when it does not exist or only holds lamports. */
9674
10073
  async function fetchUserStakePosition(rpc, address, config) {
9675
10074
  const maybeAccount = await fetchMaybeUserStakePosition(rpc, address, config);
9676
10075
  assertAccountExists(maybeAccount);
9677
10076
  return maybeAccount;
9678
10077
  }
10078
+ /**
10079
+ * Fetches a `UserStakePosition` account, or the non-existing variant when the address holds no
10080
+ * account or only lamports (see {@link accountIsCreated}).
10081
+ * {@link decodeUserStakePosition} throws for a lamports-only account instead.
10082
+ */
9679
10083
  async function fetchMaybeUserStakePosition(rpc, address, config) {
9680
- return decodeUserStakePosition(await fetchEncodedAccount(rpc, address, config));
10084
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
10085
+ return decodeUserStakePosition(accountIsCreated(maybeAccount) ? maybeAccount : {
10086
+ address,
10087
+ exists: false
10088
+ });
9681
10089
  }
10090
+ /** Fetches `UserStakePosition` accounts, throwing when any does not exist or only holds lamports. */
9682
10091
  async function fetchAllUserStakePosition(rpc, addresses, config) {
9683
10092
  const maybeAccounts = await fetchAllMaybeUserStakePosition(rpc, addresses, config);
9684
10093
  assertAccountsExist(maybeAccounts);
9685
10094
  return maybeAccounts;
9686
10095
  }
10096
+ /**
10097
+ * Fetches `UserStakePosition` accounts, with the non-existing variant for each address that holds
10098
+ * no account or only lamports (see {@link accountIsCreated}).
10099
+ * {@link decodeUserStakePosition} throws for a lamports-only account instead.
10100
+ */
9687
10101
  async function fetchAllMaybeUserStakePosition(rpc, addresses, config) {
9688
- return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeUserStakePosition(maybeAccount));
10102
+ return (await fetchEncodedAccounts(rpc, addresses, config)).map((maybeAccount) => decodeUserStakePosition(accountIsCreated(maybeAccount) ? maybeAccount : {
10103
+ address: maybeAccount.address,
10104
+ exists: false
10105
+ }));
9689
10106
  }
9690
10107
  function getUserStakePositionSize() {
9691
10108
  return 120;
@@ -12261,7 +12678,8 @@ var fee_helpers_exports = /* @__PURE__ */ __exportAll({
12261
12678
  effectiveFeeBps: () => effectiveFeeBps,
12262
12679
  fetchPartnerFees: () => fetchPartnerFees
12263
12680
  });
12264
- /** Throws if the pair is unregistered. Take `platformConfig` from the market being priced: a partner's fees differ per platform. */
12681
+ /** Fetches the `PartnerConfig` of `partner` on `platformConfig`. Throws if it does not exist.
12682
+ * Use the `platformConfig` of the market you price. A partner's fees differ per platform. */
12265
12683
  async function fetchPartnerFees(rpc, partner, platformConfig) {
12266
12684
  const [partnerPda] = await findPartnerConfigPda({
12267
12685
  partner,
@@ -12271,8 +12689,9 @@ async function fetchPartnerFees(rpc, partner, platformConfig) {
12271
12689
  if (!maybeAccount.exists) throw new Error(`No fee config for partner ${partner} on platform ${platformConfig}`);
12272
12690
  return maybeAccount.data;
12273
12691
  }
12274
- /** The `feeBps` a trade pays: the standard rate plus the decay premium from the market's
12275
- * `createdAt`. Pass `fees.launchpad` for a curve, `fees.dex` for a pool; times in unix seconds. */
12692
+ /** Returns the `feeBps` a trade pays: the standard rate plus the decay premium. `schedule` is the
12693
+ * `PartnerConfig`'s `launchpad` for a curve or `dex` for a pool. `createdAt` is the curve's or
12694
+ * pool's `createdAt`. Both times are in unix seconds. */
12276
12695
  function effectiveFeeBps(schedule, createdAt, now) {
12277
12696
  const standardFeeBps = schedule.protocolFeeBps + schedule.creatorFeeBps + ("lpFeeBps" in schedule ? schedule.lpFeeBps : 0);
12278
12697
  const premium = calculateFeeDecayPremium({
@@ -12288,7 +12707,7 @@ function effectiveFeeBps(schedule, createdAt, now) {
12288
12707
  //#region src/utils/chunk.ts
12289
12708
  /** RPCs reject a `getMultipleAccounts` call past this many addresses. */
12290
12709
  const MAX_ACCOUNTS_PER_REQUEST = 100;
12291
- /** Splits a multi-account read into 100-address calls; results follow `addresses` order. */
12710
+ /** Calls `read` once per 100 addresses. Results follow `addresses` order. */
12292
12711
  async function fetchInChunks(addresses, read) {
12293
12712
  const chunks = [];
12294
12713
  for (let start = 0; start < addresses.length; start += MAX_ACCOUNTS_PER_REQUEST) chunks.push(addresses.slice(start, start + MAX_ACCOUNTS_PER_REQUEST));
@@ -12323,9 +12742,8 @@ function compareAddresses(a, b) {
12323
12742
  if (a > b) return 1;
12324
12743
  return 0;
12325
12744
  }
12326
- /** Registered reward mints, sorted by address. Includes disabled mints: their accrued balance is
12327
- * still owed and the settle gate still counts them. Throws when the sweep disagrees with
12328
- * `StakingConfig.rewardCount` rather than settle a short list. */
12745
+ /** Returns every registered reward mint, disabled mints included, sorted by address.
12746
+ * Throws if the count differs from `StakingConfig.rewardCount`. */
12329
12747
  async function getRewardMints(rpc) {
12330
12748
  const [stakingConfig] = findStakingConfigPda();
12331
12749
  const [accounts, config] = await Promise.all([rpc.getProgramAccounts(SEND_NEXUS_PROGRAM_ADDRESS, {
@@ -12355,7 +12773,8 @@ async function resolveRewardMints(rpc, rewardMints) {
12355
12773
  if (!hasProgramAccounts(rpc)) throw new Error("This RPC has no getProgramAccounts, so the reward registry cannot be read from chain. Pass rewardMints explicitly.");
12356
12774
  return await getRewardMints(rpc);
12357
12775
  }
12358
- /** One idempotent `settle` per mint; a partial mint list leaves `stake` and `unstake` failing `RewardsNotSettled`. */
12776
+ /** Builds one `settle` per reward mint. `source` is the mint list, or an RPC to read it from.
12777
+ * `settle` is idempotent. With a partial list, `stake` and `unstake` fail with `RewardsNotSettled`. */
12359
12778
  async function buildSettleInstructions(source, params) {
12360
12779
  const rewardMints = isRewardMintList(source) ? source : await resolveRewardMints(source, void 0);
12361
12780
  return Promise.all(rewardMints.map((rewardMint) => getSettleInstructionAsync({
@@ -12376,10 +12795,11 @@ async function fetchMissingUserRewardDebts(rpc, user, stakingMint, knownRewardMi
12376
12795
  return addr;
12377
12796
  })), (chunk) => fetchEncodedAccounts(rpc, chunk));
12378
12797
  const missingMints = [];
12379
- for (const [index, rewardMint] of rewardMints.entries()) if (!encodedAccounts[index].exists) missingMints.push(rewardMint);
12798
+ for (const [index, rewardMint] of rewardMints.entries()) if (!accountIsCreated(encodedAccounts[index])) missingMints.push(rewardMint);
12380
12799
  return missingMints;
12381
12800
  }
12382
- /** Opens missing `UserRewardDebt`s, then settles every mint; the user never signs, so the stake or unstake after is one wallet prompt. */
12801
+ /** Builds a `create_user_reward_debt` for each missing `UserRewardDebt`, then a `settle` for every
12802
+ * reward mint. The user does not sign these instructions. */
12383
12803
  async function buildStakingPreflightInstructions(rpc, params) {
12384
12804
  const rewardMints = await resolveRewardMints(rpc, params.rewardMints);
12385
12805
  const missingMints = await fetchMissingUserRewardDebts(rpc, params.user, params.stakingMint, rewardMints);
@@ -12392,13 +12812,14 @@ async function buildStakingPreflightInstructions(rpc, params) {
12392
12812
  const settleIxs = await buildSettleInstructions(rewardMints, params);
12393
12813
  return [...createIxs, ...settleIxs];
12394
12814
  }
12395
- /** True once `stake` and `unstake` will pass the `settledCount == rewardCount` gate. */
12815
+ /** Returns true if `stake` and `unstake` pass the `settledCount == rewardCount` check. */
12396
12816
  async function isFullySettled(rpc, user, stakingMint) {
12397
12817
  const [config, position] = await Promise.all([fetchStakingConfigData(rpc), fetchUserStakePositionData(rpc, user, stakingMint)]);
12398
12818
  if (position === null) return config.rewardCount === 0;
12399
12819
  return position.settledCount === config.rewardCount;
12400
12820
  }
12401
- /** Fails `RewardsNotSettled` until every mint is settled at the current `stakeVersion`; run `buildStakingPreflightInstructions` first. */
12821
+ /** The instruction fails with `RewardsNotSettled` until every mint is settled at the current
12822
+ * `stakeVersion`. Run `buildStakingPreflightInstructions` first. */
12402
12823
  async function buildStakeInstruction(params) {
12403
12824
  return getStakeInstructionAsync({
12404
12825
  user: params.user,
@@ -12407,8 +12828,9 @@ async function buildStakeInstruction(params) {
12407
12828
  amount: params.amount
12408
12829
  });
12409
12830
  }
12410
- /** Settle immediately before via `buildStakingPreflightInstructions`: the gate passes on a stale settle,
12411
- * and the window since it is then paid at the post-unstake amount, forfeiting accrual. */
12831
+ /** Run `buildStakingPreflightInstructions` immediately before. The check also passes on an older
12832
+ * settle. Rewards since that settle then accrue on the smaller post-unstake amount, and the
12833
+ * difference is lost. */
12412
12834
  async function buildUnstakeInstruction(params) {
12413
12835
  return getUnstakeInstructionAsync({
12414
12836
  user: params.user,
@@ -12417,8 +12839,8 @@ async function buildUnstakeInstruction(params) {
12417
12839
  amount: params.amount
12418
12840
  });
12419
12841
  }
12420
- /** One `claim` per mint, preceded by `create_user_reward_debt` where the debt is missing:
12421
- * `Claim` requires the account to exist, so one missing debt fails the whole transaction. */
12842
+ /** Builds one `claim` per reward mint. A `create_user_reward_debt` comes before each `claim` whose
12843
+ * `UserRewardDebt` is missing: `claim` fails without it. Throws if a mint has no `RewardState`. */
12422
12844
  async function buildClaimRewardsInstructions(rpc, params) {
12423
12845
  const [stakingConfigAddr] = findStakingConfigPda();
12424
12846
  const rewardMints = await resolveRewardMints(rpc, params.rewardMints);
@@ -12446,13 +12868,13 @@ async function buildClaimRewardsInstructions(rpc, params) {
12446
12868
  const payer = params.payer ?? params.user;
12447
12869
  return (await Promise.all(rewardMints.map(async (rewardMint, index) => {
12448
12870
  const encodedRewardState = fetched[index];
12449
- if (!encodedRewardState.exists) throw new Error(`RewardState not found for mint ${rewardMint}`);
12871
+ if (!accountIsCreated(encodedRewardState)) throw new Error(`RewardState not found for mint ${rewardMint}`);
12450
12872
  const { vault } = rewardStateDecoder.decode(encodedRewardState.data);
12451
12873
  const encodedMint = fetched[rewardMints.length + index];
12452
12874
  const tokenProgram = encodedMint.exists ? encodedMint.programAddress : void 0;
12453
12875
  const [destination] = await findAssociatedTokenPda(params.user.address, rewardMint, tokenProgram);
12454
12876
  const instructions = [];
12455
- if (!fetched[rewardMints.length * 2 + index].exists) instructions.push(await getCreateUserRewardDebtInstructionAsync({
12877
+ if (!accountIsCreated(fetched[rewardMints.length * 2 + index])) instructions.push(await getCreateUserRewardDebtInstructionAsync({
12456
12878
  user: params.user.address,
12457
12879
  payer,
12458
12880
  stakingMint: params.stakingMint,
@@ -12470,7 +12892,8 @@ async function buildClaimRewardsInstructions(rpc, params) {
12470
12892
  return instructions;
12471
12893
  }))).flat();
12472
12894
  }
12473
- /** Accounts for one mint's `withdraw_fees`; call once per mint. */
12895
+ /** Returns the accounts of `withdraw_fees` for one reward mint. Without `tokenProgram`, reads it
12896
+ * from the mint account. Throws if that account does not exist. */
12474
12897
  async function buildWithdrawFeesAccounts(rpc, params) {
12475
12898
  const [stakingConfigAddr] = findStakingConfigPda();
12476
12899
  const tokenProgram = params.tokenProgram ?? (await rpc.getAccountInfo(params.rewardMint, { encoding: "base64" }).send()).value?.owner;
@@ -12503,19 +12926,19 @@ async function fetchUserStakePositionData(rpc, user, stakingMint) {
12503
12926
  const maybePosition = await fetchMaybeUserStakePosition(rpc, positionAddr);
12504
12927
  return maybePosition.exists ? maybePosition.data : null;
12505
12928
  }
12506
- /** Unbound reads as `Pubkey::default()` (the system program address), which `bind_staking_mint`
12507
- * can never store: it requires a token mint. */
12929
+ /** Returns false for the system program address, the value of an unbound staking mint. */
12508
12930
  function isStakingMintBound(stakingMint) {
12509
- return stakingMint !== SYSTEM_PROGRAM_ADDRESS;
12931
+ return stakingMint !== SYSTEM_PROGRAM_ADDRESS$3;
12510
12932
  }
12511
- /** The staking mint is immutable once bound, so this result is safe to cache. */
12933
+ /** Returns the staking mint. Throws if no staking mint is bound. A bound staking mint cannot change. */
12512
12934
  async function fetchSendMint(rpc) {
12513
12935
  const { stakingMint } = await fetchStakingConfigData(rpc);
12514
12936
  if (!isStakingMintBound(stakingMint)) throw new Error("Staking mint not yet bound -- nexus not fully initialized");
12515
12937
  return stakingMint;
12516
12938
  }
12517
- /** One entry per reward mint, in `knownRewardMints` order, else sorted by address. Each amount is in
12518
- * its own mint's base units, so never sum them, and is the vault's debit, not the claimant's credit. */
12939
+ /** Returns one entry per reward mint, in `knownRewardMints` order, else sorted by address. Each amount
12940
+ * is in the raw units of its own mint. Do not add them together. Each amount is what the vault sends,
12941
+ * before the mint's transfer fee. */
12519
12942
  async function fetchPendingRewards(rpc, user, stakingMint, knownRewardMints) {
12520
12943
  const rewardMints = await resolveRewardMints(rpc, knownRewardMints);
12521
12944
  if (rewardMints.length === 0) return [];
@@ -12556,15 +12979,15 @@ async function fetchPendingRewards(rpc, user, stakingMint, knownRewardMints) {
12556
12979
  return pdas.map(({ rewardMint }, index) => {
12557
12980
  const base = index * 3;
12558
12981
  const encodedDebt = encodedAccounts[base];
12559
- const debt = encodedDebt.exists ? userRewardDebtDecoder.decode(encodedDebt.data) : {
12982
+ const debt = accountIsCreated(encodedDebt) ? userRewardDebtDecoder.decode(encodedDebt.data) : {
12560
12983
  owed: 0n,
12561
12984
  accSnapshot: 0n,
12562
12985
  amountSnapshot: stakeAmount
12563
12986
  };
12564
12987
  const encodedLaunchpadAccrual = encodedAccounts[base + 1];
12565
- const launchpadAcc = encodedLaunchpadAccrual.exists ? rewardAccrualDecoder.decode(encodedLaunchpadAccrual.data).accPerToken : 0n;
12988
+ const launchpadAcc = accountIsCreated(encodedLaunchpadAccrual) ? rewardAccrualDecoder.decode(encodedLaunchpadAccrual.data).accPerToken : 0n;
12566
12989
  const encodedDexAccrual = encodedAccounts[base + 2];
12567
- const dexAcc = encodedDexAccrual.exists ? rewardAccrualDecoder.decode(encodedDexAccrual.data).accPerToken : 0n;
12990
+ const dexAcc = accountIsCreated(encodedDexAccrual) ? rewardAccrualDecoder.decode(encodedDexAccrual.data).accPerToken : 0n;
12568
12991
  const basis = debt.amountSnapshot < stakeAmount ? debt.amountSnapshot : stakeAmount;
12569
12992
  const combined = launchpadAcc + dexAcc;
12570
12993
  const accrued = basis * (combined > debt.accSnapshot ? combined - debt.accSnapshot : 0n) / PRECISION;
@@ -12593,9 +13016,9 @@ var platform_exports = /* @__PURE__ */ __exportAll({
12593
13016
  PLATFORM_SEED: () => PLATFORM_SEED,
12594
13017
  findPlatformAddress: () => findPlatformAddress
12595
13018
  });
12596
- /** A platform is only a key, with no on-chain account; it is a PDA so a platform account can later `init` at it. */
13019
+ /** Seed of the platform PDA. A platform has no on-chain account. */
12597
13020
  const PLATFORM_SEED = "platform";
12598
- /** The name is the platform's identity: renaming one orphans every market and partner config under the old key. */
13021
+ /** Derives the platform key for `name` under the nexus program. Each name gives a different platform. */
12599
13022
  async function findPlatformAddress(name) {
12600
13023
  return await getProgramDerivedAddress({
12601
13024
  programAddress: SEND_NEXUS_PROGRAM_ADDRESS,
@@ -12637,8 +13060,9 @@ function readEntry(view, start) {
12637
13060
  basisPoints: view.getUint16(start + FEE_BASIS_POINTS, true)
12638
13061
  };
12639
13062
  }
12640
- /** `owner` is the account's program. `undefined` means no fee extension; anything
12641
- * unparseable throws `RangeError` rather than pricing a charging mint free. */
13063
+ /** Decodes the `TransferFeeConfig` extension of a mint. `owner` is the program that owns the account.
13064
+ * Returns `undefined` if the mint has no such extension. Throws `RangeError` if `owner` is not a
13065
+ * token program or `data` is not a valid mint. */
12642
13066
  function decodeTransferFeeConfig(data, owner) {
12643
13067
  if (owner === TOKEN_PROGRAM_ADDRESS) return void 0;
12644
13068
  if (owner !== TOKEN_2022_PROGRAM_ADDRESS) throw new RangeError(`decodeTransferFeeConfig: ${owner} is not a token program`);
@@ -12667,7 +13091,7 @@ function decodeTransferFeeConfig(data, owner) {
12667
13091
  offset = next;
12668
13092
  }
12669
13093
  }
12670
- /** Mirrors SPL `get_epoch_fee`: the newer entry is live from its own epoch on. */
13094
+ /** Returns the fee for `epoch`, as SPL `get_epoch_fee` does. The newer entry applies from its own epoch on. */
12671
13095
  function transferFeeAtEpoch(config, epoch) {
12672
13096
  const entry = epoch >= config.newer.epoch ? config.newer : config.older;
12673
13097
  return {
@@ -12682,8 +13106,9 @@ function mintFeeAtEpoch(data, owner, epoch) {
12682
13106
  function currentEpoch(rpc, commitment) {
12683
13107
  return rpc.getEpochInfo(commitment === void 0 ? void 0 : { commitment }).send().then((info) => info.epoch);
12684
13108
  }
12685
- /** A missing account throws, never reads as fee-free. Valid only for `epoch`, which defaults to
12686
- * the cluster's (a second call). */
13109
+ /** Reads the transfer fee of each mint for `epoch`. The result is valid only for that epoch.
13110
+ * `epoch` defaults to the current cluster epoch, read with `getEpochInfo`. A mint without a
13111
+ * transfer fee maps to `undefined`. Throws if a mint account is missing or does not decode. */
12687
13112
  async function fetchMintFees(rpc, mints, options) {
12688
13113
  const commitment = options?.commitment;
12689
13114
  const [epoch, accounts] = await Promise.all([options?.epoch ?? currentEpoch(rpc, commitment), fetchInChunks(mints, (chunk) => rpc.getMultipleAccounts(chunk, commitment === void 0 ? { encoding: "base64" } : {
@@ -12712,7 +13137,8 @@ function decodeMintInfo(mint, data, owner) {
12712
13137
  tokenProgram: owner
12713
13138
  };
12714
13139
  }
12715
- /** Throws when the mint does not exist or is not owned by a token program. */
13140
+ /** Reads the decimals and token program of `mint`. Throws if the account does not exist, a token
13141
+ * program does not own it, or it is too short for a mint. */
12716
13142
  async function fetchQuoteMintInfo(rpc, mint, commitment) {
12717
13143
  const { value } = await rpc.getAccountInfo(mint, commitment === void 0 ? { encoding: "base64" } : {
12718
13144
  commitment,
@@ -12721,7 +13147,8 @@ async function fetchQuoteMintInfo(rpc, mint, commitment) {
12721
13147
  if (!value) throw new Error(`fetchQuoteMintInfo: no account at ${mint}`);
12722
13148
  return decodeMintInfo(mint, new Uint8Array(getBase64Encoder().encode(value.data[0])), value.owner);
12723
13149
  }
12724
- /** One round trip per 100 mints; results follow `mints` order. */
13150
+ /** Reads the decimals and token program of each mint. Results follow `mints` order. Throws as
13151
+ * {@link fetchQuoteMintInfo} does. */
12725
13152
  async function fetchQuoteMintInfos(rpc, mints, commitment) {
12726
13153
  if (mints.length === 0) return [];
12727
13154
  const value = await fetchInChunks(mints, (chunk) => rpc.getMultipleAccounts(chunk, commitment === void 0 ? { encoding: "base64" } : {
@@ -12738,6 +13165,7 @@ async function fetchQuoteMintInfos(rpc, mints, commitment) {
12738
13165
  //#endregion
12739
13166
  //#region src/utils/index.ts
12740
13167
  var utils_exports = /* @__PURE__ */ __exportAll({
13168
+ accountIsCreated: () => accountIsCreated,
12741
13169
  creatorHashFromId: () => creatorHashFromId,
12742
13170
  decodeCreatorId: () => decodeCreatorId,
12743
13171
  encodeCreatorId: () => encodeCreatorId,