Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/network-contracts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
set -ex

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

rm -rf dist
tsc -p tsconfig.build.json
Expand Down
14 changes: 11 additions & 3 deletions packages/network-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import "@nomiclabs/hardhat-etherscan"
import "hardhat-contract-sizer"
// import "hardhat-gas-reporter"

import "./tasks/copyFilesAfterCompilation"

import { HardhatUserConfig } from "hardhat/types"

declare module "hardhat/types/config" {
interface HardhatUserConfig {
dependencyCompiler?: any;
contractSizer?: any;
dependencyCompiler?: any;
contractSizer?: any;
warnings?: any;
etherscan?: any;
}
}

Expand Down Expand Up @@ -90,7 +94,7 @@ const config: HardhatUserConfig = {
chainId: 3338,
url: "https://peaq.api.onfinality.io/public",
accounts: [process.env.KEY || "0x5e98cce00cff5dea6b454889f359a4ec06b9fa6b88e9d69b86de8e1c81887da0"] // dummy key
}
},
},
dependencyCompiler: {
paths: [
Expand All @@ -107,6 +111,10 @@ const config: HardhatUserConfig = {
"@ensdomains/ens-contracts/contracts/registry/ENSRegistry.sol", // exported in exports.ts
],
},
copyFilesAfterCompilation: [{
from: "@ensdomains/ens-contracts/deployments/archive/PublicResolver_mainnet_9412610.sol/PublicResolver_mainnet_9412610.json",
to: "./artifacts/PublicResolver_mainnet_9412610.json"
}],
solidity: {
compilers: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/network-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@metamask/eth-sig-util": "7.0.1",
"@nomicfoundation/hardhat-chai-matchers": "1.0.5",
"@nomicfoundation/hardhat-toolbox": "2.0.0",
"@nomicfoundation/hardhat-verify": "2.0.11",
"@opengsn/provider": "2.2.6",
"@openzeppelin/hardhat-upgrades": "1.22.1",
"@streamr/config": "^5.0.0",
Expand Down
33 changes: 33 additions & 0 deletions packages/network-contracts/scripts/2024-11-14-streamregistry-v5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euxo pipefail

export CHAIN=polygon

# export CHAIN=polygonAmoy
# export GAS_PRICE_GWEI=30 # prevent error about zero gas price

if declare -p KEY >/dev/null 2>&1; then
echo "Using deployer private key from environment variable KEY"
else
read -p "Enter deployer private key: " KEY
export KEY="$KEY"
fi

export CONTRACT_NAME=StreamRegistryV5
export OUTPUT_FILE=newImplementationAddress.txt
export SCRIPT_FILE=scripts/upgradeStreamRegistry.ts
npm run hardhatScript

# Verify & publish the contract source code on Polygonscan

if declare -p ETHERSCAN_KEY >/dev/null 2>&1; then
echo "Using *scan API key from environment variable ETHERSCAN_KEY"
else
read -p "Enter Polygonscan API key: " ETHERSCAN_KEY
export ETHERSCAN_KEY="$ETHERSCAN_KEY"
fi

export ADDRESS=$(cat newImplementationAddress.txt)
npm run verify

rm newImplementationAddress.txt
8 changes: 6 additions & 2 deletions packages/network-contracts/scripts/upgradeStreamRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function main() {
// log("Estimated gas cost: %s ETH (gas price %s gwei)", formatEther(estimatedGasCost), formatUnits(gasPrice, "gwei"))

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

const implementationAddress = await upgrades.erc1967.getImplementationAddress(streamRegistry.address)
log("Implementation address: %s", implementationAddress)
Expand Down
43 changes: 43 additions & 0 deletions packages/network-contracts/tasks/copyFilesAfterCompilation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { copyFileSync, existsSync } from "fs"

import { task } from "hardhat/config"
import { TASK_COMPILE } from "hardhat/builtin-tasks/task-names"

declare module "hardhat/types/config" {
interface HardhatUserConfig {
/** Copy files after compilation has finished successfully
* @param from Source file to copy
* @param to Destination filename
*/
copyFilesAfterCompilation?: {
from: string,
/** Destination directory + filename */
to: string,
}[];
}

interface HardhatConfig {
copyFilesAfterCompilation: [{
from: string,
to: string,
}]
}
}

const prefixes = [
"./",
"./node_modules/",
"../../node_modules/",
"",
]

task(TASK_COMPILE, async (_, hre, runSuper) => {
await runSuper()
hre?.config?.copyFilesAfterCompilation?.forEach(({ from, to }) => {
const fromPath = prefixes.map((prefix) => prefix + from).find(existsSync)
if (!fromPath) {
throw new Error(`copyFilesAfterCompilation: File not found: ${from}`)
}
copyFileSync(fromPath, to)
})
})
Loading