Skip to content
Permalink
Browse files

Moving from previous repo to separate repo

  • Loading branch information...
mrdavey committed Feb 19, 2019
0 parents commit 824658d0a5aa50f0a4057749374e864d2973b372
@@ -0,0 +1 @@
pragma solidity ^0.5.0;
@@ -0,0 +1,53 @@
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "../Interfaces/ICommunityRegister.sol";

contract CommunityRegister is ICommunityRegister, Ownable {

mapping (address => bool) public adminAccounts;

/**
* @dev The owner is added as an admin.
*/
constructor() public {
adminAccounts[msg.sender] = true;
}

/**
* @dev Throws if called by a non-admin account.
*/
modifier onlyAdmins() {
require(adminAccounts[msg.sender] == true, "Only admins can perform this action");
_;
}

/**
* @dev Check if a user is an admin.
* @param _address The address of the user to check.
* @return A bool indicating if the specified account is an admin.
*/
function isAdmin(address _address) external view returns (bool) {
return adminAccounts[_address];
}

/**
* @dev Add an admin.
* @param _account The address of the new admin.
*/
function addAdmin(address _account) public onlyAdmins {
adminAccounts[_account] = true;
}

/**
* @dev Remove an admin.
* @notice The original owner (i.e. contract creator) should always have the
* power to restore things, so cannot be removed as an admin. If the owner
* role needs to be transfered, then call 'transferOwnership()' in Ownable.sol.
* @param _account The address of the admin to be removed.
*/
function removeAdmin(address _account) public onlyAdmins {
require(address(_account) != owner(), "Owner account cannot be removed as admin");
adminAccounts[_account] = false;
}
}
@@ -0,0 +1,29 @@
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

import "../Interfaces/IKhanaLogic.sol";
import "../Interfaces/ICommunityRegister.sol";


contract KhanaLogic is IKhanaLogic, Ownable {
ICommunityRegister communityRegister;

modifier onlyAdmins() {
require(communityRegister.isAdmin(msg.sender), "Only admins can perform this action");
_;
}

constructor(address _communityRegisterAddress) public {
communityRegister = ICommunityRegister(_communityRegisterAddress);
}

function setCommunityRegister(address _communityRegister) public onlyAdmins {
communityRegister = ICommunityRegister(_communityRegister);
}

function isAdmin(address _address) external view returns (bool) {
return communityRegister.isAdmin(_address);
}

}
@@ -0,0 +1 @@
pragma solidity ^0.5.0;
@@ -0,0 +1 @@
pragma solidity ^0.5.0;
@@ -0,0 +1 @@
pragma solidity ^0.5.0;
@@ -0,0 +1 @@
pragma solidity ^0.5.0;
@@ -0,0 +1,5 @@
pragma solidity ^0.5.0;

interface IBondedVault {

}
@@ -0,0 +1,5 @@
pragma solidity ^0.5.0;

interface ICommunityRegister {
function isAdmin(address _address) external view returns (bool);
}
@@ -0,0 +1,5 @@
pragma solidity ^0.5.0;

interface IKhanaLogic {
function isAdmin(address _address) external view returns (bool);
}
BIN +407 KB Khana MVP.png
Binary file not shown.
21 LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 David Truong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,23 @@
pragma solidity ^0.5.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

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

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

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);
}
}
@@ -0,0 +1,102 @@
pragma solidity ^0.5.0;

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

