Giter Site home page Giter Site logo

rndlabs / cowswap-twap-orders Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 2.0 723 KB

๐Ÿ„๐Ÿฎ Time-weighted average price orders for CoW Protocol

License: GNU General Public License v3.0

Solidity 76.77% TypeScript 23.23%
cow-protocol ethereum gnosis-protocol solidity tenderly trading trading-algorithms

cowswap-twap-orders's People

Contributors

mfw78 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cowswap-twap-orders's Issues

feat: action reversion handling

Problem
Naively polling every block for a tradeable order is not required with ConditionalOrders that have some defined payload. This is because the payload itself relates to the order and can be used to determine beforehand if there should be some tradeability (unless specific on-chain state is checked by the respective ConditionalOrder).

Solution
When watching for orders, we take advantage of custom errors passed on reversion:

  1. If reverted with OrderCancelled, delete it from storage.
  2. If reverted with OrderExpired, delete it from storage.
  3. If reverted with OrderNotValid, skip processing in this block (likely a result of a span).

Tasks

  • Implement reversion handling

Typo in build command

You build command goes like this:
"build": "forge buid && yarn build:actions && yarn build:cli",

Shouldn't it be:
"build": "forge build && yarn build:actions && yarn build:cli",

feat: remember order broadcast

Problem
Naively watching for orders and sending these to the API will result in multiple submissions of the same order. As CoW Protocol protects against this by monitoring the fill of each orderUid, this doesn't cause multiple executions, however it consumes resources for API submissions.

Solution
Remember the orderUids that are submitted. If an order has been previously submitted, don't submit it again. Implement a fill watch action that purges filled orderUids from the storage.

Tasks

  • Modify Registry layout to include status a Map with key of keccak256(getTradeableOrder(payload)) and value corresponding to an enum of either SUBMITTED or FILLED.
  • If order is SUBMITTED, don't attempt to submit again to CoW Protocol.

feat: action performance

Problem
It is a little difficult to monitor all the parts of an order (TWAP) to see see what the fill rate was like.

Solution
Using the status from #2 if the order becomes OrderCancelled or OrderExpired, we can generate a report.

Tasks

  • On OrderCancelled or OrderExpired, generate a report of the number of parts that were filled / not filled.

Allow variable signature length

I really like the changes that were made compared to the framework in https://github.com/cowprotocol/conditional-smart-orders as they allow more effective creation of smart orders and also make it easier to leave the Safe functional!

One decision I find difficult however, for general purpose smart orders is to require fixed length signatures. There are definitely use cases (e.g. dynamic price checkers for milkman style orders) where the same order type may have different lengths signatures.

Maybe we can define a magic value that indicates "arbitrary length" to avoid failing this check:

if (_signature.length == CONDITIONAL_ORDER_BYTES_LENGTH() && verifyTrade(_dataHash, _signature)) {

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.