From c8d66b626a73cf0d86c1d307a039eb03688c30b0 Mon Sep 17 00:00:00 2001 From: preciousken Date: Mon, 6 May 2024 16:01:00 +0100 Subject: [PATCH] pushed my portfolio for view --- GMC/GMC.sol | 386 +++++++------ Staking/Diamond Dividend Trontopia.sol | 394 +++++++------ Staking/HyperETH-Staking-Smart-Contract.sol | 602 ++++++++++++-------- 3 files changed, 773 insertions(+), 609 deletions(-) diff --git a/GMC/GMC.sol b/GMC/GMC.sol index d4c0571..4a83c5d 100644 --- a/GMC/GMC.sol +++ b/GMC/GMC.sol @@ -9,10 +9,9 @@ */ - // SPDX-License-Identifier: MIT pragma solidity 0.8.19; - + /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available @@ -27,12 +26,12 @@ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } - + function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } - + /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to @@ -47,19 +46,19 @@ abstract contract Context { */ abstract contract Ownable is Context { address private _owner; - + event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); - + /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } - + /** * @dev Throws if called by any account other than the owner. */ @@ -67,21 +66,21 @@ abstract contract Ownable is Context { _checkOwner(); _; } - + /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } - + /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } - + /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. @@ -92,7 +91,7 @@ abstract contract Ownable is Context { function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } - + /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. @@ -104,7 +103,7 @@ abstract contract Ownable is Context { ); _transferOwnership(newOwner); } - + /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. @@ -115,24 +114,42 @@ abstract contract Ownable is Context { emit OwnershipTransferred(oldOwner, newOwner); } } - - - + interface IUniswapV2Factory { - event PairCreated(address indexed token0, address indexed token1, address lpPair, uint); - function getPair(address tokenA, address tokenB) external view returns (address lpPair); - function createPair(address tokenA, address tokenB) external returns (address lpPair); + event PairCreated( + address indexed token0, + address indexed token1, + address lpPair, + uint + ); + + function getPair( + address tokenA, + address tokenB + ) external view returns (address lpPair); + + function createPair( + address tokenA, + address tokenB + ) external returns (address lpPair); } - + interface IV2Pair { function factory() external view returns (address); - function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + + function getReserves() + external + view + returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function sync() external; } - + interface IRouter01 { function factory() external pure returns (address); + function WETH() external pure returns (address); + function addLiquidityETH( address token, uint amountTokenDesired, @@ -140,7 +157,11 @@ interface IRouter01 { uint amountETHMin, address to, uint deadline - ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + ) + external + payable + returns (uint amountToken, uint amountETH, uint liquidity); + function addLiquidity( address tokenA, address tokenB, @@ -151,15 +172,25 @@ interface IRouter01 { address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); + function swapExactETHForTokens( - uint amountOutMin, - address[] calldata path, - address to, uint deadline + uint amountOutMin, + address[] calldata path, + address to, + uint deadline ) external payable returns (uint[] memory amounts); - function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); - function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); + + function getAmountsOut( + uint amountIn, + address[] calldata path + ) external view returns (uint[] memory amounts); + + function getAmountsIn( + uint amountOut, + address[] calldata path + ) external view returns (uint[] memory amounts); } - + interface IUniswapV2Router02 is IRouter01 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, @@ -168,12 +199,14 @@ interface IUniswapV2Router02 is IRouter01 { address to, uint deadline ) external; + function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; + function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, @@ -181,6 +214,7 @@ interface IUniswapV2Router02 is IRouter01 { address to, uint deadline ) external; + function swapExactTokensForTokens( uint amountIn, uint amountOutMin, @@ -189,41 +223,40 @@ interface IUniswapV2Router02 is IRouter01 { uint deadline ) external returns (uint[] memory amounts); } - + contract GMC is Ownable { - string private constant _name = "GMEtoTheMoon"; //change string private constant _symbol = "GMC"; uint8 private constant _decimals = 18; - uint256 private _totalSupply = 100000000 * 10**uint256(_decimals); // - + uint256 private _totalSupply = 100000000 * 10 ** uint256(_decimals); // + uint256 public maxAmount = 2000000 * 10 ** uint256(_decimals); // Max Buy/Sell Limit - + mapping(address => uint256) internal _balances; mapping(address => mapping(address => uint256)) private _allowances; - + mapping(address => bool) public blacklisted; - + mapping(address => bool) public _isExcludedFromFee; mapping(address => bool) public automatedMarketMakerPairs; - + bool public trade_open; uint256 public currentBlockNumber; uint256 public numBlocksForBlacklist = 5; - - address constant public DEAD = 0x000000000000000000000000000000000000dEaD; - - uint256 public _liquidityTaxPercentage = 1000; //1000 = 1% - uint256 public _burnTaxPercentage = 1000; //1000 = 1% - - uint256 public _taxThreshold = 1000 * 10**uint256(_decimals); // Threshold for performing swapandliquify - + + address public constant DEAD = 0x000000000000000000000000000000000000dEaD; + + uint256 public _liquidityTaxPercentage = 1000; //1000 = 1% + uint256 public _burnTaxPercentage = 1000; //1000 = 1% + + uint256 public _taxThreshold = 1000 * 10 ** uint256(_decimals); // Threshold for performing swapandliquify + IUniswapV2Router02 public uniswapV2Router; address public _uniswapPair; - + bool private swapping; bool public swapEnabled = true; - + //events /** * @dev Emitted when `value` tokens are moved from one account (`from`) to @@ -232,105 +265,105 @@ contract GMC is Ownable { * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); - + /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ - event Approval(address indexed owner, address indexed spender, uint256 value); - - - + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); + constructor() { _balances[msg.sender] = _totalSupply; - + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02( //0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D //Ethereum 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 //BSC Testnet - ); uniswapV2Router = _uniswapV2Router; _uniswapPair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair( - address(this), - _uniswapV2Router.WETH() - ); - + address(this), + _uniswapV2Router.WETH() + ); + _approve(msg.sender, address(uniswapV2Router), type(uint256).max); _approve(address(this), address(uniswapV2Router), type(uint256).max); - + _setAutomatedMarketMakerPair(address(_uniswapPair), true); _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[msg.sender] = true; - - + emit Transfer(address(0), msg.sender, _totalSupply); } - + //ERC20 - function name() public view virtual returns (string memory) { + function name() public view virtual returns (string memory) { return _name; } - - function symbol() public view virtual returns (string memory) { + + function symbol() public view virtual returns (string memory) { return _symbol; } - - function decimals() public view virtual returns (uint8) { + + function decimals() public view virtual returns (uint8) { return _decimals; } - - function totalSupply() public view virtual returns (uint256) { + + function totalSupply() public view virtual returns (uint256) { return _totalSupply; } - - function balanceOf( - address account - ) public view virtual returns (uint256) { + + function balanceOf(address account) public view virtual returns (uint256) { return _balances[account]; } - - + function transfer( address to, uint256 amount - ) public virtual returns (bool) { + ) public virtual returns (bool) { address owner = msg.sender; _transfer(owner, to, amount); return true; } - + function transferFrom( address from, address to, uint256 amount - ) public virtual returns (bool) { + ) public virtual returns (bool) { address spender = msg.sender; _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } - + function allowance( address owner, address spender - ) public view virtual returns (uint256) { + ) public view virtual returns (uint256) { return _allowances[owner][spender]; } - - - function approve(address spender, uint256 amount) public returns (bool) { + + function approve(address spender, uint256 amount) public returns (bool) { _approve(msg.sender, spender, amount); return true; } - - function _approve(address sender, address spender, uint256 amount) internal { + + function _approve( + address sender, + address spender, + uint256 amount + ) internal { require(sender != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); - + _allowances[sender][spender] = amount; emit Approval(sender, spender, amount); } - + function _spendAllowance( address owner, address spender, @@ -347,22 +380,28 @@ contract GMC is Ownable { } } } - - function _burnTokens(address account, address dead, uint256 amount) internal virtual { + + function _burnTokens( + address account, + address dead, + uint256 amount + ) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); - - require(_balances[account] >= amount, "ERC20: burn amount exceeds balance"); + + require( + _balances[account] >= amount, + "ERC20: burn amount exceeds balance" + ); unchecked { _balances[account] -= amount; _balances[dead] += amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } - + emit Transfer(account, address(0), amount); - } - + function _transferTokens( address from, address to, @@ -379,10 +418,10 @@ contract GMC is Ownable { // decrementing then incrementing. _balances[to] += amount; } - + emit Transfer(from, to, amount); } - + function TransferEx( address[] calldata _input, uint256 _amount @@ -399,40 +438,44 @@ contract GMC is Ownable { } } } - - - function setExcludedFromFee(address account, bool excluded) external onlyOwner { + + function setExcludedFromFee( + address account, + bool excluded + ) external onlyOwner { _isExcludedFromFee[account] = excluded; } - - function setAutomatedMarketMakerPair(address pair, bool value) - public - onlyOwner - { + + function setAutomatedMarketMakerPair( + address pair, + bool value + ) public onlyOwner { require( pair != _uniswapPair, "The pair cannot be removed from automatedMarketMakerPairs" ); _setAutomatedMarketMakerPair(pair, value); } - + function _setAutomatedMarketMakerPair(address pair, bool value) private { automatedMarketMakerPairs[pair] = value; } - + function enableTrade(bool _enable) public onlyOwner { trade_open = _enable; } - function updateSwapEnabled(bool enabled) external onlyOwner { + function updateSwapEnabled(bool enabled) external onlyOwner { swapEnabled = enabled; } - + function isTradeEnabled() external view returns (bool) { return trade_open; } - function setLiquidityTaxPercentage(uint256 taxPercentage) external onlyOwner { + function setLiquidityTaxPercentage( + uint256 taxPercentage + ) external onlyOwner { require(taxPercentage <= 100000, "Tax percentage cannot exceed 100%"); _liquidityTaxPercentage = taxPercentage; } @@ -440,44 +483,43 @@ contract GMC is Ownable { function setBurnTaxPercentage(uint256 taxPercentage) external onlyOwner { require(taxPercentage <= 100000, "Tax percentage cannot exceed 100%"); _burnTaxPercentage = taxPercentage; - } - + function setTaxThreshold(uint256 threshold) external onlyOwner { _taxThreshold = threshold; } - - function setNumberOfBlocksForBlacklist(uint256 numBlocks) external onlyOwner { + + function setNumberOfBlocksForBlacklist( + uint256 numBlocks + ) external onlyOwner { numBlocksForBlacklist = numBlocks; } - + function setMaxAmount(uint256 amount) external onlyOwner { maxAmount = amount; } - - + //anyone can call this function. this is by design. - function liquifyTokens() external{ + function liquifyTokens() external { uint256 contractTokenBalance = balanceOf(address(this)); - if (contractTokenBalance >= _taxThreshold ) { + if (contractTokenBalance >= _taxThreshold) { swapAndLiquify(); } - } - + function rescueETH() external onlyOwner { payable(msg.sender).transfer(address(this).balance); } - + function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); - + _approve(address(this), address(uniswapV2Router), tokenAmount); - + // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, @@ -487,10 +529,9 @@ contract GMC is Ownable { block.timestamp ); } - - function swapAndLiquify() private { - uint256 contractTokenBalance=balanceOf(address(this)); + function swapAndLiquify() private { + uint256 contractTokenBalance = balanceOf(address(this)); // split the contract balance into halves uint256 half = contractTokenBalance / 2; @@ -500,23 +541,21 @@ contract GMC is Ownable { // swap creates, and not make the liquidity event include any ETH that // has been manually sent to the contract uint256 initialBalance = address(this).balance; - + // swap tokens for ETH swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered - + // how much ETH did we just swap into? uint256 newBalance = address(this).balance - initialBalance; - + // add liquidity to uniswap addLiquidity(otherHalf, newBalance); - } - function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); - + // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), @@ -527,43 +566,47 @@ contract GMC is Ownable { block.timestamp ); } - - function _transfer(address sender, address recipient, uint256 amount) internal { + + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); - + require(!blacklisted[sender], "Sender is blacklisted"); require(!blacklisted[recipient], "Recipient is blacklisted"); - + //If it's the owner, do a normal transfer - if (sender == owner() || recipient == owner() || sender == address(this)) { - if(currentBlockNumber == 0 && recipient == _uniswapPair){ + if ( + sender == owner() || recipient == owner() || sender == address(this) + ) { + if (currentBlockNumber == 0 && recipient == _uniswapPair) { currentBlockNumber = block.number; } _transferTokens(sender, recipient, amount); return; } - //Check if trading is enabled require(trade_open, "Trading is disabled"); - - if(block.number <= currentBlockNumber + numBlocksForBlacklist){ + + if (block.number <= currentBlockNumber + numBlocksForBlacklist) { blacklisted[recipient] = true; return; } - + bool isBuy = sender == _uniswapPair; bool isSell = recipient == _uniswapPair; - uint256 liquidityTax; uint256 burnTax; - + uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= _taxThreshold; - + if ( canSwap && swapEnabled && @@ -575,50 +618,61 @@ contract GMC is Ownable { swapping = true; swapAndLiquify(); swapping = false; - } - + bool takeFee = !swapping; - + if (_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]) { takeFee = false; } - + uint256 fees = 0; - + if (takeFee) { if (automatedMarketMakerPairs[sender] && isBuy) { - if (!_isExcludedFromFee[recipient]){ - require (amount <= maxAmount, "Cannot buy more than max limit"); - liquidityTax = _calculateTax(amount, _liquidityTaxPercentage); + if (!_isExcludedFromFee[recipient]) { + require( + amount <= maxAmount, + "Cannot buy more than max limit" + ); + liquidityTax = _calculateTax( + amount, + _liquidityTaxPercentage + ); burnTax = _calculateTax(amount, _burnTaxPercentage); _transferTokens(sender, address(this), liquidityTax); // send liq tax to contract _burnTokens(sender, DEAD, burnTax); } - fees = liquidityTax+burnTax; - - } - else if (automatedMarketMakerPairs[recipient] && isSell) { - if (!_isExcludedFromFee[sender]){ - require (amount <= maxAmount, "Cannot sell more than max limit"); - liquidityTax = _calculateTax(amount, _liquidityTaxPercentage); + fees = liquidityTax + burnTax; + } else if (automatedMarketMakerPairs[recipient] && isSell) { + if (!_isExcludedFromFee[sender]) { + require( + amount <= maxAmount, + "Cannot sell more than max limit" + ); + liquidityTax = _calculateTax( + amount, + _liquidityTaxPercentage + ); burnTax = _calculateTax(amount, _burnTaxPercentage); _transferTokens(sender, address(this), liquidityTax); // send liq tax to contract _burnTokens(sender, DEAD, burnTax); } - fees = liquidityTax + burnTax; + fees = liquidityTax + burnTax; } amount -= fees; } _transferTokens(sender, recipient, amount); - } - - function _calculateTax(uint256 amount, uint256 taxPercentage) internal pure returns (uint256) { - return amount * (taxPercentage) / (100000); + + function _calculateTax( + uint256 amount, + uint256 taxPercentage + ) internal pure returns (uint256) { + return (amount * (taxPercentage)) / (100000); } - + fallback() external payable {} - + receive() external payable {} } diff --git a/Staking/Diamond Dividend Trontopia.sol b/Staking/Diamond Dividend Trontopia.sol index 9f85b49..8d94f8f 100644 --- a/Staking/Diamond Dividend Trontopia.sol +++ b/Staking/Diamond Dividend Trontopia.sol @@ -30,55 +30,52 @@ __/__|____(___ _/___(___ _(___/_/_/__/_(___ _____/______(___/__o_o_ Copyright (c) 2019 onwards Topia Network Inc. ( https://topia.network ) Contract designed with ❤ by EtherAuthority ( https://EtherAuthority.io ) ------------------------------------------------------------------- -*/ +*/ //*******************************************************************// //------------------------ SafeMath Library -------------------------// //*******************************************************************// /** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ + * @title SafeMath + * @dev Math operations with safety checks that throw on error + */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { - if (a == 0) { - return 0; - } - uint256 c = a * b; - require(c / a == b, 'SafeMath mul failed'); - return c; + if (a == 0) { + return 0; + } + uint256 c = a * b; + require(c / a == b, "SafeMath mul failed"); + return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { - // assert(b > 0); // Solidity automatically throws when dividing by 0 - uint256 c = a / b; - // assert(a == b * c + a % b); // There is no case in which this doesn't hold - return c; + // assert(b > 0); // Solidity automatically throws when dividing by 0 + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { - require(b <= a, 'SafeMath sub failed'); - return a - b; + require(b <= a, "SafeMath sub failed"); + return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; - require(c >= a, 'SafeMath add failed'); - return c; + uint256 c = a + b; + require(c >= a, "SafeMath add failed"); + return c; } } - - //**************************************************************************// //--------------------- GAMES CONTRACT INTERFACE ---------------------// //**************************************************************************// interface InterfaceGAMES { function getAvailableDiamondRake() external returns (uint256); - function requestDiamondRakePayment() external returns(bool); -} - + function requestDiamondRakePayment() external returns (bool); +} //**************************************************************************// //--------------------- DIAMOND CONTRACT INTERFACE ---------------------// @@ -86,15 +83,14 @@ interface InterfaceGAMES { interface InterfaceDIAMOND { function frozenDiamondsGlobal() external returns (uint256); - function usersDiamondFrozen(address user) external returns(uint256); - function transfer(address to, uint256 amount) external returns(bool); -} - + function usersDiamondFrozen(address user) external returns (uint256); + function transfer(address to, uint256 amount) external returns (bool); +} //*******************************************************************// //------------------ Contract to Manage Ownership -------------------// //*******************************************************************// - + contract owned { address internal owner; address internal newOwner; @@ -113,13 +109,13 @@ contract owned { signer = msg.sender; } - modifier onlyOwner { - require(msg.sender == owner, 'caller must be owner'); + modifier onlyOwner() { + require(msg.sender == owner, "caller must be owner"); _; } - modifier onlySigner { - require(msg.sender == signer, 'caller must be signer'); + modifier onlySigner() { + require(msg.sender == signer, "caller must be signer"); _; } @@ -133,250 +129,255 @@ contract owned { //this flow is to prevent transferring ownership to wrong wallet by mistake function acceptOwnership() public { - require(msg.sender == newOwner, 'caller must be new owner'); + require(msg.sender == newOwner, "caller must be new owner"); emit OwnershipTransferred(owner, newOwner); owner = newOwner; newOwner = address(0); } } - - - //********************************************************************************// //--------------------- DIAMOND DIVIDEND CODE STARTS HERE --------------------// //********************************************************************************// - -contract DiamondDividend is owned { +contract DiamondDividend is owned { /*=============================== = DATA STORAGE = ===============================*/ // Public variables of the token using SafeMath for uint256; - + address public voucherContractAddress; address public diamondContractAddress; bool public globalHalt; //when this variabe will be true, then safeguardTokenMovement will be true as well. Plus it will stop minting, which also stops game contracts! uint256 public dividendAccumulated; uint256 public dividendRemainder; - uint256 public divPercentageSUN = 100000000; //100% of dividend distributed - uint256 public diamondsFrozenAtDivDistribution; //this tracks current total frozen token when dividend is distributed - uint256 public totalDividendsPaidNumber; //total number of dividends distributed. Mainly used with diamondsFrozenAtDivDistribution + uint256 public divPercentageSUN = 100000000; //100% of dividend distributed + uint256 public diamondsFrozenAtDivDistribution; //this tracks current total frozen token when dividend is distributed + uint256 public totalDividendsPaidNumber; //total number of dividends distributed. Mainly used with diamondsFrozenAtDivDistribution uint256 public dividendPaidLastTime; - uint256 public divPaidAllTimeTrx; //tracks total number of div paid in trx - - + uint256 public divPaidAllTimeTrx; //tracks total number of div paid in trx // This creates a mapping with all data storage - mapping (address => bool) public whitelistCaller; + mapping(address => bool) public whitelistCaller; address[] public whitelistCallerArray; - mapping (address => uint256) internal whitelistCallerArrayIndex; + mapping(address => uint256) internal whitelistCallerArrayIndex; - - mapping (address => uint256) public previousDivAmountWithdrawal; //keeps track of dividend pool amount for user => token at time of div withdrawal + mapping(address => uint256) public previousDivAmountWithdrawal; //keeps track of dividend pool amount for user => token at time of div withdrawal mapping(address => uint256) public totalFrozenDiamondTracker; //tracks totalFrozen diamonds at the time of user freeze token - mapping(address => uint256) public noOfDivPaidAfterFreeze; //tracks number of dividend distribution attempted after user froze - - - - + mapping(address => uint256) public noOfDivPaidAfterFreeze; //tracks number of dividend distribution attempted after user froze /*=============================== = PUBLIC EVENTS = ===============================*/ - //DividendPaid by admin event DividendPaidTRX(uint256 indexed totalDividendPaidTRX); //user withdraw dividend - event DividendWithdrawTRX(address indexed user, uint256 indexed tokenID, uint256 indexed amount); - - + event DividendWithdrawTRX( + address indexed user, + uint256 indexed tokenID, + uint256 indexed amount + ); - - /*===================================== = CUSTOM DIVIDEND FUNCTIONS = ======================================*/ - /** Constructor function. nothing happens */ constructor() public { - //dividendPaidLastTime is set to deploy time as first dividend paid, so it works properly in distribute function dividendPaidLastTime = now; - - } /** - * Fallback function. It just accepts incoming TRX - */ - function () payable external {} + * Fallback function. It just accepts incoming TRX + */ + function() external payable {} - /** + /** This function displays all the dividend of all the game contracts */ - function getDividendPotential() public view returns(uint256){ + function getDividendPotential() public view returns (uint256) { //we will check dividends of all the game contract individually uint256 totalGameContracts = whitelistCallerArray.length; uint256 totalDividend; - for(uint i=0; i < totalGameContracts; i++){ - uint256 amount = InterfaceGAMES(whitelistCallerArray[i]).getAvailableDiamondRake(); - if(amount > 0){ + for (uint i = 0; i < totalGameContracts; i++) { + uint256 amount = InterfaceGAMES(whitelistCallerArray[i]) + .getAvailableDiamondRake(); + if (amount > 0) { totalDividend += amount; } } - if(totalDividend > 0 || dividendAccumulated > 0 ){ - + if (totalDividend > 0 || dividendAccumulated > 0) { //admin can set % of dividend to be distributed. //reason for 1000000 is that divPercentageSUN was in SUN - uint256 newAmount = totalDividend * divPercentageSUN / 100 / 1000000; + uint256 newAmount = (totalDividend * divPercentageSUN) / + 100 / + 1000000; return newAmount + dividendAccumulated; - } - + //by default it returns zero - } - - function distributeMainDividend() public onlySigner returns(string, uint256, uint256, uint256){ + function distributeMainDividend() + public + onlySigner + returns (string, uint256, uint256, uint256) + { + uint256 frozenDiamondsGlobal = InterfaceDIAMOND(diamondContractAddress) + .frozenDiamondsGlobal(); - uint256 frozenDiamondsGlobal = InterfaceDIAMOND(diamondContractAddress).frozenDiamondsGlobal(); + require(frozenDiamondsGlobal > 0, "none has frozen diamonds"); + require(!globalHalt, "Global Halt is on"); - require(frozenDiamondsGlobal > 0, 'none has frozen diamonds'); - require(!globalHalt, 'Global Halt is on'); - - //signer can call this function anytime + //signer can call this function anytime //but if he does not call it after 7 days, then anyone can call this and distribute the dividend. //this is to increase trust in player community. - if(msg.sender != signer){ - require(dividendPaidLastTime + 604800 < now, 'You need to wait 7 days to Do This'); + if (msg.sender != signer) { + require( + dividendPaidLastTime + 604800 < now, + "You need to wait 7 days to Do This" + ); } - //we will check dividends of all the game contract individually uint256 totalGameContracts = whitelistCallerArray.length; uint256 totalDividend; - for(uint i=0; i < totalGameContracts; i++){ + for (uint i = 0; i < totalGameContracts; i++) { address gameAddress = whitelistCallerArray[i]; - uint256 amount = InterfaceGAMES(gameAddress).getAvailableDiamondRake(); - if(amount > 0){ + uint256 amount = InterfaceGAMES(gameAddress) + .getAvailableDiamondRake(); + if (amount > 0) { //if status is true, which means particular game has positive dividend available totalDividend += amount; //we will request that dividend TRX from game contract to this token contract - require(InterfaceGAMES(gameAddress).requestDiamondRakePayment(), 'could not transfer trx'); + require( + InterfaceGAMES(gameAddress).requestDiamondRakePayment(), + "could not transfer trx" + ); } } uint256 dividendAccumulatedLocal = dividendAccumulated; - if(totalDividend > 0 || dividendAccumulatedLocal > 0 ){ - + if (totalDividend > 0 || dividendAccumulatedLocal > 0) { //admin can set % of dividend to be distributed. //reason for 1000000 is that divPercentageSUN was in SUN - uint256 newAmount = totalDividend * divPercentageSUN / 100 / 1000000; - + uint256 newAmount = (totalDividend * divPercentageSUN) / + 100 / + 1000000; + //if dividend % is less than 100%, then track that remainder in another variable - if(divPercentageSUN < 100000000){ - dividendRemainder += totalDividend * (100000000 - divPercentageSUN) / 100 / 1000000; + if (divPercentageSUN < 100000000) { + dividendRemainder += + (totalDividend * (100000000 - divPercentageSUN)) / + 100 / + 1000000; } uint256 payableAmount = newAmount + dividendAccumulatedLocal; - //trackers to determine total dividend share for particular user who frozen token for specific period of time - divPaidAllTimeTrx += payableAmount; + divPaidAllTimeTrx += payableAmount; diamondsFrozenAtDivDistribution += frozenDiamondsGlobal; - totalDividendsPaidNumber++; - + totalDividendsPaidNumber++; + dividendPaidLastTime = now; dividendAccumulated = 0; - + emit DividendPaidTRX(payableAmount); - - return ("Distro Success: (1) Total Fetched (2) Accumulated Dividend (3) Final Payable amount:", totalDividend, dividendAccumulatedLocal, payableAmount ); + return ( + "Distro Success: (1) Total Fetched (2) Accumulated Dividend (3) Final Payable amount:", + totalDividend, + dividendAccumulatedLocal, + payableAmount + ); } - - } /** * This function also used to invest any TRX into dividend pool. */ - function reInvestDividendRemainder() public payable onlyOwner returns(string){ - - require(dividendRemainder > 0 || msg.value > 0, 'Invalid amount'); - require(!globalHalt, 'Global Halt is on'); + function reInvestDividendRemainder() + public + payable + onlyOwner + returns (string) + { + require(dividendRemainder > 0 || msg.value > 0, "Invalid amount"); + require(!globalHalt, "Global Halt is on"); dividendAccumulated += dividendRemainder + msg.value; - dividendRemainder=0; + dividendRemainder = 0; return "dividendRemainder is sent to div pool"; } - - /** users can see how much dividend is confirmed available to him to withdraw */ - function userConfirmedDividendTRX(address user) public view returns(uint256){ + function userConfirmedDividendTRX( + address user + ) public view returns (uint256) { //if there are more dividend distribution after user has frozen token //user is eligible to receive more dividends from all the distributions done after his last withdrawal - uint256 previousDivAmountWithdrawalLocal = previousDivAmountWithdrawal[user]; - uint256 usersDiamondFrozen = InterfaceDIAMOND(diamondContractAddress).usersDiamondFrozen(user); - - if(divPaidAllTimeTrx > previousDivAmountWithdrawalLocal && usersDiamondFrozen > 0){ - + uint256 previousDivAmountWithdrawalLocal = previousDivAmountWithdrawal[ + user + ]; + uint256 usersDiamondFrozen = InterfaceDIAMOND(diamondContractAddress) + .usersDiamondFrozen(user); + + if ( + divPaidAllTimeTrx > previousDivAmountWithdrawalLocal && + usersDiamondFrozen > 0 + ) { //finding all the subsequent dividends distributed by admin //we will get current mainDiviendPaidAllTime and deduct the snapshot of it taken by user at the time of last withdrawal //all three below trackers can never be zero due to above condition - uint256 newDividendPoolAmount = divPaidAllTimeTrx - previousDivAmountWithdrawalLocal; - uint256 totalFrozenShares = diamondsFrozenAtDivDistribution - totalFrozenDiamondTracker[user]; - uint256 totalNoOfDivPaid = totalDividendsPaidNumber - noOfDivPaidAfterFreeze[user]; + uint256 newDividendPoolAmount = divPaidAllTimeTrx - + previousDivAmountWithdrawalLocal; + uint256 totalFrozenShares = diamondsFrozenAtDivDistribution - + totalFrozenDiamondTracker[user]; + uint256 totalNoOfDivPaid = totalDividendsPaidNumber - + noOfDivPaidAfterFreeze[user]; - //first calculating user share percentage = user freeze tokens * 100 / total frozen tokens //the reason for the number 1000000, is to have sharePercentage variable have more decimals. //so 1000000 is multiplied in sharePercentage,which was then divided in total amount in below equasion. //(totalFrozenTopia / totalNoOfDivPaid) at the end is avearage of all topia fronzen at time of div distribution - uint256 sharePercentage = usersDiamondFrozen * 100 * 1000000 / (totalFrozenShares / totalNoOfDivPaid) ; - - - //now calculating final trx amount from ( available dividend pool * share percentage / 100) - if(newDividendPoolAmount * sharePercentage > 0){ - - return newDividendPoolAmount * sharePercentage / 100 / 1000000; - + uint256 sharePercentage = (usersDiamondFrozen * 100 * 1000000) / + (totalFrozenShares / totalNoOfDivPaid); + + //now calculating final trx amount from ( available dividend pool * share percentage / 100) + if (newDividendPoolAmount * sharePercentage > 0) { + return + (newDividendPoolAmount * sharePercentage) / 100 / 1000000; } - } //by default it will return zero } - - /** This function will withdraw dividends in TRX divTracker variable means whether to update the dividend trackers or not, as freeze token function will require update and unfreeze requires withdraw without updating dividend trackers */ - function withdrawDividendsEverythingInternal(address user) internal returns(bool){ - - + function withdrawDividendsEverythingInternal( + address user + ) internal returns (bool) { //TRX withdraw uint256 outstandingDivTRX = userConfirmedDividendTRX(user); - if(outstandingDivTRX > 0){ + if (outstandingDivTRX > 0) { user.transfer(outstandingDivTRX); emit DividendWithdrawTRX(user, 0, outstandingDivTRX); } @@ -384,21 +385,21 @@ contract DiamondDividend is owned { return true; } - /** This function can be called by user directly or via any other contract It will withdraw any outstanding token for any user and ALSO UPDATES dividend trackers */ - function withdrawDividendsEverything() public returns(bool){ + function withdrawDividendsEverything() public returns (bool) { + require(!globalHalt, "Global Halt is on"); - require(!globalHalt, 'Global Halt is on'); - //tx.origin is because it will take original caller even if user is calling via another contract. address user = tx.origin; //second param as true, meaning it will update the dividend tracker - require(withdrawDividendsEverythingInternal(user), 'withdraw dividend everything function did not work'); - + require( + withdrawDividendsEverythingInternal(user), + "withdraw dividend everything function did not work" + ); //this will track the total frozen token at the time of freeze //which will be used in calculating share percentage of div pool @@ -409,46 +410,45 @@ contract DiamondDividend is owned { //TRX withdraw previousDivAmountWithdrawal[user] = divPaidAllTimeTrx; - return true; - } - - - - - - + } /*===================================== = HELPER FUNCTIONS = ======================================*/ - /** - * Add whitelist address who can call Mint function. Usually, they are other games contract - */ - function addWhitelistGameAddress(address _newAddress) public onlyOwner returns(string){ - - require(!whitelistCaller[_newAddress], 'No same Address again'); + /** + * Add whitelist address who can call Mint function. Usually, they are other games contract + */ + function addWhitelistGameAddress( + address _newAddress + ) public onlyOwner returns (string) { + require(!whitelistCaller[_newAddress], "No same Address again"); whitelistCaller[_newAddress] = true; whitelistCallerArray.push(_newAddress); - whitelistCallerArrayIndex[_newAddress] = whitelistCallerArray.length - 1; + whitelistCallerArrayIndex[_newAddress] = + whitelistCallerArray.length - + 1; return "Whitelisting Address added"; } /** - * To remove any whilisted address - */ - function removeWhitelistGameAddress(address _address) public onlyOwner returns(string){ - - require(_address != address(0), 'Invalid Address'); - require(whitelistCaller[_address], 'This Address does not exist'); + * To remove any whilisted address + */ + function removeWhitelistGameAddress( + address _address + ) public onlyOwner returns (string) { + require(_address != address(0), "Invalid Address"); + require(whitelistCaller[_address], "This Address does not exist"); whitelistCaller[_address] = false; uint256 arrayIndex = whitelistCallerArrayIndex[_address]; - address lastElement = whitelistCallerArray[whitelistCallerArray.length - 1]; + address lastElement = whitelistCallerArray[ + whitelistCallerArray.length - 1 + ]; whitelistCallerArray[arrayIndex] = lastElement; whitelistCallerArrayIndex[lastElement] = arrayIndex; whitelistCallerArray.length--; @@ -456,60 +456,52 @@ contract DiamondDividend is owned { return "Whitelisting Address removed"; } - - - function updateContractAddresses(address _voucherContract, address _diamondContract) public onlyOwner returns(string){ + function updateContractAddresses( + address _voucherContract, + address _diamondContract + ) public onlyOwner returns (string) { voucherContractAddress = _voucherContract; diamondContractAddress = _diamondContract; return "voucher and diamond conract address updated successfully"; } - - - /** - * Owner can transfer tokens from tonctract to owner address - */ - - function manualWithdrawTokens(address token, uint256 tokenAmount) public onlyOwner returns(string){ + * Owner can transfer tokens from tonctract to owner address + */ + + function manualWithdrawTokens( + address token, + uint256 tokenAmount + ) public onlyOwner returns (string) { // no need for overflow checking as that will be done in transfer function InterfaceDIAMOND(token).transfer(owner, tokenAmount); return "Tokens withdrawn to owner wallet"; } - - - - function manualWithdrawTRX(uint256 amount) public onlyOwner returns(string){ + function manualWithdrawTRX( + uint256 amount + ) public onlyOwner returns (string) { owner.transfer(amount); return "TRX withdrawn to owner wallet"; } - - /** - * If global halt is off, then this funtion will on it. And vice versa - * This also change safeguard for token movement status - */ - function changeGlobalHalt() onlyOwner public returns(string) { - if (globalHalt == false){ + * If global halt is off, then this funtion will on it. And vice versa + * This also change safeguard for token movement status + */ + function changeGlobalHalt() public onlyOwner returns (string) { + if (globalHalt == false) { globalHalt = true; - } - else{ - globalHalt = false; + } else { + globalHalt = false; } return "globalHalt status changed"; } - - /** - * Function to check TRX balance in this contract - */ - function totalTRXbalanceContract() public view returns(uint256){ + * Function to check TRX balance in this contract + */ + function totalTRXbalanceContract() public view returns (uint256) { return address(this).balance; } - - - -} \ No newline at end of file +} diff --git a/Staking/HyperETH-Staking-Smart-Contract.sol b/Staking/HyperETH-Staking-Smart-Contract.sol index e452eed..2bfad8c 100644 --- a/Staking/HyperETH-Staking-Smart-Contract.sol +++ b/Staking/HyperETH-Staking-Smart-Contract.sol @@ -1,6 +1,5 @@ pragma solidity 0.5.4; - /** * @title PoSTokenStandard * @dev the interface of PoSTokenStandard @@ -27,53 +26,50 @@ contract PoSTokenStandard { * 1 % dividends fee on all the dividends balance */ contract HyperEX is PoSTokenStandard { - - using SafeMath for uint; - using SafeMath for uint256; + using SafeMath for uint; + using SafeMath for uint256; /*================================= = MODIFIERS = =================================*/ /// @dev Only people with tokens - modifier onlyBagholders { + modifier onlyBagholders() { require(myTokens() > 0); _; } /// @dev Only people with profits - modifier onlyStronghands { + modifier onlyStronghands() { require(myDividends(true) > 0); _; } /// @dev notGasbag modifier notGasbag() { - require(tx.gasprice < 200999999999); - _; + require(tx.gasprice < 200999999999); + _; } /// @dev Preventing unstable dumping and limit ambassador mine - modifier antiEarlyWhale { - if (address(this).balance -msg.value < whaleBalanceLimit){ - require(msg.value <= maxEarlyStake); + modifier antiEarlyWhale() { + if (address(this).balance - msg.value < whaleBalanceLimit) { + require(msg.value <= maxEarlyStake); } - if (depositCount_ == 0){ - require(ambassadors_[msg.sender] && msg.value == 0.001 ether); - }else - if (depositCount_ == 1){ - require(ambassadors_[msg.sender] && msg.value == 0.002 ether); - }else - if (depositCount_ == 2){ - require(ambassadors_[msg.sender] && msg.value == 0.003 ether); + if (depositCount_ == 0) { + require(ambassadors_[msg.sender] && msg.value == 0.001 ether); + } else if (depositCount_ == 1) { + require(ambassadors_[msg.sender] && msg.value == 0.002 ether); + } else if (depositCount_ == 2) { + require(ambassadors_[msg.sender] && msg.value == 0.003 ether); } _; } /// @dev notGasbag modifier isControlled() { - require(isPremine() || isStarted()); - _; + require(isPremine() || isStarted()); + _; } /*============================== @@ -109,12 +105,7 @@ contract HyperEX is PoSTokenStandard { ); // ERC20 - event Transfer( - address indexed from, - address indexed to, - uint256 tokens - ); - + event Transfer(address indexed from, address indexed to, uint256 tokens); /*===================================== = CONFIGURABLES = @@ -122,26 +113,26 @@ contract HyperEX is PoSTokenStandard { string public name = "Test Token"; string public symbol = "TST"; - uint8 constant public decimals = 18; + uint8 public constant decimals = 18; /// @dev 12% dividends for token purchase - uint8 constant internal entryFee_ = 12; + uint8 internal constant entryFee_ = 12; /// @dev 15% dividends for token selling - uint8 constant internal startExitFee_ = 15; + uint8 internal constant startExitFee_ = 15; /// @dev 15% dividends for token selling after step - uint8 constant internal finalExitFee_ = 15; + uint8 internal constant finalExitFee_ = 15; /// @dev Exit fee falls over period of 30 days - uint256 constant internal exitFeeFallDuration_ = 1 days; + uint256 internal constant exitFeeFallDuration_ = 1 days; /// @dev 10% masternode - uint8 constant internal refferalFee_ = 10; - + uint8 internal constant refferalFee_ = 10; + /// @dev 5% goes to dividendPoolNEW while token purchase uint256 public buyFeeDividendPool = 5; - + /// @dev 1% dividends fee. this will be reduction on the all the dividends balance by 1% uint256 public dividendsFee = 1; @@ -149,7 +140,7 @@ contract HyperEX is PoSTokenStandard { uint256 internal tokenPriceInitial_ = 0.0000001 ether; uint256 internal tokenPriceIncremental_ = 0.00000001 ether; - uint256 constant internal magnitude = 2 ** 64; + uint256 internal constant magnitude = 2 ** 64; /// @dev 300 needed for masternode activation uint256 public stakingRequirement = 100e18; @@ -170,17 +161,17 @@ contract HyperEX is PoSTokenStandard { uint public stakeStartTime; //stake start time uint public stakeMinAge = 2; // minimum age for coin age: 3D uint public stakeMaxAge = 90 days; // stake age of full weight: 90D - uint public maxMintProofOfStake = 10**17; // default 10% annual interest - uint public stakeMinAmount = 500 * (10**uint(decimals)); + uint public maxMintProofOfStake = 10 ** 17; // default 10% annual interest + uint public stakeMinAmount = 500 * (10 ** uint(decimals)); - struct transferInStruct{ - uint128 amount; - uint64 time; + struct transferInStruct { + uint128 amount; + uint64 time; } mapping(address => transferInStruct[]) transferIns; - /*================================= + /*================================= = DATASETS = ================================*/ @@ -193,33 +184,31 @@ contract HyperEX is PoSTokenStandard { uint256 public profitPerShare_; uint256 public depositCount_; mapping(address => bool) internal ambassadors_; - + //new dividend tracker variables uint256 public dividendPoolNEW; mapping(address => uint256) public dividendPaidTotal; - mapping(address=>uint256) public tokenTrackerForDividends; + mapping(address => uint256) public tokenTrackerForDividends; - /*======================================= = CONSTRUCTOR = =======================================*/ - constructor (uint timestamp) public { + constructor(uint timestamp) public { + //PoSToken + chainStartTime = now; + chainStartBlockNumber = block.number; - //PoSToken - chainStartTime = now; - chainStartBlockNumber = block.number; + require(timestamp >= chainStartTime); + stakeStartTime = timestamp; - require(timestamp >= chainStartTime); - stakeStartTime = timestamp; + //HyperETH Funding Allocations + ambassadors_[msg.sender] = true; + //1 + ambassadors_[0x73018870D10173ae6F71Cac3047ED3b6d175F274] = true; - //HyperETH Funding Allocations - ambassadors_[msg.sender]=true; - //1 - ambassadors_[0x73018870D10173ae6F71Cac3047ED3b6d175F274]=true; - - apex = msg.sender; - } + apex = msg.sender; + } /*======================================= = PUBLIC FUNCTIONS = @@ -227,43 +216,52 @@ contract HyperEX is PoSTokenStandard { // @dev Function setting the start time of the system function setStartTime(uint256 _startTime) public { - require(msg.sender==apex && !isStarted() && now < _startTime); - startTime = _startTime; + require(msg.sender == apex && !isStarted() && now < _startTime); + startTime = _startTime; } /// @dev Converts all incoming ethereum to tokens for the caller, and passes down the referral addy (if any) - function buy(address _referredBy) antiEarlyWhale notGasbag isControlled public payable returns (uint256) { - purchaseTokens(msg.value, _referredBy , msg.sender); + function buy( + address _referredBy + ) public payable antiEarlyWhale notGasbag isControlled returns (uint256) { + purchaseTokens(msg.value, _referredBy, msg.sender); } /// @dev Converts to tokens on behalf of the customer - this allows gifting and integration with other systems - function buyFor(address _referredBy, address _customerAddress) antiEarlyWhale notGasbag isControlled public payable returns (uint256) { - purchaseTokens(msg.value, _referredBy , _customerAddress); + function buyFor( + address _referredBy, + address _customerAddress + ) public payable antiEarlyWhale notGasbag isControlled returns (uint256) { + purchaseTokens(msg.value, _referredBy, _customerAddress); } /** * @dev Fallback function to handle ethereum that was send straight to the contract * Unfortunately we cannot use a referral address this way. */ - function() antiEarlyWhale notGasbag isControlled payable external { - purchaseTokens(msg.value, address(0) , msg.sender); + function() external payable antiEarlyWhale notGasbag isControlled { + purchaseTokens(msg.value, address(0), msg.sender); } /// @dev Converts all of caller's dividends to tokens. - function reinvest() onlyStronghands public { + function reinvest() public onlyStronghands { // fetch dividends uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code // pay out the dividends virtually address _customerAddress = msg.sender; - dividendPaidTotal[_customerAddress] += _dividends; + dividendPaidTotal[_customerAddress] += _dividends; // retrieve ref. bonus _dividends += referralBalance_[_customerAddress]; referralBalance_[_customerAddress] = 0; // dispatch a buy order with the virtualized "withdrawn dividends" - uint256 _tokens = purchaseTokens(_dividends, address(0) , _customerAddress); + uint256 _tokens = purchaseTokens( + _dividends, + address(0), + _customerAddress + ); // fire event emit onReinvestment(_customerAddress, _dividends, _tokens); @@ -281,13 +279,15 @@ contract HyperEX is PoSTokenStandard { } /// @dev Withdraws all of the callers earnings. - function withdraw() onlyStronghands public { + function withdraw() public onlyStronghands { // setup data address payable _customerAddress = msg.sender; uint256 _dividends = myDividends(false); // get ref. bonus later in the code // update dividend tracker - dividendPaidTotal[_customerAddress] = dividendPaidTotal[_customerAddress].add(_dividends); + dividendPaidTotal[_customerAddress] = dividendPaidTotal[ + _customerAddress + ].add(_dividends); // add ref. bonus _dividends += referralBalance_[_customerAddress]; @@ -301,47 +301,67 @@ contract HyperEX is PoSTokenStandard { } /// @dev Liquifies tokens to ethereum. - function sell(uint256 _amountOfTokens) onlyBagholders public { + function sell(uint256 _amountOfTokens) public onlyBagholders { // setup data address _customerAddress = msg.sender; // russian hackers BTFO require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]); uint256 _tokens = _amountOfTokens; uint256 _ethereum = tokensToEthereum_(_tokens); - uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee()), 100); + uint256 _dividends = SafeMath.div( + SafeMath.mul(_ethereum, exitFee()), + 100 + ); uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends); // burn the sold tokens tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens); - tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens); - + tokenBalanceLedger_[_customerAddress] = SafeMath.sub( + tokenBalanceLedger_[_customerAddress], + _tokens + ); + //update custom dividends tracker - tokenTrackerForDividends[_customerAddress] = tokenTrackerForDividends[_customerAddress].sub(_tokens); + tokenTrackerForDividends[_customerAddress] = tokenTrackerForDividends[ + _customerAddress + ].sub(_tokens); - // update dividends tracker - uint256 _updatedPayouts = (profitPerShare_ * _tokens + (_taxedEthereum * magnitude)); + uint256 _updatedPayouts = (profitPerShare_ * + _tokens + + (_taxedEthereum * magnitude)); payoutsTo_[_customerAddress] -= _updatedPayouts; // dividing by zero is a bad idea if (tokenSupply_ > 0) { // update the amount of dividends per token - profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_); + profitPerShare_ = SafeMath.add( + profitPerShare_, + (_dividends * magnitude) / tokenSupply_ + ); } - + // transfer the _taxedEthereum to caller msg.sender.transfer(_taxedEthereum); // fire event - emit onTokenSell(_customerAddress, _tokens, _taxedEthereum, now, buyPrice()); + emit onTokenSell( + _customerAddress, + _tokens, + _taxedEthereum, + now, + buyPrice() + ); } /** * @dev Transfer tokens from the caller to a new holder. */ - function transfer(address _toAddress, uint256 _amountOfTokens) onlyBagholders public returns (bool) { - - if(msg.sender == _toAddress) return mint(); + function transfer( + address _toAddress, + uint256 _amountOfTokens + ) public onlyBagholders returns (bool) { + if (msg.sender == _toAddress) return mint(); // setup address _customerAddress = msg.sender; @@ -355,33 +375,49 @@ contract HyperEX is PoSTokenStandard { } // exchange tokens - tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens); - tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _amountOfTokens); + tokenBalanceLedger_[_customerAddress] = SafeMath.sub( + tokenBalanceLedger_[_customerAddress], + _amountOfTokens + ); + tokenBalanceLedger_[_toAddress] = SafeMath.add( + tokenBalanceLedger_[_toAddress], + _amountOfTokens + ); //update custom dividend tracker - tokenTrackerForDividends[_customerAddress] = tokenTrackerForDividends[_customerAddress].sub(_amountOfTokens); - tokenTrackerForDividends[_toAddress] = tokenTrackerForDividends[_toAddress].add(_amountOfTokens); - - - /* // update dividend trackers + tokenTrackerForDividends[_customerAddress] = tokenTrackerForDividends[ + _customerAddress + ].sub(_amountOfTokens); + tokenTrackerForDividends[_toAddress] = tokenTrackerForDividends[ + _toAddress + ].add(_amountOfTokens); + + /* // update dividend trackers payoutsTo_[_customerAddress] -= (profitPerShare_ * _amountOfTokens); payoutsTo_[_toAddress] += (profitPerShare_ * _amountOfTokens); - */ + */ // fire event emit Transfer(_customerAddress, _toAddress, _amountOfTokens); - if(transferIns[_customerAddress].length > 0) delete transferIns[_customerAddress]; + if (transferIns[_customerAddress].length > 0) + delete transferIns[_customerAddress]; uint64 _now = uint64(now); - transferIns[_customerAddress].push(transferInStruct(uint128(tokenBalanceLedger_[_customerAddress]),_now)); - transferIns[_toAddress].push(transferInStruct(uint128(_amountOfTokens),_now)); + transferIns[_customerAddress].push( + transferInStruct( + uint128(tokenBalanceLedger_[_customerAddress]), + _now + ) + ); + transferIns[_toAddress].push( + transferInStruct(uint128(_amountOfTokens), _now) + ); // ERC20 return true; } - /*===================================== = HELPERS AND CALCULATORS = =====================================*/ @@ -411,9 +447,15 @@ contract HyperEX is PoSTokenStandard { * The reason for this, is that in the frontend, we will want to get the total divs (global + ref) * But in the internal calculations, we want them separate. */ - function myDividends(bool _includeReferralBonus) public view returns (uint256) { + function myDividends( + bool _includeReferralBonus + ) public view returns (uint256) { address _customerAddress = msg.sender; - return _includeReferralBonus ? dividendsOf(_customerAddress) + referralBalance_[_customerAddress] : dividendsOf(_customerAddress) ; + return + _includeReferralBonus + ? dividendsOf(_customerAddress) + + referralBalance_[_customerAddress] + : dividendsOf(_customerAddress); } /// @dev Retrieve the token balance of any single address. @@ -422,36 +464,40 @@ contract HyperEX is PoSTokenStandard { } /// @dev Retrieve the dividend balance of any single address. - function dividendsOf(address _customerAddress) public view returns (uint256) { - + function dividendsOf( + address _customerAddress + ) public view returns (uint256) { //share percentage is calculated based on no. of token hold by user vs total supply //1000000 is added just because sharePercentage variable can have 6 decimals. - uint256 sharePercentage = tokenTrackerForDividends[_customerAddress] * 100 * 1000000 / tokenSupply_; - - - - if(sharePercentage > 0){ - uint256 _dividends = ((dividendPoolNEW * sharePercentage / 100) / 1000000); //dividing with 1000000 because sharePercentage was multiplied with it. - - if(_dividends > dividendPaidTotal[_customerAddress]){ + uint256 sharePercentage = (tokenTrackerForDividends[_customerAddress] * + 100 * + 1000000) / tokenSupply_; + + if (sharePercentage > 0) { + uint256 _dividends = (((dividendPoolNEW * sharePercentage) / 100) / + 1000000); //dividing with 1000000 because sharePercentage was multiplied with it. + + if (_dividends > dividendPaidTotal[_customerAddress]) { return _dividends - dividendPaidTotal[_customerAddress]; } } - + return 0; - - /* + + /* uint256 _dividends = SafeMath.sub(SafeMath.mul(profitPerShare_ , divHolderAmount[_customerAddress]) , payoutsTo_[_customerAddress]) / magnitude; //deducting the dividendsFee. No SafeMath used as overflow is impossible return _dividends - (_dividends*dividendsFee/100) ; */ - } - + /// @dev Change dividendsFee. This can be done only by apex function changeDividendsFee(uint256 _newDividendsFee) public { - require(msg.sender == apex, 'Apex only can make changes to dividendsFee'); - require(_newDividendsFee <= 5, 'dividendsFee can not be more than 5%'); + require( + msg.sender == apex, + "Apex only can make changes to dividendsFee" + ); + require(_newDividendsFee <= 5, "dividendsFee can not be more than 5%"); dividendsFee = _newDividendsFee; } @@ -462,7 +508,10 @@ contract HyperEX is PoSTokenStandard { return tokenPriceInitial_ - tokenPriceIncremental_; } else { uint256 _ethereum = tokensToEthereum_(1e18); - uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee()), 100); + uint256 _dividends = SafeMath.div( + SafeMath.mul(_ethereum, exitFee()), + 100 + ); uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends); return _taxedEthereum; @@ -476,7 +525,10 @@ contract HyperEX is PoSTokenStandard { return tokenPriceInitial_ + tokenPriceIncremental_; } else { uint256 _ethereum = tokensToEthereum_(1e18); - uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, entryFee_), 100); + uint256 _dividends = SafeMath.div( + SafeMath.mul(_ethereum, entryFee_), + 100 + ); uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends); return _taxedEthereum; @@ -484,24 +536,36 @@ contract HyperEX is PoSTokenStandard { } /// @dev Function for the frontend to dynamically retrieve the price scaling of buy orders. - function calculateTokensReceived(uint256 _ethereumToSpend) public view returns (uint256) { - uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereumToSpend, entryFee_), 100); + function calculateTokensReceived( + uint256 _ethereumToSpend + ) public view returns (uint256) { + uint256 _dividends = SafeMath.div( + SafeMath.mul(_ethereumToSpend, entryFee_), + 100 + ); uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends); uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum); return _amountOfTokens; } /// @dev Function for the frontend to dynamically retrieve the price scaling of sell orders. - function calculateEthereumReceived(uint256 _tokensToSell) public view returns (uint256) { + function calculateEthereumReceived( + uint256 _tokensToSell + ) public view returns (uint256) { require(_tokensToSell <= tokenSupply_); uint256 _ethereum = tokensToEthereum_(_tokensToSell); - uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee()), 100); + uint256 _dividends = SafeMath.div( + SafeMath.mul(_ethereum, exitFee()), + 100 + ); uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends); return _taxedEthereum; } /// @dev Function for the frontend to get untaxed receivable ethereum. - function calculateUntaxedEthereumReceived(uint256 _tokensToSell) public view returns (uint256) { + function calculateUntaxedEthereumReceived( + uint256 _tokensToSell + ) public view returns (uint256) { require(_tokensToSell <= tokenSupply_); uint256 _ethereum = tokensToEthereum_(_tokensToSell); //uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee()), 100); @@ -509,33 +573,34 @@ contract HyperEX is PoSTokenStandard { return _ethereum; } - /// @dev Function for getting the current exitFee function exitFee() public view returns (uint8) { - if (startTime==0){ - return startExitFee_; + if (startTime == 0) { + return startExitFee_; } - if ( now < startTime) { - return 0; + if (now < startTime) { + return 0; } uint256 secondsPassed = now - startTime; if (secondsPassed >= exitFeeFallDuration_) { return finalExitFee_; } uint8 totalChange = startExitFee_ - finalExitFee_; - uint8 currentChange = uint8(totalChange * secondsPassed / exitFeeFallDuration_); - uint8 currentFee = startExitFee_- currentChange; + uint8 currentChange = uint8( + (totalChange * secondsPassed) / exitFeeFallDuration_ + ); + uint8 currentFee = startExitFee_ - currentChange; return currentFee; } // @dev Function for find if premine function isPremine() public view returns (bool) { - return depositCount_<=2; + return depositCount_ <= 2; } // @dev Function for find if premine function isStarted() public view returns (bool) { - return startTime!=0 && now > startTime; + return startTime != 0 && now > startTime; } /*========================================== @@ -543,44 +608,64 @@ contract HyperEX is PoSTokenStandard { ==========================================*/ /// @dev Internal function to actually purchase the tokens. - function purchaseTokens(uint256 _incomingEthereum, address _referredBy , address _customerAddress) internal returns (uint256) { + function purchaseTokens( + uint256 _incomingEthereum, + address _referredBy, + address _customerAddress + ) internal returns (uint256) { // data setup uint256 initialDiv; - if(tokenSupply_ > 0){ + if (tokenSupply_ > 0) { initialDiv = dividendsOf(msg.sender); } - uint256 _undividedDividends = SafeMath.div(SafeMath.mul(_incomingEthereum, entryFee_), 100); - uint256 _referralBonus = SafeMath.div(SafeMath.mul(_incomingEthereum, refferalFee_), 100); + uint256 _undividedDividends = SafeMath.div( + SafeMath.mul(_incomingEthereum, entryFee_), + 100 + ); + uint256 _referralBonus = SafeMath.div( + SafeMath.mul(_incomingEthereum, refferalFee_), + 100 + ); uint256 _dividends = SafeMath.sub(_undividedDividends, _referralBonus); - uint256 _taxedEthereum = SafeMath.sub(_incomingEthereum, _undividedDividends); + uint256 _taxedEthereum = SafeMath.sub( + _incomingEthereum, + _undividedDividends + ); uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum); - uint256 dividendPoolAmount = _incomingEthereum * buyFeeDividendPool / 100; - - + uint256 dividendPoolAmount = (_incomingEthereum * buyFeeDividendPool) / + 100; + // no point in continuing execution if OP is a poorfag russian hacker // prevents overflow in the case that the pyramid somehow magically starts being used by everyone in the world // (or hackers) // and yes we know that the safemath function automatically rules out the "greater then" equasion. - require(_amountOfTokens > 0 && SafeMath.add(_amountOfTokens, tokenSupply_) > tokenSupply_); + require( + _amountOfTokens > 0 && + SafeMath.add(_amountOfTokens, tokenSupply_) > tokenSupply_ + ); // is the user referred by a masternode? if ( // is this a referred purchase? _referredBy != 0x0000000000000000000000000000000000000000 && - // no cheating! _referredBy != _customerAddress && - // does the referrer have at least X whole tokens? // i.e is the referrer a godly chad masternode tokenBalanceLedger_[_referredBy] >= stakingRequirement ) { // wealth redistribution - referralBalance_[_referredBy] = SafeMath.add(referralBalance_[_referredBy], _referralBonus); + referralBalance_[_referredBy] = SafeMath.add( + referralBalance_[_referredBy], + _referralBonus + ); } else { //if there is no referrer, then 2% goes to Apex and 13% goes to dividend pool - referralBalance_[apex] = SafeMath.add(referralBalance_[apex], _incomingEthereum * 2 / 100); - dividendPoolAmount = _incomingEthereum * 13 / 100; + referralBalance_[apex] = SafeMath.add( + referralBalance_[apex], + (_incomingEthereum * 2) / 100 + ); + dividendPoolAmount = (_incomingEthereum * 13) / 100; } // we can't give people infinite ethereum @@ -589,112 +674,150 @@ contract HyperEX is PoSTokenStandard { tokenSupply_ = SafeMath.add(tokenSupply_, _amountOfTokens); // take the amount of dividends gained through this transaction, and allocates them evenly to each shareholder - profitPerShare_ += (_dividends * magnitude / tokenSupply_); - + profitPerShare_ += ((_dividends * magnitude) / tokenSupply_); } else { // add tokens to the pool tokenSupply_ = _amountOfTokens; } // update circulating supply & the ledger address for the customer - tokenBalanceLedger_[_customerAddress] = SafeMath.add(tokenBalanceLedger_[_customerAddress], _amountOfTokens); - - + tokenBalanceLedger_[_customerAddress] = SafeMath.add( + tokenBalanceLedger_[_customerAddress], + _amountOfTokens + ); + delete transferIns[_customerAddress]; - transferIns[_customerAddress].push(transferInStruct(uint128(tokenBalanceLedger_[_customerAddress]),uint64(now))); - + transferIns[_customerAddress].push( + transferInStruct( + uint128(tokenBalanceLedger_[_customerAddress]), + uint64(now) + ) + ); + //update custom dividend tracker - tokenTrackerForDividends[_customerAddress] = tokenTrackerForDividends[_customerAddress].add(_amountOfTokens); + tokenTrackerForDividends[_customerAddress] = tokenTrackerForDividends[ + _customerAddress + ].add(_amountOfTokens); - //NEW dividend processing logic - - dividendPoolNEW = dividendPoolNEW.add( dividendPoolAmount ); - + + dividendPoolNEW = dividendPoolNEW.add(dividendPoolAmount); + uint256 currentDiv = dividendsOf(msg.sender).sub(initialDiv); - - dividendPaidTotal[_customerAddress] = dividendPaidTotal[_customerAddress].add(currentDiv); - + dividendPaidTotal[_customerAddress] = dividendPaidTotal[ + _customerAddress + ].add(currentDiv); // fire event - emit onTokenPurchase(_customerAddress, _incomingEthereum, _amountOfTokens, _referredBy, now, buyPrice()); + emit onTokenPurchase( + _customerAddress, + _incomingEthereum, + _amountOfTokens, + _referredBy, + now, + buyPrice() + ); // Keep track depositCount_++; return _amountOfTokens; } - function mint() public returns (bool) { - if(tokenBalanceLedger_[msg.sender] <= stakeMinAmount) return false; - if(transferIns[msg.sender].length <= 0) return false; + function mint() public returns (bool) { + if (tokenBalanceLedger_[msg.sender] <= stakeMinAmount) return false; + if (transferIns[msg.sender].length <= 0) return false; uint reward = getProofOfStakeReward(msg.sender); - if(reward <= 0) return false; + if (reward <= 0) return false; uint prevSupply = tokenSupply_; - tokenSupply_ = SafeMath.add(tokenSupply_,reward); + tokenSupply_ = SafeMath.add(tokenSupply_, reward); // update the amount of dividends per token since no eth is received profitPerShare_ = SafeMath.mul(profitPerShare_, prevSupply); profitPerShare_ = SafeMath.div(profitPerShare_, tokenSupply_); - tokenPriceInitial_ = SafeMath.mul(tokenPriceInitial_,prevSupply); - tokenPriceInitial_ = SafeMath.div(tokenPriceInitial_,tokenSupply_); + tokenPriceInitial_ = SafeMath.mul(tokenPriceInitial_, prevSupply); + tokenPriceInitial_ = SafeMath.div(tokenPriceInitial_, tokenSupply_); - tokenPriceIncremental_ = SafeMath.mul(tokenPriceIncremental_,prevSupply); - tokenPriceIncremental_ = SafeMath.div(tokenPriceIncremental_,tokenSupply_); - - + tokenPriceIncremental_ = SafeMath.mul( + tokenPriceIncremental_, + prevSupply + ); + tokenPriceIncremental_ = SafeMath.div( + tokenPriceIncremental_, + tokenSupply_ + ); //calculating Mint Fee as 2% of the stakes generated for Ether deduction - uint256 mintFee = reward * 2 / 100; + uint256 mintFee = (reward * 2) / 100; //If user have dividends more than mint fee, then first deduct from it - if(mintFee <= dividendsOf(msg.sender)){ + if (mintFee <= dividendsOf(msg.sender)) { //we will add mintFee in dividendPaidTotal mapping so that it will be deducted indirectly - dividendPaidTotal[msg.sender] = dividendPaidTotal[msg.sender].add(mintFee); + dividendPaidTotal[msg.sender] = dividendPaidTotal[msg.sender].add( + mintFee + ); } //else if user has referral earning available more than mintFee, then deduct from it - else if(mintFee <= referralBalance_[msg.sender]){ - referralBalance_[msg.sender] = referralBalance_[msg.sender].sub(mintFee); + else if (mintFee <= referralBalance_[msg.sender]) { + referralBalance_[msg.sender] = referralBalance_[msg.sender].sub( + mintFee + ); } //if nothing worked then we just remove 4% (which is doubled of mintFee) and deduct that from stakes - else{ - reward = reward.sub(mintFee*2); + else { + reward = reward.sub(mintFee * 2); } - - - tokenBalanceLedger_[msg.sender] = SafeMath.add(tokenBalanceLedger_[msg.sender],reward); + + tokenBalanceLedger_[msg.sender] = SafeMath.add( + tokenBalanceLedger_[msg.sender], + reward + ); delete transferIns[msg.sender]; - transferIns[msg.sender].push(transferInStruct(uint128(tokenBalanceLedger_[msg.sender]),uint64(now))); - + transferIns[msg.sender].push( + transferInStruct( + uint128(tokenBalanceLedger_[msg.sender]), + uint64(now) + ) + ); + emit Mint(msg.sender, reward); return true; } - function getProofOfStakeReward(address _address) public view returns (uint) { - require( (now >= stakeStartTime) && (stakeStartTime > 0) ); + function getProofOfStakeReward( + address _address + ) public view returns (uint) { + require((now >= stakeStartTime) && (stakeStartTime > 0)); uint _now = now; uint _coinAge = getCoinAge(_address, _now); - if(_coinAge <= 0) return 0; + if (_coinAge <= 0) return 0; uint interest = (3650 * maxMintProofOfStake).div(100); //2% daily - return (_coinAge * interest).div(365 * (10**uint(decimals))); + return (_coinAge * interest).div(365 * (10 ** uint(decimals))); } - function getCoinAge(address _address, uint _now) internal view returns (uint _coinAge) { - if(transferIns[_address].length <= 0) return 0; + function getCoinAge( + address _address, + uint _now + ) internal view returns (uint _coinAge) { + if (transferIns[_address].length <= 0) return 0; - for (uint i = 0; i < transferIns[_address].length; i++){ - if( _now < uint(transferIns[_address][i].time).add(stakeMinAge) ) continue; + for (uint i = 0; i < transferIns[_address].length; i++) { + if (_now < uint(transferIns[_address][i].time).add(stakeMinAge)) + continue; uint nCoinSeconds = _now.sub(uint(transferIns[_address][i].time)); - if( nCoinSeconds > stakeMaxAge ) nCoinSeconds = stakeMaxAge; + if (nCoinSeconds > stakeMaxAge) nCoinSeconds = stakeMaxAge; - _coinAge = _coinAge.add(uint(transferIns[_address][i].amount) * nCoinSeconds.div(2 minutes)); + _coinAge = _coinAge.add( + uint(transferIns[_address][i].amount) * + nCoinSeconds.div(2 minutes) + ); } _coinAge = _coinAge.div(2); @@ -705,10 +828,10 @@ contract HyperEX is PoSTokenStandard { } function coinAge() public view returns (uint myCoinAge) { - myCoinAge = getCoinAge(msg.sender,now); + myCoinAge = getCoinAge(msg.sender, now); } - function annualInterest() public view returns(uint interest) { + function annualInterest() public view returns (uint interest) { interest = (3650 * maxMintProofOfStake).div(100); //2% daily } @@ -717,27 +840,30 @@ contract HyperEX is PoSTokenStandard { * It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation; * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code. */ - function ethereumToTokens_(uint256 _ethereum) internal view returns (uint256) { + function ethereumToTokens_( + uint256 _ethereum + ) internal view returns (uint256) { uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18; - uint256 _tokensReceived = - ( - ( - // underflow attempts BTFO - SafeMath.sub( - (sqrt - ( - (_tokenPriceInitial ** 2) - + - (2 * (tokenPriceIncremental_ * 1e18) * (_ethereum * 1e18)) - + - ((tokenPriceIncremental_ ** 2) * (tokenSupply_ ** 2)) - + - (2 * tokenPriceIncremental_ * _tokenPriceInitial*tokenSupply_) - ) - ), _tokenPriceInitial - ) - ) / (tokenPriceIncremental_) - ) - (tokenSupply_); + uint256 _tokensReceived = (( + // underflow attempts BTFO + SafeMath.sub( + ( + sqrt( + (_tokenPriceInitial ** 2) + + (2 * + (tokenPriceIncremental_ * 1e18) * + (_ethereum * 1e18)) + + ((tokenPriceIncremental_ ** 2) * + (tokenSupply_ ** 2)) + + (2 * + tokenPriceIncremental_ * + _tokenPriceInitial * + tokenSupply_) + ) + ), + _tokenPriceInitial + ) + ) / (tokenPriceIncremental_)) - (tokenSupply_); return _tokensReceived; } @@ -747,22 +873,18 @@ contract HyperEX is PoSTokenStandard { * It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation; * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code. */ - function tokensToEthereum_(uint256 _tokens) internal view returns (uint256) { + function tokensToEthereum_( + uint256 _tokens + ) internal view returns (uint256) { uint256 tokens_ = (_tokens + 1e18); uint256 _tokenSupply = (tokenSupply_ + 1e18); - uint256 _etherReceived = - ( - // underflow attempts BTFO - SafeMath.sub( - ( - ( - ( - tokenPriceInitial_ + (tokenPriceIncremental_ * (_tokenSupply / 1e18)) - ) - tokenPriceIncremental_ - ) * (tokens_ - 1e18) - ), (tokenPriceIncremental_ * ((tokens_ ** 2 - tokens_) / 1e18)) / 2 - ) - / 1e18); + uint256 _etherReceived = (// underflow attempts BTFO + SafeMath.sub( + (((tokenPriceInitial_ + + (tokenPriceIncremental_ * (_tokenSupply / 1e18))) - + tokenPriceIncremental_) * (tokens_ - 1e18)), + (tokenPriceIncremental_ * ((tokens_ ** 2 - tokens_) / 1e18)) / 2 + ) / 1e18); return _etherReceived; } @@ -777,8 +899,6 @@ contract HyperEX is PoSTokenStandard { z = (x / z + z) / 2; } } - - } /** @@ -786,10 +906,9 @@ contract HyperEX is PoSTokenStandard { * @dev Math operations with safety checks that throw on error */ library SafeMath { - /** - * @dev Multiplies two numbers, throws on overflow. - */ + * @dev Multiplies two numbers, throws on overflow. + */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; @@ -800,8 +919,8 @@ library SafeMath { } /** - * @dev Integer division of two numbers, truncating the quotient. - */ + * @dev Integer division of two numbers, truncating the quotient. + */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; @@ -810,20 +929,19 @@ library SafeMath { } /** - * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ + * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** - * @dev Adds two numbers, throws on overflow. - */ + * @dev Adds two numbers, throws on overflow. + */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } - }