From e499700c67cd352b0456f33f4e917766da1cd15a Mon Sep 17 00:00:00 2001 From: Ilja Pavlovs Date: Tue, 10 Oct 2023 13:12:22 +0300 Subject: [PATCH] VRF-586: add env setup script for VRF V2 Plus (#10892) * VRF-586: add env setup script for VRF V2 Plus * VRF-586: deleting debug logs --- .../scripts/common/vrf/constants/constants.go | 34 ++ .../docker/db/create-multiple-databases.sh | 0 .../vrf}/docker/docker-compose.yml | 4 +- .../testnet => common/vrf}/docker/sample.env | 0 .../vrf}/docker/secrets/apicredentials | 0 .../vrf}/docker/secrets/password.txt | 0 .../vrf}/docker/toml-config/base.toml | 0 .../vrf}/docker/toml-config/bhf.toml | 0 .../vrf}/docker/toml-config/bhs.toml | 0 .../vrf}/docker/toml-config/rpc-nodes.toml | 0 .../vrf}/docker/toml-config/secrets.toml | 0 .../toml-config/vrf-backup-other-chains.toml | 2 +- .../vrf}/docker/toml-config/vrf-backup.toml | 0 .../vrf}/docker/toml-config/vrf-primary.toml | 2 +- .../wait-for-others/docker-wait-for-it.sh | 0 .../wait-for-others/docker-wait-for-others.sh | 0 .../testnet => common/vrf}/jobs/jobs.go | 42 +- core/scripts/common/vrf/model/model.go | 46 ++ .../vrf}/setup-envs/README.md | 22 +- .../testnet => common/vrf}/setup-envs/main.go | 187 +++++--- core/scripts/common/vrf/util/util.go | 22 + .../vrfv2/testnet/constants/constants.go | 28 -- core/scripts/vrfv2/testnet/main.go | 38 +- .../{scripts => v2scripts}/super_scripts.go | 121 ++--- .../testnet/{scripts => v2scripts}/util.go | 4 +- core/scripts/vrfv2plus/testnet/main.go | 45 +- .../{ => v2plusscripts}/super_scripts.go | 432 +++++++++++------- .../testnet/{ => v2plusscripts}/util.go | 66 ++- 28 files changed, 665 insertions(+), 430 deletions(-) create mode 100644 core/scripts/common/vrf/constants/constants.go rename core/scripts/{vrfv2/testnet => common/vrf}/docker/db/create-multiple-databases.sh (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/docker-compose.yml (98%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/sample.env (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/secrets/apicredentials (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/secrets/password.txt (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/base.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/bhf.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/bhs.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/rpc-nodes.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/secrets.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/vrf-backup-other-chains.toml (81%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/vrf-backup.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/vrf-primary.toml (76%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/wait-for-others/docker-wait-for-it.sh (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/wait-for-others/docker-wait-for-others.sh (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/jobs/jobs.go (55%) create mode 100644 core/scripts/common/vrf/model/model.go rename core/scripts/{vrfv2/testnet => common/vrf}/setup-envs/README.md (72%) rename core/scripts/{vrfv2/testnet => common/vrf}/setup-envs/main.go (72%) create mode 100644 core/scripts/common/vrf/util/util.go delete mode 100644 core/scripts/vrfv2/testnet/constants/constants.go rename core/scripts/vrfv2/testnet/{scripts => v2scripts}/super_scripts.go (83%) rename core/scripts/vrfv2/testnet/{scripts => v2scripts}/util.go (99%) rename core/scripts/vrfv2plus/testnet/{ => v2plusscripts}/super_scripts.go (61%) rename core/scripts/vrfv2plus/testnet/{ => v2plusscripts}/util.go (79%) diff --git a/core/scripts/common/vrf/constants/constants.go b/core/scripts/common/vrf/constants/constants.go new file mode 100644 index 00000000000..b21f6b0b323 --- /dev/null +++ b/core/scripts/common/vrf/constants/constants.go @@ -0,0 +1,34 @@ +package constants + +import ( + "math/big" +) + +var ( + SubscriptionBalanceJuels = "1e19" + SubscriptionBalanceNativeWei = "1e18" + + // optional flags + FallbackWeiPerUnitLink = big.NewInt(6e16) + BatchFulfillmentEnabled = true + MinConfs = 3 + NodeSendingKeyFundingAmount = "1e17" + MaxGasLimit = int64(2.5e6) + StalenessSeconds = int64(86400) + GasAfterPayment = int64(33285) + + //vrfv2 + FlatFeeTier1 = int64(500) + FlatFeeTier2 = int64(500) + FlatFeeTier3 = int64(500) + FlatFeeTier4 = int64(500) + FlatFeeTier5 = int64(500) + ReqsForTier2 = int64(0) + ReqsForTier3 = int64(0) + ReqsForTier4 = int64(0) + ReqsForTier5 = int64(0) + + //vrfv2plus + FlatFeeLinkPPM = int64(500) + FlatFeeNativePPM = int64(500) +) diff --git a/core/scripts/vrfv2/testnet/docker/db/create-multiple-databases.sh b/core/scripts/common/vrf/docker/db/create-multiple-databases.sh similarity index 100% rename from core/scripts/vrfv2/testnet/docker/db/create-multiple-databases.sh rename to core/scripts/common/vrf/docker/db/create-multiple-databases.sh diff --git a/core/scripts/vrfv2/testnet/docker/docker-compose.yml b/core/scripts/common/vrf/docker/docker-compose.yml similarity index 98% rename from core/scripts/vrfv2/testnet/docker/docker-compose.yml rename to core/scripts/common/vrf/docker/docker-compose.yml index d31c50f3463..5c14c4670d8 100644 --- a/core/scripts/vrfv2/testnet/docker/docker-compose.yml +++ b/core/scripts/common/vrf/docker/docker-compose.yml @@ -132,9 +132,9 @@ services: secrets: node_password: - file: ./secrets/password.txt + file: secrets/password.txt apicredentials: - file: ./secrets/apicredentials + file: secrets/apicredentials volumes: docker-compose-db: diff --git a/core/scripts/vrfv2/testnet/docker/sample.env b/core/scripts/common/vrf/docker/sample.env similarity index 100% rename from core/scripts/vrfv2/testnet/docker/sample.env rename to core/scripts/common/vrf/docker/sample.env diff --git a/core/scripts/vrfv2/testnet/docker/secrets/apicredentials b/core/scripts/common/vrf/docker/secrets/apicredentials similarity index 100% rename from core/scripts/vrfv2/testnet/docker/secrets/apicredentials rename to core/scripts/common/vrf/docker/secrets/apicredentials diff --git a/core/scripts/vrfv2/testnet/docker/secrets/password.txt b/core/scripts/common/vrf/docker/secrets/password.txt similarity index 100% rename from core/scripts/vrfv2/testnet/docker/secrets/password.txt rename to core/scripts/common/vrf/docker/secrets/password.txt diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/base.toml b/core/scripts/common/vrf/docker/toml-config/base.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/base.toml rename to core/scripts/common/vrf/docker/toml-config/base.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/bhf.toml b/core/scripts/common/vrf/docker/toml-config/bhf.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/bhf.toml rename to core/scripts/common/vrf/docker/toml-config/bhf.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/bhs.toml b/core/scripts/common/vrf/docker/toml-config/bhs.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/bhs.toml rename to core/scripts/common/vrf/docker/toml-config/bhs.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/rpc-nodes.toml b/core/scripts/common/vrf/docker/toml-config/rpc-nodes.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/rpc-nodes.toml rename to core/scripts/common/vrf/docker/toml-config/rpc-nodes.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/secrets.toml b/core/scripts/common/vrf/docker/toml-config/secrets.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/secrets.toml rename to core/scripts/common/vrf/docker/toml-config/secrets.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup-other-chains.toml b/core/scripts/common/vrf/docker/toml-config/vrf-backup-other-chains.toml similarity index 81% rename from core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup-other-chains.toml rename to core/scripts/common/vrf/docker/toml-config/vrf-backup-other-chains.toml index a39c6b15c57..ba71abe92fc 100644 --- a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup-other-chains.toml +++ b/core/scripts/common/vrf/docker/toml-config/vrf-backup-other-chains.toml @@ -1,5 +1,5 @@ [Feature] -LogPoller = false #VRF V2 uses Log Broadcast3er instead of Log poller +LogPoller = false #VRF V2 uses Log Broadcaster instead of Log poller [[EVM]] ChainID = '11155111' diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup.toml b/core/scripts/common/vrf/docker/toml-config/vrf-backup.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup.toml rename to core/scripts/common/vrf/docker/toml-config/vrf-backup.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-primary.toml b/core/scripts/common/vrf/docker/toml-config/vrf-primary.toml similarity index 76% rename from core/scripts/vrfv2/testnet/docker/toml-config/vrf-primary.toml rename to core/scripts/common/vrf/docker/toml-config/vrf-primary.toml index 67cd33659fb..6cb78789b23 100644 --- a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-primary.toml +++ b/core/scripts/common/vrf/docker/toml-config/vrf-primary.toml @@ -1,5 +1,5 @@ [Feature] -LogPoller = false #VRF V2 uses Log Broadcast3er instead of Log poller +LogPoller = false #VRF V2 uses Log Broadcaster instead of Log poller [[EVM]] ChainID = '11155111' diff --git a/core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-it.sh b/core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-it.sh similarity index 100% rename from core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-it.sh rename to core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-it.sh diff --git a/core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-others.sh b/core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-others.sh similarity index 100% rename from core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-others.sh rename to core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-others.sh diff --git a/core/scripts/vrfv2/testnet/jobs/jobs.go b/core/scripts/common/vrf/jobs/jobs.go similarity index 55% rename from core/scripts/vrfv2/testnet/jobs/jobs.go rename to core/scripts/common/vrf/jobs/jobs.go index 8ff0195bfa8..674cca175c8 100644 --- a/core/scripts/vrfv2/testnet/jobs/jobs.go +++ b/core/scripts/common/vrf/jobs/jobs.go @@ -1,7 +1,7 @@ package jobs var ( - VRFJobFormatted = `type = "vrf" + VRFV2JobFormatted = `type = "vrf" name = "vrf_v2" schemaVersion = 1 coordinatorAddress = "%s" @@ -38,6 +38,46 @@ simulate [type=ethcall decode_log->vrf->estimate_gas->simulate """` + VRFV2PlusJobFormatted = ` +type = "vrf" +name = "vrf_v2_plus" +schemaVersion = 1 +coordinatorAddress = "%s" +batchCoordinatorAddress = "%s" +batchFulfillmentEnabled = %t +batchFulfillmentGasMultiplier = 1.1 +publicKey = "%s" +minIncomingConfirmations = %d +evmChainID = "%d" +fromAddresses = ["%s"] +pollPeriod = "300ms" +requestTimeout = "30m0s" +observationSource = """ +decode_log [type=ethabidecodelog + abi="RandomWordsRequested(bytes32 indexed keyHash,uint256 requestId,uint256 preSeed,uint256 indexed subId,uint16 minimumRequestConfirmations,uint32 callbackGasLimit,uint32 numWords,bytes extraArgs,address indexed sender)" + data="$(jobRun.logData)" + topics="$(jobRun.logTopics)"] +generate_proof [type=vrfv2plus + publicKey="$(jobSpec.publicKey)" + requestBlockHash="$(jobRun.logBlockHash)" + requestBlockNumber="$(jobRun.logBlockNumber)" + topics="$(jobRun.logTopics)"] +estimate_gas [type=estimategaslimit + to="%s" + multiplier="1.1" + data="$(generate_proof.output)"] +simulate_fulfillment [type=ethcall + from="%s" + to="%s" + gas="$(estimate_gas)" + gasPrice="$(jobSpec.maxGasPrice)" + extractRevertReason=true + contract="%s" + data="$(generate_proof.output)"] +decode_log->generate_proof->estimate_gas->simulate_fulfillment +""" +` + BHSJobFormatted = `type = "blockhashstore" schemaVersion = 1 name = "blockhashstore" diff --git a/core/scripts/common/vrf/model/model.go b/core/scripts/common/vrf/model/model.go new file mode 100644 index 00000000000..bd0e3bbe364 --- /dev/null +++ b/core/scripts/common/vrf/model/model.go @@ -0,0 +1,46 @@ +package model + +import ( + "github.com/ethereum/go-ethereum/common" + "math/big" +) + +var ( + VRFPrimaryNodeName = "vrf-primary-node" + VRFBackupNodeName = "vrf-backup-node" + BHSNodeName = "bhs-node" + BHSBackupNodeName = "bhs-backup-node" + BHFNodeName = "bhf-node" +) + +type Node struct { + URL string + CredsFile string + SendingKeys []SendingKey + NumberOfSendingKeysToCreate int + SendingKeyFundingAmount *big.Int + VrfKeys []string + jobSpec string +} + +type SendingKey struct { + Address string + BalanceEth *big.Int +} + +type JobSpecs struct { + VRFPrimaryNode string + VRFBackupyNode string + BHSNode string + BHSBackupNode string + BHFNode string +} + +type ContractAddresses struct { + LinkAddress string + LinkEthAddress string + BhsContractAddress common.Address + BatchBHSAddress common.Address + CoordinatorAddress common.Address + BatchCoordinatorAddress common.Address +} diff --git a/core/scripts/vrfv2/testnet/setup-envs/README.md b/core/scripts/common/vrf/setup-envs/README.md similarity index 72% rename from core/scripts/vrfv2/testnet/setup-envs/README.md rename to core/scripts/common/vrf/setup-envs/README.md index a36e3829c43..33515338a24 100644 --- a/core/scripts/vrfv2/testnet/setup-envs/README.md +++ b/core/scripts/common/vrf/setup-envs/README.md @@ -4,8 +4,8 @@ * Currently possible to fund all nodes with one amount of native tokens ## Commands: 1. If using Docker Compose - 1. create `.env` file in `core/scripts/vrfv2/testnet/docker` (can use `sample.env` file as an example) - 2. go to `core/scripts/vrfv2/testnet/docker` folder and start containers - `docker compose up` + 1. create `.env` file in `core/scripts/common/vrf/docker` (can use `sample.env` file as an example) + 2. go to `core/scripts/common/vrf/docker` folder and start containers - `docker compose up` 2. Update [rpc-nodes.toml](..%2Fdocker%2Ftoml-config%2Frpc-nodes.toml) with relevant RPC nodes 3. Create files with credentials desirably outside `chainlink` repo (just not to push creds accidentally). Populate the files with relevant credentials for the nodes 4. Ensure that following env variables are set @@ -14,9 +14,10 @@ export ETH_URL= export ETH_CHAIN_ID= export ACCOUNT_KEY= ``` -5. execute from `core/scripts/vrfv2/testnet/setup-envs` folder +5. execute from `core/scripts/common/vrf/setup-envs` folder ``` go run . \ +--vrf-version="v2plus" \ --vrf-primary-node-url=http://localhost:6610 \ --vrf-primary-creds-file \ --vrf-backup-node-url=http://localhost:6611 \ @@ -27,13 +28,14 @@ go run . \ --bhs-bk-creds-file \ --bhf-node-url=http://localhost:6614 \ --bhf-creds-file \ ---deploy-contracts true \ ---batch-fulfillment-enabled true \ ---min-confs 1 \ ---num-eth-keys 5 \ ---num-vrf-keys 1 \ ---sending-key-funding-amount 100000000000000000 - +--deploy-contracts-and-create-jobs="true" \ +--subscription-balance="1e19" \ +--subscription-balance-native="1e18" \ +--batch-fulfillment-enabled="true" \ +--min-confs=3 \ +--num-eth-keys=1 \ +--num-vrf-keys=1 \ +--sending-key-funding-amount="1e17" ``` Optional parameters - will not be deployed if specified (NOT WORKING YET) diff --git a/core/scripts/vrfv2/testnet/setup-envs/main.go b/core/scripts/common/vrf/setup-envs/main.go similarity index 72% rename from core/scripts/vrfv2/testnet/setup-envs/main.go rename to core/scripts/common/vrf/setup-envs/main.go index 9e6edf725e5..8a7b1c8b439 100644 --- a/core/scripts/vrfv2/testnet/setup-envs/main.go +++ b/core/scripts/common/vrf/setup-envs/main.go @@ -6,11 +6,15 @@ import ( "flag" "fmt" "github.com/ethereum/go-ethereum/common" + "github.com/shopspring/decimal" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/constants" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/scripts" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/v2scripts" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2plus/testnet/v2plusscripts" clcmd "github.com/smartcontractkit/chainlink/v2/core/cmd" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" "github.com/smartcontractkit/chainlink/v2/core/web/presenters" "github.com/urfave/cli" "io" @@ -54,7 +58,7 @@ func main() { bhsNodeURL := flag.String("bhs-node-url", "", "remote node URL") bhsBackupNodeURL := flag.String("bhs-backup-node-url", "", "remote node URL") bhfNodeURL := flag.String("bhf-node-url", "", "remote node URL") - nodeSendingKeyFundingAmount := flag.Int64("sending-key-funding-amount", constants.NodeSendingKeyFundingAmountGwei, "remote node URL") + nodeSendingKeyFundingAmount := flag.String("sending-key-funding-amount", constants.NodeSendingKeyFundingAmount, "sending key funding amount") vrfPrimaryCredsFile := flag.String("vrf-primary-creds-file", "", "Creds to authenticate to the node") vrfBackupCredsFile := flag.String("vrf-bk-creds-file", "", "Creds to authenticate to the node") @@ -65,12 +69,15 @@ func main() { numEthKeys := flag.Int("num-eth-keys", 5, "Number of eth keys to create") maxGasPriceGwei := flag.Int("max-gas-price-gwei", -1, "Max gas price gwei of the eth keys") numVRFKeys := flag.Int("num-vrf-keys", 1, "Number of vrf keys to create") + batchFulfillmentEnabled := flag.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether to enable batch fulfillment on Cl node") - deployContracts := flag.Bool("deploy-contracts", true, "whether to deploy contracts and create jobs") + vrfVersion := flag.String("vrf-version", "v2", "VRF version to use") + deployContractsAndCreateJobs := flag.Bool("deploy-contracts-and-create-jobs", false, "whether to deploy contracts and create jobs") - batchFulfillmentEnabled := flag.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether to enable batch fulfillment on Cl node") - minConfs := flag.Int("min-confs", constants.MinConfs, "minimum confirmations") + subscriptionBalanceJuelsString := flag.String("subscription-balance", constants.SubscriptionBalanceJuels, "amount to fund subscription with Link token (Juels)") + subscriptionBalanceNativeWeiString := flag.String("subscription-balance-native", constants.SubscriptionBalanceNativeWei, "amount to fund subscription with native token (Wei)") + minConfs := flag.Int("min-confs", constants.MinConfs, "minimum confirmations") linkAddress := flag.String("link-address", "", "address of link token") linkEthAddress := flag.String("link-eth-feed", "", "address of link eth feed") bhsContractAddressString := flag.String("bhs-address", "", "address of BHS contract") @@ -80,41 +87,50 @@ func main() { e := helpers.SetupEnv(false) flag.Parse() - nodesMap := make(map[string]scripts.Node) + nodesMap := make(map[string]model.Node) + + if *vrfVersion != "v2" && *vrfVersion != "v2plus" { + panic(fmt.Sprintf("Invalid VRF Version `%s`. Only `v2` and `v2plus` are supported", *vrfVersion)) + } + fmt.Println("Using VRF Version:", *vrfVersion) + + fundingAmount := decimal.RequireFromString(*nodeSendingKeyFundingAmount).BigInt() + subscriptionBalanceJuels := decimal.RequireFromString(*subscriptionBalanceJuelsString).BigInt() + subscriptionBalanceNativeWei := decimal.RequireFromString(*subscriptionBalanceNativeWeiString).BigInt() if *vrfPrimaryNodeURL != "" { - nodesMap[scripts.VRFPrimaryNodeName] = scripts.Node{ + nodesMap[model.VRFPrimaryNodeName] = model.Node{ URL: *vrfPrimaryNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *vrfPrimaryCredsFile, } } if *vrfBackupNodeURL != "" { - nodesMap[scripts.VRFBackupNodeName] = scripts.Node{ + nodesMap[model.VRFBackupNodeName] = model.Node{ URL: *vrfBackupNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *vrfBackupCredsFile, } } if *bhsNodeURL != "" { - nodesMap[scripts.BHSNodeName] = scripts.Node{ + nodesMap[model.BHSNodeName] = model.Node{ URL: *bhsNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *bhsCredsFile, } } if *bhsBackupNodeURL != "" { - nodesMap[scripts.BHSBackupNodeName] = scripts.Node{ + nodesMap[model.BHSBackupNodeName] = model.Node{ URL: *bhsBackupNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *bhsBackupCredsFile, } } if *bhfNodeURL != "" { - nodesMap[scripts.BHFNodeName] = scripts.Node{ + nodesMap[model.BHFNodeName] = model.Node{ URL: *bhfNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *bhfCredsFile, } } @@ -124,14 +140,14 @@ func main() { client, app := connectToNode(&node.URL, output, node.CredsFile) ethKeys := createETHKeysIfNeeded(client, app, output, numEthKeys, &node.URL, maxGasPriceGwei) - if key == scripts.VRFPrimaryNodeName { + if key == model.VRFPrimaryNodeName { vrfKeys := createVRFKeyIfNeeded(client, app, output, numVRFKeys, &node.URL) node.VrfKeys = mapVrfKeysToStringArr(vrfKeys) printVRFKeyData(vrfKeys) exportVRFKey(client, app, vrfKeys[0], output) } - if key == scripts.VRFBackupNodeName { + if key == model.VRFBackupNodeName { vrfKeys := getVRFKeys(client, app, output) node.VrfKeys = mapVrfKeysToStringArr(vrfKeys) } @@ -141,23 +157,11 @@ func main() { fundNodesIfNeeded(node, key, e) nodesMap[key] = node } - importVRFKeyToNodeIfSet(vrfBackupNodeURL, nodesMap, output, nodesMap[scripts.VRFBackupNodeName].CredsFile) - fmt.Println() + importVRFKeyToNodeIfSet(vrfBackupNodeURL, nodesMap, output, nodesMap[model.VRFBackupNodeName].CredsFile) - if *deployContracts { - feeConfig := vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{ - FulfillmentFlatFeeLinkPPMTier1: uint32(constants.FlatFeeTier1), - FulfillmentFlatFeeLinkPPMTier2: uint32(constants.FlatFeeTier2), - FulfillmentFlatFeeLinkPPMTier3: uint32(constants.FlatFeeTier3), - FulfillmentFlatFeeLinkPPMTier4: uint32(constants.FlatFeeTier4), - FulfillmentFlatFeeLinkPPMTier5: uint32(constants.FlatFeeTier5), - ReqsForTier2: big.NewInt(constants.ReqsForTier2), - ReqsForTier3: big.NewInt(constants.ReqsForTier3), - ReqsForTier4: big.NewInt(constants.ReqsForTier4), - ReqsForTier5: big.NewInt(constants.ReqsForTier5), - } + if *deployContractsAndCreateJobs { - contractAddresses := scripts.ContractAddresses{ + contractAddresses := model.ContractAddresses{ LinkAddress: *linkAddress, LinkEthAddress: *linkEthAddress, BhsContractAddress: common.HexToAddress(*bhsContractAddressString), @@ -166,24 +170,65 @@ func main() { BatchCoordinatorAddress: common.HexToAddress(*batchCoordinatorAddressString), } - coordinatorConfig := scripts.CoordinatorConfig{ - MinConfs: minConfs, - MaxGasLimit: &constants.MaxGasLimit, - StalenessSeconds: &constants.StalenessSeconds, - GasAfterPayment: &constants.GasAfterPayment, - FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink, - FeeConfig: feeConfig, - } + var jobSpecs model.JobSpecs + + switch *vrfVersion { + case "v2": + feeConfigV2 := vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{ + FulfillmentFlatFeeLinkPPMTier1: uint32(constants.FlatFeeTier1), + FulfillmentFlatFeeLinkPPMTier2: uint32(constants.FlatFeeTier2), + FulfillmentFlatFeeLinkPPMTier3: uint32(constants.FlatFeeTier3), + FulfillmentFlatFeeLinkPPMTier4: uint32(constants.FlatFeeTier4), + FulfillmentFlatFeeLinkPPMTier5: uint32(constants.FlatFeeTier5), + ReqsForTier2: big.NewInt(constants.ReqsForTier2), + ReqsForTier3: big.NewInt(constants.ReqsForTier3), + ReqsForTier4: big.NewInt(constants.ReqsForTier4), + ReqsForTier5: big.NewInt(constants.ReqsForTier5), + } + + coordinatorConfigV2 := v2scripts.CoordinatorConfigV2{ + MinConfs: minConfs, + MaxGasLimit: &constants.MaxGasLimit, + StalenessSeconds: &constants.StalenessSeconds, + GasAfterPayment: &constants.GasAfterPayment, + FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink, + FeeConfig: feeConfigV2, + } - jobSpecs := scripts.VRFV2DeployUniverse( - e, - constants.SubscriptionBalanceJuels, - &nodesMap[scripts.VRFPrimaryNodeName].VrfKeys[0], - contractAddresses, - coordinatorConfig, - *batchFulfillmentEnabled, - nodesMap, - ) + jobSpecs = v2scripts.VRFV2DeployUniverse( + e, + subscriptionBalanceJuels, + &nodesMap[model.VRFPrimaryNodeName].VrfKeys[0], + contractAddresses, + coordinatorConfigV2, + *batchFulfillmentEnabled, + nodesMap, + ) + case "v2plus": + feeConfigV2Plus := vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig{ + FulfillmentFlatFeeLinkPPM: uint32(constants.FlatFeeLinkPPM), + FulfillmentFlatFeeNativePPM: uint32(constants.FlatFeeNativePPM), + } + coordinatorConfigV2Plus := v2plusscripts.CoordinatorConfigV2Plus{ + MinConfs: minConfs, + MaxGasLimit: &constants.MaxGasLimit, + StalenessSeconds: &constants.StalenessSeconds, + GasAfterPayment: &constants.GasAfterPayment, + FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink, + FeeConfig: feeConfigV2Plus, + } + + jobSpecs = v2plusscripts.VRFV2PlusDeployUniverse( + e, + subscriptionBalanceJuels, + subscriptionBalanceNativeWei, + &nodesMap[model.VRFPrimaryNodeName].VrfKeys[0], + contractAddresses, + coordinatorConfigV2Plus, + *batchFulfillmentEnabled, + nodesMap, + ) + } for key, node := range nodesMap { client, app := connectToNode(&node.URL, output, node.CredsFile) @@ -196,41 +241,43 @@ func main() { deleteJob(jobID, client, app, output) } //CREATE JOBS + switch key { - case scripts.VRFPrimaryNodeName: + case model.VRFPrimaryNodeName: createJob(jobSpecs.VRFPrimaryNode, client, app, output) - case scripts.VRFBackupNodeName: + case model.VRFBackupNodeName: createJob(jobSpecs.VRFBackupyNode, client, app, output) - case scripts.BHSNodeName: + case model.BHSNodeName: createJob(jobSpecs.BHSNode, client, app, output) - case scripts.BHSBackupNodeName: + case model.BHSBackupNodeName: createJob(jobSpecs.BHSBackupNode, client, app, output) - case scripts.BHFNodeName: + case model.BHFNodeName: createJob(jobSpecs.BHFNode, client, app, output) } } } - } -func fundNodesIfNeeded(node scripts.Node, key string, e helpers.Environment) { - if node.SendingKeyFundingAmount.Int64() > 0 { - fmt.Println("\nFunding", key, "Node's Sending Keys...") +func fundNodesIfNeeded(node model.Node, key string, e helpers.Environment) { + if node.SendingKeyFundingAmount.Cmp(big.NewInt(0)) == 1 { + fmt.Println("\nFunding", key, "Node's Sending Keys. Need to fund each key with", node.SendingKeyFundingAmount, "wei") for _, sendingKey := range node.SendingKeys { - fundingToSendWei := node.SendingKeyFundingAmount.Int64() - sendingKey.BalanceEth.Int64() - if fundingToSendWei > 0 { - helpers.FundNode(e, sendingKey.Address, big.NewInt(fundingToSendWei)) + fundingToSendWei := new(big.Int).Sub(node.SendingKeyFundingAmount, sendingKey.BalanceEth) + if fundingToSendWei.Cmp(big.NewInt(0)) == 1 { + helpers.FundNode(e, sendingKey.Address, fundingToSendWei) } else { - fmt.Println("\nSkipping Funding", sendingKey.Address, "since it has", sendingKey.BalanceEth.Int64(), "wei") + fmt.Println("\nSkipping Funding", sendingKey.Address, "since it has", sendingKey.BalanceEth.String(), "wei") } } + } else { + fmt.Println("\nSkipping Funding", key, "Node's Sending Keys since funding amount is 0 wei") } } -func importVRFKeyToNodeIfSet(vrfBackupNodeURL *string, nodes map[string]scripts.Node, output *bytes.Buffer, file string) { +func importVRFKeyToNodeIfSet(vrfBackupNodeURL *string, nodes map[string]model.Node, output *bytes.Buffer, file string) { if *vrfBackupNodeURL != "" { - vrfBackupNode := nodes[scripts.VRFBackupNodeName] - vrfPrimaryNode := nodes[scripts.VRFBackupNodeName] + vrfBackupNode := nodes[model.VRFBackupNodeName] + vrfPrimaryNode := nodes[model.VRFBackupNodeName] if len(vrfBackupNode.VrfKeys) == 0 || vrfPrimaryNode.VrfKeys[0] != vrfBackupNode.VrfKeys[0] { client, app := connectToNode(&vrfBackupNode.URL, output, file) @@ -335,10 +382,10 @@ func printETHKeyData(ethKeys []presenters.ETHKeyResource) { } } -func mapEthKeysToSendingKeyArr(ethKeys []presenters.ETHKeyResource) []scripts.SendingKey { - var sendingKeys []scripts.SendingKey +func mapEthKeysToSendingKeyArr(ethKeys []presenters.ETHKeyResource) []model.SendingKey { + var sendingKeys []model.SendingKey for _, ethKey := range ethKeys { - sendingKey := scripts.SendingKey{Address: ethKey.Address, BalanceEth: *ethKey.EthBalance.ToInt()} + sendingKey := model.SendingKey{Address: ethKey.Address, BalanceEth: ethKey.EthBalance.ToInt()} sendingKeys = append(sendingKeys, sendingKey) } return sendingKeys diff --git a/core/scripts/common/vrf/util/util.go b/core/scripts/common/vrf/util/util.go new file mode 100644 index 00000000000..751aa013201 --- /dev/null +++ b/core/scripts/common/vrf/util/util.go @@ -0,0 +1,22 @@ +package util + +import ( + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" +) + +func MapToSendingKeyArr(nodeSendingKeys []string) []model.SendingKey { + var sendingKeys []model.SendingKey + + for _, key := range nodeSendingKeys { + sendingKeys = append(sendingKeys, model.SendingKey{Address: key}) + } + return sendingKeys +} + +func MapToAddressArr(sendingKeys []model.SendingKey) []string { + var sendingKeysString []string + for _, sendingKey := range sendingKeys { + sendingKeysString = append(sendingKeysString, sendingKey.Address) + } + return sendingKeysString +} diff --git a/core/scripts/vrfv2/testnet/constants/constants.go b/core/scripts/vrfv2/testnet/constants/constants.go deleted file mode 100644 index 73356d48ffc..00000000000 --- a/core/scripts/vrfv2/testnet/constants/constants.go +++ /dev/null @@ -1,28 +0,0 @@ -package constants - -import ( - "github.com/smartcontractkit/chainlink/v2/core/assets" - "math/big" -) - -var ( - SubscriptionBalanceJuels = assets.Ether(10).ToInt() - - // optional flags - FallbackWeiPerUnitLink = big.NewInt(6e16) - BatchFulfillmentEnabled = true - MinConfs = 3 - NodeSendingKeyFundingAmountGwei = assets.GWei(0).Int64() //100000000 = 0.1 ETH - MaxGasLimit = int64(2.5e6) - StalenessSeconds = int64(86400) - GasAfterPayment = int64(33285) - FlatFeeTier1 = int64(500) - FlatFeeTier2 = int64(500) - FlatFeeTier3 = int64(500) - FlatFeeTier4 = int64(500) - FlatFeeTier5 = int64(500) - ReqsForTier2 = int64(0) - ReqsForTier3 = int64(0) - ReqsForTier4 = int64(0) - ReqsForTier5 = int64(0) -) diff --git a/core/scripts/vrfv2/testnet/main.go b/core/scripts/vrfv2/testnet/main.go index d418eb6d153..5b216776bd9 100644 --- a/core/scripts/vrfv2/testnet/main.go +++ b/core/scripts/vrfv2/testnet/main.go @@ -11,7 +11,7 @@ import ( "os" "strings" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/scripts" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/v2scripts" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner_test_consumer" "github.com/ethereum/go-ethereum" @@ -350,7 +350,7 @@ func main() { cmd := flag.NewFlagSet("batch-bhs-deploy", flag.ExitOnError) bhsAddr := cmd.String("bhs-address", "", "address of the blockhash store contract") helpers.ParseArgs(cmd, os.Args[2:], "bhs-address") - scripts.DeployBatchBHS(e, common.HexToAddress(*bhsAddr)) + v2scripts.DeployBatchBHS(e, common.HexToAddress(*bhsAddr)) case "batch-bhs-store": cmd := flag.NewFlagSet("batch-bhs-store", flag.ExitOnError) batchAddr := cmd.String("batch-bhs-address", "", "address of the batch bhs contract") @@ -418,7 +418,7 @@ func main() { } if *startBlock == -1 { - closestBlock, err2 := scripts.ClosestBlock(e, common.HexToAddress(*batchAddr), uint64(*endBlock), uint64(*batchSize)) + closestBlock, err2 := v2scripts.ClosestBlock(e, common.HexToAddress(*batchAddr), uint64(*endBlock), uint64(*batchSize)) // found a block with blockhash stored that's more recent that end block if err2 == nil { *startBlock = int64(closestBlock) @@ -491,14 +491,14 @@ func main() { helpers.PanicErr(err) fmt.Println("latest head number:", h.Number.String()) case "bhs-deploy": - scripts.DeployBHS(e) + v2scripts.DeployBHS(e) case "coordinator-deploy": coordinatorDeployCmd := flag.NewFlagSet("coordinator-deploy", flag.ExitOnError) coordinatorDeployLinkAddress := coordinatorDeployCmd.String("link-address", "", "address of link token") coordinatorDeployBHSAddress := coordinatorDeployCmd.String("bhs-address", "", "address of bhs") coordinatorDeployLinkEthFeedAddress := coordinatorDeployCmd.String("link-eth-feed", "", "address of link-eth-feed") helpers.ParseArgs(coordinatorDeployCmd, os.Args[2:], "link-address", "bhs-address", "link-eth-feed") - scripts.DeployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) + v2scripts.DeployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) case "coordinator-get-config": cmd := flag.NewFlagSet("coordinator-get-config", flag.ExitOnError) coordinatorAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -507,7 +507,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.PrintCoordinatorConfig(coordinator) + v2scripts.PrintCoordinatorConfig(coordinator) case "coordinator-set-config": cmd := flag.NewFlagSet("coordinator-set-config", flag.ExitOnError) setConfigAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -530,7 +530,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*setConfigAddress), e.Ec) helpers.PanicErr(err) - scripts.SetCoordinatorConfig( + v2scripts.SetCoordinatorConfig( e, *coordinator, uint16(*minConfs), @@ -564,7 +564,7 @@ func main() { *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) } - scripts.RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) + v2scripts.RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) case "coordinator-deregister-key": coordinatorDeregisterKey := flag.NewFlagSet("coordinator-deregister-key", flag.ExitOnError) deregisterKeyAddress := coordinatorDeregisterKey.String("address", "", "coordinator address") @@ -692,14 +692,14 @@ func main() { helpers.PanicErr(err) fmt.Printf("Request config %+v Rw %+v Rid %+v\n", rc, rw, rid) case "deploy-universe": - scripts.DeployUniverseViaCLI(e) + v2scripts.DeployUniverseViaCLI(e) case "eoa-consumer-deploy": consumerDeployCmd := flag.NewFlagSet("eoa-consumer-deploy", flag.ExitOnError) consumerCoordinator := consumerDeployCmd.String("coordinator-address", "", "coordinator address") consumerLinkAddress := consumerDeployCmd.String("link-address", "", "link-address") helpers.ParseArgs(consumerDeployCmd, os.Args[2:], "coordinator-address", "link-address") - scripts.EoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) + v2scripts.EoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) case "eoa-load-test-consumer-deploy": loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-load-test-consumer-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") @@ -716,7 +716,7 @@ func main() { loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-load-test-consumer-with-metrics-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") helpers.ParseArgs(loadTestConsumerDeployCmd, os.Args[2:], "coordinator-address") - scripts.EoaLoadTestConsumerWithMetricsDeploy(e, *consumerCoordinator) + v2scripts.EoaLoadTestConsumerWithMetricsDeploy(e, *consumerCoordinator) case "eoa-vrf-owner-test-consumer-deploy": loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-vrf-owner-test-consumer-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") @@ -734,7 +734,7 @@ func main() { helpers.ParseArgs(createSubCmd, os.Args[2:], "coordinator-address") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.EoaCreateSub(e, *coordinator) + v2scripts.EoaCreateSub(e, *coordinator) case "eoa-add-sub-consumer": addSubConsCmd := flag.NewFlagSet("eoa-add-sub-consumer", flag.ExitOnError) coordinatorAddress := addSubConsCmd.String("coordinator-address", "", "coordinator address") @@ -743,7 +743,7 @@ func main() { helpers.ParseArgs(addSubConsCmd, os.Args[2:], "coordinator-address", "sub-id", "consumer-address") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.EoaAddConsumerToSub(e, *coordinator, uint64(*subID), *consumerAddress) + v2scripts.EoaAddConsumerToSub(e, *coordinator, uint64(*subID), *consumerAddress) case "eoa-create-fund-authorize-sub": // Lets just treat the owner key as the EOA controlling the sub cfaSubCmd := flag.NewFlagSet("eoa-create-fund-authorize-sub", flag.ExitOnError) @@ -1029,7 +1029,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.EoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, uint64(*subID)) + v2scripts.EoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, uint64(*subID)) case "eoa-read": cmd := flag.NewFlagSet("eoa-read", flag.ExitOnError) consumerAddress := cmd.String("consumer", "", "consumer address") @@ -1197,7 +1197,7 @@ func main() { linkETHFeedAddress := cmd.String("link-eth-feed", "", "address of link-eth-feed") coordinatorAddress := cmd.String("coordinator-address", "", "address of the vrf coordinator v2 contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "link-eth-feed", "coordinator-address") - scripts.WrapperDeploy(e, + v2scripts.WrapperDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*linkETHFeedAddress), common.HexToAddress(*coordinatorAddress)) @@ -1235,7 +1235,7 @@ func main() { maxNumWords := cmd.Uint("max-num-words", 10, "the keyhash that wrapper requests should use") helpers.ParseArgs(cmd, os.Args[2:], "wrapper-address", "key-hash") - scripts.WrapperConfigure(e, + v2scripts.WrapperConfigure(e, common.HexToAddress(*wrapperAddress), *wrapperGasOverhead, *coordinatorGasOverhead, @@ -1267,7 +1267,7 @@ func main() { wrapperAddress := cmd.String("wrapper-address", "", "address of the VRFV2Wrapper contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "wrapper-address") - scripts.WrapperConsumerDeploy(e, + v2scripts.WrapperConsumerDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*wrapperAddress)) case "wrapper-consumer-request": @@ -1344,10 +1344,10 @@ func main() { batchBHSAddress := cmd.String("batch-bhs-address", "", "address of the batch blockhash store") batchSize := cmd.Uint64("batch-size", 100, "batch size") helpers.ParseArgs(cmd, os.Args[2:], "block-number", "batch-bhs-address") - _, err := scripts.ClosestBlock(e, common.HexToAddress(*batchBHSAddress), *blockNumber, *batchSize) + _, err := v2scripts.ClosestBlock(e, common.HexToAddress(*batchBHSAddress), *blockNumber, *batchSize) helpers.PanicErr(err) case "wrapper-universe-deploy": - scripts.DeployWrapperUniverse(e) + v2scripts.DeployWrapperUniverse(e) default: panic("unrecognized subcommand: " + os.Args[1]) } diff --git a/core/scripts/vrfv2/testnet/scripts/super_scripts.go b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go similarity index 83% rename from core/scripts/vrfv2/testnet/scripts/super_scripts.go rename to core/scripts/vrfv2/testnet/v2scripts/super_scripts.go index 3594636a604..f5e37005690 100644 --- a/core/scripts/vrfv2/testnet/scripts/super_scripts.go +++ b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go @@ -1,12 +1,14 @@ -package scripts +package v2scripts import ( "context" "encoding/hex" "flag" "fmt" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/constants" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/jobs" + "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" @@ -22,47 +24,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/signatures/secp256k1" ) -var ( - VRFPrimaryNodeName = "vrf-primary-node" - VRFBackupNodeName = "vrf-backup-node" - BHSNodeName = "bhs-node" - BHSBackupNodeName = "bhs-backup-node" - BHFNodeName = "bhf-node" -) - -type Node struct { - URL string - CredsFile string - SendingKeys []SendingKey - NumberOfSendingKeysToCreate int - SendingKeyFundingAmount big.Int - VrfKeys []string - jobSpec string -} - -type SendingKey struct { - Address string - BalanceEth big.Int -} - -type JobSpecs struct { - VRFPrimaryNode string - VRFBackupyNode string - BHSNode string - BHSBackupNode string - BHFNode string -} - -type ContractAddresses struct { - LinkAddress string - LinkEthAddress string - BhsContractAddress common.Address - BatchBHSAddress common.Address - CoordinatorAddress common.Address - BatchCoordinatorAddress common.Address -} - -type CoordinatorConfig struct { +type CoordinatorConfigV2 struct { MinConfs *int MaxGasLimit *int64 StalenessSeconds *int64 @@ -82,8 +44,8 @@ func DeployUniverseViaCLI(e helpers.Environment) { 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.String(), "amount to fund subscription") - nodeSendingKeyFundingAmount := deployCmd.Int64("sending-key-funding-amount", constants.NodeSendingKeyFundingAmountGwei, "CL node sending key funding amount") + 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") batchFulfillmentEnabled := deployCmd.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether send randomness fulfillments in batches inside one tx from CL node") @@ -127,11 +89,15 @@ func DeployUniverseViaCLI(e helpers.Environment) { vrfPrimaryNodeSendingKeys := strings.Split(*vrfPrimaryNodeSendingKeysString, ",") - nodesMap := make(map[string]Node) + nodesMap := make(map[string]model.Node) - nodesMap[VRFPrimaryNodeName] = Node{ - SendingKeys: mapToSendingKeyArr(vrfPrimaryNodeSendingKeys), - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + fundingAmount, ok := new(big.Int).SetString(*nodeSendingKeyFundingAmount, 10) + if !ok { + panic(fmt.Sprintf("failed to parse node sending key funding amount '%s'", *nodeSendingKeyFundingAmount)) + } + nodesMap[model.VRFPrimaryNodeName] = model.Node{ + SendingKeys: util.MapToSendingKeyArr(vrfPrimaryNodeSendingKeys), + SendingKeyFundingAmount: fundingAmount, } bhsContractAddress := common.HexToAddress(bhsContractAddressString) @@ -139,7 +105,7 @@ func DeployUniverseViaCLI(e helpers.Environment) { coordinatorAddress := common.HexToAddress(coordinatorAddressString) batchCoordinatorAddress := common.HexToAddress(batchCoordinatorAddressString) - contractAddresses := ContractAddresses{ + contractAddresses := model.ContractAddresses{ LinkAddress: linkAddress, LinkEthAddress: linkEthAddress, BhsContractAddress: bhsContractAddress, @@ -148,7 +114,7 @@ func DeployUniverseViaCLI(e helpers.Environment) { BatchCoordinatorAddress: batchCoordinatorAddress, } - coordinatorConfig := CoordinatorConfig{ + coordinatorConfig := CoordinatorConfigV2{ MinConfs: minConfs, MaxGasLimit: maxGasLimit, StalenessSeconds: stalenessSeconds, @@ -167,31 +133,22 @@ func DeployUniverseViaCLI(e helpers.Environment) { nodesMap, ) - vrfPrimaryNode := nodesMap[VRFPrimaryNodeName] + vrfPrimaryNode := nodesMap[model.VRFPrimaryNodeName] fmt.Println("Funding node's sending keys...") for _, sendingKey := range vrfPrimaryNode.SendingKeys { - helpers.FundNode(e, sendingKey.Address, &vrfPrimaryNode.SendingKeyFundingAmount) + helpers.FundNode(e, sendingKey.Address, vrfPrimaryNode.SendingKeyFundingAmount) } } -func mapToSendingKeyArr(nodeSendingKeys []string) []SendingKey { - var sendingKeys []SendingKey - - for _, key := range nodeSendingKeys { - sendingKeys = append(sendingKeys, SendingKey{Address: key}) - } - return sendingKeys -} - func VRFV2DeployUniverse( e helpers.Environment, subscriptionBalanceJuels *big.Int, registerKeyUncompressedPubKey *string, - contractAddresses ContractAddresses, - coordinatorConfig CoordinatorConfig, + contractAddresses model.ContractAddresses, + coordinatorConfig CoordinatorConfigV2, batchFulfillmentEnabled bool, - nodesMap map[string]Node, -) JobSpecs { + nodesMap map[string]model.Node, +) model.JobSpecs { // Put key in ECDSA format if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") { @@ -246,7 +203,7 @@ func VRFV2DeployUniverse( if contractAddresses.BatchCoordinatorAddress.String() == "0x0000000000000000000000000000000000000000" { fmt.Println("\nDeploying Batch Coordinator...") - contractAddresses.BatchCoordinatorAddress = deployBatchCoordinatorV2(e, contractAddresses.CoordinatorAddress) + contractAddresses.BatchCoordinatorAddress = DeployBatchCoordinatorV2(e, contractAddresses.CoordinatorAddress) } fmt.Println("\nSetting Coordinator Config...") @@ -302,31 +259,31 @@ func VRFV2DeployUniverse( fmt.Printf("Subscription %+v\n", s) formattedVrfPrimaryJobSpec := fmt.Sprintf( - jobs.VRFJobFormatted, + jobs.VRFV2JobFormatted, contractAddresses.CoordinatorAddress, //coordinatorAddress contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress batchFulfillmentEnabled, //batchFulfillmentEnabled compressedPkHex, //publicKey *coordinatorConfig.MinConfs, //minIncomingConfirmations e.ChainID, //evmChainID - strings.Join(mapToAddressArr(nodesMap[VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses + strings.Join(util.MapToAddressArr(nodesMap[model.VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[VRFPrimaryNodeName].SendingKeys[0].Address, + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0].Address, contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, ) formattedVrfBackupJobSpec := fmt.Sprintf( - jobs.VRFJobFormatted, + jobs.VRFV2JobFormatted, contractAddresses.CoordinatorAddress, //coordinatorAddress contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress batchFulfillmentEnabled, //batchFulfillmentEnabled compressedPkHex, //publicKey 100, //minIncomingConfirmations e.ChainID, //evmChainID - strings.Join(mapToAddressArr(nodesMap[VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses + strings.Join(util.MapToAddressArr(nodesMap[model.VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[VRFPrimaryNodeName].SendingKeys[0], + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0], contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, ) @@ -338,7 +295,7 @@ func VRFV2DeployUniverse( 200, //lookbackBlocks contractAddresses.BhsContractAddress, //bhs address e.ChainID, //chain id - strings.Join(mapToAddressArr(nodesMap[BHSNodeName].SendingKeys), "\",\""), //sending addresses + strings.Join(util.MapToAddressArr(nodesMap[model.BHSNodeName].SendingKeys), "\",\""), //sending addresses ) formattedBHSBackupJobSpec := fmt.Sprintf( @@ -348,7 +305,7 @@ func VRFV2DeployUniverse( 200, //lookbackBlocks contractAddresses.BhsContractAddress, //bhs adreess e.ChainID, //chain id - strings.Join(mapToAddressArr(nodesMap[BHSBackupNodeName].SendingKeys), "\",\""), //sending addresses + strings.Join(util.MapToAddressArr(nodesMap[model.BHSBackupNodeName].SendingKeys), "\",\""), //sending addresses ) formattedBHFJobSpec := fmt.Sprintf( @@ -357,7 +314,7 @@ func VRFV2DeployUniverse( contractAddresses.BhsContractAddress, //bhs adreess contractAddresses.BatchBHSAddress, //batchBHS e.ChainID, //chain id - strings.Join(mapToAddressArr(nodesMap[BHFNodeName].SendingKeys), "\",\""), //sending addresses + strings.Join(util.MapToAddressArr(nodesMap[model.BHFNodeName].SendingKeys), "\",\""), //sending addresses ) fmt.Println( @@ -379,7 +336,7 @@ func VRFV2DeployUniverse( formattedVrfPrimaryJobSpec, ) - return JobSpecs{ + return model.JobSpecs{ VRFPrimaryNode: formattedVrfPrimaryJobSpec, VRFBackupyNode: formattedVrfBackupJobSpec, BHSNode: formattedBHSJobSpec, @@ -388,14 +345,6 @@ func VRFV2DeployUniverse( } } -func mapToAddressArr(sendingKeys []SendingKey) []string { - var sendingKeysString []string - for _, sendingKey := range sendingKeys { - sendingKeysString = append(sendingKeysString, sendingKey.Address) - } - return sendingKeysString -} - func DeployWrapperUniverse(e helpers.Environment) { cmd := flag.NewFlagSet("wrapper-universe-deploy", flag.ExitOnError) linkAddress := cmd.String("link-address", "", "address of link token") diff --git a/core/scripts/vrfv2/testnet/scripts/util.go b/core/scripts/vrfv2/testnet/v2scripts/util.go similarity index 99% rename from core/scripts/vrfv2/testnet/scripts/util.go rename to core/scripts/vrfv2/testnet/v2scripts/util.go index a55a78adb58..0e348e9c01c 100644 --- a/core/scripts/vrfv2/testnet/scripts/util.go +++ b/core/scripts/vrfv2/testnet/v2scripts/util.go @@ -1,4 +1,4 @@ -package scripts +package v2scripts import ( "context" @@ -53,7 +53,7 @@ func DeployCoordinator( return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func deployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { +func DeployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { _, tx, _, err := batch_vrf_coordinator_v2.DeployBatchVRFCoordinatorV2(e.Owner, e.Ec, coordinatorAddress) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) diff --git a/core/scripts/vrfv2plus/testnet/main.go b/core/scripts/vrfv2plus/testnet/main.go index 889350a61dd..0d1bf9a9481 100644 --- a/core/scripts/vrfv2plus/testnet/main.go +++ b/core/scripts/vrfv2plus/testnet/main.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "flag" "fmt" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2plus/testnet/v2plusscripts" "log" "math/big" "os" @@ -50,7 +51,6 @@ import ( var ( batchCoordinatorV2PlusABI = evmtypes.MustGetABI(batch_vrf_coordinator_v2plus.BatchVRFCoordinatorV2PlusABI) - coordinatorV2PlusABI = evmtypes.MustGetABI(vrf_coordinator_v2plus_interface.IVRFCoordinatorV2PlusInternalABI) ) func main() { @@ -102,9 +102,9 @@ func main() { helpers.PanicErr(err) fmt.Println("gas cost:", gasCost) case "smoke": - smokeTestVRF(e) + v2plusscripts.SmokeTestVRF(e) case "smoke-bhs": - smokeTestBHS(e) + v2plusscripts.SmokeTestBHS(e) case "manual-fulfill": cmd := flag.NewFlagSet("manual-fulfill", flag.ExitOnError) // In order to get the tx data for a fulfillment transaction, you can grep the @@ -337,7 +337,7 @@ func main() { cmd := flag.NewFlagSet("batch-bhs-deploy", flag.ExitOnError) bhsAddr := cmd.String("bhs-address", "", "address of the blockhash store contract") helpers.ParseArgs(cmd, os.Args[2:], "bhs-address") - deployBatchBHS(e, common.HexToAddress(*bhsAddr)) + v2plusscripts.DeployBatchBHS(e, common.HexToAddress(*bhsAddr)) case "batch-bhs-store": cmd := flag.NewFlagSet("batch-bhs-store", flag.ExitOnError) batchAddr := cmd.String("batch-bhs-address", "", "address of the batch bhs contract") @@ -513,14 +513,14 @@ func main() { helpers.PanicErr(err) fmt.Println("latest head number:", h.Number.String()) case "bhs-deploy": - deployBHS(e) + v2plusscripts.DeployBHS(e) case "coordinator-deploy": coordinatorDeployCmd := flag.NewFlagSet("coordinator-deploy", flag.ExitOnError) coordinatorDeployLinkAddress := coordinatorDeployCmd.String("link-address", "", "address of link token") coordinatorDeployBHSAddress := coordinatorDeployCmd.String("bhs-address", "", "address of bhs") coordinatorDeployLinkEthFeedAddress := coordinatorDeployCmd.String("link-eth-feed", "", "address of link-eth-feed") helpers.ParseArgs(coordinatorDeployCmd, os.Args[2:], "link-address", "bhs-address", "link-eth-feed") - deployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) + v2plusscripts.DeployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) case "coordinator-get-config": cmd := flag.NewFlagSet("coordinator-get-config", flag.ExitOnError) coordinatorAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -529,7 +529,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - printCoordinatorConfig(coordinator) + v2plusscripts.PrintCoordinatorConfig(coordinator) case "coordinator-set-config": cmd := flag.NewFlagSet("coordinator-set-config", flag.ExitOnError) setConfigAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -545,7 +545,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*setConfigAddress), e.Ec) helpers.PanicErr(err) - setCoordinatorConfig( + v2plusscripts.SetCoordinatorConfig( e, *coordinator, uint16(*minConfs), @@ -572,7 +572,7 @@ func main() { *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) } - registerCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) + v2plusscripts.RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) case "coordinator-deregister-key": coordinatorDeregisterKey := flag.NewFlagSet("coordinator-deregister-key", flag.ExitOnError) deregisterKeyAddress := coordinatorDeregisterKey.String("address", "", "coordinator address") @@ -704,7 +704,7 @@ func main() { helpers.PanicErr(err) fmt.Printf("Request config %+v Rw %+v Rid %+v\n", rc, rw, rid) case "deploy-universe": - deployUniverse(e) + v2plusscripts.DeployUniverseViaCLI(e) case "generate-proof-v2-plus": generateProofForV2Plus(e) case "eoa-consumer-deploy": @@ -713,7 +713,7 @@ func main() { consumerLinkAddress := consumerDeployCmd.String("link-address", "", "link-address") helpers.ParseArgs(consumerDeployCmd, os.Args[2:], "coordinator-address", "link-address", "key-hash") - eoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) + v2plusscripts.EoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) case "eoa-load-test-consumer-deploy": loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-load-test-consumer-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") @@ -743,7 +743,7 @@ func main() { helpers.ParseArgs(createSubCmd, os.Args[2:], "coordinator-address") coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - eoaCreateSub(e, *coordinator) + v2plusscripts.EoaCreateSub(e, *coordinator) case "eoa-add-sub-consumer": addSubConsCmd := flag.NewFlagSet("eoa-add-sub-consumer", flag.ExitOnError) coordinatorAddress := addSubConsCmd.String("coordinator-address", "", "coordinator address") @@ -753,7 +753,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) parsedSubID := parseSubID(*subID) - eoaAddConsumerToSub(e, *coordinator, parsedSubID, *consumerAddress) + v2plusscripts.EoaAddConsumerToSub(e, *coordinator, parsedSubID, *consumerAddress) case "eoa-create-fund-authorize-sub": // Lets just treat the owner key as the EOA controlling the sub cfaSubCmd := flag.NewFlagSet("eoa-create-fund-authorize-sub", flag.ExitOnError) @@ -969,12 +969,9 @@ func main() { if !s { panic(fmt.Sprintf("failed to parse top up amount '%s'", *amountStr)) } - coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) - helpers.PanicErr(err) - e.Owner.Value = amount - tx, err := coordinator.FundSubscriptionWithNative(e.Owner, parseSubID(*subID)) - helpers.PanicErr(err) - helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) + parsedSubID := parseSubID(*subID) + + v2plusscripts.EoaFundSubWithNative(e, common.HexToAddress(*coordinatorAddress), parsedSubID, amount) case "eoa-fund-sub": fund := flag.NewFlagSet("eoa-fund-sub", flag.ExitOnError) coordinatorAddress := fund.String("coordinator-address", "", "coordinator address") @@ -989,7 +986,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - eoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, parseSubID(*subID)) + v2plusscripts.EoaFundSubWithLink(e, *coordinator, *consumerLinkAddress, amount, parseSubID(*subID)) case "eoa-read": cmd := flag.NewFlagSet("eoa-read", flag.ExitOnError) consumerAddress := cmd.String("consumer", "", "consumer address") @@ -1122,7 +1119,7 @@ func main() { linkETHFeedAddress := cmd.String("link-eth-feed", "", "address of link-eth-feed") coordinatorAddress := cmd.String("coordinator-address", "", "address of the vrf coordinator v2 contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "link-eth-feed", "coordinator-address") - wrapperDeploy(e, + v2plusscripts.WrapperDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*linkETHFeedAddress), common.HexToAddress(*coordinatorAddress)) @@ -1164,7 +1161,7 @@ func main() { fulfillmentFlatFeeNativePPM := cmd.Uint("fulfillment-flat-fee-native-ppm", 500, "the native flat fee in ppm to charge for fulfillment") helpers.ParseArgs(cmd, os.Args[2:], "wrapper-address", "key-hash", "fallback-wei-per-unit-link") - wrapperConfigure(e, + v2plusscripts.WrapperConfigure(e, common.HexToAddress(*wrapperAddress), *wrapperGasOverhead, *coordinatorGasOverhead, @@ -1200,7 +1197,7 @@ func main() { wrapperAddress := cmd.String("wrapper-address", "", "address of the VRFV2Wrapper contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "wrapper-address") - wrapperConsumerDeploy(e, + v2plusscripts.WrapperConsumerDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*wrapperAddress)) case "wrapper-consumer-request": @@ -1272,7 +1269,7 @@ func main() { helpers.ParseArgs(cmd, os.Args[2:]) _ = helpers.CalculateLatestBlockHeader(e, *blockNumber) case "wrapper-universe-deploy": - deployWrapperUniverse(e) + v2plusscripts.DeployWrapperUniverse(e) default: panic("unrecognized subcommand: " + os.Args[1]) } diff --git a/core/scripts/vrfv2plus/testnet/super_scripts.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go similarity index 61% rename from core/scripts/vrfv2plus/testnet/super_scripts.go rename to core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go index 24a737be111..4e93d20f6d6 100644 --- a/core/scripts/vrfv2plus/testnet/super_scripts.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go @@ -1,4 +1,4 @@ -package main +package v2plusscripts import ( "bytes" @@ -6,6 +6,12 @@ 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" + evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2plus_interface" "math/big" "os" "strings" @@ -18,7 +24,6 @@ import ( "github.com/shopspring/decimal" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" - "github.com/smartcontractkit/chainlink/v2/core/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" @@ -30,46 +35,18 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/vrf/proof" ) -const formattedVRFJob = ` -type = "vrf" -name = "vrf_v2_plus" -schemaVersion = 1 -coordinatorAddress = "%s" -batchCoordinatorAddress = "%s" -batchFulfillmentEnabled = %t -batchFulfillmentGasMultiplier = 1.1 -publicKey = "%s" -minIncomingConfirmations = 3 -evmChainID = "%d" -fromAddresses = ["%s"] -pollPeriod = "5s" -requestTimeout = "24h" -observationSource = """ -decode_log [type=ethabidecodelog - abi="RandomWordsRequested(bytes32 indexed keyHash,uint256 requestId,uint256 preSeed,uint256 indexed subId,uint16 minimumRequestConfirmations,uint32 callbackGasLimit,uint32 numWords,bytes extraArgs,address indexed sender)" - data="$(jobRun.logData)" - topics="$(jobRun.logTopics)"] -generate_proof [type=vrfv2plus - publicKey="$(jobSpec.publicKey)" - requestBlockHash="$(jobRun.logBlockHash)" - requestBlockNumber="$(jobRun.logBlockNumber)" - topics="$(jobRun.logTopics)"] -estimate_gas [type=estimategaslimit - to="%s" - multiplier="1.1" - data="$(generate_proof.output)"] -simulate_fulfillment [type=ethcall - to="%s" - gas="$(estimate_gas)" - gasPrice="$(jobSpec.maxGasPrice)" - extractRevertReason=true - contract="%s" - data="$(generate_proof.output)"] -decode_log->generate_proof->estimate_gas->simulate_fulfillment -""" -` - -func smokeTestVRF(e helpers.Environment) { +var coordinatorV2PlusABI = evmtypes.MustGetABI(vrf_coordinator_v2plus_interface.IVRFCoordinatorV2PlusInternalABI) + +type CoordinatorConfigV2Plus struct { + MinConfs *int + MaxGasLimit *int64 + StalenessSeconds *int64 + GasAfterPayment *int64 + FallbackWeiPerUnitLink *big.Int + FeeConfig vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig +} + +func SmokeTestVRF(e helpers.Environment) { smokeCmd := flag.NewFlagSet("smoke", flag.ExitOnError) // required flags @@ -120,7 +97,7 @@ func smokeTestVRF(e helpers.Environment) { var bhsContractAddress common.Address if len(*bhsAddressStr) == 0 { fmt.Println("\nDeploying BHS...") - bhsContractAddress = deployBHS(e) + bhsContractAddress = DeployBHS(e) } else { bhsContractAddress = common.HexToAddress(*bhsAddressStr) } @@ -128,7 +105,7 @@ func smokeTestVRF(e helpers.Environment) { var batchBHSAddress common.Address if len(*batchBHSAddressStr) == 0 { fmt.Println("\nDeploying Batch BHS...") - batchBHSAddress = deployBatchBHS(e, bhsContractAddress) + batchBHSAddress = DeployBatchBHS(e, bhsContractAddress) } else { batchBHSAddress = common.HexToAddress(*batchBHSAddressStr) } @@ -136,7 +113,7 @@ func smokeTestVRF(e helpers.Environment) { var coordinatorAddress common.Address if len(*coordinatorAddressStr) == 0 { fmt.Println("\nDeploying Coordinator...") - coordinatorAddress = deployCoordinator(e, *linkAddress, bhsContractAddress.String(), *linkEthAddress) + coordinatorAddress = DeployCoordinator(e, *linkAddress, bhsContractAddress.String(), *linkEthAddress) } else { coordinatorAddress = common.HexToAddress(*coordinatorAddressStr) } @@ -147,14 +124,14 @@ func smokeTestVRF(e helpers.Environment) { var batchCoordinatorAddress common.Address if len(*batchCoordinatorAddressStr) == 0 { fmt.Println("\nDeploying Batch Coordinator...") - batchCoordinatorAddress = deployBatchCoordinatorV2(e, coordinatorAddress) + batchCoordinatorAddress = DeployBatchCoordinatorV2(e, coordinatorAddress) } else { batchCoordinatorAddress = common.HexToAddress(*batchCoordinatorAddressStr) } if !*skipConfig { fmt.Println("\nSetting Coordinator Config...") - setCoordinatorConfig( + SetCoordinatorConfig( e, *coordinator, uint16(*minConfs), @@ -170,7 +147,7 @@ func smokeTestVRF(e helpers.Environment) { } fmt.Println("\nConfig set, getting current config from deployed contract...") - printCoordinatorConfig(coordinator) + PrintCoordinatorConfig(coordinator) // Generate compressed public key and key hash uncompressed, err := key.PublicKey.StringUncompressed() @@ -250,20 +227,20 @@ func smokeTestVRF(e helpers.Environment) { } fmt.Println("\nDeploying consumer...") - consumerAddress := eoaDeployConsumer(e, coordinatorAddress.String(), *linkAddress) + consumerAddress := EoaDeployConsumer(e, coordinatorAddress.String(), *linkAddress) fmt.Println("\nAdding subscription...") - eoaCreateSub(e, *coordinator) + EoaCreateSub(e, *coordinator) - subID := findSubscriptionID(e, coordinator) + subID := FindSubscriptionID(e, coordinator) helpers.PanicErr(err) fmt.Println("\nAdding consumer to subscription...") - eoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) + EoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) if subscriptionBalance.Cmp(big.NewInt(0)) > 0 { fmt.Println("\nFunding subscription with", subscriptionBalance, "juels...") - eoaFundSubscription(e, *coordinator, *linkAddress, subscriptionBalance, subID) + EoaFundSubWithLink(e, *coordinator, *linkAddress, subscriptionBalance, subID) } else { fmt.Println("Subscription", subID, "NOT getting funded. You must fund the subscription in order to use it!") } @@ -378,7 +355,7 @@ func smokeTestVRF(e helpers.Environment) { fmt.Println("\nfulfillment successful") } -func smokeTestBHS(e helpers.Environment) { +func SmokeTestBHS(e helpers.Environment) { smokeCmd := flag.NewFlagSet("smoke-bhs", flag.ExitOnError) // optional args @@ -390,7 +367,7 @@ func smokeTestBHS(e helpers.Environment) { var bhsContractAddress common.Address if len(*bhsAddress) == 0 { fmt.Println("\nDeploying BHS...") - bhsContractAddress = deployBHS(e) + bhsContractAddress = DeployBHS(e) } else { bhsContractAddress = common.HexToAddress(*bhsAddress) } @@ -398,7 +375,7 @@ func smokeTestBHS(e helpers.Environment) { var batchBHSContractAddress common.Address if len(*batchBHSAddress) == 0 { fmt.Println("\nDeploying Batch BHS...") - batchBHSContractAddress = deployBatchBHS(e, bhsContractAddress) + batchBHSContractAddress = DeployBatchBHS(e, bhsContractAddress) } else { batchBHSContractAddress = common.HexToAddress(*batchBHSAddress) } @@ -486,117 +463,183 @@ func sendTx(e helpers.Environment, to common.Address, data []byte) (*types.Recei e.ChainID, "send tx", signedTx.Hash().String(), "to", to.String()), signedTx.Hash() } -func deployUniverse(e helpers.Environment) { +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") - bhsAddress := deployCmd.String("bhs-address", "", "address of blockhash store") - batchBHSAddress := deployCmd.String("batch-bhs-address", "", "address of batch blockhash store") - subscriptionBalanceString := deployCmd.String("subscription-balance", "1e19", "amount to fund subscription") + 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", "1e19", "amount to fund subscription with Link token (Juels)") + subscriptionBalanceNativeWeiString := deployCmd.String("subscription-balance-native", "1e18", "amount to fund subscription with native token (Wei)") + + batchFulfillmentEnabled := deployCmd.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether send randomness fulfillments in batches inside one tx from CL node") // optional flags fallbackWeiPerUnitLinkString := deployCmd.String("fallback-wei-per-unit-link", "6e16", "fallback wei/link ratio") registerKeyUncompressedPubKey := deployCmd.String("uncompressed-pub-key", "", "uncompressed public key") - registerKeyOracleAddress := deployCmd.String("oracle-address", "", "oracle sender address") - minConfs := deployCmd.Int("min-confs", 3, "min confs") - oracleFundingAmount := deployCmd.Int64("oracle-funding-amount", assets.GWei(100_000_000).Int64(), "amount to fund sending oracle") - maxGasLimit := deployCmd.Int64("max-gas-limit", 2.5e6, "max gas limit") - stalenessSeconds := deployCmd.Int64("staleness-seconds", 86400, "staleness in seconds") - gasAfterPayment := deployCmd.Int64("gas-after-payment", 33285, "gas after payment calculation") - flatFeeLinkPPM := deployCmd.Int64("flat-fee-link-ppm", 500, "fulfillment flat fee LINK ppm") - flatFeeEthPPM := deployCmd.Int64("flat-fee-eth-ppm", 500, "fulfillment flat fee ETH ppm") + vrfPrimaryNodeSendingKeysString := deployCmd.String("vrf-primary-node-sending-keys", "", "VRF Primary Node sending keys") + minConfs := deployCmd.Int("min-confs", constants.MinConfs, "min confs") + nodeSendingKeyFundingAmount := deployCmd.String("sending-key-funding-amount", constants.NodeSendingKeyFundingAmount, "CL node sending key funding amount") + maxGasLimit := deployCmd.Int64("max-gas-limit", constants.MaxGasLimit, "max gas limit") + stalenessSeconds := deployCmd.Int64("staleness-seconds", constants.StalenessSeconds, "staleness in seconds") + gasAfterPayment := deployCmd.Int64("gas-after-payment", constants.GasAfterPayment, "gas after payment calculation") + flatFeeLinkPPM := deployCmd.Int64("flat-fee-link-ppm", constants.FlatFeeLinkPPM, "fulfillment flat fee LINK ppm") + flatFeeEthPPM := deployCmd.Int64("flat-fee-eth-ppm", constants.FlatFeeNativePPM, "fulfillment flat fee ETH ppm") - helpers.ParseArgs(deployCmd, os.Args[2:]) + helpers.ParseArgs( + deployCmd, os.Args[2:], + ) fallbackWeiPerUnitLink := decimal.RequireFromString(*fallbackWeiPerUnitLinkString).BigInt() - subscriptionBalance := decimal.RequireFromString(*subscriptionBalanceString).BigInt() + subscriptionBalanceJuels := decimal.RequireFromString(*subscriptionBalanceJuelsString).BigInt() + subscriptionBalanceNativeWei := decimal.RequireFromString(*subscriptionBalanceNativeWeiString).BigInt() + fundingAmount := decimal.RequireFromString(*nodeSendingKeyFundingAmount).BigInt() + + feeConfig := vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig{ + FulfillmentFlatFeeLinkPPM: uint32(*flatFeeLinkPPM), + FulfillmentFlatFeeNativePPM: uint32(*flatFeeEthPPM), + } + vrfPrimaryNodeSendingKeys := strings.Split(*vrfPrimaryNodeSendingKeysString, ",") + + nodesMap := make(map[string]model.Node) + + nodesMap[model.VRFPrimaryNodeName] = model.Node{ + SendingKeys: util.MapToSendingKeyArr(vrfPrimaryNodeSendingKeys), + SendingKeyFundingAmount: fundingAmount, + } + + bhsContractAddress := common.HexToAddress(bhsContractAddressString) + batchBHSAddress := common.HexToAddress(batchBHSAddressString) + coordinatorAddress := common.HexToAddress(coordinatorAddressString) + batchCoordinatorAddress := common.HexToAddress(batchCoordinatorAddressString) + + contractAddresses := model.ContractAddresses{ + LinkAddress: linkAddress, + LinkEthAddress: linkEthAddress, + BhsContractAddress: bhsContractAddress, + BatchBHSAddress: batchBHSAddress, + CoordinatorAddress: coordinatorAddress, + BatchCoordinatorAddress: batchCoordinatorAddress, + } + + coordinatorConfig := CoordinatorConfigV2Plus{ + MinConfs: minConfs, + MaxGasLimit: maxGasLimit, + StalenessSeconds: stalenessSeconds, + GasAfterPayment: gasAfterPayment, + FallbackWeiPerUnitLink: fallbackWeiPerUnitLink, + FeeConfig: feeConfig, + } + + VRFV2PlusDeployUniverse( + e, + subscriptionBalanceJuels, + subscriptionBalanceNativeWei, + registerKeyUncompressedPubKey, + contractAddresses, + coordinatorConfig, + *batchFulfillmentEnabled, + nodesMap, + ) + + vrfPrimaryNode := nodesMap[model.VRFPrimaryNodeName] + fmt.Println("Funding node's sending keys...") + for _, sendingKey := range vrfPrimaryNode.SendingKeys { + helpers.FundNode(e, sendingKey.Address, vrfPrimaryNode.SendingKeyFundingAmount) + } +} + +func VRFV2PlusDeployUniverse(e helpers.Environment, + subscriptionBalanceJuels *big.Int, + subscriptionBalanceNativeWei *big.Int, + registerKeyUncompressedPubKey *string, + contractAddresses model.ContractAddresses, + coordinatorConfig CoordinatorConfigV2Plus, + 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) } - if len(*linkAddress) == 0 { + // 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) + + if len(contractAddresses.LinkAddress) == 0 { fmt.Println("\nDeploying LINK Token...") - address := helpers.DeployLinkToken(e).String() - linkAddress = &address + contractAddresses.LinkAddress = helpers.DeployLinkToken(e).String() } - if len(*linkEthAddress) == 0 { + if len(contractAddresses.LinkEthAddress) == 0 { fmt.Println("\nDeploying LINK/ETH Feed...") - address := helpers.DeployLinkEthFeed(e, *linkAddress, fallbackWeiPerUnitLink).String() - linkEthAddress = &address + contractAddresses.LinkEthAddress = helpers.DeployLinkEthFeed(e, contractAddresses.LinkAddress, coordinatorConfig.FallbackWeiPerUnitLink).String() } - var bhsContractAddress common.Address - if len(*bhsAddress) == 0 { + if contractAddresses.BhsContractAddress.String() == "0x0000000000000000000000000000000000000000" { fmt.Println("\nDeploying BHS...") - bhsContractAddress = deployBHS(e) - } else { - bhsContractAddress = common.HexToAddress(*bhsAddress) + contractAddresses.BhsContractAddress = DeployBHS(e) } - var batchBHSContractAddress common.Address - if len(*batchBHSAddress) == 0 { + if contractAddresses.BatchBHSAddress.String() == "0x0000000000000000000000000000000000000000" { fmt.Println("\nDeploying Batch BHS...") - batchBHSContractAddress = deployBatchBHS(e, bhsContractAddress) - } else { - batchBHSContractAddress = common.HexToAddress(*batchBHSAddress) + contractAddresses.BatchBHSAddress = DeployBatchBHS(e, contractAddresses.BhsContractAddress) } - var coordinatorAddress common.Address - fmt.Println("\nDeploying Coordinator...") - coordinatorAddress = deployCoordinator(e, *linkAddress, bhsContractAddress.String(), *linkEthAddress) + if contractAddresses.CoordinatorAddress.String() == "0x0000000000000000000000000000000000000000" { + fmt.Println("\nDeploying Coordinator...") + contractAddresses.CoordinatorAddress = DeployCoordinator(e, contractAddresses.LinkAddress, contractAddresses.BhsContractAddress.String(), contractAddresses.LinkEthAddress) + } - coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(coordinatorAddress, e.Ec) + coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(contractAddresses.CoordinatorAddress, e.Ec) helpers.PanicErr(err) - fmt.Println("\nDeploying Batch Coordinator...") - batchCoordinatorAddress := deployBatchCoordinatorV2(e, coordinatorAddress) + if contractAddresses.BatchCoordinatorAddress.String() == "0x0000000000000000000000000000000000000000" { + fmt.Println("\nDeploying Batch Coordinator...") + contractAddresses.BatchCoordinatorAddress = DeployBatchCoordinatorV2(e, contractAddresses.CoordinatorAddress) + } fmt.Println("\nSetting Coordinator Config...") - setCoordinatorConfig( + SetCoordinatorConfig( e, *coordinator, - uint16(*minConfs), - uint32(*maxGasLimit), - uint32(*stalenessSeconds), - uint32(*gasAfterPayment), - fallbackWeiPerUnitLink, - vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig{ - FulfillmentFlatFeeLinkPPM: uint32(*flatFeeLinkPPM), - FulfillmentFlatFeeNativePPM: uint32(*flatFeeEthPPM), - }, + uint16(*coordinatorConfig.MinConfs), + uint32(*coordinatorConfig.MaxGasLimit), + uint32(*coordinatorConfig.StalenessSeconds), + uint32(*coordinatorConfig.GasAfterPayment), + coordinatorConfig.FallbackWeiPerUnitLink, + coordinatorConfig.FeeConfig, ) fmt.Println("\nConfig set, getting current config from deployed contract...") - printCoordinatorConfig(coordinator) - - var compressedPkHex string - var keyHash common.Hash - if len(*registerKeyUncompressedPubKey) > 0 && len(*registerKeyOracleAddress) > 0 { - // 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) + PrintCoordinatorConfig(coordinator) + if len(*registerKeyUncompressedPubKey) > 0 { fmt.Println("\nRegistering proving key...") - registerCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) + + //NOTE - register proving key against EOA account, and not against Oracle's sending address in other to be able + // easily withdraw funds from Coordinator contract back to EOA account + RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, e.Owner.From.String()) fmt.Println("\nProving key registered, getting proving key hashes from deployed contract...") _, _, provingKeyHashes, configErr := coordinator.GetRequestConfig(nil) @@ -607,22 +650,28 @@ func deployUniverse(e helpers.Environment) { } fmt.Println("\nDeploying consumer...") - consumerAddress := eoaDeployConsumer(e, coordinatorAddress.String(), *linkAddress) + consumerAddress := EoaV2PlusLoadTestConsumerWithMetricsDeploy(e, contractAddresses.CoordinatorAddress.String()) fmt.Println("\nAdding subscription...") - eoaCreateSub(e, *coordinator) + EoaCreateSub(e, *coordinator) - subID := findSubscriptionID(e, coordinator) + subID := FindSubscriptionID(e, coordinator) helpers.PanicErr(err) fmt.Println("\nAdding consumer to subscription...") - eoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) + EoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) - if subscriptionBalance.Cmp(big.NewInt(0)) > 0 { - fmt.Println("\nFunding subscription with", subscriptionBalance, "juels...") - eoaFundSubscription(e, *coordinator, *linkAddress, subscriptionBalance, subID) + if subscriptionBalanceJuels.Cmp(big.NewInt(0)) > 0 { + fmt.Println("\nFunding subscription with Link Token.", subscriptionBalanceJuels, "juels...") + EoaFundSubWithLink(e, *coordinator, contractAddresses.LinkAddress, subscriptionBalanceJuels, subID) } else { - fmt.Println("Subscription", subID, "NOT getting funded. You must fund the subscription in order to use it!") + fmt.Println("Subscription", subID, "NOT getting funded with Link Token. You must fund the subscription in order to use it!") + } + if subscriptionBalanceNativeWei.Cmp(big.NewInt(0)) > 0 { + fmt.Println("\nFunding subscription with Native Token.", subscriptionBalanceNativeWei, "wei...") + EoaFundSubWithNative(e, coordinator.Address(), subID, subscriptionBalanceNativeWei) + } else { + fmt.Println("Subscription", subID, "NOT getting funded with Native Token. You must fund the subscription in order to use it!") } fmt.Println("\nSubscribed and (possibly) funded, retrieving subscription from deployed contract...") @@ -630,45 +679,94 @@ func deployUniverse(e helpers.Environment) { helpers.PanicErr(err) fmt.Printf("Subscription %+v\n", s) - if len(*registerKeyOracleAddress) > 0 && *oracleFundingAmount > 0 { - fmt.Println("\nFunding oracle...") - helpers.FundNodes(e, []string{*registerKeyOracleAddress}, big.NewInt(*oracleFundingAmount)) - } - - formattedJobSpec := fmt.Sprintf( - formattedVRFJob, - coordinatorAddress, - batchCoordinatorAddress, - false, - compressedPkHex, - e.ChainID, - *registerKeyOracleAddress, - coordinatorAddress, - coordinatorAddress, - coordinatorAddress, + formattedVrfV2PlusPrimaryJobSpec := fmt.Sprintf( + jobs.VRFV2PlusJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress + batchFulfillmentEnabled, //batchFulfillmentEnabled + compressedPkHex, //publicKey + *coordinatorConfig.MinConfs, //minIncomingConfirmations + e.ChainID, //evmChainID + strings.Join(util.MapToAddressArr(nodesMap[model.VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses + contractAddresses.CoordinatorAddress, + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0].Address, + contractAddresses.CoordinatorAddress, + contractAddresses.CoordinatorAddress, + ) + + formattedVrfV2PlusBackupJobSpec := fmt.Sprintf( + jobs.VRFV2PlusJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress + batchFulfillmentEnabled, //batchFulfillmentEnabled + compressedPkHex, //publicKey + 100, //minIncomingConfirmations + e.ChainID, //evmChainID + strings.Join(util.MapToAddressArr(nodesMap[model.VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses + contractAddresses.CoordinatorAddress, + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0], + contractAddresses.CoordinatorAddress, + contractAddresses.CoordinatorAddress, + ) + + formattedBHSJobSpec := fmt.Sprintf( + jobs.BHSJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + 30, //waitBlocks + 200, //lookbackBlocks + contractAddresses.BhsContractAddress, //bhs address + e.ChainID, //chain id + strings.Join(util.MapToAddressArr(nodesMap[model.BHSNodeName].SendingKeys), "\",\""), //sending addresses + ) + + formattedBHSBackupJobSpec := fmt.Sprintf( + jobs.BHSJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + 100, //waitBlocks + 200, //lookbackBlocks + contractAddresses.BhsContractAddress, //bhs adreess + e.ChainID, //chain id + strings.Join(util.MapToAddressArr(nodesMap[model.BHSBackupNodeName].SendingKeys), "\",\""), //sending addresses + ) + + formattedBHFJobSpec := fmt.Sprintf( + jobs.BHFJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + contractAddresses.BhsContractAddress, //bhs adreess + contractAddresses.BatchBHSAddress, //batchBHS + e.ChainID, //chain id + strings.Join(util.MapToAddressArr(nodesMap[model.BHFNodeName].SendingKeys), "\",\""), //sending addresses ) fmt.Println( - "\n----------------------------", "\nDeployment complete.", - "\nLINK Token contract address:", *linkAddress, - "\nLINK/ETH Feed contract address:", *linkEthAddress, - "\nBlockhash Store contract address:", bhsContractAddress, - "\nBatch Blockhash Store contract address:", batchBHSContractAddress, - "\nVRF Coordinator Address:", coordinatorAddress, - "\nBatch VRF Coordinator Address:", batchCoordinatorAddress, + "\nLINK Token contract address:", contractAddresses.LinkAddress, + "\nLINK/ETH Feed contract address:", contractAddresses.LinkEthAddress, + "\nBlockhash Store contract address:", contractAddresses.BhsContractAddress, + "\nBatch Blockhash Store contract address:", contractAddresses.BatchBHSAddress, + "\nVRF Coordinator Address:", contractAddresses.CoordinatorAddress, + "\nBatch VRF Coordinator Address:", contractAddresses.BatchCoordinatorAddress, "\nVRF Consumer Address:", consumerAddress, "\nVRF Subscription Id:", subID, - "\nVRF Subscription Balance:", *subscriptionBalanceString, + "\nVRF Subscription Balance:", *subscriptionBalanceJuels, "\nPossible VRF Request command: ", - fmt.Sprintf("go run . eoa-request --consumer-address %s --sub-id %d --key-hash %s", consumerAddress, subID, keyHash), + fmt.Sprintf("go run . eoa-load-test-request-with-metrics --consumer-address=%s --sub-id=%d --key-hash=%s --request-confirmations %d --requests 1 --runs 1 --cb-gas-limit 1_000_000", consumerAddress, subID, keyHash, *coordinatorConfig.MinConfs), + "\nRetrieve Request Status: ", + fmt.Sprintf("go run . eoa-load-test-read-metrics --consumer-address=%s", consumerAddress), "\nA node can now be configured to run a VRF job with the below job spec :\n", - formattedJobSpec, - "\n----------------------------", + formattedVrfV2PlusPrimaryJobSpec, ) + + return model.JobSpecs{ + VRFPrimaryNode: formattedVrfV2PlusPrimaryJobSpec, + VRFBackupyNode: formattedVrfV2PlusBackupJobSpec, + BHSNode: formattedBHSJobSpec, + BHSBackupNode: formattedBHSBackupJobSpec, + BHFNode: formattedBHFJobSpec, + } } -func deployWrapperUniverse(e helpers.Environment) { +func DeployWrapperUniverse(e helpers.Environment) { cmd := flag.NewFlagSet("wrapper-universe-deploy", flag.ExitOnError) linkAddress := cmd.String("link-address", "", "address of link token") linkETHFeedAddress := cmd.String("link-eth-feed", "", "address of link-eth-feed") @@ -691,12 +789,12 @@ func deployWrapperUniverse(e helpers.Environment) { panic(fmt.Sprintf("failed to parse top up amount '%s'", *subFunding)) } - wrapper, subID := wrapperDeploy(e, + wrapper, subID := WrapperDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*linkETHFeedAddress), common.HexToAddress(*coordinatorAddress)) - wrapperConfigure(e, + WrapperConfigure(e, wrapper, *wrapperGasOverhead, *coordinatorGasOverhead, @@ -709,14 +807,14 @@ func deployWrapperUniverse(e helpers.Environment) { uint32(*fulfillmentFlatFeeNativePPM), ) - consumer := wrapperConsumerDeploy(e, + consumer := WrapperConsumerDeploy(e, common.HexToAddress(*linkAddress), wrapper) coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - eoaFundSubscription(e, *coordinator, *linkAddress, amount, subID) + EoaFundSubWithLink(e, *coordinator, *linkAddress, amount, subID) link, err := link_token_interface.NewLinkToken(common.HexToAddress(*linkAddress), e.Ec) helpers.PanicErr(err) diff --git a/core/scripts/vrfv2plus/testnet/util.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go similarity index 79% rename from core/scripts/vrfv2plus/testnet/util.go rename to core/scripts/vrfv2plus/testnet/v2plusscripts/util.go index 2aeb71bd598..ebe881a9951 100644 --- a/core/scripts/vrfv2plus/testnet/util.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go @@ -1,9 +1,10 @@ -package main +package v2plusscripts import ( "context" "encoding/hex" "fmt" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -22,19 +23,19 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/utils" ) -func deployBHS(e helpers.Environment) (blockhashStoreAddress common.Address) { +func DeployBHS(e helpers.Environment) (blockhashStoreAddress common.Address) { _, tx, _, err := blockhash_store.DeployBlockhashStore(e.Owner, e.Ec) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func deployBatchBHS(e helpers.Environment, bhsAddress common.Address) (batchBHSAddress common.Address) { +func DeployBatchBHS(e helpers.Environment, bhsAddress common.Address) (batchBHSAddress common.Address) { _, tx, _, err := batch_blockhash_store.DeployBatchBlockhashStore(e.Owner, e.Ec, bhsAddress) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func deployCoordinator( +func DeployCoordinator( e helpers.Environment, linkAddress string, bhsAddress string, @@ -58,27 +59,31 @@ func deployCoordinator( return coordinatorAddress } -func deployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { +func DeployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { _, tx, _, err := batch_vrf_coordinator_v2plus.DeployBatchVRFCoordinatorV2Plus(e.Owner, e.Ec, coordinatorAddress) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func eoaAddConsumerToSub(e helpers.Environment, - coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, subID *big.Int, consumerAddress string) { +func EoaAddConsumerToSub( + e helpers.Environment, + coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, + subID *big.Int, + consumerAddress string, +) { txadd, err := coordinator.AddConsumer(e.Owner, subID, common.HexToAddress(consumerAddress)) helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, txadd, e.ChainID) } -func eoaCreateSub(e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25) { +func EoaCreateSub(e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25) { tx, err := coordinator.CreateSubscription(e.Owner) helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } // returns subscription ID that belongs to the given owner. Returns result found first -func findSubscriptionID(e helpers.Environment, coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) *big.Int { +func FindSubscriptionID(e helpers.Environment, coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) *big.Int { // Use most recent 500 blocks as search window. head, err := e.Ec.BlockNumber(context.Background()) helpers.PanicErr(err) @@ -95,7 +100,7 @@ func findSubscriptionID(e helpers.Environment, coordinator *vrf_coordinator_v2_5 return subscriptionIterator.Event.SubId } -func eoaDeployConsumer(e helpers.Environment, +func EoaDeployConsumer(e helpers.Environment, coordinatorAddress string, linkAddress string) ( consumerAddress common.Address) { @@ -108,13 +113,17 @@ func eoaDeployConsumer(e helpers.Environment, return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func eoaFundSubscription(e helpers.Environment, - coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, linkAddress string, amount, subID *big.Int) { +func EoaFundSubWithLink( + e helpers.Environment, + coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, + linkAddress string, amount, + subID *big.Int, +) { linkToken, err := link_token_interface.NewLinkToken(common.HexToAddress(linkAddress), e.Ec) helpers.PanicErr(err) bal, err := linkToken.BalanceOf(nil, e.Owner.From) helpers.PanicErr(err) - fmt.Println("Initial account balance:", bal, e.Owner.From.String(), "Funding amount:", amount.String()) + fmt.Println("Initial account balance (Juels):", bal, e.Owner.From.String(), "Funding amount:", amount.String()) b, err := utils.ABIEncode(`[{"type":"uint256"}]`, subID) helpers.PanicErr(err) tx, err := linkToken.TransferAndCall(e.Owner, coordinator.Address(), amount, b) @@ -122,7 +131,16 @@ func eoaFundSubscription(e helpers.Environment, helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, fmt.Sprintf("sub ID: %d", subID)) } -func printCoordinatorConfig(coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) { +func EoaFundSubWithNative(e helpers.Environment, coordinatorAddress common.Address, subID *big.Int, amount *big.Int) { + coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(coordinatorAddress, e.Ec) + helpers.PanicErr(err) + e.Owner.Value = amount + tx, err := coordinator.FundSubscriptionWithNative(e.Owner, subID) + helpers.PanicErr(err) + helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) +} + +func PrintCoordinatorConfig(coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) { cfg, err := coordinator.SConfig(nil) helpers.PanicErr(err) @@ -133,7 +151,7 @@ func printCoordinatorConfig(coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) fmt.Printf("Coordinator fee config: %+v\n", feeConfig) } -func setCoordinatorConfig( +func SetCoordinatorConfig( e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, minConfs uint16, @@ -156,7 +174,7 @@ func setCoordinatorConfig( helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } -func registerCoordinatorProvingKey(e helpers.Environment, +func RegisterCoordinatorProvingKey(e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, uncompressed string, oracleAddress string) { pubBytes, err := hex.DecodeString(uncompressed) helpers.PanicErr(err) @@ -176,7 +194,7 @@ func registerCoordinatorProvingKey(e helpers.Environment, ) } -func wrapperDeploy( +func WrapperDeploy( e helpers.Environment, link, linkEthFeed, coordinator common.Address, ) (common.Address, *big.Int) { @@ -199,7 +217,7 @@ func wrapperDeploy( return address, subID } -func wrapperConfigure( +func WrapperConfigure( e helpers.Environment, wrapperAddress common.Address, wrapperGasOverhead, coordinatorGasOverhead, premiumPercentage uint, @@ -230,7 +248,7 @@ func wrapperConfigure( helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } -func wrapperConsumerDeploy( +func WrapperConsumerDeploy( e helpers.Environment, link, wrapper common.Address, ) common.Address { @@ -243,3 +261,13 @@ func wrapperConsumerDeploy( fmt.Printf("VRFV2WrapperConsumerExample address: %s\n", address) return address } + +func EoaV2PlusLoadTestConsumerWithMetricsDeploy(e helpers.Environment, consumerCoordinator string) (consumerAddress common.Address) { + _, tx, _, err := vrf_v2plus_load_test_with_metrics.DeployVRFV2PlusLoadTestWithMetrics( + e.Owner, + e.Ec, + common.HexToAddress(consumerCoordinator), + ) + helpers.PanicErr(err) + return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) +}