Skip to content

Commit 217342b

Browse files
committed
the script works
1 parent 8951341 commit 217342b

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

script/agglayer/Agglayer.s.sol

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.20;
33

4-
import {Script} from "forge-std/Script.sol";
54
import {TestNFT} from "./TestNFT.sol";
5+
6+
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
7+
import {Script} from "forge-std/Script.sol";
68
import {console} from "forge-std/console.sol";
79
import {Role} from "src/Role.sol";
8-
import {PolygonAgglayerCrossChain} from "src/module/token/crosschain/PolygonAgglayer.sol";
910
import {ERC20Core} from "src/core/token/ERC20Core.sol";
11+
import {PolygonAgglayerCrossChain} from "src/module/token/crosschain/PolygonAgglayer.sol";
1012
import {MintableERC20} from "src/module/token/minting/MintableERC20.sol";
11-
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
1213

1314
contract DeployTestNFT is Script {
15+
1416
TestNFT public testNFT;
1517

1618
function run() external {
@@ -22,9 +24,11 @@ contract DeployTestNFT is Script {
2224

2325
vm.stopBroadcast();
2426
}
27+
2528
}
2629

2730
contract MintTestNFT is Script {
31+
2832
TestNFT public testNFT;
2933
MintableERC20 public mintableModule;
3034
PolygonAgglayerCrossChain public polygonAgglayer;
@@ -42,7 +46,7 @@ contract MintTestNFT is Script {
4246

4347
address[] memory modules = new address[](2);
4448
bytes[] memory moduleData = new bytes[](2);
45-
49+
4650
mintableModule = new MintableERC20(address(0x0));
4751
polygonAgglayer = new PolygonAgglayerCrossChain();
4852
console.log("mintableModule deployed to:", address(mintableModule));
@@ -74,23 +78,17 @@ contract MintTestNFT is Script {
7478
core.mint(deployerAddress, 100, "");
7579
console.log("Minted test tokens to deployer");
7680

77-
core.approve(agglayerBridgeExtension, 100);
78-
console.log("Approved agglayer bridge extension");
81+
core.approve(address(core), 100);
82+
console.log("Approved core");
7983

8084
bytes memory extraArgs = abi.encode(deployerAddress, true, address(core), 100, "");
81-
bytes memory payload = abi.encodeWithSelector(
82-
bytes4(keccak256("mint(address,uint256)")),
83-
deployerAddress,
84-
1
85-
);
86-
85+
bytes memory payload = abi.encodeWithSelector(bytes4(keccak256("mint(address,uint256)")), deployerAddress, 1);
86+
8787
PolygonAgglayerCrossChain(address(core)).sendCrossChainTransaction(
88-
destinationChain,
89-
testNFTAddress,
90-
payload,
91-
extraArgs
88+
destinationChain, testNFTAddress, payload, extraArgs
9289
);
9390

9491
vm.stopBroadcast();
9592
}
93+
9694
}

src/core/token/ERC20Base.sol

+2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ contract ERC20Base is ERC20, Multicallable, Core, EIP712 {
204204
return super.transfer(to, amount);
205205
}
206206

207+
receive() external payable {}
208+
207209
/**
208210
* @notice Transfers tokens from a sender to a recipient.
209211
* @param from The address to transfer tokens from.

src/module/token/crosschain/PolygonAgglayer.sol

+14-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +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 {console} from "forge-std/console.sol";
9+
import {IERC20} from "src/interface/IERC20.sol";
1010

1111
library PolygonAgglayerCrossChainStorage {
1212

@@ -49,7 +49,6 @@ contract PolygonAgglayerCrossChain is Module, CrossChain {
4949
/// @dev Called by a Core into an Module during the installation of the Module.
5050
function onInstall(bytes calldata data) external {
5151
address router = abi.decode(data, (address));
52-
console.log("router in onInstall: ", router);
5352
_polygonAgglayerStorage().router = router;
5453
}
5554

@@ -93,12 +92,7 @@ contract PolygonAgglayerCrossChain is Module, CrossChain {
9392
uint256 _amount,
9493
bytes memory permitData
9594
) = abi.decode(_extraArgs, (address, bool, address, uint256, bytes));
96-
console.log("token address", _token);
97-
console.log("amount", _amount);
98-
console.log("destinationChain", _destinationChain);
99-
console.log("callAddress", _callAddress);
10095

101-
// IBridgeAndCall(_polygonAgglayerStorage().router).bridgeAndCall(
10296
_bridgeAndCall(
10397
_token,
10498
_amount,
@@ -109,13 +103,23 @@ contract PolygonAgglayerCrossChain is Module, CrossChain {
109103
_payload,
110104
_forceUpdateGlobalExitRoot
111105
);
112-
console.log("bridgeAndCall called successfully");
113106

114107
onCrossChainTransactionSent(_destinationChain, _callAddress, _payload, _extraArgs);
115108
}
116109

117-
function _bridgeAndCall(address _token, uint256 _amount, bytes memory permitData, uint32 _destinationChain, address _callAddress, address _fallbackAddress, bytes memory _payload, bool _forceUpdateGlobalExitRoot) internal {
118-
console.log("router: ", _polygonAgglayerStorage().router);
110+
function _bridgeAndCall(
111+
address _token,
112+
uint256 _amount,
113+
bytes memory permitData,
114+
uint32 _destinationChain,
115+
address _callAddress,
116+
address _fallbackAddress,
117+
bytes memory _payload,
118+
bool _forceUpdateGlobalExitRoot
119+
) internal {
120+
IERC20(_token).transferFrom(msg.sender, address(this), _amount);
121+
IERC20(_token).approve(_polygonAgglayerStorage().router, _amount);
122+
119123
IBridgeAndCall(_polygonAgglayerStorage().router).bridgeAndCall(
120124
_token,
121125
_amount,
@@ -127,7 +131,6 @@ contract PolygonAgglayerCrossChain is Module, CrossChain {
127131
_forceUpdateGlobalExitRoot
128132
);
129133
}
130-
131134

132135
/*//////////////////////////////////////////////////////////////
133136
INTERNAL FUNCTIONS

0 commit comments

Comments
 (0)