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

fix(bridge-ui): A2 fixes #13355

Merged
merged 10 commits into from
Mar 18, 2023
2 changes: 0 additions & 2 deletions packages/bridge-ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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];
// }))
Expand Down
58 changes: 26 additions & 32 deletions packages/bridge-ui/src/components/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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
Expand All @@ -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,
),
});

Expand All @@ -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;
}
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui/src/components/form/BridgeForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
200 changes: 200 additions & 0 deletions packages/bridge-ui/src/constants/abi/Bridge.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
8 changes: 1 addition & 7 deletions packages/bridge-ui/src/relayer-api/RelayerAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down