Skip to content

Commit

Permalink
fix(AssetMigration): remove initializable extension
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Dec 5, 2024
1 parent 5720064 commit 596c83d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 41 deletions.
6 changes: 3 additions & 3 deletions logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
| LibTokenOwner | 164 | 214 | 24,412 | 48,938 |
| MainchainBridgeManager | 20,517 | 20,742 | 4,059 | 28,410 |
| MainchainGatewayBatcher | 4,051 | 4,276 | 20,525 | 44,876 |
| MainchainGatewayV3 | 24,259 | 24,496 | 317 | 24,656 |
| MainchainGatewayV3 | 24,256 | 24,493 | 320 | 24,659 |
| Math | 85 | 135 | 24,491 | 49,017 |
| MockBridge | 1,254 | 1,282 | 23,322 | 47,870 |
| MockBridgeManager | 2,614 | 2,642 | 21,962 | 46,510 |
Expand All @@ -57,7 +57,7 @@
| MockERC721 | 4,663 | 5,355 | 19,913 | 43,797 |
| MockGatewayForTracking | 1,583 | 1,885 | 22,993 | 47,267 |
| MockRoninBridgeManager | 24,326 | 24,551 | 250 | 24,601 |
| MockRoninGatewayV3Extended | 23,847 | 24,084 | 729 | 25,068 |
| MockRoninGatewayV3Extended | 23,844 | 24,081 | 732 | 25,071 |
| MockSLP | 2,403 | 2,877 | 22,173 | 46,275 |
| MockTUint256Slot | 2,619 | 2,647 | 21,957 | 46,505 |
| MockUSDC | 2,404 | 2,869 | 22,172 | 46,283 |
Expand All @@ -69,7 +69,7 @@
| Proposal | 85 | 135 | 24,491 | 49,017 |
| RoninBridgeManager | 24,326 | 24,551 | 250 | 24,601 |
| RoninBridgeManagerConstructor | 14,743 | 14,968 | 9,833 | 34,184 |
| RoninGatewayV3 | 23,596 | 23,833 | 980 | 25,319 |
| RoninGatewayV3 | 23,593 | 23,830 | 983 | 25,322 |
| RoninMockERC1155 | 8,696 | 9,657 | 15,880 | 39,495 |
| SafeERC20 | 85 | 135 | 24,491 | 49,017 |
| StdStyle | 85 | 135 | 24,491 | 49,017 |
Expand Down
18 changes: 1 addition & 17 deletions src/extensions/AssetMigrationUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import { IWETH } from "src/interfaces/IWETH.sol";
import { ErrLengthMismatch, ErrEmptyArray } from "src/utils/CommonErrors.sol";

