@orbs-network/spot 0.0.5 → 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 CHANGED
@@ -1,97 +1,29 @@
1
1
  const raw = require('./script/input/config.json');
2
2
 
3
- // Cache for processed configs
4
- let cachedConfigs = null;
3
+ const { dex: _globalDex, ...baseDefaults } = raw['*'] ?? {};
5
4
 
6
- // Helper to deep merge objects
7
- function deepMerge(base, override) {
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
- // Cache for ABIs to avoid rebuilding on every call
58
- let abiCache = null;
8
+ const chainConfig = raw[chainId];
9
+ if (!chainConfig) return;
59
10
 
60
- module.exports.abi = () => {
61
- // Return cached result if already built
62
- if (abiCache) {
63
- return abiCache;
64
- }
11
+ const { dex, ...chainDefaults } = chainConfig;
12
+ const dexOverrides = dex?.[dexName];
13
+ if (!dexOverrides) return;
65
14
 
66
- // Load core contract ABIs once
67
- const coreAbis = {
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
- // For each DEX on this chain, include all core ABIs
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
- // Cache the result
95
- abiCache = result;
96
- return result;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/spot",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "**A DeFi protocol for noncustodial advanced order types on EVM chains.**",
5
5
  "homepage": "https://github.com/orbs-network/spot#readme",
6
6
  "bugs": {
@@ -13,7 +13,7 @@
13
13
  "type": "default:openocean-v2",
14
14
  "router": "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
15
15
  "adapter": "0x0002ADE613182cf8dcc1a88b08bD3af975b51005",
16
- "fee": ""
16
+ "fee": "0xFee010ebA414C0FEF0b123DFA332bECE6Da69740"
17
17
  }
18
18
  }
19
19
  }