Skip to content

Commit

Permalink
✨ Add the possibility to transfer all vesting for a wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Oct 16, 2023
1 parent db1c792 commit e6e1777
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 24 deletions.
76 changes: 53 additions & 23 deletions contracts/wallets/MultiVestingWallets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -236,29 +236,6 @@ contract MultiVestingWallets is FrakAccessControlUpgradeable {
/* Vesting managment */
/* -------------------------------------------------------------------------- */

/**
* @notice Transfer a vesting to another person.
*/
function transfer(address to, uint24 vestingId) external {
if (to == address(0)) revert InvalidAddress();

// Get the vesting
Vesting storage vesting = _getVestingForBeneficiary(vestingId, msg.sender);
address from = vesting.beneficiary;

if (to == from) revert InvalidAddress();

// Change the ownership of it
_removeOwnership(from, vesting.id);
_addOwnership(to, vesting.id);

// And update the beneficiary
vesting.beneficiary = to;

// Then emit the event
emit VestingTransfered(vestingId, from, to);
}

/**
* @notice Release the tokens for the specified vesting.
*/
Expand Down Expand Up @@ -327,6 +304,59 @@ contract MultiVestingWallets is FrakAccessControlUpgradeable {
}
}

/* -------------------------------------------------------------------------- */
/* Vesting transfer */
/* -------------------------------------------------------------------------- */

/**
* @dev Transfer a given vesting `vestingId` `to` another wallet.
*/
function transfer(address to, uint24 vestingId) external {
if (to == address(0)) revert InvalidAddress();

// Perform the transfer
_doTransfer(to, vestingId);
}

/**
* @dev Transfer all the vestings `to` another wallet.
*/
function transferAll(address to) external {
if (to == address(0)) revert InvalidAddress();

// Get all the vesting id of the sender
uint256[] memory _vestingIds = owned[msg.sender].values();
uint256 length = _vestingIds.length;

// Transfer all of them
for (uint256 index; index < length;) {
_doTransfer(to, uint24(_vestingIds[index]));

unchecked {
++index;
}
}
}

/**
* Execute the transfer of the given `vestingId` to the given `to` address.
*/
function _doTransfer(address to, uint24 vestingId) private {
// Get the vesting
Vesting storage vesting = _getVestingForBeneficiary(vestingId, msg.sender);
address from = vesting.beneficiary;

// Change the ownership of it
_removeOwnership(from, vesting.id);
_addOwnership(to, vesting.id);

// And update the beneficiary
vesting.beneficiary = to;

// Then emit the event
emit VestingTransfered(vestingId, from, to);
}

/* -------------------------------------------------------------------------- */
/* View methods */
/* -------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion contracts/wallets/VestingWalletFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ contract VestingWalletFactory is FrakAccessControlUpgradeable {
function addVestingGroup(uint8 id, uint96 rewardCap, uint32 duration) external onlyRole(FrakRoles.ADMIN) {
_addVestingGroup(id, rewardCap, duration);
}

/**
* @dev Add a new vesting group
*/
Expand Down

0 comments on commit e6e1777

Please sign in to comment.