From a5bd64fd649e46e2f4780319b0a67856f6c273ca Mon Sep 17 00:00:00 2001 From: Alexandre ABRIOUX Date: Fri, 4 Feb 2022 14:33:12 +0100 Subject: [PATCH] chore(request-node): eip-1559 for storage --- packages/request-node/package.json | 1 + .../src/thegraph/TheGraphStorage.ts | 18 +++- yarn.lock | 91 +++++++++++++++++++ 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/packages/request-node/package.json b/packages/request-node/package.json index 930c168d02..27fddcf545 100644 --- a/packages/request-node/package.json +++ b/packages/request-node/package.json @@ -51,6 +51,7 @@ "chalk": "4.1.0", "cors": "2.8.5", "dotenv": "8.2.0", + "eip1559-fee-suggestions-ethers": "1.3.3", "ethers": "5.5.2", "express": "4.17.1", "graphql": "15.5.0", diff --git a/packages/request-node/src/thegraph/TheGraphStorage.ts b/packages/request-node/src/thegraph/TheGraphStorage.ts index f3c83401e9..47d83ec21b 100644 --- a/packages/request-node/src/thegraph/TheGraphStorage.ts +++ b/packages/request-node/src/thegraph/TheGraphStorage.ts @@ -1,10 +1,11 @@ import { EventEmitter } from 'events'; -import { utils, Signer, ContractReceipt } from 'ethers'; +import { utils, Signer, ContractReceipt, BigNumber, providers } from 'ethers'; import TypedEmitter from 'typed-emitter'; import Utils from '@requestnetwork/utils'; import { LogTypes, StorageTypes } from '@requestnetwork/types'; import { requestHashSubmitterArtifact } from '@requestnetwork/smart-contracts'; import { RequestOpenHashSubmitter } from '@requestnetwork/smart-contracts/types'; +import { suggestFees } from 'eip1559-fee-suggestions-ethers'; type TheGraphStorageProps = { network: string; @@ -31,7 +32,7 @@ export class TheGraphStorage { this.hashSubmitter = requestHashSubmitterArtifact.connect( network, signer, - ) as RequestOpenHashSubmitter; // type mismatch with ethers. + ) as RequestOpenHashSubmitter; } async initialize(): Promise { @@ -43,10 +44,17 @@ export class TheGraphStorage { const { ipfsHash, ipfsSize } = await this.ipfsStorage.ipfsAdd(content); const fee = await this.hashSubmitter.getFeesAmount(ipfsSize); + const suggestedFee = await suggestFees( + this.hashSubmitter.provider as providers.JsonRpcProvider, + ); const tx = await this.hashSubmitter.submitHash( ipfsHash, utils.hexZeroPad(utils.hexlify(ipfsSize), 32), - { value: fee }, + { + value: fee, + maxFeePerGas: BigNumber.from(suggestedFee.baseFeeSuggestion), + maxPriorityFeePerGas: BigNumber.from(suggestedFee.maxPriorityFeeSuggestions.fast), + }, ); const eventEmitter = new EventEmitter() as TheGraphStorageEventEmitter; @@ -66,13 +74,13 @@ export class TheGraphStorage { void tx .wait() - .then((receipt) => { + .then((receipt: providers.TransactionReceipt) => { this.logger.debug( `TX ${receipt.transactionHash} confirmed at block ${receipt.blockNumber}`, ); eventEmitter.emit('confirmed', receipt); }) - .catch((e) => eventEmitter.emit('error', e)); + .catch((e: Error) => eventEmitter.emit('error', e)); return Object.assign(eventEmitter, result); } diff --git a/yarn.lock b/yarn.lock index 379f501464..3f9b18fe3a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2686,6 +2686,13 @@ dependencies: "@ethersproject/logger" "^5.5.0" +"@ethersproject/networks@5.5.2": + version "5.5.2" + resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.5.2.tgz#784c8b1283cd2a931114ab428dae1bd00c07630b" + integrity sha512-NEqPxbGBfy6O3x4ZTISb90SjEDkWYDUbEeIFhJly0F7sZjoQMnj5KYzMSkMkLKZ+1fGpx00EDpHQCy6PrDupkQ== + dependencies: + "@ethersproject/logger" "^5.5.0" + "@ethersproject/networks@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.4.0.tgz#71eecd3ef3755118b42c1a5d2a44a7e07202e10a" @@ -2805,6 +2812,31 @@ bech32 "1.1.4" ws "7.4.6" +"@ethersproject/providers@5.5.3", "@ethersproject/providers@^5.5.0": + version "5.5.3" + resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.5.3.tgz#56c2b070542ac44eb5de2ed3cf6784acd60a3130" + integrity sha512-ZHXxXXXWHuwCQKrgdpIkbzMNJMvs+9YWemanwp1fA7XZEv7QlilseysPvQe0D7Q7DlkJX/w/bGA1MdgK2TbGvA== + dependencies: + "@ethersproject/abstract-provider" "^5.5.0" + "@ethersproject/abstract-signer" "^5.5.0" + "@ethersproject/address" "^5.5.0" + "@ethersproject/basex" "^5.5.0" + "@ethersproject/bignumber" "^5.5.0" + "@ethersproject/bytes" "^5.5.0" + "@ethersproject/constants" "^5.5.0" + "@ethersproject/hash" "^5.5.0" + "@ethersproject/logger" "^5.5.0" + "@ethersproject/networks" "^5.5.0" + "@ethersproject/properties" "^5.5.0" + "@ethersproject/random" "^5.5.0" + "@ethersproject/rlp" "^5.5.0" + "@ethersproject/sha2" "^5.5.0" + "@ethersproject/strings" "^5.5.0" + "@ethersproject/transactions" "^5.5.0" + "@ethersproject/web" "^5.5.0" + bech32 "1.1.4" + ws "7.4.6" + "@ethersproject/random@5.4.0", "@ethersproject/random@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/random/-/random-5.4.0.tgz#9cdde60e160d024be39cc16f8de3b9ce39191e16" @@ -2821,6 +2853,14 @@ "@ethersproject/bytes" "^5.5.0" "@ethersproject/logger" "^5.5.0" +"@ethersproject/random@5.5.1": + version "5.5.1" + resolved "https://registry.yarnpkg.com/@ethersproject/random/-/random-5.5.1.tgz#7cdf38ea93dc0b1ed1d8e480ccdaf3535c555415" + integrity sha512-YaU2dQ7DuhL5Au7KbcQLHxcRHfgyNgvFV4sQOo0HrtW3Zkrc9ctWNz8wXQ4uCSfSDsqX2vcjhroxU5RQRV0nqA== + dependencies: + "@ethersproject/bytes" "^5.5.0" + "@ethersproject/logger" "^5.5.0" + "@ethersproject/rlp@5.4.0", "@ethersproject/rlp@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/rlp/-/rlp-5.4.0.tgz#de61afda5ff979454e76d3b3310a6c32ad060931" @@ -10839,6 +10879,16 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= +eip1559-fee-suggestions-ethers@1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/eip1559-fee-suggestions-ethers/-/eip1559-fee-suggestions-ethers-1.3.3.tgz#cf21b6ae4734b697c8f79e556d91aeda3e464d60" + integrity sha512-W/5SQICRpDL0XvOdcX5oVWfaE2sow2u9il8I6Qyd9fkL9XY1knypywTcoBTdU9ULrPoP3phn/RnEKGq7Y8qkLw== + dependencies: + "@ethersproject/providers" "^5.5.0" + bignumber.js "^9.0.1" + ethers "^5.4.2" + moving-averages "^4.0.6" + electron-to-chromium@^1.3.47: version "1.3.778" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.778.tgz#bf01048736c95b78f2988e88005e0ebb385942a4" @@ -12126,6 +12176,42 @@ ethers@^5.0.0, ethers@^5.0.1, ethers@^5.0.2: "@ethersproject/web" "5.4.0" "@ethersproject/wordlists" "5.4.0" +ethers@^5.4.2: + version "5.5.4" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.5.4.tgz#e1155b73376a2f5da448e4a33351b57a885f4352" + integrity sha512-N9IAXsF8iKhgHIC6pquzRgPBJEzc9auw3JoRkaKe+y4Wl/LFBtDDunNe7YmdomontECAcC5APaAgWZBiu1kirw== + dependencies: + "@ethersproject/abi" "5.5.0" + "@ethersproject/abstract-provider" "5.5.1" + "@ethersproject/abstract-signer" "5.5.0" + "@ethersproject/address" "5.5.0" + "@ethersproject/base64" "5.5.0" + "@ethersproject/basex" "5.5.0" + "@ethersproject/bignumber" "5.5.0" + "@ethersproject/bytes" "5.5.0" + "@ethersproject/constants" "5.5.0" + "@ethersproject/contracts" "5.5.0" + "@ethersproject/hash" "5.5.0" + "@ethersproject/hdnode" "5.5.0" + "@ethersproject/json-wallets" "5.5.0" + "@ethersproject/keccak256" "5.5.0" + "@ethersproject/logger" "5.5.0" + "@ethersproject/networks" "5.5.2" + "@ethersproject/pbkdf2" "5.5.0" + "@ethersproject/properties" "5.5.0" + "@ethersproject/providers" "5.5.3" + "@ethersproject/random" "5.5.1" + "@ethersproject/rlp" "5.5.0" + "@ethersproject/sha2" "5.5.0" + "@ethersproject/signing-key" "5.5.0" + "@ethersproject/solidity" "5.5.0" + "@ethersproject/strings" "5.5.0" + "@ethersproject/transactions" "5.5.0" + "@ethersproject/units" "5.5.0" + "@ethersproject/wallet" "5.5.0" + "@ethersproject/web" "5.5.1" + "@ethersproject/wordlists" "5.5.0" + ethjs-abi@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/ethjs-abi/-/ethjs-abi-0.2.1.tgz#e0a7a93a7e81163a94477bad56ede524ab6de533" @@ -18066,6 +18152,11 @@ move-concurrently@^1.0.1: rimraf "^2.5.4" run-queue "^1.0.3" +moving-averages@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/moving-averages/-/moving-averages-4.0.6.tgz#4978d4d9f68aef8f2b5fa028b1ec316da0cc8c95" + integrity sha512-Jv+mH0emTFP40Q5ONsBqTfIO9NuUyK9zuW4pWbOzWJm8jEqpLBtAH2CnE2MFIuH/G9f9nDugmnDVUJaHx9jckw== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"