Skip to content

Commit

Permalink
Revert "Revert "Prepare infrastructure for skale-contracts""
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Mar 5, 2024
1 parent 16ba275 commit cc7a52a
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 242 deletions.
35 changes: 18 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ on:
branches-ignore:
- 'docs-v*'

env:
NODE_VERSION: 18
PYTHON_VERSION: 3.8

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test-contracts:
runs-on: ubuntu-latest

env:
working-directory: ./proxy
defaults:
run:
working-directory: proxy

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -45,47 +50,43 @@ jobs:
- name: Install PYTHON
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: ${{ env.PYTHON_VERSION }}

- name: Install NODE JS
uses: actions/setup-node@v2
with:
node-version: 18
node-version: ${{ env.NODE_VERSION }}

- name: Install project
working-directory: ${{env.working-directory}}
run: |
yarn install
run: yarn install

- name: Install slither
working-directory: ${{env.working-directory}}
run: pip3 install -r scripts/requirements.txt

- name: Lint solidity
working-directory: ${{env.working-directory}}
run: yarn lint

- name: Compile typescript
working-directory: ${{env.working-directory}}
run: yarn tsc

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

- name: Slither checks
working-directory: ${{env.working-directory}}
run: yarn slither

- name: Test ABI generation
env:
VERSION: "0.0.0"
run: npx hardhat run scripts/generateAbi.ts

- name: Gas calculation test
working-directory: ${{env.working-directory}}
run: npx hardhat test gas/calculateGas.ts

- name: Test upgrade
run: bash ./proxy/scripts/test_upgrade.sh
run: bash scripts/test_upgrade.sh

