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 pathindex.js
239 lines (201 loc) · 6.08 KB
/
index.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Required by @openzeppelin/upgrades when running from truffle
global.artifacts = artifacts;
global.web3 = web3;
const {
Contracts,
SimpleProject,
ZWeb3,
AppProject,
Package
} = require("@openzeppelin/upgrades");
const StaticCurveLogic = Contracts.getFromLocal("StaticCurveLogic");
const BancorFormula = Contracts.getFromLocal("BancorFormula");
const BancorCurveLogic = Contracts.getFromLocal("BancorCurveLogic");
const BancorCurveService = Contracts.getFromLocal("BancorCurveService");
const BondingCurve = Contracts.getFromLocal("BondingCurve");
const BondingCurveFactory = Contracts.getFromLocal("BondingCurveFactory");
const BondedToken = Contracts.getFromLocal("BondedToken");
const RewardsDistributor = Contracts.getFromLocal("RewardsDistributor");
const CONTRACT_ABIS = {
BondingCurve,
BondingCurveFactory,
BancorCurveLogic,
StaticCurveLogic,
BondedToken,
BancorCurveService,
RewardsDistributor
};
const CONTRACT_NAMES = {
BondingCurve: "BondingCurve",
BondingCurveFactory: "BondingCurveFactory",
BancorCurveLogic: "BancorCurveLogic",
StaticCurveLogic: "StaticCurveLogic",
BondedToken: "BondedToken",
BancorCurveService: "BancorCurveService",
RewardsDistributor: "RewardsDistributor"
};
const PACKAGE_NAMES = {
self: "example-openzeppelin-upgrades-simple"
};
async function setupApp(txParams) {
// On-chain, single entry point of the entire application.
const initialVersion = "2.5.2";
const appProject = await AppProject.fetchOrDeploy(
"example-openzeppelin-upgrades-simple",
initialVersion,
txParams,
{}
);
// Add all implementations
await appProject.setImplementation(BondingCurve, CONTRACT_NAMES.BondingCurve);
await appProject.setImplementation(
BondingCurveFactory,
CONTRACT_NAMES.BondingCurveFactory
);
await appProject.setImplementation(
BancorCurveLogic,
CONTRACT_NAMES.BancorCurveLogic
);
await appProject.setImplementation(
StaticCurveLogic,
CONTRACT_NAMES.StaticCurveLogic
);
await appProject.setImplementation(BondedToken, CONTRACT_NAMES.BondedToken);
await appProject.setImplementation(
BancorCurveService,
CONTRACT_NAMES.BancorCurveService
);
await appProject.setImplementation(
RewardsDistributor,
CONTRACT_NAMES.RewardsDistributor
);
return appProject;
}
async function deployProject() {
ZWeb3.initialize(web3.currentProvider);
const [creatorAddress, initializerAddress] = await ZWeb3.accounts();
const myProject = new SimpleProject("MyProject", null, {
from: creatorAddress
});
return myProject;
}
async function deployStaticCurveLogic(myProject, initArgs) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(StaticCurveLogic, {
initArgs
});
return instance;
}
async function deployBancorFormula(myProject) {
ZWeb3.initialize(web3.currentProvider);
const [creatorAddress, initializerAddress] = await ZWeb3.accounts();
const instance = await myProject.createProxy(BancorFormula);
await instance.methods.initialize().send({ from: initializerAddress });
return instance;
}
async function deployBancorCurveService(myProject) {
ZWeb3.initialize(web3.currentProvider);
const [creatorAddress, initializerAddress] = await ZWeb3.accounts();
const instance = await myProject.createProxy(BancorCurveService);
await instance.methods.initialize().send({ from: initializerAddress });
return instance;
}
async function deployBancorCurveLogic(myProject, initArgs) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(BancorCurveLogic, {
initArgs
});
return instance;
}
async function createBondingCurve(myProject) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(BondingCurve);
return instance;
}
async function deployBondingCurve(myProject, initArgs) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(BondingCurve, {
initArgs
});
return instance;
}
async function deployBondingCurveFactory(myProject, initArgs) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(BondingCurveFactory, {
initArgs
});
return instance;
}
async function createBondedToken(myProject) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(BondedToken);
return instance;
}
async function deployBondedToken(myProject, initArgs) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(BondedToken, {
initArgs
});
return instance;
}
async function deployStandaloneERC20(myProject, initArgs) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(BondedToken, {
initArgs
});
return instance;
// const erc20Mintable = new web3.eth.Contract(erc20MintableAbi.abi);
// const instance = await erc20Mintable
// .deploy({
// data: erc20MintableAbi.deployedBytecode
// })
// .send({
// from: creatorAddress
// });
}
async function deployRewardsDistributor(myProject, initArgs) {
ZWeb3.initialize(web3.currentProvider);
const instance = await myProject.createProxy(RewardsDistributor, {
initArgs
});
return instance;
}
async function getImplementation(project, contractName) {
const directory = await project.getCurrentDirectory();
const implementation = await directory.getImplementation(contractName);
return implementation;
}
async function getAbi(contractName) {
return CONTRACT_ABIS[contractName].schema.abi;
}
// For truffle exec
module.exports = function(callback) {
main()
.then(() => callback())
.catch(err => callback(err));
};
// Logging
function log() {
if (process.env.NODE_ENV !== "test") {
console.log.apply(this, arguments);
}
}
// Testing
module.exports = {
setupApp,
deployProject,
deployStaticCurveLogic,
deployBancorFormula,
deployBancorCurveService,
deployBancorCurveLogic,
createBondingCurve,
deployBondingCurve,
deployBondingCurveFactory,
deployBondedToken,
deployStandaloneERC20,
deployRewardsDistributor,
CONTRACT_NAMES,
CONTRACT_ABIS,
getImplementation,
getAbi
};