Skip to content

Commit

Permalink
Merge pull request #3 from 0LNetworkCommunity/trade-stats
Browse files Browse the repository at this point in the history
[analytics] add statistical enrichment at extract step
  • Loading branch information
0o-de-lally authored Dec 4, 2024
2 parents 9dabb28 + 523184a commit ec7376e
Show file tree
Hide file tree
Showing 23 changed files with 1,668 additions and 361 deletions.
27 changes: 27 additions & 0 deletions docs/local_testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Local Testing

## From Neo4j Desktop
Start a Neo4j instance. Choose a password `<password>`. Allow it to create the default database namespace `neo4j`.

```
export LIBRA_GRAPH_DB_URI='neo4j://localhost'
export LIBRA_GRAPH_DB_USER='neo4j'
export LIBRA_GRAPH_DB_PASS=<password>
```

Import the sample exchange orders

```
cargo r enrich-exchange --exchange-json ./tests/fixtures/savedOlOrders2.json
```

## View graph

Go to Neo4j Explorer and try:
```
MATCH ()-[r:Swap]->()
RETURN COUNT(DISTINCT(r))
```

Should return `25450`
49 changes: 49 additions & 0 deletions docs/sample_cql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@


# Cypher query to map shill trades

```
//Top 100 shill pairs
MATCH (from:SwapAccount)-[r:Swap {shill_bid: true}]->(to:SwapAccount)
WHERE r.price_vs_rms_hour > 1
// combine from and to as users
WITH DISTINCT(collect(DISTINCT from) + collect(DISTINCT to)) AS all_users, r
UNWIND all_users AS user
WITH user, COUNT(r) AS shill_bid_count
// sorts by user with the highest count of relations with shill_bid
ORDER BY shill_bid_count DESC
// get top 100
LIMIT 100
// find all paths of owners, to tx, to onramp account
// don't need to find all paths, just the shortest one
MATCH p=SHORTEST 1 ()-[o:Owns]->(:Account)-[t:Tx]-()-[:OnRamp]->(user)
// use regex to exclude certain functions
WHERE NOT t.function =~ '(?i).*vouch.*'
// or better
/ WHERE NONE(r IN relationships(p) WHERE r.function IS NOT NULL AND r.function =~ '(?i).*vouch.*' )
// show the paths
return p
```


# Find all known users and their exchange address
```
WITH ['0xf57d3968d0bfd5b3120fda88f34310c70bd72033f77422f4407fbbef7c24557a'] AS exclude
MATCH p = SHORTEST 1 (o:Owner)-[r *..3]->(:SwapAccount)
WHERE NONE(
r IN relationships(p)
WHERE r.function IS NOT NULL
AND r.function =~ '(?i).*vouch.*'
)
AND NONE(
n IN nodes(p)
WHERE n.address IS NOT NULL
AND n.address IN exclude
)
RETURN p
```
Loading

0 comments on commit ec7376e

Please sign in to comment.