wormhole/sdk/js/src/solana/getBridgeFeeIx.ts

26 lines
898 B
TypeScript

import { Connection, PublicKey, SystemProgram } from "@solana/web3.js";
import { importCoreWasm } from "./wasm";
export async function getBridgeFeeIx(
connection: Connection,
bridgeAddress: string,
payerAddress: string
) {
const bridge = await importCoreWasm();
const feeAccount = await bridge.fee_collector_address(bridgeAddress);
const bridgeStatePK = new PublicKey(bridge.state_address(bridgeAddress));
const bridgeStateAccountInfo = await connection.getAccountInfo(bridgeStatePK);
if (bridgeStateAccountInfo?.data === undefined) {
throw new Error("bridge state not found");
}
const bridgeState = bridge.parse_state(
new Uint8Array(bridgeStateAccountInfo?.data)
);
const transferIx = SystemProgram.transfer({
fromPubkey: new PublicKey(payerAddress),
toPubkey: new PublicKey(feeAccount),
lamports: bridgeState.config.fee,
});
return transferIx;
}