"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./platform-CCG_jgOO.js"),c=require("./index-EbSw7SbC.js");class s{network;chain;provider;contracts;chainId;core;gatewayAddress;gateway;tbtcTokenAddr;constructor(n,e,a,r){if(this.network=n,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=t.TBTCBridge.getNativeTbtcToken(this.chain);if(!i)throw new Error("Native tbtc token not found");this.chainId=t.networkChainToNativeChainId.get(n,e),this.core=new c.EvmWormholeCore(n,e,a,r),this.gatewayAddress=this.contracts.tbtc,this.gateway=new t.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=t.canonicalAddress(i)}static async fromRpc(n,e){const[a,r]=await t.EvmPlatform.chainFromRpc(n),i=e[r];if(i.network!==a)throw new Error(`Network mismatch: ${i.network} != ${a}`);return new s(a,r,n,i.contracts)}async*transfer(n,e,a){const r=new t.EvmAddress(n).toString(),i=await this.gateway.sendTbtc.populateTransaction(a,t.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(t.addFrom(i,r),"TBTCBridge.Send")}async*redeem(n,e){if(e.payloadName!=="GatewayTransfer")throw new Error("Invalid VAA payload");const a=new t.EvmAddress(n).toString(),r=await this.gateway.receiveTbtc.populateTransaction(t.serialize$1(e));yield this.createUnsignedTransaction(t.addFrom(r,a),"TBTCBridge.Redeem")}async*approve(n,e,a){const r=t.EvmPlatform.getTokenImplementation(this.provider,this.tbtcTokenAddr);if(await r.allowance(n,a)<e){const o=await r.approve.populateTransaction(a,e);yield this.createUnsignedTransaction(t.addFrom(o,n),"TBTC.Approve")}}createUnsignedTransaction(n,e){return new t.EvmUnsignedTransaction(t.addChainId(n,this.chainId),this.network,this.chain,e,!1)}}t.registerProtocol(t._platform,"TBTCBridge",s);exports.EvmTBTCBridge=s;
