0

I´m working in a smart contract where the tokens are distributed to 4 addresses. My intention is to set a timelock vesting to 3 addresses, so the tokens of those wallets will be released after 48 months. I´ve tried several methods to implement it, but I couldn´t make it work. Any help? This is the ropsten address of the contract https://ropsten.etherscan.io/address/0x1f80b573e5e4bf8b9025e4e6ebbcf3070b9d1074#code and this is the code:

pragma solidity ^0.4.24;

/*

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/



library SafeMath {
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        assert(c / a == b);
        return c;
    }

    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        // assert(b > 0); // Solidity automatically throws when dividing by 0
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold
        return c;
    }

    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        assert(b <= a);
        return a - b;
    }

    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        assert(c >= a);
        return c;
    }
}



contract Ownable {

    address public owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    constructor() internal {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    function transferOwnership(address newOwner) public onlyOwner {
        require(newOwner != address(0));
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }
}





contract VALLE_ERC20 is Ownable {

    using SafeMath for uint256;


    mapping (address => uint256) public balances;


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



    // Public variables for the VALLE ERC20 VLL token contract
    string public constant standard = "VALLE erc20 and Genesis";
    uint256 public constant decimals = 18;   // hardcoded to be a constant
    string public name = "VALLE";
    string public symbol = "VLL";
    uint256 public totalSupply;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);



    function balanceOf(address _owner) public view returns (uint256) {
        return balances[_owner];
    }

    function transfer(address _to, uint256 _value) public returns (bool) {

        require(_to != address(0));
        require(_value <= balances[msg.sender]);
        // SafeMath.sub will throw if there is not enough balance.
        balances[msg.sender] = balances[msg.sender].sub(_value);


        balances[_to] = balances[_to].add(_value);

        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
        require(_to != address(0));
        require(_value <= balances[_from]);
        require(_value <= allowed[_from][msg.sender]);

        balances[_from] = balances[_from].sub(_value);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);


        balances[_to] = balances[_to].add(_value);


        emit Transfer(_from, _to, _value);
        return true;
    }

    function approve(address _spender, uint256 _value) public returns (bool) {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    function allowance(address _owner, address _spender) public view returns (uint256) {
        return allowed[_owner][_spender];
    }

    function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
        allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
        emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }

    function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
        uint oldValue = allowed[msg.sender][_spender];
        if (_subtractedValue > oldValue) {
            allowed[msg.sender][_spender] = 0;
        } else {
            allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
        }
        emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }

    /* Approve and then communicate the approved contract in a single tx */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
        tokenRecipient spender = tokenRecipient(_spender);

        if (approve(_spender, _value)) {
            spender.receiveApproval(msg.sender, _value, this, _extraData);
            return true;
        }
    }
}



interface tokenRecipient {
    function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external ;
}


//
// This creates and adds two genesis pools of VLL tokens to the balance of the A,B,C and D ETH addresses
//


contract VALLE is VALLE_ERC20 {


        address public A;
        address public B;
        address public C;
        address public D;


    constructor (

        ) public {

        A = 0x90Cbbe589765c0992cf2A2316BAB532A95C80a2a;
        B = 0x145405fC576fee86f2AdFBBDb3F1238F8B59F2d0;
        C = 0xC349954E5e620aCBB060b52B24a90A59d3eb10e8;
        D = 0x55D5C6475AAFF21e950Aa072D102Be524B4e6f5F;


        balances[A]=balances[A].add(5000000*(uint256(10)**decimals));
        balances[B]=balances[B].add(3000000*(uint256(10)**decimals));
        balances[C]=balances[C].add(1000000*(uint256(10)**decimals));
        balances[D]=balances[D].add(1000000*(uint256(10)**decimals));

        totalSupply=balances[A]+balances[B]+balances[C]+balances[D];


    }


}
1

You have 2 ways of dealing with time locked tokens.

1) implement the lock inside the token contract

  • add a mapping where you store addresses that are time locked
  • in the transfer() and transferFrom() methods, add a check for time has passed if the msg.sender is present in said mapping.

2) implement the lock in 3 new smart contracts that act as vaults. ( this could be a solution if your token contract is already live )

  • implement an "exit" method that calls the erc20 contract
  • only allow execution if "now" is later than the time you want them to be unlocked.

Method 2 would be preferred since it would not increase gas costs for every transfer call just because of the 3 locked wallets.

1
  • Do you know the address of any contract that has already implemented your option 2? – Gerardo Jul 29 '18 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.