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

Tech debt #1721

Merged
merged 45 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
417fa9a
Update package.json dependencies and fix version path for deployment …
yavrsky Nov 12, 2024
0bd9c2e
Replace hardhat plugins with updated versions for verification and ma…
yavrsky Nov 12, 2024
6245de6
Refactor helper scripts for deployment in tests
yavrsky Nov 12, 2024
2d64d75
Refactor DepositBoxes
yavrsky Nov 12, 2024
0ce05b9
Refactor TokenManagers
yavrsky Nov 12, 2024
1923ff6
FIix solidity compile
yavrsky Nov 12, 2024
a914c09
Refactor CommunityLocker
yavrsky Nov 12, 2024
42646c3
Refactor and add couple tests in CommunityPool
yavrsky Nov 12, 2024
257e758
Refactor ERCOnChain tests and Linker
yavrsky Nov 12, 2024
d37c474
Fix MessageProxy tests
yavrsky Nov 12, 2024
93faa73
Refactor deployMainnet script
yavrsky Nov 12, 2024
09ab382
Refactor upgradeMainnet script
yavrsky Nov 12, 2024
64f5ee5
Fix deploySkaleManagerComponents script
yavrsky Nov 12, 2024
dfe7022
Fix test_upgrade script
yavrsky Nov 12, 2024
9cb2ba2
Add excludes for tsconfig.json
yavrsky Nov 12, 2024
c785000
Fix eslinter
yavrsky Nov 12, 2024
08f460a
Fix calculateGas test
yavrsky Nov 12, 2024
6c044e7
Update test_deploy script to deploy only to mainnet
yavrsky Nov 12, 2024
33c432e
Comment storing new abi after upgrade
yavrsky Nov 12, 2024
e62cfe6
Refactor deployMainnet script
yavrsky Nov 13, 2024
01749f2
Remove stringKeccak256, use ethers.id instead
yavrsky Nov 13, 2024
7feb173
Update TypeScript configuration and refactor BigInt usage in tests
yavrsky Nov 13, 2024
9a0e9a0
Refactor contract interaction to use instance directly instead of get…
yavrsky Nov 13, 2024
db7a09b
Upgrade dependencies for eslint
yavrsky Nov 13, 2024
a4183ff
Add SkaleManagerMock
yavrsky Nov 14, 2024
6915f26
Fix deployMainnet.ts
yavrsky Nov 14, 2024
ba8d003
Add deploy of SkaleManager to deploySkaleManagerComponents script
yavrsky Nov 14, 2024
1931cdf
Fix linters
yavrsky Nov 14, 2024
d10d7e1
Add handler for transaction receipts in calculateGas.ts
yavrsky Nov 14, 2024
975d2f3
Fix linter
yavrsky Nov 14, 2024
912a61a
Add generation of new abi's
yavrsky Nov 15, 2024
88782a8
Fix deploy script for schain part
yavrsky Nov 15, 2024
7be6507
Fix deploySchain.ts
yavrsky Nov 18, 2024
3afbb70
Fix hotfixUpgrade script
yavrsky Nov 18, 2024
53222fe
Fix submitTransaction.ts
yavrsky Nov 18, 2024
630249a
Fix transferOwnership.ts
yavrsky Nov 18, 2024
5041226
Change name for generated abi's
yavrsky Nov 18, 2024
fa75d8d
Fix test_upgrade.sh
yavrsky Nov 18, 2024
8856adc
Fix getVersion
yavrsky Nov 18, 2024
2ced3c5
Use assert to fix eslint no-unused-expressions
yavrsky Nov 18, 2024
e74edcd
Remove unused function stringToHex
yavrsky Nov 18, 2024
61cc023
Rename SkaleManager to SkaleManagerMock
yavrsky Nov 18, 2024
05b7583
Remove .only
yavrsky Nov 18, 2024
3a15d9f
Remove isTrue
yavrsky Nov 18, 2024
1ad91a2
Bump upgrade-tools version
yavrsky Nov 19, 2024
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
2 changes: 1 addition & 1 deletion contracts/schain/tokens/ERC721OnChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contract ERC721OnChain is
)
public
view
override(AccessControlEnumerableUpgradeable, ERC721Upgradeable)
override(AccessControlEnumerableUpgradeable, ERC721Upgradeable, ERC721URIStorageUpgradeable)
returns (bool)
{
return super.supportsInterface(interfaceId);
Expand Down
522 changes: 261 additions & 261 deletions gas/calculateGas.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@nomicfoundation/hardhat-verify";
import "@nomicfoundation/hardhat-chai-matchers";
import "@openzeppelin/hardhat-upgrades";
import "@typechain/hardhat";
import "solidity-coverage";
Expand Down
294 changes: 125 additions & 169 deletions migrations/deployMainnet.ts

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion migrations/deploySchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
*/

/**
* @file deploySchain.js
* @file deploySchain.ts
* @copyright SKALE Labs 2019-Present
*/
// TODO: Remove this line after closing issue https://github.com/skalenetwork/IMA/issues/1720
DimaStebaev marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { promises as fs } from 'fs';
import { Interface } from "ethers/lib/utils";
import { ethers, upgrades } from "hardhat";
Expand Down
86 changes: 43 additions & 43 deletions migrations/deploySkaleManagerComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import { promises as fs } from 'fs';
import { ethers } from "hardhat";
import { getAbi, getContractFactory } from '@skalenetwork/upgrade-tools';
import { getAbi } from '@skalenetwork/upgrade-tools';
import { Manifest } from "@openzeppelin/upgrades-core";
import { KeyStorageMock } from '../typechain';
import { Wallet } from 'ethers';
Expand Down Expand Up @@ -59,64 +59,64 @@ async function main() {
const schainName = process.env.CHAIN_NAME_SCHAIN;

console.log("Deploy ContractManager");
const contractManagerFactory = await getContractFactory("ContractManager");
const contractManagerFactory = await ethers.getContractFactory("ContractManager");
const contractManager = await contractManagerFactory.deploy();
console.log("Contract ContractManager deployed to", contractManager.address);
console.log("Contract ContractManager deployed to", await contractManager.getAddress());

console.log("Deploy Schains");
const schainsFactory = await getContractFactory("Schains");
const schainsFactory = await ethers.getContractFactory("Schains");
const schains = await schainsFactory.deploy();
console.log("Contract Schains deployed to", schains.address);
console.log("Contract Schains deployed to", await schains.getAddress());

console.log("Deploy SchainsInternal");
const schainsInternalFactory = await getContractFactory("SchainsInternal");
const schainsInternalFactory = await ethers.getContractFactory("SchainsInternal");
const schainsInternal = await schainsInternalFactory.deploy();
console.log("Contract SchainsInternal deployed to", schainsInternal.address);
console.log("Contract SchainsInternal deployed to", await schainsInternal.getAddress());

console.log("Deploy Wallets");
const walletsFactory = await getContractFactory("Wallets");
const walletsFactory = await ethers.getContractFactory("Wallets");
const wallets = await walletsFactory.deploy();
console.log("Contract Wallets deployed to", wallets.address);
console.log("Contract Wallets deployed to", await wallets.getAddress());

console.log("Deploy SkaleVerifier");
const skaleVerifierFactory = await getContractFactory("SkaleVerifierMock");
const skaleVerifierFactory = await ethers.getContractFactory("SkaleVerifierMock");
const skaleVerifier = await skaleVerifierFactory.deploy();
console.log("Contract SkaleVerifier deployed to", skaleVerifier.address);

console.log("Contract SkaleVerifier deployed to", await skaleVerifier.getAddress());
console.log("Deploy KeyStorage");
const keyStorageFactory = await getContractFactory("KeyStorageMock");
const keyStorageFactory = await ethers.getContractFactory("KeyStorageMock");
const keyStorage = await keyStorageFactory.deploy() as KeyStorageMock;
console.log("Contract KeyStorage deployed to", keyStorage.address);
console.log("Contract KeyStorage deployed to", await keyStorage.getAddress());

console.log("Deploy Nodes");
const nodesFactory = await getContractFactory("Nodes");
const nodesFactory = await ethers.getContractFactory("Nodes");
const nodes = await nodesFactory.deploy();
console.log("Contract Nodes deployed to", nodes.address);
console.log("Contract Nodes deployed to", await nodes.getAddress());

console.log("Will set dependencies");

await schains.addContractManager( contractManager.address );
console.log("Add ContractManager address", contractManager.address, "as ContractManager to Contract Schains", schains.address, "\n");
await schainsInternal.addContractManager( contractManager.address );
console.log("Add ContractManager address", contractManager.address, "as ContractManager to Contract SchainsInternal", schainsInternal.address, "\n");
await wallets.addContractManager( contractManager.address );
console.log("Add ContractManager address", contractManager.address, "as ContractManager to Contract Wallets", wallets.address, "\n");
await contractManager.setContractsAddress( "Schains", schains.address );
console.log("Set Schains", schains.address, "to ContractManager", contractManager.address, "\n");
await contractManager.setContractsAddress( "SchainsInternal", schainsInternal.address );
console.log("Set SchainsInternal", schainsInternal.address, "to ContractManager", contractManager.address, "\n");
await contractManager.setContractsAddress( "Wallets", wallets.address );
console.log("Set Wallets", wallets.address, "to ContractManager", contractManager.address, "\n");
await contractManager.setContractsAddress( "SkaleVerifier", skaleVerifier.address );
console.log("Set SkaleVerifier", skaleVerifier.address, "to ContractManager", contractManager.address, "\n");
await contractManager.setContractsAddress( "KeyStorage", keyStorage.address );
console.log("Set KeyStorage", keyStorage.address, "to ContractManager", contractManager.address, "\n");
await contractManager.setContractsAddress( "Nodes", nodes.address );
console.log("Set Nodes", nodes.address, "to ContractManager", contractManager.address, "\n");
await schains.addContractManager( await contractManager.getAddress() );
console.log("Add ContractManager address", await contractManager.getAddress(), "as ContractManager to Contract Schains", await schains.getAddress(), "\n");
await schainsInternal.addContractManager( await contractManager.getAddress() );
console.log("Add ContractManager address", await contractManager.getAddress(), "as ContractManager to Contract SchainsInternal", await schainsInternal.getAddress(), "\n");
await wallets.addContractManager( await contractManager.getAddress() );
console.log("Add ContractManager address", await contractManager.getAddress(), "as ContractManager to Contract Wallets", await wallets.getAddress(), "\n");
await contractManager.setContractsAddress( "Schains", await schains.getAddress() );
console.log("Set Schains", await schains.getAddress(), "to ContractManager", await contractManager.getAddress(), "\n");
await contractManager.setContractsAddress( "SchainsInternal", await schainsInternal.getAddress() );
console.log("Set SchainsInternal", await schainsInternal.getAddress(), "to ContractManager", await contractManager.getAddress(), "\n");
await contractManager.setContractsAddress( "Wallets", await wallets.getAddress() );
console.log("Set Wallets", await wallets.getAddress(), "to ContractManager", await contractManager.getAddress(), "\n");
await contractManager.setContractsAddress( "SkaleVerifier", await skaleVerifier.getAddress() );
console.log("Set SkaleVerifier", await skaleVerifier.getAddress(), "to ContractManager", await contractManager.getAddress(), "\n");
await contractManager.setContractsAddress( "KeyStorage", await keyStorage.getAddress() );
console.log("Set KeyStorage", await keyStorage.getAddress(), "to ContractManager", await contractManager.getAddress(), "\n");
await contractManager.setContractsAddress( "Nodes", await nodes.getAddress() );
console.log("Set Nodes", await nodes.getAddress(), "to ContractManager", await contractManager.getAddress(), "\n");
const nodeAddress1 = new Wallet(process.env.PRIVATE_KEY_FOR_ETHEREUM).connect(ethers.provider);
const nodeAddress2 = new Wallet(process.env.PRIVATE_KEY_FOR_SCHAIN).connect(ethers.provider);
await owner.sendTransaction({to: nodeAddress1.address, value: ethers.utils.parseEther("1")});
await owner.sendTransaction({to: nodeAddress2.address, value: ethers.utils.parseEther("1")});
await owner.sendTransaction({to: nodeAddress1.address, value: ethers.parseEther("1")});
await owner.sendTransaction({to: nodeAddress2.address, value: ethers.parseEther("1")});

const nodeCreationParams1 = {
port: 1337,
Expand All @@ -142,7 +142,7 @@ async function main() {
console.log("Create Node 1 with address", nodeAddress2.address, "\n");
await schainsInternal.initializeSchain( schainName, owner.address, 1, 1 );
console.log("Initialize Schain", schainName, "with address", owner.address, "\n");
await schainsInternal.connect(owner).addNodesToSchainsGroups(ethers.utils.id(schainName), [0, 1]);
await schainsInternal.connect(owner).addNodesToSchainsGroups(ethers.id(schainName), [0, 1]);
console.log("Add Nodes 0 and 1 to schain", schainName, "\n");
const BLSPublicKey = {
x: {
Expand All @@ -155,18 +155,18 @@ async function main() {
}
};
await keyStorage.setBlsCommonPublicKeyForSchain( stringKeccak256(schainName), BLSPublicKey );
console.log("Set common public key in KeyStorage contract", keyStorage.address, "\n");
console.log("Set common public key in KeyStorage contract", await keyStorage.getAddress(), "\n");
await wallets.rechargeSchainWallet( stringKeccak256(schainName), { value: "10000000000000000000" } ); // originally it was 1000000000000000000 = 1ETH
console.log("Recharge schain wallet in Wallets contract", wallets.address, "\n");
console.log("Recharge schain wallet in Wallets contract", await wallets.getAddress(), "\n");

const jsonObject = {
contract_manager_address: contractManager.address,
contract_manager_address: await contractManager.getAddress(),
contract_manager_abi: getAbi(contractManager.interface),
schains_internal_address: schainsInternal.address,
schains_internal_address: await schainsInternal.getAddress(),
schains_internal_abi: getAbi(schainsInternal.interface),
key_storage_address: keyStorage.address,
key_storage_address: await keyStorage.getAddress(),
key_storage_abi: getAbi(keyStorage.interface),
wallets_address: wallets.address,
wallets_address: await wallets.getAddress(),
wallets_abi: getAbi(wallets.interface)
};

Expand Down
2 changes: 1 addition & 1 deletion migrations/generateManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function importAddresses(manifest: ManifestData, abi: {[ key in str

export async function manifestSetup(pathToManifest: string) {
const chainId = (await ethers.provider.getNetwork()).chainId;
const manifestName = networkNames[chainId] ?? `unknown-${chainId}`;
const manifestName = networkNames[Number(chainId)] ?? `unknown-${chainId}`;
const correctManifestPath = `.openzeppelin/${manifestName}.json`;
if (pathToManifest === "" || pathToManifest === correctManifestPath) {
await fs.access(correctManifestPath);
Expand Down
71 changes: 38 additions & 33 deletions migrations/upgradeMainnet.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
import chalk from "chalk";
import { ethers } from "hardhat";
import { promises as fs } from "fs";
import { AutoSubmitter, Upgrader } from "@skalenetwork/upgrade-tools";
import { SkaleABIFile } from "@skalenetwork/upgrade-tools/dist/src/types/SkaleABIFile";
import { contracts, contractsToDeploy, getContractKeyInAbiFile } from "./deployMainnet";
import { Interface, Transaction } from "ethers";
import { Submitter, Upgrader } from "@skalenetwork/upgrade-tools";
import { skaleContracts, Instance } from "@skalenetwork/skale-contracts-ethers-v6";
import { MessageProxyForMainnet } from "../typechain";
import { Interface } from "@ethersproject/abi";
import { contracts } from "./deployMainnet";


async function getImaMainnetInstance() {
if (!process.env.TARGET) {
console.log(chalk.red("Specify desired mainnet-ima instance"));
console.log(chalk.red("Set instance alias or MessageProxyForMainnet address to TARGET environment variable"));
process.exit(1);
}
const network = await skaleContracts.getNetworkByProvider(ethers.provider);
const project = network.getProject("mainnet-ima");
return await project.getInstance(process.env.TARGET);
}

class ImaMainnetUpgrader extends Upgrader {

constructor(
targetVersion: string,
abi: SkaleABIFile,
instance: Instance,
contractNamesToUpgrade: string[],
submitter = new AutoSubmitter()) {
submitter?: Submitter) {
super(
"proxyMainnet",
targetVersion,
abi,
contractNamesToUpgrade,
submitter);
{
contractNamesToUpgrade,
instance,
name: "proxyMainnet",
version: targetVersion,
},
submitter
);
}

async getMessageProxyForMainnet() {
return await ethers.getContractAt("MessageProxyForMainnet", this.abi.message_proxy_mainnet_address as string) as MessageProxyForMainnet;
getMessageProxyForMainnet = async () => {
return await this.instance.getContract("MessageProxyForMainnet") as MessageProxyForMainnet;
}

getDeployedVersion = async () => {
Expand All @@ -38,14 +51,14 @@ class ImaMainnetUpgrader extends Upgrader {

setVersion = async (newVersion: string) => {
const messageProxyForMainnet = await this.getMessageProxyForMainnet();
this.transactions.push({
to: messageProxyForMainnet.address,
this.transactions.push(Transaction.from({
to: await messageProxyForMainnet.getAddress(),
data: messageProxyForMainnet.interface.encodeFunctionData("setVersion", [newVersion])
});
}));
}

// deployNewContracts = () => { };

DimaStebaev marked this conversation as resolved.
Show resolved Hide resolved
initialize = async () => {
const contractManagerAddress = await (await this.getMessageProxyForMainnet()).contractManagerOfSkaleManager();
const contractManagerInterface = new Interface([{
Expand Down Expand Up @@ -89,22 +102,23 @@ class ImaMainnetUpgrader extends Upgrader {
contractManagerInterface,
ethers.provider
)
for (const contractName of contractsToDeploy) {
for (const contractName of contracts) {
try {
const contractAddress = await contractManager.getContract(contractName);
console.log(`Address of ${contractName} is set to ${contractAddress}`);
} catch {

// getContract failed because the contract is not set
const contractAddress = this.abi[`${getContractKeyInAbiFile(contractName)}_address`] as string;
this.transactions.push(
const contractAddress = await this.instance.getContract(contractName);
this.transactions.push(Transaction.from(
{
to: contractManager.address,
to: await contractManager.getAddress(),
data: contractManager.interface.encodeFunctionData(
"setContractsAddress",
[contractAddress]
)
}
)
))
console.log(`Set ${contractName} address to ${contractAddress}`);
}
}
Expand All @@ -118,19 +132,10 @@ class ImaMainnetUpgrader extends Upgrader {
}
}

async function getImaMainnetAbiAndAddress(): Promise<SkaleABIFile> {
if (!process.env.ABI) {
console.log(chalk.red("Set path to file with ABI and addresses to ABI environment variables"));
process.exit(1);
}
const abiFilename = process.env.ABI;
return JSON.parse(await fs.readFile(abiFilename, "utf-8"));
}

async function main() {
const upgrader = new ImaMainnetUpgrader(
"2.1.0",
await getImaMainnetAbiAndAddress(),
await getImaMainnetInstance(),
contracts
);
await upgrader.upgrade();
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"compile": "npx hardhat compile",
"cleanCompile": "npx hardhat clean && yarn compile",
"deploy-to-both-chains": "yarn deploy-to-mainnet && yarn deploy-to-schain",
"deploy-to-mainnet": "VERSION=$(cat ../VERSION) npx hardhat run migrations/deployMainnet.ts --network mainnet",
"deploy-to-schain": "VERSION=$(cat ../VERSION) npx hardhat run migrations/deploySchain.ts --network schain",
"deploy-to-mainnet": "VERSION=$(cat ./VERSION) npx hardhat run migrations/deployMainnet.ts --network mainnet",
"deploy-to-schain": "VERSION=$(cat ./VERSION) npx hardhat run migrations/deploySchain.ts --network schain",
"deploy-skale-manager-components": "npx hardhat run migrations/deploySkaleManagerComponents.ts --network mainnet",
"eslint": "npx eslint .",
"lint": "npx solhint \"contracts/**/*.sol\"",
Expand All @@ -21,23 +21,24 @@
"no-hooks": "git config core.hooksPath .git/hooks"
},
"dependencies": {
"@nomiclabs/hardhat-ethers": "^2.1.0",
"@nomicfoundation/hardhat-ethers": "^3.0.8",
"@openzeppelin/contracts-upgradeable": "^4.7.1",
"@openzeppelin/hardhat-upgrades": "^1.14.0",
"@openzeppelin/hardhat-upgrades": "^3.1.1",
"@safe-global/api-kit": "2.5.4",
"@skalenetwork/etherbase-interfaces": "^0.0.1-develop.20",
"@skalenetwork/ima-interfaces": "2.0.0",
"@skalenetwork/skale-manager-interfaces": "2.0.0",
"@skalenetwork/upgrade-tools": "^2.0.2",
"@skalenetwork/upgrade-tools": "3.0.0-develop.33",
"axios": "^0.21.4",
"dotenv": "^16.0.0",
"ethers": "^5.7.2",
"hardhat": "2.11.0 - 2.16.1"
"ethers": "^6.1.0",
"hardhat": "^2.22.15"
},
"devDependencies": {
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@typechain/ethers-v5": "^11.1.1",
"@typechain/hardhat": "^7.0.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
"@nomicfoundation/hardhat-verify": "^1.1.1",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.2.12",
"@types/chai-almost": "^1.0.1",
"@types/chai-as-promised": "^7.1.3",
Expand All @@ -52,7 +53,6 @@
"chai-as-promised": "^7.1.1",
"cspell": "^8.14.4",
"eslint": "^8.46.0",
"ethereum-waffle": "^4.0.10",
"ganache": "7.9.2",
"solhint": "3.3.6",
"solidity-coverage": "^0.8.4",
Expand Down
4 changes: 3 additions & 1 deletion scripts/test_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export PRIVATE_KEY_FOR_ETHEREUM=$PRIVATE_KEY
export PRIVATE_KEY_FOR_SCHAIN=$PRIVATE_KEY

yarn deploy-skale-manager-components
yarn deploy-to-both-chains
yarn deploy-to-mainnet
# TODO: Uncomment after fixing deploy script for schain, related issue https://github.com/skalenetwork/IMA/issues/1720
DimaStebaev marked this conversation as resolved.
Show resolved Hide resolved
# yarn deploy-to-both-chains

npx ganache instances stop "$GANACHE"
Loading
Loading