Skip to content

Commit

Permalink
Merge branch 'bridged-usdc-gw' into arb-usdc
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Jun 7, 2024
2 parents 46550ee + c22559c commit 2ee063f
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ import {L2ArbitrumGateway} from "./L2ArbitrumGateway.sol";
* bridging solution and keep the possibility to upgrade to native USDC at
* some point later. This solution will NOT be used in existing Arbitrum chains.
*
* Parent chain custom gateway to be used along this parent chain custom gateway is L1USDCCustomGateway.
* Parent chain custom gateway to be used along this parent chain custom gateway is L1USDCGateway.
* 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
* - withdrawals can be permanently paused by the owner
*/
contract L2USDCCustomGateway is L2ArbitrumGateway {
contract L2USDCGateway is L2ArbitrumGateway {
address public l1USDC;
address public l2USDC;
address public owner;
bool public withdrawalsPaused;

event WithdrawalsPaused();

error L2USDCCustomGateway_WithdrawalsAlreadyPaused();
error L2USDCCustomGateway_WithdrawalsPaused();
error L2USDCCustomGateway_InvalidL1USDC();
error L2USDCCustomGateway_InvalidL2USDC();
error L2USDCCustomGateway_NotOwner();
error L2USDCCustomGateway_InvalidOwner();
error L2USDCGateway_WithdrawalsAlreadyPaused();
error L2USDCGateway_WithdrawalsPaused();
error L2USDCGateway_InvalidL1USDC();
error L2USDCGateway_InvalidL2USDC();
error L2USDCGateway_NotOwner();
error L2USDCGateway_InvalidOwner();

modifier onlyOwner() {
if (msg.sender != owner) {
revert L2USDCCustomGateway_NotOwner();
revert L2USDCGateway_NotOwner();
}
_;
}
Expand All @@ -48,13 +48,13 @@ contract L2USDCCustomGateway is L2ArbitrumGateway {
address _owner
) public {
if (_l1USDC == address(0)) {
revert L2USDCCustomGateway_InvalidL1USDC();
revert L2USDCGateway_InvalidL1USDC();
}
if (_l2USDC == address(0)) {
revert L2USDCCustomGateway_InvalidL2USDC();
revert L2USDCGateway_InvalidL2USDC();
}
if (_owner == address(0)) {
revert L2USDCCustomGateway_InvalidOwner();
revert L2USDCGateway_InvalidOwner();
}
L2ArbitrumGateway._initialize(_l1Counterpart, _router);
l1USDC = _l1USDC;
Expand All @@ -68,7 +68,7 @@ contract L2USDCCustomGateway is L2ArbitrumGateway {
*/
function pauseWithdrawals() external onlyOwner {
if (withdrawalsPaused) {
revert L2USDCCustomGateway_WithdrawalsAlreadyPaused();
revert L2USDCGateway_WithdrawalsAlreadyPaused();
}
withdrawalsPaused = true;

Expand All @@ -80,7 +80,7 @@ contract L2USDCCustomGateway is L2ArbitrumGateway {
*/
function setOwner(address newOwner) external onlyOwner {
if (newOwner == address(0)) {
revert L2USDCCustomGateway_InvalidOwner();
revert L2USDCGateway_InvalidOwner();
}
owner = newOwner;
}
Expand All @@ -97,7 +97,7 @@ contract L2USDCCustomGateway is L2ArbitrumGateway {
bytes calldata _data
) public payable override returns (bytes memory res) {
if (withdrawalsPaused) {
revert L2USDCCustomGateway_WithdrawalsPaused();
revert L2USDCGateway_WithdrawalsPaused();
}
return super.outboundTransfer(_l1Token, _to, _amount, 0, 0, _data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.0;

import {L1USDCCustomGateway} from "./L1USDCCustomGateway.sol";
import {L1USDCGateway} from "./L1USDCGateway.sol";
import {IERC20Inbox} from "../L1ArbitrumMessenger.sol";
import {IERC20Bridge} from "../../libraries/IERC20Bridge.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand All @@ -17,17 +17,17 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
* bridging solution and keep the possibility to upgrade to native USDC at
* some point later. This solution will NOT be used in existing Arbitrum chains.
*
* Child chain custom gateway to be used along this parent chain custom gateway is L2USDCCustomGateway.
* Child chain custom gateway to be used along this parent chain custom gateway is L2USDCGateway.
* 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 trigger burning all the USDC tokens locked in the gateway
*
* This contract is to be used on chains where custom fee token is used. If chain is using
* ETH as native token then use L1USDCCustomGateway instead.
* ETH as native token then use L1USDCGateway instead.
*/
contract L1FeeTokenUSDCCustomGateway is L1USDCCustomGateway {
contract L1OrbitUSDCGateway is L1USDCGateway {
using SafeERC20 for IERC20;

function _parseUserEncodedData(bytes memory data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import {
* bridging solution and keep the possibility to upgrade to native USDC at
* some point later. This solution will NOT be used in existing Arbitrum chains.
*
* Child chain custom gateway to be used along this parent chain custom gateway is L2USDCCustomGateway.
* Child chain custom gateway to be used along this parent chain custom gateway is L2USDCGateway.
* 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 trigger burning all the USDC tokens locked in the gateway
*
* This contract is to be used on chains where ETH is the native token. If chain is using
* custom fee token then use L1FeeTokenUSDCCustomGateway instead.
* custom fee token then use L1OrbitUSDCGateway instead.
*/
contract L1USDCCustomGateway is L1ArbitrumExtendedGateway {
contract L1USDCGateway is L1ArbitrumExtendedGateway {
address public l1USDC;
address public l2USDC;
address public owner;
Expand All @@ -38,17 +38,17 @@ contract L1USDCCustomGateway is L1ArbitrumExtendedGateway {
event DepositsPaused();
event GatewayUsdcBurned(uint256 amount);

error L1USDCCustomGateway_DepositsAlreadyPaused();
error L1USDCCustomGateway_DepositsPaused();
error L1USDCCustomGateway_DepositsNotPaused();
error L1USDCCustomGateway_InvalidL1USDC();
error L1USDCCustomGateway_InvalidL2USDC();
error L1USDCCustomGateway_NotOwner();
error L1USDCCustomGateway_InvalidOwner();
error L1USDCGateway_DepositsAlreadyPaused();
error L1USDCGateway_DepositsPaused();
error L1USDCGateway_DepositsNotPaused();
error L1USDCGateway_InvalidL1USDC();
error L1USDCGateway_InvalidL2USDC();
error L1USDCGateway_NotOwner();
error L1USDCGateway_InvalidOwner();

modifier onlyOwner() {
if (msg.sender != owner) {
revert L1USDCCustomGateway_NotOwner();
revert L1USDCGateway_NotOwner();
}
_;
}
Expand All @@ -62,13 +62,13 @@ contract L1USDCCustomGateway is L1ArbitrumExtendedGateway {
address _owner
) public {
if (_l1USDC == address(0)) {
revert L1USDCCustomGateway_InvalidL1USDC();
revert L1USDCGateway_InvalidL1USDC();
}
if (_l2USDC == address(0)) {
revert L1USDCCustomGateway_InvalidL2USDC();
revert L1USDCGateway_InvalidL2USDC();
}
if (_owner == address(0)) {
revert L1USDCCustomGateway_InvalidOwner();
revert L1USDCGateway_InvalidOwner();
}
L1ArbitrumGateway._initialize(_l2Counterpart, _l1Router, _inbox);
l1USDC = _l1USDC;
Expand All @@ -83,7 +83,7 @@ contract L1USDCCustomGateway is L1ArbitrumExtendedGateway {
*/
function pauseDeposits() external onlyOwner {
if (depositsPaused) {
revert L1USDCCustomGateway_DepositsAlreadyPaused();
revert L1USDCGateway_DepositsAlreadyPaused();
}
depositsPaused = true;

Expand All @@ -97,7 +97,7 @@ contract L1USDCCustomGateway is L1ArbitrumExtendedGateway {
*/
function burnLockedUSDC() external onlyOwner {
if (!depositsPaused) {
revert L1USDCCustomGateway_DepositsNotPaused();
revert L1USDCGateway_DepositsNotPaused();
}
uint256 gatewayBalance = IERC20(l1USDC).balanceOf(address(this));
Burnable(l1USDC).burn(gatewayBalance);
Expand All @@ -110,7 +110,7 @@ contract L1USDCCustomGateway is L1ArbitrumExtendedGateway {
*/
function setOwner(address newOwner) external onlyOwner {
if (newOwner == address(0)) {
revert L1USDCCustomGateway_InvalidOwner();
revert L1USDCGateway_InvalidOwner();
}
owner = newOwner;
}
Expand All @@ -128,7 +128,7 @@ contract L1USDCCustomGateway is L1ArbitrumExtendedGateway {
bytes calldata _data
) public payable override returns (bytes memory res) {
if (depositsPaused) {
revert L1USDCCustomGateway_DepositsPaused();
revert L1USDCGateway_DepositsPaused();
}
return super.outboundTransferCustomRefund(
_l1Token, _refundTo, _to, _amount, _maxGas, _gasPriceBid, _data
Expand Down
30 changes: 15 additions & 15 deletions test-e2e/orbitTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
IERC20__factory,
IInbox__factory,
IOwnable__factory,
L1FeeTokenUSDCCustomGateway__factory,
L1OrbitUSDCGateway__factory,
L1GatewayRouter__factory,
L1OrbitCustomGateway__factory,
L1OrbitERC20Gateway__factory,
L1OrbitGatewayRouter__factory,
L1USDCCustomGateway__factory,
L1USDCGateway__factory,
L2CustomGateway__factory,
L2GatewayRouter__factory,
L2USDCCustomGateway__factory,
L2USDCGateway__factory,
MockL1Usdc__factory,
ProxyAdmin__factory,
TestArbCustomToken__factory,
Expand Down Expand Up @@ -657,38 +657,38 @@ describe('orbitTokenBridge', () => {
deployerL1Wallet
).deploy()
const proxyAdmin = await proxyAdminFac.deployed()
const l1USDCCustomGatewayFactory = await new L1USDCCustomGateway__factory(
const l1USDCCustomGatewayFactory = await new L1USDCGateway__factory(
deployerL1Wallet
).deploy()
const l1USDCCustomGatewayLogic = await l1USDCCustomGatewayFactory.deployed()
const tupFactory = await new TransparentUpgradeableProxy__factory(
deployerL1Wallet
).deploy(l1USDCCustomGatewayLogic.address, proxyAdmin.address, '0x')
const tup = await tupFactory.deployed()
const l1USDCCustomGateway = L1USDCCustomGateway__factory.connect(
const l1USDCCustomGateway = L1USDCGateway__factory.connect(
tup.address,
deployerL1Wallet
)
console.log('L1USDCCustomGateway address: ', l1USDCCustomGateway.address)
console.log('L1USDCGateway address: ', l1USDCCustomGateway.address)

/// create new L2 usdc gateway behind proxy
const proxyAdminL2Fac = await new ProxyAdmin__factory(
deployerL2Wallet
).deploy()
const proxyAdminL2 = await proxyAdminL2Fac.deployed()
const l2USDCCustomGatewayFactory = await new L2USDCCustomGateway__factory(
const l2USDCCustomGatewayFactory = await new L2USDCGateway__factory(
deployerL2Wallet
).deploy()
const l2USDCCustomGatewayLogic = await l2USDCCustomGatewayFactory.deployed()
const tupL2Factory = await new TransparentUpgradeableProxy__factory(
deployerL2Wallet
).deploy(l2USDCCustomGatewayLogic.address, proxyAdminL2.address, '0x')
const tupL2 = await tupL2Factory.deployed()
const l2USDCCustomGateway = L2USDCCustomGateway__factory.connect(
const l2USDCCustomGateway = L2USDCGateway__factory.connect(
tupL2.address,
deployerL2Wallet
)
console.log('L2USDCCustomGateway address: ', l2USDCCustomGateway.address)
console.log('L2USDCGateway address: ', l2USDCCustomGateway.address)

/// create l1 usdc behind proxy
const l1UsdcFactory = await new MockL1Usdc__factory(
Expand Down Expand Up @@ -904,36 +904,36 @@ describe('orbitTokenBridge', () => {
).deploy()
const proxyAdmin = await proxyAdminFac.deployed()
const l1USDCCustomGatewayFactory =
await new L1FeeTokenUSDCCustomGateway__factory(deployerL1Wallet).deploy()
await new L1OrbitUSDCGateway__factory(deployerL1Wallet).deploy()
const l1USDCCustomGatewayLogic = await l1USDCCustomGatewayFactory.deployed()
const tupFactory = await new TransparentUpgradeableProxy__factory(
deployerL1Wallet
).deploy(l1USDCCustomGatewayLogic.address, proxyAdmin.address, '0x')
const tup = await tupFactory.deployed()
const l1USDCCustomGateway = L1USDCCustomGateway__factory.connect(
const l1USDCCustomGateway = L1USDCGateway__factory.connect(
tup.address,
deployerL1Wallet
)
console.log('L1USDCCustomGateway address: ', l1USDCCustomGateway.address)
console.log('L1USDCGateway address: ', l1USDCCustomGateway.address)

/// create new L2 usdc gateway behind proxy
const proxyAdminL2Fac = await new ProxyAdmin__factory(
deployerL2Wallet
).deploy()
const proxyAdminL2 = await proxyAdminL2Fac.deployed()
const l2USDCCustomGatewayFactory = await new L2USDCCustomGateway__factory(
const l2USDCCustomGatewayFactory = await new L2USDCGateway__factory(
deployerL2Wallet
).deploy()
const l2USDCCustomGatewayLogic = await l2USDCCustomGatewayFactory.deployed()
const tupL2Factory = await new TransparentUpgradeableProxy__factory(
deployerL2Wallet
).deploy(l2USDCCustomGatewayLogic.address, proxyAdminL2.address, '0x')
const tupL2 = await tupL2Factory.deployed()
const l2USDCCustomGateway = L2USDCCustomGateway__factory.connect(
const l2USDCCustomGateway = L2USDCGateway__factory.connect(
tupL2.address,
deployerL2Wallet
)
console.log('L2USDCCustomGateway address: ', l2USDCCustomGateway.address)
console.log('L2USDCGateway address: ', l2USDCCustomGateway.address)

/// create l1 usdc behind proxy
const l1UsdcFactory = await new MockL1Usdc__factory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

pragma solidity ^0.8.0;

import "./L1USDCCustomGateway.t.sol";
import {L1FeeTokenUSDCCustomGateway} from
"contracts/tokenbridge/ethereum/gateway/L1FeeTokenUSDCCustomGateway.sol";
import "./L1USDCGateway.t.sol";
import {L1OrbitUSDCGateway} from
"contracts/tokenbridge/ethereum/gateway/L1OrbitUSDCGateway.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20InboxMock} from "contracts/tokenbridge/test/InboxMock.sol";
import {ERC20PresetMinterPauser} from
"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";

contract L1FeeTokenUSDCCustomGatewayTest is L1USDCCustomGatewayTest {
contract L1OrbitUSDCGatewayTest is L1USDCGatewayTest {
ERC20 public nativeToken;
uint256 public nativeTokenTotalFee;

Expand All @@ -21,10 +21,10 @@ contract L1FeeTokenUSDCCustomGatewayTest is L1USDCCustomGatewayTest {
ERC20PresetMinterPauser(address(nativeToken)).mint(owner, 1_000_000 ether);
ERC20InboxMock(inbox).setMockNativeToken(address(nativeToken));

usdcGateway = new L1FeeTokenUSDCCustomGateway();
usdcGateway = new L1OrbitUSDCGateway();
l1Gateway = IL1ArbitrumGateway(address(usdcGateway));

L1FeeTokenUSDCCustomGateway(address(l1Gateway)).initialize(
L1OrbitUSDCGateway(address(l1Gateway)).initialize(
l2Gateway, router, inbox, L1_USDC, L2_USDC, owner
);

Expand Down
Loading

0 comments on commit 2ee063f

Please sign in to comment.