Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 2 additions & 9 deletions packages/ethereum-storage/src/ethereum-tx-submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { requestHashSubmitterArtifact } from '@requestnetwork/smart-contracts';
import { RequestOpenHashSubmitter } from '@requestnetwork/smart-contracts/types';
import { SubmitterProps } from './ethereum-storage-ethers';
import { GasFeeDefiner } from './gas-fee-definer';
import { SimpleLogger } from '@requestnetwork/utils';
import { SimpleLogger, isEip1559Supported } from '@requestnetwork/utils';

/**
* Handles the submission of a hash on the request HashSubmitter contract
Expand Down Expand Up @@ -32,14 +32,7 @@ export class EthereumTransactionSubmitter {
}

async initialize(): Promise<void> {
try {
await this.provider.send('eth_feeHistory', [1, 'latest', []]);
} catch (e) {
this.logger.warn(
'This RPC provider does not support the "eth_feeHistory" method: switching to legacy gas price',
);
this.enableEip1559 = false;
}
this.enableEip1559 = await isEip1559Supported(this.provider, this.logger);
}

/** Submits an IPFS hash, with fees according to `ipfsSize` */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import * as artifacts from '../../src/lib';
import { BigNumber, Overrides, Wallet } from 'ethers';
import { HardhatRuntimeEnvironmentExtended } from '../types';
import { parseUnits } from 'ethers/lib/utils';
import { estimateGasFees, getCeloProvider, getDefaultProvider } from '@requestnetwork/utils';
import {
estimateGasFees,
isEip1559Supported,
getCeloProvider,
getDefaultProvider,
} from '@requestnetwork/utils';

// Fees: 0.5%
export const REQUEST_SWAP_FEES = 5;
Expand Down Expand Up @@ -249,12 +254,9 @@ export const getSignerAndGasFees = async (
}
const signer = new hre.ethers.Wallet(hre.config.xdeploy.signer).connect(provider);

let txOverrides;
try {
txOverrides = await estimateGasFees({ provider });
} catch (err) {
txOverrides = {};
}
const txOverrides = (await isEip1559Supported(provider))
? await estimateGasFees({ provider })
: {};

return {
signer,
Expand Down
18 changes: 9 additions & 9 deletions packages/smart-contracts/scripts-create2/xdeployer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { HardhatRuntimeEnvironmentExtended, IDeploymentParams, IDeploymentResult } from './types';
import { requestDeployer } from '../src/lib';
import { Overrides } from 'ethers';
import { estimateGasFees, getCeloProvider, getDefaultProvider } from '@requestnetwork/utils';
import {
estimateGasFees,
getCeloProvider,
getDefaultProvider,
isEip1559Supported,
} from '@requestnetwork/utils';

const ZERO_ETH_INPUT = 0;

Expand Down Expand Up @@ -71,17 +76,12 @@ export const xdeploy = async (
let receipt = undefined;
let deployed = false;
let error = undefined;
let txOverrides: Overrides;
let txOverrides: Overrides = {};

try {
if (await isEip1559Supported(provider, console)) {
txOverrides = await estimateGasFees({ provider });
const gasLimit = hre.config.xdeploy.gasLimit;
txOverrides.gasLimit = gasLimit;
} catch (e) {
// NOTE: On some networks utils.estimateGasFees do not work
txOverrides = {};
console.log('Cannot estimate gasLimit');
}
txOverrides.gasLimit = hre.config.xdeploy.gasLimit;

try {
const createReceipt = await (
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export {
export {
setProviderFactory,
initPaymentDetectionApiKeys,
isEip1559Supported,
getDefaultProvider,
getCeloProvider,
networkRpcs,
Expand Down
19 changes: 19 additions & 0 deletions packages/utils/src/providers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LogTypes } from '@requestnetwork/types';

import { providers, constants } from 'ethers';

type ProviderFactory = (network: string | undefined) => providers.Provider | string;
Expand Down Expand Up @@ -147,9 +149,26 @@ const getCeloProvider = (): providers.Provider => {
return provider;
};

const isEip1559Supported = async (
provider: providers.Provider | providers.JsonRpcProvider,
logger?: LogTypes.ILogger,
): Promise<boolean> => {
try {
await (provider as providers.JsonRpcProvider).send('eth_feeHistory', [1, 'latest', []]);
return true;
} catch (e) {
logger &&
logger.warn(
'This RPC provider does not support the "eth_feeHistory" method: switching to legacy gas price',
);
return false;
}
};

export {
setProviderFactory,
initPaymentDetectionApiKeys,
isEip1559Supported,
getDefaultProvider,
getCeloProvider,
networkRpcs,
Expand Down