-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathDirectInputApplicationFactory.sol
More file actions
63 lines (56 loc) · 2.31 KB
/
Copy pathDirectInputApplicationFactory.sol
File metadata and controls
63 lines (56 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
pragma solidity ^0.8.8;
import {Create2} from "@openzeppelin-contracts-5.2.0/utils/Create2.sol";
import {IApplicationFactory} from "./IApplicationFactory.sol";
import {IDirectInputApplicationFactory} from "./IDirectInputApplicationFactory.sol";
import {IOutputsMerkleRootValidator} from "../consensus/IOutputsMerkleRootValidator.sol";
import {Application} from "./Application.sol";
import {DataAvailability} from "../common/DataAvailability.sol";
import {IApplication} from "./IApplication.sol";
import {IInputBox} from "../inputs/IInputBox.sol";
/// @title Application Factory
/// @notice Allows anyone to reliably deploy a new `IApplication` contract.
contract DirectInputApplicationFactory is IDirectInputApplicationFactory {
IApplicationFactory private immutable _applicationFactory;
IInputBox private immutable _inputBox;
constructor(IApplicationFactory applicationFactory, IInputBox inputBox) {
_applicationFactory = applicationFactory;
_inputBox = inputBox;
}
function newApplication(
IOutputsMerkleRootValidator outputsMerkleRootValidator,
address appOwner,
bytes32 templateHash,
bytes32 salt
) external override returns (IApplication) {
bytes memory dataAvailability =
abi.encodeCall(DataAvailability.InputBox, (_inputBox));
return _applicationFactory.newApplication(
outputsMerkleRootValidator, appOwner, templateHash, dataAvailability, salt
);
}
function calculateApplicationAddress(
IOutputsMerkleRootValidator outputsMerkleRootValidator,
address appOwner,
bytes32 templateHash,
bytes32 salt
) external view override returns (address) {
bytes memory dataAvailability =
abi.encodeCall(DataAvailability.InputBox, (_inputBox));
return Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(Application).creationCode,
abi.encode(
outputsMerkleRootValidator,
appOwner,
templateHash,
dataAvailability
)
)
)
);
}
}