-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/fly 2184 #424
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
Open
Hakob23
wants to merge
16
commits into
v2.6.0
Choose a base branch
from
feature/FLY-2184
base: v2.6.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,036
−13
Open
Feature/fly 2184 #424
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a462c0f
feat: add ChangeOwnerToTimelock script for ownership transfer
5419947
test: implement tests for ownership transfer and upgrade delay using …
3b6f0be
feat: add Timelock configuration for legacy LBC ownership in example.env
c6f5f90
feat: add timelockOwnership script for the split architecture
Hakob23 558e77a
test: add tests for Timelock ownership scripts
Hakob23 08ed784
refactor: simplify ChangeOwnerToTimelock script by removing unused pr…
Hakob23 cd5e795
feat: supporting multiple acceptor and proposer addresses and having …
Hakob23 0fb0607
test: modifying tests for multiple address config
Hakob23 5d9d9a8
Merge branch 'v2.6.0' into feature/FLY-2184
Hakob23 7eed076
refactor: remove unused DAO fee configuration and integrate PauseRegi…
Hakob23 1325b54
fmt: fix
Hakob23 abeb58a
feat: add rskRegtest configuration for proposers and executors in tim…
Hakob23 c07d54f
refactor: remove unused LiquidityBridgeContractV2 import from ChangeO…
Hakob23 9aece8a
refactor: remove prank call from test_ScriptTransfersProxyAdminToTime…
Hakob23 ae1273d
chore: update npm package
Luisfc68 8bcae27
fix: update LiquidityBridgeContractProxy initialization to use the cu…
Hakob23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should have this script also for the split architecture, because this is going to be merged for the v2.6.0 when that architecture is supposed to be already deployed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.25; | ||
|
|
||
| import {Script, console} from "lib/forge-std/src/Script.sol"; | ||
| import {HelperConfig} from "../../HelperConfig.s.sol"; | ||
| import {TimelockController} from "@openzeppelin/contracts/governance/TimelockController.sol"; | ||
| import {LiquidityBridgeContractV2} from "../../../src/legacy/LiquidityBridgeContractV2.sol"; | ||
Hakob23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import {LiquidityBridgeContractAdmin} from "../../../src/legacy/LiquidityBridgeContractAdmin.sol"; | ||
|
|
||
| contract ChangeOwnerToTimelock is Script { | ||
| bytes32 internal constant ADMIN_SLOT = | ||
| 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; | ||
|
|
||
| error ProxyAddressNotProvided(); | ||
| error TimelockProposerIsZero(); | ||
| error TimelockExecutorIsZero(); | ||
| error OnlyCurrentLbcOwnerCanTransferOwnership(); | ||
| error ContractOwnerTransferFailed(); | ||
| error AdminAddressNotFound(); | ||
| error OnlyCurrentProxyAdminOwnerCanTransferOwnership(); | ||
| error ProxyAdminOwnerTransferFailed(); | ||
|
|
||
| function run() external { | ||
| HelperConfig helper = new HelperConfig(); | ||
| HelperConfig.NetworkConfig memory cfg = helper.getConfig(); | ||
|
|
||
| uint256 deployerKey = helper.getDeployerPrivateKey(); | ||
| vm.rememberKey(deployerKey); | ||
|
|
||
| address proxyAddress = cfg.existingProxy; | ||
| if (proxyAddress == address(0)) { | ||
| revert ProxyAddressNotProvided(); | ||
| } | ||
| if (cfg.timelockProposer == address(0)) { | ||
| revert TimelockProposerIsZero(); | ||
| } | ||
| if (cfg.timelockExecutor == address(0)) { | ||
| revert TimelockExecutorIsZero(); | ||
| } | ||
|
|
||
| address[] memory proposers = new address[](1); | ||
| proposers[0] = cfg.timelockProposer; | ||
|
|
||
| address[] memory executors = new address[](1); | ||
| executors[0] = cfg.timelockExecutor; | ||
|
|
||
| vm.startBroadcast(deployerKey); | ||
|
|
||
| TimelockController timelock = new TimelockController( | ||
Luisfc68 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cfg.timelockMinDelay, | ||
| proposers, | ||
| executors, | ||
| address(0) | ||
| ); | ||
|
|
||
| _transferContractOwnership(proxyAddress, address(timelock)); | ||
Luisfc68 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _transferProxyAdminOwnership(proxyAddress, address(timelock)); | ||
|
|
||
| vm.stopBroadcast(); | ||
|
|
||
| _logFinalState(proxyAddress, timelock, cfg); | ||
| } | ||
|
|
||
| function _transferContractOwnership( | ||
| address proxyAddress, | ||
| address timelock | ||
| ) internal { | ||
| LiquidityBridgeContractV2 contract_ = LiquidityBridgeContractV2( | ||
| payable(proxyAddress) | ||
| ); | ||
| address currentOwner = contract_.owner(); | ||
| if (currentOwner != timelock) { | ||
| if (currentOwner != msg.sender) { | ||
| revert OnlyCurrentLbcOwnerCanTransferOwnership(); | ||
| } | ||
| contract_.transferOwnership(timelock); | ||
| } | ||
| if (contract_.owner() != timelock) { | ||
| revert ContractOwnerTransferFailed(); | ||
| } | ||
| } | ||
|
|
||
| function _transferProxyAdminOwnership( | ||
| address proxyAddress, | ||
| address timelock | ||
| ) internal { | ||
| address adminAddress = address( | ||
| uint160(uint256(vm.load(proxyAddress, ADMIN_SLOT))) | ||
| ); | ||
| if (adminAddress == address(0)) { | ||
| revert AdminAddressNotFound(); | ||
| } | ||
|
|
||
| LiquidityBridgeContractAdmin admin = LiquidityBridgeContractAdmin( | ||
| adminAddress | ||
| ); | ||
| address currentAdminOwner = admin.owner(); | ||
| if (currentAdminOwner != timelock) { | ||
| if (currentAdminOwner != msg.sender) { | ||
| revert OnlyCurrentProxyAdminOwnerCanTransferOwnership(); | ||
| } | ||
| admin.transferOwnership(timelock); | ||
| } | ||
| if (admin.owner() != timelock) { | ||
| revert ProxyAdminOwnerTransferFailed(); | ||
| } | ||
| } | ||
|
|
||
| function _logFinalState( | ||
| address proxyAddress, | ||
| TimelockController timelock, | ||
| HelperConfig.NetworkConfig memory cfg | ||
| ) internal view { | ||
| LiquidityBridgeContractV2 contract_ = LiquidityBridgeContractV2( | ||
| payable(proxyAddress) | ||
| ); | ||
| address adminAddress = address( | ||
| uint160(uint256(vm.load(proxyAddress, ADMIN_SLOT))) | ||
| ); | ||
| LiquidityBridgeContractAdmin admin = LiquidityBridgeContractAdmin( | ||
| adminAddress | ||
| ); | ||
|
|
||
| console.log("=== Timelock ownership setup complete ==="); | ||
| console.log("Timelock:", address(timelock)); | ||
| console.log("Timelock minDelay:", timelock.getMinDelay()); | ||
| console.log("LBC owner:", contract_.owner()); | ||
| console.log("Expected timelock:", address(timelock)); | ||
| console.log("ProxyAdmin owner:", admin.owner()); | ||
| console.log("Expected timelock:", address(timelock)); | ||
| console.log( | ||
| "Proposer role granted:", | ||
| timelock.hasRole(timelock.PROPOSER_ROLE(), cfg.timelockProposer) | ||
| ); | ||
| console.log( | ||
| "Executor role granted:", | ||
| timelock.hasRole(timelock.EXECUTOR_ROLE(), cfg.timelockExecutor) | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.25; | ||
|
|
||
| import "lib/forge-std/src/Test.sol"; | ||
| import {TimelockController} from "@openzeppelin/contracts/governance/TimelockController.sol"; | ||
| import {HelperConfig} from "../../script/HelperConfig.s.sol"; | ||
| import {LiquidityBridgeContract} from "../../src/legacy/LiquidityBridgeContract.sol"; | ||
| import {LiquidityBridgeContractProxy} from "../../src/legacy/LiquidityBridgeContractProxy.sol"; | ||
| import {LiquidityBridgeContractAdmin} from "../../src/legacy/LiquidityBridgeContractAdmin.sol"; | ||
|
|
||
| contract ChangeOwnerToTimelockTest is Test { | ||
| bytes32 internal constant ADMIN_SLOT = | ||
| 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; | ||
|
|
||
| HelperConfig public helperConfig; | ||
| LiquidityBridgeContract public lbcImpl; | ||
| LiquidityBridgeContractProxy public proxy; | ||
| LiquidityBridgeContractAdmin public admin; | ||
| TimelockController public timelock; | ||
|
|
||
| address public proposer; | ||
| address public executor; | ||
| uint256 public minDelay; | ||
|
|
||
| function setUp() public { | ||
| helperConfig = new HelperConfig(); | ||
| proposer = makeAddr("proposer"); | ||
| executor = makeAddr("executor"); | ||
| minDelay = 7 days; | ||
|
|
||
| HelperConfig.NetworkConfig memory cfg = helperConfig.getConfig(); | ||
|
|
||
| lbcImpl = new LiquidityBridgeContract(); | ||
| admin = new LiquidityBridgeContractAdmin(); | ||
|
|
||
| bytes memory initData = abi.encodeCall( | ||
| LiquidityBridgeContract.initialize, | ||
| ( | ||
| payable(cfg.bridge), | ||
| cfg.minimumCollateral, | ||
| cfg.minimumPegIn, | ||
| cfg.rewardPercentage, | ||
| cfg.resignDelayBlocks, | ||
| cfg.dustThreshold, | ||
| cfg.btcBlockTime, | ||
| cfg.mainnet | ||
| ) | ||
| ); | ||
| proxy = new LiquidityBridgeContractProxy( | ||
| address(lbcImpl), | ||
| address(admin), | ||
| initData | ||
| ); | ||
|
|
||
| address[] memory proposers = new address[](1); | ||
| proposers[0] = proposer; | ||
| address[] memory executors = new address[](1); | ||
| executors[0] = executor; | ||
|
|
||
| timelock = new TimelockController( | ||
| minDelay, | ||
| proposers, | ||
| executors, | ||
| address(0) | ||
| ); | ||
| } | ||
|
|
||
| function test_TransfersLegacyOwnershipsToTimelock() public { | ||
| LiquidityBridgeContract lbcProxy = LiquidityBridgeContract( | ||
| payable(address(proxy)) | ||
| ); | ||
| LiquidityBridgeContractAdmin actualAdmin = _getProxyAdmin(); | ||
|
|
||
| lbcProxy.transferOwnership(address(timelock)); | ||
| vm.prank(actualAdmin.owner()); | ||
| actualAdmin.transferOwnership(address(timelock)); | ||
|
|
||
| assertEq(lbcProxy.owner(), address(timelock), "LBC owner mismatch"); | ||
| assertEq( | ||
| actualAdmin.owner(), | ||
| address(timelock), | ||
| "ProxyAdmin owner mismatch" | ||
| ); | ||
| assertEq(timelock.getMinDelay(), minDelay, "minDelay mismatch"); | ||
| assertTrue( | ||
| timelock.hasRole(timelock.PROPOSER_ROLE(), proposer), | ||
| "proposer missing" | ||
| ); | ||
| assertTrue( | ||
| timelock.hasRole(timelock.EXECUTOR_ROLE(), executor), | ||
| "executor missing" | ||
| ); | ||
| } | ||
|
|
||
| function test_OwnerOnlyOperationIsDelayedByTimelock() public { | ||
| LiquidityBridgeContract lbcProxy = LiquidityBridgeContract( | ||
| payable(address(proxy)) | ||
| ); | ||
| lbcProxy.transferOwnership(address(timelock)); | ||
|
|
||
| address newOwner = makeAddr("newOwner"); | ||
| bytes memory payload = abi.encodeWithSignature( | ||
| "transferOwnership(address)", | ||
| newOwner | ||
| ); | ||
| bytes32 predecessor = bytes32(0); | ||
| bytes32 salt = keccak256("owner-op"); | ||
|
|
||
| vm.expectRevert(); | ||
| lbcProxy.transferOwnership(newOwner); | ||
|
|
||
| vm.prank(proposer); | ||
| timelock.schedule( | ||
| address(lbcProxy), | ||
| 0, | ||
| payload, | ||
| predecessor, | ||
| salt, | ||
| minDelay | ||
| ); | ||
|
|
||
| vm.prank(executor); | ||
| vm.expectRevert(); | ||
| timelock.execute(address(lbcProxy), 0, payload, predecessor, salt); | ||
|
|
||
| vm.warp(block.timestamp + minDelay); | ||
| vm.prank(executor); | ||
| timelock.execute(address(lbcProxy), 0, payload, predecessor, salt); | ||
|
|
||
| assertEq(lbcProxy.owner(), newOwner, "timelocked owner-op failed"); | ||
| } | ||
|
|
||
| function test_ProxyAdminStoredInExpectedSlot() public { | ||
| address proxyAdminAddress = address( | ||
| uint160(uint256(vm.load(address(proxy), ADMIN_SLOT))) | ||
| ); | ||
| assertTrue(proxyAdminAddress != address(0), "EIP-1967 admin missing"); | ||
| } | ||
|
|
||
| function _getProxyAdmin() | ||
| internal | ||
| view | ||
| returns (LiquidityBridgeContractAdmin) | ||
| { | ||
| address proxyAdminAddress = address( | ||
| uint160(uint256(vm.load(address(proxy), ADMIN_SLOT))) | ||
| ); | ||
| return LiquidityBridgeContractAdmin(proxyAdminAddress); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.