|
| 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 | +canonical_sponsored_fpc_address=$(aztec \ |
| 46 | + get-canonical-sponsored-fpc-address \ |
| 47 | + | awk '{print $NF}') |
| 48 | + |
| 49 | +SPONSORED_FPC_PAYMENT_METHOD="--payment method=fpc-sponsored,fpc=${canonical_sponsored_fpc_address}" |
| 50 | + |
| 51 | +# Execute wallet commands as per: https://docs.aztec.network/guides/getting_started |
| 52 | +# Note that we are only proving the AMM specific transactions due to the test being lengthy if any other |
| 53 | +# transactions are proven. |
| 54 | + |
| 55 | +echo "Creating account" |
| 56 | + |
| 57 | +aztec-wallet \ |
| 58 | + create-account \ |
| 59 | + -a main \ |
| 60 | + --register-only |
| 61 | + |
| 62 | +aztec-wallet \ |
| 63 | + register-contract $canonical_sponsored_fpc_address SponsoredFPC \ |
| 64 | + -f accounts:main \ |
| 65 | + --salt 0 |
| 66 | + |
| 67 | +aztec-wallet \ |
| 68 | + --prover none \ |
| 69 | + deploy-account \ |
| 70 | + -f accounts:main \ |
| 71 | + $SPONSORED_FPC_PAYMENT_METHOD |
| 72 | + |
| 73 | +echo "Deploying AMM setup" |
| 74 | +aztec-wallet \ |
| 75 | + --prover none \ |
| 76 | + deploy Token \ |
| 77 | + --args accounts:main Token0 TKN0 18 \ |
| 78 | + -f accounts:main \ |
| 79 | + -a token_0 \ |
| 80 | + $SPONSORED_FPC_PAYMENT_METHOD |
| 81 | + |
| 82 | +aztec-wallet \ |
| 83 | + --prover none \ |
| 84 | + deploy Token \ |
| 85 | + --args accounts:main Token1 TKN1 18 \ |
| 86 | + -f accounts:main \ |
| 87 | + -a token_1 \ |
| 88 | + $SPONSORED_FPC_PAYMENT_METHOD |
| 89 | + |
| 90 | +aztec-wallet \ |
| 91 | + --prover none \ |
| 92 | + deploy Token \ |
| 93 | + --args accounts:main lToken lTKN 18 \ |
| 94 | + -f accounts:main \ |
| 95 | + -a token_liquidity \ |
| 96 | + $SPONSORED_FPC_PAYMENT_METHOD |
| 97 | + |
| 98 | +aztec-wallet \ |
| 99 | + --prover none \ |
| 100 | + deploy AMM \ |
| 101 | + --args contracts:token_0 contracts:token_1 contracts:token_liquidity \ |
| 102 | + -f accounts:main \ |
| 103 | + -a amm \ |
| 104 | + $SPONSORED_FPC_PAYMENT_METHOD |
| 105 | + |
| 106 | +aztec-wallet \ |
| 107 | + --prover none \ |
| 108 | + send set_minter \ |
| 109 | + -ca contracts:token_liquidity \ |
| 110 | + --args contracts:amm true \ |
| 111 | + $SPONSORED_FPC_PAYMENT_METHOD \ |
| 112 | + -f accounts:main |
| 113 | + |
| 114 | +### mint_to_private |
| 115 | + |
| 116 | +AMOUNT=420000000000 |
| 117 | + |
| 118 | +echo "Minting token_0 and token_1 to private" |
| 119 | + |
| 120 | +aztec-wallet \ |
| 121 | + --prover none \ |
| 122 | + send mint_to_private \ |
| 123 | + -ca contracts:token_0 \ |
| 124 | + --args accounts:main accounts:main $AMOUNT \ |
| 125 | + $SPONSORED_FPC_PAYMENT_METHOD \ |
| 126 | + -f accounts:main |
| 127 | + |
| 128 | +aztec-wallet \ |
| 129 | + --prover none \ |
| 130 | + send mint_to_private \ |
| 131 | + -ca contracts:token_1 \ |
| 132 | + --args accounts:main accounts:main $AMOUNT \ |
| 133 | + $SPONSORED_FPC_PAYMENT_METHOD \ |
| 134 | + -f accounts:main |
| 135 | + |
| 136 | +### add_liquidity |
| 137 | + |
| 138 | +amount_0_max=$((AMOUNT/4)) |
| 139 | +amount_1_max=$((AMOUNT/4)) |
| 140 | +amount_0_min=1 |
| 141 | +amount_1_min=1 |
| 142 | + |
| 143 | +aztec-wallet \ |
| 144 | + create-secret \ |
| 145 | + -a add-liquidity-nonce |
| 146 | + |
| 147 | +aztec-wallet \ |
| 148 | + create-authwit transfer_to_public contracts:amm \ |
| 149 | + -ca contracts:token_0 \ |
| 150 | + --args accounts:main contracts:amm $amount_0_max secrets:add-liquidity-nonce \ |
| 151 | + -f accounts:main \ |
| 152 | + -a add_liquidity_token_0 |
| 153 | + |
| 154 | +aztec-wallet \ |
| 155 | + create-authwit transfer_to_public contracts:amm \ |
| 156 | + -ca contracts:token_1 \ |
| 157 | + --args accounts:main contracts:amm $amount_1_max secrets:add-liquidity-nonce \ |
| 158 | + -f accounts:main \ |
| 159 | + -a add_liquidity_token_1 |
| 160 | + |
| 161 | +echo "Adding liquidity" |
| 162 | + |
| 163 | +aztec-wallet \ |
| 164 | + --prover native \ |
| 165 | + send add_liquidity \ |
| 166 | + -ca contracts:amm \ |
| 167 | + --args $amount_0_max $amount_1_max $amount_0_min $amount_1_min secrets:add-liquidity-nonce \ |
| 168 | + -aw authwits:add_liquidity_token_0,authwits:add_liquidity_token_1 \ |
| 169 | + -f accounts:main \ |
| 170 | + $SPONSORED_FPC_PAYMENT_METHOD |
| 171 | + |
| 172 | +### swap |
| 173 | + |
| 174 | +amount_in=$((AMOUNT/88)) |
| 175 | + |
| 176 | +aztec-wallet \ |
| 177 | + create-secret \ |
| 178 | + -a swap-nonce |
| 179 | + |
| 180 | +aztec-wallet \ |
| 181 | + create-authwit transfer_to_public contracts:amm \ |
| 182 | + -ca contracts:token_0 \ |
| 183 | + --args accounts:main contracts:amm $amount_in secrets:swap-nonce \ |
| 184 | + -f accounts:main \ |
| 185 | + -a swap_token_0 |
| 186 | + |
| 187 | +echo "Swapping" |
| 188 | + |
| 189 | +aztec-wallet \ |
| 190 | + --prover native \ |
| 191 | + send swap_exact_tokens_for_tokens \ |
| 192 | + -ca contracts:amm \ |
| 193 | + --args contracts:token_0 contracts:token_1 $amount_in 0 secrets:swap-nonce \ |
| 194 | + -aw authwits:swap_token_0 \ |
| 195 | + -f accounts:main \ |
| 196 | + $SPONSORED_FPC_PAYMENT_METHOD |
| 197 | + |
| 198 | +### remove_liquidity |
| 199 | + |
| 200 | +liquidity_token_balance=$(aztec-wallet \ |
| 201 | + simulate balance_of_private \ |
| 202 | + -ca contracts:token_liquidity \ |
| 203 | + --args accounts:main \ |
| 204 | + -f accounts:main \ |
| 205 | + | grep "Simulation result:" \ |
| 206 | + | awk '{print $3}' \ |
| 207 | + | sed 's/n$//') |
| 208 | + |
| 209 | +echo "Liquidity token balance: $liquidity_token_balance" |
| 210 | + |
| 211 | +aztec-wallet \ |
| 212 | + create-secret \ |
| 213 | + -a burn-nonce |
| 214 | + |
| 215 | +liquidity_to_remove=$((liquidity_token_balance/8)) |
| 216 | + |
| 217 | +aztec-wallet \ |
| 218 | + create-authwit transfer_to_public contracts:amm \ |
| 219 | + -ca contracts:token_liquidity \ |
| 220 | + --args accounts:main contracts:amm $liquidity_to_remove secrets:burn-nonce \ |
| 221 | + -f accounts:main \ |
| 222 | + -a remove_liquidity |
| 223 | + |
| 224 | +amount_0_min=1 |
| 225 | +amount_1_min=1 |
| 226 | + |
| 227 | +echo "Removing liquidity" |
| 228 | + |
| 229 | +aztec-wallet \ |
| 230 | + --prover native \ |
| 231 | + send remove_liquidity \ |
| 232 | + -ca contracts:amm \ |
| 233 | + --args $liquidity_to_remove $amount_0_min $amount_1_min secrets:burn-nonce \ |
| 234 | + -aw authwits:remove_liquidity \ |
| 235 | + -f accounts:main \ |
| 236 | + $SPONSORED_FPC_PAYMENT_METHOD |
0 commit comments