Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding deployment scripts #34

Merged
merged 15 commits into from
Oct 24, 2024
Merged
9 changes: 1 addition & 8 deletions contracts/contribute/Contributors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,13 @@ contract Contributors {
mapping(address => bool) public mapContributeAgents;

/// @dev Contributors initializer.
/// @param _manager Manager address.
function initialize(address _manager) external{
function initialize() external{
// Check for already initialized
if (owner != address(0)) {
revert AlreadyInitialized();
}

// Check for zero address
if (_manager == address(0)) {
revert ZeroAddress();
}

owner = msg.sender;
manager = _manager;
Comment on lines -71 to -84
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cyclic dependency, need to deploy blanc and change the manager later.

}

/// @dev Changes the contributors implementation contract address.
Expand Down
157 changes: 143 additions & 14 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require("@nomicfoundation/hardhat-toolbox");

const ALCHEMY_API_KEY_MAINNET = process.env.ALCHEMY_API_KEY_MAINNET;
const ALCHEMY_API_KEY_MATIC = process.env.ALCHEMY_API_KEY_MATIC;
const ALCHEMY_API_KEY_GOERLI = process.env.ALCHEMY_API_KEY_GOERLI;
const ALCHEMY_API_KEY_MUMBAI = process.env.ALCHEMY_API_KEY_MUMBAI;
const ALCHEMY_API_KEY_SEPOLIA = process.env.ALCHEMY_API_KEY_SEPOLIA;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing the hardhat config and adding more chains

const ALCHEMY_API_KEY_AMOY = process.env.ALCHEMY_API_KEY_AMOY;
let TESTNET_MNEMONIC = process.env.TESTNET_MNEMONIC;

const accounts = {
Expand All @@ -32,8 +32,10 @@ if (!TESTNET_MNEMONIC) {
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
const POLYGONSCAN_API_KEY = process.env.POLYGONSCAN_API_KEY;
const GNOSISSCAN_API_KEY = process.env.GNOSISSCAN_API_KEY;
const CHIADOSCAN_API_KEY = "10200";
const ARBISCAN_API_KEY = process.env.ARBISCAN_API_KEY;
const OPSCAN_API_KEY = process.env.OPSCAN_API_KEY;
const BASESCAN_API_KEY = process.env.BASESCAN_API_KEY;
const CELOSCAN_API_KEY = process.env.CELOSCAN_API_KEY;

module.exports = {
networks: {
Expand All @@ -55,31 +57,85 @@ module.exports = {
accounts: accounts,
chainId: 100,
},
goerli: {
url: "https://eth-goerli.g.alchemy.com/v2/" + ALCHEMY_API_KEY_GOERLI,
arbitrumOne: {
url: "https://arb1.arbitrum.io/rpc",
accounts: accounts,
chainId: 5,
chainId: 42161,
},
polygonMumbai: {
url: "https://polygon-mumbai.g.alchemy.com/v2/" + ALCHEMY_API_KEY_MUMBAI,
optimistic: {
url: "https://optimism.drpc.org",
accounts: accounts,
chainId: 10,
},
base: {
url: "https://mainnet.base.org",
accounts: accounts,
chainId: 8453,
},
celo: {
url: "https://forno.celo.org",
accounts: accounts,
chainId: 42220,
},
mode: {
url: "https://mainnet.mode.network",
accounts: accounts,
chainId: 34443,
},
sepolia: {
url: "https://eth-sepolia.g.alchemy.com/v2/" + ALCHEMY_API_KEY_SEPOLIA,
accounts: accounts,
chainId: 11155111,
},
polygonAmoy: {
url: "https://polygon-amoy.g.alchemy.com/v2/" + ALCHEMY_API_KEY_AMOY,
accounts: accounts,
chainId: 80002
},
chiado: {
url: "https://rpc.chiadochain.net",
accounts: accounts,
chainId: 10200
},
optimistic: {
url: "https://optimism.drpc.org",
arbitrumSepolia: {
url: "https://sepolia-rollup.arbitrum.io/rpc",
accounts: accounts,
chainId: 10,
chainId: 421614,
},
optimisticSepolia: {
url: "https://sepolia.optimism.io",
accounts: accounts,
chainId: 11155420,
},
baseSepolia: {
url: "https://sepolia.base.org",
accounts: accounts,
chainId: 84532,
},
celoAlfajores: {
url: "https://alfajores-forno.celo-testnet.org",
accounts: accounts,
chainId: 44787,
},
modeSepolia: {
url: "https://sepolia.mode.network",
accounts: accounts,
chainId: 919,
},
hardhat: {
allowUnlimitedContractSize: true
},
},
etherscan: {
customChains: [
{
network: "polygonAmoy",
chainId: 80002,
urls: {
apiURL: "https://api-amoy.polygonscan.com/api",
browserURL: "https://amoy.polygonscan.com/"
}
},
{
network: "chiado",
chainId: 10200,
Expand All @@ -96,6 +152,14 @@ module.exports = {
browserURL: "https://gnosisscan.io/"
},
},
{
network: "arbitrumSepolia",
chainId: 421614,
urls: {
apiURL: "https://api-sepolia.arbiscan.io/api",
browserURL: "https://sepolia.arbiscan.io"
},
},
{
network: "optimistic",
chainId: 10,
Expand All @@ -104,15 +168,80 @@ module.exports = {
browserURL: "https://optimistic.etherscan.io"
},
},
{
network: "optimisticSepolia",
chainId: 11155420,
urls: {
apiURL: "https://api-sepolia-optimism.etherscan.io/api",
browserURL: "https://sepolia-optimistic.etherscan.io"
},
},
{
network: "base",
chainId: 8453,
urls: {
apiURL: "https://api.basescan.org/api",
browserURL: "https://basescan.org"
},
},
{
network: "baseSepolia",
chainId: 84532,
urls: {
apiURL: "https://base-sepolia.blockscout.com/api",
browserURL: "https://base-sepolia.blockscout.com/"
},
},
{
network: "celo",
chainId: 42220,
urls: {
apiURL: "https://api.celoscan.io/api",
browserURL: "https://explorer.celo.org/"
},
},
{
network: "celoAlfajores",
chainId: 44787,
urls: {
apiURL: "https://api-alfajores.celoscan.io/api",
browserURL: "https://alfajores-blockscout.celo-testnet.org/"
},
},
{
network: "mode",
chainId: 34443,
urls: {
apiURL: "https://explorer.mode.network/api",
browserURL: "https://explorer.mode.network"
},
},
{
network: "modeSepolia",
chainId: 919,
urls: {
apiURL: "https://sepolia.explorer.mode.network/api",
browserURL: "https://sepolia.explorer.mode.network"
},
},
],
apiKey: {
mainnet: ETHERSCAN_API_KEY,
polygon: POLYGONSCAN_API_KEY,
gnosis: GNOSISSCAN_API_KEY,
goerli: ETHERSCAN_API_KEY,
polygonMumbai: POLYGONSCAN_API_KEY,
chiado: CHIADOSCAN_API_KEY,
arbitrumOne: ARBISCAN_API_KEY,
optimistic: OPSCAN_API_KEY,
base: BASESCAN_API_KEY,
celo: CELOSCAN_API_KEY,
sepolia: ETHERSCAN_API_KEY,
polygonAmoy: POLYGONSCAN_API_KEY,
chiado: GNOSISSCAN_API_KEY,
arbitrumSepolia: ARBISCAN_API_KEY,
optimisticSepolia: OPSCAN_API_KEY,
baseSepolia: OPSCAN_API_KEY,
celoAlfajores: CELOSCAN_API_KEY,
mode: OPSCAN_API_KEY,
modeSepolia: OPSCAN_API_KEY,
}
},
solidity: {
Expand Down
75 changes: 75 additions & 0 deletions scripts/deployment/deploy_07_contributors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*global process*/

const { ethers } = require("hardhat");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment is tested

const { LedgerSigner } = require("@anders-t/ethers-ledger");

async function main() {
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
let parsedData = JSON.parse(dataFromJSON);
const useLedger = parsedData.useLedger;
const derivationPath = parsedData.derivationPath;
const providerName = parsedData.providerName;
const gasPriceInGwei = parsedData.gasPriceInGwei;

let networkURL = parsedData.networkURL;
if (providerName === "polygon") {
if (!process.env.ALCHEMY_API_KEY_MATIC) {
console.log("set ALCHEMY_API_KEY_MATIC env variable");
}
networkURL += process.env.ALCHEMY_API_KEY_MATIC;
} else if (providerName === "polygonAmoy") {
if (!process.env.ALCHEMY_API_KEY_AMOY) {
console.log("set ALCHEMY_API_KEY_AMOY env variable");
return;
}
networkURL += process.env.ALCHEMY_API_KEY_AMOY;
}

const provider = new ethers.providers.JsonRpcProvider(networkURL);
const signers = await ethers.getSigners();

let EOA;
if (useLedger) {
EOA = new LedgerSigner(provider, derivationPath);
} else {
EOA = signers[0];
}
// EOA address
const deployer = await EOA.getAddress();
console.log("EOA is:", deployer);

// Transaction signing and execution
console.log("7. EOA to deploy Contributors");
console.log("You are signing the following transaction: Contributors.connect(EOA).deploy()");
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei");
const Contributors = await ethers.getContractFactory("Contributors");
const contributors = await Contributors.connect(EOA).deploy({ gasPrice });
const result = await contributors.deployed();

// Transaction details
console.log("Contract deployment: Contributors");
console.log("Contract address:", contributors.address);
console.log("Transaction:", result.deployTransaction.hash);

// Wait for half a minute for the transaction completion
await new Promise(r => setTimeout(r, 30000));

// Writing updated parameters back to the JSON file
parsedData.contributorsAddress = contributors.address;
fs.writeFileSync(globalsFile, JSON.stringify(parsedData));

// Contract verification
if (parsedData.contractVerification) {
const execSync = require("child_process").execSync;
execSync("npx hardhat verify --network " + providerName + " " + contributors.address, { encoding: "utf-8" });
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
80 changes: 80 additions & 0 deletions scripts/deployment/deploy_08_contributors_proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*global process*/

const { ethers } = require("hardhat");
const { LedgerSigner } = require("@anders-t/ethers-ledger");

async function main() {
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
let parsedData = JSON.parse(dataFromJSON);
const useLedger = parsedData.useLedger;
const derivationPath = parsedData.derivationPath;
const providerName = parsedData.providerName;
const gasPriceInGwei = parsedData.gasPriceInGwei;
const contributorsAddress = parsedData.contributorsAddress;

let networkURL = parsedData.networkURL;
if (providerName === "polygon") {
if (!process.env.ALCHEMY_API_KEY_MATIC) {
console.log("set ALCHEMY_API_KEY_MATIC env variable");
}
networkURL += process.env.ALCHEMY_API_KEY_MATIC;
} else if (providerName === "polygonAmoy") {
if (!process.env.ALCHEMY_API_KEY_AMOY) {
console.log("set ALCHEMY_API_KEY_AMOY env variable");
return;
}
networkURL += process.env.ALCHEMY_API_KEY_AMOY;
}

const provider = new ethers.providers.JsonRpcProvider(networkURL);
const signers = await ethers.getSigners();

let EOA;
if (useLedger) {
EOA = new LedgerSigner(provider, derivationPath);
} else {
EOA = signers[0];
}
// EOA address
const deployer = await EOA.getAddress();
console.log("EOA is:", deployer);

// Assemble the contributors proxy data
const contributors = await ethers.getContractAt("Contributors", contributorsAddress);
const proxyData = contributors.interface.encodeFunctionData("initialize", []);

// Transaction signing and execution
console.log("8. EOA to deploy ContributorsProxy");
console.log("You are signing the following transaction: ContributorsProxy.connect(EOA).deploy()");
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei");
const ContributorsProxy = await ethers.getContractFactory("ContributorsProxy");
const contributorsProxy = await ContributorsProxy.connect(EOA).deploy(contributorsAddress, proxyData, { gasPrice });
const result = await contributorsProxy.deployed();

// Transaction details
console.log("Contract deployment: ContributorsProxy");
console.log("Contract address:", contributorsProxy.address);
console.log("Transaction:", result.deployTransaction.hash);

// Wait for half a minute for the transaction completion
await new Promise(r => setTimeout(r, 30000));

// Writing updated parameters back to the JSON file
parsedData.contributorsProxyAddress = contributorsProxy.address;
fs.writeFileSync(globalsFile, JSON.stringify(parsedData));

// Contract verification
if (parsedData.contractVerification) {
const execSync = require("child_process").execSync;
execSync("npx hardhat verify --constructor-args scripts/deployment/verify_08_contributors_proxy.js --network " + providerName + " " + contributorsProxy.address, { encoding: "utf-8" });
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading
Loading