Open sourcing Veil.js and Veil smart contracts

Today, we’re announcing the release of Veil.js and the Veil smart contracts. Veil.js is a Typescript/Javascript library that acts as a thin wrapper over our HTTP API. Veil smarts contracts include Veil Ether and Veil’s Virtual Augur Shares template, two smart contracts that we’ve built to improve the experience of onboarding and trading on Veil.

Veil.js

Until now, the only way to interact with Veil markets is through our web app. With the release of Veil.js, we’re allowing developers to start experimenting with automated Veil trading and analytics. The library allows you to list and filter markets, view order books and trade history, and create and cancel your own orders.

We’ve been using Veil.js internally for a few weeks to run our own experimental trading bots, and we’re excited to let others do the same.

We hope to foster a community of hackers and traders who come up with clever ways of visualizing, market making, and trading on Veil markets. Some of our markets represent totally new products (memes or gas prices, for example), and we’re excited to see what strategies and tools the community builds on top of them.

Veil smart contracts: Veil Ether and Virtual Augur Shares

In addition to Veil.js, we’re open sourcing the smart contracts for Veil Ether and our Virtual Augur Shares template.

Veil uses 0x to let people trade shares in Augur markets, meaning users can immediately create orders without sending Ethereum transactions. Unfortunately it requires two awkward steps before users can trade:

  1. They need to wrap their ETH and approve it for trading with 0x.
  2. For every token they trade, they need to approve a 0x smart contract to control their balance of that token.

From the user’s perspective, both steps are tough to understand (e.g. “why do I need to wrap my ETH?”) and scary (e.g. “am I putting 1.158e+59 shares at risk?”). And both steps require at least one Ethereum transaction, which is slow and expensive.

The Veil smart contracts are designed to streamline Veil’s UX by removing the extra unlocking transaction. Veil Ether (view on Etherscan) is a fork of WETH with a custom depositAndApprove function that lets users deposit ETH and set an allowance in a single transaction. This means that once you’ve wrapped your ETH into Veil Ether, there’s no need to approve it for trading on 0x.

The second step, unlocking tokens, poses a bigger challenge for Augur shares. Each market on Veil (and Augur more generally) introduces at least two new ERC-20 tokens — one for each outcome. For a user to trade or redeem their shares in those new markets, they’ll need to unlock both tokens. If a user trades on 10–20 markets, as many of our users do, then they’re faced with an additional 20–40 Ethereum transactions. Obviously, at some point this becomes untenable, and it’s a bad user experience.

To let users skip all of these transactions, we’ve built Virtual Augur Shares, a template for ERC-20 tokens that wrap Augur shares and approve them for trading on 0x. Each Virtual Augur Share is redeemable for a share in a specific Augur token, just like WETH is redeemable for ETH. And by default Virtual Augur Shares are pre-approved for trading on 0x, so users do not have to submit a second approve transaction.

All new Veil markets will use these virtual shares by default, so you won’t see an “Unlock” button on markets created after today. The experience of trading on Veil otherwise remains the same. We hope that by cutting out this step, we make it both simpler and cheaper to trade on Veil.

Wrapping things up

In the upcoming weeks, we’ll be iterating on these repositories based on user feedback and our experience developing on them. For veil-js, we’ll be finalizing the underlying HTTP API and releasing the API documentation. For veil-contracts, we’ll be trying to find more efficient ways of managing Virtual Augur Shares (a promising candidate is ERC-1155).

As always, we welcome all feedback about both of these projects. You can follow our progress on GitHub, drop us an email or message us on Discord.

Finally, we want to thank Tom and Amir from 0x for their guidance and feedback, especially in developing the Veil smart contracts.