Files
zeekay 42a828e7e3 canonical: single Lux EVM VM ID = mgj786NP… (CB58 of ids.ID{'e','v','m'})
Removed legacy 'srEXi…' (upstream Subnet-EVM ID) — Lux uses one canonical
EVM VM ID for both C-Chain and EVM-based subnets per luxfi/constants.EVMID.
Plugin filename is mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6 only;
no dual install, no aliases.
2026-05-05 20:16:25 -07:00

189 lines
5.7 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package l1cmd
import (
"encoding/json"
"fmt"
"math/big"
"os"
"path/filepath"
"github.com/luxfi/cli/pkg/ux"
"github.com/luxfi/cli/pkg/vm"
"github.com/luxfi/constants"
"github.com/luxfi/ids"
"github.com/luxfi/sdk/models"
"github.com/spf13/cobra"
)
var importAsL1 bool
// Historic L1 configurations for LUX, ZOO, SPC
var historicL1s = []struct {
Name string
NetworkID string
BlockchainID string
EVMChainID uint64
TokenName string
TokenSymbol string
VMID string
VMVersion string
}{
{
Name: "LUX",
NetworkID: "tJqmx13PV8UPQJBbuumANQCKnfPUHCxfahdG29nJa6BHkumCK",
BlockchainID: "dnmzhuf6poM6PUNQCe7MWWfBdTJEnddhHRNXz2x7H6qSmyBEJ",
EVMChainID: 96369,
TokenName: "LUX Token",
TokenSymbol: "LUX",
VMID: "mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6",
VMVersion: "v0.6.12",
},
{
Name: "ZOO",
NetworkID: "xJzemKCLvBNgzYHoBHzXQr9uesR3S3kf3YtZ5mPHTA9LafK6L",
BlockchainID: "bXe2MhhAnXg6WGj6G8oDk55AKT1dMMsN72S8te7JdvzfZX1zM",
EVMChainID: 200200,
TokenName: "ZOO Token",
TokenSymbol: "ZOO",
VMID: "mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6",
VMVersion: "v0.6.12",
},
{
Name: "SPC",
NetworkID: "2hMMhMFfVvpCFrA9LBGS3j5zr5XfARuXdLLYXKpJR3RpnrunH9",
BlockchainID: "QFAFyn1hh59mh7kokA55dJq5ywskF5A1yn8dDpLhmKApS6FP1",
EVMChainID: 36911,
TokenName: "Sparkle Pony Token",
TokenSymbol: "MEAT",
VMID: "mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6",
VMVersion: "v0.6.12",
},
}
func newImportCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "import-historic",
Short: "Import historic blockchains as sovereign L1s",
Long: `Import historic blockchain configurations (LUX, ZOO, SPC) as sovereign L1s.
This command transforms existing chain configurations into modern L1 blockchains
with validator management capabilities.`,
RunE: importHistoricL1s,
}
cmd.Flags().BoolVar(&importAsL1, "as-l1", true, "Import as sovereign L1 (recommended)")
return cmd
}
func importHistoricL1s(_ *cobra.Command, _ []string) error {
ux.Logger.PrintToUser("Importing historic blockchains as sovereign L1s...")
for _, l1 := range historicL1s {
ux.Logger.PrintToUser("\n📥 Importing %s as L1...", l1.Name)
// Check if genesis data exists
genesisPath := filepath.Join("/home/z/work/lux", fmt.Sprintf("genesis-%s", l1.Name))
hasGenesisData := false
if _, err := os.Stat(genesisPath); err == nil {
hasGenesisData = true
ux.Logger.PrintToUser(" Found genesis data at %s", genesisPath)
}
// Create L1 configuration
sc := &models.Sidecar{
Name: l1.Name,
VM: models.EVM,
VMVersion: l1.VMVersion,
EVMChainID: fmt.Sprintf("%d", l1.EVMChainID),
Sovereign: true,
ValidatorManagement: ValidatorManagementPoA, // Default to PoA for historic chains
TokenInfo: models.TokenInfo{
Name: l1.TokenName,
Symbol: l1.TokenSymbol,
},
Version: constants.SidecarVersion,
}
// Set IDs
networkID, err := ids.FromString(l1.NetworkID)
if err != nil {
ux.Logger.PrintToUser(" ⚠️ Invalid network ID, will generate new")
} else {
sc.ChainID = networkID
}
blockchainID, err := ids.FromString(l1.BlockchainID)
if err != nil {
ux.Logger.PrintToUser(" ⚠️ Invalid blockchain ID, will generate new")
} else {
sc.BlockchainID = blockchainID
}
vmID, err := ids.FromString(l1.VMID)
if err != nil {
ux.Logger.PrintToUser(" ⚠️ Invalid VM ID, using default")
} else {
sc.ImportedVMID = vmID.String()
sc.ImportedFromLPM = true
}
// Create genesis with L1 features
genesis := vm.CreateEVMGenesis(
big.NewInt(int64(l1.EVMChainID)), //nolint:gosec // G115: Chain ID is within int64 range
nil, // allocations
nil, // timestamps
)
// Add PoA validator manager
genesis["contractConfig"] = map[string]interface{}{
"poaValidatorManager": map[string]interface{}{
"enabled": true,
"churnPeriodSeconds": 3600,
"maximumChurnPercentage": 20,
},
}
// If we have genesis data, try to preserve allocations
if hasGenesisData {
ux.Logger.PrintToUser(" Preserving existing allocations and state...")
// Genesis allocation merging will be implemented when state migration tools are available
// This will preserve existing account balances and contract deployments during import
}
// Save configuration
genesisBytes, err := json.MarshalIndent(genesis, "", " ")
if err != nil {
ux.Logger.PrintToUser(" ❌ Failed to marshal genesis: %v", err)
continue
}
if err := app.WriteGenesisFile(l1.Name, genesisBytes); err != nil {
ux.Logger.PrintToUser(" ❌ Failed to write genesis: %v", err)
continue
}
if err := app.WriteSidecarFile(sc); err != nil {
ux.Logger.PrintToUser(" ❌ Failed to write sidecar: %v", err)
continue
}
ux.Logger.PrintToUser(" ✅ Imported %s as sovereign L1", l1.Name)
ux.Logger.PrintToUser(" Chain ID: %d", l1.EVMChainID)
ux.Logger.PrintToUser(" Token: %s (%s)", l1.TokenName, l1.TokenSymbol)
ux.Logger.PrintToUser(" Blockchain ID: %s", l1.BlockchainID)
}
ux.Logger.PrintToUser("\n✅ Historic blockchain import complete!")
ux.Logger.PrintToUser("\nNext steps:")
ux.Logger.PrintToUser("1. Start local network: lux network quickstart")
ux.Logger.PrintToUser("2. Deploy L1s:")
ux.Logger.PrintToUser(" lux l1 deploy LUX --local")
ux.Logger.PrintToUser(" lux l1 deploy ZOO --local")
ux.Logger.PrintToUser(" lux l1 deploy SPC --local")
return nil
}