DAPP丨LP雙幣質押流動性挖礦分紅系統開發(開發詳細及方案)原始碼案例
Blockchain refers to a technical solution to collectively maintain a reliable database through centralization and trust.This technical scheme mainly allows any number of nodes in the participating system to pass a series of data blocks generated by using cryptography methods.Each data block contains all the system information exchange data in a certain period of time,and generates data fingerprints to verify the validity of their information and link the next database block
智慧合約是基於事件驅動有狀態,可部署共享的分散式資料庫上的計算機程式,多用IF-THEN語句。廣義來說,智慧合約是一種可以實現自我執行和自我驗證的計算機協議。
///notice calculte exchange rate according to current stage
///return exchange rate.zero if not in sale.
function exchangeRate()constant returns(uint256){
if(stage()==Stage.Early){
return venPerEthEarlyStage;
}
if(stage()==Stage.Normal){
return venPerEth;
}
return 0;
}
///notice for test purpose
function blockTime()constant returns(uint32){
return uint32(block.timestamp);
}邏輯及需求分析I35詳情7O98開發O7I8
///notice estimate stage
///return current stage
function stage()constant returns(Stage){
if(finalized){
return Stage.Finalized;
}
if(!initialized){
//deployed but not initialized
return Stage.Created;
}
if(blockTime()<startTime){
//not started yet
return Stage.Initialized;
}
if(uint256(soldOut.official).add(soldOut.channels)>=publicSupply){
//all sold out
return Stage.Closed;
}
if(blockTime()<endTime){
//in sale
if(blockTime()<startTime.add(earlyStageLasts)){
//early bird stage
return Stage.Early;
}
//normal stage
return Stage.Normal;
}
//closed
return Stage.Closed;
}開發原始碼及功能:mrsFu123
function isContract(address _addr)constant internal returns(bool){
uint size;
if(_addr==0)return false;
assembly{
size:=extcodesize(_addr)
}
return size>0;
}
///notice entry to buy tokens
function()payable{
buy();
}
///notice entry to buy tokens
function buy()payable{
//reject contract buyer to avoid breaking interval limit
require(!isContract(msg.sender));
require(msg.value>=0.01 ether);
uint256 rate=exchangeRate();
//here don't need to check stage.rate is only valid when in sale
require(rate>0);
//each account is allowed once in minBuyInterval
require(blockTime()>=ven.lastMintedTimestamp(msg.sender)+minBuyInterval);
uint256 requested;
//and limited to maxBuyEthAmount
if(msg.value>maxBuyEthAmount){
requested=maxBuyEthAmount.mul(rate);
}else{
requested=msg.value.mul(rate);
}
uint256 remained=officialLimit.sub(soldOut.official);
if(requested>remained){
//exceed remained
requested=remained;
}
uint256 ethCost=requested.div(rate);
if(requested>0){
ven.mint(msg.sender,requested,true,blockTime());
//transfer ETH to vault
ethVault.transfer(ethCost);
soldOut.official=requested.add(soldOut.official).toUINT120();
onSold(msg.sender,requested,ethCost);
}
uint256 toReturn=msg.value.sub(ethCost);
if(toReturn>0){
//return over payed ETH
msg.sender.transfer(toReturn);
}
}
///notice returns tokens sold officially
function officialSold()constant returns(uint256){
return soldOut.official;
}
///notice returns tokens sold via channels
function channelsSold()constant returns(uint256){
return soldOut.channels;
}
///notice manually offer tokens to channel
function offerToChannel(address _channelAccount,uint256 _venAmount)onlyOwner{
Stage stg=stage();
//since the settlement may be delayed,so it's allowed in closed stage
require(stg==Stage.Early||stg==Stage.Normal||stg==Stage.Closed);
soldOut.channels=_venAmount.add(soldOut.channels).toUINT120();
//should not exceed limit
require(soldOut.channels<=channelsLimit);
ven.mint(
_channelAccount,
_venAmount,
true,//unsold tokens can be claimed by channels portion
blockTime()
);
onSold(_channelAccount,_venAmount,0);
}
///notice initialize to prepare for sale
///param _ven The address VEN token contract following ERC20 standard
///param _ethVault The place to store received ETH
///param _venVault The place to store non-publicly supplied VEN tokens
function initialize(
VEN _ven,
address _ethVault,
address _venVault)onlyOwner{
require(stage()==Stage.Created);
//ownership of token contract should already be this
require(_ven.owner()==address(this));
require(address(_ethVault)!=0);
require(address(_venVault)!=0);
ven=_ven;
ethVault=_ethVault;
venVault=_venVault;
ven.mint(
venVault,
reservedForTeam.add(reservedForOperations),
false,//team and operations reserved portion can't share unsold tokens
blockTime()
);
ven.mint(
venVault,
privateSupply.add(commercialPlan),
true,//private ICO and commercial plan can share unsold tokens
blockTime()
);
initialized=true;
onInitialized();
}
///notice finalize
function finalize()onlyOwner{
//only after closed stage
require(stage()==Stage.Closed);
uint256 unsold=publicSupply.sub(soldOut.official).sub(soldOut.channels);
if(unsold>0){
//unsold VEN as bonus
ven.offerBonus(unsold);
}
ven.seal();
finalized=true;
onFinalized();
}
event onInitialized();
event onFinalized();
event onSold(address indexed buyer,uint256 venAmount,uint256 ethCost);
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2939005/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- LP流動性質押挖礦開發正式版丨LP流動性質押挖礦系統開發(詳細及案例)丨原始碼原始碼
- dapp/defi/lp流動性質押挖礦分紅系統開發(開發規則)丨詳細及原始碼APP原始碼
- DAPP智慧合約LP流動性質押挖礦分紅系統開發詳細及功能丨原始碼案例APP原始碼
- defi/dapp/lp/ido質押流動性挖礦分紅系統開發(案例及成熟)丨原始碼APP原始碼
- DAPP智慧合約代幣質押流動性挖礦分紅系統開發原始碼丨(詳細及案例)APP原始碼
- DAPP丨LP代幣合約流動性質押挖礦分紅系統開發(開發需求及案例)APP
- dapp/defi流動性lp代幣質押挖礦系統開發技術詳細丨原始碼案例APP原始碼
- defi/dapp/lp/ido質押流動性挖礦分紅系統開發(案例原始碼)APP原始碼
- 單雙幣/字母幣流動性質押挖礦分紅系統開發詳細及方案
- DAO流動性質押挖礦分紅系統開發(開發案例)丨DAO流動性質押挖礦分紅原始碼原始碼
- dapp/lp/defi代幣合約質押挖礦分紅系統開發詳細及規則丨原始碼案例APP原始碼
- DAPP鏈遊質押挖礦開發詳情丨DAPP鏈遊流動性質押挖礦分紅系統開發成熟案例及原始碼部署APP原始碼
- DAPP/LP代幣合約流動性質押挖礦分紅系統開發(規則及詳細)原始碼部署APP原始碼
- DAPP流動性質押挖礦NFT鑄造分紅系統開發詳細分析丨原始碼方案APP原始碼
- DAO/LP代幣質押流動性挖礦分紅系統開發(方案及專案)丨原始碼功能原始碼
- DAPP/LP流動性質押挖礦系統開發(程式碼及案例)APP
- dao代幣質押流動性挖礦開發正式版丨dao代幣質押流動性挖礦系統開發案例詳細及原始碼原始碼
- dapp/defi智慧合約流動性LP質押挖礦分紅系統開發(開發程式)及方案原始碼APP原始碼
- dapp/defi智慧合約流動性LP質押挖礦分紅系統開發方案原始碼APP原始碼
- dapp質押LP流動性挖礦系統開發詳情方案APP
- ULAB流動性質押挖礦系統開發(方案及詳細)丨ULAB流動性質押挖礦開發運營版及原始碼原始碼
- LP丨DAPP智慧合約質押挖礦分紅系統開發詳細方案及邏輯APP
- LP流動性質押挖礦系統開發流程解析丨LP流動性質押挖礦開發成品原始碼功能原始碼
- DAO代幣流動性質押挖礦分紅系統開發(開發詳細)及邏輯原始碼原始碼
- dapp流動性質押挖礦LP系統開發模式案例APP模式
- DAO代幣流動性質押挖礦分紅系統開發(規則及方案)案例原始碼原始碼
- defi丨dapp丨dao丨ido丨lp子母幣/單雙幣/機槍池流動性代幣質押挖礦系統開發案例及原始碼APP原始碼
- defi質押LP流動性挖礦dapp系統開發(模式詳情)LP流動性挖礦系統開發APP模式
- 流動性質押挖礦開發原始碼(海外版)丨流動性質押挖礦系統開發(詳細及規則)原始碼
- DeFi/DApp單雙幣/子母幣流動性質押LP挖礦專案系統開發案例APP
- lp流動性質押挖礦系統開發|案例詳情|原始碼出售原始碼
- DAPP代幣LP質押流動性挖礦系統開發(功能詳情)APP
- PtahDao/ProTradex/Meta2032流動性質押挖礦分紅系統開發(開發方案)及詳細原始碼原始碼
- DAPP/PIL派鏈NFT鑄造流動性質押挖礦分紅系統開發技術詳細丨案例原始碼APP原始碼
- defi流動性質押挖礦系統開發方案 | 流動性質押挖礦系統開發 DAPPAPP
- dao丨ido丨lp丨dapp丨defi單雙幣/子母幣流動性質押挖礦系統開發步驟詳細/指南教程APP
- 流動性質押挖礦開發規則丨流動性質押挖礦系統開發(方案及詳情)及程式碼部署
- DAPP字母幣(雙幣)質押LP挖礦系統開發APP