diff --git a/config/contexts/migrations/v0.0.8-v0.0.9.go b/config/contexts/migrations/v0.0.8-v0.0.9.go index 16e0b909..fcf01159 100644 --- a/config/contexts/migrations/v0.0.8-v0.0.9.go +++ b/config/contexts/migrations/v0.0.8-v0.0.9.go @@ -1,6 +1,7 @@ package contextMigrations import ( + "github.com/Layr-Labs/devkit-cli/pkg/common" "github.com/Layr-Labs/devkit-cli/pkg/migration" "gopkg.in/yaml.v3" @@ -28,12 +29,44 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { return &yaml.Node{Kind: yaml.ScalarNode, Value: "28820370"} }, }, + // Update L1 AllocationManager address + { + Path: []string{"context", "eigenlayer", "l1", "allocation_manager"}, + Condition: migration.Always{}, + Transform: func(_ *yaml.Node) *yaml.Node { + return GetAddressByChainIdFromCtx(user, common.MAINNET_ALLOCATION_MANAGER_ADDRESS, common.SEPOLIA_ALLOCATION_MANAGER_ADDRESS) + }, + }, + // Update L1 DelegationManager address + { + Path: []string{"context", "eigenlayer", "l1", "delegation_manager"}, + Condition: migration.Always{}, + Transform: func(_ *yaml.Node) *yaml.Node { + return GetAddressByChainIdFromCtx(user, common.MAINNET_DELEGATION_MANAGER_ADDRESS, common.SEPOLIA_DELEGATION_MANAGER_ADDRESS) + }, + }, + // Update L1 StrategyManager address + { + Path: []string{"context", "eigenlayer", "l1", "strategy_manager"}, + Condition: migration.Always{}, + Transform: func(_ *yaml.Node) *yaml.Node { + return GetAddressByChainIdFromCtx(user, common.MAINNET_STRATEGY_MANAGER_ADDRESS, common.SEPOLIA_STRATEGY_MANAGER_ADDRESS) + }, + }, + // Update L1 ReleaseManager address + { + Path: []string{"context", "eigenlayer", "l1", "release_manager"}, + Condition: migration.Always{}, + Transform: func(_ *yaml.Node) *yaml.Node { + return GetAddressByChainIdFromCtx(user, common.MAINNET_RELEASE_MANAGER_ADDRESS, common.SEPOLIA_RELEASE_MANAGER_ADDRESS) + }, + }, // Update L1 CrossChainRegistry address { Path: []string{"context", "eigenlayer", "l1", "cross_chain_registry"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0x287381B1570d9048c4B4C7EC94d21dDb8Aa1352a"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_CROSS_CHAIN_REGISTRY_ADDRESS, common.SEPOLIA_CROSS_CHAIN_REGISTRY_ADDRESS) }, }, // Update L1 OperatorTableUpdater address @@ -41,7 +74,7 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { Path: []string{"context", "eigenlayer", "l1", "operator_table_updater"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xB02A15c6Bd0882b35e9936A9579f35FB26E11476"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_L1_OPERATOR_TABLE_UPDATER_ADDRESS, common.SEPOLIA_L1_OPERATOR_TABLE_UPDATER_ADDRESS) }, }, // Update L1 KeyRegistrar address @@ -49,7 +82,15 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { Path: []string{"context", "eigenlayer", "l1", "key_registrar"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xA4dB30D08d8bbcA00D40600bee9F029984dB162a"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_KEY_REGISTRAR_ADDRESS, common.SEPOLIA_KEY_REGISTRAR_ADDRESS) + }, + }, + // Update L1 TaskMailbox address + { + Path: []string{"context", "eigenlayer", "l1", "task_mailbox"}, + Condition: migration.Always{}, + Transform: func(_ *yaml.Node) *yaml.Node { + return GetAddressByChainIdFromCtx(user, common.MAINNET_L1_TASK_MAILBOX_ADDRESS, common.SEPOLIA_L1_TASK_MAILBOX_ADDRESS) }, }, // Update L2 TaskMailbox address @@ -57,7 +98,7 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { Path: []string{"context", "eigenlayer", "l2", "task_mailbox"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xB99CC53e8db7018f557606C2a5B066527bF96b26"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_L2_TASK_MAILBOX_ADDRESS, common.SEPOLIA_L2_TASK_MAILBOX_ADDRESS) }, }, // Update L2 OperatorTableUpdater address @@ -65,7 +106,7 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { Path: []string{"context", "eigenlayer", "l2", "operator_table_updater"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xB02A15c6Bd0882b35e9936A9579f35FB26E11476"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_L2_OPERATOR_TABLE_UPDATER_ADDRESS, common.SEPOLIA_L2_OPERATOR_TABLE_UPDATER_ADDRESS) }, }, // Update L2 BN254CertificateVerifier address @@ -73,7 +114,7 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { Path: []string{"context", "eigenlayer", "l2", "bn254_certificate_verifier"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xff58A373c18268F483C1F5cA03Cf885c0C43373a"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_BN254_CERTIFICATE_VERIFIER_ADDRESS, common.SEPOLIA_BN254_CERTIFICATE_VERIFIER_ADDRESS) }, }, // Update L2 ECDSACertificateVerifier address @@ -81,23 +122,23 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { Path: []string{"context", "eigenlayer", "l2", "ecdsa_certificate_verifier"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xb3Cd1A457dEa9A9A6F6406c6419B1c326670A96F"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_ECDSA_CERTIFICATE_VERIFIER_ADDRESS, common.SEPOLIA_ECDSA_CERTIFICATE_VERIFIER_ADDRESS) }, }, - // Update L1 BN254TableCalculator address + // Update L1 BN254TableCalculator address (env aware - this will not be updated by zeus) { Path: []string{"context", "eigenlayer", "l1", "bn254_table_calculator"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xa19E3B00cf4aC46B5e6dc0Bbb0Fb0c86D0D65603"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_BN254_TABLE_CALCULATOR_ADDRESS, common.SEPOLIA_BN254_TABLE_CALCULATOR_ADDRESS) }, }, - // Update L1 ECDSATableCalculator address + // Update L1 ECDSATableCalculator middleware address (env aware - this will not be updated by zeus) { Path: []string{"context", "eigenlayer", "l1", "ecdsa_table_calculator"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0xaCB5DE6aa94a1908E6FA577C2ade65065333B450"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_ECDSA_TABLE_CALCULATOR_ADDRESS, common.SEPOLIA_ECDSA_TABLE_CALCULATOR_ADDRESS) }, }, }, @@ -114,3 +155,14 @@ func Migration_0_0_8_to_0_0_9(user, old, new *yaml.Node) (*yaml.Node, error) { return user, nil } + +func GetAddressByChainIdFromCtx(ctx *yaml.Node, mainnetAddress, sepoliaAddress string) *yaml.Node { + // check l1 chainId - if == 1 then use MAINNET address + chainId := migration.ResolveNode(ctx, []string{"context", "chains", "l1", "chain_id"}) + address := sepoliaAddress + if chainId != nil && chainId.Value == "1" { + address = mainnetAddress + } + + return &yaml.Node{Kind: yaml.ScalarNode, Value: address} +} diff --git a/config/contexts/migrations/v0.0.9-v0.1.0.go b/config/contexts/migrations/v0.0.9-v0.1.0.go index 458429fa..1701eff2 100644 --- a/config/contexts/migrations/v0.0.9-v0.1.0.go +++ b/config/contexts/migrations/v0.0.9-v0.1.0.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/Layr-Labs/devkit-cli/pkg/common" "github.com/Layr-Labs/devkit-cli/pkg/migration" "gopkg.in/yaml.v3" @@ -12,10 +13,18 @@ import ( func Migration_0_0_9_to_0_1_0(user, old, new *yaml.Node) (*yaml.Node, error) { // Add missing strategy upgrade to move stETH from holesky to sepolia const ( - oldStrat = "0x7D704507b76571a51d9caE8AdDAbBFd0ba0e63d3" - newStrat = "0x8b29d91e67b013e855EaFe0ad704aC4Ab086a574" + oldStrat = "0x7D704507b76571a51d9caE8AdDAbBFd0ba0e63d3" + newSepoliaStrat = "0x8b29d91e67b013e855EaFe0ad704aC4Ab086a574" + newMainnetStrat = "0x93c4b944d05dfe6df7645a86cd2206016c51564d" ) + // check l1 chainId - if == 1 then use MAINNET address + chainId := migration.ResolveNode(user, []string{"context", "chains", "l1", "chain_id"}) + newStrat := newSepoliaStrat + if chainId != nil && chainId.Value == "1" { + newStrat = newMainnetStrat + } + // Patch all changes in context engine := migration.PatchEngine{ Old: old, @@ -175,7 +184,7 @@ func Migration_0_0_9_to_0_1_0(user, old, new *yaml.Node) (*yaml.Node, error) { Path: []string{"context", "eigenlayer", "l1", "permission_controller"}, Condition: migration.Always{}, Transform: func(_ *yaml.Node) *yaml.Node { - return &yaml.Node{Kind: yaml.ScalarNode, Value: "0x44632dfBdCb6D3E21EF613B0ca8A6A0c618F5a37"} + return GetAddressByChainIdFromCtx(user, common.MAINNET_PERMISSION_CONTROLLER_ADDRESS, common.SEPOLIA_PERMISSION_CONTROLLER_ADDRESS) }, }, // Update L1 fork block diff --git a/pkg/common/constants.go b/pkg/common/constants.go index 9975a1bf..6e49d7a3 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -38,20 +38,47 @@ const ( CURVE_TYPE_KEY_REGISTRAR_ECDSA = 1 CURVE_TYPE_KEY_REGISTRAR_BN254 = 2 - // These are fallback EigenLayer deployment addresses when not specified in context (assumes seploia) - ALLOCATION_MANAGER_ADDRESS = "0x42583067658071247ec8CE0A516A58f682002d07" - DELEGATION_MANAGER_ADDRESS = "0xD4A7E1Bd8015057293f0D0A557088c286942e84b" - STRATEGY_MANAGER_ADDRESS = "0x2E3D6c0744b10eb0A4e6F679F71554a39Ec47a5D" - KEY_REGISTRAR_ADDRESS = "0xA4dB30D08d8bbcA00D40600bee9F029984dB162a" - CROSS_CHAIN_REGISTRY_ADDRESS = "0x287381B1570d9048c4B4C7EC94d21dDb8Aa1352a" - MULTICHAIN_PROXY_ADMIN = "0xC5dc0d145a21FDAD791Df8eDC7EbCB5330A3FdB5" - EIGEN_CONTRACT_ADDRESS = "0x3B78576F7D6837500bA3De27A60c7f594934027E" - RELEASE_MANAGER_ADDRESS = "0xd9Cb89F1993292dEC2F973934bC63B0f2A702776" + // These are fallback EigenLayer deployment addresses when not specified in context (seploia) + SEPOLIA_ALLOCATION_MANAGER_ADDRESS = "0x42583067658071247ec8CE0A516A58f682002d07" + SEPOLIA_DELEGATION_MANAGER_ADDRESS = "0xD4A7E1Bd8015057293f0D0A557088c286942e84b" + SEPOLIA_STRATEGY_MANAGER_ADDRESS = "0x2E3D6c0744b10eb0A4e6F679F71554a39Ec47a5D" + SEPOLIA_KEY_REGISTRAR_ADDRESS = "0xA4dB30D08d8bbcA00D40600bee9F029984dB162a" + SEPOLIA_CROSS_CHAIN_REGISTRY_ADDRESS = "0x287381B1570d9048c4B4C7EC94d21dDb8Aa1352a" + SEPOLIA_EIGEN_CONTRACT_ADDRESS = "0x3B78576F7D6837500bA3De27A60c7f594934027E" + SEPOLIA_RELEASE_MANAGER_ADDRESS = "0xd9Cb89F1993292dEC2F973934bC63B0f2A702776" + SEPOLIA_L1_TASK_MAILBOX_ADDRESS = "0xB99CC53e8db7018f557606C2a5B066527bF96b26" + SEPOLIA_L1_OPERATOR_TABLE_UPDATER_ADDRESS = "0xB02A15c6Bd0882b35e9936A9579f35FB26E11476" + SEPOLIA_PERMISSION_CONTROLLER_ADDRESS = "0x44632dfBdCb6D3E21EF613B0ca8A6A0c618F5a37" // These are fallback EigenLayer Middleware deployment addresses when not specified in context SEPOLIA_BN254_TABLE_CALCULATOR_ADDRESS = "0xa19E3B00cf4aC46B5e6dc0Bbb0Fb0c86D0D65603" SEPOLIA_ECDSA_TABLE_CALCULATOR_ADDRESS = "0xaCB5DE6aa94a1908E6FA577C2ade65065333B450" + // These are L2 fallback addresses + SEPOLIA_L2_TASK_MAILBOX_ADDRESS = "0xB99CC53e8db7018f557606C2a5B066527bF96b26" + SEPOLIA_L2_OPERATOR_TABLE_UPDATER_ADDRESS = "0xB02A15c6Bd0882b35e9936A9579f35FB26E11476" + SEPOLIA_BN254_CERTIFICATE_VERIFIER_ADDRESS = "0xff58A373c18268F483C1F5cA03Cf885c0C43373a" + SEPOLIA_ECDSA_CERTIFICATE_VERIFIER_ADDRESS = "0xb3Cd1A457dEa9A9A6F6406c6419B1c326670A96F" + + // These are fallback EigenLayer deployment addresses when not specified in context (mainnet) + MAINNET_ALLOCATION_MANAGER_ADDRESS = "0x948a420b8CC1d6BFd0B6087C2E7c344a2CD0bc39" + MAINNET_DELEGATION_MANAGER_ADDRESS = "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A" + MAINNET_STRATEGY_MANAGER_ADDRESS = "0x858646372CC42E1A627fcE94aa7A7033e7CF075A" + MAINNET_KEY_REGISTRAR_ADDRESS = "0x54f4bC6bDEbe479173a2bbDc31dD7178408A57A4" + MAINNET_CROSS_CHAIN_REGISTRY_ADDRESS = "0x9376A5863F2193cdE13e1aB7c678F22554E2Ea2b" + MAINNET_EIGEN_CONTRACT_ADDRESS = "0x3B78576F7D6837500bA3De27A60c7f594934027E" + MAINNET_RELEASE_MANAGER_ADDRESS = "0xeDA3CAd031c0cf367cF3f517Ee0DC98F9bA80C8F" + MAINNET_L1_OPERATOR_TABLE_UPDATER_ADDRESS = "0x5557E1fE3068A1e823cE5Dcd052c6C352E2617B5" + MAINNET_L1_TASK_MAILBOX_ADDRESS = "0x132b466d9d5723531F68797519DfED701aC2C749" + MAINNET_PERMISSION_CONTROLLER_ADDRESS = "0x25E5F8B1E7aDf44518d35D5B2271f114e081f0E5" + + // These are fallback EigenLayer Middleware deployment addresses when not specified in context MAINNET_BN254_TABLE_CALCULATOR_ADDRESS = "0x55F4b21681977F412B318eCB204cB933bD1dF57c" MAINNET_ECDSA_TABLE_CALCULATOR_ADDRESS = "0xA933CB4cbD0C4C208305917f56e0C3f51ad713Fa" + + // These are L2 fallback addresses + MAINNET_L2_TASK_MAILBOX_ADDRESS = "0x132b466d9d5723531F68797519DfED701aC2C749" + MAINNET_L2_OPERATOR_TABLE_UPDATER_ADDRESS = "0x5557E1fE3068A1e823cE5Dcd052c6C352E2617B5" + MAINNET_BN254_CERTIFICATE_VERIFIER_ADDRESS = "0x3F55654b2b2b86bB11bE2f72657f9C33bf88120A" + MAINNET_ECDSA_CERTIFICATE_VERIFIER_ADDRESS = "0xd0930ee96D07de4F9d493c259232222e46B6EC25" ) diff --git a/pkg/common/devnet/constants.go b/pkg/common/devnet/constants.go index 4d702bb4..9e4dabe0 100644 --- a/pkg/common/devnet/constants.go +++ b/pkg/common/devnet/constants.go @@ -18,16 +18,7 @@ const CURVE_TYPE_KEY_REGISTRAR_UNKNOWN = 0 const CURVE_TYPE_KEY_REGISTRAR_ECDSA = 1 const CURVE_TYPE_KEY_REGISTRAR_BN254 = 2 -// These are fallback EigenLayer deployment addresses when not specified in context -const ALLOCATION_MANAGER_ADDRESS = "0x42583067658071247ec8CE0A516A58f682002d07" -const DELEGATION_MANAGER_ADDRESS = "0xD4A7E1Bd8015057293f0D0A557088c286942e84b" -const STRATEGY_MANAGER_ADDRESS = "0x2E3D6c0744b10eb0A4e6F679F71554a39Ec47a5D" -const KEY_REGISTRAR_ADDRESS = "0x78De554Ac8DfF368e3CAa73B3Df8AccCfD92928A" -const CROSS_CHAIN_REGISTRY_ADDRESS = "0xe850D8A178777b483D37fD492a476e3E6004C816" -const BN254_TABLE_CALCULATOR_ADDRESS = "0xc2c0bc13571aC5115709C332dc7AE666606b08E8" -const MULTICHAIN_PROXY_ADMIN = "0xC5dc0d145a21FDAD791Df8eDC7EbCB5330A3FdB5" const EIGEN_CONTRACT_ADDRESS = "0x3B78576F7D6837500bA3De27A60c7f594934027E" -const RELEASE_MANAGER_ADDRESS = "0xd9Cb89F1993292dEC2F973934bC63B0f2A702776" const ST_ETH_TOKEN_ADDRESS = "0x00c71b0fCadE911B2feeE9912DE4Fe19eB04ca56" const B_EIGEN_TOKEN_ADDRESS = "0x275cCf9Be51f4a6C94aBa6114cdf2a4c45B9cb27" diff --git a/pkg/common/getters.go b/pkg/common/getters.go index 69539d77..2e8e66c5 100644 --- a/pkg/common/getters.go +++ b/pkg/common/getters.go @@ -32,10 +32,22 @@ func GetForkUrlDefault(contextName string, cfg *ConfigWithContextConfig, chainNa // GetEigenLayerAddresses returns EigenLayer L1 addresses from the context config // Falls back to constants if not found in context func GetEigenLayerAddresses(contextName string, cfg *ConfigWithContextConfig) (allocationManager, delegationManager, strategyManager, keyRegistrar, crossChainRegistry, bn254TableCalculator, ecdsaTableCalculator, releaseManager string) { - // Default middleware addresses according to context - var BN254_TABLE_CALCULATOR_ADDRESS = SEPOLIA_BN254_TABLE_CALCULATOR_ADDRESS - var ECDSA_TABLE_CALCULATOR_ADDRESS = SEPOLIA_ECDSA_TABLE_CALCULATOR_ADDRESS + // Default addresses according to context to return incase of bad context + ALLOCATION_MANAGER_ADDRESS := SEPOLIA_ALLOCATION_MANAGER_ADDRESS + DELEGATION_MANAGER_ADDRESS := SEPOLIA_DELEGATION_MANAGER_ADDRESS + STRATEGY_MANAGER_ADDRESS := SEPOLIA_STRATEGY_MANAGER_ADDRESS + KEY_REGISTRAR_ADDRESS := SEPOLIA_KEY_REGISTRAR_ADDRESS + CROSS_CHAIN_REGISTRY_ADDRESS := SEPOLIA_CROSS_CHAIN_REGISTRY_ADDRESS + RELEASE_MANAGER_ADDRESS := SEPOLIA_RELEASE_MANAGER_ADDRESS + BN254_TABLE_CALCULATOR_ADDRESS := SEPOLIA_BN254_TABLE_CALCULATOR_ADDRESS + ECDSA_TABLE_CALCULATOR_ADDRESS := SEPOLIA_ECDSA_TABLE_CALCULATOR_ADDRESS if contextName == "mainnet" { + ALLOCATION_MANAGER_ADDRESS = MAINNET_ALLOCATION_MANAGER_ADDRESS + DELEGATION_MANAGER_ADDRESS = MAINNET_DELEGATION_MANAGER_ADDRESS + STRATEGY_MANAGER_ADDRESS = MAINNET_STRATEGY_MANAGER_ADDRESS + KEY_REGISTRAR_ADDRESS = MAINNET_KEY_REGISTRAR_ADDRESS + CROSS_CHAIN_REGISTRY_ADDRESS = MAINNET_CROSS_CHAIN_REGISTRY_ADDRESS + RELEASE_MANAGER_ADDRESS = MAINNET_RELEASE_MANAGER_ADDRESS BN254_TABLE_CALCULATOR_ADDRESS = MAINNET_BN254_TABLE_CALCULATOR_ADDRESS ECDSA_TABLE_CALCULATOR_ADDRESS = MAINNET_ECDSA_TABLE_CALCULATOR_ADDRESS } @@ -51,44 +63,56 @@ func GetEigenLayerAddresses(contextName string, cfg *ConfigWithContextConfig) (a return ALLOCATION_MANAGER_ADDRESS, DELEGATION_MANAGER_ADDRESS, STRATEGY_MANAGER_ADDRESS, KEY_REGISTRAR_ADDRESS, CROSS_CHAIN_REGISTRY_ADDRESS, BN254_TABLE_CALCULATOR_ADDRESS, ECDSA_TABLE_CALCULATOR_ADDRESS, RELEASE_MANAGER_ADDRESS } + // Switch based on contexts chainId + chainId := cfg.Context[contextName].Chains["l1"].ChainID + // Default each address to constant if missing from discovered context allocationManager = ctx.EigenLayer.L1.AllocationManager if allocationManager == "" { - allocationManager = ALLOCATION_MANAGER_ADDRESS + allocationManager = GetAddressByChainId(chainId, MAINNET_ALLOCATION_MANAGER_ADDRESS, SEPOLIA_ALLOCATION_MANAGER_ADDRESS) } delegationManager = ctx.EigenLayer.L1.DelegationManager if delegationManager == "" { - delegationManager = DELEGATION_MANAGER_ADDRESS + delegationManager = GetAddressByChainId(chainId, MAINNET_DELEGATION_MANAGER_ADDRESS, SEPOLIA_DELEGATION_MANAGER_ADDRESS) } + strategyManager = ctx.EigenLayer.L1.StrategyManager if strategyManager == "" { - strategyManager = STRATEGY_MANAGER_ADDRESS + strategyManager = GetAddressByChainId(chainId, MAINNET_STRATEGY_MANAGER_ADDRESS, SEPOLIA_STRATEGY_MANAGER_ADDRESS) } + keyRegistrar = ctx.EigenLayer.L1.KeyRegistrar if keyRegistrar == "" { - keyRegistrar = KEY_REGISTRAR_ADDRESS + keyRegistrar = GetAddressByChainId(chainId, MAINNET_KEY_REGISTRAR_ADDRESS, SEPOLIA_KEY_REGISTRAR_ADDRESS) } crossChainRegistry = ctx.EigenLayer.L1.CrossChainRegistry if crossChainRegistry == "" { - crossChainRegistry = CROSS_CHAIN_REGISTRY_ADDRESS + crossChainRegistry = GetAddressByChainId(chainId, MAINNET_CROSS_CHAIN_REGISTRY_ADDRESS, SEPOLIA_CROSS_CHAIN_REGISTRY_ADDRESS) } bn254TableCalculator = ctx.EigenLayer.L1.BN254TableCalculator if bn254TableCalculator == "" { - bn254TableCalculator = BN254_TABLE_CALCULATOR_ADDRESS + bn254TableCalculator = GetAddressByChainId(chainId, MAINNET_BN254_TABLE_CALCULATOR_ADDRESS, SEPOLIA_BN254_TABLE_CALCULATOR_ADDRESS) } ecdsaTableCalculator = ctx.EigenLayer.L1.ECDSATableCalculator if ecdsaTableCalculator == "" { - ecdsaTableCalculator = ECDSA_TABLE_CALCULATOR_ADDRESS + ecdsaTableCalculator = GetAddressByChainId(chainId, MAINNET_ECDSA_TABLE_CALCULATOR_ADDRESS, SEPOLIA_ECDSA_TABLE_CALCULATOR_ADDRESS) } releaseManager = ctx.EigenLayer.L1.ReleaseManager if releaseManager == "" { - releaseManager = RELEASE_MANAGER_ADDRESS + releaseManager = GetAddressByChainId(chainId, MAINNET_RELEASE_MANAGER_ADDRESS, SEPOLIA_RELEASE_MANAGER_ADDRESS) } return allocationManager, delegationManager, strategyManager, keyRegistrar, crossChainRegistry, bn254TableCalculator, ecdsaTableCalculator, releaseManager } + +func GetAddressByChainId(chainId int, mainnetAddress, sepoliaAddress string) string { + if chainId == 1 { + return mainnetAddress + } + return sepoliaAddress +} diff --git a/pkg/migration/migrator.go b/pkg/migration/migrator.go index db710be1..eb4878dc 100644 --- a/pkg/migration/migrator.go +++ b/pkg/migration/migrator.go @@ -115,10 +115,11 @@ func (e *PatchEngine) Apply() error { } if userNode == nil { - parent, _ := findParent(e.User, rule.Path) + parent, idx := findParent(e.User, rule.Path) if parent == nil { continue } + base := choose(false) if base == nil { continue @@ -127,7 +128,18 @@ func (e *PatchEngine) Apply() error { if rule.Transform != nil { repl = rule.Transform(repl) } - insertNode(parent, len(parent.Content), rule.Path[len(rule.Path)-1], CloneNode(repl)) + + last := rule.Path[len(rule.Path)-1] + + if parent.Kind == yaml.MappingNode { + if idx >= 0 { + // Overwrite existing value for last key + parent.Content[idx+1] = CloneNode(repl) + } else { + // Missing node - insert once + insertNode(parent, len(parent.Content), last, CloneNode(repl)) + } + } continue } @@ -326,25 +338,40 @@ func findParent(root *yaml.Node, path []string) (*yaml.Node, int) { root = root.Content[0] } curr := root + + // walk strictly through all but the last segment for _, p := range path[:len(path)-1] { switch curr.Kind { case yaml.MappingNode: + found := false for j := 0; j < len(curr.Content)-1; j += 2 { if curr.Content[j].Value == p { // next node is value curr = curr.Content[j+1] + found = true break } } + if !found { + // missing mapping key, return nil and assert missing to caller + return nil, -1 + } case yaml.SequenceNode: - idx, _ := strconv.Atoi(p) - if idx < len(curr.Content) { - curr = curr.Content[idx] + idx, err := strconv.Atoi(p) + if err != nil || idx < 0 || idx >= len(curr.Content) { + // invalid or out-of-range index, return nil and assert missing to caller + return nil, -1 } + curr = curr.Content[idx] + default: + // cannot descend further, return nil and assert missing to caller + return nil, -1 } } - // now curr is parent of target + + // curr is parent of target target := path[len(path)-1] + // mapping parent if curr.Kind == yaml.MappingNode { for j := 0; j < len(curr.Content)-1; j += 2 { @@ -352,13 +379,21 @@ func findParent(root *yaml.Node, path []string) (*yaml.Node, int) { return curr, j } } + // parent exists but key is missing + return curr, -1 } + // sequence parent if curr.Kind == yaml.SequenceNode { - idx, _ := strconv.Atoi(target) + idx, err := strconv.Atoi(target) + if err != nil || idx < 0 || idx >= len(curr.Content) { + // parent is sequence but target index missing + return curr, -1 + } return curr, idx } - return curr, -1 + + return nil, -1 } // insertNode inserts a key/value pair from a mapping or an element from a sequence