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

feat(bridge-ui): switch to using StaticJsonRpcProvider #13482

Merged
merged 4 commits into from
Mar 28, 2023
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
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
);
successToast('Transaction completed!');
let s = store;
s = s.slice(confirmedPendingTxIndex, 0);
s.splice(confirmedPendingTxIndex, 1);
pendingTransactions.set(s);
})();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui/src/bridge/ERC20Bridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe('bridge tests', () => {
srcBridgeAddress: '0x',
destBridgeAddress: '0x',
signer: wallet,
destProvider: new ethers.providers.JsonRpcProvider(),
destProvider: new ethers.providers.StaticJsonRpcProvider(),
srcTokenVaultAddress: '0x',
}),
).rejects.toThrowError('message already processed');
Expand Down Expand Up @@ -462,7 +462,7 @@ describe('bridge tests', () => {
srcBridgeAddress: '0x',
destBridgeAddress: '0x',
signer: wallet,
destProvider: new ethers.providers.JsonRpcProvider(),
destProvider: new ethers.providers.StaticJsonRpcProvider(),
srcTokenVaultAddress: '0x',
});

Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui/src/bridge/ETHBridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ describe('bridge tests', () => {
srcBridgeAddress: '0x',
destBridgeAddress: '0x',
signer: wallet,
destProvider: new ethers.providers.JsonRpcProvider(),
destProvider: new ethers.providers.StaticJsonRpcProvider(),
srcTokenVaultAddress: '0x',
}),
).rejects.toThrowError('message already processed');
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('bridge tests', () => {
srcBridgeAddress: '0x',
destBridgeAddress: '0x',
signer: wallet,
destProvider: new ethers.providers.JsonRpcProvider(),
destProvider: new ethers.providers.StaticJsonRpcProvider(),
srcTokenVaultAddress: '0x',
});

Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui/src/components/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@
providers[chains[transaction.toChainId].id],
);

transaction.status = await contract.getMessageStatus(transaction.msgHash);

if (transaction.receipt && transaction.receipt.status !== 1) {
clearInterval(interval);
return;
}

transaction.status = await contract.getMessageStatus(transaction.msgHash);

if (transaction.status === MessageStatus.Failed) {
if (transaction.message?.data !== '0x') {
const srcTokenVaultContract = new ethers.Contract(
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/proof/ProofService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const destChain = 31336;
const map = {
[srcChain]: mockProvider,
[destChain]: mockProvider,
} as unknown as Record<string, ethers.providers.JsonRpcProvider>;
} as unknown as Record<string, ethers.providers.StaticJsonRpcProvider>;

describe('prover tests', () => {
beforeEach(() => {
Expand Down
11 changes: 8 additions & 3 deletions packages/bridge-ui/src/proof/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import type {
} from '../domain/proof';

export class ProofService implements Prover {
private readonly providers: Record<number, ethers.providers.JsonRpcProvider>;
private readonly providers: Record<
number,
ethers.providers.StaticJsonRpcProvider
>;

constructor(providers: Record<number, ethers.providers.JsonRpcProvider>) {
constructor(
providers: Record<number, ethers.providers.StaticJsonRpcProvider>,
) {
this.providers = providers;
}

Expand All @@ -29,7 +34,7 @@ export class ProofService implements Prover {

private static async getBlockAndBlockHeader(
contract: ethers.Contract,
provider: ethers.providers.JsonRpcProvider,
provider: ethers.providers.StaticJsonRpcProvider,
): Promise<{ block: Block; blockHeader: BlockHeader }> {
const latestSyncedHeader = await contract.getLatestSyncedHeader();

Expand Down
15 changes: 12 additions & 3 deletions packages/bridge-ui/src/provider/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { ethers } from 'ethers';
import type { ChainID } from '../domain/chain';
import { L1_CHAIN_ID, L1_RPC, L2_CHAIN_ID, L2_RPC } from '../constants/envVars';

export const providers: Record<ChainID, ethers.providers.JsonRpcProvider> = {
[L1_CHAIN_ID]: new ethers.providers.JsonRpcProvider(L1_RPC),
[L2_CHAIN_ID]: new ethers.providers.JsonRpcProvider(L2_RPC),
export const providers: Record<
ChainID,
ethers.providers.StaticJsonRpcProvider
> = {
[L1_CHAIN_ID]: new ethers.providers.StaticJsonRpcProvider(
L1_RPC,
L1_CHAIN_ID,
),
[L2_CHAIN_ID]: new ethers.providers.StaticJsonRpcProvider(
L2_RPC,
L2_CHAIN_ID,
),
};
7 changes: 5 additions & 2 deletions packages/bridge-ui/src/relayer-api/RelayerAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import { tokenVaults } from '../vault/tokenVaults';
import type { ChainID } from '../domain/chain';

export class RelayerAPIService implements RelayerAPI {
private readonly providers: Record<ChainID, ethers.providers.JsonRpcProvider>;
private readonly providers: Record<
ChainID,
ethers.providers.StaticJsonRpcProvider
>;
private readonly baseUrl: string;

constructor(
baseUrl: string,
providers: Record<ChainID, ethers.providers.JsonRpcProvider>,
providers: Record<ChainID, ethers.providers.StaticJsonRpcProvider>,
) {
this.providers = providers;

Expand Down
7 changes: 5 additions & 2 deletions packages/bridge-ui/src/storage/StorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import type { ChainID } from '../domain/chain';

export class StorageService implements Transactioner {
private readonly storage: Storage;
private readonly providers: Record<ChainID, ethers.providers.JsonRpcProvider>;
private readonly providers: Record<
ChainID,
ethers.providers.StaticJsonRpcProvider
>;

constructor(
storage: Storage,
providers: Record<ChainID, ethers.providers.JsonRpcProvider>,
providers: Record<ChainID, ethers.providers.StaticJsonRpcProvider>,
) {
this.storage = storage;
this.providers = providers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Token } from '../domain/token';

export const checkIfTokenIsDeployedCrossChain = async (
token: Token,
provider: ethers.providers.JsonRpcProvider,
provider: ethers.providers.StaticJsonRpcProvider,
destTokenVaultAddress: string,
toChain: Chain,
fromChain: Chain,
Expand Down