import { playgroundHelper } from "../../helpers/helpers"; import { stablecoinVaultConstants } from "../constants"; // Complete vault redemption workflow // Burns vault shares and withdraws underlying assets const SLIPPAGE = BigInt(100); const BASE_ASSET_CONTRACT = stablecoinVaultConstants.ASSET_ACCOUNT_ID; const TOKEN_ID = stablecoinVaultConstants.BASE_TOKEN_ID; const SHARES_TO_REDEEM = "599996000000000000000000"; console.log("Starting vault redemption process..."); const asset = { MultiToken: { contract_id: BASE_ASSET_CONTRACT, token_id: TOKEN_ID, }, }; const previewAssets = await playgroundHelper.account.viewFunction({ contractId: playgroundHelper.vaultContractId, methodName: "preview_redeem", args: { shares: SHARES_TO_REDEEM, asset: asset, }, }); console.log(`Expected assets from redemption: ${previewAssets}`); const min_assets = ((BigInt(previewAssets) * (BigInt(10000) - SLIPPAGE)) / BigInt(10000)).toString(); // For sync redemptions, execute immediate redemption let redeemResult = await playgroundHelper.account.callFunction({ contractId: playgroundHelper.vaultContractId, methodName: "redeem", args: { shares: SHARES_TO_REDEEM, asset: asset, min_assets: min_assets, receiver_id: playgroundHelper.account.accountId, memo: "EVM stablecoin vault sync redemption", }, gas: 150000000000000n, // 150 TGas for cross-contract calls deposit: 1n, // 1 yoctoNEAR for security }); console.log("Sync redemption result:", redeemResult); // Step 6: Check final balances const finalSharesBalance = await playgroundHelper.account.viewFunction({ contractId: playgroundHelper.vaultContractId, methodName: "ft_balance_of", args: { account_id: playgroundHelper.account.accountId, }, }); const finalAssetBalance = await playgroundHelper.account.viewFunction({ contractId: BASE_ASSET_CONTRACT, methodName: "mt_balance_of", args: { account_id: playgroundHelper.account.accountId, token_id: TOKEN_ID, }, }); console.log(`Final vault shares balance: ${finalSharesBalance}`); console.log(`Final asset balance: ${finalAssetBalance}`);