diff --git a/contracts/CreatorToken.sol b/contracts/CreatorToken.sol index d6a301e..3080243 100644 --- a/contracts/CreatorToken.sol +++ b/contracts/CreatorToken.sol @@ -1,12 +1,11 @@ //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.0; -import "hardhat/console.sol"; import "./Stakeable.sol"; import { Sqrt } from "./Math.sol"; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; -import "@openzeppelin/contracts/utils/math/SafeMath.sol"; +import "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "../node_modules/@openzeppelin/contracts/access/Ownable.sol"; +import "../node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol"; /** * @title CreatorToken @@ -64,8 +63,18 @@ contract CreatorToken is Stakeable, ERC20, Ownable { _burn(_receiver, _amount); } - function getEthBalance() public view returns (uint256) { - return address(this).balance; - } + function getEthBalance() public view returns (uint256) { + return address(this).balance; + } + + function calculateStakeReturns(uint256 _amount) public view returns (uint256, uint256){ + uint amountToMint = (_amount / (totalMinted * 1000000)).sqrt(); + + if(amountToMint == 0) revert("not enough ETH for minting a token"); + + uint amountForSender = (amountToMint * (100 - founderPercentage) / 100 ); + uint amountForOwner = (amountToMint * founderPercentage) / 100 ; + return (amountForSender, amountForOwner); + } } diff --git a/contracts/Math.sol b/contracts/Math.sol index 6aea3f0..f22fe6e 100644 --- a/contracts/Math.sol +++ b/contracts/Math.sol @@ -1,7 +1,6 @@ //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.0; -import "hardhat/console.sol"; /** * @title Math diff --git a/contracts/Stakeable.sol b/contracts/Stakeable.sol index df58a0f..854faa2 100644 --- a/contracts/Stakeable.sol +++ b/contracts/Stakeable.sol @@ -1,7 +1,6 @@ //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.0; -import "hardhat/console.sol"; /** * @title Stakeable diff --git a/test/CreatorToken.ts b/test/CreatorToken.ts index edd979d..79be3f3 100644 --- a/test/CreatorToken.ts +++ b/test/CreatorToken.ts @@ -165,6 +165,30 @@ describe("CreatorToken", () => { ).to.be.revertedWith("not enough tokens to withdraw"); }) }) + describe("View", () => { + let provider: any; + const oneFinneyTxMetadata = { value: ethers.utils.parseUnits("1.0", "finney").toNumber() }; + + beforeEach(async () => { + provider = await ethers.getDefaultProvider(); + const Sqrt = await ethers.getContractFactory("Sqrt"); + const sqrtUtil = await Sqrt.deploy(); + await sqrtUtil.deployed(); + + CreatorToken = await ethers.getContractFactory("CreatorToken", { + libraries: { + Sqrt: sqrtUtil.address + } + }); + token = await CreatorToken.deploy(1000, "CreatorTest", "TST"); + await token.deployed(); + [owner, addr1, ...addresses] = await ethers.getSigners(); + }) + it("Should let users see how many tokens will be deployed", async () => { + const tokens = await token.connect(addr1).calculateStakeReturns(ethers.utils.parseUnits("1.0", "finney").toNumber()) + expect(tokens[0].toNumber()).to.equal(900); + }) + }) }); const floatIsWithinDelta = (floatOne: number, floatTwo: number, delta = 0.001) : Boolean => {