Skip to content

Commit 9ab6b77

Browse files
jtakalaiteogeb
andauthored
build(hub-contracts): fully automated deploy script (#1029)
replace in-between manual config update step --------- Co-authored-by: Teo Gebhard <[email protected]>
1 parent 72c0776 commit 9ab6b77

File tree

5 files changed

+88
-13
lines changed

5 files changed

+88
-13
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
if declare -p KEY >/dev/null 2>&1; then
5+
echo "Using deployer private key from environment variable KEY"
6+
else
7+
read -p "Enter deployer private key: " KEY
8+
export KEY="$KEY"
9+
fi
10+
11+
if declare -p CHAIN >/dev/null 2>&1; then
12+
echo "Using chain from environment variable CHAIN"
13+
else
14+
read -p "Enter chain: " CHAIN
15+
export CHAIN="$CHAIN"
16+
fi
17+
18+
OUTPUT_FILE=project-registry-address.txt npx hardhat run --network $CHAIN scripts/hub/deployProjectRegistry.ts
19+
export PROJECT_REGISTRY_ADDRESS=$(cat project-registry-address.txt)
20+
OUTPUT_FILE=project-staking-address.txt npx hardhat run --network $CHAIN scripts/hub/deployProjectStakingV1.ts
21+
OUTPUT_FILE=marketplace-address.txt npx hardhat run --network $CHAIN scripts/hub/deployMarketplaceV4.ts
22+
set +x
23+
echo "{"
24+
echo " \"ProjectRegistryV1\": \"$PROJECT_REGISTRY_ADDRESS\","
25+
echo " \"MarketplaceV4\": \"$(cat marketplace-address.txt)\","
26+
echo " \"ProjectStakingV1\": \"$(cat project-staking-address.txt)\""
27+
echo "}"
28+
29+
rm project-registry-address.txt
30+
rm project-staking-address.txt
31+
rm marketplace-address.txt

packages/network-contracts/scripts/hub/deployMarketplaceV4.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable quotes */
2+
import { writeFileSync } from "fs"
23
import { ethers as hardhatEthers, upgrades } from "hardhat"
34
import { config } from "@streamr/config"
45
import { utils } from "ethers"
@@ -10,15 +11,21 @@ const { log } = console
1011

1112
const {
1213
CHAIN = 'dev1',
14+
PROJECT_REGISTRY_ADDRESS,
15+
OUTPUT_FILE,
1316
} = process.env
1417

1518
const {
1619
id: CHAIN_ID,
1720
contracts: {
18-
ProjectRegistryV1: PROJECT_REGISTRY_ADDRESS,
21+
ProjectRegistryV1: PROJECT_REGISTRY_ADDRESS_FROM_CONFIG,
1922
}
2023
} = (config as any)[CHAIN]
21-
if (!PROJECT_REGISTRY_ADDRESS) { throw new Error(`No ProjectRegistryV1 found in chain "${CHAIN}"`) }
24+
25+
const projectRegistryAddress = PROJECT_REGISTRY_ADDRESS || PROJECT_REGISTRY_ADDRESS_FROM_CONFIG
26+
if (!projectRegistryAddress) {
27+
throw new Error(`No ProjectRegistryV1 found in chain "${CHAIN}", please supply it in env variable PROJECT_REGISTRY_ADDRESS`)
28+
}
2229

2330
const interchainMailbox = chainToMailboxAddress(CHAIN)
2431

@@ -28,10 +35,10 @@ const interchainMailbox = chainToMailboxAddress(CHAIN)
2835
*/
2936
async function main() {
3037
log(`Deploying MarketplaceV4 to ${CHAIN}:`)
31-
log(` - project registry address: ${PROJECT_REGISTRY_ADDRESS}`)
38+
log(` - project registry address: ${projectRegistryAddress}`)
3239

3340
const projectRegistryFactory = await getContractFactory("ProjectRegistryV1")
34-
const projectRegistryFactoryTx = await projectRegistryFactory.attach(PROJECT_REGISTRY_ADDRESS)
41+
const projectRegistryFactoryTx = await projectRegistryFactory.attach(projectRegistryAddress)
3542
const projectRegistry = await projectRegistryFactoryTx.deployed()
3643
log("ProjectRegistryV1 attached at: ", projectRegistry.address)
3744

@@ -41,11 +48,19 @@ async function main() {
4148
await marketplace.deployed()
4249
log(`MarketplaceV4 deployed on ${CHAIN} at: ${marketplace.address}`)
4350

44-
await marketplace.addMailbox(interchainMailbox)
45-
log(`MarketplaceV4 added interchain mailbox: ${interchainMailbox}`)
46-
51+
try {
52+
await (await marketplace.addMailbox(interchainMailbox)).wait()
53+
log(`MarketplaceV4 added interchain mailbox: ${interchainMailbox}`)
54+
} catch (error) {
55+
log(`Error when setting interchain mailbox: ${error}`)
56+
}
4757
await projectRegistry.grantRole(id("TRUSTED_ROLE"), marketplace.address)
4858
log(`ProjectRegistry granted trusted role to MarketplaceV4.`)
59+
60+
if (OUTPUT_FILE) {
61+
writeFileSync(OUTPUT_FILE, marketplace.address)
62+
log(`MarketplaceV4 address written to ${OUTPUT_FILE}`)
63+
}
4964
}
5065

5166
main().catch((error) => {

packages/network-contracts/scripts/hub/deployProjectRegistry.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/* eslint-disable quotes */
2+
import { writeFileSync } from "fs"
3+
24
import { ethers as hhEthers, upgrades } from "hardhat"
35
import { config } from "@streamr/config"
46

57
const { log } = console
68

79
const {
810
CHAIN = 'dev1',
11+
OUTPUT_FILE,
912
} = process.env
1013

1114
const {
@@ -28,6 +31,11 @@ async function main() {
2831
const projectRegistryFactoryTx = await upgrades.deployProxy(projectRegistryFactory, [STREAM_REGISTRY_ADDRESS], { kind: 'uups' })
2932
const projectRegistry = await projectRegistryFactoryTx.deployed()
3033
log(`ProjectRegistryV1 deployed at: ${projectRegistry.address}`)
34+
35+
if (OUTPUT_FILE) {
36+
writeFileSync(OUTPUT_FILE, projectRegistry.address)
37+
log(`ProjectRegistryV1 address written to ${OUTPUT_FILE}`)
38+
}
3139
}
3240

3341
main().catch((error) => {

packages/network-contracts/scripts/hub/deployProjectStakingV1.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
11
/* eslint-disable quotes */
2+
import { writeFileSync } from "fs"
3+
24
import { ethers as hhEthers, upgrades } from "hardhat"
35
import { config } from "@streamr/config"
46

57
const { log } = console
68

79
const {
810
CHAIN = 'dev1',
11+
PROJECT_REGISTRY_ADDRESS,
12+
OUTPUT_FILE,
913
} = process.env
1014

1115
const {
1216
contracts: {
1317
DATA: STAKING_TOKEN_ADDRESS, // LINK dev1 - 0x3387F44140ea19100232873a5aAf9E46608c791E
14-
ProjectRegistryV1: PROJECT_REGISTRY_ADDRESS,
18+
ProjectRegistryV1: PROJECT_REGISTRY_ADDRESS_FROM_CONFIG,
1519
}
1620
} = (config as any)[CHAIN]
1721

18-
if (!PROJECT_REGISTRY_ADDRESS) { throw new Error(`No ProjectRegistryV1 found in chain "${CHAIN}"`) }
22+
const projectRegistryAddress = PROJECT_REGISTRY_ADDRESS || PROJECT_REGISTRY_ADDRESS_FROM_CONFIG
23+
24+
if (!projectRegistryAddress) {
25+
throw new Error(`No ProjectRegistryV1 found in chain "${CHAIN}", please supply it in env variable PROJECT_REGISTRY_ADDRESS`)
26+
}
1927

2028
/**
2129
* npx hardhat run --network dev1 scripts/deployProjectStakingV1.ts
2230
* npx hardhat flatten contracts/ProjectStaking/ProjectStakingV1.sol > ps.sol
2331
*/
2432
async function main() {
25-
log(`ProjectRegistryV1 address: ${PROJECT_REGISTRY_ADDRESS}`)
33+
log(`ProjectRegistryV1 address: ${projectRegistryAddress}`)
2634
log(`Staking token address: ${STAKING_TOKEN_ADDRESS}`)
2735
log(`Deploying ProjectStakingV1 to "${CHAIN}" chain:`)
2836
const projectStakingFactory = await hhEthers.getContractFactory("ProjectStakingV1")
2937
const projectStakingFactoryTx = await upgrades.deployProxy(projectStakingFactory, [
30-
PROJECT_REGISTRY_ADDRESS,
38+
projectRegistryAddress,
3139
STAKING_TOKEN_ADDRESS
3240
], { kind: 'uups' })
3341
const projectStaking = await projectStakingFactoryTx.deployed()
3442
log(`ProjectStakingV1 deployed at: ${projectStaking.address}`)
43+
44+
if (OUTPUT_FILE) {
45+
writeFileSync(OUTPUT_FILE, projectStaking.address)
46+
log(`ProjectStakingV1 address written to ${OUTPUT_FILE}`)
47+
}
3548
}
3649

3750
main().catch((error) => {

packages/network-contracts/scripts/hub/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable quotes */
2-
const testnet = ['alfajores', 'fuji', 'goerli', 'optGoerli', 'arbGoerli', 'polygonAmoy', 'peaq']
3-
const mainnet = ['celo', 'avalanche', 'polygon', 'gnosis', 'ethereum', 'optimism', 'arbitrum']
2+
const testnet = ['alfajores', 'fuji', 'goerli', 'optGoerli', 'arbGoerli', 'polygonAmoy', 'dev2']
3+
const mainnet = ['celo', 'avalanche', 'polygon', 'gnosis', 'ethereum', 'optimism', 'arbitrum', 'peaq', 'iotex']
44

55
/**
66
* Maps the chain name to a unique hyperlane domain id
@@ -27,6 +27,12 @@ export function chainToDomainId(name: string): number {
2727
return 8995
2828
case 'dev1':
2929
return 8997
30+
case 'dev2':
31+
return 31337
32+
case 'iotex':
33+
return 4689
34+
case 'peaq':
35+
return 3338
3036
default:
3137
throw new Error(`Unknown domain id for the given chain name (${name}).`)
3238
}
@@ -103,6 +109,8 @@ export function chainToEthereumRpcUrl(name: string): string {
103109
return `https://avalanche-fuji.infura.io/v3/${process.env.FUJI_API_KEY}`
104110
case 'dev1':
105111
return 'http://10.200.10.1:8546'
112+
case 'dev2':
113+
return 'http://10.200.10.1:8547'
106114

107115
default:
108116
throw new Error('Unknown ethereum RPC URL for the given chain name.')

0 commit comments

Comments
 (0)