GithubHelp home page GithubHelp logo

hydroprotocol / amm-bots Goto Github PK

View Code? Open in Web Editor NEW
22.0 7.0 21.0 30 KB

Automated market making bots to provide liquidity for hydro relayers

License: Apache License 2.0

Dockerfile 1.30% Go 98.70%
hydroprotocol marketmaking liquidity bot

amm-bots's Introduction

This repository is a Liquidity Module for the Hydro SDK.

Liquidity Modules allow relayers to instantly fill their orderbooks and bootstrap liquidity with minimal effort. This particular module uses a Constant Product Market Making Model, discussed in greater detail below.

Using this repository

This repository is a subset of https://github.com/HydroProtocol/hydro-scaffold-dex. It is designed to start a market making bot to provide liquidity on an existing Hydro Relayer.


AMM Bots

Automated Market Making (AMM) bots provide liquidity to a marketplace through use of algorithmic market making.

Running the AMM Bot

This repository is setup to run naturally on the Hydro Dex Scaffold. For use on other marketplaces, you could modify the code snippets below.

Running from source

BOT_TYPE=CONST_PRODUCT \
BOT_PRIVATE_KEY=0x............... \
BOT_BASE_TOKEN=HOT \
BOT_QUOTE_TOKEN=DAI \
BOT_BASE_URL=http://127.0.0.1:3001 \
BOT_MIN_PRICE=0.8 \
BOT_MAX_PRICE=1.2 \
BOT_PRICE_GAP=0.02 \
BOT_EXPAND_INVENTORY=2 \
BOT_WEB3_URL=http://127.0.0.1:8545 \
go run main.go

Running from a docker image

docker run --rm -it \
  -e BOT_TYPE=CONST_PRODUCT \
  -e BOT_PRIVATE_KEY=0x............... \
  -e BOT_BASE_TOKEN=HOT \
  -e BOT_QUOTE_TOKEN=DAI \
  -e BOT_BASE_URL=http://127.0.0.1:3001 \
  -e BOT_MIN_PRICE=0.8 \
  -e BOT_MAX_PRICE=1.2 \
  -e BOT_PRICE_GAP=0.02 \
  -e BOT_EXPAND_INVENTORY=2 \
  -e BOT_WEB3_URL=http://127.0.0.1:8545 \
  hydroprotocolio/amm-bots

Environment Variables

Basic Variables

  • BOT_TYPE Type of bot
  • BOT_BASE_URL Hydro relayer api base url
  • BOT_WEB3_URL Ethereum json rpc url
  • BOT_BASE_TOKEN Symbol of base token (e.g HOT)
  • BOT_QUOTE_TOKEN Symbol of quote token (e.g WETH)

Secret Variables

  • BOT_PRIVATE_KEY Ethereum address for place order

Algorithm Variables

Constant Product AMM

This bot runs a "constant product market maker model" (popularized in the DeFi community by Uniswap). In short, this model generates a full orderbook based on an initial price for the market. Every transaction that occurs on this market will adjust the prices of the market accordingly. It's a basic supply and demand automated market making system.

  • Buying large amounts of the base token will increase the price
  • Selling large amounts of the base token will decrease the price

A typical Constant Market Making model has a continuous price curve. This bot discretizes the continuous price curve and creates a number of limit orders to simulate the curve. The order price is limited between BOT_MAX_PRICE and BOT_MIN_PRICE. The price difference between adjacent orders is BOT_PRICE_GAP.

Image (Image Source)

Constant product algorithms have a disadvantage of low inventory utilization. For example, by default it only uses 5% of your inventory when the price increases 10%. BOT_EXPAND_INVENTORY can help you add depth near the current price.

  • BOT_MAX_PRICE Max order price
  • BOT_MIN_PRICE Min order price
  • BOT_PRICE_GAP Price difference rate between adjacent orders. For example, ask price increases by 2% and bid price decreases by 2% if BOT_PRICE_GAP=0.02.
  • BOT_EXPAND_INVENTORY Multiply your order sizes linearly. For example, all order sizes will be tripled if BOT_EXPAND_INVENTORY=3.

Liquidity Sourcing In Constant Product AMM

