import { playgroundHelper } from "../../helpers/helpers"; import { actionCreators, createTransaction, } from "@near-js/transactions"; import { baseDecode } from "@near-js/utils"; import { Account } from "@near-js/accounts"; const BRIDGE_AMOUNT = "500000000"; // 6 decimals const TOKEN_ID = "arb-0xaf88d065e77c8cc2239327c5edb3a432268e5831.omft.near"; // NEAR intents token ID (without "nep141:") const RECIPIENT = "0x24db64a117db9af57bb33a0f51018b67a529b831"; // Must match policy memo restriction console.log("Initiating token bridge from NEAR to Arb"); // Get current block hash and vault account info const block = await playgroundHelper.provider.block({ finality: "near-final", }); const derivedAccount = new Account( playgroundHelper.vaultContractId, playgroundHelper.provider ); const allKeys = await derivedAccount.getAccessKeyList(); const matchingKey = allKeys.keys.find( (e) => e.public_key === playgroundHelper.vaultPublicKey.toString() ); if (!matchingKey) { throw new Error("Key not found"); } // Create NEAR transaction for ft_withdraw const transaction = createTransaction( playgroundHelper.vaultContractId, playgroundHelper.vaultPublicKey, "intents.near", // receiver_id for ft_withdraw BigInt(matchingKey.access_key.nonce) + 1n, [ actionCreators.functionCall( "ft_withdraw", { token: TOKEN_ID, receiver_id: TOKEN_ID, amount: BRIDGE_AMOUNT, memo: `WITHDRAW_TO:${RECIPIENT}` }, 30000000000000n, // 30 TGas 1n // 1 yoctoNEAR ), ], baseDecode(block.header.hash) ); // Encode transaction as base64 const encodedTx = Buffer.from(transaction.encode()).toString("base64"); // Execute bridge transaction using the vault's NEAR Intents ft_withdraw policy const bridgeResult = await playgroundHelper.account.callFunction({ contractId: playgroundHelper.vaultContractId, methodName: "propose_execution", args: { policy_id: "near_intents_ft_withdraw_arb", function_args: encodedTx, deadline_hours: 1 }, gas: 50000000000000n, // 50 TGas }); console.log("Bridge transaction proposed:", bridgeResult); console.log(`Bridging ${BRIDGE_AMOUNT} USDC to Arbitrum address ${RECIPIENT}`);