Skip to content

Commit 2b8ef9d

Browse files
cowdancoderabbitai[bot]alfetopito
authored
Feat/add avalanche polygon (#921)
* chore: update `cow-sdk` and README * fix: error if the `build` folder doesn't exist * chore: refactor `downloadImages` to make it more robust * chore: update README * chore: update `.gitignore` * feat: add new networks - add `Avalanche` and `Polygon` networks - add `winston` logger * chore: update Readme * Update README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: update `tokenListsByNetwork` * feat: update issue templates with new networks * feat: update `fetchPermitInfo` scripts and add new networks * chore: improve logging * chore: add new networks to `processRequest` * chore: sync `CoinGecko` json files with `main` * fix: remove old logs context * Update src/permitInfo/fetchAllPermitInfo.ts Co-authored-by: Leandro <alfetopito@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Leandro <alfetopito@users.noreply.github.com>
1 parent 9ed1cfd commit 2b8ef9d

30 files changed

+11896
-161
lines changed

.github/ISSUE_TEMPLATE/1-addTokenForm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ body:
3434
- GNOSIS_CHAIN
3535
- ARBITRUM_ONE
3636
- BASE
37+
- POLYGON
38+
- AVALANCHE
3739
validations:
3840
required: true
3941
- type: input

.github/ISSUE_TEMPLATE/2-addImageForm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ body:
2626
- GNOSIS_CHAIN
2727
- ARBITRUM_ONE
2828
- BASE
29+
- POLYGON
30+
- AVALANCHE
2931
validations:
3032
required: true
3133
- type: input

.github/ISSUE_TEMPLATE/3-removeTokenForm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ body:
2626
- GNOSIS_CHAIN
2727
- ARBITRUM_ONE
2828
- BASE
29+
- POLYGON
30+
- AVALANCHE
2931
validations:
3032
required: true
3133
- type: input

.github/workflows/processRequest.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ name: ProcessRequest
2121

2222
on:
2323
issues:
24-
types: [ opened ]
24+
types: [opened]
2525

2626
env:
2727
# Matches labels from field forms to extract data
@@ -85,6 +85,12 @@ jobs:
8585
} else if (values.network === 'BASE') {
8686
values.chainId = 8453
8787
values.blockExplorer = 'basescan.org'
88+
} else if (values.network === 'AVALANCHE') {
89+
values.chainId = 43114
90+
values.blockExplorer = 'snowtrace.io'
91+
} else if (values.network === 'POLYGON'){
92+
values.chainId = 137
93+
values.blockExplorer = 'polygonscan.com'
8894
} else {
8995
values.chainId = 100
9096
values.blockExplorer = 'gnosisscan.io'
@@ -109,7 +115,6 @@ jobs:
109115
# force failure for testing
110116
# exit 1
111117
112-
113118
validateInput:
114119
runs-on: ubuntu-latest
115120
needs: extractInfoFromIssue
@@ -154,15 +159,15 @@ jobs:
154159
Make sure all the required fields are provided and submit a new issue
155160
156161
optimizeImage:
157-
needs: [ extractInfoFromIssue, validateInput ]
162+
needs: [extractInfoFromIssue, validateInput]
158163
uses: ./.github/workflows/optimizeImage.yml
159164
if: ${{ contains(github.event.issue.labels.*.name, 'addImage') || contains(github.event.issue.labels.*.name, 'addToken') }}
160165
with:
161166
url: ${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).url }}
162167
address: ${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}
163168

