2019-11-08 18:55:41 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
import { getOpenseaCollectionAddresses } from "./opesea_contrats"
|
|
|
|
|
|
|
|
import {
|
2020-01-17 08:31:42 +00:00
|
|
|
Ethereum, Terra, Tron,
|
2019-11-08 18:55:41 +00:00
|
|
|
getChainAssetsPath,
|
2020-01-17 08:31:42 +00:00
|
|
|
ethSidechains,
|
2019-11-08 18:55:41 +00:00
|
|
|
readDirSync,
|
|
|
|
readFileSync,
|
|
|
|
isChainWhitelistExistSync,
|
|
|
|
isChainBlacklistExistSync,
|
|
|
|
getChainWhitelistPath,
|
|
|
|
getChainBlacklistPath,
|
|
|
|
writeFileSync,
|
|
|
|
sortDesc,
|
|
|
|
getUnique,
|
|
|
|
mapList
|
|
|
|
} from '../src/test/helpers'
|
|
|
|
|
2020-01-17 08:31:42 +00:00
|
|
|
const assetsChains = ethSidechains.concat([Terra, Tron])
|
2019-11-08 18:55:41 +00:00
|
|
|
|
|
|
|
assetsChains.forEach(async chain => {
|
|
|
|
const assets = readDirSync(getChainAssetsPath(chain))
|
|
|
|
|
|
|
|
const whitelistPath = getChainWhitelistPath(chain)
|
|
|
|
const blacklistPath = getChainBlacklistPath(chain)
|
|
|
|
|
|
|
|
//Create inital lists if they do not exists
|
|
|
|
if (!isChainWhitelistExistSync(chain)) {
|
|
|
|
writeFileSync(whitelistPath, `[]`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isChainBlacklistExistSync(chain)) {
|
|
|
|
writeFileSync(blacklistPath, `[]`)
|
|
|
|
}
|
|
|
|
|
2020-01-04 23:20:43 +00:00
|
|
|
const currentWhitelist = JSON.parse(readFileSync(whitelistPath))
|
|
|
|
const currentBlacklist = JSON.parse(readFileSync(blacklistPath))
|
2019-11-08 18:55:41 +00:00
|
|
|
|
2020-01-04 23:20:43 +00:00
|
|
|
let newBlackList = []
|
2019-11-08 18:55:41 +00:00
|
|
|
// Some chains required pulling lists from other sources
|
|
|
|
switch (chain) {
|
|
|
|
case Ethereum:
|
|
|
|
const nftList = await getOpenseaCollectionAddresses()
|
2020-01-04 23:20:43 +00:00
|
|
|
newBlackList = currentBlacklist.concat(nftList)
|
2019-11-08 18:55:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-01-05 04:51:15 +00:00
|
|
|
newBlackList = newBlackList.concat(currentBlacklist)
|
2019-11-08 18:55:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-01-04 23:20:43 +00:00
|
|
|
|
|
|
|
const removedAssets = getRemovedAddressesFromAssets(assets, currentWhitelist)
|
|
|
|
newBlackList = newBlackList.concat(removedAssets)
|
2019-11-08 18:55:41 +00:00
|
|
|
|
2020-01-04 23:20:43 +00:00
|
|
|
fs.writeFileSync(whitelistPath, JSON.stringify(sortDesc(assets), null, 4))
|
|
|
|
fs.writeFileSync(blacklistPath, JSON.stringify(getUnique(sortDesc(newBlackList)), null, 4))
|
2019-11-08 18:55:41 +00:00
|
|
|
})
|
|
|
|
|
2020-01-04 23:20:43 +00:00
|
|
|
function getRemovedAddressesFromAssets(assets: string[], whiteList: string[]): string[] {
|
|
|
|
const mappedAssets = mapList(assets)
|
|
|
|
const removed = whiteList.filter(a => !mappedAssets.hasOwnProperty(a))
|
|
|
|
return removed
|
|
|
|
}
|