Skip to content
Merged
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
12 changes: 7 additions & 5 deletions contracts/modules/TransferManager/ExchangeTransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ contract ExchangeTransferManager is ITransferManager {
}

function verifyTransfer(address _from, address _to, uint256 /*_amount*/) public view returns(bool) {
if (_from == exchange) {
return getExchangePermission(_to);
} else if (_to == exchange) {
return getExchangePermission(_from);
if (!paused) {
if (_from == exchange) {
return getExchangePermission(_to);
} else if (_to == exchange) {
return getExchangePermission(_from);
}
}

return false;
}

Expand Down Expand Up @@ -62,4 +63,5 @@ contract ExchangeTransferManager is ITransferManager {
// e.g. calling out to another contract maintained by the exchange to get list of allowed users
return whitelist[_investor];
}

}
30 changes: 19 additions & 11 deletions contracts/modules/TransferManager/GeneralTransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,23 @@ contract GeneralTransferManager is ITransferManager {
* c) Buyer's purchase lockup is over
*/
function verifyTransfer(address _from, address _to, uint256 /*_amount*/) public view returns(bool) {
if (allowAllTransfers) {
if (!paused) {
if (allowAllTransfers) {
//All transfers allowed, regardless of whitelist
return true;
}
if (allowAllWhitelistTransfers) {
//Anyone on the whitelist can transfer, regardless of block number
return (onWhitelist(_to) && onWhitelist(_from));
}
if (allowAllWhitelistIssuances && _from == issuanceAddress) {
return onWhitelist(_to);
}
//Anyone on the whitelist can transfer provided the blocknumber is large enough
return ((onWhitelist(_from) && whitelist[_from].fromTime <= now) &&
(onWhitelist(_to) && whitelist[_to].toTime <= now));
}
if (allowAllWhitelistTransfers) {
//Anyone on the whitelist can transfer, regardless of block number
return (onWhitelist(_to) && onWhitelist(_from));
}
if (allowAllWhitelistIssuances && _from == issuanceAddress) {
return onWhitelist(_to);
}
//Anyone on the whitelist can transfer provided the blocknumber is large enough
return ((onWhitelist(_from) && whitelist[_from].fromTime <= now) &&
(onWhitelist(_to) && whitelist[_to].toTime <= now));
return false;
}

/**
Expand Down Expand Up @@ -194,4 +197,9 @@ contract GeneralTransferManager is ITransferManager {
return (((whitelist[_investor].fromTime != 0) || (whitelist[_investor].toTime != 0)) &&
(whitelist[_investor].expiryTime >= now));
}

// function pauseTransfers(bool _pause) public {
// pause = _pause;
// emit LogTransfersHalted(_pause, now);
// }
}
23 changes: 23 additions & 0 deletions contracts/modules/TransferManager/ITransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ import "../../interfaces/IModule.sol";

contract ITransferManager is IModule {

event Pause(uint256 _timestammp);
event Unpause(uint256 _timestamp);

bool public paused = false;

/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner public {
require(!paused);
paused = true;
emit Pause(now);
}

/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner public {
require(paused);
paused = false;
emit Unpause(now);
}

function verifyTransfer(address _from, address _to, uint256 _amount) public view returns(bool);

}
34 changes: 28 additions & 6 deletions contracts/tokens/SecurityToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
using SafeMath for uint256;

bytes32 public securityTokenVersion = "0.0.1";

// Use to halt all the transactions
bool public freeze = false;
// Reference to the POLY token.
ERC20 public polyToken;

Expand Down Expand Up @@ -56,6 +57,7 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
event LogModuleRemoved(uint8 indexed _type, address _module, uint256 _timestamp);
event LogModuleBudgetChanged(uint8 indexed _moduleType, address _module, uint256 _budget);
event Mint(address indexed to, uint256 amount);
event LogFreezeTransfers(bool _freeze, uint256 _timestamp);

//if _fallback is true, then we only allow the module if it is set, if it is not set we only allow the owner
modifier onlyModule(uint8 _moduleType, bool _fallback) {
Expand Down Expand Up @@ -223,6 +225,24 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
granularity = _granularity;
}

/**
* @dev freeze all the transfers
*/
function freezeTransfers() public onlyOwner {
require(!freeze);
freeze = true;
emit LogFreezeTransfers(freeze, now);
}

/**
* @dev un-freeze all the transfers
*/
function unfreezeTransfers() public onlyOwner {
require(freeze);
freeze = false;
emit LogFreezeTransfers(freeze, now);
}

/**
* @dev Overloaded version of the transfer function
*/
Expand All @@ -242,13 +262,15 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
// Permissions this to a TransferManager module, which has a key of 2
// If no TransferManager return true
function verifyTransfer(address _from, address _to, uint256 _amount) public view checkGranularity(_amount) returns (bool success) {
if (modules[TRANSFERMANAGER_KEY].length == 0) {
return true;
}
for (uint8 i = 0; i < modules[TRANSFERMANAGER_KEY].length; i++) {
if (ITransferManager(modules[TRANSFERMANAGER_KEY][i].moduleAddress).verifyTransfer(_from, _to, _amount)) {
if (!freeze) {
if (modules[TRANSFERMANAGER_KEY].length == 0) {
return true;
}
for (uint8 i = 0; i < modules[TRANSFERMANAGER_KEY].length; i++) {
if (ITransferManager(modules[TRANSFERMANAGER_KEY][i].moduleAddress).verifyTransfer(_from, _to, _amount)) {
return true;
}
}
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion test/Issuance.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ contract('Issuance', accounts => {
});

it("POLYMATH: Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: account_polymath });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: account_polymath, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol, "SecurityToken doesn't get deployed");
Expand Down
4 changes: 2 additions & 2 deletions test/capped_sto.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ contract('CappedSTO', accounts => {
});

it("Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol, "SecurityToken doesn't get deployed");
Expand Down Expand Up @@ -580,7 +580,7 @@ contract('CappedSTO', accounts => {
it("POLY: Should generate the new security token with the same symbol as registered above", async () => {
P_startTime = endTime + duration.days(2);
P_endTime = P_startTime + duration.days(30);
let tx = await I_SecurityTokenRegistry.generateSecurityToken(P_name, P_symbol, P_decimals, P_tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(P_name, P_symbol, P_decimals, P_tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, P_symbol, "SecurityToken doesn't get deployed");
Expand Down
2 changes: 1 addition & 1 deletion test/exchange_transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ contract('ExchangeTransferManager', accounts => {
});

it("Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol.toUpperCase(), "SecurityToken doesn't get deployed");
Expand Down
16 changes: 15 additions & 1 deletion test/general_transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ contract('GeneralTransferManager', accounts => {
});

it("Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner, gas: 5000000});

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol.toUpperCase(), "SecurityToken doesn't get deployed");
Expand Down Expand Up @@ -496,6 +496,20 @@ contract('GeneralTransferManager', accounts => {

});

it("should failed in trasfering the tokens", async() => {
await I_GeneralTransferManager.changeAllowAllWhitelistTransfers(true, {from : token_owner});
await I_GeneralTransferManager.pause({from: token_owner});
let errorThrown = false;
try {
await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('2','ether'), {from: account_investor2});
} catch(error) {
console.log(`Failed because trasfer is paused`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

});

});
2 changes: 1 addition & 1 deletion test/module_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ contract('ModuleRegistry', accounts => {
});

it("Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol, "SecurityToken doesn't get deployed");
Expand Down
2 changes: 1 addition & 1 deletion test/presale_sto.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ contract('PreSaleSTO', accounts => {
});

it("Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol, "SecurityToken doesn't get deployed");
Expand Down
61 changes: 60 additions & 1 deletion test/security_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ contract('SecurityToken', accounts => {
});

it("Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol, "SecurityToken doesn't get deployed");
Expand Down Expand Up @@ -625,6 +625,65 @@ contract('SecurityToken', accounts => {
assert.ok(errorThrown, message);
});

it("Should freeze the transfers", async() => {
let tx = await I_SecurityToken.freezeTransfers({from: token_owner});
assert.isTrue(tx.logs[0].args._freeze);
});

it("Should fail in buying to tokens", async() => {
let tx = await I_GeneralTransferManager.modifyWhitelist(
account_temp,
fromTime,
toTime,
expiryTime,
{
from: account_delegate,
gas: 500000
});

assert.equal(tx.logs[0].args._investor, account_temp, "Failed in adding the investor in whitelist");

let errorThrown = false;
try {
// Fallback transaction
await web3.eth.sendTransaction({
from: account_temp,
to: I_CappedSTO.address,
gas: 210000,
value: web3.utils.toWei('1', 'ether')
});

} catch (error) {
console.log(`Because all transfers get freezed`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should fail in trasfering the tokens from one user to another", async() => {
await I_GeneralTransferManager.changeAllowAllWhitelistTransfers(true, {from : token_owner});
console.log(await I_SecurityToken.balanceOf(account_investor1));
let errorThrown = false;
try {
await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), {from: account_temp});
} catch(error) {
console.log('failed in trasfer because all transfers are at hold');
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should un freeze all the transfers", async() => {
let tx = await I_SecurityToken.unfreezeTransfers({from: token_owner});
assert.isFalse(tx.logs[0].args._freeze);
});

it("Should able to transfers the tokens from one user to another", async() => {
console.log(await I_SecurityToken.balanceOf(account_investor1));
await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), {from: account_temp});
});
});

});
6 changes: 3 additions & 3 deletions test/security_token_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ contract('SecurityTokenRegistry', accounts => {
});

it("Should generate the new security token with the same symbol as registered above", async () => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol, "SecurityToken doesn't get deployed");
Expand Down Expand Up @@ -281,7 +281,7 @@ contract('SecurityTokenRegistry', accounts => {
});

it("Should generate the new security token with version 2", async() => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name2, symbol2, decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name2, symbol2, decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, symbol2, "SecurityToken doesn't get deployed");
Expand Down Expand Up @@ -329,7 +329,7 @@ contract('SecurityTokenRegistry', accounts => {
});

it("Should generate the new security token with version 3", async() => {
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name2, "DET3", decimals, tokenDetails, false, { from: token_owner });
let tx = await I_SecurityTokenRegistry.generateSecurityToken(name2, "DET3", decimals, tokenDetails, false, { from: token_owner, gas:5000000 });

// Verify the successful generation of the security token
assert.equal(tx.logs[1].args._ticker, "DET3", "SecurityToken doesn't get deployed");
Expand Down