Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PINATA_KEY=your-pinata-key
PINATA_SECRET=your-pinata-secret
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build
build
.env
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Token Lists

Automativally generate Token Lists

```bash
Expand All @@ -7,4 +8,12 @@ yarn

# Generate Coingecko list
yarn coingecko
```
```

## Download images

There's a script that will fetch all images form the CowSwap list and store them in `src/public/images/<chainId>/<address>.png`

```
yarn downloadImages
```
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
"scripts": {
"build": "npm run public && npm run coingecko",
"coingecko": "node src/coingecko.js",
"downloadImages": "node --experimental-json-modules src/downloadImages",
"uploadAndUpdateImages": "node src/uploadAndUpdateImages.js",
"public": "copyfiles src/public/*.json build/lists -f"
},
"license": "(MIT OR Apache-2.0)",
"dependencies": {
"@pinata/sdk": "^2.1.0",
"axios": "^1.0.0",
"node-fetch": "^3.2.10"
"dotenv": "^16.0.3",
"node-fetch": "^3.3.0"
},
"devDependencies": {
"@types/node": "^18.11.11",
"copyfiles": "^2.4.1"
}
}
31 changes: 31 additions & 0 deletions src/downloadImages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import cowSwapList from './public/CowSwap.json' assert { type: "json" }
import fetch from 'node-fetch';
import {createWriteStream, existsSync} from 'fs'
import path, {dirname} from 'path'
import { fileURLToPath } from 'url';



async function main() {
for(const token of cowSwapList.tokens) {
const { symbol, name, address, chainId, logoURI } = token
const filePath = `public/images/${chainId}/${address}.png`
const dirName = dirname(fileURLToPath(import.meta.url))
const absolutePath = path.join(dirName, filePath)

if (existsSync(absolutePath)) {
console.log(`Skip: ${symbol} (${name}) - Image already exists`)
continue
}

console.log(`Download image for ${symbol} (${name})
URI: ${logoURI}
File: ${filePath}\n`)
const fileStream = createWriteStream(absolutePath);
const response = await fetch(logoURI)
response.body.pipe(fileStream)
}
}


main().catch(console.error)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions src/uploadAndUpdateImages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import dotenv from 'dotenv'
import pinataSdk from '@pinata/sdk'
import {createReadStream} from 'fs'
import { strict as assert } from 'node:assert'
import path, {dirname} from 'path'
import { fileURLToPath } from 'url';

dotenv.config()
const PINATA_KEY = process.env.PINATA_KEY
assert(PINATA_KEY, 'PINATA_KEY is required environment variable')
const PINATA_SECRET = process.env.PINATA_SECRET
assert(PINATA_KEY, 'PINATA_SECRET is required environment variable')
const pinata = new pinataSdk(PINATA_KEY, PINATA_SECRET);

async function main() {
// const result = await pinata.testAuthentication()
// console.log(result)
const dirName = dirname(fileURLToPath(import.meta.url))
const absolutePath = path.join(dirName, './public/images/1/0x0ae055097c6d159879521c384f1d2123d1f195e6.png')
const fileRS = createReadStream(absolutePath)
const options = {
pinataMetadata: {
name: '0x0ae055097c6d159879521c384f1d2123d1f195e6.png',
keyvalues: {
symbol: 'xDAI',
name: 'xDAI'
}
},
// pinataOptions: {
// cidVersion: 0
// }
};
// TODO: Read directories per network. Upload image, get IPFS, update image link in the CowSwap.json
// {
// IpfsHash: 'QmTtPRDopH7vJZoe8mJoAF4rMEPqFRCqFLrHiv14ARkCxn',
// PinSize: 2119,
// Timestamp: '2022-12-08T13:12:46.964Z'
// }
const result = await pinata.pinFileToIPFS(fileRS, options)

console.log('Result', result)
}


main().catch(console.error)
Loading