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

feat: PT-3891 add upgrade executor #262

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ node_modules
dist
types/**/*.ts
**/types/**/*.ts
**/types
**/types
.vscode
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"tokens-minimal",
"tokens-test",
"transfer-manager",
"transfer-proxy"
"transfer-proxy",
"upgrade-executor"
],
"npmClient": "yarn",
"useWorkspaces": true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"tokens-minimal",
"tokens-test",
"transfer-manager",
"transfer-proxy"
"transfer-proxy",
"upgrade-executor"
]
},
"scripts": {
Expand Down
13 changes: 13 additions & 0 deletions upgrade-executor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

cache-zk
artifacts-zk
3 changes: 3 additions & 0 deletions upgrade-executor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Upgrade Executor

Upgrade Executor contract, that will eventually become the owner of all other protocol contracts
64 changes: 64 additions & 0 deletions upgrade-executor/deploy/001_deploy_UpgradeExecutor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';

type NetworkSettings = {
admin: string;
executors: string[];
}

const mainnet : NetworkSettings = {
admin: "0x0000000000000000000000000000000000000000",
executors: []
}
const goerli : NetworkSettings = {
admin: "0x0000000000000000000000000000000000000000",
executors: []
}
const def : NetworkSettings = {
admin: "0x0000000000000000000000000000000000000000",
executors: [],
}

let settings: any = {
"default": def,
"mainnet": mainnet,
"goerli": goerli
};

function getSettings(network: string) : NetworkSettings {
if (settings[network] !== undefined) {
return settings[network];
} else {
return settings["default"];
}
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`deploying contracts on network ${hre.network.name}`)

const { deploy } = hre.deployments;
const { deployer } = await hre.getNamedAccounts();

console.log("deploying contracts with the account:", deployer);

let settings = getSettings(hre.network.name)
if (settings.admin === "0x0000000000000000000000000000000000000000") {
settings.admin = deployer;
}
console.log(`using settings`, settings)

const receipt = await deploy("UpgradeExecutor", {
from: deployer,
log: true,
autoMine: true,
});

const UpgradeExecutor = await hre.ethers.getContractFactory("UpgradeExecutor");
const upgradeExecutor = await UpgradeExecutor.attach(receipt.address);

const initTx = await upgradeExecutor.initialize(settings.admin, settings.executors);
await initTx.wait()

};
export default func;
func.tags = ['all'];
228 changes: 228 additions & 0 deletions upgrade-executor/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-solc';
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "hardhat-deploy";
import "@openzeppelin/hardhat-upgrades";
import "@nomiclabs/hardhat-truffle5";

import type {
HttpNetworkUserConfig,
} from "hardhat/types";
import * as dotenv from "dotenv";
import * as os from "os";
import * as path from "path";
import fs from "fs";

dotenv.config();

function getConfigPath() {
const configPath = process.env["NETWORK_CONFIG_PATH"];
if (configPath) {
return configPath;
} else {
return path.join(os.homedir(), ".ethereum");
}
}

function getNetworkApiKey(name: string): string {
const configPath = path.join(getConfigPath(), name + ".json");
if (fs.existsSync(configPath)) {
var json = require(configPath);
if (!!json.verify) {
return json.verify.apiKey;
}
else {
return "xyz"
}
} else {
// File doesn't exist in path
return "xyz";
}
}

function getNetworkApiUrl(name: string): string {
const configPath = path.join(getConfigPath(), name + ".json");
if (fs.existsSync(configPath)) {
var json = require(configPath);
return json.verify.apiUrl;
} else {
// File doesn't exist in path
return "";
}
}

function getNetworkExplorerUrl(name: string): string {
const configPath = path.join(getConfigPath(), name + ".json");
if (fs.existsSync(configPath)) {
var json = require(configPath);
return json.verify.explorerUrl;
} else {
// File doesn't exist in path
return "";
}
}

function createNetwork(name: string): HttpNetworkUserConfig {
const configPath = path.join(getConfigPath(), name + ".json");
if (fs.existsSync(configPath)) {
var json = require(configPath);
if (json.verify && json.verify.apiUrl.endsWith("/api")) {
json.verify.apiUrl = json.verify.apiUrl.slice(0, -4);
}
return {
from: json.address,
gasPrice: "auto",
chainId: parseInt(json.network_id),
url: json.url,
accounts: [json.key],
gas: "auto",
saveDeployments: true,
verify: json.verify
? {
etherscan: {
apiKey: "4BX5JGM9IBFRHSDBMRCS4R66TX123T9E22",
apiUrl: json.verify.apiUrl,
},
}
: null,
zksync: json.zksync === true,
} as HttpNetworkUserConfig;
} else {
// File doesn't exist in path
return {
from: "0x0000000000000000000000000000000000000000",
gas: 0,
chainId: 0,
url: "",
accounts: [],
gasPrice: 0,
};
}
}

