diff --git a/packages/aurora-erc20/src/bridged-erc20/sendToEthereum/index.ts b/packages/aurora-erc20/src/bridged-erc20/sendToEthereum/index.ts index 0fe57c51..84b7c283 100644 --- a/packages/aurora-erc20/src/bridged-erc20/sendToEthereum/index.ts +++ b/packages/aurora-erc20/src/bridged-erc20/sendToEthereum/index.ts @@ -58,6 +58,7 @@ export interface TransferDraft extends TransferStatus { export interface Transfer extends TransferDraft, TransactionInfo { id: string startTime: string + finishTime?: string decimals: number destinationTokenName: string recipient: string @@ -780,7 +781,7 @@ export async function checkSync ( options.erc20LockerAbi ?? bridgeParams.erc20LockerAbi )) { try { - const finalizationTxHash = await findFinalizationTxOnEthereum({ + const { transactions, block } = await findFinalizationTxOnEthereum({ usedProofPosition: '3', proof, connectorAddress: options.erc20LockerAddress ?? bridgeParams.erc20LockerAddress, @@ -792,7 +793,8 @@ export async function checkSync ( }) transfer = { ...transfer, - unlockHashes: [...transfer.unlockHashes, ...finalizationTxHash] + finishTime: new Date(block.timestamp * 1000).toISOString(), + unlockHashes: [...transfer.unlockHashes, ...transactions] } } catch (error) { // Not finding the finalization tx should not prevent processing/recovering the transfer. @@ -953,10 +955,13 @@ export async function checkUnlock ( } } + const block = await provider.getBlock(unlockReceipt.blockNumber) + return { ...transfer, status: status.COMPLETE, completedStep: UNLOCK, + finishTime: new Date(block.timestamp * 1000).toISOString(), unlockReceipts: [...transfer.unlockReceipts, unlockReceipt] } } diff --git a/packages/aurora-ether/src/bridged-ether/sendToEthereum/index.ts b/packages/aurora-ether/src/bridged-ether/sendToEthereum/index.ts index 3d81899f..d5201fb6 100644 --- a/packages/aurora-ether/src/bridged-ether/sendToEthereum/index.ts +++ b/packages/aurora-ether/src/bridged-ether/sendToEthereum/index.ts @@ -56,6 +56,7 @@ export interface TransferDraft extends TransferStatus { export interface Transfer extends TransferDraft, TransactionInfo { id: string startTime: string + finishTime?: string decimals: number destinationTokenName: string recipient: string @@ -740,7 +741,7 @@ export async function checkSync ( options.etherCustodianAbi ?? bridgeParams.etherCustodianAbi )) { try { - const finalizationTxHash = await findFinalizationTxOnEthereum({ + const { transactions, block } = await findFinalizationTxOnEthereum({ usedProofPosition: '3', proof, connectorAddress: options.etherCustodianAddress ?? bridgeParams.etherCustodianAddress, @@ -752,7 +753,8 @@ export async function checkSync ( }) transfer = { ...transfer, - unlockHashes: [...transfer.unlockHashes, ...finalizationTxHash] + finishTime: new Date(block.timestamp * 1000).toISOString(), + unlockHashes: [...transfer.unlockHashes, ...transactions] } } catch (error) { // Not finding the finalization tx should not prevent processing/recovering the transfer. @@ -913,10 +915,13 @@ export async function checkUnlock ( } } + const block = await provider.getBlock(unlockReceipt.blockNumber) + return { ...transfer, status: status.COMPLETE, completedStep: UNLOCK, + finishTime: new Date(block.timestamp * 1000).toISOString(), unlockReceipts: [...transfer.unlockReceipts, unlockReceipt] } } diff --git a/packages/near-ether/src/bridged-ether/sendToEthereum/index.ts b/packages/near-ether/src/bridged-ether/sendToEthereum/index.ts index 7f9efb12..037e810a 100644 --- a/packages/near-ether/src/bridged-ether/sendToEthereum/index.ts +++ b/packages/near-ether/src/bridged-ether/sendToEthereum/index.ts @@ -47,6 +47,7 @@ export interface TransferDraft extends TransferStatus { export interface Transfer extends TransferDraft, TransactionInfo { id: string startTime: string + finishTime?: string decimals: number destinationTokenName: string recipient: string @@ -790,7 +791,7 @@ export async function checkSync ( options.etherCustodianAbi ?? bridgeParams.etherCustodianAbi )) { try { - const finalizationTxHash = await findFinalizationTxOnEthereum({ + const { transactions, block } = await findFinalizationTxOnEthereum({ usedProofPosition: '3', proof, connectorAddress: options.etherCustodianAddress ?? bridgeParams.etherCustodianAddress, @@ -802,7 +803,8 @@ export async function checkSync ( }) transfer = { ...transfer, - unlockHashes: [...transfer.unlockHashes, ...finalizationTxHash] + finishTime: new Date(block.timestamp * 1000).toISOString(), + unlockHashes: [...transfer.unlockHashes, ...transactions] } } catch (error) { // Not finding the finalization tx should not prevent processing/recovering the transfer. @@ -963,10 +965,13 @@ export async function checkUnlock ( } } + const block = await provider.getBlock(unlockReceipt.blockNumber) + return { ...transfer, status: status.COMPLETE, completedStep: UNLOCK, + finishTime: new Date(block.timestamp * 1000).toISOString(), unlockReceipts: [...transfer.unlockReceipts, unlockReceipt] } } diff --git a/packages/near-ether/src/natural-near/sendToEthereum/index.ts b/packages/near-ether/src/natural-near/sendToEthereum/index.ts index 7d786ad4..62d29017 100644 --- a/packages/near-ether/src/natural-near/sendToEthereum/index.ts +++ b/packages/near-ether/src/natural-near/sendToEthereum/index.ts @@ -44,6 +44,7 @@ export interface TransferDraft extends TransferStatus { export interface Transfer extends TransferDraft, TransactionInfo { id: string startTime: string + finishTime?: string decimals: number destinationTokenName: string recipient: string @@ -775,7 +776,7 @@ export async function checkSync ( options.eNEARAbi ?? bridgeParams.eNEARAbi )) { try { - const finalizationTxHash = await findFinalizationTxOnEthereum({ + const { transactions, block } = await findFinalizationTxOnEthereum({ usedProofPosition: '8', proof, connectorAddress: options.eNEARAddress ?? bridgeParams.eNEARAddress, @@ -787,7 +788,8 @@ export async function checkSync ( }) transfer = { ...transfer, - mintHashes: [...transfer.mintHashes, ...finalizationTxHash] + finishTime: new Date(block.timestamp * 1000).toISOString(), + mintHashes: [...transfer.mintHashes, ...transactions] } } catch (error) { // Not finding the finalization tx should not prevent processing/recovering the transfer. @@ -951,10 +953,13 @@ export async function checkMint ( } } + const block = await provider.getBlock(mintReceipt.blockNumber) + return { ...transfer, status: status.COMPLETE, completedStep: MINT, + finishTime: new Date(block.timestamp * 1000).toISOString(), mintReceipts: [...transfer.mintReceipts, mintReceipt] } } diff --git a/packages/nep141-erc20/src/bridged-nep141/sendToEthereum/index.ts b/packages/nep141-erc20/src/bridged-nep141/sendToEthereum/index.ts index b6a98406..84e10285 100644 --- a/packages/nep141-erc20/src/bridged-nep141/sendToEthereum/index.ts +++ b/packages/nep141-erc20/src/bridged-nep141/sendToEthereum/index.ts @@ -46,6 +46,7 @@ export interface TransferDraft extends TransferStatus { export interface Transfer extends TransferDraft, TransactionInfo { id: string startTime: string + finishTime?: string decimals: number destinationTokenName: string recipient: string @@ -790,7 +791,7 @@ export async function checkSync ( options.erc20LockerAbi ?? bridgeParams.erc20LockerAbi )) { try { - const finalizationTxHash = await findFinalizationTxOnEthereum({ + const { transactions, block } = await findFinalizationTxOnEthereum({ usedProofPosition: '3', proof, connectorAddress: options.erc20LockerAddress ?? bridgeParams.erc20LockerAddress, @@ -802,7 +803,8 @@ export async function checkSync ( }) transfer = { ...transfer, - unlockHashes: [...transfer.unlockHashes, ...finalizationTxHash] + finishTime: new Date(block.timestamp * 1000).toISOString(), + unlockHashes: [...transfer.unlockHashes, ...transactions] } } catch (error) { // Not finding the finalization tx should not prevent processing/recovering the transfer. @@ -957,19 +959,19 @@ export async function checkUnlock ( if (unlockReceipt.transactionHash !== unlockHash) { // Record the replacement tx unlockHash - return { + transfer = { ...transfer, - status: status.COMPLETE, - completedStep: UNLOCK, - unlockHashes: [...transfer.unlockHashes, unlockReceipt.transactionHash], - unlockReceipts: [...transfer.unlockReceipts, unlockReceipt] + unlockHashes: [...transfer.unlockHashes, unlockReceipt.transactionHash] } } + const block = await provider.getBlock(unlockReceipt.blockNumber) + return { ...transfer, status: status.COMPLETE, completedStep: UNLOCK, + finishTime: new Date(block.timestamp * 1000).toISOString(), unlockReceipts: [...transfer.unlockReceipts, unlockReceipt] } } diff --git a/packages/utils/src/findFinalizationTx.ts b/packages/utils/src/findFinalizationTx.ts index 7297eb3a..496f56b8 100644 --- a/packages/utils/src/findFinalizationTx.ts +++ b/packages/utils/src/findFinalizationTx.ts @@ -24,7 +24,7 @@ export async function findFinalizationTxOnEthereum ( amount: string provider: ethers.providers.Provider } -): Promise { +): Promise<{ transactions: string[], block: ethers.providers.Block }> { const usedProofsMappingPosition = '0'.repeat(63) + usedProofPosition const usedProofsKey: string = bs58.decode(proof.outcome_proof.outcome.receipt_ids[0]!).toString('hex') const proofStorageIndex = ethers.utils.keccak256('0x' + usedProofsKey + usedProofsMappingPosition) @@ -49,7 +49,12 @@ export async function findFinalizationTxOnEthereum ( // NOTE: Depending on the connector, event args are in different order or not indexed, so query all and filter. const filter = connectorContract.filters[finalizationEvent]!() const events = await connectorContract.queryFilter(filter, minBlock, minBlock) - return events.filter(e => + const transactions = events.filter(e => e.args!.recipient.toLowerCase() === recipient.toLowerCase() && e.args!.amount.toString() === amount ).map(e => e.transactionHash) + if (transactions.length === 0) { + throw new SearchError(`Finalization tx on Ethereum not found for proof: ${JSON.stringify(proof)}`) + } + const block = await provider.getBlock(minBlock) + return { transactions, block } }