Ver código fonte

use .env.template only

nidhi-singh02 3 meses atrás
pai
commit
3d3c2beecf

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 587
pnpm-lock.yaml


+ 90 - 23
target_chains/ethereum/contracts/.env.template

@@ -1,23 +1,90 @@
-# Network Config
-MIGRATIONS_DIR=             # ./migrations/prod-receiver
-MIGRATIONS_NETWORK=         # xyz
-MAINNET=
-
-# The duration that a price feed stored in the contract is considered to be
-# valid, after this duration, the price feed is stale and will be invalid.
-# This value should derive from Pyth to wormhole latency, and target chain blocktime and latency.
-VALID_TIME_PERIOD_SECONDS= # 60
-
-WORMHOLE_CHAIN_NAME= # ethereum, defined in <repo-root>/governance/xc_admin/packages/xc_admin_common/src/chains.ts
-
-CLUSTER= #mainnet/testnet The configs below are read from the cluster file
-
-# Pyth Migrations           # Example Format. If deployed on mainnet/testnet it is available in env.cluster.{cluster}
-SOLANA_CHAIN_ID=  # 0x1
-SOLANA_EMITTER=   # 0xf346195ac02f37d60d4db8ffa6ef74cb1be3550047543a4a9ee9acf4d78697b0
-PYTHNET_CHAIN_ID= # 0x1a
-PYTHNET_EMITTER= # 0xa27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6
-GOVERNANCE_CHAIN_ID= # 0x1
-GOVERNANCE_EMITTER= # 0x63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385
-GOVERNANCE_INITIAL_SEQUENCE=0 # This is optional and default is 0
-SINGLE_UPDATE_FEE_IN_WEI=0
+# =============================================================================
+# FOUNDRY DEPLOYMENT CONFIGURATION TEMPLATE
+# Copy this file to .env and fill in your actual values
+# =============================================================================
+
+# Deployment Configuration
+# Example: PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
+PRIVATE_KEY=YOUR_PRIVATE_KEY_HERE
+# Example: RPC_URL=https://rpc.ankr.com/eth (or http://localhost:8545 for local)
+RPC_URL=YOUR_RPC_URL_HERE
+# Example: ETHERSCAN_API_KEY=your_etherscan_api_key_here
+ETHERSCAN_API_KEY=YOUR_ETHERSCAN_API_KEY_HERE
+
+# =============================================================================
+# WORMHOLE CONFIGURATION  
+# =============================================================================
+
+# Initial Guardian Configuration (comma-separated addresses - Foundry native)
+# For single guardian: INIT_SIGNERS=0xYourGuardianAddress
+# For multiple guardians: INIT_SIGNERS=0xAddress1,0xAddress2,0xAddress3
+# Example: INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5
+INIT_SIGNERS=YOUR_GUARDIAN_ADDRESSES_HERE
+# Example: INIT_CHAIN_ID=1
+INIT_CHAIN_ID=YOUR_CHAIN_ID_HERE
+# Example: INIT_GOV_CHAIN_ID=1
+INIT_GOV_CHAIN_ID=YOUR_GOV_CHAIN_ID_HERE
+# Example: INIT_GOV_CONTRACT=0x0000000000000000000000000000000000000000000000000000000000000004
+INIT_GOV_CONTRACT=YOUR_GOV_CONTRACT_ADDRESS_HERE
+
+# Guardian Set Sync Configuration (set after deployment)
+# Example: WORMHOLE_ADDRESS=0x0000000000000000000000000000000000000000
+WORMHOLE_ADDRESS=DEPLOYED_WORMHOLE_ADDRESS_HERE
+
+# =============================================================================
+# PYTH CONFIGURATION
+# =============================================================================
+
+# Data Source Configuration
+# Example: SOLANA_CHAIN_ID=1
+SOLANA_CHAIN_ID=YOUR_SOLANA_CHAIN_ID_HERE
+# Example: SOLANA_EMITTER=0xf346195ac02f37d60d4db8ffa6ef74cb1be3550047543a4a9ee9acf4d78697b0
+SOLANA_EMITTER=YOUR_SOLANA_EMITTER_ADDRESS_HERE
+# Example: PYTHNET_CHAIN_ID=26
+PYTHNET_CHAIN_ID=YOUR_PYTHNET_CHAIN_ID_HERE
+# Example: PYTHNET_EMITTER=0xa27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6
+PYTHNET_EMITTER=YOUR_PYTHNET_EMITTER_ADDRESS_HERE
+
+# Governance Configuration
+# Example: GOVERNANCE_CHAIN_ID=1
+GOVERNANCE_CHAIN_ID=YOUR_GOVERNANCE_CHAIN_ID_HERE
+# Example: GOVERNANCE_EMITTER=0x63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385
+GOVERNANCE_EMITTER=YOUR_GOVERNANCE_EMITTER_ADDRESS_HERE
+# Example: GOVERNANCE_INITIAL_SEQUENCE=0
+GOVERNANCE_INITIAL_SEQUENCE=YOUR_INITIAL_SEQUENCE_HERE
+
+# Price Feed Configuration
+# Example: VALID_TIME_PERIOD_SECONDS=60
+VALID_TIME_PERIOD_SECONDS=YOUR_VALID_TIME_PERIOD_HERE
+# Example: SINGLE_UPDATE_FEE_IN_WEI=1000000000000000
+SINGLE_UPDATE_FEE_IN_WEI=YOUR_UPDATE_FEE_HERE
+
+# =============================================================================
+# LEGACY CONFIGURATION (for backward compatibility)
+# =============================================================================
+
+# Example: WORMHOLE_CHAIN_NAME=ethereum
+WORMHOLE_CHAIN_NAME=YOUR_CHAIN_NAME_HERE
+# Example: CLUSTER=mainnet
+CLUSTER=YOUR_CLUSTER_HERE
+
+# =============================================================================
+# EXAMPLE VALUES FOR REFERENCE
+# =============================================================================
+# 
+# For local testing (Anvil), you can use:
+#   PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
+#   RPC_URL=http://localhost:8545
+#   INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5
+#   INIT_CHAIN_ID=2
+#   INIT_GOV_CHAIN_ID=1
+#   INIT_GOV_CONTRACT=0x0000000000000000000000000000000000000000000000000000000000000004
+#
+# For testnet/mainnet deployment:
+#   - Get your private key from your wallet (never commit this!)
+#   - Use appropriate RPC URL (Alchemy, Infura, QuickNode, etc.)
+#   - Get Etherscan API key from https://etherscan.io/apis
+#   - Use actual guardian addresses from your network
+#   - Set proper chain IDs and governance contracts
+#
+# ⚠️  SECURITY WARNING: Never commit your actual .env file to version control!

