Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Stop treating mantle particularly
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrhn9 committed Oct 24, 2023
1 parent fe9e0f0 commit 4f09e58
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
25 changes: 0 additions & 25 deletions src/wallets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,31 +272,6 @@ describe('hasEnoughBalance', () => {
);
});

it('should throw an error when failed to get gas price (mantle)', async () => {
const sponsorWallet = {
provider: {
getBlock: jest.fn().mockResolvedValue({
timestamp: Math.floor(Date.now() / 1000),
}),
network: {
chainId: 5000,
name: 'mantle',
},
send: jest.fn().mockImplementation((method: string) => {
if (method === 'rollup_gasPrices') {
throw new Error('getGasPrice: Unexpected');
}
}),
getGasPrice: jest.fn().mockResolvedValue(ethers.utils.parseUnits('10', 'gwei')),
},
getBalance: jest.fn().mockResolvedValue(ethers.utils.parseEther('1')),
};

await expect(hasEnoughBalance(sponsorWallet as any, {} as any, {} as any, undefined, logOptions)).rejects.toThrow(
'getGasPrice: Unexpected'
);
});

it('should throw an error when failed to estimate gas', async () => {
const sponsorWallet = {
provider: {
Expand Down
23 changes: 1 addition & 22 deletions src/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { go, goSync } from '@api3/promise-utils';
import { ethers } from 'ethers';
import { uniq } from 'lodash';
import { LogOptionsOverride, logger } from './logging';
import { RateLimitedProvider } from './providers';
import { Provider, SponsorWalletsPrivateKey, getState, updateState } from './state';
import { createDummyBeaconUpdateData, shortenAddress } from './utils';
import { DataFeedUpdates } from './validation';
Expand Down Expand Up @@ -61,26 +60,6 @@ export const retrieveSponsorWallet = (sponsorAddress: string): ethers.Wallet =>
return new ethers.Wallet(sponsorWalletsPrivateKey[sponsorAddress]);
};

const getMantleGasPrice = async (provider: RateLimitedProvider) => {
const goRes = await go(() => provider.send('rollup_gasPrices', []));
if (!goRes.success) throw goRes.error;

const l1GasPrice = ethers.BigNumber.from(goRes.data.l1GasPrice);
const l2GasPrice = ethers.BigNumber.from(goRes.data.l2GasPrice);

return l1GasPrice.add(l2GasPrice);
};

const getGasPrice = async (provider: RateLimitedProvider) => {
switch (provider.network.chainId) {
case 5000:
case 5001:
return getMantleGasPrice(provider);
default:
return provider.getGasPrice();
}
};

export const hasEnoughBalance = async (
sponsorWallet: ethers.Wallet,
dummyAirnode: ethers.Wallet,
Expand All @@ -97,7 +76,7 @@ export const hasEnoughBalance = async (
const balance = goGetBalance.data;

// Get the gas price from provider
const goGasPrice = await go(() => getGasPrice(sponsorWallet.provider as RateLimitedProvider), { retries: 1 });
const goGasPrice = await go(() => sponsorWallet.provider.getGasPrice(), { retries: 1 });
if (!goGasPrice.success) {
logger.error('Failed to get chain gas price', goGasPrice.error, logOptions);
throw new Error(goGasPrice.error.message);
Expand Down

0 comments on commit 4f09e58

Please sign in to comment.