const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: "0.8.16",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
}
],
settings: {
metadata: {
// Not including the metadata hash
// https://github.com/paulrberg/hardhat-template/issues/31
bytecodeHash: "none",
},
// Disable the optimizer when debugging
// https://hardhat.org/hardhat-network/#solidity-optimizer-support
optimizer: {
enabled: true,
runs: 200,
},
},
},
namedAccounts: {
deployer: 0,
},
paths: {
sources: "src",
},
networks: {
hardhat: {},
mainnet: createNetwork("mainnet"),
polygon_mumbai: createNetwork("polygon_mumbai"),
polygon_mainnet: createNetwork("polygon_mainnet"),
polygon_dev: createNetwork("polygon_dev"),
dev: createNetwork("dev"),
goerli: createNetwork("goerli"),
staging: createNetwork("staging"),
polygon_staging: createNetwork("polygon_staging"),
optimism_mainnet: createNetwork("optimism_mainnet"),
optimism_goerli: createNetwork("optimism_goerli"),
mantle_testnet: createNetwork("mantle_testnet"),
mantle_mainnet: createNetwork("mantle_mainnet"),
arbitrum_goerli: createNetwork("arbitrum_goerli"),
arbitrum_sepolia: createNetwork("arbitrum_sepolia"),
arbitrum_mainnet: createNetwork("arbitrum_mainnet"),
zkatana_testnet: createNetwork("zkatana_testnet"),
zkatana_mainnet: createNetwork("zkatana_mainnet"),
chiliz_testnet: createNetwork("chiliz_testnet"),
chiliz_mainnet: createNetwork("chiliz_mainnet"),
zksync_testnet: createNetwork("zksync_testnet"),
},
etherscan: {
apiKey: {
mainnet: getNetworkApiKey('mainnet'),
polygon: getNetworkApiKey('polygon_mainnet'),
mumbai: getNetworkApiKey('polygon_mumbai'),
goerli: getNetworkApiKey("goerli"),
mantle_mainnet: getNetworkApiKey("mantle_mainnet"),
mantle_testnet: getNetworkApiKey("mantle_testnet"),
arbitrum_sepolia: getNetworkApiKey("arbitrum_sepolia"),
arbitrum_mainnet: getNetworkApiKey("arbitrum_mainnet"),
zksync_testnet: getNetworkApiKey("zksync_testnet"),
},
customChains: [
{
network: "mantle_mainnet",
chainId: createNetwork("mantle_mainnet").chainId!,
urls: {
apiURL: getNetworkApiUrl("mantle_mainnet"),
browserURL: getNetworkExplorerUrl("mantle_mainnet"),
},
},
{
network: "mantle_testnet",
chainId: createNetwork("mantle_testnet").chainId!,
urls: {
apiURL: getNetworkApiUrl("mantle_testnet"),
browserURL: getNetworkExplorerUrl("mantle_testnet"),
},
},
{
network: "arbitrum_sepolia",
chainId: createNetwork("arbitrum_sepolia").chainId!,
urls: {
apiURL: getNetworkApiUrl("arbitrum_sepolia"),
browserURL: getNetworkExplorerUrl("arbitrum_sepolia"),
},
},
{
network: "arbitrum_mainnet",
chainId: createNetwork("arbitrum_mainnet").chainId!,
urls: {
apiURL: getNetworkApiUrl("arbitrum_mainnet"),
browserURL: getNetworkExplorerUrl("arbitrum_mainnet"),
},
},
{
network: "zksync_testnet",
chainId: createNetwork("zksync_testnet").chainId!,
urls: {
apiURL: getNetworkApiUrl("zksync_testnet"),
browserURL: getNetworkExplorerUrl("zksync_testnet"),
},
},
],
},
zksolc: {
compilerSource: 'binary',
settings: {
isSystem: false, // optional. Enables Yul instructions available only for zkSync system contracts and libraries
forceEvmla: false, // optional. Falls back to EVM legacy assembly if there is a bug with Yul
optimizer: {
enabled: true, // optional. True by default
mode: '3' // optional. 3 by default, z to optimize bytecode size
},
}
},
};

export default config;
Loading