Skip to content

Commit

Permalink
Do not allow gasTokens to be managed by hard asset manager (#153)
Browse files Browse the repository at this point in the history
closes #144
(wrapped tokens from L2 need to be send burn and send to the children bridges by their users).
(gasToken can be burned all at once with the current implementation and send to one child in one transaction + to the other child in a second transaction).
(L1 tokens - hard assets - will be send to the child contract via the call from the hardasset manager.)
  • Loading branch information
josojo authored Jan 4, 2024
1 parent d6275f5 commit 88d7746
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion contracts/ForkableBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ contract ForkableBridge is
if (to != children[0] && to != children[1]) {
revert InvalidDestinationForHardAsset();
}
if (token == gasTokenAddress) {
revert GasTokenIsNotHardAsset();
}
IERC20(token).transfer(to, amount);
}

Expand Down Expand Up @@ -178,8 +181,12 @@ contract ForkableBridge is
* @dev Allows aynone to take out their forkonomic tokens
* and send them to the children-bridge contracts
* Notice that forkonomic tokens are special, as they their main contract
* is on L1, but they are still forkable tokens as all the tokens from
* is on L1, but they are still forkable tokens, as their contract is forked as well.
* We allow to send tokens only to one child, just in case the one child contract
* was updated shortly after the fork and contains an error (e.g. reverts on sending)
* @param amount Amount of tokens to be sent to the children-bridge contracts
* @param useFirstChild boolean indicating for which child the operation should be run
* @param useChildTokenAllowance boolean indicating if the child token allowance (previously burned tokens) should be used
*/
function sendForkonomicTokensToChild(
uint256 amount,
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IForkableBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface IForkableBridge is IForkableStructure, IPolygonZkEVMBridge {
error NotAuthorized();
/// @dev Error thrown when trying to send bridged tokens to a child contract
error InvalidDestinationForHardAsset();
/// @dev Error thrown when hardasset manager tries to send gas token to a child contract
error GasTokenIsNotHardAsset();

/**
* @dev Function to initialize the contract
Expand Down
7 changes: 7 additions & 0 deletions test/ForkableBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,13 @@ contract ForkableBridgeTest is Test {
to
);

vm.expectRevert(IForkableBridge.GasTokenIsNotHardAsset.selector);
vm.prank(hardAssetManger);
forkableBridge.transferHardAssetsToChild(
address(gasTokenAddress),
amount,
child2
);
vm.expectRevert(
IForkableBridge.InvalidDestinationForHardAsset.selector
);
Expand Down

0 comments on commit 88d7746

Please sign in to comment.