Code Monkey home page Code Monkey logo

limit-order-protocol's Introduction

1inch Limit Order Protocol Smart Contract

Build Status Coverage Status

Version warning

The master branch contains the latest work-in-progress version of limit orders. It hasn't been audited and may contain severe security issues or may not work at all.

Please, use the commit tagged version to get the latest production version that has passed through a series of security audits:

About

You can find the latest general overview and documentation on the 1inch limit orders protocol in the description.md. Documentation for this and previous versions can be found on the 1inch documentation portal.

The repository contains smart contracts for EVM-based blockchains (such as Ethereum, Binance Smart Chain, etc.). These contracts are a core part of the 1inch limit order protocol, allowing users to create limit orders off-chain that can be filled on-chain. A limit order is a data structure signed according to EIP-712.

Limit Order

The key features of the protocol are extreme flexibility and high gas efficiency, which are achieved with the following features

Basic features

  • Select an asset receiver for an order.
  • Choose whether to allow or disallow partial and multiple fills.
  • Define conditions that must be met before execution can proceed (e.g. stop-loss, take-profit orders).
  • Specify interactions (arbitrary maker's code) to execute before and after order filling.
  • Choose an approval scheme for token spend (approve, permit, permit2).
  • Request that WETH be unwrapped to ETH either before (to sell ETH) or after the swap (to receive ETH).
  • Make an order private by specifying the only allowed taker's address.
  • Set the order's expiration date.
  • Assign a nonce or epoch to the order for easy cancellation later.

Advanced features

  • Define a proxy to handle transfers of assets that are not compliant with IERC20, allowing the swapping of non-ERC20 tokens, such as ERC721 or ERC1155.
  • Define functions to calculate, on-chain, the exchange rate for maker and taker assets. These functions can be used to implement dutch auctions (where the rate decreases over time) or range orders (where the rate depends on the volume already filled), among others.

RFQ orders

Separate RFQ order are deprecated in v4. To create the most gas efficient order use a basic order without extensions.

Supported tokens

  • ERC 20
  • ERC 721
  • ERC 1155
  • Other token standards could be supported via external extension

Deployments & audits (Limit Orders Protocol v3):

You can find 1inch limit order protocol deployments here:

Ethereum mainnet: 0x119c71D3BbAC22029622cbaEc24854d3D32D2828

BSC mainnet: 0x1e38Eff998DF9d3669E32f4ff400031385Bf6362

Polygon mainnet: 0x94Bc2a1C732BcAd7343B25af48385Fe76E08734f

Optimism Mainnet: 0x11431a89893025D2a48dCA4EddC396f8C8117187

Arbitrum One: 0x7F069df72b7A39bCE9806e3AfaF579E54D8CF2b9

Gnosis Chain: 0x54431918cEC22932fCF97E54769F4E00f646690F

Avalanche: 0x0F85A912448279111694F4Ba4F85dC641c54b594

Kovan Testnet: 0xa218543cc21ee9388Fa1E509F950FD127Ca82155

Fantom Opera: 0x11DEE30E710B8d4a8630392781Cc3c0046365d4c

You can find audit reports on etherscan and in the separate audit repository.

Utils library (Limit Orders Protocol v3)

Plenty of utils that helps create & sign orders are available in our typescript utils library:

limit-order-protocol's People

Contributors

artall64 avatar byshape avatar galekseev avatar k06a avatar krboktv avatar pavelkurmacheff avatar pzixel avatar sevenswen avatar shoom3301 avatar tradersnow222 avatar typicalbuster avatar zumzoom avatar zzomrot 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

limit-order-protocol's Issues

scam

  • I'm stuck like this, can anyone help?

imageimage

order hash doesn't match

Trying to fill some order but unsuccessful. Investigating further turns out that order hash doesn't match from onchain.

Steps to reproduce:

const res = await axios.get('https://limit-orders.1inch.io/v2.0/1/limit-order/all', {
        params: {
          page: 1,
          limit: 100,
          statuses: '[1]',
        },
      })

const order = res.data[20]

const contract = new Contract('0x119c71d3bbac22029622cbaec24854d3d32d2828', IOneInchLimitOrderProtocol.abi, provider)
const orderHash = await contract.hashOrder(order.data)
assert(order.orderHash === orderHash)

Bug: orders with old price

I had very old order and I forgot about it
Screenshot from 2022-05-12 12-39-34
Right now 1inch token price is 0.8 USDT.
USDT was not approved, and when I approved USDT - old orders was bought 1inch tokens for 1.25 USDT - Whaaat?
https://www.bscscan.com/tx/0xd74f7c98cae8cf3738868754cb53952ac3752a7a237ce8f8b0c76b1cc80f072e
https://www.bscscan.com/tx/0xd74f7c98cae8cf3738868754cb53952ac3752a7a237ce8f8b0c76b1cc80f072e

Pls, fix it in the protocol - don't buy tokens higher than market (amazing idea!).
And fix it in your interface - if I forgot about this orders, it can notify me before approving USDT.. I don't want buy 1inch token right now =)
Thanks, guys for your work!

Token amounts aren't updated when taker = maker

Is it possible to use your limit order protocol for the cases when both the maker and the taker are the same address?

I'm thinking about using it to accept crypto payments for the merchants.
In my scenario, customers pay for products from the customer's wallet with the conversion of a token into stable coin in the background utilizing 1inch swap, with the following involvement of order.interaction API and withdrawal of stable coin into the merchant's wallet.

Following this Idea I'm trying to swap eth with dai assets but after all the balances aren't changing.
Cudl you take a look, please?

expect(await this.weth.balanceOf(addr1)).not.to.be.bignumber.equal('1000000');
expect(await this.dai.balanceOf(addr1)).not.to.be.bignumber.equal('1000000');

See #92 pull request opened with the test added.

LOP: Bad Signature

I'm trying it on BSC network,

Here is the order that i try to fill

{
  makerAsset: '0x4bd17003473389a42daf6a0a729f6fdb328bbbd7',
  takerAsset: '0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3',
  getMakerAmount: '0xf4a215c30000000000000000000000000000000000000000000000000003e871b540c00000000000000000000000000000000000000000000000000000013f4589a1b440',
  getTakerAmount: '0x296637bf0000000000000000000000000000000000000000000000000003e871b540c00000000000000000000000000000000000000000000000000000013f4589a1b440',
  makerAssetData: '0x',
  takerAssetData: '0x',
  salt: '770447706749',
  permit: '0x4bd17003473389a42daf6a0a729f6fdb328bbbd70000000000000000000000006ab9c477246bcaa4a1c3a825f42437ef66c559530000000000000000000000001e38eff998df9d3669e32f4ff400031385bf6362000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000624c48ab0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000001b7a9ee5e6266dddff5c891efa896da98aca28b4db6f176d6f710bb713d617113d685fb3dff3144c717e4e9b70bf9c55ce7f6a90a595f7910c3dc45a605a46d906',
  predicate: '0x961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000001e38eff998df9d3669e32f4ff400031385bf63620000000000000000000000001e38eff998df9d3669e32f4ff400031385bf63620000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e30000000000000000000000006ab9c477246bcaa4a1c3a825f42437ef66c55953000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b00000000000000000000000000000000000000000000000000000000624c48ab00000000000000000000000000000000000000000000000000000000',
  interaction: '0x',
  receiver: '0x0000000000000000000000000000000000000000',
  allowedSender: '0x0000000000000000000000000000000000000000',
  makingAmount: '1100000000000000',
  takingAmount: '351042871080000',
  maker: '0x6ab9c477246bcaa4a1c3a825f42437ef66c55953'
}

full api response

{
  signature: '0xcd2d8b5180937bdbc5caf3476b531a57ec5d37f1e67738a7d3c1ec5cb128f0ba0fde400655cce277472966841b1867a0e61ed08575422321b93afab8b6d50ccc1c',
  orderHash: '0x3cff44ec331daa07ac19639cedb9b1704829bb37cd2d373d791e3f76b7d384f6',
  createDateTime: '2022-03-29T13:48:32.400Z',
  remainingMakerAmount: '1100000000000000',
  makerBalance: '1563942553701645202',
  makerAllowance: '115792089237316195423570985008687907853269984665640564039457584007913129639935',
  data: {
    makerAsset: '0x4bd17003473389a42daf6a0a729f6fdb328bbbd7',
    takerAsset: '0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3',
    getMakerAmount: '0xf4a215c30000000000000000000000000000000000000000000000000003e871b540c00000000000000000000000000000000000000000000000000000013f4589a1b440',
    getTakerAmount: '0x296637bf0000000000000000000000000000000000000000000000000003e871b540c00000000000000000000000000000000000000000000000000000013f4589a1b440',
    makerAssetData: '0x',
    takerAssetData: '0x',
    salt: '770447706749',
    permit: '0x4bd17003473389a42daf6a0a729f6fdb328bbbd70000000000000000000000006ab9c477246bcaa4a1c3a825f42437ef66c559530000000000000000000000001e38eff998df9d3669e32f4ff400031385bf6362000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000624c48ab0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000001b7a9ee5e6266dddff5c891efa896da98aca28b4db6f176d6f710bb713d617113d685fb3dff3144c717e4e9b70bf9c55ce7f6a90a595f7910c3dc45a605a46d906',
    predicate: '0x961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000001e38eff998df9d3669e32f4ff400031385bf63620000000000000000000000001e38eff998df9d3669e32f4ff400031385bf63620000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e30000000000000000000000006ab9c477246bcaa4a1c3a825f42437ef66c55953000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b00000000000000000000000000000000000000000000000000000000624c48ab00000000000000000000000000000000000000000000000000000000',
    interaction: '0x',
    receiver: '0x0000000000000000000000000000000000000000',
    allowedSender: '0x0000000000000000000000000000000000000000',
    makingAmount: '1100000000000000',
    takingAmount: '351042871080000',
    maker: '0x6ab9c477246bcaa4a1c3a825f42437ef66c55953'
  },
  makerRate: '0.319129882800000000',
  takerRate: '3.133520406256358265'
}

So when i try to recover ecdsa with orderHash and signature in the api response it returns maker address but when i sent the order to my contract and hash it using the same hashing algorithm at 0x1e38eff998df9d3669e32f4ff400031385bf6362 it returns a different hash that is not in the api response

Challenge 1 — Margin trading on the 1inch Limit Order Protocol

Prize Title

Margin trading on the 1inch Limit Order Protocol

Prize Bounty

3,000 USD in 1INCH Tokens

Challenge Description

Write a smart contract enabling the creation of limit orders for margin trading on the 1inch Limit Order Protocol.

1inch limit order protocol is a set of smart contracts, that can work on any EVM based blockchains (Ethereum, Binance Smart Chain, Polygon, etc.). Key features of the protocol is extreme flexibility and high gas efficiency that achieved by using two different order types - regular Limit Order and RFQ Order.
Smart Contract allows users to place limit orders and RFQ Orders, that later could be filled on-chain. Both type of orders is a data structure created off-chain and signed according to EIP-712.

Judging Criteria

Solution must be unique and it must work. We expect demo, not presentations
We'll do a code review to ensure code quality to make the final decision.

Resources

Limit Order Protocol Documentation

Challenge 3 — Automated market making strategy for stablecoins using the 1inch Limit Order Protocol

Prize Title

Automated market making strategy for stablecoins using the 1inch Limit Order Protocol

Prize Bounty

3,000 USD in 1INCH Tokens

Challenge Description

Write a smart contract that creates buy/sell orders for stablecoins. The idea is to be able to buy stablecoins at lower rates and sell at higher rates, making a profit on rate differences. A smart contract would simultaneously create buy and sell orders.

1inch limit order protocol is a set of smart contracts, that can work on any EVM based blockchains (Ethereum, Binance Smart Chain, Polygon, etc.). Key features of the protocol is extreme flexibility and high gas efficiency that achieved by using two different order types - regular Limit Order and RFQ Order.
Smart Contract allows users to place limit orders and RFQ Orders, that later could be filled on-chain. Both type of orders is a data structure created off-chain and signed according to EIP-712.

Judging Criteria

Solution must be unique and it must work. We expect demo, not presentations
We'll do a code review to ensure code quality to make the final decision.

Resources

Limit Order Protocol Documentation

Challenge 2 — Limit order adapter for the 1inch Liquidity Protocol

Prize Title

Limit order adapter for the 1inch Liquidity Protocol

Prize Bounty

3,000 USD in 1INCH Tokens

Challenge Description

An adapter for creating limit orders over the 1inch Liquidity Protocol or over any decentralized exchange (DEX), based on their available liquidity. The adapter should contain isValidSignature, getMakerAmount (which calculates return amount based on DEX "getReturn" function) and transferFrom (which triggers swaps and sends to takerAddress)..

1inch limit order protocol is a set of smart contracts, that can work on any EVM based blockchains (Ethereum, Binance Smart Chain, Polygon, etc.). Key features of the protocol is extreme flexibility and high gas efficiency that achieved by using two different order types - regular Limit Order and RFQ Order.
Smart Contract allows users to place limit orders and RFQ Orders, that later could be filled on-chain. Both type of orders is a data structure created off-chain and signed according to EIP-712.

Judging Criteria

Solution must be unique and it must work. We expect demo, not presentations
We'll do a code review to ensure code quality to make the final decision.

Resources

Limit Order Protocol Documentation

supports for signTypedData_v4

Hi,

I'd like to make a limit order, with a wallet on Trezor (not using Metamask, as this seems to be not supported yet).
I get the error:

The signing of a limit order in your wallet failed. Please, use another wallet that supports the method signTypedData_v4

Based on Trezor, this should now be supported also on Trezor ONE - since the firmware release in Jan.
Please see:
trezor/trezor-firmware#2128
and
trezor/trezor-firmware#1970

Is this something you can solve on 1inch side?
Thanks!

Challenge 4 — Open Track

Prize Title

Open Track

Prize Bounty

3,000 USD in 1INCH Tokens

Challenge Description

Suggest your own solution, keeping in mind that the 1inch Limit Order Protocol has conditional execution and arbitrary price discovery.

1inch limit order protocol is a set of smart contracts, that can work on any EVM based blockchains (Ethereum, Binance Smart Chain, Polygon, etc.). Key features of the protocol is extreme flexibility and high gas efficiency that achieved by using two different order types - regular Limit Order and RFQ Order.
Smart Contract allows users to place limit orders and RFQ Orders, that later could be filled on-chain. Both type of orders is a data structure created off-chain and signed according to EIP-712.

Judging Criteria

Solution must be unique and it must work. We expect demo, not presentations
We'll do a code review to ensure code quality to make the final decision.

Resources

Limit Order Protocol Documentation

create fully onchain split, get price, and trade smart contracts

A fully onchain DEX aggrator will allow DeFi building blocks for cotrader.com and others.

Prices should be competitive with other DEX aggregator options..

Users can get prices and execute a split trade that gets the max tokens possible at the lowest prices available by using a combination of dexs, especially AMM Swap DEXs including Kyber, Bancor, Uniswap, Oasis.

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.