Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
upgrade contracts to sol 0.5; use openzeppelin as base erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
clbrge committed Nov 5, 2019
1 parent fa770d8 commit cb5fad1
Show file tree
Hide file tree
Showing 33 changed files with 5,635 additions and 6,119 deletions.
58 changes: 22 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,36 @@
# The Rouge Project - beta code factory and campaign contracts to be used with the RGE token
# The Rouge Project - factory and campaign contracts

WARNING: The Rouge token [RGE] has been audited but not yet the factory. So, please do your own due diligences if you
decide to use this code on a production network (Ethereum mainnet, POA, etc). You may lose your RGE deposit, ETH, POA
and/or any ERC20, ERC721 tokens sent as attachment to a campaign.
> solidity contracts used by the Rouge protocol
WARNING : this is NON AUDITED code. Use on testnet or with extreme caution.
The Rouge protocol is an open-source blockchain voucher and note
protocol built as a suite of smart contracts using a specific token —
the Rouge token — on Ethereum compatible blockchains (tested on
Ethereum and POA).

The project use the truffle framework (http://truffleframework.com/)
Rouge is for all types of usage of non-repudiable and unique usage
digital vouchers (for example, e-tickets, e-coupons, cashback notes,
etc).

## Versioning
This package includes low-level implementation of the protocol
in solidity.

The project follows Semantic Versioning 2.0.0 : see https://semver.org/
The Javascript [rouge.js](https://github.com/TheRougeProject/rouge.js)
library, is a far simpler and recomended method to use the protocol
than using these contracts directly.

## How to run tests :

### 1. install truffle :
Please check out the [Rouge protocol docs](https://rouge.network/docs/).

```
npm install -g truffle
```
### 2. launch the tests
## How to run tests :

``` bash
cd rouge-protocol-solidity
npm install
npm run test
```
truffle test
```

## Creating a campaign :

1. You should have a minimum of RGE tokens on the Ethereum address creating the campaign (issuer) :

mim RGE = number of notes to be issued * tare price.

The tare price is now set to be 0.1 RGE (as per the white paper, tare will be raised to 1 RGE as usage of
the network grow).

2. Call the function newCampaign(issuance, deposit)

issuance = number of notes to be created/issued

deposit = RGE that you move to the campaign as deposit (should equal or more than mim RGE)

3. Read the introduction on medium :

https://medium.com/the-rouge-project/getting-started-with-the-rouge-protocol-9a335079e69e
## Introduction on the low level implementation of the protocol

4. Enjoy :)
https://medium.com/the-rouge-project/getting-started-with-the-rouge-protocol-9a335079e69e


### Licensed under GNU AFFERO GENERAL PUBLIC LICENSE v3
Expand Down
44 changes: 21 additions & 23 deletions contracts/BridgeRGEToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
*/

pragma solidity ^0.4.24;
pragma solidity >=0.5.0 <0.7.0;

import "./EIP20.sol";
import "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract BridgeRGEToken is EIP20 {
contract BridgeRGEToken is ERC20 {

/* ERC20 */
uint8 public decimals = 6;

/* RGEToken - keeping the bridged RGE interface as similar as the home RGE */
address owner;
string public version = 'v1.0-0.4'; /* composition rge version + bridge version */
uint256 public totalSupply = 1000000000 * 10**uint(decimals);
uint256 public reserveY1 = 0;
uint256 public reserveY2 = 0;

uint256 public mintable;

modifier onlyBy(address _address) {
require(msg.sender == _address);
_;
Expand All @@ -33,14 +34,17 @@ contract BridgeRGEToken is EIP20 {
address public homeBridge;
address public homeValidator; /* validator in the RougeBridge contract on the home RGE network */

constructor(uint _network, address _validator, address _homeBridge, address _homeValidator, string _name, string _symbol)
EIP20 (totalSupply, _name, decimals, _symbol) public {
string public name;
string public symbol;

constructor(uint _network, address _validator, address _homeBridge, address _homeValidator, string memory _name, string memory _symbol) public {
owner = msg.sender;
network = _network;
validator = _validator;
homeBridge = _homeBridge;
homeValidator = _homeValidator;
balances[address(0)] = totalSupply; /* RGE on address(0) means there are not circulating on this foreign chain */
name = _name;
symbol = _symbol;
}

function newOwner(address _account) onlyBy(owner) public {
Expand Down Expand Up @@ -75,17 +79,14 @@ contract BridgeRGEToken is EIP20 {
uint8 vLock, bytes32 rLock, bytes32 sLock, uint8 vAuth, bytes32 rAuth, bytes32 sAuth)
BridgeOpen public returns (bool success) {
require(msg.sender != homeValidator);
require(balances[address(0)] >= _value);
require(!claimed[msg.sender][_depositBlock]); // check if the deposit has not been already claimed
bytes32 _lockHash = keccak256(abi.encodePacked(msg.sender, _value, network, homeBridge, _depositBlock));
require(ecrecover(prefixed(_lockHash), vLock, rLock, sLock) == validator);
require(_sealHash == keccak256(abi.encodePacked(_lockHash, vLock, rLock, sLock, _lockBlock)));
require(ecrecover(prefixed(_sealHash), vAuth, rAuth, sAuth) == homeValidator);
claimed[msg.sender][_depositBlock] = true; // distribute the claim
balances[address(0)] -= _value;
balances[msg.sender] += _value;
_mint(msg.sender, _value);
emit RGEClaim(msg.sender, network, _depositBlock, _value);
emit Transfer(address(0), msg.sender, _value);
return true;
}

Expand All @@ -97,22 +98,20 @@ contract BridgeRGEToken is EIP20 {
require(!surrendered[msg.sender][_depositBlock]); // not surrendered already
bytes32 _lockHash = keccak256(abi.encodePacked(msg.sender, _value, network, homeBridge, _depositBlock));
require(ecrecover(prefixed(_lockHash), vLock, rLock, sLock) == validator);
require(balances[msg.sender] >= _value);
require(balanceOf(msg.sender) >= _value);
surrendered[msg.sender][_depositBlock] = true; // withdraw tokens from circulation
balances[msg.sender] -= _value;
balances[address(0)] += _value;
emit Transfer(msg.sender, address(0), _value);
_burn(msg.sender, _value);
emit Surrender(msg.sender, network, _depositBlock, _value);
return true;
}

function getHexString(bytes32 value) internal pure returns (string) {
function getHexString(bytes32 value) internal pure returns (string memory) {
bytes memory result = new bytes(64);
string memory characterString = "0123456789abcdef";
bytes memory characters = bytes(characterString);
for (uint8 i = 0; i < 32; i++) {
result[i * 2] = characters[uint256((value[i] & 0xF0) >> 4)];
result[i * 2 + 1] = characters[uint256(value[i] & 0xF)];
result[i * 2] = characters[(uint8(value[i]) & 0xF0) >> 4];
result[i * 2 + 1] = characters[uint8(value[i]) & 0xF];
}
return string(result);
}
Expand Down Expand Up @@ -144,17 +143,16 @@ contract BridgeRGEToken is EIP20 {

function newCampaign(uint32 _issuance, uint256 _value) public {
transfer(factory,_value);
require(factory.call(bytes4(keccak256("createCampaign(address,uint32,uint256)")),msg.sender,_issuance,_value));
(bool success,) = factory.call(abi.encodeWithSignature("createCampaign(address,uint32,uint256)",msg.sender,_issuance,_value));
require(success);
}

event Burn(address indexed burner, uint256 value);

function burn(uint256 _value) public returns (bool success) {
require(_value > 0);
require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value;
totalSupply -= _value;
emit Transfer(msg.sender, address(0), _value);
require(balanceOf(msg.sender) >= _value);
_burn(msg.sender, _value);
emit Burn(msg.sender, _value);
return true;
}
Expand Down
71 changes: 0 additions & 71 deletions contracts/EIP20.sol

This file was deleted.

49 changes: 0 additions & 49 deletions contracts/EIP20Interface.sol

This file was deleted.

Loading

0 comments on commit cb5fad1

Please sign in to comment.