Skip to content

Commit

Permalink
Adding a global setting to skip L2 votes
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Jul 26, 2024
1 parent 18858c3 commit 3743d55
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 44 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DEPLOY_AS_PRODUCTION=true # With false, the script will deploy mock helpers
MIN_VETO_RATIO="300000" # 30%
L2_INACTIVITY_PERIOD="600" # in seconds (10 minutes)
L2_AGGREGATION_GRACE_PERIOD="172800" # in seconds (2 days)
SKIP_L2=true
MIN_STD_PROPOSAL_DELAY="8864000" # in seconds (10 days)
MIN_STD_APPROVALS="5" # How many multisig approvals are required
MIN_EMERGENCY_APPROVALS="10" # How many emergency multisig approvals are required
Expand Down
2 changes: 2 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ contract Deploy is Script {
taikoBridgeAddress: vm.envAddress("TAIKO_BRIDGE_ADDRESS"),
l2InactivityPeriod: uint64(vm.envUint("L2_INACTIVITY_PERIOD")),
l2AggregationGracePeriod: uint64(vm.envUint("L2_AGGREGATION_GRACE_PERIOD")),
skipL2: bool(vm.envBool("SKIP_L2")),
// Voting settings
minVetoRatio: uint32(vm.envUint("MIN_VETO_RATIO")),
minStdProposalDelay: uint64(vm.envUint("MIN_STD_PROPOSAL_DELAY")),
Expand Down Expand Up @@ -127,6 +128,7 @@ contract Deploy is Script {
taikoBridgeAddress: taikoBridgeAddress,
l2InactivityPeriod: uint64(vm.envUint("L2_INACTIVITY_PERIOD")),
l2AggregationGracePeriod: uint64(vm.envUint("L2_AGGREGATION_GRACE_PERIOD")),
skipL2: bool(vm.envBool("SKIP_L2")),
// Voting settings
minVetoRatio: uint32(vm.envUint("MIN_VETO_RATIO")),
minStdProposalDelay: uint64(vm.envUint("MIN_STD_PROPOSAL_DELAY")),
Expand Down
6 changes: 4 additions & 2 deletions src/OptimisticTokenVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contract OptimisticTokenVotingPlugin is
uint64 minDuration;
uint64 l2InactivityPeriod;
uint64 l2AggregationGracePeriod;
bool skipL2;
}

/// @notice A container for proposal-related information.
Expand Down Expand Up @@ -203,7 +204,8 @@ contract OptimisticTokenVotingPlugin is

/// @notice Determines whether the L2 is currently available
function isL2Available() public view returns (bool) {
if (taikoL1.paused()) return false;
if (governanceSettings.skipL2) return false;
else if (taikoL1.paused()) return false;

uint64 _id = taikoL1.slotB().numBlocks;
// No L2 blocks yet
Expand Down Expand Up @@ -342,7 +344,7 @@ contract OptimisticTokenVotingPlugin is
}

// Checks
bool _enableL2 = votingToken.getPastVotes(taikoBridge, snapshotTimestamp) > 0 && isL2Available();
bool _enableL2 = isL2Available() && votingToken.getPastVotes(taikoBridge, snapshotTimestamp) > 0;
if (effectiveVotingPower(snapshotTimestamp, _enableL2) == 0) {
revert NoVotingPower();
}
Expand Down
4 changes: 3 additions & 1 deletion src/factory/TaikoDaoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract TaikoDaoFactory {
address taikoBridgeAddress;
uint64 l2InactivityPeriod;
uint64 l2AggregationGracePeriod;
bool skipL2;
// Voting settings
uint32 minVetoRatio;
uint64 minStdProposalDelay;
Expand Down Expand Up @@ -227,7 +228,8 @@ contract TaikoDaoFactory {
settings.minVetoRatio,
0, // minDuration (the condition contract will enforce it)
settings.l2InactivityPeriod,
settings.l2AggregationGracePeriod
settings.l2AggregationGracePeriod,
settings.skipL2
);

OptimisticTokenVotingPluginSetup.TokenSettings memory existingTokenSettings =
Expand Down
135 changes: 101 additions & 34 deletions test/OptimisticTokenVotingPlugin.t.sol

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions test/OptimisticTokenVotingPluginSetup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
minVetoRatio: uint32(RATIO_BASE / 10),
minDuration: 5 days,
l2InactivityPeriod: 10 minutes,
l2AggregationGracePeriod: 2 days
l2AggregationGracePeriod: 2 days,
skipL2: false
});
tokenSettings = OptimisticTokenVotingPluginSetup.TokenSettings({
addr: address(governanceERC20Base),
Expand Down Expand Up @@ -110,7 +111,8 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
minVetoRatio: uint32(RATIO_BASE / 5),
minDuration: 60 * 60 * 24 * 5,
l2InactivityPeriod: 20 minutes,
l2AggregationGracePeriod: 20 days
l2AggregationGracePeriod: 20 days,
skipL2: false
});
bytes memory output = pluginSetup.encodeInstallationParams(
OptimisticTokenVotingPluginSetup.InstallationParameters(
Expand All @@ -128,6 +130,31 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
bytes memory expected =
hex"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000030d40000000000000000000000000000000000000000000000000000000000006978000000000000000000000000000000000000000000000000000000000000004b000000000000000000000000000000000000000000000000000000000001a5e00000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000066666666000000000000000000000000000000000000000000000000000000005555555500000000000000000000000000000000000000000000000000000000000d2f00000000000000000000000000000000000000000000000000000000123456789000000000000000000000000000000000000000000000000000000023456789010000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
assertEq(output, expected, "Incorrect encoded bytes");

// Custom 2 (skip L2)
votingSettings = OptimisticTokenVotingPlugin.OptimisticGovernanceSettings({
minVetoRatio: uint32(RATIO_BASE / 5),
minDuration: 60 * 60 * 24 * 5,
l2InactivityPeriod: 20 minutes,
l2AggregationGracePeriod: 20 days,
skipL2: true
});
output = pluginSetup.encodeInstallationParams(
OptimisticTokenVotingPluginSetup.InstallationParameters(
votingSettings,
tokenSettings,
mintSettings,
address(taikoL1),
taikoBridge,
stdProposalMinDuration,
stdProposer,
emergencyProposer
)
);

expected =
hex"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000030d40000000000000000000000000000000000000000000000000000000000006978000000000000000000000000000000000000000000000000000000000000004b000000000000000000000000000000000000000000000000000000000001a5e00000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000066666666000000000000000000000000000000000000000000000000000000005555555500000000000000000000000000000000000000000000000000000000000d2f00000000000000000000000000000000000000000000000000000000123456789000000000000000000000000000000000000000000000000000000023456789010000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
assertEq(output, expected, "Incorrect encoded bytes");
}

function test_ShouldEncodeInstallationParams_2() public {
Expand Down Expand Up @@ -208,7 +235,8 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
minVetoRatio: uint32(RATIO_BASE / 4),
minDuration: 10 days,
l2InactivityPeriod: 22 minutes,
l2AggregationGracePeriod: 24 days
l2AggregationGracePeriod: 24 days,
skipL2: false
});
tokenSettings = OptimisticTokenVotingPluginSetup.TokenSettings({
addr: address(governanceWrappedERC20Base),
Expand Down Expand Up @@ -290,7 +318,8 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
minVetoRatio: uint32(RATIO_BASE / 5),
minDuration: 12 days,
l2InactivityPeriod: 44 minutes,
l2AggregationGracePeriod: 45 days
l2AggregationGracePeriod: 45 days,
skipL2: true
});
tokenSettings = OptimisticTokenVotingPluginSetup.TokenSettings({
addr: address(governanceWrappedERC20Base),
Expand Down Expand Up @@ -462,7 +491,8 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
minVetoRatio: uint32(RATIO_BASE / 4),
minDuration: 10 days,
l2InactivityPeriod: 10 minutes,
l2AggregationGracePeriod: 2 days
l2AggregationGracePeriod: 2 days,
skipL2: false
});
tokenSettings = OptimisticTokenVotingPluginSetup.TokenSettings({
addr: address(governanceWrappedERC20Base),
Expand Down Expand Up @@ -558,7 +588,8 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
minVetoRatio: uint32(RATIO_BASE / 4),
minDuration: 10 days,
l2InactivityPeriod: 10 minutes,
l2AggregationGracePeriod: 2 days
l2AggregationGracePeriod: 2 days,
skipL2: false
});
tokenSettings = OptimisticTokenVotingPluginSetup.TokenSettings({
addr: address(0x0),
Expand Down
9 changes: 8 additions & 1 deletion test/helpers/DaoBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contract DaoBuilder is Test {
uint64 public minDuration = 4 days;
uint64 public l2InactivityPeriod = 10 minutes;
uint64 public l2AggregationGracePeriod = 2 days;
bool public skipL2 = false;

bool public onlyListed = true;
uint16 public minApprovals = 1;
Expand Down Expand Up @@ -98,6 +99,11 @@ contract DaoBuilder is Test {
return this;
}

function withSkipL2() public returns (DaoBuilder) {
skipL2 = true;
return this;
}

function withTaikoBridge(address newTaikoBridge) public returns (DaoBuilder) {
taikoBridge = newTaikoBridge;
return this;
Expand Down Expand Up @@ -177,7 +183,8 @@ contract DaoBuilder is Test {
minVetoRatio: minVetoRatio,
minDuration: minDuration,
l2InactivityPeriod: l2InactivityPeriod,
l2AggregationGracePeriod: l2AggregationGracePeriod
l2AggregationGracePeriod: l2AggregationGracePeriod,
skipL2: skipL2
});

optimisticPlugin = OptimisticTokenVotingPlugin(
Expand Down

0 comments on commit 3743d55

Please sign in to comment.