Skip to content

Commit 4f2da58

Browse files
sklppy88sklppy88
authored andcommitted
init
1 parent 0e30b2c commit 4f2da58

File tree

3 files changed

+319
-0
lines changed

3 files changed

+319
-0
lines changed

aztec-up/bootstrap.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function update_manifest {
2424
}
2525

2626
function test_cmds {
27+
echo "$hash aztec-up/scripts/run_test.sh amm_flow"
28+
echo "$hash aztec-up/scripts/run_test.sh bridge_and_claim"
2729
echo "$hash aztec-up/scripts/run_test.sh basic_install"
2830
echo "$hash aztec-up/scripts/run_test.sh counter_contract"
2931
}

aztec-up/test/amm_flow.sh

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
# Check we're in the test container.
5+
if [ ! -f /aztec_release_test_container ]; then
6+
echo "Not running inside the aztec release test container. Exiting."
7+
exit 1
8+
fi
9+
10+
if [ "$(whoami)" != "ubuntu" ]; then
11+
echo "Not running as ubuntu. Exiting."
12+
exit 1
13+
fi
14+
15+
export SKIP_PULL=1
16+
export NO_NEW_SHELL=1
17+
export INSTALL_URI=file:///home/ubuntu/aztec-packages/aztec-up/bin
18+
19+
if [ -t 0 ]; then
20+
bash_args="-i"
21+
else
22+
export NON_INTERACTIVE=1
23+
fi
24+
25+
bash ${bash_args:-} <(curl -s $INSTALL_URI/aztec-install)
26+
27+
# We can't create a new shell for this test, so just re-source our modified .bashrc to get updated PATH.
28+
PS1=" " source ~/.bash_profile
29+
30+
# Sanity check lsp.
31+
echo "Checking LSP..."
32+
echo -ne 'Content-Length: 100\r\n\r\n{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"rootUri": null, "capabilities": {}}}' \
33+
| aztec-nargo lsp \
34+
| grep -q '"jsonrpc":"2.0"'
35+
echo "LSP check passed."
36+
37+
export LOG_LEVEL=debug
38+
39+
# Start sandbox and wait for port to open.
40+
aztec start --sandbox &
41+
sandbox_pid=$!
42+
trap 'echo "Sending kill to pid $sandbox_pid"; kill $sandbox_pid &>/dev/null; wait $sandbox_pid' EXIT
43+
while ! curl -fs localhost:8080/status &>/dev/null; do sleep 1; done
44+
45+
function get_contract_address() {
46+
grep "Contract deployed at" | awk '{print $4}'
47+
}
48+
49+
canonical_sponsored_fpc_address=$(aztec \
50+
get-canonical-sponsored-fpc-address \
51+
| awk '{print $NF}')
52+
53+
SPONSORED_FPC_PAYMENT_METHOD="--payment method=fpc-sponsored,fpc=${canonical_sponsored_fpc_address}"
54+
55+
aztec-wallet import-test-accounts
56+
57+
# Execute wallet commands as per: https://docs.aztec.network/guides/getting_started
58+
59+
echo "Creating account"
60+
61+
aztec-wallet \
62+
create-account \
63+
-a main \
64+
--register-only
65+
66+
aztec-wallet \
67+
register-contract $canonical_sponsored_fpc_address SponsoredFPC \
68+
-f accounts:main \
69+
--salt 0
70+
71+
aztec-wallet \
72+
--prover native \
73+
deploy-account \
74+
-f accounts:main \
75+
$SPONSORED_FPC_PAYMENT_METHOD
76+
77+
# We only prove one of the three token deploys, because we do not want to duplicate proving effort for similar actions
78+
# We use this philosophy to dictate what we prove here and below.
79+
80+
echo "Deploying AMM setup"
81+
token_0_address=$(aztec-wallet \
82+
--prover native \
83+
deploy Token \
84+
--args accounts:main Test TST 18 \
85+
-f accounts:main \
86+
-a token_0 \
87+
$SPONSORED_FPC_PAYMENT_METHOD \
88+
| get_contract_address)
89+
90+
token_1_address=$(aztec-wallet \
91+
--prover none \
92+
deploy Token \
93+
--args accounts:main Test TST 18 \
94+
-f accounts:main \
95+
-a token_1 \
96+
$SPONSORED_FPC_PAYMENT_METHOD \
97+
| get_contract_address)
98+
99+
token_liquidity_address=$(aztec-wallet \
100+
--prover none \
101+
deploy Token \
102+
--args accounts:main Test TST 18 \
103+
-f accounts:main \
104+
-a token_liquidity \
105+
$SPONSORED_FPC_PAYMENT_METHOD \
106+
| get_contract_address)
107+
108+
amm_address=$(aztec-wallet \
109+
--prover native \
110+
deploy AMM \
111+
--args $token_0_address $token_1_address $token_liquidity_address \
112+
-f accounts:main \
113+
-a amm \
114+
$SPONSORED_FPC_PAYMENT_METHOD \
115+
| get_contract_address)
116+
117+
### mint_to_private
118+
119+
AMOUNT=420000000000
120+
121+
# We mint both tokens to our user
122+
echo "Minting token_0 and token_1 to private"
123+
124+
aztec-wallet \
125+
--prover native \
126+
send mint_to_private \
127+
-ca $token_0_address \
128+
--args accounts:main accounts:main $AMOUNT \
129+
$SPONSORED_FPC_PAYMENT_METHOD \
130+
-f accounts:main
131+
132+
aztec-wallet \
133+
--prover none \
134+
send mint_to_private \
135+
-ca $token_1_address \
136+
--args accounts:main accounts:main $AMOUNT \
137+
$SPONSORED_FPC_PAYMENT_METHOD \
138+
-f accounts:main
139+
140+
### add_liquidity
141+
142+
# We craft our authwits for sending add_liquidity
143+
aztec-wallet \
144+
create-secret \
145+
-a add-liquidity-nonce
146+
147+
aztec-wallet \
148+
create-authwit transfer_to_public $amm_address \
149+
-ca $token_0_address \
150+
--args accounts:main $amm_address $amount_0_max secrets:add-liquidity-nonce \
151+
-f accounts:main \
152+
-a amm-lp-token-0
153+
154+
aztec-wallet \
155+
create-authwit transfer_to_public $amm_address \
156+
-ca $token_1_address \
157+
--args accounts:main $amm_address $amount_1_max secrets:add-liquidity-nonce \
158+
-f accounts:main \
159+
-a amm-lp-token-1
160+
161+
amount_0_max=$((AMOUNT/4))
162+
amount_1_max=$((AMOUNT/4))
163+
amount_0_min=1
164+
amount_1_min=1
165+
166+
echo "Adding liquidity"
167+
168+
aztec-wallet \
169+
--prover native \
170+
send add_liquidity \
171+
-ca $amm_address \
172+
--args $amount_0_max $amount_1_max $amount_0_min $amount_1_min secrets:add-liquidity-nonce \
173+
-aw amm-lp-token-0 \
174+
-aw amm-lp-token-1 \
175+
-f accounts:main \
176+
$SPONSORED_FPC_PAYMENT_METHOD
177+
178+
### swap
179+
180+
amount_in=$((AMOUNT/88))
181+
182+
aztec-wallet \
183+
create-secret \
184+
-a swap-nonce
185+
186+
aztec-wallet \
187+
create-authwit transfer_to_public $amm_address \
188+
-ca $token_0_address \
189+
--args accounts:main $amm_address $amount_in secrets:swap-nonce \
190+
-f accounts:main \
191+
-a amm-swapper-token-0
192+
193+
echo "Swapping"
194+
195+
aztec-wallet \
196+
--prover native \
197+
send swap_exact_tokens_for_tokens \
198+
--ca $amm_address \
199+
--args $token_0_address $token_1_address $amount_in 0 secrets:swap-nonce \
200+
-aw amm-swapper-token-0 \
201+
-f accounts:main \
202+
$SPONSORED_FPC_PAYMENT_METHOD
203+
204+
### remove_liquidity
205+
206+
liquidity_token_balance=$(aztec-wallet \
207+
simulate balance_of_private \
208+
-ca $token_liquidity_address \
209+
--args accounts:main \
210+
-f accounts:main \
211+
| grep "Simulation result:" \
212+
| awk '{print $3}' \
213+
| sed 's/n$//')
214+
215+
echo "Liquidity token balance: $liquidity_token_balance"
216+
217+
aztec-wallet \
218+
create-secret \
219+
-a burn-nonce
220+
221+
aztec-wallet \
222+
create-authwit transfer_to_public $amm_address \
223+
-ca $token_liquidity_address \
224+
--args $current_user_address $amm_address $liquidity_token_balance secrets:burn-nonce \
225+
-f $current_user_address \
226+
-a amm-burn-token-liquidity
227+
228+
amount_0_min=1
229+
amount_1_min=1
230+
231+
echo "Removing liquidity"
232+
233+
aztec-wallet \
234+
--prover native \
235+
send remove_liquidity \
236+
--ca "amm_address \
237+
--args $((liquidity_token_balance/8)) $amount_0_min $amount_1_min secrets:burn-nonce \
238+
-aw amm-burn-token-liquidity \
239+
-f accounts:main \
240+
$SPONSORED_FPC_PAYMENT_METHOD

