Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kovart/forta-bot-analytics
๐งพ Library for semi-automatic calculation of the anomaly score for Forta bot alerts
https://github.com/kovart/forta-bot-analytics
anomaly bot forta helper
Last synced: 4 days ago
JSON representation
๐งพ Library for semi-automatic calculation of the anomaly score for Forta bot alerts
- Host: GitHub
- URL: https://github.com/kovart/forta-bot-analytics
- Owner: kovart
- Created: 2023-01-20T12:32:12.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-24T14:29:28.000Z (9 months ago)
- Last Synced: 2024-04-25T07:00:41.198Z (7 months ago)
- Topics: anomaly, bot, forta, helper
- Language: TypeScript
- Homepage:
- Size: 292 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Forta Bot Analytics
### Description
A helper library for semi-automatic calculation of the anomaly score for Forta bots.
### Usage example
```ts
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](https://raw.githubusercontent.com/kovart/forta-bot-analytics/main/blob/algorithm.svg)