Skip to content

Commit

Permalink
Merge branch 'develop' into feature/re-1696-add-ci-lint-chaincli
Browse files Browse the repository at this point in the history
  • Loading branch information
momentmaker authored Sep 22, 2023
2 parents 28c9eb0 + 1734717 commit 87da816
Show file tree
Hide file tree
Showing 13 changed files with 2,016 additions and 109 deletions.
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all_vrf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ compileContract dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol
compileContract dev/vrf/TrustedBlockhashStore.sol
compileContract dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol
compileContractAltOpts dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol 5
compileContract dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol

# VRF V2 Wrapper
compileContract vrf/VRFV2Wrapper.sol
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

import "../VRFV2PlusWrapperConsumerBase.sol";
import "../../../shared/access/ConfirmedOwner.sol";
import "../../../ChainSpecificUtil.sol";

contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, ConfirmedOwner {
uint256 public s_responseCount;
uint256 public s_requestCount;
uint256 public s_averageFulfillmentInMillions = 0; // in millions for better precision
uint256 public s_slowestFulfillment = 0;
uint256 public s_fastestFulfillment = 999;
uint256 public s_lastRequestId;
mapping(uint256 => uint256) requestHeights; // requestIds to block number when rand request was made

event WrappedRequestFulfilled(uint256 requestId, uint256[] randomWords, uint256 payment);
event WrapperRequestMade(uint256 indexed requestId, uint256 paid);

struct RequestStatus {
uint256 paid;
bool fulfilled;
uint256[] randomWords;
uint requestTimestamp;
uint fulfilmentTimestamp;
uint256 requestBlockNumber;
uint256 fulfilmentBlockNumber;
bool native;
}

mapping(uint256 => RequestStatus) /* requestId */ /* requestStatus */ public s_requests;

constructor(
address _link,
address _vrfV2PlusWrapper
) ConfirmedOwner(msg.sender) VRFV2PlusWrapperConsumerBase(_link, _vrfV2PlusWrapper) {}

function makeRequests(
uint32 _callbackGasLimit,
uint16 _requestConfirmations,
uint32 _numWords,
uint16 _requestCount
) external onlyOwner {
for (uint16 i = 0; i < _requestCount; i++) {
uint256 requestId = requestRandomness(_callbackGasLimit, _requestConfirmations, _numWords);
s_lastRequestId = requestId;

uint256 requestBlockNumber = ChainSpecificUtil.getBlockNumber();
uint256 paid = VRF_V2_PLUS_WRAPPER.calculateRequestPrice(_callbackGasLimit);
s_requests[requestId] = RequestStatus({
paid: paid,
fulfilled: false,
randomWords: new uint256[](0),
requestTimestamp: block.timestamp,
requestBlockNumber: requestBlockNumber,
fulfilmentTimestamp: 0,
fulfilmentBlockNumber: 0,
native: false
});
s_requestCount++;
requestHeights[requestId] = requestBlockNumber;
emit WrapperRequestMade(requestId, paid);
}
}

function makeRequestsNative(
uint32 _callbackGasLimit,
uint16 _requestConfirmations,
uint32 _numWords,
uint16 _requestCount
) external onlyOwner {
for (uint16 i = 0; i < _requestCount; i++) {
uint256 requestId = requestRandomnessPayInNative(_callbackGasLimit, _requestConfirmations, _numWords);
s_lastRequestId = requestId;

uint256 requestBlockNumber = ChainSpecificUtil.getBlockNumber();
uint256 paid = VRF_V2_PLUS_WRAPPER.calculateRequestPriceNative(_callbackGasLimit);
s_requests[requestId] = RequestStatus({
paid: paid,
fulfilled: false,
randomWords: new uint256[](0),
requestTimestamp: block.timestamp,
requestBlockNumber: requestBlockNumber,
fulfilmentTimestamp: 0,
fulfilmentBlockNumber: 0,
native: true
});
s_requestCount++;
requestHeights[requestId] = requestBlockNumber;
emit WrapperRequestMade(requestId, paid);
}
}

function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override {
require(s_requests[_requestId].paid > 0, "request not found");
uint256 fulfilmentBlockNumber = ChainSpecificUtil.getBlockNumber();
uint256 requestDelay = fulfilmentBlockNumber - requestHeights[_requestId];
uint256 requestDelayInMillions = requestDelay * 1_000_000;

if (requestDelay > s_slowestFulfillment) {
s_slowestFulfillment = requestDelay;
}
s_fastestFulfillment = requestDelay < s_fastestFulfillment ? requestDelay : s_fastestFulfillment;
s_averageFulfillmentInMillions = s_responseCount > 0
? (s_averageFulfillmentInMillions * s_responseCount + requestDelayInMillions) / (s_responseCount + 1)
: requestDelayInMillions;

s_responseCount++;
s_requests[_requestId].fulfilled = true;
s_requests[_requestId].randomWords = _randomWords;
s_requests[_requestId].fulfilmentTimestamp = block.timestamp;
s_requests[_requestId].fulfilmentBlockNumber = fulfilmentBlockNumber;

emit WrappedRequestFulfilled(_requestId, _randomWords, s_requests[_requestId].paid);
}

function getRequestStatus(
uint256 _requestId
)
external
view
returns (
uint256 paid,
bool fulfilled,
uint256[] memory randomWords,
uint requestTimestamp,
uint fulfilmentTimestamp,
uint256 requestBlockNumber,
uint256 fulfilmentBlockNumber
)
{
require(s_requests[_requestId].paid > 0, "request not found");
RequestStatus memory request = s_requests[_requestId];
return (
request.paid,
request.fulfilled,
request.randomWords,
request.requestTimestamp,
request.fulfilmentTimestamp,
request.requestBlockNumber,
request.fulfilmentBlockNumber
);
}

function reset() external {
s_averageFulfillmentInMillions = 0; // in millions for better precision
s_slowestFulfillment = 0;
s_fastestFulfillment = 999;
s_requestCount = 0;
s_responseCount = 0;
}

/// @notice withdrawLink withdraws the amount specified in amount to the owner
/// @param amount the amount to withdraw, in juels
function withdrawLink(uint256 amount) external onlyOwner {
LINK.transfer(owner(), amount);
}

/// @notice withdrawNative withdraws the amount specified in amount to the owner
/// @param amount the amount to withdraw, in wei
function withdrawNative(uint256 amount) external onlyOwner {
(bool success, ) = payable(owner()).call{value: amount}("");
require(success, "withdrawNative failed");
}

function getWrapper() external view returns (VRFV2PlusWrapperInterface) {
return VRF_V2_PLUS_WRAPPER;
}

receive() external payable {}

function getBalance() public view returns (uint) {
return address(this).balance;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ vrfv2plus_malicious_migrator: ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigr
vrfv2plus_reverting_example: ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample.bin d8f9b537f4f75535e3fca943d5f2d5b891fc63f38eb04e0c219fee28033883ae
vrfv2plus_wrapper: ../../contracts/solc/v0.8.6/VRFV2PlusWrapper.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapper.bin d30c6232e24e7f6007bd9e46c23534d8da17fbf332f9dfd6485a476ef1be0af9
vrfv2plus_wrapper_consumer_example: ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample.bin d4ddf86da21b87c013f551b2563ab68712ea9d4724894664d5778f6b124f4e78
vrfv2plus_wrapper_load_test_consumer: ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.bin 8212afe0f981cd0820f46f1e2e98219ce5d1b1eeae502730dbb52b8638f9ad44
1 change: 1 addition & 0 deletions core/gethwrappers/go_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ package gethwrappers
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.abi ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.bin VRFV2PlusMaliciousMigrator vrfv2plus_malicious_migrator
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics.abi ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics.bin VRFV2PlusLoadTestWithMetrics vrf_v2plus_load_test_with_metrics
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion.abi ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion.bin VRFCoordinatorV2PlusUpgradedVersion vrf_v2plus_upgraded_version
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.bin VRFV2PlusWrapperLoadTestConsumer vrfv2plus_wrapper_load_test_consumer

// Aggregators
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/AggregatorV2V3Interface.abi ../../contracts/solc/v0.8.6/AggregatorV2V3Interface.bin AggregatorV2V3Interface aggregator_v2v3_interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
LinkEthFeedResponse = big.NewInt(1e18)
MinimumConfirmations = uint16(3)
RandomnessRequestCountPerRequest = uint16(1)
VRFSubscriptionFundingAmountLink = big.NewInt(100)
VRFSubscriptionFundingAmountLink = big.NewInt(10)
VRFSubscriptionFundingAmountNativeToken = big.NewInt(1)
ChainlinkNodeFundingAmountEth = big.NewFloat(0.1)
NumberOfWords = uint32(3)
Expand All @@ -28,4 +28,12 @@ var (
FulfillmentFlatFeeLinkPPM: 500,
FulfillmentFlatFeeEthPPM: 500,
}

WrapperGasOverhead = uint32(50_000)
CoordinatorGasOverhead = uint32(52_000)
WrapperPremiumPercentage = uint8(25)
WrapperMaxNumberOfWords = uint8(10)
WrapperConsumerFundingAmountNativeToken = big.NewFloat(1)

WrapperConsumerFundingAmountLink = big.NewInt(10)
)
5 changes: 5 additions & 0 deletions integration-tests/actions/vrfv2plus/vrfv2plus_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ type VRFV2PlusContracts struct {
BHS contracts.BlockHashStore
LoadTestConsumers []contracts.VRFv2PlusLoadTestConsumer
}

type VRFV2PlusWrapperContracts struct {
VRFV2PlusWrapper contracts.VRFV2PlusWrapper
LoadTestConsumers []contracts.VRFv2PlusWrapperLoadTestConsumer
}
Loading

0 comments on commit 87da816

Please sign in to comment.