Skip to content

Commit

Permalink
refactor!: revert adding constructor arguments to Application
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Jul 2, 2024
1 parent 93eefb5 commit 2088261
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 227 deletions.
5 changes: 0 additions & 5 deletions .changeset/quiet-guests-greet.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@
Modified the `ICartesiDAppFactory` interface:

- Renamed it as `IApplicationFactory`.

- Added the following parameters to its functions and events:

- `inputBox`
- `portals`
5 changes: 0 additions & 5 deletions .changeset/red-wasps-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ Modified the `CartesiDApp` contract:

- Renamed it as `Application`.

- Added the following parameters to its constructor:

- `inputBox`
- `portals`

- Made it support the following interfaces (as in EIP-165):

- `IApplication`
Expand Down
4 changes: 0 additions & 4 deletions .changeset/silly-islands-end.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ Modified the `ICartesiDApp` interface:

- Added a `validateOutputHash` function.

- Added a `getInputBox` function.

- Added a `getPortals` function.

- Added an `InputIndexOutOfRange` error.

- Added an `OutputNotExecutable` error.
Expand Down
26 changes: 0 additions & 26 deletions contracts/dapp/Application.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pragma solidity ^0.8.8;

import {IApplication} from "./IApplication.sol";
import {IConsensus} from "../consensus/IConsensus.sol";
import {IInputBox} from "../inputs/IInputBox.sol";
import {IPortal} from "../portals/IPortal.sol";
import {LibOutputValidityProof} from "../library/LibOutputValidityProof.sol";
import {OutputValidityProof} from "../common/OutputValidityProof.sol";
import {Outputs} from "../common/Outputs.sol";
Expand Down Expand Up @@ -43,33 +41,17 @@ contract Application is
/// @dev See the `getConsensus` and `migrateToConsensus` functions.
IConsensus internal _consensus;

/// @notice The input box contract.
/// @dev See the `getInputBox` function.
IInputBox internal immutable _inputBox;

/// @notice The portals supported by the application.
/// @dev See the `getPortals` function.
IPortal[] internal _portals;

/// @notice Creates an `Application` contract.
/// @param consensus The initial consensus contract
/// @param inputBox The input box contract
/// @param portals The portals supported by the application
/// @param initialOwner The initial application owner
/// @param templateHash The initial machine state hash
constructor(
IConsensus consensus,
IInputBox inputBox,
IPortal[] memory portals,
address initialOwner,
bytes32 templateHash
) Ownable(initialOwner) {
_templateHash = templateHash;
_consensus = consensus;
_inputBox = inputBox;
for (uint256 i; i < portals.length; ++i) {
_portals.push(portals[i]);
}
}

/// @notice Accept Ether transfers.
Expand Down Expand Up @@ -153,14 +135,6 @@ contract Application is
return _consensus;
}

function getInputBox() external view override returns (IInputBox) {
return _inputBox;
}

function getPortals() external view override returns (IPortal[] memory) {
return _portals;
}

