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-v2): allow bridging to all layers #14525

Merged
merged 74 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
2f3df42
feat(bridge-ui-v2): enable L3 chain selection
KorbinianK Aug 15, 2023
57cb45a
add address mapping for multiple layer configs
KorbinianK Aug 16, 2023
65787ba
Merge remote-tracking branch 'origin/main' into feat/bridge-ui-v2--mu…
KorbinianK Aug 16, 2023
5756d28
additional logic of finding the crosschain address
KorbinianK Aug 16, 2023
810c37d
linting
KorbinianK Aug 16, 2023
ecef0be
feat(bridge-ui-v2): added custom vite plugin to generate config
KorbinianK Aug 21, 2023
a55eb1d
linting
KorbinianK Aug 21, 2023
369d447
add chainIcon
KorbinianK Aug 21, 2023
275d612
gitignore
KorbinianK Aug 21, 2023
2450745
gitignore
KorbinianK Aug 21, 2023
7ff589f
add dynamic chainicons
KorbinianK Aug 21, 2023
745b7d3
update readme
KorbinianK Aug 21, 2023
636d7a7
fix: network change updating the store when there is no change
KorbinianK Aug 22, 2023
2e6bb3f
only enable valid combinations in chainselector
KorbinianK Aug 23, 2023
582ad91
separate configs, begin on relayer config
KorbinianK Aug 24, 2023
5341e44
Merge remote-tracking branch 'origin/main' into feat/bridge-ui-v2--mu…
KorbinianK Aug 24, 2023
45e29b5
add relayer config
KorbinianK Aug 24, 2023
24ae89b
added preconfigured token via new config, removed more env variable uses
KorbinianK Aug 25, 2023
0cefd46
make only preconfigured tokens mintable
KorbinianK Aug 25, 2023
b46a991
cleanup types for config generation
KorbinianK Aug 25, 2023
bd7a542
fix using layertype
KorbinianK Aug 25, 2023
0d97efa
add fetching from all relayers
KorbinianK Aug 25, 2023
f2e4095
add schema validation, export config as base64 to .env
KorbinianK Aug 28, 2023
9d6e974
linting
KorbinianK Aug 28, 2023
9d37efc
update readme and example .env
KorbinianK Aug 29, 2023
6d82a24
linting
KorbinianK Aug 29, 2023
d75bff7
Merge remote-tracking branch 'origin/main' into feat/bridge-ui-v2--mu…
KorbinianK Aug 30, 2023
2c6f1b5
Merge remote-tracking branch 'origin/main' into feat/bridge-ui-v2--mu…
KorbinianK Aug 30, 2023
8376131
fix merge
KorbinianK Aug 30, 2023
c2ccb3a
revert auto lint to match main
KorbinianK Aug 30, 2023
7302232
revert auto lint to match main
KorbinianK Aug 30, 2023
969f25f
refactor config plugins
KorbinianK Aug 30, 2023
57bac32
prep for new contracts
KorbinianK Aug 30, 2023
01b32ea
adjustments for new contracts
KorbinianK Aug 30, 2023
799e26e
trimming whitespace for export, style fix for amount alert
KorbinianK Aug 30, 2023
83f2ecc
update readme
KorbinianK Aug 30, 2023
6fe5aac
fix token dropdown for custom tokens
KorbinianK Aug 30, 2023
172bf9b
fix claiming
KorbinianK Aug 30, 2023
53953c6
fix status, fix fetching correct addresses
KorbinianK Aug 31, 2023
d7117c6
update pnpm-lock.yaml
KorbinianK Aug 31, 2023
e750324
change tsconfig paths
KorbinianK Aug 31, 2023
23016ae
fix icons
KorbinianK Aug 31, 2023
a56efe1
adjust custom token dialog
KorbinianK Aug 31, 2023
39dfa87
fix balance color
KorbinianK Aug 31, 2023
c2b2697
fix crosschain address detection
KorbinianK Sep 1, 2023
c46899a
tsconfig push
KorbinianK Sep 1, 2023
da20edc
tsconfig
KorbinianK Sep 1, 2023
2828eff
fix processable check using wrong bridge
KorbinianK Sep 1, 2023
772c73c
Merge remote-tracking branch 'origin/main' into feat/bridge-ui-v2--mu…
KorbinianK Sep 1, 2023
3e5927c
updated mobile dialog on activities, some design fixes
KorbinianK Sep 4, 2023
29b13dd
export config via js now, fix chrosschain address search
KorbinianK Sep 4, 2023
31a10b3
revert switching chains for proof
KorbinianK Sep 4, 2023
73bba4f
Merge remote-tracking branch 'origin/main' into feat/bridge-ui-v2--mu…
KorbinianK Sep 4, 2023
8905825
update config export script
KorbinianK Sep 5, 2023
437f96e
catching offline relayer
KorbinianK Sep 5, 2023
3c7198f
fix(bridge-ui-v2): fix dest chain issues (#14650)
jscriptcoder Sep 5, 2023
57378af
Merge branch 'main' into feat/bridge-ui-v2--multi-layer-bridging
KorbinianK Sep 5, 2023
18849c8
fix chainselector colors
KorbinianK Sep 5, 2023
9b5c31d
cleanup
KorbinianK Sep 5, 2023
45b7493
Merge branch 'main' into feat/bridge-ui-v2--multi-layer-bridging
KorbinianK Sep 6, 2023
c3857c7
update lockfile
KorbinianK Sep 6, 2023
517484e
remove repeated declaration
jscriptcoder Sep 6, 2023
1377718
i18n
jscriptcoder Sep 6, 2023
e0327b9
fix relayer using old message params
KorbinianK Sep 6, 2023
aa1db75
Merge branch 'feat/bridge-ui-v2--multi-layer-bridging' of https://git…
KorbinianK Sep 6, 2023
7a4af7a
sorting
KorbinianK Sep 6, 2023
818e220
relayerAPI mapping wrong contracts for tokentype
KorbinianK Sep 6, 2023
6311b38
style for bridge button and spinner
KorbinianK Sep 6, 2023
f0584b9
fix mobile status dialog not being full width
KorbinianK Sep 6, 2023
703c968
fix erc20 claiming by corretly using the decoded hex data
KorbinianK Sep 6, 2023
e7593ef
adjust dialog loading mask, catching error
KorbinianK Sep 6, 2023
bcb209a
re-added relayer baseurl
KorbinianK Sep 6, 2023
f653149
fix chainselector colors
KorbinianK Sep 6, 2023
3f2ea48
Merge branch 'main' into feat/bridge-ui-v2--multi-layer-bridging
dantaik Sep 7, 2023
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
28 changes: 16 additions & 12 deletions packages/bridge-ui-v2/src/components/Bridge/Bridge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
MessageStatus,
} from '$libs/bridge';
import type { ERC20Bridge } from '$libs/bridge/ERC20Bridge';
import { chainContractsMap, chains, chainUrlMap } from '$libs/chain';
import { chains, chainUrlMap, routingContractsMap } from '$libs/chain';
import {
ApproveError,
InsufficientAllowanceError,
Expand All @@ -45,11 +45,10 @@
let recipientComponent: Recipient;
let processingFeeComponent: ProcessingFee;

function onNetworkChange(network: Network) {
if (network && chains.length === 2) {
// If there are only two chains, the destination chain will be the other one
const otherChain = chains.find((chain) => chain.id !== network.id);

function onNetworkChange(newNetwork: Network, oldNetwork: Network) {
// since we just show two networks we simply swap them
if (newNetwork) {
const otherChain = oldNetwork;
if (otherChain) destNetwork.set(otherChain);
}
}
Expand Down Expand Up @@ -81,7 +80,7 @@
throw new Error('token address not found');
}

const spenderAddress = chainContractsMap[$network.id].tokenVaultAddress;
const spenderAddress = routingContractsMap[$network.id][$destNetwork.id].erc20VaultAddress;

const txHash = await erc20Bridge.approve({
tokenAddress,
Expand Down Expand Up @@ -156,7 +155,7 @@
case TokenType.ETH: {
// Specific arguments for ETH bridge:
// - bridgeAddress
const bridgeAddress = chainContractsMap[$network.id].bridgeAddress;
const bridgeAddress = routingContractsMap[$network.id][$destNetwork.id].bridgeAddress;
bridgeArgs = { ...bridgeArgs, bridgeAddress } as ETHBridgeArgs;
break;
}
Expand All @@ -176,7 +175,7 @@
throw new Error('token address not found');
}

const tokenVaultAddress = chainContractsMap[$network.id].tokenVaultAddress;
const tokenVaultAddress = routingContractsMap[$network.id][$destNetwork.id].erc20VaultAddress;

const isTokenAlreadyDeployed = await isDeployedCrossChain({
token: $selectedToken,
Expand All @@ -192,7 +191,12 @@
} as ERC20BridgeArgs;
break;
}

case TokenType.ERC721:
// todo: implement
break;
case TokenType.ERC1155:
// todo: implement
break;
default:
throw new Error('invalid token type');
}
Expand Down Expand Up @@ -280,12 +284,12 @@
<Card class="w-full md:w-[524px]" title={$t('bridge.title.default')} text={$t('bridge.description')}>
<div class="space-y-[35px]">
<div class="f-between-center gap-4">
<ChainSelector class="flex-1 " value={$network} switchWallet />
<ChainSelector class="flex-1 " bind:value={$network} switchWallet />

<SwitchChainsButton />

<!-- TODO: should not be readOnly when multiple layers -->
<ChainSelector class="flex-1" value={$destNetwork} readOnly />
<ChainSelector class="flex-1" bind:value={$destNetwork} />
</div>

<TokenDropdown {tokens} bind:value={$selectedToken} />
Expand Down
9 changes: 9 additions & 0 deletions packages/bridge-ui-v2/src/components/Icon/L3.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
export let size = 20;
export let width = size;
export let height = size;
</script>

<svg {width} {height} viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<!-- Todo -->
</svg>
1 change: 1 addition & 0 deletions packages/bridge-ui-v2/src/components/Icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default as BllIcon } from './BLL.svelte';
export { default as EthIcon } from './ETH.svelte';
export { default as HorseIcon } from './HORSE.svelte';
export { default as Icon, type IconType } from './Icon.svelte';
export { default as TaikoL3Icon } from './L3.svelte';
export { default as TaikoIcon } from './Taiko.svelte';
6 changes: 3 additions & 3 deletions packages/bridge-ui-v2/src/libs/bridge/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getContract, type GetContractResult, type WalletClient } from '@wagmi/c
import { type Hash, UserRejectedRequestError } from 'viem';

