Code Monkey home page Code Monkey logo

marigold-dev / batcher Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 2.0 4.58 MB

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.

Home Page: https://batcher.marigold.dev/

License: MIT License

LigoLANG 38.34% Shell 0.31% Nix 0.84% Makefile 0.95% Dockerfile 0.10% JavaScript 6.78% TypeScript 46.30% Less 6.38%
defi ligo tezos web3

batcher's People

Contributors

aguillon avatar cyrilevos avatar glottologist avatar hakimba avatar kienle371999 avatar laucans avatar melwyn95 avatar oteku avatar vanessamontesb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

melwyn95

batcher's Issues

Move time constants into storage

The time constants that we have for defining the waiting periods should be moved into storage so they can be manipulated in the tests.

Treasury

We need a treasury system to support the deposit of tokens to support the order matching mechanism.

The treasury should be able to accept deposits and link them to orders. It should also be able to return tokens after orders have been cancelled.

Price fetching

We need a mechanism to collect the current price of the token pair from an external source (oracle / dex).

For the PoC, this should be the simplest source possible (probably a DEX feed)

Treasury

The swap execution will need to be supported by a treasury mecanism that supports multiple token types per address

Clearing Price Calculator

Based on the new doc we should create the clearing price calculator to support the design doc.

It should receive a batch (i.e. a number of swap orders at different levels and sides) and an Oracle price. From this we need to calculate the clearing price level.

Fix deployment

For the PoC we need to be able to deploy to a testnet easily (this has mostly been done) but we need to test after merging the components and then fix any deployment issues.

We should also target Ghostnet for deployment

Remove sub-contract entrypoints

The separate components like treasury and matching won't be individual contracts for the POC so we should remove the contract entrypoints and switch to method calls from the main slip contract

Add design doc

We need a design do to show how all the components fit together

Switch token pair from XTZ/USDT to tzBTC USDT

What will need to change:

  • Design doc
  • Code references to tokens
  • Price poster (tzBTC/USDT isn't directly available from the source we are using so it will need to be calculated from XTZ/USDT and XTZ/tzBTC)

UI

We need a very simple UI to enable processing the swaps. This needs to be functional - not pretty

Order matching

  • We need a mechanism to match off orders either completely or partially (this would mean leaving the remaining un-filled part of the order until it expires or is itself filled or partially filled).
  • Any orders that have expired should be cancelled

Testnet Deployment and Testing

We need to run through a complete test which means

  • Deployment to testnet
  • Deposits (using UI or CLI) - at least 15 swap orders
  • Posting of prices
  • Successful execution of swap orders
  • Successful redmption

Fix pricing calculation and write tests

we have to decide and find how do we want to deal with the math file and prices calculation, and write tests (maybe implementing the sheet Jason made in excel but with tests)

CI

CI needs to be fixed to use the make file and run the tests

Order execution

once we know the clearing level (which has been coded) we can progress to the settlement of the orders. Any orders at or below the clearing price can be settled pro-rata (first come first serve), this could include partial fills. All others are not executed.

On-chain views

In order to make the UI work easier, we need a single or multiple on-chain views that provide the following:

  • current batch time remaining? (0 if no batch open)
  • current order book (not sure this will be in the production version but will be useful for testing)
  • current orders for given user
  • summary of previous orders for current user

Test Token Deposits in Contract.

When we deposit a swap in the testnet contract, this should be reflected in the wallet amount. I.e. a swap deposit should remove an equal amount of token from the trader/user's wallet and that token should be in the contract's treasury.

We need to test that this is actually happening on the testnet.

Test Plan for PoC

Initial Test for 0-slip PoC

The following should be run on the deployed contract for both initially supported pairs - XTZ/USDT and USDT/tzBTC,

Scenario 1. Simple Matching Swap

Setup:

  • Update Oracle price for swap.
  • Place equal and opposing swaps from different wallets at exact price and correct amounts

Result:

  • The swaps should match and the treasury should redeem the correct amounts to the respective wallets

Scenario 2. Simple Non Matching Swap

Setup:

  • Update Oracle price for swap.
  • Place first swap
  • Update oracle price again
  • Place opposing swap from a different wallet at a different price

Result:

  • The swaps should not match and deposits be returned correctly after expiry

Scenario 3. Partial Matching Swap

Setup:

  • Update Oracle price for swap.
  • Place first swap
  • Place equal and opposing swap from a different wallet at the same price but differing amount.

Result:

  • The swaps should partially match and the treasury should redeem the amounts correctly
  • Any remaining non matched amount should be redeemed to the correct wallet after swap expiry

Test Tokens

To be able to test the contract we will need tokens and XTZ in a defined wallet. We will be testing two pairs for the PoC - XTZ/USDT & UDST/tzBTC

  • Create re-usable test wallets (two minimum)
  • Get XTZ, tzBTC and USDT from faucets and transfer to wallets ready for testing

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.