Skip to content

Commit

Permalink
feat: expose contract addresses in deploy script stdout (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan committed Jun 16, 2023
1 parent 9cca7de commit 03cee85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
34 changes: 10 additions & 24 deletions scripts/deploy-topos-msg-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const main = async function (...args: string[]) {
const wallet = new Wallet(toposDeployerPrivateKey, provider)

const tokenDeployerAddress = await processContract(
'TokenDeployer',
wallet,
tokenDeployerJSON,
tokenDeployerSalt!,
Expand All @@ -67,7 +66,6 @@ const main = async function (...args: string[]) {
)

const toposCoreAddress = await processContract(
'ToposCore',
wallet,
toposCoreJSON,
toposCoreSalt!,
Expand All @@ -80,16 +78,14 @@ 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!,
[toposCoreAddress, toposCoreProxyParams],
4_000_000
)

await processContract(
'ERC20Messaging',
const erc20MessagingAddresss = await processContract(
wallet,
erc20MessagingJSON,
erc20MessagingSalt!,
Expand All @@ -98,6 +94,13 @@ 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}
`)
}

const sanitizeHexString = function (hexString: string) {
Expand All @@ -118,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,
Expand All @@ -144,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,
Expand All @@ -165,10 +159,6 @@ const processContract = async function (
process.exit(1)
})

console.info(
`Successfully deployed ${contractName} at ${newContractAddress}\n`
)

return newContractAddress
}
}
Expand All @@ -178,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,
Expand All @@ -204,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)
Expand Down
12 changes: 4 additions & 8 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,17 @@ const main = async function (..._args: Arg[]) {
return
}

await deployContractConstant(
const address = await deployContractConstant(
wallet,
contractJson,
<string>salt,
args,
<number>gasLimit
)
.then((contract) => {
console.info(
`Successfully deployed ${
(<string>contractJsonPath).split('.json')[0]
} at ${contract.address}`
)
})
.then(({ address }) => address)
.catch(console.error)

console.log(address)
}

const args = process.argv.slice(2)
Expand Down

0 comments on commit 03cee85

Please sign in to comment.