Skip to content
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

chore: add replayed funds sent back to l1 event on l2 adapter receive… #134

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/contracts/L2OpUSDCBridgeAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ contract L2OpUSDCBridgeAdapter is IL2OpUSDCBridgeAdapter, OpUSDCBridgeAdapter {
ICrossDomainMessenger(MESSENGER).sendMessage(
LINKED_ADAPTER, abi.encodeCall(IOpUSDCBridgeAdapter.receiveMessage, (_spender, _spender, _amount)), _minGasLimit
);

emit ReplayedFundsSentBackToL1(_spender, _amount);
} else {
// Mint the tokens to the user
try IUSDC(USDC).mint(_user, _amount) {
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/IL2OpUSDCBridgeAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ interface IL2OpUSDCBridgeAdapter {
*/
event USDCFunctionSent(bytes4 _functionSignature);

/**
* @notice Emitted when a `receiveMessage` call message is replayed after the adapter was deprecated
* @param _spender The address that provided the tokens
* @param _amount The amount of USDC sent back to L1
*/
event ReplayedFundsSentBackToL1(address _spender, uint256 _amount);

/*///////////////////////////////////////////////////////////////
LOGIC
///////////////////////////////////////////////////////////////*/
Expand Down
12 changes: 7 additions & 5 deletions src/interfaces/IOpUSDCBridgeAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ interface IOpUSDCBridgeAdapter {
* @param _messenger The address of the messenger contract that was sent through
* @param _minGasLimit Minimum gas limit that the message can be executed with
*/
event MessageSent(address _user, address _to, uint256 _amount, address _messenger, uint32 _minGasLimit);
event MessageSent(
address indexed _user, address indexed _to, uint256 _amount, address indexed _messenger, uint32 _minGasLimit
);

/**
* @notice Emitted when a message as recieved
Expand All @@ -67,7 +69,7 @@ interface IOpUSDCBridgeAdapter {
* @param _amount The amount of tokens recieved
* @param _messenger The address of the messenger contract that was recieved through
*/
event MessageReceived(address _spender, address _user, uint256 _amount, address _messenger);
event MessageReceived(address indexed _spender, address indexed _user, uint256 _amount, address indexed _messenger);

/**
* @notice Emitted when messaging is resumed
Expand All @@ -91,21 +93,21 @@ interface IOpUSDCBridgeAdapter {
* @param _amount The amount of tokens that were added to the blacklisted funds
* @param _messenger The address of the messenger that the message failed for
*/
event MessageFailed(address _spender, address _user, uint256 _amount, address _messenger);
event MessageFailed(address indexed _spender, address indexed _user, uint256 _amount, address indexed _messenger);

/**
* @notice Emitted when the blacklisted funds are withdrawn
* @param _user The user that the funds were withdrawn for
* @param _amountWithdrawn The amount of tokens that were withdrawn
*/
event BlacklistedFundsWithdrawn(address _user, uint256 _amountWithdrawn);
event BlacklistedFundsWithdrawn(address indexed _user, uint256 _amountWithdrawn);

/**
* @notice Emitted when the blacklisted funds are sent back to L1
* @param _spender The address that provided the tokens
* @param _amountSent The amount of tokens that were withdrawn
*/
event BlacklistedFundsSentBackToL1(address _spender, uint256 _amountSent);
event BlacklistedFundsSentBackToL1(address indexed _spender, uint256 _amountSent);

/*///////////////////////////////////////////////////////////////
ERRORS
Expand Down
14 changes: 8 additions & 6 deletions test/unit/L1OpUSDCBridgeAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ abstract contract Base is Helpers {
event MigratingToNative(address _messenger, address _newOwner);
event BurnAmountSet(uint256 _burnAmount);
event MigrationComplete(uint256 _burnedAmount);
event MessageSent(address _user, address _to, uint256 _amount, address _messenger, uint32 _minGasLimit);
event MessageReceived(address _spender, address _user, uint256 _amount, address _messenger);
event MessageSent(
address indexed _user, address indexed _to, uint256 _amount, address indexed _messenger, uint32 _minGasLimit
);
event MessageReceived(address indexed _spender, address indexed _user, uint256 _amount, address indexed _messenger);

function setUp() public virtual {
(_signerAd, _signerPk) = makeAddrAndKey('signer');
Expand Down Expand Up @@ -1051,7 +1053,7 @@ contract L1OpUSDCBridgeAdapter_Unit_SendMessageWithSignature is Base {
}

contract L1OpUSDCBridgeAdapter_Unit_ReceiveMessage is Base {
event MessageFailed(address _spender, address _user, uint256 _amount, address _messenger);
event MessageFailed(address indexed _spender, address indexed _user, uint256 _amount, address indexed _messenger);

/**
* @notice Check that the function reverts if the sender is not the messenger
Expand Down Expand Up @@ -1166,7 +1168,7 @@ contract L1OpUSDCBridgeAdapter_Unit_ReceiveMessage is Base {
}

contract L1OpUSDCBridgeAdapter_Unit_ReceiveWithdrawBlacklistedFundsPostMigration is Base {
event BlacklistedFundsWithdrawn(address _user, uint256 _amountWithdrawn);
event BlacklistedFundsWithdrawn(address indexed _user, uint256 _amountWithdrawn);

/**
* @notice Check that the function reverts if the sender is not the messenger
Expand Down Expand Up @@ -1251,7 +1253,7 @@ contract L1OpUSDCBridgeAdapter_Unit_ReceiveWithdrawBlacklistedFundsPostMigration
}

contract L1OpUSDCBridgeAdapter_Unit_WithdrawBlacklistedFunds is Base {
event BlacklistedFundsWithdrawn(address _user, uint256 _amountWithdrawn);
event BlacklistedFundsWithdrawn(address indexed _user, uint256 _amountWithdrawn);

/**
* @notice Check that the function expects the correct calls
Expand Down Expand Up @@ -1287,7 +1289,7 @@ contract L1OpUSDCBridgeAdapter_Unit_WithdrawBlacklistedFunds is Base {
assertEq(adapter.blacklistedFundsDetails(_spender, _user), 0, 'User blacklisted funds should be updated');
}

function test_emitsEvent(uint256 _amount, address _user, address _spender) external {
function test_emitEvent(uint256 _amount, address _user, address _spender) external {
vm.assume(_amount > 0);
vm.assume(_user != address(0));
adapter.forTest_setUserBlacklistedFunds(_spender, _user, _amount);
Expand Down
31 changes: 26 additions & 5 deletions test/unit/L2OpUSDCBridgeAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ abstract contract Base is Helpers {
uint256 internal _signerPk;

event MigratingToNative(address _messenger, address _roleCaller);
event MessageSent(address _user, address _to, uint256 _amount, address _messenger, uint32 _minGasLimit);
event MessageReceived(address _spender, address _user, uint256 _amount, address _messenger);
event MessageSent(
address indexed _user, address indexed _to, uint256 _amount, address indexed _messenger, uint32 _minGasLimit
);
event MessageReceived(address indexed _spender, address indexed _user, uint256 _amount, address indexed _messenger);
event USDCFunctionSent(bytes4 _functionSignature);

function setUp() public virtual {
Expand Down Expand Up @@ -688,7 +690,9 @@ contract L2OpUSDCBridgeAdapter_Unit_SendMessageWithSignature is Base {
}

contract L2OpUSDCBridgeAdapter_Unit_ReceiveMessage is Base {
event MessageFailed(address _spender, address _user, uint256 _amount, address _messenger);
event ReplayedFundsSentBackToL1(address _spender, uint256 _amount);

event MessageFailed(address indexed _spender, address indexed _user, uint256 _amount, address indexed _messenger);

/**
* @notice Check that the function reverts if the sender is not the messenger
Expand Down Expand Up @@ -739,6 +743,23 @@ contract L2OpUSDCBridgeAdapter_Unit_ReceiveMessage is Base {
adapter.receiveMessage(_user, _user, _amount);
}

/**
* @notice Check that the function emits the event as expected
*/
function test_emitReplayedEvent(address _spender, uint256 _amount) external {
adapter.forTest_setMessengerStatus(IOpUSDCBridgeAdapter.Status.Deprecated);
// Mock calls
vm.mockCall(_messenger, abi.encodeWithSignature('xDomainMessageSender()'), abi.encode(_linkedAdapter));

// Expect event to be emitted
vm.expectEmit(true, true, true, true);
emit ReplayedFundsSentBackToL1(_spender, _amount);

// Execute
vm.prank(_messenger);
adapter.receiveMessage(_user, _spender, _amount);
}

/**
* @notice Check that the token minting works as expected
*/
Expand Down Expand Up @@ -811,8 +832,8 @@ contract L2OpUSDCBridgeAdapter_Unit_ReceiveMessage is Base {
}

contract L2OpUSDCBridgeAdapter_Unit_WithdrawBlacklistedFunds is Base {
event BlacklistedFundsWithdrawn(address _user, uint256 _amountWithdrawn);
event BlacklistedFundsSentBackToL1(address _spender, uint256 _amountSent);
event BlacklistedFundsWithdrawn(address indexed _user, uint256 _amountWithdrawn);
event BlacklistedFundsSentBackToL1(address indexed _spender, uint256 _amountSent);

/**
* @notice Check that the function expects the correct calls
Expand Down
Loading