From 0edc2b9590749af23e434b3b879d072875fc5aee Mon Sep 17 00:00:00 2001 From: jtfirek Date: Wed, 28 Aug 2024 18:09:19 -0500 Subject: [PATCH] removing unnecessary initialization --- script/deploys/BucketRateLimiter.s.sol | 54 -------------------------- src/BucketRateLimiter.sol | 14 +------ test/BucketRaterLimiter.t.sol | 9 +++-- test/TestSetup.sol | 2 +- 4 files changed, 9 insertions(+), 70 deletions(-) delete mode 100644 script/deploys/BucketRateLimiter.s.sol diff --git a/script/deploys/BucketRateLimiter.s.sol b/script/deploys/BucketRateLimiter.s.sol deleted file mode 100644 index 60a2046d..00000000 --- a/script/deploys/BucketRateLimiter.s.sol +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import "forge-std/Script.sol"; - -import "../../src/BucketRateLimiter.sol"; -import "../../src/UUPSProxy.sol"; - -interface IL2SyncPool { - function setRateLimiter(address rateLimiter) external; -} - -contract Deploy is Script { - - function run() external { - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); - address deployer = vm.addr(deployerPrivateKey); - address l2syncpool; - - if (block.chainid == 59144) l2syncpool = 0x823106E745A62D0C2FC4d27644c62aDE946D9CCa; // LINEA - else if (block.chainid == 81457) l2syncpool = 0x52c4221Cb805479954CDE5accfF8C4DcaF96623B; // BLAST - else if (block.chainid == 34443) l2syncpool = 0x52c4221Cb805479954CDE5accfF8C4DcaF96623B; // MODE - else if (block.chainid == 8453) l2syncpool = 0xc38e046dFDAdf15f7F56853674242888301208a5; // BASE - else revert("Unsupported chain id"); - - vm.startBroadcast(deployerPrivateKey); - - BucketRateLimiter impl = new BucketRateLimiter(); - UUPSProxy proxy = new UUPSProxy(address(impl), ""); - BucketRateLimiter limiter = BucketRateLimiter(address(proxy)); - limiter.initialize(); - - limiter.updateConsumer(l2syncpool); - IL2SyncPool(l2syncpool).setRateLimiter(address(limiter)); - - vm.stopBroadcast(); - - // TEST - - vm.startPrank(deployer); - limiter.setCapacity(0.0002 ether); - limiter.setRefillRatePerSecond(0.0002 ether); - vm.stopPrank(); - - vm.prank(l2syncpool); - vm.expectRevert("BucketRateLimiter: rate limit exceeded"); - limiter.updateRateLimit(address(0), address(0), 0.0001 ether, 0.0001 ether); - - vm.prank(l2syncpool); - vm.warp(block.timestamp + 1); - limiter.updateRateLimit(address(0), address(0), 0.0001 ether, 0.0001 ether); - } - -} \ No newline at end of file diff --git a/src/BucketRateLimiter.sol b/src/BucketRateLimiter.sol index 987f0b5e..bb461c4d 100644 --- a/src/BucketRateLimiter.sol +++ b/src/BucketRateLimiter.sol @@ -16,9 +16,6 @@ contract BucketRateLimiter is IRateLimiter, IPausable, Initializable, PausableUp BucketLimiter.Limit public limit; address public consumer; - mapping(address => bool) public DEPRECATED_admins; - mapping(address => bool) public DEPRECATED_pausers; - mapping(address => BucketLimiter.Limit) public limitsPerToken; RoleRegistry public roleRegistry; @@ -32,19 +29,12 @@ contract BucketRateLimiter is IRateLimiter, IPausable, Initializable, PausableUp _disableInitializers(); } - function initialize() external initializer { + function initialize(address _roleRegistry) external initializer { __Pausable_init(); __Ownable_init(); __UUPSUpgradeable_init(); limit = BucketLimiter.create(0, 0); - } - - function initializeV2dot5(address _roleRegistry) external onlyOwner { - require(address(roleRegistry) == address(0x00), "already initialized"); - - // TODO: compile list of values in DEPRECATED_pausers to clear out - // TODO: compile list of values in DEPRECATED_admins to clear out roleRegistry = RoleRegistry(_roleRegistry); } @@ -116,4 +106,4 @@ contract BucketRateLimiter is IRateLimiter, IPausable, Initializable, PausableUp function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} -} \ No newline at end of file +} diff --git a/test/BucketRaterLimiter.t.sol b/test/BucketRaterLimiter.t.sol index 7096240c..d7163798 100644 --- a/test/BucketRaterLimiter.t.sol +++ b/test/BucketRaterLimiter.t.sol @@ -17,7 +17,7 @@ contract BucketRateLimiterTest is TestSetup { BucketRateLimiter impl = new BucketRateLimiter(); UUPSProxy proxy = new UUPSProxy(address(impl), ""); limiter = BucketRateLimiter(address(proxy)); - limiter.initialize(); + limiter.initialize(address(roleRegistry)); limiter.updateConsumer(owner); limiter.setCapacity(200 ether); @@ -106,8 +106,11 @@ contract BucketRateLimiterTest is TestSetup { function test_pauser() public { // Test pausing logic with V2.5 upgrade setUpTests(); - vm.prank(limiter.owner()); - limiter.initializeV2dot5(address(roleRegistry)); + // deploy a new bucket rate limiter to initialize against the role registry + BucketRateLimiter impl = new BucketRateLimiter(); + UUPSProxy proxy = new UUPSProxy(address(impl), ""); + limiter = BucketRateLimiter(address(proxy)); + limiter.initialize(address(roleRegistry)); vm.prank(chad); vm.expectRevert(BucketRateLimiter.IncorrectRole.selector); diff --git a/test/TestSetup.sol b/test/TestSetup.sol index 92cac959..790dae87 100644 --- a/test/TestSetup.sol +++ b/test/TestSetup.sol @@ -405,7 +405,7 @@ contract TestSetup is Test { address impl = address(new BucketRateLimiter()); bucketRateLimiter = BucketRateLimiter(address(new UUPSProxy(impl, ""))); - bucketRateLimiter.initialize(); + bucketRateLimiter.initialize(address(roleRegistry)); bucketRateLimiter.updateConsumer(address(liquifierInstance)); bucketRateLimiter.setCapacity(40 ether);