Skip to content

eQereum/hardhat-ethers-upgradeable-minimal-clones-campman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Campaign Management Project using Hardhat/Ethers

This project represents deploying of a Campaign Management Project that is upgradeable using OpenZeppelin Transparent Upgradeable Proxy: A proxy with a built in admin and upgrade interface.

In summary, first time you will deploy 3 separate contracts with the following sequence:

  1. Implementation: Contains contracts logic that is the the only contract that will be upgraded every time and admin contract will set this new implementation contract address in TransparentUpgradeableProxy contract.
  2. ProxyAdmin: Has immutable address that will set implementation contract address every time on TransparentUpgradeableProxy contract.
  3. TransparentUpgradeableProxy: Has immutable address that will interact with user and it will delegatecall to implementation contract functions.

Note: Make sure you don't change storage slots order for state variables (if you intent to add new state variables, add it after original ones).

This project also benefits from OpenZeppelin Minimal Clones. To simply and cheaply clone contract functionality in an immutable way, EIP-1167 standard specifies a minimal bytecode implementation that delegates all calls to a known, fixed address.

The exact bytecode of the standard clone contract is this: 0x363d3d373d3d3d363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3 wherein the bytes at indices 10 - 29 (inclusive) are replaced with the 20 byte address of the master functionality contract.

### Clone the Repository
git clone --recursive https://github.com/0xhamedETH/hardhat-ethers-upgradeable-minimal-clones-campman.git your-directory

Install Packages

cd your-directory/ethereum
npm install

Compile

Compile first to create json artifacts in artifacts folder

npx hardhat compile

Test

You can test contracts either separately or totally.

npx hardhat test --network hardhat
npx hardhat test test/FactoryV1.test.js  --network hardhat
npx hardhat test test/Campaign.test.js --network hardhat
npx hardhat test test/Token.test.js --network hardhat
npx hardhat test test/Pool.test.js --network hardhat

Deploy

For this step, you first need to fill .env file with your api keys (Alchemy, ...)

Scripts folder is resposible for deploying contracts.

You can deploy in any network you want but make sure hardhat.config.js contains that network, otherwise add it.

Note: Make sure you fill config section of deploy_Factory_v1.js correctly.

Note: You can change buildPath of output json file containing abi, bytecode, ... .

Deploy FactoryV1:

Before factory contract, 3 separate contracts (Campaign, Token & Pool) wiil deploy first and their addresses will pass as arguments to factory contract to use as master functionality contracts for minimal clone deployment.

npx hardhat run scripts/deploy_Factory_v1.js --network rinkeby

Verify Contracts

Note: Make sure you provide your network explorer apiKey in hardhat.config.js.

  1. Implementation: You need to verify Implementation contract by yourself to be able to see the source code on Network Explorer (in this case Rinkeby Testnet Explorer: Etherscan)
npx hardhat verify --network rinkeby implementationContractAddress
  1. TransparentUpgradeableProxy: To verify this contract as proxy, you need to follow these steps:
  • Go to Etherscan and search the TransparentUpgradeableProxy contract address
  • Go to Contract tab > More Options > Is this a proxy? > Verify
  1. ProxyAdmin: This contract is already verified.

Upgrade to FactoryV2

For upgrade, make sure you fill proxyAddress in config section of upgrade_Factory_v2 script.

npx hardhat run scripts/upgrade_Factory_v2.js --network rinkeby

After this, 2 transactions will send:

1st to deploy new Implementation contract

2nd to call upgrade function of ProxyAdmin contract.

Give a Star! ⭐

If you like or use this project, please give it a star. Thanks !!!