Skip to content

Commit

Permalink
feat: refactor operation script
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Nov 15, 2023
1 parent 4ebdc61 commit 6040a29
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 85 deletions.
178 changes: 120 additions & 58 deletions config.sh
Original file line number Diff line number Diff line change
@@ -1,93 +1,155 @@
# Function to print usage and exit
source .env

EXTRA_ARGS=()
FROM=
TARGET=
CURRENT_NONCE=
EXTRA_GAS_PRICE=
CURRENT_GAS_PRICE=
DEPLOYMENT_ROOT='deployments'

# Function to display script usage
usage() {
echo "Usage: $0 -c <network>"
echo " -c: Specify the network (ronin-testnet or ronin-mainnet)"
echo "Usage: $0 -c <network> -m <mode> [-eg <extra_gas_price>] -f <from>"
echo "Options:"
echo " -c: Specify the network <ronin-mainnet|ronin-testnet>"
echo " -m: Specify running mode <estimate|broadcast|trace>"
echo " -f: Specify the sender address"
echo " -eg: Extra gas price (default: 0)"
exit 1
}

# Function to load configuration based on network and mode
loadConfig() {
local network="$1"

if [ "$network" == 'ronin-mainnet' ]; then
RPC=https://api.roninchain.com/rpc
EXPLORER=https://app.roninchain.com/tx
FROM=0x968D0Cd7343f711216817E617d3f92a23dC91c07

RESOLVER=0xadb077d236d9E81fB24b96AE9cb8089aB9942d48
CONTROLLER=0x662852853614cbBb5D04BF2E29955b97E3C50B69
RNS_UNIFIED=0xf0c99c9677EDa0D13291C093b27E6512E4ACdF83
RNS_AUCTION=0xD55e6d80aeA1FF4650BC952C1653ab3CF1b940A9
RNS_DOMAIN_PRICE=0x2BdC555A87Db9207E5d175f0c12B237736181675
OWNED_MULTICALLER=0x8975923D01132bEB6c412F827f63D44712726E13
ERC721_BATCH_TRANSFER=0x2368dfed532842db89b470fde9fd584d48d4f644
if [ "$NETWORK" == 'ronin-mainnet' ]; then
RPC=$MAINNET_URL
EXPLORER=https://app.roninchain.com

CURRENT_GAS_PRICE=$(cast gas-price --rpc-url $RPC)
CURRENT_NONCE=$(cast nonce --rpc-url $RPC $FROM)
ERC721_BATCH_TRANSFER=0x2368dfed532842db89b470fde9fd584d48d4f644

PK=$(op read "op://Private/Ronin Mainnet Deployer/private key")
if [ "$MODE" == "broadcast" ]; then
PK=$TESTNET_PK
fi
else
RPC=https://saigon-archive.roninchain.com/rpc
FROM=0x057B3862d021f8931c96f789f2A7c4d3eA3C665f
EXPLORER=https://saigon-app.roninchain.com/tx

RESOLVER=0x803c459dCB8771e5354D1fC567Ecc6885A9fd5E6
CONTROLLER=0x512699B52ac2dC2b2aD505d9f29DcDad078FA799
RNS_UNIFIED=0x67C409DaB0EE741A1B1Be874bd1333234cfDBF44
RNS_AUCTION=0xb962eddeD164f55D136E491a3022246815e1B5A8
RNS_DOMAIN_PRICE=0x51cAF51678f469e9DD4c878a7b0ceBEbbd4A4AB5
OWNED_MULTICALLER=0x8975923D01132bEB6c412F827f63D44712726E13
RPC=$TESTNET_URL
EXPLORER=https://saigon-app.roninchain.com

ERC721_BATCH_TRANSFER=0x2e889348bd37f192063bfec8ff39bd3635949e20

CURRENT_GAS_PRICE=$(cast gas-price --rpc-url $RPC)
if [ "$MODE" == "broadcast" ]; then
PK=$MAINNET_PK
fi
fi

if [ "$MODE" == "broadcast" ]; then
CURRENT_NONCE=$(cast nonce --rpc-url $RPC $FROM)
CURRENT_GAS_PRICE=$(cast gas-price --rpc-url $RPC)

PK=$(op read "op://SC Vault/Testnet Admin/private key")
if [[ "$PK" == op://* ]]; then
PK=$(op read "$PK")
fi
fi
}

estimate() {
# Function to load address from deployment file
loadAddress() {
local contract="$1"
echo $(jq -r '.address' ${DEPLOYMENT_ROOT}/${NETWORK}/${contract}.json)
}

# Function to execute based on the specified mode
execute() {
local nonce="$1"
local target="$2"
local args="$3"

if [ "$MODE" == "broadcast" ]; then
broadcast "$nonce" "$target" "$args"
elif [ "$MODE" == "estimate" ]; then
estimate "$target" "$args"
elif [ "$MODE" == "trace" ]; then
trace "$target" "$args"
else
echo "Error: Invalid mode option. Choose either 'broadcast', 'estimate', or 'trace'."
fi
}

# Function to perform a trace
trace() {
local target="$1"
local args="$2"
cast c $EXTRA_ARGS --from $FROM --trace --rpc-url $RPC $target $args
}

gas=$(cast e --from $FROM --rpc-url $RPC $target $args)
# Function to estimate gas
estimate() {
local target="$1"
local args="$2"
gas=$(cast e $EXTRA_ARGS --from $FROM --rpc-url $RPC $target $args)
echo estimated gas: $gas
}

# Function to broadcast a transaction
broadcast() {
local gasPrice="$1"
local nonce="$2"
local target="$3"
local args="$4"
local nonce="$1"
local target="$2"
local args="$3"

txHash=$(cast s --from $FROM --legacy --gas-price $gasPrice --async --confirmations 0 --nonce $nonce --private-key $PK --rpc-url $RPC $target $args)
txHash=$(cast s $EXTRA_ARGS --from $FROM --legacy --gas-price $((CURRENT_GAS_PRICE + EXTRA_GAS_PRICE)) --async --confirmations 0 --nonce $nonce --private-key $PK --rpc-url $RPC $target $args)

echo $EXPLORER/$txHash
echo $EXPLORER/tx/$txHash
}

# Parse command-line options
# Check if command-line arguments are provided
if [ "$#" -eq 0 ]; then
usage
fi

# Parse command-line options
while getopts "c:" opt; do
case $opt in
c)
case "$OPTARG" in
ronin-testnet)
loadConfig "ronin-testnet"
;;
ronin-mainnet)
loadConfig "ronin-mainnet"
;;
*)
echo "Unknown network specified: $OPTARG"
usage
;;
esac
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--from | -f)
shift
FROM="$1"
;;
--chain | -c)
shift
NETWORK="$1"
;;
--mode | -m)
shift
MODE="$1"
;;
--extra-gas | -eg)
shift
EXTRA_GAS_PRICE="$1"
;;
*)
usage
# Check if the next argument is present
if [ -n "$2" ]; then
# Add both the flag and its value to EXTRA_ARGS
EXTRA_ARGS+=("$1 $2")
shift
else
# Add only the flag to EXTRA_ARGS
EXTRA_ARGS+=("$1")
fi
;;
esac
shift
done

