Skip to content

kovart/forta-bot-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forta Bot Analytics

Description

A helper library for semi-automatic calculation of the anomaly score for Forta bots.

Usage example

const analytics = new BotAnalytics(new FortaBotStorage(), {
  maxSyncDelay: 7 * 24 * 60 * 60, // 7d
  syncTimeout: 5 * 60, // 5m
  observableInterval: 24 * 60 * 60, // 24h
  defaultAnomalyScore: { [BotAnalytics.GeneralAlertId]: 0.123 },
});

const handleTransaction: HandleTransaction = async (txEvent: TransactionEvent) => {
  await analytics.sync(txEvent.timestamp);

  const tetherTransferEvents = txEvent.filterLog(ERC20_TRANSFER_EVENT, TETHER_ADDRESS);

  tetherTransferEvents.forEach((transferEvent) => {
    analytics.incrementBotTriggers(txEvent.timestamp);

    const { value } = transferEvent.args;
    const normalizedValue = value.div(10 ** TETHER_DECIMALS);

    if (normalizedValue.gt(TRANSFER_THRESHOLD)) {
      analytics.incrementAlertTriggers(txEvent.timestamp);
      findings.push(
        Finding.fromObject({
          ...
          metadata: {
            anomaly_score: analytics.getAnomalyScore()
          }
        })
      );
    }
  })
};

Sync algorithm

Working algorithm

About

🧾 Library for semi-automatic calculation of the anomaly score for Forta bot alerts

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published