Skip to content

Commit

Permalink
chore: simplify deployment flow
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Oct 15, 2024
1 parent eb6671b commit 1855b6b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 26 deletions.
10 changes: 6 additions & 4 deletions l1-contracts/src/governance/Gerousia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ contract Gerousia is IGerousia {

uint256 public constant LIFETIME_IN_ROUNDS = 5;

IApella public immutable APELLA;
IRegistry public immutable REGISTRY;
uint256 public immutable N;
uint256 public immutable M;

mapping(address instance => mapping(uint256 roundNumber => RoundAccounting)) public rounds;

constructor(IApella _apella, IRegistry _registry, uint256 _n, uint256 _m) {
APELLA = _apella;
constructor(IRegistry _registry, uint256 _n, uint256 _m) {
REGISTRY = _registry;
N = _n;
M = _m;
Expand Down Expand Up @@ -120,7 +118,7 @@ contract Gerousia is IGerousia {

emit ProposalPushed(round.leader, _roundNumber);

require(APELLA.propose(round.leader), Errors.Gerousia__FailedToPropose(round.leader));
require(getApella().propose(round.leader), Errors.Gerousia__FailedToPropose(round.leader));
return true;
}

Expand Down Expand Up @@ -152,4 +150,8 @@ contract Gerousia is IGerousia {
function computeRound(Slot _slot) public view override(IGerousia) returns (uint256) {
return _slot.unwrap() / M;
}

function getApella() public view override(IGerousia) returns (IApella) {
return IApella(REGISTRY.getApella());
}
}
8 changes: 8 additions & 0 deletions l1-contracts/src/governance/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ contract Registry is IRegistry, Ownable {
return currentSnapshot;
}

/**
* @notice Returns the address of the apella
* @return The apella address
*/
function getApella() external view override(IRegistry) returns (address) {
return owner();
}

/**
* @notice Creates a new snapshot of the registry
*
Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/src/governance/interfaces/IGerousia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.27;

import {Slot} from "@aztec/core/libraries/TimeMath.sol";

import {IApella} from "@aztec/governance/interfaces/IApella.sol";
import {IPayload} from "@aztec/governance/interfaces/IPayload.sol";

interface IGerousia {
Expand All @@ -16,4 +16,5 @@ interface IGerousia {
view
returns (uint256);
function computeRound(Slot _slot) external view returns (uint256);
function getApella() external view returns (IApella);
}
2 changes: 2 additions & 0 deletions l1-contracts/src/governance/interfaces/IRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ interface IRegistry {
// docs:end:registry_number_of_versions

function isRollupRegistered(address _rollup) external view returns (bool);

function getApella() external view returns (address);
}
12 changes: 4 additions & 8 deletions l1-contracts/test/governance/apella/base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ contract ApellaBase is TestBase {
function setUp() public virtual {
token = IMintableERC20(address(new TestERC20()));

// @todo We should be using a bit of create2 magic to do this nicely
apella = new Apella(token, address(0));
registry = new Registry(address(apella));
gerousia = new Gerousia(apella, registry, 677, 1000);
registry = new Registry(address(this));
gerousia = new Gerousia(registry, 677, 1000);

// cheeky breeky
vm.store(address(apella), 0, bytes32(uint256(uint160(address(gerousia)))));

assertEq(apella.gerousia(), address(gerousia));
apella = new Apella(token, address(gerousia));
registry.transferOwnership(address(apella));

{
CallAssetPayload payload = new CallAssetPayload(token, address(apella));
Expand Down
13 changes: 6 additions & 7 deletions l1-contracts/test/governance/gerousia/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {Registry} from "@aztec/governance/Registry.sol";
import {Gerousia} from "@aztec/governance/Gerousia.sol";

import {IPayload} from "@aztec/governance/interfaces/IPayload.sol";
import {IApella} from "@aztec/governance/interfaces/IApella.sol";

contract FakeApella {
address public gerousia;
address immutable GEROUSIA;

mapping(IPayload => bool) public proposals;

function setGerousia(address _gerousia) external {
gerousia = _gerousia;
constructor(address _gerousia) {
GEROUSIA = _gerousia;
}

function propose(IPayload _proposal) external returns (bool) {
Expand All @@ -31,10 +30,10 @@ contract GerousiaBase is Test {

function setUp() public virtual {
registry = new Registry(address(this));
apella = new FakeApella();

gerousia = new Gerousia(IApella(address(apella)), registry, 667, 1000);
gerousia = new Gerousia(registry, 667, 1000);
apella = new FakeApella(address(gerousia));

apella.setGerousia(address(gerousia));
registry.transferOwnership(address(apella));
}
}
9 changes: 3 additions & 6 deletions l1-contracts/test/governance/gerousia/constructor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {Test} from "forge-std/Test.sol";
import {Gerousia} from "@aztec/governance/Gerousia.sol";
import {Errors} from "@aztec/governance/libraries/Errors.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {IApella} from "@aztec/governance/interfaces/IApella.sol";

contract ConstructorTest is Test {
IApella internal constant APELLA = IApella(address(0x01));
IRegistry internal constant REGISTRY = IRegistry(address(0x02));

function test_WhenNIsLessThanOrEqualHalfOfM(uint256 _n, uint256 _m) external {
Expand All @@ -17,7 +15,7 @@ contract ConstructorTest is Test {
uint256 n = bound(_n, 0, _m / 2);

vm.expectRevert(abi.encodeWithSelector(Errors.Gerousia__InvalidNAndMValues.selector, n, _m));
new Gerousia(APELLA, REGISTRY, n, _m);
new Gerousia(REGISTRY, n, _m);
}

function test_WhenNLargerThanM(uint256 _n, uint256 _m) external {
Expand All @@ -26,7 +24,7 @@ contract ConstructorTest is Test {
uint256 n = bound(_n, m + 1, type(uint256).max);

vm.expectRevert(abi.encodeWithSelector(Errors.Gerousia__NCannotBeLargerTHanM.selector, n, m));
new Gerousia(APELLA, REGISTRY, n, m);
new Gerousia(REGISTRY, n, m);
}

function test_WhenNIsGreatherThanHalfOfM(uint256 _n, uint256 _m) external {
Expand All @@ -35,9 +33,8 @@ contract ConstructorTest is Test {
uint256 m = bound(_m, 1, type(uint256).max);
uint256 n = bound(_n, m / 2 + 1, m);

Gerousia g = new Gerousia(APELLA, REGISTRY, n, m);
Gerousia g = new Gerousia(REGISTRY, n, m);

assertEq(address(g.APELLA()), address(APELLA));
assertEq(address(g.REGISTRY()), address(REGISTRY));
assertEq(g.N(), n);
assertEq(g.M(), m);
Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/test/governance/gerousia/pushProposal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract PushProposalTest is GerousiaBase {

modifier givenCanonicalInstanceHoldCode() {
leonidas = new Leonidas(address(this));
vm.prank(registry.getApella());
registry.upgrade(address(leonidas));

// We jump into the future since slot 0, will behave as if already voted in
Expand Down Expand Up @@ -196,6 +197,7 @@ contract PushProposalTest is GerousiaBase {

// When using a new registry we change the gerousia's interpetation of time :O
Leonidas freshInstance = new Leonidas(address(this));
vm.prank(registry.getApella());
registry.upgrade(address(freshInstance));

// The old is still there, just not executable.
Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/test/governance/gerousia/vote.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract VoteTest is GerousiaBase {

modifier givenCanonicalRollupHoldCode() {
leonidas = new Leonidas(address(this));
vm.prank(registry.getApella());
registry.upgrade(address(leonidas));

// We jump into the future since slot 0, will behave as if already voted in
Expand Down Expand Up @@ -129,6 +130,7 @@ contract VoteTest is GerousiaBase {
uint256 yeaBefore = gerousia.yeaCount(address(leonidas), leonidasRound, proposal);

Leonidas freshInstance = new Leonidas(address(this));
vm.prank(registry.getApella());
registry.upgrade(address(freshInstance));

vm.warp(Timestamp.unwrap(freshInstance.getTimestampForSlot(Slot.wrap(1))));
Expand Down

0 comments on commit 1855b6b

Please sign in to comment.