Skip to content

Commit

Permalink
fix: reducing code size
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgj94 committed Mar 22, 2024
1 parent f9c6150 commit 6282200
Show file tree
Hide file tree
Showing 22 changed files with 3,015 additions and 129 deletions.
35 changes: 35 additions & 0 deletions broadcast/L2AggVetoing.s.sol/84532/run-1711100006.json

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions broadcast/L2AggVetoing.s.sol/84532/run-1711100012.json

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions broadcast/L2AggVetoing.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions broadcast/OptimisticTokenVotingPlugin.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions broadcast/OptimisticTokenVotingPlugin.s.sol/80001/run-1711102075.json

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions broadcast/OptimisticTokenVotingPlugin.s.sol/80001/run-1711102081.json

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions broadcast/OptimisticTokenVotingPlugin.s.sol/80001/run-1711102453.json

Large diffs are not rendered by default.

1,013 changes: 1,013 additions & 0 deletions broadcast/OptimisticTokenVotingPlugin.s.sol/80001/run-1711102460.json

Large diffs are not rendered by default.

1,013 changes: 1,013 additions & 0 deletions broadcast/OptimisticTokenVotingPlugin.s.sol/80001/run-latest.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions broadcast/VetoToken.s.sol/84532/run-1711099873.json

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions broadcast/VetoToken.s.sol/84532/run-1711099879.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions broadcast/VetoToken.s.sol/84532/run-1711099909.json

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions broadcast/VetoToken.s.sol/84532/run-1711099915.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions broadcast/VetoToken.s.sol/84532/run-1711099976.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions broadcast/VetoToken.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ optimizer-runs = 10_000_000
[rpc_endpoints]
sepolia = "${SEPOLIA_RPC_URL}"
sepolia_base = "${SEPOLIA_BASE_RPC_URL}"
mumbai = "${MUMBAI_RPC_URL}"

[etherscan]
sepolia = { key = "${ETHERSCAN_API_KEY}" }
sepolia_base = { key = "${ETHERSCAN_API_KEY}" }
taiko = "${TAIKO_RPC_URL}"
mumbai = { key = "${ETHERSCAN_API_KEY}" }
4 changes: 2 additions & 2 deletions script/OptimisticTokenVotingPlugin.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract OptimisticTokenVotingPluginScript is Script {
// 2. // 2. Publishing it in the Aragon OSx Protocol
PluginRepo pluginRepo = PluginRepoFactory(pluginRepoFactory)
.createPluginRepoWithFirstVersion(
"optimisticCrosschain1",
"optimistic-crosschain69",
address(pluginSetup),
msg.sender,
"0x00", // TODO: Give these actual values on prod
Expand All @@ -58,7 +58,7 @@ contract OptimisticTokenVotingPluginScript is Script {
DAOFactory.DAOSettings memory daoSettings = DAOFactory.DAOSettings(
address(0),
"",
"optimisticCrosschain1", // This should be changed on each deployment
"optimistic-crosschain69", // This should be changed on each deployment
""
);

Expand Down
12 changes: 0 additions & 12 deletions src/IOptimisticTokenVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ interface IOptimisticTokenVoting {
/// @return The token used for voting.
function getVotingToken() external view returns (IVotesUpgradeable);

/// @notice Returns the veto ratio parameter stored in the optimistic governance settings.
/// @return The veto ratio parameter.
function minVetoRatio() external view returns (uint32);

/// @notice Returns the minimum duration parameter stored in the vetoing settings.
/// @return The minimum duration parameter.
function minDuration() external view returns (uint64);

/// @notice Returns the minimum vetoing power required to create a proposal stored in the vetoing settings.
/// @return The minimum vetoing power required to create a proposal.
function minProposerVotingPower() external view returns (uint256);

/// @notice Creates a new optimistic proposal.
/// @param _metadata The metadata of the proposal.
/// @param _actions The actions that will be executed after the proposal passes.
Expand Down
20 changes: 3 additions & 17 deletions src/OptimisticTokenVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,6 @@ contract OptimisticTokenVotingPlugin is
return proposal_.vetoTally >= proposal_.parameters.minVetoVotingPower;
}

/// @inheritdoc IOptimisticTokenVoting
function minVetoRatio() public view virtual returns (uint32) {
return governanceSettings.minVetoRatio;
}

/// @inheritdoc IOptimisticTokenVoting
function minDuration() public view virtual returns (uint64) {
return governanceSettings.minDuration;
}

/// @inheritdoc IOptimisticTokenVoting
function minProposerVotingPower() public view virtual returns (uint256) {
return governanceSettings.minProposerVotingPower;
}

/// @notice Returns all information for a proposal vote by its ID.
/// @param _proposalId The ID of the proposal.
/// @return open Whether the proposal is open or not.
Expand Down Expand Up @@ -357,7 +342,8 @@ contract OptimisticTokenVotingPlugin is
) external auth(PROPOSER_PERMISSION_ID) returns (uint256 proposalId) {
// Check that either `_msgSender` owns enough tokens or has enough voting power from being a delegatee.
{
uint256 minProposerVotingPower_ = minProposerVotingPower();
uint256 minProposerVotingPower_ = governanceSettings
.minProposerVotingPower;

if (minProposerVotingPower_ != 0) {
// Because of the checks in `OptimisticTokenVotingSetup`, we can assume that `votingToken` is an [ERC-20](https://eips.ethereum.org/EIPS/eip-20) token.
Expand Down Expand Up @@ -406,7 +392,7 @@ contract OptimisticTokenVotingPlugin is
proposal_.parameters.snapshotBlock = snapshotBlock.toUint64();
proposal_.parameters.minVetoVotingPower = _applyRatioCeiled(
totalVotingPower_,
minVetoRatio()
governanceSettings.minVetoRatio
);

// Save gas
Expand Down
37 changes: 24 additions & 13 deletions src/VetoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,39 @@ import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

contract VetoToken is ERC20, ERC20Permit, ERC20Votes {
constructor() ERC20("VetoToken", "VETO") ERC20Permit("VetoToken") {}
constructor() ERC20("VetoToken", "VETO") ERC20Permit("VetoToken") {
mint(msg.sender, 10 ether);
}

// The following functions are overrides required by Solidity.

function _afterTokenTransfer(address from, address to, uint256 amount)
internal
override(ERC20, ERC20Votes)
{
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20, ERC20Votes) {
super._afterTokenTransfer(from, to, amount);
}

function _mint(address to, uint256 amount)
internal
override(ERC20, ERC20Votes)
{
function mint(address to, uint256 amount) public {
_mint(to, amount);
}

function burn(address account, uint256 amount) public {
_burn(account, amount);
}

function _mint(
address to,
uint256 amount
) internal override(ERC20, ERC20Votes) {
super._mint(to, amount);
}

function _burn(address account, uint256 amount)
internal
override(ERC20, ERC20Votes)
{
function _burn(
address account,
uint256 amount
) internal override(ERC20, ERC20Votes) {
super._burn(account, amount);
}
}
84 changes: 0 additions & 84 deletions test/OptimisticTokenVotingPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,6 @@ contract OptimisticTokenVotingPluginTest is Test {
)
)
);
assertEq(
plugin.minVetoRatio(),
uint32(RATIO_BASE / 10),
"Incorrect minVetoRatio"
);
assertEq(plugin.minDuration(), 10 days, "Incorrect minDuration");
assertEq(
plugin.minProposerVotingPower(),
0,
"Incorrect minProposerVotingPower"
);

// Different minVetoRatio
settings.minVetoRatio = uint32(RATIO_BASE / 5);
Expand All @@ -179,11 +168,6 @@ contract OptimisticTokenVotingPluginTest is Test {
)
)
);
assertEq(
plugin.minVetoRatio(),
uint32(RATIO_BASE / 5),
"Incorrect minVetoRatio"
);

// Different minDuration
settings.minDuration = 25 days;
Expand All @@ -199,7 +183,6 @@ contract OptimisticTokenVotingPluginTest is Test {
)
)
);
assertEq(plugin.minDuration(), 25 days, "Incorrect minDuration");

// A token with 10 eth supply
votingToken = ERC20VotesMock(
Expand Down Expand Up @@ -238,11 +221,6 @@ contract OptimisticTokenVotingPluginTest is Test {
)
)
);
assertEq(
plugin.minProposerVotingPower(),
1 ether,
"Incorrect minProposerVotingPower"
);
}

