Skip to content

Commit

Permalink
Deposits can be unpaused
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Jul 1, 2024
1 parent 84b1864 commit 3b5eb00
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
20 changes: 17 additions & 3 deletions contracts/tokenbridge/ethereum/gateway/L1USDCGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test-foundry/L1USDCGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 3b5eb00

Please sign in to comment.