Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules

.idea/
99 changes: 61 additions & 38 deletions contracts/DebtToken.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'zeppelin/token/ERC20Basic.sol';
import 'zeppelin/token/MintableToken.sol';
import 'zeppelin/ownership/Ownable.sol';
import 'zeppelin/math/SafeMath.sol';

pragma solidity ^0.4.15;

contract DebtToken is ERC20Basic,MintableToken{

contract DebtToken is Ownable {
using SafeMath for uint256;
/**
Recognition data
*/
Expand All @@ -27,8 +27,7 @@ contract DebtToken is ERC20Basic,MintableToken{
uint256 public lastinterestCycle; //Keep record of Initial value of Loan
address public debtOwner; //The address from which the loan will be funded, and to which the refund will be directed
uint256 public constant divisor = 100;



function DebtToken(string _tokenName,
string _tokenSymbol,
uint256 _initialAmount,
Expand All @@ -52,10 +51,63 @@ contract DebtToken is ERC20Basic,MintableToken{
interestCycleLength = _loanCycle; //set the Interest cycle period
interestRate = _interestRate; //Set the Interest rate per cycle
debtOwner = _debtOwner; //set Debt owner
mintingFinished = true; //Disable minting

Transfer(0,msg.sender,totalSupply);//Allow funding be tracked
}

/**
Partial ERC20 functionality
*/
uint256 public totalSupply;
mapping(address => uint256) balances;

event Transfer(address indexed from, address indexed to, uint256 value);

function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}

/**
MintableToken functionality
*/
event Mint(address indexed to, uint256 amount);
event MintFinished();

bool public mintingFinished = true;


modifier canMint() {
require(!mintingFinished);
_;
}

/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) canMint private returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(0x0, _to, _amount);
return true;
}

/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner private returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}

/**
Debt token functionality
*/
function actualTotalSupply() public constant returns(uint) {
uint256 coins;
uint256 cycle;
Expand Down Expand Up @@ -140,7 +192,7 @@ contract DebtToken is ERC20Basic,MintableToken{
assert(interest_coins > 0 && interest_cycle > 0);
totalInterestCycle = totalInterestCycle.add(interest_cycle);
lastinterestCycle = lastinterestCycle.add( interest_cycle.mul( interestCycleLength.mul(dayLength) ) );
super.mint(debtOwner , interest_coins);
mint(debtOwner , interest_coins);
}

/**
Expand Down Expand Up @@ -174,7 +226,7 @@ contract DebtToken is ERC20Basic,MintableToken{
require(msg.value == getLoanValue(false));

require(balances[debtOwner] > 0);
super.finishMinting() ;//Prevent further Minting
finishMinting() ;//Prevent further Minting

balances[debtOwner] = balances[debtOwner].sub(totalSupply);
balances[owner] = balances[owner].add(totalSupply);
Expand All @@ -199,33 +251,4 @@ contract DebtToken is ERC20Basic,MintableToken{
function transferOwnership(address newOwner) onlyOwner public {
revert(); //Disable the transferOwnership feature: Loan non-transferrable
}

function transfer(address to, uint256 value) public returns (bool){
revert(); //Disable the transfer feature: Loan non-transferrable
}

function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
revert(); //Disable the transferFrom feature: Loan non-transferrable
}

function approve(address _spender, uint256 _value) public returns (bool) {
revert(); //Disable the approve feature: Loan non-transferrable
}

function allowance(address _owner, address _spender) public constant returns (uint256) {
revert(); //Disable the allowance feature: Loan non-transferrable
}

function increaseApproval (address _spender, uint _addedValue) public returns (bool) {
revert(); //Disable the increaseApproval feature: Loan non-transferrable
}

function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool) {
revert(); //Disable the decreaseApproval feature: Loan non-transferrable
}

function finishMinting() onlyOwner public returns (bool) {
revert(); //Disable the external control of finishMinting
}

}
52 changes: 52 additions & 0 deletions contracts/DeployDebtToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import './DebtToken.sol';
pragma solidity ^0.4.15;
contract DeployDebtToken is Ownable{

address public owner;
address public dayTokenAddress;
uint public dayTokenFees; //DAY tokens to be paid for deploying custom DAY contract
ERC20 dayToken;

event FeeUpdated(uint _fee, uint _time);
event DebtTokenCreated(address _creator, address _debtTokenAddress, uint256 _time);

function DeployDebtToken(address _dayTokenAddress, uint _dayTokenFees){
dayTokenAddress = _dayTokenAddress;
dayTokenFees = _dayTokenFees;
owner = msg.sender;
dayToken = ERC20(dayTokenAddress);
}

function updateDayTokenFees(uint _dayTokenFees) onlyOwner public {
dayTokenFees = _dayTokenFees;
FeeUpdated(dayTokenFees, now);
}

function createDebtToken(string _tokenName,
string _tokenSymbol,
uint256 _initialAmount,
uint256 _exchangeRate,
uint256 _decimalUnits,
uint256 _dayLength,
uint256 _loanTerm,
uint256 _loanCycle,
uint256 _interestRate,
address _debtOwner){

address user = msg.sender;

if(dayToken.transferFrom(user, this, dayTokenFees)){
DebtToken newDebtToken = new DebtToken(_tokenName, _tokenSymbol, _initialAmount, _exchangeRate,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When calling new DebtToken from DeployDebtToken the msg.sender seen by DebtToken will be the address of DeployDebtToken contract.

To fix this we shall modify the contract so it accepts 'borrower' as an input.

@adibas03 adibas03 Jan 17, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Observation, we would create a different DeployableDebtToken with that feature, so we can separate development process of the two.
Following the pattern used in the DayToken

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the way DayToken has resolved it. In case of debt contract, I think it has too much of overhead. If we "rename" owner to "borrower" there is no need for 3rd party like owner.

My proposal is to

  • add explicit argument to ctor borrower
  • remove owner variable and semantics and replace with borrower (remove ownable inheritance)

_decimalUnits, _dayLength, _loanTerm, _loanCycle,
_interestRate, _debtOwner);
DebtTokenCreated(user, address(newDebtToken), now);
}

}

// to collect all fees paid till now
function fetchDayTokens() onlyOwner public {
dayToken.transfer(owner, dayToken.balanceOf(this));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the fallback function, just to ensure that ether are not transferred to the address?

@kosecki123 kosecki123 Jan 11, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default fallback is not payable so TX with ETH will be reverted

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for deployment code.

}
6 changes: 2 additions & 4 deletions test/debtToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ contract('DebtToken', function(accounts){
})

it('Should fail to allow owner run finishMinting function',function(done){
contract.finishMinting({from:Me},function(e,r){
assert.notEqual(e,null,'Owner successfuly prevented minting without refunding Loan');
done();
});
assert.isNotOk(contract.finishMinting, "finishMiting shall be available internally only");
done();
})

})
Expand Down