[internal] Allowlist: auto-allow only assets with both logo and info (#4877)

* Allowlist: auto-allow only assets with both logo and info.

* Rmove unsed imports.

* Lint fix

* Lint

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2020-11-20 11:40:44 +01:00 committed by GitHub
parent 0aa5690704
commit e785fae5cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,12 +1,20 @@
import { chainsWithDenylist } from "./blockchains";
import {
getChainAssetsList,
getChainAssetInfoPath,
getChainAssetLogoPath,
//getChainAssetsList,
getChainAssetsPath,
getChainAllowlistPath,
getChainDenylistPath
} from "./repo-structure";
import { readFileSync, writeFileSync } from "./filesystem";
import {
arrayDiff,
isPathExistsSync,
readDirSync,
readFileSync,
writeFileSync
} from "./filesystem";
import {
//arrayDiff,
arrayDiffNocase,
findCommonElementsOrDuplicates,
makeUnique
@ -15,10 +23,35 @@ import { ActionInterface, CheckStepInterface } from "./interface";
import { formatSortJson } from "./json";
import * as bluebird from "bluebird";
// Find assets for which full info is available -- logo+info -- and is not in the allowlist
async function findFullAssetsWithNoAllow(chain: string, allowlist: string[]): Promise<string[]> {
const list: string[] = [];
const assetsPath = getChainAssetsPath(chain);
if (!isPathExistsSync(assetsPath)) {
return list;
}
await bluebird.mapSeries(readDirSync(assetsPath), async asset => {
if (allowlist.includes(asset)) {
// present in allowlist, skip
return;
}
const logoPath = getChainAssetLogoPath(chain, asset);
if (!isPathExistsSync(logoPath)) {
return;
}
const infoPath = getChainAssetInfoPath(chain, asset);
if (!isPathExistsSync(infoPath)) {
return;
}
// both files exist, not in allowlist
list.push(asset);
});
return list;
}
async function checkUpdateAllowDenyList(chain: string, checkOnly: boolean ): Promise<[boolean, string[], string[]]> {
const errorMsgs: string[] = [];
const warningMsgs: string[] = [];
const assets = getChainAssetsList(chain);
const allowlistPath = getChainAllowlistPath(chain);
const denylistPath = getChainDenylistPath(chain);
@ -32,16 +65,18 @@ async function checkUpdateAllowDenyList(chain: string, checkOnly: boolean ): Pro
if (commonElementsOrDuplicates && commonElementsOrDuplicates.length > 0) {
errorMsgs.push(`Denylist and allowlist for chain ${chain} should have no common elements or duplicates, found ${commonElementsOrDuplicates.length} ${commonElementsOrDuplicates[0]}`);
}
//const assetsWithLogo = getChainAssetsList(chain);
const assetsWithInfoNotInAllow = await findFullAssetsWithNoAllow(chain, currentAllowlist);
/*
const allowlistOrphan = arrayDiff(currentAllowlist, assets);
const allowlistOrphan = arrayDiff(currentAllowlist, assetsWithLogo);
if (allowlistOrphan && allowlistOrphan.length > 0) {
// warning only
warningMsgs.push(`Allowlist for chain ${chain} contains non-exitent assets, found ${allowlistOrphan.length}, ${allowlistOrphan[0]}`);
warningMsgs.push(`Allowlist for chain ${chain} contains non-exitent assetsWithLogo, found ${allowlistOrphan.length}, ${allowlistOrphan[0]}`);
}
*/
//const newDeny = makeUnique(currentDenylist.concat(allowlistOrphan));
const tempAssetsOrAllow = makeUnique(currentAllowlist.concat(assets));
const tempAssetsOrAllow = makeUnique(currentAllowlist.concat(assetsWithInfoNotInAllow));
const newAllow = makeUnique(arrayDiffNocase(tempAssetsOrAllow, currentDenylist));
//console.log(currentAllowlist.length, "vs.", newAllow.length);
//console.log(currentDenylist.length, "vs.", newDeny.length);