DAPP丨LP代幣合約流動性質押挖礦分紅系統開發(開發需求及案例)

xiaofufu發表於2023-03-10

  


  區塊鏈是一種技術。簡單、通俗來說,區塊鏈技術就是人人記賬,或者分散式賬本。




在網際網路時代,每個系統背後都有資料庫,這個資料庫可以看作是一個大的賬本,以往都是維護系統的人負責管理資料庫,記錄使用者的行為,也就是記賬,而區塊鏈“去中心化”,它讓系統中的每一個成員都參與其中,不僅人人記賬,而且透過連結,人人都能擁有完整的賬本


  Supplies supplies;


  //Packed to 256bit to save gas usage.


  struct Account{


  //uint112's max value is about 5e33.


  //it's enough to present amount of tokens


  uint112 balance;


  //raw token can be transformed into balance with bonus


  uint112 rawTokens;


  //safe to store timestamp


  uint32 lastMintedTimestamp;


  }


  //Balances for each account


  mapping(address=>Account)accounts;


  //Owner of account approves the transfer of an amount to another account


  mapping(address=>mapping(address=>uint256))allowed;


  //bonus that can be shared by raw tokens


  uint256 bonusOffered;


  //Constructor 


  function VEN(){


  }


  function totalSupply()constant returns(uint256 supply){


  return supplies.total;


  }


  //Send back ether sent to me


  function(){


  revert();


  }設計及方案:mrsfu123


  //If sealed,transfer is enabled and mint is disabled


  function isSealed()constant returns(bool){


  return owner==0;


  }


  function lastMintedTimestamp(address _owner)constant returns(uint32){


  return accounts[_owner].lastMintedTimestamp;


  }


  //Claim bonus by raw tokens


  function claimBonus(address _owner)internal{


  require(isSealed());


  if(accounts[_owner].rawTokens!=0){


  uint256 realBalance=balanceOf(_owner);


  uint256 bonus=realBalance


  .sub(accounts[_owner].balance)


  .sub(accounts[_owner].rawTokens);


  accounts[_owner].balance=realBalance.toUINT112();


  accounts[_owner].rawTokens=0;


  if(bonus>0){


  Transfer(this,_owner,bonus);


  }


  }


  }


  //What is the balance of a particular account?


  function balanceOf(address _owner)constant returns(uint256 balance){


  if(accounts[_owner].rawTokens==0)


  return accounts[_owner].balance;


  if(bonusOffered>0){


  uint256 bonus=bonusOffered


  .mul(accounts[_owner].rawTokens)


  .div(supplies.rawTokens);


  return bonus.add(accounts[_owner].balance)


  .add(accounts[_owner].rawTokens);


  }


  return uint256(accounts[_owner].balance)


  .add(accounts[_owner].rawTokens);


  }


  //Transfer the balance from owner's account to another account


  function transfer(address _to,uint256 _amount)returns(bool success){


  require(isSealed());


  //implicitly claim bonus for both sender and receiver


  claimBonus(msg.sender);


  claimBonus(_to);


  //according to VEN's total supply,never overflow here


  if(accounts[msg.sender].balance>=_amount


  &&_amount>0){


  accounts[msg.sender].balance-=uint112(_amount);


  accounts[_to].balance=_amount.add(accounts[_to].balance).toUINT112();


  Transfer(msg.sender,_to,_amount);


  return true;


  }else{


  return false;


  }


  }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2939011/,如需轉載,請註明出處,否則將追究法律責任。

相關文章