Files
sdk/validatormanager/validator_manager_pos.go
zeekayandHanzo Dev da299df77d the corporate name is Lux Industries Inc
Lux Partners Limited is not the entity behind this work. Every place the
old name stood — copyright lines, site footers, brand config, legal and
compliance text — now names the company that actually holds it.

lux.fund is the exception and is not renamed to match: that site belongs
to Lux Assets Management LLC, a different company, and it says so.

Two kinds of line were left for a person rather than rewritten. A dated
news item recording that Lux Partners Limited was established in the Isle
of Man is a historical fact, and renaming it would falsify the record. And
a sentence asserting that the company is domiciled in the Isle of Man is a
claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle
of Man company, so swapping the name there would assert something untrue.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-28 13:05:15 -07:00

116 lines
3.4 KiB
Go

// Copyright (C) 2025, Lux Industries Inc All rights reserved.
// See the file LICENSE for licensing terms.
package validatormanager
import (
"fmt"
"math/big"
"github.com/luxfi/geth/core/types"
"github.com/luxfi/sdk/contract"
"github.com/luxfi/crypto"
)
// PoSValidatorManagerInitialize initializes contract [managerAddress] at [rpcURL], to
// manage validators on [chainID] using PoS specific settings.
func PoSValidatorManagerInitialize(
rpcURL string,
managerAddress crypto.Address,
specializedManagerAddress crypto.Address,
managerOwnerPrivateKey string,
privateKey string,
chainID [32]byte,
posParams PoSParams,
useACP99 bool,
) (*types.Transaction, *types.Receipt, error) {
if err := posParams.Verify(); err != nil {
return nil, nil, err
}
const (
defaultChurnPeriodSeconds = uint64(0) // no churn period
defaultMaximumChurnPercentage = uint8(20) // 20% of the validator set can be churned per churn period
)
if useACP99 {
if tx, receipt, err := contract.TxToMethod(
rpcURL,
false,
crypto.Address{},
privateKey,
specializedManagerAddress,
nil,
"initialize Native Token PoS manager",
ErrorSignatureToError,
"initialize((address,uint256,uint256,uint64,uint16,uint8,uint256,address,bytes32))",
NativeTokenValidatorManagerSettingsV2_0_0{
Manager: managerAddress,
MinimumStakeAmount: posParams.MinimumStakeAmount,
MaximumStakeAmount: posParams.MaximumStakeAmount,
MinimumStakeDuration: posParams.MinimumStakeDuration,
MinimumDelegationFeeBips: posParams.MinimumDelegationFee,
MaximumStakeMultiplier: posParams.MaximumStakeMultiplier,
WeightToValueFactor: posParams.WeightToValueFactor,
RewardCalculator: crypto.HexToAddress(posParams.RewardCalculatorAddress),
UptimeBlockchainID: posParams.UptimeBlockchainID,
},
); err != nil {
return tx, receipt, err
}
err := contract.TransferOwnership(
rpcURL,
managerAddress,
managerOwnerPrivateKey,
specializedManagerAddress,
)
return nil, nil, err
}
return contract.TxToMethod(
rpcURL,
false,
crypto.Address{},
privateKey,
managerAddress,
nil,
"initialize Native Token PoS manager",
ErrorSignatureToError,
"initialize(((bytes32,uint64,uint8),uint256,uint256,uint64,uint16,uint8,uint256,address,bytes32))",
NativeTokenValidatorManagerSettingsV1_0_0{
BaseSettings: ValidatorManagerSettings{
ChainID: chainID,
ChurnPeriodSeconds: defaultChurnPeriodSeconds,
MaximumChurnPercentage: defaultMaximumChurnPercentage,
},
MinimumStakeAmount: posParams.MinimumStakeAmount,
MaximumStakeAmount: posParams.MaximumStakeAmount,
MinimumStakeDuration: posParams.MinimumStakeDuration,
MinimumDelegationFeeBips: posParams.MinimumDelegationFee,
MaximumStakeMultiplier: posParams.MaximumStakeMultiplier,
WeightToValueFactor: posParams.WeightToValueFactor,
RewardCalculator: crypto.HexToAddress(posParams.RewardCalculatorAddress),
UptimeBlockchainID: posParams.UptimeBlockchainID,
},
)
}
func PoSWeightToValue(
rpcURL string,
managerAddress crypto.Address,
weight uint64,
) (*big.Int, error) {
out, err := contract.CallToMethod(
rpcURL,
managerAddress,
"weightToValue(uint64)->(uint256)",
weight,
)
if err != nil {
return nil, err
}
value, b := out[0].(*big.Int)
if !b {
return nil, fmt.Errorf("error at weightToValue, expected *big.Int, got %T", out[0])
}
return value, nil
}