// SPDX-License-Identifier: MIT // Disclaimer https://github.com/hats-finance/hats-contracts/blob/main/DISCLAIMER.md pragma solidity 0.8.16; import "@openzeppelin/contracts-upgradeable/interfaces/IERC4626Upgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./IRewardController.sol"; import "./IHATVaultsRegistry.sol"; import "./IHATClaimsManager.sol"; /** @title Interface for Hats.finance Vaults * @author Hats.finance * @notice A HATVault holds the funds for a specific project's bug bounties. * Anyone can permissionlessly deposit into the HATVault using * the vault’s native token. When a bug is submitted and approved, the bounty * is paid out using the funds in the vault. Bounties are paid out as a * percentage of the vault. The percentage is set according to the severity of * the bug. Vaults have regular safety periods (typically for an hour twice a * day) which are time for the committee to make decisions. * * In addition to the roles defined in the HATVaultsRegistry, every HATVault * has the roles: * Committee - The only address which can submit a claim for a bounty payout * and set the maximum bounty. * User - Anyone can deposit the vault's native token into the vault and * recieve shares for it. Shares represent the user's relative part in the * vault, and when a bounty is paid out, users lose part of their deposits * (based on percentage paid), but keep their share of the vault. * Users also receive rewards for their deposits, which can be claimed at any * time. * To withdraw previously deposited tokens, a user must first send a withdraw * request, and the withdrawal will be made available after a pending period. * Withdrawals are not permitted during safety periods or while there is an * active claim for a bounty payout. * * Bounties are payed out distributed between a few channels, and that * distribution is set upon creation (the hacker gets part in direct transfer, * part in vested reward and part in vested HAT token, part gets rewarded to * the committee, part gets swapped to HAT token and burned and/or sent to Hats * governance). * * NOTE: Vaults should not use tokens which do not guarantee that the amount * specified is the amount transferred * * This project is open-source and can be found at: * https://github.com/hats-finance/hats-contracts */ interface IHATVault is IERC4626Upgradeable { /** * @notice Initialization parameters for the vault token * @param name The vault's name (concatenated as "Hats Vault " + name) * @param symbol The vault's symbol (concatenated as "HAT" + symbol) * @param rewardController The reward controller for the vault * @param asset The vault's native token * @param owner The address of the vault's owner * @param isPaused Whether to initialize the vault with deposits disabled * @param descriptionHash The hash of the vault's description */ struct VaultInitParams { string name; string symbol; IRewardController[] rewardControllers; IERC20 asset; address owner; bool isPaused; string descriptionHash; } // Only claims manager can make this call error OnlyClaimsManager(); // Only registry owner error OnlyRegistryOwner(); // Vault not started yet error VaultNotStartedYet(); // First deposit must return at least MINIMAL_AMOUNT_OF_SHARES error AmountOfSharesMustBeMoreThanMinimalAmount(); // Withdraw amount must be greater than zero error WithdrawMustBeGreaterThanZero(); // Cannot mint burn or transfer 0 amount of shares error AmountCannotBeZero(); // Cannot transfer shares to self error CannotTransferToSelf(); // Cannot deposit to another user with withdraw request error CannotTransferToAnotherUserWithActiveWithdrawRequest(); // Redeem amount cannot be more than maximum for user error RedeemMoreThanMax(); // Deposit passed max slippage error DepositSlippageProtection(); // Mint passed max slippage error MintSlippageProtection(); // Withdraw passed max slippage error WithdrawSlippageProtection(); // Redeem passed max slippage error RedeemSlippageProtection(); // Cannot add the same reward controller more than once error DuplicatedRewardController(); // Fee must be less than or equal to 2% error WithdrawalFeeTooBig(); // System is in an emergency pause error SystemInEmergencyPause(); // Only fee setter error OnlyFeeSetter(); // Cannot unpasue deposits for a vault that was destroyed error CannotUnpauseDestroyedVault(); event AddRewardController(IRewardController indexed _newRewardController); event SetWithdrawalFee(uint256 _newFee); event VaultPayout(uint256 _amount); event SetDepositPause(bool _depositPause); event SetWithdrawPaused(bool _withdrawPaused); event VaultStarted(); event VaultDestroyed(); event SetVaultDescription(string _descriptionHash); event WithdrawRequest( address indexed _beneficiary, uint256 _withdrawEnableTime ); /** * @notice Initialize a vault token instance * @param _claimsManager The vault's claims manager * @param _params The vault token initialization parameters * @dev See {IHATVault-VaultInitParams} for more details * @dev Called when the vault token is created in {IHATVaultsRegistry-createVault} */ function initialize(address _claimsManager, VaultInitParams calldata _params) external; /** * @notice Adds a reward controller to the reward controllers list * @param _rewardController The reward controller to add */ function addRewardController(IRewardController _rewardController) external; /** * @notice Called by the vault's owner to disable all deposits to the vault * @param _depositPause Are deposits paused */ function setDepositPause(bool _depositPause) external; /** * @notice Called by the registry's fee setter to set the fee for * withdrawals from the vault. * @param _fee The new fee. Must be smaller than or equal to `MAX_WITHDRAWAL_FEE` */ function setWithdrawalFee(uint256 _fee) external; /** * @notice Make a payout out of the vault * @param _amount The amount to send out for the payout */ function makePayout(uint256 _amount) external; /** * @notice Called by the vault's claims manager to disable all withdrawals from the vault * @param _withdrawPaused Are withdraws paused */ function setWithdrawPaused(bool _withdrawPaused) external; /** * @notice Start the vault, deposits are disabled until the vault is first started */ function startVault() external; /** * @notice Permanently disables deposits to the vault */ function destroyVault() external; /** * @notice Called by the registry's owner to change the description of the * vault in the Hats.finance UI * @param _descriptionHash the hash of the vault's description */ function setVaultDescription(string calldata _descriptionHash) external; /** * @notice Returns the vault's version * @return The vault's version */ function VERSION() external view returns(string calldata); /** * @notice Returns the vault's registry * @return The registry's address */ function registry() external view returns(IHATVaultsRegistry); /** * @notice Returns the vault's registry * @return The registry's address */ function claimsManager() external view returns(address); /** * @notice Submit a request to withdraw funds from the vault. * The request will only be approved if there is no previous active * withdraw request. * The request will be pending for a period of * {HATVaultsRegistry.generalParameters.withdrawRequestPendingPeriod}, * after which a withdraw will be possible for a duration of * {HATVaultsRegistry.generalParameters.withdrawRequestEnablePeriod} */ function withdrawRequest() external; /** * @notice Withdraw previously deposited funds from the vault and claim * the HAT reward that the user has earned. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * @param assets Amount of tokens to withdraw * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @dev See {IERC4626-withdraw}. */ function withdrawAndClaim(uint256 assets, address receiver, address owner) external returns (uint256 shares); /** * @notice Redeem shares in the vault for the respective amount * of underlying assets and claim the HAT reward that the user has earned. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * @param shares Amount of shares to redeem * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @dev See {IERC4626-redeem}. */ function redeemAndClaim(uint256 shares, address receiver, address owner) external returns (uint256 assets); /** * @notice Redeem all of the user's shares in the vault for the respective amount * of underlying assets without calling the reward controller, meaning user renounces * their uncommited part of the reward. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * @param receiver Address of receiver of the funds */ function emergencyWithdraw(address receiver) external returns (uint256 assets); /** * @notice Withdraw previously deposited funds from the vault, without * transferring the accumulated rewards. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * @param assets Amount of tokens to withdraw * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @dev See {IERC4626-withdraw}. */ function withdraw(uint256 assets, address receiver, address owner) external returns (uint256); /** * @notice Redeem shares in the vault for the respective amount * of underlying assets, without transferring the accumulated reward. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * @param shares Amount of shares to redeem * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @dev See {IERC4626-redeem}. */ function redeem(uint256 shares, address receiver, address owner) external returns (uint256); /** * @dev Deposit funds to the vault. Can only be called if the committee had * checked in and deposits are not paused, and the registry is not in an emergency pause. * @param receiver Reciever of the shares from the deposit * @param assets Amount of vault's native token to deposit * @dev See {IERC4626-deposit}. */ function deposit(uint256 assets, address receiver) external returns (uint256); /** * @dev Deposit funds to the vault. Can only be called if the committee had * checked in and deposits are not paused, and the registry is not in an emergency pause. * Allows to specify minimum shares to be minted for slippage protection. * @param receiver Reciever of the shares from the deposit * @param assets Amount of vault's native token to deposit * @param minShares Minimum amount of shares to minted for the assets */ function deposit(uint256 assets, address receiver, uint256 minShares) external returns (uint256); /** * @dev Deposit funds to the vault based on the amount of shares to mint specified. * Can only be called if the committee had checked in and deposits are not paused, * and the registry is not in an emergency pause. * Allows to specify maximum assets to be deposited for slippage protection. * @param receiver Reciever of the shares from the deposit * @param shares Amount of vault's shares to mint * @param maxAssets Maximum amount of assets to deposit for the shares */ function mint(uint256 shares, address receiver, uint256 maxAssets) external returns (uint256); /** * @notice Withdraw previously deposited funds from the vault, without * transferring the accumulated HAT reward. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * Allows to specify maximum shares to be burnt for slippage protection. * @param assets Amount of tokens to withdraw * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @param maxShares Maximum amount of shares to burn for the assets */ function withdraw(uint256 assets, address receiver, address owner, uint256 maxShares) external returns (uint256); /** * @notice Redeem shares in the vault for the respective amount * of underlying assets, without transferring the accumulated reward. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * Allows to specify minimum assets to be received for slippage protection. * @param shares Amount of shares to redeem * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @param minAssets Minimum amount of assets to receive for the shares */ function redeem(uint256 shares, address receiver, address owner, uint256 minAssets) external returns (uint256); /** * @notice Withdraw previously deposited funds from the vault and claim * the HAT reward that the user has earned. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * Allows to specify maximum shares to be burnt for slippage protection. * @param assets Amount of tokens to withdraw * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @param maxShares Maximum amount of shares to burn for the assets * @dev See {IERC4626-withdraw}. */ function withdrawAndClaim(uint256 assets, address receiver, address owner, uint256 maxShares) external returns (uint256 shares); /** * @notice Redeem shares in the vault for the respective amount * of underlying assets and claim the HAT reward that the user has earned. * Can only be performed if a withdraw request has been previously * submitted, and the pending period had passed, and while the withdraw * enabled timeout had not passed. Withdrawals are not permitted during * safety periods or while there is an active claim for a bounty payout. * Allows to specify minimum assets to be received for slippage protection. * @param shares Amount of shares to redeem * @param receiver Address of receiver of the funds * @param owner Address of owner of the funds * @param minAssets Minimum amount of assets to receive for the shares * @dev See {IERC4626-redeem}. */ function redeemAndClaim(uint256 shares, address receiver, address owner, uint256 minAssets) external returns (uint256 assets); /** * @notice Returns the amount of shares to be burned to give the user the exact * amount of assets requested plus cover for the fee. Also returns the amount assets * to be paid as fee. * @return shares The amount of shares to be burned to get the requested amount of assets * @return fee The amount of assets that will be paid as fee */ function previewWithdrawAndFee(uint256 assets) external view returns (uint256 shares, uint256 fee); /** * @notice Returns the amount of assets to be sent to the user for the exact * amount of shares to redeem. Also returns the amount assets to be paid as fee. * @return assets amount of assets to be sent in exchange for the amount of shares specified * @return fee The amount of assets that will be paid as fee */ function previewRedeemAndFee(uint256 shares) external view returns (uint256 assets, uint256 fee); }