Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constrained UI swapping to valid swaps #420

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
8495a5d
344 reduce duplication in contract storage (#351)
glottologist Jun 9, 2023
d895076
Fixed merge issues
glottologist Jun 9, 2023
a71b585
346 only open batches on first trade (#371)
glottologist Jun 20, 2023
80eea91
Moved burn from deposit. Allowed redemption to calculate how much of…
glottologist Jun 20, 2023
d6ccd0a
327-move-fees style suggestion (#373)
aguillon Jun 20, 2023
0a660bb
Release new contract to Ghostnet due to faucet changes (#374)
glottologist Jun 26, 2023
9cba481
345 remove batches from bigmap imp2 (#377)
glottologist Jul 11, 2023
60cf52f
380 add documentation (#381)
glottologist Jul 13, 2023
fa6bd9a
380 add documentation (#382)
glottologist Jul 13, 2023
d1f67d4
Cancellations (#375)
glottologist Jul 17, 2023
0d53644
add google analytics tracking (#385)
cyrilevos Jul 25, 2023
4f62ac1
edit pipelines [skip ci]
cyrilevos Jul 25, 2023
f6cc409
Revive tests (#384)
glottologist Aug 8, 2023
fa5ab1d
w
glottologist Aug 9, 2023
612c9b8
[1
glottologist Aug 9, 2023
e24bb8b
Added market maker doc
glottologist Aug 10, 2023
e737e4b
Added market maker doc
glottologist Aug 10, 2023
31d2879
Added Add Liquidity enpoint
glottologist Aug 14, 2023
ea94b98
Added test for adding liquidity
glottologist Aug 14, 2023
ee3d7cf
Add liquidity to market maker and test
glottologist Aug 22, 2023
8e2097b
Added add/remove liquidity and claim rewards tests. Added view for g…
glottologist Aug 30, 2023
9f2ad10
Current mainnet contract (#393)
glottologist Aug 31, 2023
ed3aa21
Current mainnet contract (#395)
quentin-burg Sep 1, 2023
75f3372
edit pipeline to create a docker image for beta version. [skip ci]
cyrilevos Sep 4, 2023
0bf9f33
Upgrade Batcher UI (#388)
quentin-burg Sep 4, 2023
fa693fc
:wrench: update github workflow with staging branch instead of featur…
Sep 5, 2023
78c6d1a
:bug: fix volumes update when received an event from bigmap
Sep 5, 2023
5fe3184
Improve requests (#398)
quentin-burg Sep 6, 2023
22a34ee
:recycle: remove tzkt SDK
Sep 6, 2023
c993ef5
:bug: get fees amount from storage before deposit tokens
Sep 6, 2023
e9a60b5
:recycle: improve check status from http request
Sep 6, 2023
bf17a14
:mag: write open graph metadata
Sep 7, 2023
1cc383e
:sparkles: add token icon in swap selector
Sep 7, 2023
8f0d7ec
:bento: add tzbtc icon in local
Sep 7, 2023
43ebce3
Started splitting market maker off into own contract
glottologist Sep 7, 2023
7528a6a
Seperated out tests
glottologist Sep 7, 2023
5a60310
Merged makefile
glottologist Sep 7, 2023
e4901b7
:construction: test og metadata
Sep 7, 2023
b00afdb
:sparkles add tooltip on price strategy
Sep 7, 2023
7d5f7c3
Split out mm contract from Batcher and pulled out common code into sh…
glottologist Sep 7, 2023
3480734
Amended tests to work with new split contracts
glottologist Sep 8, 2023
a9515a6
:sparkles: select tokens both side
Sep 8, 2023
9577d3b
:sparkles: add toasts for error and info
Sep 8, 2023
d71e47d
:green_heart: try to fix CI failure
Sep 8, 2023
d855fd1
:wrench: choose the right network depending on network targeted
Sep 11, 2023
3b94cce
:construction: try to fix CI
Sep 11, 2023
5b48165
:bug: fix issues with holdings and improve other things
Sep 11, 2023
bba18f5
:recycle: upgrade taquito
Sep 11, 2023
9746649
favicon is missing
Sep 12, 2023
4a8ceda
Populated ghostnet storage for marketmaker
glottologist Sep 12, 2023
71d5b8f
Added get market holdings mechanism
glottologist Sep 12, 2023
4686b2a
Added user holdings display and buttons for MM
glottologist Sep 13, 2023
bf30e3c
Added contract calls
glottologist Sep 14, 2023
85a1330
Added Batcher modifications to handle fee payouts and makring a batch…
glottologist Sep 18, 2023
ec93d7b
Added placeholders for market vault operations against batcher
glottologist Sep 18, 2023
620fe4c
Added rebalancing up to amount exchange
glottologist Sep 21, 2023
f73d70c
Added redemption of holdings
glottologist Sep 21, 2023
248f03d
Added operator and deposit ops to utils
glottologist Sep 22, 2023
655474f
Added approve, deposit and revoke operations to the market maker
glottologist Sep 25, 2023
e7a5f3e
Added liquidity injection for market maker
glottologist Sep 26, 2023
5d7c487
Added additional tokens
glottologist Oct 5, 2023
a9666bd
Set up new pairs in ghostnet storage
glottologist Oct 5, 2023
fe06661
Added new tokens and pairs into market maker
glottologist Oct 5, 2023
e16af2b
Added new ghostnet batcher contract to mm storage
glottologist Oct 5, 2023
d48eb01
Added new ghostnet mm address to batcher ghostnet storage
glottologist Oct 5, 2023
5696905
Added new ghhostnet addresses to the config
glottologist Oct 5, 2023
d6c815f
Fix issue cmm (#407)
quentin-burg Oct 5, 2023
c77cc8a
Added redeem by batch
glottologist Oct 5, 2023
83f7a11
Fix CMM UI (#408)
quentin-burg Oct 5, 2023
9c8c05f
Merge branch 'release-ghostnet-beta' into 389-community-market-maker-1
glottologist Oct 5, 2023
abb052c
389 community market maker 1 (#409)
glottologist Oct 6, 2023
ef68ee8
Fixed merge issues, rebuilt to deploy
glottologist Oct 6, 2023
2c6cd69
Added measure for mm contract
glottologist Oct 6, 2023
2284c2b
Skeleton token manager
glottologist Oct 10, 2023
ecb47a7
Added vault contract and moved michelson output to own folder
glottologist Oct 13, 2023
b1959ca
Test types
glottologist Oct 17, 2023
895f627
Adjusted Batcher to support calling the token manager
glottologist Oct 17, 2023
c04dd01
Removed unused code in Batcher
glottologist Oct 17, 2023
2f6ea0c
Added fee map insteand of single market maker address
glottologist Oct 17, 2023
44255d2
:recycle: fix swap pair management to ensure swap is valid
Oct 6, 2023
97dc418
Added liquidity injection to Vault
glottologist Oct 17, 2023
33d87c2
Added reward distribution in vaults
glottologist Oct 23, 2023
5467257
Amended clean mechanism in makefule
glottologist Oct 23, 2023
213dc1b
Added liquidity injection request into market maker
glottologist Oct 24, 2023
a763aed
Fixed getting native tokens view call from vaults
glottologist Oct 24, 2023
bdedb9c
Fixed bug in upsert methods
glottologist Oct 24, 2023
4a4c782
Added a build step to build all contracts
glottologist Oct 24, 2023
08834cc
Fixed issue on makefile and tzbtc vault storage
glottologist Oct 24, 2023
55ace34
Added new vault endpoint call into Batcher for adding rewards to the …
glottologist Oct 24, 2023
06a7181
Added vault balance requests after add or remove liquidity and liquid…
glottologist Oct 25, 2023
f571a33
Removed balance assertion from deposit for testing
glottologist Oct 25, 2023
01be131
Removed foreign token assertions for testing
glottologist Oct 26, 2023
a60de19
Fixed silly token standard parsing error
glottologist Oct 26, 2023
9bd5d79
Fixed silly token standard parsing error
glottologist Oct 26, 2023
a2aa960
Fixed silly token standard parsing error
glottologist Oct 26, 2023
49de0db
Compile all for ghostnet
glottologist Oct 26, 2023
e917111
Moved assert balances into its own entry
glottologist Oct 28, 2023
6b4c980
Added clause to test batch for liquidity
glottologist Oct 28, 2023
a4103f6
Removed todo clause
glottologist Oct 28, 2023
a9c1535
Added debug view to vault to test token balance endpoints
glottologist Oct 30, 2023
fa03d3d
Adjusted callback types
glottologist Oct 30, 2023
ff06943
Adjusted vault process response
glottologist Oct 30, 2023
f1a85c8
Adjusted vault process response
glottologist Oct 30, 2023
690531f
Adjusted getBalance endpoint call opt
glottologist Oct 30, 2023
5600f79
Adjusted type of getBlanace response for callback
glottologist Oct 30, 2023
6f43ef4
:wrench: rewrite config due to new contracts architecture
Oct 17, 2023
af5b877
:recycle: redirect tokens management to token manager contract
Oct 17, 2023
1980265
:recycle: refactor components && fetch token vault informations
Oct 18, 2023
2f2042f
Updated ghostnet contracts in config
glottologist Oct 31, 2023
385eaed
Updated contract error codes
glottologist Oct 31, 2023
821cd20
Changed UI to support new contract structure
glottologist Nov 6, 2023
0b672f3
Added UI changes manually
glottologist Nov 7, 2023
2b73699
Updated batcher contracts to newest version
glottologist Nov 7, 2023
28fc3a5
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 7, 2023
67231db
Merge new UI for separate contracts (#413)
glottologist Nov 7, 2023
348e04e
Please the linter
glottologist Nov 7, 2023
f644300
cicd: edit dockerfile
cyrilevos Nov 7, 2023
7e60c32
Adjusted tick script to tick more pairs and also tick the market maker
glottologist Nov 8, 2023
3bdbdd2
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 8, 2023
e69d2fd
Amended tick operation to pull rates for all pairs
glottologist Nov 10, 2023
886cfc1
Adjusted tick script to call new unified tick endpoint and re-pointed…
glottologist Nov 10, 2023
63f315d
Repointed UI to new ghostnet contract
glottologist Nov 10, 2023
33ec6e0
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 10, 2023
a250476
Repoint to new Batcher beta Ghonest contract (#414)
glottologist Nov 10, 2023
590bae7
new batcher contract hash for docker file
glottologist Nov 13, 2023
a1e350a
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 13, 2023
ac2dcb9
Added get_vaults view to marketmaker and removed no_batch error on UI
glottologist Nov 13, 2023
19a6437
Repointed to new marketmaker
glottologist Nov 13, 2023
c4f5bca
Use - instead of / for swap pairs i.e. tzBTC-USDT instead of tzBTC/USDT
glottologist Nov 13, 2023
f08ca8f
Use - instead of / for swap pairs i.e. tzBTC-USDT instead of tzBTC/US…
glottologist Nov 13, 2023
115a8e3
Repointed to new marketmaker
glottologist Nov 13, 2023
8210e42
corrected tick script calls
glottologist Nov 13, 2023
267b999
corrected tick script calls
glottologist Nov 13, 2023
dcd751a
corrected tick script calls
glottologist Nov 13, 2023
d1a0c5d
corrected tick script calls
glottologist Nov 13, 2023
8484fec
corrected tick script calls
glottologist Nov 13, 2023
2c100b0
Changed ghostnet oracles
glottologist Nov 13, 2023
4d7826f
Added tokens list to exchange state and fixed Volume display
glottologist Nov 14, 2023
0e7397b
Fixed holdings display
glottologist Nov 14, 2023
8f78c0d
Fixed holdings display
glottologist Nov 14, 2023
46edd4b
Fixed linting and type issues
glottologist Nov 14, 2023
5bda817
Fixed linting and type issues
glottologist Nov 14, 2023
76a7f58
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 14, 2023
00ae6a2
410 further split out batcher and mm contracts to avoid size constrai…
glottologist Nov 14, 2023
0f1b5f6
Added swaps to state and fixed token selection
glottologist Nov 16, 2023
0421cc6
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 16, 2023
a4d69bd
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 16, 2023
a8e2ddd
Fixed Token Selection (#416)
glottologist Nov 16, 2023
45f9edb
Fixed merge issues
glottologist Nov 16, 2023
2ffcf6c
Fixed UI docker build issues
glottologist Nov 16, 2023
ce17e16
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 16, 2023
c2d7695
Fix UI Docker build issues (#417)
glottologist Nov 16, 2023
48e7adc
Use the swap tokens to get pair name
glottologist Nov 20, 2023
fe60680
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 20, 2023
dab0731
Repointed to new ghostnet batcher contract
glottologist Nov 20, 2023
9965f1c
Added view to get single swap
glottologist Nov 20, 2023
4f25ac7
Added view to get single swap
glottologist Nov 20, 2023
a580b81
Added view to get single swap
glottologist Nov 20, 2023
d6adea3
Added view to get pair name
glottologist Nov 20, 2023
16f4829
Changed token pair keys for BTCtz
glottologist Nov 21, 2023
0bda1a0
Changed token pair keys for BTCtz
glottologist Nov 21, 2023
c134b75
Updated ghostnet contracts
glottologist Nov 21, 2023
7ba7312
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 21, 2023
803c042
Cajoled the token swaps pair name to match that in Ligo
glottologist Nov 23, 2023
79d6d7b
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 23, 2023
c9378fb
Constrained UI for swapping and fixed oracle price
glottologist Nov 26, 2023
44f13f8
fixed typing on oracle calc
glottologist Nov 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .ash_history
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
exit
oc --endpoint https://ghostnet.tezos.marigold.dev originate contract batcher_ghost transferring 0 from batcher running batcher/batcher-ghostnet.tz --init "$(cat batcher/batcher-storage-ghostnet.tz)" --burn-cap 8 --force
oc gen keys tzthree --sig p256
ls
oc gen keys --help
oc list keys
oc list known addresses
oc keys
oc export --help
oc list known addresses
oc show address tzthree -S
oc show address tzthree -S --help
oc show address tzthree -S | grep prive
oc show address tzthree -S | grep priv
oc show address tzthree -S | grep Priv
oc show address tzthree -S | grep sec
oc show address tzthree -S
oc show address tzthree -S | grep Secre
oc show address tzthree -S | grep Secre > tz3key.txt
ls
oc --endpoint https://ghostnet.tezos.marigold.dev originate contract batcher_ghost transferring 0 from batcher running batcher/batcher-ghostnet.tz --init "$(cat batcher/batcher-storage-ghostnet.tz)" --burn-cap 8 --force
oc --endpoint "https://mainnet.tezos.marigold.dev" config update
oc --endpoint "https://ghostnet.tezos.marigold.dev" config update
exit
oc --endpoint "https://ghostnet.tezos.marigold.dev" config update
alias oc=octez-client
oc --endpoint "https://ghostnet.tezos.marigold.dev" config update
oc --endpoint https://ghostnet.tezos.marigold.dev originate contract batcher_ghost transferring 0 from batcher running batcher/batcher-ghostnet.tz --init "$(cat batcher/batcher-storage-ghostnet.tz)" --burn-cap 8 --force
67 changes: 67 additions & 0 deletions .github/workflows/docker-ghostnet-front-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Docker ghostnet front staging

on:
push:
branches:
- 'release-ghostnet-staging'
- 'release-ghostnet-beta'
pull_request:
branches:
- 'release-ghostnet-staging'
- 'release-ghostnet-beta'
types:
- closed
workflow_dispatch:

jobs:
ui:
strategy:
matrix:
network: [ghostnet]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
submodules: true

- name: Set outputs
id: vars
run: |
echo "date=$(date +%Y-%m-%dT%H-%M-%S)" >> "${GITHUB_OUTPUT}"
echo "sha_short=$(git rev-parse --short HEAD)" >> "${GITHUB_OUTPUT}"

- name: Set up Docker Buildx
uses: docker/Setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push ui version release-ghostnet-staging
if: github.ref == 'refs/heads/release-ghostnet-staging'
uses: docker/build-push-action@v3
with:
file: ./batcher-ui/Dockerfile.${{ matrix.network }}
context: ./batcher-ui/
push: ${{ github.ref == 'refs/heads/release-ghostnet-staging' }}
tags: |
ghcr.io/marigold-dev/batcher-${{ matrix.network }}:staging
ghcr.io/marigold-dev/batcher-${{ matrix.network }}:${{ steps.vars.outputs.date }}-${{ steps.vars.outputs.sha_short }}-staging
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build and push ui version on release-ghostnet-beta
if: github.ref == 'refs/heads/release-ghostnet-beta'
uses: docker/build-push-action@v3
with:
file: ./batcher-ui/Dockerfile.${{ matrix.network }}
context: ./batcher-ui/
push: ${{ github.ref == 'refs/heads/release-ghostnet-beta' }}
tags: |
ghcr.io/marigold-dev/batcher-${{ matrix.network }}:beta
ghcr.io/marigold-dev/batcher-${{ matrix.network }}:${{ steps.vars.outputs.date }}-${{ steps.vars.outputs.sha_short }}-beta
cache-from: type=gha
cache-to: type=gha,mode=max
9 changes: 8 additions & 1 deletion .github/workflows/docker-ghostnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ on:
push:
branches:
- 'release-ghostnet'
pull_request:
branches:
- 'release-ghostnet'
types:
- closed
workflow_dispatch:

jobs:
ui:
# Only run this job if it's a direct push or a *merged* pull request
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
strategy:
matrix:
network: [ghostnet]
Expand All @@ -33,7 +40,7 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push release version
- name: Build and push release version of ui
uses: docker/build-push-action@v3
with:
file: ./batcher-ui/Dockerfile.${{ matrix.network }}
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
push:
paths:
- docs/**
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: 'latest'
- run: mdbook build docs/
- name: store Artefact
uses: actions/upload-artifact@v2
with:
name: "batcher-docs"
path: ./docs/book
retention-days: 1
- name: deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/book
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Ligo Tests

on:
workflow_dispatch: # adding the workflow_dispatch so it can be triggered manually
push:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Ligo version
uses: marigold-dev/[email protected]
with:
ligo_version: 0.69.0
command: version
working_directory: batcher
- name: Install deps
uses: marigold-dev/[email protected]
with:
ligo_version: 0.70.1
command: install
working_directory: batcher
- name: Run batcher test
uses: marigold-dev/[email protected]
with:
ligo_version: 0.70.1
command: run test test/test-batcher.mligo
working_directory: batcher
- name: Run market maker test
uses: marigold-dev/[email protected]
with:
ligo_version: 0.70.1
command: run test test/test-market-maker.mligo
working_directory: batcher
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ result
# Ligo files
.ligoproject
.ligo/
.ligo/term_acceptance

# ESY files
_esy/
Expand All @@ -62,3 +63,5 @@ node_modules
dist
batcher-bot/notifications/node_modules/
batcher-bot/liquidity/node_modules/
book

4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "docs/theme"]
path = docs/theme
url = https://github.com/marigold-dev/marigold-docs-theme.git
branch = main
16 changes: 16 additions & 0 deletions Dockerfile.tick.beta.ghostnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM oxheadalpha/flextesa:latest

RUN apk update && \
apk add bash && \
apk add curl && \
apk add jq

RUN octez-client --endpoint https://ghostnet.tezos.marigold.dev config update && \
octez-client import secret key oracle_account unencrypted:edskRzJUQ1xqCPkVXzT8EiUXjcCsXXkhpiHWE19fAV2JmqW68T6nVoXVPJyx99mjJzUa98NEeGr3kLcEh6NQGcpFKj7BoPRd88 --force

WORKDIR /etc/run

COPY ./tick.sh /etc/run/

CMD [ "/etc/run/tick.sh", "-b", "KT1JG7r23BFcc2GFdSnKBvijmagVzUncn9ry", "-m", "KT1VpMZjKtPa2oEdD2tQJiV7Mj3r4xY4QKFQ", "-f", "180" ]

3 changes: 2 additions & 1 deletion Dockerfile.tick.ghostnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ WORKDIR /etc/run

COPY ./tick.sh /etc/run/

CMD [ "/etc/run/tick.sh", "-b", "KT1VbeN9etQe5c2b6EAFfCZVaSTpiieHj5u1", "-f", "150" ]
CMD [ "/etc/run/tick.sh", "-b", "KT1Txkbx4sDc3qXQubG48vL3ojoTK4HH8Ci8", "-f", "150" ]

136 changes: 3 additions & 133 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,135 +1,5 @@
# Design document for the Batch Clearing DEX POC
# Batcher

The aim of the batch clearing dex is to enable users to deposit tokens with the aim of being swapped at a fair price with bounded slippage and almost no impermanent loss. To enable this users will deposit tokens during a deposit window; all deposits during this window will be a 'batch'. Once the deposit window is over the 'batch' will be 'locked'. Deposits to the dex will not specify a price for the swap, they will specify an offset to whichever oracle price is received after the 'batch' is 'locked'; those offsets being 0, +10bps, or -10bps. Once the batch is locked there will be a waiting window before the process starts to await an oracle price. Upon receipt of the oracle price, the batch is terminated and the orders are cleared.
Batcher is a batch clearing DEX. The aim of the batch clearing dex is to enable users to deposit tokens with the aim of being swapped at a fair price with bounded slippage and almost no impermanent loss. To enable this users will deposit tokens during a deposit window; all deposits during this window will be a 'batch'. Once the deposit window is over the 'batch' will be 'locked'. Deposits to the dex will not specify a price for the swap, they will specify an offset to whichever oracle price is received after the 'batch' is 'locked'; those offsets being 0, +10bps, or -10bps. Once the batch is locked there will be a waiting window before the process starts to await an oracle price. Upon receipt of the oracle price, the batch is terminated and the orders are cleared. After the termination of the batch, the users that placed orders can retrieve their funds. Either the user's order did not clear and they retrieve their original funds or the order cleared (totally or partially) and the get an execution of their order.

> For V1, the deposit window will be 10 mins and then a wait time of 2 minutes before awaiting the oracle price.
> Only the XTZ/USDT pair will be supported for V1

After the termination of the batch, the users that placed orders can retrieve their funds. Either the user's order did not clear and they retrieve their original funds or the order cleared (totally or partially) and the get an execution of their order.


## Deposit

The deposit window is open for a finite time period. During the time period users can deposit their tokens for a BUY or SELL order on the token pair along with an offset to the future received oracle price.

> For V1, deposit windows won't run sequentially, in that as soon as a deposit window closes another will open straight away. Once the deposit window closes, users will need to wait for that batch to be cleared before another deposit window opens.

## Waiting

Once the deposit window has closed there will be a period of 2 minutes prior to awaiting an oracle price. Once that period has elapsed the first received oracle price will close the batch and clearing will start.

## Clearing

The clearing process is the process of matching the orders to ensure that all users can trade at the fairest possible price. Upon deposit there will be six categories of order.

### Side

Depending on whether you are buying or selling the pair you will either be on the BUY side or the SELL side. For the pair XTZ/USDT, XTZ is the base and USDT is the quote. So if the XTZ/USDT rate was 1.9 you would get 1 unit of XTZ for 1.9 of USDT if I am buying the pair, i.e. on the BUY side. If I am selling the pair, the inverse would be true. The side of the trade is important to understand which token needs to be deposited in a given swap order.


### Tolerance

For any deposit, the user can specify the tolerance to the oracle price that they are willing to trade at. This means that each side can further be segregated into their tolerance levels; $Price_{oracle}-10bps$, $Price_{oracle}$ , $Price_{oracle}+10bps$.


### Clearing Level

Given the three tolerance levels, we need to find the level at which we will clear the most orders; the clearing level.

Considering that the amount of deposits for each category is different then we have six categories with a differing amount of tokens deposited for each tolerance.


| Deposits | P-10bps | P | P+10bps |
|----------|:---------:|----------:|----------:|
| *BUY* | X of USDT | Y of USDT | Z of USDT |
| *SELL* | R of XTZ | S of XTZ | T of XTZ |


An added complexity is that if I am will to buy at $Price_{oracle}+10bps$ then I will also be implicitly interested in buying at $Price_{oracle}$ and $Price_{oracle}-10bps$ as they are both cheaper levels if I am on the BUY side. The converse is true for the sell side in that if I sell for $Price_{oracle}-10bps$, then I would be willing to sell for the higher prices of $Price_{oracle}$ and $Price_{oracle}+10bps$.

#### Determining the clearing level

| Prices | P-10bps | P | P+10bps |
|----------|:----------------:|----------:|-----------------:|
| *BUY* | P / 1.0001 | P | P * 1.0001 |
| *SELL* | 1.0001 / P | 1/P | 1/ (1.0001 * P) |


##### P-10bps level

Lets take the P-10bps sell level first. All of the buy levels would be interested in buying at that price, so the clearing volume at that level would be:

$$ CP_{P-10bps} = \min(X + Y + Z, R * \dfrac{ 1.0001 }{P}) $$


##### P level

Lets take the P sell level first. Only the upper 2 buy levels would be interested in buying at that price, but the lower two SELL levels would be interested in selling so the clearing volume at that level would be:

$$ CP_{P} = \min(Y + Z, (R+S) * \dfrac{1}{P}) $$

##### P+10bps level

Lets take the P+10bps sell level first. All of the sell levels would be interested in selling at that price, but only the upper BUY level would be interested in buying so the clearing volume at that level would be:

$$ CP_{P+10bps} = \min(Z, (R+S+T) * \dfrac{1}{(P * 1.0001)}) $$

#### Illustrative Examples

If the Oracle price for XTZ/USDT is 1.9 and the tolerance is +/- 10 basis points, then the six price levels are:

| Price Levels | BUY | SELL |
|--------------|:------:|:-------:|
|Price + 10bps |1.90019 | 0.52626 |
|Price | 1.9 | 0.52631 |
|Price - 10bps | 1.89981| 0.52636 |

Assuming these levels we can determine some very basic illustrative examples of different market scenarios:


| MARKET | AMOUNTS SKEW | BUY X @ (P-) | BUY Y @ (P) | BUY Z @ (P+) | SELL R @ (P-) | SELL @ S (P) | SELL T @ (P+) | Orders cleared @ P-10bps | Orders cleared @ P | Orders cleared @ P+10bps | Clearance Level |
|---|---|---|---|---|---|---|---|---|---|---|---|
|SELL PRESSUE |CENTERED |55 |100 |45 |1000 |1900 |900 |200 |155 |55 |P-10bps|
|SELL PRESSUE |NEG |100 |55 |45 |1900 |1000 |900 |200 |155 |100 |P-10bps|
|SELL PRESSUE |POS |45 |55 |100 |900 |1000 |1900 |200 |100 |45 |P-10bps|
|BUY PRESSURE |CENTERED |250 |100 |250 |95 |190 |95 |50 |150 |200 |P+10bps|
|BUY PRESSURE |NEG |250 |100 |250 |190 |95 |95 |100 |150 |200 |P+10bps|
|BUY PRESSURE |POS |250 |100 |250 |95 |95 |190 |50 |100 |200 |P+10bps|
|BALANCED |CENTERED |50 |101 |50 |95 |190 |95 |50 |150 |50| P|
|BALANCED |NEG |101| 50| 50| 190|95| 95 |100|150| 101| P|
|BALANCED |POS |50 |50 |101| 95| 95| 190 |50 |100| 50| P|
|BALANCED |OPPOSING (NEG) |50 |50| 101| 190| 95| 95| 100| 100| 50| P-10bps|
|BALANCED |OPPOSING (POS) |101 |50| 50| 95| 95| 190| 50| 100 |101| P+10bps|

Once we know the clearing level and the volume that can be cleared at that level, we will know how many can be matched (some partially) and those will receive pro-rata execution of their orders. For those that bid outside of the clearing level they will receive their deposits back when they claim.

> A Google [Sheet](https://docs.google.com/spreadsheets/d/1tWIQEVi2COW3UOH7BPbcNrqe77SsPqZVFqN7nfLe6mc/edit?usp=sharing) with these calculations in is available.
>
## Claiming

After clearing, users can claim their 'results', whether that be their original deposits, a partially matched order result or a fully filled order for the opposing token.

# Timelines


```mermaid
gantt
dateFormat YYYY-MM-DD
title Timelines for Batcher going to mainnet
excludes weekends

section Development
End of internal audit :ia, 2023-01-09, 4d
Fee Burning :fb, 2023-01-09, 4d
Oracle :or, 2023-01-09, 10d
Multiple Token Pools (incl. contract management and multisig) :mtp, after fb, 3w
Stabilisation / Final Testing :ft, after mtp, 5d
Mainnet launch :mn, after ft, 3d

section Engagement
Blog post for fee burning :bpfb, 2023-01-20, 5d
Blog post for token pools :bptp, 2023-01-27, 5d
Blog post for oracle :bpor, 2023-02-10, 5d
Blog post for mainnet :bpmn, 2023-02-20, 5d

```
Full documentation can be found [here](https://marigold-dev.github.io/batcher/)
8 changes: 0 additions & 8 deletions batcher-ui/.eslintrc.js

This file was deleted.

Loading
Loading