Skip to content

Commit

Permalink
feat: update generate-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Apr 9, 2024
1 parent f02f9ce commit 6f52ac8
Show file tree
Hide file tree
Showing 3 changed files with 1,364 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/scripts/generate-lists.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if (!fs.existsSync(path.join(cwd, '.git'))) {

try {
generate(DataDirectory);
const aggregatedTokens = {}
for (const chain in perChain) {
//load the existing list
const previousLists = fs.existsSync(path.join(DataDirectory, chain, IndexName))
Expand All @@ -67,6 +68,7 @@ try {
version: previousLists.version,
tokens: perChain[chain]
};
aggregatedTokens[Number(chain)] = 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}`);
Expand All @@ -89,6 +91,47 @@ try {

fs.writeFileSync(path.join(DataDirectory, chain, IndexName), JSON.stringify(newList, null, 4));
}

const previousAggrLists = fs.existsSync(path.join(DataDirectory, IndexName))
? JSON.parse(fs.readFileSync(path.join(DataDirectory, IndexName)))
: {};
if (!previousAggrLists.version) {
previousAggrLists.version = {
major: 0,
minor: 0,
patch: 0
};
}
if (!previousAggrLists.tokens) {
previousAggrLists.tokens = [];
}
const newList = {
version: previousAggrLists.version,
tokens: aggregatedTokens
};

//compare the new list with the old one
if (JSON.stringify(previousAggrLists.tokens) === JSON.stringify(newList.tokens)) {
console.log(`No changes detected for general list`);
} else if (previousAggrLists.tokens.length > newList.tokens.length) {
// At least one token was removed
newList.version.major = previousAggrLists.version.major + 1;
newList.version.minor = 0;
newList.version.patch = 0;
} else if (previousAggrLists.tokens.length < newList.tokens.length) {
// At least one token was added
newList.version.major = previousAggrLists.version.major;
newList.version.minor = previousAggrLists.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 = previousAggrLists.version.major;
newList.version.minor = previousAggrLists.version.minor;
newList.version.patch = previousAggrLists.version.patch + 1;
}


fs.writeFileSync(path.join(DataDirectory, IndexName), JSON.stringify(newList, null, 4));
} catch (error) {
console.error(error);
process.exit(1);
Expand Down
10 changes: 10 additions & 0 deletions tokens/81457/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": {
"major": 0,
"minor": 1,
"patch": 0
},
"tokens": [
"0x000000dAA580e54635a043D2773f2c698593836a"
]
}
Loading

0 comments on commit 6f52ac8

Please sign in to comment.