Fix cmc script.ts (#2736)

This commit is contained in:
Nick Kozlov 2020-07-14 14:40:42 +03:00 committed by GitHub
parent ce34e54b4f
commit 3f1529273d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ import {
readFileSync, readFileSync,
getChainAssetLogoPath, getChainAssetLogoPath,
isPathExistsSync, isPathExistsSync,
getChainName,
makeDirSync, makeDirSync,
getChainAssetPath, getChainAssetPath,
ethSidechains, ethSidechains,
@ -16,6 +17,7 @@ import {
getChainWhitelist, getChainWhitelist,
} from "../../src/test/helpers"; } from "../../src/test/helpers";
import { TickerType, mapTiker, PlatformType } from "../../src/test/models"; import { TickerType, mapTiker, PlatformType } from "../../src/test/models";
import { CoinType } from "@trustwallet/types";
// Steps required to run this: // Steps required to run this:
// 1. (Optional) CMC API key already setup, use yours if needed. Install script deps "npm i" if hasn't been run before. // 1. (Optional) CMC API key already setup, use yours if needed. Install script deps "npm i" if hasn't been run before.
@ -54,6 +56,7 @@ const custom: mapTiker[] = [
] ]
const allContracts: mapTiker[] = [] // Temp storage for mapped assets const allContracts: mapTiker[] = [] // Temp storage for mapped assets
let bip44Constants = {}
let bnbOwnerToSymbol = {} // e.g: bnb1tawge8u97slduhhtumm03l4xl4c46dwv5m9yzk: WISH-2D5 let bnbOwnerToSymbol = {} // e.g: bnb1tawge8u97slduhhtumm03l4xl4c46dwv5m9yzk: WISH-2D5
let bnbOriginalSymbolToSymbol = {} // e.g: WISH: WISH-2D5 let bnbOriginalSymbolToSymbol = {} // e.g: WISH: WISH-2D5
@ -78,97 +81,98 @@ async function processCoin(coin) {
const platformType: PlatformType = platform == null ? "" : platform.name const platformType: PlatformType = platform == null ? "" : platform.name
log(`${symbol}:${platformType}`) log(`${symbol}:${platformType}`)
// await BluebirbPromise.mapSeries(types, async type => { // await BluebirbPromise.mapSeries(types, async type => {
switch (platformType) { switch (platformType) {
case PlatformType.Ethereum: case PlatformType.Ethereum:
// log(`Ticker ${name}(${symbol}) is a token with address ${address} and CMC id ${id}`) // log(`Ticker ${name}(${symbol}) is a token with address ${address} and CMC id ${id}`)
if (platform.token_address) { if (platform.token_address) {
try { try {
const checksum = toChecksum(platform.token_address) const checksum = toChecksum(platform.token_address)
if (!isAddressInBlackList("ethereum", checksum)) { if (!isAddressInBlackList("ethereum", checksum)) {
log(`Added ${checksum}`) log(`Added ${checksum}`)
addToContractsList({ addToContractsList({
coin: 60, coin: 60,
type: typeToken, type: typeToken,
token_id: checksum, token_id: checksum,
id id
}) })
}
} catch (error) {
console.log(`Etheruem platform error`, error)
break
} }
// await getImageIfMissing(getChainName(CoinType.ethereum), checksum, id)
} catch (error) {
console.log(`Etheruem platform error`, error)
break
} }
}
break
case PlatformType.Binance:
if (symbol === "BNB") {
break break
case PlatformType.Binance: }
if (symbol === "BNB") { const ownerAddress = platform.token_address.trim()
break log(`Symbol ${symbol}:${ownerAddress}:${id}`)
} if (ownerAddress && (ownerAddress in bnbOwnerToSymbol)) {
const ownerAddress = platform.token_address.trim() log(`Added ${bnbOwnerToSymbol[ownerAddress]}`)
log(`Symbol ${symbol}:${ownerAddress}:${id}`) addToContractsList({
if (ownerAddress && (ownerAddress in bnbOwnerToSymbol)) { coin: 714,
log(`Added ${bnbOwnerToSymbol[ownerAddress]}`) type: typeToken,
addToContractsList({ token_id: bnbOwnerToSymbol[ownerAddress],
coin: 714, id
type: typeToken, })
token_id: bnbOwnerToSymbol[ownerAddress],
id
})
break
}
if (symbol in bnbOriginalSymbolToSymbol) {
log(`Added Binance ${bnbOriginalSymbolToSymbol[symbol]}`)
addToContractsList({
coin: 714,
type: typeToken,
token_id: bnbOriginalSymbolToSymbol[symbol].trim(),
id
})
break
}
break break
case PlatformType.TRON: }
if (symbol === "TRX") {
break
}
const tokenAddr = platform.token_address.trim()
log(`tron: ${tokenAddr}`)
addToContractsList({
coin: 195,
type: typeToken,
token_id: tokenAddr,
id
})
break
// case PlatformType.VeChain:
// if (symbol === "VET") {
// break
// }
// const addr = platform.token_address.trim() if (symbol in bnbOriginalSymbolToSymbol) {
// log(`vechain: ${tokenAddr}`) log(`Added Binance ${bnbOriginalSymbolToSymbol[symbol]}`)
// addToContractsList({ addToContractsList({
// coin: 0, coin: 714,
// type: typeCoin, type: typeToken,
// token_id: addr, token_id: bnbOriginalSymbolToSymbol[symbol].trim(),
// id id
// }) })
// break
default:
const coinIndex = getSlip44Index(symbol, name)
if (coinIndex >= 0) {
log(`Ticker ${name}(${symbol}) is a coin with id ${coinIndex}`)
addToContractsList({
coin: coinIndex,
type: typeCoin,
id
})
} else {
log(`Coin ${coinIndex} ${name}(${symbol}) not listed in slip44`)
}
break break
} }
break
case PlatformType.TRON:
if (symbol === "TRX") {
break
}
const tokenAddr = platform.token_address.trim()
log(`tron: ${tokenAddr}`)
addToContractsList({
coin: 195,
type: typeToken,
token_id: tokenAddr,
id
})
break
// case PlatformType.VeChain:
// if (symbol === "VET") {
// break
// }
// const addr = platform.token_address.trim()
// log(`vechain: ${tokenAddr}`)
// addToContractsList({
// coin: 0,
// type: typeCoin,
// token_id: addr,
// id
// })
// break
default:
const coinIndex = getSlip44Index(symbol, name)
if (coinIndex >= 0) {
log(`Ticker ${name}(${symbol}) is a coin with id ${coinIndex}`)
addToContractsList({
coin: coinIndex,
type: typeCoin,
id
})
} else {
log(`Coin ${coinIndex} ${name}(${symbol}) not listed in slip44`)
}
break
}
// }) // })
} }
@ -312,8 +316,8 @@ function readBEP2() {
} }
async function getTickers() { async function getTickers() {
const url = `https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?&limit=3500&CMC_PRO_API_KEY=${CMC_PRO_API_KEY}` const url = `https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?&limit=3500&CMC_PRO_API_KEY=${CMC_PRO_API_KEY}`
return axios.get(url).then(res => res.data.data).catch(e => {throw `Error getTickers ${e.message}`}) return axios.get(url).then(res => res.data.data).catch(e => {throw `Error getTickers ${e.message}`})
} }
function log(string, cb?) { function log(string, cb?) {