# Check if all required arguments are provided
if [ -z "$NETWORK" ] || [ -z "$MODE" ] || [ -z "$FROM" ]; then
echo "Error: Missing required arguments!"
usage
fi

# Validate network and mode options
if [ "$NETWORK" != "ronin-testnet" ] && [ "$NETWORK" != "ronin-mainnet" ]; then
echo "Error: Invalid network option. Choose either 'ronin-testnet' or 'ronin-mainnet'."
usage
fi

# Load configuration based on network and mode
loadConfig
2 changes: 1 addition & 1 deletion script/operations/batch-transfer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for index in "${indices[@]}"; do
echo "${namehashResults[*]}"
)

broadcast $CURRENT_GAS_PRICE $nextNonce $ERC721_BATCH_TRANSFER $(cast calldata "safeBatchTransfer(address,uint256[],address[])" $RNS_UNIFIED "[$joinedString]" "[$addresses]")
execute $nextNonce $ERC721_BATCH_TRANSFER $(cast calldata "safeBatchTransfer(address,uint256[],address[])" $(loadAddress RNSUnifiedProxy) "[$joinedString]" "[$addresses]")
) &

# Check if index is a multiple of 100, then wait
Expand Down
2 changes: 1 addition & 1 deletion script/operations/bulk-claim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for index in "${indices[@]}"; do
echo "${namehashResults[*]}"
)

