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

Feat introduced icp nonces for context contract #1031

Open
wants to merge 28 commits into
base: feat--add-near-calls-nonce
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
945be8f
fix: remove timestamp from contracts
frdomovic Dec 20, 2024
bbd07ee
fix: tests 2
frdomovic Dec 20, 2024
964fa46
fix: removed prints in mock contract, optimized proxy contract deploy…
alenmestrov Dec 20, 2024
9bbc038
feat: introduced nonces in icp context contract
alenmestrov Dec 20, 2024
545b72d
fix: lint
alenmestrov Dec 20, 2024
39e5c26
fix: check the transfer result before doing cross contract call
alenmestrov Dec 20, 2024
2fa86ac
fix: resolved PR comments
alenmestrov Dec 20, 2024
d3d22a7
fix:lint
alenmestrov Dec 20, 2024
fcd5b3a
fix: reverted back grouping of members and nonces
alenmestrov Dec 20, 2024
14db1bb
fix: lint
alenmestrov Dec 20, 2024
bc99546
fix: resolved PR comments
alenmestrov Dec 20, 2024
244aab0
simplify nonce validation
miraclx Dec 20, 2024
0182e26
prevent spurious proxy deployment for existing context
miraclx Dec 20, 2024
647192c
pulled latest changes
alenmestrov Dec 23, 2024
f440214
fix: removed mock_ledger from Cargo
alenmestrov Dec 23, 2024
dcac961
fix: lint
alenmestrov Dec 23, 2024
d73e5e5
merged feat--add-near-calls-nonce
alenmestrov Dec 23, 2024
af88a83
fix: removed mock_ledger build process
alenmestrov Dec 23, 2024
ba80769
feat: added automated script for devnet deployment
alenmestrov Dec 23, 2024
a5f839d
fix: resolved issue with NEAR nonce
alenmestrov Dec 23, 2024
42a9528
feat: added container_ids.json file to gitignore
alenmestrov Dec 23, 2024
df5b56f
fix: check if canister_ids.json file exists before trying to delete it
alenmestrov Dec 23, 2024
84ff731
fix: fixed getting proxy contract wasm content
alenmestrov Dec 23, 2024
f99d909
fix: fixed fetching nonce encoding
alenmestrov Dec 24, 2024
95d0d1d
fix: updated script for devnet deployment, adjusted initial context c…
alenmestrov Dec 26, 2024
5fb103d
feat: implemented endpoint for fetching proxy contract ID
alenmestrov Dec 26, 2024
5ee39c9
fix: lint
alenmestrov Dec 26, 2024
8912db4
fix: cleaned deployment script and created test recipient account
alenmestrov Dec 26, 2024
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
679 changes: 485 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ members = [

"./contracts/icp/context-config",
"./contracts/icp/context-proxy",
"./contracts/icp/context-proxy/mock/ledger",
"./contracts/icp/context-proxy/mock/external",

"./e2e-tests",
Expand Down
1 change: 1 addition & 0 deletions contracts/icp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ dist/
pocket-ic

!**/res/*.did
**/canister_ids.json
3 changes: 2 additions & 1 deletion contracts/icp/context-config/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

# DFX CANISTER ENVIRONMENT VARIABLES
DFX_VERSION='0.24.2'
DFX_VERSION='0.24.3'
DFX_NETWORK='local'
CANISTER_ID_LEDGER='bd3sg-teaaa-aaaaa-qaaba-cai'
CANISTER_ID_CONTEXT_CONTRACT='bkyz2-fmaaa-aaaaa-qaaaq-cai'
CANISTER_ID='bkyz2-fmaaa-aaaaa-qaaaq-cai'
CANISTER_CANDID_PATH='/Users/alen/www/calimero/core/contracts/icp/context-config/./res/calimero_context_config_icp.did'
Expand Down
161 changes: 154 additions & 7 deletions contracts/icp/context-config/deploy_devnet.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,160 @@
#!/bin/bash
set -e

# Build the contract
./build.sh
# Function to generate a new identity and return its principal
generate_identity() {
local name=$1
dfx identity new "$name" --storage-mode=plaintext || true
dfx identity use "$name"
dfx identity get-principal
}

# Function to get account ID from principal
get_account_id() {
local principal=$1
dfx ledger account-id --of-principal "$principal"
}

echo "Checking dependencies..."
command -v dfx >/dev/null 2>&1 || { echo "dfx is required but not installed. Aborting." >&2; exit 1; }
command -v cargo >/dev/null 2>&1 || { echo "cargo is required but not installed. Aborting." >&2; exit 1; }

dfxvm default 0.24.3

# Stop the replica
# Stop dfx and clean up all state
dfx stop
rm -rf .dfx
rm -rf ~/.config/dfx/replica-configuration/
rm -rf ~/.config/dfx/identity/minting
rm -rf ~/.config/dfx/identity/initial
rm -rf ~/.config/dfx/identity/archive
rm -rf ~/.cache/dfinity/
rm -rf ~/.config/dfx/
dfxvm default 0.24.3
# Remove canister_ids.json if it exists
if [ -f "canister_ids.json" ]; then
rm canister_ids.json
fi

# Generate minting account
dfx identity new minting --storage-mode=plaintext || true
dfx identity use minting
MINTING_PRINCIPAL=$(dfx identity get-principal)
MINTING_ACCOUNT=$(get_account_id "$MINTING_PRINCIPAL")

# Generate initial account
dfx identity new initial --storage-mode=plaintext || true
dfx identity use initial
INITIAL_PRINCIPAL=$(dfx identity get-principal)
INITIAL_ACCOUNT=$(get_account_id "$INITIAL_PRINCIPAL")

# Generate archive controller account
dfx identity new archive --storage-mode=plaintext || true
dfx identity use archive
ARCHIVE_PRINCIPAL=$(dfx identity get-principal)

# Generate test recipient account
dfx identity new recipient --storage-mode=plaintext || true
dfx identity use recipient
RECIPIENT_PRINCIPAL=$(dfx identity get-principal)

# Switch back to default identity
dfx identity use default

# Start dfx with clean state
dfx start --clean --background

dfx identity use default

# Create initial identity if needed
dfx identity new --storage-mode=plaintext minting || true
# dfx identity use minting

echo "Creating and deploying canister..."
dfx canister create context_contract
dfx canister create ledger

# Get the context ID
CONTEXT_ID=$(dfx canister id context_contract)
# Get the wallet ID and seed it
WALLET_ID=$(dfx identity get-wallet)

# abricate cycles for the wallet
dfx ledger fabricate-cycles --canister $WALLET_ID --amount 200000

# Transfer cycles from wallet to context contract
dfx canister deposit-cycles 1000000000000000000 $CONTEXT_ID

echo "Done! Cycles transferred to context contract: $CONTEXT_ID"

# Get the IDs
CONTEXT_ID=$(dfx canister id context_contract)
LEDGER_ID=$(dfx canister id ledger)

# Build contracts
echo "Building contracts..."
cd "$(dirname $0)"
./build.sh
cd ../context-proxy
./build.sh
cd ../context-config

# Prepare ledger initialization argument
LEDGER_INIT_ARG="(variant { Init = record {
minting_account = \"${MINTING_ACCOUNT}\";
initial_values = vec {
record { \"${INITIAL_ACCOUNT}\"; record { e8s = 100_000_000_000 } }
};
send_whitelist = vec {};
transfer_fee = opt record { e8s = 10_000 };
token_symbol = opt \"LICP\";
token_name = opt \"Local Internet Computer Protocol Token\";
archive_options = opt record {
trigger_threshold = 2000;
num_blocks_to_archive = 1000;
controller_id = principal \"${ARCHIVE_PRINCIPAL}\"
};
} })"

