Compare commits

..

11 Commits

Author SHA1 Message Date
David E. Perez Negron Rocha bcf24dfb70 Merge branch 'hotfix/Fix_Integer_Overflow/Underflow' 2020-06-19 18:57:35 -05:00
David E. Perez Negron Rocha 0b45255267 Fix Integer Overflow / Underflow 2020-06-19 18:57:01 -05:00
David E. Perez Negron Rocha efc8046b2b Merge branch 'hotfix/extendableICO' 2020-06-08 14:42:49 -05:00
David E. Perez Negron Rocha 83414e1780 Tested and Audited appendWeeks function 2020-06-08 14:39:52 -05:00
David E. Perez Negron Rocha 618de6cb61 Adding DISCLAIMERS 2020-06-04 22:52:59 -05:00
David E. Perez Negron Rocha d97f7cd426 adding appendWeeks function 2020-05-26 18:28:58 -05:00
David E. Perez Negron Rocha 3d723163e8 Merge branch 'release/1.2.0' 2020-05-09 22:49:52 -05:00
David E. Perez Negron Rocha ced2d42dc3 update version 2020-05-09 22:47:36 -05:00
David E. Perez Negron Rocha 628cf32976 Update CI build at README.md 2020-05-08 20:32:16 -05:00
David E. Perez Negron Rocha 22c466bf17 Updates Ready for Master, NOTE: includes the integration of the previously audited function updateCCDBAddress 2020-05-08 20:20:18 -05:00
David E. Perez Negron Rocha ec7e25a456 Update transferAnyERC20 function test 2020-02-27 18:53:03 -06:00
10 changed files with 367 additions and 3355 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
package-lock.json
/node_modules

26
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,26 @@
image: node:12.16.3
before_script:
- npm install -g ganache-cli
- npm install -g truffle@5.1.3
- npm i @openzeppelin/contracts@2.4.0
stages:
- build
- test
build:
stage: build
script:
- truffle compile
tags:
- docker
test:
stage: test
script:
- ./run-rpc.sh &
- truffle test
tags:
- docker

32
DISCLAIMERS Normal file
View File

