Bancor3: Token Whitelisting Code Guide
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
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()
.
_addTokenToWhitelist()
utilizes the EnumerableSetUpgradeable
library from OpenZeppelin in order to add the token to _protectedTokenWhitelist
set.
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.
Whitelisting the token with a funding limit
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.
_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.
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
- Introduction to Bancor3: Redefining DeFi Playbooks Once Again
- Key Concepts in Bancor3: Key Concepts Driving The Next DeFi Wave
- Bancor3 Tokenomics: A New Token Model
- Bancor3 Governance Tokenomics: The Voting Premium
Smart Contract Guides
- Token Whitelisting: Technical Documentation
- Pool Creation: Code Guide
- Depositing ERC20 Tokens: Code Guide
- Depositing BNT Tokens: Code Guide
- Trading: Code Guide
- Withdrawal Request: Code Guide
- BNT Withdrawal Claim: Code Guide
- ERC20 Withdrawal Claim: Code Guide
Other Links
- Personal Smart Contract Gitbook: https://kai27.gitbook.io/bancor/
- Glossary of Terms (WIP): https://kai27.gitbook.io/bancor/glossary
Official Links
- Bancor Home: https://home.bancor.network/
- Bancor Support: https://support.bancor.network/hc/en-us
- Bancor App: https://app.bancor.network/earn
- Bancor Official Documentation: https://docs.bancor.network/about-bancor-network/bancor-v3