diff --git a/.changeset/tough-sloths-hammer.md b/.changeset/tough-sloths-hammer.md new file mode 100644 index 0000000000..07dda285b4 --- /dev/null +++ b/.changeset/tough-sloths-hammer.md @@ -0,0 +1,9 @@ +--- +'@api3/airnode-utilities': minor +'@api3/airnode-deployer': minor +'@api3/airnode-examples': minor +'@api3/airnode-admin': minor +'@api3/airnode-node': minor +--- + +Replace Node.js 18 with Node.js 20 diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 69c5fbfb09..ee89c52e36 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -9,7 +9,7 @@ on: env: DOCKER_BUILDKIT: 1 - TARGET_NODE_VERSION: '18.14.0' + TARGET_NODE_VERSION: '20.10.0' jobs: documentation: @@ -139,6 +139,8 @@ jobs: with: node-version: ${{ env.TARGET_NODE_VERSION }} cache: yarn + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 - name: Start background services run: yarn run dev:background - run: yarn run test:e2e-${{ matrix.package }} @@ -159,6 +161,8 @@ jobs: with: node-version: ${{ env.TARGET_NODE_VERSION }} cache: yarn + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 - name: Start background services run: yarn run dev:background - run: yarn run test:e2e-examples diff --git a/.github/workflows/protocol-verify.yml b/.github/workflows/protocol-verify.yml index d9ecf97319..74a46ed191 100644 --- a/.github/workflows/protocol-verify.yml +++ b/.github/workflows/protocol-verify.yml @@ -11,7 +11,7 @@ on: env: DOCKER_BUILDKIT: 1 - TARGET_NODE_VERSION: '18.14.0' + TARGET_NODE_VERSION: '20.10.0' jobs: pre-build: diff --git a/docker/Dockerfile b/docker/Dockerfile index c3e129f7a5..2406e78c90 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18.14.0-alpine3.17 AS environment +FROM node:20.10.0-alpine3.17 AS environment ENV appDir="/app" \ buildDir="/build" \ @@ -7,7 +7,7 @@ ENV appDir="/app" \ CI="true" RUN apk add --update --no-cache git rsync docker $([ $(arch) == "aarch64" ] && echo "python3 make g++") && \ - yarn global add npm@^9.8.1 && \ + yarn global add npm && \ # Download both solidity compilers as per: https://github.com/nomiclabs/hardhat/issues/1280#issuecomment-949822371 mkdir -p /root/.cache/hardhat-nodejs/compilers-v2/wasm && \ wget -O /root/.cache/hardhat-nodejs/compilers-v2/wasm/soljson-v0.8.9+commit.e5eed63a.js https://solc-bin.ethereum.org/wasm/soljson-v0.8.9+commit.e5eed63a.js && \ diff --git a/package.json b/package.json index 078dadb554..443772901c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "0.1.0", "private": true, "engines": { - "node": "^18.14.0" + "node": "^20.10.0" }, "repository": { "type": "git", @@ -110,7 +110,7 @@ "@changesets/cli": "^2.27.1", "@octokit/core": "^5.1.0", "@types/libsodium-wrappers": "^0.7.13", - "@types/node": "^18.19.21", + "@types/node": "^20.10.0", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "@vercel/ncc": "^0.38.1", @@ -131,5 +131,6 @@ "ts-node": "^10.9.2", "typescript": "^5.3.3", "yargs": "^17.7.2" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/packages/airnode-adapter/package.json b/packages/airnode-adapter/package.json index 7b12666b66..d37dff2bff 100644 --- a/packages/airnode-adapter/package.json +++ b/packages/airnode-adapter/package.json @@ -34,7 +34,7 @@ "@types/mocha": "^10.0.6", "chai": "^4.4.1", "ethereum-waffle": "^4.0.10", - "hardhat": "^2.14.1", + "hardhat": "^2.23.0-dev.3", "jest": "^29.7.0", "rimraf": "^5.0.5", "ts-jest": "^29.1.2", diff --git a/packages/airnode-adapter/src/request-building/build-request.test.ts b/packages/airnode-adapter/src/request-building/build-request.test.ts index 933e8c771a..288198c0a4 100644 --- a/packages/airnode-adapter/src/request-building/build-request.test.ts +++ b/packages/airnode-adapter/src/request-building/build-request.test.ts @@ -6,7 +6,7 @@ describe('buildingRequest', () => { const options = fixtures.buildRequestOptions(); const res = build.buildRequest(options); expect(res).toEqual({ - baseUrl: 'http://localhost:5000', + baseUrl: 'http://localhost:5005', data: { access_key: 'super-secret-key', amount: '1', diff --git a/packages/airnode-adapter/src/request-building/execution.test.ts b/packages/airnode-adapter/src/request-building/execution.test.ts index a61a0e371f..74e2d02057 100644 --- a/packages/airnode-adapter/src/request-building/execution.test.ts +++ b/packages/airnode-adapter/src/request-building/execution.test.ts @@ -10,7 +10,7 @@ describe('executeRequest', () => { it('executes simple GET requests', async () => { responseMock.mockResolvedValueOnce({ value: '10000' }); const request: Request = { - baseUrl: 'http://localhost:5000', + baseUrl: 'http://localhost:5005', data: { from: 'ETH', to: 'USD' }, headers: { api_key: 'supersecret' }, method: 'get', @@ -20,7 +20,7 @@ describe('executeRequest', () => { expect(res).toEqual({ value: '10000' }); expect(axios).toHaveBeenCalledTimes(1); expect(axios).toHaveBeenCalledWith({ - url: 'http://localhost:5000/convert', + url: 'http://localhost:5005/convert', method: 'get', headers: { api_key: 'supersecret' }, params: { from: 'ETH', to: 'USD' }, @@ -30,7 +30,7 @@ describe('executeRequest', () => { it('executes GET requests with config', async () => { responseMock.mockResolvedValueOnce({ value: '10000' }); const request: Request = { - baseUrl: 'http://localhost:5000', + baseUrl: 'http://localhost:5005', data: { from: 'ETH', to: 'USD' }, headers: { api_key: 'supersecret' }, method: 'get', @@ -40,7 +40,7 @@ describe('executeRequest', () => { expect(res).toEqual({ value: '10000' }); expect(axios).toHaveBeenCalledTimes(1); expect(axios).toHaveBeenCalledWith({ - url: 'http://localhost:5000/convert', + url: 'http://localhost:5005/convert', method: 'get', headers: { api_key: 'supersecret' }, params: { from: 'ETH', to: 'USD' }, @@ -51,7 +51,7 @@ describe('executeRequest', () => { it('executes simple POST requests', async () => { responseMock.mockResolvedValueOnce({ value: '10000' }); const request: Request = { - baseUrl: 'http://localhost:5000', + baseUrl: 'http://localhost:5005', data: { from: 'ETH', to: 'USD' }, headers: { api_key: 'supersecret' }, method: 'post', @@ -61,7 +61,7 @@ describe('executeRequest', () => { expect(res).toEqual({ value: '10000' }); expect(axios).toHaveBeenCalledTimes(1); expect(axios).toHaveBeenCalledWith({ - url: 'http://localhost:5000/convert', + url: 'http://localhost:5005/convert', method: 'post', headers: { api_key: 'supersecret' }, data: { from: 'ETH', to: 'USD' }, @@ -71,7 +71,7 @@ describe('executeRequest', () => { it('executes POST requests with config', async () => { responseMock.mockResolvedValueOnce({ value: '10000' }); const request: Request = { - baseUrl: 'http://localhost:5000', + baseUrl: 'http://localhost:5005', data: { from: 'ETH', to: 'USD' }, headers: { api_key: 'supersecret' }, method: 'post', @@ -81,7 +81,7 @@ describe('executeRequest', () => { expect(res).toEqual({ value: '10000' }); expect(axios).toHaveBeenCalledTimes(1); expect(axios).toHaveBeenCalledWith({ - url: 'http://localhost:5000/convert', + url: 'http://localhost:5005/convert', method: 'post', headers: { api_key: 'supersecret' }, data: { from: 'ETH', to: 'USD' }, @@ -98,7 +98,7 @@ describe('buildAndExecuteRequest', () => { expect(res).toEqual({ value: '10000' }); expect(axios).toHaveBeenCalledTimes(1); expect(axios).toHaveBeenCalledWith({ - url: 'http://localhost:5000/convert', + url: 'http://localhost:5005/convert', method: 'get', headers: {}, params: { @@ -117,7 +117,7 @@ describe('buildAndExecuteRequest', () => { expect(res).toEqual({ value: '7777' }); expect(axios).toHaveBeenCalledTimes(1); expect(axios).toHaveBeenCalledWith({ - url: 'http://localhost:5000/convert', + url: 'http://localhost:5005/convert', method: 'get', headers: {}, params: { diff --git a/packages/airnode-adapter/test/fixtures/ois.ts b/packages/airnode-adapter/test/fixtures/ois.ts index c061fb078b..4683326e06 100644 --- a/packages/airnode-adapter/test/fixtures/ois.ts +++ b/packages/airnode-adapter/test/fixtures/ois.ts @@ -8,7 +8,7 @@ export function buildOIS(overrides?: Partial): OIS { apiSpecifications: { servers: [ { - url: 'http://localhost:5000', + url: 'http://localhost:5005', }, ], paths: { diff --git a/packages/airnode-admin/docker/Dockerfile b/packages/airnode-admin/docker/Dockerfile index b97f7a0b5d..be235d068f 100644 --- a/packages/airnode-admin/docker/Dockerfile +++ b/packages/airnode-admin/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18.14.0-alpine3.17 +FROM node:20.10.0-alpine3.17 ARG npmRegistryUrl=https://registry.npmjs.org/ ARG npmTag=latest diff --git a/packages/airnode-admin/package.json b/packages/airnode-admin/package.json index 3743b0e5af..e6c8d08026 100644 --- a/packages/airnode-admin/package.json +++ b/packages/airnode-admin/package.json @@ -35,7 +35,7 @@ }, "devDependencies": { "@types/lodash": "^4.14.202", - "@types/node": "^18.19.21", + "@types/node": "^20.10.0", "@types/yargs": "^17.0.32", "jest": "^29.7.0", "rimraf": "^5.0.5", diff --git a/packages/airnode-admin/test/e2e/cli.feature.ts b/packages/airnode-admin/test/e2e/cli.feature.ts index 3b2de7975e..ae1b01f027 100644 --- a/packages/airnode-admin/test/e2e/cli.feature.ts +++ b/packages/airnode-admin/test/e2e/cli.feature.ts @@ -24,9 +24,9 @@ it('has disabled DEBUG_COMMANDS flag', () => { expect(DEBUG_COMMANDS).toBe(false); }); -describe('CLI', () => { - jest.setTimeout(45_000); +jest.setTimeout(120_000); +describe('CLI', () => { let provider: ethers.providers.JsonRpcProvider; let deployer: ethers.providers.JsonRpcSigner; const aliceDerivationPath = "m/44'/60'/0'/0/1"; @@ -229,7 +229,7 @@ describe('CLI', () => { ['--max-fee', 20], ['--max-priority-fee', 10] ) - ).toThrow('Transaction requires at least 21560 gas but got 1'); + ).toThrow(); }); it('stops sponsoring requester', async () => { diff --git a/packages/airnode-admin/test/e2e/sdk.feature.ts b/packages/airnode-admin/test/e2e/sdk.feature.ts index 6f8bb96c7f..2f3f000a20 100644 --- a/packages/airnode-admin/test/e2e/sdk.feature.ts +++ b/packages/airnode-admin/test/e2e/sdk.feature.ts @@ -75,7 +75,7 @@ describe('SDK', () => { it('uses transaction overrides', async () => { await expect(sdk.sponsorRequester(wallet.address, { gasLimit: 1 })).rejects.toThrow( - 'Transaction requires at least 21572 gas but got 1' + expect.objectContaining({ name: expect.stringContaining('Error'), message: expect.stringContaining('gas') }) ); }); }); diff --git a/packages/airnode-deployer/docker/Dockerfile b/packages/airnode-deployer/docker/Dockerfile index 0a596820e7..1b10dd3d29 100644 --- a/packages/airnode-deployer/docker/Dockerfile +++ b/packages/airnode-deployer/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18.14.0-alpine3.17 +FROM node:20.10.0-alpine3.17 ARG npmRegistryUrl=https://registry.npmjs.org/ ARG npmTag=latest diff --git a/packages/airnode-deployer/package.json b/packages/airnode-deployer/package.json index 55a5b9fdf3..0f22c43b05 100644 --- a/packages/airnode-deployer/package.json +++ b/packages/airnode-deployer/package.json @@ -51,7 +51,7 @@ "@types/adm-zip": "^0.5.5", "@types/aws-lambda": "^8.10.136", "@types/lodash": "^4.14.202", - "@types/node": "^18.19.21", + "@types/node": "^20.10.0", "@types/yargs": "^17.0.32", "aws-sdk-client-mock": "^3.0.1", "aws-sdk-client-mock-jest": "^3.0.1", diff --git a/packages/airnode-deployer/terraform/aws/modules/function/main.tf b/packages/airnode-deployer/terraform/aws/modules/function/main.tf index a91b59fad1..0a8b3e9ea8 100644 --- a/packages/airnode-deployer/terraform/aws/modules/function/main.tf +++ b/packages/airnode-deployer/terraform/aws/modules/function/main.tf @@ -43,7 +43,7 @@ resource "aws_lambda_function" "lambda" { function_name = var.name handler = var.handler memory_size = var.memory_size - runtime = "nodejs18.x" + runtime = "nodejs20.x" role = aws_iam_role.lambda_role.arn timeout = var.timeout reserved_concurrent_executions = var.reserved_concurrent_executions diff --git a/packages/airnode-deployer/terraform/gcp/modules/function/main.tf b/packages/airnode-deployer/terraform/gcp/modules/function/main.tf index 78e471ae95..cb014d8170 100644 --- a/packages/airnode-deployer/terraform/gcp/modules/function/main.tf +++ b/packages/airnode-deployer/terraform/gcp/modules/function/main.tf @@ -56,7 +56,7 @@ resource "google_storage_bucket_object" "function_zip" { resource "google_cloudfunctions_function" "function" { name = var.name - runtime = "nodejs18" + runtime = "nodejs20" available_memory_mb = var.memory_size source_archive_bucket = google_storage_bucket_object.function_zip.bucket diff --git a/packages/airnode-examples/package.json b/packages/airnode-examples/package.json index d06f5514bf..42b7c4c6a4 100644 --- a/packages/airnode-examples/package.json +++ b/packages/airnode-examples/package.json @@ -46,12 +46,12 @@ "@nomiclabs/hardhat-ethers": "^2.2.3", "@nomiclabs/hardhat-waffle": "^2.0.6", "@types/jest": "^29.5.12", - "@types/node": "^18.19.21", + "@types/node": "^20.10.0", "@types/prompts": "^2.4.9", "chalk": "^4.1.2", "dotenv": "^16.4.5", "ethereum-waffle": "^4.0.10", - "hardhat": "^2.14.1", + "hardhat": "^2.23.0-dev.3", "jest": "^29.7.0", "prompts": "^2.4.2", "ts-jest": "^29.1.2", diff --git a/packages/airnode-node/config/config.example.json b/packages/airnode-node/config/config.example.json index 8fcc4bd02c..c8a1365e4d 100644 --- a/packages/airnode-node/config/config.example.json +++ b/packages/airnode-node/config/config.example.json @@ -119,7 +119,7 @@ "apiSpecifications": { "servers": [ { - "url": "http://localhost:5000" + "url": "http://localhost:5005" } ], "paths": { diff --git a/packages/airnode-node/docker/Dockerfile b/packages/airnode-node/docker/Dockerfile index bd722f215a..e6819d8a8b 100644 --- a/packages/airnode-node/docker/Dockerfile +++ b/packages/airnode-node/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18.14.0-alpine3.17 +FROM node:20.10.0-alpine3.17 ARG npmRegistryUrl=https://registry.npmjs.org/ ARG npmTag=latest diff --git a/packages/airnode-node/package.json b/packages/airnode-node/package.json index 36fe1d15da..29e6e54e9d 100644 --- a/packages/airnode-node/package.json +++ b/packages/airnode-node/package.json @@ -48,7 +48,7 @@ "@types/express": "^4.17.21", "@types/jest": "^29.5.12", "@types/lodash": "^4.14.202", - "@types/node": "^18.19.21", + "@types/node": "^20.10.0", "@types/yargs": "^17.0.32", "aws-sdk-client-mock": "^3.0.1", "aws-sdk-client-mock-jest": "^3.0.1", diff --git a/packages/airnode-node/test/fixtures/config/ois.ts b/packages/airnode-node/test/fixtures/config/ois.ts index c44e25891c..86807d7172 100644 --- a/packages/airnode-node/test/fixtures/config/ois.ts +++ b/packages/airnode-node/test/fixtures/config/ois.ts @@ -8,7 +8,7 @@ export function buildOIS(ois?: Partial): OIS { apiSpecifications: { servers: [ { - url: 'http://localhost:5000', + url: 'http://localhost:5005', }, ], paths: { diff --git a/packages/airnode-operation/ecosystem.config.js b/packages/airnode-operation/ecosystem.config.js index c0a1b5e1fa..964761c0aa 100644 --- a/packages/airnode-operation/ecosystem.config.js +++ b/packages/airnode-operation/ecosystem.config.js @@ -23,7 +23,7 @@ module.exports = { }, { name: 'ethereum-node', - script: 'hardhat node', + script: 'anvil', env: { NODE_ENV: 'development', }, @@ -37,5 +37,37 @@ module.exports = { out_file: 'logs/ethereum-node.log', merge_logs: true, }, + // { + // name: 'ethereum-node-anvil', + // script: 'anvil --port 8546', + // env: { + // NODE_ENV: 'development', + // }, + // env_production: { + // NODE_ENV: 'production', + // }, + // + // // Logs + // log_date_format: 'YYYY-MM-DD HH:mm:ss', + // error_file: 'logs/ethereum-node-anvil.log', + // out_file: 'logs/ethereum-node-anvil.log', + // merge_logs: true, + // }, + // { + // name: 'ethereum-node', + // script: 'hardhat node', + // env: { + // NODE_ENV: 'development', + // }, + // env_production: { + // NODE_ENV: 'production', + // }, + // + // // Logs + // log_date_format: 'YYYY-MM-DD HH:mm:ss', + // error_file: 'logs/ethereum-node.log', + // out_file: 'logs/ethereum-node.log', + // merge_logs: true, + // }, ], }; diff --git a/packages/airnode-operation/hardhat.config.ts b/packages/airnode-operation/hardhat.config.ts index 0ac22553fa..a287637f8a 100644 --- a/packages/airnode-operation/hardhat.config.ts +++ b/packages/airnode-operation/hardhat.config.ts @@ -7,15 +7,6 @@ const config: HardhatUserConfig = { compilers: [{ version: '0.6.12', settings: {} }], }, networks: { - hardhat: { - accounts: { - // These accounts are used to deploy contracts and fund all Airnode - // related accounts. Make sure they have more than enough ETH to - // do this (1m ETH each). - accountsBalance: '1000000000000000000000000', - count: 100, - }, - }, localhost: { url: 'http://127.0.0.1:8545/', }, diff --git a/packages/airnode-operation/package.json b/packages/airnode-operation/package.json index 2b6d727c2b..68319352ad 100644 --- a/packages/airnode-operation/package.json +++ b/packages/airnode-operation/package.json @@ -33,7 +33,7 @@ "@api3/airnode-utilities": "^0.14.0", "ethers": "^5.7.2", "express": "^4.18.3", - "hardhat": "^2.14.1", + "hardhat": "^2.23.0-dev.3", "morgan": "^1.10.0", "pm2": "^5.3.1" }, diff --git a/packages/airnode-operation/src/server.ts b/packages/airnode-operation/src/server.ts index 1c6d8374f8..3fc6f77727 100644 --- a/packages/airnode-operation/src/server.ts +++ b/packages/airnode-operation/src/server.ts @@ -2,7 +2,7 @@ import express from 'express'; import morgan from 'morgan'; import { logger } from '@api3/airnode-utilities'; -const PORT = 5000; +const PORT = 5005; const app = express(); diff --git a/packages/airnode-protocol/package.json b/packages/airnode-protocol/package.json index 4c7af74f82..b68f3a1235 100644 --- a/packages/airnode-protocol/package.json +++ b/packages/airnode-protocol/package.json @@ -37,7 +37,7 @@ "chai": "^4.4.1", "copyfiles": "^2.4.1", "ethereum-waffle": "^4.0.10", - "hardhat": "^2.14.1", + "hardhat": "^2.23.0-dev.3", "hardhat-deploy": "^0.12.1", "hardhat-gas-reporter": "^1.0.10", "rimraf": "^5.0.5", diff --git a/packages/airnode-utilities/package.json b/packages/airnode-utilities/package.json index 27796aefae..bc6273c451 100644 --- a/packages/airnode-utilities/package.json +++ b/packages/airnode-utilities/package.json @@ -26,8 +26,8 @@ "devDependencies": { "@nomiclabs/hardhat-ethers": "^2.2.3", "@types/jest": "^29.5.12", - "@types/node": "^18.19.21", - "hardhat": "^2.14.1", + "@types/node": "^20.10.0", + "hardhat": "^2.23.0-dev.3", "jest": "^29.7.0", "rimraf": "^5.0.5", "ts-node": "^10.9.2", diff --git a/packages/airnode-utilities/test/e2e/gas-oracle.feature.ts b/packages/airnode-utilities/test/e2e/gas-oracle.feature.ts index 36d2afd0ce..01d39c6e80 100644 --- a/packages/airnode-utilities/test/e2e/gas-oracle.feature.ts +++ b/packages/airnode-utilities/test/e2e/gas-oracle.feature.ts @@ -1,11 +1,13 @@ +import { spawn } from 'node:child_process'; import * as hre from 'hardhat'; -import { BigNumber, ethers } from 'ethers'; +// import { BigNumber } from 'ethers'; +// import { BigNumber, ethers } from 'ethers'; import '@nomiclabs/hardhat-ethers'; import { go, assertGoSuccess } from '@api3/promise-utils'; import { config } from '@api3/airnode-validator'; import * as gasOracle from '../../src/evm/gas-prices/gas-oracle'; -import { GasTarget } from '../../src/evm/gas-prices/types'; -import { executeTransactions } from '../setup/transactions'; +// import { GasTarget } from '../../src/evm/gas-prices/types'; +// import { executeTransactions } from '../setup/transactions'; // Jest version 27 has a bug where jest.setTimeout does not work correctly inside describe or test blocks // https://github.com/facebook/jest/issues/11607 @@ -58,49 +60,54 @@ const defaultChainOptions: config.ChainOptions = { fulfillmentGasLimit, }; -const multiplyGasPrice = (gasPrice: BigNumber, recommendedGasPriceMultiplier?: number) => - recommendedGasPriceMultiplier ? gasOracle.multiplyGasPrice(gasPrice, recommendedGasPriceMultiplier) : gasPrice; - -const processBlockData = async ( - provider: ethers.providers.StaticJsonRpcProvider, - blocksWithGasPrices: { blockNumber: number; gasPrices: BigNumber[] }[], - percentile: number, - maxDeviationMultiplier: number, - fallbackGasPrice: config.Amount, - recommendedGasPriceMultiplier: number -): Promise => { - const latestBlock = blocksWithGasPrices[0]; - const referenceBlock = blocksWithGasPrices[20]; - - const latestBlockPercentileGasPrice = gasOracle.getPercentile( - latestBlockPercentileGasPriceStrategy.percentile, - latestBlock.gasPrices.map((p) => p) - ); - const referenceBlockPercentileGasPrice = gasOracle.getPercentile( - percentile, - referenceBlock.gasPrices.map((p) => p) - ); - - const isWithinDeviationLimit = gasOracle.checkMaxDeviationLimit( - latestBlockPercentileGasPrice!, - referenceBlockPercentileGasPrice!, - maxDeviationMultiplier - ); - - if (isWithinDeviationLimit) return { type: 0, gasPrice: latestBlockPercentileGasPrice! }; - - try { - const providerGasPrice = await provider.getGasPrice(); - return { - type: 0, - gasPrice: multiplyGasPrice(providerGasPrice, recommendedGasPriceMultiplier), - }; - } catch (_e) { - return { - type: 0, - gasPrice: gasOracle.parsePriorityFee(fallbackGasPrice), - }; - } +// const multiplyGasPrice = (gasPrice: BigNumber, recommendedGasPriceMultiplier?: number) => +// recommendedGasPriceMultiplier ? gasOracle.multiplyGasPrice(gasPrice, recommendedGasPriceMultiplier) : gasPrice; + +// const processBlockData = async ( +// provider: ethers.providers.StaticJsonRpcProvider, +// blocksWithGasPrices: { blockNumber: number; gasPrices: BigNumber[] }[], +// percentile: number, +// maxDeviationMultiplier: number, +// fallbackGasPrice: config.Amount, +// recommendedGasPriceMultiplier: number +// ): Promise => { +// const latestBlock = blocksWithGasPrices[0]; +// const referenceBlock = blocksWithGasPrices[20]; +// +// const latestBlockPercentileGasPrice = gasOracle.getPercentile( +// latestBlockPercentileGasPriceStrategy.percentile, +// latestBlock.gasPrices.map((p) => p) +// ); +// const referenceBlockPercentileGasPrice = gasOracle.getPercentile( +// percentile, +// referenceBlock.gasPrices.map((p) => p) +// ); +// +// const isWithinDeviationLimit = gasOracle.checkMaxDeviationLimit( +// latestBlockPercentileGasPrice!, +// referenceBlockPercentileGasPrice!, +// maxDeviationMultiplier +// ); +// +// if (isWithinDeviationLimit) return { type: 0, gasPrice: latestBlockPercentileGasPrice! }; +// +// try { +// const providerGasPrice = await provider.getGasPrice(); +// return { +// type: 0, +// gasPrice: multiplyGasPrice(providerGasPrice, recommendedGasPriceMultiplier), +// }; +// } catch (_e) { +// return { +// type: 0, +// gasPrice: gasOracle.parsePriorityFee(fallbackGasPrice), +// }; +// } +// }; + +const resetAnvil = async () => { + spawn('bash', ['-c', 'killall anvil;']); + await new Promise((f) => setTimeout(f, 1000)); }; describe('Gas oracle', () => { @@ -111,19 +118,21 @@ describe('Gas oracle', () => { txTypes.forEach((txType) => { describe(`${txType} network`, () => { - let blocksWithGasPrices: { blockNumber: number; gasPrices: BigNumber[] }[]; + // let blocksWithGasPrices: { blockNumber: number; gasPrices: BigNumber[] }[]; beforeEach(async () => { // Reset the local hardhat network state for each test to prevent issues with other test contracts - await hre.network.provider.send('hardhat_reset'); + // await hre.network.provider.send('hardhat_reset'); + await resetAnvil(); + // Disable automining to get multiple transaction per block await hre.network.provider.send('evm_setAutomine', [false]); jest.resetAllMocks(); jest.restoreAllMocks(); - const transactions = await executeTransactions(txType); + // const transactions = await executeTransactions(txType); - blocksWithGasPrices = transactions.blocksWithGasPrices.sort((a, b) => b.blockNumber - a.blockNumber); + // blocksWithGasPrices = transactions.blocksWithGasPrices.sort((a, b) => b.blockNumber - a.blockNumber); // Set automining to true await hre.network.provider.send('evm_setAutomine', [true]); @@ -131,20 +140,20 @@ describe('Gas oracle', () => { startTime = Date.now(); }); - it('returns latestBlockPercentileGasPrice', async () => { - const [_logs, gasTarget] = await gasOracle.getGasPrice(provider, defaultChainOptions); - - const processedPercentileGasPrice = await processBlockData( - provider, - blocksWithGasPrices, - latestBlockPercentileGasPriceStrategy.percentile, - latestBlockPercentileGasPriceStrategy.maxDeviationMultiplier, - constantGasPriceStrategy.gasPrice as config.Amount, - providerRecommendedGasPriceStrategy.recommendedGasPriceMultiplier - ); - - expect(gasTarget).toEqual(gasOracle.getGasTargetWithGasLimit(processedPercentileGasPrice, fulfillmentGasLimit)); - }); + // it('returns latestBlockPercentileGasPrice', async () => { + // const [_logs, gasTarget] = await gasOracle.getGasPrice(provider, defaultChainOptions); + // + // const processedPercentileGasPrice = await processBlockData( + // provider, + // blocksWithGasPrices, + // latestBlockPercentileGasPriceStrategy.percentile, + // latestBlockPercentileGasPriceStrategy.maxDeviationMultiplier, + // constantGasPriceStrategy.gasPrice as config.Amount, + // providerRecommendedGasPriceStrategy.recommendedGasPriceMultiplier + // ); + // + // expect(gasTarget).toEqual(gasOracle.getGasTargetWithGasLimit(processedPercentileGasPrice, fulfillmentGasLimit)); + // }); it('returns providerRecommendedEip1559GasPrice', async () => { const [_logs, gasTarget] = await gasOracle.getGasPrice(provider, { diff --git a/yarn.lock b/yarn.lock index 0b4ba40269..afe1f21ff6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2550,65 +2550,53 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@nomicfoundation/edr-darwin-arm64@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.2.1.tgz#10c1a07add192583ce8b2d4cc93439f52b390a41" - integrity sha512-aMYaRaZVQ/TmyNJIoXf1bU4k0zfinaL9Sy1day4yGlL6eiQPFfRGj9W6TZaZIoYG0XTx/mQWD7dkXJ7LdrleJA== - -"@nomicfoundation/edr-darwin-x64@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.2.1.tgz#eaa29d2ba9f91ddb5f59b872c5a54f94a6fe3095" - integrity sha512-ma0SLcjHm5L3nPHcKFJB0jv/gKGSKaxr5Z65rurX/eaYUQJ7YGMsb8er9bSCo9rjzOtxf4FoPj3grL3zGpOj8A== - -"@nomicfoundation/edr-linux-arm64-gnu@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.2.1.tgz#8149db0d742157405effe82d485ea9bfefddc795" - integrity sha512-NX3G4pBhRitWrjSGY3HTyCq3wKSm5YqrKVOCNQGl9/jcjSovqxlgzFMiTx4YZCzGntfJ/1om9AI84OWxYJjoDw== - -"@nomicfoundation/edr-linux-arm64-musl@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.2.1.tgz#7d53afe5607eb406d199a199d00209a6304ff07b" - integrity sha512-gdQ3QHkt9XRkdtOGQ8fMwS11MXdjLeZgLrqoial4V4qtMaamIMMhVczK+VEvUhD8p7G4BVmp6kmkvcsthmndmw== - -"@nomicfoundation/edr-linux-x64-gnu@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.2.1.tgz#b762c95368fcb88bbbabba4d8be5380f38967413" - integrity sha512-OqabFY37vji6mYbLD9CvG28lja68czeVw58oWByIhFV3BpBu/cyP1oAbhzk3LieylujabS3Ekpvjw2Tkf0A9RQ== - -"@nomicfoundation/edr-linux-x64-musl@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.2.1.tgz#522448c42bff7d2abd52ddcf11ae6ca3dfdd6db4" - integrity sha512-vHfFFK2EPISuQUQge+bdjXamb0EUjfl8srYSog1qfiwyLwLeuSbpyyFzDeITAgPpkkFuedTfJW553K0Hipspyg== - -"@nomicfoundation/edr-win32-arm64-msvc@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-arm64-msvc/-/edr-win32-arm64-msvc-0.2.1.tgz#ccfa443c274e49de93016a1060be810096dc6f1d" - integrity sha512-K/mui67RCKxghbSyvhvW3rvyVN1pa9M1Q9APUx1PtWjSSdXDFpqEY1NYsv2syb47Ca8ObJwVMF+LvnB6GvhUOQ== - -"@nomicfoundation/edr-win32-ia32-msvc@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-ia32-msvc/-/edr-win32-ia32-msvc-0.2.1.tgz#822b19d3e67d6dcfa5394cb6a4d55d8bab1b2f26" - integrity sha512-HHK0mXEtjvfjJrJlqcYgQCy3lZIXS1KNl2GaP8bwEIuEwx++XxXs/ThLjPepM1nhCGICij8IGy7p3KrkzRelsw== - -"@nomicfoundation/edr-win32-x64-msvc@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.2.1.tgz#7b56ff742b2724779cc9f3385815b394f76de8df" - integrity sha512-FY4eQJdj1/y8ST0RyQycx63yr+lvdYNnUkzgWf4X+vPH1lOhXae+L2NDcNCQlTDAfQcD6yz0bkBUkLrlJ8pTww== - -"@nomicfoundation/edr@^0.2.0": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.2.1.tgz#a3d2a542dcd5dc5a8d757116d52baea05f370531" - integrity sha512-Dleau3ItHJh2n85G2J6AIPBoLgu/mOWkmrh26z3VsJE2tp/e00hUk/dqz85ncsVcBYEc6/YOn/DomWu0wSF9tQ== - optionalDependencies: - "@nomicfoundation/edr-darwin-arm64" "0.2.1" - "@nomicfoundation/edr-darwin-x64" "0.2.1" - "@nomicfoundation/edr-linux-arm64-gnu" "0.2.1" - "@nomicfoundation/edr-linux-arm64-musl" "0.2.1" - "@nomicfoundation/edr-linux-x64-gnu" "0.2.1" - "@nomicfoundation/edr-linux-x64-musl" "0.2.1" - "@nomicfoundation/edr-win32-arm64-msvc" "0.2.1" - "@nomicfoundation/edr-win32-ia32-msvc" "0.2.1" - "@nomicfoundation/edr-win32-x64-msvc" "0.2.1" +"@nomicfoundation/edr-darwin-arm64@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.4.0-alpha.4.tgz#6ad8bf592581ae40a88860c756ee79a37c5d83ed" + integrity sha512-mCeUEWKOe09FywQSP92rho3jgB207YOrKMCwCc2rDc45wdZII2wqAnfHqDbadeg+Fg/n3BH6J+VzyP/m0NpPhQ== + +"@nomicfoundation/edr-darwin-x64@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.4.0-alpha.4.tgz#94475c9728f882277f99482577b317db874df17f" + integrity sha512-wGAe9jTS/PF2DmAdkvbbIl+lvWCbldWafxGMZ6TzGAMQvEib41QSKWs+Sp3YwDy1JIUhX8B5SxOw8o0jOTGDAA== + +"@nomicfoundation/edr-linux-arm64-gnu@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.4.0-alpha.4.tgz#60c19df5311ccc7fd5af2a1745ecbbd1c7804c8a" + integrity sha512-fnCG/vW3j1sg7uwbRH69a0xDzaW+YDrHDdJuv3SPrIVbRGTsL3FWxsled9FRxlE0ojQCRRMlgidTM0k1/8FNQg== + +"@nomicfoundation/edr-linux-arm64-musl@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.4.0-alpha.4.tgz#e691bb8b029d6057153c8b9f770056dfa5c56fa2" + integrity sha512-zpgxJrkecK3bdK3vKF+zm0MOalWP7aqPPRaaMzUEPdtrFWAMKhrzkawmxHAN83ohkLnLBpzeJOLjG1a80XRLMA== + +"@nomicfoundation/edr-linux-x64-gnu@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.4.0-alpha.4.tgz#2aec4e84646ce1df0d5f2e5175d1e4c4c12d7e52" + integrity sha512-kvlqo937otCKm5th1Wq4K1E6AW8doHqeawjuJy32m1lKEbNdMugF2o+IW9xMaEFhevITSJYgSMXgc3ppyD+8pQ== + +"@nomicfoundation/edr-linux-x64-musl@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.4.0-alpha.4.tgz#4a6d5a79554d1e939b8e1050417ea03726e36371" + integrity sha512-ps/cO414xx+XWr7HtHX4PuAfy+p/BLpJP4SA9qSU7RtC6TXdl2EEaZYwC/qV1vdXCfVN+0QMuvnIWBqMHdrcIg== + +"@nomicfoundation/edr-win32-x64-msvc@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.4.0-alpha.4.tgz#f2e105aff22a618a8cd3b13fe52793954eb8f27a" + integrity sha512-QSrKqq9w/7lwFvbh1SRwwX9n88fE8BlRRp8zGdUuAIyuqS/jZNCuzTPwZ07HAHrRW3Fe2+RYebGT/jz0AGCHIA== + +"@nomicfoundation/edr@0.4.0-alpha.4": + version "0.4.0-alpha.4" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.4.0-alpha.4.tgz#5214558ba68d1c5cd4d5c13a341872355786a99f" + integrity sha512-6EK/5WRhE8GDFfkiCi6EMQVNXckx5wM3G7jtz+xrR/mAl3Qi2+0gRNCdpoMq9TNjufunG7FmdDQdswdHb+R9tw== + dependencies: + "@nomicfoundation/edr-darwin-arm64" "0.4.0-alpha.4" + "@nomicfoundation/edr-darwin-x64" "0.4.0-alpha.4" + "@nomicfoundation/edr-linux-arm64-gnu" "0.4.0-alpha.4" + "@nomicfoundation/edr-linux-arm64-musl" "0.4.0-alpha.4" + "@nomicfoundation/edr-linux-x64-gnu" "0.4.0-alpha.4" + "@nomicfoundation/edr-linux-x64-musl" "0.4.0-alpha.4" + "@nomicfoundation/edr-win32-x64-msvc" "0.4.0-alpha.4" "@nomicfoundation/ethereumjs-common@4.0.4": version "4.0.4" @@ -4456,7 +4444,7 @@ "@types/node" "*" form-data "^4.0.0" -"@types/node@*": +"@types/node@*", "@types/node@^20.10.0": version "20.11.25" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.25.tgz#0f50d62f274e54dd7a49f7704cc16bfbcccaf49f" integrity sha512-TBHyJxk2b7HceLVGFcpAUjsa5zIdsPWlR6XHfyGzd0SFu+/NFgQgMAl96MSDZgQDvJAvV6BKsFOrt6zIL09JDw== @@ -4478,13 +4466,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== -"@types/node@^18.19.21": - version "18.19.22" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.22.tgz#f622f92514b897e6b09903e97c16a0db8e94689f" - integrity sha512-p3pDIfuMg/aXBmhkyanPshdfJuX5c5+bQjYLIikPLXAUycEogij/c50n/C+8XOA5L93cU4ZRXtn+dNQGi0IZqQ== - dependencies: - undici-types "~5.26.4" - "@types/node@^8.0.0": version "8.10.66" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.66.tgz#dd035d409df322acc83dff62a602f12a5783bbb3" @@ -9097,14 +9078,14 @@ hardhat-gas-reporter@^1.0.10: eth-gas-reporter "^0.2.25" sha1 "^1.1.1" -hardhat@^2.14.1: - version "2.21.0" - resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.21.0.tgz#2e23126310a6c77cd7e149e6af1dd67626b7a74f" - integrity sha512-8DlJAVJDEVHaV1sh9FLuKLLgCFv9EAJ+M+8IbjSIPgoeNo3ss5L1HgGBMfnI88c7OzMEZkdcuyGoobFeK3Orqw== +hardhat@^2.23.0-dev.3: + version "2.23.0-dev.3" + resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.23.0-dev.3.tgz#234d57c484d1f26d86603e86219a54c210dbe290" + integrity sha512-IBplNKWUhjlM63yPBSp6Mbsrk6Hhj3dFoxAUw3Aw02v8dYr2y0UXicTiKlL6iHFAij35XJumdXL8esgAobMhbA== dependencies: "@ethersproject/abi" "^5.1.2" "@metamask/eth-sig-util" "^4.0.0" - "@nomicfoundation/edr" "^0.2.0" + "@nomicfoundation/edr" "0.4.0-alpha.4" "@nomicfoundation/ethereumjs-common" "4.0.4" "@nomicfoundation/ethereumjs-tx" "5.0.4" "@nomicfoundation/ethereumjs-util" "9.0.4"