broadcast $CURRENT_GAS_PRICE $nextNonce $RNS_AUCTION $(cast calldata "bulkClaimBidNames(uint256[])" "[$joinedString]")
execute $nextNonce $(loadAddress RNSUnifiedProxy) $(cast calldata "bulkClaimBidNames(uint256[])" "[$joinedString]")
) &

# Check if index is a multiple of 100, then wait
Expand Down
2 changes: 1 addition & 1 deletion script/operations/claim-auction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for index in {0..0}; do

echo "Labels for AuctionNames${index}: $labelsString"

broadcast $CURRENT_GAS_PRICE $nextNonce $RNS_AUCTION $(cast calldata "bulkRegister(string[])" "[$labelsString]")
execute $nextNonce $(loadAddress RNSAuctionProxy) $(cast calldata "bulkRegister(string[])" "[$labelsString]")
) &

# Check if index is a multiple of 100, then wait
Expand Down
2 changes: 1 addition & 1 deletion script/operations/list-auction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for index in {0..0}; do
echo auctionId $auctionId
echo startingPrices $startingPrices

broadcast $CURRENT_GAS_PRICE $nextNonce $RNS_AUCTION $(cast calldata "listNamesForAuction(bytes32,uint256[],uint256[])" "$auctionId" "[$joinedString]" "[$startingPrices]")
execute $nextNonce $(loadAddress RNSAuctionProxy) $(cast calldata "listNamesForAuction(bytes32,uint256[],uint256[])" "$auctionId" "[$joinedString]" "[$startingPrices]")
) &

# Check if index is a multiple of 100, then wait
Expand Down
2 changes: 1 addition & 1 deletion script/operations/mint-reseved-names.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ for index in "${indices[@]}"; do
echo auctionId $auctionId
echo addresses $addresses

broadcast $CURRENT_GAS_PRICE $nextNonce $OWNED_MULTICALLER $(cast calldata "multiMint(address,uint256,address,uint64,address[],string[])" $RNS_UNIFIED $RON_ID $RESOLVER $DURATION "[$(IFS=, echo "${addresses[*]}")]" "[$(IFS=, echo "${labels[*]}")]")
execute $nextNonce $(loadAddress OwnedMulticaller) $(cast calldata "multiMint(address,uint256,address,uint64,address[],string[])" $(loadAddress RNSUnifiedProxy) $RON_ID $(loadAddress PublicResolverProxy) $DURATION "[$(IFS=, echo "${addresses[*]}")]" "[$(IFS=, echo "${labels[*]}")]")
) &

# Check if index is a multiple of 100, then wait
Expand Down
2 changes: 1 addition & 1 deletion script/operations/override-fee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ for index in $(seq $start $end); do
echo "${labelhashResults[*]}"
)

broadcast $CURRENT_GAS_PRICE $nextNonce $RNS_DOMAIN_PRICE $(cast calldata "bulkOverrideRenewalFees(bytes32[],uint256[])" "[$lbHash]" "[$fees]")
execute $nextNonce $(loadAddress RNSDomainPriceProxy) $(cast calldata "bulkOverrideRenewalFees(bytes32[],uint256[])" "[$lbHash]" "[$fees]")
) &
done

