Skip to content

Commit

Permalink
Merge pull request #1552 from skalenetwork/merge-beta
Browse files Browse the repository at this point in the history
Merge beta
  • Loading branch information
DimaStebaev authored Aug 16, 2023
2 parents a6b79d8 + 7e652c6 commit ed8695e
Show file tree
Hide file tree
Showing 52 changed files with 3,232 additions and 5,980 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:

- name: Lint typescript
working-directory: ${{env.working-directory}}
run: yarn tslint
run: yarn eslint

- name: Slither checks
working-directory: ${{env.working-directory}}
Expand Down Expand Up @@ -351,7 +351,7 @@ jobs:
- name: Start background ganache
run: |
cd proxy
NODE_OPTIONS="--max_old_space_size=3072" npx ganache-cli --gasLimit 12000000 --quiet --allowUnlimitedContractSize --defaultBalanceEther 2000000 --acctKeys ../test/accounts.json &
npx ganache --miner.blockGasLimit 12000000 --logging.quiet --chain.allowUnlimitedContractSize --wallet.defaultBalance 2000000 --wallet.accountKeysPath ../test/accounts.json &
- name: Prepare test (PY part)
working-directory: ${{env.working-directory}}
Expand Down
16 changes: 16 additions & 0 deletions proxy/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-env node */
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {

},
ignorePatterns: [

]
};
4 changes: 0 additions & 4 deletions proxy/customTypes/typings.d.ts

This file was deleted.

34 changes: 13 additions & 21 deletions proxy/gas/calculateGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ import {
TokenManagerLinker,
Wallets,
Linker,
IMessageProxy,
} from "../typechain";

chai.should();
chai.use((chaiAsPromised as any));
chai.use(chaiAsPromised);

import { deployLinker } from "../test/utils/deploy/mainnet/linker";
import { deployDepositBoxEth } from "../test/utils/deploy/mainnet/depositBoxEth";
Expand All @@ -70,14 +71,6 @@ import { deployERC721OnChain } from "../test/utils/deploy/erc721OnChain";
import { deployERC1155OnChain } from "../test/utils/deploy/erc1155OnChain";

import { deployContractManager } from "../test/utils/skale-manager-utils/contractManager";
// import { deployContractManager } from "../test/utils/skale-manager-utils/keyStorage";
// const KeyStorage: KeyStorageContract = artifacts.require("./KeyStorage");
// const Nodes: NodesContract = artifacts.require("./Nodes");
// const Schains: SchainsContract = artifacts.require("./Schains");
// const SchainsInternal: SchainsInternalContract = artifacts.require("./SchainsInternal");
// const SkaleVerifierMock: SkaleVerifierMockContract = artifacts.require("./SkaleVerifierMock");
// const Wallets: WalletsContract = artifacts.require("./Wallets");

import { deployTokenManagerLinker } from "../test/utils/deploy/schain/tokenManagerLinker";
import { deployTokenManagerEth } from "../test/utils/deploy/schain/tokenManagerEth";
import { deployTokenManagerERC20 } from "../test/utils/deploy/schain/tokenManagerERC20";
Expand All @@ -86,16 +79,15 @@ import { deployTokenManagerERC1155 } from "../test/utils/deploy/schain/tokenMana
import { deployMessageProxyForSchain } from "../test/utils/deploy/schain/messageProxyForSchain";
import { deployMessages } from "../test/utils/deploy/messages";

import { stringValue, getPublicKey } from "../test/utils/helper";
import { stringKeccak256, getPublicKey } from "../test/utils/helper";

import { ethers, web3 } from "hardhat";
import { ethers } from "hardhat";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address";
import { BigNumber, BytesLike, Wallet } from "ethers";
import { BigNumber, Wallet } from "ethers";

import { assert, expect } from "chai";
import { expect } from "chai";
import { deployCommunityLocker } from "../test/utils/deploy/schain/communityLocker";
import { deployCommunityPool } from "../test/utils/deploy/mainnet/communityPool";
// import { LockAndDataForSchain } from "../typechain/LockAndDataForSchain";