# Build and install canisters
dfx build
dfx canister install context_contract --mode=install
dfx canister install ledger --mode=install --argument "$LEDGER_INIT_ARG"

# Get the directory where the script is located
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

# Build path relative to the script location
WASM_FILE="${SCRIPT_DIR}/../context-proxy/res/calimero_context_proxy_icp.wasm"

# Verify file exists
if [ ! -f "$WASM_FILE" ]; then
echo "Error: WASM file not found at: $WASM_FILE"
exit 1
fi

# Then modify the script to use a consistent reading method
WASM_CONTENTS=$(xxd -p "$WASM_FILE" | tr -d '\n' | sed 's/\(..\)/\\\1/g')

TEMP_CMD=$(mktemp)
echo "(
blob \"${WASM_CONTENTS}\",
principal \"${LEDGER_ID}\"
)" > "$TEMP_CMD"

# Execute the command using the temporary file
dfx canister call context_contract set_proxy_code --argument-file "$TEMP_CMD"

# Start the replica
dfx start --background
# Clean up
rm "$TEMP_CMD"

# Deploy the contract
dfx deploy
# Print all relevant information at the end
echo -e "\n=== Deployment Summary ==="
echo "Context Contract ID: ${CONTEXT_ID}"
echo "Ledger Contract ID: ${LEDGER_ID}"
echo -e "\nAccount Information:"
echo "Minting Account: ${MINTING_ACCOUNT}"
echo "Initial Account: ${INITIAL_ACCOUNT}"
echo "Archive Principal: ${ARCHIVE_PRINCIPAL}"
echo "Recipient Principal: ${RECIPIENT_PRINCIPAL}"
echo -e "\nDeployment completed successfully!"
16 changes: 15 additions & 1 deletion contracts/icp/context-config/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"package": "calimero-context-config-icp",
"candid": "./res/calimero_context_config_icp.did",
"type": "rust"
},
"ledger": {
"type": "custom",
"wasm": "https://download.dfinity.systems/ic/aba60ffbc46acfc8990bf4d5685c1360bd7026b9/canisters/ledger-canister.wasm.gz",
"candid": "https://raw.githubusercontent.com/dfinity/ic/aba60ffbc46acfc8990bf4d5685c1360bd7026b9/rs/ledger_suite/icp/ledger.did"
}
},
"defaults": {
Expand All @@ -12,6 +17,15 @@
"packtool": ""
}
},
"output_env_file": ".env",
"networks": {
"local": {
"bind": "127.0.0.1:4943",
"type": "persistent"
}
},
"routing_table": {
"start_canister_id": "aaaaa-aa",
"end_canister_id": "zzzzz-zz"
},
"version": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Result = variant { Ok; Err : text };
service : () -> {
application : (blob) -> (ICApplication) query;
application_revision : (blob) -> (nat64) query;
fetch_nonce : (blob, blob) -> (opt nat64) query;
has_member : (blob, blob) -> (bool) query;
members : (blob, nat64, nat64) -> (vec blob) query;
members_revision : (blob) -> (nat64) query;
Expand Down
1 change: 1 addition & 0 deletions contracts/icp/context-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Context {
pub application: Guard<ICApplication>,
pub members: Guard<BTreeSet<ICRepr<ContextIdentity>>>,
pub proxy: Guard<Principal>,
pub member_nonces: BTreeMap<ICRepr<ContextIdentity>, u64>,
alenmestrov marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(CandidType, Deserialize, Debug)]
Expand Down
Loading
Loading