164169
addToken:
165-
needs: [ extractInfoFromIssue, optimizeImage ]
170+
needs: [extractInfoFromIssue, optimizeImage]
166171
uses: ./.github/workflows/executeAction.yml
167172
if: ${{ contains(github.event.issue.labels.*.name, 'addToken') }}
168173
secrets: inherit
@@ -171,7 +176,7 @@ jobs:
171176
issueInfo: ${{ needs.extractInfoFromIssue.outputs.issueInfo }}
172177
# Custom per type
173178
operation: addToken
174-
prTitle: "[addToken] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).symbol }}` to `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`"
179+
prTitle: '[addToken] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).symbol }}` to `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`'
175180
prBody: |
176181
Adding token `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).symbol }}` on network `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`
177182
@@ -191,14 +196,14 @@ jobs:
191196
```
192197
193198
removeToken:
194-
needs: [ extractInfoFromIssue, validateInput ]
199+
needs: [extractInfoFromIssue, validateInput]
195200
uses: ./.github/workflows/executeAction.yml
196201
if: ${{ contains(github.event.issue.labels.*.name, 'removeToken') }}
197202
secrets: inherit
198203
with:
199204
issueInfo: ${{ needs.extractInfoFromIssue.outputs.issueInfo }}
200205
operation: removeToken
201-
prTitle: "[removeToken] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}` from `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`"
206+
prTitle: '[removeToken] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}` from `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`'
202207
prBody: |
203208
Removing token from network `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`
204209
@@ -213,14 +218,14 @@ jobs:
213218
```
214219
215220
addImage:
216-
needs: [ extractInfoFromIssue, optimizeImage ]
221+
needs: [extractInfoFromIssue, optimizeImage]
217222
uses: ./.github/workflows/executeAction.yml
218223
if: ${{ contains(github.event.issue.labels.*.name, 'addImage') }}
219224
secrets: inherit
220225
with:
221226
issueInfo: ${{ needs.extractInfoFromIssue.outputs.issueInfo }}
222227
operation: addImage
223-
prTitle: "[addImage] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}` to `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`"
228+
prTitle: '[addImage] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}` to `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`'
224229
prBody: |
225230
Adding image to network `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`
226231

.github/workflows/updatePermitInfo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false # continue parallel jobs even if individual parts fail
1818
matrix:
19-
chainId: [1, 100, 8453, 42161] # all supported chains
19+
chainId: [1, 100, 8453, 42161, 137, 43114] # all supported chains
2020

2121
steps:
2222
- name: Checkout code

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
node_modules
22
build
3+
34
# MacOS
45
.DS_Store
6+
57
# Intellij
68
.idea
9+
710
# Vscode
811
.vscode
12+
913
# yalc
1014
.yalc
1115
yalc.lock
12-
src/cowFi/TEMP*
16+
17+
# Temporary files
18+
src/cowFi/TEMP*
19+
20+
# logs
21+
*.log

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ Instructions for setting up and running the various scripts locally
5252

5353
### Setup
5454

55+
### Prerequisites
56+
57+
Currently runs on Node.js LTS/Gallium v16.20.2
58+
5559
```bash
5660
# Install dependencies
5761
yarn
@@ -60,7 +64,7 @@ yarn
6064
yarn coingecko
6165
```
6266

63-
### Download images
67+
### Download images (deprecated)
6468

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

@@ -95,5 +99,7 @@ The script generates token list files in `src/public/` for the following network
9599

96100
- Ethereum (CoinGecko.1.json)
97101
- Arbitrum (CoinGecko.42161.json, Uniswap.42161.json)
102+
- Avalanche (Coingecko.43114.json, Uniswap.43114.json)
98103
- Base (CoinGecko.8453.json, Uniswap.8453.json)
99104
- Gnosis Chain (CoinGecko.100.json, Uniswap.100.json)
105+
- Polygon (CoinGecko.137.json, Uniswap.137.json)

