Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TD1320 ImmutableSignedZoneV2 deploy script #215

Merged
merged 8 commits into from
May 13, 2024
Merged
107 changes: 107 additions & 0 deletions script/trading/seaport/DeployImmutableSignedZoneV2.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) Immutable Pty Ltd 2018 - 2024
// SPDX-License-Identifier: Apache-2
// solhint-disable-next-line compiler-version
pragma solidity 0.8.20;

import "forge-std/Test.sol";
import {ImmutableSignedZoneV2} from "../../../contracts/trading/seaport/zones/immutable-signed-zone/v2/ImmutableSignedZoneV2.sol";

/**
* @title IDeployer Interface
* @notice This interface defines the contract responsible for deploying and optionally initializing new contracts
* via a specified deployment method.
* @dev Credit to axelarnetwork https://github.com/axelarnetwork/axelar-gmp-sdk-solidity/blob/main/contracts/interfaces/IDeployer.sol
*/
interface IDeployer {
function deploy(bytes memory bytecode, bytes32 salt) external payable returns (address deployedAddress_);
}

struct DeploymentArgs {
address signer;
address factory;
string salt;
}

struct ZoneDeploymentArgs {
address owner;
string name;
string apiEndpoint;
string documentationURI;
}

contract DeployImmutableSignedZoneV2 is Test {
function testDeploy() external {
/// @dev Fork the Immutable zkEVM testnet for this test
string memory rpcURL = "https://rpc.testnet.immutable.com";
vm.createSelectFork(rpcURL);

/// @dev These are Immutable zkEVM testnet values where necessary
DeploymentArgs memory deploymentArgs = DeploymentArgs({
signer: 0xdDA0d9448Ebe3eA43aFecE5Fa6401F5795c19333,
factory: 0x37a59A845Bb6eD2034098af8738fbFFB9D589610,
salt: "salty"
});

/// @dev These are Immutable zkEVM testnet values where necessary
ZoneDeploymentArgs memory zoneDeploymentArgs = ZoneDeploymentArgs({
owner: address(0xC606830D8341bc9F5F5Dd7615E9313d2655B505D),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the owner be defaulted to the deployer? Isn't the plan to then transfer ownership of the contract to the multisig wallet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this is just a test value

name: "TestImmutableSignedZoneV2",
apiEndpoint: "https://api.sandbox.immutable.com/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the V1 zone deployment script, we've left the api_endpoint empty. Having the api endpoint info is fine but the script will need to account for the different values in different evnironments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naveen-imtb this is the test, actual deployments will use env var during deployment

documentationURI: ""
});

// Run deployment against forked testnet
ImmutableSignedZoneV2 deployedContract = _deploy(deploymentArgs, zoneDeploymentArgs);

// Assert
(
,
string memory apiEndpoint,
,
string memory documentationURI
) = deployedContract.sip7Information();

assertEq(true, (keccak256(abi.encodePacked(apiEndpoint)) == keccak256(abi.encodePacked(zoneDeploymentArgs.apiEndpoint))));
assertEq(true, (keccak256(abi.encodePacked(documentationURI)) == keccak256(abi.encodePacked(zoneDeploymentArgs.documentationURI))));
}

function deploy() external {
address signer = vm.envAddress("DEPLOYER_ADDRESS");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the role of the signer?
Does the msg.sender have no role in this workflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signer is the deployer used

address factory = vm.envAddress("OWNABLE_CREATE3_FACTORY_ADDRESS");
address owner = vm.envAddress("OWNER");
string memory documentationURI = vm.envString("DOCUMENTATION_URI");
string memory apiEndpoint = vm.envString("API_ENDPOINT");
string memory name = vm.envString("NAME");
string memory salt = vm.envString("SALT");

DeploymentArgs memory deploymentArgs = DeploymentArgs({signer: signer, factory: factory, salt: salt});

ZoneDeploymentArgs memory zoneDeploymentArgs =
ZoneDeploymentArgs({owner: owner, apiEndpoint: apiEndpoint, documentationURI: documentationURI, name: name});

_deploy(deploymentArgs, zoneDeploymentArgs);
}

function _deploy(DeploymentArgs memory deploymentArgs, ZoneDeploymentArgs memory zoneArgs)
internal
returns (ImmutableSignedZoneV2 zoneContract)
{
IDeployer ownableCreate3 = IDeployer(deploymentArgs.factory);

// Create deployment bytecode and encode constructor args
bytes memory deploymentBytecode = abi.encodePacked(
type(ImmutableSignedZoneV2).creationCode,
abi.encode(zoneArgs.name, zoneArgs.apiEndpoint, zoneArgs.documentationURI, zoneArgs.owner)
);

bytes32 saltBytes = keccak256(abi.encode(deploymentArgs.salt));

/// @dev Deploy the contract via the Ownable CREATE3 factory
vm.startBroadcast(deploymentArgs.signer);

address deployedAddress = ownableCreate3.deploy(deploymentBytecode, saltBytes);
zoneContract = ImmutableSignedZoneV2(deployedAddress);

vm.stopBroadcast();
}
}
28 changes: 28 additions & 0 deletions script/trading/seaport/DeployImmutableSignedZoneV2Dev.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Immutable Pty Ltd 2018 - 2024
// SPDX-License-Identifier: Apache-2

import {Script} from "forge-std/Script.sol";
import {ImmutableSignedZoneV2} from "../../../contracts/trading/seaport/zones/immutable-signed-zone/v2/ImmutableSignedZoneV2.sol";

// solhint-disable-next-line compiler-version
pragma solidity 0.8.20;


// Deploy ImmutableSignedZoneV2 to dev environment (without create3)
contract DeployImmutableSignedZoneV2Dev is Script {
function run() external {
vm.startBroadcast();

// replace args with test values if necessary
ImmutableSignedZoneV2 c = new ImmutableSignedZoneV2("ImmutableSignedZone", "", "", address(0xC606830D8341bc9F5F5Dd7615E9313d2655B505D));

c.grantRole(bytes32("ZONE_MANAGER"), address(0xC606830D8341bc9F5F5Dd7615E9313d2655B505D));

// set server side signer address
c.addSigner(address(0xBE63B9F9F2Ed97fac4b71630268bC050ddB53395));

vm.stopBroadcast();
}
}

// 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
Loading