From e6e17773995edf2a003ece35d2c9e67e322bfea3 Mon Sep 17 00:00:00 2001 From: KONFeature Date: Mon, 16 Oct 2023 18:30:24 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20the=20possibility=20to=20tran?= =?UTF-8?q?sfer=20all=20vesting=20for=20a=20wallet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/wallets/MultiVestingWallets.sol | 76 +++++++++++++++------- contracts/wallets/VestingWalletFactory.sol | 2 +- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/contracts/wallets/MultiVestingWallets.sol b/contracts/wallets/MultiVestingWallets.sol index c0ca56e..24676c9 100644 --- a/contracts/wallets/MultiVestingWallets.sol +++ b/contracts/wallets/MultiVestingWallets.sol @@ -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. */ @@ -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 */ /* -------------------------------------------------------------------------- */ diff --git a/contracts/wallets/VestingWalletFactory.sol b/contracts/wallets/VestingWalletFactory.sol index 2adbc48..f68e2b6 100644 --- a/contracts/wallets/VestingWalletFactory.sol +++ b/contracts/wallets/VestingWalletFactory.sol @@ -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 */