-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·109 lines (79 loc) · 5.81 KB
/
deploy.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
#!/bin/bash
# set -x
private_key="0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659"
# Define the modules
# modules=("bitmap" "engine")
modules=("bitmap" "tick" "order" "matcher" "engine")
# Define the deployment command
deploy_command="cargo stylus deploy -e http://localhost:8547 --private-key \$private_key --no-verify"
# Declare an associative array to store addresses
declare -A addresses
# Loop through each module and deploy
for module in "${modules[@]}"; do
echo "Deploying $module..."
output=$(cd "$(dirname "$0")/$module" && eval $deploy_command 2>&1)
# Print the output for debugging
# echo "Deployment output for $module:"
# echo "$output"
# Parse the deployed contract address and remove color codes
address=$(echo "$output" | sed -r 's/\x1b\[[0-9;]*m//g' | awk '/deployed code at address:/ {print $NF}')
# Store the address in the associative array
addresses[$module]=$address
echo "Deployed $module at address: ${addresses[$module]}"
done
# Print all addresses
echo "All deployed addresses:"
for module in "${!addresses[@]}"; do
snake_case_module=$(echo "$module" | sed -r 's/([a-z])([A-Z])/\1_\2/g; s/-/_/g' | tr '[:lower:]' '[:upper:]')
echo "export "${snake_case_module}_ADDRESS=${addresses[$module]}""
done
# Define the RPC URL
rpc_url="http://localhost:8547"
echo "Initialize contracts"
# Initialize engine
# cast send "${addresses[engine]}" "initialize(address,address,address,address)" "${addresses[tick]}" "${addresses[order]}" "${addresses[bitmap]}" "${addresses[matcher]}" --rpc-url $rpc_url --private-key $private_key
cast send "${addresses[engine]}" "initialize(address,address,address,address)" "${addresses[tick]}" "${addresses[order]}" "${addresses[bitmap]}" "${addresses[matcher]}" --rpc-url $rpc_url --private-key $private_key > /dev/null 2>&1
# Initialize matcher
# cast send "${addresses[matcher]}" "initialize(address,address)" "${addresses[bitmap]}" "${addresses[order]}" --rpc-url $rpc_url --private-key $private_key
cast send "${addresses[matcher]}" "initialize(address,address)" "${addresses[bitmap]}" "${addresses[order]}" --rpc-url $rpc_url --private-key $private_key > /dev/null 2>&1
# Initialize tick
# cast send "${addresses[tick]}" "initialize(address,address,address)" "${addresses[engine]}" "${addresses[bitmap]}" "${addresses[order]}" --rpc-url $rpc_url --private-key $private_key
cast send "${addresses[tick]}" "initialize(address,address,address)" "${addresses[engine]}" "${addresses[bitmap]}" "${addresses[order]}" --rpc-url $rpc_url --private-key $private_key > /dev/null 2>&1
# Initialize order
# cast send "${addresses[order]}" "initialize(address,address,address)" "${addresses[engine]}" "${addresses[bitmap]}" "${addresses[tick]}" --rpc-url $rpc_url --private-key $private_key
cast send "${addresses[order]}" "initialize(address,address,address)" "${addresses[engine]}" "${addresses[bitmap]}" "${addresses[tick]}" --rpc-url $rpc_url --private-key $private_key > /dev/null 2>&1
echo "Set initial tick"
cast send --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "setCurrentTick(uint256)" 100 > /dev/null 2>&1
# cast send --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "setCurrentTick(uint256)" 100 > /dev/null 2>&1
echo "Place sell orders..."
# Place sell orders (false = sell)
for tick in {105..100}; do
# cast send --rpc-url $rpc_url --private-key $private_key "${addresses[engine]}" "placeOrder(uint256,uint256,address,bool,bool)" $tick 100 "0xf7ced2890a5428cc1f46252b0f04600234e8ab6e" false false
cast send --rpc-url $rpc_url --private-key $private_key "${addresses[engine]}" "placeOrder(uint256,uint256,address,bool,bool)" $tick 100 "0xf7ced2890a5428cc1f46252b0f04600234e8ab6e" false false > /dev/null 2>&1
done
echo "Place buy orders..."
# Place buy orders (true = buy)
for tick in {99..95}; do
# cast send --rpc-url $rpc_url --private-key $private_key "${addresses[engine]}" "placeOrder(uint256,uint256,address,bool,bool)" $tick 100 "0xf7ced2890a5428cc1f46252b0f04600234e8ab6e" true false
cast send --rpc-url $rpc_url --private-key $private_key "${addresses[engine]}" "placeOrder(uint256,uint256,address,bool,bool)" $tick 100 "0xf7ced2890a5428cc1f46252b0f04600234e8ab6e" true false > /dev/null 2>&1
done
echo "Get top best ticks for seller"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "topNBestTicks(bool)" false
echo "Get top best ticks for buyer"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "topNBestTicks(bool)" true
echo "Get bitmap #1"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "getBitmap(int16)" 0
echo "Get tick #1"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "getCurrentTick()(uint256)"
echo "Place limit buy order to fill sell order at tick 101"
cast send --rpc-url $rpc_url --private-key $private_key "${addresses[engine]}" "placeOrder(uint256,uint256,address,bool,bool)" 101 100 "0xf7ced2890a5428cc1f46252b0f04600234e8ab6e" true false > /dev/null 2>&1
echo "Get bitmap #2"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "getBitmap(int16)" 0
echo "Get tick #2"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "getCurrentTick()(uint256)"
echo "Place limit sell order to fill buy order at tick 98 (The order book will use 100 to fill this order since it was the best buy tick)"
cast send --rpc-url $rpc_url --private-key $private_key "${addresses[engine]}" "placeOrder(uint256,uint256,address,bool,bool)" 98 100 "0xf7ced2890a5428cc1f46252b0f04600234e8ab6e" false false > /dev/null 2>&1
echo "Get bitmap #3"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "getBitmap(int16)" 0
echo "Get tick #3"
cast call --rpc-url $rpc_url --private-key $private_key "${addresses[bitmap]}" "getCurrentTick()(uint256)"