nautechsystems/nautilus_trader · error · anyhow::Error

Wallet balance snapshot contains unexpected token addresses:

Error message

Wallet balance snapshot contains unexpected token addresses: {}

What it means

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.

Source

Thrown at crates/model/src/defi/wallet.rs:254

            .collect::<Vec<_>>();
        let mut unexpected = token_addresses
            .difference(&self.token_universe)
            .copied()
            .collect::<Vec<_>>();
        missing.sort_unstable();
        unexpected.sort_unstable();

        match (missing.is_empty(), unexpected.is_empty()) {
            (false, false) => anyhow::bail!(
                "Wallet balance snapshot is missing configured token addresses: {}; contains unexpected token addresses: {}",
                format_addresses(&missing),
                format_addresses(&unexpected)
            ),
            (false, true) => anyhow::bail!(
                "Wallet balance snapshot is missing configured token addresses: {}",
                format_addresses(&missing)
            ),
            (true, false) => anyhow::bail!(
                "Wallet balance snapshot contains unexpected token addresses: {}",
                format_addresses(&unexpected)
            ),
            (true, true) => Ok(()),
        }
    }
}

fn format_addresses(addresses: &[Address]) -> String {
    addresses
        .iter()
        .map(ToString::to_string)
        .collect::<Vec<_>>()
        .join(", ")
}

#[cfg(test)]
mod tests {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Add the listed unexpected addresses to your configured token set if they should be tracked.
  2. Filter the snapshot's balances to only configured addresses before validation.
  3. Confirm addresses are checksum-normalized identically in both config and snapshot.

Example fix

// before
let snapshot = WalletBalanceSnapshot::new(all_balances);
// after
let snapshot = WalletBalanceSnapshot::new(
    all_balances.into_iter().filter(|b| configured.contains(&b.token)).collect(),
);
Defensive patterns

Strategy: validation

Validate before calling

let extra: Vec<_> = snapshot.token_addresses().into_iter().filter(|a| !configured.contains(a)).collect();
debug_assert!(extra.is_empty(), "unexpected tokens in snapshot: {:?}", extra);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/e2bd68cd7ee8e0dd. Report an issue: GitHub.