diff --git a/contracts/MigratorV1/DelayMigratorState.sol b/contracts/MigratorV1/DelayMigratorState.sol index 73217c9..d9943d0 100644 --- a/contracts/MigratorV1/DelayMigratorState.sol +++ b/contracts/MigratorV1/DelayMigratorState.sol @@ -5,20 +5,49 @@ import "../interfaces/IDelayVaultProvider.sol"; import "../interfaces/IDelayVaultV1.sol"; import "../interfaces/IMigrator.sol"; import "@poolzfinance/poolz-helper-v2/contracts/interfaces/IVaultManager.sol"; - +/** + * @title Delay Migrator State + * @dev Abstract contract serving as a base for delay vault migrator contract. + * +*/ abstract contract DelayMigratorState is IMigrator { + /** + * @dev The old version of the delay vault (IDelayVaultV1) from which data is migrated. + */ IDelayVaultV1 public oldVault; + + /** + * @dev The new version of the delay vault provider (IDelayVaultProvider) where data is migrated. + */ IDelayVaultProvider public newVault; + + /** + * @dev NFT contract representing lock deals in the migration process. + */ ILockDealNFT public lockDealNFT; + + /** + * @dev Address of the ERC-20 token involved in the migration. + */ address public token; - address public owner = msg.sender; // Initialize owner at declaration + /** + * @dev Address of the contract owner. Initialized at contract deployment. + */ + address public owner = msg.sender; + + /** + * @dev Modifier to enforce that certain functions are called only after the contract is initialized. + * The `_afterInit` function checks whether the owner is still the zero address, indicating initialization. + */ modifier afterInit() { _afterInit(); _; } - ///@dev internal function to save small amounts of gas + /** + * @dev Internal function to save gas by checking if the owner is not initialized. + */ function _afterInit() internal view { require(owner == address(0), "DelayVaultMigrator: not initialized"); } diff --git a/contracts/MigratorV1/DelayVaultMigrator.sol b/contracts/MigratorV1/DelayVaultMigrator.sol index e0e2478..c28a5c4 100644 --- a/contracts/MigratorV1/DelayVaultMigrator.sol +++ b/contracts/MigratorV1/DelayVaultMigrator.sol @@ -7,6 +7,11 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; contract DelayVaultMigrator is DelayMigratorState, ILockDealV2 { + /** + * @dev Constructor to initialize the DelayVaultMigrator with the LockDealNFT and the old DelayVault contract. + * @param _nft Address of the LockDealNFT contract. + * @param _oldVault Address of the old DelayVault (IDelayVaultV1) contract. + */ constructor(ILockDealNFT _nft, IDelayVaultV1 _oldVault) { require(address(_oldVault) != address(0), "DelayVaultMigrator: Invalid old delay vault contract"); require(address(_nft) != address(0), "DelayVaultMigrator: Invalid lock deal nft contract"); @@ -14,6 +19,10 @@ contract DelayVaultMigrator is DelayMigratorState, ILockDealV2 { lockDealNFT = _nft; } + /** + * @dev Finalize the migration process by setting the new DelayVaultProvider and updating related parameters. + * @param _newVault Address of the new DelayVaultProvider contract. + */ function finalize(IDelayVaultProvider _newVault) external { require(owner != address(0), "DelayVaultMigrator: already initialized"); require(msg.sender == owner, "DelayVaultMigrator: not owner"); @@ -26,7 +35,10 @@ contract DelayVaultMigrator is DelayMigratorState, ILockDealV2 { owner = address(0); // Set owner to zero address } - //this option is to get tokens from the DelayVaultV1 and deposit them to the DelayVaultV2 (LockDealNFT, v3) + /** + * @dev Migrate tokens from the old DelayVault to the new DelayVaultProvider and receive DelayVaultProvider NFT. + * Requires user approval in the old DelayVault. + */ function fullMigrate() external afterInit { require(oldVault.Allowance(token, msg.sender), "DelayVaultMigrator: not allowed"); uint256 amount = getUserV1Amount(msg.sender); @@ -37,7 +49,10 @@ contract DelayVaultMigrator is DelayMigratorState, ILockDealV2 { newVault.createNewDelayVault(msg.sender, params); } - //this option is to get tokens from the DelayVaultV1 and deposit them to the LockDealNFT (v3) + /** + * @dev Migrate tokens from the old DelayVault to the LockDealNFT (v3) and receive NFT providers. + * Requires user approval in the old DelayVault. + */ function withdrawTokensFromV1Vault() external afterInit { require(oldVault.Allowance(token, msg.sender), "DelayVaultMigrator: not allowed"); uint256 amount = getUserV1Amount(msg.sender); @@ -50,17 +65,29 @@ contract DelayVaultMigrator is DelayMigratorState, ILockDealV2 { providerData.provider.registerPool(newPoolId, params); } + /** + * @dev Get the amount of tokens held by a user in the old DelayVault. + * @param user Address of the user. + * @return amount The amount of tokens held by the user. + */ function getUserV1Amount(address user) public view returns (uint256 amount) { (amount, , , ) = oldVault.VaultMap(token, user); } + /** + * @dev Create a new pool using the LockDealNFT (v3) when withdrawing from the old DelayVault. + * The function can only be called by the old DelayVault (DelayVaultV1). + * @param _Token Token address to lock. + * @param _StartAmount Total amount of tokens. + * @param _Owner Address of the owner of the tokens. + */ function CreateNewPool( - address _Token, //token to lock address - uint256, // Until what time the pool will start - uint256, //Before CliffTime can't withdraw tokens - uint256, //Until what time the pool will end - uint256 _StartAmount, //Total amount of the tokens to sell in the pool - address _Owner // Who the tokens belong to + address _Token, + uint256, + uint256, + uint256, + uint256 _StartAmount, + address _Owner ) external payable override afterInit { require(msg.sender == address(oldVault), "DelayVaultMigrator: not DelayVaultV1"); uint8 theType = newVault.theTypeOf(newVault.getTotalAmount(_Owner)); @@ -71,4 +98,4 @@ contract DelayVaultMigrator is DelayMigratorState, ILockDealV2 { uint256[] memory params = newVault.getWithdrawPoolParams(_StartAmount, theType); providerData.provider.registerPool(newPoolId, params); } -} +} \ No newline at end of file diff --git a/contracts/interfaces/IDelayVaultV1.sol b/contracts/interfaces/IDelayVaultV1.sol index 5e6b4fa..db2e482 100644 --- a/contracts/interfaces/IDelayVaultV1.sol +++ b/contracts/interfaces/IDelayVaultV1.sol @@ -1,10 +1,32 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; +/** + * @title Delay Vault Version 1 Interface + * @dev Interface outlining functions for interacting with the Delay Vault Version 1. + */ interface IDelayVaultV1 { + /** + * @dev Redeem tokens from the Delay Vault from a specific owner. + * @param _token Address of the ERC-20 token to redeem. + * @param _owner Address of the owner whose tokens are being redeemed. + * @param _amount Amount of tokens to redeem. + */ function redeemTokensFromVault(address _token, address _owner, uint256 _amount) external; + /** + * @dev Check if the owner has authorized the use of their tokens in DelayVault. + * @param _token Address of the ERC-20 token to check allowance for. + * @param _owner Address of the owner to check allowance for. + * @return Does the system have permission for owner tokens? + */ function Allowance(address _token, address _owner) external view returns (bool); + /** + * @dev Retrieve information from the Delay Vault map for a specific owner and token. + * @param _token Address of the ERC-20 token in the vault map. + * @param _owner Address of the owner in the vault map. + * @return The vault map information including total, withdrawn, cliff, and start amounts. + */ function VaultMap(address _token, address _owner) external view returns (uint256, uint256, uint256, uint256); } diff --git a/contracts/interfaces/ILockDealV2.sol b/contracts/interfaces/ILockDealV2.sol index 44a44f1..f57da6b 100644 --- a/contracts/interfaces/ILockDealV2.sol +++ b/contracts/interfaces/ILockDealV2.sol @@ -1,13 +1,26 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; +/** + * @title Lock Deal Version 2 Interface + * @dev This interface outlines the function required to create a new pool in the Lock Deal system. + */ interface ILockDealV2 { + /** + * @dev Create a new pool in the Lock Deal system. + * @param _Token Address of the token to lock. + * @param _StartTime Time when the pool will start. + * @param _CliffTime Time before which tokens cannot be withdrawn. + * @param _FinishTime Time until which the pool will be active. + * @param _StartAmount Total amount of tokens to sell in the pool. + * @param _Owner Address of the owner of the tokens. + */ function CreateNewPool( - address _Token, //token to lock address - uint256 _StartTime, //Until what time the pool will start - uint256 _CliffTime, //Before CliffTime can't withdraw tokens - uint256 _FinishTime, //Until what time the pool will end - uint256 _StartAmount, //Total amount of the tokens to sell in the pool - address _Owner // Who the tokens belong to + address _Token, + uint256 _StartTime, + uint256 _CliffTime, + uint256 _FinishTime, + uint256 _StartAmount, + address _Owner ) external payable; }