Skip to content

Commit

Permalink
get latest block timestamp, proofreceipt util
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed Mar 12, 2024
1 parent afd580d commit 7c66c2c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetProofReceiptResponse> => {
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;
};
18 changes: 17 additions & 1 deletion packages/bridge-ui/src/libs/bridge/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<Address>;
};
13 changes: 13 additions & 0 deletions packages/bridge-ui/src/libs/util/getLatestBlockTimestamp.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 7c66c2c

Please sign in to comment.