Skip to content

Commit

Permalink
chore(bridge-ui): clean up domains (#13337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jscriptcoder authored Mar 17, 2023
1 parent 8655ff1 commit 25259a4
Show file tree
Hide file tree
Showing 38 changed files with 512 additions and 515 deletions.
44 changes: 20 additions & 24 deletions packages/bridge-ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import Home from './pages/home/Home.svelte';
import { setupI18n } from './i18n';
import { BridgeType } from './domain/bridge';
import { ETHBridge } from './eth/ETHBridge';
import { ETHBridge } from './bridge/ETHBridge';
import { ERC20Bridge } from './bridge/ERC20Bridge';
import { bridges, chainIdToTokenVaultAddress } from './store/bridge';
import { ERC20Bridge } from './erc20/ERC20Bridge';
import {
pendingTransactions,
transactioner,
Expand All @@ -28,15 +28,6 @@
import { wagmiClient } from './store/wagmi';
setupI18n({ withLocale: 'en' });
import {
chains,
CHAIN_ID_MAINNET,
CHAIN_ID_TAIKO,
CHAIN_MAINNET,
CHAIN_TKO,
mainnet,
taiko,
} from './domain/chain';
import SwitchEthereumChainModal from './components/modals/SwitchEthereumChainModal.svelte';
import { ProofService } from './proof/ProofService';
import { ethers } from 'ethers';
Expand All @@ -53,24 +44,32 @@
import { RelayerAPIService } from './relayer-api/RelayerAPIService';
import type { RelayerAPI } from './domain/relayerApi';
import { relayerApi, relayerBlockInfoMap } from './store/relayerApi';
import {
L1_CHAIN_ID,
L1_TOKEN_VAULT_ADDRESS,
L2_CHAIN_ID,
L2_TOKEN_VAULT_ADDRESS,
} from './constants/envVars';
import {
chainsRecord,
mainnetWagmiChain,
taikoWagmiChain,
} from './chain/chains';
const providerMap: Map<number, ethers.providers.JsonRpcProvider> = new Map<
number,
ethers.providers.JsonRpcProvider
>();
const providerMap = new Map<number, ethers.providers.JsonRpcProvider>();
providerMap.set(
CHAIN_ID_MAINNET,
L1_CHAIN_ID,
new ethers.providers.JsonRpcProvider(import.meta.env.VITE_L1_RPC_URL),
);
providerMap.set(
CHAIN_ID_TAIKO,
L2_CHAIN_ID,
new ethers.providers.JsonRpcProvider(import.meta.env.VITE_L2_RPC_URL),
);
providers.set(providerMap);
const { chains: wagmiChains, provider } = configureChains(
[mainnet, taiko],
[mainnetWagmiChain, taikoWagmiChain],
[
publicProvider(),
jsonRpcProvider({
Expand Down Expand Up @@ -115,11 +114,8 @@
});
chainIdToTokenVaultAddress.update((store) => {
store.set(CHAIN_TKO.id, import.meta.env.VITE_TAIKO_TOKEN_VAULT_ADDRESS);
store.set(
CHAIN_MAINNET.id,
import.meta.env.VITE_MAINNET_TOKEN_VAULT_ADDRESS,
);
store.set(L2_CHAIN_ID, L2_TOKEN_VAULT_ADDRESS);
store.set(L1_CHAIN_ID, L1_TOKEN_VAULT_ADDRESS);
return store;
});
Expand Down Expand Up @@ -221,7 +217,7 @@
if (!tx.msgHash) return;
const contract = new ethers.Contract(
chains[tx.toChainId].bridgeAddress,
chainsRecord[tx.toChainId].bridgeAddress,
BridgeABI,
provider,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { BigNumber, ethers, Wallet } from 'ethers';
import {
CHAIN_ID_MAINNET,
CHAIN_ID_TAIKO,
mainnet,
taiko,
} from '../domain/chain';
import type { ApproveOpts, Bridge, BridgeOpts } from '../domain/bridge';
import { ERC20Bridge } from './ERC20Bridge';
import { Message, MessageStatus } from '../domain/message';
import { L1_CHAIN_ID, L2_CHAIN_ID } from '../constants/envVars';

const mockSigner = {
getAddress: jest.fn(),
Expand Down Expand Up @@ -48,8 +43,8 @@ const opts: BridgeOpts = {
amountInWei: BigNumber.from(1),
signer: wallet,
tokenAddress: '0xtoken',
fromChainId: mainnet.id,
toChainId: taiko.id,
fromChainId: L1_CHAIN_ID,
toChainId: L2_CHAIN_ID,
tokenVaultAddress: '0x456',
processingFeeInWei: BigNumber.from(2),
memo: 'memo',
Expand Down Expand Up @@ -226,8 +221,8 @@ describe('bridge tests', () => {
amountInWei: BigNumber.from(1),
signer: wallet,
tokenAddress: '0xtoken',
fromChainId: mainnet.id,
toChainId: taiko.id,
fromChainId: L1_CHAIN_ID,
toChainId: L2_CHAIN_ID,
tokenVaultAddress: '0x456',
to: await wallet.getAddress(),
};
Expand Down Expand Up @@ -261,8 +256,8 @@ describe('bridge tests', () => {
await expect(
bridge.Claim({
message: {
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
gasLimit: BigNumber.from(1),
} as unknown as Message,
msgHash: '0x',
Expand All @@ -285,8 +280,8 @@ describe('bridge tests', () => {
await expect(
bridge.Claim({
message: {
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
gasLimit: BigNumber.from(1),
} as unknown as Message,
msgHash: '0x',
Expand Down Expand Up @@ -314,8 +309,8 @@ describe('bridge tests', () => {
bridge.Claim({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
gasLimit: BigNumber.from(1),
} as unknown as Message,
msgHash: '0x',
Expand Down Expand Up @@ -348,8 +343,8 @@ describe('bridge tests', () => {
await bridge.Claim({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down Expand Up @@ -384,8 +379,8 @@ describe('bridge tests', () => {
await bridge.Claim({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down Expand Up @@ -421,8 +416,8 @@ describe('bridge tests', () => {
bridge.ReleaseTokens({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down Expand Up @@ -456,8 +451,8 @@ describe('bridge tests', () => {
await bridge.ReleaseTokens({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ERC20 from '../constants/abi/ERC20';
import type { Prover } from '../domain/proof';
import { MessageStatus } from '../domain/message';
import BridgeABI from '../constants/abi/Bridge';
import { chains } from '../domain/chain';
import { chainsRecord } from '../chain/chains';

export class ERC20Bridge implements Bridge {
private readonly prover: Prover;
Expand Down Expand Up @@ -179,9 +179,9 @@ export class ERC20Bridge implements Bridge {
srcBridgeAddress: opts.srcBridgeAddress,
destChain: opts.message.destChainId.toNumber(),
destHeaderSyncAddress:
chains[opts.message.destChainId.toNumber()].headerSyncAddress,
chainsRecord[opts.message.destChainId.toNumber()].headerSyncAddress,
srcSignalServiceAddress:
chains[opts.message.srcChainId.toNumber()].signalServiceAddress,
chainsRecord[opts.message.srcChainId.toNumber()].signalServiceAddress,
});

if (opts.message.gasLimit.gt(BigNumber.from(2500000))) {
Expand Down Expand Up @@ -224,9 +224,9 @@ export class ERC20Bridge implements Bridge {
destBridgeAddress: opts.destBridgeAddress,
destChain: opts.message.destChainId.toNumber(),
destHeaderSyncAddress:
chains[opts.message.destChainId.toNumber()].headerSyncAddress,
chainsRecord[opts.message.destChainId.toNumber()].headerSyncAddress,
srcHeaderSyncAddress:
chains[opts.message.srcChainId.toNumber()].headerSyncAddress,
chainsRecord[opts.message.srcChainId.toNumber()].headerSyncAddress,
};

const proof = await this.prover.GenerateReleaseProof(proofOpts);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { BigNumber, ethers, Wallet } from 'ethers';
import {
CHAIN_ID_MAINNET,
CHAIN_ID_TAIKO,
mainnet,
taiko,
} from '../domain/chain';
import type { Bridge, BridgeOpts } from '../domain/bridge';
import { ETHBridge } from './ETHBridge';
import { Message, MessageStatus } from '../domain/message';
import { L1_CHAIN_ID, L2_CHAIN_ID } from '../constants/envVars';

const mockSigner = {
getAddress: jest.fn(),
Expand Down Expand Up @@ -79,8 +74,8 @@ describe('bridge tests', () => {
amountInWei: BigNumber.from(1),
signer: wallet,
tokenAddress: '',
fromChainId: mainnet.id,
toChainId: taiko.id,
fromChainId: L1_CHAIN_ID,
toChainId: L2_CHAIN_ID,
tokenVaultAddress: '0x456',
processingFeeInWei: BigNumber.from(2),
memo: 'memo',
Expand Down Expand Up @@ -113,8 +108,8 @@ describe('bridge tests', () => {
amountInWei: BigNumber.from(1),
signer: wallet,
tokenAddress: '',
fromChainId: mainnet.id,
toChainId: taiko.id,
fromChainId: L1_CHAIN_ID,
toChainId: L2_CHAIN_ID,
tokenVaultAddress: '0x456',
to: await wallet.getAddress(),
};
Expand Down Expand Up @@ -143,8 +138,8 @@ describe('bridge tests', () => {
await expect(
bridge.Claim({
message: {
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
gasLimit: BigNumber.from(1),
} as unknown as Message,
msgHash: '0x',
Expand Down Expand Up @@ -172,8 +167,8 @@ describe('bridge tests', () => {
bridge.Claim({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
gasLimit: BigNumber.from(1),
} as unknown as Message,
msgHash: '0x',
Expand Down Expand Up @@ -206,8 +201,8 @@ describe('bridge tests', () => {
await bridge.Claim({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down Expand Up @@ -242,8 +237,8 @@ describe('bridge tests', () => {
await bridge.Claim({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down Expand Up @@ -279,8 +274,8 @@ describe('bridge tests', () => {
bridge.ReleaseTokens({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down Expand Up @@ -314,8 +309,8 @@ describe('bridge tests', () => {
await bridge.ReleaseTokens({
message: {
owner: '0x',
srcChainId: BigNumber.from(CHAIN_ID_TAIKO),
destChainId: BigNumber.from(CHAIN_ID_MAINNET),
srcChainId: BigNumber.from(L2_CHAIN_ID),
destChainId: BigNumber.from(L1_CHAIN_ID),
sender: '0x01',
gasLimit: BigNumber.from(1),
} as unknown as Message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TokenVault from '../constants/abi/TokenVault';
import type { Prover } from '../domain/proof';
import { MessageStatus } from '../domain/message';
import BridgeABI from '../constants/abi/Bridge';
import { chains } from '../domain/chain';
import { chainsRecord } from '../chain/chains';

export class ETHBridge implements Bridge {
private readonly prover: Prover;
Expand Down Expand Up @@ -127,9 +127,9 @@ export class ETHBridge implements Bridge {
srcBridgeAddress: opts.srcBridgeAddress,
destChain: opts.message.destChainId.toNumber(),
destHeaderSyncAddress:
chains[opts.message.destChainId.toNumber()].headerSyncAddress,
chainsRecord[opts.message.destChainId.toNumber()].headerSyncAddress,
srcSignalServiceAddress:
chains[opts.message.srcChainId.toNumber()].signalServiceAddress,
chainsRecord[opts.message.srcChainId.toNumber()].signalServiceAddress,
};

const proof = await this.prover.GenerateProof(proofOpts);
Expand Down Expand Up @@ -168,9 +168,9 @@ export class ETHBridge implements Bridge {
destBridgeAddress: opts.destBridgeAddress,
destChain: opts.message.destChainId.toNumber(),
destHeaderSyncAddress:
chains[opts.message.destChainId.toNumber()].headerSyncAddress,
chainsRecord[opts.message.destChainId.toNumber()].headerSyncAddress,
srcHeaderSyncAddress:
chains[opts.message.srcChainId.toNumber()].headerSyncAddress,
chainsRecord[opts.message.srcChainId.toNumber()].headerSyncAddress,
};

const proof = await this.prover.GenerateReleaseProof(proofOpts);
Expand Down
Loading

0 comments on commit 25259a4

Please sign in to comment.