Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Aug 28, 2024
1 parent 2dd6cd0 commit 45cdd11
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
28 changes: 14 additions & 14 deletions contracts/proxy/Clones.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ library Clones {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
bytes memory bytecode = _cloneWithImmutableArgsCode(implementation, args);
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
assembly ("memory-safe") {
instance := create(value, add(bytecode, 0x20), mload(bytecode))
}
Expand All @@ -169,53 +169,53 @@ library Clones {
* `implementation` and `salt` multiple time will revert, since the clones cannot be deployed twice at the same
* address.
*/
function cloneWithImmutableArgsDeterministic(
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal returns (address instance) {
return cloneWithImmutableArgsDeterministic(implementation, args, salt, 0);
return cloneDeterministicWithImmutableArgs(implementation, args, salt, 0);
}

/**
* @dev Same as {xref-Clones-cloneWithImmutableArgsDeterministic-address-bytes-bytes32-}[cloneWithImmutableArgsDeterministic],
* @dev Same as {xref-Clones-cloneDeterministicWithImmutableArgs-address-bytes-bytes32-}[cloneDeterministicWithImmutableArgs],
* but with a `value` parameter to send native currency to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneWithImmutableArgsDeterministic(
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
uint256 value
) internal returns (address instance) {
bytes memory bytecode = _cloneWithImmutableArgsCode(implementation, args);
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.deploy(value, salt, bytecode);
}

/**
* @dev Computes the address of a clone deployed using {Clones-cloneWithImmutableArgsDeterministic}.
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictWithImmutableArgsDeterministicAddress(
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
bytes memory bytecode = _cloneWithImmutableArgsCode(implementation, args);
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.computeAddress(salt, keccak256(bytecode), deployer);
}

/**
* @dev Computes the address of a clone deployed using {Clones-cloneWithImmutableArgsDeterministic}.
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictWithImmutableArgsDeterministicAddress(
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal view returns (address predicted) {
return predictWithImmutableArgsDeterministicAddress(implementation, args, salt, address(this));
return predictDeterministicAddressWithImmutableArgs(implementation, args, salt, address(this));
}

/**
Expand All @@ -224,7 +224,7 @@ library Clones {
* - If `instance` is a clone that was deployed using `clone` or `cloneDeterministic`, this
* function will return an empty array.
* - If `instance` is a clone that was deployed using `cloneWithImmutableArgs` or
* `cloneWithImmutableArgsDeterministic`, this function will return the args array used at
* `cloneDeterministicWithImmutableArgs`, this function will return the args array used at
* creation.
* - If `instance` is NOT a clone deployed using this library, the behavior is undefined. This
* function should only be used to check addresses that are known to be clones.
Expand All @@ -247,7 +247,7 @@ library Clones {
* NOTE: https://eips.ethereum.org/EIPS/eip-3860[EIP-3860] limits the length of the `initcode` to 49152 bytes.
* With the proxy code taking 45 bytes, that limits the length of the immutable args to 49107 bytes.
*/
function _cloneWithImmutableArgsCode(
function _cloneCodeWithImmutableArgs(
address implementation,
bytes memory args
) private pure returns (bytes memory) {
Expand Down
6 changes: 3 additions & 3 deletions test/proxy/Clones.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ contract ClonesTest is Test {
assertEq(spillage, bytes32(0));
}

function testSymbolicPredictWithImmutableArgsDeterministicAddressSpillage(
function testSymbolicPredictDeterministicAddressWithImmutableArgsSpillage(
address implementation,
bytes32 salt,
bytes memory args
) public {
vm.assume(args.length < 0xffd3);

address predicted = Clones.predictWithImmutableArgsDeterministicAddress(implementation, args, salt);
address predicted = Clones.predictDeterministicAddressWithImmutableArgs(implementation, args, salt);
bytes32 spillage;
/// @solidity memory-safe-assembly
assembly {
Expand Down Expand Up @@ -72,7 +72,7 @@ contract ClonesTest is Test {
vm.assume(args.length < 0xffd3);

address instance1 = Clones.cloneWithImmutableArgs(address(this), args);
address instance2 = Clones.cloneWithImmutableArgsDeterministic(address(this), args, salt);
address instance2 = Clones.cloneDeterministicWithImmutableArgs(address(this), args, salt);

// both clones have the same code
assertEq(instance1.code, instance2.code);
Expand Down
14 changes: 7 additions & 7 deletions test/proxy/Clones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ async function fixture() {
async (opts = {}) => {
const salt = opts.salt ?? ethers.randomBytes(32);
const clone = await (args
? factory.$cloneWithImmutableArgsDeterministic.staticCall(implementation, args, salt)
? factory.$cloneDeterministicWithImmutableArgs.staticCall(implementation, args, salt)
: factory.$cloneDeterministic.staticCall(implementation, salt)
).then(address => implementation.attach(address));
const tx = await (args
? opts.deployValue
? factory.$cloneWithImmutableArgsDeterministic(
? factory.$cloneDeterministicWithImmutableArgs(
implementation,
args,
salt,
ethers.Typed.uint256(opts.deployValue),
)
: factory.$cloneWithImmutableArgsDeterministic(implementation, args, salt)
: factory.$cloneDeterministicWithImmutableArgs(implementation, args, salt)
: opts.deployValue
? factory.$cloneDeterministic(implementation, salt, ethers.Typed.uint256(opts.deployValue))
: factory.$cloneDeterministic(implementation, salt));
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('Clones', function () {

const deployClone = () =>
args
? this.factory.$cloneWithImmutableArgsDeterministic(this.implementation, args, salt)
? this.factory.$cloneDeterministicWithImmutableArgs(this.implementation, args, salt)
: this.factory.$cloneDeterministic(this.implementation, salt);

// deploy once
Expand All @@ -132,15 +132,15 @@ describe('Clones', function () {
);

if (args) {
const predicted = await this.factory.$predictWithImmutableArgsDeterministicAddress(
const predicted = await this.factory.$predictDeterministicAddressWithImmutableArgs(
this.implementation,
args,
salt,
);
expect(predicted).to.equal(expected);

await expect(this.factory.$cloneWithImmutableArgsDeterministic(this.implementation, args, salt))
.to.emit(this.factory, 'return$cloneWithImmutableArgsDeterministic_address_bytes_bytes32')
await expect(this.factory.$cloneDeterministicWithImmutableArgs(this.implementation, args, salt))
.to.emit(this.factory, 'return$cloneDeterministicWithImmutableArgs_address_bytes_bytes32')
.withArgs(predicted);
} else {
const predicted = await this.factory.$predictDeterministicAddress(this.implementation, salt);
Expand Down

0 comments on commit 45cdd11

Please sign in to comment.