@send-fun/sdk 1.1.0 → 2.0.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 (80) hide show
  1. package/README.md +8 -9
  2. package/dist/index.cjs +777 -433
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +678 -217
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +678 -217
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +777 -433
  9. package/dist/index.mjs.map +1 -1
  10. package/package.json +7 -7
  11. package/src/dex/generated/accounts/globalConfig.ts +39 -2
  12. package/src/dex/generated/accounts/pool.ts +60 -9
  13. package/src/dex/generated/accounts/rewardAccrual.ts +39 -2
  14. package/src/dex/generated/errors/sendDex.ts +16 -8
  15. package/src/dex/generated/events/creatorClaimEvent.ts +3 -2
  16. package/src/dex/generated/events/poolCreateEvent.ts +8 -2
  17. package/src/dex/generated/events/tokenCreateEvent.ts +8 -9
  18. package/src/dex/generated/events/tradeEvent.ts +9 -2
  19. package/src/dex/generated/index.ts +1 -0
  20. package/src/dex/generated/instructions/claimCreatorFees.ts +21 -5
  21. package/src/{nexus → dex}/generated/pdas/creatorFeeConfig.ts +6 -6
  22. package/src/dex/generated/pdas/index.ts +1 -0
  23. package/src/dex/generated/plugins/sendDex.ts +3 -0
  24. package/src/dex/generated/shared/index.ts +52 -0
  25. package/src/dex/trade.ts +12 -13
  26. package/src/launchpad/create.ts +13 -38
  27. package/src/launchpad/generated/accounts/bondingCurve.ts +62 -9
  28. package/src/launchpad/generated/accounts/globalConfig.ts +39 -2
  29. package/src/launchpad/generated/accounts/rewardAccrual.ts +39 -2
  30. package/src/launchpad/generated/errors/sendLaunchpad.ts +12 -4
  31. package/src/launchpad/generated/events/completeEvent.ts +3 -2
  32. package/src/launchpad/generated/events/creatorClaimEvent.ts +3 -2
  33. package/src/launchpad/generated/events/migrateEvent.ts +3 -2
  34. package/src/launchpad/generated/events/tokenCreateEvent.ts +10 -9
  35. package/src/launchpad/generated/events/tradeEvent.ts +9 -2
  36. package/src/launchpad/generated/index.ts +1 -0
  37. package/src/launchpad/generated/instructions/claimCreatorFees.ts +17 -4
  38. package/src/launchpad/generated/instructions/createToken.ts +32 -50
  39. package/src/launchpad/generated/instructions/migrate.ts +79 -12
  40. package/src/launchpad/generated/pdas/creatorFeeConfig.ts +39 -0
  41. package/src/launchpad/generated/pdas/index.ts +1 -0
  42. package/src/launchpad/generated/plugins/sendLaunchpad.ts +3 -0
  43. package/src/launchpad/generated/shared/index.ts +52 -0
  44. package/src/launchpad/migrate.ts +7 -4
  45. package/src/launchpad/trade.ts +15 -15
  46. package/src/math/amm.ts +40 -33
  47. package/src/math/fee-decay.ts +3 -2
  48. package/src/math/fees.ts +4 -2
  49. package/src/math/internal.ts +1 -1
  50. package/src/nexus/fee-helpers.ts +10 -5
  51. package/src/nexus/generated/accounts/altRegistry.ts +41 -2
  52. package/src/nexus/generated/accounts/feePreset.ts +43 -4
  53. package/src/nexus/generated/accounts/globalConfig.ts +39 -2
  54. package/src/nexus/generated/accounts/index.ts +0 -1
  55. package/src/nexus/generated/accounts/partnerConfig.ts +48 -5
  56. package/src/nexus/generated/accounts/partnerMetadata.ts +39 -2
  57. package/src/nexus/generated/accounts/rewardState.ts +41 -2
  58. package/src/nexus/generated/accounts/sendNexus.accounts.ts +0 -5
  59. package/src/nexus/generated/accounts/stakingConfig.ts +39 -2
  60. package/src/nexus/generated/accounts/userRewardDebt.ts +42 -5
  61. package/src/nexus/generated/accounts/userStakePosition.ts +42 -5
  62. package/src/nexus/generated/errors/sendNexus.ts +12 -4
  63. package/src/nexus/generated/index.ts +1 -0
  64. package/src/nexus/generated/pdas/index.ts +0 -1
  65. package/src/nexus/generated/plugins/sendNexus.ts +0 -35
  66. package/src/nexus/generated/shared/index.ts +52 -0
  67. package/src/nexus/generated/types/dexFees.ts +4 -4
  68. package/src/nexus/generated/types/index.ts +0 -1
  69. package/src/nexus/generated/types/launchpadFees.ts +4 -4
  70. package/src/nexus/staking.ts +45 -41
  71. package/src/platform.ts +2 -2
  72. package/src/transfer-fee.ts +19 -17
  73. package/src/utils/chunk.ts +1 -1
  74. package/src/utils/index.ts +2 -5
  75. package/src/utils/mint-info.ts +8 -7
  76. package/src/utils/partner.ts +1 -1
  77. package/src/utils/pda.ts +1 -1
  78. package/src/nexus/generated/accounts/creatorFeeConfig.ts +0 -200
  79. package/src/nexus/generated/types/callerType.ts +0 -38
  80. package/src/utils/creator-hash.ts +0 -57
