import { playgroundHelper } from "../helpers/helpers"; import { Connection, PublicKey, TransactionMessage, VersionedTransaction, } from "@solana/web3.js"; import { createTransferCheckedInstruction, getAssociatedTokenAddress, } from "@solana/spl-token"; import { svm_constant } from "./constant"; import { MPCSignature } from "chainsig.js"; const addressInfo = await playgroundHelper.provider.callFunction<{ public_key: string; address: string; }>( playgroundHelper.vaultContractId, "derive_address_and_public_key", { path: "1", chain: "SVM", near_network: "Testnet", }); if(!addressInfo){ throw new Error("Unable to find chain sig address info") } const connection = new Connection("https://api.devnet.solana.com"); const fromPublicKey = new PublicKey(addressInfo.address); // random address from solscan const receiverPublicKey = new PublicKey( "4PkiqJkUvxr9P8C1UsMqGN8NJsUcep9GahDRLfmeu8UK" ); const mint = new PublicKey(svm_constant.DEV_NET_USDC_ADDRESS); const fromTokenAccount = await getAssociatedTokenAddress(mint, fromPublicKey); const toTokenAccount = await getAssociatedTokenAddress(mint, receiverPublicKey); const ix = createTransferCheckedInstruction( fromTokenAccount, mint, toTokenAccount, fromPublicKey, 100, 6 ); const { blockhash } = await connection.getLatestBlockhash({ commitment: "finalized", }); const message = new TransactionMessage({ payerKey: new PublicKey(addressInfo.address), recentBlockhash: blockhash, instructions: [ix], }).compileToV0Message(); const encodedTx = Buffer.from(message.serialize()).toString("base64"); const signatures = await playgroundHelper.account.callFunction({ contractId: playgroundHelper.vaultContractId, methodName: "propose_execution", args: { policy_id: "transfer_devnet_solana_usdc", function_args: encodedTx, deadline_hours: 0, }, }); const firstSignResult = signatures[0]; if (!("signature" in firstSignResult)) { throw new Error("invalid signature"); } const signatureBuffer = Buffer.from(firstSignResult.signature); const versionedTransaction = new VersionedTransaction(message); versionedTransaction.addSignature( new PublicKey(addressInfo.address), signatureBuffer ); const hash = await connection.sendTransaction(versionedTransaction); console.log(hash);