@wormhole-foundation/wormhole-connect 2.5.0-beta.15-development → 2.5.0-beta.16-development

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 (114) hide show
  1. package/dist/assets/{aptos-Cutllx5i.js → aptos-r6k7eJCM.js} +2 -2
  2. package/dist/assets/{ccip-C6cz5NqJ.js → ccip-DoYNnipC.js} +1 -1
  3. package/dist/assets/{evm-DzwJdvcV.js → evm-C5Ivowrf.js} +2 -2
  4. package/dist/assets/{evm-LJDXipdh.js → evm-DSNDNefN.js} +3 -3
  5. package/dist/assets/{index-DwJjUFus.js → index-7lgoK4KP.js} +1 -1
  6. package/dist/assets/{index-D3R8fZfr.js → index-BQQC6_X5.js} +1 -1
  7. package/dist/assets/{index-RZp63Yuv.js → index-BiBNC4RU.js} +1 -1
  8. package/dist/assets/{index-BVJL1orJ.js → index-BtCNeMnf.js} +1 -1
  9. package/dist/assets/{index-iiAA6CTH.js → index-CD-O7bSQ.js} +1 -1
  10. package/dist/assets/{index-CSiH4dly.js → index-CItGJ_dO.js} +1 -1
  11. package/dist/assets/{index-CJZzjIow.js → index-CKNeANkQ.js} +1 -1
  12. package/dist/assets/{index-C6UKJUdm.js → index-CLAfmegc.js} +1 -1
  13. package/dist/assets/{index-wwvQRwKh.js → index-Cefdj6j_.js} +1 -1
  14. package/dist/assets/{index-CqEHg303.js → index-CrZXNnmG.js} +1 -1
  15. package/dist/assets/{index-m7pOREIu.js → index-Cts3aOUg.js} +1 -1
  16. package/dist/assets/{index-BwNyYZxM.js → index-CuW_tQti.js} +1 -1
  17. package/dist/assets/{index-Ds_BlDdN.js → index-DPi-hS0A.js} +2 -2
  18. package/dist/assets/{index-BECoIARf.js → index-DQWOpudg.js} +1 -1
  19. package/dist/assets/{index-BO5vFz_J.js → index-TjYk9nid.js} +1 -1
  20. package/dist/assets/{index-EvC_Tjca.js → index-XgkrTsoW.js} +1 -1
  21. package/dist/assets/{index-Dxpp9NXJ.js → index-mE5izIg0.js} +1 -1
  22. package/dist/assets/{index.es-C9O0OD76.js → index.es-e2znZrg8.js} +6 -6
  23. package/dist/assets/solana-BNhbIgt5.js +2 -0
  24. package/dist/assets/{solana-BGWrrBcM.js → solana-DCCw_nmt.js} +2 -2
  25. package/dist/assets/solanaEmbed.esm-D6aTKNPa.js +37 -0
  26. package/dist/assets/{sui-COEHPNCD.js → sui-CqkItMnZ.js} +2 -2
  27. package/dist/assets/{tokens-CzZADlQh.js → tokens-BSV7gluG.js} +1 -1
  28. package/dist/main.js +53 -53
  29. package/lib/{aptos-CeQAnpez.mjs → aptos-B_0vi8q5.mjs} +5 -5
  30. package/lib/{aptos-DM8l3csb.js → aptos-Bq95ywod.js} +1 -1
  31. package/lib/{aptos-BQFmduMd.js → aptos-CZeHb71O.js} +2 -2
  32. package/lib/{aptos-CFJxiJmC.mjs → aptos-DT2vzzvi.mjs} +2 -2
  33. package/lib/{base64-CHhsJk6A.mjs → base64-COK36zSs.mjs} +1 -1
  34. package/lib/{base64-D9lqOebt.js → base64-CZQMgJPg.js} +1 -1
  35. package/lib/{ccip-CgZgkY8Y.js → ccip-BMWN6mUe.js} +1 -1
  36. package/lib/{ccip-DIBA7ZPU.mjs → ccip-OItyAOfS.mjs} +1 -1
  37. package/lib/{chunk-IMTC3J2M-CZ9g11yQ.mjs → chunk-IMTC3J2M-BDC_vQUG.mjs} +3 -3
  38. package/lib/{chunk-IMTC3J2M-CMDaOJhu.js → chunk-IMTC3J2M-CdK66Gd0.js} +1 -1
  39. package/lib/{evm-B4FdqIm_.js → evm-B8do5bRe.js} +2 -2
  40. package/lib/{evm-DIChhZyr.mjs → evm-BlmFliMr.mjs} +5 -5
  41. package/lib/{evm-ue5IlD46.js → evm-CQ-_bicP.js} +3 -3
  42. package/lib/{evm-Dc_rWE9Y.mjs → evm-YzP22UIh.mjs} +6 -6
  43. package/lib/{index-BVUd-qAx.js → index-9QDfPDAt.js} +1 -1
  44. package/lib/{index-D6rdTBQ_.mjs → index-B1ZLlUX_.mjs} +1 -1
  45. package/lib/{index-CJReTDxB.js → index-B2rKFKuc.js} +1 -1
  46. package/lib/{index-DGDFGoDX.mjs → index-B8-yYDbb.mjs} +2 -2
  47. package/lib/{index-DQJ5IMd3.mjs → index-B9a8iQAY.mjs} +1 -1
  48. package/lib/{index-BcZ5yPJ4.mjs → index-B9ceWZWn.mjs} +1 -1
  49. package/lib/{index-BGjIKUEk.mjs → index-BBDgOG5m.mjs} +1 -1
  50. package/lib/{index-Bnnn4cdG.mjs → index-BOD0JbTK.mjs} +15 -17
  51. package/lib/{index-D5JrYq_0.js → index-BRgpPBei.js} +1 -1
  52. package/lib/{index-B2ab2XtW.mjs → index-BRnbVNBB.mjs} +1 -1
  53. package/lib/{index-bjRbczrw.mjs → index-BTrEvW5f.mjs} +3 -3
  54. package/lib/{index-PZieeYNW.mjs → index-BW0PVtoo.mjs} +1 -1
  55. package/lib/{index-Bt1Gnf-O.mjs → index-BrjkSw_2.mjs} +2 -2
  56. package/lib/{index-Ghp7efN9.js → index-BulciDEP.js} +1 -1
  57. package/lib/{index-CRvTBc48.js → index-C-GPWLns.js} +1 -1
  58. package/lib/{index-Dcz-16pD.mjs → index-C0a9Lr6a.mjs} +2 -2
  59. package/lib/{index-DlgBKu9O.js → index-C52V666L.js} +1 -1
  60. package/lib/{index-CXtp5GKq.js → index-C6lC72hy.js} +1 -1
  61. package/lib/{index-BZyf12j0.js → index-C8i0VBfG.js} +1 -1
  62. package/lib/{index-HjrA7REP.js → index-CIL_hNIg.js} +1 -1
  63. package/lib/{index-wTziIUpS.js → index-CUgFK5ex.js} +1 -1
  64. package/lib/{index-BSsBLI7m.js → index-CUnIraeu.js} +1 -1
  65. package/lib/{index-B5xcX9Pc.js → index-CWv9euDC.js} +1 -1
  66. package/lib/{index-DkuruFPE.mjs → index-CY6GX-7w.mjs} +1 -1
  67. package/lib/{index-Bu697BJP.js → index-CliZ4E05.js} +1 -1
  68. package/lib/{index-BskY1_ip.mjs → index-CqYIha8G.mjs} +2 -2
  69. package/lib/{index-DTxneAkn.js → index-Cs5YQSh6.js} +1 -1
  70. package/lib/{index-Bo7Tv5Eo.mjs → index-CwfZcLrv.mjs} +3 -3
  71. package/lib/{index-WwuUq9Aw.js → index-D1aACi02.js} +1 -1
  72. package/lib/{index-BDu7oYbW.js → index-D4jfCW8J.js} +1 -1
  73. package/lib/{index-D5cipXo-.js → index-D74R0bwx.js} +1 -1
  74. package/lib/{index-DcaoqeHs.mjs → index-DBNmOAMs.mjs} +2 -2
  75. package/lib/{index-BCVTOYpu.mjs → index-DIql-M62.mjs} +2 -2
  76. package/lib/{index-MlkcvO4G.js → index-DIvEOa-k.js} +1 -1
  77. package/lib/{index-CsLUIX2T.mjs → index-DJILvbYp.mjs} +2 -2
  78. package/lib/{index-DekUp2hz.mjs → index-DLUeHBim.mjs} +4 -4
  79. package/lib/{index-BFSevX7g.js → index-DMhLZESv.js} +1 -1
  80. package/lib/{index-CZM3CbIN.mjs → index-DOyZRNfq.mjs} +2 -2
  81. package/lib/{index-2NJ-Uc1n.mjs → index-DhHyV5Rf.mjs} +1 -1
  82. package/lib/{index-X1wTeN-B.js → index-DoE4VQhB.js} +3 -3
  83. package/lib/{index-C9vy8VuD.js → index-Drp6LJGk.js} +1 -1
  84. package/lib/{index-DXY3TcAw.mjs → index-DtMVR4Z_.mjs} +2 -2
  85. package/lib/{index-CLwJAWXV.js → index-OvtkwIrm.js} +1 -1
  86. package/lib/{index-C4e6Tr94.mjs → index-RRzYEpPP.mjs} +1 -1
  87. package/lib/{index-CuQ35zWu.mjs → index-XZFtH_Uh.mjs} +1 -1
  88. package/lib/{index-CcgIIKqT.js → index-_UjA-Vft.js} +1 -1
  89. package/lib/{index-B5ZPnsOX.js → index-f2frXUPl.js} +1 -1
  90. package/lib/{index-DVI7iWJA.mjs → index-qdz_PIx9.mjs} +1 -1
  91. package/lib/{index.es-CQrihLMh.mjs → index.es-D2nwWIpj.mjs} +5 -5
  92. package/lib/{index.es-BFV_Hq98.js → index.es-DLocQOXa.js} +2 -2
  93. package/lib/index.js +1 -1
  94. package/lib/index.mjs +1 -1
  95. package/lib/{signer-BGahG9Lx.mjs → signer-DJ1HF-CK.mjs} +1 -1
  96. package/lib/{signer-DVlvBrTY.js → signer-DZOcy7cH.js} +1 -1
  97. package/lib/{solana-DZVSRj8-.mjs → solana-CFnSQELF.mjs} +4 -4
  98. package/lib/solana-CrWCptDL.mjs +17 -0
  99. package/lib/{solana-25r-MPDz.js → solana-Ct8Sn9KJ.js} +1 -1
  100. package/lib/solana-CyM9Bqyp.js +1 -0
  101. package/lib/{solanaEmbed.esm-D6F7GU7N.js → solanaEmbed.esm-BD__0VpK.js} +1 -1
  102. package/lib/{solanaEmbed.esm-ea6sDZ8N.mjs → solanaEmbed.esm-CPaTID-O.mjs} +2 -2
  103. package/lib/{sui-ZMZ9Uq_a.js → sui-Bh4bUzgA.js} +1 -1
  104. package/lib/{sui-BHAlSArP.js → sui-CbwKq8Oh.js} +1 -1
  105. package/lib/{sui-CG9oss4-.mjs → sui-Da5D6kut.mjs} +1 -1
  106. package/lib/{sui-9tHCVvtM.mjs → sui-DnkD0Bxo.mjs} +5 -5
  107. package/lib/{tokens-BZf6dpqe.mjs → tokens-C4Y28hR0.mjs} +2 -2
  108. package/lib/{tokens-B2mOzW4r.js → tokens-CAwPmit8.js} +1 -1
  109. package/package.json +1 -1
  110. package/dist/assets/events-MYC_Tkdh.js +0 -1
  111. package/dist/assets/solana-B0Eox3vZ.js +0 -2
  112. package/dist/assets/solanaEmbed.esm-C9Mwa0DJ.js +0 -37
  113. package/lib/solana-5YorGJTB.mjs +0 -17
  114. package/lib/solana-Dg31-6OS.js +0 -1
@@ -13,7 +13,7 @@ var Cx = (c, e, x, a) => ({
13
13
  return O(c, e, a);
14
14
  }
15
15
  });
