Last active
May 8, 2021 04:13
-
-
Save percybolmer/3d4490bd9efbb2fb2a9c8a8251a3ed22 to your computer and use it in GitHub Desktop.
A simple Staking method, several bugs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract DevToken is ERC20, Ownable { | |
using Address for address; | |
/** | |
* @notice | |
* This is a mapping where we store all Stakes that are performed on the Contract | |
* The stakes for each address | |
*/ | |
mapping(address => uint256) internal stakes; | |
/** | |
* @notice Wrap the ERC20 constructor with our own construtor, in this case we dont do anything but call the ERC constructor. | |
*/ | |
constructor() ERC20("DevToken", "DEVTK"){ | |
// Here we mint 100000 tokens to the account that creates the smart contract, 18 0s because ERC20 uses 18 Decimals | |
_mint(msg.sender, 100000); | |
} | |
/** | |
* @notice | |
* stake is used to make a stake for an sender. It will remove the amount staked from the stakers account and place those tokens inside a stake container | |
*/ | |
function stake(uint256 _stake) public { | |
// Simple check so that user does not stake 0 | |
require(_stake > 0, "Cannot stake nothing"); | |
// Make sure staker actually is good for it | |
// Burn the amount of tokens on the sender | |
_burn(msg.sender, _stake); | |
// Add the stake to the stakes container | |
stakes[msg.sender] = stakes[msg.sender] + _stake; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment