Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(request-node): eip-1559 for TheGraphDataAccess #760

Merged
merged 4 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/request-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions packages/request-node/src/thegraph/TheGraphStorage.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
91 changes: 91 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down