Skip to content
Closed
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
46 changes: 46 additions & 0 deletions cairo/Makefile
Original file line number Diff line number Diff line change
@@ -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
%:
@:
5 changes: 5 additions & 0 deletions cairo/crates/contracts/src/fee_token.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use starknet::ContractAddress;

pub fn FEE_TOKEN() -> ContractAddress {
0x04718f5a0Fc34cC1AF16A1cdee98fFB20C31f5cD61D6Ab07201858f4287c938D.try_into().unwrap()
}
3 changes: 2 additions & 1 deletion cairo/crates/contracts/src/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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;
use starknet::ContractAddress;
use starknet::EthAddress;

pub fn ETH_ADDRESS() -> ContractAddress {
0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7.try_into().unwrap()
FEE_TOKEN()
}
Comment on lines 9 to 11
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we change usage of ETH_ADDRESS to FEE_TOKEN to avoid this (improperly named) indirection?


#[derive(Serde, Drop, Debug, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions cairo/crates/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod fee_token;
pub mod interfaces;
pub mod mailbox;
pub mod libs {
Expand Down
38 changes: 38 additions & 0 deletions cairo/feeToken
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we name this file with a .sh suffix


# Script to update the FEE_TOKEN address dynamically
# Usage: ./feeToken 0x1234567890abcdef...

if [ $# -eq 0 ]; then
echo "Usage: $0 <fee_token_address>"
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
Loading