describe("Gas calculation", () => {
let deployer: SignerWithAddress;
Expand Down Expand Up @@ -138,7 +130,7 @@ describe("Gas calculation", () => {
let ERC1155TokenOnSchain: ERC1155OnChain;

const schainName = "GasCalculation";
const schainNameHash = web3.utils.soliditySha3("GasCalculation");
const schainNameHash = stringKeccak256("GasCalculation");
const contractManagerAddress = "0x0000000000000000000000000000000000000000";
const mainnetName = "Mainnet";

Expand Down Expand Up @@ -204,8 +196,8 @@ describe("Gas calculation", () => {

// initialize schain and data
await schainsInternal.connect(deployer).initializeSchain(schainName, schainOwner.address, 12345678, 12345678);
await schainsInternal.connect(deployer).addNodesToSchainsGroups(stringValue(schainNameHash), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
await wallets.connect(deployer).rechargeSchainWallet(stringValue(schainNameHash), {value: "1000000000000000000"});
await schainsInternal.connect(deployer).addNodesToSchainsGroups(schainNameHash, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
await wallets.connect(deployer).rechargeSchainWallet(schainNameHash, {value: "1000000000000000000"});

// set BLS Public Key to schain
// P.s. this is test public key from test of SkaleManager.SkaleVerifier - please do not use it!!!
Expand All @@ -219,7 +211,7 @@ describe("Gas calculation", () => {
b: "14411459380456065006136894392078433460802915485975038137226267466736619639091",
}
}
await keyStorage.connect(deployer).setBlsCommonPublicKeyForSchain(stringValue(schainNameHash), BLSPublicKey);
await keyStorage.connect(deployer).setBlsCommonPublicKeyForSchain(schainNameHash, BLSPublicKey);
// await wallets.rechargeSchainWallet(stringValue(schainNameHash), {value: "1000000000000000000"});

// IMA mainnet part deployment
Expand Down Expand Up @@ -569,7 +561,7 @@ describe("Gas calculation", () => {
hashB: "15163860114293529009901628456926790077787470245128337652112878212941459329347",
};

async function postIncomingMessages(startingCounter: number, arrayOfMessages: any, action: string) {
async function postIncomingMessages(startingCounter: number, arrayOfMessages: IMessageProxy.MessageStruct[], action: string) {
const res = await (await messageProxyForMainnet.connect(nodeAddress).postIncomingMessages(
schainName,
startingCounter,
Expand Down Expand Up @@ -1091,7 +1083,7 @@ describe("Gas calculation", () => {
async function checkBalance() {
const balanceIds = await ERC1155TokenOnMainnet.balanceOfBatch([user.address, user.address, user.address, user.address, user.address], [1, 2, 3, 4, 5]);
const balanceIdsNumber: number[] = [];
balanceIds.forEach((element: any) => {
balanceIds.forEach((element) => {
balanceIdsNumber.push(BigNumber.from(element).toNumber())
});
expect(balanceIdsNumber).to.deep.equal([1, 2, 3, 4, 5]);
Expand Down Expand Up @@ -1225,4 +1217,4 @@ describe("Gas calculation", () => {
});
});
});
});
});
9 changes: 6 additions & 3 deletions proxy/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HardhatUserConfig, task } from "hardhat/config";
import { HardhatUserConfig } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@nomiclabs/hardhat-web3";
import "@openzeppelin/hardhat-upgrades";
import "@typechain/hardhat";
import "solidity-coverage";
Expand Down Expand Up @@ -64,6 +63,7 @@ const config: HardhatUserConfig = {
},
schain: {
url: getCustomUrl(process.env.URL_W3_S_CHAIN),
gas: 12000000,
accounts: getCustomPrivateKey(process.env.PRIVATE_KEY_FOR_SCHAIN),
}
},
Expand All @@ -72,7 +72,10 @@ const config: HardhatUserConfig = {
},
typechain: {
outDir: "typechain/",
externalArtifacts: ['node_modules/@openzeppelin/upgrades-core/artifacts/*.json']
externalArtifacts: [
'node_modules/@openzeppelin/upgrades-core/artifacts/AdminUpgradeabilityProxy.json',
'node_modules/@openzeppelin/upgrades-core/artifacts/ProxyAdmin.json'
]
}
};

Expand Down
23 changes: 12 additions & 11 deletions proxy/migrations/deployMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
*/
import { promises as fs } from 'fs';
import { Interface } from "ethers/lib/utils";
import { ethers, upgrades, web3 } from "hardhat";
import { ethers, upgrades } from "hardhat";
import { MessageProxyForMainnet, Linker } from "../typechain";
import { getAbi, getContractFactory, verifyProxy, getVersion } from '@skalenetwork/upgrade-tools';
import { Manifest } from "@openzeppelin/upgrades-core";
import { SkaleABIFile } from '@skalenetwork/upgrade-tools/dist/src/types/SkaleABIFile';

export function getContractKeyInAbiFile(contract: string) {
if (contract === "MessageProxyForMainnet") {
Expand All @@ -37,15 +38,15 @@ export function getContractKeyInAbiFile(contract: string) {
}

export async function getManifestFile(): Promise<string> {
return (await Manifest.forNetwork(ethers.provider)).file;;
return (await Manifest.forNetwork(ethers.provider)).file;
}

export function getContractManager() {
const defaultFilePath = "../data/skaleManagerComponents.json";
const jsonData = require(defaultFilePath);
async function getContractManager() {
const defaultFilePath = "data/skaleManagerComponents.json";
const jsonData = JSON.parse(await fs.readFile(defaultFilePath)) as SkaleABIFile;
try {
const contractManagerAddress = jsonData.contract_manager_address;
const contractManagerABI = jsonData.contract_manager_abi;
const contractManagerAddress = jsonData.contract_manager_address as string;
const contractManagerABI = jsonData.contract_manager_abi as [];
return { address: contractManagerAddress, abi: contractManagerABI };
} catch (e) {
console.log(e);
Expand Down Expand Up @@ -76,7 +77,7 @@ async function main() {
const [ owner,] = await ethers.getSigners();
const deployed = new Map<string, {address: string, interface: Interface}>();

const contractManager = getContractManager();
const contractManager = await getContractManager();
const version = await getVersion();

const messageProxyForMainnetName = "MessageProxyForMainnet";
Expand Down Expand Up @@ -188,7 +189,7 @@ async function main() {

console.log("Store ABIs");

const outputObject: {[k: string]: any} = {};
const outputObject: {[k: string]: string | []} = {};
for (const contract of contracts) {
const contractKey = getContractKeyInAbiFile(contract);
const deployedContract = deployed.get(contract);
Expand All @@ -209,8 +210,8 @@ async function main() {

if( contractManager?.address !== null && contractManager?.address !== "" && contractManager?.address !== "0x0000000000000000000000000000000000000000" ) {
// register MessageProxy in ContractManager
if( contractManager?.abi !== "" && contractManager?.abi !== undefined ) {
if( await web3.eth.getCode( contractManager?.address) !== "0x") {
if( contractManager?.abi !== undefined ) {
if( await ethers.provider.getCode( contractManager?.address) !== "0x") {
const contractManagerInst = new ethers.Contract(contractManager?.address, contractManager?.abi, owner);
if (await contractManagerInst.owner() !== owner.address) {
console.log( "Owner of ContractManager is not the same of the deployer" );
Expand Down
Loading

0 comments on commit ed8695e

Please sign in to comment.