[internal] Add support for BEP8 mini tokens. (#3077)

* Add support for BEP8 mini tokens.

* Missing asset retrieval is BEP2 only.

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2020-08-06 17:16:53 +02:00 committed by GitHub
parent 44251c825c
commit 3021525d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 10 deletions

View File

@ -16,7 +16,9 @@ Token repository [https://github.com/trustwallet/assets](https://github.com/trus
- [Callisto Network (CLO)](https://callisto.network/)
- [Thunder Token (TT)](https://thundercore.com/)
2. [BEP2](https://github.com/binance-chain/BEPs/blob/master/BEP2.md) Binance DEX token (native marketplace on Binance Chain)
2. [BEP2](https://github.com/binance-chain/BEPs/blob/master/BEP2.md)
[BEP8](https://github.com/binance-chain/BEPs/blob/master/BEP8.md)
Binance DEX token (native marketplace on Binance Chain)
3. [TRC10, TRC20](https://developers.tron.network/docs/trc10-token) tokens on TRON blockchain
@ -164,7 +166,7 @@ To remain in validators list:
## Common uploads
Uploading:
1. Ethereum ERC20 [token folder](https://github.com/trustwallet/assets/tree/master/blockchains/ethereum/assets)
2. Binance DEX BEP2 token [token folder](https://github.com/trustwallet/assets/tree/master/blockchains/binance/assets)
2. Binance DEX BEP2, BEP8 token [token folder](https://github.com/trustwallet/assets/tree/master/blockchains/binance/assets)
3. TRON TRC10, TRC20 token [token folder](https://github.com/trustwallet/assets/tree/master/blockchains/tron/assets)
4. Add Cosmos validator image [](https://github.com/trustwallet/assets/tree/master/blockchains/cosmos/validators)
5. Add Tezos validator info [](https://github.com/trustwallet/assets/tree/master/blockchains/tezos/validators/list.json)
@ -250,6 +252,11 @@ BEP-2:
https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/assets/ANKR-E97/logo.png
```
BEP-8:
```js
https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/assets/BHC-3E8M/logo.png
```
TRC-10:
```js
https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/assets/1002000/logo.png

View File

@ -13,7 +13,7 @@ import {
const binanceChain = "binance"
const binanceAssetsUrl = config.getConfig("binance_assets_url", "https://explorer.binance.org/api/v1/assets?page=1&rows=1000");
async function retrieveAssetList() {
async function retrieveBep2AssetList() {
console.log(`Retrieving assets info from: ${binanceAssetsUrl}`);
const { assetInfoList } = await axios.get(binanceAssetsUrl).then(r => r.data);
console.log(`Retrieved ${assetInfoList.length} asset infos`);
@ -74,10 +74,11 @@ async function fetchMissingImages(toFetch: any[]): Promise<string[]> {
}
export async function update() {
const assetInfoList = await retrieveAssetList();
// retrieve missing token images; BEP2 (bep8 not supported)
const bep2InfoList = await retrieveBep2AssetList();
const blacklist: string[] = require(getChainBlacklistPath(binanceChain));
const toFetch = findImagesToFetch(assetInfoList, blacklist);
const toFetch = findImagesToFetch(bep2InfoList, blacklist);
const fetchedAssets = await fetchMissingImages(toFetch);
if (fetchedAssets.length > 0) {

View File

@ -105,11 +105,17 @@ export const isLowerCase = (str: string): boolean => str.toLowerCase() === str
export const isUpperCase = (str: string): boolean => str.toUpperCase() === str
export const isChecksum = (address: string): boolean => web3.utils.checkAddressChecksum(address)
export const toChecksum = (address: string): string => web3.utils.toChecksumAddress(address)
export const getBinanceBEP2Symbols = async () => axios.get(`https://dex-atlantic.binance.org/api/v1/tokens?limit=1000`).then(res => res.data.map(({ symbol }) => symbol))
export const getFileName = (name: string): string => path.basename(name, path.extname(name))
export const getFileExt = (name: string): string => name.slice((Math.max(0, name.lastIndexOf(".")) || Infinity) + 1)
export async function getBinanceTokenSymbols() {
const bep2assets = await axios.get(`https://dex-atlantic.binance.org/api/v1/tokens?limit=1000`);
const bep8assets = await axios.get(`https://dex-atlantic.binance.org/api/v1/mini/tokens?limit=1000`);
return bep2assets.data.map(({ symbol }) => symbol)
.concat(bep8assets.data.map(({ symbol }) => symbol));
}
export const isTRC10 = (str: string): boolean => (/^\d+$/.test(str))
export const isTRC20 = (address: string) => {
return address.length == 34 &&

View File

@ -7,7 +7,7 @@ import {
chainsFolderPath,
ethSidechains,
findFiles,
getBinanceBEP2Symbols,
getBinanceTokenSymbols,
getChainAssetLogoPath,
getChainAssetPath,
getChainAssetsPath,
@ -138,7 +138,8 @@ describe(`Test "blockchains" folder`, () => {
describe(`Check "binace" folder`, () => {
it("Asset must exist on chain", async () => {
const tokenSymbols = await getBinanceBEP2Symbols()
const tokenSymbols = await getBinanceTokenSymbols()
console.log(tokenSymbols);
const assets = readDirSync(getChainAssetsPath(Binance))
assets.forEach(asset => {
@ -362,7 +363,7 @@ describe("Test Coinmarketcap mapping", () => {
});
test(`"token_id" should be in correct format`, async () => {
const bep2Symbols = await getBinanceBEP2Symbols()
const bepSymbols = await getBinanceTokenSymbols()
cmcMap.forEach(el => {
const {coin, token_id, type, id} = el
@ -379,7 +380,7 @@ describe("Test Coinmarketcap mapping", () => {
}
case 714:
if (type === TickerType.Token) {
expect(bep2Symbols.indexOf(token_id), `"token_id" ${token_id} with id ${id} must be BEP2 symbol`).toBeGreaterThan(0)
expect(bepSymbols.indexOf(token_id), `"token_id" ${token_id} with id ${id} must be BEP2 or BEP8 symbol`).toBeGreaterThan(0)
break;
}
default: