@gardenfi/core 0.1.14 → 0.2.0-beta.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/index.cjs +809 -1
- package/dist/index.js +809 -1
- package/dist/src/index.d.ts +10 -3
- package/dist/src/lib/bitcoin/htlc.d.ts +105 -0
- package/dist/src/lib/bitcoin/internalKey.d.ts +8 -0
- package/dist/src/lib/errors.d.ts +15 -1
- package/dist/src/lib/evmRelay/abi.d.ts +305 -0
- package/dist/src/lib/evmRelay/evmRelay.d.ts +13 -0
- package/dist/src/lib/evmRelay/evmRelay.types.d.ts +26 -0
- package/dist/src/lib/garden/garden.d.ts +19 -0
- package/dist/src/lib/garden/garden.types.d.ts +34 -0
- package/dist/src/lib/orderExecutor/blockNumber.d.ts +21 -0
- package/dist/src/lib/orderExecutor/orderCache.d.ts +15 -0
- package/dist/src/lib/orderExecutor/orderExecutor.d.ts +25 -0
- package/dist/src/lib/orderExecutor/orderExecutor.types.d.ts +190 -0
- package/dist/src/lib/orderExecutor/orderStatusParser.d.ts +27 -0
- package/dist/src/lib/secretManager/secretManager.d.ts +15 -0
- package/dist/src/lib/secretManager/secretManager.types.d.ts +26 -0
- package/dist/src/lib/utils.d.ts +15 -0
- package/package.json +15 -11
- package/dist/src/lib/catalogActions.d.ts +0 -3
- package/dist/src/lib/garden.d.ts +0 -46
- package/dist/src/lib/garden.types.d.ts +0 -53
- package/dist/src/lib/swapper.d.ts +0 -35
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { Garden } from './lib/garden/garden';
|
|
2
|
+
export type { IGardenJS, SwapParams, TimeLocks, } from './lib/garden/garden.types';
|
|
3
|
+
export { EvmRelay } from './lib/evmRelay/evmRelay';
|
|
4
|
+
export type { IEVMRelay } from './lib/evmRelay/evmRelay.types';
|
|
5
|
+
export { OrderExecutor } from './lib/orderExecutor/orderExecutor';
|
|
6
|
+
export type { IOrderExecutor, OrderStatus, SwapStatus, OrderActions, } from './lib/orderExecutor/orderExecutor.types';
|
|
7
|
+
export { fetchBitcoinBlockNumber, fetchL1BlockNumber, fetchEVMBlockNumber, } from './lib/orderExecutor/blockNumber';
|
|
8
|
+
export { parseAction, ParseOrderStatus, ParseSwapStatus, } from './lib/orderExecutor/orderStatusParser';
|
|
9
|
+
export { SecretManager } from './lib/secretManager/secretManager';
|
|
10
|
+
export type { ISecretManager, Secret, } from './lib/secretManager/secretManager.types';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { IBitcoinWallet, IHTLCWallet } from '@catalogfi/wallets';
|
|
2
|
+
|
|
3
|
+
export declare enum Leaf {
|
|
4
|
+
REFUND = 0,
|
|
5
|
+
REDEEM = 1,
|
|
6
|
+
INSTANT_REFUND = 2
|
|
7
|
+
}
|
|
8
|
+
export declare class GardenHTLC implements IHTLCWallet {
|
|
9
|
+
/**
|
|
10
|
+
* Signer of the HTLC can be either the initiator or the redeemer
|
|
11
|
+
*/
|
|
12
|
+
private signer;
|
|
13
|
+
private secretHash;
|
|
14
|
+
/**
|
|
15
|
+
* redeemer's x-only public key without 02 or 03 prefix
|
|
16
|
+
*/
|
|
17
|
+
private redeemerPubkey;
|
|
18
|
+
/**
|
|
19
|
+
* initiator's x-only public key without 02 or 03 prefix
|
|
20
|
+
*/
|
|
21
|
+
private initiatorPubkey;
|
|
22
|
+
private expiry;
|
|
23
|
+
/**
|
|
24
|
+
* NUMS internal key which blocks key path spending
|
|
25
|
+
*/
|
|
26
|
+
private internalPubkey;
|
|
27
|
+
private network;
|
|
28
|
+
private initiateAmount;
|
|
29
|
+
/**
|
|
30
|
+
* Note: redeemerAddress and initiatorAddress should be x-only public key without 02 or 03 prefix
|
|
31
|
+
*/
|
|
32
|
+
private constructor();
|
|
33
|
+
/**
|
|
34
|
+
* Creates a GardenHTLC instance
|
|
35
|
+
* @param signer Bitcoin wallet of the initiator or redeemer
|
|
36
|
+
* @param secretHash 32 bytes secret hash
|
|
37
|
+
* @param initiatorPubkey initiator's x-only public key without 02 or 03 prefix
|
|
38
|
+
* @param redeemerPubkey redeemer's x-only public key without 02 or 03 prefix
|
|
39
|
+
* @param expiry block height after which the funds can be refunded
|
|
40
|
+
* @returns GardenHTLC instance
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* Note: When the signer is the initiator, only refund and instant refund can be done
|
|
44
|
+
* When the signer is the redeemer, only redeem can be done
|
|
45
|
+
*/
|
|
46
|
+
static from(signer: IBitcoinWallet, initiateAmount: number, secretHash: string, initiatorPubkey: string, redeemerPubkey: string, expiry: number): Promise<GardenHTLC>;
|
|
47
|
+
/**
|
|
48
|
+
* Generates a taproot address for receiving the funds
|
|
49
|
+
*/
|
|
50
|
+
address(): string;
|
|
51
|
+
/**
|
|
52
|
+
* returns the address of the HTLC
|
|
53
|
+
*/
|
|
54
|
+
id(): string;
|
|
55
|
+
private _buildRawTx;
|
|
56
|
+
/**
|
|
57
|
+
* Builds a raw unsigned transaction with utxos from gardenHTLC address
|
|
58
|
+
* and uses signer's address as the output address
|
|
59
|
+
*/
|
|
60
|
+
private buildRawTx;
|
|
61
|
+
/**
|
|
62
|
+
* prevout script for the gardenHTLC address
|
|
63
|
+
*/
|
|
64
|
+
private getOutputScript;
|
|
65
|
+
init(fee?: number): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Instantly refunds the funds to the initiator given the counterparty's signatures and pubkey
|
|
68
|
+
*
|
|
69
|
+
* Note: If there are multiple UTXOs being spend, there should be a signature for each UTXO in counterPartySigs
|
|
70
|
+
*/
|
|
71
|
+
instantRefund(counterPartySigs: {
|
|
72
|
+
utxo: string;
|
|
73
|
+
sig: string;
|
|
74
|
+
}[], fee?: number): Promise<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Reveals the secret and redeems the HTLC
|
|
77
|
+
*/
|
|
78
|
+
redeem(secret: string, receiver?: string, fee?: number): Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* Refunds the funds back to the initiator if the expiry block height + 1 is reached
|
|
81
|
+
*/
|
|
82
|
+
refund(receiver?: string, fee?: number): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Given a list of UTXOs, checks if the HTLC can be refunded
|
|
85
|
+
*/
|
|
86
|
+
private canRefund;
|
|
87
|
+
/**
|
|
88
|
+
* Given a leaf, generates the control block necessary for spending the leaf
|
|
89
|
+
*/
|
|
90
|
+
private generateControlBlockFor;
|
|
91
|
+
/**
|
|
92
|
+
* Generates the hash of the leaf script
|
|
93
|
+
* @param leaf Use leaf enum or pass 0 for refund, 1 for redeem, 2 for instant refund
|
|
94
|
+
* @returns hash of the leaf script
|
|
95
|
+
*/
|
|
96
|
+
leafHash(leaf: Leaf): Buffer;
|
|
97
|
+
private refundLeaf;
|
|
98
|
+
private redeemLeaf;
|
|
99
|
+
private instantRefundLeaf;
|
|
100
|
+
private leaves;
|
|
101
|
+
/**
|
|
102
|
+
* Generates the merkle proof for the leaf script
|
|
103
|
+
*/
|
|
104
|
+
private generateMerkleProofFor;
|
|
105
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as ecc from 'tiny-secp256k1';
|
|
2
|
+
/**
|
|
3
|
+
* Generates NUMS internal key
|
|
4
|
+
*
|
|
5
|
+
* Uses Standard ECDSA secp256k1 curve's G point
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateInternalkey(): Buffer;
|
|
8
|
+
export declare function tweakPubkey(pubkey: Buffer, hash: Buffer): ecc.XOnlyPointAddTweakResult;
|
package/dist/src/lib/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const GardenErrors: {
|
|
2
2
|
WALLET_NOT_FOUND: (from: boolean) => string;
|
|
3
3
|
CHAIN_WALLET_NOT_FOUND: (blockchain: "EVM" | "Bitcoin") => string;
|
|
4
4
|
};
|
|
@@ -7,3 +7,17 @@ export declare const SwapperErrors: {
|
|
|
7
7
|
NO_SECRET: string;
|
|
8
8
|
INVALID_ACTION: (action: "init" | "redeem" | "refund", status: number) => string;
|
|
9
9
|
};
|
|
10
|
+
export declare const htlcErrors: {
|
|
11
|
+
secretMismatch: string;
|
|
12
|
+
secretHashLenMismatch: string;
|
|
13
|
+
pubkeyLenMismatch: string;
|
|
14
|
+
zeroOrNegativeExpiry: string;
|
|
15
|
+
htlcAddressGenerationFailed: string;
|
|
16
|
+
notFunded: string;
|
|
17
|
+
noCounterpartySigs: string;
|
|
18
|
+
counterPartySigNotFound: (utxo: string) => string;
|
|
19
|
+
invalidCounterpartySigForUTXO: (utxo: string) => string;
|
|
20
|
+
htlcNotExpired: (blocks: number) => string;
|
|
21
|
+
controlBlockGenerationFailed: string;
|
|
22
|
+
invalidLeaf: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
export declare const AtomicSwapABI: readonly [{
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly internalType: "address";
|
|
4
|
+
readonly name: "token_";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
}, {
|
|
7
|
+
readonly internalType: "string";
|
|
8
|
+
readonly name: "name";
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
}, {
|
|
11
|
+
readonly internalType: "string";
|
|
12
|
+
readonly name: "version";
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
}];
|
|
15
|
+
readonly stateMutability: "nonpayable";
|
|
16
|
+
readonly type: "constructor";
|
|
17
|
+
}, {
|
|
18
|
+
readonly inputs: readonly [];
|
|
19
|
+
readonly name: "InvalidShortString";
|
|
20
|
+
readonly type: "error";
|
|
21
|
+
}, {
|
|
22
|
+
readonly inputs: readonly [{
|
|
23
|
+
readonly internalType: "string";
|
|
24
|
+
readonly name: "str";
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
}];
|
|
27
|
+
readonly name: "StringTooLong";
|
|
28
|
+
readonly type: "error";
|
|
29
|
+
}, {
|
|
30
|
+
readonly anonymous: false;
|
|
31
|
+
readonly inputs: readonly [];
|
|
32
|
+
readonly name: "EIP712DomainChanged";
|
|
33
|
+
readonly type: "event";
|
|
34
|
+
}, {
|
|
35
|
+
readonly anonymous: false;
|
|
36
|
+
readonly inputs: readonly [{
|
|
37
|
+
readonly indexed: true;
|
|
38
|
+
readonly internalType: "bytes32";
|
|
39
|
+
readonly name: "orderID";
|
|
40
|
+
readonly type: "bytes32";
|
|
41
|
+
}, {
|
|
42
|
+
readonly indexed: true;
|
|
43
|
+
readonly internalType: "bytes32";
|
|
44
|
+
readonly name: "secretHash";
|
|
45
|
+
readonly type: "bytes32";
|
|
46
|
+
}, {
|
|
47
|
+
readonly indexed: false;
|
|
48
|
+
readonly internalType: "uint256";
|
|
49
|
+
readonly name: "amount";
|
|
50
|
+
readonly type: "uint256";
|
|
51
|
+
}];
|
|
52
|
+
readonly name: "Initiated";
|
|
53
|
+
readonly type: "event";
|
|
54
|
+
}, {
|
|
55
|
+
readonly anonymous: false;
|
|
56
|
+
readonly inputs: readonly [{
|
|
57
|
+
readonly indexed: true;
|
|
58
|
+
readonly internalType: "bytes32";
|
|
59
|
+
readonly name: "orderID";
|
|
60
|
+
readonly type: "bytes32";
|
|
61
|
+
}, {
|
|
62
|
+
readonly indexed: true;
|
|
63
|
+
readonly internalType: "bytes32";
|
|
64
|
+
readonly name: "secretHash";
|
|
65
|
+
readonly type: "bytes32";
|
|
66
|
+
}, {
|
|
67
|
+
readonly indexed: false;
|
|
68
|
+
readonly internalType: "bytes";
|
|
69
|
+
readonly name: "secret";
|
|
70
|
+
readonly type: "bytes";
|
|
71
|
+
}];
|
|
72
|
+
readonly name: "Redeemed";
|
|
73
|
+
readonly type: "event";
|
|
74
|
+
}, {
|
|
75
|
+
readonly anonymous: false;
|
|
76
|
+
readonly inputs: readonly [{
|
|
77
|
+
readonly indexed: true;
|
|
78
|
+
readonly internalType: "bytes32";
|
|
79
|
+
readonly name: "orderID";
|
|
80
|
+
readonly type: "bytes32";
|
|
81
|
+
}];
|
|
82
|
+
readonly name: "Refunded";
|
|
83
|
+
readonly type: "event";
|
|
84
|
+
}, {
|
|
85
|
+
readonly inputs: readonly [];
|
|
86
|
+
readonly name: "eip712Domain";
|
|
87
|
+
readonly outputs: readonly [{
|
|
88
|
+
readonly internalType: "bytes1";
|
|
89
|
+
readonly name: "fields";
|
|
90
|
+
readonly type: "bytes1";
|
|
91
|
+
}, {
|
|
92
|
+
readonly internalType: "string";
|
|
93
|
+
readonly name: "name";
|
|
94
|
+
readonly type: "string";
|
|
95
|
+
}, {
|
|
96
|
+
readonly internalType: "string";
|
|
97
|
+
readonly name: "version";
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
}, {
|
|
100
|
+
readonly internalType: "uint256";
|
|
101
|
+
readonly name: "chainId";
|
|
102
|
+
readonly type: "uint256";
|
|
103
|
+
}, {
|
|
104
|
+
readonly internalType: "address";
|
|
105
|
+
readonly name: "verifyingContract";
|
|
106
|
+
readonly type: "address";
|
|
107
|
+
}, {
|
|
108
|
+
readonly internalType: "bytes32";
|
|
109
|
+
readonly name: "salt";
|
|
110
|
+
readonly type: "bytes32";
|
|
111
|
+
}, {
|
|
112
|
+
readonly internalType: "uint256[]";
|
|
113
|
+
readonly name: "extensions";
|
|
114
|
+
readonly type: "uint256[]";
|
|
115
|
+
}];
|
|
116
|
+
readonly stateMutability: "view";
|
|
117
|
+
readonly type: "function";
|
|
118
|
+
}, {
|
|
119
|
+
readonly inputs: readonly [{
|
|
120
|
+
readonly internalType: "address";
|
|
121
|
+
readonly name: "redeemer";
|
|
122
|
+
readonly type: "address";
|
|
123
|
+
}, {
|
|
124
|
+
readonly internalType: "uint256";
|
|
125
|
+
readonly name: "timelock";
|
|
126
|
+
readonly type: "uint256";
|
|
127
|
+
}, {
|
|
128
|
+
readonly internalType: "uint256";
|
|
129
|
+
readonly name: "amount";
|
|
130
|
+
readonly type: "uint256";
|
|
131
|
+
}, {
|
|
132
|
+
readonly internalType: "bytes32";
|
|
133
|
+
readonly name: "secretHash";
|
|
134
|
+
readonly type: "bytes32";
|
|
135
|
+
}];
|
|
136
|
+
readonly name: "initiate";
|
|
137
|
+
readonly outputs: readonly [];
|
|
138
|
+
readonly stateMutability: "nonpayable";
|
|
139
|
+
readonly type: "function";
|
|
140
|
+
}, {
|
|
141
|
+
readonly inputs: readonly [{
|
|
142
|
+
readonly internalType: "address";
|
|
143
|
+
readonly name: "redeemer";
|
|
144
|
+
readonly type: "address";
|
|
145
|
+
}, {
|
|
146
|
+
readonly internalType: "uint256";
|
|
147
|
+
readonly name: "timelock";
|
|
148
|
+
readonly type: "uint256";
|
|
149
|
+
}, {
|
|
150
|
+
readonly internalType: "uint256";
|
|
151
|
+
readonly name: "amount";
|
|
152
|
+
readonly type: "uint256";
|
|
153
|
+
}, {
|
|
154
|
+
readonly internalType: "bytes32";
|
|
155
|
+
readonly name: "secretHash";
|
|
156
|
+
readonly type: "bytes32";
|
|
157
|
+
}, {
|
|
158
|
+
readonly internalType: "bytes";
|
|
159
|
+
readonly name: "signature";
|
|
160
|
+
readonly type: "bytes";
|
|
161
|
+
}];
|
|
162
|
+
readonly name: "initiateWithSignature";
|
|
163
|
+
readonly outputs: readonly [];
|
|
164
|
+
readonly stateMutability: "nonpayable";
|
|
165
|
+
readonly type: "function";
|
|
166
|
+
}, {
|
|
167
|
+
readonly inputs: readonly [{
|
|
168
|
+
readonly internalType: "bytes32";
|
|
169
|
+
readonly name: "orderID";
|
|
170
|
+
readonly type: "bytes32";
|
|
171
|
+
}, {
|
|
172
|
+
readonly internalType: "bytes";
|
|
173
|
+
readonly name: "signature";
|
|
174
|
+
readonly type: "bytes";
|
|
175
|
+
}];
|
|
176
|
+
readonly name: "instantRefund";
|
|
177
|
+
readonly outputs: readonly [];
|
|
178
|
+
readonly stateMutability: "nonpayable";
|
|
179
|
+
readonly type: "function";
|
|
180
|
+
}, {
|
|
181
|
+
readonly inputs: readonly [{
|
|
182
|
+
readonly components: readonly [{
|
|
183
|
+
readonly internalType: "address";
|
|
184
|
+
readonly name: "redeemer";
|
|
185
|
+
readonly type: "address";
|
|
186
|
+
}, {
|
|
187
|
+
readonly internalType: "uint256";
|
|
188
|
+
readonly name: "expiry";
|
|
189
|
+
readonly type: "uint256";
|
|
190
|
+
}, {
|
|
191
|
+
readonly internalType: "uint256";
|
|
192
|
+
readonly name: "amount";
|
|
193
|
+
readonly type: "uint256";
|
|
194
|
+
}, {
|
|
195
|
+
readonly internalType: "bytes32";
|
|
196
|
+
readonly name: "secretHash";
|
|
197
|
+
readonly type: "bytes32";
|
|
198
|
+
}, {
|
|
199
|
+
readonly internalType: "bytes";
|
|
200
|
+
readonly name: "signature";
|
|
201
|
+
readonly type: "bytes";
|
|
202
|
+
}];
|
|
203
|
+
readonly internalType: "struct HTLC.InitWithSig[]";
|
|
204
|
+
readonly name: "inits";
|
|
205
|
+
readonly type: "tuple[]";
|
|
206
|
+
}, {
|
|
207
|
+
readonly components: readonly [{
|
|
208
|
+
readonly internalType: "bytes32";
|
|
209
|
+
readonly name: "orderID";
|
|
210
|
+
readonly type: "bytes32";
|
|
211
|
+
}, {
|
|
212
|
+
readonly internalType: "bytes";
|
|
213
|
+
readonly name: "secret";
|
|
214
|
+
readonly type: "bytes";
|
|
215
|
+
}];
|
|
216
|
+
readonly internalType: "struct HTLC.Redeem[]";
|
|
217
|
+
readonly name: "redeems";
|
|
218
|
+
readonly type: "tuple[]";
|
|
219
|
+
}, {
|
|
220
|
+
readonly components: readonly [{
|
|
221
|
+
readonly internalType: "bytes32";
|
|
222
|
+
readonly name: "orderID";
|
|
223
|
+
readonly type: "bytes32";
|
|
224
|
+
}];
|
|
225
|
+
readonly internalType: "struct HTLC.Refund[]";
|
|
226
|
+
readonly name: "refunds";
|
|
227
|
+
readonly type: "tuple[]";
|
|
228
|
+
}];
|
|
229
|
+
readonly name: "multicall";
|
|
230
|
+
readonly outputs: readonly [{
|
|
231
|
+
readonly internalType: "bool[]";
|
|
232
|
+
readonly name: "results";
|
|
233
|
+
readonly type: "bool[]";
|
|
234
|
+
}];
|
|
235
|
+
readonly stateMutability: "nonpayable";
|
|
236
|
+
readonly type: "function";
|
|
237
|
+
}, {
|
|
238
|
+
readonly inputs: readonly [{
|
|
239
|
+
readonly internalType: "bytes32";
|
|
240
|
+
readonly name: "";
|
|
241
|
+
readonly type: "bytes32";
|
|
242
|
+
}];
|
|
243
|
+
readonly name: "orders";
|
|
244
|
+
readonly outputs: readonly [{
|
|
245
|
+
readonly internalType: "bool";
|
|
246
|
+
readonly name: "isFulfilled";
|
|
247
|
+
readonly type: "bool";
|
|
248
|
+
}, {
|
|
249
|
+
readonly internalType: "address";
|
|
250
|
+
readonly name: "initiator";
|
|
251
|
+
readonly type: "address";
|
|
252
|
+
}, {
|
|
253
|
+
readonly internalType: "address";
|
|
254
|
+
readonly name: "redeemer";
|
|
255
|
+
readonly type: "address";
|
|
256
|
+
}, {
|
|
257
|
+
readonly internalType: "uint256";
|
|
258
|
+
readonly name: "initiatedAt";
|
|
259
|
+
readonly type: "uint256";
|
|
260
|
+
}, {
|
|
261
|
+
readonly internalType: "uint256";
|
|
262
|
+
readonly name: "timelock";
|
|
263
|
+
readonly type: "uint256";
|
|
264
|
+
}, {
|
|
265
|
+
readonly internalType: "uint256";
|
|
266
|
+
readonly name: "amount";
|
|
267
|
+
readonly type: "uint256";
|
|
268
|
+
}];
|
|
269
|
+
readonly stateMutability: "view";
|
|
270
|
+
readonly type: "function";
|
|
271
|
+
}, {
|
|
272
|
+
readonly inputs: readonly [{
|
|
273
|
+
readonly internalType: "bytes32";
|
|
274
|
+
readonly name: "orderID";
|
|
275
|
+
readonly type: "bytes32";
|
|
276
|
+
}, {
|
|
277
|
+
readonly internalType: "bytes";
|
|
278
|
+
readonly name: "secret";
|
|
279
|
+
readonly type: "bytes";
|
|
280
|
+
}];
|
|
281
|
+
readonly name: "redeem";
|
|
282
|
+
readonly outputs: readonly [];
|
|
283
|
+
readonly stateMutability: "nonpayable";
|
|
284
|
+
readonly type: "function";
|
|
285
|
+
}, {
|
|
286
|
+
readonly inputs: readonly [{
|
|
287
|
+
readonly internalType: "bytes32";
|
|
288
|
+
readonly name: "orderID";
|
|
289
|
+
readonly type: "bytes32";
|
|
290
|
+
}];
|
|
291
|
+
readonly name: "refund";
|
|
292
|
+
readonly outputs: readonly [];
|
|
293
|
+
readonly stateMutability: "nonpayable";
|
|
294
|
+
readonly type: "function";
|
|
295
|
+
}, {
|
|
296
|
+
readonly inputs: readonly [];
|
|
297
|
+
readonly name: "token";
|
|
298
|
+
readonly outputs: readonly [{
|
|
299
|
+
readonly internalType: "contract IERC20";
|
|
300
|
+
readonly name: "";
|
|
301
|
+
readonly type: "address";
|
|
302
|
+
}];
|
|
303
|
+
readonly stateMutability: "view";
|
|
304
|
+
readonly type: "function";
|
|
305
|
+
}];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WalletClient } from 'viem';
|
|
2
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
3
|
+
import { EVMRelayOpts, IEVMRelay } from './evmRelay.types';
|
|
4
|
+
import { AsyncResult } from '@catalogfi/utils';
|
|
5
|
+
|
|
6
|
+
export declare class EvmRelay implements IEVMRelay {
|
|
7
|
+
private walletClient;
|
|
8
|
+
private url;
|
|
9
|
+
private auth;
|
|
10
|
+
constructor(url: string, walletClient: WalletClient, opts?: EVMRelayOpts);
|
|
11
|
+
init(order: MatchedOrder, currentL1BlockNumber: number): AsyncResult<string, string>;
|
|
12
|
+
redeem(orderId: string, secret: string): AsyncResult<string, string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AsyncResult } from '@catalogfi/utils';
|
|
2
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
3
|
+
import { IStore } from '@gardenfi/utils';
|
|
4
|
+
|
|
5
|
+
export type EVMRelayOpts = {
|
|
6
|
+
store?: IStore;
|
|
7
|
+
domain?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface IEVMRelay {
|
|
10
|
+
/**
|
|
11
|
+
* Deposits funds to the EVM atomic swap contract using relay service.
|
|
12
|
+
* Sends the signature to the relay service.
|
|
13
|
+
* @param order Matched Order
|
|
14
|
+
* @param currentL1BlockNumber Current L1 block number. Used to calculate the swap expiry.
|
|
15
|
+
* @NOTE send the current block number of the L1 chain even if the order is on L2 chain.
|
|
16
|
+
* @returns txHash of Initiation
|
|
17
|
+
*/
|
|
18
|
+
init(order: MatchedOrder, currentL1BlockNumber: number): AsyncResult<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Redeems funds from the EVM atomic swap contract using relay service.
|
|
21
|
+
* Sends the secret to the relay service.
|
|
22
|
+
* @param orderId Create order Id of the order
|
|
23
|
+
* @param secret Secret of the HTLC generated when creating the order
|
|
24
|
+
*/
|
|
25
|
+
redeem(orderId: string, secret: string): AsyncResult<string, string>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ISecretManager } from './../secretManager/secretManager.types';
|
|
2
|
+
import { AsyncResult } from '@catalogfi/utils';
|
|
3
|
+
import { IGardenJS, SwapParams } from './garden.types';
|
|
4
|
+
import { IOrderbook } from '@gardenfi/orderbook';
|
|
5
|
+
import { IStore } from '@gardenfi/utils';
|
|
6
|
+
import { IOrderExecutor } from '../orderExecutor/orderExecutor.types';
|
|
7
|
+
|
|
8
|
+
export declare class Garden implements IGardenJS {
|
|
9
|
+
private secretManager;
|
|
10
|
+
private orderBook;
|
|
11
|
+
private relayURL;
|
|
12
|
+
private opts;
|
|
13
|
+
constructor(orderbook: IOrderbook, relayUrl: string, secretManager: ISecretManager, opts?: {
|
|
14
|
+
store?: IStore;
|
|
15
|
+
domain?: string;
|
|
16
|
+
});
|
|
17
|
+
swap(params: SwapParams): AsyncResult<string, string>;
|
|
18
|
+
subscribeOrders(cb: (executor: IOrderExecutor) => Promise<void>, interval?: number): Promise<() => void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AsyncResult } from '@catalogfi/utils';
|
|
2
|
+
import { Asset } from '@gardenfi/orderbook';
|
|
3
|
+
import { IOrderExecutor } from '../orderExecutor/orderExecutor.types';
|
|
4
|
+
|
|
5
|
+
export type SwapParams = {
|
|
6
|
+
fromAsset: Asset;
|
|
7
|
+
toAsset: Asset;
|
|
8
|
+
sendAmount: string;
|
|
9
|
+
receiveAmount: string;
|
|
10
|
+
sendAddress: string;
|
|
11
|
+
receiveAddress: string;
|
|
12
|
+
timelock?: number;
|
|
13
|
+
minDestinationConfirmations?: number;
|
|
14
|
+
additionalData?: {
|
|
15
|
+
btcAddress: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare enum TimeLocks {
|
|
19
|
+
evm = 14400,
|
|
20
|
+
btc = 288
|
|
21
|
+
}
|
|
22
|
+
export interface IGardenJS {
|
|
23
|
+
/**
|
|
24
|
+
* Create Order
|
|
25
|
+
* @param {SwapParams} - The parameters for creating the order.
|
|
26
|
+
*/
|
|
27
|
+
swap(params: SwapParams): AsyncResult<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to orders. This will poll the orderbook and call callback for each order.
|
|
30
|
+
* @param cb - Callback function to be called for each order. This callback will take orderExecutor as an argument.
|
|
31
|
+
* @param interval - Polling interval in milliseconds.
|
|
32
|
+
*/
|
|
33
|
+
subscribeOrders(cb: (orderExecutor: IOrderExecutor) => Promise<void>, interval?: number): Promise<() => void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AsyncResult } from '@catalogfi/utils';
|
|
2
|
+
import { IBitcoinProvider } from '@catalogfi/wallets';
|
|
3
|
+
import { WalletClient } from 'viem';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches the latest block number of EVM chain
|
|
7
|
+
* @param walletClient Wallet client
|
|
8
|
+
* @returns EVM latest block number
|
|
9
|
+
*/
|
|
10
|
+
export declare const fetchEVMBlockNumber: (walletClient: WalletClient) => AsyncResult<number, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Fetches the latest block number of Bitcoin chain
|
|
13
|
+
* @param btcProvider Bitcoin provider
|
|
14
|
+
* @returns bitcoin latest block number
|
|
15
|
+
*/
|
|
16
|
+
export declare const fetchBitcoinBlockNumber: (btcProvider: IBitcoinProvider) => AsyncResult<number, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns L1 blockNumber
|
|
19
|
+
* @returns Ethereum chain latest block number
|
|
20
|
+
*/
|
|
21
|
+
export declare const fetchL1BlockNumber: () => Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<number, never>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
2
|
+
import { IStore } from '@gardenfi/utils';
|
|
3
|
+
import { IOrderCache, OrderCacheAction, OrderCacheValue } from './orderExecutor.types';
|
|
4
|
+
|
|
5
|
+
export declare class OrderCache implements IOrderCache {
|
|
6
|
+
private order;
|
|
7
|
+
private store;
|
|
8
|
+
private cacheExpirationDuration;
|
|
9
|
+
constructor(order: MatchedOrder, store: IStore);
|
|
10
|
+
getOrder(): MatchedOrder;
|
|
11
|
+
set(action: OrderCacheAction, txHash: string): void;
|
|
12
|
+
get(action: OrderCacheAction): OrderCacheValue | null;
|
|
13
|
+
remove(action: OrderCacheAction): void;
|
|
14
|
+
deleteHistory(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WalletClient } from 'viem';
|
|
2
|
+
import { ExecuteParams, IOrderExecutor } from './orderExecutor.types';
|
|
3
|
+
import { IBitcoinWallet } from '@catalogfi/wallets';
|
|
4
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
5
|
+
import { IStore } from '@gardenfi/utils';
|
|
6
|
+
import { AsyncResult } from '@catalogfi/utils';
|
|
7
|
+
import { ISecretManager } from '../secretManager/secretManager.types';
|
|
8
|
+
|
|
9
|
+
export declare class OrderExecutor implements IOrderExecutor {
|
|
10
|
+
private order;
|
|
11
|
+
private relayURL;
|
|
12
|
+
private secretManager;
|
|
13
|
+
private opts;
|
|
14
|
+
private orderCache;
|
|
15
|
+
constructor(order: MatchedOrder, relayURL: string, secretManager: ISecretManager, opts?: {
|
|
16
|
+
store?: IStore;
|
|
17
|
+
domain?: string;
|
|
18
|
+
});
|
|
19
|
+
getOrder(): MatchedOrder;
|
|
20
|
+
init(walletClient: WalletClient, currentBlockNumber: number): AsyncResult<string, string>;
|
|
21
|
+
redeem(wallet: WalletClient | IBitcoinWallet, secret: string): AsyncResult<string, string>;
|
|
22
|
+
refund(wallet: IBitcoinWallet): AsyncResult<string, string>;
|
|
23
|
+
execute(params: ExecuteParams): AsyncResult<string | void, string>;
|
|
24
|
+
private fetchCurrentBlockNumber;
|
|
25
|
+
}
|