|
1 | 1 | # sora2API |
2 | 2 | SORA v2 API Wrapper — Python interface for the SORA decentralized economy platform, providing balance queries, token swaps via Polkaswap DEX, liquidity pool inspection, and network status monitoring |
| 3 | +<div align="center"> |
| 4 | + |
| 5 | +# SORA v2 API Wrapper |
| 6 | + |
| 7 | +[](https://www.python.org/) |
| 8 | +[](LICENSE) |
| 9 | +[](https://sora.org/) |
| 10 | +[](https://polkaswap.io/) |
| 11 | + |
| 12 | +**Python interface for the SORA v2 decentralized economy platform — balance queries, token swaps, liquidity pools, and network monitoring.** |
| 13 | + |
| 14 | +[Features](#features) · [Getting Started](#getting-started) · [Configuration](#configuration) · [Architecture](#architecture) |
| 15 | + |
| 16 | +</div> |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Overview |
| 21 | + |
| 22 | +SORA v2 is a decentralized economic system built on Substrate, featuring: |
| 23 | + |
| 24 | +- **Polkaswap DEX** — a non-custodial decentralized exchange with multiple liquidity sources (XYK pools, multi-collateral bonding curve, order book) |
| 25 | +- **XOR** — the native utility and governance token with a token bonding curve supply mechanism |
| 26 | +- **VAL** — validator reward token for SORA network validators |
| 27 | +- **PSWAP** — liquidity provision incentive token |
| 28 | + |
| 29 | +This wrapper provides a Python API client and interactive TUI for querying balances, executing swaps, inspecting liquidity pools, and monitoring network state. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## Features |
| 34 | + |
| 35 | +| Feature | Description | |
| 36 | +|---------|-------------| |
| 37 | +| Balance queries | Fetch asset balances for any SORA account | |
| 38 | +| Token swaps | Get quotes and execute swaps via Polkaswap DEX | |
| 39 | +| Liquidity pools | List pools with reserve and liquidity data | |
| 40 | +| Network info | Chain metadata, block height, peer count | |
| 41 | +| Well-known assets | Built-in resolution for XOR, VAL, PSWAP, DAI, ETH, XSTUSD | |
| 42 | +| Multi-source routing | XYK Pool and bonding curve routing support | |
| 43 | +| Data models | Typed dataclasses for assets, pools, quotes, results | |
| 44 | +| Rich TUI | Interactive terminal menu for all operations | |
| 45 | +| Configurable | JSON config with interactive setup wizard | |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## Getting Started |
| 50 | + |
| 51 | +### Prerequisites |
| 52 | + |
| 53 | +- Python 3.9+ |
| 54 | +- Network access to a SORA node or API endpoint |
| 55 | + |
| 56 | +### Installation |
| 57 | + |
| 58 | +```bash |
| 59 | +git clone https://github.com/example/sora2api-wrapper.git |
| 60 | +cd sora2api-wrapper |
| 61 | + |
| 62 | +pip install -r requirements.txt |
| 63 | + |
| 64 | +python main.py |
| 65 | +``` |
| 66 | + |
| 67 | +### Quick Setup |
| 68 | + |
| 69 | +1. Run `python main.py` and select **Install dependencies** |
| 70 | +2. Select **Configure API** to set endpoint URLs |
| 71 | +3. Use **Query balances** to check account holdings |
| 72 | +4. Use **Swap tokens** to get quotes and execute trades |
| 73 | +5. Use **Liquidity pools** to browse available pools |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## Configuration |
| 78 | + |
| 79 | +Configuration is stored in `config.json`. Edit directly or use the interactive setup. |
| 80 | + |
| 81 | +| Parameter | Default | Description | |
| 82 | +|-----------|---------|-------------| |
| 83 | +| `api_url` | `https://mof.sora.org` | SORA REST API base URL | |
| 84 | +| `substrate_url` | `wss://mof2.sora.org` | Substrate WebSocket endpoint | |
| 85 | +| `network` | `mainnet` | Network (mainnet or testnet) | |
| 86 | +| `default_dex_id` | `0` | Default DEX ID for Polkaswap | |
| 87 | +| `timeout` | `30` | Request timeout in seconds | |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## Architecture |
| 92 | + |
| 93 | +``` |
| 94 | +sora2api/ |
| 95 | +├── main.py # TUI entry point (Rich-based menu) |
| 96 | +├── client.py # SORA API client (balances, swaps, pools, network) |
| 97 | +├── config.py # Configuration load/save/interactive setup |
| 98 | +├── models.py # Data models (Asset, Pool, SwapQuote, SwapResult, etc.) |
| 99 | +├── config.json # Runtime configuration |
| 100 | +├── requirements.txt # Python dependencies |
| 101 | +└── README.md |
| 102 | +``` |
| 103 | + |
| 104 | +### API Client |
| 105 | + |
| 106 | +The `SoraClient` class handles all communication with the SORA network API: |
| 107 | + |
| 108 | +- **Balance queries** via `/accounts/{address}/balances` |
| 109 | +- **Swap quotes** via `/dex/quote` with configurable liquidity sources |
| 110 | +- **Swap execution** via `/dex/swap` with slippage tolerance |
| 111 | +- **Pool listing** via `/dex/pools` |
| 112 | +- **Network info** via `/network/info` |
| 113 | + |
| 114 | +### Data Models |
| 115 | + |
| 116 | +All API responses are mapped to typed Python dataclasses: |
| 117 | + |
| 118 | +- `Asset` — registered token with ID, symbol, precision |
| 119 | +- `Pool` — liquidity pool with reserves and fee data |
| 120 | +- `SwapQuote` — price quote with route and impact information |
| 121 | +- `SwapResult` — executed swap with transaction hash and status |
| 122 | +- `AccountBalance` — per-asset balance breakdown (free, reserved, frozen) |
| 123 | +- `NetworkInfo` — chain state snapshot |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Well-Known Assets |
| 128 | + |
| 129 | +| Symbol | Description | |
| 130 | +|--------|-------------| |
| 131 | +| XOR | Native utility token, bonding curve supply | |
| 132 | +| VAL | Validator reward token | |
| 133 | +| PSWAP | Polkaswap liquidity incentive token | |
| 134 | +| DAI | Bridged MakerDAO stablecoin | |
| 135 | +| ETH | Bridged Ether | |
| 136 | +| XSTUSD | SORA synthetic USD stablecoin | |
| 137 | + |
| 138 | +--- |
| 139 | + |
| 140 | +## Dependencies |
| 141 | + |
| 142 | +| Package | Purpose | |
| 143 | +|---------|---------| |
| 144 | +| `rich` | Terminal UI, tables, panels, prompts | |
| 145 | +| `requests` | HTTP client for REST API calls | |
| 146 | +| `websockets` | WebSocket connection to Substrate nodes | |
| 147 | +| `substrate-interface` | Substrate RPC and storage queries | |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## Disclaimer |
| 152 | + |
| 153 | +This tool is provided for **informational and development purposes**. Always verify swap parameters and slippage settings before executing trades. The authors accept no responsibility for financial losses from incorrect usage or API changes. |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +<div align="center"> |
| 158 | + |
| 159 | +**MIT License** · Contributions welcome |
| 160 | + |
| 161 | +</div> |
0 commit comments