-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automated validation of tokens decimals (#87)
* ci: workflow to validate tokens decimals feat: bash script to validate token decimals chore: .env example file chore: remove redundant tokens from list * polish comment
- Loading branch information
1 parent
877f352
commit dd6b419
Showing
8 changed files
with
156 additions
and
51 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,27 @@ | ||
export API_KEY_INFURA="YOUR_RPC_API_KEY" | ||
|
||
# Mainnets | ||
export ARBITRUM_MAINNET_RPC_URL="https://arbitrum-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export AVALANCHE_MAINNET_RPC_URL="https://avalanche-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export BASE_MAINNET_RPC_URL="https://base-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export BLAST_MAINNET_RPC_URL="https://blast-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export BSC_MAINNET_RPC_URL="https://bsc-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export ETHEREUM_MAINNET_RPC_URL="https://mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export GNOSIS_MAINNET_RPC_URL="YOUR_GNOSIS_MAINNET_RPC_URL" | ||
export IOTEX_MAINNET_RPC_URL="YOUR_IOTEX_MAINNET_RPC_URL" | ||
export LIGHTLINK_MAINNET_RPC_URL="YOUR_LIGHTLINK_MAINNET_RPC_URL" | ||
export LINEA_MAINNET_RPC_URL="https://linea-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export MODE_MAINNET_RPC_URL="YOUR_MODE_MAINNET_RPC_URL" | ||
export MORPH_MAINNET_RPC_URL="YOUR_MORPH_MAINNET_RPC_URL" | ||
export OPTIMISM_MAINNET_RPC_URL="https://optimism-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export POLYGON_MAINNET_RPC_URL="https://polygon-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export RONIN_MAINNET_RPC_URL="YOUR_RONIN_MAINNET_RPC_URL" | ||
export SCROLL_MAINNET_RPC_URL="https://scroll-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
export SUPERSEED_MAINNET_RPC_URL="YOUR_SUPERSEED_MAINNET_RPC_URL" | ||
export TANGLE_MAINNET_RPC_URL="YOUR_TANGLE_MAINNET_RPC_URL" | ||
export ZKSYNC_MAINNET_RPC_URL="https://zksync-mainnet.infura.io/v3/$API_KEY_INFURA" | ||
|
||
# Testnets | ||
export BASE_SEPOLIA_RPC_URL="https://base-sepolia.infura.io/v3/$API_KEY_INFURA" | ||
export RONIN_TESTNET_RPC_URL="YOUR_RONIN_TESTNET_RPC_URL" | ||
export SEPOLIA_RPC_URL="https://sepolia.infura.io/v3/$API_KEY_INFURA" |
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,45 @@ | ||
name: "CI Tokenlist" | ||
|
||
env: | ||
ARBITRUM_MAINNET_RPC_URL: "https://arbitrum-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
AVALANCHE_MAINNET_RPC_URL: "https://avalanche-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
BASE_MAINNET_RPC_URL: "https://base-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
BASE_SEPOLIA_RPC_URL: "https://base-sepolia.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
BLAST_MAINNET_RPC_URL: "https://blast-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
BSC_MAINNET_RPC_URL: "https://bsc-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
ETHEREUM_MAINNET_RPC_URL: "https://mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
GNOSIS_MAINNET_RPC_URL: ${{ secrets.GNOSIS_MAINNET_RPC_URL }} | ||
IOTEX_MAINNET_RPC_URL: ${{ secrets.IOTEX_MAINNET_RPC_URL }} | ||
LIGHTLINK_MAINNET_RPC_URL: ${{ secrets.LIGHTLINK_MAINNET_RPC_URL }} | ||
LINEA_MAINNET_RPC_URL: "https://linea-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
MODE_MAINNET_RPC_URL: ${{ secrets.MODE_MAINNET_RPC_URL }} | ||
MORPH_MAINNET_RPC_URL: ${{ secrets.MORPH_MAINNET_RPC_URL }} | ||
OPTIMISM_MAINNET_RPC_URL: "https://optimism-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
POLYGON_MAINNET_RPC_URL: "https://polygon-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
RONIN_MAINNET_RPC_URL: ${{ secrets.RONIN_MAINNET_RPC_URL }} | ||
RONIN_TESTNET_RPC_URL: ${{ secrets.RONIN_TESTNET_RPC_URL }} | ||
SCROLL_MAINNET_RPC_URL: "https://scroll-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
SEPOLIA_RPC_URL: "https://sepolia.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
SUPERSEED_MAINNET_RPC_URL: ${{ secrets.SUPERSEED_MAINNET_RPC_URL }} | ||
TANGLE_MAINNET_RPC_URL: ${{ secrets.TANGLE_MAINNET_RPC_URL }} | ||
ZKSYNC_MAINNET_RPC_URL: "https://zksync-mainnet.infura.io/v3/${{ secrets.API_KEY_INFURA }}" | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- "main" | ||
schedule: | ||
- cron: "0 3 * * 0" # at 3:00am UTC every Sunday | ||
|
||
jobs: | ||
check-tokenlist: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Check decimals for tokens list" | ||
run: ./shell/tokenlist.sh | ||
shell: bash |
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,75 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Pre-requisites for running this script: | ||
# | ||
# - bash >=4.0.0 | ||
# - .env file | ||
|
||
set -euo pipefail | ||
|
||
# Source variables from .env file if it exists. | ||
if [ -f .env ]; then | ||
export $(grep -v '^#' .env | xargs) | ||
source <(envsubst < .env) | ||
fi | ||
|
||
# Loop through files in `src/tokens` directory | ||
for file in src/tokens/*.json; do | ||
json_objects=$(cat "$file") | ||
|
||
# Extract the filename and replace '-' with '_' | ||
network=$(basename "$file" .json | tr '-' '_' | tr '[:lower:]' '[:upper:]') | ||
|
||
echo -n "Decimals for $network tokens list: " | ||
|
||
# Construct the RPC URL variable name from filename | ||
rpc_url_var="${network}_RPC_URL" | ||
|
||
# Load the RPC URL from the environment variable | ||
rpc_url=${!rpc_url_var} | ||
|
||
# Loop through JSON objects and extract address and token decimals | ||
echo "$json_objects" | jq -c '.[]' | while read -r row; do | ||
address=$(echo "$row" | jq -r '.address') | ||
token_decimal=$(echo "$row" | jq -r '.decimals') | ||
|
||
# Indicate progress | ||
echo -n "." | ||
|
||
# Make request through RPC | ||
response=$(curl -sS $rpc_url \ | ||
-X POST \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"jsonrpc": "2.0", | ||
"method": "eth_call", | ||
"params": [{ | ||
"to": "'"$address"'", | ||
"data": "0x313ce567" | ||
}, "latest"], | ||
"id": 1 | ||
}') | ||
|
||
# Get token decimals (base-16) from curl response, exit if response is not valid | ||
if ! actual_decimals=$(echo $response | jq -r '.result'); then | ||
echo -e "\e[31m🔴 $response" | ||
exit 1 | ||
fi | ||
|
||
# Convert token decimals to base-10, exit if response is not valid | ||
if ! actual_decimals=$(printf "%d" "$actual_decimals"); then | ||
echo -e "🟡 Invalid for $address, could be an RPC issue, manual check is recommended." | ||
continue | ||
fi | ||
|
||
# Compare token decimal with actual decimals and throw if they do not match | ||
if [ "$token_decimal" -ne "$actual_decimals" ]; then | ||
echo -e "\e[31m🔴 Mismatch for $address. Set to $token_decimal. Should be $actual_decimals\e[0m" | ||
exit 1 | ||
fi | ||
|
||
done | ||
|
||
# Log success | ||
echo -e "\e[32m🟢 Valid\e[0m" | ||
done |
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
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
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