@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
@@ -42,6 +42,7 @@ import {
42
42
  type ReadonlyUint8Array,
43
43
  } from '@solana/kit';
44
44
  import { SEND_LAUNCHPAD_PROGRAM_ADDRESS } from '../programs/index.js';
45
+ import { accountIsCreated } from '../shared/index.js';
45
46
  import {
46
47
  getBondingCurveStatusDecoder,
47
48
  getBondingCurveStatusEncoder,
@@ -191,9 +192,25 @@ export function getBondingCurveCodec(): FixedSizeCodec<
191
192
  return combineCodec(getBondingCurveEncoder(), getBondingCurveDecoder());
192
193
  }
193
194
 
195
+ /**
196
+ * Decodes a `BondingCurve` account, throwing when another program owns it or its discriminator
197
+ * does not match.
198
+ *
199
+ * Unlike {@link fetchMaybeBondingCurve}, this throws for an address that only holds lamports rather
200
+ * than returning the non-existing variant: an account passed as existing must never come back as that
201
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
202
+ */
194
203
  export function decodeBondingCurve<TAddress extends string = string>(
195
204
  encodedAccount: EncodedAccount<TAddress>,
196
205
  ): Account<BondingCurve, TAddress>;
206
+ /**
207
+ * Decodes a `BondingCurve` account, throwing when another program owns it or its discriminator
208
+ * does not match.
209
+ *
210
+ * Unlike {@link fetchMaybeBondingCurve}, this throws for an address that only holds lamports rather
211
+ * than returning the non-existing variant: an account passed as existing must never come back as that
212
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
213
+ */
197
214
  export function decodeBondingCurve<TAddress extends string = string>(
198
215
  encodedAccount: MaybeEncodedAccount<TAddress>,
199
216
  ): MaybeAccount<BondingCurve, TAddress>;
@@ -224,6 +241,7 @@ export function decodeBondingCurve<TAddress extends string = string>(
224
241
  );
225
242
  }
226
243
 
