Skip to content

Commit

Permalink
move from JsonRpcProvider to StaticJsonRpcProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
andrearampin committed Mar 8, 2024
1 parent 23464e8 commit ef0cc1b
Show file tree
Hide file tree
Showing 36 changed files with 160 additions and 160 deletions.
10 changes: 5 additions & 5 deletions packages/checkout/sdk/src/gasEstimate/gasEstimator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jest.mock('ethers', () => ({
}));

describe('gasServiceEstimator', () => {
let readOnlyProviders: Map<ChainId, ethers.providers.JsonRpcProvider>;
let readOnlyProviders: Map<ChainId, ethers.providers.StaticJsonRpcProvider>;
let config: CheckoutConfiguration;
let decimalsMock: jest.Mock;
let nameMock: jest.Mock;
Expand All @@ -43,7 +43,7 @@ describe('gasServiceEstimator', () => {
symbol: symbolMock,
});

readOnlyProviders = new Map<ChainId, ethers.providers.JsonRpcProvider>([
readOnlyProviders = new Map<ChainId, ethers.providers.StaticJsonRpcProvider>([
[
ChainId.SEPOLIA,
{
Expand All @@ -52,7 +52,7 @@ describe('gasServiceEstimator', () => {
maxPriorityFeePerGas: '0x1',
gasPrice: null,
}),
} as unknown as ethers.providers.JsonRpcProvider,
} as unknown as ethers.providers.StaticJsonRpcProvider,
],
]);

Expand Down Expand Up @@ -257,7 +257,7 @@ describe('gasServiceEstimator', () => {

const readOnlyProvidersUndefinedFees = new Map<
ChainId,
ethers.providers.JsonRpcProvider
ethers.providers.StaticJsonRpcProvider
>([
[
ChainId.SEPOLIA,
Expand All @@ -268,7 +268,7 @@ describe('gasServiceEstimator', () => {
maxPriorityFeePerGas: null,
gasPrice: '0x1',
}),
} as unknown as ethers.providers.JsonRpcProvider,
} as unknown as ethers.providers.StaticJsonRpcProvider,
],
]);
const result = (await gasEstimator(
Expand Down
6 changes: 3 additions & 3 deletions packages/checkout/sdk/src/gasEstimate/gasEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const DUMMY_WALLET_ADDRESS = '0x0000000000000000000000000000000000000001';
const DEFAULT_TOKEN_DECIMALS = 18;

async function bridgeToL2GasEstimator(
readOnlyProviders: Map<ChainId, ethers.providers.JsonRpcProvider>,
readOnlyProviders: Map<ChainId, ethers.providers.StaticJsonRpcProvider>,
config: CheckoutConfiguration,
): Promise<GasEstimateBridgeToL2Result> {
const fromChainId = getL1ChainId(config);
const toChainId = getL2ChainId(config);

const provider = readOnlyProviders.get(fromChainId);
if (!provider) throw new Error(`Missing JsonRpcProvider for chain id: ${fromChainId}`);
if (!provider) throw new Error(`Missing StaticJsonRpcProvider for chain id: ${fromChainId}`);

try {
const tokenBridge = instance.createBridgeInstance(
Expand Down Expand Up @@ -123,7 +123,7 @@ async function swapGasEstimator(

export async function gasEstimator(
params: GasEstimateParams,
readOnlyProviders: Map<ChainId, ethers.providers.JsonRpcProvider>,
readOnlyProviders: Map<ChainId, ethers.providers.StaticJsonRpcProvider>,
config: CheckoutConfiguration,
): Promise<GasEstimateSwapResult | GasEstimateBridgeToL2Result> {
switch (params.gasEstimateType) {
Expand Down
6 changes: 3 additions & 3 deletions packages/checkout/sdk/src/instance/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ describe('instance', () => {
describe('createBridgeInstance', () => {
const readOnlyProviders = new Map<
ChainId,
ethers.providers.JsonRpcProvider
ethers.providers.StaticJsonRpcProvider
>([
[ChainId.SEPOLIA, new ethers.providers.JsonRpcProvider('sepolia')],
[ChainId.SEPOLIA, new ethers.providers.StaticJsonRpcProvider('sepolia')],
[
ChainId.IMTBL_ZKEVM_TESTNET,
new ethers.providers.JsonRpcProvider('devnet'),
new ethers.providers.StaticJsonRpcProvider('devnet'),
],
]);

Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/instance/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CheckoutConfiguration } from '../config';
export function createBridgeInstance(
fromChainId: ChainId,
toChainId: ChainId,
readOnlyProviders: Map<ChainId, ethers.providers.JsonRpcProvider>,
readOnlyProviders: Map<ChainId, ethers.providers.StaticJsonRpcProvider>,
config: CheckoutConfiguration,
): TokenBridge {
const rootChainProvider = readOnlyProviders.get(fromChainId);
Expand Down
10 changes: 5 additions & 5 deletions packages/checkout/sdk/src/readOnlyProviders/readOnlyProvider.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import * as network from '../network';
import { ChainId, NetworkFilterTypes } from '../types';
import { CheckoutConfiguration } from '../config';

export async function createReadOnlyProviders(
config: CheckoutConfiguration,
existingReadOnlyProviders?: Map<ChainId, JsonRpcProvider>,
): Promise<Map<ChainId, JsonRpcProvider>> {
existingReadOnlyProviders?: Map<ChainId, StaticJsonRpcProvider>,
): Promise<Map<ChainId, StaticJsonRpcProvider>> {
if (config.isProduction && existingReadOnlyProviders?.has(ChainId.ETHEREUM)) return existingReadOnlyProviders;
if (existingReadOnlyProviders?.has(ChainId.SEPOLIA)) return existingReadOnlyProviders;

const readOnlyProviders = new Map<ChainId, JsonRpcProvider>();
const readOnlyProviders = new Map<ChainId, StaticJsonRpcProvider>();

const allowedNetworks = await network.getNetworkAllowList(config, {
type: NetworkFilterTypes.ALL,
});

allowedNetworks.networks.forEach((networkInfo) => {
const rpcUrl = config.networkMap.get(networkInfo.chainId)?.rpcUrls[0];
const provider = new JsonRpcProvider(rpcUrl);
const provider = new StaticJsonRpcProvider(rpcUrl);
readOnlyProviders.set(networkInfo.chainId, provider);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Environment } from '@imtbl/config';
import { JsonRpcProvider } from '@ethersproject/providers';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { ChainId, ChainName, GetNetworkAllowListResult } from '../types';
import { createReadOnlyProviders } from './readOnlyProvider';
import { CheckoutConfiguration } from '../config';
Expand All @@ -9,7 +9,7 @@ import { HttpClient } from '../api/http';
jest.mock('../network');
jest.mock('@ethersproject/providers', () => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
JsonRpcProvider: jest.fn(),
StaticJsonRpcProvider: jest.fn(),
}));

const mockedHttpClient = new HttpClient() as jest.Mocked<HttpClient>;
Expand Down Expand Up @@ -51,10 +51,10 @@ describe('read only providers', () => {
});

it('should return new map of read only providers', async () => {
const existingReadOnlyProviders = new Map<ChainId, JsonRpcProvider>();
const existingReadOnlyProviders = new Map<ChainId, StaticJsonRpcProvider>();
existingReadOnlyProviders.set(
ChainId.ETHEREUM,
new JsonRpcProvider('mainnet-url'),
new StaticJsonRpcProvider('mainnet-url'),
);

const result = await createReadOnlyProviders(
Expand All @@ -69,10 +69,10 @@ describe('read only providers', () => {
});

it('should return existing map of read only providers', async () => {
const existingReadOnlyProviders = new Map<ChainId, JsonRpcProvider>();
const existingReadOnlyProviders = new Map<ChainId, StaticJsonRpcProvider>();
existingReadOnlyProviders.set(
ChainId.SEPOLIA,
new JsonRpcProvider('sepolia-url'),
new StaticJsonRpcProvider('sepolia-url'),
);

const result = await createReadOnlyProviders(
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('Connect', () => {

it('should call gasEstimate function', async () => {
(createReadOnlyProviders as jest.Mock).mockResolvedValue(
{} as Map<ChainId, ethers.providers.JsonRpcProvider>,
{} as Map<ChainId, ethers.providers.StaticJsonRpcProvider>,
);
(gasEstimator as jest.Mock).mockResolvedValue({} as GasEstimateSwapResult);

Expand Down
4 changes: 2 additions & 2 deletions packages/checkout/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const SANDBOX_CONFIGURATION = {

// Checkout SDK
export class Checkout {
private readOnlyProviders: Map<ChainId, ethers.providers.JsonRpcProvider>;
private readOnlyProviders: Map<ChainId, ethers.providers.StaticJsonRpcProvider>;

private httpClient: HttpClient;

Expand All @@ -105,7 +105,7 @@ export class Checkout {
this.httpClient = new HttpClient(config);
this.config = new CheckoutConfiguration(config, this.httpClient);
this.fiatRampService = new FiatRampService(this.config);
this.readOnlyProviders = new Map<ChainId, ethers.providers.JsonRpcProvider>();
this.readOnlyProviders = new Map<ChainId, ethers.providers.StaticJsonRpcProvider>();
this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction);
this.passport = config.passport;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Environment } from '@imtbl/config';
import { JsonRpcProvider } from '@ethersproject/providers';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { BigNumber, utils } from 'ethers';
import {
BridgeRequirement,
Expand Down Expand Up @@ -33,9 +33,9 @@ describe('bridgeRoute', () => {
baseConfig: { environment: Environment.SANDBOX },
}, mockedHttpClient);

const readonlyProviders = new Map<ChainId, JsonRpcProvider>([
[ChainId.SEPOLIA, {} as JsonRpcProvider],
[ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider],
const readonlyProviders = new Map<ChainId, StaticJsonRpcProvider>([
[ChainId.SEPOLIA, {} as StaticJsonRpcProvider],
[ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider],
]);

describe('bridgeRoute', () => {
Expand Down Expand Up @@ -829,8 +829,8 @@ describe('bridgeRoute', () => {
try {
await bridgeRoute(
config,
new Map<ChainId, JsonRpcProvider>([
[ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider],
new Map<ChainId, StaticJsonRpcProvider>([
[ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider],
]),
{
bridge: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export type BridgeRequirement = {
};
export const bridgeRoute = async (
config: CheckoutConfiguration,
readOnlyProviders: Map<ChainId, ethers.providers.JsonRpcProvider>,
readOnlyProviders: Map<ChainId, ethers.providers.StaticJsonRpcProvider>,
availableRoutingOptions: AvailableRoutingOptions,
bridgeRequirement: BridgeRequirement,
tokenBalanceResults: Map<ChainId, TokenBalanceResult>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock('../../../gasEstimate');
jest.mock('../../../instance');

describe('getBridgeFeeEstimate', () => {
const readOnlyProviders = new Map<ChainId, ethers.providers.JsonRpcProvider>([]);
const readOnlyProviders = new Map<ChainId, ethers.providers.StaticJsonRpcProvider>([]);
const mockedHttpClient = new HttpClient() as jest.Mocked<HttpClient>;
const config = new CheckoutConfiguration({
baseConfig: { environment: Environment.SANDBOX },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as instance from '../../../instance';

export const getBridgeFeeEstimate = async (
config: CheckoutConfiguration,
readOnlyProviders: Map<ChainId, ethers.providers.JsonRpcProvider>,
readOnlyProviders: Map<ChainId, ethers.providers.StaticJsonRpcProvider>,
fromChainId: ChainId,
toChainId: ChainId,
): Promise<BridgeFeeResponse & { approvalGas: BigNumber; }> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Environment } from '@imtbl/config';
import { BigNumber } from 'ethers';
import { JsonRpcProvider } from '@ethersproject/providers';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { Quote } from '@imtbl/dex-sdk';
import { CheckoutConfiguration } from '../../../config';
import {
Expand Down Expand Up @@ -35,9 +35,9 @@ describe('bridgeAndSwapRoute', () => {
baseConfig: { environment: Environment.SANDBOX },
}, mockedHttpClient);

const readonlyProviders = new Map<ChainId, JsonRpcProvider>([
[ChainId.SEPOLIA, {} as JsonRpcProvider],
[ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider],
const readonlyProviders = new Map<ChainId, StaticJsonRpcProvider>([
[ChainId.SEPOLIA, {} as StaticJsonRpcProvider],
[ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider],
]);

const availableRoutingOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber, utils } from 'ethers';
import { JsonRpcProvider } from '@ethersproject/providers';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { CheckoutConfiguration, getL2ChainId } from '../../../config';
import {
AvailableRoutingOptions,
Expand Down Expand Up @@ -208,7 +208,7 @@ export type BridgeAndSwapRoute = {
};
export const bridgeAndSwapRoute = async (
config: CheckoutConfiguration,
readOnlyProviders: Map<ChainId, JsonRpcProvider>,
readOnlyProviders: Map<ChainId, StaticJsonRpcProvider>,
availableRoutingOptions: AvailableRoutingOptions,
insufficientRequirement: BalanceNativeRequirement | BalanceERC20Requirement,
ownerAddress: string,
Expand Down
Loading

0 comments on commit ef0cc1b

Please sign in to comment.