欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)

這篇文章主要介紹了區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)文章都會有所收獲,下面我們一起來看看吧。

創(chuàng)新互聯(lián)建站:從2013年創(chuàng)立為各行業(yè)開拓出企業(yè)自己的“網(wǎng)站建設(shè)”服務(wù),為近千家公司企業(yè)提供了專業(yè)的網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)和網(wǎng)站推廣服務(wù), 按需策劃由設(shè)計(jì)師親自精心設(shè)計(jì),設(shè)計(jì)的效果完全按照客戶的要求,并適當(dāng)?shù)奶岢龊侠淼慕ㄗh,擁有的視覺效果,策劃師分析客戶的同行競爭對手,根據(jù)客戶的實(shí)際情況給出合理的網(wǎng)站構(gòu)架,制作客戶同行業(yè)具有領(lǐng)先地位的。

【本文目標(biāo)】通過本文學(xué)習(xí),可以實(shí)現(xiàn)區(qū)塊鏈私募,基金會員工期權(quán)(代幣)激勵時(shí)鎖倉一定時(shí)間,逐步釋放的方法。

【前置條件】1)已經(jīng)完成了一個(gè)ERC20的代幣,本文以作者接觸的CLB為樣例。 2) 懂得在REMIX調(diào)試SOLIDITY語言,不熟悉的參考文章Solidity語言編輯器REMIX指導(dǎo)大全。

需求實(shí)現(xiàn)描述

一般區(qū)塊鏈項(xiàng)目在私募或者員工溝通時(shí),都會明確代幣發(fā)放的政策,一般來說都會要求項(xiàng)目上線后鎖倉多久,分幾年釋放。如果通過合同的方式來人工操作,一個(gè)是實(shí)現(xiàn)比較麻煩或者存在不可控性,另一方面也存在無法取信私募機(jī)構(gòu)或者員工的情況。

那么專業(yè)的團(tuán)隊(duì)會選擇通過智能合約來實(shí)現(xiàn),這是更可信、公開、且不可串改的最佳方式。

這個(gè)實(shí)現(xiàn)概括講包括3步:1)發(fā)布ERC20代幣智能合約 2)配置鎖倉合約參數(shù), 發(fā)布鎖倉的智能合約 3)把要鎖倉的ERC20代幣轉(zhuǎn)入鎖倉智能合約

鎖倉智能合約分析

鎖倉智能合約核心代碼:

/** 

 * @title TokenVesting

 * @dev A token holder contract that can release its token balance gradually like a

 * typical vesting scheme, with a cliff and vesting period. Optionally revocable by the

 * owner.

 */

contract TokenVesting is Ownable {
  using SafeMath for uint256;

  using SafeERC20 for Colorbay;

  event Released(uint256 amount);

  event Revoked();

  // beneficiary of tokens after they are released

  address public beneficiary;

  uint256 public cliff;

  uint256 public start;

  uint256 public duration;

  bool public revocable;

  mapping (address => uint256) public released;

  mapping (address => bool) public revoked;

  /**

   * @dev Creates a vesting contract that vests its balance of any ERC20 token to the

   * _beneficiary, gradually in a linear fashion until _start + _duration. By then all

   * of the balance will have vested.

   * @param _beneficiary address of the beneficiary to whom vested tokens are transferred

   * @param _cliff duration in seconds of the cliff in which tokens will begin to vest

   * @param _start the time (as Unix time) at which point vesting starts

   * @param _duration duration in seconds of the period in which the tokens will vest

   * @param _revocable whether the vesting is revocable or not

   */

  constructor(

    address _beneficiary,

    uint256 _start,

    uint256 _cliff,

    uint256 _duration,

    bool _revocable

  )

    public

  {

    require(_beneficiary != address(0));

    require(_cliff <= _duration);

    beneficiary = _beneficiary;

    revocable = _revocable;

    duration = _duration;

    cliff = _start.add(_cliff);

    start = _start;

  }

  /**

   * @notice Transfers vested tokens to beneficiary.

   * @param _token Colorbay token which is being vested

   */

  function release(Colorbay _token) public {

    uint256 unreleased = releasableAmount(_token);

    require(unreleased > 0);

    released[_token] = released[_token].add(unreleased);

    _token.safeTransfer(beneficiary, unreleased);

    emit Released(unreleased);

  }

  /**

   * @notice Allows the owner to revoke the vesting. Tokens already vested

   * remain in the contract, the rest are returned to the owner.
   * @param _token ERC20 token which is being vested

   */  function revoke(Colorbay _token) public onlyOwner {

    require(revocable);

    require(!revoked[_token]);

    uint256 balance = _token.balanceOf(address(this));

    uint256 unreleased = releasableAmount(_token);

    uint256 refund = balance.sub(unreleased);

    revoked[_token] = true;

    _token.safeTransfer(owner, refund);

    emit Revoked();

  }

  /**

   * @dev Calculates the amount that has already vested but hasn't been released yet.

   * @param _token Colorbay token which is being vested

   */

  function releasableAmount(Colorbay _token) public view returns (uint256) {

    return vestedAmount(_token).sub(released[_token]);

  }

  /**

   * @dev Calculates the amount that has already vested.

   * @param _token ERC20 token which is being vested

   */  function vestedAmount(Colorbay _token) public view returns (uint256) {

    uint256 currentBalance = _token.balanceOf(this);

    uint256 totalBalance = currentBalance.add(released[_token]);

        if (block.timestamp < cliff) {

      return 0;

    } else if (block.timestamp >= start.add(duration) || revoked[_token]) {

      return totalBalance;

    } else {

      return totalBalance.mul(block.timestamp.sub(start)).div(duration);

    }

  }

}

