balancer decentralized finance defi market maker

DeFi Deep Dive - What is Balancer?

Written By Ivan on Tech

Aug 09, 2020

Balancer is an automated market maker (AMM) for multiple tokens. It enables portfolio owners to create Balancer Pools where traders can then trade against these pools. Balancer is still a relatively new liquidity provider (LP) in the decentralized finance (DeFi) space. It only launched in March 2020. 

Exchanges, whether they be centralized (CEX) or decentralized (DEX), exist to fulfill buy and sell orders. Their role is to find matches for a wide variety of orders from buyers and sellers so their orders can be executed. Traders rarely find the perfect match on the other side of a trade, so compromises have to be made. Hence, the need for market makers.

Market Makers

A traditional market maker is an individual or member firm of an exchange that buys and sells securities with the primary goal of profiting on the spread. Investopedia describes it this way: “Many market makers are brokerage houses that provide trading services for investors to keep financial markets liquid.”

Let’s say a buyer wants to sell 100 shares of Apple stock for $450 each on a traditional stock exchange. But a buyer on the other side of the trade wants to buy 100 shares for $440 each. If neither order is filled, the buyer may decide to go up to $445 and the seller may drop the price to meet the $445 offer. If they compromise, then 100 shares of stock can trade hands. 

With the law of supply and demand at work, when demand from buyers is low and the supply from sellers is high, sellers will have to make concessions if they want to sell. Likewise, when demand from buyers is high and the supply of sellers is low, buyers will have to compromise. After all, both parties want their orders filled quickly so long as they don’t have to give too much away on price.

Trading on the Ethereum Blockchain

The typical back-and-forth between buyers and sellers on traditional exchanges is relatively quick and inexpensive. As long as you don’t count all the upfront, time costs with registration, Know Your Customer (KYC) and Anti-Money Laundering (AML) forms. Not to mention the issues that surround handing over custody of funds. However, once a user sets up their trading account on a traditional exchange, things move relatively quickly.

Accommodating buyers and sellers on the Ethereum blockchain, however, brings about some new challenges. There are smart contract verifications that need to take place when matching up parties. It might take multiple price calls before settling which eats up gas fees.   

Automated Market Makers

Automated Market Makers (AMMs) brilliantly disrupt the traditional way buyers and sellers come together. Instead of two parties agreeing, traders can instead interact directly with a smart contract. 

Let’s repeat the same example above with some fictional Apple stock, except this time, we’ll throw in a smart contract. The smart contract will determine the price based on three variables, X, Y, and K. We’ll let X represent Apple and Y equal the U.S. dollar (USD). If one share of Apple equals $450 and one USD equals $1, then we’d have to supply 2 shares of Apple and 900 USD if we wanted to have an equal supply of $900. 

In this AMM, K = (X*Y), so K = (2*900) or 1,800  

So whether a buyer or seller deals with this AMM, they will swap Apple for USD (and vice versa) and the K will remain constant. To keep the value of K constant, the weight of Apple and USD must be adjusted with each trade. This is the kind of AMM Uniswap uses— a constant product market maker (CPMM).  

AMMs have existed ever since people figured out how to automate conventional trades. Algorithms that define the rules for trades control AMMs, but smart contracts on Ethereum have elevated the AMM. They can combine the custody of assets and the algorithms that decide how the assets will be traded. 

Balancer’s Constant Mean Market Maker (CMMM)

Balancer uses a more elaborate structure with its CMMM. That’s because it can utilize more than just two assets. So for three assets in a pool (Z being the third), the equation would look like this: 

(X*Y*Z)^(1/3) = K 

(The carat symbol ^ in math indicates raised to a power. So, 5^3 is 5 to the 3rd power.) 

The K stays constant so the weight of the 3 assets in the pool must adjust. Think of AMMs as a decentralized version of the traditional order book. 

Balancer Pools

As mentioned before, Balancer Pools can contain two or more tokens (up to 8 total). Each token carries an arbitrary weight that makes up the pool’s total value. Pools provide liquidity to the protocol and they earn money since traders must pay trading fees to trade.  

Balancer has three types of pools: Private Pools, Shared Pools, and Smart Pools. 

  1. Private Pools: 

Only one LP is in charge of the pool. 

  1. Shared Pools:

Anyone can add liquidity and the Balancer Pool Token (BPT) tracks ownership of this pool. 

  1. Smart Pools:

Like Shared Pools, anyone can add liquidity, and BPT tracks ownership. However, this pool is operated by a smart contract. This is a powerful feature of Balancer that allows the smart contract to readjust balances, weighting, and fees.  

Liquidity Providers and Traders

Pool owners are the LPs. They can create a pool to profit from trading fees. This is the same incentive Uniswap offers. The difference being that LPs on Balancer can create a pool with the ERC-20 tokens of their choice. 

On Balancer, LPs can create these “Balancer Pools” and traders can then trade against them. The pools provide liquidity and traders pay a trading fee directly to the pool LPs. These pools can be described as AMMs since users can trade between any two tokens in a pool.

Similar to Uniswap, two types of users can profit from Balancer: 

  1. LPs who own or participate in shared pools, and 
  2. Traders who use pools to trade.

How is Balancer Different?

Balancer possesses the same advantages as other DeFi protocols with no KYC or AML forms or registration required. Nor does a user need to give up custody of their funds. Balancer offers a decentralized version of the traditional world of finance except users can exchange tokens on-chain without bids/asks or order books. Some have described it as a self-balancing exchange-traded fund (ETF). 

Although the most efficient weights for two-token pools are 50/50, a user can supply up to eight tokens of unequal weights. For example, a three-token pool might consist of 40% DAI, 20% BAL, and 40% MKR.  

