HomeKnowledge BaseIntroducing the Programmatic Order Framework, from CoW Protocol

Introducing the Programmatic Order Framework, from CoW Protocol

8 min read

As a pioneer in the field of intents, CoW Swap has consistently brought faster, easier, and safer trading to DAOs and DeFi enthusiasts.

As DeFi grows and transactions become ever-more complex, the friction of having to sign and make orders manually becomes more pronounced. Traders looking to place recurring orders as a part of a complex trading strategy, DAO operators responsible for managing a treasury, and individuals tired of signing repetitive transactions could all benefit from a system that allows for automated order placement.

Today, CoW Protocol is proud to announce the release of two features that take the pain out of order placement and open up a wide range of possibilities for automation.

To start off, we’re introducing a new order primitive to the world of DeFi. We call it “Programmatic Orders”. Programmatic Orders are orders that create more orders. They require just one signature to create, then execute when on-chain conditions (prices, volumes, balances, times, etc.) are met. Programmatic Orders can execute indefinitely into the future, automating everything from complex trading strategies to advanced order types, portfolio management, DAO operations, and more.

Alongside Programmatic Orders, CoW Protocol is launching the Programmatic Order Framework. As the name implies, it’s a framework that allows for the easy creation of Programmatic Orders.

Below, we take a deeper look at Programmatic Orders, the Programmatic Order Framework, and the technical details necessary for implementation. We also call on the DeFi ecosystem to submit proposals for building applications on top of the Programmatic Order Framework through the CoW Grants Program.

The current state of programmatic actions

The DeFi space currently supports very simple programmatic actions — for example, individual limit orders. Unfortunately, users have to trust a centralized operator to execute these actions correctly and fairly.

Despite the rise of autonomous agents in the wake of initiatives like ERC-1271, the vast majority of interactions are performed manually, which means there is a dependency on individuals, and a central point of failure.

Even when orders are executed properly, users still have to sign a transaction every time they want to place a new order. This may not be an issue for one-off transactions, but it starts to become a nuisance for frequent, recurring transactions.

The Programmatic Order Framework is built to address these problems.

The Programmatic Order Framework: A decentralized solution for automated orders

At its core, the Programmatic Order Framework brings simplicity to order creation by automating the boilerplate code necessary for order placement. This allows DeFi users to programmatically create any set of orders and automatically approve them for execution with just a single signature.

Users can create advanced order types (such as Stop Loss and TWAP orders), automate DAO payrolls, and create or destroy multiple orders with just one on-chain transaction. Thanks to a “WatchTower” relayer, orders built with the Programmatic Order Framework execute automatically whenever certain on-chain conditions are met, eliminating the need for tedious and repetitive signatures for programmatic actions.

The framework is a plug-and-play system that takes in order logic and executes orders in perpetuity based on on-chain conditions. Creating orders only requires coding the order logic itself. The rest of the swap components like order creation, order validation, signature validation, API calls, order placement, and order settlement are provided by the framework itself.

1-programmatic-order-framework.webp

The key unlock of the Programmatic Order Framework is the low cost of deploying, updating, and deleting orders in large quantities. Developers only need to write code specifying the particular type of order they’d like to execute and the framework takes care of everything else — storing the data, validating parameters, and placing orders.

The WatchTower relayer verifies that order conditions are met, validates the order signature, and places the order on behalf of the user’s smart contract. To make deploying Programmatic Orders easy, CoW Protocol runs a default WatchTower that users can route orders through. However, users can also run their own WatchTower instance for maximum privacy.

The all-in-one order automation kit

With the Programmatic Order Framework, a single signature can create hundreds of Programmatic Orders. The WatchTower monitors on-chain order conditions continuously and places orders whenever these conditions are met.

For example, a DAO with a diverse treasury can set up conditional orders for each token within its treasury. Based on these conditions, the framework may initiate a swap to rotate into stables when the treasury value rises above a certain threshold, or it may initiate a payout for DAO contractors on a given day of the month.

As the treasury receives various tokens, the framework executes trades accordingly, making DAO financial operations simple and automatic.

Benefits of the Programmatic Order Framework

The Programmatic Order Framework unlocks a world of convenience for individuals and on-chain organizations:

  • Leverage on-chain conditions: Build highly complex use-cases that rely on custom conditional order logic through the Programmatic Order Framework. Create orders that get picked up by the WatchTower on a certain date, once the balance of your contract or wallet is above a defined threshold, or based on other on-chain conditions
  • Deploy orders en masse: Create hundreds or even thousands of orders with a single on-chain transaction. Developers can also mass-update orders all at once with a single gas payment by simply updating the Merkle root with another transaction
  • Execute many orders in parallel: In a traditional smart contract wallet, orders execute sequentially. With the Programmatic Order Framework, the WatchTower monitors your orders and executes them as soon as the on-chain conditions are met, meaning you can execute many orders simultaneously

Most importantly, the framework is fully decentralized, providing 100% trustless execution with no intermediate contracts or centralized parties.

Examples & use-cases

With the Programmatic Order Framework, you can program a limitless number of use-cases:

  • Special order types: Gone are the days of centralized exchanges offering order types you can’t get in DeFi. Program intricate order types like stop-loss, good-after-time, and take-profit orders — plus many more. CoW Swap’s very own TWAP feature is built using the Programmatic Order Framework
  • Automated DAO operations: Blockchain-native organizations like DAOs process hundreds or even thousands of transactions every month. Thanks to the Programmatic Order Framework, your DAO can automate payroll, treasury diversification, fee collection, or any other type of repetitive transaction
  • Portfolio rebalancing: Set up order logic to programmatically rebalance assets based on a portfolio value. Automatically diversify based on market conditions or use custom logic to manage loan risk, farm yield, or hedge positions
  • Private conditional orders: Thanks to the framework’s support for private WatchTower configurations, traders can place highly complex conditional orders while simultaneously keeping them private. Buy and sell tokens through a recurring strategy while keeping your parameters hidden
  • Protocol integrations: The Programmatic Order Framework isn’t just for Safe! DeFi protocols can leverage its power to assist with recurring protocol-level transactions like loan liquidations
  • Easy transaction modules: Program custom functionality into any order type. Companies can build DAO tooling with a fraction of the complexity. Focus on building adoption rather than fiddling with backend tech

With just a few lines of code, the Programmatic Order Framework brings convenience and predictability to all types of DeFi actions.

What will you build, anon?

CoW Protocol is bringing Programmatic Orders to Ethereum through the Programmatic Order Framework. Create any order type you can imagine and deploy it instantly — all within the security of your own smart contract wallet.

The CoW Grants Program is also putting out a request for proposals relating to the Programmatic Order Framework. Have an idea for a solution built on top of the framework (especially one that includes a UI)? Submit a grant proposal!

The Programmatic Order Framework is now live. Read the documentation here to get started.

Have questions? The CoW Protocol team is here to help: join us on Discord or send us a Twitter DM.

About CoW DAO

CoW DAO is an open organization of developers, traders, market makers and many more community members aligned with its vision. CoW DAO is focused on fair and decentralized trading systems — in particular, building, maintaining and advancing the CoW Protocol. CoW Protocol technology powers a network of traders and solvers, enabling trustless and efficient peer-to-peer trading. Leveraging batch auctions as a key concept uniquely positions CoW Protocol as native trading infrastructure for discrete-time settlement layers like Ethereum and enables fair and accessible trading to its users.

🐦 Twitter| 📒 Documentation| 💬 Forum | 📊 Analytics | 📸 Snapshot