Code Monkey home page Code Monkey logo

milkman's Introduction

Milkman

Tests License: LGPL-3.0

Fulfills all of your smart contract's CoW needs. ๐Ÿฎ

A simple way for smart contracts to sell their tokens via the CoW Protocol, reaping the benefits of MEV protection even when tx.origin is malicious (e.g., a liquidator bot in a borrow/lend protocol).

How to use

To swap via Milkman, call milkman.requestSwapExactTokensForTokens, passing in the following parameters:

  • amountIn: an amount of tokens to sell
  • fromToken: ERC20 you're swapping out of
  • toToken: ERC20 you're swapping into
  • to: the intended receiver of the bought tokens
  • priceChecker: the address of a price checker, or address(0) for none; explained below
  • priceCheckerData: encoded data to pass to the price checker; explained below

After you submit a swap request, it should be picked up and executed within 1-2 minutes.

See docs/EXAMPLES for examples.

Price checkers

After token have been sent to Milkman, it functions like a 'conditional signer', only releasing those tokens to CoW protocol under certain conditions. Anyone can generate an off-chain order for an on-chain swap request, but Milkman will only sign off on orders that pass its checks.

Many of these checks are baked into Milkman itself, such as ensuring that the off-chain order is a sell order (not a buy order). However, an important one is not: validating that the bot-supplied minOut approximates the true value of the tokens that a user is swapping. Users who don't want to trust the CoW off-chain system can use price checkers. Price checkers verify that a minOut is in-line with some on-chain price feed. For example, one price checker could verify that minOut is at least 90% of what they could get from selling the tokens via SushiSwap.

The only requirement for a price checker is that it needs to be compatible with the IPriceChecker interface. Anyone can create a new one, and new ones don't need to be whitelisted.

Developing new price checkers

To be valid, price checkers need to implement the following function:

function checkPrice(
        uint256 _amountIn,
        address _fromToken,
        address _toToken,
        uint256 _minOut,
        bytes calldata _data
    ) external view returns (bool);

The process of building one is straightforward. Examples can be found in the pricecheckers folder.

milkman's People

Contributors

charlesndalton avatar fleupold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

milkman's Issues

feature request: add temporary asset holder getter

After swap has been called & before the swap is executed, the assets are held by a contract deployed for the each specific swap.

When users are testing that the swaps are correctly implemented, we also wanna check that the correct assets and amounts were transfered to this new "order proxy" contract.

a view only function that returns this newly created address would help a lot with the usability

feel free to close if useless :)

great job, keep up the great work

How to test ?

I am working on a protocol that need to swap some tokens (relatively small amounts), I want those swaps to be permissionless, so using the milkman looks like a good idea, but I am missing 2 things:

  1. Some kind of callback notifying the swap was executed, can be called back even after a few hours.
  2. A way to test/simulate an executed trade, testing on a local network without solvers will never execute.

Do you have any suggestions how to tackle those issues ?

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.