Skip to content

Commit

Permalink
325 bot jit liquidity (#337)
Browse files Browse the repository at this point in the history
* Added skeleton for liquidity cli

* Added initial start of jit implementation

* Added buy side jit provisioning rules to bot

* Added initial always on provision

* Corrected path in message for always-on

* Tidy up

* Tidy up

* Add interaction with batcher contract on ghostnet (#336)

* gitignore for javascript compiled files

* Add a dependency to Taquito

* Add interaction with Batcher contract: deposit and redeem.
Also, wallets.

* Working versions for both liquidity bots

* Packaged build to single file and add release action

* Added working sub dir to build and manual trigger for testing

* Added example config files into build file and expanded ghostnet example

* Corrected release pathing

* Corrected release pathing

* Compress and hash release artefacts

* corrected compression

* Added zip compression to release artefacts

* Added zip compression to release artefacts

* Removed pre-release clause

* Removed bundled compilation

* Package node modules with liq bots

* Updated packaging to prune modules

* Always on only submits once per batch

* Tidied bot status message

* Tidied bot status message

* Correctly parse status

* Update batcher-bot/liquidity/src/utils.ts

Co-authored-by: Ulrik Strid <[email protected]>

* PRC:  Throw if no private key in environment

* Added usage README content for liq bot

* PRC:  Use if in structure rather than getting all keys

* PRC:  Change lets to consts where applicable in provisioning

* PRC:  Change lets to consts where applicable in provisioning

* PRC:  Declare events prior to subscription

---------

Co-authored-by: aguillon <[email protected]>
Co-authored-by: Ulrik Strid <[email protected]>
  • Loading branch information
3 people authored May 19, 2023
1 parent 42f35ea commit 23470b1
Show file tree
Hide file tree
Showing 20 changed files with 5,198 additions and 94 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release-bots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release Liquidity Bots

on:
workflow_dispatch: # adding the workflow_dispatch so it can be triggered manually
push:
tags:
- 'bots-v*'

defaults:
run:
working-directory: batcher-bot/liquidity
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '18.x'
- name: Install modules
run: npm install
- name: Build
run: npm run build
- name: Package
run: npm run package
- name: Tar compress
run: tar -cvf batcher-liquidity-bot.tar.xz dist/*
- name: Hash Tar
run: echo $(md5sum batcher-liquidity-bot.tar.xz) > batcher-liquidity-bot.tar.hash.md
- name: Zip compress
run: zip -r batcher-liquidity-bot.zip dist/*
- name: Hash Tar
run: echo $(md5sum batcher-liquidity-bot.zip) > batcher-liquidity-bot.zip.hash.md
- name: Release
uses: softprops/action-gh-release@v1
with:
fail_on_unmatched_files: true
files: |
./batcher-bot/liquidity/batcher-liquidity-bot.tar.xz
./batcher-bot/liquidity/batcher-liquidity-bot.tar.hash.md
./batcher-bot/liquidity/batcher-liquidity-bot.zip
./batcher-bot/liquidity/batcher-liquidity-bot.zip.hash.md
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ USDT_token_storage.tz
# Tezos client artefacts
.tezos-client/

node_modules
./*/node_modules/
dist
batcher-bot/notifications/node_modules/
batcher-bot/liquidity/node_modules/
2 changes: 2 additions & 0 deletions batcher-bot/liquidity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/*.js
lib/*.d.ts
126 changes: 126 additions & 0 deletions batcher-bot/liquidity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Liquidity Bot

## Pre-requisites

To run the bot you will need to have an environment that has Node.js installed.

> The releases were developed and tested with v18.14.0 of Node.
## Installation

The release package can be downloaded from the releases pages of the repo in either zip or tar.xz formats. A hash.md for each format is supplied so that the contents of the file can be verified.

## Operation

Once the release has been downloaded and unpacked it can be run from the command line.

### Liquidity Modes

The liquidity bot allows deposits to be made automatically based on configuration. There are two specific modes of liquidity:

- JIT (just-in-time): This mode listens for trades in each batch and places an opposing deposit.
- ALWAYS-ON : This mode supplies a given deposit at batch open.

To run the bot simply specify the mode as the first argument. The second argument should be the path to the configuration file:

Jit mode:
```bash
node index.js jit <path to config>
```

Alwys-on mode:
```bash
node index.js always-on <path to config>
```

### Liquidity configuration

Both modes use a configuration file that supplies rules for the deposits for one or more pairs. Examples of config files for mainnet and ghostnet are bundled with the release; they include the variables for the Batcher contract address, the address of a Tezos node and the relevant tzkt api address.

Example of ghostnet config file.

```json
{
"batcher_address": "KT1VbeN9etQe5c2b6EAFfCZVaSTpiieHj5u1",
"tezos_node_uri": "https://ghostnet.tezos.marigold.dev",
"tzkt_uri_api": "https://api.ghostnet.tzkt.io",
"token_pairs": [
{
"name": "tzBTC/USDT",
"side": "both",
"buy_limit_per_batch": 0.02,
"buy_tolerance": "worse",
"sell_limit_per_batch": 200,
"sell_tolerance": "oracle"
},
{
"name": "tzBTC/EURL",
"side": "either",
"buy_limit_per_batch": 0.02,
"buy_tolerance": "oracle",
"sell_limit_per_batch": 220,
"sell_tolerance": "better"
}
]


}

```

More importantly, they contain the configuration of the liquidity provision for the token pairs.

```json
"token_pairs": [
{
"name": "tzBTC/USDT",
"side": "both",
"buy_limit_per_batch": 0.02,
"buy_tolerance": "worse",
"sell_limit_per_batch": 200,
"sell_tolerance": "oracle"
},
{
"name": "tzBTC/EURL",
"side": "either",
"buy_limit_per_batch": 0.02,
"buy_tolerance": "oracle",
"sell_limit_per_batch": 220,
"sell_tolerance": "better"
}
]

```

When running the bot, a user is free to only include the pairs they are interested in. For each pair, the configuration should include the name of the pair, the side one wishes to supply liquidity for, and the amount limit per batch and tolerance for each side.

### Name

The name of the pair should be the same as that specified in the `valid_swap` item in the Batcher contract storage. At the time of writing this is either *tzBTC/USDT* or *tzBTC/EURL*.

### Side

The 'side' configuration is the side that a user is interested in trading. These can be:

- both - one can supply liquidity to both sides of a trade if one should choose.
- either - one can supply either side of a trade; *this is only a valid option for the 'jit' mode*.
- buy - only supply liquidity for the buy side of a given pair
- sell - only supply liquidity for the sell side of a given pair

### Limit Per Batch

The `buy_limit_per_batch` and `sell_limit_per_batch` configurations define the deposit size that will occur in any given batch.

### Tolerance

With the `buy_tolerance` and `sell_tolerance`, one can set their choice of price level for a given batch that one is willing to trade at. These follow the usual Batcher conventions:

- worse - A worse price but a better chance of the order being filled
- oracle - Trade at the Oracle price accepted after the batch has closed
- better - A better price but less chance of being filled.

> The tolerances are ten basis points off a given future Oracle price.
## Redemption

In either mode the bot will redeem any holdings once a batch is cleared.
Loading

0 comments on commit 23470b1

Please sign in to comment.