Skip to content

Commit

Permalink
change VRF to 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
joezhou618 committed Jun 22, 2024
1 parent 2f1e665 commit 25b185b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
35 changes: 19 additions & 16 deletions contracts/vrf/VRFConsumerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
// An example of a consumer contract that relies on a subscription for funding.
pragma solidity ^0.8.7;

// import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol";
import {VRFConsumerBaseV2Plus} from "@chainlink/contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol";
import {VRFV2PlusClient} from "@chainlink/contracts/src/v0.8/dev/vrf/libraries/VRFV2PlusClient.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";

// import {Executor} from "seaport-core/lib/Executor.sol";
/**
* @title The VRFConsumerV2 contract
* @notice A contract that gets random values from Chainlink VRF V2
*/
contract VRFConsumerV2 is VRFConsumerBaseV2, AccessControl {
VRFCoordinatorV2Interface immutable COORDINATOR;
// LinkTokenInterface immutable LINKTOKEN;
// ISeaportContract immutable Seaport;
contract VRFConsumerV2 is VRFConsumerBaseV2Plus, AccessControl {

// Your subscription ID.
uint64 immutable s_subscriptionId;
Expand Down Expand Up @@ -59,8 +55,7 @@ contract VRFConsumerV2 is VRFConsumerBaseV2, AccessControl {
* @param vrfCoordinator - coordinator, check https://docs.chain.link/docs/vrf-contracts/#configurations
* @param keyHash - the gas lane to use, which specifies the maximum gas price to bump to
*/
constructor(uint64 subscriptionId, address vrfCoordinator, bytes32 keyHash) VRFConsumerBaseV2(vrfCoordinator) {
COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);
constructor(uint64 subscriptionId, address vrfCoordinator, bytes32 keyHash) VRFConsumerBaseV2Plus(vrfCoordinator) {
// LINKTOKEN = LinkTokenInterface(link);
s_keyHash = keyHash;
s_owner = msg.sender;
Expand All @@ -82,14 +77,22 @@ contract VRFConsumerV2 is VRFConsumerBaseV2, AccessControl {
* Assumes the subscription is funded sufficiently; "Words" refers to unit of data in Computer Science
*/
function requestRandomWords(uint32 s_numWords) external onlyRole(MARKET) returns (uint256) {
// Will revert if subscription is not set and funded.
s_requestId = COORDINATOR.requestRandomWords(
s_keyHash,
s_subscriptionId,
s_requestConfirmations,
s_callbackGasLimit,
s_numWords

s_requestId = s_vrfCoordinator.requestRandomWords(
VRFV2PlusClient.RandomWordsRequest({
keyHash: s_keyHash,
subId: s_subscriptionId,
requestConfirmations: s_requestConfirmations,
callbackGasLimit: s_callbackGasLimit,
numWords: s_numWords,
extraArgs: VRFV2PlusClient._argsToBytes(
VRFV2PlusClient.ExtraArgsV1({
nativePayment: false
})
)
})
);

return s_requestId;
}

Expand Down
14 changes: 8 additions & 6 deletions scripts/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const VRFConfig: {
[k: string]: { coor: string; subId: BigNumberish; keyHash: string };
} = {
sepolia: {
coor: "0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625",
subId: 7066,
keyHash: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c",
coor: "0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B",
subId: 88287894418893955350156106731922667574706298581066323091458404590883695184525,
keyHash: "0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae",
},
arbitrum_sepolia: {
coor: "0x50d47e4142598E3411aA864e08a44284e471AC6f",
Expand All @@ -24,9 +24,9 @@ const VRFConfig: {
};

const MemberConfig: { [k: string]: string } = {
sepolia: "0x7ddBFF9D74D0A2F33Dfb13cEC538B334f2011462",
arb_sepolia: "0x0da3C82d0785ad289Be2Cb6cE7382a879E72d18b",
arbitrum_sepolia: "0x7ddBFF9D74D0A2F33Dfb13cEC538B334f2011462",
sepolia: "0x7a9b890aEC794B8EFfdCd6b743A6A3AF950e99F9",
arb_sepolia: "0x7a9b890aEC794B8EFfdCd6b743A6A3AF950e99F9",
arbitrum_sepolia: "0x7a9b890aEC794B8EFfdCd6b743A6A3AF950e99F9",
};

async function main() {
Expand All @@ -50,6 +50,8 @@ async function main() {
]);
const vrf = await ethers.getContractAt("VRFConsumerV2", vrfAddress);
const roleMarket = await vrf.MARKET();
console.log("roleMarket");
console.log(roleMarket);
if (!(await vrf.hasRole(roleMarket, marketAddress))) {
await vrf.connect(owner).grantRole(roleMarket, marketAddress, { gasLimit: 2000000 }).then(wait1Tx);
}
Expand Down

0 comments on commit 25b185b

Please sign in to comment.