Skip to content

Commit

Permalink
VRFv2 feedback #2 (#5175)
Browse files Browse the repository at this point in the history
* V3 listener working with integration test

* Testing offchain sim

* Address misc audit feedback

* Cleanup

* Lints, fix MaliciousConsumer test and add a reserved link test

* Fmt and fix linter after rebasing

* Contract lint

* Little more time for tx fulfillment

* Some comments about gasAfterPaymentCalc

* Address go feedback

* Add tiered fees

* More tiers

* Remove unused event and include fallback linketh price in public config

* Bump timeouts on FM tests and remove redundant app stop

* Fix FM tests, remove unused import

* One more

Co-authored-by: autorebase-bot <92488320+autorebase-bot@users.noreply.github.com>
Co-authored-by: Jordan Krage <jmank88@gmail.com>
  • Loading branch information
3 people committed Oct 18, 2021
1 parent ee26835 commit 6c6d8eb
Show file tree
Hide file tree
Showing 27 changed files with 1,518 additions and 894 deletions.
287 changes: 169 additions & 118 deletions contracts/src/v0.8/dev/VRFCoordinatorV2.sol

Large diffs are not rendered by default.

42 changes: 1 addition & 41 deletions contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,6 @@
pragma solidity ^0.8.0;

interface VRFCoordinatorV2Interface {
/**
* @notice Returns the global config that applies to all VRF requests.
* @return minimumRequestBlockConfirmations - A minimum number of confirmation
* blocks on VRF requests before oracles should respond.
* @return fulfillmentFlatFeeLinkPPM - The charge per request on top of the gas fees.
* Its flat fee specified in millionths of LINK.
* @return maxGasLimit - The maximum gas limit supported for a fulfillRandomWords callback.
* @return stalenessSeconds - How long we wait until we consider the ETH/LINK price
* (used for converting gas costs to LINK) is stale and use `fallbackWeiPerUnitLink`
* @return gasAfterPaymentCalculation - How much gas is used outside of the payment calculation,
* i.e. the gas overhead of actually making the payment to oracles.
* @return minimumSubscriptionBalance - The minimum subscription balance required to make a request. Its set to be about 300%
* of the cost of a single request to handle in ETH/LINK price between request and fulfillment time.
* @return fallbackWeiPerUnitLink - fallback ETH/LINK price in the case of a stale feed.
*/
function getConfig()
external
view
returns (
uint16 minimumRequestBlockConfirmations,
uint32 fulfillmentFlatFeeLinkPPM,
uint32 maxGasLimit,
uint32 stalenessSeconds,
uint32 gasAfterPaymentCalculation,
uint96 minimumSubscriptionBalance,
int256 fallbackWeiPerUnitLink
);

/**
* @notice Request a set of random words.
* @param keyHash - Corresponds to a particular oracle job which uses
Expand All @@ -47,7 +19,7 @@ interface VRFCoordinatorV2Interface {
* may be slightly less than this amount because of gas used calling the function
* (argument decoding etc.), so you may need to request slightly more than you expect
* to have inside fulfillRandomWords. The acceptable range is
* [5000, maxGasLimit].
* [0, maxGasLimit]
* @param numWords - The number of uint256 random values you'd like to receive
* in your fulfillRandomWords callback. Note these numbers are expanded in a
* secure way by the VRFCoordinator from a single random value supplied by the oracle.
Expand Down Expand Up @@ -119,18 +91,6 @@ interface VRFCoordinatorV2Interface {
*/
function removeConsumer(uint64 subId, address consumer) external;

/**
* @notice Withdraw funds from a VRF subscription
* @param subId - ID of the subscription
* @param to - Where to send the withdrawn LINK to
* @param amount - How much to withdraw in juels
*/
function defundSubscription(
uint64 subId,
address to,
uint96 amount
) external;

/**
* @notice Cancel a subscription
* @param subId - ID of the subscription
Expand Down
6 changes: 6 additions & 0 deletions contracts/src/v0.8/tests/VRFConsumerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ contract VRFConsumerV2 is VRFConsumerBaseV2 {
LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(s_subId));
}

function topUpSubscription(uint96 amount) external {
require(s_subId != 0, "sub not set");
// Approve the link transfer.
LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(s_subId));
}

function updateSubscription(address[] memory consumers) external {
require(s_subId != 0, "subID not set");
for (uint256 i = 0; i < consumers.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/test-helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Contract, ContractTransaction } from 'ethers'
import type { providers } from 'ethers'
import { providers } from 'ethers'
import { assert } from 'chai'
import { ethers } from 'hardhat'
import cbor from 'cbor'
Expand Down
Loading

0 comments on commit 6c6d8eb

Please sign in to comment.