Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d7abab2
revamp the lockup
SatyamSB Nov 13, 2018
21bd05a
test suite addition
SatyamSB Nov 14, 2018
b847f54
minor fixes
SatyamSB Nov 16, 2018
d28ef32
change to external
SatyamSB Nov 16, 2018
d4d35e5
stack too deep erro fix
SatyamSB Nov 16, 2018
1f4e9c1
remove some require statements
SatyamSB Nov 22, 2018
9852a9d
Merge branch 'dev-2.1.0' into reinvent-lockup
SatyamSB Nov 22, 2018
8199aa2
Merge branch 'dev-2.1.0' into reinvent-lockup
adamdossa Nov 26, 2018
0c61008
Merge branch 'dev-2.1.0' into reinvent-lockup
VictorVicente Nov 29, 2018
4eb3a5a
redesign the lockup module
SatyamSB Nov 29, 2018
3469a7d
test case improvement
SatyamSB Nov 30, 2018
c2449c9
Merge branch 'reinvent-lockup' of https://github.com/PolymathNetwork/…
SatyamSB Nov 30, 2018
64c85d4
Merge branch 'dev-2.1.0' into reinvent-lockup
satyamakgec Nov 30, 2018
f91bbc4
Merge branch 'dev-2.1.0' into reinvent-lockup
satyamakgec Nov 30, 2018
ae08093
minor fixes
SatyamSB Nov 30, 2018
57c24be
allow the lockup start could be 0
SatyamSB Nov 30, 2018
35d73d5
Merge branch 'dev-2.1.0' into reinvent-lockup
VictorVicente Dec 4, 2018
3fd2a34
resolve conflicts and add Lockup module in migrations
SatyamSB Dec 5, 2018
f1c82d6
Merge branch 'dev-2.1.0' into reinvent-lockup
VictorVicente Dec 10, 2018
4162766
CLI - LockupTM support
VictorVicente Dec 11, 2018
4ae3a21
recommended fixes
SatyamSB Dec 12, 2018
d1598e5
CLI - Fixes for new contract changes
VictorVicente Dec 12, 2018
4ebc150
Merge branch 'dev-2.1.0' into reinvent-lockup
VictorVicente Dec 13, 2018
18a0426
Merge branch 'dev-2.1.0' into reinvent-lockup
VictorVicente Jan 8, 2019
23e7d51
Fixed test file
maxsam4 Jan 8, 2019
887860e
Trigger TravisCI
VictorVicente Jan 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
recommended fixes
  • Loading branch information
