Skip to content

Commit

Permalink
Merge pull request #360 from goran-ethernal/governance/add-new-parameter
Browse files Browse the repository at this point in the history
Add new parameter (`baseFeeChangeDenom`) to `NetworkParams` contract
  • Loading branch information
ZeroEkkusu authored Sep 1, 2023
2 parents b6e631f + be03196 commit 2bec973
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
19 changes: 18 additions & 1 deletion contracts/child/NetworkParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract NetworkParams is Ownable2Step, Initializable {
uint256 newVotingDelay; // in blocks
uint256 newVotingPeriod; // in blocks
uint256 newProposalThreshold; // in percent
uint256 newBaseFeeChangeDenom; // in wei
}

uint256 public checkpointBlockInterval; // in blocks
Expand All @@ -39,6 +40,7 @@ contract NetworkParams is Ownable2Step, Initializable {
uint256 public votingDelay; // in blocks
uint256 public votingPeriod; // in blocks
uint256 public proposalThreshold; // in percent
uint256 public baseFeeChangeDenom; // in wei

event NewCheckpointBlockInterval(uint256 indexed checkpointInterval);
event NewEpochSize(uint256 indexed size);
Expand All @@ -52,6 +54,7 @@ contract NetworkParams is Ownable2Step, Initializable {
event NewVotingDelay(uint256 indexed votingDelay);
event NewVotingPeriod(uint256 indexed votingPeriod);
event NewProposalThreshold(uint256 indexed proposalThreshold);
event NewBaseFeeChangeDenom(uint256 indexed baseFeeChangeDenom);

/**
* @notice initializer for NetworkParams, sets the initial set of values for the network
Expand All @@ -70,7 +73,8 @@ contract NetworkParams is Ownable2Step, Initializable {
initParams.newWithdrawalWaitPeriod != 0 &&
initParams.newBlockTime != 0 &&
initParams.newBlockTimeDrift != 0 &&
initParams.newVotingPeriod != 0,
initParams.newVotingPeriod != 0 &&
initParams.newBaseFeeChangeDenom != 0,
"NetworkParams: INVALID_INPUT"
);
checkpointBlockInterval = initParams.newCheckpointBlockInterval;
Expand All @@ -85,6 +89,7 @@ contract NetworkParams is Ownable2Step, Initializable {
votingDelay = initParams.newVotingDelay;
votingPeriod = initParams.newVotingPeriod;
proposalThreshold = initParams.newProposalThreshold;
baseFeeChangeDenom = initParams.newBaseFeeChangeDenom;
_transferOwnership(initParams.newOwner);
}

Expand Down Expand Up @@ -231,4 +236,16 @@ contract NetworkParams is Ownable2Step, Initializable {

emit NewProposalThreshold(newProposalThreshold);
}

/**
* @notice function to set new base fee change denominator
* @dev disallows setting of a zero value for sanity check purposes
* @param newBaseFeeChangeDenom new base fee change denominator
*/
function setNewBaseFeeChangeDenom(uint256 newBaseFeeChangeDenom) external onlyOwner {
require(newBaseFeeChangeDenom != 0, "NetworkParams: INVALID_BASE_FEE_CHANGE_DENOM");
baseFeeChangeDenom = newBaseFeeChangeDenom;

emit NewBaseFeeChangeDenom(newBaseFeeChangeDenom);
}
}
49 changes: 49 additions & 0 deletions docs/child/NetworkParams.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ function acceptOwnership() external nonpayable
*The new owner accepts the ownership transfer.*


### baseFeeChangeDenom

```solidity
function baseFeeChangeDenom() external view returns (uint256)
```






#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

### blockTime

```solidity
Expand Down Expand Up @@ -218,6 +235,22 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*


### setNewBaseFeeChangeDenom

```solidity
function setNewBaseFeeChangeDenom(uint256 newBaseFeeChangeDenom) external nonpayable
```

function to set new base fee change denominator

*disallows setting of a zero value for sanity check purposes*

#### Parameters

| Name | Type | Description |
|---|---|---|
| newBaseFeeChangeDenom | uint256 | new base fee change denominator |

### setNewBlockTime

```solidity
Expand Down Expand Up @@ -514,6 +547,22 @@ event Initialized(uint8 version)
|---|---|---|
| version | uint8 | undefined |

### NewBaseFeeChangeDenom

```solidity
event NewBaseFeeChangeDenom(uint256 indexed baseFeeChangeDenom)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| baseFeeChangeDenom `indexed` | uint256 | undefined |

### NewBlockTime

```solidity
Expand Down
25 changes: 25 additions & 0 deletions test/child/NetworkParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("NetworkParams", () => {
newVotingDelay: 0,
newVotingPeriod: 0,
newProposalThreshold: 0,
newBaseFeeChangeDenom: 0,
};
});

