diff --git a/contracts/InverseApi3ReaderProxyV1.sol b/contracts/InverseApi3ReaderProxyV1.sol index 69e1765..f55a946 100644 --- a/contracts/InverseApi3ReaderProxyV1.sol +++ b/contracts/InverseApi3ReaderProxyV1.sol @@ -1,34 +1,29 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.27; -import "./interfaces/IApi3ReaderProxyWithDappId.sol"; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "./interfaces/IInverseApi3ReaderProxyV1.sol"; /// @title An immutable proxy contract that inverts the value returned by an -/// IApi3ReaderProxyWithDappId data feed +/// IApi3ReaderProxy data feed /// @dev This contract implements the AggregatorV2V3Interface to be compatible /// with Chainlink aggregators. This allows the contract to be used as a drop-in /// replacement for Chainlink aggregators in existing dApps. /// Refer to https://github.com/api3dao/migrate-from-chainlink-to-api3 for more /// information about the Chainlink interface implementation. contract InverseApi3ReaderProxyV1 is IInverseApi3ReaderProxyV1 { - /// @notice IApi3ReaderProxyWithDappId contract address + /// @notice IApi3ReaderProxy contract address address public immutable override proxy; - /// @notice dApp ID of the proxy - uint256 public immutable override dappId; - - /// @param proxy_ IApi3ReaderProxyWithDappId contract address + /// @param proxy_ IApi3ReaderProxy contract address constructor(address proxy_) { if (proxy_ == address(0)) { revert ZeroProxyAddress(); } proxy = proxy_; - dappId = IApi3ReaderProxyWithDappId(proxy_).dappId(); } - /// @notice Returns the inverted value of the underlying - /// IApi3ReaderProxyWithDappId + /// @notice Returns the inverted value of the underlying IApi3ReaderProxy /// @dev Calculates `int224(1e36) / baseValue`. The operation will revert if /// `baseValue` is zero. If `baseValue` is non-zero but its absolute value is /// greater than `1e36`, the result of the integer division will be `0`. @@ -40,9 +35,8 @@ contract InverseApi3ReaderProxyV1 is IInverseApi3ReaderProxyV1 { override returns (int224 value, uint32 timestamp) { - (int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxyWithDappId( - proxy - ).read(); + (int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxy(proxy) + .read(); if (baseValue == 0) { revert DivisionByZero(); diff --git a/contracts/NormalizedApi3ReaderProxyV1.sol b/contracts/NormalizedApi3ReaderProxyV1.sol index 375b374..2ed00a4 100644 --- a/contracts/NormalizedApi3ReaderProxyV1.sol +++ b/contracts/NormalizedApi3ReaderProxyV1.sol @@ -15,9 +15,6 @@ contract NormalizedApi3ReaderProxyV1 is INormalizedApi3ReaderProxyV1 { /// @notice Chainlink AggregatorV2V3Interface contract address address public immutable override feed; - /// @notice dApp ID of the proxy - uint256 public immutable override dappId; - /// @notice Pre-calculated factor for scaling the feed's value to 18 /// decimals. int256 public immutable scalingFactor; @@ -27,8 +24,7 @@ contract NormalizedApi3ReaderProxyV1 is INormalizedApi3ReaderProxyV1 { bool public immutable isUpscaling; /// @param feed_ The address of the Chainlink AggregatorV2V3Interface feed - /// @param dappId_ dApp ID of the proxy - constructor(address feed_, uint256 dappId_) { + constructor(address feed_) { if (feed_ == address(0)) { revert ZeroProxyAddress(); } @@ -40,7 +36,6 @@ contract NormalizedApi3ReaderProxyV1 is INormalizedApi3ReaderProxyV1 { revert NoNormalizationNeeded(); } feed = feed_; - dappId = dappId_; uint8 delta = feedDecimals_ > 18 ? feedDecimals_ - 18 : 18 - feedDecimals_; diff --git a/contracts/PriceCappedApi3ReaderProxyV1.sol b/contracts/PriceCappedApi3ReaderProxyV1.sol index a594914..2e4d939 100644 --- a/contracts/PriceCappedApi3ReaderProxyV1.sol +++ b/contracts/PriceCappedApi3ReaderProxyV1.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.27; -import "./interfaces/IApi3ReaderProxyWithDappId.sol"; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "./interfaces/IPriceCappedApi3ReaderProxyV1.sol"; /** @@ -21,19 +21,16 @@ import "./interfaces/IPriceCappedApi3ReaderProxyV1.sol"; * floored at 0 if `lowerBound_` is 0. */ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 { - /// @notice IApi3ReaderProxyWithDappId contract address + /// @notice IApi3ReaderProxy contract address address public immutable override proxy; - /// @notice dApp ID of the proxy - uint256 public immutable override dappId; - /// @notice The minimum price (inclusive) that this proxy will report. int224 public immutable override lowerBound; /// @notice The maximum price (inclusive) that this proxy will report. int224 public immutable override upperBound; - /// @param proxy_ IApi3ReaderProxyWithDappId contract address + /// @param proxy_ IApi3ReaderProxy contract address /// @param lowerBound_ The minimum price (inclusive) this proxy will report /// @param upperBound_ The maximum price (inclusive) this proxy will report constructor(address proxy_, int224 lowerBound_, int224 upperBound_) { @@ -47,13 +44,12 @@ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 { revert UpperBoundMustBeGreaterOrEqualToLowerBound(); } proxy = proxy_; - dappId = IApi3ReaderProxyWithDappId(proxy_).dappId(); lowerBound = lowerBound_; upperBound = upperBound_; } /// @notice Reads the current value and timestamp from the underlying - /// `IApi3ReaderProxyWithDappId` and applies the price bounds. + /// `IApi3ReaderProxy` and applies the price bounds. /// @dev If the `baseValue` from the underlying proxy is less than /// `lowerBound`, then `lowerBound` is returned as the `value`. If /// `baseValue` is greater than `upperBound`, then `upperBound` is returned. @@ -67,9 +63,8 @@ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 { override returns (int224 value, uint32 timestamp) { - (int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxyWithDappId( - proxy - ).read(); + (int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxy(proxy) + .read(); timestamp = baseTimestamp; @@ -87,7 +82,7 @@ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 { /// @return True if the base value is less than `lowerBound` or greater /// than `upperBound`, false otherwise. function isCapped() external view returns (bool) { - (int224 baseValue, ) = IApi3ReaderProxyWithDappId(proxy).read(); + (int224 baseValue, ) = IApi3ReaderProxy(proxy).read(); return baseValue < lowerBound || baseValue > upperBound; } diff --git a/contracts/ProductApi3ReaderProxyV1.sol b/contracts/ProductApi3ReaderProxyV1.sol index e6bfb60..762f09f 100644 --- a/contracts/ProductApi3ReaderProxyV1.sol +++ b/contracts/ProductApi3ReaderProxyV1.sol @@ -1,28 +1,25 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.27; -import "./interfaces/IApi3ReaderProxyWithDappId.sol"; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "./interfaces/IProductApi3ReaderProxyV1.sol"; /// @title An immutable proxy contract that is used to read a composition of two -/// IApi3ReaderProxyWithDappId data feeds by multiplying their values +/// IApi3ReaderProxy data feeds by multiplying their values /// @dev This contract implements the AggregatorV2V3Interface to be compatible /// with Chainlink aggregators. This allows the contract to be used as a drop-in /// replacement for Chainlink aggregators in existing dApps. /// Refer to https://github.com/api3dao/migrate-from-chainlink-to-api3 for more /// information about the Chainlink interface implementation. contract ProductApi3ReaderProxyV1 is IProductApi3ReaderProxyV1 { - /// @notice First IApi3ReaderProxyWithDappId contract address + /// @notice First IApi3ReaderProxy contract address address public immutable override proxy1; - /// @notice Second IApi3ReaderProxyWithDappId contract address + /// @notice Second IApi3ReaderProxy contract address address public immutable override proxy2; - /// @notice The dApp ID of the two proxies - uint256 public immutable override dappId; - - /// @param proxy1_ First IApi3ReaderProxyWithDappId contract address - /// @param proxy2_ Second IApi3ReaderProxyWithDappId contract address + /// @param proxy1_ First IApi3ReaderProxy contract address + /// @param proxy2_ Second IApi3ReaderProxy contract address constructor(address proxy1_, address proxy2_) { if (proxy1_ == address(0) || proxy2_ == address(0)) { revert ZeroProxyAddress(); @@ -30,19 +27,12 @@ contract ProductApi3ReaderProxyV1 is IProductApi3ReaderProxyV1 { if (proxy1_ == proxy2_) { revert SameProxyAddress(); } - uint256 dappId1 = IApi3ReaderProxyWithDappId(proxy1_).dappId(); - uint256 dappId2 = IApi3ReaderProxyWithDappId(proxy2_).dappId(); - if (dappId1 != dappId2) { - revert DappIdMismatch(); - } proxy1 = proxy1_; proxy2 = proxy2_; - dappId = dappId1; } /// @notice Returns the current value and timestamp of the rate composition - /// between two IApi3ReaderProxyWithDappId proxies by multiplying their - /// values + /// between two IApi3ReaderProxy proxies by multiplying their values /// @dev Calculates product as `(int256(value1) * int256(value2)) / 1e18`. /// The initial multiplication `int256(value1) * int256(value2)` may revert /// on `int256` overflow. The final `int256` result of the full expression @@ -59,8 +49,8 @@ contract ProductApi3ReaderProxyV1 is IProductApi3ReaderProxyV1 { override returns (int224 value, uint32 timestamp) { - (int224 value1, ) = IApi3ReaderProxyWithDappId(proxy1).read(); - (int224 value2, ) = IApi3ReaderProxyWithDappId(proxy2).read(); + (int224 value1, ) = IApi3ReaderProxy(proxy1).read(); + (int224 value2, ) = IApi3ReaderProxy(proxy2).read(); value = int224((int256(value1) * int256(value2)) / 1e18); timestamp = uint32(block.timestamp); diff --git a/contracts/adapters/ScaledApi3FeedProxyV1.sol b/contracts/adapters/ScaledApi3FeedProxyV1.sol index 740d18d..0e85194 100644 --- a/contracts/adapters/ScaledApi3FeedProxyV1.sol +++ b/contracts/adapters/ScaledApi3FeedProxyV1.sol @@ -1,15 +1,14 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.27; -import "../interfaces/IApi3ReaderProxyWithDappId.sol"; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "./interfaces/IScaledApi3FeedProxyV1.sol"; /// @title An immutable Chainlink AggregatorV2V3Interface feed contract that -/// scales the value of an IApi3ReaderProxyWithDappId data feed to a target -/// number of decimals +/// scales the value of an IApi3ReaderProxy data feed to a target number of +/// decimals /// @dev This contract reads an `int224` value (assumed to be 18 decimals) -/// from the underlying `IApi3ReaderProxyWithDappId` and scales it to -///`targetDecimals`. +/// from the underlying `IApi3ReaderProxy` and scales it to `targetDecimals`. /// The scaling arithmetic uses `int256` for intermediate results, allowing the /// scaled value to exceed `int224` limits if upscaling significantly; it will /// revert on `int256` overflow. @@ -17,12 +16,9 @@ import "./interfaces/IScaledApi3FeedProxyV1.sol"; /// which truncates and may lead to precision loss. Integrators must carefully /// consider this potential precision loss for their specific use case. contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 { - /// @notice IApi3ReaderProxyWithDappId contract address + /// @notice IApi3ReaderProxy contract address address public immutable override proxy; - /// @notice dApp ID of the proxy - uint256 public immutable override dappId; - /// @notice Pre-calculated factor for scaling the proxy's 18-decimal value /// to `targetDecimals`. int256 public immutable override scalingFactor; @@ -34,9 +30,8 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 { /// @dev Target decimals for the scaled value. uint8 private immutable targetDecimals; - /// @param proxy_ IApi3ReaderProxyWithDappId contract address - /// @param targetDecimals_ Decimals to scale the IApi3ReaderProxyWithDappId - /// value + /// @param proxy_ IApi3ReaderProxy contract address + /// @param targetDecimals_ Decimals to scale the IApi3ReaderProxy value constructor(address proxy_, uint8 targetDecimals_) { if (proxy_ == address(0)) { revert ZeroProxyAddress(); @@ -48,7 +43,6 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 { revert NoScalingNeeded(); } proxy = proxy_; - dappId = IApi3ReaderProxyWithDappId(proxy_).dappId(); targetDecimals = targetDecimals_; uint8 delta = targetDecimals_ > 18 ? targetDecimals_ - 18 @@ -94,7 +88,7 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 { revert FunctionIsNotSupported(); } - /// @dev Decimals used to scale the IApi3ReaderProxyWithDappId value + /// @dev Decimals used to scale the IApi3ReaderProxy value function decimals() external view override returns (uint8) { return targetDecimals; } @@ -143,7 +137,7 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 { updatedAt = startedAt; } - /// @notice Reads a value from the underlying `IApi3ReaderProxyWithDappId` + /// @notice Reads a value from the underlying `IApi3ReaderProxy` /// and scales it to `targetDecimals`. /// @dev Reads from the underlying proxy and applies scaling to /// `targetDecimals`. Upscaling uses multiplication; downscaling uses integer @@ -152,9 +146,8 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 { /// @return value The scaled signed fixed-point value with `targetDecimals`. /// @return timestamp The timestamp from the underlying proxy. function _read() internal view returns (int256 value, uint32 timestamp) { - (int224 proxyValue, uint32 proxyTimestamp) = IApi3ReaderProxyWithDappId( - proxy - ).read(); + (int224 proxyValue, uint32 proxyTimestamp) = IApi3ReaderProxy(proxy) + .read(); value = isUpscaling ? proxyValue * scalingFactor diff --git a/contracts/adapters/interfaces/IScaledApi3FeedProxyV1.sol b/contracts/adapters/interfaces/IScaledApi3FeedProxyV1.sol index 5d6f2a6..2ba6b2c 100644 --- a/contracts/adapters/interfaces/IScaledApi3FeedProxyV1.sol +++ b/contracts/adapters/interfaces/IScaledApi3FeedProxyV1.sol @@ -17,6 +17,4 @@ interface IScaledApi3FeedProxyV1 is AggregatorV2V3Interface { function scalingFactor() external view returns (int256); function isUpscaling() external view returns (bool); - - function dappId() external view returns (uint256); } diff --git a/contracts/interfaces/IApi3ReaderProxyWithDappId.sol b/contracts/interfaces/IApi3ReaderProxyWithDappId.sol deleted file mode 100644 index 5fea802..0000000 --- a/contracts/interfaces/IApi3ReaderProxyWithDappId.sol +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.27; - -import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; - -interface IApi3ReaderProxyWithDappId is IApi3ReaderProxy { - function dappId() external view returns (uint256); -} diff --git a/contracts/interfaces/IInverseApi3ReaderProxyV1.sol b/contracts/interfaces/IInverseApi3ReaderProxyV1.sol index ab92249..c76c778 100644 --- a/contracts/interfaces/IInverseApi3ReaderProxyV1.sol +++ b/contracts/interfaces/IInverseApi3ReaderProxyV1.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "../vendor/@chainlink/contracts@1.2.0/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol"; -import "./IApi3ReaderProxyWithDappId.sol"; interface IInverseApi3ReaderProxyV1 is - IApi3ReaderProxyWithDappId, + IApi3ReaderProxy, AggregatorV2V3Interface { error ZeroProxyAddress(); diff --git a/contracts/interfaces/INormalizedApi3ReaderProxyV1.sol b/contracts/interfaces/INormalizedApi3ReaderProxyV1.sol index 40cc0df..274a87f 100644 --- a/contracts/interfaces/INormalizedApi3ReaderProxyV1.sol +++ b/contracts/interfaces/INormalizedApi3ReaderProxyV1.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "../vendor/@chainlink/contracts@1.2.0/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol"; -import "./IApi3ReaderProxyWithDappId.sol"; interface INormalizedApi3ReaderProxyV1 is - IApi3ReaderProxyWithDappId, + IApi3ReaderProxy, AggregatorV2V3Interface { error ZeroProxyAddress(); diff --git a/contracts/interfaces/IPriceCappedApi3ReaderProxyV1.sol b/contracts/interfaces/IPriceCappedApi3ReaderProxyV1.sol index fff8e48..7fea22d 100644 --- a/contracts/interfaces/IPriceCappedApi3ReaderProxyV1.sol +++ b/contracts/interfaces/IPriceCappedApi3ReaderProxyV1.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "../vendor/@chainlink/contracts@1.2.0/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol"; -import "./IApi3ReaderProxyWithDappId.sol"; interface IPriceCappedApi3ReaderProxyV1 is - IApi3ReaderProxyWithDappId, + IApi3ReaderProxy, AggregatorV2V3Interface { error ZeroProxyAddress(); diff --git a/contracts/interfaces/IProductApi3ReaderProxyV1.sol b/contracts/interfaces/IProductApi3ReaderProxyV1.sol index 040199a..1ef6fdb 100644 --- a/contracts/interfaces/IProductApi3ReaderProxyV1.sol +++ b/contracts/interfaces/IProductApi3ReaderProxyV1.sol @@ -1,19 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; import "../vendor/@chainlink/contracts@1.2.0/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol"; -import "./IApi3ReaderProxyWithDappId.sol"; interface IProductApi3ReaderProxyV1 is - IApi3ReaderProxyWithDappId, + IApi3ReaderProxy, AggregatorV2V3Interface { error ZeroProxyAddress(); error SameProxyAddress(); - error DappIdMismatch(); - error ZeroDenominator(); error FunctionIsNotSupported(); diff --git a/contracts/test/MockApi3ReaderProxyV1.sol b/contracts/test/MockApi3ReaderProxyV1.sol index 8e266e0..003126b 100644 --- a/contracts/test/MockApi3ReaderProxyV1.sol +++ b/contracts/test/MockApi3ReaderProxyV1.sol @@ -7,15 +7,12 @@ import {IApi3ReaderProxyV1} from "@api3/contracts/api3-server-v1/proxies/interfa /// @dev This mock implements the minimal functions required for testing the /// data-feed-proxy-combinators contracts. Other functions will revert. contract MockApi3ReaderProxyV1 is IApi3ReaderProxyV1 { - /// @notice The dApp ID of the mock proxy. - uint256 public immutable override dappId; /// @notice The mock value to be returned by read(). int224 private _value; /// @notice The mock timestamp to be returned by read(). uint32 private _timestamp; - constructor(uint256 dappId_, int224 value_, uint32 timestamp_) { - dappId = dappId_; + constructor(int224 value_, uint32 timestamp_) { _value = value_; _timestamp = timestamp_; } @@ -51,4 +48,8 @@ contract MockApi3ReaderProxyV1 is IApi3ReaderProxyV1 { function dapiName() external pure override returns (bytes32) { revert("Mock: Not implemented"); } + + function dappId() external pure override returns (uint256) { + revert("Mock: Not implemented"); + } } diff --git a/deploy/001_deploy_InverseApi3ReaderProxyV1.ts b/deploy/001_deploy_InverseApi3ReaderProxyV1.ts index a5b10ce..c670b00 100644 --- a/deploy/001_deploy_InverseApi3ReaderProxyV1.ts +++ b/deploy/001_deploy_InverseApi3ReaderProxyV1.ts @@ -2,8 +2,6 @@ import type { HardhatRuntimeEnvironment } from 'hardhat/types'; import type { DeploymentsExtension } from 'hardhat-deploy/types'; import { getDeploymentName } from '../src'; -import * as testUtils from '../test/test-utils'; -import { IApi3ReaderProxyWithDappId__factory } from '../typechain-types'; export const CONTRACT_NAME = 'InverseApi3ReaderProxyV1'; @@ -11,7 +9,6 @@ const deployMockApi3ReaderProxyV1 = async (deployments: DeploymentsExtension, de const { address } = await deployments.deploy('MockApi3ReaderProxyV1', { from: deployerAddress, args: [ - testUtils.generateRandomBytes32(), // A mock dappId '2000000000000000000000', // A mock value (2000e18) Math.floor(Date.now() / 1000), // A mock timestamp ], @@ -43,16 +40,6 @@ module.exports = async (hre: HardhatRuntimeEnvironment) => { } log(`Proxy address: ${proxyAddress}`); - if (!isLocalNetwork) { - try { - const proxy = IApi3ReaderProxyWithDappId__factory.connect(proxyAddress, ethers.provider); - const dappId = await proxy.dappId(); - log(`Proxy dappId: ${dappId}`); - } catch { - throw new Error(`Failed to read dappId from proxy at ${proxyAddress}`); - } - } - const confirmations = isLocalNetwork ? 1 : 5; log(`Deployment confirmations: ${confirmations}`); diff --git a/deploy/002_deploy_NormalizedApi3ReaderProxyV1.ts b/deploy/002_deploy_NormalizedApi3ReaderProxyV1.ts index fe2504e..b56fa75 100644 --- a/deploy/002_deploy_NormalizedApi3ReaderProxyV1.ts +++ b/deploy/002_deploy_NormalizedApi3ReaderProxyV1.ts @@ -2,7 +2,6 @@ import type { HardhatRuntimeEnvironment } from 'hardhat/types'; import type { DeploymentsExtension } from 'hardhat-deploy/types'; import { getDeploymentName } from '../src'; -import * as testUtils from '../test/test-utils'; export const CONTRACT_NAME = 'NormalizedApi3ReaderProxyV1'; @@ -42,20 +41,11 @@ module.exports = async (hre: HardhatRuntimeEnvironment) => { } log(`Feed address: ${feedAddress}`); - const dappId = isLocalNetwork ? testUtils.generateRandomBytes32() : process.env.DAPP_ID; - if (!dappId) { - throw new Error('DAPP_ID environment variable not set. Please provide the dApp ID.'); - } - if (!ethers.isHexString(dappId, 32)) { - throw new Error(`Invalid dApp ID provided: ${dappId}`); - } - log(`dApp ID: ${dappId}`); - const confirmations = isLocalNetwork ? 1 : 5; log(`Deployment confirmations: ${confirmations}`); - const constructorArgs = [feedAddress, dappId]; - const constructorArgTypes = ['address', 'uint256']; + const constructorArgs = [feedAddress]; + const constructorArgTypes = ['address']; const deploymentName = getDeploymentName(CONTRACT_NAME, constructorArgTypes, constructorArgs); log(`Generated deterministic deployment name for this instance: ${deploymentName}`); diff --git a/deploy/003_deploy_ProductApi3ReaderProxyV1.ts b/deploy/003_deploy_ProductApi3ReaderProxyV1.ts index ea19c48..c600089 100644 --- a/deploy/003_deploy_ProductApi3ReaderProxyV1.ts +++ b/deploy/003_deploy_ProductApi3ReaderProxyV1.ts @@ -1,21 +1,21 @@ +import { go } from '@api3/promise-utils'; import type { HardhatRuntimeEnvironment } from 'hardhat/types'; import type { DeploymentsExtension } from 'hardhat-deploy/types'; import { getDeploymentName } from '../src'; -import * as testUtils from '../test/test-utils'; -import { IApi3ReaderProxyWithDappId__factory } from '../typechain-types'; +import { IApi3ReaderProxyV1__factory } from '../typechain-types'; export const CONTRACT_NAME = 'ProductApi3ReaderProxyV1'; const deployMockApi3ReaderProxyV1 = async ( deployments: DeploymentsExtension, deployerAddress: string, - dappId: string + name: string ) => { - const { address } = await deployments.deploy('MockApi3ReaderProxyV1', { + const { address } = await deployments.deploy(name, { + contract: 'MockApi3ReaderProxyV1', from: deployerAddress, args: [ - dappId, '2000000000000000000000', // A mock value (2000e18) Math.floor(Date.now() / 1000), // A mock timestamp ], @@ -36,9 +36,8 @@ module.exports = async (hre: HardhatRuntimeEnvironment) => { const isLocalNetwork = network.name === 'hardhat' || network.name === 'localhost'; - const dappId = testUtils.generateRandomBytes32(); const proxy1Address = isLocalNetwork - ? await deployMockApi3ReaderProxyV1(deployments, deployerAddress, dappId) + ? await deployMockApi3ReaderProxyV1(deployments, deployerAddress, 'MockApi3ReaderProxyV1_1') : process.env.PROXY1; if (!proxy1Address) { throw new Error('PROXY1 environment variable not set. Please provide the address of the first proxy contract.'); @@ -48,24 +47,13 @@ module.exports = async (hre: HardhatRuntimeEnvironment) => { } log(`Proxy 1 address: ${proxy1Address}`); - let dappId1; - if (!isLocalNetwork) { - try { - const proxy1 = IApi3ReaderProxyWithDappId__factory.connect(proxy1Address, ethers.provider); - dappId1 = await proxy1.dappId(); - log(`Proxy 1 dappId: ${dappId1}`); - } catch { - throw new Error(`Failed to read dappId from proxy at ${proxy1Address}`); - } - } - // Sleep for 1 sec when deploying to local network in order to generate a different proxy address if (isLocalNetwork) { await new Promise((resolve) => setTimeout(resolve, 1000)); } const proxy2Address = isLocalNetwork - ? await deployMockApi3ReaderProxyV1(deployments, deployerAddress, dappId) + ? await deployMockApi3ReaderProxyV1(deployments, deployerAddress, 'MockApi3ReaderProxyV1_2') : process.env.PROXY2; if (!proxy2Address) { throw new Error('PROXY2 environment variable not set. Please provide the address of the second proxy contract.'); @@ -75,19 +63,30 @@ module.exports = async (hre: HardhatRuntimeEnvironment) => { } log(`Proxy 2 address: ${proxy2Address}`); - let dappId2; if (!isLocalNetwork) { - try { - const proxy2 = IApi3ReaderProxyWithDappId__factory.connect(proxy2Address, ethers.provider); - dappId2 = await proxy2.dappId(); + let dappId1, dappId2; + const proxy1 = IApi3ReaderProxyV1__factory.connect(proxy1Address, ethers.provider); + const proxy2 = IApi3ReaderProxyV1__factory.connect(proxy2Address, ethers.provider); + + const goDappId1 = await go(() => proxy1.dappId()); + if (goDappId1.success) { + dappId1 = goDappId1.data; + log(`Proxy 1 dappId: ${dappId1}`); + } else { + log('Proxy 1 does not have a dappId'); + } + + const goDappId2 = await go(() => proxy2.dappId()); + if (goDappId2.success) { + dappId2 = goDappId2.data; log(`Proxy 2 dappId: ${dappId2}`); - } catch { - throw new Error(`Failed to read dappId from proxy at ${proxy2Address}`); + } else { + log('Proxy 2 does not have a dappId'); } - } - if (!isLocalNetwork && dappId1 && dappId2 && dappId1 !== dappId2) { - throw new Error(`dApp IDs of PROXY1 (${dappId1}) and PROXY2 (${dappId2}) do not match.`); + if (dappId1 && dappId2 && dappId1 !== dappId2) { + throw new Error(`dApp IDs of PROXY1 (${dappId1}) and PROXY2 (${dappId2}) do not match.`); + } } const confirmations = isLocalNetwork ? 1 : 5; diff --git a/deploy/004_deploy_ScaledApi3FeedProxyV1.ts b/deploy/004_deploy_ScaledApi3FeedProxyV1.ts index 06e2744..23c5ac0 100644 --- a/deploy/004_deploy_ScaledApi3FeedProxyV1.ts +++ b/deploy/004_deploy_ScaledApi3FeedProxyV1.ts @@ -2,8 +2,6 @@ import type { HardhatRuntimeEnvironment } from 'hardhat/types'; import type { DeploymentsExtension } from 'hardhat-deploy/types'; import { getDeploymentName } from '../src'; -import * as testUtils from '../test/test-utils'; -import { IApi3ReaderProxyWithDappId__factory } from '../typechain-types'; export const CONTRACT_NAME = 'ScaledApi3FeedProxyV1'; @@ -11,7 +9,6 @@ const deployMockApi3ReaderProxyV1 = async (deployments: DeploymentsExtension, de const { address } = await deployments.deploy('MockApi3ReaderProxyV1', { from: deployerAddress, args: [ - testUtils.generateRandomBytes32(), // A mock dappId '2000000000000000000000', // A mock value (2000e18) Math.floor(Date.now() / 1000), // A mock timestamp ], @@ -49,16 +46,6 @@ module.exports = async (hre: HardhatRuntimeEnvironment) => { } log(`Proxy address: ${proxyAddress}`); - if (!isLocalNetwork) { - try { - const proxy = IApi3ReaderProxyWithDappId__factory.connect(proxyAddress, ethers.provider); - const dappId = await proxy.dappId(); - log(`Proxy dappId: ${dappId}`); - } catch { - throw new Error(`Failed to read dappId from proxy at ${proxyAddress}`); - } - } - const confirmations = isLocalNetwork ? 1 : 5; log(`Deployment confirmations: ${confirmations}`); diff --git a/deploy/005_deploy_PriceCappedApi3ReaderProxyV1.ts b/deploy/005_deploy_PriceCappedApi3ReaderProxyV1.ts index 7beb517..9068926 100644 --- a/deploy/005_deploy_PriceCappedApi3ReaderProxyV1.ts +++ b/deploy/005_deploy_PriceCappedApi3ReaderProxyV1.ts @@ -2,8 +2,6 @@ import type { HardhatRuntimeEnvironment } from 'hardhat/types'; import type { DeploymentsExtension } from 'hardhat-deploy/types'; import { getDeploymentName } from '../src'; -import * as testUtils from '../test/test-utils'; -import { IApi3ReaderProxyWithDappId__factory } from '../typechain-types'; export const CONTRACT_NAME = 'PriceCappedApi3ReaderProxyV1'; @@ -11,7 +9,6 @@ const deployMockApi3ReaderProxyV1 = async (deployments: DeploymentsExtension, de const { address } = await deployments.deploy('MockApi3ReaderProxyV1', { from: deployerAddress, args: [ - testUtils.generateRandomBytes32(), // A mock dappId '2000000000000000000000', // A mock value (2000e18) Math.floor(Date.now() / 1000), // A mock timestamp ], @@ -43,16 +40,6 @@ module.exports = async (hre: HardhatRuntimeEnvironment) => { } log(`Proxy address: ${proxyAddress}`); - if (!isLocalNetwork) { - try { - const proxy = IApi3ReaderProxyWithDappId__factory.connect(proxyAddress, ethers.provider); - const dappId = await proxy.dappId(); - log(`Proxy dappId: ${dappId}`); - } catch { - throw new Error(`Failed to read dappId from proxy at ${proxyAddress}`); - } - } - const lowerBound = process.env.LOWER_BOUND ? BigInt(process.env.LOWER_BOUND) : 0n; // Defaults to 0 log(`Using lower bound: ${lowerBound.toString()}`); diff --git a/package.json b/package.json index 2488f8f..7e31438 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "devDependencies": { "@api3/contracts": "^29.0.0", "@api3/eslint-plugin-commons": "^3.0.0", + "@api3/promise-utils": "^0.4.0", "@eslint/js": "^9.36.0", "@nomicfoundation/hardhat-ethers": "^3.1.0", "@nomicfoundation/hardhat-network-helpers": "^1.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6c62c5c..33de4ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@api3/eslint-plugin-commons': specifier: ^3.0.0 version: 3.0.0(@babel/core@7.27.1)(eslint@8.57.1)(prettier@3.6.2)(typescript@5.9.3) + '@api3/promise-utils': + specifier: ^0.4.0 + version: 0.4.0 '@eslint/js': specifier: ^9.36.0 version: 9.36.0 @@ -113,6 +116,9 @@ packages: peerDependencies: eslint: ^8.57.1 + '@api3/promise-utils@0.4.0': + resolution: {integrity: sha512-+8fcNjjQeQAuuSXFwu8PMZcYzjwjDiGYcMUfAQ0lpREb1zHonwWZ2N0B9h/g1cvWzg9YhElbeb/SyhCrNm+b/A==} + '@babel/code-frame@7.27.1': resolution: {integrity: sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==} engines: {node: '>=6.9.0'} @@ -782,14 +788,6 @@ packages: typescript: optional: true - '@typescript-eslint/eslint-plugin@8.32.1': - resolution: {integrity: sha512-6u6Plg9nP/J1GRpe/vcjjabo6Uc5YQPAMxsgQyGC/I0RuukiG1wIe3+Vtg3IrSCVJDmqK3j8adrtzXSENRtFgg==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - '@typescript-eslint/parser': ^8.0.0 || ^8.0.0-alpha.0 - eslint: ^8.57.0 || ^9.0.0 - typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/eslint-plugin@8.45.0': resolution: {integrity: sha512-HC3y9CVuevvWCl/oyZuI47dOeDF9ztdMEfMH8/DW/Mhwa9cCLnK1oD7JoTVGW/u7kFzNZUKUoyJEqkaJh5y3Wg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -808,13 +806,6 @@ packages: typescript: optional: true - '@typescript-eslint/parser@8.32.1': - resolution: {integrity: sha512-LKMrmwCPoLhM45Z00O1ulb6jwyVr2kr3XJp+G+tSEZcbauNnScewcQwtJqXDhXeYPDEjZ8C1SjXm015CirEmGg==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - eslint: ^8.57.0 || ^9.0.0 - typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/parser@8.45.0': resolution: {integrity: sha512-TGf22kon8KW+DeKaUmOibKWktRY8b2NSAZNdtWh798COm1NWx8+xJ6iFBtk3IvLdv6+LGLJLRlyhrhEDZWargQ==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -832,10 +823,6 @@ packages: resolution: {integrity: sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==} engines: {node: ^18.18.0 || >=20.0.0} - '@typescript-eslint/scope-manager@8.32.1': - resolution: {integrity: sha512-7IsIaIDeZn7kffk7qXC3o6Z4UblZJKV3UBpkvRNpr5NSyLji7tvTcvmnMNYuYLyh26mN8W723xpo3i4MlD33vA==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@typescript-eslint/scope-manager@8.45.0': resolution: {integrity: sha512-clmm8XSNj/1dGvJeO6VGH7EUSeA0FMs+5au/u3lrA3KfG8iJ4u8ym9/j2tTEoacAffdW1TVUzXO30W1JTJS7dA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -856,13 +843,6 @@ packages: typescript: optional: true - '@typescript-eslint/type-utils@8.32.1': - resolution: {integrity: sha512-mv9YpQGA8iIsl5KyUPi+FGLm7+bA4fgXaeRcFKRDRwDMu4iwrSHeDPipwueNXhdIIZltwCJv+NkxftECbIZWfA==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - eslint: ^8.57.0 || ^9.0.0 - typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/type-utils@8.45.0': resolution: {integrity: sha512-bpjepLlHceKgyMEPglAeULX1vixJDgaKocp0RVJ5u4wLJIMNuKtUXIczpJCPcn2waII0yuvks/5m5/h3ZQKs0A==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -874,10 +854,6 @@ packages: resolution: {integrity: sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==} engines: {node: ^18.18.0 || >=20.0.0} - '@typescript-eslint/types@8.32.1': - resolution: {integrity: sha512-YmybwXUJcgGqgAp6bEsgpPXEg6dcCyPyCSr0CAAueacR/CCBi25G3V8gGQ2kRzQRBNol7VQknxMs9HvVa9Rvfg==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@typescript-eslint/types@8.45.0': resolution: {integrity: sha512-WugXLuOIq67BMgQInIxxnsSyRLFxdkJEJu8r4ngLR56q/4Q5LrbfkFRH27vMTjxEK8Pyz7QfzuZe/G15qQnVRA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -891,12 +867,6 @@ packages: typescript: optional: true - '@typescript-eslint/typescript-estree@8.32.1': - resolution: {integrity: sha512-Y3AP9EIfYwBb4kWGb+simvPaqQoT5oJuzzj9m0i6FCY6SPvlomY2Ei4UEMm7+FXtlNJbor80ximyslzaQF6xhg==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/typescript-estree@8.45.0': resolution: {integrity: sha512-GfE1NfVbLam6XQ0LcERKwdTTPlLvHvXXhOeUGC1OXi4eQBoyy1iVsW+uzJ/J9jtCz6/7GCQ9MtrQ0fml/jWCnA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -909,13 +879,6 @@ packages: peerDependencies: eslint: ^8.56.0 - '@typescript-eslint/utils@8.32.1': - resolution: {integrity: sha512-DsSFNIgLSrc89gpq1LJB7Hm1YpuhK086DRDJSNrewcGvYloWW1vZLHBTIvarKZDcAORIy/uWNx8Gad+4oMpkSA==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - eslint: ^8.57.0 || ^9.0.0 - typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/utils@8.45.0': resolution: {integrity: sha512-bxi1ht+tLYg4+XV2knz/F7RVhU0k6VrSMc9sb8DQ6fyCTrGQLHfo7lDtN0QJjZjKkLA2ThrKuCdHEvLReqtIGg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -927,10 +890,6 @@ packages: resolution: {integrity: sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==} engines: {node: ^18.18.0 || >=20.0.0} - '@typescript-eslint/visitor-keys@8.32.1': - resolution: {integrity: sha512-ar0tjQfObzhSaW3C3QNmTc5ofj0hDoNQ5XWrCy6zDyabdr0TWhCkClp+rywGNj/odAFBVzzJrK4tEq5M4Hmu4w==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@typescript-eslint/visitor-keys@8.45.0': resolution: {integrity: sha512-qsaFBA3e09MIDAGFUrTk+dzqtfv1XPVz8t8d1f0ybTzrCY7BKiMC5cjrl1O/P7UmHsNyW90EYSkU/ZWpmXelag==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -1939,10 +1898,6 @@ packages: resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - eslint-visitor-keys@4.2.0: - resolution: {integrity: sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - eslint-visitor-keys@4.2.1: resolution: {integrity: sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -4039,16 +3994,16 @@ snapshots: '@api3/eslint-plugin-commons@3.0.0(@babel/core@7.27.1)(eslint@8.57.1)(prettier@3.6.2)(typescript@5.9.3)': dependencies: '@shopify/eslint-plugin': 45.0.0(@babel/core@7.27.1)(eslint@8.57.1)(prettier@3.6.2)(typescript@5.9.3) - '@typescript-eslint/eslint-plugin': 8.32.1(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3) - '@typescript-eslint/parser': 8.32.1(eslint@8.57.1)(typescript@5.9.3) + '@typescript-eslint/eslint-plugin': 8.45.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3) + '@typescript-eslint/parser': 8.45.0(eslint@8.57.1)(typescript@5.9.3) eslint: 8.57.1 eslint-config-next: 14.2.28(eslint@8.57.1)(typescript@5.9.3) eslint-plugin-check-file: 2.8.0(eslint@8.57.1) eslint-plugin-cypress: 3.6.0(eslint@8.57.1) eslint-plugin-deprecation: 3.0.0(eslint@8.57.1)(typescript@5.9.3) eslint-plugin-functional: 6.6.3(eslint@8.57.1)(typescript@5.9.3) - eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1) - eslint-plugin-jest: 28.11.0(@typescript-eslint/eslint-plugin@8.32.1(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3) + eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1) + eslint-plugin-jest: 28.11.0(@typescript-eslint/eslint-plugin@8.45.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3) eslint-plugin-jest-formatting: 3.1.0(eslint@8.57.1) eslint-plugin-lodash: 7.4.0(eslint@8.57.1) eslint-plugin-no-only-tests: 3.3.0 @@ -4069,6 +4024,8 @@ snapshots: - supports-color - typescript + '@api3/promise-utils@0.4.0': {} + '@babel/code-frame@7.27.1': dependencies: '@babel/helper-validator-identifier': 7.27.1 @@ -5036,23 +4993,6 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/eslint-plugin@8.32.1(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3)': - dependencies: - '@eslint-community/regexpp': 4.12.1 - '@typescript-eslint/parser': 8.32.1(eslint@8.57.1)(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.32.1 - '@typescript-eslint/type-utils': 8.32.1(eslint@8.57.1)(typescript@5.9.3) - '@typescript-eslint/utils': 8.32.1(eslint@8.57.1)(typescript@5.9.3) - '@typescript-eslint/visitor-keys': 8.32.1 - eslint: 8.57.1 - graphemer: 1.4.0 - ignore: 7.0.4 - natural-compare: 1.4.0 - ts-api-utils: 2.1.0(typescript@5.9.3) - typescript: 5.9.3 - transitivePeerDependencies: - - supports-color - '@typescript-eslint/eslint-plugin@8.45.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3)': dependencies: '@eslint-community/regexpp': 4.12.1 @@ -5083,18 +5023,6 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3)': - dependencies: - '@typescript-eslint/scope-manager': 8.32.1 - '@typescript-eslint/types': 8.32.1 - '@typescript-eslint/typescript-estree': 8.32.1(typescript@5.9.3) - '@typescript-eslint/visitor-keys': 8.32.1 - debug: 4.4.1(supports-color@8.1.1) - eslint: 8.57.1 - typescript: 5.9.3 - transitivePeerDependencies: - - supports-color - '@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3)': dependencies: '@typescript-eslint/scope-manager': 8.45.0 @@ -5121,11 +5049,6 @@ snapshots: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 - '@typescript-eslint/scope-manager@8.32.1': - dependencies: - '@typescript-eslint/types': 8.32.1 - '@typescript-eslint/visitor-keys': 8.32.1 - '@typescript-eslint/scope-manager@8.45.0': dependencies: '@typescript-eslint/types': 8.45.0 @@ -5147,17 +5070,6 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/type-utils@8.32.1(eslint@8.57.1)(typescript@5.9.3)': - dependencies: - '@typescript-eslint/typescript-estree': 8.32.1(typescript@5.9.3) - '@typescript-eslint/utils': 8.32.1(eslint@8.57.1)(typescript@5.9.3) - debug: 4.4.1(supports-color@8.1.1) - eslint: 8.57.1 - ts-api-utils: 2.1.0(typescript@5.9.3) - typescript: 5.9.3 - transitivePeerDependencies: - - supports-color - '@typescript-eslint/type-utils@8.45.0(eslint@8.57.1)(typescript@5.9.3)': dependencies: '@typescript-eslint/types': 8.45.0 @@ -5172,8 +5084,6 @@ snapshots: '@typescript-eslint/types@7.18.0': {} - '@typescript-eslint/types@8.32.1': {} - '@typescript-eslint/types@8.45.0': {} '@typescript-eslint/typescript-estree@7.18.0(typescript@5.9.3)': @@ -5191,20 +5101,6 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/typescript-estree@8.32.1(typescript@5.9.3)': - dependencies: - '@typescript-eslint/types': 8.32.1 - '@typescript-eslint/visitor-keys': 8.32.1 - debug: 4.4.1(supports-color@8.1.1) - fast-glob: 3.3.3 - is-glob: 4.0.3 - minimatch: 9.0.5 - semver: 7.7.2 - ts-api-utils: 2.1.0(typescript@5.9.3) - typescript: 5.9.3 - transitivePeerDependencies: - - supports-color - '@typescript-eslint/typescript-estree@8.45.0(typescript@5.9.3)': dependencies: '@typescript-eslint/project-service': 8.45.0(typescript@5.9.3) @@ -5232,17 +5128,6 @@ snapshots: - supports-color - typescript - '@typescript-eslint/utils@8.32.1(eslint@8.57.1)(typescript@5.9.3)': - dependencies: - '@eslint-community/eslint-utils': 4.7.0(eslint@8.57.1) - '@typescript-eslint/scope-manager': 8.32.1 - '@typescript-eslint/types': 8.32.1 - '@typescript-eslint/typescript-estree': 8.32.1(typescript@5.9.3) - eslint: 8.57.1 - typescript: 5.9.3 - transitivePeerDependencies: - - supports-color - '@typescript-eslint/utils@8.45.0(eslint@8.57.1)(typescript@5.9.3)': dependencies: '@eslint-community/eslint-utils': 4.7.0(eslint@8.57.1) @@ -5259,11 +5144,6 @@ snapshots: '@typescript-eslint/types': 7.18.0 eslint-visitor-keys: 3.4.3 - '@typescript-eslint/visitor-keys@8.32.1': - dependencies: - '@typescript-eslint/types': 8.32.1 - eslint-visitor-keys: 4.2.0 - '@typescript-eslint/visitor-keys@8.45.0': dependencies: '@typescript-eslint/types': 8.45.0 @@ -6188,11 +6068,11 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint@8.57.1): + eslint-module-utils@2.12.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint@8.57.1): dependencies: debug: 3.2.7 optionalDependencies: - '@typescript-eslint/parser': 8.32.1(eslint@8.57.1)(typescript@5.9.3) + '@typescript-eslint/parser': 8.45.0(eslint@8.57.1)(typescript@5.9.3) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 transitivePeerDependencies: @@ -6274,7 +6154,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1): + eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.8 @@ -6285,7 +6165,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint@8.57.1) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint@8.57.1) hasown: 2.0.2 is-core-module: 2.16.1 is-glob: 4.0.3 @@ -6297,7 +6177,7 @@ snapshots: string.prototype.trimend: 1.0.9 tsconfig-paths: 3.15.0 optionalDependencies: - '@typescript-eslint/parser': 8.32.1(eslint@8.57.1)(typescript@5.9.3) + '@typescript-eslint/parser': 8.45.0(eslint@8.57.1)(typescript@5.9.3) transitivePeerDependencies: - eslint-import-resolver-typescript - eslint-import-resolver-webpack @@ -6309,7 +6189,7 @@ snapshots: eslint-plugin-jest@28.11.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3): dependencies: - '@typescript-eslint/utils': 8.32.1(eslint@8.57.1)(typescript@5.9.3) + '@typescript-eslint/utils': 8.45.0(eslint@8.57.1)(typescript@5.9.3) eslint: 8.57.1 optionalDependencies: '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3) @@ -6317,12 +6197,12 @@ snapshots: - supports-color - typescript - eslint-plugin-jest@28.11.0(@typescript-eslint/eslint-plugin@8.32.1(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3): + eslint-plugin-jest@28.11.0(@typescript-eslint/eslint-plugin@8.45.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3): dependencies: - '@typescript-eslint/utils': 8.32.1(eslint@8.57.1)(typescript@5.9.3) + '@typescript-eslint/utils': 8.45.0(eslint@8.57.1)(typescript@5.9.3) eslint: 8.57.1 optionalDependencies: - '@typescript-eslint/eslint-plugin': 8.32.1(@typescript-eslint/parser@8.32.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3) + '@typescript-eslint/eslint-plugin': 8.45.0(@typescript-eslint/parser@8.45.0(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1)(typescript@5.9.3) transitivePeerDependencies: - supports-color - typescript @@ -6453,8 +6333,6 @@ snapshots: eslint-visitor-keys@3.4.3: {} - eslint-visitor-keys@4.2.0: {} - eslint-visitor-keys@4.2.1: {} eslint@8.57.1: diff --git a/test/InverseApi3ReaderProxyV1.sol.ts b/test/InverseApi3ReaderProxyV1.sol.ts index a10bfc3..667967b 100644 --- a/test/InverseApi3ReaderProxyV1.sol.ts +++ b/test/InverseApi3ReaderProxyV1.sol.ts @@ -1,38 +1,37 @@ import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'; import * as helpers from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { ethers } from 'hardhat'; - -import * as testUtils from './test-utils'; +import hre from 'hardhat'; describe('InverseApi3ReaderProxyV1', function () { async function deploy() { const roleNames = ['deployer']; - const accounts = await ethers.getSigners(); + const accounts = await hre.ethers.getSigners(); const roles: Record = roleNames.reduce((acc, roleName, index) => { return { ...acc, [roleName]: accounts[index] }; }, {}); - const dappId = testUtils.generateRandomBytes32(); const decimals = 20; - const answer = ethers.parseUnits('1824.97', decimals); + const answer = hre.ethers.parseUnits('1824.97', decimals); const timestamp = await helpers.time.latest(); - const mockAggregatorV2V3Factory = await ethers.getContractFactory('MockAggregatorV2V3', roles.deployer); + const mockAggregatorV2V3Factory = await hre.ethers.getContractFactory('MockAggregatorV2V3', roles.deployer); const feed = await mockAggregatorV2V3Factory.deploy(decimals, answer, timestamp); - const normalizedApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const normalizedApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'NormalizedApi3ReaderProxyV1', roles.deployer ); - const proxy = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress(), dappId); + const proxy = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress()); - const inverseApi3ReaderProxyV1Factory = await ethers.getContractFactory('InverseApi3ReaderProxyV1', roles.deployer); + const inverseApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( + 'InverseApi3ReaderProxyV1', + roles.deployer + ); const inverseApi3ReaderProxyV1 = await inverseApi3ReaderProxyV1Factory.deploy(await proxy.getAddress()); return { proxy, - dappId, inverseApi3ReaderProxyV1, roles, }; @@ -43,14 +42,16 @@ describe('InverseApi3ReaderProxyV1', function () { it('constructs', async function () { const { proxy, inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); expect(await inverseApi3ReaderProxyV1.proxy()).to.equal(await proxy.getAddress()); - expect(await inverseApi3ReaderProxyV1.dappId()).to.equal(await proxy.dappId()); }); }); context('proxy is zero address', function () { it('reverts', async function () { const { roles } = await helpers.loadFixture(deploy); - const inverseApi3ReaderProxyV1 = await ethers.getContractFactory('InverseApi3ReaderProxyV1', roles.deployer); - await expect(inverseApi3ReaderProxyV1.deploy(ethers.ZeroAddress)) + const inverseApi3ReaderProxyV1 = await hre.ethers.getContractFactory( + 'InverseApi3ReaderProxyV1', + roles.deployer + ); + await expect(inverseApi3ReaderProxyV1.deploy(hre.ethers.ZeroAddress)) .to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'ZeroProxyAddress') .withArgs(); }); @@ -96,7 +97,7 @@ describe('InverseApi3ReaderProxyV1', function () { describe('getAnswer', function () { it('reverts', async function () { const { inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(inverseApi3ReaderProxyV1.getAnswer(blockNumber)) .to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -106,7 +107,7 @@ describe('InverseApi3ReaderProxyV1', function () { describe('getTimestamp', function () { it('reverts', async function () { const { inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(inverseApi3ReaderProxyV1.getTimestamp(blockNumber)) .to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -137,7 +138,7 @@ describe('InverseApi3ReaderProxyV1', function () { describe('getRoundData', function () { it('reverts', async function () { const { inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(inverseApi3ReaderProxyV1.getRoundData(blockNumber)) .to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); diff --git a/test/NormalizedApi3ReaderProxyV1.sol.ts b/test/NormalizedApi3ReaderProxyV1.sol.ts index 619c207..ef5c139 100644 --- a/test/NormalizedApi3ReaderProxyV1.sol.ts +++ b/test/NormalizedApi3ReaderProxyV1.sol.ts @@ -1,38 +1,31 @@ import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'; import * as helpers from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { ethers } from 'hardhat'; - -import * as testUtils from './test-utils'; +import hre from 'hardhat'; describe('NormalizedApi3ReaderProxyV1', function () { async function deploy() { const roleNames = ['deployer']; - const accounts = await ethers.getSigners(); + const accounts = await hre.ethers.getSigners(); const roles: Record = roleNames.reduce((acc, roleName, index) => { return { ...acc, [roleName]: accounts[index] }; }, {}); - const dappId = testUtils.generateRandomBytes32(); const decimals = 8; - const answer = ethers.parseUnits('0.25', decimals); + const answer = hre.ethers.parseUnits('0.25', decimals); const timestamp = await helpers.time.latest(); - const mockAggregatorV2V3Factory = await ethers.getContractFactory('MockAggregatorV2V3', roles.deployer); + const mockAggregatorV2V3Factory = await hre.ethers.getContractFactory('MockAggregatorV2V3', roles.deployer); const feed = await mockAggregatorV2V3Factory.deploy(decimals, answer, timestamp); - const normalizedApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const normalizedApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'NormalizedApi3ReaderProxyV1', roles.deployer ); - const normalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory.deploy( - await feed.getAddress(), - dappId - ); + const normalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress()); return { feed, - dappId, mockAggregatorV2V3Factory, normalizedApi3ReaderProxyV1, roles, @@ -51,22 +44,25 @@ describe('NormalizedApi3ReaderProxyV1', function () { context('feed is not zero address', function () { context('feed does not have 18 decimals', function () { it('constructs', async function () { - const { feed, dappId, normalizedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); + const { feed, normalizedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); expect(await normalizedApi3ReaderProxyV1.feed()).to.equal(await feed.getAddress()); - expect(await normalizedApi3ReaderProxyV1.dappId()).to.equal(dappId); expect(await normalizedApi3ReaderProxyV1.isUpscaling()).to.equal(true); // 8 < 18 is true expect(await normalizedApi3ReaderProxyV1.scalingFactor()).to.equal(10_000_000_000n); // 10**(18-8) }); }); context('feed has 18 decimals', function () { it('reverts', async function () { - const { dappId, roles, mockAggregatorV2V3Factory } = await helpers.loadFixture(deploy); - const feed = await mockAggregatorV2V3Factory.deploy(18, ethers.parseEther('1'), await helpers.time.latest()); - const normalizedApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const { roles, mockAggregatorV2V3Factory } = await helpers.loadFixture(deploy); + const feed = await mockAggregatorV2V3Factory.deploy( + 18, + hre.ethers.parseEther('1'), + await helpers.time.latest() + ); + const normalizedApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'NormalizedApi3ReaderProxyV1', roles.deployer ); - await expect(normalizedApi3ReaderProxyV1Factory.deploy(feed, dappId)) + await expect(normalizedApi3ReaderProxyV1Factory.deploy(feed)) .to.be.revertedWithCustomError(normalizedApi3ReaderProxyV1Factory, 'NoNormalizationNeeded') .withArgs(); }); @@ -74,12 +70,12 @@ describe('NormalizedApi3ReaderProxyV1', function () { }); context('feed is zero address', function () { it('reverts', async function () { - const { dappId, roles } = await helpers.loadFixture(deploy); - const normalizedApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const { roles } = await helpers.loadFixture(deploy); + const normalizedApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'NormalizedApi3ReaderProxyV1', roles.deployer ); - await expect(normalizedApi3ReaderProxyV1Factory.deploy(ethers.ZeroAddress, dappId)) + await expect(normalizedApi3ReaderProxyV1Factory.deploy(hre.ethers.ZeroAddress)) .to.be.revertedWithCustomError(normalizedApi3ReaderProxyV1Factory, 'ZeroProxyAddress') .withArgs(); }); @@ -88,8 +84,7 @@ describe('NormalizedApi3ReaderProxyV1', function () { describe('read', function () { it('reads the normalized to 18 decimals rate', async function () { - const { feed, dappId, mockAggregatorV2V3Factory, normalizedApi3ReaderProxyV1, roles } = - await helpers.loadFixture(deploy); + const { feed, mockAggregatorV2V3Factory, normalizedApi3ReaderProxyV1, roles } = await helpers.loadFixture(deploy); const decimals = await feed.decimals(); const [, answer, , updatedAt] = await feed.latestRoundData(); @@ -101,13 +96,12 @@ describe('NormalizedApi3ReaderProxyV1', function () { // Normalizes down const newFeed = await mockAggregatorV2V3Factory.deploy(8, answer, updatedAt); - const normalizedApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const normalizedApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'NormalizedApi3ReaderProxyV1', roles.deployer ); const newNormalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory.deploy( - await newFeed.getAddress(), - dappId + await newFeed.getAddress() ); const newDataFeed = await newNormalizedApi3ReaderProxyV1.read(); expect(newDataFeed.value).to.equal(normalize(answer, 8)); @@ -143,7 +137,7 @@ describe('NormalizedApi3ReaderProxyV1', function () { describe('getAnswer', function () { it('reverts', async function () { const { normalizedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(normalizedApi3ReaderProxyV1.getAnswer(blockNumber)) .to.be.revertedWithCustomError(normalizedApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -153,7 +147,7 @@ describe('NormalizedApi3ReaderProxyV1', function () { describe('getTimestamp', function () { it('reverts', async function () { const { normalizedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(normalizedApi3ReaderProxyV1.getTimestamp(blockNumber)) .to.be.revertedWithCustomError(normalizedApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -184,7 +178,7 @@ describe('NormalizedApi3ReaderProxyV1', function () { describe('getRoundData', function () { it('reverts', async function () { const { normalizedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(normalizedApi3ReaderProxyV1.getRoundData(blockNumber)) .to.be.revertedWithCustomError(normalizedApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); diff --git a/test/PriceCappedApi3ReaderProxyV1.sol.ts b/test/PriceCappedApi3ReaderProxyV1.sol.ts index faf32cc..1e126b7 100644 --- a/test/PriceCappedApi3ReaderProxyV1.sol.ts +++ b/test/PriceCappedApi3ReaderProxyV1.sol.ts @@ -1,28 +1,25 @@ import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'; import * as helpers from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { ethers } from 'hardhat'; - -import * as testUtils from './test-utils'; +import hre from 'hardhat'; describe('PriceCappedApi3ReaderProxyV1', function () { async function deploy() { const roleNames = ['deployer']; - const accounts = await ethers.getSigners(); + const accounts = await hre.ethers.getSigners(); const roles: Record = roleNames.reduce((acc, roleName, index) => { return { ...acc, [roleName]: accounts[index] }; }, {}); - const dappId = testUtils.generateRandomBytes32(); - const beaconValue = ethers.parseEther('1.0001'); + const beaconValue = hre.ethers.parseEther('1.0001'); const beaconTimestamp = await helpers.time.latest(); - const mockApi3ReaderProxyV1Factory = await ethers.getContractFactory('MockApi3ReaderProxyV1', roles.deployer); - const proxy = await mockApi3ReaderProxyV1Factory.deploy(dappId, beaconValue, beaconTimestamp); + const mockApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory('MockApi3ReaderProxyV1', roles.deployer); + const proxy = await mockApi3ReaderProxyV1Factory.deploy(beaconValue, beaconTimestamp); - const lowerBound = ethers.parseEther('0.9995'); - const upperBound = ethers.parseEther('1.0005'); + const lowerBound = hre.ethers.parseEther('0.9995'); + const upperBound = hre.ethers.parseEther('1.0005'); - const priceCappedApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const priceCappedApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'PriceCappedApi3ReaderProxyV1', roles.deployer ); @@ -48,7 +45,6 @@ describe('PriceCappedApi3ReaderProxyV1', function () { it('constructs', async function () { const { proxy, priceCappedApi3ReaderProxyV1, lowerBound, upperBound } = await helpers.loadFixture(deploy); expect(await priceCappedApi3ReaderProxyV1.proxy()).to.equal(await proxy.getAddress()); - expect(await priceCappedApi3ReaderProxyV1.dappId()).to.equal(await proxy.dappId()); expect(await priceCappedApi3ReaderProxyV1.lowerBound()).to.equal(lowerBound); expect(await priceCappedApi3ReaderProxyV1.upperBound()).to.equal(upperBound); }); @@ -56,7 +52,7 @@ describe('PriceCappedApi3ReaderProxyV1', function () { context('upperBound is less than lowerBound', function () { it('reverts', async function () { const { proxy, lowerBound, upperBound, roles } = await helpers.loadFixture(deploy); - const priceCappedApi3ReaderProxyV1 = await ethers.getContractFactory( + const priceCappedApi3ReaderProxyV1 = await hre.ethers.getContractFactory( 'PriceCappedApi3ReaderProxyV1', roles.deployer ); @@ -69,11 +65,11 @@ describe('PriceCappedApi3ReaderProxyV1', function () { context('lowerBound is negative', function () { it('reverts', async function () { const { proxy, upperBound, roles } = await helpers.loadFixture(deploy); - const priceCappedApi3ReaderProxyV1 = await ethers.getContractFactory( + const priceCappedApi3ReaderProxyV1 = await hre.ethers.getContractFactory( 'PriceCappedApi3ReaderProxyV1', roles.deployer ); - await expect(priceCappedApi3ReaderProxyV1.deploy(proxy, ethers.parseEther('-0.9995'), upperBound)) + await expect(priceCappedApi3ReaderProxyV1.deploy(proxy, hre.ethers.parseEther('-0.9995'), upperBound)) .to.be.revertedWithCustomError(priceCappedApi3ReaderProxyV1, 'LowerBoundMustBeNonNegative') .withArgs(); }); @@ -82,11 +78,11 @@ describe('PriceCappedApi3ReaderProxyV1', function () { context('proxy is zero address', function () { it('reverts', async function () { const { roles, lowerBound, upperBound } = await helpers.loadFixture(deploy); - const priceCappedApi3ReaderProxyV1 = await ethers.getContractFactory( + const priceCappedApi3ReaderProxyV1 = await hre.ethers.getContractFactory( 'PriceCappedApi3ReaderProxyV1', roles.deployer ); - await expect(priceCappedApi3ReaderProxyV1.deploy(ethers.ZeroAddress, lowerBound, upperBound)) + await expect(priceCappedApi3ReaderProxyV1.deploy(hre.ethers.ZeroAddress, lowerBound, upperBound)) .to.be.revertedWithCustomError(priceCappedApi3ReaderProxyV1, 'ZeroProxyAddress') .withArgs(); }); @@ -103,14 +99,14 @@ describe('PriceCappedApi3ReaderProxyV1', function () { expect(dataFeed.timestamp).to.equal(timestamp); let newTimestamp = await helpers.time.latest(); - await proxy.update(ethers.parseEther('0.9991'), newTimestamp); + await proxy.update(hre.ethers.parseEther('0.9991'), newTimestamp); const cappedToLowerBoundDataFeed = await priceCappedApi3ReaderProxyV1.read(); expect(cappedToLowerBoundDataFeed.value).to.equal(lowerBound); expect(cappedToLowerBoundDataFeed.timestamp).to.equal(newTimestamp); newTimestamp = await helpers.time.latest(); - await proxy.update(ethers.parseEther('1.0006'), newTimestamp); + await proxy.update(hre.ethers.parseEther('1.0006'), newTimestamp); const cappedToUpperBoundDataFeed = await priceCappedApi3ReaderProxyV1.read(); expect(cappedToUpperBoundDataFeed.value).to.equal(upperBound); @@ -146,7 +142,7 @@ describe('PriceCappedApi3ReaderProxyV1', function () { describe('getAnswer', function () { it('reverts', async function () { const { priceCappedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(priceCappedApi3ReaderProxyV1.getAnswer(blockNumber)) .to.be.revertedWithCustomError(priceCappedApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -156,7 +152,7 @@ describe('PriceCappedApi3ReaderProxyV1', function () { describe('getTimestamp', function () { it('reverts', async function () { const { priceCappedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(priceCappedApi3ReaderProxyV1.getTimestamp(blockNumber)) .to.be.revertedWithCustomError(priceCappedApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -187,7 +183,7 @@ describe('PriceCappedApi3ReaderProxyV1', function () { describe('getRoundData', function () { it('reverts', async function () { const { priceCappedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(priceCappedApi3ReaderProxyV1.getRoundData(blockNumber)) .to.be.revertedWithCustomError(priceCappedApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); diff --git a/test/ProductApi3ReaderProxyV1.sol.ts b/test/ProductApi3ReaderProxyV1.sol.ts index c6ace49..41277ea 100644 --- a/test/ProductApi3ReaderProxyV1.sol.ts +++ b/test/ProductApi3ReaderProxyV1.sol.ts @@ -1,28 +1,28 @@ import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'; import * as helpers from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { ethers } from 'hardhat'; - -import * as testUtils from './test-utils'; +import hre from 'hardhat'; describe('ProductApi3ReaderProxyV1', function () { async function deploy() { const roleNames = ['deployer']; - const accounts = await ethers.getSigners(); + const accounts = await hre.ethers.getSigners(); const roles: Record = roleNames.reduce((acc, roleName, index) => { return { ...acc, [roleName]: accounts[index] }; }, {}); - const dappId = testUtils.generateRandomBytes32(); - const mockApi3ReaderProxyV1Factory = await ethers.getContractFactory('MockApi3ReaderProxyV1', roles.deployer); - const beaconValue1 = ethers.parseEther('1824.97'); + const mockApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory('MockApi3ReaderProxyV1', roles.deployer); + const beaconValue1 = hre.ethers.parseEther('1824.97'); const beaconTimestamp1 = await helpers.time.latest(); - const proxy1 = await mockApi3ReaderProxyV1Factory.deploy(dappId, beaconValue1, beaconTimestamp1); - const beaconValue2 = ethers.parseEther('0.08202'); + const proxy1 = await mockApi3ReaderProxyV1Factory.deploy(beaconValue1, beaconTimestamp1); + const beaconValue2 = hre.ethers.parseEther('0.08202'); const beaconTimestamp2 = await helpers.time.latest(); - const proxy2 = await mockApi3ReaderProxyV1Factory.deploy(dappId, beaconValue2, beaconTimestamp2); + const proxy2 = await mockApi3ReaderProxyV1Factory.deploy(beaconValue2, beaconTimestamp2); - const productApi3ReaderProxyV1Factory = await ethers.getContractFactory('ProductApi3ReaderProxyV1', roles.deployer); + const productApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( + 'ProductApi3ReaderProxyV1', + roles.deployer + ); const productApi3ReaderProxyV1 = await productApi3ReaderProxyV1Factory.deploy( proxy1.getAddress(), @@ -52,20 +52,16 @@ describe('ProductApi3ReaderProxyV1', function () { await helpers.loadFixture(deploy); expect(await productApi3ReaderProxyV1.proxy1()).to.equal(await proxy1.getAddress()); expect(await productApi3ReaderProxyV1.proxy2()).to.equal(await proxy2.getAddress()); - expect(await productApi3ReaderProxyV1.dappId()).to.equal(await proxy1.dappId()); - expect(await productApi3ReaderProxyV1.dappId()).to.equal(await proxy2.dappId()); expect(await productApi3ReaderProxyV1Compound.proxy1()).to.equal(await proxy1.getAddress()); expect(await productApi3ReaderProxyV1Compound.proxy2()).to.equal( await productApi3ReaderProxyV1.getAddress() ); - expect(await productApi3ReaderProxyV1Compound.dappId()).to.equal(await proxy1.dappId()); - expect(await productApi3ReaderProxyV1Compound.dappId()).to.equal(await productApi3ReaderProxyV1.dappId()); }); }); context('proxy1 is the same as proxy2', function () { it('reverts', async function () { const { proxy1, roles } = await helpers.loadFixture(deploy); - const productApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const productApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'ProductApi3ReaderProxyV1', roles.deployer ); @@ -78,11 +74,11 @@ describe('ProductApi3ReaderProxyV1', function () { context('proxy2 is zero address', function () { it('reverts', async function () { const { proxy1, roles } = await helpers.loadFixture(deploy); - const productApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const productApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'ProductApi3ReaderProxyV1', roles.deployer ); - await expect(productApi3ReaderProxyV1Factory.deploy(await proxy1.getAddress(), ethers.ZeroAddress)) + await expect(productApi3ReaderProxyV1Factory.deploy(await proxy1.getAddress(), hre.ethers.ZeroAddress)) .to.be.revertedWithCustomError(productApi3ReaderProxyV1Factory, 'ZeroProxyAddress') .withArgs(); }); @@ -91,11 +87,11 @@ describe('ProductApi3ReaderProxyV1', function () { context('proxy1 is zero address', function () { it('reverts', async function () { const { proxy1, roles } = await helpers.loadFixture(deploy); - const productApi3ReaderProxyV1Factory = await ethers.getContractFactory( + const productApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory( 'ProductApi3ReaderProxyV1', roles.deployer ); - await expect(productApi3ReaderProxyV1Factory.deploy(ethers.ZeroAddress, await proxy1.getAddress())) + await expect(productApi3ReaderProxyV1Factory.deploy(hre.ethers.ZeroAddress, await proxy1.getAddress())) .to.be.revertedWithCustomError(productApi3ReaderProxyV1Factory, 'ZeroProxyAddress') .withArgs(); }); @@ -141,7 +137,7 @@ describe('ProductApi3ReaderProxyV1', function () { describe('getAnswer', function () { it('reverts', async function () { const { productApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(productApi3ReaderProxyV1.getAnswer(blockNumber)) .to.be.revertedWithCustomError(productApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -151,7 +147,7 @@ describe('ProductApi3ReaderProxyV1', function () { describe('getTimestamp', function () { it('reverts', async function () { const { productApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(productApi3ReaderProxyV1.getTimestamp(blockNumber)) .to.be.revertedWithCustomError(productApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -182,7 +178,7 @@ describe('ProductApi3ReaderProxyV1', function () { describe('getRoundData', function () { it('reverts', async function () { const { productApi3ReaderProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(productApi3ReaderProxyV1.getRoundData(blockNumber)) .to.be.revertedWithCustomError(productApi3ReaderProxyV1, 'FunctionIsNotSupported') .withArgs(); diff --git a/test/adapters/ScaledApi3FeedProxyV1.sol.ts b/test/adapters/ScaledApi3FeedProxyV1.sol.ts index f84cf27..e326447 100644 --- a/test/adapters/ScaledApi3FeedProxyV1.sol.ts +++ b/test/adapters/ScaledApi3FeedProxyV1.sol.ts @@ -1,27 +1,24 @@ import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'; import * as helpers from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { ethers } from 'hardhat'; - -import * as testUtils from '../test-utils'; +import hre from 'hardhat'; describe('ScaledApi3FeedProxyV1', function () { async function deploy() { const roleNames = ['deployer']; - const accounts = await ethers.getSigners(); + const accounts = await hre.ethers.getSigners(); const roles: Record = roleNames.reduce((acc, roleName, index) => { return { ...acc, [roleName]: accounts[index] }; }, {}); - const dappId = testUtils.generateRandomBytes32(); - const beaconValue = ethers.parseEther('1.0001'); + const beaconValue = hre.ethers.parseEther('1.0001'); const beaconTimestamp = await helpers.time.latest(); - const mockproxyFactory = await ethers.getContractFactory('MockApi3ReaderProxyV1', roles.deployer); - const proxy = await mockproxyFactory.deploy(dappId, beaconValue, beaconTimestamp); + const mockproxyFactory = await hre.ethers.getContractFactory('MockApi3ReaderProxyV1', roles.deployer); + const proxy = await mockproxyFactory.deploy(beaconValue, beaconTimestamp); const decimals = 8; - const scaledApi3FeedProxyV1Factory = await ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); + const scaledApi3FeedProxyV1Factory = await hre.ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); const scaledApi3FeedProxyV1 = await scaledApi3FeedProxyV1Factory.deploy(await proxy.getAddress(), decimals); return { @@ -47,7 +44,6 @@ describe('ScaledApi3FeedProxyV1', function () { it('constructs', async function () { const { proxy, scaledApi3FeedProxyV1 } = await helpers.loadFixture(deploy); expect(await scaledApi3FeedProxyV1.proxy()).to.equal(await proxy.getAddress()); - expect(await scaledApi3FeedProxyV1.dappId()).to.equal(await proxy.dappId()); expect(await scaledApi3FeedProxyV1.isUpscaling()).to.equal(false); // targetDecimals (8) > 18 is false expect(await scaledApi3FeedProxyV1.scalingFactor()).to.equal(10_000_000_000n); // 10**(18-8) }); @@ -55,7 +51,7 @@ describe('ScaledApi3FeedProxyV1', function () { context('targetDecimals is 18', function () { it('reverts', async function () { const { proxy, roles } = await helpers.loadFixture(deploy); - const scaledApi3FeedProxyV1 = await ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); + const scaledApi3FeedProxyV1 = await hre.ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); await expect(scaledApi3FeedProxyV1.deploy(await proxy.getAddress(), 18)) .to.be.revertedWithCustomError(scaledApi3FeedProxyV1, 'NoScalingNeeded') .withArgs(); @@ -65,7 +61,7 @@ describe('ScaledApi3FeedProxyV1', function () { context('targetDecimals is invalid', function () { it('reverts', async function () { const { proxy, roles } = await helpers.loadFixture(deploy); - const scaledApi3FeedProxyV1 = await ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); + const scaledApi3FeedProxyV1 = await hre.ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); await expect(scaledApi3FeedProxyV1.deploy(await proxy.getAddress(), 0)) .to.be.revertedWithCustomError(scaledApi3FeedProxyV1, 'InvalidDecimals') .withArgs(); @@ -78,8 +74,8 @@ describe('ScaledApi3FeedProxyV1', function () { context('proxy is zero address', function () { it('reverts', async function () { const { decimals, roles } = await helpers.loadFixture(deploy); - const scaledApi3FeedProxyV1 = await ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); - await expect(scaledApi3FeedProxyV1.deploy(ethers.ZeroAddress, decimals)) + const scaledApi3FeedProxyV1 = await hre.ethers.getContractFactory('ScaledApi3FeedProxyV1', roles.deployer); + await expect(scaledApi3FeedProxyV1.deploy(hre.ethers.ZeroAddress, decimals)) .to.be.revertedWithCustomError(scaledApi3FeedProxyV1, 'ZeroProxyAddress') .withArgs(); }); @@ -114,7 +110,7 @@ describe('ScaledApi3FeedProxyV1', function () { describe('getAnswer', function () { it('reverts', async function () { const { scaledApi3FeedProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(scaledApi3FeedProxyV1.getAnswer(blockNumber)) .to.be.revertedWithCustomError(scaledApi3FeedProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -124,7 +120,7 @@ describe('ScaledApi3FeedProxyV1', function () { describe('getTimestamp', function () { it('reverts', async function () { const { scaledApi3FeedProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(scaledApi3FeedProxyV1.getTimestamp(blockNumber)) .to.be.revertedWithCustomError(scaledApi3FeedProxyV1, 'FunctionIsNotSupported') .withArgs(); @@ -155,7 +151,7 @@ describe('ScaledApi3FeedProxyV1', function () { describe('getRoundData', function () { it('reverts', async function () { const { scaledApi3FeedProxyV1 } = await helpers.loadFixture(deploy); - const blockNumber = await ethers.provider.getBlockNumber(); + const blockNumber = await hre.ethers.provider.getBlockNumber(); await expect(scaledApi3FeedProxyV1.getRoundData(blockNumber)) .to.be.revertedWithCustomError(scaledApi3FeedProxyV1, 'FunctionIsNotSupported') .withArgs(); diff --git a/test/test-utils.ts b/test/test-utils.ts deleted file mode 100644 index 4fdfcc2..0000000 --- a/test/test-utils.ts +++ /dev/null @@ -1,251 +0,0 @@ -import type { Api3ServerV1 } from '@api3/contracts'; -import type { AddressLike, BaseWallet, BigNumberish, BytesLike } from 'ethers'; -import { ethers } from 'hardhat'; - -const PROTOCOL_IDS = { - RRP: '1', - PSP: '2', - RELAYED_RRP: '3', - RELAYED_PSP: '4', - AIRSEEKER: '5', - AIRKEEPER: '12345', -}; - -const BIT_MASK_FOR_LEAST_SIGNIFICANT_31_BITS = BigInt(2 ** 31 - 1); - -const ROOT_PATH = "m/44'/60'/0'"; - -function deriveWalletPathFromSponsorAddress(sponsorAddress: AddressLike, protocolId: number) { - const sponsorAddressBN = BigInt(sponsorAddress as any); - const paths = []; - for (let i = 0; i < 6; i++) { - const shiftedSponsorAddressBN = sponsorAddressBN >> BigInt(31 * i); - paths.push((shiftedSponsorAddressBN & BIT_MASK_FOR_LEAST_SIGNIFICANT_31_BITS).toString()); - } - return `${protocolId}/${paths.join('/')}`; -} - -function generateRandomAirnodeWallet() { - const airnodeWallet = ethers.HDNodeWallet.createRandom(); - const airnodeMnemonic = airnodeWallet.mnemonic!.phrase; - const airnodeXpub = ethers.HDNodeWallet.fromPhrase(airnodeMnemonic, undefined, ROOT_PATH).neuter().extendedKey; - return { airnodeAddress: airnodeWallet.address, airnodeMnemonic, airnodeXpub }; -} - -function generateRandomAddress() { - return ethers.getAddress(ethers.hexlify(ethers.randomBytes(20))); -} - -function generateRandomBytes32() { - return ethers.hexlify(ethers.randomBytes(32)); -} - -function generateRandomBytes() { - return ethers.hexlify(ethers.randomBytes(256)); -} - -function deriveSponsorWalletAddress(airnodeXpub: string, sponsorAddress: AddressLike, protocolId: number) { - return ethers.HDNodeWallet.fromExtendedKey(airnodeXpub).derivePath( - deriveWalletPathFromSponsorAddress(sponsorAddress, protocolId) - ).address; -} - -function deriveSponsorWallet(airnodeMnemonic: string, sponsorAddress: AddressLike, protocolId: number) { - return ethers.HDNodeWallet.fromPhrase( - airnodeMnemonic, - undefined, - `${ROOT_PATH}/${deriveWalletPathFromSponsorAddress(sponsorAddress, protocolId)}` - ); -} - -function decodeRevertString(returndata: BytesLike) { - try { - return ethers.AbiCoder.defaultAbiCoder().decode(['string'], `0x${returndata.toString().slice(2 + 4 * 2)}`)[0]; - } catch { - return 'No revert string'; - } -} - -function deriveRootRole(managerAddress: AddressLike) { - return ethers.solidityPackedKeccak256(['address'], [managerAddress]); -} - -function deriveRole(adminRole: BytesLike, roleDescription: string) { - return ethers.solidityPackedKeccak256( - ['bytes32', 'bytes32'], - [adminRole, ethers.solidityPackedKeccak256(['string'], [roleDescription])] - ); -} - -async function signData(airnode: BaseWallet, templateId: BytesLike, timestamp: number, data: BytesLike) { - const signature = await airnode.signMessage( - ethers.getBytes(ethers.solidityPackedKeccak256(['bytes32', 'uint256', 'bytes'], [templateId, timestamp, data])) - ); - return signature; -} - -async function signOevData( - api3ServerV1: Api3ServerV1, - oevProxyAddress: AddressLike, - dataFeedId: BytesLike, - updateId: BytesLike, - timestamp: number, - data: BytesLike, - searcherAddress: AddressLike, - bidAmount: BigNumberish, - airnode: BaseWallet, - templateId: BytesLike -) { - const { chainId } = await api3ServerV1.runner!.provider!.getNetwork(); - const oevUpdateHash = ethers.solidityPackedKeccak256( - ['uint256', 'address', 'address', 'bytes32', 'bytes32', 'uint256', 'bytes', 'address', 'uint256'], - [ - chainId, - await api3ServerV1.getAddress(), - oevProxyAddress, - dataFeedId, - updateId, - timestamp, - data, - searcherAddress, - bidAmount, - ] - ); - const signature = await airnode.signMessage( - ethers.getBytes(ethers.solidityPackedKeccak256(['bytes32', 'bytes32'], [oevUpdateHash, templateId])) - ); - return signature; -} - -async function updateBeacon( - api3ServerV1: Api3ServerV1, - feedName: string, - airnode: BaseWallet, - timestamp: BigNumberish, - value: BigNumberish -) { - const encodedValue = ethers.AbiCoder.defaultAbiCoder().encode(['int224'], [value]); - const templateId = deriveTemplateId(`OIS title of Airnode with address ${airnode.address}`, feedName); - const beaconId = deriveBeaconId(airnode.address, templateId); - await api3ServerV1.updateBeaconWithSignedData( - airnode.address, - templateId, - timestamp, - encodedValue, - await airnode.signMessage( - ethers.getBytes( - ethers.solidityPackedKeccak256(['bytes32', 'uint256', 'bytes'], [templateId, timestamp, encodedValue]) - ) - ) - ); - return { - templateId, - beaconId, - }; -} - -async function updateBeaconSet( - api3ServerV1: Api3ServerV1, - feedName: string, - airnodes: BaseWallet[], - timestamp: BigNumberish, - value: BigNumberish -) { - const encodedValue = ethers.AbiCoder.defaultAbiCoder().encode(['int224'], [value]); - - const beaconUpdateData = airnodes.map((airnode) => { - const templateId = deriveTemplateId(`OIS title of Airnode with address ${airnode.address}`, feedName); - return { - airnode, - templateId, - beaconId: deriveBeaconId(airnode.address, templateId), - }; - }); - for (const beaconUpdateDatum of beaconUpdateData) { - await api3ServerV1.updateBeaconWithSignedData( - beaconUpdateDatum.airnode.address, - beaconUpdateDatum.templateId, - timestamp, - encodedValue, - await beaconUpdateDatum.airnode.signMessage( - ethers.getBytes( - ethers.solidityPackedKeccak256( - ['bytes32', 'uint256', 'bytes'], - [beaconUpdateDatum.templateId, timestamp, encodedValue] - ) - ) - ) - ); - } - const beaconIds = beaconUpdateData.map((beaconUpdateDatum) => beaconUpdateDatum.beaconId); - await api3ServerV1.updateBeaconSetWithBeacons(beaconIds); - return { - templateIds: beaconUpdateData.map((beaconUpdateDatum) => beaconUpdateDatum.templateId), - beaconIds, - beaconSetId: deriveBeaconSetId(beaconIds), - }; -} - -async function readBeacons(api3ServerV1: Api3ServerV1, beaconIds: BytesLike[]) { - const returndata = await api3ServerV1.multicall.staticCall( - beaconIds.map((beaconId) => api3ServerV1.interface.encodeFunctionData('dataFeeds', [beaconId])) - ); - return returndata - .map((returndata) => ethers.AbiCoder.defaultAbiCoder().decode(['int224', 'uint32'], returndata)) - .map((decodedReturnData) => { - return { value: decodedReturnData[0], timestamp: decodedReturnData[1] }; - }); -} - -function encodeUpdateParameters(deviationThreshold: number, deviationReference: number, heartbeatInterval: number) { - return ethers.AbiCoder.defaultAbiCoder().encode( - ['uint256', 'int224', 'uint256'], - [deviationThreshold, deviationReference, heartbeatInterval] - ); -} - -function deriveTemplateId(oisTitle: string, feedName: string) { - const endpointId = ethers.solidityPackedKeccak256(['string', 'string'], [oisTitle, 'feed']); - // Parameters encoded in Airnode ABI - // https://docs.api3.org/reference/airnode/latest/specifications/airnode-abi.html - return ethers.solidityPackedKeccak256( - ['bytes32', 'bytes'], - [ - endpointId, - ethers.AbiCoder.defaultAbiCoder().encode( - ['bytes32', 'bytes32', 'bytes32'], - [ethers.encodeBytes32String('1b'), ethers.encodeBytes32String('name'), ethers.encodeBytes32String(feedName)] - ), - ] - ); -} - -function deriveBeaconId(airnodeAddress: AddressLike, templateId: BytesLike) { - return ethers.solidityPackedKeccak256(['address', 'bytes32'], [airnodeAddress, templateId]); -} - -function deriveBeaconSetId(beaconIds: BytesLike[]) { - return ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(['bytes32[]'], [beaconIds])); -} - -export { - decodeRevertString, - deriveBeaconId, - deriveBeaconSetId, - deriveRole, - deriveRootRole, - deriveSponsorWallet, - deriveSponsorWalletAddress, - deriveTemplateId, - encodeUpdateParameters, - generateRandomAddress, - generateRandomAirnodeWallet, - generateRandomBytes, - generateRandomBytes32, - PROTOCOL_IDS, - readBeacons, - signData, - signOevData, - updateBeacon, - updateBeaconSet, -};