Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/upgrade mainnets v2 #427

Merged
merged 19 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/apps/UsingWitnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract contract UsingWitnet
__witnet = _wrb;
__witnetDefaultSLA = WitnetV2.RadonSLA({
// Number of nodes in the Witnet blockchain that will take part in solving the data request:
committeeSize: 15,
committeeSize: 10,
// Fee in $nanoWIT paid to every node in the Witnet blockchain involved in solving the data request:
witnessingFeeNanoWit: 2 * 10 ** 8 // defaults to 0.2 $WIT
});
Expand Down
85 changes: 85 additions & 0 deletions contracts/core/customs/WitnetDeployerCfxCore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "../WitnetProxy.sol";

/// @notice WitnetDeployer contract used both as CREATE2 factory (EIP-1014) for Witnet artifacts,
/// @notice and CREATE3 factory (EIP-3171) for Witnet proxies, on the Conflux Core Ecosystem.
/// @author Guillermo Díaz <[email protected]>

contract WitnetDeployerCfxCore {

/// @notice Use given `_initCode` and `_salt` to deploy a contract into a deterministic address.
/// @dev The address of deployed address will be determined by both the `_initCode` and the `_salt`, but not the address
/// @dev nor the nonce of the caller (i.e. see EIP-1014).
/// @param _initCode Creation code, including construction logic and input parameters.
/// @param _salt Arbitrary value to modify resulting address.
/// @return _deployed Just deployed contract address.
function deploy(bytes memory _initCode, bytes32 _salt)
public
returns (address _deployed)
{
_deployed = determineAddr(_initCode, _salt);
if (_deployed.code.length == 0) {
assembly {
_deployed := create2(0, add(_initCode, 0x20), mload(_initCode), _salt)
}
require(_deployed != address(0), "WitnetDeployer: deployment failed");
}
}

/// @notice Determine counter-factual address of the contract that would be deployed by the given `_initCode` and a `_salt`.
/// @param _initCode Creation code, including construction logic and input parameters.
/// @param _salt Arbitrary value to modify resulting address.
/// @return Deterministic contract address.
function determineAddr(bytes memory _initCode, bytes32 _salt)
public view
returns (address)
{
return address(
(uint160(uint(keccak256(
abi.encodePacked(
bytes1(0xff),
address(this),
_salt,
keccak256(_initCode)
)
))) & uint160(0x0fffFFFFFfFfffFfFfFFffFffFffFFfffFfFFFFf)
) | uint160(0x8000000000000000000000000000000000000000)
);
}

function determineProxyAddr(bytes32 _salt)
public view
returns (address)
{
return determineAddr(type(WitnetProxy).creationCode, _salt);
}

function proxify(bytes32 _proxySalt, address _firstImplementation, bytes memory _initData)
external
returns (WitnetProxy)
{
address _proxyAddr = determineProxyAddr(_proxySalt);
if (_proxyAddr.code.length == 0) {
// deploy the WitnetProxy
deploy(type(WitnetProxy).creationCode, _proxySalt);
// settle first implementation address,
WitnetProxy(payable(_proxyAddr)).upgradeTo(
_firstImplementation,
// and initialize it, providing
abi.encode(
// the owner (i.e. the caller of this function)
msg.sender,
// and some (optional) initialization data
_initData
)
);
return WitnetProxy(payable(_proxyAddr));
} else {
revert("WitnetDeployer: already proxified");
}
}

}
84 changes: 84 additions & 0 deletions contracts/core/customs/WitnetDeployerMeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "../WitnetProxy.sol";

/// @notice WitnetDeployer contract used both as CREATE2 factory (EIP-1014) for Witnet artifacts,
/// @notice and CREATE3 factory (EIP-3171) for Witnet proxies, on the Meter Ecosystem.
/// @author Guillermo Díaz <[email protected]>

contract WitnetDeployerMeter {

/// @notice Use given `_initCode` and `_salt` to deploy a contract into a deterministic address.
/// @dev The address of deployed address will be determined by both the `_initCode` and the `_salt`, but not the address
/// @dev nor the nonce of the caller (i.e. see EIP-1014).
/// @param _initCode Creation code, including construction logic and input parameters.
/// @param _salt Arbitrary value to modify resulting address.
/// @return _deployed Just deployed contract address.
function deploy(bytes memory _initCode, bytes32 _salt)
public
returns (address _deployed)
{
_deployed = determineAddr(_initCode, _salt);
if (_deployed.code.length == 0) {
assembly {
_deployed := create2(0, add(_initCode, 0x20), mload(_initCode), _salt)
}
require(_deployed != address(0), "WitnetDeployerMeter: deployment failed");
}
}

/// @notice Determine counter-factual address of the contract that would be deployed by the given `_initCode` and a `_salt`.
/// @param _initCode Creation code, including construction logic and input parameters.
/// @param _salt Arbitrary value to modify resulting address.
/// @return Deterministic contract address.
function determineAddr(bytes memory _initCode, bytes32 _salt)
public view
returns (address)
{
return address(
uint160(uint(keccak256(
abi.encodePacked(
bytes1(0xff),
address(this),
_salt,
keccak256(_initCode)
)
)))
);
}

function determineProxyAddr(bytes32 _salt)
public view
returns (address)
{
return determineAddr(type(WitnetProxy).creationCode, _salt);
}

function proxify(bytes32 _proxySalt, address _firstImplementation, bytes memory _initData)
external
returns (WitnetProxy)
{
address _proxyAddr = determineProxyAddr(_proxySalt);
if (_proxyAddr.code.length == 0) {
// deploy the WitnetProxy
deploy(type(WitnetProxy).creationCode, _proxySalt);
// settle first implementation address,
WitnetProxy(payable(_proxyAddr)).upgradeTo(
_firstImplementation,
// and initialize it, providing
abi.encode(
// the owner (i.e. the caller of this function)
msg.sender,
// and some (optional) initialization data
_initData
)
);
return WitnetProxy(payable(_proxyAddr));
} else {
revert("WitnetDeployerMeter: already proxified");
}
}

}
4 changes: 0 additions & 4 deletions contracts/core/customs/WitnetRequestFactoryCfxCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ contract WitnetRequestFactoryCfxCore
is
WitnetRequestFactoryDefault
{
function class() virtual override public view returns (string memory) {
return type(WitnetRequestFactoryCfxCore).name;
}

constructor(
WitnetOracle _witnet,
WitnetRequestBytecodes _registry,
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/defaults/WitnetOracleTrustableBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ abstract contract WitnetOracleTrustableBase
_batchResults[_i].queryId,
string(abi.encodePacked(
class(),
"invalid report data"
": invalid report data"
))
);
} else {
Expand Down
Loading