智能合约Token分发方案

Smart contract Token distribution solution

我对代币销售有疑问:代币分配如何运作?

一个例子:

10% for private sale
30% for public sale 
20% for dev team
40% for rewards 

令牌创建时将转移到这些地址或之后转移到这些地址的令牌数量?

这取决于令牌合约的实现,可以是两者。

例如在创建代币后立即铸造 100 个代币以 public 销售,并保留另外 50 个代币稍后由开发团队地址归属:

pragma solidity ^0.8;

contract MyToken {
    mapping (address => uint256) _balances;
    mapping (address => Vesting) _vesting;
    
    struct Vesting {
        uint256 amount;
        uint64 unlockTime;
    }
    
    constructor() {
        address publicSaleAddress = address(0x123);
        address devTeamAddress = address(0x456);
        
        // set the `publicSaleAddress` balance right away
        _balances[publicSaleAddress] = 100;

        // don't set the `devTeamAddress` balance now
        // instead, allow them to claim it after some time
        uint64 deadline = uint64(block.timestamp) + 365 days;
        _vesting[devTeamAddress] = Vesting(
            50,
           deadline
        );
    }
    
    function unvest() external {
        // check if they have something to unvest
        require(_vesting[msg.sender].amount > 0, 'Nothing to unvest');
        
        // check if they are allowed to unvest yet
        require(_vesting[msg.sender].unlockTime >= block.timestamp, 'Not yet');
        
        // increase their balance
        _balances[msg.sender] += _vesting[msg.sender].amount;
        
        // prevent them from claiming the balance again
        _vesting[msg.sender] = Vesting(0, 0);
    }
}