Skip to content

Commit

Permalink
docs(world): add NatSpec to Create2, Create2Factory (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
qbzzt authored Sep 29, 2023
1 parent 6cd17d0 commit 82bb5b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/world/src/Create2.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.21;

/**
* @title Create2
* @dev Library to deploy contracts using the CREATE2 opcode.
*/
library Create2 {
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
Expand All @@ -13,9 +17,17 @@ library Create2 {
*
* - `bytecode` must not be empty.
* - `salt` must have not been used for `bytecode` already.
*
* @param byteCode The bytecode of the contract to be deployed.
* @param salt A 256-bit value that, combined with the bytecode, determines the address.
* @return addr The address of the newly deployed contract.
* @dev If the CREATE2 fails, reverts
*/
function deploy(bytes memory byteCode, uint256 salt) internal returns (address addr) {
assembly {
// byteCode is one word (0x20 bytes) with the length, followed by the actual
// code for the constructor. So the code starts at byteCode+0x20, and is mload(byteCode)
// bytes long.
addr := create2(0, add(byteCode, 0x20), mload(byteCode), salt)
if iszero(extcodesize(addr)) {
revert(0, 0)
Expand Down
13 changes: 11 additions & 2 deletions packages/world/src/Create2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ pragma solidity >=0.8.21;
import { Create2 } from "./Create2.sol";

/**
@dev Helper Contract to facilitate create2 deployment of Contracts.
*/
* @title Create2Factory
* @dev Helper Contract to facilitate create2 deployment of Contracts.
*/
contract Create2Factory {
/**
* @dev Emitted when a new contract is deployed using the `deployContract` function.
* @param addr The address of the newly deployed contract.
* @param salt The salt value used in the `CREATE2` operation.
*/
event ContractDeployed(address addr, uint256 salt);

/**
* @dev Deploys a new Contract using create2.
* @param byteCode The bytecode of the contract to be deployed.
* @param salt A 256-bit value that, combined with the bytecode, determines the address.
* @dev Emit ContractDeployed on success
*/
function deployContract(bytes memory byteCode, uint256 salt) public {
address addr = Create2.deploy(byteCode, salt);
Expand Down

0 comments on commit 82bb5b6

Please sign in to comment.