|
| 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 | +} |
0 commit comments