package.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,28 @@
1919
"public": "copyfiles src/public/*.json build/lists -f",
2020
"workflowHelper": "python3 src/scripts/workflow_helper.py",
2121
"validate": "ajv -s node_modules/@uniswap/token-lists/dist/tokenlist.schema.json -d src/public/CowSwap.json -c ajv-formats --errors text",
22-
"fetchPermitInfo": "yarn run-script src/permitInfo/fetchPermitInfo.ts",
22+
"fetchAllPermitInfo": "yarn run-script src/permitInfo/fetchAllPermitInfo.ts",
23+
"fetchPermitInfo": "yarn run-script src/permitInfo/fetchPermitInfoByChain.ts",
2324
"fetchPermitInfo:mainnet": "yarn run fetchPermitInfo -- 1",
2425
"fetchPermitInfo:arb1": "yarn run fetchPermitInfo -- 42161",
2526
"fetchPermitInfo:base": "yarn run fetchPermitInfo -- 8453",
2627
"fetchPermitInfo:gnosis": "yarn run fetchPermitInfo -- 100",
2728
"fetchPermitInfo:sepolia": "yarn run fetchPermitInfo -- 11155111",
28-
"recheckPermitInfo:mainnet": "yarn run fetchPermitInfo -- 1 '' '' true",
29-
"recheckPermitInfo:arb1": "yarn run fetchPermitInfo -- 42161 '' '' true",
30-
"recheckPermitInfo:base": "yarn run fetchPermitInfo -- 8453 '' '' true",
31-
"recheckPermitInfo:gnosis": "yarn run fetchPermitInfo -- 100 '' '' true",
32-
"recheckPermitInfo:sepolia": "yarn run fetchPermitInfo -- 11155111 '' '' true",
29+
"fetchPermitInfo:avalanche": "yarn run fetchPermitInfo -- 43114",
30+
"fetchPermitInfo:polygon": "yarn run fetchPermitInfo -- 137",
31+
"recheckPermitInfo:mainnet": "yarn run fetchPermitInfo -- 1 true",
32+
"recheckPermitInfo:arb1": "yarn run fetchPermitInfo -- 42161 true",
33+
"recheckPermitInfo:base": "yarn run fetchPermitInfo -- 8453 true",
34+
"recheckPermitInfo:gnosis": "yarn run fetchPermitInfo -- 100 true",
35+
"recheckPermitInfo:sepolia": "yarn run fetchPermitInfo -- 11155111 true",
36+
"recheckPermitInfo:avalanche": "yarn run fetchPermitInfo -- 43114 true",
37+
"recheckPermitInfo:polygon": "yarn run fetchPermitInfo -- 137 true",
3338
"run-script": "node --loader ts-node/esm --experimental-json-modules --experimental-specifier-resolution=node",
3439
"test": "node --test"
3540
},
3641
"license": "(MIT OR Apache-2.0)",
3742
"dependencies": {
38-
"@cowprotocol/cow-sdk": "^5.7.0-RC.0",
43+
"@cowprotocol/cow-sdk": "^5.11.0-RC.0",
3944
"@cowprotocol/permit-utils": "^0.4.0",
4045
"@uniswap/token-lists": "^1.0.0-beta.33",
4146
"ajv": "^8.12.0",
@@ -47,7 +52,8 @@
4752
"lodash": "^4.17.21",
4853
"p-retry": "^6.1.0",
4954
"p-throttle": "^5.1.0",
50-
"ts-node": "^10.9.1"
55+
"ts-node": "^10.9.1",
56+
"winston": "^3.17.0"
5157
},
5258
"devDependencies": {
5359
"@types/node": "^20.8.7",
@@ -56,4 +62,4 @@
5662
"prettier": "^3.0.3",
5763
"typescript": "^5.2.2"
5864
}
59-
}
65+
}

src/permitInfo/const.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const DEFAULT_RPC_URLS: Record<SupportedChainId, string> = {
1111
[SupportedChainId.BASE]: 'https://mainnet.base.org',
1212
[SupportedChainId.GNOSIS_CHAIN]: 'https://rpc.gnosischain.com',
1313
[SupportedChainId.SEPOLIA]: 'https://ethereum-sepolia.publicnode.com',
14+
[SupportedChainId.AVALANCHE]: 'https://api.avax.network/ext/bc/C/rpc',
15+
[SupportedChainId.POLYGON]: 'https://polygon-rpc.com',
1416
}
1517

1618
export const BASE_PATH = join('..', 'public')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import path from 'path'
2+
import { argv, chdir } from 'node:process'
3+
4+
import { SupportedChainId } from '@cowprotocol/cow-sdk'
5+
import { fetchPermitInfo } from './fetchPermitInfo'
6+
import { getLogger, removeOldLogs } from 'scripts/auxLists/utils'
7+
8+
async function fetchAllPermitInfo() {
9+
const [, scriptPath] = argv
10+
11+
chdir(path.dirname(scriptPath))
12+
13+
removeOldLogs('fetch-permit')
14+
15+
const logger = getLogger('fetch-permit')
16+
17+
for (const chainId in SupportedChainId) {
18+
if (!isNaN(Number(chainId))) {
19+
try {
20+
await fetchPermitInfo({
21+
chainId: +chainId as SupportedChainId,
22+
tokenListPath: undefined,
23+
rpcUrl: undefined,
24+
recheckUnsupported: false,
25+
forceRecheck: false,
26+
})
27+
} catch (error) {
28+
logger.error(`Error fetching permit info for chain ${chainId}:`, error)
29+
}
30+
}
31+
}
32+
}
33+
34+
fetchAllPermitInfo()

0 commit comments

Comments
 (0)