{"record":{"id":"e2bd68cd7ee8e0dd","repo":"nautechsystems/nautilus_trader","slug":"wallet-balance-snapshot-contains-unexpected-token","errorCode":null,"errorMessage":"Wallet balance snapshot contains unexpected token addresses: {}","messagePattern":"Wallet balance snapshot contains unexpected token addresses: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/wallet.rs","lineNumber":254,"sourceCode":"            .collect::<Vec<_>>();\n        let mut unexpected = token_addresses\n            .difference(&self.token_universe)\n            .copied()\n            .collect::<Vec<_>>();\n        missing.sort_unstable();\n        unexpected.sort_unstable();\n\n        match (missing.is_empty(), unexpected.is_empty()) {\n            (false, false) => anyhow::bail!(\n                \"Wallet balance snapshot is missing configured token addresses: {}; contains unexpected token addresses: {}\",\n                format_addresses(&missing),\n                format_addresses(&unexpected)\n            ),\n            (false, true) => anyhow::bail!(\n                \"Wallet balance snapshot is missing configured token addresses: {}\",\n                format_addresses(&missing)\n            ),\n            (true, false) => anyhow::bail!(\n                \"Wallet balance snapshot contains unexpected token addresses: {}\",\n                format_addresses(&unexpected)\n            ),\n            (true, true) => Ok(()),\n        }\n    }\n}\n\nfn format_addresses(addresses: &[Address]) -> String {\n    addresses\n        .iter()\n        .map(ToString::to_string)\n        .collect::<Vec<_>>()\n        .join(\", \")\n}\n\n#[cfg(test)]\nmod tests {","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/wallet.rs#L236-L272","documentation":"validate_token_addresses fails when the snapshot holds token addresses that are not in the configured set (with no missing addresses). Extra tokens make the snapshot inconsistent with expectations, so account_balances refuses to proceed.","triggerScenarios":"Calling account_balances when the wallet received an airdrop or new token after configuration, or the snapshot was built from a broader token list than the configured one.","commonSituations":"Untracked token transfers appearing in the wallet, a snapshot reused across configurations, or a case/checksum mismatch making the same token look like a new address.","solutions":["Add the listed unexpected addresses to your configured token set if they should be tracked.","Filter the snapshot's balances to only configured addresses before validation.","Confirm addresses are checksum-normalized identically in both config and snapshot."],"exampleFix":"// before\nlet snapshot = WalletBalanceSnapshot::new(all_balances);\n// after\nlet snapshot = WalletBalanceSnapshot::new(\n    all_balances.into_iter().filter(|b| configured.contains(&b.token)).collect(),\n);","handlingStrategy":"validation","validationCode":"let extra: Vec<_> = snapshot.token_addresses().into_iter().filter(|a| !configured.contains(a)).collect();\ndebug_assert!(extra.is_empty(), \"unexpected tokens in snapshot: {:?}\", extra);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter snapshot balances to configured addresses before validation.","Keep configuration in sync when the wallet receives new tokens."],"tags":["defi","validation","unexpected-data"],"backgroundTag":"schema-validation-failed","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"}