Skip to content

Commit

Permalink
feat!: make authority factories return interface
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Oct 10, 2024
1 parent e1bcf0d commit 9e515d4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-radios-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/rollups": major
---

Make `IAuthorityFactory` functions return `IAuthority`
5 changes: 5 additions & 0 deletions .changeset/metal-dryers-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/rollups": major
---

Made `ISelfHostedApplicationFactory` return `IApplication`
11 changes: 6 additions & 5 deletions contracts/consensus/authority/AuthorityFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";

import {IAuthorityFactory} from "./IAuthorityFactory.sol";
import {Authority} from "./Authority.sol";
import {IAuthority} from "./IAuthority.sol";

/// @title Authority Factory
/// @notice Allows anyone to reliably deploy a new `Authority` contract.
/// @notice Allows anyone to reliably deploy a new `IAuthority` contract.
contract AuthorityFactory is IAuthorityFactory {
function newAuthority(
address authorityOwner,
uint256 epochLength
) external override returns (Authority) {
Authority authority = new Authority(authorityOwner, epochLength);
) external override returns (IAuthority) {
IAuthority authority = new Authority(authorityOwner, epochLength);

emit AuthorityCreated(authority);

Expand All @@ -26,8 +27,8 @@ contract AuthorityFactory is IAuthorityFactory {
address authorityOwner,
uint256 epochLength,
bytes32 salt
) external override returns (Authority) {
Authority authority = new Authority{salt: salt}(
) external override returns (IAuthority) {
IAuthority authority = new Authority{salt: salt}(
authorityOwner,
epochLength
);
Expand Down
8 changes: 4 additions & 4 deletions contracts/consensus/authority/IAuthorityFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pragma solidity ^0.8.8;

import {Authority} from "./Authority.sol";
import {IAuthority} from "./IAuthority.sol";

/// @title Authority Factory interface
interface IAuthorityFactory {
Expand All @@ -12,7 +12,7 @@ interface IAuthorityFactory {
/// @notice A new authority was deployed.
/// @param authority The authority
/// @dev MUST be triggered on a successful call to `newAuthority`.
event AuthorityCreated(Authority authority);
event AuthorityCreated(IAuthority authority);

// Permissionless functions

Expand All @@ -26,7 +26,7 @@ interface IAuthorityFactory {
function newAuthority(
address authorityOwner,
uint256 epochLength
) external returns (Authority);
) external returns (IAuthority);

/// @notice Deploy a new authority deterministically.
/// @param authorityOwner The initial authority owner
Expand All @@ -40,7 +40,7 @@ interface IAuthorityFactory {
address authorityOwner,
uint256 epochLength,
bytes32 salt
) external returns (Authority);
) external returns (IAuthority);

/// @notice Calculate the address of an authority to be deployed deterministically.
/// @param authorityOwner The initial authority owner
Expand Down
6 changes: 3 additions & 3 deletions contracts/dapp/ISelfHostedApplicationFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

pragma solidity ^0.8.8;

import {Authority} from "../consensus/authority/Authority.sol";
import {IAuthority} from "../consensus/authority/IAuthority.sol";
import {IAuthorityFactory} from "../consensus/authority/IAuthorityFactory.sol";
import {IApplication} from "./IApplication.sol";
import {IApplicationFactory} from "./IApplicationFactory.sol";

/// @title Self-hosted Application Factory interface
interface ISelfHostedApplicationFactory {
/// @notice Get the factory used to deploy `Authority` contracts
/// @notice Get the factory used to deploy `IAuthority` contracts
/// @return The authority factory
function getAuthorityFactory() external view returns (IAuthorityFactory);

Expand Down Expand Up @@ -38,7 +38,7 @@ interface ISelfHostedApplicationFactory {
address appOwner,
bytes32 templateHash,
bytes32 salt
) external returns (IApplication, Authority);
) external returns (IApplication, IAuthority);

/// @notice Calculate the addresses of the application and authority contracts
/// to be deployed deterministically.
Expand Down
6 changes: 3 additions & 3 deletions contracts/dapp/SelfHostedApplicationFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
pragma solidity ^0.8.8;

import {IConsensus} from "../consensus/IConsensus.sol";
import {Authority} from "../consensus/authority/Authority.sol";
import {IAuthority} from "../consensus/authority/IAuthority.sol";
import {IAuthorityFactory} from "../consensus/authority/IAuthorityFactory.sol";
import {IApplication} from "./IApplication.sol";
import {IApplicationFactory} from "./IApplicationFactory.sol";
import {ISelfHostedApplicationFactory} from "./ISelfHostedApplicationFactory.sol";

/// @title Self-hosted Application Factory
/// @notice Allows anyone to reliably deploy a new Authority contract,
/// @notice Allows anyone to reliably deploy a new IAuthority contract,
/// along with an IApplication contract already linked to it.
contract SelfHostedApplicationFactory is ISelfHostedApplicationFactory {
IAuthorityFactory immutable _authorityFactory;
Expand Down Expand Up @@ -51,7 +51,7 @@ contract SelfHostedApplicationFactory is ISelfHostedApplicationFactory {
address appOwner,
bytes32 templateHash,
bytes32 salt
) external returns (IApplication application, Authority authority) {
) external returns (IApplication application, IAuthority authority) {
authority = _authorityFactory.newAuthority(
authorityOwner,
epochLength,
Expand Down
8 changes: 4 additions & 4 deletions test/foundry/consensus/authority/AuthorityFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Test} from "forge-std/Test.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {AuthorityFactory, IAuthorityFactory} from "contracts/consensus/authority/AuthorityFactory.sol";
import {Authority} from "contracts/consensus/authority/Authority.sol";
import {IAuthority} from "contracts/consensus/authority/IAuthority.sol";

contract AuthorityFactoryTest is Test {
AuthorityFactory _factory;
Expand Down Expand Up @@ -63,7 +63,7 @@ contract AuthorityFactoryTest is Test {

vm.recordLogs();

Authority authority = _factory.newAuthority(
IAuthority authority = _factory.newAuthority(
authorityOwner,
epochLength
);
Expand All @@ -87,7 +87,7 @@ contract AuthorityFactoryTest is Test {

vm.recordLogs();

Authority authority = _factory.newAuthority(
IAuthority authority = _factory.newAuthority(
authorityOwner,
epochLength,
salt
Expand Down Expand Up @@ -115,7 +115,7 @@ contract AuthorityFactoryTest is Test {
function _testNewAuthorityAux(
address authorityOwner,
uint256 epochLength,
Authority authority
IAuthority authority
) internal {
Vm.Log[] memory entries = vm.getRecordedLogs();

Expand Down
4 changes: 2 additions & 2 deletions test/foundry/dapp/SelfHostedApplicationFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {IAuthorityFactory} from "contracts/consensus/authority/IAuthorityFactory.sol";
import {AuthorityFactory} from "contracts/consensus/authority/AuthorityFactory.sol";
import {Authority} from "contracts/consensus/authority/Authority.sol";
import {IAuthority} from "contracts/consensus/authority/IAuthority.sol";
import {IApplicationFactory} from "contracts/dapp/IApplicationFactory.sol";
import {ApplicationFactory} from "contracts/dapp/ApplicationFactory.sol";
import {IApplication} from "contracts/dapp/IApplication.sol";
Expand Down Expand Up @@ -135,7 +135,7 @@ contract SelfHostedApplicationFactoryTest is TestBase {
);

IApplication application;
Authority authority;
IAuthority authority;

(application, authority) = factory.deployContracts(
authorityOwner,
Expand Down

0 comments on commit 9e515d4

Please sign in to comment.