{"id":34758304,"url":"https://github.com/defipy-devs/defipy-book","last_synced_at":"2026-05-26T19:33:29.223Z","repository":{"id":326555747,"uuid":"1099304307","full_name":"defipy-devs/defipy-book","owner":"defipy-devs","description":"Official DeFiPy Book Reference Repository","archived":false,"fork":false,"pushed_at":"2026-04-18T20:16:50.000Z","size":412,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-18T22:18:10.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/defipy-devs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-18T20:43:12.000Z","updated_at":"2026-04-18T20:16:54.000Z","dependencies_parsed_at":"2025-12-02T08:00:57.304Z","dependency_job_id":null,"html_url":"https://github.com/defipy-devs/defipy-book","commit_stats":null,"previous_names":["defipy-devs/defipy-book"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/defipy-devs/defipy-book","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defipy-devs%2Fdefipy-book","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defipy-devs%2Fdefipy-book/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defipy-devs%2Fdefipy-book/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defipy-devs%2Fdefipy-book/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/defipy-devs","download_url":"https://codeload.github.com/defipy-devs/defipy-book/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defipy-devs%2Fdefipy-book/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33536654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-25T05:48:21.371Z","updated_at":"2026-05-26T19:33:29.214Z","avatar_url":"https://github.com/defipy-devs.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📘 DeFiPy: Python SDK for On-chain Analytics\n\n**A quantitative and computational guide to decentralized finance using Python.**\n\n*DeFiPy: Python SDK for On-chain Analytics* accompanies the open-source analytics framework [**DeFiPy**](https://defipy.org) and provides a structured, reproducible foundation for DeFi modeling, simulation, and risk analysis. It unifies the mathematical, programmatic, and architectural components of decentralized finance into an executable, open research framework.\n\n---\n\n## 🧭 Overview\n\nThis repository contains the **Jupyter notebooks** for the *DeFiPy TextBook* which is a comprehensive technical reference for the `defipy` ecosystem.\n\nThe book introduces:\n\n- **DeFi architecture** – infrastructure, EVM/ABI/JSON-RPC connectivity  \n- **AMM mathematics** – constant-product, Balancer, and StableSwap invariants  \n- **Analytics and risk modeling** – impermanent loss, expected value, variance, stationarity  \n- **Event-driven pipelines** – Web3-based feed handling via `web3.py` and `web3scout`  \n- **Agent-based simulation** – supervisory and transition-matrix modeling of DeFi systems  \n\n---\n\n## 🧩 Ecosystem\n\n**DeFiPy** is the root analytics package, composed of three major submodules:\n\n| Module | Description |\n|:-------|:-------------|\n| [`uniswappy`](https://github.com/defipy-devs/uniswappy) | Uniswap-focused invariant and tick-math analytics |\n| [`balancerpy`](https://github.com/defipy-devs/balancerpy) | Balancer-style multi-asset pool invariants and weighting logic |\n| [`stableswappy`](https://github.com/defipy-devs/stableswappy) | Curve-style StableSwap invariant and slippage analysis |\n\nDeFiPy integrates seamlessly with **[`web3scout`](https://github.com/defipy-devs/web3scout)**, which is a lightweight extension of `web3.py` that provides efficient on-chain data fetching and event monitoring for analytics pipelines.\n\n---\n\n## 🧱 Repository Structure\n\n```\ndefipy-book/\n├─ notebooks/                # One Jupyter notebook per chapter (chapter1.ipynb … chapter9.ipynb)\n├─ LICENSE                   # Apache 2.0 License\n└─ README.md                 # This file\n```\n\nThe full Jupyter notebook suite for all chapter examples lives in the [**defipy-book/notebooks**](https://github.com/defipy-devs/defipy-book/tree/main/notebooks) directory.\n\n---\n\n## 💻 Companion Notebooks\n\nAll executable examples are provided as Jupyter notebooks (one per chapter) in the official [**defipy-book/notebooks**](https://github.com/defipy-devs/defipy-book/tree/main/notebooks) repository.\n\nEach notebook reproduces the code listings from the text and can be run locally or in Colab. After installing DeFiPy (see Installation below), clone the notebooks and launch JupyterLab:\n\n```bash\n# Install DeFiPy with full book support (needed for chapter 9)\npip install defipy[book] jupyterlab matplotlib\n\n# Clone notebooks and launch\ngit clone https://github.com/defipy-devs/defipy-book.git\ncd defipy-book/notebooks\njupyter lab\n```\n\n\u003e **Note:** Chapters 1–8 work with the core install (`pip install defipy`). Only chapter 9 (*Building Autonomous DeFi Agents*) requires the `[book]` extra, which pulls in `web3scout` for on-chain integration.\n\n### Setting Your RPC Endpoint\n\nTo run the on-chain examples in this repository, you’ll need a reliable Ethereum JSON-RPC endpoint. The easiest option is to create a free [Infura](https://www.infura.io/) account and generate a project endpoint. Infura provides HTTPS and WebSocket gateways to Ethereum (and other chains), and integrates seamlessly with Web3.py. \n\nTo set one up you can visit [Infura](https://www.infura.io/); once you sign in:\n\n* Create a new Web3 project\n* Select Ethereum as the network\n* Copy your HTTPS endpoint, which will look like:\n\n```bash\nhttps://mainnet.infura.io/v3/\u003cYOUR_API_KEY\u003e\n```\n\n---\n\n## 🚀 Installation\n\nDeFiPy is installed via pip. There are two install options depending on which chapters you plan to run.\n\n\n### Book install \n\nFor the mathematical, analytical, and simulation chapters — which use only DeFiPy's core packages (`uniswappy`, `balancerpy`, `stableswappy`). Chapter 9 of *Hands-On AMMs with Python* — *Building Autonomous DeFi Agents* — uses live chain integration via `web3scout`. To run those examples, install the `[book]` extra:\n\n```\n\u003e pip install 'defipy[book]'\n```\n\nThe `[book]` extra carries the same package set as `[chain]` (`web3scout` + `web3`). The split is intent-based — `[chain]` signals production live-state reads via LiveProvider; `[book]` signals textbook chapter 9 use. Either works for either purpose.\n\n### Python version\n\nDeFiPy requires **Python 3.10 or later**. Tested through Python 3.14.\n\n### System libraries for gmpy2\n\n`defipy` depends on `gmpy2` for high-precision arithmetic in StableSwap math. `gmpy2` requires the GMP, MPFR, and MPC system libraries to be installed *before* running `pip install`:\n\n**macOS (Homebrew):**\n```bash\nbrew install gmp mpfr libmpc\n```\n\n**Linux (Debian / Ubuntu):**\n```bash\nsudo apt install libgmp-dev libmpfr-dev libmpc-dev\n```\n\n### Jupyter\n\nTo run the notebooks you'll also need JupyterLab and a plotting library:\n\n```bash\npip install jupyterlab matplotlib\n```\n\n---\n\n## 📖 Citation\n\nIf you use this book or its code in your research or coursework, please cite:\n\n```\nMoore, I. (2025). DeFiPy: Python SDK for On-chain Analytics.\nDeFiPy.org, Apache-2.0.\n```\n\n---\n\n## 🪶 License\n\nLicensed 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 at:\n\n\u003e http://www.apache.org/licenses/LICENSE-2.0\n\nAll examples, text, and notebooks are distributed on an “AS IS” basis, without warranties or conditions of any kind.\n\n---\n\n## 🔗 Links\n\n- 📚 [DeFiPy Documentation](https://defipy.org)  \n- 💻 [DeFiPy GitHub](https://github.com/defipy-devs/defipy)  \n- 🧮 [Companion Notebooks](https://github.com/defipy-devs/defipy-book)  \n- ⚙️ [Web3Scout Extension](https://github.com/defipy-devs/web3scout)  \n\n---\n\n**© 2025 defipy-devs / Ian Moore and contributors.**  \nBuilding open, deterministic analytics for decentralized finance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefipy-devs%2Fdefipy-book","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefipy-devs%2Fdefipy-book","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefipy-devs%2Fdefipy-book/lists"}