@reality.eth/contracts 3.0.14 → 3.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -122,16 +122,6 @@
122
122
  }
123
123
  }
124
124
  },
125
- "LINK": {
126
- "RealityETH_ERC20-3.0": {
127
- "address": "0x4a38a9EdE2f997E97Cac2D7BF8e002Ec20d2c2Ca",
128
- "block": 11107294,
129
- "token_address": "0x01be23585060835e02b77ef475b0cc51aa1e0709",
130
- "notes": null,
131
- "arbitrators": {},
132
- "factory_address": "0x9e862794f4f80386185b9d3baa532668e988c530"
133
- }
134
- },
135
125
  "TRST": {
136
126
  "Arbitrator": {
137
127
  "address": "0xa682C58333F4959cbF728c2a871548E3D8978Fa2",
@@ -100,13 +100,6 @@
100
100
  "100": "0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb"
101
101
  }
102
102
  },
103
- "LINK": {
104
- "decimals": 18,
105
- "small_number": 1000000000000000000,
106
- "erc20_chains": {
107
- "4": "0x01be23585060835e02b77ef475b0cc51aa1e0709"
108
- }
109
- },
110
103
  "POLK": {
111
104
  "decimals": 18,
112
105
  "small_number": 1000000000000000000,
package/index.js CHANGED
@@ -1,9 +1,27 @@
1
- const all_config = require('./generated/contracts.json');
2
- const token_info = require('./generated/tokens.json');
1
+ let all_config = require('./generated/contracts.json');
2
+ let token_info = require('./generated/tokens.json');
3
3
  const chain_info = require('./generated/chains.json');
4
4
  const template_config = require('./config/templates.json');
5
5
  const factory_config = require('./generated/factories.json');
6
6
 
7
+ function populateImports(imported_contracts, chain_id) {
8
+ for(var ctr in imported_contracts) {
9
+ let to_imp = imported_contracts[ctr];
10
+ to_imp.realityETH= ctr;
11
+ const imp = tokenAndContractConfigFromFactory(to_imp, chain_id);
12
+ const token = imp.token.ticker;
13
+ if (!all_config[chain_id][token]) {
14
+ all_config[chain_id][token] = {};
15
+ }
16
+ const ver = imp.contract.version_number;
17
+ all_config[chain_id][token][ver] = imp.contract;
18
+
19
+ if (!token_info[token]) {
20
+ token_info[token] = imp.token;
21
+ }
22
+ }
23
+ }
24
+
7
25
  function realityETHInstance(config) {
8
26
  const abis = {
9
27
  'RealityETH-2.0': require('./abi/solc-0.8.6/RealityETH-2.0.abi.json'),
@@ -36,7 +54,7 @@ function arbitratorInstance(chain_id) {
36
54
  function erc20Instance(config) {
37
55
  const abi = require('./abi/solc-0.4.25/ERC20.abi.json');
38
56
  if (!config.token_address) {
39
- console.log('config', config);
57
+ // console.log('config', config);
40
58
  throw new Error("token address for erc20 instance not found");
41
59
  return null;
42
60
  }
@@ -166,7 +184,7 @@ function isChainSupported(chain_id) {
166
184
  function walletAddParameters(chain_id) {
167
185
  var params = ['chainId', 'chainName', 'nativeCurrency', 'rpcUrls', 'blockExplorerUrls']
168
186
  var ret = {};
169
- console.log('looking for config for chain', chain_id);
187
+ // console.log('looking for config for chain', chain_id);
170
188
  var config = chain_info[""+chain_id];
171
189
  for (var i=0; i<params.length; i++) {
172
190
  var item = params[i];
@@ -210,6 +228,49 @@ function versionHasFeature(vernum, feature_name) {
210
228
  }
211
229
  }
212
230
 
231
+ function factoryConfigForAddress(address, chain_id) {
232
+
233
+ for(var cid in factory_config) {
234
+ if (chain_id && cid != chain_id) {
235
+ continue;
236
+ }
237
+ for(var ver in factory_config[cid]) {
238
+ const config = factory_config[cid][ver];
239
+ if (address.toLowerCase() == config.address.toLowerCase()) {
240
+ return config;
241
+ }
242
+ }
243
+ }
244
+ return null;
245
+
246
+ }
247
+
248
+ function configForAddress(addr, chain_id) {
249
+ for(var cid in all_config) {
250
+ if (chain_id && cid != chain_id) {
251
+ continue;
252
+ }
253
+ for(var ticker in all_config[cid]) {
254
+ for(var ver in all_config[cid][ticker]) {
255
+ const config = all_config[cid][ticker][ver];
256
+ if (addr.toLowerCase() == config.address.toLowerCase()) {
257
+ if (!config.arbitrators) {
258
+ config.arbitrators = [];
259
+ }
260
+ const [contract_name, contract_version] = ver.split('-');
261
+ config.version_number = ver;
262
+ config.chain_id = cid;
263
+ config.contract_name = contract_name;
264
+ config.contract_version = contract_version;
265
+ return config;
266
+ }
267
+ }
268
+ }
269
+ }
270
+ return null;
271
+
272
+ }
273
+
213
274
  function factoryList(chain_id) {
214
275
  if (!factory_config[chain_id]) {
215
276
  return {};
@@ -217,6 +278,43 @@ function factoryList(chain_id) {
217
278
  return factory_config[chain_id];
218
279
  }
219
280
 
281
+ function tokenAndContractConfigFromFactory(factory_data, chain_id) {
282
+ // Get the library for the factory
283
+ const factory_config = factoryConfigForAddress(factory_data.factory, chain_id);
284
+
285
+ const template_orig = configForAddress(factory_config.library_address, chain_id);
286
+ let template = {};
287
+ for (let k in template_orig) {
288
+ template[k] = template_orig[k];
289
+ }
290
+
291
+ if (!template) {
292
+ console.log('no template found for', factory_data, factory_config, chain_id);
293
+ return null;
294
+ }
295
+
296
+ template.address = factory_data.realityETH;
297
+ template.block = parseInt(factory_data.createdBlock);
298
+ template.token_address = factory_data.token_address;
299
+ template.token_ticker = factory_data.token_symbol;
300
+
301
+ const erc20_chains_val = {};
302
+ erc20_chains_val[chain_id] = factory_data.token_address;
303
+
304
+ return {
305
+ 'token': {
306
+ 'ticker': factory_data.token_symbol,
307
+ 'decimals': factory_data.token_decimals,
308
+ 'is_native': false,
309
+ 'small_number': 1000000000000000000,
310
+ 'erc20_chains': erc20_chains_val
311
+ },
312
+ 'contract': template
313
+ }
314
+
315
+ }
316
+
317
+
220
318
  module.exports.realityETHConfig = realityETHConfig;
221
319
  module.exports.realityETHConfigs = realityETHConfigs;
222
320
  module.exports.realityETHInstance = realityETHInstance;
@@ -231,3 +329,6 @@ module.exports.defaultTokenForChain = defaultTokenForChain;
231
329
  module.exports.versionHasFeature = versionHasFeature;
232
330
  module.exports.isChainSupported = isChainSupported;
233
331
  module.exports.factoryList = factoryList;
332
+ module.exports.tokenAndContractConfigFromFactory = tokenAndContractConfigFromFactory;
333
+ module.exports.configForAddress = configForAddress;
334
+ module.exports.populateImports = populateImports;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reality.eth/contracts",
3
- "version": "3.0.14",
3
+ "version": "3.0.15",
4
4
  "description": "Collection of smart contracts for the Realitio fact verification platform",
5
5
  "scripts": {
6
6
  "generate-chains": "node scripts/generate_chains_json.js",
@@ -30,7 +30,7 @@
30
30
  "url": "https://github.com/RealityETH/monorepo/issues"
31
31
  },
32
32
  "homepage": "https://reality.eth.link",
33
- "gitHead": "a6967162fe1addfaa727cb3d3bac37fcabb2c7bb",
33
+ "gitHead": "4601364942fcc90d5f93f10f53e3934c7e772d46",
34
34
  "dependencies": {
35
35
  "ethers": "^5.6.8"
36
36
  }
@@ -1,8 +0,0 @@
1
- {
2
- "address": "0x4a38a9EdE2f997E97Cac2D7BF8e002Ec20d2c2Ca",
3
- "block": 11107294,
4
- "token_address": "0x01be23585060835e02b77ef475b0cc51aa1e0709",
5
- "notes": null,
6
- "arbitrators": {},
7
- "factory_address": "0x9e862794f4f80386185b9d3baa532668e988c530"
8
- }
package/tokens/LINK.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "decimals": 18,
3
- "small_number": 1000000000000000000,
4
- "erc20_chains": {
5
- "4": "0x01be23585060835e02b77ef475b0cc51aa1e0709"
6
- }
7
- }