@liquid-af/sdk 0.3.0 → 0.4.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 (74) hide show
  1. package/dist/accounts/liquid.d.ts +2 -3
  2. package/dist/accounts/liquid.d.ts.map +1 -1
  3. package/dist/accounts/liquid.js +3 -4
  4. package/dist/accounts/liquid.js.map +1 -1
  5. package/dist/client.d.ts +4 -4
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +6 -6
  8. package/dist/client.js.map +1 -1
  9. package/dist/helpers/preview.d.ts.map +1 -1
  10. package/dist/helpers/preview.js +1 -1
  11. package/dist/helpers/preview.js.map +1 -1
  12. package/dist/idl/index.d.ts +1 -0
  13. package/dist/idl/index.d.ts.map +1 -1
  14. package/dist/idl/index.js +15 -4
  15. package/dist/idl/index.js.map +1 -1
  16. package/dist/idl/liquid.d.ts +0 -20
  17. package/dist/idl/liquid.d.ts.map +1 -1
  18. package/dist/idl/liquid.json +0 -20
  19. package/dist/idl/patch-idl.d.ts +10 -0
  20. package/dist/idl/patch-idl.d.ts.map +1 -0
  21. package/dist/idl/patch-idl.js +62 -0
  22. package/dist/idl/patch-idl.js.map +1 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/instructions/liquid.d.ts.map +1 -1
  28. package/dist/instructions/liquid.js +3 -3
  29. package/dist/instructions/liquid.js.map +1 -1
  30. package/dist/instructions/program-cache.d.ts.map +1 -1
  31. package/dist/instructions/program-cache.js +10 -6
  32. package/dist/instructions/program-cache.js.map +1 -1
  33. package/dist/pda/index.d.ts.map +1 -1
  34. package/dist/pda/index.js +1 -1
  35. package/dist/pda/index.js.map +1 -1
  36. package/dist/pda/liquid.d.ts +2 -3
  37. package/dist/pda/liquid.d.ts.map +1 -1
  38. package/dist/pda/liquid.js +3 -4
  39. package/dist/pda/liquid.js.map +1 -1
  40. package/package.json +4 -4
  41. package/src/accounts/liquid-fees.ts +2 -2
  42. package/src/accounts/liquid-state.ts +7 -7
  43. package/src/accounts/liquid-swap.ts +4 -4
  44. package/src/accounts/liquid.ts +7 -10
  45. package/src/client.ts +33 -36
  46. package/src/config.ts +10 -10
  47. package/src/errors.ts +6 -6
  48. package/src/events/parser.ts +5 -5
  49. package/src/helpers/preview.ts +31 -32
  50. package/src/helpers/user.ts +1 -1
  51. package/src/idl/index.ts +31 -8
  52. package/src/idl/liquid.json +0 -20
  53. package/src/idl/liquid.ts +0 -20
  54. package/src/idl/patch-idl.ts +80 -0
  55. package/src/index.ts +1 -0
  56. package/src/instructions/liquid-fees.ts +14 -14
  57. package/src/instructions/liquid-state.ts +4 -4
  58. package/src/instructions/liquid-swap.ts +18 -18
  59. package/src/instructions/liquid.ts +47 -50
  60. package/src/instructions/program-cache.ts +18 -9
  61. package/src/math/amm.ts +3 -3
  62. package/src/math/bonding-curve.ts +6 -6
  63. package/src/math/fees.ts +9 -9
  64. package/src/math/tiered-fees.ts +5 -5
  65. package/src/oracle.ts +3 -3
  66. package/src/pda/index.ts +27 -28
  67. package/src/pda/liquid-fees.ts +6 -6
  68. package/src/pda/liquid-state.ts +13 -13
  69. package/src/pda/liquid-swap.ts +16 -16
  70. package/src/pda/liquid.ts +17 -19
  71. package/src/provider.ts +2 -2
  72. package/src/transaction/builder.ts +4 -4
  73. package/src/transaction/send.ts +4 -4
  74. package/src/types.ts +2 -2
