@luxfi/exchange 0.1.0 → 1.0.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.
Files changed (69) hide show
  1. package/dist/bridge/use-private-teleport.d.ts +1 -1
  2. package/dist/bridge/use-private-teleport.d.ts.map +1 -1
  3. package/dist/bridge/use-private-teleport.js +73 -71
  4. package/dist/contracts/abis/amm-v2-factory.d.ts +148 -0
  5. package/dist/contracts/abis/amm-v2-factory.d.ts.map +1 -0
  6. package/dist/contracts/abis/amm-v2-factory.js +52 -0
  7. package/dist/contracts/abis/amm-v2-pair.d.ts +236 -0
  8. package/dist/contracts/abis/amm-v2-pair.d.ts.map +1 -0
  9. package/dist/contracts/abis/amm-v2-pair.js +88 -0
  10. package/dist/contracts/abis/amm-v2-router.d.ts +496 -0
  11. package/dist/contracts/abis/amm-v2-router.d.ts.map +1 -0
  12. package/dist/contracts/abis/amm-v2-router.js +149 -0
  13. package/dist/contracts/abis/amm-v3-factory.d.ts +152 -0
  14. package/dist/contracts/abis/amm-v3-factory.d.ts.map +1 -0
  15. package/dist/contracts/abis/amm-v3-factory.js +48 -0
  16. package/dist/contracts/abis/amm-v3-pool.d.ts +254 -0
  17. package/dist/contracts/abis/amm-v3-pool.d.ts.map +1 -0
  18. package/dist/contracts/abis/amm-v3-pool.js +84 -0
  19. package/dist/contracts/abis/index.d.ts +8 -5
  20. package/dist/contracts/abis/index.d.ts.map +1 -1
  21. package/dist/contracts/abis/index.js +13 -6
  22. package/dist/contracts/abis/lux-amm-v2-factory.d.ts +148 -0
  23. package/dist/contracts/abis/lux-amm-v2-factory.d.ts.map +1 -0
  24. package/dist/contracts/abis/lux-amm-v2-factory.js +52 -0
  25. package/dist/contracts/abis/lux-amm-v2-pair.d.ts +236 -0
  26. package/dist/contracts/abis/lux-amm-v2-pair.d.ts.map +1 -0
  27. package/dist/contracts/abis/lux-amm-v2-pair.js +88 -0
  28. package/dist/contracts/abis/lux-amm-v2-router.d.ts +496 -0
  29. package/dist/contracts/abis/lux-amm-v2-router.d.ts.map +1 -0
  30. package/dist/contracts/abis/lux-amm-v2-router.js +149 -0
  31. package/dist/contracts/abis/lux-amm-v3-factory.d.ts +152 -0
  32. package/dist/contracts/abis/lux-amm-v3-factory.d.ts.map +1 -0
  33. package/dist/contracts/abis/lux-amm-v3-factory.js +48 -0
  34. package/dist/contracts/abis/lux-amm-v3-pool.d.ts +254 -0
  35. package/dist/contracts/abis/lux-amm-v3-pool.d.ts.map +1 -0
  36. package/dist/contracts/abis/lux-amm-v3-pool.js +84 -0
  37. package/dist/contracts/addresses.d.ts +18 -48
  38. package/dist/contracts/addresses.d.ts.map +1 -1
  39. package/dist/contracts/addresses.js +30 -22
  40. package/dist/index.d.ts +1 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +2 -2
  43. package/dist/tokens/index.d.ts +25 -0
  44. package/dist/tokens/index.d.ts.map +1 -1
  45. package/dist/tokens/index.js +90 -5
  46. package/package.json +6 -2
  47. package/src/bridge/cross-chain-store.ts +210 -0
  48. package/src/bridge/index.ts +81 -0
  49. package/src/bridge/private-teleport-types.ts +578 -0
  50. package/src/bridge/types.ts +125 -0
  51. package/src/bridge/use-cross-chain-mint.ts +299 -0
  52. package/src/bridge/use-private-teleport.ts +951 -0
  53. package/src/contracts/abis/{uniswap-v2-factory.ts → amm-v2-factory.ts} +6 -2
  54. package/src/contracts/abis/{uniswap-v2-pair.ts → amm-v2-pair.ts} +6 -2
  55. package/src/contracts/abis/{uniswap-v2-router.ts → amm-v2-router.ts} +6 -2
  56. package/src/contracts/abis/{uniswap-v3-factory.ts → amm-v3-factory.ts} +6 -2
  57. package/src/contracts/abis/{uniswap-v3-pool.ts → amm-v3-pool.ts} +6 -2
  58. package/src/contracts/abis/index.ts +16 -6
  59. package/src/contracts/abis/pool-manager.ts +1 -1
  60. package/src/contracts/addresses.ts +53 -52
  61. package/src/hooks/use-pools.ts +8 -6
  62. package/src/hooks/use-positions.ts +3 -3
  63. package/src/hooks/use-swap-quote.ts +1 -1
  64. package/src/hooks/use-swap.ts +1 -1
  65. package/src/index.ts +2 -2
  66. package/src/tokens/index.ts +148 -32
  67. package/dist/bridge/__tests__/use-private-teleport.test.d.ts +0 -2
  68. package/dist/bridge/__tests__/use-private-teleport.test.d.ts.map +0 -1
  69. package/dist/bridge/__tests__/use-private-teleport.test.js +0 -272
