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

add allowSgtValue/disallowSgtValue to SGT contract #89

Open
wants to merge 1 commit into
base: op-es
Choose a base branch
from
Open
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
25 changes: 24 additions & 1 deletion packages/contracts-bedrock/src/L2/SoulGasToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import { Constants } from "src/libraries/Constants.sol";
contract SoulGasToken is ERC20Upgradeable, OwnableUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.SoulGasToken
struct SoulGasTokenStorage {
// _minters are be whitelist EOAs, only used when !IS_BACKED_BY_NATIVE
// _minters are whitelist EOAs, only used when !IS_BACKED_BY_NATIVE
mapping(address => bool) _minters;
// _burners are whitelist EOAs to burn/withdraw SoulGasToken
mapping(address => bool) _burners;
// _allow_sgt_value are whitelist contracts to consume sgt as msg.value
// when IS_BACKED_BY_NATIVE
mapping(address => bool) _allow_sgt_value;
}

// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.SoulGasToken")) - 1)) & ~bytes32(uint256(0xff))
Expand Down Expand Up @@ -151,6 +154,26 @@ contract SoulGasToken is ERC20Upgradeable, OwnableUpgradeable {
}
}

/// @notice allowSgtValue is called by the owner to enable whitelist contracts to consume sgt as msg.value
function allowSgtValue(address[] calldata contracts) external onlyOwner {
require(IS_BACKED_BY_NATIVE, "allowSgtValue should only be called when IS_BACKED_BY_NATIVE");
SoulGasTokenStorage storage $ = _getSoulGasTokenStorage();
uint256 i;
for (i = 0; i < contracts.length; i++) {
$._allow_sgt_value[contracts[i]] = true;
}
}

/// @notice allowSgtValue is called by the owner to disable whitelist contracts to consume sgt as msg.value
function disallowSgtValue(address[] calldata contracts) external onlyOwner {
require(IS_BACKED_BY_NATIVE, "disallowSgtValue should only be called when IS_BACKED_BY_NATIVE");
SoulGasTokenStorage storage $ = _getSoulGasTokenStorage();
uint256 i;
for (i = 0; i < contracts.length; i++) {
$._allow_sgt_value[contracts[i]] = false;
}
}

/// @notice burnFrom is called when !IS_BACKED_BY_NATIVE:
/// 1. by the burner to burn SoulGasToken.
/// 2. by DEPOSITOR_ACCOUNT to burn SoulGasToken.
Expand Down