What if 0x could be used for decentralised real-time bidding advertising?
A look into ZEIP18 and the opportunities it opens up by allowing orders to be funnelled through external contracts.
🚨 This is a crude post. Ideas are presented raw to be killed early or stolen quickly.

There has been a lot of talk on crypto collectibles becoming “the application of 2018" for decentralised networks. Media distribution businesses are also in a frenzy, many believing this is the year when GAFA begins to fail, and distributed alternatives enter the mainstream.
Another increasingly promising field, and the one we’ll be looking into here, is that of decentralised exchanging. 0x, one of the most used DEX protocols, has seen a staggering growth of developer activity in its ecosystem, with a dozen relayers being actively worked on and some turning profits already. The emphasis of the project on open governance seems to be yielding fruits: ZeroX Improvement Proposals, or ZEIPs, are working smoothly since the network has launched, with a lot new tweaks and features in sight. Here, we’ll explore the possibilities opened up by one of this proposals.
0x protocol

0x is a building block for decentralised exchanging. The protocol defines a message format for orders (as in an order book), to be signed and communicated off-chain. But no one would have reason to “listen to”, or to collect such orders, unless they can earn something with it. That’s where Exchange.sol comes into place. This contract can receive orders “injected” into it by any party, and execute one against another, on-chain, atomically. It is a simple contract and can only fill or cancel orders.
One can make point-to-point orders (in case the counter party is already known, and there is no need to find liquidity)… or, otherwise, broadcast orders that don’t previously specify a counter party and can be picked up by an agent willing to find matches for them.
Makers, Takers and Relayers
In 0x terminology, the maker is the agent who makes an ask order, and the taker is the agent which makes a bid order.

Relayers, in turn, can be seen as “robots” that listen to such orders and aggregate them into order books. They compete in providing liquidity to traders, by running flexible matching strategies (which may include batchFilling of orders, for example), pairing compatible ask-bid orders and injecting them into 0x’s exchange contract. Relayers do this in exchange for a fee, usually charged upon the taker. This scheme originated the expression “off-chain order relay with on chain settlement”, commonly used to the describe the type of protocol 0x conforms to.
A relayer can maintain, on its own, a friendly interface imitating an actual centralised exchange order book (e.g. Radar Relay); they can focus on APIs for providing liquidity specifically to dApps that need multiple tokens to operate (e.g. Amadeus); they can even adopt models or tackle niches we’re not aware of, yet.
ZEIP18: decoupling agents for increased flexibility
ZEIP18 was put forth in the last day of 2017, and is still under discussion. It’s final aim is to allow orders to be funnelled through pipelines of custom logic.
The basic proposal is to decouple the taker of an order from its msg.sender (in the current implementation, the taker is always the sender), by allowing the signature of the taker to be passed into fillOrder.
What’s interesting is that a trader can also set the taker field as the address of an Externally Owned Account - a smart contract - that will be required to execute the order. This contract can be then used to implement arbitrarily complex processes, while maintaining a clean distinction from the protocol’s core contract and components.

Some of the things one could do through such mechanics are (ideas come from Will Warren):
- Creating orders that can only be filled by addresses in a whitelist, or with a signature from another party.
- “Funnel orders through a contract that eliminates front-running and trade collisions by enforcing rules around trade execution”.
- “Funnel orders through a contract that allows a network of “wranglers” to liquidate a trader’s margin position if it falls below its collateral requirement, per the rate provided by a trusted price oracle”.
But what if we could use this EOA to enforce non-financial logic? Suppose that, in order for the taker to pass in his signature and fill the order on Exchange.sol, he first has to receive a signature himself, and one that proves not only identity but also the fact that its issuer has received and hashed a unique piece of data?
A decentralised RTB-driven ad-delivery network
Let’s consider the following case: an internet user browses to a random page that displays advertising right on the spot. A cookie sends user and contextual information to a labyrinthian supply chain and, after some milliseconds, an advertiser’s bid has already been matched with your profile, probably by a demand-side platform (which means your attention has been bought for some pennies), and an ugly banner comes to life in the screen.

That’s a rough summary of the process that actually takes place. The machinery in between is monstrous, in reality. Traffic data is aggregated by supply-side platforms (SSPs); processed by data management platforms (DMPs); impressions are put for sale on exchanges; bids for them come in through demand-side platforms (DSPs); originally sent by agencies. In most cases, the publisher is responsible for ensuring the ad has been delivered.
This logistic allows for precise user segmentation and near-instant trades. However, it doesn’t really optimise for price (with all those intermediaries to feed), and the data it shuffles around is not fully auditable, since it travels between a number of closed silos. You have widespread liquidity, but no global accountability. Also noteworthy, the process is twofold: a payment happens, then an ad is delivered. The execution of both is not atomic by design (we’ll see below how it could potentially be).
The idea here is to try abstracting this labyrinthian “exchange mechanism” through 0x, placing its execution in the hands of relayers.







