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

Gas Benchmark #3

Merged
merged 6 commits into from
Feb 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -29,4 +29,4 @@ jobs:

- name: test
run: |
forge test --match-contract MIPM17IntegrationTest --fork-url https://rpc.api.moonbeam.network
forge test --match-contract MIPM17IntegrationTest --fork-url https://rpc.api.moonbeam.network -vvv
4 changes: 2 additions & 2 deletions src/MErc20DelegateFixer.sol
Expand Up @@ -104,10 +104,10 @@ contract MErc20DelegateFixer is MErc20Delegate {
);

/// zero out the user's tokens
accountTokens[user] = 0;
delete accountTokens[user];
}

emit UserFixed(user, liquidator, accountTokens[liquidator]);
emit UserFixed(user, liquidator, liquidated);
}

/// @notice zero the balance of a user
Expand Down
28 changes: 22 additions & 6 deletions src/proposals/mips/mip-m17/mip-m17.sol
Expand Up @@ -106,7 +106,11 @@ contract mipm17 is Governor {
IMErc20Delegator mFRAXDelegator = IMErc20Delegator(mFRAXAddress);

for (uint256 i = 0; i < mFRAXDebtors.length; i++) {
if (mFRAXDelegator.balanceOf(mFRAXDebtors[i].addr) > 0) {
if (
mFRAXDelegator.borrowBalanceStored(mFRAXDebtors[i].addr) >
0 ||
mFRAXDelegator.balanceOf(mFRAXDebtors[i].addr) != 0
) {
_pushAction(
mFRAXAddress,
abi.encodeWithSignature(
Expand Down Expand Up @@ -136,7 +140,11 @@ contract mipm17 is Governor {
IMErc20Delegator mxcDOTDelegator = IMErc20Delegator(mxcDOTAddress);

for (uint256 i = 0; i < mxcDOTDebtors.length; i++) {
if (mxcDOTDelegator.balanceOf(mxcDOTDebtors[i].addr) > 0) {
if (
mxcDOTDelegator.borrowBalanceStored(mxcDOTDebtors[i].addr) >
0 ||
mxcDOTDelegator.balanceOf(mxcDOTDebtors[i].addr) != 0
) {
_pushAction(
mxcDOTAddress,
abi.encodeWithSignature(
Expand All @@ -149,6 +157,7 @@ contract mipm17 is Governor {
}
}
}

address mUSDCAddress = addresses.getAddress("MOONWELL_mUSDC");
address mETHAddress = addresses.getAddress("MOONWELL_mETH");
address mwBTCAddress = addresses.getAddress("MOONWELL_mwBTC");
Expand Down Expand Up @@ -215,15 +224,11 @@ contract mipm17 is Governor {
/// @dev set debug
// setDebug(true);

uint256 gas_start = gasleft();
simulateActions(
addresses.getAddress("ARTEMIS_GOVERNOR"),
addresses.getAddress("WELL"),
address(this)
);
uint256 gas_used = gas_start - gasleft();

emit log_named_uint("Gas Metering", gas_used);
}

function _validate(Addresses addresses, address) internal override {
Expand All @@ -247,6 +252,7 @@ contract mipm17 is Governor {
IMErc20Delegator mErc20DelegatorxcDot = IMErc20Delegator(
addresses.getAddress("MOONWELL_mxcDOT")
);

for (uint256 i = 0; i < debtors.length; i++) {
(uint256 err, , ) = comptroller.getAccountLiquidity(
debtors[i].addr
Expand All @@ -262,6 +268,11 @@ contract mipm17 is Governor {
)
)
);
assertEq(
mErc20Delegator.borrowBalanceStored(debtors[i].addr),
0,
"mfrax borrow balance after seizing not zero"
);
assertEq(
mErc20Delegator.balanceOf(debtors[i].addr),
0,
Expand Down Expand Up @@ -289,6 +300,11 @@ contract mipm17 is Governor {
);
for (uint256 i = 0; i < debtors.length; i++) {
assertEq(mErc20Delegator.balanceOf(debtors[i].addr), 0);
assertEq(
mErc20Delegator.borrowBalanceStored(debtors[i].addr),
0,
"mxcDOT borrow balance after seizing not zero"
);
}
}

Expand Down
46 changes: 36 additions & 10 deletions test/integration/helpers/Governor.sol
Expand Up @@ -5,9 +5,7 @@ import "@forge-std/console.sol";
import {Address} from "@utils/Address.sol";
import {IVotes} from "@openzeppelin/governance/utils/IVotes.sol";
import {GovernorBravoDelegate} from "@comp-governance/GovernorBravoDelegate.sol";
import {
TimelockInterface, GovernorBravoDelegateStorageV1 as Bravo
} from "@comp-governance/GovernorBravoInterfaces.sol";
import {TimelockInterface, GovernorBravoDelegateStorageV1 as Bravo} from "@comp-governance/GovernorBravoInterfaces.sol";

import {GovernorBravoProposal} from "@forge-proposal-simulator/proposals/GovernorBravoProposal.sol";

Expand All @@ -18,14 +16,20 @@ contract Governor is GovernorBravoProposal {
/// @param governorAddress address of the Governor Bravo Delegator contract
/// @param governanceToken address of the governance token of the system
/// @param proposerAddress address of the proposer
function simulateActions(address governorAddress, address governanceToken, address proposerAddress) internal {
function simulateActions(
address governorAddress,
address governanceToken,
address proposerAddress
) internal {
GovernorBravoDelegate governor = GovernorBravoDelegate(governorAddress);

{
// Ensure proposer has meets minimum proposal threshold and quorum votes to pass the proposal
uint256 quorumVotes = governor.quorumVotes();
uint256 proposalThreshold = governor.proposalThreshold();
uint256 votingPower = quorumVotes > proposalThreshold ? quorumVotes : proposalThreshold;
uint256 votingPower = quorumVotes > proposalThreshold
? quorumVotes
: proposalThreshold;
deal(governanceToken, proposerAddress, votingPower);
// Delegate proposer's votes to itself
vm.prank(proposerAddress);
Expand All @@ -36,12 +40,25 @@ contract Governor is GovernorBravoProposal {
bytes memory proposeCalldata = getProposeCalldata();

// Register the proposal
vm.prank(proposerAddress);
bytes memory data = address(payable(governorAddress)).functionCall(proposeCalldata);
bytes memory data;
{
// Execute the proposal
uint256 gas_start = gasleft();
vm.prank(proposerAddress);
data = address(payable(governorAddress)).functionCall(
proposeCalldata
);

emit log_named_uint("Propose Gas Metering", gas_start - gasleft());
}
uint256 proposalId = abi.decode(data, (uint256));

if (DEBUG) {
console.log("schedule batch calldata with ", actions.length, (actions.length > 1 ? "actions" : "action"));
console.log(
"schedule batch calldata with ",
actions.length,
(actions.length > 1 ? "actions" : "action")
);

if (data.length > 0) {
console.log("proposalId: %s", proposalId);
Expand Down Expand Up @@ -73,8 +90,17 @@ contract Governor is GovernorBravoProposal {
TimelockInterface timelock = TimelockInterface(governor.timelock());
vm.warp(block.timestamp + timelock.delay());

// Execute the proposal
governor.execute(proposalId);
{
// Execute the proposal
uint256 gas_start = gasleft();
governor.execute(proposalId);

emit log_named_uint(
"Execution Gas Metering",
gas_start - gasleft()
);
}

require(governor.state(proposalId) == Bravo.ProposalState.Executed);
}
}