WIP Commit - Truffle verification

+ https://github.com/rkalis/truffle-plugin-verify
This commit is contained in:
2021-04-30 22:57:51 -04:00
parent 5d78e05703
commit ebb4e5a2d5
10 changed files with 1056 additions and 78 deletions

View File

@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
// https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations#initial-migration
contract Migrations {
address public owner = msg.sender;
uint public last_completed_migration;
@@ -10,10 +11,13 @@ contract Migrations {
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
_; // Execute the body of the function
}
// A function with the signature `setCompleted(uint)` is required.
// + Restrict this call to the owner of this Migration contract
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}

View File

@@ -8,12 +8,15 @@ pragma solidity >= 0.8.0;
// ETH EIP repo: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
// ----------------------------------------------------------------------------
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
// ----------------------------------------------------------------------------
// SourceCoin Contract
// Karma Contract
// ----------------------------------------------------------------------------
contract Karma is IERC20
contract Karma is IERC20, Initializable
{
// Avoid initializing fields in declarations
// https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#avoid-initial-values-in-field-declarations
string public name;
string public symbol;
uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it
@@ -24,24 +27,46 @@ contract Karma is IERC20
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
//
// /**
// * Constrctor function
// *
// * Initializes contract with initial supply tokens to the creator of the contract
// */
// constructor()
// {
// name = "Karma"; // Name of the token
// symbol = "KRMA"; // Abbreviation of the token
// decimals = 18; // Number of decimals that can be used to split token
//
//
// // FORMAT: <SUPPLY><DECIMALS>
// // Where SUPPLY is the number of coins in base 10 decimal notation
// // And DECIMALS is a trailing number of 0's; Count must match `decimals` value set above
// // 1000 000 000 000000000000000000 == 1 billion total supply;
// // + trailing 0's represent the 18 decimal locations that can be used to send fractions
// _totalSupply = 1000000000000000000000000000;
//
//
// // Set the remaining balance of the contract owner to the total supply
// balances[msg.sender] = _totalSupply; // msg.sender is the calling address for this constructor
// // Transfer the total supply to the contract owner on initialization
// emit Transfer(address(0), msg.sender, _totalSupply); // address(0) is used to represent a new TX
// }
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor()
function initialize() public initializer
{
// ERC20 Standard dictates names of these variables
// https://ethereum.org/en/developers/docs/standards/tokens/erc-20/#body
name = "Karma"; // Name of the token
symbol = "KRMA"; // Abbreviation of the token
decimals = 18; // Number of decimals that can be used to split token
// FORMAT: <SUPPLY><DECIMALS>
// Where SUPPLY is the number of coins in base 10 decimal notation
// And DECIMALS is a trailing number of 0's; Count must match `decimals` value set above
// 1000 000 000 000000000000000000 == 1 billion total supply;
// 1000 000 000 000000000000000000 == 1 billion total supply;
// + trailing 0's represent the 18 decimal locations that can be used to send fractions
_totalSupply = 1000000000000000000000000000;
@@ -66,20 +91,42 @@ contract Karma is IERC20
return balances[tokenOwner]; // Return the balance of the owner's address
}
/// @param tokenOwner The address of the account owning tokens
/// @param spender The address of the account able to transfer the tokens
/// returns Amount of remaining tokens allowed to spent
// To initiate a transaction, we first approve an address to withdraw from our wallet
// + msg.sender is approving spender to withdraw from its balance _value tokens
// Allow `spender` to withdraw from your account, multiple times, up to the `tokens`
// If this function is called again it overwrites the current allowance with _value
function approve(address spender, uint _value) public override returns (bool success)
{
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
//if ((value != 0) && (allowed[msg.sender][spender] != 0)) throw;
allowed[msg.sender][spender] = _value;
emit Approval(msg.sender, spender, _value);
return true;
}
// Helper to check the amount of tokens allowed for this spender at this address
// @param tokenOwner The address of the account owning tokens
// @param spender The address of the account able to transfer the tokens
// returns Amount of remaining tokens allowed to spent
function allowance(address tokenOwner, address spender) public override view returns (uint remaining)
{
return allowed[tokenOwner][spender];
}
// Allow `spender` to withdraw from your account, multiple times, up to the `tokens`
// If this function is called again it overwrites the current allowance with _value.
function approve(address spender, uint tokens) public override returns (bool success)
// Send `_value` amount of tokens from address `from` to address `to`
function transferFrom(address from, address to, uint _value) public override returns (bool success)
{
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
// Set this wallet balance -= _value
balances[from] = balances[from] - _value;
// Update this wallet's approved balance for the withdrawing address
// uint allowance = allowed[from][msg.sender];
allowed[from][msg.sender] -= _value;
// Add the amount of tokens to the balance at the receiving address
balances[to] = balances[to] + _value;
emit Transfer(from, to, _value);
return true;
}
@@ -91,20 +138,5 @@ contract Karma is IERC20
emit Transfer(msg.sender, to, tokens);
return true;
}
// Send `tokens` amount of tokens from address `from` to address `to`
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom(address from, address to, uint tokens) public override returns (bool success)
{
balances[from] = balances[from] - tokens;
allowed[from][msg.sender] = allowed[from][msg.sender] - tokens;
balances[to] = balances[to] - tokens;
emit Transfer(from, to, tokens);
return true;
}
}