From dd56b0122a7849cd838f61a13e0f4dbee20afa0c Mon Sep 17 00:00:00 2001 From: Adam R <13562139+catenocrypt@users.noreply.github.com> Date: Mon, 8 Feb 2021 11:23:34 +0100 Subject: [PATCH] [Internal] Enforce values for type in info files (#5513) * Generate missing info files for ETC tokens. * Add missing waves info files * Revert * Fix wanchain ID casing. * Enforce values for type in info files. Co-authored-by: Catenocrypt --- .../info.json | 2 +- .../info.json | 2 +- .../info.json | 2 +- .../info.json | 2 +- .../info.json | 2 +- blockchains/ontology/assets/ong/info.json | 2 +- .../info.json | 2 +- .../info.json | 2 +- .../info.json | 2 +- .../info.json | 2 +- script/generic/asset-infos.ts | 30 +++++++++++++++++-- 11 files changed, 38 insertions(+), 12 deletions(-) diff --git a/blockchains/gochain/assets/0x064353B5C02A9F35979524Ebbfff4042151cF0c6/info.json b/blockchains/gochain/assets/0x064353B5C02A9F35979524Ebbfff4042151cF0c6/info.json index 592ca3de9..f05db9ce9 100644 --- a/blockchains/gochain/assets/0x064353B5C02A9F35979524Ebbfff4042151cF0c6/info.json +++ b/blockchains/gochain/assets/0x064353B5C02A9F35979524Ebbfff4042151cF0c6/info.json @@ -1,7 +1,7 @@ { "name": "BosTravel", "symbol": "BOT", - "type": "G020", + "type": "GO20", "decimals": 18, "description": "-", "website": "", diff --git a/blockchains/gochain/assets/0x473A70391d961D1D81044f7e2b69eeCd59dc355c/info.json b/blockchains/gochain/assets/0x473A70391d961D1D81044f7e2b69eeCd59dc355c/info.json index de6510ee0..4856d1cc6 100644 --- a/blockchains/gochain/assets/0x473A70391d961D1D81044f7e2b69eeCd59dc355c/info.json +++ b/blockchains/gochain/assets/0x473A70391d961D1D81044f7e2b69eeCd59dc355c/info.json @@ -1,7 +1,7 @@ { "name": "GoDental", "symbol": "GOD", - "type": "G020", + "type": "GO20", "decimals": 18, "description": "-", "website": "", diff --git a/blockchains/gochain/assets/0x53A6Bec3126BCE4e0dE349a9Ad3D9e4F997E76C4/info.json b/blockchains/gochain/assets/0x53A6Bec3126BCE4e0dE349a9Ad3D9e4F997E76C4/info.json index c184adbb4..88d5228d8 100644 --- a/blockchains/gochain/assets/0x53A6Bec3126BCE4e0dE349a9Ad3D9e4F997E76C4/info.json +++ b/blockchains/gochain/assets/0x53A6Bec3126BCE4e0dE349a9Ad3D9e4F997E76C4/info.json @@ -1,7 +1,7 @@ { "name": "Lam Anh Dental", "symbol": "LAD", - "type": "G020", + "type": "GO20", "decimals": 18, "description": "-", "website": "", diff --git a/blockchains/gochain/assets/0x721Cc970CB5A22915f7663a6833E605deDDb7B92/info.json b/blockchains/gochain/assets/0x721Cc970CB5A22915f7663a6833E605deDDb7B92/info.json index 409790606..143c28cf6 100644 --- a/blockchains/gochain/assets/0x721Cc970CB5A22915f7663a6833E605deDDb7B92/info.json +++ b/blockchains/gochain/assets/0x721Cc970CB5A22915f7663a6833E605deDDb7B92/info.json @@ -1,7 +1,7 @@ { "name": "PAZTether", "symbol": "PAZT", - "type": "G020", + "type": "GO20", "decimals": 18, "description": "-", "website": "", diff --git a/blockchains/gochain/assets/0xB881f9bB7EEa9499073c279D6eAC59B1A9010617/info.json b/blockchains/gochain/assets/0xB881f9bB7EEa9499073c279D6eAC59B1A9010617/info.json index 95d816a41..af3b346e1 100644 --- a/blockchains/gochain/assets/0xB881f9bB7EEa9499073c279D6eAC59B1A9010617/info.json +++ b/blockchains/gochain/assets/0xB881f9bB7EEa9499073c279D6eAC59B1A9010617/info.json @@ -1,7 +1,7 @@ { "name": "Go A2ZHome", "symbol": "A2Z", - "type": "G020", + "type": "GO20", "decimals": 18, "description": "-", "website": "", diff --git a/blockchains/ontology/assets/ong/info.json b/blockchains/ontology/assets/ong/info.json index 8d063406d..df88bcea6 100644 --- a/blockchains/ontology/assets/ong/info.json +++ b/blockchains/ontology/assets/ong/info.json @@ -1,7 +1,7 @@ { "name": "Ontology Gas", "symbol": "ONG", - "type": "gas", + "type": "ontology", "decimals": 9, "description": "-", "website": "", diff --git a/blockchains/tomochain/assets/0x01F83cE6636179b54b0CC0C408f9a8bce40ae776/info.json b/blockchains/tomochain/assets/0x01F83cE6636179b54b0CC0C408f9a8bce40ae776/info.json index 0579def68..d141d041f 100644 --- a/blockchains/tomochain/assets/0x01F83cE6636179b54b0CC0C408f9a8bce40ae776/info.json +++ b/blockchains/tomochain/assets/0x01F83cE6636179b54b0CC0C408f9a8bce40ae776/info.json @@ -1,7 +1,7 @@ { "name": "PayFrequent EURO", "symbol": "PEUR", - "type": "TRC20", + "type": "TRC21", "decimals": 6, "description": "-", "website": "", diff --git a/blockchains/tomochain/assets/0x5e55D0c59287F5F8d540eF0766cA3F3810C71B84/info.json b/blockchains/tomochain/assets/0x5e55D0c59287F5F8d540eF0766cA3F3810C71B84/info.json index 95a9ef57a..813dfaf12 100644 --- a/blockchains/tomochain/assets/0x5e55D0c59287F5F8d540eF0766cA3F3810C71B84/info.json +++ b/blockchains/tomochain/assets/0x5e55D0c59287F5F8d540eF0766cA3F3810C71B84/info.json @@ -1,7 +1,7 @@ { "name": "PayFrequent", "symbol": "PayFQ", - "type": "TRC20", + "type": "TRC21", "decimals": 6, "description": "-", "website": "", diff --git a/blockchains/tomochain/assets/0x936b1F7290c8CFC57e31D7e4a301D5F9fA5B0cd8/info.json b/blockchains/tomochain/assets/0x936b1F7290c8CFC57e31D7e4a301D5F9fA5B0cd8/info.json index 50b596c4c..c5481e0ea 100644 --- a/blockchains/tomochain/assets/0x936b1F7290c8CFC57e31D7e4a301D5F9fA5B0cd8/info.json +++ b/blockchains/tomochain/assets/0x936b1F7290c8CFC57e31D7e4a301D5F9fA5B0cd8/info.json @@ -1,7 +1,7 @@ { "name": "24x7 Crypto", "symbol": "24x7", - "type": "TRC20", + "type": "TRC21", "decimals": 4, "description": "-", "website": "", diff --git a/blockchains/tomochain/assets/0xcE98172f4fC9Ad02da607843A2C211b7834431da/info.json b/blockchains/tomochain/assets/0xcE98172f4fC9Ad02da607843A2C211b7834431da/info.json index a19df6df4..fe8522cdc 100644 --- a/blockchains/tomochain/assets/0xcE98172f4fC9Ad02da607843A2C211b7834431da/info.json +++ b/blockchains/tomochain/assets/0xcE98172f4fC9Ad02da607843A2C211b7834431da/info.json @@ -1,7 +1,7 @@ { "name": "PayFrequent USD", "symbol": "PUSD", - "type": "TRC20", + "type": "TRC21", "decimals": 6, "description": "-", "website": "", diff --git a/script/generic/asset-infos.ts b/script/generic/asset-infos.ts index bbd90c919..c8846b6b7 100644 --- a/script/generic/asset-infos.ts +++ b/script/generic/asset-infos.ts @@ -24,7 +24,7 @@ function isAssetInfoHasAllKeys(info: unknown, path: string): [boolean, string] { return [hasAllKeys, `Info at path '${path}' missing next key(s): ${arrayDiff(requiredKeys, infoKeys)}`]; } -function isAssetInfoValid(info: unknown, path: string, address: string): [string, string] { +function isAssetInfoValid(info: unknown, path: string, address: string, chain: string): [string, string] { const isKeys1CorrectType = typeof info['name'] === "string" && info['name'] !== "" && typeof info['type'] === "string" && info['type'] !== "" && @@ -35,6 +35,10 @@ function isAssetInfoValid(info: unknown, path: string, address: string): [string return [`Check keys1 '${info['name']}' '${info['type']}' '${info['symbol']}' '${info['decimals']}' '${info['id']}' ${path}`, ""]; } + if (typeof info['type'] !== "string" || chainFromAssetType(info['type']) !== chain ) { + return [`Incorrect type '${info['type']}' '${chain}' '${path}`, ""]; + } + if (typeof info['id'] !== "string" || info['id'] !== address ) { return [`Incorrect id '${info['id']}' '${path}`, ""]; } @@ -56,6 +60,28 @@ function isAssetInfoValid(info: unknown, path: string, address: string): [string return ["", ""]; } +export function chainFromAssetType(type: string): string { + switch (type) { + case "ERC20": return "ethereum"; + case "BEP2": return "binance"; + case "BEP20": return "smartchain"; + case "ETC20": return "classic"; + case "TRC10": + case "TRC20": + return "tron"; + case "WAN20": return "wanchain"; + case "TRC21": return "tomochain"; + case "TT20": return "thundertoken"; + case "SPL": return "solana"; + case "GO20": return "gochain"; + case "KAVA": return "kava"; + case "NEP5": return "neo"; + case "NRC20": return "nuls"; + case "VET": return "vechain"; + case "ontology": return "ontology"; + } +} + export function explorerUrl(chain: string, contract: string): string { if (contract) { switch (chain.toLowerCase()) { @@ -146,7 +172,7 @@ function isAssetInfoOK(chain: string, address: string, errors: string[], warning errors.push(msg1); } - const [err2, warn2] = isAssetInfoValid(info, assetInfoPath, address); + const [err2, warn2] = isAssetInfoValid(info, assetInfoPath, address, chain); if (err2) { errors.push(err2); }