From 21ba3c0604f302216ab527938e6e641708f94c30 Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Wed, 23 Apr 2025 13:32:22 +0200 Subject: [PATCH] Load router and token addresses from env vars. --- .../uniswap/nomiswap/src/constants/chains.js | 7 ++--- .../uniswap/nomiswap/src/constants/coins.js | 26 ++++++------------- .../uniswap/nomiswap/src/constants/env.js | 21 +++++++++++++++ 3 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 sz-poc-offsite-2025/uniswap/nomiswap/src/constants/env.js diff --git a/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/chains.js b/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/chains.js index f5bd7a6..135bdb1 100644 --- a/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/chains.js +++ b/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/chains.js @@ -1,4 +1,6 @@ -export const networks = [1, 3,4,5,42,123, 1337, 65110000, 65010000] +import config from './env.js'; + +export const networks = [1, 3, 4, 5, 42, 123, 1337, 65110000, 65010000] export const ChainId = { MAINNET: 1, @@ -21,5 +23,4 @@ routerAddress.set(ChainId.KOVAN, "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); routerAddress.set(ChainId.DEVNET, "0x04e555283D37aE85F6eB311fe2578F3B3f3dFc52"); routerAddress.set(ChainId.AUTONITY, "0x04e555283D37aE85F6eB311fe2578F3B3f3dFc52"); routerAddress.set(ChainId.PARASTATE, "0x07a1905D44feeA439ceFAabd11a63bEf684abE11"); -routerAddress.set(ChainId.GANCHE, "0x0F44AC51198D8F99847db6C431448dBC673428f1"); - +routerAddress.set(ChainId.GANCHE, config.routerAddress); diff --git a/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/coins.js b/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/coins.js index 6e4541c..9f9e9bf 100644 --- a/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/coins.js +++ b/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/coins.js @@ -1,4 +1,5 @@ import * as chains from './chains'; +import config from './env.js'; // If you add coins for a new network, make sure Weth address (for the router you are using) is the first entry @@ -74,7 +75,7 @@ const PARASTATECoins = [ abbr: "TB", address: "0x4489D87C8440B19f11d63FA2246f943F492F3F5F", }, - + { name: "Token C", abbr: "TC", @@ -94,25 +95,14 @@ const GANACHECoins = [ address: "", // Weth address is fetched from the router }, { - name: "Token A", - abbr: "TA", - address: "0xE8C4BE1Bd495c984dD83B683966B7B538d3Ea82C", + name: "Mehmet", + abbr: "MEM", + address: config.tokenMemAddress, }, { - name: "Token B", - abbr: "TB", - address: "0x30988e63329713c3f3FeA1ca1B94D4Abb02F78C5", - }, - - { - name: "Token C", - abbr: "TC", - address: "0x23b4ce07ef4e2378319E40CbC0cc95EAbCf8E419", - }, - { - name: "Token D", - abbr: "TD", - address: "0x49Ec3915F4daB907f7C6F74Cf5110366FCCc81A5", + name: "New Ether", + abbr: "NET", + address: config.tokenNetAddress, } ] diff --git a/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/env.js b/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/env.js new file mode 100644 index 0000000..6a532e3 --- /dev/null +++ b/sz-poc-offsite-2025/uniswap/nomiswap/src/constants/env.js @@ -0,0 +1,21 @@ +import 'dotenv/config.js'; + +const REQUIRED_ENV = [ + "REACT_APP_NOMISWAP_ROUTER_ADDRESS", + "REACT_APP_NOMISWAP_TOKEN_MEM", + "REACT_APP_NOMISWAP_TOKEN_NET" +]; + +const missingVars = REQUIRED_ENV.filter(key => !process.env[key]); +if (missingVars.length > 0) { + console.error(`❌ Missing required environment variables: ${missingVars.join(', ')}`); + process.exit(1); +} + +const config = { + routerAddress: process.env.REACT_APP_NOMISWAP_ROUTER_ADDRESS, + tokenMemAddress: process.env.REACT_APP_NOMISWAP_TOKEN_MEM, + tokenNetAddress: process.env.REACT_APP_NOMISWAP_TOKEN_NET +}; + +export default config; \ No newline at end of file