Skip to content

Commit

Permalink
Merge pull request #2 from Schlagonia/base
Browse files Browse the repository at this point in the history
build: base deployer
  • Loading branch information
Schlagonia authored Apr 21, 2024
2 parents 567e50d + 4fd1f3f commit ef3cd38
Show file tree
Hide file tree
Showing 9 changed files with 598 additions and 280 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Check out github repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 1

Expand All @@ -27,7 +27,7 @@ jobs:
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Restore yarn cache
uses: actions/cache@v2
uses: actions/cache@v3
id: yarn-cache
with:
path: |
Expand All @@ -50,9 +50,9 @@ jobs:

steps:
- name: Check out github repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run commitlint
uses: wagoid/commitlint-github-action@v2
uses: wagoid/commitlint-github-action@v5
129 changes: 122 additions & 7 deletions src/DeployerBase.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,135 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.20;

Check warning on line 2 in src/DeployerBase.sol

View workflow job for this annotation

GitHub Actions / solidity

Compiler version ^0.8.20 does not satisfy the 0.8.18 semver requirement

import {Proxy} from "@zkevm-stb/Proxy.sol";
import {ICREATE3Factory} from "./interfaces/ICREATE3Factory.sol";
import {IPolygonZkEVMBridge} from "./interfaces/Polygon/IPolygonZkEVMBridge.sol";

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/**
* @title DeployerBase
* @notice To be inherited by the L1 and L2 Deployer's for common functionality.
*/
abstract contract DeployerBase {
bytes32 public constant ESCROW_IMPLEMENTATION =
keccak256("Escrow Implementation");
bytes32 public constant L1_DEPLOYER = keccak256("L1 Deployer");
bytes32 public constant L2_DEPLOYER = keccak256("L2 Deployer");

contract DeployerBase {
/// @notice Address of the ICREATE3Factory contract used for deployment
ICREATE3Factory internal constant create3Factory =

Check warning on line 19 in src/DeployerBase.sol

View workflow job for this annotation

GitHub Actions / solidity

Constant name must be in capitalized SNAKE_CASE
ICREATE3Factory(0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1);

address public immutable counterPartContract;
/// @notice Immutable original chain ID
uint256 public immutable originalChainID;

Check warning on line 23 in src/DeployerBase.sol

View workflow job for this annotation

GitHub Actions / solidity

Immutable variables name are set to be in capitalized SNAKE_CASE

address public immutable polygonZkEVMBridge;
/// @notice Address of the PolygonZkEVMBridge contract
IPolygonZkEVMBridge public immutable polygonZkEVMBridge;

Check warning on line 26 in src/DeployerBase.sol

View workflow job for this annotation

GitHub Actions / solidity

Immutable variables name are set to be in capitalized SNAKE_CASE

constructor(address _counterPartContract, address _polygonZkEVMBridge) {
counterPartContract = _counterPartContract;
polygonZkEVMBridge = _polygonZkEVMBridge;
constructor(address _polygonZkEVMBridge) {
polygonZkEVMBridge = IPolygonZkEVMBridge(_polygonZkEVMBridge);
originalChainID = block.chainid;
}

/**
* @notice Abstract functions to get the Layer 1 deployer address
* @return Address of the Layer 1 deployer
*/
function getL1Deployer() public view virtual returns (address);

/**
* @notice Abstract functions to get the Layer 2 deployer address
* @return Address of the Layer 2 deployer
*/
function getL2Deployer() public view virtual returns (address);

/**
* @notice Abstract functions to get the Escrow Implementation address
* @return Address of the Escrow Implementation.
*/
function getEscrowImplementation() external view virtual returns (address);

/**
* @notice Get expected L2 token address for a given asset
* @param _l1TokenAddress Address of the L1 token
* @return Address of the expected L2 token contract
*/
function getL2TokenAddress(
address _l1TokenAddress
) public view virtual returns (address) {
return
create3Factory.getDeployed(
getL2Deployer(),
keccak256(abi.encodePacked(bytes("L2Token:"), _l1TokenAddress))
);
}

/**
* @notice Get expected L1 escrow address for a given asset
* @param _l1TokenAddress Address of the L1 token
* @return Address of the expected L1 escrow contract
*/
function getL1EscrowAddress(
address _l1TokenAddress
) public view virtual returns (address) {
return
create3Factory.getDeployed(
getL1Deployer(),
keccak256(abi.encodePacked(bytes("L1Escrow:"), _l1TokenAddress))
);
}

/**
* @notice Get expected L2 escrow address for a given asset
* @param _l1TokenAddress Address of the L1 token
* @return Address of the expected L2 escrow contract
*/
function getL2EscrowAddress(
address _l1TokenAddress
) public view virtual returns (address) {
return
create3Factory.getDeployed(
getL2Deployer(),
keccak256(abi.encodePacked(bytes("L2Escrow:"), _l1TokenAddress))
);
}

/**
* @notice Get expected L2 converter address for a given asset
* @param _l1TokenAddress Address of the L1 token
* @return Address of the expected L2 converter contract
*/
function getL2ConvertorAddress(
address _l1TokenAddress
) public view virtual returns (address) {
return
create3Factory.getDeployed(
getL2Deployer(),
keccak256(
abi.encodePacked(
bytes("L2TokenConverter:"),
_l1TokenAddress
)
)
);
}

/**
* @notice Deploy a contract using CREATE3
* @param _salt Salt value for contract deployment
* @param _implementation Address of the contract implementation
* @param _initData Data to initialize the contract with
* @return Address of the deployed contract
*/
function _create3Deploy(
bytes32 _salt,
address _implementation,
bytes memory _initData
) internal returns (address) {
bytes memory _creationCode = abi.encodePacked(
type(Proxy).creationCode,
abi.encode(_implementation, _initData)
);

return create3Factory.deploy(_salt, _creationCode);
}
}
Loading

0 comments on commit ef3cd38

Please sign in to comment.