Skip to content

Commit

Permalink
feat(bridge-ui-v2): L2 <-> L2 bridging with multi-hop (#15395)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaodino <[email protected]>
  • Loading branch information
dantaik and xiaodino authored Dec 19, 2023
1 parent 8cb9a64 commit 79c44d7
Show file tree
Hide file tree
Showing 17 changed files with 280 additions and 150 deletions.
2 changes: 1 addition & 1 deletion packages/bridge-ui-v2/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export PUBLIC_WALLETCONNECT_PROJECT_ID=""

# Enable NFT Bridge ("true" or "false")
export PUBLIC_NFT_BRIDGE_ENABLED=""
PUBLIC_NFT_BATCH_TRANSFERS_ENABLED=""
export PUBLIC_NFT_BATCH_TRANSFERS_ENABLED=""

# Sentry
export PUBLIC_SENTRY_DSN=https://
Expand Down
18 changes: 16 additions & 2 deletions packages/bridge-ui-v2/config/sample/configuredBridges.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@
"erc721VaultAddress": "",
"erc1155VaultAddress": "",
"crossChainSyncAddress": "",
"signalServiceAddress": ""
"signalServiceAddress": "",
"hops": [
{
"chaind: ,
"crossChainSyncAddress": "",
"signalServiceAddress": "",
}
]
}
},
{
Expand All @@ -45,7 +52,14 @@
"erc721VaultAddress": "",
"erc1155VaultAddress": "",
"crossChainSyncAddress": "",
"signalServiceAddress": ""
"signalServiceAddress": "",
"hops": [
{
"chaind: ,
"crossChainSyncAddress": "",
"signalServiceAddress": "",
}
]
}
}
]
Expand Down
19 changes: 19 additions & 0 deletions packages/bridge-ui-v2/config/schemas/configuredBridges.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
},
"signalServiceAddress": {
"type": "string"
},
"hops": {
"type": "array",
"default": [],
"items": {
"type": "object",
"properties": {
"chainId": {
"type": "number"
},
"crossChainSyncAddress": {
"type": "string"
},
"signalServiceAddress": {
"type": "string"
}
},
"required": ["chainId", "crossChainSyncAddress", "signalServiceAddress"]
}
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ async function buildBridgeConfig(sourceFile: SourceFile, configuredBridgesConfig
}

const _formatObjectToTsLiteral = (obj: RoutingMap): string => {
const formatValue = (value: string | number | boolean | null): string => {
const formatValue = (value: string | number | boolean | null | object): string => {
if (typeof value === 'string') {
return `"${value}"`;
}
if (typeof value === 'object') {
return JSON.stringify(value);
}
return String(value);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function generateChainConfig() {
const isValid = validateJsonAgainstSchema(configuredChainsConfigFile, configuredChainsSchema);

if (!isValid) {
throw new Error('encoded configuredBridges.json is not valid.');
throw new Error('encoded configuredChains.json is not valid.');
}
} else {
configuredChainsConfigFile = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function generateCustomTokenConfig() {
const isValid = validateJsonAgainstSchema(configuredTokenConfigFile, configuredChainsSchema);

if (!isValid) {
throw new Error('encoded configuredBridges.json is not valid.');
throw new Error('encoded generateCustomTokenConfig.json is not valid.');
}
}
const tsFilePath = path.resolve(outputPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function generateEventIndexerConfig() {
// Valide JSON against schema
const isValid = validateJsonAgainstSchema(configuredEventIndexerConfigFile, configuredEventIndexerSchema);
if (!isValid) {
throw new Error('encoded configuredBridges.json is not valid.');
throw new Error('encoded configuredEventIndexer.json is not valid.');
}
}
// Path to where you want to save the generated Typ eScript file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function generateRelayerConfig() {
// Valide JSON against schema
const isValid = validateJsonAgainstSchema(configuredRelayerConfigFile, configuredRelayerSchema);
if (!isValid) {
throw new Error('encoded configuredBridges.json is not valid.');
throw new Error('encoded configuredRelayer.json is not valid.');
}
}
// Path to where you want to save the generated Typ eScript file
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge-ui-v2/src/libs/bridge/ERC1155Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export class ERC1155Bridge extends Bridge {
const {
to,
wallet,
srcChainId,
destChainId,
token,
fee,
Expand All @@ -214,6 +215,7 @@ export class ERC1155Bridge extends Bridge {
: BigInt(0);

const sendERC1155Args: NFTBridgeTransferOp = {
srcChainId: BigInt(srcChainId),
destChainId: BigInt(destChainId),
to,
token,
Expand Down
14 changes: 13 additions & 1 deletion packages/bridge-ui-v2/src/libs/bridge/ERC20Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ const log = getLogger('ERC20Bridge');

export class ERC20Bridge extends Bridge {
private static async _prepareTransaction(args: ERC20BridgeArgs) {
const { to, amount, wallet, destChainId, token, fee, tokenVaultAddress, isTokenAlreadyDeployed, memo = '' } = args;
const {
to,
amount,
wallet,
srcChainId,
destChainId,
token,
fee,
tokenVaultAddress,
isTokenAlreadyDeployed,
memo = '',
} = args;

const tokenVaultContract = getContract({
walletClient: wallet,
Expand All @@ -49,6 +60,7 @@ export class ERC20Bridge extends Bridge {
: BigInt(0);

const sendERC20Args: BridgeTransferOp = {
srcChainId: BigInt(srcChainId),
destChainId: BigInt(destChainId),
to,
token,
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge-ui-v2/src/libs/bridge/ERC721Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export class ERC721Bridge extends Bridge {
const {
to,
wallet,
srcChainId,
destChainId,
token,
fee,
Expand All @@ -220,6 +221,7 @@ export class ERC721Bridge extends Bridge {
: BigInt(0);

const sendERC721Args: NFTBridgeTransferOp = {
srcChainId: BigInt(srcChainId),
destChainId: BigInt(destChainId),
to,
token,
Expand Down
9 changes: 9 additions & 0 deletions packages/bridge-ui-v2/src/libs/bridge/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export type BridgeTransaction = {
};

export type BridgeTransferOp = {
srcChainId: bigint;
destChainId: bigint;
to: Address;
token: Address;
Expand All @@ -89,6 +90,7 @@ export type BridgeTransferOp = {
};

export type NFTBridgeTransferOp = {
srcChainId: bigint;
destChainId: bigint;
to: Address;
token: Address;
Expand Down Expand Up @@ -200,6 +202,13 @@ export type AddressConfig = {
erc1155VaultAddress: Address;
crossChainSyncAddress: Address;
signalServiceAddress: Address;
hops?: Array<HopAddressConfig>;
};

export type HopAddressConfig = {
chainId: number;
crossChainSyncAddress: Address;
signalServiceAddress: Address;
};

export enum ContractType {
Expand Down
4 changes: 4 additions & 0 deletions packages/bridge-ui-v2/src/libs/error/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class InvalidProofError extends Error {
name = 'InvalidProofError';
}

export class WrongBridgeConfigError extends Error {
name = 'WrongBridgeConfigError';
}

export class MessageStatusError extends Error {
name = 'MessageStatusError';
}
Expand Down
Loading

2 comments on commit 79c44d7

@vercel
Copy link

@vercel vercel bot commented on 79c44d7 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-internal – ./packages/bridge-ui-v2

bridge-ui-v2-internal.vercel.app
bridge-ui-v2-internal-git-alpha-6-taikoxyz.vercel.app
bridge-ui-v2-internal-taikoxyz.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 79c44d7 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-a6 – ./packages/bridge-ui-v2

bridge-ui-v2-a6-taikoxyz.vercel.app
bridge-ui-v2-a6-git-alpha-6-taikoxyz.vercel.app
bridge-ui-v2-a6.vercel.app

Please sign in to comment.