Skip to content

Commit

Permalink
Merge pull request #1068 from skalenetwork/skale-contracts
Browse files Browse the repository at this point in the history
Add ABI generation
  • Loading branch information
DimaStebaev authored Apr 11, 2024
2 parents cb775b1 + 27f074d commit 1864238
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 49 deletions.
93 changes: 68 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,93 @@ env:
jobs:
build:
runs-on: ubuntu-latest
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
if: github.event_name != 'pull_request' || github.event.pull_request.merged == true

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- uses: actions/checkout@v4

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

- name: Install project
run: yarn install

- name: Build and publish container
- name: Calculate version
id: version
run: |
export BRANCH=${GITHUB_REF##*/}
echo "Branch $BRANCH"
export VERSION=$(bash ./scripts/calculate_version.sh)
echo "Version $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
( test $BRANCH = "stable" || test $BRANCH = "master" && export PRERELEASE=false ) || export PRERELEASE=true
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
bash ./scripts/build_and_publish.sh
- name: Generate ABI
run: npx hardhat run scripts/generateAbi.ts

- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: data
path: data

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
draft: false
tag: ${{ env.VERSION }}
prerelease: ${{ env.PRERELEASE }}
artifacts: "data/skale-manager-*-abi.json"

docker:
runs-on: ubuntu-latest

if: github.event_name != 'pull_request' || github.event.pull_request.merged == true

steps:
- uses: actions/checkout@v4

- name: Build and publish container
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
export BRANCH=${GITHUB_REF##*/}
echo "Branch $BRANCH"
export VERSION=$(bash ./scripts/calculate_version.sh)
echo "Version $VERSION"
bash ./scripts/build_and_publish.sh
abi:
runs-on: ubuntu-latest

needs:
build

env:
VERSION: ${{ needs.build.outputs.version }}

steps:
- uses: actions/checkout@v4
with:
ref: abi

- name: Load artifacts
uses: actions/download-artifact@v4
with:
name: data

- name: Commit ABI
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "Add ABI for version ${{ env.VERSION }}"
add: "*-abi.json"
30 changes: 8 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,19 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4

- name: Install NODE JS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'

- name: Install project
run: yarn install
Expand All @@ -74,6 +57,9 @@ jobs:
NODE_VERSION: ${{ matrix.node-version }}
run: ./scripts/test_upgrade.sh

- name: Test ABI ageneration
run: npx hardhat run scripts/generateAbi.ts

- name: Run tests
run: npx hardhat coverage --solcoverjs .solcover.js

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16
FROM node:18

RUN mkdir /usr/src/manager
WORKDIR /usr/src/manager
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0
2.0.0
50 changes: 50 additions & 0 deletions scripts/generateAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { promises as fs } from 'fs';
import { contracts } from "../migrations/deploy";
import { ethers } from "hardhat";
import { getAbi, getVersion } from '@skalenetwork/upgrade-tools';
import { ContractFactory } from 'ethers';
import { Libraries } from '@nomiclabs/hardhat-ethers/types';

async function main() {
const allContracts = contracts.concat(["SkaleToken", "TimeHelpersWithDebug"])
const abi: {[name: string]: []} = {};
const librariesRequirements: {[name: string]: string[]} = {
"Nodes": [
"SegmentTree"
],
"SkaleDKG": [
"SkaleDkgAlright",
"SkaleDkgBroadcast",
"SkaleDkgComplaint",
"SkaleDkgPreResponse",
"SkaleDkgResponse"
]
}
for (const contractName of allContracts) {
console.log(`Load ABI of ${contractName}`);
let factory: ContractFactory;
if (Object.keys(librariesRequirements).includes(contractName)) {
const libraries: Libraries = {};
for(const library of librariesRequirements[contractName]) {
libraries[library] = ethers.constants.AddressZero;
}
factory = await ethers.getContractFactory(contractName, {libraries});
} else {
factory = await ethers.getContractFactory(contractName);
}
abi[contractName] = getAbi(factory.interface);
}
const version = await getVersion();
const filename = `data/skale-manager-${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);
});
}

0 comments on commit 1864238

Please sign in to comment.