Skip to content

Commit 2a41b69

Browse files
refactor: modify deploy script
1 parent 4f36d02 commit 2a41b69

File tree

4 files changed

+282
-304
lines changed

4 files changed

+282
-304
lines changed

.github/workflows/deploy_and_release.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v3
11-
- name: Use Node.js
11+
- name: Use Node.js
1212
uses: actions/setup-node@v3
1313
with:
1414
cache: 'npm'
@@ -38,20 +38,26 @@ jobs:
3838
get-network:
3939
runs-on: ubuntu-latest
4040
needs: [lint-and-test]
41-
outputs:
41+
outputs:
4242
network: ${{steps.network-name.outputs.result}}
43+
version: ${{steps.network-name.outputs.result}}
4344
steps:
4445
- name: GET NETWORK NAME
45-
id: network-name
46+
id: network-name
4647
uses: actions/github-script@v6
4748
with:
4849
github-token: ${{secrets.GITHUB_TOKEN}}
4950
result-encoding: string
5051
script: |
5152
const tag = process.env.GITHUB_REF_NAME;
52-
const regex = /v.*\-(eth|hteth|matic|tmatic|bsc|tbsc|arbeth|tarbeth|opeth|topeth|zketh|tzketh)$/;
53-
const network = tag.match(regex);
54-
return network ? network[1] : "hteth";
53+
const regex = (v[\d\.]+)\-(eth|hteth|matic|tmatic|bsc|tbsc|arbeth|tarbeth|opeth|topeth|zketh|tzketh)$
54+
const tagArray = tag.match(regex);
55+
const network = tagArray ? tagArray[2] : "hteth";
56+
const version = tarArray ? tagArray[1] : "v1.0";
57+
return {
58+
network: network,
59+
version: version
60+
};
5561
deploy-to-test:
5662
runs-on: ubuntu-latest
5763
needs: [lint-and-test, get-network]
@@ -82,7 +88,9 @@ jobs:
8288
BSCSCAN_API_KEY: ${{ secrets.BSCSCAN_API_KEY }}
8389
ARBISCAN_API_KEY: ${{ secrets.ARBISCAN_API_KEY }}
8490
OPTIMISTIC_ETHERSCAN_API_KEY: ${{ secrets.OPTIMISTIC_ETHERSCAN_API_KEY }}
85-
ZKSYNC_EXPLORER_API_KEY: ${{ secrets.ZKSYNC_EXPLORER_API_KEY }}
91+
ZKSYNC_EXPLORER_API_KEY: ${{ secrets.ZKSYNC_EXPLORER_API_KEY }},
92+
VERSION: ${{ needs.get-network.outputs.version }},
93+
ENV: 'TEST'
8694
- name: Update release notes
8795
uses: actions/github-script@v6
8896
with:
@@ -140,7 +148,9 @@ jobs:
140148
OPTIMISTIC_ETHERSCAN_API_KEY: ${{ secrets.OPTIMISTIC_ETHERSCAN_API_KEY }}
141149
ZKSYNC_EXPLORER_API_KEY: ${{ secrets.ZKSYNC_EXPLORER_API_KEY }}
142150
QUICKNODE_ARBITRUM_ONE_API_KEY: ${{ secrets.QUICKNODE_ARBITRUM_ONE_API_KEY }}
143-
QUICKNODE_OPTIMISM_API_KEY: ${{ secrets.QUICKNODE_OPTIMISM_API_KEY }}
151+
QUICKNODE_OPTIMISM_API_KEY: ${{ secrets.QUICKNODE_OPTIMISM_API_KEY }},
152+
VERSION: ${{ needs.get-network.outputs.version }},
153+
ENV: 'PROD'
144154
- name: Update release notes
145155
uses: actions/github-script@v6
146156
with:

hardhat.config.ts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,39 @@ const {
2727
BSCSCAN_API_KEY,
2828
ARBISCAN_API_KEY,
2929
OPTIMISTIC_ETHERSCAN_API_KEY,
30-
ZKSYNC_EXPLORER_API_KEY
30+
ZKSYNC_EXPLORER_API_KEY,
31+
VERSION,
32+
ENV
3133
} = process.env;
3234

35+
const version = VERSION ? VERSION.split('.')[0] : 'v1';
36+
37+
const privateKey: { [key: string]: string } = {
38+
v4Prod: PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT ?? '',
39+
v4Test: PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT ?? '',
40+
v2Prod: MAINNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT ?? '',
41+
v2Test: TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT ?? '',
42+
v1ProdTestWallet: PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT ?? '',
43+
v1ProdTestForwarder: PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP ?? ''
44+
};
45+
46+
function getPrivateKey(version: string): string[] {
47+
switch (version) {
48+
case 'v1':
49+
return [
50+
privateKey['v1ProdTestWallet'],
51+
privateKey['v1ProdTestForwarder']
52+
];
53+
case 'v2':
54+
return ENV === 'TEST' ? [privateKey['v2Test']] : [privateKey['v2Prod']];
55+
case 'v4':
56+
return ENV === 'TEST' ? [privateKey['v4Test']] : [privateKey['v4Prod']];
57+
default:
58+
console.error('Invalid Version Number or Tag');
59+
process.exit(1);
60+
}
61+
}
62+
3363
const config: HardhatUserConfig = {
3464
solidity: {
3565
compilers: [
@@ -67,60 +97,48 @@ const config: HardhatUserConfig = {
6797
},
6898
eth: {
6999
url: `https://ethereum-rpc.publicnode.com`,
70-
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
100+
accounts: getPrivateKey(version)
71101
},
72102
hteth: {
73103
url: `https://rpc.holesky.ethpandaops.io/`,
74-
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`]
104+
accounts: getPrivateKey(version)
75105
},
76106
matic: {
77107
url: `https://polygon-rpc.com/`,
78-
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
108+
accounts: getPrivateKey(version)
79109
},
80110
tmatic: {
81111
// https://polygon-amoy.g.alchemy.com
82112
url: `https://polygon-amoy-bor-rpc.publicnode.com`,
83-
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
113+
accounts: getPrivateKey(version)
84114
},
85115
bsc: {
86116
url: `https://bsc-dataseed1.binance.org/`,
87-
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
117+
accounts: getPrivateKey(version)
88118
},
89119
tbsc: {
90120
url: `https://data-seed-prebsc-1-s1.binance.org:8545/`,
91-
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
121+
accounts: getPrivateKey(version)
92122
},
93123
tarbeth: {
94124
url: `${QUICKNODE_ARBITRUM_SEPOLIA_API_KEY}`,
95-
accounts: [
96-
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
97-
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
98-
]
125+
accounts: getPrivateKey(version)
99126
},
100127
arbeth: {
101128
url: `${QUICKNODE_ARBITRUM_ONE_API_KEY}`,
102-
accounts: [
103-
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
104-
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
105-
]
129+
accounts: getPrivateKey(version)
106130
},
107131
topeth: {
108132
url: `${QUICKNODE_OPTIMISM_SEPOLIA_API_KEY}`,
109-
accounts: [
110-
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
111-
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
112-
]
133+
accounts: getPrivateKey(version)
113134
},
114135
opeth: {
115136
url: `${QUICKNODE_OPTIMISM_API_KEY}`,
116-
accounts: [
117-
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
118-
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
119-
]
137+
accounts: getPrivateKey(version)
120138
},
121139
tzketh: {
122140
url: `${QUICKNODE_ZKSYNC_SEPOLIA_API_KEY}`,
123-
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
141+
accounts: getPrivateKey(version)
124142
}
125143
},
126144
gasReporter: {

0 commit comments

Comments
 (0)