Skip to content

Commit

Permalink
feat: add arbitrum one (#389)
Browse files Browse the repository at this point in the history
* feat: add permit info for arbitrum one

* feat: add permitinfo file checked against coingecko list

https://tokens.coingecko.com/arbitrum-one/all.json

* feat: update templates to allow adding arb1 tokens with gh forms

* chore: update dependencies which support arb1

* chore: add commands related to arb1

* chore: update text
  • Loading branch information
alfetopito authored May 15, 2024
1 parent e437827 commit 40e9d85
Show file tree
Hide file tree
Showing 10 changed files with 3,036 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/1-addTokenForm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ body:
Please fill in all the required fields in the form.
We will process and evaluate your request as soon as possible.
Also, don't forget to update the issue title adding your token's `SYMBOL` and `NETWORK` (MAINNET or GNOSIS_CHAIN)
Also, don't forget to update the issue title adding your token's `SYMBOL` and `NETWORK`.
## Disclaimer
CoW DAO reserves the right, at its sole discretion, to accept or reject the listing of any token.
Expand All @@ -32,6 +32,7 @@ body:
options:
- MAINNET
- GNOSIS_CHAIN
- ARBITRUM_ONE
validations:
required: true
- type: input
Expand Down
11 changes: 6 additions & 5 deletions .github/ISSUE_TEMPLATE/2-addImageForm.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Add Image
description: Creates a request to add a token image to CoW Swap's image repository
title: "[AddImage] `SYMBOL` on `NETWORK`"
title: '[AddImage] `SYMBOL` on `NETWORK`'
labels: [addImage]

body:
Expand All @@ -9,11 +9,11 @@ body:
value: |
# Request to ADD image
Thank you for contributing to CoW Swap's image repository.
Please fill in all the required fields in the form.
We will process and evaluate your request as soon as possible.
Also, don't forget to update the issue title adding your token's `SYMBOL` and `NETWORK` (MAINNET or GNOSIS_CHAIN)
Also, don't forget to update the issue title adding your token's `SYMBOL` and `NETWORK`.
- type: dropdown
id: network
Expand All @@ -24,6 +24,7 @@ body:
options:
- MAINNET
- GNOSIS_CHAIN
- ARBITRUM_ONE
validations:
required: true
- type: input
Expand All @@ -40,4 +41,4 @@ body:
description: Ideally a 256x256 PNG file. But we'll take care of optimizing it later.
placeholder: https://gateway.pinata.cloud/ipfs/Qme9B6jRpGtZsRFcPjHvA5T4ugFuL4c3SzWfxyMPa59AMo
validations:
required: true
required: true
11 changes: 6 additions & 5 deletions .github/ISSUE_TEMPLATE/3-removeTokenForm.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Remove Token
description: Creates a request to remove a token from CoW Swap's default token list
title: "[RemoveToken] `SYMBOL` on `NETWORK`"
title: '[RemoveToken] `SYMBOL` on `NETWORK`'
labels: [removeToken]

body:
Expand All @@ -9,11 +9,11 @@ body:
value: |
# Request to REMOVE token
Thank you for contributing to CoW Swap's default token list.
Please fill in all the required fields in the form.
Please fill in all the required fields in the form.
We will process and evaluate your request as soon as possible.
Also, don't forget to update the issue title adding your token's `SYMBOL` and `NETWORK` (MAINNET or GNOSIS_CHAIN)
Also, don't forget to update the issue title adding your token's `SYMBOL` and `NETWORK` (MAINNET or GNOSIS_CHAIN)
- type: dropdown
id: network
Expand All @@ -24,6 +24,7 @@ body:
options:
- MAINNET
- GNOSIS_CHAIN
- ARBITRUM_ONE
validations:
required: true
- type: input
Expand Down
55 changes: 29 additions & 26 deletions .github/workflows/processRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
issue-number: ${{ github.event.issue.number }}
body: |
Your request has been received and is being processed.
This issue will be updated when completed.
- name: Extract info
Expand All @@ -61,35 +61,38 @@ jobs:
# Using JS, build a new comment body
script: |
const body = context.payload.issue.body
const fieldNames = `${ process.env.FIELD_NAMES }`.split(',')
// Extract the values for each field - if it exists - based on their labels from the issue body
const values = fieldNames.reduce((acc, f) => {
// Create a regex for each field, with capturing group with the same name
const r = new RegExp(String.raw`${f}\s+(?<${f.toLowerCase()}>.*?)(\s+###|$)`, 's')
// Build an object with the capturing group and value for each field
return {...acc, ...body.match(r)?.groups}
}, {})
// Lower case the address at the source
values.address = values.address.toLowerCase()
if (values.network === 'MAINNET') {
values.chainId = 1
values.blockExplorer = 'etherscan'
} else if () {
values.chainId = 42161
values.blockExplorer = 'arbiscan'
} else {
values.chainId = 100
values.blockExplorer = 'gnosisscan'
}
// Used only in the PR context for displaying it
values.prImageUrl = `https://raw.githubusercontent.com/cowprotocol/token-lists/{0}/${ values.chainId }_${ values.address }/src/public/images/${ values.chainId }/${ values.address }/logo.png`
// Will be the final URL once it's merged to `main`
values.logoURI = `https://raw.githubusercontent.com/cowprotocol/token-lists/main/src/public/images/${ values.chainId }/${ values.address }/logo.png`
// Return a string
return JSON.stringify(values)
result-encoding: string
Expand All @@ -99,10 +102,10 @@ jobs:
cat << EOF
${{ steps.extractInfo.outputs.result }}
EOF
# force failure for testing
# exit 1
validateInput:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -133,7 +136,7 @@ jobs:
if: env.SYMBOL && contains(env.SYMBOL, ' ')
run: |
echo "${{ env.SYMBOL }}"
echo "::error title={Validation failed}::{Symbol cannot contain spaces}"
echo "::error title={Validation failed}::{Symbol cannot contain spaces}"
exit 1
- name: Validate removeToken
if: contains(github.event.issue.labels.*.name, 'removeToken') && (!env.NETWORK || !env.REASON || !env.ADDRESS)
Expand All @@ -147,8 +150,8 @@ jobs:
with:
comment: |
Invalid request
Make sure all the required fields are provided and submit a new issue
Make sure all the required fields are provided and submit a new issue
optimizeImage:
needs: [ extractInfoFromIssue, validateInput ]
Expand All @@ -171,18 +174,18 @@ jobs:
prTitle: "[addToken] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).symbol }}` to `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`"
prBody: |
Adding token `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).symbol }}` on network `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`
*Address*: `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}`
[Link to block explorer ↗︎](https://${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).blockExplorer }}.io/token/${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }})
| Description | Image |
|-|-|
| Original | ![original](${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).url }}) |
| Optimized | ![optimized](${{ format(fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).prImageUrl, 'addToken') }}) |
### Reason
```
${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).reason }}
```
Expand All @@ -198,13 +201,13 @@ jobs:
prTitle: "[removeToken] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}` from `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`"
prBody: |
Removing token from network `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`
*Address*: `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}`
[Link to block explorer ↗︎](https://${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).blockExplorer }}.io/token/${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }})
### Reason
```
${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).reason }}
```
Expand All @@ -220,11 +223,11 @@ jobs:
prTitle: "[addImage] `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}` to `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`"
prBody: |
Adding image to network `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).network }}`
*Address*: `${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }}`
[Link to block explorer ↗︎](https://${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).blockExplorer }}.io/token/${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).address }})
| Description | Image |
|-|-|
| Original | ![original](${{ fromJSON(needs.extractInfoFromIssue.outputs.issueInfo).url }}) |
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
"validate": "ajv -s node_modules/@uniswap/token-lists/dist/tokenlist.schema.json -d src/public/CowSwap.json -c ajv-formats --errors text",
"fetchPermitInfo": "yarn run-script src/permitInfo/fetchPermitInfo.ts",
"fetchPermitInfo:mainnet": "yarn run fetchPermitInfo -- 1",
"fetchPermitInfo:arb1": "yarn run fetchPermitInfo -- 42161",
"fetchPermitInfo:gnosis": "yarn run fetchPermitInfo -- 100",
"fetchPermitInfo:sepolia": "yarn run fetchPermitInfo -- 11155111",
"recheckPermitInfo:mainnet": "yarn run fetchPermitInfo -- 1 '' '' true",
"recheckPermitInfo:arb1": "yarn run fetchPermitInfo -- 42161 '' '' true",
"recheckPermitInfo:gnosis": "yarn run fetchPermitInfo -- 100 '' '' true",
"recheckPermitInfo:sepolia": "yarn run fetchPermitInfo -- 11155111 '' '' true",
"run-script": "node --loader ts-node/esm --experimental-json-modules --experimental-specifier-resolution=node",
"test": "node --test"
},
"license": "(MIT OR Apache-2.0)",
"dependencies": {
"@cowprotocol/cow-sdk": "^5.1.0",
"@cowprotocol/permit-utils": "^0.2.0",
"@cowprotocol/cow-sdk": "^5.3.0-RC.1",
"@cowprotocol/permit-utils": "^0.3.0-RC.0",
"@uniswap/token-lists": "^1.0.0-beta.33",
"ajv": "^8.12.0",
"ajv-cli": "^5.0.0",
Expand All @@ -46,4 +48,4 @@
"prettier": "^3.0.3",
"typescript": "^5.2.2"
}
}
}
5 changes: 3 additions & 2 deletions src/permitInfo/const.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { env } from 'node:process'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { join } from 'node:path'
import {SupportedChainId} from '@cowprotocol/cow-sdk'
import { env } from 'node:process'