abstract contract AssetMigrationUpgradeable is Initializable {
abstract contract AssetMigrationUpgradeable {
using SafeERC20 for IERC20;

/// @dev Error when the storage location is null
Expand Down Expand Up @@ -52,21 +51,6 @@ abstract contract AssetMigrationUpgradeable is Initializable {
return _getAssetMigration()._wnt;
}

/**
* @dev Initializes the neccessary data.
*/
function __AssetMigration_init(address wnt, address migrator) internal onlyInitializing {
__AssetMigration_init_unchained(wnt, migrator);
}

/**
* @dev Initializes the neccessary data.
*/
function __AssetMigration_init_unchained(address wnt, address migrator) internal onlyInitializing {
_setMigrator(migrator);
_setWrappedNativeToken(wnt);
}

/**
* @dev Migrates the given tokens to the specified addresses.
*
Expand Down
46 changes: 34 additions & 12 deletions src/mainchain/MainchainGatewayV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ contract MainchainGatewayV3 is
}
}

function initializeV2(address bridgeManagerContract) external reinitializer(2) {
function initializeV2(
address bridgeManagerContract
) external reinitializer(2) {
_setContract(ContractType.BRIDGE_MANAGER, bridgeManagerContract);
}

Expand All @@ -130,15 +132,21 @@ contract MainchainGatewayV3 is
_totalOperatorWeight = totalWeight;
}

function initializeV4(address payable /* wethUnwrapper_ */) external reinitializer(4) {
/** @deprecated
function initializeV4(
address payable /* wethUnwrapper_ */
) external reinitializer(4) {
/**
* @deprecated
*
* wethUnwrapper = WethUnwrapper(wethUnwrapper_);
*/
}

function initializeV5(address migrator) external reinitializer(5) {
__AssetMigration_init_unchained(address(wrappedNativeToken), migrator);
function initializeV5(
address migrator
) external reinitializer(5) {
_setWrappedNativeToken(address(wrappedNativeToken));
_setMigrator(migrator);
}

/**
Expand All @@ -156,14 +164,18 @@ contract MainchainGatewayV3 is
/**
* @inheritdoc IMainchainGatewayV3
*/
function setWrappedNativeTokenContract(IWETH _wrappedToken) external virtual onlyProxyAdmin {
function setWrappedNativeTokenContract(
IWETH _wrappedToken
) external virtual onlyProxyAdmin {
_setWrappedNativeTokenContract(_wrappedToken);
}

/**
* @inheritdoc IMainchainGatewayV3
*/
function requestDepositFor(Transfer.Request calldata _request) external payable virtual whenNotPaused {
function requestDepositFor(
Transfer.Request calldata _request
) external payable virtual whenNotPaused {
_requestDepositFor(_request, msg.sender);
}

Expand All @@ -177,7 +189,9 @@ contract MainchainGatewayV3 is
/**
* @inheritdoc IMainchainGatewayV3
*/
function unlockWithdrawal(Transfer.Receipt calldata receipt) external onlyRole(WITHDRAWAL_UNLOCKER_ROLE) {
function unlockWithdrawal(
Transfer.Receipt calldata receipt
) external onlyRole(WITHDRAWAL_UNLOCKER_ROLE) {
bytes32 _receiptHash = receipt.hash();
if (withdrawalHash[receipt.id] != receipt.hash()) {
revert ErrInvalidReceipt();
Expand Down Expand Up @@ -236,7 +250,9 @@ contract MainchainGatewayV3 is
/**
* @inheritdoc IMainchainGatewayV3
*/
function getRoninToken(address mainchainToken) public view returns (MappedToken memory token) {
function getRoninToken(
address mainchainToken
) public view returns (MappedToken memory token) {
token = _roninToken[mainchainToken];
if (token.tokenAddr == address(0)) revert ErrUnsupportedToken();
}
Expand Down Expand Up @@ -441,7 +457,9 @@ contract MainchainGatewayV3 is
* Emits the `WrappedNativeTokenContractUpdated` event.
*
*/
function _setWrappedNativeTokenContract(IWETH _wrappedToken) internal {
function _setWrappedNativeTokenContract(
IWETH _wrappedToken
) internal {
wrappedNativeToken = _wrappedToken;
emit WrappedNativeTokenContractUpdated(_wrappedToken);
}
Expand Down Expand Up @@ -478,7 +496,9 @@ contract MainchainGatewayV3 is
/**
* @dev Returns the weight of an address.
*/
function _getWeight(address addr) internal view returns (uint256) {
function _getWeight(
address addr
) internal view returns (uint256) {
return _operatorWeight[addr];
}

Expand Down Expand Up @@ -537,7 +557,9 @@ contract MainchainGatewayV3 is
return IBridgeManagerCallback.onBridgeOperatorsRemoved.selector;
}

function supportsInterface(bytes4 interfaceId) public view override(AccessControlEnumerable, IERC165, ERC1155Receiver) returns (bool) {
function supportsInterface(
bytes4 interfaceId
) public view override(AccessControlEnumerable, IERC165, ERC1155Receiver) returns (bool) {
return
interfaceId == type(IMainchainGatewayV3).interfaceId || interfaceId == type(IBridgeManagerCallback).interfaceId || super.supportsInterface(interfaceId);
}
Expand Down
35 changes: 26 additions & 9 deletions src/ronin/gateway/RoninGatewayV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ contract RoninGatewayV3 is
delete ____deprecated2;
}

function initializeV3(address bridgeAdmin) external reinitializer(3) {
function initializeV3(
address bridgeAdmin
) external reinitializer(3) {
_setContract(ContractType.BRIDGE_MANAGER, bridgeAdmin);
}

function initializeV4(address wnt, address migrator) external reinitializer(4) {
__AssetMigration_init(wnt, migrator);
_setWrappedNativeToken(wnt);
_setMigrator(migrator);
}

/**
Expand All @@ -149,14 +152,18 @@ contract RoninGatewayV3 is
/**
* @inheritdoc IRoninGatewayV3
*/
function depositFor(Transfer.Receipt calldata _receipt) external whenNotPaused onlyBridgeOperator {
function depositFor(
Transfer.Receipt calldata _receipt
) external whenNotPaused onlyBridgeOperator {
_depositFor(_receipt, msg.sender, minimumVoteWeight());
}

/**
* @inheritdoc IRoninGatewayV3
*/
function tryBulkAcknowledgeMainchainWithdrew(uint256[] calldata _withdrawalIds) external onlyBridgeOperator returns (bool[] memory _executedReceipts) {
function tryBulkAcknowledgeMainchainWithdrew(
uint256[] calldata _withdrawalIds
) external onlyBridgeOperator returns (bool[] memory _executedReceipts) {
address governor = msg.sender;
uint256 minVoteWeight = minimumVoteWeight();

Expand Down Expand Up @@ -191,7 +198,9 @@ contract RoninGatewayV3 is
/**
* @inheritdoc IRoninGatewayV3
*/
function tryBulkDepositFor(Transfer.Receipt[] calldata receipts) external whenNotPaused onlyBridgeOperator returns (bool[] memory _executedReceipts) {
function tryBulkDepositFor(
Transfer.Receipt[] calldata receipts
) external whenNotPaused onlyBridgeOperator returns (bool[] memory _executedReceipts) {
uint length = receipts.length;
_executedReceipts = new bool[](length);
uint256 minVoteWeight = minimumVoteWeight();
Expand Down Expand Up @@ -230,7 +239,9 @@ contract RoninGatewayV3 is
/**
* @inheritdoc IRoninGatewayV3
*/
function requestWithdrawalSignatures(uint256 _withdrawalId) external whenNotPaused {
function requestWithdrawalSignatures(
uint256 _withdrawalId
) external whenNotPaused {
if (mainchainWithdrew(_withdrawalId)) revert ErrWithdrawnOnMainchainAlready();

Transfer.Receipt memory _receipt = withdrawal[_withdrawalId];
Expand Down Expand Up @@ -328,7 +339,9 @@ contract RoninGatewayV3 is
/**
* @inheritdoc IRoninGatewayV3
*/
function mainchainWithdrew(uint256 _withdrawalId) public view returns (bool) {
function mainchainWithdrew(
uint256 _withdrawalId
) public view returns (bool) {
return mainchainWithdrewVote[_withdrawalId].status == VoteStatus.Executed;
}

Expand Down Expand Up @@ -546,11 +559,15 @@ contract RoninGatewayV3 is
/**
* @dev Returns minimum trusted vote weight.
*/
function _minimumTrustedVoteWeight(uint256 _totalTrustedWeight) internal view virtual returns (uint256) {
function _minimumTrustedVoteWeight(
uint256 _totalTrustedWeight
) internal view virtual returns (uint256) {
return (_trustedNum * _totalTrustedWeight + _trustedDenom - 1) / _trustedDenom;
}

function supportsInterface(bytes4 interfaceId) public view override(AccessControlEnumerable, ERC1155Receiver) returns (bool) {
function supportsInterface(
bytes4 interfaceId
) public view override(AccessControlEnumerable, ERC1155Receiver) returns (bool) {
return AccessControlEnumerable.supportsInterface(interfaceId) || ERC1155Receiver.supportsInterface(interfaceId);
}
}

0 comments on commit 596c83d

Please sign in to comment.