Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed May 9, 2024
1 parent 0d7a806 commit a0d4b61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
30 changes: 12 additions & 18 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ contract BridgedERC20 is EssentialContract, IBridgedERC20, ERC20Upgradeable {
error BTOKEN_INVALID_PARAMS();
error BTOKEN_INVALID_TO_ADDR();
error BTOKEN_MINT_DISALLOWED();
error BTOKEN_BURN_DISALLOWED();

/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
Expand Down Expand Up @@ -115,29 +116,25 @@ contract BridgedERC20 is EssentialContract, IBridgedERC20, ERC20Upgradeable {
emit MigratedFrom(_migratingAddress, _account, _amount);
} else {
// Bridging from vault
_authorizedMintBurn(msg.sender);
_authorizedMint(msg.sender);
}

_mint(_account, _amount);
}

/// @notice Burns tokens in case of 'migrating out' from msg.sender (EOA) or from the ERC20Vault
/// if bridging back to canonical token.
/// @notice Burns tokens in case of 'migrating out' from msg.sender.
/// @param _amount The amount of tokens to burn.
function burn(uint256 _amount) external whenNotPaused nonReentrant {
if (isMigratingOut()) {
// Outbound migration
address _migratingAddress = migratingAddress;
emit MigratedTo(_migratingAddress, msg.sender, _amount);
// Ask the new bridged token to mint token for the user.
IBridgedERC20(_migratingAddress).mint(msg.sender, _amount);
} else {
// When user wants to burn tokens only during 'migrating out' phase is possible. If
// ERC20Vault burns the tokens, that will go through the burn(amount) function.
_authorizedMintBurn(msg.sender);
}
if (!isMigratingOut()) revert BTOKEN_BURN_DISALLOWED();

// Outbound migration
address _migratingAddress = migratingAddress;

_burn(msg.sender, _amount);

emit MigratedTo(_migratingAddress, msg.sender, _amount);
// Ask the new bridged token to mint token for the user.
IBridgedERC20(_migratingAddress).mint(msg.sender, _amount);
}

/// @dev Transfers tokens then burn.
Expand Down Expand Up @@ -192,8 +189,5 @@ contract BridgedERC20 is EssentialContract, IBridgedERC20, ERC20Upgradeable {
return super._beforeTokenTransfer(_from, _to, _amount);
}

function _authorizedMintBurn(address addr)
private
onlyFromOwnerOrNamed(LibStrings.B_ERC20_VAULT)
{ }
function _authorizedMint(address addr) private onlyFromOwnerOrNamed(LibStrings.B_ERC20_VAULT) { }
}
11 changes: 0 additions & 11 deletions packages/protocol/test/tokenvault/BridgedERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ contract TestBridgedERC20 is TaikoTest {
newToken.mint(Bob, 15);
assertEq(newToken.balanceOf(Bob), 235);

// Vault can only burn if it owns the tokens
vm.prank(vault);
vm.expectRevert();
newToken.burn(25);
assertEq(newToken.balanceOf(Bob), 235);

// Imitate current bridge-back operation, as Bob gave approval (for bridging back) and then
// ERC20Vault does the "transfer and burn"
vm.prank(Bob);
Expand All @@ -113,11 +107,6 @@ contract TestBridgedERC20 is TaikoTest {
// Following the "transfer and burn" pattern
vm.prank(vault);
newToken.transferFrom(Bob, vault, 25);

vm.prank(vault);
newToken.burn(25);

assertEq(newToken.balanceOf(Bob), 210);
}

function deployBridgedToken(string memory name) internal returns (BridgedERC20) {
Expand Down

0 comments on commit a0d4b61

Please sign in to comment.