@gardenfi/core 2.3.1-beta.3 → 2.3.1-beta.4

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.
@@ -5,7 +5,7 @@ import { MatchedOrder } from '@gardenfi/orderbook';
5
5
 
6
6
  /**
7
7
  * A Relay is an endpoint that submits the transaction on-chain on one's behalf, paying any fees.
8
- * SolanaRelay is one such implementation performs the atomic swaps through a given relayer url.
8
+ * SolanaRelay is a unified implementation that performs atomic swaps for both SPL and native tokens.
9
9
  */
10
10
  export declare class SolanaRelay implements ISolanaHTLC {
11
11
  private provider;
@@ -13,37 +13,84 @@ export declare class SolanaRelay implements ISolanaHTLC {
13
13
  /**
14
14
  * The on-chain Program Derived Address (PDA) that facilitates this swap.
15
15
  * A PDA represents an on-chain memory space. It can store SOL too and is owned by a program (that derived it).
16
- * This PDA stores the swap state (initiator, redeemer, secrethash etc) on-chain and also escrows the SOL.
16
+ * This PDA stores the swap state (initiator, redeemer, secrethash etc) on-chain and also escrows the tokens/SOL.
17
17
  */
18
18
  private swapAccount?;
19
- private program;
19
+ private splProgram;
20
+ private nativeProgram;
20
21
  private relayer;
21
22
  /**
22
23
  * Creates a new instance of SolanaRelay.
23
24
  * @param {AnchorProvider} provider - An abstraction of RPC connection and a Wallet
24
25
  * @param {Url} endpoint - API endpoint of the relayer node
25
26
  * @param {string} relayer - On-chain address of the relayer in base58 format
27
+ * @param {string} splProgramAddress - On-chain address of the SPL token swap program
28
+ * @param {string} nativeProgramAddress - On-chain address of the native token swap program
26
29
  * @throws {Error} If any required parameters are missing or invalid
27
30
  */
28
- constructor(provider: AnchorProvider, url: Url, relayer: string, programAddress: string);
31
+ constructor(provider: AnchorProvider, url: Url, relayer: string, nativeProgramAddress: string, splProgramAddress: string);
29
32
  /**
30
- * Gets the on-chain address of the atomic swap program.
31
- * @returns {string} The program's on-chain address in base58 format
32
- * @throws {Error} If no program ID is found
33
+ * Gets the on-chain address of the current user's wallet.
34
+ * @returns {string} The wallet's on-chain address in base58 format
35
+ * @throws {Error} If no provider public key is found
33
36
  */
34
37
  get htlcActorAddress(): string;
35
38
  /**
36
- * Sends a transaction via the relayer.
39
+ * Determines if the given order is for a native Solana token (SOL).
40
+ * @param {MatchedOrder} order - The matched order to check
41
+ * @returns {boolean} True if it's a native token, false if it's an SPL token
42
+ * @private
43
+ */
44
+ private isNativeToken;
45
+ /**
46
+ * Sends a transaction via the relayer for SPL tokens.
47
+ * @param {web3.Transaction} transaction - The transaction to send
48
+ * @param {string} orderId - The order ID for tracking
49
+ * @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
50
+ * - Ok with the transaction ID on success
51
+ * - Err with an error message on failure
52
+ * @private
53
+ */
54
+ private sendSplViaRelayer;
55
+ /**
56
+ * Initiates a swap directly via HTLC (without relayer).
37
57
  * @param {web3.Transaction} transaction - The transaction to send
58
+ * @param {MatchedOrder} order - The matched order
38
59
  * @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
39
60
  * - Ok with the transaction ID on success
40
61
  * - Err with an error message on failure
41
62
  * @private
42
63
  */
43
- private sendViaRelayer;
44
64
  private initiateViaHTLC;
65
+ /**
66
+ * Creates a PDA (Program Derived Address) for the swap account.
67
+ * @param {Buffer} secretHash - The secret hash buffer
68
+ * @param {web3.PublicKey} programId - The program ID to use for PDA derivation
69
+ * @returns {web3.PublicKey} The derived PDA
70
+ * @private
71
+ */
72
+ private createSwapPDA;
73
+ /**
74
+ * Initiates a swap for SPL tokens.
75
+ * @param {MatchedOrder} order - The matched order containing swap details
76
+ * @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
77
+ * - Ok with the transaction ID on success
78
+ * - Err with an error message on failure
79
+ * @private
80
+ */
81
+ private initiateSplSwap;
82
+ /**
83
+ * Initiates a swap for native tokens (SOL).
84
+ * @param {MatchedOrder} order - The matched order containing swap details
85
+ * @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
86
+ * - Ok with the transaction ID on success
87
+ * - Err with an error message on failure
88
+ * @private
89
+ */
90
+ private initiateNativeSwap;
45
91
  /**
46
92
  * Initiates a swap by creating a new swap account and locking funds.
93
+ * Automatically detects whether to use SPL or native token handling.
47
94
  * @param {MatchedOrder} order - The matched order containing swap details
48
95
  * @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
49
96
  * - Ok with the transaction ID on success
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/core",
3
- "version": "2.3.1-beta.3",
3
+ "version": "2.3.1-beta.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -27,8 +27,9 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@coral-xyz/anchor": "^0.30.1",
30
- "@gardenfi/orderbook": "2.3.1",
31
- "@gardenfi/utils": "2.3.1",
30
+ "@gardenfi/orderbook": "2.3.1-beta.2",
31
+ "@gardenfi/utils": "2.3.0",
32
+ "@solana/spl-token": "^0.4.13",
32
33
  "bignumber.js": "^9.1.2",
33
34
  "bip32": "^4.0.0",
34
35
  "bip39": "^3.1.0",