function test_InitializeEmitsEvent() public {
Expand Down Expand Up @@ -374,12 +352,6 @@ contract OptimisticTokenVotingPluginTest is Test {
}

function test_MinVetoRatioReturnsTheRightValue() public {
assertEq(
plugin.minVetoRatio(),
uint32(RATIO_BASE / 10),
"Incorrect minVetoRatio"
);

// New plugin instance
OptimisticTokenVotingPlugin.OptimisticGovernanceSettings
memory settings = OptimisticTokenVotingPlugin
Expand All @@ -401,17 +373,9 @@ contract OptimisticTokenVotingPluginTest is Test {
)
)
);

assertEq(
plugin.minVetoRatio(),
uint32(RATIO_BASE / 5),
"Incorrect minVetoRatio"
);
}

function test_MinDurationReturnsTheRightValue() public {
assertEq(plugin.minDuration(), 10 days, "Incorrect minDuration");

// New plugin instance
OptimisticTokenVotingPlugin.OptimisticGovernanceSettings
memory settings = OptimisticTokenVotingPlugin
Expand All @@ -433,54 +397,6 @@ contract OptimisticTokenVotingPluginTest is Test {
)
)
);

assertEq(plugin.minDuration(), 25 days, "Incorrect minDuration");
}

function test_MinProposerVotingPowerReturnsTheRightValue() public {
assertEq(
plugin.minProposerVotingPower(),
0,
"Incorrect minProposerVotingPower"
);

// New token
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);
votingToken.mint(alice, 10 ether);
vm.roll(block.number + 1);

// Deploy a new plugin instance
OptimisticTokenVotingPlugin.OptimisticGovernanceSettings
memory settings = OptimisticTokenVotingPlugin
.OptimisticGovernanceSettings({
minVetoRatio: uint32(RATIO_BASE / 10),
minDuration: 10 days,
minProposerVotingPower: 1 ether
});

plugin = OptimisticTokenVotingPlugin(
createProxyAndCall(
address(pluginBase),
abi.encodeWithSelector(
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken,
lzAppEndpoint
)
)
);

assertEq(
plugin.minProposerVotingPower(),
1 ether,
"Incorrect minProposerVotingPower"
);
}

function test_TokenHoldersAreMembers() public {
Expand Down

0 comments on commit 6282200

Please sign in to comment.