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

fix: use right admin priv key for register subnet script #110

Merged
merged 3 commits into from
Sep 12, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@topos-protocol/topos-smart-contracts",
"version": "1.2.2",
"version": "1.2.3",
"description": "Topos Smart Contracts",
"repository": {
"type": "git",
Expand Down
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, 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, 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
Loading