Skip to content

Commit 6f52ac8

Browse files
committed
feat: update generate-lists
1 parent f02f9ce commit 6f52ac8

3 files changed

Lines changed: 1364 additions & 0 deletions

File tree

.github/scripts/generate-lists.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ if (!fs.existsSync(path.join(cwd, '.git'))) {
4848

4949
try {
5050
generate(DataDirectory);
51+
const aggregatedTokens = {}
5152
for (const chain in perChain) {
5253
//load the existing list
5354
const previousLists = fs.existsSync(path.join(DataDirectory, chain, IndexName))
@@ -67,6 +68,7 @@ try {
6768
version: previousLists.version,
6869
tokens: perChain[chain]
6970
};
71+
aggregatedTokens[Number(chain)] = perChain[chain];
7072
//compare the new list with the old one
7173
if (JSON.stringify(previousLists.tokens) === JSON.stringify(newList.tokens)) {
7274
console.log(`No changes detected for chain ${chain}`);
@@ -89,6 +91,47 @@ try {
8991

9092
fs.writeFileSync(path.join(DataDirectory, chain, IndexName), JSON.stringify(newList, null, 4));
9193
}
94+
95+
const previousAggrLists = fs.existsSync(path.join(DataDirectory, IndexName))
96+
? JSON.parse(fs.readFileSync(path.join(DataDirectory, IndexName)))
97+
: {};
98+
if (!previousAggrLists.version) {
99+
previousAggrLists.version = {
100+
major: 0,
101+
minor: 0,
102+
patch: 0
103+
};
104+
}
105+
if (!previousAggrLists.tokens) {
106+
previousAggrLists.tokens = [];
107+
}
108+
const newList = {
109+
version: previousAggrLists.version,
110+
tokens: aggregatedTokens
111+
};
112+
113+
//compare the new list with the old one
114+
if (JSON.stringify(previousAggrLists.tokens) === JSON.stringify(newList.tokens)) {
115+
console.log(`No changes detected for general list`);
116+
} else if (previousAggrLists.tokens.length > newList.tokens.length) {
117+
// At least one token was removed
118+
newList.version.major = previousAggrLists.version.major + 1;
119+
newList.version.minor = 0;
120+
newList.version.patch = 0;
121+
} else if (previousAggrLists.tokens.length < newList.tokens.length) {
122+
// At least one token was added
123+
newList.version.major = previousAggrLists.version.major;
124+
newList.version.minor = previousAggrLists.version.minor + 1;
125+
newList.version.patch = 0;
126+
} else {
127+
// The list has the same length, but at least one token was changed. This should never happen somehown
128+
newList.version.major = previousAggrLists.version.major;
129+
newList.version.minor = previousAggrLists.version.minor;
130+
newList.version.patch = previousAggrLists.version.patch + 1;
131+
}
132+
133+
134+
fs.writeFileSync(path.join(DataDirectory, IndexName), JSON.stringify(newList, null, 4));
92135
} catch (error) {
93136
console.error(error);
94137
process.exit(1);

tokens/81457/list.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": {
3+
"major": 0,
4+
"minor": 1,
5+
"patch": 0
6+
},
7+
"tokens": [
8+
"0x000000dAA580e54635a043D2773f2c698593836a"
9+
]
10+
}

0 commit comments

Comments
 (0)