@@ -45,6 +45,7 @@ import {
45
45
  import {
46
46
  EVENT_AUTHORITY_PDA_ADDRESS,
47
47
  findBondingCurvePda,
48
+ findCreatorFeeConfigPda,
48
49
  MIGRATION_AUTHORITY_PDA_ADDRESS,
49
50
  } from '../pdas/index.js';
50
51
  import { SEND_LAUNCHPAD_PROGRAM_ADDRESS } from '../programs/index.js';
@@ -90,6 +91,7 @@ export type MigrateInstruction<
90
91
  'FJVebqCthxH6JM8vvkJb7yRYA7Emsib1C1vu4ZePSP3T',
91
92
  TAccountProgram extends string | AccountMeta<string> =
92
93
  '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP',
94
+ TAccountDexCreatorFeeConfig extends string | AccountMeta<string> = string,
93
95
  TRemainingAccounts extends readonly AccountMeta<string>[] = [],
94
96
  > = Instruction<TProgram> &
95
97
  InstructionWithData<ReadonlyUint8Array> &
@@ -142,7 +144,7 @@ export type MigrateInstruction<
142
144
  ? ReadonlyAccount<TAccountNexusProgram>
143
145
  : TAccountNexusProgram,
144
146
  TAccountCreatorFeeConfig extends string
145
- ? ReadonlyAccount<TAccountCreatorFeeConfig>
147
+ ? WritableAccount<TAccountCreatorFeeConfig>
146
148
  : TAccountCreatorFeeConfig,
147
149
  TAccountBaseTokenProgram extends string
148
150
  ? ReadonlyAccount<TAccountBaseTokenProgram>
@@ -162,6 +164,9 @@ export type MigrateInstruction<
162
164
  TAccountProgram extends string
163
165
  ? ReadonlyAccount<TAccountProgram>
164
166
  : TAccountProgram,
167
+ TAccountDexCreatorFeeConfig extends string
168
+ ? WritableAccount<TAccountDexCreatorFeeConfig>
169
+ : TAccountDexCreatorFeeConfig,
165
170
  ...TRemainingAccounts,
166
171
  ]
167
172
  >;
@@ -209,6 +214,7 @@ export type MigrateAsyncInput<
209
214
  TAccountPoolLpAccount extends string = string,
210
215
  TAccountCreatorFeeConfig extends string = string,
211
216
  TAccountQuoteTokenProgram extends string = string,
217
+ TAccountDexCreatorFeeConfig extends string = string,
212
218
  > = {
213
219
  caller: TransactionSigner<TAccountCaller>;
214
220
  bondingCurve?: Address<TAccountBondingCurve>;
@@ -221,8 +227,9 @@ export type MigrateAsyncInput<
221
227
  poolBaseVault: Address<TAccountPoolBaseVault>;
222
228
  poolQuoteVault: Address<TAccountPoolQuoteVault>;
223
229
  poolLpAccount: Address<TAccountPoolLpAccount>;
224
- creatorFeeConfig: Address<TAccountCreatorFeeConfig>;
230
+ creatorFeeConfig?: Address<TAccountCreatorFeeConfig>;
225
231
  quoteTokenProgram: Address<TAccountQuoteTokenProgram>;
232
+ dexCreatorFeeConfig?: Address<TAccountDexCreatorFeeConfig>;
226
233
  };
