@hadron-fi/sdk 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ // src/hadron.ts
2
+ import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3 } from "@solana/spl-token";
3
+
1
4
  // src/helpers/sol.ts
2
5
  import {
3
6
  SystemProgram
@@ -43,9 +46,38 @@ function createWsolAtaInstruction(user) {
43
46
  TOKEN_PROGRAM_ID
44
47
  );
45
48
  }
46
- function unwrapSolInstruction(user) {
49
+ function unwrapSolInstructions(user) {
47
50
  const ata = getAssociatedTokenAddressSync(NATIVE_MINT, user, false, TOKEN_PROGRAM_ID);
48
- return createCloseAccountInstruction(ata, user, user, [], TOKEN_PROGRAM_ID);
51
+ return [
52
+ createCloseAccountInstruction(ata, user, user, [], TOKEN_PROGRAM_ID),
53
+ createAssociatedTokenAccountIdempotentInstruction(
54
+ user,
55
+ ata,
56
+ user,
57
+ NATIVE_MINT,
58
+ TOKEN_PROGRAM_ID
59
+ )
60
+ ];
61
+ }
62
+ function buildFeeRecipientAtaIxs(payer, feeRecipient, mintX, mintY, tokenProgramX = TOKEN_PROGRAM_ID, tokenProgramY = TOKEN_PROGRAM_ID) {
63
+ const ataX = getAssociatedTokenAddressSync(mintX, feeRecipient, false, tokenProgramX);
64
+ const ataY = getAssociatedTokenAddressSync(mintY, feeRecipient, false, tokenProgramY);
65
+ return [
66
+ createAssociatedTokenAccountIdempotentInstruction(
67
+ payer,
68
+ ataX,
69
+ feeRecipient,
70
+ mintX,
71
+ tokenProgramX
72
+ ),
73
+ createAssociatedTokenAccountIdempotentInstruction(
74
+ payer,
75
+ ataY,
76
+ feeRecipient,
77
+ mintY,
78
+ tokenProgramY
79
+ )
80
+ ];
49
81
  }
50
82
 
51
83
  // src/constants/index.ts
@@ -1417,6 +1449,22 @@ var Hadron = class _Hadron {
1417
1449
  instructions.push(buildInitialize(payer, resolvedParams, programId));
1418
1450
  return { instructions, poolAddress, seed };
1419
1451
  }
1452
+ /**
1453
+ * Build idempotent create-ATA instructions for the fee recipient for both mints.
1454
+ *
1455
+ * These are no-ops on-chain if the ATAs already exist. Include them alongside
1456
+ * initialize or first deposit to ensure swaps don't fail due to missing fee ATAs.
1457
+ */
1458
+ static buildFeeRecipientAtaIxs(payer, feeRecipient, mintX, mintY, tokenProgramX, tokenProgramY) {
1459
+ return buildFeeRecipientAtaIxs(
1460
+ payer,
1461
+ feeRecipient,
1462
+ mintX,
1463
+ mintY,
1464
+ tokenProgramX ?? TOKEN_PROGRAM_ID3,
1465
+ tokenProgramY ?? TOKEN_PROGRAM_ID3
1466
+ );
1467
+ }
1420
1468
  /** Generate a random u64 seed. */
1421
1469
  static randomSeed() {
1422
1470
  const buf = new Uint8Array(8);
@@ -1797,7 +1845,7 @@ var Hadron = class _Hadron {
1797
1845
  }
1798
1846
  ixs.push(this.withdraw(user, params));
1799
1847
  if (hasSol) {
1800
- ixs.push(unwrapSolInstruction(user));
1848
+ ixs.push(...unwrapSolInstructions(user));
1801
1849
  }
1802
1850
  return ixs;
1803
1851
  }
@@ -1818,7 +1866,7 @@ var Hadron = class _Hadron {
1818
1866
  }
1819
1867
  ixs.push(this.swap(user, params));
1820
1868
  if (isNativeMint(outputMint)) {
1821
- ixs.push(unwrapSolInstruction(user));
1869
+ ixs.push(...unwrapSolInstructions(user));
1822
1870
  }
1823
1871
  return ixs;
1824
1872
  }
@@ -2387,9 +2435,9 @@ var HadronOrderbook = class _HadronOrderbook {
2387
2435
  import {
2388
2436
  getAssociatedTokenAddressSync as getAssociatedTokenAddressSync6,
2389
2437
  createAssociatedTokenAccountInstruction,
2390
- TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3
2438
+ TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID4
2391
2439
  } from "@solana/spl-token";
2392
- async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ID3, allowOwnerOffCurve = false) {
2440
+ async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ID4, allowOwnerOffCurve = false) {
2393
2441
  const address = getAssociatedTokenAddressSync6(
2394
2442
  mint,
2395
2443
  owner,
@@ -2451,6 +2499,7 @@ export {
2451
2499
  buildApplyCurveUpdates,
2452
2500
  buildClosePool,
2453
2501
  buildDeposit,
2502
+ buildFeeRecipientAtaIxs,
2454
2503
  buildInitialize,
2455
2504
  buildInitializeFeeConfig,
2456
2505
  buildInitializePoolFeeConfig,
@@ -2504,7 +2553,7 @@ export {
2504
2553
  spreadBpsToQ32,
2505
2554
  spreadQ32ToBps,
2506
2555
  toQ32,
2507
- unwrapSolInstruction,
2556
+ unwrapSolInstructions,
2508
2557
  wrapSolInstructions
2509
2558
  };
2510
2559
  //# sourceMappingURL=index.mjs.map