From 64d2882e950aa640d02bbd3a794cac6584c6dfd2 Mon Sep 17 00:00:00 2001 From: Kostia Degtiarenko Date: Thu, 4 Nov 2021 11:27:24 +0200 Subject: [PATCH 1/4] Update 2_deploy_contracts.js --- migrations/2_deploy_contracts.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index bdd80d30..76cd5b31 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -7,11 +7,11 @@ const { BN, time } = require('@openzeppelin/test-helpers'); const { ZERO_ADDRESS } = require('@openzeppelin/test-helpers/src/constants'); const argv = require('minimist')(process.argv.slice(2), { - string: ['ipfs_hash'], + string: ['ipfs_hash'] }); const argvMigration = require('minimist')(process.argv.slice(2), { - string: ['migration'], + string: ['migration'] }); const migration = argvMigration['migration']; let runMigration = null; @@ -29,6 +29,7 @@ var RCOrderbook = artifacts.require('./RCOrderbook.sol'); var RCLeaderboard = artifacts.require('./RCLeaderboard.sol'); var NftHubL2 = artifacts.require('./nfthubs/RCNftHubL2.sol'); var NftHubL1 = artifacts.require('./nfthubs/RCNftHubL1.sol'); +var RCAchievements = artifacts.require('./nfthubs/RCAchievements.sol'); var RealitioMockup = artifacts.require('./mockups/RealitioMockup.sol'); var tokenMockup = artifacts.require('./mockups/tokenMockup.sol'); @@ -91,7 +92,7 @@ module.exports = async (deployer, network, accounts) => { // tell treasury about factory & ARB, tell factory about nft hub and reference await treasury.setFactoryAddress(factory.address, { gas: 200000 }); await factory.setReferenceContractAddress(reference.address, { - gas: 100000, + gas: 100000 }); await factory.setNftHubAddress(nftHubL2.address, { gas: 100000 }); await factory.setRealitioAddress(realitio.address, { gas: 100000 }); @@ -161,6 +162,8 @@ module.exports = async (deployer, network, accounts) => { nftHubL2 = await NftHubL2.deployed(); await deployer.deploy(NftHubL1, MintableERC721PredicateProxy); nftHubL1 = await NftHubL1.deployed(); + await deployer.deploy(RCAchievements, childChainManager); + achievements = await RCAchievements.deployed(); // tell treasury and factory about various things await treasury.setFactoryAddress(factory.address); await treasury.setOrderbookAddress(orderbook.address); @@ -172,7 +175,7 @@ module.exports = async (deployer, network, accounts) => { // fund accounts for (let index = 0; index < 101; index++) { await erc20.transfer(accounts[index], '1000000000000000000000', { - from: accounts[0], + from: accounts[0] }); } //whitelist accounts @@ -191,6 +194,7 @@ module.exports = async (deployer, network, accounts) => { market, factory, treasury, + achievements, ipfsHashes, time, createMarket, @@ -218,6 +222,7 @@ module.exports = async (deployer, network, accounts) => { console.log('factory.address: ', factory.address); console.log('orderbook.address: ', orderbook.address); console.log('leaderboard.address: ', leaderboard.address); + console.log('achievements.address: ', achievements.address); } else { console.log('No deploy script for this network'); } @@ -238,7 +243,7 @@ async function createMarket(options) { artistAddress: ZERO_ADDRESS, affiliateAddress: ZERO_ADDRESS, cardAffiliate: [], // remember this is an array - sponsorship: 0, + sponsorship: 0 }; options = setDefaults(options, defaults); // assemble arrays @@ -284,7 +289,7 @@ async function createMarket(options) { async function closeMarket(options) { var defaults = { market: market[0], - winningOutcome: 0, + winningOutcome: 0 }; options = setDefaults(options, defaults); @@ -309,7 +314,7 @@ async function rent(options) { outcome: 0, from: 0x00, timeLimit: 0, - startingPosition: ZERO_ADDRESS, + startingPosition: ZERO_ADDRESS }; options = setDefaults(options, defaults); @@ -359,7 +364,7 @@ async function exit(options) { var defaults = { market: market[0], outcome: 0, - from: 0x00, + from: 0x00 }; options = setDefaults(options, defaults); @@ -370,16 +375,16 @@ async function sponsor(options) { var defaults = { market: market[0], amount: 0, - from: 0x00, + from: 0x00 }; options = setDefaults(options, defaults); var amount = web3.utils.toWei(options.amount.toString(), 'ether'); await erc20.approve(treasury.address, amount, { - from: options.from, + from: options.from }); await options.market.sponsor(options.from, amount, { - from: options.from, + from: options.from }); } From a8b257a758fc0ed05463f669be3f18c85f7f2939 Mon Sep 17 00:00:00 2001 From: Kostia Degtiarenko Date: Thu, 4 Nov 2021 18:29:47 +0200 Subject: [PATCH 2/4] added tokenId argument --- contracts/nfthubs/RCAchievements.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/nfthubs/RCAchievements.sol b/contracts/nfthubs/RCAchievements.sol index 37869083..9a1a89e6 100644 --- a/contracts/nfthubs/RCAchievements.sol +++ b/contracts/nfthubs/RCAchievements.sol @@ -60,7 +60,7 @@ contract RCAchievements is string imageURI, string requirements ); - event achievementAwarded(address user, uint256 achievementIndex); + event achievementAwarded(address user, uint256 achievementIndex, uint256 tokenId); event userEligableForAchievement(address user, uint256 achievementIndex); /*╔═════════════════════════════════╗ @@ -112,7 +112,7 @@ contract RCAchievements is function awardAchievement(address user, uint256 achievementIndex) public { _mint(user, mintCount); _setTokenURI(mintCount, achievementArray[achievementIndex].imageURI); - emit achievementAwarded(user, achievementIndex); + emit achievementAwarded(user, achievementIndex, mintCount); } function allowAchievement(address user, uint256 achievementIndex) public { From 7606bbddc1a7a1a6a2ac8983d2e6f737f777e8b6 Mon Sep 17 00:00:00 2001 From: Kostia Degtiarenko Date: Thu, 11 Nov 2021 14:10:11 +0200 Subject: [PATCH 3/4] fixed mintcount --- contracts/nfthubs/RCAchievements.sol | 39 ++++++++++++++++------------ 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/contracts/nfthubs/RCAchievements.sol b/contracts/nfthubs/RCAchievements.sol index 9a1a89e6..3ee8c13a 100644 --- a/contracts/nfthubs/RCAchievements.sol +++ b/contracts/nfthubs/RCAchievements.sol @@ -8,13 +8,13 @@ pragma solidity 0.8.7; ██║ ██║███████╗██║ ██║███████╗██║ ██║ ██║ ╚██████╗██║ ██║██║ ██║██████╔╝███████║ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝ */ -import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; -import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; -import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; -import "@openzeppelin/contracts/access/AccessControl.sol"; -import "hardhat/console.sol"; -import "../lib/NativeMetaTransaction.sol"; +import '@openzeppelin/contracts/token/ERC721/ERC721.sol'; +import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol'; +import '@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol'; +import '@openzeppelin/contracts/access/Ownable.sol'; +import '@openzeppelin/contracts/access/AccessControl.sol'; +import 'hardhat/console.sol'; +import '../lib/NativeMetaTransaction.sol'; /// @title Reality Cards Achievements NFT Hub /// @author Daniel Chilvers @@ -44,9 +44,9 @@ contract RCAchievements is mapping(uint256 => address) public marketTracker; /// @dev governance variables - bytes32 public constant UBER_OWNER = keccak256("UBER_OWNER"); - bytes32 public constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE"); - bytes32 public constant MINTER = keccak256("MINTER"); + bytes32 public constant UBER_OWNER = keccak256('UBER_OWNER'); + bytes32 public constant DEPOSITOR_ROLE = keccak256('DEPOSITOR_ROLE'); + bytes32 public constant MINTER = keccak256('MINTER'); mapping(uint256 => bool) public withdrawnTokens; event TransferWithMetadata( address indexed from, @@ -60,7 +60,11 @@ contract RCAchievements is string imageURI, string requirements ); - event achievementAwarded(address user, uint256 achievementIndex, uint256 tokenId); + event achievementAwarded( + address user, + uint256 achievementIndex, + uint256 tokenId + ); event userEligableForAchievement(address user, uint256 achievementIndex); /*╔═════════════════════════════════╗ @@ -71,13 +75,13 @@ contract RCAchievements is ║ CONSTRUCTOR ║ ╚═════════════════════════════════╝*/ - constructor(address childChainManager) ERC721("RealityCards", "RC") { + constructor(address childChainManager) ERC721('RealityCards', 'RC') { require( childChainManager != address(0), - "Must add childChainManager address" + 'Must add childChainManager address' ); // initialise MetaTransactions - _initializeEIP712("RealityCardsNftHubL2", "1"); + _initializeEIP712('RealityCardsNftHubL2', '1'); _setupRole(DEFAULT_ADMIN_ROLE, msgSender()); _setupRole(MINTER, msgSender()); _setupRole(DEPOSITOR_ROLE, childChainManager); @@ -89,7 +93,7 @@ contract RCAchievements is function setTokenURI(uint256 _tokenId, string calldata _tokenURI) external { address _msgSender = msgSender(); - require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender), "Not Authorised"); + require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender), 'Not Authorised'); _setTokenURI(_tokenId, _tokenURI); } @@ -113,6 +117,7 @@ contract RCAchievements is _mint(user, mintCount); _setTokenURI(mintCount, achievementArray[achievementIndex].imageURI); emit achievementAwarded(user, achievementIndex, mintCount); + mintCount++; } function allowAchievement(address user, uint256 achievementIndex) public { @@ -187,7 +192,7 @@ contract RCAchievements is function withdraw(uint256 tokenId) external { require( _isApprovedOrOwner(msgSender(), tokenId), - "ChildMintableERC721: INVALID_TOKEN_OWNER" + 'ChildMintableERC721: INVALID_TOKEN_OWNER' ); withdrawnTokens[tokenId] = true; _burn(tokenId); @@ -196,7 +201,7 @@ contract RCAchievements is function withdrawWithMetadata(uint256 tokenId) external { require( _isApprovedOrOwner(msgSender(), tokenId), - "ChildMintableERC721: INVALID_TOKEN_OWNER" + 'ChildMintableERC721: INVALID_TOKEN_OWNER' ); withdrawnTokens[tokenId] = true; From 3f511c3c9da42b7328b72a2e0ea1292b81889a62 Mon Sep 17 00:00:00 2001 From: Kostia Degtiarenko Date: Fri, 12 Nov 2021 13:48:47 +0200 Subject: [PATCH 4/4] added hash check --- contracts/nfthubs/RCAchievements.sol | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/contracts/nfthubs/RCAchievements.sol b/contracts/nfthubs/RCAchievements.sol index 3ee8c13a..6eb440f1 100644 --- a/contracts/nfthubs/RCAchievements.sol +++ b/contracts/nfthubs/RCAchievements.sol @@ -129,7 +129,19 @@ contract RCAchievements is ║ CORE FUNCTIONS ║ ╚═════════════════════════════════╝*/ - function claimAchievement(uint256 achievementIndex) public { + function claimAchievement(uint256 achievementIndex, bytes32 secret) public { + uint256 secret_number = 69; + require( + secret == + keccak256( + abi.encodePacked( + secret_number, + achievementIndex, + msg.sender + ) + ), + 'Achievement is unavailable' + ); awardAchievement(msgSender(), achievementIndex); }