Created
February 21, 2022 18:36
-
-
Save PascalDuval/12464af9f51c3016578232d3f5391e96 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.4; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract Ico2 is ERC20, Ownable { | |
uint256 public trusteeCount; | |
uint256 public goal = 1111 ether; | |
uint256 public priceToken = 0.01 ether; | |
bool public isIcoActive; | |
uint256 public contractEtherBalance; // Ethers received by the contract | |
event Participated(); | |
event ICOFinished(); | |
constructor() ERC20("BILDUNG", "BLD") { | |
_mint(msg.sender, 0 * 10 ** decimals()); // pre-minted tokens here equal to 0 | |
isIcoActive = true; | |
} | |
function participate() external payable { | |
require(isIcoActive, "ICO inactive"); | |
require(msg.value > 0.01 ether, "Participation must be over 0.01 ether !"); | |
if(contractEtherBalance + msg.value >= goal) { | |
contractEtherBalance += msg.value; // allow to add anyway | |
_mint(msg.sender, msg.value / priceToken); | |
isIcoActive = false; // but stop the ICO | |
emit ICOFinished(); | |
} | |
else { | |
contractEtherBalance += msg.value; | |
_mint(msg.sender, msg.value / priceToken); | |
} | |
emit Participated(); | |
trusteeCount +=1; | |
} | |
function getICOParameters() public view returns(uint256 icoGoal, uint256 icoEtherBalance, bool isActive, uint256 totalTokenSupply, | |
uint256 icoParticipantCount, string memory tokenSymbol, string memory icoName, uint256 numTrustees) | |
{ | |
icoGoal = goal; | |
icoEtherBalance = contractEtherBalance; | |
isActive = isIcoActive; | |
totalTokenSupply = totalSupply(); | |
icoParticipantCount = trusteeCount; | |
tokenSymbol = symbol(); | |
icoName = name(); | |
numTrustees = trusteeCount; | |
} | |
function sendbackEther(address payable owner) public onlyOwner { // on renvoie au owner du contrat uniquemet | |
owner.transfer(address(this).balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Une amélioration substantielle de https://github.com/adorsys/p2p-lending/blob/master/contracts/IcoContract/TrustToken.sol qui utilise la V4 de OpenZeppelin