DAPP丨LP雙幣質押流動性挖礦分紅系統開發(開發詳細及方案)原始碼案例

xiaofufu發表於2023-03-10

  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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章