Skip to content

Commit

Permalink
Merge pull request #36 from AndrewDrury/master
Browse files Browse the repository at this point in the history
Adding original contract code for ethereum network
  • Loading branch information
twtaylorbitgo authored May 18, 2021
2 parents b0ffa83 + a883a2c commit 753c585
Show file tree
Hide file tree
Showing 41 changed files with 8,551 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ This repository has the contracts that implement the wrapped tokens.

# Tron network
[tron/README.md](tron/README.md)

# Original Ethereum network
[ethereum/README.md](ethereum/README.md)
9 changes: 9 additions & 0 deletions ethereum/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
norpc: false,
testCommand: '../node_modules/.bin/truffle test --network coverage',
compileCommand: '../node_modules/.bin/truffle compile',
skipFiles: [
'Migrations.sol',
'mocks'
]
}
24 changes: 24 additions & 0 deletions ethereum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This repository has the orginal contracts that implement the wrapped btc token.
The contracts in this repo are NOT deployed. You can find the deployed contracts
for the wrapped btc token on the Ethereum network in [ethereumV2/README.md](../ethereumV2/README.md).

# Installation

npm install

# Compilation

node_modules/.bin/truffle compile

# Testing

node_modules/.bin/truffle test

# Testing Coverage

node node_modules/.bin/solidity-coverage

# Deployment

node scripts/deployer.js --input-file [file] --gas-price-gwei [gwei] --rpc-url [url]

23 changes: 23 additions & 0 deletions ethereum/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.4.23;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
93 changes: 93 additions & 0 deletions ethereum/contracts/controller/Controller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
pragma solidity 0.4.24;

import "../utils/OwnableContract.sol";
import "../utils/OwnableContractOwner.sol";
import "../controller/ControllerInterface.sol";
import "../token/WBTC.sol";
import "../factory/MembersInterface.sol";


contract Controller is ControllerInterface, OwnableContract, OwnableContractOwner {

WBTC public token;
MembersInterface public members;
address public factory;

constructor(WBTC _token) public {
require(_token != address(0), "invalid _token address");
token = _token;
}

modifier onlyFactory() {
require(msg.sender == factory, "sender not authorized for minting or burning.");
_;
}

// setters
event MembersSet(MembersInterface indexed members);

function setMembers(MembersInterface _members) external onlyOwner returns (bool) {
require(_members != address(0), "invalid _members address");
members = _members;
emit MembersSet(members);
return true;
}

event FactorySet(address indexed factory);

function setFactory(address _factory) external onlyOwner returns (bool) {
require(_factory != address(0), "invalid _factory address");
factory = _factory;
emit FactorySet(factory);
return true;
}

// only owner actions on token
event Paused();

function pause() external onlyOwner returns (bool) {
token.pause();
emit Paused();
return true;
}

event Unpaused();

function unpause() external onlyOwner returns (bool) {
token.unpause();
emit Unpaused();
return true;
}

// only factory actions on token
function mint(address to, uint amount) external onlyFactory returns (bool) {
require(to != address(0), "invalid to address");
require(!token.paused(), "token is paused.");
require(token.mint(to, amount), "minting failed.");
return true;
}

function burn(uint value) external onlyFactory returns (bool) {
require(!token.paused(), "token is paused.");
token.burn(value);
return true;
}

// all accessible
function isCustodian(address addr) external view returns (bool) {
return members.isCustodian(addr);
}

function isMerchant(address addr) external view returns (bool) {
return members.isMerchant(addr);
}

function getWBTC() external view returns (ERC20) {
return token;
}

// overriding
function renounceOwnership() public onlyOwner {
revert("renouncing ownership is blocked.");
}
}
12 changes: 12 additions & 0 deletions ethereum/contracts/controller/ControllerInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";


interface ControllerInterface {
function mint(address to, uint amount) external returns (bool);
function burn(uint value) external returns (bool);
function isCustodian(address addr) external view returns (bool);
function isMerchant(address addr) external view returns (bool);
function getWBTC() external view returns (ERC20);
}
Loading

0 comments on commit 753c585

Please sign in to comment.