Skip to content

Commit d128e4b

Browse files
authored
Merge pull request #37 from akropolisio/add-mint-started
Add mintStarted method
2 parents dc0b546 + cb08ad6 commit d128e4b

26 files changed

Lines changed: 1297 additions & 377 deletions

.devcontainer/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/python-3/.devcontainer/base.Dockerfile
2+
3+
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
4+
ARG VARIANT="3.10-bullseye"
5+
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
6+
7+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
8+
ARG NODE_VERSION="none"
9+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
10+
11+
# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
12+
# COPY requirements.txt /tmp/pip-tmp/
13+
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
14+
# && rm -rf /tmp/pip-tmp
15+
16+
# [Optional] Uncomment this section to install additional OS packages.
17+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18+
# && apt-get -y install --no-install-recommends <your-package-list-here>
19+
20+
# [Optional] Uncomment this line to install global node packages.
21+
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g ganache" 2>&1

.devcontainer/devcontainer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/python-3
3+
{
4+
"name": "Python 3",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
"context": "..",
8+
"args": {
9+
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
10+
// Append -bullseye or -buster to pin to an OS version.
11+
// Use -bullseye variants on local on arm64/Apple Silicon.
12+
"VARIANT": "3.8",
13+
// Options
14+
"NODE_VERSION": "10"
15+
}
16+
},
17+
18+
// Set *default* container specific settings.json values on container create.
19+
"settings": {
20+
"python.defaultInterpreterPath": "/usr/local/bin/python",
21+
"python.linting.enabled": true,
22+
"python.linting.pylintEnabled": true,
23+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
24+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
25+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
26+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
27+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
28+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
29+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
30+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
31+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
32+
},
33+
34+
// Add the IDs of extensions you want installed when the container is created.
35+
"extensions": [
36+
"ms-python.python",
37+
"ms-python.vscode-pylance",
38+
"streetsidesoftware.code-spell-checker",
39+
"esbenp.prettier-vscode",
40+
"juanblanco.solidity"
41+
],
42+
43+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
44+
// "forwardPorts": [],
45+
46+
// Use 'postCreateCommand' to run commands after the container is created.
47+
"postCreateCommand": "git config --global url.\"https://github.com/\".insteadOf git://github.com/",
48+
49+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
50+
"remoteUser": "vscode"
51+
}

.example.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
INFURA_API_KEY=""
2+
METAMASK_MNEMONIC=""
3+
ETHERSCAN_API_KEY=""

