Skip to content

Commit

Permalink
fix : remove node verification on stack function
Browse files Browse the repository at this point in the history
  • Loading branch information
Wagalidoom committed Nov 7, 2023
1 parent c90e517 commit b81ad9e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
11 changes: 6 additions & 5 deletions contracts/NumberRunnerClub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ contract NumberRunnerClub is ERC721URIStorage, Ownable, ReentrancyGuard {
event NFTKilled(uint256 tokenId);

uint256 constant ONE_WEEK = 1 weeks;
bytes32 constant ETH_NODE = keccak256(abi.encodePacked(bytes32(0), keccak256(abi.encodePacked(".eth"))));

struct PieceDetails {
uint256 maxSupply;
Expand Down Expand Up @@ -484,12 +485,12 @@ contract NumberRunnerClub is ERC721URIStorage, Ownable, ReentrancyGuard {
}

function stack(bytes32 label, uint256 tokenId) external {
bytes32 node = keccak256(abi.encodePacked(label, ".eth"));
// bytes32 labelHash = uint256(keccak256(abi.encodePacked(label)));
// Ensure the function caller owns the ENS node
require(ens.owner(node) == msg.sender, "Not owner of ENS node");
// require(ens.owner(node) == msg.sender, "Not owner of ENS node");
require(!isForSale(tokenId), "This NFT is already on sale");
require(nodeOfTokenId[tokenId] == 0x0, "Token is already stacked");
require(tokenIdOfNode[node] == 0, "ENS name is already used");
// require(tokenIdOfNode[node] == 0, "ENS name is already used");
// Ensure the function caller owns the NFT
require(ownerOf(tokenId) == msg.sender, "Not owner of NFT");

Expand Down Expand Up @@ -532,9 +533,9 @@ contract NumberRunnerClub is ERC721URIStorage, Ownable, ReentrancyGuard {
// Transfer the NFT to this contract
transferFrom(msg.sender, address(this), tokenId);
// Set the token ID for the ENS node
nodeOfTokenId[tokenId] = node;
// nodeOfTokenId[tokenId] = node;
nameOfTokenId[tokenId] = label;
tokenIdOfNode[node] = tokenId;
// tokenIdOfNode[node] = tokenId;
emit NFTStacked(tokenId, label, expiration[tokenId]);
}

Expand Down
21 changes: 14 additions & 7 deletions contracts/NumberRunnerClubGoerli.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "truffle/console.sol";
import "abdk-libraries-solidity/ABDKMath64x64.sol";
import "@ensdomains/ens-contracts/contracts/registry/ENS.sol";
import "@ensdomains/ens-contracts/contracts/ethregistrar/BaseRegistrarImplementation.sol";
Expand Down Expand Up @@ -147,8 +148,10 @@ contract NumberRunnerClubGoerli is ERC721URIStorage, Ownable, ReentrancyGuard {
event UpdateUnclaimedRewards(uint256 tokenId, uint256 rewards);
event KingHandRevealed(bool success);
event NFTKilled(uint256 tokenId);
event DebugInfo(bytes32 label, bytes32 labelHash, bytes32 node);

uint256 constant ONE_WEEK = 1 weeks;
bytes32 constant ETH_NODE = keccak256(abi.encodePacked(bytes32(0), keccak256(abi.encodePacked(".eth"))));

struct PieceDetails {
uint256 maxSupply;
Expand Down Expand Up @@ -236,12 +239,12 @@ contract NumberRunnerClubGoerli is ERC721URIStorage, Ownable, ReentrancyGuard {
}

modifier saleIsActive() {
require(currentSupply + MAX_NFT_SUPPLY - totalMinted > 999, "Collection ended");
require(currentSupply + MAX_NFT_SUPPLY - totalMinted > 999);
_;
}

modifier saleIsNotActive() {
require(!(currentSupply + MAX_NFT_SUPPLY - totalMinted > 999), "Collection not ended");
require(!(currentSupply + MAX_NFT_SUPPLY - totalMinted > 999));
_;
}

Expand Down Expand Up @@ -455,7 +458,7 @@ contract NumberRunnerClubGoerli is ERC721URIStorage, Ownable, ReentrancyGuard {
currentSupply--;

if (rewards > 0) {
require(address(this).balance >= rewards - (rewards * 15) / 100, "Not enough balance in contract to send rewards");
require(address(this).balance >= rewards - (rewards * 15) / 100);
if (nodeOfTokenId[tokenId] != 0x0) {
payable(ens.owner(nodeOfTokenId[tokenId])).transfer(rewards - (rewards * 15) / 100);
tokenIdOfNode[nodeOfTokenId[tokenId]] = 0;
Expand Down Expand Up @@ -483,8 +486,12 @@ contract NumberRunnerClubGoerli is ERC721URIStorage, Ownable, ReentrancyGuard {
expiration[tokenId] = getDomainExpirationDate(name);
}

function stack(bytes32 label, uint256 tokenId) external {
bytes32 node = keccak256(abi.encodePacked(label, ".eth"));
function stack(bytes32 label, uint256 tokenId) external returns (bytes32, bytes32, bytes32) {
bytes32 labelHash = keccak256(abi.encodePacked(label));
bytes32 node = keccak256(abi.encodePacked(ETH_NODE, labelHash));

emit DebugInfo(label, labelHash, node);
return (label, labelHash, node);
// Ensure the function caller owns the ENS node
require(ens.owner(node) == msg.sender, "Not owner of ENS node");
require(!isForSale(tokenId), "This NFT is already on sale");
Expand Down Expand Up @@ -574,7 +581,7 @@ contract NumberRunnerClubGoerli is ERC721URIStorage, Ownable, ReentrancyGuard {

function listNFT(uint256 tokenId, uint256 price) external saleIsActive {
require(!isForSale(tokenId));
require(_isApprovedOrOwner(msg.sender, tokenId), "ERC721: transfer caller is not owner nor approved");
require(_isApprovedOrOwner(msg.sender, tokenId));
require(price > 0);
approve(address(this), tokenId);
_setNftPrice(tokenId, price);
Expand Down Expand Up @@ -891,4 +898,4 @@ contract NumberRunnerClubGoerli is ERC721URIStorage, Ownable, ReentrancyGuard {
function getPrizePool() external view returns (uint256) {
return prizePool;
}
}
}
16 changes: 9 additions & 7 deletions test/killNft.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const ethers = require("ethers");
const namehash = require('eth-ens-namehash');
const BigNumber = require('bignumber.js');

const userA = "0x3A1BECdd4AaaE635e3ea41257Ca755ED32Cf36d3";
const userB = "0x67169E1Af4de6cd667871C58bD1a0b7980070350";
const contractAddress = "0x056A9414630e8940b120853dd90FD74368A08708";
const userA = "0xd7C2361eF31db331b44d027732d02DFb64a16ef9";
const userB = "0xd61c2C4954d95398F3a541865d6300464C2b7Ad1";
const contractAddress = "0xa0D0d8F4e793457D6fBf5C789C03C749A7174F82";

const chooseColor = async (instance, colorIndex, fromAddress) => {
await instance.chooseColor(colorIndex, { from: fromAddress });
Expand Down Expand Up @@ -43,8 +43,8 @@ const approveToken = async (instance, tokenId, toAddress, fromAddress) => {
};

const stackToken = async (instance, domain, tokenId, fromAddress) => {
await instance.stack(namehash.hash(domain), web3.utils.asciiToHex(domain), tokenId, { from: fromAddress });
console.log(`Stacked token ${tokenId}`);
const _Stack = await instance.stack(web3.utils.asciiToHex(domain), tokenId, { from: fromAddress });
console.log(`Stacked token ${JSON.stringify(_Stack, null, 2)}`);
};

const unstackToken = async (instance, tokenId, fromAddress) => {
Expand Down Expand Up @@ -79,11 +79,13 @@ module.exports = async function(callback) {
const instance = await NumberRunnerClubGoerli.deployed();
const balance = await web3.eth.getBalance(contractAddress);
console.log("Deployed ! Contract balance : ",balance);
await chooseColor(instance, 1, userA);

await stackToken(instance, "764", 370, userA);
// await chooseColor(instance, 1, userA);
// await chooseColor(instance, 2, userB);
// const tokenId1 = await mintToken(instance, userA, 20000000000000);
// const tokenId2 = await mintToken(instance, userA, 20000000000000);
const tokenId1 = await multiMint(instance, 17, userA, 2000000000000000);
// const tokenId1 = await multiMint(instance, 17, userA, 2000000000000000);
// await listToken(instance, tokenId1, web3.utils.toWei('10', 'ether'), userA);
// await burnToken(instance, "370", userA);
// await stackToken(instance, "17921.eth", tokenId1, userA);
Expand Down

0 comments on commit b81ad9e

Please sign in to comment.