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

feat: ownable sysstia #9398

Merged
merged 2 commits into from
Oct 25, 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
16 changes: 11 additions & 5 deletions l1-contracts/src/governance/Sysstia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {ISysstia} from "@aztec/governance/interfaces/ISysstia.sol";

import {Errors} from "@aztec/governance/libraries/Errors.sol";
import {Ownable} from "@oz/access/Ownable.sol";

contract Sysstia is ISysstia {
contract Sysstia is ISysstia, Ownable {
using SafeERC20 for IERC20;

// This value is pulled out my ass. Don't take it seriously
uint256 public constant BLOCK_REWARD = 50e18;

IERC20 public immutable ASSET;
IRegistry public immutable REGISTRY;
IRegistry public registry;

constructor(IERC20 _asset, IRegistry _registry) {
constructor(IERC20 _asset, IRegistry _registry, address _owner) Ownable(_owner) {
ASSET = _asset;
REGISTRY = _registry;
registry = _registry;
}

function updateRegistry(IRegistry _registry) external onlyOwner {
registry = _registry;
emit RegistryUpdated(_registry);
}

/**
Expand All @@ -48,6 +54,6 @@ contract Sysstia is ISysstia {
}

function canonicalRollup() public view returns (address) {
return REGISTRY.getRollup();
return registry.getRollup();
}
}
5 changes: 5 additions & 0 deletions l1-contracts/src/governance/interfaces/ISysstia.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.27;

import {IRegistry} from "./IRegistry.sol";

interface ISysstia {
event RegistryUpdated(IRegistry indexed registry);

function updateRegistry(IRegistry _registry) external;
function claim(address _to) external returns (uint256);
function canonicalRollup() external view returns (address);
}
2 changes: 1 addition & 1 deletion l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ contract RollupTest is DecoderBase {
);
testERC20.mint(address(feeJuicePortal), Constants.FEE_JUICE_INITIAL_MINT);
feeJuicePortal.initialize();
sysstia = new Sysstia(testERC20, registry);
sysstia = new Sysstia(testERC20, registry, address(this));
testERC20.mint(address(sysstia), 1e6 ether);

rollup =
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/fee_portal/depositToAztecPublic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract DepositToAztecPublic is Test {

token.mint(address(feeJuicePortal), Constants.FEE_JUICE_INITIAL_MINT);
feeJuicePortal.initialize();
sysstia = new Sysstia(token, registry);
sysstia = new Sysstia(token, registry, address(this));
rollup =
new Rollup(feeJuicePortal, sysstia, bytes32(0), bytes32(0), address(this), new address[](0));

Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/fee_portal/distributeFees.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract DistributeFees is Test {
token.mint(address(feeJuicePortal), Constants.FEE_JUICE_INITIAL_MINT);
feeJuicePortal.initialize();

sysstia = new Sysstia(token, registry);
sysstia = new Sysstia(token, registry, address(this));
rollup =
new Rollup(feeJuicePortal, sysstia, bytes32(0), bytes32(0), address(this), new address[](0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract UpgradeGerousiaTest is TestBase {
initialValidators[i - 1] = validator;
}

Sysstia sysstia = new Sysstia(token, registry);
Sysstia sysstia = new Sysstia(token, registry, address(this));
rollup = new Rollup(
new MockFeeJuicePortal(), sysstia, bytes32(0), bytes32(0), address(this), initialValidators
);
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/governance/sysstia/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ contract SysstiaBase is Test {
function setUp() public {
token = IMintableERC20(address(new TestERC20()));
registry = new Registry(address(this));
sysstia = new Sysstia(token, registry);
sysstia = new Sysstia(token, registry, address(this));
}
}
43 changes: 43 additions & 0 deletions l1-contracts/test/governance/sysstia/updateRegistry.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.27;

import {SysstiaBase} from "./Base.t.sol";
import {Ownable} from "@oz/access/Ownable.sol";

import {Registry} from "@aztec/governance/Registry.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {ISysstia} from "@aztec/governance/interfaces/ISysstia.sol";

contract UpdateRegistryTest is SysstiaBase {
address internal caller;

function test_WhenCallerIsNotOwner(address _caller) external {
// it reverts
vm.assume(_caller != sysstia.owner());

vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, _caller));
vm.prank(_caller);
sysstia.updateRegistry(IRegistry(address(0xdead)));
}

function test_WhenCallerIsOwner() external {
// it updates the registry
// it emits a {RegistryUpdated} event

Registry registry = new Registry(address(this));
registry.upgrade(address(0xbeef));

IRegistry oldRegistry = sysstia.registry();
address oldCanonical = sysstia.canonicalRollup();

vm.prank(sysstia.owner());
vm.expectEmit(true, true, false, true, address(sysstia));
emit ISysstia.RegistryUpdated(registry);
sysstia.updateRegistry(registry);

assertEq(address(sysstia.registry()), address(registry));
assertNotEq(address(oldRegistry), address(registry));
assertEq(sysstia.canonicalRollup(), address(0xbeef));
assertNotEq(oldCanonical, address(0xbeef));
}
}
6 changes: 6 additions & 0 deletions l1-contracts/test/governance/sysstia/updateRegistry.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UpdateRegistryTest
├── when caller is not owner
│ └── it reverts
└── when caller is owner
├── it updates the registry
└── it emits a {RegistryUpdated} event
2 changes: 1 addition & 1 deletion l1-contracts/test/portals/TokenPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract TokenPortalTest is Test {
function setUp() public {
registry = new Registry(address(this));
testERC20 = new TestERC20();
sysstia = new Sysstia(testERC20, registry);
sysstia = new Sysstia(testERC20, registry, address(this));
rollup = new Rollup(
new MockFeeJuicePortal(), sysstia, bytes32(0), bytes32(0), address(this), new address[](0)
);
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/portals/UniswapPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract UniswapPortalTest is Test {
vm.selectFork(forkId);

registry = new Registry(address(this));
Sysstia sysstia = new Sysstia(DAI, registry);
Sysstia sysstia = new Sysstia(DAI, registry, address(this));
rollup = new Rollup(
new MockFeeJuicePortal(), sysstia, bytes32(0), bytes32(0), address(this), new address[](0)
);
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/sparta/Sparta.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ contract SpartaTest is DecoderBase {

testERC20 = new TestERC20();
Registry registry = new Registry(address(this));
sysstia = new Sysstia(testERC20, registry);
sysstia = new Sysstia(testERC20, registry, address(this));
rollup = new Rollup(
new MockFeeJuicePortal(), sysstia, bytes32(0), bytes32(0), address(this), initialValidators
);
Expand Down
27 changes: 14 additions & 13 deletions yarn-project/ethereum/src/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,6 @@ export const deployL1Contracts = async (
const feeJuiceAddress = await govDeployer.deploy(l1Artifacts.feeJuice);
logger.info(`Deployed Fee Juice at ${feeJuiceAddress}`);

const nomismatokopioAddress = await govDeployer.deploy(l1Artifacts.nomismatokopio, [
feeJuiceAddress.toString(),
1n * 10n ** 18n, // @todo #8084
account.address.toString(),
]);
logger.info(`Deployed Nomismatokopio at ${nomismatokopioAddress}`);

const sysstiaAddress = await govDeployer.deploy(l1Artifacts.sysstia, [
feeJuiceAddress.toString(),
registryAddress.toString(),
]);
logger.info(`Deployed Sysstia at ${sysstiaAddress}`);

// @todo #8084
// @note These numbers are just chosen to make testing simple.
const quorumSize = 6n;
Expand All @@ -345,6 +332,20 @@ export const deployL1Contracts = async (
]);
logger.info(`Deployed Apella at ${apellaAddress}`);

const nomismatokopioAddress = await govDeployer.deploy(l1Artifacts.nomismatokopio, [
feeJuiceAddress.toString(),
1n * 10n ** 18n, // @todo #8084
apellaAddress.toString(),
]);
logger.info(`Deployed Nomismatokopio at ${nomismatokopioAddress}`);

const sysstiaAddress = await govDeployer.deploy(l1Artifacts.sysstia, [
feeJuiceAddress.toString(),
registryAddress.toString(),
apellaAddress.toString(),
]);
logger.info(`Deployed Sysstia at ${sysstiaAddress}`);

await govDeployer.waitForDeployments();
logger.info(`All governance contracts deployed`);

Expand Down
Loading