This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathecosystem.initialize.js
121 lines (102 loc) · 3.45 KB
/
ecosystem.initialize.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
114
115
116
117
118
119
120
121
/* eslint-disable no-console */
require("dotenv").config();
const fs = require("fs");
const App = artifacts.require("App");
const contractNames = {
StaticCurveLogic: "StaticCurveLogic",
BancorCurveLogic: "BancorCurveLogic",
BondedToken: "BondedToken",
RewardsDistributor: "RewardsDistributor",
BondingCurve: "BondingCurve",
BondingCurveFactory: "BondingCurveFactory",
BancorCurveService: "BancorCurveService"
};
const BancorCurveService = artifacts.require("BancorCurveService");
const BondingCurveFactory = artifacts.require("BondingCurveFactory");
const truffleConfig = require("./truffle-config.js");
const OZ_PACKAGE = "@dorgtech/open-raise";
function activeNetwork() {
const networkIndex = process.argv.lastIndexOf("--network");
if (networkIndex < 2) {
return "development";
}
return process.argv[networkIndex + 1];
}
function activeNetworkName() {
return activeNetwork() === "development"
? `dev-${App.network_id}`
: activeNetwork();
}
/*
* Get zos config info for specified networkId.
*/
function getOZNetworkConfig(networkName) {
const zosNetworkFile = fs.readFileSync(`./.openzeppelin/${networkName}.json`);
return JSON.parse(zosNetworkFile);
}
function getAppAddress() {
const ozNetworkConfig = getOZNetworkConfig(activeNetworkName());
return ozNetworkConfig.app.address;
}
function getLatestProxy(contractName) {
const ozNetworkConfig = getOZNetworkConfig(activeNetworkName());
const proxies = ozNetworkConfig.proxies[`${OZ_PACKAGE}/${contractName}`];
if (!proxies || proxies.length <= 1) {
throw Error(`No deployed proxies of contract ${contractName} found`);
}
return proxies[proxies.length - 1];
}
function helpers() {
return {
constants: {
ZERO_ADDRESS: "0x0000000000000000000000000000000000000000"
}
};
}
async function initializeBancorCurveService(contractAddress) {
const contract = await BancorCurveService.at(contractAddress);
return contract.initialize();
}
async function initializeBondingCurveFactory(contractAddress) {
const ozNetworkConfig = getOZNetworkConfig(activeNetworkName());
const contract = await BondingCurveFactory.at(contractAddress);
return contract.initialize(
ozNetworkConfig.contracts.StaticCurveLogic.address,
ozNetworkConfig.contracts.BancorCurveLogic.address,
ozNetworkConfig.contracts.BondedToken.address,
ozNetworkConfig.contracts.BondingCurve.address,
ozNetworkConfig.contracts.RewardsDistributor.address,
getLatestProxy(contractNames.BancorCurveService).address
);
}
module.exports = async () => {
const { constants } = helpers();
try {
const bancorCurveServiceAddress = getLatestProxy(
contractNames.BancorCurveService
).address;
const bondingCurveFactoryAddress = getLatestProxy(
contractNames.BondingCurveFactory
).address;
console.log(
`${contractNames.BancorCurveService} to initialize:`,
bancorCurveServiceAddress
);
console.log(
`${contractNames.BondingCurveFactory} to initialize:`,
bondingCurveFactoryAddress
);
// let initializeTx = await initializeBancorCurveService(bancorCurveServiceAddress);
// console.log(`${contractNames.BancorCurveService} initialization tx:`, initializeTx.tx);
let initializeTx = await initializeBondingCurveFactory(
bondingCurveFactoryAddress
);
console.log(
`${contractNames.BondingCurveFactory} initialization tx:`,
initializeTx.tx
);
} catch (e) {
console.error(e);
}
process.exit();
};