Skip to content

Commit

Permalink
Merge pull request #6 from marktoda/addWxrp
Browse files Browse the repository at this point in the history
Add WXRP Token
  • Loading branch information
barathcj authored Nov 26, 2019
2 parents b1395c6 + d8694d8 commit 74368f0
Show file tree
Hide file tree
Showing 14 changed files with 1,653 additions and 1,490 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
.idea
node_modules
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ This repository has the contracts that implement the wrapped btc token.

# Compilation

node_modules/.bin/truffle compile
npm run compile

# Testing

node_modules/.bin/truffle test
npm test

# Testing Coverage

node node_modules/.bin/solidity-coverage
npm run coverage

# Deployment

Expand Down
10 changes: 5 additions & 5 deletions contracts/controller/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ pragma solidity 0.4.24;

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


contract Controller is ControllerInterface, OwnableContract, OwnableContractOwner {

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

constructor(WBTC _token) public {
constructor(WrappedToken _token) public {
require(_token != address(0), "invalid _token address");
token = _token;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ contract Controller is ControllerInterface, OwnableContract, OwnableContractOwne
return members.isMerchant(addr);
}

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

Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/ControllerInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ interface ControllerInterface {
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);
function getToken() external view returns (ERC20);
}
116 changes: 58 additions & 58 deletions contracts/factory/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ contract Factory is OwnableContract {

struct Request {
address requester; // sender of the request.
uint amount; // amount of wbtc to mint/burn.
string btcDepositAddress; // custodian's btc address in mint, merchant's btc address in burn.
string btcTxid; // bitcoin txid for sending/redeeming btc in the mint/burn process.
uint amount; // amount of token to mint/burn.
string depositAddress; // custodian's asset address in mint, merchant's asset address in burn.
string txid; // asset txid for sending/redeeming asset in the mint/burn process.
uint nonce; // serial number allocated for each request.
uint timestamp; // time of the request creation.
RequestStatus status; // status of the request.
Expand All @@ -22,10 +22,10 @@ contract Factory is OwnableContract {

// mapping between merchant to the corresponding custodian deposit address, used in the minting process.
// by using a different deposit address per merchant the custodian can identify which merchant deposited.
mapping(address=>string) public custodianBtcDepositAddress;
mapping(address=>string) public custodianDepositAddress;

// mapping between merchant to the its deposit address where btc should be moved to, used in the burning process.
mapping(address=>string) public merchantBtcDepositAddress;
// mapping between merchant to the its deposit address where the asset should be moved to, used in the burning process.
mapping(address=>string) public merchantDepositAddress;

// mapping between a mint request hash and the corresponding request nonce.
mapping(bytes32=>uint) public mintRequestNonce;
Expand All @@ -52,65 +52,65 @@ contract Factory is OwnableContract {
_;
}

event CustodianBtcDepositAddressSet(address indexed merchant, address indexed sender, string btcDepositAddress);
event CustodianDepositAddressSet(address indexed merchant, address indexed sender, string depositAddress);

function setCustodianBtcDepositAddress(
function setCustodianDepositAddress(
address merchant,
string btcDepositAddress
string depositAddress
)
external
onlyCustodian
returns (bool)
{
require(merchant != 0, "invalid merchant address");
require(controller.isMerchant(merchant), "merchant address is not a real merchant.");
require(!isEmptyString(btcDepositAddress), "invalid btc deposit address");
require(!isEmptyString(depositAddress), "invalid asset deposit address");

custodianBtcDepositAddress[merchant] = btcDepositAddress;
emit CustodianBtcDepositAddressSet(merchant, msg.sender, btcDepositAddress);
custodianDepositAddress[merchant] = depositAddress;
emit CustodianDepositAddressSet(merchant, msg.sender, depositAddress);
return true;
}

event MerchantBtcDepositAddressSet(address indexed merchant, string btcDepositAddress);
event MerchantDepositAddressSet(address indexed merchant, string depositAddress);

function setMerchantBtcDepositAddress(string btcDepositAddress) external onlyMerchant returns (bool) {
require(!isEmptyString(btcDepositAddress), "invalid btc deposit address");
function setMerchantDepositAddress(string depositAddress) external onlyMerchant returns (bool) {
require(!isEmptyString(depositAddress), "invalid asset deposit address");

merchantBtcDepositAddress[msg.sender] = btcDepositAddress;
emit MerchantBtcDepositAddressSet(msg.sender, btcDepositAddress);
merchantDepositAddress[msg.sender] = depositAddress;
emit MerchantDepositAddressSet(msg.sender, depositAddress);
return true;
}

event MintRequestAdd(
uint indexed nonce,
address indexed requester,
uint amount,
string btcDepositAddress,
string btcTxid,
string depositAddress,
string txid,
uint timestamp,
bytes32 requestHash
);

function addMintRequest(
uint amount,
string btcTxid,
string btcDepositAddress
string txid,
string depositAddress
)
external
onlyMerchant
returns (bool)
{
require(!isEmptyString(btcDepositAddress), "invalid btc deposit address");
require(compareStrings(btcDepositAddress, custodianBtcDepositAddress[msg.sender]), "wrong btc deposit address");
require(!isEmptyString(depositAddress), "invalid asset deposit address");
require(compareStrings(depositAddress, custodianDepositAddress[msg.sender]), "wrong asset deposit address");

uint nonce = mintRequests.length;
uint timestamp = getTimestamp();

Request memory request = Request({
requester: msg.sender,
amount: amount,
btcDepositAddress: btcDepositAddress,
btcTxid: btcTxid,
depositAddress: depositAddress,
txid: txid,
nonce: nonce,
timestamp: timestamp,
status: RequestStatus.PENDING
Expand All @@ -120,7 +120,7 @@ contract Factory is OwnableContract {
mintRequestNonce[requestHash] = nonce;
mintRequests.push(request);

emit MintRequestAdd(nonce, msg.sender, amount, btcDepositAddress, btcTxid, timestamp, requestHash);
emit MintRequestAdd(nonce, msg.sender, amount, depositAddress, txid, timestamp, requestHash);
return true;
}

Expand All @@ -143,8 +143,8 @@ contract Factory is OwnableContract {
uint indexed nonce,
address indexed requester,
uint amount,
string btcDepositAddress,
string btcTxid,
string depositAddress,
string txid,
uint timestamp,
bytes32 requestHash
);
Expand All @@ -162,8 +162,8 @@ contract Factory is OwnableContract {
request.nonce,
request.requester,
request.amount,
request.btcDepositAddress,
request.btcTxid,
request.depositAddress,
request.txid,
request.timestamp,
requestHash
);
Expand All @@ -174,8 +174,8 @@ contract Factory is OwnableContract {
uint indexed nonce,
address indexed requester,
uint amount,
string btcDepositAddress,
string btcTxid,
string depositAddress,
string txid,
uint timestamp,
bytes32 requestHash
);
Expand All @@ -192,8 +192,8 @@ contract Factory is OwnableContract {
request.nonce,
request.requester,
request.amount,
request.btcDepositAddress,
request.btcTxid,
request.depositAddress,
request.txid,
request.timestamp,
requestHash
);
Expand All @@ -204,26 +204,26 @@ contract Factory is OwnableContract {
uint indexed nonce,
address indexed requester,
uint amount,
string btcDepositAddress,
string depositAddress,
uint timestamp,
bytes32 requestHash
);

function burn(uint amount) external onlyMerchant returns (bool) {
string memory btcDepositAddress = merchantBtcDepositAddress[msg.sender];
require(!isEmptyString(btcDepositAddress), "merchant btc deposit address was not set");
string memory depositAddress = merchantDepositAddress[msg.sender];
require(!isEmptyString(depositAddress), "merchant asset deposit address was not set");

uint nonce = burnRequests.length;
uint timestamp = getTimestamp();

// set txid as empty since it is not known yet.
string memory btcTxid = "";
string memory txid = "";

Request memory request = Request({
requester: msg.sender,
amount: amount,
btcDepositAddress: btcDepositAddress,
btcTxid: btcTxid,
depositAddress: depositAddress,
txid: txid,
nonce: nonce,
timestamp: timestamp,
status: RequestStatus.PENDING
Expand All @@ -233,39 +233,39 @@ contract Factory is OwnableContract {
burnRequestNonce[requestHash] = nonce;
burnRequests.push(request);

require(controller.getWBTC().transferFrom(msg.sender, controller, amount), "trasnfer tokens to burn failed");
require(controller.getToken().transferFrom(msg.sender, controller, amount), "transfer tokens to burn failed");
require(controller.burn(amount), "burn failed");

emit Burned(nonce, msg.sender, amount, btcDepositAddress, timestamp, requestHash);
emit Burned(nonce, msg.sender, amount, depositAddress, timestamp, requestHash);
return true;
}

event BurnConfirmed(
uint indexed nonce,
address indexed requester,
uint amount,
string btcDepositAddress,
string btcTxid,
string depositAddress,
string txid,
uint timestamp,
bytes32 inputRequestHash
);

function confirmBurnRequest(bytes32 requestHash, string btcTxid) external onlyCustodian returns (bool) {
function confirmBurnRequest(bytes32 requestHash, string txid) external onlyCustodian returns (bool) {
uint nonce;
Request memory request;

(nonce, request) = getPendingBurnRequest(requestHash);

burnRequests[nonce].btcTxid = btcTxid;
burnRequests[nonce].txid = txid;
burnRequests[nonce].status = RequestStatus.APPROVED;
burnRequestNonce[calcRequestHash(burnRequests[nonce])] = nonce;

emit BurnConfirmed(
request.nonce,
request.requester,
request.amount,
request.btcDepositAddress,
btcTxid,
request.depositAddress,
txid,
request.timestamp,
requestHash
);
Expand All @@ -279,8 +279,8 @@ contract Factory is OwnableContract {
uint requestNonce,
address requester,
uint amount,
string btcDepositAddress,
string btcTxid,
string depositAddress,
string txid,
uint timestamp,
string status,
bytes32 requestHash
Expand All @@ -292,8 +292,8 @@ contract Factory is OwnableContract {
requestNonce = request.nonce;
requester = request.requester;
amount = request.amount;
btcDepositAddress = request.btcDepositAddress;
btcTxid = request.btcTxid;
depositAddress = request.depositAddress;
txid = request.txid;
timestamp = request.timestamp;
status = statusString;
requestHash = calcRequestHash(request);
Expand All @@ -310,8 +310,8 @@ contract Factory is OwnableContract {
uint requestNonce,
address requester,
uint amount,
string btcDepositAddress,
string btcTxid,
string depositAddress,
string txid,
uint timestamp,
string status,
bytes32 requestHash
Expand All @@ -323,8 +323,8 @@ contract Factory is OwnableContract {
requestNonce = request.nonce;
requester = request.requester;
amount = request.amount;
btcDepositAddress = request.btcDepositAddress;
btcTxid = request.btcTxid;
depositAddress = request.depositAddress;
txid = request.txid;
timestamp = request.timestamp;
status = statusString;
requestHash = calcRequestHash(request);
Expand Down Expand Up @@ -362,8 +362,8 @@ contract Factory is OwnableContract {
return keccak256(abi.encode(
request.requester,
request.amount,
request.btcDepositAddress,
request.btcTxid,
request.depositAddress,
request.txid,
request.nonce,
request.timestamp
));
Expand Down
18 changes: 2 additions & 16 deletions contracts/token/WBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@ import "openzeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/BurnableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/PausableToken.sol";
import "../utils/OwnableContract.sol";
import "../token/WrappedToken.sol";


contract WBTC is StandardToken, DetailedERC20("Wrapped BTC", "WBTC", 8),
MintableToken, BurnableToken, PausableToken, OwnableContract {

function burn(uint value) public onlyOwner {
super.burn(value);
}

function finishMinting() public onlyOwner returns (bool) {
return false;
}

function renounceOwnership() public onlyOwner {
revert("renouncing ownership is blocked");
}
}
contract WBTC is WrappedToken, DetailedERC20("Wrapped BTC", "WBTC", 8) {}

Loading

0 comments on commit 74368f0

Please sign in to comment.