Defi Graph
This is package for creating and visualizing graphs in DeFi protocols.
Install
Install using pip or uv
pip install defigraph
# or using uv
uv add defigraph
Modules
- Edge - describes a path between tokens
- Vertex - describes a token
- Graph - describes a defi market
- Pool - describes trading token pairs
Edge type
Edges store two main state:
self.weight- a weight between two tokens- typeof
float {0,1}Depends on direction of edge- Calculated as
-Math.log(self.pool.token_price_{0,1})
- typeof
self.pool- an instance of a token pool- typeof
Pool
- typeof
self._tuple- Allows indexing/iteration of the edge object- typeof
iter - Array of
[Vertex1, Vertex2, (self.weight, Pool)]
- typeof
Pool type
A pool object describing tokens:
self.address- the address of the pool- typeof
Hexchecksum address
- typeof
self.token0- a token described as a vertex- typeof
Vertex
- typeof
self.token1- a token described as a vertex- typeof
Vertex
- typeof
self.token0_price- the price of token0- typeof
float
- typeof
self.token1_price- the price of token1- typeof `float
self.fee- describes the pool fee e.g Uniswap (100 | 500 | 1000 | 3000)- typeof
int
- typeof
Graph type
An adjacency list graph object desribing a defi market
self.vertices- contains a list of all vertices- typeof
List[Vertex]
- typeof
self.adjascency_list- a mapping describing edges in the graph- typeof
Dict[Vertex, List[Edge]] - example: {Vertex: [Edge1, Edge2, Edge3, Edge4]}
- typeof
Vertex type
A node on the graph describing a token
self.name- name of the token- typeof
string
- typeof
self.decimals- number of decimals for token- typeof
int
- typeof
self.address- address of token- typeof
Hexchecksum address
- typeof
Tests
Run tests:
pytest
Usage
See example in docs/notebooks/graph.ipynb
Metadata
Release files for defigraph 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| defigraph-0.1.2.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| defigraph-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / defigraph-0.1.2.tar.gz
| Download URL | defigraph-0.1.2.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32ae51f65c8ac35d7a6ca7d1289c4a55740fa41264e64d83450221f25e6efc51
|
|
BLAKE2b-256 checksum How to use checksums |
4122d722f815fc4125ba010e4cab33583a162c0ce61481f3220637a34756a823
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / defigraph-0.1.2-py3-none-any.whl
| Download URL | defigraph-0.1.2-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3a83e65df37cb85c046a2bd1462e03c13185f56c48995df4afe2f5bd2881eb3
|
|
BLAKE2b-256 checksum How to use checksums |
e3e5a1357245a017368f54639855659eca00cc2de27c4239c31787c2b8e78688
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|