Skip to content

Commit

Permalink
chore: fix lint and zksync configs
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlymite committed Dec 14, 2024
1 parent b3ff49e commit 9969804
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Compiler files
cache/
out/
zkout/

# Ignores development broadcast logs
!/broadcast
Expand Down
17 changes: 16 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ libs = ["lib"]
fs_permissions = [{ access = "write", path = "./reports" }]
ffi = true

[profile.zksync]
src = 'src'
test = 'zksync'
script = 'scripts'
libs = ['lib']
solc = '0.8.20'
fs_permissions = [{ access = "write", path = "./reports" }]
ffi = true
evm_version = 'shanghai'

[profile.zksync.zksync]
compile = true
optimizer_mode = '3'
zksolc = '1.5.7'

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
[rpc_endpoints]
mainnet = "${RPC_MAINNET}"
Expand Down Expand Up @@ -47,4 +62,4 @@ scroll = { key = "${ETHERSCAN_API_KEY_SCROLL}", chainId = 534352 }
zksync = { key = "${ETHERSCAN_API_KEY_ZKSYNC}", chain = 324 }

[fmt]
tab_width = 2
tab_width = 2
39 changes: 11 additions & 28 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,17 @@ import {CollectorWithCustomImpl} from "../src/CollectorWithCustomImpl.sol";
import {UpgradePayload} from "../src/UpgradePayload.sol";

