import re
import requests

API_KEY = "<TRUFFLEHOG_REDACTED_BSCSCAN>"
BASE_URL = "https://api.bscscan.com/api"
similarity_threshold = 0.3

def remove_comments(source_code):
    # Remove single-line comments
    source_code = re.sub(r"//.", "", source_code)

    # Remove multi-line comments
    source_code = re.sub(r" / *[\s\S]? * / ", "", source_code)

    return source_code

def get_contract_source_code(address):
    params = {
    "module": "contract",
    "action": "getsourcecode",
    "address": address,
    "apiKey": API_KEY
    }

    response = requests.get(BASE_URL, params=params)
    data = response.json()

    if data["status"] == "1":
        source_code = data["result"][0]["SourceCode"]
        return remove_comments(source_code)
    else:
        return None

def jaccard_similarity(str1, str2):
    a = set(str1.split())
    b = set(str2.split())
    c = a.intersection(b)
    return float(len(c)) / (len(a) + len(b) - len(c))

def find_similar_contracts(reference_addresses, candidate_addresses):
    reference_source_codes = {}
    for reference_address in reference_addresses:
        source_code = get_contract_source_code(reference_address)
        if source_code is not None:
            reference_source_codes[reference_address] = source_code

    if not reference_source_codes:
        print("No source code found for reference contracts")
        return []

    similar_contracts = {}
    for address in candidate_addresses:
        candidate_source_code = get_contract_source_code(address)
        if candidate_source_code is not None:
            for reference_address, reference_source_code in reference_source_codes.items():
                similarity = jaccard_similarity(candidate_source_code, reference_source_code)
                if similarity >= similarity_threshold:
                    if reference_address not in similar_contracts:
                        similar_contracts[reference_address] = [(address, similarity)]
                    else:
                        similar_contracts[reference_address].append((address, similarity))

    return similar_contracts

if __name__ == "__main__":
    # Replace this list with a list of reference contract addresses to check
    reference_addresses = ["0x4401E60E39F7d3F8D5021F113306AF1759a6c168", "0x2023aa62a7570ffd59f13fde2cac0527d45abf91",    #1#    50-75x  75-100x
                           "0x445645eC7c2E66A28e50fbCF11AAa666290Cd5bb", "0x1f5FbCF2787140b2F05081Fd9f69Bc0F436B13C1",    #3#    20x   30-50x
                           "0x44f790ED5FfaEbeD9Ba91744b0CbE4D260F26A47", "0xa6C2d7788830E5ef286db79295C533F402Cca734,"     #5#    5-7x 4x
                           "0xd481997fbe2D7C7f9E651e5f2450AcbC38Eed750"]


    # Replace this list with a list of candidate contract addresses to check
    candidate_addresses = ["0xa6C2d7788830E5ef286db79295C533F402Cca734", "0x2023aa62a7570ffd59f13fde2cac0527d45abf91",    #1#
                           "0x445645eC7c2E66A28e50fbCF11AAa666290Cd5bb", "0x1f5FbCF2787140b2F05081Fd9f69Bc0F436B13C1",    #3#
                           "0x44f790ED5FfaEbeD9Ba91744b0CbE4D260F26A47", "0xa6C2d7788830E5ef286db79295C533F402Cca734",     #5#    5-7x 4x
                           "0xd481997fbe2D7C7f9E651e5f2450AcbC38Eed750"]                                                    #7#                                           #5#

    similar_contracts = find_similar_contracts(reference_addresses, candidate_addresses)
    print("Contracts with similar source code (ignoring comments):")
    for reference_address, similar_addresses in similar_contracts.items():
        print(f"Reference contract: {reference_address}")
        for address, similarity in similar_addresses:
            print(f"Similar contract: {address} with a similarity of {similarity:.2f}")

The code above does not process all the addresses in the reference_addresses and candidate_addresses arrays. Make it so that the comparison occurs at all addresses in these arrays