[Internal] Fix for running in Action; Adjust token validity check (#5429)

* Extra logs

* External Updates

* Move token validity check, cheksumFormat ID is available only later.

* External Updates

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2021-01-29 08:26:38 +01:00 committed by GitHub
parent 80f623673a
commit 5efd533fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 56 deletions

View File

@ -1,7 +1,7 @@
{
"name": "Trust Wallet: Ethereum",
"logoURI": "https://trustwallet.com/assets/images/favicon.png",
"timestamp": "2021-01-28T10:04:51.984Z",
"timestamp": "2021-01-29T07:23:30.936Z",
"tokens": [
{
"chainId": 1,
@ -23,10 +23,10 @@
"base": "c60_t0x00a8b738E453fFd858a7edf03bcCfe20412f0Eb0"
},
{
"base": "c60_t0x0258F474786DdFd37ABCE6df6BBb1Dd5dfC4434a"
"base": "c60_t0x00c83aeCC790e8a4453e5dD3B0B4b3680501a7A7"
},
{
"base": "c60_t0x0417912b3a7AF768051765040A55BB0925D4DDcF"
"base": "c60_t0x0258F474786DdFd37ABCE6df6BBb1Dd5dfC4434a"
},
{
"base": "c60_t0x04Fa0d235C4abf4BcF4787aF4CF447DE572eF828"
@ -106,6 +106,9 @@
{
"base": "c60_t0x429881672B9AE42b8EbA0E26cD9C73711b891Ca5"
},
{
"base": "c60_t0x4a220E6096B25EADb88358cb44068A3248254675"
},
{
"base": "c60_t0x4c11249814f11b9346808179Cf06e71ac328c1b5"
},
@ -361,6 +364,16 @@
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x00a8b738E453fFd858a7edf03bcCfe20412f0Eb0/logo.png",
"pairs": []
},
{
"asset": "c60_t0x00c83aeCC790e8a4453e5dD3B0B4b3680501a7A7",
"type": "ERC20",
"address": "0x00c83aeCC790e8a4453e5dD3B0B4b3680501a7A7",
"name": "SKALE",
"symbol": "SKL",
"decimals": 18,
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x00c83aeCC790e8a4453e5dD3B0B4b3680501a7A7/logo.png",
"pairs": []
},
{
"asset": "c60_t0x0258F474786DdFd37ABCE6df6BBb1Dd5dfC4434a",
"type": "ERC20",
@ -371,16 +384,6 @@
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x0258F474786DdFd37ABCE6df6BBb1Dd5dfC4434a/logo.png",
"pairs": []
},
{
"asset": "c60_t0x0417912b3a7AF768051765040A55BB0925D4DDcF",
"type": "ERC20",
"address": "0x0417912b3a7AF768051765040A55BB0925D4DDcF",
"name": "Liquidity Dividends Protocol",
"symbol": "LID",
"decimals": 18,
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x0417912b3a7AF768051765040A55BB0925D4DDcF/logo.png",
"pairs": []
},
{
"asset": "c60_t0x04Fa0d235C4abf4BcF4787aF4CF447DE572eF828",
"type": "ERC20",
@ -655,6 +658,16 @@
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x429881672B9AE42b8EbA0E26cD9C73711b891Ca5/logo.png",
"pairs": []
},
{
"asset": "c60_t0x4a220E6096B25EADb88358cb44068A3248254675",
"type": "ERC20",
"address": "0x4a220E6096B25EADb88358cb44068A3248254675",
"name": "Quant",
"symbol": "QNT",
"decimals": 18,
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x4a220E6096B25EADb88358cb44068A3248254675/logo.png",
"pairs": []
},
{
"asset": "c60_t0x4c11249814f11b9346808179Cf06e71ac328c1b5",
"type": "ERC20",
@ -1427,7 +1440,7 @@
}
],
"version": {
"major": 1,
"major": 2,
"minor": 0,
"patch": 0
}

View File

@ -1,7 +1,7 @@
{
"name": "Trust Wallet: Smart Chain",
"logoURI": "https://trustwallet.com/assets/images/favicon.png",
"timestamp": "2021-01-28T10:04:32.196Z",
"timestamp": "2021-01-29T07:23:25.492Z",
"tokens": [
{
"chainId": 56,
@ -82,12 +82,18 @@
{
"base": "c20000714_t0x728C5baC3C3e370E372Fc4671f9ef6916b814d8B"
},
{
"base": "c20000714_t0x78650B139471520656b9E7aA7A5e9276814a38e9"
},
{
"base": "c20000714_t0x88f1A5ae2A3BF98AEAF342D26B30a79438c9142e"
},
{
"base": "c20000714_t0x8fF795a6F4D97E7887C79beA79aba5cc76444aDf"
},
{
"base": "c20000714_t0x928e55daB735aa8260AF3cEDadA18B5f70C72f1b"
},
{
"base": "c20000714_t0xa1faa113cbE53436Df28FF0aEe54275c13B40975"
},
@ -103,6 +109,9 @@
{
"base": "c20000714_t0xBf5140A22578168FD562DCcF235E5D43A02ce9B1"
},
{
"base": "c20000714_t0xbF7c81FFF98BbE61B40Ed186e4AfD6DDd01337fe"
},
{
"base": "c20000714_t0xcF6BB5389c92Bdda8a3747Ddb454cB7a64626C63"
},
@ -358,6 +367,16 @@
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/assets/0x728C5baC3C3e370E372Fc4671f9ef6916b814d8B/logo.png",
"pairs": []
},
{
"asset": "c20000714_t0x78650B139471520656b9E7aA7A5e9276814a38e9",
"type": "BEP20",
"address": "0x78650B139471520656b9E7aA7A5e9276814a38e9",
"name": "StandardBTCHashrateToken",
"symbol": "BTCST",
"decimals": 18,
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/assets/0x78650B139471520656b9E7aA7A5e9276814a38e9/logo.png",
"pairs": []
},
{
"asset": "c20000714_t0x88f1A5ae2A3BF98AEAF342D26B30a79438c9142e",
"type": "BEP20",
@ -378,6 +397,16 @@
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/assets/0x8fF795a6F4D97E7887C79beA79aba5cc76444aDf/logo.png",
"pairs": []
},
{
"asset": "c20000714_t0x928e55daB735aa8260AF3cEDadA18B5f70C72f1b",
"type": "BEP20",
"address": "0x928e55daB735aa8260AF3cEDadA18B5f70C72f1b",
"name": "Frontier Token",
"symbol": "FRONT",
"decimals": 18,
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/assets/0x928e55daB735aa8260AF3cEDadA18B5f70C72f1b/logo.png",
"pairs": []
},
{
"chainId": 56,
"asset": "c20000714_t0xa1faa113cbE53436Df28FF0aEe54275c13B40975",
@ -432,6 +461,16 @@
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/assets/0xBf5140A22578168FD562DCcF235E5D43A02ce9B1/logo.png",
"pairs": []
},
{
"asset": "c20000714_t0xbF7c81FFF98BbE61B40Ed186e4AfD6DDd01337fe",
"type": "BEP20",
"address": "0xbF7c81FFF98BbE61B40Ed186e4AfD6DDd01337fe",
"name": "Elrond",
"symbol": "EGLD",
"decimals": 18,
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/assets/0xbF7c81FFF98BbE61B40Ed186e4AfD6DDd01337fe/logo.png",
"pairs": []
},
{
"chainId": 56,
"asset": "c20000714_t0xcF6BB5389c92Bdda8a3747Ddb454cB7a64626C63",
@ -487,7 +526,7 @@
}
],
"version": {
"major": 1,
"major": 2,
"minor": 0,
"patch": 0
}

View File

@ -172,7 +172,7 @@
},
"status": {
"disabled": true,
"note": "No more capacity: -34224"
"note": "No more capacity: -34155"
}
},
{

View File

@ -6,9 +6,7 @@ import {
primaryTokenIndex,
TokenInfo
} from "../generic/subgraph";
import { getChainAllowlistPath } from "../generic/repo-structure";
import { Ethereum } from "../generic/blockchains";
import { readJsonFile } from "../generic/json";
import {
rebuildTokenlist,
TokenItem
@ -23,9 +21,6 @@ const PrimaryTokens: string[] = ["WETH", "ETH"];
async function retrieveUniswapPairs(): Promise<PairInfo[]> {
console.log(`Retrieving pairs from Uniswap, limit liquidity USD ${config.Uniswap_MinLiquidity} volume ${config.Uniswap_MinVol24} txcount ${config.Uniswap_MinTxCount24}`);
// prepare phase, read allowlist
const allowlist: string[] = readJsonFile(getChainAllowlistPath(Ethereum)) as string[];
const pairs = await getTradingPairs(config.Uniswap_TradingPairsUrl, config.Uniswap_TradingPairsQuery);
const filtered: PairInfo[] = [];
pairs.forEach(x => {
@ -33,7 +28,7 @@ async function retrieveUniswapPairs(): Promise<PairInfo[]> {
if (typeof(x) === "object") {
const pairInfo = x as PairInfo;
if (pairInfo) {
if (checkTradingPair(pairInfo, Ethereum, config.Uniswap_MinLiquidity, config.Uniswap_MinVol24, config.Uniswap_MinTxCount24, allowlist, PrimaryTokens)) {
if (checkTradingPair(pairInfo, config.Uniswap_MinLiquidity, config.Uniswap_MinVol24, config.Uniswap_MinTxCount24, PrimaryTokens)) {
filtered.push(pairInfo);
}
}

View File

@ -6,13 +6,11 @@ import {
primaryTokenIndex,
TokenInfo
} from "../generic/subgraph";
import { getChainAllowlistPath } from "../generic/repo-structure";
import { SmartChain } from "../generic/blockchains";
import {
rebuildTokenlist,
TokenItem
} from "../generic/tokenlists";
import { readJsonFile } from "../generic/json";
import { toChecksum } from "../generic/eth-address";
import { assetID, logoURI } from "../generic/asset";
import * as config from "../config"
@ -22,9 +20,6 @@ const PrimaryTokens: string[] = ["WBNB", "BNB"];
async function retrievePancakeSwapPairs(): Promise<PairInfo[]> {
console.log(`Retrieving pairs from PancakeSwap, limit liquidity USD ${config.PancakeSwap_MinLiquidity} volume ${config.PancakeSwap_MinVol24} txcount ${config.PancakeSwap_MinTxCount24}`);
// prepare phase, read allowlist
const allowlist: string[] = readJsonFile(getChainAllowlistPath(SmartChain)) as string[];
const pairs = await getTradingPairs(config.PancakeSwap_TradingPairsUrl, config.PancakeSwap_TradingPairsQuery);
const filtered: PairInfo[] = [];
pairs.forEach(x => {
@ -32,7 +27,7 @@ async function retrievePancakeSwapPairs(): Promise<PairInfo[]> {
if (typeof(x) === "object") {
const pairInfo = x as PairInfo;
if (pairInfo) {
if (checkTradingPair(pairInfo, SmartChain, config.PancakeSwap_MinLiquidity, config.PancakeSwap_MinVol24, config.PancakeSwap_MinTxCount24, allowlist, PrimaryTokens)) {
if (checkTradingPair(pairInfo, config.PancakeSwap_MinLiquidity, config.PancakeSwap_MinVol24, config.PancakeSwap_MinTxCount24, PrimaryTokens)) {
filtered.push(pairInfo);
}
}

View File

@ -1,8 +1,6 @@
// Interfacing with TheGraph subgraph APIs
import axios from "axios";
import { getChainAssetLogoPath } from "../generic/repo-structure";
import { isPathExistsSync } from "../generic/filesystem";
export interface TokenInfo {
id: string;
@ -40,18 +38,6 @@ export async function getTradingPairs(apiUrl: string, subgraphQuery: string): Pr
}
}
function checkBSCTokenExists(id: string, chainName: string, tokenAllowlist: string[]): boolean {
const logoPath = getChainAssetLogoPath(chainName, id);
if (!isPathExistsSync(logoPath)) {
return false;
}
if (tokenAllowlist.find(t => (id.toLowerCase() === t.toLowerCase())) === undefined) {
//console.log(`Token not found in allowlist, ${id}`);
return false;
}
return true;
}
function isTokenPrimary(token: TokenInfo, primaryTokens: string[]): boolean {
return (primaryTokens.find(t => (t === token.symbol.toUpperCase())) != undefined);
}
@ -68,9 +54,7 @@ export function primaryTokenIndex(pair: PairInfo, primaryTokens: string[]): numb
}
// Verify a trading pair, whether we support the tokens, has enough liquidity, etc.
export function checkTradingPair(pair: PairInfo, chainName: string,
minLiquidity: number, minVol24: number, minTxCount24: number,
tokenAllowlist: string[], primaryTokens: string[]
export function checkTradingPair(pair: PairInfo, minLiquidity: number, minVol24: number, minTxCount24: number, primaryTokens: string[]
): boolean {
if (!pair.id || !pair.reserveUSD || !pair.volumeUSD || !pair.txCount || !pair.token0 || !pair.token1) {
return false;
@ -87,14 +71,6 @@ export function checkTradingPair(pair: PairInfo, chainName: string,
console.log("pair with low tx count:", pair.token0.symbol, "--", pair.token1.symbol, " ", pair.txCount);
return false;
}
if (!checkBSCTokenExists(pair.token0.id, chainName, tokenAllowlist)) {
console.log("pair with unsupported 1st coin:", pair.token0.symbol, "--", pair.token1.symbol);
return false;
}
if (!checkBSCTokenExists(pair.token1.id, chainName, tokenAllowlist)) {
console.log("pair with unsupported 2nd coin:", pair.token0.symbol, "--", pair.token1.symbol);
return false;
}
if (primaryTokenIndex(pair, primaryTokens) == 0) {
console.log("pair with no primary coin:", pair.token0.symbol, "--", pair.token1.symbol);
return false;

View File

@ -4,10 +4,13 @@ import { readJsonFile, writeJsonFile } from "../generic/json";
import { diff } from "jsondiffpatch";
import { tokenInfoFromTwApi, TokenTwInfo } from "../generic/asset";
import {
getChainAssetLogoPath,
getChainAllowlistPath,
getChainTokenlistBasePath,
getChainTokenlistPath
getChainTokenlistPath,
} from "../generic/repo-structure";
import * as bluebird from "bluebird";
import { isPathExistsSync } from "../generic/filesystem";
class Version {
major: number
@ -162,6 +165,19 @@ function addPairToToken(pairToken: TokenItem, token: TokenItem, list: List): voi
tokenInList.pairs.push(new Pair(pairToken.asset));
}
function checkTokenExists(id: string, chainName: string, tokenAllowlist: string[]): boolean {
const logoPath = getChainAssetLogoPath(chainName, id);
if (!isPathExistsSync(logoPath)) {
//console.log("logo file missing", logoPath);
return false;
}
if (tokenAllowlist.find(t => (id.toLowerCase() === t.toLowerCase())) === undefined) {
//console.log(`Token not found in allowlist, ${id}`);
return false;
}
return true;
}
export async function addPairIfNeeded(token0: TokenItem, token1: TokenItem, list: List): Promise<void> {
await addTokenIfNeeded(token0, list);
await addTokenIfNeeded(token1, list);
@ -206,6 +222,24 @@ export async function rebuildTokenlist(chainName: string, pairs: [TokenItem, Tok
return;
}
// filter out missing tokens
// prepare phase, read allowlist
const allowlist: string[] = readJsonFile(getChainAllowlistPath(chainName)) as string[];
const pairs2: [TokenItem, TokenItem][] = [];
pairs.forEach(p => {
if (!checkTokenExists(p[0].address, chainName, allowlist)) {
console.log("pair with unsupported 1st coin:", p[0].symbol, "--", p[1].symbol);
return;
}
if (!checkTokenExists(p[1].address, chainName, allowlist)) {
console.log("pair with unsupported 2nd coin:", p[0].symbol, "--", p[1].symbol);
return;
}
pairs2.push(p);
});
const filteredCount: number = pairs.length - pairs2.length;
console.log(`${filteredCount} unsupported tokens filtered out, ${pairs2.length} pairs`);
const tokenlistFile = getChainTokenlistPath(chainName);
{
// show current size
@ -218,7 +252,7 @@ export async function rebuildTokenlist(chainName: string, pairs: [TokenItem, Tok
const list: List = json as List;
console.log(`Tokenlist base: ${list.tokens.length} tokens`);
await bluebird.each(pairs, async (p) => {
await bluebird.each(pairs2, async (p) => {
await addPairIfNeeded(p[0], p[1], list);
});
console.log(`Tokenlist updated: ${list.tokens.length} tokens`);