244
+ /** Fetches a `BondingCurve` account, throwing when it does not exist or only holds lamports. */
227
245
  export async function fetchBondingCurve<TAddress extends string = string>(
228
246
  rpc: Parameters<typeof fetchEncodedAccount>[0],
229
247
  address: Address<TAddress>,
@@ -234,15 +252,25 @@ export async function fetchBondingCurve<TAddress extends string = string>(
234
252
  return maybeAccount;
235
253
  }
236
254
 
255
+ /**
256
+ * Fetches a `BondingCurve` account, or the non-existing variant when the address holds no
257
+ * account or only lamports (see {@link accountIsCreated}).
258
+ * {@link decodeBondingCurve} throws for a lamports-only account instead.
259
+ */
237
260
  export async function fetchMaybeBondingCurve<TAddress extends string = string>(
238
261
  rpc: Parameters<typeof fetchEncodedAccount>[0],
239
262
  address: Address<TAddress>,
240
263
  config?: FetchAccountConfig,
241
264
  ): Promise<MaybeAccount<BondingCurve, TAddress>> {
242
265
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
243
- return decodeBondingCurve(maybeAccount);
266
+ return decodeBondingCurve(
267
+ accountIsCreated(maybeAccount)
268
+ ? maybeAccount
269
+ : { address, exists: false },
270
+ );
244
271
  }
245
272
 
273
+ /** Fetches `BondingCurve` accounts, throwing when any does not exist or only holds lamports. */
246
274
  export async function fetchAllBondingCurve(
247
275
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
248
276
  addresses: Array<Address>,
@@ -257,6 +285,11 @@ export async function fetchAllBondingCurve(
257
285
  return maybeAccounts;
258
286
  }
259
287
 
288
+ /**
289
+ * Fetches `BondingCurve` accounts, with the non-existing variant for each address that holds
290
+ * no account or only lamports (see {@link accountIsCreated}).
291
+ * {@link decodeBondingCurve} throws for a lamports-only account instead.
292
+ */
260
293
  export async function fetchAllMaybeBondingCurve(
261
294
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
262
295
  addresses: Array<Address>,
@@ -264,7 +297,11 @@ export async function fetchAllMaybeBondingCurve(
264
297
  ): Promise<MaybeAccount<BondingCurve>[]> {
265
298
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
266
299
  return maybeAccounts.map((maybeAccount) =>
267
- decodeBondingCurve(maybeAccount),
300
+ decodeBondingCurve(
301
+ accountIsCreated(maybeAccount)
302
+ ? maybeAccount
303
+ : { address: maybeAccount.address, exists: false },
304
+ ),
268
305
  );
269
306
  }
270
307
 
@@ -42,6 +42,7 @@ import {
42
42
  type ReadonlyUint8Array,
43
43
  } from '@solana/kit';
44
44
  import { SEND_LAUNCHPAD_PROGRAM_ADDRESS } from '../programs/index.js';
45
+ import { accountIsCreated } from '../shared/index.js';
45
46
 
46
47
  export const GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
47
48
  149, 8, 156, 202, 160, 252, 176, 217,
@@ -129,9 +130,25 @@ export function getGlobalConfigCodec(): FixedSizeCodec<
129
130
  return combineCodec(getGlobalConfigEncoder(), getGlobalConfigDecoder());
130
131
  }
131
132
 
133
+ /**
134
+ * Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
135
+ * does not match.
136
+ *
137
+ * Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
138
+ * than returning the non-existing variant: an account passed as existing must never come back as that
139
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
140
+ */
132
141
  export function decodeGlobalConfig<TAddress extends string = string>(
133
142
  encodedAccount: EncodedAccount<TAddress>,
134
143
  ): Account<GlobalConfig, TAddress>;
144
+ /**
145
+ * Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
146
+ * does not match.
147
+ *
148
+ * Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
149
+ * than returning the non-existing variant: an account passed as existing must never come back as that
150
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
151
+ */
135
152
  export function decodeGlobalConfig<TAddress extends string = string>(
136
153
  encodedAccount: MaybeEncodedAccount<TAddress>,
137
154
  ): MaybeAccount<GlobalConfig, TAddress>;
@@ -162,6 +179,7 @@ export function decodeGlobalConfig<TAddress extends string = string>(
162
179
  );
163
180
  }
164
181
 
182
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
165
183
  export async function fetchGlobalConfig<TAddress extends string = string>(
166
184
  rpc: Parameters<typeof fetchEncodedAccount>[0],
167
185
  address: Address<TAddress>,
@@ -172,15 +190,25 @@ export async function fetchGlobalConfig<TAddress extends string = string>(
172
190
  return maybeAccount;
173
191
  }
174
192
 
193
+ /**
194
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
195
+ * account or only lamports (see {@link accountIsCreated}).
196
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
197
+ */
175
198
  export async function fetchMaybeGlobalConfig<TAddress extends string = string>(
176
199
  rpc: Parameters<typeof fetchEncodedAccount>[0],
177
200
  address: Address<TAddress>,
178
201
  config?: FetchAccountConfig,
179
202
  ): Promise<MaybeAccount<GlobalConfig, TAddress>> {
180
203
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
181
- return decodeGlobalConfig(maybeAccount);
204
+ return decodeGlobalConfig(
205
+ accountIsCreated(maybeAccount)
206
+ ? maybeAccount
207
+ : { address, exists: false },
208
+ );
182
209
  }
183
210
 
211
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
184
212
  export async function fetchAllGlobalConfig(
185
213
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
186
214
  addresses: Array<Address>,
@@ -195,6 +223,11 @@ export async function fetchAllGlobalConfig(
195
223
  return maybeAccounts;
196
224
  }
197
225
 
226
+ /**
227
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
228
+ * no account or only lamports (see {@link accountIsCreated}).
229
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
230
+ */
198
231
  export async function fetchAllMaybeGlobalConfig(
199
232
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
200
233
  addresses: Array<Address>,
@@ -202,7 +235,11 @@ export async function fetchAllMaybeGlobalConfig(
202
235
  ): Promise<MaybeAccount<GlobalConfig>[]> {
203
236
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
204
237
  return maybeAccounts.map((maybeAccount) =>
205
- decodeGlobalConfig(maybeAccount),
238
+ decodeGlobalConfig(
239
+ accountIsCreated(maybeAccount)
240
+ ? maybeAccount
241
+ : { address: maybeAccount.address, exists: false },
242
+ ),
206
243
  );
207
244
  }
208
245
 
@@ -42,6 +42,7 @@ import {
42
42
  type ReadonlyUint8Array,
43
43
  } from '@solana/kit';
44
44
  import { SEND_LAUNCHPAD_PROGRAM_ADDRESS } from '../programs/index.js';
45
+ import { accountIsCreated } from '../shared/index.js';
45
46
 
46
47
  export const REWARD_ACCRUAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
47
48
  158, 244, 116, 30, 227, 132, 105, 182,
@@ -109,9 +110,25 @@ export function getRewardAccrualCodec(): FixedSizeCodec<
109
110
  return combineCodec(getRewardAccrualEncoder(), getRewardAccrualDecoder());
110
111
  }
111
112
 
113
+ /**
114
+ * Decodes a `RewardAccrual` account, throwing when another program owns it or its discriminator
115
+ * does not match.
116
+ *
117
+ * Unlike {@link fetchMaybeRewardAccrual}, this throws for an address that only holds lamports rather
118
+ * than returning the non-existing variant: an account passed as existing must never come back as that
119
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
120
+ */
112
121
  export function decodeRewardAccrual<TAddress extends string = string>(
113
122
  encodedAccount: EncodedAccount<TAddress>,
114
123
  ): Account<RewardAccrual, TAddress>;
124
+ /**
125
+ * Decodes a `RewardAccrual` account, throwing when another program owns it or its discriminator
126
+ * does not match.
127
+ *
128
+ * Unlike {@link fetchMaybeRewardAccrual}, this throws for an address that only holds lamports rather
129
+ * than returning the non-existing variant: an account passed as existing must never come back as that
130
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
131
+ */
115
132
  export function decodeRewardAccrual<TAddress extends string = string>(
116
133
  encodedAccount: MaybeEncodedAccount<TAddress>,
117
134
  ): MaybeAccount<RewardAccrual, TAddress>;
@@ -142,6 +159,7 @@ export function decodeRewardAccrual<TAddress extends string = string>(
142
159
  );
143
160
  }
144
161
 
162
+ /** Fetches a `RewardAccrual` account, throwing when it does not exist or only holds lamports. */
145
163
  export async function fetchRewardAccrual<TAddress extends string = string>(
146
164
  rpc: Parameters<typeof fetchEncodedAccount>[0],
147
165
  address: Address<TAddress>,
@@ -152,15 +170,25 @@ export async function fetchRewardAccrual<TAddress extends string = string>(
152
170
  return maybeAccount;
153
171
  }
154
172
 
173
+ /**
174
+ * Fetches a `RewardAccrual` account, or the non-existing variant when the address holds no
175
+ * account or only lamports (see {@link accountIsCreated}).
176
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
177
+ */
155
178
  export async function fetchMaybeRewardAccrual<TAddress extends string = string>(
156
179
  rpc: Parameters<typeof fetchEncodedAccount>[0],
157
180
  address: Address<TAddress>,
158
181
  config?: FetchAccountConfig,
159
182
  ): Promise<MaybeAccount<RewardAccrual, TAddress>> {
160
183
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
161
- return decodeRewardAccrual(maybeAccount);
184
+ return decodeRewardAccrual(
185
+ accountIsCreated(maybeAccount)
186
+ ? maybeAccount
187
+ : { address, exists: false },
188
+ );
162
189
  }
163
190
 
191
+ /** Fetches `RewardAccrual` accounts, throwing when any does not exist or only holds lamports. */
164
192
  export async function fetchAllRewardAccrual(
165
193
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
166
194
  addresses: Array<Address>,
@@ -175,6 +203,11 @@ export async function fetchAllRewardAccrual(
175
203
  return maybeAccounts;
176
204
  }
177
205
 
206
+ /**
207
+ * Fetches `RewardAccrual` accounts, with the non-existing variant for each address that holds
208
+ * no account or only lamports (see {@link accountIsCreated}).
209
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
210
+ */
178
211
  export async function fetchAllMaybeRewardAccrual(
179
212
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
180
213
  addresses: Array<Address>,
@@ -182,7 +215,11 @@ export async function fetchAllMaybeRewardAccrual(
182
215
  ): Promise<MaybeAccount<RewardAccrual>[]> {
183
216
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
184
217
  return maybeAccounts.map((maybeAccount) =>
185
- decodeRewardAccrual(maybeAccount),
218
+ decodeRewardAccrual(
219
+ accountIsCreated(maybeAccount)
220
+ ? maybeAccount
221
+ : { address: maybeAccount.address, exists: false },
222
+ ),
186
223
  );
187
224
  }
188
225
 
@@ -13,4 +13,5 @@ export * from './instructions/index.js';
13
13
  export * from './pdas/index.js';
14
14
  export * from './plugins/index.js';
15
15
  export * from './programs/index.js';
16
+ export * from './shared/index.js';
16
17
  export * from './types/index.js';
@@ -45,7 +45,7 @@ import {
45
45
  getAddressFromResolvedInstructionAccount,
46
46
  getNonNullResolvedInstructionInput,
47
47
  type ResolvedInstructionAccount,
48
- } from '@solana/program-client-core';
48
+ } from '@solana/kit/program-client-core';
49
49
  import {
50
50
  EVENT_AUTHORITY_PDA_ADDRESS,
51
51
  findBondingCurvePda,
@@ -45,7 +45,7 @@ import {
45
45
  getAddressFromResolvedInstructionAccount,
46
46
  getNonNullResolvedInstructionInput,
47
47
  type ResolvedInstructionAccount,
48
- } from '@solana/program-client-core';
48
+ } from '@solana/kit/program-client-core';
49
49
  import {
50
50
  EVENT_AUTHORITY_PDA_ADDRESS,
51
51
  findBondingCurvePda,
@@ -41,7 +41,7 @@ import {
41
41
  getAccountMetaFactory,
42
42
  getAddressFromResolvedInstructionAccount,
43
43
  type ResolvedInstructionAccount,
44
- } from '@solana/program-client-core';
44
+ } from '@solana/kit/program-client-core';
45
45
  import {
46
46
  EVENT_AUTHORITY_PDA_ADDRESS,
47
47
  findBondingCurvePda,
@@ -40,7 +40,7 @@ import {
40
40
  getAccountMetaFactory,
41
41
  getAddressFromResolvedInstructionAccount,
42
42
  type ResolvedInstructionAccount,
43
- } from '@solana/program-client-core';
43
+ } from '@solana/kit/program-client-core';
44
44
  import {
45
45
  EVENT_AUTHORITY_PDA_ADDRESS,
46
46
  findBondingCurvePda,
@@ -50,7 +50,7 @@ import {
50
50
  getAddressFromResolvedInstructionAccount,
51
51
  getNonNullResolvedInstructionInput,
52
52
  type ResolvedInstructionAccount,
53
- } from '@solana/program-client-core';
53
+ } from '@solana/kit/program-client-core';
54
54
  import {
55
55
  EVENT_AUTHORITY_PDA_ADDRESS,
56
56
  findBondingCurvePda,
@@ -41,7 +41,7 @@ import {
41
41
  getAccountMetaFactory,
42
42
  getAddressFromResolvedInstructionAccount,
43
43
  type ResolvedInstructionAccount,
44
- } from '@solana/program-client-core';
44
+ } from '@solana/kit/program-client-core';
45
45
  import {
46
46
  EVENT_AUTHORITY_PDA_ADDRESS,
47
47
  findBondingCurvePda,
@@ -45,7 +45,7 @@ import {
45
45
  getAddressFromResolvedInstructionAccount,
46
46
  getNonNullResolvedInstructionInput,
47
47
  type ResolvedInstructionAccount,
48
- } from '@solana/program-client-core';
48
+ } from '@solana/kit/program-client-core';
49
49
  import {
50
50
  EVENT_AUTHORITY_PDA_ADDRESS,
51
51
  findBondingCurvePda,
@@ -45,7 +45,7 @@ import {
45
45
  getAddressFromResolvedInstructionAccount,
46
46
  getNonNullResolvedInstructionInput,
47
47
  type ResolvedInstructionAccount,
48
- } from '@solana/program-client-core';
48
+ } from '@solana/kit/program-client-core';
49
49
  import {
50
50
  EVENT_AUTHORITY_PDA_ADDRESS,
51
51
  findBondingCurvePda,
@@ -20,7 +20,7 @@ import {
20
20
  addSelfPlanAndSendFunctions,
21
21
  type SelfFetchFunctions,
22
22
  type SelfPlanAndSendFunctions,
23
- } from '@solana/program-client-core';
23
+ } from '@solana/kit/program-client-core';
24
24
  import {
25
25
  fetchAllBondingCurve,
26
26
  fetchAllGlobalConfig,
@@ -0,0 +1,52 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import type { Address, EncodedAccount, MaybeEncodedAccount } from '@solana/kit';
10
+
11
+ /** The System Program, which owns every address nobody has created an account at yet. */
12
+ const SYSTEM_PROGRAM_ADDRESS =
13
+ '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
14
+
15
+ /**
16
+ * Whether an encoded account was created on-chain, rather than merely sent lamports.
17
+ *
18
+ * Anyone can send lamports to an address before its account is created, which leaves it on-chain,
19
+ * owned by the System Program, with no data. This returns `false` for that shape, as it does for an
20
+ * account that does not exist. Any other existing account counts as created, whoever owns it; the
21
+ * `decode*` functions still check the owner.
22
+ *
23
+ * The generated `fetchMaybe*` and `fetchAllMaybe*` helpers apply this rule themselves. Apply it to
24
+ * accounts you fetch or receive another way (subscriptions, batch loaders, caches) before passing
25
+ * them to a `decode*` function, which throws for a lamports-only account: an account passed to it as
26
+ * existing must never come back as the non-existing variant typed as an `Account`.
27
+ *
28
+ * Only a `true` result narrows the type. A lamports-only account is still `exists: true` at runtime,
29
+ * so a `false` result leaves the type unchanged instead of narrowing it to the non-existing variant.
30
+ * The `uncreated` property in the narrowed type is never present; it exists only to prevent that.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const maybeAccount = decodeMyAccount(
35
+ * accountIsCreated(encodedAccount) ? encodedAccount : { address: encodedAccount.address, exists: false },
36
+ * );
37
+ * ```
38
+ */
39
+ export function accountIsCreated<
40
+ TAccount extends EncodedAccount | MaybeEncodedAccount,
41
+ >(
42
+ account: TAccount,
43
+ ): account is Exclude<TAccount, { readonly exists: false }> & {
44
+ readonly uncreated?: never;
45
+ } {
46
+ const maybeAccount: EncodedAccount | MaybeEncodedAccount = account;
47
+ if ('exists' in maybeAccount && !maybeAccount.exists) return false;
48
+ return !(
49
+ maybeAccount.programAddress === SYSTEM_PROGRAM_ADDRESS &&
50
+ maybeAccount.data.length === 0
51
+ );
52
+ }
@@ -9,7 +9,7 @@ export interface MigrateParams {
9
9
  caller: TransactionSigner;
10
10
  baseMint: Address;
11
11
  quoteMint: Address;
12
- /** `bondingCurve.creatorFeeConfig`; `migrate` rejects any other address. */
12
+ /** `bondingCurve.creatorFeeConfig`. `migrate` rejects any other address. */
13
13
  creatorFeeConfig: Address;
14
14
  quoteTokenProgram: Address;
15
15
  }
@@ -19,7 +19,7 @@ export interface LaunchpadTradeParams {
19
19
  partner: PartnerInput;
20
20
  platformConfig: Address;
21
21
  quoteTokenProgram: Address;
22
- /** Token-2022 schedule for the epoch the trade lands in; stale or missing skews the slippage bounds. */
22
+ /** The quote mint's transfer fee for the epoch the trade lands in. A missing or old fee gives wrong slippage bounds. */
23
23
  quoteFee?: MintFee;
24
24
  baseFee?: MintFee;
25
25
  /** {@inheritDoc LaunchpadInstructionParams.userQuoteAccount} */
@@ -40,16 +40,16 @@ export interface LaunchpadInstructionParams {
40
40
  partner: PartnerInput;
41
41
  platformConfig: Address;
42
42
  quoteTokenProgram: Address;
43
- /** Any user-owned quote-mint account. Defaults to the ATA, created mid-trade
44
- * if missing (payer funds rent), which only rescues a sell. For WSOL,
45
- * a throwaway `createAccountWithSeed` account is cheaper. */
43
+ /** Any quote-mint token account that `user` owns. Defaults to the user's ATA.
44
+ * The program creates a missing ATA, and `payer` pays the rent. */
46
45
  userQuoteAccount?: Address;
47
- /** Any user-owned base-mint account. Defaults to the ATA, created mid-trade
48
- * if missing (payer funds rent), which only rescues a buy. */
46
+ /** Any base-mint token account that `user` owns. Defaults to the user's ATA.
47
+ * The program creates a missing ATA, and `payer` pays the rent. */
49
48
  userBaseAccount?: Address;
50
49
  }
51
50
 
52
- /** `baseAmountOut` is net to the buyer: the program reads `amount` as `base_to_user`. */
51
+ /** `baseAmountOut` is the base the buyer receives, after the base mint's transfer fee.
52
+ * The buy is capped at the curve's supply left. Read the result from `quote.baseToUser`. */
53
53
  export async function buyExactOut(
54
54
  params: LaunchpadBuyParams & { baseAmountOut: bigint },
55
55
  ): Promise<{ instruction: Instruction; quote: BuyQuote }> {
@@ -62,7 +62,7 @@ export async function buyExactOut(
62
62
  baseFee: params.baseFee,
63
63
  baseReserveCap: params.realBaseReserves,
64
64
  });
65
- // The cap is measured on the gross the buyer sends, quote transfer fee included.
65
+ // The program checks `maxAmountIn` against the gross the buyer sends, quote transfer fee included.
66
66
  const maxQuoteIn = amm.calculateSlippageUp(
67
67
  quote.quoteFromUser,
68
68
  params.slippageBps,
@@ -70,7 +70,7 @@ export async function buyExactOut(
70
70
  return {
71
71
  instruction: await buildBuyExactOutInstruction({
72
72
  ...params,
73
- // Capped at the supply left. The program reverts a short fill.
73
+ // Capped at the supply left. The program rejects a larger amount.
74
74
  amountOut: quote.baseToUser,
75
75
  maxAmountIn: maxQuoteIn,
76
76
  }),
@@ -90,7 +90,7 @@ export async function buyExactIn(
90
90
  baseFee: params.baseFee,
91
91
  baseReserveCap: params.realBaseReserves,
92
92
  });
93
- // The floor is measured on the buyer's credit, not the vault's debit.
93
+ // The program checks `minAmountOut` against what the buyer receives, not the vault's debit.
94
94
  const minBaseOut = amm.calculateSlippageDown(
95
95
  quote.baseToUser,
96
96
  params.slippageBps,
@@ -116,7 +116,7 @@ export async function sellExactIn(
116
116
  quoteFee: params.quoteFee,
117
117
  baseFee: params.baseFee,
118
118
  });
119
- // The floor is measured on the seller's credit, not what leaves the vault.
119
+ // The program checks `minAmountOut` against what the seller receives, not the vault's debit.
120
120
  const minQuoteOut = amm.calculateSlippageDown(
121
121
  quote.quoteToUser,
122
122
  params.slippageBps,
@@ -131,7 +131,7 @@ export async function sellExactIn(
131
131
  };
132
132
  }
133
133
 
134
- /** `quoteAmountOut` is net to the seller: the program reads `amount` as `quote_to_user`. */
134
+ /** `quoteAmountOut` is the quote the seller receives, after the quote mint's transfer fee. */
135
135
  export async function sellExactOut(
136
136
  params: LaunchpadTradeParams & { quoteAmountOut: bigint },
137
137
  ): Promise<{ instruction: Instruction; quote: SellQuote }> {
@@ -143,7 +143,7 @@ export async function sellExactOut(
143
143
  quoteFee: params.quoteFee,
144
144
  baseFee: params.baseFee,
145
145
  });
146
- // The cap is measured on the gross the seller sends, base transfer fee included.
146
+ // The program checks `maxAmountIn` against the gross the seller sends, base transfer fee included.
147
147
  const maxBaseIn = amm.calculateSlippageUp(
148
148
  quote.baseFromUser,
149
149
  params.slippageBps,
@@ -214,7 +214,7 @@ export async function buildSellExactOutInstruction(
214
214
  });
215
215
  }
216
216
 
217
- /** Percent of the curve's real base sold (0-100); 100 is the migration threshold. */
217
+ /** Returns the percent of the curve's real base sold, from 0 to 100. At 100 the curve can migrate. */
218
218
  export function calculateBondingCurveProgress(params: {
219
219
  realBaseReserves: bigint;
220
220
  initialRealBase: bigint;
@@ -237,7 +237,7 @@ function resolveSharedAccounts(params: LaunchpadInstructionParams) {
237
237
  partner: params.partner,
238
238
  platformConfig: params.platformConfig,
239
239
  quoteTokenProgram: params.quoteTokenProgram,
240
- // Left undefined so the generated client derives the ATA itself.
240
+ // When omitted, the generated client derives the ATA.
241
241
  ...(params.userQuoteAccount !== undefined && {
242
242
  userQuoteAccount: params.userQuoteAccount,
243
243
  }),