Skip to content

Commit

Permalink
Owner ssets the burn amount
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Jul 1, 2024
1 parent 5b8a2c5 commit 84b1864
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
34 changes: 20 additions & 14 deletions contracts/tokenbridge/ethereum/gateway/L1USDCGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ pragma solidity ^0.8.4;
import {
L1ArbitrumExtendedGateway,
L1ArbitrumGateway,
IL1ArbitrumGateway,
ITokenGateway,
TokenGateway,
IERC20
TokenGateway
} from "./L1ArbitrumExtendedGateway.sol";
import {IFiatToken} from "../../libraries/IFiatToken.sol";

Expand All @@ -26,6 +24,7 @@ import {IFiatToken} from "../../libraries/IFiatToken.sol";
* - it is ownable
* - owner can one-time permanently pause 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
*
* This contract is to be used on chains where ETH is the native token. If chain is using
Expand All @@ -37,11 +36,12 @@ contract L1USDCGateway is L1ArbitrumExtendedGateway {
address public owner;
address public burner;
bool public depositsPaused;
uint256 public l2GatewaySupply;
uint256 public burnAmount;

event DepositsPaused();
event GatewayUsdcBurned(uint256 amount);
event BurnerSet(address indexed burner);
event BurnAmountSet(uint256 amount);

error L1USDCGateway_DepositsAlreadyPaused();
error L1USDCGateway_DepositsPaused();
Expand All @@ -51,7 +51,7 @@ contract L1USDCGateway is L1ArbitrumExtendedGateway {
error L1USDCGateway_NotOwner();
error L1USDCGateway_InvalidOwner();
error L1USDCGateway_NotBurner();
error L1USDCGateway_L2SupplyNotSet();
error L1USDCGateway_BurnAmountNotSet();

modifier onlyOwner() {
if (msg.sender != owner) {
Expand Down Expand Up @@ -97,14 +97,20 @@ contract L1USDCGateway is L1ArbitrumExtendedGateway {
emit DepositsPaused();
}

function setL2GatewaySupply(uint256 _l2GatewaySupply) external onlyOwner {
l2GatewaySupply = _l2GatewaySupply;
/**
* @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
* should verify that correct amount is set before proceeding with burning.
*/
function setBurnAmount(uint256 _burnAmount) external onlyOwner {
burnAmount = _burnAmount;
emit BurnAmountSet(_burnAmount);
}

/**
* @notice Burns the USDC tokens escrowed in the gateway.
* @dev Can be called by burner when deposits are paused and when
* L2 gateway has set the L2 supply. That's the amount that will be burned
* owner has set the burn amount. Amount should match the L2 supply.
* Function signature complies by Bridged USDC Standard.
*/
function burnLockedUSDC() external {
Expand All @@ -114,14 +120,14 @@ contract L1USDCGateway is L1ArbitrumExtendedGateway {
if (!depositsPaused) {
revert L1USDCGateway_DepositsNotPaused();
}
uint256 _amountToBurn = l2GatewaySupply;
if (_amountToBurn == 0) {
revert L1USDCGateway_L2SupplyNotSet();
uint256 _burnAmount = burnAmount;
if (_burnAmount == 0) {
revert L1USDCGateway_BurnAmountNotSet();
}

l2GatewaySupply = 0;
IFiatToken(l1USDC).burn(_amountToBurn);
emit GatewayUsdcBurned(_amountToBurn);
burnAmount = 0;
IFiatToken(l1USDC).burn(_burnAmount);
emit GatewayUsdcBurned(_burnAmount);
}

/**
Expand Down
25 changes: 20 additions & 5 deletions test-foundry/L1USDCGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ contract L1USDCGatewayTest is L1ArbitrumExtendedGatewayTest {
vm.prank(owner);
usdcGateway.setBurner(burner);

/// set L2 supply
vm.prank(address(IInbox(l1Gateway.inbox()).bridge()));
/// set burn amount
vm.prank(owner);
uint256 l2Supply = lockedAmount - 100;
usdcGateway.setL2GatewaySupply(l2Supply);
usdcGateway.setBurnAmount(l2Supply);

vm.expectEmit(true, true, true, true);
emit GatewayUsdcBurned(l2Supply);
Expand Down Expand Up @@ -82,7 +82,7 @@ contract L1USDCGatewayTest is L1ArbitrumExtendedGatewayTest {
usdcGateway.burnLockedUSDC();
}

function test_burnLockedUSDC_revert_L2SupplyNotSet() public {
function test_burnLockedUSDC_revert_BurnAmountNotSet() public {
/// add some USDC to the gateway
uint256 lockedAmount = 234 ether;
deal(L1_USDC, address(usdcGateway), lockedAmount);
Expand All @@ -96,7 +96,9 @@ contract L1USDCGatewayTest is L1ArbitrumExtendedGatewayTest {
vm.prank(owner);
usdcGateway.setBurner(burner);

vm.expectRevert(abi.encodeWithSelector(L1USDCGateway.L1USDCGateway_L2SupplyNotSet.selector));
vm.expectRevert(
abi.encodeWithSelector(L1USDCGateway.L1USDCGateway_BurnAmountNotSet.selector)
);
vm.prank(burner);
usdcGateway.burnLockedUSDC();
}
Expand Down Expand Up @@ -370,6 +372,18 @@ contract L1USDCGatewayTest is L1ArbitrumExtendedGatewayTest {
usdcGateway.setBurner(address(0));
}

function test_setBurnAmount() public {
uint256 amount = 100;

vm.expectEmit(true, true, true, true);
emit BurnAmountSet(amount);

vm.prank(owner);
usdcGateway.setBurnAmount(amount);

assertEq(usdcGateway.burnAmount(), amount, "Invalid burnAmount");
}

function test_setOwner() public {
address newOwner = makeAddr("new-owner");
vm.prank(owner);
Expand All @@ -395,6 +409,7 @@ contract L1USDCGatewayTest is L1ArbitrumExtendedGatewayTest {
event DepositsPaused();
event GatewayUsdcBurned(uint256 amount);
event BurnerSet(address indexed burner);
event BurnAmountSet(uint256 amount);

event TicketData(uint256 maxSubmissionCost);
event RefundAddresses(address excessFeeRefundAddress, address callValueRefundAddress);
Expand Down

0 comments on commit 84b1864

Please sign in to comment.