227
234
 
228
235
  export async function getMigrateInstructionAsync<
@@ -239,6 +246,7 @@ export async function getMigrateInstructionAsync<
239
246
  TAccountPoolLpAccount extends string,
240
247
  TAccountCreatorFeeConfig extends string,
241
248
  TAccountQuoteTokenProgram extends string,
249
+ TAccountDexCreatorFeeConfig extends string,
242
250
  >(
243
251
  input: MigrateAsyncInput<
244
252
  TAccountCaller,
@@ -253,7 +261,8 @@ export async function getMigrateInstructionAsync<
253
261
  TAccountPoolQuoteVault,
254
262
  TAccountPoolLpAccount,
255
263
  TAccountCreatorFeeConfig,
256
- TAccountQuoteTokenProgram
264
+ TAccountQuoteTokenProgram,
265
+ TAccountDexCreatorFeeConfig
257
266
  >,
258
267
  ): Promise<
259
268
  MigrateInstruction<
@@ -279,7 +288,8 @@ export async function getMigrateInstructionAsync<
279
288
  'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
280
289
  '11111111111111111111111111111111',
281
290
  'FJVebqCthxH6JM8vvkJb7yRYA7Emsib1C1vu4ZePSP3T',
282
- '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP'
291
+ '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP',
292
+ TAccountDexCreatorFeeConfig
283
293
  >
284
294
  > {
285
295
  // Program address.
@@ -307,7 +317,7 @@ export async function getMigrateInstructionAsync<
307
317
  nexusProgram: { value: null, isWritable: false },
308
318
  creatorFeeConfig: {
309
319
  value: input.creatorFeeConfig ?? null,
310
- isWritable: false,
320
+ isWritable: true,
311
321
  },
312
322
  baseTokenProgram: { value: null, isWritable: false },
313
323
  quoteTokenProgram: {
@@ -318,6 +328,10 @@ export async function getMigrateInstructionAsync<
318
328
  systemProgram: { value: null, isWritable: false },
319
329
  eventAuthority: { value: null, isWritable: false },
320
330
  program: { value: null, isWritable: false },
331
+ dexCreatorFeeConfig: {
332
+ value: input.dexCreatorFeeConfig ?? null,
333
+ isWritable: true,
334
+ },
321
335
  };
322
336
  const accounts = originalAccounts as Record<
323
337
  keyof typeof originalAccounts,
@@ -445,6 +459,18 @@ export async function getMigrateInstructionAsync<
445
459
  accounts.nexusProgram.value =
446
460
  '7rrCurqdWFesbzwtYPo95fM8waTtVXgXwCom45x1sfNX' as Address<'7rrCurqdWFesbzwtYPo95fM8waTtVXgXwCom45x1sfNX'>;
447
461
  }
462
+ if (!accounts.creatorFeeConfig.value) {
463
+ accounts.creatorFeeConfig.value = await findCreatorFeeConfigPda({
464
+ baseMint: getAddressFromResolvedInstructionAccount(
465
+ 'baseMint',
466
+ accounts.baseMint.value,
467
+ ),
468
+ quoteMint: getAddressFromResolvedInstructionAccount(
469
+ 'quoteMint',
470
+ accounts.quoteMint.value,
471
+ ),
472
+ });
473
+ }
448
474
  if (!accounts.baseTokenProgram.value) {
449
475
  accounts.baseTokenProgram.value =
450
476
  'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
@@ -464,6 +490,32 @@ export async function getMigrateInstructionAsync<
464
490
  accounts.program.value =
465
491
  '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP' as Address<'5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP'>;
466
492
  }
