Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
DeFliTeam authored Oct 26, 2023
2 parents baa004c + 9e75b01 commit a4ae72b
Show file tree
Hide file tree
Showing 46 changed files with 1,862 additions and 12 deletions.
93 changes: 93 additions & 0 deletions .github/scripts/generate-lists.mjs
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);
}
2 changes: 1 addition & 1 deletion .github/scripts/verify-chains.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function validate(directory) {
allValid = false;
} else {
const svgValue = fs.readFileSync(path.join(file, "logo.svg"));
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:image/jpeg;base64`)) {
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:img/png;base64`) || svgValue.includes(`data:image/jpeg;base64`) || svgValue.includes(`data:img/jpeg;base64`)) {
console.error(`Error: "${file}" logo.svg contains base64 encoded image.`);
allValid = false;
}
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/verify-tokens.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function validate(directory) {
allValid = false;
} else {
const svgValue = fs.readFileSync(path.join(file, "logo.svg"));
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:image/jpeg;base64`)) {
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:img/png;base64`) || svgValue.includes(`data:image/jpeg;base64`) || svgValue.includes(`data:img/jpeg;base64`)) {
console.error(`Error: "${file}" logo.svg contains base64 encoded image.`);
allValid = false;
}
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/build.yml
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ async function resolveNotFound(request: Request): Promise<Response> {
if (fallback === 'true') {
const baseURI = (process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : (request as any)?.nextUrl?.origin);
const result = await fetch(`${baseURI}/not-found.png`);
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=60, stale-while-revalidate=3600, must-revalidate'}});
}

if (fallback) {
const result = await fetch(fallback);
const contentTypeFromFallback = result.headers.get('Content-Type');
if (contentTypeFromFallback?.startsWith('image/')) {
console.warn(`Using fallback image for gas token: ${fallback}`);
return new Response(result.body, {headers: {'Content-Type': contentTypeFromFallback, 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
return new Response(result.body, {headers: {'Content-Type': contentTypeFromFallback, 'Cache-Control': 'public, max-age=60, stale-while-revalidate=3600, must-revalidate'}});
}
}
return new Response('Not found', {status: 404});
Expand All @@ -30,14 +30,14 @@ async function resolveGasToken(request: Request): Promise<Response> {
if (fallback === 'true') {
const baseURI = (process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : (request as any)?.nextUrl?.origin);
const result = await fetch(`${baseURI}/gas-token.png`);
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=60, stale-while-revalidate=3600, must-revalidate'}});
}
if (fallback) {
const result = await fetch(fallback);
const contentTypeFromFallback = result.headers.get('Content-Type');
if (contentTypeFromFallback?.startsWith('image/')) {
console.warn(`Using fallback image for gas token: ${fallback}`);
return new Response(result.body, {headers: {'Content-Type': contentTypeFromFallback, 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
return new Response(result.body, {headers: {'Content-Type': contentTypeFromFallback, 'Cache-Control': 'public, max-age=60, stale-while-revalidate=3600, must-revalidate'}});
}
}
return new Response('Not found', {status: 404});
Expand All @@ -58,9 +58,9 @@ export async function GET(request: Request, context: TContext): Promise<Response
const result = await fetch(`${baseURI}/tokens/${chainIDStr}/${tokenAddress}/${fileName}`);
if (result.ok) {
if (fileName.endsWith('.svg')) {
return new Response(result.body, {headers: {'Content-Type': 'image/svg+xml', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
return new Response(result.body, {headers: {'Content-Type': 'image/svg+xml', 'Cache-Control': 'public, max-age=60, stale-while-revalidate=3600, must-revalidate'}});
}
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=60, stale-while-revalidate=3600, must-revalidate'}});
}

if (tokenAddress === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
Expand Down
Loading

0 comments on commit a4ae72b

Please sign in to comment.