Skip to content

Commit

Permalink
Return request price with requestRandomness (#10978)
Browse files Browse the repository at this point in the history
Co-authored-by: Sri Kidambi <[email protected]>
  • Loading branch information
kidambisrinivas and kidambisrinivas authored Oct 17, 2023
1 parent 93c75b1 commit 49b2fc0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
17 changes: 10 additions & 7 deletions contracts/src/v0.8/vrf/dev/VRFV2PlusWrapperConsumerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ abstract contract VRFV2PlusWrapperConsumerBase {
uint16 _requestConfirmations,
uint32 _numWords,
bytes memory extraArgs
) internal returns (uint256 requestId) {
) internal returns (uint256 requestId, uint256 reqPrice) {
reqPrice = i_vrfV2PlusWrapper.calculateRequestPrice(_callbackGasLimit);
s_linkToken.transferAndCall(
address(i_vrfV2PlusWrapper),
i_vrfV2PlusWrapper.calculateRequestPrice(_callbackGasLimit),
reqPrice,
abi.encode(_callbackGasLimit, _requestConfirmations, _numWords, extraArgs)
);
return i_vrfV2PlusWrapper.lastRequestId();
return (i_vrfV2PlusWrapper.lastRequestId(), reqPrice);
}

// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
Expand All @@ -92,15 +93,17 @@ abstract contract VRFV2PlusWrapperConsumerBase {
uint16 _requestConfirmations,
uint32 _numWords,
bytes memory extraArgs
) internal returns (uint256 requestId) {
uint256 requestPrice = i_vrfV2PlusWrapper.calculateRequestPriceNative(_callbackGasLimit);
return
) internal returns (uint256 requestId, uint256 requestPrice) {
requestPrice = i_vrfV2PlusWrapper.calculateRequestPriceNative(_callbackGasLimit);
return (
i_vrfV2PlusWrapper.requestRandomWordsInNative{value: requestPrice}(
_callbackGasLimit,
_requestConfirmations,
_numWords,
extraArgs
);
),
requestPrice
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ contract VRFV2PlusWrapperConsumerExample is VRFV2PlusWrapperConsumerBase, Confir
uint32 _numWords
) external onlyOwner returns (uint256 requestId) {
bytes memory extraArgs = VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: false}));
requestId = requestRandomness(_callbackGasLimit, _requestConfirmations, _numWords, extraArgs);
uint256 paid = i_vrfV2PlusWrapper.calculateRequestPrice(_callbackGasLimit);
uint256 paid;
(requestId, paid) = requestRandomness(_callbackGasLimit, _requestConfirmations, _numWords, extraArgs);
s_requests[requestId] = RequestStatus({paid: paid, randomWords: new uint256[](0), fulfilled: false, native: false});
emit WrapperRequestMade(requestId, paid);
return requestId;
Expand All @@ -42,8 +42,8 @@ contract VRFV2PlusWrapperConsumerExample is VRFV2PlusWrapperConsumerBase, Confir
uint32 _numWords
) external onlyOwner returns (uint256 requestId) {
bytes memory extraArgs = VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: true}));
requestId = requestRandomnessPayInNative(_callbackGasLimit, _requestConfirmations, _numWords, extraArgs);
uint256 paid = i_vrfV2PlusWrapper.calculateRequestPriceNative(_callbackGasLimit);
uint256 paid;
(requestId, paid) = requestRandomnessPayInNative(_callbackGasLimit, _requestConfirmations, _numWords, extraArgs);
s_requests[requestId] = RequestStatus({paid: paid, randomWords: new uint256[](0), fulfilled: false, native: true});
emit WrapperRequestMade(requestId, paid);
return requestId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi
) external onlyOwner {
for (uint16 i = 0; i < _requestCount; i++) {
bytes memory extraArgs = VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: false}));
uint256 requestId = requestRandomness(_callbackGasLimit, _requestConfirmations, _numWords, extraArgs);
(uint256 requestId, uint256 paid) = requestRandomness(
_callbackGasLimit,
_requestConfirmations,
_numWords,
extraArgs
);
s_lastRequestId = requestId;

uint256 requestBlockNumber = ChainSpecificUtil._getBlockNumber();
uint256 paid = i_vrfV2PlusWrapper.calculateRequestPrice(_callbackGasLimit);
s_requests[requestId] = RequestStatus({
paid: paid,
fulfilled: false,
Expand All @@ -74,11 +78,15 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi
) external onlyOwner {
for (uint16 i = 0; i < _requestCount; i++) {
bytes memory extraArgs = VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: true}));
uint256 requestId = requestRandomnessPayInNative(_callbackGasLimit, _requestConfirmations, _numWords, extraArgs);
(uint256 requestId, uint256 paid) = requestRandomnessPayInNative(
_callbackGasLimit,
_requestConfirmations,
_numWords,
extraArgs
);
s_lastRequestId = requestId;

uint256 requestBlockNumber = ChainSpecificUtil._getBlockNumber();
uint256 paid = i_vrfV2PlusWrapper.calculateRequestPriceNative(_callbackGasLimit);
s_requests[requestId] = RequestStatus({
paid: paid,
fulfilled: false,
Expand Down
Loading

0 comments on commit 49b2fc0

Please sign in to comment.