+ 39 - 17
target_chains/ethereum/contracts/.env.test

@@ -1,27 +1,49 @@
-# Migrations Metadata
-MIGRATIONS_DIR=./migrations/test
+# =============================================================================
+# FOUNDRY TEST CONFIGURATION
+# This file contains test values for local development and testing
+# Uses Foundry-native environment variable formats
+# =============================================================================
 
-# Wormhole Core Migrations
-INIT_SIGNERS=["0xbeFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe"]
-INIT_CHAIN_ID=0x2
-INIT_GOV_CHAIN_ID=0x1
+# Deployment Configuration (Anvil/Local Testing)
+PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
+RPC_URL=http://localhost:8545
+ETHERSCAN_API_KEY=test_api_key_not_needed_for_local
+
+# =============================================================================
+# WORMHOLE TEST CONFIGURATION  
+# =============================================================================
+
+# Guardian Configuration (comma-separated addresses - Foundry native)
+INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5,0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
+INIT_CHAIN_ID=2
+INIT_GOV_CHAIN_ID=1
 INIT_GOV_CONTRACT=0x0000000000000000000000000000000000000000000000000000000000000004
 
-# Bridge Migrations
-BRIDGE_INIT_CHAIN_ID=0x2
-BRIDGE_INIT_GOV_CHAIN_ID=0x1
-BRIDGE_INIT_GOV_CONTRACT=0x0000000000000000000000000000000000000000000000000000000000000004
-BRIDGE_INIT_WETH=0xDDb64fE46a91D46ee29420539FC25FD07c5FEa3E
+# Guardian Set Sync Configuration (will be set after deployment)
+WORMHOLE_ADDRESS=0x0000000000000000000000000000000000000000
+
+# =============================================================================
+# PYTH TEST CONFIGURATION
+# =============================================================================
 
-#Pyth
-SOLANA_CHAIN_ID=0x1
+# Test Data Source Configuration
+SOLANA_CHAIN_ID=1
 SOLANA_EMITTER=0x71f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b
+PYTHNET_CHAIN_ID=26
+PYTHNET_EMITTER=0xa27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6
 
-VALID_TIME_PERIOD_SECONDS=60
+# Test Governance Configuration
+GOVERNANCE_CHAIN_ID=1
+GOVERNANCE_EMITTER=0x0000000000000000000000000000000000000000000000000000000000001234
+GOVERNANCE_INITIAL_SEQUENCE=0
 
+# Test Price Feed Configuration
+VALID_TIME_PERIOD_SECONDS=60
+SINGLE_UPDATE_FEE_IN_WEI=1
 
-GOVERNANCE_CHAIN_ID=0x1
-GOVERNANCE_EMITTER=0x0000000000000000000000000000000000000000000000000000000000001234
+# =============================================================================
+# LEGACY CONFIGURATION (for backward compatibility)
+# =============================================================================
 
 WORMHOLE_CHAIN_NAME=ethereum
-SINGLE_UPDATE_FEE_IN_WEI=1
+CLUSTER=testnet

+ 180 - 0
target_chains/ethereum/contracts/FOUNDRY_ENV_GUIDE.md

@@ -0,0 +1,180 @@
+# Foundry Environment Variables Guide
+
+This guide shows the **recommended Foundry-native approaches** for reading environment variables in deployment scripts, without custom parsers.
+
+## 🎯 Recommended Approaches
+
+### 1. **Comma-Separated Arrays** ⭐ **BEST FOR MOST CASES**
+
+**Use Case:** Arrays of addresses, numbers, or simple types
+
+**Environment Format:**
+```bash
+# Multiple addresses
+INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5,0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
+
+# Multiple numbers
+CHAIN_IDS=1,137,56,43114
+
+# Multiple strings (if supported)
+NETWORKS=ethereum,polygon,bsc
+```
+
+**Solidity Code:**
+```solidity
+// Read address array
+address[] memory signers = vm.envAddress("INIT_SIGNERS", ",");
+
+// Read uint array  
+uint256[] memory chainIds = vm.envUint("CHAIN_IDS", ",");
+
+// Convert addresses to bytes32 if needed
+bytes32[] memory guardians = new bytes32[](signers.length);
+for (uint i = 0; i < signers.length; i++) {
+    guardians[i] = bytes32(uint256(uint160(signers[i])));
+}
+```
+
+**✅ Advantages:**
+- Native Foundry support
+- Clean, readable format
+- No parsing needed
+- Works with all basic types
+
+### 2. **JSON with vm.parseJson** (For Complex Data)
+
+**Use Case:** Complex nested data structures
+
+**Environment Format:**
+```bash
+# Simple array
+INIT_SIGNERS='["0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5","0x025ceeba2ab2a27d53d963393999eeebe83dc4ae"]'
+
+# Complex object
+CONFIG='{"guardians":["0x..."],"chainId":1,"enabled":true}'
+```
+
+**Solidity Code:**
+```solidity
+// Simple array
+string memory signersJson = vm.envString("INIT_SIGNERS");
+address[] memory signers = abi.decode(vm.parseJson(signersJson), (address[]));
+
+// Complex object with key selection
+string memory configJson = vm.envString("CONFIG");
+address[] memory guardians = abi.decode(vm.parseJson(configJson, ".guardians"), (address[]));
+uint256 chainId = abi.decode(vm.parseJson(configJson, ".chainId"), (uint256));
+bool enabled = abi.decode(vm.parseJson(configJson, ".enabled"), (bool));
+```
+
+**⚠️ Requirements:**
+- JSON must be properly formatted
+- Use single quotes in .env files to prevent shell parsing issues
+- May need escaping for complex nested structures
+
+### 3. **Individual Environment Variables** (Simple & Reliable)
+
+**Use Case:** When you have a known, small number of values
+
+**Environment Format:**
+```bash
+GUARDIAN_1=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5
+GUARDIAN_2=0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
+GUARDIAN_COUNT=2
+```
+
+**Solidity Code:**
+```solidity
+uint256 guardianCount = vm.envUint("GUARDIAN_COUNT");
+bytes32[] memory guardians = new bytes32[](guardianCount);
+
+for (uint i = 0; i < guardianCount; i++) {
+    string memory key = string(abi.encodePacked("GUARDIAN_", vm.toString(i + 1)));
+    address guardian = vm.envAddress(key);
+    guardians[i] = bytes32(uint256(uint160(guardian)));
+}
+```
+
+**✅ Advantages:**
+- Most reliable
+- Easy to debug
+- No parsing issues
+- Clear variable names
+
+## 📋 Available Foundry VM Methods
+
+```solidity
+// Basic types
+vm.envString("KEY")          // string
+vm.envAddress("KEY")         // address  
+vm.envUint("KEY")            // uint256
+vm.envInt("KEY")             // int256
+vm.envBytes32("KEY")         // bytes32
+vm.envBytes("KEY")           // bytes
+vm.envBool("KEY")            // bool
+
+// Arrays with delimiter
+vm.envAddress("KEY", ",")    // address[]
+vm.envUint("KEY", ",")       // uint256[]
+vm.envInt("KEY", ",")        // int256[]
+vm.envBytes32("KEY", ",")    // bytes32[]
+vm.envString("KEY", ",")     // string[]
+
+// With default values
+vm.envOr("KEY", defaultValue)
+
+// JSON parsing
+vm.parseJson(jsonString)           // Parse entire JSON
+vm.parseJson(jsonString, ".key")   // Parse specific key
+```
+
+## 🛠️ Our Implementation
+
+**Current Deploy.s.sol uses Approach #1 (Comma-Separated):**
+
+```solidity
+// ✅ Clean, native Foundry approach
+address[] memory signerAddresses = vm.envAddress("INIT_SIGNERS", ",");
+
+// Convert to bytes32 for Wormhole
+bytes32[] memory initialSigners = new bytes32[](signerAddresses.length);
+for (uint i = 0; i < signerAddresses.length; i++) {
+    initialSigners[i] = bytes32(uint256(uint160(signerAddresses[i])));
+}
+```
+
+**Environment Format:**
+```bash
+INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5,0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
+```
+
+## 🚫 What to Avoid
+
+- ❌ Custom string parsing functions
+- ❌ Complex regex operations
+- ❌ Manual hex conversion (use vm.envAddress instead)
+- ❌ Hardcoded values in scripts
+- ❌ Unescaped JSON in environment files
+
+## 💡 Best Practices
+
+1. **Use comma-separated for simple arrays**
+2. **Use individual vars for small, known sets**
+3. **Use JSON only for complex nested data**
+4. **Always validate environment variables exist**
+5. **Use `vm.envOr()` for optional values with defaults**
+6. **Keep environment files well-documented**
+7. **Test with different environment configurations**
+
+## 🧪 Testing
+
+```bash
+# Test with current environment
+forge script script/Deploy.s.sol
+
+# Test with specific environment file
+cp .env.test .env && forge script script/Deploy.s.sol
+
+# Test individual components
+forge script script/Deploy.s.sol --sig "deployWormhole()"
+```

+ 1 - 1
target_chains/ethereum/contracts/README.md

@@ -41,7 +41,7 @@ To deploy the contracts, you'll need to set up your environment variables and us
 1. Copy the environment template and fill in your values:
 
 ```bash
-cp deploy.env.example .env
+cp .env.template .env
 # Edit .env with your configuration
 ```
 

+ 0 - 24
target_chains/ethereum/contracts/deploy.env.example

@@ -1,24 +0,0 @@
-# Deployment Configuration
-PRIVATE_KEY=your_private_key_here
-
-# Wormhole Configuration
-INIT_SIGNERS=["0x...","0x..."]  # JSON array of initial guardian public keys
-INIT_CHAIN_ID=1                 # Chain ID for this deployment
-INIT_GOV_CHAIN_ID=1            # Governance chain ID
-INIT_GOV_CONTRACT=0x0000000000000000000000000000000000000000000000000000000000000004
-
-# Pyth Configuration
-SOLANA_CHAIN_ID=1              # Solana chain ID for Pyth data source
-SOLANA_EMITTER=0x...           # Pyth emitter address on Solana
-GOVERNANCE_CHAIN_ID=1          # Governance chain ID
-GOVERNANCE_EMITTER=0x...       # Governance emitter address
-GOVERNANCE_INITIAL_SEQUENCE=0  # Initial governance sequence number
-VALID_TIME_PERIOD_SECONDS=60   # Valid time period for price updates in seconds
-SINGLE_UPDATE_FEE_IN_WEI=1000000000000000  # Fee for single price update in wei
-
-# RPC Configuration
-RPC_URL=https://rpc.ankr.com/eth
-ETHERSCAN_API_KEY=your_etherscan_api_key_here
-
-# Guardian Set Sync Configuration
-WORMHOLE_ADDRESS=0x...  # Address of the deployed Wormhole contract

+ 3 - 2
target_chains/ethereum/contracts/script/Deploy.s.sol

@@ -31,7 +31,7 @@ contract DeployScript is Script {
 
     function deployWormhole() internal returns (address) {
         // Read environment variables
-        bytes32[] memory initialSigners = abi.decode(vm.parseJson(vm.envString("INIT_SIGNERS")), (bytes32[]));
+        address[] memory initialSigners = vm.envAddress("INIT_SIGNERS", ",");
         uint16 chainId = uint16(vm.envUint("INIT_CHAIN_ID"));
         uint16 governanceChainId = uint16(vm.envUint("INIT_GOV_CHAIN_ID"));
         bytes32 governanceContract = vm.envBytes32("INIT_GOV_CONTRACT");
@@ -49,7 +49,7 @@ contract DeployScript is Script {
 
         // Encode initialization data
         bytes memory initData = abi.encodeWithSignature(
-            "setup(address,bytes32[],uint16,uint16,bytes32)",
+            "setup(address,address[],uint16,uint16,bytes32)",
             address(implementation),
             initialSigners,
             chainId,
@@ -109,4 +109,5 @@ contract DeployScript is Script {
         
         return address(pythProxy);
     }
+
 }

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff