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

Feature: Decouple constellations #118

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lemon-readers-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@openformat/contracts": minor
---

- Remove ConstellationFactory and ERC20Constellation
- Renames Star to App
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity ^0.8.16;
import "forge-std/Script.sol";
import "forge-std/console.sol";
import {Utils} from "scripts/utils/Utils.sol";
import {StarFactory} from "src/factories/Star.sol";
import {AppFactory} from "src/factories/App.sol";

string constant CONTRACT_NAME = "StarFactory";
string constant CONTRACT_NAME = "AppFactory";

contract Deploy is Script, Utils {
function run() external {
Expand All @@ -21,7 +21,7 @@ contract Deploy is Script, Utils {
revert("cannot find deployments, make sure to deploy Proxy, Registry, Globals first");
}

StarFactory factory = new StarFactory(proxy, registry, globals);
AppFactory factory = new AppFactory(proxy, registry, globals);

vm.stopBroadcast();

Expand All @@ -40,8 +40,7 @@ contract CreateApp is Script, Utils {
revert("please provide an app name, make CreateApp args=appName");
}

address appAddress =
StarFactory(getContractDeploymentAddress(CONTRACT_NAME)).create(appNameBytes32, address(0), address(0));
address appAddress = AppFactory(getContractDeploymentAddress(CONTRACT_NAME)).create(appNameBytes32, address(0));

console.log("App:", appName);
console.log("Deployed:", appAddress);
Expand Down
50 changes: 0 additions & 50 deletions scripts/core/ConstellationFactory.s.sol

This file was deleted.

29 changes: 0 additions & 29 deletions scripts/tokens/ERC20Constellation.s.sol

This file was deleted.

41 changes: 16 additions & 25 deletions src/factories/Star.sol → src/factories/App.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ pragma solidity ^0.8.16;
import {Ownable} from "@solidstate/contracts/access/ownable/Ownable.sol";
import {MinimalProxyFactory} from "@solidstate/contracts/factory/MinimalProxyFactory.sol";

import {IStar} from "./IStar.sol";
import {IApp} from "./IApp.sol";
import {Proxy} from "../proxy/Proxy.sol";
import {IERC20} from "@solidstate/contracts/interfaces/IERC20.sol";
import {IERC165} from "@solidstate/contracts/interfaces/IERC165.sol";
import {ERC20Base} from "../tokens/ERC20/ERC20Base.sol";

/**
* @title "Star Factory"
* @notice A contract for creating proxy (star) contracts.
* @title "App Factory"
* @notice A contract for creating proxy (app) contracts.
* This contract deploys minimal proxies that point to a Proxy implementation/template
* and is designed to be deployed separately from the registry and managed by Open Format.
*/
contract StarFactory is IStar, MinimalProxyFactory, Ownable {
contract AppFactory is IApp, MinimalProxyFactory, Ownable {
address public template;
address public registry;
address public globals;

// store created stars
mapping(bytes32 => address) public stars; // salt => deployment address
// store created apps
mapping(bytes32 => address) public apps; // salt => deployment address

constructor(address _template, address _registry, address _globals) {
_setOwner(msg.sender);
Expand All @@ -32,44 +32,35 @@ contract StarFactory is IStar, MinimalProxyFactory, Ownable {
}

/**
* @dev _salt param can be thought as the star id
* @dev _salt param can be thought as the app id
*/
function create(bytes32 _name, address _constellation, address _owner) external returns (address id) {
function create(bytes32 _name, address _owner) external returns (address id) {
bytes32 salt = keccak256(abi.encode(_owner, _name));

// check proxy not already deployed
if (stars[salt] != address(0)) {
revert Factory_nameAlreadyUsed();
}

// check _constellation address is a valid ERC20
if (!IERC165(_constellation).supportsInterface(type(IERC20).interfaceId)) {
revert Factory_invalidConstellation();
}

if (!ERC20Base(_constellation).hasRole(bytes32(uint256(0)), msg.sender)) {
revert Factory_notConstellationOwner();
if (apps[salt] != address(0)) {
revert App_nameAlreadyUsed();
}

// deploy new proxy using CREATE2
id = _deployMinimalProxy(template, salt);
stars[salt] = id;
apps[salt] = id;

Proxy(payable(id)).init(_owner, registry, globals);

emit Created(id, _constellation, _owner, string(abi.encodePacked(_name)));
emit Created(id, _owner, string(abi.encodePacked(_name)));
}

/**
* @notice returns the deterministic deployment address for a stsar
* @dev The contract deployed is a minimal proxy pointing to the star template
* @return deploymentAddress the address of the star
* @dev The contract deployed is a minimal proxy pointing to the app template
* @return deploymentAddress the address of the app
*/
function calculateDeploymentAddress(address _account, bytes32 _name) external view returns (address) {
bytes32 salt = keccak256(abi.encode(_account, _name));
// check proxy not already deployed
if (stars[salt] != address(0)) {
revert Factory_nameAlreadyUsed();
if (apps[salt] != address(0)) {
revert App_nameAlreadyUsed();
}

return _calculateMinimalProxyDeploymentAddress(template, salt);
Expand Down
96 changes: 0 additions & 96 deletions src/factories/Constellation.sol

This file was deleted.

8 changes: 8 additions & 0 deletions src/factories/IApp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.16;

interface IApp {
error App_nameAlreadyUsed();

event Created(address id, address owner, string name);
}
11 changes: 0 additions & 11 deletions src/factories/IConstellation.sol

This file was deleted.

10 changes: 0 additions & 10 deletions src/factories/IStar.sol

This file was deleted.

Loading
Loading