Skip to content

Commit 9295f9e

Browse files
TD1320 ImmutableSignedZoneV2 deploy script (#215)
* Basic deploy script for ImmutableSignedZoneV2 * use create3 Signed-off-by: Frank Li <[email protected]> * fix test Signed-off-by: Frank Li <[email protected]> * seperate dev script * feedback Signed-off-by: Frank Li <[email protected]> --------- Signed-off-by: Frank Li <[email protected]> Co-authored-by: Leslie Fung <[email protected]>
1 parent 2ec5c61 commit 9295f9e

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) Immutable Pty Ltd 2018 - 2024
2+
// SPDX-License-Identifier: Apache-2
3+
// solhint-disable-next-line compiler-version
4+
pragma solidity 0.8.20;
5+
6+
import "forge-std/Test.sol";
7+
import {ImmutableSignedZoneV2} from "../../../contracts/trading/seaport/zones/immutable-signed-zone/v2/ImmutableSignedZoneV2.sol";
8+
9+
/**
10+
* @title IDeployer Interface
11+
* @notice This interface defines the contract responsible for deploying and optionally initializing new contracts
12+
* via a specified deployment method.
13+
* @dev Credit to axelarnetwork https://github.com/axelarnetwork/axelar-gmp-sdk-solidity/blob/main/contracts/interfaces/IDeployer.sol
14+
*/
15+
interface IDeployer {
16+
function deploy(bytes memory bytecode, bytes32 salt) external payable returns (address deployedAddress_);
17+
}
18+
19+
struct DeploymentArgs {
20+
address signer;
21+
address factory;
22+
string salt;
23+
}
24+
25+
struct ZoneDeploymentArgs {
26+
address owner;
27+
string name;
28+
string apiEndpoint;
29+
string documentationURI;
30+
}
31+
32+
contract DeployImmutableSignedZoneV2 is Test {
33+
function testDeploy() external {
34+
/// @dev Fork the Immutable zkEVM testnet for this test
35+
string memory rpcURL = "https://rpc.testnet.immutable.com";
36+
vm.createSelectFork(rpcURL);
37+
38+
/// @dev These are Immutable zkEVM testnet values where necessary
39+
DeploymentArgs memory deploymentArgs = DeploymentArgs({
40+
signer: 0xdDA0d9448Ebe3eA43aFecE5Fa6401F5795c19333,
41+
factory: 0x37a59A845Bb6eD2034098af8738fbFFB9D589610,
42+
salt: "salty"
43+
});
44+
45+
/// @dev These are Immutable zkEVM testnet values where necessary
46+
ZoneDeploymentArgs memory zoneDeploymentArgs = ZoneDeploymentArgs({
47+
owner: address(0xC606830D8341bc9F5F5Dd7615E9313d2655B505D),
48+
name: "TestImmutableSignedZoneV2",
49+
apiEndpoint: "https://api.sandbox.immutable.com/",
50+
documentationURI: ""
51+
});
52+
53+
// Run deployment against forked testnet
54+
ImmutableSignedZoneV2 deployedContract = _deploy(deploymentArgs, zoneDeploymentArgs);
55+
56+
// Assert
57+
(
58+
,
59+
string memory apiEndpoint,
60+
,
61+
string memory documentationURI
62+
) = deployedContract.sip7Information();
63+
64+
assertEq(true, (keccak256(abi.encodePacked(apiEndpoint)) == keccak256(abi.encodePacked(zoneDeploymentArgs.apiEndpoint))));
65+
assertEq(true, (keccak256(abi.encodePacked(documentationURI)) == keccak256(abi.encodePacked(zoneDeploymentArgs.documentationURI))));
66+
}
67+
68+
function deploy() external {
69+
address signer = vm.envAddress("DEPLOYER_ADDRESS");
70+
address factory = vm.envAddress("OWNABLE_CREATE3_FACTORY_ADDRESS");
71+
address owner = vm.envAddress("OWNER");
72+
string memory documentationURI = vm.envString("DOCUMENTATION_URI");
73+
string memory apiEndpoint = vm.envString("API_ENDPOINT");
74+
string memory name = vm.envString("NAME");
75+
string memory salt = vm.envString("SALT");
76+
77+
DeploymentArgs memory deploymentArgs = DeploymentArgs({signer: signer, factory: factory, salt: salt});
78+
79+
ZoneDeploymentArgs memory zoneDeploymentArgs =
80+
ZoneDeploymentArgs({owner: owner, apiEndpoint: apiEndpoint, documentationURI: documentationURI, name: name});
81+
82+
_deploy(deploymentArgs, zoneDeploymentArgs);
83+
}
84+
85+
function _deploy(DeploymentArgs memory deploymentArgs, ZoneDeploymentArgs memory zoneArgs)
86+
internal
87+
returns (ImmutableSignedZoneV2 zoneContract)
88+
{
89+
IDeployer ownableCreate3 = IDeployer(deploymentArgs.factory);
90+
91+
// Create deployment bytecode and encode constructor args
92+
bytes memory deploymentBytecode = abi.encodePacked(
93+
type(ImmutableSignedZoneV2).creationCode,
94+
abi.encode(zoneArgs.name, zoneArgs.apiEndpoint, zoneArgs.documentationURI, zoneArgs.owner)
95+
);
96+
97+
bytes32 saltBytes = keccak256(abi.encode(deploymentArgs.salt));
98+
99+
/// @dev Deploy the contract via the Ownable CREATE3 factory
100+
vm.startBroadcast(deploymentArgs.signer);
101+
102+
address deployedAddress = ownableCreate3.deploy(deploymentBytecode, saltBytes);
103+
zoneContract = ImmutableSignedZoneV2(deployedAddress);
104+
105+
vm.stopBroadcast();
106+
}
107+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Immutable Pty Ltd 2018 - 2024
2+
// SPDX-License-Identifier: Apache-2
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {ImmutableSignedZoneV2} from "../../../contracts/trading/seaport/zones/immutable-signed-zone/v2/ImmutableSignedZoneV2.sol";
6+
7+
// solhint-disable-next-line compiler-version
8+
pragma solidity 0.8.20;
9+
10+
11+
// Deploy ImmutableSignedZoneV2 to dev environment (without create3)
12+
contract DeployImmutableSignedZoneV2Dev is Script {
13+
function run() external {
14+
vm.startBroadcast();
15+
16+
// replace args with test values if necessary
17+
ImmutableSignedZoneV2 c = new ImmutableSignedZoneV2("ImmutableSignedZone", "", "", address(0xC606830D8341bc9F5F5Dd7615E9313d2655B505D));
18+
19+
c.grantRole(bytes32("ZONE_MANAGER"), address(0xC606830D8341bc9F5F5Dd7615E9313d2655B505D));
20+
21+
// set server side signer address
22+
c.addSigner(address(0xBE63B9F9F2Ed97fac4b71630268bC050ddB53395));
23+
24+
vm.stopBroadcast();
25+
}
26+
}
27+
28+
// forge script script/trading/seaport/DeployImmutableSignedZoneV2Dev.s.sol:DeployImmutableSignedZoneV2Dev --rpc-url "https://rpc.dev.immutable.com" --broadcast -vvvv --priority-gas-price 10000000000 --with-gas-price 11000000000 --private-key=xx

0 commit comments

Comments
 (0)