Proxy

Clones

Git Source

Authors: cosimo.demedici.eth (https://github.com/ninfa-labs/ninfa-contracts), modified from OpenZeppelin Contracts v5.1.0 (access/AccessControl)

Implements the EIP 1167 standard for deploying minimal proxy contracts, also known as "clones". This standard provides a minimal bytecode implementation that delegates all calls to a known, fixed address, allowing to clone contract functionality in an immutable way. The library includes functions to deploy a proxy using either create (traditional deployment) or create2 (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the deterministic method.

Functions

clone

Deploys a clone that mimics the behaviour of implementation and returns its address.

This function uses the create opcode, which should never revert.

function clone(address implementation) internal returns (address instance);

Parameters

Name
Type
Description

implementation

address

The address of the contract to clone.

Returns

Name
Type
Description

instance

address

The address of the deployed clone.

cloneDeterministic

Deploys a clone that mimics the behaviour of implementation and returns its address.

This function uses the create2 opcode and a salt to deterministically deploy the clone. Using the same implementation and salt multiple times will revert, since the clones cannot be deployed twice at the same address.

Parameters

Name
Type
Description

implementation

address

The address of the contract to clone.

salt

bytes32

The salt for deterministic deployment.

Returns

Name
Type
Description

instance

address

The address of the deployed clone.

predictDeterministicAddress

Computes the address of a clone deployed using {Clones-cloneDeterministic}.

Parameters

Name
Type
Description

implementation

address

The address of the contract to clone.

salt

bytes32

The salt for deterministic deployment.

deployer

address

The address of the deployer.

Returns

Name
Type
Description

predicted

address

The predicted address of the deployed clone.

predictDeterministicAddress

Computes the address of a clone deployed using {Clones-cloneDeterministic}.

Parameters

Name
Type
Description

implementation

address

The address of the contract to clone.

salt

bytes32

The salt for deterministic deployment.

Returns

Name
Type
Description

predicted

address

The predicted address of the deployed clone.

Last updated