MultiAccount Deployment Guide
This document outlines the required steps and responsibilities for deploying the MultiAccount contract.
Responsibility and Security The full responsibility for the deployment and ongoing management of the MultiAccount contract lies with the deploying entity. To ensure the integrity and security of the contract, please take the following actions:
Conduct thorough audits of the contract code.
Implement robust security checks.
Ensure regular maintenance and monitoring of the deployed contract.
Deployment of Latest Version It is essential to deploy the latest version of the MultiAccount contract. The most current version can be found at the following link: MultiAccount Contract
Please note that the MultiAccount contract available in this repository is a sample code. You are free to modify or customize the code to meet your specific requirements. However, be aware that any modifications or changes to the contract may extend the time required for the registration process, as the SYMMIO team will need to thoroughly review and approve the changes.
Transfer of Admin Roles and ProxyAdmin Ownership Upon successful deployment, the following steps must be completed to ensure secure management of the contract:
Transfer the admin roles to the appropriate entity.
Transfer ownership of the ProxyAdmin to a 3-day timelock contract for added security.
These measures are necessary to safeguard the contract against unauthorized access or modifications.
Proposal to SYMMIO Team After deploying the contract and completing the necessary security measures, a formal proposal must be submitted to the SYMMIO team. The proposal should request that the deployed MultiAccount contract address be registered in the SYMMIO Core Contracts. If any modifications have been made to the original sample contract, please note that the registration process may take longer due to the required review of the changes by the SYMMIO team.
Prerequisites
Install Node.js and npm.
Install Hardhat in your project directory:
npm install --save-dev hardhat
Install Typescript and
ts-node
:npm install --save-dev typescript ts-node
Step 1: Setting up Hardhat
Initialize a new Hardhat project:
Follow the prompts to create a sample project.
To run a TypeScript deployment script with Hardhat, you'll need to make sure your environment is set up correctly for TypeScript execution.
TypeScript Configuration:
Ensure you have a tsconfig.json
file in your project root. This file configures options for TypeScript in your project. Hardhat automatically generates this for you if you initialize your project with TypeScript support:
Step 2: Adding the MultiAccount Contract to our Project
Once you have your TypeScript configuration ready, the next step in setting up your deployment is to incorporate the MultiAccount contract and its essential interfaces. You'll need to place the contracts and its associated interfaces within the /contracts
directory of your project. These components are available in the SYMMIO's protocol-core GitHub repository, within the /contracts/multiAccount
and /contracts/interfaces
directories. Ensure the following files are added to your project:
Contracts: (/contracts/multiAccount
)
MultiAccount.sol
: The primary contract for managing multiple accounts.SymmioPartyA.sol
: This is used for deploying user sub-accounts through the CREATE-2 opcode, offering a more efficient and flexible account creation process.
Interfaces: (/contracts/interfaces
)
IMultiAccount.sol
: Interface for the MultiAccount contract.ISymmio.sol
: SYMMIO protocol interface.ISymmioPartyA.sol
: Interface specific to the SymmioPartyA contract.
Step 3: Installing Required Packages
The MultiAccount.sol contract imports from earlier versions of Openzeppelin's libraries. We'll install @openzeppelin/contracts@^4.9.0
and @openzeppelin/contracts-upgradeable@^4.7.3
Open your terminal or command prompt, navigate to your project's root directory and run the following commands:
Install OpenZeppelin Contracts:
This command installs the OpenZeppelin Contracts package at version
4.9.0
or the latest minor version within the4.9.x
range.Install OpenZeppelin Contracts-Upgradeable:
After running these commands, your package.json
file will be automatically updated to reflect these dependencies and their versions under the dependencies
section. It should look something like this:
Step 4: Saving the Deployed Address
After successful deployment of the MultiAccount
and SymmioPartyA
contracts, it's helpful to track the deployed contract addresses for future deployments. We'll incorporate a utility module specifically designed for saving and loading these critical addresses. This approach ensures that when the MultiAccount contract is initialized, it can readily access the protocol address (symmioAddress
) and the bytecode for the SymmioPartyA
contract. The /utilty/file.ts
script handles this for us, and we'll incorporate it into our main deployment script.
To initiate our first deployment, create an addresses.json
file that contains the contract addresses needed to initialize the MultiAccount
contract. Use the contract addresses to populate the fields according to the specific chain you'd like to deploy on.
Step 5: Installing Dependencies for the Deployment Script
Before moving on to the actual deployment, we'll be installing and using hardhat-ethers
and hardhat-upgrades
. The ethers.js
library is designed to provide a comprehensive yet compact toolkit for interacting with the Ethereum Blockchain and its vast ecosystem, serving as the foundation of our deployment scripts. hardhat-upgrades
, is a plugin aimed at streamlining the deployment and upgrade process of smart contracts through proxies.
Run this command in the command prompt:
Step 6: Writing the Deployment Script
First import the dependencies we installed in Step 4:
Then import the file utility for loading and saving addresses:
The deployment script should perform the following:
Getting Signers: The script starts by retrieving the list of signers (accounts) available from the node it's connected to, using Hardhat's
ethers
plugin. It assumes the first account (deployer
) is the one to be used for deploying the contracts. The private key for the deployer account is declared inhardhat.config.ts
Loading Contract Deployments: It attempts to load previously deployed addresses from a function
loadAddresses()
Contract Factory for
SymmioPartyA
: It creates a contract factory forSymmioPartyA
. This factory is used to deploy new instances of the contract.Deploying
MultiAccount
as Upgradeable: It proceeds to deployMultiAccount
in an upgradeable manner using OpenZeppelin'supgrades
plugin. The deployment uses a proxy pattern where the actual contract logic (implementation) and state are separated. The contract initializes with:
admin
: theadmin
address.symmioAddress
: the SYMMIO contract address.accountImplementation_
: the bytecode ofSymmioPartyA
Logging Deployment Addresses: After deployment, it logs the addresses related to the deployed upgradeable contract, including the proxy address, the admin address and the implementation address.
Saving Addresses: The script then updates the
addresses.json
with the newmultiAccountAddress
for reference in future deployments.Verification Process: It attempts to verify the deployed contract on a blockchain explorer. The verification process is delayed by 15 seconds before using Hardhat's
verify:verify
task to submit verification information.Error Handling and Script Completion: The script ends with a basic structure to handle promise resolution, logging any errors encountered and exiting the process accordingly.
Step 7: Configuring the Deployment Script for Specified Chains
Deploying the MultiAccount contract requires the deployment account's private and public keys. Due to their sensitive nature, its important to integrate dotenv
with our script. dotenv
facilitates the safe storage and access of private variables, like the deployment account's keys, through an environment file (*.env
).
Create a .env
File
In the root of your project, create a file named .env
. Inside this file, you'll define environment variables. For example:
In our config file, we'll declare these as:
Networks Configuration
Each network has specific settings that tell Hardhat where to deploy the contracts, which accounts to use, and any network-specific options like gas prices. Here are examples for various chains:
URL: Each network has a
url
that specifies the JSON-RPC endpoint to connect to. This is essential for deploying to that specific network.Accounts: Specifies which accounts to use for transactions on the network. This can be a list of private keys or a single key.
Explorer Configuration
This part of the configuration is essential for verifying contract deployments on different networks, allowing you to interact with your contracts through blockchain explorers.
API Key: Each entry under
apiKey
is crucial for authentication when using the Etherscan-like services to verify contracts. The API key can be obtained from creating an account with an explorer.Custom Chains: Configuration for custom networks (not standard like Ethereum Mainnet or Ropsten) to ensure that the Hardhat Etherscan plugin knows how to interact with these networks' explorers.
An example hardhat-config.ts
file can be found at this Github repository. Ensure you install the necessary dependency versions if you're using this method.
Step 8: Deploying the MultiAccount contract
To run the deployment script, enter the following command in the terminal, where {chain}
is the desired deployment chain:
Troubleshooting
It might be necessary to set a gasPrice
to ensure timely deployments. This can be customized in the hardhat config file:
Last updated