@gardenfi/core 2.5.2 → 2.5.3-beta.1
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/README.md +8 -10
- package/dist/{ccip-DW9K4PmQ.js → ccip-Blujdoyx.js} +1 -1
- package/dist/{ccip-D9S6QM7J.cjs → ccip-Dz1z3fd5.cjs} +1 -1
- package/dist/index-BVbDrfLG.cjs +106 -0
- package/dist/index-DZ7PA04Y.js +33072 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +32 -38
- package/dist/src/index.d.ts +9 -12
- package/dist/src/lib/bitcoin/API.d.ts +3 -1
- package/dist/src/lib/bitcoin/bitcoinHtlc.d.ts +98 -0
- package/dist/src/lib/bitcoin/bitcoinhtlc.types.d.ts +53 -0
- package/dist/src/lib/bitcoin/provider/provider.d.ts +2 -1
- package/dist/src/lib/bitcoin/wallet/abstractWallet.d.ts +1 -1
- package/dist/src/lib/bitcoin/wallet/wallet.d.ts +1 -1
- package/dist/src/lib/bitcoin/wallet/wallet.interface.d.ts +1 -1
- package/dist/src/lib/constants.d.ts +4 -8
- package/dist/src/lib/evm/htlc/evmHTLC.d.ts +69 -69
- package/dist/src/lib/evm/htlc.types.d.ts +4 -4
- package/dist/src/lib/evm/relay/evmRelay.d.ts +5 -4
- package/dist/src/lib/garden/cache/GardenCache.d.ts +45 -0
- package/dist/src/lib/garden/executor/executor.d.ts +26 -0
- package/dist/src/lib/garden/garden.d.ts +42 -52
- package/dist/src/lib/garden/garden.types.d.ts +68 -105
- package/dist/src/lib/garden/utils.d.ts +4 -0
- package/dist/src/lib/quote/quote.d.ts +4 -3
- package/dist/src/lib/quote/quote.types.d.ts +17 -8
- package/dist/src/lib/routeValidator/routeValidator.d.ts +30 -0
- package/dist/src/lib/solana/htlc/ISolanaHTLC.d.ts +4 -4
- package/dist/src/lib/solana/htlc/solanaHTLC.d.ts +7 -7
- package/dist/src/lib/solana/relayer/solanaRelay.d.ts +27 -35
- package/dist/src/lib/solana/solanaTypes.d.ts +3 -3
- package/dist/src/lib/starknet/htlc/starknetHTLC.d.ts +4 -4
- package/dist/src/lib/starknet/relay/starknetRelay.d.ts +8 -5
- package/dist/src/lib/starknet/starknetHTLC.types.d.ts +4 -4
- package/dist/src/lib/sui/htlc/suiHTLC.d.ts +7 -6
- package/dist/src/lib/sui/relay/suiRelay.d.ts +4 -3
- package/dist/src/lib/sui/suiHTLC.types.d.ts +4 -4
- package/dist/src/lib/switchOrAddNetwork.d.ts +4 -3
- package/dist/src/lib/utils.d.ts +29 -6
- package/package.json +5 -4
- package/dist/index-9VBMeQEM.cjs +0 -105
- package/dist/index-BsWv07Gh.js +0 -31911
- package/dist/src/lib/bitcoin/htlc.d.ts +0 -106
- package/dist/src/lib/blockNumberFetcher/blockNumber.d.ts +0 -15
- package/dist/src/lib/evm/relay/evmRelay.types.d.ts +0 -26
- package/dist/src/lib/garden/cache/executorCache.d.ts +0 -14
- package/dist/src/lib/orderStatus/orderStatusParser.d.ts +0 -37
- package/dist/src/lib/orderStatus/status.d.ts +0 -130
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { AsyncResult, Environment, EventBroker, IAuth, DigestKey } from '@gardenfi/utils';
|
|
1
|
+
import { AffiliateFee, AssetLike, BitcoinOrderResponse, BlockchainType, EvmOrderResponse, IOrderbook, Order, OrderAction, OrderStatus, SolanaOrderResponse, StarknetOrderResponse, SuiOrderResponse } from '@gardenfi/orderbook';
|
|
2
|
+
import { ApiKey, AsyncResult, IAuth, Network, DigestKey } from '@gardenfi/utils';
|
|
4
3
|
import { ISecretManager } from '../secretManager/secretManager.types';
|
|
5
4
|
import { IQuote } from '../quote/quote.types';
|
|
6
|
-
import { IBlockNumberFetcher } from '../blockNumberFetcher/blockNumber';
|
|
7
5
|
import { IEVMHTLC } from '../evm/htlc.types';
|
|
8
6
|
import { IStarknetHTLC } from '../starknet/starknetHTLC.types';
|
|
9
7
|
import { AccountInterface } from 'starknet';
|
|
10
8
|
import { WalletClient } from 'viem';
|
|
11
|
-
import { Api } from '../constants';
|
|
12
9
|
import { IBitcoinWallet } from '../bitcoin/wallet/wallet.interface';
|
|
13
10
|
import { ISolanaHTLC } from '../solana/htlc/ISolanaHTLC';
|
|
14
11
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
12
|
+
import { Api } from '../constants';
|
|
15
13
|
import { ISuiHTLC } from '../sui/suiHTLC.types';
|
|
16
14
|
import { WalletWithRequiredFeatures } from '@mysten/wallet-standard';
|
|
15
|
+
import { IBitcoinHTLC } from '../bitcoin/bitcoinhtlc.types';
|
|
16
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
17
17
|
|
|
18
18
|
export type SwapParams = {
|
|
19
19
|
/**
|
|
20
20
|
* Asset to be sent.
|
|
21
21
|
*/
|
|
22
|
-
fromAsset:
|
|
22
|
+
fromAsset: AssetLike;
|
|
23
23
|
/**
|
|
24
24
|
* Asset to be received.
|
|
25
25
|
*/
|
|
26
|
-
toAsset:
|
|
26
|
+
toAsset: AssetLike;
|
|
27
27
|
/**
|
|
28
28
|
* Amount in lowest denomination of the sendAsset.
|
|
29
29
|
*/
|
|
@@ -33,101 +33,52 @@ export type SwapParams = {
|
|
|
33
33
|
*/
|
|
34
34
|
receiveAmount: string;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
timelock?: number;
|
|
39
|
-
/**
|
|
40
|
-
* This will wait for the specified number of confirmations before redeeming the funds.
|
|
36
|
+
* Slippage for the order.
|
|
41
37
|
*/
|
|
42
|
-
|
|
38
|
+
slippage?: number;
|
|
43
39
|
/**
|
|
44
|
-
*
|
|
40
|
+
* Addresses for the order.
|
|
45
41
|
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Additional data for the order.
|
|
49
|
-
*/
|
|
50
|
-
additionalData: {
|
|
51
|
-
/**
|
|
52
|
-
* Get strategy id from the quote
|
|
53
|
-
*/
|
|
54
|
-
strategyId: string;
|
|
55
|
-
/**
|
|
56
|
-
* Provide btcAddress if the destination or source chain is bitcoin. This address is used as refund address if source chain is bitcoin, and as redeem address if destination chain is bitcoin.
|
|
57
|
-
*/
|
|
58
|
-
btcAddress?: string;
|
|
59
|
-
};
|
|
42
|
+
addresses?: Partial<Record<BlockchainType, string>>;
|
|
60
43
|
/**
|
|
61
44
|
* Integrator fee for the order.
|
|
62
45
|
*/
|
|
63
|
-
affiliateFee?:
|
|
46
|
+
affiliateFee?: AffiliateFee[];
|
|
64
47
|
};
|
|
65
|
-
export type OrderWithStatus =
|
|
48
|
+
export type OrderWithStatus = Order & {
|
|
66
49
|
status: OrderStatus;
|
|
67
50
|
};
|
|
68
51
|
export type GardenEvents = {
|
|
69
|
-
error: (order:
|
|
70
|
-
success: (order:
|
|
52
|
+
error: (order: Order, error: string) => void;
|
|
53
|
+
success: (order: Order, action: OrderAction, result: string) => void;
|
|
71
54
|
onPendingOrdersChanged: (orders: OrderWithStatus[]) => void;
|
|
72
55
|
log: (id: string, message: string) => void;
|
|
73
|
-
rbf: (order:
|
|
56
|
+
rbf: (order: Order, result: string) => void;
|
|
57
|
+
};
|
|
58
|
+
export type GardenEventEmitter = {
|
|
59
|
+
emit: <K extends keyof GardenEvents>(event: K, ...args: Parameters<GardenEvents[K]>) => void;
|
|
74
60
|
};
|
|
75
61
|
export type EventCallback = (...args: any[]) => void;
|
|
76
62
|
/**
|
|
77
63
|
* Interface representing the GardenJS library.
|
|
78
64
|
*/
|
|
79
|
-
export interface IGardenJS extends
|
|
65
|
+
export interface IGardenJS extends IOrderbook {
|
|
80
66
|
/**
|
|
81
67
|
* Create Order
|
|
82
68
|
* @param {SwapParams} params - The parameters for creating the order.
|
|
83
|
-
* @returns {AsyncResult<
|
|
84
|
-
*/
|
|
85
|
-
swap(params: SwapParams): AsyncResult<MatchedOrder, string>;
|
|
86
|
-
/**
|
|
87
|
-
* Execute an action.
|
|
88
|
-
* @returns {Promise<() => void>} A promise that resolves to a function to cancel the execution.
|
|
89
|
-
*/
|
|
90
|
-
execute(): Promise<() => void>;
|
|
91
|
-
/**
|
|
92
|
-
* The EVM relay.
|
|
93
|
-
* @readonly
|
|
94
|
-
*/
|
|
95
|
-
get evmHTLC(): IEVMHTLC | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* The Starknet relay.
|
|
98
|
-
* @readonly
|
|
99
|
-
*/
|
|
100
|
-
get starknetHTLC(): IStarknetHTLC | undefined;
|
|
101
|
-
/**
|
|
102
|
-
* The Solana relay.
|
|
103
|
-
* @readonly
|
|
104
|
-
*/
|
|
105
|
-
get solanaHTLC(): ISolanaHTLC | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* The Sui relay.
|
|
108
|
-
* @readonly
|
|
69
|
+
* @returns {AsyncResult<string, string>} The result of the swap operation.
|
|
109
70
|
*/
|
|
110
|
-
|
|
71
|
+
createSwap(params: SwapParams): AsyncResult<string, string>;
|
|
111
72
|
/**
|
|
112
73
|
* The current quote.
|
|
113
74
|
* @readonly
|
|
114
75
|
*/
|
|
115
76
|
get quote(): IQuote;
|
|
116
77
|
/**
|
|
117
|
-
*
|
|
78
|
+
* All HTLC modules at once.
|
|
118
79
|
* @readonly
|
|
119
80
|
*/
|
|
120
|
-
get
|
|
121
|
-
/**
|
|
122
|
-
* The orderbook.
|
|
123
|
-
* @readonly
|
|
124
|
-
*/
|
|
125
|
-
get orderbook(): IOrderbook;
|
|
126
|
-
/**
|
|
127
|
-
* The block number fetcher.
|
|
128
|
-
* @readonly
|
|
129
|
-
*/
|
|
130
|
-
get blockNumberFetcher(): IBlockNumberFetcher;
|
|
81
|
+
get htlcs(): GardenHTLCModules;
|
|
131
82
|
/**
|
|
132
83
|
* The secret manager.
|
|
133
84
|
* @readonly
|
|
@@ -142,7 +93,20 @@ export interface IGardenJS extends EventBroker<GardenEvents> {
|
|
|
142
93
|
* The digest key.
|
|
143
94
|
* @readonly
|
|
144
95
|
*/
|
|
145
|
-
get digestKey(): DigestKey;
|
|
96
|
+
get digestKey(): DigestKey | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The redeem service enabled.
|
|
99
|
+
* @readonly
|
|
100
|
+
*/
|
|
101
|
+
get redeemServiceEnabled(): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* The events.
|
|
104
|
+
*/
|
|
105
|
+
on<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
|
|
106
|
+
/**
|
|
107
|
+
* The events.
|
|
108
|
+
*/
|
|
109
|
+
off<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
|
|
146
110
|
}
|
|
147
111
|
export type OrderCacheValue = {
|
|
148
112
|
txHash: string;
|
|
@@ -150,51 +114,50 @@ export type OrderCacheValue = {
|
|
|
150
114
|
btcRedeemUTXO?: string;
|
|
151
115
|
};
|
|
152
116
|
export interface IOrderExecutorCache {
|
|
153
|
-
set(order:
|
|
154
|
-
get(order:
|
|
155
|
-
remove(order:
|
|
117
|
+
set(order: Order, action: OrderAction, txHash: string, utxo?: string): void;
|
|
118
|
+
get(order: Order, action: OrderAction): OrderCacheValue | null;
|
|
119
|
+
remove(order: Order, action: OrderAction): void;
|
|
156
120
|
}
|
|
157
|
-
export type ApiConfig =
|
|
158
|
-
|
|
121
|
+
export type ApiConfig = Network | (Partial<Api> & {
|
|
122
|
+
network: Network;
|
|
159
123
|
});
|
|
160
124
|
export type GardenCoreConfig = {
|
|
161
125
|
environment: ApiConfig;
|
|
162
|
-
|
|
126
|
+
apiKey: string | ApiKey;
|
|
127
|
+
digestKey?: string | DigestKey;
|
|
163
128
|
secretManager?: ISecretManager;
|
|
164
129
|
auth?: IAuth;
|
|
165
130
|
orderbook?: IOrderbook;
|
|
166
131
|
quote?: IQuote;
|
|
167
|
-
blockNumberFetcher?: IBlockNumberFetcher;
|
|
168
|
-
btcWallet?: IBitcoinWallet;
|
|
169
132
|
solanaProgramAddress?: {
|
|
170
133
|
native?: string;
|
|
171
134
|
spl?: string;
|
|
172
135
|
};
|
|
173
136
|
};
|
|
174
137
|
export type GardenHTLCModules = {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
};
|
|
138
|
+
evm?: IEVMHTLC;
|
|
139
|
+
starknet?: IStarknetHTLC;
|
|
140
|
+
solana?: ISolanaHTLC;
|
|
141
|
+
sui?: ISuiHTLC;
|
|
142
|
+
bitcoin?: IBitcoinHTLC;
|
|
181
143
|
};
|
|
182
144
|
export type GardenWalletModules = {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
145
|
+
evm?: WalletClient;
|
|
146
|
+
starknet?: AccountInterface;
|
|
147
|
+
solana?: AnchorProvider;
|
|
148
|
+
sui?: WalletWithRequiredFeatures | Ed25519Keypair;
|
|
149
|
+
bitcoin?: IBitcoinWallet;
|
|
150
|
+
};
|
|
151
|
+
export type GardenConfigWithWallets = GardenCoreConfig & {
|
|
152
|
+
wallets?: GardenWalletModules;
|
|
153
|
+
};
|
|
154
|
+
export type GardenConfigWithHTLCs = GardenCoreConfig & {
|
|
155
|
+
htlc?: GardenHTLCModules;
|
|
156
|
+
};
|
|
157
|
+
export type ResponseTypeMap = {
|
|
158
|
+
[BlockchainType.evm]: EvmOrderResponse;
|
|
159
|
+
[BlockchainType.bitcoin]: BitcoinOrderResponse;
|
|
160
|
+
[BlockchainType.starknet]: StarknetOrderResponse;
|
|
161
|
+
[BlockchainType.solana]: SolanaOrderResponse;
|
|
162
|
+
[BlockchainType.sui]: SuiOrderResponse;
|
|
189
163
|
};
|
|
190
|
-
export type GardenConfigWithWallets = GardenCoreConfig & GardenWalletModules;
|
|
191
|
-
export type GardenConfigWithHTLCs = GardenCoreConfig & GardenHTLCModules;
|
|
192
|
-
/**
|
|
193
|
-
* Actions that can be performed on the order.
|
|
194
|
-
*/
|
|
195
|
-
export declare enum OrderActions {
|
|
196
|
-
Idle = "Idle",
|
|
197
|
-
Initiate = "Initiate",
|
|
198
|
-
Redeem = "Redeem",
|
|
199
|
-
Refund = "Refund"
|
|
200
|
-
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Err, Ok, Request as UtilsRequest } from '@gardenfi/utils';
|
|
2
2
|
import { IQuote, QuoteParamsForAssets, QuoteResponse, Strategies } from './quote.types';
|
|
3
|
+
import { AssetLike } from '@gardenfi/orderbook';
|
|
3
4
|
|
|
4
5
|
export declare class Quote implements IQuote {
|
|
5
6
|
private quoteUrl;
|
|
6
7
|
constructor(quoteUrl: string);
|
|
7
|
-
getQuoteFromAssets({ fromAsset, toAsset, amount, isExactOut, options, }: QuoteParamsForAssets): Promise<Err<string> | Ok<QuoteResponse>>;
|
|
8
|
-
getQuote(
|
|
8
|
+
getQuoteFromAssets({ fromAsset, toAsset, amount, isExactOut, options, }: QuoteParamsForAssets): Promise<Err<string> | Ok<QuoteResponse[]>>;
|
|
9
|
+
getQuote(from: AssetLike, to: AssetLike, amount: number, isExactOut?: boolean, options?: {
|
|
9
10
|
affiliateFee?: number;
|
|
10
11
|
request?: UtilsRequest;
|
|
11
|
-
}): Promise<Err<string> | Ok<QuoteResponse>>;
|
|
12
|
+
}): Promise<Err<string> | Ok<QuoteResponse[]>>;
|
|
12
13
|
getStrategies(): Promise<Err<string> | Ok<Strategies>>;
|
|
13
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, Chain } from '@gardenfi/orderbook';
|
|
1
|
+
import { Asset, AssetLike, Chain, ChainAsset } from '@gardenfi/orderbook';
|
|
2
2
|
import { APIResponse, AsyncResult, Request } from '@gardenfi/utils';
|
|
3
3
|
|
|
4
4
|
export interface IQuote {
|
|
@@ -12,7 +12,7 @@ export interface IQuote {
|
|
|
12
12
|
* @param options { affiliateFee?: number; request?: Request } - The options for the quote request, affiliate fee in bps and request object
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
getQuoteFromAssets(params: QuoteParamsForAssets): AsyncResult<QuoteResponse, string>;
|
|
15
|
+
getQuoteFromAssets(params: QuoteParamsForAssets): AsyncResult<QuoteResponse[], string>;
|
|
16
16
|
/**
|
|
17
17
|
* Get a quote for the given orderpair and amount
|
|
18
18
|
* @param orderpair - A string representing the order pair for which the quote is requested.
|
|
@@ -24,7 +24,7 @@ export interface IQuote {
|
|
|
24
24
|
* @param isExactOut - Whether the amount is exact out
|
|
25
25
|
* @param options { affiliateFee?: number; request?: Request } - The options for the quote request, affiliate fee in bps and request object
|
|
26
26
|
*/
|
|
27
|
-
getQuote(
|
|
27
|
+
getQuote(from: AssetLike, to: AssetLike, amount: number, isExactOut: boolean, options?: QuoteOptions): AsyncResult<QuoteResponse[], string>;
|
|
28
28
|
/**
|
|
29
29
|
* Get the strategies available for quoting
|
|
30
30
|
* @returns {Strategies} The strategies available
|
|
@@ -45,14 +45,23 @@ export type QuoteParamsForAssets = BaseQuoteParams & {
|
|
|
45
45
|
toAsset: Asset;
|
|
46
46
|
};
|
|
47
47
|
export type QuoteParamsForOrderPair = BaseQuoteParams & {
|
|
48
|
-
|
|
48
|
+
from: ChainAsset;
|
|
49
|
+
to: ChainAsset;
|
|
49
50
|
};
|
|
50
51
|
export type QuoteResponse = {
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
source: {
|
|
53
|
+
asset: string;
|
|
54
|
+
amount: string;
|
|
55
|
+
display: string;
|
|
56
|
+
value: string;
|
|
53
57
|
};
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
destination: {
|
|
59
|
+
asset: string;
|
|
60
|
+
amount: string;
|
|
61
|
+
display: string;
|
|
62
|
+
value: string;
|
|
63
|
+
};
|
|
64
|
+
solver_id: string;
|
|
56
65
|
};
|
|
57
66
|
export type Strategies = Record<string, {
|
|
58
67
|
id: string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ChainAsset } from '@gardenfi/orderbook';
|
|
2
|
+
|
|
3
|
+
interface RoutePolicy {
|
|
4
|
+
default: 'open' | 'closed';
|
|
5
|
+
isolation_groups: string[];
|
|
6
|
+
blacklist_pairs: string[];
|
|
7
|
+
whitelist_overrides: string[];
|
|
8
|
+
}
|
|
9
|
+
declare class RouteValidator {
|
|
10
|
+
private apiBaseUrl;
|
|
11
|
+
private apiKey;
|
|
12
|
+
private policy;
|
|
13
|
+
constructor(apiBaseUrl: string, apiKey: string);
|
|
14
|
+
loadPolicy(): Promise<void>;
|
|
15
|
+
isValidRoute(fromAsset: ChainAsset, toAsset: ChainAsset): boolean;
|
|
16
|
+
getValidDestinations(fromAsset: ChainAsset, allAssets: ChainAsset[]): ChainAsset[];
|
|
17
|
+
getAllValidRoutes(assets: ChainAsset[]): Array<{
|
|
18
|
+
from: ChainAsset;
|
|
19
|
+
to: ChainAsset;
|
|
20
|
+
}>;
|
|
21
|
+
private isInIsolationGroup;
|
|
22
|
+
private isValidIsolationGroup;
|
|
23
|
+
private isWhitelistOverride;
|
|
24
|
+
private isBlacklisted;
|
|
25
|
+
private parseIsolationGroup;
|
|
26
|
+
private matchesPattern;
|
|
27
|
+
private matchesAssetPattern;
|
|
28
|
+
}
|
|
29
|
+
declare function buildRouteMatrix(assets: ChainAsset[], validator: RouteValidator): Record<string, ChainAsset[]>;
|
|
30
|
+
export { RouteValidator, buildRouteMatrix, type RoutePolicy };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Order, SolanaOrderResponse } from '@gardenfi/orderbook';
|
|
2
2
|
import { AsyncResult } from '@gardenfi/utils';
|
|
3
3
|
|
|
4
4
|
export interface ISolanaHTLC {
|
|
@@ -11,18 +11,18 @@ export interface ISolanaHTLC {
|
|
|
11
11
|
* @param order - The matched order.
|
|
12
12
|
* @returns A promise resolving to the transaction hash of the initiation.
|
|
13
13
|
*/
|
|
14
|
-
initiate(order:
|
|
14
|
+
initiate(order: Order | SolanaOrderResponse): AsyncResult<string, string>;
|
|
15
15
|
/**
|
|
16
16
|
* Redeems funds from the HTLC contract to the actor's address.
|
|
17
17
|
* @param order - The matched order.
|
|
18
18
|
* @param secret - The secret required to unlock the htlc.
|
|
19
19
|
* @returns A promise resolving to the transaction hash of the redemption.
|
|
20
20
|
*/
|
|
21
|
-
redeem(order:
|
|
21
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
22
22
|
/**
|
|
23
23
|
* Refunds funds from the HTLC contract back to the actor's address upon expiration.
|
|
24
24
|
* @param order - The matched order.
|
|
25
25
|
* @returns A promise resolving to the transaction hash of the refund.
|
|
26
26
|
*/
|
|
27
|
-
refund(order:
|
|
27
|
+
refund(order: Order): AsyncResult<string, string>;
|
|
28
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
2
2
|
import { ISolanaHTLC } from './ISolanaHTLC';
|
|
3
|
-
import {
|
|
3
|
+
import { Order } from '@gardenfi/orderbook';
|
|
4
4
|
import { AsyncResult } from '@gardenfi/utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -30,27 +30,27 @@ export declare class SolanaHTLC implements ISolanaHTLC {
|
|
|
30
30
|
get htlcActorAddress(): string;
|
|
31
31
|
/**
|
|
32
32
|
* Initiates a swap by creating a new swap account and locking funds.
|
|
33
|
-
* @param {
|
|
33
|
+
* @param {Order} order - The matched order containing swap details
|
|
34
34
|
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
35
35
|
* - Ok with the transaction ID on success
|
|
36
36
|
* - Err with an error message on failure
|
|
37
37
|
*/
|
|
38
|
-
initiate(order:
|
|
38
|
+
initiate(order: Order): AsyncResult<string, string>;
|
|
39
39
|
/**
|
|
40
40
|
* Redeems a swap by providing the secret.
|
|
41
|
-
* @param {
|
|
41
|
+
* @param {Order} order - Matched order object containing swap details
|
|
42
42
|
* @param {string} secret - Secret key in hex format
|
|
43
43
|
* @returns {AsyncResult<string, string>} A promise that resolves to either:
|
|
44
44
|
* - Ok with the transaction ID on success
|
|
45
45
|
* - Err with an error message on failure
|
|
46
46
|
*/
|
|
47
|
-
redeem(order:
|
|
47
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
48
48
|
/**
|
|
49
49
|
* Refunds the swap back to the initiator.
|
|
50
|
-
* @param {
|
|
50
|
+
* @param {Order} order - Matched order object
|
|
51
51
|
* @returns {AsyncResult<string, string>} A promise that resolves to either:
|
|
52
52
|
* - Ok with the transaction ID on success
|
|
53
53
|
* - Err with an error message on failure
|
|
54
54
|
*/
|
|
55
|
-
refund(order:
|
|
55
|
+
refund(order: Order): AsyncResult<string, string>;
|
|
56
56
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
2
|
-
import { AsyncResult, Url } from '@gardenfi/utils';
|
|
2
|
+
import { AsyncResult, IAuth, Url, Network } from '@gardenfi/utils';
|
|
3
3
|
import { ISolanaHTLC } from '../htlc/ISolanaHTLC';
|
|
4
|
-
import {
|
|
4
|
+
import { Order, SolanaOrderResponse } 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.
|
|
@@ -18,18 +18,24 @@ export declare class SolanaRelay implements ISolanaHTLC {
|
|
|
18
18
|
private splProgram?;
|
|
19
19
|
private nativeProgram?;
|
|
20
20
|
private relayer;
|
|
21
|
+
private auth;
|
|
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
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {
|
|
26
|
+
* @param {Network} network - Chain network for selecting default relayer and program addresses
|
|
27
|
+
* @param {IAuth} auth - Auth provider for relayer endpoints
|
|
28
|
+
* @param {object} [overrides] - Optional overrides for relayer/program addresses
|
|
29
|
+
* @param {string} [overrides.relayer] - Custom relayer address (base58)
|
|
30
|
+
* @param {{native?: string; spl?: string}} [overrides.programAddress] - Custom program addresses
|
|
28
31
|
* @throws {Error} If any required parameters are missing or invalid
|
|
29
32
|
*/
|
|
30
|
-
constructor(provider: AnchorProvider, url: Url,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
constructor(provider: AnchorProvider, url: Url, network: Network, auth: IAuth, overrides?: {
|
|
34
|
+
relayer?: string;
|
|
35
|
+
programAddress?: {
|
|
36
|
+
native?: string;
|
|
37
|
+
spl?: string;
|
|
38
|
+
};
|
|
33
39
|
});
|
|
34
40
|
/**
|
|
35
41
|
* Gets the on-chain address of the current user's wallet.
|
|
@@ -38,12 +44,14 @@ export declare class SolanaRelay implements ISolanaHTLC {
|
|
|
38
44
|
*/
|
|
39
45
|
get htlcActorAddress(): string;
|
|
40
46
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
44
|
-
* @
|
|
47
|
+
* Initiates a swap by creating a new swap account and locking funds.
|
|
48
|
+
* Automatically detects whether to use SPL or native token handling.
|
|
49
|
+
* @param {Order} order - The matched order containing swap details
|
|
50
|
+
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
51
|
+
* - Ok with the transaction ID on success
|
|
52
|
+
* - Err with an error message on failure
|
|
45
53
|
*/
|
|
46
|
-
|
|
54
|
+
initiate(order: Order | SolanaOrderResponse): AsyncResult<string, string>;
|
|
47
55
|
/**
|
|
48
56
|
* Sends a transaction via the relayer for SPL tokens.
|
|
49
57
|
* @param {web3.Transaction} transaction - The transaction to send
|
|
@@ -57,24 +65,16 @@ export declare class SolanaRelay implements ISolanaHTLC {
|
|
|
57
65
|
/**
|
|
58
66
|
* Initiates a swap directly via HTLC (without relayer).
|
|
59
67
|
* @param {web3.Transaction} transaction - The transaction to send
|
|
60
|
-
* @param {
|
|
68
|
+
* @param {Order} order - The matched order
|
|
61
69
|
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
62
70
|
* - Ok with the transaction ID on success
|
|
63
71
|
* - Err with an error message on failure
|
|
64
72
|
* @private
|
|
65
73
|
*/
|
|
66
74
|
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
75
|
/**
|
|
76
76
|
* Initiates a swap for SPL tokens.
|
|
77
|
-
* @param {
|
|
77
|
+
* @param {Order} order - The matched order containing swap details
|
|
78
78
|
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
79
79
|
* - Ok with the transaction ID on success
|
|
80
80
|
* - Err with an error message on failure
|
|
@@ -83,31 +83,23 @@ export declare class SolanaRelay implements ISolanaHTLC {
|
|
|
83
83
|
private initiateSplSwap;
|
|
84
84
|
/**
|
|
85
85
|
* Initiates a swap for native tokens (SOL).
|
|
86
|
-
* @param {
|
|
86
|
+
* @param {Order} order - The matched order containing swap details
|
|
87
87
|
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
88
88
|
* - Ok with the transaction ID on success
|
|
89
89
|
* - Err with an error message on failure
|
|
90
90
|
* @private
|
|
91
91
|
*/
|
|
92
92
|
private initiateNativeSwap;
|
|
93
|
-
|
|
94
|
-
* Initiates a swap by creating a new swap account and locking funds.
|
|
95
|
-
* Automatically detects whether to use SPL or native token handling.
|
|
96
|
-
* @param {MatchedOrder} order - The matched order containing swap details
|
|
97
|
-
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
98
|
-
* - Ok with the transaction ID on success
|
|
99
|
-
* - Err with an error message on failure
|
|
100
|
-
*/
|
|
101
|
-
initiate(order: MatchedOrder): AsyncResult<string, string>;
|
|
93
|
+
private initiateWithCreateOrderResponse;
|
|
102
94
|
/**
|
|
103
95
|
* Redeems a swap by providing the secret.
|
|
104
|
-
* @param {
|
|
96
|
+
* @param {Order} order - Matched order object containing swap details
|
|
105
97
|
* @param {string} secret - Secret key in hex format
|
|
106
98
|
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
107
99
|
* - Ok with the transaction ID on success
|
|
108
100
|
* - Err with an error message on failure
|
|
109
101
|
*/
|
|
110
|
-
redeem(order:
|
|
102
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
111
103
|
/**
|
|
112
104
|
* DO NOT CALL THIS FUNCTION. Refund is automatically taken care of by the relayer!
|
|
113
105
|
* This method exists only to satisfy the ISolanaHTLC interface but is not intended for direct use.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { web3, BN } from '@coral-xyz/anchor';
|
|
2
|
-
import {
|
|
2
|
+
import { Order } from '@gardenfi/orderbook';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A Swap configuration in Solana
|
|
@@ -20,9 +20,9 @@ export declare class SwapConfig {
|
|
|
20
20
|
constructor(swapId: string, redeemer: string, secretHash: string, amount: bigint, expiresIn: number);
|
|
21
21
|
/**
|
|
22
22
|
* Constructs a SwapConfig from a matched order object with Solana as a source swap
|
|
23
|
-
* @param order - The
|
|
23
|
+
* @param order - The Order with a Solana as source swap
|
|
24
24
|
*/
|
|
25
|
-
static from(order:
|
|
25
|
+
static from(order: Order): SwapConfig;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Checks whether given secret is a valid 32 byte hex string.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Order } from '@gardenfi/orderbook';
|
|
2
2
|
import { Account, CallData } from 'starknet';
|
|
3
3
|
import { AsyncResult, Network } from '@gardenfi/utils';
|
|
4
4
|
import { IStarknetHTLC } from '../starknetHTLC.types';
|
|
@@ -14,7 +14,7 @@ export declare class StarknetHTLC implements IStarknetHTLC {
|
|
|
14
14
|
* @param order Order to initiate HTLC for
|
|
15
15
|
* @returns Transaction ID
|
|
16
16
|
*/
|
|
17
|
-
initiate(order:
|
|
17
|
+
initiate(order: Order): AsyncResult<string, string>;
|
|
18
18
|
callData: CallData;
|
|
19
19
|
/**
|
|
20
20
|
* Redeems the HTLC
|
|
@@ -23,12 +23,12 @@ export declare class StarknetHTLC implements IStarknetHTLC {
|
|
|
23
23
|
* @param secret Secret to redeem HTLC with
|
|
24
24
|
* @returns Transaction ID
|
|
25
25
|
*/
|
|
26
|
-
redeem(order:
|
|
26
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
27
27
|
/**
|
|
28
28
|
* Refunds the HTLC
|
|
29
29
|
*
|
|
30
30
|
* @param order Order to refund HTLC for
|
|
31
31
|
* @returns Refund transaction ID
|
|
32
32
|
*/
|
|
33
|
-
refund(order:
|
|
33
|
+
refund(order: Order): AsyncResult<string, string>;
|
|
34
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AccountInterface } from 'starknet';
|
|
2
|
-
import {
|
|
3
|
-
import { AsyncResult, Network, Url } from '@gardenfi/utils';
|
|
2
|
+
import { Order, StarknetOrderResponse } from '@gardenfi/orderbook';
|
|
3
|
+
import { AsyncResult, IAuth, Network, Url } from '@gardenfi/utils';
|
|
4
4
|
import { IStarknetHTLC } from '../starknetHTLC.types';
|
|
5
5
|
|
|
6
6
|
export declare class StarknetRelay implements IStarknetHTLC {
|
|
@@ -8,11 +8,14 @@ export declare class StarknetRelay implements IStarknetHTLC {
|
|
|
8
8
|
private account;
|
|
9
9
|
private starknetProvider;
|
|
10
10
|
private chainId;
|
|
11
|
-
|
|
11
|
+
private auth;
|
|
12
|
+
constructor(relayerUrl: string | Url, account: AccountInterface, network: Network, auth: IAuth, nodeUrl?: string);
|
|
12
13
|
get htlcActorAddress(): string;
|
|
13
|
-
initiate(order:
|
|
14
|
+
initiate(order: Order | StarknetOrderResponse): AsyncResult<string, string>;
|
|
14
15
|
private approveAndInitiate;
|
|
15
16
|
private initiateRelay;
|
|
16
|
-
redeem(order:
|
|
17
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
18
|
+
executeApprovalTransaction(order: StarknetOrderResponse): AsyncResult<string, string>;
|
|
19
|
+
initiateWithCreateOrderResponse(order: StarknetOrderResponse): AsyncResult<string, string>;
|
|
17
20
|
refund(): AsyncResult<string, string>;
|
|
18
21
|
}
|