@luxfi/exchange 0.1.0 → 0.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.
@@ -0,0 +1,578 @@
1
+ /**
2
+ * Private Teleport Types
3
+ *
4
+ * Types for cross-chain private teleportation using Z-Chain privacy layer
5
+ * Flow: XVM UTXO → Warp → ZNote (shielded) → Z-Chain AMM (private swap) → C-Chain/XVM
6
+ */
7
+
8
+ // ═══════════════════════════════════════════════════════════════════════════
9
+ // TELEPORT STATE
10
+ // ═══════════════════════════════════════════════════════════════════════════
11
+
12
+ /** Teleport state enum (matches contract) */
13
+ export enum TeleportState {
14
+ INITIATED = 0, // Waiting for Warp message
15
+ SHIELDED = 1, // ZNote created, amount hidden
16
+ SWAP_COMPLETE = 2, // Private swap completed on Z-Chain AMM
17
+ EXPORTED = 3, // Sending to destination chain
18
+ COMPLETED = 4, // Fully settled
19
+ CANCELLED = 5, // User or timeout cancelled
20
+ EXPIRED = 6, // Deadline passed
21
+ }
22
+
23
+ /** String state type for backward compatibility */
24
+ export type TeleportStateString =
25
+ | 'pending' // Waiting for Warp message
26
+ | 'shielded' // ZNote created, amount hidden
27
+ | 'swapped' // Private swap completed on Z-Chain AMM
28
+ | 'exporting' // Sending to destination chain
29
+ | 'complete' // Fully settled
30
+ | 'cancelled' // User or timeout cancelled
31
+ | 'expired' // Deadline passed
32
+
33
+ // ═══════════════════════════════════════════════════════════════════════════
34
+ // TELEPORT CONFIGURATION
35
+ // ═══════════════════════════════════════════════════════════════════════════
36
+
37
+ export interface PrivateTeleportConfig {
38
+ /** Network ID */
39
+ networkId: number
40
+ /** PrivateTeleport contract address */
41
+ teleportContract: `0x${string}`
42
+ /** ZNote contract address */
43
+ zNoteContract: `0x${string}`
44
+ /** ZChainAMM contract address */
45
+ zChainAMMContract: `0x${string}`
46
+ /** PrivateBridge contract address */
47
+ privateBridgeContract: `0x${string}`
48
+ /** Warp precompile address */
49
+ warpPrecompile: `0x${string}`
50
+ /** Default deadline in seconds */
51
+ defaultDeadline: number
52
+ /** Minimum blocks for shield protection */
53
+ minShieldBlocks: number
54
+ }
55
+
56
+ export const DEFAULT_PRIVATE_TELEPORT_CONFIG: PrivateTeleportConfig = {
57
+ networkId: 1,
58
+ teleportContract: '0x0000000000000000000000000000000000000420',
59
+ zNoteContract: '0x0000000000000000000000000000000000000421',
60
+ zChainAMMContract: '0x0000000000000000000000000000000000000422',
61
+ privateBridgeContract: '0x0000000000000000000000000000000000000423',
62
+ warpPrecompile: '0x0200000000000000000000000000000000000005',
63
+ defaultDeadline: 3600,
64
+ minShieldBlocks: 5,
65
+ }
66
+
67
+ // ═══════════════════════════════════════════════════════════════════════════
68
+ // CHAIN IDENTIFIERS
69
+ // ═══════════════════════════════════════════════════════════════════════════
70
+
71
+ export interface ChainInfo {
72
+ chainId: `0x${string}`
73
+ name: string
74
+ type: 'xvm' | 'cchain' | 'zchain'
75
+ }
76
+
77
+ export const LUX_CHAINS: Record<string, ChainInfo> = {
78
+ xChain: {
79
+ chainId: '0x0000000000000000000000000000000000000000000000000000000000000000',
80
+ name: 'X-Chain (XVM)',
81
+ type: 'xvm',
82
+ },
83
+ cChain: {
84
+ chainId: '0x0000000000000000000000000000000000000000000000000000000000000001',
85
+ name: 'C-Chain (EVM)',
86
+ type: 'cchain',
87
+ },
88
+ zChain: {
89
+ chainId: '0x0000000000000000000000000000000000000000000000000000000000000002',
90
+ name: 'Z-Chain (Privacy)',
91
+ type: 'zchain',
92
+ },
93
+ }
94
+
95
+ // ═══════════════════════════════════════════════════════════════════════════
96
+ // PRIVACY PRIMITIVES
97
+ // ═══════════════════════════════════════════════════════════════════════════
98
+
99
+ /** Pedersen commitment to an amount */
100
+ export interface PedersenCommitment {
101
+ commitment: `0x${string}`
102
+ /** Blinding factor (only known to owner) */
103
+ blindingFactor?: `0x${string}`
104
+ }
105
+
106
+ /** FHE-encrypted value */
107
+ export interface EncryptedValue {
108
+ ciphertext: `0x${string}`
109
+ /** FHE public key used for encryption */
110
+ publicKey: `0x${string}`
111
+ }
112
+
113
+ /** Nullifier for spending a note */
114
+ export interface Nullifier {
115
+ nullifier: `0x${string}`
116
+ /** Hash of nullifier for on-chain tracking */
117
+ nullifierHash: `0x${string}`
118
+ }
119
+
120
+ /** Bulletproof range proof */
121
+ export interface RangeProof {
122
+ proof: `0x${string}`
123
+ /** Commitment being proved */
124
+ commitment: `0x${string}`
125
+ /** Range in bits (typically 64) */
126
+ rangeBits: number
127
+ }
128
+
129
+ /** Merkle proof for note membership */
130
+ export interface MerkleProof {
131
+ path: `0x${string}`[]
132
+ indices: number[]
133
+ root: `0x${string}`
134
+ }
135
+
136
+ // ═══════════════════════════════════════════════════════════════════════════
137
+ // ZNOTE TYPES
138
+ // ═══════════════════════════════════════════════════════════════════════════
139
+
140
+ /** ZNote - UTXO-style shielded note */
141
+ export interface ZNote {
142
+ /** Pedersen commitment */
143
+ commitment: `0x${string}`
144
+ /** FHE-encrypted owner viewing key */
145
+ encryptedOwner: `0x${string}`
146
+ /** FHE-encrypted value */
147
+ encryptedValue: `0x${string}`
148
+ /** Asset identifier */
149
+ assetId: `0x${string}`
150
+ /** Creation timestamp */
151
+ createdAt: bigint
152
+ /** Note index in Merkle tree */
153
+ noteIndex: number
154
+ }
155
+
156
+ /** Spend proof for a ZNote */
157
+ export interface SpendProof {
158
+ nullifier: `0x${string}`
159
+ merkleRoot: `0x${string}`
160
+ merkleProof: `0x${string}`[]
161
+ zkProof: `0x${string}`
162
+ }
163
+
164
+ // ═══════════════════════════════════════════════════════════════════════════
165
+ // TELEPORT REQUEST/RECORD
166
+ // ═══════════════════════════════════════════════════════════════════════════
167
+
168
+ /** Request to initiate private teleport */
169
+ export interface PrivateTeleportRequest {
170
+ /** Source chain (typically X-Chain) */
171
+ sourceChain: `0x${string}`
172
+ /** Destination chain */
173
+ destChain: `0x${string}`
174
+ /** Source asset ID */
175
+ sourceAsset: `0x${string}`
176
+ /** Destination asset (if swapping) */
177
+ destAsset?: `0x${string}`
178
+ /** Amount to teleport (plaintext - will be encrypted) */
179
+ amount: bigint
180
+ /** Recipient address */
181
+ recipient: `0x${string}`
182
+ /** Deadline timestamp */
183
+ deadline: number
184
+ /** Whether to perform private swap on Z-Chain */
185
+ privateSwap: boolean
186
+ /** Minimum output for swap (if privateSwap) */
187
+ minReceive?: bigint
188
+ /** Pool ID for swap (if privateSwap) */
189
+ poolId?: `0x${string}`
190
+ }
191
+
192
+ /** Full teleport record with privacy metadata */
193
+ export interface TeleportRecord {
194
+ /** Unique teleport ID */
195
+ teleportId: `0x${string}`
196
+ /** Current state */
197
+ state: TeleportState
198
+ /** Source chain */
199
+ sourceChain: `0x${string}`
200
+ /** Destination chain */
201
+ destChain: `0x${string}`
202
+ /** Source asset */
203
+ sourceAsset: `0x${string}`
204
+ /** Destination asset */
205
+ destAsset: `0x${string}`
206
+ /** Pedersen commitment to amount */
207
+ noteCommitment: `0x${string}`
208
+ /** FHE-encrypted amount */
209
+ encryptedAmount: `0x${string}`
210
+ /** Nullifier hash (when spent) */
211
+ nullifierHash?: `0x${string}`
212
+ /** Sender address */
213
+ sender: `0x${string}`
214
+ /** Recipient address */
215
+ recipient: `0x${string}`
216
+ /** Deadline timestamp */
217
+ deadline: number
218
+ /** Block when teleport was created */
219
+ createdBlock: number
220
+ /** Whether private swap is enabled */
221
+ privateSwap: boolean
222
+ /** ZNote if created */
223
+ note?: ZNote
224
+ /** Merkle proof for export */
225
+ merkleProof?: MerkleProof
226
+ /** Range proof for withdrawal */
227
+ rangeProof?: RangeProof
228
+ }
229
+
230
+ // ═══════════════════════════════════════════════════════════════════════════
231
+ // Z-CHAIN AMM TYPES
232
+ // ═══════════════════════════════════════════════════════════════════════════
233
+
234
+ /** Private pool on Z-Chain AMM */
235
+ export interface PrivatePool {
236
+ poolId: `0x${string}`
237
+ assetA: `0x${string}`
238
+ assetB: `0x${string}`
239
+ /** FHE-encrypted reserve A */
240
+ encryptedReserveA: `0x${string}`
241
+ /** FHE-encrypted reserve B */
242
+ encryptedReserveB: `0x${string}`
243
+ /** Fee rate in basis points */
244
+ feeRate: number
245
+ active: boolean
246
+ }
247
+
248
+ /** Private swap request */
249
+ export interface PrivateSwapRequest {
250
+ poolId: `0x${string}`
251
+ /** FHE-encrypted input amount */
252
+ encryptedInput: `0x${string}`
253
+ /** FHE-encrypted minimum output */
254
+ encryptedMinOutput: `0x${string}`
255
+ /** Input note nullifier */
256
+ inputNullifier: `0x${string}`
257
+ /** Output note commitment */
258
+ outputCommitment: `0x${string}`
259
+ /** ZK proof of valid swap */
260
+ swapProof: `0x${string}`
261
+ }
262
+
263
+ // ═══════════════════════════════════════════════════════════════════════════
264
+ // WARP MESSAGE TYPES
265
+ // ═══════════════════════════════════════════════════════════════════════════
266
+
267
+ /** Warp message for teleport */
268
+ export interface TeleportWarpMessage {
269
+ /** Source chain ID */
270
+ sourceChainId: `0x${string}`
271
+ /** Source asset */
272
+ sourceAsset: `0x${string}`
273
+ /** Sender address (X-Chain format) */
274
+ sender: string
275
+ /** Deadline timestamp */
276
+ deadline: number
277
+ /** Pedersen commitment */
278
+ commitment: `0x${string}`
279
+ /** FHE-encrypted amount */
280
+ encryptedAmount: `0x${string}`
281
+ /** BLS aggregated signature */
282
+ signature: `0x${string}`
283
+ /** Signing validators */
284
+ signers: `0x${string}`[]
285
+ }
286
+
287
+ // ═══════════════════════════════════════════════════════════════════════════
288
+ // PROOF GENERATION
289
+ // ═══════════════════════════════════════════════════════════════════════════
290
+
291
+ /** Input for generating Pedersen commitment */
292
+ export interface CommitmentInput {
293
+ amount: bigint
294
+ blindingFactor?: `0x${string}`
295
+ asset: `0x${string}`
296
+ nonce?: `0x${string}`
297
+ }
298
+
299
+ /** Input for generating nullifier */
300
+ export interface NullifierInput {
301
+ commitment: `0x${string}`
302
+ /** Secret spending key */
303
+ spendingKey: `0x${string}`
304
+ noteIndex: number
305
+ }
306
+
307
+ /** Input for generating range proof */
308
+ export interface RangeProofInput {
309
+ amount: bigint
310
+ commitment: `0x${string}`
311
+ blindingFactor: `0x${string}`
312
+ rangeBits?: number // Default 64
313
+ }
314
+
315
+ // ═══════════════════════════════════════════════════════════════════════════
316
+ // CONTRACT ABIS (PARTIAL)
317
+ // ═══════════════════════════════════════════════════════════════════════════
318
+
319
+ export const PRIVATE_TELEPORT_ABI = [
320
+ // ═══════════════════════════════════════════════════════════════════════════
321
+ // INITIATE & SWAP
322
+ // ═══════════════════════════════════════════════════════════════════════════
323
+ {
324
+ name: 'initiateTeleport',
325
+ type: 'function',
326
+ stateMutability: 'nonpayable',
327
+ inputs: [
328
+ { name: 'warpMessage', type: 'bytes' },
329
+ { name: 'commitment', type: 'bytes32' },
330
+ { name: 'encryptedAmount', type: 'bytes32' },
331
+ { name: 'recipient', type: 'address' },
332
+ { name: 'destChain', type: 'bytes32' },
333
+ { name: 'destAsset', type: 'bytes32' },
334
+ { name: 'privateSwap', type: 'bool' },
335
+ ],
336
+ outputs: [{ name: 'teleportId', type: 'bytes32' }],
337
+ },
338
+ {
339
+ name: 'executePrivateSwap',
340
+ type: 'function',
341
+ stateMutability: 'nonpayable',
342
+ inputs: [
343
+ { name: 'teleportId', type: 'bytes32' },
344
+ { name: 'poolId', type: 'bytes32' },
345
+ { name: 'minOutput', type: 'bytes32' },
346
+ { name: 'proof', type: 'bytes' },
347
+ ],
348
+ outputs: [],
349
+ },
350
+ // ═══════════════════════════════════════════════════════════════════════════
351
+ // EXPORT (UNSHIELD)
352
+ // ═══════════════════════════════════════════════════════════════════════════
353
+ {
354
+ name: 'exportToDestination',
355
+ type: 'function',
356
+ stateMutability: 'nonpayable',
357
+ inputs: [
358
+ { name: 'teleportId', type: 'bytes32' },
359
+ { name: 'rangeProof', type: 'bytes' },
360
+ { name: 'nullifier', type: 'bytes32' },
361
+ { name: 'merkleProof', type: 'bytes32[]' },
362
+ ],
363
+ outputs: [],
364
+ },
365
+ {
366
+ name: 'unshieldToXChain',
367
+ type: 'function',
368
+ stateMutability: 'nonpayable',
369
+ inputs: [
370
+ { name: 'teleportId', type: 'bytes32' },
371
+ { name: 'destinationAddress', type: 'bytes' },
372
+ { name: 'amount', type: 'uint64' },
373
+ { name: 'nullifier', type: 'bytes32' },
374
+ { name: 'merkleProof', type: 'bytes32[]' },
375
+ { name: 'rangeProof', type: 'bytes' },
376
+ ],
377
+ outputs: [{ name: 'exportTxId', type: 'bytes32' }],
378
+ },
379
+ // ═══════════════════════════════════════════════════════════════════════════
380
+ // PRIVATE TRANSFERS (STAY SHIELDED)
381
+ // ═══════════════════════════════════════════════════════════════════════════
382
+ {
383
+ name: 'privateTransferToRecipient',
384
+ type: 'function',
385
+ stateMutability: 'nonpayable',
386
+ inputs: [
387
+ { name: 'teleportId', type: 'bytes32' },
388
+ { name: 'recipientCommitment', type: 'bytes32' },
389
+ { name: 'encryptedNote', type: 'bytes' },
390
+ { name: 'nullifier', type: 'bytes32' },
391
+ { name: 'merkleProof', type: 'bytes32[]' },
392
+ { name: 'transferProof', type: 'bytes' },
393
+ ],
394
+ outputs: [{ name: 'newNoteIndex', type: 'uint256' }],
395
+ },
396
+ {
397
+ name: 'splitAndTransfer',
398
+ type: 'function',
399
+ stateMutability: 'nonpayable',
400
+ inputs: [
401
+ { name: 'teleportId', type: 'bytes32' },
402
+ { name: 'outputs', type: 'tuple[]', components: [
403
+ { name: 'commitment', type: 'bytes32' },
404
+ { name: 'encryptedNote', type: 'bytes' },
405
+ { name: 'encryptedMemo', type: 'bytes' },
406
+ ]},
407
+ { name: 'nullifier', type: 'bytes32' },
408
+ { name: 'merkleProof', type: 'bytes32[]' },
409
+ { name: 'splitProof', type: 'bytes' },
410
+ ],
411
+ outputs: [{ name: 'noteIndices', type: 'uint256[]' }],
412
+ },
413
+ // ═══════════════════════════════════════════════════════════════════════════
414
+ // COMPLETE & CANCEL
415
+ // ═══════════════════════════════════════════════════════════════════════════
416
+ {
417
+ name: 'completeTeleport',
418
+ type: 'function',
419
+ stateMutability: 'nonpayable',
420
+ inputs: [
421
+ { name: 'teleportId', type: 'bytes32' },
422
+ { name: 'warpConfirmation', type: 'bytes' },
423
+ ],
424
+ outputs: [],
425
+ },
426
+ {
427
+ name: 'cancelTeleport',
428
+ type: 'function',
429
+ stateMutability: 'nonpayable',
430
+ inputs: [{ name: 'teleportId', type: 'bytes32' }],
431
+ outputs: [],
432
+ },
433
+ {
434
+ name: 'getTeleport',
435
+ type: 'function',
436
+ stateMutability: 'view',
437
+ inputs: [{ name: 'teleportId', type: 'bytes32' }],
438
+ outputs: [
439
+ {
440
+ name: '',
441
+ type: 'tuple',
442
+ components: [
443
+ { name: 'teleportId', type: 'bytes32' },
444
+ { name: 'state', type: 'uint8' },
445
+ { name: 'sourceChain', type: 'bytes32' },
446
+ { name: 'destChain', type: 'bytes32' },
447
+ { name: 'sourceAsset', type: 'bytes32' },
448
+ { name: 'destAsset', type: 'bytes32' },
449
+ { name: 'noteCommitment', type: 'bytes32' },
450
+ { name: 'encryptedAmount', type: 'bytes32' },
451
+ { name: 'nullifierHash', type: 'bytes32' },
452
+ { name: 'sender', type: 'address' },
453
+ { name: 'recipient', type: 'address' },
454
+ { name: 'deadline', type: 'uint256' },
455
+ { name: 'createdBlock', type: 'uint256' },
456
+ { name: 'privateSwap', type: 'bool' },
457
+ ],
458
+ },
459
+ ],
460
+ },
461
+ {
462
+ name: 'isComplete',
463
+ type: 'function',
464
+ stateMutability: 'view',
465
+ inputs: [{ name: 'teleportId', type: 'bytes32' }],
466
+ outputs: [{ name: '', type: 'bool' }],
467
+ },
468
+ {
469
+ name: 'isExpired',
470
+ type: 'function',
471
+ stateMutability: 'view',
472
+ inputs: [{ name: 'teleportId', type: 'bytes32' }],
473
+ outputs: [{ name: '', type: 'bool' }],
474
+ },
475
+ ] as const
476
+
477
+ export const ZNOTE_ABI = [
478
+ {
479
+ name: 'importFromXChain',
480
+ type: 'function',
481
+ stateMutability: 'nonpayable',
482
+ inputs: [
483
+ { name: 'commitment', type: 'bytes32' },
484
+ { name: 'encryptedAmount', type: 'bytes32' },
485
+ { name: 'assetId', type: 'bytes32' },
486
+ { name: 'recipient', type: 'address' },
487
+ ],
488
+ outputs: [{ name: 'noteIndex', type: 'uint256' }],
489
+ },
490
+ {
491
+ name: 'verifyMerkleProof',
492
+ type: 'function',
493
+ stateMutability: 'view',
494
+ inputs: [
495
+ { name: 'proof', type: 'bytes32[]' },
496
+ { name: 'commitment', type: 'bytes32' },
497
+ ],
498
+ outputs: [{ name: '', type: 'bool' }],
499
+ },
500
+ {
501
+ name: 'getMerkleProof',
502
+ type: 'function',
503
+ stateMutability: 'view',
504
+ inputs: [{ name: 'noteIndex', type: 'uint256' }],
505
+ outputs: [{ name: 'proof', type: 'bytes32[]' }],
506
+ },
507
+ {
508
+ name: 'getNoteRoot',
509
+ type: 'function',
510
+ stateMutability: 'view',
511
+ inputs: [],
512
+ outputs: [{ name: '', type: 'bytes32' }],
513
+ },
514
+ {
515
+ name: 'getNote',
516
+ type: 'function',
517
+ stateMutability: 'view',
518
+ inputs: [{ name: 'commitment', type: 'bytes32' }],
519
+ outputs: [
520
+ {
521
+ name: '',
522
+ type: 'tuple',
523
+ components: [
524
+ { name: 'commitment', type: 'bytes32' },
525
+ { name: 'encryptedOwner', type: 'bytes' },
526
+ { name: 'encryptedValue', type: 'bytes' },
527
+ { name: 'assetId', type: 'bytes32' },
528
+ { name: 'createdAt', type: 'uint64' },
529
+ ],
530
+ },
531
+ ],
532
+ },
533
+ ] as const
534
+
535
+ export const ZCHAIN_AMM_ABI = [
536
+ {
537
+ name: 'swapEncrypted',
538
+ type: 'function',
539
+ stateMutability: 'nonpayable',
540
+ inputs: [
541
+ { name: 'poolId', type: 'bytes32' },
542
+ { name: 'encryptedAmount', type: 'bytes32' },
543
+ { name: 'encryptedMinOutput', type: 'bytes32' },
544
+ { name: 'recipient', type: 'address' },
545
+ ],
546
+ outputs: [{ name: 'outputCommitment', type: 'bytes32' }],
547
+ },
548
+ {
549
+ name: 'verifySwapProof',
550
+ type: 'function',
551
+ stateMutability: 'view',
552
+ inputs: [
553
+ { name: 'proof', type: 'bytes' },
554
+ { name: 'commitment', type: 'bytes32' },
555
+ { name: 'poolId', type: 'bytes32' },
556
+ ],
557
+ outputs: [{ name: '', type: 'bool' }],
558
+ },
559
+ {
560
+ name: 'getPool',
561
+ type: 'function',
562
+ stateMutability: 'view',
563
+ inputs: [{ name: 'poolId', type: 'bytes32' }],
564
+ outputs: [
565
+ {
566
+ name: '',
567
+ type: 'tuple',
568
+ components: [
569
+ { name: 'poolId', type: 'bytes32' },
570
+ { name: 'assetA', type: 'bytes32' },
571
+ { name: 'assetB', type: 'bytes32' },
572
+ { name: 'feeRate', type: 'uint16' },
573
+ { name: 'active', type: 'bool' },
574
+ ],
575
+ },
576
+ ],
577
+ },
578
+ ] as const
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Cross-chain bridge types for XVM ↔ C-Chain atomic swaps
3
+ */
4
+
5
+ export type CrossChainMintStatus =
6
+ | 'idle'
7
+ | 'initiating'
8
+ | 'locking'
9
+ | 'waiting_confirmation'
10
+ | 'minting'
11
+ | 'swapping'
12
+ | 'complete'
13
+ | 'failed'
14
+ | 'cancelled'
15
+
16
+ export interface CrossChainMintRequest {
17
+ /** Source chain (XVM) asset ID */
18
+ sourceAsset: `0x${string}`
19
+ /** Amount to bridge (in source chain decimals) */
20
+ amount: bigint
21
+ /** Recipient address on C-Chain */
22
+ recipient: `0x${string}`
23
+ /** Optional: target token on C-Chain (if swap desired) */
24
+ targetToken?: `0x${string}`
25
+ /** Minimum amount to receive (slippage protection) */
26
+ minReceive?: bigint
27
+ /** Deadline timestamp in seconds */
28
+ deadline: number
29
+ }
30
+
31
+ export interface CrossChainMintState {
32
+ /** Unique swap ID from bridge */
33
+ swapId: `0x${string}` | null
34
+ /** Current status of the mint operation */
35
+ status: CrossChainMintStatus
36
+ /** Source transaction hash on X-Chain */
37
+ sourceTxHash: string | null
38
+ /** Mint transaction hash on C-Chain */
39
+ mintTxHash: string | null
40
+ /** Swap transaction hash (if target token specified) */
41
+ swapTxHash: string | null
42
+ /** Error message if failed */
43
+ error: string | null
44
+ /** Timestamp when operation started */
45
+ startedAt: number | null
46
+ /** Timestamp when operation completed */
47
+ completedAt: number | null
48
+ }
49
+
50
+ export interface SwapRoute {
51
+ tokenIn: `0x${string}`
52
+ tokenOut: `0x${string}`
53
+ poolFee: number
54
+ tickSpacing: number
55
+ hooks?: `0x${string}`
56
+ }
57
+
58
+ export interface AtomicSwapConfig {
59
+ /** Network ID for Warp messages */
60
+ networkId: number
61
+ /** XVM chain ID */
62
+ xvmChainId: `0x${string}`
63
+ /** C-Chain ID */
64
+ cChainId: `0x${string}`
65
+ /** Warp precompile address */
66
+ warpPrecompile: `0x${string}`
67
+ /** Atomic swap bridge contract on C-Chain */
68
+ bridgeContract: `0x${string}`
69
+ /** Default deadline in seconds */
70
+ defaultDeadline: number
71
+ }
72
+
73
+ export const DEFAULT_SWAP_CONFIG: AtomicSwapConfig = {
74
+ networkId: 1,
75
+ xvmChainId: '0x0000000000000000000000000000000000000000000000000000000000000000',
76
+ cChainId: '0x0000000000000000000000000000000000000000000000000000000000000000',
77
+ warpPrecompile: '0x0200000000000000000000000000000000000005',
78
+ bridgeContract: '0x0000000000000000000000000000000000000410',
79
+ defaultDeadline: 3600, // 1 hour
80
+ }
81
+
82
+ /**
83
+ * XVM asset mapping to C-Chain wrapped tokens
84
+ */
85
+ export interface AssetMapping {
86
+ /** XVM asset ID */
87
+ xvmAssetId: `0x${string}`
88
+ /** C-Chain wrapped token address */
89
+ wrappedToken: `0x${string}`
90
+ /** Token symbol */
91
+ symbol: string
92
+ /** Token decimals (always 6 for XVM) */
93
+ decimals: number
94
+ }
95
+
96
+ /**
97
+ * Well-known asset mappings for Lux mainnet
98
+ */
99
+ export const ASSET_MAPPINGS: AssetMapping[] = [
100
+ {
101
+ xvmAssetId: '0x0000000000000000000000000000000000000000000000000000000000000001',
102
+ wrappedToken: '0x0000000000000000000000000000000000000001', // WLUX
103
+ symbol: 'WLUX',
104
+ decimals: 6,
105
+ },
106
+ // Add more mappings as tokens are registered
107
+ ]
108
+
109
+ /**
110
+ * Get wrapped token address for an XVM asset
111
+ */
112
+ export function getWrappedToken(xvmAssetId: `0x${string}`): `0x${string}` | null {
113
+ const mapping = ASSET_MAPPINGS.find((m) => m.xvmAssetId === xvmAssetId)
114
+ return mapping?.wrappedToken ?? null
115
+ }
116
+
117
+ /**
118
+ * Get XVM asset ID for a wrapped token
119
+ */
120
+ export function getXvmAsset(wrappedToken: `0x${string}`): `0x${string}` | null {
121
+ const mapping = ASSET_MAPPINGS.find(
122
+ (m) => m.wrappedToken.toLowerCase() === wrappedToken.toLowerCase()
123
+ )
124
+ return mapping?.xvmAssetId ?? null
125
+ }