-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dragonswap-app:feature/sync-tokenlist
New tokenlist, validation, logos
- Loading branch information
Showing
27 changed files
with
419 additions
and
23 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,2 @@ | ||
node_modules | ||
dist/ |
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 @@ | ||
npm run check-filenames |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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,28 @@ | ||
{ | ||
"name": "assets", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"check-filenames": "npx tsc && node dist/precommit.js", | ||
"prepare": "husky" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "dist/precommit.js" | ||
} | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"husky": "^9.0.11", | ||
"viem": "^2.8.9", | ||
"zod": "^3.22.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.11.28", | ||
"typescript": "^5.4.2" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { isAddress, getAddress } from "viem"; | ||
import { tokensSchema } from "./tokensSchema.js"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const logosDir = path.join(__dirname, "../logos"); | ||
|
||
const tokenList = JSON.parse( | ||
fs.readFileSync(path.join(__dirname, "../tokenlist.json"), "utf8") | ||
); | ||
|
||
const val = tokensSchema.safeParse(tokenList); | ||
|
||
if (!val.success) { | ||
throw new Error(`Invalid tokens.json: ${val.error.message}`); | ||
} | ||
|
||
fs.readdir(logosDir, (err, files) => { | ||
if (err) { | ||
throw new Error(`Error reading directory: ${err}`); | ||
} | ||
|
||
files.forEach((file) => { | ||
const filePath = path.join(logosDir, file); | ||
fs.stat(filePath, (err, stats) => { | ||
if (err) { | ||
throw new Error(`Error getting file stats: ${err}`); | ||
} | ||
|
||
if (stats.isDirectory()) { | ||
if (!isAddress(file, { strict: true })) { | ||
throw new Error( | ||
`${file} is not checksum encoded! Here's the encoded version: ${getAddress( | ||
file | ||
)}` | ||
); | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
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,23 @@ | ||
import { getAddress, isAddress } from "viem"; | ||
import { z } from "zod"; | ||
|
||
const tokensSchema = z.object({ | ||
tokens: z.array( | ||
z | ||
.object({ | ||
chainId: z.number(), | ||
address: z | ||
.string() | ||
.refine(isAddress, { message: "Invalid address" }) | ||
.transform((val) => getAddress(val)), | ||
decimals: z.number(), | ||
name: z.string(), | ||
about: z.string(), | ||
symbol: z.string(), | ||
tags: z.array(z.string()), | ||
}) | ||
.strict() | ||
), | ||
}); | ||
|
||
export { tokensSchema }; |
Oops, something went wrong.