diff --git a/core/contracts/test/upgrades/AcreBitcoinDepositorV2.sol b/core/contracts/test/upgrades/AcreBitcoinDepositorV2.sol index 911570891..73f488558 100644 --- a/core/contracts/test/upgrades/AcreBitcoinDepositorV2.sol +++ b/core/contracts/test/upgrades/AcreBitcoinDepositorV2.sol @@ -25,35 +25,17 @@ contract AcreBitcoinDepositorV2 is enum StakeRequestState { Unknown, Initialized, - Finalized, - Queued, - FinalizedFromQueue, - CancelledFromQueue - } - - struct StakeRequest { - // State of the stake request. - StakeRequestState state; - // The address to which the stBTC shares will be minted. Stored only when - // request is queued. - address staker; - // tBTC token amount to stake after deducting tBTC minting fees and the - // Depositor fee. Stored only when request is queued. - uint88 queuedAmount; + Finalized } /// @notice Mapping of stake requests. /// @dev The key is a deposit key identifying the deposit. - mapping(uint256 => StakeRequest) public stakeRequests; + mapping(uint256 => StakeRequestState) public stakeRequests; /// @notice tBTC Token contract. - // TODO: Remove slither disable when introducing upgradeability. - // slither-disable-next-line immutable-states IERC20 public tbtcToken; /// @notice stBTC contract. - // TODO: Remove slither disable when introducing upgradeability. - // slither-disable-next-line immutable-states stBTC public stbtc; /// @notice Minimum amount of a single stake request (in tBTC token precision). @@ -61,29 +43,6 @@ contract AcreBitcoinDepositorV2 is /// amount supported by tBTC Bridge. uint256 public minStakeAmount; - /// @notice Maximum amount of a single stake request (in tBTC token precision). - /// @dev The staking flow in the dApp is asynchronous and there is a short period - /// of time between a deposit funding transaction is made on Bitcoin chain - /// and revealed to this contract. This limit is used to gain better control - /// on the stakes queue, and reduce a risk of concurrent stake requests - /// made in the dApp being blocked by another big deposit. - uint256 public maxSingleStakeAmount; - - /// @notice Maximum total assets soft limit (in tBTC token precision). - /// @dev stBTC contract defines a maximum total assets limit held by the protocol - /// that new deposits cannot exceed (hard cap). Due to the asynchronous - /// manner of Bitcoin deposits process we introduce a soft limit (soft cap) - /// set to a value lower than the hard cap to let the dApp initialize - /// Bitcoin deposits only up to the soft cap limit. - uint256 public maxTotalAssetsSoftLimit; - - /// @notice Total balance of pending stake requests (in tBTC token precision). - /// @dev stBTC contract introduces limits for total deposits amount. Due to - /// asynchronous manner of the staking flow, this contract needs to track - /// balance of pending stake requests to ensure new stake request are - /// not initialized if they won't be able to finalize. - uint256 public queuedStakesBalance; - /// @notice Divisor used to compute the depositor fee taken from each deposit /// and transferred to the treasury upon stake request finalization. /// @dev That fee is computed as follows: @@ -134,57 +93,14 @@ contract AcreBitcoinDepositorV2 is uint256 stakedAmount ); - /// @notice Emitted when a stake request is queued. - /// @param depositKey Deposit key identifying the deposit. - /// @param caller Address that finalized the stake request. - /// @param queuedAmount Amount of queued tBTC tokens. - event StakeRequestQueued( - uint256 indexed depositKey, - address indexed caller, - uint256 queuedAmount - ); - - /// @notice Emitted when a stake request is finalized from the queue. - /// @dev Deposit details can be fetched from {{ ERC4626.Deposit }} - /// event emitted in the same transaction. - /// @param depositKey Deposit key identifying the deposit. - /// @param caller Address that finalized the stake request. - /// @param stakedAmount Amount of staked tBTC tokens. - event StakeRequestFinalizedFromQueue( - uint256 indexed depositKey, - address indexed caller, - uint256 stakedAmount - ); - - /// @notice Emitted when a queued stake request is cancelled. - /// @param depositKey Deposit key identifying the deposit. - /// @param staker Address of the staker. - /// @param amountCancelled Amount of queued tBTC tokens that got cancelled. - event StakeRequestCancelledFromQueue( - uint256 indexed depositKey, - address indexed staker, - uint256 amountCancelled - ); - /// @notice Emitted when a minimum single stake amount is updated. /// @param minStakeAmount New value of the minimum single stake /// amount (in tBTC token precision). event MinStakeAmountUpdated(uint256 minStakeAmount); - /// @notice Emitted when a maximum single stake amount is updated. - /// @param maxSingleStakeAmount New value of the maximum single stake - /// amount (in tBTC token precision). - event MaxSingleStakeAmountUpdated(uint256 maxSingleStakeAmount); - - /// @notice Emitted when a maximum total assets soft limit is updated. - /// @param maxTotalAssetsSoftLimit New value of the maximum total assets - /// soft limit (in tBTC token precision). - event MaxTotalAssetsSoftLimitUpdated(uint256 maxTotalAssetsSoftLimit); - /// @notice Emitted when a depositor fee divisor is updated. /// @param depositorFeeDivisor New value of the depositor fee divisor. event DepositorFeeDivisorUpdated(uint64 depositorFeeDivisor); - // TEST: New event; event NewEvent(); @@ -204,10 +120,6 @@ contract AcreBitcoinDepositorV2 is StakeRequestState expectedState ); - /// @dev Attempted to initialize a stake request with a deposit amount - /// exceeding the maximum limit for a single stake amount. - error ExceededMaxSingleStake(uint256 amount, uint256 max); - /// @dev Attempted to finalize bridging with depositor's contract tBTC balance /// lower than the calculated bridged tBTC amount. This error means /// that Governance should top-up the tBTC reserve for bridging fees @@ -217,31 +129,12 @@ contract AcreBitcoinDepositorV2 is uint256 currentBalance ); - /// @dev Attempted to notify a bridging completion, while it was already - /// notified. - error BridgingCompletionAlreadyNotified(); - - /// @dev Attempted to finalize a stake request, while bridging completion has - /// not been notified yet. - error BridgingNotCompleted(); - /// @dev Calculated depositor fee exceeds the amount of minted tBTC tokens. error DepositorFeeExceedsBridgedAmount( uint256 depositorFee, uint256 bridgedAmount ); - /// @dev Attempted to call bridging finalization for a stake request for - /// which the function was already called. - error BridgingFinalizationAlreadyCalled(); - - /// @dev Attempted to finalize or cancel a stake request that was not added - /// to the queue, or was already finalized or cancelled. - error StakeRequestNotQueued(); - - /// @dev Attempted to call function by an account that is not the staker. - error CallerNotStaker(); - /// @dev Attempted to set minimum stake amount to a value lower than the /// tBTC Bridge deposit dust threshold. error MinStakeAmountLowerThanBridgeMinDeposit( @@ -292,7 +185,7 @@ contract AcreBitcoinDepositorV2 is // We don't check if the request was already initialized, as this check // is enforced in `_initializeDeposit` when calling the // `Bridge.revealDepositWithExtraData` function. - (uint256 depositKey, uint256 initialDepositAmount) = _initializeDeposit( + (uint256 depositKey, ) = _initializeDeposit( fundingTx, reveal, encodeExtraData(staker, referral) @@ -304,12 +197,6 @@ contract AcreBitcoinDepositorV2 is StakeRequestState.Initialized ); - if (initialDepositAmount > maxSingleStakeAmount) - revert ExceededMaxSingleStake( - initialDepositAmount, - maxSingleStakeAmount - ); - emit StakeRequestInitialized(depositKey, msg.sender, staker); } @@ -318,9 +205,6 @@ contract AcreBitcoinDepositorV2 is /// It stakes the tBTC from the given deposit into stBTC, emitting the /// stBTC shares to the staker specified in the deposit extra data /// and using the referral provided in the extra data. - /// @dev In case depositing in stBTC vault fails (e.g. because of the - /// maximum deposit limit being reached), the `queueStake` function - /// should be called to add the stake request to the staking queue. /// @param depositKey Deposit key identifying the deposit. function finalizeStake(uint256 depositKey) external { transitionStakeRequestState( @@ -339,104 +223,6 @@ contract AcreBitcoinDepositorV2 is stbtc.deposit(amountToStake, staker); } - /// @notice This function should be called for previously initialized stake - /// request, after tBTC bridging process was finalized, in case the - /// `finalizeStake` failed due to stBTC vault deposit limit - /// being reached. - /// @dev It queues the stake request, until the stBTC vault is ready to - /// accept the deposit. The request must be finalized with `finalizeQueuedStake` - /// after the limit is increased or other user withdraws their funds - /// from the stBTC contract to make place for another deposit. - /// The staker has a possibility to submit `cancelQueuedStake` that - /// will withdraw the minted tBTC token and abort staking process. - /// @param depositKey Deposit key identifying the deposit. - function queueStake(uint256 depositKey) external { - transitionStakeRequestState( - depositKey, - StakeRequestState.Initialized, - StakeRequestState.Queued - ); - - StakeRequest storage request = stakeRequests[depositKey]; - - uint256 amountToQueue; - (amountToQueue, request.staker) = finalizeBridging(depositKey); - - request.queuedAmount = SafeCast.toUint88(amountToQueue); - - // Increase pending stakes balance. - queuedStakesBalance += amountToQueue; - - emit StakeRequestQueued(depositKey, msg.sender, amountToQueue); - } - - /// @notice This function should be called for previously queued stake - /// request, when stBTC vault is able to accept a deposit. - /// @param depositKey Deposit key identifying the deposit. - function finalizeQueuedStake(uint256 depositKey) external { - transitionStakeRequestState( - depositKey, - StakeRequestState.Queued, - StakeRequestState.FinalizedFromQueue - ); - - StakeRequest storage request = stakeRequests[depositKey]; - - if (request.queuedAmount == 0) revert StakeRequestNotQueued(); - - uint256 amountToStake = request.queuedAmount; - delete (request.queuedAmount); - - // Decrease pending stakes balance. - queuedStakesBalance -= amountToStake; - - emit StakeRequestFinalizedFromQueue( - depositKey, - msg.sender, - amountToStake - ); - - // Deposit tBTC in stBTC. - tbtcToken.safeIncreaseAllowance(address(stbtc), amountToStake); - // slither-disable-next-line unused-return - stbtc.deposit(amountToStake, request.staker); - } - - /// @notice Cancel queued stake. - /// The function can be called by the staker to recover tBTC that cannot - /// be finalized to stake in stBTC contract due to a deposit limit being - /// reached. - /// @dev This function can be called only after the stake request was added - /// to queue. - /// @dev Only staker provided in the extra data of the stake request can - /// call this function. - /// @param depositKey Deposit key identifying the deposit. - function cancelQueuedStake(uint256 depositKey) external { - transitionStakeRequestState( - depositKey, - StakeRequestState.Queued, - StakeRequestState.CancelledFromQueue - ); - - StakeRequest storage request = stakeRequests[depositKey]; - - uint256 amount = request.queuedAmount; - if (amount == 0) revert StakeRequestNotQueued(); - - address staker = request.staker; - // Check if caller is the staker. - if (msg.sender != staker) revert CallerNotStaker(); - - delete (request.queuedAmount); - - emit StakeRequestCancelledFromQueue(depositKey, staker, amount); - - // Decrease pending stakes balance. - queuedStakesBalance -= amount; - - tbtcToken.safeTransfer(staker, amount); - } - /// @notice Updates the minimum stake amount. /// @dev It requires that the new value is greater or equal to the tBTC Bridge /// deposit dust threshold, to ensure deposit will be able to be bridged. @@ -456,30 +242,9 @@ contract AcreBitcoinDepositorV2 is minStakeAmount = newMinStakeAmount; emit MinStakeAmountUpdated(newMinStakeAmount); - } - - /// @notice Updates the maximum single stake amount. - /// @param newMaxSingleStakeAmount New maximum single stake amount (in tBTC - /// precision). - function updateMaxSingleStakeAmount( - uint256 newMaxSingleStakeAmount - ) external onlyOwner { - maxSingleStakeAmount = newMaxSingleStakeAmount; // TEST: Emit newly added event. emit NewEvent(); - emit MaxSingleStakeAmountUpdated(newMaxSingleStakeAmount); - } - - /// @notice Updates the maximum total assets soft limit. - /// @param newMaxTotalAssetsSoftLimit New maximum total assets soft limit - /// (in tBTC precision). - function updateMaxTotalAssetsSoftLimit( - uint256 newMaxTotalAssetsSoftLimit - ) external onlyOwner { - maxTotalAssetsSoftLimit = newMaxTotalAssetsSoftLimit; - - emit MaxTotalAssetsSoftLimitUpdated(newMaxTotalAssetsSoftLimit); } /// @notice Updates the depositor fee divisor. @@ -502,34 +267,6 @@ contract AcreBitcoinDepositorV2 is return minStakeAmount; } - /// @notice Maximum stake amount (in tBTC token precision). - /// @dev It takes into consideration the maximum total assets soft limit (soft - /// cap), that is expected to be set below the stBTC maximum total assets - /// limit (hard cap). - /// @dev This function should be called before Bitcoin transaction funding - /// is made. The `initializeStakeRequest` function is not enforcing this - /// limit, not to block the reveal deposit operation of the concurrent - /// deposits made in the dApp in the short window between limit check, - /// submission of Bitcoin funding transaction and stake request - /// initialization. - /// @return Maximum allowed stake amount. - function maxStake() external view returns (uint256) { - uint256 currentTotalAssets = stbtc.totalAssets(); - - if (currentTotalAssets >= maxTotalAssetsSoftLimit) { - return 0; - } - - uint256 availableLimit = maxTotalAssetsSoftLimit - currentTotalAssets; - - if (queuedStakesBalance >= availableLimit) { - return 0; - } - availableLimit -= queuedStakesBalance; - - return Math.min(availableLimit, maxSingleStakeAmount); - } - // TODO: Handle minimum deposit amount in tBTC Bridge vs stBTC. /// @notice Encodes staker address and referral as extra data. @@ -572,14 +309,14 @@ contract AcreBitcoinDepositorV2 is StakeRequestState newState ) internal { // Validate current stake request state. - if (stakeRequests[depositKey].state != expectedState) + if (stakeRequests[depositKey] != expectedState) revert UnexpectedStakeRequestState( - stakeRequests[depositKey].state, + stakeRequests[depositKey], expectedState ); // Transition to a new state. - stakeRequests[depositKey].state = newState; + stakeRequests[depositKey] = newState; } /// @notice This function should be called for previously initialized stake diff --git a/core/contracts/test/upgrades/stBTCV2.sol b/core/contracts/test/upgrades/stBTCV2.sol index 586c1e246..608a79c5e 100644 --- a/core/contracts/test/upgrades/stBTCV2.sol +++ b/core/contracts/test/upgrades/stBTCV2.sol @@ -1,17 +1,16 @@ // SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.21; -import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol"; -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; import "../../Dispatcher.sol"; +import "../../lib/ERC4626Fees.sol"; /// @title stBTCV2 /// @dev This is a contract used to test stBTC upgradeability. It is a copy of /// stBTC contract with some differences marked with `TEST:` comments. -contract stBTCV2 is ERC4626Upgradeable, Ownable2StepUpgradeable { +contract stBTCV2 is ERC4626Fees, Ownable2StepUpgradeable { using SafeERC20 for IERC20; /// Dispatcher contract that routes tBTC from stBTC to a given vault and back. @@ -27,9 +26,6 @@ contract stBTCV2 is ERC4626Upgradeable, Ownable2StepUpgradeable { /// before depositing in the Acre contract. uint256 public minimumDepositAmount; - /// Maximum total amount of tBTC token held by Acre protocol. - uint256 public maximumTotalAssets; - /// Entry fee basis points applied to entry fee calculation. uint256 public entryFeeBasisPoints; @@ -45,17 +41,21 @@ contract stBTCV2 is ERC4626Upgradeable, Ownable2StepUpgradeable { /// Emitted when deposit parameters are updated. /// @param minimumDepositAmount New value of the minimum deposit amount. - /// @param maximumTotalAssets New value of the maximum total assets amount. - event DepositParametersUpdated( - uint256 minimumDepositAmount, - uint256 maximumTotalAssets - ); + event DepositParametersUpdated(uint256 minimumDepositAmount); /// Emitted when the dispatcher contract is updated. /// @param oldDispatcher Address of the old dispatcher contract. /// @param newDispatcher Address of the new dispatcher contract. event DispatcherUpdated(address oldDispatcher, address newDispatcher); + /// Emitted when the entry fee basis points are updated. + /// @param entryFeeBasisPoints New value of the fee basis points. + event EntryFeeBasisPointsUpdated(uint256 entryFeeBasisPoints); + + /// Emitted when the exit fee basis points are updated. + /// @param exitFeeBasisPoints New value of the fee basis points. + event ExitFeeBasisPointsUpdated(uint256 exitFeeBasisPoints); + // TEST: New event. event NewEvent(); @@ -101,25 +101,15 @@ contract stBTCV2 is ERC4626Upgradeable, Ownable2StepUpgradeable { } /// @notice Updates deposit parameters. - /// @dev To disable the limit for deposits, set the maximum total assets to - /// maximum (`type(uint256).max`). /// @param _minimumDepositAmount New value of the minimum deposit amount. It /// is the minimum amount for a single deposit operation. - /// @param _maximumTotalAssets New value of the maximum total assets amount. - /// It is the maximum amount of the tBTC token that the Acre protocol - /// can hold. function updateDepositParameters( - uint256 _minimumDepositAmount, - uint256 _maximumTotalAssets + uint256 _minimumDepositAmount ) external onlyOwner { // TODO: Introduce a parameters update process. minimumDepositAmount = _minimumDepositAmount; - maximumTotalAssets = _maximumTotalAssets; - emit DepositParametersUpdated( - _minimumDepositAmount, - _maximumTotalAssets - ); + emit DepositParametersUpdated(_minimumDepositAmount); } // TODO: Implement a governed upgrade process that initiates an update and @@ -150,6 +140,30 @@ contract stBTCV2 is ERC4626Upgradeable, Ownable2StepUpgradeable { IERC20(asset()).forceApprove(address(dispatcher), type(uint256).max); } + // TODO: Implement a governed upgrade process that initiates an update and + // then finalizes it after a delay. + /// @notice Update the entry fee basis points. + /// @param newEntryFeeBasisPoints New value of the fee basis points. + function updateEntryFeeBasisPoints( + uint256 newEntryFeeBasisPoints + ) external onlyOwner { + entryFeeBasisPoints = newEntryFeeBasisPoints; + + emit EntryFeeBasisPointsUpdated(newEntryFeeBasisPoints); + } + + // TODO: Implement a governed upgrade process that initiates an update and + // then finalizes it after a delay. + /// @notice Update the exit fee basis points. + /// @param newExitFeeBasisPoints New value of the fee basis points. + function updateExitFeeBasisPoints( + uint256 newExitFeeBasisPoints + ) external onlyOwner { + exitFeeBasisPoints = newExitFeeBasisPoints; + + emit ExitFeeBasisPointsUpdated(newExitFeeBasisPoints); + } + // TEST: Modified function. function deposit( uint256 assets, @@ -169,11 +183,15 @@ contract stBTCV2 is ERC4626Upgradeable, Ownable2StepUpgradeable { /// which determines the minimum amount for a single deposit operation. /// The amount of the assets has to be pre-approved in the tBTC /// contract. - /// The msg.sender is required to grant approval for tBTC transfer. + /// The msg.sender is required to grant approval for the transfer of a + /// certain amount of tBTC, and in addition, approval for the associated + /// fee. Specifically, the total amount to be approved (amountToApprove) + /// should be equal to the sum of the deposited amount and the fee. /// To determine the total assets amount necessary for approval /// corresponding to a given share amount, use the `previewMint` function. /// @param shares Amount of shares to mint. /// @param receiver The address to which the shares will be minted. + /// @return assets Used assets to mint shares. function mint( uint256 shares, address receiver @@ -191,45 +209,24 @@ contract stBTCV2 is ERC4626Upgradeable, Ownable2StepUpgradeable { return convertToAssets(balanceOf(account)); } - /// @notice Returns the maximum amount of the tBTC token that can be - /// deposited into the vault for the receiver through a deposit - /// call. It takes into account the deposit parameter, maximum total - /// assets, which determines the total amount of tBTC token held by - /// Acre protocol. - /// @dev When the remaining amount of unused limit is less than the minimum - /// deposit amount, this function returns 0. - /// @return The maximum amount of tBTC token that can be deposited into - /// Acre protocol for the receiver. - function maxDeposit(address) public view override returns (uint256) { - if (maximumTotalAssets == type(uint256).max) { - return type(uint256).max; - } - - uint256 _totalAssets = totalAssets(); + /// @return Returns deposit parameters. + function depositParameters() public view returns (uint256) { + return (minimumDepositAmount); + } - return - _totalAssets >= maximumTotalAssets - ? 0 - : maximumTotalAssets - _totalAssets; + /// @return Returns entry fee basis point used in deposits. + function _entryFeeBasisPoints() internal view override returns (uint256) { + return entryFeeBasisPoints; } - /// @notice Returns the maximum amount of the vault shares that can be - /// minted for the receiver, through a mint call. - /// @dev Since the stBTC 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) { - uint256 _maxDeposit = maxDeposit(receiver); - - // slither-disable-next-line incorrect-equality - return - _maxDeposit == type(uint256).max - ? type(uint256).max - : convertToShares(_maxDeposit); + /// @return Returns exit fee basis point used in withdrawals. + function _exitFeeBasisPoints() internal view override returns (uint256) { + return exitFeeBasisPoints; } - /// @return Returns deposit parameters. - function depositParameters() public view returns (uint256, uint256) { - return (minimumDepositAmount, maximumTotalAssets); + /// @notice Returns the address of the treasury wallet, where fees should be + /// transferred to. + function _feeRecipient() internal view override returns (address) { + return treasury; } } diff --git a/core/test/AcreBitcoinDepositor.upgrade.test.ts b/core/test/AcreBitcoinDepositor.upgrade.test.ts index 7bad1eda9..c447c74ce 100644 --- a/core/test/AcreBitcoinDepositor.upgrade.test.ts +++ b/core/test/AcreBitcoinDepositor.upgrade.test.ts @@ -38,59 +38,11 @@ describe("AcreBitcoinDepositor contract upgrade", () => { ;({ governance } = await helpers.signers.getNamedSigners()) }) - context("when upgrading to an invalid contract", () => { - context("when the new variable was added before the old one", () => { - beforeAfterSnapshotWrapper() - - it("should throw an error", async () => { - await expect( - helpers.upgrades.upgradeProxy( - "AcreBitcoinDepositor", - "AcreBitcoinDepositorMisplacedSlot", - { - initializerArgs: [ - await tbtcBridge.getAddress(), - await tbtcVault.getAddress(), - await tbtc.getAddress(), - await stbtc.getAddress(), - ], - factoryOpts: { signer: governance }, - }, - ), - ).to.rejectedWith(Error, "Inserted `newVariable`") - }) - }) - - context("when a variable was removed", () => { - beforeAfterSnapshotWrapper() - - it("should throw an error", async () => { - await expect( - helpers.upgrades.upgradeProxy( - "AcreBitcoinDepositor", - "AcreBitcoinDepositorMissingSlot", - { - initializerArgs: [ - await tbtcBridge.getAddress(), - await tbtcVault.getAddress(), - await tbtc.getAddress(), - await stbtc.getAddress(), - ], - factoryOpts: { signer: governance }, - }, - ), - ).to.be.rejectedWith(Error, "Deleted `queuedStakesBalance`") - }) - }) - }) - context("when upgrading to a valid contract", () => { const newVariable = 1n let bitcoinDepositorV2: AcreBitcoinDepositorV2 let v1InitialParameters: { minStakeAmount: bigint - maxSingleStakeAmount: bigint - maxTotalAssetsSoftLimit: bigint depositorFeeDivisor: bigint } @@ -98,15 +50,11 @@ describe("AcreBitcoinDepositor contract upgrade", () => { before(async () => { const minStakeAmount = await bitcoinDepositor.minStakeAmount() - const maxSingleStakeAmount = await bitcoinDepositor.maxSingleStakeAmount() - const maxTotalAssetsSoftLimit = - await bitcoinDepositor.maxTotalAssetsSoftLimit() + const depositorFeeDivisor = await bitcoinDepositor.depositorFeeDivisor() v1InitialParameters = { minStakeAmount, - maxSingleStakeAmount, - maxTotalAssetsSoftLimit, depositorFeeDivisor, } @@ -154,27 +102,20 @@ describe("AcreBitcoinDepositor contract upgrade", () => { expect(await bitcoinDepositorV2.minStakeAmount()).to.eq( v1InitialParameters.minStakeAmount, ) - expect(await bitcoinDepositorV2.maxSingleStakeAmount()).to.eq( - v1InitialParameters.maxSingleStakeAmount, - ) - - expect(await bitcoinDepositorV2.maxTotalAssetsSoftLimit()).to.eq( - v1InitialParameters.maxTotalAssetsSoftLimit, - ) expect(await bitcoinDepositorV2.depositorFeeDivisor()).to.eq( v1InitialParameters.depositorFeeDivisor, ) }) }) - describe("upgraded `updateMaxSingleStakeAmount` function", () => { - const newMaxSingleStakeAmount: bigint = to1e18(1000) + describe("upgraded `updateMinStakeAmount` function", () => { + const newMinStakeAmount: bigint = to1e18(1000) let tx: ContractTransactionResponse before(async () => { tx = await bitcoinDepositorV2 .connect(governance) - .updateMaxSingleStakeAmount(newMaxSingleStakeAmount) + .updateMinStakeAmount(newMinStakeAmount) }) it("should emit `NewEvent` event", async () => { diff --git a/core/test/stBTC.upgrade.test.ts b/core/test/stBTC.upgrade.test.ts index 01d39d9d6..3bf77cbc1 100644 --- a/core/test/stBTC.upgrade.test.ts +++ b/core/test/stBTC.upgrade.test.ts @@ -20,54 +20,22 @@ describe("stBTC contract upgrade", () => { let tbtcAddress: string let stbtc: StBTC let treasury: HardhatEthersSigner - let deployer: HardhatEthersSigner let governance: HardhatEthersSigner before(async () => { ;({ tbtc, stbtc } = await loadFixture(fixture)) tbtcAddress = await tbtc.getAddress() - ;({ deployer, treasury, governance } = - await helpers.signers.getNamedSigners()) - }) - - context("when upgrading to an invalid contract", () => { - context("when the new variable was added before the old one", () => { - beforeAfterSnapshotWrapper() - - it("should throw an error", async () => { - await expect( - helpers.upgrades.upgradeProxy("stBTC", "stBTCMisplacedSlot", { - initializerArgs: [tbtcAddress, treasury.address], - factoryOpts: { signer: deployer }, - }), - ).to.rejectedWith(Error, "Inserted `newVariable`") - }) - }) - - context("when a variable was removed", () => { - beforeAfterSnapshotWrapper() - - it("should throw an error", async () => { - await expect( - helpers.upgrades.upgradeProxy("stBTC", "stBTCMissingSlot", { - initializerArgs: [tbtcAddress, treasury.address], - factoryOpts: { signer: deployer }, - }), - ).to.be.rejectedWith(Error, "Deleted `treasury`") - }) - }) + ;({ treasury, governance } = await helpers.signers.getNamedSigners()) }) context("when upgrading to a valid contract", () => { let stbtcV2: StBTCV2 let v1MinimumDepositAmount: bigint - let v1MaximumTotalAssets: bigint const newVariable = 1n beforeAfterSnapshotWrapper() before(async () => { - v1MaximumTotalAssets = await stbtc.maximumTotalAssets() v1MinimumDepositAmount = await stbtc.minimumDepositAmount() const [upgradedStBTC] = await helpers.upgrades.upgradeProxy( @@ -104,7 +72,6 @@ describe("stBTC contract upgrade", () => { expect(await stbtcV2.minimumDepositAmount()).to.eq( v1MinimumDepositAmount, ) - expect(await stbtcV2.maximumTotalAssets()).to.eq(v1MaximumTotalAssets) }) })