diff --git a/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go index f5e37005690..23ad8e1374b 100644 --- a/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go +++ b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go @@ -5,10 +5,6 @@ import ( "encoding/hex" "flag" "fmt" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" "math/big" "os" "strings" @@ -18,6 +14,11 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/shopspring/decimal" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" + helpers "github.com/smartcontractkit/chainlink/core/scripts/common" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" @@ -37,12 +38,12 @@ func DeployUniverseViaCLI(e helpers.Environment) { deployCmd := flag.NewFlagSet("deploy-universe", flag.ExitOnError) // required flags - linkAddress := *deployCmd.String("link-address", "", "address of link token") - linkEthAddress := *deployCmd.String("link-eth-feed", "", "address of link eth feed") - bhsContractAddressString := *deployCmd.String("bhs-address", "", "address of BHS contract") - batchBHSAddressString := *deployCmd.String("batch-bhs-address", "", "address of Batch BHS contract") - coordinatorAddressString := *deployCmd.String("coordinator-address", "", "address of VRF Coordinator contract") - batchCoordinatorAddressString := *deployCmd.String("batch-coordinator-address", "", "address Batch VRF Coordinator contract") + linkAddress := deployCmd.String("link-address", "", "address of link token") + linkEthAddress := deployCmd.String("link-eth-feed", "", "address of link eth feed") + bhsContractAddressString := deployCmd.String("bhs-address", "", "address of BHS contract") + batchBHSAddressString := deployCmd.String("batch-bhs-address", "", "address of Batch BHS contract") + coordinatorAddressString := deployCmd.String("coordinator-address", "", "address of VRF Coordinator contract") + batchCoordinatorAddressString := deployCmd.String("batch-coordinator-address", "", "address Batch VRF Coordinator contract") subscriptionBalanceJuelsString := deployCmd.String("subscription-balance", constants.SubscriptionBalanceJuels, "amount to fund subscription") nodeSendingKeyFundingAmount := deployCmd.String("sending-key-funding-amount", constants.NodeSendingKeyFundingAmount, "CL node sending key funding amount") @@ -87,7 +88,10 @@ func DeployUniverseViaCLI(e helpers.Environment) { ReqsForTier5: big.NewInt(*reqsForTier5), } - vrfPrimaryNodeSendingKeys := strings.Split(*vrfPrimaryNodeSendingKeysString, ",") + var vrfPrimaryNodeSendingKeys []string + if len(*vrfPrimaryNodeSendingKeysString) > 0 { + vrfPrimaryNodeSendingKeys = strings.Split(*vrfPrimaryNodeSendingKeysString, ",") + } nodesMap := make(map[string]model.Node) @@ -100,14 +104,14 @@ func DeployUniverseViaCLI(e helpers.Environment) { SendingKeyFundingAmount: fundingAmount, } - bhsContractAddress := common.HexToAddress(bhsContractAddressString) - batchBHSAddress := common.HexToAddress(batchBHSAddressString) - coordinatorAddress := common.HexToAddress(coordinatorAddressString) - batchCoordinatorAddress := common.HexToAddress(batchCoordinatorAddressString) + bhsContractAddress := common.HexToAddress(*bhsContractAddressString) + batchBHSAddress := common.HexToAddress(*batchBHSAddressString) + coordinatorAddress := common.HexToAddress(*coordinatorAddressString) + batchCoordinatorAddress := common.HexToAddress(*batchCoordinatorAddressString) contractAddresses := model.ContractAddresses{ - LinkAddress: linkAddress, - LinkEthAddress: linkEthAddress, + LinkAddress: *linkAddress, + LinkEthAddress: *linkEthAddress, BhsContractAddress: bhsContractAddress, BatchBHSAddress: batchBHSAddress, CoordinatorAddress: coordinatorAddress, @@ -149,29 +153,32 @@ func VRFV2DeployUniverse( batchFulfillmentEnabled bool, nodesMap map[string]model.Node, ) model.JobSpecs { - - // Put key in ECDSA format - if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") { - *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) - } - - // Generate compressed public key and key hash - pubBytes, err := hex.DecodeString(*registerKeyUncompressedPubKey) - helpers.PanicErr(err) - pk, err := crypto.UnmarshalPubkey(pubBytes) - helpers.PanicErr(err) - var pkBytes []byte - if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { - pkBytes = append(pk.X.Bytes(), 1) - } else { - pkBytes = append(pk.X.Bytes(), 0) + var compressedPkHex string + var keyHash common.Hash + if len(*registerKeyUncompressedPubKey) > 0 { + // Put key in ECDSA format + if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") { + *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) + } + + // Generate compressed public key and key hash + pubBytes, err := hex.DecodeString(*registerKeyUncompressedPubKey) + helpers.PanicErr(err) + pk, err := crypto.UnmarshalPubkey(pubBytes) + helpers.PanicErr(err) + var pkBytes []byte + if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { + pkBytes = append(pk.X.Bytes(), 1) + } else { + pkBytes = append(pk.X.Bytes(), 0) + } + var newPK secp256k1.PublicKey + copy(newPK[:], pkBytes) + + compressedPkHex = hexutil.Encode(pkBytes) + keyHash, err = newPK.Hash() + helpers.PanicErr(err) } - var newPK secp256k1.PublicKey - copy(newPK[:], pkBytes) - - compressedPkHex := hexutil.Encode(pkBytes) - keyHash, err := newPK.Hash() - helpers.PanicErr(err) if len(contractAddresses.LinkAddress) == 0 { fmt.Println("\nDeploying LINK Token...") @@ -268,7 +275,13 @@ func VRFV2DeployUniverse( e.ChainID, //evmChainID strings.Join(util.MapToAddressArr(nodesMap[model.VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[model.VRFPrimaryNodeName].SendingKeys[0].Address, + func() string { + if keys := nodesMap[model.VRFPrimaryNodeName].SendingKeys; len(keys) > 0 { + return keys[0].Address + } else { + return common.HexToAddress("0x0").String() + } + }(), contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, ) @@ -283,7 +296,13 @@ func VRFV2DeployUniverse( e.ChainID, //evmChainID strings.Join(util.MapToAddressArr(nodesMap[model.VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[model.VRFPrimaryNodeName].SendingKeys[0], + func() string { + if keys := nodesMap[model.VRFPrimaryNodeName].SendingKeys; len(keys) > 0 { + return keys[0].Address + } else { + return common.HexToAddress("0x0").String() + } + }(), contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, )