Skip to content

Commit

Permalink
refactor: modify deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
venkateshv1266 committed Jul 12, 2024
1 parent 4f36d02 commit fd64a3f
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 321 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/deploy_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: 'npm'
Expand Down Expand Up @@ -38,20 +38,26 @@ jobs:
get-network:
runs-on: ubuntu-latest
needs: [lint-and-test]
outputs:
outputs:
network: ${{steps.network-name.outputs.result}}
version: ${{steps.network-name.outputs.result}}
steps:
- name: GET NETWORK NAME
id: network-name
id: network-name
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const tag = process.env.GITHUB_REF_NAME;
const regex = /v.*\-(eth|hteth|matic|tmatic|bsc|tbsc|arbeth|tarbeth|opeth|topeth|zketh|tzketh)$/;
const network = tag.match(regex);
return network ? network[1] : "hteth";
const regex = (v[\d\.]+)\-(eth|hteth|matic|tmatic|bsc|tbsc|arbeth|tarbeth|opeth|topeth|zketh|tzketh)$
const tagArray = tag.match(regex);
const network = tagArray ? tagArray[2] : "hteth";
const version = tarArray ? tagArray[1] : "v1.0";
return {
network: network,
version: version
};
deploy-to-test:
runs-on: ubuntu-latest
needs: [lint-and-test, get-network]
Expand Down Expand Up @@ -82,7 +88,9 @@ jobs:
BSCSCAN_API_KEY: ${{ secrets.BSCSCAN_API_KEY }}
ARBISCAN_API_KEY: ${{ secrets.ARBISCAN_API_KEY }}
OPTIMISTIC_ETHERSCAN_API_KEY: ${{ secrets.OPTIMISTIC_ETHERSCAN_API_KEY }}
ZKSYNC_EXPLORER_API_KEY: ${{ secrets.ZKSYNC_EXPLORER_API_KEY }}
ZKSYNC_EXPLORER_API_KEY: ${{ secrets.ZKSYNC_EXPLORER_API_KEY }},
VERSION: ${{ needs.get-network.outputs.version }},
ENV: 'TEST'
- name: Update release notes
uses: actions/github-script@v6
with:
Expand Down Expand Up @@ -140,7 +148,9 @@ jobs:
OPTIMISTIC_ETHERSCAN_API_KEY: ${{ secrets.OPTIMISTIC_ETHERSCAN_API_KEY }}
ZKSYNC_EXPLORER_API_KEY: ${{ secrets.ZKSYNC_EXPLORER_API_KEY }}
QUICKNODE_ARBITRUM_ONE_API_KEY: ${{ secrets.QUICKNODE_ARBITRUM_ONE_API_KEY }}
QUICKNODE_OPTIMISM_API_KEY: ${{ secrets.QUICKNODE_OPTIMISM_API_KEY }}
QUICKNODE_OPTIMISM_API_KEY: ${{ secrets.QUICKNODE_OPTIMISM_API_KEY }},
VERSION: ${{ needs.get-network.outputs.version }},
ENV: 'PROD'
- name: Update release notes
uses: actions/github-script@v6
with:
Expand Down
63 changes: 39 additions & 24 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,36 @@ const {
BSCSCAN_API_KEY,
ARBISCAN_API_KEY,
OPTIMISTIC_ETHERSCAN_API_KEY,
ZKSYNC_EXPLORER_API_KEY
ZKSYNC_EXPLORER_API_KEY,
VERSION,
ENV
} = process.env;

const version = (VERSION ? VERSION.split(".")[0] : "v1");

const privateKey: { [key: string]: string } = {
v4Prod: PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT ?? "",
v4Test: PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT ?? "",
v2Prod: MAINNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT ?? "",
v2Test: TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT ?? "",
v1ProdTestWallet: PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT ?? "",
v1ProdTestForwarder: PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP ?? "",
};

function getPrivateKey(version : string) : string[] {
switch (version){
case "v1":
return [privateKey["v1ProdTestWallet"], privateKey["v1ProdTestForwarder"]]
case "v2":
return ENV === "TEST" ? [privateKey["v2Test"]] : [privateKey["v2Prod"]];
case "v4":
return ENV === "TEST" ? [privateKey["v4Test"]] : [privateKey["v4Prod"]];
default:
console.error("Invalid Version Number or Tag");
process.exit(1);
}
}

const config: HardhatUserConfig = {
solidity: {
compilers: [
Expand Down Expand Up @@ -67,60 +94,48 @@ const config: HardhatUserConfig = {
},
eth: {
url: `https://ethereum-rpc.publicnode.com`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
accounts: getPrivateKey(version)
},
hteth: {
url: `https://rpc.holesky.ethpandaops.io/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`]
accounts: getPrivateKey(version)
},
matic: {
url: `https://polygon-rpc.com/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
accounts: getPrivateKey(version)
},
tmatic: {
// https://polygon-amoy.g.alchemy.com
url: `https://polygon-amoy-bor-rpc.publicnode.com`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
accounts: getPrivateKey(version)
},
bsc: {
url: `https://bsc-dataseed1.binance.org/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
accounts: getPrivateKey(version)
},
tbsc: {
url: `https://data-seed-prebsc-1-s1.binance.org:8545/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
accounts: getPrivateKey(version)
},
tarbeth: {
url: `${QUICKNODE_ARBITRUM_SEPOLIA_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
accounts: getPrivateKey(version)
},
arbeth: {
url: `${QUICKNODE_ARBITRUM_ONE_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
accounts: getPrivateKey(version)
},
topeth: {
url: `${QUICKNODE_OPTIMISM_SEPOLIA_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
accounts: getPrivateKey(version)
},
opeth: {
url: `${QUICKNODE_OPTIMISM_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
accounts: getPrivateKey(version)
},
tzketh: {
url: `${QUICKNODE_ZKSYNC_SEPOLIA_API_KEY}`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
accounts: getPrivateKey(version)
}
},
gasReporter: {
Expand Down
Loading

0 comments on commit fd64a3f

Please sign in to comment.