-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.sh
executable file
·157 lines (134 loc) · 3.82 KB
/
config.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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> -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() {
if [ "$NETWORK" == 'ronin-mainnet' ]; then
RPC=$MAINNET_URL
EXPLORER=https://app.roninchain.com
ERC721_BATCH_TRANSFER=0x2368dfed532842db89b470fde9fd584d48d4f644
if [ "$MODE" == "broadcast" ]; then
PK=$MAINNET_PK
fi
else
RPC=$TESTNET_URL
EXPLORER=https://saigon-app.roninchain.com
ERC721_BATCH_TRANSFER=0x2e889348bd37f192063bfec8ff39bd3635949e20
if [ "$MODE" == "broadcast" ]; then
PK=$TESTNET_PK
fi
fi
if [ "$MODE" == "broadcast" ]; then
CURRENT_GAS_PRICE=$(cast gas-price --rpc-url $RPC)
if [[ "$PK" == op://* ]]; then
PK=$(op read "$PK")
fi
fi
CURRENT_NONCE=$(cast nonce --rpc-url $RPC $FROM)
echo "Current nonce: $CURRENT_NONCE"
}
# 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
}
# 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 nonce="$1"
local target="$2"
local args="$3"
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/tx/$txHash
}
# Check if command-line arguments are provided
if [ "$#" -eq 0 ]; then
usage
fi
# 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"
;;
*)
# 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