Unipay: Token-to-Token Payments Using Uniswap

Vic Woeltjen
@thebeetoken
Published in
4 min readFeb 25, 2019

We’d been stuck at the bridge for hours. The troll wanted gold.

We had silver. We had gems. We had precious artwork, rare textiles, fine cheese. But the troll wanted gold, and so all the value we’d fought to find in the world meant nothing, just then.

Finally, someone had an idea:

“Feed it to the unicorn.”

What goes into a unicorn? What you’ve got. What comes out? What you wish!

A squirrel wishes to find nuts, and so what comes out of a unicorn, to a squirrel, is nuts.

A bee wishes to find pollen, and so what comes out of a unicorn, to a bee, is pollen.

A troll wishes to find gold.

After building a marketplace around a utility token, we quickly encountered a (predictable) problem: Who owns our token? We rapidly found that the circulation created by our token sale was smaller than the base of consumers we wanted to reach. Exchanges are confusing. The whole model is new. The pain of acquiring tokens blocked their use.

Clearly, we needed a unicorn.

Uniswap is presently seeking a more unicorn-themed logo.

Enter Uniswap: “A protocol for automated token exchange on Ethereum.” Uniswap provides liquidity pooling for ERC-20 tokens, abiding by the Constant Product Market Maker Model in determining exchange amounts.

What does the Constant Product Market Maker Model look like?

x × y = k

All this asserts is that the product of two variables, x and y, remains constant, k.

In a Uniswap pool, x measures the quantity of pooled ether and y measures the quantity of pooled ERC-20 tokens. A smart contract holds the ether and tokens, and permits swaps which maintain the constant relationship of their product. (To encourage the pooling of liquidity, stakers are allocated a 0.3% fee per swap.)

(x + 𝚫x) × (y + 𝚫y) = k

Consequently, Uniswap provides heterogeneous liquidity at self-adjusting exchange rates.

The guests we’re trying to reach aren’t interested in swapping tokens, though; they want to book travel! Sending customers off to an exchange (Uniswap or otherwise) is just not viable.

And so we introduced Unipay. The goal of Unipay is simple: Allow buyers and sellers to transact transparently in their preferred token.

This is not such a new idea; credit cards and other payment processors already handle currency conversion as a matter of course. Unipay introduces this capability to the ERC-20 token ecosystem, and it does so in a trustless, auditable way, end-to-end.

Payments with ERC-20 tokens most often take the form of an approve call: A token holder grants permission to an address (usually a contract) to withdraw some amount of tokens, and then the payment system uses that approval to handle the rest.

The technical realization of transparent token conversion should, then, adhere to the same pattern: The purchaser makes an approve call, and the payment handler sees an approve call. However, this approval needs to occur on two different tokens.

Unipay bridges this gap. Specifically, Unipay is a smart contract which withdraws an approved amount of tokens from a purchaser, uses Uniswap to exchange those tokens for our preferred token, and then approves the withdrawal of those tokens by our Payments contract. Payment via ether is handled similarly, for the most part. There is no equivalent to an approve call with ether, so instead funds are directly transferred by the purchaser and then converted to tokens for withdrawal.

We’re now accepting DAI at Beenest using Unipay, and adding support for more tokens will be as simple as updating our user interface to provide those options.

Does your organization have a token? Would you like to use that token to book your organization’s travel? Get in touch with us! We can make that happen: We’ll just put it in the unicorn. We know we’re going to like what comes out in the end.

Developers: Check out the source code for Unipay on Github.

--

--

Vic Woeltjen
@thebeetoken

Computer scientist engineering decision systems.