@@ -6,6 +6,7 @@ import {Role} from "../../../Role.sol";
66
77import {CrossChain} from "./CrossChain.sol " ;
88import {IBridgeAndCall} from "@lxly-bridge-and-call/IBridgeAndCall.sol " ;
9+ import {PolygonZkEVMBridgeV2} from "@zkevm-contracts/v2/PolygonZkEVMBridgeV2.sol " ;
910
1011library PolygonAgglayerCrossChainStorage {
1112
@@ -15,6 +16,7 @@ library PolygonAgglayerCrossChainStorage {
1516
1617 struct Data {
1718 address router;
19+ address bridge;
1820 }
1921
2022 function data () internal pure returns (Data storage data_ ) {
@@ -45,8 +47,9 @@ contract PolygonAgglayerCrossChainERC721 is Module, CrossChain {
4547
4648 /// @dev Called by a Core into an Module during the installation of the Module.
4749 function onInstall (bytes calldata data ) external {
48- address router = abi.decode (data, (address ));
50+ ( address router , address bridge ) = abi.decode (data, (address , address ));
4951 _polygonAgglayerStorage ().router = router;
52+ _polygonAgglayerStorage ().bridge = bridge;
5053 }
5154
5255 /// @dev Called by a Core into an Module during the uninstallation of the Module.
@@ -83,18 +86,28 @@ contract PolygonAgglayerCrossChainERC721 is Module, CrossChain {
8386 bytes calldata _extraArgs
8487 ) external payable override {
8588 address router = _polygonAgglayerStorage ().router;
86- (address _fallbackAddress , bool _forceUpdateGlobalExitRoot , address _token , uint256 _amount ) =
87- abi.decode (_extraArgs, (address , bool , address , uint256 ));
88-
89- IBridgeAndCall (router).bridgeAndCall (
90- _token,
91- _amount,
92- uint32 (_destinationChain),
93- _callAddress,
94- _fallbackAddress,
95- _payload,
96- _forceUpdateGlobalExitRoot
97- );
89+ (address _fallbackAddress , bool _forceUpdateGlobalExitRoot , address _token , uint256 _amount , bytes memory permitData ) =
90+ abi.decode (_extraArgs, (address , bool , address , uint256 , bytes ));
91+
92+ if (_token == address (0 ) && _amount == 0 ) {
93+ PolygonZkEVMBridgeV2 (router).bridgeMessage (
94+ uint32 (_destinationChain), _callAddress, _forceUpdateGlobalExitRoot, _payload
95+ );
96+ } else if (_payload.length == 0 ) {
97+ PolygonZkEVMBridgeV2 (router).bridgeAsset (
98+ uint32 (_destinationChain), _callAddress, _amount, _token, _forceUpdateGlobalExitRoot, _permitData)
99+ );
100+ } else {
101+ IBridgeAndCall (router).bridgeAndCall (
102+ _token,
103+ _amount,
104+ uint32 (_destinationChain),
105+ _callAddress,
106+ _fallbackAddress,
107+ _payload,
108+ _forceUpdateGlobalExitRoot
109+ );
110+ }
98111
99112 onCrossChainTransactionSent (_destinationChain, _callAddress, _payload, _extraArgs);
100113 }
0 commit comments