forked from SmolDapp/tokenAssets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,862 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import createKeccakHash from 'keccak' | ||
|
||
const DataDirectory = "./tokens"; | ||
const IndexName = "list.json"; | ||
|
||
function toChecksumAddress(address) { | ||
address = address.toLowerCase().replace('0x', '') | ||
var hash = createKeccakHash('keccak256').update(address).digest('hex') | ||
var ret = '0x' | ||
|
||
for (var i = 0; i < address.length; i++) { | ||
if (parseInt(hash[i], 16) >= 8) { | ||
ret += address[i].toUpperCase() | ||
} else { | ||
ret += address[i] | ||
} | ||
} | ||
|
||
return ret | ||
} | ||
|
||
const perChain = {}; | ||
function generate(directory) { | ||
for (let name of fs.readdirSync(directory)) { | ||
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue; | ||
const file = path.join(directory, name); | ||
const stat = fs.lstatSync(file); | ||
if (stat.isDirectory()) { | ||
if (name.startsWith("0x")) { | ||
const currentChain = Number(directory.split("/").pop()); | ||
if (perChain[currentChain] === undefined) { | ||
perChain[currentChain] = []; | ||
} | ||
perChain[currentChain].push(toChecksumAddress(name)); | ||
} | ||
generate(file); | ||
} | ||
} | ||
} | ||
|
||
const cwd = process.cwd(); | ||
if (!fs.existsSync(path.join(cwd, ".git"))) { | ||
console.error("Error: script should be run in the root of the repo."); | ||
process.exit(1); | ||
} | ||
|
||
try { | ||
generate(DataDirectory); | ||
for (const chain in perChain) { | ||
//load the existing list | ||
const previousLists = fs.existsSync(path.join(DataDirectory, chain, IndexName)) ? JSON.parse(fs.readFileSync(path.join(DataDirectory, chain, IndexName))) : {}; | ||
if (!previousLists.version) { | ||
previousLists.version = { | ||
'major': 0, | ||
'minor': 0, | ||
'patch': 0 | ||
}; | ||
} | ||
if (!previousLists.tokens) { | ||
previousLists.tokens = []; | ||
} | ||
const newList = { | ||
version: previousLists.version, | ||
tokens: perChain[chain] | ||
} | ||
//compare the new list with the old one | ||
if (JSON.stringify(previousLists.tokens) === JSON.stringify(newList.tokens)) { | ||
console.log(`No changes detected for chain ${chain}`); | ||
} else if (previousLists.tokens.length > newList.tokens.length) { | ||
// At least one token was removed | ||
newList.version.major = previousLists.version.major + 1; | ||
newList.version.minor = 0; | ||
newList.version.patch = 0; | ||
} else if (previousLists.tokens.length < newList.tokens.length) { | ||
// At least one token was added | ||
newList.version.major = previousLists.version.major; | ||
newList.version.minor = previousLists.version.minor + 1; | ||
newList.version.patch = 0; | ||
} else { | ||
// The list has the same length, but at least one token was changed. This should never happen somehown | ||
newList.version.major = previousLists.version.major; | ||
newList.version.minor = previousLists.version.minor; | ||
newList.version.patch = previousLists.version.patch + 1; | ||
} | ||
|
||
fs.writeFileSync(path.join(DataDirectory, chain, IndexName), JSON.stringify(newList, null, 4)); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: 📑 Updating lists | ||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
if: "!contains(github.event.head_commit.message, '[bot] - Update lists')" | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
with: | ||
persist-credentials: false | ||
fetch-depth: 0 | ||
|
||
- name: Use Node 14.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
|
||
- name: Install deps | ||
run: npm install | ||
|
||
- name: Build token lists | ||
run: node ./.github/scripts/generate-lists.mjs | ||
|
||
- name: Commit files | ||
run: | | ||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git commit -a -m "[bot] - Update lists" | ||
- name: Temporarily disable "include administrators" branch protection | ||
uses: benjefferies/branch-protection-bot@master | ||
if: always() | ||
with: | ||
access_token: ${{ secrets.ACCESS_TOKEN }} | ||
branch: ${{ github.event.repository.default_branch }} | ||
enforce_admins: false | ||
|
||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.ACCESS_TOKEN }} | ||
branch: ${{ github.ref }} | ||
|
||
- name: Enable "include administrators" branch protection | ||
uses: benjefferies/branch-protection-bot@master | ||
if: always() # Force to always run this step to ensure "include administrators" is always turned back on | ||
with: | ||
access_token: ${{ secrets.ACCESS_TOKEN }} | ||
owner: smoldapp | ||
repo: tokenAssets | ||
branch: ${{ github.event.repository.default_branch }} | ||
enforce_admins: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.