Skip to content

Commit

Permalink
Use FiatTokenV2_2
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Jun 19, 2024
1 parent 97c062e commit 9dab9f4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 33 deletions.
15 changes: 15 additions & 0 deletions contracts/tokenbridge/libraries/IFiatToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ pragma solidity >0.6.0 <0.9.0;
* This interface is used in the L1USDCGateway, L1OrbitUSDCGateway and L2USDCGateway contracts.
*/
interface IFiatToken {
function initialize(
string memory tokenName,
string memory tokenSymbol,
string memory tokenCurrency,
uint8 tokenDecimals,
address newMasterMinter,
address newPauser,
address newBlacklister,
address newOwner
) external;
function initializeV2(string calldata newName) external;
function initializeV2_1(address lostAndFound) external;
function initializeV2_2(address[] calldata accountsToBlacklist, string calldata newSymbol)
external;
function configureMinter(address minter, uint256 minterAllowedAmount) external;
function burn(uint256 _amount) external;
function mint(address _to, uint256 _amount) external;
}
63 changes: 33 additions & 30 deletions test-foundry/L2USDCGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,42 @@ import {L1USDCGateway} from "contracts/tokenbridge/ethereum/gateway/L1USDCGatewa
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {AddressAliasHelper} from "contracts/tokenbridge/libraries/AddressAliasHelper.sol";
import {L2GatewayToken} from "contracts/tokenbridge/libraries/L2GatewayToken.sol";
import {IFiatToken} from "contracts/tokenbridge/libraries/IFiatToken.sol";
import {TestUtil} from "./util/TestUtil.sol";

contract L2USDCGatewayTest is L2ArbitrumGatewayTest {
L2USDCGateway public l2USDCGateway;
address public l1USDC = makeAddr("l1USDC");
address public l2USDC;
address public user = makeAddr("usdc_user");
address public owner = makeAddr("l2gw-owner");
address masterMinter = makeAddr("masterMinter");

function setUp() public virtual {
l2USDCGateway = new L2USDCGateway();
l2Gateway = L2ArbitrumGateway(address(l2USDCGateway));

l2USDC = address(new MockFiatToken(address(l2USDCGateway)));
l2USDCGateway.initialize(l1Counterpart, router, l1USDC, l2USDC, owner);
address bridgedUsdcLogic = TestUtil.deployBridgedUsdcToken();
l2USDC = TestUtil.deployProxy(bridgedUsdcLogic);
IFiatToken(l2USDC).initialize(
"USDC token",
"USDC.e",
"USD",
uint8(6),
masterMinter,
makeAddr("newPauser"),
makeAddr("newBlacklister"),
owner
);
IFiatToken(l2USDC).initializeV2("USDC");
IFiatToken(l2USDC).initializeV2_1(makeAddr("lostAndFound"));
IFiatToken(l2USDC).initializeV2_2(new address[](0), "USDC.e");

vm.prank(masterMinter);
IFiatToken(l2USDC).configureMinter(address(l2USDCGateway), type(uint256).max);

vm.prank(owner);
l2USDCGateway.initialize(l1Counterpart, router, l1USDC, l2USDC, owner);
vm.etch(0x0000000000000000000000000000000000000064, address(arbSysMock).code);
}

Expand Down Expand Up @@ -127,7 +148,8 @@ contract L2USDCGatewayTest is L2ArbitrumGatewayTest {

function test_outboundTransfer() public override {
// mint token to user
deal(address(l2USDC), sender, 1 ether);
vm.prank(address(l2USDCGateway));
IFiatToken(l2USDC).mint(sender, 20 ether);

// withdrawal params
uint256 withdrawalAmount = 200_500;
Expand Down Expand Up @@ -155,7 +177,8 @@ contract L2USDCGatewayTest is L2ArbitrumGatewayTest {

function test_outboundTransfer_4Args() public override {
// mint token to user
deal(address(l2USDC), sender, 1 ether);
vm.prank(address(l2USDCGateway));
IFiatToken(l2USDC).mint(sender, 20 ether);

// withdrawal params
uint256 withdrawalAmount = 200_500;
Expand Down Expand Up @@ -199,13 +222,18 @@ contract L2USDCGatewayTest is L2ArbitrumGatewayTest {
function test_pauseWithdrawals() public {
assertEq(l2USDCGateway.withdrawalsPaused(), false, "Invalid withdrawalsPaused");

uint256 mockL2Supply = 5000 ether;
vm.mockCall(
address(l2USDC), abi.encodeWithSignature("totalSupply()"), abi.encode(mockL2Supply)
);

// events
vm.expectEmit(true, true, true, true);
emit TxToL1(
address(l2USDCGateway),
address(l1Counterpart),
0,
abi.encodeCall(L1USDCGateway.setL2GatewaySupply, (5000 ether))
abi.encodeCall(L1USDCGateway.setL2GatewaySupply, mockL2Supply)
);

vm.expectEmit(true, true, true, true);
Expand Down Expand Up @@ -259,28 +287,3 @@ contract L2USDCGatewayTest is L2ArbitrumGatewayTest {
event WithdrawalsPaused();
event WithdrawalsUnpaused();
}

contract MockFiatToken is ERC20 {
address public minter;

constructor(address _minter) ERC20("Bridged USDC", "USDC.e") {
minter = _minter;
}

modifier onlyMinter() {
require(msg.sender == minter, "only minter");
_;
}

function totalSupply() public view override returns (uint256) {
return 5000 ether;
}

function mint(address account, uint256 amount) public onlyMinter {
_mint(account, amount);
}

function burn(uint256 amount) public onlyMinter {
_burn(msg.sender, amount);
}
}
Loading

0 comments on commit 9dab9f4

Please sign in to comment.