diff --git a/.github/scripts/run_smartnet.sh b/.github/scripts/run_smartnet.sh index d2b1b23a71..72223e9e3f 100755 --- a/.github/scripts/run_smartnet.sh +++ b/.github/scripts/run_smartnet.sh @@ -2,7 +2,8 @@ set -e -export NODE_IMAGE=public.ecr.aws/p6e8q1z1/aleph-node:latest +export NODE_IMAGE=573243519133.dkr.ecr.us-east-1.amazonaws.com/feature-env-aleph-node:fe-benjamin_c643069 + # key derived from "//0" export NODE_ID=5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH export ALICE=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY diff --git a/.github/workflows/contracts-e2e-tests-and-deploy.yaml b/.github/workflows/contracts-e2e-tests-and-deploy.yaml index 721ff0e994..f4a226b521 100644 --- a/.github/workflows/contracts-e2e-tests-and-deploy.yaml +++ b/.github/workflows/contracts-e2e-tests-and-deploy.yaml @@ -26,6 +26,10 @@ jobs: env: RUST_BACKTRACE: full steps: + + - name: Checkout Source code + uses: actions/checkout@v3 + - name: Install binaryen run: | wget https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz @@ -39,9 +43,6 @@ jobs: shell: bash run: wasm-opt --version - - name: Checkout Source code - uses: actions/checkout@v3 - - name: Install Rust Toolchain uses: actions-rs/toolchain@v1 @@ -81,11 +82,11 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }} aws-region: eu-central-1 - - name: Login to Public Amazon ECR - id: login-public-ecr + - name: Login to Private Amazon ECR + id: login-private-ecr uses: docker/login-action@v1 with: - registry: public.ecr.aws + registry: 573243519133.dkr.ecr.us-east-1.amazonaws.com username: ${{ secrets.AWS_MAINNET_ACCESS_KEY_ID }} password: ${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }} env: @@ -249,15 +250,15 @@ jobs: shell: bash run: | aws s3 cp contracts/addresses.json s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/addresses.json - + for i in `find contracts -name "metadata.json" | awk -F/ '{print $2}'`; do \ aws s3 cp contracts/"$i"/target/ink/metadata.json s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/"$i"/metadata.json; \ done - + echo -n "${{ steps.get_branch.outputs.sha_short }}" > commit_sha.txt - + aws s3 cp commit_sha.txt s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/commit_sha.txt - + source contracts/env/${{ env.CONTRACTS_ENVFILE }} && echo -n "$NODE" > env_NODE.txt aws s3 cp env_NODE.txt s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/env_NODE.txt diff --git a/contracts/scripts/deploy.sh b/contracts/scripts/deploy.sh index 2088495fb6..ecdd343570 100755 --- a/contracts/scripts/deploy.sh +++ b/contracts/scripts/deploy.sh @@ -104,7 +104,6 @@ function deploy_button_game { local contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --args "$ticket_token" "$game_token" "$marketplace" "$LIFETIME" "$game_type" --suri "$AUTHORITY_SEED" --salt "$salt" --skip-confirm) local contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 14-) - echo "$game_type contract instance address: $contract_address" # --- GRANT PRIVILEGES ON THE CONTRACT @@ -181,6 +180,15 @@ function deploy_simple_dex { eval "$__resultvar='$contract_address'" } +function whitelist_swap_pair() { + local from_address=$1 + local to_address=$2 + + cd "$CONTRACTS_PATH"/simple_dex + + cargo contract call --url "$NODE" --contract "$SIMPLE_DEX" --message add_swap_pair --args "$from_address" "$to_address" --suri "$AUTHORITY_SEED" --skip-confirm +} + function deploy_wrapped_azero { local __resultvar=$1 @@ -297,15 +305,28 @@ deploy_game_token THE_PRESSIAH_COMETH_TOKEN Lono LON $salt deploy_marketplace THE_PRESSIAH_COMETH_MARKETPLACE "$MARKETPLACE_CODE_HASH" the_pressiah_cometh "$salt" "$THE_PRESSIAH_COMETH_TICKET" "$THE_PRESSIAH_COMETH_TOKEN" deploy_button_game THE_PRESSIAH_COMETH ThePressiahCometh "$THE_PRESSIAH_COMETH_TICKET" "$THE_PRESSIAH_COMETH_TOKEN" "$THE_PRESSIAH_COMETH_MARKETPLACE" "$salt" +# --- DEPLOY WRAPPED AZERO CONTRACT + +echo "Wrapped Azero" +deploy_wrapped_azero WRAPPED_AZERO + # --- DEPLOY DEX CONTRACT echo "Simple Dex" deploy_simple_dex SIMPLE_DEX -# --- DEPLOY WRAPPED AZERO CONTRACT +echo "Whitelisting swap token pairs" +whitelist_swap_pair $EARLY_BIRD_SPECIAL_TOKEN $BACK_TO_THE_FUTURE_TOKEN +whitelist_swap_pair $EARLY_BIRD_SPECIAL_TOKEN $THE_PRESSIAH_COMETH_TOKEN +whitelist_swap_pair $EARLY_BIRD_SPECIAL_TOKEN $WRAPPED_AZERO -echo "Wrapped Azero" -deploy_wrapped_azero WRAPPED_AZERO +whitelist_swap_pair $BACK_TO_THE_FUTURE_TOKEN $EARLY_BIRD_SPECIAL_TOKEN +whitelist_swap_pair $BACK_TO_THE_FUTURE_TOKEN $THE_PRESSIAH_COMETH_TOKEN +whitelist_swap_pair $BACK_TO_THE_FUTURE_TOKEN $WRAPPED_AZERO + +whitelist_swap_pair $THE_PRESSIAH_COMETH_TOKEN $EARLY_BIRD_SPECIAL_TOKEN +whitelist_swap_pair $THE_PRESSIAH_COMETH_TOKEN $BACK_TO_THE_FUTURE_TOKEN +whitelist_swap_pair $THE_PRESSIAH_COMETH_TOKEN $WRAPPED_AZERO # spit adresses to a JSON file cd "$CONTRACTS_PATH" diff --git a/contracts/simple_dex/lib.rs b/contracts/simple_dex/lib.rs index d73051912b..933c6a8208 100644 --- a/contracts/simple_dex/lib.rs +++ b/contracts/simple_dex/lib.rs @@ -322,6 +322,12 @@ mod simple_dex { Ok(()) } + /// Returns true if a pair of tokens is whitelisted for swapping between + #[ink(message)] + pub fn can_swap_pair(&self, from: AccountId, to: AccountId) -> bool { + self.swap_pairs.contains(&SwapPair::new(from, to)) + } + /// Blacklists a token pair from swapping /// /// Token pair is understood as a swap between tokens in one direction diff --git a/docker/smartnet-compose.yml b/docker/smartnet-compose.yml index 4733ebb9c2..bee3b91850 100644 --- a/docker/smartnet-compose.yml +++ b/docker/smartnet-compose.yml @@ -2,7 +2,7 @@ version: '3' services: smartnode: - image: public.ecr.aws/p6e8q1z1/aleph-node:latest + image: $NODE_IMAGE container_name: smartnode environment: - ALLOW_PRIVATE_IPV4=true diff --git a/e2e-tests/src/test/button_game/contracts.rs b/e2e-tests/src/test/button_game/contracts.rs index 65868dc2b9..7d5b2c4949 100644 --- a/e2e-tests/src/test/button_game/contracts.rs +++ b/e2e-tests/src/test/button_game/contracts.rs @@ -55,6 +55,19 @@ impl SimpleDexInstance { .contract_exec(conn, "add_swap_pair", &[&from.to_string(), &to.to_string()]) } + pub fn remove_swap_pair( + &self, + conn: &SignedConnection, + from: AccountId, + to: AccountId, + ) -> Result<()> { + self.contract.contract_exec( + conn, + "remove_swap_pair", + &[&from.to_string(), &to.to_string()], + ) + } + pub fn deposit( &self, conn: &SignedConnection, diff --git a/e2e-tests/src/test/button_game/mod.rs b/e2e-tests/src/test/button_game/mod.rs index ac116ef382..edd2e88532 100644 --- a/e2e-tests/src/test/button_game/mod.rs +++ b/e2e-tests/src/test/button_game/mod.rs @@ -115,6 +115,7 @@ pub fn simple_dex(config: &Config) -> Result<()> { let more_than_liquidity = mega(1_000_000); dex.swap(account_conn, token1, 100, token2, more_than_liquidity)?; + refute_recv_id(&mut events, "Swapped"); let initial_amount = mega(100); @@ -159,6 +160,12 @@ pub fn simple_dex(config: &Config) -> Result<()> { dex.swap(account_conn, token1, balance_after, token3, mega(90))?; assert_recv_id(&mut events, "Swapped"); + + // can't swap a pair not on the whitelist + + dex.remove_swap_pair(authority_conn, token3.into(), token1.into())?; + assert_recv_id(&mut events, "SwapPairRemoved"); + let balance_token3 = token3.balance_of(&conn, &account.public().into())?; token3.approve(account_conn, &dex.into(), balance_token3)?; dex.swap(account_conn, token3, balance_token3, token1, mega(90))?;