Skip to content

Commit

Permalink
Merge branch 'main' into fix-solhint-noprompt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDEnYO authored Mar 4, 2025
2 parents a9baa8f + b8797fb commit e0b4475
Show file tree
Hide file tree
Showing 14 changed files with 1,071 additions and 664 deletions.
38 changes: 33 additions & 5 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,40 @@
}
],
"code-complexity": ["error", 20],
"compiler-version": ["error", "^0.8.17"],
"const-name-snakecase": "off",
"func-name-mixedcase": "off",
"explicit-types": ["error", "explicit"],
"max-states-count": ["error", 15],
"no-empty-blocks": "error",
"no-global-import": "error",
"no-unused-import": "error",
"no-unused-vars": "error",
"one-contract-per-file": "off",
"payable-fallback": "error",
"reason-string": ["error", { "maxLength": 64 }],
"interface-starts-with-i": "error",
"const-name-snakecase": "error",
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
"not-rely-on-time": "off",
"reason-string": ["warn", { "maxLength": 64 }]
"contract-name-capwords": "error",
"event-name-capwords": "error",
"immutable-vars-naming": ["error", { "immutablesAsConstants": true }],
"use-forbidden-name": "error",
"var-name-mixedcase": "error",
"imports-on-top": "error",
"visibility-modifier-order": "error",
"gas-custom-errors": "error",
"quotes": ["error","double"],
"avoid-call-value": "off",
"avoid-low-level-calls": "off",
"avoid-sha3": "error",
"avoid-suicide": "error",
"avoid-throw": "error",
"avoid-tx-origin": "error",
"check-send-result": "error",
"compiler-version": ["error", "^0.8.17"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"no-inline-assembly": "off",
"not-rely-on-block-hash": "error",
"reentrancy": "error",
"state-visibility": "error"
}
}
185 changes: 185 additions & 0 deletions archive/scripts/Tasks/diamondSyncDEXs_BACKUP.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/bin/bash

