diff --git a/scripts/deploy-subnet-registrator.ts b/scripts/deploy-subnet-registrator.ts index cef0855..0b3f0c9 100644 --- a/scripts/deploy-subnet-registrator.ts +++ b/scripts/deploy-subnet-registrator.ts @@ -1,55 +1,59 @@ -import { ContractFactory, providers, utils, Wallet } from 'ethers' +import { Contract, 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, sequencerPrivateKey, salt, gasLimit, ...args] = _args + const [providerEndpoint, _adminPrivateKey, salt, gasLimit, ...args] = _args const provider = new providers.JsonRpcProvider(providerEndpoint) - // Fetch the sequencer wallet - const sequencerPrivateKeyHex = sanitizeHexString( - 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, - salt, - [...args], - 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(address) - subnetRegistrator.initialize(sequencerWallet.address) + subnetRegistrator.initialize(adminAddress) + }) + .catch((error) => { + console.error(error) + process.exit(1) + }) } const sanitizeHexString = function (hexString: string) { diff --git a/scripts/register-subnet.ts b/scripts/register-subnet.ts index d07e44b..49dc7c4 100644 --- a/scripts/register-subnet.ts +++ b/scripts/register-subnet.ts @@ -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) } @@ -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)) { @@ -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,