16
- import { j as u, k as w, l as Te, w as Ce, m as Ie, p as ke, r as Oe, n as Ix, o as Se, q as u0, s as Bx, u as Q0, t as Fx, v as m0, x as hx, y as l0, z as _x, B as V, D as l, E as Z0, F as ve, G as Pe, H as kx, I as ux, J as Ue, L as Ox, N as Y, O as Kx, Q as px, R as Le, U as N0, W as Gx, X as Me, Y as yx, Z as Vx, _ as L0, $ as De, a0 as $e, a1 as Be, a2 as Fe, a3 as _e, a4 as Ke, a5 as Ge, a6 as bx, a7 as Ve, a8 as We, a9 as ze, aa as Ye, ab as He } from "./index-Bnnn4cdG.mjs";
16
+ import { j as u, k as w, l as Te, w as Ce, m as Ie, p as ke, r as Oe, n as Ix, o as Se, q as u0, s as Bx, u as Q0, t as Fx, v as m0, x as hx, y as l0, z as _x, B as V, D as l, E as Z0, F as ve, G as Pe, H as kx, I as ux, J as Ue, L as Ox, N as Y, O as Kx, Q as px, R as Le, U as N0, W as Gx, X as Me, Y as yx, Z as Vx, _ as L0, $ as De, a0 as $e, a1 as Be, a2 as Fe, a3 as _e, a4 as Ke, a5 as Ge, a6 as bx, a7 as Ve, a8 as We, a9 as ze, aa as Ye, ab as He } from "./index-BOD0JbTK.mjs";
17
17
  function Je(c) {
18
18
  const e = u(c, "randomBytes");
19
19
  e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
@@ -1591,11 +1591,11 @@ const _a = {
1591
1591
  Platform: bx,
1592
1592
  getSigner: Da,
1593
1593
  protocols: {
1594
- WormholeCore: () => import("./index-Bnnn4cdG.mjs").then((c) => c.e9),
1595
- TokenBridge: () => import("./index-PZieeYNW.mjs"),
1596
- PorticoBridge: () => import("./index-CZM3CbIN.mjs"),
1597
- CircleBridge: () => import("./index-Dcz-16pD.mjs"),
1598
- TBTCBridge: () => import("./index-BGjIKUEk.mjs")
1594
+ WormholeCore: () => import("./index-BOD0JbTK.mjs").then((c) => c.e9),
1595
+ TokenBridge: () => import("./index-BW0PVtoo.mjs"),
1596
+ PorticoBridge: () => import("./index-DOyZRNfq.mjs"),
1597
+ CircleBridge: () => import("./index-C0a9Lr6a.mjs"),
1598
+ TBTCBridge: () => import("./index-BBDgOG5m.mjs")
1599
1599
  },
1600
1600
  getChain: (c, e, x) => new We(e, new bx(c, Ye(c, He, {
1601
1601
  [e]: x
@@ -1 +1 @@
1
- "use strict";var G=Object.defineProperty;var V=(n,i,t)=>i in n?G(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var c=(n,i,t)=>V(n,typeof i!="symbol"?i+"":i,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-X1wTeN-B.js"),d=require("./index-WwuUq9Aw.js"),U={version:"0.1.0",name:"wormhole_gateway",instructions:[{name:"initialize",accounts:[{name:"authority",isMut:!0,isSigner:!0},{name:"custodian",isMut:!0,isSigner:!1},{name:"tbtcMint",isMut:!1,isSigner:!1,docs:["TBTC Program's mint PDA address bump is saved in this program's config. Ordinarily, we would","not have to deserialize this account. But we do in this case to make sure the TBTC program","has been initialized before this program."]},{name:"wrappedTbtcMint",isMut:!1,isSigner:!1},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1},{name:"tokenBridgeSender",isMut:!1,isSigner:!1,docs:["sign for transferring via Token Bridge program with a message."]},{name:"systemProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1}],args:[{name:"mintingLimit",type:"u64"}]},{name:"changeAuthority",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"authority",isMut:!1,isSigner:!0},{name:"newAuthority",isMut:!1,isSigner:!1}],args:[]},{name:"cancelAuthorityChange",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"authority",isMut:!1,isSigner:!0}],args:[]},{name:"takeAuthority",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"pendingAuthority",isMut:!1,isSigner:!0}],args:[]},{name:"updateGatewayAddress",accounts:[{name:"custodian",isMut:!1,isSigner:!1},{name:"gatewayInfo",isMut:!0,isSigner:!1},{name:"authority",isMut:!0,isSigner:!0},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"args",type:{defined:"UpdateGatewayAddressArgs"}}]},{name:"updateMintingLimit",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"authority",isMut:!1,isSigner:!0}],args:[{name:"newLimit",type:"u64"}]},{name:"receiveTbtc",accounts:[{name:"payer",isMut:!0,isSigner:!0},{name:"custodian",isMut:!0,isSigner:!1},{name:"postedVaa",isMut:!1,isSigner:!1},{name:"tokenBridgeClaim",isMut:!0,isSigner:!1,docs:["transfer. By checking whether this account exists is a short-circuit way of bailing out","early if this transfer has already been redeemed (as opposed to letting the Token Bridge","instruction fail)."]},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["Custody account."]},{name:"wrappedTbtcMint",isMut:!0,isSigner:!1,docs:["This mint is owned by the Wormhole Token Bridge program. This PDA address is stored in the","custodian account."]},{name:"tbtcMint",isMut:!0,isSigner:!1},{name:"recipientToken",isMut:!0,isSigner:!1,docs:["Token account for minted tBTC.","","NOTE: Because the recipient is encoded in the transfer message payload, we can check the","authority from the deserialized VAA. But we should still check whether the authority is the","zero address in access control."]},{name:"recipient",isMut:!1,isSigner:!1,docs:["be created for him."]},{name:"recipientWrappedToken",isMut:!0,isSigner:!1,docs:["The gateway will create an associated token account for the recipient if it doesn't exist.","","NOTE: When the minting limit increases, the recipient can use this token account to mint","tBTC using the deposit_wormhole_tbtc instruction."]},{name:"tbtcConfig",isMut:!1,isSigner:!1},{name:"tbtcMinterInfo",isMut:!1,isSigner:!1},{name:"tokenBridgeConfig",isMut:!1,isSigner:!1},{name:"tokenBridgeRegisteredEmitter",isMut:!1,isSigner:!1},{name:"tokenBridgeWrappedAsset",isMut:!1,isSigner:!1},{name:"tokenBridgeMintAuthority",isMut:!1,isSigner:!1},{name:"rent",isMut:!1,isSigner:!1},{name:"tbtcProgram",isMut:!1,isSigner:!1},{name:"tokenBridgeProgram",isMut:!1,isSigner:!1},{name:"coreBridgeProgram",isMut:!1,isSigner:!1},{name:"associatedTokenProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"messageHash",type:{array:["u8",32]}}]},{name:"sendTbtcGateway",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"gatewayInfo",isMut:!1,isSigner:!1},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["Custody account."]},{name:"wrappedTbtcMint",isMut:!0,isSigner:!1},{name:"tbtcMint",isMut:!0,isSigner:!1},{name:"senderToken",isMut:!0,isSigner:!1},{name:"sender",isMut:!0,isSigner:!0},{name:"tokenBridgeConfig",isMut:!1,isSigner:!1},{name:"tokenBridgeWrappedAsset",isMut:!1,isSigner:!1},{name:"tokenBridgeTransferAuthority",isMut:!1,isSigner:!1},{name:"coreBridgeData",isMut:!0,isSigner:!1},{name:"coreMessage",isMut:!0,isSigner:!1},{name:"tokenBridgeCoreEmitter",isMut:!1,isSigner:!1},{name:"coreEmitterSequence",isMut:!0,isSigner:!1},{name:"coreFeeCollector",isMut:!0,isSigner:!1},{name:"clock",isMut:!1,isSigner:!1},{name:"tokenBridgeSender",isMut:!1,isSigner:!1,docs:["sign for transferring via Token Bridge program with a message."]},{name:"rent",isMut:!1,isSigner:!1},{name:"tokenBridgeProgram",isMut:!1,isSigner:!1},{name:"coreBridgeProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"args",type:{defined:"SendTbtcGatewayArgs"}}]},{name:"sendTbtcWrapped",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["Custody account."]},{name:"wrappedTbtcMint",isMut:!0,isSigner:!1},{name:"tbtcMint",isMut:!0,isSigner:!1},{name:"senderToken",isMut:!0,isSigner:!1},{name:"sender",isMut:!0,isSigner:!0},{name:"tokenBridgeConfig",isMut:!1,isSigner:!1},{name:"tokenBridgeWrappedAsset",isMut:!1,isSigner:!1},{name:"tokenBridgeTransferAuthority",isMut:!1,isSigner:!1},{name:"coreBridgeData",isMut:!0,isSigner:!1},{name:"coreMessage",isMut:!0,isSigner:!1},{name:"tokenBridgeCoreEmitter",isMut:!1,isSigner:!1},{name:"coreEmitterSequence",isMut:!0,isSigner:!1},{name:"coreFeeCollector",isMut:!0,isSigner:!1},{name:"clock",isMut:!1,isSigner:!1},{name:"rent",isMut:!1,isSigner:!1},{name:"tokenBridgeProgram",isMut:!1,isSigner:!1},{name:"coreBridgeProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"args",type:{defined:"SendTbtcWrappedArgs"}}]},{name:"depositWormholeTbtc",accounts:[{name:"custodian",isMut:!0,isSigner:!1,docs:["NOTE: This account also acts as a minter for the TBTC program."]},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["This token account is owned by this program, whose mint is the wrapped TBTC mint. This PDA","address is stored in the custodian account."]},{name:"wrappedTbtcMint",isMut:!1,isSigner:!1,docs:["This mint is owned by the Wormhole Token Bridge program. This PDA address is stored in the","custodian account."]},{name:"tbtcMint",isMut:!0,isSigner:!1,docs:["This mint is owned by the TBTC program. This PDA address is stored in the custodian account."]},{name:"recipientWrappedToken",isMut:!0,isSigner:!1},{name:"recipientToken",isMut:!0,isSigner:!1},{name:"recipient",isMut:!1,isSigner:!0,docs:["This program requires that the owner of the TBTC token account sign for TBTC being minted","into his account."]},{name:"tbtcConfig",isMut:!1,isSigner:!1},{name:"tbtcMinterInfo",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"tbtcProgram",isMut:!1,isSigner:!1}],args:[{name:"amount",type:"u64"}]}],accounts:[{name:"custodian",type:{kind:"struct",fields:[{name:"bump",type:"u8"},{name:"authority",type:"publicKey"},{name:"pendingAuthority",type:{option:"publicKey"}},{name:"tbtcMint",type:"publicKey"},{name:"wrappedTbtcMint",type:"publicKey"},{name:"wrappedTbtcToken",type:"publicKey"},{name:"tokenBridgeSender",type:"publicKey"},{name:"tokenBridgeSenderBump",type:"u8"},{name:"mintingLimit",type:"u64"},{name:"mintedAmount",type:"u64"}]}},{name:"GatewayInfo",type:{kind:"struct",fields:[{name:"bump",type:"u8"},{name:"address",type:{array:["u8",32]}}]}}],types:[{name:"UpdateGatewayAddressArgs",type:{kind:"struct",fields:[{name:"chain",type:"u16"},{name:"address",type:{array:["u8",32]}}]}},{name:"SendTbtcGatewayArgs",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"recipientChain",type:"u16"},{name:"recipient",type:{array:["u8",32]}},{name:"nonce",type:"u32"}]}},{name:"SendTbtcWrappedArgs",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"recipientChain",type:"u16"},{name:"recipient",type:{array:["u8",32]}},{name:"arbiterFee",type:"u64"},{name:"nonce",type:"u32"}]}}],events:[{name:"WormholeTbtcReceived",fields:[{name:"receiver",type:"publicKey",index:!1},{name:"amount",type:"u64",index:!1}]},{name:"WormholeTbtcSent",fields:[{name:"amount",type:"u64",index:!1},{name:"recipientChain",type:"u16",index:!1},{name:"gateway",type:{array:["u8",32]},index:!1},{name:"recipient",type:{array:["u8",32]},index:!1},{name:"arbiterFee",type:"u64",index:!1},{name:"nonce",type:"u32",index:!1}]},{name:"WormholeTbtcDeposited",fields:[{name:"depositor",type:"publicKey",index:!1},{name:"amount",type:"u64",index:!1}]},{name:"GatewayAddressUpdated",fields:[{name:"chain",type:"u16",index:!1},{name:"gateway",type:{array:["u8",32]},index:!1}]},{name:"MintingLimitUpdated",fields:[{name:"mintingLimit",type:"u64",index:!1}]}],errors:[{code:6016,name:"MintingLimitExceeded",msg:"Cannot mint more than the minting limit"},{code:6032,name:"IsNotAuthority",msg:"Only custodian authority is permitted for this action"},{code:6034,name:"IsNotPendingAuthority",msg:"Not valid pending authority to take authority"},{code:6036,name:"NoPendingAuthorityChange",msg:"No pending authority"},{code:6048,name:"ZeroRecipient",msg:"0x0 recipient not allowed"},{code:6064,name:"NotEnoughWrappedTbtc",msg:"Not enough wormhole tBTC in the gateway to bridge"},{code:6080,name:"ZeroAmount",msg:"Amount must not be 0"},{code:6112,name:"TransferAlreadyRedeemed",msg:"Token Bridge transfer already redeemed"},{code:6128,name:"InvalidEthereumTbtc",msg:"Token chain and address do not match Ethereum's tBTC"},{code:6144,name:"NoTbtcTransferred",msg:"No tBTC transferred"},{code:6160,name:"RecipientZeroAddress",msg:"0x0 receiver not allowed"},{code:6176,name:"MintedAmountUnderflow",msg:"Not enough minted by the gateway to satisfy sending tBTC"},{code:6178,name:"MintedAmountOverflow",msg:"Minted amount after deposit exceeds u64"}]};function I(n){return e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("redeemer")],new e.PublicKey(n))[0]}function q(n,i){const t=e.dist.Buffer.alloc(8);return t.writeBigUInt64LE(i),e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("msg"),t],new e.PublicKey(n))[0]}function L(n,i){const t=e.dist.Buffer.alloc(2);return t.writeUInt16LE(e.toChainId(i)),e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("gateway-info"),t],new e.PublicKey(n))[0]}const T=new e.PublicKey("Gj93RRt6QB7FjmyokAD5rcMAku7pq3Fk2Aa8y6nNbwsV");function D(){return e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("config")],T)[0]}function _(n){return e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("minter-info"),n.toBuffer()],T)[0]}const B=new e.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");new e.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");const b=new e.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");new e.PublicKey("So11111111111111111111111111111111111111112");new e.PublicKey("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP");class F extends Error{constructor(i){super(i)}}class z extends F{constructor(){super(...arguments),this.name="TokenOwnerOffCurveError"}}const Y=e.struct([e.u32$1("mintAuthorityOption"),e.publicKey("mintAuthority"),e.u64("supply"),e.u8("decimals"),e.bool("isInitialized"),e.u32$1("freezeAuthorityOption"),e.publicKey("freezeAuthority")]);Y.span;async function M(n,i,t=!1,a=B,s=b){if(!t&&!e.PublicKey.isOnCurve(i.toBuffer()))throw new z;const[r]=await e.PublicKey.findProgramAddress([i.toBuffer(),a.toBuffer(),n.toBuffer()],s);return r}function $(n,i,t,a,s=B,r=b){return H(n,i,t,a,e.dist.Buffer.alloc(0),s,r)}function H(n,i,t,a,s,r=B,o=b){const u=[{pubkey:n,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:u,programId:o,data:s})}class h{constructor(i,t,a,s){c(this,"network");c(this,"chain");c(this,"connection");c(this,"contracts");c(this,"gateway");c(this,"tokenBridgeId");c(this,"coreBridgeId");if(this.network=i,this.chain=t,this.connection=a,this.contracts=s,this.network!=="Mainnet")throw new Error("TBTC is only supported on Mainnet");if(!this.contracts.tbtc)throw new Error("TBTC contract address is required");if(!this.contracts.tokenBridge)throw new Error("TokenBridge contract address is required");if(!this.contracts.coreBridge)throw new Error("CoreBridge contract address is required");this.gateway=new e.Program(U,this.contracts.tbtc,{connection:a}),this.tokenBridgeId=new e.PublicKey(this.contracts.tokenBridge),this.coreBridgeId=new e.PublicKey(this.contracts.coreBridge)}static async fromRpc(i,t){const[a,s]=await e.SolanaPlatform.chainFromRpc(i),r=t[s];if(r.network!==a)throw new Error(`Network mismatch: ${r.network} != ${a}`);return new h(a,s,i,r.contracts)}async*transfer(i,t,a){const s=new e.SolanaAddress(i).unwrap(),r=I(this.gateway.programId),{tbtcMint:o,wrappedTbtcToken:u,wrappedTbtcMint:g}=await this.gateway.account.custodian.fetch(r),p=d.deriveWrappedMetaKey(this.tokenBridgeId,g),m=d.deriveTokenBridgeConfigKey(this.tokenBridgeId),l=d.deriveAuthoritySignerKey(this.tokenBridgeId),A=e.deriveFeeCollectorKey(this.coreBridgeId),{sequence:y}=await e.getProgramSequenceTracker(this.connection,this.tokenBridgeId,this.coreBridgeId),S=q(this.gateway.programId,y),w=e.deriveWormholeBridgeDataKey(this.coreBridgeId),f=e.deriveWormholeEmitterKey(this.tokenBridgeId),k=e.deriveEmitterSequenceKey(f,this.coreBridgeId),K=L(this.gateway.programId,t.chain),E=d.deriveSenderAccountKey(this.gateway.programId),P={amount:new e.bnExports.BN(a.toString()),recipientChain:e.toChainId(t.chain),recipient:[...t.address.toUniversalAddress().toUint8Array()],nonce:0},W=await M(o,s),x=e.tbtc.get(this.network,t.chain),C={custodian:r,wrappedTbtcToken:u,wrappedTbtcMint:g,tbtcMint:o,senderToken:W,sender:s,tokenBridgeConfig:m,tokenBridgeWrappedAsset:p,tokenBridgeTransferAuthority:l,coreBridgeData:w,coreMessage:S,tokenBridgeCoreEmitter:f,coreEmitterSequence:k,coreFeeCollector:A,clock:e.SYSVAR_CLOCK_PUBKEY,rent:e.SYSVAR_RENT_PUBKEY,tokenBridgeProgram:this.tokenBridgeId,coreBridgeProgram:this.coreBridgeId},v=x?await this.gateway.methods.sendTbtcGateway({...P}).accounts({...C,gatewayInfo:K,tokenBridgeSender:E}).instruction():await this.gateway.methods.sendTbtcWrapped({...P,arbiterFee:new e.bnExports.BN(0)}).accounts(C).instruction(),{blockhash:N}=await this.connection.getLatestBlockhash(),O=e.MessageV0.compile({instructions:[v],payerKey:s,recentBlockhash:N}),R=new e.VersionedTransaction(O);yield this.createUnsignedTransaction({transaction:R},"TBTCBridge.Send")}async*redeem(i,t){if(t.payloadName!=="GatewayTransfer")throw new Error("Invalid VAA payload");yield*new e.SolanaWormholeCore(this.network,this.chain,this.connection,this.contracts).postVaa(i,t);const s=[],r=new e.SolanaAddress(i).unwrap(),o=t.payload.payload.recipient.toNative(this.chain).unwrap(),u=I(this.gateway.programId),{tbtcMint:g,wrappedTbtcToken:p,wrappedTbtcMint:m}=await this.gateway.account.custodian.fetch(u),l=await M(g,o);await this.connection.getAccountInfo(l)||s.push($(r,l,o,g));const y=d.deriveWrappedMetaKey(this.tokenBridgeId,m),S=await M(m,o);s.push(await this.gateway.methods.receiveTbtc([...t.hash]).accounts({payer:r,custodian:u,postedVaa:e.derivePostedVaaKey(this.coreBridgeId,e.dist.Buffer.from(t.hash)),tokenBridgeClaim:e.deriveClaimKey(this.tokenBridgeId,t.emitterAddress.toUint8Array(),e.toChainId(t.emitterChain),t.sequence),wrappedTbtcToken:p,wrappedTbtcMint:m,tbtcMint:g,recipientToken:l,recipient:o,recipientWrappedToken:S,tbtcConfig:D(),tbtcMinterInfo:_(u),tokenBridgeConfig:d.deriveTokenBridgeConfigKey(this.tokenBridgeId),tokenBridgeRegisteredEmitter:d.deriveEndpointKey(this.tokenBridgeId,e.toChainId(t.emitterChain),t.emitterAddress.toUint8Array()),tokenBridgeWrappedAsset:y,tokenBridgeMintAuthority:d.deriveMintAuthorityKey(this.tokenBridgeId),rent:e.SYSVAR_RENT_PUBKEY,tbtcProgram:T,tokenBridgeProgram:this.tokenBridgeId,coreBridgeProgram:this.coreBridgeId}).instruction());const{blockhash:w}=await this.connection.getLatestBlockhash(),f=e.MessageV0.compile({instructions:s,payerKey:r,recentBlockhash:w}),k=new e.VersionedTransaction(f);yield this.createUnsignedTransaction({transaction:k},"TBTCBridge.Send")}createUnsignedTransaction(i,t){return new e.SolanaUnsignedTransaction(i,this.network,this.chain,t,!1)}}e.registerProtocol(e._platform$1,"TBTCBridge",h);exports.SolanaTBTCBridge=h;
1
+ "use strict";var G=Object.defineProperty;var V=(n,i,t)=>i in n?G(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var c=(n,i,t)=>V(n,typeof i!="symbol"?i+"":i,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DoE4VQhB.js"),d=require("./index-D1aACi02.js"),U={version:"0.1.0",name:"wormhole_gateway",instructions:[{name:"initialize",accounts:[{name:"authority",isMut:!0,isSigner:!0},{name:"custodian",isMut:!0,isSigner:!1},{name:"tbtcMint",isMut:!1,isSigner:!1,docs:["TBTC Program's mint PDA address bump is saved in this program's config. Ordinarily, we would","not have to deserialize this account. But we do in this case to make sure the TBTC program","has been initialized before this program."]},{name:"wrappedTbtcMint",isMut:!1,isSigner:!1},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1},{name:"tokenBridgeSender",isMut:!1,isSigner:!1,docs:["sign for transferring via Token Bridge program with a message."]},{name:"systemProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1}],args:[{name:"mintingLimit",type:"u64"}]},{name:"changeAuthority",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"authority",isMut:!1,isSigner:!0},{name:"newAuthority",isMut:!1,isSigner:!1}],args:[]},{name:"cancelAuthorityChange",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"authority",isMut:!1,isSigner:!0}],args:[]},{name:"takeAuthority",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"pendingAuthority",isMut:!1,isSigner:!0}],args:[]},{name:"updateGatewayAddress",accounts:[{name:"custodian",isMut:!1,isSigner:!1},{name:"gatewayInfo",isMut:!0,isSigner:!1},{name:"authority",isMut:!0,isSigner:!0},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"args",type:{defined:"UpdateGatewayAddressArgs"}}]},{name:"updateMintingLimit",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"authority",isMut:!1,isSigner:!0}],args:[{name:"newLimit",type:"u64"}]},{name:"receiveTbtc",accounts:[{name:"payer",isMut:!0,isSigner:!0},{name:"custodian",isMut:!0,isSigner:!1},{name:"postedVaa",isMut:!1,isSigner:!1},{name:"tokenBridgeClaim",isMut:!0,isSigner:!1,docs:["transfer. By checking whether this account exists is a short-circuit way of bailing out","early if this transfer has already been redeemed (as opposed to letting the Token Bridge","instruction fail)."]},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["Custody account."]},{name:"wrappedTbtcMint",isMut:!0,isSigner:!1,docs:["This mint is owned by the Wormhole Token Bridge program. This PDA address is stored in the","custodian account."]},{name:"tbtcMint",isMut:!0,isSigner:!1},{name:"recipientToken",isMut:!0,isSigner:!1,docs:["Token account for minted tBTC.","","NOTE: Because the recipient is encoded in the transfer message payload, we can check the","authority from the deserialized VAA. But we should still check whether the authority is the","zero address in access control."]},{name:"recipient",isMut:!1,isSigner:!1,docs:["be created for him."]},{name:"recipientWrappedToken",isMut:!0,isSigner:!1,docs:["The gateway will create an associated token account for the recipient if it doesn't exist.","","NOTE: When the minting limit increases, the recipient can use this token account to mint","tBTC using the deposit_wormhole_tbtc instruction."]},{name:"tbtcConfig",isMut:!1,isSigner:!1},{name:"tbtcMinterInfo",isMut:!1,isSigner:!1},{name:"tokenBridgeConfig",isMut:!1,isSigner:!1},{name:"tokenBridgeRegisteredEmitter",isMut:!1,isSigner:!1},{name:"tokenBridgeWrappedAsset",isMut:!1,isSigner:!1},{name:"tokenBridgeMintAuthority",isMut:!1,isSigner:!1},{name:"rent",isMut:!1,isSigner:!1},{name:"tbtcProgram",isMut:!1,isSigner:!1},{name:"tokenBridgeProgram",isMut:!1,isSigner:!1},{name:"coreBridgeProgram",isMut:!1,isSigner:!1},{name:"associatedTokenProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"messageHash",type:{array:["u8",32]}}]},{name:"sendTbtcGateway",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"gatewayInfo",isMut:!1,isSigner:!1},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["Custody account."]},{name:"wrappedTbtcMint",isMut:!0,isSigner:!1},{name:"tbtcMint",isMut:!0,isSigner:!1},{name:"senderToken",isMut:!0,isSigner:!1},{name:"sender",isMut:!0,isSigner:!0},{name:"tokenBridgeConfig",isMut:!1,isSigner:!1},{name:"tokenBridgeWrappedAsset",isMut:!1,isSigner:!1},{name:"tokenBridgeTransferAuthority",isMut:!1,isSigner:!1},{name:"coreBridgeData",isMut:!0,isSigner:!1},{name:"coreMessage",isMut:!0,isSigner:!1},{name:"tokenBridgeCoreEmitter",isMut:!1,isSigner:!1},{name:"coreEmitterSequence",isMut:!0,isSigner:!1},{name:"coreFeeCollector",isMut:!0,isSigner:!1},{name:"clock",isMut:!1,isSigner:!1},{name:"tokenBridgeSender",isMut:!1,isSigner:!1,docs:["sign for transferring via Token Bridge program with a message."]},{name:"rent",isMut:!1,isSigner:!1},{name:"tokenBridgeProgram",isMut:!1,isSigner:!1},{name:"coreBridgeProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"args",type:{defined:"SendTbtcGatewayArgs"}}]},{name:"sendTbtcWrapped",accounts:[{name:"custodian",isMut:!0,isSigner:!1},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["Custody account."]},{name:"wrappedTbtcMint",isMut:!0,isSigner:!1},{name:"tbtcMint",isMut:!0,isSigner:!1},{name:"senderToken",isMut:!0,isSigner:!1},{name:"sender",isMut:!0,isSigner:!0},{name:"tokenBridgeConfig",isMut:!1,isSigner:!1},{name:"tokenBridgeWrappedAsset",isMut:!1,isSigner:!1},{name:"tokenBridgeTransferAuthority",isMut:!1,isSigner:!1},{name:"coreBridgeData",isMut:!0,isSigner:!1},{name:"coreMessage",isMut:!0,isSigner:!1},{name:"tokenBridgeCoreEmitter",isMut:!1,isSigner:!1},{name:"coreEmitterSequence",isMut:!0,isSigner:!1},{name:"coreFeeCollector",isMut:!0,isSigner:!1},{name:"clock",isMut:!1,isSigner:!1},{name:"rent",isMut:!1,isSigner:!1},{name:"tokenBridgeProgram",isMut:!1,isSigner:!1},{name:"coreBridgeProgram",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"args",type:{defined:"SendTbtcWrappedArgs"}}]},{name:"depositWormholeTbtc",accounts:[{name:"custodian",isMut:!0,isSigner:!1,docs:["NOTE: This account also acts as a minter for the TBTC program."]},{name:"wrappedTbtcToken",isMut:!0,isSigner:!1,docs:["This token account is owned by this program, whose mint is the wrapped TBTC mint. This PDA","address is stored in the custodian account."]},{name:"wrappedTbtcMint",isMut:!1,isSigner:!1,docs:["This mint is owned by the Wormhole Token Bridge program. This PDA address is stored in the","custodian account."]},{name:"tbtcMint",isMut:!0,isSigner:!1,docs:["This mint is owned by the TBTC program. This PDA address is stored in the custodian account."]},{name:"recipientWrappedToken",isMut:!0,isSigner:!1},{name:"recipientToken",isMut:!0,isSigner:!1},{name:"recipient",isMut:!1,isSigner:!0,docs:["This program requires that the owner of the TBTC token account sign for TBTC being minted","into his account."]},{name:"tbtcConfig",isMut:!1,isSigner:!1},{name:"tbtcMinterInfo",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"tbtcProgram",isMut:!1,isSigner:!1}],args:[{name:"amount",type:"u64"}]}],accounts:[{name:"custodian",type:{kind:"struct",fields:[{name:"bump",type:"u8"},{name:"authority",type:"publicKey"},{name:"pendingAuthority",type:{option:"publicKey"}},{name:"tbtcMint",type:"publicKey"},{name:"wrappedTbtcMint",type:"publicKey"},{name:"wrappedTbtcToken",type:"publicKey"},{name:"tokenBridgeSender",type:"publicKey"},{name:"tokenBridgeSenderBump",type:"u8"},{name:"mintingLimit",type:"u64"},{name:"mintedAmount",type:"u64"}]}},{name:"GatewayInfo",type:{kind:"struct",fields:[{name:"bump",type:"u8"},{name:"address",type:{array:["u8",32]}}]}}],types:[{name:"UpdateGatewayAddressArgs",type:{kind:"struct",fields:[{name:"chain",type:"u16"},{name:"address",type:{array:["u8",32]}}]}},{name:"SendTbtcGatewayArgs",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"recipientChain",type:"u16"},{name:"recipient",type:{array:["u8",32]}},{name:"nonce",type:"u32"}]}},{name:"SendTbtcWrappedArgs",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"recipientChain",type:"u16"},{name:"recipient",type:{array:["u8",32]}},{name:"arbiterFee",type:"u64"},{name:"nonce",type:"u32"}]}}],events:[{name:"WormholeTbtcReceived",fields:[{name:"receiver",type:"publicKey",index:!1},{name:"amount",type:"u64",index:!1}]},{name:"WormholeTbtcSent",fields:[{name:"amount",type:"u64",index:!1},{name:"recipientChain",type:"u16",index:!1},{name:"gateway",type:{array:["u8",32]},index:!1},{name:"recipient",type:{array:["u8",32]},index:!1},{name:"arbiterFee",type:"u64",index:!1},{name:"nonce",type:"u32",index:!1}]},{name:"WormholeTbtcDeposited",fields:[{name:"depositor",type:"publicKey",index:!1},{name:"amount",type:"u64",index:!1}]},{name:"GatewayAddressUpdated",fields:[{name:"chain",type:"u16",index:!1},{name:"gateway",type:{array:["u8",32]},index:!1}]},{name:"MintingLimitUpdated",fields:[{name:"mintingLimit",type:"u64",index:!1}]}],errors:[{code:6016,name:"MintingLimitExceeded",msg:"Cannot mint more than the minting limit"},{code:6032,name:"IsNotAuthority",msg:"Only custodian authority is permitted for this action"},{code:6034,name:"IsNotPendingAuthority",msg:"Not valid pending authority to take authority"},{code:6036,name:"NoPendingAuthorityChange",msg:"No pending authority"},{code:6048,name:"ZeroRecipient",msg:"0x0 recipient not allowed"},{code:6064,name:"NotEnoughWrappedTbtc",msg:"Not enough wormhole tBTC in the gateway to bridge"},{code:6080,name:"ZeroAmount",msg:"Amount must not be 0"},{code:6112,name:"TransferAlreadyRedeemed",msg:"Token Bridge transfer already redeemed"},{code:6128,name:"InvalidEthereumTbtc",msg:"Token chain and address do not match Ethereum's tBTC"},{code:6144,name:"NoTbtcTransferred",msg:"No tBTC transferred"},{code:6160,name:"RecipientZeroAddress",msg:"0x0 receiver not allowed"},{code:6176,name:"MintedAmountUnderflow",msg:"Not enough minted by the gateway to satisfy sending tBTC"},{code:6178,name:"MintedAmountOverflow",msg:"Minted amount after deposit exceeds u64"}]};function I(n){return e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("redeemer")],new e.PublicKey(n))[0]}function q(n,i){const t=e.dist.Buffer.alloc(8);return t.writeBigUInt64LE(i),e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("msg"),t],new e.PublicKey(n))[0]}function L(n,i){const t=e.dist.Buffer.alloc(2);return t.writeUInt16LE(e.toChainId(i)),e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("gateway-info"),t],new e.PublicKey(n))[0]}const T=new e.PublicKey("Gj93RRt6QB7FjmyokAD5rcMAku7pq3Fk2Aa8y6nNbwsV");function D(){return e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("config")],T)[0]}function _(n){return e.PublicKey.findProgramAddressSync([e.dist.Buffer.from("minter-info"),n.toBuffer()],T)[0]}const B=new e.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");new e.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");const b=new e.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");new e.PublicKey("So11111111111111111111111111111111111111112");new e.PublicKey("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP");class F extends Error{constructor(i){super(i)}}class z extends F{constructor(){super(...arguments),this.name="TokenOwnerOffCurveError"}}const Y=e.struct([e.u32$1("mintAuthorityOption"),e.publicKey("mintAuthority"),e.u64("supply"),e.u8("decimals"),e.bool("isInitialized"),e.u32$1("freezeAuthorityOption"),e.publicKey("freezeAuthority")]);Y.span;async function M(n,i,t=!1,a=B,s=b){if(!t&&!e.PublicKey.isOnCurve(i.toBuffer()))throw new z;const[r]=await e.PublicKey.findProgramAddress([i.toBuffer(),a.toBuffer(),n.toBuffer()],s);return r}function $(n,i,t,a,s=B,r=b){return H(n,i,t,a,e.dist.Buffer.alloc(0),s,r)}function H(n,i,t,a,s,r=B,o=b){const u=[{pubkey:n,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:u,programId:o,data:s})}class h{constructor(i,t,a,s){c(this,"network");c(this,"chain");c(this,"connection");c(this,"contracts");c(this,"gateway");c(this,"tokenBridgeId");c(this,"coreBridgeId");if(this.network=i,this.chain=t,this.connection=a,this.contracts=s,this.network!=="Mainnet")throw new Error("TBTC is only supported on Mainnet");if(!this.contracts.tbtc)throw new Error("TBTC contract address is required");if(!this.contracts.tokenBridge)throw new Error("TokenBridge contract address is required");if(!this.contracts.coreBridge)throw new Error("CoreBridge contract address is required");this.gateway=new e.Program(U,this.contracts.tbtc,{connection:a}),this.tokenBridgeId=new e.PublicKey(this.contracts.tokenBridge),this.coreBridgeId=new e.PublicKey(this.contracts.coreBridge)}static async fromRpc(i,t){const[a,s]=await e.SolanaPlatform.chainFromRpc(i),r=t[s];if(r.network!==a)throw new Error(`Network mismatch: ${r.network} != ${a}`);return new h(a,s,i,r.contracts)}async*transfer(i,t,a){const s=new e.SolanaAddress(i).unwrap(),r=I(this.gateway.programId),{tbtcMint:o,wrappedTbtcToken:u,wrappedTbtcMint:g}=await this.gateway.account.custodian.fetch(r),p=d.deriveWrappedMetaKey(this.tokenBridgeId,g),m=d.deriveTokenBridgeConfigKey(this.tokenBridgeId),l=d.deriveAuthoritySignerKey(this.tokenBridgeId),A=e.deriveFeeCollectorKey(this.coreBridgeId),{sequence:y}=await e.getProgramSequenceTracker(this.connection,this.tokenBridgeId,this.coreBridgeId),S=q(this.gateway.programId,y),w=e.deriveWormholeBridgeDataKey(this.coreBridgeId),f=e.deriveWormholeEmitterKey(this.tokenBridgeId),k=e.deriveEmitterSequenceKey(f,this.coreBridgeId),K=L(this.gateway.programId,t.chain),E=d.deriveSenderAccountKey(this.gateway.programId),P={amount:new e.bnExports.BN(a.toString()),recipientChain:e.toChainId(t.chain),recipient:[...t.address.toUniversalAddress().toUint8Array()],nonce:0},W=await M(o,s),x=e.tbtc.get(this.network,t.chain),C={custodian:r,wrappedTbtcToken:u,wrappedTbtcMint:g,tbtcMint:o,senderToken:W,sender:s,tokenBridgeConfig:m,tokenBridgeWrappedAsset:p,tokenBridgeTransferAuthority:l,coreBridgeData:w,coreMessage:S,tokenBridgeCoreEmitter:f,coreEmitterSequence:k,coreFeeCollector:A,clock:e.SYSVAR_CLOCK_PUBKEY,rent:e.SYSVAR_RENT_PUBKEY,tokenBridgeProgram:this.tokenBridgeId,coreBridgeProgram:this.coreBridgeId},v=x?await this.gateway.methods.sendTbtcGateway({...P}).accounts({...C,gatewayInfo:K,tokenBridgeSender:E}).instruction():await this.gateway.methods.sendTbtcWrapped({...P,arbiterFee:new e.bnExports.BN(0)}).accounts(C).instruction(),{blockhash:N}=await this.connection.getLatestBlockhash(),O=e.MessageV0.compile({instructions:[v],payerKey:s,recentBlockhash:N}),R=new e.VersionedTransaction(O);yield this.createUnsignedTransaction({transaction:R},"TBTCBridge.Send")}async*redeem(i,t){if(t.payloadName!=="GatewayTransfer")throw new Error("Invalid VAA payload");yield*new e.SolanaWormholeCore(this.network,this.chain,this.connection,this.contracts).postVaa(i,t);const s=[],r=new e.SolanaAddress(i).unwrap(),o=t.payload.payload.recipient.toNative(this.chain).unwrap(),u=I(this.gateway.programId),{tbtcMint:g,wrappedTbtcToken:p,wrappedTbtcMint:m}=await this.gateway.account.custodian.fetch(u),l=await M(g,o);await this.connection.getAccountInfo(l)||s.push($(r,l,o,g));const y=d.deriveWrappedMetaKey(this.tokenBridgeId,m),S=await M(m,o);s.push(await this.gateway.methods.receiveTbtc([...t.hash]).accounts({payer:r,custodian:u,postedVaa:e.derivePostedVaaKey(this.coreBridgeId,e.dist.Buffer.from(t.hash)),tokenBridgeClaim:e.deriveClaimKey(this.tokenBridgeId,t.emitterAddress.toUint8Array(),e.toChainId(t.emitterChain),t.sequence),wrappedTbtcToken:p,wrappedTbtcMint:m,tbtcMint:g,recipientToken:l,recipient:o,recipientWrappedToken:S,tbtcConfig:D(),tbtcMinterInfo:_(u),tokenBridgeConfig:d.deriveTokenBridgeConfigKey(this.tokenBridgeId),tokenBridgeRegisteredEmitter:d.deriveEndpointKey(this.tokenBridgeId,e.toChainId(t.emitterChain),t.emitterAddress.toUint8Array()),tokenBridgeWrappedAsset:y,tokenBridgeMintAuthority:d.deriveMintAuthorityKey(this.tokenBridgeId),rent:e.SYSVAR_RENT_PUBKEY,tbtcProgram:T,tokenBridgeProgram:this.tokenBridgeId,coreBridgeProgram:this.coreBridgeId}).instruction());const{blockhash:w}=await this.connection.getLatestBlockhash(),f=e.MessageV0.compile({instructions:s,payerKey:r,recentBlockhash:w}),k=new e.VersionedTransaction(f);yield this.createUnsignedTransaction({transaction:k},"TBTCBridge.Send")}createUnsignedTransaction(i,t){return new e.SolanaUnsignedTransaction(i,this.network,this.chain,t,!1)}}e.registerProtocol(e._platform$1,"TBTCBridge",h);exports.SolanaTBTCBridge=h;
@@ -1,4 +1,4 @@
1
- import { c as _e, dr as yf, b as or, dw as zi, d as ne, dx as ou, dy as vt, dz as ha, aI as Qr, dC as fu } from "./index-Bnnn4cdG.mjs";
1
+ import { c as _e, dr as yf, b as or, dw as zi, d as ne, dx as ou, dy as vt, dz as ha, aI as Qr, dC as fu } from "./index-BOD0JbTK.mjs";
2
2
  var Zi = {}, vf = { exports: {} }, Hi = {};