493
+ if (!accounts.dexCreatorFeeConfig.value) {
494
+ accounts.dexCreatorFeeConfig.value = await getProgramDerivedAddress({
495
+ programAddress:
496
+ '84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX' as Address<'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX'>,
497
+ seeds: [
498
+ getBytesEncoder().encode(
499
+ new Uint8Array([
500
+ 99, 114, 101, 97, 116, 111, 114, 95, 102, 101, 101, 95,
501
+ 99, 111, 110, 102, 105, 103,
502
+ ]),
503
+ ),
504
+ getAddressEncoder().encode(
505
+ getAddressFromResolvedInstructionAccount(
506
+ 'baseMint',
507
+ accounts.baseMint.value,
508
+ ),
509
+ ),
510
+ getAddressEncoder().encode(
511
+ getAddressFromResolvedInstructionAccount(
512
+ 'quoteMint',
513
+ accounts.quoteMint.value,
514
+ ),
515
+ ),
516
+ ],
517
+ });
518
+ }
467
519
 
468
520
  const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
469
521
  return Object.freeze({
@@ -493,6 +545,7 @@ export async function getMigrateInstructionAsync<
493
545
  getAccountMeta('systemProgram', accounts.systemProgram),
494
546
  getAccountMeta('eventAuthority', accounts.eventAuthority),
495
547
  getAccountMeta('program', accounts.program),
548
+ getAccountMeta('dexCreatorFeeConfig', accounts.dexCreatorFeeConfig),
496
549
  ],
497
550
  data: getMigrateInstructionDataEncoder().encode({}),
498
551
  programAddress,
@@ -519,7 +572,8 @@ export async function getMigrateInstructionAsync<
519
572
  'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
520
573
  '11111111111111111111111111111111',
521
574
  'FJVebqCthxH6JM8vvkJb7yRYA7Emsib1C1vu4ZePSP3T',
522
- '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP'
575
+ '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP',
576
+ TAccountDexCreatorFeeConfig
523
577
  >);
524
578
  }
525
579
 
@@ -537,6 +591,7 @@ export type MigrateInput<
537
591
  TAccountPoolLpAccount extends string = string,
538
592
  TAccountCreatorFeeConfig extends string = string,
539
593
  TAccountQuoteTokenProgram extends string = string,
594
+ TAccountDexCreatorFeeConfig extends string = string,
540
595
  > = {
541
596
  caller: TransactionSigner<TAccountCaller>;
542
597
  bondingCurve: Address<TAccountBondingCurve>;
@@ -551,6 +606,7 @@ export type MigrateInput<
551
606
  poolLpAccount: Address<TAccountPoolLpAccount>;
552
607
  creatorFeeConfig: Address<TAccountCreatorFeeConfig>;
553
608
  quoteTokenProgram: Address<TAccountQuoteTokenProgram>;
609
+ dexCreatorFeeConfig: Address<TAccountDexCreatorFeeConfig>;
554
610
  };
555
611
 
556
612
  export function getMigrateInstruction<
@@ -567,6 +623,7 @@ export function getMigrateInstruction<
567
623
  TAccountPoolLpAccount extends string,
568
624
  TAccountCreatorFeeConfig extends string,
569
625
  TAccountQuoteTokenProgram extends string,
626
+ TAccountDexCreatorFeeConfig extends string,
570
627
  >(
571
628
  input: MigrateInput<
572
629
  TAccountCaller,
@@ -581,7 +638,8 @@ export function getMigrateInstruction<
581
638
  TAccountPoolQuoteVault,
582
639
  TAccountPoolLpAccount,
583
640
  TAccountCreatorFeeConfig,
584
- TAccountQuoteTokenProgram
641
+ TAccountQuoteTokenProgram,
642
+ TAccountDexCreatorFeeConfig
585
643
  >,
586
644
  ): MigrateInstruction<
587
645
  typeof SEND_LAUNCHPAD_PROGRAM_ADDRESS,
@@ -606,7 +664,8 @@ export function getMigrateInstruction<
606
664
  'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
607
665
  '11111111111111111111111111111111',
608
666
  'FJVebqCthxH6JM8vvkJb7yRYA7Emsib1C1vu4ZePSP3T',
