Skip to content

Commit

Permalink
Merge branch 'release/core-contracts/12' into martinvol/AddOraclesToF…
Browse files Browse the repository at this point in the history
…eeHandlersSellers
  • Loading branch information
pahor167 authored Oct 17, 2024
2 parents 43a27f0 + a5a33dc commit 2f4f14e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
29 changes: 15 additions & 14 deletions packages/protocol/contracts-0.8/common/ProxyFactory08.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,34 @@ import "../../contracts/common/interfaces/IProxy.sol";

import "@openzeppelin/contracts8/utils/Create2.sol";

/**
* @title Used for deploying Proxy contracts using Create2.
*/
contract ProxyFactory08 {
// Deploys a new bytecode and transfers ownership to the provided address
// Calls with the same initCode that results in the same bytecode, sender and salt
// will revert as two contracts can not get deployed to the same address
/**
* @notice Deploys a new bytecode and transfers ownership to the provided address.
* @param value Amount of CELO to transfer to the new contract.
* @param owner The proxy owner to set.
* @param _salt The Create2 salt to use.
* @param initCode The contract init code to use for deployment.
* @return Address of the deployed contract.
* @dev Calls with the same initCode, sender, and salt will revert as two
* contracts cannot get deployed to the same address.
* @dev Assumes the deployed contract is a Proxy with a `_transferOwnership`
* function that will be called. Will revert if that call reverts.
*/
function deployArbitraryByteCode(
uint256 value,
address owner,
uint256 _salt,
bytes memory initCode
) external returns (address) {
return _deployArbitraryByteCode(value, owner, _salt, initCode);
}

function _deployArbitraryByteCode(
uint256 value,
address owner,
uint256 _salt,
bytes memory initCode
) private returns (address) {
address deployedContract = Create2.deploy(
value,
keccak256(abi.encode(_salt, msg.sender)),
abi.encodePacked(initCode)
);

// function will fail if contract doesn't implement
// _transferOwnership function
IProxy proxy = IProxy(deployedContract);
proxy._transferOwnership(owner);

Expand Down
16 changes: 16 additions & 0 deletions packages/protocol/contracts/common/Create2.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
pragma solidity ^0.5.13;

/**
* @title Used for deploying contracts using the CREATE2 opcode.
*/
library Create2 {
/**
* @notice Deploys a contract with CREATE2.
* @param salt The CREATE2 salt.
* @param initCode The contract init code to use for deployment.
* @return Address of the deployed contract.
*/
function deploy(bytes32 salt, bytes memory initCode) internal returns (address) {
address deployedAddress;
assembly {
Expand All @@ -12,6 +21,13 @@ library Create2 {
return deployedAddress;
}

/**
* @notice Computes the CREATE2 address for given inputs.
* @param deployer Address of the deployer.
* @param salt The CREATE2 salt.
* @param initCodeHash Hash of the init code used for deployment.
* @return The address at which such a contract would be deployed.
*/
function computeAddress(
address deployer,
bytes32 salt,
Expand Down
23 changes: 14 additions & 9 deletions packages/protocol/contracts/common/ProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ pragma solidity ^0.5.13;
import "./Proxy.sol";
import "./interfaces/IProxyFactory.sol";

/**
* @title Used for deploying Proxy contracts.
*/
contract ProxyFactory is IProxyFactory {
// Deploys a new proxy contract and transfers ownership to the provided address
function deployProxy(address owner) external returns (address) {
return _deployProxy(owner);
}

// Deploys a new proxy contract and transfers ownership to the sender
/**
* @notice Deploys a new proxy contract and transfers ownership to the sender
* @return Address of the deployed proxy.
*/
function deployProxy() external returns (address) {
return _deployProxy(msg.sender);
return deployProxy(msg.sender);
}

// Deploys a new proxy contract and transfers ownership to the provided address
function _deployProxy(address owner) private returns (address) {
/**
* @notice Deploys a new proxy contract and transfers ownership to the provided address
* @param owner The address to transfer ownership to.
* @return Address of the deployed proxy.
*/
function deployProxy(address owner) public returns (address) {
Proxy proxy = new Proxy();
proxy._transferOwnership(owner);
return address(proxy);
Expand Down

0 comments on commit 2f4f14e

Please sign in to comment.