From 3b5eb00777ade3a9feeb23d4d56dded917e0ecc1 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Mon, 1 Jul 2024 14:15:49 +0200 Subject: [PATCH] Deposits can be unpaused --- .../ethereum/gateway/L1USDCGateway.sol | 20 +++++++++-- test-foundry/L1USDCGateway.t.sol | 33 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/contracts/tokenbridge/ethereum/gateway/L1USDCGateway.sol b/contracts/tokenbridge/ethereum/gateway/L1USDCGateway.sol index 67a4dddc4..605f6b9f2 100644 --- a/contracts/tokenbridge/ethereum/gateway/L1USDCGateway.sol +++ b/contracts/tokenbridge/ethereum/gateway/L1USDCGateway.sol @@ -22,7 +22,7 @@ import {IFiatToken} from "../../libraries/IFiatToken.sol"; * This custom gateway differs from standard gateway in the following ways: * - it supports a single parent chain - child chain USDC token pair * - it is ownable - * - owner can one-time permanently pause deposits + * - owner can pause and unpause deposits * - owner can set a burner address * - owner can set the amount of USDC tokens to be burned by burner * - burner can trigger burning the amount of USDC tokens locked in the gateway that matches the L2 supply @@ -39,11 +39,13 @@ contract L1USDCGateway is L1ArbitrumExtendedGateway { uint256 public burnAmount; event DepositsPaused(); + event DepositsUnpaused(); event GatewayUsdcBurned(uint256 amount); event BurnerSet(address indexed burner); event BurnAmountSet(uint256 amount); error L1USDCGateway_DepositsAlreadyPaused(); + error L1USDCGateway_DepositsAlreadyUnpaused(); error L1USDCGateway_DepositsPaused(); error L1USDCGateway_DepositsNotPaused(); error L1USDCGateway_InvalidL1USDC(); @@ -85,8 +87,8 @@ contract L1USDCGateway is L1ArbitrumExtendedGateway { /** * @notice Pauses deposits. This can only be called by the owner. - * @dev Pausing is permanent and can't be undone. Pausing is prerequisite for burning escrowed USDC tokens. - * Incoming withdrawals are not affected. Pausing the withdrawals needs to be done separately on the child chain. + * @dev Pausing is prerequisite for burning escrowed USDC tokens. Incoming withdrawals are not affected. + * Pausing the withdrawals needs to be done separately on the child chain. */ function pauseDeposits() external onlyOwner { if (depositsPaused) { @@ -97,6 +99,18 @@ contract L1USDCGateway is L1ArbitrumExtendedGateway { emit DepositsPaused(); } + /** + * @notice Unpauses deposits. This can only be called by the owner. + */ + function unpauseDeposits() external onlyOwner { + if (!depositsPaused) { + revert L1USDCGateway_DepositsAlreadyUnpaused(); + } + depositsPaused = false; + + emit DepositsUnpaused(); + } + /** * @notice Owner sets the amount of USDC tokens to be burned by burner account. * @dev This amount should match the L2 supply of bridged USDC. But it's not enforced, so burner diff --git a/test-foundry/L1USDCGateway.t.sol b/test-foundry/L1USDCGateway.t.sol index 2b69ea6f1..3b69be656 100644 --- a/test-foundry/L1USDCGateway.t.sol +++ b/test-foundry/L1USDCGateway.t.sol @@ -384,6 +384,11 @@ contract L1USDCGatewayTest is L1ArbitrumExtendedGatewayTest { assertEq(usdcGateway.burnAmount(), amount, "Invalid burnAmount"); } + function test_setBurnAmount_revert_NotOwner() public { + vm.expectRevert(abi.encodeWithSelector(L1USDCGateway.L1USDCGateway_NotOwner.selector)); + usdcGateway.setBurnAmount(100); + } + function test_setOwner() public { address newOwner = makeAddr("new-owner"); vm.prank(owner); @@ -403,10 +408,38 @@ contract L1USDCGatewayTest is L1ArbitrumExtendedGatewayTest { usdcGateway.setOwner(owner); } + function test_unpauseDeposits() public { + vm.prank(owner); + usdcGateway.pauseDeposits(); + assertEq(usdcGateway.depositsPaused(), true, "Invalid depositPaused"); + + vm.expectEmit(true, true, true, true); + emit DepositsUnpaused(); + + vm.prank(owner); + usdcGateway.unpauseDeposits(); + + assertEq(usdcGateway.depositsPaused(), false, "Invalid depositPaused"); + } + + function test_unpauseDeposits_revert_NotOwner() public { + vm.expectRevert(abi.encodeWithSelector(L1USDCGateway.L1USDCGateway_NotOwner.selector)); + usdcGateway.unpauseDeposits(); + } + + function test_unpauseDeposits_revert_DepositsAlreadyUnpaused() public { + vm.prank(owner); + vm.expectRevert( + abi.encodeWithSelector(L1USDCGateway.L1USDCGateway_DepositsAlreadyUnpaused.selector) + ); + usdcGateway.unpauseDeposits(); + } + //// // Event declarations //// event DepositsPaused(); + event DepositsUnpaused(); event GatewayUsdcBurned(uint256 amount); event BurnerSet(address indexed burner); event BurnAmountSet(uint256 amount);