UNPKG

2.41 kBJavaScriptView Raw
1const ENS = artifacts.require("./ENSRegistry.sol");
2const FIFSRegistrar = artifacts.require('./FIFSRegistrar.sol');
3
4// Currently the parameter('./ContractName') is only used to imply
5// the compiled contract JSON file name. So even though `Registrar.sol` is
6// not existed, it's valid to put it here.
7// TODO: align the contract name with the source code file name.
8const Registrar = artifacts.require('./HashRegistrar.sol');
9const web3 = new (require('web3'))();
10const namehash = require('eth-ens-namehash');
11
12/**
13 * Calculate root node hashes given the top level domain(tld)
14 *
15 * @param {string} tld plain text tld, for example: 'eth'
16 */
17function getRootNodeFromTLD(tld) {
18 return {
19 namehash: namehash(tld),
20 sha3: web3.sha3(tld)
21 };
22}
23
24/**
25 * Deploy the ENS and FIFSRegistrar
26 *
27 * @param {Object} deployer truffle deployer helper
28 * @param {string} tld tld which the FIFS registrar takes charge of
29 */
30function deployFIFSRegistrar(deployer, tld) {
31 var rootNode = getRootNodeFromTLD(tld);
32
33 // Deploy the ENS first
34 deployer.deploy(ENS)
35 .then(() => {
36 // Deploy the FIFSRegistrar and bind it with ENS
37 return deployer.deploy(FIFSRegistrar, ENS.address, rootNode.namehash);
38 })
39 .then(function() {
40 // Transfer the owner of the `rootNode` to the FIFSRegistrar
41 return ENS.at(ENS.address).then((c) => c.setSubnodeOwner('0x0', rootNode.sha3, FIFSRegistrar.address));
42 });
43}
44
45/**
46 * Deploy the ENS and HashRegistrar(Simplified)
47 *
48 * @param {Object} deployer truffle deployer helper
49 * @param {string} tld tld which the Hash registrar takes charge of
50 */
51function deployAuctionRegistrar(deployer, tld) {
52 var rootNode = getRootNodeFromTLD(tld);
53
54 // Deploy the ENS first
55 deployer.deploy(ENS)
56 .then(() => {
57 // Deploy the HashRegistrar and bind it with ENS
58 // The last argument `0` specifies the auction start date to `now`
59 return deployer.deploy(Registrar, ENS.address, rootNode.namehash, 0);
60 })
61 .then(function() {
62 // Transfer the owner of the `rootNode` to the HashRegistrar
63 return ENS.at(ENS.address).then((c) => c.setSubnodeOwner('0x0', rootNode.sha3, Registrar.address));
64 });
65}
66
67module.exports = function(deployer, network) {
68 var tld = 'eth';
69
70 if (network === 'dev.fifs') {
71 deployFIFSRegistrar(deployer, tld);
72 }
73 else if (network === 'dev.auction') {
74 deployAuctionRegistrar(deployer, tld);
75 }
76
77};