Bancor3: Token Whitelisting Code Guide

Aw Kai Shin
4 min readMay 26, 2022

--

Bancor Proposals

In order for a token to be listed on Bancor, it will first have to go through a BancorDAO governance process. This process requires a proposal to be created with vBNT stakers having the right to vote on the proposal. Following a successful proposal, the token will then be approved and added to the set of whitelisted tokens. This can be done in 2 ways:

  • Whitelisting the token
  • Whitelisting the token with a funding limit

For further information on the voting process, please refer: Bancor Governance Voting Guide

For whitelisting requirements: https://gov.bancor.network/t/whitelisting-requirements/1849

State Changes

//NetworkSettings.sol
EnumerableSetUpgradeable.AddressSet private _protectedTokenWhitelist;

_protectedTokenWhitelist is the set of tokens which have been whitelisted and are eligible for protection. New tokens which are whitelisted are added to this set.

//NetworkSettings.sol
mapping(Token => uint256) private _poolFundingLimits;

_poolFundingLimits maps the funding limits for each token.

Whitelisting the token

Source

For token whitelisting, there are 2 entry points defined in NetworkSettings.sol depending on whether single or multiple tokens are being added. addTokensToWhitelist() uses a for loop to iterate over each token to be added using the same _addTokenToWhitelist() .

Code

_addTokenToWhitelist() utilizes the EnumerableSetUpgradeable library from OpenZeppelin in order to add the token to _protectedTokenWhitelist set.

Code

Of note, the add function as implemented by OpenZeppelin first adds the value to the set before returning true. As such, the if statement in _addTokenToWhitelist utilizes the NOT operator (!) in order to throw AlreadyExists() error or emit a TokenAddedToWhitelist() success.

OpenZeppelin

Whitelisting the token with a funding limit

Source

The BancorDAO can, in a single action, also choose to set a funding limit in addition to just whitelisting the token. addTokenToWhitelistWithLimit() builds upon addTokenToWhitelist() by calling _setFundingLimit upon completion of _addTokenToWhitelist . In other words, adding of token to the whitelist follows the above process which subsequently sets a funding limit for the newly whitelisted token.

Code

_setFundingLimit first checks if the token is whitelisted and then adds the funding limit of the token to the _poolFundingLimits mapping. FundingLimitUpdated() is emitted upon success.

Code

Following token whitelisting, the next step would then be the creation of the pool as well as the pool token which is the topic of the next article.

Thanks for staying till the end. Would love to hear your thought/comments so do drop a comment. I’m active on twitter @AwKaiShin if you would like to receive more digestible tidbits of crypto-related info or visit my personal website if you would like my services :)

Bancor3 Deep Dive Series

Analysis

Smart Contract Guides

Other Links

Official Links

--

--

Aw Kai Shin
Aw Kai Shin

Written by Aw Kai Shin

Web3, Crypto & Blockchain: Building a More Equitable Web | Technical Writer @FactorDAO | www.awkaishin.com

No responses yet