From 7f4fdf22688d47b9de9b524c0e2467d42a7cd098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Thu, 15 Jun 2023 14:02:06 -0400 Subject: [PATCH 1/7] feat: add predict contract address script --- scripts/predict-const-address.ts | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/predict-const-address.ts diff --git a/scripts/predict-const-address.ts b/scripts/predict-const-address.ts new file mode 100644 index 0000000..165360c --- /dev/null +++ b/scripts/predict-const-address.ts @@ -0,0 +1,52 @@ +import { utils, Wallet } from 'ethers' +import fs from 'fs' + +import { + Arg, + ContractOutputJSON, + predictContractConstant, +} from './const-addr-deployer' + +const main = async function (..._args: Arg[]) { + const [contractJsonPath, salt, ...args] = _args + const privateKey = process.env.PRIVATE_KEY + + if (!privateKey || !utils.isHexString(privateKey, 32)) { + console.error('ERROR: Please provide a valid private key! (PRIVATE_KEY)') + return + } + + const wallet = new Wallet(process.env.PRIVATE_KEY || '') + + let rawdata + try { + rawdata = fs.readFileSync(contractJsonPath) + } catch (error) { + console.error( + `ERROR: Could not find a contract JSON file at ${contractJsonPath}` + ) + return + } + + let contractJson: ContractOutputJSON + try { + contractJson = JSON.parse(rawdata.toString()) + } catch (error) { + console.error( + `ERROR: Could not parse the contract JSON file found at ${contractJsonPath}` + ) + return + } + + const address = await predictContractConstant( + wallet, + contractJson, + salt, + args + ).catch(console.error) + + return address +} + +const args = process.argv.slice(2) +main(...args) From 062c36068acc5e64e62717f5579b825019dfc70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Thu, 15 Jun 2023 14:21:30 -0400 Subject: [PATCH 2/7] fix: add missing npm script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8e4999d..25956c9 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "lint:sol:fix": "npm run lint:sol -- --fix", "lint:ts": "eslint --ext .ts .", "lint:ts:fix": "npm run lint:ts -- --fix", + "predict-const-address": "ts-node scripts/predict-const-address.ts", "register-subnet": "ts-node scripts/register-subnet.ts", "test": "hardhat test" }, From 351a6f90afc15c2dc2b85be792a014214dd06417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Thu, 15 Jun 2023 15:14:07 -0400 Subject: [PATCH 3/7] feat: get address from deploy script instead --- scripts/deploy.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 2624d1d..f344512 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -39,7 +39,7 @@ const main = async function (..._args: Arg[]) { return } - await deployContractConstant( + const address = await deployContractConstant( wallet, contractJson, salt, @@ -52,8 +52,11 @@ const main = async function (..._args: Arg[]) { (contractJsonPath).split('.json')[0] } at ${contract.address}` ) + return contract.address }) .catch(console.error) + + return address } const args = process.argv.slice(2) From cc74084a4369764280de0d73e597aaab5deae533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Thu, 15 Jun 2023 15:24:57 -0400 Subject: [PATCH 4/7] feat: return addresses of all contracts --- scripts/deploy-topos-msg-protocol.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/deploy-topos-msg-protocol.ts b/scripts/deploy-topos-msg-protocol.ts index 6561912..f0222a0 100644 --- a/scripts/deploy-topos-msg-protocol.ts +++ b/scripts/deploy-topos-msg-protocol.ts @@ -88,7 +88,7 @@ const main = async function (...args: string[]) { 4_000_000 ) - await processContract( + const erc20MessagingAddresss = await processContract( 'ERC20Messaging', wallet, erc20MessagingJSON, @@ -98,6 +98,13 @@ const main = async function (...args: string[]) { ) setSubnetId(toposCoreProxyAddress, wallet, subnetId) + + return ` + export TOPOS_CORE_CONTRACT_ADDRESS=${toposCoreAddress} + export TOPOS_CORE_PROXY_CONTRACT_ADDRESS=${toposCoreProxyAddress} + export TOKEN_DEPLOYER_CONTRACT_ADDRESS=${tokenDeployerAddress} + export ERC20_MESSAGING_CONTRACT_ADDRESS=${erc20MessagingAddresss} + ` } const sanitizeHexString = function (hexString: string) { From 951709ddc295f24a43ffd43e4566f6bbe9e9f114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Thu, 15 Jun 2023 16:17:09 -0400 Subject: [PATCH 5/7] fix: use console stdout to return values --- scripts/deploy-topos-msg-protocol.ts | 29 ++++------------------------ scripts/deploy.ts | 11 ++--------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/scripts/deploy-topos-msg-protocol.ts b/scripts/deploy-topos-msg-protocol.ts index f0222a0..32ad0c6 100644 --- a/scripts/deploy-topos-msg-protocol.ts +++ b/scripts/deploy-topos-msg-protocol.ts @@ -58,7 +58,6 @@ const main = async function (...args: string[]) { const wallet = new Wallet(toposDeployerPrivateKey, provider) const tokenDeployerAddress = await processContract( - 'TokenDeployer', wallet, tokenDeployerJSON, tokenDeployerSalt!, @@ -67,7 +66,6 @@ const main = async function (...args: string[]) { ) const toposCoreAddress = await processContract( - 'ToposCore', wallet, toposCoreJSON, toposCoreSalt!, @@ -80,7 +78,6 @@ const main = async function (...args: string[]) { [[wallet.address], 1] // TODO: Use a different admin address than ToposDeployer ) const toposCoreProxyAddress = await processContract( - 'ToposCoreProxy', wallet, toposCoreProxyJSON, toposCoreProxySalt!, @@ -89,7 +86,6 @@ const main = async function (...args: string[]) { ) const erc20MessagingAddresss = await processContract( - 'ERC20Messaging', wallet, erc20MessagingJSON, erc20MessagingSalt!, @@ -99,12 +95,12 @@ const main = async function (...args: string[]) { setSubnetId(toposCoreProxyAddress, wallet, subnetId) - return ` + console.log(` export TOPOS_CORE_CONTRACT_ADDRESS=${toposCoreAddress} export TOPOS_CORE_PROXY_CONTRACT_ADDRESS=${toposCoreProxyAddress} export TOKEN_DEPLOYER_CONTRACT_ADDRESS=${tokenDeployerAddress} export ERC20_MESSAGING_CONTRACT_ADDRESS=${erc20MessagingAddresss} - ` + `) } const sanitizeHexString = function (hexString: string) { @@ -125,15 +121,12 @@ const verifySalt = function ( } const processContract = async function ( - contractName: string, wallet: Wallet, contractJson: ContractOutputJSON, salt: string, args: Arg[] = [], gasLimit: number | null = null ) { - console.info(`\nVerifying if ${contractName} is already deployed...`) - const predictedContractAddress = await predictContractConstant( wallet, contractJson, @@ -151,14 +144,8 @@ const processContract = async function ( const thereIsCodeAtAddress = codeAtPredictedAddress !== '0x' if (thereIsCodeAtAddress) { - console.info( - `${contractName} is already deployed! (${predictedContractAddress})` - ) - return predictedContractAddress } else { - console.info(`Deploying ${contractName} with constant address...`) - const newContractAddress = await deployContractConstant( wallet, contractJson, @@ -172,10 +159,6 @@ const processContract = async function ( process.exit(1) }) - console.info( - `Successfully deployed ${contractName} at ${newContractAddress}\n` - ) - return newContractAddress } } @@ -185,8 +168,6 @@ const setSubnetId = async function ( wallet: Wallet, subnetId: string ) { - console.info(`\nSetting subnetId on ToposCore via proxy`) - const toposCoreInterface = new Contract( toposCoreProxyAddress, toposCoreInterfaceJSON.abi, @@ -211,10 +192,8 @@ const setSubnetId = async function ( console.error(error) process.exit(1) }) - const networkSubnetId = await toposCoreInterface.networkSubnetId() - console.info( - `Successfully set ${networkSubnetId} subnetId on ToposCore via proxy\n` - ) + + await toposCoreInterface.networkSubnetId() } const args = process.argv.slice(2) diff --git a/scripts/deploy.ts b/scripts/deploy.ts index f344512..2774d86 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -46,17 +46,10 @@ const main = async function (..._args: Arg[]) { args, gasLimit ) - .then((contract) => { - console.info( - `Successfully deployed ${ - (contractJsonPath).split('.json')[0] - } at ${contract.address}` - ) - return contract.address - }) + .then(({ address }) => address) .catch(console.error) - return address + console.log(address) } const args = process.argv.slice(2) From 22c389f69f0bd862ec2f0b46c4da0684c5bc53e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Thu, 15 Jun 2023 16:53:04 -0400 Subject: [PATCH 6/7] fix: change indentation --- scripts/deploy-topos-msg-protocol.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/deploy-topos-msg-protocol.ts b/scripts/deploy-topos-msg-protocol.ts index 32ad0c6..0c41318 100644 --- a/scripts/deploy-topos-msg-protocol.ts +++ b/scripts/deploy-topos-msg-protocol.ts @@ -96,10 +96,10 @@ const main = async function (...args: string[]) { setSubnetId(toposCoreProxyAddress, wallet, subnetId) console.log(` - export TOPOS_CORE_CONTRACT_ADDRESS=${toposCoreAddress} - export TOPOS_CORE_PROXY_CONTRACT_ADDRESS=${toposCoreProxyAddress} - export TOKEN_DEPLOYER_CONTRACT_ADDRESS=${tokenDeployerAddress} - export ERC20_MESSAGING_CONTRACT_ADDRESS=${erc20MessagingAddresss} +export TOPOS_CORE_CONTRACT_ADDRESS=${toposCoreAddress} +export TOPOS_CORE_PROXY_CONTRACT_ADDRESS=${toposCoreProxyAddress} +export TOKEN_DEPLOYER_CONTRACT_ADDRESS=${tokenDeployerAddress} +export ERC20_MESSAGING_CONTRACT_ADDRESS=${erc20MessagingAddresss} `) } From 3c41a8f2eca5c52b19cfa1fe46b4d6f6d09e333e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Fri, 16 Jun 2023 14:01:26 -0400 Subject: [PATCH 7/7] chore: remove unused script --- package.json | 1 - scripts/predict-const-address.ts | 52 -------------------------------- 2 files changed, 53 deletions(-) delete mode 100644 scripts/predict-const-address.ts diff --git a/package.json b/package.json index 25956c9..8e4999d 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "lint:sol:fix": "npm run lint:sol -- --fix", "lint:ts": "eslint --ext .ts .", "lint:ts:fix": "npm run lint:ts -- --fix", - "predict-const-address": "ts-node scripts/predict-const-address.ts", "register-subnet": "ts-node scripts/register-subnet.ts", "test": "hardhat test" }, diff --git a/scripts/predict-const-address.ts b/scripts/predict-const-address.ts deleted file mode 100644 index 165360c..0000000 --- a/scripts/predict-const-address.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { utils, Wallet } from 'ethers' -import fs from 'fs' - -import { - Arg, - ContractOutputJSON, - predictContractConstant, -} from './const-addr-deployer' - -const main = async function (..._args: Arg[]) { - const [contractJsonPath, salt, ...args] = _args - const privateKey = process.env.PRIVATE_KEY - - if (!privateKey || !utils.isHexString(privateKey, 32)) { - console.error('ERROR: Please provide a valid private key! (PRIVATE_KEY)') - return - } - - const wallet = new Wallet(process.env.PRIVATE_KEY || '') - - let rawdata - try { - rawdata = fs.readFileSync(contractJsonPath) - } catch (error) { - console.error( - `ERROR: Could not find a contract JSON file at ${contractJsonPath}` - ) - return - } - - let contractJson: ContractOutputJSON - try { - contractJson = JSON.parse(rawdata.toString()) - } catch (error) { - console.error( - `ERROR: Could not parse the contract JSON file found at ${contractJsonPath}` - ) - return - } - - const address = await predictContractConstant( - wallet, - contractJson, - salt, - args - ).catch(console.error) - - return address -} - -const args = process.argv.slice(2) -main(...args)