SatyamSB committed Dec 12, 2018
commit 4ae3a219c4f5880308201637da9a170f07d39f66
66 changes: 28 additions & 38 deletions contracts/modules/TransferManager/LockUpTransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ contract LockUpTransferManager is ITransferManager {

bytes32[] lockupArray;

event AddNewLockUpToUser(
address indexed userAddress,
bytes32 indexed lockupName
event AddLockUpToUser(
address indexed _userAddress,
bytes32 indexed _lockupName
);

event RemoveLockUpFromUser(
address indexed userAddress,
bytes32 indexed lockupName
address indexed _userAddress,
bytes32 indexed _lockupName
);

event ModifyLockUpType(
uint256 lockupAmount,
uint256 startTime,
uint256 lockUpPeriodSeconds,
uint256 releaseFrequencySeconds,
bytes32 indexed lockupName
uint256 _lockupAmount,
uint256 _startTime,
uint256 _lockUpPeriodSeconds,
uint256 _releaseFrequencySeconds,
bytes32 indexed _lockupName
);

event AddNewLockUpType(
bytes32 indexed lockupName,
uint256 lockupAmount,
uint256 startTime,
uint256 lockUpPeriodSeconds,
uint256 releaseFrequencySeconds
bytes32 indexed _lockupName,
uint256 _lockupAmount,
uint256 _startTime,
uint256 _lockUpPeriodSeconds,
uint256 _releaseFrequencySeconds
);

event RemoveLockUpType(bytes32 indexed lockupName);
event RemoveLockUpType(bytes32 indexed _lockupName);

/**
* @notice Constructor
Expand Down Expand Up @@ -344,37 +344,27 @@ contract LockUpTransferManager is ITransferManager {
}
}

/**
* @notice Get the length of the lockups array for a specific user address
* @param _userAddress Address of the user whose tokens should be locked up
*/
function getLockUpsLength(address _userAddress) public view returns (uint256) {
return userToLockups[_userAddress].length;
}

/**
* @notice Get a specific element in a user's lockups array given the user's address and the element index
* @param _userAddress Address of the user whose tokens should be locked up
* @param _lockupName The name of the lockup
*/
function getLockUp(address _userAddress, bytes32 _lockupName) public view returns (
function getLockUp(bytes32 _lockupName) external view returns (
uint256 lockupAmount,
uint256 startTime,
uint256 lockUpPeriodSeconds,
uint256 releaseFrequencySeconds,
uint256 unlockedAmount
) {
require(
userToLockups[_userAddress][userToLockupIndex[_userAddress][_lockupName]] == _lockupName,
"User not assosicated with given lockup"
);
return (
lockups[_lockupName].lockupAmount,
lockups[_lockupName].startTime,
lockups[_lockupName].lockUpPeriodSeconds,
lockups[_lockupName].releaseFrequencySeconds,
_getUnlockedAmountForLockup(_lockupName)
);
if (lockups[_lockupName].lockupAmount != 0) {
return (
lockups[_lockupName].lockupAmount,
lockups[_lockupName].startTime,
lockups[_lockupName].lockUpPeriodSeconds,
lockups[_lockupName].releaseFrequencySeconds,
_getUnlockedAmountForLockup(_lockupName)
);
}
return (uint256(0), uint256(0), uint256(0), uint256(0), uint256(0));
}

/**
Expand Down Expand Up @@ -582,7 +572,7 @@ contract LockUpTransferManager is ITransferManager {
lockupToUserIndex[_lockupName][_userAddress] = lockupToUsers[_lockupName].length;
userToLockups[_userAddress].push(_lockupName);
lockupToUsers[_lockupName].push(_userAddress);
emit AddNewLockUpToUser(_userAddress, _lockupName);
emit AddLockUpToUser(_userAddress, _lockupName);
}

function _addNewLockUpType(
Expand Down
41 changes: 18 additions & 23 deletions test/w_lockup_transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ contract('LockUpTransferManager', accounts => {
from: token_owner
}
);
assert.equal((tx.logs[0].args.lockupAmount).toNumber(), web3.utils.toWei('12', 'ether'));
assert.equal((tx.logs[0].args._lockupAmount).toNumber(), web3.utils.toWei('12', 'ether'));
});

it("Should fail to add the creation of the lockup where lockupName is already exists", async() => {
Expand Down Expand Up @@ -478,8 +478,8 @@ contract('LockUpTransferManager', accounts => {
from: token_owner
}
);
assert.equal(tx.logs[1].args.userAddress, account_investor1);
assert.equal((tx.logs[0].args.lockupAmount).toNumber(), web3.utils.toWei('0.5', 'ether'));
assert.equal(tx.logs[1].args._userAddress, account_investor1);
assert.equal((tx.logs[0].args._lockupAmount).toNumber(), web3.utils.toWei('0.5', 'ether'));
});

it("Should allow the creation of a lockup where the lockup amount is prime no", async() => {
Expand All @@ -495,8 +495,8 @@ contract('LockUpTransferManager', accounts => {
from: token_owner
}
);
assert.equal(tx.logs[1].args.userAddress, account_investor1);
assert.equal((tx.logs[0].args.lockupAmount).toNumber(), web3.utils.toWei('64951', 'ether'));
assert.equal(tx.logs[1].args._userAddress, account_investor1);
assert.equal((tx.logs[0].args._lockupAmount).toNumber(), web3.utils.toWei('64951', 'ether'));
});

it("Should prevent the transfer of tokens in a lockup", async() => {
Expand All @@ -517,7 +517,7 @@ contract('LockUpTransferManager', accounts => {
}
);
await increaseTime(2);
let tx = await I_LockUpTransferManager.getLockUp.call(account_investor2, "b_lockup");
let tx = await I_LockUpTransferManager.getLockUp.call("b_lockup");
console.log("Amount get unlocked:", (tx[4].toNumber()));
await catchRevert(
I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), { from: account_investor2 })
Expand All @@ -527,21 +527,21 @@ contract('LockUpTransferManager', accounts => {
it("Should prevent the transfer of tokens if the amount is larger than the amount allowed by lockups", async() => {
// wait 20 seconds
await increaseTime(duration.seconds(20));
let tx = await I_LockUpTransferManager.getLockUp.call(account_investor2, "b_lockup");
let tx = await I_LockUpTransferManager.getLockUp.call("b_lockup");
console.log("Amount get unlocked:", (tx[4].toNumber()));
await catchRevert(
I_SecurityToken.transfer(account_investor1, web3.utils.toWei('4', 'ether'), { from: account_investor2 })
);
});

it("Should allow the transfer of tokens in a lockup if a period has passed", async() => {
let tx = await I_LockUpTransferManager.getLockUp.call(account_investor2, "b_lockup");
let tx = await I_LockUpTransferManager.getLockUp.call("b_lockup");
console.log("Amount get unlocked:", (tx[4].toNumber()));
await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), { from: account_investor2 });
});

it("Should again transfer of tokens in a lockup if a period has passed", async() => {
let tx = await I_LockUpTransferManager.getLockUp.call(account_investor2, "b_lockup");
let tx = await I_LockUpTransferManager.getLockUp.call("b_lockup");
console.log("Amount get unlocked:", (tx[4].toNumber()));
await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), { from: account_investor2 });
});
Expand All @@ -550,7 +550,7 @@ contract('LockUpTransferManager', accounts => {

// wait 20 more seconds + 1 to get rid of same block time
await increaseTime(duration.seconds(21));
let tx = await I_LockUpTransferManager.getLockUp.call(account_investor2, "b_lockup");
let tx = await I_LockUpTransferManager.getLockUp.call( "b_lockup");
console.log("Amount get unlocked:", (tx[4].toNumber()));
await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('2', 'ether'), { from: account_investor2 });
});
Expand Down Expand Up @@ -682,8 +682,8 @@ contract('LockUpTransferManager', accounts => {
);

await increaseTime(1);
let tx = await I_LockUpTransferManager.getLockUp.call(account_investor3, "c_lockup");
let tx2 = await I_LockUpTransferManager.getLockUp.call(account_investor3, "d_lockup");
let tx = await I_LockUpTransferManager.getLockUp.call("c_lockup");
let tx2 = await I_LockUpTransferManager.getLockUp.call("d_lockup");
console.log("Total Amount get unlocked:", (tx[4].toNumber()) + (tx2[4].toNumber()));
await catchRevert(
I_SecurityToken.transfer(account_investor2, web3.utils.toWei('2', 'ether'), { from: account_investor3 })
Expand Down Expand Up @@ -859,11 +859,7 @@ contract('LockUpTransferManager', accounts => {
I_SecurityToken.transfer(account_investor2, web3.utils.toWei('1', 'ether'), { from: account_investor1 })
);

// check and get the lockup
let lockUpCount = await I_LockUpTransferManager.getLockUpsLength(account_investor1);
assert.equal(lockUpCount, 1)

let lockUp = await I_LockUpTransferManager.getLockUp(account_investor1, "f_lockup");
let lockUp = await I_LockUpTransferManager.getLockUp("f_lockup");
console.log(lockUp);
// elements in lockup array are uint lockUpPeriodSeconds, uint releaseFrequencySeconds, uint startTime, uint totalAmount
assert.equal(
Expand Down Expand Up @@ -902,7 +898,7 @@ contract('LockUpTransferManager', accounts => {

it("Modify the lockup during the lockup periods", async() => {
let balance = await I_SecurityToken.balanceOf(account_investor1)
let lockUp = await I_LockUpTransferManager.getLockUp(account_investor1, "f_lockup");
let lockUp = await I_LockUpTransferManager.getLockUp("f_lockup");
console.log(lockUp[4].dividedBy(new BigNumber(1).times(new BigNumber(10).pow(18))).toNumber());
// edit the lockup
await I_LockUpTransferManager.modifyLockUpType(
Expand Down Expand Up @@ -931,7 +927,7 @@ contract('LockUpTransferManager', accounts => {

// removing the lockup type
let tx = await I_LockUpTransferManager.removeLockupType("k_lockup", {from: token_owner});
assert.equal(web3.utils.toUtf8(tx.logs[0].args.lockupName), "k_lockup");
assert.equal(web3.utils.toUtf8(tx.logs[0].args._lockupName), "k_lockup");

// attaching the lockup to a user

Expand All @@ -944,10 +940,9 @@ contract('LockUpTransferManager', accounts => {
);
})

it("Should succesfully get the lockup - fail because no lockup exist for the user of this name", async() => {
await catchRevert(
I_LockUpTransferManager.getLockUp(account_investor1, 9)
);
it("Should succesfully get the non existed lockup value, it will give everything 0", async() => {
let data = await I_LockUpTransferManager.getLockUp(9);
assert.equal(data[0], 0);
})

it("Should get configuration function signature", async() => {
Expand Down