Skip to content

Commit

Permalink
fixed nft shares
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinter410 committed Jun 16, 2023
1 parent bc7c9ce commit 40593a4
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6,199 deletions.
39 changes: 19 additions & 20 deletions contracts/NumberRunnerClub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
require(isStacked[tokenId] == false, "Cannot burn a stacked token");
uint8 _pieceType = getPieceType(tokenId);
require(_pieceType != 0, "Cannot burn the King");
uint256 taxAmount = (tokenBalance[tokenId] * pieceDetails[_pieceType].burnTax) / 100;
uint256 balance = tokenBalance[tokenId];
uint256 reward = (shareTypeAccumulator[_pieceType][epoch] - nftShares[tokenId]);
uint256 taxAmount = (reward * pieceDetails[_pieceType].burnTax) / 100;
// TODO revoir la redistribution pour gérer les arrondis
uint256 holdersTax = taxAmount / 2;
prizePool += taxAmount / 2;
Expand Down Expand Up @@ -200,8 +200,8 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
userOwnedNFTs[msg.sender][indexNFT] = userOwnedNFTs[msg.sender][userOwnedNFTs[msg.sender].length - 1];
userOwnedNFTs[msg.sender].pop();
currentSupply--;
tokenBalance[tokenId] = 0;
payable(msg.sender).transfer(balance - taxAmount);
nftShares[tokenId] = epoch; // ???
payable(msg.sender).transfer(reward - taxAmount);
}

// comment verifier que le token stake provient bien de la collection ?
Expand Down Expand Up @@ -300,8 +300,9 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
require(isForSale(tokenId), "NFT is not for sale");
address seller = ownerOf(tokenId);

uint256 taxAmount = (tokenBalance[tokenId] * 16) / 100;
uint256 balance = tokenBalance[tokenId];
uint256 _pieceType = getPieceType(tokenId);
uint256 reward = (shareTypeAccumulator[_pieceType][epoch] - nftShares[tokenId]);
uint256 taxAmount = (reward * 16) / 100;

prizePool += taxAmount / 2;
uint256 holdersTax = taxAmount / 2;
Expand All @@ -315,8 +316,8 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
}
}

tokenBalance[tokenId] = 0;
payable(seller).transfer(balance - taxAmount);
nftShares[tokenId] = epoch; /// ???
payable(seller).transfer(reward - taxAmount);
safeTransferFrom(msg.sender, buyer, tokenId);
uint256 indexNFT = findIndexOfOwnedNFT(msg.sender, tokenId);
userOwnedNFTs[seller][indexNFT] = userOwnedNFTs[seller][userOwnedNFTs[seller].length - 1];
Expand Down Expand Up @@ -455,14 +456,6 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
isKingsHandSet = true;
}

// Laquelle des deux fonctions utiliser ? Et reverser a la cagnotte du nft ou directement transfer au holder?
function distributeKingAuction() private {
uint256 pieceShare = kingHandsPrize / kingHands.length;
for (uint256 i = 0; i < kingHands.length; i++) {
tokenBalance[kingHands[i]] += pieceShare;
}
}

function claimKingHand(uint256 tokenId) public {
require(totalMinted == MAX_NFT_SUPPLY && currentSupply == 999, "Collection not ended yet");

Expand All @@ -478,7 +471,7 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
}
require(isKingHand, "Token must be a King's Hand");
uint256 pieceShare = kingHandsPrize / kingHands.length;
tokenBalance[tokenId] += pieceShare;
// tokenBalance[tokenId] += pieceShare; faire un transfer ici
kingHands[i] = kingHands[kingHands.length - 1];
kingHands.pop();
}
Expand Down Expand Up @@ -542,9 +535,10 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
function claimPrivatePrize(uint256 tokenId) public {
require(totalMinted == MAX_NFT_SUPPLY && currentSupply <= 999, "Burn or sell the nft to claim your rewards");
require(ownerOf(tokenId) == msg.sender, "Not owner of NFT");
uint256 balance = tokenBalance[tokenId];
tokenBalance[tokenId] = 0;
payable(msg.sender).transfer(balance);
uint8 _pieceType = getPieceType(tokenId);
uint256 reward = (shareTypeAccumulator[_pieceType][epoch] - nftShares[tokenId]);
nftShares[tokenId] = epoch;
payable(msg.sender).transfer(reward);
}

