Creating a Sub-Account

Creating a Sub-Account for Trading

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:

Project NameVersionHedger StateChainSYMMIO AddressCollateral AddressMultiAccount AddressPartyBAddressPartyB API AddressMain SubgraphAnalytics SubgraphParties SubgraphFunding Rate SubgraphEvents SubgraphMuon

Core

0.8.2

Active

Blast

0x3d17f073cCb9c3764F105550B0BCF9550477D266

0x4300000000000000000000000000000000000003

0xd6ee1fd75d11989e57B57AA6Fd75f558fBf02a5e

0xECbd0788bB5a72f9dFDAc1FFeAAF9B7c2B26E456

blast-hedger.rasa.capital

crypto-v3-shield.deus.finance/v1/ crypto-v3-shield2.deus.finance/v1/

IntentX (Blast)

0.8.2

Active

Blast

0x3d17f073cCb9c3764F105550B0BCF9550477D266

0x4300000000000000000000000000000000000003

0x083267D20Dbe6C2b0A83Bd0E601dC2299eD99015

0xECbd0788bB5a72f9dFDAc1FFeAAF9B7c2B26E456

blast-hedger.rasa.capital

https://crypto-v3-shield.deus.finance/v1/' https://crypto-v3-shield2.deus.finance/v1/

Thena V3

0.8.2

Active

BNB

0x9A9F48888600FC9c05f11E03Eab575EBB2Fc2c8f

0x55d398326f99059ff775485246999027b3197955

0x650a2D6C263A93cFF5EdD41f836ce832F05A1cF3

0x9fa01a45E245015fA685F21763e60C60832Ed2D6

crypto-v3-shield.deus.finance/v1/ crypto-v3-shield2.deus.finance/v1/

IntentX

0.8.2

Active

Base

0x91Cf2D8Ed503EC52768999aA6D8DBeA6e52dbe43

0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913

0x8Ab178C07184ffD44F0ADfF4eA2ce6cFc33F3b86

0x9206D9d8F7F1B212A4183827D20De32AF3A23c59

intentx-shield.deus.finance intentx-shield1.deus.finance

Based

0.8.2

Active

Base

0x91Cf2D8Ed503EC52768999aA6D8DBeA6e52dbe43

0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913

0x1c03B6480a4efC2d4123ba90d7857f0e1878B780

0x9206D9d8F7F1B212A4183827D20De32AF3A23c59

base-hedger82.rasa.capital

intentx-shield.deus.finance intentx-shield1.deus.finance

CloverField (Polygon)

0.8.2

Pending

Polygon

0x976c87Cd3eB2DE462Db249cCA711E4C89154537b

0x50E88C692B137B8a51b6017026Ef414651e0d5ba

0xffE2C25404525D2D4351D75177B92F18D9DaF4Af

0x5044238ea045585C704dC2C6387D66d29eD56648

hedger.deus.finance

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:

WALLET_PRIVATE_KEY=
WALLET_ADDRESS=
PROVIDER_URL=
MUON_URL=

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();
const config = require('./symmconfig'); //using a separate config file for contract addresses
const { Web3 } = require('web3');
const { multiAccountABI } = require('./abi/MultiAccount');

const web3 = new Web3(new Web3.providers.HttpProvider(process.env.PROVIDER_URL));

const multiAccountAddress = config.MULTI_ACCOUNT_ADDRESS;
const multiAccount = new web3.eth.Contract(multiAccountABI, multiAccountAddress);

const account = 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.

async function addAccount(accountName) {
  if (!accountName) {
    console.error("Account name is not provided.");
    return;
  }

  try {
  //Gas Estimates
    const currentGasPrice = await web3.eth.getGasPrice();
    const increasedGasPriceBigInt = BigInt(currentGasPrice) * BigInt(120) / BigInt(100);
    const gasEstimate = await multiAccount.methods.addAccount(accountName).estimateGas({ from: account.address });
    const gasEstimateBigInt = BigInt(gasEstimate);
    const gasLimitWithBuffer = gasEstimateBigInt + (gasEstimateBigInt * BigInt(20) / BigInt(100));

    const receipt = await multiAccount.methods.addAccount(accountName).send({
      from: account.address,
      gas: gasLimitWithBuffer.toString(), 
      gasPrice: increasedGasPriceBigInt.toString()
    });

    console.log("Account Creation Successful. Transaction hash: ", receipt.transactionHash);

    if (receipt.events.AddAccount) {
      const event = receipt.events.AddAccount.returnValues;
      console.log("Account Created. Address: ", event.account);
      return event.account;
    } else {
      console.log("No AddAccount event found.");
    }
  } catch (error) {
    console.error("Failed to add account:", error);
  }
}

This function creates a sub-account and returns the address.

Last updated

Logo

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