Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
function burn(address account, uint256 amount) public onlyOwner returns(bool) {
_burn(account, amount);
return true;
}
/**
* @notice mint is used to create tokens and assign them to msg.sender
*
* See {_mint}
* Requires
/**
* @notice _allowances is used to manage and control allownace
* An allowance is the right to use another accounts balance, or part of it
*/
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @notice Approval is emitted when a new Spender is approved to spend Tokens on
* the Owners account
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @notice getOwner just calls Ownables owner function.
* returns owner of the token
*
*/
function getOwner() external view returns (address) {
return owner();
}
/**
* @notice allowance is used view how much allowance an spender has
it ("allow account some allowance", async() => {
devToken = await DevToken.deployed();
try{
// Give account(0) access too 100 tokens on creator
await devToken.approve('0x0000000000000000000000000000000000000000', 100);
}catch(error){
assert.equal(error.reason, 'DevToken: approve cannot be to zero address', "Should be able to approve zero address");
}
@percybolmer
percybolmer / Crypto-BEP20-Stakeable-Empty
Last active July 23, 2021 06:42
An empty stakeable contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
* @notice Stakeable is a contract who is ment to be inherited by other contract that wants Staking capabilities
*/
contract Stakeable {
/**
@percybolmer
percybolmer / Crypto-BEP20-DevToken-Inheritance
Created July 23, 2021 06:46
DevToken inherits two other contracts, merging them into one
import "./Ownable.sol";
import "./Stakable.sol";
/**
* @notice DevToken is a development token that we use to learn how to code solidity
* and what BEP-20 interface requires
*/
contract DevToken is Ownable, Stakeable{
@percybolmer
percybolmer / Crypto-BEP20-Stakeable-Structs
Last active July 23, 2021 07:14
A beginning of all the strcuts needed for our staking
/**
* @notice Constructor since this contract is not ment to be used without inheritance
* push once to stakeholders for it to work proplerly
*/
constructor() {
// This push is needed so we avoid index 0 causing bug of index-1
stakeholders.push();
}
/**
* @notice
/**
* @notice _addStakeholder takes care of adding a stakeholder to the stakeholders array
*/
function _addStakeholder(address staker) internal returns (uint256){
// Push a empty item to the Array to make space for our new stakeholder
stakeholders.push();
// Calculate the index of the last item in the array by Len-1
uint256 userIndex = stakeholders.length - 1;
// Assign the address to the new index
stakeholders[userIndex].user = staker;
@percybolmer
percybolmer / Crypto-BEP20-Stakeable-Stake
Created July 23, 2021 07:17
A example Staking Function
/**
* @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
* StakeID
*/
function _stake(uint256 _amount) internal{
// Simple check so that user does not stake 0
require(_amount > 0, "Cannot stake nothing");