Skip to content

Commit

Permalink
feat: zkSync (#320)
Browse files Browse the repository at this point in the history
* chore: zksync configs

* chore: copy ProtocolV3TestBase

* fix: ProtocolV3TestBase

* chore: misc cleanup

* test: protocolV3TestBase

* fix: script utils

* feat: create2 utils

* chore: some comments

* fix: create2Utils

* fix: zksync govV3 helpers

* chore: add zksync payloadsController

* chore: update address-book

* fix: govV3Helpers

* chore: make method pure

* chore: fix chainId

* chore: update libs

* feat: zksync config engine payload

* chore: update solidity-utils

* fix: generate diff in snapshot helpers

* chore: update address book

* fix: move create2 zksync to solidity-utils

* chore: fix rpc name

* fix: evm version

* chore: update libs

* chore: add zksync ci

* chore: test ci

* chore: trigger

* chore: update forge-std

* chore: test ci

* chore: test ci

* fix: remove test

* fix: workflow to main branch

* fix: update foundry.toml

* fix: updated libs to main

---------

Co-authored-by: sendra <[email protected]>
  • Loading branch information
brotherlymite and sendra authored Aug 7, 2024
1 parent 07b8d57 commit 920554b
Show file tree
Hide file tree
Showing 12 changed files with 1,021 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RPC_GNOSIS=https://rpc.gnosischain.com
RPC_ZKEVM=https://polygon-zkevm.drpc.org
RPC_SCROLL=https://rpc.scroll.io
RPC_ZKEVM=https://zkevm-rpc.com
RPC_ZKSYNC=https://mainnet.era.zksync.io

# Testnet rpc_endpoints
RPC_SEPOLIA=wss://ethereum-sepolia.publicnode.com
Expand All @@ -29,3 +30,4 @@ ETHERSCAN_API_KEY_ARBITRUM=
ETHERSCAN_API_KEY_BASE=
ETHERSCAN_API_KEY_BNB=
ETHERSCAN_API_KEY_ZKEVM=
ETHERSCAN_API_KEY_ZKSYNC=
7 changes: 7 additions & 0 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ jobs:
test:
uses: bgd-labs/github-workflows/.github/workflows/foundry-test.yml@main
secrets: inherit
test-sol-zksync:
uses: bgd-labs/github-workflows/.github/workflows/foundry-test.yml@main
secrets: inherit
with:
mode: "CHANGED"
zksync: true
ROOT_DIR: "zksync"
release:
needs: [test]
uses: bgd-labs/github-workflows/.github/workflows/release.yml@main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cache/
out/
zkout/
.idea
.env
broadcast
Expand Down
17 changes: 17 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ ffi = true
solc = '0.8.18'
evm_version = 'shanghai'

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

[profile.zksync.zksync]
compile = true
fallback_oz = true
mode = '3'
zksolc = '1.5.1'

[rpc_endpoints]
mainnet = "${RPC_MAINNET}"
optimism = "${RPC_OPTIMISM}"
Expand All @@ -25,6 +40,7 @@ sepolia = "${RPC_SEPOLIA}"
gnosis = "${RPC_GNOSIS}"
scroll = "${RPC_SCROLL}"
zkevm = "${RPC_ZKEVM}"
zksync = "${RPC_ZKSYNC}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY_MAINNET}", chainId = 1 }
Expand All @@ -39,4 +55,5 @@ sepolia = { key = "${ETHERSCAN_API_KEY_MAINNET}", chainId = 11155111 }
gnosis = { key = "${ETHERSCAN_API_KEY_GNOSIS}", chainId = 100, url = 'https://api.gnosisscan.io/api' }
scroll = { key = "${ETHERSCAN_API_KEY_SCROLL}", chainId = 534352 }
zkevm = { key = "${ETHERSCAN_API_KEY_ZKEVM}", chainId = 1101 }
zksync = { key = "${ETHERSCAN_API_KEY_ZKSYNC}", chain = 324 }
# See more config options https://github.com/gakonst/foundry/tree/master/config
2 changes: 1 addition & 1 deletion lib/forge-std
83 changes: 83 additions & 0 deletions src/GovV3Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import {GovernanceV3BNB} from 'aave-address-book/GovernanceV3BNB.sol';
import {GovernanceV3Gnosis} from 'aave-address-book/GovernanceV3Gnosis.sol';
import {GovernanceV3Scroll} from 'aave-address-book/GovernanceV3Scroll.sol';
import {GovernanceV3PolygonZkEvm} from 'aave-address-book/GovernanceV3PolygonZkEvm.sol';
import {GovernanceV3ZkSync} from 'aave-address-book/GovernanceV3ZkSync.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';
import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import {Create2Utils} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {StorageHelpers} from './StorageHelpers.sol';
import {ProxyHelpers} from './ProxyHelpers.sol';
import {Create2UtilsZkSync} from 'solidity-utils/../zksync/src/contracts/utils/ScriptUtilsZkSync.sol';

