Skip to content

Commit 013ac45

Browse files
authored
Merge pull request #542 from PolymathNetwork/lockup-add-getter
add getAllLockupData getter
2 parents 5c79d98 + e36e38a commit 013ac45

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

CLI/commands/transfer_manager.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ async function lockUpTransferManager() {
22092209

22102210
let options = ['Add new lockup'];
22112211
if (currentLockups.length > 0) {
2212-
options.push('Manage existing lockups', 'Explore investor');
2212+
options.push('Show all existing lockups', 'Manage existing lockups', 'Explore investor');
22132213
}
22142214
options.push('Operate with multiple lockups');
22152215

@@ -2256,6 +2256,16 @@ async function lockUpTransferManager() {
22562256
console.log(chalk.green(`${web3.utils.hexToUtf8(addLockupTypeEvent._lockupName)} lockup type has been added successfully!`));
22572257
}
22582258
break;
2259+
case 'Show all existing lockups':
2260+
let allLockups = await currentTransferManager.methods.getAllLockupData().call();
2261+
let nameArray = allLockups[0];
2262+
let amountArray = allLockups[1];
2263+
let startTimeArray = allLockups[2];
2264+
let periodSecondsArray = allLockups[3];
2265+
let releaseFrequencySecondsArray = allLockups[4];
2266+
let unlockedAmountsArray = allLockups[5];
2267+
showLockupTable(nameArray, amountArray, startTimeArray, periodSecondsArray, releaseFrequencySecondsArray, unlockedAmountsArray);
2268+
break;
22592269
case 'Manage existing lockups':
22602270
let options = currentLockups.map(b => web3.utils.hexToUtf8(b));
22612271
let index = readlineSync.keyInSelect(options, 'Which lockup type do you want to manage? ', { cancel: 'RETURN' });
@@ -2291,6 +2301,22 @@ async function lockUpTransferManager() {
22912301
await lockUpTransferManager();
22922302
}
22932303

2304+
function showLockupTable(nameArray, amountArray, startTimeArray, periodSecondsArray, releaseFrequencySecondsArray, unlockedAmountsArray) {
2305+
let dataTable = [['Lockup Name', `Amount (${tokenSymbol})`, 'Start time', 'Period (seconds)', 'Release frequency (seconds)', `Unlocked amount (${tokenSymbol})`]];
2306+
for (let i = 0; i < nameArray.length; i++) {
2307+
dataTable.push([
2308+
web3.utils.hexToUtf8(nameArray[i]),
2309+
web3.utils.fromWei(amountArray[i]),
2310+
moment.unix(startTimeArray[i]).format('MM/DD/YYYY HH:mm'),
2311+
periodSecondsArray[i],
2312+
releaseFrequencySecondsArray[i],
2313+
web3.utils.fromWei(unlockedAmountsArray[i])
2314+
]);
2315+
}
2316+
console.log();
2317+
console.log(table(dataTable));
2318+
}
2319+
22942320
async function manageExistingLockups(lockupName) {
22952321
console.log('\n', chalk.blue(`Lockup ${web3.utils.hexToUtf8(lockupName)}`), '\n');
22962322

@@ -2464,6 +2490,7 @@ async function addLockupsInBatch() {
24642490
for (let batch = 0; batch < batches.length; batch++) {
24652491
console.log(`Batch ${batch + 1} - Attempting to add the following lockups: \n\n`, lockupNameArray[batch], '\n');
24662492
lockupNameArray[batch] = lockupNameArray[batch].map(n => web3.utils.toHex(n));
2493+
amountArray[batch] = amountArray[batch].map(n => web3.utils.toWei(n.toString()));
24672494
let action = currentTransferManager.methods.addNewLockUpTypeMulti(amountArray[batch], startTimeArray[batch], lockUpPeriodArray[batch], releaseFrequencyArray[batch], lockupNameArray[batch]);
24682495
let receipt = await common.sendTransaction(action);
24692496
console.log(chalk.green('Add multiple lockups transaction was successful.'));
@@ -2498,6 +2525,7 @@ async function modifyLockupsInBatch() {
24982525
for (let batch = 0; batch < batches.length; batch++) {
24992526
console.log(`Batch ${batch + 1} - Attempting to modify the following lockups: \n\n`, lockupNameArray[batch], '\n');
25002527
lockupNameArray[batch] = lockupNameArray[batch].map(n => web3.utils.toHex(n));
2528+
amountArray[batch] = amountArray[batch].map(n => web3.utils.toWei(n.toString()));
25012529
let action = currentTransferManager.methods.modifyLockUpTypeMulti(amountArray[batch], startTimeArray[batch], lockUpPeriodArray[batch], releaseFrequencyArray[batch], lockupNameArray[batch]);
25022530
let receipt = await common.sendTransaction(action);
25032531
console.log(chalk.green('Modify multiple lockups transaction was successful.'));

contracts/modules/Experimental/TransferManager/LockUpTransferManager.sol

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ contract LockUpTransferManager is ITransferManager {
348348
* @notice Get a specific element in a user's lockups array given the user's address and the element index
349349
* @param _lockupName The name of the lockup
350350
*/
351-
function getLockUp(bytes32 _lockupName) external view returns (
351+
function getLockUp(bytes32 _lockupName) public view returns (
352352
uint256 lockupAmount,
353353
uint256 startTime,
354354
uint256 lockUpPeriodSeconds,
@@ -385,6 +385,36 @@ contract LockUpTransferManager is ITransferManager {
385385
return lockupArray;
386386
}
387387

388+
/**
389+
* @notice Return the data of the lockups
390+
*/
391+
function getAllLockupData() external view returns(
392+
bytes32[] memory,
393+
uint256[] memory,
394+
uint256[] memory,
395+
uint256[] memory,
396+
uint256[] memory,
397+
uint256[] memory
398+
)
399+
{
400+
uint256[] memory lockupAmounts = new uint256[](lockupArray.length);
401+
uint256[] memory startTimes = new uint256[](lockupArray.length);
402+
uint256[] memory lockUpPeriodSeconds = new uint256[](lockupArray.length);
403+
uint256[] memory releaseFrequencySeconds = new uint256[](lockupArray.length);
404+
uint256[] memory unlockedAmounts = new uint256[](lockupArray.length);
405+
for (uint256 i = 0; i < lockupArray.length; i++) {
406+
(lockupAmounts[i], startTimes[i], lockUpPeriodSeconds[i], releaseFrequencySeconds[i], unlockedAmounts[i]) = getLockUp(lockupArray[i]);
407+
}
408+
return (
409+
lockupArray,
410+
lockupAmounts,
411+
startTimes,
412+
lockUpPeriodSeconds,
413+
releaseFrequencySeconds,
414+
unlockedAmounts
415+
);
416+
}
417+
388418
/**
389419
* @notice get the list of the lockups for a given user
390420
* @param _user Address of the user

test/w_lockup_transfer_manager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,10 @@ contract('LockUpTransferManager', accounts => {
940940
);
941941
})
942942

943+
it("Should get the data of all lockups", async() => {
944+
console.log(await I_LockUpTransferManager.getAllLockupData.call());
945+
});
946+
943947
it("Should succesfully get the non existed lockup value, it will give everything 0", async() => {
944948
let data = await I_LockUpTransferManager.getLockUp(9);
945949
assert.equal(data[0], 0);

0 commit comments

Comments
 (0)