Skip to content

Commit 8d1d13f

Browse files
committed
updated from extension to module
1 parent 177b3b3 commit 8d1d13f

File tree

1 file changed

+28
-48
lines changed

1 file changed

+28
-48
lines changed
Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.20;
33

4-
import {ModularExtension} from "../../../ModularExtension.sol";
4+
import {ModularModule} from "../../../ModularModule.sol";
55
import {Role} from "../../../Role.sol";
66
import {BeforeTransferCallbackERC721} from "../../../callback/BeforeTransferCallbackERC721.sol";
77
import {IBridgeAndCall} from "@lxly-bridge-and-call/IBridgeAndCall.sol";
88

99
library BridgeAndCallStorage {
10+
1011
/// @custom:storage-location erc7201:token.bridgeAndCall
1112
bytes32 public constant BRIDGE_AND_CALL_STORAGE_POSITION =
12-
keccak256(abi.encode(uint256(keccak256("token.bridgeAndCall")) - 1)) &
13-
~bytes32(uint256(0xff));
13+
keccak256(abi.encode(uint256(keccak256("token.bridgeAndCall")) - 1)) & ~bytes32(uint256(0xff));
1414

1515
struct Data {
16-
address bridgeExtension;
16+
address bridgeModule;
1717
}
1818

1919
function data() internal pure returns (Data storage data_) {
@@ -22,69 +22,58 @@ library BridgeAndCallStorage {
2222
data_.slot := position
2323
}
2424
}
25+
2526
}
2627

27-
contract BridgeAndCallERC721 is ModularExtension, BeforeTransferCallbackERC721 {
28+
contract BridgeAndCallERC721 is ModularModule, BeforeTransferCallbackERC721 {
29+
2830
/*//////////////////////////////////////////////////////////////
2931
ERRORS
3032
//////////////////////////////////////////////////////////////*/
3133

3234
/// @notice Emitted on attempt to transfer a token when the bridge extension is not set.
33-
error bridgeExtensionNotSet();
35+
error bridgeModuleNotSet();
3436

3537
/*//////////////////////////////////////////////////////////////
3638
EXTENSION CONFIG
3739
//////////////////////////////////////////////////////////////*/
3840

3941
/// @notice Returns all implemented callback and extension functions.
40-
function getExtensionConfig()
41-
external
42-
pure
43-
override
44-
returns (ExtensionConfig memory config)
45-
{
42+
function getModuleConfig() external pure override returns (ModuleConfig memory config) {
4643
config.fallbackFunctions = new FallbackFunction[](4);
4744

48-
config.fallbackFunctions[0] = FallbackFunction({
49-
selector: this.getBridgeExtension.selector,
50-
permissionBits: 0
51-
});
52-
config.fallbackFunctions[1] = FallbackFunction({
53-
selector: this.setBridgeExtension.selector,
54-
permissionBits: Role._MANAGER_ROLE
55-
});
56-
config.fallbackFunctions[2] = FallbackFunction({
57-
selector: this.bridgeAndCall.selector,
58-
permissionBits: 0
59-
});
45+
config.fallbackFunctions[0] = FallbackFunction({selector: this.getBridgeModule.selector, permissionBits: 0});
46+
config.fallbackFunctions[1] =
47+
FallbackFunction({selector: this.setBridgeModule.selector, permissionBits: Role._MANAGER_ROLE});
48+
config.fallbackFunctions[2] = FallbackFunction({selector: this.bridgeAndCall.selector, permissionBits: 0});
6049

6150
config.requiredInterfaces = new bytes4[](1);
6251
config.requiredInterfaces[0] = 0x80ac58cd; // ERC721.
6352

6453
config.registerInstallationCallback = true;
6554
}
6655

67-
/// @dev Called by a Core into an Extension during the installation of the Extension.
56+
/// @dev Called by a Core into an Module during the installation of the Module.
6857
function onInstall(bytes calldata data) external {
69-
address bridgeExtension = abi.decode(data, (address));
70-
_bridgeAndCallStorage().bridgeExtension = bridgeExtension;
58+
address bridgeModule = abi.decode(data, (address));
59+
_bridgeAndCallStorage().bridgeModule = bridgeModule;
7160
}
7261

73-
/// @dev Called by a Core into an Extension during the uninstallation of the Extension.
62+
/// @dev Called by a Core into an Module during the uninstallation of the Module.
7463
function onUninstall(bytes calldata data) external {}
7564

7665
/*//////////////////////////////////////////////////////////////
7766
FALLBACK FUNCTIONS
7867
//////////////////////////////////////////////////////////////*/
7968

8069
/// @notice Returns whether transfers is enabled for the token.
81-
function getBridgeExtension() external view returns (address) {
82-
return _bridgeAndCallStorage().bridgeExtension;
70+
function getBridgeModule() external view returns (address) {
71+
return _bridgeAndCallStorage().bridgeModule;
8372
}
8473

8574
/// @notice Set transferability for a token.
86-
function setBridgeExtension(address enableTransfer) external {
87-
_bridgeAndCallStorage().bridgeExtension = enableTransfer;
75+
function setBridgeModule(address enableTransfer) external {
76+
_bridgeAndCallStorage().bridgeModule = enableTransfer;
8877
}
8978

9079
/// @notice Set transferability for a token.
@@ -96,31 +85,22 @@ contract BridgeAndCallERC721 is ModularExtension, BeforeTransferCallbackERC721 {
9685
bytes calldata callData,
9786
bool forceUpdateGlobalExitRoot
9887
) external {
99-
address bridgeExtension = _bridgeAndCallStorage().bridgeExtension;
100-
if (bridgeExtension == address(0)) {
101-
revert bridgeExtensionNotSet();
88+
address bridgeModule = _bridgeAndCallStorage().bridgeModule;
89+
if (bridgeModule == address(0)) {
90+
revert bridgeModuleNotSet();
10291
}
10392

104-
IBridgeAndCall(bridgeExtension).bridgeAndCall(
105-
address(this),
106-
amount,
107-
destinationNetwork,
108-
callAddress,
109-
fallbackAddress,
110-
callData,
111-
forceUpdateGlobalExitRoot
93+
IBridgeAndCall(bridgeModule).bridgeAndCall(
94+
address(this), amount, destinationNetwork, callAddress, fallbackAddress, callData, forceUpdateGlobalExitRoot
11295
);
11396
}
11497

11598
/*//////////////////////////////////////////////////////////////
11699
INTERNAL FUNCTIONS
117100
//////////////////////////////////////////////////////////////*/
118101

119-
function _bridgeAndCallStorage()
120-
internal
121-
pure
122-
returns (BridgeAndCallStorage.Data storage)
123-
{
102+
function _bridgeAndCallStorage() internal pure returns (BridgeAndCallStorage.Data storage) {
124103
return BridgeAndCallStorage.data();
125104
}
105+
126106
}

0 commit comments

Comments
 (0)