Skip to content
Merged
5 changes: 2 additions & 3 deletions packages/contracts-bedrock/scripts/SetupCustomGasToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import { Constants } from "src/libraries/Constants.sol";
/// @dev This script:
/// 1. Pre-checks L1 configuration
/// 2. Deploys DepositedOKBAdapter with designated owner
/// 3. Adds designated owner address to whitelist for deposits
/// 4. Sets gas paying token in SystemConfig storage
/// 5. Post-checks configuration
/// 3. Sets gas paying token in SystemConfig storage
/// 4. Post-checks configuration
contract SetupCustomGasToken is Script {
// Addresses to be loaded from deployment artifacts
address systemConfigProxy;
Expand Down
200 changes: 0 additions & 200 deletions test-pp-op/cgt-only-contract.sh

This file was deleted.

3 changes: 3 additions & 0 deletions test/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ L1_BEACON_URL_IN_DOCKER=http://l1-beacon-chain:3500
SAFE_ADDRESS=0x0000000000000000000000000000000000000000
TRANSACTOR=0x0000000000000000000000000000000000000000

DEPLOYER_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
SEQUENCER_P2P_KEY=0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
OP_BATCHER_PRIVATE_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
Expand All @@ -45,6 +46,8 @@ SYSTEM_CONFIG_PROXY_ADDRESS=0x330cff9f99a75bc9c71750b5c60fdc0eff1789e1
PROXY_ADMIN=0x922d6956c99e12dfeb3224dea977d0939758a1fe
PROPOSER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
OPTIMISM_PORTAL_PROXY_ADDRESS=0xc8e8b7b181db301f27aef90ed285787a3ce179e9
# For testing, Adapter owner is the deployer
OKB_ADAPTER_OWNER_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

# OKB Token Address on L1. If not set, a new MockOKB will be deployed.
OKB_TOKEN_ADDRESS=0x75231f58b43240c9718dd58b4967c5114342a86c
Expand Down
12 changes: 1 addition & 11 deletions test/setup-cgt-function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ setup_cgt() {
# Export required environment variables for the setup script
export SYSTEM_CONFIG_PROXY_ADDRESS="$SYSTEM_CONFIG_PROXY_ADDRESS"
export OPTIMISM_PORTAL_PROXY_ADDRESS="$OPTIMISM_PORTAL_PROXY_ADDRESS"
export OKB_ADAPTER_OWNER_ADDRESS="$OKB_ADAPTER_OWNER_ADDRESS"

# Temporarily disable set -e to capture forge output properly
set +e
Expand Down Expand Up @@ -129,15 +130,4 @@ setup_cgt() {
echo " OKB Token: $OKB_TOKEN"
echo " Adapter: $ADAPTER_ADDRESS"
echo ""

# Save OKB_TOKEN_ADDRESS to .env file for the test script to use
echo "💾 Updating .env with OKB token address..."

# Update OKB_TOKEN_ADDRESS in .env
sed_inplace "s/^OKB_TOKEN_ADDRESS=.*/OKB_TOKEN_ADDRESS=$OKB_TOKEN_ADDRESS/" "$PWD_DIR/.env"

echo " ✅ OKB token address updated in .env file"
echo " 💡 ADAPTER_ADDRESS can be queried from SystemConfig.gasPayingToken()"
echo " 💡 INIT_TOTAL_SUPPLY can be queried from OKB token contract"
echo ""
}
80 changes: 59 additions & 21 deletions test/test-cgt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
set -e

ROOT_DIR=$(git rev-parse --show-toplevel)
PWD_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

cd $PWD_DIR
# Use current working directory to allow symlinks to work
# This way test/ and test-pp-op/ can each use their own .env
PWD_DIR="$(pwd)"

source .env

# Check if CGT has been set up (OKB_TOKEN_ADDRESS should be in .env)
if [ -z "$OKB_TOKEN_ADDRESS" ]; then
echo "❌ ERROR: OKB_TOKEN_ADDRESS not found in .env"
echo ""
echo "Please run '2-deploy-op-contracts.sh' first to set up CGT and configure OKB token."
echo ""
# Validate we're in a test directory with .env
if [ ! -f "$PWD_DIR/.env" ]; then
echo "❌ ERROR: .env file not found in current directory: $PWD_DIR"
echo "Please run this script from a test directory (test/ or test-pp-op/)"
exit 1
fi

source .env

SYSTEM_CONFIG_PROXY_ADDRESS=$(jq -r '.opChainDeployments[0].SystemConfigProxy' $PWD_DIR/config-op/state.json)

# Query ADAPTER_ADDRESS from SystemConfig.gasPayingToken()
echo "📝 Querying ADAPTER_ADDRESS from SystemConfig..."
ADAPTER_ADDRESS=$(cast call "$SYSTEM_CONFIG_PROXY_ADDRESS" "gasPayingToken()(address,uint8)" --rpc-url "$L1_RPC_URL" | head -n1)
Expand All @@ -26,6 +27,15 @@ if [ -z "$ADAPTER_ADDRESS" ] || [ "$ADAPTER_ADDRESS" = "0x0000000000000000000000
exit 1
fi

# Query OKB_TOKEN_ADDRESS from the adapter
echo "📝 Querying OKB_TOKEN_ADDRESS from adapter..."
OKB_TOKEN_ADDRESS=$(cast call "$ADAPTER_ADDRESS" "OKB()(address)" --rpc-url "$L1_RPC_URL")
if [ -z "$OKB_TOKEN_ADDRESS" ] || [ "$OKB_TOKEN_ADDRESS" = "0x0000000000000000000000000000000000000000" ]; then
echo "❌ ERROR: Could not query OKB_TOKEN_ADDRESS from adapter"
echo " Adapter address: $ADAPTER_ADDRESS"
exit 1
fi

# Query INIT_TOTAL_SUPPLY from OKB token contract
echo "📝 Querying INIT_TOTAL_SUPPLY from OKB token..."
INIT_TOTAL_SUPPLY=$(cast call "$OKB_TOKEN_ADDRESS" "totalSupply()(uint256)" --rpc-url "$L1_RPC_URL")
Expand Down Expand Up @@ -96,30 +106,51 @@ if [ -n "$OKB_TOKEN_ADDRESS" ] && [ -n "$ADAPTER_ADDRESS" ]; then

DEPOSIT_AMOUNT="7999000000000000"

# L2 recipient address
L2_RECIPIENT=0x70997970C51812dc3A010C7d01b50e0d17dc79C9
# Get deployer address and verify it's the adapter owner
DEPLOYER_ADDRESS=$(cast wallet address --private-key "$DEPLOYER_PRIVATE_KEY")
ADAPTER_OWNER=$(cast call "$ADAPTER_ADDRESS" "owner()(address)" --rpc-url "$L1_RPC_URL")

INIT_BALANCE=$(cast balance $L2_RECIPIENT --rpc-url $L2_RPC_URL)
echo " Deposit Amount: $DEPOSIT_AMOUNT"
echo " L2 Recipient: $L2_RECIPIENT"
echo " Initial Balance: $INIT_BALANCE"
echo " Deployer Address: $DEPLOYER_ADDRESS"
echo " Adapter Owner: $ADAPTER_OWNER"

if [ "$DEPLOYER_ADDRESS" != "$ADAPTER_OWNER" ]; then
echo ""
echo "❌ ERROR: Deployer is not the adapter owner"
echo " This script assumes deployer has ownership of the adapter"
echo " Current owner: $ADAPTER_OWNER"
exit 1
fi

echo " ✅ Deployer is verified as adapter owner"
echo ""

# Check deployer's OKB balance before proceeding
DEPLOYER_ADDRESS=$(cast wallet address --private-key "$DEPLOYER_PRIVATE_KEY")
# Check deployer's OKB balance
DEPLOYER_OKB_BALANCE=$(cast call "$OKB_TOKEN_ADDRESS" "balanceOf(address)(uint256)" "$DEPLOYER_ADDRESS" --rpc-url "$L1_RPC_URL")
echo " Deployer ($DEPLOYER_ADDRESS) OKB Balance: $DEPLOYER_OKB_BALANCE"
echo " Deployer OKB Balance: $DEPLOYER_OKB_BALANCE"
echo ""

# Step 2a: Add deployer to whitelist
echo " Adding deployer to whitelist..."
cast send "$ADAPTER_ADDRESS" \
"addToWhitelistBatch(address[])" \
"[$DEPLOYER_ADDRESS]" \
--rpc-url "$L1_RPC_URL" \
--private-key "$DEPLOYER_PRIVATE_KEY"
echo " ✅ Deployer added to whitelist"
echo ""

# Step 2a: Approve the adapter to spend OKB
# Step 2b: Approve the adapter to spend OKB
cast send "$OKB_TOKEN_ADDRESS" \
"approve(address,uint256)" \
"$ADAPTER_ADDRESS" \
"$DEPOSIT_AMOUNT" \
--rpc-url "$L1_RPC_URL" \
--private-key "$DEPLOYER_PRIVATE_KEY"

# Step 2b: Perform the deposit
# L2 recipient address
L2_RECIPIENT=$DEPLOYER_ADDRESS

# Step 2c: Perform the deposit
cast send "$ADAPTER_ADDRESS" \
"deposit(address,uint256)" \
"$L2_RECIPIENT" \
Expand All @@ -134,6 +165,13 @@ if [ -n "$OKB_TOKEN_ADDRESS" ] && [ -n "$ADAPTER_ADDRESS" ]; then
echo " Checking balance every 5 seconds..."
echo ""

INIT_BALANCE=$(cast balance $L2_RECIPIENT --rpc-url $L2_RPC_URL)
echo " Deposit From $DEPLOYER_ADDRESS to $L2_RECIPIENT"
echo " Deposit Amount: $DEPOSIT_AMOUNT"
echo " L2 Recipient: $L2_RECIPIENT"
echo " L2 Recipient Initial Balance: $INIT_BALANCE"
echo ""

# Expected final balance
EXPECTED_BALANCE=$((INIT_BALANCE + DEPOSIT_AMOUNT))

Expand Down