How to Use Balancer - Token Swaps & Pool Management [Detailed Tutorial]

How to Use Balancer - Token Swaps & Pool Management [Detailed Tutorial]

By D3F1 | DeFi Box | 14 Jul 2020


In this Tutorial, I want to provide a very intricate understanding of how to use the entire Balancer platform.

Balancer is the recent DeFi player in the Automated Market Maker (AMM) category. 

Balancer is slightly different from your typical AMMs as it is a non-custodial automated portfolio manager. It allows anybody to come and provide liquidity to existing liquidity pools or even create one themselves (we will do both today!).

The unique thing about Balancer is the fact that you can create liquidity pools made up of 2 to 8 tokens (Unlike Uniswap, where a 50%/50% token ratio needs to be maintained. The technology behind Balancer ensures that the set percentage values of each token stick to the assigned weight by trading them between each other.

By the end of this tutorial, I hope you will be able to conduct a token swap on the Balancer Exchange, add liquidity to an existing shared pool, and set your very own shared liquidity pool up.

Your First Token Swap on Balancer Exchange

The absolute first thing that you must do is install either MetaMask (or WalletConnect) to use as a wallet during this entire process. I will be using MetaMask and will be starting with 1.2 ETH;

8f7996d0197b10ee3800560f55c724149f11eeee959bd227182f6b7a15809011.png

Next, we head over to the Balancer Exchange platform homepage and connect our MetaMask (or WalletConnect) to the platform. Go ahead and click “connect wallet”’;

c06da51df518f4b926569751b13c331df7db4c63d8aac9b88b31a2c972e51ca7.png

You will see the following screen to connect your wallet;

ea4da05444a95694c816b7399a6ac0a78ef4deb56c09de7fd01b3d8d25b7cfbf.png

I am using MetaMask in this post, but I am pretty sure that WalletConnect should work just as well. 

You will know that you have successfully connected your wallet if you see something like this in the top right-hand corner;

9b8f88e97212526b715869910125d5d5b529f7d90e3d06f28d8dd931e7b57a48.png

So, the entire idea of this part of my post is to show you how to actually make your first token swap. 

Let’s go ahead and do that right now. 

On the homepage for the Balancer.Exchange, you should see this following box;

fab3953e69da90bce8513edaaa42574c0a60ec7154fd14f0583f269fecee62dc.png

This is the section where you can convert tokens between each other through the Balancer protocol. The left-hand box is the token that I currently possess and would like to sell whilst the right-hand box shows the token that I am looking to buy.

Let’s start by buying some DAI. To buy the DAI I will be selling ETH and, therefore, select ETH as the token to sell and DAI as the token to buy. You can see that I have entered .12 ETH which gives us a total of 27.58 DAI in exchange.

Right now, the exchange rate for 1 ETH is around 230 DAI. So for 30 DAI, a total of 0.13 ETH is required;

ffb22556f133810931a3cd0a950fa4c6516d30459709560e5bd779cc81049fad.png

Let’s go ahead and hit swap to conduct the swap.

457b610f66fa90aa8879879e1631f6afea8a482a6f8e0764246a2a863ce57a49.png

After clicking swap, another window with your MetaMask wallet should pop up;

891f5c872afb787e4230bef49a6b83b9d03a8cf8a0f56b617d0c6cb57a93c204.png

You can see that the GAS fee is quite high right now at $1.84. Don’t worry, it is not typically this high. I am sure that the network was just fairly busy when I was doing the transaction. Furthermore, fees will be significantly lower when Ethereum switches to ETH 2.0.

The total for the DAI with the GAS fee on top comes to $33.76. Go ahead and press confirm. 

After confirming, you will see that the transaction is occurring on the top-right hand side of the Balance Exchange platform screen.

917a93aa558d5c5a41ed4d1f9d4ed2a7eb09f9fe9b332a376db01fbc06ae7278.png

This shows that your transaction is occurring right now on-chain. You can actually head into your MetaMask wallet and see that a transaction has occurred and is waiting for a number of confirmations. It might take a few minutes for this transaction to be confirmed depending on how busy the Ethereum network is at the time but usually it should be done in under a minute.

Once the transaction has been confirmed, you will see the following after clicking your wallet at the top right-hand side of the screen;

180a0da3e6ba76a161517856a77071ecf294687da2ad3379493cf2ce50ff91a2.png

Congratulations! You have successfully made your first token swap on Balancer. You can go to your MetaMask wallet and confirm that the 30 DAI that we purchased has actually gone to our wallet;

149874239749ca2a2714d31e66a10704caade9ba2bd640f4b88245373d109867.png

Joining a Shared Pool

The entire idea of this next section is to join a Shared Pool on the Balancer Protocol. This will allow us to invest in user-created pools that have a custom percentage distribution of value. 

Each balancer Shared Pool can simply be thought of as a self-balancing index fund, only, the liquidity providers are rewarded each time the pool is rebalanced. 

To join up to a Shared Pool we need to head to the Pool management page. You should see the following screen;

e5507813743f74bd3c9820b828615e80e4e3dee9392ea7fa55dee5dc584c0731.png

Let me break all of this down for you;

944fdc138438d6fe417d0eb8a99ab73e55281847a2dd1c22d5935dd395988382.png

a - this lets you switch between Shared and Private pools.

b - this shows you the liquidity you have in shared pools, currently, I have nothing and nor should you.

c - this section allows you to ‘wrap’ ETH. Wrapping ETH is important because it allows WETH to directly communicate inside the smart contract and ERC-20 tokens inside it.

d - this shows you your current holdings.

e - this is a list of all of the different Shared Pools that you can join to. It shows the different Assets that are in the pool, the fee, liquidity (total value in the Shared Pool), and the past 24hr Trade Volume.

For this tutorial, I will be adding to the pool with the second-largest liquidity;

6b8f2aa35e207f72c886864c49739af95d6a68ca1eba30353d3db34ead64be04.png

You can see that this pool requires a distribution of 75% MKR and 25% WETH. We can also see other details for this pool such as the fact that the swapping fee is 0.2% and there is over $6.5 million worth of liquidity here. Let us add liquidity to this pool by clicking on it. You should then see the following screen;

1afd52b21533fad8b0024910b73fd3f22af278bea364edb865b924e7805e3964.png

This shows the stats for the pool. We can see that there is over $6.5 million worth of liquidity in this pool. Let us g ahead and add some liquidity to this pool. Click “add liquidity”.

You might be directed to the following screen to set up a proxy contract to manage liquidity on Balancer;

7c4023f43a4704c2e8920b5d305d1068c426a3622c71a5d21095ff8d066caba5.png

Go ahead and click “Setup”. Your MetaMask wallet should open again asking you to confirm a transaction;

5874aebd90aba7ab63123bda13cc3f2b50416f9a127e0d8f5593a0ea76778d78.png

We can see that the GAS fee is still quite high. Go ahead and click confirm. You should see another transaction appearing in your MetaMask wallet page to confirm that it is signed and waiting for 10 confirmations;

5c6958946fe3ccfe8bc8ef8cda718172b189a2e4325740951f835c35fd3f3f55.png

Once 10 confirmations have passed, you can go ahead and click add liquidity again on the Shared Pool page that we will be adding liquidity to;

1afd52b21533fad8b0024910b73fd3f22af278bea364edb865b924e7805e3964.png

You should see the following screen;

85c07f387af9123fcd1cd4a86383bb55f29fa07693dfe6a4553d78f68a0b7c8f.png

It shows the pool overview and the coins that are associated with the Shared Pool. Here, we can see that there is both MKR and WETH and I have neither coins so the first thing I need to do is pick up some MKR and wrap some ETH.

We can see that the split is 75% MKR to 25% ETH. This means that if I was adding $100 worth of liquidity, I would need $75 worth of MKR and $25 worth of WETH. 

You can buy your MKR and wrap your ETH anywhere you wish, but I will go ahead and exchange some ETH for MKR and wrap ETH directly on the Balance platform.

Firstly, I need MKR. I headed back to the Balancer Exchange page and entered 0.28 MKR into the swap section and we can see that it cost a total of 0.6535 ETH;

c64c90598705100439073858cff5e3476356bd9d41822322f18f96112fbf11ee.png

Go ahead and click swap. A MetaMask window should open again to confirm the transaction from your wallet;

193562da9458c02a48ecfefdc1a68022367505cb2b8c1b97a3b0920e3b6bfd91.png

We can see that the total cost for this swap is $154 with $1.60 worth of fees (prices are coming down quickly!).

Once the swap has been completed on-chain, you will see the MKR in your MetaMask wallet. You can see that I have .280 MKR;

b1ccf26dd2bc5e3bd428ab2c961c444a650964bbdd2627f8c5b7f456d5c6b2af.png

Next, it is time to wrap some ETH. We need around 0.22 ETH to get around $50 in WETH. Head over to the pool management page again. In the ETH wrap section of the platform (section c from above) I entered 0.225 ETH to wrap and clicked WRAP;

fc802b4a44491c55f4e9b3b5fa2981d58de6f3dfa05803c1dbddb371ad4758db.png

As always, a MetaMask window appeared asking me to confirm the transaction;

1c0332156bb6e8361ace3f153ce0713e930f149159e8aaa371a1bab442ac6c96.png

We can see that the total value of the wrap is $52.35 and the cost for the GAS has dropped right down to $0.30. These are the typical fees you can expect when using Ethereum, not the $5 fees we saw before.

If everything has gone correctly, you will see the MKR and the WETH in the “My Wallet” section on the pool management page;

9144f353f06f2c379c53504c841d96f6b23eeac8c0bd560d1eae5fa77c7a2546.png

You can see that I have ETH, WETH, DAI, and MKR. 

Time to put the WETH and MKR to good use!

Head back over to the “add liquidity” page on the Shared Pool;

eb1b1af03c57195112bb8fd2642a808bb263699e68f928d91b8503d4eef92d32.png

You will notice that you have to unlock both the MKR and WETH wallet. Hit the “unlock” button next to MKR.

You will be presented with another MetaMask confirmation request;

4b6cfcb9798c5eb09b9021077dd344fb5b4d3eb3610887f9e8cbffbefbdfc6c5.png

Hit confirm and do the same for the WETH wallet.

Once both transactions have confirmed, you can head back and add liquidity to the shared pool. Simply click the “Max” for the MKR Deposit Amount and it will automatically calculate what the maximum is you can deposit according to your balance;

42dcc8e78e3a8b33785a67896814d8677c347dbf23f9591367cc38e58b01a89f.png

You can see that I can deposit a total of 0.28 MKR and 0.217 WETH. Go ahead and click “Add Liquidity” and click confirm on the following MetMask notification;

20e89cd5c3b70c7bebbcc07d8c0ac079482a110a208a019c44d2f27a09e26ae4.png

You now must wait for the transaction to be confirmed;

a7d66462b31efbd8b3529bdd7cc953a5710396fe6c33a53735dadaf847795c8f.png

Once this transaction has confirmed, you will see that you will have your corresponding balance on the Shared Pool page;

3f96ce14b212653c9139d23e3f3f7018b44f1ae72d9b45ca982320171637b38e.png

You will also notice that your WETH and MKR balance has dropped;

ccd927b7b003aaee13044e5bcdbd19a9a6565f9e922fda0bd589206e43654afb.png

Furthermore, you will also see your new corresponding balance in ‘section b’ of the Balancer Pools Management page;

66badf8b6e025f59fa1dc44c3f29dd660bd222b1652fe1757cb823b6cb3245c6.png

All of this confirms that you have successfully added liquidity to a Shared Pool. 

Congratulations!

Removing Liquidity From a Pool 

Now that you know how to add liquidity to a Shared Pool, it’s now time to learn how to actually remove your liquidity from the pool if you ever need it. 

The process is quite simple.

First, just head over to the specific Shared Pool page that you would like to remove liquidity from and click “Remove Liquidity”;

b2aca0d565d9cbd3234d04243dd27a29e31b4611a4021fa02881e0c2f200eb7c.png

You should see the following screen;

60f7de09df7b38be267d039609eaaa32f0685db3a0ac19e14ff2e7de8264b4b0.png

This screen allows you to remove a specific percentage of liquidity from the Shared Pool. You can enter whatever percentage of the total liquidity you have in the pool and hit “remove liquidity” to remove the liquidity from the pool.

In this example, I will remove 75% of the liquidity from the pool. This means that I will be withdrawing a total of 75% from the entire liquidity which is split between MKR and WETH. I enter 75% and hit “Remove Liquidity” and hit confirm on the MetaMask request screen;

a7a656b581130c955d258230848f5c565012210dfd3f1026c696fc2fc489d14a.png

After the transaction is confirmed, you will see that the percentage of the liquidity you removed have returned as coins in your MetaMask wallet;

6c319b18a55e6db705d06fa804ce24d149a219fda6568821791441daac42c04f.png

That is all there is to it!

Creating Your Own Liquidity Pool 

Now you know how to swap tokens, add liquidity to a pool, and remove liquidity to a pool it is now time to learn how to set up your own liquidity pool which is what this next section is all about!

This can get quite technical but, overall, it is fairly easy if you follow this tutorial step-by-step.

Head over to the Pools Management page and click “create pool”;

073390d019b656d44d15f816ada6b09cc744d64d9c1f7b970f09fa5abd0be9bd.png

You should see the following screen;

5d8d9631ed12453d2a01ec5b341935059c097086ae19ea5ba2884db2f025f90a.png

This page allows you to set up your Shared Pool by selecting which tokens you would like in the pool along with their assigned weight and the total swap fee. 

Personally, I’m a big fan of ETH, BAT, and LRC so I will use these three coins in my self balancing pool - with WETH having a weight of 50% and LRC and BAT having 25% each;

0dcf0084bb8066ccbca0b946a7e83bf5dad275799c51bfee0457250decbdfff6.png

You can see above that WETH is weighted at 50% with BAT and LRC weighted at 25% each. After entering .362 EWTH to add to the new liquidity pool it showed that I would need 188 BAT and 470 LRC. I went for the default 0.15% swap fee but you can change this to anything you wish it to be. The higher the swap fee the more earnings you would make from providing liquidity to the pool.

Once your new liquidity pool is set up, go ahead and click create and hit confirm on the confirmation screen of MetaMask. Remember, we are setting up a pool so the gas fee will be particularly high here;

8256a4fe80767a8611b1f4a2c09f57bf983817f1bfbcaa3cdac83c3b7ba50219.png

Now, it is time to wait for the transaction with the contract to go through.

Once complete, you can head over to the main Pools Management page and see your newly created Shared Pool in the “My Liquidity” section;

9d72d3549613a2e5f84aa675d01915385b6e0e83e1e672ae62c0425e97234ce3.png

You can click the Pool here and see all of the stats associated with your pool;

42a64f04167dca696c89311913e74e8b3ed5f49f26a9a60e6a46e9d68fa56594.png

Here, you can also add liquidity or remove liquidity in the same manner as explained previously.

That’s all there is to it! You have now created a liquidity pool on the Balancer protocol between ETH, LRC, and BAT (or whatever token you selected).

Shared vs Private Liquidity Pools

Right now, Shared Pools are the only type of liquidity pools you can create on the Balancer Protocol as this feature is still in the Beta stage. However, this does mean that you can go ahead and add some liquidity to the liquidity pool that we just set up!

Become a liquidity provider and head over to the pool to add some liquidity through this link.

You see, eventually there will be types of pools that you can create on Balancer; Shared and Private.

Shared pools have fixed parameters that cannot be changed by anybody once executed. This means that I cannot change the percentage of each of the tokens in my liquidity pool because this would allow me to indirectly steal money from other liquidity providers.

Private pools are exactly how they sound - private. Only the creator of the Private pool can add liquidity to any type of private pool. This means that it is not open to the public and nobody but the owner of the pool can provide liquidity. 

However, private pools also have a feature that is known as smart pools. Smart pools are private pools that are owned by smart contracts that can be used as a gateway to allow liquidity to be added through known conditions. For example, PieDAO BTC++ pool is a project that is a private pool but allows liquidity to enter through their set conditions. The weightings of each coin can easily be changed by PieDAO through the on-chain governance system that they have in place.


D3F1
D3F1

Yet another defi fan


DeFi Box
DeFi Box

DeFi world in a nutshell.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.