
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
This library allows to get DeFi data from several protocols in a structured and standard way. This data comes from different subgraphs displayed in The Graph protocol
Python 3.6
pip install deficrawler
To get data from a protocol, it's needed to create an instance of the protocol with the name, version and blockchain where the protocols exists, the supported protocols can be found in supported protocols section. And the entities for the protocols with the field types in the entities folder
To get data from Lending protocols
# Instanciate the protocol with the name, version and chain
from deficrawler import Lending
aave = Lending(protocol="Aave", chain="Ethereum", version=2)
aave_polygon = Lending(protocol="Aave", chain="Polygon", version=2)
compound = Lending(protocol="Compound", chain="Ethereum", version=2)
cream = Lending(protocol="Cream", chain="Ethereum", version=2)
cream_bsc = Lending(protocol="Cream", chain="bsc", version=2)
# Not all the protocols has the same available events to get data, to know which entities are supported for each protocol:
aave.supported_entities()
uniswap.suported_entities()
## For each different entity, data can be retrieved in a specific time range.
compound.get_data_from_date_range(start_date, end_date, "borrow")
# To get the all the users of a protocol
cream_bsc.get_all_users()
# And the user positions
cream_bsc.get_all_users(user)
To get data from Dex protocols
# Instanciate the protocol with the name, version and chain
from deficrawler import Dex
uniswap = Dex(protocol="Uniswap", chain="Ethereum", version=2)
balancer = Dex(protocol="Balancer", chain="Ethereum", version=1)
bancor = Dex("Bancor", chain="Ethereum", version=1)
shushi = Dex("SushiSwap", chain="Ethereum", version=1)
# Not all the protocols has the same available events to get data, to know which entities are supported for each protocol:
uniswap.supported_entities()
balancer.suported_entities()
## For each different entity, data can be retrieved in a specific time range.
uniswap.get_data_from_date_range(start_date_amm, end_date_amm, "swap")
# To get the all the pools of a protocol
uniswap.get_all_pools()
To get prices from the oracles it's needed to instanciate an oracle object and call the functions.
# Instanciate the oracle with the name, version and chain
from deficrawler import Oracle
chainlink = Oracle(protocol="chainlink", version=1, chain="Ethereum")
#Get all the available pairs to get the data
chainlink.get_all_pairs()
#Get the price for a specific pair in a time range
chainlink.get_price_from_date_range(from_date=start_date, to_date=end_date, pair="ETH/USD")
Name | Type | Version | Chain |
---|---|---|---|
Aave | Lending | 2 | Ethereum |
Aave | Lending | 2 | Polygon |
Aave | Lending | 2 | Avalanche |
Compound | Lending | 2 | Ethereum |
Cream | Lending | 2 | Ethereum |
Cream | Lending | 2 | BSC |
Cream | Lending | 2 | Polygon |
Cream | Lending | 2 | Arbitrum |
Cream | Lending | 2 | Avalance |
Cream | Lending | 2 | Fantom |
Kashi | Lending | 1 | Ethereum |
Kashi | Lending | 1 | Polygon |
Kashi | Lending | 1 | xDai |
Kashi | Lending | 1 | fantom |
Uniswap | Dexes | 2 | Ethereum |
Uniswap | Dexes | 3 | Ethereum |
Uniswap | Dexes | 3 | Optimism |
Balancer | Dexes | 2 | Ethereum |
Balancer | Dexes | 2 | Arbitrum |
Balancer | Dexes | 2 | Polygon |
Bancor | Dexes | 1 | Ethereum |
SushiSwap | Dexes | 1 | Ethereum |
SushiSwap | Dexes | 1 | BSC |
SushiSwap | Dexes | 1 | Polygon |
SushiSwap | Dexes | 1 | Fantom |
SushiSwap | Dexes | 1 | Celo |
Dodoex | Dexes | 2 | Ethereum |
Dodoex | Dexes | 2 | Polygon |
Dodoex | Dexes | 2 | BSC |
Dodoex | Dexes | 2 | Arbitrum |
Ubeswap | Dexes | 1 | Celo |
Pancakeswap | Dexes | 2 | BSC |
Pangolin | Dexes | 1 | Avalanche |
Traderjoe | Dexes | 1 | Avalanche |
Name | Type | Version | Chain |
---|---|---|---|
Chainlink | Oracle | 1 | Ethereum |
Tests are creatd using Pytest library. To run the tests
pytest -v
To run the examples run
python3 docs/examples.py
If you want to add a new protocol to be supported or a new entity to retrive data, create a PR with the new configuration of the protocol and the unit/integration tests of this new feature.
To add a new protocol, create a new json config file in the config folder, with the struture protocolname-version.json
.
Inside this configuration file must be the following sections:
This section specifies the global configuration of the protocol. The required fields are
Example
"protocol": {
"name": "AAVE",
"type": "Lending",
"version": 2,
"endpoint": {
"ethereum": "https://api.thegraph.com/subgraphs/name/aave/protocol-v2",
"polygon": "https://api.thegraph.com/subgraphs/name/aave/aave-v2-matic"
}
}
After this section the supported entities should be specified. Each entity has three different sections inside of them.
"borrow": {
"attributes": {
"tx_id":[
"id"
],
"user": [
"user",
"id"
],
"token": [
"reserve",
"symbol"
],
"amount": [
"amount"
],
"timestamp": [
"timestamp"
]
}
"query": {
"extra_fields": {
"decimals": [
"reserve",
"decimals"
]
},
"name": "borrows",
"params": {
"orderBy": "timestamp"
}
}
"transformations": {
"amount": "decimals",
"tx_id":"tx_id_colon"
}
Copyright 2020 Keyko GmbH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
FAQs
Python package to query DeFi data from several The Graph subgraphs
We found that deficrawler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.