interface IGovernance_V2_5 {
/**
Expand Down Expand Up @@ -156,6 +158,32 @@ library GovV3Helpers {
IVotingMachineWithProofs(machine).submitVote(proposalId, support, votingBalanceProofs);
}

// Deploys using the unsanitized bytecodeHash we get via `type(Contract).creationCode`
function deployDeterministicZkSync(bytes memory bytecodeHash) internal returns (address) {
return Create2UtilsZkSync.create2Deploy('v1', bytecodeHash);
}

// Deploys using the unsanitized bytecodeHash we get via `type(Contract).creationCode`
function deployDeterministicZkSync(
bytes memory bytecodeHash,
bytes memory arguments
) internal returns (address) {
return Create2UtilsZkSync.create2Deploy('v1', bytecodeHash, arguments);
}

// Deploys using the sanitized bytecodeHash
function deployDeterministicZkSync(bytes32 bytecodeHash) internal returns (address) {
return Create2UtilsZkSync.create2Deploy('v1', bytecodeHash);
}

// Deploys using the sanitized bytecodeHash
function deployDeterministicZkSync(
bytes32 bytecodeHash,
bytes memory arguments
) internal returns (address) {
return Create2UtilsZkSync.create2Deploy('v1', bytecodeHash, arguments);
}

/**
* Deploys a contract with a constant salt
*/
Expand Down Expand Up @@ -184,6 +212,35 @@ library GovV3Helpers {
return Create2Utils.computeCreate2Address('v1', bytecode, arguments);
}

function predictDeterministicAddressZkSync(bytes32 bytecodeHash) internal pure returns (address) {
return Create2UtilsZkSync.computeCreate2Address('v1', bytecodeHash);
}

function predictDeterministicAddressZkSync(
bytes32 bytecodeHash,
bytes memory arguments
) internal pure returns (address) {
return Create2UtilsZkSync.computeCreate2Address('v1', bytecodeHash, arguments);
}

function buildActionZkSync(
Vm vm,
string memory contractName
) internal view returns (IPayloadsControllerCore.ExecutionAction memory) {
bytes32 bytecodeHash = _getBytecodeHashFromArtifacts(vm, contractName);
address payloadAddress = predictDeterministicAddressZkSync(bytecodeHash);
return buildAction(payloadAddress);
}

function _getBytecodeHashFromArtifacts(Vm vm, string memory contractName) private view returns (bytes32 bytecodeHash) {
string memory artifactPath = string.concat('zkout/', contractName, '.sol/', contractName, '.json');
string memory artifact = vm.readFile(artifactPath);
bytecodeHash = vm.parseJsonBytes32(artifact, ".hash");

require(bytecodeHash != (bytes32(0)), 'Unable to fetch bytecodeHash from the zkout artifacts');
return bytecodeHash;
}

/**
* @dev builds a action to be registered on a payloadsController
* - assumes accesscontrol level 1
Expand Down Expand Up @@ -606,6 +663,30 @@ library GovV3Helpers {
return _buildPayload(vm, ChainIds.SCROLL, action);
}

/**
* Builds a payload to be executed via governance
* @param vm Vm
* @param actions actions array
*/
function buildZkSyncPayload(
Vm vm,
IPayloadsControllerCore.ExecutionAction[] memory actions
) internal returns (PayloadsControllerUtils.Payload memory) {
return _buildPayload(vm, ChainIds.ZKSYNC, actions);
}

/**
* Builds a payload to be executed via governance
* @param vm Vm
* @param action actions array
*/
function buildZkSyncPayload(
Vm vm,
IPayloadsControllerCore.ExecutionAction memory action
) internal returns (PayloadsControllerUtils.Payload memory) {
return _buildPayload(vm, ChainIds.ZKSYNC, action);
}

/**
* @dev creates a proposal with multiple payloads
* @param vm Vm
Expand Down Expand Up @@ -685,6 +766,8 @@ library GovV3Helpers {
return GovernanceV3Scroll.PAYLOADS_CONTROLLER;
} else if (chainId == ChainIds.ZK_EVM) {
return GovernanceV3PolygonZkEvm.PAYLOADS_CONTROLLER;
} else if (chainId == ChainIds.ZKSYNC) {
return GovernanceV3ZkSync.PAYLOADS_CONTROLLER;
}

revert CannotFindPayloadsController();
Expand Down
2 changes: 1 addition & 1 deletion src/ProtocolV3TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ contract ProtocolV3TestBase is RawProtocolV3TestBase, CommonTestBase {
function _writeStrategyConfigs(
string memory path,
ReserveConfig[] memory configs
) internal override {
) internal virtual override {
// keys for json stringification
string memory strategiesKey = 'stategies';
string memory content = '{}';
Expand Down
15 changes: 15 additions & 0 deletions src/v3-config-engine/AaveV3PayloadZkSync.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {AaveV3ZkSync} from 'aave-address-book/AaveV3ZkSync.sol';
import 'aave-v3-origin/periphery/contracts/v3-config-engine/AaveV3Payload.sol';

/**
* @dev Base smart contract for an Aave v3.1.0 listing on v3 ZkSync.
* @author BGD Labs
*/
abstract contract AaveV3PayloadZkSync is AaveV3Payload(IEngine(AaveV3ZkSync.CONFIG_ENGINE)) {
function getPoolContext() public pure override returns (IEngine.PoolContext memory) {
return IEngine.PoolContext({networkName: 'ZkSync', networkAbbreviation: 'Zks'});
}
}
Loading

1 comment on commit 920554b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foundry report

forge 0.0.2 (0ae6903 2024-08-07T00:22:28.145787438Z)
Build log
Compiling 173 files with ZkSolc 0.8.20
ZkSolc 0.8.20 finished in 88.00s
Compiler run successful with warnings:
Warning (5667)
Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> zksync/src/ProtocolV3TestBase.sol:65:5:
   |
65 |     string memory reportName,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^

| Contract                            | Size (B) | Margin (B) |
|-------------------------------------|----------|------------|
| AaveArbEthERC20Bridge               |   11,872 |     12,704 |
| AaveGovernanceV2                    |      224 |     24,352 |
| AaveOpEthERC20Bridge                |   10,592 |     13,984 |
| AavePolEthERC20Bridge               |   16,544 |      8,032 |
| AavePolEthPlasmaBridge              |   13,408 |     11,168 |
| AaveSwapper                         |   19,488 |      5,088 |
| AaveV2Avalanche                     |      224 |     24,352 |
| AaveV2AvalancheAssets               |      224 |     24,352 |
| AaveV2ConfigEngine                  |    8,992 |     15,584 |
| AaveV2Ethereum                      |      224 |     24,352 |
| AaveV2EthereumAMM                   |      224 |     24,352 |
| AaveV2EthereumAMMAssets             |      224 |     24,352 |
| AaveV2EthereumAssets                |      224 |     24,352 |
| AaveV2Polygon                       |      224 |     24,352 |
| AaveV2PolygonAssets                 |      224 |     24,352 |
| AaveV3Arbitrum                      |      224 |     24,352 |
| AaveV3ArbitrumAssets                |      224 |     24,352 |
| AaveV3ArbitrumEModes                |      224 |     24,352 |
| AaveV3ArbitrumExternalLibraries     |      224 |     24,352 |
| AaveV3Avalanche                     |      224 |     24,352 |
| AaveV3AvalancheAssets               |      224 |     24,352 |
| AaveV3AvalancheEModes               |      224 |     24,352 |
| AaveV3AvalancheExternalLibraries    |      224 |     24,352 |
| AaveV3BNB                           |      224 |     24,352 |
| AaveV3BNBAssets                     |      224 |     24,352 |
| AaveV3BNBEModes                     |      224 |     24,352 |
| AaveV3BNBExternalLibraries          |      224 |     24,352 |
| AaveV3Base                          |      224 |     24,352 |
| AaveV3BaseAssets                    |      224 |     24,352 |
| AaveV3BaseEModes                    |      224 |     24,352 |
| AaveV3BaseExternalLibraries         |      224 |     24,352 |
| AaveV3Ethereum                      |      224 |     24,352 |
| AaveV3EthereumAssets                |      224 |     24,352 |
| AaveV3EthereumEModes                |      224 |     24,352 |
| AaveV3EthereumExternalLibraries     |      224 |     24,352 |
| AaveV3EthereumLido                  |      224 |     24,352 |
| AaveV3EthereumLidoAssets            |      224 |     24,352 |
| AaveV3EthereumLidoEModes            |      224 |     24,352 |
| AaveV3EthereumLidoExternalLibraries |      224 |     24,352 |
| AaveV3Gnosis                        |      224 |     24,352 |
| AaveV3GnosisAssets                  |      224 |     24,352 |
| AaveV3GnosisEModes                  |      224 |     24,352 |
| AaveV3GnosisExternalLibraries       |      224 |     24,352 |
| AaveV3Metis                         |      224 |     24,352 |
| AaveV3MetisAssets                   |      224 |     24,352 |
| AaveV3MetisEModes                   |      224 |     24,352 |
| AaveV3MetisExternalLibraries        |      224 |     24,352 |
| AaveV3Optimism                      |      224 |     24,352 |
| AaveV3OptimismAssets                |      224 |     24,352 |
| AaveV3OptimismEModes                |      224 |     24,352 |
| AaveV3OptimismExternalLibraries     |      224 |     24,352 |
| AaveV3Polygon                       |      224 |     24,352 |
| AaveV3PolygonAssets                 |      224 |     24,352 |
| AaveV3PolygonEModes                 |      224 |     24,352 |
| AaveV3PolygonExternalLibraries      |      224 |     24,352 |
| AaveV3PolygonZkEvm                  |      224 |     24,352 |
| AaveV3PolygonZkEvmAssets            |      224 |     24,352 |
| AaveV3PolygonZkEvmEModes            |      224 |     24,352 |
| AaveV3Scroll                        |      224 |     24,352 |
| AaveV3ScrollAssets                  |      224 |     24,352 |
| AaveV3ScrollEModes                  |      224 |     24,352 |
| AaveV3ScrollExternalLibraries       |      224 |     24,352 |
| AaveWstethWithdrawer                |   19,744 |      4,832 |
| Address                             |      224 |     24,352 |
| CapsPlusRiskSteward                 |    9,632 |     14,944 |
| CapsPlusRiskStewardErrors           |    1,440 |     23,136 |
| ChainHelpers                        |      224 |     24,352 |
| ChainIds                            |      224 |     24,352 |
| ConfiguratorInputTypes              |      224 |     24,352 |
| Create2Utils                        |      480 |     24,096 |
| Create2UtilsZkSync                  |      480 |     24,096 |
| DataTypes                           |      224 |     24,352 |
| DefaultReserveInterestRateStrategy  |   17,696 |      6,880 |
| DeployV2EngineAvaLib                |      224 |     24,352 |
| DeployV2EngineEthAMMLib             |      224 |     24,352 |
| DeployV2EngineEthLib                |      224 |     24,352 |
| DeployV2EnginePolLib                |      224 |     24,352 |
| DeployV2RatesFactoryAvaLib          |      224 |     24,352 |
| DeployV2RatesFactoryEthAMMLib       |      224 |     24,352 |
| DeployV2RatesFactoryEthLib          |      224 |     24,352 |
| DeployV2RatesFactoryLib             |      224 |     24,352 |
| DeployV2RatesFactoryPolLib          |      224 |     24,352 |
| ERC1967Proxy                        |    5,088 |     19,488 |
| EngineFlags                         |      224 |     24,352 |
| Errors                              |   14,176 |     10,400 |
| FreezingSteward                     |    3,872 |     20,704 |
| GovV3Helpers                        |   11,936 |     12,640 |
| GovV3StorageHelpers                 |      224 |     24,352 |
| GovernanceV3Arbitrum                |      224 |     24,352 |
| GovernanceV3Avalanche               |      224 |     24,352 |
| GovernanceV3BNB                     |      224 |     24,352 |
| GovernanceV3Base                    |      224 |     24,352 |
| GovernanceV3Ethereum                |      224 |     24,352 |
| GovernanceV3Gnosis                  |      224 |     24,352 |
| GovernanceV3Metis                   |      224 |     24,352 |
| GovernanceV3Optimism                |      224 |     24,352 |
| GovernanceV3Polygon                 |      224 |     24,352 |
| GovernanceV3PolygonZkEvm            |      224 |     24,352 |
| GovernanceV3Scroll                  |      224 |     24,352 |
| GovernanceV3ZkSync                  |      224 |     24,352 |
| IpfsUtils                           |      224 |     24,352 |
| MiscAvalanche                       |      224 |     24,352 |
| MiscEthereum                        |      224 |     24,352 |
| MiscPolygon                         |      224 |     24,352 |
| MockERC20                           |   14,688 |      9,888 |
| MockERC721                          |   15,520 |      9,056 |
| PayloadsControllerUtils             |      224 |     24,352 |
| PercentageMath                      |      224 |     24,352 |
| ProxyAdmin                          |    7,200 |     17,376 |
| ProxyHelpers                        |      224 |     24,352 |
| ReserveConfiguration                |      480 |     24,096 |
| SafeERC20                           |      224 |     24,352 |
| SafeMath                            |      224 |     24,352 |
| StdStyle                            |      224 |     24,352 |
| StorageHelpers                      |      224 |     24,352 |
| StorageSlot                         |      224 |     24,352 |
| TestNetChainIds                     |      224 |     24,352 |
| TransparentProxyFactory             |    8,608 |     15,968 |
| TransparentUpgradeableProxy         |   13,536 |     11,040 |
| V2RateStrategyFactory               |   22,496 |      2,080 |
| WadRayMath                          |      224 |     24,352 |
| console                             |      224 |     24,352 |
| safeconsole                         |      224 |     24,352 |
| stdError                            |    1,568 |     23,008 |
| stdJson                             |      224 |     24,352 |
| stdMath                             |      224 |     24,352 |
| stdStorage                          |      224 |     24,352 |
| stdStorageSafe                      |      224 |     24,352 |
| stdToml                             |      224 |     24,352 |
Test success 🌈

Please sign in to comment.