sblegos package#
Submodules#
sblegos.TransactionAnalyser module#
- class sblegos.TransactionAnalyser.TransactionAnalyser(df_transactions, array_address)[source]#
Bases:
objectThis class is used to analyse transactions of an address. It has methods that allows to perform on chain analysis of an address.
- count_interaction_any(address, array_address)[source]#
Return an integer of the number of interactions with the addresses in the array_address :param address: The address to check :type address: str :param array_address: The array of addresses to check :type array_address: narray
- Returns:
count_interaction_with_any – The number of interactions with the addresses in the array_address
- Return type:
int
- count_interaction_with_other_contributor(address)[source]#
Return the number of interactions of the address with other contributor (not itself) :param address: The address to check :type address: str
- Returns:
count_interaction_with_other_contributor – The number of interactions of the address with other contributor (not itself)
- Return type:
int
- count_same_seed(address)[source]#
Return the number of address having the same seed wallet as one of the seed wallet of the df_transactions using a non-naive algorithm. For some address the first transaction is not the incoming funding transaction. It is possible to interact with a smart contract even before receiving any fund. This algorithm takes that into account. Note that it does not retrieve the true funder through the internal transaction but the first incoming transaction.
- Parameters:
address (str) – The address to check
- Returns:
count_same_seed – The number of addresses having the same seed wallet as one of the seed wallet of the df_transactions
- Return type:
int
- count_same_seed_naive(address)[source]#
Return if the address has the same seed wallet as one of the seed wallet of the df_transactions
If the df_seed_wallet is not set, it will set it Note df_transaction could contain transactions from multiple network but the seed wallet of the address is filtered which prevent unexpected raise of the boolean.
- Parameters:
address (str) – The address to check
- Returns:
count_same_seed – The number of addresses having the same seed wallet
- Return type:
int
- count_transactions(address)[source]#
Return the number of transactions of the address :param address: The address to check :type address: str
- Returns:
count_transactions – The number of transactions of the address
- Return type:
int
- static get_address_same_seed(df, address)[source]#
Return a df of address that have the same seed wallet as the address given in parameter. :param df: The df to filter :type df: pd.DataFrame :param address: The address to check :type address: str
- Returns:
df_same_seed – The df of address that have the same seed wallet as the address given in parameter.
- Return type:
pd.DataFrame
- get_address_transactions(address)[source]#
Get transactions of an address from the self.df_transaction df using the group by :param address: The address to retrieve transactions :type address: str
- Returns:
df – The data frame with the transactions of the address
- Return type:
pd.DataFrame
- get_address_transactions_add(df, address)[source]#
Get transactions of an address from a dataframe df :param df: Data frame of transactions with the ‘EOA’ column :type df: pd.dataFrame :param address: The address to retrieve transactions :type address: str
- Returns:
df – The data frame with the transactions of the address
- Return type:
pd.DataFrame
- static get_array_transactions(df_address_transactions, address, algo_type='address_only')[source]#
This method replace the target address by an arbitrary “x” to be able to compare the similitude of two wallet.
- Parameters:
df_address_transactions (pd.DataFrame) – The data frame of transactions
address (str) – The address to replace by x
algo_type (str) –
- The type of algorithm to use,
”address_only” only return from_address and to_address with the address replaced by x “address_and_value” return from_address, value, to_address with the address replaced by x
- Returns:
array_transactions – An array of strings
- Return type:
narray
- get_contributors()[source]#
Return a list of contributors of the grant :returns: contributors – The array of contributors of the grant :rtype: narray
- get_df_features(list_features=None)[source]#
Get the features of the transaction dataset :param list_features:
- The list of features to retrieve, if None, the default features are retrieved[‘count_tx’, ‘less_10_tx’,
‘count_same_seed’, ‘count_same_seed_naive’,’same_seed’, ‘same_seed_naive’, ‘seed_suspicious’, ‘count_interact_other_ctbt’,’details_first_incoming_transaction’, ‘details_first_outgoing_transaction’] if ‘all’ is passed, the lcs feature is added
- Returns:
df_features – The data frame with the features index : EOA all unique addresses in the df_transactions
- Return type:
pd.DataFrame
- has_interacted_with_any(address, array_address)[source]#
Return a boolean whether the address has interacted with any address in the array_address :param address: The address to check :type address: str :param array_address: The array of addresses to check :type array_address: narray
- Returns:
has_interacted_with_any – True if the address has interacted with one or more of the addresses in the array_address
- Return type:
bool
- has_interacted_with_other_contributor(address)[source]#
Return a boolean whether the address has interacted with other contributor (not itself) :param address: The address to check :type address: str
- Returns:
has_interacted_with_other_contributor – True if the address has interacted with one or more contributor of the grant
- Return type:
bool
- has_less_than_n_transactions(address, n=5)[source]#
Return a boolean whether the address has less than n transactions :param address: The address to check :type address: str :param n: The number of transactions :type n: int
- Returns:
has_less_than_n_transactions – True if the address has less than n transactions
- Return type:
bool
- has_same_seed(address)[source]#
Return if the address has the same seed wallet as one of the seed wallet of the df_transactions using a non-naive algorithm. For some address the first transaction is not the incoming funding transaction. It is possible to interact with a smart contract even before receiving any fund. This algorithm takes that into account.
You should consider using count_same_seed_naive and applying a vectorized operation.
2. df_transaction could contain transactions from multiple network but the seed wallet of the address is filtered which prevent unexpected raise of the boolean.
- Parameters:
address (str) – The address to check
- Returns:
has_same_seed – True if the address has the same seed wallet as one of the seed wallet of the df_transactions
- Return type:
bool
- has_same_seed_naive(address)[source]#
Return if the address has the same seed wallet as one of the seed wallet of the df_transactions
Note 1. You should consider using count_same_seed_naive and applying a vectorized operation. 2. df_transaction could contain transactions from multiple network but the seed wallet of the address is filtered which prevent unexpected raise of the boolean.
- Parameters:
address (str) – The address to check
- Returns:
has_same_seed – True if the address has the same seed wallet as one of the seed wallet of the df_transactions
- Return type:
bool
- has_suspicious_seed_behavior(address)[source]#
Return a boolean whether the address has suspicious seed behavior. Most addresses have a seed wallet that is given by first transaction given by the naive algorithm. However, some addresses first transaction is no the first incoming transaction because they first interacted with a smart contract. This is a suspicious behavior. :param address: The address to check :type address: str
- Returns:
has_suspicious_seed_behavior – True if the address has suspicious seed behavior
- Return type:
bool
- set_details_first_incoming_transaction()[source]#
Set the details_first_incoming_transaction attribute of the class. It holds the details of the first incoming transaction of the address given in parameter
- Returns:
Set the details_first_incoming_transaction attribute of the class
- Return type:
None
- set_dict_add_interacted()[source]#
Set the dict_add_interacted attribute of the class. It holds a dictionary of address as key and the list of address interacted with as value. Returns None ——-
- set_dict_add_string_transactions(algo_type='address_only')[source]#
This method create a dictionary with the address as key and the array of transactions as value. The array of transactions is the array crated with the get_array_transactions method. :param algo_type: The type of algorithm to use :type algo_type: str
- Returns:
it sets the self.dict_add_string_tx or self.dict_add_value_string_tx attribute
- Return type:
None
- set_group_by_sorted_EOA()[source]#
Set the gb_EOA_sorted attribute of the class it holds the df_transactions sorted by block_timestamp and grouped by EOA
- Returns:
Set the gb_EOA_sorted attribute of the class
- Return type:
None
- set_seed_wallet()[source]#
Set the df_seed_wallet attribute of the class. It holds the seed wallet of the addresses in ‘EOA’ of df_transactions. It is a non-naive method that look for the first incoming transaction of the address to get the seed wallet. :returns: Set the df_seed_wallet attribute of the class :rtype: None
- set_seed_wallet_naive()[source]#
Set the df_seed_wallet_naive attribute of the class. It holds the seed wallet of the addresses in ‘EOA’ using a naive method that takes the from_address from the transaction of the address
- Returns:
Set the df_seed_wallet_naive attribute of the class
- Return type:
None
- transaction_similitude_pylcs(address, algo_type='address_only', minimum_sim_tx=5)[source]#
Return a boolean and the list of addresses if it finds other addresses with similar actions. it first stores some repetitive tasks into a class attribute and then use it to speed up the process.
The algorithm is the following: 1. Transform all transactions in to a String of the form: “from_address, to_address, from_address, to_address, …” 2. Replace the address of the wallet by “x” to ba able to compare the behavior of two addresses. 3. Run the algorithm common longest substring on all the transactions 4. If the longest common substring is longer than 5, return true for the current address. 5. Keep iterating to find the longest common substring and then the score is the length of the longest common substring divided by half the length of the target address string. The score is the min(score, 1) to avoid having a score > 1.
- Parameters:
address (str) – The address to check
algo_type (str) – The type of algorithm to use. Default is “address_only” which only use the address to compare. options are: address_only, address_and_value
minimum_sim_tx (int) – The number of transactions to use to compare. Default is 5.
char_tolerance (#) –
0. (# The number of character to skip when using the longest common substring algorithm. Default is) –
"address_and_value". (# 1 may be a good choice when algo_type is) –
- Returns:
has_similar_behavior (bool) – True if the address has similar behavior as another address
score_similar_behavior (float) – The similarity score of the address
list_similar_address (map) – The map of address and their similarity score