- name: Run tests
working-directory: ${{env.working-directory}}
run: |
npx hardhat coverage --solcoverjs .solcover.js
bash <(curl -s https://codecov.io/bash) -f coverage/lcov.info -t $CODECOV_TOKEN || echo "Codecov did not collect coverage reports"
Expand Down Expand Up @@ -124,12 +125,12 @@ jobs:
- name: Install PYTHON
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: ${{ env. PYTHON_VERSION }}

- name: Install NODE JS
uses: actions/setup-node@v2
with:
node-version: 18
node-version: ${{ env.NODE_VERSION }}

- name: Install project
run: |
Expand Down
56 changes: 33 additions & 23 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ on:
tags:
- 'custom-release-*'

env:
NODE_VERSION: 18
PYTHON_VERSION: 3.8

jobs:
build:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
PROXY_DIR: "proxy"
defaults:
run:
working-directory: proxy
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive

Expand All @@ -47,22 +53,20 @@ jobs:
- name: Install NODE JS
uses: actions/setup-node@v2
with:
node-version: '18'
node-version: ${{ env.NODE_VERSION }}

- name: Install Python 3.8
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: ${{ env.PYTHON_VERSION }}

- name: Prepare for pip package building
run: |
python3 -m pip install --upgrade build
python3 -m pip install --user --upgrade twine
- name: Install project
working-directory: ${{env.PROXY_DIR}}
run: |
yarn install
run: yarn install

- name: Calculate version
run: |
Expand All @@ -75,30 +79,28 @@ jobs:
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
- name: Generate Manifest
working-directory: ${{env.PROXY_DIR}}
run: |
npx hardhat run migrations/generateManifest.ts
run: npx hardhat run migrations/generateManifest.ts

- name: Install python testing staff
working-directory: ${{env.PROXY_DIR}}
run: pip3 install -r predeployed/test/requirements.txt

- name: Build predeployed pip package
working-directory: ${{env.PROXY_DIR}}
env:
VERSION: ${{ env.VERSION }}
run: |
./predeployed/scripts/build_package.sh
run: ./predeployed/scripts/build_package.sh

- name: Publish predeployed pip package
working-directory: ${{env.PROXY_DIR}}
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
./predeployed/scripts/publish_package.sh
run: ./predeployed/scripts/publish_package.sh

- name: Generate mainnet ABIs
env:
VERSION: ${{ env.VERSION }}
run: npx hardhat run scripts/generateAbi.ts

- name: Generate ABIs
working-directory: ${{env.PROXY_DIR}}/predeployed
- name: Generate predeployed ABIs
working-directory: proxy/predeployed
env:
VERSION: ${{ env.VERSION }}
run: |
Expand Down Expand Up @@ -126,7 +128,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
assets_path: proxy/predeployed/dist/
assets_path: predeployed/dist/

- name: Upload Release Assets
id: upload-static-data
Expand All @@ -135,7 +137,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
assets_path: proxy/predeployed/data/
assets_path: predeployed/data/

- name: Upload Release Assets
id: upload-manifest-data
Expand All @@ -144,7 +146,15 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
assets_path: proxy/data/ima-schain-*-manifest.json
assets_path: data/ima-schain-*-manifest.json

- name: Upload Release Assets
uses: dwenegar/upload-release-assets@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
assets_path: data/*-abi.json

- name: Build and publish image
env:
Expand Down
7 changes: 7 additions & 0 deletions proxy/migrations/deployMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ async function main() {
try {
await contractManagerInst.setContractsAddress( "MessageProxyForMainnet", deployed.get( "MessageProxyForMainnet" )?.address);
await contractManagerInst.setContractsAddress( "CommunityPool", deployed.get( "CommunityPool" )?.address);
for (const contractName of contractsToDeploy) {
const contractAddress = deployed.get(contractName);
if (contractAddress === undefined) {
throw new Error(`${contractName} was not found`);
}
await contractManagerInst.setContractsAddress( contractName, contractAddress);
}
console.log( "Successfully registered MessageProxy in ContractManager" );
} catch ( error ) {
console.log( "Registration of MessageProxy is failed on ContractManager. Please redo it by yourself!\nError:", error );
Expand Down
40 changes: 5 additions & 35 deletions proxy/migrations/deploySchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import { promises as fs } from 'fs';
import { Interface } from "ethers/lib/utils";
import { ethers, upgrades, network } from "hardhat";
import { ethers, upgrades } from "hardhat";
import hre from "hardhat";
import { getAbi, getVersion } from '@skalenetwork/upgrade-tools';
import { Manifest } from "@openzeppelin/upgrades-core";
Expand Down Expand Up @@ -181,36 +181,8 @@ async function main() {
deployed.set( "TokenManagerEth", { address: tokenManagerEth.address, interface: tokenManagerEth.interface } );
console.log("Contract TokenManagerEth deployed to", tokenManagerEth.address);

/*
In the moment of this code was written
ganache had a bug
that prevented proper execution
of estimateGas function
during deployment of smart contract
that exceed 24KB limit.
In addition to this problem
upgrade-hardhat library
did not supported
manual gas limit configuration.
TODO: in case of any one or both issues fixed
please remove this crazy workaround below
*/
if (network.config.gas === "auto") {
throw Error("Can't use auto because of problems with gas estimations");
}
if (!process.env.PRIVATE_KEY_FOR_SCHAIN) {
throw Error("PRIVATE_KEY_FOR_SCHAIN is not set");
}
const key = process.env.PRIVATE_KEY_FOR_SCHAIN;
const signerWithFixedGasEstimation = new ethers.Wallet(key, ethers.provider);
signerWithFixedGasEstimation.estimateGas = async() => {
return ethers.BigNumber.from(network.config.gas as number);
}

console.log("Deploy TokenManagerERC20");
const tokenManagerERC20Factory = await ethers.getContractFactory("TokenManagerERC20", signerWithFixedGasEstimation);
const tokenManagerERC20Factory = await ethers.getContractFactory("TokenManagerERC20");
const tokenManagerERC20 = await upgrades.deployProxy(tokenManagerERC20Factory, [
schainName,
messageProxy.address,
Expand All @@ -222,10 +194,8 @@ async function main() {
deployed.set( "TokenManagerERC20", { address: tokenManagerERC20.address, interface: tokenManagerERC20.interface } );
console.log("Contract TokenManagerERC20 deployed to", tokenManagerERC20.address);

// The end of TODO:

console.log("Deploy TokenManagerERC721");
const tokenManagerERC721Factory = await ethers.getContractFactory("TokenManagerERC721", signerWithFixedGasEstimation);
const tokenManagerERC721Factory = await ethers.getContractFactory("TokenManagerERC721");
const tokenManagerERC721 = await upgrades.deployProxy(tokenManagerERC721Factory, [
schainName,
messageProxy.address,
Expand All @@ -238,7 +208,7 @@ async function main() {
console.log("Contract TokenManagerERC721 deployed to", tokenManagerERC721.address);

console.log("Deploy TokenManagerERC1155");
const tokenManagerERC1155Factory = await ethers.getContractFactory("TokenManagerERC1155", signerWithFixedGasEstimation);
const tokenManagerERC1155Factory = await ethers.getContractFactory("TokenManagerERC1155");
const tokenManagerERC1155 = await upgrades.deployProxy(tokenManagerERC1155Factory, [
schainName,
messageProxy.address,
Expand All @@ -251,7 +221,7 @@ async function main() {
console.log("Contract TokenManagerERC1155 deployed to", tokenManagerERC1155.address);

console.log("Deploy TokenManagerERC721WithMetadata");
const tokenManagerERC721WithMetadataFactory = await ethers.getContractFactory("TokenManagerERC721WithMetadata", signerWithFixedGasEstimation);
const tokenManagerERC721WithMetadataFactory = await ethers.getContractFactory("TokenManagerERC721WithMetadata");
const tokenManagerERC721WithMetadata = await upgrades.deployProxy(tokenManagerERC721WithMetadataFactory, [
schainName,
messageProxy.address,
Expand Down
68 changes: 66 additions & 2 deletions proxy/migrations/upgradeMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ 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 } from "./deployMainnet";
import { contracts, contractsToDeploy, getContractKeyInAbiFile } from "./deployMainnet";
import { MessageProxyForMainnet } from "../typechain";
import { Interface } from "@ethersproject/abi";


class ImaMainnetUpgrader extends Upgrader {

Expand Down Expand Up @@ -44,7 +46,69 @@ class ImaMainnetUpgrader extends Upgrader {

// deployNewContracts = () => { };

// initialize = async () => { };
initialize = async () => {
const contractManagerAddress = await (await this.getMessageProxyForMainnet()).contractManagerOfSkaleManager();
const contractManagerInterface = new Interface([{
"type": "function",
"name": "getContract",
"constant": true,
"stateMutability": "view",
"payable": false,
"inputs": [
{
"type": "string",
"name": "name"
}
],
"outputs": [
{
"type": "address",
"name": "contractAddress"
}
]
},
{
"type": "function",
"name": "setContractsAddress",
"constant": false,
"payable": false,
"inputs": [
{
"type": "string",
"name": "contractsName"
},
{
"type": "address",
"name": "newContractsAddress"
}
],
"outputs": []
}]);
const contractManager = new ethers.Contract(
contractManagerAddress,
contractManagerInterface,
ethers.provider
)
for (const contractName of contractsToDeploy) {
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(
{
to: contractManager.address,
data: contractManager.interface.encodeFunctionData(
"setContractsAddress",
[contractAddress]
)
}
)
console.log(`Set ${contractName} address to ${contractAddress}`);
}
}
};

_getContractKeyInAbiFile(contract: string) {
if (contract === "MessageProxyForMainnet") {
Expand Down
Loading

0 comments on commit cc7a52a

Please sign in to comment.