npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sushiswap/settlement

v0.13.1

Published

Contracts that support limit orders feature for SushiSwap

Downloads

40

Readme

SushiSwap Settlement

This repository contains solidity contracts to enable limit orders for SushiSwap.

Overview

Typically AMMs only settle orders with market price, which represents a significant limitation compared to orderbook driven exchanges. SushiSwap addresses this critical AMM pain point with the release of the limit order feature.

Contracts in this repo help you submit a limit order with a lower price than what it is now. Later, when the price gets lower enough to meet the requirement of your order, it gets settled.

Contracts

Limit orders on SushiSwap work in a completely decentralized manner, without the need of any centralized authority. The system consists of two contracts: OrderBook and Settlement.

OrderBook

OrderBook is deployed at 0x460c3749ea885617afb9a375ca36d1487781efb3 on kovan and rinkeby testnets.

OrderBook keeps limit orders that users have submitted. Anyone can call createOrder() to create a limit order with the amount to sell and the minimum price. He/she needs to approve the amount to sell for the Settlement contract.

To reduce users' gas fee, OrderBook isn't deployed on the mainnet. The one on kovan testnet is used for production.

Settlement

Settlement is deployed at 0x44c9c1b05139bbc49045852d6e671c5a9f37078a on the Ethereum mainnet, kovan and rinkeby testnets.

Settlement is in charge of swapping tokens for orders. Anyone can call fillOrder() to fill the order submitted. We'll call this caller a 'relayer'. Relayers need to call it with proper parameters to meet the minimum price requirement set in the order. If the call is successful, fee will be transferred to the relayer.

The maker of an order can cancel it with cancelOrder() on Settlement.

It is possible to fill only a certain amount of tokens, not all. In most cases, submitted orders will reside on the OrderBook and their amount will be filled by different callers in different blocks.

Incentives

Relayer

Settlement is a wrapper contract around UniswapV2Router02. Every function in this contract has a duplicated version in the Settlement with an extra parameter args. If args is not empty, it is used for filling orders; see Settlement.fillOrders() for details.

So, users for SushiSwap can choose to be a relayer or not. If he/she decided to do so, calling any swap functions in Settlement will benefit them. Otherwise, he/she can just call functions in UniswapV2Router02 without receiving any fee.

Fee

For every fillOrder() call, 0.2% fee of the amount sold is charged. Out of the fee, 20% goes to xSUSHI holders and the remainder to the relayer. The fee is deducted prior to the swap.

Let's assume Alice created an order to sell 1 ETH with the minimum price of 500 DAI. Current price of ETH is 400 DAI so this order cannot be filled right away. Leter, when the market price goes up to 500 DAI, Bob is trying to fill the entire amount of this order as a relayer.

If the call is successful, amounts of tokens transferred are:

  • Limit Order Fee: 1 ETH x 0.2% x 80% = 0.0016 ETH (goes to Bob; relayer)
  • Limit Order Fee Split: 1 ETH x 0.2% x 20% = 0.0004 ETH (goes to xSUSHI)
  • Swap Fee: (1 ETH - 0.002 ETH) x 0.3% = 0.002994 ETH (goes to the liquidity provider)
  • ETH Amount Sold: 1 ETH - 0.002 ETH - 0.002994 ETH = 0.995006 ETH (goes to the liquidity pool)
  • DAI Amount Bought: 0.995006 ETH x 500 DAI = 497.503 DAI (goes to Alice; maker)

Audits

This repository has been audited by Quantstamp and Peckshield.

License

MIT