aztec-up/test/bridge_and_claim.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
# Check we're in the test container.
5+
if [ ! -f /aztec_release_test_container ]; then
6+
echo "Not running inside the aztec release test container. Exiting."
7+
exit 1
8+
fi
9+
10+
if [ "$(whoami)" != "ubuntu" ]; then
11+
echo "Not running as ubuntu. Exiting."
12+
exit 1
13+
fi
14+
15+
export SKIP_PULL=1
16+
export NO_NEW_SHELL=1
17+
export INSTALL_URI=file:///home/ubuntu/aztec-packages/aztec-up/bin
18+
19+
if [ -t 0 ]; then
20+
bash_args="-i"
21+
else
22+
export NON_INTERACTIVE=1
23+
fi
24+
25+
bash ${bash_args:-} <(curl -s $INSTALL_URI/aztec-install)
26+
27+
# We can't create a new shell for this test, so just re-source our modified .bashrc to get updated PATH.
28+
PS1=" " source ~/.bash_profile
29+
30+
# Sanity check lsp.
31+
echo "Checking LSP..."
32+
echo -ne 'Content-Length: 100\r\n\r\n{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"rootUri": null, "capabilities": {}}}' \
33+
| aztec-nargo lsp \
34+
| grep -q '"jsonrpc":"2.0"'
35+
echo "LSP check passed."
36+
37+
export LOG_LEVEL=debug
38+
39+
# Start sandbox and wait for port to open.
40+
aztec start --sandbox &
41+
sandbox_pid=$!
42+
trap 'echo "Sending kill to pid $sandbox_pid"; kill $sandbox_pid &>/dev/null; wait $sandbox_pid' EXIT
43+
while ! curl -fs localhost:8080/status &>/dev/null; do sleep 1; done
44+
45+
# Execute wallet commands as per: https://docs.aztec.network/guides/getting_started
46+
aztec-wallet import-test-accounts
47+
48+
aztec-wallet \
49+
create-account \
50+
-a main \
51+
--register-only
52+
53+
aztec-wallet \
54+
bridge-fee-juice 1000000000000000000 accounts:main \
55+
--mint \
56+
--no-wait
57+
58+
# We need to send these transactions to advance the chain to claim our bridged funds
59+
for i in $(seq 1 3); do
60+
aztec-wallet \
61+
--prover none \
62+
deploy Token \
63+
--args accounts:test0 TestToken TST 18 \
64+
-f accounts:test0
65+
done
66+
67+
aztec-wallet \
68+
--prover native \
69+
deploy-account \
70+
--payment method=fee_juice,claim \
71+
-f accounts:main
72+
73+
aztec-wallet \
74+
--prover native \
75+
deploy Token \
76+
--args accounts:main TestToken TST 18 \
77+
-f accounts:main

0 commit comments

Comments
 (0)