Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

amun/set-v2-strategies-deployments

 
 

Repository files navigation

set-v2-strategies-deployments

This repository manages SetProtocol V2 Strategies contract deployments using the hardhat-deploy plugin. Each deployment is tracked and recorded by network in a deployments/outputs file.

These deployments are peripheral to the core SetProtocol system and include things like SetToken strategy contracts, example SetToken instances and other helper contracts.

All proposed deployments should:

  • deploy to HardhatEVM
  • have unit tests which check the correctness of state variables set in the constructor
  • be deployed to a testnet have its contract code verified on a block explorer like Etherscan

Chains

Several networks are supported and each one is managed in its own folder.

There are dedicated environments for:

  • Ethereum (mainnet, kovan)
  • Polygon (mainnet-polygon, mumbai, goerli)
  • Optimism (mainnet, kovan)
  • Arbitrum (mainnet, rinkeby)
  • Avalanche (mainnet, fuji)

To run commands like test, deploy, navigate to the folder for the chain you're working with.

Install

Run these commands in the project root.

cp .env.default .env
yarn
cd <chain_folder> // e.g ethereum, polygon, etc

Test (deployment)

We use the hardhat network forking feature to simulate and test deployments. You'll need a valid alchemy.com project id to run these.

yarn clean-dev-deployment
yarn deploy:local

Test (unit)

yarn test

Example Testnet Deployment (Kovan)

Fill in the following fields in your .env file:

Run:

yarn deploy:kovan
yarn etherscan:kovan

(If etherscan fails, see the Etherscan section below).

Usage Guide

New deployments have at least two (and sometimes 3) phases:

Phase Pull Request / Op Pre-requisites
1 Deployment script PR with tests Code merged at set-v2-strategies & published to npm
2 Executed deployment PR Phase 1 complete
3 Activate new components via Gnosis multisig Phase 2 complete & deployment is production

Deployment scripts

Create the new files you'll need by running the create:deployment command.

This will generate files numbered for the latest stage in the deploy, deployments, and test folders.

$ yarn create:deployment my_deployment_name

New deployment files at:
> .../ethereum/deploy/001_my_deployment_name.ts
> .../ethereum/deployments/constants/001_my_deployment_name.ts
> .../ethereum/test/deploys/001_my_deployment_name.spec.ts

Then, find the most recent scripts and tests which are suitable templates for your deployment and copy/paste them into the new files, adapting as necessary.

💡 Pro Tips 💡:

  • Verify new contracts on Kovan to catch any contract verification issues early in the process.
  • Useful helpers can be found in outputHelper.ts and deployUtils.ts
  • Addresses for on-chain dependencies can be found in dependencies.ts

Executing Deployments

Step Action Command
1 Checkout master, git pull, and run yarn
2 Checkout a new branch git checkout -b alex/deploy_....
3 Deploy to staging_mainnet yarn deploy:staging_mainnet
4 Verify deployment on Etherscan yarn etherscan:staging_mainnet
5 Check contracts' read/write endpoints in Etherscan's UI
6 Deploy to production yarn deploy:production
7 Verify deployment on Etherscan yarn etherscan:production
8 Commit automated changes made to outputs logs
9 Open PR documenting the addresses of new components

Multisig Operations (deferred transactions)

When modules, integrations, and price oracles are added to Set in production, @asoong and @felix2feng enable them via multisig with Gnosis Safe wallets online.

Deployment scripts should save the tx data generated for these deferred transactions using a flow similar to that used in deployUtils#addIntegrationToRegistry.

Resources:

Semantic Release

This repository uses semantic-release to automatically publish in CI on merge to master. We only publish metadata about staging and production deployments and releases are only necessary when there are changes to the network/deployments/outputs production or staging files.

Use the following naming convention in your PR descriptions

  • chore: no release: chore(scripts): description
    • example: chore(scripts): DelegatedBaseManager Optimism deploy scripts
  • feature release (e.g 1.1.0 -> 1.2.0): feat(deploy): description
    • example: feat(deploy): Deploy DelegatedBaseManager to Optimism production

Chain resources

Ethereum

Polygon

Etherscan verification

Set ETHERSCAN_API_KEY to a valid Etherscan API key in .env

After deploying, run the command for your network:

yarn etherscan:kovan
yarn etherscan:staging_mainnet
yarn etherscan:production

When Etherscan fails...

Verification may fail because of solidity issue 9573 which causes Etherscan to generate different bytecode from a minimized contract set than what was generated locally with all contracts in the project. The error message says:

Compiling your contract excluding unrelated contracts did not produce identical bytecode.
...
NomicLabsHardhatPluginError: Source code exceeds max accepted (500k chars) length

To get around this, use the compile:one task to compile your target contract in isolation.

In a deployment script, right before the problematic contract is deployed:

// Compile in isolation for Etherscan verification bug
await bre.run("set:compile:one", { contractName: "GeneralIndexModule"});

... or a the command line:

yarn compile:one GeneralIndexModule
yarn deploy:kovan
yarn etherscan:kovan

Deployment creation utility

yarn create:deployment

The create:deployment command creates standard files necessary for each new deployment. It takes a deployment name as an argument and automatically prefixes it with the next increment of the deployment sequence.

$ yarn create:deployment my_deployment_name

New deployment files at:
> .../ethereum/deploy/001_my_deployment_name.ts
> .../ethereum/deployments/constants/001_my_deployment_name.ts
> .../ethereum/test/deploys/001_my_deployment_name.spec.ts

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.3%
  • Other 1.7%