diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index 6d0e3ef7da5..3fd774ecdc0 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -141,12 +141,10 @@ const userAddress = await store.getAddress(); const apiTxs = await $relayerApi.GetAllByAddress(userAddress); - const blockInfoMap = await $relayerApi.GetBlockInfo(); relayerBlockInfoMap.set(blockInfoMap); const txs = await $transactioner.GetAllByAddress(userAddress); - // const hashToApiTxsMap = new Map(apiTxs.map((tx) => { // return [tx.hash, tx]; // })) diff --git a/packages/bridge-ui/src/components/Transaction.svelte b/packages/bridge-ui/src/components/Transaction.svelte index aa2df2c1055..06eeac8142e 100644 --- a/packages/bridge-ui/src/components/Transaction.svelte +++ b/packages/bridge-ui/src/components/Transaction.svelte @@ -59,20 +59,26 @@ async function claim(bridgeTx: BridgeTransaction) { try { loading = true; - if (fromChain.id !== bridgeTx.message.destChainId.toNumber()) { - const chain = chainsRecord[bridgeTx.message.destChainId.toNumber()]; + // if the current "from chain", ie, the chain youre connected to, is not the destination + // of the bridge transaction, we need to change chains so your wallet is pointed + // to the right network. + if ($fromChainStore.id !== bridgeTx.toChainId) { + const chain = chainsRecord[bridgeTx.toChainId]; await switchChainAndSetSigner(chain); } + const tx = await $bridges - .get(bridgeTx.message.data === '0x' ? BridgeType.ETH : BridgeType.ERC20) + .get( + bridgeTx.message.data === '0x' || !bridgeTx.message.data + ? BridgeType.ETH + : BridgeType.ERC20, + ) .Claim({ signer: $signer, message: bridgeTx.message, msgHash: bridgeTx.msgHash, - destBridgeAddress: - chainsRecord[bridgeTx.message.destChainId.toNumber()].bridgeAddress, - srcBridgeAddress: - chainsRecord[bridgeTx.message.srcChainId.toNumber()].bridgeAddress, + destBridgeAddress: chainsRecord[bridgeTx.toChainId].bridgeAddress, + srcBridgeAddress: chainsRecord[bridgeTx.fromChainId].bridgeAddress, }); pendingTransactions.update((store) => { @@ -92,8 +98,8 @@ async function releaseTokens(bridgeTx: BridgeTransaction) { try { loading = true; - if (fromChain.id !== bridgeTx.message.srcChainId.toNumber()) { - const chain = chainsRecord[bridgeTx.message.srcChainId.toNumber()]; + if (fromChain.id !== bridgeTx.fromChainId) { + const chain = chainsRecord[bridgeTx.fromChainId]; await switchChainAndSetSigner(chain); } const tx = await $bridges @@ -102,13 +108,11 @@ signer: $signer, message: bridgeTx.message, msgHash: bridgeTx.msgHash, - destBridgeAddress: - chainsRecord[bridgeTx.message.destChainId.toNumber()].bridgeAddress, - srcBridgeAddress: - chainsRecord[bridgeTx.message.srcChainId.toNumber()].bridgeAddress, - destProvider: $providers.get(bridgeTx.message.destChainId.toNumber()), + destBridgeAddress: chainsRecord[bridgeTx.toChainId].bridgeAddress, + srcBridgeAddress: chainsRecord[bridgeTx.fromChainId].bridgeAddress, + destProvider: $providers.get(bridgeTx.toChainId), srcTokenVaultAddress: $chainIdToTokenVaultAddress.get( - bridgeTx.message.srcChainId.toNumber(), + bridgeTx.fromChainId, ), }); @@ -132,18 +136,14 @@ if (transaction.status !== MessageStatus.New) return true; const contract = new Contract( - chainsRecord[ - transaction.message.destChainId.toNumber() - ].headerSyncAddress, + chainsRecord[transaction.toChainId].headerSyncAddress, HeaderSync, - $providers.get( - chainsRecord[transaction.message.destChainId.toNumber()].id, - ), + $providers.get(chainsRecord[transaction.toChainId].id), ); const latestSyncedHeader = await contract.getLatestSyncedHeader(); const srcBlock = await $providers - .get(chainsRecord[transaction.message.srcChainId.toNumber()].id) + .get(chainsRecord[transaction.fromChainId].id) .getBlock(latestSyncedHeader); return transaction.receipt.blockNumber <= srcBlock.number; } @@ -153,20 +153,16 @@ const contract = new ethers.Contract( chainsRecord[transaction.toChainId].bridgeAddress, Bridge, - $providers.get( - chainsRecord[transaction.message.destChainId.toNumber()].id, - ), + $providers.get(chainsRecord[transaction.toChainId].id), ); transaction.status = await contract.getMessageStatus(transaction.msgHash); if (transaction.status === MessageStatus.Failed) { - if (transaction.message.data !== '0x') { + if (transaction.message?.data !== '0x') { const srcTokenVaultContract = new ethers.Contract( $chainIdToTokenVaultAddress.get(transaction.fromChainId), TokenVault, - $providers.get( - chainsRecord[transaction.message.srcChainId.toNumber()].id, - ), + $providers.get(chainsRecord[transaction.fromChainId].id), ); const { token, amount } = await srcTokenVaultContract.messageDeposits( transaction.msgHash, @@ -178,9 +174,7 @@ const srcBridgeContract = new ethers.Contract( chainsRecord[transaction.fromChainId].bridgeAddress, Bridge, - $providers.get( - chainsRecord[transaction.message.srcChainId.toNumber()].id, - ), + $providers.get(chainsRecord[transaction.fromChainId].id), ); const isFailedMessageResolved = await srcBridgeContract.isEtherReleased( transaction.msgHash, diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index 6b11922d906..f1f8aa27be0 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -270,11 +270,11 @@ // tx.chainId is not set immediately but we need it later. set it // manually. tx.chainId = $fromChain.id; - const storageKey = `transactions-${await ( + const storageKey = `transactions-${( await $signer.getAddress() ).toLowerCase()}`; let transactions: BridgeTransaction[] = JSON.parse( - await window.localStorage.getItem(storageKey), + window.localStorage.getItem(storageKey), ); const bridgeTransaction: BridgeTransaction = { diff --git a/packages/bridge-ui/src/constants/abi/Bridge.ts b/packages/bridge-ui/src/constants/abi/Bridge.ts index 841e3245422..209111d7125 100644 --- a/packages/bridge-ui/src/constants/abi/Bridge.ts +++ b/packages/bridge-ui/src/constants/abi/Bridge.ts @@ -1,4 +1,204 @@ export default [ + { + inputs: [], + name: 'B_CANNOT_RECEIVE', + type: 'error', + }, + { + inputs: [], + name: 'B_DENIED', + type: 'error', + }, + { + inputs: [], + name: 'B_DENIED', + type: 'error', + }, + { + inputs: [], + name: 'B_ERC20_CANNOT_RECEIVE', + type: 'error', + }, + { + inputs: [], + name: 'B_ETHER_RELEASED_ALREADY', + type: 'error', + }, + { + inputs: [], + name: 'B_ETHER_RELEASED_ALREADY', + type: 'error', + }, + { + inputs: [], + name: 'B_EV_DO_NOT_BURN', + type: 'error', + }, + { + inputs: [], + name: 'B_EV_NOT_AUTHORIZED', + type: 'error', + }, + { + inputs: [], + name: 'B_EV_PARAM', + type: 'error', + }, + { + inputs: [], + name: 'B_FAILED_TRANSFER', + type: 'error', + }, + { + inputs: [], + name: 'B_FAILED_TRANSFER', + type: 'error', + }, + { + inputs: [], + name: 'B_FORBIDDEN', + type: 'error', + }, + { + inputs: [], + name: 'B_FORBIDDEN', + type: 'error', + }, + { + inputs: [], + name: 'B_GAS_LIMIT', + type: 'error', + }, + { + inputs: [], + name: 'B_GAS_LIMIT', + type: 'error', + }, + { + inputs: [], + name: 'B_INCORRECT_VALUE', + type: 'error', + }, + { + inputs: [], + name: 'B_INCORRECT_VALUE', + type: 'error', + }, + { + inputs: [], + name: 'B_INIT_PARAM_ERROR', + type: 'error', + }, + { + inputs: [], + name: 'B_MSG_HASH_NULL', + type: 'error', + }, + { + inputs: [], + name: 'B_MSG_HASH_NULL', + type: 'error', + }, + { + inputs: [], + name: 'B_MSG_NON_RETRIABLE', + type: 'error', + }, + { + inputs: [], + name: 'B_MSG_NON_RETRIABLE', + type: 'error', + }, + { + inputs: [], + name: 'B_MSG_NOT_FAILED', + type: 'error', + }, + { + inputs: [], + name: 'B_MSG_NOT_FAILED', + type: 'error', + }, + { + inputs: [], + name: 'B_NULL_APP_ADDR', + type: 'error', + }, + { + inputs: [], + name: 'B_OWNER_IS_NULL', + type: 'error', + }, + { + inputs: [], + name: 'B_OWNER_IS_NULL', + type: 'error', + }, + { + inputs: [], + name: 'B_OWNER_IS_NULL', + type: 'error', + }, + { + inputs: [], + name: 'B_SIGNAL_NOT_RECEIVED', + type: 'error', + }, + { + inputs: [], + name: 'B_SIGNAL_NOT_RECEIVED', + type: 'error', + }, + { + inputs: [], + name: 'B_STATUS_MISMTACH', + type: 'error', + }, + { + inputs: [], + name: 'B_STATUS_MISMTACH', + type: 'error', + }, + { + inputs: [], + name: 'B_WRONG_CHAIN_ID', + type: 'error', + }, + { + inputs: [], + name: 'B_WRONG_CHAIN_ID', + type: 'error', + }, + { + inputs: [], + name: 'B_WRONG_CHAIN_ID', + type: 'error', + }, + { + inputs: [], + name: 'B_WRONG_CHAIN_ID', + type: 'error', + }, + { + inputs: [], + name: 'B_WRONG_CHAIN_ID', + type: 'error', + }, + { + inputs: [], + name: 'B_WRONG_TO_ADDRESS', + type: 'error', + }, + { + inputs: [], + name: 'B_WRONG_TO_ADDRESS', + type: 'error', + }, + { + inputs: [], + name: 'B_ZERO_SIGNAL', + type: 'error', + }, { inputs: [], name: 'RESOLVER_DENIED', diff --git a/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts b/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts index 3797e5e592e..5ed01f1c39f 100644 --- a/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts +++ b/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts @@ -109,13 +109,7 @@ export class RelayerAPIService implements RelayerAPI { receipt.blockNumber, ); - // A block could have multiple events being triggered so we need to find this particular tx - const event = events.find( - (e) => - e.args.message.owner.toLowerCase() === address.toLowerCase() && - e.args.message.depositValue.eq(tx.message.depositValue) && - e.args.msgHash === tx.msgHash, - ); + const event = events.find((e) => e.transactionHash === tx.hash); if (!event) { return tx; diff --git a/packages/protocol/contracts/signal/SignalService.sol b/packages/protocol/contracts/signal/SignalService.sol index 952249d7a0a..d5b62b9581b 100644 --- a/packages/protocol/contracts/signal/SignalService.sol +++ b/packages/protocol/contracts/signal/SignalService.sol @@ -104,19 +104,6 @@ contract SignalService is ISignalService, EssentialContract { address app, bytes32 signal ) public pure returns (bytes32 signalSlot) { - assembly { - // Load the free memory pointer and allocate memory for the concatenated arguments - let input := mload(0x40) - - // Store the app address and signal bytes32 value in the allocated memory - mstore(input, app) - mstore(add(input, 0x20), signal) - - // Calculate the hash of the concatenated arguments using keccak256 - signalSlot := keccak256(input, 0x40) - - // Free the memory allocated for the input - mstore(0x40, add(input, 0x60)) - } + signalSlot = keccak256(abi.encodePacked(app, signal)); } } diff --git a/packages/protocol/test/signal/SignalService.test.ts b/packages/protocol/test/signal/SignalService.test.ts index 41bf8c8a68b..2c26fad6fb5 100644 --- a/packages/protocol/test/signal/SignalService.test.ts +++ b/packages/protocol/test/signal/SignalService.test.ts @@ -40,6 +40,17 @@ describe("SignalService", function () { await expect(slot1).to.be.not.equal(slot2); }); + it("should return expected slot", async () => { + const want = + "0x9b11525774df15071344c44c56f02418dd56a9050effcc5de3912e88ccf1b95d"; + + const slot = await signalService.getSignalSlot( + "0x2aB7C0ab9AB47fcF370d13058BfEE28f2Ec0940c", + "0xf697cc0b80c778b40a4e863d2d2a723cc707bcdf2ba463bb1cd28aa2c888b229" + ); + + await expect(slot).to.be.equal(want); + }); }); describe("isSignalSent()", function () {