Skip to content

Commit d02912e

Browse files
committed
updated to align with CrossChain contract
1 parent 300ccae commit d02912e

File tree

1 file changed

+53
-39
lines changed

1 file changed

+53
-39
lines changed

src/module/token/crosschain/PolygonAgglayer.sol

+53-39
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.20;
33

4-
import {ModularModule} from "../../../ModularModule.sol";
4+
import {Module} from "../../../Module.sol";
55
import {Role} from "../../../Role.sol";
6-
import {BeforeTransferCallbackERC721} from "../../../callback/BeforeTransferCallbackERC721.sol";
6+
7+
import {CrossChain} from "./CrossChain.sol";
78
import {IBridgeAndCall} from "@lxly-bridge-and-call/IBridgeAndCall.sol";
89

910
library PolygonAgglayerCrossChainStorage {
@@ -13,7 +14,7 @@ library PolygonAgglayerCrossChainStorage {
1314
keccak256(abi.encode(uint256(keccak256("token.bridgeAndCall")) - 1)) & ~bytes32(uint256(0xff));
1415

1516
struct Data {
16-
address bridgeModule;
17+
address router;
1718
}
1819

1920
function data() internal pure returns (Data storage data_) {
@@ -25,88 +26,101 @@ library PolygonAgglayerCrossChainStorage {
2526

2627
}
2728

28-
contract PolygonAgglayerCrossChainERC721 is ModularModule, BeforeTransferCallbackERC721 {
29-
30-
/*//////////////////////////////////////////////////////////////
31-
ERRORS
32-
//////////////////////////////////////////////////////////////*/
33-
34-
/// @notice Emitted on attempt to transfer a token when the bridge extension is not set.
35-
error bridgeModuleNotSet();
29+
contract PolygonAgglayerCrossChainERC721 is Module, CrossChain {
3630

3731
/*//////////////////////////////////////////////////////////////
3832
EXTENSION CONFIG
3933
//////////////////////////////////////////////////////////////*/
4034

41-
/// @notice Returns all implemented callback and extension functions.
35+
/// @notice Returns all implemented callback and fallback functions.
4236
function getModuleConfig() external pure override returns (ModuleConfig memory config) {
43-
config.fallbackFunctions = new FallbackFunction[](4);
37+
config.fallbackFunctions = new FallbackFunction[](3);
4438

45-
config.fallbackFunctions[0] = FallbackFunction({selector: this.getBridgeModule.selector, permissionBits: 0});
39+
config.fallbackFunctions[0] = FallbackFunction({selector: this.getRouter.selector, permissionBits: 0});
4640
config.fallbackFunctions[1] =
47-
FallbackFunction({selector: this.setBridgeModule.selector, permissionBits: Role._MANAGER_ROLE});
41+
FallbackFunction({selector: this.setRouter.selector, permissionBits: Role._MANAGER_ROLE});
4842
config.fallbackFunctions[2] =
4943
FallbackFunction({selector: this.sendCrossChainTransaction.selector, permissionBits: 0});
50-
51-
config.requiredInterfaces = new bytes4[](1);
52-
config.requiredInterfaces[0] = 0x80ac58cd; // ERC721.
53-
54-
config.registerInstallationCallback = true;
5544
}
5645

5746
/// @dev Called by a Core into an Module during the installation of the Module.
5847
function onInstall(bytes calldata data) external {
59-
address bridgeModule = abi.decode(data, (address));
60-
_polygonAgglayerStorage().bridgeModule = bridgeModule;
48+
address router = abi.decode(data, (address));
49+
_polygonAgglayerStorage().router = router;
6150
}
6251

6352
/// @dev Called by a Core into an Module during the uninstallation of the Module.
6453
function onUninstall(bytes calldata data) external {}
6554

55+
/// @dev Returns bytes encoded install params, to be sent to `onInstall` function
56+
function encodeBytesOnInstall(address router) external pure returns (bytes memory) {
57+
return abi.encode(router);
58+
}
59+
60+
/// @dev Returns bytes encoded uninstall params, to be sent to `onUninstall` function
61+
function encodeBytesOnUninstall() external pure returns (bytes memory) {
62+
return "";
63+
}
64+
6665
/*//////////////////////////////////////////////////////////////
6766
FALLBACK FUNCTIONS
6867
//////////////////////////////////////////////////////////////*/
6968

7069
/// @notice Returns whether transfers is enabled for the token.
71-
function getBridgeModule() external view returns (address) {
72-
return _polygonAgglayerStorage().bridgeModule;
70+
function getRouter() external view override returns (address) {
71+
return _polygonAgglayerStorage().router;
7372
}
7473

7574
/// @notice Set transferability for a token.
76-
function setBridgeModule(address bridgeModule) external {
77-
_polygonAgglayerStorage().bridgeModule = bridgeModule;
75+
function setRouter(address router) external override {
76+
_polygonAgglayerStorage().router = router;
7877
}
7978

8079
function sendCrossChainTransaction(
8180
uint64 _destinationChain,
8281
address _callAddress,
83-
address _recipient,
84-
address _token,
85-
uint256 _amount,
86-
bytes calldata _data,
82+
bytes calldata _payload,
8783
bytes calldata _extraArgs
88-
) external {
89-
address bridgeModule = _polygonAgglayerStorage().bridgeModule;
90-
if (bridgeModule == address(0)) {
91-
revert bridgeModuleNotSet();
92-
}
93-
(address _fallbackAddress, bool _forceUpdateGlobalExitRoot) = abi.decode(_extraArgs, (address, bool));
84+
) external payable override {
85+
address router = _polygonAgglayerStorage().router;
86+
(address _fallbackAddress, bool _forceUpdateGlobalExitRoot, address _token, uint256 _amount) =
87+
abi.decode(_extraArgs, (address, bool, address, uint256));
9488

95-
IBridgeAndCall(bridgeModule).bridgeAndCall(
96-
address(this),
89+
IBridgeAndCall(router).bridgeAndCall(
90+
_token,
9791
_amount,
9892
uint32(_destinationChain),
9993
_callAddress,
10094
_fallbackAddress,
101-
_data,
95+
_payload,
10296
_forceUpdateGlobalExitRoot
10397
);
98+
99+
onCrossChainTransactionSent(_destinationChain, _callAddress, _payload, _extraArgs);
104100
}
105101

106102
/*//////////////////////////////////////////////////////////////
107103
INTERNAL FUNCTIONS
108104
//////////////////////////////////////////////////////////////*/
109105

106+
function onCrossChainTransactionSent(
107+
uint64 _destinationChain,
108+
address _callAddress,
109+
bytes calldata _payload,
110+
bytes calldata _extraArgs
111+
) internal override {
112+
/// post cross chain transaction sent logic goes here
113+
}
114+
115+
function onCrossChainTransactionReceived(
116+
uint64 _sourceChain,
117+
address _sourceAddress,
118+
bytes memory _payload,
119+
bytes memory _extraArgs
120+
) internal override {
121+
/// post cross chain transaction received logic goes here
122+
}
123+
110124
function _polygonAgglayerStorage() internal pure returns (PolygonAgglayerCrossChainStorage.Data storage) {
111125
return PolygonAgglayerCrossChainStorage.data();
112126
}

0 commit comments

Comments
 (0)