|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +CHAINS_PATH="chains" |
| 4 | +TOKEN_LIST_FILENAME="token-list.json" |
| 5 | + |
| 6 | +process_chain() { |
| 7 | + local chain_dir=$1 |
| 8 | + local assets_path="$chain_dir/assets" |
| 9 | + local token_list_path="$chain_dir/$TOKEN_LIST_FILENAME" |
| 10 | + |
| 11 | + echo "Processing chain directory: $chain_dir" |
| 12 | + |
| 13 | + # Initialize token list array |
| 14 | + local token_list="[]" |
| 15 | + |
| 16 | + # Iterate over each subdirectory in the assets directory |
| 17 | + for dir_name in "$assets_path"/*; do |
| 18 | + if [ -d "$dir_name" ]; then |
| 19 | + local token_info_path="$dir_name/token-info.json" |
| 20 | + local token_logo_path="$dir_name/token-logo.svg" |
| 21 | + |
| 22 | + if [ -f "$token_info_path" ] && [ -f "$token_logo_path" ]; then |
| 23 | + local token_info=$(cat "$token_info_path") |
| 24 | + token_list=$(echo "$token_list" | jq --argjson token_info "$token_info" '. + [$token_info]') |
| 25 | + else |
| 26 | + echo "token-info.json or token-logo.svg not found in $dir_name" |
| 27 | + fi |
| 28 | + fi |
| 29 | + done |
| 30 | + |
| 31 | + # Read existing token list if it exists |
| 32 | + if [ -f "$token_list_path" ]; then |
| 33 | + local existing_token_list=$(cat "$token_list_path") |
| 34 | + else |
| 35 | + local existing_token_list="[]" |
| 36 | + fi |
| 37 | + |
| 38 | + # Sort token list by tokenAddress |
| 39 | + token_list=$(echo "$token_list" | jq 'sort_by(.tokenAddress)') |
| 40 | + |
| 41 | + # Check if the new token list is different from the existing one |
| 42 | + if [ "$token_list" != "$existing_token_list" ]; then |
| 43 | + # Write updated token list to token-list.json |
| 44 | + echo "$token_list" | jq '.' > "$token_list_path" |
| 45 | + echo "Written updated token list to $token_list_path" |
| 46 | + else |
| 47 | + echo "No changes detected in $token_list_path, skipping write." |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +# Iterate over each subdirectory in the chains directory |
| 52 | +for chain_dir in "$CHAINS_PATH"/*; do |
| 53 | + if [ -d "$chain_dir" ]; then |
| 54 | + process_chain "$chain_dir" |
| 55 | + else |
| 56 | + echo "No directories found in $CHAINS_PATH" |
| 57 | + fi |
| 58 | +done |
| 59 | + |
| 60 | +echo "All token lists updated." |
0 commit comments