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