function diamondSyncDEXs {
echo ""
echo "[info] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> running script syncDEXs now...."
# load env variables
source .env

# load config & helper functions
source script/helperFunctions.sh

# read function arguments into variables
local NETWORK="$1"
local ENVIRONMENT="$2"
local DIAMOND_CONTRACT_NAME="$3"
local EXIT_ON_ERROR="$4"

# if no NETWORK was passed to this function, ask user to select it
if [[ -z "$NETWORK" ]]; then
# find out if script should be executed for one network or for all networks
echo ""
echo "Should the script be executed on one network or all networks"
NETWORK=$(echo -e "All (non-excluded) Networks\n$(cat ./networks)" | gum filter --placeholder "Network")
if [[ "$NETWORK" != "All (non-excluded) Networks" ]]; then
checkRequiredVariablesInDotEnv $NETWORK
fi
fi

# get file suffix based on value in variable ENVIRONMENT
local FILE_SUFFIX=$(getFileSuffix "$ENVIRONMENT")

# if no DIAMOND_CONTRACT_NAME was passed to this function, ask user to select it
if [[ -z "$DIAMOND_CONTRACT_NAME" ]]; then
echo ""
echo "Please select which type of diamond contract to sync:"
DIAMOND_CONTRACT_NAME=$(userDialogSelectDiamondType)
echo "[info] selected diamond type: $DIAMOND_CONTRACT_NAME"
fi

# create array with network/s for which the script should be executed
if [[ "$NETWORK" == "All (non-excluded) Networks" ]]; then
# get array with all network names
NETWORKS=($(getIncludedNetworksArray))
else
NETWORKS=($NETWORK)
fi



# go through all networks and execute the script
for NETWORK in "${NETWORKS[@]}"; do

# Skip for localanvil or any testnet
if [[ "$NETWORK" == "localanvil" || \
"$NETWORK" == "bsc-testnet" || \
"$NETWORK" == "lineatest" || \
"$NETWORK" == "mumbai" || \
"$NETWORK" == "sepolia" ]]; then
continue
fi

# get diamond address from deployments script
DIAMOND_ADDRESS=$(getContractAddressFromDeploymentLogs "$NETWORK" "$ENVIRONMENT" "$DIAMOND_CONTRACT_NAME")

# logging for debug purposes
echo ""
echoDebug "in function syncDEXs"
echoDebug "NETWORKS=$NETWORKS"
echoDebug "CURRENT NETWORK=$NETWORK"
echoDebug "ENVIRONMENT=$ENVIRONMENT"
echoDebug "FILE_SUFFIX=$FILE_SUFFIX"
echoDebug "DIAMOND_CONTRACT_NAME=$DIAMOND_CONTRACT_NAME"
echoDebug "DIAMOND_ADDRESS=$DIAMOND_ADDRESS"
echo ""

# if no diamond address was found, throw an error and exit the script
if [[ "$DIAMOND_ADDRESS" == "null" || -z "$DIAMOND_ADDRESS" ]]; then
error "could not find address for $DIAMOND_CONTRACT_NAME on network $NETWORK in file './deployments/${NETWORK}.${FILE_SUFFIX}json' - exiting syncDEXs script now"
local RETURN=1
continue
fi

# get RPC URL for given network
RPC_URL=$(getRPCUrl "$NETWORK")

echo "[info] now syncing DEXs for $DIAMOND_CONTRACT_NAME on network $NETWORK with address $DIAMOND_ADDRESS"

# get list of DEX addresses from config file
CFG_DEXS=$(jq -r --arg network "$NETWORK" '.[$network][]' "./config/dexs.json")

# get addresses of DEXs that are already approved in the diamond contract
RESULT=$(cast call "$DIAMOND_ADDRESS" "approvedDexs() returns (address[])" --rpc-url "$RPC_URL")

# Check if any approved DEXs were found
if [[ "$RESULT" == "[]" ]]; then
DEXS=()
else
# reformat
DEXS=($(echo ${RESULT:1:${#RESULT}-1} | tr ',' '\n' | tr '[:upper:]' '[:lower:]'))
fi

# Check the length of the array
if [ ${#DEXS[@]} -eq 0 ]; then
echoDebug "0 approved DEXs found on diamond $DIAMOND_ADDRESS"
else
echoDebug "${#DEXS[@]} approved DEXs found on diamond $DIAMOND_ADDRESS: [${DEXS[*]}]"
fi

# Loop through all DEX addresses from config and check if they are already known by the diamond
NEW_DEXS=()
for DEX_ADDRESS in $CFG_DEXS; do
# if address is in config file but not in DEX addresses returned from diamond...
if [[ ! " ${DEXS[*]} " == *" $(echo "$DEX_ADDRESS" | tr '[:upper:]' '[:lower:]')"* ]]; then
CHECKSUMMED=$(cast --to-checksum-address "$DEX_ADDRESS")
CODE=$(cast code $CHECKSUMMED --rpc-url "$RPC_URL")
if [[ "$CODE" == "0x" ]]; then
error "DEX $CHECKSUMMED is not deployed on network $NETWORK - skipping"
echo "$NETWORK - $CHECKSUMMED" >>.invalid-dexs
continue
fi
# ... add it to the array
NEW_DEXS+=("$CHECKSUMMED")
fi
done

echoDebug "${#NEW_DEXS[@]} new DEXs to be added: [${NEW_DEXS[*]}]"

# add new DEXs to diamond
if [[ ! ${#NEW_DEXS[@]} -eq 0 ]]; then
# Convert the list of addresses to an array
ADDRESS_ARRAY=($(echo "${NEW_DEXS[*]}"))

# Convert the array to a string with comma-separated values
ADDRESS_STRING=$(printf "%s," "${ADDRESS_ARRAY[@]}")
PARAMS="[${ADDRESS_STRING%,}]"

# call batchAddDex function in diamond to add DEXs
local ATTEMPTS=1
while [ $ATTEMPTS -le "$MAX_ATTEMPTS_PER_SCRIPT_EXECUTION" ]; do
echo "[info] Trying to add missing DEXs now - attempt ${ATTEMPTS} (max attempts: $MAX_ATTEMPTS_PER_SCRIPT_EXECUTION) "

# ensure that gas price is below maximum threshold (for mainnet only)
doNotContinueUnlessGasIsBelowThreshold "$NETWORK"

# call diamond
if [[ "$DEBUG" == *"true"* ]]; then
# print output to console
cast send "$DIAMOND_ADDRESS" "batchAddDex(address[])" "${PARAMS[@]}" --rpc-url "$RPC_URL" --private-key $(getPrivateKey "$NETWORK" "$ENVIRONMENT") --legacy
else
# do not print output to console
cast send "$DIAMOND_ADDRESS" "batchAddDex(address[])" "${PARAMS[@]}" --rpc-url "$RPC_URL" --private-key $(getPrivateKey "$NETWORK" "$ENVIRONMENT") --legacy >/dev/null
fi

# check the return code the last call
if [ $? -eq 0 ]; then
break # exit the loop if the operation was successful
fi

ATTEMPTS=$((ATTEMPTS + 1)) # increment ATTEMPTS
sleep 1 # wait for 1 second before trying the operation again
done

# check if call was executed successfully or used all ATTEMPTS
if [ $ATTEMPTS -gt "$MAX_ATTEMPTS_PER_SCRIPT_EXECUTION" ]; then
error "failed to add missing DEXs to $DIAMOND_CONTRACT_NAME with address $DIAMOND_ADDRESS on network $NETWORK"
RETURN=1
fi
else
echo '[info] no new DEXs to add'
fi
done

# end script according to return status
if [ "$RETURN" == 1 ]; then
if [[ -z "$EXIT_ON_ERROR" ]]; then
return 1
else
exit 1
fi
else
return 0
fi

echo "[info] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< script syncDEXs completed"
}
11 changes: 0 additions & 11 deletions config/global.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"create3Factory": {
"default": "0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1",
"berachain": "0x5f63A2d7850776465b84Bc0fe6284BBC8188dbC7",
"ink": "0xeBbbaC35500713C4AD49929e1bE4225c7efF6510",
"kaia": "0xC3C73FEE9Cef413880696e6C39365BDf8cD564f9",
"linea": "0x8437A5fE47A4Df14700c96DF1870824e72FA8499",
"metis": "0x763f212f355433C59d734C71247d16fCE74D8785",
"soneium": "0xeBbbaC35500713C4AD49929e1bE4225c7efF6510",
"taiko": "0x8437A5fE47A4Df14700c96DF1870824e72FA8499",
"unichain": "0xeBbbaC35500713C4AD49929e1bE4225c7efF6510"
},
"refundWallet": "0x156CeBba59DEB2cB23742F70dCb0a11cC775591F",
"withdrawWallet": "0x08647cc950813966142A416D40C382e2c5DB73bB",
"pauserWallet": "0xd38743b48d26743C0Ec6898d699394FBc94657Ee",
Expand Down
Loading

0 comments on commit e0b4475

Please sign in to comment.