import BN from 'bn.js';
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import { getMint } from '@solana/spl-token';
import {
StarVault,
buildLockCommitmentTx,
buildWithdrawCommitmentTx,
fetchCommitmentRecord,
getVaultStatusKey,
} from '@starfun/sdk-vault';
const connection = new Connection(RPC_URL, 'confirmed');
const vaultAddress = new PublicKey(VAULT_ADDRESS);
const programId = new PublicKey(VAULT_PROGRAM_ID);
const vault = await StarVault.create(connection, vaultAddress, programId);
const quoteMint = new PublicKey(vault.account.quoteMint);
const quoteTokenProgramId = new PublicKey(vault.account.quoteTokenProgram);
const mint = await getMint(connection, quoteMint, 'confirmed', quoteTokenProgramId);
async function send(tx: Transaction) {
const latest = await connection.getLatestBlockhash('confirmed');
tx.feePayer = wallet.publicKey;
tx.recentBlockhash = latest.blockhash;
const signed = await wallet.signTransaction(tx);
const signature = await connection.sendRawTransaction(signed.serialize());
console.log('Submitted:', signature); // Save this receipt before waiting.
const result = await connection.confirmTransaction({ signature, ...latest }, 'confirmed');
if (result.value.err) throw new Error(`Transaction failed: ${signature}`);
return signature;
}