From 6890efc048156349e1117c035a9fdbea38f20a4c Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 20:21:32 -0700 Subject: [PATCH 01/57] VestingWallet skeleton with initiate and cancel --- .../VestingEscrowWallet/VestingWallet.sol | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 contracts/modules/VestingEscrowWallet/VestingWallet.sol diff --git a/contracts/modules/VestingEscrowWallet/VestingWallet.sol b/contracts/modules/VestingEscrowWallet/VestingWallet.sol new file mode 100644 index 000000000..948d0e7ad --- /dev/null +++ b/contracts/modules/VestingEscrowWallet/VestingWallet.sol @@ -0,0 +1,196 @@ +pragma solidity ^0.4.24; + +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; + +/** + * @title Escrow wallet for distributing tokens on a vesting schedule + */ +contract VestingWallet is Ownable { + using SafeMath for uint; + + bytes32 public constant ISSUER = "ISSUER"; + address public securityToken; + + struct VestingSchedule { + // ID of the vesting schedule + bytes32 vestingId; + // Total number of vesting tokens at start of vesting period + uint256 totalAllocation; + // Length of the vesting period + uint256 vestingDuration; + // Start date of vesting schedule + uint256 startDate; + // Vesting frequency of the tokens + uint256 vestingFrequency; + // Total number of tokens released to the target + uint256 totalTokensReleased; + // Total number of tokens remaining to collect + uint256 totalTokensRemaining; + // Number of tokens to release to the target per period + uint256 tokensPerPeriod; + } + + mapping(address => uint256) public individualVestingCount; + mapping(address => mapping(uint256 => VestingSchedule)) public individualVestingDetails; + + /* Events */ + event VestingStarted( + address indexed target, + bytes32 indexed vestingId, + uint256 indexed totalAllocation, + uint256 vestingDuration, + uint256 startDate, + uint256 vestingFrequency, + uint256 totalTokensReleased, + uint256 totalTokensRemaining, + uint256 tokensPerPeriod + ); + + event VestingCancelled( + address indexed target, + uint256 indexed whichVestingShedule, + bytes32 indexed vestingId, + uint256 tokensCollected, + uint256 cancellationTime + ); + + event TokensCollected( + address indexed target, + uint256 indexed whichVestingShedule, + bytes32 indexed vestingId, + uint256 numberTokensCollected + ); + + /** + * @notice Constructor + * @param _securityToken Address of the security token + * @param _polyAddress Address of the polytoken + */ + // constructor (address _securityToken, address _polyAddress) + // public + // Module(_securityToken, _polyAddress) + // { + // } + + /** + * @notice Function used to intialize the differnet variables + * @param _startTime Unix timestamp at which offering get started + * @param _endTime Unix timestamp at which offering get ended + * @param _cap Maximum No. of tokens for sale + * @param _someString Any string that contails the details + */ + // function configure(uint256 _startTime, uint256 _endTime, uint256 _cap, string _someString) public onlyFactory { + // startTime = _startTime; + // endTime = _endTime; + // cap = _cap; + // someString = _someString; + // } + + /** + * @notice This function returns the signature of configure function + */ + // function getInitFunction() public pure returns (bytes4) { + // return bytes4(keccak256("configure(uint256,uint256,uint256,string)")); + // } + + /** + * @notice Initiate a vesting schedule for an employee or affiliate + * @param _target Address of the employee or the affiliate + * @param _totalAllocation Total number of tokens allocated for the target + * @param _vestingDuration Total duration of the vesting schedule + * @param _startDate Start date of the vesting schedule + * @param _vestingFrequency Frequency of release of tokens + */ + function initiateVestingSchedule( + address _target, + uint256 _totalAllocation, + uint256 _vestingDuration, + uint256 _startDate, + uint256 _vestingFrequency + ) + public + onlyOwner + { + require(_target != address(0), "The target should be a valid addrss"); + require(_totalAllocation != 0, "The total allocation should not be 0"); + require(_vestingDuration != 0, "The vestingDuration should not be 0"); + require(_startDate >= now, "The starting date should be after now"); + require( + _vestingFrequency != 0 && _vestingFrequency <= _vestingDuration, + "The vestingFrequency should not be 0 and it should be less than the duration"); + require(_vestingDuration % _vestingFrequency == 0, "The vesting frequency should be a multiple of the vesting duration"); + // require(securityToken.balanceOf[address(this)] >= _totalAllocation, "Tokens must have been already sent to the smart contract"); + + uint256 _numPeriods = _vestingDuration.div(_vestingFrequency); + uint256 _tokensPerPeriod = _totalAllocation.div(_numPeriods); // TODO: Edge cases/truncation. If uneven, take this into account. I asked on Github + + bytes32 _vestingId = keccak256( + abi.encodePacked( + block.timestamp, + _target, + _totalAllocation, + _vestingDuration, + _startDate, + _vestingFrequency + ) + ); + + uint256 _individualVestingCount = individualVestingCount[_target]; + individualVestingCount[_target] += 1; + + uint256 _totalTokensReleased = 0; + uint256 _totalTokensRemaining = _totalAllocation; + + individualVestingDetails[_target][_individualVestingCount] = VestingSchedule({ + vestingId: _vestingId, + totalAllocation: _totalAllocation, + vestingDuration: _vestingDuration, + startDate: _startDate, + vestingFrequency: _vestingFrequency, + totalTokensReleased: _totalTokensReleased, + totalTokensRemaining: _totalTokensRemaining, + tokensPerPeriod: _tokensPerPeriod + }); + + emit VestingStarted( + _target, + _vestingId, + _totalAllocation, + _vestingDuration, + _startDate, + _vestingFrequency, + _totalTokensReleased, + _totalTokensRemaining, + _tokensPerPeriod + ); + } + + /** + * @notice Cancel a vesting schedule for an employee or affiliate + * @param _target Address of the employee or the affiliate + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule) + public + onlyOwner + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); + + bytes32 _vestingId = _vestingSchedule.vestingId; + uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; + delete individualVestingDetails[_target][_whichVestingSchedule]; // TODO: Change this to a flag depending on Github response + + emit VestingCancelled( + _target, + _whichVestingSchedule, + _vestingId, + _tokensCollected, + block.timestamp + ); + + // TODO: Return tokens to issuer. Asked what to do on Github + } +} From 2d47fe6d3740f43670c4acd77a188d420e31b567 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 20:51:57 -0700 Subject: [PATCH 02/57] Add collectTokens --- .../VestingEscrowWallet/VestingWallet.sol | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/contracts/modules/VestingEscrowWallet/VestingWallet.sol b/contracts/modules/VestingEscrowWallet/VestingWallet.sol index 948d0e7ad..158293d01 100644 --- a/contracts/modules/VestingEscrowWallet/VestingWallet.sol +++ b/contracts/modules/VestingEscrowWallet/VestingWallet.sol @@ -177,7 +177,7 @@ contract VestingWallet is Ownable { { VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. bytes32 _vestingId = _vestingSchedule.vestingId; uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; @@ -193,4 +193,51 @@ contract VestingWallet is Ownable { // TODO: Return tokens to issuer. Asked what to do on Github } + + /** + * @notice Collect vested tokens + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function collectTokens(uint256 _whichVestingSchedule) + public + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + + uint256 currentPeriod = _calculateCurrentPeriod(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 tokensToDistribute = _calculateTokensToDistribute(currentPeriod, _vestingSchedule.tokensPerPeriod, _vestingSchedule.totalTokensReleased); + + _vestingSchedule.totalTokensReleased += tokensToDistribute; + _vestingSchedule.totalTokensRemaining -= tokensToDistribute; + + // TODO: Send tokens to target. + } + + function _calculateCurrentPeriod( + uint256 _startDate, + uint256 _vestingDuration + ) + internal + view + returns (uint256) + { + return now < _startDate + ? 0 + : (now.sub(_startDate)).div(_vestingDuration); + } + + function _calculateTokensToDistribute( + uint256 _currentPeriod, + uint256 _tokensPerPeriod, + uint256 _totalTokensReleased + ) + internal + view + returns (uint256) + { + uint256 _tokensToDistribute = _currentPeriod.mul(_tokensPerPeriod); + return _tokensToDistribute.sub(_totalTokensReleased); + } } From c1c60bbcd5949dbee76e4254f08a4d25d5680f2c Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 21:02:33 -0700 Subject: [PATCH 03/57] Add ability to bulk upload vesting schedules for users --- .../VestingEscrowWallet/VestingWallet.sol | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/contracts/modules/VestingEscrowWallet/VestingWallet.sol b/contracts/modules/VestingEscrowWallet/VestingWallet.sol index 158293d01..7a1573111 100644 --- a/contracts/modules/VestingEscrowWallet/VestingWallet.sol +++ b/contracts/modules/VestingEscrowWallet/VestingWallet.sol @@ -94,6 +94,37 @@ contract VestingWallet is Ownable { // return bytes4(keccak256("configure(uint256,uint256,uint256,string)")); // } + /** + * @notice Initiate a vesting schedule for any number of employees or affiliates + * @param _target Address of the employee or the affiliate + * @param _totalAllocation Total number of tokens allocated for the target + * @param _vestingDuration Total duration of the vesting schedule + * @param _startDate Start date of the vesting schedule + * @param _vestingFrequency Frequency of release of tokens + */ function initiateVestingSchedule( + address[] _target, + uint256[] _totalAllocation, + uint256[] _vestingDuration, + uint256[] _startDate, + uint256[] _vestingFrequency + ) + public + onlyOwner + { + require(_target.length == _totalAllocation.length && + _target.length == _vestingDuration.length && + _target.length == _startDate.length && + _target.length == _vestingFrequency.length); + + for (uint i = 0; i <= _target.length; i++) { + _initiateVestingScheduleIterate(_target[i], + _totalAllocation[i], + _vestingDuration[i], + _startDate[i], + _vestingFrequency[i]); + } + } + /** * @notice Initiate a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate @@ -102,15 +133,14 @@ contract VestingWallet is Ownable { * @param _startDate Start date of the vesting schedule * @param _vestingFrequency Frequency of release of tokens */ - function initiateVestingSchedule( + function _initiateVestingScheduleIterate( address _target, uint256 _totalAllocation, uint256 _vestingDuration, uint256 _startDate, uint256 _vestingFrequency ) - public - onlyOwner + internal { require(_target != address(0), "The target should be a valid addrss"); require(_totalAllocation != 0, "The total allocation should not be 0"); From ba10ad0752112d136aef34f144f2b26e39c34962 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 21:03:06 -0700 Subject: [PATCH 04/57] Formatting fix --- contracts/modules/VestingEscrowWallet/VestingWallet.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/modules/VestingEscrowWallet/VestingWallet.sol b/contracts/modules/VestingEscrowWallet/VestingWallet.sol index 7a1573111..3e0d1e8b0 100644 --- a/contracts/modules/VestingEscrowWallet/VestingWallet.sol +++ b/contracts/modules/VestingEscrowWallet/VestingWallet.sol @@ -108,8 +108,8 @@ contract VestingWallet is Ownable { uint256[] _startDate, uint256[] _vestingFrequency ) - public - onlyOwner + public + onlyOwner { require(_target.length == _totalAllocation.length && _target.length == _vestingDuration.length && From 1048cc0c2897a3c1ff59e97d3d0f4f42411bd21e Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 21:25:12 -0700 Subject: [PATCH 05/57] Add comments, formatting, and a small refactor --- .../VestingEscrowWallet/VestingWallet.sol | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/contracts/modules/VestingEscrowWallet/VestingWallet.sol b/contracts/modules/VestingEscrowWallet/VestingWallet.sol index 3e0d1e8b0..b89187b6e 100644 --- a/contracts/modules/VestingEscrowWallet/VestingWallet.sol +++ b/contracts/modules/VestingEscrowWallet/VestingWallet.sol @@ -27,8 +27,8 @@ contract VestingWallet is Ownable { uint256 totalTokensReleased; // Total number of tokens remaining to collect uint256 totalTokensRemaining; - // Number of tokens to release to the target per period - uint256 tokensPerPeriod; + // Number of tokens to release to the target per tranche + uint256 tokensPerTranche; } mapping(address => uint256) public individualVestingCount; @@ -44,7 +44,7 @@ contract VestingWallet is Ownable { uint256 vestingFrequency, uint256 totalTokensReleased, uint256 totalTokensRemaining, - uint256 tokensPerPeriod + uint256 tokensPerTranche ); event VestingCancelled( @@ -101,7 +101,8 @@ contract VestingWallet is Ownable { * @param _vestingDuration Total duration of the vesting schedule * @param _startDate Start date of the vesting schedule * @param _vestingFrequency Frequency of release of tokens - */ function initiateVestingSchedule( + */ + function initiateVestingSchedule( address[] _target, uint256[] _totalAllocation, uint256[] _vestingDuration, @@ -152,8 +153,8 @@ contract VestingWallet is Ownable { require(_vestingDuration % _vestingFrequency == 0, "The vesting frequency should be a multiple of the vesting duration"); // require(securityToken.balanceOf[address(this)] >= _totalAllocation, "Tokens must have been already sent to the smart contract"); - uint256 _numPeriods = _vestingDuration.div(_vestingFrequency); - uint256 _tokensPerPeriod = _totalAllocation.div(_numPeriods); // TODO: Edge cases/truncation. If uneven, take this into account. I asked on Github + uint256 _numTranches = _vestingDuration.div(_vestingFrequency); + uint256 _tokensPerTranche = _totalAllocation.div(_numTranches); // TODO: Edge cases/truncation. If uneven, take this into account. I asked on Github bytes32 _vestingId = keccak256( abi.encodePacked( @@ -180,7 +181,7 @@ contract VestingWallet is Ownable { vestingFrequency: _vestingFrequency, totalTokensReleased: _totalTokensReleased, totalTokensRemaining: _totalTokensRemaining, - tokensPerPeriod: _tokensPerPeriod + tokensPerTranche: _tokensPerTranche }); emit VestingStarted( @@ -192,8 +193,10 @@ contract VestingWallet is Ownable { _vestingFrequency, _totalTokensReleased, _totalTokensRemaining, - _tokensPerPeriod + _tokensPerTranche ); + + // Send tokens to contract here (see lucidchart -> assumptions -> 2) } /** @@ -236,8 +239,8 @@ contract VestingWallet is Ownable { require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - uint256 currentPeriod = _calculateCurrentPeriod(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 tokensToDistribute = _calculateTokensToDistribute(currentPeriod, _vestingSchedule.tokensPerPeriod, _vestingSchedule.totalTokensReleased); + uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); _vestingSchedule.totalTokensReleased += tokensToDistribute; _vestingSchedule.totalTokensRemaining -= tokensToDistribute; @@ -245,7 +248,14 @@ contract VestingWallet is Ownable { // TODO: Send tokens to target. } - function _calculateCurrentPeriod( + // TODO: May need to push tokens as well. Asked on Github. + + /** + * @notice Calculate the current tranche the user is on + * @param _startDate Start date of the vesting period + * @param _vestingDuration Total duration of the vesting schedule + */ + function _calculateCurrentTranche( uint256 _startDate, uint256 _vestingDuration ) @@ -258,16 +268,22 @@ contract VestingWallet is Ownable { : (now.sub(_startDate)).div(_vestingDuration); } + /** + * @notice Calculate the number of tokens to distribute per transaction + * @param _currentTranche Current tranche of the vesting schedule + * @param _tokensPerTranche Number of tokens to distribute in each tranche + * @param _totalTokensReleased Number of tokens released thus far + */ function _calculateTokensToDistribute( - uint256 _currentPeriod, - uint256 _tokensPerPeriod, + uint256 _currentTranche, + uint256 _tokensPerTranche, uint256 _totalTokensReleased ) internal view returns (uint256) { - uint256 _tokensToDistribute = _currentPeriod.mul(_tokensPerPeriod); + uint256 _tokensToDistribute = _currentTranche.mul(_tokensPerTranche); return _tokensToDistribute.sub(_totalTokensReleased); } } From 6157240ec74d8eb97a4367074e0ceb901f543a2f Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 22:33:48 -0700 Subject: [PATCH 06/57] Add VestingEscrowWalletFactory.sol and refactor --- contracts/modules/Wallet/IWallet.sol | 0 .../modules/Wallet/VestingEscrowWallet.sol | 289 ++++++++++++++++++ .../Wallet/VestingEscrowWalletFactory.sol | 101 ++++++ 3 files changed, 390 insertions(+) create mode 100644 contracts/modules/Wallet/IWallet.sol create mode 100644 contracts/modules/Wallet/VestingEscrowWallet.sol create mode 100644 contracts/modules/Wallet/VestingEscrowWalletFactory.sol diff --git a/contracts/modules/Wallet/IWallet.sol b/contracts/modules/Wallet/IWallet.sol new file mode 100644 index 000000000..e69de29bb diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol new file mode 100644 index 000000000..71eac9b29 --- /dev/null +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -0,0 +1,289 @@ +pragma solidity ^0.4.24; + +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; + +/** + * @title Escrow wallet for distributing tokens on a vesting schedule + */ +contract VestingEscrowWallet is Ownable { + using SafeMath for uint; + + bytes32 public constant ISSUER = "ISSUER"; + address public securityToken; + + struct VestingSchedule { + // ID of the vesting schedule + bytes32 vestingId; + // Total number of vesting tokens at start of vesting period + uint256 totalAllocation; + // Length of the vesting period + uint256 vestingDuration; + // Start date of vesting schedule + uint256 startDate; + // Vesting frequency of the tokens + uint256 vestingFrequency; + // Total number of tokens released to the target + uint256 totalTokensReleased; + // Total number of tokens remaining to collect + uint256 totalTokensRemaining; + // Number of tokens to release to the target per tranche + uint256 tokensPerTranche; + } + + mapping(address => uint256) public individualVestingCount; + mapping(address => mapping(uint256 => VestingSchedule)) public individualVestingDetails; + + /* Events */ + event VestingStarted( + address indexed target, + bytes32 indexed vestingId, + uint256 indexed totalAllocation, + uint256 vestingDuration, + uint256 startDate, + uint256 vestingFrequency, + uint256 totalTokensReleased, + uint256 totalTokensRemaining, + uint256 tokensPerTranche + ); + + event VestingCancelled( + address indexed target, + uint256 indexed whichVestingShedule, + bytes32 indexed vestingId, + uint256 tokensCollected, + uint256 cancellationTime + ); + + event TokensCollected( + address indexed target, + uint256 indexed whichVestingShedule, + bytes32 indexed vestingId, + uint256 numberTokensCollected + ); + + /** + * @notice Constructor + * @param _securityToken Address of the security token + * @param _polyAddress Address of the polytoken + */ + // constructor (address _securityToken, address _polyAddress) + // public + // Module(_securityToken, _polyAddress) + // { + // } + + /** + * @notice Function used to intialize the differnet variables + * @param _startTime Unix timestamp at which offering get started + * @param _endTime Unix timestamp at which offering get ended + * @param _cap Maximum No. of tokens for sale + * @param _someString Any string that contails the details + */ + // function configure(uint256 _startTime, uint256 _endTime, uint256 _cap, string _someString) public onlyFactory { + // startTime = _startTime; + // endTime = _endTime; + // cap = _cap; + // someString = _someString; + // } + + /** + * @notice This function returns the signature of configure function + */ + // function getInitFunction() public pure returns (bytes4) { + // return bytes4(keccak256("configure(uint256,uint256,uint256,string)")); + // } + + /** + * @notice Initiate a vesting schedule for any number of employees or affiliates + * @param _target Address of the employee or the affiliate + * @param _totalAllocation Total number of tokens allocated for the target + * @param _vestingDuration Total duration of the vesting schedule + * @param _startDate Start date of the vesting schedule + * @param _vestingFrequency Frequency of release of tokens + */ + function initiateVestingSchedule( + address[] _target, + uint256[] _totalAllocation, + uint256[] _vestingDuration, + uint256[] _startDate, + uint256[] _vestingFrequency + ) + public + onlyOwner + { + require(_target.length == _totalAllocation.length && + _target.length == _vestingDuration.length && + _target.length == _startDate.length && + _target.length == _vestingFrequency.length); + + for (uint i = 0; i <= _target.length; i++) { + _initiateVestingScheduleIterate(_target[i], + _totalAllocation[i], + _vestingDuration[i], + _startDate[i], + _vestingFrequency[i]); + } + } + + /** + * @notice Initiate a vesting schedule for an employee or affiliate + * @param _target Address of the employee or the affiliate + * @param _totalAllocation Total number of tokens allocated for the target + * @param _vestingDuration Total duration of the vesting schedule + * @param _startDate Start date of the vesting schedule + * @param _vestingFrequency Frequency of release of tokens + */ + function _initiateVestingScheduleIterate( + address _target, + uint256 _totalAllocation, + uint256 _vestingDuration, + uint256 _startDate, + uint256 _vestingFrequency + ) + internal + { + require(_target != address(0), "The target should be a valid addrss"); + require(_totalAllocation != 0, "The total allocation should not be 0"); + require(_vestingDuration != 0, "The vestingDuration should not be 0"); + require(_startDate >= now, "The starting date should be after now"); + require( + _vestingFrequency != 0 && _vestingFrequency <= _vestingDuration, + "The vestingFrequency should not be 0 and it should be less than the duration"); + require(_vestingDuration % _vestingFrequency == 0, "The vesting frequency should be a multiple of the vesting duration"); + // require(securityToken.balanceOf[address(this)] >= _totalAllocation, "Tokens must have been already sent to the smart contract"); + + uint256 _numTranches = _vestingDuration.div(_vestingFrequency); + uint256 _tokensPerTranche = _totalAllocation.div(_numTranches); // TODO: Edge cases/truncation. If uneven, take this into account. I asked on Github + + bytes32 _vestingId = keccak256( + abi.encodePacked( + block.timestamp, + _target, + _totalAllocation, + _vestingDuration, + _startDate, + _vestingFrequency + ) + ); + + uint256 _individualVestingCount = individualVestingCount[_target]; + individualVestingCount[_target] += 1; + + uint256 _totalTokensReleased = 0; + uint256 _totalTokensRemaining = _totalAllocation; + + individualVestingDetails[_target][_individualVestingCount] = VestingSchedule({ + vestingId: _vestingId, + totalAllocation: _totalAllocation, + vestingDuration: _vestingDuration, + startDate: _startDate, + vestingFrequency: _vestingFrequency, + totalTokensReleased: _totalTokensReleased, + totalTokensRemaining: _totalTokensRemaining, + tokensPerTranche: _tokensPerTranche + }); + + emit VestingStarted( + _target, + _vestingId, + _totalAllocation, + _vestingDuration, + _startDate, + _vestingFrequency, + _totalTokensReleased, + _totalTokensRemaining, + _tokensPerTranche + ); + + // Send tokens to contract here (see lucidchart -> assumptions -> 2) + } + + /** + * @notice Cancel a vesting schedule for an employee or affiliate + * @param _target Address of the employee or the affiliate + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule) + public + onlyOwner + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + + bytes32 _vestingId = _vestingSchedule.vestingId; + uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; + delete individualVestingDetails[_target][_whichVestingSchedule]; // TODO: Change this to a flag depending on Github response + + emit VestingCancelled( + _target, + _whichVestingSchedule, + _vestingId, + _tokensCollected, + block.timestamp + ); + + // TODO: Return tokens to issuer. Asked what to do on Github + } + + /** + * @notice Collect vested tokens + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function collectTokens(uint256 _whichVestingSchedule) + public + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + + uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); + + _vestingSchedule.totalTokensReleased += tokensToDistribute; + _vestingSchedule.totalTokensRemaining -= tokensToDistribute; + + // TODO: Send tokens to target. + } + + // TODO: May need to push tokens as well. Asked on Github. + + /** + * @notice Calculate the current tranche the user is on + * @param _startDate Start date of the vesting period + * @param _vestingDuration Total duration of the vesting schedule + */ + function _calculateCurrentTranche( + uint256 _startDate, + uint256 _vestingDuration + ) + internal + view + returns (uint256) + { + return now < _startDate + ? 0 + : (now.sub(_startDate)).div(_vestingDuration); + } + + /** + * @notice Calculate the number of tokens to distribute per transaction + * @param _currentTranche Current tranche of the vesting schedule + * @param _tokensPerTranche Number of tokens to distribute in each tranche + * @param _totalTokensReleased Number of tokens released thus far + */ + function _calculateTokensToDistribute( + uint256 _currentTranche, + uint256 _tokensPerTranche, + uint256 _totalTokensReleased + ) + internal + view + returns (uint256) + { + uint256 _tokensToDistribute = _currentTranche.mul(_tokensPerTranche); + return _tokensToDistribute.sub(_totalTokensReleased); + } +} diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol new file mode 100644 index 000000000..ed7b87b44 --- /dev/null +++ b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol @@ -0,0 +1,101 @@ +pragma solidity ^0.4.24; + +import "./VestingEscrowWallet.sol"; +import "../ModuleFactory.sol"; +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; + +/** + * @title Factory for deploying VotingEscrowWallet + */ +contract VestingEscrowWalletFactory is ModuleFactory { + + /** + * @notice Constructor + * @param _polyAddress Address of the polytoken + */ + constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public + ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost) + { + version = "1.0.0"; + name = "VotingEscrowWallet"; + title = "Voting Escrow Wallet"; + description = "Allows Issuer to program an automated token vesting schedule for employees and/or affiliates so that Tokens get delivered to their wallets as contractually defined."; + } + + /** + * @notice used to launch the Module with the help of factory + * @param _data Data used for the intialization of the module factory variables + * @return address Contract address of the Module + */ + function deploy(bytes _data) external returns(address) { + if (setupCost > 0) { + require(polyToken.transferFrom(msg.sender, owner, setupCost), "Sufficent Allowance is not provided"); + } + //Check valid bytes - can only call module init function + VestingEscrowWallet vestingEscrowWallet = new VestingEscrowWallet(msg.sender, address(polyToken)); + //Checks that _data is valid (not calling anything it shouldn't) + require(Util.getSig(_data) == vestingEscrowWallet.getInitFunction(), "Invalid data"); + require(address(vestingEscrowWallet).call(_data), "Unsuccessfull call"); + emit LogGenerateModuleFromFactory(address(vestingEscrowWallet), getName(), address(this), msg.sender, setupCost, now); + return address(vestingEscrowWallet); + } + + /** + * @notice Type of the Module factory + */ + function getType() public view returns(uint8) { + return 5; + } + + /** + * @notice Get the name of the Module + */ + function getName() public view returns(bytes32) { + return name; + } + + /** + * @notice Get the description of the Module + */ + function getDescription() public view returns(string) { + return description; + } + + /** + * @notice Get the title of the Module + */ + function getTitle() public view returns(string) { + return title; + } + + /** + * @notice Get the version of the Module + */ + function getVersion() external view returns(string) { + return version; + } + + /** + * @notice Get the setup cost of the module + */ + function getSetupCost() external view returns (uint256) { + return setupCost; + } + + /** + * @notice Get the Instructions that helped to used the module + */ + function getInstructions() public view returns(string) { + return "Configure and track vesting allocations"; + } + + /** + * @notice Get the tags related to the module factory + */ + function getTags() public view returns(bytes32[]) { + bytes32[] memory availableTags = new bytes32[](1); + availableTags[0] = "Presale"; // TODO: Change this when Github quesiton gets answered + return availableTags; + } + +} From fa061525c21fb8bde6343d690b4013c97d2fdd6d Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 22:35:38 -0700 Subject: [PATCH 07/57] Removed old directory --- .../VestingEscrowWallet/VestingWallet.sol | 289 ------------------ 1 file changed, 289 deletions(-) delete mode 100644 contracts/modules/VestingEscrowWallet/VestingWallet.sol diff --git a/contracts/modules/VestingEscrowWallet/VestingWallet.sol b/contracts/modules/VestingEscrowWallet/VestingWallet.sol deleted file mode 100644 index b89187b6e..000000000 --- a/contracts/modules/VestingEscrowWallet/VestingWallet.sol +++ /dev/null @@ -1,289 +0,0 @@ -pragma solidity ^0.4.24; - -import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; - -/** - * @title Escrow wallet for distributing tokens on a vesting schedule - */ -contract VestingWallet is Ownable { - using SafeMath for uint; - - bytes32 public constant ISSUER = "ISSUER"; - address public securityToken; - - struct VestingSchedule { - // ID of the vesting schedule - bytes32 vestingId; - // Total number of vesting tokens at start of vesting period - uint256 totalAllocation; - // Length of the vesting period - uint256 vestingDuration; - // Start date of vesting schedule - uint256 startDate; - // Vesting frequency of the tokens - uint256 vestingFrequency; - // Total number of tokens released to the target - uint256 totalTokensReleased; - // Total number of tokens remaining to collect - uint256 totalTokensRemaining; - // Number of tokens to release to the target per tranche - uint256 tokensPerTranche; - } - - mapping(address => uint256) public individualVestingCount; - mapping(address => mapping(uint256 => VestingSchedule)) public individualVestingDetails; - - /* Events */ - event VestingStarted( - address indexed target, - bytes32 indexed vestingId, - uint256 indexed totalAllocation, - uint256 vestingDuration, - uint256 startDate, - uint256 vestingFrequency, - uint256 totalTokensReleased, - uint256 totalTokensRemaining, - uint256 tokensPerTranche - ); - - event VestingCancelled( - address indexed target, - uint256 indexed whichVestingShedule, - bytes32 indexed vestingId, - uint256 tokensCollected, - uint256 cancellationTime - ); - - event TokensCollected( - address indexed target, - uint256 indexed whichVestingShedule, - bytes32 indexed vestingId, - uint256 numberTokensCollected - ); - - /** - * @notice Constructor - * @param _securityToken Address of the security token - * @param _polyAddress Address of the polytoken - */ - // constructor (address _securityToken, address _polyAddress) - // public - // Module(_securityToken, _polyAddress) - // { - // } - - /** - * @notice Function used to intialize the differnet variables - * @param _startTime Unix timestamp at which offering get started - * @param _endTime Unix timestamp at which offering get ended - * @param _cap Maximum No. of tokens for sale - * @param _someString Any string that contails the details - */ - // function configure(uint256 _startTime, uint256 _endTime, uint256 _cap, string _someString) public onlyFactory { - // startTime = _startTime; - // endTime = _endTime; - // cap = _cap; - // someString = _someString; - // } - - /** - * @notice This function returns the signature of configure function - */ - // function getInitFunction() public pure returns (bytes4) { - // return bytes4(keccak256("configure(uint256,uint256,uint256,string)")); - // } - - /** - * @notice Initiate a vesting schedule for any number of employees or affiliates - * @param _target Address of the employee or the affiliate - * @param _totalAllocation Total number of tokens allocated for the target - * @param _vestingDuration Total duration of the vesting schedule - * @param _startDate Start date of the vesting schedule - * @param _vestingFrequency Frequency of release of tokens - */ - function initiateVestingSchedule( - address[] _target, - uint256[] _totalAllocation, - uint256[] _vestingDuration, - uint256[] _startDate, - uint256[] _vestingFrequency - ) - public - onlyOwner - { - require(_target.length == _totalAllocation.length && - _target.length == _vestingDuration.length && - _target.length == _startDate.length && - _target.length == _vestingFrequency.length); - - for (uint i = 0; i <= _target.length; i++) { - _initiateVestingScheduleIterate(_target[i], - _totalAllocation[i], - _vestingDuration[i], - _startDate[i], - _vestingFrequency[i]); - } - } - - /** - * @notice Initiate a vesting schedule for an employee or affiliate - * @param _target Address of the employee or the affiliate - * @param _totalAllocation Total number of tokens allocated for the target - * @param _vestingDuration Total duration of the vesting schedule - * @param _startDate Start date of the vesting schedule - * @param _vestingFrequency Frequency of release of tokens - */ - function _initiateVestingScheduleIterate( - address _target, - uint256 _totalAllocation, - uint256 _vestingDuration, - uint256 _startDate, - uint256 _vestingFrequency - ) - internal - { - require(_target != address(0), "The target should be a valid addrss"); - require(_totalAllocation != 0, "The total allocation should not be 0"); - require(_vestingDuration != 0, "The vestingDuration should not be 0"); - require(_startDate >= now, "The starting date should be after now"); - require( - _vestingFrequency != 0 && _vestingFrequency <= _vestingDuration, - "The vestingFrequency should not be 0 and it should be less than the duration"); - require(_vestingDuration % _vestingFrequency == 0, "The vesting frequency should be a multiple of the vesting duration"); - // require(securityToken.balanceOf[address(this)] >= _totalAllocation, "Tokens must have been already sent to the smart contract"); - - uint256 _numTranches = _vestingDuration.div(_vestingFrequency); - uint256 _tokensPerTranche = _totalAllocation.div(_numTranches); // TODO: Edge cases/truncation. If uneven, take this into account. I asked on Github - - bytes32 _vestingId = keccak256( - abi.encodePacked( - block.timestamp, - _target, - _totalAllocation, - _vestingDuration, - _startDate, - _vestingFrequency - ) - ); - - uint256 _individualVestingCount = individualVestingCount[_target]; - individualVestingCount[_target] += 1; - - uint256 _totalTokensReleased = 0; - uint256 _totalTokensRemaining = _totalAllocation; - - individualVestingDetails[_target][_individualVestingCount] = VestingSchedule({ - vestingId: _vestingId, - totalAllocation: _totalAllocation, - vestingDuration: _vestingDuration, - startDate: _startDate, - vestingFrequency: _vestingFrequency, - totalTokensReleased: _totalTokensReleased, - totalTokensRemaining: _totalTokensRemaining, - tokensPerTranche: _tokensPerTranche - }); - - emit VestingStarted( - _target, - _vestingId, - _totalAllocation, - _vestingDuration, - _startDate, - _vestingFrequency, - _totalTokensReleased, - _totalTokensRemaining, - _tokensPerTranche - ); - - // Send tokens to contract here (see lucidchart -> assumptions -> 2) - } - - /** - * @notice Cancel a vesting schedule for an employee or affiliate - * @param _target Address of the employee or the affiliate - * @param _whichVestingSchedule Index of the vesting schedule for the target - */ - function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule) - public - onlyOwner - { - VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; - - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - - bytes32 _vestingId = _vestingSchedule.vestingId; - uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; - delete individualVestingDetails[_target][_whichVestingSchedule]; // TODO: Change this to a flag depending on Github response - - emit VestingCancelled( - _target, - _whichVestingSchedule, - _vestingId, - _tokensCollected, - block.timestamp - ); - - // TODO: Return tokens to issuer. Asked what to do on Github - } - - /** - * @notice Collect vested tokens - * @param _whichVestingSchedule Index of the vesting schedule for the target - */ - function collectTokens(uint256 _whichVestingSchedule) - public - { - VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; - - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - - uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); - - _vestingSchedule.totalTokensReleased += tokensToDistribute; - _vestingSchedule.totalTokensRemaining -= tokensToDistribute; - - // TODO: Send tokens to target. - } - - // TODO: May need to push tokens as well. Asked on Github. - - /** - * @notice Calculate the current tranche the user is on - * @param _startDate Start date of the vesting period - * @param _vestingDuration Total duration of the vesting schedule - */ - function _calculateCurrentTranche( - uint256 _startDate, - uint256 _vestingDuration - ) - internal - view - returns (uint256) - { - return now < _startDate - ? 0 - : (now.sub(_startDate)).div(_vestingDuration); - } - - /** - * @notice Calculate the number of tokens to distribute per transaction - * @param _currentTranche Current tranche of the vesting schedule - * @param _tokensPerTranche Number of tokens to distribute in each tranche - * @param _totalTokensReleased Number of tokens released thus far - */ - function _calculateTokensToDistribute( - uint256 _currentTranche, - uint256 _tokensPerTranche, - uint256 _totalTokensReleased - ) - internal - view - returns (uint256) - { - uint256 _tokensToDistribute = _currentTranche.mul(_tokensPerTranche); - return _tokensToDistribute.sub(_totalTokensReleased); - } -} From 02575644a97087d6409e2e8b39b94eccd1206bf4 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 25 Sep 2018 23:08:30 -0700 Subject: [PATCH 08/57] Update styling --- .../modules/Wallet/VestingEscrowWallet.sol | 99 +++++++++---------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 71eac9b29..134a325d1 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -126,6 +126,55 @@ contract VestingEscrowWallet is Ownable { } } + /** + * @notice Cancel a vesting schedule for an employee or affiliate + * @param _target Address of the employee or the affiliate + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule) + public + onlyOwner + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + + bytes32 _vestingId = _vestingSchedule.vestingId; + uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; + delete individualVestingDetails[_target][_whichVestingSchedule]; // TODO: Change this to a flag depending on Github response + + emit VestingCancelled( + _target, + _whichVestingSchedule, + _vestingId, + _tokensCollected, + block.timestamp + ); + + // TODO: Return tokens to issuer. Asked what to do on Github + } + + /** + * @notice Collect vested tokens + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function collectTokens(uint256 _whichVestingSchedule) + public + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + + uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); + + _vestingSchedule.totalTokensReleased += tokensToDistribute; + _vestingSchedule.totalTokensRemaining -= tokensToDistribute; + + // TODO: Send tokens to target. + } + /** * @notice Initiate a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate @@ -198,56 +247,6 @@ contract VestingEscrowWallet is Ownable { // Send tokens to contract here (see lucidchart -> assumptions -> 2) } - - /** - * @notice Cancel a vesting schedule for an employee or affiliate - * @param _target Address of the employee or the affiliate - * @param _whichVestingSchedule Index of the vesting schedule for the target - */ - function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule) - public - onlyOwner - { - VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; - - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - - bytes32 _vestingId = _vestingSchedule.vestingId; - uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; - delete individualVestingDetails[_target][_whichVestingSchedule]; // TODO: Change this to a flag depending on Github response - - emit VestingCancelled( - _target, - _whichVestingSchedule, - _vestingId, - _tokensCollected, - block.timestamp - ); - - // TODO: Return tokens to issuer. Asked what to do on Github - } - - /** - * @notice Collect vested tokens - * @param _whichVestingSchedule Index of the vesting schedule for the target - */ - function collectTokens(uint256 _whichVestingSchedule) - public - { - VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; - - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - - uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); - - _vestingSchedule.totalTokensReleased += tokensToDistribute; - _vestingSchedule.totalTokensRemaining -= tokensToDistribute; - - // TODO: Send tokens to target. - } - // TODO: May need to push tokens as well. Asked on Github. /** From b26e784c891a70b1bb030bf7c99bf98cdebea2b8 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Wed, 26 Sep 2018 15:43:54 -0700 Subject: [PATCH 09/57] Add tags --- .../Wallet/VestingEscrowWalletFactory.sol | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol index ed7b87b44..86125e37f 100644 --- a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol +++ b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol @@ -2,10 +2,10 @@ pragma solidity ^0.4.24; import "./VestingEscrowWallet.sol"; import "../ModuleFactory.sol"; -import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "../../libraries/Util.sol"; /** - * @title Factory for deploying VotingEscrowWallet + * @title Factory for deploying VestingEscrowWallet */ contract VestingEscrowWalletFactory is ModuleFactory { @@ -17,8 +17,8 @@ contract VestingEscrowWalletFactory is ModuleFactory { ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost) { version = "1.0.0"; - name = "VotingEscrowWallet"; - title = "Voting Escrow Wallet"; + name = "VestingEscrowWallet"; + title = "Vesting Escrow Wallet"; description = "Allows Issuer to program an automated token vesting schedule for employees and/or affiliates so that Tokens get delivered to their wallets as contractually defined."; } @@ -28,16 +28,14 @@ contract VestingEscrowWalletFactory is ModuleFactory { * @return address Contract address of the Module */ function deploy(bytes _data) external returns(address) { - if (setupCost > 0) { - require(polyToken.transferFrom(msg.sender, owner, setupCost), "Sufficent Allowance is not provided"); - } - //Check valid bytes - can only call module init function + if(setupCost > 0) + require(polyToken.transferFrom(msg.sender, owner, setupCost), "Failed transferFrom because of sufficent Allowance is not provided"); VestingEscrowWallet vestingEscrowWallet = new VestingEscrowWallet(msg.sender, address(polyToken)); - //Checks that _data is valid (not calling anything it shouldn't) - require(Util.getSig(_data) == vestingEscrowWallet.getInitFunction(), "Invalid data"); - require(address(vestingEscrowWallet).call(_data), "Unsuccessfull call"); + require(Util.getSig(_data) == vestingEscrowWallet.getInitFunction(), "Provided data is not valid"); + require(address(vestingEscrowWallet).call(_data), "Un-successfull call"); emit LogGenerateModuleFromFactory(address(vestingEscrowWallet), getName(), address(this), msg.sender, setupCost, now); return address(vestingEscrowWallet); + } /** @@ -94,7 +92,8 @@ contract VestingEscrowWalletFactory is ModuleFactory { */ function getTags() public view returns(bytes32[]) { bytes32[] memory availableTags = new bytes32[](1); - availableTags[0] = "Presale"; // TODO: Change this when Github quesiton gets answered + availableTags[0] = "Vested Wallet"; + availableTags[1] = "Escrow"; return availableTags; } From 5ab925a81ee1796e79b2cb9e97d689a5794f8bb5 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Wed, 26 Sep 2018 15:44:17 -0700 Subject: [PATCH 10/57] Add interface --- contracts/modules/Wallet/IWallet.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/contracts/modules/Wallet/IWallet.sol b/contracts/modules/Wallet/IWallet.sol index e69de29bb..194a4a77b 100644 --- a/contracts/modules/Wallet/IWallet.sol +++ b/contracts/modules/Wallet/IWallet.sol @@ -0,0 +1,19 @@ +pragma solidity ^0.4.24; + +import "../../Pausable.sol"; +import "../Module.sol"; + +/** + * @title Interface to be implemented by all Wallet Manager modules + */ +contract IWallet is Pausable, Module { + + function unpause() onlyOwner public { + super._unpause(); + } + + function pause() onlyOwner public { + super._pause(); + } + +} From 459a3e3b0aa3ff54bd0de9b3261c679b45dc3edf Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Wed, 26 Sep 2018 15:44:52 -0700 Subject: [PATCH 11/57] Add ability to push tokens --- .../modules/Wallet/VestingEscrowWallet.sol | 63 ++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 134a325d1..f1a8713cd 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -1,12 +1,12 @@ pragma solidity ^0.4.24; +import "./IWallet.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; /** * @title Escrow wallet for distributing tokens on a vesting schedule */ -contract VestingEscrowWallet is Ownable { +contract VestingEscrowWallet is IWallet { using SafeMath for uint; bytes32 public constant ISSUER = "ISSUER"; @@ -67,32 +67,18 @@ contract VestingEscrowWallet is Ownable { * @param _securityToken Address of the security token * @param _polyAddress Address of the polytoken */ - // constructor (address _securityToken, address _polyAddress) - // public - // Module(_securityToken, _polyAddress) - // { - // } - - /** - * @notice Function used to intialize the differnet variables - * @param _startTime Unix timestamp at which offering get started - * @param _endTime Unix timestamp at which offering get ended - * @param _cap Maximum No. of tokens for sale - * @param _someString Any string that contails the details - */ - // function configure(uint256 _startTime, uint256 _endTime, uint256 _cap, string _someString) public onlyFactory { - // startTime = _startTime; - // endTime = _endTime; - // cap = _cap; - // someString = _someString; - // } + constructor (address _securityToken, address _polyAddress) + public + Module(_securityToken, _polyAddress) + { + } /** - * @notice This function returns the signature of configure function - */ - // function getInitFunction() public pure returns (bytes4) { - // return bytes4(keccak256("configure(uint256,uint256,uint256,string)")); - // } + * @notice This function returns the signature of configure function + */ + function getInitFunction() public pure returns (bytes4) { + return bytes4(0); + } /** * @notice Initiate a vesting schedule for any number of employees or affiliates @@ -158,7 +144,7 @@ contract VestingEscrowWallet is Ownable { * @notice Collect vested tokens * @param _whichVestingSchedule Index of the vesting schedule for the target */ - function collectTokens(uint256 _whichVestingSchedule) + function collectVestedTokens(uint256 _whichVestingSchedule) public { VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; @@ -175,6 +161,28 @@ contract VestingEscrowWallet is Ownable { // TODO: Send tokens to target. } + /** + * @notice Push vested tokens + * @param _target Address of the employee or the affiliate + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function pushVestedTokens(address _target, uint256 _whichVestingSchedule) + public + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + + uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); + + _vestingSchedule.totalTokensReleased += tokensToDistribute; + _vestingSchedule.totalTokensRemaining -= tokensToDistribute; + + // TODO: Send tokens to target. + } + /** * @notice Initiate a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate @@ -247,7 +255,6 @@ contract VestingEscrowWallet is Ownable { // Send tokens to contract here (see lucidchart -> assumptions -> 2) } - // TODO: May need to push tokens as well. Asked on Github. /** * @notice Calculate the current tranche the user is on From 0bce6a036a0b04eca9a94980e06f3ff593c1137d Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 17:22:10 -0700 Subject: [PATCH 12/57] Add token transfers --- .../modules/Wallet/VestingEscrowWallet.sol | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index f1a8713cd..8b758d242 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -2,6 +2,7 @@ pragma solidity ^0.4.24; import "./IWallet.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "../../interfaces/ISecurityToken.sol"; /** * @title Escrow wallet for distributing tokens on a vesting schedule @@ -158,7 +159,17 @@ contract VestingEscrowWallet is IWallet { _vestingSchedule.totalTokensReleased += tokensToDistribute; _vestingSchedule.totalTokensRemaining -= tokensToDistribute; - // TODO: Send tokens to target. + require(ISecurityToken(securityToken).transferFrom( + address(this), + msg.sender, + tokensToDistribute), "Unable to transfer tokens"); + + emit TokensCollected( + msg.sender, + _whichVestingSchedule, + _vestingSchedule.vestingId, + tokensToDistribute + ); } /** @@ -180,7 +191,17 @@ contract VestingEscrowWallet is IWallet { _vestingSchedule.totalTokensReleased += tokensToDistribute; _vestingSchedule.totalTokensRemaining -= tokensToDistribute; - // TODO: Send tokens to target. + require(ISecurityToken(securityToken).transferFrom( + address(this), + _target, + tokensToDistribute), "Unable to transfer tokens"); + + emit TokensCollected( + _target, + _whichVestingSchedule, + _vestingSchedule.vestingId, + tokensToDistribute + ); } /** @@ -241,6 +262,11 @@ contract VestingEscrowWallet is IWallet { tokensPerTranche: _tokensPerTranche }); + require(ISecurityToken(securityToken).transferFrom( + msg.sender, + address(this), + _totalAllocation), "Unable to transfer tokens"); + emit VestingStarted( _target, _vestingId, @@ -252,8 +278,6 @@ contract VestingEscrowWallet is IWallet { _totalTokensRemaining, _tokensPerTranche ); - - // Send tokens to contract here (see lucidchart -> assumptions -> 2) } /** @@ -292,4 +316,5 @@ contract VestingEscrowWallet is IWallet { uint256 _tokensToDistribute = _currentTranche.mul(_tokensPerTranche); return _tokensToDistribute.sub(_totalTokensReleased); } + } From b620851205b101c24d52c0d5c72a0763069401e8 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 17:22:50 -0700 Subject: [PATCH 13/57] Add check to see if total allocation is a whole multiple of number of tranches --- .../modules/Wallet/VestingEscrowWallet.sol | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 8b758d242..cf40aa33e 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -81,6 +81,15 @@ contract VestingEscrowWallet is IWallet { return bytes4(0); } + /** + * @notice Return the permissions flag that are associated with VotingEscrowWallet + */ + function getPermissions() public view returns(bytes32[]) { + bytes32[] memory allPermissions = new bytes32[](1); + allPermissions[0] = ISSUER; + return allPermissions; + } + /** * @notice Initiate a vesting schedule for any number of employees or affiliates * @param _target Address of the employee or the affiliate @@ -204,6 +213,20 @@ contract VestingEscrowWallet is IWallet { ); } + /** + * @notice Edit an existing vesting schedule + * @param _target Address of the employee or the affiliate + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function editVestingSchedule(address _target, uint256 _whichVestingSchedule) + public + onlyOwner + { + VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; + + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + + } /** * @notice Initiate a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate @@ -232,7 +255,8 @@ contract VestingEscrowWallet is IWallet { // require(securityToken.balanceOf[address(this)] >= _totalAllocation, "Tokens must have been already sent to the smart contract"); uint256 _numTranches = _vestingDuration.div(_vestingFrequency); - uint256 _tokensPerTranche = _totalAllocation.div(_numTranches); // TODO: Edge cases/truncation. If uneven, take this into account. I asked on Github + require(_totalAllocation % _numTranches == 0, "The total allocation should be a multiple of the number of tranches"); + uint256 _tokensPerTranche = _totalAllocation.div(_numTranches); bytes32 _vestingId = keccak256( abi.encodePacked( From 11698de4b29af07f8a2b1d1af178c00d619fd0d4 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 17:38:52 -0700 Subject: [PATCH 14/57] Add ability to reclaim tokens from cancelled contract or to leave them in the contract --- .../modules/Wallet/VestingEscrowWallet.sol | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index cf40aa33e..511618680 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -11,7 +11,9 @@ contract VestingEscrowWallet is IWallet { using SafeMath for uint; bytes32 public constant ISSUER = "ISSUER"; + address public treasury; address public securityToken; + uint256 public numExcessTokens; struct VestingSchedule { // ID of the vesting schedule @@ -67,11 +69,13 @@ contract VestingEscrowWallet is IWallet { * @notice Constructor * @param _securityToken Address of the security token * @param _polyAddress Address of the polytoken + * @param _treasury Address of the token treasury */ - constructor (address _securityToken, address _polyAddress) + constructor (address _securityToken, address _polyAddress, addreess _treasury) public Module(_securityToken, _polyAddress) { + treasury = _treasury; } /** @@ -126,8 +130,9 @@ contract VestingEscrowWallet is IWallet { * @notice Cancel a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate * @param _whichVestingSchedule Index of the vesting schedule for the target + * @param _isReclaiming True if the issuer is reclaiming the tokens out of the contract */ - function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule) + function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule, bool _isReclaiming) public onlyOwner { @@ -137,8 +142,26 @@ contract VestingEscrowWallet is IWallet { bytes32 _vestingId = _vestingSchedule.vestingId; uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; + uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); + delete individualVestingDetails[_target][_whichVestingSchedule]; // TODO: Change this to a flag depending on Github response + require(ISecurityToken(securityToken).transferFrom( + address(this), + _target, + _tokensToDistribute), "Unable to transfer tokens"); + + // Send extra tokens to the treasury or hold them in the contract + if (_isReclaiming) { + require(ISecurityToken(securityToken).transferFrom( + address(this), + treasury, + _tokensToDistribute), "Unable to transfer tokens"); + } else { + numExcessTokens = numExcessTokens.add(_tokensToDistribute); + } + emit VestingCancelled( _target, _whichVestingSchedule, @@ -162,22 +185,22 @@ contract VestingEscrowWallet is IWallet { require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); + uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); - _vestingSchedule.totalTokensReleased += tokensToDistribute; - _vestingSchedule.totalTokensRemaining -= tokensToDistribute; + _vestingSchedule.totalTokensReleased += _tokensToDistribute; + _vestingSchedule.totalTokensRemaining -= _tokensToDistribute; require(ISecurityToken(securityToken).transferFrom( address(this), msg.sender, - tokensToDistribute), "Unable to transfer tokens"); + _tokensToDistribute), "Unable to transfer tokens"); emit TokensCollected( msg.sender, _whichVestingSchedule, _vestingSchedule.vestingId, - tokensToDistribute + _tokensToDistribute ); } From 30a10080a63648f9472dac5b35faa3ab28668c2d Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 17:39:46 -0700 Subject: [PATCH 15/57] Update event to reflect cancellation reclaim --- contracts/modules/Wallet/VestingEscrowWallet.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 511618680..f8c037d67 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -55,6 +55,7 @@ contract VestingEscrowWallet is IWallet { uint256 indexed whichVestingShedule, bytes32 indexed vestingId, uint256 tokensCollected, + bool tokensReclaimed, uint256 cancellationTime ); @@ -167,6 +168,7 @@ contract VestingEscrowWallet is IWallet { _whichVestingSchedule, _vestingId, _tokensCollected, + _isReclaiming, block.timestamp ); From f3dc779f9bc7c443c79cb3ae478b0ae376a24e20 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 17:52:30 -0700 Subject: [PATCH 16/57] Update token distribution and logging upon cancellation and add treasury to configure function --- .../modules/Wallet/VestingEscrowWallet.sol | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index f8c037d67..4d125784d 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -70,20 +70,27 @@ contract VestingEscrowWallet is IWallet { * @notice Constructor * @param _securityToken Address of the security token * @param _polyAddress Address of the polytoken - * @param _treasury Address of the token treasury */ - constructor (address _securityToken, address _polyAddress, addreess _treasury) + constructor (address _securityToken, address _polyAddress) public Module(_securityToken, _polyAddress) { - treasury = _treasury; } /** - * @notice This function returns the signature of configure function + * @notice Function used to initialize the different variables + * @param _treasury Treasury wallet to send excess funds + */ + function configure(address _treasury) public onlyFactory { + require(_treasury != 0, "Treasury should not be 0"); + treasury = _treasury; + } + + /** + * @notice This function returns the signature of the configure function */ function getInitFunction() public pure returns (bytes4) { - return bytes4(0); + return bytes4(keccak256("configure(address)")); } /** @@ -142,11 +149,11 @@ contract VestingEscrowWallet is IWallet { require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. bytes32 _vestingId = _vestingSchedule.vestingId; - uint256 _tokensCollected = _vestingSchedule.totalTokensRemaining; uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); - - delete individualVestingDetails[_target][_whichVestingSchedule]; // TODO: Change this to a flag depending on Github response + uint256 _totalTokensRemaining = _vestingSchedule.totalTokensRemaining.sub(_tokensToDistribute); + uint256 _totalTokensReleased = _vestingSchedule.totalTokensReleased.add(_tokensToDistribute); + delete individualVestingDetails[_target][_whichVestingSchedule]; require(ISecurityToken(securityToken).transferFrom( address(this), @@ -158,16 +165,16 @@ contract VestingEscrowWallet is IWallet { require(ISecurityToken(securityToken).transferFrom( address(this), treasury, - _tokensToDistribute), "Unable to transfer tokens"); + _totalTokensRemaining), "Unable to transfer tokens"); } else { - numExcessTokens = numExcessTokens.add(_tokensToDistribute); + numExcessTokens = numExcessTokens.add(_totalTokensRemaining); } emit VestingCancelled( _target, _whichVestingSchedule, _vestingId, - _tokensCollected, + _totalTokensReleased, _isReclaiming, block.timestamp ); From 273d7878fc8d434f410697fd8a508db78fe98b27 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 18:21:37 -0700 Subject: [PATCH 17/57] Chagne tokensRemaining/tokensReleased to numVestedTokens/numUnvestedTokens/numClaimedVestedTokens/numUnclaimedVestedTokens --- .../modules/Wallet/VestingEscrowWallet.sol | 74 +++++++++++-------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 4d125784d..8397aa0ef 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -26,10 +26,14 @@ contract VestingEscrowWallet is IWallet { uint256 startDate; // Vesting frequency of the tokens uint256 vestingFrequency; - // Total number of tokens released to the target - uint256 totalTokensReleased; - // Total number of tokens remaining to collect - uint256 totalTokensRemaining; + // Total number of vested tokens + uint256 numVestedTokens; + // Total number of unvested tokens + uint256 numUnvestedTokens; + // Total number of claimed vested tokens + uint256 numClaimedVestedTokens; + // Total number of unclaimed vested tokens + uint256 numUnclaimedVestedTokens; // Number of tokens to release to the target per tranche uint256 tokensPerTranche; } @@ -45,8 +49,10 @@ contract VestingEscrowWallet is IWallet { uint256 vestingDuration, uint256 startDate, uint256 vestingFrequency, - uint256 totalTokensReleased, - uint256 totalTokensRemaining, + uint256 numVestedTokens, + uint256 numUnvestedTokens, + uint256 numClaimedVestedTokens, + uint256 numUnclaimedVestedTokens, uint256 tokensPerTranche ); @@ -150,9 +156,9 @@ contract VestingEscrowWallet is IWallet { bytes32 _vestingId = _vestingSchedule.vestingId; uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); - uint256 _totalTokensRemaining = _vestingSchedule.totalTokensRemaining.sub(_tokensToDistribute); - uint256 _totalTokensReleased = _vestingSchedule.totalTokensReleased.add(_tokensToDistribute); + uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); + uint256 _numUnvestedTokens = _vestingSchedule.numUnvestedTokens.sub(_tokensToDistribute); + uint256 _numVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); delete individualVestingDetails[_target][_whichVestingSchedule]; require(ISecurityToken(securityToken).transferFrom( @@ -165,16 +171,16 @@ contract VestingEscrowWallet is IWallet { require(ISecurityToken(securityToken).transferFrom( address(this), treasury, - _totalTokensRemaining), "Unable to transfer tokens"); + _numUnvestedTokens), "Unable to transfer tokens"); } else { - numExcessTokens = numExcessTokens.add(_totalTokensRemaining); + numExcessTokens = numExcessTokens.add(_numUnvestedTokens); } emit VestingCancelled( _target, _whichVestingSchedule, _vestingId, - _totalTokensReleased, + _tokensToDistribute, _isReclaiming, block.timestamp ); @@ -192,13 +198,13 @@ contract VestingEscrowWallet is IWallet { VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); + uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); - _vestingSchedule.totalTokensReleased += _tokensToDistribute; - _vestingSchedule.totalTokensRemaining -= _tokensToDistribute; + _vestingSchedule.numClaimedVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); + _vestingSchedule.numUnclaimedVestedTokens = _vestingSchedule.numUnclaimedVestedTokens.sub(_tokensToDistribute); require(ISecurityToken(securityToken).transferFrom( address(this), @@ -224,24 +230,25 @@ contract VestingEscrowWallet is IWallet { VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - require(_vestingSchedule.totalTokensRemaining != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - uint256 currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 tokensToDistribute = _calculateTokensToDistribute(currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.totalTokensReleased); + uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); + uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); + + _vestingSchedule.numClaimedVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); + _vestingSchedule.numUnclaimedVestedTokens = _vestingSchedule.numUnclaimedVestedTokens.sub(_tokensToDistribute); - _vestingSchedule.totalTokensReleased += tokensToDistribute; - _vestingSchedule.totalTokensRemaining -= tokensToDistribute; require(ISecurityToken(securityToken).transferFrom( address(this), _target, - tokensToDistribute), "Unable to transfer tokens"); + _tokensToDistribute), "Unable to transfer tokens"); emit TokensCollected( _target, _whichVestingSchedule, _vestingSchedule.vestingId, - tokensToDistribute + _tokensToDistribute ); } @@ -304,8 +311,7 @@ contract VestingEscrowWallet is IWallet { uint256 _individualVestingCount = individualVestingCount[_target]; individualVestingCount[_target] += 1; - uint256 _totalTokensReleased = 0; - uint256 _totalTokensRemaining = _totalAllocation; + uint256 _numUnvestedTokens = _totalAllocation; individualVestingDetails[_target][_individualVestingCount] = VestingSchedule({ vestingId: _vestingId, @@ -313,8 +319,10 @@ contract VestingEscrowWallet is IWallet { vestingDuration: _vestingDuration, startDate: _startDate, vestingFrequency: _vestingFrequency, - totalTokensReleased: _totalTokensReleased, - totalTokensRemaining: _totalTokensRemaining, + numVestedTokens: 0, + numUnvestedTokens: _numUnvestedTokens, + numClaimedVestedTokens: 0, + numUnclaimedVestedTokens: 0, tokensPerTranche: _tokensPerTranche }); @@ -330,8 +338,10 @@ contract VestingEscrowWallet is IWallet { _vestingDuration, _startDate, _vestingFrequency, - _totalTokensReleased, - _totalTokensRemaining, + 0, + _numUnvestedTokens, + 0, + 0, _tokensPerTranche ); } @@ -358,19 +368,19 @@ contract VestingEscrowWallet is IWallet { * @notice Calculate the number of tokens to distribute per transaction * @param _currentTranche Current tranche of the vesting schedule * @param _tokensPerTranche Number of tokens to distribute in each tranche - * @param _totalTokensReleased Number of tokens released thus far + * @param _numClaimedVestedTokens Number of vested tokens claimed thus far */ function _calculateTokensToDistribute( uint256 _currentTranche, uint256 _tokensPerTranche, - uint256 _totalTokensReleased + uint256 _numClaimedVestedTokens ) internal view returns (uint256) { uint256 _tokensToDistribute = _currentTranche.mul(_tokensPerTranche); - return _tokensToDistribute.sub(_totalTokensReleased); + return _tokensToDistribute.sub(_numClaimedVestedTokens); } } From 758bcbbc2c48898bfcf2b5d0d6f6702d3fe953be Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 18:32:42 -0700 Subject: [PATCH 18/57] Add ability to use existing tokens in contract as tokens for new vesting schedule --- .../modules/Wallet/VestingEscrowWallet.sol | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 8397aa0ef..b06e00077 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -291,7 +291,7 @@ contract VestingEscrowWallet is IWallet { _vestingFrequency != 0 && _vestingFrequency <= _vestingDuration, "The vestingFrequency should not be 0 and it should be less than the duration"); require(_vestingDuration % _vestingFrequency == 0, "The vesting frequency should be a multiple of the vesting duration"); - // require(securityToken.balanceOf[address(this)] >= _totalAllocation, "Tokens must have been already sent to the smart contract"); + require(ISecurityToken(securityToken).balanceOf(address(this)) >= _totalAllocation, "Tokens must have been already sent to the smart contract"); uint256 _numTranches = _vestingDuration.div(_vestingFrequency); require(_totalAllocation % _numTranches == 0, "The total allocation should be a multiple of the number of tranches"); @@ -326,10 +326,14 @@ contract VestingEscrowWallet is IWallet { tokensPerTranche: _tokensPerTranche }); - require(ISecurityToken(securityToken).transferFrom( - msg.sender, - address(this), - _totalAllocation), "Unable to transfer tokens"); + uint256 _tokensToSend = _calculateTokensToSend(_totalAllocation); + + if (_tokensToSend != 0) { + require(ISecurityToken(securityToken).transferFrom( + msg.sender, + address(this), + _totalAllocation), "Unable to transfer tokens"); + } emit VestingStarted( _target, @@ -383,4 +387,26 @@ contract VestingEscrowWallet is IWallet { return _tokensToDistribute.sub(_numClaimedVestedTokens); } + /** + * @notice Calculate the number of tokens the issuer must send to the contract + * @param _totalAllocation Total allocation being used for this instance + */ + function _calculateTokensToSend( + uint256 _totalAllocation + ) + internal + view + returns (uint256) + { + if (numExcessTokens > 0){ + if (numExcessTokens >= _totalAllocation) { + return 0; + } else { + return _totalAllocation.sub(numExcessTokens); + } + } else { + return _totalAllocation; + } + } + } From 4f288e9cc4ce11ebb8cf311295be40dd19b18a11 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 19:14:26 -0700 Subject: [PATCH 19/57] Add templates --- .../modules/Wallet/VestingEscrowWallet.sol | 102 ++++++++++++------ 1 file changed, 72 insertions(+), 30 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index b06e00077..47eab3167 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -14,6 +14,7 @@ contract VestingEscrowWallet is IWallet { address public treasury; address public securityToken; uint256 public numExcessTokens; + uint256 public templateCount; struct VestingSchedule { // ID of the vesting schedule @@ -38,8 +39,18 @@ contract VestingEscrowWallet is IWallet { uint256 tokensPerTranche; } + struct VestingTemplate { + // Total number of vesting tokens at start of vesting period + uint256 totalAllocation; + // Length of the vesting period + uint256 vestingDuration; + // Vesting frequency of the tokens + uint256 vestingFrequency; + } + mapping(address => uint256) public individualVestingCount; mapping(address => mapping(uint256 => VestingSchedule)) public individualVestingDetails; + mapping(uint256 => VestingTemplate) public vestingTemplates; /* Events */ event VestingStarted( @@ -108,6 +119,27 @@ contract VestingEscrowWallet is IWallet { return allPermissions; } + /** + * @notice Create a template to be used for the creation of new vesting schedules + * @param _totalAllocation Total number of tokens allocated for the target + * @param _vestingDuration Total duration of the vesting schedule + * @param _vestingFrequency Frequency of release of tokens + */ + function createTemplate( + uint256 _totalAllocation, + uint256 _vestingDuration, + uint256 _vestingFrequency + ) + public + onlyOwner + { + vestingTemplates[templateCount].totalAllocation = _totalAllocation; + vestingTemplates[templateCount].vestingDuration = _vestingDuration; + vestingTemplates[templateCount].vestingFrequency = _vestingFrequency; + + templateCount += 1; + } + /** * @notice Initiate a vesting schedule for any number of employees or affiliates * @param _target Address of the employee or the affiliate @@ -126,18 +158,44 @@ contract VestingEscrowWallet is IWallet { public onlyOwner { - require(_target.length == _totalAllocation.length && - _target.length == _vestingDuration.length && - _target.length == _startDate.length && - _target.length == _vestingFrequency.length); - - for (uint i = 0; i <= _target.length; i++) { - _initiateVestingScheduleIterate(_target[i], - _totalAllocation[i], - _vestingDuration[i], - _startDate[i], - _vestingFrequency[i]); - } + require(_target.length == _totalAllocation.length && + _target.length == _vestingDuration.length && + _target.length == _startDate.length && + _target.length == _vestingFrequency.length); + + for (uint i = 0; i <= _target.length; i++) { + _initiateVestingScheduleIterate(_target[i], + _totalAllocation[i], + _vestingDuration[i], + _startDate[i], + _vestingFrequency[i]); + } + } + + /** + * @notice Initiate a vesting schedule for any number of employees from a template + * @param _target Address of the employee or the affiliate + * @param _templateNumber Template number to use + * @param _startDate Start date of the vesting schedule + */ + function initiateVestingSchedule( + address[] _target, + uint256 _templateNumber, + uint256 _startDate + ) + public + onlyOwner + { + VestingTemplate memory _vestingTemplate = vestingTemplates[_templateNumber]; + + for (uint i = 0; i <= _target.length; i++) { + require(_target[i] != address(0)); + _initiateVestingScheduleIterate(_target[i], + _vestingTemplate.totalAllocation, + _vestingTemplate.vestingDuration, + _startDate, + _vestingTemplate.vestingFrequency); + } } /** @@ -158,9 +216,9 @@ contract VestingEscrowWallet is IWallet { uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); uint256 _numUnvestedTokens = _vestingSchedule.numUnvestedTokens.sub(_tokensToDistribute); - uint256 _numVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); delete individualVestingDetails[_target][_whichVestingSchedule]; + // Send vested, unclaimed tokens to the target require(ISecurityToken(securityToken).transferFrom( address(this), _target, @@ -184,8 +242,6 @@ contract VestingEscrowWallet is IWallet { _isReclaiming, block.timestamp ); - - // TODO: Return tokens to issuer. Asked what to do on Github } /** @@ -252,20 +308,6 @@ contract VestingEscrowWallet is IWallet { ); } - /** - * @notice Edit an existing vesting schedule - * @param _target Address of the employee or the affiliate - * @param _whichVestingSchedule Index of the vesting schedule for the target - */ - function editVestingSchedule(address _target, uint256 _whichVestingSchedule) - public - onlyOwner - { - VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; - - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - - } /** * @notice Initiate a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate @@ -380,7 +422,7 @@ contract VestingEscrowWallet is IWallet { uint256 _numClaimedVestedTokens ) internal - view + pure returns (uint256) { uint256 _tokensToDistribute = _currentTranche.mul(_tokensPerTranche); From c3af9e8d5caf5a9f5dc4576e049ca5f8eab34f21 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 20:09:58 -0700 Subject: [PATCH 20/57] Update formatting and deployment --- .../modules/Wallet/VestingEscrowWallet.sol | 22 ++++++++++++++----- .../Wallet/VestingEscrowWalletFactory.sol | 14 +++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 47eab3167..03f559111 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -67,6 +67,13 @@ contract VestingEscrowWallet is IWallet { uint256 tokensPerTranche ); + event AddTemplate( + uint256 templateNumber, + uint256 totalAllocation, + uint256 vestingDuration, + uint256 vestingFrequency + ); + event VestingCancelled( address indexed target, uint256 indexed whichVestingShedule, @@ -137,6 +144,11 @@ contract VestingEscrowWallet is IWallet { vestingTemplates[templateCount].vestingDuration = _vestingDuration; vestingTemplates[templateCount].vestingFrequency = _vestingFrequency; + emit AddTemplate( + templateCount, + _totalAllocation, + _vestingDuration, + _vestingFrequency); templateCount += 1; } @@ -210,7 +222,7 @@ contract VestingEscrowWallet is IWallet { { VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); bytes32 _vestingId = _vestingSchedule.vestingId; uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); @@ -253,8 +265,8 @@ contract VestingEscrowWallet is IWallet { { VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); + require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); @@ -285,8 +297,8 @@ contract VestingEscrowWallet is IWallet { { VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. - require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); // TODO: May need to check a flag. Asked on Github. There may be an ID if we don't have to delete this. + require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); + require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol index 86125e37f..ffef54847 100644 --- a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol +++ b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol @@ -24,18 +24,14 @@ contract VestingEscrowWalletFactory is ModuleFactory { /** * @notice used to launch the Module with the help of factory - * @param _data Data used for the intialization of the module factory variables * @return address Contract address of the Module */ - function deploy(bytes _data) external returns(address) { - if(setupCost > 0) + function deploy(bytes /* _data */) external returns(address) { + if (setupCost > 0) require(polyToken.transferFrom(msg.sender, owner, setupCost), "Failed transferFrom because of sufficent Allowance is not provided"); - VestingEscrowWallet vestingEscrowWallet = new VestingEscrowWallet(msg.sender, address(polyToken)); - require(Util.getSig(_data) == vestingEscrowWallet.getInitFunction(), "Provided data is not valid"); - require(address(vestingEscrowWallet).call(_data), "Un-successfull call"); - emit LogGenerateModuleFromFactory(address(vestingEscrowWallet), getName(), address(this), msg.sender, setupCost, now); - return address(vestingEscrowWallet); - + address vestingEscrwoWallet = new VestingEscrowWallet(msg.sender, address(polyToken)); + emit LogGenerateModuleFromFactory(vestingEscrwoWallet, getName(), address(this), msg.sender, setupCost, now); + return vestingEscrwoWallet; } /** From 693bcce9fbba07c49088e0c6a6588ee094c3b277 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 20:10:30 -0700 Subject: [PATCH 21/57] Add initial tests and update deployment file to include VestingEscrowWalletFactory --- migrations/2_deploy_contracts.js | 16 + test/u_vesting_escrow_wallet.js | 928 +++++++++++++++++++++++++++++++ 2 files changed, 944 insertions(+) create mode 100644 test/u_vesting_escrow_wallet.js diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index 57e16c177..b8db23547 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -6,6 +6,7 @@ const PercentageTransferManagerFactory = artifacts.require('./PercentageTransfer const CountTransferManagerFactory = artifacts.require('./CountTransferManagerFactory.sol') const EtherDividendCheckpointFactory = artifacts.require('./EtherDividendCheckpointFactory.sol') const ERC20DividendCheckpointFactory = artifacts.require('./ERC20DividendCheckpointFactory.sol') +const VestingEscrowWalletFactory = artifacts.require('./VestingEscrowWalletFactory.sol') const ManualApprovalTransferManagerFactory = artifacts.require('./ManualApprovalTransferManagerFactory.sol') const CappedSTOFactory = artifacts.require('./CappedSTOFactory.sol') const USDTieredSTOFactory = artifacts.require('./USDTieredSTOFactory.sol') @@ -137,6 +138,10 @@ module.exports = function (deployer, network, accounts) { // D) Deploy the ERC20DividendCheckpointFactory Contract (Factory used to generate the ERC20DividendCheckpoint contract use // to provide the functionality of the dividend in terms of ERC20 token) return deployer.deploy(ERC20DividendCheckpointFactory, PolyToken, 0, 0, 0, {from: PolymathAccount}); + }).then(() => { + // D) Deploy the VestingEscrowWalletFactory Contract (Factory used to generate the VestingEscrowWallet contract use + // to provide the functionality of a vesting wallet) + return deployer.deploy(VestingEscrowWalletFactory, PolyToken, 0, 0, 0, {from: PolymathAccount}); }).then(() => { // D) Deploy the ManualApprovalTransferManagerFactory Contract (Factory used to generate the ManualApprovalTransferManager contract use // to manual approve the transfer that will overcome the other transfer restrictions) @@ -169,6 +174,10 @@ module.exports = function (deployer, network, accounts) { // E) Register the ERC20DividendCheckpointFactory in the ModuleRegistry to make the factory available at the protocol level. // So any securityToken can use that factory to generate the ERC20DividendCheckpoint contract. return moduleRegistry.registerModule(ERC20DividendCheckpointFactory.address, {from: PolymathAccount}); + }).then(() => { + // E) Register the VestingEscrowWalletFactory in the ModuleRegistry to make the factory available at the protocol level. + // So any securityToken can use that factory to generate the VestingEscrowWallet contract. + return moduleRegistry.registerModule(VestingEscrowWalletFactory.address, {from: PolymathAccount}); }).then(() => { // F) Once the GeneralTransferManagerFactory registered with the ModuleRegistry contract then for making them accessble to the securityToken // contract, Factory should comes under the verified list of factories or those factories deployed by the securityToken issuers only. @@ -199,6 +208,11 @@ module.exports = function (deployer, network, accounts) { // contract, Factory should comes under the verified list of factories or those factories deployed by the securityToken issuers only. // Here it gets verified because it is deployed by the third party account (Polymath Account) not with the issuer accounts. return moduleRegistry.verifyModule(ERC20DividendCheckpointFactory.address, true, {from: PolymathAccount}); + }).then(() => { + // G) Once the VestingEscrowWalletFactory registered with the ModuleRegistry contract then for making them accessble to the securityToken + // contract, Factory should comes under the verified list of factories or those factories deployed by the securityToken issuers only. + // Here it gets verified because it is deployed by the third party account (Polymath Account) not with the issuer accounts. + return moduleRegistry.verifyModule(VestingEscrowWalletFactory.address, true, {from: PolymathAccount}); }).then(() => { // G) Once the ManualApprovalTransferManagerFactory registered with the ModuleRegistry contract then for making them accessble to the securityToken // contract, Factory should comes under the verified list of factories or those factories deployed by the securityToken issuers only. @@ -282,6 +296,8 @@ module.exports = function (deployer, network, accounts) { EtherDividendCheckpointFactory: ${EtherDividendCheckpointFactory.address} ERC20DividendCheckpointFactory: ${ERC20DividendCheckpointFactory.address} + + VestingEscrowWalletFactory: ${VestingEscrowWalletFactory.address} ----------------------------------------------------------------------------- `); console.log('\n'); diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js new file mode 100644 index 000000000..ef81ec8a3 --- /dev/null +++ b/test/u_vesting_escrow_wallet.js @@ -0,0 +1,928 @@ +import latestTime from './helpers/latestTime'; +import { duration, ensureException, promisifyLogWatch, latestBlock } from './helpers/utils'; +import takeSnapshot, { increaseTime, revertToSnapshot } from './helpers/time'; +import { encodeProxyCall } from './helpers/encodeCall'; + +const PolymathRegistry = artifacts.require('./PolymathRegistry.sol') +const ModuleRegistry = artifacts.require('./ModuleRegistry.sol'); +const SecurityToken = artifacts.require('./SecurityToken.sol'); +const SecurityTokenRegistry = artifacts.require('./SecurityTokenRegistry.sol'); +const SecurityTokenRegistryProxy = artifacts.require('./SecurityTokenRegistryProxy.sol'); +const FeatureRegistry = artifacts.require('./FeatureRegistry.sol'); +const STFactory = artifacts.require('./STFactory.sol'); +const GeneralPermissionManagerFactory = artifacts.require('./GeneralPermissionManagerFactory.sol'); +const GeneralTransferManagerFactory = artifacts.require('./GeneralTransferManagerFactory.sol'); +const GeneralTransferManager = artifacts.require('./GeneralTransferManager'); +const ERC20DividendCheckpointFactory = artifacts.require('./ERC20DividendCheckpointFactory.sol'); +const ERC20DividendCheckpoint = artifacts.require('./ERC20DividendCheckpoint'); +const VestingEscrowWalletFactory = artifacts.require('./VestingEscrowWalletFactory.sol'); +const VestingEscrowWallet = artifacts.require('./VestingEscrowWallet.sol'); +const GeneralPermissionManager = artifacts.require('./GeneralPermissionManager'); +const PolyTokenFaucet = artifacts.require('./PolyTokenFaucet.sol'); + +const Web3 = require('web3'); +const BigNumber = require('bignumber.js'); +const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")) // Hardcoded development port + +contract('VestingEscrowWallet', accounts => { + + // Accounts Variable declaration + let account_polymath; + let account_issuer; + let token_owner; + let account_investor1; + let account_investor2; + let account_investor3; + let account_investor4; + let account_temp; + + // investor Details + let fromTime = latestTime(); + let toTime = latestTime(); + let expiryTime = toTime + duration.days(15); + + let message = "Transaction Should Fail!"; + + // Contract Instance Declaration + let I_GeneralPermissionManagerFactory; + let I_GeneralTransferManagerFactory; + let I_SecurityTokenRegistryProxy; + let I_VestingEscrowWalletFactory; + let I_ERC20DividendCheckpointFactory; + let P_ERC20DividendCheckpointFactory; + let P_ERC20DividendCheckpoint; + let P_VestingEscrowWalletFactory; + let P_VestingEscrowWallet; + let I_GeneralPermissionManager; + let I_ERC20DividendCheckpoint; + let I_VestingEscrowWallet; + let I_GeneralTransferManager; + let I_ExchangeTransferManager; + let I_ModuleRegistry; + let I_STRProxied; + let I_FeatureRegistry; + let I_SecurityTokenRegistry; + let I_STFactory; + let I_SecurityToken; + let I_PolyToken; + let I_PolymathRegistry; + + // SecurityToken Details + const name = "Team"; + const symbol = "sap"; + const tokenDetails = "This is equity type of issuance"; + const decimals = 18; + const contact = "team@polymath.network"; + let snapId; + // Module key + const delegateManagerKey = 1; + const transferManagerKey = 2; + const stoKey = 3; + const checkpointKey = 4; + const walletKey = 5; + + // Initial fee for ticker registry and security token registry + const initRegFee = web3.utils.toWei("250"); + + before(async() => { + // Accounts setup + account_polymath = accounts[0]; + account_issuer = accounts[1]; + + token_owner = account_issuer; + + account_investor1 = accounts[6]; + account_investor2 = accounts[7]; + account_investor3 = accounts[8]; + account_investor4 = accounts[9]; + account_temp = accounts[2]; + + // ----------- POLYMATH NETWORK Configuration ------------ + + // Step 0: Deploy the PolymathRegistry + I_PolymathRegistry = await PolymathRegistry.new({from: account_polymath}); + + // Step 1: Deploy the token Faucet and Mint tokens for token_owner + I_PolyToken = await PolyTokenFaucet.new(); + await I_PolyToken.getTokens((10000 * Math.pow(10, 18)), token_owner); + await I_PolymathRegistry.changeAddress("PolyToken", I_PolyToken.address, {from: account_polymath}) + + // STEP 2: Deploy the ModuleRegistry + I_ModuleRegistry = await ModuleRegistry.new(I_PolymathRegistry.address, {from:account_polymath}); + await I_PolymathRegistry.changeAddress("ModuleRegistry", I_ModuleRegistry.address, {from: account_polymath}); + + assert.notEqual( + I_ModuleRegistry.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "ModuleRegistry contract was not deployed" + ); + + // STEP 2: Deploy the GeneralTransferManagerFactory + I_GeneralTransferManagerFactory = await GeneralTransferManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); + + assert.notEqual( + I_GeneralTransferManagerFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "GeneralTransferManagerFactory contract was not deployed" + ); + + // STEP 3: Deploy the GeneralDelegateManagerFactory + I_GeneralPermissionManagerFactory = await GeneralPermissionManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); + + assert.notEqual( + I_GeneralPermissionManagerFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "GeneralDelegateManagerFactory contract was not deployed" + ); + + // // STEP 4: Deploy the ERC20DividendCheckpoint + // P_ERC20DividendCheckpointFactory = await ERC20DividendCheckpointFactory.new(I_PolyToken.address, web3.utils.toWei("500","ether"), 0, 0, {from:account_polymath}); + // assert.notEqual( + // P_ERC20DividendCheckpointFactory.address.valueOf(), + // "0x0000000000000000000000000000000000000000", + // "ERC20DividendCheckpointFactory contract was not deployed" + // ); + // + // // STEP 4: Deploy the ERC20DividendCheckpoint + // I_ERC20DividendCheckpointFactory = await ERC20DividendCheckpointFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); + // assert.notEqual( + // I_ERC20DividendCheckpointFactory.address.valueOf(), + // "0x0000000000000000000000000000000000000000", + // "ERC20DividendCheckpointFactory contract was not deployed" + // ); + + // STEP 4: Deploy the VestingWallet + P_VestingEscrowWalletFactory = await VestingEscrowWalletFactory.new(I_PolyToken.address, web3.utils.toWei("500","ether"), 0, 0, {from:account_polymath}); + assert.notEqual( + P_VestingEscrowWalletFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "VestingEscrowWalletFactory contract was not deployed" + ); + + // STEP 4: Deploy the VestingWallet + I_VestingEscrowWalletFactory = await VestingEscrowWalletFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); + assert.notEqual( + I_VestingEscrowWalletFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "VestingEscrowWalletFactory contract was not deployed" + ); + + // STEP 5: Register the Modules with the ModuleRegistry contract + // (A) : Register the GeneralTransferManagerFactory + await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(I_GeneralTransferManagerFactory.address, true, { from: account_polymath }); + + // (B) : Register the GeneralDelegateManagerFactory + await I_ModuleRegistry.registerModule(I_GeneralPermissionManagerFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(I_GeneralPermissionManagerFactory.address, true, { from: account_polymath }); + + // (C) : Register the VestingEscrowWalletFactory + await I_ModuleRegistry.registerModule(I_VestingEscrowWalletFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(I_VestingEscrowWalletFactory.address, true, { from: account_polymath }); + + // (C) : Register the Paid VestingEscrowWalletFactory + await I_ModuleRegistry.registerModule(P_VestingEscrowWalletFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(P_VestingEscrowWalletFactory.address, true, { from: account_polymath }); + + // Step 7: Deploy the STFactory contract + I_STFactory = await STFactory.new(I_GeneralTransferManagerFactory.address); + + assert.notEqual( + I_STFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "STFactory contract was not deployed", + ); + + // Step 9: Deploy the SecurityTokenRegistry + // Deploy the SecurityTokenregistry + I_SecurityTokenRegistry = await SecurityTokenRegistry.new({from: account_polymath }); + + assert.notEqual( + I_SecurityTokenRegistry.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "SecurityTokenRegistry contract was not deployed", + ); + + // Step 10: update the registries addresses from the PolymathRegistry contract + I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: account_polymath}); + let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, initRegFee, initRegFee, I_PolyToken.address, account_polymath]); + await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: account_polymath}); + I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); + + // Step 10: Deploy the FeatureRegistry + I_FeatureRegistry = await FeatureRegistry.new( + I_PolymathRegistry.address, + { + from: account_polymath + }); + await I_PolymathRegistry.changeAddress("FeatureRegistry", I_FeatureRegistry.address, {from: account_polymath}); + + assert.notEqual( + I_FeatureRegistry.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "FeatureRegistry contract was not deployed", + ); + + // Step 11: update the registries addresses from the PolymathRegistry contract + await I_PolymathRegistry.changeAddress("SecurityTokenRegistry", I_STRProxied.address, {from: account_polymath}); + await I_ModuleRegistry.updateFromRegistry({from: account_polymath}); + + // Printing all the contract addresses + console.log(` + --------------------- Polymath Network Smart Contracts: --------------------- + PolymathRegistry: ${PolymathRegistry.address} + SecurityTokenRegistryProxy: ${SecurityTokenRegistryProxy.address} + SecurityTokenRegistry: ${SecurityTokenRegistry.address} + ModuleRegistry: ${ModuleRegistry.address} + FeatureRegistry: ${FeatureRegistry.address} + + STFactory: ${STFactory.address} + GeneralTransferManagerFactory: ${GeneralTransferManagerFactory.address} + GeneralPermissionManagerFactory: ${GeneralPermissionManagerFactory.address} + + VestingEscrowWalletFactory: ${I_VestingEscrowWalletFactory.address} + ----------------------------------------------------------------------------- + `); + }); + + describe("Generate the SecurityToken", async() => { + + it("Should register the ticker before the generation of the security token", async () => { + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); + let tx = await I_STRProxied.registerTicker(token_owner, symbol, contact, { from : token_owner }); + assert.equal(tx.logs[0].args._owner, token_owner); + assert.equal(tx.logs[0].args._ticker, symbol.toUpperCase()); + }); + + it("Should generate the new security token with the same symbol as registered above", async () => { + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); + let _blockNo = latestBlock(); + let tx = await I_STRProxied.generateSecurityToken(name, symbol, tokenDetails, false, { from: token_owner, gas: 85000000 }); + + // Verify the successful generation of the security token + assert.equal(tx.logs[1].args._ticker, symbol.toUpperCase(), "SecurityToken doesn't get deployed"); + + I_SecurityToken = SecurityToken.at(tx.logs[1].args._securityTokenAddress); + + const log = await promisifyLogWatch(I_SecurityToken.LogModuleAdded({from: _blockNo}), 1); + // Verify that GeneralTransferManager module get added successfully or not + assert.equal(log.args._type.toNumber(), 2); + assert.equal( + web3.utils.toAscii(log.args._name) + .replace(/\u0000/g, ''), + "GeneralTransferManager" + ); + }); + + it("Should intialize the auto attached modules", async () => { + let moduleData = await I_SecurityToken.modules(2, 0); + I_GeneralTransferManager = GeneralTransferManager.at(moduleData); + + }); + + it("Should successfully attach the VestingEscrowWallet with the security token", async () => { + let errorThrown = false; + try { + const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); + } catch(error) { + console.log(` tx -> failed because Token is not paid`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("Should successfully attach the VestingEscrowWallet with the security token", async () => { + let snapId = await takeSnapshot() + await I_PolyToken.getTokens(web3.utils.toWei("500", "ether"), token_owner); + await I_PolyToken.transfer(I_SecurityToken.address, web3.utils.toWei("500", "ether"), {from: token_owner}); + const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); + assert.equal(tx.logs[3].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); + assert.equal( + web3.utils.toAscii(tx.logs[3].args._name) + .replace(/\u0000/g, ''), + "VestingEscrowWallet", + "VestingEscrowWallet module was not added" + ); + P_ERC20DividendCheckpoint = VestingEscrowWallet.at(tx.logs[3].args._module); + await revertToSnapshot(snapId); + }); + + it("Should successfully attach the VestingEscrowWallet with the security token", async () => { + const tx = await I_SecurityToken.addModule(I_VestingEscrowWalletFactory.address, "", 0, 0, { from: token_owner }); + assert.equal(tx.logs[2].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); + assert.equal( + web3.utils.toAscii(tx.logs[2].args._name) + .replace(/\u0000/g, ''), + "VestingEscrowWallet", + "VestingEscrowWallet module was not added" + ); + I_ERC20DividendCheckpoint = VestingEscrowWallet.at(tx.logs[2].args._module); + }); + }); + + describe("Check Dividend payouts", async() => { + + // it("Buy some tokens for account_investor1 (1 ETH)", async() => { + // // Add the Investor in to the whitelist + // + // let tx = await I_GeneralTransferManager.modifyWhitelist( + // account_investor1, + // latestTime(), + // latestTime(), + // latestTime() + duration.days(30), + // true, + // { + // from: account_issuer, + // gas: 500000 + // }); + // + // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_investor1.toLowerCase(), "Failed in adding the investor in whitelist"); + // + // // Jump time + // await increaseTime(5000); + // + // // Mint some tokens + // await I_SecurityToken.mint(account_investor1, web3.utils.toWei('1', 'ether'), { from: token_owner }); + // + // assert.equal( + // (await I_SecurityToken.balanceOf(account_investor1)).toNumber(), + // web3.utils.toWei('1', 'ether') + // ); + // }); + // + // it("Buy some tokens for account_investor2 (2 ETH)", async() => { + // // Add the Investor in to the whitelist + // + // let tx = await I_GeneralTransferManager.modifyWhitelist( + // account_investor2, + // latestTime(), + // latestTime(), + // latestTime() + duration.days(30), + // true, + // { + // from: account_issuer, + // gas: 500000 + // }); + // + // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_investor2.toLowerCase(), "Failed in adding the investor in whitelist"); + // + // // Mint some tokens + // await I_SecurityToken.mint(account_investor2, web3.utils.toWei('2', 'ether'), { from: token_owner }); + // + // assert.equal( + // (await I_SecurityToken.balanceOf(account_investor2)).toNumber(), + // web3.utils.toWei('2', 'ether') + // ); + // }); + // + // it("Should fail in creating the dividend", async() => { + // let errorThrown = false; + // let maturity = latestTime(); + // let expiry = latestTime() + duration.days(10); + // await I_PolyToken.getTokens(web3.utils.toWei('1.5', 'ether'), token_owner); + // try { + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because allowance = 0`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Should fail in creating the dividend", async() => { + // let errorThrown = false; + // let maturity = latestTime(); + // let expiry = latestTime() - duration.days(10); + // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // try { + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because maturity > expiry`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Should fail in creating the dividend", async() => { + // let errorThrown = false; + // let maturity = latestTime() - duration.days(2); + // let expiry = latestTime() - duration.days(1); + // try { + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because now > expiry`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Should fail in creating the dividend", async() => { + // let errorThrown = false; + // let maturity = latestTime(); + // let expiry = latestTime() + duration.days(10); + // try { + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, 0, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because token address is 0x`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Should fail in creating the dividend", async() => { + // let errorThrown = false; + // let maturity = latestTime(); + // let expiry = latestTime() + duration.days(10); + // try { + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, 0, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because amount < 0`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Create new dividend of POLY tokens", async() => { + // let maturity = latestTime() + duration.days(1); + // let expiry = latestTime() + duration.days(10); + // + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 1, "Dividend should be created at checkpoint 1"); + // }); + // + // it("Investor 1 transfers his token balance to investor 2", async() => { + // await I_SecurityToken.transfer(account_investor2, web3.utils.toWei('1', 'ether'), {from: account_investor1}); + // assert.equal(await I_SecurityToken.balanceOf(account_investor1), 0); + // assert.equal(await I_SecurityToken.balanceOf(account_investor2), web3.utils.toWei('3', 'ether')); + // }); + // + // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { + // let errorThrown = false; + // try { + // await I_ERC20DividendCheckpoint.pushDividendPayment(0, 0, 10, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because dividend index has maturity in future`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { + // let errorThrown = false; + // // Increase time by 2 day + // await increaseTime(duration.days(2)); + // try { + // await I_ERC20DividendCheckpoint.pushDividendPayment(0, 0, 10, {from: account_temp}); + // } catch(error) { + // console.log(` tx -> failed because msg.sender is not the owner`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { + // let errorThrown = false; + // try { + // await I_ERC20DividendCheckpoint.pushDividendPayment(2, 0, 10, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because dividend index is greator than the dividend array length`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { + // let _dev = await I_ERC20DividendCheckpoint.dividends.call(0); + // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // await I_ERC20DividendCheckpoint.pushDividendPayment(0, 0, 10, {from: token_owner, gas: 5000000}); + // let investor1BalanceAfter = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2BalanceAfter = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // assert.equal(investor1BalanceAfter.sub(investor1Balance).toNumber(), web3.utils.toWei('0.5', 'ether')); + // assert.equal(investor2BalanceAfter.sub(investor2Balance).toNumber(), web3.utils.toWei('1', 'ether')); + // //Check fully claimed + // assert.equal((await I_ERC20DividendCheckpoint.dividends(0))[6].toNumber(), web3.utils.toWei('1.5', 'ether')); + // }); + // + // it("Buy some tokens for account_temp (1 ETH)", async() => { + // // Add the Investor in to the whitelist + // + // let tx = await I_GeneralTransferManager.modifyWhitelist( + // account_temp, + // latestTime(), + // latestTime(), + // latestTime() + duration.days(20), + // true, + // { + // from: account_issuer, + // gas: 500000 + // }); + // + // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_temp.toLowerCase(), "Failed in adding the investor in whitelist"); + // + // // Mint some tokens + // await I_SecurityToken.mint(account_temp, web3.utils.toWei('1', 'ether'), { from: token_owner }); + // + // assert.equal( + // (await I_SecurityToken.balanceOf(account_temp)).toNumber(), + // web3.utils.toWei('1', 'ether') + // ); + // }); + // + // it("Create new dividend", async() => { + // let maturity = latestTime() + duration.days(1); + // let expiry = latestTime() + duration.days(10); + // await I_PolyToken.getTokens(web3.utils.toWei('1.5', 'ether'), token_owner); + // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); + // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 2, "Dividend should be created at checkpoint 1"); + // }); + // + // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { + // let errorThrown = false; + // await increaseTime(duration.days(12)); + // try { + // await I_ERC20DividendCheckpoint.pushDividendPayment(1, 0, 10, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because dividend index has passed its expiry`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { + // let errorThrown = false; + // let tx = await I_ERC20DividendCheckpoint.reclaimDividend(1, {from: token_owner, gas: 500000}); + // assert.equal((tx.logs[0].args._claimedAmount).toNumber(), web3.utils.toWei("1.5", "ether")); + // try { + // await I_ERC20DividendCheckpoint.reclaimDividend(1, {from: token_owner, gas: 500000}); + // } catch(error) { + // console.log(` tx -> failed because dividend index has already reclaimed`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Buy some tokens for account_investor3 (7 ETH)", async() => { + // // Add the Investor in to the whitelist + // + // let tx = await I_GeneralTransferManager.modifyWhitelist( + // account_investor3, + // latestTime(), + // latestTime(), + // latestTime() + duration.days(10), + // true, + // { + // from: account_issuer, + // gas: 500000 + // }); + // + // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_investor3.toLowerCase(), "Failed in adding the investor in whitelist"); + // + // // Mint some tokens + // await I_SecurityToken.mint(account_investor3, web3.utils.toWei('7', 'ether'), { from: token_owner }); + // + // assert.equal( + // (await I_SecurityToken.balanceOf(account_investor3)).toNumber(), + // web3.utils.toWei('7', 'ether') + // ); + // }); + // + // it("Create another new dividend", async() => { + // let maturity = latestTime(); + // let expiry = latestTime() + duration.days(10); + // await I_PolyToken.getTokens(web3.utils.toWei('11', 'ether'), token_owner); + // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('11', 'ether'), {from: token_owner}); + // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('11', 'ether'), {from: token_owner}); + // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 3, "Dividend should be created at checkpoint 2"); + // }); + // + // it("should investor 3 claims dividend", async() => { + // let errorThrown = false; + // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // try { + // await I_ERC20DividendCheckpoint.pullDividendPayment(5, {from: account_investor3, gasPrice: 0}); + // } catch(error) { + // console.log(` tx -> failed because dividend index is not valid`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("should investor 3 claims dividend", async() => { + // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // await I_ERC20DividendCheckpoint.pullDividendPayment(2, {from: account_investor3, gasPrice: 0}); + // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // assert.equal(investor1BalanceAfter1.sub(investor1Balance).toNumber(), 0); + // assert.equal(investor2BalanceAfter1.sub(investor2Balance).toNumber(), 0); + // assert.equal(investor3BalanceAfter1.sub(investor3Balance).toNumber(), web3.utils.toWei('7', 'ether')); + // }); + // + // it("should investor 3 claims dividend", async() => { + // let errorThrown = false; + // try { + // await I_ERC20DividendCheckpoint.pullDividendPayment(2, {from: account_investor3, gasPrice: 0}); + // } catch(error) { + // console.log(` tx -> failed because investor already claimed the dividend`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("should issuer pushes remain", async() => { + // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // await I_ERC20DividendCheckpoint.pushDividendPayment(2, 0, 10, {from: token_owner}); + // let investor1BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // assert.equal(investor1BalanceAfter2.sub(investor1BalanceAfter1).toNumber(), 0); + // assert.equal(investor2BalanceAfter2.sub(investor2BalanceAfter1).toNumber(), web3.utils.toWei('3', 'ether')); + // assert.equal(investor3BalanceAfter2.sub(investor3BalanceAfter1).toNumber(), 0); + // //Check fully claimed + // assert.equal((await I_ERC20DividendCheckpoint.dividends(2))[6].toNumber(), web3.utils.toWei('11', 'ether')); + // }); + // + // it("Investor 2 transfers 1 ETH of his token balance to investor 1", async() => { + // await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), {from: account_investor2}); + // assert.equal(await I_SecurityToken.balanceOf(account_investor1), web3.utils.toWei('1', 'ether')); + // assert.equal(await I_SecurityToken.balanceOf(account_investor2), web3.utils.toWei('2', 'ether')); + // assert.equal(await I_SecurityToken.balanceOf(account_investor3), web3.utils.toWei('7', 'ether')); + // }); + // + // it("Create another new dividend with explicit", async() => { + // let errorThrown = false; + // let maturity = latestTime(); + // let expiry = latestTime() + duration.days(2); + // let tx = await I_SecurityToken.createCheckpoint({from: token_owner}); + // await I_PolyToken.getTokens(web3.utils.toWei('20', 'ether'), token_owner); + // try { + // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 4, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because allowance is not provided`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Create another new dividend with explicit", async() => { + // let errorThrown = false; + // let maturity = latestTime(); + // let expiry = latestTime() - duration.days(10); + // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('20', 'ether'), {from: token_owner}); + // try { + // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 4, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because maturity > expiry`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Create another new dividend with explicit", async() => { + // let errorThrown = false; + // let maturity = latestTime() - duration.days(5); + // let expiry = latestTime() - duration.days(2); + // try { + // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 4, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because now > expiry`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Create another new dividend with explicit", async() => { + // let errorThrown = false; + // let maturity = latestTime(); + // let expiry = latestTime() + duration.days(2); + // try { + // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 5, {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because checkpoint id > current checkpoint`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Create another new dividend with explicit", async() => { + // let maturity = latestTime(); + // let expiry = latestTime() + duration.days(10); + // let tx = await I_SecurityToken.createCheckpoint({from: token_owner}); + // await I_PolyToken.getTokens(web3.utils.toWei('11', 'ether'), token_owner); + // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('11', 'ether'), {from: token_owner}); + // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('11', 'ether'), 4, {from: token_owner}); + // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 4, "Dividend should be created at checkpoint 3"); + // }); + // + // it("Investor 2 claims dividend, issuer pushes investor 1", async() => { + // let errorThrown = false; + // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // try { + // await I_ERC20DividendCheckpoint.pushDividendPaymentToAddresses(2, [account_investor2, account_investor1],{from: account_investor2, gasPrice: 0}); + // } catch(error) { + // console.log(` tx -> failed because not called by the owner`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Investor 2 claims dividend, issuer pushes investor 1", async() => { + // let errorThrown = false; + // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // try { + // await I_ERC20DividendCheckpoint.pushDividendPaymentToAddresses(5, [account_investor2, account_investor1],{from: token_owner, gasPrice: 0}); + // } catch(error) { + // console.log(` tx -> failed because dividend index is not valid`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("should calculate dividend before the push dividend payment", async() => { + // let dividendAmount1 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor1); + // let dividendAmount2 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor2); + // let dividendAmount3 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor3); + // let dividendAmount_temp = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_temp); + // assert.equal(dividendAmount1.toNumber(), web3.utils.toWei("1", "ether")); + // assert.equal(dividendAmount2.toNumber(), web3.utils.toWei("2", "ether")); + // assert.equal(dividendAmount3.toNumber(), web3.utils.toWei("7", "ether")); + // assert.equal(dividendAmount_temp.toNumber(), web3.utils.toWei("1", "ether")); + // }); + // + // it("Investor 2 claims dividend", async() => { + // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // let tempBalance = BigNumber(await web3.eth.getBalance(account_temp)); + // await I_ERC20DividendCheckpoint.pullDividendPayment(3, {from: account_investor2, gasPrice: 0}); + // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // let tempBalanceAfter1 = BigNumber(await web3.eth.getBalance(account_temp)); + // assert.equal(investor1BalanceAfter1.sub(investor1Balance).toNumber(), 0); + // assert.equal(investor2BalanceAfter1.sub(investor2Balance).toNumber(), web3.utils.toWei('2', 'ether')); + // assert.equal(investor3BalanceAfter1.sub(investor3Balance).toNumber(), 0); + // assert.equal(tempBalanceAfter1.sub(tempBalance).toNumber(), 0); + // }); + // + // it("Should issuer pushes investor 1 and temp investor", async() => { + // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // let tempBalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_temp)); + // await I_ERC20DividendCheckpoint.pushDividendPaymentToAddresses(3, [account_temp, account_investor1], {from: token_owner}); + // let investor1BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); + // let investor2BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); + // let investor3BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); + // let tempBalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_temp)); + // assert.equal(investor1BalanceAfter2.sub(investor1BalanceAfter1).toNumber(), web3.utils.toWei('1', 'ether')); + // assert.equal(investor2BalanceAfter2.sub(investor2BalanceAfter1).toNumber(), 0); + // assert.equal(investor3BalanceAfter2.sub(investor3BalanceAfter1).toNumber(), 0); + // assert.equal(tempBalanceAfter2.sub(tempBalanceAfter1).toNumber(), web3.utils.toWei('1', 'ether')); + // //Check fully claimed + // assert.equal((await I_ERC20DividendCheckpoint.dividends(3))[6].toNumber(), web3.utils.toWei('4', 'ether')); + // }); + // + // it("should calculate dividend after the push dividend payment", async() => { + // let dividendAmount1 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor1); + // let dividendAmount2 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor2); + // assert.equal(dividendAmount1.toNumber(), 0); + // assert.equal(dividendAmount2.toNumber(), 0); + // }); + // + // it("Issuer unable to reclaim dividend (expiry not passed)", async() => { + // let errorThrown = false; + // try { + // await I_ERC20DividendCheckpoint.reclaimDividend(3, {from: token_owner}); + // } catch(error) { + // console.log(`Tx Failed because expiry is in the future ${0}. Test Passed Successfully`); + // errorThrown = true; + // ensureException(error); + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Issuer is able to reclaim dividend after expiry", async() => { + // let errorThrown = false; + // await increaseTime(11 * 24 * 60 * 60); + // try { + // await I_ERC20DividendCheckpoint.reclaimDividend(8, {from: token_owner, gasPrice: 0}); + // } catch(error) { + // console.log(` tx -> failed because dividend index is not valid`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Issuer is able to reclaim dividend after expiry", async() => { + // let tokenOwnerBalance = BigNumber(await I_PolyToken.balanceOf(token_owner)); + // await I_ERC20DividendCheckpoint.reclaimDividend(3, {from: token_owner, gasPrice: 0}); + // let tokenOwnerAfter = BigNumber(await I_PolyToken.balanceOf(token_owner)); + // assert.equal(tokenOwnerAfter.sub(tokenOwnerBalance).toNumber(), web3.utils.toWei('7', 'ether')); + // }); + // + // + // it("Issuer is able to reclaim dividend after expiry", async() => { + // let errorThrown = false; + // let tokenOwnerBalance = BigNumber(await I_PolyToken.balanceOf(token_owner)); + // try { + // await I_ERC20DividendCheckpoint.reclaimDividend(3, {from: token_owner, gasPrice: 0}); + // } catch(error) { + // console.log(` tx -> failed because dividend are already reclaimed`.grey); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // + // it("Investor 3 unable to pull dividend after expiry", async() => { + // let errorThrown = false; + // try { + // await I_ERC20DividendCheckpoint.pullDividendPayment(3, {from: account_investor3, gasPrice: 0}); + // } catch(error) { + // console.log(`Tx Failed because expiry is in the past ${0}. Test Passed Successfully`); + // errorThrown = true; + // ensureException(error); + // } + // assert.ok(errorThrown, message); + // + // }); + // + // it("Should give the right dividend index", async() => { + // let index = await I_ERC20DividendCheckpoint.getDividendIndex.call(3); + // assert.equal(index[0], 2); + // }); + // + // it("Should give the right dividend index", async() => { + // let index = await I_ERC20DividendCheckpoint.getDividendIndex.call(8); + // assert.equal(index.length, 0); + // }); + // + // it("Get the init data", async() => { + // let tx = await I_ERC20DividendCheckpoint.getInitFunction.call(); + // assert.equal(web3.utils.toAscii(tx).replace(/\u0000/g, ''),0); + // }); + // + // it("Should get the listed permissions", async() => { + // let tx = await I_ERC20DividendCheckpoint.getPermissions.call(); + // assert.equal(tx.length,1); + // }); + // + // describe("Test cases for the ERC20DividendCheckpointFactory", async() => { + // it("should get the exact details of the factory", async() => { + // assert.equal((await I_ERC20DividendCheckpointFactory.setupCost.call()).toNumber(), 0); + // assert.equal(await I_ERC20DividendCheckpointFactory.getType.call(), 4); + // assert.equal(web3.utils.toAscii(await I_ERC20DividendCheckpointFactory.getName.call()) + // .replace(/\u0000/g, ''), + // "ERC20DividendCheckpoint", + // "Wrong Module added"); + // assert.equal(await I_ERC20DividendCheckpointFactory.getDescription.call(), + // "Create ERC20 dividends for token holders at a specific checkpoint", + // "Wrong Module added"); + // assert.equal(await I_ERC20DividendCheckpointFactory.getTitle.call(), + // "ERC20 Dividend Checkpoint", + // "Wrong Module added"); + // assert.equal(await I_ERC20DividendCheckpointFactory.getInstructions.call(), + // "Create a ERC20 dividend which will be paid out to token holders proportional to their balances at the point the dividend is created", + // "Wrong Module added"); + // let tags = await I_ERC20DividendCheckpointFactory.getTags.call(); + // assert.equal(tags.length, 3); + // + // }); + // }); + + }); + +}); From 28a320f4a00cfaf02d23c33c5d6f3f4a8bef4c59 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 20:54:49 -0700 Subject: [PATCH 22/57] Add template creation tests --- test/u_vesting_escrow_wallet.js | 217 +++++++++++++++++--------------- 1 file changed, 117 insertions(+), 100 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index ef81ec8a3..41a19d38b 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -13,8 +13,6 @@ const STFactory = artifacts.require('./STFactory.sol'); const GeneralPermissionManagerFactory = artifacts.require('./GeneralPermissionManagerFactory.sol'); const GeneralTransferManagerFactory = artifacts.require('./GeneralTransferManagerFactory.sol'); const GeneralTransferManager = artifacts.require('./GeneralTransferManager'); -const ERC20DividendCheckpointFactory = artifacts.require('./ERC20DividendCheckpointFactory.sol'); -const ERC20DividendCheckpoint = artifacts.require('./ERC20DividendCheckpoint'); const VestingEscrowWalletFactory = artifacts.require('./VestingEscrowWalletFactory.sol'); const VestingEscrowWallet = artifacts.require('./VestingEscrowWallet.sol'); const GeneralPermissionManager = artifacts.require('./GeneralPermissionManager'); @@ -30,10 +28,10 @@ contract('VestingEscrowWallet', accounts => { let account_polymath; let account_issuer; let token_owner; - let account_investor1; - let account_investor2; - let account_investor3; - let account_investor4; + let employee1; + let employee2; + let employee3; + let employee4; let account_temp; // investor Details @@ -48,13 +46,9 @@ contract('VestingEscrowWallet', accounts => { let I_GeneralTransferManagerFactory; let I_SecurityTokenRegistryProxy; let I_VestingEscrowWalletFactory; - let I_ERC20DividendCheckpointFactory; - let P_ERC20DividendCheckpointFactory; - let P_ERC20DividendCheckpoint; let P_VestingEscrowWalletFactory; let P_VestingEscrowWallet; let I_GeneralPermissionManager; - let I_ERC20DividendCheckpoint; let I_VestingEscrowWallet; let I_GeneralTransferManager; let I_ExchangeTransferManager; @@ -91,10 +85,10 @@ contract('VestingEscrowWallet', accounts => { token_owner = account_issuer; - account_investor1 = accounts[6]; - account_investor2 = accounts[7]; - account_investor3 = accounts[8]; - account_investor4 = accounts[9]; + employee1 = accounts[6]; + employee2 = accounts[7]; + employee3 = accounts[8]; + employee4 = accounts[9]; account_temp = accounts[2]; // ----------- POLYMATH NETWORK Configuration ------------ @@ -135,22 +129,6 @@ contract('VestingEscrowWallet', accounts => { "GeneralDelegateManagerFactory contract was not deployed" ); - // // STEP 4: Deploy the ERC20DividendCheckpoint - // P_ERC20DividendCheckpointFactory = await ERC20DividendCheckpointFactory.new(I_PolyToken.address, web3.utils.toWei("500","ether"), 0, 0, {from:account_polymath}); - // assert.notEqual( - // P_ERC20DividendCheckpointFactory.address.valueOf(), - // "0x0000000000000000000000000000000000000000", - // "ERC20DividendCheckpointFactory contract was not deployed" - // ); - // - // // STEP 4: Deploy the ERC20DividendCheckpoint - // I_ERC20DividendCheckpointFactory = await ERC20DividendCheckpointFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); - // assert.notEqual( - // I_ERC20DividendCheckpointFactory.address.valueOf(), - // "0x0000000000000000000000000000000000000000", - // "ERC20DividendCheckpointFactory contract was not deployed" - // ); - // STEP 4: Deploy the VestingWallet P_VestingEscrowWalletFactory = await VestingEscrowWalletFactory.new(I_PolyToken.address, web3.utils.toWei("500","ether"), 0, 0, {from:account_polymath}); assert.notEqual( @@ -247,81 +225,120 @@ contract('VestingEscrowWallet', accounts => { describe("Generate the SecurityToken", async() => { - it("Should register the ticker before the generation of the security token", async () => { - await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); - let tx = await I_STRProxied.registerTicker(token_owner, symbol, contact, { from : token_owner }); - assert.equal(tx.logs[0].args._owner, token_owner); - assert.equal(tx.logs[0].args._ticker, symbol.toUpperCase()); - }); - - it("Should generate the new security token with the same symbol as registered above", async () => { - await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); - let _blockNo = latestBlock(); - let tx = await I_STRProxied.generateSecurityToken(name, symbol, tokenDetails, false, { from: token_owner, gas: 85000000 }); - - // Verify the successful generation of the security token - assert.equal(tx.logs[1].args._ticker, symbol.toUpperCase(), "SecurityToken doesn't get deployed"); - - I_SecurityToken = SecurityToken.at(tx.logs[1].args._securityTokenAddress); - - const log = await promisifyLogWatch(I_SecurityToken.LogModuleAdded({from: _blockNo}), 1); - // Verify that GeneralTransferManager module get added successfully or not - assert.equal(log.args._type.toNumber(), 2); - assert.equal( - web3.utils.toAscii(log.args._name) - .replace(/\u0000/g, ''), - "GeneralTransferManager" - ); - }); - - it("Should intialize the auto attached modules", async () => { - let moduleData = await I_SecurityToken.modules(2, 0); - I_GeneralTransferManager = GeneralTransferManager.at(moduleData); + it("Should register the ticker before the generation of the security token", async () => { + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); + let tx = await I_STRProxied.registerTicker(token_owner, symbol, contact, { from : token_owner }); + assert.equal(tx.logs[0].args._owner, token_owner); + assert.equal(tx.logs[0].args._ticker, symbol.toUpperCase()); + }); + + it("Should generate the new security token with the same symbol as registered above", async () => { + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); + let _blockNo = latestBlock(); + let tx = await I_STRProxied.generateSecurityToken(name, symbol, tokenDetails, false, { from: token_owner, gas: 85000000 }); + + // Verify the successful generation of the security token + assert.equal(tx.logs[1].args._ticker, symbol.toUpperCase(), "SecurityToken doesn't get deployed"); + + I_SecurityToken = SecurityToken.at(tx.logs[1].args._securityTokenAddress); + + const log = await promisifyLogWatch(I_SecurityToken.LogModuleAdded({from: _blockNo}), 1); + // Verify that GeneralTransferManager module get added successfully or not + assert.equal(log.args._type.toNumber(), 2); + assert.equal( + web3.utils.toAscii(log.args._name) + .replace(/\u0000/g, ''), + "GeneralTransferManager" + ); + }); + + it("Should intialize the auto attached modules", async () => { + let moduleData = await I_SecurityToken.modules(2, 0); + I_GeneralTransferManager = GeneralTransferManager.at(moduleData); + + }); + + it("Should successfully attach the VestingEscrowWallet with the security token", async () => { + let errorThrown = false; + try { + const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); + } catch(error) { + console.log(` tx -> failed because Token is not paid`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("Should successfully attach the VestingEscrowWallet with the security token", async () => { + let snapId = await takeSnapshot() + await I_PolyToken.getTokens(web3.utils.toWei("500", "ether"), token_owner); + await I_PolyToken.transfer(I_SecurityToken.address, web3.utils.toWei("500", "ether"), {from: token_owner}); + const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); + assert.equal(tx.logs[3].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); + assert.equal( + web3.utils.toAscii(tx.logs[3].args._name) + .replace(/\u0000/g, ''), + "VestingEscrowWallet", + "VestingEscrowWallet module was not added" + ); + P_VestingEscrowWallet = VestingEscrowWallet.at(tx.logs[3].args._module); + await revertToSnapshot(snapId); + }); + + it("Should successfully attach the VestingEscrowWallet with the security token", async () => { + const tx = await I_SecurityToken.addModule(I_VestingEscrowWalletFactory.address, "", 0, 0, { from: token_owner }); + assert.equal(tx.logs[2].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); + assert.equal( + web3.utils.toAscii(tx.logs[2].args._name) + .replace(/\u0000/g, ''), + "VestingEscrowWallet", + "VestingEscrowWallet module was not added" + ); + I_VestingEscrowWallet = VestingEscrowWallet.at(tx.logs[2].args._module); + }); + }); + describe("Check Escrow Wallet", async() => { + context("Create Template", async() => { + it("Create a vesting schedule template", async() => { + let vestingDuration = latestTime() + duration.years(4); + let vestingFrequency = latestTime() + (duration.years(1)/4); + let amount = '10000'; + let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount, 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); + assert.equal(tx.logs[0].args.templateNumber.toNumber(), 0, "Template should be created at number 0"); }); - - it("Should successfully attach the VestingEscrowWallet with the security token", async () => { - let errorThrown = false; - try { - const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); - } catch(error) { - console.log(` tx -> failed because Token is not paid`.grey); - ensureException(error); - errorThrown = true; - } - assert.ok(errorThrown, message); + it("Create two more vesting schdule templates", async() => { + let vestingDuration = latestTime() + duration.years(4); + let vestingFrequency = latestTime() + (duration.years(1)/4); + let amount = ['25000', '50000']; + let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount[0], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); + assert.equal(tx.logs[0].args.templateNumber.toNumber(), 1, "Template should be created at number 1"); + tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount[1], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); + assert.equal(tx.logs[0].args.templateNumber.toNumber(), 2, "Template should be created at number 2"); }); - - it("Should successfully attach the VestingEscrowWallet with the security token", async () => { - let snapId = await takeSnapshot() - await I_PolyToken.getTokens(web3.utils.toWei("500", "ether"), token_owner); - await I_PolyToken.transfer(I_SecurityToken.address, web3.utils.toWei("500", "ether"), {from: token_owner}); - const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); - assert.equal(tx.logs[3].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); - assert.equal( - web3.utils.toAscii(tx.logs[3].args._name) - .replace(/\u0000/g, ''), - "VestingEscrowWallet", - "VestingEscrowWallet module was not added" - ); - P_ERC20DividendCheckpoint = VestingEscrowWallet.at(tx.logs[3].args._module); - await revertToSnapshot(snapId); + it("Should fail to create a vesting schedule template", async() => { + let errorThrown = false; + let vestingDuration = latestTime() + duration.years(4); + let vestingFrequency = latestTime() + (duration.years(1)/4); + let amount = '10000'; + try { + let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount, 'ether'), vestingDuration, vestingFrequency, {from: employee1}); + } catch(error) { + console.log(` tx -> failed because caller is not the issuer`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); }); - - it("Should successfully attach the VestingEscrowWallet with the security token", async () => { - const tx = await I_SecurityToken.addModule(I_VestingEscrowWalletFactory.address, "", 0, 0, { from: token_owner }); - assert.equal(tx.logs[2].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); - assert.equal( - web3.utils.toAscii(tx.logs[2].args._name) - .replace(/\u0000/g, ''), - "VestingEscrowWallet", - "VestingEscrowWallet module was not added" - ); - I_ERC20DividendCheckpoint = VestingEscrowWallet.at(tx.logs[2].args._module); + it("Increment the templateCount", async() => { + let vestingDuration = latestTime() + duration.years(4); + let vestingFrequency = latestTime() + (duration.years(1)/4); + let amount = '10000'; + let count = await I_VestingEscrowWallet.templateCount.call(); + assert.equal(count.toNumber(), 3, "Template count should be 3"); }); - }); - - describe("Check Dividend payouts", async() => { + }) // it("Buy some tokens for account_investor1 (1 ETH)", async() => { // // Add the Investor in to the whitelist From 38aca0f5ccc55bad6f6a116dd090f8002d219712 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 20:56:12 -0700 Subject: [PATCH 23/57] Update function name for clarity --- contracts/modules/Wallet/VestingEscrowWallet.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 03f559111..5f1c27d81 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -190,7 +190,7 @@ contract VestingEscrowWallet is IWallet { * @param _templateNumber Template number to use * @param _startDate Start date of the vesting schedule */ - function initiateVestingSchedule( + function initiateVestingScheduleFromTemplate( address[] _target, uint256 _templateNumber, uint256 _startDate From 7309e6430e925225f74b6bd273b59f1f5cabdaf5 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 21:19:07 -0700 Subject: [PATCH 24/57] Remove requirement for tokens to have already been sent to the vesting contract --- contracts/modules/Wallet/VestingEscrowWallet.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 5f1c27d81..277f76d79 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -345,7 +345,6 @@ contract VestingEscrowWallet is IWallet { _vestingFrequency != 0 && _vestingFrequency <= _vestingDuration, "The vestingFrequency should not be 0 and it should be less than the duration"); require(_vestingDuration % _vestingFrequency == 0, "The vesting frequency should be a multiple of the vesting duration"); - require(ISecurityToken(securityToken).balanceOf(address(this)) >= _totalAllocation, "Tokens must have been already sent to the smart contract"); uint256 _numTranches = _vestingDuration.div(_vestingFrequency); require(_totalAllocation % _numTranches == 0, "The total allocation should be a multiple of the number of tranches"); From e411064c775c2c081ab2e0c83d07daf464c4e048 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 21:37:54 -0700 Subject: [PATCH 25/57] Unvested token checks now happen after tokensToDistribute calculation --- contracts/modules/Wallet/VestingEscrowWallet.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 277f76d79..393c846a1 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -266,11 +266,12 @@ contract VestingEscrowWallet is IWallet { VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); - require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); + require(_tokensToDistribute != 0, "No tokens remain"); + _vestingSchedule.numClaimedVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); _vestingSchedule.numUnclaimedVestedTokens = _vestingSchedule.numUnclaimedVestedTokens.sub(_tokensToDistribute); @@ -298,11 +299,12 @@ contract VestingEscrowWallet is IWallet { VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); - require(_vestingSchedule.numUnvestedTokens != 0, "No tokens remain"); uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); + require(_tokensToDistribute != 0, "No tokens remain"); + _vestingSchedule.numClaimedVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); _vestingSchedule.numUnclaimedVestedTokens = _vestingSchedule.numUnclaimedVestedTokens.sub(_tokensToDistribute); From 42f592cdd55c8269013239f1f5546509e2911f56 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 21:44:04 -0700 Subject: [PATCH 26/57] Abstract _distributeVestedTokesn from collecteVestedTokens and pushVestedTokens --- .../modules/Wallet/VestingEscrowWallet.sol | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 393c846a1..213e574d2 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -263,29 +263,7 @@ contract VestingEscrowWallet is IWallet { function collectVestedTokens(uint256 _whichVestingSchedule) public { - VestingSchedule memory _vestingSchedule = individualVestingDetails[msg.sender][_whichVestingSchedule]; - - require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); - - uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); - uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); - - require(_tokensToDistribute != 0, "No tokens remain"); - - _vestingSchedule.numClaimedVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); - _vestingSchedule.numUnclaimedVestedTokens = _vestingSchedule.numUnclaimedVestedTokens.sub(_tokensToDistribute); - - require(ISecurityToken(securityToken).transferFrom( - address(this), - msg.sender, - _tokensToDistribute), "Unable to transfer tokens"); - - emit TokensCollected( - msg.sender, - _whichVestingSchedule, - _vestingSchedule.vestingId, - _tokensToDistribute - ); + _distributeVestedTokens(msg.sender, _whichVestingSchedule); } /** @@ -295,6 +273,18 @@ contract VestingEscrowWallet is IWallet { */ function pushVestedTokens(address _target, uint256 _whichVestingSchedule) public + onlyOwner + { + _distributeVestedTokens(_target, _whichVestingSchedule); + } + + /** + * @notice Distribute vested tokens + * @param _target Address of the employee or the affiliate + * @param _whichVestingSchedule Index of the vesting schedule for the target + */ + function _distributeVestedTokens(address _target, uint256 _whichVestingSchedule) + internal { VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; From ca9cc8496804ee98e6a3e47a95b3a6456d8d923b Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 27 Sep 2018 21:45:04 -0700 Subject: [PATCH 27/57] Add testing skeleton --- test/u_vesting_escrow_wallet.js | 165 ++++++++++++++++++++++++++++---- 1 file changed, 145 insertions(+), 20 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index 41a19d38b..16ddbd5ce 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -301,45 +301,170 @@ contract('VestingEscrowWallet', accounts => { describe("Check Escrow Wallet", async() => { context("Create Template", async() => { - it("Create a vesting schedule template", async() => { - let vestingDuration = latestTime() + duration.years(4); - let vestingFrequency = latestTime() + (duration.years(1)/4); - let amount = '10000'; - let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount, 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); - assert.equal(tx.logs[0].args.templateNumber.toNumber(), 0, "Template should be created at number 0"); - }); - it("Create two more vesting schdule templates", async() => { - let vestingDuration = latestTime() + duration.years(4); - let vestingFrequency = latestTime() + (duration.years(1)/4); - let amount = ['25000', '50000']; - let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount[0], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); - assert.equal(tx.logs[0].args.templateNumber.toNumber(), 1, "Template should be created at number 1"); - tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount[1], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); - assert.equal(tx.logs[0].args.templateNumber.toNumber(), 2, "Template should be created at number 2"); - }); it("Should fail to create a vesting schedule template", async() => { + let totalAllocation = '10000'; let errorThrown = false; let vestingDuration = latestTime() + duration.years(4); let vestingFrequency = latestTime() + (duration.years(1)/4); - let amount = '10000'; try { - let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(amount, 'ether'), vestingDuration, vestingFrequency, {from: employee1}); + let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation, 'ether'), vestingDuration, vestingFrequency, {from: employee1}); } catch(error) { console.log(` tx -> failed because caller is not the issuer`.grey); + console.log(error); ensureException(error); errorThrown = true; } assert.ok(errorThrown, message); }); + it("Create a vesting schedule template", async() => { + let totalAllocation = '10000'; + let vestingDuration = latestTime() + duration.years(4); + let vestingFrequency = latestTime() + (duration.years(1)/4); + let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation, 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); + assert.equal(tx.logs[0].args.templateNumber.toNumber(), 0, "Template should be created at number 0"); + }); + it("Create two more vesting schdule templates", async() => { + let totalAllocation = ['25000', '50000']; + let vestingDuration = latestTime() + duration.years(4); + let vestingFrequency = latestTime() + (duration.years(1)/4); + let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation[0], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); + assert.equal(tx.logs[0].args.templateNumber.toNumber(), 1, "Template should be created at number 1"); + tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation[1], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); + assert.equal(tx.logs[0].args.templateNumber.toNumber(), 2, "Template should be created at number 2"); + }); it("Increment the templateCount", async() => { + let totalAllocation = '10000'; let vestingDuration = latestTime() + duration.years(4); let vestingFrequency = latestTime() + (duration.years(1)/4); - let amount = '10000'; let count = await I_VestingEscrowWallet.templateCount.call(); assert.equal(count.toNumber(), 3, "Template count should be 3"); }); }) - + context("Initiate Vesting Schedule", async() => { + it("Should fail to initiate a vesting schedule because the caller is not the owner", async() => { + // let errorThrown = false; + // let target = [employee1, employee2, employee3] + // let totalAllocation = ['10000', '25000', '50000']; + // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + // let vestingDuration = latestTime() + duration.years(4); + // let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + // let vestingFrequency = [latestTime() + (duration.years(1)/4), latestTime() + (duration.years(1)/2)]; + // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: employee1}); + // console.log(tx); + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: employee1}); + // } catch(error) { + // console.log(` tx -> failed because caller is not the issuer`.grey); + // console.log(error); + // ensureException(error); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule because the the input arrays are not of equal length", async() => { + }); + it("Should fail to initiate a vesting schedule because a target input was 0", async() => { + }); + it("Should fail to initiate a vesting schedule because a totalAllocation input was 0", async() => { + }); + it("Should fail to initiate a vesting schedule because a vestingDuration input was 0", async() => { + }); + it("Should fail to initiate a vesting schedule because a startDate was input was before now", async() => { + }); + it("Should fail to initiate a vesting schedule because a vestingFrequency input was 0", async() => { + }); + it("Should fail to initiate a vesting schedule because a vestingFrequency was greater than the associated vestingDuration", async() => { + }); + it("Should fail to initiate a vesting schedule because a vestingFrequency was not a whole factor of the associated vestingDuration ", async() => { + }); + it("Should fail to initiate a vesting schedule because a _numTranches was not a whole factor of the associated totalAllocation ", async() => { + }); + it("Create a vesting schedule for each of the employees", async() => { + }); + it("Increment the vesting schedule for a specific employee", async() => { + }); + it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { + }); + it("Send all tokens if no tokens already exist in the contract", async() => { + }); + it("Send partial tokens if some of the required tokens already exist in the contract", async() => { + }); + it("Send no tokens if the all of the required tokens already exist in the contract", async() => { + }); + }) + context("Initiate Vesting Schedule From Template", async() => { + it("Should fail to initiate a vesting schedule from template because the caller is not the owner", async() => { + }); + it("Should fail to initiate a vesting schedule from template because an input target is 0", async() => { + }); + it("Create a vesting schedule for an employee based on a template", async() => { + }); + it("Create a vesting schedule for multiple employees based on a template", async() => { + }); + it("Increment the vesting schedule for a specific employee", async() => { + }); + it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { + }); + it("Send all tokens if no tokens already exist in the contract", async() => { + }); + it("Send partial tokens if some of the required tokens already exist in the contract", async() => { + }); + it("Send no tokens if the all of the required tokens already exist in the contract", async() => { + }); + }) + context("Cancel Vesting Scheduel", async() => { + it("Should fail to cancel a vesting schedule because the caller is not the owner", async() => { + }); + it("Should fail to cancel a vesting schedule because it does not exist", async() => { + }); + it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the employee", async() => { + }); + it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the treasury", async() => { + }); + it("Cancel a vesting schedule", async() => { + }); + it("Delete the individualVestingDetails from storage", async() => { + }); + it("Send vested, unclaimed tokens to the employee", async() => { + }); + it("Send unvested tokens to the treasury if the issuer wants to reclaim them", async() => { + }); + it("Keep tokens in the contract and update numExcessTokens if the issuer sets _isReclaiming false", async() => { + }); + }) + context("Collect Vested Tokens", async() => { + it("Should fail to collect because a vesting schedule does not exist", async() => { + }); + it("Should fail to collect because there are no remaining tokens to claim", async() => { + }); + it("Should fail to collect because the contract does not have the required number of tokens to send to the employee", async() => { + }); + it("Send vested tokens to the employee", async() => { + }); + it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { + }); + it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { + }); + it("Send vested, unclaimed tokens to the employee", async() => { + }); + }) + context("Push Vested Tokens", async() => { + it("Should fail to push because a vesting schedule does not exist", async() => { + }); + it("Should fail to push because there are no remaining tokens to claim", async() => { + }); + it("Should fail to push because the contract does not have the required number of tokens to send to the employee", async() => { + }); + it("Send vested tokens to the employee", async() => { + }); + it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { + }); + it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { + }); + it("Send vested, unclaimed tokens to the employee", async() => { + }); + }) // it("Buy some tokens for account_investor1 (1 ETH)", async() => { // // Add the Investor in to the whitelist // From 34f80a077ad43e8621e64afa2de0c6b224a38026 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Fri, 28 Sep 2018 15:43:38 -0700 Subject: [PATCH 28/57] Remove loop bug --- contracts/modules/Wallet/VestingEscrowWallet.sol | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 213e574d2..85e7ab74e 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -175,12 +175,12 @@ contract VestingEscrowWallet is IWallet { _target.length == _startDate.length && _target.length == _vestingFrequency.length); - for (uint i = 0; i <= _target.length; i++) { - _initiateVestingScheduleIterate(_target[i], - _totalAllocation[i], - _vestingDuration[i], - _startDate[i], - _vestingFrequency[i]); + for (uint i = 0; i < _target.length; i++) { + _initiateVestingScheduleIterate(_target[i], + _totalAllocation[i], + _vestingDuration[i], + _startDate[i], + _vestingFrequency[i]); } } @@ -200,7 +200,7 @@ contract VestingEscrowWallet is IWallet { { VestingTemplate memory _vestingTemplate = vestingTemplates[_templateNumber]; - for (uint i = 0; i <= _target.length; i++) { + for (uint i = 0; i < _target.length; i++) { require(_target[i] != address(0)); _initiateVestingScheduleIterate(_target[i], _vestingTemplate.totalAllocation, From e1c706df9fb17a06204f86838ed63240b834bc30 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Sun, 30 Sep 2018 04:59:15 -0700 Subject: [PATCH 29/57] WIP - Add test code --- test/u_vesting_escrow_wallet.js | 462 +++++++++++++++++++++++--------- 1 file changed, 338 insertions(+), 124 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index 16ddbd5ce..9a658894a 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -243,7 +243,7 @@ contract('VestingEscrowWallet', accounts => { I_SecurityToken = SecurityToken.at(tx.logs[1].args._securityTokenAddress); const log = await promisifyLogWatch(I_SecurityToken.LogModuleAdded({from: _blockNo}), 1); - // Verify that GeneralTransferManager module get added successfully or not + // Verify that 0 module get added successfully or not assert.equal(log.args._type.toNumber(), 2); assert.equal( web3.utils.toAscii(log.args._name) @@ -305,12 +305,11 @@ contract('VestingEscrowWallet', accounts => { let totalAllocation = '10000'; let errorThrown = false; let vestingDuration = latestTime() + duration.years(4); - let vestingFrequency = latestTime() + (duration.years(1)/4); + let vestingFrequency = (duration.years(1)/4); try { let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation, 'ether'), vestingDuration, vestingFrequency, {from: employee1}); } catch(error) { console.log(` tx -> failed because caller is not the issuer`.grey); - console.log(error); ensureException(error); errorThrown = true; } @@ -318,15 +317,16 @@ contract('VestingEscrowWallet', accounts => { }); it("Create a vesting schedule template", async() => { let totalAllocation = '10000'; - let vestingDuration = latestTime() + duration.years(4); - let vestingFrequency = latestTime() + (duration.years(1)/4); + let vestingDuration = duration.years(4); + let vestingFrequency = (duration.years(1)/4); let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation, 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); + assert.equal(tx.logs[0].args.templateNumber.toNumber(), 0, "Template should be created at number 0"); }); it("Create two more vesting schdule templates", async() => { let totalAllocation = ['25000', '50000']; - let vestingDuration = latestTime() + duration.years(4); - let vestingFrequency = latestTime() + (duration.years(1)/4); + let vestingDuration = duration.years(4); + let vestingFrequency = (duration.years(1)/4); let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation[0], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); assert.equal(tx.logs[0].args.templateNumber.toNumber(), 1, "Template should be created at number 1"); tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation[1], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); @@ -334,136 +334,350 @@ contract('VestingEscrowWallet', accounts => { }); it("Increment the templateCount", async() => { let totalAllocation = '10000'; - let vestingDuration = latestTime() + duration.years(4); - let vestingFrequency = latestTime() + (duration.years(1)/4); + let vestingDuration = duration.years(4); + let vestingFrequency = (duration.years(1)/4); let count = await I_VestingEscrowWallet.templateCount.call(); assert.equal(count.toNumber(), 3, "Template count should be 3"); }); }) context("Initiate Vesting Schedule", async() => { it("Should fail to initiate a vesting schedule because the caller is not the owner", async() => { - // let errorThrown = false; - // let target = [employee1, employee2, employee3] - // let totalAllocation = ['10000', '25000', '50000']; - // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] - // let vestingDuration = latestTime() + duration.years(4); - // let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] - // let vestingFrequency = [latestTime() + (duration.years(1)/4), latestTime() + (duration.years(1)/2)]; - // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: employee1}); - // console.log(tx); - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: employee1}); - // } catch(error) { - // console.log(` tx -> failed because caller is not the issuer`.grey); - // console.log(error); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['10000', '25000', '50000']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(1)/4),(duration.years(1)/2), (duration.years(1)/2)]; + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: employee1}); + } catch(error) { + console.log(` tx -> failed because caller is not the issuer`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); }); it("Should fail to initiate a vesting schedule because the the input arrays are not of equal length", async() => { + let errorThrown = false; + let target = [employee1, employee2] + let totalAllocation = ['10000', '25000', '50000']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because arrays ar unequal`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); }); - it("Should fail to initiate a vesting schedule because a target input was 0", async() => { - }); - it("Should fail to initiate a vesting schedule because a totalAllocation input was 0", async() => { - }); - it("Should fail to initiate a vesting schedule because a vestingDuration input was 0", async() => { - }); - it("Should fail to initiate a vesting schedule because a startDate was input was before now", async() => { - }); - it("Should fail to initiate a vesting schedule because a vestingFrequency input was 0", async() => { - }); - it("Should fail to initiate a vesting schedule because a vestingFrequency was greater than the associated vestingDuration", async() => { - }); - it("Should fail to initiate a vesting schedule because a vestingFrequency was not a whole factor of the associated vestingDuration ", async() => { - }); - it("Should fail to initiate a vesting schedule because a _numTranches was not a whole factor of the associated totalAllocation ", async() => { - }); - it("Create a vesting schedule for each of the employees", async() => { - }); - it("Increment the vesting schedule for a specific employee", async() => { - }); - it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { - }); - it("Send all tokens if no tokens already exist in the contract", async() => { - }); - it("Send partial tokens if some of the required tokens already exist in the contract", async() => { - }); - it("Send no tokens if the all of the required tokens already exist in the contract", async() => { - }); - }) - context("Initiate Vesting Schedule From Template", async() => { - it("Should fail to initiate a vesting schedule from template because the caller is not the owner", async() => { - }); - it("Should fail to initiate a vesting schedule from template because an input target is 0", async() => { - }); - it("Create a vesting schedule for an employee based on a template", async() => { - }); - it("Create a vesting schedule for multiple employees based on a template", async() => { - }); - it("Increment the vesting schedule for a specific employee", async() => { - }); - it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { - }); - it("Send all tokens if no tokens already exist in the contract", async() => { - }); - it("Send partial tokens if some of the required tokens already exist in the contract", async() => { - }); - it("Send no tokens if the all of the required tokens already exist in the contract", async() => { - }); - }) - context("Cancel Vesting Scheduel", async() => { - it("Should fail to cancel a vesting schedule because the caller is not the owner", async() => { - }); - it("Should fail to cancel a vesting schedule because it does not exist", async() => { - }); - it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the employee", async() => { - }); - it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the treasury", async() => { - }); - it("Cancel a vesting schedule", async() => { - }); - it("Delete the individualVestingDetails from storage", async() => { - }); - it("Send vested, unclaimed tokens to the employee", async() => { - }); - it("Send unvested tokens to the treasury if the issuer wants to reclaim them", async() => { - }); - it("Keep tokens in the contract and update numExcessTokens if the issuer sets _isReclaiming false", async() => { - }); - }) - context("Collect Vested Tokens", async() => { - it("Should fail to collect because a vesting schedule does not exist", async() => { - }); - it("Should fail to collect because there are no remaining tokens to claim", async() => { - }); - it("Should fail to collect because the contract does not have the required number of tokens to send to the employee", async() => { - }); - it("Send vested tokens to the employee", async() => { - }); - it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { - }); - it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { - }); - it("Send vested, unclaimed tokens to the employee", async() => { - }); - }) - context("Push Vested Tokens", async() => { - it("Should fail to push because a vesting schedule does not exist", async() => { - }); - it("Should fail to push because there are no remaining tokens to claim", async() => { - }); - it("Should fail to push because the contract does not have the required number of tokens to send to the employee", async() => { - }); - it("Send vested tokens to the employee", async() => { + it("Should add to the whitelist", async() => { + // Add the Investor in to the whitelist + + let tx = await I_GeneralTransferManager.modifyWhitelist( + token_owner, + latestTime(), + latestTime(), + latestTime() + duration.days(10), + true, + { + from: token_owner, + gas: 500000 + }); + + assert.equal(tx.logs[0].args._investor.toLowerCase(), token_owner.toLowerCase(), "Failed in adding the investor in whitelist"); }); - it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { + it("Should add to the whitelist", async() => { + // Add the Investor in to the whitelist + + let tx = await I_GeneralTransferManager.modifyWhitelist( + employee1, + latestTime(), + latestTime(), + latestTime() + duration.days(10), + true, + { + from: token_owner, + gas: 500000 + }); + + assert.equal(tx.logs[0].args._investor.toLowerCase(), employee1.toLowerCase(), "Failed in adding the investor in whitelist"); }); - it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { + it("Should add to the whitelist", async() => { + // Add the Investor in to the whitelist + + let tx = await I_GeneralTransferManager.modifyWhitelist( + I_VestingEscrowWallet.address, + latestTime(), + latestTime(), + latestTime() + duration.days(10), + true, + { + from: token_owner, + gas: 500000 + }); + + assert.equal(tx.logs[0].args._investor.toLowerCase(), I_VestingEscrowWallet.address.toLowerCase(), "Failed in adding the investor in whitelist"); }); - it("Send vested, unclaimed tokens to the employee", async() => { + + it("Should fail to initiate a vesting schedule because a target input was 0", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['16', '20', '24']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + // await I_SecurityToken.mint(I_VestingEscrowWallet.address, web3.utils.toWei('500', 'ether'), { from: token_owner }); + // await I_SecurityToken.approve(I_VestingEscrowWallet.address, web3.utils.toWei('500', 'ether'), {from: token_owner}); + var test = await I_SecurityToken.balanceOf(token_owner); + console.log(test.valueOf()) + console.log(I_VestingEscrowWallet.address); + console.log(web3.utils.toWei('5', 'ether')); + + var txion = await I_SecurityToken.transfer(I_VestingEscrowWallet.address, web3.utils.toWei('5', 'ether'), {from: token_owner}) + // await I_PolyToken.getTokens(web3.utils.toWei('5000000', 'ether'), token_owner); + await I_PolyToken.approve(I_VestingEscrowWallet.address, web3.utils.toWei('5000000', 'ether'), {from: token_owner}); + await I_PolyToken.approve(token_owner, web3.utils.toWei('5000000', 'ether'), {from: token_owner}); + + let test2 = await I_PolyToken.balanceOf(token_owner); + let test3 = await I_PolyToken.balanceOf(I_VestingEscrowWallet.address); + + console.log("New owner - ", test2); + console.log("New contract - ", test3); + + + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + console.log(params); + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because a target input was 0`.grey); + // Object.keys(error).forEach(function (key){ + // ensureException(error[key]); + // }); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); }); + // it("Should fail to initiate a vesting schedule because a totalAllocation input was 0", async() => { + // let errorThrown = false; + // let target = [employee1, employee2, employee3] + // let totalAllocation = ['10000', '25000', '50000']; + // totalAllocation = [0, web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + // let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because a totalAllocation input was 0`.grey); + // Object.keys(error).forEach(function (key){ + // ensureException(error[key]); + // }); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // it("Should fail to initiate a vesting schedule because a vestingDuration input was 0", async() => { + // let errorThrown = false; + // let target = [employee1, employee2, employee3] + // let totalAllocation = ['10000', '25000', '50000']; + // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + // let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because a vestingDuration input was 0`.grey); + // Object.keys(error).forEach(function (key){ + // ensureException(error[key]); + // }); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // it("Should fail to initiate a vesting schedule because a startDate was input was before now", async() => { + // let errorThrown = false; + // let target = [employee1, employee2, employee3] + // let totalAllocation = ['10000', '25000', '50000']; + // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + // let startDate = [0, latestTime() + duration.days(2), latestTime() + duration.days(3)] + // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because a startDate input was 0`.grey); + // Object.keys(error).forEach(function (key){ + // ensureException(error[key]); + // }); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // it("Should fail to initiate a vesting schedule because a vestingFrequency input was 0", async() => { + // let errorThrown = false; + // let target = [employee1, employee2, employee3] + // let totalAllocation = ['10000', '25000', '50000']; + // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + // let startDate = [0, latestTime() + duration.days(2), latestTime() + duration.days(3)] + // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because a vestingFrequency input was 0`.grey); + // Object.keys(error).forEach(function (key){ + // ensureException(error[key]); + // }); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // it("Should fail to initiate a vesting schedule because a vestingFrequency was greater than the associated vestingDuration", async() => { + // let errorThrown = false; + // let target = [employee1, employee2, employee3] + // let totalAllocation = ['10000', '25000', '50000']; + // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + // let startDate = [latestTime() + duration.days(2), latestTime() + duration.days(2), latestTime() + duration.days(3)] + // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because a startDate input was 0`.grey); + // Object.keys(error).forEach(function (key){ + // ensureException(error[key]); + // }); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // it("Should fail to initiate a vesting schedule because a vestingFrequency was not a whole factor of the associated vestingDuration ", async() => { + // let errorThrown = false; + // let target = [employee1, employee2, employee3] + // let totalAllocation = ['10000', '25000', '50000']; + // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + // let startDate = [latestTime() + duration.days(2), latestTime() + duration.days(2), latestTime() + duration.days(3)] + // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + // try { + // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + // } catch(error) { + // console.log(` tx -> failed because a startDate input was 0`.grey); + // Object.keys(error).forEach(function (key){ + // ensureException(error[key]); + // }); + // errorThrown = true; + // } + // assert.ok(errorThrown, message); + // }); + // it("Should fail to initiate a vesting schedule because a _numTranches was not a whole factor of the associated totalAllocation ", async() => { + // }); + // it("Create a vesting schedule for each of the employees", async() => { + // }); + // it("Increment the vesting schedule for a specific employee", async() => { + // }); + // it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { + // }); + // it("Send all tokens if no tokens already exist in the contract", async() => { + // }); + // it("Send partial tokens if some of the required tokens already exist in the contract", async() => { + // }); + // it("Send no tokens if the all of the required tokens already exist in the contract", async() => { + // }); + // }) + // context("Initiate Vesting Schedule From Template", async() => { + // it("Should fail to initiate a vesting schedule from template because the caller is not the owner", async() => { + // }); + // it("Should fail to initiate a vesting schedule from template because an input target is 0", async() => { + // }); + // it("Create a vesting schedule for an employee based on a template", async() => { + // }); + // it("Create a vesting schedule for multiple employees based on a template", async() => { + // }); + // it("Increment the vesting schedule for a specific employee", async() => { + // }); + // it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { + // }); + // it("Send all tokens if no tokens already exist in the contract", async() => { + // }); + // it("Send partial tokens if some of the required tokens already exist in the contract", async() => { + // }); + // it("Send no tokens if the all of the required tokens already exist in the contract", async() => { + // }); + // }) + // context("Cancel Vesting Scheduel", async() => { + // it("Should fail to cancel a vesting schedule because the caller is not the owner", async() => { + // }); + // it("Should fail to cancel a vesting schedule because it does not exist", async() => { + // }); + // it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the employee", async() => { + // }); + // it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the treasury", async() => { + // }); + // it("Cancel a vesting schedule", async() => { + // }); + // it("Delete the individualVestingDetails from storage", async() => { + // }); + // it("Send vested, unclaimed tokens to the employee", async() => { + // }); + // it("Send unvested tokens to the treasury if the issuer wants to reclaim them", async() => { + // }); + // it("Keep tokens in the contract and update numExcessTokens if the issuer sets _isReclaiming false", async() => { + // }); + // }) + // context("Collect Vested Tokens", async() => { + // it("Should fail to collect because a vesting schedule does not exist", async() => { + // }); + // it("Should fail to collect because there are no remaining tokens to claim", async() => { + // }); + // it("Should fail to collect because the contract does not have the required number of tokens to send to the employee", async() => { + // }); + // it("Send vested tokens to the employee", async() => { + // }); + // it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { + // }); + // it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { + // }); + // it("Send vested, unclaimed tokens to the employee", async() => { + // }); + // }) + // context("Push Vested Tokens", async() => { + // it("Should fail to push because a vesting schedule does not exist", async() => { + // }); + // it("Should fail to push because there are no remaining tokens to claim", async() => { + // }); + // it("Should fail to push because the contract does not have the required number of tokens to send to the employee", async() => { + // }); + // it("Send vested tokens to the employee", async() => { + // }); + // it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { + // }); + // it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { + // }); + // it("Send vested, unclaimed tokens to the employee", async() => { + // }); }) // it("Buy some tokens for account_investor1 (1 ETH)", async() => { // // Add the Investor in to the whitelist From 8f74d93307def007c2e91e6fc7e3c687ff1f3a43 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 15:08:42 -0700 Subject: [PATCH 30/57] Remove redundant declaration of securityToken --- contracts/modules/Wallet/VestingEscrowWallet.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 85e7ab74e..2cb85260c 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -12,7 +12,6 @@ contract VestingEscrowWallet is IWallet { bytes32 public constant ISSUER = "ISSUER"; address public treasury; - address public securityToken; uint256 public numExcessTokens; uint256 public templateCount; From 693f615b269c0cb4ee976d91defc5ef5f3c32903 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 15:25:12 -0700 Subject: [PATCH 31/57] Working test initialization --- test/u_vesting_escrow_wallet.js | 97 +++++++++++---------------------- 1 file changed, 31 insertions(+), 66 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index 9a658894a..ce3dccec8 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -341,6 +341,36 @@ contract('VestingEscrowWallet', accounts => { }); }) context("Initiate Vesting Schedule", async() => { + it("Should whitelist all relevant parties", async() => { + let tx = await I_GeneralTransferManager.modifyWhitelistMulti( + [token_owner, employee1, employee2, employee3, employee4, I_VestingEscrowWallet.address], + [latestTime(),latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], + [latestTime(),latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], + [latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10)], + [true, true, true, true, true, true], + { + from: token_owner, + gas: 6000000 + }); + + assert.equal(tx.logs[0].args._investor, token_owner); + assert.equal(tx.logs[1].args._investor, employee1); + assert.equal(tx.logs[2].args._investor, employee2); + assert.equal(tx.logs[3].args._investor, employee3); + assert.equal(tx.logs[4].args._investor, employee4); + assert.equal(tx.logs[5].args._investor, I_VestingEscrowWallet.address); + }); + + it("Should mint tokens for the token_owner and approve the contract address", async() => { + let tokenOwnerInitialBalance = await I_SecurityToken.balanceOf(token_owner); + + await I_SecurityToken.mint(token_owner, web3.utils.toWei('500', 'ether'), { from: token_owner }); + await I_SecurityToken.approve(I_VestingEscrowWallet.address, web3.utils.toWei('500', 'ether'), {from: token_owner}); + + let tokenOwnerNewBalance = await I_SecurityToken.balanceOf(token_owner); + + assert.equal(tokenOwnerNewBalance.toNumber() - web3.utils.toWei('500', 'ether'), tokenOwnerInitialBalance.toNumber(), "Template should be created at number 2"); + }); it("Should fail to initiate a vesting schedule because the caller is not the owner", async() => { let errorThrown = false; let target = [employee1, employee2, employee3] @@ -381,54 +411,6 @@ contract('VestingEscrowWallet', accounts => { } assert.ok(errorThrown, message); }); - it("Should add to the whitelist", async() => { - // Add the Investor in to the whitelist - - let tx = await I_GeneralTransferManager.modifyWhitelist( - token_owner, - latestTime(), - latestTime(), - latestTime() + duration.days(10), - true, - { - from: token_owner, - gas: 500000 - }); - - assert.equal(tx.logs[0].args._investor.toLowerCase(), token_owner.toLowerCase(), "Failed in adding the investor in whitelist"); - }); - it("Should add to the whitelist", async() => { - // Add the Investor in to the whitelist - - let tx = await I_GeneralTransferManager.modifyWhitelist( - employee1, - latestTime(), - latestTime(), - latestTime() + duration.days(10), - true, - { - from: token_owner, - gas: 500000 - }); - - assert.equal(tx.logs[0].args._investor.toLowerCase(), employee1.toLowerCase(), "Failed in adding the investor in whitelist"); - }); - it("Should add to the whitelist", async() => { - // Add the Investor in to the whitelist - - let tx = await I_GeneralTransferManager.modifyWhitelist( - I_VestingEscrowWallet.address, - latestTime(), - latestTime(), - latestTime() + duration.days(10), - true, - { - from: token_owner, - gas: 500000 - }); - - assert.equal(tx.logs[0].args._investor.toLowerCase(), I_VestingEscrowWallet.address.toLowerCase(), "Failed in adding the investor in whitelist"); - }); it("Should fail to initiate a vesting schedule because a target input was 0", async() => { let errorThrown = false; @@ -438,27 +420,10 @@ contract('VestingEscrowWallet', accounts => { let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // await I_SecurityToken.mint(I_VestingEscrowWallet.address, web3.utils.toWei('500', 'ether'), { from: token_owner }); + // await I_SecurityToken.mint(token_owner, web3.utils.toWei('500', 'ether'), { from: token_owner }); // await I_SecurityToken.approve(I_VestingEscrowWallet.address, web3.utils.toWei('500', 'ether'), {from: token_owner}); - var test = await I_SecurityToken.balanceOf(token_owner); - console.log(test.valueOf()) - console.log(I_VestingEscrowWallet.address); - console.log(web3.utils.toWei('5', 'ether')); - - var txion = await I_SecurityToken.transfer(I_VestingEscrowWallet.address, web3.utils.toWei('5', 'ether'), {from: token_owner}) - // await I_PolyToken.getTokens(web3.utils.toWei('5000000', 'ether'), token_owner); - await I_PolyToken.approve(I_VestingEscrowWallet.address, web3.utils.toWei('5000000', 'ether'), {from: token_owner}); - await I_PolyToken.approve(token_owner, web3.utils.toWei('5000000', 'ether'), {from: token_owner}); - - let test2 = await I_PolyToken.balanceOf(token_owner); - let test3 = await I_PolyToken.balanceOf(I_VestingEscrowWallet.address); - - console.log("New owner - ", test2); - console.log("New contract - ", test3); - let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - console.log(params); let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); // try { From 9f54aeb6023744b590a2102a4d4d1cf5ebee6286 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 15:32:53 -0700 Subject: [PATCH 32/57] Remove redundant mod check --- contracts/modules/Wallet/VestingEscrowWallet.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 2cb85260c..5c0b21d4f 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -338,7 +338,6 @@ contract VestingEscrowWallet is IWallet { require(_vestingDuration % _vestingFrequency == 0, "The vesting frequency should be a multiple of the vesting duration"); uint256 _numTranches = _vestingDuration.div(_vestingFrequency); - require(_totalAllocation % _numTranches == 0, "The total allocation should be a multiple of the number of tranches"); uint256 _tokensPerTranche = _totalAllocation.div(_numTranches); bytes32 _vestingId = keccak256( From a3e237f31653093cc798b550ca05f75b99df6e41 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 16:16:59 -0700 Subject: [PATCH 33/57] Fix issue where _totalAllocation was sent during schedule deployment rather than _tokensToSend --- contracts/modules/Wallet/VestingEscrowWallet.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 5c0b21d4f..25d3505fc 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -375,7 +375,7 @@ contract VestingEscrowWallet is IWallet { require(ISecurityToken(securityToken).transferFrom( msg.sender, address(this), - _totalAllocation), "Unable to transfer tokens"); + _tokensToSend), "Unable to transfer tokens"); } emit VestingStarted( From 2d44a4e57e914a040ce5b75c461b7721461565b4 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 16:24:53 -0700 Subject: [PATCH 34/57] Add numExcessTokens decrement in schedule creation --- contracts/modules/Wallet/VestingEscrowWallet.sol | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 25d3505fc..3f04c0dd6 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -371,6 +371,11 @@ contract VestingEscrowWallet is IWallet { uint256 _tokensToSend = _calculateTokensToSend(_totalAllocation); + // Remove tokens from the excess token count if existing tokens are used + if (_tokensToSend != _totalAllocation) { + numExcessTokens = numExcessTokens.sub(_totalAllocation.sub(_tokensToSend)); + } + if (_tokensToSend != 0) { require(ISecurityToken(securityToken).transferFrom( msg.sender, From 929c2efc26f0c3bcde15eb42dbf45787c95fd3de Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 16:25:36 -0700 Subject: [PATCH 35/57] Add initiateVestingSchedule tests --- test/u_vesting_escrow_wallet.js | 432 ++++++++++++++++++++------------ 1 file changed, 277 insertions(+), 155 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index ce3dccec8..aed8b27a9 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -31,7 +31,6 @@ contract('VestingEscrowWallet', accounts => { let employee1; let employee2; let employee3; - let employee4; let account_temp; // investor Details @@ -88,7 +87,6 @@ contract('VestingEscrowWallet', accounts => { employee1 = accounts[6]; employee2 = accounts[7]; employee3 = accounts[8]; - employee4 = accounts[9]; account_temp = accounts[2]; // ----------- POLYMATH NETWORK Configuration ------------ @@ -343,11 +341,11 @@ contract('VestingEscrowWallet', accounts => { context("Initiate Vesting Schedule", async() => { it("Should whitelist all relevant parties", async() => { let tx = await I_GeneralTransferManager.modifyWhitelistMulti( - [token_owner, employee1, employee2, employee3, employee4, I_VestingEscrowWallet.address], - [latestTime(),latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], - [latestTime(),latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], - [latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10)], - [true, true, true, true, true, true], + [token_owner, employee1, employee2, employee3, I_VestingEscrowWallet.address], + [latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], + [latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], + [latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10)], + [true, true, true, true, true], { from: token_owner, gas: 6000000 @@ -357,8 +355,7 @@ contract('VestingEscrowWallet', accounts => { assert.equal(tx.logs[1].args._investor, employee1); assert.equal(tx.logs[2].args._investor, employee2); assert.equal(tx.logs[3].args._investor, employee3); - assert.equal(tx.logs[4].args._investor, employee4); - assert.equal(tx.logs[5].args._investor, I_VestingEscrowWallet.address); + assert.equal(tx.logs[4].args._investor, I_VestingEscrowWallet.address); }); it("Should mint tokens for the token_owner and approve the contract address", async() => { @@ -413,6 +410,158 @@ contract('VestingEscrowWallet', accounts => { }); it("Should fail to initiate a vesting schedule because a target input was 0", async() => { + let errorThrown = false; + let target = [0, employee2, employee3] + let totalAllocation = ['16', '20', '24']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because a target input was 0`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule because a totalAllocation input was 0", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['16', '20', '24']; + totalAllocation = [0, web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because a target input was 0`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule because a vestingDuration input was 0", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['16', '20', '24']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [0, duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because a target input was 0`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule because a startDate was input was before now", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['16', '20', '24']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() - duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; + + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because a target input was 0`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule because a vestingFrequency input was 0", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['10000', '25000', '50000']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [0, latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [0, (duration.years(1)/2), (duration.years(1)/2)]; + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because a vestingFrequency input was 0`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule because a vestingFrequency was greater than the associated vestingDuration", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['16', '20', '24']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(5)), (duration.years(1)/2), (duration.years(1)/2)]; + + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because a target input was 0`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule because a vestingFrequency was not a whole factor of the associated vestingDuration ", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let totalAllocation = ['16', '20', '24']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] + let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; + let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] + let vestingFrequency = [(duration.years(3)/4), (duration.years(1)/2), (duration.years(1)/2)]; + + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + try { + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because a target input was 0`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Create a vesting schedule for each of the employees", async() => { let errorThrown = false; let target = [employee1, employee2, employee3] let totalAllocation = ['16', '20', '24']; @@ -420,157 +569,130 @@ contract('VestingEscrowWallet', accounts => { let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // await I_SecurityToken.mint(token_owner, web3.utils.toWei('500', 'ether'), { from: token_owner }); - // await I_SecurityToken.approve(I_VestingEscrowWallet.address, web3.utils.toWei('500', 'ether'), {from: token_owner}); let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because a target input was 0`.grey); - // Object.keys(error).forEach(function (key){ - // ensureException(error[key]); - // }); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); + let employee1VestingCount = await I_VestingEscrowWallet.individualVestingCount(employee1) + let employee2VestingCount = await I_VestingEscrowWallet.individualVestingCount(employee2) + let employee3VestingCount = await I_VestingEscrowWallet.individualVestingCount(employee3) + + assert.equal(employee1VestingCount.toNumber(), 1, "Did not receive a vesting schedule.") + assert.equal(employee2VestingCount.toNumber(), 1, "Did not receive a vesting schedule.") + assert.equal(employee3VestingCount.toNumber(), 1, "Did not receive a vesting schedule.") + }); + it("Increment the vesting schedule for a specific employee", async() => { + let errorThrown = false; + let target = [employee1] + let totalAllocation = ['20']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] + let vestingDuration = [duration.years(4)]; + let startDate = [latestTime() + duration.days(1)] + let vestingFrequency = [(duration.years(1)/4)]; + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + + let employee1VestingCount = await I_VestingEscrowWallet.individualVestingCount(employee1) + + assert.equal(employee1VestingCount.toNumber(), 2, "Did not receive a vesting schedule.") + }); + it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { + let txOne = await I_VestingEscrowWallet.individualVestingDetails(employee1, 0); + let totalAllocationOne = txOne[1].toNumber(); + let txTwo = await I_VestingEscrowWallet.individualVestingDetails(employee1, 1); + let totalAllocationTwo = txTwo[1].toNumber(); + + assert.equal(totalAllocationOne, web3.utils.toWei('16', 'ether'), "Schedule did not get stored"); + assert.equal(totalAllocationTwo, web3.utils.toWei('20', 'ether'), "Schedule did not get stored") + }); + it("Issuer should send all tokens if no tokens available exist in the contract upon vesting schedule creation", async() => { + let tokenOwnerBalanceBefore = await I_SecurityToken.balanceOf(token_owner); + + let errorThrown = false; + let target = [employee1] + let totalAllocation = ['20']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] + let vestingDuration = [duration.years(4)]; + let startDate = [latestTime() + duration.days(1)] + let vestingFrequency = [(duration.years(1)/4)]; + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + + let tokenOwnerBalanceAfter = await I_SecurityToken.balanceOf(token_owner); + + assert.equal(tokenOwnerBalanceAfter.add(totalAllocation).toNumber(), tokenOwnerBalanceBefore.toNumber(), "Tokens did not get transferred.") + }); + it("Issuer should send partial tokens if some of the required tokens already exist and are available in the contract upon vesting schedule creation", async() => { + let tokenOwnerBalanceBefore = await I_SecurityToken.balanceOf(token_owner); + + // Create a vesting schedule + let errorThrown = false; + let target = [employee1] + let totalAllocation = ['20']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] + let vestingDuration = [duration.years(4)]; + let startDate = [latestTime() + duration.days(1)] + let vestingFrequency = [(duration.years(1)/4)]; + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + + // Cancel schedule and leave tokens + // This is the 4th schedule creation for employee1 + await I_VestingEscrowWallet.cancelVestingSchedule(employee1, 3, false, {from: token_owner}); + + let tokenOwnerBalanceMiddle = await I_SecurityToken.balanceOf(token_owner); + + assert.equal(tokenOwnerBalanceMiddle.add(totalAllocation).toNumber(), tokenOwnerBalanceBefore.toNumber(), "Tokens did not get left in the contract.") + + // Create schedule with double the amount of tokens. Owner should only send 20, since there are 20 in the contract already + let newTotalAllocation = ['40']; + newTotalAllocation = [web3.utils.toWei(newTotalAllocation[0], 'ether')] + + params = [target, newTotalAllocation, vestingDuration, startDate, vestingFrequency]; + await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + + let tokenOwnerBalanceAfter = await I_SecurityToken.balanceOf(token_owner); + + assert.equal(tokenOwnerBalanceAfter.add(totalAllocation).toNumber(), tokenOwnerBalanceMiddle.toNumber(), "Tokens did not get transferred.") + }); + it("Issuer should send no tokens if the all of the required tokens already exist and are available in the contract upon vesting schedule creation", async() => { + let tokenOwnerBalanceBefore = await I_SecurityToken.balanceOf(token_owner); + + // Create a vesting schedule + let errorThrown = false; + let target = [employee1] + let totalAllocation = ['40']; + totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] + let vestingDuration = [duration.years(4)]; + let startDate = [latestTime() + duration.days(1)] + let vestingFrequency = [(duration.years(1)/4)]; + let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; + + await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + + // Cancel schedule and leave tokens + // This is the 6th schedule creation for employee1 + await I_VestingEscrowWallet.cancelVestingSchedule(employee1, 5, false, {from: token_owner}); + + let tokenOwnerBalanceMiddle = await I_SecurityToken.balanceOf(token_owner); + + assert.equal(tokenOwnerBalanceMiddle.add(totalAllocation).toNumber(), tokenOwnerBalanceBefore.toNumber(), "Tokens did not get left in the contract.") + + // Create schedule with double the amount of tokens. Owner should only send 20, since there are 20 in the contract already + let newTotalAllocation = ['20']; + newTotalAllocation = [web3.utils.toWei(newTotalAllocation[0], 'ether')] + + params = [target, newTotalAllocation, vestingDuration, startDate, vestingFrequency]; + await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); + + let tokenOwnerBalanceAfter = await I_SecurityToken.balanceOf(token_owner); + + assert.equal(tokenOwnerBalanceAfter.toNumber(), tokenOwnerBalanceMiddle.toNumber(), "Tokens did not get transferred.") }); - // it("Should fail to initiate a vesting schedule because a totalAllocation input was 0", async() => { - // let errorThrown = false; - // let target = [employee1, employee2, employee3] - // let totalAllocation = ['10000', '25000', '50000']; - // totalAllocation = [0, web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] - // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; - // let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] - // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because a totalAllocation input was 0`.grey); - // Object.keys(error).forEach(function (key){ - // ensureException(error[key]); - // }); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // it("Should fail to initiate a vesting schedule because a vestingDuration input was 0", async() => { - // let errorThrown = false; - // let target = [employee1, employee2, employee3] - // let totalAllocation = ['10000', '25000', '50000']; - // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] - // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; - // let startDate = [latestTime() + duration.days(1), latestTime() + duration.days(2), latestTime() + duration.days(3)] - // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because a vestingDuration input was 0`.grey); - // Object.keys(error).forEach(function (key){ - // ensureException(error[key]); - // }); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // it("Should fail to initiate a vesting schedule because a startDate was input was before now", async() => { - // let errorThrown = false; - // let target = [employee1, employee2, employee3] - // let totalAllocation = ['10000', '25000', '50000']; - // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] - // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; - // let startDate = [0, latestTime() + duration.days(2), latestTime() + duration.days(3)] - // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because a startDate input was 0`.grey); - // Object.keys(error).forEach(function (key){ - // ensureException(error[key]); - // }); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // it("Should fail to initiate a vesting schedule because a vestingFrequency input was 0", async() => { - // let errorThrown = false; - // let target = [employee1, employee2, employee3] - // let totalAllocation = ['10000', '25000', '50000']; - // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] - // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; - // let startDate = [0, latestTime() + duration.days(2), latestTime() + duration.days(3)] - // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because a vestingFrequency input was 0`.grey); - // Object.keys(error).forEach(function (key){ - // ensureException(error[key]); - // }); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // it("Should fail to initiate a vesting schedule because a vestingFrequency was greater than the associated vestingDuration", async() => { - // let errorThrown = false; - // let target = [employee1, employee2, employee3] - // let totalAllocation = ['10000', '25000', '50000']; - // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] - // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; - // let startDate = [latestTime() + duration.days(2), latestTime() + duration.days(2), latestTime() + duration.days(3)] - // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because a startDate input was 0`.grey); - // Object.keys(error).forEach(function (key){ - // ensureException(error[key]); - // }); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // it("Should fail to initiate a vesting schedule because a vestingFrequency was not a whole factor of the associated vestingDuration ", async() => { - // let errorThrown = false; - // let target = [employee1, employee2, employee3] - // let totalAllocation = ['10000', '25000', '50000']; - // totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] - // let vestingDuration = [duration.years(4), duration.years(4), duration.years(4)]; - // let startDate = [latestTime() + duration.days(2), latestTime() + duration.days(2), latestTime() + duration.days(3)] - // let vestingFrequency = [(duration.years(1)/4), (duration.years(1)/2), (duration.years(1)/2)]; - // let params = [target, totalAllocation, vestingDuration, startDate, vestingFrequency]; - // try { - // let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because a startDate input was 0`.grey); - // Object.keys(error).forEach(function (key){ - // ensureException(error[key]); - // }); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // it("Should fail to initiate a vesting schedule because a _numTranches was not a whole factor of the associated totalAllocation ", async() => { - // }); - // it("Create a vesting schedule for each of the employees", async() => { - // }); - // it("Increment the vesting schedule for a specific employee", async() => { - // }); - // it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { - // }); - // it("Send all tokens if no tokens already exist in the contract", async() => { - // }); - // it("Send partial tokens if some of the required tokens already exist in the contract", async() => { - // }); - // it("Send no tokens if the all of the required tokens already exist in the contract", async() => { - // }); // }) // context("Initiate Vesting Schedule From Template", async() => { // it("Should fail to initiate a vesting schedule from template because the caller is not the owner", async() => { From 4ce400c10a08ef5a9336cc016c1265ce76a077eb Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 16:55:02 -0700 Subject: [PATCH 36/57] Add initiateVestingScheduleFromTemplate tests --- test/u_vesting_escrow_wallet.js | 710 ++++---------------------------- 1 file changed, 78 insertions(+), 632 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index aed8b27a9..8158d017f 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -300,7 +300,7 @@ contract('VestingEscrowWallet', accounts => { describe("Check Escrow Wallet", async() => { context("Create Template", async() => { it("Should fail to create a vesting schedule template", async() => { - let totalAllocation = '10000'; + let totalAllocation = '10'; let errorThrown = false; let vestingDuration = latestTime() + duration.years(4); let vestingFrequency = (duration.years(1)/4); @@ -314,7 +314,7 @@ contract('VestingEscrowWallet', accounts => { assert.ok(errorThrown, message); }); it("Create a vesting schedule template", async() => { - let totalAllocation = '10000'; + let totalAllocation = '10'; let vestingDuration = duration.years(4); let vestingFrequency = (duration.years(1)/4); let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation, 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); @@ -322,7 +322,7 @@ contract('VestingEscrowWallet', accounts => { assert.equal(tx.logs[0].args.templateNumber.toNumber(), 0, "Template should be created at number 0"); }); it("Create two more vesting schdule templates", async() => { - let totalAllocation = ['25000', '50000']; + let totalAllocation = ['25', '50']; let vestingDuration = duration.years(4); let vestingFrequency = (duration.years(1)/4); let tx = await I_VestingEscrowWallet.createTemplate(web3.utils.toWei(totalAllocation[0], 'ether'), vestingDuration, vestingFrequency, {from: token_owner}); @@ -331,7 +331,7 @@ contract('VestingEscrowWallet', accounts => { assert.equal(tx.logs[0].args.templateNumber.toNumber(), 2, "Template should be created at number 2"); }); it("Increment the templateCount", async() => { - let totalAllocation = '10000'; + let totalAllocation = '10'; let vestingDuration = duration.years(4); let vestingFrequency = (duration.years(1)/4); let count = await I_VestingEscrowWallet.templateCount.call(); @@ -562,7 +562,6 @@ contract('VestingEscrowWallet', accounts => { assert.ok(errorThrown, message); }); it("Create a vesting schedule for each of the employees", async() => { - let errorThrown = false; let target = [employee1, employee2, employee3] let totalAllocation = ['16', '20', '24']; totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether'), web3.utils.toWei(totalAllocation[1], 'ether'), web3.utils.toWei(totalAllocation[2], 'ether')] @@ -583,7 +582,6 @@ contract('VestingEscrowWallet', accounts => { assert.equal(employee3VestingCount.toNumber(), 1, "Did not receive a vesting schedule.") }); it("Increment the vesting schedule for a specific employee", async() => { - let errorThrown = false; let target = [employee1] let totalAllocation = ['20']; totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] @@ -610,7 +608,6 @@ contract('VestingEscrowWallet', accounts => { it("Issuer should send all tokens if no tokens available exist in the contract upon vesting schedule creation", async() => { let tokenOwnerBalanceBefore = await I_SecurityToken.balanceOf(token_owner); - let errorThrown = false; let target = [employee1] let totalAllocation = ['20']; totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] @@ -629,7 +626,6 @@ contract('VestingEscrowWallet', accounts => { let tokenOwnerBalanceBefore = await I_SecurityToken.balanceOf(token_owner); // Create a vesting schedule - let errorThrown = false; let target = [employee1] let totalAllocation = ['20']; totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] @@ -663,7 +659,6 @@ contract('VestingEscrowWallet', accounts => { let tokenOwnerBalanceBefore = await I_SecurityToken.balanceOf(token_owner); // Create a vesting schedule - let errorThrown = false; let target = [employee1] let totalAllocation = ['40']; totalAllocation = [web3.utils.toWei(totalAllocation[0], 'ether')] @@ -693,27 +688,80 @@ contract('VestingEscrowWallet', accounts => { assert.equal(tokenOwnerBalanceAfter.toNumber(), tokenOwnerBalanceMiddle.toNumber(), "Tokens did not get transferred.") }); - // }) - // context("Initiate Vesting Schedule From Template", async() => { - // it("Should fail to initiate a vesting schedule from template because the caller is not the owner", async() => { - // }); - // it("Should fail to initiate a vesting schedule from template because an input target is 0", async() => { - // }); - // it("Create a vesting schedule for an employee based on a template", async() => { - // }); - // it("Create a vesting schedule for multiple employees based on a template", async() => { - // }); - // it("Increment the vesting schedule for a specific employee", async() => { - // }); - // it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { - // }); - // it("Send all tokens if no tokens already exist in the contract", async() => { - // }); - // it("Send partial tokens if some of the required tokens already exist in the contract", async() => { - // }); - // it("Send no tokens if the all of the required tokens already exist in the contract", async() => { - // }); - // }) + }) + context("Initiate Vesting Schedule From Template", async() => { + it("Should fail to initiate a vesting schedule from template because the caller is not the owner", async() => { + let errorThrown = false; + let target = [employee1, employee2, employee3] + let templateNumber = 0; + let startDate = latestTime() + duration.days(1) + + try { + let tx = await I_VestingEscrowWallet.initiateVestingScheduleFromTemplate(target, templateNumber, startDate, {from: employee1}); + } catch(error) { + console.log(` tx -> failed because caller is not the issuer`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to initiate a vesting schedule from template because an input target is 0", async() => { + let errorThrown = false; + let target = [0, employee2, employee3] + let templateNumber = 0; + let startDate = latestTime() + duration.days(1) + + try { + let tx = await I_VestingEscrowWallet.initiateVestingScheduleFromTemplate(target, templateNumber, startDate, {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because caller is not the issuer`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Create a vesting schedule for an employee based on a template", async() => { + let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + let target = [employee1, employee2, employee3] + let templateNumber = 0; + let startDate = latestTime() + duration.days(1) + + let tx = await I_VestingEscrowWallet.initiateVestingScheduleFromTemplate(target, templateNumber, startDate, {from: token_owner}); + let newScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + + assert.equal(currentScheduleCount.add(1).toNumber(), newScheduleCount.toNumber(), "Schedule count did not get updated") + }); + it("Create a vesting schedule for multiple employees based on a template", async() => { + let currentScheduleCountOne = await I_VestingEscrowWallet.individualVestingCount(employee1); + let currentScheduleCountTwo = await I_VestingEscrowWallet.individualVestingCount(employee2); + let currentScheduleCountThree = await I_VestingEscrowWallet.individualVestingCount(employee3); + + let target = [employee1, employee2, employee3] + let templateNumber = 0; + let startDate = latestTime() + duration.days(1) + + let tx = await I_VestingEscrowWallet.initiateVestingScheduleFromTemplate(target, templateNumber, startDate, {from: token_owner}); + let newScheduleCountOne = await I_VestingEscrowWallet.individualVestingCount(employee1); + let newScheduleCountTwo = await I_VestingEscrowWallet.individualVestingCount(employee2); + let newScheduleCountThree = await I_VestingEscrowWallet.individualVestingCount(employee3); + + assert.equal(currentScheduleCountOne.add(1).toNumber(), newScheduleCountOne.toNumber(), "Schedule count did not get updated") + assert.equal(currentScheduleCountTwo.add(1).toNumber(), newScheduleCountTwo.toNumber(), "Schedule count did not get updated") + assert.equal(currentScheduleCountThree.add(1).toNumber(), newScheduleCountThree.toNumber(), "Schedule count did not get updated") + }); + it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { + let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + + let tx = await I_VestingEscrowWallet.individualVestingDetails(employee1, currentScheduleCount.sub(1)); + let totalAllocation = tx[1].toNumber(); + + assert.equal(totalAllocation, web3.utils.toWei('10', 'ether'), "Schedule did not get stored"); + }); + }); // context("Cancel Vesting Scheduel", async() => { // it("Should fail to cancel a vesting schedule because the caller is not the owner", async() => { // }); @@ -766,606 +814,4 @@ contract('VestingEscrowWallet', accounts => { // it("Send vested, unclaimed tokens to the employee", async() => { // }); }) - // it("Buy some tokens for account_investor1 (1 ETH)", async() => { - // // Add the Investor in to the whitelist - // - // let tx = await I_GeneralTransferManager.modifyWhitelist( - // account_investor1, - // latestTime(), - // latestTime(), - // latestTime() + duration.days(30), - // true, - // { - // from: account_issuer, - // gas: 500000 - // }); - // - // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_investor1.toLowerCase(), "Failed in adding the investor in whitelist"); - // - // // Jump time - // await increaseTime(5000); - // - // // Mint some tokens - // await I_SecurityToken.mint(account_investor1, web3.utils.toWei('1', 'ether'), { from: token_owner }); - // - // assert.equal( - // (await I_SecurityToken.balanceOf(account_investor1)).toNumber(), - // web3.utils.toWei('1', 'ether') - // ); - // }); - // - // it("Buy some tokens for account_investor2 (2 ETH)", async() => { - // // Add the Investor in to the whitelist - // - // let tx = await I_GeneralTransferManager.modifyWhitelist( - // account_investor2, - // latestTime(), - // latestTime(), - // latestTime() + duration.days(30), - // true, - // { - // from: account_issuer, - // gas: 500000 - // }); - // - // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_investor2.toLowerCase(), "Failed in adding the investor in whitelist"); - // - // // Mint some tokens - // await I_SecurityToken.mint(account_investor2, web3.utils.toWei('2', 'ether'), { from: token_owner }); - // - // assert.equal( - // (await I_SecurityToken.balanceOf(account_investor2)).toNumber(), - // web3.utils.toWei('2', 'ether') - // ); - // }); - // - // it("Should fail in creating the dividend", async() => { - // let errorThrown = false; - // let maturity = latestTime(); - // let expiry = latestTime() + duration.days(10); - // await I_PolyToken.getTokens(web3.utils.toWei('1.5', 'ether'), token_owner); - // try { - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because allowance = 0`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Should fail in creating the dividend", async() => { - // let errorThrown = false; - // let maturity = latestTime(); - // let expiry = latestTime() - duration.days(10); - // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // try { - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because maturity > expiry`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Should fail in creating the dividend", async() => { - // let errorThrown = false; - // let maturity = latestTime() - duration.days(2); - // let expiry = latestTime() - duration.days(1); - // try { - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because now > expiry`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Should fail in creating the dividend", async() => { - // let errorThrown = false; - // let maturity = latestTime(); - // let expiry = latestTime() + duration.days(10); - // try { - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, 0, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because token address is 0x`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Should fail in creating the dividend", async() => { - // let errorThrown = false; - // let maturity = latestTime(); - // let expiry = latestTime() + duration.days(10); - // try { - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, 0, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because amount < 0`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Create new dividend of POLY tokens", async() => { - // let maturity = latestTime() + duration.days(1); - // let expiry = latestTime() + duration.days(10); - // - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 1, "Dividend should be created at checkpoint 1"); - // }); - // - // it("Investor 1 transfers his token balance to investor 2", async() => { - // await I_SecurityToken.transfer(account_investor2, web3.utils.toWei('1', 'ether'), {from: account_investor1}); - // assert.equal(await I_SecurityToken.balanceOf(account_investor1), 0); - // assert.equal(await I_SecurityToken.balanceOf(account_investor2), web3.utils.toWei('3', 'ether')); - // }); - // - // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { - // let errorThrown = false; - // try { - // await I_ERC20DividendCheckpoint.pushDividendPayment(0, 0, 10, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because dividend index has maturity in future`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { - // let errorThrown = false; - // // Increase time by 2 day - // await increaseTime(duration.days(2)); - // try { - // await I_ERC20DividendCheckpoint.pushDividendPayment(0, 0, 10, {from: account_temp}); - // } catch(error) { - // console.log(` tx -> failed because msg.sender is not the owner`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { - // let errorThrown = false; - // try { - // await I_ERC20DividendCheckpoint.pushDividendPayment(2, 0, 10, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because dividend index is greator than the dividend array length`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { - // let _dev = await I_ERC20DividendCheckpoint.dividends.call(0); - // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // await I_ERC20DividendCheckpoint.pushDividendPayment(0, 0, 10, {from: token_owner, gas: 5000000}); - // let investor1BalanceAfter = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2BalanceAfter = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // assert.equal(investor1BalanceAfter.sub(investor1Balance).toNumber(), web3.utils.toWei('0.5', 'ether')); - // assert.equal(investor2BalanceAfter.sub(investor2Balance).toNumber(), web3.utils.toWei('1', 'ether')); - // //Check fully claimed - // assert.equal((await I_ERC20DividendCheckpoint.dividends(0))[6].toNumber(), web3.utils.toWei('1.5', 'ether')); - // }); - // - // it("Buy some tokens for account_temp (1 ETH)", async() => { - // // Add the Investor in to the whitelist - // - // let tx = await I_GeneralTransferManager.modifyWhitelist( - // account_temp, - // latestTime(), - // latestTime(), - // latestTime() + duration.days(20), - // true, - // { - // from: account_issuer, - // gas: 500000 - // }); - // - // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_temp.toLowerCase(), "Failed in adding the investor in whitelist"); - // - // // Mint some tokens - // await I_SecurityToken.mint(account_temp, web3.utils.toWei('1', 'ether'), { from: token_owner }); - // - // assert.equal( - // (await I_SecurityToken.balanceOf(account_temp)).toNumber(), - // web3.utils.toWei('1', 'ether') - // ); - // }); - // - // it("Create new dividend", async() => { - // let maturity = latestTime() + duration.days(1); - // let expiry = latestTime() + duration.days(10); - // await I_PolyToken.getTokens(web3.utils.toWei('1.5', 'ether'), token_owner); - // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('1.5', 'ether'), {from: token_owner}); - // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 2, "Dividend should be created at checkpoint 1"); - // }); - // - // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { - // let errorThrown = false; - // await increaseTime(duration.days(12)); - // try { - // await I_ERC20DividendCheckpoint.pushDividendPayment(1, 0, 10, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because dividend index has passed its expiry`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Issuer pushes dividends iterating over account holders - dividends proportional to checkpoint", async() => { - // let errorThrown = false; - // let tx = await I_ERC20DividendCheckpoint.reclaimDividend(1, {from: token_owner, gas: 500000}); - // assert.equal((tx.logs[0].args._claimedAmount).toNumber(), web3.utils.toWei("1.5", "ether")); - // try { - // await I_ERC20DividendCheckpoint.reclaimDividend(1, {from: token_owner, gas: 500000}); - // } catch(error) { - // console.log(` tx -> failed because dividend index has already reclaimed`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Buy some tokens for account_investor3 (7 ETH)", async() => { - // // Add the Investor in to the whitelist - // - // let tx = await I_GeneralTransferManager.modifyWhitelist( - // account_investor3, - // latestTime(), - // latestTime(), - // latestTime() + duration.days(10), - // true, - // { - // from: account_issuer, - // gas: 500000 - // }); - // - // assert.equal(tx.logs[0].args._investor.toLowerCase(), account_investor3.toLowerCase(), "Failed in adding the investor in whitelist"); - // - // // Mint some tokens - // await I_SecurityToken.mint(account_investor3, web3.utils.toWei('7', 'ether'), { from: token_owner }); - // - // assert.equal( - // (await I_SecurityToken.balanceOf(account_investor3)).toNumber(), - // web3.utils.toWei('7', 'ether') - // ); - // }); - // - // it("Create another new dividend", async() => { - // let maturity = latestTime(); - // let expiry = latestTime() + duration.days(10); - // await I_PolyToken.getTokens(web3.utils.toWei('11', 'ether'), token_owner); - // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('11', 'ether'), {from: token_owner}); - // let tx = await I_ERC20DividendCheckpoint.createDividend(maturity, expiry, I_PolyToken.address, web3.utils.toWei('11', 'ether'), {from: token_owner}); - // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 3, "Dividend should be created at checkpoint 2"); - // }); - // - // it("should investor 3 claims dividend", async() => { - // let errorThrown = false; - // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // try { - // await I_ERC20DividendCheckpoint.pullDividendPayment(5, {from: account_investor3, gasPrice: 0}); - // } catch(error) { - // console.log(` tx -> failed because dividend index is not valid`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("should investor 3 claims dividend", async() => { - // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // await I_ERC20DividendCheckpoint.pullDividendPayment(2, {from: account_investor3, gasPrice: 0}); - // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // assert.equal(investor1BalanceAfter1.sub(investor1Balance).toNumber(), 0); - // assert.equal(investor2BalanceAfter1.sub(investor2Balance).toNumber(), 0); - // assert.equal(investor3BalanceAfter1.sub(investor3Balance).toNumber(), web3.utils.toWei('7', 'ether')); - // }); - // - // it("should investor 3 claims dividend", async() => { - // let errorThrown = false; - // try { - // await I_ERC20DividendCheckpoint.pullDividendPayment(2, {from: account_investor3, gasPrice: 0}); - // } catch(error) { - // console.log(` tx -> failed because investor already claimed the dividend`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("should issuer pushes remain", async() => { - // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // await I_ERC20DividendCheckpoint.pushDividendPayment(2, 0, 10, {from: token_owner}); - // let investor1BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // assert.equal(investor1BalanceAfter2.sub(investor1BalanceAfter1).toNumber(), 0); - // assert.equal(investor2BalanceAfter2.sub(investor2BalanceAfter1).toNumber(), web3.utils.toWei('3', 'ether')); - // assert.equal(investor3BalanceAfter2.sub(investor3BalanceAfter1).toNumber(), 0); - // //Check fully claimed - // assert.equal((await I_ERC20DividendCheckpoint.dividends(2))[6].toNumber(), web3.utils.toWei('11', 'ether')); - // }); - // - // it("Investor 2 transfers 1 ETH of his token balance to investor 1", async() => { - // await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), {from: account_investor2}); - // assert.equal(await I_SecurityToken.balanceOf(account_investor1), web3.utils.toWei('1', 'ether')); - // assert.equal(await I_SecurityToken.balanceOf(account_investor2), web3.utils.toWei('2', 'ether')); - // assert.equal(await I_SecurityToken.balanceOf(account_investor3), web3.utils.toWei('7', 'ether')); - // }); - // - // it("Create another new dividend with explicit", async() => { - // let errorThrown = false; - // let maturity = latestTime(); - // let expiry = latestTime() + duration.days(2); - // let tx = await I_SecurityToken.createCheckpoint({from: token_owner}); - // await I_PolyToken.getTokens(web3.utils.toWei('20', 'ether'), token_owner); - // try { - // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 4, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because allowance is not provided`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Create another new dividend with explicit", async() => { - // let errorThrown = false; - // let maturity = latestTime(); - // let expiry = latestTime() - duration.days(10); - // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('20', 'ether'), {from: token_owner}); - // try { - // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 4, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because maturity > expiry`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Create another new dividend with explicit", async() => { - // let errorThrown = false; - // let maturity = latestTime() - duration.days(5); - // let expiry = latestTime() - duration.days(2); - // try { - // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 4, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because now > expiry`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Create another new dividend with explicit", async() => { - // let errorThrown = false; - // let maturity = latestTime(); - // let expiry = latestTime() + duration.days(2); - // try { - // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('20', 'ether'), 5, {from: token_owner}); - // } catch(error) { - // console.log(` tx -> failed because checkpoint id > current checkpoint`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Create another new dividend with explicit", async() => { - // let maturity = latestTime(); - // let expiry = latestTime() + duration.days(10); - // let tx = await I_SecurityToken.createCheckpoint({from: token_owner}); - // await I_PolyToken.getTokens(web3.utils.toWei('11', 'ether'), token_owner); - // await I_PolyToken.approve(I_ERC20DividendCheckpoint.address, web3.utils.toWei('11', 'ether'), {from: token_owner}); - // tx = await I_ERC20DividendCheckpoint.createDividendWithCheckpoint(maturity, expiry, I_PolyToken.address, web3.utils.toWei('11', 'ether'), 4, {from: token_owner}); - // assert.equal(tx.logs[0].args._checkpointId.toNumber(), 4, "Dividend should be created at checkpoint 3"); - // }); - // - // it("Investor 2 claims dividend, issuer pushes investor 1", async() => { - // let errorThrown = false; - // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // try { - // await I_ERC20DividendCheckpoint.pushDividendPaymentToAddresses(2, [account_investor2, account_investor1],{from: account_investor2, gasPrice: 0}); - // } catch(error) { - // console.log(` tx -> failed because not called by the owner`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Investor 2 claims dividend, issuer pushes investor 1", async() => { - // let errorThrown = false; - // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // try { - // await I_ERC20DividendCheckpoint.pushDividendPaymentToAddresses(5, [account_investor2, account_investor1],{from: token_owner, gasPrice: 0}); - // } catch(error) { - // console.log(` tx -> failed because dividend index is not valid`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("should calculate dividend before the push dividend payment", async() => { - // let dividendAmount1 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor1); - // let dividendAmount2 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor2); - // let dividendAmount3 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor3); - // let dividendAmount_temp = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_temp); - // assert.equal(dividendAmount1.toNumber(), web3.utils.toWei("1", "ether")); - // assert.equal(dividendAmount2.toNumber(), web3.utils.toWei("2", "ether")); - // assert.equal(dividendAmount3.toNumber(), web3.utils.toWei("7", "ether")); - // assert.equal(dividendAmount_temp.toNumber(), web3.utils.toWei("1", "ether")); - // }); - // - // it("Investor 2 claims dividend", async() => { - // let investor1Balance = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2Balance = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3Balance = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // let tempBalance = BigNumber(await web3.eth.getBalance(account_temp)); - // await I_ERC20DividendCheckpoint.pullDividendPayment(3, {from: account_investor2, gasPrice: 0}); - // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // let tempBalanceAfter1 = BigNumber(await web3.eth.getBalance(account_temp)); - // assert.equal(investor1BalanceAfter1.sub(investor1Balance).toNumber(), 0); - // assert.equal(investor2BalanceAfter1.sub(investor2Balance).toNumber(), web3.utils.toWei('2', 'ether')); - // assert.equal(investor3BalanceAfter1.sub(investor3Balance).toNumber(), 0); - // assert.equal(tempBalanceAfter1.sub(tempBalance).toNumber(), 0); - // }); - // - // it("Should issuer pushes investor 1 and temp investor", async() => { - // let investor1BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3BalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // let tempBalanceAfter1 = BigNumber(await I_PolyToken.balanceOf(account_temp)); - // await I_ERC20DividendCheckpoint.pushDividendPaymentToAddresses(3, [account_temp, account_investor1], {from: token_owner}); - // let investor1BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor1)); - // let investor2BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor2)); - // let investor3BalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_investor3)); - // let tempBalanceAfter2 = BigNumber(await I_PolyToken.balanceOf(account_temp)); - // assert.equal(investor1BalanceAfter2.sub(investor1BalanceAfter1).toNumber(), web3.utils.toWei('1', 'ether')); - // assert.equal(investor2BalanceAfter2.sub(investor2BalanceAfter1).toNumber(), 0); - // assert.equal(investor3BalanceAfter2.sub(investor3BalanceAfter1).toNumber(), 0); - // assert.equal(tempBalanceAfter2.sub(tempBalanceAfter1).toNumber(), web3.utils.toWei('1', 'ether')); - // //Check fully claimed - // assert.equal((await I_ERC20DividendCheckpoint.dividends(3))[6].toNumber(), web3.utils.toWei('4', 'ether')); - // }); - // - // it("should calculate dividend after the push dividend payment", async() => { - // let dividendAmount1 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor1); - // let dividendAmount2 = await I_ERC20DividendCheckpoint.calculateDividend.call(3, account_investor2); - // assert.equal(dividendAmount1.toNumber(), 0); - // assert.equal(dividendAmount2.toNumber(), 0); - // }); - // - // it("Issuer unable to reclaim dividend (expiry not passed)", async() => { - // let errorThrown = false; - // try { - // await I_ERC20DividendCheckpoint.reclaimDividend(3, {from: token_owner}); - // } catch(error) { - // console.log(`Tx Failed because expiry is in the future ${0}. Test Passed Successfully`); - // errorThrown = true; - // ensureException(error); - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Issuer is able to reclaim dividend after expiry", async() => { - // let errorThrown = false; - // await increaseTime(11 * 24 * 60 * 60); - // try { - // await I_ERC20DividendCheckpoint.reclaimDividend(8, {from: token_owner, gasPrice: 0}); - // } catch(error) { - // console.log(` tx -> failed because dividend index is not valid`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Issuer is able to reclaim dividend after expiry", async() => { - // let tokenOwnerBalance = BigNumber(await I_PolyToken.balanceOf(token_owner)); - // await I_ERC20DividendCheckpoint.reclaimDividend(3, {from: token_owner, gasPrice: 0}); - // let tokenOwnerAfter = BigNumber(await I_PolyToken.balanceOf(token_owner)); - // assert.equal(tokenOwnerAfter.sub(tokenOwnerBalance).toNumber(), web3.utils.toWei('7', 'ether')); - // }); - // - // - // it("Issuer is able to reclaim dividend after expiry", async() => { - // let errorThrown = false; - // let tokenOwnerBalance = BigNumber(await I_PolyToken.balanceOf(token_owner)); - // try { - // await I_ERC20DividendCheckpoint.reclaimDividend(3, {from: token_owner, gasPrice: 0}); - // } catch(error) { - // console.log(` tx -> failed because dividend are already reclaimed`.grey); - // ensureException(error); - // errorThrown = true; - // } - // assert.ok(errorThrown, message); - // }); - // - // it("Investor 3 unable to pull dividend after expiry", async() => { - // let errorThrown = false; - // try { - // await I_ERC20DividendCheckpoint.pullDividendPayment(3, {from: account_investor3, gasPrice: 0}); - // } catch(error) { - // console.log(`Tx Failed because expiry is in the past ${0}. Test Passed Successfully`); - // errorThrown = true; - // ensureException(error); - // } - // assert.ok(errorThrown, message); - // - // }); - // - // it("Should give the right dividend index", async() => { - // let index = await I_ERC20DividendCheckpoint.getDividendIndex.call(3); - // assert.equal(index[0], 2); - // }); - // - // it("Should give the right dividend index", async() => { - // let index = await I_ERC20DividendCheckpoint.getDividendIndex.call(8); - // assert.equal(index.length, 0); - // }); - // - // it("Get the init data", async() => { - // let tx = await I_ERC20DividendCheckpoint.getInitFunction.call(); - // assert.equal(web3.utils.toAscii(tx).replace(/\u0000/g, ''),0); - // }); - // - // it("Should get the listed permissions", async() => { - // let tx = await I_ERC20DividendCheckpoint.getPermissions.call(); - // assert.equal(tx.length,1); - // }); - // - // describe("Test cases for the ERC20DividendCheckpointFactory", async() => { - // it("should get the exact details of the factory", async() => { - // assert.equal((await I_ERC20DividendCheckpointFactory.setupCost.call()).toNumber(), 0); - // assert.equal(await I_ERC20DividendCheckpointFactory.getType.call(), 4); - // assert.equal(web3.utils.toAscii(await I_ERC20DividendCheckpointFactory.getName.call()) - // .replace(/\u0000/g, ''), - // "ERC20DividendCheckpoint", - // "Wrong Module added"); - // assert.equal(await I_ERC20DividendCheckpointFactory.getDescription.call(), - // "Create ERC20 dividends for token holders at a specific checkpoint", - // "Wrong Module added"); - // assert.equal(await I_ERC20DividendCheckpointFactory.getTitle.call(), - // "ERC20 Dividend Checkpoint", - // "Wrong Module added"); - // assert.equal(await I_ERC20DividendCheckpointFactory.getInstructions.call(), - // "Create a ERC20 dividend which will be paid out to token holders proportional to their balances at the point the dividend is created", - // "Wrong Module added"); - // let tags = await I_ERC20DividendCheckpointFactory.getTags.call(); - // assert.equal(tags.length, 3); - // - // }); - // }); - - }); - }); From fa1ccd950d0a21455e3dc46bc14954aafda252b0 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Tue, 2 Oct 2018 17:07:35 -0700 Subject: [PATCH 37/57] Check to see if there are tokens to transfer before actually transferring them --- .../modules/Wallet/VestingEscrowWallet.sol | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 3f04c0dd6..cb59e325d 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -10,7 +10,7 @@ import "../../interfaces/ISecurityToken.sol"; contract VestingEscrowWallet is IWallet { using SafeMath for uint; - bytes32 public constant ISSUER = "ISSUER"; + bytes32 public constant ISSUER = "ISSUER"; // TODO: Is this needed? address public treasury; uint256 public numExcessTokens; uint256 public templateCount; @@ -230,19 +230,23 @@ contract VestingEscrowWallet is IWallet { delete individualVestingDetails[_target][_whichVestingSchedule]; // Send vested, unclaimed tokens to the target - require(ISecurityToken(securityToken).transferFrom( - address(this), - _target, - _tokensToDistribute), "Unable to transfer tokens"); - - // Send extra tokens to the treasury or hold them in the contract - if (_isReclaiming) { + if (_tokensToDistribute != 0) { require(ISecurityToken(securityToken).transferFrom( address(this), - treasury, - _numUnvestedTokens), "Unable to transfer tokens"); - } else { - numExcessTokens = numExcessTokens.add(_numUnvestedTokens); + _target, + _tokensToDistribute), "Unable to transfer tokens"); + } + + // Send extra tokens to the treasury or hold them in the contract + if (_numUnvestedTokens != 0) { + if (_isReclaiming) { + require(ISecurityToken(securityToken).transferFrom( + address(this), + treasury, + _numUnvestedTokens), "Unable to transfer tokens"); + } else { + numExcessTokens = numExcessTokens.add(_numUnvestedTokens); + } } emit VestingCancelled( From b2940455111c50376edb12d116c44daeacb1fbfa Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Wed, 3 Oct 2018 12:29:42 -0700 Subject: [PATCH 38/57] Update transferFrom to transfer for contract -> payee transactions --- contracts/modules/Wallet/VestingEscrowWallet.sol | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index cb59e325d..2fd247291 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -231,8 +231,7 @@ contract VestingEscrowWallet is IWallet { // Send vested, unclaimed tokens to the target if (_tokensToDistribute != 0) { - require(ISecurityToken(securityToken).transferFrom( - address(this), + require(ISecurityToken(securityToken).transfer( _target, _tokensToDistribute), "Unable to transfer tokens"); } @@ -240,8 +239,7 @@ contract VestingEscrowWallet is IWallet { // Send extra tokens to the treasury or hold them in the contract if (_numUnvestedTokens != 0) { if (_isReclaiming) { - require(ISecurityToken(securityToken).transferFrom( - address(this), + require(ISecurityToken(securityToken).transfer( treasury, _numUnvestedTokens), "Unable to transfer tokens"); } else { From d75e4addbfd5e08362631baa8310a4653a7d974f Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 4 Oct 2018 20:22:22 -0700 Subject: [PATCH 39/57] Change transferFrom to transfer --- contracts/modules/Wallet/VestingEscrowWallet.sol | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 2fd247291..67d7cd14a 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -240,7 +240,8 @@ contract VestingEscrowWallet is IWallet { if (_numUnvestedTokens != 0) { if (_isReclaiming) { require(ISecurityToken(securityToken).transfer( - treasury, + // treasury, + msg.sender, _numUnvestedTokens), "Unable to transfer tokens"); } else { numExcessTokens = numExcessTokens.add(_numUnvestedTokens); @@ -297,11 +298,8 @@ contract VestingEscrowWallet is IWallet { require(_tokensToDistribute != 0, "No tokens remain"); _vestingSchedule.numClaimedVestedTokens = _vestingSchedule.numClaimedVestedTokens.add(_tokensToDistribute); - _vestingSchedule.numUnclaimedVestedTokens = _vestingSchedule.numUnclaimedVestedTokens.sub(_tokensToDistribute); - - require(ISecurityToken(securityToken).transferFrom( - address(this), + require(ISecurityToken(securityToken).transfer( _target, _tokensToDistribute), "Unable to transfer tokens"); From 51739e4233b4916b4ddd073982b1ee67102eb653 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 4 Oct 2018 20:23:44 -0700 Subject: [PATCH 40/57] All tests complete --- test/u_vesting_escrow_wallet.js | 239 +++++++++++++++++++++----------- 1 file changed, 161 insertions(+), 78 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index 8158d017f..dc0945db6 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -77,6 +77,18 @@ contract('VestingEscrowWallet', accounts => { // Initial fee for ticker registry and security token registry const initRegFee = web3.utils.toWei("250"); + let treasury = accounts[9]; + + let bytesSTO = web3.eth.abi.encodeFunctionCall({ + name: 'configure', + type: 'function', + inputs: [{ + type: 'address', + name: '_treasury' + } + ] + }, [treasury]); + before(async() => { // Accounts setup account_polymath = accounts[0]; @@ -89,6 +101,7 @@ contract('VestingEscrowWallet', accounts => { employee3 = accounts[8]; account_temp = accounts[2]; + // ----------- POLYMATH NETWORK Configuration ------------ // Step 0: Deploy the PolymathRegistry @@ -259,7 +272,7 @@ contract('VestingEscrowWallet', accounts => { it("Should successfully attach the VestingEscrowWallet with the security token", async () => { let errorThrown = false; try { - const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); + const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, bytesSTO, web3.utils.toWei("500", "ether"), 0, { from: token_owner }); } catch(error) { console.log(` tx -> failed because Token is not paid`.grey); ensureException(error); @@ -272,7 +285,7 @@ contract('VestingEscrowWallet', accounts => { let snapId = await takeSnapshot() await I_PolyToken.getTokens(web3.utils.toWei("500", "ether"), token_owner); await I_PolyToken.transfer(I_SecurityToken.address, web3.utils.toWei("500", "ether"), {from: token_owner}); - const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, "", web3.utils.toWei("500", "ether"), 0, { from: token_owner }); + const tx = await I_SecurityToken.addModule(P_VestingEscrowWalletFactory.address, bytesSTO, web3.utils.toWei("500", "ether"), 0, { from: token_owner }); assert.equal(tx.logs[3].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); assert.equal( web3.utils.toAscii(tx.logs[3].args._name) @@ -285,7 +298,7 @@ contract('VestingEscrowWallet', accounts => { }); it("Should successfully attach the VestingEscrowWallet with the security token", async () => { - const tx = await I_SecurityToken.addModule(I_VestingEscrowWalletFactory.address, "", 0, 0, { from: token_owner }); + const tx = await I_SecurityToken.addModule(I_VestingEscrowWalletFactory.address, bytesSTO, 0, 0, { from: token_owner }); assert.equal(tx.logs[2].args._type.toNumber(), walletKey, "VestingEscrowWallet doesn't get deployed"); assert.equal( web3.utils.toAscii(tx.logs[2].args._name) @@ -341,11 +354,11 @@ contract('VestingEscrowWallet', accounts => { context("Initiate Vesting Schedule", async() => { it("Should whitelist all relevant parties", async() => { let tx = await I_GeneralTransferManager.modifyWhitelistMulti( - [token_owner, employee1, employee2, employee3, I_VestingEscrowWallet.address], - [latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], - [latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], - [latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10),latestTime() + duration.days(10)], - [true, true, true, true, true], + [token_owner, employee1, employee2, employee3, I_VestingEscrowWallet.address, treasury], + [latestTime(),latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], + [latestTime(),latestTime(),latestTime(),latestTime(),latestTime(),latestTime()], + [latestTime() + duration.years(20),latestTime() + duration.years(20),latestTime() + duration.years(20),latestTime() + duration.years(20),latestTime() + duration.years(20),latestTime() + duration.years(20)], + [true, true, true, true, true, true], { from: token_owner, gas: 6000000 @@ -356,6 +369,8 @@ contract('VestingEscrowWallet', accounts => { assert.equal(tx.logs[2].args._investor, employee2); assert.equal(tx.logs[3].args._investor, employee3); assert.equal(tx.logs[4].args._investor, I_VestingEscrowWallet.address); + assert.equal(tx.logs[5].args._investor, treasury); + }); it("Should mint tokens for the token_owner and approve the contract address", async() => { @@ -400,7 +415,7 @@ contract('VestingEscrowWallet', accounts => { try { let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); } catch(error) { - console.log(` tx -> failed because arrays ar unequal`.grey); + console.log(` tx -> failed because arrays are unequal`.grey); Object.keys(error).forEach(function (key){ ensureException(error[key]); }); @@ -445,7 +460,7 @@ contract('VestingEscrowWallet', accounts => { try { let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); } catch(error) { - console.log(` tx -> failed because a target input was 0`.grey); + console.log(` tx -> failed because a totalAllocation input was 0`.grey); Object.keys(error).forEach(function (key){ ensureException(error[key]); }); @@ -467,7 +482,7 @@ contract('VestingEscrowWallet', accounts => { try { let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); } catch(error) { - console.log(` tx -> failed because a target input was 0`.grey); + console.log(` tx -> failed because a vestingDuration input was 0`.grey); Object.keys(error).forEach(function (key){ ensureException(error[key]); }); @@ -489,7 +504,7 @@ contract('VestingEscrowWallet', accounts => { try { let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); } catch(error) { - console.log(` tx -> failed because a target input was 0`.grey); + console.log(` tx -> failed because a startDate input was 0`.grey); Object.keys(error).forEach(function (key){ ensureException(error[key]); }); @@ -531,7 +546,7 @@ contract('VestingEscrowWallet', accounts => { try { let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); } catch(error) { - console.log(` tx -> failed because a target input was 0`.grey); + console.log(` tx -> failed because a vestingFrequency was greater than the associated vestingDuration`.grey); Object.keys(error).forEach(function (key){ ensureException(error[key]); }); @@ -539,7 +554,7 @@ contract('VestingEscrowWallet', accounts => { } assert.ok(errorThrown, message); }); - it("Should fail to initiate a vesting schedule because a vestingFrequency was not a whole factor of the associated vestingDuration ", async() => { + it("Should fail to initiate a vesting schedule because a vestingFrequency was not a whole factor of the associated vestingDuration", async() => { let errorThrown = false; let target = [employee1, employee2, employee3] let totalAllocation = ['16', '20', '24']; @@ -553,7 +568,7 @@ contract('VestingEscrowWallet', accounts => { try { let tx = await I_VestingEscrowWallet.initiateVestingSchedule(params[0], params[1], params[2], params[3], params[4], {from: token_owner}); } catch(error) { - console.log(` tx -> failed because a target input was 0`.grey); + console.log(` tx -> failed because a vestingFrequency was not a whole factor of the associated vestingDuration`.grey); Object.keys(error).forEach(function (key){ ensureException(error[key]); }); @@ -716,7 +731,7 @@ contract('VestingEscrowWallet', accounts => { try { let tx = await I_VestingEscrowWallet.initiateVestingScheduleFromTemplate(target, templateNumber, startDate, {from: token_owner}); } catch(error) { - console.log(` tx -> failed because caller is not the issuer`.grey); + console.log(` tx -> failed because a target input was 0`.grey); Object.keys(error).forEach(function (key){ ensureException(error[key]); }); @@ -725,15 +740,15 @@ contract('VestingEscrowWallet', accounts => { assert.ok(errorThrown, message); }); it("Create a vesting schedule for an employee based on a template", async() => { - let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); - let target = [employee1, employee2, employee3] - let templateNumber = 0; - let startDate = latestTime() + duration.days(1) + let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + let target = [employee1, employee2, employee3] + let templateNumber = 0; + let startDate = latestTime() + duration.days(1) - let tx = await I_VestingEscrowWallet.initiateVestingScheduleFromTemplate(target, templateNumber, startDate, {from: token_owner}); - let newScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + let tx = await I_VestingEscrowWallet.initiateVestingScheduleFromTemplate(target, templateNumber, startDate, {from: token_owner}); + let newScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); - assert.equal(currentScheduleCount.add(1).toNumber(), newScheduleCount.toNumber(), "Schedule count did not get updated") + assert.equal(currentScheduleCount.add(1).toNumber(), newScheduleCount.toNumber(), "Schedule count did not get updated") }); it("Create a vesting schedule for multiple employees based on a template", async() => { let currentScheduleCountOne = await I_VestingEscrowWallet.individualVestingCount(employee1); @@ -754,64 +769,132 @@ contract('VestingEscrowWallet', accounts => { assert.equal(currentScheduleCountThree.add(1).toNumber(), newScheduleCountThree.toNumber(), "Schedule count did not get updated") }); it("Save vesting schedule for a specific employee in individualVestingDetails", async() => { - let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); - let tx = await I_VestingEscrowWallet.individualVestingDetails(employee1, currentScheduleCount.sub(1)); - let totalAllocation = tx[1].toNumber(); + let tx = await I_VestingEscrowWallet.individualVestingDetails(employee1, currentScheduleCount.sub(1)); + let totalAllocation = tx[1].toNumber(); - assert.equal(totalAllocation, web3.utils.toWei('10', 'ether'), "Schedule did not get stored"); + assert.equal(totalAllocation, web3.utils.toWei('10', 'ether'), "Schedule did not get stored"); }); }); - // context("Cancel Vesting Scheduel", async() => { - // it("Should fail to cancel a vesting schedule because the caller is not the owner", async() => { - // }); - // it("Should fail to cancel a vesting schedule because it does not exist", async() => { - // }); - // it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the employee", async() => { - // }); - // it("Should fail to cancel a vesting schedule because the contract does not have the required number of tokens to send to the treasury", async() => { - // }); - // it("Cancel a vesting schedule", async() => { - // }); - // it("Delete the individualVestingDetails from storage", async() => { - // }); - // it("Send vested, unclaimed tokens to the employee", async() => { - // }); - // it("Send unvested tokens to the treasury if the issuer wants to reclaim them", async() => { - // }); - // it("Keep tokens in the contract and update numExcessTokens if the issuer sets _isReclaiming false", async() => { - // }); - // }) - // context("Collect Vested Tokens", async() => { - // it("Should fail to collect because a vesting schedule does not exist", async() => { - // }); - // it("Should fail to collect because there are no remaining tokens to claim", async() => { - // }); - // it("Should fail to collect because the contract does not have the required number of tokens to send to the employee", async() => { - // }); - // it("Send vested tokens to the employee", async() => { - // }); - // it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { - // }); - // it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { - // }); - // it("Send vested, unclaimed tokens to the employee", async() => { - // }); - // }) - // context("Push Vested Tokens", async() => { - // it("Should fail to push because a vesting schedule does not exist", async() => { - // }); - // it("Should fail to push because there are no remaining tokens to claim", async() => { - // }); - // it("Should fail to push because the contract does not have the required number of tokens to send to the employee", async() => { - // }); - // it("Send vested tokens to the employee", async() => { - // }); - // it("Update the numClaimedVestedTokens for that employee's specific vesting schedule", async() => { - // }); - // it("Update the numUnclaimedVestedTokens for that employee's specific vesting schedule", async() => { - // }); - // it("Send vested, unclaimed tokens to the employee", async() => { - // }); + context("Cancel Vesting Scheduel", async() => { + it("Should fail to cancel a vesting schedule because the caller is not the owner", async() => { + let errorThrown = false; + let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + currentScheduleCount = currentScheduleCount.sub(1); + try { + await I_VestingEscrowWallet.cancelVestingSchedule(employee1, currentScheduleCount, false, {from: employee1}); + } catch(error) { + console.log(` tx -> failed because caller is not the issuer`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Should fail to cancel a vesting schedule because it does not exist", async() => { + let errorThrown = false; + let nonexistentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + nonexistentScheduleCount = nonexistentScheduleCount.add(1); + try { + await I_VestingEscrowWallet.cancelVestingSchedule(employee1, nonexistentScheduleCount, false, {from: token_owner}); + } catch(error) { + console.log(` tx -> failed because veasting schedule does not exist`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Delete the individualVestingDetails from storage", async() => { + let currentScheduleCount = await I_VestingEscrowWallet.individualVestingCount(employee1); + currentScheduleCount = currentScheduleCount.sub(1); + + let tx = await I_VestingEscrowWallet.individualVestingDetails(employee1, currentScheduleCount); + let totalAllocation = tx[1].toNumber(); + + assert.equal(totalAllocation, web3.utils.toWei('10', 'ether'), "Schedule did not get stored"); + + await I_VestingEscrowWallet.cancelVestingSchedule(employee1, currentScheduleCount, false, {from: token_owner}); + + tx = await I_VestingEscrowWallet.individualVestingDetails(employee1, currentScheduleCount); + totalAllocation = tx[1].toNumber(); + + assert.equal(totalAllocation, 0, "Schedule did not get deleted") + }); + it("Send unvested tokens to the treasury if the issuer wants to reclaim them", async() => { + await increaseTime(duration.years(10)); + + let employee1InitialBalance = await I_SecurityToken.balanceOf(employee1); + let treasuryInitialBalance = await I_SecurityToken.balanceOf(token_owner); + + await I_VestingEscrowWallet.cancelVestingSchedule(employee1, 4, true, {from: token_owner}); + + let employee1NewBalance = await I_SecurityToken.balanceOf(employee1); + let treasuryNewBalance = await I_SecurityToken.balanceOf(token_owner); + + // Send 5 vested tokens to the employee and the remaining 35 to the treasury + let expectedEmployeeTokens = new BigNumber(5e18); + let expectedTreasuryTokens = new BigNumber(35e18); + + assert.equal(employee1NewBalance.sub(employee1InitialBalance).valueOf(), expectedEmployeeTokens.valueOf(), "Employee did not get their tokens.") + assert.equal(treasuryNewBalance.sub(treasuryInitialBalance).valueOf(), expectedTreasuryTokens.valueOf(), "Treasury did not get their tokens."); + }); + it("Keep tokens in the contract if the issuer sets _isReclaiming false", async() => { + let employee3InitialBalance = await I_SecurityToken.balanceOf(employee3); + let contractInitialBalance = await I_SecurityToken.balanceOf(I_VestingEscrowWallet.address); + + await I_VestingEscrowWallet.cancelVestingSchedule(employee3, 2, false, {from: token_owner}); + + let employee3NewBalance = await I_SecurityToken.balanceOf(employee3); + let contractNewBalance = await I_SecurityToken.balanceOf(I_VestingEscrowWallet.address); + + let expectedEmployeeTokens = new BigNumber(5e18); + assert.equal(employee3NewBalance.sub(employee3InitialBalance).valueOf(), expectedEmployeeTokens.valueOf(), "Employee did not get their tokens.") + assert.equal(contractNewBalance.valueOf(), contractInitialBalance.valueOf(), "Contract did not keep its tokens"); + }); + }) + context("Collect Vested Tokens", async() => { + it("Should fail to collect because a vesting schedule does not exist", async() => { + let errorThrown = false; + + try { + await I_VestingEscrowWallet.collectVestedTokens(1000, {from: employee2}); + } catch(error) { + console.log(` tx -> failed because a vestingFrequency was not a whole factor of the associated vestingDuration`.grey); + Object.keys(error).forEach(function (key){ + ensureException(error[key]); + }); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + it("Send vested tokens to the employee", async() => { + let employee2InitialBalance = await I_SecurityToken.balanceOf(employee2); + + await I_VestingEscrowWallet.collectVestedTokens(0, {from: employee2}); + + let employee2NewBalance = await I_SecurityToken.balanceOf(employee2); + + let expectedGains = new BigNumber(5e18); + + assert.equal(employee2InitialBalance.plus(expectedGains).valueOf(), employee2NewBalance.valueOf(), "Tokens did not get claimed") + }); }) + context("Push Vested Tokens", async() => { + it("Should function in the exact same manner as collectVestedTokens, except they are pushed by the owner", async() => { + let employee3InitialBalance = await I_SecurityToken.balanceOf(employee3); + + await I_VestingEscrowWallet.pushVestedTokens(employee3, 0, {from: token_owner}); + + let employee3NewBalance = await I_SecurityToken.balanceOf(employee3); + + let expectedGains = new BigNumber(6e18); + + assert.equal(employee3InitialBalance.plus(expectedGains).valueOf(), employee3NewBalance.valueOf(), "Tokens did not get claimed") + }); + }); + }); }); From 357e13408ea448bc870b99acfde0d42a7940f9ae Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 4 Oct 2018 20:25:04 -0700 Subject: [PATCH 41/57] Clean up code --- contracts/modules/Wallet/VestingEscrowWallet.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 67d7cd14a..13b06aaf3 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -10,7 +10,7 @@ import "../../interfaces/ISecurityToken.sol"; contract VestingEscrowWallet is IWallet { using SafeMath for uint; - bytes32 public constant ISSUER = "ISSUER"; // TODO: Is this needed? + bytes32 public constant ISSUER = "ISSUER"; address public treasury; uint256 public numExcessTokens; uint256 public templateCount; From e7b1a6aa756066a4fada644f3e7957ba5670a37e Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 09:44:29 -0700 Subject: [PATCH 42/57] Add address typecast --- contracts/modules/Wallet/VestingEscrowWallet.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 13b06aaf3..426285f20 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -105,7 +105,7 @@ contract VestingEscrowWallet is IWallet { * @param _treasury Treasury wallet to send excess funds */ function configure(address _treasury) public onlyFactory { - require(_treasury != 0, "Treasury should not be 0"); + require(_treasury != address(0), "Treasury should not be 0"); treasury = _treasury; } From 5c5702064f2934c9e8036fd62088ec910b94f898 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 09:51:01 -0700 Subject: [PATCH 43/57] Add new initialization and checks --- contracts/modules/Wallet/VestingEscrowWallet.sol | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 426285f20..88d5f38fc 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -139,9 +139,11 @@ contract VestingEscrowWallet is IWallet { public onlyOwner { - vestingTemplates[templateCount].totalAllocation = _totalAllocation; - vestingTemplates[templateCount].vestingDuration = _vestingDuration; - vestingTemplates[templateCount].vestingFrequency = _vestingFrequency; + require(_totalAllocation != 0, "Total allocation was initialized to 0"); + require(_vestingDuration != 0, "Vesting duration was initialized to 0"); + require(_vestingFrequency != 0, "Vesting frequency was initialized to 0"); + + vestingTemplates[templateCount] = VestingTemplate(_totalAllocation, _vestingDuration, _vestingFrequency); emit AddTemplate( templateCount, From cebe11a01b64f9116e575c13914ef0678ec3b480 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 09:51:53 -0700 Subject: [PATCH 44/57] Indexed templateNumber --- contracts/modules/Wallet/VestingEscrowWallet.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 88d5f38fc..9091f4662 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -67,7 +67,7 @@ contract VestingEscrowWallet is IWallet { ); event AddTemplate( - uint256 templateNumber, + uint256 indexed templateNumber, uint256 totalAllocation, uint256 vestingDuration, uint256 vestingFrequency From eab0f5a062ed6b41e716c7ae4c3d7a89d5cea3dd Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:04:13 -0700 Subject: [PATCH 45/57] Remove event --- contracts/modules/Wallet/VestingEscrowWalletFactory.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol index ffef54847..47c6d3914 100644 --- a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol +++ b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol @@ -30,7 +30,6 @@ contract VestingEscrowWalletFactory is ModuleFactory { if (setupCost > 0) require(polyToken.transferFrom(msg.sender, owner, setupCost), "Failed transferFrom because of sufficent Allowance is not provided"); address vestingEscrwoWallet = new VestingEscrowWallet(msg.sender, address(polyToken)); - emit LogGenerateModuleFromFactory(vestingEscrwoWallet, getName(), address(this), msg.sender, setupCost, now); return vestingEscrwoWallet; } From 85cabb4ca9de883c5abe61522c7b9c71204bf1b1 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:06:43 -0700 Subject: [PATCH 46/57] Add withPerm() modifier to initiateVestingSchedule --- contracts/modules/Wallet/VestingEscrowWallet.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 9091f4662..c53a8f740 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -170,6 +170,7 @@ contract VestingEscrowWallet is IWallet { ) public onlyOwner + withPerm(ISSUER) { require(_target.length == _totalAllocation.length && _target.length == _vestingDuration.length && From baa5a888c90ae0aff89f3170741bdb979969650e Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:09:39 -0700 Subject: [PATCH 47/57] Remove emitting of 0 values --- contracts/modules/Wallet/VestingEscrowWallet.sol | 6 ------ 1 file changed, 6 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index c53a8f740..a894a6c15 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -59,10 +59,7 @@ contract VestingEscrowWallet is IWallet { uint256 vestingDuration, uint256 startDate, uint256 vestingFrequency, - uint256 numVestedTokens, - uint256 numUnvestedTokens, uint256 numClaimedVestedTokens, - uint256 numUnclaimedVestedTokens, uint256 tokensPerTranche ); @@ -393,10 +390,7 @@ contract VestingEscrowWallet is IWallet { _vestingDuration, _startDate, _vestingFrequency, - 0, _numUnvestedTokens, - 0, - 0, _tokensPerTranche ); } From e94d11063cf4dd05d994145ebd2c3fa60dc9e6a2 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:11:22 -0700 Subject: [PATCH 48/57] Add withPerm() to initiateVestingScheduleFromTemplate --- contracts/modules/Wallet/VestingEscrowWallet.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index a894a6c15..58b4a4371 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -196,6 +196,7 @@ contract VestingEscrowWallet is IWallet { ) public onlyOwner + withPerm(ISSUER) { VestingTemplate memory _vestingTemplate = vestingTemplates[_templateNumber]; From c300610b958e5da736bd38588835135e47707f06 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:15:33 -0700 Subject: [PATCH 49/57] Make initiateVestingScheduleIterate a public function with the withPerm() modifier --- .../modules/Wallet/VestingEscrowWallet.sol | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 58b4a4371..025912008 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -175,11 +175,11 @@ contract VestingEscrowWallet is IWallet { _target.length == _vestingFrequency.length); for (uint i = 0; i < _target.length; i++) { - _initiateVestingScheduleIterate(_target[i], - _totalAllocation[i], - _vestingDuration[i], - _startDate[i], - _vestingFrequency[i]); + initiateVestingScheduleIterate(_target[i], + _totalAllocation[i], + _vestingDuration[i], + _startDate[i], + _vestingFrequency[i]); } } @@ -202,11 +202,11 @@ contract VestingEscrowWallet is IWallet { for (uint i = 0; i < _target.length; i++) { require(_target[i] != address(0)); - _initiateVestingScheduleIterate(_target[i], - _vestingTemplate.totalAllocation, - _vestingTemplate.vestingDuration, - _startDate, - _vestingTemplate.vestingFrequency); + initiateVestingScheduleIterate(_target[i], + _vestingTemplate.totalAllocation, + _vestingTemplate.vestingDuration, + _startDate, + _vestingTemplate.vestingFrequency); } } @@ -320,14 +320,15 @@ contract VestingEscrowWallet is IWallet { * @param _startDate Start date of the vesting schedule * @param _vestingFrequency Frequency of release of tokens */ - function _initiateVestingScheduleIterate( + function initiateVestingScheduleIterate( address _target, uint256 _totalAllocation, uint256 _vestingDuration, uint256 _startDate, uint256 _vestingFrequency ) - internal + public + withPerm(ISSUER) { require(_target != address(0), "The target should be a valid addrss"); require(_totalAllocation != 0, "The total allocation should not be 0"); From f9677a55e39b5be27e9fd86490af6d868cac8b0f Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:18:00 -0700 Subject: [PATCH 50/57] Renamed _whichVestingSchedule to _vestingScheduleIndex --- .../modules/Wallet/VestingEscrowWallet.sol | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 025912008..822e36222 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -213,14 +213,14 @@ contract VestingEscrowWallet is IWallet { /** * @notice Cancel a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate - * @param _whichVestingSchedule Index of the vesting schedule for the target + * @param _vestingScheduleIndex Index of the vesting schedule for the target * @param _isReclaiming True if the issuer is reclaiming the tokens out of the contract */ - function cancelVestingSchedule(address _target, uint256 _whichVestingSchedule, bool _isReclaiming) + function cancelVestingSchedule(address _target, uint256 _vestingScheduleIndex, bool _isReclaiming) public onlyOwner { - VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; + VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_vestingScheduleIndex]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); @@ -228,7 +228,7 @@ contract VestingEscrowWallet is IWallet { uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); uint256 _numUnvestedTokens = _vestingSchedule.numUnvestedTokens.sub(_tokensToDistribute); - delete individualVestingDetails[_target][_whichVestingSchedule]; + delete individualVestingDetails[_target][_vestingScheduleIndex]; // Send vested, unclaimed tokens to the target if (_tokensToDistribute != 0) { @@ -251,7 +251,7 @@ contract VestingEscrowWallet is IWallet { emit VestingCancelled( _target, - _whichVestingSchedule, + _vestingScheduleIndex, _vestingId, _tokensToDistribute, _isReclaiming, @@ -261,35 +261,35 @@ contract VestingEscrowWallet is IWallet { /** * @notice Collect vested tokens - * @param _whichVestingSchedule Index of the vesting schedule for the target + * @param _vestingScheduleIndex Index of the vesting schedule for the target */ - function collectVestedTokens(uint256 _whichVestingSchedule) + function collectVestedTokens(uint256 _vestingScheduleIndex) public { - _distributeVestedTokens(msg.sender, _whichVestingSchedule); + _distributeVestedTokens(msg.sender, _vestingScheduleIndex); } /** * @notice Push vested tokens * @param _target Address of the employee or the affiliate - * @param _whichVestingSchedule Index of the vesting schedule for the target + * @param _vestingScheduleIndex Index of the vesting schedule for the target */ - function pushVestedTokens(address _target, uint256 _whichVestingSchedule) + function pushVestedTokens(address _target, uint256 _vestingScheduleIndex) public onlyOwner { - _distributeVestedTokens(_target, _whichVestingSchedule); + _distributeVestedTokens(_target, _vestingScheduleIndex); } /** * @notice Distribute vested tokens * @param _target Address of the employee or the affiliate - * @param _whichVestingSchedule Index of the vesting schedule for the target + * @param _vestingScheduleIndex Index of the vesting schedule for the target */ - function _distributeVestedTokens(address _target, uint256 _whichVestingSchedule) + function _distributeVestedTokens(address _target, uint256 _vestingScheduleIndex) internal { - VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_whichVestingSchedule]; + VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_vestingScheduleIndex]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); @@ -306,7 +306,7 @@ contract VestingEscrowWallet is IWallet { emit TokensCollected( _target, - _whichVestingSchedule, + _vestingScheduleIndex, _vestingSchedule.vestingId, _tokensToDistribute ); From ffb5587726a6bcc4cfc2e1e88dc7b3daf9843ef3 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:20:52 -0700 Subject: [PATCH 51/57] Renamed _isReclaiming to _revokeVestingSchedule --- contracts/modules/Wallet/VestingEscrowWallet.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 822e36222..9bd0de2ae 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -214,9 +214,9 @@ contract VestingEscrowWallet is IWallet { * @notice Cancel a vesting schedule for an employee or affiliate * @param _target Address of the employee or the affiliate * @param _vestingScheduleIndex Index of the vesting schedule for the target - * @param _isReclaiming True if the issuer is reclaiming the tokens out of the contract + * @param _revokeVestingSchedule True if the issuer is reclaiming the tokens out of the contract */ - function cancelVestingSchedule(address _target, uint256 _vestingScheduleIndex, bool _isReclaiming) + function cancelVestingSchedule(address _target, uint256 _vestingScheduleIndex, bool _revokeVestingSchedule) public onlyOwner { @@ -239,7 +239,7 @@ contract VestingEscrowWallet is IWallet { // Send extra tokens to the treasury or hold them in the contract if (_numUnvestedTokens != 0) { - if (_isReclaiming) { + if (_revokeVestingSchedule) { require(ISecurityToken(securityToken).transfer( // treasury, msg.sender, @@ -254,7 +254,7 @@ contract VestingEscrowWallet is IWallet { _vestingScheduleIndex, _vestingId, _tokensToDistribute, - _isReclaiming, + _revokeVestingSchedule, block.timestamp ); } From d20c7993168d5015c9eac2bc335be69944dee14e Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:25:08 -0700 Subject: [PATCH 52/57] Add compatibleVersionRange --- contracts/modules/Wallet/VestingEscrowWalletFactory.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol index 47c6d3914..c36554802 100644 --- a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol +++ b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol @@ -20,6 +20,8 @@ contract VestingEscrowWalletFactory is ModuleFactory { name = "VestingEscrowWallet"; title = "Vesting Escrow Wallet"; description = "Allows Issuer to program an automated token vesting schedule for employees and/or affiliates so that Tokens get delivered to their wallets as contractually defined."; + compatibleSTVersionRange["lowerBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0)); + compatibleSTVersionRange["upperBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0)); } /** From 73d4a723bc8164152b017d852089f7a3bb0af250 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:26:02 -0700 Subject: [PATCH 53/57] Rename getType() to getTypes() --- contracts/modules/Wallet/VestingEscrowWalletFactory.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol index c36554802..8e0bc0f6a 100644 --- a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol +++ b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol @@ -38,7 +38,7 @@ contract VestingEscrowWalletFactory is ModuleFactory { /** * @notice Type of the Module factory */ - function getType() public view returns(uint8) { + function getTypes() public view returns(uint8) { return 5; } From 9ea1307e2c1808fc72c9ca84206bb79caa009d3d Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:38:16 -0700 Subject: [PATCH 54/57] Update mappings --- .../modules/Wallet/VestingEscrowWallet.sol | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 9bd0de2ae..e8bb43829 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -47,10 +47,13 @@ contract VestingEscrowWallet is IWallet { uint256 vestingFrequency; } - mapping(address => uint256) public individualVestingCount; - mapping(address => mapping(uint256 => VestingSchedule)) public individualVestingDetails; + mapping(bytes32 => uint256) vestingScheduleIndex; + mapping(address => VestingSchedule[]) userToVestingSchedules; + // mapping(address => mapping(uint256 => VestingSchedule)) public userToVestingSchedules; mapping(uint256 => VestingTemplate) public vestingTemplates; + + /* Events */ event VestingStarted( address indexed target, @@ -220,7 +223,7 @@ contract VestingEscrowWallet is IWallet { public onlyOwner { - VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_vestingScheduleIndex]; + VestingSchedule memory _vestingSchedule = userToVestingSchedules[_target]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); @@ -228,7 +231,7 @@ contract VestingEscrowWallet is IWallet { uint256 _currentTranche = _calculateCurrentTranche(_vestingSchedule.startDate, _vestingSchedule.vestingDuration); uint256 _tokensToDistribute = _calculateTokensToDistribute(_currentTranche, _vestingSchedule.tokensPerTranche, _vestingSchedule.numClaimedVestedTokens); uint256 _numUnvestedTokens = _vestingSchedule.numUnvestedTokens.sub(_tokensToDistribute); - delete individualVestingDetails[_target][_vestingScheduleIndex]; + delete userToVestingSchedules[_target]; // Send vested, unclaimed tokens to the target if (_tokensToDistribute != 0) { @@ -289,7 +292,7 @@ contract VestingEscrowWallet is IWallet { function _distributeVestedTokens(address _target, uint256 _vestingScheduleIndex) internal { - VestingSchedule memory _vestingSchedule = individualVestingDetails[_target][_vestingScheduleIndex]; + VestingSchedule memory _vestingSchedule = userToVestingSchedules[_target]; require(_vestingSchedule.vestingId != 0, "Schedule not initialized"); @@ -353,12 +356,12 @@ contract VestingEscrowWallet is IWallet { ) ); - uint256 _individualVestingCount = individualVestingCount[_target]; - individualVestingCount[_target] += 1; + uint256 _vestingScheduleIndex = vestingScheduleIndex[_target]; + vestingScheduleIndex[_target] += 1; uint256 _numUnvestedTokens = _totalAllocation; - individualVestingDetails[_target][_individualVestingCount] = VestingSchedule({ + userToVestingSchedules[_target] = VestingSchedule({ vestingId: _vestingId, totalAllocation: _totalAllocation, vestingDuration: _vestingDuration, From 07ec3ed553a8d3a63b14ab08bf76ab28319567f1 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Thu, 11 Oct 2018 10:43:01 -0700 Subject: [PATCH 55/57] Remove extra comment --- contracts/modules/Wallet/VestingEscrowWallet.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index e8bb43829..67406167c 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -49,7 +49,6 @@ contract VestingEscrowWallet is IWallet { mapping(bytes32 => uint256) vestingScheduleIndex; mapping(address => VestingSchedule[]) userToVestingSchedules; - // mapping(address => mapping(uint256 => VestingSchedule)) public userToVestingSchedules; mapping(uint256 => VestingTemplate) public vestingTemplates; From 8dc4ad7d25b9290a1812cb8d4dc3e1b853f6154f Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Fri, 12 Oct 2018 09:12:41 -0700 Subject: [PATCH 56/57] Add ternary operator --- contracts/modules/Wallet/VestingEscrowWallet.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index 67406167c..fb6e33aa0 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -144,12 +144,13 @@ contract VestingEscrowWallet is IWallet { vestingTemplates[templateCount] = VestingTemplate(_totalAllocation, _vestingDuration, _vestingFrequency); + templateCount = templateCount == 0 ? 0 : templateCount +1; + emit AddTemplate( templateCount, _totalAllocation, _vestingDuration, _vestingFrequency); - templateCount += 1; } /** From 90aa0da064c0f1086379e20bbcd7564b7306f3f2 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Fri, 12 Oct 2018 09:14:57 -0700 Subject: [PATCH 57/57] Update test to reflect latest standard --- test/u_vesting_escrow_wallet.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/u_vesting_escrow_wallet.js b/test/u_vesting_escrow_wallet.js index dc0945db6..8460676df 100644 --- a/test/u_vesting_escrow_wallet.js +++ b/test/u_vesting_escrow_wallet.js @@ -5,6 +5,7 @@ import { encodeProxyCall } from './helpers/encodeCall'; const PolymathRegistry = artifacts.require('./PolymathRegistry.sol') const ModuleRegistry = artifacts.require('./ModuleRegistry.sol'); +const ModuleRegistryProxy = artifacts.require('./ModuleRegistryProxy.sol'); const SecurityToken = artifacts.require('./SecurityToken.sol'); const SecurityTokenRegistry = artifacts.require('./SecurityTokenRegistry.sol'); const SecurityTokenRegistryProxy = artifacts.require('./SecurityTokenRegistryProxy.sol'); @@ -13,10 +14,12 @@ const STFactory = artifacts.require('./STFactory.sol'); const GeneralPermissionManagerFactory = artifacts.require('./GeneralPermissionManagerFactory.sol'); const GeneralTransferManagerFactory = artifacts.require('./GeneralTransferManagerFactory.sol'); const GeneralTransferManager = artifacts.require('./GeneralTransferManager'); -const VestingEscrowWalletFactory = artifacts.require('./VestingEscrowWalletFactory.sol'); -const VestingEscrowWallet = artifacts.require('./VestingEscrowWallet.sol'); +const TrackedRedemptionFactory = artifacts.require('./TrackedRedemptionFactory.sol'); +const TrackedRedemption = artifacts.require('./TrackedRedemption'); const GeneralPermissionManager = artifacts.require('./GeneralPermissionManager'); const PolyTokenFaucet = artifacts.require('./PolyTokenFaucet.sol'); +const VestingEscrowWalletFactory = artifacts.require('./VestingEscrowWalletFactory.sol'); +const VestingEscrowWallet = artifacts.require('./VestingEscrowWallet.sol'); const Web3 = require('web3'); const BigNumber = require('bignumber.js');