3
3
  (function(e) {
4
4
  e.fetch = i(_e.fetch) && i(_e.ReadableStream), e.writableStream = i(_e.WritableStream), e.abortController = i(_e.AbortController);
@@ -1 +1 @@
1
- "use strict";const W=require("./index-X1wTeN-B.js"),j="logger/5.8.0";let F=!1,k=!1;const U={debug:1,default:2,info:2,warning:3,error:4,off:5};let G=U.default,O=null;function Q(){try{const r=[];if(["NFD","NFC","NFKD","NFKC"].forEach(t=>{try{if("test".normalize(t)!=="test")throw new Error("bad normalize")}catch{r.push(t)}}),r.length)throw new Error("missing "+r.join(", "));if("é".normalize("NFD")!=="é")throw new Error("broken implementation")}catch(r){return r.message}return null}const L=Q();var D;(function(r){r.DEBUG="DEBUG",r.INFO="INFO",r.WARNING="WARNING",r.ERROR="ERROR",r.OFF="OFF"})(D||(D={}));var E;(function(r){r.UNKNOWN_ERROR="UNKNOWN_ERROR",r.NOT_IMPLEMENTED="NOT_IMPLEMENTED",r.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",r.NETWORK_ERROR="NETWORK_ERROR",r.SERVER_ERROR="SERVER_ERROR",r.TIMEOUT="TIMEOUT",r.BUFFER_OVERRUN="BUFFER_OVERRUN",r.NUMERIC_FAULT="NUMERIC_FAULT",r.MISSING_NEW="MISSING_NEW",r.INVALID_ARGUMENT="INVALID_ARGUMENT",r.MISSING_ARGUMENT="MISSING_ARGUMENT",r.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",r.CALL_EXCEPTION="CALL_EXCEPTION",r.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",r.NONCE_EXPIRED="NONCE_EXPIRED",r.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",r.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",r.TRANSACTION_REPLACED="TRANSACTION_REPLACED",r.ACTION_REJECTED="ACTION_REJECTED"})(E||(E={}));const B="0123456789abcdef";class o{constructor(t){Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}_log(t,e){const n=t.toLowerCase();U[n]==null&&this.throwArgumentError("invalid log level name","logLevel",t),!(G>U[n])&&console.log.apply(console,e)}debug(...t){this._log(o.levels.DEBUG,t)}info(...t){this._log(o.levels.INFO,t)}warn(...t){this._log(o.levels.WARNING,t)}makeError(t,e,n){if(k)return this.makeError("censored error",e,{});e||(e=o.errors.UNKNOWN_ERROR),n||(n={});const i=[];Object.keys(n).forEach(g=>{const p=n[g];try{if(p instanceof Uint8Array){let S="";for(let I=0;I<p.length;I++)S+=B[p[I]>>4],S+=B[p[I]&15];i.push(g+"=Uint8Array(0x"+S+")")}else i.push(g+"="+JSON.stringify(p))}catch{i.push(g+"="+JSON.stringify(n[g].toString()))}}),i.push(`code=${e}`),i.push(`version=${this.version}`);const N=t;let m="";switch(e){case E.NUMERIC_FAULT:{m="NUMERIC_FAULT";const g=t;switch(g){case"overflow":case"underflow":case"division-by-zero":m+="-"+g;break;case"negative-power":case"negative-width":m+="-unsupported";break;case"unbound-bitwise-result":m+="-unbound-result";break}break}case E.CALL_EXCEPTION:case E.INSUFFICIENT_FUNDS:case E.MISSING_NEW:case E.NONCE_EXPIRED:case E.REPLACEMENT_UNDERPRICED:case E.TRANSACTION_REPLACED:case E.UNPREDICTABLE_GAS_LIMIT:m=e;break}m&&(t+=" [ See: https://links.ethers.org/v5-errors-"+m+" ]"),i.length&&(t+=" ("+i.join(", ")+")");const b=new Error(t);return b.reason=N,b.code=e,Object.keys(n).forEach(function(g){b[g]=n[g]}),b}throwError(t,e,n){throw this.makeError(t,e,n)}throwArgumentError(t,e,n){return this.throwError(t,o.errors.INVALID_ARGUMENT,{argument:e,value:n})}assert(t,e,n,i){t||this.throwError(e,n,i)}assertArgument(t,e,n,i){t||this.throwArgumentError(e,n,i)}checkNormalize(t){L&&this.throwError("platform missing String.prototype.normalize",o.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:L})}checkSafeUint53(t,e){typeof t=="number"&&(e==null&&(e="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(e,o.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(e,o.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}checkArgumentCount(t,e,n){n?n=": "+n:n="",t<e&&this.throwError("missing argument"+n,o.errors.MISSING_ARGUMENT,{count:t,expectedCount:e}),t>e&&this.throwError("too many arguments"+n,o.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:e})}checkNew(t,e){(t===Object||t==null)&&this.throwError("missing new",o.errors.MISSING_NEW,{name:e.name})}checkAbstract(t,e){t===e?this.throwError("cannot instantiate abstract class "+JSON.stringify(e.name)+" directly; use a sub-class",o.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):(t===Object||t==null)&&this.throwError("missing new",o.errors.MISSING_NEW,{name:e.name})}static globalLogger(){return O||(O=new o(j)),O}static setCensorship(t,e){if(!t&&e&&this.globalLogger().throwError("cannot permanently disable censorship",o.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),F){if(!t)return;this.globalLogger().throwError("error censorship permanent",o.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}k=!!t,F=!!e}static setLogLevel(t){const e=U[t.toLowerCase()];if(e==null){o.globalLogger().warn("invalid log level - "+t);return}G=e}static from(t){return new o(t)}}o.errors=E;o.levels=D;const Y="bytes/5.8.0",f=new o(Y);function V(r){return!!r.toHexString}function y(r){return r.slice||(r.slice=function(){const t=Array.prototype.slice.call(arguments);return y(new Uint8Array(Array.prototype.slice.apply(r,t)))}),r}function rr(r){return l(r)&&!(r.length%2)||P(r)}function z(r){return typeof r=="number"&&r==r&&r%1===0}function P(r){if(r==null)return!1;if(r.constructor===Uint8Array)return!0;if(typeof r=="string"||!z(r.length)||r.length<0)return!1;for(let t=0;t<r.length;t++){const e=r[t];if(!z(e)||e<0||e>=256)return!1}return!0}function A(r,t){if(t||(t={}),typeof r=="number"){f.checkSafeUint53(r,"invalid arrayify value");const e=[];for(;r;)e.unshift(r&255),r=parseInt(String(r/256));return e.length===0&&e.push(0),y(new Uint8Array(e))}if(t.allowMissingPrefix&&typeof r=="string"&&r.substring(0,2)!=="0x"&&(r="0x"+r),V(r)&&(r=r.toHexString()),l(r)){let e=r.substring(2);e.length%2&&(t.hexPad==="left"?e="0"+e:t.hexPad==="right"?e+="0":f.throwArgumentError("hex data is odd-length","value",r));const n=[];for(let i=0;i<e.length;i+=2)n.push(parseInt(e.substring(i,i+2),16));return y(new Uint8Array(n))}return P(r)?y(new Uint8Array(r)):f.throwArgumentError("invalid arrayify value","value",r)}function tr(r){const t=r.map(i=>A(i)),e=t.reduce((i,N)=>i+N.length,0),n=new Uint8Array(e);return t.reduce((i,N)=>(n.set(N,i),i+N.length),0),y(n)}function er(r,t){r=A(r),r.length>t&&f.throwArgumentError("value out of range","value",arguments[0]);const e=new Uint8Array(t);return e.set(r,t-r.length),y(e)}function l(r,t){return!(typeof r!="string"||!r.match(/^0x[0-9A-Fa-f]*$/)||t&&r.length!==2+2*t)}const d="0123456789abcdef";function c(r,t){if(t||(t={}),typeof r=="number"){f.checkSafeUint53(r,"invalid hexlify value");let e="";for(;r;)e=d[r&15]+e,r=Math.floor(r/16);return e.length?(e.length%2&&(e="0"+e),"0x"+e):"0x00"}if(typeof r=="bigint")return r=r.toString(16),r.length%2?"0x0"+r:"0x"+r;if(t.allowMissingPrefix&&typeof r=="string"&&r.substring(0,2)!=="0x"&&(r="0x"+r),V(r))return r.toHexString();if(l(r))return r.length%2&&(t.hexPad==="left"?r="0x0"+r.substring(2):t.hexPad==="right"?r+="0":f.throwArgumentError("hex data is odd-length","value",r)),r.toLowerCase();if(P(r)){let e="0x";for(let n=0;n<r.length;n++){let i=r[n];e+=d[(i&240)>>4]+d[i&15]}return e}return f.throwArgumentError("invalid hexlify value","value",r)}function nr(r){if(typeof r!="string")r=c(r);else if(!l(r)||r.length%2)return null;return(r.length-2)/2}function ir(r,t,e){return typeof r!="string"?r=c(r):(!l(r)||r.length%2)&&f.throwArgumentError("invalid hexData","value",r),t=2+2*t,e!=null?"0x"+r.substring(t,2+2*e):"0x"+r.substring(t)}function sr(r){let t="0x";return r.forEach(e=>{t+=c(e).substring(2)}),t}function _(r,t){for(typeof r!="string"?r=c(r):l(r)||f.throwArgumentError("invalid hex string","value",r),r.length>2*t+2&&f.throwArgumentError("value out of range","value",arguments[1]);r.length<2*t+2;)r="0x0"+r.substring(2);return r}function or(r){const t={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(rr(r)){let e=A(r);e.length===64?(t.v=27+(e[32]>>7),e[32]&=127,t.r=c(e.slice(0,32)),t.s=c(e.slice(32,64))):e.length===65?(t.r=c(e.slice(0,32)),t.s=c(e.slice(32,64)),t.v=e[64]):f.throwArgumentError("invalid signature string","signature",r),t.v<27&&(t.v===0||t.v===1?t.v+=27:f.throwArgumentError("signature invalid v byte","signature",r)),t.recoveryParam=1-t.v%2,t.recoveryParam&&(e[32]|=128),t._vs=c(e.slice(32,64))}else{if(t.r=r.r,t.s=r.s,t.v=r.v,t.recoveryParam=r.recoveryParam,t._vs=r._vs,t._vs!=null){const i=er(A(t._vs),32);t._vs=c(i);const N=i[0]>=128?1:0;t.recoveryParam==null?t.recoveryParam=N:t.recoveryParam!==N&&f.throwArgumentError("signature recoveryParam mismatch _vs","signature",r),i[0]&=127;const m=c(i);t.s==null?t.s=m:t.s!==m&&f.throwArgumentError("signature v mismatch _vs","signature",r)}if(t.recoveryParam==null)t.v==null?f.throwArgumentError("signature missing v and recoveryParam","signature",r):t.v===0||t.v===1?t.recoveryParam=t.v:t.recoveryParam=1-t.v%2;else if(t.v==null)t.v=27+t.recoveryParam;else{const i=t.v===0||t.v===1?t.v:1-t.v%2;t.recoveryParam!==i&&f.throwArgumentError("signature recoveryParam mismatch v","signature",r)}t.r==null||!l(t.r)?f.throwArgumentError("signature missing or invalid r","signature",r):t.r=_(t.r,32),t.s==null||!l(t.s)?f.throwArgumentError("signature missing or invalid s","signature",r):t.s=_(t.s,32);const e=A(t.s);e[0]>=128&&f.throwArgumentError("signature s out of range","signature",r),t.recoveryParam&&(e[0]|=128);const n=c(e);t._vs&&(l(t._vs)||f.throwArgumentError("signature invalid _vs","signature",r),t._vs=_(t._vs,32)),t._vs==null?t._vs=n:t._vs!==n&&f.throwArgumentError("signature _vs mismatch v and s","signature",r)}return t.yParityAndS=t._vs,t.compact=t.r+t.yParityAndS.substring(2),t}const fr="bignumber/5.7.0";var T=W.BN.BN;const w=new o(fr),C={},ur=9007199254740991;let $=!1;class h{constructor(t,e){t!==C&&w.throwError("cannot call constructor directly; use BigNumber.from",o.errors.UNSUPPORTED_OPERATION,{operation:"new (BigNumber)"}),this._hex=e,this._isBigNumber=!0,Object.freeze(this)}fromTwos(t){return u(s(this).fromTwos(t))}toTwos(t){return u(s(this).toTwos(t))}abs(){return this._hex[0]==="-"?h.from(this._hex.substring(1)):this}add(t){return u(s(this).add(s(t)))}sub(t){return u(s(this).sub(s(t)))}div(t){return h.from(t).isZero()&&a("division-by-zero","div"),u(s(this).div(s(t)))}mul(t){return u(s(this).mul(s(t)))}mod(t){const e=s(t);return e.isNeg()&&a("division-by-zero","mod"),u(s(this).umod(e))}pow(t){const e=s(t);return e.isNeg()&&a("negative-power","pow"),u(s(this).pow(e))}and(t){const e=s(t);return(this.isNegative()||e.isNeg())&&a("unbound-bitwise-result","and"),u(s(this).and(e))}or(t){const e=s(t);return(this.isNegative()||e.isNeg())&&a("unbound-bitwise-result","or"),u(s(this).or(e))}xor(t){const e=s(t);return(this.isNegative()||e.isNeg())&&a("unbound-bitwise-result","xor"),u(s(this).xor(e))}mask(t){return(this.isNegative()||t<0)&&a("negative-width","mask"),u(s(this).maskn(t))}shl(t){return(this.isNegative()||t<0)&&a("negative-width","shl"),u(s(this).shln(t))}shr(t){return(this.isNegative()||t<0)&&a("negative-width","shr"),u(s(this).shrn(t))}eq(t){return s(this).eq(s(t))}lt(t){return s(this).lt(s(t))}lte(t){return s(this).lte(s(t))}gt(t){return s(this).gt(s(t))}gte(t){return s(this).gte(s(t))}isNegative(){return this._hex[0]==="-"}isZero(){return s(this).isZero()}toNumber(){try{return s(this).toNumber()}catch{a("overflow","toNumber",this.toString())}return null}toBigInt(){try{return BigInt(this.toString())}catch{}return w.throwError("this platform does not support BigInt",o.errors.UNSUPPORTED_OPERATION,{value:this.toString()})}toString(){return arguments.length>0&&(arguments[0]===10?$||($=!0,w.warn("BigNumber.toString does not accept any parameters; base-10 is assumed")):arguments[0]===16?w.throwError("BigNumber.toString does not accept any parameters; use bigNumber.toHexString()",o.errors.UNEXPECTED_ARGUMENT,{}):w.throwError("BigNumber.toString does not accept parameters",o.errors.UNEXPECTED_ARGUMENT,{})),s(this).toString(10)}toHexString(){return this._hex}toJSON(t){return{type:"BigNumber",hex:this.toHexString()}}static from(t){if(t instanceof h)return t;if(typeof t=="string")return t.match(/^-?0x[0-9a-f]+$/i)?new h(C,R(t)):t.match(/^-?[0-9]+$/)?new h(C,R(new T(t))):w.throwArgumentError("invalid BigNumber string","value",t);if(typeof t=="number")return t%1&&a("underflow","BigNumber.from",t),(t>=ur||t<=-9007199254740991)&&a("overflow","BigNumber.from",t),h.from(String(t));const e=t;if(typeof e=="bigint")return h.from(e.toString());if(P(e))return h.from(c(e));if(e)if(e.toHexString){const n=e.toHexString();if(typeof n=="string")return h.from(n)}else{let n=e._hex;if(n==null&&e.type==="BigNumber"&&(n=e.hex),typeof n=="string"&&(l(n)||n[0]==="-"&&l(n.substring(1))))return h.from(n)}return w.throwArgumentError("invalid BigNumber value","value",t)}static isBigNumber(t){return!!(t&&t._isBigNumber)}}function R(r){if(typeof r!="string")return R(r.toString(16));if(r[0]==="-")return r=r.substring(1),r[0]==="-"&&w.throwArgumentError("invalid hex","value",r),r=R(r),r==="0x00"?r:"-"+r;if(r.substring(0,2)!=="0x"&&(r="0x"+r),r==="0x")return"0x00";for(r.length%2&&(r="0x0"+r.substring(2));r.length>4&&r.substring(0,4)==="0x00";)r="0x"+r.substring(4);return r}function u(r){return h.from(R(r))}function s(r){const t=h.from(r).toHexString();return t[0]==="-"?new T("-"+t.substring(3),16):new T(t.substring(2),16)}function a(r,t,e){const n={fault:r,operation:t};return e!=null&&(n.value=e),w.throwError(r,o.errors.NUMERIC_FAULT,n)}function hr(r){return new T(r,36).toString(16)}const cr="properties/5.7.0",K=new o(cr);function J(r,t,e){Object.defineProperty(r,t,{enumerable:!0,value:e,writable:!1})}function lr(r,t){for(let e=0;e<32;e++){if(r[t])return r[t];if(!r.prototype||typeof r.prototype!="object")break;r=Object.getPrototypeOf(r.prototype).constructor}return null}const ar={bigint:!0,boolean:!0,function:!0,number:!0,string:!0};function Z(r){if(r==null||ar[typeof r])return!0;if(Array.isArray(r)||typeof r=="object"){if(!Object.isFrozen(r))return!1;const t=Object.keys(r);for(let e=0;e<t.length;e++){let n=null;try{n=r[t[e]]}catch{continue}if(!Z(n))return!1}return!0}return K.throwArgumentError(`Cannot deepCopy ${typeof r}`,"object",r)}function gr(r){if(Z(r))return r;if(Array.isArray(r))return Object.freeze(r.map(t=>M(t)));if(typeof r=="object"){const t={};for(const e in r){const n=r[e];n!==void 0&&J(t,e,M(n))}return t}return K.throwArgumentError(`Cannot deepCopy ${typeof r}`,"object",r)}function M(r){return gr(r)}class Er{constructor(t){for(const e in t)this[e]=M(t[e])}}function q(r){return"0x"+W.sha3.keccak_256(A(r))}const mr="address/5.7.0",x=new o(mr);function H(r){l(r,20)||x.throwArgumentError("invalid address","address",r),r=r.toLowerCase();const t=r.substring(2).split(""),e=new Uint8Array(40);for(let i=0;i<40;i++)e[i]=t[i].charCodeAt(0);const n=A(q(e));for(let i=0;i<40;i+=2)n[i>>1]>>4>=8&&(t[i]=t[i].toUpperCase()),(n[i>>1]&15)>=8&&(t[i+1]=t[i+1].toUpperCase());return"0x"+t.join("")}const Nr=9007199254740991;function wr(r){return Math.log10?Math.log10(r):Math.log(r)/Math.LN10}const v={};for(let r=0;r<10;r++)v[String(r)]=String(r);for(let r=0;r<26;r++)v[String.fromCharCode(65+r)]=String(10+r);const X=Math.floor(wr(Nr));function Ar(r){r=r.toUpperCase(),r=r.substring(4)+r.substring(0,2)+"00";let t=r.split("").map(n=>v[n]).join("");for(;t.length>=X;){let n=t.substring(0,X);t=parseInt(n,10)%97+t.substring(n.length)}let e=String(98-parseInt(t,10)%97);for(;e.length<2;)e="0"+e;return e}function yr(r){let t=null;if(typeof r!="string"&&x.throwArgumentError("invalid address","address",r),r.match(/^(0x)?[0-9a-fA-F]{40}$/))r.substring(0,2)!=="0x"&&(r="0x"+r),t=H(r),r.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&t!==r&&x.throwArgumentError("bad address checksum","address",r);else if(r.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(r.substring(2,4)!==Ar(r)&&x.throwArgumentError("bad icap checksum","address",r),t=hr(r.substring(4));t.length<40;)t="0"+t;t=H("0x"+t)}else x.throwArgumentError("invalid address","address",r);return t}exports.BigNumber=h;exports.Description=Er;exports.Logger=o;exports.arrayify=A;exports.concat=tr;exports.defineReadOnly=J;exports.getAddress=yr;exports.getStatic=lr;exports.hexConcat=sr;exports.hexDataLength=nr;exports.hexDataSlice=ir;exports.hexZeroPad=_;exports.hexlify=c;exports.isHexString=l;exports.keccak256=q;exports.splitSignature=or;
1
+ "use strict";const W=require("./index-DoE4VQhB.js"),j="logger/5.8.0";let F=!1,k=!1;const U={debug:1,default:2,info:2,warning:3,error:4,off:5};let G=U.default,O=null;function Q(){try{const r=[];if(["NFD","NFC","NFKD","NFKC"].forEach(t=>{try{if("test".normalize(t)!=="test")throw new Error("bad normalize")}catch{r.push(t)}}),r.length)throw new Error("missing "+r.join(", "));if("é".normalize("NFD")!=="é")throw new Error("broken implementation")}catch(r){return r.message}return null}const L=Q();var D;(function(r){r.DEBUG="DEBUG",r.INFO="INFO",r.WARNING="WARNING",r.ERROR="ERROR",r.OFF="OFF"})(D||(D={}));var E;(function(r){r.UNKNOWN_ERROR="UNKNOWN_ERROR",r.NOT_IMPLEMENTED="NOT_IMPLEMENTED",r.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",r.NETWORK_ERROR="NETWORK_ERROR",r.SERVER_ERROR="SERVER_ERROR",r.TIMEOUT="TIMEOUT",r.BUFFER_OVERRUN="BUFFER_OVERRUN",r.NUMERIC_FAULT="NUMERIC_FAULT",r.MISSING_NEW="MISSING_NEW",r.INVALID_ARGUMENT="INVALID_ARGUMENT",r.MISSING_ARGUMENT="MISSING_ARGUMENT",r.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",r.CALL_EXCEPTION="CALL_EXCEPTION",r.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",r.NONCE_EXPIRED="NONCE_EXPIRED",r.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",r.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",r.TRANSACTION_REPLACED="TRANSACTION_REPLACED",r.ACTION_REJECTED="ACTION_REJECTED"})(E||(E={}));const B="0123456789abcdef";class o{constructor(t){Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}_log(t,e){const n=t.toLowerCase();U[n]==null&&this.throwArgumentError("invalid log level name","logLevel",t),!(G>U[n])&&console.log.apply(console,e)}debug(...t){this._log(o.levels.DEBUG,t)}info(...t){this._log(o.levels.INFO,t)}warn(...t){this._log(o.levels.WARNING,t)}makeError(t,e,n){if(k)return this.makeError("censored error",e,{});e||(e=o.errors.UNKNOWN_ERROR),n||(n={});const i=[];Object.keys(n).forEach(g=>{const p=n[g];try{if(p instanceof Uint8Array){let S="";for(let I=0;I<p.length;I++)S+=B[p[I]>>4],S+=B[p[I]&15];i.push(g+"=Uint8Array(0x"+S+")")}else i.push(g+"="+JSON.stringify(p))}catch{i.push(g+"="+JSON.stringify(n[g].toString()))}}),i.push(`code=${e}`),i.push(`version=${this.version}`);const N=t;let m="";switch(e){case E.NUMERIC_FAULT:{m="NUMERIC_FAULT";const g=t;switch(g){case"overflow":case"underflow":case"division-by-zero":m+="-"+g;break;case"negative-power":case"negative-width":m+="-unsupported";break;case"unbound-bitwise-result":m+="-unbound-result";break}break}case E.CALL_EXCEPTION:case E.INSUFFICIENT_FUNDS:case E.MISSING_NEW:case E.NONCE_EXPIRED:case E.REPLACEMENT_UNDERPRICED:case E.TRANSACTION_REPLACED:case E.UNPREDICTABLE_GAS_LIMIT:m=e;break}m&&(t+=" [ See: https://links.ethers.org/v5-errors-"+m+" ]"),i.length&&(t+=" ("+i.join(", ")+")");const b=new Error(t);return b.reason=N,b.code=e,Object.keys(n).forEach(function(g){b[g]=n[g]}),b}throwError(t,e,n){throw this.makeError(t,e,n)}throwArgumentError(t,e,n){return this.throwError(t,o.errors.INVALID_ARGUMENT,{argument:e,value:n})}assert(t,e,n,i){t||this.throwError(e,n,i)}assertArgument(t,e,n,i){t||this.throwArgumentError(e,n,i)}checkNormalize(t){L&&this.throwError("platform missing String.prototype.normalize",o.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:L})}checkSafeUint53(t,e){typeof t=="number"&&(e==null&&(e="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(e,o.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(e,o.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}checkArgumentCount(t,e,n){n?n=": "+n:n="",t<e&&this.throwError("missing argument"+n,o.errors.MISSING_ARGUMENT,{count:t,expectedCount:e}),t>e&&this.throwError("too many arguments"+n,o.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:e})}checkNew(t,e){(t===Object||t==null)&&this.throwError("missing new",o.errors.MISSING_NEW,{name:e.name})}checkAbstract(t,e){t===e?this.throwError("cannot instantiate abstract class "+JSON.stringify(e.name)+" directly; use a sub-class",o.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):(t===Object||t==null)&&this.throwError("missing new",o.errors.MISSING_NEW,{name:e.name})}static globalLogger(){return O||(O=new o(j)),O}static setCensorship(t,e){if(!t&&e&&this.globalLogger().throwError("cannot permanently disable censorship",o.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),F){if(!t)return;this.globalLogger().throwError("error censorship permanent",o.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}k=!!t,F=!!e}static setLogLevel(t){const e=U[t.toLowerCase()];if(e==null){o.globalLogger().warn("invalid log level - "+t);return}G=e}static from(t){return new o(t)}}o.errors=E;o.levels=D;const Y="bytes/5.8.0",f=new o(Y);function V(r){return!!r.toHexString}function y(r){return r.slice||(r.slice=function(){const t=Array.prototype.slice.call(arguments);return y(new Uint8Array(Array.prototype.slice.apply(r,t)))}),r}function rr(r){return l(r)&&!(r.length%2)||P(r)}function z(r){return typeof r=="number"&&r==r&&r%1===0}function P(r){if(r==null)return!1;if(r.constructor===Uint8Array)return!0;if(typeof r=="string"||!z(r.length)||r.length<0)return!1;for(let t=0;t<r.length;t++){const e=r[t];if(!z(e)||e<0||e>=256)return!1}return!0}function A(r,t){if(t||(t={}),typeof r=="number"){f.checkSafeUint53(r,"invalid arrayify value");const e=[];for(;r;)e.unshift(r&255),r=parseInt(String(r/256));return e.length===0&&e.push(0),y(new Uint8Array(e))}if(t.allowMissingPrefix&&typeof r=="string"&&r.substring(0,2)!=="0x"&&(r="0x"+r),V(r)&&(r=r.toHexString()),l(r)){let e=r.substring(2);e.length%2&&(t.hexPad==="left"?e="0"+e:t.hexPad==="right"?e+="0":f.throwArgumentError("hex data is odd-length","value",r));const n=[];for(let i=0;i<e.length;i+=2)n.push(parseInt(e.substring(i,i+2),16));return y(new Uint8Array(n))}return P(r)?y(new Uint8Array(r)):f.throwArgumentError("invalid arrayify value","value",r)}function tr(r){const t=r.map(i=>A(i)),e=t.reduce((i,N)=>i+N.length,0),n=new Uint8Array(e);return t.reduce((i,N)=>(n.set(N,i),i+N.length),0),y(n)}function er(r,t){r=A(r),r.length>t&&f.throwArgumentError("value out of range","value",arguments[0]);const e=new Uint8Array(t);return e.set(r,t-r.length),y(e)}function l(r,t){return!(typeof r!="string"||!r.match(/^0x[0-9A-Fa-f]*$/)||t&&r.length!==2+2*t)}const d="0123456789abcdef";function c(r,t){if(t||(t={}),typeof r=="number"){f.checkSafeUint53(r,"invalid hexlify value");let e="";for(;r;)e=d[r&15]+e,r=Math.floor(r/16);return e.length?(e.length%2&&(e="0"+e),"0x"+e):"0x00"}if(typeof r=="bigint")return r=r.toString(16),r.length%2?"0x0"+r:"0x"+r;if(t.allowMissingPrefix&&typeof r=="string"&&r.substring(0,2)!=="0x"&&(r="0x"+r),V(r))return r.toHexString();if(l(r))return r.length%2&&(t.hexPad==="left"?r="0x0"+r.substring(2):t.hexPad==="right"?r+="0":f.throwArgumentError("hex data is odd-length","value",r)),r.toLowerCase();if(P(r)){let e="0x";for(let n=0;n<r.length;n++){let i=r[n];e+=d[(i&240)>>4]+d[i&15]}return e}return f.throwArgumentError("invalid hexlify value","value",r)}function nr(r){if(typeof r!="string")r=c(r);else if(!l(r)||r.length%2)return null;return(r.length-2)/2}function ir(r,t,e){return typeof r!="string"?r=c(r):(!l(r)||r.length%2)&&f.throwArgumentError("invalid hexData","value",r),t=2+2*t,e!=null?"0x"+r.substring(t,2+2*e):"0x"+r.substring(t)}function sr(r){let t="0x";return r.forEach(e=>{t+=c(e).substring(2)}),t}function _(r,t){for(typeof r!="string"?r=c(r):l(r)||f.throwArgumentError("invalid hex string","value",r),r.length>2*t+2&&f.throwArgumentError("value out of range","value",arguments[1]);r.length<2*t+2;)r="0x0"+r.substring(2);return r}function or(r){const t={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(rr(r)){let e=A(r);e.length===64?(t.v=27+(e[32]>>7),e[32]&=127,t.r=c(e.slice(0,32)),t.s=c(e.slice(32,64))):e.length===65?(t.r=c(e.slice(0,32)),t.s=c(e.slice(32,64)),t.v=e[64]):f.throwArgumentError("invalid signature string","signature",r),t.v<27&&(t.v===0||t.v===1?t.v+=27:f.throwArgumentError("signature invalid v byte","signature",r)),t.recoveryParam=1-t.v%2,t.recoveryParam&&(e[32]|=128),t._vs=c(e.slice(32,64))}else{if(t.r=r.r,t.s=r.s,t.v=r.v,t.recoveryParam=r.recoveryParam,t._vs=r._vs,t._vs!=null){const i=er(A(t._vs),32);t._vs=c(i);const N=i[0]>=128?1:0;t.recoveryParam==null?t.recoveryParam=N:t.recoveryParam!==N&&f.throwArgumentError("signature recoveryParam mismatch _vs","signature",r),i[0]&=127;const m=c(i);t.s==null?t.s=m:t.s!==m&&f.throwArgumentError("signature v mismatch _vs","signature",r)}if(t.recoveryParam==null)t.v==null?f.throwArgumentError("signature missing v and recoveryParam","signature",r):t.v===0||t.v===1?t.recoveryParam=t.v:t.recoveryParam=1-t.v%2;else if(t.v==null)t.v=27+t.recoveryParam;else{const i=t.v===0||t.v===1?t.v:1-t.v%2;t.recoveryParam!==i&&f.throwArgumentError("signature recoveryParam mismatch v","signature",r)}t.r==null||!l(t.r)?f.throwArgumentError("signature missing or invalid r","signature",r):t.r=_(t.r,32),t.s==null||!l(t.s)?f.throwArgumentError("signature missing or invalid s","signature",r):t.s=_(t.s,32);const e=A(t.s);e[0]>=128&&f.throwArgumentError("signature s out of range","signature",r),t.recoveryParam&&(e[0]|=128);const n=c(e);t._vs&&(l(t._vs)||f.throwArgumentError("signature invalid _vs","signature",r),t._vs=_(t._vs,32)),t._vs==null?t._vs=n:t._vs!==n&&f.throwArgumentError("signature _vs mismatch v and s","signature",r)}return t.yParityAndS=t._vs,t.compact=t.r+t.yParityAndS.substring(2),t}const fr="bignumber/5.7.0";var T=W.BN.BN;const w=new o(fr),C={},ur=9007199254740991;let $=!1;class h{constructor(t,e){t!==C&&w.throwError("cannot call constructor directly; use BigNumber.from",o.errors.UNSUPPORTED_OPERATION,{operation:"new (BigNumber)"}),this._hex=e,this._isBigNumber=!0,Object.freeze(this)}fromTwos(t){return u(s(this).fromTwos(t))}toTwos(t){return u(s(this).toTwos(t))}abs(){return this._hex[0]==="-"?h.from(this._hex.substring(1)):this}add(t){return u(s(this).add(s(t)))}sub(t){return u(s(this).sub(s(t)))}div(t){return h.from(t).isZero()&&a("division-by-zero","div"),u(s(this).div(s(t)))}mul(t){return u(s(this).mul(s(t)))}mod(t){const e=s(t);return e.isNeg()&&a("division-by-zero","mod"),u(s(this).umod(e))}pow(t){const e=s(t);return e.isNeg()&&a("negative-power","pow"),u(s(this).pow(e))}and(t){const e=s(t);return(this.isNegative()||e.isNeg())&&a("unbound-bitwise-result","and"),u(s(this).and(e))}or(t){const e=s(t);return(this.isNegative()||e.isNeg())&&a("unbound-bitwise-result","or"),u(s(this).or(e))}xor(t){const e=s(t);return(this.isNegative()||e.isNeg())&&a("unbound-bitwise-result","xor"),u(s(this).xor(e))}mask(t){return(this.isNegative()||t<0)&&a("negative-width","mask"),u(s(this).maskn(t))}shl(t){return(this.isNegative()||t<0)&&a("negative-width","shl"),u(s(this).shln(t))}shr(t){return(this.isNegative()||t<0)&&a("negative-width","shr"),u(s(this).shrn(t))}eq(t){return s(this).eq(s(t))}lt(t){return s(this).lt(s(t))}lte(t){return s(this).lte(s(t))}gt(t){return s(this).gt(s(t))}gte(t){return s(this).gte(s(t))}isNegative(){return this._hex[0]==="-"}isZero(){return s(this).isZero()}toNumber(){try{return s(this).toNumber()}catch{a("overflow","toNumber",this.toString())}return null}toBigInt(){try{return BigInt(this.toString())}catch{}return w.throwError("this platform does not support BigInt",o.errors.UNSUPPORTED_OPERATION,{value:this.toString()})}toString(){return arguments.length>0&&(arguments[0]===10?$||($=!0,w.warn("BigNumber.toString does not accept any parameters; base-10 is assumed")):arguments[0]===16?w.throwError("BigNumber.toString does not accept any parameters; use bigNumber.toHexString()",o.errors.UNEXPECTED_ARGUMENT,{}):w.throwError("BigNumber.toString does not accept parameters",o.errors.UNEXPECTED_ARGUMENT,{})),s(this).toString(10)}toHexString(){return this._hex}toJSON(t){return{type:"BigNumber",hex:this.toHexString()}}static from(t){if(t instanceof h)return t;if(typeof t=="string")return t.match(/^-?0x[0-9a-f]+$/i)?new h(C,R(t)):t.match(/^-?[0-9]+$/)?new h(C,R(new T(t))):w.throwArgumentError("invalid BigNumber string","value",t);if(typeof t=="number")return t%1&&a("underflow","BigNumber.from",t),(t>=ur||t<=-9007199254740991)&&a("overflow","BigNumber.from",t),h.from(String(t));const e=t;if(typeof e=="bigint")return h.from(e.toString());if(P(e))return h.from(c(e));if(e)if(e.toHexString){const n=e.toHexString();if(typeof n=="string")return h.from(n)}else{let n=e._hex;if(n==null&&e.type==="BigNumber"&&(n=e.hex),typeof n=="string"&&(l(n)||n[0]==="-"&&l(n.substring(1))))return h.from(n)}return w.throwArgumentError("invalid BigNumber value","value",t)}static isBigNumber(t){return!!(t&&t._isBigNumber)}}function R(r){if(typeof r!="string")return R(r.toString(16));if(r[0]==="-")return r=r.substring(1),r[0]==="-"&&w.throwArgumentError("invalid hex","value",r),r=R(r),r==="0x00"?r:"-"+r;if(r.substring(0,2)!=="0x"&&(r="0x"+r),r==="0x")return"0x00";for(r.length%2&&(r="0x0"+r.substring(2));r.length>4&&r.substring(0,4)==="0x00";)r="0x"+r.substring(4);return r}function u(r){return h.from(R(r))}function s(r){const t=h.from(r).toHexString();return t[0]==="-"?new T("-"+t.substring(3),16):new T(t.substring(2),16)}function a(r,t,e){const n={fault:r,operation:t};return e!=null&&(n.value=e),w.throwError(r,o.errors.NUMERIC_FAULT,n)}function hr(r){return new T(r,36).toString(16)}const cr="properties/5.7.0",K=new o(cr);function J(r,t,e){Object.defineProperty(r,t,{enumerable:!0,value:e,writable:!1})}function lr(r,t){for(let e=0;e<32;e++){if(r[t])return r[t];if(!r.prototype||typeof r.prototype!="object")break;r=Object.getPrototypeOf(r.prototype).constructor}return null}const ar={bigint:!0,boolean:!0,function:!0,number:!0,string:!0};function Z(r){if(r==null||ar[typeof r])return!0;if(Array.isArray(r)||typeof r=="object"){if(!Object.isFrozen(r))return!1;const t=Object.keys(r);for(let e=0;e<t.length;e++){let n=null;try{n=r[t[e]]}catch{continue}if(!Z(n))return!1}return!0}return K.throwArgumentError(`Cannot deepCopy ${typeof r}`,"object",r)}function gr(r){if(Z(r))return r;if(Array.isArray(r))return Object.freeze(r.map(t=>M(t)));if(typeof r=="object"){const t={};for(const e in r){const n=r[e];n!==void 0&&J(t,e,M(n))}return t}return K.throwArgumentError(`Cannot deepCopy ${typeof r}`,"object",r)}function M(r){return gr(r)}class Er{constructor(t){for(const e in t)this[e]=M(t[e])}}function q(r){return"0x"+W.sha3.keccak_256(A(r))}const mr="address/5.7.0",x=new o(mr);function H(r){l(r,20)||x.throwArgumentError("invalid address","address",r),r=r.toLowerCase();const t=r.substring(2).split(""),e=new Uint8Array(40);for(let i=0;i<40;i++)e[i]=t[i].charCodeAt(0);const n=A(q(e));for(let i=0;i<40;i+=2)n[i>>1]>>4>=8&&(t[i]=t[i].toUpperCase()),(n[i>>1]&15)>=8&&(t[i+1]=t[i+1].toUpperCase());return"0x"+t.join("")}const Nr=9007199254740991;function wr(r){return Math.log10?Math.log10(r):Math.log(r)/Math.LN10}const v={};for(let r=0;r<10;r++)v[String(r)]=String(r);for(let r=0;r<26;r++)v[String.fromCharCode(65+r)]=String(10+r);const X=Math.floor(wr(Nr));function Ar(r){r=r.toUpperCase(),r=r.substring(4)+r.substring(0,2)+"00";let t=r.split("").map(n=>v[n]).join("");for(;t.length>=X;){let n=t.substring(0,X);t=parseInt(n,10)%97+t.substring(n.length)}let e=String(98-parseInt(t,10)%97);for(;e.length<2;)e="0"+e;return e}function yr(r){let t=null;if(typeof r!="string"&&x.throwArgumentError("invalid address","address",r),r.match(/^(0x)?[0-9a-fA-F]{40}$/))r.substring(0,2)!=="0x"&&(r="0x"+r),t=H(r),r.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&t!==r&&x.throwArgumentError("bad address checksum","address",r);else if(r.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(r.substring(2,4)!==Ar(r)&&x.throwArgumentError("bad icap checksum","address",r),t=hr(r.substring(4));t.length<40;)t="0"+t;t=H("0x"+t)}else x.throwArgumentError("invalid address","address",r);return t}exports.BigNumber=h;exports.Description=Er;exports.Logger=o;exports.arrayify=A;exports.concat=tr;exports.defineReadOnly=J;exports.getAddress=yr;exports.getStatic=lr;exports.hexConcat=sr;exports.hexDataLength=nr;exports.hexDataSlice=ir;exports.hexZeroPad=_;exports.hexlify=c;exports.isHexString=l;exports.keccak256=q;exports.splitSignature=or;
@@ -1,8 +1,8 @@
1
1
  var oe = Object.defineProperty;
2
2
  var se = (k, t, e) => t in k ? oe(k, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : k[t] = e;
3
3
  var h = (k, t, e) => se(k, typeof t != "symbol" ? t + "" : t, e);
4
- import { cY as N, cZ as F, c_ as ae, c$ as Z, d0 as W, d1 as $, d2 as S, bM as ie, aD as I, c5 as R, d3 as b, c6 as q, bR as ce, bK as j, aF as O, am as v, bO as de, cb as H, c8 as le, d4 as _, d5 as C, d6 as ge, d7 as ue, d8 as M, d9 as fe, bS as V, da as D, db as Q, dc as pe, dd as x, de as he, df as we, ap as U, dg as ye, dh as X, cP as ke, di as me, cC as Y, dj as be, dk as Ie, dl as G, bW as ee } from "./index-Bnnn4cdG.mjs";
5
- import "./index-CuQ35zWu.mjs";
4
+ import { cY as N, cZ as F, c_ as ae, c$ as Z, d0 as W, d1 as $, d2 as S, bM as ie, aD as I, c5 as R, d3 as b, c6 as q, bR as ce, bK as j, aF as O, am as v, bO as de, cb as H, c8 as le, d4 as _, d5 as C, d6 as ge, d7 as ue, d8 as M, d9 as fe, bS as V, da as D, db as Q, dc as pe, dd as x, de as he, df as we, ap as U, dg as ye, dh as X, cP as ke, di as me, cC as Y, dj as be, dk as Ie, dl as G, bW as ee } from "./index-BOD0JbTK.mjs";
5
+ import "./index-XZFtH_Uh.mjs";
6
6
  const L = async (k, t, e) => {
7
7
  var d, r, n;
8
8
  if (!N(e))
@@ -375,7 +375,7 @@ class ke {
375
375
  }
376
376
  async initUi() {
377
377
  if (typeof window < "u") {
378
- await import("./index-BskY1_ip.mjs");
378
+ await import("./index-CqYIha8G.mjs");
379
379
  const t = document.createElement("wcm-modal");
380
380
  document.body.insertAdjacentElement("beforeend", t), w.setIsUiLoaded(!0);
381
381
  }
@@ -1,4 +1,4 @@
1
- import { ch as J, dv as Z } from "./index-Bnnn4cdG.mjs";
1
+ import { ch as J, dv as Z } from "./index-BOD0JbTK.mjs";
2
2
  const j = "logger/5.8.0";
3
3
  let F = !1, k = !1;
4
4
  const U = { debug: 1, default: 2, info: 2, warning: 3, error: 4, off: 5 };
@@ -1,7 +1,7 @@
1
1
  var T = Object.defineProperty;
2
2
  var l = (i, t, e) => t in i ? T(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
3
  var r = (i, t, e) => l(i, typeof t != "symbol" ? t + "" : t, e);
4
- import { cc as b, bM as p, bL as g, i as y, bO as m, a6 as d, a9 as h, bK as f, bQ as o, bS as u, bU as k, bV as v, bW as C, ab as A } from "./index-Bnnn4cdG.mjs";
4
+ import { cc as b, bM as p, bL as g, i as y, bO as m, a6 as d, a9 as h, bK as f, bQ as o, bS as u, bU as k, bV as v, bW as C, ab as A } from "./index-BOD0JbTK.mjs";
5
5
  class c {
6
6
  constructor(t, e, a, n) {
7
7
  r(this, "network");
@@ -10155,7 +10155,7 @@ const MAINNET_TOKENS = [
10155
10155
  index: 0,
10156
10156
  keys: ["0x13947Bd48b18E53fdAeEe77F3473391aC727C638"]
10157
10157
  }
10158
- }, WORMSCAN = "https://wormholescan.io/#/", CONNECT_VERSION = "2.5.0-beta.15-development", CONNECT_GIT_HASH = "62897b9c992049c23a5d8ff3c03bf1cf5e77421b", CHAIN_ORDER = [
10158
+ }, WORMSCAN = "https://wormholescan.io/#/", CONNECT_VERSION = "2.5.0-beta.16-development", CONNECT_GIT_HASH = "011f24fb63bf02d3cb237887c8adde6c789613e7", CHAIN_ORDER = [
10159
10159
  "Ethereum",
10160
10160
  "Solana",
10161
10161
  "Arbitrum",
@@ -74896,7 +74896,7 @@ async function wormhole(t, e, l) {
74896
74896
  const d = (await loadPlatforms(e)).map((h) => h.Platform);
74897
74897
  return new Wormhole(t, d, l);
74898
74898
  }
74899
- const evm = async () => (await import("./evm-Dc_rWE9Y.mjs")).default, solana$1 = async () => (await import("./solana-5YorGJTB.mjs")).default, aptos$1 = async () => (await import("./aptos-CeQAnpez.mjs").then((t) => t.a)).default, sui = async () => (await import("./sui-9tHCVvtM.mjs")).default;
74899
+ const evm = async () => (await import("./evm-YzP22UIh.mjs")).default, solana$1 = async () => (await import("./solana-CrWCptDL.mjs")).default, aptos$1 = async () => (await import("./aptos-B_0vi8q5.mjs").then((t) => t.a)).default, sui = async () => (await import("./sui-DnkD0Bxo.mjs")).default;
74900
74900
  class SuiUnsignedTransaction {
74901
74901
  constructor(e, l, d, h, u = !1) {
74902
74902
  ye(this, "transaction");
@@ -78386,7 +78386,7 @@ class TokenCache extends TokenMapping {
78386
78386
  const l = await getWormholeContextV2(), d = l.getChain(e.chain), h = await d.getDecimals(e.address), u = await fetchTokenMetadata(e);
78387
78387
  let p = ((I = u == null ? void 0 : u.symbol) == null ? void 0 : I.toUpperCase()) || "", m = (u == null ? void 0 : u.name) || "", y = ((E = u == null ? void 0 : u.image) == null ? void 0 : E.large) || null;
78388
78388
  if (!p) {
78389
- const { getTokenMetadataFromRpc: k } = await import("./tokens-BZf6dpqe.mjs"), N = await k(e);
78389
+ const { getTokenMetadataFromRpc: k } = await import("./tokens-C4Y28hR0.mjs"), N = await k(e);
78390
78390
  N && (console.info("Got metadata from RPC", N), p = N.symbol, m = N.name, y = N.icon);
78391
78391
  }
78392
78392
  let x;
@@ -79188,7 +79188,7 @@ ye(wn, "_platform", _platform$2);
79188
79188
  let EvmPlatform = wn;
79189
79189
  class SolanaChain extends ChainContext {
79190
79190
  async getTokenAccount(e, l) {
79191
- const { getAssociatedTokenAddress: d } = await import("./index-Bt1Gnf-O.mjs"), h = new SolanaAddress(l).unwrap(), u = new SolanaAddress(e).unwrap(), p = await d(h, u);
79191
+ const { getAssociatedTokenAddress: d } = await import("./index-BrjkSw_2.mjs"), h = new SolanaAddress(l).unwrap(), u = new SolanaAddress(e).unwrap(), p = await d(h, u);
79192
79192
  return {
79193
79193
  chain: this.chain,
79194
79194
  address: new SolanaAddress(p.toString())
@@ -81070,24 +81070,24 @@ const walletConnection = {
81070
81070
  if (!u)
81071
81071
  throw new Error("wallet is undefined");
81072
81072
  if (h.context === Context.ETH)
81073
- return await (await import("./evm-DIChhZyr.mjs").then((y) => y.k)).signAndSendTransaction(
81073
+ return await (await import("./evm-BlmFliMr.mjs").then((y) => y.k)).signAndSendTransaction(
81074
81074
  e,
81075
81075
  u,
81076
81076
  t
81077
81077
  );
81078
81078
  if (h.context === Context.SOLANA)
81079
- return await (await import("./solana-DZVSRj8-.mjs")).signAndSendTransaction(
81079
+ return await (await import("./solana-CFnSQELF.mjs")).signAndSendTransaction(
81080
81080
  e,
81081
81081
  u,
81082
81082
  d
81083
81083
  );
81084
81084
  if (h.context === Context.SUI)
81085
- return (await (await import("./sui-CG9oss4-.mjs")).signAndSendTransaction(
81085
+ return (await (await import("./sui-Da5D6kut.mjs")).signAndSendTransaction(
81086
81086
  e,
81087
81087
  u
81088
81088
  )).id;
81089
81089
  if (h.context === Context.APTOS)
81090
- return (await (await import("./aptos-CFJxiJmC.mjs")).signAndSendTransaction(
81090
+ return (await (await import("./aptos-DT2vzzvi.mjs")).signAndSendTransaction(
81091
81091
  e,
81092
81092
  u
81093
81093
  )).id;
@@ -81107,16 +81107,16 @@ const walletConnection = {
81107
81107
  if (t === void 0)
81108
81108
  return [];
81109
81109
  if (t.context === Context.ETH) {
81110
- const e = await import("./evm-DIChhZyr.mjs").then((l) => l.k);
81110
+ const e = await import("./evm-BlmFliMr.mjs").then((l) => l.k);
81111
81111
  return Object.values(mapWallets(e.getWallets(), Context.ETH));
81112
81112
  } else if (t.context === Context.SOLANA) {
81113
- const l = (await import("./solana-DZVSRj8-.mjs")).fetchOptions();
81113
+ const l = (await import("./solana-CFnSQELF.mjs")).fetchOptions();
81114
81114
  return Object.values(mapWallets(l, Context.SOLANA));
81115
81115
  } else if (t.context === Context.SUI) {
81116
- const l = await (await import("./sui-CG9oss4-.mjs")).fetchOptions();
81116
+ const l = await (await import("./sui-Da5D6kut.mjs")).fetchOptions();
81117
81117
  return Object.values(mapWallets(l, Context.SUI));
81118
81118
  } else if (t.context === Context.APTOS) {
81119
- const l = (await import("./aptos-CFJxiJmC.mjs")).fetchOptions();
81119
+ const l = (await import("./aptos-DT2vzzvi.mjs")).fetchOptions();
81120
81120
  return Object.values(mapWallets(l, Context.APTOS));
81121
81121
  }
81122
81122
  return [];
@@ -136087,9 +136087,7 @@ const useStyles$h = makeStyles()((t) => ({
136087
136087
  return z && isSameToken(z, U) ? 2 : U.isTokenBridgeWrappedToken ? 0 : 1;
136088
136088
  }, I = useMemo(() => {
136089
136089
  if (!t.tokenList) return [];
136090
- const U = t.tokenList.filter(
136091
- (G) => !isFrankensteinToken(G, t.selectedChainConfig.sdkName)
136092
- );
136090
+ let U = t.tokenList;
136093
136091
  if (m) {
136094
136092
  let G = [];
136095
136093
  const Y = config$1.tokens.get(
@@ -136180,9 +136178,9 @@ const useStyles$h = makeStyles()((t) => ({
136180
136178
  return !!([U.symbol, U.name].some(
136181
136179
  (Y) => {
136182
136180
  var Q, re;
136183
- return (re = (Q = Y == null ? void 0 : Y.toLowerCase()) == null ? void 0 : Q.includes) == null ? void 0 : re.call(Q, W);
136181
+ return (re = (Q = Y == null ? void 0 : Y.toLowerCase()) == null ? void 0 : Q.startsWith) == null ? void 0 : re.call(Q, W);
136184
136182
  }
136185
- ) || U.address.toString().toLowerCase().includes(W) || U.tokenBridgeOriginalTokenId && U.tokenBridgeOriginalTokenId.address.toString().toLowerCase().includes(W));
136183
+ ) || U.address.toString().toLowerCase() === W || U.tokenBridgeOriginalTokenId && U.tokenBridgeOriginalTokenId.address.toString().toLowerCase().includes(W));
136186
136184
  },
136187
136185
  renderFn: (U) => {
136188
136186
  var Y, Q, re;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-X1wTeN-B.js");class o extends Error{constructor(r){super(r)}}class s extends o{constructor(){super(...arguments),this.name="TokenOwnerOffCurveError"}}const n=e.struct([e.u32$1("mintAuthorityOption"),e.publicKey("mintAuthority"),e.u64("supply"),e.u8("decimals"),e.bool("isInitialized"),e.u32$1("freezeAuthorityOption"),e.publicKey("freezeAuthority")]);n.span;async function c(t,r,u=!1,i=e.TOKEN_PROGRAM_ID,O=e.ASSOCIATED_TOKEN_PROGRAM_ID){if(!u&&!e.PublicKey.isOnCurve(r.toBuffer()))throw new s;const[A]=await e.PublicKey.findProgramAddress([r.toBuffer(),i.toBuffer(),t.toBuffer()],O);return A}exports.ASSOCIATED_TOKEN_PROGRAM_ID=e.ASSOCIATED_TOKEN_PROGRAM_ID;exports.TOKEN_2022_PROGRAM_ID=e.TOKEN_2022_PROGRAM_ID;exports.TOKEN_PROGRAM_ID=e.TOKEN_PROGRAM_ID;exports.MintLayout=n;exports.TokenError=o;exports.TokenOwnerOffCurveError=s;exports.getAssociatedTokenAddress=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DoE4VQhB.js");class o extends Error{constructor(r){super(r)}}class s extends o{constructor(){super(...arguments),this.name="TokenOwnerOffCurveError"}}const n=e.struct([e.u32$1("mintAuthorityOption"),e.publicKey("mintAuthority"),e.u64("supply"),e.u8("decimals"),e.bool("isInitialized"),e.u32$1("freezeAuthorityOption"),e.publicKey("freezeAuthority")]);n.span;async function c(t,r,u=!1,i=e.TOKEN_PROGRAM_ID,O=e.ASSOCIATED_TOKEN_PROGRAM_ID){if(!u&&!e.PublicKey.isOnCurve(r.toBuffer()))throw new s;const[A]=await e.PublicKey.findProgramAddress([r.toBuffer(),i.toBuffer(),t.toBuffer()],O);return A}exports.ASSOCIATED_TOKEN_PROGRAM_ID=e.ASSOCIATED_TOKEN_PROGRAM_ID;exports.TOKEN_2022_PROGRAM_ID=e.TOKEN_2022_PROGRAM_ID;exports.TOKEN_PROGRAM_ID=e.TOKEN_PROGRAM_ID;exports.MintLayout=n;exports.TokenError=o;exports.TokenOwnerOffCurveError=s;exports.getAssociatedTokenAddress=c;
@@ -1,7 +1,7 @@
1
1
  var Pt = Object.defineProperty;
2
2
  var _t = (e, t, r) => t in e ? Pt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var f = (e, t, r) => _t(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { P as c, d as l, bC as A, T as le, bG as z, bF as U, bH as G, bE as S, bD as V, cv as Ge, cw as He, cx as Wt, cy as It, cz as Ut, cA as Nt, cq as O, cd as E, bK as y, cB as T, cC as Ft, cD as ye, c6 as dt, cE as xt, ce as lt, cf as zt, cF as Ot, cG as Q, cH as Lt, ct as H, cu as Z, cI as Dt, cr as qt, cJ as Kt, cK as Vt, cL as Se, cM as Gt, ch as v, cs as Ht, ad as oe, ae as k, c5 as Ce, bR as Zt, am as $, cb as Be, cN as Yt, cO as Qt, K as se, a$ as L, cP as Xt, ci as ft, bW as mt, af as gt } from "./index-Bnnn4cdG.mjs";
4
+ import { P as c, d as l, bC as A, T as le, bG as z, bF as U, bH as G, bE as S, bD as V, cv as Ge, cw as He, cx as Wt, cy as It, cz as Ut, cA as Nt, cq as O, cd as E, bK as y, cB as T, cC as Ft, cD as ye, c6 as dt, cE as xt, ce as lt, cf as zt, cF as Ot, cG as Q, cH as Lt, ct as H, cu as Z, cI as Dt, cr as qt, cJ as Kt, cK as Vt, cL as Se, cM as Gt, ch as v, cs as Ht, ad as oe, ae as k, c5 as Ce, bR as Zt, am as $, cb as Be, cN as Yt, cO as Qt, K as se, a$ as L, cP as Xt, ci as ft, bW as mt, af as gt } from "./index-BOD0JbTK.mjs";
5
5
  const M = new c("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
6
6
  new c("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
7
7
  const Ae = new c("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"), D = new c("So11111111111111111111111111111111111111112");
@@ -1,8 +1,8 @@
1
- import { bv as Do, dm as uy, d as De, dn as Zy, aI as Pv, dp as eg, dq as tg, bd as ng } from "./index-Bnnn4cdG.mjs";
2
- import { e as iy, d as ag } from "./base64-CHhsJk6A.mjs";
1
+ import { bv as Do, dm as uy, d as De, dn as Zy, aI as Pv, dp as eg, dq as tg, bd as ng } from "./index-BOD0JbTK.mjs";
2
+ import { e as iy, d as ag } from "./base64-COK36zSs.mjs";
3
3
  import * as Wf from "react";
4
4
  import d1, { createContext as lg, useState as is, useEffect as Ky, useCallback as ug, useContext as ig } from "react";
5
- import { L as ot, B as mn, d as i2, a as o0, h as U2, b as og, c as w9, g as od, e as Jy, k as cd, f as wr, i as cg, j as Tr, D as vs } from "./index-BcZ5yPJ4.mjs";
5
+ import { L as ot, B as mn, d as i2, a as o0, h as U2, b as og, c as w9, g as od, e as Jy, k as cd, f as wr, i as cg, j as Tr, D as vs } from "./index-B9ceWZWn.mjs";
6
6
  function rd(c, i) {
7
7
  (i == null || i > c.length) && (i = c.length);
8
8
  for (var d = 0, f = new Array(i); d < i; d++) f[d] = c[d];
@@ -1,7 +1,7 @@
1
1
  var K = Object.defineProperty;
2
2
  var L = (i, e, b) => e in i ? K(i, e, { enumerable: !0, configurable: !0, writable: !0, value: b }) : i[e] = b;
3
3
  var d = (i, e, b) => L(i, typeof e != "symbol" ? e + "" : e, b);
4
- import { bM as D, bL as U, a6 as l, c5 as W, bK as m, bR as j, c6 as J, a9 as c, am as k, c7 as Q, c8 as Z, bS as A, c9 as E, ca as h, bQ as s, cb as _, bU as P, bV as N, c4 as q, bJ as O, i as H, bW as V, ab as $ } from "./index-Bnnn4cdG.mjs";
4
+ import { bM as D, bL as U, a6 as l, c5 as W, bK as m, bR as j, c6 as J, a9 as c, am as k, c7 as Q, c8 as Z, bS as A, c9 as E, ca as h, bQ as s, cb as _, bU as P, bV as N, c4 as q, bJ as O, i as H, bW as V, ab as $ } from "./index-BOD0JbTK.mjs";
5
5
  const z = {
6
6
  Mainnet: {
7
7
  Acala: "0x0000000000000000000000000000000000000000",
@@ -1,5 +1,5 @@
1
- import { bA as f, bB as c, P as s, bC as O, bD as t, bE as o, bF as A, bG as b, bH as d } from "./index-Bnnn4cdG.mjs";
2
- import { bI as h } from "./index-Bnnn4cdG.mjs";
1
+ import { bA as f, bB as c, P as s, bC as O, bD as t, bE as o, bF as A, bG as b, bH as d } from "./index-BOD0JbTK.mjs";
2
+ import { bI as h } from "./index-BOD0JbTK.mjs";
3
3
  class p extends Error {
4
4
  constructor(r) {
5
5
  super(r);
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var y=(i,e,t)=>e in i?l(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var o=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index-X1wTeN-B.js"),g=require("./unsignedTransaction-C1YeEl4G.js"),f=require("./aptos-BQFmduMd.js"),w=[{name:"tokenBridgeAddress",...s.universalAddressItem},{name:"chain",...s.chainItem()},{name:"domainSeparator",binary:"bytes",custom:s.bytes.encode(s.APTOS_SEPARATOR),omit:!0},{name:"tokenId",...s.universalAddressItem},{name:"domainSeparator",binary:"bytes",custom:new Uint8Array([255]),omit:!0}],T=i=>s.serialize$1(w,i);class d{constructor(e,t,n,r){o(this,"network");o(this,"chain");o(this,"connection");o(this,"contracts");o(this,"chainId");o(this,"tokenBridgeAddress");this.network=e,this.chain=t,this.connection=n,this.contracts=r,this.chainId=s.toChainId(t);const a=r.tokenBridge;if(!a)throw new Error(`TokenBridge contract Address for chain ${t} not found`);this.tokenBridgeAddress=a}static async fromRpc(e,t){const[n,r]=await f.AptosPlatform.chainFromRpc(e),a=t[r];if(a.network!==n)throw new Error("Network mismatch "+a.network+" !== "+n);return new d(n,r,e,a.contracts)}async isWrappedAsset(e){try{return await this.getOriginalAsset(e),!0}catch{return!1}}async getOriginalAsset(e){const t=e.toString().split(s.APTOS_SEPARATOR),n=await this.connection.getAccountResource({accountAddress:t[0],resourceType:`${this.tokenBridgeAddress}::state::OriginInfo`});if(!n)throw s.ErrNotWrapped(e.toString());const r=s.toChain(parseInt(n.token_chain.number)),a=new s.UniversalAddress(n.token_address.external_address);return{chain:r,address:a}}async getTokenUniversalAddress(e){return new s.UniversalAddress(s.hex.encode(s.sha3_256(e.toString()),!0))}async getTokenNativeAddress(e,t){const n=e===this.chain?await this.getTypeFromExternalAddress(t.toString()):await this.getAssetFullyQualifiedType({chain:e,address:t});if(!n)throw new Error("Invalid asset address.");return new s.AptosAddress(n)}async hasWrappedAsset(e){try{return await this.getWrappedAsset(e),!0}catch{}return!1}async getWrappedAsset(e){if(s.isNative(e.address))throw new Error("native asset cannot be a wrapped asset");const t=await this.getAssetFullyQualifiedType(e);if(!t)throw new Error("Invalid asset address.");return await this.connection.getAccountResource({accountAddress:s.coalesceModuleAddress(t),resourceType:`${this.tokenBridgeAddress}::state::OriginInfo`}),s.toNative(this.chain,t)}async isTransferCompleted(e){const n=(await this.connection.getAccountResource({accountAddress:this.tokenBridgeAddress,resourceType:`${this.tokenBridgeAddress}::state::State`})).consumed_vaas.elems.handle;try{return await this.connection.getTableItem({handle:n,data:{key_type:"vector<u8>",value_type:"u8",key:`0x${s.dist.Buffer.from(s.keccak_256(e.hash)).toString("hex")}`}}),!0}catch{return!1}}async getWrappedNative(){return s.toNative(this.chain,s.APTOS_COIN)}async*createAttestation(e,t){const n={chain:this.chain,address:new s.AptosAddress(e)},r=await this.getAssetFullyQualifiedType(n);if(!r)throw new Error("Invalid asset address.");yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::attest_token::attest_token_entry`,typeArguments:[r],functionArguments:[]},"Aptos.AttestToken")}async*submitAttestation(e,t){yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::wrapped::create_wrapped_coin_type`,typeArguments:[],functionArguments:[s.serialize(e)]},"Aptos.CreateWrappedCoinType");const n=await this.getAssetFullyQualifiedType(e.payload.token);if(!n)throw new Error("Invalid asset address.");yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::wrapped::create_wrapped_coin`,typeArguments:[n],functionArguments:[s.serialize(e)]},"Aptos.CreateWrappedCoin")}async*transfer(e,t,n,r,a){const p=0n,c=0n,h=s.isNative(n)?s.APTOS_COIN:n.toString(),u=t.address.toUniversalAddress().toUint8Array(),A=s.toChainId(t.chain);a?yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::transfer_tokens::transfer_tokens_with_payload_entry`,typeArguments:[h],functionArguments:[r,A,u,c,a]},"Aptos.TransferTokensWithPayload"):yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::transfer_tokens::transfer_tokens_entry`,typeArguments:[h],functionArguments:[r,A,u,p,c]},"Aptos.TransferTokens")}async*redeem(e,t,n=!0){const r=t.payload.token.chain===this.chain?await this.getTypeFromExternalAddress(t.payload.token.address.toString()):await this.getAssetFullyQualifiedType(t.payload.token);if(!r)throw new Error("Invalid asset address.");yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::complete_transfer::submit_vaa_and_register_entry`,typeArguments:[r],functionArguments:[s.serialize(t)]},"Aptos.CompleteTransfer")}async getAssetFullyQualifiedType(e){return e.chain===this.chain?s.isValidAptosType(e.address.toString())?e.address.toString():null:`${d.getForeignAssetAddress(this.chain,this.tokenBridgeAddress,e)}::coin::T`}async getTypeFromExternalAddress(e){try{const t=await this.connection.getAccountResource({accountAddress:this.tokenBridgeAddress,resourceType:`${this.tokenBridgeAddress}::state::State`}),{handle:n}=t.native_infos,r=await this.connection.getTableItem({handle:n,data:{key_type:`${this.tokenBridgeAddress}::token_hash::TokenHash`,value_type:"0x1::type_info::TypeInfo",key:{hash:e}}});return r?[r.account_address,String.fromCharCode(...s.hex.decode(r.module_name)),String.fromCharCode(...s.hex.decode(r.struct_name))].join(s.APTOS_SEPARATOR):null}catch{return null}}static getForeignAssetAddress(e,t,n){if(s.isNative(n.address))throw new Error("Invalid token address");const r=T({chain:n.chain,tokenBridgeAddress:new s.AptosAddress(t).toUniversalAddress(),tokenId:n.address.toUniversalAddress()});return s.hex.encode(s.sha3_256(r),!0)}createUnsignedTx(e,t,n=!1){return new g.AptosUnsignedTransaction(e,this.network,this.chain,t,n)}}s.registerProtocol("Aptos","TokenBridge",d);exports.AptosTokenBridge=d;
1
+ "use strict";var l=Object.defineProperty;var y=(i,e,t)=>e in i?l(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var o=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index-DoE4VQhB.js"),g=require("./unsignedTransaction-C1YeEl4G.js"),f=require("./aptos-CZeHb71O.js"),w=[{name:"tokenBridgeAddress",...s.universalAddressItem},{name:"chain",...s.chainItem()},{name:"domainSeparator",binary:"bytes",custom:s.bytes.encode(s.APTOS_SEPARATOR),omit:!0},{name:"tokenId",...s.universalAddressItem},{name:"domainSeparator",binary:"bytes",custom:new Uint8Array([255]),omit:!0}],T=i=>s.serialize$1(w,i);class d{constructor(e,t,n,r){o(this,"network");o(this,"chain");o(this,"connection");o(this,"contracts");o(this,"chainId");o(this,"tokenBridgeAddress");this.network=e,this.chain=t,this.connection=n,this.contracts=r,this.chainId=s.toChainId(t);const a=r.tokenBridge;if(!a)throw new Error(`TokenBridge contract Address for chain ${t} not found`);this.tokenBridgeAddress=a}static async fromRpc(e,t){const[n,r]=await f.AptosPlatform.chainFromRpc(e),a=t[r];if(a.network!==n)throw new Error("Network mismatch "+a.network+" !== "+n);return new d(n,r,e,a.contracts)}async isWrappedAsset(e){try{return await this.getOriginalAsset(e),!0}catch{return!1}}async getOriginalAsset(e){const t=e.toString().split(s.APTOS_SEPARATOR),n=await this.connection.getAccountResource({accountAddress:t[0],resourceType:`${this.tokenBridgeAddress}::state::OriginInfo`});if(!n)throw s.ErrNotWrapped(e.toString());const r=s.toChain(parseInt(n.token_chain.number)),a=new s.UniversalAddress(n.token_address.external_address);return{chain:r,address:a}}async getTokenUniversalAddress(e){return new s.UniversalAddress(s.hex.encode(s.sha3_256(e.toString()),!0))}async getTokenNativeAddress(e,t){const n=e===this.chain?await this.getTypeFromExternalAddress(t.toString()):await this.getAssetFullyQualifiedType({chain:e,address:t});if(!n)throw new Error("Invalid asset address.");return new s.AptosAddress(n)}async hasWrappedAsset(e){try{return await this.getWrappedAsset(e),!0}catch{}return!1}async getWrappedAsset(e){if(s.isNative(e.address))throw new Error("native asset cannot be a wrapped asset");const t=await this.getAssetFullyQualifiedType(e);if(!t)throw new Error("Invalid asset address.");return await this.connection.getAccountResource({accountAddress:s.coalesceModuleAddress(t),resourceType:`${this.tokenBridgeAddress}::state::OriginInfo`}),s.toNative(this.chain,t)}async isTransferCompleted(e){const n=(await this.connection.getAccountResource({accountAddress:this.tokenBridgeAddress,resourceType:`${this.tokenBridgeAddress}::state::State`})).consumed_vaas.elems.handle;try{return await this.connection.getTableItem({handle:n,data:{key_type:"vector<u8>",value_type:"u8",key:`0x${s.dist.Buffer.from(s.keccak_256(e.hash)).toString("hex")}`}}),!0}catch{return!1}}async getWrappedNative(){return s.toNative(this.chain,s.APTOS_COIN)}async*createAttestation(e,t){const n={chain:this.chain,address:new s.AptosAddress(e)},r=await this.getAssetFullyQualifiedType(n);if(!r)throw new Error("Invalid asset address.");yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::attest_token::attest_token_entry`,typeArguments:[r],functionArguments:[]},"Aptos.AttestToken")}async*submitAttestation(e,t){yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::wrapped::create_wrapped_coin_type`,typeArguments:[],functionArguments:[s.serialize(e)]},"Aptos.CreateWrappedCoinType");const n=await this.getAssetFullyQualifiedType(e.payload.token);if(!n)throw new Error("Invalid asset address.");yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::wrapped::create_wrapped_coin`,typeArguments:[n],functionArguments:[s.serialize(e)]},"Aptos.CreateWrappedCoin")}async*transfer(e,t,n,r,a){const p=0n,c=0n,h=s.isNative(n)?s.APTOS_COIN:n.toString(),u=t.address.toUniversalAddress().toUint8Array(),A=s.toChainId(t.chain);a?yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::transfer_tokens::transfer_tokens_with_payload_entry`,typeArguments:[h],functionArguments:[r,A,u,c,a]},"Aptos.TransferTokensWithPayload"):yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::transfer_tokens::transfer_tokens_entry`,typeArguments:[h],functionArguments:[r,A,u,p,c]},"Aptos.TransferTokens")}async*redeem(e,t,n=!0){const r=t.payload.token.chain===this.chain?await this.getTypeFromExternalAddress(t.payload.token.address.toString()):await this.getAssetFullyQualifiedType(t.payload.token);if(!r)throw new Error("Invalid asset address.");yield this.createUnsignedTx({function:`${this.tokenBridgeAddress}::complete_transfer::submit_vaa_and_register_entry`,typeArguments:[r],functionArguments:[s.serialize(t)]},"Aptos.CompleteTransfer")}async getAssetFullyQualifiedType(e){return e.chain===this.chain?s.isValidAptosType(e.address.toString())?e.address.toString():null:`${d.getForeignAssetAddress(this.chain,this.tokenBridgeAddress,e)}::coin::T`}async getTypeFromExternalAddress(e){try{const t=await this.connection.getAccountResource({accountAddress:this.tokenBridgeAddress,resourceType:`${this.tokenBridgeAddress}::state::State`}),{handle:n}=t.native_infos,r=await this.connection.getTableItem({handle:n,data:{key_type:`${this.tokenBridgeAddress}::token_hash::TokenHash`,value_type:"0x1::type_info::TypeInfo",key:{hash:e}}});return r?[r.account_address,String.fromCharCode(...s.hex.decode(r.module_name)),String.fromCharCode(...s.hex.decode(r.struct_name))].join(s.APTOS_SEPARATOR):null}catch{return null}}static getForeignAssetAddress(e,t,n){if(s.isNative(n.address))throw new Error("Invalid token address");const r=T({chain:n.chain,tokenBridgeAddress:new s.AptosAddress(t).toUniversalAddress(),tokenId:n.address.toUniversalAddress()});return s.hex.encode(s.sha3_256(r),!0)}createUnsignedTx(e,t,n=!1){return new g.AptosUnsignedTransaction(e,this.network,this.chain,t,n)}}s.registerProtocol("Aptos","TokenBridge",d);exports.AptosTokenBridge=d;
@@ -1 +1 @@
1
- "use strict";var h=Object.defineProperty;var w=(o,t,e)=>t in o?h(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var s=(o,t,e)=>w(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index-X1wTeN-B.js");class c{constructor(t,e,a,r){s(this,"network");s(this,"chain");s(this,"provider");s(this,"contracts");s(this,"chainId");s(this,"core");s(this,"gatewayAddress");s(this,"gateway");s(this,"tbtcTokenAddr");if(this.network=t,this.chain=e,this.provider=a,this.contracts=r,this.network!=="Mainnet")throw new Error("TBTC is only supported on Mainnet");if(!this.contracts.tbtc)throw new Error("TBTC contract address is required");const i=n.TBTCBridge.getNativeTbtcToken(this.chain);if(!i)throw new Error("Native tbtc token not found");this.chainId=n.networkChainToNativeChainId.get(t,e),this.core=new n.EvmWormholeCore(t,e,a,r),this.gatewayAddress=this.contracts.tbtc,this.gateway=new n.Contract(this.gatewayAddress,["function sendTbtc(uint256 amount, uint16 recipientChain, bytes32 recipient, uint256 arbiterFee, uint32 nonce) payable returns (uint64)","function receiveTbtc(bytes calldata encodedVm)"],a),this.tbtcTokenAddr=n.canonicalAddress(i)}static async fromRpc(t,e){const[a,r]=await n.EvmPlatform.chainFromRpc(t),i=e[r];if(i.network!==a)throw new Error(`Network mismatch: ${i.network} != ${a}`);return new c(a,r,t,i.contracts)}async*transfer(t,e,a){const r=new n.EvmAddress(t).toString(),i=await this.gateway.sendTbtc.populateTransaction(a,n.toChainId(e.chain),e.address.toUniversalAddress().toUint8Array(),0n,0n);i.value=await this.core.getMessageFee(),yield*this.approve(r,a,this.gatewayAddress),yield this.createUnsignedTransaction(n.addFrom(i,r),"TBTCBridge.Send")}async*redeem(t,e){if(e.payloadName!=="GatewayTransfer")throw new Error("Invalid VAA payload");const a=new n.EvmAddress(t).toString(),r=await this.gateway.receiveTbtc.populateTransaction(n.serialize(e));yield this.createUnsignedTransaction(n.addFrom(r,a),"TBTCBridge.Redeem")}async*approve(t,e,a){const r=n.EvmPlatform.getTokenImplementation(this.provider,this.tbtcTokenAddr);if(await r.allowance(t,a)<e){const d=await r.approve.populateTransaction(a,e);yield this.createUnsignedTransaction(n.addFrom(d,t),"TBTC.Approve")}}createUnsignedTransaction(t,e){return new n.EvmUnsignedTransaction(n.addChainId(t,this.chainId),this.network,this.chain,e,!1)}}n.registerProtocol(n._platform,"TBTCBridge",c);exports.EvmTBTCBridge=c;
1
+ "use strict";var h=Object.defineProperty;var w=(o,t,e)=>t in o?h(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var s=(o,t,e)=>w(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index-DoE4VQhB.js");class c{constructor(t,e,a,r){s(this,"network");s(this,"chain");s(this,"provider");s(this,"contracts");s(this,"chainId");s(this,"core");s(this,"gatewayAddress");s(this,"gateway");s(this,"tbtcTokenAddr");if(this.network=t,this.chain=e,this.provider=a,this.contracts=r,this.network!=="Mainnet")throw new Error("TBTC is only supported on Mainnet");if(!this.contracts.tbtc)throw new Error("TBTC contract address is required");const i=n.TBTCBridge.getNativeTbtcToken(this.chain);if(!i)throw new Error("Native tbtc token not found");this.chainId=n.networkChainToNativeChainId.get(t,e),this.core=new n.EvmWormholeCore(t,e,a,r),this.gatewayAddress=this.contracts.tbtc,this.gateway=new n.Contract(this.gatewayAddress,["function sendTbtc(uint256 amount, uint16 recipientChain, bytes32 recipient, uint256 arbiterFee, uint32 nonce) payable returns (uint64)","function receiveTbtc(bytes calldata encodedVm)"],a),this.tbtcTokenAddr=n.canonicalAddress(i)}static async fromRpc(t,e){const[a,r]=await n.EvmPlatform.chainFromRpc(t),i=e[r];if(i.network!==a)throw new Error(`Network mismatch: ${i.network} != ${a}`);return new c(a,r,t,i.contracts)}async*transfer(t,e,a){const r=new n.EvmAddress(t).toString(),i=await this.gateway.sendTbtc.populateTransaction(a,n.toChainId(e.chain),e.address.toUniversalAddress().toUint8Array(),0n,0n);i.value=await this.core.getMessageFee(),yield*this.approve(r,a,this.gatewayAddress),yield this.createUnsignedTransaction(n.addFrom(i,r),"TBTCBridge.Send")}async*redeem(t,e){if(e.payloadName!=="GatewayTransfer")throw new Error("Invalid VAA payload");const a=new n.EvmAddress(t).toString(),r=await this.gateway.receiveTbtc.populateTransaction(n.serialize(e));yield this.createUnsignedTransaction(n.addFrom(r,a),"TBTCBridge.Redeem")}async*approve(t,e,a){const r=n.EvmPlatform.getTokenImplementation(this.provider,this.tbtcTokenAddr);if(await r.allowance(t,a)<e){const d=await r.approve.populateTransaction(a,e);yield this.createUnsignedTransaction(n.addFrom(d,t),"TBTC.Approve")}}createUnsignedTransaction(t,e){return new n.EvmUnsignedTransaction(n.addChainId(t,this.chainId),this.network,this.chain,e,!1)}}n.registerProtocol(n._platform,"TBTCBridge",c);exports.EvmTBTCBridge=c;
@@ -1,8 +1,8 @@
1
1
  var Z = Object.defineProperty;
2
2
  var G = (n, f, e) => f in n ? Z(n, f, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[f] = e;
3
3
  var d = (n, f, e) => G(n, typeof f != "symbol" ? f + "" : f, e);
4
- import "./index-PZieeYNW.mjs";
5
- import { D as y, k as f0, y as L, j as p, v as e0, I as a0, bX as t0, bY as C, a2 as b0, bZ as n0, b_ as d0, bM as H, b$ as D, a6 as v, a9 as I, c0 as U, ap as F, bQ as u, c1 as q, x as c0, c2 as N, bU as j, bV as V, bL as s0, bK as i0, c3 as r0, c4 as S, bJ as $, i as E, bW as J, ab as K } from "./index-Bnnn4cdG.mjs";
4
+ import "./index-BW0PVtoo.mjs";
5
+ import { D as y, k as f0, y as L, j as p, v as e0, I as a0, bX as t0, bY as C, a2 as b0, bZ as n0, b_ as d0, bM as H, b$ as D, a6 as v, a9 as I, c0 as U, ap as F, bQ as u, c1 as q, x as c0, c2 as N, bU as j, bV as V, bL as s0, bK as i0, c3 as r0, c4 as S, bJ as $, i as E, bW as J, ab as K } from "./index-BOD0JbTK.mjs";
6
6
  const p0 = new RegExp("^bytes([0-9]+)$"), y0 = new RegExp("^(u?int)([0-9]*)$"), o0 = new RegExp("^(.*)\\[([0-9]*)\\]$");
7
7
  function Q(n, f, e) {
8
8
  switch (n) {
@@ -1 +1 @@
1
- "use strict";var $=Object.defineProperty;var U=(k,r,t)=>r in k?$(k,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):k[r]=t;var w=(k,r,t)=>U(k,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-X1wTeN-B.js");require("./index-Bu697BJP.js");const B=async(k,r,t)=>{var l,n,o;if(!e.isValidSuiType(t))throw new Error(`Invalid Sui type: ${t}`);const c=await e.getObjectFields(k,r);if(!c)throw new Error(`Unable to fetch object fields from token bridge state. Object ID: ${r}`);const i=(n=(l=c.token_registry.fields)==null?void 0:l.id)==null?void 0:n.id;if(!i)throw new Error("Unable to fetch token registry object ID");const a=e.getPackageIdFromType((o=c.token_registry)==null?void 0:o.type);if(!a)throw new Error("Unable to fetch token registry package ID");return k.getDynamicFieldObject({parentId:i,name:{type:`${a}::token_registry::Key<${t}>`,value:{dummy_field:!1}}})},_=async(k,r,t,c)=>{var s,f,p,y;const i=await e.getObjectFields(k,r);if(!i)throw new Error("Unable to fetch object fields from token bridge state");const a=(f=(s=i.token_registry)==null?void 0:s.fields)==null?void 0:f.coin_types,l=(y=(p=a==null?void 0:a.fields)==null?void 0:p.id)==null?void 0:y.id;if(!l)throw new Error("Unable to fetch coin types");const n=e.getTableKeyType(a==null?void 0:a.type);if(!n)throw new Error("Unable to get key type");const o=await k.getDynamicFieldObject({parentId:l,name:{type:n,value:{addr:[...t],chain:c}}});if(o.error){if(o.error.code==="dynamicFieldNotFound")return null;throw new Error(`Unexpected getDynamicFieldObject response ${o.error}`)}const g=e.getFieldsFromObjectResponse(o);if(!g)return null;if(!e.isMoveStructObject(g))throw new Error("What?");return"value"in g?e.trimSuiType(g.value):null};class S{constructor(r,t,c,i){w(this,"network");w(this,"chain");w(this,"provider");w(this,"contracts");w(this,"coreBridgeObjectId");w(this,"tokenBridgeObjectId");w(this,"chainId");this.network=r,this.chain=t,this.provider=c,this.contracts=i,this.chainId=e.networkChainToNativeChainId.get(r,t);const a=this.contracts.tokenBridge;if(!a)throw new Error(`Wormhole Token Bridge contract for domain ${t} not found`);const l=this.contracts.coreBridge;if(!l)throw new Error(`Wormhole Token Bridge contract for domain ${t} not found`);this.tokenBridgeObjectId=a,this.coreBridgeObjectId=l}static async fromRpc(r,t){const[c,i]=await e.SuiPlatform.chainFromRpc(r),a=t[i];if(a.network!==c)throw new Error(`Network mismatch: ${a.network} != ${c}`);return new S(c,i,r,a.contracts)}async isWrappedAsset(r){try{return await this.getOriginalAsset(r),!0}catch{return!1}}async getOriginalAsset(r){let t=r.getCoinType();if(!e.isValidSuiType(t))throw new Error(`Invalid Sui type: ${t}`);const c=await B(this.provider,this.tokenBridgeObjectId,t),i=e.getFieldsFromObjectResponse(c);if(!i)throw e.ErrNotWrapped(t);if(!e.isMoveStructObject(i))throw new Error("Expected fields to be a MoveStruct");if(!("value"in i))throw new Error("Expected a `value` key in fields of MoveStruct");const a=i.value;if(!e.isMoveStructStruct(a))throw new Error("Expected fields to be a MoveStruct");const l=e.trimSuiType(a.type);if(t=e.trimSuiType(t),l.includes(`wrapped_asset::WrappedAsset<${t}>`)){const n=a.fields.info;if(!e.isMoveStructStruct(n))throw new Error("Expected fields to be a MoveStruct");const o=n.fields.token_address;if(!e.isMoveStructStruct(o))throw new Error("Expected fields to be a MoveStruct");if(!e.isMoveStructObject(o.fields))throw new Error("Expected address data to be a MoveObject");if(!("value"in o.fields))throw new Error("Expected a `value` key in fields of MoveStruct");const g=o.fields.value;if(!e.isMoveStructStruct(g))throw new Error("Expected fields to be a MoveStruct");const s=new Uint8Array(g.fields.data);return{chain:e.toChain(Number(n.fields.token_chain)),address:new e.UniversalAddress(s)}}throw e.ErrNotWrapped(t)}async getTokenUniversalAddress(r){let t=r.getCoinType();if(!e.isValidSuiType(t))throw new Error(`Invalid Sui type: ${t}`);const c=await B(this.provider,this.tokenBridgeObjectId,t),i=e.getFieldsFromObjectResponse(c);if(!i)throw new Error(`Token of type ${t} has not been registered with the token bridge. Has it been attested?`);if(!e.isMoveStructObject(i))throw new Error("Expected fields to be a MoveStruct");if(!("value"in i))throw new Error("Expected a `value` key in fields of MoveStruct");const a=i.value;if(!e.isMoveStructStruct(a))throw new Error("Expected fields to be a MoveStruct");const l=e.trimSuiType(a.type);if(t=e.trimSuiType(t),l.includes(`native_asset::NativeAsset<${t}>`)){const n=a.fields.token_address;if(!e.isMoveStructStruct(n))throw new Error("Expected fields to be a MoveStruct");if(!("value"in n.fields))throw new Error("Expected a `value` key in fields of MoveStruct");const o=n.fields.value;if(!e.isMoveStructStruct(o))throw new Error("Expected fields to be a MoveStruct");const g=new Uint8Array(o.fields.data);return new e.UniversalAddress(g)}throw new Error(`Token of type ${t} is not a native asset`)}async getTokenNativeAddress(r,t){const c=await _(this.provider,this.tokenBridgeObjectId,t.toUint8Array(),e.toChainId(r));if(!c)throw new Error(`Token ${t.toString()} not found in token registry`);return new e.SuiAddress(c)}async hasWrappedAsset(r){try{return await this.getWrappedAsset(r),!0}catch{}return!1}async getWrappedAsset(r){if(e.isNative(r.address))throw new Error("Token Address required, 'native' literal not supported");const t=await _(this.provider,this.tokenBridgeObjectId,r.address.toUniversalAddress().toUint8Array(),e.toChainId(r.chain));if(!t)throw e.ErrNotWrapped(e.canonicalAddress(r));return e.toNative(this.chain,t)}async isTransferCompleted(r){var n,o,g,s,f,p,y,m;const t=await e.getObjectFields(this.provider,this.tokenBridgeObjectId);if(!t)throw new Error("Unable to fetch object fields from token bridge state");const c=(o=(n=t.consumed_vaas)==null?void 0:n.fields)==null?void 0:o.hashes,i=e.getTableKeyType((s=(g=c==null?void 0:c.fields)==null?void 0:g.items)==null?void 0:s.type);if(!i)throw new Error("Unable to get key type");const a=(m=(y=(p=(f=c==null?void 0:c.fields)==null?void 0:f.items)==null?void 0:p.fields)==null?void 0:y.id)==null?void 0:m.id;if(!a)throw new Error("Unable to fetch consumed VAAs table");const l=await this.provider.getDynamicFieldObject({parentId:a,name:{type:i,value:{data:[...e.keccak_256(r.hash)]}}});if(!l.error)return!0;if(l.error.code==="dynamicFieldNotFound")return!1;throw new Error(`Unexpected getDynamicFieldObject response ${l.error}`)}async*createAttestation(r){const t=0n,i=r.toString(),a=await this.provider.getCoinMetadata({coinType:i});if(a===null||a.id===null)throw new Error(`Coin metadata ID for type ${i} not found`);const[l,n]=await this.getPackageIds(),o=new e.Transaction$2,[g]=o.splitCoins(o.gas,[o.pure.u64(t)]),[s]=o.moveCall({target:`${n}::attest_token::attest_token`,arguments:[o.object(this.tokenBridgeObjectId),o.object(a.id),o.pure.u32(0)],typeArguments:[i]});o.moveCall({target:`${l}::publish_message::publish_message`,arguments:[o.object(this.coreBridgeObjectId),g,s,o.object(e.SUI_CLOCK_OBJECT_ID)]}),yield this.createUnsignedTx(o,"Sui.TokenBridge.CreateAttestation")}async*submitAttestation(r,t){const[c,i]=await this.getPackageIds(),a=t.toString(),l=Math.min(r.payload.decimals,8),n=await this.getCoinBuildOutput(c,i,l),o=await e.publishPackage(n,a);yield this.createUnsignedTx(o,"Sui.TokenBridge.PrepareCreateWrapped");let g="",s="",f="",p="",y="",m=!1;for(;!m;){await new Promise(h=>setTimeout(h,500));const I=await this.provider.queryTransactionBlocks({filter:{FromAddress:a},options:{showObjectChanges:!0},limit:3});for(const h of I.data)if("objectChanges"in h){for(const u of h.objectChanges)e.isSuiPublishEvent(u)&&u.packageId!==void 0?g=u.packageId:e.isSuiCreateEvent(u)&&u.objectType.includes("WrappedAssetSetup")?(s=u.objectId,y=u.objectType.split(", ")[1].replace(">","")):e.isSuiCreateEvent(u)&&u.objectType.includes("UpgradeCap")?f=u.objectId:e.isSuiCreateEvent(u)&&u.objectType.includes("CoinMetadata")&&(p=u.objectId);if(g!==""&&s!==""&&f!==""&&p!==""){m=!0;break}else g="",s="",f="",p=""}}const b=e.getCoinTypeFromPackageId(g),d=new e.Transaction$2,[j]=d.moveCall({target:`${c}::vaa::parse_and_verify`,arguments:[d.object(this.coreBridgeObjectId),d.pure.vector("u8",e.serialize(r)),d.object(e.SUI_CLOCK_OBJECT_ID)]}),[T]=d.moveCall({target:`${i}::vaa::verify_only_once`,arguments:[d.object(this.tokenBridgeObjectId),j]});d.moveCall({target:`${i}::create_wrapped::complete_registration`,arguments:[d.object(this.tokenBridgeObjectId),d.object(p),d.object(s),d.object(f),T],typeArguments:[b,y]}),yield this.createUnsignedTx(d,"Sui.TokenBridge.SubmitAttestation")}async*transfer(r,t,c,i,a){const l=0n,n=0n,g=r.toString(),s=(e.isNative(c)?e.SUI_TYPE_ARG:c).toString(),f=await e.SuiPlatform.getCoins(this.provider,r,s),[p,...y]=f.filter(h=>e.isSameType(h.coinType,s));if(p===void 0)throw new Error(`Coins array doesn't contain any coins of type ${s}`);const[m,b]=await this.getPackageIds(),d=new e.Transaction$2,[j]=(()=>{if(s===e.SUI_TYPE_ARG)return d.splitCoins(d.gas,[d.pure.u64(i)]);{const h=d.object(p.coinObjectId);return y.length&&d.mergeCoins(h,y.map(u=>d.object(u.coinObjectId))),d.splitCoins(h,[d.pure.u64(i)])}})(),[T]=d.splitCoins(d.gas,[d.pure.u64(l)]),[I]=d.moveCall({target:`${b}::state::verified_asset`,arguments:[d.object(this.tokenBridgeObjectId)],typeArguments:[s]});if(a){if(!g)throw new Error("senderAddress is required for transfer with payload");let h=!1;const u=await(async()=>{const O=await e.getOldestEmitterCapObjectId(this.provider,m,g);if(O!==null)return d.object(O);{const[P]=d.moveCall({target:`${m}::emitter::new`,arguments:[d.object(this.coreBridgeObjectId)]});return h=!0,P}})(),[v,A]=d.moveCall({target:`${b}::transfer_tokens_with_payload::prepare_transfer`,arguments:[u,I,j,d.pure.u16(e.toChainId(t.chain)),d.pure.vector("u8",t.address.toUint8Array()),d.pure.vector("u8",a),d.pure.u32(0)],typeArguments:[s]});d.moveCall({target:`${b}::coin_utils::return_nonzero`,arguments:[A],typeArguments:[s]});const[E]=d.moveCall({target:`${b}::transfer_tokens_with_payload::transfer_tokens_with_payload`,arguments:[d.object(this.tokenBridgeObjectId),v],typeArguments:[s]});d.moveCall({target:`${m}::publish_message::publish_message`,arguments:[d.object(this.coreBridgeObjectId),T,E,d.object(e.SUI_CLOCK_OBJECT_ID)]}),h&&d.transferObjects([u],d.pure.address(g)),yield this.createUnsignedTx(d,"Sui.TokenBridge.TransferWithPayload")}else{const[h,u]=d.moveCall({target:`${b}::transfer_tokens::prepare_transfer`,arguments:[I,j,d.pure.u16(e.toChainId(t.chain)),d.pure.vector("u8",t.address.toUint8Array()),d.pure.u64(n),d.pure.u32(0)],typeArguments:[s]});d.moveCall({target:`${b}::coin_utils::return_nonzero`,arguments:[u],typeArguments:[s]});const[v]=d.moveCall({target:`${b}::transfer_tokens::transfer_tokens`,arguments:[d.object(this.tokenBridgeObjectId),h],typeArguments:[s]});d.moveCall({target:`${m}::publish_message::publish_message`,arguments:[d.object(this.coreBridgeObjectId),T,v,d.object(e.SUI_CLOCK_OBJECT_ID)]}),yield this.createUnsignedTx(d,"Sui.TokenBridge.Transfer")}}async*redeem(r,t,c=!0){const i=await _(this.provider,this.tokenBridgeObjectId,t.payload.token.address.toUint8Array(),e.toChainId(t.payload.token.chain));if(!i)throw new Error("Unable to fetch token coinType");const[a,l]=await this.getPackageIds(),n=new e.Transaction$2,[o]=n.moveCall({target:`${a}::vaa::parse_and_verify`,arguments:[n.object(this.coreBridgeObjectId),n.pure.vector("u8",e.serialize(t)),n.object(e.SUI_CLOCK_OBJECT_ID)]}),[g]=n.moveCall({target:`${l}::vaa::verify_only_once`,arguments:[n.object(this.tokenBridgeObjectId),o]}),[s]=n.moveCall({target:`${l}::complete_transfer::authorize_transfer`,arguments:[n.object(this.tokenBridgeObjectId),g],typeArguments:[i]}),[f]=n.moveCall({target:`${l}::complete_transfer::redeem_relayer_payout`,arguments:[s],typeArguments:[i]});n.moveCall({target:`${l}::coin_utils::return_nonzero`,arguments:[f],typeArguments:[i]}),yield this.createUnsignedTx(n,"Sui.TokenBridge.Redeem")}async getWrappedNative(){return e.toNative(this.chain,e.SUI_TYPE_ARG)}async getPackageIds(){return Promise.all([e.getPackageId(this.provider,this.coreBridgeObjectId),e.getPackageId(this.provider,this.tokenBridgeObjectId)])}async getCoinBuildOutput(r,t,c){var n;if(c>8)throw new Error("Decimals is capped at 8");const i=(n=await e.getOriginalPackageId(this.provider,this.tokenBridgeObjectId))==null?void 0:n.replace("0x","");if(!i)throw new Error(`Original token bridge package ID not found for object ID ${this.tokenBridgeObjectId}`);const a="a11ceb0b060000000901000a020a14031e1704350405392d07669f01088502600ae502050cea02160004010b010c0205020d000002000201020003030c020001000104020700000700010001090801010c020a050600030803040202000302010702080007080100020800080303090002070801010b020209000901010608010105010b0202080008030209000504434f494e095478436f6e7465787408565f5f305f325f3011577261707065644173736574536574757004636f696e0e6372656174655f777261707065640b64756d6d795f6669656c6404696e697414707265706172655f726567697374726174696f6e0f7075626c69635f7472616e736665720673656e646572087472616e736665720a74785f636f6e746578740f76657273696f6e5f636f6e74726f6c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"+i+"00020106010000000001090b0031"+c.toString(16).padStart(2,"0")+"0a0138000b012e110238010200";return{modules:[e.b64.encode(e.hex.decode(a))],dependencies:["0x1","0x2",t,r].map(o=>e.normalizeSuiObjectId(o))}}createUnsignedTx(r,t,c=!1){return new e.SuiUnsignedTransaction(r,this.network,this.chain,t,c)}}class C{constructor(r,t,c,i){w(this,"network");w(this,"chain");w(this,"connection");w(this,"contracts");w(this,"tokenBridgeRelayerObjectId");w(this,"coreBridgeObjectId");w(this,"tokenBridgeObjectId");w(this,"fields");this.network=r,this.chain=t,this.connection=c,this.contracts=i;const{tokenBridge:a,tokenBridgeRelayer:l,coreBridge:n}=i;if(!a||!l||!n)throw new Error(`Some object IDs for ${t} Automatic Token Bridge not found`);this.tokenBridgeRelayerObjectId=l,this.tokenBridgeObjectId=a,this.coreBridgeObjectId=n}static async fromRpc(r,t){const[c,i]=await e.SuiPlatform.chainFromRpc(r),a=t[i];if(a.network!==c)throw new Error(`Network mismatch for chain ${i}: ${a.network} != ${c}`);return new C(c,i,r,a.contracts)}async*transfer(r,t,c,i,a){const n=new e.SuiAddress(e.isNative(c)?e.SuiPlatform.nativeTokenId(this.network,this.chain).address:c).getCoinType(),{coreBridge:o,tokenBridge:g}=await this.getPackageIds(),s=new e.Transaction$2,f=BigInt(0),[p]=s.splitCoins(s.gas,[s.pure.u64(f)]),[y]=await(async()=>{if(e.isNative(c))return s.splitCoins(s.gas,[s.pure.u64(i)]);{const T=await e.SuiPlatform.getCoins(this.connection,r,n),[I,...h]=T.filter(v=>v.coinType===n);if(I===void 0)throw new Error(`Coins array doesn't contain any coins of type ${n}`);const u=s.object(I.coinObjectId);return h.length&&s.mergeCoins(u,h.map(v=>s.object(v.coinObjectId))),s.splitCoins(u,[s.pure.u64(i)])}})(),[m]=s.moveCall({target:`${g}::state::verified_asset`,arguments:[s.object(this.tokenBridgeObjectId)],typeArguments:[n]}),b=await this.getPackageId(),[d]=s.moveCall({target:`${b}::transfer::transfer_tokens_with_relay`,arguments:[s.object(this.tokenBridgeRelayerObjectId),y,m,s.pure.u64(a??0n),s.pure.u16(e.toChainId(t.chain)),s.pure.address(e.hex.encode(t.address.toUint8Array(),!0)),s.pure.u32(123)],typeArguments:[n]}),[j]=s.moveCall({target:`${g}::transfer_tokens_with_payload::transfer_tokens_with_payload`,arguments:[s.object(this.tokenBridgeObjectId),d],typeArguments:[n]});s.moveCall({target:`${o}::publish_message::publish_message`,arguments:[s.object(this.coreBridgeObjectId),p,j,s.object(e.SUI_CLOCK_OBJECT_ID)]}),yield this.createUnsignedTx(s,"AutomaticTokenBridge.transfer")}async*redeem(r,t){const{coreBridge:c,tokenBridge:i}=await this.getPackageIds(),{address:a,chain:l}=t.payload.token,n=await _(this.connection,this.tokenBridgeObjectId,a.toUniversalAddress().toUint8Array(),e.toChainId(l));if(!n)throw new Error("Unable to fetch token coinType");const o=new e.Transaction$2,[g]=o.moveCall({target:`${c}::vaa::parse_and_verify`,arguments:[o.object(this.coreBridgeObjectId),o.pure.vector("u8",e.serialize(t)),o.object(e.SUI_CLOCK_OBJECT_ID)]}),[s]=o.moveCall({target:`${i}::vaa::verify_only_once`,arguments:[o.object(this.tokenBridgeObjectId),g]}),[f]=o.moveCall({target:`${i}::complete_transfer_with_payload::authorize_transfer`,arguments:[o.object(this.tokenBridgeObjectId),s],typeArguments:[n]}),p=await this.getPackageId();o.moveCall({target:`${p}::redeem::complete_transfer`,arguments:[o.object(this.tokenBridgeRelayerObjectId),f],typeArguments:[n]}),yield this.createUnsignedTx(o,"AutomaticTokenBridge.redeem")}async getRelayerFee(r,t){const c=e.isNative(t)?e.SuiPlatform.nativeTokenId(this.network,this.chain):t,i=await this.getTokenInfo(c.toString());if(i===null)throw new Error("Unsupported token for relay");const a=await this.getFields(),l=await this.connection.getDynamicFieldObject({parentId:this.tokenBridgeRelayerObjectId,name:{type:"vector<u8>",value:Array.from(e.bytes.encode("relayer_fees"))}});if(!l.data||!l.data.content)throw l.error?new Error("Failed to get relayer fees: "+JSON.stringify(l.error)):new Error("Unable to compute relayer fee");const{content:n}=l.data;if(!e.isMoveStructStruct(n)||!e.isMoveStructId(n.fields.id))throw new Error("Unable to compute relayer fee");const o=await this.connection.getDynamicFieldObject({parentId:n.fields.id.id,name:{type:"u16",value:e.toChainId(r)}});if(!o.data||!o.data.content)throw o.error?new Error("Failed to get relayer fees: "+JSON.stringify(l.error)):new Error("Unable to compute relayer fee");const{content:g}=o.data;if(!e.isMoveStructStruct(g))throw new Error("Unable to compute relayer fee");const s=await e.SuiPlatform.getDecimals(this.chain,this.connection,t.toString()),f=i.swap_rate,p=a.relayer_fee_precision,y=a.swap_rate_precision,m=g.fields.value;return 10n**BigInt(s)*BigInt(m)*BigInt(y)/(BigInt(f)*BigInt(p))}async maxSwapAmount(r){var o,g;const c=(e.isNative(r)?e.SuiPlatform.nativeTokenId(this.network,this.chain):r).toString(),i=await this.connection.getCoinMetadata({coinType:c});if(!i)throw new Error("metadata is null");const a=await this.getPackageId(),l=new e.Transaction$2;l.moveCall({target:`${a}::redeem::calculate_max_swap_amount_in`,arguments:[l.object(this.tokenBridgeRelayerObjectId),l.pure.u8(i.decimals)],typeArguments:[c]});const n=await this.connection.devInspectTransactionBlock({transactionBlock:l,sender:e.hex.encode(new Uint8Array(32))});if(!n.results||n.results.length==0||!((o=n.results[0])!=null&&o.returnValues)||((g=n.results[0])==null?void 0:g.returnValues.length)!==1)throw Error("swap rate not set");return e.bignum.decode(new Uint8Array(n.results[0].returnValues[0][0].toReversed()))}async nativeTokenAmount(r,t){var g,s;const i=(e.isNative(r)?e.SuiPlatform.nativeTokenId(this.network,this.chain):r).toString(),a=await this.connection.getCoinMetadata({coinType:i});if(!a)throw new Error("metadata is null");const l=await this.getPackageId(),n=new e.Transaction$2;n.moveCall({target:`${l}::redeem::calculate_native_swap_amount_out`,arguments:[n.object(this.tokenBridgeRelayerObjectId),n.pure.u64(t),n.pure.u8(a.decimals)],typeArguments:[i]});const o=await this.connection.devInspectTransactionBlock({transactionBlock:n,sender:e.hex.encode(new Uint8Array(32))});if(!o.results||o.results.length==0||!((g=o.results[0])!=null&&g.returnValues)||((s=o.results[0])==null?void 0:s.returnValues.length)!==1)throw Error("swap rate not set");return e.bignum.decode(new Uint8Array(o.results[0].returnValues[0][0].toReversed()))}async getRegisteredTokens(){const t=(await this.getFields()).registered_tokens.fields.id.id;return(await this.connection.getDynamicFields({parentId:t})).data.map(a=>{const{address:l,module:n,name:o}=e.parseStructTag(a.objectType);return new e.SuiAddress([l,n,o].join(e.SUI_SEPARATOR))})}async isRegisteredToken(r){const t=new e.SuiAddress(e.isNative(r)?e.SuiPlatform.nativeTokenId(this.network,this.chain).address:r).unwrap();try{return await this.getTokenInfo(t)!==null}catch(c){console.error(c)}return!1}async getTokenInfo(r){var o;const t=await this.getFields(),i=new e.SuiAddress(t.registered_tokens.type).getPackageId(),a=t.registered_tokens.fields.id.id,l=new e.SuiAddress(r),n=e.isSameType(e.SUI_COIN,l.unwrap())?e.SUI_COIN:l.getCoinType();try{const g=await this.connection.getDynamicFieldObject({parentId:a,name:{type:`${i}::registered_tokens::Key<${n}>`,value:{dummy_field:!1}}});if(g.error)throw new Error("Failed to get token info: "+JSON.stringify(g.error));if(!g.data||!g.data.content)throw new Error("Failed to get token info: "+JSON.stringify(g));const{content:s}=g.data;return e.isMoveStructStruct(s)&&e.isMoveStructStruct(s.fields.value)?s.fields.value.fields:null}catch(g){if((g==null?void 0:g.code)===-32e3&&((o=g.message)!=null&&o.includes("RPC Error")))return console.error(g),null;throw g}}async getFields(){if(!this.fields){const r=await e.getObjectFields(this.connection,this.tokenBridgeRelayerObjectId);if(r===null)throw new Error("Failed to get fields from token bridge relayer state");this.fields=r}return this.fields}async getPackageId(){const r=await this.getFields();return new e.SuiAddress(r.registered_tokens.type).getPackageId()}async getPackageIds(){const[r,t]=await Promise.all([e.getPackageId(this.connection,this.coreBridgeObjectId),e.getPackageId(this.connection,this.tokenBridgeObjectId)]);return{coreBridge:r,tokenBridge:t}}createUnsignedTx(r,t,c=!1){return new e.SuiUnsignedTransaction(r,this.network,this.chain,t,c)}}e.registerProtocol("Sui","TokenBridge",S);e.registerProtocol("Sui","AutomaticTokenBridge",C);exports.SuiAutomaticTokenBridge=C;exports.SuiTokenBridge=S;exports.getTokenCoinType=_;exports.getTokenFromTokenRegistry=B;
1
+ "use strict";var $=Object.defineProperty;var U=(k,r,t)=>r in k?$(k,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):k[r]=t;var w=(k,r,t)=>U(k,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DoE4VQhB.js");require("./index-CliZ4E05.js");const B=async(k,r,t)=>{var l,n,o;if(!e.isValidSuiType(t))throw new Error(`Invalid Sui type: ${t}`);const c=await e.getObjectFields(k,r);if(!c)throw new Error(`Unable to fetch object fields from token bridge state. Object ID: ${r}`);const i=(n=(l=c.token_registry.fields)==null?void 0:l.id)==null?void 0:n.id;if(!i)throw new Error("Unable to fetch token registry object ID");const a=e.getPackageIdFromType((o=c.token_registry)==null?void 0:o.type);if(!a)throw new Error("Unable to fetch token registry package ID");return k.getDynamicFieldObject({parentId:i,name:{type:`${a}::token_registry::Key<${t}>`,value:{dummy_field:!1}}})},_=async(k,r,t,c)=>{var s,f,p,y;const i=await e.getObjectFields(k,r);if(!i)throw new Error("Unable to fetch object fields from token bridge state");const a=(f=(s=i.token_registry)==null?void 0:s.fields)==null?void 0:f.coin_types,l=(y=(p=a==null?void 0:a.fields)==null?void 0:p.id)==null?void 0:y.id;if(!l)throw new Error("Unable to fetch coin types");const n=e.getTableKeyType(a==null?void 0:a.type);if(!n)throw new Error("Unable to get key type");const o=await k.getDynamicFieldObject({parentId:l,name:{type:n,value:{addr:[...t],chain:c}}});if(o.error){if(o.error.code==="dynamicFieldNotFound")return null;throw new Error(`Unexpected getDynamicFieldObject response ${o.error}`)}const g=e.getFieldsFromObjectResponse(o);if(!g)return null;if(!e.isMoveStructObject(g))throw new Error("What?");return"value"in g?e.trimSuiType(g.value):null};class S{constructor(r,t,c,i){w(this,"network");w(this,"chain");w(this,"provider");w(this,"contracts");w(this,"coreBridgeObjectId");w(this,"tokenBridgeObjectId");w(this,"chainId");this.network=r,this.chain=t,this.provider=c,this.contracts=i,this.chainId=e.networkChainToNativeChainId.get(r,t);const a=this.contracts.tokenBridge;if(!a)throw new Error(`Wormhole Token Bridge contract for domain ${t} not found`);const l=this.contracts.coreBridge;if(!l)throw new Error(`Wormhole Token Bridge contract for domain ${t} not found`);this.tokenBridgeObjectId=a,this.coreBridgeObjectId=l}static async fromRpc(r,t){const[c,i]=await e.SuiPlatform.chainFromRpc(r),a=t[i];if(a.network!==c)throw new Error(`Network mismatch: ${a.network} != ${c}`);return new S(c,i,r,a.contracts)}async isWrappedAsset(r){try{return await this.getOriginalAsset(r),!0}catch{return!1}}async getOriginalAsset(r){let t=r.getCoinType();if(!e.isValidSuiType(t))throw new Error(`Invalid Sui type: ${t}`);const c=await B(this.provider,this.tokenBridgeObjectId,t),i=e.getFieldsFromObjectResponse(c);if(!i)throw e.ErrNotWrapped(t);if(!e.isMoveStructObject(i))throw new Error("Expected fields to be a MoveStruct");if(!("value"in i))throw new Error("Expected a `value` key in fields of MoveStruct");const a=i.value;if(!e.isMoveStructStruct(a))throw new Error("Expected fields to be a MoveStruct");const l=e.trimSuiType(a.type);if(t=e.trimSuiType(t),l.includes(`wrapped_asset::WrappedAsset<${t}>`)){const n=a.fields.info;if(!e.isMoveStructStruct(n))throw new Error("Expected fields to be a MoveStruct");const o=n.fields.token_address;if(!e.isMoveStructStruct(o))throw new Error("Expected fields to be a MoveStruct");if(!e.isMoveStructObject(o.fields))throw new Error("Expected address data to be a MoveObject");if(!("value"in o.fields))throw new Error("Expected a `value` key in fields of MoveStruct");const g=o.fields.value;if(!e.isMoveStructStruct(g))throw new Error("Expected fields to be a MoveStruct");const s=new Uint8Array(g.fields.data);return{chain:e.toChain(Number(n.fields.token_chain)),address:new e.UniversalAddress(s)}}throw e.ErrNotWrapped(t)}async getTokenUniversalAddress(r){let t=r.getCoinType();if(!e.isValidSuiType(t))throw new Error(`Invalid Sui type: ${t}`);const c=await B(this.provider,this.tokenBridgeObjectId,t),i=e.getFieldsFromObjectResponse(c);if(!i)throw new Error(`Token of type ${t} has not been registered with the token bridge. Has it been attested?`);if(!e.isMoveStructObject(i))throw new Error("Expected fields to be a MoveStruct");if(!("value"in i))throw new Error("Expected a `value` key in fields of MoveStruct");const a=i.value;if(!e.isMoveStructStruct(a))throw new Error("Expected fields to be a MoveStruct");const l=e.trimSuiType(a.type);if(t=e.trimSuiType(t),l.includes(`native_asset::NativeAsset<${t}>`)){const n=a.fields.token_address;if(!e.isMoveStructStruct(n))throw new Error("Expected fields to be a MoveStruct");if(!("value"in n.fields))throw new Error("Expected a `value` key in fields of MoveStruct");const o=n.fields.value;if(!e.isMoveStructStruct(o))throw new Error("Expected fields to be a MoveStruct");const g=new Uint8Array(o.fields.data);return new e.UniversalAddress(g)}throw new Error(`Token of type ${t} is not a native asset`)}async getTokenNativeAddress(r,t){const c=await _(this.provider,this.tokenBridgeObjectId,t.toUint8Array(),e.toChainId(r));if(!c)throw new Error(`Token ${t.toString()} not found in token registry`);return new e.SuiAddress(c)}async hasWrappedAsset(r){try{return await this.getWrappedAsset(r),!0}catch{}return!1}async getWrappedAsset(r){if(e.isNative(r.address))throw new Error("Token Address required, 'native' literal not supported");const t=await _(this.provider,this.tokenBridgeObjectId,r.address.toUniversalAddress().toUint8Array(),e.toChainId(r.chain));if(!t)throw e.ErrNotWrapped(e.canonicalAddress(r));return e.toNative(this.chain,t)}async isTransferCompleted(r){var n,o,g,s,f,p,y,m;const t=await e.getObjectFields(this.provider,this.tokenBridgeObjectId);if(!t)throw new Error("Unable to fetch object fields from token bridge state");const c=(o=(n=t.consumed_vaas)==null?void 0:n.fields)==null?void 0:o.hashes,i=e.getTableKeyType((s=(g=c==null?void 0:c.fields)==null?void 0:g.items)==null?void 0:s.type);if(!i)throw new Error("Unable to get key type");const a=(m=(y=(p=(f=c==null?void 0:c.fields)==null?void 0:f.items)==null?void 0:p.fields)==null?void 0:y.id)==null?void 0:m.id;if(!a)throw new Error("Unable to fetch consumed VAAs table");const l=await this.provider.getDynamicFieldObject({parentId:a,name:{type:i,value:{data:[...e.keccak_256(r.hash)]}}});if(!l.error)return!0;if(l.error.code==="dynamicFieldNotFound")return!1;throw new Error(`Unexpected getDynamicFieldObject response ${l.error}`)}async*createAttestation(r){const t=0n,i=r.toString(),a=await this.provider.getCoinMetadata({coinType:i});if(a===null||a.id===null)throw new Error(`Coin metadata ID for type ${i} not found`);const[l,n]=await this.getPackageIds(),o=new e.Transaction$2,[g]=o.splitCoins(o.gas,[o.pure.u64(t)]),[s]=o.moveCall({target:`${n}::attest_token::attest_token`,arguments:[o.object(this.tokenBridgeObjectId),o.object(a.id),o.pure.u32(0)],typeArguments:[i]});o.moveCall({target:`${l}::publish_message::publish_message`,arguments:[o.object(this.coreBridgeObjectId),g,s,o.object(e.SUI_CLOCK_OBJECT_ID)]}),yield this.createUnsignedTx(o,"Sui.TokenBridge.CreateAttestation")}async*submitAttestation(r,t){const[c,i]=await this.getPackageIds(),a=t.toString(),l=Math.min(r.payload.decimals,8),n=await this.getCoinBuildOutput(c,i,l),o=await e.publishPackage(n,a);yield this.createUnsignedTx(o,"Sui.TokenBridge.PrepareCreateWrapped");let g="",s="",f="",p="",y="",m=!1;for(;!m;){await new Promise(h=>setTimeout(h,500));const I=await this.provider.queryTransactionBlocks({filter:{FromAddress:a},options:{showObjectChanges:!0},limit:3});for(const h of I.data)if("objectChanges"in h){for(const u of h.objectChanges)e.isSuiPublishEvent(u)&&u.packageId!==void 0?g=u.packageId:e.isSuiCreateEvent(u)&&u.objectType.includes("WrappedAssetSetup")?(s=u.objectId,y=u.objectType.split(", ")[1].replace(">","")):e.isSuiCreateEvent(u)&&u.objectType.includes("UpgradeCap")?f=u.objectId:e.isSuiCreateEvent(u)&&u.objectType.includes("CoinMetadata")&&(p=u.objectId);if(g!==""&&s!==""&&f!==""&&p!==""){m=!0;break}else g="",s="",f="",p=""}}const b=e.getCoinTypeFromPackageId(g),d=new e.Transaction$2,[j]=d.moveCall({target:`${c}::vaa::parse_and_verify`,arguments:[d.object(this.coreBridgeObjectId),d.pure.vector("u8",e.serialize(r)),d.object(e.SUI_CLOCK_OBJECT_ID)]}),[T]=d.moveCall({target:`${i}::vaa::verify_only_once`,arguments:[d.object(this.tokenBridgeObjectId),j]});d.moveCall({target:`${i}::create_wrapped::complete_registration`,arguments:[d.object(this.tokenBridgeObjectId),d.object(p),d.object(s),d.object(f),T],typeArguments:[b,y]}),yield this.createUnsignedTx(d,"Sui.TokenBridge.SubmitAttestation")}async*transfer(r,t,c,i,a){const l=0n,n=0n,g=r.toString(),s=(e.isNative(c)?e.SUI_TYPE_ARG:c).toString(),f=await e.SuiPlatform.getCoins(this.provider,r,s),[p,...y]=f.filter(h=>e.isSameType(h.coinType,s));if(p===void 0)throw new Error(`Coins array doesn't contain any coins of type ${s}`);const[m,b]=await this.getPackageIds(),d=new e.Transaction$2,[j]=(()=>{if(s===e.SUI_TYPE_ARG)return d.splitCoins(d.gas,[d.pure.u64(i)]);{const h=d.object(p.coinObjectId);return y.length&&d.mergeCoins(h,y.map(u=>d.object(u.coinObjectId))),d.splitCoins(h,[d.pure.u64(i)])}})(),[T]=d.splitCoins(d.gas,[d.pure.u64(l)]),[I]=d.moveCall({target:`${b}::state::verified_asset`,arguments:[d.object(this.tokenBridgeObjectId)],typeArguments:[s]});if(a){if(!g)throw new Error("senderAddress is required for transfer with payload");let h=!1;const u=await(async()=>{const O=await e.getOldestEmitterCapObjectId(this.provider,m,g);if(O!==null)return d.object(O);{const[P]=d.moveCall({target:`${m}::emitter::new`,arguments:[d.object(this.coreBridgeObjectId)]});return h=!0,P}})(),[v,A]=d.moveCall({target:`${b}::transfer_tokens_with_payload::prepare_transfer`,arguments:[u,I,j,d.pure.u16(e.toChainId(t.chain)),d.pure.vector("u8",t.address.toUint8Array()),d.pure.vector("u8",a),d.pure.u32(0)],typeArguments:[s]});d.moveCall({target:`${b}::coin_utils::return_nonzero`,arguments:[A],typeArguments:[s]});const[E]=d.moveCall({target:`${b}::transfer_tokens_with_payload::transfer_tokens_with_payload`,arguments:[d.object(this.tokenBridgeObjectId),v],typeArguments:[s]});d.moveCall({target:`${m}::publish_message::publish_message`,arguments:[d.object(this.coreBridgeObjectId),T,E,d.object(e.SUI_CLOCK_OBJECT_ID)]}),h&&d.transferObjects([u],d.pure.address(g)),yield this.createUnsignedTx(d,"Sui.TokenBridge.TransferWithPayload")}else{const[h,u]=d.moveCall({target:`${b}::transfer_tokens::prepare_transfer`,arguments:[I,j,d.pure.u16(e.toChainId(t.chain)),d.pure.vector("u8",t.address.toUint8Array()),d.pure.u64(n),d.pure.u32(0)],typeArguments:[s]});d.moveCall({target:`${b}::coin_utils::return_nonzero`,arguments:[u],typeArguments:[s]});const[v]=d.moveCall({target:`${b}::transfer_tokens::transfer_tokens`,arguments:[d.object(this.tokenBridgeObjectId),h],typeArguments:[s]});d.moveCall({target:`${m}::publish_message::publish_message`,arguments:[d.object(this.coreBridgeObjectId),T,v,d.object(e.SUI_CLOCK_OBJECT_ID)]}),yield this.createUnsignedTx(d,"Sui.TokenBridge.Transfer")}}async*redeem(r,t,c=!0){const i=await _(this.provider,this.tokenBridgeObjectId,t.payload.token.address.toUint8Array(),e.toChainId(t.payload.token.chain));if(!i)throw new Error("Unable to fetch token coinType");const[a,l]=await this.getPackageIds(),n=new e.Transaction$2,[o]=n.moveCall({target:`${a}::vaa::parse_and_verify`,arguments:[n.object(this.coreBridgeObjectId),n.pure.vector("u8",e.serialize(t)),n.object(e.SUI_CLOCK_OBJECT_ID)]}),[g]=n.moveCall({target:`${l}::vaa::verify_only_once`,arguments:[n.object(this.tokenBridgeObjectId),o]}),[s]=n.moveCall({target:`${l}::complete_transfer::authorize_transfer`,arguments:[n.object(this.tokenBridgeObjectId),g],typeArguments:[i]}),[f]=n.moveCall({target:`${l}::complete_transfer::redeem_relayer_payout`,arguments:[s],typeArguments:[i]});n.moveCall({target:`${l}::coin_utils::return_nonzero`,arguments:[f],typeArguments:[i]}),yield this.createUnsignedTx(n,"Sui.TokenBridge.Redeem")}async getWrappedNative(){return e.toNative(this.chain,e.SUI_TYPE_ARG)}async getPackageIds(){return Promise.all([e.getPackageId(this.provider,this.coreBridgeObjectId),e.getPackageId(this.provider,this.tokenBridgeObjectId)])}async getCoinBuildOutput(r,t,c){var n;if(c>8)throw new Error("Decimals is capped at 8");const i=(n=await e.getOriginalPackageId(this.provider,this.tokenBridgeObjectId))==null?void 0:n.replace("0x","");if(!i)throw new Error(`Original token bridge package ID not found for object ID ${this.tokenBridgeObjectId}`);const a="a11ceb0b060000000901000a020a14031e1704350405392d07669f01088502600ae502050cea02160004010b010c0205020d000002000201020003030c020001000104020700000700010001090801010c020a050600030803040202000302010702080007080100020800080303090002070801010b020209000901010608010105010b0202080008030209000504434f494e095478436f6e7465787408565f5f305f325f3011577261707065644173736574536574757004636f696e0e6372656174655f777261707065640b64756d6d795f6669656c6404696e697414707265706172655f726567697374726174696f6e0f7075626c69635f7472616e736665720673656e646572087472616e736665720a74785f636f6e746578740f76657273696f6e5f636f6e74726f6c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"+i+"00020106010000000001090b0031"+c.toString(16).padStart(2,"0")+"0a0138000b012e110238010200";return{modules:[e.b64.encode(e.hex.decode(a))],dependencies:["0x1","0x2",t,r].map(o=>e.normalizeSuiObjectId(o))}}createUnsignedTx(r,t,c=!1){return new e.SuiUnsignedTransaction(r,this.network,this.chain,t,c)}}class C{constructor(r,t,c,i){w(this,"network");w(this,"chain");w(this,"connection");w(this,"contracts");w(this,"tokenBridgeRelayerObjectId");w(this,"coreBridgeObjectId");w(this,"tokenBridgeObjectId");w(this,"fields");this.network=r,this.chain=t,this.connection=c,this.contracts=i;const{tokenBridge:a,tokenBridgeRelayer:l,coreBridge:n}=i;if(!a||!l||!n)throw new Error(`Some object IDs for ${t} Automatic Token Bridge not found`);this.tokenBridgeRelayerObjectId=l,this.tokenBridgeObjectId=a,this.coreBridgeObjectId=n}static async fromRpc(r,t){const[c,i]=await e.SuiPlatform.chainFromRpc(r),a=t[i];if(a.network!==c)throw new Error(`Network mismatch for chain ${i}: ${a.network} != ${c}`);return new C(c,i,r,a.contracts)}async*transfer(r,t,c,i,a){const n=new e.SuiAddress(e.isNative(c)?e.SuiPlatform.nativeTokenId(this.network,this.chain).address:c).getCoinType(),{coreBridge:o,tokenBridge:g}=await this.getPackageIds(),s=new e.Transaction$2,f=BigInt(0),[p]=s.splitCoins(s.gas,[s.pure.u64(f)]),[y]=await(async()=>{if(e.isNative(c))return s.splitCoins(s.gas,[s.pure.u64(i)]);{const T=await e.SuiPlatform.getCoins(this.connection,r,n),[I,...h]=T.filter(v=>v.coinType===n);if(I===void 0)throw new Error(`Coins array doesn't contain any coins of type ${n}`);const u=s.object(I.coinObjectId);return h.length&&s.mergeCoins(u,h.map(v=>s.object(v.coinObjectId))),s.splitCoins(u,[s.pure.u64(i)])}})(),[m]=s.moveCall({target:`${g}::state::verified_asset`,arguments:[s.object(this.tokenBridgeObjectId)],typeArguments:[n]}),b=await this.getPackageId(),[d]=s.moveCall({target:`${b}::transfer::transfer_tokens_with_relay`,arguments:[s.object(this.tokenBridgeRelayerObjectId),y,m,s.pure.u64(a??0n),s.pure.u16(e.toChainId(t.chain)),s.pure.address(e.hex.encode(t.address.toUint8Array(),!0)),s.pure.u32(123)],typeArguments:[n]}),[j]=s.moveCall({target:`${g}::transfer_tokens_with_payload::transfer_tokens_with_payload`,arguments:[s.object(this.tokenBridgeObjectId),d],typeArguments:[n]});s.moveCall({target:`${o}::publish_message::publish_message`,arguments:[s.object(this.coreBridgeObjectId),p,j,s.object(e.SUI_CLOCK_OBJECT_ID)]}),yield this.createUnsignedTx(s,"AutomaticTokenBridge.transfer")}async*redeem(r,t){const{coreBridge:c,tokenBridge:i}=await this.getPackageIds(),{address:a,chain:l}=t.payload.token,n=await _(this.connection,this.tokenBridgeObjectId,a.toUniversalAddress().toUint8Array(),e.toChainId(l));if(!n)throw new Error("Unable to fetch token coinType");const o=new e.Transaction$2,[g]=o.moveCall({target:`${c}::vaa::parse_and_verify`,arguments:[o.object(this.coreBridgeObjectId),o.pure.vector("u8",e.serialize(t)),o.object(e.SUI_CLOCK_OBJECT_ID)]}),[s]=o.moveCall({target:`${i}::vaa::verify_only_once`,arguments:[o.object(this.tokenBridgeObjectId),g]}),[f]=o.moveCall({target:`${i}::complete_transfer_with_payload::authorize_transfer`,arguments:[o.object(this.tokenBridgeObjectId),s],typeArguments:[n]}),p=await this.getPackageId();o.moveCall({target:`${p}::redeem::complete_transfer`,arguments:[o.object(this.tokenBridgeRelayerObjectId),f],typeArguments:[n]}),yield this.createUnsignedTx(o,"AutomaticTokenBridge.redeem")}async getRelayerFee(r,t){const c=e.isNative(t)?e.SuiPlatform.nativeTokenId(this.network,this.chain):t,i=await this.getTokenInfo(c.toString());if(i===null)throw new Error("Unsupported token for relay");const a=await this.getFields(),l=await this.connection.getDynamicFieldObject({parentId:this.tokenBridgeRelayerObjectId,name:{type:"vector<u8>",value:Array.from(e.bytes.encode("relayer_fees"))}});if(!l.data||!l.data.content)throw l.error?new Error("Failed to get relayer fees: "+JSON.stringify(l.error)):new Error("Unable to compute relayer fee");const{content:n}=l.data;if(!e.isMoveStructStruct(n)||!e.isMoveStructId(n.fields.id))throw new Error("Unable to compute relayer fee");const o=await this.connection.getDynamicFieldObject({parentId:n.fields.id.id,name:{type:"u16",value:e.toChainId(r)}});if(!o.data||!o.data.content)throw o.error?new Error("Failed to get relayer fees: "+JSON.stringify(l.error)):new Error("Unable to compute relayer fee");const{content:g}=o.data;if(!e.isMoveStructStruct(g))throw new Error("Unable to compute relayer fee");const s=await e.SuiPlatform.getDecimals(this.chain,this.connection,t.toString()),f=i.swap_rate,p=a.relayer_fee_precision,y=a.swap_rate_precision,m=g.fields.value;return 10n**BigInt(s)*BigInt(m)*BigInt(y)/(BigInt(f)*BigInt(p))}async maxSwapAmount(r){var o,g;const c=(e.isNative(r)?e.SuiPlatform.nativeTokenId(this.network,this.chain):r).toString(),i=await this.connection.getCoinMetadata({coinType:c});if(!i)throw new Error("metadata is null");const a=await this.getPackageId(),l=new e.Transaction$2;l.moveCall({target:`${a}::redeem::calculate_max_swap_amount_in`,arguments:[l.object(this.tokenBridgeRelayerObjectId),l.pure.u8(i.decimals)],typeArguments:[c]});const n=await this.connection.devInspectTransactionBlock({transactionBlock:l,sender:e.hex.encode(new Uint8Array(32))});if(!n.results||n.results.length==0||!((o=n.results[0])!=null&&o.returnValues)||((g=n.results[0])==null?void 0:g.returnValues.length)!==1)throw Error("swap rate not set");return e.bignum.decode(new Uint8Array(n.results[0].returnValues[0][0].toReversed()))}async nativeTokenAmount(r,t){var g,s;const i=(e.isNative(r)?e.SuiPlatform.nativeTokenId(this.network,this.chain):r).toString(),a=await this.connection.getCoinMetadata({coinType:i});if(!a)throw new Error("metadata is null");const l=await this.getPackageId(),n=new e.Transaction$2;n.moveCall({target:`${l}::redeem::calculate_native_swap_amount_out`,arguments:[n.object(this.tokenBridgeRelayerObjectId),n.pure.u64(t),n.pure.u8(a.decimals)],typeArguments:[i]});const o=await this.connection.devInspectTransactionBlock({transactionBlock:n,sender:e.hex.encode(new Uint8Array(32))});if(!o.results||o.results.length==0||!((g=o.results[0])!=null&&g.returnValues)||((s=o.results[0])==null?void 0:s.returnValues.length)!==1)throw Error("swap rate not set");return e.bignum.decode(new Uint8Array(o.results[0].returnValues[0][0].toReversed()))}async getRegisteredTokens(){const t=(await this.getFields()).registered_tokens.fields.id.id;return(await this.connection.getDynamicFields({parentId:t})).data.map(a=>{const{address:l,module:n,name:o}=e.parseStructTag(a.objectType);return new e.SuiAddress([l,n,o].join(e.SUI_SEPARATOR))})}async isRegisteredToken(r){const t=new e.SuiAddress(e.isNative(r)?e.SuiPlatform.nativeTokenId(this.network,this.chain).address:r).unwrap();try{return await this.getTokenInfo(t)!==null}catch(c){console.error(c)}return!1}async getTokenInfo(r){var o;const t=await this.getFields(),i=new e.SuiAddress(t.registered_tokens.type).getPackageId(),a=t.registered_tokens.fields.id.id,l=new e.SuiAddress(r),n=e.isSameType(e.SUI_COIN,l.unwrap())?e.SUI_COIN:l.getCoinType();try{const g=await this.connection.getDynamicFieldObject({parentId:a,name:{type:`${i}::registered_tokens::Key<${n}>`,value:{dummy_field:!1}}});if(g.error)throw new Error("Failed to get token info: "+JSON.stringify(g.error));if(!g.data||!g.data.content)throw new Error("Failed to get token info: "+JSON.stringify(g));const{content:s}=g.data;return e.isMoveStructStruct(s)&&e.isMoveStructStruct(s.fields.value)?s.fields.value.fields:null}catch(g){if((g==null?void 0:g.code)===-32e3&&((o=g.message)!=null&&o.includes("RPC Error")))return console.error(g),null;throw g}}async getFields(){if(!this.fields){const r=await e.getObjectFields(this.connection,this.tokenBridgeRelayerObjectId);if(r===null)throw new Error("Failed to get fields from token bridge relayer state");this.fields=r}return this.fields}async getPackageId(){const r=await this.getFields();return new e.SuiAddress(r.registered_tokens.type).getPackageId()}async getPackageIds(){const[r,t]=await Promise.all([e.getPackageId(this.connection,this.coreBridgeObjectId),e.getPackageId(this.connection,this.tokenBridgeObjectId)]);return{coreBridge:r,tokenBridge:t}}createUnsignedTx(r,t,c=!1){return new e.SuiUnsignedTransaction(r,this.network,this.chain,t,c)}}e.registerProtocol("Sui","TokenBridge",S);e.registerProtocol("Sui","AutomaticTokenBridge",C);exports.SuiAutomaticTokenBridge=C;exports.SuiTokenBridge=S;exports.getTokenCoinType=_;exports.getTokenFromTokenRegistry=B;