Skip to content

Commit

Permalink
fix: use right admin priv key for register subnet script
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan committed Sep 12, 2023
1 parent c3c48d0 commit bcbe34b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
74 changes: 39 additions & 35 deletions scripts/deploy-subnet-registrator.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
import { ContractFactory, providers, utils, Wallet } from 'ethers'
import { Contract, ContractFactory, providers, utils, Wallet } from 'ethers'

Check failure on line 1 in scripts/deploy-subnet-registrator.ts

View workflow job for this annotation

GitHub Actions / Lint

'ContractFactory' is defined but never used

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, sequencerPrivateKey, salt, gasLimit, ...args] = _args
const [providerEndpoint, _adminPrivateKey, salt, gasLimit, ...args] = _args
const provider = new providers.JsonRpcProvider(<string>providerEndpoint)

// Fetch the sequencer wallet
const sequencerPrivateKeyHex = sanitizeHexString(
<string>sequencerPrivateKey || ''
)
if (!utils.isHexString(sequencerPrivateKeyHex, 32)) {
if (!_adminPrivateKey) {
console.error('ERROR: Please provide the admin private key!')
process.exit(1)
}

const adminPrivateKey = sanitizeHexString(_adminPrivateKey as string)
if (!utils.isHexString(adminPrivateKey, 32)) {
console.error('ERROR: Please provide a valid private key!')
return
process.exit(1)
}
const sequencerWallet = new Wallet(sequencerPrivateKeyHex || '', provider)

const isCompressed = true
const adminPublicKey = utils.computePublicKey(adminPrivateKey, isCompressed)

const adminAddress = utils.computeAddress(adminPublicKey)

// 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
console.error(
'ERROR: Please provide a valid deployer private key! (PRIVATE_KEY)'
)
process.exit(1)
}
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
deployContractConstant(
deployerWallet,
subnetRegistratorJSON,
salt as string,
[...args],
gasLimit as number
)
.then(({ address }) => {
console.log(address)
const subnetRegistrator = new Contract(
address,
subnetRegistratorJSON.abi,
deployerWallet
)
).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)
subnetRegistrator.initialize(adminAddress)
})
.catch((error) => {
console.error(error)
process.exit(1)
})
}

const sanitizeHexString = function (hexString: string) {
Expand Down
17 changes: 11 additions & 6 deletions scripts/register-subnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ const main = async function (...args: string[]) {
subnetRPCEndpoint,
subnetCurrencySymbol,
subnetLogoUrl,
_adminPrivateKey,
_sequencerPrivateKey,
] = args
const provider = new providers.JsonRpcProvider(toposSubnetProviderEndpoint)
const toposDeployerPrivateKey = sanitizeHexString(
process.env.PRIVATE_KEY || ''
)

if (!utils.isHexString(toposDeployerPrivateKey, 32)) {
if (!_adminPrivateKey) {
console.error(
'ERROR: Please provide a valid toposDeployer private key! (PRIVATE_KEY)'
'ERROR: Please provide the SubnetRegistrator admin private key!'
)
process.exit(1)
}
Expand Down Expand Up @@ -55,6 +53,13 @@ const main = async function (...args: string[]) {
process.exit(1)
}

const adminPrivateKey = sanitizeHexString(_adminPrivateKey)

if (!utils.isHexString(_adminPrivateKey, 32)) {
console.error('ERROR: The admin private key is not a valid key!')
process.exit(1)
}

const sequencerPrivateKey = sanitizeHexString(_sequencerPrivateKey)

if (!utils.isHexString(sequencerPrivateKey, 32)) {
Expand All @@ -77,7 +82,7 @@ const main = async function (...args: string[]) {
process.exit(1)
}

const wallet = new Wallet(sequencerPrivateKey, provider)
const wallet = new Wallet(adminPrivateKey, provider)

const contract = new Contract(
subnetRegistratorAddress,
Expand Down

0 comments on commit bcbe34b

Please sign in to comment.