diff --git a/packages/checkout/sdk/src/gasEstimate/gasEstimator.test.ts b/packages/checkout/sdk/src/gasEstimate/gasEstimator.test.ts index 1d657b4edf..c4f7bcaef0 100644 --- a/packages/checkout/sdk/src/gasEstimate/gasEstimator.test.ts +++ b/packages/checkout/sdk/src/gasEstimate/gasEstimator.test.ts @@ -27,7 +27,7 @@ jest.mock('ethers', () => ({ })); describe('gasServiceEstimator', () => { - let readOnlyProviders: Map; + let readOnlyProviders: Map; let config: CheckoutConfiguration; let decimalsMock: jest.Mock; let nameMock: jest.Mock; @@ -43,7 +43,7 @@ describe('gasServiceEstimator', () => { symbol: symbolMock, }); - readOnlyProviders = new Map([ + readOnlyProviders = new Map([ [ ChainId.SEPOLIA, { @@ -52,7 +52,7 @@ describe('gasServiceEstimator', () => { maxPriorityFeePerGas: '0x1', gasPrice: null, }), - } as unknown as ethers.providers.JsonRpcProvider, + } as unknown as ethers.providers.StaticJsonRpcProvider, ], ]); @@ -257,7 +257,7 @@ describe('gasServiceEstimator', () => { const readOnlyProvidersUndefinedFees = new Map< ChainId, - ethers.providers.JsonRpcProvider + ethers.providers.StaticJsonRpcProvider >([ [ ChainId.SEPOLIA, @@ -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( diff --git a/packages/checkout/sdk/src/gasEstimate/gasEstimator.ts b/packages/checkout/sdk/src/gasEstimate/gasEstimator.ts index 589a569272..9814749902 100644 --- a/packages/checkout/sdk/src/gasEstimate/gasEstimator.ts +++ b/packages/checkout/sdk/src/gasEstimate/gasEstimator.ts @@ -23,14 +23,14 @@ const DUMMY_WALLET_ADDRESS = '0x0000000000000000000000000000000000000001'; const DEFAULT_TOKEN_DECIMALS = 18; async function bridgeToL2GasEstimator( - readOnlyProviders: Map, + readOnlyProviders: Map, config: CheckoutConfiguration, ): Promise { 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( @@ -123,7 +123,7 @@ async function swapGasEstimator( export async function gasEstimator( params: GasEstimateParams, - readOnlyProviders: Map, + readOnlyProviders: Map, config: CheckoutConfiguration, ): Promise { switch (params.gasEstimateType) { diff --git a/packages/checkout/sdk/src/instance/instance.test.ts b/packages/checkout/sdk/src/instance/instance.test.ts index 20e990d4e3..c450078f5f 100644 --- a/packages/checkout/sdk/src/instance/instance.test.ts +++ b/packages/checkout/sdk/src/instance/instance.test.ts @@ -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'), ], ]); diff --git a/packages/checkout/sdk/src/instance/instance.ts b/packages/checkout/sdk/src/instance/instance.ts index ab6786f430..1c5df791b1 100644 --- a/packages/checkout/sdk/src/instance/instance.ts +++ b/packages/checkout/sdk/src/instance/instance.ts @@ -17,7 +17,7 @@ import { CheckoutConfiguration } from '../config'; export function createBridgeInstance( fromChainId: ChainId, toChainId: ChainId, - readOnlyProviders: Map, + readOnlyProviders: Map, config: CheckoutConfiguration, ): TokenBridge { const rootChainProvider = readOnlyProviders.get(fromChainId); diff --git a/packages/checkout/sdk/src/readOnlyProviders/readOnlyProvider.ts b/packages/checkout/sdk/src/readOnlyProviders/readOnlyProvider.ts index 4abfa71c74..e6cb55d269 100644 --- a/packages/checkout/sdk/src/readOnlyProviders/readOnlyProvider.ts +++ b/packages/checkout/sdk/src/readOnlyProviders/readOnlyProvider.ts @@ -1,16 +1,16 @@ -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, -): Promise> { + existingReadOnlyProviders?: Map, +): Promise> { if (config.isProduction && existingReadOnlyProviders?.has(ChainId.ETHEREUM)) return existingReadOnlyProviders; if (existingReadOnlyProviders?.has(ChainId.SEPOLIA)) return existingReadOnlyProviders; - const readOnlyProviders = new Map(); + const readOnlyProviders = new Map(); const allowedNetworks = await network.getNetworkAllowList(config, { type: NetworkFilterTypes.ALL, @@ -18,7 +18,7 @@ export async function createReadOnlyProviders( 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); }); diff --git a/packages/checkout/sdk/src/readOnlyProviders/readOnlyProviders.test.ts b/packages/checkout/sdk/src/readOnlyProviders/readOnlyProviders.test.ts index ba8d246b3e..91883fb43f 100644 --- a/packages/checkout/sdk/src/readOnlyProviders/readOnlyProviders.test.ts +++ b/packages/checkout/sdk/src/readOnlyProviders/readOnlyProviders.test.ts @@ -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'; @@ -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; @@ -51,10 +51,10 @@ describe('read only providers', () => { }); it('should return new map of read only providers', async () => { - const existingReadOnlyProviders = new Map(); + const existingReadOnlyProviders = new Map(); existingReadOnlyProviders.set( ChainId.ETHEREUM, - new JsonRpcProvider('mainnet-url'), + new StaticJsonRpcProvider('mainnet-url'), ); const result = await createReadOnlyProviders( @@ -69,10 +69,10 @@ describe('read only providers', () => { }); it('should return existing map of read only providers', async () => { - const existingReadOnlyProviders = new Map(); + const existingReadOnlyProviders = new Map(); existingReadOnlyProviders.set( ChainId.SEPOLIA, - new JsonRpcProvider('sepolia-url'), + new StaticJsonRpcProvider('sepolia-url'), ); const result = await createReadOnlyProviders( diff --git a/packages/checkout/sdk/src/sdk.test.ts b/packages/checkout/sdk/src/sdk.test.ts index fb348e8b00..83cfad1206 100644 --- a/packages/checkout/sdk/src/sdk.test.ts +++ b/packages/checkout/sdk/src/sdk.test.ts @@ -272,7 +272,7 @@ describe('Connect', () => { it('should call gasEstimate function', async () => { (createReadOnlyProviders as jest.Mock).mockResolvedValue( - {} as Map, + {} as Map, ); (gasEstimator as jest.Mock).mockResolvedValue({} as GasEstimateSwapResult); diff --git a/packages/checkout/sdk/src/sdk.ts b/packages/checkout/sdk/src/sdk.ts index b094966362..690f7498c2 100644 --- a/packages/checkout/sdk/src/sdk.ts +++ b/packages/checkout/sdk/src/sdk.ts @@ -83,7 +83,7 @@ const SANDBOX_CONFIGURATION = { // Checkout SDK export class Checkout { - private readOnlyProviders: Map; + private readOnlyProviders: Map; private httpClient: HttpClient; @@ -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(); + this.readOnlyProviders = new Map(); this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction); this.passport = config.passport; diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.test.ts index dac07caace..0ee631d95b 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.test.ts @@ -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, @@ -33,9 +33,9 @@ describe('bridgeRoute', () => { baseConfig: { environment: Environment.SANDBOX }, }, mockedHttpClient); - const readonlyProviders = new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + const readonlyProviders = new Map([ + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ]); describe('bridgeRoute', () => { @@ -829,8 +829,8 @@ describe('bridgeRoute', () => { try { await bridgeRoute( config, - new Map([ - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + new Map([ + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ]), { bridge: true, diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.ts index 1a55f9dbd6..8055650972 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridge/bridgeRoute.ts @@ -115,7 +115,7 @@ export type BridgeRequirement = { }; export const bridgeRoute = async ( config: CheckoutConfiguration, - readOnlyProviders: Map, + readOnlyProviders: Map, availableRoutingOptions: AvailableRoutingOptions, bridgeRequirement: BridgeRequirement, tokenBalanceResults: Map, diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts index 0d94f08e98..8d85d1d084 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts @@ -11,7 +11,7 @@ jest.mock('../../../gasEstimate'); jest.mock('../../../instance'); describe('getBridgeFeeEstimate', () => { - const readOnlyProviders = new Map([]); + const readOnlyProviders = new Map([]); const mockedHttpClient = new HttpClient() as jest.Mocked; const config = new CheckoutConfiguration({ baseConfig: { environment: Environment.SANDBOX }, diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts index 95b4ee8448..da12c46da5 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts @@ -9,7 +9,7 @@ import * as instance from '../../../instance'; export const getBridgeFeeEstimate = async ( config: CheckoutConfiguration, - readOnlyProviders: Map, + readOnlyProviders: Map, fromChainId: ChainId, toChainId: ChainId, ): Promise => { diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.test.ts index b47a296328..a9f5552f55 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.test.ts @@ -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 { @@ -35,9 +35,9 @@ describe('bridgeAndSwapRoute', () => { baseConfig: { environment: Environment.SANDBOX }, }, mockedHttpClient); - const readonlyProviders = new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + const readonlyProviders = new Map([ + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ]); const availableRoutingOptions = { diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.ts index 7e34bfddbb..267c2b0a73 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.ts @@ -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, @@ -208,7 +208,7 @@ export type BridgeAndSwapRoute = { }; export const bridgeAndSwapRoute = async ( config: CheckoutConfiguration, - readOnlyProviders: Map, + readOnlyProviders: Map, availableRoutingOptions: AvailableRoutingOptions, insufficientRequirement: BalanceNativeRequirement | BalanceERC20Requirement, ownerAddress: string, diff --git a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts index e3470afae2..4dd40e7442 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts @@ -1,6 +1,6 @@ import { BigNumber, utils } from 'ethers'; import { Environment } from '@imtbl/config'; -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { getBridgeAndSwapFundingSteps, getSwapFundingSteps, @@ -47,9 +47,9 @@ jest.mock('./bridgeAndSwap/bridgeAndSwapRoute'); describe('routingCalculator', () => { let config: CheckoutConfiguration; - const readonlyProviders = new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + const readonlyProviders = new Map([ + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ]); beforeEach(() => { @@ -69,8 +69,8 @@ describe('routingCalculator', () => { const balanceRequirements = {} as BalanceCheckResult; (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); const routingOptions = await routingCalculator( @@ -90,8 +90,8 @@ describe('routingCalculator', () => { const availableRoutingOptions = {}; const balanceRequirements = {} as BalanceCheckResult; (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); const routingOptions = await routingCalculator( @@ -205,8 +205,8 @@ describe('routingCalculator', () => { (bridgeRoute as jest.Mock).mockResolvedValue(bridgeFundingStep); (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); const routingOptions = await routingCalculator( @@ -342,8 +342,8 @@ describe('routingCalculator', () => { (swapRoute as jest.Mock).mockResolvedValue([swapFundingStep]); (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); const routingOptions = await routingCalculator( @@ -518,8 +518,8 @@ describe('routingCalculator', () => { (swapRoute as jest.Mock).mockResolvedValue([swapFundingStep1, swapFundingStep2]); (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); const routingOptions = await routingCalculator( @@ -655,8 +655,8 @@ describe('routingCalculator', () => { (swapRoute as jest.Mock).mockResolvedValue(undefined); (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); const routingOptions = await routingCalculator( @@ -901,8 +901,8 @@ describe('routingCalculator', () => { ]); (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); const routingOptions = await routingCalculator( @@ -984,8 +984,8 @@ describe('routingCalculator', () => { ])); (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); (bridgeRoute as jest.Mock).mockResolvedValue({ @@ -1034,8 +1034,8 @@ describe('routingCalculator', () => { ])); (createReadOnlyProviders as jest.Mock).mockResolvedValue(new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ])); (bridgeRoute as jest.Mock).mockResolvedValue(undefined); diff --git a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts index 82587fea45..9b53dedeb8 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { BalanceCheckResult, BalanceRequirement, @@ -57,7 +57,7 @@ export const getInsufficientRequirement = ( export const getBridgeFundingStep = async ( config: CheckoutConfiguration, - readOnlyProviders: Map, + readOnlyProviders: Map, availableRoutingOptions: AvailableRoutingOptions, insufficientRequirement: BalanceRequirement | undefined, tokenBalances: Map, @@ -124,7 +124,7 @@ export const getSwapFundingSteps = async ( export const getBridgeAndSwapFundingSteps = async ( config: CheckoutConfiguration, - readOnlyProviders: Map, + readOnlyProviders: Map, availableRoutingOptions: AvailableRoutingOptions, insufficientRequirement: BalanceRequirement | undefined, ownerAddress: string, diff --git a/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.test.ts index 6f375d474d..d483357d3c 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.test.ts @@ -1,5 +1,5 @@ import { Environment } from '@imtbl/config'; -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { BigNumber } from 'ethers'; import { getAllTokenBalances } from './tokenBalances'; import { CheckoutConfiguration, getL1ChainId, getL2ChainId } from '../../config'; @@ -34,9 +34,9 @@ describe('tokenBalances', () => { bridge: true, }; - const readonlyProviders = new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + const readonlyProviders = new Map([ + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ]); const getBalancesResult = { @@ -76,9 +76,9 @@ describe('tokenBalances', () => { bridge: false, }; - const readonlyProviders = new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + const readonlyProviders = new Map([ + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ]); const getBalancesResult = { @@ -118,7 +118,7 @@ describe('tokenBalances', () => { bridge: true, }; - const readonlyProviders = new Map([]); + const readonlyProviders = new Map([]); const tokenBalances = await getAllTokenBalances( mockConfig, @@ -146,8 +146,8 @@ describe('tokenBalances', () => { bridge: true, }; - const readonlyProviders = new Map([ - [ChainId.IMTBL_ZKEVM_TESTNET, {} as JsonRpcProvider], + const readonlyProviders = new Map([ + [ChainId.IMTBL_ZKEVM_TESTNET, {} as StaticJsonRpcProvider], ]); const getBalancesResult = { @@ -191,8 +191,8 @@ describe('tokenBalances', () => { bridge: true, }; - const readonlyProviders = new Map([ - [ChainId.SEPOLIA, {} as JsonRpcProvider], + const readonlyProviders = new Map([ + [ChainId.SEPOLIA, {} as StaticJsonRpcProvider], ]); const getBalancesResult = { diff --git a/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.ts b/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.ts index ea339efed1..849302ffcd 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/tokenBalances.ts @@ -8,7 +8,7 @@ import { TokenBalanceResult } from './types'; export const getAllTokenBalances = async ( config: CheckoutConfiguration, - readOnlyProviders: Map, + readOnlyProviders: Map, ownerAddress: string, availableRoutingOptions: AvailableRoutingOptions, ): Promise> => { diff --git a/packages/checkout/sdk/src/tokens/tokens.ts b/packages/checkout/sdk/src/tokens/tokens.ts index 29afd81bdf..7f4fc91f4c 100644 --- a/packages/checkout/sdk/src/tokens/tokens.ts +++ b/packages/checkout/sdk/src/tokens/tokens.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, Web3Provider } from '@ethersproject/providers'; import { Contract } from 'ethers'; import { BridgeConfig, @@ -72,7 +72,7 @@ export const isNativeToken = ( ): boolean => !address || isMatchingAddress(address, NATIVE); export async function getERC20TokenInfo( - web3Provider: Web3Provider | JsonRpcProvider, + web3Provider: Web3Provider | StaticJsonRpcProvider, tokenAddress: string, ) { return await withCheckoutError( diff --git a/packages/checkout/sdk/src/types/tokenInfo.ts b/packages/checkout/sdk/src/types/tokenInfo.ts index 6f29bac3f5..a83873e06c 100644 --- a/packages/checkout/sdk/src/types/tokenInfo.ts +++ b/packages/checkout/sdk/src/types/tokenInfo.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, Web3Provider } from '@ethersproject/providers'; /** * Represents information about a token. @@ -19,10 +19,10 @@ export interface TokenInfo { /** * Interface representing the parameters for {@link Checkout.getTokenInfo}. - * @property {Web3Provider | JsonRpcProvider} provider - The provider used to get the balance. + * @property {Web3Provider | StaticJsonRpcProvider} provider - The provider used to get the balance. * @property {string} tokenAddress - The contract address of the token. */ export interface GetTokenInfoParams { - provider: Web3Provider | JsonRpcProvider; + provider: Web3Provider | StaticJsonRpcProvider; tokenAddress: string; } diff --git a/packages/checkout/widgets-lib/src/components/Transactions/Transactions.tsx b/packages/checkout/widgets-lib/src/components/Transactions/Transactions.tsx index 3a900ca179..2e49563b98 100644 --- a/packages/checkout/widgets-lib/src/components/Transactions/Transactions.tsx +++ b/packages/checkout/widgets-lib/src/components/Transactions/Transactions.tsx @@ -10,7 +10,7 @@ import { connectToProvider, isPassportProvider, } from 'lib/provider'; -import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, Web3Provider } from '@ethersproject/providers'; import { TokenFilterTypes, TokenInfo, WalletProviderRdns, @@ -160,12 +160,12 @@ export function Transactions({ ) missingTokens[key] = value; }); // Root provider is always L1 - const rootProvider = new JsonRpcProvider( + const rootProvider = new StaticJsonRpcProvider( checkout.config.networkMap.get(getL1ChainId(checkout.config))?.rpcUrls[0], ); // Child provider is always L2 - const childProvider = new JsonRpcProvider( + const childProvider = new StaticJsonRpcProvider( checkout.config.networkMap.get(getL2ChainId(checkout.config))?.rpcUrls[0], ); diff --git a/packages/checkout/widgets-lib/src/widgets/bridge/BridgeWidget.tsx b/packages/checkout/widgets-lib/src/widgets/bridge/BridgeWidget.tsx index 70ec1f076a..6089ae5153 100644 --- a/packages/checkout/widgets-lib/src/widgets/bridge/BridgeWidget.tsx +++ b/packages/checkout/widgets-lib/src/widgets/bridge/BridgeWidget.tsx @@ -12,7 +12,7 @@ import { } from 'react'; import { StrongCheckoutWidgetsConfig } from 'lib/withDefaultWidgetConfig'; import { CryptoFiatProvider } from 'context/crypto-fiat-context/CryptoFiatProvider'; -import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, Web3Provider } from '@ethersproject/providers'; import { BridgeClaimWithdrawalFailure, BridgeWidgetViews } from 'context/view-context/BridgeViewContextTypes'; import { StatusView } from 'components/Status/StatusView'; import { StatusType } from 'components/Status/StatusType'; @@ -109,12 +109,12 @@ export default function BridgeWidget({ if (checkout.config.isProduction) bridgeInstance = ETH_MAINNET_TO_ZKEVM_MAINNET; // Root provider is always L1 - const rootProvider = new JsonRpcProvider( + const rootProvider = new StaticJsonRpcProvider( checkout.config.networkMap.get(getL1ChainId(checkout.config))?.rpcUrls[0], ); // Child provider is always L2 - const childProvider = new JsonRpcProvider( + const childProvider = new StaticJsonRpcProvider( checkout.config.networkMap.get(getL2ChainId(checkout.config))?.rpcUrls[0], ); const bridgeConfiguration = new BridgeConfiguration({ diff --git a/packages/passport/sdk/src/Passport.int.test.ts b/packages/passport/sdk/src/Passport.int.test.ts index 3c671aa87f..ce437eae68 100644 --- a/packages/passport/sdk/src/Passport.int.test.ts +++ b/packages/passport/sdk/src/Passport.int.test.ts @@ -166,7 +166,7 @@ describe('Passport', () => { it('returns the users ether key', async () => { mockGetUser.mockResolvedValue(mockOidcUserZkevm); useMswHandlers([ - mswHandlers.jsonRpcProvider.success, + mswHandlers.staticJsonRpcProvider.success, ]); const zkEvmProvider = getZkEvmProvider(); @@ -200,7 +200,7 @@ describe('Passport', () => { mockSigninPopup.mockResolvedValue(mockOidcUser); mockSigninSilent.mockResolvedValueOnce(mockOidcUserZkevm); useMswHandlers([ - mswHandlers.jsonRpcProvider.success, + mswHandlers.staticJsonRpcProvider.success, mswHandlers.counterfactualAddress.success, mswHandlers.api.chains.success, ]); @@ -242,7 +242,7 @@ describe('Passport', () => { useMswHandlers([ mswHandlers.counterfactualAddress.success, - mswHandlers.jsonRpcProvider.success, + mswHandlers.staticJsonRpcProvider.success, mswHandlers.relayer.success, mswHandlers.guardian.evaluateTransaction.success, ]); @@ -296,7 +296,7 @@ describe('Passport', () => { it('returns the user\'s ether key if the user is logged in', async () => { mockGetUser.mockResolvedValue(mockOidcUserZkevm); useMswHandlers([ - mswHandlers.jsonRpcProvider.success, + mswHandlers.staticJsonRpcProvider.success, ]); const zkEvmProvider = getZkEvmProvider(); diff --git a/packages/passport/sdk/src/mocks/zkEvm/msw.ts b/packages/passport/sdk/src/mocks/zkEvm/msw.ts index e4e967ac4e..12623da07b 100644 --- a/packages/passport/sdk/src/mocks/zkEvm/msw.ts +++ b/packages/passport/sdk/src/mocks/zkEvm/msw.ts @@ -46,7 +46,7 @@ export const mswHandlers = { (req, res, ctx) => res(ctx.status(500)), ), }, - jsonRpcProvider: { + staticJsonRpcProvider: { success: rest.post('https://rpc.testnet.immutable.com', async (req, res, ctx) => { const body = await req.json(); switch (body.method) { diff --git a/packages/passport/sdk/src/zkEvm/relayerClient.test.ts b/packages/passport/sdk/src/zkEvm/relayerClient.test.ts index 33f554716d..3bb61b9505 100644 --- a/packages/passport/sdk/src/zkEvm/relayerClient.test.ts +++ b/packages/passport/sdk/src/zkEvm/relayerClient.test.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import AuthManager from 'authManager'; import { RelayerClient } from './relayerClient'; import { PassportConfiguration } from '../config'; @@ -14,12 +14,12 @@ describe('relayerClient', () => { const user = { accessToken: 'accessToken123', }; - const jsonRpcProvider: Partial = { + const staticJsonRpcProvider: Partial = { ready: Promise.resolve({ chainId, name: '' }), }; const relayerClient = new RelayerClient({ config: config as PassportConfiguration, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, authManager: { getUserZkEvm: jest.fn().mockResolvedValue(user as UserZkEvm), } as unknown as AuthManager, diff --git a/packages/passport/sdk/src/zkEvm/relayerClient.ts b/packages/passport/sdk/src/zkEvm/relayerClient.ts index 1b5f95f6ae..c59b382832 100644 --- a/packages/passport/sdk/src/zkEvm/relayerClient.ts +++ b/packages/passport/sdk/src/zkEvm/relayerClient.ts @@ -1,5 +1,5 @@ import { BytesLike } from 'ethers'; -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import AuthManager from 'authManager'; import { PassportConfiguration } from '../config'; import { FeeOption, RelayerTransaction, TypedDataPayload } from './types'; @@ -7,7 +7,7 @@ import { getEip155ChainId } from './walletHelpers'; export type RelayerClientInput = { config: PassportConfiguration, - jsonRpcProvider: JsonRpcProvider, + staticJsonRpcProvider: StaticJsonRpcProvider, authManager: AuthManager }; @@ -78,13 +78,13 @@ export type RelayerTransactionRequest = export class RelayerClient { private readonly config: PassportConfiguration; - private readonly jsonRpcProvider: JsonRpcProvider; + private readonly staticJsonRpcProvider: StaticJsonRpcProvider; private readonly authManager: AuthManager; - constructor({ config, jsonRpcProvider, authManager }: RelayerClientInput) { + constructor({ config, staticJsonRpcProvider, authManager }: RelayerClientInput) { this.config = config; - this.jsonRpcProvider = jsonRpcProvider; + this.staticJsonRpcProvider = staticJsonRpcProvider; this.authManager = authManager; } @@ -115,7 +115,7 @@ export class RelayerClient { } public async ethSendTransaction(to: string, data: BytesLike): Promise { - const { chainId } = await this.jsonRpcProvider.ready; + const { chainId } = await this.staticJsonRpcProvider.ready; const payload: EthSendTransactionRequest = { method: 'eth_sendTransaction', params: [{ @@ -138,7 +138,7 @@ export class RelayerClient { } public async imGetFeeOptions(userAddress: string, data: BytesLike): Promise { - const { chainId } = await this.jsonRpcProvider.ready; + const { chainId } = await this.staticJsonRpcProvider.ready; const payload: ImGetFeeOptionsRequest = { method: 'im_getFeeOptions', params: [{ @@ -152,7 +152,7 @@ export class RelayerClient { } public async imSignTypedData(address: string, eip712Payload: TypedDataPayload): Promise { - const { chainId } = await this.jsonRpcProvider.ready; + const { chainId } = await this.staticJsonRpcProvider.ready; const payload: ImSignTypedDataRequest = { method: 'im_signTypedData', params: [{ diff --git a/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts b/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts index c06b71f883..3d74de0730 100644 --- a/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts +++ b/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider, TransactionRequest } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, TransactionRequest } from '@ethersproject/providers'; import { Signer } from '@ethersproject/abstract-signer'; import { getEip155ChainId, getNonce, getSignedMetaTransactions } from './walletHelpers'; import { sendTransaction } from './sendTransaction'; @@ -26,7 +26,7 @@ describe('sendTransaction', () => { data: '0x456', value: '0x00', }; - const jsonRpcProvider = { + const staticJsonRpcProvider = { ready: Promise.resolve({ chainId }), }; const relayerClient = { @@ -76,7 +76,7 @@ describe('sendTransaction', () => { const result = await sendTransaction({ params: [transactionRequest], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, zkevmAddress: mockUserZkEvm.zkEvm.ethAddress, guardianClient: guardianClient as unknown as GuardianClient, @@ -108,7 +108,7 @@ describe('sendTransaction', () => { const result = await sendTransaction({ params: [transactionRequest], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, zkevmAddress: mockUserZkEvm.zkEvm.ethAddress, guardianClient: guardianClient as unknown as GuardianClient, @@ -147,7 +147,7 @@ describe('sendTransaction', () => { const result = await sendTransaction({ params: [transactionRequest], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, zkevmAddress: mockUserZkEvm.zkEvm.ethAddress, guardianClient: guardianClient as unknown as GuardianClient, @@ -192,7 +192,7 @@ describe('sendTransaction', () => { sendTransaction({ params: [transactionRequest], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, zkevmAddress: mockUserZkEvm.zkEvm.ethAddress, guardianClient: guardianClient as unknown as GuardianClient, diff --git a/packages/passport/sdk/src/zkEvm/sendTransaction.ts b/packages/passport/sdk/src/zkEvm/sendTransaction.ts index 1a8089e0ef..425dc975ff 100644 --- a/packages/passport/sdk/src/zkEvm/sendTransaction.ts +++ b/packages/passport/sdk/src/zkEvm/sendTransaction.ts @@ -1,5 +1,5 @@ import { - JsonRpcProvider, TransactionRequest, + StaticJsonRpcProvider, TransactionRequest, } from '@ethersproject/providers'; import { BigNumber, BigNumberish } from 'ethers'; import { Signer } from '@ethersproject/abstract-signer'; @@ -15,7 +15,7 @@ const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000; export type EthSendTransactionParams = { ethSigner: Signer; - jsonRpcProvider: JsonRpcProvider; + staticJsonRpcProvider: StaticJsonRpcProvider; guardianClient: GuardianClient; relayerClient: RelayerClient; zkevmAddress: string, @@ -70,7 +70,7 @@ const getMetaTransactions = async ( export const sendTransaction = ({ params, ethSigner, - jsonRpcProvider, + staticJsonRpcProvider, relayerClient, guardianClient, zkevmAddress, @@ -81,10 +81,10 @@ export const sendTransaction = ({ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field'); } - const { chainId } = await jsonRpcProvider.ready; + const { chainId } = await staticJsonRpcProvider.ready; const chainIdBigNumber = BigNumber.from(chainId); - const nonce = await getNonce(jsonRpcProvider, zkevmAddress); + const nonce = await getNonce(staticJsonRpcProvider, zkevmAddress); const metaTransaction: MetaTransaction = { to: transactionRequest.to, data: transactionRequest.data, diff --git a/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts b/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts index b6d2fa2880..b3be8f3b56 100644 --- a/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts +++ b/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { BigNumber } from 'ethers'; import GuardianClient from 'guardian'; import { Signer } from '@ethersproject/abstract-signer'; @@ -26,7 +26,7 @@ describe('signTypedDataV4', () => { const relayerSignature = '02011b1d383526a2815d26550eb314b5d7e0551327330043c4d07715346a7d5517ecbc32304fc1ccdcd52fea386c94c3b58b90410f20cd1d5c6db8fa1f03c34e82dce78c3445ce38583e0b0689c69b8fbedbc33d3a2e45431b0103'; const combinedSignature = '0x000202011b1d383526a2815d26550eb314b5d7e0551327330043c4d07715346a7d5517ecbc32304fc1ccdcd52fea386c94c3b58b90410f20cd1d5c6db8fa1f03c34e82dce78c3445ce38583e0b0689c69b8fbedbc33d3a2e45431b01030001d25acf5eef26fb627f91e02ebd111580030ab8fb0a55567ac8cc66c34de7ae98185125a76adc6ee2fea042c7fce9c85a41e790ce3529f93dfec281bf56620ef21b02'; const ethSigner = {} as Signer; - const jsonRpcProvider = { + const staticJsonRpcProvider = { ready: Promise.resolve({ chainId }), }; const relayerClient = { @@ -56,7 +56,7 @@ describe('signTypedDataV4', () => { method: 'eth_signTypedData_v4', params: [address, JSON.stringify(eip712Payload)], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, guardianClient: guardianClient as unknown as GuardianClient, }); @@ -82,7 +82,7 @@ describe('signTypedDataV4', () => { method: 'eth_signTypedData_v4', params: [address, eip712Payload], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, guardianClient: guardianClient as any, }); @@ -109,7 +109,7 @@ describe('signTypedDataV4', () => { method: 'eth_signTypedData_v4', params: [address], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, guardianClient: guardianClient as any, }) @@ -126,7 +126,7 @@ describe('signTypedDataV4', () => { method: 'eth_signTypedData_v4', params: [address, '*~<|8)-/-<'], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, guardianClient: guardianClient as any, }) @@ -151,7 +151,7 @@ describe('signTypedDataV4', () => { method: 'eth_signTypedData_v4', params: [address, payload], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, guardianClient: guardianClient as any, }) @@ -176,7 +176,7 @@ describe('signTypedDataV4', () => { }, ], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, guardianClient: guardianClient as any, }) @@ -200,7 +200,7 @@ describe('signTypedDataV4', () => { payload, ], ethSigner, - jsonRpcProvider: jsonRpcProvider as JsonRpcProvider, + staticJsonRpcProvider: staticJsonRpcProvider as StaticJsonRpcProvider, relayerClient: relayerClient as unknown as RelayerClient, guardianClient: guardianClient as any, }); diff --git a/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts b/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts index 6f8058a826..b9db9d425e 100644 --- a/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts +++ b/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { Signer } from '@ethersproject/abstract-signer'; import { BigNumber } from 'ethers'; import GuardianClient from 'guardian'; @@ -9,7 +9,7 @@ import { RelayerClient } from './relayerClient'; export type SignTypedDataV4Params = { ethSigner: Signer; - jsonRpcProvider: JsonRpcProvider; + staticJsonRpcProvider: StaticJsonRpcProvider; relayerClient: RelayerClient; method: string; params: Array; @@ -66,7 +66,7 @@ export const signTypedDataV4 = async ({ params, method, ethSigner, - jsonRpcProvider, + staticJsonRpcProvider, relayerClient, guardianClient, }: SignTypedDataV4Params): Promise => guardianClient @@ -78,7 +78,7 @@ export const signTypedDataV4 = async ({ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `${method} requires an address and a typed data JSON`); } - const { chainId } = await jsonRpcProvider.ready; + const { chainId } = await staticJsonRpcProvider.ready; const typedData = transformTypedData(typedDataParam, chainId); await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData }); diff --git a/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.test.ts b/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.test.ts index 8702128fd0..9140e3c376 100644 --- a/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.test.ts +++ b/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.test.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { Signer } from '@ethersproject/abstract-signer'; import { signRaw } from '@imtbl/toolkit'; import { MultiRollupApiClients } from '@imtbl/generated-clients'; @@ -54,7 +54,7 @@ describe('registerZkEvmUser', () => { ethSigner: ethSignerMock as unknown as Signer, multiRollupApiClients: multiRollupApiClients as unknown as MultiRollupApiClients, accessToken, - jsonRpcProvider: jsonRPCProvider as unknown as JsonRpcProvider, + staticJsonRpcProvider: jsonRPCProvider as unknown as StaticJsonRpcProvider, })).rejects.toThrow('Failed to create counterfactual address: Error: Internal server error'); }); }); @@ -72,7 +72,7 @@ describe('registerZkEvmUser', () => { ethSigner: ethSignerMock as unknown as Signer, multiRollupApiClients: multiRollupApiClients as unknown as MultiRollupApiClients, accessToken, - jsonRpcProvider: jsonRPCProvider as unknown as JsonRpcProvider, + staticJsonRpcProvider: jsonRPCProvider as unknown as StaticJsonRpcProvider, }); expect(result).toEqual(mockUserZkEvm.zkEvm.ethAddress); diff --git a/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.ts b/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.ts index 565d09ed26..6bceac159f 100644 --- a/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.ts +++ b/packages/passport/sdk/src/zkEvm/user/registerZkEvmUser.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { MultiRollupApiClients } from '@imtbl/generated-clients'; import { signRaw } from '@imtbl/toolkit'; import { getEip155ChainId } from 'zkEvm/walletHelpers'; @@ -11,7 +11,7 @@ export type RegisterZkEvmUserInput = { ethSigner: Signer, multiRollupApiClients: MultiRollupApiClients, accessToken: string; - jsonRpcProvider: JsonRpcProvider; + staticJsonRpcProvider: StaticJsonRpcProvider; }; const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport'; @@ -21,12 +21,12 @@ export async function registerZkEvmUser({ ethSigner, multiRollupApiClients, accessToken, - jsonRpcProvider, + staticJsonRpcProvider, }: RegisterZkEvmUserInput): Promise { const [ethereumAddress, ethereumSignature, network, chainListResponse] = await Promise.all([ ethSigner.getAddress(), signRaw(MESSAGE_TO_SIGN, ethSigner), - jsonRpcProvider.ready, + staticJsonRpcProvider.ready, multiRollupApiClients.chainsApi.listChains(), ]); diff --git a/packages/passport/sdk/src/zkEvm/walletHelpers.test.ts b/packages/passport/sdk/src/zkEvm/walletHelpers.test.ts index 3e19f516bc..ca46a79964 100644 --- a/packages/passport/sdk/src/zkEvm/walletHelpers.test.ts +++ b/packages/passport/sdk/src/zkEvm/walletHelpers.test.ts @@ -1,7 +1,7 @@ import { BigNumber, Wallet, Contract, errors, } from 'ethers'; -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { getNonce, getSignedMetaTransactions, getSignedTypedData } from './walletHelpers'; import { TypedDataPayload } from './types'; @@ -120,7 +120,7 @@ describe('getSignedTypedData', () => { }); describe('getNonce', () => { - const jsonRpcProvider = {} as JsonRpcProvider; + const staticJsonRpcProvider = {} as StaticJsonRpcProvider; const nonceMock = jest.fn(); beforeEach(() => { @@ -138,7 +138,7 @@ describe('getNonce', () => { nonceMock.mockRejectedValue(error); - const result = await getNonce(jsonRpcProvider, walletAddress); + const result = await getNonce(staticJsonRpcProvider, walletAddress); expect(result).toEqual(BigNumber.from(0)); }); @@ -150,7 +150,7 @@ describe('getNonce', () => { Object.defineProperty(error, 'code', { value: errors.NETWORK_ERROR }); nonceMock.mockRejectedValue(error); - await expect(() => getNonce(jsonRpcProvider, walletAddress)).rejects.toThrow(error); + await expect(() => getNonce(staticJsonRpcProvider, walletAddress)).rejects.toThrow(error); }); }); }); @@ -159,7 +159,7 @@ describe('getNonce', () => { it('should return a number', async () => { nonceMock.mockResolvedValue(BigNumber.from(20)); - const result = await getNonce(jsonRpcProvider, walletAddress); + const result = await getNonce(staticJsonRpcProvider, walletAddress); expect(result).toEqual(BigNumber.from(20)); }); diff --git a/packages/passport/sdk/src/zkEvm/walletHelpers.ts b/packages/passport/sdk/src/zkEvm/walletHelpers.ts index ab07769eb9..6800929caa 100644 --- a/packages/passport/sdk/src/zkEvm/walletHelpers.ts +++ b/packages/passport/sdk/src/zkEvm/walletHelpers.ts @@ -7,7 +7,7 @@ import { errors, } from 'ethers'; import { walletContracts } from '@0xsequence/abi'; -import { JsonRpcProvider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { Signer } from '@ethersproject/abstract-signer'; import { v1 as sequenceCoreV1 } from '@0xsequence/core'; import { MetaTransaction, MetaTransactionNormalised, TypedDataPayload } from './types'; @@ -47,14 +47,14 @@ export function digestOfTransactionsAndNonce(nonce: BigNumberish, normalisedTran } export const getNonce = async ( - jsonRpcProvider: JsonRpcProvider, + staticJsonRpcProvider: StaticJsonRpcProvider, smartContractWalletAddress: string, ): Promise => { try { const contract = new Contract( smartContractWalletAddress, walletContracts.mainModule.abi, - jsonRpcProvider, + staticJsonRpcProvider, ); const result = await contract.nonce(); if (result instanceof BigNumber) { diff --git a/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts b/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts index 8113b489c6..105c59dfe0 100644 --- a/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts +++ b/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, Web3Provider } from '@ethersproject/providers'; import AuthManager from 'authManager'; import { ZkEvmProvider, ZkEvmProviderInput } from './zkEvmProvider'; import { sendTransaction } from './sendTransaction'; @@ -128,7 +128,7 @@ describe('ZkEvmProvider', () => { params: [transaction], guardianClient, ethSigner, - jsonRpcProvider: expect.any(Object), + staticJsonRpcProvider: expect.any(Object), relayerClient: expect.any(RelayerClient), zkevmAddress: mockUserZkEvm.zkEvm.ethAddress, }); @@ -167,7 +167,7 @@ describe('ZkEvmProvider', () => { params: [address, typedDataPayload], guardianClient, ethSigner, - jsonRpcProvider: expect.any(Object), + staticJsonRpcProvider: expect.any(Object), relayerClient: expect.any(RelayerClient), }); }); @@ -377,7 +377,7 @@ describe('ZkEvmProvider', () => { beforeEach(() => { jest.resetAllMocks(); - (JsonRpcProvider as unknown as jest.Mock).mockImplementation(() => ({ + (StaticJsonRpcProvider as unknown as jest.Mock).mockImplementation(() => ({ send: sendMock, network: Promise.resolve({ chainId: 13371, @@ -385,7 +385,7 @@ describe('ZkEvmProvider', () => { })); }); - it.each(passthroughMethods)('should passthrough %s to the jsonRpcProvider', async (method, returnValue) => { + it.each(passthroughMethods)('should passthrough %s to the staticJsonRpcProvider', async (method, returnValue) => { sendMock.mockResolvedValueOnce(returnValue); const provider = getProvider(); diff --git a/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts b/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts index 314cb69dd0..c678e89fbb 100644 --- a/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts +++ b/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, Web3Provider } from '@ethersproject/providers'; import { MultiRollupApiClients } from '@imtbl/generated-clients'; import { Signer } from '@ethersproject/abstract-signer'; import { @@ -47,7 +47,7 @@ export class ZkEvmProvider implements Provider { readonly #guardianClient: GuardianClient; - readonly #jsonRpcProvider: JsonRpcProvider; // Used for read + readonly #staticJsonRpcProvider: StaticJsonRpcProvider; // Used for read readonly #magicAdapter: MagicAdapter; @@ -83,19 +83,19 @@ export class ZkEvmProvider implements Provider { this.#guardianClient = guardianClient; if (config.crossSdkBridgeEnabled) { - // JsonRpcProvider by default sets the referrer as "client". + // StaticJsonRpcProvider by default sets the referrer as "client". // On Unreal 4 this errors as the browser used is expecting a valid URL. - this.#jsonRpcProvider = new JsonRpcProvider({ + this.#staticJsonRpcProvider = new StaticJsonRpcProvider({ url: this.#config.zkEvmRpcUrl, fetchOptions: { referrer: 'http://imtblgamesdk.local' }, }); } else { - this.#jsonRpcProvider = new JsonRpcProvider(this.#config.zkEvmRpcUrl); + this.#staticJsonRpcProvider = new StaticJsonRpcProvider(this.#config.zkEvmRpcUrl); } this.#relayerClient = new RelayerClient({ config: this.#config, - jsonRpcProvider: this.#jsonRpcProvider, + staticJsonRpcProvider: this.#staticJsonRpcProvider, authManager: this.#authManager, }); @@ -178,7 +178,7 @@ export class ZkEvmProvider implements Provider { authManager: this.#authManager, multiRollupApiClients: this.#multiRollupApiClients, accessToken: user.accessToken, - jsonRpcProvider: this.#jsonRpcProvider, + staticJsonRpcProvider: this.#staticJsonRpcProvider, }); } else { this.#zkEvmAddress = user.zkEvm.ethAddress; @@ -199,7 +199,7 @@ export class ZkEvmProvider implements Provider { params: request.params || [], ethSigner, guardianClient: this.#guardianClient, - jsonRpcProvider: this.#jsonRpcProvider, + staticJsonRpcProvider: this.#staticJsonRpcProvider, relayerClient: this.#relayerClient, zkevmAddress: this.#zkEvmAddress, }); @@ -219,7 +219,7 @@ export class ZkEvmProvider implements Provider { method: request.method, params: request.params || [], ethSigner, - jsonRpcProvider: this.#jsonRpcProvider, + staticJsonRpcProvider: this.#staticJsonRpcProvider, relayerClient: this.#relayerClient, guardianClient: this.#guardianClient, }); @@ -238,7 +238,7 @@ export class ZkEvmProvider implements Provider { case 'eth_getTransactionByHash': case 'eth_getTransactionReceipt': case 'eth_getTransactionCount': { - return this.#jsonRpcProvider.send(request.method, request.params || []); + return this.#staticJsonRpcProvider.send(request.method, request.params || []); } default: { throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');