Skip to content

Commit

Permalink
clean up contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Oct 25, 2023
1 parent e1e640c commit 0e98ac3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 9 additions & 3 deletions packages/hardhat/contracts/FeedRegistryConsumer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol";
import "@chainlink/contracts/src/v0.8/Denominations.sol";

/**Contract to consume the Chainlink FeedRegistry
/** Simple contract to consume the Chainlink FeedRegistry
*
* @notice FeedRegistry address only exists on the Ethereum Mainnet
* @notice https://docs.chain.link/data-feeds/feed-registry#contract-addresses
*/

contract FeedRegistryConsumer {
FeedRegistryInterface internal immutable i_registry;

Expand All @@ -21,8 +22,13 @@ contract FeedRegistryConsumer {
* Get the latest price of ETH/USD
*/
function getEthUsdPrice() public view returns (int) {
(, /*uint80 roundID*/ int price, , , ) = /*uint startedAt*/ /*uint timeStamp*/ /*uint80 answeredInRound*/
i_registry.latestRoundData(Denominations.ETH, Denominations.USD);
(
,
/*uint80 roundID*/ int price /*uint startedAt*/ /*uint timeStamp*/ /*uint80 answeredInRound*/,
,
,

) = i_registry.latestRoundData(Denominations.ETH, Denominations.USD);
return price;
}

Expand Down
22 changes: 12 additions & 10 deletions packages/hardhat/contracts/VRFConsumer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol";
import "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";

/**
* Spin the wheel to get a random number from chainlink VRF
/** Simple contract that request random numbers from chainlink VRF
*
* this example uses the "Direct Funding" method
* https://docs.chain.link/vrf#two-methods-to-request-randomness
*/

contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {
// State Variables
// if gas consumed by fulfillRandomWords() exceeds this limit, the transaction will revert
uint32 callbackGasLimit = 100000;
// blocks before chainlink node responds (must be greater than a minimum amout set by VRF coordinator contract)
uint16 requestConfirmations = 3;
// how many random numbers to generate
uint32 numValues = 1;
address public linkAddress;
uint32 callbackGasLimit = 100000; // limit for gas can be used when chainlink node calls fulfillRandomWords()
uint16 requestConfirmations = 3; // blocks before chainlink node responds (must be greater than a minimum amout set by VRF coordinator contract)
uint32 numValues = 1; // how many random numbers to generate

// keeping track of who requested which random number
mapping(uint256 => address) public s_spinners; // requestId => msg.sender
mapping(address => uint256) public s_results; // msg.sender => random number

// Events
event WheelSpun(uint256 indexed requestId, address indexed spinner);
event WheelResult(
uint256 indexed requestId,
Expand All @@ -38,7 +42,7 @@ contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {

/** This function triggers the request to chainlink node that generates the random number
*
* "requestRandomness()" is inherited from VRFV2WrapperConsumerBase
* requestRandomness() is inherited from VRFV2WrapperConsumerBase
*
* @return requestId each request has a unique ID
*/
Expand Down Expand Up @@ -68,7 +72,6 @@ contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {
uint256 requestId,
uint256[] memory randomWords
) internal override {
// The remainder of division by 6 can only be 0 - 5
uint256 randomNumber = (randomWords[0] % 6);
// update mapping to record who received which random number by using the requestId
s_results[s_spinners[requestId]] = randomNumber;
Expand All @@ -83,7 +86,6 @@ contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {
);
}

// Getters
function getLinkBalance() public view returns (uint256) {
LinkTokenInterface link = LinkTokenInterface(linkAddress);
return link.balanceOf(address(this));
Expand Down

0 comments on commit 0e98ac3

Please sign in to comment.