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 6, 2024
1 parent 1190a8c commit a5d86ce
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 159 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ jobs:
cache: 'yarn'

- name: Install project
run: |
yarn install
run: yarn install

- name: Install slither
run: pip3 install -r scripts/requirements.txt
Expand All @@ -59,14 +58,19 @@ jobs:
- name: Slither checks
run: yarn slither

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

- name: Gas calculation test
run: npx hardhat test gas/calculateGas.ts

- name: Test deploy
run: bash ./scripts/test_deploy.sh

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

- name: Run tests
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
2 changes: 0 additions & 2 deletions proxy/migrations/deploySchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ 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");
const tokenManagerERC721 = await upgrades.deployProxy(tokenManagerERC721Factory, [
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
8 changes: 1 addition & 7 deletions proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@
"@skalenetwork/upgrade-tools": "^2.0.2",
"axios": "^0.21.4",
"dotenv": "^16.0.0",
"ethereumjs-tx": "2.1.2",
"ethereumjs-util": "^7.1.5",
"ethers": "^5.7.2",
"ethers-eip712": "^0.2.0",
"hardhat": "2.11.0 - 2.16.1",
"path": "^0.12.7"
"hardhat": "2.11.0 - 2.16.1"
},
"devDependencies": {
"@nomiclabs/hardhat-etherscan": "^3.1.0",
Expand All @@ -51,11 +47,9 @@
"@types/sinon-chai": "^3.2.5",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"bignumber.js": "^9.0.0",
"chai": "^4.2.0",
"chai-almost": "^1.0.1",
"chai-as-promised": "^7.1.1",
"codecov": "^3.7.1",
"eslint": "^8.46.0",
"ethereum-waffle": "^4.0.10",
"ganache": "7.9.2",
Expand Down
26 changes: 26 additions & 0 deletions proxy/scripts/generateAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { promises as fs } from 'fs';
import { contracts } from "../migrations/deployMainnet";
import { ethers } from "hardhat";
import { getAbi, getVersion } from '@skalenetwork/upgrade-tools';

async function main() {
const abi: {[name: string]: []} = {};
for (const contractName of contracts) {
console.log(`Load ABI of ${contractName}`);
const factory = await ethers.getContractFactory(contractName);
abi[contractName] = getAbi(factory.interface);
}
const version = await getVersion();
const filename = `data/mainnet-ima-${version}-abi.json`;
console.log(`Save to ${filename}`)
await fs.writeFile(filename, JSON.stringify(abi, null, 4));
}

if (require.main === module) {
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
}
3 changes: 1 addition & 2 deletions proxy/scripts/test_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ GANACHE=$(npx ganache \
--wallet.accountKeysPath "$ACCOUNTS_FILENAME" \
)

cd "$DEPLOYED_DIR"
cd "$DEPLOYED_DIR/proxy"
yarn install
cd proxy
PRIVATE_KEY_FOR_ETHEREUM=$(cat "$ACCOUNTS_FILENAME" | jq -r '.private_keys | to_entries | .[8].value')
PRIVATE_KEY_FOR_SCHAIN=$(cat "$ACCOUNTS_FILENAME" | jq -r '.private_keys | to_entries | .[9].value')
CHAIN_NAME_SCHAIN="Test" VERSION="$DEPLOYED_VERSION" PRIVATE_KEY_FOR_ETHEREUM="$PRIVATE_KEY_FOR_ETHEREUM" PRIVATE_KEY_FOR_SCHAIN="$PRIVATE_KEY_FOR_SCHAIN" npx hardhat run migrations/deploySkaleManagerComponents.ts --network localhost
Expand Down
Loading

0 comments on commit a5d86ce

Please sign in to comment.