Skip to content

Commit

Permalink
Add treasury wallet in global storage (#555)
Browse files Browse the repository at this point in the history
* add treasury wallet in global storage

* change in the dataStore authorization

* fix tests

* change string to hex

* minor fixes

* remove modifier from data store

* add minor comment

* add generateSecurityTokenWithTreasury to maintain backwards compatibility

* minor fixes

* not allowing 0x0 address to be treasury wallet

* add event

* minor fix

* small change to fix the coverage

* remove the function from the interface

* minor fixes
  • Loading branch information
satyamakgec authored and adamdossa committed Mar 6, 2019
1 parent a2e8b17 commit 84f01b0
Show file tree
Hide file tree
Showing 46 changed files with 357 additions and 212 deletions.
7 changes: 6 additions & 1 deletion contracts/SecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
* @param _ticker is the ticker symbol of the security token
* @param _tokenDetails is the off-chain details of the token
* @param _divisible is whether or not the token is divisible
* @param _treasuryWallet Ethereum address which will holds the STs.
* @param _protocolVersion Version of securityToken contract
* - `_protocolVersion` is the packed value of uin8[3] array (it will be calculated offchain)
* - if _protocolVersion == 0 then latest version of securityToken will be generated
Expand All @@ -497,13 +498,15 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
string calldata _ticker,
string calldata _tokenDetails,
bool _divisible,
address _treasuryWallet,
uint256 _protocolVersion
)
external
whenNotPausedOrOwner
{
uint256 protocolVersion = _protocolVersion;
require(bytes(_name).length > 0 && bytes(_ticker).length > 0, "Bad ticker");
require(_treasuryWallet != address(0), "0x0 not allowed");
if (_protocolVersion == 0) {
protocolVersion = getUintValue(Encoder.getKey("latestVersion"));
}
Expand All @@ -515,7 +518,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
require(_tickerOwner(ticker) == msg.sender, "Not authorised");
/*solium-disable-next-line security/no-block-members*/
require(getUintValue(Encoder.getKey("registeredTickers_expiryDate", ticker)) >= now, "Ticker expired");
_deployToken(_name, ticker, _tokenDetails, msg.sender, _divisible, protocolVersion);
_deployToken(_name, ticker, _tokenDetails, msg.sender, _divisible, _treasuryWallet, protocolVersion);
}

function _deployToken(
Expand All @@ -524,6 +527,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
string memory _tokenDetails,
address _issuer,
bool _divisible,
address _wallet,
uint256 _protocolVersion
)
internal
Expand All @@ -536,6 +540,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
_tokenDetails,
_issuer,
_divisible,
_wallet,
getAddressValue(POLYMATHREGISTRY)
);

Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/ISTFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ISTFactory {
* @param _tokenDetails is the off-chain data associated with the Security Token
* @param _issuer is the owner of the Security Token
* @param _divisible whether the token is divisible or not
* @param _treasuryWallet Ethereum address which will holds the STs.
* @param _polymathRegistry is the address of the Polymath Registry contract
*/
function deployToken(
Expand All @@ -22,6 +23,7 @@ interface ISTFactory {
string calldata _tokenDetails,
address _issuer,
bool _divisible,
address _treasuryWallet,
address _polymathRegistry
)
external
Expand Down
3 changes: 3 additions & 0 deletions contracts/interfaces/ISecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ pragma solidity ^0.5.0;
* @title Interface for the Polymath Security Token Registry contract
*/
interface ISecurityTokenRegistry {

/**
* @notice Deploys an instance of a new Security Token and records it to the registry
* @param _name is the name of the token
* @param _ticker is the ticker symbol of the security token
* @param _tokenDetails is the off-chain details of the token
* @param _divisible is whether or not the token is divisible
* @param _treasuryWallet Ethereum address which will holds the STs.
* @param _protocolVersion Version of securityToken contract
* - `_protocolVersion` is the packed value of uin8[3] array (it will be calculated offchain)
* - if _protocolVersion == 0 then latest version of securityToken will be generated
Expand All @@ -19,6 +21,7 @@ interface ISecurityTokenRegistry {
string calldata _ticker,
string calldata _tokenDetails,
bool _divisible,
address _treasuryWallet,
uint256 _protocolVersion
) external;

Expand Down
2 changes: 2 additions & 0 deletions contracts/mocks/STFactoryMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract STFactoryMock is ISTFactory {
string calldata _tokenDetails,
address _issuer,
bool _divisible,
address _treasuryWallet,
address _polymathRegistry
)
external
Expand All @@ -45,6 +46,7 @@ contract STFactoryMock is ISTFactory {
);
//NB When dataStore is generated, the security token address is automatically set via the constructor in DataStoreProxy.
newSecurityToken.changeDataStore(dataStoreFactory.generateDataStore(address(newSecurityToken)));
newSecurityToken.changeTreasuryWallet(_treasuryWallet);
newSecurityToken.addModule(transferManagerFactory, "", 0, 0);
newSecurityToken.transferOwnership(_issuer);
return address(newSecurityToken);
Expand Down
14 changes: 13 additions & 1 deletion contracts/modules/Checkpoint/DividendCheckpoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module {
}

function _setWallet(address payable _wallet) internal {
require(_wallet != address(0));
emit SetWallet(wallet, _wallet);
wallet = _wallet;
}
Expand All @@ -75,6 +74,19 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module {
return excluded;
}

/**
* @notice Returns the treasury wallet address
*/
function getTreasuryWallet() public view returns(address payable) {
if (wallet == address(0)) {
address payable treasuryWallet = address(uint160(IDataStore(getDataStore()).getAddress(TREASURY)));
require(address(treasuryWallet) != address(0), "Invalid address");
return treasuryWallet;
}
else
return wallet;
}

/**
* @notice Creates a checkpoint on the security token
* @return Checkpoint ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ contract ERC20DividendCheckpoint is ERC20DividendCheckpointStorage, DividendChec
dividends[_dividendIndex].reclaimed = true;
Dividend storage dividend = dividends[_dividendIndex];
uint256 remainingAmount = dividend.amount.sub(dividend.claimedAmount);
require(IERC20(dividendTokens[_dividendIndex]).transfer(wallet, remainingAmount), "transfer failed");
require(IERC20(dividendTokens[_dividendIndex]).transfer(getTreasuryWallet(), remainingAmount), "transfer failed");
emit ERC20DividendReclaimed(wallet, _dividendIndex, dividendTokens[_dividendIndex], remainingAmount);
}

Expand All @@ -270,7 +270,7 @@ contract ERC20DividendCheckpoint is ERC20DividendCheckpointStorage, DividendChec
Dividend storage dividend = dividends[_dividendIndex];
uint256 remainingWithheld = dividend.totalWithheld.sub(dividend.totalWithheldWithdrawn);
dividend.totalWithheldWithdrawn = dividend.totalWithheld;
require(IERC20(dividendTokens[_dividendIndex]).transfer(wallet, remainingWithheld), "transfer failed");
require(IERC20(dividendTokens[_dividendIndex]).transfer(getTreasuryWallet(), remainingWithheld), "transfer failed");
emit ERC20DividendWithholdingWithdrawn(wallet, _dividendIndex, dividendTokens[_dividendIndex], remainingWithheld);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ contract EtherDividendCheckpoint is DividendCheckpoint {
Dividend storage dividend = dividends[_dividendIndex];
dividend.reclaimed = true;
uint256 remainingAmount = dividend.amount.sub(dividend.claimedAmount);
address payable wallet = getTreasuryWallet();
wallet.transfer(remainingAmount);
emit EtherDividendReclaimed(wallet, _dividendIndex, remainingAmount);
}
Expand All @@ -210,6 +211,7 @@ contract EtherDividendCheckpoint is DividendCheckpoint {
Dividend storage dividend = dividends[_dividendIndex];
uint256 remainingWithheld = dividend.totalWithheld.sub(dividend.totalWithheldWithdrawn);
dividend.totalWithheldWithdrawn = dividend.totalWithheld;
address payable wallet = getTreasuryWallet();
wallet.transfer(remainingWithheld);
emit EtherDividendWithholdingWithdrawn(wallet, _dividendIndex, remainingWithheld);
}
Expand Down
24 changes: 19 additions & 5 deletions contracts/modules/Experimental/Wallet/VestingEscrowWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ contract VestingEscrowWallet is VestingEscrowWalletStorage, Wallet {
* @notice This function returns the signature of the configure function
*/
function getInitFunction() public pure returns (bytes4) {
return bytes4(keccak256("configure(address)"));
return this.configure.selector;
}

/**
* @notice Used to initialize the treasury wallet address
* @param _treasuryWallet Address of the treasury wallet
*/
function configure(address _treasuryWallet) public onlyFactory {
require(_treasuryWallet != address(0), "Invalid address");
treasuryWallet = _treasuryWallet;
_setWallet(_treasuryWallet);
}

/**
Expand All @@ -75,7 +74,10 @@ contract VestingEscrowWallet is VestingEscrowWalletStorage, Wallet {
*/
function changeTreasuryWallet(address _newTreasuryWallet) public {
_onlySecurityTokenOwner();
require(_newTreasuryWallet != address(0));
_setWallet(_newTreasuryWallet);
}

function _setWallet(address _newTreasuryWallet) internal {
emit TreasuryWalletChanged(_newTreasuryWallet, treasuryWallet);
treasuryWallet = _newTreasuryWallet;
}
Expand Down Expand Up @@ -107,10 +109,22 @@ contract VestingEscrowWallet is VestingEscrowWalletStorage, Wallet {
require(_amount <= unassignedTokens, "Amount is greater than unassigned tokens");
uint256 amount = unassignedTokens;
unassignedTokens = 0;
require(ISecurityToken(securityToken).transfer(treasuryWallet, amount), "Transfer failed");
require(ISecurityToken(securityToken).transfer(getTreasuryWallet(), amount), "Transfer failed");
emit SendToTreasury(amount, msg.sender);
}

/**
* @notice Returns the treasury wallet address
*/
function getTreasuryWallet() public view returns(address) {
if (treasuryWallet == address(0)) {
address wallet = IDataStore(getDataStore()).getAddress(TREASURY);
require(wallet != address(0), "Invalid address");
return wallet;
} else
return treasuryWallet;
}

/**
* @notice Pushes available tokens to the beneficiary's address
* @param _beneficiary Address of the beneficiary who will receive tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract VestingEscrowWalletFactory is UpgradableModuleFactory {
*/
function types() external view returns(uint8[] memory) {
uint8[] memory res = new uint8[](1);
res[0] = 6;
res[0] = 7;
return res;
}

Expand Down
Loading

0 comments on commit 84f01b0

Please sign in to comment.