33# It assumes that the secrets defined in the .env.example file are set in the environment
44# and that the Stellar CLI and Rust are installed.
55
6- set -x
7-
8- pushd ../soroban
9-
10- stellar contract build
11-
12- stellar contract deploy \
13- --wasm target/wasm32-unknown-unknown/release/account.wasm \
14- --source-account ${TEST_CLIENT_WALLET_SECRET} \
15- --network testnet \
16- --salt 616e63686f722d706c6174666f726d \
17- -- \
18- --admin ${TEST_CLIENT_WALLET_SECRET} \
19- --signer ${TEST_CLIENT_WALLET_PK_BYTES}
20-
21- stellar contract deploy \
22- --wasm target/wasm32-unknown-unknown/release/web_auth.wasm \
23- --source-account ${SECRET_SEP10_SIGNING_SEED} \
24- --network testnet \
25- --salt 616e63686f722d706c6174666f726d \
26- -- \
27- --admin ${SECRET_SEP10_SIGNING_SEED}
28-
29- stellar contract asset deploy \
30- --source ${SECRET_SEP10_SIGNING_SEED} \
31- --network testnet \
32- --asset USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP
6+ set -e
7+
8+ RED=' \033[0;31m'
9+ GREEN=' \033[0;32m'
10+ YELLOW=' \033[1;33m'
11+ BLUE=' \033[0;34m'
12+ NC=' \033[0m'
13+
14+ log_info () { echo -e " ${BLUE} [INFO]${NC} $1 " ; }
15+ log_success () { echo -e " ${GREEN} [SUCCESS]${NC} $1 " ; }
16+ log_warning () { echo -e " ${YELLOW} [WARNING]${NC} $1 " ; }
17+ log_error () { echo -e " ${RED} [ERROR]${NC} $1 " ; }
18+
19+ check_prerequisites () {
20+ log_info " Checking prerequisites..."
21+ command -v stellar & > /dev/null || {
22+ log_error " Stellar CLI not installed"
23+ exit 1
24+ }
25+ command -v rustc & > /dev/null || {
26+ log_error " Rust not installed"
27+ exit 1
28+ }
29+ log_success " Prerequisites check passed"
30+ }
31+
32+ load_env () {
33+ log_info " Loading environment..."
34+ [[ -f " ../.env" ]] || {
35+ log_error " .env file not found"
36+ exit 1
37+ }
38+ source ../.env
39+ log_success " Environment loaded"
40+ }
41+
42+ fund_account () {
43+ local public_key=$1
44+ log_info " Funding: $public_key "
45+ curl -s " https://friendbot.stellar.org/?addr=$public_key " > /dev/null
46+ }
47+
48+ fund_test_accounts () {
49+ log_info " Funding test accounts..."
50+ local accounts=(
51+ " SECRET_SEP10_SIGNING_SEED:GDAHPZ2NSYIIHZXM56Y36SBVTV5QKFIZGYMMBHOU53ETUSWTP62B63EQ"
52+ " TEST_CLIENT_WALLET_SECRET:GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
53+ " TEST_CLIENT_WALLET_EXTRA_SIGNER_1_SECRET:GC6X2ANA2OS3O2ESHUV6X44NH6J46EP2EO2JB7563Y7DYOIXFKHMHJ5O"
54+ " TEST_CLIENT_WALLET_EXTRA_SIGNER_2_SECRET:GATEYCIMJZ2F6Y437QSYH4XFQ6HLD5YP4MBJZFFPZVEQDJOY4QTCB7BB"
55+ " TEST_WITHDRAW_FUND_CLIENT_SECRET_1:GDC2U5GRKUSPGV5XENLBWKQZH2C4PG7ZEVMQOUA2QZKIRXE5FYYEMEF7"
56+ " TEST_WITHDRAW_FUND_CLIENT_SECRET_2:GASI56WX7UKIDFPZRCQEI4OQE3V3QBGXEOB4ZY6ZMU5MZXPHQHIDA7JU"
57+ " TEST_DEPOSIT_FUND_CLIENT_SECRET_1:GD4C2QRT7YL4WJFJPYQCYRXEDBB7ERHC3XZGWR6KXKRHPEFXXNXIVNFY"
58+ " TEST_DEPOSIT_FUND_CLIENT_SECRET_2:GC56VTOVOJDRQAJRYLZW6DLQGVTQSYDTZU7ISNIZ2VJIE3FYWI2HMD5G"
59+ )
60+
61+ for account_info in " ${accounts[@]} " ; do
62+ local secret_var=" ${account_info%%:* } "
63+ local public_key=" ${account_info##*: } "
64+ if [[ -n " ${! secret_var} " ]]; then
65+ fund_account " $public_key "
66+ fi
67+ sleep 1
68+ done
69+ }
70+
71+ setup_trustlines () {
72+ log_info " Setting up USDC trustlines..."
73+ local usdc_issuer=" ${USDC_ISSUER_PUBLIC:- GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP} "
74+ local circle_usdc_issuer=" GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
75+ local accounts=(
76+ " TEST_CLIENT_WALLET_SECRET"
77+ " TEST_WITHDRAW_FUND_CLIENT_SECRET_1"
78+ " TEST_WITHDRAW_FUND_CLIENT_SECRET_2"
79+ " TEST_DEPOSIT_FUND_CLIENT_SECRET_1"
80+ " TEST_DEPOSIT_FUND_CLIENT_SECRET_2"
81+ )
82+
83+ for account_var in " ${accounts[@]} " ; do
84+ local account_secret=" ${! account_var} "
85+ if [[ -n " $account_secret " ]]; then
86+ stellar tx new change-trust \
87+ --source-account " $account_secret " \
88+ --network testnet \
89+ --line " USDC:$usdc_issuer " > /dev/null 2>&1
90+ log_success " Anchor USDC trustline created for $account_var "
91+
92+ stellar tx new change-trust \
93+ --source-account " $account_secret " \
94+ --network testnet \
95+ --line " USDC:$circle_usdc_issuer " > /dev/null 2>&1
96+ log_success " Circle USDC trustline created for $account_var "
97+ fi
98+ sleep 1
99+ done
100+ }
101+
102+ issue_and_fund_usdc () {
103+ log_info " Issuing USDC and funding accounts..."
104+ local usdc_issuer_secret=" $USDC_ISSUER_SECRET "
105+ local usdc_issuer_public=" ${USDC_ISSUER_PUBLIC:- GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP} "
106+
107+ fund_account " $usdc_issuer_public "
108+
109+ local recipient_accounts=(
110+ " TEST_CLIENT_WALLET_SECRET:GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
111+ " TEST_WITHDRAW_FUND_CLIENT_SECRET_1:GDC2U5GRKUSPGV5XENLBWKQZH2C4PG7ZEVMQOUA2QZKIRXE5FYYEMEF7"
112+ " TEST_WITHDRAW_FUND_CLIENT_SECRET_2:GASI56WX7UKIDFPZRCQEI4OQE3V3QBGXEOB4ZY6ZMU5MZXPHQHIDA7JU"
113+ " TEST_DEPOSIT_FUND_CLIENT_SECRET_1:GD4C2QRT7YL4WJFJPYQCYRXEDBB7ERHC3XZGWR6KXKRHPEFXXNXIVNFY"
114+ " TEST_DEPOSIT_FUND_CLIENT_SECRET_2:GC56VTOVOJDRQAJRYLZW6DLQGVTQSYDTZU7ISNIZ2VJIE3FYWI2HMD5G"
115+ )
116+
117+ for recipient_info in " ${recipient_accounts[@]} " ; do
118+ local account_var=" ${recipient_info%%:* } "
119+ local recipient_public=" ${recipient_info##*: } "
120+ local account_secret=" ${! account_var} "
121+
122+ if [[ -n " $account_secret " ]]; then
123+ log_info " Sending 1000 USDC to $account_var ($recipient_public )..."
124+ if stellar tx new payment \
125+ --source-account " $usdc_issuer_secret " \
126+ --destination " $recipient_public " \
127+ --asset " USDC:$usdc_issuer_public " \
128+ --amount 10000000000 \
129+ --network testnet; then
130+ log_success " Sent 1000 USDC to $account_var "
131+ else
132+ log_warning " Failed to send USDC to $account_var "
133+ fi
134+ else
135+ log_warning " Skipping $account_var (no secret key found)"
136+ fi
137+ done
138+ }
139+
140+ reset_multisig () {
141+ log_info " Ensuring signers are present with 1/1/1 thresholds..."
142+ local primary_secret=" $TEST_CLIENT_WALLET_SECRET "
143+
144+ local signer1_public=" GC6X2ANA2OS3O2ESHUV6X44NH6J46EP2EO2JB7563Y7DYOIXFKHMHJ5O"
145+ local signer2_public=" GATEYCIMJZ2F6Y437QSYH4XFQ6HLD5YP4MBJZFFPZVEQDJOY4QTCB7BB"
146+
147+ stellar tx new set-options \
148+ --source-account " $primary_secret " \
149+ --network testnet \
150+ --signer " $signer1_public " \
151+ --signer-weight 1 > /dev/null 2>&1
152+
153+ stellar tx new set-options \
154+ --source-account " $primary_secret " \
155+ --network testnet \
156+ --signer " $signer2_public " \
157+ --signer-weight 1 > /dev/null 2>&1
158+
159+ log_success " Signers configured with 1/1/1 thresholds"
160+ }
161+
162+ deploy_contracts () {
163+ log_info " Deploying contracts..."
164+
165+ local deployer_secret=" $TEST_CLIENT_WALLET_SECRET "
166+ local deployer_public=" GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
167+
168+ log_info " Using $deployer_public as contract deployer"
169+
170+ pushd ../soroban > /dev/null
171+ stellar contract build
172+
173+ log_info " Deploying account contract..."
174+ local account_contract_result=$( stellar contract deploy \
175+ --wasm target/wasm32-unknown-unknown/release/account.wasm \
176+ --source-account " $deployer_secret " \
177+ --network testnet \
178+ --salt 616e63686f722d706c6174666f726d \
179+ -- \
180+ --admin " $deployer_public " \
181+ --signer " $CLIENT_WALLET_PK_BYTES " 2>&1 )
182+
183+ if [[ $? -eq 0 ]]; then
184+ local account_contract_id=$( echo " $account_contract_result " | tail -1)
185+ log_success " Account contract deployed: $account_contract_id "
186+ else
187+ log_warning " Account contract deployment skipped (already exists)"
188+ fi
189+
190+ log_info " Deploying web auth contract..."
191+ local webauth_deployer_secret=" $SECRET_SEP10_SIGNING_SEED "
192+ local webauth_deployer_public=" GDAHPZ2NSYIIHZXM56Y36SBVTV5QKFIZGYMMBHOU53ETUSWTP62B63EQ"
193+
194+ local webauth_contract_result=$( stellar contract deploy \
195+ --wasm target/wasm32-unknown-unknown/release/web_auth.wasm \
196+ --source-account " $webauth_deployer_secret " \
197+ --network testnet \
198+ --salt 616e63686f722d706c6174666f726d \
199+ -- \
200+ --admin " $webauth_deployer_public " 2>&1 )
201+
202+ if [[ $? -eq 0 ]]; then
203+ local webauth_contract_id=$( echo " $webauth_contract_result " | tail -1)
204+ log_success " Web auth contract deployed: $webauth_contract_id "
205+ else
206+ log_warning " Web auth contract deployment skipped (already exists)"
207+ fi
208+
209+ log_info " Deploying USDC asset contract..."
210+ if stellar contract asset deploy \
211+ --source " $deployer_secret " \
212+ --network testnet \
213+ --asset USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP 2> /dev/null; then
214+ log_success " USDC asset contract deployed"
215+ else
216+ log_warning " USDC asset contract deployment skipped (already exists)"
217+ fi
218+
219+ popd > /dev/null
220+ log_success " Contracts deployed"
221+ }
222+
223+ main () {
224+ log_info " Starting testnet reset..."
225+ check_prerequisites
226+ load_env
227+ fund_test_accounts
228+ reset_multisig
229+ setup_trustlines
230+ issue_and_fund_usdc
231+ deploy_contracts
232+ log_success " ✨ Testnet setup completed!"
233+ }
234+
235+ main " $@ "
0 commit comments