contract BondedVault is Ownable {

address public authorisedSender;
bool public collateralIsEth;
ERC20Mintable public collateralToken;
bool public isFrozen;

event LogCollateralSend(
uint amount,
address indexed account
);

event LogCollateralTypeChanged(
bool isEth,
address indexed account
);

event LogEthDonated(
uint amount,
address indexed account
);

event LogAuthorisedSenderChanged(
address indexed newSender,
address oldSender,
address owner
);

event LogVaultFrozen(
address indexed owner,
bool isFrozen
);

modifier onlyAuthorisedSender() {
require(msg.sender == authorisedSender, "Non-authorised sender");
_;
}

modifier onlyUnfrozen() {
require(!isFrozen, "Vault is currently frozen");
_;
}

/**
* @dev Send the underlying collateral to a specific address
* @notice This function will send ETH or another ERC20 depending on the value of collateralIsEth.
* @param _amount The amount of collateral to be transfered.
* @param _account The address of the user to awarded.
*/
function sendCollateral(uint _amount, address payable _account) public onlyAuthorisedSender onlyUnfrozen {
if (collateralIsEth) {
_account.transfer(_amount);
} else {
collateralToken.transfer(_account, _amount);
}
emit LogCollateralSend(_amount, _account);
}

/**
* @dev Set the underlying asset type for collateral
* @notice By default this is set to non ETH (i.e. ERC20).
* @param _collateralIsEth A bool value to determine if ETH is the collateral underlying the curve
*/
function setCollateralToEth(bool _collateralIsEth) public onlyOwner {
collateralIsEth = _collateralIsEth;
emit LogCollateralTypeChanged(_collateralIsEth, msg.sender);
}

/**
* @dev Fallback function to accept direct ETH transfers as free donations to the bonding curve.
* @notice Does not accept funds when vault is frozen.
*/
function () external onlyUnfrozen payable {
emit LogEthDonated(msg.value, msg.sender);
}

/**
* @dev Set the authorisedSender address.
* @notice The authorisedSender is able to send collateral to an address. Ideally the authorisedSender
* should be another contract such as the CommunityRegister.
* @param _authorisedSender The address of the new authorisedSender.
*/
function setAuthorisedSender(address _authorisedSender) public onlyOwner {
address oldSender = authorisedSender;
authorisedSender = _authorisedSender;
emit LogAuthorisedSenderChanged(_authorisedSender, oldSender, msg.sender);
}

/**
* @dev Sets or unsets the vault in a frozen state, where no transfers are possible.
* @param _isFrozen Whether the vault should be frozen or not.
*/
function setFreeze(bool _isFrozen) public onlyOwner {
isFrozen = _isFrozen;
emit LogVaultFrozen(msg.sender, isFrozen);
}
}
@@ -0,0 +1,73 @@
pragma solidity ^0.5.0;

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

import "../Interfaces/IKhanaLogic.sol";
import "../Interfaces/IBondedVault.sol";

/**
* @author David Truong | Khana.io
* @title Collateral Token contract
* @notice This contract will be used as a temporary measure to bridge between testnet
* and mainnet. Real collateral will be held in a multisig vault on mainnet, with the
* testnet collateral keeping a 1 to 1 peg with the multisig vault.
* As collateral is added to the bonding curve, the same must be applied to both the
* testnet and mainnet collateral pools. This ensures that the 'price' calculated per
* token is accurate, real, and transferable.
* In the case of a catastrophic failure, this collateral token contract can be 'reset',
* with the mainnet collateral being safe under the multisig holders.
*/
contract CollateralToken is ERC20, Ownable {

IKhanaLogic public khanaLogic;
IBondedVault public bondedVault;

modifier onlyAdmins() {
require(khanaLogic.isAdmin(msg.sender), "Only admins can perform this action");
_;
}

constructor(address _khanaLogicAddress, address _bondedVaultAddress) public {
khanaLogic = IKhanaLogic(_khanaLogicAddress);
bondedVault = IBondedVault(_bondedVaultAddress);
}

/**
* @dev Change the default khanaLogic address
* @param _khanaLogic The address of the khanaLogic contract, that conforms
* to the IKhanaLogic interface
*/
function setKhanaLogic(address _khanaLogic) public onlyAdmins {
khanaLogic = IKhanaLogic(_khanaLogic);
}

/**
* @dev Change the default bondedVault address
* @param _bondedVaultAddress The address of the bondedVault contract, that conforms
* to the IBondedvault interface
*/
function setBondedVault(address _bondedVaultAddress) public onlyAdmins {
bondedVault = IBondedVault(_bondedVaultAddress);
}

/**
* @dev Mint the ERC20 collateral for the BondedVault contract.
* @notice The collateral can only be minted into the BondedVault contract.
* @param _value The amount of collateral to be minted
*/
function mintCollateral(uint _value) external onlyAdmins returns (bool) {
_mint(address(bondedVault), _value);
return true;
}

/**
* @dev Burn the ERC20 collateral from the BondedVault contract.
* @notice The collateral can only be burned from the BondedVault contract.
* @param _value The amount of collateral to be burned
*/
function burnCollateral(uint _value) external onlyAdmins returns (bool) {
_burn(address(bondedVault), _value);
return true;
}
}

0 comments on commit 824658d

Please sign in to comment.
You can’t perform that action at this time.