PowH3D 智能合约
Posted 江东戏子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PowH3D 智能合约相关的知识,希望对你有一定的参考价值。
购买股权
出售股权
t=tokenPriceInitial_
c=tokenPriceIncremental_
s=tokenSupply_
v = _taxedEthereum
a=_tokensReceived
// 合约地址: https://etherscan.io/address/0xb3775fb83f7d12a36e0475abdd1fca35c091efbe#code
pragma solidity ^0.4.20;
contract Hourglass
/*=================================
= MODIFIERS =
=================================*/
// 用于校验有余额,卖出和转账
modifier onlyBagholders()
require(myTokens() > 0);
_;
// 用于校验是否有推荐分红
modifier onlyStronghands()
require(myDividends(true) > 0);
_;
// 用于校验是否是管理员
modifier onlyAdministrator()
address _customerAddress = msg.sender;
require(administrators[keccak256(_customerAddress)]);
_;
// 校验状态
modifier antiEarlyWhale(uint256 _amountOfEthereum)
address _customerAddress = msg.sender;
if( onlyAmbassadors && ((totalEthereumBalance() - _amountOfEthereum) <= ambassadorQuota_ ))
require(
// 顾客是在推荐人的列表里
ambassadors_[_customerAddress] == true &&
// 顾客在推荐人额度是否小于购买量
(ambassadorAccumulatedQuota_[_customerAddress] + _amountOfEthereum) <= ambassadorMaxPurchase_
);
// 已购买额度叠加
ambassadorAccumulatedQuota_[_customerAddress] = SafeMath.add(ambassadorAccumulatedQuota_[_customerAddress], _amountOfEthereum);
_;
else
// 不满足条件,唯一推荐人取消
onlyAmbassadors = false;
_;
/*==============================
= EVENTS =
==============================*/
event onTokenPurchase(
address indexed customerAddress,
uint256 incomingEthereum,
uint256 tokensMinted,
address indexed referredBy
);
event onTokenSell(
address indexed customerAddress,
uint256 tokensBurned,
uint256 ethereumEarned
);
event onReinvestment(
address indexed customerAddress,
uint256 ethereumReinvested,
uint256 tokensMinted
);
event onWithdraw(
address indexed customerAddress,
uint256 ethereumWithdrawn
);
event Transfer(
address indexed from,
address indexed to,
uint256 tokens
);
/*=====================================
= CONFIGURABLES =
=====================================*/
string public name = "PowH3D";
string public symbol = "P3D";
uint8 constant public decimals = 18;
uint8 constant internal dividendFee_ = 10;
// 初始价格
uint256 constant internal tokenPriceInitial_ = 0.0000001 * 10**18;
// 增价
uint256 constant internal tokenPriceIncremental_ = 0.00000001 *10;
// 级数
uint256 constant internal magnitude = 2**64;
// 股权持有量
uint256 public stakingRequirement = 100e18;
// 推荐人
mapping(address => bool) internal ambassadors_;
// 购买推荐人的最大额度
uint256 constant internal ambassadorMaxPurchase_ = 1 ether;
// 推荐人的额度
uint256 constant internal ambassadorQuota_ = 20 ether;
/*================================
= DATASETS =
================================*/
// 客户余额列表
mapping(address => uint256) internal tokenBalanceLedger_;
// 推荐收益表
mapping(address => uint256) internal referralBalance_;
// 负债表
mapping(address => int256) internal payoutsTo_;
// 推荐人累计额度
mapping(address => uint256) internal ambassadorAccumulatedQuota_;
// 总量
uint256 internal tokenSupply_ = 0;
// 均分利润
uint256 internal profitPerShare_;
// 管理员列表
mapping(bytes32 => bool) public administrators;
// 唯一推荐人
bool public onlyAmbassadors = true;
/*=======================================
= PUBLIC FUNCTIONS =
=======================================*/
/*
* -- APPLICATION ENTRY POINTS --
*/
// 设置管理员和推荐人,及其注释其作用
function Hourglass() public
// add administrators here
administrators[0xdd8bb99b13fe33e1c32254dfb8fff3e71193f6b730a89dd33bfe5dedc6d83002] = true;
// add the ambassadors here.
// mantso - lead solidity dev & lead web dev.
ambassadors_[0x8b4DA1827932D71759687f925D17F81Fc94e3A9D] = true;
// ponzibot - mathematics & website, and undisputed meme god.
ambassadors_[0x8e0d985f3Ec1857BEc39B76aAabDEa6B31B67d53] = true;
// swagg - concept design, feedback, management.
ambassadors_[0x7563A35d5610eE7c9CD330E255Da0e779a644C19] = true;
// k-dawgz - shilling machine, meme maestro, bizman.
ambassadors_[0x215e3C713BADb158A457e61f99325bBB5d278E57] = true;
// elmojo - all those pretty .GIFs & memes you see? you can thank this man for that.
ambassadors_[0xaFF8B5CDCB339eEf5e1100597740a394C7B9c6cA] = true;
// capex - community moderator.
ambassadors_[0x8dc6569c28521560EAF1890bC41b2F3FC2010E1b] = true;
// jörmungandr - pentests & twitter trendsetter.
ambassadors_[0xf14BE3662FE4c9215c27698166759Db6967De94f] = true;
// inventor - the source behind the non-intrusive referral model.
ambassadors_[0x18E90Fc6F70344f53EBd4f6070bf6Aa23e2D748C] = true;
// tocsick - pentesting, contract auditing.
ambassadors_[0x49Aae4D923207e80Fc91E626BCb6532502264dfC] = true;
// arc - pentesting, contract auditing.
ambassadors_[0x3a0cca1A832644B60730E5D4c27947C5De609d62] = true;
// sumpunk - contract auditing.
ambassadors_[0x7ac74Fcc1a71b106F12c55ee8F802C9F672Ce40C] = true;
// randall - charts & sheets, data dissector, advisor.
ambassadors_[0x2b219C2178f099dE4E9A3667d5cCc2cc64da0763] = true;
// ambius - 3d chart visualization.
ambassadors_[0x2A04C7335f90a6bd4e9c4F713DD792200e27F2E6] = true;
// contributors that need to remain private out of security concerns.
ambassadors_[0x35668818ba8F768D4C21787a6f45C86C69394dfD] = true; //dp
ambassadors_[0xa3120da52e604aC3Fc80A63813Ef15476e0B6AbD] = true; //tc
ambassadors_[0x924E71bA600372e2410285423F1Fe66799b717EC] = true; //ja
ambassadors_[0x6Ed450e062C20F929CB7Ee72fCc53e9697980a18] = true; //sf
ambassadors_[0x18864A6682c8EB79EEA5B899F11bC94ef9a85ADb] = true; //tb
ambassadors_[0x9cC1BdC994b7a847705D19106287C0BF94EF04B5] = true; //sm
ambassadors_[0x6926572813ec1438088963f208C61847df435a74] = true; //mc
ambassadors_[0xE16Ab764a02Ae03681E351Ac58FE79717c0eE8C6] = true; //et
ambassadors_[0x276F4a79F22D1BfC51Bd8dc5b27Bfd934C823932] = true; //sn
ambassadors_[0xA2b4ed3E2f4beF09FB35101B76Ef4cB9D3eeCaCf] = true; //bt
ambassadors_[0x147fc6b04c95BCE47D013c8d7a200ee434323669] = true; //al
// 买,参数:推荐人地址
function buy(address _referredBy) public payable returns(uint256)
// 购买函数
purchaseTokens(msg.value, _referredBy);
function() payable public
purchaseTokens(msg.value, 0x0);
// 在投资
function reinvest() onlyStronghands() public
// 获取分红
uint256 _dividends = myDividends(false);
address _customerAddress = msg.sender;
// 负债表增加,即分红已领取
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
// 获取推荐奖励
_dividends += referralBalance_[_customerAddress];
// 推荐奖励置0
referralBalance_[_customerAddress] = 0;
// 投资,拿到股权数量
uint256 _tokens = purchaseTokens(_dividends, 0x0);
onReinvestment(_customerAddress, _dividends, _tokens);
// 退出
function exit() public
address _customerAddress = msg.sender;
// 获取股权数量
uint256 _tokens = tokenBalanceLedger_[_customerAddress];
// 有股权则卖出
if(_tokens > 0) sell(_tokens);
// 清算
withdraw();
// 清算
function withdraw() onlyStronghands() public
address _customerAddress = msg.sender;
uint256 _dividends = myDividends(false);
// 负债表增加,表示已提现收益
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
_dividends += referralBalance_[_customerAddress];
referralBalance_[_customerAddress] = 0;
_customerAddress.transfer(_dividends);
onWithdraw(_customerAddress, _dividends);
// 卖出,卖出逻辑和买入逻辑相反
function sell(uint256 _amountOfTokens) onlyBagholders() public
address _customerAddress = msg.sender;
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
uint256 _tokens = _amountOfTokens;
uint256 _ethereum = tokensToEthereum_(_tokens);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);
int256 _updatedPayouts = (int256) (profitPerShare_ * _tokens + (_taxedEthereum * magnitude));
payoutsTo_[_customerAddress] -= _updatedPayouts;
if (tokenSupply_ > 0)
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
onTokenSell(_customerAddress, _tokens, _taxedEthereum);
// 转账
function transfer(address _toAddress, uint256 _amountOfTokens) onlyBagholders() public returns(bool)
address _customerAddress = msg.sender;
// 检验余额大于等于转账数量
require(!onlyAmbassadors && _amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
// 提现
if(myDividends(true) > 0) withdraw();
// 手续费
uint256 _tokenFee = SafeMath.div(_amountOfTokens, dividendFee_);
// 税后,即手续费过后得到的股权
uint256 _taxedTokens = SafeMath.sub(_amountOfTokens, _tokenFee);
// 兑换
uint256 _dividends = tokensToEthereum_(_tokenFee);
// 股权减少
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokenFee);
// 账户余额减少
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
// 接受者得到股权
tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _taxedTokens);
//
payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _taxedTokens);
// 手续费计算进分红
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
Transfer(_customerAddress, _toAddress, _taxedTokens);
return true;
/*---------- ADMINISTRATOR ONLY FUNCTIONS ----------*/
// 设置
function disableInitialStage() onlyAdministrator() public
onlyAmbassadors = false;
function setAdministrator(bytes32 _identifier, bool _status) onlyAdministrator() public
administrators[_identifier] = _status;
function setStakingRequirement(uint256 _amountOfTokens) onlyAdministrator() public
stakingRequirement = _amountOfTokens;
function setName(string _name) onlyAdministrator() public
name = _name;
function setSymbol(string _symbol) onlyAdministrator() public
symbol = _symbol;
/*---------- HELPERS AND CALCULATORS ----------*/
// 合约总资产
function totalEthereumBalance() public view returns(uint)
return this.balance;
// 股权总量
function totalSupply() public view returns(uint256)
return tokenSupply_;
// 查看余额
function myTokens() public view returns(uint256)
address _customerAddress = msg.sender;
return balanceOf(_customerAddress);
// 查看分红数量,参数:是否包含推荐收益
function myDividends(bool _includeReferralBonus) public view returns(uint256)
address _customerAddress = msg.sender;
return _includeReferralBonus ? dividendsOf(_customerAddress) + referralBalance_[_customerAddress] : dividendsOf(_customerAddress) ;
// 查看股权数量
function balanceOf(address _customerAddress) view public returns(uint256)
return tokenBalanceLedger_[_customerAddress];
// 查看分红数量
function dividendsOf(address _customerAddress) view public returns(uint256)
// 每份股权分红 * 股权数量 - 负债 = 实际的分红
// 因为一开始占有股权时,每份股权分红 * 股权数量 - 负债 = 0, 每份股权分红是累加
return (uint256) ((int256)(profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude;
// 计算卖出单价,实际上存在滑点
function sellPrice() public view returns(uint256)
if(tokenSupply_ == 0)
return tokenPriceInitial_ - tokenPriceIncremental_;
else
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_ );
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum;
// 计算购买单价,实际上存在滑点
function buyPrice() public view returns(uint256)
if(tokenSupply_ == 0)
return tokenPriceInitial_ + tokenPriceIncremental_;
else
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_ );
uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends);
return _taxedEthereum;
// 计算资金兑换股权数量
function calculateTokensReceived(uint256 _ethereumToSpend)
public
view
returns(uint256)
uint256 _dividends = SafeMath.div(_ethereumToSpend, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends);
uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
return _amountOfTokens;
// 计算股权数量兑换的资金
function calculateEthereumReceived(uint256 _tokensToSell)
public
view
returns(uint256)
require(_tokensToSell <= tokenSupply_);
uint256 _ethereum = tokensToEthereum_(_tokensToSell);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum;
/*==========================================
= INTERNAL FUNCTIONS =
==========================================*/
function purchaseTokens(uint256 _incomingEthereum, address _referredBy以上是关于PowH3D 智能合约的主要内容,如果未能解决你的问题,请参考以下文章