Skip to content

Commit

Permalink
Add VRFOwner contract support to VRF V2 Super Script (#11414)
Browse files Browse the repository at this point in the history
* Deploy VRFOwner contract and transfer ownership of coordinator

* Minor changes

* Execute vrfOwner.SetAuthorizedSenders for all sending keys

---------

Co-authored-by: Ilja Pavlovs <[email protected]>
  • Loading branch information
kidambisrinivas and iljapavlovs authored Nov 30, 2023
1 parent 0ae8279 commit 3a58f94
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
7 changes: 4 additions & 3 deletions core/scripts/common/arbitrum.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package common

const (
ArbitrumGoerliChainID int64 = 421613
ArbitrumOneChainID int64 = 42161
ArbitrumGoerliChainID int64 = 421613
ArbitrumOneChainID int64 = 42161
ArbitrumSepoliaChainID int64 = 421614
)

// IsArbitrumChainID returns true if and only if the given chain ID corresponds
// to an Arbitrum chain (testnet or mainnet).
func IsArbitrumChainID(chainID int64) bool {
return chainID == ArbitrumGoerliChainID || chainID == ArbitrumOneChainID
return chainID == ArbitrumGoerliChainID || chainID == ArbitrumOneChainID || chainID == ArbitrumSepoliaChainID
}
55 changes: 51 additions & 4 deletions core/scripts/vrfv2/testnet/v2scripts/super_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model"
"github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util"

evmtypes "github.com/ethereum/go-ethereum/core/types"
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"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner"
"github.com/smartcontractkit/chainlink/v2/core/services/signatures/secp256k1"
)

