Compare commits

..

No commits in common. "master" and "feature/truffle+openzeppelin" have entirely different histories.

10 changed files with 3355 additions and 367 deletions

2
.gitignore vendored
View File

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

View File

@ -1,26 +0,0 @@
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

View File

@ -1,32 +0,0 @@
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 NEETSEC INTERNATIONAL INC. Copyright (C) 2018 David E. Perez Negron Rocha
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 NEETSEC INTERNATIONAL INC. DCC Copyright (C) 2018 David E. Perez Negron Rocha
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,185 +1,9 @@
Decentralized Carbon Credits ERC20 # DCC
===
![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
## Table of Contents # In order to run tests:
- npm i -g ganache-cli
[[_TOC_]] - edit last line at run-rpc.sh, fix to the correct path to your ganache-cli
- open shell and execute "./run-rpc.sh"
## DECA Project Tree - open second shell, and execute "truffle tests
```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,8 +22,6 @@ 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);
@ -85,14 +83,6 @@ 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;
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -153,15 +143,6 @@ 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 Normal file

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -84,64 +84,63 @@ 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})
describe('check pause', function () { wasErr = false;
it('should get/set pause', async function () { try {
let p = await this.deca.getPause.call(); let rs = await web3.eth.sendTransaction({
assert.equal(false, p, "pause should be disabled") from: this.creator.address,
await this.deca.setPause(true, {from: this.creator.address, gas: 6712390}) to: this.deca.address,
p = await this.deca.getPause.call(); value: 225,
assert.equal(true, p, "pause should be enabled") gas: 6712390
}) });
it('should fail on pay', async function () { } catch (err) {
await this.deca.setPause(true, {from: this.creator.address, gas: 6712390}) wasErr = true;
let wasErr = false; }
try { assert.equal(false, wasErr, "pause should work")
let rs = await web3.eth.sendTransaction({ })
from: this.creator.address, 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, to: this.deca.address,
value: 225, value: 1,
gas: 6712390 gas: 6712390
}); });
} catch (err) { let wasErr = false;
wasErr = true; try {
} await this.deca.setPause(true, {from: sender.address, gas: 6712390})
await this.deca.setPause(false, {from: this.creator.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")
})
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 () {
@ -200,55 +199,46 @@ 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({
var sender = await getHighBalance(); // from: this.creator.address,
await web3.eth.sendTransaction({ // gas: 6712390
from: sender.address, // })
to: this.deca.address, //
value: 1, // var sender = await getHighBalance();
gas: 6712390 // await web3.eth.sendTransaction({
}); // from: sender.address,
let decaBalance = await this.deca.balanceOf.call(this.deca.address) // to: this.deca2.address,
await this.deca.transfer(this.deca.address, 10, {from: sender.address, gas: 6712390}) // value: 1,
decaBalance = await this.deca.balanceOf.call(this.deca.address) // gas: 6712390
assert.equal(decaBalance.toString(10), '10', " contract should have balance") // });
// let deca2Balance = await this.deca2.balanceOf.call(sender.address)
let wasErr = false; // console.log('DECA2 BALANCE : ', deca2Balance.toString(10))
try { //
let ok = await this.deca.transferAnyERC20Token(this.deca.address, 10, { // assert.equal(deca2Balance.toString(10), '300', " sender should have balance")
from: this.creator.address, //
gas: 6712390 // let wasErr = false;
}) // try {
assert.equal(true, ok, "transferAnyERC20Token should return positive result") // let ok = await this.deca.transferAnyERC20Token(this.deca2.address, 1, {
} catch (err) { // from: this.creator.address,
console.dir(err) // gas: 6712390
wasErr = true; // })
} // assert.equal(true, ok, "transferAnyERC20Token should return positive result")
// } catch (err) {
assert.equal(true, wasErr, "transferAnyERC20Token should proces without error") // console.dir(err)
}) // wasErr = true;
}) // }
// SOMEHOW THIS FUNCTIONS TEST WORKED IN ROPSTEN // deca2Balance = await this.deca2.balanceOf.call(sender.address)
//
// assert.equal(deca2Balance.toString(10), '0', " sender should have 0 on balance")
// })
// })
// describe('check payout', async function () { // describe('check payout', async function () {
// it.only('check getETH', async function () { // it('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();
@ -277,4 +267,5 @@ contract('DECA', function (accs) {
// //
// }) // })
// }) // })
}) })

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 KiB