Adding Liquidity
To add/remove liquidity using a front-end interface here is a step-by-step guide.
The remainder of the guide below is for developers looking to tap into the Bancor liquidity network from their apps or smart contracts.
Liquidity Provision for Developers
Note that you'll need to approve
all underlying ERC20 transfers before adding liquidity on Bancor.
Step #1: Identify the Pool Version
Bancor is a fast-moving protocol, while at the same time remaining permissionless and decentralized. When we push an upgrade, the owner of the converter contract must opt in to the new version. For that reason, developers need to check first what type of converter they're interacting with in order to know how to correctly interface with the contract.
We recommend that you use the Bancor SDK to query for the converter version.
Step #2: Query for Converter Type (version >= 28)
Move on to Step #3 if your converter version is 27 or lower.
As of version 28:
The
LiquidTokenConverter
has a single reserve and manages a liquid tokenThe
LiquidityPoolV1Converter
has multiple reserves and is the base contract for converters that manage liquidity poolsThe
LiquidityPoolV2Converter
has two reserves and is the Bancor v2 base contract
Each contract has a converterType
function that will return 0
for a LiquidTokenConverter
, 1
for a LiquidityPoolV1Converter
, and 2
for a LiquidityPoolV2Converter
You'll only be able to add liquidity for converter types 1 & 2.
Step #3a: Adding Liquidity Bancor V2
Adding liquidity to bancor V2 pools is using a new interface
The Bancor V2 AddLiquidity
function is different from other types in that it requires you to specify only one reserve, as the process of adding liquidity is designed for single token staking. LPs can now specify the exact number of tokens of each underlying reserve they'd like to contribute. LPs will still need to roughly estimate expected issuance in order to input the _minReturn
of liquidity tokens they would accept, but overall the new process leaves less room for error and confusion.
Calculating expected pool tokens:addLiquidity Amount * (StakedBalance / PoolTokenSupply)
Recall that starting with version 28, LPs can directly contribute ETH using the address 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
.
Adding liquidity will result in the emission of an event:
Step #3b: Adding Liquidity (version >= 28)
You'll find the newer interface for adding liquidity below. In contrast to older versions, liquidity providers can now specify the exact number of tokens of each underlying reserve they'd like to contribute. Previously, LPs needed to calculate the number of liquidity tokens they expected to be issued. LPs will still need to roughly estimate expected issuance in order to input the _minReturn
of liquidity tokens they would accept, but overall the new process leaves less room for error and confusion.
Recall that starting with version 28, LPs can directly contribute ETH using the address 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
.
Note that while the addLiquidityToPool
function is payable, it works just the same for ERC20 liquidity provision.
Adding liquidity will result in the emission of an event for each token reserve:
Step #3c: Adding Liquidity (version < 28)
When we push a new version, each converter needs to be manually upgraded by its owner. For that reason, many active converters are still using earlier versions of our code.
The _amount
value in the fund function is the number of liquidity tokens expected on liquidity contribution. This may require some math in your smart contract or Web3 code.
Based on the liquidity token _amount
value, the contract will transfer the requisite amount of tokens of each reserve corresponding to the token figure. This call is made directly on the pool converter contract, unlike conversion which is triggered on the BancorNetwork
contract.
Adding Liquidity via Web3
Note that this demo assumes that you've already configured a Web3 connection via your preferred method
The process for adding liquidity via Web3 or via smart contract is largely the same. Here is a walk-through:
First, you'll need to identify the converter version as outlined in Step #1 above.
Bancor V2 pools
First, copy the LiquidityPoolV2Converter
ABI into your project. Note that converters of the LiquidTokenConverter
type are not eligible for liquidity provision (as outlined in Step #2).
Find the LiquidityPoolV2Converter
ABI here.
Your Web3 code will look something like this:
Versions 28 and Above
First, copy the LiquidityPoolV1Converter
ABI into your project. Note that converters of the LiquidTokenConverter
type are not eligible for liquidity provision (as outlined in Step #2).
Find the LiquidityPoolV1Converter
ABI here.
Your Web3 code will look something like this:
Versions Lower than 28
First, copy the ConverterBase
ABI into your project. Found here.
Your Web3 code will look something like this:
****
****
Last updated