From 28f42d952b0adead0ba19f5da2b3ab2d8042cd1d Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Thu, 8 Jun 2023 14:14:39 +0400 Subject: [PATCH 1/4] refactor: networks getter --- .npmignore | 4 ++++ src/getHardhatConfigNetworks.ts | 34 ++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..799d1b0 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +/src +/scripts +/networks.schema.json +/tsconfig.json \ No newline at end of file diff --git a/src/getHardhatConfigNetworks.ts b/src/getHardhatConfigNetworks.ts index 9131c73..572f382 100644 --- a/src/getHardhatConfigNetworks.ts +++ b/src/getHardhatConfigNetworks.ts @@ -1,27 +1,39 @@ import fs from "fs"; import path from "path"; -export const getHardhatConfigNetworks = (accounts: string[]): any => { - // Read and parse the JSON file - const dataBuffer = fs.readFileSync( - path.resolve(__dirname, "..", "data", "networks.json") - ); - const dataJson: any = JSON.parse(dataBuffer.toString()); +export const networks = JSON.parse( + fs + .readFileSync(path.resolve(__dirname, "..", "data", "networks.json")) + .toString() +); +export const getHardhatConfigNetworks = (accounts: string[]): any => { const config: any = {}; // Loop through the JSON object and create the required structure - for (const network in dataJson) { - let apiUrls = dataJson[network].api; + for (const network in networks) { + let apiUrls = networks[network].api; let evmApi = apiUrls?.find((api: any) => api.type === "evm"); config[network] = { accounts, - chainId: dataJson[network].chain_id, - gas: dataJson[network].fees.assets[0].gas, - gasPrice: dataJson[network].fees.assets[0].gas_price, + chainId: networks[network].chain_id, + gas: networks[network].fees.assets[0].gas, + gasPrice: networks[network].fees.assets[0].gas_price, url: evmApi?.url || "", }; } return config; }; + +// Temporary function that maps chain IDs to the old chain names +// used by @zetachain/addresses +export const chainNameById = (chainId: number): any => { + return { + 7001: "athens", + 97: "bsc-testnet", + 5: "goerli", + 1001: "klaytn-baobab", + 80001: "polygon-mumbai", + }[chainId]; +}; From 77ecc00e3f13392d42acaea2d2820768aa5b4992 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Thu, 8 Jun 2023 14:21:50 +0400 Subject: [PATCH 2/4] 1.1.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3e645a2..1c4b057 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zetachain/networks", - "version": "1.0.0", + "version": "1.1.0", "description": "", "main": "dist/index.js", "scripts": { @@ -18,4 +18,4 @@ "ts-node": "^10.9.1", "typescript": "^5.0.4" } -} \ No newline at end of file +} From 6f209fcbf4df0157dd659f415f2ff27d952182eb Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Thu, 8 Jun 2023 14:50:40 +0400 Subject: [PATCH 3/4] 1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1c4b057..cbf085d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zetachain/networks", - "version": "1.1.0", + "version": "1.2.0", "description": "", "main": "dist/index.js", "scripts": { From 0b6aea8de63b0d6afa6ace432aff7647b7959110 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Thu, 8 Jun 2023 15:48:59 +0400 Subject: [PATCH 4/4] ci: publish action --- .github/workflows/publish-npm.yaml | 31 ++++++++++++++++++++++++++++++ package.json | 4 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-npm.yaml diff --git a/.github/workflows/publish-npm.yaml b/.github/workflows/publish-npm.yaml new file mode 100644 index 0000000..08a1bc0 --- /dev/null +++ b/.github/workflows/publish-npm.yaml @@ -0,0 +1,31 @@ +name: Publish to NPM + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "16" + registry-url: "https://registry.npmjs.org" + + - name: Install Dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Publish to NPM + run: yarn publish --new-version ${GITHUB_REF#refs/tags/v} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + GITHUB_REF: ${{ github.ref }} diff --git a/package.json b/package.json index cbf085d..25b9a43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zetachain/networks", - "version": "1.2.0", + "version": "0.0.0-set-on-publish", "description": "", "main": "dist/index.js", "scripts": { @@ -18,4 +18,4 @@ "ts-node": "^10.9.1", "typescript": "^5.0.4" } -} +} \ No newline at end of file