57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Export the compact liquidity-pools CSV from the generated master-map JSON."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import csv
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
ROOT = Path(__file__).resolve().parents[2]
|
||
|
|
INPUT_JSON = ROOT / "reports/status/liquidity-pools-master-map-latest.json"
|
||
|
|
OUTPUT_CSV = ROOT / "reports/status/liquidity-pools-master-map-compact-latest.csv"
|
||
|
|
|
||
|
|
FIELDNAMES = [
|
||
|
|
"chainId",
|
||
|
|
"network",
|
||
|
|
"pair",
|
||
|
|
"poolAddress",
|
||
|
|
"baseTokenAddress",
|
||
|
|
"quoteTokenAddress",
|
||
|
|
"baseBalance",
|
||
|
|
"quoteBalance",
|
||
|
|
"status",
|
||
|
|
]
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> int:
|
||
|
|
data = json.loads(INPUT_JSON.read_text())
|
||
|
|
OUTPUT_CSV.parent.mkdir(parents=True, exist_ok=True)
|
||
|
|
|
||
|
|
with OUTPUT_CSV.open("w", newline="") as fh:
|
||
|
|
writer = csv.DictWriter(fh, fieldnames=FIELDNAMES)
|
||
|
|
writer.writeheader()
|
||
|
|
for chain in data.get("chains", []):
|
||
|
|
for pool in chain.get("pools", []):
|
||
|
|
writer.writerow(
|
||
|
|
{
|
||
|
|
"chainId": pool.get("chainId", chain.get("chainId")),
|
||
|
|
"network": pool.get("network", chain.get("network")),
|
||
|
|
"pair": f"{pool.get('baseSymbol')}/{pool.get('quoteSymbol')}",
|
||
|
|
"poolAddress": pool.get("poolAddress", ""),
|
||
|
|
"baseTokenAddress": pool.get("baseAddress", ""),
|
||
|
|
"quoteTokenAddress": pool.get("quoteAddress", ""),
|
||
|
|
"baseBalance": ((pool.get("balances") or {}).get("base") or {}).get("formatted", ""),
|
||
|
|
"quoteBalance": ((pool.get("balances") or {}).get("quote") or {}).get("formatted", ""),
|
||
|
|
"status": pool.get("status", ""),
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
print(f"Wrote {OUTPUT_CSV.relative_to(ROOT)}")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
raise SystemExit(main())
|