Skip to content

Commit

Permalink
refactor: introduce TransparentProxy in favor of StakeManagerProxy
Browse files Browse the repository at this point in the history
We use `IStakeManagerProxy` to ensure instances of `TransparentProxy`
are stake managers where necessary.
  • Loading branch information
0x-r4bbit committed Feb 3, 2025
1 parent a22da25 commit a47d46d
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 72 deletions.
285 changes: 223 additions & 62 deletions .gas-report

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ IntegrationTest:testStakeFoo() (gas: 1218594)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 6214173)
LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 297675)
LeaveTest:test_TrustNewStakeManager() (gas: 6269901)
LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1002, μ: 344783, ~: 344801)
LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1000, μ: 344783, ~: 344801)
LockTest:test_LockFailsWithNoStake() (gas: 102637)
LockTest:test_LockFailsWithZero() (gas: 315022)
LockTest:test_LockWithoutPriorLock() (gas: 393335)
Expand Down
7 changes: 5 additions & 2 deletions script/DeployRewardsStreamerMP.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity ^0.8.26;

import { BaseScript } from "./Base.s.sol";
import { DeploymentConfig } from "./DeploymentConfig.s.sol";
import { TransparentProxy } from "../src/TransparentProxy.sol";
import { IStakeManagerProxy } from "../src/interfaces/IStakeManagerProxy.sol";
import { StakeManagerProxy } from "../src/StakeManagerProxy.sol";
import { RewardsStreamerMP } from "../src/RewardsStreamerMP.sol";
import { StakeVault } from "../src/StakeVault.sol";

Expand All @@ -16,8 +16,11 @@ contract DeployRewardsStreamerMPScript is BaseScript {
bytes memory initializeData = abi.encodeCall(RewardsStreamerMP.initialize, (deployer, stakingToken));

vm.startBroadcast(deployer);

// Deploy RewardsStreamerMP logic contract
address impl = address(new RewardsStreamerMP());
address proxy = address(new StakeManagerProxy(impl, initializeData));
// Create upgradeable proxy
address proxy = address(new TransparentProxy(impl, initializeData));
vm.stopBroadcast();

RewardsStreamerMP stakeManager = RewardsStreamerMP(proxy);
Expand Down
2 changes: 1 addition & 1 deletion src/StakeManagerProxy.sol → src/TransparentProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.26;

import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract StakeManagerProxy is ERC1967Proxy {
contract TransparentProxy is ERC1967Proxy {
constructor(address _implementation, bytes memory _data) ERC1967Proxy(_implementation, _data) { }

function implementation() external view returns (address) {
Expand Down
5 changes: 2 additions & 3 deletions src/interfaces/IStakeManagerProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.26;

import { IStakeManager } from "./IStakeManager.sol";
import { ITransparentProxy } from "./ITransparentProxy.sol";

interface IStakeManagerProxy is IStakeManager {
function implementation() external view returns (address);
}
interface IStakeManagerProxy is IStakeManager, ITransparentProxy { }

Check warning on line 7 in src/interfaces/IStakeManagerProxy.sol

View workflow job for this annotation

GitHub Actions / lint

Code contains empty blocks
6 changes: 6 additions & 0 deletions src/interfaces/ITransparentProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

interface ITransparentProxy {
function implementation() external view returns (address);
}
1 change: 0 additions & 1 deletion test/RewardsStreamerMP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { RewardsStreamerMP } from "../src/RewardsStreamerMP.sol";
import { StakeMath } from "../src/math/StakeMath.sol";
import { StakeVault } from "../src/StakeVault.sol";
import { IStakeManagerProxy } from "../src/interfaces/IStakeManagerProxy.sol";
import { StakeManagerProxy } from "../src/StakeManagerProxy.sol";
import { MockToken } from "./mocks/MockToken.sol";
import { StackOverflowStakeManager } from "./mocks/StackOverflowStakeManager.sol";

Expand Down
4 changes: 2 additions & 2 deletions test/StakeVault.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.26;
import { Test } from "forge-std/Test.sol";

import { IStakeManagerProxy } from "../src/interfaces/IStakeManagerProxy.sol";
import { StakeManagerProxy } from "../src/StakeManagerProxy.sol";
import { TransparentProxy } from "../src/TransparentProxy.sol";
import { RewardsStreamerMP } from "../src/RewardsStreamerMP.sol";
import { StakeVault } from "../src/StakeVault.sol";
import { MockToken } from "./mocks/MockToken.sol";
Expand Down Expand Up @@ -33,7 +33,7 @@ contract StakeVaultTest is Test {
bytes memory initializeData = abi.encodeWithSelector(
RewardsStreamerMP.initialize.selector, address(this), address(stakingToken), address(rewardToken)
);
address proxy = address(new StakeManagerProxy(impl, initializeData));
address proxy = address(new TransparentProxy(impl, initializeData));
streamer = RewardsStreamerMP(proxy);

stakingToken.mint(alice, 10_000e18);
Expand Down

0 comments on commit a47d46d

Please sign in to comment.