import { bridgeABI } from '$abi';
import { chainContractsMap } from '$libs/chain';
import { routingContractsMap } from '$libs/chain';
import { MessageStatusError, RetryError, WrongChainError, WrongOwnerError } from '$libs/error';
import type { BridgeProver } from '$libs/proof';
import { getLogger } from '$libs/util/logger';
Expand Down Expand Up @@ -42,7 +42,7 @@ export abstract class Bridge {
throw new WrongOwnerError('user cannot process this as it is not their message');
}

const destBridgeAddress = chainContractsMap[connectedChainId].bridgeAddress;
const destBridgeAddress = routingContractsMap[connectedChainId][destChainId].bridgeAddress;

const destBridgeContract = getContract({
address: destBridgeAddress,
Expand Down Expand Up @@ -93,7 +93,7 @@ export abstract class Bridge {

// Before releasing we need to make sure the message has failed
const destChainId = Number(message.destChainId);
const destBridgeAddress = chainContractsMap[destChainId].bridgeAddress;
const destBridgeAddress = routingContractsMap[srcChainId][destChainId].bridgeAddress;

const destBridgeContract = getContract({
address: destBridgeAddress,
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/ERC20Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UserRejectedRequestError } from 'viem';

import { erc20ABI, tokenVaultABI } from '$abi';
import { bridgeService } from '$config';
import { chainContractsMap } from '$libs/chain';
import { routingContractsMap } from '$libs/chain';
import {
ApproveError,
InsufficientAllowanceError,
Expand Down Expand Up @@ -238,7 +238,7 @@ export class ERC20Bridge extends Bridge {

const proof = await this._prover.generateProofToRelease(msgHash, srcChainId, destChainId);

const srcTokenVaultAddress = chainContractsMap[connectedChainId].tokenVaultAddress;
const srcTokenVaultAddress = routingContractsMap[connectedChainId][destChainId].erc20VaultAddress;
const srcTokenVaultContract = getContract({
walletClient: wallet,
abi: tokenVaultABI,
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/ETHBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UserRejectedRequestError } from 'viem';

import { bridgeABI } from '$abi';
import { bridgeService } from '$config';
import { chainContractsMap } from '$libs/chain';
import { routingContractsMap } from '$libs/chain';
import { ProcessMessageError, ReleaseError, SendMessageError } from '$libs/error';
import type { BridgeProver } from '$libs/proof';
import { getLogger } from '$libs/util/logger';
Expand Down Expand Up @@ -149,7 +149,7 @@ export class ETHBridge extends Bridge {

const proof = await this._prover.generateProofToRelease(msgHash, srcChainId, destChainId);

const srcBridgeAddress = chainContractsMap[connectedChainId].bridgeAddress;
const srcBridgeAddress = routingContractsMap[connectedChainId][destChainId].bridgeAddress;
const srcBridgeContract = getContract({
walletClient: wallet,
abi: bridgeABI,
Expand Down
11 changes: 5 additions & 6 deletions packages/bridge-ui-v2/src/libs/bridge/checkBalanceToBridge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getPublicClient } from '@wagmi/core';
import { type Address, zeroAddress } from 'viem';

import { chainContractsMap } from '$libs/chain';
import { routingContractsMap } from '$libs/chain';
import { InsufficientAllowanceError, InsufficientBalanceError, RevertedWithFailedError } from '$libs/error';
import { getAddress, type Token, TokenType } from '$libs/token';
import { isDeployedCrossChain } from '$libs/token/isDeployedCrossChain';
Expand Down Expand Up @@ -44,8 +44,7 @@ export async function checkBalanceToBridge({
} as BridgeArgs;

if (token.type === TokenType.ETH) {
const { bridgeAddress } = chainContractsMap[srcChainId];

const { bridgeAddress } = routingContractsMap[srcChainId][destChainId];
try {
estimatedCost = await estimateCostOfBridging(bridges.ETH, {
...bridgeArgs,
Expand All @@ -67,7 +66,7 @@ export async function checkBalanceToBridge({
throw new InsufficientBalanceError('you do not have enough balance to bridge');
}
} else {
const { tokenVaultAddress } = chainContractsMap[srcChainId];
const { erc20VaultAddress } = routingContractsMap[srcChainId][destChainId];
const tokenAddress = await getAddress({ token, srcChainId, destChainId });

// since we are briding a token, we need the ETH balance of the wallet
Expand All @@ -84,7 +83,7 @@ export async function checkBalanceToBridge({
amount,
tokenAddress,
ownerAddress: wallet.account.address,
spenderAddress: tokenVaultAddress,
spenderAddress: erc20VaultAddress,
});

if (allowance) {
Expand All @@ -105,7 +104,7 @@ export async function checkBalanceToBridge({
estimatedCost = await estimateCostOfBridging(bridges.ERC20, {
...bridgeArgs,
tokenAddress,
tokenVaultAddress,
tokenVaultAddress: erc20VaultAddress,
isTokenAlreadyDeployed,
} as ERC20BridgeArgs);
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/getMaxAmountToBridge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Address } from 'viem';

import { chainContractsMap } from '$libs/chain';
import { routingContractsMap } from '$libs/chain';
import { type Token, TokenType } from '$libs/token';
import { getConnectedWallet } from '$libs/util/getConnectedWallet';
import { getLogger } from '$libs/util/logger';
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function getMaxAmountToBridge({
}

const wallet = await getConnectedWallet();
const { bridgeAddress } = chainContractsMap[srcChainId];
const { bridgeAddress } = routingContractsMap[srcChainId][destChainId];

const bridgeArgs = {
to,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getContract } from '@wagmi/core';

import { crossChainSyncABI } from '$abi';
import { chainContractsMap } from '$libs/chain';
import { routingContractsMap } from '$libs/chain';
import { publicClient } from '$libs/wagmi';

import { type BridgeTransaction, MessageStatus } from './types';
Expand All @@ -19,7 +19,7 @@ export async function isTransactionProcessable(bridgeTx: BridgeTransaction) {
// TODO: do better job here as this is to make the UI happy
if (status !== MessageStatus.NEW) return true;

const destCrossChainSyncAddress = chainContractsMap[Number(destChainId)].crossChainSyncAddress;
const destCrossChainSyncAddress = routingContractsMap[Number(srcChainId)][Number(destChainId)].crossChainSyncAddress;

try {
const destCrossChainSyncContract = getContract({
Expand Down
5 changes: 3 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/messageStatusPoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { EventEmitter } from 'events';

import { bridgeABI } from '$abi';
import { bridgeTransactionPoller } from '$config';
import { chainContractsMap } from '$libs/chain';
import { routingContractsMap } from '$libs/chain';
import { BridgeTxPollingError } from '$libs/error';
import { getLogger } from '$libs/util/logger';
import { nextTick } from '$libs/util/nextTick';

import { srcChain } from './../../../../pos-dashboard/src/store/chain';
import { isTransactionProcessable } from './isTransactionProcessable';
import { type BridgeTransaction, MessageStatus } from './types';

Expand Down Expand Up @@ -64,7 +65,7 @@ export function startPolling(bridgeTx: BridgeTransaction, runImmediately = false
let interval = hashIntervalMap[hash];

// We are gonna be polling the destination bridge contract
const destBridgeAddress = chainContractsMap[Number(destChainId)].bridgeAddress;
const destBridgeAddress = routingContractsMap[Number(srcChain)][Number(destChainId)].bridgeAddress;
const destBridgeContract = getContract({
address: destBridgeAddress,
abi: bridgeABI,
Expand Down
Loading
Loading