Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
chore: adapt SubnetRegistrator deploy script
Browse files Browse the repository at this point in the history
Signed-off-by: Jawad Tariq <[email protected]>
  • Loading branch information
JDawg287 committed Sep 11, 2023
1 parent c76d993 commit 7389b11
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions scripts/deploy-subnet-registrator.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
import { providers, utils, Wallet } from 'ethers'
import { ContractFactory, providers, utils, Wallet } from 'ethers'
import subnetRegistratorJSON from '../artifacts/contracts/topos-core/SubnetRegistrator.sol/SubnetRegistrator.json'
import { Arg, deployContractConstant } from './const-addr-deployer'

const main = async function (..._args: Arg[]) {
const [providerEndpoint, privateKey, salt, gasLimit, ...args] = _args
const [providerEndpoint, sequencerPrivateKey, salt, gasLimit, ...args] = _args
const provider = new providers.JsonRpcProvider(<string>providerEndpoint)

const sequencerPrivateKey = sanitizeHexString(<string>privateKey || '')
if (!utils.isHexString(sequencerPrivateKey, 32)) {
// Fetch the sequencer wallet
const sequencerPrivateKeyHex = sanitizeHexString(
<string>sequencerPrivateKey || ''
)
if (!utils.isHexString(sequencerPrivateKeyHex, 32)) {
console.error('ERROR: Please provide a valid private key!')
return
}
const sequencerWallet = new Wallet(sequencerPrivateKeyHex || '', provider)

const wallet = new Wallet(sequencerPrivateKey || '', provider)
const address = await deployContractConstant(
wallet,
subnetRegistratorJSON,
<string>salt,
[wallet.address, ...args],
<number>gasLimit
)
.then(({ address }) => address)
.catch(console.error)
// Fetch the deployer wallet
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 deployerWallet = new Wallet(process.env.PRIVATE_KEY || '', provider)

// Deploy SubnetRegistrator contract with constant address
let address
try {
address = (
await deployContractConstant(
deployerWallet,
subnetRegistratorJSON,
<string>salt,
[...args],
<number>gasLimit
)
).address
} catch (error) {
console.error(error)
return
}
console.log(address)

// Initialize SubnetRegistrator contract
const SubnetRegistratorFactory = new ContractFactory(
subnetRegistratorJSON.abi,
subnetRegistratorJSON.bytecode,
deployerWallet
)
const subnetRegistrator = SubnetRegistratorFactory.attach(<string>address)
subnetRegistrator.initialize(sequencerWallet.address)
}

const sanitizeHexString = function (hexString: string) {
Expand Down

0 comments on commit 7389b11

Please sign in to comment.