How Bancor Relays Work14th April 2019
Although the Bancor Protocol is unique, you don’t need a degree in quantum computing to understand it. The protocol introduces a new standard for enabling liquidity between tokens through a network of interconnected smart contracts. Each contract, known as a Bancor “relay”, acts as an on-chain liquidity pool that performs pricing and conversions between any integrated token in the network, with predetermined and foreseeable terms.
Traditional exchanges work by matching buy and sell orders in a bid/ask system using order books or a matching engine to fulfil trades. When there are enough buyers and sellers of a token, this system generally works well; however, it assumes a given level of volume and interest in a token. If a token has low volume at any time, it not only becomes difficult to buy or sell, but individual transactions can cause unpredictable price swings, reducing a token’s usability and adoption.
Because relays don’t rely on matching buyers and sellers, and instead use on-chain “reserves” as always-available liquidity pools, they have the potential to remove a token’s dependency on trade volume and ensure constant liquidity for tokens. Even low-volume tokens can offer frictionless conversions for their users — in their earliest days or during periods of decreased volume.
In order to understand how relays work, let’s first consider a thought experiment. Imagine you had to find the fair market value of watermelons priced in terms of grapes. How many grapes equal one watermelon? Cryptocurrency markets face similar issues when converting between tokens. Bancor Protocol suggests a solution for price discovery and token liquidity through the use of relays.
Relays are programmed to receive and dispense tokens according to a predetermined formula which continuously measures the supply of tokens staked to the network. To achieve this functionality, a relay maintains two token “reserves”, each holding a specific type of token. Relays adjust the prices of each token in terms of the other, in order to maintain a fixed 50/50 ratio between the two reserves.
For example, a relay created with watermelon tokens and grape tokens will allow a user to sell a watermelon to the relay and receive grapes in return. Such a transaction would add a watermelon to the relay’s watermelon reserve, and withdraw grapes from the relay’s grape reserve. In order for the relay to maintain its 50/50 reserve ratio, the relay rebalances prices to decrease the price of the sold token (watermelons) and increase the price of the purchased token (grapes). This continuous rebalancing is designed to reflect real-time supply and demand for watermelons and grapes in the network.
Here’s a quick video by EOS Weekly explaining this process:
That time @eosweekly used watermelons & grapes to explain the Bancor Protocol & automated liquidity. 🍉🍇 Full Video: https://t.co/ZnaT7FxBhq #DeFi #Tokens https://t.co/ElzavqYOqB
The amount of liquidity staked in a relay (a metric known as “liquidity depth”) depends on how much the liquidity provider deposits in the smart contract. If a user performs a large conversion relative to a token’s liquidity depth, the conversion will cause the price of the desired token to move as the conversion is processed, also known as price “slippage”. While slippage is expected in nearly every token conversion (albeit in infinitesimally small amounts for highly liquid tokens), a unique characteristic of Bancor relays is that they pre-calculate a token’s slippage prior to a user submitting a conversion, giving users the ability to see how much of an asset they’ll receive for any conversion with far greater accuracy compared to solutions based on order-matching.
Relays are just one implementation of the Bancor Protocol, characterized by their fixed 50/50 reserve ratio. Upcoming blog posts will explore additional implementations of the protocol with different and dynamic reserve ratios. Reserve functions can be designed to favor certain market behaviors or promote certain economic incentives.
A “liquidity network” emerges when there are two or more relays connected to one another by holding the same token in one of their reserves. Through transference, if one relay holds tokens A and B, and another relay holds B and C, token A becomes convertible for token C via token B. Liquidity networks allow integrated tokens to be autonomously convertible for one another without the need for a central entity, across an unaffiliated and unlimited community of network users.
Today more than 140 relays form the Bancor Network, with each relay funded by an independent “liquidity provider” who serves as a node in the network . To set up a relay on the Bancor Network, a liquidity provider stakes an amount of one type of token (ERC20 or EOS-based) along with Bancor’s Network Token (BNT) in a smart contract. BNT is the mechanism through which relays connect in Bancor’s liquidity network, automating on-chain convertibility across 1000s of live token pairs, including cross-blockchain conversions. Until now, liquidity providers have collectively staked over $12.7M in ERC20 and EOS tokens to the Bancor Network.
The figure below shows a simple implementation of a liquidity network consisting of only two Bancor relays (Token A and Token B), where the price of each token as well as BNT is set to $1:
Token A is converted into Token B by:
- Sending one Token A to Token A Relay, increasing the Token A supply in the Relay to 11 As.
- Token A Relay sends one BNT, decreasing the supply of BNT to 9 BNTs.
- This creates an imbalanced Relay. To balance it, the Relay decreases the price of the sold Token A — setting its price using the Relay’s new token balances 9(BNT)/11(A) or $0.81.
- The withdrawn BNT is automatically sent to the Token B Relay, which increases the supply of BNT inside the Token B relay to 11 BNTs.
- Token B relay sends one Token B to the user, which decreases Token B supply to 9Bs.
- This once again creates an imbalanced relay. To balance it, the relay increases the price of the purchased Token B to 11(BNT)/9(B) or $1.22.
As shown above, tokens on Bancor increase their price when they are purchased and decrease when they are sold, so users know they are always getting a fair price based on real-time token supply and demand.
Since its creation in 2017, Bancor Protocol has enabled billions in conversions for tokens of all sizes, providing automated liquidity through an open and decentralized protocol — similar to how protocols like HTTPS and SMTP unlocked open access to Internet and email services.
Using relays, the Bancor Protocol reimagines asset conversions from a human-mediated process to an automated process that occurs fully on the blockchain between a user and a smart contract. In the future, any user will be able to add a token to the Bancor Network via self-service functionality, allowing even crypto beginners to create instantly liquid tokens and tokenize new kinds of online ecosystems — without worrying about creating enough volume or securing listings to ensure liquidity from day one.
About The Bancor Protocol
Bancor is an on-chain liquidity protocol revolutionizing the way people create and share value by enabling constant convertibility between tokens. Conversions via Bancor Protocol are executed against on-chain liquidity pools using automated market makers to price and process transactions without order books or counterparties, allowing for faster, cheaper and more predictable conversions across 9700+ ERC20 and EOS token pairs, including non-custodial conversions between blockchains.
How to get involved with Bancor
- Add your token to the Bancor Network.
- Checkout Github, jump in and contribute code.
- Build a dApp with the Bancor APIs.
- Support us on social media.
- Join our team. We have new positions posting all the time.
How Bancor Relays Work was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.