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): L2 <-> L2 bridging with multi-hops #15393

Merged
merged 9 commits into from
Dec 18, 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-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
8 changes: 4 additions & 4 deletions packages/bridge-ui-v2/config/sample/configuredBridges.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"erc20VaultAddress": "",
"erc721VaultAddress": "",
"erc1155VaultAddress": "",
"crossChainSyncAddress": "",
"taikoAddress": "",
"signalServiceAddress": ""
}
},
Expand All @@ -20,7 +20,7 @@
"erc20VaultAddress": "",
"erc721VaultAddress": "",
"erc1155VaultAddress": "",
"crossChainSyncAddress": "",
"taikoAddress": "",
"signalServiceAddress": ""
}
},
Expand All @@ -32,7 +32,7 @@
"erc20VaultAddress": "",
"erc721VaultAddress": "",
"erc1155VaultAddress": "",
"crossChainSyncAddress": "",
"taikoAddress": "",
"signalServiceAddress": ""
}
},
Expand All @@ -44,7 +44,7 @@
"erc20VaultAddress": "",
"erc721VaultAddress": "",
"erc1155VaultAddress": "",
"crossChainSyncAddress": "",
"taikoAddress": "",
"signalServiceAddress": ""
}
}
Expand Down
25 changes: 22 additions & 3 deletions packages/bridge-ui-v2/config/schemas/configuredBridges.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,39 @@
"erc1155VaultAddress": {
"type": "string"
},
"crossChainSyncAddress": {
"taikoAddress": {
"type": "string"
},
"signalServiceAddress": {
"type": "string"
},
"hops": {
"type": "array",
"default": [],
"items": {
"type": "object",
"properties": {
"chainId": {
"type": "number"
},
"taikoAddress": {
"type": "string"
},
"signalServiceAddress": {
"type": "string"
}
}
}
}
},
"required": [
"bridgeAddress",
"erc20VaultAddress",
"erc721VaultAddress",
"erc1155VaultAddress",
"crossChainSyncAddress",
"signalServiceAddress"
"taikoAddress",
"signalServiceAddress",
"hops"
],
"additionalProperties": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ const _formatObjectToTsLiteral = (obj: RoutingMap): 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 configuredRelayer.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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
loading = LoadingState.CLAIMING;

try {
const { msgHash, message } = bridgeTx;
const { msgHash, message, receipt } = bridgeTx;

if (!msgHash || !message) {
throw new Error('Missing msgHash or message');
Expand All @@ -109,7 +109,7 @@
log(`Claiming ${bridgeTx.tokenType} for transaction`, bridgeTx);

// Step 5: Call claim() method on the bridge
const txHash = await bridge.claim({ msgHash, message, wallet });
const txHash = await bridge.claim({ msgHash, message, receipt, wallet });

const { explorer } = chainConfig[Number(bridgeTx.destChainId)].urls;

Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/ERC1155Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ export class ERC1155Bridge extends Bridge {
const gasLimit = !isTokenAlreadyDeployed
? BigInt(bridgeService.noERC1155TokenDeployedGasLimit)
: fee > 0
? bridgeService.noOwnerGasLimit
: BigInt(0);
? bridgeService.noOwnerGasLimit
: BigInt(0);

const sendERC1155Args: NFTBridgeTransferOp = {
destChainId: BigInt(destChainId),
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 @@ -45,8 +45,8 @@ export class ERC20Bridge extends Bridge {
const gasLimit = !isTokenAlreadyDeployed
? BigInt(bridgeService.noERC20TokenDeployedGasLimit)
: fee > 0
? bridgeService.noOwnerGasLimit
: BigInt(0);
? bridgeService.noOwnerGasLimit
: BigInt(0);

const sendERC20Args: BridgeTransferOp = {
destChainId: BigInt(destChainId),
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/ERC721Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export class ERC721Bridge extends Bridge {
const gasLimit = !isTokenAlreadyDeployed
? BigInt(bridgeService.noERC721TokenDeployedGasLimit)
: fee > 0
? bridgeService.noOwnerGasLimit
: BigInt(0);
? bridgeService.noOwnerGasLimit
: BigInt(0);

const sendERC721Args: NFTBridgeTransferOp = {
destChainId: BigInt(destChainId),
Expand Down
11 changes: 9 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/ETHBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,19 @@ export class ETHBridge extends Bridge {
const { messageStatus, destBridgeContract } = await super.beforeClaiming(args);

let txHash: Hash;
const { msgHash, message } = args;
const { msgHash, message, receipt } = args;
const srcChainId = Number(message.srcChainId);
const destChainId = Number(message.destChainId);

if (messageStatus === MessageStatus.NEW) {
const proof = await this._prover.encodedSignalProof(msgHash, srcChainId, destChainId);
const hops = routingContractsMap[srcChainId][destChainId].hops;

let proof;
if (hops.length > 0) {
proof = await this._prover.encodedSignalProofWithHops(msgHash, receipt, srcChainId, destChainId);
} else {
proof = await this._prover.encodedSignalProof(msgHash, srcChainId, destChainId);
}

try {
txHash = await destBridgeContract.write.processMessage([message, proof]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vi.mock('$bridgeConfig', () => ({
bridgeAddress: '0x00002',
erc721VaultAddress: '0x00003',
erc1155VaultAddress: '0x00004',
crossChainSyncAddress: '0x00005',
taikoAddress: '0x00005',
signalServiceAddress: '0x00006',
},
},
Expand All @@ -27,7 +27,7 @@ vi.mock('$bridgeConfig', () => ({
bridgeAddress: '0x00008',
erc721VaultAddress: '0x00009',
erc1155VaultAddress: '0x00010',
crossChainSyncAddress: '0x00011',
taikoAddress: '0x00011',
signalServiceAddress: '0x00012',
},
},
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('getContractAddressBasedOnType', () => {
tokenType: TokenType.ERC20,
};

const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].crossChainSyncAddress;
const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].taikoAddress;

// When
const address = getContractAddressByType(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getContractAddressByType = (args: GetContractAddressType): Address
case ContractType.SIGNALSERVICE:
return addressConfig.signalServiceAddress;
case ContractType.CROSSCHAINSYNC:
return addressConfig.crossChainSyncAddress;
return addressConfig.taikoAddress;
default:
throw new Error('Invalid contract type');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = routingContractsMap[Number(destChainId)][Number(srcChainId)].crossChainSyncAddress;
const destCrossChainSyncAddress = routingContractsMap[Number(destChainId)][Number(srcChainId)].taikoAddress;

try {
const destCrossChainSyncContract = getContract({
Expand Down
10 changes: 9 additions & 1 deletion packages/bridge-ui-v2/src/libs/bridge/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export type RequireApprovalArgs = {
export type ClaimArgs = {
msgHash: Hash;
message: Message;
receipt?: TransactionReceipt;
wallet: WalletClient;
};

Expand Down Expand Up @@ -198,7 +199,14 @@ export type AddressConfig = {
etherVaultAddress?: Address;
erc721VaultAddress: Address;
erc1155VaultAddress: Address;
crossChainSyncAddress: Address;
taikoAddress: Address;
signalServiceAddress: Address;
hops: Array<HopAddressConfig>;
};

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

Expand Down
Loading
Loading