From 82bb5b6f946e1f313935b50cd2d6ccfbd5a04cfc Mon Sep 17 00:00:00 2001 From: Ori Pomerantz Date: Fri, 29 Sep 2023 07:42:14 -0500 Subject: [PATCH] docs(world): add NatSpec to Create2, Create2Factory (#1628) --- packages/world/src/Create2.sol | 12 ++++++++++++ packages/world/src/Create2Factory.sol | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/world/src/Create2.sol b/packages/world/src/Create2.sol index 36ee580a9f..3b06186d5c 100644 --- a/packages/world/src/Create2.sol +++ b/packages/world/src/Create2.sol @@ -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 @@ -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) diff --git a/packages/world/src/Create2Factory.sol b/packages/world/src/Create2Factory.sol index 4ac4b4986c..30c9bec11b 100644 --- a/packages/world/src/Create2Factory.sol +++ b/packages/world/src/Create2Factory.sol @@ -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);