pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

contract BitcoinWorldCurrencyGuess {

// Address of the NFT collection

address public nftCollection;

// Mapping of NFT token IDs to boolean values indicating whether a guess has been made

mapping(uint256 => bool) public guessMade;

// Mapping of dates to number of guesses made for that date

mapping(uint256 => uint256) public dateToGuesses;

// Total number of guesses allowed

uint256 public totalGuesses;

// ETH amount locked up in the contract from the mint of the NFT token

uint256 public lockedETH;

// Address of the oracle providing the Bitcoin/USD exchange rate

address public oracle;

// Aggregator interface for the Bitcoin/USD exchange rate

AggregatorV3Interface internal priceFeed;

// Uniswap V2 router contract address

address public uniswapRouter;

// Address of the wrapped Bitcoin contract

address public wbtcAddress;

// Event emitted when a guess is made for an NFT

event GuessMade(address indexed guesser, uint256 indexed tokenId, uint256 guessDate);

// Event emitted when the correct date is verified and the ETH is swapped for WBTC and distributed to the winner(s)

event WinnerSelected(address indexed winner, uint256 indexed winningDate, uint256 wbtcAmount);

constructor(address _nftCollection, uint256 _totalGuesses, uint256 _lockedETH, address _oracle, address _uniswapRouter, address _wbtcAddress) {

nftCollection = _nftCollection;

totalGuesses = _totalGuesses;

lockedETH = _lockedETH;

oracle = _oracle;

priceFeed = AggregatorV3Interface(oracle);

uniswapRouter = _uniswapRouter;

wbtcAddress = _wbtcAddress;

}

// Function to make a guess for an NFT

function makeGuess(uint256 _tokenId, uint256 _guessDate) public {

require(msg.sender == ownerOf(_tokenId), "BitcoinWorldCurrencyGuess: sender is not owner of NFT");

require(!guessMade[_tokenId], "BitcoinWorldCurrencyGuess: guess already made for NFT");

require(dateToGuesses[_guessDate] < totalGuesses, "BitcoinWorldCurrencyGuess: too many guesses for that date");

// Record the guess for the NFT and the date

guessMade[_tokenId] = true;

dateToGuesses[_guessDate]++;

// Emit GuessMade event

emit GuessMade(msg.sender, _tokenId, _guessDate);

}

// Function to select the winner(s), swap ETH for WBTC, and distribute the WBTC to the winner(s)

function selectWinner() public {

require(isBitcoinWorldCurrency(), "BitcoinWorldCurrencyGuess: Bitcoin is not the world currency yet");

// Calculate the winning date and the number of winners

uint256 winningDate;

uint256 maxGuesses = 0;

uint256 numWinners = 0;

for (uint256 i = 0; i < totalGuesses; i++) {

if (dateToGuesses[i] > maxGuesses) {

winningDate = i;

Reply to this note

Please Login to reply.

Discussion

No replies yet.