|
| 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=silent |
| 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 | +FPC_ALIAS=sponsoredFPC |
| 46 | + |
| 47 | +# Execute wallet commands as per: https://docs.aztec.network/guides/getting_started |
| 48 | +aztec-wallet import-test-accounts |
| 49 | + |
| 50 | +# We deploy a SponsoredFPC instance, note that we could reuse the "canonical" instance already deployed, but it is easier to re-deploy it to access its address. |
| 51 | +# Also, we are able to test the bridging and claim flow here. |
| 52 | +aztec-wallet --prover none deploy sponsored_fpc_contract@SponsoredFPC -f test0 -a $FPC_ALIAS --no-init |
| 53 | +CLAIM=$(aztec-wallet bridge-fee-juice 1000000000000000000 contracts:$FPC_ALIAS --mint --no-wait --json) |
| 54 | + |
| 55 | +retrieve () { |
| 56 | + echo "$CLAIM" | grep "\"$1\"" | awk -F ': ' '{print $2}' | tr -d '",' |
| 57 | +} |
| 58 | + |
| 59 | +claimAmount=$(retrieve claimAmount) |
| 60 | +claimSecret=$(retrieve claimSecret) |
| 61 | +messageLeafIndex=$(retrieve messageLeafIndex) |
| 62 | + |
| 63 | +# We need to send these transactions to advance the chain to claim our bridged funds |
| 64 | +for i in $(seq 1 2); do |
| 65 | + aztec-wallet --prover none deploy TokenContractArtifact \ |
| 66 | + --from accounts:test0 \ |
| 67 | + --args accounts:test0 TestToken TST 18 -a testtoken |
| 68 | +done |
| 69 | + |
| 70 | +# Claim the fee juice by calling the fee juice contract directly (address = 5). |
| 71 | +feeJuice=0x0000000000000000000000000000000000000000000000000000000000000005 |
| 72 | +# Using a pre-funded test account because SponsoredFPC is not an account contract and can't be used to send a tx. |
| 73 | +aztec-wallet --prover native send claim -ca $feeJuice -c fee_juice_contract@FeeJuice --args contracts:$FPC_ALIAS $claimAmount $claimSecret $messageLeafIndex -f test0 |
| 74 | + |
| 75 | +SPONSORED_FPC_PAYMENT_METHOD="--payment method=fpc-sponsored,fpc=contracts:sponsoredFPC" |
| 76 | + |
| 77 | +aztec-wallet --prover native create-account -a main $SPONSORED_FPC_PAYMENT_METHOD |
| 78 | + |
| 79 | +aztec-wallet --prover native create-account -a account2 $SPONSORED_FPC_PAYMENT_METHOD |
| 80 | + |
| 81 | +# We only prove one of the three token deploys, because we do not want to duplicate proving effort for similar actions |
| 82 | +# We use this philosophy to dictate what we prove here and below. |
| 83 | +token_0_address=$(aztec-wallet --prover native deploy Token --args accounts:test0 Test TST 18 -f test0 --node-url http://104.198.9.16:8080 -a token_0 | grep "Contract deployed at" | awk '{print $4}') |
| 84 | +token_1_address=$(aztec-wallet --prover none deploy Token --args accounts:test0 Test TST 18 -f test0 --node-url http://104.198.9.16:8080 -a token_1 | grep "Contract deployed at" | awk '{print $4}') |
| 85 | +token_liquidity_address=$(aztec-wallet --prover none deploy Token --args accounts:test0 Test TST 18 -f test0 --node-url http://104.198.9.16:8080 -a token_liquidity | grep "Contract deployed at" | awk '{print $4}') |
| 86 | +amm_address=$(aztec-wallet --prover native deploy AMM --args "$token_0_address" "$token_1_address" "$token_liquidity_address" -f test0 --node-url http://104.198.9.16:8080 -a amm | grep "Contract deployed at" | awk '{print $4}') |
| 87 | + |
| 88 | +### mint_to_private |
| 89 | + |
| 90 | +# We mint both tokens to our user |
| 91 | +aztec-wallet --prover native send mint_to_private -ca "$token_0_address" --args test0 "$current_user_address" "$AMOUNT" -f test0 --node-url http://104.198.9.16:8080 $SPONSORED_FPC_PAYMENT_METHOD |
| 92 | +aztec-wallet --prover none send mint_to_private -ca "$token_1_address" --args test0 "$current_user_address" "$AMOUNT" -f test0 --node-url http://104.198.9.16:8080 $SPONSORED_FPC_PAYMENT_METHOD |
| 93 | + |
| 94 | +### add_liquidity |
| 95 | + |
| 96 | +# We craft our authwits for sending add_liquidity |
| 97 | +aztec-wallet create-secret -a add-liquidity-nonce |
| 98 | +aztec-wallet create-authwit transfer_to_public "$amm_address" -ca "$token_0_address" --args "$current_user_address" "$amm_address" "$amount_0_max" secrets:add-liquidity-nonce -f "$current_user_address" -a amm-lp-token-0 |
| 99 | +aztec-wallet create-authwit transfer_to_public "$amm_address" -ca "$token_1_address" --args "$current_user_address" "$amm_address" "$amount_1_max" secrets:add-liquidity-nonce -f "$current_user_address" -a amm-lp-token-1 |
| 100 | + |
| 101 | +amount_0_max=$((private_balance_token_0/4)) |
| 102 | +amount_1_max=$((private_balance_token_1/4)) |
| 103 | +amount_0_min=1 |
| 104 | +amount_1_min=1 |
| 105 | + |
| 106 | +aztec-wallet --prover native send add_liquidity -ca "$amm_address" --args "$amount_0_max" "$amount_1_max" "$amount_0_min" "$amount_1_min" secrets:add-liquidity-nonce -aw amm-lp-token-0 -aw amm-lp-token-1 -f "$liquidity_provider" $SPONSORED_FPC_PAYMENT_METHOD |
| 107 | + |
| 108 | +### swap |
| 109 | + |
| 110 | +amount_in=$((private_balance_token_0/88)) |
| 111 | + |
| 112 | +aztec-wallet create-secret -a swap-nonce |
| 113 | +aztec-wallet create-authwit transfer_to_public "$amm_address" -ca "$token_0_address" --args "$current_user_address" "$amm_address" "$amount_in" secrets:swap-nonce -f "$current_user_address" -a amm-swapper-token-0 |
| 114 | + |
| 115 | +amount_out_min=$(aztec-wallet simulate get_amount_out_for_exact_in -ca "$amm_address" --args "$balance_of_public_token_0_amm" "$balance_of_public_token_1_amm" "$amount_in" -f "$swapper") |
| 116 | +echo "Amount out min for swap: $amount_out_min" |
| 117 | + |
| 118 | +aztec-wallet --prover native send swap_exact_tokens_for_tokens --ca "$amm_address" --args "$token_0_address" "$token_1_address" "$amount_in" 0 secrets:swap-nonce -aw amm-swapper-token-0 -f "$current_user_address" $SPONSORED_FPC_PAYMENT_METHOD |
| 119 | + |
| 120 | +### remove_liquidity |
| 121 | + |
| 122 | +liquidity_token_balance=$(aztec-wallet simulate balance_of_private -ca "$token_liquidity_address" --args "$other_liquidity_provider" -f "$other_liquidity_provider" --node-url http://104.198.9.16:8080 | grep "Simulation result:" | awk '{print $3}') |
| 123 | +echo "Liquidity token balance: $liquidity_token_balance" |
| 124 | + |
| 125 | +aztec-wallet create-secret -a burn-nonce |
| 126 | +aztec-wallet create-authwit transfer_to_public "$amm_address" -ca "$token_liquidity_address" --args "$current_user_address" "$amm_address" "$liquidity_token_balance" secrets:burn-nonce -f "$current_user_address" -a amm-burn-token-liquidity |
| 127 | + |
| 128 | +amount_0_min=1 |
| 129 | +amount_1_min=1 |
| 130 | + |
| 131 | +aztec-wallet --prover native send remove_liquidity --ca "$amm_address" --args $((liquidity_token_balance/8)) "$amount_0_min" "$amount_1_min" secrets:burn-nonce -aw amm-burn-token-liquidity -f "$current_user_address" $SPONSORED_FPC_PAYMENT_METHOD |
0 commit comments