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

feat(protocol): allow GuardianProver set TKO allowance for TaikoL1 #16831

Merged
merged 5 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import "../common/LibStrings.sol";
/// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent
/// contract list.
/// We can simplify the code since we no longer need to maintain upgradability with Hekla.
// solhint-disable contract-name-camelcase
abstract contract EssentialContract_ is EssentialContract {
// solhint-disable var-name-mixedcase
uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable;
}

Expand Down
21 changes: 21 additions & 0 deletions packages/protocol/contracts/L1/provers/GuardianProver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../common/LibStrings.sol";
import "../../verifiers/IVerifier.sol";
import "../tiers/ITierProvider.sol";
Expand All @@ -12,6 +13,7 @@
/// @custom:security-contact security@taiko.xyz
contract GuardianProver is IVerifier, Guardians {
error GV_PERMISSION_DENIED();
error GV_ZERO_ADDRESS();

uint256[50] private __gap;

Expand All @@ -36,6 +38,25 @@
__Essential_init(_owner, _addressManager);
}

/// @notice Enables unlimited allowance for Taiko L1 contract.
/// param _enable true if unlimited allowance is approved, false to set the allowance to 0.
function enableTaikoTokenAllowance(bool _enable) external onlyOwner {
address tko = resolve(LibStrings.B_TAIKO_TOKEN, false);
address taiko = resolve(LibStrings.B_TAIKO, false);
IERC20(tko).approve(taiko, _enable ? type(uint256).max : 0);
}
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

/// @dev Withdraws Taiko Token to a given address.
/// @param _to The recipient address.
/// @param _amount The amount of Taiko token to withdraw. Use 0 for all balance.
function withdrawTaikoToken(address _to, uint256 _amount) external onlyOwner {
if (_to == address(0)) revert GV_ZERO_ADDRESS();

IERC20 tko = IERC20(resolve(LibStrings.B_TAIKO_TOKEN, false));
uint256 amount = _amount == 0 ? tko.balanceOf(address(this)) : _amount;
tko.transfer(_to, amount);
}
Fixed Show fixed Hide fixed

/// @dev Called by guardians to approve a guardian proof
/// @param _meta The block's metadata.
/// @param _tran The valid transition.
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import "./BridgedERC20Base.sol";
/// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent
/// contract list.
/// We can simplify the code since we no longer need to maintain upgradability with Hekla.
// solhint-disable contract-name-camelcase
abstract contract BridgedERC20Base_ is BridgedERC20Base {
// solhint-disable var-name-mixedcase
uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/test/L1/TaikoL1TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ abstract contract TaikoL1TestBase is TaikoTest {
);

L1.init(address(0), address(addressManager), GENESIS_BLOCK_HASH);

gp.enableTaikoTokenAllowance(true);
printVariables("init ");
}

Expand Down
Loading