Skip to content

Commit

Permalink
Merge branch 'refactor/dao-voting' of github.com:HQ20/contracts into …
Browse files Browse the repository at this point in the history
…refactor/dao-voting
  • Loading branch information
uivlis committed Mar 2, 2020
2 parents 5d159d7 + 7ed4a8b commit 3ded3c1
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 310 deletions.
18 changes: 3 additions & 15 deletions contracts/drafts/issuance/IssuanceAdvanced.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../../token/IERC20Detailed.sol";
import "../../token/IERC20MintableDetailed.sol";
import "./../../state/StateMachine.sol";
import "../../utils/SafeCast.sol";
import "../../math/DecimalMath.sol";


/**
Expand All @@ -18,9 +19,7 @@ import "../../utils/SafeCast.sol";
contract IssuanceAdvanced is Ownable, StateMachine, ReentrancyGuard {

using SafeMath for uint256;
using FixidityLib for int256;
using SafeCast for int256;
using SafeCast for uint256;
using DecimalMath for uint256;

event IssuanceCreated();

Expand Down Expand Up @@ -102,23 +101,12 @@ contract IssuanceAdvanced is Ownable, StateMachine, ReentrancyGuard {
require(investments[msg.sender] > 0, "No investments found.");
uint256 amount = investments[msg.sender];
investments[msg.sender] = 0;
IERC20Detailed _currencyToken = IERC20Detailed(currencyToken);
IERC20MintableDetailed _issuanceToken = IERC20MintableDetailed(
issuanceToken
);
int256 investedFixed = amount.safeUintToInt().newFixed(
_currencyToken.decimals()
);
int256 issuePriceFixed = issuePrice.safeUintToInt().newFixed(
_currencyToken.decimals()
);
int256 issuanceTokensFixed = investedFixed.divide(issuePriceFixed);
uint256 issuanceTokens = issuanceTokensFixed.fromFixed(
_issuanceToken.decimals()
).safeIntToUint();
_issuanceToken.mint(
msg.sender,
issuanceTokens
amount.divd(issuePrice, _issuanceToken.decimals())
);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/dao/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "./VentureEth.sol";
import "../../drafts/voting/Voting.sol";
import "./../../voting/Voting.sol";


/**
Expand Down
18 changes: 3 additions & 15 deletions contracts/issuance/Issuance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../token/IERC20Detailed.sol";
import "../token/IERC20MintableDetailed.sol";
import "../state/StateMachine.sol";
import "../utils/SafeCast.sol";
import "../math/DecimalMath.sol";


/**
Expand All @@ -29,9 +30,7 @@ import "../utils/SafeCast.sol";
*/
contract Issuance is Ownable, StateMachine, ReentrancyGuard {
using SafeMath for uint256;
using FixidityLib for int256;
using SafeCast for int256;
using SafeCast for uint256;
using DecimalMath for uint256;

event IssuanceCreated();
event IssuePriceSet();
Expand Down Expand Up @@ -98,23 +97,12 @@ contract Issuance is Ownable, StateMachine, ReentrancyGuard {
);
uint256 amount = investments[msg.sender];
investments[msg.sender] = 0;
IERC20Detailed _currencyToken = IERC20Detailed(currencyToken);
IERC20MintableDetailed _issuanceToken = IERC20MintableDetailed(
issuanceToken
);
int256 investedFixed = amount.safeUintToInt().newFixed(
_currencyToken.decimals()
);
int256 issuePriceFixed = issuePrice.safeUintToInt().newFixed(
_currencyToken.decimals()
);
int256 issuanceTokensFixed = investedFixed.divide(issuePriceFixed);
uint256 issuanceTokens = issuanceTokensFixed.fromFixed(
_issuanceToken.decimals()
).safeIntToUint();
_issuanceToken.mint(
msg.sender,
issuanceTokens
amount.divd(issuePrice, _issuanceToken.decimals())
);
}

Expand Down
14 changes: 3 additions & 11 deletions contracts/issuance/IssuanceEth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "../token/IERC20MintableDetailed.sol";
import "../state/StateMachine.sol";
import "../utils/SafeCast.sol";
import "../math/DecimalMath.sol";


/**
Expand All @@ -27,9 +27,7 @@ import "../utils/SafeCast.sol";
*/
contract IssuanceEth is Ownable, StateMachine, ReentrancyGuard {
using SafeMath for uint256;
using FixidityLib for int256;
using SafeCast for int256;
using SafeCast for uint256;
using DecimalMath for uint256;

event IssuanceCreated();
event IssuePriceSet();
Expand Down Expand Up @@ -73,15 +71,9 @@ contract IssuanceEth is Ownable, StateMachine, ReentrancyGuard {
IERC20MintableDetailed _issuanceToken = IERC20MintableDetailed(
issuanceToken
);
int256 investedFixed = amount.safeUintToInt().newFixed(18);
int256 issuePriceFixed = issuePrice.safeUintToInt().newFixed(18);
int256 issuanceTokensFixed = investedFixed.divide(issuePriceFixed);
uint256 issuanceTokens = issuanceTokensFixed.fromFixed(
_issuanceToken.decimals()
).safeIntToUint();
_issuanceToken.mint(
msg.sender,
issuanceTokens
amount.divd(issuePrice, _issuanceToken.decimals())
);
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../state/StateMachine.sol";
import "../../utils/SafeCast.sol";
import "../state/StateMachine.sol";
import "../utils/SafeCast.sol";


/**
Expand Down
Loading

0 comments on commit 3ded3c1

Please sign in to comment.