-
Notifications
You must be signed in to change notification settings - Fork 1
/
2_deploy_contracts.js
113 lines (101 loc) · 3.63 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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 namehash = 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: namehash(tld),
sha3: web3.sha3(tld)
};
}
/**
* Deploy FIFSRegistrar
*
* @param {Object} deployer truffle deployer helper
* @param {string} tld tld which the FIFS registrar takes charge of
*/
function deployFIFSRegistrarOnly(deployer, tld) {
var rootNode = getRootNodeFromTLD(tld);
var ensaddress='0xed055F160D056EB858A4e510C31B9328475dc205';
// Deploy the FIFSRegistrar and bind it with ENS
deployer.deploy(FIFSRegistrar, ensaddress, rootNode.namehash)
.then(function() {
// Transfer the owner of the `rootNode` to the FIFSRegistrar
return ENS.at(ensaddress).then((c) => c.setSubnodeOwner('0x0', rootNode.sha3, FIFSRegistrar.address));
});
}
function deployFIFSRegistrarOnly1(deployer, tld) {
var rootNode = getRootNodeFromTLD(tld);
var ensaddress='0xed055F160D056EB858A4e510C31B9328475dc205';
// Deploy the ENS first
ENS.at(ensaddress)
.then(() => {
// Deploy the FIFSRegistrar and bind it with ENS
return deployer.deploy(FIFSRegistrar, ensaddress, rootNode.namehash);
})
.then(function() {
// Transfer the owner of the `rootNode` to the FIFSRegistrar
return ENS.at(ensaddress).then((c) => c.setSubnodeOwner('0x0', rootNode.sha3, FIFSRegistrar.address));
});
}
/**
* 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);
}
else if (network === 'allcom') {
deployFIFSRegistrarOnly(deployer, 'fax');
}
};