Expand All @@ -49,6 +50,7 @@ describe("NetworkParams", () => {
initParams.newVotingDelay = 2 ** Math.floor(Math.random() * 5 + 10);
initParams.newVotingPeriod = 2 ** Math.floor(Math.random() * 5 + 10);
initParams.newProposalThreshold = Math.floor(Math.random() * 100 + 1);
initParams.newBaseFeeChangeDenom = ethers.utils.parseUnits(String(Math.floor(Math.random() * 20 + 1)));

await networkParams.initialize(initParams);

Expand All @@ -65,6 +67,7 @@ describe("NetworkParams", () => {
expect(await networkParams.votingDelay()).to.equal(initParams.newVotingDelay);
expect(await networkParams.votingPeriod()).to.equal(initParams.newVotingPeriod);
expect(await networkParams.proposalThreshold()).to.equal(initParams.newProposalThreshold);
expect(await networkParams.baseFeeChangeDenom()).to.equal(initParams.newBaseFeeChangeDenom);
});

it("should throw error on reinitialization", async () => {
Expand Down Expand Up @@ -313,4 +316,26 @@ describe("NetworkParams", () => {

expect(await networkParams.proposalThreshold()).to.equal(initParams.newProposalThreshold);
});

it("set new base fee change denom fail: only owner", async () => {
await impersonateAccount(accounts[1].address);
await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
const newNetworkParams = networkParams.connect(accounts[1]);

await expect(newNetworkParams.setNewBaseFeeChangeDenom(1)).to.be.revertedWith("Ownable: caller is not the owner");
await stopImpersonatingAccount(accounts[1].address);
});

it("set new base fee change denom fail: invalid input", async () => {
await expect(networkParams.setNewBaseFeeChangeDenom(0)).to.be.revertedWith(
"NetworkParams: INVALID_BASE_FEE_CHANGE_DENOM"
);
});

it("set new base fee change denom success", async () => {
initParams.newBaseFeeChangeDenom = ethers.utils.parseUnits(String(Math.floor(Math.random() * 20 + 11)));
await networkParams.setNewBaseFeeChangeDenom(initParams.newBaseFeeChangeDenom);

expect(await networkParams.baseFeeChangeDenom()).to.equal(initParams.newBaseFeeChangeDenom);
});
});
2 changes: 1 addition & 1 deletion test/forge/child/validator/RewardPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract Uninitialized is Test {

function setUp() public virtual {
networkParams = new NetworkParams();
networkParams.initialize(NetworkParams.InitParams(address(1), 1, 64, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1));
networkParams.initialize(NetworkParams.InitParams(address(1), 1, 64, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1));

token = new MockERC20();
validatorSet = new ValidatorSet();
Expand Down
2 changes: 1 addition & 1 deletion test/forge/child/validator/ValidatorSet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract contract Uninitialized is Test {
function setUp() public virtual {
networkParams = new NetworkParams();
networkParams.initialize(
NetworkParams.InitParams(address(1), 1, epochSize, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1)
NetworkParams.InitParams(address(1), 1, epochSize, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
);

stateSender = new L2StateSender();
Expand Down
Empty file.

0 comments on commit 2bec973

Please sign in to comment.