<commit_before>import { Interface } from 'ethers/lib/utils';
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const { makeInterfaceId } = require('@openzeppelin/test-helpers')

function computeInterfaceId(iface: Interface) {
  return makeInterfaceId.ERC165(Object.values(iface.functions).map((frag) => frag.format("sighash")));
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
  const { getNamedAccounts, deployments, network } = hre
  const { deploy, fetchIfDifferent } = deployments
  const { deployer } = await getNamedAccounts()

  const registrar = await ethers.getContract('BaseRegistrarImplementation')
  const priceOracle = await ethers.getContract('ExponentialPremiumPriceOracle')
  const reverseRegistrar = await ethers.getContract('ReverseRegistrar')
  const nameWrapper = await ethers.getContract('NameWrapper')

  const deployArgs = {
    from: deployer,
    args: [
      registrar.address,
      priceOracle.address,
      60,
      86400,
      reverseRegistrar.address,
      nameWrapper.address,
    ],
    log: true,
  };
  const controller = await deploy('ETHRegistrarController', deployArgs)
  if(!controller.newlyDeployed) return;

  // Only attempt to make controller etc changes directly on testnets
  if(network.name === 'mainnet') return;

  const tx1 = await registrar.addController(controller.address, {
    from: deployer,
  })
  console.log(
    `Adding ETHRegistrarController as controller on BaseRegistrarImplementation (tx: ${tx1.hash})...`,
  )
  await tx1.wait()

  const tx2 = await nameWrapper.setController(controller.address, {
    from: deployer,
  })
  console.log(
    `Adding ETHRegistrarController as a controller of NameWrapper (tx: ${tx2.hash})...`,
  )
  await tx2.wait()

  const tx3 = await reverseRegistrar.setController(controller.address, {
    from: deployer,
  })
  console.log(
    `Adding ETHRegistrarController as a controller of ReverseRegistrar (tx: ${tx3.hash})...`,
  )
  await tx3.wait()

  const artifact = await deployments.getArtifact("IETHRegistrarController");
  const interfaceId = computeInterfaceId(new Interface(artifact.abi));
  const provider = await ethers.getDefaultProvider();
  const resolver = await provider.getResolver("eth");
  if(resolver === null) {
    console.log("No resolver set for .eth; not setting interface for ETH Registrar Controller");
    return;
  }
  const resolverContract = await ethers.getContractAt('PublicResolver', resolver.address);
  const tx4 = await resolverContract.setInterface(ethers.utils.namehash('eth'), interfaceId, controller.address);
  console.log(
    `Setting ETHRegistrarController interface ID ${interfaceId} on .eth resolver (tx: ${tx4.hash})...`
  )
  await tx4.wait()
}

func.tags = ['ethregistrar', 'ETHRegistrarController']
func.dependencies = [
  'ENSRegistry',
  'BaseRegistrarImplementation',
  'ExponentialPremiumPriceOracle',<commit_msg>Don't set ETHRegistrarController as a controller of BaseRegistrar<commit_after>import { Interface } from 'ethers/lib/utils';
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const { makeInterfaceId } = require('@openzeppelin/test-helpers')

function computeInterfaceId(iface: Interface) {
  return makeInterfaceId.ERC165(Object.values(iface.functions).map((frag) => frag.format("sighash")));
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
  const { getNamedAccounts, deployments, network } = hre
  const { deploy, fetchIfDifferent } = deployments
  const { deployer } = await getNamedAccounts()

  const registrar = await ethers.getContract('BaseRegistrarImplementation')
  const priceOracle = await ethers.getContract('ExponentialPremiumPriceOracle')
  const reverseRegistrar = await ethers.getContract('ReverseRegistrar')
  const nameWrapper = await ethers.getContract('NameWrapper')

  const deployArgs = {
    from: deployer,
    args: [
      registrar.address,
      priceOracle.address,
      60,
      86400,
      reverseRegistrar.address,
      nameWrapper.address,
    ],
    log: true,
  };
  const controller = await deploy('ETHRegistrarController', deployArgs)
  if(!controller.newlyDeployed) return;

  // Only attempt to make controller etc changes directly on testnets
  if(network.name === 'mainnet') return;

  const tx1 = await nameWrapper.setController(controller.address, {
    from: deployer,
  })
  console.log(
    `Adding ETHRegistrarController as a controller of NameWrapper (tx: ${tx1.hash})...`,
  )
  await tx1.wait()

  const tx2 = await reverseRegistrar.setController(controller.address, {
    from: deployer,
  })
  console.log(
    `Adding ETHRegistrarController as a controller of ReverseRegistrar (tx: ${tx2.hash})...`,
  )
  await tx2.wait()

  const artifact = await deployments.getArtifact("IETHRegistrarController");
  const interfaceId = computeInterfaceId(new Interface(artifact.abi));
  const provider = await ethers.getDefaultProvider();
  const resolver = await provider.getResolver("eth");
  if(resolver === null) {
    console.log("No resolver set for .eth; not setting interface for ETH Registrar Controller");
    return;
  }
  const resolverContract = await ethers.getContractAt('PublicResolver', resolver.address);
  const tx3 = await resolverContract.setInterface(ethers.utils.namehash('eth'), interfaceId, controller.address);
  console.log(
    `Setting ETHRegistrarController interface ID ${interfaceId} on .eth resolver (tx: ${tx3.hash})...`
  )
  await tx3.wait()
}

func.tags = ['ethregistrar', 'ETHRegistrarController']
func.dependencies = [
  'ENSRegistry',
  'BaseRegistrarImplementation',
  'ExponentialPremiumPriceOracle',
{'fraction_non_alphanumeric': 0.11349957007738606, 'fraction_numerical': 0.0070507308684436805, 'mean_word_length': 4.758415841584158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4666973', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1726, 'n_words': 407}