Skip to content

Deploy wazero #733

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

Merged
merged 6 commits into from
Nov 16, 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
49 changes: 23 additions & 26 deletions .github/workflows/contracts-e2e-tests-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ concurrency:
cancel-in-progress: false

env:
CHECKOUT_BRANCH: benjamin
CACHE_KEY: fe-benjamin-button
CONTRACTS_ENVFILE: fe-benjamin
CARGOCONTRACT_REV: 2b1758756de59bd81e7bed5f8429d364f281cb9a
Expand Down Expand Up @@ -70,11 +69,12 @@ jobs:
contracts/ticket_token/target/
contracts/wrapped_azero/target/

# TODO : this should NOT be built every time
- name: Install cargo-contract
run: |
cargo install cargo-dylint dylint-link --force
# revision merging Hans's PR changes [fix for node URL parsing ]
cargo install --git https://github.com/paritytech/cargo-contract.git --rev 2b1758756de59bd81e7bed5f8429d364f281cb9a --force
cargo install --git https://github.com/paritytech/cargo-contract.git --rev ${{ env.CARGOCONTRACT_REV }} --force

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down Expand Up @@ -142,8 +142,6 @@ jobs:
steps:
- name: Checkout repo
uses: actions/[email protected]
with:
ref: ${{ env.CHECKOUT_BRANCH }}

- name: Check if environment is reachable
shell: bash
Expand Down Expand Up @@ -188,13 +186,22 @@ jobs:
with:
target-key: ${{ env.CACHE_KEY }}
cargo-key: ${{ env.CACHE_KEY }}
cache-version: v1
cache-version: v2
cargo-targets: |
contracts/access_control/target/
contracts/button/target/
contracts/game_token/target/
contracts/marketplace/target/
contracts/simple_dex/target/
contracts/ticket_token/target/
contracts/wrapped_azero/target/

- name: Install cargo additional libs
run: |
. "$HOME/.cargo/env"
cargo install dylint-link cargo-dylint

# TODO : this should NOT be built every time
- name: Install cargo-contract with bug fixes around URL parsing
run: |
. "$HOME/.cargo/env"
Expand All @@ -211,24 +218,17 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_DEVNET_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Get contracts' target directories cache from S3 bucket
shell: bash
continue-on-error: true
run: |
aws s3 cp s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/targets.tgz targets.tgz
tar -xzf targets.tgz

- name: Copy metadata.json and addresses.json files from S3 bucket
continue-on-error: true
shell: bash
run: |
aws s3 cp s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/addresses.json contracts/addresses.json
for i in ticket_token marketplace button game_token simple_dex access_control; do \
for i in ticket_token marketplace button game_token simple_dex wrapped_azero access_control; do \
mkdir -p contracts/"$i"/target/ink
aws s3 cp s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/"$i"/metadata.json contracts/"$i"/target/ink/metadata.json; \
done

- name: Run clean.sh script
continue-on-error: true
shell: bash
run: |
. "$HOME/.cargo/env"
Expand All @@ -244,19 +244,22 @@ jobs:
shell: bash
run: |
aws s3 cp contracts/addresses.json s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/addresses.json
for i in ticket_token marketplace button game_token simple_dex access_control; do \
for i in ticket_token marketplace button game_token simple_dex wrapped_azero access_control; 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

- name: Rename metadata and addresses JSON files to artifact upload
shell: bash
run: |
cp contracts/addresses.json addresses.${{ env.CONTRACTS_ENVFILE }}.json
for i in ticket_token marketplace button game_token access_control; do \
for i in ticket_token marketplace button game_token wrapped_azero access_control; do \
cp contracts/"$i"/target/ink/metadata.json metadata_"$i".${{ env.CONTRACTS_ENVFILE }}.json; \
done

Expand All @@ -276,16 +279,8 @@ jobs:
if-no-files-found: error
retention-days: 90

- name: Cache contracts' target directories in S3 bucket
shell: bash
run: |
tar -czf targets.tgz contracts/ticket_token/target \
contracts/marketplace/target \
contracts/button/target \
contracts/game_token/target \
contracts/simple_dex/target \
contracts/access_control/target
aws s3 cp targets.tgz s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/targets.tgz
- name: Cleanup cache
uses: ./.github/actions/post-cache

- name: Trigger Indexer deployment workflow
run: |
Expand All @@ -300,3 +295,5 @@ jobs:
-H "Accept: application/vnd.github+json" \
-H 'Authorization: Bearer ${{ secrets.CI_GH_TOKEN }}' \
-d '{ "ref":"main", "inputs": { "buildImage": "false", "deployImage": "true" }}'

# TODO : Here the workflow should wait for a hook that notifies this workflow when the two prior steps have been finished succesfully
5 changes: 4 additions & 1 deletion contracts/scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function remove_contract_code {
rm -f $tmp_output_file
set -e


fi
}

Expand Down Expand Up @@ -93,6 +92,10 @@ terminate_contract simple_dex simple_dex
remove_contract_code simple_dex_code_hash
echo "succesfully terminated and removed simple_dex"

