diff --git a/core/contracts/Acre.sol b/core/contracts/Acre.sol index 6b5838b8e..5bf418dfa 100644 --- a/core/contracts/Acre.sol +++ b/core/contracts/Acre.sol @@ -49,6 +49,20 @@ contract Acre is ERC4626 { return shares; } + function mint( + uint256 shares, + address receiver + ) public override returns (uint256) { + uint256 assets = super.mint(shares, receiver); + + require( + assets >= stakingParameters.minimumDepositAmount, + "Amount is less than minimum" + ); + + return assets; + } + /// @notice Stakes a given amount of tBTC token and mints shares to a /// receiver. /// @dev This function calls `deposit` function from `ERC4626` contract. The @@ -81,4 +95,13 @@ contract Acre is ERC4626 { function maxDeposit(address) public view override returns (uint256) { return stakingParameters.maximumTotalAssets - totalAssets(); } + + /// @notice Returns the maximum amount of the vault shares that can be + /// minted for the receiver, through a mint call. + /// @dev Since the Acre contract limits the maximum total tBTC tokens this + /// function converts the maximum deposit amount to shares. + /// @return The maximum amount of the vault shares. + function maxMint(address receiver) public view override returns (uint256) { + return previewDeposit(maxDeposit(receiver)); + } } diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index c7cb3bec0..7d67e7923 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -481,4 +481,42 @@ describe("Acre", () => { }) }) }) + + describe("mint", () => { + context("when staker wants to mint more shares than allowed", () => { + let sharesToMint: bigint + + beforeEach(async () => { + const maxMint = await acre.maxMint(staker1.address) + + sharesToMint = maxMint + 1n + }) + + it("should take into account the max total assets parameter and revert", async () => { + await expect( + acre.mint(sharesToMint, staker1.address), + ).to.be.revertedWithCustomError(acre, "ERC4626ExceededMaxMint") + }) + }) + + context( + "when staker wants to mint less shares than is equal to the min deposit amount", + () => { + let sharesToMint: bigint + + beforeEach(async () => { + const { minimumDepositAmount } = await acre.stakingParameters() + const previewDeposit = await acre.previewDeposit(minimumDepositAmount) + + sharesToMint = previewDeposit - 1n + }) + + it("should take into account the min deposit amount parameter and revert", async () => { + await expect( + acre.mint(sharesToMint, staker1.address), + ).to.be.revertedWith("Amount is less than minimum") + }) + }, + ) + }) })