From 3021525d6b6faec4afc69825d9fe9b8481454aa8 Mon Sep 17 00:00:00 2001 From: Adam R <13562139+catenocrypt@users.noreply.github.com> Date: Thu, 6 Aug 2020 17:16:53 +0200 Subject: [PATCH] [internal] Add support for BEP8 mini tokens. (#3077) * Add support for BEP8 mini tokens. * Missing asset retrieval is BEP2 only. Co-authored-by: Catenocrypt --- README.md | 11 +++++++++-- script/action/binance.ts | 7 ++++--- src/test/helpers.ts | 8 +++++++- src/test/index.test.ts | 9 +++++---- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 78acc2796..4bfe4fa3a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/script/action/binance.ts b/script/action/binance.ts index ca83fe9b8..2269fb18b 100644 --- a/script/action/binance.ts +++ b/script/action/binance.ts @@ -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 { } 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) { diff --git a/src/test/helpers.ts b/src/test/helpers.ts index b1a3c6041..f8a9b92c6 100644 --- a/src/test/helpers.ts +++ b/src/test/helpers.ts @@ -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 && diff --git a/src/test/index.test.ts b/src/test/index.test.ts index b1d6fab8d..6e8d6e7f3 100644 --- a/src/test/index.test.ts +++ b/src/test/index.test.ts @@ -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: