@gardenfi/core 2.4.6 → 2.5.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.
- package/dist/{ccip-zRBTY1vL.cjs → ccip-D9S6QM7J.cjs} +1 -1
- package/dist/{ccip-ZkIgcVu1.js → ccip-DW9K4PmQ.js} +1 -1
- package/dist/index-9VBMeQEM.cjs +105 -0
- package/dist/index-BsWv07Gh.js +31911 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/src/lib/constants.d.ts +13 -2
- package/dist/src/lib/evm/htlc/evmHTLC.d.ts +1567 -3804
- package/dist/src/lib/garden/garden.d.ts +4 -0
- package/dist/src/lib/garden/garden.types.d.ts +13 -1
- package/dist/src/lib/solana/idl/spl/solana_spl_swaps.d.ts +637 -0
- package/dist/src/lib/solana/idl/spl/solana_spl_swaps.json.d.ts +633 -0
- package/dist/src/lib/solana/relayer/solanaRelay.d.ts +59 -10
- package/dist/src/lib/sui/htlc/suiHTLC.d.ts +34 -0
- package/dist/src/lib/sui/relay/suiRelay.d.ts +17 -0
- package/dist/src/lib/sui/suiHTLC.types.d.ts +28 -0
- package/package.json +10 -5
- package/dist/index-BcHwWFv2.js +0 -24364
- package/dist/index-DpRp0W1D.cjs +0 -99
- /package/dist/src/lib/solana/idl/{solana_native_swaps.d.ts → native/solana_native_swaps.d.ts} +0 -0
- /package/dist/src/lib/solana/idl/{solana_native_swaps.json.d.ts → native/solana_native_swaps.json.d.ts} +0 -0
|
@@ -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
|
|
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,86 @@ 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
|
-
private
|
|
19
|
-
private
|
|
18
|
+
private splProgram?;
|
|
19
|
+
private nativeProgram?;
|
|
20
20
|
private relayer;
|
|
21
21
|
/**
|
|
22
22
|
* Creates a new instance of SolanaRelay.
|
|
23
23
|
* @param {AnchorProvider} provider - An abstraction of RPC connection and a Wallet
|
|
24
24
|
* @param {Url} endpoint - API endpoint of the relayer node
|
|
25
25
|
* @param {string} relayer - On-chain address of the relayer in base58 format
|
|
26
|
+
* @param {string} splProgramAddress - On-chain address of the SPL token swap program
|
|
27
|
+
* @param {string} nativeProgramAddress - On-chain address of the native token swap program
|
|
26
28
|
* @throws {Error} If any required parameters are missing or invalid
|
|
27
29
|
*/
|
|
28
|
-
constructor(provider: AnchorProvider, url: Url, relayer: string, programAddress:
|
|
30
|
+
constructor(provider: AnchorProvider, url: Url, relayer: string, programAddress: {
|
|
31
|
+
native?: string;
|
|
32
|
+
spl?: string;
|
|
33
|
+
});
|
|
29
34
|
/**
|
|
30
|
-
* Gets the on-chain address of the
|
|
31
|
-
* @returns {string} The
|
|
32
|
-
* @throws {Error} If no
|
|
35
|
+
* Gets the on-chain address of the current user's wallet.
|
|
36
|
+
* @returns {string} The wallet's on-chain address in base58 format
|
|
37
|
+
* @throws {Error} If no provider public key is found
|
|
33
38
|
*/
|
|
34
39
|
get htlcActorAddress(): string;
|
|
35
40
|
/**
|
|
36
|
-
*
|
|
41
|
+
* Determines if the given order is for a native Solana token (SOL).
|
|
42
|
+
* @param {MatchedOrder} order - The matched order to check
|
|
43
|
+
* @returns {boolean} True if it's a native token, false if it's an SPL token
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private isNativeToken;
|
|
47
|
+
/**
|
|
48
|
+
* Sends a transaction via the relayer for SPL tokens.
|
|
49
|
+
* @param {web3.Transaction} transaction - The transaction to send
|
|
50
|
+
* @param {string} orderId - The order ID for tracking
|
|
51
|
+
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
52
|
+
* - Ok with the transaction ID on success
|
|
53
|
+
* - Err with an error message on failure
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
private sendSplViaRelayer;
|
|
57
|
+
/**
|
|
58
|
+
* Initiates a swap directly via HTLC (without relayer).
|
|
37
59
|
* @param {web3.Transaction} transaction - The transaction to send
|
|
60
|
+
* @param {MatchedOrder} order - The matched order
|
|
38
61
|
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
39
62
|
* - Ok with the transaction ID on success
|
|
40
63
|
* - Err with an error message on failure
|
|
41
64
|
* @private
|
|
42
65
|
*/
|
|
43
|
-
private sendViaRelayer;
|
|
44
66
|
private initiateViaHTLC;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a PDA (Program Derived Address) for the swap account.
|
|
69
|
+
* @param {Buffer} secretHash - The secret hash buffer
|
|
70
|
+
* @param {web3.PublicKey} programId - The program ID to use for PDA derivation
|
|
71
|
+
* @returns {web3.PublicKey} The derived PDA
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
private createSwapPDA;
|
|
75
|
+
/**
|
|
76
|
+
* Initiates a swap for SPL tokens.
|
|
77
|
+
* @param {MatchedOrder} order - The matched order containing swap details
|
|
78
|
+
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
79
|
+
* - Ok with the transaction ID on success
|
|
80
|
+
* - Err with an error message on failure
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
private initiateSplSwap;
|
|
84
|
+
/**
|
|
85
|
+
* Initiates a swap for native tokens (SOL).
|
|
86
|
+
* @param {MatchedOrder} order - The matched order containing swap details
|
|
87
|
+
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
88
|
+
* - Ok with the transaction ID on success
|
|
89
|
+
* - Err with an error message on failure
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
private initiateNativeSwap;
|
|
45
93
|
/**
|
|
46
94
|
* Initiates a swap by creating a new swap account and locking funds.
|
|
95
|
+
* Automatically detects whether to use SPL or native token handling.
|
|
47
96
|
* @param {MatchedOrder} order - The matched order containing swap details
|
|
48
97
|
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
49
98
|
* - Ok with the transaction ID on success
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
2
|
+
import { AsyncResult, Network } from '@gardenfi/utils';
|
|
3
|
+
import { ISuiHTLC } from '../suiHTLC.types';
|
|
4
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
5
|
+
import { WalletWithRequiredFeatures } from '@mysten/wallet-standard';
|
|
6
|
+
|
|
7
|
+
export declare class SuiHTLC implements ISuiHTLC {
|
|
8
|
+
private client;
|
|
9
|
+
private account;
|
|
10
|
+
private network;
|
|
11
|
+
constructor(account: WalletWithRequiredFeatures | Ed25519Keypair, network: Network);
|
|
12
|
+
get htlcActorAddress(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Initiates the HTLC
|
|
15
|
+
* @param order Order to initiate HTLC for
|
|
16
|
+
* @returns Transaction ID
|
|
17
|
+
*/
|
|
18
|
+
initiate(order: MatchedOrder): AsyncResult<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Redeems the HTLC
|
|
21
|
+
*
|
|
22
|
+
* @param order Order to redeem HTLC for
|
|
23
|
+
* @param secret Secret to redeem HTLC with
|
|
24
|
+
* @returns Transaction ID
|
|
25
|
+
*/
|
|
26
|
+
redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Refunds the HTLC
|
|
29
|
+
*
|
|
30
|
+
* @param order Order to refund HTLC for
|
|
31
|
+
* @returns Refund transaction ID
|
|
32
|
+
*/
|
|
33
|
+
refund(order: MatchedOrder): AsyncResult<string, string>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
2
|
+
import { AsyncResult, Network, Url } from '@gardenfi/utils';
|
|
3
|
+
import { ISuiHTLC } from '../suiHTLC.types';
|
|
4
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
5
|
+
import { WalletWithRequiredFeatures } from '@mysten/wallet-standard';
|
|
6
|
+
|
|
7
|
+
export declare class SuiRelay implements ISuiHTLC {
|
|
8
|
+
private client;
|
|
9
|
+
private url;
|
|
10
|
+
private account;
|
|
11
|
+
private network;
|
|
12
|
+
constructor(relayerUrl: string | Url, account: WalletWithRequiredFeatures | Ed25519Keypair, network: Network);
|
|
13
|
+
get htlcActorAddress(): string;
|
|
14
|
+
initiate(order: MatchedOrder): AsyncResult<string, string>;
|
|
15
|
+
redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
|
|
16
|
+
refund(): AsyncResult<string, string>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
2
|
+
import { AsyncResult } from '@gardenfi/utils';
|
|
3
|
+
|
|
4
|
+
export interface ISuiHTLC {
|
|
5
|
+
/**
|
|
6
|
+
* The address of the HTLC actor.
|
|
7
|
+
*/
|
|
8
|
+
get htlcActorAddress(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Initiates the HTLC by sending funds to the HTLC contract.
|
|
11
|
+
* @param order - The matched order.
|
|
12
|
+
* @returns A promise resolving to the transaction hash of the initiation.
|
|
13
|
+
*/
|
|
14
|
+
initiate(order: MatchedOrder): AsyncResult<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Redeems funds from the HTLC contract to the actor's address.
|
|
17
|
+
* @param order - The matched order.
|
|
18
|
+
* @param secret - The secret required to unlock the htlc.
|
|
19
|
+
* @returns A promise resolving to the transaction hash of the redemption.
|
|
20
|
+
*/
|
|
21
|
+
redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Refunds funds from the HTLC contract back to the actor's address upon expiration.
|
|
24
|
+
* @param order - The matched order.
|
|
25
|
+
* @returns A promise resolving to the transaction hash of the refund.
|
|
26
|
+
*/
|
|
27
|
+
refund(order: MatchedOrder): AsyncResult<string, string>;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
7
7
|
"test": "vitest run",
|
|
8
|
-
"dev": "vite build --watch"
|
|
8
|
+
"dev": "vite build --watch",
|
|
9
|
+
"link": "yarn link"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"dist"
|
|
@@ -26,9 +27,13 @@
|
|
|
26
27
|
"registry": "https://registry.npmjs.org/"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@coral-xyz/anchor": "^0.
|
|
30
|
-
"@gardenfi/orderbook": "2.
|
|
31
|
-
"@gardenfi/utils": "2.
|
|
30
|
+
"@coral-xyz/anchor": "^0.31.1",
|
|
31
|
+
"@gardenfi/orderbook": "2.5.0",
|
|
32
|
+
"@gardenfi/utils": "2.5.0",
|
|
33
|
+
"@mysten/signers": "^0.3.4",
|
|
34
|
+
"@mysten/sui": "^1.37.1",
|
|
35
|
+
"@mysten/wallet-standard": "^0.16.9",
|
|
36
|
+
"@solana/spl-token": "^0.4.13",
|
|
32
37
|
"bignumber.js": "^9.1.2",
|
|
33
38
|
"bip32": "^4.0.0",
|
|
34
39
|
"bip39": "^3.1.0",
|