@ -0,0 +1,32 @@
Disclaimers for DECA offering:
General Disclaimer:
This Offering may be subject to securities regulations in your country of
residence. As such, you may wish to consult with your investment advisor.
The complete explanation of the DECA project and the merits of the investment
in DECA are outlined in the White Paper and other supporting documents.
These are available for review on the DECA website (https://deca.eco).
Further Disclaimer if investor is located in North America:
This Offering may be subject to securities regulations in your country of
residence. As such, you may wish to consult with your investment advisor.
The complete explanation of the DECA project and the merits of the investment
in DECA are outlined in the White Paper and other supporting documents.
These are available for review on the DECA website (https://deca.eco).
Investors who are located in North America may qualify for investment under an
“accredited investor” exemption. While this exemption may vary by jurisdiction,
the general criteria is outlined as follows:
“Accredited Investor”, means a purchaser that:
 
(a) Has, in each of the past two years, had gross income before taxes of
$200,000 (or $300,000 with a spouse) and has a reasonable expectation of
achieving such income in the current year;
 
(b) Has financial assets of $1,000,000 (either alone or with a spouse), where
financial assets means cash and securities; or
 
(c) Has net assets of $5,000,000 (either alone or with a spouse).

View File

@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found. the "copyright" line and a pointer to where the full notice is found.
DCC DCC
Copyright (C) 2018 David E. Perez Negron Rocha Copyright (C) 2018 NEETSEC INTERNATIONAL INC.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode: notice like this when it starts in an interactive mode:
DCC Copyright (C) 2018 David E. Perez Negron Rocha DCC Copyright (C) 2018 NEETSEC INTERNATIONAL INC.
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details. under certain conditions; type `show c' for details.

190
README.md
View File

@ -1,9 +1,185 @@
# DCC Decentralized Carbon Credits ERC20
===
![build](https://gitlab.com/deca-currency/dcc/badges/develop/pipeline.svg)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/deca-currency/community)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
Decentralized Carbon Credits in an ERC20 by neetsec Decentralized Carbon Credits in an ERC20 by Neetsec
# In order to run tests: ## Table of Contents
- npm i -g ganache-cli
- edit last line at run-rpc.sh, fix to the correct path to your ganache-cli [[_TOC_]]
- open shell and execute "./run-rpc.sh"
- open second shell, and execute "truffle tests ## DECA Project Tree
```sh
|-- LICENSE
|-- README.md
|-- contracts
|-- build
| |-- contracts
| |-- Context.json
| |-- DECA.json
| |-- ERC20.json
| |-- IERC20.json
| |-- Migrations.json
| |-- Ownable.json
| `-- SafeMath.json
| |-- DECA.sol
| `-- Migrations.sol
|-- migrations
| |-- 1_initial_migration.js
| `-- 2_deploy_contracts.js
|-- package.json
|-- run-rpc.sh
|-- test
| `-- DECA.js
|-- truffle.js
|-- .gitignore
|-- .gitlab-ci.yml
```
## Requirements
* Node.js >= 12
* @openzeppelin/contracts = 2.4.0
#### Global install
* ganache-cli >= 6.9.1
* truffle = 5.1.3
## Instalation
**Download and install Node.js v12.x and npm.**
* Node.js
**Using Ubuntu**
```sh
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt-get install -y nodejs
```
**Using Debian, as root**
```sh
$ curl -sL https://deb.nodesource.com/setup_12.x | bash -
$ apt-get install -y nodejs
```
**Clone the repo**
```sh
$ git clone https://gitlab.com/deca-currency/dcc.git
$ cd dcc
```
**Install the dependencies**
```sh
$ npm install
```
**Install ganache-cli**
```sh
$ sudo npm install -g ganache-cli
```
**Install truffle**
```sh
$ sudo npm install -g truffle@5.1.3
```
## Testing the Smart Contract:
- can see the test in pipelines or you can run it locally
#### Running locally
- open shell and execute "./run-rpc.sh" (remember change /usr/local/bin/ganache-cli to your path)
```sh
$ ./run-rpc.sh
```
- open second shell, and execute
```sh
$ truffle tests
```
## Class Diagram ERC20 Token generated with [sol2uml](https://github.com/naddison36/sol2uml)
<p align="center">
<img src="uml/diagram.png" width="720" />
</p>
## Specification
### Methods
Apart from the [ERC20 standard](https://eips.ethereum.org/EIPS/eip-20) methods that our token complies, we introduce some
improvements, either for security or others that match DECA specific requirements.
**Notes:**
* The following specifications use syntax from Solidity (0.5.12)
#### owner
Returns the address of the current owner.
```sh
function owner() public view returns (address payable)
```
#### isOwner
Returns true if the caller is the current owner.
```sh
function isOwner() public view returns (bool)
```
#### transferOwnership
Can only be called by the current owner.
```sh
function transferOwnership(address payable newOwner) public onlyOwner
```
#### updateCCDBAddress
Updates the official orbitDB address for carbon credits.
Can Only be updated by the current owner
```sh
function updateCCDBAddress(string memory newCCDBAddress) public onlyOwner
```
#### transferAnyERC20Token
Owner can transfer out any accidentally sent ERC20 tokens
```sh
function transferAnyERC20Token(address payable tokenAddress, uint tokens) public onlyOwner returns (bool success)
```
#### getETH
Close down the ICO and claim the Ether.
```sh
function getETH() public onlyOwner { require(now >= endDate); owner().transfer(address(this).balance); }
```
## DECA Promotion Dates
Now, based on the total Ethereums we got by the ICO (ETHTS)
and considering our promodates which are:
| PROMO | TIME (weeks) | DECA TOKENS PER ETH |
|--------|--------------|---------------------|
| preICO | 1 | 300 |
| Bonus1 | 2 | 275 |
| Bonus2 | 3 | 250 |
| ICO | 5 | 225 |

View File

@ -22,6 +22,8 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
contract Ownable is Context { contract Ownable is Context {
address payable private _owner; address payable private _owner;
using SafeMath for uint256; using SafeMath for uint256;
string public _CCDBAddress;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
@ -83,6 +85,14 @@ contract Ownable is Context {
emit OwnershipTransferred(_owner, newOwner); emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner; _owner = newOwner;
} }
/**
*Function that updates the official orbitDB address for carbon credits.
*Can Only be updated by the current owner
*/
function updateCCDBAddress(string memory newCCDBAddress) public onlyOwner {
_CCDBAddress = newCCDBAddress;
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -143,6 +153,15 @@ contract DECA is ERC20, Ownable {
_mint(msg.sender, toSender); _mint(msg.sender, toSender);
} }
//Add weeks in case ICO gets not enough funds
function appendWeeks(uint addWeeks ) public onlyOwner {
require(now >= bonus2Ends && now < endDate);
// Fix Integer Overflow / Underflow
require(endDate < (endDate + (addWeeks * 1 weeks)));
// add weeks to the endDate
endDate += (addWeeks * 1 weeks);
}
//Close down the ICO and claim the Ether. //Close down the ICO and claim the Ether.
function getETH() public onlyOwner { function getETH() public onlyOwner {
require(now >= endDate); require(now >= endDate);

3253
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "carbon-token", "name": "carbon-token",
"version": "1.0.0", "version": "1.2.0",
"description": "", "description": "",
"main": "truffle-config.js", "main": "truffle-config.js",
"directories": { "directories": {
@ -13,10 +13,11 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"openzeppelin-solidity": "2.4.0", "@openzeppelin/contracts": "^2.4.0",
"solc": "^0.6.0" "truffle": "^5.1.3"
}, },
"devDependencies": { "devDependencies": {
"web3": "^1.2.4" "web3": "^1.2.4"
} }
} }

View File

@ -84,63 +84,64 @@ contract('DECA', function (accs) {
}) })
}), }),
describe('check pause', function () {
it('should get/set pause', async function () {
let p = await this.deca.getPause.call();
assert.equal(false, p, "pause should be disabled")
await this.deca.setPause(true, {from: this.creator.address, gas: 6712390})
p = await this.deca.getPause.call();
assert.equal(true, p, "pause should be enabled")
})
it('should fail on pay', async function () {
await this.deca.setPause(true, {from: this.creator.address, gas: 6712390})
let wasErr = false;
try {
let rs = await web3.eth.sendTransaction({
from: this.creator.address,
to: this.deca.address,
value: 225,
gas: 6712390
});
} catch (err) {
wasErr = true;
}
await this.deca.setPause(false, {from: this.creator.address, gas: 6712390})
wasErr = false; describe('check pause', function () {
try { it('should get/set pause', async function () {
let rs = await web3.eth.sendTransaction({ let p = await this.deca.getPause.call();
from: this.creator.address, assert.equal(false, p, "pause should be disabled")
to: this.deca.address, await this.deca.setPause(true, {from: this.creator.address, gas: 6712390})
value: 225, p = await this.deca.getPause.call();
gas: 6712390 assert.equal(true, p, "pause should be enabled")
}); })
} catch (err) { it('should fail on pay', async function () {
wasErr = true; await this.deca.setPause(true, {from: this.creator.address, gas: 6712390})
} let wasErr = false;
assert.equal(false, wasErr, "pause should work") try {
}) let rs = await web3.eth.sendTransaction({
it('check intruder pause', async function () { from: this.creator.address,
var sender = await getHighBalance();
await increaseTime(duration.days(1))
await web3.eth.sendTransaction({
from: sender.address,
to: this.deca.address, to: this.deca.address,
value: 1, value: 225,
gas: 6712390 gas: 6712390
}); });
let wasErr = false; } catch (err) {
try { wasErr = true;
await this.deca.setPause(true, {from: sender.address, gas: 6712390}) }
} catch (err) { await this.deca.setPause(false, {from: this.creator.address, gas: 6712390})
wasErr = true;
}
assert.equal(true, wasErr, "only owner could pause")
let own = await this.deca.owner();
assert.equal(this.creator.address, own, "owner does not match")
})
wasErr = false;
try {
let rs = await web3.eth.sendTransaction({
from: this.creator.address,
to: this.deca.address,
value: 225,
gas: 6712390
});
} catch (err) {
wasErr = true;
}
assert.equal(false, wasErr, "pause should work")
}) })
it('check intruder pause', async function () {
var sender = await getHighBalance();
await increaseTime(duration.days(1))
await web3.eth.sendTransaction({
from: sender.address,
to: this.deca.address,
value: 1,
gas: 6712390
});
let wasErr = false;
try {
await this.deca.setPause(true, {from: sender.address, gas: 6712390})
} catch (err) {
wasErr = true;
}
assert.equal(true, wasErr, "only owner could pause")
let own = await this.deca.owner();
assert.equal(this.creator.address, own, "owner does not match")
})
})
describe('check crowdsale dates', function () { describe('check crowdsale dates', function () {
it('check preICOEnds', async function () { it('check preICOEnds', async function () {
@ -199,46 +200,55 @@ contract('DECA', function (accs) {
assert.equal(true, wasErr, "crowdsale should be stopped") assert.equal(true, wasErr, "crowdsale should be stopped")
}) })
it('check appendWeeks', async function () {
await increaseTime(duration.weeks(10))
// get endDate before
let endDateBefore = await this.deca.endDate.call();
// add one week
await this.deca.appendWeeks(1, {
from: this.creator.address,
gas: 6712390
});
// get endDate after
let endDateAfter = await this.deca.endDate.call();
// 1 week = 604800 seconds
assert.equal(604800, endDateAfter - endDateBefore, "appendWeeks does not work");
})
}) })
// SOMEHOW THIS FUNCTIONS TEST WORKED IN ROPSTEN
// describe('transferAnyERC20Token', async function () { describe('transferAnyERC20Token', async function () {
// it('check transfer from external', async function () { it('check transfer from external', async function () {
// this.deca2 = await DECA.new({
// from: this.creator.address, var sender = await getHighBalance();
// gas: 6712390 await web3.eth.sendTransaction({
// }) from: sender.address,
// to: this.deca.address,
// var sender = await getHighBalance(); value: 1,
// await web3.eth.sendTransaction({ gas: 6712390
// from: sender.address, });
// to: this.deca2.address, let decaBalance = await this.deca.balanceOf.call(this.deca.address)
// value: 1, await this.deca.transfer(this.deca.address, 10, {from: sender.address, gas: 6712390})
// gas: 6712390 decaBalance = await this.deca.balanceOf.call(this.deca.address)
// }); assert.equal(decaBalance.toString(10), '10', " contract should have balance")
// let deca2Balance = await this.deca2.balanceOf.call(sender.address)
// console.log('DECA2 BALANCE : ', deca2Balance.toString(10)) let wasErr = false;
// try {
// assert.equal(deca2Balance.toString(10), '300', " sender should have balance") let ok = await this.deca.transferAnyERC20Token(this.deca.address, 10, {
// from: this.creator.address,
// let wasErr = false; gas: 6712390
// try { })
// let ok = await this.deca.transferAnyERC20Token(this.deca2.address, 1, { assert.equal(true, ok, "transferAnyERC20Token should return positive result")
// from: this.creator.address, } catch (err) {
// gas: 6712390 console.dir(err)
// }) wasErr = true;
// assert.equal(true, ok, "transferAnyERC20Token should return positive result") }
// } catch (err) {
// console.dir(err) assert.equal(true, wasErr, "transferAnyERC20Token should proces without error")
// wasErr = true; })
// } })
// deca2Balance = await this.deca2.balanceOf.call(sender.address) // SOMEHOW THIS FUNCTIONS TEST WORKED IN ROPSTEN
//
// assert.equal(deca2Balance.toString(10), '0', " sender should have 0 on balance")
// })
// })
// describe('check payout', async function () { // describe('check payout', async function () {
// it('check getETH', async function () { // it.only('check getETH', async function () {
// let decaBalance = await web3.eth.getBalance(this.deca.address); // let decaBalance = await web3.eth.getBalance(this.deca.address);
// assert.equal(decaBalance.toString(10), '0', " wrong contract balance") // assert.equal(decaBalance.toString(10), '0', " wrong contract balance")
// var sender = await getHighBalance(); // var sender = await getHighBalance();
@ -267,5 +277,4 @@ contract('DECA', function (accs) {
// //
// }) // })
// }) // })
}) })

BIN
uml/diagram.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB