The next step is to call the depositAndAllocate function on the MultiAccount Contract so the bot can start trading with the funds provided to the sub-account. The input parameters will be the as follows:
subAccount: the address of the sub-account we created here.
amount: Tokens to deposit (in Wei).
First we have to approve the collateralContract to transfer up to a specified amount of tokens on behalf of the main wallet, then we'll call the depositAndAllocateForAccount function on the multiAccountContract, which forwards the call to the SYMM Diamond Facet with the input parameters.
asyncfunctiondepositAndAllocateForAccount(subAccount, amount) {try {//Approving tokenslet nonce =awaitweb3.eth.getTransactionCount(account.address,'latest');console.log(`Approving ${amount} tokens for the multi-account contract...`);constapproveTx=collateralContract.methods.approve(config.MULTI_ACCOUNT_ADDRESS, amount);constapproveGas=awaitapproveTx.estimateGas({ from:account.address });constapproveGasPrice=awaitweb3.eth.getGasPrice(); awaitapproveTx.send({ from:account.address, gas: approveGas, gasPrice: approveGasPrice, nonce: nonce });console.log(`Approval successful. Proceeding to deposit and allocate for account ${subAccount}...`); nonce++;//Depositing and AllocatingconstdepositTx=multiAccountContract.methods.depositAndAllocateForAccount(subAccount, amount);constdepositGas=awaitdepositTx.estimateGas({ from:account.address });let depositGasPrice =awaitweb3.eth.getGasPrice();constdepositReceipt=awaitdepositTx.send({ from:account.address, gas: depositGas, gasPrice: depositGasPrice, nonce: nonce });console.log("Deposit and allocation successful!"); } catch (error) {console.error("An error occurred during the deposit and allocation process:", error); }}