Skip to content

Commit

Permalink
Make fee vaults upgradeable (#821)
Browse files Browse the repository at this point in the history
* Contract updates to make fee vaults upgradeable & removes Ownable

* Deploy fee vaults to genesis
  • Loading branch information
okkothejawa authored Jun 28, 2024
1 parent b3fb9fc commit 07fd364
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 100 deletions.
41 changes: 0 additions & 41 deletions crates/evm/src/evm/system_contracts/lib/Ownable.sol

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "../lib/Ownable.sol";
import "./interfaces/IBitcoinLightClient.sol";
import "bitcoin-spv/solidity/contracts/ValidateSPV.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
Expand Down
11 changes: 8 additions & 3 deletions crates/evm/src/evm/system_contracts/src/FeeVault.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "../lib/Ownable.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
import "openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol";

/// @title Fee accumulator contract template
/// @author Citrea

abstract contract FeeVault is Ownable {
abstract contract FeeVault is UUPSUpgradeable, Ownable2StepUpgradeable {
address public recipient;
uint256 public minWithdraw = 0.5 ether;
uint256 public minWithdraw;

uint256[50] private __gap;

event RecipientUpdated(address oldRecipient, address newRecipient);
event MinWithdrawUpdated(uint256 oldMinWithdraw, uint256 newMinWithdraw);
Expand Down Expand Up @@ -37,4 +40,6 @@ abstract contract FeeVault is Ownable {
minWithdraw = _minWithdraw;
emit MinWithdrawUpdated(oldMinWithdraw, _minWithdraw);
}

function _authorizeUpgrade(address) internal override onlyOwner {}
}
15 changes: 14 additions & 1 deletion crates/evm/src/evm/system_contracts/test/BaseFeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ pragma solidity ^0.8.13;

import "./FeeVault.t.sol";
import "../src/BaseFeeVault.sol";
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";


contract BaseFeeVaultTest is FeeVaultTest {
function setUp() public {
feeVault = new BaseFeeVault();
feeVault = BaseFeeVault(payable(address(0x3100000000000000000000000000000000000003)));
address baseFeeVaultImpl = address(new BaseFeeVault());
address erc1967Impl = address(new ERC1967Proxy(baseFeeVaultImpl, ""));
vm.etch(address(feeVault), erc1967Impl.code);
bytes32 IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
bytes32 OWNER_SLOT = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
bytes32 RECIPIENT_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000000;
bytes32 MIN_WITHDRAW_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000001;
vm.store(address(feeVault), IMPLEMENTATION_SLOT, bytes32(uint256(uint160(baseFeeVaultImpl))));
vm.store(address(feeVault), OWNER_SLOT, bytes32(uint256(uint160(owner))));
vm.store(address(feeVault), RECIPIENT_SLOT, bytes32(uint256(uint160(recipient))));
vm.store(address(feeVault), MIN_WITHDRAW_SLOT, bytes32(uint256(0.5 ether)));
}
}
16 changes: 10 additions & 6 deletions crates/evm/src/evm/system_contracts/test/FeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,45 @@ import "forge-std/console.sol";
import "../src/FeeVault.sol";
abstract contract FeeVaultTest is Test {
FeeVault feeVault;
address owner = makeAddr("citrea_owner");
address recipient = makeAddr("citrea_recipient");

function testWithdraw() public {
vm.deal(address(feeVault), 1 ether);
address recipient = vm.addr(0x1234);
feeVault.setRecipient(recipient);
vm.prank(owner);
feeVault.withdraw();
assertEq(address(recipient).balance, 1 ether);
}

function testCannotWithdrawLessThanMinWithdraw() public {
vm.deal(address(feeVault), 0.1 ether);
address recipient = vm.addr(0x1234);
feeVault.setRecipient(recipient);
vm.startPrank(owner);
vm.expectRevert("Withdrawal amount must be greater than minimum withdraw amount");
feeVault.withdraw();
}

function testSetRecipient() public {
vm.prank(owner);
feeVault.setRecipient(address(this));
assertEq(feeVault.recipient(), address(this));
}

function testSetMinWithdraw() public {
vm.prank(owner);
feeVault.setMinWithdraw(1.7 ether);
assertEq(feeVault.minWithdraw(), 1.7 ether);
}

function testCanChangeOwnerAndSetState() public {
vm.startPrank(owner);
feeVault.setRecipient(address(this));
feeVault.setMinWithdraw(1.7 ether);
assertEq(feeVault.recipient(), address(this));
assertEq(feeVault.minWithdraw(), 1.7 ether);

address newOwner = vm.addr(0x1234);
feeVault.transferOwnership(newOwner);
vm.stopPrank();
vm.startPrank(newOwner);
feeVault.acceptOwnership();
feeVault.setRecipient(address(1));
Expand All @@ -53,9 +57,9 @@ abstract contract FeeVaultTest is Test {
function testNonOwnerCannotChangeState() public {
address nonOwner = vm.addr(0x1234);
vm.startPrank(nonOwner);
vm.expectRevert("Caller is not owner");
vm.expectRevert();
feeVault.setRecipient(address(1));
vm.expectRevert("Caller is not owner");
vm.expectRevert();
feeVault.setMinWithdraw(0.3 ether);
}
}
15 changes: 14 additions & 1 deletion crates/evm/src/evm/system_contracts/test/L1FeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ pragma solidity ^0.8.13;

import "./FeeVault.t.sol";
import "../src/L1FeeVault.sol";
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";


contract L1FeeVaultTest is FeeVaultTest {
function setUp() public {
feeVault = new L1FeeVault();
feeVault = L1FeeVault(payable(address(0x3100000000000000000000000000000000000004)));
address l1FeeVaultImpl = address(new L1FeeVault());
address erc1967Impl = address(new ERC1967Proxy(l1FeeVaultImpl, ""));
vm.etch(address(feeVault), erc1967Impl.code);
bytes32 IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
bytes32 OWNER_SLOT = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
bytes32 RECIPIENT_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000000;
bytes32 MIN_WITHDRAW_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000001;
vm.store(address(feeVault), IMPLEMENTATION_SLOT, bytes32(uint256(uint160(l1FeeVaultImpl))));
vm.store(address(feeVault), OWNER_SLOT, bytes32(uint256(uint160(owner))));
vm.store(address(feeVault), RECIPIENT_SLOT, bytes32(uint256(uint160(recipient))));
vm.store(address(feeVault), MIN_WITHDRAW_SLOT, bytes32(uint256(0.5 ether)));
}
}
46 changes: 0 additions & 46 deletions crates/evm/src/evm/system_contracts/test/Ownable.t.sol

This file was deleted.

15 changes: 14 additions & 1 deletion crates/evm/src/evm/system_contracts/test/PriorityFeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ pragma solidity ^0.8.13;

import "./FeeVault.t.sol";
import "../src/PriorityFeeVault.sol";
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";


contract PriorityFeeVaultTest is FeeVaultTest {
function setUp() public {
feeVault = new PriorityFeeVault();
feeVault = PriorityFeeVault(payable(address(0x3100000000000000000000000000000000000005)));
address priorityFeeVaultImpl = address(new PriorityFeeVault());
address erc1967Impl = address(new ERC1967Proxy(priorityFeeVaultImpl, ""));
vm.etch(address(feeVault), erc1967Impl.code);
bytes32 IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
bytes32 OWNER_SLOT = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
bytes32 RECIPIENT_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000000;
bytes32 MIN_WITHDRAW_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000001;
vm.store(address(feeVault), IMPLEMENTATION_SLOT, bytes32(uint256(uint160(priorityFeeVaultImpl))));
vm.store(address(feeVault), OWNER_SLOT, bytes32(uint256(uint160(owner))));
vm.store(address(feeVault), RECIPIENT_SLOT, bytes32(uint256(uint160(recipient))));
vm.store(address(feeVault), MIN_WITHDRAW_SLOT, bytes32(uint256(0.5 ether)));
}
}
51 changes: 51 additions & 0 deletions resources/genesis/bitcoin-regtest/evm.json

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions resources/genesis/mock/evm.json

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions resources/test-data/demo-tests/bitcoin-regtest/evm.json

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions resources/test-data/demo-tests/mock/evm.json

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions resources/test-data/integration-tests-low-block-gas-limit/evm.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions resources/test-data/integration-tests/evm.json

Large diffs are not rendered by default.

0 comments on commit 07fd364

Please sign in to comment.