609
- '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP'
667
+ '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP',
668
+ TAccountDexCreatorFeeConfig
610
669
  > {
611
670
  // Program address.
612
671
  const programAddress = SEND_LAUNCHPAD_PROGRAM_ADDRESS;
@@ -633,7 +692,7 @@ export function getMigrateInstruction<
633
692
  nexusProgram: { value: null, isWritable: false },
634
693
  creatorFeeConfig: {
635
694
  value: input.creatorFeeConfig ?? null,
636
- isWritable: false,
695
+ isWritable: true,
637
696
  },
638
697
  baseTokenProgram: { value: null, isWritable: false },
639
698
  quoteTokenProgram: {
@@ -644,6 +703,10 @@ export function getMigrateInstruction<
644
703
  systemProgram: { value: null, isWritable: false },
645
704
  eventAuthority: { value: null, isWritable: false },
646
705
  program: { value: null, isWritable: false },
706
+ dexCreatorFeeConfig: {
707
+ value: input.dexCreatorFeeConfig ?? null,
708
+ isWritable: true,
709
+ },
647
710
  };
648
711
  const accounts = originalAccounts as Record<
649
712
  keyof typeof originalAccounts,
@@ -714,6 +777,7 @@ export function getMigrateInstruction<
714
777
  getAccountMeta('systemProgram', accounts.systemProgram),
715
778
  getAccountMeta('eventAuthority', accounts.eventAuthority),
716
779
  getAccountMeta('program', accounts.program),
780
+ getAccountMeta('dexCreatorFeeConfig', accounts.dexCreatorFeeConfig),
717
781
  ],
718
782
  data: getMigrateInstructionDataEncoder().encode({}),
719
783
  programAddress,
@@ -740,7 +804,8 @@ export function getMigrateInstruction<
740
804
  'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
741
805
  '11111111111111111111111111111111',
742
806
  'FJVebqCthxH6JM8vvkJb7yRYA7Emsib1C1vu4ZePSP3T',
743
- '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP'
807
+ '5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP',
808
+ TAccountDexCreatorFeeConfig
744
809
  >);
745
810
  }
746
811
 
@@ -772,6 +837,7 @@ export type ParsedMigrateInstruction<
772
837
  systemProgram: TAccountMetas[19];
773
838
  eventAuthority: TAccountMetas[20];
774
839
  program: TAccountMetas[21];
840
+ dexCreatorFeeConfig: TAccountMetas[22];
775
841
  };
776
842
  data: MigrateInstructionData;
777
843
  };
@@ -792,12 +858,12 @@ export function parseMigrateInstruction<
792
858
  error.name = 'InstructionDiscriminatorMismatchError';
793
859
  throw error;
794
860
  }
795
- if (instruction.accounts.length < 22) {
861
+ if (instruction.accounts.length < 23) {
796
862
  throw new SolanaError(
797
863
  SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
798
864
  {
799
865
  actualAccountMetas: instruction.accounts.length,
800
- expectedAccountMetas: 22,
866
+ expectedAccountMetas: 23,
801
867
  },
802
868
  );
803
869
  }
@@ -834,6 +900,7 @@ export function parseMigrateInstruction<
834
900
  systemProgram: getNextAccount(),
835
901
  eventAuthority: getNextAccount(),
836
902
  program: getNextAccount(),
903
+ dexCreatorFeeConfig: getNextAccount(),
837
904
  },
838
905
  data: getMigrateInstructionDataDecoder().decode(instruction.data),
839
906
  };
@@ -0,0 +1,39 @@
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 {
10
+ getAddressEncoder,
11
+ getBytesEncoder,
12
+ getProgramDerivedAddress,
13
+ type Address,
14
+ type ProgramDerivedAddress,
15
+ } from '@solana/kit';
16
+ import { SEND_LAUNCHPAD_PROGRAM_ADDRESS } from '../programs/index.js';
17
+
18
+ export type CreatorFeeConfigSeeds = {
19
+ baseMint: Address;
20
+ quoteMint: Address;
21
+ };
22
+
23
+ export async function findCreatorFeeConfigPda(
24
+ seeds: CreatorFeeConfigSeeds,
25
+ ): Promise<ProgramDerivedAddress> {
26
+ return await getProgramDerivedAddress({
27
+ programAddress: SEND_LAUNCHPAD_PROGRAM_ADDRESS,
28
+ seeds: [
29
+ getBytesEncoder().encode(
30
+ new Uint8Array([
31
+ 99, 114, 101, 97, 116, 111, 114, 95, 102, 101, 101, 95, 99,
32
+ 111, 110, 102, 105, 103,
33
+ ]),
34
+ ),
35
+ getAddressEncoder().encode(seeds.baseMint),
36
+ getAddressEncoder().encode(seeds.quoteMint),
37
+ ],
38
+ });
39
+ }
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  export * from './bondingCurve.js';
10
+ export * from './creatorFeeConfig.js';
10
11
  export * from './eventAuthority.js';
