Skip to content

Commit 8c0c611

Browse files
authored
deploy streamregistry v5 (#927)
* deployment: iotex testnet also touched up deployment scripts so that the testnet deployment went nicely in one go. Next up: figure out a way to test if the deployment works! At least add the network to hub and test a happy path manually. * build: deploy script for iotex * WIP: iotex deployment automation in testnet * build: update package-lock.json * deploy: PRE deployment of StreamRegistryV5 not yet done, just for review * remove non StreamRegistryV5 related scripts from PR * remove non StreamRegistryV5 related deployment data from PR * remove non StreamRegistryV5 related scripts from PR * remove non StreamRegistryV5 related scripts from PR * remove non StreamRegistryV5 related deployment data from PR * remove non StreamRegistryV5 related scripts from PR * remove non StreamRegistryV5 related scripts from PR * reverted "WIP" script changes * add comment
1 parent ba44346 commit 8c0c611

File tree

7 files changed

+202
-7
lines changed

7 files changed

+202
-7
lines changed

package-lock.json

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/network-contracts/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
set -ex
33

44
rm -rf artifacts
5-
hardhat compile
6-
cp ../../node_modules/@ensdomains/ens-contracts/deployments/archive/PublicResolver_mainnet_9412610.sol/PublicResolver_mainnet_9412610.json artifacts/PublicResolver_mainnet_9412610.json
5+
npm run compile
76

87
rm -rf dist
98
tsc -p tsconfig.build.json

packages/network-contracts/hardhat.config.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import "@nomiclabs/hardhat-etherscan"
88
import "hardhat-contract-sizer"
99
// import "hardhat-gas-reporter"
1010

11+
import "./tasks/copyFilesAfterCompilation"
12+
1113
import { HardhatUserConfig } from "hardhat/types"
1214

1315
declare module "hardhat/types/config" {
1416
interface HardhatUserConfig {
15-
dependencyCompiler?: any;
16-
contractSizer?: any;
17+
dependencyCompiler?: any;
18+
contractSizer?: any;
19+
warnings?: any;
20+
etherscan?: any;
1721
}
1822
}
1923

@@ -90,7 +94,7 @@ const config: HardhatUserConfig = {
9094
chainId: 3338,
9195
url: "https://peaq.api.onfinality.io/public",
9296
accounts: [process.env.KEY || "0x5e98cce00cff5dea6b454889f359a4ec06b9fa6b88e9d69b86de8e1c81887da0"] // dummy key
93-
}
97+
},
9498
},
9599
dependencyCompiler: {
96100
paths: [
@@ -107,6 +111,10 @@ const config: HardhatUserConfig = {
107111
"@ensdomains/ens-contracts/contracts/registry/ENSRegistry.sol", // exported in exports.ts
108112
],
109113
},
114+
copyFilesAfterCompilation: [{
115+
from: "@ensdomains/ens-contracts/deployments/archive/PublicResolver_mainnet_9412610.sol/PublicResolver_mainnet_9412610.json",
116+
to: "./artifacts/PublicResolver_mainnet_9412610.json"
117+
}],
110118
solidity: {
111119
compilers: [
112120
{

packages/network-contracts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@metamask/eth-sig-util": "7.0.1",
6363
"@nomicfoundation/hardhat-chai-matchers": "1.0.5",
6464
"@nomicfoundation/hardhat-toolbox": "2.0.0",
65+
"@nomicfoundation/hardhat-verify": "2.0.11",
6566
"@opengsn/provider": "2.2.6",
6667
"@openzeppelin/hardhat-upgrades": "1.22.1",
6768
"@streamr/config": "^5.0.0",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
export CHAIN=polygon
5+
6+
# export CHAIN=polygonAmoy
7+
# export GAS_PRICE_GWEI=30 # prevent error about zero gas price
8+
9+
if declare -p KEY >/dev/null 2>&1; then
10+
echo "Using deployer private key from environment variable KEY"
11+
else
12+
read -p "Enter deployer private key: " KEY
13+
export KEY="$KEY"
14+
fi
15+
16+
export CONTRACT_NAME=StreamRegistryV5
17+
export OUTPUT_FILE=newImplementationAddress.txt
18+
export SCRIPT_FILE=scripts/upgradeStreamRegistry.ts
19+
npm run hardhatScript
20+
21+
# Verify & publish the contract source code on Polygonscan
22+
23+
if declare -p ETHERSCAN_KEY >/dev/null 2>&1; then
24+
echo "Using *scan API key from environment variable ETHERSCAN_KEY"
25+
else
26+
read -p "Enter Polygonscan API key: " ETHERSCAN_KEY
27+
export ETHERSCAN_KEY="$ETHERSCAN_KEY"
28+
fi
29+
30+
export ADDRESS=$(cat newImplementationAddress.txt)
31+
npm run verify
32+
33+
rm newImplementationAddress.txt

packages/network-contracts/scripts/upgradeStreamRegistry.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function main() {
6363
// log("Estimated gas cost: %s ETH (gas price %s gwei)", formatEther(estimatedGasCost), formatUnits(gasPrice, "gwei"))
6464

6565
const balanceBefore = await provider.getBalance(signer.address)
66-
log("Balance of %s: %s ETH", signer.address, formatEther(balanceBefore))
66+
log("Balance of %s: %s native tokens", signer.address, formatEther(balanceBefore))
6767
// if (balanceBefore.lt(estimatedGasCost)) {
6868
// if (!IGNORE_BALANCE) {
6969
// throw new Error(
@@ -78,7 +78,11 @@ async function main() {
7878
await getContractFactory(CONTRACT_NAME, { signer, txOverrides })
7979
) as StreamRegistryV5
8080
log("Checking new StreamRegistry at %s", upgradedStreamRegistry.address)
81-
log(" %s [OK]", await upgradedStreamRegistry.getUserKeyForUserId("test.eth/1", "0x1234"))
81+
try {
82+
log(" %s [OK]", await upgradedStreamRegistry.getUserKeyForUserId("test.eth/1", "0x1234"))
83+
} catch (error: any) {
84+
log("Error calling getUserKeyForUserId: %o", error.message)
85+
}
8286

8387
const implementationAddress = await upgrades.erc1967.getImplementationAddress(streamRegistry.address)
8488
log("Implementation address: %s", implementationAddress)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { copyFileSync, existsSync } from "fs"
2+
3+
import { task } from "hardhat/config"
4+
import { TASK_COMPILE } from "hardhat/builtin-tasks/task-names"
5+
6+
declare module "hardhat/types/config" {
7+
interface HardhatUserConfig {
8+
/** Copy files after compilation has finished successfully
9+
* @param from Source file to copy
10+
* @param to Destination filename
11+
*/
12+
copyFilesAfterCompilation?: {
13+
from: string,
14+
/** Destination directory + filename */
15+
to: string,
16+
}[];
17+
}
18+
19+
interface HardhatConfig {
20+
copyFilesAfterCompilation: [{
21+
from: string,
22+
to: string,
23+
}]
24+
}
25+
}
26+
27+
const prefixes = [
28+
"./",
29+
"./node_modules/",
30+
"../../node_modules/",
31+
"",
32+
]
33+
34+
task(TASK_COMPILE, async (_, hre, runSuper) => {
35+
await runSuper()
36+
hre?.config?.copyFilesAfterCompilation?.forEach(({ from, to }) => {
37+
const fromPath = prefixes.map((prefix) => prefix + from).find(existsSync)
38+
if (!fromPath) {
39+
throw new Error(`copyFilesAfterCompilation: File not found: ${from}`)
40+
}
41+
copyFileSync(fromPath, to)
42+
})
43+
})

0 commit comments

Comments
 (0)