diff --git a/cairo/Makefile b/cairo/Makefile new file mode 100644 index 0000000..1a5cb85 --- /dev/null +++ b/cairo/Makefile @@ -0,0 +1,46 @@ +# Makefile for Hyperlane Starknet Cairo + +.PHONY: build clean rebuild help + +# Default target +help: + @echo "Available targets:" + @echo " build [FEE_TOKEN_ADDRESS] - Build project, optionally setting fee token first" + @echo " clean - Clean the project with scarb" + @echo " rebuild [FEE_TOKEN_ADDRESS] - Clean and build, optionally setting fee token" + @echo "" + @echo "Examples:" + @echo " make build # Build with current fee token" + @echo " make build 0x1234567890abcdef... # Set fee token and build" + @echo " make rebuild 0x1234567890abcdef... # Set fee token, clean and build" + +# Build the project (with optional fee token address as first argument) +build: +ifneq ($(word 2,$(MAKECMDGOALS)),) + @echo "Cleaning project before fee token update..." + scarb clean + @echo "Updating fee token to $(word 2,$(MAKECMDGOALS))..." + ./feeToken $(word 2,$(MAKECMDGOALS)) +endif + @echo "Building project..." + scarb build + +# Clean the project +clean: + @echo "Cleaning project..." + scarb clean + +# Clean and build (with optional fee token address) +rebuild: + @echo "Cleaning project..." + scarb clean +ifneq ($(word 2,$(MAKECMDGOALS)),) + @echo "Updating fee token to $(word 2,$(MAKECMDGOALS))..." + ./feeToken $(word 2,$(MAKECMDGOALS)) +endif + @echo "Building project..." + scarb build + +# Prevent make from treating the address argument as a target +%: + @: \ No newline at end of file diff --git a/cairo/crates/contracts/src/fee_token.cairo b/cairo/crates/contracts/src/fee_token.cairo new file mode 100644 index 0000000..d9b83aa --- /dev/null +++ b/cairo/crates/contracts/src/fee_token.cairo @@ -0,0 +1,5 @@ +use starknet::ContractAddress; + +pub fn FEE_TOKEN() -> ContractAddress { + 0x04718f5a0Fc34cC1AF16A1cdee98fFB20C31f5cD61D6Ab07201858f4287c938D.try_into().unwrap() +} \ No newline at end of file diff --git a/cairo/crates/contracts/src/interfaces.cairo b/cairo/crates/contracts/src/interfaces.cairo index 68ec5e7..458de5b 100644 --- a/cairo/crates/contracts/src/interfaces.cairo +++ b/cairo/crates/contracts/src/interfaces.cairo @@ -1,4 +1,5 @@ use alexandria_bytes::Bytes; +use contracts::fee_token::FEE_TOKEN; use contracts::hooks::merkle_tree_hook::merkle_tree_hook::Tree; use contracts::libs::message::Message; use core::array::ArrayTrait; @@ -6,7 +7,7 @@ use starknet::ContractAddress; use starknet::EthAddress; pub fn ETH_ADDRESS() -> ContractAddress { - 0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7.try_into().unwrap() + FEE_TOKEN() } #[derive(Serde, Drop, Debug, PartialEq)] diff --git a/cairo/crates/contracts/src/lib.cairo b/cairo/crates/contracts/src/lib.cairo index 34a56e5..907e53b 100644 --- a/cairo/crates/contracts/src/lib.cairo +++ b/cairo/crates/contracts/src/lib.cairo @@ -1,3 +1,4 @@ +pub mod fee_token; pub mod interfaces; pub mod mailbox; pub mod libs { diff --git a/cairo/feeToken b/cairo/feeToken new file mode 100755 index 0000000..4c1285f --- /dev/null +++ b/cairo/feeToken @@ -0,0 +1,38 @@ +#!/bin/bash + +# Script to update the FEE_TOKEN address dynamically +# Usage: ./feeToken 0x1234567890abcdef... + +if [ $# -eq 0 ]; then + echo "Usage: $0 " + echo "Example: $0 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" + exit 1 +fi + +NEW_ADDRESS="$1" + +# Validate the address format (basic check for 0x prefix and length) +if [[ ! "$NEW_ADDRESS" =~ ^0x[0-9a-fA-F]{63,64}$ ]]; then + echo "Error: Invalid address format. Expected hex string starting with 0x" + exit 1 +fi + +FEE_TOKEN_FILE="crates/contracts/src/fee_token.cairo" + +if [ ! -f "$FEE_TOKEN_FILE" ]; then + echo "Error: Fee token file not found at $FEE_TOKEN_FILE" + exit 1 +fi + +echo "Updating FEE_TOKEN address to: $NEW_ADDRESS" + +# Update the fee token address in the file +sed -i.bak "s/0x[0-9a-fA-F]\\{63,64\\}/$NEW_ADDRESS/g" "$FEE_TOKEN_FILE" + +if [ $? -eq 0 ]; then + echo "Successfully updated FEE_TOKEN address in $FEE_TOKEN_FILE" + rm -f "${FEE_TOKEN_FILE}.bak" # Remove backup file +else + echo "Error: Failed to update fee token address" + exit 1 +fi \ No newline at end of file