Skip to content

Commit

Permalink
Merge pull request #479 from PolymathNetwork/Split-out-ISTO
Browse files Browse the repository at this point in the history
Split out ISTO.sol
  • Loading branch information
satyamakgec committed Dec 18, 2018
2 parents 139a36b + d842c20 commit 68f1af9
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 79 deletions.
13 changes: 13 additions & 0 deletions contracts/interfaces/ISTO.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pragma solidity ^0.4.24;

/**
* @title Interface to be implemented by all STO modules
*/
interface ISTO {

/**
* @notice Returns the total no. of tokens sold
*/
function getTokensSold() external view returns (uint256);

}
15 changes: 15 additions & 0 deletions contracts/interfaces/ITransferManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.4.24;

import "./TransferManagerEnums.sol";

/**
* @title Interface to be implemented by all Transfer Manager modules
*/
interface ITransferManager {

/**
* @notice Determines if the transfer between these two accounts can happen
*/
function verifyTransfer(address _from, address _to, uint256 _amount, bytes _data, bool _isTransfer) external returns(TransferManagerEnums.Result);

}
15 changes: 15 additions & 0 deletions contracts/interfaces/TransferManagerEnums.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.4.24;

/**
* @title Container contract for transfer manager enums
*/
contract TransferManagerEnums {

//If verifyTransfer returns:
// FORCE_VALID, the transaction will always be valid, regardless of other TM results
// INVALID, then the transfer should not be allowed regardless of other TM results
// VALID, then the transfer is valid for this TM
// NA, then the result from this TM is ignored
enum Result {INVALID, NA, VALID, FORCE_VALID}

}
6 changes: 3 additions & 3 deletions contracts/modules/Experimental/Mixed/ScheduledCheckpoint.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pragma solidity ^0.4.24;

