- 
        Couldn't load subscription status. 
- Fork 157
Bridged usdc custom gateway #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            118 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b97102c
              
                Skeleton for bridged usdc gateway
              
              
                gvladika 0913a39
              
                burn locked USDC  draft
              
              
                gvladika e54ad2c
              
                Draft L2USDCGateway
              
              
                gvladika 6ca29d3
              
                Use ownable
              
              
                gvladika 7ce93c7
              
                Make depositing pausable
              
              
                gvladika deab8b0
              
                Make withdrawals pausable
              
              
                gvladika 7822064
              
                Send L1-L2 msg to pause withdrawals
              
              
                gvladika 03e1ea3
              
                Mark initializer, check if paused before burning
              
              
                gvladika 402c649
              
                Add test skeleton
              
              
                gvladika 5f065e0
              
                Add events
              
              
                gvladika 9a0d25c
              
                Add tests
              
              
                gvladika bc1c2a2
              
                Add pauseDeposits tests
              
              
                gvladika 28aa86a
              
                Test burnLockedUSDC
              
              
                gvladika 3d388ff
              
                Add outboundTransfer tests
              
              
                gvladika ad28ba8
              
                Add finalize inbound transfe test
              
              
                gvladika ae406d1
              
                Check if params are address(0)
              
              
                gvladika 558c81a
              
                Add l2 usdc gateway tests
              
              
                gvladika 55d0f2a
              
                Add more tests
              
              
                gvladika a81f5e5
              
                Add pauseWithdrawals tests
              
              
                gvladika 4b60ef6
              
                Check outbound transfer reverts when withdrawals are paused
              
              
                gvladika 799d31b
              
                Implement ownable directly into base contract
              
              
                gvladika 40ec0cd
              
                Merge branch 'main' into bridged-usdc-gw
              
              
                gvladika 84d43f1
              
                First draft of e2e test
              
              
                gvladika e133a66
              
                Fix registration
              
              
                gvladika e3b6dfb
              
                Wait for L2 msg
              
              
                gvladika 761d791
              
                Pause and check it was successful
              
              
                gvladika 1bf071e
              
                Still in progress
              
              
                gvladika d305518
              
                Use mock USDC implementations
              
              
                gvladika 9feb6ff
              
                Test burning the L1 USDC supply
              
              
                gvladika 1f867a0
              
                Simulate ownership transfer
              
              
                gvladika dac051e
              
                Run test only for eth based chains
              
              
                gvladika dfd5b48
              
                Make existing tests work with eth based chains
              
              
                gvladika 65d604b
              
                Run CI e2e tests for both erc20/eth chains
              
              
                gvladika b79d4d8
              
                Fix format
              
              
                gvladika 1ce46a3
              
                Fix test
              
              
                gvladika 33d8be2
              
                Add natspec
              
              
                gvladika 58a0ecc
              
                Add natspec
              
              
                gvladika 8975eb4
              
                Make L2 isdc gateway ownable. Don't use cross-chain msgs for pausing
              
              
                gvladika 3774d25
              
                Provide referent bridged USDC implementation -  BridgedUsdcCustomToken
              
              
                gvladika 44c26b7
              
                Fund accounts
              
              
                gvladika c1c088c
              
                Add fee token version of custom usdc gateway
              
              
                gvladika 28d299c
              
                Add Foundry tests for L1 fee token usdc gateway
              
              
                gvladika 68e76dd
              
                Add coverage
              
              
                gvladika d8f336c
              
                Add e2e test for L1 fee token usdc gateway
              
              
                gvladika de4a2d9
              
                Fix test
              
              
                gvladika 76b93ab
              
                First draft
              
              
                gvladika f971a57
              
                Add Solady
              
              
                gvladika 89bede4
              
                Remove solady
              
              
                gvladika d3b69b8
              
                Add helper function to deploy usdc token from bytecode
              
              
                gvladika 4b86a99
              
                Deploy and init FiatTokenArbitrumOrbitV2_2 in FOundry tests
              
              
                gvladika bc9865b
              
                Add back initialization
              
              
                gvladika 59457fc
              
                Use FiatTokenArbitrumOrbitV2_2 for usdc token
              
              
                gvladika cb941df
              
                Update test
              
              
                gvladika 98d711e
              
                Add initializtion of usdc token
              
              
                gvladika 5b1f6bf
              
                Update refs
              
              
                gvladika 0c899ae
              
                Remove unused
              
              
                gvladika 53dc0d2
              
                Set minter in separate call
              
              
                gvladika 46550ee
              
                Set minter in separate call in e2e tests
              
              
                gvladika c22559c
              
                Rename contracts
              
              
                gvladika 2ee063f
              
                Merge branch 'bridged-usdc-gw' into arb-usdc
              
              
                gvladika 16f5e8c
              
                FOrmatting
              
              
                gvladika 766d5e1
              
                Use latest token implementation
              
              
                gvladika bda2829
              
                Formatting
              
              
                gvladika 4951bad
              
                Merge branch 'bridged-usdc-gw' into arb-usdc
              
              
                gvladika 09436a5
              
                Make USDC gateway burn and mint tokens directly
              
              
                gvladika 8b4460f
              
                Adapt l1address check for USDC gateway
              
              
                gvladika f5009a9
              
                Add ability to unpause bridging
              
              
                gvladika 52288c2
              
                Make burning the USDC only avaiable to separate burner account
              
              
                gvladika 1ad8584
              
                Keep base gateway unchanged
              
              
                gvladika d1d9f5a
              
                Send L2 supply from l2gw to l1gw when withdrawals are paused
              
              
                gvladika 1b654d6
              
                Remove ability to unpause
              
              
                gvladika 635c6ea
              
                Simplify finalizeInboundTransfer
              
              
                gvladika e60232b
              
                Extract IFiatToken interface
              
              
                gvladika 97c062e
              
                Merge branch 'bridged-usdc-gw' into arb-usdc
              
              
                gvladika 9dab9f4
              
                Use FiatTokenV2_2
              
              
                gvladika 925b340
              
                Bump SDK
              
              
                gvladika d19bb45
              
                Adapt network registration to the new SDK requirements
              
              
                gvladika d345b73
              
                Update e2e test to latest design
              
              
                gvladika 9a33cc0
              
                Update e2e test for fee token chains
              
              
                gvladika 700be14
              
                Merge pull request #88 from OffchainLabs/arb-usdc
              
              
                gvladika ae73006
              
                Re-set L2 supply after burning
              
              
                gvladika 5d5e589
              
                Update slither db
              
              
                gvladika 538e4c5
              
                Update natspec
              
              
                gvladika 226c57f
              
                Re-order storage
              
              
                gvladika 053e1f0
              
                Add test
              
              
                gvladika a55ebb0
              
                Remove unused contract
              
              
                gvladika 4f9f7ba
              
                Remove implementation from child contract
              
              
                gvladika 8628836
              
                Check address validity when finalizing deposit in internal function
              
              
                gvladika 11ebb25
              
                Use _isValidTokenAddress in withdrawal entrypoint
              
              
                gvladika 43d1eb9
              
                Natspec
              
              
                gvladika e3de5b3
              
                Slither
              
              
                gvladika de23c24
              
                Add package with circle's usdc code
              
              
                gvladika d218bd9
              
                Use bytecode from package
              
              
                gvladika c8a4f72
              
                deploy sig checker from imported bytecode
              
              
                gvladika afb8544
              
                Merge pull request #89 from OffchainLabs/refactor-internal-func
              
              
                gzeoneth 363f13f
              
                chore: bump stablecoin version
              
              
                gzeoneth 4febc71
              
                Remove unrelated script
              
              
                gvladika 5b8a2c5
              
                Do not send L2 to L1 msg
              
              
                gvladika 84b1864
              
                Owner ssets the burn amount
              
              
                gvladika 3b5eb00
              
                Deposits can be unpaused
              
              
                gvladika b7abeeb
              
                Make withdrawals unpausable
              
              
                gvladika d277437
              
                Update e2e
              
              
                gvladika e6ecd2d
              
                Slither exception
              
              
                gvladika 49d69c6
              
                Add transferUSDCRoles function
              
              
                gvladika 24b3da7
              
                Adapt e2e tests
              
              
                gvladika eca36f7
              
                Slither update
              
              
                gvladika 5211e5e
              
                Update natspec
              
              
                gvladika 684416f
              
                Slither update
              
              
                gvladika 25672c7
              
                Update natspec
              
              
                gvladika 43b48db
              
                Merge branch 'develop' into bridged-usdc-gw
              
              
                gvladika b877058
              
                ADjust fee amounts
              
              
                gvladika 08a65a7
              
                Use deafult nitro-testnode branch
              
              
                gvladika 965eb5f
              
                Add missing storage layout files
              
              
                gvladika d2c09d2
              
                Add missing sig files
              
              
                gvladika 8a9f1d6
              
                feat: usdc bridge deployment (#93)
              
              
                gvladika 6f0a61f
              
                Merge remote-tracking branch 'origin/develop' into bridged-usdc-gw
              
              
                gzeoneth 10bd936
              
                chore: bump version to 1.2.3
              
              
                gzeoneth 0b4efcf
              
                chore: slither
              
              
                gzeoneth File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            216 changes: 216 additions & 0 deletions
          
          216 
        
  contracts/tokenbridge/arbitrum/gateway/L2USDCGateway.sol
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.4; | ||
|  | ||
| import "./L2ArbitrumGateway.sol"; | ||
| import {IFiatToken, IFiatTokenProxy} from "../../ethereum/gateway/L1USDCGateway.sol"; | ||
| import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|  | ||
| /** | ||
| * @title Child chain custom gateway for USDC implementing Bridged USDC Standard. | ||
| * @notice Reference to the Circle's Bridged USDC Standard: | ||
| * https://github.com/circlefin/stablecoin-evm/blob/master/doc/bridged_USDC_standard.md | ||
| * | ||
| * @dev This contract can be used on new Orbit chains which want to provide USDC | ||
| * 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 child chain custom gateway is | ||
| * L1USDCGateway (when eth is used to pay fees) or L1OrbitUSDCGateway (when custom fee token is used). | ||
| * 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 paused by the owner | ||
| * - owner can set an "transferrer" account which will be able to transfer USDC ownership | ||
| * - transferrer can transfer USDC owner and proxyAdmin | ||
| * | ||
| * NOTE: before withdrawing funds, make sure that recipient address is not blacklisted on the parent chain. | ||
| * Also, make sure that USDC token itself is not paused. Otherwise funds might get stuck. | ||
| */ | ||
| contract L2USDCGateway is L2ArbitrumGateway { | ||
| using SafeERC20 for IERC20; | ||
| using Address for address; | ||
|  | ||
| address public l1USDC; | ||
| address public l2USDC; | ||
| address public owner; | ||
| address public usdcOwnershipTransferrer; | ||
| bool public withdrawalsPaused; | ||
|  | ||
| event WithdrawalsPaused(); | ||
| event WithdrawalsUnpaused(); | ||
| event OwnerSet(address indexed owner); | ||
| event USDCOwnershipTransferrerSet(address indexed usdcOwnershipTransferrer); | ||
| event USDCOwnershipTransferred(address indexed newOwner, address indexed newProxyAdmin); | ||
|  | ||
| error L2USDCGateway_WithdrawalsAlreadyPaused(); | ||
| error L2USDCGateway_WithdrawalsAlreadyUnpaused(); | ||
| error L2USDCGateway_WithdrawalsPaused(); | ||
| error L2USDCGateway_InvalidL1USDC(); | ||
| error L2USDCGateway_InvalidL2USDC(); | ||
| error L2USDCGateway_NotOwner(); | ||
| error L2USDCGateway_InvalidOwner(); | ||
| error L2USDCGateway_NotUSDCOwnershipTransferrer(); | ||
|  | ||
| modifier onlyOwner() { | ||
| if (msg.sender != owner) { | ||
| revert L2USDCGateway_NotOwner(); | ||
| } | ||
| _; | ||
| } | ||
|  | ||
| function initialize( | ||
| address _l1Counterpart, | ||
| address _router, | ||
| address _l1USDC, | ||
| address _l2USDC, | ||
| address _owner | ||
| ) public { | ||
| if (_l1USDC == address(0)) { | ||
| revert L2USDCGateway_InvalidL1USDC(); | ||
| } | ||
| if (_l2USDC == address(0)) { | ||
| revert L2USDCGateway_InvalidL2USDC(); | ||
| } | ||
| if (_owner == address(0)) { | ||
| revert L2USDCGateway_InvalidOwner(); | ||
| } | ||
| L2ArbitrumGateway._initialize(_l1Counterpart, _router); | ||
| l1USDC = _l1USDC; | ||
| l2USDC = _l2USDC; | ||
| owner = _owner; | ||
| } | ||
|  | ||
| /** | ||
| * @notice Pause all withdrawals. This can only be called by the owner. | ||
| */ | ||
| function pauseWithdrawals() external onlyOwner { | ||
| if (withdrawalsPaused) { | ||
| revert L2USDCGateway_WithdrawalsAlreadyPaused(); | ||
| } | ||
| withdrawalsPaused = true; | ||
| emit WithdrawalsPaused(); | ||
| } | ||
|  | ||
| /** | ||
| * @notice Unpause withdrawals. This can only be called by the owner. | ||
| */ | ||
| function unpauseWithdrawals() external onlyOwner { | ||
| if (!withdrawalsPaused) { | ||
| revert L2USDCGateway_WithdrawalsAlreadyUnpaused(); | ||
| } | ||
| withdrawalsPaused = false; | ||
| emit WithdrawalsUnpaused(); | ||
| } | ||
|  | ||
| /** | ||
| * @notice Sets a new owner. | ||
| */ | ||
| function setOwner(address newOwner) external onlyOwner { | ||
| if (newOwner == address(0)) { | ||
| revert L2USDCGateway_InvalidOwner(); | ||
| } | ||
| owner = newOwner; | ||
| emit OwnerSet(newOwner); | ||
| } | ||
|  | ||
| /** | ||
| * @notice Sets the account which is able to transfer USDC role away from the gateway to some other account. | ||
| */ | ||
| function setUsdcOwnershipTransferrer(address _usdcOwnershipTransferrer) external onlyOwner { | ||
| usdcOwnershipTransferrer = _usdcOwnershipTransferrer; | ||
| emit USDCOwnershipTransferrerSet(_usdcOwnershipTransferrer); | ||
| } | ||
|  | ||
| /** | ||
| * @notice In accordance with bridged USDC standard, the ownership of the USDC token contract is transferred | ||
| * to the new owner, and the proxy admin is transferred to the caller (usdcOwnershipTransferrer). | ||
| * @dev For transfer to be successful, this gateway should be both the owner and the proxy admin of L2 USDC token. | ||
| */ | ||
| function transferUSDCRoles(address _owner) external { | ||
| if (msg.sender != usdcOwnershipTransferrer) { | ||
| revert L2USDCGateway_NotUSDCOwnershipTransferrer(); | ||
| } | ||
|  | ||
| IFiatTokenProxy(l2USDC).changeAdmin(msg.sender); | ||
| IFiatToken(l2USDC).transferOwnership(_owner); | ||
|  | ||
| emit USDCOwnershipTransferred(_owner, msg.sender); | ||
| } | ||
|  | ||
| /** | ||
| * @notice Entrypoint for withdrawing USDC, can be used only if withdrawals are not paused. | ||
| */ | ||
| function outboundTransfer( | ||
| address _l1Token, | ||
| address _to, | ||
| uint256 _amount, | ||
| uint256, /* _maxGas */ | ||
| uint256, /* _gasPriceBid */ | ||
| bytes calldata _data | ||
| ) public payable override returns (bytes memory res) { | ||
| if (withdrawalsPaused) { | ||
| revert L2USDCGateway_WithdrawalsPaused(); | ||
| } | ||
| return super.outboundTransfer(_l1Token, _to, _amount, 0, 0, _data); | ||
| } | ||
|  | ||
| /** | ||
| * @notice Only parent chain - child chain USDC token pair is supported | ||
| */ | ||
| function calculateL2TokenAddress(address l1ERC20) public view override returns (address) { | ||
| if (l1ERC20 != l1USDC) { | ||
| // invalid L1 usdc address | ||
| return address(0); | ||
| } | ||
| return l2USDC; | ||
| } | ||
|  | ||
| function inboundEscrowTransfer(address _l2Address, address _dest, uint256 _amount) | ||
| internal | ||
| override | ||
| { | ||
| IFiatToken(_l2Address).mint(_dest, _amount); | ||
| } | ||
|  | ||
| function outboundEscrowTransfer(address _l2Token, address _from, uint256 _amount) | ||
| internal | ||
| override | ||
| returns (uint256) | ||
| { | ||
| // fetch the USDC tokens from the user and then burn them | ||
| IERC20(_l2Token).safeTransferFrom(_from, address(this), _amount); | ||
| IFiatToken(_l2Token).burn(_amount); | ||
|  | ||
| return _amount; | ||
| } | ||
|  | ||
| /** | ||
| * @notice Withdraw back the USDC if child chain side is not set up properly | ||
| */ | ||
| function handleNoContract( | ||
| address l1ERC20, | ||
| address, /* expectedL2Address */ | ||
| address _from, | ||
| address, /* _to */ | ||
| uint256 _amount, | ||
| bytes memory /* deployData */ | ||
| ) internal override returns (bool shouldHalt) { | ||
| // it is assumed that the custom token is deployed to child chain before deposits are made | ||
| triggerWithdrawal(l1ERC20, address(this), _from, _amount, ""); | ||
| return true; | ||
| } | ||
|  | ||
| /** | ||
| * @notice We need to override this function because base implementation assumes that L2 token implements | ||
| * `l1Address()` function from IArbToken interface. In the case of USDC gateway IArbToken logic is | ||
| * part of this contract, so we just check that addresses match the expected L1 and L2 USDC address. | ||
| */ | ||
| function _isValidTokenAddress(address _l1Address, address _expectedL2Address) | ||
|         
                  gvladika marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| internal | ||
| view | ||
| override | ||
| returns (bool) | ||
| { | ||
| return _l1Address == l1USDC && _expectedL2Address == l2USDC; | ||
| } | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.