Skip to content

Commit

Permalink
handle spam deposits made to Safe (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtzman authored Jul 9, 2024
1 parent 2faa9a6 commit 75d454e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/gnosis/api_data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub struct MultiSigTransaction {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct TokenInfo {
/// Number of decimals in non-integer representation
pub decimals: u32,
pub decimals: Option<u32>,

/// Address of the token contract
pub address: String,
Expand Down Expand Up @@ -143,7 +143,7 @@ pub struct EthereumTransfer {
pub token_info: Option<TokenInfo>,

/// Value being transferred
pub value: EthTxValue,
pub value: Option<EthTxValue>,
}

/// Ethereum transaction
Expand Down
3 changes: 3 additions & 0 deletions src/gnosis/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum Error {
/// Api result parse error: {0}
ApiResultParse(String),

/// Unknown Token: {0}
UnknownToken(String),

/// Other: {0}
Other(String),
}
Expand Down
20 changes: 15 additions & 5 deletions src/gnosis/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,17 @@ impl GnosisSync {

match tx.decode()? {
Transaction::Ethereum(eth_tx) => {
self.process_eth_transaction(&conn, &eth_tx)?;
match self.process_eth_transaction(&conn, &eth_tx) {
Ok(_) => {}
Err(err) => {
// log but otherwise ignore unknown token transfers
if let Error::Gnosis(GnosisError::UnknownToken(_)) = err {
log::warn!(self.logger, "Unknown token deposited to Safe");
} else {
return Err(err);
}
}
}
}
Transaction::MultiSig(multi_sig_tx) => {
self.process_multi_sig_transaction(&conn, &multi_sig_tx)?;
Expand Down Expand Up @@ -150,11 +160,11 @@ impl GnosisSync {
.iter()
.find(|token| token.eth_token_contract_addrs.contains(token_addr))
.ok_or_else(|| {
GnosisError::ApiResultParse("Unknown transfer token address".into())
GnosisError::UnknownToken("Unknown token transfer".into())
})?;

let truncated_transaction_value = truncate_value(
transfer.value,
transfer.value.unwrap(),
token_config.decimals,
self.audited_safe.token_decimals_max,
);
Expand All @@ -163,7 +173,7 @@ impl GnosisSync {
None,
transfer.tx_hash,
tx.execution_date,
transfer.value,
transfer.value.unwrap(),
tx.eth_block_number,
transfer.to.clone(),
token_addr.clone(),
Expand Down Expand Up @@ -384,7 +394,7 @@ impl GnosisSync {
let token_transfer = &token_transfers[0];

// The number hould be EthTxValue-parseable
let eth_tx_value = token_transfer.value;
let eth_tx_value = token_transfer.value.unwrap();

// the recipient address of the transaction
let to_addr = token_transfer.to.clone();
Expand Down

0 comments on commit 75d454e

Please sign in to comment.