Giter Site home page Giter Site logo

warthog-network / shifu-matching Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coinfumastershifu/shifu-matching

0.0 0.0 1.0 324 KB

Demo of next generation matching engine to be included in Warthog Network. Price is determined by supply and demand AND also pool liquidity.

C++ 80.06% Python 1.41% Julia 0.68% HTML 16.13% Meson 1.72%

shifu-matching's Introduction

Shifu Matching Engine Demo

This is my custom matching engine that I wrote for Warthog Network. It matches both, buy and sell orders and also pool liquidity.

Why does the world need this?

Decentralized Finance (DeFi) is becoming a killer application of crypto and is only going to grow in importance. However it suffers from a fundamental problem: transactions can be reordered within a block.

Since there is no direct concept of time in a block chain, but instead the blocks form the discrete-time sequence of events, there is no notion of which order came before or after within a block. Block builders artificially specify an order in which DeFi orders are processed. This leads to the concept of Maximal Extractable Value (MEV) which describes this property and the possibility to reorder, add and/or omit specific orders such that an arbitrage-like opportunity is formed and exploited.

The most notable incarnation of this practice is the dreaded Sandwich which describes carefully crafted front-running and back-running of a victim's order such that it is pushed to the order to the specified limit price. For example it works by buying before you buy and selling after you buy and this is done precisely as much as your order's limit price allows.

Basically the sandwich is doing this to your order:

Sublime's custom image

The struggle is real. One method to avoid this problem is to be secretive with your order but this does not always work well nor is it practical. Therefore we need to make DeFi great again and fight back. The solution to this problem is simple to formulate but difficult to implement: We need to get rid of the ordering of transactions within a block. Each transaction shall be treated equally. Obviously then front and back-running is not possible anymore and so won't be sandwiches.

I propose a new matching engine that finds the same price for all buys and all sells for a market. This price is fairly determined by supply and demand and also by pool liquidity.

The goal is to implement this matching engine in Warthog Network at some later stage together with hard-coded DeFi capabilities.

What does the Repo contain?

The repository contains a C++ implementation of my Shifu Matching Engine. It can be compiled to webassembly using this commands:

meson setup build-wasm --cross-file=crosscompile/emscripten.txt
cd build-wasm
ninja

when the Emscripten SDK is installed. Then a python3 server can be launched at the top level of the repo:

python3 server.py

to play with the demo website at localhost:8000/website/demo.html.

shifu-matching's People

Contributors

julskawa avatar coinfumastershifu avatar

Forkers

julskawa

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.