Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 29 additions & 1 deletion CLI/commands/transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2209,7 +2209,7 @@ async function lockUpTransferManager() {

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

Expand Down Expand Up @@ -2256,6 +2256,16 @@ async function lockUpTransferManager() {
console.log(chalk.green(`${web3.utils.hexToUtf8(addLockupTypeEvent._lockupName)} lockup type has been added successfully!`));
}
break;
case 'Show all existing lockups':
let allLockups = await currentTransferManager.methods.getAllLockupData().call();
let nameArray = allLockups[0];
let amountArray = allLockups[1];
let startTimeArray = allLockups[2];
let periodSecondsArray = allLockups[3];
let releaseFrequencySecondsArray = allLockups[4];
let unlockedAmountsArray = allLockups[5];
showLockupTable(nameArray, amountArray, startTimeArray, periodSecondsArray, releaseFrequencySecondsArray, unlockedAmountsArray);
break;
case 'Manage existing lockups':
let options = currentLockups.map(b => web3.utils.hexToUtf8(b));
let index = readlineSync.keyInSelect(options, 'Which lockup type do you want to manage? ', { cancel: 'RETURN' });
Expand Down Expand Up @@ -2291,6 +2301,22 @@ async function lockUpTransferManager() {
await lockUpTransferManager();
}

function showLockupTable(nameArray, amountArray, startTimeArray, periodSecondsArray, releaseFrequencySecondsArray, unlockedAmountsArray) {
let dataTable = [['Lockup Name', `Amount (${tokenSymbol})`, 'Start time', 'Period (seconds)', 'Release frequency (seconds)', `Unlocked amount (${tokenSymbol})`]];
for (let i = 0; i < nameArray.length; i++) {
dataTable.push([
web3.utils.hexToUtf8(nameArray[i]),
web3.utils.fromWei(amountArray[i]),
moment.unix(startTimeArray[i]).format('MM/DD/YYYY HH:mm'),
periodSecondsArray[i],
releaseFrequencySecondsArray[i],
web3.utils.fromWei(unlockedAmountsArray[i])
]);
}
console.log();
console.log(table(dataTable));
}

async function manageExistingLockups(lockupName) {
console.log('\n', chalk.blue(`Lockup ${web3.utils.hexToUtf8(lockupName)}`), '\n');

Expand Down Expand Up @@ -2464,6 +2490,7 @@ async function addLockupsInBatch() {
for (let batch = 0; batch < batches.length; batch++) {
console.log(`Batch ${batch + 1} - Attempting to add the following lockups: \n\n`, lockupNameArray[batch], '\n');
lockupNameArray[batch] = lockupNameArray[batch].map(n => web3.utils.toHex(n));
amountArray[batch] = amountArray[batch].map(n => web3.utils.toWei(n.toString()));
let action = currentTransferManager.methods.addNewLockUpTypeMulti(amountArray[batch], startTimeArray[batch], lockUpPeriodArray[batch], releaseFrequencyArray[batch], lockupNameArray[batch]);
let receipt = await common.sendTransaction(action);
console.log(chalk.green('Add multiple lockups transaction was successful.'));
Expand Down Expand Up @@ -2498,6 +2525,7 @@ async function modifyLockupsInBatch() {
for (let batch = 0; batch < batches.length; batch++) {
console.log(`Batch ${batch + 1} - Attempting to modify the following lockups: \n\n`, lockupNameArray[batch], '\n');
lockupNameArray[batch] = lockupNameArray[batch].map(n => web3.utils.toHex(n));
amountArray[batch] = amountArray[batch].map(n => web3.utils.toWei(n.toString()));
let action = currentTransferManager.methods.modifyLockUpTypeMulti(amountArray[batch], startTimeArray[batch], lockUpPeriodArray[batch], releaseFrequencyArray[batch], lockupNameArray[batch]);
let receipt = await common.sendTransaction(action);
console.log(chalk.green('Modify multiple lockups transaction was successful.'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ contract LockUpTransferManager is ITransferManager {
* @notice Get a specific element in a user's lockups array given the user's address and the element index
* @param _lockupName The name of the lockup
*/
function getLockUp(bytes32 _lockupName) external view returns (
function getLockUp(bytes32 _lockupName) public view returns (
uint256 lockupAmount,
uint256 startTime,
uint256 lockUpPeriodSeconds,
Expand Down Expand Up @@ -385,6 +385,36 @@ contract LockUpTransferManager is ITransferManager {
return lockupArray;
}

/**
* @notice Return the data of the lockups
*/
function getAllLockupData() external view returns(
bytes32[] memory,
uint256[] memory,
uint256[] memory,
uint256[] memory,
uint256[] memory,
uint256[] memory
)
{
uint256[] memory lockupAmounts = new uint256[](lockupArray.length);
uint256[] memory startTimes = new uint256[](lockupArray.length);
uint256[] memory lockUpPeriodSeconds = new uint256[](lockupArray.length);
uint256[] memory releaseFrequencySeconds = new uint256[](lockupArray.length);
uint256[] memory unlockedAmounts = new uint256[](lockupArray.length);
for (uint256 i = 0; i < lockupArray.length; i++) {
(lockupAmounts[i], startTimes[i], lockUpPeriodSeconds[i], releaseFrequencySeconds[i], unlockedAmounts[i]) = getLockUp(lockupArray[i]);
}
return (
lockupArray,
lockupAmounts,
startTimes,
lockUpPeriodSeconds,
releaseFrequencySeconds,
unlockedAmounts
);
}

/**
* @notice get the list of the lockups for a given user
* @param _user Address of the user
Expand Down
4 changes: 4 additions & 0 deletions test/w_lockup_transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,10 @@ contract('LockUpTransferManager', accounts => {
);
})

it("Should get the data of all lockups", async() => {
console.log(await I_LockUpTransferManager.getAllLockupData.call());
});

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);
Expand Down