Constant Product AMM requires a single source of funds for both the base and quote token. As such, the general flow of setting up the AMM bot from scratch is:

  • Prepare an address that holds both the BASE and QUOTE token of the trading pair you want to provide liquidity for
  • Set the initial parameters for the bot
    • This determines the initial price, spread, sensitivity, etc.
  • Run the bot

Upon running the bot, it will generate an orderbook for your marketplace. The orderbook will appear to be static, but every trade will shift the market accordingly.

Further Information On Constant Product AMM

For more information on these models, Scalar Capital provided a detailed analysis of constant market making.

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details

amm-bots's People

Contributors

davidqhr avatar scottddex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

amm-bots's Issues

connect: connection refused

Hello guys,
I've tested your bot in locally, but when I try to run with

docker run --rm -it \
  -e BOT_TYPE=CONST_PRODUCT \
  -e BOT_PRIVATE_KEY=0x.. \
  -e BOT_BASE_TOKEN=HOT \
  -e BOT_QUOTE_TOKEN=DAI \
  -e BOT_BASE_URL=http://127.0.0.1:3001 \
  -e BOT_MIN_PRICE=0.8 \
  -e BOT_MAX_PRICE=1.2 \
  -e BOT_PRICE_GAP=0.02 \
  -e BOT_EXPAND_INVENTORY=2 \
  -e BOT_WEB3_URL=http://127.0.0.1:8545 \
  hydroprotocolio/amm-bots

I will get this error

panic: Get http://localhost:3001/markets: dial tcp 127.0.0.1:3001: connect: connection refused

If i try to browse on http://localhost:3001/markets this is the response

{"status":0,"desc":"success","data":{"markets":[{"id":"HOT-DAI","baseToken":"HOT","baseTokenProjectUrl":"","baseTokenName":"HOT","baseTokenDecimals":18,"baseTokenAddress":"0x4c4fa7e8ea4cfcfc93deae2c0cff142a1dd3a218","quoteToken":"DAI","quoteTokenDecimals":18,"quoteTokenAddress":"0xbc3524faa62d0763818636d5e400f112279d6cc0","minOrderSize":"0.001","pricePrecision":5,"priceDecimals":5,"amountDecimals":5,"asMakerFeeRate":"0.001","asTakerFeeRate":"0.003","gasFeeAmount":"0.45","supportedOrderTypes":["limit","market"],"marketOrderMaxSlippage":"0.1","lastPriceIncrease":"0","lastPrice":"0","price24h":"0","amount24h":"0","quoteTokenVolume24h":"0"},{"id":"WETH-DAI","baseToken":"WETH","baseTokenProjectUrl":"","baseTokenName":"WETH","baseTokenDecimals":18,"baseTokenAddress":"0x4a817489643A89a1428b2DD441c3fbe4DBf44789","quoteToken":"DAI","quoteTokenDecimals":18,"quoteTokenAddress":"0xbc3524faa62d0763818636d5e400f112279d6cc0","minOrderSize":"0.001","pricePrecision":5,"priceDecimals":5,"amountDecimals":5,"asMakerFeeRate":"0.001","asTakerFeeRate":"0.003","gasFeeAmount":"0.00000045","supportedOrderTypes":["limit","market"],"marketOrderMaxSlippage":"0.1","lastPriceIncrease":"0","lastPrice":"0","price24h":"0","amount24h":"0","quoteTokenVolume24h":"0"},{"id":"HOT-WETH","baseToken":"HOT","baseTokenProjectUrl":"","baseTokenName":"HOT","baseTokenDecimals":18,"baseTokenAddress":"0x4c4fa7e8ea4cfcfc93deae2c0cff142a1dd3a218","quoteToken":"WETH","quoteTokenDecimals":18,"quoteTokenAddress":"0x4a817489643A89a1428b2DD441c3fbe4DBf44789","minOrderSize":"0.001","pricePrecision":5,"priceDecimals":5,"amountDecimals":5,"asMakerFeeRate":"0.001","asTakerFeeRate":"0.003","gasFeeAmount":"0.000000003","supportedOrderTypes":["limit","market"],"marketOrderMaxSlippage":"0.1","lastPriceIncrease":"0","lastPrice":"0","price24h":"0","amount24h":"0","quoteTokenVolume24h":"0"}]}}

Why the bot cannot connect?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.