Expand Down Expand Up @@ -50,6 +52,8 @@ func DeployUniverseViaCLI(e helpers.Environment) {

batchFulfillmentEnabled := deployCmd.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether send randomness fulfillments in batches inside one tx from CL node")

deployVRFOwner := deployCmd.Bool("deploy-vrf-owner", false, "whether to deploy VRF owner contracts")

// optional flags
fallbackWeiPerUnitLinkString := deployCmd.String("fallback-wei-per-unit-link", constants.FallbackWeiPerUnitLink.String(), "fallback wei/link ratio")
registerVRFKeyUncompressedPubKey := deployCmd.String("uncompressed-pub-key", "", "uncompressed public key")
Expand Down Expand Up @@ -98,10 +102,7 @@ func DeployUniverseViaCLI(e helpers.Environment) {

nodesMap := make(map[string]model.Node)

fundingAmount, ok := new(big.Int).SetString(*nodeSendingKeyFundingAmount, 10)
if !ok {
panic(fmt.Sprintf("failed to parse node sending key funding amount '%s'", *nodeSendingKeyFundingAmount))
}
fundingAmount := decimal.RequireFromString(*nodeSendingKeyFundingAmount).BigInt()
nodesMap[model.VRFPrimaryNodeName] = model.Node{
SendingKeys: util.MapToSendingKeyArr(vrfPrimaryNodeSendingKeys),
SendingKeyFundingAmount: fundingAmount,
Expand Down Expand Up @@ -143,6 +144,7 @@ func DeployUniverseViaCLI(e helpers.Environment) {
coordinatorConfig,
*batchFulfillmentEnabled,
nodesMap,
*deployVRFOwner,
)

vrfPrimaryNode := nodesMap[model.VRFPrimaryNodeName]
Expand All @@ -160,6 +162,7 @@ func VRFV2DeployUniverse(
coordinatorConfig CoordinatorConfigV2,
batchFulfillmentEnabled bool,
nodesMap map[string]model.Node,
deployVRFOwner bool,
) model.JobSpecs {
var compressedPkHex string
var keyHash common.Hash
Expand Down Expand Up @@ -216,6 +219,15 @@ func VRFV2DeployUniverse(
coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(contractAddresses.CoordinatorAddress, e.Ec)
helpers.PanicErr(err)

var vrfOwnerAddress common.Address
if deployVRFOwner {
var tx *evmtypes.Transaction
fmt.Printf("\nDeploying VRF Owner for coordinator %v\n", contractAddresses.CoordinatorAddress)
vrfOwnerAddress, tx, _, err = vrf_owner.DeployVRFOwner(e.Owner, e.Ec, contractAddresses.CoordinatorAddress)
helpers.PanicErr(err)
helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID)
}

if contractAddresses.BatchCoordinatorAddress.String() == "0x0000000000000000000000000000000000000000" {
fmt.Println("\nDeploying Batch Coordinator...")
contractAddresses.BatchCoordinatorAddress = DeployBatchCoordinatorV2(e, contractAddresses.CoordinatorAddress)
Expand Down Expand Up @@ -273,6 +285,28 @@ func VRFV2DeployUniverse(
helpers.PanicErr(err)
fmt.Printf("Subscription %+v\n", s)

if deployVRFOwner {
// VRF Owner
vrfOwner, err := vrf_owner.NewVRFOwner(vrfOwnerAddress, e.Ec)
helpers.PanicErr(err)
var authorizedSendersSlice []common.Address
for _, s := range nodesMap[model.VRFPrimaryNodeName].SendingKeys {
authorizedSendersSlice = append(authorizedSendersSlice, common.HexToAddress(s.Address))
}
fmt.Printf("\nSetting authorised senders for VRF Owner: %v, Authorised senders %v\n", vrfOwnerAddress.String(), authorizedSendersSlice)
tx, err := vrfOwner.SetAuthorizedSenders(e.Owner, authorizedSendersSlice)
helpers.PanicErr(err)
helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "vrf owner set authorized senders")
fmt.Printf("\nTransfering ownership of coordinator: %v, VRF Owner %v\n", contractAddresses.CoordinatorAddress, vrfOwnerAddress.String())
tx, err = coordinator.TransferOwnership(e.Owner, vrfOwnerAddress)
helpers.PanicErr(err)
helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "transfer ownership to", vrfOwnerAddress.String())
fmt.Printf("\nAccepting ownership of coordinator: %v, VRF Owner %v\n", contractAddresses.CoordinatorAddress, vrfOwnerAddress.String())
tx, err = vrfOwner.AcceptVRFOwnership(e.Owner)
helpers.PanicErr(err)
helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "vrf owner accepting vrf ownership")
}

formattedVrfPrimaryJobSpec := fmt.Sprintf(
jobs.VRFV2JobFormatted,
contractAddresses.CoordinatorAddress, //coordinatorAddress
Expand All @@ -293,6 +327,12 @@ func VRFV2DeployUniverse(
contractAddresses.CoordinatorAddress,
contractAddresses.CoordinatorAddress,
)
if deployVRFOwner {
formattedVrfPrimaryJobSpec = strings.Replace(formattedVrfPrimaryJobSpec,
"minIncomingConfirmations",
fmt.Sprintf("vrfOwnerAddress = \"%s\"\nminIncomingConfirmations", vrfOwnerAddress.Hex()),
1)
}

formattedVrfBackupJobSpec := fmt.Sprintf(
jobs.VRFV2JobFormatted,
Expand All @@ -314,6 +354,12 @@ func VRFV2DeployUniverse(
contractAddresses.CoordinatorAddress,
contractAddresses.CoordinatorAddress,
)
if deployVRFOwner {
formattedVrfBackupJobSpec = strings.Replace(formattedVrfBackupJobSpec,
"minIncomingConfirmations",
fmt.Sprintf("vrfOwnerAddress = \"%s\"\nminIncomingConfirmations", vrfOwnerAddress.Hex()),
1)
}

formattedBHSJobSpec := fmt.Sprintf(
jobs.BHSJobFormatted,
Expand Down Expand Up @@ -353,6 +399,7 @@ func VRFV2DeployUniverse(
"\nVRF Coordinator Address:", contractAddresses.CoordinatorAddress,
"\nBatch VRF Coordinator Address:", contractAddresses.BatchCoordinatorAddress,
"\nVRF Consumer Address:", consumerAddress,
"\nVRF Owner Address:", vrfOwnerAddress,
"\nVRF Subscription Id:", subID,
"\nVRF Subscription Balance:", *subscriptionBalanceJuels,
"\nPossible VRF Request command: ",
Expand Down
1 change: 0 additions & 1 deletion core/scripts/vrfv2/testnet/v2scripts/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func EoaFundSubscription(e helpers.Environment, coordinator vrf_coordinator_v2.V
fmt.Println("Initial account balance:", bal, e.Owner.From.String(), "Funding amount:", amount.String())
b, err := utils.ABIEncode(`[{"type":"uint64"}]`, subID)
helpers.PanicErr(err)
e.Owner.GasLimit = 500000
tx, err := linkToken.TransferAndCall(e.Owner, coordinator.Address(), amount, b)
helpers.PanicErr(err)
helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, fmt.Sprintf("sub ID: %d", subID))
Expand Down

0 comments on commit 3a58f94

Please sign in to comment.