function spawnKings() public {
Expand Down Expand Up @@ -610,6 +604,11 @@ contract NumberRunnerClub is INumberRunnerClub, ERC721URIStorage, VRFV2WrapperCo
return (shareTypeAccumulator.length, shareTypeAccumulator[0].length);
}

function getReward(uint256 tokenId) public view returns (uint) {
uint8 _pieceType = getPieceType(tokenId);
return (shareTypeAccumulator[_pieceType][epoch] - nftShares[tokenId]);
}

// a terminer
// function auctionEnded(uint256 _price, address _newOwner, uint256 _tokenId) public {
// kingHandsPrize += _price;
Expand Down
106 changes: 60 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dependencies": {
"dotenv": "^16.0.3",
"ethers": "^6.6.0",
"ganache": "^7.8.0"
},
"devDependencies": {
"@chainlink/contracts": "^0.5.1",
"@ensdomains/ens-contracts": "^0.0.21",
"@openzeppelin/contracts": "^4.9.1",
"ethers": "^6.6.0",
"truffle": "^5.9.4"
"truffle": "^5.8.4"
}
}
19 changes: 11 additions & 8 deletions test/NRC.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
const NumberRunnerClub = artifacts.require("NumberRunnerClub");
const ethers = require("ethers");


module.exports = async function(callback) {
try {
console.log(ethers.version)
const instance = await NumberRunnerClub.deployed();
// await instance.chooseColor(1, {from: "0x892a8ae9356f6706a6c2a0d0431b66d7e4eca3d1"})
for (let i = 0; i < 100; i++) {
const _Mint = await instance.mint(5, {from: "0x892a8ae9356f6706a6c2a0d0431b66d7e4eca3d1", value: web3.utils.toWei('0.21', 'ether')});
await instance.chooseColor(1, {from: "0xaa174310699b475FeCA57060Dc644EFb056FF877"})
for (let i = 0; i < 5; i++) {
const _Mint = await instance.mint(5,0, {from: "0xaa174310699b475FeCA57060Dc644EFb056FF877", value: web3.utils.toWei('0.21', 'ether')});
console.log("Gas used MINT :", _Mint.receipt.gasUsed)
id = _Mint.logs[0].args.tokenId.words[0]
console.log(id)
console.log(`Minted token ${id}`);
await instance.approve("0x9C163b47501670493E363ad855A99A6F5f282Dc0", id)
await instance.approve("0x2b9a4aB7a36cc4514f7D2BE2B70A4065A8AC49E5", id)
const _Stake = await instance.stack(web3.utils.asciiToHex("121.eth"), id);
console.log("Gas used STAKING :", _Stake.receipt.gasUsed)
console.log(_Stake.logs[0].args)
// console.log(_Stake.logs[0].args)
console.log(`Staked token ${id}`);

console.log("Rewards du 362 : ", (await instance.getReward(362)).toString());

}

let size = await instance.getTotalSharePerTokenSize();
let size = await instance.getShareTypeAccumulatorSize();
for (let i = 0; i < size[0]; i++) {
for (let j = 0; j < size[1]; j++) {
let element = await instance.getTotalSharePerToken(i, j);
let element = await instance.getShareTypeAccumulator(i, j);
console.log(`totalSharePerToken[${i}][${j}] = ${element}`);
}
}
Expand Down
11 changes: 6 additions & 5 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ module.exports = {
// tab if you use this network and you must also set the `host`, `port` and `network_id`
// options below to some value.
//
// development: {
// host: "127.0.0.1", // Localhost (default: none)
// port: 8545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
gas: 50000000 // Change this value
},
//
// goerli: {
// provider: () => new HDWalletProvider(mnemonic, `https://goerli.infura.io/v3/${infuraProjectId}`),
Expand Down
Loading

0 comments on commit 40593a4

Please sign in to comment.