From 7c66c2cc84313f73f1f8804048c0f6f082eb740b Mon Sep 17 00:00:00 2001 From: Korbinian Date: Tue, 12 Mar 2024 01:05:38 +0100 Subject: [PATCH] get latest block timestamp, proofreceipt util --- .../libs/bridge/getProofReceiptForMsgHash.ts | 7 ++++--- packages/bridge-ui/src/libs/bridge/types.ts | 18 +++++++++++++++++- .../src/libs/util/getLatestBlockTimestamp.ts | 13 +++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 packages/bridge-ui/src/libs/util/getLatestBlockTimestamp.ts diff --git a/packages/bridge-ui/src/libs/bridge/getProofReceiptForMsgHash.ts b/packages/bridge-ui/src/libs/bridge/getProofReceiptForMsgHash.ts index 2d7936bf74..bc1af11643 100644 --- a/packages/bridge-ui/src/libs/bridge/getProofReceiptForMsgHash.ts +++ b/packages/bridge-ui/src/libs/bridge/getProofReceiptForMsgHash.ts @@ -4,17 +4,18 @@ import { bridgeAbi } from '$abi'; import { routingContractsMap } from '$bridgeConfig'; import { config } from '$libs/wagmi'; -import type { GetProofReceiptParams } from './types'; +import type { GetProofReceiptParams, GetProofReceiptResponse } from './types'; -export const getProofReceiptForMsgHash = async (args: GetProofReceiptParams) => { +export const getProofReceiptForMsgHash = async (args: GetProofReceiptParams): Promise => { const { msgHash, destChainId, srcChainId } = args; const destBridgeAddress = routingContractsMap[Number(destChainId)][Number(srcChainId)].bridgeAddress; - return await readContract(config, { + const response: GetProofReceiptResponse = await readContract(config, { abi: bridgeAbi, address: destBridgeAddress, functionName: 'proofReceipt', args: [msgHash], chainId: Number(destChainId), }); + return response; }; diff --git a/packages/bridge-ui/src/libs/bridge/types.ts b/packages/bridge-ui/src/libs/bridge/types.ts index c8ab83df51..c712611429 100644 --- a/packages/bridge-ui/src/libs/bridge/types.ts +++ b/packages/bridge-ui/src/libs/bridge/types.ts @@ -8,7 +8,9 @@ export enum MessageStatus { RETRIABLE, DONE, FAILED, - ONLY_OWNER, + TOO_EARLY, // ONLY UI: If the invaction is too early + ONLY_OWNER, // ONLY UI: Gas limit is 0, so only the user can claim + PROVEN, // ONLY UI: Claim step 1 of 2 } // Bridge sendMessage() @@ -234,3 +236,17 @@ export type GetContractAddressType = { tokenType: TokenType; contractType: ContractType; }; + +export type GetProofReceiptParams = { + msgHash: Hash; + destChainId: bigint; + srcChainId: bigint; +}; + +// timestamp, preferred claimer address +export type GetProofReceiptResponse = readonly [bigint, Address]; + +export type DetermineTransactionStatusArgs = { + tx: BridgeTransaction; + claimer: Maybe
; +}; diff --git a/packages/bridge-ui/src/libs/util/getLatestBlockTimestamp.ts b/packages/bridge-ui/src/libs/util/getLatestBlockTimestamp.ts new file mode 100644 index 0000000000..d8443fd398 --- /dev/null +++ b/packages/bridge-ui/src/libs/util/getLatestBlockTimestamp.ts @@ -0,0 +1,13 @@ +import { getPublicClient } from '@wagmi/core'; + +import { ClientError } from '$libs/error'; +import { config } from '$libs/wagmi'; + +export const getLatestBlockTimestamp = async (srcChainId: bigint) => { + const client = getPublicClient(config, { chainId: Number(srcChainId) }); + if (!client) throw new ClientError('Client not found'); + const block = await client.getBlock({ + blockTag: 'latest', + }); + return block.timestamp; +};