-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
133 changed files
with
31,489 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Aave v2 API | ||
----------- | ||
|
||
This is Python documentation for high-level `Aave lending protocol <https://tradingstrategy.ai/glossary/aave>`_ APIs. | ||
|
||
Functionality includes: | ||
|
||
- Reading current and historical Aave data and metrics | ||
|
||
.. autosummary:: | ||
:toctree: _autosummary_aave_v2 | ||
:recursive: | ||
|
||
eth_defi.aave_v2.constants | ||
eth_defi.aave_v2.events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Aave v2 constants.""" | ||
|
||
from typing import NamedTuple | ||
|
||
from eth_defi.aave_v3.constants import ( # noqa: passthrough imports, don't remove | ||
MAX_AMOUNT, | ||
AaveVersion, | ||
) | ||
|
||
|
||
class AaveV2Network(NamedTuple): | ||
# Network name | ||
name: str | ||
|
||
# Aave v2 lending pool address | ||
pool_address: str | ||
|
||
# Block number when the pool was created | ||
pool_created_at_block: int | ||
|
||
|
||
# https://docs.aave.com/developers/v/2.0/deployed-contracts/deployed-contracts | ||
AAVE_V2_NETWORK_CHAINS: dict[int, str] = { | ||
1: "ethereum", | ||
137: "polygon", | ||
43114: "avalanche", | ||
} | ||
|
||
AAVE_V2_NETWORKS: dict[str, AaveV2Network] = { | ||
# Ethereum Mainnet | ||
"ethereum": AaveV2Network( | ||
name="Ethereum", | ||
pool_address="0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9", | ||
# https://etherscan.io/tx/0x7d77cc7523a491fa670bfefa0a386ab036b6511d6d9fa6c2cf5c07b349dc9d3a | ||
pool_created_at_block=11362579, | ||
), | ||
# Polygon Mainnet | ||
"polygon": AaveV2Network( | ||
name="Polygon", | ||
pool_address="0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf", | ||
# https://polygonscan.com/tx/0xb5a63fed49e97a58135b012fa14d83e680a0f3cd3aefeb551228d6e3640dbec9 | ||
pool_created_at_block=12687245, | ||
), | ||
# Avalanche C-Chain | ||
"avalanche": AaveV2Network( | ||
name="Avalanche", | ||
pool_address="0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C", | ||
# https://snowtrace.io/tx/0x5db8b8c3026d4a433ca67cbc120540ab6f8897b3aff37e78ba014ac505d167bc?chainId=43114 | ||
pool_created_at_block=4607005, | ||
), | ||
} | ||
|
||
|
||
def get_aave_v2_network_by_chain_id(chain_id: int) -> AaveV2Network: | ||
if chain_id not in AAVE_V2_NETWORK_CHAINS: | ||
raise ValueError(f"Unsupported chain id: {chain_id}") | ||
network_slug = AAVE_V2_NETWORK_CHAINS[chain_id] | ||
return AAVE_V2_NETWORKS[network_slug] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Aave v2 event reader. | ||
Efficiently read Aave v2 from a blockchain. | ||
Currently we are tracking these events: | ||
- ReserveDataUpdated | ||
""" | ||
|
||
import logging | ||
from typing import Callable | ||
|
||
from eth_defi.aave_v3.constants import AaveVersion | ||
from eth_defi.aave_v3.events import _fetch_aave_events_to_csv | ||
from eth_defi.event_reader.reorganisation_monitor import ReorganisationMonitor | ||
from eth_defi.event_reader.state import ScanState | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def aave_v2_fetch_events_to_csv( | ||
json_rpc_url: str, | ||
state: ScanState, | ||
aave_network_name: str, | ||
start_block: int, | ||
end_block: int, | ||
output_folder: str = "/tmp", | ||
max_workers: int = 16, | ||
log_info: Callable = print, | ||
reorg_monitor: ReorganisationMonitor | None = None, | ||
): | ||
"""Fetch all tracked Aave v2 events to CSV files for notebook analysis. | ||
Creates a CSV file with the event data: | ||
- `/tmp/aave-v2-{aave_network_name.lower()}-reservedataupdated.csv` | ||
A progress bar and estimation on the completion is rendered for console / Jupyter notebook using `tqdm`. | ||
The scan be resumed using `state` storage to retrieve the last scanned block number from the previous round. | ||
However, the mechanism here is no perfect and only good for notebook use - for advanced | ||
persistent usage like database backed scans, please write your own scan loop using proper transaction management. | ||
.. note :: | ||
Any Ethereum address is lowercased in the resulting dataset and is not checksummed. | ||
:param json_rpc_url: JSON-RPC URL | ||
:param start_block: First block to process (inclusive), default is block xxx (when Aave v2 xxx was created on mainnet) | ||
:param end_block: Last block to process (inclusive), default is block xxx (1000 block after default start block) | ||
:param aave_network_name: Network name, e.g. 'Polygon' | ||
:param state: Store the current scan state, so we can resume | ||
:param output_folder: Folder to contain output CSV files, default is /tmp folder | ||
:param max_workers: | ||
How many threads to allocate for JSON-RPC IO. | ||
You can increase your EVM node output a bit by making a lot of parallel requests, | ||
until you exhaust your nodes IO capacity. Experiement with different values | ||
and see how your node performs. | ||
:param log_info: Which function to use to output info messages about the progress | ||
""" | ||
|
||
return _fetch_aave_events_to_csv( | ||
json_rpc_url=json_rpc_url, | ||
state=state, | ||
aave_network_name=aave_network_name, | ||
start_block=start_block, | ||
end_block=end_block, | ||
output_folder=output_folder, | ||
max_workers=max_workers, | ||
log_info=log_info, | ||
reorg_monitor=reorg_monitor, | ||
aave_version=AaveVersion.V2, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.