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 UpgradeSoulGasToken.s.sol #172

Merged
merged 4 commits into from
Jan 23, 2025
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
3 changes: 3 additions & 0 deletions packages/contracts-bedrock/interfaces/L2/ISoulGasToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ interface ISoulGasToken {
function initialize(string memory _name, string memory _symbol, address _owner) external;

function __constructor__() external;

function name() external view returns (string memory);
function symbol() external view returns (string memory);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IStorageSetter {
function setBytes32(bytes32, bytes32) external;

function __constructor__() external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var excludeContracts = []string{

"IInitializable", "IOptimismMintableERC20", "ILegacyMintableERC20",
"KontrolCheatsBase", "ISystemConfigInterop", "IResolvedDelegateProxy",
"IERC20Upgradeable", "ISoulGasToken",
"IERC20Upgradeable", "ISoulGasToken", "IStorageSetter",
}

type ContractDefinition struct {
Expand Down
108 changes: 108 additions & 0 deletions packages/contracts-bedrock/scripts/deploy/UpgradeSoulGasToken.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

// Forge
import {Script} from "forge-std/Script.sol";

// Scripts
import {DeployUtils} from "scripts/libraries/DeployUtils.sol";

// Contracts
import {StorageSetter} from "src/universal/StorageSetter.sol";

// Interfaces
import {IProxyAdmin} from "interfaces/universal/IProxyAdmin.sol";
import {IStorageSetter} from "interfaces/universal/IStorageSetter.sol";
import {IProxy} from "interfaces/universal/IProxy.sol";
import {ISoulGasToken} from "interfaces/L2/ISoulGasToken.sol";

/// @title UpgradeSoulGasToken
contract UpgradeSoulGasToken is Script {
function run(address _storageSetter) public {
vm.startBroadcast();
upgradeSoulGasTokenImpl(_storageSetter);
vm.stopBroadcast();
checkOutput();
}

function upgradeSoulGasTokenImpl(address _storageSetter) internal {
if (_storageSetter == address(0)) {
_storageSetter = DeployUtils.create1({
_name: "StorageSetter",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(IStorageSetter.__constructor__, ())
)
});
}

IProxyAdmin proxyAdmin = IProxyAdmin(
0x4200000000000000000000000000000000000018
);
address payable soulGasToken = payable(
0x4200000000000000000000000000000000000800
);

address impl = IProxy(soulGasToken).implementation();

bytes memory data;
data = encodeStorageSetterZeroOutInitializedSlot();
upgradeAndCall(proxyAdmin, soulGasToken, _storageSetter, data);
data = encodeSoulGasTokenInitializer();
upgradeAndCall(proxyAdmin, soulGasToken, impl, data);
}

function encodeStorageSetterZeroOutInitializedSlot()
internal
pure
returns (bytes memory)
{
return abi.encodeCall(IStorageSetter.setBytes32, (0, 0));
}

function encodeSoulGasTokenInitializer()
internal
view
virtual
returns (bytes memory)
{
return
abi.encodeCall(
ISoulGasToken.initialize,
("SoulQKC", "SoulQKC", tx.origin)
);
}

/// @notice Makes an external call to the target to initialize the proxy with the specified data.
/// First performs safety checks to ensure the target, implementation, and proxy admin are valid.
function upgradeAndCall(
IProxyAdmin _proxyAdmin,
address _target,
address _implementation,
bytes memory _data
) internal {
DeployUtils.assertValidContractAddress(address(_proxyAdmin));
DeployUtils.assertValidContractAddress(_target);
DeployUtils.assertValidContractAddress(_implementation);

_proxyAdmin.upgradeAndCall(
payable(address(_target)),
_implementation,
_data
);
}

function checkOutput() public view {
ISoulGasToken soulGasToken = ISoulGasToken(
0x4200000000000000000000000000000000000800
);

require(
keccak256(abi.encodePacked(soulGasToken.name())) ==
keccak256("SoulQKC")
);
require(
keccak256(abi.encodePacked(soulGasToken.symbol())) ==
keccak256("SoulQKC")
);
}
}