Skip to content

Commit 9b10da1

Browse files
authored
Merge pull request #553 from PolymathNetwork/upgradable-modules
Upgradable modules
2 parents 3613255 + b83785c commit 9b10da1

File tree

112 files changed

+1264
-1241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1264
-1241
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
2121
* Replaced `updatePolyTokenAddress()` function with `updateFromRegistry()` in `SecurityTokenRegistry`.
2222
* Migrate all the getters of `SecurityTokenRegsitry.sol` to `STRGetter.sol` contract.
2323
* Removed `_polyToken` parameter from `initialize` function in `SecurityTokenRegistry`.
24+
* Return SecurityToken version in the `getSecurityTokenData()` function.
2425

2526
## GeneralTransferManager
2627
* `modifyWhitelist()` function renamed to `modifyKYCData()`.

contracts/ModuleRegistry.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
137137

138138
function _isCompatibleModule(address _moduleFactory, address _securityToken) internal view returns(bool) {
139139
uint8[] memory _latestVersion = ISecurityToken(_securityToken).getVersion();
140-
uint8[] memory _lowerBound = IModuleFactory(_moduleFactory).getLowerSTVersionBounds();
141-
uint8[] memory _upperBound = IModuleFactory(_moduleFactory).getUpperSTVersionBounds();
140+
uint8[] memory _lowerBound = IModuleFactory(_moduleFactory).lowerSTVersionBounds();
141+
uint8[] memory _upperBound = IModuleFactory(_moduleFactory).upperSTVersionBounds();
142142
bool _isLowerAllowed = VersionUtils.compareLowerBound(_lowerBound, _latestVersion);
143143
bool _isUpperAllowed = VersionUtils.compareUpperBound(_upperBound, _latestVersion);
144144
return (_isLowerAllowed && _isUpperAllowed);
@@ -162,15 +162,15 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
162162
//Enforce type uniqueness
163163
uint256 i;
164164
uint256 j;
165-
uint8[] memory moduleTypes = moduleFactory.getTypes();
165+
uint8[] memory moduleTypes = moduleFactory.types();
166166
for (i = 1; i < moduleTypes.length; i++) {
167167
for (j = 0; j < i; j++) {
168168
require(moduleTypes[i] != moduleTypes[j], "Type mismatch");
169169
}
170170
}
171171
require(moduleTypes.length != 0, "Factory must have type");
172172
// NB - here we index by the first type of the module.
173-
uint8 moduleType = moduleFactory.getTypes()[0];
173+
uint8 moduleType = moduleFactory.types()[0];
174174
set(Encoder.getKey("registry", _moduleFactory), uint256(moduleType));
175175
set(
176176
Encoder.getKey("moduleListIndex", _moduleFactory),
@@ -263,14 +263,14 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
263263
uint256 i;
264264
uint256 j;
265265
for (i = 0; i < _modules.length; i++) {
266-
counter = counter + IModuleFactory(_modules[i]).getTags().length;
266+
counter = counter + IModuleFactory(_modules[i]).tags().length;
267267
}
268268
bytes32[] memory tags = new bytes32[](counter);
269269
address[] memory modules = new address[](counter);
270270
bytes32[] memory tempTags;
271271
counter = 0;
272272
for (i = 0; i < _modules.length; i++) {
273-
tempTags = IModuleFactory(_modules[i]).getTags();
273+
tempTags = IModuleFactory(_modules[i]).tags();
274274
for (j = 0; j < tempTags.length; j++) {
275275
tags[counter] = tempTags[j];
276276
modules[counter] = _modules[i];

contracts/STRGetter.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pragma solidity ^0.5.0;
22

33
import "./storage/EternalStorage.sol";
4+
import "./interfaces/ISecurityToken.sol";
45
import "./libraries/Util.sol";
56
import "./libraries/Encoder.sol";
67
import "./interfaces/IOwnable.sol";
@@ -199,13 +200,15 @@ contract STRGetter is EternalStorage {
199200
* @return address is the issuer of the security Token.
200201
* @return string is the details of the security token.
201202
* @return uint256 is the timestamp at which security Token was deployed.
203+
* @return version of the securityToken
202204
*/
203-
function getSecurityTokenData(address _securityToken) external view returns (string memory, address, string memory, uint256) {
205+
function getSecurityTokenData(address _securityToken) external view returns (string memory, address, string memory, uint256, uint8[] memory) {
204206
return (
205207
getStringValue(Encoder.getKey("securityTokens_ticker", _securityToken)),
206208
IOwnable(_securityToken).owner(),
207209
getStringValue(Encoder.getKey("securityTokens_tokenDetails", _securityToken)),
208-
getUintValue(Encoder.getKey("securityTokens_deployedAt", _securityToken))
210+
getUintValue(Encoder.getKey("securityTokens_deployedAt", _securityToken)),
211+
ISecurityToken(_securityToken).getVersion()
209212
);
210213
}
211214

contracts/interfaces/IModule.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ interface IModule {
1717
/**
1818
* @notice Used to withdraw the fee by the factory owner
1919
*/
20-
function takeFee(uint256 _amount) external returns(bool);
20+
function takeUsageFee() external returns(bool);
2121

2222
}

contracts/interfaces/IModuleFactory.sol

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,52 @@ interface IModuleFactory {
1212
address indexed _moduleFactory,
1313
address _creator,
1414
uint256 _setupCost,
15-
uint256 _setupCostInPoly,
16-
uint256 _timestamp
15+
uint256 _setupCostInPoly
1716
);
1817
event ChangeSTVersionBound(string _boundType, uint8 _major, uint8 _minor, uint8 _patch);
1918

2019
//Should create an instance of the Module, or throw
2120
function deploy(bytes calldata _data) external returns(address);
2221

2322
/**
24-
* @notice Type of the Module factory
23+
* @notice Get the tags related to the module factory
24+
*/
25+
function version() external view returns(string memory);
26+
27+
/**
28+
* @notice Get the tags related to the module factory
29+
*/
30+
function name() external view returns(bytes32);
31+
32+
/**
33+
* @notice Returns the title associated with the module
2534
*/
26-
function getTypes() external view returns(uint8[] memory);
35+
function title() external view returns(string memory);
2736

2837
/**
29-
* @notice Get the name of the Module
38+
* @notice Returns the description associated with the module
3039
*/
31-
function getName() external view returns(bytes32);
40+
function description() external view returns(string memory);
3241

3342
/**
34-
* @notice Returns the instructions associated with the module
43+
* @notice Get the setup cost of the module in USD
44+
*/
45+
function usageCost() external returns(uint256);
46+
47+
/**
48+
* @notice Get the setup cost of the module in USD
49+
*/
50+
function setupCost() external returns(uint256);
51+
52+
/**
53+
* @notice Type of the Module factory
3554
*/
36-
function getInstructions() external view returns(string memory);
55+
function types() external view returns(uint8[] memory);
3756

3857
/**
3958
* @notice Get the tags related to the module factory
4059
*/
41-
function getTags() external view returns(bytes32[] memory);
60+
function tags() external view returns(bytes32[] memory);
4261

4362
/**
4463
* @notice Used to change the setup fee
@@ -62,23 +81,23 @@ interface IModuleFactory {
6281
/**
6382
* @notice Get the setup cost of the module in USD
6483
*/
65-
function getSetupCost() external view returns(uint256);
84+
function usageCostInPoly() external returns(uint256);
6685

6786
/**
6887
* @notice Get the setup cost of the module
6988
*/
70-
function getSetupCostInPoly() external returns (uint256);
89+
function setupCostInPoly() external returns (uint256);
7190

7291
/**
7392
* @notice Used to get the lower bound
7493
* @return Lower bound
7594
*/
76-
function getLowerSTVersionBounds() external view returns(uint8[] memory);
95+
function lowerSTVersionBounds() external view returns(uint8[] memory);
7796

7897
/**
7998
* @notice Used to get the upper bound
8099
* @return Upper bound
81100
*/
82-
function getUpperSTVersionBounds() external view returns(uint8[] memory);
101+
function upperSTVersionBounds() external view returns(uint8[] memory);
83102

84103
}

contracts/interfaces/ISecurityTokenRegistry.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ interface ISecurityTokenRegistry {
7979
* @return string Symbol of the Security Token.
8080
* @return address Address of the issuer of Security Token.
8181
* @return string Details of the Token.
82-
* @return uint256 Timestamp at which Security Token get launched on Polymath platform.
82+
* @return uint256 Timestamp at which Security Token get launched on Polymath platform
83+
* @return version of the securityToken
8384
*/
84-
function getSecurityTokenData(address _securityToken) external view returns(string memory, address, string memory, uint256);
85+
function getSecurityTokenData(address _securityToken) external view returns(string memory, address, string memory, uint256, uint8[] memory);
8586

8687
/**
8788
* @notice Get the current STFactory Address

contracts/libraries/TokenLib.sol

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pragma solidity ^0.5.0;
22

33
import "../interfaces/IPoly.sol";
4+
import "../modules/UpgradableModuleFactory.sol";
45
import "../interfaces/IDataStore.sol";
56
import "../tokens/SecurityTokenStorage.sol";
67
import "../interfaces/ITransferManager.sol";
@@ -14,6 +15,8 @@ library TokenLib {
1415
bytes32 internal constant WHITELIST = "WHITELIST";
1516
bytes32 internal constant INVESTORSKEY = 0xdf3a8dd24acdd05addfc6aeffef7574d2de3f844535ec91e8e0f3e45dba96731; //keccak256(abi.encodePacked("INVESTORS"))
1617

18+
// Emit when Module get upgraded from the securityToken
19+
event ModuleUpgraded(uint8[] _types, address _module);
1720
// Emit when Module is archived from the SecurityToken
1821
event ModuleArchived(uint8[] _types, address _module);
1922
// Emit when Module is unarchived from the SecurityToken
@@ -26,28 +29,37 @@ library TokenLib {
2629
/**
2730
* @notice Archives a module attached to the SecurityToken
2831
* @param _moduleData Storage data
29-
* @param _module Address of module to archive
3032
*/
31-
function archiveModule(SecurityTokenStorage.ModuleData storage _moduleData, address _module) public {
33+
function archiveModule(SecurityTokenStorage.ModuleData storage _moduleData) public {
3234
require(!_moduleData.isArchived, "Module archived");
3335
require(_moduleData.module != address(0), "Module missing");
3436
/*solium-disable-next-line security/no-block-members*/
35-
emit ModuleArchived(_moduleData.moduleTypes, _module);
37+
emit ModuleArchived(_moduleData.moduleTypes, _moduleData.module);
3638
_moduleData.isArchived = true;
3739
}
3840

3941
/**
4042
* @notice Unarchives a module attached to the SecurityToken
4143
* @param _moduleData Storage data
42-
* @param _module Address of module to unarchive
4344
*/
44-
function unarchiveModule(SecurityTokenStorage.ModuleData storage _moduleData, address _module) public {
45+
function unarchiveModule(SecurityTokenStorage.ModuleData storage _moduleData) public {
4546
require(_moduleData.isArchived, "Module unarchived");
4647
/*solium-disable-next-line security/no-block-members*/
47-
emit ModuleUnarchived(_moduleData.moduleTypes, _module);
48+
emit ModuleUnarchived(_moduleData.moduleTypes, _moduleData.module);
4849
_moduleData.isArchived = false;
4950
}
5051

52+
/**
53+
* @notice Upgrades a module attached to the SecurityToken
54+
* @param _moduleData Storage data
55+
*/
56+
function upgradeModule(SecurityTokenStorage.ModuleData storage _moduleData) public {
57+
require(_moduleData.module != address(0), "Module missing");
58+
// Will revert if module isn't upgradable
59+
UpgradableModuleFactory(_moduleData.moduleFactory).upgrade(_moduleData.module);
60+
emit ModuleUpgraded(_moduleData.moduleTypes, _moduleData.module);
61+
}
62+
5163
/**
5264
* @notice Removes a module attached to the SecurityToken
5365
* @param _module address of module to unarchive
@@ -259,11 +271,11 @@ library TokenLib {
259271
uint256 value,
260272
bytes memory data,
261273
bool transfersFrozen
262-
)
263-
public
274+
)
275+
public
264276
view
265-
returns(bool, bytes32)
266-
{
277+
returns(bool, bytes32)
278+
{
267279
if (!transfersFrozen) {
268280
bool isInvalid = false;
269281
bool isValid = false;

0 commit comments

Comments
 (0)