@orbs-network/spot 0.0.6 → 0.0.7
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.
- package/index.js +20 -88
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,97 +1,29 @@
|
|
|
1
1
|
const raw = require('./script/input/config.json');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
let cachedConfigs = null;
|
|
3
|
+
const { dex: _globalDex, ...baseDefaults } = raw['*'] ?? {};
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const result = { ...base };
|
|
9
|
-
for (const key in override) {
|
|
10
|
-
if (override[key] && typeof override[key] === 'object' && !Array.isArray(override[key])) {
|
|
11
|
-
result[key] = deepMerge(result[key] || {}, override[key]);
|
|
12
|
-
} else {
|
|
13
|
-
result[key] = override[key];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Build all configs with defaults merged
|
|
20
|
-
function buildConfigs() {
|
|
21
|
-
if (cachedConfigs) return cachedConfigs;
|
|
22
|
-
|
|
23
|
-
const base = raw['*'];
|
|
24
|
-
const result = {};
|
|
25
|
-
|
|
26
|
-
for (const key in raw) {
|
|
27
|
-
if (key === '*') continue;
|
|
28
|
-
result[key] = deepMerge(base, raw[key]);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
cachedConfigs = result;
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports.configs = () => {
|
|
36
|
-
return buildConfigs();
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
module.exports.config = (chainId, dex) => {
|
|
40
|
-
// No chainId: return defaults
|
|
41
|
-
if (!chainId) {
|
|
42
|
-
return { ...raw['*'] };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// chainId but no dex: return undefined (require both parameters)
|
|
46
|
-
if (!dex || typeof dex !== 'string' || dex.trim() === '') {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Both chainId and dex: return specific dex config or undefined
|
|
51
|
-
const allConfigs = buildConfigs();
|
|
52
|
-
const chainConfig = allConfigs[chainId];
|
|
53
|
-
|
|
54
|
-
return chainConfig && chainConfig.dex && chainConfig.dex[dex] ? chainConfig.dex[dex] : undefined;
|
|
55
|
-
};
|
|
5
|
+
function config(chainId, dexName) {
|
|
6
|
+
if (!chainId || !dexName?.trim()) return;
|
|
56
7
|
|
|
57
|
-
|
|
58
|
-
|
|
8
|
+
const chainConfig = raw[chainId];
|
|
9
|
+
if (!chainConfig) return;
|
|
59
10
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
return abiCache;
|
|
64
|
-
}
|
|
11
|
+
const { dex, ...chainDefaults } = chainConfig;
|
|
12
|
+
const dexOverrides = dex?.[dexName];
|
|
13
|
+
if (!dexOverrides) return;
|
|
65
14
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
wm: require('./out/WM.sol/WM.abi.json'),
|
|
69
|
-
repermit: require('./out/RePermit.sol/RePermit.abi.json'),
|
|
70
|
-
reactor: require('./out/OrderReactor.sol/OrderReactor.abi.json'),
|
|
71
|
-
executor: require('./out/Executor.sol/Executor.abi.json'),
|
|
72
|
-
refinery: require('./out/Refinery.sol/Refinery.abi.json'),
|
|
73
|
-
adapter: require('./out/DefaultDexAdapter.sol/DefaultDexAdapter.abi.json'),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// Build structure: { chainid: { dex: { dexname: { contract: abi }}}}
|
|
77
|
-
const result = {};
|
|
78
|
-
|
|
79
|
-
// Iterate through all chain configurations
|
|
80
|
-
for (const chainId in raw) {
|
|
81
|
-
if (chainId === '*') continue; // Skip the base config
|
|
82
|
-
|
|
83
|
-
const chainConfig = raw[chainId];
|
|
84
|
-
if (!chainConfig.dex) continue; // Skip if no dex config
|
|
85
|
-
|
|
86
|
-
result[chainId] = { dex: {} };
|
|
15
|
+
return { ...baseDefaults, ...chainDefaults, ...dexOverrides };
|
|
16
|
+
}
|
|
87
17
|
|
|
88
|
-
|
|
89
|
-
for (const dexName in chainConfig.dex) {
|
|
90
|
-
result[chainId].dex[dexName] = { ...coreAbis };
|
|
91
|
-
}
|
|
92
|
-
}
|
|
18
|
+
const loadAbi = (name) => require(`./out/${name}.sol/${name}.abi.json`);
|
|
93
19
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
20
|
+
const abis = {
|
|
21
|
+
wm: loadAbi('WM'),
|
|
22
|
+
repermit: loadAbi('RePermit'),
|
|
23
|
+
reactor: loadAbi('OrderReactor'),
|
|
24
|
+
executor: loadAbi('Executor'),
|
|
25
|
+
refinery: loadAbi('Refinery'),
|
|
26
|
+
adapter: loadAbi('DefaultDexAdapter'),
|
|
97
27
|
};
|
|
28
|
+
|
|
29
|
+
module.exports = { config, abis };
|
package/package.json
CHANGED