{"id":13815136,"url":"https://github.com/0xfffangel/web3dex-python","last_synced_at":"2025-05-15T07:32:00.899Z","repository":{"id":37590592,"uuid":"456125068","full_name":"0xfffangel/web3dex-python","owner":"0xfffangel","description":"A python library to work with multiple DEX based on web3","archived":false,"fork":false,"pushed_at":"2022-09-05T18:05:53.000Z","size":111,"stargazers_count":34,"open_issues_count":0,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-01T11:24:23.855Z","etag":null,"topics":["defi","dex","shitcoins","web3py"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xfffangel.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}},"created_at":"2022-02-06T10:59:33.000Z","updated_at":"2024-11-30T12:50:32.000Z","dependencies_parsed_at":"2022-08-03T06:30:56.066Z","dependency_job_id":null,"html_url":"https://github.com/0xfffangel/web3dex-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfffangel%2Fweb3dex-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfffangel%2Fweb3dex-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfffangel%2Fweb3dex-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfffangel%2Fweb3dex-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xfffangel","download_url":"https://codeload.github.com/0xfffangel/web3dex-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254295952,"owners_count":22047175,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["defi","dex","shitcoins","web3py"],"created_at":"2024-08-04T04:03:00.581Z","updated_at":"2025-05-15T07:31:58.311Z","avatar_url":"https://github.com/0xfffangel.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"WEB3Dex\n===\n\nA flexible python library to interact with evm-like DEX.\nWEB3Dex library provide a unified interface for SC based on uniswap-fork.\nBased on [web3](https://github.com/ethereum/web3.py).\n\n### Supported Dex in chains\n- Avalance\n- Bsc\n- Cronos\n- Ethereum\n- Fantom\n- Moonbeam\n- Moonriver\n- Polygon\n\n### Get it ready\n```sh\npip install web3dex\n```\n\n### How to start\nPython script:\n```python\nfrom web3dex.ethereum import Uniswap\n\nuniswap = Uniswap()\nUSDC = \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\"\n\nprint(\"reserves: \", uniswap.reserves(USDC))\nprint(\"liquidity_in: \", uniswap.liquidity_in(USDC))\nprint(\"liquidity_out: \", uniswap.liquidity_out(USDC))\nprint(\"reserve_ratio: {:.18f}\".format(uniswap.reserve_ratio(USDC)))\nprint(\"price: {:.18f}\".format(uniswap.price(USDC)))\n```\n\nResult:\n```shell\nreserves:  [64985095.457761, 32622.06165275629, 1660409488]\nliquidity_in:  64985095.457761\nliquidity_out:  32622.565503187332\nreserve_ratio:  0.0005019929788971377\nprice:  0.000500486992281985\n```\n\n### How to swap them\n\n```python\nimport web3dex\n\n# setup env\nuniswap = web3dex.ethereum.Uniswap()\nUSDC = \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\"\nwallet_address = \"\"\nprivate_key = \"\"\namount = 0.001\n\n# approve token for wallet_address if now allowance\nif not uniswap.check_approval(wallet_address, USDC):\n    tx = uniswap.approve(token=USDC, wallet_address=wallet_address)\n    signed_tx = uniswap.signTransaction(transaction = tx, private_key = private_key)\n    tx_hash = uniswap.sendTransaction(signed_transaction = signed_tx)\n    if not uniswap.waitTransaction(tx_hash):\n        raise Exception(\"TransactionExpection: \" + tx_hash.hex())\n\n# swap from base to token\ntx = uniswap.swapFromBaseToTokens(amount, USDC, wallet_address)\nsigned_tx = uniswap.signTransaction(transaction = tx, private_key = private_key)\ntx_hash = uniswap.sendTransaction(signed_transaction = signed_tx)\nif not uniswap.waitTransaction(tx_hash):\n    raise Exception(\"TransactionExpection: \" + tx_hash.hex())\nprint(tx_hash)\n\n# get updated balances\nprint(\"base balance {:.18f}\".format(uniswap.balance(wallet_address)))\nprint(\"USDC balance {:.18f}\".format(uniswap.balance(wallet_address, USDC)))\n\n# swap from token to base\ntx = uniswap.swapFromTokensToBase(amount, USDC, wallet_address)\nsigned_tx = uniswap.signTransaction(transaction = tx, private_key = private_key)\ntx_hash = uniswap.sendTransaction(signed_transaction = signed_tx)\nif not uniswap.waitTransaction(tx_hash):\n    raise Exception(\"TransactionExpection: \" + tx_hash.hex())\nprint(tx_hash)\n```\n\n### Open PR for new Dex\n1. Define a new Dex config json in the chain folder (ex for `uniswap`: `web3dex/configs/ethereum/uniswap.json`):\n```json\n{\n    \"PROVIDER\": \"https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161\",\n    \"FACTORY_ADDR\": \"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f\",\n    \"ROUTER_ADDR\": \"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D\",\n    \"FACTORY_ABI_FILE\": \"./abi/uniswapv2_factory_abi.json\",\n    \"ROUTER_ABI_FILE\": \"./abi/uniswapv2_router_abi.json\",\n    \"LIQUIDITY_ABI_FILE\": \"./abi/uniswapv2_liquidity_abi.json\",\n    \"BASE_SYMBOL\": \"ETH\",\n    \"BASE_CONTRACT\": \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\"\n}\n```\n2. Add new Dex object in the chain script (ex: `web3dex/configs/ethereum.py`):\n```python\nclass Uniswap(Dex):\n    def __init__(self):\n        super().__init__(configs + \"/uniswap.json\"))\n```\n3. Add the class name into the `all` groups to be listed:\n```python\n\nall = [\n    ...,\n    Uniswap()\n]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xfffangel%2Fweb3dex-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xfffangel%2Fweb3dex-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xfffangel%2Fweb3dex-python/lists"}