-
Notifications
You must be signed in to change notification settings - Fork 0
/
tenderlyDeal.sh
executable file
·128 lines (110 loc) · 3.28 KB
/
tenderlyDeal.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
#!/bin/bash
source .env.local
# this script is used to deal tokens to the specified account
# check if MNEMONIC is set, if not, prompt the user
if [ -z "$MNEMONIC" ]; then
echo "Enter Mnemonic:"
read mnemonic
# if mnemonic is empty, use default
if [ -z "$mnemonic" ]; then
export MNEMONIC='test test test test test test test test test test test junk'
else
export MNEMONIC=$mnemonic
fi
else
mnemonic=$MNEMONIC
fi
rpc_url=$REMOTE_RPC_URL
# select mnemonic index from 0 to 10. ask the user
echo "Enter account index (0-256):"
read accountIndex
# if accountIndex is not a number, exit
if ! [[ $accountIndex =~ ^[0-9]+$ ]]; then
echo "Invalid account index"
exit 1
fi
# if accountIndex is greater than 256, exit
if [ $accountIndex -gt 256 ]; then
echo "Account index is greater than 256"
exit 1
fi
account=$(cast wallet address --mnemonic "$MNEMONIC" --mnemonic-index $accountIndex)
dealValue=1000000
echo "Trying to deal the tokens to $account..."
echo "Setting ETH balance..."
ethDecimals=18
ethDealValueCalc=$(echo "obase=16; $dealValue * 10^$ethDecimals" | bc)
ethDealValueHex="0x$(printf $ethDealValueCalc)"
# fund ETH first
jsonPayload=$(jq -n \
--arg account "$account" \
--arg ethDealValueHex "$ethDealValueHex" \
'{
"jsonrpc": "2.0",
"method": "tenderly_setBalance",
"params": [
$account,
$ethDealValueHex
],
"id": 1
}')
echo "JSON payload for $symbol: $jsonPayload"
response=$(curl -s -X POST $rpc_url \
-H "Content-Type: application/json" \
-d "$jsonPayload")
# Load the token list from the JSON file
tokenListPath=$(pwd)"/data/forkTokenList.json"
tokenListJson=$(cat $tokenListPath)
# Loop through the JSON array of tokens
for row in $(echo "${tokenListJson}" | jq -r '.[] | @base64'); do
echo "--------------------------------------------------------------------------------"
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
# Get the token address, decimals and symbol
asset=$(_jq '.addressInfo')
decimals=$(_jq '.decimals')
symbol=$(_jq '.symbol')
dealValueCalc=$(echo "obase=16; $dealValue * 10^$decimals" | bc)
dealValueHex="0x$(printf $dealValueCalc)"
echo "Deal value in hex: $dealValueHex"
# successfullyDealt=false
# https://docs.tenderly.co/devnets/advanced/custom-rpc-methods#tenderly_seterc20balance
# {
# "jsonrpc": "2.0",
# "method": "tenderly_setErc20Balance",
# "params": [
# "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
# "0x40BdB4497614bAe1A67061EE20AAdE3c2067AC9e",
# "0xDE0B6B3A7640000"
# ],
# "id": 3640
# }
# Construct the JSON payload
jsonPayload=$(jq -n \
--arg account "$account" \
--arg asset "$asset" \
--arg dealValueHex "$dealValueHex" \
'{
"jsonrpc": "2.0",
"method": "tenderly_setErc20Balance",
"params": [
$asset,
$account,
$dealValueHex
],
"id": 1
}')
echo "JSON payload for $symbol: $jsonPayload"
response=$(curl -s -X POST $rpc_url \
-H "Content-Type: application/json" \
-d "$jsonPayload")
# example response
# {
# "id": 3640,
# "jsonrpc": "2.0",
# "result": "0x8a84686634729c57532b9ffa4e632e241b2de5c880c771c5c214d5e7ec465b1c"
# }
echo "Response for token $symbol: $response"
done
echo Done