Created
January 7, 2023 21:46
-
-
Save algolog/a664e923c64b7de27f3033f5d5592d89 to your computer and use it in GitHub Desktop.
List Humble.sh DEX pools from on-chain logs
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
from itertools import chain | |
from base64 import b64decode | |
from algosdk.v2client.indexer import IndexerClient | |
from algosdk.encoding import checksum | |
# List of Humble.sh DEX pools from on-chain logs. | |
# Translated to Python from https://gist.github.com/DanBurton/d11a6c8a99b33f28ea7fc83a82ccaef8 | |
# Pool ABI docs: https://reach-sh.github.io/humble-sdk/LP-ABI.html | |
indexer = IndexerClient("", "https://mainnet-idx.algonode.cloud") | |
# The Reach declaration for pool registration Event type is: | |
# Register: [ Contract, MToken, Token ] | |
# Event signature prefix, see ARC 28 | |
# https://github.com/reach-sh/ARCs/blob/arc-0028-events/ARCs/arc-0028.md | |
sig = 'Register(uint64,(byte,byte[8]),uint64)'.encode() | |
prefix_hex = checksum(sig).hex()[0:8] | |
manager_app_id = 771884869 | |
# We are ignoring next-token for simplicity in this example | |
logs_nested = indexer.application_logs(manager_app_id) | |
# make flat list of all logs | |
logs = chain.from_iterable(x['logs'] for x in logs_nested['log-data']) | |
# Filter down to only the Register logs by looking for the matching prefix | |
register_logs = [l for l in logs if b64decode(l)[0:4].hex() == prefix_hex] | |
for rlog in register_logs: | |
data = b64decode(rlog) | |
# interpret the next 8 bytes after the 4-byte prefix as the registered Contract (app_id: uint64) | |
pool_app_id = int(data[4:12].hex(), base=16) | |
pool_type = int(data[12:13].hex(), base=16) | |
assetA = int(data[13:21].hex(), base=16) | |
assetB = int(data[21:29].hex(), base=16) | |
if pool_type == 0: | |
if assetA != 0: | |
raise ValueError("Non-zero assetA for ALGO-OTHER pool type.") | |
print(f"{pool_app_id:12} {assetA:12} {assetB:12}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment