mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 09:50:01 +00:00
## Summary
- Add multi-environment deployment support (stagenet, testnet, mainnet)
to CLI and contracts
- Configure stagenet and testnet runtimes with correct genesis hashes
and Snowbridge Agent IDs
- Add CLI commands for BEEFY checkpoint updates and rewards origin
computation
- Add ETH validator strategies (native beacon chain ETH + LSTs) to all
config files
## Changes
### Runtime Configuration
**Stagenet Runtime:**
- Set `StagenetGenesisHash` to DataHaven stagenet genesis hash
- Configure `RewardsAgentOrigin` with computed Snowbridge Agent ID
- Add tests verifying rewards account derivation and agent ID
computation
**Testnet Runtime:**
- Set `TestnetGenesisHash` to DataHaven testnet genesis hash
- Configure `RewardsAgentOrigin` with computed Snowbridge Agent ID
- Add tests verifying rewards account derivation and agent ID
computation
The Rewards Agent ID is computed following Snowbridge's location
description pattern:
```
blake2_256(SCALE_ENCODE("GlobalConsensus", ByGenesis(genesis), "AccountKey20", rewards_account))
```
### CLI Enhancements
- All contracts subcommands (`status`, `deploy`, `verify`,
`update-metadata`) now accept `--environment` option
- Config and deployment files use environment-prefixed naming (e.g.,
`stagenet-hoodi.json`, `testnet-hoodi.json`)
- New `update-beefy-checkpoint` command that:
- Connects to a live DataHaven chain via WebSocket RPC
- Fetches all BEEFY data at the same finalized block for consistency
- Uses parallel queries with `Promise.all` for better performance
- Computes authority hashes (keccak256 of Ethereum addresses derived
from BEEFY public keys)
- Uses Snowbridge's quorum formula `n - floor((n-1)/3)` for strictly >
2/3 majority
- New `update-rewards-origin` command that computes the Snowbridge Agent
ID for the rewards pallet
- Centralized validation via `contractsPreActionHook` for all contract
commands
- Environment validation against allowlist (`stagenet`, `testnet`,
`mainnet`)
### Contract Changes
- Network validation uses explicit allowlist instead of suffix matching
- Added `initialValidatorSetId` and `nextValidatorSetId` fields to
`SnowbridgeConfig` struct
- `DeployBase.s.sol` now uses config values for validator set IDs
instead of hardcoded 0/1
- `DeployParams.s.sol` loads validator set IDs from config with
backwards compatibility
### Validator Strategies
Added ETH-equivalent strategies to allow validators to stake using
native ETH or LSTs:
**All Networks:**
- `0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0` - Native beacon chain ETH
(virtual strategy)
**Hoodi Testnet:**
- `0xf8a1a66130d614c7360e868576d5e59203475fe0` - stETH
- `0x24579aD4fe83aC53546E5c2D3dF5F85D6383420d` - WETH
**Ethereum Mainnet:**
- `0x93c4b944D05dfe6df7645A86cd2206016c51564D` - stETH
- `0x1BeE69b7dFFfA4E2d53C2a2Df135C388AD25dCD2` - rETH
- `0x54945180dB7943c0ed0FEE7EdaB2Bd24620256bc` - cbETH
### Config Files
- `stagenet-hoodi.json` - Hoodi testnet with stagenet EigenLayer
addresses
- `testnet-hoodi.json` - Hoodi testnet with testnet EigenLayer addresses
- `mainnet-ethereum.json` - Ethereum mainnet with mainnet EigenLayer
addresses
- Removed `hoodi.json` (replaced by environment-prefixed files)
## Usage
```bash
# Deploy to stagenet on Hoodi
bun cli contracts deploy --chain hoodi --environment stagenet
# Update BEEFY checkpoint from live chain
bun cli contracts update-beefy-checkpoint \
--chain hoodi \
--environment stagenet \
--rpc-url wss://services.datahaven-dev.network/stagenet
# Compute rewards origin for a chain
bun cli contracts update-rewards-origin \
--chain hoodi \
--environment stagenet \
--rpc-url wss://services.datahaven-dev.network/stagenet
# Check deployment status
bun cli contracts status --chain hoodi --environment stagenet
```
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
171 lines
5.3 KiB
TypeScript
171 lines
5.3 KiB
TypeScript
import { logger, printDivider, printHeader } from "utils";
|
|
import { deployContracts } from "../../../scripts/deploy-contracts";
|
|
import { showDeploymentPlanAndStatus } from "./status";
|
|
import { verifyContracts } from "./verify";
|
|
|
|
/**
|
|
* Extracts chain and environment options from command options and parent command.
|
|
* This handles the case where options may be specified at either the subcommand
|
|
* or parent command level.
|
|
*/
|
|
const getChainAndEnvironment = (
|
|
options: any,
|
|
command: any
|
|
): { chain: string | undefined; environment: string | undefined } => {
|
|
let chain = options.chain;
|
|
if (!chain && command.parent) {
|
|
chain = command.parent.getOptionValue("chain");
|
|
}
|
|
if (!chain) {
|
|
chain = command.getOptionValue("chain");
|
|
}
|
|
|
|
let environment = options.environment;
|
|
if (!environment && command.parent) {
|
|
environment = command.parent.getOptionValue("environment");
|
|
}
|
|
|
|
return { chain, environment };
|
|
};
|
|
|
|
export const contractsDeploy = async (options: any, command: any) => {
|
|
const { chain, environment } = getChainAndEnvironment(options, command);
|
|
|
|
// Build display name for logging
|
|
const displayName = environment ? `${environment}-${chain}` : chain;
|
|
|
|
printHeader(`Deploying DataHaven Contracts to ${displayName}`);
|
|
|
|
const txExecutionOverride = options.executeOwnerTransactions ? true : undefined;
|
|
|
|
try {
|
|
logger.info("🚀 Starting deployment...");
|
|
logger.info(`📡 Using chain: ${chain}`);
|
|
if (environment) {
|
|
logger.info(`📡 Using environment: ${environment}`);
|
|
}
|
|
if (options.rpcUrl) {
|
|
logger.info(`📡 Using RPC URL: ${options.rpcUrl}`);
|
|
}
|
|
|
|
// Chain is guaranteed to be defined by preAction hook validation
|
|
await deployContracts({
|
|
chain: chain!,
|
|
environment: environment,
|
|
rpcUrl: options.rpcUrl,
|
|
privateKey: options.privateKey,
|
|
avsOwnerKey: options.avsOwnerKey,
|
|
avsOwnerAddress: options.avsOwnerAddress,
|
|
txExecution: txExecutionOverride
|
|
});
|
|
|
|
printDivider();
|
|
} catch (error) {
|
|
logger.error(`❌ Deployment failed: ${error}`);
|
|
}
|
|
};
|
|
|
|
export const contractsCheck = async (options: any, command: any) => {
|
|
const { chain, environment } = getChainAndEnvironment(options, command);
|
|
|
|
// Build network identifier with environment prefix if specified
|
|
const networkId = environment ? `${environment}-${chain}` : chain;
|
|
|
|
printHeader(`Checking DataHaven ${networkId} Configuration and Status`);
|
|
|
|
logger.info("🔍 Showing deployment plan and status");
|
|
|
|
// Use the status function from status.ts
|
|
// Chain is guaranteed to be defined by preAction hook validation
|
|
await showDeploymentPlanAndStatus(chain!, environment);
|
|
};
|
|
|
|
export const contractsVerify = async (options: any, command: any) => {
|
|
const { chain, environment } = getChainAndEnvironment(options, command);
|
|
|
|
// Build display name for logging
|
|
const displayName = environment ? `${environment}-${chain}` : chain;
|
|
|
|
printHeader(`Verifying DataHaven Contracts on ${displayName} Block Explorer`);
|
|
|
|
if (options.skipVerification) {
|
|
logger.info("⏭️ Skipping verification as requested");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const verifyOptions = {
|
|
...options,
|
|
chain: chain,
|
|
environment: environment
|
|
};
|
|
await verifyContracts(verifyOptions);
|
|
printDivider();
|
|
} catch (error) {
|
|
logger.error(`❌ Verification failed: ${error}`);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Supported networks for contract deployment.
|
|
* These must correspond to config files in contracts/config/{network}.json
|
|
*/
|
|
export const SUPPORTED_NETWORKS = [
|
|
"anvil",
|
|
"hoodi",
|
|
"stagenet-hoodi",
|
|
"testnet-hoodi",
|
|
"ethereum",
|
|
"mainnet-ethereum"
|
|
] as const;
|
|
|
|
export const contractsPreActionHook = async (thisCommand: any) => {
|
|
let chain = thisCommand.getOptionValue("chain");
|
|
let environment = thisCommand.getOptionValue("environment");
|
|
|
|
if (!chain && thisCommand.parent) {
|
|
chain = thisCommand.parent.getOptionValue("chain");
|
|
}
|
|
if (!environment && thisCommand.parent) {
|
|
environment = thisCommand.parent.getOptionValue("environment");
|
|
}
|
|
|
|
const privateKey = thisCommand.getOptionValue("privateKey");
|
|
|
|
if (!chain) {
|
|
logger.error("❌ Chain is required. Use --chain option (hoodi, ethereum, anvil)");
|
|
process.exit(1);
|
|
}
|
|
|
|
const supportedChains = ["hoodi", "ethereum", "anvil"];
|
|
if (!supportedChains.includes(chain)) {
|
|
logger.error(`❌ Unsupported chain: ${chain}. Supported chains: ${supportedChains.join(", ")}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Validate environment if provided
|
|
if (environment) {
|
|
const supportedEnvironments = ["stagenet", "testnet", "mainnet"];
|
|
if (!supportedEnvironments.includes(environment)) {
|
|
logger.error(
|
|
`❌ Unsupported environment: ${environment}. Supported environments: ${supportedEnvironments.join(", ")}`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Validate the full network identifier exists
|
|
const networkId = `${environment}-${chain}`;
|
|
if (!SUPPORTED_NETWORKS.includes(networkId as (typeof SUPPORTED_NETWORKS)[number])) {
|
|
logger.error(
|
|
`❌ Unsupported network combination: ${networkId}. Supported networks: ${SUPPORTED_NETWORKS.join(", ")}`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
if (!privateKey && !process.env.DEPLOYER_PRIVATE_KEY) {
|
|
logger.warn(
|
|
"⚠️ Private key not provided. Will use DEPLOYER_PRIVATE_KEY environment variable if set, or default Anvil key."
|
|
);
|
|
}
|
|
};
|