{"record":{"id":"a3439adf98f3c4d8","repo":"nautechsystems/nautilus_trader","slug":"invalid-factory-address-for-dex-name-on-chain-c","errorCode":null,"errorMessage":"Invalid factory address for DEX {name} on chain {chain} for factory address {factory}: {e}","messagePattern":"Invalid factory address for DEX (.+?) on chain (.+?) for factory address (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/dex.rs","lineNumber":204,"sourceCode":"        name: DexType,\n        factory: &str,\n        factory_creation_block: u64,\n        amm_type: AmmType,\n        pool_created_event: &str,\n        swap_event: &str,\n        mint_event: &str,\n        burn_event: &str,\n        collect_event: &str,\n    ) -> Self {\n        let encoded_pool_created_event =\n            hex::encode_prefixed(keccak256(pool_created_event.as_bytes()));\n        let encoded_swap_event = hex::encode_prefixed(keccak256(swap_event.as_bytes()));\n        let encoded_mint_event = hex::encode_prefixed(keccak256(mint_event.as_bytes()));\n        let encoded_burn_event = hex::encode_prefixed(keccak256(burn_event.as_bytes()));\n        let encoded_collect_event = hex::encode_prefixed(keccak256(collect_event.as_bytes()));\n        let factory_address = match validate_address(factory) {\n            Ok(address) => address,\n            Err(e) => panic!(\n                \"Invalid factory address for DEX {name} on chain {chain} for factory address {factory}: {e}\"\n            ),\n        };\n        Self {\n            chain,\n            name,\n            factory: factory_address,\n            factory_creation_block,\n            pool_created_event: encoded_pool_created_event.into(),\n            initialize_event: None,\n            swap_created_event: encoded_swap_event.into(),\n            mint_created_event: encoded_mint_event.into(),\n            burn_created_event: encoded_burn_event.into(),\n            collect_created_event: encoded_collect_event.into(),\n            flash_created_event: None,\n            fee_protocol_update_event: None,\n            fee_protocol_collect_event: None,\n            amm_type,","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/dex.rs#L186-L222","documentation":"AmmsDex/DEX constructor validates the factory contract address with validate_address() and panics if the hex string is not a valid address. The panic includes the DEX name, chain, offending address, and the underlying validation error so the misconfiguration is immediately obvious.","triggerScenarios":"Constructing a DEX (AmmDex::new) with a factory address that is not a valid 20-byte hex address (wrong length, missing 0x, non-hex characters, or a checksum/shape error from validate_address).","commonSituations":"Hardcoded config files with a truncated or malformed address; copying a factory address from docs of a different network; placeholder addresses left in a config; config values typed as ENS names instead of hex addresses.","solutions":["Fix the factory address in your configuration to a full 0x-prefixed 40-hex-character address","Run validate_address(factory) yourself before constructing the DEX to fail early with a clean message","Verify the address is the correct contract for the specified chain (e.g. via an explorer)"],"exampleFix":"// before\nlet dex = AmmDex::new(chain, \"UniswapV3\", \"0x1f9843...\"); // truncated -> panic\n// after\nlet factory = \"0x1F98431c8aD98523631AE4a59f267346ea31F984\";\nvalidate_address(factory).expect(\"valid factory address\");\nlet dex = AmmDex::new(chain, \"UniswapV3\", factory);","handlingStrategy":"validation","validationCode":"// Validate before constructing the DEX\nfn valid_factory(factory: &str) -> bool {\n    factory.len() == 42 && factory.starts_with(\"0x\") && factory[2..].chars().all(|c| c.is_ascii_hexdigit())\n}","typeGuard":"fn is_hex_address(s: &str) -> bool {\n    s.len() == 42 && s.starts_with(\"0x\") && s[2..].chars().all(|c| c.is_ascii_hexdigit())\n}","tryCatchPattern":"assert!(is_hex_address(factory), \"bad factory address: {factory}\");\nlet dex = AmmDex::new(chain, name, factory);","preventionTips":["Store factory addresses as validated constants, not free-form config strings","Cross-check addresses against a block explorer for the target chain","Run validate_address on all addresses at config load time"],"tags":["rust","panic","defi","address-validation","config"],"backgroundTag":"invalid-argument-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}