Code Monkey home page Code Monkey logo

cfmmrouter.jl's Introduction

CFMMRouter

Dev Build Status codecov

Overview

This package contains a fast solver for the CFMM Routing problem. We partially decompose the problem to enable fast solutions when the number of CFMMs is large relative to the number of tokens. We describe our algorithm in detail in our paper, An Efficient Algorithm for Optimal Routing Through Constant Function Market Makers.

For more information, also check out the documentation.

Quick Start

First, add the package locally.

using Pkg; Pkg.add("CFMMRouter")

Make some swap pools.

using LinearAlgebra
using CFMMRouter

equal_pool = ProductTwoCoin([1e6, 1e6], 1, [1, 2])
unequal_small_pool = ProductTwoCoin([1e3, 2e3], 1, [1, 2])
prices = ones(2)

Build a Router & route.

router = Router(
    LinearNonnegative(prices),
    [equal_pool, unequal_small_pool],
    2,
)
route!(router)

Check out the results.

Ψ = round.(Int, netflows(router))
println("Profit: $(dot(prices, Ψ))")

Performance

This routing algorithm scales approximately linearly in the number of swap pools for the arbitrage problem. These tests were run on a MacBook Pro with a 2.3GHz 8-Core Intel i9 processor. Several performance improvements are possible. alt text

Citing

@article{diamandis2023efficient,
  title={An Efficient Algorithm for Optimal Routing Through Constant Function Market Makers},
  author={Diamandis, Theo and Resnick, Max and Chitra, Tarun and Angeris, Guillermo},
  journal={arXiv preprint arXiv:2302.04938},
  year={2023}
}

References

cfmmrouter.jl's People

Contributors

angeris avatar frjnn avatar max-riskharbor avatar songjhaha avatar tjdiamandis avatar

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.