Compare commits
1 Commits
upgradeabl
...
basic-karm
| Author | SHA1 | Date | |
|---|---|---|---|
| 7600aff80c |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,5 +3,4 @@ build/
|
|||||||
cache/
|
cache/
|
||||||
node_modules/
|
node_modules/
|
||||||
.idea/
|
.idea/
|
||||||
temp/
|
|
||||||
.openzeppelin/
|
|
||||||
|
|||||||
@@ -2,10 +2,6 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
An upgradeable Ethereum ERC20 token minted by my cat, Karma.
|
An Ethereum ERC20 token minted by my cat, Karma.
|
||||||
|
|
||||||
[Ropsten Token](https://ropsten.etherscan.io/token/0xdCDA9d33Eb6eEf5C748743Bb1e2B7FBFBc500904)
|
[Ropsten ERC20 Token](https://ropsten.etherscan.io/token/0x5Fd2d64C7223D2D67eA287EA1c4Cb95e03209c84)
|
||||||
|
|
||||||
[Ropsten Contract](https://ropsten.etherscan.io/address/0xdCDA9d33Eb6eEf5C748743Bb1e2B7FBFBc500904)
|
|
||||||
|
|
||||||
[Current KarmaV3 Contract](https://ropsten.etherscan.io/address/0x9e3be3194de7a033f82e7ac121b1036dd817f4c7#code)
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
pragma solidity >=0.4.22 <0.9.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
// https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations#initial-migration
|
|
||||||
contract Migrations {
|
contract Migrations {
|
||||||
address public owner = msg.sender;
|
address public owner = msg.sender;
|
||||||
uint public last_completed_migration;
|
uint public last_completed_migration;
|
||||||
@@ -11,13 +10,10 @@ contract Migrations {
|
|||||||
msg.sender == owner,
|
msg.sender == owner,
|
||||||
"This function is restricted to the contract's 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 {
|
function setCompleted(uint completed) public restricted {
|
||||||
last_completed_migration = completed;
|
last_completed_migration = completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
// Copyright [2021] - [2021], [Shaun Reed] and [Karma] contributors
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
pragma solidity >= 0.8.0;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Import ERC Token Standard #20 Interface
|
|
||||||
// ETH EIP repo: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
|
|
||||||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Karma Contract
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
contract Karma is Initializable, ERC20Upgradeable
|
|
||||||
{
|
|
||||||
function initialize(string memory name, string memory symbol, uint256 initialSupply) public virtual initializer {
|
|
||||||
__ERC20_init(name, symbol);
|
|
||||||
_mint(_msgSender(), initialSupply);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
// Copyright [2021] - [2021], [Shaun Reed] and [Karma] contributors
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
pragma solidity >= 0.8.0;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Import ERC Token Standard #20 Interface
|
|
||||||
// ETH EIP repo: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
|
|
||||||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Karma Contract
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
contract KarmaV2 is Initializable, ERC20Upgradeable
|
|
||||||
{
|
|
||||||
function initialize(string memory name, string memory symbol, uint256 initialSupply) public virtual initializer {
|
|
||||||
__ERC20_init(name, symbol);
|
|
||||||
_mint(_msgSender(), initialSupply);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isToken() public returns (bool)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// Copyright [2021] - [2021], [Shaun Reed] and [Karma] contributors
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
pragma solidity >= 0.8.0;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Import ERC Token Standard #20 Interface
|
|
||||||
// ETH EIP repo: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
|
|
||||||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Karma Contract
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
contract KarmaV3 is Initializable, ERC20Upgradeable
|
|
||||||
{
|
|
||||||
function initialize(string memory name, string memory symbol, uint256 initialSupply) public virtual initializer {
|
|
||||||
__ERC20_init(name, symbol);
|
|
||||||
_mint(_msgSender(), initialSupply);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isToken() public pure returns (bool)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAddress() public view returns (address)
|
|
||||||
{
|
|
||||||
return address(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
110
contracts/karma-ERC20.sol
Normal file
110
contracts/karma-ERC20.sol
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
// Copyright [2021] - [2021], [Shaun Reed] and [Karma] contributors
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity >= 0.8.0;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Import ERC Token Standard #20 Interface
|
||||||
|
// ETH EIP repo: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// SourceCoin Contract
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
contract Karma is IERC20
|
||||||
|
{
|
||||||
|
string public name;
|
||||||
|
string public symbol;
|
||||||
|
uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it
|
||||||
|
uint256 public _totalSupply;
|
||||||
|
|
||||||
|
// Balances for each account; A hashmap using wallet address as key and uint as value
|
||||||
|
mapping(address => uint) balances;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get the total circulating supply of the token
|
||||||
|
function totalSupply() public override view returns (uint)
|
||||||
|
{
|
||||||
|
// By subtracting from tokens held at address(0), we provide an address to 'burn' the supply
|
||||||
|
return _totalSupply - balances[address(0)]; // Subtract from tokens held at address(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the token balance for account `tokenOwner`
|
||||||
|
function balanceOf(address tokenOwner) public override view returns (uint balance)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
allowed[msg.sender][spender] = tokens;
|
||||||
|
emit Approval(msg.sender, spender, tokens);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transfer the balance from owner's account to another account
|
||||||
|
function transfer(address to, uint tokens) public override returns (bool success)
|
||||||
|
{
|
||||||
|
balances[msg.sender] = balances[msg.sender] - tokens;
|
||||||
|
balances[to] = balances[to] + tokens;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
5
migrations/2_deploy.js
Normal file
5
migrations/2_deploy.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const Karma = artifacts.require("Karma");
|
||||||
|
|
||||||
|
module.exports = function (deployer) {
|
||||||
|
deployer.deploy(Karma);
|
||||||
|
};
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
const Karma = artifacts.require('Karma');
|
|
||||||
|
|
||||||
module.exports = async function (deployer) {
|
|
||||||
await deployer.deploy(Karma);
|
|
||||||
};
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
const Karma = artifacts.require('Karma');
|
|
||||||
|
|
||||||
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
|
|
||||||
|
|
||||||
module.exports = async function (deployer) {
|
|
||||||
await deployProxy(
|
|
||||||
Karma,
|
|
||||||
['Karma', 'KRMA', '1000000000000000000000000000'],
|
|
||||||
{ deployer, initializer: 'initialize' }
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
|
||||||
|
|
||||||
const Karma = artifacts.require('Karma');
|
|
||||||
const KarmaV2 = artifacts.require('KarmaV2');
|
|
||||||
|
|
||||||
module.exports = async function (deployer) {
|
|
||||||
const existing = await Karma.deployed();
|
|
||||||
await upgradeProxy(existing.address, KarmaV2, { deployer });
|
|
||||||
};
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
|
||||||
|
|
||||||
const KarmaV2 = artifacts.require('KarmaV2');
|
|
||||||
const KarmaV3 = artifacts.require('KarmaV3');
|
|
||||||
|
|
||||||
module.exports = async function (deployer) {
|
|
||||||
const existing = await KarmaV2.deployed();
|
|
||||||
await upgradeProxy(existing.address, KarmaV3, { deployer });
|
|
||||||
};
|
|
||||||
24493
package-lock.json
generated
24493
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,12 +11,8 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@openzeppelin/contracts": "^4.0.0",
|
"@openzeppelin/contracts": "^4.0.0",
|
||||||
"@openzeppelin/contracts-upgradeable": "^4.1.0",
|
|
||||||
"@openzeppelin/truffle-upgrades": "^1.6.0",
|
|
||||||
"@truffle/hdwallet-provider": "^1.3.0",
|
"@truffle/hdwallet-provider": "^1.3.0",
|
||||||
"chai": "^4.3.4",
|
|
||||||
"truffle": "^5.3.3",
|
"truffle": "^5.3.3",
|
||||||
"truffle-flattener": "^1.5.0",
|
|
||||||
"truffle-plugin-verify": "^0.5.7"
|
"truffle-plugin-verify": "^0.5.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ module.exports = {
|
|||||||
// tab if you use this network and you must also set the `host`, `port` and `network_id`
|
// tab if you use this network and you must also set the `host`, `port` and `network_id`
|
||||||
// options below to some value.
|
// options below to some value.
|
||||||
//
|
//
|
||||||
development: {
|
// development: {
|
||||||
host: "127.0.0.1", // Localhost (default: none)
|
// host: "127.0.0.1", // Localhost (default: none)
|
||||||
port: 8545, // Standard Ethereum port (default: none)
|
// port: 8545, // Standard Ethereum port (default: none)
|
||||||
network_id: "*", // Any network (default: none)
|
// network_id: "*", // Any network (default: none)
|
||||||
},
|
// },
|
||||||
// Another network with more advanced options...
|
// Another network with more advanced options...
|
||||||
// advanced: {
|
// advanced: {
|
||||||
// port: 8777, // Custom port
|
// port: 8777, // Custom port
|
||||||
@@ -116,6 +116,5 @@ module.exports = {
|
|||||||
|
|
||||||
db: {
|
db: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user