Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 4 additions & 8 deletions contracts/Aavegotchi/InitDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {IERC165} from "../shared/interfaces/IERC165.sol";
import {IERC721} from "../shared/interfaces/IERC721.sol";
import {IDiamondLoupe} from "../shared/interfaces/IDiamondLoupe.sol";
import {IERC173} from "../shared/interfaces/IERC173.sol";
import {ILink} from "./interfaces/ILink.sol";

import "./libraries/LibAppStorage.sol";

contract InitDiamond {
AppStorage internal s;
Expand All @@ -22,9 +23,8 @@ contract InitDiamond {
string name;
string symbol;
address ghstContract;
bytes32 chainlinkKeyHash;
uint64 subscriptionId;
address vrfCoordinator;
RequestConfig requestConfig;
}

function init(Args memory _args) external {
Expand All @@ -44,14 +44,10 @@ contract InitDiamond {
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true;
ds.supportedInterfaces[type(IERC173).interfaceId] = true;
ds.supportedInterfaces[(type(IERC721).interfaceId)] = true;

s.ghstContract = _args.ghstContract;
s.keyHash = _args.chainlinkKeyHash;
s.subscriptionId = _args.subscriptionId;
s.vrfCoordinator = _args.vrfCoordinator;

s.requestConfig = _args.requestConfig;
s.listingFeeInWei = 1e17;

s.name = _args.name;
s.symbol = _args.symbol;
}
Expand Down
113 changes: 0 additions & 113 deletions contracts/Aavegotchi/facets/PolygonXGeistBridgeFacet.sol

This file was deleted.

67 changes: 29 additions & 38 deletions contracts/Aavegotchi/facets/VRFFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import {Modifiers} from "../libraries/LibAppStorage.sol";
import {LibMeta} from "../../shared/libraries/LibMeta.sol";
import {LibERC721Marketplace} from "../libraries/LibERC721Marketplace.sol";
import {LibAavegotchi} from "../libraries/LibAavegotchi.sol";
import {ILink} from "../interfaces/ILink.sol";
import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol";
import {REQUEST_CONFIRMATIONS, NO_OF_WORDS, VRF_GAS_LIMIT} from "../libraries/LibAppStorage.sol";
// import {ILink} from "../interfaces/ILink.sol";

import {RequestConfig} from "../libraries/LibAppStorage.sol";
//import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol";
// // import {REQUEST_CONFIRMATIONS, NO_OF_WORDS, VRF_GAS_LIMIT} from "../libraries/LibAppStorage.sol";

import {IVRF} from "../interfaces/IVRF.sol";

import {LibVrf} from "../libraries/LibVrf.sol";

//import "hardhat/console.sol";

Expand Down Expand Up @@ -102,14 +108,6 @@ contract VrfFacet is Modifiers {
return s.vrfCoordinator;
}

// function link() external view returns (address) {
// return address(s.link);
// }

function keyHash() external view returns (bytes32) {
return s.keyHash;
}

/***********************************|
| Write Functions |
|__________________________________*/
Expand All @@ -135,12 +133,16 @@ contract VrfFacet is Modifiers {

function drawRandomNumber(uint256 _tokenId) internal returns (uint256 requestId_) {
s.aavegotchis[_tokenId].status = LibAavegotchi.STATUS_VRF_PENDING;
requestId_ = VRFCoordinatorV2Interface(s.vrfCoordinator).requestRandomWords(
s.keyHash,
s.subscriptionId,
REQUEST_CONFIRMATIONS,
VRF_GAS_LIMIT,
NO_OF_WORDS

requestId_ = IVRF(s.vrfCoordinator).requestRandomWords(
LibVrf.RandomWordsRequest({
keyHash: s.requestConfig.keyHash,
subId: s.requestConfig.subId,
requestConfirmations: s.requestConfig.requestConfirmations,
callbackGasLimit: s.requestConfig.callbackGasLimit,
numWords: s.requestConfig.numWords,
extraArgs: LibVrf._argsToBytes(LibVrf.ExtraArgsV1({nativePayment: s.requestConfig.nativePayment}))
})
);
s.vrfRequestIdToTokenId[requestId_] = _tokenId;
// for testing
Expand Down Expand Up @@ -178,14 +180,12 @@ contract VrfFacet is Modifiers {
* @param _requestId The Id initially returned by requestRandomness
* @param _randomWords the VRF output
*/
function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external {
function rawFulfillRandomWords(uint256 _requestId, uint256[] calldata _randomWords) external {
require(LibMeta.msgSender() == s.vrfCoordinator, "Only VRFCoordinator can fulfill");
uint256 tokenId = s.vrfRequestIdToTokenId[_requestId];
require(s.aavegotchis[tokenId].status == LibAavegotchi.STATUS_VRF_PENDING, "VrfFacet: VRF is not pending");

s.aavegotchis[tokenId].status = LibAavegotchi.STATUS_OPEN_PORTAL;
s.tokenIdToRandomNumber[tokenId] = _randomWords[0];

emit PortalOpened(tokenId);
emit VrfRandomNumber(tokenId, _randomWords[0], block.timestamp);
}
Expand All @@ -195,23 +195,14 @@ contract VrfFacet is Modifiers {
//@param _keyHash New keyhash
//@param _vrfCoordinator The new vrf coordinator address
//@param _link New LINK token contract address
function changeVrf(uint64 _newSubscriptionId, bytes32 _keyHash, address _vrfCoordinator) external onlyOwner {
if (_newSubscriptionId != 0) {
s.subscriptionId = _newSubscriptionId;
}
if (_keyHash != 0) {
s.keyHash = _keyHash;
}
if (_vrfCoordinator != address(0)) {
s.vrfCoordinator = _vrfCoordinator;
}
}

function getVrfInfo() public view returns (uint64, bytes32, address, string memory) {
return (s.subscriptionId, s.keyHash, s.vrfCoordinator, s.name);
function setConfig(RequestConfig calldata _requestConfig) external onlyOwner {
s.requestConfig = RequestConfig(
_requestConfig.keyHash,
_requestConfig.subId,
_requestConfig.requestConfirmations,
_requestConfig.callbackGasLimit,
_requestConfig.numWords,
_requestConfig.nativePayment
);
}
// // Remove the LINK tokens from this contract that are used to pay for VRF random number fees
// function removeLinkTokens(address _to, uint256 _value) external onlyOwner {
// s.link.transfer(_to, _value);
// }
}
8 changes: 8 additions & 0 deletions contracts/Aavegotchi/interfaces/IVRF.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pragma solidity 0.8.1;

import {LibVrf} from "../libraries/LibVrf.sol";

//to totally circumvent chainlink contracct solidity version requirements
interface IVRF {
function requestRandomWords(LibVrf.RandomWordsRequest calldata req) external returns (uint256 requestId);
}
19 changes: 14 additions & 5 deletions contracts/Aavegotchi/libraries/LibAppStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ uint256 constant NUMERIC_TRAITS_NUM = 6;
uint256 constant TRAIT_BONUSES_NUM = 5;
uint256 constant PORTAL_AAVEGOTCHIS_NUM = 10;

uint16 constant REQUEST_CONFIRMATIONS = 3;
uint32 constant NO_OF_WORDS = 1;
uint32 constant VRF_GAS_LIMIT = 2_500_000;
// uint16 constant REQUEST_CONFIRMATIONS = 3;
// uint32 constant NO_OF_WORDS = 1;
// uint32 constant VRF_GAS_LIMIT = 2_500_000;

struct RequestConfig {
bytes32 keyHash;
uint256 subId;
uint16 requestConfirmations;
uint32 callbackGasLimit;
uint32 numWords;
bool nativePayment;
}

// switch (traitType) {
// case 0:
Expand Down Expand Up @@ -295,8 +304,6 @@ struct AppStorage {
//VRF
mapping(uint256 => uint256) vrfRequestIdToTokenId;
// mapping(bytes32 => uint256) vrfNonces;
bytes32 keyHash;
uint64 subscriptionId;
address vrfCoordinator;
// Marketplace
uint256 nextERC1155ListingId;
Expand Down Expand Up @@ -389,6 +396,8 @@ struct AppStorage {
address gotchGeistBridge;
address itemGeistBridge;
mapping(address => bool) baazaarTradingAllowlist; // allowlist for baazaar trading
//chainlink vrf 2.5
RequestConfig requestConfig;
}

library LibAppStorage {
Expand Down
24 changes: 24 additions & 0 deletions contracts/Aavegotchi/libraries/LibVrf.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.1;

// End consumer library.
library LibVrf {
// extraArgs will evolve to support new features
bytes4 public constant EXTRA_ARGS_V1_TAG = bytes4(keccak256("VRF ExtraArgsV1"));
struct ExtraArgsV1 {
bool nativePayment;
}

struct RandomWordsRequest {
bytes32 keyHash;
uint256 subId;
uint16 requestConfirmations;
uint32 callbackGasLimit;
uint32 numWords;
bytes extraArgs;
}

function _argsToBytes(ExtraArgsV1 memory extraArgs) internal pure returns (bytes memory bts) {
return abi.encodeWithSelector(EXTRA_ARGS_V1_TAG, extraArgs);
}
}
2 changes: 1 addition & 1 deletion data/airdrops/collaterals/collateralTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export function getCollaterals(

if (network === "kovan") {
collateralAddress = collateralType.kovanAddress;
} else if (network === "hardhat") {
} else if (network === "hardhat" || network === "localhost") {
collateralAddress = ghstAddress;
} else if (network === "mainnet") {
collateralAddress = collateralType.mainnetAddress;
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default {
baseSepolia: {
url: process.env.BASE_SEPOLIA_URL,
accounts: [process.env.SECRET],
chainId: 84532,
},

// gorli: {
Expand Down
Loading