Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dex whitelist #805

Merged
merged 11 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/scripts/run_smartnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which commit was used to compile this docker image?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know, maybe @mikogs does


# key derived from "//0"
export NODE_ID=5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH
export ALICE=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/contracts-e2e-tests-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
29 changes: 25 additions & 4 deletions contracts/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions contracts/simple_dex/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
deuszx marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
2 changes: 1 addition & 1 deletion docker/smartnet-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions e2e-tests/src/test/button_game/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions e2e-tests/src/test/button_game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why had the test below been failing before you added these two lines? i.e. it [the test] asserts that there was no trade made and I'm assuming that it used to pass so why did it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cause before pair was not on a whitelist for swapping


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))?;
Expand Down