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

Feat/ten testnet #403

Merged
merged 11 commits into from
Mar 21, 2024
5 changes: 5 additions & 0 deletions contracts/data/WitnetBoardData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ abstract contract WitnetBoardData {
_;
}

modifier onlyRequester(uint256 _queryId) {
require(__query(_queryId).from == msg.sender, "WitnetRequestBoard: only the requester");
_;
}

/// Asserts the give query was actually posted before calling this method.
modifier wasPosted(uint256 _queryId) {
require(_queryId > 0 && _queryId <= __storage().numQueries, "WitnetRequestBoard: not yet posted");
Expand Down
12 changes: 6 additions & 6 deletions contracts/impls/core/customs/WitnetRequestBoardTrustableBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ abstract contract WitnetRequestBoardTrustableBase
/// @dev or deleted.
/// @param _queryId The unique identifier of a previously posted query.
function readRequest(uint256 _queryId)
external view
override
public view
virtual override
inStatus(_queryId, Witnet.QueryStatus.Posted)
returns (Witnet.Request memory _request)
{
Expand Down Expand Up @@ -684,8 +684,8 @@ abstract contract WitnetRequestBoardTrustableBase
/// @dev Fails if the `_queryId` is not in 'Reported' status.
/// @param _queryId The unique query identifier
function readResponse(uint256 _queryId)
external view
override
public view
virtual override
inStatus(_queryId, Witnet.QueryStatus.Reported)
returns (Witnet.Response memory _response)
{
Expand Down Expand Up @@ -720,8 +720,8 @@ abstract contract WitnetRequestBoardTrustableBase
/// @dev Fails if the `_queryId` is not in 'Reported' status.
/// @param _queryId The unique query identifier
function readResponseResult(uint256 _queryId)
external view
override
public view
virtual override
inStatus(_queryId, Witnet.QueryStatus.Reported)
returns (Witnet.Result memory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: MIT

/* solhint-disable var-name-mixedcase */

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../WitnetRequestBoardTrustableDefault.sol";

/// @title Witnet Request Board "trustable" implementation contract.
/// @notice Contract to bridge requests to Witnet Decentralized Oracle Network.
/// @dev This contract enables posting requests that Witnet bridges will insert into the Witnet network.
/// The result of the requests will be posted back to this contract by the bridge nodes too.
/// @author The Witnet Foundation
contract WitnetRequestBoardTrustableObscuro
is
WitnetRequestBoardTrustableDefault
{
constructor(
WitnetRequestFactory _factory,
bool _upgradable,
bytes32 _versionTag,
uint256 _reportResultGasLimit
)
WitnetRequestBoardTrustableDefault(
_factory,
_upgradable,
_versionTag,
_reportResultGasLimit
)
{}

// ================================================================================================================
// --- Overrides implementation of 'IWitnetRequestBoardView' ------------------------------------------------------

/// @notice Retrieves the whole Request record posted to the Witnet Request Board.
/// @dev Fails if the `_queryId` is not valid or, if it has already been reported
/// @dev or deleted, or if `msg.sender` is not the actual requester.
/// @param _queryId The unique identifier of a previously posted query.
function readRequest(uint256 _queryId)
public view
virtual override
onlyRequester(_queryId)
returns (Witnet.Request memory)
{
return WitnetRequestBoardTrustableBase.readRequest(_queryId);
}

/// Retrieves the Witnet-provided result, and metadata, to a previously posted request.
/// @dev Fails if the `_queryId` is not in 'Reported' status, or if `msg.sender` is not the actual requester.
/// @param _queryId The unique query identifier
function readResponse(uint256 _queryId)
public view
virtual override
onlyRequester(_queryId)
returns (Witnet.Response memory _response)
{
return WitnetRequestBoardTrustableBase.readResponse(_queryId);
}

/// Retrieves the Witnet-provided CBOR-bytes result of a previously posted request.
/// @dev Fails if the `_queryId` is not in 'Reported' status, or if `msg.sender` is not the actual requester.
/// @param _queryId The unique query identifier
function readResponseResult(uint256 _queryId)
public view
virtual override
onlyRequester(_queryId)
returns (Witnet.Result memory)
{
return WitnetRequestBoardTrustableBase.readResponseResult(_queryId);
}

}
78 changes: 40 additions & 38 deletions migrations/scripts/1_Create2Factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,49 @@ module.exports = async function (deployer, network, [, from,,,,, master]) {
if (!addresses[ecosystem]) addresses[ecosystem] = {}
if (!addresses[ecosystem][network]) addresses[ecosystem][network] = {}

let factory
if (utils.isNullAddress(addresses[ecosystem][network]?.Create2Factory)) {
await deployer.deploy(Create2Factory, { from: master })
factory = await Create2Factory.deployed()
addresses[ecosystem][network].Create2Factory = factory.address
if (!isDryRun) {
utils.saveAddresses(addresses)
if (addresses[ecosystem][network]?.Create2Factory !== undefined) {
let factory
if (addresses[ecosystem][network].Create2Factory === "") {
await deployer.deploy(Create2Factory, { from: master })
factory = await Create2Factory.deployed()
addresses[ecosystem][network].Create2Factory = factory.address
if (!isDryRun) {
utils.saveAddresses(addresses)
}
} else {
factory = await Create2Factory.at(addresses[ecosystem][network].Create2Factory)
Create2Factory.address = factory.address
utils.traceHeader("Skipping 'Create2Factory'")
console.info(" > Contract address:", factory.address)
console.info()
}
} else {
factory = await Create2Factory.at(addresses[ecosystem][network].Create2Factory)
Create2Factory.address = factory.address
utils.traceHeader("Skipping 'Create2Factory'")
console.info(" > Contract address:", factory.address)
console.info()
}

// Settle WitnetProxy bytecode and source code as to guarantee
// salted addresses remain as expected no matter if the solc version
// is changed in migrations/witnet.settings.js
utils.traceHeader("Defrosting 'WitnetProxy' artifact")
fs.writeFileSync(
`build/${ecosystem}/contracts/WitnetProxy.json`,
fs.readFileSync("migrations/abis/WitnetProxy.json"),
{ encoding: "utf8", flag: "w" }
)
const WitnetProxy = artifacts.require("WitnetProxy")
const metadata = JSON.parse(WitnetProxy.metadata)
console.info(" ", "> compiler: ", metadata.compiler.version)
console.info(" ", "> compilation target:", metadata.settings.compilationTarget)
console.info(" ", "> evmVersion: ", metadata.settings.evmVersion)
console.info(" ", "> optimizer: ", JSON.stringify(metadata.settings.optimizer))
// Settle WitnetProxy bytecode and source code as to guarantee
// salted addresses remain as expected no matter if the solc version
// is changed in migrations/witnet.settings.js
utils.traceHeader("Defrosting 'WitnetProxy' artifact")
fs.writeFileSync(
`build/${ecosystem}/contracts/WitnetProxy.json`,
fs.readFileSync("migrations/abis/WitnetProxy.json"),
{ encoding: "utf8", flag: "w" }
)
const WitnetProxy = artifacts.require("WitnetProxy")
const metadata = JSON.parse(WitnetProxy.metadata)
console.info(" ", "> compiler: ", metadata.compiler.version)
console.info(" ", "> compilation target:", metadata.settings.compilationTarget)
console.info(" ", "> evmVersion: ", metadata.settings.evmVersion)
console.info(" ", "> optimizer: ", JSON.stringify(metadata.settings.optimizer))

if (addresses[ecosystem][network]?.WitnetProxy === "") {
await deployer.deploy(WitnetProxy, { from })
addresses[ecosystem][network].WitnetProxy = WitnetProxy.address
} else {
if (addresses[ecosystem][network]?.WitnetProxy) {
WitnetProxy.address = addresses[ecosystem][network]?.WitnetProxy
if (addresses[ecosystem][network]?.WitnetProxy === "") {
await deployer.deploy(WitnetProxy, { from })
addresses[ecosystem][network].WitnetProxy = WitnetProxy.address
} else {
if (addresses[ecosystem][network]?.WitnetProxy) {
WitnetProxy.address = addresses[ecosystem][network]?.WitnetProxy
}
}
if (!isDryRun) {
utils.saveAddresses(addresses)
}
}
if (!isDryRun) {
utils.saveAddresses(addresses)
}
}
12 changes: 5 additions & 7 deletions migrations/scripts/3_WitnetBytecodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ module.exports = async function (deployer, network, [, from]) {

const artifactNames = merge(settings.artifacts.default, settings.artifacts[ecosystem], settings.artifacts[network])
const WitnetBytecodesImplementation = artifacts.require(artifactNames.WitnetBytecodes)
const create2FactoryAddr = addresses[ecosystem][network]?.Create2Factory

let proxy
if (utils.isNullAddress(addresses[ecosystem][network]?.WitnetBytecodes)) {
const factory = await Create2Factory.deployed()
if (
factory && !utils.isNullAddress(factory.address) &&
singletons?.WitnetBytecodes
) {
if (!utils.isNullAddress(create2FactoryAddr) && singletons?.WitnetBytecodes) {
// Deploy the proxy via a singleton factory and a salt...
const create2Factory = await Create2Factory.at(create2FactoryAddr)
const bytecode = WitnetProxy.toJSON().bytecode
const salt = singletons.WitnetBytecodes?.salt
? "0x" + ethUtils.setLengthLeft(
Expand All @@ -44,13 +42,13 @@ module.exports = async function (deployer, network, [, from]) {
).toString("hex")
: "0x0"

const proxyAddr = await factory.determineAddr.call(bytecode, salt, { from })
const proxyAddr = await create2Factory.determineAddr.call(bytecode, salt, { from })
if ((await web3.eth.getCode(proxyAddr)).length <= 3) {
// deploy instance only if not found in current network:
utils.traceHeader("Singleton inception of 'WitnetBytecodes':")
const balance = await web3.eth.getBalance(from)
const gas = singletons.WitnetBytecodes.gas
const tx = await factory.deploy(bytecode, salt, { from, gas })
const tx = await create2Factory.deploy(bytecode, salt, { from, gas })
utils.traceTx(
tx.receipt,
web3.utils.fromWei((balance - await web3.eth.getBalance(from)).toString())
Expand Down
9 changes: 4 additions & 5 deletions migrations/scripts/4_WitnetRequestFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@

const artifactNames = merge(settings.artifacts.default, settings.artifacts[ecosystem], settings.artifacts[network])
const WitnetRequestFactoryImplementation = artifacts.require(artifactNames.WitnetRequestFactory)
const create2FactoryAddr = addresses[ecosystem][network]?.Create2Factory

let proxy
if (utils.isNullAddress(addresses[ecosystem][network]?.WitnetRequestFactory)) {

Check failure on line 33 in migrations/scripts/4_WitnetRequestFactory.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Block must not be padded by blank lines
const create2Factory = await Create2Factory.deployed()
if (
create2Factory && !utils.isNullAddress(create2Factory.address) &&
singletons?.WitnetRequestFactory
) {

if (!utils.isNullAddress(create2FactoryAddr) && singletons?.WitnetRequestFactory) {
// Deploy the proxy via a singleton factory and a salt...
const create2Factory = await Create2Factory.at(create2FactoryAddr)
const bytecode = WitnetProxy.toJSON().bytecode
const salt = singletons.WitnetRequestFactory?.salt
? "0x" + ethUtils.setLengthLeft(
Expand Down
13 changes: 6 additions & 7 deletions migrations/scripts/5_WitnetRequestBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@

const artifactsName = merge(settings.artifacts.default, settings.artifacts[ecosystem], settings.artifacts[network])
const WitnetRequestBoardImplementation = artifacts.require(artifactsName.WitnetRequestBoard)
const create2FactoryAddr = addresses[ecosystem][network]?.Create2Factory


Check failure on line 33 in migrations/scripts/5_WitnetRequestBoard.js

View workflow job for this annotation

GitHub Actions / build (16.x)

More than 1 blank line not allowed
let proxy
const factory = await Create2Factory.deployed()
if (utils.isNullAddress(addresses[ecosystem][network]?.WitnetRequestBoard)) {
if (
factory && !utils.isNullAddress(factory.address) &&
singletons?.WitnetRequestBoard
) {
if (!utils.isNullAddress(create2FactoryAddr) && singletons?.WitnetPriceFeeds) {
// Deploy the proxy via a singleton factory and a salt...
const create2Factory = await Create2Factory.at(create2FactoryAddr)
const bytecode = WitnetProxy.toJSON().bytecode
const salt = singletons.WitnetRequestBoard?.salt
? "0x" + ethUtils.setLengthLeft(
Expand All @@ -46,13 +45,13 @@
).toString("hex")
: "0x0"

const proxyAddr = await factory.determineAddr.call(bytecode, salt, { from })
const proxyAddr = await create2Factory.determineAddr.call(bytecode, salt, { from })
if ((await web3.eth.getCode(proxyAddr)).length <= 3) {
// deploy instance only if not found in current network:
utils.traceHeader("Singleton inception of 'WitnetRequestBoard':")
const balance = await web3.eth.getBalance(from)
const gas = singletons.WitnetRequestBoard.gas
const tx = await factory.deploy(bytecode, salt, { from, gas })
const tx = await create2Factory.deploy(bytecode, salt, { from, gas })
utils.traceTx(
tx.receipt,
web3.utils.fromWei((balance - await web3.eth.getBalance(from)).toString())
Expand Down
9 changes: 3 additions & 6 deletions migrations/scripts/7_WitnetPriceFeeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = async function (deployer, network, [, from]) {

if (!addresses[ecosystem]) addresses[ecosystem] = {}
if (!addresses[ecosystem][network]) addresses[ecosystem][network] = {}
const create2FactoryAddr = addresses[ecosystem][network]?.Create2Factory

console.info()
if (!isDryRun && addresses[ecosystem][network].WitnetPriceFeeds === undefined) {
Expand Down Expand Up @@ -54,12 +55,9 @@ module.exports = async function (deployer, network, [, from]) {
if (addresses[ecosystem][network]?.WitnetPriceFeedsImplementation !== undefined || isDryRun) {
let proxy
if (utils.isNullAddress(addresses[ecosystem][network]?.WitnetPriceFeeds)) {
const create2Factory = await Create2Factory.deployed()
if (
create2Factory && !utils.isNullAddress(create2Factory.address) &&
singletons?.WitnetPriceFeeds
) {
if (!utils.isNullAddress(create2FactoryAddr) && singletons?.WitnetPriceFeeds) {
// Deploy the proxy via a singleton factory and a salt...
const create2Factory = await Create2Factory.at(create2FactoryAddr)
const bytecode = WitnetProxy.toJSON().bytecode
const salt = singletons.WitnetPriceFeeds?.salt
? "0x" + ethUtils.setLengthLeft(
Expand Down Expand Up @@ -99,7 +97,6 @@ module.exports = async function (deployer, network, [, from]) {
proxy = await WitnetProxy.at(addresses[ecosystem][network].WitnetPriceFeeds)
console.info(` Skipped: 'WitnetPriceFeeds' deployed at ${proxy.address}`)
}

let router
if (utils.isNullAddress(addresses[ecosystem][network]?.WitnetPriceFeedsImplementation)) {
await deployer.deploy(
Expand Down
Loading
Loading