@gardenfi/core 2.1.14 → 2.2.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-CQkMVqmN.cjs → ccip-B4Z6_o5z.cjs} +1 -1
- package/dist/{ccip-DgpQO1MZ.js → ccip-cu_e7Kb7.js} +1 -1
- package/dist/index-CslSAu9n.js +26584 -0
- package/dist/index-aGo-Fuz8.cjs +84 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +25 -21
- package/dist/src/index.d.ts +4 -1
- package/dist/src/lib/constants.d.ts +6 -0
- package/dist/src/lib/garden/garden.d.ts +11 -1
- package/dist/src/lib/garden/garden.types.d.ts +12 -1
- package/dist/src/lib/solana/htlc/ISolanaHTLC.d.ts +28 -0
- package/dist/src/lib/solana/htlc/solanaHTLC.d.ts +56 -0
- package/dist/src/lib/solana/idl/solana_native_swaps.d.ts +299 -0
- package/dist/src/lib/solana/idl/solana_native_swaps.json.d.ts +296 -0
- package/dist/src/lib/solana/relayer/solanaRelay.d.ts +71 -0
- package/dist/src/lib/solana/solanaTypes.d.ts +31 -0
- package/dist/src/lib/utils.d.ts +2 -0
- package/package.json +5 -3
- package/dist/index-BwOLJ71D.cjs +0 -75
- package/dist/index-CAqXP6qV.js +0 -24196
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
"address": "2bag6xpshpvPe7SJ9nSDLHpxqhEAoHPGpEkjNSv7gxoF",
|
|
3
|
+
"metadata": {
|
|
4
|
+
"name": "solana_native_swaps",
|
|
5
|
+
"version": "0.3.0",
|
|
6
|
+
"spec": "0.1.0",
|
|
7
|
+
"description": "Created with Anchor"
|
|
8
|
+
},
|
|
9
|
+
"instructions": [
|
|
10
|
+
{
|
|
11
|
+
"name": "initiate",
|
|
12
|
+
"discriminator": [5, 63, 123, 113, 153, 75, 148, 14],
|
|
13
|
+
"accounts": [
|
|
14
|
+
{
|
|
15
|
+
"name": "swap_account",
|
|
16
|
+
"writable": true,
|
|
17
|
+
"pda": {
|
|
18
|
+
"seeds": [
|
|
19
|
+
{
|
|
20
|
+
"kind": "const",
|
|
21
|
+
"value": [115, 119, 97, 112, 95, 97, 99, 99, 111, 117, 110, 116]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"kind": "account",
|
|
25
|
+
"path": "initiator"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"kind": "arg",
|
|
29
|
+
"path": "secret_hash"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "initiator",
|
|
36
|
+
"docs": ["Initiator must sign this transaction"],
|
|
37
|
+
"writable": true,
|
|
38
|
+
"signer": true
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "system_program",
|
|
42
|
+
"address": "11111111111111111111111111111111"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"args": [
|
|
46
|
+
{
|
|
47
|
+
"name": "amount_lamports",
|
|
48
|
+
"type": "u64"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "expires_in_slots",
|
|
52
|
+
"type": "u64"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "redeemer",
|
|
56
|
+
"type": "pubkey"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "secret_hash",
|
|
60
|
+
"type": {
|
|
61
|
+
"array": ["u8", 32]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "instant_refund",
|
|
68
|
+
"discriminator": [211, 202, 103, 41, 183, 147, 59, 251],
|
|
69
|
+
"accounts": [
|
|
70
|
+
{
|
|
71
|
+
"name": "swap_account",
|
|
72
|
+
"writable": true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "initiator",
|
|
76
|
+
"writable": true
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "redeemer",
|
|
80
|
+
"docs": ["Redeemer must sign this transaction"],
|
|
81
|
+
"signer": true
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"args": []
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "redeem",
|
|
88
|
+
"discriminator": [184, 12, 86, 149, 70, 196, 97, 225],
|
|
89
|
+
"accounts": [
|
|
90
|
+
{
|
|
91
|
+
"name": "swap_account",
|
|
92
|
+
"writable": true
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "initiator",
|
|
96
|
+
"docs": [
|
|
97
|
+
"This is included here for the PDA rent refund using the `close` attribute above"
|
|
98
|
+
],
|
|
99
|
+
"writable": true
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "redeemer",
|
|
103
|
+
"writable": true
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"args": [
|
|
107
|
+
{
|
|
108
|
+
"name": "secret",
|
|
109
|
+
"type": {
|
|
110
|
+
"array": ["u8", 32]
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "refund",
|
|
117
|
+
"discriminator": [2, 96, 183, 251, 63, 208, 46, 46],
|
|
118
|
+
"accounts": [
|
|
119
|
+
{
|
|
120
|
+
"name": "swap_account",
|
|
121
|
+
"writable": true
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "initiator",
|
|
125
|
+
"writable": true
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"args": []
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"accounts": [
|
|
132
|
+
{
|
|
133
|
+
"name": "SwapAccount",
|
|
134
|
+
"discriminator": [53, 126, 9, 14, 14, 197, 105, 182]
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"events": [
|
|
138
|
+
{
|
|
139
|
+
"name": "Initiated",
|
|
140
|
+
"discriminator": [6, 108, 212, 91, 67, 60, 207, 221]
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "InstantRefunded",
|
|
144
|
+
"discriminator": [220, 50, 18, 207, 183, 232, 218, 25]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"name": "Redeemed",
|
|
148
|
+
"discriminator": [14, 29, 183, 71, 31, 165, 107, 38]
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "Refunded",
|
|
152
|
+
"discriminator": [35, 103, 149, 246, 196, 123, 221, 99]
|
|
153
|
+
}
|
|
154
|
+
],
|
|
155
|
+
"errors": [
|
|
156
|
+
{
|
|
157
|
+
"code": 6000,
|
|
158
|
+
"name": "InvalidInitiator",
|
|
159
|
+
"msg": "The provided initiator is not the original initiator of this swap account"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"code": 6001,
|
|
163
|
+
"name": "InvalidRedeemer",
|
|
164
|
+
"msg": "The provided redeemer is not the original redeemer of this swap amount"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"code": 6002,
|
|
168
|
+
"name": "InvalidSecret",
|
|
169
|
+
"msg": "The provided secret does not correspond to the secret hash in the swap account"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"code": 6003,
|
|
173
|
+
"name": "RefundBeforeExpiry",
|
|
174
|
+
"msg": "Attempt to perform a refund before expiry time"
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
"types": [
|
|
178
|
+
{
|
|
179
|
+
"name": "Initiated",
|
|
180
|
+
"type": {
|
|
181
|
+
"kind": "struct",
|
|
182
|
+
"fields": [
|
|
183
|
+
{
|
|
184
|
+
"name": "amount_lamports",
|
|
185
|
+
"type": "u64"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"name": "expires_in_slots",
|
|
189
|
+
"type": "u64"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"name": "initiator",
|
|
193
|
+
"type": "pubkey"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"name": "redeemer",
|
|
197
|
+
"type": "pubkey"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"name": "secret_hash",
|
|
201
|
+
"type": {
|
|
202
|
+
"array": ["u8", 32]
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"name": "InstantRefunded",
|
|
210
|
+
"type": {
|
|
211
|
+
"kind": "struct",
|
|
212
|
+
"fields": [
|
|
213
|
+
{
|
|
214
|
+
"name": "initiator",
|
|
215
|
+
"type": "pubkey"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"name": "secret_hash",
|
|
219
|
+
"type": {
|
|
220
|
+
"array": ["u8", 32]
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"name": "Redeemed",
|
|
228
|
+
"type": {
|
|
229
|
+
"kind": "struct",
|
|
230
|
+
"fields": [
|
|
231
|
+
{
|
|
232
|
+
"name": "initiator",
|
|
233
|
+
"type": "pubkey"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"name": "secret",
|
|
237
|
+
"type": {
|
|
238
|
+
"array": ["u8", 32]
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"name": "Refunded",
|
|
246
|
+
"type": {
|
|
247
|
+
"kind": "struct",
|
|
248
|
+
"fields": [
|
|
249
|
+
{
|
|
250
|
+
"name": "initiator",
|
|
251
|
+
"type": "pubkey"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"name": "secret_hash",
|
|
255
|
+
"type": {
|
|
256
|
+
"array": ["u8", 32]
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"name": "SwapAccount",
|
|
264
|
+
"type": {
|
|
265
|
+
"kind": "struct",
|
|
266
|
+
"fields": [
|
|
267
|
+
{
|
|
268
|
+
"name": "amount_lamports",
|
|
269
|
+
"type": "u64"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"name": "expiry_slot",
|
|
273
|
+
"type": "u64"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"name": "initiator",
|
|
277
|
+
"type": "pubkey"
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"name": "redeemer",
|
|
281
|
+
"type": "pubkey"
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
"name": "secret_hash",
|
|
285
|
+
"type": {
|
|
286
|
+
"array": ["u8", 32]
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
;
|
|
295
|
+
|
|
296
|
+
export default _default;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
2
|
+
import { AsyncResult } from '@catalogfi/utils';
|
|
3
|
+
import { Url } from '@gardenfi/utils';
|
|
4
|
+
import { ISolanaHTLC } from '../htlc/ISolanaHTLC';
|
|
5
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A Relay is an endpoint that submits the transaction on-chain on one's behalf, paying any fees.
|
|
9
|
+
* SolanaRelay is one such implementation performs the atomic swaps through a given relayer url.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SolanaRelay implements ISolanaHTLC {
|
|
12
|
+
private provider;
|
|
13
|
+
private url;
|
|
14
|
+
/**
|
|
15
|
+
* The on-chain Program Derived Address (PDA) that facilitates this swap.
|
|
16
|
+
* A PDA represents an on-chain memory space. It can store SOL too and is owned by a program (that derived it).
|
|
17
|
+
* This PDA stores the swap state (initiator, redeemer, secrethash etc) on-chain and also escrows the SOL.
|
|
18
|
+
*/
|
|
19
|
+
private swapAccount?;
|
|
20
|
+
private program;
|
|
21
|
+
private relayer;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new instance of SolanaRelay.
|
|
24
|
+
* @param {AnchorProvider} provider - An abstraction of RPC connection and a Wallet
|
|
25
|
+
* @param {Url} endpoint - API endpoint of the relayer node
|
|
26
|
+
* @param {string} relayer - On-chain address of the relayer in base58 format
|
|
27
|
+
* @throws {Error} If any required parameters are missing or invalid
|
|
28
|
+
*/
|
|
29
|
+
constructor(provider: AnchorProvider, url: Url, relayer: string, programAddress: string);
|
|
30
|
+
/**
|
|
31
|
+
* Gets the on-chain address of the atomic swap program.
|
|
32
|
+
* @returns {string} The program's on-chain address in base58 format
|
|
33
|
+
* @throws {Error} If no program ID is found
|
|
34
|
+
*/
|
|
35
|
+
get htlcActorAddress(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Sends a transaction via the relayer.
|
|
38
|
+
* @param {web3.Transaction} transaction - The transaction to send
|
|
39
|
+
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
40
|
+
* - Ok with the transaction ID on success
|
|
41
|
+
* - Err with an error message on failure
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
private sendViaRelayer;
|
|
45
|
+
private initiateViaHTLC;
|
|
46
|
+
/**
|
|
47
|
+
* Initiates a swap by creating a new swap account and locking funds.
|
|
48
|
+
* @param {MatchedOrder} order - The matched order containing swap details
|
|
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
|
+
*/
|
|
53
|
+
initiate(order: MatchedOrder): AsyncResult<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* Redeems a swap by providing the secret.
|
|
56
|
+
* @param {MatchedOrder} order - Matched order object containing swap details
|
|
57
|
+
* @param {string} secret - Secret key in hex format
|
|
58
|
+
* @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
|
|
59
|
+
* - Ok with the transaction ID on success
|
|
60
|
+
* - Err with an error message on failure
|
|
61
|
+
*/
|
|
62
|
+
redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* DO NOT CALL THIS FUNCTION. Refund is automatically taken care of by the relayer!
|
|
65
|
+
* This method exists only to satisfy the ISolanaHTLC interface but is not intended for direct use.
|
|
66
|
+
* @param order - Matched order object
|
|
67
|
+
* @returns {AsyncResult<string, string>} Always returns an error message
|
|
68
|
+
* @deprecated This function should never be called directly
|
|
69
|
+
*/
|
|
70
|
+
refund(): AsyncResult<string, string>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { web3, BN } from '@coral-xyz/anchor';
|
|
2
|
+
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A Swap configuration in Solana
|
|
6
|
+
*/
|
|
7
|
+
export declare class SwapConfig {
|
|
8
|
+
swapId: number[];
|
|
9
|
+
redeemer: web3.PublicKey;
|
|
10
|
+
secretHash: number[];
|
|
11
|
+
amount: BN;
|
|
12
|
+
expiresIn: BN;
|
|
13
|
+
/**
|
|
14
|
+
* @param swapId - A Unique 32-bit ID to represent this configuration in hex
|
|
15
|
+
* @param redeemer - The Solana address of redeemer in base58
|
|
16
|
+
* @param secretHash - The 32-bit Secret Hash used for this Swap in hex
|
|
17
|
+
* @param amount - The Swap amount in lowest denomination
|
|
18
|
+
* @param expiresIn - The number of Slots in which the Swap should expire. (1 Solana Slot = 400 ms)
|
|
19
|
+
*/
|
|
20
|
+
constructor(swapId: string, redeemer: string, secretHash: string, amount: bigint, expiresIn: number);
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a SwapConfig from a matched order object with Solana as a source swap
|
|
23
|
+
* @param order - The MatchedOrder with a Solana as source swap
|
|
24
|
+
*/
|
|
25
|
+
static from(order: MatchedOrder): SwapConfig;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether given secret is a valid 32 byte hex string.
|
|
29
|
+
* @returns Validated and decoded secret
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateSecret(secret: string): number[];
|
package/dist/src/lib/utils.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Chain } from '@gardenfi/orderbook';
|
|
|
4
4
|
import { Signature } from 'starknet';
|
|
5
5
|
import { Api } from './constants';
|
|
6
6
|
import { ApiConfig } from './garden/garden.types';
|
|
7
|
+
import { web3 } from '@coral-xyz/anchor';
|
|
7
8
|
|
|
8
9
|
export declare function resolveApiConfig(env: ApiConfig): {
|
|
9
10
|
api: Api;
|
|
@@ -32,3 +33,4 @@ export declare function validateBTCAddress(address: string, networkType: Environ
|
|
|
32
33
|
export declare const getBitcoinNetwork: (network: Environment) => BitcoinNetwork;
|
|
33
34
|
export declare const isHexString: (value: string) => boolean;
|
|
34
35
|
export declare const formatStarknetSignature: (sig: Signature) => Ok<string[]> | Err<string>;
|
|
36
|
+
export declare const waitForSolanaTxConfirmation: (connection: web3.Connection, txHash: string) => Promise<boolean>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -26,9 +26,11 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org/"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@catalogfi/utils": "^0.1.6",
|
|
29
30
|
"@catalogfi/wallets": "^0.2.59",
|
|
30
|
-
"@
|
|
31
|
-
"@gardenfi/
|
|
31
|
+
"@coral-xyz/anchor": "^0.30.1",
|
|
32
|
+
"@gardenfi/orderbook": "2.2.0",
|
|
33
|
+
"@gardenfi/utils": "2.2.0",
|
|
32
34
|
"bignumber.js": "^9.1.2",
|
|
33
35
|
"bitcoinjs-lib": "^6.1.6",
|
|
34
36
|
"starknet": "6.23.1",
|