function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC1155Holder, IERC165) returns (bool) {
Expand Down
38 changes: 3 additions & 35 deletions contracts/dapp/ApplicationFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,46 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";

import {IApplicationFactory} from "./IApplicationFactory.sol";
import {IConsensus} from "../consensus/IConsensus.sol";
import {IInputBox} from "../inputs/IInputBox.sol";
import {IPortal} from "../portals/IPortal.sol";
import {Application} from "./Application.sol";

/// @title Application Factory
/// @notice Allows anyone to reliably deploy a new `Application` contract.
contract ApplicationFactory is IApplicationFactory {
function newApplication(
IConsensus consensus,
IInputBox inputBox,
IPortal[] memory portals,
address appOwner,
bytes32 templateHash
) external override returns (Application) {
Application appContract = new Application(
consensus,
inputBox,
portals,
appOwner,
templateHash
);

emit ApplicationCreated(
consensus,
inputBox,
portals,
appOwner,
templateHash,
appContract
);
emit ApplicationCreated(consensus, appOwner, templateHash, appContract);

return appContract;
}

function newApplication(
IConsensus consensus,
IInputBox inputBox,
IPortal[] memory portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
) external override returns (Application) {
Application appContract = new Application{salt: salt}(
consensus,
inputBox,
portals,
appOwner,
templateHash
);

emit ApplicationCreated(
consensus,
inputBox,
portals,
appOwner,
templateHash,
appContract
);
emit ApplicationCreated(consensus, appOwner, templateHash, appContract);

return appContract;
}

function calculateApplicationAddress(
IConsensus consensus,
IInputBox inputBox,
IPortal[] memory portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
Expand All @@ -83,13 +57,7 @@ contract ApplicationFactory is IApplicationFactory {
keccak256(
abi.encodePacked(
type(Application).creationCode,
abi.encode(
consensus,
inputBox,
portals,
appOwner,
templateHash
)
abi.encode(consensus, appOwner, templateHash)
)
)
);
Expand Down
14 changes: 2 additions & 12 deletions contracts/dapp/IApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Re
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";

import {IConsensus} from "../consensus/IConsensus.sol";
import {IInputBox} from "../inputs/IInputBox.sol";
import {IPortal} from "../portals/IPortal.sol";
import {OutputValidityProof} from "../common/OutputValidityProof.sol";

/// @notice The base layer incarnation of an application running on the execution layer.
/// @notice The state of the application advances through inputs sent to an `IInputBox` contract (see the `getInputBox` function).
/// @notice These inputs can be sent either directly, or indirectly through portals (see the `getPortals` function).
/// @notice The state of the application advances through inputs sent to an `IInputBox` contract.
/// @notice These inputs can be sent either directly, or indirectly through portals.
/// @notice Reader nodes can retrieve inputs sent to the `IInputBox` contract through events, and feed them into the machine.
/// @notice Validator nodes can also submit claims to the `IConsensus` contract (see the `getConsensus` function).
/// @notice Once accepted, claims can be used to validate outputs generated by the machine.
Expand Down Expand Up @@ -114,12 +112,4 @@ interface IApplication is IERC721Receiver, IERC1155Receiver {
/// @notice Get the current consensus.
/// @return The current consensus
function getConsensus() external view returns (IConsensus);

/// @notice Get the input box that the application is listening to.
/// @return The input box
function getInputBox() external view returns (IInputBox);

/// @notice Get the portals that the application expects inputs from.
/// @return The portals.
function getPortals() external view returns (IPortal[] memory);
}
18 changes: 0 additions & 18 deletions contracts/dapp/IApplicationFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ pragma solidity ^0.8.8;

import {Application} from "./Application.sol";
import {IConsensus} from "../consensus/IConsensus.sol";
import {IInputBox} from "../inputs/IInputBox.sol";
import {IPortal} from "../portals/IPortal.sol";

/// @title Application Factory interface
interface IApplicationFactory {
// Events

/// @notice A new application was deployed.
/// @param consensus The initial consensus contract
/// @param inputBox The input box contract
/// @param portals The portals supported by the application
/// @param appOwner The initial application owner
/// @param templateHash The initial machine state hash
/// @param appContract The application contract
/// @dev MUST be triggered on a successful call to `newApplication`.
event ApplicationCreated(
IConsensus indexed consensus,
IInputBox inputBox,
IPortal[] portals,
address appOwner,
bytes32 templateHash,
Application appContract
Expand All @@ -33,42 +27,32 @@ interface IApplicationFactory {

/// @notice Deploy a new application.
/// @param consensus The initial consensus contract
/// @param inputBox The input box contract
/// @param portals The portals supported by the application
/// @param appOwner The initial application owner
/// @param templateHash The initial machine state hash
/// @return The application
/// @dev On success, MUST emit an `ApplicationCreated` event.
function newApplication(
IConsensus consensus,
IInputBox inputBox,
IPortal[] calldata portals,
address appOwner,
bytes32 templateHash
) external returns (Application);

/// @notice Deploy a new application deterministically.
/// @param consensus The initial consensus contract
/// @param inputBox The input box contract
/// @param portals The portals supported by the application
/// @param appOwner The initial application owner
/// @param templateHash The initial machine state hash
/// @param salt The salt used to deterministically generate the application contract address
/// @return The application
/// @dev On success, MUST emit an `ApplicationCreated` event.
function newApplication(
IConsensus consensus,
IInputBox inputBox,
IPortal[] calldata portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
) external returns (Application);

/// @notice Calculate the address of an application contract to be deployed deterministically.
/// @param consensus The initial consensus contract
/// @param inputBox The input box contract
/// @param portals The portals supported by the application
/// @param appOwner The initial application owner
/// @param templateHash The initial machine state hash
/// @param salt The salt used to deterministically generate the application contract address
Expand All @@ -77,8 +61,6 @@ interface IApplicationFactory {
/// is able to deterministically deploy an application.
function calculateApplicationAddress(
IConsensus consensus,
IInputBox inputBox,
IPortal[] calldata portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
Expand Down
10 changes: 0 additions & 10 deletions contracts/dapp/ISelfHostedApplicationFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {Authority} from "../consensus/authority/Authority.sol";
import {IAuthorityFactory} from "../consensus/authority/IAuthorityFactory.sol";
import {Application} from "./Application.sol";
import {IApplicationFactory} from "./IApplicationFactory.sol";
import {IInputBox} from "../inputs/IInputBox.sol";
import {IPortal} from "../portals/IPortal.sol";

/// @title Self-hosted Application Factory interface
interface ISelfHostedApplicationFactory {
Expand All @@ -25,17 +23,13 @@ interface ISelfHostedApplicationFactory {

/// @notice Deploy new application and authority contracts deterministically.
/// @param authorityOwner The initial authority owner
/// @param inputBox The input box contract
/// @param portals The portals supported by the application
/// @param appOwner The initial Application owner
/// @param templateHash The initial machine state hash
/// @param salt The salt used to deterministically generate the addresses
/// @return The application contract
/// @return The authority contract
function deployContracts(
address authorityOwner,
IInputBox inputBox,
IPortal[] calldata portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
Expand All @@ -44,17 +38,13 @@ interface ISelfHostedApplicationFactory {
/// @notice Calculate the addresses of the application and authority contracts
/// to be deployed deterministically.
/// @param authorityOwner The initial authority owner
/// @param inputBox The input box contract
/// @param portals The portals supported by the application
/// @param appOwner The initial Application owner
/// @param templateHash The initial machine state hash
/// @param salt The salt used to deterministically generate the addresses
/// @return The application address
/// @return The authority address
function calculateAddresses(
address authorityOwner,
IInputBox inputBox,
IPortal[] calldata portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
Expand Down
10 changes: 0 additions & 10 deletions contracts/dapp/SelfHostedApplicationFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {IAuthorityFactory} from "../consensus/authority/IAuthorityFactory.sol";
import {Application} from "./Application.sol";
import {IApplicationFactory} from "./IApplicationFactory.sol";
import {ISelfHostedApplicationFactory} from "./ISelfHostedApplicationFactory.sol";
import {IInputBox} from "../inputs/IInputBox.sol";
import {IPortal} from "../portals/IPortal.sol";

/// @title Self-hosted Application Factory
/// @notice Allows anyone to reliably deploy a new Authority contract,
Expand Down Expand Up @@ -49,8 +47,6 @@ contract SelfHostedApplicationFactory is ISelfHostedApplicationFactory {

function deployContracts(
address authorityOwner,
IInputBox inputBox,
IPortal[] memory portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
Expand All @@ -59,8 +55,6 @@ contract SelfHostedApplicationFactory is ISelfHostedApplicationFactory {

application = _applicationFactory.newApplication(
authority,
inputBox,
portals,
appOwner,
templateHash,
salt
Expand All @@ -69,8 +63,6 @@ contract SelfHostedApplicationFactory is ISelfHostedApplicationFactory {

function calculateAddresses(
address authorityOwner,
IInputBox inputBox,
IPortal[] memory portals,
address appOwner,
bytes32 templateHash,
bytes32 salt
Expand All @@ -82,8 +74,6 @@ contract SelfHostedApplicationFactory is ISelfHostedApplicationFactory {

application = _applicationFactory.calculateApplicationAddress(
IConsensus(authority),
inputBox,
portals,
appOwner,
templateHash,
salt
Expand Down
Loading

0 comments on commit 2088261

Please sign in to comment.