@@ -16,7 +16,7 @@ import { getLiquidProgram } from "../idl/index.js";
16
16
  */
17
17
  export async function fetchLiquidGlobalConfig(
18
18
  connection: Connection,
19
- config: LiquidConfig
19
+ config: LiquidConfig,
20
20
  ) {
21
21
  const program = getLiquidProgram(connection, config);
22
22
  const [pda] = getLiquidGlobalConfigPDA(config.liquidProgramId);
@@ -34,7 +34,7 @@ export async function fetchLiquidGlobalConfig(
34
34
  export async function fetchNativeBondingCurve(
35
35
  connection: Connection,
36
36
  mint: PublicKey,
37
- config: LiquidConfig
37
+ config: LiquidConfig,
38
38
  ) {
39
39
  const program = getLiquidProgram(connection, config);
40
40
  const [pda] = getBondingCurvePDA(mint, config.liquidProgramId);
@@ -52,32 +52,29 @@ export async function fetchNativeBondingCurve(
52
52
  export async function fetchNativeBondingCurveByAddress(
53
53
  connection: Connection,
54
54
  bondingCurveAddress: PublicKey,
55
- config: LiquidConfig
55
+ config: LiquidConfig,
56
56
  ) {
57
57
  const program = getLiquidProgram(connection, config);
58
58
  return program.account.nativeBondingCurve.fetch(bondingCurveAddress);
59
59
  }
60
60
 
61
61
  /**
62
- * Fetches a token bonding curve account by mint and quote mint addresses.
62
+ * Fetches a token bonding curve account by mint address.
63
63
  *
64
64
  * @param connection - Solana RPC connection
65
65
  * @param mint - Token mint address (base token)
66
- * @param quoteMint - Quote token mint address (e.g., USDC)
67
66
  * @param config - Liquid protocol configuration
68
67
  * @returns The deserialized token bonding curve account
69
68
  */
70
69
  export async function fetchStableBondingCurve(
71
70
  connection: Connection,
72
71
  mint: PublicKey,
73
- quoteMint: PublicKey,
74
- config: LiquidConfig
72
+ config: LiquidConfig,
75
73
  ) {
76
74
  const program = getLiquidProgram(connection, config);
77
75
  const [pda] = getStableBondingCurvePDA(
78
76
  mint,
79
- quoteMint,
80
- config.liquidProgramId
77
+ config.liquidProgramId,
81
78
  );
82
79
  return program.account.stableBondingCurve.fetch(pda);
83
80
  }
@@ -93,7 +90,7 @@ export async function fetchStableBondingCurve(
93
90
  export async function fetchStableBondingCurveByAddress(
94
91
  connection: Connection,
95
92
  stableBondingCurveAddress: PublicKey,
96
- config: LiquidConfig
93
+ config: LiquidConfig,
97
94
  ) {
98
95
  const program = getLiquidProgram(connection, config);
99
96
  return program.account.stableBondingCurve.fetch(stableBondingCurveAddress);
package/src/client.ts CHANGED
@@ -514,21 +514,21 @@ export class LiquidClient {
514
514
  const [poolAddress] = getPoolPDA(
515
515
  params.baseMint,
516
516
  quoteMint,
517
- this.config.liquidSwapProgramId
517
+ this.config.liquidSwapProgramId,
518
518
  );
519
519
  const [lpMint] = getPoolLpMintPDA(
520
520
  poolAddress,
521
- this.config.liquidSwapProgramId
521
+ this.config.liquidSwapProgramId,
522
522
  );
523
523
  const [baseVault] = getPoolVaultPDA(
524
524
  poolAddress,
525
525
  params.baseMint,
526
- this.config.liquidSwapProgramId
526
+ this.config.liquidSwapProgramId,
527
527
  );
528
528
  const [quoteVault] = getPoolVaultPDA(
529
529
  poolAddress,
530
530
  quoteMint,
531
- this.config.liquidSwapProgramId
531
+ this.config.liquidSwapProgramId,
532
532
  );
533
533
 
534
534
  const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
@@ -576,21 +576,21 @@ export class LiquidClient {
576
576
  const [poolAddress] = getPoolPDA(
577
577
  params.baseMint,
578
578
  quoteMint,
579
- this.config.liquidSwapProgramId
579
+ this.config.liquidSwapProgramId,
580
580
  );
581
581
  const [lpMint] = getPoolLpMintPDA(
582
582
  poolAddress,
583
- this.config.liquidSwapProgramId
583
+ this.config.liquidSwapProgramId,
584
584
  );
585
585
  const [baseVault] = getPoolVaultPDA(
586
586
  poolAddress,
587
587
  params.baseMint,
588
- this.config.liquidSwapProgramId
588
+ this.config.liquidSwapProgramId,
589
589
  );
590
590
  const [quoteVault] = getPoolVaultPDA(
591
591
  poolAddress,
592
592
  quoteMint,
593
- this.config.liquidSwapProgramId
593
+ this.config.liquidSwapProgramId,
594
594
  );
595
595
 
596
596
  const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
@@ -752,17 +752,16 @@ export class LiquidClient {
752
752
  return fetchNativeBondingCurveByAddressFn(
753
753
  this.connection,
754
754
  address,
755
- this.config
755
+ this.config,
756
756
  );
757
757
  }
758
758
 
759
- /** Fetches a stable bonding curve account by token mint and quote mint. */
760
- fetchStableBondingCurve(mint: PublicKey, quoteMint: PublicKey) {
759
+ /** Fetches a stable bonding curve account by token mint. */
760
+ fetchStableBondingCurve(mint: PublicKey) {
761
761
  return fetchStableBondingCurveFn(
762
762
  this.connection,
763
763
  mint,
764
- quoteMint,
765
- this.config
764
+ this.config,
766
765
  );
767
766
  }
768
767
 
@@ -771,7 +770,7 @@ export class LiquidClient {
771
770
  return fetchStableBondingCurveByAddressFn(
772
771
  this.connection,
773
772
  address,
774
- this.config
773
+ this.config,
775
774
  );
776
775
  }
777
776
 
@@ -786,7 +785,7 @@ export class LiquidClient {
786
785
  this.connection,
787
786
  baseMint,
788
787
  quoteMint,
789
- this.config
788
+ this.config,
790
789
  );
791
790
  }
792
791
 
@@ -800,7 +799,7 @@ export class LiquidClient {
800
799
  return fetchObservationStateFn(
801
800
  this.connection,
802
801
  poolAddress,
803
- this.config
802
+ this.config,
804
803
  );
805
804
  }
806
805
 
@@ -860,14 +859,14 @@ export class LiquidClient {
860
859
  previewBuyOnCurve(
861
860
  mint: PublicKey,
862
861
  amountInQuote: BN,
863
- options: CurveAsyncOptions
862
+ options: CurveAsyncOptions,
864
863
  ): Promise<BuyCurvePreview> {
865
864
  return previewBuyOnCurveFn(
866
865
  this.connection,
867
866
  mint,
868
867
  amountInQuote,
869
868
  this.config,
870
- options
869
+ options,
871
870
  );
872
871
  }
873
872
 
@@ -882,14 +881,14 @@ export class LiquidClient {
882
881
  previewSellOnCurve(
883
882
  mint: PublicKey,
884
883
  amountInTokens: BN,
885
- options: CurveAsyncOptions
884
+ options: CurveAsyncOptions,
886
885
  ): Promise<SellCurvePreview> {
887
886
  return previewSellOnCurveFn(
888
887
  this.connection,
889
888
  mint,
890
889
  amountInTokens,
891
890
  this.config,
892
- options
891
+ options,
893
892
  );
894
893
  }
895
894
 
@@ -898,7 +897,7 @@ export class LiquidClient {
898
897
  baseMint: PublicKey,
899
898
  quoteMint: PublicKey,
900
899
  amountIn: BN,
901
- options?: { prefetched?: SwapPrefetchedState }
900
+ options?: { prefetched?: SwapPrefetchedState },
902
901
  ): Promise<SwapPreview> {
903
902
  return previewSwapSellFn(
904
903
  this.connection,
@@ -906,7 +905,7 @@ export class LiquidClient {
906
905
  quoteMint,
907
906
  amountIn,
908
907
  this.config,
909
- options
908
+ options,
910
909
  );
911
910
  }
912
911
 
@@ -915,7 +914,7 @@ export class LiquidClient {
915
914
  baseMint: PublicKey,
916
915
  quoteMint: PublicKey,
917
916
  amountOut: BN,
918
- options?: { prefetched?: SwapPrefetchedState }
917
+ options?: { prefetched?: SwapPrefetchedState },
919
918
  ): Promise<SwapPreview> {
920
919
  return previewSwapBuyFn(
921
920
  this.connection,
@@ -923,7 +922,7 @@ export class LiquidClient {
923
922
  quoteMint,
924
923
  amountOut,
925
924
  this.config,
926
- options
925
+ options,
927
926
  );
928
927
  }
929
928
 
@@ -932,15 +931,13 @@ export class LiquidClient {
932
931
  return getBondingCurvePDA(mint, this.config.liquidProgramId);
933
932
  }
934
933
 
935
- /** Derives the stable bonding curve PDA for a token mint and quote mint. */
934
+ /** Derives the stable bonding curve PDA for a token mint. */
936
935
  getStableBondingCurvePDA(
937
936
  mint: PublicKey,
938
- quoteMint: PublicKey
939
937
  ): [PublicKey, number] {
940
938
  return getStableBondingCurvePDA(
941
939
  mint,
942
- quoteMint,
943
- this.config.liquidProgramId
940
+ this.config.liquidProgramId,
944
941
  );
945
942
  }
946
943
 
@@ -948,7 +945,7 @@ export class LiquidClient {
948
945
  getBondingCurveSolVaultPDA(bondingCurve: PublicKey): [PublicKey, number] {
949
946
  return getBondingCurveSolVaultPDA(
950
947
  bondingCurve,
951
- this.config.liquidProgramId
948
+ this.config.liquidProgramId,
952
949
  );
953
950
  }
954
951
 
@@ -965,7 +962,7 @@ export class LiquidClient {
965
962
  /** Derives the pool state PDA for a token pair. */
966
963
  getPoolPDA(
967
964
  baseMint: PublicKey,
968
- quoteMint: PublicKey = WSOL_MINT
965
+ quoteMint: PublicKey = WSOL_MINT,
969
966
  ): [PublicKey, number] {
970
967
  return getPoolPDA(baseMint, quoteMint, this.config.liquidSwapProgramId);
971
968
  }
@@ -978,12 +975,12 @@ export class LiquidClient {
978
975
  /** Derives the pool vault PDA for a specific token. */
979
976
  getPoolVaultPDA(
980
977
  poolState: PublicKey,
981
- mint: PublicKey
978
+ mint: PublicKey,
982
979
  ): [PublicKey, number] {
983
980
  return getPoolVaultPDA(
984
981
  poolState,
985
982
  mint,
986
- this.config.liquidSwapProgramId
983
+ this.config.liquidSwapProgramId,
987
984
  );
988
985
  }
989
986
 
@@ -1005,12 +1002,12 @@ export class LiquidClient {
1005
1002
  /** Derives the recipient vault PDA for a specific recipient within a fee config. */
1006
1003
  getRecipientVaultPDA(
1007
1004
  feeConfig: PublicKey,
1008
- recipient: PublicKey
1005
+ recipient: PublicKey,
1009
1006
  ): [PublicKey, number] {
1010
1007
  return getRecipientVaultPDA(
1011
1008
  feeConfig,
1012
1009
  recipient,
1013
- this.config.liquidFeesProgramId
1010
+ this.config.liquidFeesProgramId,
1014
1011
  );
1015
1012
  }
1016
1013
 
@@ -1029,7 +1026,7 @@ export class LiquidClient {
1029
1026
  return getUserSnapshotPDA(
1030
1027
  user,
1031
1028
  index,
1032
- this.config.liquidStateProgramId
1029
+ this.config.liquidStateProgramId,
1033
1030
  );
1034
1031
  }
1035
1032
 
@@ -1064,7 +1061,7 @@ export class LiquidClient {
1064
1061
  */
1065
1062
  buildTransaction(
1066
1063
  instructions: TransactionInstruction[],
1067
- options: BuildTransactionOptions
1064
+ options: BuildTransactionOptions,
1068
1065
  ): Promise<Transaction> {
1069
1066
  return buildTransactionFn(this.connection, instructions, options);
1070
1067
  }
package/src/config.ts CHANGED
@@ -17,32 +17,32 @@ export interface LiquidConfig {
17
17
  /** Mainnet program IDs */
18
18
  export const MAINNET_CONFIG: LiquidConfig = {
19
19
  liquidProgramId: new PublicKey(
20
- "LiquidsqH2a9gsPRf1M2QFhFqfLXWYTDZGzbsNQCDux"
20
+ "LiquidsqH2a9gsPRf1M2QFhFqfLXWYTDZGzbsNQCDux",
21
21
  ),
22
22
  liquidSwapProgramId: new PublicKey(
23
- "SwapMXcpJdXgnFG9BZak2fBZUiNeR2qYxzexF2ZxdW8"
23
+ "SwapMXcpJdXgnFG9BZak2fBZUiNeR2qYxzexF2ZxdW8",
24
24
  ),
25
25
  liquidFeesProgramId: new PublicKey(
26
- "FeesZQLb1xTeZbvaFRGnqzrZYzzmQtwhTYKQphbNGQru"
26
+ "FeesZQLb1xTeZbvaFRGnqzrZYzzmQtwhTYKQphbNGQru",
27
27
  ),
28
28
  liquidStateProgramId: new PublicKey(
29
- "State3HtEfi7cXdsTpAtRoBvrij8zSFCiGTAVWmYH2d"
29
+ "State3HtEfi7cXdsTpAtRoBvrij8zSFCiGTAVWmYH2d",
30
30
  ),
31
31
  } as const;
32
32
 
33
33
  /** Devnet program IDs (liquid differs, others same as mainnet) */
34
34
  export const DEVNET_CONFIG: LiquidConfig = {
35
35
  liquidProgramId: new PublicKey(
36
- "76sZav3FHaGLQmo2wHpyboeEk3Bc7wbL6bPibaSyhxnt"
36
+ "76sZav3FHaGLQmo2wHpyboeEk3Bc7wbL6bPibaSyhxnt",
37
37
  ),
38
38
  liquidSwapProgramId: new PublicKey(
39
- "DoBPPSQETr2xK5fKeTDR8wJ2Y4aTjtDbNwd9K72whhQB"
39
+ "DoBPPSQETr2xK5fKeTDR8wJ2Y4aTjtDbNwd9K72whhQB",
40
40
  ),
41
41
  liquidFeesProgramId: new PublicKey(
42
- "3iFrDQxt6ZQT5eTyoHSpdq9hpyj9QmXDjTNEopGYpvTh"
42
+ "3iFrDQxt6ZQT5eTyoHSpdq9hpyj9QmXDjTNEopGYpvTh",
43
43
  ),
44
44
  liquidStateProgramId: new PublicKey(
45
- "9ZcKPa3HAEVEKxwFX8fYD56ZJCKPEQgqjgr9rfUvtwKJ"
45
+ "9ZcKPa3HAEVEKxwFX8fYD56ZJCKPEQgqjgr9rfUvtwKJ",
46
46
  ),
47
47
  } as const;
48
48
 
@@ -51,12 +51,12 @@ export const LOCALNET_CONFIG: LiquidConfig = { ...MAINNET_CONFIG } as const;
51
51
 
52
52
  /** WSOL mint address */
53
53
  export const WSOL_MINT = new PublicKey(
54
- "So11111111111111111111111111111111111111112"
54
+ "So11111111111111111111111111111111111111112",
55
55
  );
56
56
 
57
57
  /** Pyth Solana Receiver program ID (same across all networks and mock) */
58
58
  export const PYTH_RECEIVER_PROGRAM_ID = new PublicKey(
59
- "rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ"
59
+ "rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ",
60
60
  );
61
61
 
62
62
  /** Basis points denominator (10,000 = 100%) */
package/src/errors.ts CHANGED
@@ -30,7 +30,7 @@ export class LiquidError extends Error {
30
30
  constructor(
31
31
  readonly code: LiquidErrorCode,
32
32
  message: string,
33
- readonly cause?: unknown
33
+ readonly cause?: unknown,
34
34
  ) {
35
35
  super(message);
36
36
  }
@@ -58,7 +58,7 @@ export class LiquidError extends Error {
58
58
  return new LiquidError(
59
59
  LiquidErrorCode.AccountNotFound,
60
60
  msg,
61
- err
61
+ err,
62
62
  );
63
63
  }
64
64
 
@@ -66,7 +66,7 @@ export class LiquidError extends Error {
66
66
  return new LiquidError(
67
67
  LiquidErrorCode.TransactionTimeout,
68
68
  msg,
69
- err
69
+ err,
70
70
  );
71
71
  }
72
72
 
@@ -74,21 +74,21 @@ export class LiquidError extends Error {
74
74
  return new LiquidError(
75
75
  LiquidErrorCode.SimulationFailed,
76
76
  msg,
77
- err
77
+ err,
78
78
  );
79
79
  }
80
80
 
81
81
  return new LiquidError(
82
82
  LiquidErrorCode.TransactionBuildFailed,
83
83
  msg,
84
- err
84
+ err,
85
85
  );
86
86
  }
87
87
 
88
88
  return new LiquidError(
89
89
  LiquidErrorCode.TransactionBuildFailed,
90
90
  String(err),
91
- err
91
+ err,
92
92
  );
93
93
  }
94
94
  }
@@ -15,11 +15,11 @@ export interface ParsedEvent<T = unknown> {
15
15
  */
16
16
  export const parseTransactionEvents = (
17
17
  logs: string[],
18
- program: Program
18
+ program: Program,
19
19
  ): ParsedEvent[] => {
20
20
  const parser = new EventParser(
21
21
  program.programId,
22
- new BorshCoder(program.idl)
22
+ new BorshCoder(program.idl),
23
23
  );
24
24
  const events: ParsedEvent[] = [];
25
25
  const generator = parser.parseLogs(logs);
@@ -41,7 +41,7 @@ export const parseTransactionEvents = (
41
41
  export const addEventListener = <T>(
42
42
  program: Program,
43
43
  eventName: string,
44
- callback: (event: T) => void
44
+ callback: (event: T) => void,
45
45
  ): number => {
46
46
  return program.addEventListener(eventName, (data: T) => {
47
47
  callback(data);
@@ -64,7 +64,7 @@ export async function waitForEvent<TEvent, TResult = string>(
64
64
  program: Program<any>,
65
65
  eventName: string,
66
66
  trigger: () => Promise<TResult>,
67
- timeoutMs = 5000
67
+ timeoutMs = 5000,
68
68
  ): Promise<{ result: TResult; event: TEvent }> {
69
69
  let eventData: TEvent | null = null;
70
70
  const listenerId = program.addEventListener(eventName, (data: TEvent) => {
@@ -79,7 +79,7 @@ export async function waitForEvent<TEvent, TResult = string>(
79
79
  await program.removeEventListener(listenerId);
80
80
  if (!eventData) {
81
81
  throw new Error(
82
- `Event '${eventName}' not received within ${timeoutMs}ms`
82
+ `Event '${eventName}' not received within ${timeoutMs}ms`,
83
83
  );
84
84
  }
85
85
  return { result, event: eventData };