mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
102 lines
2.8 KiB
Go
102 lines
2.8 KiB
Go
// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
package validatormanager
|
|
|
|
import (
|
|
_ "embed"
|
|
"math/big"
|
|
|
|
"github.com/luxfi/cli/v2/pkg/contract"
|
|
"github.com/luxfi/cli/v2/sdk/evm"
|
|
validatorManagerSDK "github.com/luxfi/cli/v2/sdk/validatormanager"
|
|
"github.com/luxfi/geth/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
)
|
|
|
|
func SetupValidatorProxyImplementation(
|
|
rpcURL string,
|
|
proxyManagerPrivateKey string,
|
|
validatorManager common.Address,
|
|
) (*types.Transaction, *types.Receipt, error) {
|
|
return contract.TxToMethod(
|
|
rpcURL,
|
|
false,
|
|
common.Address{},
|
|
proxyManagerPrivateKey,
|
|
common.HexToAddress(validatorManagerSDK.ValidatorProxyAdminContractAddress),
|
|
big.NewInt(0),
|
|
"set validator proxy implementation",
|
|
validatorManagerSDK.ErrorSignatureToError,
|
|
"upgrade(address,address)",
|
|
common.HexToAddress(validatorManagerSDK.ValidatorProxyContractAddress),
|
|
validatorManager,
|
|
)
|
|
}
|
|
|
|
func GetValidatorProxyImplementation(
|
|
rpcURL string,
|
|
) (common.Address, error) {
|
|
out, err := contract.CallToMethod(
|
|
rpcURL,
|
|
common.HexToAddress(validatorManagerSDK.ValidatorProxyAdminContractAddress),
|
|
"getProxyImplementation(address)->(address)",
|
|
common.HexToAddress(validatorManagerSDK.ValidatorProxyContractAddress),
|
|
)
|
|
if err != nil {
|
|
return common.Address{}, err
|
|
}
|
|
return contract.GetSmartContractCallResult[common.Address]("getProxyImplementation", out)
|
|
}
|
|
|
|
func ValidatorProxyHasImplementationSet(
|
|
rpcURL string,
|
|
) (bool, error) {
|
|
validatorManagerAddress, err := GetValidatorProxyImplementation(rpcURL)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
client, err := evm.GetClient(rpcURL)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return client.ContractAlreadyDeployed(
|
|
validatorManagerAddress.Hex(),
|
|
)
|
|
}
|
|
|
|
func GetSpecializedValidatorProxyImplementation(
|
|
rpcURL string,
|
|
) (common.Address, error) {
|
|
out, err := contract.CallToMethod(
|
|
rpcURL,
|
|
common.HexToAddress(validatorManagerSDK.SpecializationProxyAdminContractAddress),
|
|
"getProxyImplementation(address)->(address)",
|
|
common.HexToAddress(validatorManagerSDK.SpecializationProxyContractAddress),
|
|
)
|
|
if err != nil {
|
|
return common.Address{}, err
|
|
}
|
|
return contract.GetSmartContractCallResult[common.Address]("getProxyImplementation", out)
|
|
}
|
|
|
|
func SetupSpecializationProxyImplementation(
|
|
rpcURL string,
|
|
proxyManagerPrivateKey string,
|
|
validatorManager common.Address,
|
|
) (*types.Transaction, *types.Receipt, error) {
|
|
return contract.TxToMethod(
|
|
rpcURL,
|
|
false,
|
|
common.Address{},
|
|
proxyManagerPrivateKey,
|
|
common.HexToAddress(validatorManagerSDK.SpecializationProxyAdminContractAddress),
|
|
big.NewInt(0),
|
|
"set specialization proxy implementation",
|
|
validatorManagerSDK.ErrorSignatureToError,
|
|
"upgrade(address,address)",
|
|
common.HexToAddress(validatorManagerSDK.SpecializationProxyContractAddress),
|
|
validatorManager,
|
|
)
|
|
}
|