Skip to content

Commit 7fef22f

Browse files
committed
feat: add deployment workflow and update config script for new networks
1 parent df8c19d commit 7fef22f

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Deploy PoCo Contracts
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
network:
6+
description: 'Target Network'
7+
required: true
8+
type: choice
9+
options:
10+
- hardhat
11+
- avalancheFujiTestnet
12+
- arbitrumSepolia
13+
- bellecour
14+
environment:
15+
description: 'Deployment Environment'
16+
required: true
17+
type: choice
18+
options:
19+
- develop
20+
- production
21+
default: 'develop'
22+
23+
jobs:
24+
deploy:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: write # Required for saving deployment
28+
environment: ${{ inputs.environment }} # Use the selected environment
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Nodejs
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 20
37+
cache: 'npm' # Cache dependencies
38+
39+
- name: Install dependencies
40+
run: npm ci
41+
42+
- name: Run tests
43+
if: inputs.environment != 'production'
44+
run: |
45+
if [ "${{ inputs.network }}" == "arbitrumSepolia" ]; then
46+
npm run test:arbitrumSepolia
47+
elif [ "${{ inputs.network }}" == "avalancheFujiTestnet" ]; then
48+
npm run test:fuji
49+
else
50+
npm run test
51+
fi
52+
53+
- name: Deploy contracts
54+
env:
55+
PRIVATE_KEY: ${{ inputs.environment == 'production' ? secrets.PROD_PRIVATE_KEY : secrets.DEV_PRIVATE_KEY }}
56+
FUJI_RPC_URL: ${{ inputs.network == 'avalancheFujiTestnet' && secrets.FUJI_RPC_URL || '' }}
57+
ARBITRUM_SEPOLIA_RPC_URL: ${{ inputs.network == 'arbitrumSepolia' && secrets.ARBITRUM_SEPOLIA_RPC_URL || '' }}
58+
BELLECOUR_RPC_URL: ${{ inputs.network == 'bellecour' && secrets.BELLECOUR_RPC_URL || '' }}
59+
run: |
60+
echo "Deploying to: ${{ inputs.network }} with ${{ inputs.environment }} environment"
61+
npm run deploy -- --network ${{ inputs.network }}
62+
63+
- name: Update config.json with ERC1538Proxy address
64+
run: |
65+
if [ -f "deployments/${{ inputs.network }}/ERC1538Proxy.json" ]; then
66+
PROXY_ADDRESS=$(jq -r '.address' deployments/${{ inputs.network }}/ERC1538Proxy.json)
67+
# Verify we have an address before updating
68+
if [ -n "$PROXY_ADDRESS" ] && [ "$PROXY_ADDRESS" != "null" ]; then
69+
echo "Found ERC1538Proxy address: $PROXY_ADDRESS"
70+
# Update config.json using our script
71+
node scripts/update-config.js "${{ inputs.network }}" "ERC1538Proxy" "$PROXY_ADDRESS"
72+
else
73+
echo "Failed to extract a valid ERC1538Proxy address"
74+
fi
75+
else
76+
echo "ERC1538Proxy deployment file not found. Skipping config update."
77+
fi
78+
79+
- name: Save deployment artifacts and updated config
80+
uses: stefanzweifel/git-auto-commit-action@v5
81+
with:
82+
commit_message: "chore: save deployment artifacts for ${{ inputs.network }} (${{ inputs.environment }}, ${{ github.run_id }})"
83+
file_pattern: 'deployments/${{ inputs.network }}/* config/config.json'
84+
commit_user_name: "GitHub Actions Bot"
85+
commit_user_email: "github-actions[bot]@users.noreply.github.com"
86+
commit_author: "GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>"
87+
88+
- name: Verify contracts
89+
if: inputs.network != 'hardhat'
90+
env:
91+
PRIVATE_KEY: ${{ inputs.environment == 'production' ? secrets.PROD_PRIVATE_KEY : secrets.DEV_PRIVATE_KEY }}
92+
FUJI_RPC_URL: ${{ inputs.network == 'avalancheFujiTestnet' && secrets.FUJI_RPC_URL || '' }}
93+
ARBITRUM_SEPOLIA_RPC_URL: ${{ inputs.network == 'arbitrumSepolia' && secrets.ARBITRUM_SEPOLIA_RPC_URL || '' }}
94+
BELLECOUR_RPC_URL: ${{ inputs.network == 'bellecour' && secrets.BELLECOUR_RPC_URL || '' }}
95+
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
96+
ARBISCAN_API_KEY: ${{ secrets.ARBISCAN_API_KEY }}
97+
SNOWTRACE_API_KEY: ${{ secrets.SNOWTRACE_API_KEY }}
98+
run: |
99+
# Add a delay to allow block explorers to index the contracts
100+
echo "Waiting for contracts to be indexed..."
101+
sleep 60
102+
npx hardhat run ./scripts/verify.ts --network ${{ inputs.network }}

scripts/tools/update-config.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
// Map network names to chain IDs
5+
const NETWORK_TO_CHAIN_ID = {
6+
hardhat: "31337",
7+
avalancheFujiTestnet: "43113",
8+
arbitrumSepolia: "421614",
9+
bellecour: "134"
10+
};
11+
12+
// Get arguments from command line
13+
const [networkName, contractKey, contractAddress] = process.argv.slice(2);
14+
15+
if (!networkName || !contractKey || !contractAddress) {
16+
console.error("Usage: node update-config.js <networkName> <contractKey> <address>");
17+
process.exit(1);
18+
}
19+
20+
const chainId = NETWORK_TO_CHAIN_ID[networkName];
21+
if (!chainId) {
22+
console.error(`Unknown network: ${networkName}`);
23+
process.exit(1);
24+
}
25+
26+
// Read config file
27+
const configPath = path.resolve("config/config.json");
28+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
29+
30+
// Ensure the chain structure exists
31+
if (!config.chains) {
32+
config.chains = {};
33+
}
34+
35+
if (!config.chains[chainId]) {
36+
config.chains[chainId] = {
37+
v5: {}
38+
};
39+
}
40+
41+
if (!config.chains[chainId].v5) {
42+
config.chains[chainId].v5 = {};
43+
}
44+
45+
// Update the contract address
46+
const previousValue = config.chains[chainId].v5[contractKey] || "null";
47+
config.chains[chainId].v5[contractKey] = contractAddress;
48+
49+
// Write the updated config back to file
50+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
51+
52+
console.log(`Updated ${chainId}.v5.${contractKey}:`);
53+
console.log(`Previous: ${previousValue}`);
54+
console.log(`New: ${contractAddress}`);

0 commit comments

Comments
 (0)