pub async fn filter_deployed_contracts(
        &mut self,
        addresses: impl Iterator<Item = Address>,
        at_l2_block: Option<L2BlockNumber>,
    ) -> DalResult<HashMap<Address, (L2BlockNumber, H256)>> {
        let (bytecode_hashed_keys, address_by_hashed_key): (Vec<_>, HashMap<_, _>) = addresses
            .map(|address| {
                let hashed_key = get_code_key(&address).hashed_key().0;
                (hashed_key, (hashed_key, address))
            })
            .unzip();
        let max_l2_block_number = at_l2_block.map_or(u32::MAX, |number| number.0);
        // Get the latest `value` and corresponding `miniblock_number` for each of `bytecode_hashed_keys`. For failed deployments,
        // this value will equal `FAILED_CONTRACT_DEPLOYMENT_BYTECODE_HASH`, so that they can be easily filtered.
        let rows = sqlx::query!(
            r#"
            SELECT
                sl.hashed_key,
                lat.miniblock_number,
                lat.value
            FROM
                storage_logs sl
            JOIN LATERAL (
                SELECT
                    miniblock_number,
                    value
                FROM
                    storage_logs
                WHERE
                    hashed_key = sl.hashed_key
                    AND miniblock_number <= $2
                    AND miniblock_number <= COALESCE(
                        (
                            SELECT
                                MAX(number)
                            FROM
                                miniblocks
                        ),
                        (
                            SELECT
                                miniblock_number
                            FROM
                                snapshot_recovery
                        )
                    )
                ORDER BY
                    miniblock_number DESC,
                    operation_number DESC
                LIMIT 1
            ) lat
                ON TRUE
            WHERE
                hashed_key = ANY($1)
            "#,
            &bytecode_hashed_keys as &[_],
            i64::from(max_l2_block_number)
        )
        .instrument("filter_deployed_contracts")
        .with_arg("addresses.len", &bytecode_hashed_keys.len())
        .with_arg("at_l2_block", &at_l2_block)
        .report_latency()
        .fetch_all(self.storage)
        .await?;

        let deployment_data = rows.into_iter().filter_map(|row| {
            let bytecode_hash = H256::from_slice(&row.value);
            if bytecode_hash == FAILED_CONTRACT_DEPLOYMENT_BYTECODE_HASH {
                return None;
            }
            let l2_block_number = L2BlockNumber(row.miniblock_number as u32);
            let address = address_by_hashed_key[row.hashed_key.as_slice()];
            Some((address, (l2_block_number, bytecode_hash)))
        });
        Ok(deployment_data.collect())
    }
Returns addresses and the corresponding deployment L2 block numbers among the specified contract
`addresses`. `at_l2_block` allows filtering deployment by L2 blocks.
core/lib/dal/src/storage_logs_dal.rs