import { playgroundHelper } from "../../helpers/helpers"; import { stablecoinVaultConstants } from "../constants"; // Complete vault deposit workflow using multi-token transfer // This handles both synchronous and asynchronous deposit flows const BASE_ASSET_CONTRACT = stablecoinVaultConstants.ASSET_ACCOUNT_ID; // Multi-token contract address const TOKEN_ID = stablecoinVaultConstants.BASE_TOKEN_ID; // Token identifier const DEPOSIT_AMOUNT = "9999980"; const SLIPPAGE = BigInt(100); // 1% in basis points console.log("Starting vault deposit process..."); const exchangeRate = await playgroundHelper.account.viewFunction({ contractId: playgroundHelper.vaultContractId, methodName: "get_exchange_rate", args: { asset: { MultiToken: { contract_id: BASE_ASSET_CONTRACT, token_id: TOKEN_ID, }, }, }, }); console.log(`Current exchange rate: ${exchangeRate}`); // Step 3: Preview deposit to estimate shares const previewShares = await playgroundHelper.account.viewFunction({ contractId: playgroundHelper.vaultContractId, methodName: "preview_deposit", args: { assets: DEPOSIT_AMOUNT, asset: { MultiToken: { contract_id: BASE_ASSET_CONTRACT, token_id: TOKEN_ID, }, }, }, }); console.log(`Expected shares from deposit: ${previewShares}`); // // Step 4: Register user for NEP-141 storage if not already registered // console.log("Registering user for vault shares storage..."); // try { // await playgroundHelper.account.callFunction({ // contractId: playgroundHelper.vaultContractId, // methodName: "storage_deposit", // args: { // account_id: playgroundHelper.account.accountId, // registration_only: true, // }, // gas: 30000000000000n, // 30 TGas // deposit: 1250000000000000000000n, // 0.00125 NEAR storage deposit // }); // console.log("User registered for vault shares storage"); // } catch (error) { // console.log("User already registered or registration failed:"); // } // Step 5: Create deposit message with slippage protection const previewSharesBigInt = BigInt(previewShares); const minShares = ( (previewSharesBigInt * (BigInt(10000) - SLIPPAGE)) / BigInt(10000) ).toString(); const depositMessage = { min_shares: minShares.toString(), receiver_id: playgroundHelper.account.accountId, memo: "EVM stablecoin vault deposit with slippage protection", }; // Step 6: Execute multi-token transfer to initiate deposit console.log("Executing multi-token transfer to vault..."); const transferResult = await playgroundHelper.account.callFunction({ contractId: BASE_ASSET_CONTRACT, methodName: "mt_transfer_call", args: { receiver_id: playgroundHelper.vaultContractId, token_id: TOKEN_ID, amount: DEPOSIT_AMOUNT, memo: "Vault deposit", msg: JSON.stringify(depositMessage), }, gas: 150000000000000n, // 150 TGas for complex operations deposit: 1n, // 1 yoctoNEAR for security }); console.log("Transfer transaction result:", transferResult); // Step 7: Check final vault shares balance const finalBalance = await playgroundHelper.account.viewFunction({ contractId: playgroundHelper.vaultContractId, methodName: "ft_balance_of", args: { account_id: playgroundHelper.account.accountId, }, }); console.log(`Final vault shares balance: ${finalBalance}`); console.log("Vault deposit process completed!");