forked from connext/monorepo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-integration-local-test.sh
executable file
·149 lines (122 loc) · 5.75 KB
/
setup-integration-local-test.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
#!/bin/bash
##### Loading .env file contents
echo "Loading .env contents"
set -a
source .env
set +a
echo ".env contents loaded"
#####
#For M* macs set the default platform to linux/amd64
# export DOCKER_DEFAULT_PLATFORM=linux/amd64
##### Config Variables
LOCALHOST="127.0.0.1"
NETWORK="local"
#####
##### Delete previous local-mainnet, local-optimism and local-arbitrum chain deployment records if they exist.
rm -rf -- packages/deployments/contracts/deployments/local-mainnet
rm -rf -- packages/deployments/contracts/deployments/local-optimism
rm -rf -- packages/deployments/contracts/deployments/local-arbitrum
#####
##### Local chains, graph nodes, and IPFS.
echo "Starting mainnet, optimism, arbitrum local chains..."
docker compose -f docker-compose.chains.yaml up -d --force-recreate
sleep 5
#####
##### Contract Deployments
echo "Deploying contracts to local-mainnet..."
yarn workspace @connext/smart-contracts hardhat deploy --network local-mainnet --tags local
echo "Deployed contracts to local-mainnet"
echo "Deploying contracts to local-optimism..."
yarn workspace @connext/smart-contracts hardhat deploy --network local-optimism --tags local
echo "Deployed contracts to local-optimism"
echo "Deploying contracts to local-arbitrum..."
yarn workspace @connext/smart-contracts hardhat deploy --network local-arbitrum --tags local
echo "Deployed contracts to local-arbtirum"
yarn workspace @connext/smart-contracts run export
#####
##### Contract Deployments
echo "Initializing contracts..."
yarn workspace @connext/smart-contracts run local:init
echo "Initialized contracts..."
#####
##### Subgraph Deployments
echo "Building subgraph for the hub chain - mainnet-local..."
yarn workspace @connext/nxtp-subgraph prepare:local:hub
yarn workspace @connext/nxtp-subgraph codegen
echo "Built subgraph for the hub chain"
echo "Deploying subgraph to the hub chain - mainnet-local..."
yarn workspace @connext/nxtp-subgraph create:local:hub:mainnet
yarn workspace @connext/nxtp-subgraph deploy:local:hub:mainnet
yarn workspace @connext/nxtp-subgraph prepare:local:spoke:mainnet
yarn workspace @connext/nxtp-subgraph codegen
yarn workspace @connext/nxtp-subgraph create:local:spoke:mainnet
yarn workspace @connext/nxtp-subgraph deploy:local:spoke:mainnet
echo "Deployed subgraph to the hub chain - mainnet-local"
echo "Building subgraph for the spoke chain - optimism-local"
yarn workspace @connext/nxtp-subgraph prepare:local:spoke:optimism
yarn workspace @connext/nxtp-subgraph codegen
echo "Built subgraph for the spoke chain - optimism-local"
echo "Deploying subgraph to the spoke chain - optimism-local..."
yarn workspace @connext/nxtp-subgraph create:local:spoke:optimism
yarn workspace @connext/nxtp-subgraph deploy:local:spoke:optimism
echo "Deployed subgraphs to the optimism-local"
echo "Building subgraph for the spoke chain - arbitrum-local"
yarn workspace @connext/nxtp-subgraph prepare:local:spoke:arbitrum
yarn workspace @connext/nxtp-subgraph codegen
echo "Built subgraph for the spoke chain - arbitrum-local"
echo "Deploying subgraph to the spoke chain - arbitrum-local..."
yarn workspace @connext/nxtp-subgraph create:local:spoke:arbitrum
yarn workspace @connext/nxtp-subgraph deploy:local:spoke:arbitrum
echo "Deployed subgraph to the arbitrum-local"
#####
##### Create config files from the templates.
mainnet_rpcs=("http://local-mainnet:8545")
optimism_rpcs=("http://local-optimism:8545")
arbitrum_rpcs=("http://local-arbitrum:8545")
chains_mainnet=$(jq -n --argjson providers "$(printf '%s\n' "${mainnet_rpcs[@]}" | jq -R . | jq -s .)" '{"providers": $providers}')
chains_optimism=$(jq -n --argjson providers "$(printf '%s\n' "${optimism_rpcs[@]}" | jq -R . | jq -s .)" '{"providers": $providers}')
chains_arbitrum=$(jq -n --argjson providers "$(printf '%s\n' "${arbitrum_rpcs[@]}" | jq -R . | jq -s .)" '{"providers": $providers}')
echo "mainnet: $chains_mainnet"
echo "optimism: $chains_optimism"
echo "arbitrum: $chains_arbitrum"
chains_json=$(jq -n \
--argjson chains_mainnet "$chains_mainnet" \
--argjson chains_optimism "$chains_optimism" \
--argjson chains_arbitrum "$chains_arbitrum" \
'{"31337": $chains_mainnet, "31338": $chains_optimism, "31339": $chains_arbitrum}'
)
echo "chains: $chains_json"
# Add docker paths to replace/add `chains` in config.json
config_dir_paths=("docker/cartographer" "docker/lighthouse" "docker/router" "docker/sequencer" "docker/relayer" "docker/watcher")
template_file="config-template.json"
for dir_path in "${config_dir_paths[@]}"; do
echo "Finding $template_file in $dir_path"
template_file_path="$dir_path/$template_file"
# Check if the config file exists
if [ -f "$template_file_path" ]; then
target_file_path="${dir_path}/config.json"
# Use jq to load the JSON file, add elements, and save the modified content
jq ". + { "network": \"$NETWORK\", "chains": $chains_json }" "$template_file_path" > "$target_file_path"
else
echo "$template_file_path not found"
fi
done
#####
# Extract deployed addresses into docker config
echo "Updating docker config with the deployed contract addresses for router, sequencer and lighthouse"
yarn workspace @connext/nxtp-integration gen:config router local
yarn workspace @connext/nxtp-integration gen:config sequencer local
yarn workspace @connext/nxtp-integration gen:config lighthouse local
yarn workspace @connext/nxtp-integration gen:config relayer local
echo "Updating docker config done"
#####
##### Off-Chain Agents
echo "Starting services and off-chain agents..."
docker compose -f docker-compose.services.yaml up -d --force-recreate
sleep 5
#####
# Setup db schema
DATABASE_URL="postgresql://postgres:[email protected]:5435/connext?sslmode=disable"
echo "Setup db schema..."
yarn workspace @connext/nxtp-adapters-database dbmate -url $DATABASE_URL up
#####