library DeploymentLibrary {
function _deploy(
address aclManager,
address collector,
address proxyAdmin
) private returns (address) {
address impl = GovV3Helpers.deployDeterministic(
type(CollectorWithCustomImpl).creationCode,
abi.encode(aclManager)
);
CollectorWithCustomImpl(impl).initialize(0);
return address(new UpgradePayload(collector, impl, proxyAdmin));
}
function _deploy(address aclManager, address collector, address proxyAdmin) private returns (address) {
address impl = GovV3Helpers.deployDeterministic(type(CollectorWithCustomImpl).creationCode, abi.encode(aclManager));
CollectorWithCustomImpl(impl).initialize(0);
return address(new UpgradePayload(collector, impl, proxyAdmin));
}

function deployMainnet() internal returns (address) {
return
_deploy(
address(AaveV3Ethereum.ACL_MANAGER),
address(AaveV3Ethereum.COLLECTOR),
MiscEthereum.PROXY_ADMIN
);
}
function deployMainnet() internal returns (address) {
return _deploy(address(AaveV3Ethereum.ACL_MANAGER), address(AaveV3Ethereum.COLLECTOR), MiscEthereum.PROXY_ADMIN);
}

function deployPolygon() internal returns (address) {
return
_deploy(
address(AaveV3Polygon.ACL_MANAGER),
address(AaveV3Polygon.COLLECTOR),
MiscPolygon.PROXY_ADMIN
);
}
function deployPolygon() internal returns (address) {
return _deploy(address(AaveV3Polygon.ACL_MANAGER), address(AaveV3Polygon.COLLECTOR), MiscPolygon.PROXY_ADMIN);
}
}
21 changes: 11 additions & 10 deletions src/CollectorWithCustomImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import {Collector, ICollector} from "aave-v3-origin/contracts/treasury/Collector
* - storage slot 51 is reset to 0
* - storage slot 52 is set to 1 (which is the default state of the reentrancy guard)
* @author BGD Labs
**/
*
*/
contract CollectorWithCustomImpl is Collector {
constructor(address aclManager) Collector(aclManager) {
// intentionally left empty
}
constructor(address aclManager) Collector(aclManager) {
// intentionally left empty
}

/// @inheritdoc ICollector
function initialize(uint256) external virtual override initializer {
assembly {
sstore(51, 0) // this slot was _status, but is now part of the gap
sstore(52, 1) // this slot was the funds admin, but is now _status
}
/// @inheritdoc ICollector
function initialize(uint256) external virtual override initializer {
assembly {
sstore(51, 0) // this slot was _status, but is now part of the gap
sstore(52, 1) // this slot was the funds admin, but is now _status
}
}
}
21 changes: 11 additions & 10 deletions src/CollectorWithCustomImplZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import {Collector, ICollector} from "aave-v3-origin/contracts/treasury/Collector
* - storage slot 51 is reset to 0
* - storage slot 52 is set to 1 (which is the default state of the reentrancy guard)
* @author BGD Labs
**/
*
*/
contract CollectorWithCustomImplZkSync is Collector {
constructor(address aclManager) Collector(aclManager) {
// intentionally left empty
}
constructor(address aclManager) Collector(aclManager) {
// intentionally left empty
}

/// @inheritdoc ICollector
function initialize(uint256) external virtual override initializer {
assembly {
sstore(53, 100000) // this slot was _fundsAdmin, but is now _nextStreamId
sstore(54, 0) // this slot was _nextStreamId, but is now _streams
}
/// @inheritdoc ICollector
function initialize(uint256) external virtual override initializer {
assembly {
sstore(53, 100000) // this slot was _fundsAdmin, but is now _nextStreamId
sstore(54, 0) // this slot was _nextStreamId, but is now _streams
}
}
}
45 changes: 23 additions & 22 deletions src/UpgradePayload.sol
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {ITransparentUpgradeableProxy, ProxyAdmin} from "solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol";

import {
ITransparentUpgradeableProxy,
ProxyAdmin
} from "solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol";
import {IAccessControl} from "aave-v3-origin/contracts/dependencies/openzeppelin/contracts/IAccessControl.sol";
import {ICollector} from "aave-v3-origin/contracts/treasury/ICollector.sol";

contract UpgradePayload {
address public immutable PROXY_ADMIN;
address public immutable COLLECTOR;
address public immutable COLLECTOR_IMPL;
address public immutable PROXY_ADMIN;
address public immutable COLLECTOR;
address public immutable COLLECTOR_IMPL;

constructor(address collector, address collectorImpl, address proxyAdmin) {
COLLECTOR = collector;
COLLECTOR_IMPL = collectorImpl;
PROXY_ADMIN = proxyAdmin;
}
constructor(address collector, address collectorImpl, address proxyAdmin) {
COLLECTOR = collector;
COLLECTOR_IMPL = collectorImpl;
PROXY_ADMIN = proxyAdmin;
}

function execute() external {
// upgrade collector implementation with custom initialize to align storage
ProxyAdmin(PROXY_ADMIN).upgradeAndCall(
ITransparentUpgradeableProxy(COLLECTOR),
COLLECTOR_IMPL,
abi.encodeWithSelector(ICollector.initialize.selector, 0)
);
// grant funds admin permissions to the executor
IAccessControl(ICollector(COLLECTOR).ACL_MANAGER()).grantRole(
ICollector(COLLECTOR).FUNDS_ADMIN_ROLE(),
address(this)
);
}
function execute() external {
// upgrade collector implementation with custom initialize to align storage
ProxyAdmin(PROXY_ADMIN).upgradeAndCall(
ITransparentUpgradeableProxy(COLLECTOR), COLLECTOR_IMPL, abi.encodeWithSelector(ICollector.initialize.selector, 0)
);
// grant funds admin permissions to the executor
IAccessControl(ICollector(COLLECTOR).ACL_MANAGER()).grantRole(
ICollector(COLLECTOR).FUNDS_ADMIN_ROLE(), address(this)
);
}
}
14 changes: 7 additions & 7 deletions test/Mainnet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {UpgradeTest} from "./UpgradeTest.sol";
import {DeploymentLibrary} from "../script/Deploy.s.sol";

contract MainnetTest is UpgradeTest {
constructor() UpgradeTest("mainnet", 21336615) {}
constructor() UpgradeTest("mainnet", 21336615) {}

function _getPayload() internal virtual override returns (address) {
return DeploymentLibrary.deployMainnet();
}
function _getPayload() internal virtual override returns (address) {
return DeploymentLibrary.deployMainnet();
}

function _getPool() internal virtual override returns (IPool) {
return AaveV3Ethereum.POOL;
}
function _getPool() internal virtual override returns (IPool) {
return AaveV3Ethereum.POOL;
}
}
14 changes: 7 additions & 7 deletions test/Polygon.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {UpgradeTest} from "./UpgradeTest.sol";
import {DeploymentLibrary} from "../script/Deploy.s.sol";

contract PolygonTest is UpgradeTest {
constructor() UpgradeTest("polygon", 65118236) {}
constructor() UpgradeTest("polygon", 65118236) {}

function _getPayload() internal virtual override returns (address) {
return DeploymentLibrary.deployPolygon();
}
function _getPayload() internal virtual override returns (address) {
return DeploymentLibrary.deployPolygon();
}

function _getPool() internal virtual override returns (IPool) {
return AaveV3Polygon.POOL;
}
function _getPool() internal virtual override returns (IPool) {
return AaveV3Polygon.POOL;
}
}
Loading

0 comments on commit 9969804

Please sign in to comment.