@layerzerolabs/create3-factory 2.1.23 → 2.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @layerzerolabs/create3-factory
2
2
 
3
+ ## 2.1.24
4
+
5
+ ### Patch Changes
6
+
7
+ - c663d78: remove duplicate `sleep` func
8
+
3
9
  ## 2.1.23
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: AGPL-3.0
2
+ pragma solidity >=0.8.0;
3
+
4
+ /// @notice Library for converting between addresses and bytes32 values.
5
+ /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/Bytes32AddressLib.sol)
6
+ library Bytes32AddressLib {
7
+ function fromLast20Bytes(bytes32 bytesValue) internal pure returns (address) {
8
+ return address(uint160(uint256(bytesValue)));
9
+ }
10
+
11
+ function fillLast12Bytes(address addressValue) internal pure returns (bytes32) {
12
+ return bytes32(bytes20(addressValue));
13
+ }
14
+ }
@@ -0,0 +1,83 @@
1
+ // SPDX-License-Identifier: AGPL-3.0
2
+ pragma solidity >=0.8.0;
3
+
4
+ import { Bytes32AddressLib } from "./Bytes32AddressLib.sol";
5
+
6
+ /// @notice Deploy to deterministic addresses without an initcode factor.
7
+ /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/CREATE3.sol)
8
+ /// @author Modified from 0xSequence (https://github.com/0xSequence/create3/blob/master/contracts/Create3.sol)
9
+ library CREATE3 {
10
+ using Bytes32AddressLib for bytes32;
11
+
12
+ //--------------------------------------------------------------------------------//
13
+ // Opcode | Opcode + Arguments | Description | Stack View //
14
+ //--------------------------------------------------------------------------------//
15
+ // 0x36 | 0x36 | CALLDATASIZE | size //
16
+ // 0x3d | 0x3d | RETURNDATASIZE | 0 size //
17
+ // 0x3d | 0x3d | RETURNDATASIZE | 0 0 size //
18
+ // 0x37 | 0x37 | CALLDATACOPY | //
19
+ // 0x36 | 0x36 | CALLDATASIZE | size //
20
+ // 0x3d | 0x3d | RETURNDATASIZE | 0 size //
21
+ // 0x34 | 0x34 | CALLVALUE | value 0 size //
22
+ // 0xf0 | 0xf0 | CREATE | newContract //
23
+ //--------------------------------------------------------------------------------//
24
+ // Opcode | Opcode + Arguments | Description | Stack View //
25
+ //--------------------------------------------------------------------------------//
26
+ // 0x67 | 0x67XXXXXXXXXXXXXXXX | PUSH8 bytecode | bytecode //
27
+ // 0x3d | 0x3d | RETURNDATASIZE | 0 bytecode //
28
+ // 0x52 | 0x52 | MSTORE | //
29
+ // 0x60 | 0x6008 | PUSH1 08 | 8 //
30
+ // 0x60 | 0x6018 | PUSH1 18 | 24 8 //
31
+ // 0xf3 | 0xf3 | RETURN | //
32
+ //--------------------------------------------------------------------------------//
33
+ bytes internal constant PROXY_BYTECODE = hex"67_36_3d_3d_37_36_3d_34_f0_3d_52_60_08_60_18_f3";
34
+
35
+ bytes32 internal constant PROXY_BYTECODE_HASH = keccak256(PROXY_BYTECODE);
36
+
37
+ function deploy(bytes32 salt, bytes memory creationCode, uint256 value) internal returns (address deployed) {
38
+ bytes memory proxyChildBytecode = PROXY_BYTECODE;
39
+
40
+ address proxy;
41
+ /// @solidity memory-safe-assembly
42
+ assembly {
43
+ // Deploy a new contract with our pre-made bytecode via CREATE2.
44
+ // We start 32 bytes into the code to avoid copying the byte length.
45
+ proxy := create2(0, add(proxyChildBytecode, 32), mload(proxyChildBytecode), salt)
46
+ }
47
+ require(proxy != address(0), "DEPLOYMENT_FAILED");
48
+
49
+ deployed = getDeployed(salt);
50
+ (bool success, ) = proxy.call{ value: value }(creationCode);
51
+ require(success && deployed.code.length != 0, "INITIALIZATION_FAILED");
52
+ }
53
+
54
+ function getDeployed(bytes32 salt) internal view returns (address) {
55
+ return getDeployed(salt, address(this));
56
+ }
57
+
58
+ function getDeployed(bytes32 salt, address creator) internal pure returns (address) {
59
+ address proxy = keccak256(
60
+ abi.encodePacked(
61
+ // Prefix:
62
+ bytes1(0xFF),
63
+ // Creator:
64
+ creator,
65
+ // Salt:
66
+ salt,
67
+ // Bytecode hash:
68
+ PROXY_BYTECODE_HASH
69
+ )
70
+ ).fromLast20Bytes();
71
+
72
+ return
73
+ keccak256(
74
+ abi.encodePacked(
75
+ // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01)
76
+ // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex)
77
+ hex"d6_94",
78
+ proxy,
79
+ hex"01" // Nonce of the proxy contract (1)
80
+ )
81
+ ).fromLast20Bytes();
82
+ }
83
+ }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: AGPL-3.0
2
+ pragma solidity ^0.8.13;
3
+
4
+ import { CREATE3 } from "./CREATE3.sol";
5
+
6
+ import { ICREATE3Factory } from "./ICREATE3Factory.sol";
7
+
8
+ /// @title Factory for deploying contracts to deterministic addresses via CREATE3
9
+ /// @author zefram.eth
10
+ /// @notice Enables deploying contracts using CREATE3. Each deployer (msg.sender) has
11
+ /// its own namespace for deployed addresses.
12
+ contract CREATE3Factory is ICREATE3Factory {
13
+ /// @inheritdoc ICREATE3Factory
14
+ function deploy(bytes32 salt, bytes memory creationCode) external payable override returns (address deployed) {
15
+ // hash salt with the deployer address to give each deployer its own namespace
16
+ salt = keccak256(abi.encodePacked(msg.sender, salt));
17
+ return CREATE3.deploy(salt, creationCode, msg.value);
18
+ }
19
+
20
+ /// @inheritdoc ICREATE3Factory
21
+ function getDeployed(address deployer, bytes32 salt) external view override returns (address deployed) {
22
+ // hash salt with the deployer address to give each deployer its own namespace
23
+ salt = keccak256(abi.encodePacked(deployer, salt));
24
+ return CREATE3.getDeployed(salt);
25
+ }
26
+ }
@@ -0,0 +1,22 @@
1
+ // SPDX-License-Identifier: AGPL-3.0
2
+ pragma solidity >=0.6.0;
3
+
4
+ /// @title Factory for deploying contracts to deterministic addresses via CREATE3
5
+ /// @author zefram.eth
6
+ /// @notice Enables deploying contracts using CREATE3. Each deployer (msg.sender) has
7
+ /// its own namespace for deployed addresses.
8
+ interface ICREATE3Factory {
9
+ /// @notice Deploys a contract using CREATE3
10
+ /// @dev The provided salt is hashed together with msg.sender to generate the final salt
11
+ /// @param salt The deployer-specific salt for determining the deployed contract's address
12
+ /// @param creationCode The creation code of the contract to deploy
13
+ /// @return deployed The address of the deployed contract
14
+ function deploy(bytes32 salt, bytes memory creationCode) external payable returns (address deployed);
15
+
16
+ /// @notice Predicts the address of a deployed contract
17
+ /// @dev The provided salt is hashed together with the deployer address to generate the final salt
18
+ /// @param deployer The deployer account that will call deploy()
19
+ /// @param salt The deployer-specific salt for determining the deployed contract's address
20
+ /// @return deployed The address of the contract that will be deployed
21
+ function getDeployed(address deployer, bytes32 salt) external view returns (address deployed);
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/create3-factory",
3
- "version": "2.1.23",
3
+ "version": "2.1.24",
4
4
  "license": "AGPL-3.0",
5
5
  "exports": {
6
6
  ".": {
@@ -13,6 +13,7 @@
13
13
  "main": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
15
15
  "files": [
16
+ "contracts/**/*",
16
17
  "deployments/**/*"
17
18
  ],
18
19
  "scripts": {
@@ -35,15 +36,15 @@
35
36
  "@ethersproject/abi": "^5.7.0",
36
37
  "@ethersproject/providers": "^5.7.0",
37
38
  "@layerzerolabs/hardhat-config": "^0.0.0",
38
- "@layerzerolabs/hardhat-tron": "^2.1.23",
39
- "@layerzerolabs/lz-definitions": "^2.1.23",
40
- "@layerzerolabs/lz-utilities": "^2.1.23",
41
- "@layerzerolabs/ops-cli": "^2.1.23",
42
- "@layerzerolabs/ops-core": "^2.1.23",
43
- "@layerzerolabs/ops-plugin-core": "^2.1.23",
44
- "@layerzerolabs/ops-utilities": "^2.1.23",
45
- "@layerzerolabs/tsup-config-next": "^2.1.23",
46
- "@layerzerolabs/typescript-config-next": "^2.1.23",
39
+ "@layerzerolabs/hardhat-tron": "^2.1.24",
40
+ "@layerzerolabs/lz-definitions": "^2.1.24",
41
+ "@layerzerolabs/lz-utilities": "^2.1.24",
42
+ "@layerzerolabs/ops-cli": "^2.1.24",
43
+ "@layerzerolabs/ops-core": "^2.1.24",
44
+ "@layerzerolabs/ops-plugin-core": "^2.1.24",
45
+ "@layerzerolabs/ops-utilities": "^2.1.24",
46
+ "@layerzerolabs/tsup-config-next": "^2.1.24",
47
+ "@layerzerolabs/typescript-config-next": "^2.1.24",
47
48
  "@matterlabs/hardhat-zksync-deploy": "^0.6.5",
48
49
  "@matterlabs/hardhat-zksync-solc": "^1.0.3",
49
50
  "@nomicfoundation/hardhat-chai-matchers": "^1.0.6",