mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
Fix cmc script.ts (#2736)
This commit is contained in:
parent
ce34e54b4f
commit
3f1529273d
|
@ -9,6 +9,7 @@ import {
|
|||
readFileSync,
|
||||
getChainAssetLogoPath,
|
||||
isPathExistsSync,
|
||||
getChainName,
|
||||
makeDirSync,
|
||||
getChainAssetPath,
|
||||
ethSidechains,
|
||||
|
@ -16,6 +17,7 @@ import {
|
|||
getChainWhitelist,
|
||||
} from "../../src/test/helpers";
|
||||
import { TickerType, mapTiker, PlatformType } from "../../src/test/models";
|
||||
import { CoinType } from "@trustwallet/types";
|
||||
|
||||
// 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.
|
||||
|
@ -54,6 +56,7 @@ const custom: mapTiker[] = [
|
|||
]
|
||||
|
||||
const allContracts: mapTiker[] = [] // Temp storage for mapped assets
|
||||
let bip44Constants = {}
|
||||
let bnbOwnerToSymbol = {} // e.g: bnb1tawge8u97slduhhtumm03l4xl4c46dwv5m9yzk: WISH-2D5
|
||||
let bnbOriginalSymbolToSymbol = {} // e.g: WISH: WISH-2D5
|
||||
|
||||
|
@ -78,97 +81,98 @@ async function processCoin(coin) {
|
|||
const platformType: PlatformType = platform == null ? "" : platform.name
|
||||
log(`${symbol}:${platformType}`)
|
||||
// await BluebirbPromise.mapSeries(types, async type => {
|
||||
switch (platformType) {
|
||||
case PlatformType.Ethereum:
|
||||
// log(`Ticker ${name}(${symbol}) is a token with address ${address} and CMC id ${id}`)
|
||||
if (platform.token_address) {
|
||||
try {
|
||||
const checksum = toChecksum(platform.token_address)
|
||||
if (!isAddressInBlackList("ethereum", checksum)) {
|
||||
log(`Added ${checksum}`)
|
||||
addToContractsList({
|
||||
coin: 60,
|
||||
type: typeToken,
|
||||
token_id: checksum,
|
||||
id
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Etheruem platform error`, error)
|
||||
break
|
||||
switch (platformType) {
|
||||
case PlatformType.Ethereum:
|
||||
// log(`Ticker ${name}(${symbol}) is a token with address ${address} and CMC id ${id}`)
|
||||
if (platform.token_address) {
|
||||
try {
|
||||
const checksum = toChecksum(platform.token_address)
|
||||
if (!isAddressInBlackList("ethereum", checksum)) {
|
||||
log(`Added ${checksum}`)
|
||||
addToContractsList({
|
||||
coin: 60,
|
||||
type: typeToken,
|
||||
token_id: checksum,
|
||||
id
|
||||
})
|
||||
}
|
||||
// await getImageIfMissing(getChainName(CoinType.ethereum), checksum, id)
|
||||
} catch (error) {
|
||||
console.log(`Etheruem platform error`, error)
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
case PlatformType.Binance:
|
||||
if (symbol === "BNB") {
|
||||
break
|
||||
case PlatformType.Binance:
|
||||
if (symbol === "BNB") {
|
||||
break
|
||||
}
|
||||
const ownerAddress = platform.token_address.trim()
|
||||
log(`Symbol ${symbol}:${ownerAddress}:${id}`)
|
||||
if (ownerAddress && (ownerAddress in bnbOwnerToSymbol)) {
|
||||
log(`Added ${bnbOwnerToSymbol[ownerAddress]}`)
|
||||
addToContractsList({
|
||||
coin: 714,
|
||||
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
|
||||
}
|
||||
}
|
||||
const ownerAddress = platform.token_address.trim()
|
||||
log(`Symbol ${symbol}:${ownerAddress}:${id}`)
|
||||
if (ownerAddress && (ownerAddress in bnbOwnerToSymbol)) {
|
||||
log(`Added ${bnbOwnerToSymbol[ownerAddress]}`)
|
||||
addToContractsList({
|
||||
coin: 714,
|
||||
type: typeToken,
|
||||
token_id: bnbOwnerToSymbol[ownerAddress],
|
||||
id
|
||||
})
|
||||
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`)
|
||||
}
|
||||
if (symbol in bnbOriginalSymbolToSymbol) {
|
||||
log(`Added Binance ${bnbOriginalSymbolToSymbol[symbol]}`)
|
||||
addToContractsList({
|
||||
coin: 714,
|
||||
type: typeToken,
|
||||
token_id: bnbOriginalSymbolToSymbol[symbol].trim(),
|
||||
id
|
||||
})
|
||||
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() {
|
||||
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}`})
|
||||
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}`})
|
||||
}
|
||||
|
||||
function log(string, cb?) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user