var H = Object.defineProperty;
var Q = (n, t, e) => t in n ? H(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
var d = (n, t, e) => Q(n, typeof t != "symbol" ? t + "" : t, e);
import { a9 as s, O as c, b2 as h, aW as X, aX as E, aY as W, aZ as Y, a_ as J, a$ as j, bE as $, bF as ee, bG as te, e as ne, f as K, bL as ie, bM as se, bN as ae, bO as re, bP as oe, bJ as x, bQ as ce, bR as N, bS as de, bT as v, ac as O, bU as ue, bV as ge, bW as me, bK as fe, bf as le, g as he } from "./index-6NRj6D5S.mjs";
import { deriveWrappedMetaKey as G, deriveTokenBridgeConfigKey as R, deriveAuthoritySignerKey as pe, deriveSenderAccountKey as ye, deriveMintAuthorityKey as we, deriveEndpointKey as Se } from "./index-DV3sBKmN.mjs";
const ke = {
  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 L(n) {
  return s.findProgramAddressSync([c.Buffer.from("redeemer")], new s(n))[0];
}
function Me(n, t) {
  const e = c.Buffer.alloc(8);
  return e.writeBigUInt64LE(t), s.findProgramAddressSync([c.Buffer.from("msg"), e], new s(n))[0];
}
function Te(n, t) {
  const e = c.Buffer.alloc(2);
  return e.writeUInt16LE(h(t)), s.findProgramAddressSync([c.Buffer.from("gateway-info"), e], new s(n))[0];
}
const T = new s("Gj93RRt6QB7FjmyokAD5rcMAku7pq3Fk2Aa8y6nNbwsV");
function Be() {
  return s.findProgramAddressSync([c.Buffer.from("config")], T)[0];
}
function be(n) {
  return s.findProgramAddressSync([c.Buffer.from("minter-info"), n.toBuffer()], T)[0];
}
const B = new s("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
new s("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
const b = new s("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
new s("So11111111111111111111111111111111111111112");
new s("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP");
class Ae extends Error {
  constructor(t) {
    super(t);
  }
}
class Ce extends Ae {
  constructor() {
    super(...arguments), this.name = "TokenOwnerOffCurveError";
  }
}
const Pe = X([
  E("mintAuthorityOption"),
  W("mintAuthority"),
  Y("supply"),
  J("decimals"),
  j("isInitialized"),
  E("freezeAuthorityOption"),
  W("freezeAuthority")
]);
Pe.span;
async function M(n, t, e = !1, r = B, i = b) {
  if (!e && !s.isOnCurve(t.toBuffer()))
    throw new Ce();
  const [a] = await s.findProgramAddress([t.toBuffer(), r.toBuffer(), n.toBuffer()], i);
  return a;
}
function Ie(n, t, e, r, i = B, a = b) {
  return Ee(n, t, e, r, c.Buffer.alloc(0), i, a);
}
function Ee(n, t, e, r, i, a = B, o = b) {
  const u = [
    { pubkey: n, isSigner: !0, isWritable: !0 },
    { pubkey: t, isSigner: !1, isWritable: !0 },
    { pubkey: e, isSigner: !1, isWritable: !1 },
    { pubkey: r, isSigner: !1, isWritable: !1 },
    { pubkey: $.programId, isSigner: !1, isWritable: !1 },
    { pubkey: a, isSigner: !1, isWritable: !1 }
  ];
  return new ee({
    keys: u,
    programId: o,
    data: i
  });
}
class A {
  constructor(t, e, r, i) {
    d(this, "network");
    d(this, "chain");
    d(this, "connection");
    d(this, "contracts");
    d(this, "gateway");
    d(this, "tokenBridgeId");
    d(this, "coreBridgeId");
    if (this.network = t, this.chain = e, this.connection = r, this.contracts = i, 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 te(ke, this.contracts.tbtc, {
      connection: r
    }), this.tokenBridgeId = new s(this.contracts.tokenBridge), this.coreBridgeId = new s(this.contracts.coreBridge);
  }
  static async fromRpc(t, e) {
    const [r, i] = await ne.chainFromRpc(t), a = e[i];
    if (a.network !== r)
      throw new Error(`Network mismatch: ${a.network} != ${r}`);
    return new A(r, i, t, a.contracts);
  }
  async *transfer(t, e, r) {
    const i = new K(t).unwrap(), a = L(this.gateway.programId), { tbtcMint: o, wrappedTbtcToken: u, wrappedTbtcMint: g } = await this.gateway.account.custodian.fetch(a), p = G(this.tokenBridgeId, g), m = R(this.tokenBridgeId), f = pe(this.tokenBridgeId), C = ie(this.coreBridgeId), { sequence: y } = await se(this.connection, this.tokenBridgeId, this.coreBridgeId), w = Me(this.gateway.programId, y), S = ae(this.coreBridgeId), l = re(this.tokenBridgeId), k = oe(l, this.coreBridgeId), U = Te(this.gateway.programId, e.chain), V = ye(this.gateway.programId), P = {
      amount: new x(r.toString()),
      recipientChain: h(e.chain),
      recipient: [...e.address.toUniversalAddress().toUint8Array()],
      nonce: 0
    }, D = await M(o, i), q = ce.get(this.network, e.chain), I = {
      custodian: a,
      wrappedTbtcToken: u,
      wrappedTbtcMint: g,
      tbtcMint: o,
      senderToken: D,
      sender: i,
      tokenBridgeConfig: m,
      tokenBridgeWrappedAsset: p,
      tokenBridgeTransferAuthority: f,
      coreBridgeData: S,
      coreMessage: w,
      tokenBridgeCoreEmitter: l,
      coreEmitterSequence: k,
      coreFeeCollector: C,
      clock: de,
      rent: N,
      tokenBridgeProgram: this.tokenBridgeId,
      coreBridgeProgram: this.coreBridgeId
    }, _ = q ? await this.gateway.methods.sendTbtcGateway({ ...P }).accounts({
      ...I,
      gatewayInfo: U,
      tokenBridgeSender: V
    }).instruction() : await this.gateway.methods.sendTbtcWrapped({
      ...P,
      arbiterFee: new x(0)
    }).accounts(I).instruction(), { blockhash: F } = await this.connection.getLatestBlockhash(), z = v.compile({
      instructions: [_],
      payerKey: i,
      recentBlockhash: F
    }), Z = new O(z);
    yield this.createUnsignedTransaction({ transaction: Z }, "TBTCBridge.Send");
  }
  async *redeem(t, e) {
    if (e.payloadName !== "GatewayTransfer")
      throw new Error("Invalid VAA payload");
    yield* new ue(this.network, this.chain, this.connection, this.contracts).postVaa(t, e);
    const i = [], a = new K(t).unwrap(), o = e.payload.payload.recipient.toNative(this.chain).unwrap(), u = L(this.gateway.programId), { tbtcMint: g, wrappedTbtcToken: p, wrappedTbtcMint: m } = await this.gateway.account.custodian.fetch(u), f = await M(g, o);
    await this.connection.getAccountInfo(f) || i.push(Ie(a, f, o, g));
    const y = G(this.tokenBridgeId, m), w = await M(m, o);
    i.push(await this.gateway.methods.receiveTbtc([...e.hash]).accounts({
      payer: a,
      custodian: u,
      postedVaa: me(this.coreBridgeId, c.Buffer.from(e.hash)),
      tokenBridgeClaim: ge(this.tokenBridgeId, e.emitterAddress.toUint8Array(), h(e.emitterChain), e.sequence),
      wrappedTbtcToken: p,
      wrappedTbtcMint: m,
      tbtcMint: g,
      recipientToken: f,
      recipient: o,
      recipientWrappedToken: w,
      tbtcConfig: Be(),
      tbtcMinterInfo: be(u),
      tokenBridgeConfig: R(this.tokenBridgeId),
      tokenBridgeRegisteredEmitter: Se(this.tokenBridgeId, h(e.emitterChain), e.emitterAddress.toUint8Array()),
      tokenBridgeWrappedAsset: y,
      tokenBridgeMintAuthority: we(this.tokenBridgeId),
      rent: N,
      tbtcProgram: T,
      tokenBridgeProgram: this.tokenBridgeId,
      coreBridgeProgram: this.coreBridgeId
    }).instruction());
    const { blockhash: S } = await this.connection.getLatestBlockhash(), l = v.compile({
      instructions: i,
      payerKey: a,
      recentBlockhash: S
    }), k = new O(l);
    yield this.createUnsignedTransaction({ transaction: k }, "TBTCBridge.Send");
  }
  createUnsignedTransaction(t, e) {
    return new fe(t, this.network, this.chain, e, !1);
  }
}
le(he, "TBTCBridge", A);
export {
  A as SolanaTBTCBridge
};