@@ -4,7 +4,7 @@
4
4
  * React hook for cross-chain private teleportation
5
5
  * Enables: XVM UTXO → ZNote (shielded) → Z-Chain AMM → destination
6
6
  */
7
- import { type PrivateTeleportConfig, type PrivateTeleportRequest, type TeleportRecord, type TeleportState } from './private-teleport-types';
7
+ import { type PrivateTeleportConfig, type PrivateTeleportRequest, type TeleportRecord, TeleportState } from './private-teleport-types';
8
8
  export interface UsePrivateTeleportOptions {
9
9
  /** Custom config */
10
10
  config?: Partial<PrivateTeleportConfig>;
@@ -1 +1 @@
1
- {"version":3,"file":"use-private-teleport.d.ts","sourceRoot":"","sources":["../../src/bridge/use-private-teleport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,aAAa,EASnB,MAAM,0BAA0B,CAAA;AAMjC,MAAM,WAAW,yBAAyB;IACxC,oBAAoB;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAA;IACvC,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;CACnE;AAED,oDAAoD;AACpD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,gBAAgB,EAAE,KAAK,MAAM,EAAE,CAAA;IAC/B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAA;I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B;IAC1B,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACnE,oCAAoC;IACpC,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACpD,mCAAmC;IACnC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,6BAA6B;IAC7B,YAAY,EAAE,aAAa,GAAG,IAAI,CAAA;IAClC,oBAAoB;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,kBAAkB;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAqGD,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,wBAAwB,CA4uB1B;AAGD,YAAY,EACV,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,qBAAqB,GACtB,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"use-private-teleport.d.ts","sourceRoot":"","sources":["../../src/bridge/use-private-teleport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,aAAa,EAUd,MAAM,0BAA0B,CAAA;AAMjC,MAAM,WAAW,yBAAyB;IACxC,oBAAoB;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAA;IACvC,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;CACnE;AAED,oDAAoD;AACpD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,gBAAgB,EAAE,KAAK,MAAM,EAAE,CAAA;IAC/B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAA;IACd,6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C1B,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACnE,oCAAoC;IACpC,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACpD,mCAAmC;IACnC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,6BAA6B;IAC7B,YAAY,EAAE,aAAa,GAAG,IAAI,CAAA;IAClC,oBAAoB;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,kBAAkB;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAqGD,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,wBAAwB,CA8uB1B;AAGD,YAAY,EACV,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,qBAAqB,GACtB,MAAM,0BAA0B,CAAA"}
@@ -7,7 +7,7 @@
7
7
  import { useCallback, useEffect, useState } from 'react';
8
8
  import { usePublicClient, useWalletClient } from 'wagmi';
9
9
  import { encodeFunctionData, keccak256, toHex } from 'viem';
10
- import { DEFAULT_PRIVATE_TELEPORT_CONFIG, PRIVATE_TELEPORT_ABI, ZNOTE_ABI, } from './private-teleport-types';
10
+ import { TeleportState, DEFAULT_PRIVATE_TELEPORT_CONFIG, PRIVATE_TELEPORT_ABI, ZNOTE_ABI, } from './private-teleport-types';
11
11
  // ═══════════════════════════════════════════════════════════════════════════
12
12
  // CRYPTO UTILITIES (STUB - REAL IMPL USES @luxfi/crypto)
13
13
  // ═══════════════════════════════════════════════════════════════════════════
@@ -20,7 +20,7 @@ async function generateCommitment(amount, blindingFactor) {
20
20
  const bf = blindingFactor ?? toHex(BigInt(Math.random() * Number.MAX_SAFE_INTEGER));
21
21
  // Pedersen: C = g^amount * h^blinding
22
22
  // Simplified for now - real implementation uses elliptic curve ops
23
- const commitment = keccak256(toHex(amount) + bf.slice(2));
23
+ const commitment = keccak256(`${toHex(amount)}${bf.slice(2)}`);
24
24
  return {
25
25
  commitment,
26
26
  blindingFactor: bf,
@@ -32,7 +32,7 @@ async function generateCommitment(amount, blindingFactor) {
32
32
  */
33
33
  async function fheEncrypt(value, publicKey) {
34
34
  // Simplified - real implementation uses TFHE
35
- const ciphertext = keccak256(toHex(value) + publicKey.slice(2));
35
+ const ciphertext = keccak256(`${toHex(value)}${publicKey.slice(2)}`);
36
36
  return {
37
37
  ciphertext,
38
38
  publicKey,
@@ -44,7 +44,7 @@ async function fheEncrypt(value, publicKey) {
44
44
  */
45
45
  async function generateRangeProof(amount, commitment, blindingFactor, rangeBits = 64) {
46
46
  // Simplified - real implementation generates actual Bulletproof
47
- const proof = keccak256(commitment + blindingFactor.slice(2) + toHex(amount).slice(2));
47
+ const proof = keccak256(`${commitment}${blindingFactor.slice(2)}${toHex(amount).slice(2)}`);
48
48
  return {
49
49
  proof,
50
50
  commitment,
@@ -55,19 +55,19 @@ async function generateRangeProof(amount, commitment, blindingFactor, rangeBits
55
55
  * Generate nullifier for spending a note
56
56
  */
57
57
  function generateNullifier(commitment, spendingKey, noteIndex) {
58
- return keccak256(commitment + spendingKey.slice(2) + toHex(noteIndex).slice(2));
58
+ return keccak256(`${commitment}${spendingKey.slice(2)}${toHex(noteIndex).slice(2)}`);
59
59
  }
60
60
  // ═══════════════════════════════════════════════════════════════════════════
61
61
  // STATE MAPPING
62
62
  // ═══════════════════════════════════════════════════════════════════════════
63
63
  const stateMap = {
64
- 0: 'pending',
65
- 1: 'shielded',
66
- 2: 'swapped',
67
- 3: 'exporting',
68
- 4: 'complete',
69
- 5: 'cancelled',
70
- 6: 'expired',
64
+ 0: TeleportState.INITIATED,
65
+ 1: TeleportState.SHIELDED,
66
+ 2: TeleportState.SWAP_COMPLETE,
67
+ 3: TeleportState.EXPORTED,
68
+ 4: TeleportState.COMPLETED,
69
+ 5: TeleportState.CANCELLED,
70
+ 6: TeleportState.EXPIRED,
71
71
  };
72
72
  // ═══════════════════════════════════════════════════════════════════════════
73
73
  // HOOK IMPLEMENTATION
@@ -148,7 +148,7 @@ export function usePrivateTeleport(options = {}) {
148
148
  noteIndex: 0, // Would be extracted from event
149
149
  }));
150
150
  setCurrentTeleportId(teleportId);
151
- setCurrentState('pending');
151
+ setCurrentState(TeleportState.INITIATED);
152
152
  return teleportId;
153
153
  }
154
154
  catch (err) {
@@ -191,8 +191,8 @@ export function usePrivateTeleport(options = {}) {
191
191
  value: BigInt(0),
192
192
  });
193
193
  await publicClient.waitForTransactionReceipt({ hash });
194
- setCurrentState('swapped');
195
- onStateChange?.(teleportId, 'swapped');
194
+ setCurrentState(TeleportState.SWAP_COMPLETE);
195
+ onStateChange?.(teleportId, TeleportState.SWAP_COMPLETE);
196
196
  }
197
197
  catch (err) {
198
198
  const e = err instanceof Error ? err : new Error(String(err));
@@ -204,6 +204,46 @@ export function usePrivateTeleport(options = {}) {
204
204
  }
205
205
  }, [walletClient, publicClient, config, onStateChange]);
206
206
  // ─────────────────────────────────────────────────────────────────────────
207
+ // GET TELEPORT RECORD (defined early for use by other callbacks)
208
+ // ─────────────────────────────────────────────────────────────────────────
209
+ const getTeleportRecord = useCallback(async (teleportId) => {
210
+ if (!publicClient) {
211
+ throw new Error('Client not connected');
212
+ }
213
+ try {
214
+ const result = await publicClient.readContract({
215
+ address: config.teleportContract,
216
+ abi: PRIVATE_TELEPORT_ABI,
217
+ functionName: 'getTeleport',
218
+ args: [teleportId],
219
+ });
220
+ const tuple = result;
221
+ const [id, state, sourceChain, destChain, sourceAsset, destAsset, noteCommitment, encryptedAmount, nullifierHash, sender, recipient, deadline, createdBlock, privateSwap] = tuple;
222
+ if (id === '0x' + '00'.repeat(32)) {
223
+ return null;
224
+ }
225
+ return {
226
+ teleportId: id,
227
+ state: stateMap[state] ?? TeleportState.INITIATED,
228
+ sourceChain,
229
+ destChain,
230
+ sourceAsset,
231
+ destAsset,
232
+ noteCommitment,
233
+ encryptedAmount,
234
+ nullifierHash: nullifierHash !== '0x' + '00'.repeat(32) ? nullifierHash : undefined,
235
+ sender,
236
+ recipient,
237
+ deadline: Number(deadline),
238
+ createdBlock: Number(createdBlock),
239
+ privateSwap,
240
+ };
241
+ }
242
+ catch {
243
+ return null;
244
+ }
245
+ }, [publicClient, config]);
246
+ // ─────────────────────────────────────────────────────────────────────────
207
247
  // EXPORT TO DESTINATION
208
248
  // ─────────────────────────────────────────────────────────────────────────
209
249
  const exportToDestination = useCallback(async (teleportId) => {
@@ -250,8 +290,8 @@ export function usePrivateTeleport(options = {}) {
250
290
  value: BigInt(0),
251
291
  });
252
292
  await publicClient.waitForTransactionReceipt({ hash });
253
- setCurrentState('exporting');
254
- onStateChange?.(teleportId, 'exporting');
293
+ setCurrentState(TeleportState.EXPORTED);
294
+ onStateChange?.(teleportId, TeleportState.EXPORTED);
255
295
  }
256
296
  catch (err) {
257
297
  const e = err instanceof Error ? err : new Error(String(err));
@@ -283,8 +323,8 @@ export function usePrivateTeleport(options = {}) {
283
323
  value: BigInt(0),
284
324
  });
285
325
  await publicClient.waitForTransactionReceipt({ hash });
286
- setCurrentState('complete');
287
- onStateChange?.(teleportId, 'complete');
326
+ setCurrentState(TeleportState.COMPLETED);
327
+ onStateChange?.(teleportId, TeleportState.COMPLETED);
288
328
  // Clean up secrets
289
329
  setSecrets(prev => {
290
330
  const next = new Map(prev);
@@ -352,8 +392,8 @@ export function usePrivateTeleport(options = {}) {
352
392
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
353
393
  // Extract exportTxId from logs
354
394
  const exportTxId = receipt.logs[0]?.topics[1] ?? hash;
355
- setCurrentState('complete');
356
- onStateChange?.(request.teleportId, 'complete');
395
+ setCurrentState(TeleportState.COMPLETED);
396
+ onStateChange?.(request.teleportId, TeleportState.COMPLETED);
357
397
  // Clean up secrets
358
398
  setSecrets(prev => {
359
399
  const next = new Map(prev);
@@ -392,7 +432,7 @@ export function usePrivateTeleport(options = {}) {
392
432
  // Generate new commitment for recipient
393
433
  const recipientCommitment = await generateCommitment(request.amount);
394
434
  // Encrypt note to recipient's viewing key
395
- const encryptedNote = keccak256(request.recipientViewKey + recipientCommitment.commitment.slice(2));
435
+ const encryptedNote = keccak256(`${request.recipientViewKey}${recipientCommitment.commitment.slice(2)}`);
396
436
  // Generate nullifier
397
437
  const nullifier = generateNullifier(record.noteCommitment, secret.spendingKey, secret.noteIndex);
398
438
  // Get Merkle proof
@@ -403,7 +443,7 @@ export function usePrivateTeleport(options = {}) {
403
443
  args: [BigInt(secret.noteIndex)],
404
444
  });
405
445
  // Generate transfer proof (proves amount conservation)
406
- const transferProof = keccak256(record.noteCommitment + recipientCommitment.commitment.slice(2));
446
+ const transferProof = keccak256(`${record.noteCommitment}${recipientCommitment.commitment.slice(2)}`);
407
447
  const txData = encodeFunctionData({
408
448
  abi: PRIVATE_TELEPORT_ABI,
409
449
  functionName: 'privateTransferToRecipient',
@@ -424,8 +464,8 @@ export function usePrivateTeleport(options = {}) {
424
464
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
425
465
  // Extract note index from logs (simplified)
426
466
  const newNoteIndex = Number(receipt.logs[0]?.data?.slice(0, 66) ?? '0');
427
- setCurrentState('complete');
428
- onStateChange?.(request.teleportId, 'complete');
467
+ setCurrentState(TeleportState.COMPLETED);
468
+ onStateChange?.(request.teleportId, TeleportState.COMPLETED);
429
469
  // Clean up secrets for this teleport
430
470
  setSecrets(prev => {
431
471
  const next = new Map(prev);
@@ -467,7 +507,7 @@ export function usePrivateTeleport(options = {}) {
467
507
  // Generate commitments for each output
468
508
  const outputNotes = await Promise.all(outputs.map(async (output) => {
469
509
  const commitment = await generateCommitment(output.amount);
470
- const encryptedNote = keccak256(output.recipient + commitment.commitment.slice(2));
510
+ const encryptedNote = keccak256(`${output.recipient}${commitment.commitment.slice(2)}`);
471
511
  return {
472
512
  commitment: commitment.commitment,
473
513
  encryptedNote,
@@ -484,7 +524,7 @@ export function usePrivateTeleport(options = {}) {
484
524
  args: [BigInt(secret.noteIndex)],
485
525
  });
486
526
  // Generate split proof (proves sum of outputs = input)
487
- const splitProof = keccak256(record.noteCommitment + outputNotes.map(n => n.commitment).join(''));
527
+ const splitProof = keccak256(`${record.noteCommitment}${outputNotes.map(n => n.commitment.slice(2)).join('')}`);
488
528
  const txData = encodeFunctionData({
489
529
  abi: PRIVATE_TELEPORT_ABI,
490
530
  functionName: 'splitAndTransfer',
@@ -504,8 +544,8 @@ export function usePrivateTeleport(options = {}) {
504
544
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
505
545
  // Extract note indices from logs (simplified)
506
546
  const noteIndices = outputs.map((_, i) => i);
507
- setCurrentState('complete');
508
- onStateChange?.(teleportId, 'complete');
547
+ setCurrentState(TeleportState.COMPLETED);
548
+ onStateChange?.(teleportId, TeleportState.COMPLETED);
509
549
  // Clean up secrets for this teleport
510
550
  setSecrets(prev => {
511
551
  const next = new Map(prev);
@@ -544,8 +584,8 @@ export function usePrivateTeleport(options = {}) {
544
584
  value: BigInt(0),
545
585
  });
546
586
  await publicClient.waitForTransactionReceipt({ hash });
547
- setCurrentState('cancelled');
548
- onStateChange?.(teleportId, 'cancelled');
587
+ setCurrentState(TeleportState.CANCELLED);
588
+ onStateChange?.(teleportId, TeleportState.CANCELLED);
549
589
  // Clean up secrets
550
590
  setSecrets(prev => {
551
591
  const next = new Map(prev);
@@ -562,45 +602,7 @@ export function usePrivateTeleport(options = {}) {
562
602
  setIsLoading(false);
563
603
  }
564
604
  }, [walletClient, publicClient, config, onStateChange]);
565
- // ─────────────────────────────────────────────────────────────────────────
566
- // GET TELEPORT RECORD
567
- // ─────────────────────────────────────────────────────────────────────────
568
- const getTeleportRecord = useCallback(async (teleportId) => {
569
- if (!publicClient) {
570
- throw new Error('Client not connected');
571
- }
572
- try {
573
- const result = await publicClient.readContract({
574
- address: config.teleportContract,
575
- abi: PRIVATE_TELEPORT_ABI,
576
- functionName: 'getTeleport',
577
- args: [teleportId],
578
- });
579
- const [id, state, sourceChain, destChain, sourceAsset, destAsset, noteCommitment, encryptedAmount, nullifierHash, sender, recipient, deadline, createdBlock, privateSwap] = result;
580
- if (id === '0x' + '00'.repeat(32)) {
581
- return null;
582
- }
583
- return {
584
- teleportId: id,
585
- state: stateMap[state] ?? 'pending',
586
- sourceChain,
587
- destChain,
588
- sourceAsset,
589
- destAsset,
590
- noteCommitment,
591
- encryptedAmount,
592
- nullifierHash: nullifierHash !== '0x' + '00'.repeat(32) ? nullifierHash : undefined,
593
- sender,
594
- recipient,
595
- deadline: Number(deadline),
596
- createdBlock: Number(createdBlock),
597
- privateSwap,
598
- };
599
- }
600
- catch {
601
- return null;
602
- }
603
- }, [publicClient, config]);
605
+ // Wrapper for external API
604
606
  const getTeleport = useCallback(async (teleportId) => {
605
607
  return getTeleportRecord(teleportId);
606
608
  }, [getTeleportRecord]);
@@ -628,7 +630,7 @@ export function usePrivateTeleport(options = {}) {
628
630
  // POLLING
629
631
  // ─────────────────────────────────────────────────────────────────────────
630
632
  useEffect(() => {
631
- if (!currentTeleportId || !publicClient || currentState === 'complete' || currentState === 'cancelled') {
633
+ if (!currentTeleportId || !publicClient || currentState === TeleportState.COMPLETED || currentState === TeleportState.CANCELLED) {
632
634
  return;
633
635
  }
634
636
  const poll = async () => {
@@ -0,0 +1,148 @@
1
+ /**
2
+ * AMM V2 Factory ABI
3
+ * Compatible with Uniswap V2 Factory interface
4
+ */
5
+ export declare const AMM_V2_FACTORY_ABI: readonly [{
6
+ readonly type: "function";
7
+ readonly name: "getPair";
8
+ readonly inputs: readonly [{
9
+ readonly name: "tokenA";
10
+ readonly type: "address";
11
+ }, {
12
+ readonly name: "tokenB";
13
+ readonly type: "address";
14
+ }];
15
+ readonly outputs: readonly [{
16
+ readonly name: "pair";
17
+ readonly type: "address";
18
+ }];
19
+ readonly stateMutability: "view";
20
+ }, {
21
+ readonly type: "function";
22
+ readonly name: "allPairs";
23
+ readonly inputs: readonly [{
24
+ readonly name: "index";
25
+ readonly type: "uint256";
26
+ }];
27
+ readonly outputs: readonly [{
28
+ readonly name: "pair";
29
+ readonly type: "address";
30
+ }];
31
+ readonly stateMutability: "view";
32
+ }, {
33
+ readonly type: "function";
34
+ readonly name: "allPairsLength";
35
+ readonly inputs: readonly [];
36
+ readonly outputs: readonly [{
37
+ readonly type: "uint256";
38
+ }];
39
+ readonly stateMutability: "view";
40
+ }, {
41
+ readonly type: "function";
42
+ readonly name: "createPair";
43
+ readonly inputs: readonly [{
44
+ readonly name: "tokenA";
45
+ readonly type: "address";
46
+ }, {
47
+ readonly name: "tokenB";
48
+ readonly type: "address";
49
+ }];
50
+ readonly outputs: readonly [{
51
+ readonly name: "pair";
52
+ readonly type: "address";
53
+ }];
54
+ readonly stateMutability: "nonpayable";
55
+ }, {
56
+ readonly type: "event";
57
+ readonly name: "PairCreated";
58
+ readonly inputs: readonly [{
59
+ readonly name: "token0";
60
+ readonly type: "address";
61
+ readonly indexed: true;
62
+ }, {
63
+ readonly name: "token1";
64
+ readonly type: "address";
65
+ readonly indexed: true;
66
+ }, {
67
+ readonly name: "pair";
68
+ readonly type: "address";
69
+ readonly indexed: false;
70
+ }, {
71
+ readonly name: "index";
72
+ readonly type: "uint256";
73
+ readonly indexed: false;
74
+ }];
75
+ }];
76
+ /** @deprecated Use AMM_V2_FACTORY_ABI instead */
77
+ export declare const UNISWAP_V2_FACTORY_ABI: readonly [{
78
+ readonly type: "function";
79
+ readonly name: "getPair";
80
+ readonly inputs: readonly [{
81
+ readonly name: "tokenA";
82
+ readonly type: "address";
83
+ }, {
84
+ readonly name: "tokenB";
85
+ readonly type: "address";
86
+ }];
87
+ readonly outputs: readonly [{
88
+ readonly name: "pair";
89
+ readonly type: "address";
90
+ }];
91
+ readonly stateMutability: "view";
92
+ }, {
93
+ readonly type: "function";
94
+ readonly name: "allPairs";
95
+ readonly inputs: readonly [{
96
+ readonly name: "index";
97
+ readonly type: "uint256";
98
+ }];
99
+ readonly outputs: readonly [{
100
+ readonly name: "pair";
101
+ readonly type: "address";
102
+ }];
103
+ readonly stateMutability: "view";
104
+ }, {
105
+ readonly type: "function";
106
+ readonly name: "allPairsLength";
107
+ readonly inputs: readonly [];
108
+ readonly outputs: readonly [{
109
+ readonly type: "uint256";
110
+ }];
111
+ readonly stateMutability: "view";
112
+ }, {
113
+ readonly type: "function";
114
+ readonly name: "createPair";
115
+ readonly inputs: readonly [{
116
+ readonly name: "tokenA";
117
+ readonly type: "address";
118
+ }, {
119
+ readonly name: "tokenB";
120
+ readonly type: "address";
121
+ }];
122
+ readonly outputs: readonly [{
123
+ readonly name: "pair";
124
+ readonly type: "address";
125
+ }];
126
+ readonly stateMutability: "nonpayable";
127
+ }, {
128
+ readonly type: "event";
129
+ readonly name: "PairCreated";
130
+ readonly inputs: readonly [{
131
+ readonly name: "token0";
132
+ readonly type: "address";
133
+ readonly indexed: true;
134
+ }, {
135
+ readonly name: "token1";
136
+ readonly type: "address";
137
+ readonly indexed: true;
138
+ }, {
139
+ readonly name: "pair";
140
+ readonly type: "address";
141
+ readonly indexed: false;
142
+ }, {
143
+ readonly name: "index";
144
+ readonly type: "uint256";
145
+ readonly indexed: false;
146
+ }];
147
+ }];
148
+ //# sourceMappingURL=amm-v2-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amm-v2-factory.d.ts","sourceRoot":"","sources":["../../../src/contracts/abis/amm-v2-factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6CrB,CAAA;AAEV,iDAAiD;AACjD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAqB,CAAA"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * AMM V2 Factory ABI
3
+ * Compatible with Uniswap V2 Factory interface
4
+ */
5
+ export const AMM_V2_FACTORY_ABI = [
6
+ {
7
+ type: 'function',
8
+ name: 'getPair',
9
+ inputs: [
10
+ { name: 'tokenA', type: 'address' },
11
+ { name: 'tokenB', type: 'address' },
12
+ ],
13
+ outputs: [{ name: 'pair', type: 'address' }],
14
+ stateMutability: 'view',
15
+ },
16
+ {
17
+ type: 'function',
18
+ name: 'allPairs',
19
+ inputs: [{ name: 'index', type: 'uint256' }],
20
+ outputs: [{ name: 'pair', type: 'address' }],
21
+ stateMutability: 'view',
22
+ },
23
+ {
24
+ type: 'function',
25
+ name: 'allPairsLength',
26
+ inputs: [],
27
+ outputs: [{ type: 'uint256' }],
28
+ stateMutability: 'view',
29
+ },
30
+ {
31
+ type: 'function',
32
+ name: 'createPair',
33
+ inputs: [
34
+ { name: 'tokenA', type: 'address' },
35
+ { name: 'tokenB', type: 'address' },
36
+ ],
37
+ outputs: [{ name: 'pair', type: 'address' }],
38
+ stateMutability: 'nonpayable',
39
+ },
40
+ {
41
+ type: 'event',
42
+ name: 'PairCreated',
43
+ inputs: [
44
+ { name: 'token0', type: 'address', indexed: true },
45
+ { name: 'token1', type: 'address', indexed: true },
46
+ { name: 'pair', type: 'address', indexed: false },
47
+ { name: 'index', type: 'uint256', indexed: false },
48
+ ],
49
+ },
50
+ ];
51
+ /** @deprecated Use AMM_V2_FACTORY_ABI instead */
52
+ export const UNISWAP_V2_FACTORY_ABI = AMM_V2_FACTORY_ABI;