import "./../../Checkpoint/ICheckpoint.sol";
import "../../TransferManager/ITransferManager.sol";
import "../../TransferManager/TransferManager.sol";
import "../../../interfaces/ISecurityToken.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title Burn module for burning tokens and keeping track of burnt amounts
*/
contract ScheduledCheckpoint is ICheckpoint, ITransferManager {
contract ScheduledCheckpoint is ICheckpoint, TransferManager {
using SafeMath for uint256;

struct Schedule {
Expand Down Expand Up @@ -85,7 +85,7 @@ contract ScheduledCheckpoint is ICheckpoint, ITransferManager {
* @param _isTransfer whether or not an actual transfer is occuring
* @return always returns Result.NA
*/
function verifyTransfer(address /* _from */, address /* _to */, uint256 /* _amount */, bytes /* _data */, bool _isTransfer) public returns(Result) {
function verifyTransfer(address /* _from */, address /* _to */, uint256 /* _amount */, bytes /* _data */, bool _isTransfer) external returns(Result) {
require(_isTransfer == false || msg.sender == securityToken, "Sender is not owner");
if (paused || !_isTransfer) {
return Result.NA;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity ^0.4.24;

import "./../../TransferManager/ITransferManager.sol";
import "./../../TransferManager/TransferManager.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";


contract LockupVolumeRestrictionTM is ITransferManager {
contract LockupVolumeRestrictionTM is TransferManager {

using SafeMath for uint256;

Expand Down Expand Up @@ -66,7 +66,7 @@ contract LockupVolumeRestrictionTM is ITransferManager {
* @param _amount The amount of tokens to transfer
* @param _isTransfer Whether or not this is an actual transfer or just a test to see if the tokens would be transferrable
*/
function verifyTransfer(address _from, address /* _to*/, uint256 _amount, bytes /* _data */, bool _isTransfer) public returns(Result) {
function verifyTransfer(address _from, address /* _to*/, uint256 _amount, bytes /* _data */, bool _isTransfer) external returns(Result) {
// only attempt to verify the transfer if the token is unpaused, this isn't a mint txn, and there exists a lockup for this user
if (!paused && _from != address(0) && lockUps[_from].length != 0) {
// check if this transfer is valid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pragma solidity ^0.4.24;

import "./../../TransferManager/ITransferManager.sol";
import "./../../TransferManager/TransferManager.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title Transfer Manager for limiting volume of tokens in a single trade
*/

contract SingleTradeVolumeRestrictionTM is ITransferManager {
contract SingleTradeVolumeRestrictionTM is TransferManager {
using SafeMath for uint256;

bytes32 constant public ADMIN = "ADMIN";
Expand Down Expand Up @@ -63,7 +63,7 @@ contract SingleTradeVolumeRestrictionTM is ITransferManager {
bytes /* _data */,
bool /* _isTransfer */
)
public
external
returns(Result)
{
bool validTransfer;
Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/STO/CappedSTO.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pragma solidity ^0.4.24;

import "./ISTO.sol";
import "./STO.sol";
import "../../interfaces/ISecurityToken.sol";
import "openzeppelin-solidity/contracts/utils/ReentrancyGuard.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title STO module for standard capped crowdsale
*/
contract CappedSTO is ISTO, ReentrancyGuard {
contract CappedSTO is STO, ReentrancyGuard {
using SafeMath for uint256;

// Determine whether users can invest on behalf of a beneficiary
Expand Down Expand Up @@ -141,7 +141,7 @@ contract CappedSTO is ISTO, ReentrancyGuard {
/**
* @notice Return the total no. of tokens sold
*/
function getTokensSold() public view returns (uint256) {
function getTokensSold() external view returns (uint256) {
return totalTokensSold;
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/STO/DummySTO.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pragma solidity ^0.4.24;

import "./ISTO.sol";
import "./STO.sol";
import "../../interfaces/ISecurityToken.sol";

/**
* @title STO module for sample implementation of a different crowdsale module
*/
contract DummySTO is ISTO {
contract DummySTO is STO {

bytes32 public constant ADMIN = "ADMIN";

Expand Down Expand Up @@ -76,7 +76,7 @@ contract DummySTO is ISTO {
/**
* @notice Returns the total no. of investors
*/
function getTokensSold() public view returns (uint256) {
function getTokensSold() external view returns (uint256) {
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/STO/PreSaleSTO.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pragma solidity ^0.4.24;

import "./ISTO.sol";
import "./STO.sol";
import "../../interfaces/ISecurityToken.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title STO module for private presales
*/
contract PreSaleSTO is ISTO {
contract PreSaleSTO is STO {
using SafeMath for uint256;

bytes32 public constant PRE_SALE_ADMIN = "PRE_SALE_ADMIN";
Expand Down Expand Up @@ -51,7 +51,7 @@ contract PreSaleSTO is ISTO {
/**
* @notice Returns the total no. of tokens sold
*/
function getTokensSold() public view returns (uint256) {
function getTokensSold() external view returns (uint256) {
return totalTokensSold;
}

Expand Down
12 changes: 4 additions & 8 deletions contracts/modules/STO/ISTO.sol → contracts/modules/STO/STO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ pragma solidity ^0.4.24;
import "../../Pausable.sol";
import "../Module.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "./ISTOStorage.sol";
import "./STOStorage.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "../../interfaces/ISTO.sol";

/**
* @title Interface to be implemented by all STO modules
* @title Base abstract contract to be extended by all STO modules
*/
contract ISTO is ISTOStorage, Module, Pausable {
contract STO is ISTO, STOStorage, Module, Pausable {
using SafeMath for uint256;

enum FundRaiseType { ETH, POLY, DAI }
Expand All @@ -36,11 +37,6 @@ contract ISTO is ISTOStorage, Module, Pausable {
return fundsRaised[uint8(_fundRaiseType)];
}

/**
* @notice Returns the total no. of tokens sold
*/
function getTokensSold() public view returns (uint256);

/**
* @notice Pause (overridden function)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma solidity ^0.4.24;

/**
* @title Storage layout for the ISTO contract
* @title Storage layout for the STO contract
*/
contract ISTOStorage {
contract STOStorage {

mapping (uint8 => bool) public fundRaiseTypes;
mapping (uint8 => uint256) public fundsRaised;
Expand Down
12 changes: 8 additions & 4 deletions contracts/modules/STO/USDTieredSTO.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.24;

import "./ISTO.sol";
import "./STO.sol";
import "../../interfaces/ISecurityToken.sol";
import "../../interfaces/IOracle.sol";
import "../../RegistryUpdater.sol";
Expand All @@ -12,7 +12,7 @@ import "./USDTieredSTOStorage.sol";
/**
* @title STO module for standard capped crowdsale
*/
contract USDTieredSTO is USDTieredSTOStorage, ISTO, ReentrancyGuard {
contract USDTieredSTO is USDTieredSTOStorage, STO, ReentrancyGuard {
using SafeMath for uint256;

string public constant POLY_ORACLE = "PolyUsdOracle";
Expand Down Expand Up @@ -713,7 +713,11 @@ contract USDTieredSTO is USDTieredSTOStorage, ISTO, ReentrancyGuard {
* @notice Return the total no. of tokens sold
* @return uint256 Total number of tokens sold
*/
function getTokensSold() public view returns (uint256) {
function getTokensSold() external view returns (uint256) {
return _getTokensSold();
}

function _getTokensSold() internal view returns (uint256) {
if (isFinalized)
return totalTokensSold;
else
Expand Down Expand Up @@ -820,7 +824,7 @@ contract USDTieredSTO is USDTieredSTOStorage, ISTO, ReentrancyGuard {
rate,
fundsRaisedUSD,
investorCount,
getTokensSold(),
_getTokensSold(),
_fundRaiseTypes
);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/TransferManager/CountTransferManager.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pragma solidity ^0.4.24;

import "./ITransferManager.sol";
import "./TransferManager.sol";

/**
* @title Transfer Manager for limiting maximum number of token holders
*/
contract CountTransferManager is ITransferManager {
contract CountTransferManager is TransferManager {

// The maximum number of concurrent token holders
uint256 public maxHolderCount;
Expand Down Expand Up @@ -36,7 +36,7 @@ contract CountTransferManager is ITransferManager {
bytes /* _data */,
bool /* _isTransfer */
)
public
external
returns(Result)
{
if (!paused) {
Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/TransferManager/GeneralTransferManager.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pragma solidity ^0.4.24;

import "./ITransferManager.sol";
import "./TransferManager.sol";
import "./GeneralTransferManagerStorage.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title Transfer Manager module for core transfer validation functionality
*/
contract GeneralTransferManager is GeneralTransferManagerStorage, ITransferManager {
contract GeneralTransferManager is GeneralTransferManagerStorage, TransferManager {

using SafeMath for uint256;

Expand Down Expand Up @@ -141,7 +141,7 @@ contract GeneralTransferManager is GeneralTransferManagerStorage, ITransferManag
* @param _from Address of the sender
* @param _to Address of the receiver
*/
function verifyTransfer(address _from, address _to, uint256 /*_amount*/, bytes /* _data */, bool /* _isTransfer */) public returns(Result) {
function verifyTransfer(address _from, address _to, uint256 /*_amount*/, bytes /* _data */, bool /* _isTransfer */) external returns(Result) {
if (!paused) {
if (allowAllTransfers) {
//All transfers allowed, regardless of whitelist
Expand Down
28 changes: 0 additions & 28 deletions contracts/modules/TransferManager/ITransferManager.sol

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pragma solidity ^0.4.24;

import "./ITransferManager.sol";
import "./TransferManager.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title Transfer Manager module for manually approving or blocking transactions between accounts
*/
contract ManualApprovalTransferManager is ITransferManager {
contract ManualApprovalTransferManager is TransferManager {
using SafeMath for uint256;

//Address from which issuances come
Expand Down Expand Up @@ -84,7 +84,7 @@ contract ManualApprovalTransferManager is ITransferManager {
* @param _amount The amount of tokens to transfer
* @param _isTransfer Whether or not this is an actual transfer or just a test to see if the tokens would be transferrable
*/
function verifyTransfer(address _from, address _to, uint256 _amount, bytes /* _data */, bool _isTransfer) public returns(Result) {
function verifyTransfer(address _from, address _to, uint256 _amount, bytes /* _data */, bool _isTransfer) external returns(Result) {
// function must only be called by the associated security token if _isTransfer == true
require(_isTransfer == false || msg.sender == securityToken, "Sender is not the owner");
// manual blocking takes precidence over manual approval
Expand Down
Loading

0 comments on commit 68f1af9

Please sign in to comment.