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

Commit

Permalink
Merge pull request #1 from rithvikvibhu/new-deploy-verify
Browse files Browse the repository at this point in the history
New deploy code and contract verification script (+misc)
  • Loading branch information
kibagateaux committed Jan 2, 2022
2 parents ad66cb8 + dc6ee6b commit 39b8beb
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 23 deletions.
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,28 @@ Referrer is set in register() instead of verify() because any person or register

## quickstart

Clone the repo and install dependencies:
```bash
git clone https://github.com/hnsfund/xnhns.git

cd xnhns
```

```bash

yarn install

```

Start the frontend dev server with:
```bash

yarn start

```

> in a second terminal window:
In a second terminal window, start a local hardhat network (this will deploy all contracts on a fresh chain):
```bash

cd packages/hardhat
yarn chain --network hardhat

```

> in a third terminal window:
In a third terminal window, run this to compile and publish to frontend (required after every contract modification):
```bash

cd packages/hardhat
yarn deploy:test

```


Expand Down
1 change: 1 addition & 0 deletions packages/hardhat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deployments/
6 changes: 3 additions & 3 deletions packages/hardhat/contracts/resolvers/PublicResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../../interfaces/IENS.sol";
import "./ABIResolver.sol";
import "./AddrResolver.sol";
import "./ContentHashResolver.sol";
// import "./DNSResolver.sol";
import "./DNSResolver.sol";
import "./InterfaceResolver.sol";
import "./NameResolver.sol";
import "./PubkeyResolver.sol";
Expand All @@ -16,7 +16,7 @@ import "./TextResolver.sol";
* A simple resolver anyone can use; only allows the owner of a node to set its
* address.
*/
contract PublicResolver is ABIResolver, AddrResolver, ContentHashResolver, InterfaceResolver, PubkeyResolver, TextResolver, NameResolver, Ownable {
contract PublicResolver is ABIResolver, AddrResolver, ContentHashResolver, InterfaceResolver, PubkeyResolver, TextResolver, NameResolver, DNSResolver, Ownable {
ENS ens;

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ contract PublicResolver is ABIResolver, AddrResolver, ContentHashResolver, Inter
return results;
}

function supportsInterface(bytes4 interfaceID) virtual override(ABIResolver, AddrResolver, ContentHashResolver, InterfaceResolver, NameResolver, PubkeyResolver, TextResolver) public pure returns(bool) {
function supportsInterface(bytes4 interfaceID) virtual override(ABIResolver, AddrResolver, ContentHashResolver, DNSResolver, InterfaceResolver, NameResolver, PubkeyResolver, TextResolver) public pure returns(bool) {
return super.supportsInterface(interfaceID);
}
}
88 changes: 88 additions & 0 deletions packages/hardhat/deploy/00_deploy_all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const fs = require('fs');

const namespace = 'matic'

module.exports = async ({getNamedAccounts, deployments}) => {
const {deploy, execute} = deployments;
const {deployer} = await getNamedAccounts();

const ENSRegistry = await deploy('ENSRegistry', {
from: deployer,
args: [],
log: true,
});

const Root = await deploy('Root', {
from: deployer,
args: [ENSRegistry.address],
log: true,
});

// Set ENSRegistry's owner to Root
if (ENSRegistry.newlyDeployed) {
await execute(
'ENSRegistry',
{
from: deployer,
log: true
},
'setOwner',
// args:
'0x0000000000000000000000000000000000000000000000000000000000000000', Root.address
);
}

const TrustedXNHNSOracle = await deploy('TrustedXNHNSOracle', {
from: deployer,
args: [namespace],
log: true,
});

const HNSRegistrar = await deploy('HNSRegistrar', {
from: deployer,
args: [ENSRegistry.address, namespace, TrustedXNHNSOracle.address],
log: true,
});

// Set Root's controller to HNSRegistrar
if (Root.newlyDeployed) {
await execute(
'Root',
{
from: deployer,
log: true
},
'setController',
// args:
HNSRegistrar.address, true
);
}

// Allow HNSRegistrar to call XNHNSOracle
if (TrustedXNHNSOracle.newlyDeployed || Root.newlyDeployed) {
await execute(
'TrustedXNHNSOracle',
{
from: deployer,
log: true
},
'setCallerPermission',
// args:
HNSRegistrar.address, true
);
}

const PublicResolver = await deploy('PublicResolver', {
from: deployer,
args: [ENSRegistry.address],
log: true,
});

fs.writeFileSync('artifacts/ENSRegistry.address', ENSRegistry.address);
fs.writeFileSync('artifacts/Root.address', Root.address);
fs.writeFileSync('artifacts/TrustedXNHNSOracle.address', TrustedXNHNSOracle.address);
fs.writeFileSync('artifacts/HNSRegistrar.address', HNSRegistrar.address);
fs.writeFileSync('artifacts/PublicResolver.address', PublicResolver.address);
};

module.exports.tags = ['all'];
3 changes: 3 additions & 0 deletions packages/hardhat/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ module.exports = {
},
},
},
// Set API key for etherscan/polygonscan/mumbai.polygonscan
// Endpoint will be chosen based on default network
// TODO: Replace this hardcode with a switch on defaultNetwork
etherscan: {
apiKey: '43JVMCI3EJCZSECDWX99KRZRYWDX3H7MCH'
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
"chalk": "^4.1.0",
"ethereum-waffle": "^3.1.1",
"ethers": "^5.0.17",
"hardhat": "^2.0.8",
"hardhat": "^2.8.0",
"hardhat-deploy": "^0.7.0-beta.45",
"node-watch": "^0.7.0",
"qrcode-terminal": "^0.12.0",
"ramda": "^0.27.1"
},
"scripts": {
"chain": "hardhat node",
"chain": "hardhat node --write true",
"console": "hardhat console",
"test": "hardhat test",
"compile": "hardhat compile",
"deploy": "yarn run deploy-xnhns",
"deploy:test": "yarn run deploy-xnhns && hardhat run scripts/publish.js",
"deploy:singleton": "hardhat run scripts/deploy-single-tld-ens.js && hardhat run scripts/publish.js",
"deploy-xnhns": "hardhat run scripts/deploy-xnhns.js",
"deploy-xnhns": "hardhat deploy",
"postdeploy": " hardhat run scripts/publish.js",
"watch": "node scripts/watch.js",
"accounts": "hardhat accounts",
Expand Down
70 changes: 70 additions & 0 deletions packages/hardhat/scripts/verify-contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const fs = require('fs');
const hre = require('hardhat');

const namespace = 'matic';

// Comment ones you don't want to verify (lazy peeps customizable way)
const contractNames = [
'ENSRegistry',
'Root',
'TrustedXNHNSOracle',
'HNSRegistrar',
'PublicResolver'
];

// Gather all addresses from artifacts directory
const addresses = {};
fs.readdirSync(`${hre.config.paths.artifacts}`, {withFileTypes: true}).map(file => {
if (!file.isFile() || !file.name.endsWith('.address')) return;
addresses[file.name.replace(/\.address$/, '')] = fs.readFileSync(`${hre.config.paths.artifacts}/${file.name}`)?.toString() || null;
})
console.log('Addresses:', addresses);

// Constructor arguments needed to verify
const constructorArguments = {
'ENSRegistry': [],
'Root': [addresses.ENSRegistry],
'TrustedXNHNSOracle': [namespace],
'HNSRegistrar': [addresses.ENSRegistry, namespace, addresses.TrustedXNHNSOracle],
'PublicResolver': [addresses.ENSRegistry],
};
console.log('Constructor Arguments:', constructorArguments);


// Verify all (uncommented) contracts
async function main() {
for (const name of contractNames) {
console.log(`Verifying contract ${name}...`);

const address = addresses[name];

if (!address || !address.length) {
console.log('No address found, skipping.');
continue;
}

try {
await hre.run('verify:verify', {
address: address,
constructorArguments: constructorArguments[name],
});
} catch (error) {
const alreadyVerified = error.message.includes('Contract source code already verified') ||
error.message.includes('Already Verified')
if (alreadyVerified) {
console.log('Already verified, skipping.');
} else {
throw error;
}
}

console.log('Done!')
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
1 change: 1 addition & 0 deletions packages/react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/contracts/
2 changes: 2 additions & 0 deletions packages/react-app/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export const NETWORKS = {
},
mumbai: {
name: "mumbai",
namespace: 'matic',
xnhnsRegistry: '0x0',
color: '#92D9FA',
chainId: 80001,
price: 1,
Expand Down
Loading

0 comments on commit 39b8beb

Please sign in to comment.