wallet lock and unlock in solidity

Viewed 34

i want create a simple smartcontract, where initial supply is 1000 & 1000 to a specific wallet.now i want the supply of wallet(1000) to lock for a year and every month 5% of that supply should be added to initial supply.

so far i develop

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

contract Timer{

uint256 public  intialSuply= 1000;
address public wallet= 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
address public  owner;
mapping (address=>uint) public  balances;

constructor(){
    owner=msg.sender;
     balances[wallet]=1000;
}

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


function locker()public {

}

}

1 Answers

Your post explanation and the code example you've provided is very unclear. I assume you're not using the standards of ERC-20 and only need to keep track of a single parameter of initialSupply.

Check this out :

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

contract Timer{
    /* 
       @param initialSupply : adding 18 decimals to avoid fraction 
    */
    uint256 public initialSupply = 1000 * (10 ** 18);
    uint256 public ts_end;
    address public wallet = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
    address public owner;
    bool public claimed;
    mapping (address => uint256) public balances;

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

    constructor() {
        owner = msg.sender;
        balances[wallet] = initialSupply;
        /* Assuming a year with 365-days , i.e no leep year */
        ts_end = block.timestamp + (86400 * 30 * 12);
        
    }

    function claim() public onlyOwner {
        require(ts_end > block.timestamp,"Can not claim yet");
        require(claimed = false,"Already claimed");
        claimed = true;

        for(uint i = 0 ; i < 12 ; i++) {
            initialSupply += (initialSupply * 15) / 100;
        }
        balances[wallet] = initialSupply;
    }

    function balanceOf() external view returns(uint256) {
        return balances[msg.sender];
    }

}
Related