There are two distinct functions for redeeming shares in an Enzyme vault; one is used if you want to redeem all of your shares, and another is used if you want to redeem a specific amount.
import { ComptrollerLib, StandardToken } from'@enzymefinance/protocol';import { providers, BigNumber, Wallet, constants, utils } from'ethers';constprovider=providers.StaticJsonRpcProvider(ethNodeAddress, ethNetwork); constsigner=newWallet(investorsEthPrivateKey, provider);// the vault's address, available on the vault's dashboard in the Enzyme appconstvaultAddress='0x8syweo...';// instantiate the vault token contractconstvaultToken=newStandardToken(vaultAddress, provider);// check the investor's current balanceconstsharesBalance=awaitvaultToken.balanceOf(signer.address);// this is an arbitrary numberconstsharesToRedeem=utils.parseUnits('1',18);// the vault's comptroller address, available on the vault's dashboard in the Enzyme appconstcomptrollerAddress='0x8syweo...'constcomptrollerContract=newComptrollerLib(comptrollerAddress, signer);constredeemTx=sharesBalance.gt(sharesToRedeem) ?comptrollerContract.redeemSharesDetailed.args( sharesToRedeem, [],// additional assets [],// assets to skip. These two parameters are adjustable but most commonly left empty ) :comptrollerContract.redeemShares();constredeemTxReceipt=awaitredeemTx.send();console.log('Pending transaction:',redeemTxReceipt.transactionHash);console.log('Transaction included in block number:',redeemTxReceipt.blockNumber);