函數(shù)說明:

1,鎖倉合約初始化函數(shù)constructor(...),包含5個(gè)參數(shù):

  • address _beneficiary:接受通證投放的收益賬戶;

  • uint256 _start: 起始時(shí)間(Unix time),提示從什么時(shí)刻開始計(jì)時(shí);

  • uint256 _cliff: 單位為秒(s),斷崖時(shí)間,例如“鎖倉4年,1年之后一次性解凍25%”中的1年

  • uint256 _duration: 單位為秒(s),持續(xù)鎖倉時(shí)間,例如“鎖倉4年,1年之后一次性解凍25%”中的4年;

  • bool _revocable: 是否可回收 (例如公司給了員工張三 10K 代幣鎖倉4年,張三在工作一年的時(shí)候離職了,剩余的部分公司是否可回收)

舉例來說明:

如果 _cliff=半年 ,_duration=1年 具體解凍情況如下: Month 1: I get 0 tokens Month 2: I get 0 tokens Month 3: I get 0 tokens Month 4: I get 0 tokens Month 5: I get 0 tokens Month 6: I get 0 tokens --- End of cliff Month 7: I get 700 tokens (7/12th) Month 8: I get 100 tokens (8/12th) Month 9: I get 100 tokens (9/12th) Month 10: I get 100 tokens (10/12th) Month 11: I get 100 tokens (11/12th) Month 12: I get 100 tokens (12/12th)

2,期權(quán)代幣釋放函數(shù)release(...),包含1個(gè)參數(shù):

  • Colorbay _token:_token為CLB代幣的實(shí)例參數(shù),時(shí)間到后通過該函數(shù)釋放給對應(yīng)的收益賬戶;

3,期權(quán)代幣回收函數(shù)revoke(...),包含1個(gè)參數(shù):

  • Colorbay _token:_token為CLB代幣的實(shí)例參數(shù),把未釋放的代幣打回給之前的分配賬戶池;

4

測試用例驗(yàn)證

1]  管理員賬號發(fā)布一個(gè)ERC20的ColorBay代幣合約

  • 管理員地址:0xca35b7d915458ef540ade6068dfe2f44e8fa733c

  • 代幣合約信息如下:(1) decimals = 18; (2) totalSupply() = 10億; (3) symbol = CLB (4) paused = false (5) owner = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c (6) contract address = 0x692a70d2e424a56d2c6c27aa97d1a86395877b3a

區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)

CLB相關(guān)信息

2] 管理員賬號轉(zhuǎn)發(fā)500萬給員工激勵專用賬號用于期權(quán)激勵專用

  • 管理員地址:0xca35b7d915458ef540ade6068dfe2f44e8fa733c

  • 員工激勵專用賬號地址:0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

  • 轉(zhuǎn)賬操作:(記得去除500萬后面的",")transfer("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c", "5000000,000000000000000000")

  • 【結(jié)果驗(yàn)證】balanceOf("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c") 檢查確認(rèn)余額為500萬CLB。

3] 當(dāng)前賬號切換到員工激勵專用賬號下創(chuàng)建期權(quán)激勵計(jì)劃

  • 場景假設(shè):激勵計(jì)劃起始時(shí)間為[2018.08.06 20:25],2分鐘內(nèi)不得釋放,持續(xù)5分鐘(300s),支持回收未釋放的期權(quán)

  • 員工激勵專用賬號地址:0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

  • 被員工李四的私人收益賬號地址:0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db

  • 調(diào)用函數(shù):  constructor("0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db", "1533558300", "120", "300", true)

    【說明】如何獲得準(zhǔn)確的起始時(shí)間,可用站長工具輸入具體時(shí)間來轉(zhuǎn)換。

  • 期權(quán)激勵智能合約實(shí)例創(chuàng)建成功信息如下:(1) contract address = 0x0fdf4894a3b7c5a101686829063be52ad45bcfb7

4] 在CLB合約下,把CLB通證打給期權(quán)激勵智能合約地址

  • 切換到員工激勵專用賬號0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

  • 執(zhí)行轉(zhuǎn)賬操作,(記得去除100萬后面的",")transfer("0x0fdf4894a3b7c5a101686829063be52ad45bcfb7", "1000000,000000000000000000")

  • 結(jié)果balanceOf("0x0fdf4894a3b7c5a101686829063be52ad45bcfb7") 檢查確認(rèn)余額為100萬,表示CLB代幣已經(jīng)轉(zhuǎn)給期權(quán)激勵智能合約了。

5] [2018.08.06 17:31] 5分鐘(300s)后測試分配期權(quán)

  • 執(zhí)行期權(quán)是否操作release("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")

  • 切換到CLB合約下,查詢李四私人賬號balanceOf("0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db") 檢查確認(rèn)余額為100萬,轉(zhuǎn)賬成功。

區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)

查詢結(jié)果

6] 離職員工激勵計(jì)劃實(shí)施

  • 場景假設(shè)當(dāng)前賬號切換到員工激勵專用賬號下創(chuàng)建期權(quán)激勵計(jì)劃,假定給員工王五做的激勵,起始時(shí)間為[2018.08.06 21:00],2分鐘內(nèi)不得釋放,持續(xù)5分鐘(300s),支持回收期權(quán)。王五在4分鐘的時(shí)候離職,公司收回未激勵代幣,打回到員工激勵專用賬號下。

  • 員工激勵專用賬號:0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

  • 被員工王五私人收益賬號:0x583031d1113ad414f02576bd6afabfb302140225

  • **執(zhí)行操作: ** constructor("0x583031d1113ad414f02576bd6afabfb302140225", "1533560400", "120", "300", true)

  • 期權(quán)激勵智能合約信息如下:contract address = 0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2

7]  在CLB合約下,通證打給期權(quán)激勵智能合約地址

  • 切換到員工激勵專用賬號,在CLB合約下操作0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

  • 王五期權(quán)激勵智能合約實(shí)例地址:0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2

  • 具體操作(記得去除100萬后面的",")transfer("0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2", "1000000,000000000000000000")

  • 查詢王五期權(quán)激勵智能合約的賬戶余額:balanceOf("0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2") 檢查確認(rèn)余額為100萬

  • 查詢員工期權(quán)激勵智能合約的賬戶余額:balanceOf("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c") 檢查確認(rèn)余額為300萬

8] [2018.08.06 21:03] 3分鐘(180s)后測試分配期權(quán)

  • 2分鐘內(nèi)操作release均會失敗回滾。21:03操作釋放函數(shù):release("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")

  • 切換到CLB合約下,查詢王五私人賬號balanceOf("0x583031d1113ad414f02576bd6afabfb302140225") 檢查有76萬代幣釋放到王五收益賬戶。

區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)

9] [2018.08.06 21:05] 4分鐘(240s)后,李四離職,收回分配期權(quán)

revoke("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")

  • 切換到CLB合約下,查詢李四私人賬號balanceOf("0x583031d1113ad414f02576bd6afabfb302140225") 檢查有76萬代幣在王五收益賬戶,沒有增加。

區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)

  • 查詢員工專用賬戶余額balanceOf("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c")

發(fā)現(xiàn)王五剩余未釋放的額度全部返回到員工專用賬號了。

關(guān)于“區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當(dāng)前文章:區(qū)塊鏈鎖倉智能合約怎么實(shí)現(xiàn)
鏈接URL:http://chinadenli.net/article10/ppgpgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、搜索引擎優(yōu)化、面包屑導(dǎo)航企業(yè)網(wǎng)站制作、用戶體驗(yàn)網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)