README.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,74 @@
11
# AkropolisToken
2-
Mintable, Burnable, Standard ERC20 with ability to upgrade to a more secure Pausable and Lockable ERC20
3-
2+
3+
Mintable, Burnable, Standard ERC20 with ability to upgrade to a more secure Pausable and Lockable ERC20
4+
5+
## Development
6+
7+
### Clone repository
8+
9+
clone using HTTPS:
10+
11+
```bash
12+
git clone https://github.com/akropolisio/AkropolisToken.git
13+
```
14+
15+
change directory:
16+
17+
```bash
18+
cd AkropolisToken
19+
```
20+
21+
### Setup environment
22+
23+
#### VSCode + Docker (recommended)
24+
25+
- install [Docker](https://docs.docker.com/get-docker/)
26+
- install [VSCode](https://code.visualstudio.com/)
27+
- install [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) VSCode extension
28+
- open cloned repository in VSCode
29+
- click F1 and run `>Remote-Containers: Reopen in Container`
30+
- wait until all dependencies are installed (you will see the message "Done. Press any key to close the terminal." in the terminal `Configuring`)
31+
- install local dependencies:
32+
```bash
33+
npm install
34+
```
35+
36+
#### Manual
37+
38+
- you will need Python 3.8 and Node.js v10
39+
- install Ganache:
40+
```bash
41+
npm install -g ganache
42+
```
43+
- install local dependencies:
44+
```bash
45+
npm install
46+
```
47+
48+
### Run tests
49+
50+
#### Default development network
51+
52+
- start Ganache in a separate terminal `ganache`
53+
- run all tests with `npm run test-all`
54+
55+
#### Mainnet Fork
56+
57+
- start Ganache in a separate terminal `scripts/rpc_fork.sh`
58+
- run all tests with `npm run test-fork`
59+
- Ganache will fork from Mainnet starting from a specific block number configured in `scripts/rpc_fork.sh`
60+
- make sure to restart Ganache before launching tests
61+
62+
### Deployment
63+
64+
- setup .env:
65+
- run `cp .example.env .env`
66+
- insert keys into `.env`
67+
- run truffle migrations:
68+
- deploy to development `npm run deploy` (make sure Ganache is running)
69+
- deploy to live networks `npm run deploy -- --network rinkeby`
70+
- to run all migrations from the beginning use `npm run deploy -- --network rinkeby --reset`
71+
472
MIT License
573

674
Copyright (c) 2019 A Labs Ltd.

contracts/token/AkropolisBaseToken.sol

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@ import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
77
import "../helpers/Ownable.sol";
88

99
/**
10-
* @title AkropolisBaseToken
11-
* @notice A basic ERC20 token with modular data storage
12-
*/
10+
* @title AkropolisBaseToken
11+
* @notice A basic ERC20 token with modular data storage
12+
*/
1313
contract AkropolisBaseToken is ERC20, TokenStorage, Ownable {
1414
using SafeMath for uint256;
1515

1616
/** Events */
1717
event Mint(address indexed to, uint256 value);
1818
event MintFinished();
19+
event MintStarted();
1920
event Burn(address indexed burner, uint256 value);
2021
event Transfer(address indexed from, address indexed to, uint256 value);
21-
event Approval(address indexed owner, address indexed spender, uint256 value);
22-
23-
24-
constructor (address _balances, address _allowances, string _name, uint8 _decimals, string _symbol) public
25-
TokenStorage(_balances, _allowances, _name, _decimals, _symbol) {}
22+
event Approval(
23+
address indexed owner,
24+
address indexed spender,
25+
uint256 value
26+
);
27+
28+
constructor(
29+
address _balances,
30+
address _allowances,
31+
string _name,
32+
uint8 _decimals,
33+
string _symbol
34+
) public TokenStorage(_balances, _allowances, _name, _decimals, _symbol) {}
2635

2736
/** Modifiers **/
2837

@@ -41,7 +50,6 @@ contract AkropolisBaseToken is ERC20, TokenStorage, Ownable {
4150
_burn(msg.sender, _amount);
4251
}
4352

44-
4553
function isMintingFinished() public view returns (bool) {
4654
bytes32 slot = keccak256(abi.encode("Minting", "mint"));
4755
uint256 v;
@@ -51,7 +59,6 @@ contract AkropolisBaseToken is ERC20, TokenStorage, Ownable {
5159
return v != 0;
5260
}
5361

54-
5562
function setMintingFinished(bool value) internal {
5663
bytes32 slot = keccak256(abi.encode("Minting", "mint"));
5764
uint256 v = value ? 1 : 0;
@@ -65,30 +72,42 @@ contract AkropolisBaseToken is ERC20, TokenStorage, Ownable {
6572
emit MintFinished();
6673
}
6774

75+
function mintStarted() public onlyOwner {
76+
setMintingFinished(false);
77+
emit MintStarted();
78+
}
6879

69-
function approve(address _spender, uint256 _value)
70-
public returns (bool) {
80+
function approve(address _spender, uint256 _value) public returns (bool) {
7181
allowances.setAllowance(msg.sender, _spender, _value);
7282
emit Approval(msg.sender, _spender, _value);
7383
return true;
7484
}
7585

7686
function transfer(address _to, uint256 _amount) public returns (bool) {
77-
require(_to != address(0),"to address cannot be 0x0");
78-
require(_amount <= balanceOf(msg.sender),"not enough balance to transfer");
87+
require(_to != address(0), "to address cannot be 0x0");
88+
require(
89+
_amount <= balanceOf(msg.sender),
90+
"not enough balance to transfer"
91+
);
7992

8093
balances.subBalance(msg.sender, _amount);
8194
balances.addBalance(_to, _amount);
8295
emit Transfer(msg.sender, _to, _amount);
8396
return true;
8497
}
8598

86-
function transferFrom(address _from, address _to, uint256 _amount)
87-
public returns (bool) {
88-
require(_amount <= allowance(_from, msg.sender),"not enough allowance to transfer");
89-
require(_to != address(0),"to address cannot be 0x0");
90-
require(_amount <= balanceOf(_from),"not enough balance to transfer");
91-
99+
function transferFrom(
100+
address _from,
101+
address _to,
102+
uint256 _amount
103+
) public returns (bool) {
104+
require(
105+
_amount <= allowance(_from, msg.sender),
106+
"not enough allowance to transfer"
107+
);
108+
require(_to != address(0), "to address cannot be 0x0");
109+
require(_amount <= balanceOf(_from), "not enough balance to transfer");
110+
92111
allowances.subAllowance(_from, msg.sender, _amount);
93112
balances.addBalance(_to, _amount);
94113
balances.subBalance(_from, _amount);
@@ -97,31 +116,34 @@ contract AkropolisBaseToken is ERC20, TokenStorage, Ownable {
97116
}
98117

99118
/**
100-
* @notice Implements balanceOf() as specified in the ERC20 standard.
101-
*/
119+
* @notice Implements balanceOf() as specified in the ERC20 standard.
120+
*/
102121
function balanceOf(address who) public view returns (uint256) {
103122
return balances.balanceOf(who);
104123
}
105124

106125
/**
107-
* @notice Implements allowance() as specified in the ERC20 standard.
108-
*/
109-
function allowance(address owner, address spender) public view returns (uint256) {
126+
* @notice Implements allowance() as specified in the ERC20 standard.
127+
*/
128+
function allowance(address owner, address spender)
129+
public
130+
view
131+
returns (uint256)
132+
{
110133
return allowances.allowanceOf(owner, spender);
111134
}
112135

113136
/**
114-
* @notice Implements totalSupply() as specified in the ERC20 standard.
115-
*/
137+
* @notice Implements totalSupply() as specified in the ERC20 standard.
138+
*/
116139
function totalSupply() public view returns (uint256) {
117140
return balances.totalSupply();
118141
}
119142

120-
121143
/** Internal functions **/
122144

123145
function _burn(address _tokensOf, uint256 _amount) internal {
124-
require(_amount <= balanceOf(_tokensOf),"not enough balance to burn");
146+
require(_amount <= balanceOf(_tokensOf), "not enough balance to burn");
125147
// no need to require value <= totalSupply, since that would imply the
126148
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
127149
balances.subBalance(_tokensOf, _amount);
@@ -136,5 +158,4 @@ contract AkropolisBaseToken is ERC20, TokenStorage, Ownable {
136158
emit Mint(_to, _amount);
137159
emit Transfer(address(0), _to, _amount);
138160
}
139-
140-
}
161+
}

migrations/2_deploy_token_logic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
var AkropolisToken = artifacts.require("./AkropolisToken.sol");
22

3-
module.exports = function(deployer, network, accounts) {
3+
module.exports = function (deployer, network, accounts) {
44
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
55
let owner = accounts[0];
66
console.log('owner of token contracts: ' + owner)
7-
deployer.deploy(AkropolisToken, ZERO_ADDRESS, ZERO_ADDRESS, "", 0, "", {from:owner});
7+
deployer.deploy(AkropolisToken, ZERO_ADDRESS, ZERO_ADDRESS, "", 0, "", { from: owner });
88
};

0 commit comments

Comments
 (0)