Expand Down
2 changes: 1 addition & 1 deletion script/operations/place-bid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ index=0
for id in "${namehashResults[@]}"; do
(
nextNonce=$((CURRENT_NONCE + index))
broadcast $CURRENT_GAS_PRICE $nextNonce $RNS_AUCTION $(cast calldata "placeBid(uint256)" "$id")
execute $nextNonce $(loadAddress RNSAuctionProxy) $(cast calldata "placeBid(uint256)" "$id")
) &

# Increment the index
Expand Down
2 changes: 1 addition & 1 deletion script/operations/set-protected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ for index in "${indices[@]}"; do
# Print the result
echo "Joined String: $joinedString"

broadcast $CURRENT_GAS_PRICE $nextNonce $RNS_UNIFIED $(cast calldata "bulkSetProtected(uint256[],bool)" "[$joinedString]" false)
execute $nextNonce $(loadAddress RNSUnifiedProxy) $(cast calldata "bulkSetProtected(uint256[],bool)" "[$joinedString]" false)
) &

# Check if index is a multiple of 100, then wait
Expand Down
2 changes: 1 addition & 1 deletion script/operations/whitelist-protected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ for index in "${indices[@]}"; do
echo "Ids String: $ids"
echo "Owners String: $owners"

broadcast $CURRENT_GAS_PRICE $nextNonce $CONTROLLER $(cast calldata "bulkWhitelistProtectedNames(uint256[],address[],bool)" "[$ids]" "[$owners]" true)
execute $nextNonce $(loadAddress RONRegistrarControllerProxy) $(cast calldata "bulkWhitelistProtectedNames(uint256[],address[],bool)" "[$ids]" "[$owners]" true)
) &

# Check if index is a multiple of 100, then wait
Expand Down
43 changes: 25 additions & 18 deletions upload-sig.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set -ex
# Default network value
networkName="ronin-testnet"
# Function to print usage and exit
Expand Down Expand Up @@ -46,26 +47,32 @@ for file in "$folder"/*.json; do
contractName=$(jq -r '.contractName' "$file")
# Check if contractName and address are not empty
if [ -n "$contractName" ]; then
# Initialize arrays to store events and errors keys
events_keys=()
errors_keys=()
# Get events and errors JSON data
events=$(forge inspect $contractName events)
errors=$(forge inspect $contractName errors)
# Extract keys and populate the arrays
while read -r key; do
events_keys+=("\"event $key\"")
done <<<"$(echo "$events" | jq -r 'keys[]')"
while read -r key; do
errors_keys+=("\"$key\"")
done <<<"$(echo "$errors" | jq -r 'keys[]')"
# Combine keys from events and errors
all_keys=("${events_keys[@]}" "${errors_keys[@]}")
# Call cast upload-signature
cast upload-signature "${all_keys[@]}"
(
# Initialize arrays to store events and errors keys
events_keys=()
errors_keys=()
# Get events and errors JSON data
events=$(forge inspect $contractName events)
errors=$(forge inspect $contractName errors)
# Extract keys and populate the arrays
while read -r key; do
events_keys+=("\"event $key\"")
done <<<"$(echo "$events" | jq -r 'keys[]')"
while read -r key; do
errors_keys+=("\"$key\"")
done <<<"$(echo "$errors" | jq -r 'keys[]')"
# Combine keys from events and errors
all_keys=("${events_keys[@]}" "${errors_keys[@]}")
# Call cast upload-signature
cast upload-signature "${all_keys[@]}"
) &
else
echo "Error: Missing contractName or address in $file"
fi
fi

done
forge selectors upload --all

forge selectors upload --all &

wait

0 comments on commit 6040a29

Please sign in to comment.