// CoW protocol contract address. Could be any address in theory for checking the token is permittable
export const SPENDER_ADDRESS = '0xC92E8bdf79f0507f65a392b0ab4667716BFE0110'

export const DEFAULT_RPC_URLS: Record<SupportedChainId, string> = {
[SupportedChainId.MAINNET]: 'https://mainnet.infura.io/v3/' + env.INFURA_API_KEY,
[SupportedChainId.ARBITRUM_ONE]: 'https://arbitrum.meowrpc.com',
[SupportedChainId.GNOSIS_CHAIN]: 'https://rpc.gnosischain.com',
[SupportedChainId.SEPOLIA]: 'https://ethereum-sepolia.publicnode.com',
}
Expand Down
4 changes: 2 additions & 2 deletions src/permitInfo/utils/getProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { JsonRpcProvider } from '@ethersproject/providers'
import { DEFAULT_RPC_URLS } from '../const'
import { ethers } from 'ethers'
import {SupportedChainId} from '@cowprotocol/cow-sdk'
import { DEFAULT_RPC_URLS } from '../const'

export function getProvider(chainId: number, rpcUrl: string | undefined): JsonRpcProvider {
const rpcEndpoint = rpcUrl ? rpcUrl : DEFAULT_RPC_URLS[chainId as SupportedChainId]
Expand Down
9 changes: 4 additions & 5 deletions src/permitInfo/utils/getTokensFromTokenList.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { BASE_PATH } from '../const'
import { Token } from '../types'
import { join } from 'node:path'
import { SupportedChainId } from '@cowprotocol/cow-sdk'

const tokenListsByNetwork: Record<SupportedChainId, string> = {
[SupportedChainId.MAINNET]: 'CowSwap.json',
[SupportedChainId.ARBITRUM_ONE]: 'CowSwap.json',
[SupportedChainId.GNOSIS_CHAIN]: 'CowSwap.json',
[SupportedChainId.SEPOLIA]: 'CowSwapSepolia.json',
}

export function getTokensFromTokenList(chainId: SupportedChainId, tokenListPath: string | undefined): Array<Token> {
const filePath = tokenListPath
? tokenListPath
: join(BASE_PATH, tokenListsByNetwork[chainId])
const filePath = tokenListPath ? tokenListPath : join(BASE_PATH, tokenListsByNetwork[chainId])

return JSON.parse(readFileSync(filePath, 'utf-8')).tokens
}
Loading

0 comments on commit 40e9d85

Please sign in to comment.