Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native payment to RandomWordsFulfilled event #12085

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
uint256 outputSeed,
uint256 indexed subId,
uint96 payment,
bool nativePayment,
bool success,
bool onlyPremium
);
Expand Down Expand Up @@ -457,28 +458,23 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
}
}

uint256 requestId = output.requestId;
delete s_requestCommitments[requestId];
bool success = _deliverRandomness(requestId, rc, randomWords);
delete s_requestCommitments[output.requestId];
bool success = _deliverRandomness(output.requestId, rc, randomWords);

// Increment the req count for the subscription.
uint256 subId = rc.subId;
++s_subscriptions[subId].reqCount;
++s_subscriptions[rc.subId].reqCount;

// stack too deep error
{
bool nativePayment = uint8(rc.extraArgs[rc.extraArgs.length - 1]) == 1;
bool nativePayment = uint8(rc.extraArgs[rc.extraArgs.length - 1]) == 1;

// We want to charge users exactly for how much gas they use in their callback.
// The gasAfterPaymentCalculation is meant to cover these additional operations where we
// decrement the subscription balance and increment the oracles withdrawable balance.
payment = _calculatePaymentAmount(startGas, gasPrice, nativePayment, onlyPremium);
// We want to charge users exactly for how much gas they use in their callback.
// The gasAfterPaymentCalculation is meant to cover these additional operations where we
// decrement the subscription balance and increment the oracles withdrawable balance.
payment = _calculatePaymentAmount(startGas, gasPrice, nativePayment, onlyPremium);

_chargePayment(payment, nativePayment, subId);
}
_chargePayment(payment, nativePayment, rc.subId);

// Include payment in the event for tracking costs.
emit RandomWordsFulfilled(requestId, randomness, subId, payment, success, onlyPremium);
emit RandomWordsFulfilled(output.requestId, randomness, rc.subId, payment, nativePayment, success, onlyPremium);

return payment;
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ contract VRFV2Plus is BaseTest {
VmSafe.Log[] memory entries = vm.getRecordedLogs();
assertEq(entries[0].topics[1], bytes32(uint256(requestId)));
assertEq(entries[0].topics[2], bytes32(uint256(subId)));
(uint256 loggedOutputSeed, , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool));
(uint256 loggedOutputSeed, , , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool, bool));
assertEq(loggedOutputSeed, outputSeed);
assertEq(loggedSuccess, true);

Expand Down Expand Up @@ -374,7 +374,7 @@ contract VRFV2Plus is BaseTest {
VmSafe.Log[] memory entries = vm.getRecordedLogs();
assertEq(entries[0].topics[1], bytes32(uint256(requestId)));
assertEq(entries[0].topics[2], bytes32(uint256(subId)));
(uint256 loggedOutputSeed, , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool));
(uint256 loggedOutputSeed, , , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool, bool));
assertEq(loggedOutputSeed, outputSeed);
assertEq(loggedSuccess, true);

Expand Down Expand Up @@ -624,7 +624,7 @@ contract VRFV2Plus is BaseTest {
VmSafe.Log[] memory entries = vm.getRecordedLogs();
assertEq(entries[0].topics[1], bytes32(uint256(requestId)));
assertEq(entries[0].topics[2], bytes32(uint256(subId)));
(uint256 loggedOutputSeed, , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool));
(uint256 loggedOutputSeed, , , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool, bool));
assertEq(loggedOutputSeed, outputSeed);
assertEq(loggedSuccess, true);

Expand Down Expand Up @@ -671,7 +671,7 @@ contract VRFV2Plus is BaseTest {
VmSafe.Log[] memory entries = vm.getRecordedLogs();
assertEq(entries[0].topics[1], bytes32(uint256(requestId)));
assertEq(entries[0].topics[2], bytes32(uint256(subId)));
(uint256 loggedOutputSeed, , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool));
(uint256 loggedOutputSeed, , , bool loggedSuccess) = abi.decode(entries[0].data, (uint256, uint256, bool, bool));
assertEq(loggedOutputSeed, outputSeed);
assertEq(loggedSuccess, true);

Expand Down
Loading
Loading