1
1
// SPDX-License-Identifier: Apache-2.0
2
2
pragma solidity ^ 0.8.20 ;
3
3
4
- import {ModularModule } from "../../../ModularModule .sol " ;
4
+ import {Module } from "../../../Module .sol " ;
5
5
import {Role} from "../../../Role.sol " ;
6
- import {BeforeTransferCallbackERC721} from "../../../callback/BeforeTransferCallbackERC721.sol " ;
6
+
7
+ import {CrossChain} from "./CrossChain.sol " ;
7
8
import {IBridgeAndCall} from "@lxly-bridge-and-call/IBridgeAndCall.sol " ;
8
9
9
10
library PolygonAgglayerCrossChainStorage {
@@ -13,7 +14,7 @@ library PolygonAgglayerCrossChainStorage {
13
14
keccak256 (abi.encode (uint256 (keccak256 ("token.bridgeAndCall " )) - 1 )) & ~ bytes32 (uint256 (0xff ));
14
15
15
16
struct Data {
16
- address bridgeModule ;
17
+ address router ;
17
18
}
18
19
19
20
function data () internal pure returns (Data storage data_ ) {
@@ -25,88 +26,101 @@ library PolygonAgglayerCrossChainStorage {
25
26
26
27
}
27
28
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 {
36
30
37
31
/*//////////////////////////////////////////////////////////////
38
32
EXTENSION CONFIG
39
33
//////////////////////////////////////////////////////////////*/
40
34
41
- /// @notice Returns all implemented callback and extension functions.
35
+ /// @notice Returns all implemented callback and fallback functions.
42
36
function getModuleConfig () external pure override returns (ModuleConfig memory config ) {
43
- config.fallbackFunctions = new FallbackFunction [](4 );
37
+ config.fallbackFunctions = new FallbackFunction [](3 );
44
38
45
- config.fallbackFunctions[0 ] = FallbackFunction ({selector: this .getBridgeModule .selector , permissionBits: 0 });
39
+ config.fallbackFunctions[0 ] = FallbackFunction ({selector: this .getRouter .selector , permissionBits: 0 });
46
40
config.fallbackFunctions[1 ] =
47
- FallbackFunction ({selector: this .setBridgeModule .selector , permissionBits: Role._MANAGER_ROLE});
41
+ FallbackFunction ({selector: this .setRouter .selector , permissionBits: Role._MANAGER_ROLE});
48
42
config.fallbackFunctions[2 ] =
49
43
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 ;
55
44
}
56
45
57
46
/// @dev Called by a Core into an Module during the installation of the Module.
58
47
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 ;
61
50
}
62
51
63
52
/// @dev Called by a Core into an Module during the uninstallation of the Module.
64
53
function onUninstall (bytes calldata data ) external {}
65
54
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
+
66
65
/*//////////////////////////////////////////////////////////////
67
66
FALLBACK FUNCTIONS
68
67
//////////////////////////////////////////////////////////////*/
69
68
70
69
/// @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 ;
73
72
}
74
73
75
74
/// @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 ;
78
77
}
79
78
80
79
function sendCrossChainTransaction (
81
80
uint64 _destinationChain ,
82
81
address _callAddress ,
83
- address _recipient ,
84
- address _token ,
85
- uint256 _amount ,
86
- bytes calldata _data ,
82
+ bytes calldata _payload ,
87
83
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 ));
94
88
95
- IBridgeAndCall (bridgeModule ).bridgeAndCall (
96
- address ( this ) ,
89
+ IBridgeAndCall (router ).bridgeAndCall (
90
+ _token ,
97
91
_amount,
98
92
uint32 (_destinationChain),
99
93
_callAddress,
100
94
_fallbackAddress,
101
- _data ,
95
+ _payload ,
102
96
_forceUpdateGlobalExitRoot
103
97
);
98
+
99
+ onCrossChainTransactionSent (_destinationChain, _callAddress, _payload, _extraArgs);
104
100
}
105
101
106
102
/*//////////////////////////////////////////////////////////////
107
103
INTERNAL FUNCTIONS
108
104
//////////////////////////////////////////////////////////////*/
109
105
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
+
110
124
function _polygonAgglayerStorage () internal pure returns (PolygonAgglayerCrossChainStorage.Data storage ) {
111
125
return PolygonAgglayerCrossChainStorage.data ();
112
126
}
0 commit comments