Depositing and Allocating Tokens

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.

async function depositAndAllocateForAccount(subAccount, amount) {
  try {
  //Approving tokens
      let nonce = await web3.eth.getTransactionCount(account.address, 'latest');
      console.log(`Approving ${amount} tokens for the multi-account contract...`);
      const approveTx = collateralContract.methods.approve(config.MULTI_ACCOUNT_ADDRESS, amount);
      const approveGas = await approveTx.estimateGas({ from: account.address });
      const approveGasPrice = await web3.eth.getGasPrice(); 

      await approveTx.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 Allocating
      const depositTx = multiAccountContract.methods.depositAndAllocateForAccount(subAccount, amount);
      const depositGas = await depositTx.estimateGas({ from: account.address });
      let depositGasPrice = await web3.eth.getGasPrice();
      const depositReceipt = await depositTx.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);
  }
}

Last updated

Logo

All rights to the people (c) 2023 Symmetry Labs A.G.