Skip to content

Instantly share code, notes, and snippets.

@arkhaminferno
Created October 2, 2019 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkhaminferno/26aa1e06f828b431179d6a5d98a09b4f to your computer and use it in GitHub Desktop.
Save arkhaminferno/26aa1e06f828b431179d6a5d98a09b4f 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.4.26+commit.4563c3fc.js&optimize=false&gist=
pragma solidity ^0.4.11;
contract hadcoin_ico{
// Introducing the total number of hadcoin tokens available for sealed
uint public max_hadcoins = 1000000;
// Introducing the USD to hadcoin conversion rate
uint public usd_to_hadcoins = 1000;
// Introducing the total number of hadcoins that have been bought by the investors
uint public total_hadcoins_bought = 0;
// Mapping from the investor address to its equity in hadcoins and USD
mapping(address => uint) equity_hadcoins;
mapping(address => uint) equity_usd;
// Checking if an investor can buy Hadcoins
modifier can_buy_hadcoins(uint usd_invested) {
require(usd_invested * usd_to_hadcoins + total_hadcoins_bought <= max_hadcoins);
_;
}
// Getting the equity in Hadcoins of an investor
function equity_in_hadcoins(address investor) external constant returns(uint){
return equity_hadcoins[investor];
}
// Getting the equity in USD of an investor
function equity_in_usd(address investor) external constant returns(uint){
return equity_usd[investor];
}
//Buy Hadcoins
function buy_hadcoins(address investor ,uint usd_invested) external
can_buy_hadcoins(usd_invested)
{
uint hadcoins_bought = usd_invested * usd_to_hadcoins;
equity_hadcoins[investor] += hadcoins_bought;
equity_usd[investor] = equity_hadcoins[investor] / 1000;
total_hadcoins_bought += hadcoins_bought;
}
// Selling Hadcoin
function sell_hadcoins(address investor,uint hadcoins_sold) external{
equity_hadcoins[investor] -= hadcoins_sold;
equity_usd[investor] = equity_hadcoins[investor] / 1000;
total_hadcoins_bought -= hadcoins_sold;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment