Skip to content

Commit 8d76cce

Browse files
committed
WIP: middle of testing out agglayer content
1 parent 5ed97bd commit 8d76cce

3 files changed

Lines changed: 92 additions & 27 deletions

File tree

script/agglayer/Agglayer.s.sol

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {TestNFT} from "./TestNFT.sol";
6+
import {console} from "forge-std/console.sol";
7+
import {Role} from "src/Role.sol";
8+
import {PolygonAgglayerCrossChain} from "src/module/token/crosschain/PolygonAgglayer.sol";
9+
import {ERC20Base} from "src/core/token/ERC20Base.sol";
10+
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
11+
12+
contract DeployTestNFT is Script {
13+
TestNFT public testNFT;
14+
15+
function run() external {
16+
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
17+
vm.startBroadcast(deployerPrivateKey);
18+
19+
testNFT = new TestNFT("TestNFT", "TNFT");
20+
console.log("TestNFT deployed to:", address(testNFT));
21+
22+
vm.stopBroadcast();
23+
}
24+
}
25+
26+
contract MintTestNFT is Script {
27+
TestNFT public testNFT;
28+
ERC20Base public testToken;
29+
30+
function run() external {
31+
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
32+
address deployerAddress = vm.addr(deployerPrivateKey);
33+
address testNFTAddress = vm.envAddress("TEST_NFT_ADDRESS");
34+
address testTokenAddress = vm.envAddress("TEST_TOKEN_ADDRESS");
35+
uint64 destinationChain = 2442;
36+
vm.startBroadcast(deployerPrivateKey);
37+
38+
testNFT = TestNFT(testNFTAddress);
39+
testToken = ERC20Base(payable(testTokenAddress));
40+
41+
OwnableRoles(testTokenAddress).grantRoles(deployerAddress, Role._MINTER_ROLE);
42+
testToken.mint(deployerAddress, 100, "");
43+
console.log("Minted test tokens to deployer");
44+
45+
bytes memory extraArgs = abi.encode(address(0), false, testToken, 100);
46+
bytes memory payload = abi.encodeWithSelector(
47+
bytes4(keccak256("mint(address,uint256)")),
48+
deployerAddress,
49+
1
50+
);
51+
52+
PolygonAgglayerCrossChain(testTokenAddress).sendCrossChainTransaction(
53+
destinationChain,
54+
address(testNFT),
55+
payload,
56+
extraArgs
57+
);
58+
59+
vm.stopBroadcast();
60+
}
61+
}

script/agglayer/TestNFT.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import {ERC721A} from "@erc721a/ERC721A.sol";
5+
6+
contract TestNFT is ERC721A {
7+
constructor(
8+
string memory _name,
9+
string memory _symbol
10+
) ERC721A(_name, _symbol) {}
11+
12+
function mint(address to, uint256 amount) public {
13+
_mint(to, amount);
14+
}
15+
}
16+
17+

src/module/token/crosschain/PolygonAgglayer.sol

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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";
109

1110
library PolygonAgglayerCrossChainStorage {
1211

@@ -16,7 +15,6 @@ library PolygonAgglayerCrossChainStorage {
1615

1716
struct Data {
1817
address router;
19-
address bridge;
2018
}
2119

2220
function data() internal pure returns (Data storage data_) {
@@ -28,7 +26,7 @@ library PolygonAgglayerCrossChainStorage {
2826

2927
}
3028

31-
contract PolygonAgglayerCrossChainERC721 is Module, CrossChain {
29+
contract PolygonAgglayerCrossChain is Module, CrossChain {
3230

3331
/*//////////////////////////////////////////////////////////////
3432
EXTENSION CONFIG
@@ -47,9 +45,8 @@ contract PolygonAgglayerCrossChainERC721 is Module, CrossChain {
4745

4846
/// @dev Called by a Core into an Module during the installation of the Module.
4947
function onInstall(bytes calldata data) external {
50-
(address router, address bridge) = abi.decode(data, (address, address));
48+
address router = abi.decode(data, (address));
5149
_polygonAgglayerStorage().router = router;
52-
_polygonAgglayerStorage().bridge = bridge;
5350
}
5451

5552
/// @dev Called by a Core into an Module during the uninstallation of the Module.
@@ -86,28 +83,18 @@ contract PolygonAgglayerCrossChainERC721 is Module, CrossChain {
8683
bytes calldata _extraArgs
8784
) external payable override {
8885
address router = _polygonAgglayerStorage().router;
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-
}
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+
);
11198

11299
onCrossChainTransactionSent(_destinationChain, _callAddress, _payload, _extraArgs);
113100
}

0 commit comments

Comments
 (0)