Skip to content

Commit 5ed97bd

Browse files
committed
updated to incorporate bridgeAsset and bridgeMessage
1 parent d02912e commit 5ed97bd

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

remappings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ forge-std/=lib/forge-std/src/
66
@limitbreak/creator-token-standards/=lib/creator-token-standards/src/
77
@limitbreak/permit-c/=lib/PermitC/src/
88
@lxly-bridge-and-call/=lib/lxly-bridge-and-call/src/
9+
@zkevm-contracts/=lib/lxly-bridge-and-call/lib/zkevm-contracts/contracts/

src/module/token/crosschain/PolygonAgglayer.sol

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Role} from "../../../Role.sol";
66

77
import {CrossChain} from "./CrossChain.sol";
88
import {IBridgeAndCall} from "@lxly-bridge-and-call/IBridgeAndCall.sol";
9+
import {PolygonZkEVMBridgeV2} from "@zkevm-contracts/v2/PolygonZkEVMBridgeV2.sol";
910

1011
library 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

Comments
 (0)