nautechsystems/nautilus_trader · error

Contract address should be set in logs

Error message

Contract address should be set in logs

What it means

parse_fee_protocol_update_event_hypersync unwraps log.address with expect() because a Hypersync log for a PancakeSwap V3 SetFeeProtocol event must carry the emitting contract address, which becomes the pool identifier. If the Hypersync query returned a log row without an address, this expect panics. The doc comment on these parsers explicitly documents the panic condition.

Source

Thrown at crates/adapters/blockchain/src/exchanges/parsing/pancakeswap_v3/fee_protocol_update.rs:78

        log,
    )?;

    if let Some(data) = &log.data {
        let data_bytes = data.as_ref();

        if data_bytes.len() < 4 * 32 {
            anyhow::bail!("SetFeeProtocol event data is too short");
        }

        let decoded = match <SetFeeProtocolEventData as SolType>::abi_decode(data_bytes) {
            Ok(decoded) => decoded,
            Err(e) => anyhow::bail!("Failed to decode SetFeeProtocol event data: {e}"),
        };

        let pool_address = Address::from_slice(
            log.address
                .clone()
                .expect("Contract address should be set in logs")
                .as_ref(),
        );
        let pool_identifier = PoolIdentifier::Address(Ustr::from(&pool_address.to_string()));

        Ok(FeeProtocolUpdateEvent::new(
            dex,
            pool_identifier,
            extract_block_number(log)?,
            extract_transaction_hash(log)?,
            extract_transaction_index(log)?,
            extract_log_index(log)?,
            decoded.fee_protocol0_new,
            decoded.fee_protocol1_new,
        ))
    } else {
        anyhow::bail!("Missing data in SetFeeProtocol event log");
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Ensure the Hypersync query/request includes the log address field in its selected columns so every returned log has an address.
  2. Guard before calling: skip or log-and-drop logs with address None instead of passing them to the parser.
  3. In the parser, replace expect with ok_or(anyhow!(...)) to return a recoverable error for address-less logs.

Example fix

// before
let pool_address = Address::from_slice(
    log.address.clone().expect("Contract address should be set in logs").as_ref(),
);
// after
let raw_address = log.address.as_ref()
    .ok_or_else(|| anyhow::anyhow!("missing contract address in SetFeeProtocol log"))?;
let pool_address = Address::from_slice(raw_address.as_ref());
Defensive patterns

Strategy: validation

Validate before calling

if log.address.is_none() {
    log::warn!("skipping SetFeeProtocol log without contract address");
    return Ok(());
}
let event = parse_fee_protocol_update_event_hypersync(dex.clone(), &log)?;

Type guard

fn has_address(log: &HypersyncLog) -> bool {
    log.address.is_some()
}

Try / catch

match parse_fee_protocol_update_event_hypersync(dex, &log) {
    Ok(event) => handle(event),
    Err(e) => log::error!("failed to parse SetFeeProtocol log: {e:#}"),
}
// Note: missing address panics via expect(); pre-check log.address before calling.

Prevention

When it happens

Trigger: Calling parse_fee_protocol_update_event_hypersync with a HypersyncLog whose address field is None — i.e. a log produced by a Hypersync query that did not request/return the address field, or a hand-built test log missing address.

Common situations: Hypersync schema/API changes or query projections that omit log.address; constructing synthetic HypersyncLog fixtures without setting address; upstream Hypersync returning partial rows for contract-creation or malformed logs.

Related errors


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