var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { importCoreWasm } from "./wasm";
export function getBridgeFeeIx(connection, bridgeAddress, payerAddress) {
    return __awaiter(this, void 0, void 0, function* () {
        const bridge = yield importCoreWasm();
        const feeAccount = yield bridge.fee_collector_address(bridgeAddress);
        const bridgeStatePK = new PublicKey(bridge.state_address(bridgeAddress));
        const bridgeStateAccountInfo = yield connection.getAccountInfo(bridgeStatePK);
        if ((bridgeStateAccountInfo === null || bridgeStateAccountInfo === void 0 ? void 0 : bridgeStateAccountInfo.data) === undefined) {
            throw new Error("bridge state not found");
        }
        const bridgeState = bridge.parse_state(new Uint8Array(bridgeStateAccountInfo === null || bridgeStateAccountInfo === void 0 ? void 0 : bridgeStateAccountInfo.data));
        const transferIx = SystemProgram.transfer({
            fromPubkey: new PublicKey(payerAddress),
            toPubkey: new PublicKey(feeAccount),
            lamports: bridgeState.config.fee,
        });
        return transferIx;
    });
}
