In order to place trades using a SYMM frontend solution or otherwise, it's necessary to create a sub-account using a MultiAccount contract that is whitelisted to interact with the hedger. All MultiAccount contract addresses are listed in the table below:
Users are required to provide a name an input parameter when they create a sub-account. All positions on a sub-account are in CROSS, but positions between sub-accounts are ISOLATED. If you're creating a bot that hedges against the impermanent loss an LP might incur, it could be useful to create a sub-account for each hedged position.
First, we'll define our environment-dependent variables in a .env file like so:
The PROVIDER_URL field should contain the Ankr RPC URL and the appropriate MUON_URL can be found here.
First we'll define the contract that we want to interact with using Web3. In this case it's the MultiAccount contract. We create a new web3 Contract with the ABI provided in the /abi directory and the multiAccountAddress. We'll also use our WALLET_PRIVATE_KEY defined in the environment to set up our web3 account.
require('dotenv').config();constconfig=require('./symmconfig'); //using a separate config file for contract addressesconst { Web3 } =require('web3');const { multiAccountABI } =require('./abi/MultiAccount');constweb3=newWeb3(newWeb3.providers.HttpProvider(process.env.PROVIDER_URL));constmultiAccountAddress=config.MULTI_ACCOUNT_ADDRESS;constmultiAccount=newweb3.eth.Contract(multiAccountABI, multiAccountAddress);constaccount=web3.eth.accounts.privateKeyToAccount(process.env.WALLET_PRIVATE_KEY);web3.eth.accounts.wallet.add(account);
Adding a Sub-Account
The addAccount() function takes one parameter, the accountName, here we are simply calling the function on the MultiAccount contract and logging information related to the transaction.