terminate_contract wrapped_azero wrapped_azero
remove_contract_code wrapped_azero_code_hash
echo "succesfully terminated and removed wrapped_azero"

# remove access control as last
terminate_contract access_control access_control
remove_contract_code access_control_code_hash
Expand Down
41 changes: 38 additions & 3 deletions contracts/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function deploy_ticket_token {
eval $__resultvar="'$contract_address'"
}


function deploy_game_token {

local __resultvar=$1
Expand All @@ -90,7 +89,6 @@ function deploy_game_token {
eval "$__resultvar='$contract_address'"
}


function deploy_button_game {

local __resultvar=$1
Expand Down Expand Up @@ -183,6 +181,28 @@ function deploy_simple_dex {
eval "$__resultvar='$contract_address'"
}

function deploy_wrapped_azero {
local __resultvar=$1

# --- CREATE AN INSTANCE OF THE CONTRACT

cd "$CONTRACTS_PATH"/wrapped_azero

local contract_address
contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --suri "$AUTHORITY_SEED" --skip-confirm)
contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 14-)

echo "wrapped Azero contract instance address: $contract_address"

# --- GRANT PRIVILEGES ON THE CONTRACT

cd "$CONTRACTS_PATH"/access_control

cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" --skip-confirm

eval "$__resultvar='$contract_address'"
}

function link_bytecode() {
local contract=$1
local placeholder=$2
Expand Down Expand Up @@ -217,6 +237,9 @@ cargo contract build --release
cd "$CONTRACTS_PATH"/simple_dex
cargo contract build --release

cd "$CONTRACTS_PATH"/wrapped_azero
cargo contract build --release

# --- DEPLOY ACCESS CONTROL CONTRACT

cd "$CONTRACTS_PATH"/access_control
Expand All @@ -237,6 +260,7 @@ upload_contract GAME_TOKEN_CODE_HASH game_token
upload_contract BUTTON_CODE_HASH button
upload_contract MARKETPLACE_CODE_HASH marketplace
upload_contract SIMPLE_DEX_CODE_HASH simple_dex
upload_contract WRAPPED_AZERO_CODE_HASH wrapped_azero

start=$(date +%s.%N)

Expand Down Expand Up @@ -273,9 +297,16 @@ 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 DEX CONTRACT

echo "Simple Dex"
deploy_simple_dex SIMPLE_DEX

# --- DEPLOY WRAPPED AZERO CONTRACT

echo "Wrapped Azero"
deploy_wrapped_azero WRAPPED_AZERO

# spit adresses to a JSON file
cd "$CONTRACTS_PATH"

Expand All @@ -299,6 +330,8 @@ jq -n --arg early_bird_special "$EARLY_BIRD_SPECIAL" \
--arg access_control_code_hash "$ACCESS_CONTROL_CODE_HASH" \
--arg simple_dex "$SIMPLE_DEX" \
--arg simple_dex_code_hash "$SIMPLE_DEX_CODE_HASH" \
--arg wrapped_azero "$WRAPPED_AZERO" \
--arg wrapped_azero_code_hash "$WRAPPED_AZERO_CODE_HASH" \
'{
early_bird_special: $early_bird_special,
early_bird_special_marketplace: $early_bird_special_marketplace,
Expand All @@ -319,7 +352,9 @@ jq -n --arg early_bird_special "$EARLY_BIRD_SPECIAL" \
game_token_code_hash: $game_token_code_hash,
marketplace_code_hash: $marketplace_code_hash,
access_control_code_hash: $access_control_code_hash,
simple_dex_code_hash: $simple_dex_code_hash
simple_dex_code_hash: $simple_dex_code_hash,
wrapped_azero: $wrapped_azero,
wrapped_azero_code_hash: $wrapped_azero_code_hash
}' > addresses.json

end=`date +%s.%N`
Expand Down
8 changes: 4 additions & 4 deletions contracts/wrapped_azero/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod wrapped_azero {
codegen::{EmitEvent, Env},
reflect::ContractEventBase,
};
use ink_prelude::{format, string::String};
use ink_prelude::format;
use ink_storage::traits::SpreadAllocate;
use num_traits::identities::Zero;
use openbrush::{
Expand Down Expand Up @@ -127,7 +127,7 @@ pub mod wrapped_azero {
///
/// Will revert if called from an account without a proper role
#[ink(constructor)]
pub fn new(name: String, symbol: String) -> Self {
pub fn new() -> Self {
let caller = Self::env().caller();
let code_hash = Self::env()
.own_code_hash()
Expand All @@ -143,8 +143,8 @@ pub mod wrapped_azero {

match role_check {
Ok(_) => ink_lang::codegen::initialize_contract(|instance: &mut WrappedAzero| {
instance.metadata.name = Some(name.into());
instance.metadata.symbol = Some(symbol.into());
instance.metadata.name = Some("wAzero".into());
instance.metadata.symbol = Some("wA0".into());
instance.metadata.decimals = 12; // same as AZERO

instance.access_control = AccountId::from(ACCESS_CONTROL_PUBKEY);
Expand Down