In true AMM fashion, the proportions within the pool will remain constant regardless of how these three tokens fluctuate in value. And there is no need for LPs to rebalance their portfolio themselves. They create the pool and let traders and arbitrageurs work their magic. Trading fees can range from .0001% to 10%.  

Who Can Profit on Balancer?

Balancer works for LPs who own Balancer Pools and traders who seek to profit from these pools, including:

  1. Arbitrageurs seeking to profit off the market inefficiencies between Balancer and other exchanges.
  2. Portfolio managers who want exposure to different assets without undertaking complex rebalancing actions.
  3. Hodlers who have ERC-20 tokens sitting idly.
  4. Ethereum Smart Contracts seeking liquidity.

Balancer Governance Token

With the release of the Balancer Protocol Governance Token (BAL), LPs, and traders are incentivized to participate in the future direction of the protocol. Any disputable concerns will go to the token holders for review.  

DEXs are experiencing higher usage and many (like Uniswap and Balancer) incentivize LPs by offering trading fees. With the launch of BAL and COMP (which is Compound’s governance token), this trend has only accelerated along with the growth of Yield Farming. Protocols that have decided to remain “tokenless” are missing out on this profit center.

LPs receive BAL tokens each week based on the amount of liquidity they have provided. So, the more liquidity supplied, the more tokens they can earn. The token wasn’t designed to be a speculative asset, but it is an attractive incentive to onboard new users.

Balancer vs. Kyber, Curve, and Uniswap 

The battle between DEXs has grown hotter with increasing competition. Balancer is similar to Curve, Uniswap, and others in that they each offer their version of the AMM. AMMs are attracting the most attention and DEX volume for now. Balancer may just need to refine its incentives to better compete with the likes of Curve, Uniswap, and Kyber.

For now, Balancer can offer better rates for stablecoin pairs than Uniswap and has better liquidity. Uniswap wins the slippage battle and has better liquidity for nearly all the ERC-20 tokens excluding stablecoins. This may not be the case if yield farming slows down, but for now, the rates for stablecoin pairs are better.

Some worry that Balancer still struggles with volume even with their impressive liquidity. Questions have been raised as to why the liquidity factor hasn’t translated to higher usage yet. But things can change fast in DeFi. 

The Balancer Hack

Unfortunately, Balancer got hacked very early in its existence. Only four months after its launch, a sophisticated engineer with some serious smart-contract skills exploited the protocol for approximately $500k. The hacker utilized his knowledge of ERC-20 tokens, deflationary assets, and Flash Loans to pull off the heist. 

Specifically, the hacker used a Flash Loan from dYdX and the Statera (STA) deflationary token. We’ve discussed Flash Loans on Aave before. Flash Loans allow users access to huge amounts of capital with no collateral so long as they can pay it within the same transaction. 

STA tokens are deflationary because 1% of each transaction is destroyed. And STA hodlers prefer yield farming platforms like Balancer so there was STA in a pool. The pool that caused the problems for Balancer was equally weighted with STA, SNX, LINK, WETH, and WBTC.

So, the attacker took out approximately 104,000 WETH ($23 million) in a Flash Loan from dYdX and promptly swapped it back-and-forth for STA multiple times. Since each transaction burned 1% of the STA, the amount of WETH grew exponentially. 

Understanding Liquidity Pools

Why is this? Well, think about Balancer’s CMMM that we discussed above. The K remains constant in the equation, right? With multiple swaps involving STA, the Balancer’s AMM should have accounted for the diminishing STA (1% for each trade). But it didn’t, and the hacker knew it didn’t. Balancer only recorded the STA token transfers, not its deflationary aspects.

With superior knowledge of Balancer’s pools, the hacker figured out how to throw its numbers off. He then proceeded to drain the remainder of the tokens in the pool. The sad thing is, a bug bounty had been previously submitted by the Twitter handle, “Hex Capital.” The bug bounty request warned of this very possibility with the STA token. The warning went unheeded. 

However, once the dust cleared, Balancer did promise to reimburse those who lost funds in the pool as well as to pay for the previously ignored bug bounty. And the team will certainly be nervous about whitelisting any deflationary tokens (at least in the short run). Sometimes though bad things should happen to a company early on rather than later. It will make them all more security conscious and by the time DeFi kicks off with the next bull run, most will have forgotten about it.  

The Future of Balancer

We must not forget that Balancer only launched back in March 2020, so the growth it has experienced is quite impressive despite any shortcomings. It is one of the more complex projects out there, but that has not stopped its growing popularity. 

In its short existence, Balancer has already clipped Curve Finance for the #1 spot for DEXs (at the time of writing). DeFi Pulse shows the Total Value Locked (TVL) at $263 million. One has to wonder if that number would be higher were it not for the hack (see below) that took place?

Even with its complexity, Balancer offers a sleek UI. It may not be the best place for a novice to start, but the process of becoming an LP is quite easy for anyone acquainted with the DeFi space. 

While these kinds of exploits described previously are never encouraged, they nonetheless point out the profit potential of DeFi protocols. Those with knowledge can profit immensely. And it's always better to learn how to profit honestly. 

To further your education in Balancer and other DeFi protocols, visit Ivan on Tech Academy and check out the DeFi 101 and DeFi 201 courses. Ivan on Tech Academy is one of the premier platforms for blockchain courses and offers a wealth of content for anyone looking to learn more about crypto and blockchain.

Author: MindFrac

Like what you're reading?

Get to work in a fast growing industry. Start learning blockchain together with our 20,000+ students today.
Use coupon code BLOG20 for 20% off.

Become Blockchain Certified Today No Prior Knowledge Needed!
Close

Get our Free Ebook

Enter your email and we will send it to you!