11
12
  export * from './globalConfig.js';
12
13
  export * from './migrationAuthority.js';
@@ -76,6 +76,7 @@ import {
76
76
  } from '../instructions/index.js';
77
77
  import {
78
78
  findBondingCurvePda,
79
+ findCreatorFeeConfigPda,
79
80
  findEventAuthorityPda,
80
81
  findGlobalConfigPda,
81
82
  findMigrationAuthorityPda,
@@ -150,6 +151,7 @@ export type SendLaunchpadPluginInstructions = {
150
151
  export type SendLaunchpadPluginPdas = {
151
152
  bondingCurve: typeof findBondingCurvePda;
152
153
  eventAuthority: typeof findEventAuthorityPda;
154
+ creatorFeeConfig: typeof findCreatorFeeConfigPda;
153
155
  rewardAccrual: typeof findRewardAccrualPda;
154
156
  globalConfig: typeof findGlobalConfigPda;
155
157
  wsolRewardAccrual: typeof findWsolRewardAccrualPda;
@@ -299,6 +301,7 @@ export function sendLaunchpadProgram() {
299
301
  pdas: {
300
302
  bondingCurve: findBondingCurvePda,
301
303
  eventAuthority: findEventAuthorityPda,
304
+ creatorFeeConfig: findCreatorFeeConfigPda,
302
305
  rewardAccrual: findRewardAccrualPda,
303
306
  globalConfig: findGlobalConfigPda,
304
307
  wsolRewardAccrual: findWsolRewardAccrualPda,
@@ -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
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Address, Instruction, TransactionSigner } from '@solana/kit';
2
2
  import { TOKEN_2022_PROGRAM_ADDRESS } from '../constants.js';
3
3
  import { findAssociatedTokenPda } from '../utils/pda.js';
4
+ import { findCreatorFeeConfigPda as findDexCreatorFeeConfigPda } from '../dex/generated/pdas/creatorFeeConfig.js';
4
5
  import { findPoolPda } from '../dex/generated/pdas/pool.js';
5
6
  import { findLpMintPda } from '../dex/generated/pdas/lpMint.js';
6
7
  import { getMigrateInstructionAsync } from './generated/instructions/migrate.js';
@@ -9,8 +10,6 @@ export interface MigrateParams {
9
10
  caller: TransactionSigner;
10
11
  baseMint: Address;
11
12
  quoteMint: Address;
12
- /** `bondingCurve.creatorFeeConfig`; `migrate` rejects any other address. */
13
- creatorFeeConfig: Address;
14
13
  quoteTokenProgram: Address;
15
14
  }
16
15
 
@@ -19,7 +18,7 @@ export async function buildMigrateInstruction(
19
18
  ): Promise<Instruction> {
20
19
  const { quoteTokenProgram } = params;
21
20
 
22
- const [[pool], [lpMint]] = await Promise.all([
21
+ const [[pool], [lpMint], [dexCreatorFeeConfig]] = await Promise.all([
23
22
  findPoolPda({
24
23
  baseMint: params.baseMint,
25
24
  quoteMint: params.quoteMint,
@@ -28,6 +27,10 @@ export async function buildMigrateInstruction(
28
27
  baseMint: params.baseMint,
29
28
  quoteMint: params.quoteMint,
30
29
  }),
30
+ findDexCreatorFeeConfigPda({
31
+ baseMint: params.baseMint,
32
+ quoteMint: params.quoteMint,
33
+ }),
31
34
  ]);
32
35
 
33
36
  const [[poolBaseVault], [poolQuoteVault], [poolLpAccount]] =
@@ -45,7 +48,7 @@ export async function buildMigrateInstruction(
45
48
  caller: params.caller,
46
49
  baseMint: params.baseMint,
47
50
  quoteMint: params.quoteMint,
48
- creatorFeeConfig: params.creatorFeeConfig,
51
+ dexCreatorFeeConfig,
49
52
  poolBaseVault,
50
53
  poolQuoteVault,
51
54
  poolLpAccount,
@@ -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
  }),